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
- Request.
plugin.WorkspaceRequest{Workspace, Path, Checkout{Mode, Base, Branch, Name}}is the one structure every channel fills: onEvent.Workspace(a Transport, e.g. the HTTP API'sworkspacefield, the console's current directory asPath) or onDecision.Workspace(a Trigger, e.g. the chat trigger's/ws). A new decision actionworkspacebinds or shows the conversation's workspace without starting a run. - Providers. A workspace tool plugin (today
localenv) may implementplugin.WorkspaceProvider:Workspaces(ctx)lists named workspaces with their scope (users, conversation kinds, connections). Names are unique across a runtime'suses. - 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
Pathonly on connections whoseallow_pathsis on; it defaults to the transport manifest'spaths: true(the console declares it). An unknown or disallowed name in an event is refused atSubmit, so an API caller gets a 4xx and no run starts. A connection default that no provider declares stopsserve. - What tools see. The resolved
plugin.WorkspaceRef{Name, Path, Checkout, Key}is stored with the run and passed asCallContext.Workspace; the provider turns it into a directory. An empty ref is the scratch directory, so behavior without configuration is unchanged. - 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,osandshell. (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.) - Bindings. The Host keeps
workspace_bindings(connection, conversation, thread, and the sender in groups, as the owner chose) and clears a binding at/new. - Hand-back (amended 2026-11-18, slice C). A decision action
workspace_done(the chat trigger's/done) ends the conversation's worktree task;/newwith a worktree bound does the same. A provider may implement the optionalplugin.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 returnsplugin.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
WorkspaceRequestand nothing else; new kinds of workspace are provider plugins; routing is a separate role (a later slice). - ◆
CallContext,EventandDecisiongain optional fields: JSON-compatible, old plugins ignore them. - ◆Worktrees, hand-back and the router build on these fields in later slices.