Give `clai2` plugins the session's directory as `PluginHost.workspace` and stop changing the working directory after startup

Merged
MP
2mo ago
+338-120

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 /workspace and /resume moves. PluginLoader(..., workspace=) passes it to every host.
  • Commands(*, workspace: Callable[[], Path] = Path.cwd): @ path completion lists the session's directory.
  • coder reads skills and agent folders from host.workspace; MCP project files come from it, and a stdio server starts in host.workspace / (server.cwd or '').
  • !command and !!command run with cwd= the session's directory (run_shell_command(..., cwd=), run_in_terminal(..., cwd=)).
  • observability's user_tag: git-email reads Git's email in the session's repository (git_email(*, cwd: Path)).
  • /workspaces create and the web orchestrator's workspace_create resolve a relative repository in the session's directory (Workspaces.create(..., base: Path | None = None)).
  • SessionWorkspace.move and clai2 --web --resume no longer call os.chdir; create_shell(..., workspace=) sets the session's directory. Worktree cleanup at exit keeps its existing order.
  • open_stock_agent gives plugins and Commands its workspace instead of the process's directory.
  • PLUGINS.md documents host.workspace and says plugins must not read Path.cwd() or call os.chdir; reference.md, customization.md and FILE_MAP.md follow.

Verification.

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.