feat(subagents): stable color assignment for spawned agents#282
Merged
Conversation
Slice of Phase 8.10 (color manager piece). Each spawned subagent now gets one of eight stable color slots (red, blue, green, yellow, purple, orange, pink, cyan) for the duration of the session, mapped through the per-theme `subagent_*` slots PR #275 added. - New `services::subagent_colors` module with `SubagentColor` enum and `SubagentColorManager`. Assignment is deterministic (insertion-order counter, not hashmap iteration), idempotent per id, and wraps after the eighth subagent. - `AppState` carries a shared manager; `ToolContext` and `TaskContext` plumb it through so the Agent tool and `LocalAgentExecutor` see the same allocation table. - `AgentTool` resolves a stable subagent id (input field or fresh uuid), assigns a color, and propagates both to the child via `AGENT_CODE_SUBAGENT_ID` / `AGENT_CODE_SUBAGENT_COLOR`. - `LocalAgentExecutor` registers a `LocalAgent` task entry stamped with the assigned color (new `TaskManager::register_with_color`) so `/tasks` shows the run with its color. - `format_task_list` paints the description with the matching `subagent_*` theme slot via the new `subagent_theme_color` bridge in `ui::theme`. - Tests: manager unit tests (8-distinct, wrap, idempotent, for_id None, Send+Sync, concurrent), theme-bridge round-trip across every advertised theme, `/tasks` colorization, and a manager↔ task-manager integration test. Fork/resume and the coordinator memory snapshot pieces of 8.10 are out of scope for this PR.
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
Slice of Phase 8.10 (subagent color manager piece). Spawned subagents now receive a stable, distinct color across the session — visible in
/tasksand propagated to the child via env vars for downstream renderers.services::subagent_colorsmodule:SubagentColor(8 stable slots) andSubagentColorManager(deterministic insertion-order assignment, idempotent per id, wraps after the eighth).AppStateowns one sharedArc<SubagentColorManager>;ToolContextandTaskContextplumb it through.AgentToolresolves a stable subagent id (input field or uuid), assigns a color, propagatesAGENT_CODE_SUBAGENT_IDandAGENT_CODE_SUBAGENT_COLORto the child.LocalAgentExecutorpre-assigns a color, registers aLocalAgentqueue entry stamped with it (newTaskManager::register_with_color), and drives the entry to a terminal status when the run finishes./tasksrendering colorizes LocalAgent descriptions through the newsubagent_theme_colorbridge inui::theme. Shell-task rows stay plain./tasks display
After spawning four subagents in a single session the table looks roughly like:
Each agent's description is painted with its assigned
subagent_*slot from the active theme (the comments on the right are illustrative — there's no extra column). Shell tasks keep the plain rendering they have today.Out of scope (deferred follow-ups)
tui::render_turn_summary— needs the subagent id plumbed throughToolEntry/ tool-call events. Invasive enough that I shipped the manager +/tasksintegration without it; flagging for a follow-up.Test plan
cargo check --all-targetscargo clippy --all-targets -- -D warningscargo fmt --all -- --checkcargo test --tests— all new tests green; the only pre-existing failures arebwrap_*sandbox tests that need real user namespaces in the runner (unrelated to this change).for_idreturnsNonefor unknown ids, concurrent assignment yields 8 distinct slots,Send + Synccompile-time check.subagent_theme_color: every variant maps to its matchingsubagent_*slot across every advertised theme.LocalAgentqueue entries with their colors, confirmformat_task_listsurfaces both rows.