From 60f13bbe36f1b8c7864b4ca4f4afeda5d9d21659 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 16:19:17 +0800 Subject: [PATCH 01/28] docs: design the normal, codemode and shell tool modes Add docs/design/agent-tool-modes.md and index it. A mode is the unit of action a Session gives its model: one tool call, one program or one shell session. The mode decides which declarations a request carries, while the branch's adopted tool set stays mode-independent, so switching takes effect with the next request. Refs #2135 --- docs/INDEX.md | 1 + docs/design/agent-tool-modes.md | 362 ++++++++++++++++++++++++++++++++ 2 files changed, 363 insertions(+) create mode 100644 docs/design/agent-tool-modes.md diff --git a/docs/INDEX.md b/docs/INDEX.md index 13b16e09be..4883bd4acf 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -10,6 +10,7 @@ This index is navigation. Delivery status lives in issues, not here. - [CLI feature list](feature-list.md) - [Model preferences and Agent configuration](design/model-configuration.md) - [Model startup](design/model-startup.md): temporary model, effort and multi-protocol connections with branch/member/compaction inheritance +- [Agent tool modes](design/agent-tool-modes.md) (#2135): normal, codemode and shell as one user-scope choice, the visible/exposed tool surface, and the shell tool's place in the product assembly - [Model failures](design/model-failures.md)([中文](zh/design/model-failures.md)): the failure kind, the fact on the terminal event, who words the line, and retry (#1197) - [模型请求重试与任务续接方案](design/research/model-retry-recovery.md)(中文,#1210):请求重试的可见性、独立恢复能力的边界及所有者合同需求 - [服务面:跨语言形状的策略、盘点与第一批改造](design/service-faces.md)(中文,Draft),装配现状见[生成的服务目录](architecture/rust-agent/generated/catalog.md)。 diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md new file mode 100644 index 0000000000..bdf6d75737 --- /dev/null +++ b/docs/design/agent-tool-modes.md @@ -0,0 +1,362 @@ +# Agent tool modes: normal, codemode and shell + +Status: Draft. Scope: process (the default and the availability), Session (the mode and the tool +surface), branch (the mode a request pins). +Issue: [#2135](https://github.com/arcships/dim/issues/2135). Delivery status belongs in the issue. + +Today the model has one way to act: one tool call per decision, with every tool declared before the +first request. This design gives the product three mutually exclusive working styles — one call, one +program, one shell session — so a person can choose how the agent acts, not just which tools it +sees. + +A mode is therefore a rule over the Session's tool set: it decides the unit of action and, from +that, which declarations a request carries. It enables and disables no plugin: a Session whose tool +set lacks the mode's entry tool runs `normal`, and every tool that is registered stays registered. + +## 1. Why a tool-mode choice + +### 1.1 One way to act + +The model has one way to act today: each decision calls one tool, and every tool is declared before +the first request. Some work does not have that shape. A task may need the model to find out which +tools exist, call several of them in a loop, branch on their results, and collect one answer. As +single calls that is many model round trips, and every intermediate result has to re-enter the +context. + +Two capabilities in this repository already offer another shape: Code Mode runs one bounded program +per call ([CodeMode](plugins/CodeMode.md)), and the persistent shell runs commands in one shell +session that keeps its working directory, environment and jobs (`ShellSession`). A third, the +ordinary tool set, offers the opposite: one precise call at a time, each one its own decision. The +product exposes only the third. `codemode` is installed beside the direct tools, so the model keeps +choosing the direct tools — as it does in this very session — and the persistent shell exists only +in the minimal-execution profile. + +### 1.2 What the modes change: the unit of action + +A mode is the unit of action the model is given, not a subset of tools. Each already exists in the +repository; the shell is the one without a product form. + +| Mode | Unit of action | What one step can do | Product form today | +| --- | --- | --- | --- | +| `normal` | one tool call | one precise action, its own approval, one result | the product | +| `codemode` | one program | discover tools, call them, branch, loop, aggregate; child results stay out of the model context | the `codemode` tool beside the direct tools | +| `shell` | one shell session | compose commands; working directory, environment and jobs persist across calls | the minimal-execution profile only | + +In `codemode` and `shell` the ordinary tool declarations do not appear. That absence is a property +of the mode — the model acts through one surface — not the goal of the change. Fewer declarations +per request, fewer round trips and less context churn follow from it; the 23 tools declared today +carry about 12 kB of description and about 20 kB with schemas, but saving that is a result, not the +requirement. + +### 1.3 The one real risk: how well the model uses the mode + +The modes change the unit of action, and whether that is better depends on the model: + +- **Writing the program.** `codemode` pays off only if the model writes a correct program: it reads + the tool set (`tools.list`, `tools.describe`), handles `ToolCallError`, bounds its own loops and + aggregates the results. A model trained mostly on direct tool calls may write one-call programs, + guess an argument shape, or fail on syntax, and then the mode is slower than the tools it + replaced. +- **Writing the pipeline.** `shell` pays off only if the model is fluent in the platform's shell + dialect: quoting and escaping, the difference between an interactive and a non-interactive + command, when to background and when to wait. A command that waits for input occupies the shell. +- **Fitting the task.** A task that needs one edit gains nothing from a program or a shell session. + The default `normal` and the ability to switch keep that cheap, but the mode is a product bet on + how people work. + +The mechanism cannot make a model better at this. What it provides is the material to judge and to +fail visibly: each child call is a Timeline fact, a program has hard bounds (time, memory, calls, +output), and a failure returns its partial result. Whether a model is good enough is measured with +the evaluation harness, not argued here, and the design claims no success rate. + +### 1.4 The modes are exclusive + +A mode exists only if the model faces one unit of action. With both `codemode` and the direct tools +the model uses the direct tools, as it does today, and `codemode` is just another declaration. With +both `execute` and the file tools the model mixes two write paths (shell redirection and +`write`/`edit`), and "the command is the state" stops holding. Exclusivity is what makes each mode +mean something, not a simplification. + +### 1.5 Alternatives considered + +| Alternative | Why not | +| --- | --- | +| Keep `codemode` as one more tool | The model keeps choosing the direct tools, so the orchestrator is never the way it works | +| A tool picker in settings | Changes which tools exist, not the unit of action; still one call per decision | +| A mode that loads or unloads plugins | Structural configuration changes loader rows and reloads them, which contradicts "independent of plugin enablement" | +| One daemon profile per mode | A different process and home, no shared sessions, and no way to switch with a setting | + +## 2. Product behavior + +| Mode | The model sees | How it works | +| --- | --- | --- | +| `normal` (default) | every tool the Session mounts, except `codemode` and `execute` | one tool call per decision | +| `codemode` | `codemode` only | one program uses `tools.list` / `tools.describe` / `tools.call` | +| `shell` | `execute` only | commands in one persistent shell | + +Rules that hold in every mode: + +- Approval and Permission are unchanged. Each call is admitted under the called tool's own risk, + including a Code Mode child call; approving `codemode` approves no child. +- Tool sources are unchanged. MCP servers, extension tools and other registered tools still + contribute to the Session's tool set; the mode decides what the model sees and, in `codemode`, + what a program may call. It does not enable or disable a source. +- Client surfaces are unchanged. Mention search (`session.files`), command-output paging, skills, + approvals and settings work in every mode. +- `shell` mode has no `ask_user` tool, so its model cannot ask the operator a question. It can still + be stopped, and an `execute` approval still reaches the operator. + +## 3. Who owns the mode + +The mode belongs to a Session, and the operator owns it. A mode is a capability choice — `shell` +removes the file tools, `codemode` hides every other declaration — so nobody else may change it +behind the operator's back. + +| Situation | Rule | Why | +| --- | --- | --- | +| A new Session from a client | starts in the mode the request names, or in the user default when it names none | the operator should not re-choose for every Session | +| A running Session | the operator can switch it at any time; the next request declares the new mode, and a turn in flight keeps the mode it pinned | otherwise a change of style means abandoning the conversation | +| A branch (line) | has no mode of its own; every line of a Session runs the Session's mode | a line is the same agent; a line in another mode would hand the agent tools the operator excluded | +| A member Session | starts in its creator Session's current mode, and the operator can switch it like any Session | the member is the same agent doing delegated work; the model must not decide how the agent acts | +| The model | never chooses or changes a mode | it is the operator's choice of capability | + +A switch does not rewrite the history the model already has: the next request carries the new +declarations. + +## 4. The tool surface rule + +The Session's tools are one set with one owner. `ToolRegistry` already owns the mount list and the +Session's tool set ([ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md)), so it +also owns this projection. Four terms: + +- **callable**: what the Session mounts: host tools, registered tools and each source's sets, after + `SessionConfig.tools` and `excluded_tools`. The branch adopts and pins this set, and it does not + change when the mode does. +- **entry tool**: `codemode` → `codemode`, `shell` → `execute`, `normal` → none. +- **exposed**: what a call of this mode may reach. +- **visible**: what the request declares to the model. + +| Mode | exposed | visible | entry tool absent from callable | +| --- | --- | --- | --- | +| `normal` | callable − {`codemode`, `execute`} | same as exposed | — | +| `codemode` | callable | {`codemode`} | the Session runs `normal` | +| `shell` | {`execute`} | {`execute`} | the Session runs `normal` | + +- Only `visible` reaches the model request, its token accounting and compaction. `exposed` never + appears in a prompt, a declaration or the usage counter. +- A request pins the mode it was prepared under, together with the callable set it pins today. The + declarations are the projection of that pinned set, so a switch takes effect with the next + request and needs no re-adoption: the branch's configuration, the version pins and the source + sets stay as they are. Each request is itself a `model/call` fact carrying its declarations, so a + restore keeps what past requests declared and the next request projects with the current mode. +- A call outside the request's pinned `exposed` is refused as an unknown tool. The check reads the + pinned mode, so a turn in flight keeps the mode it started with even if the Session switches + meanwhile. +- A Code Mode program projects its list from the pinned set: `tools.list` and `tools.describe` are + `exposed − {codemode}`, and `tools.call` still resolves the pinned handler with Permission and + Approval ([CodeMode §1.4](plugins/CodeMode.md#14-tool-exposure-and-eligibility)). +- The mount list and an Agent profile's tool list narrow the surface and never widen it. `normal` + hides the two mode tools even when a list names them. + +Registration is dynamic, so the projection follows the current set and the current mode: a Session +whose entry tool is not registered, is withdrawn, or is excluded runs `normal` until it appears. +The two product clients also read which modes the daemon's assembly can serve: `hello.features` +carries `tool-mode.codemode` and `tool-mode.shell`, so a picker can mark an unavailable mode instead +of silently falling back. + +## 5. Configuration, creation and switching + +One declared Settings source, user scope only, is the default for new Sessions: + +```json +{"mode": "normal"} +``` + +- Registered by the App Server with a schema whose `mode` is an enum of the three values and whose + default is `normal`. It is served by `settings.read` / `settings.update`, the path the `execution` + source already uses, and the web entry adds `tool-mode` to `WEB_SETTINGS_SOURCES`. +- `session.create` may name the mode; absent uses the stored default. The field is additive and + advertised as `session.create.toolMode`, like `session.language`, because an older daemon rejects + an unknown field. +- The App Server records the mode in `SessionConfig.toolMode`. `normal` omits the member, so a + normal Session's stored configuration has the same bytes as before this field existed; an old + record reads as `normal`. A fork copies the value, and a restore starts from it. + +The mode is live for the Session's lifetime: + +- `ToolRegistry` holds the Session's current mode, initialised from the configuration. Requests + read it when they are prepared; nothing re-adopts a tool set when it changes. +- `session.tool_mode.get` returns `{mode, effective}`. `session.tool_mode.update` writes the stored + record (native storage only, as `session.language.update` does) and the live value, and refuses a + mode whose entry tool is absent, so a client cannot store a mode that is not in force. The pair is + advertised as `session.tool_mode`, like `session.language`. +- The model has no tool for this; it is a client method only. + +```text +default `tool-mode` ──┐ +session.create.mode ──┴─▶ SessionConfig.toolMode ──▶ ToolRegistry (live mode) + ├─ a request pins the mode ──▶ visible ──▶ model request, usage + └─ a call checks the pinned mode ──▶ exposed ──▶ admit or refuse + session.tool_mode.update ──▶ live mode + stored record +``` + +A member Session records the creating Session's current mode when it is created. Switching the +creator later does not change it: the member is its own Session with its own operator control. + +## 6. Shell mode's tool + +The product's local-execution profile does not mount the persistent shell today; `execute` exists +only in the minimal-execution profile, where `ShellTools` takes the Session's single `ToolHost`. + +- The product profile mounts `ShellSession` (branch) and the shell tool in every Session, so a + `shell` or `codemode` Session can use it. `ShellSession` starts no OS process until its first + command, so an unused mode costs a registered part, not a PTY. +- `execute` becomes an ordinary registered tool: the `ShellTools` Session part registers its + declaration and handler with `ToolRegistry` instead of providing `ToolHost`, and still resolves + the calling branch's `ShellSession` per call. The registry's registration already carries what a + host tool needs: declaration, handler, risk, mount-list filtering and per-Session lifetime. +- The minimal-execution profile, which has no other host tools, binds an empty host table. + +Why not conditional mounting: a Session has one `ToolHost` (`WorkspaceTools` provides it in the +product), and mounting `ShellTools` instead of `WorkspaceTools` for shell Sessions would also remove +the client methods that part registers (`session.files` mention search, command-output paging), so a +shell Session would lose client features that have nothing to do with its tools. + +## 7. What each mode still needs + +This design fixes the unit of action and the tool surface. Making each mode good is separate work: +the items below are follow-up requirements, not part of this change. + +`codemode`: + +- A failure manifest: when a program fails, the result names the child calls that ran and what they + declared, beyond today's "some child calls may have completed". +- Approval wording: the operator approves a program and then each child by its own risk, so the + prompt must say that and show the child calls as they happen. +- Grouping: v4 carries `parent_call_id`; the TUI and web must group a program's children under one + row, with their own detail. +- Asking the operator from inside a program, and a surface to answer it. +- Stopping a program and its children with a clear terminal result. +- Description and examples that teach the model when to call `tools.describe`, how to bound loops + and how to report a partial result. + +`shell`: + +- A command title for the background task list (`exec` takes one; `execute` does not today). +- Command-level approval wording and output paging; the permission command rules already name + `exec` and `execute`. +- Operator-visible shell state: the current directory, running jobs, and a command waiting for + input. +- Description and examples for the dialect, background work and timeouts. + +Both: + +- A mode-aware environment block: on Windows it carries guidance about `read`/`edit`/`write` text + encoding, which is noise in `shell` mode; the block should follow the surface the model has. + +## 8. Clients + +Both clients change this Session's mode and the default for new Sessions; both use the existing +revision CAS for the default and report a refused mode. + +- TUI: `/settings` gains a Tools group with two rows: "Tool mode" for this Session and "Default tool + mode" for new ones. The first calls `session.tool_mode.update`; the second writes the source. +- Web: the chat composer menu next to the permission menu switches this Session; the Agent defaults + page holds the default. + +```text +╭──────────────────────────────────────────────╮ +│ Settings esc close │ +│ Interface │ +│ › Theme System › │ +│ ... │ +│ Tools │ +│ › Tool mode Code Mode › │ +│ Default tool mode Code Mode › │ +│ Permissions │ +│ Permission Workspace write › │ +│ Process isolation › │ +│ ↑↓ move · enter select · esc close │ +╰──────────────────────────────────────────────╯ +``` + +The picker lists all three modes; a mode whose `hello.features` entry is absent is shown as +unavailable and cannot be saved. A switch takes effect from the next request; the row shows the +effective mode, so a mode that fell back to `normal` is not reported as in force. + +## 9. Compatibility + +- Stored records: an absent `toolMode` is `normal`; `normal` is omitted when serialized, so the + native store's text form does not change for existing Sessions. +- A fork copies its source's current configuration and therefore its mode. +- The v3 Code Mode gate stays. `excluded_tools` keeps `codemode` out of that Session's callable set, + the fallback rule makes the Session `normal`, and a v3 client can neither select nor receive Code + Mode ([child tool batches §2.6](appserver/child-tool-batches.md#26-app-server-code-mode-gate)). +- [CodeMode](plugins/CodeMode.md) and [child tool batches](appserver/child-tool-batches.md) change + in one respect: the `codemode` tool is offered in `codemode` mode, not to every v4 Session. The + child-event contract is unchanged. +- A Session restored from a record that predates this field becomes `normal`. A Session that used + the `codemode` tool therefore loses it on upgrade until the operator selects `codemode`. That is + the intended product change. + +## 10. Verification + +- Flow: create a Session in each mode (request field and default) and assert the request's + declarations: `normal` = the mounted tools without `codemode`/`execute`, `codemode` = only + `codemode`, `shell` = only `execute`. +- Flow: switch a running Session in each direction; the next request declares the new visible set, + the turn in flight finishes under its pinned mode, and a line created before the switch uses the + new mode at its next request. +- Flow: in `codemode` mode, a program calls a tool the model does not see; the child + `step/tool-call` and `step/tool-result` carry `parent_call_id`, and Permission admits the child by + its own risk. A call outside the pinned `exposed` set is refused as an unknown tool. +- Flow: fallback — an unavailable entry tool makes `session.tool_mode.update` refuse that mode, and + a mode that becomes unavailable while it is in force falls back to `normal` in `get`. +- Flow: a member created under `codemode` records it; switching the creator leaves the member + unchanged. +- Flow: restore a record without the field, and fork a Session; both keep `normal` and the source + mode respectively. Changing the default does not touch an open Session. +- Settings: `tool-mode` round trip with revision conflict, the web entry's allowed source, a web + component test for the composer menu and the default, and one tmux TUI case for the two rows and + the picker. +- No event type, envelope or stored format changes, so the fixture compatibility baseline is + untouched. + +## 11. Rule check + +- §1 Capability: no new Capability. `ToolRegistry` stays a Session part that publishes a tool set, + `ToolBinding` stays the branch part ToolExecution owns, and the App Server gains one declared + Settings source, one Session method pair and no business state. +- §4 rule 1: no module writes another owner's state; the registry owns the live mode, the App Server + owns the record and the client method. +- §4 rule 2: no handover of a Timeline object. +- §4 rule 3: no `before` callback. +- §4 rule 4: the mode is a configuration value and the two tool names it maps to belong to the + registry that applies them, not to core infrastructure. +- §4 rule 5: no batches. +- §4 rule 6: the visible set is exactly what the request declares; no new context path. +- §4 rule 7: parts coordinate through the Session configuration and the registry's own read. +- §4 rule 8: no infrastructure change; Timeline, Dispatcher, the event envelope, assembly and the + Session facades are untouched. +- §4 rule 9: the mode is Session configuration, not a Timeline fact, and follows + `session.language`: the current value lives in the registry, the durable copy in the stored + record. +- §7.1 for the live mode: the resource is the value; lifecycle is the Session's; the operations are + `get` and `update`, whose cancellation stops the record write, and whose one error is a mode whose + entry tool is absent. +- §7.1 for the settings source: the resource is one user document; it lives as long as the App + Server that registered it; the operations are the existing `settings.read` / `settings.update`. +- §7.2: no object or resource handle crosses an owner; no new service, and the mode methods join + the existing Session method face; the document is data and the conflict is the existing revision + CAS. +- [ADR 002](../adr/002-plugin-scope.md) D1: the default is process configuration, the mode is + Session configuration, and the pinned mode is branch state. D2: no wiring module. D3: ToolRegistry + keeps no hard dependency on Code Mode; an absent or excluded `codemode` falls back to `normal`. + D4: business configuration, read at creation and changed by its owner's operation. D5: the source + is a JSON document and the mode methods take data. +## 12. Requirements raised to mechanism owners + +None. The change stays within the owners that already exist: ToolRegistry projects its own set and +holds the live mode, ToolBinding pins the mode with the callable set, ToolExecution refuses a call +outside it, ContextUsage counts `visible`, the App Server owns the settings source, the stored +record and the Session methods, and each client owns its controls. From 0ba67d0cfc029d42ff90456f557c3ce5761bf26d Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 16:25:44 +0800 Subject: [PATCH 02/28] docs: keep the tool mode on the Session, without a default setting A separate default the operator sets is redundant with the switch: a new Session starts normal, a client sends the mode it last used, and session.create may name one. Availability falls back to normal instead of refusing the stored choice. Refs #2135 --- docs/design/agent-tool-modes.md | 99 +++++++++++++++------------------ 1 file changed, 45 insertions(+), 54 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index bdf6d75737..1fba9987fe 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -1,7 +1,7 @@ # Agent tool modes: normal, codemode and shell -Status: Draft. Scope: process (the default and the availability), Session (the mode and the tool -surface), branch (the mode a request pins). +Status: Draft. Scope: process (mode availability), Session (the mode and the tool surface), +branch (the mode a request pins). Issue: [#2135](https://github.com/arcships/dim/issues/2135). Delivery status belongs in the issue. Today the model has one way to act: one tool call per decision, with every tool declared before the @@ -114,7 +114,7 @@ behind the operator's back. | Situation | Rule | Why | | --- | --- | --- | -| A new Session from a client | starts in the mode the request names, or in the user default when it names none | the operator should not re-choose for every Session | +| A new Session from a client | starts in the mode the request names, or `normal` when it names none; the client sends the mode it last used | the operator should not re-choose for every Session | | A running Session | the operator can switch it at any time; the next request declares the new mode, and a turn in flight keeps the mode it pinned | otherwise a change of style means abandoning the conversation | | A branch (line) | has no mode of its own; every line of a Session runs the Session's mode | a line is the same agent; a line in another mode would hand the agent tools the operator excluded | | A member Session | starts in its creator Session's current mode, and the operator can switch it like any Session | the member is the same agent doing delegated work; the model must not decide how the agent acts | @@ -161,42 +161,38 @@ also owns this projection. Four terms: Registration is dynamic, so the projection follows the current set and the current mode: a Session whose entry tool is not registered, is withdrawn, or is excluded runs `normal` until it appears. The two product clients also read which modes the daemon's assembly can serve: `hello.features` -carries `tool-mode.codemode` and `tool-mode.shell`, so a picker can mark an unavailable mode instead -of silently falling back. +carries `session.tool_mode.codemode` and `session.tool_mode.shell`, so a picker can mark an +unavailable mode instead of silently falling back. ## 5. Configuration, creation and switching -One declared Settings source, user scope only, is the default for new Sessions: +The mode is Session configuration; there is no daemon-wide default to maintain. -```json -{"mode": "normal"} -``` - -- Registered by the App Server with a schema whose `mode` is an enum of the three values and whose - default is `normal`. It is served by `settings.read` / `settings.update`, the path the `execution` - source already uses, and the web entry adds `tool-mode` to `WEB_SETTINGS_SOURCES`. -- `session.create` may name the mode; absent uses the stored default. The field is additive and - advertised as `session.create.toolMode`, like `session.language`, because an older daemon rejects - an unknown field. +- `session.create` may name the mode; a Session created without one starts `normal`. The field is + additive and advertised as `session.create.toolMode`, like `session.language`, because an older + daemon rejects an unknown field. - The App Server records the mode in `SessionConfig.toolMode`. `normal` omits the member, so a normal Session's stored configuration has the same bytes as before this field existed; an old record reads as `normal`. A fork copies the value, and a restore starts from it. +- The product clients remember the last mode the operator chose in that client and send it when they + create a Session, so a new Session starts the way the operator last worked. That memory is client + state; it is not a daemon setting. The mode is live for the Session's lifetime: - `ToolRegistry` holds the Session's current mode, initialised from the configuration. Requests read it when they are prepared; nothing re-adopts a tool set when it changes. -- `session.tool_mode.get` returns `{mode, effective}`. `session.tool_mode.update` writes the stored - record (native storage only, as `session.language.update` does) and the live value, and refuses a - mode whose entry tool is absent, so a client cannot store a mode that is not in force. The pair is - advertised as `session.tool_mode`, like `session.language`. +- `session.tool_mode.get` returns `{mode, effective}`: the mode the operator chose and the one in + force. A mode whose entry tool is absent stays chosen and is not in force; that is the fallback. + `session.tool_mode.update` writes the stored record (native storage only, as + `session.language.update` does) and the live value. The pair is advertised as `session.tool_mode`, + like `session.language`. - The model has no tool for this; it is a client method only. ```text -default `tool-mode` ──┐ -session.create.mode ──┴─▶ SessionConfig.toolMode ──▶ ToolRegistry (live mode) - ├─ a request pins the mode ──▶ visible ──▶ model request, usage - └─ a call checks the pinned mode ──▶ exposed ──▶ admit or refuse +session.create.mode ──▶ SessionConfig.toolMode ──▶ ToolRegistry (live mode) + ├─ a request pins the mode ──▶ visible ──▶ model request, usage + └─ a call checks the pinned mode ──▶ exposed ──▶ admit or refuse session.tool_mode.update ──▶ live mode + stored record ``` @@ -256,13 +252,14 @@ Both: ## 8. Clients -Both clients change this Session's mode and the default for new Sessions; both use the existing -revision CAS for the default and report a refused mode. +Both clients switch this Session's mode and remember the choice for the Sessions they create next; +there is no default row to set. -- TUI: `/settings` gains a Tools group with two rows: "Tool mode" for this Session and "Default tool - mode" for new ones. The first calls `session.tool_mode.update`; the second writes the source. -- Web: the chat composer menu next to the permission menu switches this Session; the Agent defaults - page holds the default. +- TUI: `/settings` gains a Tools group with one row, "Tool mode", which calls + `session.tool_mode.update`. The chosen mode is kept in the client's own settings and sent on the + next Session creation. +- Web: the chat composer menu next to the permission menu switches this Session; the same choice is + kept in the browser's local state and sent on creation. ```text ╭──────────────────────────────────────────────╮ @@ -272,7 +269,6 @@ revision CAS for the default and report a refused mode. │ ... │ │ Tools │ │ › Tool mode Code Mode › │ -│ Default tool mode Code Mode › │ │ Permissions │ │ Permission Workspace write › │ │ Process isolation › │ @@ -281,7 +277,7 @@ revision CAS for the default and report a refused mode. ``` The picker lists all three modes; a mode whose `hello.features` entry is absent is shown as -unavailable and cannot be saved. A switch takes effect from the next request; the row shows the +unavailable and cannot be chosen. A switch takes effect from the next request, and the row shows the effective mode, so a mode that fell back to `normal` is not reported as in force. ## 9. Compatibility @@ -301,7 +297,7 @@ effective mode, so a mode that fell back to `normal` is not reported as in force ## 10. Verification -- Flow: create a Session in each mode (request field and default) and assert the request's +- Flow: create a Session in each mode (request field; absent = `normal`) and assert the request's declarations: `normal` = the mounted tools without `codemode`/`execute`, `codemode` = only `codemode`, `shell` = only `execute`. - Flow: switch a running Session in each direction; the next request declares the new visible set, @@ -310,23 +306,22 @@ effective mode, so a mode that fell back to `normal` is not reported as in force - Flow: in `codemode` mode, a program calls a tool the model does not see; the child `step/tool-call` and `step/tool-result` carry `parent_call_id`, and Permission admits the child by its own risk. A call outside the pinned `exposed` set is refused as an unknown tool. -- Flow: fallback — an unavailable entry tool makes `session.tool_mode.update` refuse that mode, and - a mode that becomes unavailable while it is in force falls back to `normal` in `get`. +- Flow: fallback — a mode whose entry tool is absent stays chosen in `get` and is reported as not in + force; the Session declares the `normal` surface. - Flow: a member created under `codemode` records it; switching the creator leaves the member unchanged. - Flow: restore a record without the field, and fork a Session; both keep `normal` and the source - mode respectively. Changing the default does not touch an open Session. -- Settings: `tool-mode` round trip with revision conflict, the web entry's allowed source, a web - component test for the composer menu and the default, and one tmux TUI case for the two rows and - the picker. + mode respectively. +- Clients: a web component test for the composer menu and the remembered choice, and one tmux TUI + case for the row and the picker. - No event type, envelope or stored format changes, so the fixture compatibility baseline is untouched. ## 11. Rule check - §1 Capability: no new Capability. `ToolRegistry` stays a Session part that publishes a tool set, - `ToolBinding` stays the branch part ToolExecution owns, and the App Server gains one declared - Settings source, one Session method pair and no business state. + `ToolBinding` stays the branch part ToolExecution owns, and the App Server gains one Session + method pair and no business state. - §4 rule 1: no module writes another owner's state; the registry owns the live mode, the App Server owns the record and the client method. - §4 rule 2: no handover of a Timeline object. @@ -342,21 +337,17 @@ effective mode, so a mode that fell back to `normal` is not reported as in force `session.language`: the current value lives in the registry, the durable copy in the stored record. - §7.1 for the live mode: the resource is the value; lifecycle is the Session's; the operations are - `get` and `update`, whose cancellation stops the record write, and whose one error is a mode whose - entry tool is absent. -- §7.1 for the settings source: the resource is one user document; it lives as long as the App - Server that registered it; the operations are the existing `settings.read` / `settings.update`. + `get` and `update`, whose cancellation stops the record write and which report the effective mode + rather than refusing one. - §7.2: no object or resource handle crosses an owner; no new service, and the mode methods join - the existing Session method face; the document is data and the conflict is the existing revision - CAS. -- [ADR 002](../adr/002-plugin-scope.md) D1: the default is process configuration, the mode is - Session configuration, and the pinned mode is branch state. D2: no wiring module. D3: ToolRegistry - keeps no hard dependency on Code Mode; an absent or excluded `codemode` falls back to `normal`. - D4: business configuration, read at creation and changed by its owner's operation. D5: the source - is a JSON document and the mode methods take data. + the existing Session method face; the parameters are data. +- [ADR 002](../adr/002-plugin-scope.md) D1: the mode is Session configuration and the pinned mode is + branch state. D2: no wiring module. D3: ToolRegistry keeps no hard dependency on Code Mode; an + absent or excluded `codemode` falls back to `normal`. D4: business configuration, read at creation + and changed by its owner's operation. D5: the mode methods take data. ## 12. Requirements raised to mechanism owners None. The change stays within the owners that already exist: ToolRegistry projects its own set and holds the live mode, ToolBinding pins the mode with the callable set, ToolExecution refuses a call -outside it, ContextUsage counts `visible`, the App Server owns the settings source, the stored -record and the Session methods, and each client owns its controls. +outside it, ContextUsage counts `visible`, the App Server owns the stored record and the Session +methods, and each client owns its control and its remembered choice. From 32ff639e2b30fee404d6e183ce9eee72c1a0d4f0 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 16:54:08 +0800 Subject: [PATCH 03/28] docs: separate top-level and child admission, and route the stop path Pin two allowlists per request: visible for top-level model calls and delegated for Code Mode child calls, so a hidden tool cannot be reached by naming it directly and discovery agrees with admission. State which retry and recovery paths keep the pin, and add the stop route for a persistent shell task plus the minimal profile's shell mode. Refs #2135 --- docs/design/agent-tool-modes.md | 76 +++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 1fba9987fe..2a1bec6377 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -115,7 +115,7 @@ behind the operator's back. | Situation | Rule | Why | | --- | --- | --- | | A new Session from a client | starts in the mode the request names, or `normal` when it names none; the client sends the mode it last used | the operator should not re-choose for every Session | -| A running Session | the operator can switch it at any time; the next request declares the new mode, and a turn in flight keeps the mode it pinned | otherwise a change of style means abandoning the conversation | +| A running Session | the operator can switch it at any time; the next model request declares the new mode, a request already prepared keeps its pin (including its own recovery), and a call already admitted finishes | otherwise a change of style means abandoning the conversation | | A branch (line) | has no mode of its own; every line of a Session runs the Session's mode | a line is the same agent; a line in another mode would hand the agent tools the operator excluded | | A member Session | starts in its creator Session's current mode, and the operator can switch it like any Session | the member is the same agent doing delegated work; the model must not decide how the agent acts | | The model | never chooses or changes a mode | it is the operator's choice of capability | @@ -126,35 +126,39 @@ declarations. ## 4. The tool surface rule The Session's tools are one set with one owner. `ToolRegistry` already owns the mount list and the -Session's tool set ([ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md)), so it -also owns this projection. Four terms: +Session's tool set ([ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md)), so it also +owns this projection. Four terms: - **callable**: what the Session mounts: host tools, registered tools and each source's sets, after `SessionConfig.tools` and `excluded_tools`. The branch adopts and pins this set, and it does not change when the mode does. - **entry tool**: `codemode` → `codemode`, `shell` → `execute`, `normal` → none. -- **exposed**: what a call of this mode may reach. -- **visible**: what the request declares to the model. +- **visible**: what the request declares and what a top-level model call may name. +- **delegated**: what a Code Mode child call may name. Their union is the request's exposed set, the + only tools the request binds. -| Mode | exposed | visible | entry tool absent from callable | +| Mode | visible (top-level) | delegated (child) | entry tool absent | | --- | --- | --- | --- | -| `normal` | callable − {`codemode`, `execute`} | same as exposed | — | -| `codemode` | callable | {`codemode`} | the Session runs `normal` | -| `shell` | {`execute`} | {`execute`} | the Session runs `normal` | - -- Only `visible` reaches the model request, its token accounting and compaction. `exposed` never +| `normal` | callable − {`codemode`, `execute`} | none | — | +| `codemode` | {`codemode`} | callable − {`codemode`} | the Session runs `normal` | +| `shell` | {`execute`} | none | the Session runs `normal` | + +- Admission is by call origin: a top-level call is admitted only inside `visible`, a child call only + inside `delegated`. Both then pass the called tool's own Permission and Approval. A call outside + its origin's set is refused as an unknown tool, even when the tool is bound. The origin is the + existing parent-call scope (`current_parent_call_id`), so a hidden tool cannot be reached by + naming it directly. +- A Code Mode program discovers and calls exactly the `delegated` set: `tools.list` and + `tools.describe` project it, and `tools.call` admits inside it. `codemode` itself is never + delegated, so a program cannot nest one. +- A request pins the mode it was prepared under, together with the callable set it pins today, and + derives both sets from that pin. A switch takes effect with the next request and needs no + re-adoption: the branch's configuration, the version pins and the source sets stay as they are. A + request retried through its own source (a budget recovery or a restart recovery) keeps the pin; a + continuation request is a new request and pins the current mode, as does the request that follows + a tool result. +- Only `visible` reaches the model request, its token accounting and compaction. `delegated` never appears in a prompt, a declaration or the usage counter. -- A request pins the mode it was prepared under, together with the callable set it pins today. The - declarations are the projection of that pinned set, so a switch takes effect with the next - request and needs no re-adoption: the branch's configuration, the version pins and the source - sets stay as they are. Each request is itself a `model/call` fact carrying its declarations, so a - restore keeps what past requests declared and the next request projects with the current mode. -- A call outside the request's pinned `exposed` is refused as an unknown tool. The check reads the - pinned mode, so a turn in flight keeps the mode it started with even if the Session switches - meanwhile. -- A Code Mode program projects its list from the pinned set: `tools.list` and `tools.describe` are - `exposed − {codemode}`, and `tools.call` still resolves the pinned handler with Permission and - Approval ([CodeMode §1.4](plugins/CodeMode.md#14-tool-exposure-and-eligibility)). - The mount list and an Agent profile's tool list narrow the surface and never widen it. `normal` hides the two mode tools even when a list names them. @@ -211,13 +215,25 @@ only in the minimal-execution profile, where `ShellTools` takes the Session's si declaration and handler with `ToolRegistry` instead of providing `ToolHost`, and still resolves the calling branch's `ShellSession` per call. The registry's registration already carries what a host tool needs: declaration, handler, risk, mount-list filtering and per-Session lifetime. -- The minimal-execution profile, which has no other host tools, binds an empty host table. +- The minimal-execution profile is `shell` by construction: its Sessions set `toolMode: shell`, + because `normal` would filter the only tool it has. Why not conditional mounting: a Session has one `ToolHost` (`WorkspaceTools` provides it in the product), and mounting `ShellTools` instead of `WorkspaceTools` for shell Sessions would also remove the client methods that part registers (`session.files` mention search, command-output paging), so a shell Session would lose client features that have nothing to do with its tools. +Stopping a task is a separate route. Today `session.exec.stop` resolves the branch's +`BackgroundExec` and stops a native process; a live persistent-shell command belongs to +`ShellSession`, which provides the branch's `dyn ExecStop`. With `execute` in the product, both +kinds exist in one Session: + +- The stop route asks `BackgroundExec` first and, when it does not know the id, the branch's + `ExecStop`, so either kind stops and writes its `exec/ended`. +- Both parts stay mounted when the mode changes, so a task started in `shell` or `codemode` can + still be stopped after the Session switches to `normal`. +- `session.stop` remains the turn's stop and stops no background task. + ## 7. What each mode still needs This design fixes the unit of action and the tool surface. Making each mode good is separate work: @@ -300,18 +316,24 @@ effective mode, so a mode that fell back to `normal` is not reported as in force - Flow: create a Session in each mode (request field; absent = `normal`) and assert the request's declarations: `normal` = the mounted tools without `codemode`/`execute`, `codemode` = only `codemode`, `shell` = only `execute`. -- Flow: switch a running Session in each direction; the next request declares the new visible set, - the turn in flight finishes under its pinned mode, and a line created before the switch uses the - new mode at its next request. +- Flow: in `codemode` mode a top-level call naming `read` is refused as an unknown tool even though + the request pinned it for children, and a child call to `codemode` is refused as outside + `delegated`. In `normal` mode a top-level call naming `codemode` or `execute` is refused. - Flow: in `codemode` mode, a program calls a tool the model does not see; the child `step/tool-call` and `step/tool-result` carry `parent_call_id`, and Permission admits the child by - its own risk. A call outside the pinned `exposed` set is refused as an unknown tool. + its own risk. +- Flow: switch a running Session in each direction; the next request declares the new visible set, + the request after a tool result uses the new mode, a request retried through its own source + (budget or restart recovery) keeps its pin, and a call already admitted finishes. - Flow: fallback — a mode whose entry tool is absent stays chosen in `get` and is reported as not in force; the Session declares the `normal` surface. - Flow: a member created under `codemode` records it; switching the creator leaves the member unchanged. - Flow: restore a record without the field, and fork a Session; both keep `normal` and the source mode respectively. +- Flow: stop a shell task with `session.exec.stop` after switching the Session to `normal`; the same + route stops a native process from `BackgroundExec`. The minimal-execution profile's Session runs + `shell` and keeps `execute`. - Clients: a web component test for the composer menu and the remembered choice, and one tmux TUI case for the row and the picker. - No event type, envelope or stored format changes, so the fixture compatibility baseline is From 1aa4f1c984784a84f3a083e27d64bdd4b202a518 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 19:11:27 +0800 Subject: [PATCH 04/28] docs: list the tools each product mode declares Read the surface rule for the assembled product profile: the normal list, the codemode delegation and the shell's single tool. The list is a reading of the rule, not a second source. Refs #2135 --- docs/design/agent-tool-modes.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 2a1bec6377..53d6b5aeef 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -94,6 +94,24 @@ mean something, not a simplification. | `codemode` | `codemode` only | one program uses `tools.list` / `tools.describe` / `tools.call` | | `shell` | `execute` only | commands in one persistent shell | +### The product profile's tool list + +The product profile mounts the same tool set in every Session; the mode decides what is declared and +what a program may call. These are the lists the assembly yields today. The rule in §4 derives them, +so a mount list, an Agent profile's tool list, an absent part, a disabled source or an unavailable +tool narrows them; this table is a reading, not a second source. + +| Mode | Declared (model-visible) | Delegated to Code Mode | +| --- | --- | --- | +| `normal` | `read`, `write`, `edit`, `glob`, `grep`, `exec`, `exec_stop`, `wait`, `recall`, `skill`, `branch`, `settings`, `ask_user`, `goal_update`, `events`, `schedule`, `wakeup`, `loop`, `image_understand`, `agent`, `plugin`, `web_fetch` | — | +| `codemode` | `codemode` | the `normal` list and `execute` | +| `shell` | `execute` | — | + +`normal` is today's list without `codemode`; `execute` is mounted by this change and stays hidden +there, so switching to `shell` or `codemode` uses the already-registered tool. `web_search`, when a +search service is usable, and every MCP tool follow the same rule: declared in `normal`, delegated +in `codemode`, hidden in `shell`. + Rules that hold in every mode: - Approval and Permission are unchanged. Each call is admitted under the called tool's own risk, From 6d4011c04ac7b9df79ec7e08d920219204808510 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 19:19:59 +0800 Subject: [PATCH 05/28] docs: classify tools by role instead of listing each mode's set A mode replaces the Workspace tools; the Session tools, the extension tools and the MCP tools stay in every mode. Each owner declares a tool's role at registration, so a new tool joins the rule without editing the design, and the shell and codemode modes keep the interaction surface the operator needs. Refs #2135 --- docs/design/agent-tool-modes.md | 86 ++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 53d6b5aeef..ea1ed0d4bb 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -42,11 +42,11 @@ repository; the shell is the one without a product form. | `codemode` | one program | discover tools, call them, branch, loop, aggregate; child results stay out of the model context | the `codemode` tool beside the direct tools | | `shell` | one shell session | compose commands; working directory, environment and jobs persist across calls | the minimal-execution profile only | -In `codemode` and `shell` the ordinary tool declarations do not appear. That absence is a property -of the mode — the model acts through one surface — not the goal of the change. Fewer declarations -per request, fewer round trips and less context churn follow from it; the 23 tools declared today -carry about 12 kB of description and about 20 kB with schemas, but saving that is a result, not the -requirement. +In `codemode` and `shell` the Workspace tool declarations do not appear; the Session tools stay +(§2). That absence is a property of the mode — the model does its workspace work through one +surface — not the goal of the change. Fewer declarations per request, fewer round trips and less +context churn follow from it; the Workspace tools declared today carry about 5 kB of that +description, but saving it is a result, not the requirement. ### 1.3 The one real risk: how well the model uses the mode @@ -88,29 +88,32 @@ mean something, not a simplification. ## 2. Product behavior -| Mode | The model sees | How it works | -| --- | --- | --- | -| `normal` (default) | every tool the Session mounts, except `codemode` and `execute` | one tool call per decision | -| `codemode` | `codemode` only | one program uses `tools.list` / `tools.describe` / `tools.call` | -| `shell` | `execute` only | commands in one persistent shell | - -### The product profile's tool list +A mode changes how workspace work is done. It does not change how the agent talks to the operator, +looks things up, or coordinates its own lines, so those tools stay in every mode. -The product profile mounts the same tool set in every Session; the mode decides what is declared and -what a program may call. These are the lists the assembly yields today. The rule in §4 derives them, -so a mount list, an Agent profile's tool list, an absent part, a disabled source or an unavailable -tool narrows them; this table is a reading, not a second source. +Tools fall into two roles, and the two entry tools stand apart. Each owner declares its tool's role +when it registers the tool; a tool that declares none is a Session tool. The role is not a field of +the model-facing declaration and is never sent to the model. -| Mode | Declared (model-visible) | Delegated to Code Mode | +| Role | What it does | Today's members | | --- | --- | --- | -| `normal` | `read`, `write`, `edit`, `glob`, `grep`, `exec`, `exec_stop`, `wait`, `recall`, `skill`, `branch`, `settings`, `ask_user`, `goal_update`, `events`, `schedule`, `wakeup`, `loop`, `image_understand`, `agent`, `plugin`, `web_fetch` | — | -| `codemode` | `codemode` | the `normal` list and `execute` | -| `shell` | `execute` | — | +| Workspace | reads, writes or runs in the workspace; a shell command does the same job | `read`, `write`, `edit`, `glob`, `grep`, `exec`, `exec_stop` | +| Session | talks to the operator, another line or agent, schedules this Session's own future, or gets information and configuration; also every extension and MCP tool | everything else | +| Entry | gives the mode its unit of action | `codemode`, `execute` | -`normal` is today's list without `codemode`; `execute` is mounted by this change and stays hidden -there, so switching to `shell` or `codemode` uses the already-registered tool. `web_search`, when a -search service is usable, and every MCP tool follow the same rule: declared in `normal`, delegated -in `codemode`, hidden in `shell`. +| Mode | Workspace tools | Session tools | Entry tool | +| --- | --- | --- | --- | +| `normal` (default) | declared | declared | — | +| `codemode` | hidden; a program may call them | declared | `codemode` declared | +| `shell` | hidden | declared | `execute` declared | + +- An entry tool is declared only in its own mode: `codemode` only in `codemode`, `execute` only in + `shell`. In `codemode` a program may call `execute` like any other tool it does not see. +- A Code Mode program may call every tool except `codemode`: the Workspace tools its model does not + see, and the Session tools it may also call directly. Interaction stays possible from the + program, and the child path already carries an `ask_user`. +- A new tool needs no edit here: a Workspace tool added by `WorkspaceTools` or `ShellTools` joins + the role and the rule, and a new capability's tool is a Session tool, declared in every mode. Rules that hold in every mode: @@ -121,14 +124,12 @@ Rules that hold in every mode: what a program may call. It does not enable or disable a source. - Client surfaces are unchanged. Mention search (`session.files`), command-output paging, skills, approvals and settings work in every mode. -- `shell` mode has no `ask_user` tool, so its model cannot ask the operator a question. It can still - be stopped, and an `execute` approval still reaches the operator. ## 3. Who owns the mode The mode belongs to a Session, and the operator owns it. A mode is a capability choice — `shell` -removes the file tools, `codemode` hides every other declaration — so nobody else may change it -behind the operator's back. +replaces the workspace tools with one shell, `codemode` hides them behind one program — so nobody +else may change it behind the operator's back. | Situation | Rule | Why | | --- | --- | --- | @@ -145,22 +146,24 @@ declarations. The Session's tools are one set with one owner. `ToolRegistry` already owns the mount list and the Session's tool set ([ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md)), so it also -owns this projection. Four terms: +owns this projection. Three terms: - **callable**: what the Session mounts: host tools, registered tools and each source's sets, after `SessionConfig.tools` and `excluded_tools`. The branch adopts and pins this set, and it does not change when the mode does. -- **entry tool**: `codemode` → `codemode`, `shell` → `execute`, `normal` → none. - **visible**: what the request declares and what a top-level model call may name. - **delegated**: what a Code Mode child call may name. Their union is the request's exposed set, the only tools the request binds. | Mode | visible (top-level) | delegated (child) | entry tool absent | | --- | --- | --- | --- | -| `normal` | callable − {`codemode`, `execute`} | none | — | -| `codemode` | {`codemode`} | callable − {`codemode`} | the Session runs `normal` | -| `shell` | {`execute`} | none | the Session runs `normal` | +| `normal` | every Workspace tool and every Session tool | none | — | +| `codemode` | every Session tool and `codemode` | every tool except `codemode` | the Session runs `normal` | +| `shell` | every Session tool and `execute` | none | the Session runs `normal` | +- The entry tools are their own role and are declared only in their own mode, and no other tool is + named here: the roles in §2 decide the sets, so a new Workspace tool joins the rule and a new tool + that declares no role is a Session tool in every mode. - Admission is by call origin: a top-level call is admitted only inside `visible`, a child call only inside `delegated`. Both then pass the called tool's own Permission and Approval. A call outside its origin's set is refused as an unknown tool, even when the tool is bound. The origin is the @@ -178,7 +181,7 @@ owns this projection. Four terms: - Only `visible` reaches the model request, its token accounting and compaction. `delegated` never appears in a prompt, a declaration or the usage counter. - The mount list and an Agent profile's tool list narrow the surface and never widen it. `normal` - hides the two mode tools even when a list names them. + hides the two entry tools even when a list names them. Registration is dynamic, so the projection follows the current set and the current mode: a Session whose entry tool is not registered, is withdrawn, or is excluded runs `normal` until it appears. @@ -332,14 +335,17 @@ effective mode, so a mode that fell back to `normal` is not reported as in force ## 10. Verification - Flow: create a Session in each mode (request field; absent = `normal`) and assert the request's - declarations: `normal` = the mounted tools without `codemode`/`execute`, `codemode` = only - `codemode`, `shell` = only `execute`. + declarations: `normal` declares the Workspace tools and the Session tools but not `codemode` or + `execute`; `codemode` declares `codemode` and the Session tools but no Workspace tool; `shell` + declares `execute` and the Session tools but no other Workspace tool. +- Flow: a tool registered without a role is declared in every mode; a Workspace tool added to the + host joins the rule, so `codemode` hides it and `shell` hides it. - Flow: in `codemode` mode a top-level call naming `read` is refused as an unknown tool even though the request pinned it for children, and a child call to `codemode` is refused as outside - `delegated`. In `normal` mode a top-level call naming `codemode` or `execute` is refused. -- Flow: in `codemode` mode, a program calls a tool the model does not see; the child - `step/tool-call` and `step/tool-result` carry `parent_call_id`, and Permission admits the child by - its own risk. + `delegated`. In `normal` and `shell` a top-level call naming a hidden Workspace tool is refused. +- Flow: in `codemode` mode, a program calls a Workspace tool the model does not see and a Session + tool the model does see; the child `step/tool-call` and `step/tool-result` carry `parent_call_id`, + and Permission admits each child by its own risk. - Flow: switch a running Session in each direction; the next request declares the new visible set, the request after a tool result uses the new mode, a request retried through its own source (budget or restart recovery) keeps its pin, and a call already admitted finishes. From 80e8cbd6b08306cd791037a59472c95c414c6e50 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 21:40:54 +0800 Subject: [PATCH 06/28] docs: give each mode its entry and the dialogue tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A mode declares its entry tool plus ask_user, recall and goal_update: a shell cannot ask the operator, read a compacted conversation or close a goal. Everything else is work — declared in normal, callable from a codemode program, hidden in shell — so codemode loses no reach and shell is deliberately the shell plus the dialogue. Refs #2135 --- docs/design/agent-tool-modes.md | 93 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index ea1ed0d4bb..c06fdc7677 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -42,11 +42,11 @@ repository; the shell is the one without a product form. | `codemode` | one program | discover tools, call them, branch, loop, aggregate; child results stay out of the model context | the `codemode` tool beside the direct tools | | `shell` | one shell session | compose commands; working directory, environment and jobs persist across calls | the minimal-execution profile only | -In `codemode` and `shell` the Workspace tool declarations do not appear; the Session tools stay -(§2). That absence is a property of the mode — the model does its workspace work through one -surface — not the goal of the change. Fewer declarations per request, fewer round trips and less -context churn follow from it; the Workspace tools declared today carry about 5 kB of that -description, but saving it is a result, not the requirement. +In `codemode` and `shell` the work tools are not declared; the three dialogue tools stay (§2). That +absence is a property of the mode — the model does its work through one surface — not the goal of +the change. Fewer declarations per request, fewer round trips and less context churn follow from +it; the work tools declared today carry most of that description, but saving it is a result, not the +requirement. ### 1.3 The one real risk: how well the model uses the mode @@ -88,32 +88,27 @@ mean something, not a simplification. ## 2. Product behavior -A mode changes how workspace work is done. It does not change how the agent talks to the operator, -looks things up, or coordinates its own lines, so those tools stay in every mode. +A mode decides how work is done. Three tools keep the dialogue itself working, so every mode +declares them: `ask_user` talks to the operator, `recall` reads the conversation a compaction +shortened, and `goal_update` settles the Session's goal. Everything else is work or coordination +that the mode either does itself or hides. -Tools fall into two roles, and the two entry tools stand apart. Each owner declares its tool's role -when it registers the tool; a tool that declares none is a Session tool. The role is not a field of -the model-facing declaration and is never sent to the model. - -| Role | What it does | Today's members | -| --- | --- | --- | -| Workspace | reads, writes or runs in the workspace; a shell command does the same job | `read`, `write`, `edit`, `glob`, `grep`, `exec`, `exec_stop` | -| Session | talks to the operator, another line or agent, schedules this Session's own future, or gets information and configuration; also every extension and MCP tool | everything else | -| Entry | gives the mode its unit of action | `codemode`, `execute` | - -| Mode | Workspace tools | Session tools | Entry tool | +| Mode | Declared | A program may call | Hidden | | --- | --- | --- | --- | -| `normal` (default) | declared | declared | — | -| `codemode` | hidden; a program may call them | declared | `codemode` declared | -| `shell` | hidden | declared | `execute` declared | - -- An entry tool is declared only in its own mode: `codemode` only in `codemode`, `execute` only in - `shell`. In `codemode` a program may call `execute` like any other tool it does not see. -- A Code Mode program may call every tool except `codemode`: the Workspace tools its model does not - see, and the Session tools it may also call directly. Interaction stays possible from the - program, and the child path already carries an `ask_user`. -- A new tool needs no edit here: a Workspace tool added by `WorkspaceTools` or `ShellTools` joins - the role and the rule, and a new capability's tool is a Session tool, declared in every mode. +| `normal` (default) | every tool except `codemode` and `execute` | — | `codemode`, `execute` | +| `codemode` | `codemode`, `ask_user`, `recall`, `goal_update` | every tool except `codemode` | — | +| `shell` | `execute`, `ask_user`, `recall`, `goal_update` | — | every other tool | + +- The three dialogue tools are what a mode cannot replace: a shell command cannot ask the operator, + read a compacted conversation or close a goal. A mode that dropped them would trap the agent in + its own work. +- `codemode` loses no reach. Its program calls every tool except `codemode`, so skills, images, the + web, MCP, lines, agents, schedules and settings stay available inside a program; they are simply + not declared, because the model is meant to do that work in one program. +- `shell` deliberately drops them. A shell Session has the shell and the dialogue, nothing else: no + skill tool, no image understanding, no web, no MCP, no lines or agents, no schedules, no settings + or plugin tool. Adding one back is a decision on this table, not a mechanism change. +- An entry tool is declared only in its own mode. Rules that hold in every mode: @@ -124,12 +119,14 @@ Rules that hold in every mode: what a program may call. It does not enable or disable a source. - Client surfaces are unchanged. Mention search (`session.files`), command-output paging, skills, approvals and settings work in every mode. +- A new tool is work by default: `normal` declares it, a `codemode` program may call it, and `shell` + hides it. A tool that belongs to the dialogue is added to the table above. ## 3. Who owns the mode The mode belongs to a Session, and the operator owns it. A mode is a capability choice — `shell` -replaces the workspace tools with one shell, `codemode` hides them behind one program — so nobody -else may change it behind the operator's back. +replaces the work tools with one shell, `codemode` hides them behind one program — so nobody else +may change it behind the operator's back. | Situation | Rule | Why | | --- | --- | --- | @@ -157,13 +154,12 @@ owns this projection. Three terms: | Mode | visible (top-level) | delegated (child) | entry tool absent | | --- | --- | --- | --- | -| `normal` | every Workspace tool and every Session tool | none | — | -| `codemode` | every Session tool and `codemode` | every tool except `codemode` | the Session runs `normal` | -| `shell` | every Session tool and `execute` | none | the Session runs `normal` | +| `normal` | every tool except `codemode` and `execute` | none | — | +| `codemode` | `codemode`, `ask_user`, `recall`, `goal_update` | every tool except `codemode` | the Session runs `normal` | +| `shell` | `execute`, `ask_user`, `recall`, `goal_update` | none | the Session runs `normal` | -- The entry tools are their own role and are declared only in their own mode, and no other tool is - named here: the roles in §2 decide the sets, so a new Workspace tool joins the rule and a new tool - that declares no role is a Session tool in every mode. +- The sets follow §2's table, and a new tool follows its default: declared in `normal`, callable in +a `codemode` program, hidden in `shell`. No other tool is named here. - Admission is by call origin: a top-level call is admitted only inside `visible`, a child call only inside `delegated`. Both then pass the called tool's own Permission and Approval. A call outside its origin's set is refused as an unknown tool, even when the tool is bound. The origin is the @@ -181,7 +177,7 @@ owns this projection. Three terms: - Only `visible` reaches the model request, its token accounting and compaction. `delegated` never appears in a prompt, a declaration or the usage counter. - The mount list and an Agent profile's tool list narrow the surface and never widen it. `normal` - hides the two entry tools even when a list names them. + and `shell` hide the other modes' entry tools even when a list names them. Registration is dynamic, so the projection follows the current set and the current mode: a Session whose entry tool is not registered, is withdrawn, or is excluded runs `normal` until it appears. @@ -335,17 +331,16 @@ effective mode, so a mode that fell back to `normal` is not reported as in force ## 10. Verification - Flow: create a Session in each mode (request field; absent = `normal`) and assert the request's - declarations: `normal` declares the Workspace tools and the Session tools but not `codemode` or - `execute`; `codemode` declares `codemode` and the Session tools but no Workspace tool; `shell` - declares `execute` and the Session tools but no other Workspace tool. -- Flow: a tool registered without a role is declared in every mode; a Workspace tool added to the - host joins the rule, so `codemode` hides it and `shell` hides it. -- Flow: in `codemode` mode a top-level call naming `read` is refused as an unknown tool even though - the request pinned it for children, and a child call to `codemode` is refused as outside - `delegated`. In `normal` and `shell` a top-level call naming a hidden Workspace tool is refused. -- Flow: in `codemode` mode, a program calls a Workspace tool the model does not see and a Session - tool the model does see; the child `step/tool-call` and `step/tool-result` carry `parent_call_id`, - and Permission admits each child by its own risk. + declarations: `normal` declares every tool except `codemode` and `execute`; `codemode` declares + `codemode`, `ask_user`, `recall` and `goal_update`; `shell` declares `execute` and the same three. +- Flow: a tool registered by a capability or an MCP server is declared in `normal`, callable from a + `codemode` program, and absent from a `shell` Session. +- Flow: in `codemode` mode a top-level call naming `read` or `skill` is refused as an unknown tool + even though the request pinned it for children, and a child call to `codemode` is refused as + outside `delegated`. In `shell` mode a top-level call naming `read` is refused. +- Flow: in `codemode` mode, a program calls a work tool the model does not see and a dialogue tool + it does see; the child `step/tool-call` and `step/tool-result` carry `parent_call_id`, and + Permission admits each child by its own risk. - Flow: switch a running Session in each direction; the next request declares the new visible set, the request after a tool result uses the new mode, a request retried through its own source (budget or restart recovery) keeps its pin, and a call already admitted finishes. From 8ca53c3a55ccd1729ef38a49e13002a8f9a57fc5 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 21:50:27 +0800 Subject: [PATCH 07/28] docs: keep only ask_user and recall beside each entry tool A mode declares its entry plus ask_user and recall. Everything else is the entry's job: codemode calls it from the program, and shell leaves it to another mode. Refs #2135 --- docs/design/agent-tool-modes.md | 108 ++++++++++++++++---------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index c06fdc7677..bd66cad562 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -42,10 +42,11 @@ repository; the shell is the one without a product form. | `codemode` | one program | discover tools, call them, branch, loop, aggregate; child results stay out of the model context | the `codemode` tool beside the direct tools | | `shell` | one shell session | compose commands; working directory, environment and jobs persist across calls | the minimal-execution profile only | -In `codemode` and `shell` the work tools are not declared; the three dialogue tools stay (§2). That +In `codemode` and `shell` only the entry and the two conversation tools are declared (§2). That absence is a property of the mode — the model does its work through one surface — not the goal of -the change. Fewer declarations per request, fewer round trips and less context churn follow from -it; the work tools declared today carry most of that description, but saving it is a result, not the +the change. Fewer declarations +per request, fewer round trips and less context churn follow from it; the tools declared today +carry about 12 kB of description and about 20 kB with schemas, but saving that is a result, not the requirement. ### 1.3 The one real risk: how well the model uses the mode @@ -88,27 +89,22 @@ mean something, not a simplification. ## 2. Product behavior -A mode decides how work is done. Three tools keep the dialogue itself working, so every mode -declares them: `ask_user` talks to the operator, `recall` reads the conversation a compaction -shortened, and `goal_update` settles the Session's goal. Everything else is work or coordination -that the mode either does itself or hides. +A mode declares its entry tool and two conversation tools, `ask_user` and `recall`: asking the +operator and reading a shortened conversation are what a mode cannot replace. | Mode | Declared | A program may call | Hidden | | --- | --- | --- | --- | | `normal` (default) | every tool except `codemode` and `execute` | — | `codemode`, `execute` | -| `codemode` | `codemode`, `ask_user`, `recall`, `goal_update` | every tool except `codemode` | — | -| `shell` | `execute`, `ask_user`, `recall`, `goal_update` | — | every other tool | - -- The three dialogue tools are what a mode cannot replace: a shell command cannot ask the operator, - read a compacted conversation or close a goal. A mode that dropped them would trap the agent in - its own work. -- `codemode` loses no reach. Its program calls every tool except `codemode`, so skills, images, the - web, MCP, lines, agents, schedules and settings stay available inside a program; they are simply - not declared, because the model is meant to do that work in one program. -- `shell` deliberately drops them. A shell Session has the shell and the dialogue, nothing else: no - skill tool, no image understanding, no web, no MCP, no lines or agents, no schedules, no settings - or plugin tool. Adding one back is a decision on this table, not a mechanism change. -- An entry tool is declared only in its own mode. +| `codemode` | `codemode`, `ask_user`, `recall` | every tool except `codemode` | — | +| `shell` | `execute`, `ask_user`, `recall` | — | every other tool | + +- `codemode` loses no reach: its program calls every tool except `codemode`, so skills, images, the + web, MCP, lines, agents, schedules, settings and the shell are all available inside a program. + They are not declared because the model does that work in one program. +- `shell` is the shell, plus the two conversation tools. It cannot load a skill, read an image, call + an MCP tool, open a line, start a member, schedule or manage settings and plugins. Those are the + mode's boundary: a task that needs one runs in another mode. +- What each entry tool must provide to carry its mode is §7. Rules that hold in every mode: @@ -119,8 +115,6 @@ Rules that hold in every mode: what a program may call. It does not enable or disable a source. - Client surfaces are unchanged. Mention search (`session.files`), command-output paging, skills, approvals and settings work in every mode. -- A new tool is work by default: `normal` declares it, a `codemode` program may call it, and `shell` - hides it. A tool that belongs to the dialogue is added to the table above. ## 3. Who owns the mode @@ -155,11 +149,11 @@ owns this projection. Three terms: | Mode | visible (top-level) | delegated (child) | entry tool absent | | --- | --- | --- | --- | | `normal` | every tool except `codemode` and `execute` | none | — | -| `codemode` | `codemode`, `ask_user`, `recall`, `goal_update` | every tool except `codemode` | the Session runs `normal` | -| `shell` | `execute`, `ask_user`, `recall`, `goal_update` | none | the Session runs `normal` | +| `codemode` | `codemode`, `ask_user`, `recall` | every tool except `codemode` | the Session runs `normal` | +| `shell` | `execute`, `ask_user`, `recall` | none | the Session runs `normal` | -- The sets follow §2's table, and a new tool follows its default: declared in `normal`, callable in -a `codemode` program, hidden in `shell`. No other tool is named here. +- The sets follow §2 and name no other tool: a new tool is declared in `normal`, callable from a + `codemode` program and hidden in `shell`, so it needs no edit here. - Admission is by call origin: a top-level call is admitted only inside `visible`, a child call only inside `delegated`. Both then pass the called tool's own Permission and Approval. A call outside its origin's set is refused as an unknown tool, even when the tool is bound. The origin is the @@ -251,37 +245,43 @@ kinds exist in one Session: still be stopped after the Session switches to `normal`. - `session.stop` remains the turn's stop and stops no background task. -## 7. What each mode still needs +## 7. What the entry tools must provide -This design fixes the unit of action and the tool surface. Making each mode good is separate work: -the items below are follow-up requirements, not part of this change. +A mode declares one tool, so that tool must carry everything the mode promises. The items below are +its requirements; the ones marked missing are follow-up work, not part of this change. `codemode`: -- A failure manifest: when a program fails, the result names the child calls that ran and what they - declared, beyond today's "some child calls may have completed". -- Approval wording: the operator approves a program and then each child by its own risk, so the - prompt must say that and show the child calls as they happen. -- Grouping: v4 carries `parent_call_id`; the TUI and web must group a program's children under one - row, with their own detail. -- Asking the operator from inside a program, and a surface to answer it. -- Stopping a program and its children with a clear terminal result. -- Description and examples that teach the model when to call `tools.describe`, how to bound loops - and how to report a partial result. - -`shell`: - -- A command title for the background task list (`exec` takes one; `execute` does not today). -- Command-level approval wording and output paging; the permission command rules already name - `exec` and `execute`. -- Operator-visible shell state: the current directory, running jobs, and a command waiting for - input. -- Description and examples for the dialect, background work and timeouts. - -Both: - -- A mode-aware environment block: on Windows it carries guidance about `read`/`edit`/`write` text - encoding, which is noise in `shell` mode; the block should follow the surface the model has. +- Discovery and call (`tools.list`, `tools.describe`, `tools.call`) over the request's pinned set, + everything except `codemode`. Exists. +- Asking the operator from inside a program: a child `ask_user` already carries `parent_call_id` and + is answerable through `session.question.respond`; the clients must show it under the program and + let the operator answer it. Missing on the client side. +- Progress: each child call is a `step/tool-call`/`step/tool-result` event; the client groups them + under the program row. The protocol exists (v4); grouping is a client feature. +- A failure manifest: a failed program names the child calls that ran and their effects, beyond + today's "some child calls may have completed". Missing. +- Stop: stopping the program ends its children and writes a terminal result that says what may have + run. Missing. +- Bounds on time, memory, calls and output. Exists. +- A description and examples that teach discovery, loop bounds and partial results. Missing. + +`execute`: + +- One shell per branch with cwd, environment, shell variables and jobs persisting across calls. + Exists. +- Background work with a task id, an output path and a wake on completion. Exists; a title for the + task list is missing. +- Foreground occupancy: a command still running at the timeout returns its output so far and keeps + the shell occupied. Exists. +- Stop through the route in §6, so a shell task stops and writes `exec/ended`. Missing. +- Pageable output, and operator-visible state: the current directory, the running job, a command + waiting for input. Output paging exists for native tasks; the state view is missing. +- A description and examples for the dialect, backgrounding and timeouts. Missing. + +The boundary is §2's: a shell Session cannot load a skill, read an image, call an MCP tool, open a +line, start a member, schedule or manage settings and plugins. A task that needs one runs in another +mode. ## 8. Clients @@ -332,7 +332,7 @@ effective mode, so a mode that fell back to `normal` is not reported as in force - Flow: create a Session in each mode (request field; absent = `normal`) and assert the request's declarations: `normal` declares every tool except `codemode` and `execute`; `codemode` declares - `codemode`, `ask_user`, `recall` and `goal_update`; `shell` declares `execute` and the same three. + `codemode`, `ask_user` and `recall`; `shell` declares `execute`, `ask_user` and `recall`. - Flow: a tool registered by a capability or an MCP server is declared in `normal`, callable from a `codemode` program, and absent from a `shell` Session. - Flow: in `codemode` mode a top-level call naming `read` or `skill` is refused as an unknown tool From 78dfcd4444b2b838da6da88f6bcba67b536ea291 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 22:08:41 +0800 Subject: [PATCH 08/28] docs: carry content blocks, order child calls, keep async work A codemode program can return a child result and have its image blocks rebuilt into the outer result; child calls follow ToolConcurrency; work handed to an owner outlives the program. codemode declares codemode and skill, shell declares execute, ask_user and recall. Refs #2135 --- docs/design/agent-tool-modes.md | 81 ++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index bd66cad562..9853ec6d6a 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -42,9 +42,9 @@ repository; the shell is the one without a product form. | `codemode` | one program | discover tools, call them, branch, loop, aggregate; child results stay out of the model context | the `codemode` tool beside the direct tools | | `shell` | one shell session | compose commands; working directory, environment and jobs persist across calls | the minimal-execution profile only | -In `codemode` and `shell` only the entry and the two conversation tools are declared (§2). That -absence is a property of the mode — the model does its work through one surface — not the goal of -the change. Fewer declarations +In `codemode` and `shell` only the entry and the tools a program cannot consume are declared (§2). +That absence is a property of the mode — the model does its work through one surface — not the goal +of the change. Fewer declarations per request, fewer round trips and less context churn follow from it; the tools declared today carry about 12 kB of description and about 20 kB with schemas, but saving that is a result, not the requirement. @@ -89,21 +89,27 @@ mean something, not a simplification. ## 2. Product behavior -A mode declares its entry tool and two conversation tools, `ask_user` and `recall`: asking the -operator and reading a shortened conversation are what a mode cannot replace. +A mode declares its entry tool, plus the tools whose result the program cannot consume: `skill` +carries instructions for the model, and a shell has no program, so it also declares `ask_user` and +`recall`. | Mode | Declared | A program may call | Hidden | | --- | --- | --- | --- | | `normal` (default) | every tool except `codemode` and `execute` | — | `codemode`, `execute` | -| `codemode` | `codemode`, `ask_user`, `recall` | every tool except `codemode` | — | +| `codemode` | `codemode`, `skill` | every tool except `codemode` | — | | `shell` | `execute`, `ask_user`, `recall` | — | every other tool | -- `codemode` loses no reach: its program calls every tool except `codemode`, so skills, images, the - web, MCP, lines, agents, schedules, settings and the shell are all available inside a program. - They are not declared because the model does that work in one program. -- `shell` is the shell, plus the two conversation tools. It cannot load a skill, read an image, call - an MCP tool, open a line, start a member, schedule or manage settings and plugins. Those are the - mode's boundary: a task that needs one runs in another mode. +- `codemode` loses no reach: its program calls every tool except `codemode`, so images, the web, + MCP, lines, agents, schedules, settings and the shell are all available inside a program. + `ask_user` and `recall` are orchestration inputs a program can process and use — it may ask the + operator several times and act on each answer, or search the history and decide from it — so they + are calls, not declarations. +- `skill` is different: its result is instructions for the model, not data for the program, so it + stays declared. +- `shell` is the shell, plus `ask_user` and `recall`, because it has no program to carry them. It + cannot load a skill, read an image, call an MCP tool, open a line, start a member, schedule or + manage settings and plugins. Those are the mode's boundary: a task that needs one runs in another + mode. - What each entry tool must provide to carry its mode is §7. Rules that hold in every mode: @@ -149,7 +155,7 @@ owns this projection. Three terms: | Mode | visible (top-level) | delegated (child) | entry tool absent | | --- | --- | --- | --- | | `normal` | every tool except `codemode` and `execute` | none | — | -| `codemode` | `codemode`, `ask_user`, `recall` | every tool except `codemode` | the Session runs `normal` | +| `codemode` | `codemode`, `skill` | every tool except `codemode` | the Session runs `normal` | | `shell` | `execute`, `ask_user`, `recall` | none | the Session runs `normal` | - The sets follow §2 and name no other tool: a new tool is declared in `normal`, callable from a @@ -247,16 +253,32 @@ kinds exist in one Session: ## 7. What the entry tools must provide -A mode declares one tool, so that tool must carry everything the mode promises. The items below are -its requirements; the ones marked missing are follow-up work, not part of this change. +A mode declares one entry tool, so that tool must carry everything the mode promises. The items +below are its requirements; the ones marked missing are follow-up work, not part of this change. `codemode`: - Discovery and call (`tools.list`, `tools.describe`, `tools.call`) over the request's pinned set, everything except `codemode`. Exists. -- Asking the operator from inside a program: a child `ask_user` already carries `parent_call_id` and - is answerable through `session.question.respond`; the clients must show it under the program and - let the operator answer it. Missing on the client side. +- **Content blocks on return.** A child result can carry image blocks (`read` of an image, an MCP + result), and they reach the model only if the return path rebuilds them. When the returned value + is a child result or its `content`, the host rebuilds the blocks it handed out; an image block is + rebuilt only when it equals one a child result returned, so a program cannot point the model at + pixels it never read. Text blocks always become text, and anything else stays JSON text. The + existing output bound applies. Missing. +- **Ordering.** A program calls tools in any order and in parallel, and child calls currently bypass + `ToolConcurrency`. The gate must order them the way a top-level batch does: calls start in the + order the program issued them, `Concurrent` calls may overlap, an `Exclusive` call waits for the + calls before it and holds back the calls after it, and a call waiting for an approval or a + question keeps its place. Missing. +- **Async lifetime.** Work handed to its owner — a background `exec` or `execute` task, an `events` + subscription, a `schedule`/`wakeup`/`loop` timer, a branch line, a member — is not tied to the + child call or the program: cancelling the program does not cancel it, and its completion arrives + as it does today. A call cancelled before it hands the work over does nothing. Mostly exists; + verify and pin it. +- Asking the operator from inside a program: a child `ask_user` carries `parent_call_id` and is + answerable through `session.question.respond`; the clients must show it under the program and let + the operator answer it. Missing on the client side. - Progress: each child call is a `step/tool-call`/`step/tool-result` event; the client groups them under the program row. The protocol exists (v4); grouping is a client feature. - A failure manifest: a failed program names the child calls that ran and their effects, beyond @@ -332,15 +354,20 @@ effective mode, so a mode that fell back to `normal` is not reported as in force - Flow: create a Session in each mode (request field; absent = `normal`) and assert the request's declarations: `normal` declares every tool except `codemode` and `execute`; `codemode` declares - `codemode`, `ask_user` and `recall`; `shell` declares `execute`, `ask_user` and `recall`. -- Flow: a tool registered by a capability or an MCP server is declared in `normal`, callable from a - `codemode` program, and absent from a `shell` Session. -- Flow: in `codemode` mode a top-level call naming `read` or `skill` is refused as an unknown tool - even though the request pinned it for children, and a child call to `codemode` is refused as - outside `delegated`. In `shell` mode a top-level call naming `read` is refused. -- Flow: in `codemode` mode, a program calls a work tool the model does not see and a dialogue tool - it does see; the child `step/tool-call` and `step/tool-result` carry `parent_call_id`, and - Permission admits each child by its own risk. + `codemode` and `skill`; `shell` declares `execute`, `ask_user` and `recall`. +- Flow: in `codemode` mode a top-level call naming `read`, `ask_user` or `execute` is refused as an + unknown tool even though the request pinned it for children, and a child call to `codemode` is + refused as outside `delegated`. In `shell` mode a top-level call naming `read` is refused. +- Flow: a program returns a `read` image result; the outer result carries the same image block, and + the model request renders it as an image, not as JSON. A fabricated image block falls back to + text. +- Flow: a program issues two `write` calls in parallel; the gate serializes them as `Exclusive` + calls in issue order, while two `read` calls overlap. +- Flow: a program starts a background `exec` and then fails or is stopped; the task keeps running, + the Session wakes on its completion, and `session.exec.stop` stops it. +- Flow: a child `ask_user` is shown under the program and is answerable through + `session.question.respond`; its result drives the program and is not duplicated into the model + context unless the program returns it. - Flow: switch a running Session in each direction; the next request declares the new visible set, the request after a tool result uses the new mode, a request retried through its own source (budget or restart recovery) keeps its pin, and a call already admitted finishes. From 92bad9bd39e4dd5e4e01cb7369b5b45af0f340f0 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 22:19:45 +0800 Subject: [PATCH 09/28] docs: do not order codemode child calls ToolConcurrency orders one batch, and a child call is its own batch of one, so the program's await and parallel structure are the order. The file tools keep their per-path lock; exec keeps none, as across turns. Refs #2135 --- docs/design/agent-tool-modes.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 9853ec6d6a..2694dd44f7 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -266,11 +266,12 @@ below are its requirements; the ones marked missing are follow-up work, not part rebuilt only when it equals one a child result returned, so a program cannot point the model at pixels it never read. Text blocks always become text, and anything else stays JSON text. The existing output bound applies. Missing. -- **Ordering.** A program calls tools in any order and in parallel, and child calls currently bypass - `ToolConcurrency`. The gate must order them the way a top-level batch does: calls start in the - order the program issued them, `Concurrent` calls may overlap, an `Exclusive` call waits for the - calls before it and holds back the calls after it, and a call waiting for an approval or a - question keeps its place. Missing. +- **Ordering.** `ToolConcurrency` orders the calls of one batch. Each child call is its own batch of + one, so the class has nothing to order: the program's `await` and parallel structure are the + order, and the runtime does not impose another. A handler that needs exclusion enforces it itself + — the file tools hold a per-path lock, so two writes to one path still serialize — and `exec` + holds none, so a program that runs `exec` beside a write can race it, as it already can across + turns and background tasks. Exists; state the boundary, add no gate. - **Async lifetime.** Work handed to its owner — a background `exec` or `execute` task, an `events` subscription, a `schedule`/`wakeup`/`loop` timer, a branch line, a member — is not tied to the child call or the program: cancelling the program does not cancel it, and its completion arrives @@ -361,8 +362,9 @@ effective mode, so a mode that fell back to `normal` is not reported as in force - Flow: a program returns a `read` image result; the outer result carries the same image block, and the model request renders it as an image, not as JSON. A fabricated image block falls back to text. -- Flow: a program issues two `write` calls in parallel; the gate serializes them as `Exclusive` - calls in issue order, while two `read` calls overlap. +- Flow: a program issues two `write` calls to one path in parallel; the per-path lock serializes +them. Ordering between `exec` and a write is not guaranteed inside a program, as it is not across +turns. - Flow: a program starts a background `exec` and then fails or is stopped; the task keeps running, the Session wakes on its completion, and `session.exec.stop` stops it. - Flow: a child `ask_user` is shown under the program and is answerable through From bd6890c3cef7f172580be43dbb071a756cbba14b Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 22:26:49 +0800 Subject: [PATCH 10/28] docs: drop the codemode ordering item Child calls need no ordering rule; the program is the order. The design does not state one. Refs #2135 --- docs/design/agent-tool-modes.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 2694dd44f7..202afccd24 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -266,12 +266,6 @@ below are its requirements; the ones marked missing are follow-up work, not part rebuilt only when it equals one a child result returned, so a program cannot point the model at pixels it never read. Text blocks always become text, and anything else stays JSON text. The existing output bound applies. Missing. -- **Ordering.** `ToolConcurrency` orders the calls of one batch. Each child call is its own batch of - one, so the class has nothing to order: the program's `await` and parallel structure are the - order, and the runtime does not impose another. A handler that needs exclusion enforces it itself - — the file tools hold a per-path lock, so two writes to one path still serialize — and `exec` - holds none, so a program that runs `exec` beside a write can race it, as it already can across - turns and background tasks. Exists; state the boundary, add no gate. - **Async lifetime.** Work handed to its owner — a background `exec` or `execute` task, an `events` subscription, a `schedule`/`wakeup`/`loop` timer, a branch line, a member — is not tied to the child call or the program: cancelling the program does not cancel it, and its completion arrives @@ -362,9 +356,6 @@ effective mode, so a mode that fell back to `normal` is not reported as in force - Flow: a program returns a `read` image result; the outer result carries the same image block, and the model request renders it as an image, not as JSON. A fabricated image block falls back to text. -- Flow: a program issues two `write` calls to one path in parallel; the per-path lock serializes -them. Ordering between `exec` and a write is not guaranteed inside a program, as it is not across -turns. - Flow: a program starts a background `exec` and then fails or is stopped; the task keeps running, the Session wakes on its completion, and `session.exec.stop` stops it. - Flow: a child `ask_user` is shown under the program and is answerable through From 82f0b06b542825d7556552658fb176dd48cd0043 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 22:31:52 +0800 Subject: [PATCH 11/28] docs: answer the design review on admission, stops and goals Split the diagram's admission by call origin, spell the create field toolMode, check the allowlist before claim, distinguish budget recovery from restart, name the minimal profile's host and restore rule, route a live stop to its owner first, and pause an active goal when a Session is in shell mode. Contracts gain the mode with the implementation. Refs #2135 --- docs/INDEX.md | 2 +- docs/design/agent-tool-modes.md | 119 +++++++++++++++++++++----------- 2 files changed, 80 insertions(+), 41 deletions(-) diff --git a/docs/INDEX.md b/docs/INDEX.md index 4883bd4acf..9fa794e37e 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -10,7 +10,7 @@ This index is navigation. Delivery status lives in issues, not here. - [CLI feature list](feature-list.md) - [Model preferences and Agent configuration](design/model-configuration.md) - [Model startup](design/model-startup.md): temporary model, effort and multi-protocol connections with branch/member/compaction inheritance -- [Agent tool modes](design/agent-tool-modes.md) (#2135): normal, codemode and shell as one user-scope choice, the visible/exposed tool surface, and the shell tool's place in the product assembly +- [Agent tool modes](design/agent-tool-modes.md) (#2135): normal, codemode and shell as one choice per Session, the visible and delegated tool surfaces, and the shell tool's place in the product assembly - [Model failures](design/model-failures.md)([中文](zh/design/model-failures.md)): the failure kind, the fact on the terminal event, who words the line, and retry (#1197) - [模型请求重试与任务续接方案](design/research/model-retry-recovery.md)(中文,#1210):请求重试的可见性、独立恢复能力的边界及所有者合同需求 - [服务面:跨语言形状的策略、盘点与第一批改造](design/service-faces.md)(中文,Draft),装配现状见[生成的服务目录](architecture/rust-agent/generated/catalog.md)。 diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 202afccd24..a1009ae725 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -89,9 +89,9 @@ mean something, not a simplification. ## 2. Product behavior -A mode declares its entry tool, plus the tools whose result the program cannot consume: `skill` -carries instructions for the model, and a shell has no program, so it also declares `ask_user` and -`recall`. +`codemode` and `shell` declare their entry tool, plus the tools a program cannot consume. +`codemode` adds `skill`, whose result is instructions for the model; `shell` has no program, so it +adds `ask_user` and `recall`. `normal` declares the work tools. | Mode | Declared | A program may call | Hidden | | --- | --- | --- | --- | @@ -112,6 +112,23 @@ carries instructions for the model, and a shell has no program, so it also decla mode. - What each entry tool must provide to carry its mode is §7. +### Goals in shell mode + +`shell` declares no `goal_update`, so a shell Session cannot complete or block a goal. The mode +contract: + +- Entering `shell` rewrites no goal. On the next continuation, Goal reads the Session's mode and, in + `shell`, pauses the goal (`paused`, reason `mode`) instead of continuing, so the model is never + asked to call a tool the mode does not declare. +- `session.goal.set` and `session.goal.resume` are refused in `shell` with a named error; `pause`, + `edit`, `clear` and `get` keep working. +- Leaving `shell` does not resume the goal: the operator resumes it explicitly, as Goal already + requires for a paused goal. +- A completed or blocked goal stays as it is. + +Goal's owner states this lifecycle and its acceptance cases in [Goal](plugins/Goal.md); this design +sets the requirement and writes no Goal fact itself. + Rules that hold in every mode: - Approval and Permission are unchanged. Each call is admitted under the called tool's own risk, @@ -131,7 +148,7 @@ may change it behind the operator's back. | Situation | Rule | Why | | --- | --- | --- | | A new Session from a client | starts in the mode the request names, or `normal` when it names none; the client sends the mode it last used | the operator should not re-choose for every Session | -| A running Session | the operator can switch it at any time; the next model request declares the new mode, a request already prepared keeps its pin (including its own recovery), and a call already admitted finishes | otherwise a change of style means abandoning the conversation | +| A running Session | the operator can switch it at any time; the next model request declares the new mode, a request already prepared keeps its pin (an in-process budget recovery reuses it; a process restart settles the in-flight request), and a call already admitted finishes | otherwise a change of style means abandoning the conversation | | A branch (line) | has no mode of its own; every line of a Session runs the Session's mode | a line is the same agent; a line in another mode would hand the agent tools the operator excluded | | A member Session | starts in its creator Session's current mode, and the operator can switch it like any Session | the member is the same agent doing delegated work; the model must not decide how the agent acts | | The model | never chooses or changes a mode | it is the operator's choice of capability | @@ -149,8 +166,8 @@ owns this projection. Three terms: `SessionConfig.tools` and `excluded_tools`. The branch adopts and pins this set, and it does not change when the mode does. - **visible**: what the request declares and what a top-level model call may name. -- **delegated**: what a Code Mode child call may name. Their union is the request's exposed set, the - only tools the request binds. +- **delegated**: what a Code Mode child call may name. The request binds their union; neither is an + admission set by itself. | Mode | visible (top-level) | delegated (child) | entry tool absent | | --- | --- | --- | --- | @@ -164,14 +181,16 @@ owns this projection. Three terms: inside `delegated`. Both then pass the called tool's own Permission and Approval. A call outside its origin's set is refused as an unknown tool, even when the tool is bound. The origin is the existing parent-call scope (`current_parent_call_id`), so a hidden tool cannot be reached by - naming it directly. + naming it directly. The check runs before a handler's `claim`, so a refused call registers no + waiter and takes no effect. - A Code Mode program discovers and calls exactly the `delegated` set: `tools.list` and `tools.describe` project it, and `tools.call` admits inside it. `codemode` itself is never delegated, so a program cannot nest one. - A request pins the mode it was prepared under, together with the callable set it pins today, and derives both sets from that pin. A switch takes effect with the next request and needs no re-adoption: the branch's configuration, the version pins and the source sets stay as they are. A - request retried through its own source (a budget recovery or a restart recovery) keeps the pin; a + request retried through its own source (an in-process budget recovery) keeps the pin; a process + restart settles the in-flight request as the loop already does and does not reissue it; a continuation request is a new request and pins the current mode, as does the request that follows a tool result. - Only `visible` reaches the model request, its token accounting and compaction. `delegated` never @@ -189,9 +208,10 @@ unavailable mode instead of silently falling back. The mode is Session configuration; there is no daemon-wide default to maintain. -- `session.create` may name the mode; a Session created without one starts `normal`. The field is - additive and advertised as `session.create.toolMode`, like `session.language`, because an older - daemon rejects an unknown field. +- `session.create` may name the mode in `toolMode`; a Session created without one starts `normal`. + The field is additive and advertised as `session.create.toolMode`, like `session.language`, + because an older daemon rejects an unknown field. `Create` carries it as `tool_mode`, which + serializes as `toolMode`. - The App Server records the mode in `SessionConfig.toolMode`. `normal` omits the member, so a normal Session's stored configuration has the same bytes as before this field existed; an old record reads as `normal`. A fork copies the value, and a restore starts from it. @@ -205,15 +225,17 @@ The mode is live for the Session's lifetime: read it when they are prepared; nothing re-adopts a tool set when it changes. - `session.tool_mode.get` returns `{mode, effective}`: the mode the operator chose and the one in force. A mode whose entry tool is absent stays chosen and is not in force; that is the fallback. - `session.tool_mode.update` writes the stored record (native storage only, as - `session.language.update` does) and the live value. The pair is advertised as `session.tool_mode`, - like `session.language`. + `session.tool_mode.update` follows `session.language.update`'s order: a failure before the record + write changes nothing; once the record is written the live value is replaced, and a later + cancellation keeps the new value stored, so the two do not diverge. The pair is advertised as + `session.tool_mode`, like `session.language`. - The model has no tool for this; it is a client method only. ```text -session.create.mode ──▶ SessionConfig.toolMode ──▶ ToolRegistry (live mode) - ├─ a request pins the mode ──▶ visible ──▶ model request, usage - └─ a call checks the pinned mode ──▶ exposed ──▶ admit or refuse +session.create.toolMode ──▶ SessionConfig.toolMode ──▶ ToolRegistry (live mode) + ├─ a request pins the mode ──▶ visible ──▶ model request, usage + ├─ a top-level call checks `visible` ──▶ admit or refuse + └─ a child call checks `delegated` ──▶ admit or refuse session.tool_mode.update ──▶ live mode + stored record ``` @@ -232,8 +254,10 @@ only in the minimal-execution profile, where `ShellTools` takes the Session's si declaration and handler with `ToolRegistry` instead of providing `ToolHost`, and still resolves the calling branch's `ShellSession` per call. The registry's registration already carries what a host tool needs: declaration, handler, risk, mount-list filtering and per-Session lifetime. -- The minimal-execution profile is `shell` by construction: its Sessions set `toolMode: shell`, - because `normal` would filter the only tool it has. +- The minimal-execution profile is `shell` by construction: its host sets `toolMode: shell` when it + creates a Session and when it restores one whose record lacks the field, because `normal` would + filter the only tool it has. It binds `ToolHost` with an empty driver, because `ShellTools` no + longer provides one. Why not conditional mounting: a Session has one `ToolHost` (`WorkspaceTools` provides it in the product), and mounting `ShellTools` instead of `WorkspaceTools` for shell Sessions would also remove @@ -245,16 +269,17 @@ Stopping a task is a separate route. Today `session.exec.stop` resolves the bran `ShellSession`, which provides the branch's `dyn ExecStop`. With `execute` in the product, both kinds exist in one Session: -- The stop route asks `BackgroundExec` first and, when it does not know the id, the branch's - `ExecStop`, so either kind stops and writes its `exec/ended`. +- The stop route resolves the live owner first: the branch's `ExecStop` for a live shell task, then + `BackgroundExec` for a native process. A task neither owns is read from shared history for its + terminal result; history never answers for a live task. - Both parts stay mounted when the mode changes, so a task started in `shell` or `codemode` can still be stopped after the Session switches to `normal`. - `session.stop` remains the turn's stop and stops no background task. ## 7. What the entry tools must provide -A mode declares one entry tool, so that tool must carry everything the mode promises. The items -below are its requirements; the ones marked missing are follow-up work, not part of this change. +A mode's entry is one tool, so that tool must carry everything the mode promises. The items below +are its requirements; the ones marked missing are follow-up work, not part of this change. `codemode`: @@ -278,10 +303,13 @@ below are its requirements; the ones marked missing are follow-up work, not part under the program row. The protocol exists (v4); grouping is a client feature. - A failure manifest: a failed program names the child calls that ran and their effects, beyond today's "some child calls may have completed". Missing. -- Stop: stopping the program ends its children and writes a terminal result that says what may have - run. Missing. +- Stop: the turn's stop and interrupt already cancel the program's children and return the + may-have-run warning; a per-program stop that leaves the turn running is missing. - Bounds on time, memory, calls and output. Exists. -- A description and examples that teach discovery, loop bounds and partial results. Missing. +- Approval wording: the outer approval says a program will call tools, and the child calls appear + under it as they happen. Missing. +- The description exists; examples that teach discovery, loop bounds and partial results are + missing. `execute`: @@ -326,9 +354,10 @@ there is no default row to set. ╰──────────────────────────────────────────────╯ ``` -The picker lists all three modes; a mode whose `hello.features` entry is absent is shown as -unavailable and cannot be chosen. A switch takes effect from the next request, and the row shows the -effective mode, so a mode that fell back to `normal` is not reported as in force. +The picker lists all three modes; `normal` is always available, and `codemode` or `shell` is shown +as unavailable when its `hello.features` entry is absent. A switch takes effect from the next +request, and the row shows the effective mode, so a mode that fell back to `normal` is not reported +as in force. ## 9. Compatibility @@ -339,9 +368,15 @@ effective mode, so a mode that fell back to `normal` is not reported as in force the fallback rule makes the Session `normal`, and a v3 client can neither select nor receive Code Mode ([child tool batches §2.6](appserver/child-tool-batches.md#26-app-server-code-mode-gate)). - [CodeMode](plugins/CodeMode.md) and [child tool batches](appserver/child-tool-batches.md) change - in one respect: the `codemode` tool is offered in `codemode` mode, not to every v4 Session. The - child-event contract is unchanged. -- A Session restored from a record that predates this field becomes `normal`. A Session that used + in two respects: the `codemode` tool is offered in `codemode` mode, not to every v4 Session, and + its request declares only `codemode` and `skill` instead of every adopted tool. The child-event + contract is unchanged. +- The canonical contracts gain the mode with the implementation, each by its owner: + `SessionConfig.toolMode` in [session access](contracts/session-access.md), the live mode and + projection in [ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md), and the + declaration set plus admission split in [CodeMode](plugins/CodeMode.md). +- A Session restored from a record that predates this field becomes `normal`, except in the + minimal-execution profile, whose host sets `shell` on create and restore (§6). A Session that used the `codemode` tool therefore loses it on upgrade until the operator selects `codemode`. That is the intended product change. @@ -362,17 +397,21 @@ effective mode, so a mode that fell back to `normal` is not reported as in force `session.question.respond`; its result drives the program and is not duplicated into the model context unless the program returns it. - Flow: switch a running Session in each direction; the next request declares the new visible set, - the request after a tool result uses the new mode, a request retried through its own source - (budget or restart recovery) keeps its pin, and a call already admitted finishes. + the request after a tool result uses the new mode, an in-process budget recovery keeps its pin, a + process restart settles the in-flight request without reissuing it, and a call already admitted + finishes. - Flow: fallback — a mode whose entry tool is absent stays chosen in `get` and is reported as not in force; the Session declares the `normal` surface. - Flow: a member created under `codemode` records it; switching the creator leaves the member unchanged. - Flow: restore a record without the field, and fork a Session; both keep `normal` and the source - mode respectively. -- Flow: stop a shell task with `session.exec.stop` after switching the Session to `normal`; the same - route stops a native process from `BackgroundExec`. The minimal-execution profile's Session runs - `shell` and keeps `execute`. + mode respectively, except that the minimal-execution host restores its Sessions as `shell`. +- Flow: a goal set before switching to `shell` pauses at the next continuation with reason `mode`; + `session.goal.set` and `resume` are refused in `shell`; after leaving, the operator resumes it and + it continues. +- Flow: stop a shell task with `session.exec.stop` after switching the Session to `normal`; the + route resolves the live `ExecStop` before `BackgroundExec`, and neither answers for a live task + from history. The minimal-execution profile's Session runs `shell` and keeps `execute`. - Clients: a web component test for the composer menu and the remembered choice, and one tmux TUI case for the row and the picker. - No event type, envelope or stored format changes, so the fixture compatibility baseline is @@ -392,8 +431,8 @@ effective mode, so a mode that fell back to `normal` is not reported as in force - §4 rule 5: no batches. - §4 rule 6: the visible set is exactly what the request declares; no new context path. - §4 rule 7: parts coordinate through the Session configuration and the registry's own read. -- §4 rule 8: no infrastructure change; Timeline, Dispatcher, the event envelope, assembly and the - Session facades are untouched. +- §4 rule 8: no infrastructure change; the product profile's tool wiring changes (§6), while + Timeline, Dispatcher, the event envelope, rutis assembly and the Session facades are untouched. - §4 rule 9: the mode is Session configuration, not a Timeline fact, and follows `session.language`: the current value lives in the registry, the durable copy in the stored record. From bbbcd673c8c63cc0ecf88377566c61f9527bfbc0 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 22:43:32 +0800 Subject: [PATCH 12/28] docs: finish the review follow-ups on contracts and wording List every document the mode changes, put Goal under the requirements to an owner and name the read it uses, fix the cancelled update, the skill and execute descriptions, and the client's handling of a refused goal call. Refs #2135 --- docs/design/agent-tool-modes.md | 55 +++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index a1009ae725..b0acdd836d 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -42,12 +42,11 @@ repository; the shell is the one without a product form. | `codemode` | one program | discover tools, call them, branch, loop, aggregate; child results stay out of the model context | the `codemode` tool beside the direct tools | | `shell` | one shell session | compose commands; working directory, environment and jobs persist across calls | the minimal-execution profile only | -In `codemode` and `shell` only the entry and the tools a program cannot consume are declared (§2). -That absence is a property of the mode — the model does its work through one surface — not the goal -of the change. Fewer declarations -per request, fewer round trips and less context churn follow from it; the tools declared today -carry about 12 kB of description and about 20 kB with schemas, but saving that is a result, not the -requirement. +In `codemode` and `shell` only the entry and the tools §2 lists are declared. That absence is a +property of the mode — the model does its work through one surface — not the goal of the change. +Fewer declarations per request, fewer round trips and less context churn follow from it; the tools +declared today carry about 12 kB of description and about 20 kB with schemas, but saving that is a +result, not the requirement. ### 1.3 The one real risk: how well the model uses the mode @@ -104,8 +103,8 @@ adds `ask_user` and `recall`. `normal` declares the work tools. `ask_user` and `recall` are orchestration inputs a program can process and use — it may ask the operator several times and act on each answer, or search the history and decide from it — so they are calls, not declarations. -- `skill` is different: its result is instructions for the model, not data for the program, so it - stays declared. +- `skill` is declared because the model needs the instructions directly; a program may call it too, + but loading them through a program would only return them as data. - `shell` is the shell, plus `ask_user` and `recall`, because it has no program to carry them. It cannot load a skill, read an image, call an MCP tool, open a line, start a member, schedule or manage settings and plugins. Those are the mode's boundary: a task that needs one runs in another @@ -193,8 +192,8 @@ owns this projection. Three terms: restart settles the in-flight request as the loop already does and does not reissue it; a continuation request is a new request and pins the current mode, as does the request that follows a tool result. -- Only `visible` reaches the model request, its token accounting and compaction. `delegated` never - appears in a prompt, a declaration or the usage counter. +- A tool that is only delegated never appears in a prompt, a declaration or the usage counter; + `skill` is in both sets. - The mount list and an Agent profile's tool list narrow the surface and never widen it. `normal` and `shell` hide the other modes' entry tools even when a list names them. @@ -322,7 +321,7 @@ are its requirements; the ones marked missing are follow-up work, not part of th - Stop through the route in §6, so a shell task stops and writes `exec/ended`. Missing. - Pageable output, and operator-visible state: the current directory, the running job, a command waiting for input. Output paging exists for native tasks; the state view is missing. -- A description and examples for the dialect, backgrounding and timeouts. Missing. +- The description exists; examples for the dialect, backgrounding and timeouts are missing. The boundary is §2's: a shell Session cannot load a skill, read an image, call an MCP tool, open a line, start a member, schedule or manage settings and plugins. A task that needs one runs in another @@ -357,7 +356,8 @@ there is no default row to set. The picker lists all three modes; `normal` is always available, and `codemode` or `shell` is shown as unavailable when its `hello.features` entry is absent. A switch takes effect from the next request, and the row shows the effective mode, so a mode that fell back to `normal` is not reported -as in force. +as in force. A client that offers Goal disables `set` and `resume` while the Session is in `shell` +and shows the named refusal otherwise. ## 9. Compatibility @@ -367,14 +367,15 @@ as in force. - The v3 Code Mode gate stays. `excluded_tools` keeps `codemode` out of that Session's callable set, the fallback rule makes the Session `normal`, and a v3 client can neither select nor receive Code Mode ([child tool batches §2.6](appserver/child-tool-batches.md#26-app-server-code-mode-gate)). -- [CodeMode](plugins/CodeMode.md) and [child tool batches](appserver/child-tool-batches.md) change - in two respects: the `codemode` tool is offered in `codemode` mode, not to every v4 Session, and - its request declares only `codemode` and `skill` instead of every adopted tool. The child-event - contract is unchanged. -- The canonical contracts gain the mode with the implementation, each by its owner: - `SessionConfig.toolMode` in [session access](contracts/session-access.md), the live mode and - projection in [ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md), and the - declaration set plus admission split in [CodeMode](plugins/CodeMode.md). +- [CodeMode](plugins/CodeMode.md) changes in four respects with the implementation: the mode gate + (offered in `codemode` mode, not to every v4 Session), the declaration set (`codemode` and `skill` + instead of every adopted tool), the admission split (a child only inside `delegated`), and the + outer result rebuilding content blocks instead of serializing the program value as JSON. Its + child-event contract is unchanged. +- [Goal](plugins/Goal.md) gains the shell lifecycle in §2. +- The remaining contracts gain the mode with the implementation, each by its owner: + `SessionConfig.toolMode` in [session access](contracts/session-access.md), and the live mode plus + projection in [ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md). - A Session restored from a record that predates this field becomes `normal`, except in the minimal-execution profile, whose host sets `shell` on create and restore (§6). A Session that used the `codemode` tool therefore loses it on upgrade until the operator selects `codemode`. That is @@ -437,8 +438,8 @@ as in force. `session.language`: the current value lives in the registry, the durable copy in the stored record. - §7.1 for the live mode: the resource is the value; lifecycle is the Session's; the operations are - `get` and `update`, whose cancellation stops the record write and which report the effective mode - rather than refusing one. + `get` and `update`. A cancellation before the record write changes nothing; after it the new value + stays stored and in force. Both report the effective mode rather than refusing one. - §7.2: no object or resource handle crosses an owner; no new service, and the mode methods join the existing Session method face; the parameters are data. - [ADR 002](../adr/002-plugin-scope.md) D1: the mode is Session configuration and the pinned mode is @@ -447,7 +448,15 @@ as in force. and changed by its owner's operation. D5: the mode methods take data. ## 12. Requirements raised to mechanism owners -None. The change stays within the owners that already exist: ToolRegistry projects its own set and +None for the mechanism. One requirement goes to another capability's owner: + +- **Goal.** On each continuation, read the Session's mode and, in `shell`, pause with reason `mode` + instead of continuing; refuse `session.goal.set` and `resume` in `shell`; leave resumption to the + operator after the Session leaves `shell` (§2). Goal reads `ToolRegistry`'s current mode, the + value `session.tool_mode.get` reports, not another owner's state. Its owner carries this into + [Goal](plugins/Goal.md). + +Everything else stays within the owners that already exist: ToolRegistry projects its own set and holds the live mode, ToolBinding pins the mode with the callable set, ToolExecution refuses a call outside it, ContextUsage counts `visible`, the App Server owns the stored record and the Session methods, and each client owns its control and its remembered choice. From a50164466a2ad9798fa21fcc4f6b2081f290c142 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 23:06:01 +0800 Subject: [PATCH 13/28] docs: key the goal contract on the mode in force Goal reads the effective mode, so a chosen shell that falls back to normal keeps goal_update. Switching to an effective shell settles Goal before the update returns: pause each branch and withdraw an unapplied continuation, while an applied one finishes under its old surface. Refs #2135 --- docs/design/agent-tool-modes.md | 55 ++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index b0acdd836d..438f7c1884 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -88,9 +88,9 @@ mean something, not a simplification. ## 2. Product behavior -`codemode` and `shell` declare their entry tool, plus the tools a program cannot consume. -`codemode` adds `skill`, whose result is instructions for the model; `shell` has no program, so it -adds `ask_user` and `recall`. `normal` declares the work tools. +`codemode` and `shell` declare what the table lists: their entry tool and the extras their mode +needs. `codemode` adds `skill`, whose instructions the model reads directly; `shell` has no +program, so it adds `ask_user` and `recall`. `normal` declares the work tools. | Mode | Declared | A program may call | Hidden | | --- | --- | --- | --- | @@ -113,14 +113,19 @@ adds `ask_user` and `recall`. `normal` declares the work tools. ### Goals in shell mode -`shell` declares no `goal_update`, so a shell Session cannot complete or block a goal. The mode -contract: - -- Entering `shell` rewrites no goal. On the next continuation, Goal reads the Session's mode and, in - `shell`, pauses the goal (`paused`, reason `mode`) instead of continuing, so the model is never - asked to call a tool the mode does not declare. -- `session.goal.set` and `session.goal.resume` are refused in `shell` with a named error; `pause`, - `edit`, `clear` and `get` keep working. +`shell` declares no `goal_update`, so a Session whose mode **in force** is `shell` cannot complete +or block a goal. Everything below keys on the mode in force — the value `session.tool_mode.get` +reports in `effective` — not on the mode the operator chose: a chosen `shell` without `execute` +runs `normal` and keeps `goal_update`. + +- Switching to an effective `shell` settles Goal before the update returns. For every branch with + an active goal, Goal writes `paused` with reason `mode` and withdraws the continuation it queued + when the InputQueue has not applied it; an applied continuation is the request in flight, which + pinned the old surface and finishes under it. +- While `shell` is in force, a new continuation pauses the goal instead of continuing, so the model + is never asked to call a tool the mode does not declare. +- `session.goal.set` and `session.goal.resume` are refused while `shell` is in force, with a named + error; `pause`, `edit`, `clear` and `get` keep working. - Leaving `shell` does not resume the goal: the operator resumes it explicitly, as Goal already requires for a paused goal. - A completed or blocked goal stays as it is. @@ -135,8 +140,9 @@ Rules that hold in every mode: - Tool sources are unchanged. MCP servers, extension tools and other registered tools still contribute to the Session's tool set; the mode decides what the model sees and, in `codemode`, what a program may call. It does not enable or disable a source. -- Client surfaces are unchanged. Mention search (`session.files`), command-output paging, skills, - approvals and settings work in every mode. +- Apart from the mode control and the Goal control in §8, client surfaces are unchanged. Mention + search (`session.files`), command-output paging, skills, approvals and settings work in every + mode. ## 3. Who owns the mode @@ -322,6 +328,8 @@ are its requirements; the ones marked missing are follow-up work, not part of th - Pageable output, and operator-visible state: the current directory, the running job, a command waiting for input. Output paging exists for native tasks; the state view is missing. - The description exists; examples for the dialect, backgrounding and timeouts are missing. +- A mode-aware environment block: on Windows it carries guidance about `read`/`edit`/`write` text + encoding, which is noise in shell mode. Missing. The boundary is §2's: a shell Session cannot load a skill, read an image, call an MCP tool, open a line, start a member, schedule or manage settings and plugins. A task that needs one runs in another @@ -407,16 +415,18 @@ and shows the named refusal otherwise. unchanged. - Flow: restore a record without the field, and fork a Session; both keep `normal` and the source mode respectively, except that the minimal-execution host restores its Sessions as `shell`. -- Flow: a goal set before switching to `shell` pauses at the next continuation with reason `mode`; - `session.goal.set` and `resume` are refused in `shell`; after leaving, the operator resumes it and - it continues. +- Flow: a goal with a queued continuation, switched to an effective `shell` before it is applied: + the continuation is withdrawn, the goal pauses (`mode`), and no request carrying the + `goal_update` instruction is prepared. Switched after it is applied, that request finishes under + the old surface. `set`/`resume` are refused while `shell` is in force; a chosen `shell` that runs + `normal` (no `execute`) neither pauses nor refuses; after leaving, the operator resumes the goal. - Flow: stop a shell task with `session.exec.stop` after switching the Session to `normal`; the route resolves the live `ExecStop` before `BackgroundExec`, and neither answers for a live task from history. The minimal-execution profile's Session runs `shell` and keeps `execute`. - Clients: a web component test for the composer menu and the remembered choice, and one tmux TUI case for the row and the picker. -- No event type, envelope or stored format changes, so the fixture compatibility baseline is - untouched. +- No event type or envelope changes. The stored configuration gains an optional field that old + records omit, so the fixture compatibility baseline is untouched and old records load as before. ## 11. Rule check @@ -450,10 +460,11 @@ and shows the named refusal otherwise. None for the mechanism. One requirement goes to another capability's owner: -- **Goal.** On each continuation, read the Session's mode and, in `shell`, pause with reason `mode` - instead of continuing; refuse `session.goal.set` and `resume` in `shell`; leave resumption to the - operator after the Session leaves `shell` (§2). Goal reads `ToolRegistry`'s current mode, the - value `session.tool_mode.get` reports, not another owner's state. Its owner carries this into +- **Goal.** Read the mode in force, the value `session.tool_mode.get` reports in `effective`, never + the chosen mode. When a switch makes `shell` effective, settle before the update returns: pause + each branch's active goal (`mode`) and withdraw a continuation the InputQueue has not applied; + while `shell` is in force, pause new continuations and refuse `session.goal.set` and `resume`; + leave resumption to the operator after `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). Everything else stays within the owners that already exist: ToolRegistry projects its own set and From 826b867523851927bbfb3f56273cba430f88a759 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 23:28:34 +0800 Subject: [PATCH 14/28] docs: pin the mode per turn and order the goal pause A turn pins the mode when it starts, so an applied goal continuation cannot be prepared under a new shell surface mid-turn. The switch writes Goal's pause before the live mode, and the environment block moves to PromptSources, its owner. Refs #2135 --- docs/design/agent-tool-modes.md | 72 +++++++++++++++++---------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 438f7c1884..04fdaddeaf 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -1,7 +1,7 @@ # Agent tool modes: normal, codemode and shell Status: Draft. Scope: process (mode availability), Session (the mode and the tool surface), -branch (the mode a request pins). +branch (the mode a turn pins). Issue: [#2135](https://github.com/arcships/dim/issues/2135). Delivery status belongs in the issue. Today the model has one way to act: one tool call per decision, with every tool declared before the @@ -118,10 +118,12 @@ or block a goal. Everything below keys on the mode in force — the value `sessi reports in `effective` — not on the mode the operator chose: a chosen `shell` without `execute` runs `normal` and keeps `goal_update`. -- Switching to an effective `shell` settles Goal before the update returns. For every branch with - an active goal, Goal writes `paused` with reason `mode` and withdraws the continuation it queued - when the InputQueue has not applied it; an applied continuation is the request in flight, which - pinned the old surface and finishes under it. +- Switching to an effective `shell` writes Goal's pause before the mode changes, so every turn that + starts in `shell` has the pause in its history. For each branch with an active goal, Goal writes + `paused` with reason `mode` and withdraws the continuation it queued when the InputQueue has not + applied it; an applied continuation belongs to a turn that started earlier, which pinned the old + mode and finishes under it. A cancelled update after the pause leaves the goal paused and the + mode unchanged; the operator resumes it. - While `shell` is in force, a new continuation pauses the goal instead of continuing, so the model is never asked to call a tool the mode does not declare. - `session.goal.set` and `session.goal.resume` are refused while `shell` is in force, with a named @@ -153,12 +155,12 @@ may change it behind the operator's back. | Situation | Rule | Why | | --- | --- | --- | | A new Session from a client | starts in the mode the request names, or `normal` when it names none; the client sends the mode it last used | the operator should not re-choose for every Session | -| A running Session | the operator can switch it at any time; the next model request declares the new mode, a request already prepared keeps its pin (an in-process budget recovery reuses it; a process restart settles the in-flight request), and a call already admitted finishes | otherwise a change of style means abandoning the conversation | +| A running Session | the operator can switch it at any time; the next turn declares the new mode, a turn already started keeps its pin (an in-process budget recovery reuses it; a process restart settles the in-flight request), and a call already admitted finishes | otherwise a change of style means abandoning the conversation | | A branch (line) | has no mode of its own; every line of a Session runs the Session's mode | a line is the same agent; a line in another mode would hand the agent tools the operator excluded | | A member Session | starts in its creator Session's current mode, and the operator can switch it like any Session | the member is the same agent doing delegated work; the model must not decide how the agent acts | | The model | never chooses or changes a mode | it is the operator's choice of capability | -A switch does not rewrite the history the model already has: the next request carries the new +A switch does not rewrite the history the model already has: the next turn carries the new declarations. ## 4. The tool surface rule @@ -191,13 +193,12 @@ owns this projection. Three terms: - A Code Mode program discovers and calls exactly the `delegated` set: `tools.list` and `tools.describe` project it, and `tools.call` admits inside it. `codemode` itself is never delegated, so a program cannot nest one. -- A request pins the mode it was prepared under, together with the callable set it pins today, and - derives both sets from that pin. A switch takes effect with the next request and needs no - re-adoption: the branch's configuration, the version pins and the source sets stay as they are. A - request retried through its own source (an in-process budget recovery) keeps the pin; a process - restart settles the in-flight request as the loop already does and does not reissue it; a - continuation request is a new request and pins the current mode, as does the request that follows - a tool result. +- A turn pins the mode when it starts — when its driving input is applied — and every request of + the turn uses that pin, together with the callable set it pins today. A switch takes effect with + the next turn and needs no re-adoption: the branch's configuration, the version pins and the + source sets stay as they are. A request retried through its own source (an in-process budget + recovery) keeps the pin; a process restart settles the in-flight request as the loop already does + and does not reissue it; the request that follows a tool result keeps the turn's pin. - A tool that is only delegated never appears in a prompt, a declaration or the usage counter; `skill` is in both sets. - The mount list and an Agent profile's tool list narrow the surface and never widen it. `normal` @@ -226,8 +227,8 @@ The mode is Session configuration; there is no daemon-wide default to maintain. The mode is live for the Session's lifetime: -- `ToolRegistry` holds the Session's current mode, initialised from the configuration. Requests - read it when they are prepared; nothing re-adopts a tool set when it changes. +- `ToolRegistry` holds the Session's current mode, initialised from the configuration. A turn reads + it when it starts; nothing re-adopts a tool set when it changes. - `session.tool_mode.get` returns `{mode, effective}`: the mode the operator chose and the one in force. A mode whose entry tool is absent stays chosen and is not in force; that is the fallback. `session.tool_mode.update` follows `session.language.update`'s order: a failure before the record @@ -238,7 +239,7 @@ The mode is live for the Session's lifetime: ```text session.create.toolMode ──▶ SessionConfig.toolMode ──▶ ToolRegistry (live mode) - ├─ a request pins the mode ──▶ visible ──▶ model request, usage + ├─ a turn pins the mode ──▶ visible ──▶ model request, usage ├─ a top-level call checks `visible` ──▶ admit or refuse └─ a child call checks `delegated` ──▶ admit or refuse session.tool_mode.update ──▶ live mode + stored record @@ -328,8 +329,6 @@ are its requirements; the ones marked missing are follow-up work, not part of th - Pageable output, and operator-visible state: the current directory, the running job, a command waiting for input. Output paging exists for native tasks; the state view is missing. - The description exists; examples for the dialect, backgrounding and timeouts are missing. -- A mode-aware environment block: on Windows it carries guidance about `read`/`edit`/`write` text - encoding, which is noise in shell mode. Missing. The boundary is §2's: a shell Session cannot load a skill, read an image, call an MCP tool, open a line, start a member, schedule or manage settings and plugins. A task that needs one runs in another @@ -362,10 +361,10 @@ there is no default row to set. ``` The picker lists all three modes; `normal` is always available, and `codemode` or `shell` is shown -as unavailable when its `hello.features` entry is absent. A switch takes effect from the next -request, and the row shows the effective mode, so a mode that fell back to `normal` is not reported -as in force. A client that offers Goal disables `set` and `resume` while the Session is in `shell` -and shows the named refusal otherwise. +as unavailable when its `hello.features` entry is absent. A switch takes effect from the next turn, +and the row shows the effective mode, so a mode that fell back to `normal` is not reported as in +force. A client that offers Goal disables `set` and `resume` while `shell` is in force (the +`effective` value) and shows the named refusal otherwise. ## 9. Compatibility @@ -405,10 +404,10 @@ and shows the named refusal otherwise. - Flow: a child `ask_user` is shown under the program and is answerable through `session.question.respond`; its result drives the program and is not duplicated into the model context unless the program returns it. -- Flow: switch a running Session in each direction; the next request declares the new visible set, - the request after a tool result uses the new mode, an in-process budget recovery keeps its pin, a - process restart settles the in-flight request without reissuing it, and a call already admitted - finishes. +- Flow: switch a running Session in each direction; the next turn declares the new visible set, a + request after a tool result in the same turn keeps the turn's pin, an in-process budget recovery + keeps its pin, a process restart settles the in-flight request without reissuing it, and a call + already admitted finishes. - Flow: fallback — a mode whose entry tool is absent stays chosen in `get` and is reported as not in force; the Session declares the `normal` surface. - Flow: a member created under `codemode` records it; switching the creator leaves the member @@ -416,9 +415,11 @@ and shows the named refusal otherwise. - Flow: restore a record without the field, and fork a Session; both keep `normal` and the source mode respectively, except that the minimal-execution host restores its Sessions as `shell`. - Flow: a goal with a queued continuation, switched to an effective `shell` before it is applied: - the continuation is withdrawn, the goal pauses (`mode`), and no request carrying the - `goal_update` instruction is prepared. Switched after it is applied, that request finishes under - the old surface. `set`/`resume` are refused while `shell` is in force; a chosen `shell` that runs + the continuation is withdrawn, the goal pauses (`mode`), and no turn carrying the `goal_update` + instruction starts in `shell`. Switched after it is applied, that turn pinned the old mode and + finishes under it. The pause is written before the live mode, so a turn that starts in `shell` + has it in history; a cancelled update after the pause leaves the goal paused and the mode + unchanged. `set`/`resume` are refused while `shell` is in force; a chosen `shell` that runs `normal` (no `execute`) neither pauses nor refuses; after leaving, the operator resumes the goal. - Flow: stop a shell task with `session.exec.stop` after switching the Session to `normal`; the route resolves the live `ExecStop` before `BackgroundExec`, and neither answers for a live task @@ -461,11 +462,14 @@ and shows the named refusal otherwise. None for the mechanism. One requirement goes to another capability's owner: - **Goal.** Read the mode in force, the value `session.tool_mode.get` reports in `effective`, never - the chosen mode. When a switch makes `shell` effective, settle before the update returns: pause - each branch's active goal (`mode`) and withdraw a continuation the InputQueue has not applied; - while `shell` is in force, pause new continuations and refuse `session.goal.set` and `resume`; - leave resumption to the operator after `shell` leaves. Its owner carries this into + the chosen mode. When a switch makes `shell` effective, write the pause before the live mode + changes: pause each branch's active goal (`mode`) and withdraw a continuation the InputQueue has + not applied; while `shell` is in force, pause new continuations and refuse `session.goal.set` and + `resume`; leave resumption to the operator after `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). +- **PromptSources.** The environment block follows the surface: in `shell` mode it drops the + Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into + [PromptSources](plugins/PromptSources.md). Everything else stays within the owners that already exist: ToolRegistry projects its own set and holds the live mode, ToolBinding pins the mode with the callable set, ToolExecution refuses a call From 041f1e151961ec52f6b0ff3499ce49d9c4f399e6 Mon Sep 17 00:00:00 2001 From: scotares Date: Tue, 24 Nov 2026 23:52:04 +0800 Subject: [PATCH 15/28] docs: settle goals on every transition to shell Goal settles on the registry's effective-mode transition, not only on an operator update, writes a pause text the model can read, and orders the pause before the record write and the live mode. The turn pin moves to the Loop, and PromptSources owns the environment block. Refs #2135 --- docs/design/agent-tool-modes.md | 87 ++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 04fdaddeaf..136e76a170 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -114,18 +114,26 @@ program, so it adds `ask_user` and `recall`. `normal` declares the work tools. ### Goals in shell mode `shell` declares no `goal_update`, so a Session whose mode **in force** is `shell` cannot complete -or block a goal. Everything below keys on the mode in force — the value `session.tool_mode.get` -reports in `effective` — not on the mode the operator chose: a chosen `shell` without `execute` -runs `normal` and keeps `goal_update`. - -- Switching to an effective `shell` writes Goal's pause before the mode changes, so every turn that - starts in `shell` has the pause in its history. For each branch with an active goal, Goal writes - `paused` with reason `mode` and withdraws the continuation it queued when the InputQueue has not - applied it; an applied continuation belongs to a turn that started earlier, which pinned the old - mode and finishes under it. A cancelled update after the pause leaves the goal paused and the - mode unchanged; the operator resumes it. -- While `shell` is in force, a new continuation pauses the goal instead of continuing, so the model - is never asked to call a tool the mode does not declare. +or block a goal. Everything below keys on the mode in force — the `effective` value +`session.tool_mode.get` reports — never on the chosen mode. + +- **Trigger.** `ToolRegistry` publishes the effective mode to its readers. Goal settles on every + transition to an effective `shell` — an operator update, the entry tool registering, or an + exclusion change — not only on `session.tool_mode.update`. +- **Settle.** Goal writes `paused` with reason `mode`, a pause input text carrying that reason + (Goal state alone does not enter the model context), and withdraws the continuation it queued + when the InputQueue has not applied it. An applied continuation belongs to a turn that started + earlier, which pinned the old mode and finishes under it. +- **Order with an update.** The operator update runs: Goal settles (a committed effect), then the + record write, then the live mode. A failure before the record write leaves the mode unchanged and + the Goal pause in place; the operator resumes it. A Goal failure stops the update before the mode + changes. +- **Guarantee.** A turn that starts after the pause is committed carries the pause text in its + history, and its requests declare no `goal_update`. If a held continuation is released between a + registration transition and Goal's settle, that one turn can carry the continuation under + `shell`, and its `goal_update` call is refused as an unknown tool. Closing that window needs the + registry's transition to settle Goal before its projection flips; §12 records it. +- While `shell` is in force, a new continuation pauses the goal instead of continuing. - `session.goal.set` and `session.goal.resume` are refused while `shell` is in force, with a named error; `pause`, `edit`, `clear` and `get` keep working. - Leaving `shell` does not resume the goal: the operator resumes it explicitly, as Goal already @@ -193,8 +201,9 @@ owns this projection. Three terms: - A Code Mode program discovers and calls exactly the `delegated` set: `tools.list` and `tools.describe` project it, and `tools.call` admits inside it. `codemode` itself is never delegated, so a program cannot nest one. -- A turn pins the mode when it starts — when its driving input is applied — and every request of - the turn uses that pin, together with the callable set it pins today. A switch takes effect with +- The Loop holds the turn's mode: a turn pins it when it starts — when its driving input is + applied — and every request of the turn uses that pin, together with the callable set ToolBinding + pins today. A switch takes effect with the next turn and needs no re-adoption: the branch's configuration, the version pins and the source sets stay as they are. A request retried through its own source (an in-process budget recovery) keeps the pin; a process restart settles the in-flight request as the loop already does @@ -289,7 +298,7 @@ are its requirements; the ones marked missing are follow-up work, not part of th `codemode`: -- Discovery and call (`tools.list`, `tools.describe`, `tools.call`) over the request's pinned set, +- Discovery and call (`tools.list`, `tools.describe`, `tools.call`) over the turn's pinned set, everything except `codemode`. Exists. - **Content blocks on return.** A child result can carry image blocks (`read` of an image, an MCP result), and they reach the model only if the return path rebuilds them. When the returned value @@ -379,7 +388,8 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in instead of every adopted tool), the admission split (a child only inside `delegated`), and the outer result rebuilding content blocks instead of serializing the program value as JSON. Its child-event contract is unchanged. -- [Goal](plugins/Goal.md) gains the shell lifecycle in §2. +- [Goal](plugins/Goal.md) gains the shell lifecycle in §2, and + [PromptSources](plugins/PromptSources.md) gains the mode-aware environment block. - The remaining contracts gain the mode with the implementation, each by its owner: `SessionConfig.toolMode` in [session access](contracts/session-access.md), and the live mode plus projection in [ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md). @@ -415,12 +425,15 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in - Flow: restore a record without the field, and fork a Session; both keep `normal` and the source mode respectively, except that the minimal-execution host restores its Sessions as `shell`. - Flow: a goal with a queued continuation, switched to an effective `shell` before it is applied: - the continuation is withdrawn, the goal pauses (`mode`), and no turn carrying the `goal_update` - instruction starts in `shell`. Switched after it is applied, that turn pinned the old mode and - finishes under it. The pause is written before the live mode, so a turn that starts in `shell` - has it in history; a cancelled update after the pause leaves the goal paused and the mode - unchanged. `set`/`resume` are refused while `shell` is in force; a chosen `shell` that runs - `normal` (no `execute`) neither pauses nor refuses; after leaving, the operator resumes the goal. + the continuation is withdrawn, the goal pauses (`mode`) with its pause text, and no turn carrying + the `goal_update` instruction starts in `shell`. Switched after it is applied, that turn pinned + the old mode and finishes under it. The same settle runs when `execute` registers and makes + `shell` effective without an update; a held continuation released in that window can reach one + turn, whose `goal_update` call is refused. The pause is committed before the record write and the + live mode, so a turn that starts in `shell` has the pause text in history; a cancelled update + after the pause leaves the goal paused and the mode unchanged. `set`/`resume` are refused while + `shell` is in force; a chosen `shell` that runs `normal` (no `execute`) neither pauses nor + refuses; after leaving, the operator resumes the goal. - Flow: stop a shell task with `session.exec.stop` after switching the Session to `normal`; the route resolves the live `ExecStop` before `BackgroundExec`, and neither answers for a live task from history. The minimal-execution profile's Session runs `shell` and keeps `execute`. @@ -449,8 +462,9 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in `session.language`: the current value lives in the registry, the durable copy in the stored record. - §7.1 for the live mode: the resource is the value; lifecycle is the Session's; the operations are - `get` and `update`. A cancellation before the record write changes nothing; after it the new value - stays stored and in force. Both report the effective mode rather than refusing one. + `get` and `update`. A cancellation before the record write leaves the mode pair unchanged; a Goal + pause already committed stays. After the record write, the new value stays stored and in force. + Both report the effective mode rather than refusing one. - §7.2: no object or resource handle crosses an owner; no new service, and the mode methods join the existing Session method face; the parameters are data. - [ADR 002](../adr/002-plugin-scope.md) D1: the mode is Session configuration and the pinned mode is @@ -461,17 +475,24 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in None for the mechanism. One requirement goes to another capability's owner: +Requirements go to other owners: + - **Goal.** Read the mode in force, the value `session.tool_mode.get` reports in `effective`, never - the chosen mode. When a switch makes `shell` effective, write the pause before the live mode - changes: pause each branch's active goal (`mode`) and withdraw a continuation the InputQueue has - not applied; while `shell` is in force, pause new continuations and refuse `session.goal.set` and + the chosen mode. Settle on every transition to an effective `shell`, including the entry tool + registering or an exclusion change: write `paused` (`mode`), a pause text carrying the reason, + and withdraw a continuation the InputQueue has not applied, before the record write and the live + mode; while `shell` is in force, pause new continuations and refuse `session.goal.set` and `resume`; leave resumption to the operator after `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). -- **PromptSources.** The environment block follows the surface: in `shell` mode it drops the - Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into - [PromptSources](plugins/PromptSources.md). +- **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration or + exclusion transition, and make that transition settle Goal before the projection flips; until it + does, the one-turn window in §2 stands. +- **PromptSources.** The environment block follows the surface: while `shell` is in force (the + `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its + owner carries this into [PromptSources](plugins/PromptSources.md). Everything else stays within the owners that already exist: ToolRegistry projects its own set and -holds the live mode, ToolBinding pins the mode with the callable set, ToolExecution refuses a call -outside it, ContextUsage counts `visible`, the App Server owns the stored record and the Session -methods, and each client owns its control and its remembered choice. +holds the live mode, the Loop holds the turn's mode pin, ToolBinding pins the callable set, +ToolExecution refuses a call outside the turn's sets, ContextUsage counts `visible`, the App Server +owns the stored record and the Session methods, and each client owns its control and its remembered +choice. From ad433f40e8b0c836409559e82593fb39fcbbf3d2 Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 00:25:10 +0800 Subject: [PATCH 16/28] docs: name the goal settle caller and the turn pin owner The update passes the pending mode to Goal before the record write; a registration transition settles on the registry's published effective mode. The Goal Session part fans out per branch, the Loop holds the turn pin, and section 5 states the update order the rest of the document uses. Refs #2135 --- docs/design/agent-tool-modes.md | 62 ++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 136e76a170..4d7c17bccf 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -117,22 +117,24 @@ program, so it adds `ask_user` and `recall`. `normal` declares the work tools. or block a goal. Everything below keys on the mode in force — the `effective` value `session.tool_mode.get` reports — never on the chosen mode. -- **Trigger.** `ToolRegistry` publishes the effective mode to its readers. Goal settles on every - transition to an effective `shell` — an operator update, the entry tool registering, or an - exclusion change — not only on `session.tool_mode.update`. -- **Settle.** Goal writes `paused` with reason `mode`, a pause input text carrying that reason - (Goal state alone does not enter the model context), and withdraws the continuation it queued - when the InputQueue has not applied it. An applied continuation belongs to a turn that started - earlier, which pinned the old mode and finishes under it. -- **Order with an update.** The operator update runs: Goal settles (a committed effect), then the - record write, then the live mode. A failure before the record write leaves the mode unchanged and - the Goal pause in place; the operator resumes it. A Goal failure stops the update before the mode - changes. +- **Update.** `session.tool_mode.update` calls Goal's settle operation with the pending mode before + the record write and waits for it. Goal settles only when that mode would be effective `shell` — + its entry tool is in the callable set — because a chosen `shell` without `execute` runs `normal`. +- **Registration.** When the entry tool registers or withdraws and makes `shell` effective without + an update, `ToolRegistry` publishes the effective mode; Goal settles on that signal. A held + continuation released before Goal settles can reach one turn under `shell`, and its `goal_update` + call is refused as an unknown tool. Closing that window needs a pre-change signal from the + registry; §12 records it. +- **Settle.** The Goal Session part fans out to every branch with an active goal: it writes + `paused` with reason `mode`, a pause input text carrying that reason (Goal state alone does not + enter the model context), and withdraws the continuation it queued when the InputQueue has not + applied it. An applied continuation belongs to a turn that started earlier, which pinned the old + mode and finishes under it. +- **Order.** The update runs: Goal settles, the record is written, the live mode is replaced. A + failure before the record write leaves the mode pair unchanged and a committed Goal pause in + place, and the operator resumes it; a Goal failure stops the update before the mode changes. - **Guarantee.** A turn that starts after the pause is committed carries the pause text in its - history, and its requests declare no `goal_update`. If a held continuation is released between a - registration transition and Goal's settle, that one turn can carry the continuation under - `shell`, and its `goal_update` call is refused as an unknown tool. Closing that window needs the - registry's transition to settle Goal before its projection flips; §12 records it. + history, and its requests declare no `goal_update`. - While `shell` is in force, a new continuation pauses the goal instead of continuing. - `session.goal.set` and `session.goal.resume` are refused while `shell` is in force, with a named error; `pause`, `edit`, `clear` and `get` keep working. @@ -391,8 +393,9 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in - [Goal](plugins/Goal.md) gains the shell lifecycle in §2, and [PromptSources](plugins/PromptSources.md) gains the mode-aware environment block. - The remaining contracts gain the mode with the implementation, each by its owner: - `SessionConfig.toolMode` in [session access](contracts/session-access.md), and the live mode plus - projection in [ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md). + `SessionConfig.toolMode` in [session access](contracts/session-access.md), the live mode plus + projection in [ToolRegistry](../architecture/rust-agent/plugins/ToolRegistry.md), and the turn's + mode pin in [Loop](../architecture/rust-agent/plugins/Loop.md). - A Session restored from a record that predates this field becomes `normal`, except in the minimal-execution profile, whose host sets `shell` on create and restore (§6). A Session that used the `codemode` tool therefore loses it on upgrade until the operator selects `codemode`. That is @@ -455,7 +458,8 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in registry that applies them, not to core infrastructure. - §4 rule 5: no batches. - §4 rule 6: the visible set is exactly what the request declares; no new context path. -- §4 rule 7: parts coordinate through the Session configuration and the registry's own read. +- §4 rule 7: parts coordinate through the Session configuration, the registry's read, and the Goal + owner's settle operation (§2), which the App Server calls and the registry signals. - §4 rule 8: no infrastructure change; the product profile's tool wiring changes (§6), while Timeline, Dispatcher, the event envelope, rutis assembly and the Session facades are untouched. - §4 rule 9: the mode is Session configuration, not a Timeline fact, and follows @@ -473,23 +477,25 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in and changed by its owner's operation. D5: the mode methods take data. ## 12. Requirements raised to mechanism owners -None for the mechanism. One requirement goes to another capability's owner: - Requirements go to other owners: - **Goal.** Read the mode in force, the value `session.tool_mode.get` reports in `effective`, never - the chosen mode. Settle on every transition to an effective `shell`, including the entry tool - registering or an exclusion change: write `paused` (`mode`), a pause text carrying the reason, - and withdraw a continuation the InputQueue has not applied, before the record write and the live - mode; while `shell` is in force, pause new continuations and refuse `session.goal.set` and - `resume`; leave resumption to the operator after `shell` leaves. Its owner carries this into - [Goal](plugins/Goal.md). + the chosen mode. Settle on every transition to an effective `shell`: on an update, when the App + Server calls it with the pending mode before the record write; on a registration or withdrawal, on + the registry's published effective mode. Fan out from the Goal Session part to every branch with + an active goal: write `paused` (`mode`), a pause text carrying the reason, and withdraw a + continuation the InputQueue has not applied. While `shell` is in force, pause new continuations + and refuse `session.goal.set` and `resume`; leave resumption to the operator after `shell` + leaves. Its owner carries this into [Goal](plugins/Goal.md). - **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration or - exclusion transition, and make that transition settle Goal before the projection flips; until it - does, the one-turn window in §2 stands. + withdrawal transition; a pre-change signal that lets Goal settle before the projection flips + closes the one-turn window in §2. - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). +- **Loop.** Read the effective mode when the driving input is applied and hold it for the turn; + its page gains the turn's mode pin. Its owner carries this into + [Loop](../architecture/rust-agent/plugins/Loop.md). Everything else stays within the owners that already exist: ToolRegistry projects its own set and holds the live mode, the Loop holds the turn's mode pin, ToolBinding pins the callable set, From 42d71970114917411e88920bb65bb13a7d5df81e Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 00:47:39 +0800 Subject: [PATCH 17/28] docs: state the update order in section 5 and close the goal wording Section 5 now carries the Goal, record, live order and the failure rule. Only a registration makes shell effective; a withdrawal runs normal and does not resume. The pre-change signal requirement is dropped in favour of the documented one-turn window, and the pending-mode exception is explicit. Refs #2135 --- docs/design/agent-tool-modes.md | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 4d7c17bccf..35f404d169 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -115,16 +115,17 @@ program, so it adds `ask_user` and `recall`. `normal` declares the work tools. `shell` declares no `goal_update`, so a Session whose mode **in force** is `shell` cannot complete or block a goal. Everything below keys on the mode in force — the `effective` value -`session.tool_mode.get` reports — never on the chosen mode. +`session.tool_mode.get` reports — never on the chosen mode. The one exception is an update, which +hands Goal the pending mode and Goal checks that it would be effective. - **Update.** `session.tool_mode.update` calls Goal's settle operation with the pending mode before the record write and waits for it. Goal settles only when that mode would be effective `shell` — its entry tool is in the callable set — because a chosen `shell` without `execute` runs `normal`. -- **Registration.** When the entry tool registers or withdraws and makes `shell` effective without - an update, `ToolRegistry` publishes the effective mode; Goal settles on that signal. A held - continuation released before Goal settles can reach one turn under `shell`, and its `goal_update` - call is refused as an unknown tool. Closing that window needs a pre-change signal from the - registry; §12 records it. +- **Registration.** When the entry tool registers and makes `shell` effective without an update, + `ToolRegistry` publishes the effective mode; Goal settles on that signal. A held continuation + released before Goal settles can reach one turn under `shell`, and its `goal_update` call is + refused as an unknown tool; that window is accepted. A withdrawal that removes the entry tool + runs `normal` and does not resume a paused goal. - **Settle.** The Goal Session part fans out to every branch with an active goal: it writes `paused` with reason `mode`, a pause input text carrying that reason (Goal state alone does not enter the model context), and withdraws the continuation it queued when the InputQueue has not @@ -242,10 +243,11 @@ The mode is live for the Session's lifetime: it when it starts; nothing re-adopts a tool set when it changes. - `session.tool_mode.get` returns `{mode, effective}`: the mode the operator chose and the one in force. A mode whose entry tool is absent stays chosen and is not in force; that is the fallback. - `session.tool_mode.update` follows `session.language.update`'s order: a failure before the record - write changes nothing; once the record is written the live value is replaced, and a later - cancellation keeps the new value stored, so the two do not diverge. The pair is advertised as - `session.tool_mode`, like `session.language`. + `session.tool_mode.update` runs, in order: Goal settles for the pending mode when it would be + effective `shell` (§2), the record is written, the live value is replaced. A failure before the + record write leaves the mode pair unchanged and a committed Goal pause in place; once the record + is written, a later cancellation keeps the new value stored, so the record and the live value do + not diverge. The pair is advertised as `session.tool_mode`, like `session.language`. - The model has no tool for this; it is a client method only. ```text @@ -480,16 +482,16 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in Requirements go to other owners: - **Goal.** Read the mode in force, the value `session.tool_mode.get` reports in `effective`, never - the chosen mode. Settle on every transition to an effective `shell`: on an update, when the App - Server calls it with the pending mode before the record write; on a registration or withdrawal, on - the registry's published effective mode. Fan out from the Goal Session part to every branch with + the chosen mode. On an update, take the pending mode from the App Server and check its entry tool + in the callable set; the general lifecycle reads the effective mode. Settle on every transition to + an effective `shell`: on an update, before the record write; on a registration, on the registry's + published effective mode. Fan out from the Goal Session part to every branch with an active goal: write `paused` (`mode`), a pause text carrying the reason, and withdraw a continuation the InputQueue has not applied. While `shell` is in force, pause new continuations and refuse `session.goal.set` and `resume`; leave resumption to the operator after `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). -- **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration or - withdrawal transition; a pre-change signal that lets Goal settle before the projection flips - closes the one-turn window in §2. +- **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration + transition; the one-turn window in §2 stands. - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). From 75d7bd2a8733eaa7e0eb71999020428514c8c1e7 Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 01:10:05 +0800 Subject: [PATCH 18/28] docs: scope the goal guarantee to a shell turn A failed update leaves the old mode in force, so a normal turn still declares goal_update while the goal is paused. The guarantee is scoped to a turn that starts in shell, and the cancellation point is named. Refs #2135 --- docs/design/agent-tool-modes.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 35f404d169..12f3f52eaf 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -134,8 +134,9 @@ hands Goal the pending mode and Goal checks that it would be effective. - **Order.** The update runs: Goal settles, the record is written, the live mode is replaced. A failure before the record write leaves the mode pair unchanged and a committed Goal pause in place, and the operator resumes it; a Goal failure stops the update before the mode changes. -- **Guarantee.** A turn that starts after the pause is committed carries the pause text in its - history, and its requests declare no `goal_update`. +- **Guarantee.** A turn that starts in `shell` after the pause is committed carries the pause text + in its history, and its requests declare no `goal_update`. A failed update leaves the old mode in + force, as above, so a `normal` turn still declares `goal_update` while the goal is paused. - While `shell` is in force, a new continuation pauses the goal instead of continuing. - `session.goal.set` and `session.goal.resume` are refused while `shell` is in force, with a named error; `pause`, `edit`, `clear` and `get` keep working. @@ -436,9 +437,9 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in `shell` effective without an update; a held continuation released in that window can reach one turn, whose `goal_update` call is refused. The pause is committed before the record write and the live mode, so a turn that starts in `shell` has the pause text in history; a cancelled update - after the pause leaves the goal paused and the mode unchanged. `set`/`resume` are refused while - `shell` is in force; a chosen `shell` that runs `normal` (no `execute`) neither pauses nor - refuses; after leaving, the operator resumes the goal. + after the pause and before the record write leaves the goal paused and the mode unchanged. + `set`/`resume` are refused while `shell` is in force; a chosen `shell` that runs `normal` (no + `execute`) neither pauses nor refuses; after leaving, the operator resumes the goal. - Flow: stop a shell task with `session.exec.stop` after switching the Session to `normal`; the route resolves the live `ExecStop` before `BackgroundExec`, and neither answers for a live task from history. The minimal-execution profile's Session runs `shell` and keeps `execute`. From fc9923afb9069deecaa3d937b4d57b549eaf6a3d Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 10:05:04 +0800 Subject: [PATCH 19/28] docs: order goal activation against the mode publish The update and goal set/resume share the Session's mode gate: the update holds it from the settle through the live publish, and activation checks the effective mode at its commit boundary, so a resume in that interval is refused and one before the settle is paused and withdrawn. Refs #2135 --- docs/design/agent-tool-modes.md | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 12f3f52eaf..309d76b50d 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -131,9 +131,14 @@ hands Goal the pending mode and Goal checks that it would be effective. enter the model context), and withdraws the continuation it queued when the InputQueue has not applied it. An applied continuation belongs to a turn that started earlier, which pinned the old mode and finishes under it. -- **Order.** The update runs: Goal settles, the record is written, the live mode is replaced. A - failure before the record write leaves the mode pair unchanged and a committed Goal pause in - place, and the operator resumes it; a Goal failure stops the update before the mode changes. +- **Order.** The update runs, under the Session's mode gate: Goal settles, the record is written, + the live mode is replaced. A failure before the record write leaves the mode pair unchanged and a + committed Goal pause in place, and the operator resumes it; a Goal failure stops the update before + the mode changes. +- **Activation.** `session.goal.set` and `resume` take the same mode gate and check the effective + mode at their commit boundary. A `resume` that arrives after the settle and before the publish + waits on the gate and is refused once `shell` is effective; one that commits before the settle is + paused, and its unapplied continuation is withdrawn, by the settle. Either interleaving is safe. - **Guarantee.** A turn that starts in `shell` after the pause is committed carries the pause text in its history, and its requests declare no `goal_update`. A failed update leaves the old mode in force, as above, so a `normal` turn still declares `goal_update` while the goal is paused. @@ -430,6 +435,9 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in unchanged. - Flow: restore a record without the field, and fork a Session; both keep `normal` and the source mode respectively, except that the minimal-execution host restores its Sessions as `shell`. +- Flow: a `resume` arriving after the update's settle and before the live publish waits on the mode + gate and is refused because `shell` is effective; one arriving before the settle commits and the + settle pauses it and withdraws its unapplied continuation. - Flow: a goal with a queued continuation, switched to an effective `shell` before it is applied: the continuation is withdrawn, the goal pauses (`mode`) with its pause text, and no turn carrying the `goal_update` instruction starts in `shell`. Switched after it is applied, that turn pinned @@ -484,15 +492,17 @@ Requirements go to other owners: - **Goal.** Read the mode in force, the value `session.tool_mode.get` reports in `effective`, never the chosen mode. On an update, take the pending mode from the App Server and check its entry tool - in the callable set; the general lifecycle reads the effective mode. Settle on every transition to - an effective `shell`: on an update, before the record write; on a registration, on the registry's - published effective mode. Fan out from the Goal Session part to every branch with - an active goal: write `paused` (`mode`), a pause text carrying the reason, and withdraw a - continuation the InputQueue has not applied. While `shell` is in force, pause new continuations - and refuse `session.goal.set` and `resume`; leave resumption to the operator after `shell` - leaves. Its owner carries this into [Goal](plugins/Goal.md). + in the callable set; the general lifecycle reads the effective mode. Take the Session's mode gate + around `set` and `resume` and re-check the effective mode at their commit boundary. Settle on + every transition to an effective `shell`: on an update, before the record write; on a + registration, on the registry's published effective mode. Fan out from the Goal Session part to + every branch with an active goal: write `paused` (`mode`), a pause text carrying the reason, and + withdraw a continuation the InputQueue has not applied. While `shell` is in force, pause new + continuations and refuse `session.goal.set` and `resume`; leave resumption to the operator after + `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). - **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration - transition; the one-turn window in §2 stands. + transition, and provide the Session's mode gate the update holds and Goal's `set`/`resume` take; + the one-turn window in §2 stands. - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). From a3b85a85298c3e9ea0262b459025c6fb276052e0 Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 10:27:08 +0800 Subject: [PATCH 20/28] docs: withdraw the goal trigger as well as the continuation A set or resume queues its driving trigger, not only an automatic continuation, so the settle withdraws both when the InputQueue has not applied them. The update order is stated once in section 5 and referenced elsewhere. Refs #2135 --- docs/design/agent-tool-modes.md | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 309d76b50d..2dabad89a9 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -128,17 +128,16 @@ hands Goal the pending mode and Goal checks that it would be effective. runs `normal` and does not resume a paused goal. - **Settle.** The Goal Session part fans out to every branch with an active goal: it writes `paused` with reason `mode`, a pause input text carrying that reason (Goal state alone does not - enter the model context), and withdraws the continuation it queued when the InputQueue has not - applied it. An applied continuation belongs to a turn that started earlier, which pinned the old - mode and finishes under it. -- **Order.** The update runs, under the Session's mode gate: Goal settles, the record is written, - the live mode is replaced. A failure before the record write leaves the mode pair unchanged and a - committed Goal pause in place, and the operator resumes it; a Goal failure stops the update before - the mode changes. + enter the model context), and withdraws the input it queued — the `set`/`resume` trigger and any + automatic continuation — when the InputQueue has not applied it. An applied input belongs to a + turn that started earlier, which pinned the old mode and finishes under it. +- **Order.** The update runs under the Session's mode gate with Goal's settle first; its order and + failure rule are §5's. A Goal failure stops the update before the mode changes. - **Activation.** `session.goal.set` and `resume` take the same mode gate and check the effective mode at their commit boundary. A `resume` that arrives after the settle and before the publish waits on the gate and is refused once `shell` is effective; one that commits before the settle is - paused, and its unapplied continuation is withdrawn, by the settle. Either interleaving is safe. + paused, and its unapplied trigger and continuation are withdrawn, by the settle. Either + interleaving is safe. - **Guarantee.** A turn that starts in `shell` after the pause is committed carries the pause text in its history, and its requests declare no `goal_update`. A failed update leaves the old mode in force, as above, so a `normal` turn still declares `goal_update` while the goal is paused. @@ -436,8 +435,8 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in - Flow: restore a record without the field, and fork a Session; both keep `normal` and the source mode respectively, except that the minimal-execution host restores its Sessions as `shell`. - Flow: a `resume` arriving after the update's settle and before the live publish waits on the mode - gate and is refused because `shell` is effective; one arriving before the settle commits and the - settle pauses it and withdraws its unapplied continuation. + gate and is refused because `shell` is effective; one that commits before the settle is paused by + the settle, which withdraws its unapplied trigger and continuation. - Flow: a goal with a queued continuation, switched to an effective `shell` before it is applied: the continuation is withdrawn, the goal pauses (`mode`) with its pause text, and no turn carrying the `goal_update` instruction starts in `shell`. Switched after it is applied, that turn pinned @@ -469,8 +468,9 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in registry that applies them, not to core infrastructure. - §4 rule 5: no batches. - §4 rule 6: the visible set is exactly what the request declares; no new context path. -- §4 rule 7: parts coordinate through the Session configuration, the registry's read, and the Goal - owner's settle operation (§2), which the App Server calls and the registry signals. +- §4 rule 7: parts coordinate through the Session configuration, the registry's read, the Goal + owner's settle operation (§2), and the Session's mode gate, which is a synchronization primitive, + not business state. - §4 rule 8: no infrastructure change; the product profile's tool wiring changes (§6), while Timeline, Dispatcher, the event envelope, rutis assembly and the Session facades are untouched. - §4 rule 9: the mode is Session configuration, not a Timeline fact, and follows @@ -481,7 +481,8 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in pause already committed stays. After the record write, the new value stays stored and in force. Both report the effective mode rather than refusing one. - §7.2: no object or resource handle crosses an owner; no new service, and the mode methods join - the existing Session method face; the parameters are data. + the existing Session method face; the parameters are data. The mode gate is a synchronization + primitive, not a service or a value. - [ADR 002](../adr/002-plugin-scope.md) D1: the mode is Session configuration and the pinned mode is branch state. D2: no wiring module. D3: ToolRegistry keeps no hard dependency on Code Mode; an absent or excluded `codemode` falls back to `normal`. D4: business configuration, read at creation @@ -497,9 +498,10 @@ Requirements go to other owners: every transition to an effective `shell`: on an update, before the record write; on a registration, on the registry's published effective mode. Fan out from the Goal Session part to every branch with an active goal: write `paused` (`mode`), a pause text carrying the reason, and - withdraw a continuation the InputQueue has not applied. While `shell` is in force, pause new - continuations and refuse `session.goal.set` and `resume`; leave resumption to the operator after - `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). + withdraw the `set`/`resume` trigger and any continuation the InputQueue has not applied. While + `shell` is in force, pause new continuations and refuse `session.goal.set` and `resume`; leave + resumption to the operator after `shell` leaves. Its owner carries this into + [Goal](plugins/Goal.md). - **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration transition, and provide the Session's mode gate the update holds and Goal's `set`/`resume` take; the one-turn window in §2 stands. From 1274e4c3ad1d99dc2b4d9211ee0903e429de7093 Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 10:39:30 +0800 Subject: [PATCH 21/28] docs: pin the mode when the turn starts An input can be applied and wait for compaction, or be recovered after a restart, before its turn starts. Pinning at turn start makes that interval use the mode in force then; the Goal pause precedes the live mode, so a shell turn still has it in history. Refs #2135 --- docs/design/agent-tool-modes.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 2dabad89a9..9f0c8a00e2 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -209,13 +209,16 @@ owns this projection. Three terms: - A Code Mode program discovers and calls exactly the `delegated` set: `tools.list` and `tools.describe` project it, and `tools.call` admits inside it. `codemode` itself is never delegated, so a program cannot nest one. -- The Loop holds the turn's mode: a turn pins it when it starts — when its driving input is - applied — and every request of the turn uses that pin, together with the callable set ToolBinding - pins today. A switch takes effect with - the next turn and needs no re-adoption: the branch's configuration, the version pins and the - source sets stay as they are. A request retried through its own source (an in-process budget - recovery) keeps the pin; a process restart settles the in-flight request as the loop already does - and does not reissue it; the request that follows a tool result keeps the turn's pin. +- The Loop holds the turn's mode: a turn pins it when it starts, before its first request is + prepared, not when its input is applied. A turn deferred while compaction runs, or recovered + after a restart, therefore starts under the mode in force when it actually starts; the Goal pause + is written before the live mode, so a turn that starts in `shell` has it in history. Every request + of the turn uses the pin, together with the callable set ToolBinding pins today. A switch takes + effect with the next turn and needs no re-adoption: the branch's configuration, the version pins + and the source sets stay as they are. A request retried through its own source (an in-process + budget recovery) keeps the pin; a process restart settles the in-flight request as the loop + already does and does not reissue it; the request that follows a tool result keeps the turn's + pin. - A tool that is only delegated never appears in a prompt, a declaration or the usage counter; `skill` is in both sets. - The mount list and an Agent profile's tool list narrow the surface and never widen it. `normal` @@ -428,6 +431,9 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in request after a tool result in the same turn keeps the turn's pin, an in-process budget recovery keeps its pin, a process restart settles the in-flight request without reissuing it, and a call already admitted finishes. +- Flow: a turn whose input is applied but which is deferred for compaction, or recovered after a + restart, pins the mode when it starts; a switch in that interval applies to it, and a turn that + starts in `shell` has the Goal pause in its history. - Flow: fallback — a mode whose entry tool is absent stays chosen in `get` and is reported as not in force; the Session declares the `normal` surface. - Flow: a member created under `codemode` records it; switching the creator leaves the member @@ -508,9 +514,9 @@ Requirements go to other owners: - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). -- **Loop.** Read the effective mode when the driving input is applied and hold it for the turn; - its page gains the turn's mode pin. Its owner carries this into - [Loop](../architecture/rust-agent/plugins/Loop.md). +- **Loop.** Read the effective mode when the turn starts and hold it for the turn, including a + turn deferred for compaction or recovered after a restart; its page gains the turn's mode pin. + Its owner carries this into [Loop](../architecture/rust-agent/plugins/Loop.md). Everything else stays within the owners that already exist: ToolRegistry projects its own set and holds the live mode, the Loop holds the turn's mode pin, ToolBinding pins the callable set, From 9ecf4d4b257f6c411619fa4078a019c0b5e89750 Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 10:51:28 +0800 Subject: [PATCH 22/28] docs: reconcile the goal settle with the turn-start pin An applied input is not withdrawn by the settle; its turn pins the mode when it starts. A turn that already started keeps its pin and one that starts after the switch pins shell with the pause text. The pause text is an Append input with a mode phrase, and the registration transition takes the mode gate. Refs #2135 --- docs/design/agent-tool-modes.md | 40 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 9f0c8a00e2..dad181e2a8 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -122,15 +122,17 @@ hands Goal the pending mode and Goal checks that it would be effective. the record write and waits for it. Goal settles only when that mode would be effective `shell` — its entry tool is in the callable set — because a chosen `shell` without `execute` runs `normal`. - **Registration.** When the entry tool registers and makes `shell` effective without an update, - `ToolRegistry` publishes the effective mode; Goal settles on that signal. A held continuation - released before Goal settles can reach one turn under `shell`, and its `goal_update` call is - refused as an unknown tool; that window is accepted. A withdrawal that removes the entry tool - runs `normal` and does not resume a paused goal. + `ToolRegistry` publishes the effective mode and takes the Session's mode gate around the + effective-mode change and Goal's settle. A held continuation released before Goal settles can + reach one turn under `shell`, and its `goal_update` call is refused as an unknown tool; that + window is accepted. A withdrawal that removes the entry tool runs `normal` and does not resume a + paused goal. - **Settle.** The Goal Session part fans out to every branch with an active goal: it writes - `paused` with reason `mode`, a pause input text carrying that reason (Goal state alone does not - enter the model context), and withdraws the input it queued — the `set`/`resume` trigger and any - automatic continuation — when the InputQueue has not applied it. An applied input belongs to a - turn that started earlier, which pinned the old mode and finishes under it. + `paused` with reason `mode`, a pause input text with a `mode` phrase as an `Append` input, so it + precedes the next turn (Goal state alone does not enter the model context), and withdraws the + input it queued — the `set`/`resume` trigger and any automatic continuation — when the InputQueue + has not applied it. An applied input was already handed over; the settle does not withdraw it. + Its turn pins the mode in force when it starts (§4). - **Order.** The update runs under the Session's mode gate with Goal's settle first; its order and failure rule are §5's. A Goal failure stops the update before the mode changes. - **Activation.** `session.goal.set` and `resume` take the same mode gate and check the effective @@ -140,7 +142,8 @@ hands Goal the pending mode and Goal checks that it would be effective. interleaving is safe. - **Guarantee.** A turn that starts in `shell` after the pause is committed carries the pause text in its history, and its requests declare no `goal_update`. A failed update leaves the old mode in - force, as above, so a `normal` turn still declares `goal_update` while the goal is paused. + force, as above, so a `normal` turn still declares `goal_update`, when it is mounted, while the + goal is paused. - While `shell` is in force, a new continuation pauses the goal instead of continuing. - `session.goal.set` and `session.goal.resume` are refused while `shell` is in force, with a named error; `pause`, `edit`, `clear` and `get` keep working. @@ -211,8 +214,9 @@ owns this projection. Three terms: delegated, so a program cannot nest one. - The Loop holds the turn's mode: a turn pins it when it starts, before its first request is prepared, not when its input is applied. A turn deferred while compaction runs, or recovered - after a restart, therefore starts under the mode in force when it actually starts; the Goal pause - is written before the live mode, so a turn that starts in `shell` has it in history. Every request + after a restart, therefore starts under the mode in force when it actually starts. On an update, + the Goal pause is committed before the live mode, so a turn that starts in `shell` after the pause + has it in history; a registration-window turn may start before the settle (§2). Every request of the turn uses the pin, together with the callable set ToolBinding pins today. A switch takes effect with the next turn and needs no re-adoption: the branch's configuration, the version pins and the source sets stay as they are. A request retried through its own source (an in-process @@ -445,8 +449,9 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in the settle, which withdraws its unapplied trigger and continuation. - Flow: a goal with a queued continuation, switched to an effective `shell` before it is applied: the continuation is withdrawn, the goal pauses (`mode`) with its pause text, and no turn carrying - the `goal_update` instruction starts in `shell`. Switched after it is applied, that turn pinned - the old mode and finishes under it. The same settle runs when `execute` registers and makes + the `goal_update` instruction starts in `shell`. Switched after it is applied, a turn that already + started keeps the old pin and finishes under it; one that was applied but starts after the switch + pins `shell` and carries the pause text. The same settle runs when `execute` registers and makes `shell` effective without an update; a held continuation released in that window can reach one turn, whose `goal_update` call is refused. The pause is committed before the record write and the live mode, so a turn that starts in `shell` has the pause text in history; a cancelled update @@ -503,14 +508,15 @@ Requirements go to other owners: around `set` and `resume` and re-check the effective mode at their commit boundary. Settle on every transition to an effective `shell`: on an update, before the record write; on a registration, on the registry's published effective mode. Fan out from the Goal Session part to - every branch with an active goal: write `paused` (`mode`), a pause text carrying the reason, and - withdraw the `set`/`resume` trigger and any continuation the InputQueue has not applied. While + every branch with an active goal: write `paused` (`mode`), a pause text with a `mode` phrase as an + `Append` input, and withdraw the `set`/`resume` trigger and any continuation the InputQueue has + not applied. While `shell` is in force, pause new continuations and refuse `session.goal.set` and `resume`; leave resumption to the operator after `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). - **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration - transition, and provide the Session's mode gate the update holds and Goal's `set`/`resume` take; - the one-turn window in §2 stands. + transition, and provide the Session's mode gate the update holds, the registration takes and + Goal's `set`/`resume` take; the one-turn window in §2 stands. - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). From 7bfbbd3d8f1f42619368ee317fd3e91552bb4c94 Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 18:45:51 +0800 Subject: [PATCH 23/28] docs: settle goal through an internal transition service The App Server cannot call Goal: Goal depends on it, not the reverse. Goal registers a settle handler with an internal tool-mode transition service in the Session; the update and the registration transition call it under the mode gate, so neither owner depends on the other. Refs #2135 --- docs/design/agent-tool-modes.md | 38 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index dad181e2a8..456cfaebee 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -118,12 +118,14 @@ or block a goal. Everything below keys on the mode in force — the `effective` `session.tool_mode.get` reports — never on the chosen mode. The one exception is an update, which hands Goal the pending mode and Goal checks that it would be effective. -- **Update.** `session.tool_mode.update` calls Goal's settle operation with the pending mode before - the record write and waits for it. Goal settles only when that mode would be effective `shell` — - its entry tool is in the callable set — because a chosen `shell` without `execute` runs `normal`. +- **Update.** The Session's tool-mode transition service (internal, in-process) carries the settle + handlers. Goal registers its handler in `apply`; `session.tool_mode.update` calls it with the + pending mode before the record write and waits. Goal settles only when that mode would be + effective `shell` — its entry tool is in the callable set — because a chosen `shell` without + `execute` runs `normal`. - **Registration.** When the entry tool registers and makes `shell` effective without an update, - `ToolRegistry` publishes the effective mode and takes the Session's mode gate around the - effective-mode change and Goal's settle. A held continuation released before Goal settles can + `ToolRegistry` takes the Session's mode gate and calls the transition service's settle before it + publishes the effective mode. A held continuation released before Goal settles can reach one turn under `shell`, and its `goal_update` call is refused as an unknown tool; that window is accepted. A withdrawal that removes the entry tool runs `normal` and does not resume a paused goal. @@ -479,9 +481,10 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in registry that applies them, not to core infrastructure. - §4 rule 5: no batches. - §4 rule 6: the visible set is exactly what the request declares; no new context path. -- §4 rule 7: parts coordinate through the Session configuration, the registry's read, the Goal - owner's settle operation (§2), and the Session's mode gate, which is a synchronization primitive, - not business state. +- §4 rule 7: parts coordinate through the Session configuration, the registry's read, the Session's + mode gate (a synchronization primitive, not business state), and the internal tool-mode + transition service, where Goal registers its settle handler (§2). The service is in-process and + carries no public face; neither the App Server nor the registry depends on Goal. - §4 rule 8: no infrastructure change; the product profile's tool wiring changes (§6), while Timeline, Dispatcher, the event envelope, rutis assembly and the Session facades are untouched. - §4 rule 9: the mode is Session configuration, not a Timeline fact, and follows @@ -491,9 +494,10 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in `get` and `update`. A cancellation before the record write leaves the mode pair unchanged; a Goal pause already committed stays. After the record write, the new value stays stored and in force. Both report the effective mode rather than refusing one. -- §7.2: no object or resource handle crosses an owner; no new service, and the mode methods join - the existing Session method face; the parameters are data. The mode gate is a synchronization - primitive, not a service or a value. +- §7.2: no object or resource handle crosses an owner; no new public service, and the mode methods + join the existing Session method face; the parameters are data. The mode gate is a + synchronization primitive, not a service or a value; the tool-mode transition service is an + internal in-process Session service, not a public face. - [ADR 002](../adr/002-plugin-scope.md) D1: the mode is Session configuration and the pinned mode is branch state. D2: no wiring module. D3: ToolRegistry keeps no hard dependency on Code Mode; an absent or excluded `codemode` falls back to `normal`. D4: business configuration, read at creation @@ -503,9 +507,10 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in Requirements go to other owners: - **Goal.** Read the mode in force, the value `session.tool_mode.get` reports in `effective`, never - the chosen mode. On an update, take the pending mode from the App Server and check its entry tool - in the callable set; the general lifecycle reads the effective mode. Take the Session's mode gate - around `set` and `resume` and re-check the effective mode at their commit boundary. Settle on + the chosen mode. Register the settle handler with the internal tool-mode transition service; on + an update, take the pending mode it passes and check its entry tool in the callable set; the + general lifecycle reads the effective mode. Take the Session's mode gate around `set` and + `resume` and re-check the effective mode at their commit boundary. Settle on every transition to an effective `shell`: on an update, before the record write; on a registration, on the registry's published effective mode. Fan out from the Goal Session part to every branch with an active goal: write `paused` (`mode`), a pause text with a `mode` phrase as an @@ -515,8 +520,9 @@ Requirements go to other owners: resumption to the operator after `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). - **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration - transition, and provide the Session's mode gate the update holds, the registration takes and - Goal's `set`/`resume` take; the one-turn window in §2 stands. + transition; provide the Session's mode gate the update holds, the registration takes and Goal's + `set`/`resume` take; call the transition service on a registration before publishing. The + one-turn window in §2 stands. - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). From 2a488298e94977dabe6c5197fdbc6472e35678de Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 19:22:13 +0800 Subject: [PATCH 24/28] docs: pass the mode to the transition service A registration calls settle(shell, registration) before it publishes, so the handler takes the mode and cause as data and never reads the published value. The service names its provider, operation, handler lifetime, no-handler and failure rules; the registration acceptance flow is in section 10. Refs #2135 --- docs/design/agent-tool-modes.md | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 456cfaebee..cf80bb9357 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -118,17 +118,21 @@ or block a goal. Everything below keys on the mode in force — the `effective` `session.tool_mode.get` reports — never on the chosen mode. The one exception is an update, which hands Goal the pending mode and Goal checks that it would be effective. -- **Update.** The Session's tool-mode transition service (internal, in-process) carries the settle - handlers. Goal registers its handler in `apply`; `session.tool_mode.update` calls it with the - pending mode before the record write and waits. Goal settles only when that mode would be - effective `shell` — its entry tool is in the callable set — because a chosen `shell` without - `execute` runs `normal`. +- **Service.** `ToolRegistry` provides the internal Session `ToolModeTransition` service. Its one + operation is `settle(mode, cause)`, with cause `update` or `registration`. Goal registers one + handler in `apply`; the registry removes it with the part's registration when the part unloads or + reloads. With no handler the call succeeds and changes nothing (no active Goal). A failure blocks + the record write for an update and the publish for a registration, and the caller reports it. +- **Update.** `session.tool_mode.update` calls `settle(pending, update)` before the record write and + waits. Goal settles only when that mode would be effective `shell` — its entry tool is in the + callable set — because a chosen `shell` without `execute` runs `normal`. - **Registration.** When the entry tool registers and makes `shell` effective without an update, - `ToolRegistry` takes the Session's mode gate and calls the transition service's settle before it - publishes the effective mode. A held continuation released before Goal settles can - reach one turn under `shell`, and its `goal_update` call is refused as an unknown tool; that - window is accepted. A withdrawal that removes the entry tool runs `normal` and does not resume a - paused goal. + `ToolRegistry` takes the Session's mode gate and calls `settle(shell, registration)` before it + publishes. The handler takes the mode and cause as data; it does not read the published value. A + failure leaves the projection at `normal` and records a fault. A held continuation released + before Goal settles can reach one turn under `shell`, and its `goal_update` call is refused as an + unknown tool; that window is accepted. A withdrawal that removes the entry tool runs `normal` + and does not resume a paused goal. - **Settle.** The Goal Session part fans out to every branch with an active goal: it writes `paused` with reason `mode`, a pause input text with a `mode` phrase as an `Append` input, so it precedes the next turn (Goal state alone does not enter the model context), and withdraws the @@ -449,6 +453,9 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in - Flow: a `resume` arriving after the update's settle and before the live publish waits on the mode gate and is refused because `shell` is effective; one that commits before the settle is paused by the settle, which withdraws its unapplied trigger and continuation. +- Flow: a registration that makes `shell` effective calls `settle(shell, registration)` before it + publishes; a `resume` that commits before that call is paused and withdrawn, and one that waits on + the gate is refused after the publish. A settle failure keeps the projection at `normal`. - Flow: a goal with a queued continuation, switched to an effective `shell` before it is applied: the continuation is withdrawn, the goal pauses (`mode`) with its pause text, and no turn carrying the `goal_update` instruction starts in `shell`. Switched after it is applied, a turn that already @@ -519,10 +526,9 @@ Requirements go to other owners: `shell` is in force, pause new continuations and refuse `session.goal.set` and `resume`; leave resumption to the operator after `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). -- **ToolRegistry.** Publish the effective mode to its readers so Goal settles on a registration - transition; provide the Session's mode gate the update holds, the registration takes and Goal's - `set`/`resume` take; call the transition service on a registration before publishing. The - one-turn window in §2 stands. +- **ToolRegistry.** Provide the `ToolModeTransition` service and the Session's mode gate; on a + registration, call `settle(shell, registration)` under the gate before publishing, and keep the + projection at `normal` on a failure. The one-turn window in §2 stands. - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). From 88929a5585e62698a140f1401adca6f33889b830 Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 19:33:50 +0800 Subject: [PATCH 25/28] docs: make the goal requirement take the transition data The Goal requirement still said a registration settles on the registry's published effective mode. It now takes (shell, registration) from the service before the registry publishes, like the other two passages. Refs #2135 --- docs/design/agent-tool-modes.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index cf80bb9357..26d8689b9b 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -513,18 +513,17 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in Requirements go to other owners: -- **Goal.** Read the mode in force, the value `session.tool_mode.get` reports in `effective`, never - the chosen mode. Register the settle handler with the internal tool-mode transition service; on - an update, take the pending mode it passes and check its entry tool in the callable set; the - general lifecycle reads the effective mode. Take the Session's mode gate around `set` and - `resume` and re-check the effective mode at their commit boundary. Settle on - every transition to an effective `shell`: on an update, before the record write; on a - registration, on the registry's published effective mode. Fan out from the Goal Session part to - every branch with an active goal: write `paused` (`mode`), a pause text with a `mode` phrase as an - `Append` input, and withdraw the `set`/`resume` trigger and any continuation the InputQueue has - not applied. While - `shell` is in force, pause new continuations and refuse `session.goal.set` and `resume`; leave - resumption to the operator after `shell` leaves. Its owner carries this into +- **Goal.** Register the settle handler with the internal `ToolModeTransition` service. The + handler receives `(mode, cause)` as data — `update` with the pending mode, `registration` with + `shell` — and settles on every transition to an effective `shell`, before the record write for an + update and before the registry publishes for a registration. It never reads the published value. + Fan out from the Goal Session part to every branch with an active goal: write `paused` (`mode`), a + pause text with a `mode` phrase as an `Append` input, and withdraw the `set`/`resume` trigger and + any continuation the InputQueue has not applied. For the general lifecycle, read the mode in + force, the value `session.tool_mode.get` reports in `effective`, never the chosen mode, and take + the Session's mode gate around `set` and `resume` to re-check the effective mode at their commit + boundary. While `shell` is in force, pause new continuations and refuse `session.goal.set` and + `resume`; leave resumption to the operator after `shell` leaves. Its owner carries this into [Goal](plugins/Goal.md). - **ToolRegistry.** Provide the `ToolModeTransition` service and the Session's mode gate; on a registration, call `settle(shell, registration)` under the gate before publishing, and keep the From 8f647665ac171e5dae5a59e35614db20df21239a Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 19:42:13 +0800 Subject: [PATCH 26/28] docs: close the registration window with the mode gate The registration holds the gate from before the settle through the publish, and the turn-start read takes the same gate, so no turn pins shell before the pause and the withdrawals commit. The pause text's Append order puts it before the first request's history cutoff. Refs #2135 --- docs/design/agent-tool-modes.md | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 26d8689b9b..a971f051ca 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -127,12 +127,12 @@ hands Goal the pending mode and Goal checks that it would be effective. waits. Goal settles only when that mode would be effective `shell` — its entry tool is in the callable set — because a chosen `shell` without `execute` runs `normal`. - **Registration.** When the entry tool registers and makes `shell` effective without an update, - `ToolRegistry` takes the Session's mode gate and calls `settle(shell, registration)` before it - publishes. The handler takes the mode and cause as data; it does not read the published value. A - failure leaves the projection at `normal` and records a fault. A held continuation released - before Goal settles can reach one turn under `shell`, and its `goal_update` call is refused as an - unknown tool; that window is accepted. A withdrawal that removes the entry tool runs `normal` - and does not resume a paused goal. + `ToolRegistry` holds the Session's mode gate from before `settle(shell, registration)` through + the publish. The handler takes the mode and cause as data; it does not read the published value. + The Loop's turn-start read takes the same gate, so no turn pins `shell` before the pause text and + the withdrawals are committed; a `set`/`resume` that waits on the gate is refused after the + publish. A failure leaves the projection at `normal` and records a fault. A withdrawal that + removes the entry tool runs `normal` and does not resume a paused goal. - **Settle.** The Goal Session part fans out to every branch with an active goal: it writes `paused` with reason `mode`, a pause input text with a `mode` phrase as an `Append` input, so it precedes the next turn (Goal state alone does not enter the model context), and withdraws the @@ -222,7 +222,8 @@ owns this projection. Three terms: prepared, not when its input is applied. A turn deferred while compaction runs, or recovered after a restart, therefore starts under the mode in force when it actually starts. On an update, the Goal pause is committed before the live mode, so a turn that starts in `shell` after the pause - has it in history; a registration-window turn may start before the settle (§2). Every request + has it in history; a turn-start read takes the mode gate, so a registration cannot publish `shell` + under a pinned turn (§2). Every request of the turn uses the pin, together with the callable set ToolBinding pins today. A switch takes effect with the next turn and needs no re-adoption: the branch's configuration, the version pins and the source sets stay as they are. A request retried through its own source (an in-process @@ -461,9 +462,10 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in the `goal_update` instruction starts in `shell`. Switched after it is applied, a turn that already started keeps the old pin and finishes under it; one that was applied but starts after the switch pins `shell` and carries the pause text. The same settle runs when `execute` registers and makes - `shell` effective without an update; a held continuation released in that window can reach one - turn, whose `goal_update` call is refused. The pause is committed before the record write and the - live mode, so a turn that starts in `shell` has the pause text in history; a cancelled update + `shell` effective without an update: the registry holds the gate from before the settle through + the publish, and a turn that starts waits; it pins `shell` only after the pause text and the + withdrawals are committed. The pause is committed before the record write and the live mode, so a + turn that starts in `shell` has the pause text in history; a cancelled update after the pause and before the record write leaves the goal paused and the mode unchanged. `set`/`resume` are refused while `shell` is in force; a chosen `shell` that runs `normal` (no `execute`) neither pauses nor refuses; after leaving, the operator resumes the goal. @@ -523,11 +525,13 @@ Requirements go to other owners: force, the value `session.tool_mode.get` reports in `effective`, never the chosen mode, and take the Session's mode gate around `set` and `resume` to re-check the effective mode at their commit boundary. While `shell` is in force, pause new continuations and refuse `session.goal.set` and - `resume`; leave resumption to the operator after `shell` leaves. Its owner carries this into - [Goal](plugins/Goal.md). + `resume`; leave resumption to the operator after `shell` leaves. The pause text is an `Append` + input committed before the publish, so a turn that starts in `shell` has it before its first + request's history cutoff. Its owner carries this into [Goal](plugins/Goal.md). - **ToolRegistry.** Provide the `ToolModeTransition` service and the Session's mode gate; on a - registration, call `settle(shell, registration)` under the gate before publishing, and keep the - projection at `normal` on a failure. The one-turn window in §2 stands. + registration, hold the gate from before `settle(shell, registration)` through the publish, and + keep the projection at `normal` on a failure. Turn-start reads take the gate, so no turn pins + `shell` before the settle commits. - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). From c92409ced2d0a36d70920f3f8732e365176d1c75 Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 20:18:28 +0800 Subject: [PATCH 27/28] docs: pin the mode when the input is applied An applied input keeps its mode through compaction and rebuild, so a continuation applied under normal finishes under normal. The applied record carries the mode; shell turns wait for the committed pause text to be adopted before their first request. The issue's acceptance rows now match. Refs #2135 --- docs/design/agent-tool-modes.md | 70 +++++++++++++++++---------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index a971f051ca..6a475f8808 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -129,9 +129,9 @@ hands Goal the pending mode and Goal checks that it would be effective. - **Registration.** When the entry tool registers and makes `shell` effective without an update, `ToolRegistry` holds the Session's mode gate from before `settle(shell, registration)` through the publish. The handler takes the mode and cause as data; it does not read the published value. - The Loop's turn-start read takes the same gate, so no turn pins `shell` before the pause text and - the withdrawals are committed; a `set`/`resume` that waits on the gate is refused after the - publish. A failure leaves the projection at `normal` and records a fault. A withdrawal that + The InputQueue's application read takes the same gate, so no input pins `shell` before the pause + text and the withdrawals are committed; a `set`/`resume` that waits on the gate is refused after + the publish. A failure leaves the projection at `normal` and records a fault. A withdrawal that removes the entry tool runs `normal` and does not resume a paused goal. - **Settle.** The Goal Session part fans out to every branch with an active goal: it writes `paused` with reason `mode`, a pause input text with a `mode` phrase as an `Append` input, so it @@ -180,7 +180,7 @@ may change it behind the operator's back. | Situation | Rule | Why | | --- | --- | --- | | A new Session from a client | starts in the mode the request names, or `normal` when it names none; the client sends the mode it last used | the operator should not re-choose for every Session | -| A running Session | the operator can switch it at any time; the next turn declares the new mode, a turn already started keeps its pin (an in-process budget recovery reuses it; a process restart settles the in-flight request), and a call already admitted finishes | otherwise a change of style means abandoning the conversation | +| A running Session | the operator can switch it at any time; an input applied after the switch uses the new mode, a turn already started or already applied keeps its pin (an in-process budget recovery reuses it; a process restart settles the in-flight request), and a call already admitted finishes | otherwise a change of style means abandoning the conversation | | A branch (line) | has no mode of its own; every line of a Session runs the Session's mode | a line is the same agent; a line in another mode would hand the agent tools the operator excluded | | A member Session | starts in its creator Session's current mode, and the operator can switch it like any Session | the member is the same agent doing delegated work; the model must not decide how the agent acts | | The model | never chooses or changes a mode | it is the operator's choice of capability | @@ -218,18 +218,18 @@ owns this projection. Three terms: - A Code Mode program discovers and calls exactly the `delegated` set: `tools.list` and `tools.describe` project it, and `tools.call` admits inside it. `codemode` itself is never delegated, so a program cannot nest one. -- The Loop holds the turn's mode: a turn pins it when it starts, before its first request is - prepared, not when its input is applied. A turn deferred while compaction runs, or recovered - after a restart, therefore starts under the mode in force when it actually starts. On an update, - the Goal pause is committed before the live mode, so a turn that starts in `shell` after the pause - has it in history; a turn-start read takes the mode gate, so a registration cannot publish `shell` - under a pinned turn (§2). Every request - of the turn uses the pin, together with the callable set ToolBinding pins today. A switch takes - effect with the next turn and needs no re-adoption: the branch's configuration, the version pins - and the source sets stay as they are. A request retried through its own source (an in-process - budget recovery) keeps the pin; a process restart settles the in-flight request as the loop - already does and does not reissue it; the request that follows a tool result keeps the turn's - pin. +- The Loop holds the turn's mode. The InputQueue records the effective mode when it applies an + input, under the mode gate, and the turn — even one deferred for compaction or recovered after a + restart — uses that recorded mode; the applied record carries it, so a rebuild recovers it. Every + request of the turn uses the pin, together with the callable set ToolBinding pins today. A switch + takes effect with the next applied input, not with the next request, and needs no re-adoption: + the branch's configuration, the version pins and the source sets stay as they are. A request + retried through its own source (an in-process budget recovery) keeps the pin; a process restart + settles the in-flight request as the loop already does and does not reissue it; the request that + follows a tool result keeps the turn's pin. An applied input keeps its mode: a continuation + applied under `normal` finishes under `normal`. A turn that pins `shell` is one whose input was + applied after the live value, and it waits for the committed pause text to be adopted before its + first request; the Dispatcher keeps running while it waits. - A tool that is only delegated never appears in a prompt, a declaration or the usage counter; `skill` is in both sets. - The mount list and an Agent profile's tool list narrow the surface and never widen it. `normal` @@ -258,8 +258,8 @@ The mode is Session configuration; there is no daemon-wide default to maintain. The mode is live for the Session's lifetime: -- `ToolRegistry` holds the Session's current mode, initialised from the configuration. A turn reads - it when it starts; nothing re-adopts a tool set when it changes. +- `ToolRegistry` holds the Session's current mode, initialised from the configuration. The + InputQueue records it when it applies an input; nothing re-adopts a tool set when it changes. - `session.tool_mode.get` returns `{mode, effective}`: the mode the operator chose and the one in force. A mode whose entry tool is absent stays chosen and is not in force; that is the fallback. `session.tool_mode.update` runs, in order: Goal settles for the pending mode when it would be @@ -393,15 +393,16 @@ there is no default row to set. ``` The picker lists all three modes; `normal` is always available, and `codemode` or `shell` is shown -as unavailable when its `hello.features` entry is absent. A switch takes effect from the next turn, -and the row shows the effective mode, so a mode that fell back to `normal` is not reported as in -force. A client that offers Goal disables `set` and `resume` while `shell` is in force (the -`effective` value) and shows the named refusal otherwise. +as unavailable when its `hello.features` entry is absent. A switch takes effect from the next +applied input, and the row shows the effective mode, so a mode that fell back to `normal` is not +reported as in force. A client that offers Goal disables `set` and `resume` while `shell` is in +force (the `effective` value) and shows the named refusal otherwise. ## 9. Compatibility - Stored records: an absent `toolMode` is `normal`; `normal` is omitted when serialized, so the - native store's text form does not change for existing Sessions. + native store's text form does not change for existing Sessions. The applied input record gains + an optional `toolMode`; a record without it reads as `normal`, the only mode before this feature. - A fork copies its source's current configuration and therefore its mode. - The v3 Code Mode gate stays. `excluded_tools` keeps `codemode` out of that Session's callable set, the fallback rule makes the Session `normal`, and a v3 client can neither select nor receive Code @@ -438,13 +439,14 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in - Flow: a child `ask_user` is shown under the program and is answerable through `session.question.respond`; its result drives the program and is not duplicated into the model context unless the program returns it. -- Flow: switch a running Session in each direction; the next turn declares the new visible set, a - request after a tool result in the same turn keeps the turn's pin, an in-process budget recovery - keeps its pin, a process restart settles the in-flight request without reissuing it, and a call - already admitted finishes. +- Flow: switch a running Session in each direction; an input applied after the switch declares the + new visible set, a request after a tool result in the same turn keeps the turn's pin, an + in-process budget recovery keeps its pin, a process restart settles the in-flight request without + reissuing it, and a call already admitted finishes. - Flow: a turn whose input is applied but which is deferred for compaction, or recovered after a - restart, pins the mode when it starts; a switch in that interval applies to it, and a turn that - starts in `shell` has the Goal pause in its history. + restart, uses the mode recorded at application; a switch after the application does not change it. + A turn that pins `shell` waits for the committed pause text to be adopted before its first + request, and the Dispatcher keeps running while it waits. - Flow: fallback — a mode whose entry tool is absent stays chosen in `get` and is reported as not in force; the Session declares the `normal` surface. - Flow: a member created under `codemode` records it; switching the creator leaves the member @@ -463,7 +465,7 @@ force. A client that offers Goal disables `set` and `resume` while `shell` is in started keeps the old pin and finishes under it; one that was applied but starts after the switch pins `shell` and carries the pause text. The same settle runs when `execute` registers and makes `shell` effective without an update: the registry holds the gate from before the settle through - the publish, and a turn that starts waits; it pins `shell` only after the pause text and the + the publish, and an input application waits; it pins `shell` only after the pause text and the withdrawals are committed. The pause is committed before the record write and the live mode, so a turn that starts in `shell` has the pause text in history; a cancelled update after the pause and before the record write leaves the goal paused and the mode unchanged. @@ -535,9 +537,11 @@ Requirements go to other owners: - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). -- **Loop.** Read the effective mode when the turn starts and hold it for the turn, including a - turn deferred for compaction or recovered after a restart; its page gains the turn's mode pin. - Its owner carries this into [Loop](../architecture/rust-agent/plugins/Loop.md). +- **Loop.** Record the effective mode when the input is applied, under the mode gate, and recover + it from the applied record on a rebuild; hold it for the turn. Adopt a committed pause text + before starting a turn that pins `shell`, and keep the Dispatcher running while the turn waits. + Its page gains the turn's mode pin. Its owner carries this into + [Loop](../architecture/rust-agent/plugins/Loop.md). Everything else stays within the owners that already exist: ToolRegistry projects its own set and holds the live mode, the Loop holds the turn's mode pin, ToolBinding pins the callable set, From 0e6d305090dbd40907df4b5803c94269ed7c87af Mon Sep 17 00:00:00 2001 From: scotares Date: Wed, 25 Nov 2026 20:40:46 +0800 Subject: [PATCH 28/28] docs: apply the pin at input application everywhere Rewrite the three turn-start leftovers to the applied record, and state the progress guarantee around the registration gate: a pending application does not block the withdrawal or the pause, the switch completes, and the first new shell request includes the pause. Refs #2135 --- docs/design/agent-tool-modes.md | 51 ++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/docs/design/agent-tool-modes.md b/docs/design/agent-tool-modes.md index 6a475f8808..eb32053ea4 100644 --- a/docs/design/agent-tool-modes.md +++ b/docs/design/agent-tool-modes.md @@ -129,16 +129,18 @@ hands Goal the pending mode and Goal checks that it would be effective. - **Registration.** When the entry tool registers and makes `shell` effective without an update, `ToolRegistry` holds the Session's mode gate from before `settle(shell, registration)` through the publish. The handler takes the mode and cause as data; it does not read the published value. - The InputQueue's application read takes the same gate, so no input pins `shell` before the pause - text and the withdrawals are committed; a `set`/`resume` that waits on the gate is refused after - the publish. A failure leaves the projection at `normal` and records a fault. A withdrawal that - removes the entry tool runs `normal` and does not resume a paused goal. + While the switch runs, an application that is pending does not block the withdrawal or the + pause: both are still delivered, the switch completes, and the first new `shell` request is + prepared only after the pause is applied. An application that completes after the switch pins + `shell`; a `set`/`resume` that waits on the gate is refused after the publish. A failure leaves + the projection at `normal` and records a fault. A withdrawal that removes the entry tool runs + `normal` and does not resume a paused goal. - **Settle.** The Goal Session part fans out to every branch with an active goal: it writes `paused` with reason `mode`, a pause input text with a `mode` phrase as an `Append` input, so it precedes the next turn (Goal state alone does not enter the model context), and withdraws the input it queued — the `set`/`resume` trigger and any automatic continuation — when the InputQueue has not applied it. An applied input was already handed over; the settle does not withdraw it. - Its turn pins the mode in force when it starts (§4). + The applied record carries the mode and the turn keeps it (§4). - **Order.** The update runs under the Session's mode gate with Goal's settle first; its order and failure rule are §5's. A Goal failure stops the update before the mode changes. - **Activation.** `session.goal.set` and `resume` take the same mode gate and check the effective @@ -219,9 +221,10 @@ owns this projection. Three terms: `tools.describe` project it, and `tools.call` admits inside it. `codemode` itself is never delegated, so a program cannot nest one. - The Loop holds the turn's mode. The InputQueue records the effective mode when it applies an - input, under the mode gate, and the turn — even one deferred for compaction or recovered after a - restart — uses that recorded mode; the applied record carries it, so a rebuild recovers it. Every - request of the turn uses the pin, together with the callable set ToolBinding pins today. A switch + input, at its serial position on the Dispatcher, and the turn — even one deferred for compaction + or recovered after a restart — uses that recorded mode; the applied record carries it, so a + rebuild recovers it. Every request of the turn uses the pin, together with the callable set + ToolBinding pins today. A switch takes effect with the next applied input, not with the next request, and needs no re-adoption: the branch's configuration, the version pins and the source sets stay as they are. A request retried through its own source (an in-process budget recovery) keeps the pin; a process restart @@ -461,14 +464,14 @@ force (the `effective` value) and shows the named refusal otherwise. the gate is refused after the publish. A settle failure keeps the projection at `normal`. - Flow: a goal with a queued continuation, switched to an effective `shell` before it is applied: the continuation is withdrawn, the goal pauses (`mode`) with its pause text, and no turn carrying - the `goal_update` instruction starts in `shell`. Switched after it is applied, a turn that already - started keeps the old pin and finishes under it; one that was applied but starts after the switch - pins `shell` and carries the pause text. The same settle runs when `execute` registers and makes - `shell` effective without an update: the registry holds the gate from before the settle through - the publish, and an input application waits; it pins `shell` only after the pause text and the - withdrawals are committed. The pause is committed before the record write and the live mode, so a - turn that starts in `shell` has the pause text in history; a cancelled update - after the pause and before the record write leaves the goal paused and the mode unchanged. + the `goal_update` instruction starts in `shell`. An input applied before the switch keeps its pin; + one applied after the switch pins `shell` and waits for the pause text before its first request. + A turn that already started finishes under its pin. The same settle runs when `execute` registers + and makes `shell` effective without an update: the registry holds the gate from before the settle + through the publish; a pending application does not block the withdrawal or the pause, and after + the switch it pins `shell` with the pause in its history. The pause is committed before the record + write and the live mode, so a turn that pins `shell` has the pause text in history; a cancelled + update after the pause and before the record write leaves the goal paused and the mode unchanged. `set`/`resume` are refused while `shell` is in force; a chosen `shell` that runs `normal` (no `execute`) neither pauses nor refuses; after leaving, the operator resumes the goal. - Flow: stop a shell task with `session.exec.stop` after switching the Session to `normal`; the @@ -528,18 +531,20 @@ Requirements go to other owners: the Session's mode gate around `set` and `resume` to re-check the effective mode at their commit boundary. While `shell` is in force, pause new continuations and refuse `session.goal.set` and `resume`; leave resumption to the operator after `shell` leaves. The pause text is an `Append` - input committed before the publish, so a turn that starts in `shell` has it before its first - request's history cutoff. Its owner carries this into [Goal](plugins/Goal.md). + input committed before the publish, so a turn that pins `shell` has it before its first request's + history cutoff. Its owner carries this into [Goal](plugins/Goal.md). - **ToolRegistry.** Provide the `ToolModeTransition` service and the Session's mode gate; on a registration, hold the gate from before `settle(shell, registration)` through the publish, and - keep the projection at `normal` on a failure. Turn-start reads take the gate, so no turn pins - `shell` before the settle commits. + keep the projection at `normal` on a failure. While the switch runs, a pending application does + not block the withdrawal or the pause; it is ordered after the switch, so the first new `shell` + request includes the pause. - **PromptSources.** The environment block follows the surface: while `shell` is in force (the `effective` value) it drops the Windows file-encoding guidance about `read`/`edit`/`write`. Its owner carries this into [PromptSources](plugins/PromptSources.md). -- **Loop.** Record the effective mode when the input is applied, under the mode gate, and recover - it from the applied record on a rebuild; hold it for the turn. Adopt a committed pause text - before starting a turn that pins `shell`, and keep the Dispatcher running while the turn waits. +- **Loop.** Record the effective mode when the input is applied, at its serial position, and + recover it from the applied record on a rebuild; hold it for the turn. Adopt a committed pause + text before starting a turn that pins `shell`, and keep the Dispatcher running while the turn + waits. Its page gains the turn's mode pin. Its owner carries this into [Loop](../architecture/rust-agent/plugins/Loop.md).