@songtonyli/dsh-cli 0.1.63 → 0.1.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@deepseek-ai/dsh-api-remotes/lib/client.js +1 -1
  4. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +1 -1
  5. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  6. package/node_modules/@deepseek-ai/dsh-experimental-auto-review/README.i18n.yaml +17 -14
  7. package/node_modules/@deepseek-ai/dsh-experimental-auto-review/README.md +17 -7
  8. package/node_modules/@deepseek-ai/dsh-experimental-auto-review/README.zh.md +17 -7
  9. package/node_modules/@deepseek-ai/dsh-experimental-auto-review/lib/index.js +37 -3
  10. package/node_modules/@deepseek-ai/dsh-experimental-auto-review/package.json +1 -0
  11. package/node_modules/@deepseek-ai/dsh-permission-presets/README.i18n.yaml +8 -8
  12. package/node_modules/@deepseek-ai/dsh-permission-presets/README.md +4 -4
  13. package/node_modules/@deepseek-ai/dsh-permission-presets/README.zh.md +4 -4
  14. package/node_modules/@deepseek-ai/dsh-permission-presets/lib/index.js +42 -4
  15. package/node_modules/@deepseek-ai/dsh-permission-presets/lib/typert.host.js +9 -2
  16. package/node_modules/@deepseek-ai/dsh-permission-presets/lib/typert.remote-client.js +1 -1
  17. package/node_modules/@deepseek-ai/dsh-permission-presets/lib/types/index.js +48 -4
  18. package/node_modules/@deepseek-ai/dsh-sandbox/README.i18n.yaml +2 -2
  19. package/node_modules/@deepseek-ai/dsh-sandbox/README.md +1 -1
  20. package/node_modules/@deepseek-ai/dsh-sandbox/README.zh.md +1 -1
  21. package/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js +13 -4
  22. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.i18n.yaml +2 -2
  23. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.md +2 -2
  24. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.zh.md +2 -2
  25. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/index.js +14 -1
  26. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.i18n.yaml +2 -2
  27. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.md +1 -1
  28. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.zh.md +1 -1
  29. package/node_modules/@deepseek-ai/dsh-sandbox-policy/lib/index.js +16 -0
  30. package/node_modules/@deepseek-ai/dsh-tool-bash/lib/index.js +3 -1
  31. package/node_modules/@deepseek-ai/dsh-tool-cordis/lib/types/api-catalog.js +13 -1
  32. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +6 -6
  33. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +4 -4
  34. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +4 -4
  35. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +31 -11
  36. package/node_modules/http-cache-semantics/index.js +32 -9
  37. package/node_modules/http-cache-semantics/package.json +3 -3
  38. package/package.json +2 -2
package/README.md CHANGED
@@ -26,7 +26,7 @@ workspace and no build step. Native packages that ship one build per platform
26
26
  ripgrep, the PTY backend's addons, sharp, koffi, and the Landlock launcher — are
27
27
  ordinary optional dependencies, so npm resolves the right one for your machine.
28
28
 
29
- Requires Node `^22.19.0 || >=24.0.0`. Version 0.1.63; `dsh --version`
29
+ Requires Node `^22.19.0 || >=24.0.0`. Version 0.1.65; `dsh --version`
30
30
  also reports the harness build the package was assembled from.
31
31
 
32
32
  ## License
package/bin/dsh.mjs CHANGED
@@ -18,7 +18,7 @@ const argv = process.argv.slice(2)
18
18
  // version this package publishes. Reporting only one of the two would make an
19
19
  // ordinary `npm install @songtonyli/dsh-cli@x` look like it installed something else.
20
20
  if (argv.length === 1 && (argv[0] === '--version' || argv[0] === '-V')) {
21
- console.log('@songtonyli/dsh-cli 0.1.63 (deepseek-harness 0.2.1-alpha.1)')
21
+ console.log('@songtonyli/dsh-cli 0.1.65 (deepseek-harness 0.2.1-alpha.1)')
22
22
  process.exit(0)
23
23
  }
24
24
 
@@ -9994,7 +9994,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
9994
9994
  },
9995
9995
  sourceLocation: {
9996
9996
  "file": "packages/interaction/permission-presets/src/index.ts",
9997
- "line": 293,
9997
+ "line": 305,
9998
9998
  "column": 3
9999
9999
  }
10000
10000
  }]
@@ -48,8 +48,8 @@
48
48
  "micromark-util-sanitize-uri": "^2.0.1",
49
49
  "simple-icons": "16.31.0",
50
50
  "@deepseek-ai/dsh-client-store": "0.2.1-alpha.1",
51
- "@deepseek-ai/cordis": "~4.0.5-alpha.1",
52
51
  "@deepseek-ai/dsh-util-workspace-path": "0.2.1-alpha.1",
52
+ "@deepseek-ai/cordis": "~4.0.5-alpha.1",
53
53
  "@deepseek-ai/dsh-util-code-language": "0.2.1-alpha.1"
54
54
  },
55
55
  "files": [
@@ -167,7 +167,7 @@ window.__ModuleLoader__.load({
167
167
  const SCROLLBAR_LINGER_MS = 2e3;
168
168
  /** Format complete-build metadata for the local brand badge. */
169
169
  function localBuildVersion() {
170
- return `0.2.1-alpha.1-89e4c26` + ({}.DSH_CLIENT_GIT_DIRTY === "true" ? "-dirty" : "");
170
+ return `0.2.1-alpha.1-a121561` + ({}.DSH_CLIENT_GIT_DIRTY === "true" ? "-dirty" : "");
171
171
  }
172
172
  /** Each panel row subscribes only to its own selection state. */
173
173
  function PanelRow({ id, label, wide, usePanelInfo, selectPanel, renderSlot }) {
@@ -3,14 +3,14 @@
3
3
  # After editing either side, bring the other along and re-record with:
4
4
  # pnpm run verify-translation-pairing --write packages/experimental/auto-review/README.md
5
5
  /:
6
- en: 4ba7553052e868d6
7
- zh: 84ef71a398b68599
6
+ en: 69a05f8df88e7a24
7
+ zh: d278a12427f2c62b
8
8
  /deepseek-ai-dsh-experimental-auto-review:
9
9
  en: 566562e610f1b52b
10
10
  zh: 88796a19ab0b98b8
11
11
  /deepseek-ai-dsh-experimental-auto-review/summary:
12
- en: a9deacccf0e79927
13
- zh: 089704e9f48555f3
12
+ en: 7b1dc0cab49753bb
13
+ zh: 8858beb0b56a6f53
14
14
  /deepseek-ai-dsh-experimental-auto-review/table-of-contents:
15
15
  en: d152484eb41ac6b4
16
16
  zh: 09388d293f9be9cb
@@ -21,11 +21,14 @@
21
21
  en: 63f8f1baa0fb2655
22
22
  zh: 6bc64160f6d02114
23
23
  /deepseek-ai-dsh-experimental-auto-review/use-this-package/what-you-get:
24
- en: 556e89c0055ae9cc
25
- zh: 75afbcb9a2af6467
24
+ en: 2f4f6cbeca07708e
25
+ zh: 4fbdf5ad81271b77
26
+ /deepseek-ai-dsh-experimental-auto-review/use-this-package/auto-on-the-container-backend:
27
+ en: b441182c5bcf944e
28
+ zh: 9f53b679e51832d6
26
29
  /deepseek-ai-dsh-experimental-auto-review/understand-the-implementation:
27
- en: 36950514e3b99263
28
- zh: 8d2b8252cdc8d75e
30
+ en: 428319935e5f7216
31
+ zh: 246955f3c88b18a9
29
32
  /deepseek-ai-dsh-experimental-auto-review/further-exploration:
30
33
  en: 8b81d32ea370ecd3
31
34
  zh: dc53ff4da78232ac
@@ -36,14 +39,14 @@
36
39
  en: 7ec217b1012cd8fa
37
40
  zh: 6188796b4990f2ef
38
41
  /deepseek-ai-dsh-experimental-auto-review/model-experience/per-call-reviewer/what-the-model-sees:
39
- en: f77cfa836d8f9aef
40
- zh: fd93d0afcac4fb64
42
+ en: 2837073770a73ca9
43
+ zh: c39eade00f7a6ecd
41
44
  /deepseek-ai-dsh-experimental-auto-review/model-experience/per-call-reviewer/token-effect:
42
45
  en: 0477fcb8eda9767f
43
46
  zh: 76d5b56acb2942da
44
47
  /deepseek-ai-dsh-experimental-auto-review/model-experience/per-call-reviewer/kv-cache-effect:
45
- en: 67b73d97f22f3c75
46
- zh: 4dd263e571043cf4
48
+ en: ca7e68720f506d52
49
+ zh: adb123d889a725d7
47
50
  /deepseek-ai-dsh-experimental-auto-review/model-experience/tool-denial:
48
51
  en: f9b4d7b686f14fc5
49
52
  zh: a2fac9a8eaf5e2a3
@@ -57,8 +60,8 @@
57
60
  en: 8da1089dee147f94
58
61
  zh: 87361347bfd10c6c
59
62
  /deepseek-ai-dsh-experimental-auto-review/known-limitations-and-deferred-work:
60
- en: def1bd5ef705d4de
61
- zh: c02672d92e6df455
63
+ en: 2a0d03dcf6f443ae
64
+ zh: d55b56f6d143c6cd
62
65
  /deepseek-ai-dsh-experimental-auto-review/known-limitations-and-deferred-work/dev-note:
63
66
  en: e67f633dc6fe7773
64
67
  zh: 3bb0c20c93f16f98
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: "Add experimental per-call Auto review, using the current agent's model before tools execute with Full access."
2
+ description: "Add experimental per-call Auto review, using the current agent's model before tools execute with Full access, or confined where the sandbox backend confines reads."
3
3
  kind: "package-bundle"
4
4
  ---
5
5
 
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
9
9
 
10
10
  ## Summary
11
11
 
12
- Add Auto review to the current-session permission pickers. Before each native or PTC inner tool call, the current agent's provider and model assess the pending action; an allowed call executes with Full access, and a denied call asks the user. The shipped TUI profile includes this layer. Default Web keeps its three permission modes until it is switched on from the Web sidebar's Plugins page or installed explicitly. Auto review is experimental: it can allow unsafe actions, deny useful work, and spend additional tokens.
12
+ Add Auto review to the current-session permission pickers. Before each native or PTC inner tool call, the current agent's provider and model assess the pending action; an allowed call executes with Full access, or confined in the container while the session runs on the Apple container backend, and a denied call asks the user. The shipped TUI profile includes this layer. Default Web keeps its three permission modes until it is switched on from the Web sidebar's Plugins page or installed explicitly. Auto review is experimental: it can allow unsafe actions, deny useful work, and spend additional tokens.
13
13
 
14
14
  ## Table of Contents
15
15
 
@@ -47,6 +47,12 @@ Auto reviews every supported call once before its body, including each started P
47
47
 
48
48
  A final denial uses the ordinary tool card. The collapsed row identifies Auto review; expanded output states that the body did not execute and displays the optional reason. [The Web permission package](../../client/ui-permission-presets/README.md) owns picker interaction, and [the tool UI](../../client/ui-tool/README.md) owns reason display.
49
49
 
50
+ ### Auto on the container backend
51
+
52
+ While a session runs on the [Apple container backend](../../sandbox/sandbox-apple-container/README.md), Auto keeps the sandbox: selecting it writes `workspace-write` instead of `danger-full-access`, so allowed commands run confined in the container. A call that has to leave the container, such as the model's one-shot `sandbox_permissions` escalation or a read outside the workspace, is decided by the reviewer instead of the user: an allowed call answers every approval it raises while it runs. A call the reviewer denied still asks the user about the call itself, and any approval it then raises reaches the user as well. The outer `run_code` transport is not reviewed, so an escalation of its own process still asks the user.
53
+
54
+ A session recorded while Auto always wrote `danger-full-access` is confined at its next call once its backend confines reads. A backend switch never widens a confined Auto session, so after `/sandbox local` select Auto again to return to Full access on the host. Backends that confine writes alone keep Auto at Full access.
55
+
50
56
  -----
51
57
 
52
58
  <a id="understand-the-implementation"></a>
@@ -55,11 +61,13 @@ A final denial uses the ordinary tool card. The collapsed row identifies Auto re
55
61
  <details>
56
62
  <summary>Implementation internals — click to expand</summary>
57
63
 
58
- [`cordis.patch.yml`](cordis.patch.yml) inserts the package itself as the `auto-review` row. [`src/index.ts`](src/index.ts) requires the approval, LLM, permission, Session, and tools services, then installs the preset contribution and prepended pre-execute listener in one effect. After the review settles, a denial reads the Session's approval policy: under `never` it is final; under `ask` the listener delegates to later pre-execute listeners and returns the tools pipeline's `ask` decision only when they allow the call, so a later denial, cancellation, or `ask` (with its own reason) takes precedence. The `ask` decision carries an English audited reason and localized prompt text that keeps the raw reviewer reason. The [permission owner](../../interaction/permission-presets/README.md) supplies the current identity and process catalog; Auto uses Full access's sandbox value with the `ask` approval policy and does not change tool definitions.
64
+ [`cordis.patch.yml`](cordis.patch.yml) inserts the package itself as the `auto-review` row. [`src/index.ts`](src/index.ts) requires the approval, LLM, permission, Session, and tools services, then installs the preset contribution and prepended pre-execute listener in one effect. After the review settles, a denial reads the Session's approval policy: under `never` it is final; under `ask` the listener delegates to later pre-execute listeners and returns the tools pipeline's `ask` decision only when they allow the call, so a later denial, cancellation, or `ask` (with its own reason) takes precedence. The `ask` decision carries an English audited reason and localized prompt text that keeps the raw reviewer reason. The [permission owner](../../interaction/permission-presets/README.md) supplies the current identity and process catalog; Auto writes the `ask` approval policy with Full access's sandbox value, or with `workspace-write` while the session's backend confines reads, and does not change tool definitions.
65
+
66
+ Two more listeners keep Auto on a confining backend. Before any call body, the pre-execute listener calls the preset service's `confineAuto(session)`, which narrows a session that still has `danger-full-access` while its backend confines reads by appending only the sandbox mode, so the approval policy a delegated child pins is unchanged; it runs for the unreviewed `run_code` transport too, and a rejected change, such as the persistent-terminal fence, fails the call instead of running it under the stale mode. A prepended `approval/request` listener answers `allowed-once` for a request that names a call the reviewer allowed, that is still running, in a session still in Auto; a downstream listener's own ask for that call is not covered, and `tools/post-execute` forgets the call when it settles.
59
67
 
60
68
  The reviewer reconstructs five sections from the current Session surface and pending execution: fixed policy, cwd-only environment, sourced project constraints, filtered sourced history, and the complete pending action. Native schema comes from the latest request header. A PTC binding freezes its schema and carries it through the scheduler into transient execution metadata; start and settle events never serialize description or parameters. Main-agent `system/message` nodes, assistant text and reasoning, and tool results are excluded. The outer review input is a frozen `RequestUserInput` without durable identity or source; retained history keeps its original source attribution in the review text. [The decision record](../../../.agents/notes/implemented/feature/2026-08-28-auto-review.md) owns authority, lifecycle, and child-inheritance rationale.
61
69
 
62
- Unloading closes selection and review admission, migrates live Auto Sessions to Full access through the existing preset writer, then aborts and drains reviews before withdrawing the listener and contribution. The migration writes the `never` approval policy through the Session writer without queuing a policy-change notice; the model sees the new policy in the next runtime-context snapshot. The sandbox value and persistent terminals survive the migration. A persisted Auto Session cannot publish without the complete integration; reopening it after installation is an explicit user action. Reinstalling the layer restores the option but does not switch live Sessions back to Auto.
70
+ Unloading closes selection and review admission, migrates live Auto Sessions through the existing preset writer, then aborts and drains reviews before withdrawing the listener and contribution. A session at `danger-full-access` becomes Full access, which writes the `never` approval policy through the Session writer without queuing a policy-change notice; a session at `workspace-write` becomes Workspace Write, which writes the `ask` approval policy only when the session does not have it already. The model sees the new policy in the next runtime-context snapshot. Each session keeps its sandbox value, and persistent terminals survive the migration. A persisted Auto Session cannot publish without the complete integration; reopening it after installation is an explicit user action. Reinstalling the layer restores the option but does not switch live Sessions back to Auto.
63
71
 
64
72
  </details>
65
73
 
@@ -82,7 +90,7 @@ Unloading closes selection and review admission, migrates live Auto Sessions to
82
90
 
83
91
  #### What the model sees
84
92
 
85
- The reviewer uses the latest `request/header.config` provider and model with the shipped adapter's default reasoning. The `temperature` setting accepts numbers from `0` through `2` or `provider-default`, which omits the request parameter; the plugin defaults to `0`, while the bundle selects `provider-default` only for the `tui` profile so providers that reject temperature can review calls. Its fixed `REVIEW_POLICY` replaces human approval for exactly one action: allow executes immediately with Full access. The other four sections contain only the retained facts described above. It returns one strict JSON text object with `risk` and `decision`; deny may include a string `reason`. Reasoning blocks may precede that single text block. Only `low + allow`, `medium + allow/deny`, and `high + deny` are valid.
93
+ The reviewer uses the latest `request/header.config` provider and model with the shipped adapter's default reasoning. The `temperature` setting accepts numbers from `0` through `2` or `provider-default`, which omits the request parameter; the plugin defaults to `0`, while the bundle selects `provider-default` only for the `tui` profile so providers that reject temperature can review calls. Its fixed `REVIEW_POLICY` replaces human approval for exactly one action: allow executes immediately, worded as with full host access even when the session keeps the container, so the reviewer judges every call as if it had that access. The other four sections contain only the retained facts described above. It returns one strict JSON text object with `risk` and `decision`; deny may include a string `reason`. Reasoning blocks may precede that single text block. Only `low + allow`, `medium + allow/deny`, and `high + deny` are valid.
86
94
 
87
95
  #### Token effect
88
96
 
@@ -90,7 +98,7 @@ One additional model request per supported call. When a completed text response
90
98
 
91
99
  #### KV Cache effect
92
100
 
93
- The fixed reviewer policy can share a prefix; retained history and the pending action vary per call. Auto adds no dedicated runtime context or mode-switch prompt to the main agent.
101
+ The fixed reviewer policy can share a prefix; retained history and the pending action vary per call. Auto adds no dedicated runtime context or mode-switch prompt to the main agent. Selecting Auto on the container backend, or confining a session recorded at full access, changes the existing sandbox policy and backend contributions once; the new snapshot is appended after retained history, so the cached prefix is unchanged.
94
102
 
95
103
  ### Tool denial
96
104
 
@@ -111,7 +119,9 @@ The denial appends an ordinary tool result; it does not rewrite earlier context
111
119
  <a id="known-limitations-and-deferred-work"></a>
112
120
 
113
121
  - The shipped TUI profile includes Auto review. Default Web, Headless, General settings, and new-session defaults omit it until this layer is switched on.
114
- - Auto provides no file sandbox. The outer `run_code` transport and direct Node effects inside a PTC program do not pass through inner-tool review.
122
+ - Auto provides no file sandbox of its own. On a backend that confines reads it keeps that backend's `workspace-write` confinement, and elsewhere it runs with Full access. The outer `run_code` transport and direct Node effects inside a PTC program do not pass through inner-tool review.
123
+ - The fixed reviewer policy words every allow as full host access and the reviewer is not told the session's sandbox mode, so it can deny a call the container would have contained.
124
+ - A reviewer allow that answers an approval is logged as an ordinary `approval/decided` event with the `allowed-once` outcome. The audit trail does not record that the reviewer, not the user, granted it, and the reviewer's risk and decision are not persisted.
115
125
  - Model classification can be wrong. There are no deterministic tool exemptions, persistent grants, or configurable policy. Formatting retries cannot correct a valid but mistaken classification.
116
126
  - In-process Auto children review their own calls. Out-of-process children retain their native permission systems after the parent delegation call is allowed.
117
127
  - The reviewer reads the Session action history through the deprecated synchronous `snapshotEvents()` reader under a line-scoped waiver. Prior calls, PTC starts, and the direct parent's initial prompt have no projection or paged reader yet, so the migration stays deferred by [the synchronous-read decision](../../../.agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.md).
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: "添加实验性逐调用 Auto review,在工具以 Full access 执行前使用当前 agent 的模型审查。"
2
+ description: "添加实验性逐调用 Auto review,在工具以 Full access 执行前使用当前 agent 的模型审查;沙箱后端限制读取时则在受限状态下执行。"
3
3
  kind: "package-bundle"
4
4
  ---
5
5
 
@@ -9,7 +9,7 @@ kind: "package-bundle"
9
9
 
10
10
  ## 概述
11
11
 
12
- 为当前会话权限选择器添加 Auto review。每次原生或 PTC inner 工具调用前,当前 agent 的 provider 与模型会评估待执行动作;获准调用以 Full access 执行,被拒绝调用会请求用户审批。随附的 TUI profile 包含此层。在 Web 侧栏插件页开启或显式安装之前,默认 Web 保持三种权限模式。Auto review 是实验功能:它可能误放行不安全动作、误拒绝有用操作,并消耗额外 token。
12
+ 为当前会话权限选择器添加 Auto review。每次原生或 PTC inner 工具调用前,当前 agent 的 provider 与模型会评估待执行动作;获准调用以 Full access 执行,会话运行在 Apple container 后端时则在容器内受限执行,被拒绝调用会请求用户审批。随附的 TUI profile 包含此层。在 Web 侧栏插件页开启或显式安装之前,默认 Web 保持三种权限模式。Auto review 是实验功能:它可能误放行不安全动作、误拒绝有用操作,并消耗额外 token。
13
13
 
14
14
  ## 目录
15
15
 
@@ -47,6 +47,12 @@ Auto 在每个受支持调用的 body 执行前审查一次,包括每个已开
47
47
 
48
48
  最终拒绝使用普通工具卡片。折叠行标识 Auto review;展开输出说明 body 未执行,并显示可选理由。[Web 权限包](../../client/ui-permission-presets/README.zh.md)拥有选择器交互,[工具 UI](../../client/ui-tool/README.zh.md)拥有理由展示。
49
49
 
50
+ ### Auto 在容器后端上
51
+
52
+ 会话运行在 [Apple container 后端](../../sandbox/sandbox-apple-container/README.zh.md)时,Auto 会保留沙箱:选择它写入 `workspace-write` 而不是 `danger-full-access`,因此获准的命令在容器内受限运行。必须离开容器的调用,例如模型发起的一次性 `sandbox_permissions` 提权或读取工作区之外的内容,由 reviewer 而不是用户决定:获准的调用在运行期间提出的每一项审批都由它代为应答。被 reviewer 拒绝的调用仍会就该调用本身请求用户审批,其随后提出的任何审批也会交给用户。外层 `run_code` transport 不经过审查,因此对其自身进程的提权仍会请求用户审批。
53
+
54
+ 在 Auto 一律写入 `danger-full-access` 时记录的会话,一旦其后端限制读取,就会在下一次调用时被限制。切换后端绝不会放宽已受限的 Auto 会话,因此执行 `/sandbox local` 后,需要再次选择 Auto 才能回到宿主机上的 Full access。只限制写入的后端让 Auto 保持 Full access。
55
+
50
56
  -----
51
57
 
52
58
  <a id="understand-the-implementation"></a>
@@ -55,11 +61,13 @@ Auto 在每个受支持调用的 body 执行前审查一次,包括每个已开
55
61
  <details>
56
62
  <summary>实现内部机制——点击展开</summary>
57
63
 
58
- [`cordis.patch.yml`](cordis.patch.yml)把本包自身插入为 `auto-review` 行。[`src/index.ts`](src/index.ts)要求 approval、LLM、permission、Session 与 tools 服务,然后在同一个 effect 中安装 preset contribution 和置前的 pre-execute listener。Review 结束后,拒绝会读取 Session 的审批策略:`never` 下为最终拒绝;`ask` 下 listener 先交给后续 pre-execute listener,只有它们放行调用时才返回 tools 流水线的 `ask` 决定,因此后续的拒绝、取消或 `ask`(带自己的理由)优先。`ask` 决定携带英文审计理由,以及保留原始 reviewer 理由的本地化提示文本。[权限 owner](../../interaction/permission-presets/README.zh.md)提供当前身份和进程目录;Auto 使用 Full access 的沙箱值与 `ask` 审批策略,不改变工具定义。
64
+ [`cordis.patch.yml`](cordis.patch.yml)把本包自身插入为 `auto-review` 行。[`src/index.ts`](src/index.ts)要求 approval、LLM、permission、Session 与 tools 服务,然后在同一个 effect 中安装 preset contribution 和置前的 pre-execute listener。Review 结束后,拒绝会读取 Session 的审批策略:`never` 下为最终拒绝;`ask` 下 listener 先交给后续 pre-execute listener,只有它们放行调用时才返回 tools 流水线的 `ask` 决定,因此后续的拒绝、取消或 `ask`(带自己的理由)优先。`ask` 决定携带英文审计理由,以及保留原始 reviewer 理由的本地化提示文本。[权限 owner](../../interaction/permission-presets/README.zh.md)提供当前身份和进程目录;Auto 写入 `ask` 审批策略,搭配 Full access 的沙箱值;会话的后端限制读取时则搭配 `workspace-write`;它不改变工具定义。
65
+
66
+ 另有两个 listener 让 Auto 留在受限后端上。在任何调用 body 之前,pre-execute listener 会调用权限预设服务的 `confineAuto(session)`,它在后端限制读取时收窄仍为 `danger-full-access` 的会话,只追加沙箱模式,因此委派子会话所固定的审批策略不变;它对未经审查的 `run_code` transport 同样运行,被拒绝的变更(例如持久终端的沙箱模式限制)会使调用失败,而不是让它在陈旧的模式下运行。置前的 `approval/request` listener 对满足以下条件的请求应答 `allowed-once`:请求指向 reviewer 已放行、仍在运行的调用,且会话仍处于 Auto;下游 listener 针对该调用自己发起的审批不在其覆盖范围内,调用结算时 `tools/post-execute` 会让它忘记该调用。
59
67
 
60
68
  Reviewer 从当前 Session surface 与待执行调用重建五个分区:固定策略、仅 cwd 的环境、带来源的项目约束、过滤后带来源的历史,以及完整待审动作。原生 schema 来自最新 request header。PTC binding 冻结其 schema,经由调度器传入临时执行元数据;开始与结算事件都不序列化描述或参数 schema。主 agent 的 `system/message` 节点、assistant 正文与 reasoning、tool results 全部排除。外层评审输入是冻结的 `RequestUserInput`,不含持久身份或来源;保留历史在评审文本中仍携带原始来源。[决策记录](../../../.agents/notes/implemented/feature/2026-08-28-auto-review.zh.md)拥有权威、生命周期与 child 继承的理由。
61
69
 
62
- 卸载时先关闭选择与 review admission,经由既有 preset writer 将存活 Auto Session 迁移到 Full access,再中止并等待在途 review 结清,最后撤回 listener 与 contribution。迁移通过 Session writer 写入 `never` 审批策略,不排入策略变更通知;模型在下一次 runtime-context 快照中看到新策略。沙箱值与持久终端在迁移中保持不变。持久 Auto Session 缺少完整 integration 时不能发布;安装后重新打开需要用户显式操作。重装只恢复选项,不把存活 Session 切回 Auto。
70
+ 卸载时先关闭选择与 review admission,经由既有 preset writer 迁移存活 Auto Session,再中止并等待在途 review 结清,最后撤回 listener 与 contribution。处于 `danger-full-access` 的会话变为 Full access,通过 Session writer 写入 `never` 审批策略,不排入策略变更通知;处于 `workspace-write` 的会话变为 Workspace Write,仅当会话尚无 `ask` 审批策略时才写入它。模型在下一次 runtime-context 快照中看到新策略。每个会话保留自己的沙箱值,持久终端在迁移中保持不变。持久 Auto Session 缺少完整 integration 时不能发布;安装后重新打开需要用户显式操作。重装只恢复选项,不把存活 Session 切回 Auto。
63
71
 
64
72
  </details>
65
73
 
@@ -82,7 +90,7 @@ Reviewer 从当前 Session surface 与待执行调用重建五个分区:固定
82
90
 
83
91
  #### 模型看到什么
84
92
 
85
- Reviewer 使用最新 `request/header.config` 的 provider 与模型,并沿用 shipped adapter 默认 reasoning。`temperature` 设置接受 `0` 到 `2` 的数值或 `provider-default`;后者省略请求参数。插件默认值为 `0`,bundle 仅在 `tui` profile 中选择 `provider-default`,使不接受 temperature 的 provider 也能审查调用。固定 `REVIEW_POLICY` 替代恰好一个动作的人工审批:allow 后立即以 Full access 执行。其余四个分区只包含上文列出的保留事实。响应为一个严格 JSON text 对象,包含 `risk` 与 `decision`;deny 可附字符串 `reason`。Reasoning blocks 可以位于这唯一 text block 之前。只有 `low + allow`、`medium + allow/deny` 和 `high + deny` 合法。
93
+ Reviewer 使用最新 `request/header.config` 的 provider 与模型,并沿用 shipped adapter 默认 reasoning。`temperature` 设置接受 `0` 到 `2` 的数值或 `provider-default`;后者省略请求参数。插件默认值为 `0`,bundle 仅在 `tui` profile 中选择 `provider-default`,使不接受 temperature 的 provider 也能审查调用。固定 `REVIEW_POLICY` 替代恰好一个动作的人工审批:allow 后立即执行,措辞上视为拥有完整宿主机访问权限,即使会话保留着容器也是如此,因此 reviewer 会把每个调用都当作拥有该权限来评判。其余四个分区只包含上文列出的保留事实。响应为一个严格 JSON text 对象,包含 `risk` 与 `decision`;deny 可附字符串 `reason`。Reasoning blocks 可以位于这唯一 text block 之前。只有 `low + allow`、`medium + allow/deny` 和 `high + deny` 合法。
86
94
 
87
95
  #### Token 影响
88
96
 
@@ -90,7 +98,7 @@ Reviewer 使用最新 `request/header.config` 的 provider 与模型,并沿用
90
98
 
91
99
  #### KV Cache 影响
92
100
 
93
- 固定 reviewer policy 可以共享前缀;保留历史与待审动作随调用变化。Auto 不向主 agent 增加专门 runtime context 或模式切换提示词。
101
+ 固定 reviewer policy 可以共享前缀;保留历史与待审动作随调用变化。Auto 不向主 agent 增加专门 runtime context 或模式切换提示词。在容器后端上选择 Auto,或限制一个按完全访问记录的会话,会让既有的沙箱策略与后端贡献变化一次;新快照追加在保留历史之后,因此缓存前缀不变。
94
102
 
95
103
  ### 工具拒绝
96
104
 
@@ -111,7 +119,9 @@ Reviewer 使用最新 `request/header.config` 的 provider 与模型,并沿用
111
119
  <a id="known-limitations-and-deferred-work"></a>
112
120
 
113
121
  - 随附的 TUI profile 包含 Auto review。默认 Web、Headless、通用设置与新会话默认值在开启此层之前都不包含它。
114
- - Auto 不提供文件沙箱。外层 `run_code` transport 及PTC 程序内直接 Node 效果不经过 inner-tool review。
122
+ - Auto 自身不提供文件沙箱。在限制读取的后端上,它保留该后端的 `workspace-write` 限制,其他后端上以 Full access 运行。外层 `run_code` transport 及 PTC 程序内直接 Node 效果不经过 inner-tool review。
123
+ - 固定 reviewer policy 把每次 allow 都表述为完整宿主机访问,且不会告知 reviewer 会话的沙箱模式,因此它可能拒绝容器本可限制住的调用。
124
+ - 应答审批的 reviewer allow 会记录为普通的 `approval/decided` 事件,结果为 `allowed-once`。审计轨迹不会记录这次授权来自 reviewer 而非用户,reviewer 的 risk 与 decision 也不持久化。
115
125
  - 模型分类可能出错。不提供确定性工具豁免、持久 grant 或可配置策略。格式重试无法纠正有效但错误的分类。
116
126
  - 进程内 Auto child 独立审查自身调用。进程外 child 在父委派调用获准后保留原生权限系统。
117
127
  - reviewer 在带行级豁免的情况下,通过已废弃的同步 `snapshotEvents()` 读取 Session 动作历史。此前的调用、PTC start 与直接父级的初始 prompt 目前都没有投影或分页读取方,因此迁移按[同步读取决策](../../../.agents/notes/implemented/architecture/2026-09-09-deprecate-synchronous-session-event-reads.zh.md)继续延期。
@@ -11,6 +11,11 @@ import { RUN_CODE_NAME } from "@deepseek-ai/dsh-tools";
11
11
  * Under the `ask` approval policy a reviewer denial asks the user; under
12
12
  * `never` it is final.
13
13
  *
14
+ * An allowed call also answers the approvals it raises while it runs, such as a
15
+ * one-shot sandbox escalation, so the reviewer decides instead of the user. On a
16
+ * backend that confines reads, Auto keeps the sandbox: its mode is
17
+ * `workspace-write`, and only such an escalation leaves it.
18
+ *
14
19
  * @module @deepseek-ai/dsh-experimental-auto-review
15
20
  */
16
21
  /** Structured error name persisted for every final reviewer denial. */
@@ -486,17 +491,33 @@ function failed(exec, error) {
486
491
  reason: `Auto review of tool "${exec.name}" failed; its body was not executed: ${message}`
487
492
  };
488
493
  }
494
+ /**
495
+ * The preset a live Auto session migrates to when the integration unloads: it
496
+ * keeps the session's sandbox mode, so migration neither widens it nor trips the
497
+ * persistent-terminal mode fence.
498
+ */
499
+ function migrationPreset(ctx, session) {
500
+ return ctx.get("sandboxPolicy")?.overrideOf(session) === "workspace-write" ? "workspace-write" : "danger-full-access";
501
+ }
489
502
  /** Install the Auto preset and its prepended per-call review gate. */
490
503
  function apply(ctx, config) {
491
504
  const permissionPresets = ctx.permissionPresets;
492
505
  let accepting = true;
493
506
  const active = /* @__PURE__ */ new Set();
494
507
  const lifecycle = new AbortController();
508
+ const allowedCalls = /* @__PURE__ */ new WeakMap();
509
+ const allowCall = (agent, callId) => {
510
+ const calls = allowedCalls.get(agent) ?? /* @__PURE__ */ new Set();
511
+ calls.add(callId);
512
+ allowedCalls.set(agent, calls);
513
+ };
495
514
  ctx.effect(function* () {
496
515
  yield ctx.on("tools/pre-execute", async (exec, next) => {
497
516
  const agent = exec.agent;
498
- if (agent === void 0 || exec.parent === void 0 && exec.name === RUN_CODE_NAME) return next();
517
+ if (agent === void 0) return next();
499
518
  if (permissionPresets.current(agent.session) !== AUTO_PRESET) return next();
519
+ if (accepting) permissionPresets.confineAuto(agent.session);
520
+ if (exec.parent === void 0 && exec.name === RUN_CODE_NAME) return next();
500
521
  if (!accepting || lifecycle.signal.aborted) return { kind: "cancel" };
501
522
  const completed = Promise.withResolvers();
502
523
  active.add(completed.promise);
@@ -514,13 +535,26 @@ function apply(ctx, config) {
514
535
  if (decision.decision === "deny" && ctx.approval.overrideOf(agent.session) === "never") return denied(exec, decision.reason);
515
536
  const downstream = await next();
516
537
  if (isAborted(lifecycle.signal)) return { kind: "cancel" };
517
- if (decision.decision === "allow" || downstream.kind !== "allow") return downstream;
538
+ if (decision.decision === "allow") {
539
+ if (downstream.kind === "allow") allowCall(agent, exec.callId);
540
+ return downstream;
541
+ }
542
+ if (downstream.kind !== "allow") return downstream;
518
543
  return askUser(exec, decision.reason);
519
544
  } finally {
520
545
  active.delete(completed.promise);
521
546
  completed.resolve();
522
547
  }
523
548
  }, { prepend: true });
549
+ yield ctx.on("approval/request", (request, next) => {
550
+ if (request.callId === void 0 || allowedCalls.get(request.agent)?.has(request.callId) !== true) return next();
551
+ if (permissionPresets.current(request.agent.session) !== AUTO_PRESET) return next();
552
+ return Promise.resolve("allowed-once");
553
+ }, { prepend: true });
554
+ yield ctx.on("tools/post-execute", (exec, _result, next) => {
555
+ if (exec.agent !== void 0) allowedCalls.get(exec.agent)?.delete(exec.callId);
556
+ return next();
557
+ }, { prepend: true });
524
558
  yield permissionPresets.registerAuto(() => {
525
559
  if (!accepting) throw new Error("auto-review: integration is closing");
526
560
  });
@@ -529,7 +563,7 @@ function apply(ctx, config) {
529
563
  try {
530
564
  for (const session of ctx.sessions.list()) {
531
565
  if (permissionPresets.current(session) !== AUTO_PRESET) continue;
532
- permissionPresets.set(session, "danger-full-access");
566
+ permissionPresets.set(session, migrationPreset(ctx, session));
533
567
  }
534
568
  } finally {
535
569
  lifecycle.abort(/* @__PURE__ */ new Error("auto-review integration disposed"));
@@ -60,6 +60,7 @@
60
60
  "@deepseek-ai/dsh-permission-presets": "0.2.1-alpha.1",
61
61
  "@deepseek-ai/dsh-ptc-runtime-node": "0.2.1-alpha.1",
62
62
  "@deepseek-ai/dsh-sandbox": "0.2.1-alpha.1",
63
+ "@deepseek-ai/dsh-sandbox-apple-container": "0.2.0-rc.2",
63
64
  "@deepseek-ai/dsh-sandbox-policy": "0.2.1-alpha.1",
64
65
  "@deepseek-ai/dsh-session": "0.2.1-alpha.1",
65
66
  "@deepseek-ai/dsh-session-projection": "0.2.1-alpha.1",
@@ -21,11 +21,11 @@
21
21
  en: 3b3fe69be228870a
22
22
  zh: af3f146f86615ad4
23
23
  /deepseek-ai-dsh-permission-presets/use-this-package/switching-presets:
24
- en: ede3169d799a7578
25
- zh: cb88e3ade597e486
24
+ en: 3004d00a18c56e0c
25
+ zh: 9d6d536017a85b50
26
26
  /deepseek-ai-dsh-permission-presets/use-this-package/what-users-see:
27
- en: 628a5bdd956e206c
28
- zh: 172be9a9748d65ce
27
+ en: d7a2005199968758
28
+ zh: 05141e093c4d05e0
29
29
  /deepseek-ai-dsh-permission-presets/use-this-package/session-defaults:
30
30
  en: 88218998b169a203
31
31
  zh: 7a3646ff0ca28549
@@ -36,11 +36,11 @@
36
36
  en: 172f5c8af5705ada
37
37
  zh: b424834e38adb25d
38
38
  /deepseek-ai-dsh-permission-presets/understand-the-implementation/write-path:
39
- en: b01849a5fa73aae9
40
- zh: cbd7fcf50117502b
39
+ en: 795fbc41a089f6fe
40
+ zh: f239cc3e060d44f1
41
41
  /deepseek-ai-dsh-permission-presets/understand-the-implementation/read-side-and-custom:
42
- en: c9ca792038f44654
43
- zh: 83cc2641c800c114
42
+ en: 92b52102237657ac
43
+ zh: f2e2c091ef82cdd9
44
44
  /deepseek-ai-dsh-permission-presets/understand-the-implementation/session-pinning-and-blank-reuse:
45
45
  en: 893cea88bce22903
46
46
  zh: 2431e19ced670511
@@ -53,11 +53,11 @@ The generated [configuration catalog](../../../docs/config-catalog.md#deepseek-a
53
53
 
54
54
  ### Switching presets
55
55
 
56
- Switching to Auto first runs its synchronous admission check; every preset switch then changes only the knobs whose effective value differs, and selecting the preset already in effect changes nothing. The current value resolves as the still-matching last recorded selection, including a recorded Auto selection under the `never` approval policy, else the first matching configured entry, else `custom`. Users switch through the `/permission` command: a bare invocation reports the current preset and every available entry, and a preset argument switches to it.
56
+ Switching to Auto first runs its synchronous admission check; every preset switch then changes only the knobs whose effective value differs, and selecting the preset already in effect changes nothing. The current value resolves as the still-matching last recorded selection, including a recorded Auto selection under either approval policy and either sandbox value Auto writes, else the first matching configured entry, else `custom`. Users switch through the `/permission` command: a bare invocation reports the current preset and every available entry, and a preset argument switches to it.
57
57
 
58
58
  ### What users see
59
59
 
60
- Clients render selectable entries from the process catalog: configured presets in table order followed by Auto while its integration is live. They join that snapshot with the Session's current value; an unmatched `custom` value may label the current control but never appears as a selectable catalog row. Auto's identity and knob bundle, Full access sandbox with the `ask` approval policy, are fixed inside this service; a recorded Auto selection also matches the `never` policy that delegated children pin. The shipped client locale dictionaries own Auto's label and description, while configured presets retain Host-supplied presentation. Callers cannot publish another preset through a generic contribution API, and they can switch away from `custom` but cannot select or persist a named custom preset through this service.
60
+ Clients render selectable entries from the process catalog: configured presets in table order followed by Auto while its integration is live. They join that snapshot with the Session's current value; an unmatched `custom` value may label the current control but never appears as a selectable catalog row. Auto's identity and knob bundle are fixed inside this service: the `ask` approval policy with the Full access sandbox, or with `workspace-write` while the session's sandbox backend also confines reads, so Auto keeps the Apple container. A recorded Auto selection also matches either sandbox value and the `never` policy that delegated children pin. The shipped client locale dictionaries own Auto's label and description, while configured presets retain Host-supplied presentation. Callers cannot publish another preset through a generic contribution API, and they can switch away from `custom` but cannot select or persist a named custom preset through this service.
61
61
 
62
62
  ### Session defaults
63
63
 
@@ -82,11 +82,11 @@ The observable behavior is covered in [Use this package](#use-this-package); thi
82
82
 
83
83
  ### Write path
84
84
 
85
- `set()` resolves the preset and synchronously runs Auto admission when applicable. Transitions append `permission/preset` only when the effective preset changes, then write each changed knob through its canonical setter — `setSandboxMode` from `dsh-sandbox-policy` and `setApprovalPolicy` from `dsh-user-approval`. The selection event therefore preserves user intent when two presets share a bundle. Switching between Auto and Full access records the new identity and the changed approval policy. A net-zero selection appends nothing.
85
+ `set()` resolves the preset and synchronously runs Auto admission when applicable. For Auto it resolves the sandbox value from `ctx.sandboxPolicy.confinesReads(session)`: `workspace-write` on a backend that confines reads, otherwise `danger-full-access`. The value is logged like any knob, so a backend switch never rewrites it and selecting Auto again resolves it anew. Transitions append `permission/preset` only when the effective preset changes, then write each changed knob through its canonical setter — `setSandboxMode` from `dsh-sandbox-policy` and `setApprovalPolicy` from `dsh-user-approval`. The selection event therefore preserves user intent when two presets share a bundle. Switching between Auto and Full access records the new identity and the changed approval policy, and also the sandbox mode when the session's backend confines reads. A net-zero selection appends nothing. `confineAuto(session)` is the one other write: it narrows an Auto session that still has `danger-full-access` to `workspace-write` when its backend confines reads, appending only `sandbox/mode`. It never widens a confined session and leaves the identity and the approval policy a delegated child pins unchanged.
86
86
 
87
87
  ### Read side and `custom`
88
88
 
89
- `current(session)` reads the required `permissions` projection, whose unit folds the three whole-value knob events over the composition defaults (`ctx.shell.sandboxMode` and the approval config). The host state also retains whether `session/end-seed` has occurred, so session pinning distinguishes an explicitly empty restored seed from a genuinely fresh session without rescanning the log. A still-matching last selection wins shared-bundle ties, and a recorded Auto selection also matches the `never` approval policy; otherwise the first configured match wins; otherwise the derived `CUSTOM_PRESET` is returned. A missing projection key fails explicitly.
89
+ `current(session)` reads the required `permissions` projection, whose unit folds the three whole-value knob events over the composition defaults (`ctx.shell.sandboxMode` and the approval config). The host state also retains whether `session/end-seed` has occurred, so session pinning distinguishes an explicitly empty restored seed from a genuinely fresh session without rescanning the log. A still-matching last selection wins shared-bundle ties, and a recorded Auto selection also matches either approval policy and either sandbox value Auto writes; otherwise the first configured match wins; otherwise the derived `CUSTOM_PRESET` is returned. A missing projection key fails explicitly.
90
90
 
91
91
  `optionOf(name)` returns a configured entry, the live Auto entry, or the display-only `custom` entry. It throws only when the name matches none of those; a withdrawn Auto entry is unavailable.
92
92
 
@@ -53,11 +53,11 @@ kind: "package-reference"
53
53
 
54
54
  ### 切换预设
55
55
 
56
- 切换到 Auto 时,服务先同步执行其准入检查;每次预设切换随后只改变实际值不同的旋钮,再次选择当前已生效的预设不会产生任何变化。当前值解析顺序为:仍匹配的最近一次记录选择(已记录的 Auto 选择在 `never` 审批策略下也匹配),其次是配置表中的第一个匹配项,否则为 `custom`。用户通过 `/permission` 命令切换:不带参数调用时报告当前预设与所有可用条目,带预设参数时切换过去。
56
+ 切换到 Auto 时,服务先同步执行其准入检查;每次预设切换随后只改变实际值不同的旋钮,再次选择当前已生效的预设不会产生任何变化。当前值解析顺序为:仍匹配的最近一次记录选择(已记录的 Auto 选择在任一审批策略、且沙箱值为 Auto 会写入的两种之一时也匹配),其次是配置表中的第一个匹配项,否则为 `custom`。用户通过 `/permission` 命令切换:不带参数调用时报告当前预设与所有可用条目,带预设参数时切换过去。
57
57
 
58
58
  ### 用户看到什么
59
59
 
60
- 客户端从进程级目录渲染可选条目:先按表顺序列出配置预设,再在 Auto integration 存活时列出 Auto。客户端把这份快照与 Session 当前值合并;不匹配的 `custom` 值可以标记当前控件,但绝不会成为可选目录行。Auto 的身份与旋钮组合(Full access 沙箱加 `ask` 审批策略)固定在本服务内部;已记录的 Auto 选择也匹配委派子会话固定的 `never` 策略。shipped 客户端的 locale 字典拥有 Auto 的 label 与 description,而配置预设保留 Host 提供的展示信息。调用方不能通过通用 contribution API 发布其他预设;他们可以从 `custom` 切换出去,但不能通过此服务选中或持久化一个具名 custom 预设。
60
+ 客户端从进程级目录渲染可选条目:先按表顺序列出配置预设,再在 Auto integration 存活时列出 Auto。客户端把这份快照与 Session 当前值合并;不匹配的 `custom` 值可以标记当前控件,但绝不会成为可选目录行。Auto 的身份与旋钮组合固定在本服务内部:`ask` 审批策略搭配 Full access 沙箱,当会话的沙箱后端同时限制读取时则搭配 `workspace-write`,因此 Auto 会保留 Apple container。已记录的 Auto 选择也匹配这两种沙箱值,以及委派子会话固定的 `never` 策略。shipped 客户端的 locale 字典拥有 Auto 的 label 与 description,而配置预设保留 Host 提供的展示信息。调用方不能通过通用 contribution API 发布其他预设;他们可以从 `custom` 切换出去,但不能通过此服务选中或持久化一个具名 custom 预设。
61
61
 
62
62
  ### 会话默认值
63
63
 
@@ -82,11 +82,11 @@ kind: "package-reference"
82
82
 
83
83
  ### 写入路径
84
84
 
85
- `set()` 解析预设,并在适用时同步执行 Auto 准入检查。切换仅在有效预设变化时追加 `permission/preset`,再通过各自的权威 setter——`dsh-sandbox-policy` 的 `setSandboxMode` 与 `dsh-user-approval` 的 `setApprovalPolicy`——写入每个变化的旋钮。因此,两个预设共享同一组取值时,选择事件仍会保留用户意图。Auto 与 Full access 之间切换时,记录新的身份与变化的审批策略。净变化为零的选择不追加任何内容。
85
+ `set()` 解析预设,并在适用时同步执行 Auto 准入检查。对于 Auto,它根据 `ctx.sandboxPolicy.confinesReads(session)` 解析沙箱值:后端限制读取时为 `workspace-write`,否则为 `danger-full-access`。该值像任何旋钮一样写入日志,因此切换后端不会改写它,再次选择 Auto 会重新解析。切换仅在有效预设变化时追加 `permission/preset`,再通过各自的权威 setter——`dsh-sandbox-policy` 的 `setSandboxMode` 与 `dsh-user-approval` 的 `setApprovalPolicy`——写入每个变化的旋钮。因此,两个预设共享同一组取值时,选择事件仍会保留用户意图。Auto 与 Full access 之间切换时,记录新的身份与变化的审批策略,会话的后端限制读取时还会记录沙箱模式。净变化为零的选择不追加任何内容。`confineAuto(session)` 是另一个写入入口:当后端限制读取时,它把仍为 `danger-full-access` 的 Auto 会话收窄为 `workspace-write`,只追加 `sandbox/mode`。它绝不放宽已受限的会话,并保持身份以及委派子会话所固定的审批策略不变。
86
86
 
87
87
  ### 读取侧与 `custom`
88
88
 
89
- `current(session)` 读取必需的 `permissions` 投影;该单元在组合默认值(`ctx.shell.sandboxMode` 与审批配置)之上折叠三个全量值旋钮事件。host 状态还会保留 `session/end-seed` 是否已经出现,使会话固定无需重扫日志即可区分显式为空的恢复 seed 与真正的新会话。仍匹配的最近选择在共享捆绑时胜出,已记录的 Auto 选择在 `never` 审批策略下也匹配;否则配置表中的第一个匹配项胜出;否则返回推导出的 `CUSTOM_PRESET`。投影 key 缺失时会显式失败。
89
+ `current(session)` 读取必需的 `permissions` 投影;该单元在组合默认值(`ctx.shell.sandboxMode` 与审批配置)之上折叠三个全量值旋钮事件。host 状态还会保留 `session/end-seed` 是否已经出现,使会话固定无需重扫日志即可区分显式为空的恢复 seed 与真正的新会话。仍匹配的最近选择在共享捆绑时胜出,已记录的 Auto 选择在任一审批策略、且沙箱值为 Auto 会写入的两种之一时也匹配;否则配置表中的第一个匹配项胜出;否则返回推导出的 `CUSTOM_PRESET`。投影 key 缺失时会显式失败。
90
90
 
91
91
  `optionOf(name)` 返回配置条目、存活的 Auto 条目或仅供显示的 `custom` 条目。只有名称不匹配这三者时才抛错;已撤回的 Auto 条目不可用。
92
92
 
@@ -53,12 +53,21 @@ const AUTO_PRESET = "auto";
53
53
  /**
54
54
  * Fixed execution bundle for the live Auto integration. `ask` routes reviewer
55
55
  * denials to the user; a stored Auto identity also matches `never`, which a
56
- * delegated child pins so its reviewer denials stay final.
56
+ * delegated child pins so its reviewer denials stay final. `sandbox` applies
57
+ * unless the session's backend confines reads, which keeps
58
+ * {@link CONFINED_AUTO_SANDBOX}.
57
59
  */
58
60
  const AUTO_PRESET_SPEC = {
59
61
  sandbox: "danger-full-access",
60
62
  approval: "ask"
61
63
  };
64
+ /**
65
+ * The sandbox mode Auto writes while the session's backend also confines
66
+ * reads (see `SandboxPolicyService.confinesReads`): the backend keeps
67
+ * confining commands and the review gate replaces the approval prompts for
68
+ * leaving it.
69
+ */
70
+ const CONFINED_AUTO_SANDBOX = "workspace-write";
62
71
  const permissionStateSchema = z$1.object({
63
72
  preset: z$1.string().nullable(),
64
73
  sandbox: z$1.union([
@@ -299,7 +308,7 @@ let PermissionPresetService = (() => {
299
308
  if (state.preset !== null) {
300
309
  const spec = this.specOf(state.preset);
301
310
  if (spec !== void 0 && matches(spec)) return state.preset;
302
- if (state.preset === "auto" && spec?.sandbox === sandbox && approval === "never") return AUTO_PRESET;
311
+ if (state.preset === "auto" && spec !== void 0 && (sandbox === AUTO_PRESET_SPEC.sandbox || sandbox === CONFINED_AUTO_SANDBOX)) return AUTO_PRESET;
303
312
  }
304
313
  for (const [name, spec] of Object.entries(this.presets)) if (matches(spec)) return name;
305
314
  return CUSTOM_PRESET;
@@ -307,7 +316,9 @@ let PermissionPresetService = (() => {
307
316
  /**
308
317
  * Resolve an available preset's knob bundle.
309
318
  * @param name - the preset name to resolve.
310
- * @returns the configured bundle.
319
+ * @returns the configured bundle; for Auto, the bundle of a session whose
320
+ * backend does not confine reads. `set` writes `workspace-write` instead
321
+ * for a session whose backend confines reads.
311
322
  * @throws when `name` is neither configured nor the currently live Auto preset.
312
323
  */
313
324
  resolve(name) {
@@ -346,9 +357,36 @@ let PermissionPresetService = (() => {
346
357
  setApprovalPolicy(session, policy);
347
358
  });
348
359
  }
360
+ /**
361
+ * Narrow an Auto session that still has full access to the confined mode its
362
+ * backend keeps: a Session recorded before Auto kept the container, or one
363
+ * whose backend switched to it afterwards. Writes only the sandbox mode, so
364
+ * the preset identity and the approval policy a delegated child pins stay as
365
+ * they are. Never widens a confined session.
366
+ * @param session - the session to narrow.
367
+ * @returns whether the session's sandbox mode changed.
368
+ */
369
+ confineAuto(session) {
370
+ if (this.current(session) !== "auto") return false;
371
+ if ((this.permissionState(session).sandbox ?? this.ctx.shell.sandboxMode) !== AUTO_PRESET_SPEC.sandbox || this.autoSandbox(session) !== CONFINED_AUTO_SANDBOX) return false;
372
+ setSandboxMode(session, CONFINED_AUTO_SANDBOX);
373
+ return true;
374
+ }
375
+ /**
376
+ * The sandbox mode an Auto selection writes for `session`: the confined mode
377
+ * while its backend also confines reads, otherwise full access. The mode is
378
+ * logged like any preset knob, so a later backend switch never rewrites it.
379
+ */
380
+ autoSandbox(session) {
381
+ return this.ctx.get("sandboxPolicy")?.confinesReads(session) === true ? CONFINED_AUTO_SANDBOX : AUTO_PRESET_SPEC.sandbox;
382
+ }
349
383
  /** Apply one preset through its durable identity and canonical knob setters. */
350
384
  apply(session, name, setApproval) {
351
- const spec = this.resolve(name);
385
+ const resolved = this.resolve(name);
386
+ const spec = name === "auto" ? {
387
+ ...resolved,
388
+ sandbox: this.autoSandbox(session)
389
+ } : resolved;
352
390
  if (name === "auto") this.autoAdmit?.();
353
391
  const current = this.current(session);
354
392
  const knobs = this.permissionState(session);
@@ -35,7 +35,7 @@ export const TYPERT = {
35
35
  typeSymbol: '@deepseek-ai/dsh-permission-presets/client#PermissionCatalog',
36
36
  create: _deepseek_ai_dsh_permission_presets_permissionPresets_catalog_result$schema,
37
37
  },
38
- sourceLocation: {"file":"packages/interaction/permission-presets/src/index.ts","line":293,"column":3},
38
+ sourceLocation: {"file":"packages/interaction/permission-presets/src/index.ts","line":305,"column":3},
39
39
  },
40
40
  ],
41
41
  model: {
@@ -88,7 +88,7 @@ export const TYPERT = {
88
88
  "name": "resolve",
89
89
  "signature": "resolve(name: string): PresetSpec",
90
90
  "summary": "Resolve an available preset's knob bundle.",
91
- "jsDoc": "/**\n * Resolve an available preset's knob bundle.\n * @param name - the preset name to resolve.\n * @returns the configured bundle.\n * @throws when `name` is neither configured nor the currently live Auto preset.\n */"
91
+ "jsDoc": "/**\n * Resolve an available preset's knob bundle.\n * @param name - the preset name to resolve.\n * @returns the configured bundle; for Auto, the bundle of a session whose\n * backend does not confine reads. `set` writes `workspace-write` instead\n * for a session whose backend confines reads.\n * @throws when `name` is neither configured nor the currently live Auto preset.\n */"
92
92
  },
93
93
  {
94
94
  "kind": "method",
@@ -103,6 +103,13 @@ export const TYPERT = {
103
103
  "signature": "set(session: Session, name: string): void",
104
104
  "summary": "Record a changed preset, then update each changed knob through its own setter.",
105
105
  "jsDoc": "/**\n * Record a changed preset, then update each changed knob through its own\n * setter. Selecting the effective preset again appends nothing.\n * @param session - the session the switch belongs to.\n * @param name - the preset to switch to; unknown names throw.\n */"
106
+ },
107
+ {
108
+ "kind": "method",
109
+ "name": "confineAuto",
110
+ "signature": "confineAuto(session: Session): boolean",
111
+ "summary": "Narrow an Auto session that still has full access to the confined mode its backend keeps: a Session recorded before Auto kept the container, or one whose backend switched to it afterwards.",
112
+ "jsDoc": "/**\n * Narrow an Auto session that still has full access to the confined mode its\n * backend keeps: a Session recorded before Auto kept the container, or one\n * whose backend switched to it afterwards. Writes only the sandbox mode, so\n * the preset identity and the approval policy a delegated child pins stay as\n * they are. Never widens a confined session.\n * @param session - the session to narrow.\n * @returns whether the session's sandbox mode changed.\n */"
106
113
  }
107
114
  ],
108
115
  "types": [
@@ -32,7 +32,7 @@ export const TYPERT_REMOTE = {
32
32
  typeSymbol: '@deepseek-ai/dsh-permission-presets/client#PermissionCatalog',
33
33
  create: _deepseek_ai_dsh_permission_presets_permissionPresets_catalog_result$schema,
34
34
  },
35
- sourceLocation: {"file":"packages/interaction/permission-presets/src/index.ts","line":293,"column":3},
35
+ sourceLocation: {"file":"packages/interaction/permission-presets/src/index.ts","line":305,"column":3},
36
36
  },
37
37
  ],
38
38
  }