Skip to content

refactor(core): split agent/mod.rs monolith into focused submodules#4933

Merged
bug-ops merged 1 commit into
mainfrom
refactor/4923-core-agent-mod-split
Jun 6, 2026
Merged

refactor(core): split agent/mod.rs monolith into focused submodules#4933
bug-ops merged 1 commit into
mainfrom
refactor/4923-core-agent-mod-split

Conversation

@bug-ops

@bug-ops bug-ops commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

crates/zeph-core/src/agent/mod.rs held a single impl<C: Channel> Agent<C> block of 58 methods across 4120 lines — the largest production monolith in the workspace. This splits it into focused submodules along concern boundaries, following the pattern of the prior agent/persistence (#4878), router (#4875), and config (#4874) splits.

mod.rs is reduced to ~2000 lines, retaining only the struct definition, DispatchFlow, constructors, the main agent loop (run and its dispatch helpers), and the free helper functions used by the loop.

Extracted submodules

File Responsibility
shutdown.rs Graceful shutdown: structured session-summary generation (with plain-text fallback) + orphaned tool-use tombstone flush
subagent_commands.rs /agent command handlers (list/status/approve/deny/spawn/cancel/resume), sub-agent polling, and bounded spawn-context assembly (incl. the estimate_parts_size / trim_parent_messages / sanitize_parent_messages helpers)
skill_reload.rs Skill matcher rebuild, trust refresh, and skill/instruction hot-reload
config_reload.rs Config overlay hot-reload, context-budget recompute, shell-overlay divergence warning
hooks_dispatch.rs CwdChanged / FileChanged lifecycle hook dispatch + the McpManagerDispatch MCP-bridge adapter

The three SideQuest eviction methods (maybe_sidequest_eviction, sidequest_apply_pending, sidequest_schedule_next) move into the existing sidequest.rs.

Visibility

The shared impl block is now split across files. Because a private inherent method defined in agent::<submodule> is no longer visible to the parent agent module or its siblings, the 14 methods called cross-module are bumped to pub(super); every method called only within its own new module stays private. No public API changepub / pub(crate) signatures are untouched.

The one internal test referencing the moved crate::agent::{estimate_parts_size, trim_parent_messages} free functions is updated to the new subagent_commands path. The stale do-not-split TODO at the top of mod.rs (which predated and is superseded by this work) is removed.

Validation

  • cargo +nightly fmt --check — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features desktop,ide,server,chat,pdf,scheduler --locked — clean
  • cargo nextest run --workspace --lib --bins10530 passed, 21 skipped
  • cargo test --doc -p zeph-core — 32 passed
  • RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps -p zeph-core — builds (one pre-existing unrelated warning in builder.rs)

Closes #4923

@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes core zeph-core crate labels Jun 6, 2026
@bug-ops bug-ops self-assigned this Jun 6, 2026
@github-actions github-actions Bot added refactor Code refactoring without functional changes size/XL Extra large PR (500+ lines) labels Jun 6, 2026
@bug-ops
bug-ops force-pushed the refactor/4923-core-agent-mod-split branch from f60af29 to b7a6fff Compare June 6, 2026 15:11
@bug-ops
bug-ops enabled auto-merge (squash) June 6, 2026 15:11
agent/mod.rs held a single impl<C: Channel> Agent<C> block of 58 methods
across 4120 lines — the largest production monolith in the workspace. Extract
cohesive concern groups into focused submodules, leaving mod.rs (now ~2000
lines) with the struct, constructors, and the main agent loop:

- shutdown.rs        — session-summary generation + orphaned tool-use flush
- subagent_commands.rs — /agent command handlers, sub-agent polling, and
                         spawn-context assembly (estimate_parts_size,
                         trim_parent_messages, sanitize_parent_messages)
- skill_reload.rs    — skill / instruction hot-reload
- config_reload.rs   — config overlay hot-reload
- hooks_dispatch.rs  — CwdChanged / FileChanged hook dispatch + the
                       McpManagerDispatch adapter

The three SideQuest eviction methods move into the existing sidequest.rs.

The shared impl block is now split across files, so 14 cross-module
entrypoints are bumped to pub(super); all other moved methods stay private.
No public API change. The trim_parent_messages test import is updated to the
new subagent_commands path. Remove the stale do-not-split TODO superseded by
this change.

Closes #4923
@bug-ops
bug-ops force-pushed the refactor/4923-core-agent-mod-split branch from b7a6fff to 98190ae Compare June 6, 2026 15:15
@bug-ops
bug-ops merged commit c98d1f7 into main Jun 6, 2026
32 checks passed
@bug-ops
bug-ops deleted the refactor/4923-core-agent-mod-split branch June 6, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation refactor Code refactoring without functional changes rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(core): agent/mod.rs is 4120 lines — split into focused submodules

1 participant