fix(desktop): select the agent tab when opening a CLI-created workspace

AA
1d ago
+81-10

What & why

Fixes the remaining case of #9260. #9344 fixed tab order for workspaces created from the desktop New Workspace flow. Workspaces created outside the desktop (superset ws create --agent …, automations, orchestration) still open on the setup tab.

Those workspaces never reach appendLaunchesToPaneLayout. useAutoAdoptBackgroundSessions gives each running terminal a tab, oldest first, so the agent does land in tab 1. But addTab always makes the new tab active, and the hook restored the previous selection only when the layout already had tabs. In a new workspace the last adopted tab, which is setup, stayed selected.

The new adoptTerminalPanes util keeps the user's tab when one exists. In an empty layout it selects the oldest terminal, which is the agent because the host starts an independent agent before the setup terminal (#7041).

Not in this PR: on this path the adopted tabs still show the raw command / "Terminal" instead of "Claude" / "Workspace Setup", because the labels exist only in the create result. That can be a follow-up.

How I tested it

Local dev stack (setup.local.sh), test repo with a .paradev/config.json setup script (sleep 5), driven over CDP:

FlowBeforeAfter
Desktop New Workspace + ClaudeClaude tab 1, selectedunchanged
superset ws create --agent claude, then open from sidebarClaude tab 1, Setup tab selectedClaude tab 1, Claude selected

The before/after for the CLI flow was confirmed by reading the pane store's activeTabId over CDP and with screenshots of the dev app:

Before: CLI-created workspace opens on the setup tab (tab 1 is the Claude terminal, tab 2 the setup terminal)

After: CLI-created workspace opens on the Claude tab

Desktop New Workspace flow (unchanged): Claude first and selected

  • New unit tests: adoptTerminalPanes.test.ts (empty layout selects the oldest terminal; an existing selection is kept)
  • bun run lint, desktop bun run typecheck, desktop bun test (9411 pass, 0 fail)

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs
  • I have signed the CLA (the bot asks on your first PR)

Summary by CodeRabbit

  • Bug Fixes
    • Background terminal sessions are added in the intended order. When existing tabs are present, their active selection is preserved; otherwise, the first new terminal is selected.