Skip to content

feat(commands): fork-agent infra + /btw /simplify /advisor (#33 #37 #62) - #85

Merged
Crsei merged 1 commit into
Crsei:rust-litefrom
yaohaowei0914:claude/recursing-shockley-8337fa
Apr 21, 2026
Merged

feat(commands): fork-agent infra + /btw /simplify /advisor (#33 #37 #62)#85
Crsei merged 1 commit into
Crsei:rust-litefrom
yaohaowei0914:claude/recursing-shockley-8337fa

Conversation

@yaohaowei0914

Copy link
Copy Markdown
Contributor

Summary

Delivers the fork-agent infrastructure and the three commands that depend on it:

Fork infrastructure (issue #37)

  • New engine::agent::fork::run_fork primitive — spawns an ephemeral child QueryEngine with no persistence, configurable tool set, and single/multi-turn caps. Optionally seeds with parent messages for cache-safe reuse.
  • SkillContext::Fork in tools/skill.rs now dispatches through run_fork instead of the prior "inline fallback", honoring each skill's allowed_tools.

/btw (issue #37)

  • /btw <question> runs a tool-free, single-turn fork.
  • Answer returned via CommandResult::Output, so the main transcript is not polluted.
  • Side-question role pinned by a short system-prompt fragment to keep cache hits high.

/simplify (issue #62)

  • Bridges the bundled simplify skill to a user-facing slash command.
  • Multi-agent mode (default): fans out three parallel reviewer forks covering reuse / quality / efficiency via futures::future::join_all, then joins the outputs into a single action-oriented summary.
  • --single / -1 runs a single-agent pass; optional scope argument (/simplify src/foo.rs) narrows the review.

/advisor + advisor_model plumbing (issue #33)

  • advisor_model: Option<String> added to:
    • AppState (types/app_state.rs)
    • SettingsJson runtime projection (cc-config/runtime_settings.rs)
    • RawSettings / EffectiveSettings + JSON schema (camelCase key advisorModel)
    • ModelCallParamsMessagesRequest (serialized with skip_serializing_if)
  • provider_supports_advisor() gates Anthropic / Azure / Bedrock / Vertex; other providers are stripped with a debug! log (engine/lifecycle/deps.rs).
  • /advisor supports show / set / unset (aliases: none, off, clear), persists atomically via write_user_settings, and surfaces a clear inactive-provider note in its output.

Test plan

  • cargo test -p claude-code-rs --bin claude-code-rs -- commands::btw commands::simplify commands::advisor engine::agent::fork api::client::tests::test_messages_request api::client::tests::test_provider_supports_advisor27/27 pass
  • cargo test -p claude-code-rs --bin claude-code-rs -- commands:: --test-threads=1299/299 pass (4 pre-existing env-var races surface only under parallelism; none of them are new tests in this PR — verified by running tests against base before stashing)
  • cargo build -p claude-code-rs — clean, only the 2 pre-existing session_id warnings in web/handlers.rs

Review notes

  • The run_fork primitive is small on purpose: it reuses the existing collect_stream_result from the AgentTool path and skips the global agent-tree + IPC event registration, so /btw stays lightweight.
  • Advisor tests use a noop_persist closure so the command tests are hermetic (no env-var mutation, no touching of the user's real settings.json). Disk round-trip is covered separately by persist_to_path_round_trips_via_disk.
  • Provider matrix for advisor support is intentionally conservative (Anthropic wire format only). OpenAI-compatible + Google are stripped; when users set advisor on such a provider, /advisor still persists the value but the status line flags it as inactive.

🤖 Generated with Claude Code

…rsei#37 Crsei#62)

Builds a real forked-agent execution path and layers three user-facing
commands on top of it.

## Fork infrastructure (issue Crsei#37)
- `engine::agent::fork::run_fork` — ephemeral child QueryEngine with no
  persistence, configurable tool set, and single/multi-turn caps.
- `SkillContext::Fork` now dispatches through this primitive instead of
  the prior "inline fallback", honoring each skill's `allowed_tools`.

## /btw (issue Crsei#37)
- Tool-free, single-turn side-question fork that reuses the parent
  conversation as cache-safe context. Answer returned via
  `CommandResult::Output`, so the main transcript is not polluted.

## /simplify (issue Crsei#62)
- Slash entrypoint for the bundled `simplify` skill.
- Multi-agent mode: fans out three parallel reviewer forks (reuse /
  quality / efficiency) via `futures::future::join_all` and joins the
  outputs into a single action-oriented summary.
- `--single` / `-1` fallback for a single-agent pass; optional scope
  argument narrows the review.

## /advisor + advisor_model plumbing (issue Crsei#33)
- `advisor_model: Option<String>` added to `AppState`, `SettingsJson`
  (runtime), `RawSettings`/`EffectiveSettings` (on-disk, camelCase key
  `advisorModel`) and the JSON schema.
- `ModelCallParams` carries it through the query loop into
  `MessagesRequest::advisor_model` (serialized with
  `skip_serializing_if`). `provider_supports_advisor` gates Anthropic,
  Azure, Bedrock, Vertex; other providers are stripped with a debug log.
- `/advisor` supports show / set / unset (aliases: none/off/clear),
  persists atomically via `write_user_settings`, and flags inactive
  providers in its output.

Tests: 27 new unit tests covering fork params, /btw usage path,
/simplify arg parsing + multi-agent aggregation, advisor state
transitions + on-disk round-trip, and provider-support matrix.
All pass alongside the existing suite (299/299 serial).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Crsei
Crsei merged commit 474dd85 into Crsei:rust-lite Apr 21, 2026
1 of 4 checks passed
yaohaowei0914 pushed a commit to yaohaowei0914/claude-code-rust that referenced this pull request Apr 21, 2026
Integrates the fork-agent infrastructure and ancillary command/IPC
updates that landed on rust-lite after this branch opened:

- PR Crsei#85: fork-agent infra + /btw /simplify /advisor (Crsei#33 Crsei#37 Crsei#62)
- PR Crsei#87: MCP/plugin/reload-plugins/ide/reload-plugins commands (Crsei#41 Crsei#44 Crsei#47 Crsei#49)
- PR Crsei#88: /loop /schedule /team-onboarding (Crsei#43 Crsei#58 Crsei#60 Crsei#63)

## Conflict resolution

Git's recursive merge handled every hunk on its own — each of the five
files flagged as overlapping had non-overlapping line ranges between
my workspace-split edits and rust-lite's feature edits:

- `crates/cc-engine/src/types/app_state.rs` — my move to cc-engine vs.
  advisor/fork-related AppState fields. Clean auto-merge.
- `crates/claude-code-rs/src/engine/agent/mod.rs` — my `cc_types::agent_*`
  import rewrites vs. rust-lite's `pub mod fork;` addition. Clean.
- `crates/claude-code-rs/src/engine/lifecycle/deps.rs` — my
  `cc_types::background_agents` retyping and `hook_runner()` impl vs.
  rust-lite's `advisor_model` stripping logic. Clean.
- `crates/claude-code-rs/src/query/deps.rs` — my `hook_runner()` /
  `drain_background_results` signature changes vs. rust-lite's new
  `ModelCallParams::advisor_model` field. Clean.
- `crates/claude-code-rs/src/query/loop_impl.rs` — my hook-runner-trait
  rewiring vs. rust-lite's advisor model plumbing. Clean.

All 40+ other touched files (api/*, commands/*, ide/*, ipc/*,
services/*, etc.) merged without conflict — they're in regions my
branch didn't touch.

## Verification

- `cargo check --workspace`: clean (2 pre-existing warnings).
- `cargo test -p cc-types`: 4/4 passing (teams + background_agents).
- `cargo test -p cc-engine`: status_line + types suite unchanged.
- `cargo test --bin claude-code-rs engine::agent query::loop_impl`:
  69/69 passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants