(user_input: str, history: list, yolo: bool = False)
| 304 | console.print(line) |
| 305 | |
| 306 | def handle_command(user_input: str, history: list, yolo: bool = False) -> tuple[bool, list]: |
| 307 | cmd = user_input.strip() |
| 308 | low = cmd.lower() |
| 309 | |
| 310 | if low in ("/exit", "/quit", "exit", "quit"): |
| 311 | from core.sessions import save_session |
| 312 | save_session(history) |
| 313 | console.print("[dim]Session saved. Goodbye![/dim]") |
| 314 | shutdown() |
| 315 | sys.exit(0) |
| 316 | |
| 317 | if low == "/clear": |
| 318 | history.clear() |
| 319 | ctx.clear_context() |
| 320 | from core.filehistory import clear_history |
| 321 | clear_history() |
| 322 | from core.sessions import clear_session |
| 323 | clear_session() |
| 324 | success("History, context, undo history, and saved session cleared.") |
| 325 | return True, history |
| 326 | |
| 327 | if low == "/summarize": |
| 328 | if len(history) < 4: |
| 329 | info("Not enough history to summarize (need at least 2 turns).") |
| 330 | else: |
| 331 | from core.summarizer import summarize_history |
| 332 | from core.tokens import estimate_messages_tokens |
| 333 | old_tokens = estimate_messages_tokens(history) |
| 334 | history = summarize_history(history) |
| 335 | new_tokens = estimate_messages_tokens(history) |
| 336 | success(f"Context compressed: {old_tokens} → {new_tokens} tokens") |
| 337 | return True, history |
| 338 | |
| 339 | if low.startswith("/undo"): |
| 340 | from core.filehistory import undo, list_history |
| 341 | parts = cmd.split(maxsplit=1) |
| 342 | if len(parts) < 2: |
| 343 | hist = list_history() |
| 344 | if not hist: |
| 345 | info("Nothing to undo this session.") |
| 346 | else: |
| 347 | console.print("[bold]Files with undo history:[/bold]") |
| 348 | for path, timestamps in hist.items(): |
| 349 | console.print(f" 📄 {Path(path).name} — {', '.join(timestamps)}") |
| 350 | info("Usage: /undo <filename>") |
| 351 | else: |
| 352 | result = undo(parts[1]) |
| 353 | error(result) if result.startswith("[ERROR]") else None |
| 354 | return True, history |
| 355 | |
| 356 | if low.startswith("/diff"): |
| 357 | from core.filehistory import diff, list_history |
| 358 | parts = cmd.split(maxsplit=1) |
| 359 | if len(parts) < 2: |
| 360 | hist = list_history() |
| 361 | if not hist: |
| 362 | info("No file changes this session.") |
| 363 | else: |
no test coverage detected