refactor(core): split agent/mod.rs monolith into focused submodules#4933
Merged
Conversation
bug-ops
force-pushed
the
refactor/4923-core-agent-mod-split
branch
from
June 6, 2026 15:11
f60af29 to
b7a6fff
Compare
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
force-pushed
the
refactor/4923-core-agent-mod-split
branch
from
June 6, 2026 15:15
b7a6fff to
98190ae
Compare
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.
Summary
crates/zeph-core/src/agent/mod.rsheld a singleimpl<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.rsis reduced to ~2000 lines, retaining only the struct definition,DispatchFlow, constructors, the main agent loop (runand its dispatch helpers), and the free helper functions used by the loop.Extracted submodules
shutdown.rssubagent_commands.rs/agentcommand handlers (list/status/approve/deny/spawn/cancel/resume), sub-agent polling, and bounded spawn-context assembly (incl. theestimate_parts_size/trim_parent_messages/sanitize_parent_messageshelpers)skill_reload.rsconfig_reload.rshooks_dispatch.rsCwdChanged/FileChangedlifecycle hook dispatch + theMcpManagerDispatchMCP-bridge adapterThe three
SideQuesteviction methods (maybe_sidequest_eviction,sidequest_apply_pending,sidequest_schedule_next) move into the existingsidequest.rs.Visibility
The shared
implblock is now split across files. Because a private inherent method defined inagent::<submodule>is no longer visible to the parentagentmodule or its siblings, the 14 methods called cross-module are bumped topub(super); every method called only within its own new module stays private. No public API change —pub/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 newsubagent_commandspath. The staledo-not-splitTODO at the top ofmod.rs(which predated and is superseded by this work) is removed.Validation
cargo +nightly fmt --check— cleancargo clippy --workspace --all-targets -- -D warnings— cleanRUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features desktop,ide,server,chat,pdf,scheduler --locked— cleancargo nextest run --workspace --lib --bins— 10530 passed, 21 skippedcargo test --doc -p zeph-core— 32 passedRUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps -p zeph-core— builds (one pre-existing unrelated warning inbuilder.rs)Closes #4923