Move a `clai2` session's runtime out of `_app.py` into `SessionRuntime` over a shared `ClaiProcess`

Merged
MP
2mo ago
+1694-1496

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

Why. To run several live sessions in one process, CLAI needs one object per live session and one for what the process shares. Today both live in _app.py (about 1,650 lines) as create_shell and _Shell. This PR moves them out without changing behaviour, so the next PRs can build N runtimes over one process.

What changes

  • New runtime/session_runtime.py: SessionRuntime (formerly _app._Shell), one live session with its prompt loop, built-in /commands, plugin loader, input queue and turns; create_shell(..., process: ClaiProcess | None = None) builds one. The code is moved, not rewritten.
  • New runtime/process.py: ClaiProcess(*, store: SettingsStore, conversations: SqliteConversationStore) and ClaiProcess.open(store=None), what every session in a process shares. For now it holds the settings and conversation stores, and each create_shell call opens its own; PR 3 makes chat share one and adds the shared services.
  • New models/resolver.py: ModelResolver (formerly _app._ModelResolver).
  • _app.py keeps chat, startup resume, /reload and /update restarts, and open_stock_agent. pydantic_clai2.chat, create_agent, open_stock_agent and DEFAULT_PLUGINS are unchanged.
  • Tests import (and monkeypatch) the moved names from their new modules, and the /reload test edits the module the text now lives in; FILE_MAP.md lists the new modules.

All three modules are internal; no public API changes.

Verification.

  • The existing suite is the oracle: the moved code runs unchanged under every test that drove _Shell.
  • New test_a_runtime_without_a_terminal_serves_input_over_the_process_stores: a runtime with no terminal reads send_input, runs a turn, and saves it in the process's conversation store with its workspace.
  • Real run in tmux (scratch XDG dirs, fail keyring): prompt, /reload ("Conversation preserved"), /fork and /forks, /resume of the fork, double Esc, Ctrl-C twice to exit. clai2 --web: skills follow /workspace and the process's cwd stays put.

What changes for existing users. Nothing.

  • 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.