Expand description
In-process minimal REPL — defect --repl.
Does not use ACP or TUI: reads one line from stdin as a prompt, runs one turn, and prints the session event stream to stdout as plain colored text. Its purpose is a convenient entry point for “hand-crafting prompts during development to quickly test agent behavior”, not a polished frontend for end users.
The entire module is gated by the repl feature (see Cargo.toml) — when the feature
is disabled, this code is not compiled and owo-colors / crossterm are not pulled
in.
§Why line editing is done manually
Initially we relied on the terminal’s canonical (cooked) mode for line editing, which
had two bugs: backspace could erase the prompt, and deleting Chinese characters
removed bytes instead of whole Unicode chars. So we switch to raw mode during line
reading and handle it ourselves: maintain a String buffer (where pop() naturally
deletes by char), and on each key press redraw by “carriage return + clear line +
redraw prompt+buffer” — the prompt is redrawn and thus cannot be erased, and CJK wide
characters work correctly because the terminal advances the cursor by display width.
Raw mode is only active during line reading; event rendering during a turn still runs
in cooked mode, so \n works normally.
We use crossterm for raw mode and key event parsing (consistent across Linux /
macOS / Windows) — its event::read() returns already-parsed KeyEvent values
(multi-byte chars are delivered directly, no need to manually assemble UTF-8), and raw
mode switching is cross-platform.
§Relationship with the ACP path
Reuses the same AgentCore: creates a session with
Frontend::Cli, and uses local
LocalFsBackend / LocalShellBackend (the REPL runs on the local machine, files and
commands are executed directly, no delegation). The event stream consumption logic is
a minimal version of the defect-acp event pump — that one translates events into
wire notifications, while this one translates them into terminal text.
Functions§
- run
- Run an interactive REPL until stdin EOF (Ctrl-D) or until
:q/:quit/:exitis read.