Show one live `clai2` session at a time in the terminal, and `/resume` one open in the browser instead of forking it
Merged
MP
2mo ago+1340+1340+0123456789012345678901234567890123456789-156-156-012345678901234567890123456789
Part 8 of the clai2 multi-session stack (#10468 → #10469 → #10477 → #10485 → #10494 → #10495 → #10504 → this PR → #10549). Based on #10504. No linked issue: requested by the CLAI maintainer.
Why. With /web from a terminal, the browser opens more live sessions in the same process, but the terminal could only drive the one it started with. /resume of a session open in the browser forked it as busy elsewhere, and Ctrl-C, the editor, and restarts did not know which session they belonged to. This also lands the terminal driver split deferred from PR 2.
What changes
Terminal(ui/prompt/terminal.py) owns the console,LivePrompt, line prompt, transcript, input history, and pasted images, and shows one live session at a time.SessionRuntimekeeps no terminal-only state:terminal,shown_in(),show_live(),restart_refusal() -> str | None./resume ID, or a pick in the resume browser, of a conversation another live session holds shows that session, mid-turn too, instead of forking it. The session shown before stays live and can be closed for idleness. Prompts queued for a session stay its own.- Ctrl-C and Esc follow the shown session (
Interrupts.focus(signals=)). Hidden sessions print nowhere, and an answer streaming when its session is shown goes on in the terminal. /reloadand/updaterun only in the shown session. They are refused while other sessions run turns ("2 other sessions are running turns; try again when they finish") and from a shown session in another folder; Settings > About says so too.- An
N livetoolbar segment appears only when more than one session is live. chat(..., settings_for=...)setsprocess.live.build, so the web UI opens sessions beside the terminal's, each with its folder's project settings.clai2 --webkeeps its terminal on its first session.LiveRuntimes.runtime(conversation_id)anddriving(runtime);serving()raises a lone error unwrapped.
Verification.
tests/clai2/test_terminal_focus.py: a mid-turn focus switch without a fork, Ctrl-C ownership across switches, refusals whileFunctionModelturns are blocked on events, restarts from the shown session, idle closing of the hidden first session, queued prompts, streaming after a switch, a failed reload,chatwith per-folder settings, and--webkeeping its session.- Changed lines have 100% branch coverage locally; one line is covered by the
reload_script.pysubprocess test. - Real run in tmux with a scratch config and headed Playwright:
/web, a slow turn started in a browser session,/reloadrefused,/resume IDshowed it mid-turn without a fork, Esc and Ctrl-C interrupted it,/reloadaccepted once idle, and Ctrl-C twice exited.
What changes for existing users. Nothing with one live session. With /web from a terminal, /resume of a session open in the browser shows it instead of copying it.
- 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.