Move a `clai2` session's runtime out of `_app.py` into `SessionRuntime` over a shared `ClaiProcess`
Merged
MP
2mo ago+1694+1694+0123456789012345678901234567890123456789-1496-1496-0123456789012345678901234567890123456789
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)andClaiProcess.open(store=None), what every session in a process shares. For now it holds the settings and conversation stores, and eachcreate_shellcall opens its own; PR 3 makeschatshare one and adds the shared services. - New
models/resolver.py:ModelResolver(formerly_app._ModelResolver). _app.pykeepschat, startup resume,/reloadand/updaterestarts, andopen_stock_agent.pydantic_clai2.chat,create_agent,open_stock_agentandDEFAULT_PLUGINSare unchanged.- Tests import (and monkeypatch) the moved names from their new modules, and the
/reloadtest edits the module the text now lives in;FILE_MAP.mdlists 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 readssend_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"),/forkand/forks,/resumeof the fork, double Esc, Ctrl-C twice to exit.clai2 --web: skills follow/workspaceand 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.