4.9 KiB
Phase 1 Step 14 — Implementation Notes
Status
Done.
Plan reference
- Plan:
docs/PHASE-1-IMPLEMENTATION-PLAN.md - Section: "Step 14: Migrate
Inputconstructors and REPL"
Summary
Eliminated GlobalConfig from every file except config/mod.rs
(where the type is defined). Input constructors take
&RequestContext. REPL holds Arc<RwLock<RequestContext>> instead
of GlobalConfig. Reedline components read from shared
RequestContext. Sync helpers deleted. to_global_config() deleted.
macro_execute takes &mut RequestContext. Implemented
RequestContext::use_agent. Added MCP loading spinner, MCP server
tab completions, and filtered internal tools from completions.
What was changed
Files modified
-
src/config/input.rs— constructors take&RequestContextinstead of&GlobalConfig.capture_input_configandresolve_roleread fromRequestContext/AppConfig. -
src/config/request_context.rs— addeduse_agent()method. Deletedto_global_config()andsync_mcp_from_registry(). Added MCP loading spinner inrebuild_tool_scope. Added configured MCP servers to.set enabled_mcp_serverscompletions. Filtereduser__*,mcp_*,todo__*,agent__*from.set enabled_toolscompletions. -
src/repl/mod.rs—Replstruct holdsArc<RwLock<RequestContext>>, noGlobalConfigfield.askandrun_repl_commandtake&mut RequestContextonly. Deletedsync_ctx_to_config,sync_config_to_ctx,sync_app_config_to_ctx,reinit_mcp_registry. -
src/repl/completer.rs— holdsArc<RwLock<RequestContext>>instead ofGlobalConfig. -
src/repl/prompt.rs— holdsArc<RwLock<RequestContext>>instead ofGlobalConfig. -
src/repl/highlighter.rs— updated if it heldGlobalConfig. -
src/config/macros.rs—macro_executetakes&mut RequestContextinstead of&GlobalConfig. -
src/main.rs— allto_global_config()calls eliminated. Agent path usesctx.use_agent(). Macro path passes&mut ctxdirectly.
Methods added
RequestContext::use_agent(app, name, session, abort_signal)— callsAgent::init, sets up MCP viarebuild_tool_scope, sets agent/rag/supervisor, starts session.
Methods deleted
RequestContext::to_global_config()RequestContext::sync_mcp_from_registry()- REPL:
sync_ctx_to_config,sync_config_to_ctx,sync_app_config_to_ctx,reinit_mcp_registry
UX improvements
- MCP loading spinner restored in
rebuild_tool_scope .set enabled_mcp_servers<TAB>shows configured servers frommcp.json+ mapping aliases.set enabled_tools<TAB>hides internal tools (user__*,mcp_*,todo__*,agent__*)
GlobalConfig remaining
Only src/config/mod.rs (13 references): type definition, legacy
Config::use_agent, Config::use_session_safely,
Config::use_role_safely, Config::update, Config::delete — all
dead code. Step 15 deletes them.
Post-implementation review (Oracle)
Oracle reviewed all REPL and CLI flows. Findings:
-
AbortSignal not threaded through rebuild_tool_scope — FIXED.
rebuild_tool_scope,bootstrap_tools,use_role,use_session,use_agent,updatenow all thread the realAbortSignalthrough to the MCP loading spinner. Ctrl+C properly cancels MCP server loading. -
RwLock held across await in REPL — KNOWN LIMITATION.
Repl::runholdsctx.write()for the duration ofrun_repl_command. This is safe in the current design because reedline's prompt/completion is synchronous (runs between line reads, before the write lock is taken). Phase 2 should refactor to ownedRequestContext+ lightweight snapshot for reedline. -
MCP subprocess leaks — NOT AN ISSUE.
rmcp::RunningServicehas aDropGuardthat cancels the tokio cancellation token on Drop. Servers are killed when theirArc<ConnectedServer>refcount hits zero. -
MCP duplication — NOT AN ISSUE after Step 14. The
initial_globalsync was removed. MCP runtime is populated only byrebuild_tool_scope→McpFactory::acquire, which deduplicates viaWeakreferences. -
Agent+session MCP override — PRE-EXISTING behavior, not a regression. When an agent session has its own MCP config, it takes precedence. Supervisor child agents handle this explicitly via
populate_agent_mcp_runtime. -
Stale Input in tool loop — PRE-EXISTING design. Input captures state at construction time and uses
merge_tool_resultsfor continuations. Tools communicate results via tool results, not by mutating the session mid-turn. Not a regression. -
Auto-compression — REPL does inline compression in
ask. CLI directive path relies on session save which happens inafter_chat_completion. Consistent with pre-migration behavior.
Verification
cargo check— 6 dead-code warnings (legacy Config methods)cargo test— 63 passed, 0 failed