Switch freely between live `clai2` web sessions, with running, queued, and asking dots

Merged
MP
2mo ago
+861-438

Part 7 of the clai2 multi-session stack (#10468 → #10469 → #10477 → #10485 → #10494 → #10495 → this PR → #10541 → #10549). Based on #10495. No linked issue: requested by the CLAI maintainer.

Why. #10495 lets one clai2 --web process drive many live sessions, but the page still showed one session at a time, opened another only when no turn ran, and showed others read-only behind "A turn is running. You can switch to this session once it ends."

What changes (web UI only, src/pydantic_clai2/web-ui/, plus the rebuilt bundle)

  • Clicking any sidebar session opens it live (POST /api/sessions/{id}/open) and watches it ({"type": "watch", "sessions": [id]}), whatever else runs. Switching back mid-stream shows the turn still streaming, from a fresh snapshot. The running-turn preview and its banner are gone; read-only stays for sessions CLAI cannot open (folder gone).
  • state.ts: page-wide state plus the shown session's Chat, a live map from the live message, and a watch handshake (show, give_up, fallback) that survives reconnects, sessions that close, and /new typed in the session. Settings dialogs stay page-wide.
  • api.ts: sessionApi(id) with the per-session routes (input, interrupt, complete, model, switch, questions), given to the composer, run switches, question cards and Monty through SessionContext. open, new and fork return the ID to show.
  • Sidebar: a dot per live session: running (pulsing), queued (ringed), asking (amber), each with aria-label/title, in dark and light. Collapsed groups show the most urgent one. Live sessions cannot be deleted.
  • Esc and the stop button interrupt only the shown session. Each session keeps its own draft.
  • clai2_web_README.md: switching, dots, and Esc.

Verification. npx tsc --noEmit, npm run build (bundle committed), pytest tests/clai2/test_web.py tests/clai2/test_web_sessions.py tests/clai2/test_web_client.py (72 passed). The project has no JS test runner. Headed Chromium (Playwright) against an isolated clai2 --web with a slow streaming test model and two scratch repos:

  • Three sessions streamed at once across both repos. Switching among them mid-stream showed each one still growing.
  • The dots showed running and queued (a second prompt sent mid-turn), plus asking on a question.
  • Esc stopped only the shown session; the others kept streaming.
  • Each session's tools read its own AGENTS.md; / completion listed only its own repo's skill; /mcp trust status named its own .mcp.json.
  • The process cwd (lsof) never changed.
  • Also checked: fork, /new and /exit typed in a session, a server restart while a non-default session was shown, and /web from a terminal.

What changes for existing users. clai2 --web users can switch between sessions freely while turns run; the terminal and /web behave as before.

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.