Skip to content

refactor(workspace): P5 break hub cycles (tools↔engine, engine↔commands) - #83

Merged
Crsei merged 1 commit into
Crsei:rust-litefrom
yaohaowei0914:claude/recursing-cannon-90df2c
Apr 21, 2026
Merged

refactor(workspace): P5 break hub cycles (tools↔engine, engine↔commands)#83
Crsei merged 1 commit into
Crsei:rust-litefrom
yaohaowei0914:claude/recursing-cannon-90df2c

Conversation

@yaohaowei0914

Copy link
Copy Markdown
Contributor

Summary

Breaks the three narrow import cycles that would block extracting tools, engine, and commands into separate crates in Phase 6. Everything still compiles as one crate today; Phase 5 is purely a preparatory refactor.

Closes #74. Part of #68.

What changed

5a — Move Agent tool into engine/

  • crates/claude-code-rs/src/tools/agent/crates/claude-code-rs/src/engine/agent/ (5 files)
  • Tool registry updated to construct crate::engine::agent::AgentTool
  • Agent tool is semantically an engine sub-process launcher; this is its natural home

5b — Extract HookRunner trait into cc-types

  • New crates/cc-types/src/hooks.rs defines HookRunner trait + plain data types (HookEventConfig, HookEntry, HookOutput, PermissionOverride, PreToolHookResult, PostToolHookResult) + NoopHookRunner
  • tools/hooks/mod.rs re-exports types and adds concrete ShellHookRunner
  • QueryEngine, QueryEngineDeps, and ToolUseContext now hold Arc<dyn HookRunner> instead of importing tools::hooks directly
  • Agent code fires SubagentStart/Stop hooks via ctx.hook_runner

5c — Invert engine → commands

  • New crates/cc-types/src/commands.rs with CommandDispatcher trait, ParsedCommand type, NoopCommandDispatcher
  • commands/mod.rs adds concrete DefaultCommandDispatcher
  • process_user_input now takes &dyn CommandDispatcher; engine threads the dispatcher through

External call sites (main.rs, teams/runner.rs, web/handlers.rs) install the shell/default impls; tests use the no-op defaults.

Verification

Cycle-check greps (all return zero):

  • grep -rn "use crate::engine" crates/claude-code-rs/src/tools/
  • grep -rn "use crate::tools::hooks" crates/claude-code-rs/src/engine/
  • grep -rn "use crate::commands" crates/claude-code-rs/src/engine/

Build & test:

  • cargo build --release -p claude-code-rs — clean (two pre-existing warnings on unused session_id fields in web/handlers.rs)
  • Targeted: engine::agent 59/59, engine::input_processing 6/6, tools::hooks 20/20, test_submit_local_command pass
  • Full suite: 1226/1234; the 8 failures are pre-existing env-dependent tests (teams mailbox paths, daemon log path, Windows %TEMP%-tied tests, plugin paths, model_add pricing) — none touch hooks/agent/commands/input_processing

Test plan

  • CI cargo build green
  • CI cargo test green (or at least no new failures vs. rust-lite baseline)
  • No new warnings
  • Reviewer spot-check: Arc<dyn HookRunner> / Arc<dyn CommandDispatcher> wiring at external call sites is correct

…mmands)

- Move tools::agent -> engine::agent (5a)
- Extract HookRunner trait into cc-types; engine no longer imports tools::hooks (5b)
- Extract CommandDispatcher trait into cc-types; engine no longer imports commands (5c)

Closes Crsei#74
@Crsei
Crsei merged commit 52cdaf4 into Crsei:rust-lite Apr 21, 2026
1 of 4 checks passed
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.

[workspace-split] Phase 5: Break hub cycles (tools↔engine, engine↔commands)

2 participants