Give `clai2` plugins the session's directory as `PluginHost.workspace` and stop changing the working directory after startup
Part 1 of the clai2 multi-session stack (this PR → #10469 → #10477 → #10485 → #10494 → #10495 → #10504 → #10541 → #10549). Based on main. No linked issue: requested by the CLAI maintainer.
Why. The web UI will run several live sessions in one process, each in its own folder. Today clai2 --web moves a session to another folder with os.chdir, and plugins, MCP servers, ! commands and @ completion read the process's working directory. With two sessions in one process, one chdir would move the other. This PR gives every consumer its session's directory explicitly and stops changing the working directory after startup. Nothing else changes yet.
What changes
- New public
PluginHost.workspace -> Path: the session's directory.PluginHost(..., workspace: Callable[[], Path] = Path.cwd)reads it lazily, so it follows/workspaceand/resumemoves.PluginLoader(..., workspace=)passes it to every host. Commands(*, workspace: Callable[[], Path] = Path.cwd):@path completion lists the session's directory.coderreads skills and agent folders fromhost.workspace; MCP project files come from it, and a stdio server starts inhost.workspace / (server.cwd or '').!commandand!!commandrun withcwd=the session's directory (run_shell_command(..., cwd=),run_in_terminal(..., cwd=)).observability'suser_tag: git-emailreads Git's email in the session's repository (git_email(*, cwd: Path))./workspaces createand the web orchestrator'sworkspace_createresolve a relative repository in the session's directory (Workspaces.create(..., base: Path | None = None)).SessionWorkspace.moveandclai2 --web --resumeno longer callos.chdir;create_shell(..., workspace=)sets the session's directory. Worktree cleanup at exit keeps its existing order.open_stock_agentgives plugins andCommandsitsworkspaceinstead of the process's directory.PLUGINS.mddocumentshost.workspaceand says plugins must not readPath.cwd()or callos.chdir;reference.md,customization.mdandFILE_MAP.mdfollow.
Verification.
- New tests:
test_relative_paths_complete_in_the_workspace,test_the_sessions_directory_is_searched_not_the_processs,test_skills_come_from_the_workspaces_repository,test_commands_run_in_the_sessions_directory,test_git_email_is_the_repositorys_own,test_a_relative_repository_is_in_the_sessions_directory(and its kind-default twin), and a parametrized stdiocwdcase intest_tools_without_start_and_empty_server.test_web.pyandtest_web_parts.pyassertPath.cwd()stays at launch whilesession.workspacemoves. - 100% branch coverage of changed lines; pyright and ruff clean.
- Real run: isolated
clai2 --web(scratch XDG dirs, fail keyring) in repoalpha./api/completeoffered onlyalpha-skill; after/workspace ../beta, onlybeta-skill.lsof -pshowed the process's cwd stayedalphathroughout.
What changes for existing users. Nothing in the terminal. Under clai2 --web, a session moved with /workspace or /resume works in its new folder as before, but the process's working directory stays where CLAI started.
- 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.