MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / handle_command

Function handle_command

main.py:306–1072  ·  view source on GitHub ↗
(user_input: str, history: list, yolo: bool = False)

Source from the content-addressed store, hash-verified

304 console.print(line)
305
306def 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:

Callers 1

replFunction · 0.85

Calls 15

save_sessionFunction · 0.90
clear_historyFunction · 0.90
clear_sessionFunction · 0.90
successFunction · 0.90
infoFunction · 0.90
estimate_messages_tokensFunction · 0.90
summarize_historyFunction · 0.90
list_historyFunction · 0.90
undoFunction · 0.90
errorFunction · 0.90
diffFunction · 0.90
search_in_projectFunction · 0.90

Tested by

no test coverage detected