Repository navigation
refactor(claude_code, agy): split the backends, no behaviour change - #63
Merged
Merged
Conversation
…hole turns Before splitting the two backends, pin what they do through the paths a refactor could move: a 47-line corpus over map_line (every event type, subagent and empty cases, each way a failed result describes itself, lines that do not parse) and that only a result line writes the outcome; the exact argv and environment of claude's command for a plain turn, a fully configured one and one after the thinking flag was refused, and the stdin message; agy's exact command, default and configured. Whole turns run through run_turn on stand-in CLIs: the events in order, the outcome, the session kept, and the exact error texts for a CLI that cannot start, a turn with no result line and a cancelled agy turn. All pass on the original single-file code. Co-Authored-By: Claude <noreply@anthropic.com>
claude_code.rs (3557 lines with the pins) becomes src/agent/claude_code/: the backend and its AgentBackend face (mod.rs), the stream-json lines and what each becomes (wire.rs), the argv and environment a turn starts with (command.rs), one run of the CLI with the bridge and the stream loop (turn.rs), profile and login choice (profiles.rs), and deny rendering (deny.rs); tests split into tests.rs (stand_in_cli stays at its crate path), wire_tests.rs, command_tests.rs and profile_tests.rs. Everything other code names is re-exported, so every crate::agent::claude_code:: path is unchanged. map_line is a dispatch over named steps (session_started, stream_delta, assistant_text, quota, result_events, failure_detail); run_once is spawn plumbing plus trace_spawn, dump_argv, spawn and finish, with the process tree kept alive until stderr is read, as before. agy's run_turn becomes spawn, read, started, finished and no_result_line, and its tests move to agy_tests.rs. A stray doc comment that sat on PROFILE_ENV goes back to consume, which it describes. MAX_UNWIRED 41 -> 38, as the wiring ratchet asks. The old file had a column-zero #[cfg(test)] at line 8, so the scanner never read it: Toolbox::run_subagents_on and tool_bridge::client_entry were listed unwired while called from it, and are now seen. The third drop is NOT real wiring: guards::restrictions is still called only by tests, which the scanner now reads because test files reached by #[path]/mod have no column-zero marker (the same blind spot api_wire_tests.rs and the runner's test files already have). The pins from the previous commit pass unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
From the independent review of #63: budget_for_spawn's doc named claude_code.rs for run_once (now claude_code/turn.rs), and contracts.json's RateLimitInfo _owner named claude_code.rs (now claude_code/wire.rs). Documentation only; nothing reads _owner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Answers the code-auditor findings on the two CLI backends, with no behaviour change.
Findings
claude_code.rs(2999 lines, fan-out 465) becomessrc/agent/claude_code/, with every file 42-899 lines.map_line(complexity 24) becomes a dispatch oversession_started,stream_delta,assistant_text,quota,result_eventsandfailure_detail.run_once(157 lines) becomes setup plustrace_spawn,dump_argv,spawnandfinish.run_turn(117 lines) becomesspawn,read,started,finishedandno_result_line. Its tests move toagy_tests.rs.audit_static_checkreports no function over 100 lines and no complexity over 20 in any changed file. Fan-out is left as the split leaves it. The two remaining cycle reports inwire_tests.rsare name-matching false positives (the test helpermapis matched against.map(calls).Commits
map_linecorpus;run_turnon stand-in CLIs, with the exact error texts (spawn failure, no result line, cancelled).crate::agent::claude_code::path is re-exported unchanged. The process tree still lives until stderr is read, as before.MAX_UNWIRED41 -> 38: read this before mergingThe old file had a column-zero
#[cfg(test)]at line 8, so the wiring scanner never read the rest of it.Toolbox::run_subagents_onandtool_bridge::client_entrywere listed as unwired while called from that file. They are now correctly seen.guards::restrictionsis not really wired. It is still called only by tests. The scanner now reads the split-out test files as production code because they have no column-zero marker, the same blind spotapi_wire_tests.rsandrunner/*_tests.rsalready have. That is a scanner limitation to decide on separately.Gate (Windows)
cargo fmt --all -- --check: clean.cargo clippy --all-targets -- -D warnings: clean.cargo test: lib 2305 passed, 10 ignored. Before this work: 2289 passed, 10 ignored.#[allow], no new crates.