feat(desktop): agent tree in the sidebar agents chip and the pane subagents menu

KI
2mo ago
+1638-205

Links

Summary

  • New shared AgentTree component: agents → subagents → nested subagents with connector rails, fold chevrons, state glyph, harness title, activity line and elapsed time. Arrow keys move, ←/→ fold, Enter opens.
  • The sidebar agents chip's card renders that tree with an "N ended" section and a Show tree in sidebar switch; switch on renders single-line rows under the workspace's activity line. The chip's +N takes the worst child state's colour.
  • The pane header's "N subagents" menu renders the same tree. The two hand-rolled row lists are deleted.

Why / Context

#7481: nested subagents are hidden, stateless and unmanageable. The chip's card showed one level with every child labelled "Subagent", and the pane menu a flat list where every row said "Running". This is the rendering half of the change; the data comes from the stacked host PR.

How It Works

  • buildAgentTree(roots) (pure, tested) nests by parentSubagentId with a cycle guard, re-roots a child whose parent left the roster, omits the agent row when there is a single terminal agent, and promotes an ended parent back into the live tree while any descendant still runs (Claude launches Agent-tool children in the background, so the parent's turn ends first).
  • AgentTreeRow draws rails per ancestor level; the sidebar variant is single-line with type, activity and "Parent unknown" in a tooltip; card and menu variants carry the activity line.
  • useDashboardSidebarWorkspaceAgentTree keeps the existing chip gate (2+ agents or any subagent, live or recently ended) and computes the worst child state for the +N.
  • The switch is sidebarState.agentTreeShown on the workspace local-state row (healed to false), with the same session-only zustand fallback the sidebar tab uses for a rowless local main (stores/sidebar-agent-tree.ts, not persisted, so no registry entry).
  • formatCompactDuration joins @superset/i18n/format for "42s" / "3m" / "2h" via Intl.NumberFormat unit narrow.
  • Six new strings translated into all 16 non-English catalogs; bun run check:i18n passes.

Manual QA Checklist

Dev desktop from this worktree, driven over CDP, Claude Code 2.1.270 in a real workspace, three fan-out prompts (screenshots on the page).

  • Chip shows 2 +5 with two terminal agents and five live children
  • Card: three-level tree, titles from Task descriptions, activity lines, elapsed, ended section, switch
  • Switch on → rows under the workspace; type/activity in tooltip; "10 ended" folded by default
  • Switch survived a relaunch of the dev app (local-state row)
  • Pane menu: same tree rooted at the terminal, "5 live · N ended" header
  • Clicking a nested row opened its transcript pane beside the parent; a second click focused the existing pane
  • No console errors during the session
  • +N yellow / red (no child needed input or failed in the bypass-permissions session)
  • Codex end to end

Testing

  • bunx tsc --noEmit -p apps/desktop/tsconfig.json (only the pre-existing generated file-icons manifest error remains)
  • bun test desktop: AgentTree, DashboardSidebar, CollectionsProvider, persisted-keys suites → 275 pass
  • bun test in packages/i18n → 160 pass (incl. formatCompactDuration)
  • bun run check:i18n
  • bunx biome check on the touched directories

Design Decisions

  • Switch on the card, not a chip click: the chip's click already toggles the card; a labelled switch says what it does and makes the state legible.
  • Inline rows, not a bigger card: a card closes when the pointer leaves, which is when a supervisor wants to watch five children. Rows are not sortable so they never interfere with workspace drag.
  • Popover instead of DropdownMenu for the pane menu: Radix menu key handling would fight the tree's roving focus.

Known Limitations

  • The focused pane's row is not highlighted (selectedKey is wired but nothing supplies it yet).
  • Terminal agents read Idle while their background children run; that is Claude's main-loop Stop, the children's state is in the tree.

Follow-ups

  • Persist the roster in host.db so the tree survives a host-service restart.
  • Terminal children (parentTerminalId) so CLI-spawned agents appear in the tree with full stop/restart/input.
  • A Settings → Sidebar default for the switch.

https://claude.ai/code/session_01GojHrw82odVV1wVhJQdgaM


Summary by cubic

Renders nested subagents as a tree in the sidebar agents chip card and the terminal pane's "N subagents" menu, replacing the flat one-level lists that labelled every child "Subagent" and "Running" (fixes #7481).

  • Adds a shared AgentTree component (agents → subagents → nested subagents) with connector rails, fold chevrons, status glyph, harness title, activity line, and elapsed time; arrow keys move, ←/→ fold, Enter opens the node's transcript or terminal.
  • Builds the tree from parentSubagentId with a cycle guard; orphans re-root under the agent; an ended parent stays dimmed in the live tree while any descendant still runs.
  • The chip's +N takes the worst child state's colour; a "Show tree in sidebar" switch keeps the tree open as single-line rows under the workspace, persisted in the workspace's local-state row (session-only fallback for rowless local mains).
  • The pane menu now uses a popover (Radix menu key handling fought tree roving focus) and shows "N live · M ended" in the header.
  • Adds formatCompactDuration for "42s"/"3m"/"2h" and translates six new strings into all 16 non-English catalogs.
  • Depends on the host-service roster PR (agent-tree-roster) for the parent pointer, status, and activity this tree renders.