feat: improve diff comment composer agent picker legibility (#5189)
What
Addresses part of #5189 — making it clearer which terminal session a diff comment will be sent to.
The picker (AgentPickerSelect) and the closed SelectTrigger historically rendered each existing session as agentId · terminalId[0:6] (e.g. claude · a1b2c3). Two problems the issue calls out:
agentIdis generic — multiple sessions running the same agent all read asclaude/codex, so the headline doesn't disambiguate them.terminalId.slice(0, 6)is an opaque hash —a1b2c3maps to nothing the user sees elsewhere.
Scope of this PR (option 4 from the issue)
This implements the same-agent disambiguation piece, which is fully self-contained and unit-testable today. When more than one live session shares an agent, the picker now appends a stable, human-countable ordinal — claude #1, claude #2 (ordered most-recent-first, matching the composer's existing sort) — to both the dropdown option and the closed trigger. The short id is kept as a secondary hint. Single-session agents are unchanged (no #1 noise).
The fuller "show the visible tab/pane title" correlation (options 1/2) is intentionally not included here: TerminalAgentBinding carries no human-readable title, and resolving terminalId → tab/pane depends on the desktop tab-state index tracked in #5126 / #5108. This PR is a strict improvement that doesn't block on those.
Implementation
- New pure helper
buildSessionLabels(sessions)→Map<terminalId, SessionLabel>, plusformatSessionName(label). Pure and deterministic, so option and trigger render identically. AgentPickerSelectconsumes it via a memo and passes the resolved label intoExistingSessionOption.
Tests
buildSessionLabels.test.ts (bun:test):
- documents the reported same-agent ambiguity (two
claudesessions collapse to one headline), - verifies distinct ordinals are assigned and the resulting names are unique,
- verifies single-session agents get no ordinal,
- verifies ordinals are numbered per agent following input (recency) order,
- verifies the short-id hint and the empty-input case.
All 6 tests pass; bun run lint clean; desktop typecheck shows no new errors.
Refs #5189
Summary by cubic
Disambiguates same-agent terminal sessions in the diff comment composer by adding a stable ordinal to session names in the agent picker and trigger (e.g., "claude #1", "claude #2"). Addresses #5189; the 6-char short id stays as a hint, and single-session agents show no ordinal.
- New Features
- Number multiple sessions per agent by recency (most recent = #1) and use the same label in the dropdown and closed trigger.
- Add
buildSessionLabelsandformatSessionNameutilities and wire them intoAgentPickerSelect; includes tests for ordinals and edge cases.