ADR 0009doc/{zh,en}/adr/0009-workspaces.md

ADR 0009: Workspaces in the Host Contract

Status: accepted, 2026-11-18 (P83; the owner's decisions in the workspace design, section 9).

Status: accepted, 2026-11-18 (P83; the owner's decisions in the workspace design, section 9).

Context

A tool call finds its directory from CallContext alone: the run, the person, the conversation and the connection. A request cannot say "work on orquelo", "in a new worktree from main" or "in my terminal's current directory", and the model is not told which project or checkout it is in. The design resolves a workspace per run from the request, the conversation's binding, a router, the connection's default, or today's scratch directory. That needs a few generic fields in the Host contract, the same for every channel.

Decision

  1. Request. plugin.WorkspaceRequest{Workspace, Path, Checkout{Mode, Base, Branch, Name}} is the one structure every channel fills: on Event.Workspace (a Transport, e.g. the HTTP API's workspace field, the console's current directory as Path) or on Decision.Workspace (a Trigger, e.g. the chat trigger's /ws). A new decision action workspace binds or shows the conversation's workspace without starting a run.
  2. Providers. A workspace tool plugin (today localenv) may implement plugin.WorkspaceProvider: Workspaces(ctx) lists named workspaces with their scope (users, conversation kinds, connections). Names are unique across a runtime's uses.
  3. Resolution and trust. The Host resolves each run's workspace in the design's order, checks the person against the workspace's scope, and accepts Path only on connections whose allow_paths is on; it defaults to the transport manifest's paths: true (the console declares it). An unknown or disallowed name in an event is refused at Submit, so an API caller gets a 4xx and no run starts. A connection default that no provider declares stops serve.
  4. What tools see. The resolved plugin.WorkspaceRef{Name, Path, Checkout, Key} is stored with the run and passed as CallContext.Workspace; the provider turns it into a directory. An empty ref is the scratch directory, so behavior without configuration is unchanged.
  5. What the model sees. The provider's environment context item adds the workspace name, kind, checkout, branch and base, and a short git snapshot, beside today's workspace, os and shell. (2026-12-04, context refactor slice 3: the git snapshot of status lines and the last commit is no longer sent; the branch is, also for a repository that is no named workspace.)
  6. Bindings. The Host keeps workspace_bindings (connection, conversation, thread, and the sender in groups, as the owner chose) and clears a binding at /new.
  7. Hand-back (amended 2026-11-18, slice C). A decision action workspace_done (the chat trigger's /done) ends the conversation's worktree task; /new with a worktree bound does the same. A provider may implement the optional plugin.WorkspaceFinisher{FinishWorkspace(ctx, cc, task)}: it commits the changes on the task branch locally with the repository's git identity (never pushing), removes a worktree with nothing new and keeps one with commits, and returns plugin.WorkspaceHandback{Changed, Branch, Commit, Path, Files, Diff}. The Host tells the person in their language and sends the diff as a file. For now only builtin providers can offer it; the process-plugin protocol does not carry it yet.

Consequences

  • ◆Channels added later fill WorkspaceRequest and nothing else; new kinds of workspace are provider plugins; routing is a separate role (a later slice).
  • ◆CallContext, Event and Decision gain optional fields: JSON-compatible, old plugins ignore them.
  • ◆Worktrees, hand-back and the router build on these fields in later slices.