Repository navigation
tui: centralize agent rebuild in one rebuild_agent helper - #201
Merged
gi-dellav merged 1 commit intoJul 19, 2026
Merged
Conversation
Item 2 of "Control flow and duplication" from gi-dellav#186. Every main-agent rebuild path used to hand-roll the same completion_model / resolve_temperature / resolve_extra_body + build_agent preamble (~15 copies across app, event_handler, slash commands). Introduce AgentBuildCtx, a borrow bundle of the build inputs with a single rebuild_agent(model_id, reasoning_enabled) method, obtainable from UiContext (main loop, mid-turn compaction) and SlashCtx (slash commands), or built from owned clones in the startup prebuild task. Converted: ensure_agent (start_main_run, mid-turn compaction), /loop and worktree respawns, worktree startup/exit, MCP reconnect, prebuild, SlashCtx::rebuild_agent(_with_client), switch_to_prompt_model, apply_prompt_model, handle_compress, /model switching. Behavior preserved: advisor syncs keep their order, /loop and worktree respawns keep hardcoded reasoning=true, model switches build against the not-yet-committed model id, MCP lazy-connect stays at startup. Refs gi-dellav#186
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.
Implements item 2 of Control flow and duplication from #186:
What changed
Every main-agent rebuild path hand-rolled the same
completion_model/resolve_temperature/resolve_extra_body+build_agentpreamble (~15 copies acrossapp,event_handler, and slash commands).Introduced
AgentBuildCtx(src/ui/state.rs): a borrow bundle of the build inputs with a singlerebuild_agent(model_id, reasoning_enabled)method, obtainable fromUiContext::agent_build_ctx()(main loop, mid-turn compaction) andSlashCtx::agent_build_ctx()(slash commands), or built from owned clones in the startup prebuild task.Converted call sites:
ensure_agent— used bystart_main_run, mid-turn compaction, worktree-merge runhandle_compress— /compress and auto/mid-turn compactionSlashCtx::rebuild_agent/rebuild_agent_with_client/switch_to_prompt_model,apply_prompt_model— all slash-command rebuilds (/model, /provider, /add, /mode, prompt-model switches, ...)event_handler.rs)app.rs)apply_model/handle_model(slash/providers.rs)Net: −312 / +149 lines. Out of scope and untouched: subagent and /btw builders, non-TUI one-shot/ACP modes.
Behavior preserved
reasoning = trueVerification
cargo fmtcargo test— 608 passed (default features)cargo test --features advisor,hooks,memory— 784 passedcargo test --no-default-features— 510 passedcargo install --path . --debugOKRefs #186