Skip to main content

Module agent_cli

Module agent_cli 

Source
Expand description

Subprocess backends: drive a round’s edits by shelling out to the claude, opencode, codex, or cursor-agent CLI in non-interactive mode, run with the scheduler crate directory as the cwd so the CLI’s own tools edit the files in place. The controller then builds/validates the resulting diff exactly as it does for the built-in openai backend, so keep/revert/dedup work unchanged.

Each CLI runs in one of two Modes. In Mode::Edit it edits the crate in place with its approval/permission prompts disabled and full write access, so only run that where it is acceptable. In Mode::Plan it runs read-only and returns a textual plan that is handed to the coder role: claude uses its plan permission mode, codex a read-only sandbox, and cursor-agent its plan mode (all genuinely cannot write); opencode uses its built-in plan agent on a best-effort basis and may still touch files (its edits are just validated/reverted like any other round).

Structs§

ClaudePlanCapture 🔒
StreamPrinter 🔒
Streams a subprocess backend’s assistant text and reasoning to stdout as the CLI emits it, mirroring the openai backend. This is chunk-level: each CLI event (text block / part / item) is printed whole as it arrives, not token-by-token. Reasoning is dimmed to set it apart from the answer. Tool-call lines are printed separately to stderr and are not handled here.

Enums§

Mode
How a subprocess backend runs this turn.

Functions§

arg_hint 🔒
Pick the most informative argument from a tool-call input object (the command run, or the file/path/pattern it targets), truncated for one-line display.
claude_plan_path 🔒
claude_supports_partial_messages 🔒
Whether the installed claude advertises --include-partial-messages (added in newer versions). Detected once from claude --help and cached: older builds reject unknown flags, so we must not pass it blindly. When absent we fall back to chunk-level output (the result-event text printed at turn end).
codex_file_paths 🔒
Best-effort changed-file paths from a codex file_change item.
codex_item_label 🔒
A concise label for a codex item.completed item, or None for non-tool items (assistant text / reasoning). Includes the command run or files changed.
cursor_is_new_fragment 🔒
cursor streams a message as fragment deltas (with --stream-partial-output), then repeats the whole message as one consolidation event whose text equals the accumulated fragments. Track the running segment so that consolidation is dropped instead of printed a second time. Returns true if text is a new fragment to print, false if it is the repeat (and the segment is reset, ready for the next message).
cursor_tool_label 🔒
A concise label for a cursor-agent tool_call event. The tool_call object carries the tool under a single <name>ToolCall key (e.g. shellToolCall, readToolCall, editToolCall) alongside bookkeeping keys like hookAdditionalContexts / toolCallId. serde_json orders object keys alphabetically, so pick the *ToolCall key explicitly rather than the first one; strip the suffix and pull a salient argument (command / path) from args.
first_line 🔒
format_command 🔒
codex command is a string or an argv array; render it as a single line.
invoke_claude 🔒
invoke_codex 🔒
invoke_cursor 🔒
invoke_opencode 🔒
is_claude_plan_path 🔒
nonempty_string 🔒
print_recovered_claude_plan 🔒
print_tool 🔒
Print a concise tool-call line (matches the openai backend’s non-verbose output).
run
Run one prompt through the configured subprocess backend in cwd, returning the CLI’s final text. In Mode::Edit this is the round’s change summary (the CLI edits cwd directly); in Mode::Plan it is the plan handed to the coder. When stream_stdout is set the assistant’s text and reasoning are streamed to stdout as the CLI emits them (chunk-level, mirroring the openai backend). Token usage reported by the CLI is summed into usage (reliably for claude; opencode/codex only when they emit it).
run_streaming 🔒
Spawn cmd with stdin_payload piped in, stream stdout line-by-line, call on_event for each JSON line (echoing raw lines to stderr when verbose), and return the exit status plus captured stderr.
terminate_process_group 🔒
tool_label 🔒
name(hint) when a salient argument is available, else just name.
truncate 🔒