dsh-taskbridge 1.4.2 → 1.5.0

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 (40) hide show
  1. package/CHANGELOG.md +16 -2
  2. package/README.md +8 -7
  3. package/bin/dsh-delegate-mcp.d.ts +20 -3
  4. package/bin/dsh-delegate-mcp.js +15 -0
  5. package/codex/dsh-taskbridge.toml +74 -5
  6. package/docs/INTRODUCTION.md +2 -2
  7. package/docs/INTRODUCTION.zh.md +2 -2
  8. package/docs/codex-integration.md +4 -2
  9. package/docs/conversation-placement.md +44 -7
  10. package/docs/plugin-market.md +1 -1
  11. package/docs/redaction-contract.md +47 -4
  12. package/docs/releases/1.5.0-token-benchmark.zh.md +73 -0
  13. package/docs/releases/1.5.0.zh.md +51 -0
  14. package/docs/runtime-compatibility.md +4 -4
  15. package/docs/silent-wait.md +84 -0
  16. package/docs/taskbridge-upgrade.md +1 -1
  17. package/docs/worker-permissions.md +154 -17
  18. package/lib/client.js +3 -0
  19. package/package.json +4 -2
  20. package/src/client/api.js +26 -0
  21. package/src/codex/installer.js +15 -0
  22. package/src/config/redact.js +72 -11
  23. package/src/http/execution-plane.js +76 -5
  24. package/src/index.d.ts +285 -0
  25. package/src/index.js +72 -2
  26. package/src/jobs/activity.js +10 -0
  27. package/src/jobs/continuation-identity.js +278 -0
  28. package/src/jobs/engine.js +326 -36
  29. package/src/jobs/history.js +53 -0
  30. package/src/mcp/continuation.js +317 -0
  31. package/src/mcp/metrics.js +343 -0
  32. package/src/mcp/server.js +1079 -47
  33. package/src/mcp/wait.js +266 -74
  34. package/src/review/prompts.js +145 -126
  35. package/src/runtime/agent-runner.js +165 -0
  36. package/src/runtime/permissions.js +192 -2
  37. package/src/runtime/question-call.js +162 -0
  38. package/src/runtime/questions.js +909 -0
  39. package/src/runtime/session-placement.js +78 -5
  40. package/src/version.js +99 -0
@@ -1,6 +1,6 @@
1
1
  # Runtime compatibility
2
2
 
3
- Build 1.4.2 has **no DSH version whitelist**: it omits `engines.dsh`, declares
3
+ Build 1.5.0 retains the loading policy introduced in 1.4.2: **no DSH version whitelist**: it omits `engines.dsh`, declares
4
4
  host-provided `@deepseek-ai/dsh-*` peers as `*`, and publishes no DSH engine range
5
5
  in the custom plugin index. The plugin uses runtime capability checks rather than
6
6
  rejecting a host solely by its version number. Node.js `>=24` is still required.
@@ -53,7 +53,7 @@ acceptance run.
53
53
  - Development dependencies remain pinned for reproducible tests; they do not
54
54
  restrict the host-provided peer versions used by an installed plugin.
55
55
  - Older plugin packages keep their own metadata and can still be refused by a
56
- newer host. Upgrade to `dsh-taskbridge@1.4.2` to use this loading policy.
56
+ newer host. Upgrade to `dsh-taskbridge@1.5.0` to use this loading policy.
57
57
 
58
58
  ## 2. What DSH 0.2.2 changes
59
59
 
@@ -184,10 +184,10 @@ What remains genuinely unverified:
184
184
 
185
185
  ## 5. Upgrading from an older plugin build
186
186
 
187
- 1. Download `dsh-taskbridge-1.4.2.tgz` from the GitHub Release, or build the package locally (`npm pack`).
187
+ 1. Download `dsh-taskbridge-1.5.0.tgz` from the GitHub Release, or build the package locally (`npm pack`).
188
188
  2. Install it the way your surface requires: the Desktop **Plugins manager** for a
189
189
  Desktop profile (npm/CLI operations on that profile are refused), or
190
- `dsh plugin --profile <name> add ./dsh-taskbridge-1.4.2.tgz` for a CLI profile you
190
+ `dsh plugin --profile <name> add ./dsh-taskbridge-1.5.0.tgz` for a CLI profile you
191
191
  start yourself.
192
192
  3. The settings, the switch value and the task history are preserved
193
193
  (`$DSH_HOME/data/dsh-delegate`); nothing is migrated destructively.
@@ -188,6 +188,68 @@ node bin/dsh-delegate-control.js cancel <taskId> # 只停止这一个任务
188
188
  - 不会被报告成"长时间没进展";
189
189
  - 授权决定只对**那一次调用**有效,不构成常规权限,也不会被后续调用复用。
190
190
 
191
+ ### 5.1 决定之后直接续等(`waitAfterDecision`)
192
+
193
+ `delegate_permission_decide` 有一个可选参数 `waitAfterDecision: boolean`,默认 `false`。
194
+
195
+ - **省略或 `false`**:行为与之前完全一致——只做决定,返回权限路由自己的原样答复
196
+ (`ok`/`task`/`permission`/`hostAcceptance`),不额外增加任何字段。旧客户端不受影响。
197
+ - **`true`**:在同一次 MCP 调用内,决定被后端确认生效后,**复用同一个等待循环**
198
+ (`delegate_wait` 的那一套:25 秒一次的受限观察、默认一小时的截止时间、心跳处理、
199
+ `interrupted` 分类)继续等同一个 `taskId`,直到出现真正需要判断的事件。
200
+
201
+ 答复形状是**扁平的 `delegate_wait` 形状 + `decisionReceipt`**:`reason`/`state`/
202
+ `actionable`/`terminal`/`permission`/`task` 在顶层,新申请仍带完整的脱敏操作、
203
+ `completeness` 与 `fingerprint`。不嵌套 `followUpWait` 这样的子块,因此已有的
204
+ `boundedJson` 权限保护照旧生效:答复过大时,**回执和当前待定申请都会保留**,
205
+ 被截短的操作会明确标记为不可放行(`permissionDecidable: false`),不会被当成完整操作。
206
+
207
+ `decisionReceipt` 说明决定本身的结果,例如
208
+ `{ taskId, requestId, decision, fingerprint, applied, confirmation, outcome?, verified? }`:
209
+
210
+ | 情形 | 回执 | 含义 |
211
+ | --- | --- | --- |
212
+ | 后端确认生效 | `applied: true`、`confirmation: "applied"` | 决定已生效,后续等待失败或取消都不会撤销它 |
213
+ | 后端明确拒绝 | 抛出原有拒绝码,无回执 | 决定未生效,也不会有任何等待开始 |
214
+ | 传输失败、超时、畸形答复 | `applied: null`、`confirmation: "unknown"` | **不知道**是否已生效;先读任务真实状态,不要直接重送 |
215
+ | 答复与所决定的不一致 | `applied: null`、`confirmation: "unknown"`,附 `reason`/`evidence` | 答复中的 task、request 或 operation 与实际不符,或缺少 `state`/`outcome` 等必要证据 |
216
+ | 答复 `ok: false` 或缺证据 | 同上 | `applied` 只可能来自**匹配的真实证据**,不会因为"有答复"就置真 |
217
+ | 答复过大被裁剪 | 最小回执:身份 + `applied` + `confirmation`(`evidenceOmitted: true`) | 大块 `grant`/`verified` 证据被丢弃并可另读,但回执身份不丢 |
218
+
219
+ 确认"已生效"要求同时满足:`ok: true`、同一 task、同一 request、同一 operation fingerprint、
220
+ `state` 为已结算、`outcome` 与本次决定一致(`allow-once` 对应 `allowed-once`,
221
+ `reject` 对应 `rejected`)。`allow-once` 还需要 `verified` 证据,`reject` 不需要。
222
+ 真实后端记录的 `decision` 字段可能为 `null`,因此不把它当作必要条件;判定依据是
223
+ `outcome` 与实际证据。**引用的 fingerprint 不会被后端值静默替换**:不一致就是矛盾。
224
+
225
+ 几条固定规则:
226
+
227
+ - **已经决定的申请不会被再次询问**:等待循环按 `requestId` + `fingerprint` 完整匹配跳过
228
+ 旧记录;**新 `requestId`,或同一 id 但操作变了,都是新问题**,不会继承上一次的允许。
229
+ - **决定被拒绝时不会进入等待**;决定是本次调用的第一次请求,所以被拒时不会留下任何观察。
230
+ - **决定已生效而后续等待失败/被取消/抛错时,本次仍是成功答复**:`decisionReceipt.applied`
231
+ 保持 `true`,`reason` 为 `null`(没有观察到任何任务状态,就不编造),并附
232
+ `waitError`(含 `phase: "follow-up-wait"`)与"不要重送决定、执行未被停止"的明确指引。
233
+ 回执只保证在**真实已生效**这一分支不丢;它不意味着任何答复都能恢复任意失败的决定。
234
+ - **无法确认的决定不会进入等待**:拒绝码为 `MCP_DECISION_UNCONFIRMED`(或传输失败时保留
235
+ 后端码),`error.details.decisionReceipt` 带 `applied: null` 与原始身份。
236
+ - 同一请求重复提交仍由现有引擎拒绝;恢复时先读真实状态,不伪造幂等批准。
237
+
238
+ ## 5.2 计量(`delegate_metrics`)
239
+
240
+ `delegate_metrics` 是**本 MCP 进程**的只读计数,不需要任务 id:
241
+
242
+ - 每个工具被调用了多少次;每次等待返回的原因、耗时、内部观察次数;
243
+ - 交给宿主的**工具文本字节数**——在最终脱敏、裁剪后的文本上,用
244
+ `Buffer.byteLength(..., 'utf8')` 计量,不是字符数,也不是答复里自报的自身长度。
245
+ 它表示"交给传输层的数据量",**不等于**宿主确认收到;
246
+ - 已生效的决定次数,以及每次决定之后那次等待的关联 id。
247
+
248
+ 它**不**记录工具参数、思考正文、答复正文、密钥或任务内容。宿主模型自己的轮次、
249
+ token 用量和费用在这个进程里**不可见**,因此报告为 `not-integrated`,而不是填 `0`。
250
+ 这里的数字是**程序**等待了多少,不是"叫醒了模型多少次",本插件也没有任何
251
+ 跨客户端的零唤醒承诺。
252
+
191
253
  ## 6. 集中审查:什么时候读证据
192
254
 
193
255
  插件不会把对话内容、推理过程或工具输出塞进状态报告。派工方在**执行结束之后**
@@ -264,5 +326,27 @@ node bin/dsh-delegate-control.js cancel <taskId> # 只停止这一个任务
264
326
  字段是判断依据,不要只看原因名字。
265
327
  - 串行宿主下没有通用的“并发”承诺:插件传输支持并发,独立控制程序只提供 `status` 与
266
328
  `cancel` 两个动作,也不能改变宿主的调度方式。
329
+ - **四类"结束"不是一回事**,不要混用:(a) `wait-limit` 是**这次调用自己**的等待预算用完,
330
+ 任务本身没变,继续等同一个 `taskId`;(b) 外层宿主工具/执行时限把调用提前交回,是
331
+ **外层事件**,观察没结束、执行也没停;(c) `attention` 是**真的没有活动**超过阈值
332
+ (默认 10 分钟);(d) 任务的**总执行超时**是执行方自己的预算,以终态报告,既不是
333
+ `wait-limit` 也不是 `attention`,更不是客户端事件。
334
+ - 插件**不能**创建后台等待者、不能唤醒宿主模型,也**不**承诺跨客户端的零唤醒。宿主有
335
+ 自动续接时,一次长等待只占一个续接窗口;没有时,每个 yield 窗口要花一次续接。这一点
336
+ 必须如实说明,不能编造后台唤醒。
337
+ - 2026-11-14 的候选验收使用真实 Codex 外层调用、独立 stdio MCP 进程、本机 HTTP 通道与生产活动监控器,
338
+ 持续等待 1200 秒:内部观察 48 次、消化心跳 47 次,仅返回 1 次交付事件,期间没有读取中间结果。
339
+ 活动由脚本按真实事件格式模拟,包含持续思考流;这证明该客户端能够维持这次 20 分钟等待,
340
+ **不等于**真实提供方连续执行 20 分钟、所有客户端零续接或固定比例的 token/费用节省。
267
341
  - 设置页的自动刷新只在"任务记录"标签页可见、且存在进行中的任务时运行;
268
342
  终端状态的任务不会触发刷新。
343
+
344
+ ## 1.5.0:原生提问、拒绝理由与真实验收
345
+
346
+ - 原生 `ask_user_question` 通过 `reason: question` 即时返回,问题处于 `awaiting-question`,不等十分钟停滞提醒。`delegate_question_answer` 回答一次;使用 `waitAfterAnswer: true` 可在同次调用继续等待原任务。
347
+ - 问题与选项完整传送;超过整体界限或含必须脱敏的内容时明确拒绝。若返回 `questionsOmitted: true` 或 `questionAnswerable: false`,不得依据残缺内容作答。
348
+ - `answerReceipt` 和 `decisionReceipt` 的身份、`applied`、`confirmation` 在结果裁剪或后续等待失败时仍保留。大批答案可标明省略,不反复回传全文;收到已应用回执后不要重送。
349
+ - 题目默认十分钟到期,最多三十分钟;DSH 原生调用若更早撤销,也立即失效。题目绑定同一 Agent、Session 和原工具调用,不会移交给新回合的同名调用。
350
+ - 审批拒绝理由注入同一个执行 Agent。`rejectionFeedback.delivered` 表示注入是否成功,不等于模型已理解;原操作仍被拒绝,后续申请独立判断。问题回答始终不授予任何权限。
351
+
352
+ 2026-11-15,本地 test.2 候选通过实际 DSH Desktop 重启续接,以及真实模型12轮串行100秒工具等待/只读校验,整轮约21分23秒。1次 MCP 等待、1次ready返回、0次中间结果读取;外层客户端20分钟时仍需续接同一个exec。账单实测见[1.5.0等待阶段对照](releases/1.5.0-token-benchmark.zh.md),不承诺跨客户端零唤醒或所有任务固定节省率。
@@ -6,7 +6,7 @@
6
6
 
7
7
  1. 等待当前任务结束,关闭旧插件的本机调用开关。
8
8
  2. 在 DSH 插件管理中停用并卸载本项目旧 `dsh-delegate` 或 `dsh-taskdispatch` 包。**保留 `<DSH_HOME>/data/dsh-delegate` 数据目录**;DSH 若提供删除数据选项,不要勾选。新旧包不能同时启用。
9
- 3. 在“添加插件”中输入 **`dsh-taskbridge@1.4.2`**。中国大陆镜像未同步时改选 npm 官方源。也可安装本项目 Release 的 `dsh-taskbridge-1.4.2.tgz`,或添加本项目固定 Git 提交的自定义索引。不要手动修改 Desktop 保留的 profile。
9
+ 3. 在“添加插件”中输入 **`dsh-taskbridge@1.5.0`**。中国大陆镜像未同步时改选 npm 官方源。也可安装本项目 Release 的 `dsh-taskbridge-1.5.0.tgz`,或添加本项目固定 Git 提交的自定义索引。不要手动修改 Desktop 保留的 profile。
10
10
  4. 打开 **DSH TaskBridge** 配置页,核对 API、模型、思考强度和总开关。数据目录与旧版相同;安装前关闭旧开关,避免恢复之前保存的开启状态。
11
11
  5. 在 Codex 集成中点击“安装 / 更新 TaskBridge 智能体”,更新智能体及 MCP,然后重新加载 Codex。未修改的旧 `dsh-delegate.toml` 会迁移为 `dsh-taskbridge.toml`;修改过的文件保留。只需修复 MCP 时可使用“仅修复 MCP 配置”。启动自检不会接管其他安装目录。
12
12
  6. 若添加过旧索引,改用 `https://ranranyya.github.io/dsh-taskbridge/index.json`。
@@ -1,18 +1,11 @@
1
- # Worker session permissions (1.0.0; unchanged in 1.1.0 and 1.2.0)
2
-
3
- This document states what a delegated **worker** run is allowed to do on the machine
4
- it runs on, how that is established, which connection may continue an existing
5
- thread, when a single tool call may ask the commander for permission, and what is
6
- *not* verified. It describes this build (`1.0.0`) only; the runtime-facing changes
7
- in DSH 0.2.2 are stated in `docs/runtime-compatibility.md`, and the runtime
8
- implementation itself is reviewed separately.
9
-
10
- **Production status:** the per-call decision feature is exercised by this repository's
11
- tests, not yet by a real production run. The production Desktop profile still runs
12
- the previous plugin build, where this sixth tool is absent; exposing it needs a Desktop plugin upgrade and
13
- an MCP reconnect or new session, and the end-to-end provider → commander → resume
14
- acceptance run remains pending.
15
-
1
+ # Worker session permissions (1.5.0; historical 1.0.0–1.2.0 audits retained)
2
+
3
+ This document describes the worker sandbox, per-call approval and ordinary-question boundaries. The standing worker sandbox remains `workspace-write`; a question answer never grants access. A single approved operation does not authorize another call.
4
+
5
+ **1.5.0 acceptance status:** the verified test.2 candidate was installed through native DSH Desktop plugin management. Real provider runs exercised both rejection and a separately approved call, delivery of the rejection reason, native question forwarding, answer-and-wait, and decision-and-wait. An actual Desktop restart retained the source identity, Session and saved host acceptance. A subsequent real-model, twelve-round timing/read-only exercise lasted over twenty minutes with one MCP wait and no intermediate result reads. See [1.5.0 release notes](releases/1.5.0.zh.md).
6
+
7
+ Historical validation sections below describe their own older builds and do not override this current acceptance statement. These checks do not prove every host/platform combination or turn the same-user loopback switch into per-process authentication.
8
+
16
9
  ## The policy
17
10
 
18
11
  Every delegated worker run drives a DSH session whose policy is fixed by this
@@ -87,12 +80,37 @@ An `allow-once` is accepted only when ALL of these hold at the moment of the dec
87
80
  | the turn that asked for the call has not ended | `PERMISSION_REQUEST_CHANGED` |
88
81
  | the request is still pending and inside its deadline | `PERMISSION_REQUEST_NOT_PENDING` / `PERMISSION_REQUEST_EXPIRED` |
89
82
 
90
- A projection that was shortened by a bound (a long `bash.command` whose tail was cut, a
83
+ A projection that was shortened by a bound (a `bash.command` whose tail was cut, a
91
84
  large `write` body) is reported as `permission.pending.completeness: "truncated"` and
92
85
  **cannot be allowed** — an allow would grant a call whose executable material the
93
86
  commander never saw. `reject` needs no fingerprint and no completeness, because refusing
94
87
  is always safe.
95
88
 
89
+ ### The evidence bounds are sized from real commands
90
+
91
+ | Bound | Value | What it holds |
92
+ | --- | --- | --- |
93
+ | one redacted argument scalar (`argumentValueChars`) | 8 192 | a complete PowerShell/`bash` command, including a long Windows path |
94
+ | the whole redacted argument object (`argumentsChars`) | 16 384 | that command plus its other fields (`sandbox_permissions`, `justification`, …) |
95
+ | `McpPermissionRequest.arguments` at the MCP layer | the engine's own `argumentsChars` | the published operation, never a smaller second cap |
96
+
97
+ They are finite, and the rule above is what makes them safe: a request past either cap is
98
+ still cut, still says so, and still cannot be allowed. The correction was to the **size**,
99
+ not to the gate. Two refusals motivated it:
100
+
101
+ - the per-scalar cap was 400 characters, so a real Windows path plus a write-back command
102
+ (~403 characters) was cut, marking the request `truncated` and unapprovable — a
103
+ reviewable request was turned into an un-reviewable one;
104
+ - the MCP text layer separately capped `permission.pending.arguments` at 4 000 characters,
105
+ *below* the engine's own cap, so an operation the engine published whole could be cut
106
+ again at the last layer before the host saw it and forced back to `argumentsComplete:
107
+ false`.
108
+
109
+ `tests/permission-evidence-bounds.test.js` pins both: a ~403, ~1000 and ~8000 character
110
+ command is published whole and decidable, a command past the cap is cut and refused for
111
+ `allow-once`, the fingerprint still covers the complete real arguments, and neither the
112
+ MCP projection nor the history projection re-cuts an operation the engine kept whole.
113
+
96
114
  A decision is refused when the request is unknown, already settled, past its
97
115
  deadline, or carries a fingerprint that does not match the pending operation; and
98
116
  a task of another connection is answered as absent, so the reply cannot be used to
@@ -170,8 +188,127 @@ inheriting an older, possibly interactive policy. Nothing here touches the
170
188
  operator's ordinary DSH sessions: the policy is installed only for a delegated
171
189
  worker session.
172
190
 
173
- ## Reviews: the sandbox policy and the bridge do not apply
191
+ ## Ordinary questions: a separate channel that grants nothing
174
192
 
193
+ A delegated worker may also ask a HUMAN something with the native `ask_user_question`
194
+ tool — an ambiguity it must not resolve itself, a choice it must not invent. That is a
195
+ different situation from a permission request, and it gets a different channel.
196
+
197
+ **The seam.** `ask_user_question` dispatches the Agent-scoped Cordis waterfall
198
+ `'user-questions/request'` (`@deepseek-ai/dsh-user-questions`):
199
+
200
+ ```js
201
+ ctx.on('user-questions/request', (request, next) => …, { prepend: true })
202
+ // request = { questions: [{ id, question, header?, detail?, options?, multiSelect?, intent? }],
203
+ // agent?, signal?, wait?: { callId, timed? } }
204
+ // → { answers: [{ id, selected: string[], custom?: string }] }
205
+ ```
206
+
207
+ Each run registers its own answerer on its own Agent's scoped context, with
208
+ `prepend: true` for the same reason the approval answerer needs it: the waterfall gives
209
+ the request to the FIRST answerer that returns a value, and this run exists so the
210
+ **commander** sees the question. Without it a UI answerer composed earlier would claim
211
+ the request and the commander would never learn the worker was asking — which is exactly
212
+ what happened in the acceptance run, where the task sat in `execute` for ten minutes
213
+ until the silence threshold.
214
+
215
+ **What the commander sees, and when.** A pending question makes an observation answer
216
+ `reason: 'question'` **immediately** — not after a silence threshold — carrying the whole
217
+ `question` block: `requestId`, `taskId`, `sessionId`, `callId` and `questions[]` with each
218
+ question's text, options and detail. The task stays `running` with phase
219
+ `awaiting-question`, keeps its lock, its concurrency slot and its provider lease, and the
220
+ wait is charged to the question's own deadline instead of the execution budget.
221
+
222
+ The timing matters and is enforced in the MONITOR, not only in the engine: an observation
223
+ that is already inside its bounded wait polls for a pending question on every slice, so a
224
+ question raised mid-wait returns at once instead of after the 25-second bound. A pending
225
+ permission request still outranks a question, because that is the one wait that can grant
226
+ something.
227
+
228
+ **Answering.** `delegate_question_answer({ taskId, requestId, answers })`, or
229
+ `POST /dsh-delegate/x/tasks/question` on the execution plane. Each asked question is
230
+ answered **exactly once**; every selected label must be one of that question's own
231
+ options; a single-select question takes exactly one label (a selection AND custom text
232
+ together is legal, matching the native tool); a question with no options needs `custom`
233
+ text. A refused batch leaves the question **pending**, so a correct answer can still be
234
+ made. An answer applies **once**: a repeat is `QUESTION_ALREADY_ANSWERED`, and an expired
235
+ or cancelled question cannot be answered.
236
+
237
+ **Published whole, or refused.** A question set is accepted only if its EXACT serialised
238
+ form — every question, header, detail, option label and description, with all JSON
239
+ escapes counted — fits `QUESTION_BOUNDS.wireChars` (12 000, deliberately below the
240
+ 20 000-character tool-text bound so the block, the task summary and a receipt travel
241
+ together). A set that does not fit is refused with `QUESTION_PAYLOAD_TOO_LARGE` **before**
242
+ anything is published, so the commander is never shown a shortened menu it could answer
243
+ from. The id is used verbatim (no trimming, no generated substitute), a duplicate id or a
244
+ duplicate option label is refused, and the id is bounded.
245
+
246
+ **Bound to a real call, with a finite life.** The answer resumes the paused native call, so
247
+ the bridge binds that call: `request.wait.callId` is verified against the Session log (it
248
+ must be an `ask_user_question` call in the OPEN turn with no recorded result), and a
249
+ legacy request that names none is bound only when the open turn holds exactly one such
250
+ call — two candidates are an ambiguity, which is a refusal rather than a guess. The call is
251
+ re-checked BEFORE the answer is applied: once it has returned or its turn closed, the answer
252
+ is refused with `QUESTION_CALL_GONE` and the set is closed instead of left answerable.
253
+
254
+ A pending question has its own **finite** deadline — ten minutes by default, capped at
255
+ thirty — because it pauses the execution budget. An unanswered question therefore ends with
256
+ the native `ASK_TIMED_OUT`; cancellation, switch-off and disposal end it with `ASK_ABORTED`.
257
+
258
+ **It is not an approval, and it cannot become one.**
259
+
260
+ - A question whose `intent.kind` is `'approval'` is **refused** here with
261
+ `QUESTION_APPROVAL_INTENT`. A permission decision must go through
262
+ `delegate_permission_decide`, which binds one exact tool call and one fingerprint;
263
+ answering it on the question channel would grant access with none of that.
264
+ - A `'plan-review'` question is an information answer: the decision text goes back to the
265
+ worker, and any widening it then wants still needs its own approval.
266
+ - The published block states `grantsAccess: false`, so no reader has to infer it.
267
+
268
+ **Lifecycle.** Cancellation, switch-off, revocation, agent disposal, plugin teardown and
269
+ the question's own deadline all settle the outstanding wait with the native refusal
270
+ (`ASK_ABORTED` / `ASK_TIMED_OUT`) and release the record, so a paused worker is never left
271
+ waiting for a commander that can no longer answer. A restart begins with no bridge and no
272
+ question, so an interrupted question is history only and is never replayed as an answer.
273
+ A harness without the `userQuestions` seam simply gets no answerer: the native call then
274
+ fails at once with `NO_PROVIDER` instead of hanging.
275
+
276
+ ## Rejection reasons reach the worker
277
+
278
+ The native approval protocol cannot carry prose: `ApprovalService.request()` resolves one
279
+ of four closed outcomes (`allowed-once`, `rejected`, `cancelled`, `unavailable`). So a
280
+ commander's reason used to be recorded in history and nowhere else — the worker saw a bare
281
+ `rejected` and could not know that shortening its command would let it ask again.
282
+
283
+ The reason is now sent into the **same Agent** through the channel that does carry prose
284
+ into its next model step: `agent.inject(createUserMessage(...))`, the call the native
285
+ approval service itself uses for its policy notices. The note states, in one message:
286
+
287
+ - **why** that one call was rejected, quoted from the decision (redacted and bounded);
288
+ - that the rejection **stands** and the call did not run;
289
+ - that nothing was widened — not the sandbox, the switch, the policy or the standing mode;
290
+ - that this is **not** a new authorization and grants nothing by itself;
291
+ - what to do: change the operation to fit the reason and request approval again.
292
+
293
+ Delivery is tracked per request id, so a repeated reject, a retried decision or a restart
294
+ cannot deliver the same note twice. The note names the task, the request and the call so
295
+ the worker can place exactly which operation was refused. The settled evidence records
296
+ `rejectionFeedback: { delivered, reason, requestId, callId, messageId, text }` —
297
+ `delivered: true` only after an actual injection on the bound Agent — and that record is
298
+ carried into durable history, so "the worker was told why" survives a restart and can be
299
+ checked instead of claimed. A failed injection is reported as **not delivered** and never
300
+ un-rejects the call or claims the worker was told.
301
+
302
+ The message is built by the REAL native `createUserMessage`, injected by the plugin's own
303
+ composition (`src/index.js`); the locally built default exists only for a harness-free
304
+ import and uses the same `user-approval` source the native approval service itself emits, so
305
+ it is a stand-in rather than a different protocol.
306
+
307
+ **Metrics.** `delegate_metrics` counts question waits under their own `question` reason and
308
+ question answers on their own `questionAnswers` axis. A question answer is **never** counted
309
+ as a permission decision or a refusal: it authorizes nothing.
310
+
311
+ ## Reviews: the sandbox policy and the bridge do not apply
175
312
  The optional read-only review agent uses its own composition (its own provider,
176
313
  model and effort, read-only tools and its own workspace). It does **not** run through
177
314
  the worker sandbox path, it gets **no permission bridge**, and this release does not
package/lib/client.js CHANGED
@@ -402,6 +402,9 @@ window.__ModuleLoader__.load({
402
402
  "before-create": "即将创建执行器",
403
403
  execute: "执行中",
404
404
  "awaiting-permission": "等待本次调用授权决定",
405
+ // A question is a DIFFERENT wait from an approval: answering it grants nothing, so the
406
+ // label must not read as an authorization either.
407
+ "awaiting-question": "等待回答问题",
405
408
  review: "附加审查中",
406
409
  "awaiting-host-review": "等待宿主审查",
407
410
  failed: "已失败",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-taskbridge",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "description": "让 Claude Code 或 Codex 指挥 DSH 完成任务;在 DSH 插件中配置 API、执行模型、思考强度、权限审批与集中审查。",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -76,7 +76,9 @@
76
76
  "docs/releases/1.4.0.zh.md",
77
77
  "docs/releases/1.4.0-token-benchmark.zh.md",
78
78
  "docs/releases/1.4.1.zh.md",
79
- "docs/releases/1.4.2.zh.md"
79
+ "docs/releases/1.4.2.zh.md",
80
+ "docs/releases/1.5.0.zh.md",
81
+ "docs/releases/1.5.0-token-benchmark.zh.md"
80
82
  ],
81
83
  "dsh": {
82
84
  "manifestVersion": 1,
package/src/client/api.js CHANGED
@@ -552,6 +552,9 @@ export const TASK_PHASE_LABELS = Object.freeze({
552
552
  'before-create': '即将创建执行器',
553
553
  execute: '执行中',
554
554
  'awaiting-permission': '等待本次调用授权决定',
555
+ // A question is a DIFFERENT wait from an approval: answering it grants nothing, so the
556
+ // label must not read as an authorization either.
557
+ 'awaiting-question': '等待回答问题',
555
558
  review: '附加审查中',
556
559
  'awaiting-host-review': '等待宿主审查',
557
560
  failed: '已失败',
@@ -1130,6 +1133,29 @@ export function pendingPermission(task) {
1130
1133
  return pending !== null && typeof pending === 'object' ? pending : null;
1131
1134
  }
1132
1135
 
1136
+ /**
1137
+ * Whether the worker is waiting for an ORDINARY QUESTION answer.
1138
+ *
1139
+ * Kept separate from {@link isAwaitingPermission}: answering a question authorizes
1140
+ * nothing, so a UI must not present it as an approval card.
1141
+ * @param {object} task - task view.
1142
+ * @returns {boolean} true when a question is outstanding.
1143
+ */
1144
+ export function isAwaitingQuestion(task) {
1145
+ if (task?.question?.waiting === true) return true;
1146
+ return task?.phase === 'awaiting-question';
1147
+ }
1148
+
1149
+ /**
1150
+ * The pending ordinary question set of one task, or `null`.
1151
+ * @param {object} task - task view.
1152
+ * @returns {object | null} the pending question.
1153
+ */
1154
+ export function pendingQuestion(task) {
1155
+ const pending = task?.question?.pending ?? null;
1156
+ return pending !== null && typeof pending === 'object' ? pending : null;
1157
+ }
1158
+
1133
1159
  /**
1134
1160
  * One-line, plain-Chinese summary of what a task's permission state means.
1135
1161
  *
@@ -350,6 +350,21 @@ export const KNOWN_AGENT_TEMPLATES = [
350
350
  // Exact published 1.4.1 companion, including its LF and CRLF forms.
351
351
  { version: '1.4.1', sha256: '8b6211918ce867ecfdac3495973813a70b7290bdd40221b439d98638f82ac3d4' },
352
352
  { version: '1.4.1', sha256: 'e2a8dc4cac897266e198b98be8fbf91d4159ab9a799704f200224457d292b5be' },
353
+ // Exact 1.4.2 bytes, taken from that RELEASE's own `codex/dsh-taskbridge.toml` in the
354
+ // repository's HEAD (the file as it was published, before later edits), in the LF form it
355
+ // was committed in (`38234033…`, 26388 bytes) and the CRLF form a Windows install rewrites
356
+ // it to (`b62426ab…`, 26740 bytes). Both were computed from the committed blob, never from
357
+ // the current working-tree template: deriving them from the NEW text would make every
358
+ // untouched 1.4.2 install hash to an unknown value, be reported `modified` and never be
359
+ // refreshed. An operator-edited file still hashes to something unknown and stays untouched.
360
+ { version: '1.4.2', sha256: '38234033103190c0523fbf5223c848186fbd03d86b109e89940d1623e430bfb7' },
361
+ { version: '1.4.2', sha256: 'b62426abad77e06b054941cc71fb3d821a9e0d695b1196f62e2170c47c6d17a7' },
362
+ // Exact local test.1 template, read from its installed package (LF and CRLF).
363
+ { version: '1.4.3-test.1', sha256: 'a42fa6da6f028f7ea489ee4b97af7a734958d0cf5ee9affe4361fd534b233882' },
364
+ { version: '1.4.3-test.1', sha256: 'd9fcf481dd7cd61a019dfd753f9dc29c6ad34e6a6aeb4e31e08de7117ff1deaf' },
365
+ // Exact installed test.2 package verified by the coordinator before 1.5.0.
366
+ { version: '1.4.3-test.2', sha256: 'a761461a769b8f297be0e4b7bb68de591918d5afa74a8348e9d475c87011a967' },
367
+ { version: '1.4.3-test.2', sha256: '75ee69400e040d8e18542121a0a49467539368cc0205cc120785b62b6692e16d' },
353
368
  ];
354
369
 
355
370
  /** The `version = "…"` line of an agent file, at column 0. */
@@ -12,16 +12,72 @@ const BEARER_PATTERN = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi;
12
12
  const KEYLIKE_PATTERN = /\b(sk|pk|ak)-[A-Za-z0-9_-]{16,}\b/g;
13
13
  const ASSIGNMENT_PATTERN = /\b([A-Za-z0-9_]*(?:API_?KEY|SECRET|TOKEN|PASSWORD)[A-Za-z0-9_]*)\s*=\s*("[^"]*"|'[^']*'|\S+)/gi;
14
14
  /**
15
- * A profile key embedded in a *directory* name, the shape this repository's own
16
- * workspace has (`…/Local/Temp/dsh-SoexNz/…`, which held the local user id). It is
17
- * masked because it identifies an account; only a path-shaped key is matched, so
18
- * an ordinary hyphenated word in prose is untouched.
15
+ * A per-user profile directory under the OPERATING SYSTEM'S temporary root.
16
+ *
17
+ * The observed shape is `%TEMP%\dsh-VG1MVl\dsh-delegate-test-…` (and on some hosts
18
+ * `~/.cache/dsh-SoexNz/…`): the platform points `TEMP` at a per-profile directory
19
+ * whose six-character suffix is the account key. That suffix is exactly what is
20
+ * masked, and the marker is `dsh-`/`profile-` plus six characters plus digits —
21
+ * nothing more.
22
+ *
23
+ * Two earlier versions were wrong in opposite directions, so the rule is stated
24
+ * around what is PROVABLE instead of around what looks unusual:
25
+ *
26
+ * * the first masked every `dsh-`/`profile-` segment with six alphanumerics, so an
27
+ * ordinary repository or package name — this product's own `dsh-delegate` and its
28
+ * installed `dsh-taskbridge` — was rewritten in every published path;
29
+ * * the second tried to tell a profile key from a word by case and digit shape. That
30
+ * is a guess: a repository may be `v2-tools`, a package `dsh-Bridge2`. A masked
31
+ * path proves nothing, so a guess that fires wrongly disables continuation.
32
+ *
33
+ * A profile key is only recognised where it actually lives: directly under a
34
+ * temporary root ({@link TEMPORARY_ROOT}), or anywhere in such a path. An ordinary
35
+ * segment elsewhere, whatever its case or digits, keeps its readable path.
19
36
  *
20
37
  * The preceding separator is captured and re-emitted so a Windows path keeps its
21
- * backslash. A single combined character class would normalise `\` to `/` and
22
- * change a path an operator is trying to recognise.
38
+ * backslash; a combined character class would normalise `\` to `/`.
39
+ */
40
+ const PROFILE_SEGMENT = String.raw`(?:dsh|profile)-[A-Za-z0-9]{6}(?![A-Za-z0-9])`;
41
+
42
+ /**
43
+ * The directory names the platform's temporary root is reached through.
44
+ *
45
+ * `temp` is the Windows/POSIX temporary root; `tmp` and `.cache` cover the POSIX and
46
+ * per-user-cache spellings. They are matched as complete, case-insensitive segment
47
+ * names, so they anchor WHERE a profile key may appear rather than being redacted.
23
48
  */
24
- const PATH_KEY_PATTERN = /([\\/])(?:dsh|profile)-[A-Za-z0-9]{6,}(?=[\\/]|$)/g;
49
+ const TEMPORARY_ROOT = String.raw`(?:temp|tmp|\.cache)`;
50
+
51
+ /**
52
+ * Mask a profile key only where it is provably one: as a segment directly under a
53
+ * temporary root. Both the separator and the temp-root segment are kept; only the key
54
+ * is replaced, so `…\Temp\dsh-VG1MVl\work` becomes `…\Temp\<mask>\work` and the
55
+ * platform's own separator survives (`/home/u/.cache/<mask>/x`).
56
+ *
57
+ * Two anchored forms, because a stored path may start at the root or continue through
58
+ * it:
59
+ *
60
+ * 1. `…<sep><temp><sep><key>…` — separators are captured and re-emitted verbatim;
61
+ * 2. `^<temp><sep><key>…` — the path begins with the root, e.g. `temp\dsh-abc123\x`.
62
+ */
63
+ const PATH_KEY_PATTERN = new RegExp(
64
+ [
65
+ String.raw`([\\/])`,
66
+ `(${TEMPORARY_ROOT})`,
67
+ String.raw`([\\/])`,
68
+ // The placeholder itself is never rewritten again, so redaction is idempotent.
69
+ String.raw`(?!(?:dsh|profile)-mask)`,
70
+ PROFILE_SEGMENT,
71
+ String.raw`(?=[\\/]|$)`,
72
+ ].join(''),
73
+ 'gi',
74
+ );
75
+
76
+ /** The same rule for a path that STARTS with the temporary root (`temp\dsh-abc123\x`). */
77
+ const LEADING_TEMP_KEY_PATTERN = new RegExp(
78
+ [`^(${TEMPORARY_ROOT})`, String.raw`([\\/])`, PROFILE_SEGMENT, String.raw`(?=[\\/]|$)`].join(''),
79
+ 'i',
80
+ );
25
81
 
26
82
  /** What {@link PATH_KEY_PATTERN} replaces the identifying segment with. */
27
83
  const PATH_KEY_SEGMENT = 'masks-user-profile-segment';
@@ -100,10 +156,15 @@ export function redactText(text) {
100
156
  .replace(BEARER_PATTERN, `Bearer ${MASK}`)
101
157
  .replace(KEYLIKE_PATTERN, MASK)
102
158
  .replace(ASSIGNMENT_PATTERN, (_match, name) => `${name}=${MASK}`)
103
- // Last, and path-anchored: a workspace path reported by a preflight is shown
104
- // so an operator can recognise the repository, but the per-profile segment of
105
- // the platform temp path is not theirs to see.
106
- .replace(PATH_KEY_PATTERN, (_match, separator) => `${separator}${PATH_KEY_SEGMENT}`);
159
+ // Last, and path-anchored: an ordinary workspace path is shown so an operator can
160
+ // recognise the repository; only a profile key under a temporary root is masked.
161
+ // The leading-root form runs first. Each pass re-emits every separator and the
162
+ // temp-root segment it matched, so a POSIX `.cache` path keeps its `/`.
163
+ .replace(LEADING_TEMP_KEY_PATTERN, (_match, root, separator) => `${root}${separator}${PATH_KEY_SEGMENT}`)
164
+ .replace(
165
+ PATH_KEY_PATTERN,
166
+ (_match, before, root, separator) => `${before}${root}${separator}${PATH_KEY_SEGMENT}`,
167
+ );
107
168
  }
108
169
 
109
170
  /**
@@ -66,6 +66,9 @@ export function createExecutionHandler(deps) {
66
66
  // The switch gate below applies to it exactly as it does to a submission,
67
67
  // because a decision is an authorization exercise like any other.
68
68
  ['POST /tasks/permission', decidePermission],
69
+ // The ordinary-question answer. Registered beside the permission route because it is
70
+ // the other way a paused native tool call resumes.
71
+ ['POST /tasks/question', answerQuestion],
69
72
  // The commander's DELIVERY REVIEW of one finished task. It is the only write that
70
73
  // records `hostAcceptance`, and it is narrow on purpose: it decides no permission,
71
74
  // changes no switch/provider/model/isolation/credential, merges no file and creates
@@ -118,12 +121,13 @@ export function createExecutionHandler(deps) {
118
121
 
119
122
  let connection;
120
123
  if (deps.engine.authorizationMode === 'switch') {
121
- // Only the two AUTHORIZING verbs need the switch: a submission creates work and a
122
- // decision releases a paused call. A delivery REVIEW is not one of them: it records
123
- // a conclusion about an already-finished result, so it stays answerable with the
124
+ // Only the AUTHORIZING verbs need the switch: a submission creates work, and a
125
+ // decision (a permission decision or a question answer) releases a paused call
126
+ // whose work already exists. A delivery REVIEW is not one of them: it records a
127
+ // conclusion about an already-finished result, so it stays answerable with the
124
128
  // switch off, exactly like reading or cancelling a task. Reads, cancel and
125
129
  // preflight are equally unaffected.
126
- const gated = key === 'POST /tasks' || key === 'POST /tasks/permission';
130
+ const gated = key === 'POST /tasks' || key === 'POST /tasks/permission' || key === 'POST /tasks/question';
127
131
  if (gated && deps.engine.posture().authorized !== true) {
128
132
  sendJson(res, 403, {
129
133
  ok: false,
@@ -339,7 +343,74 @@ async function decidePermission({ req, res, connection, deps }) {
339
343
  sendJson(res, 200, { ok: true, ...result });
340
344
  }
341
345
 
342
- /** Body fields `POST /tasks/review` accepts. Everything else is refused. */
346
+ /**
347
+ * Answer one pending QUESTION for one owned task.
348
+ *
349
+ * Shaped like the permission route and for the same reasons: the connection identity is
350
+ * the authenticated one (never the body's), so a caller can only answer its OWN task, and
351
+ * the body is validated here because any local caller can reach this route. The answer
352
+ * batch itself is validated by the bridge against the questions the worker actually
353
+ * asked — this route only checks the shape, so a malformed batch is refused early.
354
+ *
355
+ * Nothing here can grant access: the engine settles a paused native question, and any
356
+ * widening still needs `POST /tasks/permission`.
357
+ * @param {object} context - `req`, `res`, `connection`, `deps`.
358
+ * @returns {Promise<void>} resolves after the answer is sent.
359
+ */
360
+ async function answerQuestion({ req, res, connection, deps }) {
361
+ const body = await readJsonBody(req);
362
+ // A closed top-level field set: an unknown field (including a transport CONTROL field
363
+ // such as `waitAfterAnswer`, which the MCP server strips and the route must not accept)
364
+ // is refused rather than silently dropped, so a caller never believes it changed
365
+ // something here.
366
+ for (const key of Object.keys(body)) {
367
+ if (!['taskId', 'requestId', 'answers'].includes(key)) {
368
+ throw new HttpError(400, 'QUESTION_FIELD_UNKNOWN', `unknown field ${JSON.stringify(key)}`);
369
+ }
370
+ }
371
+ if (typeof body.taskId !== 'string' || body.taskId.trim() === '') {
372
+ throw new HttpError(400, 'TASK_ID_REQUIRED', 'taskId is required');
373
+ }
374
+ if (typeof body.requestId !== 'string' || body.requestId.trim() === '') {
375
+ throw new HttpError(400, 'QUESTION_REQUEST_ID_REQUIRED', 'requestId is required');
376
+ }
377
+ if (!Array.isArray(body.answers)) {
378
+ throw new HttpError(400, 'QUESTION_ANSWERS_REQUIRED', 'answers must be an array');
379
+ }
380
+ for (const answer of body.answers) {
381
+ if (answer === null || typeof answer !== 'object' || Array.isArray(answer)) {
382
+ throw new HttpError(400, 'QUESTION_ANSWER_INVALID', 'each answer must be an object');
383
+ }
384
+ // Each answer is a closed shape too: an unknown field is refused, not ignored.
385
+ const allowed = ['id', 'selected', 'custom'];
386
+ for (const key of Object.keys(answer)) {
387
+ if (!allowed.includes(key)) {
388
+ throw new HttpError(400, 'QUESTION_ANSWER_INVALID', `unknown answer field ${JSON.stringify(key)}`);
389
+ }
390
+ }
391
+ if (typeof answer.id !== 'string' || answer.id === '') {
392
+ throw new HttpError(400, 'QUESTION_ANSWER_INVALID', 'each answer needs a question id');
393
+ }
394
+ if (answer.selected !== undefined && (!Array.isArray(answer.selected)
395
+ || answer.selected.some((label) => typeof label !== 'string'))) {
396
+ throw new HttpError(400, 'QUESTION_ANSWER_INVALID', 'selected must be an array of labels');
397
+ }
398
+ if (answer.custom !== undefined && answer.custom !== null && typeof answer.custom !== 'string') {
399
+ throw new HttpError(400, 'QUESTION_ANSWER_INVALID', 'custom must be a string when present');
400
+ }
401
+ }
402
+ const result = await deps.engine.decideQuestion({
403
+ connectionId: connection.connectionId,
404
+ taskId: body.taskId,
405
+ requestId: body.requestId,
406
+ answers: body.answers.map((answer) => ({
407
+ id: answer.id,
408
+ selected: Array.isArray(answer.selected) ? [...answer.selected] : [],
409
+ ...(typeof answer.custom === 'string' ? { custom: answer.custom } : {}),
410
+ })),
411
+ });
412
+ sendJson(res, 200, { ok: true, ...result });
413
+ }
343
414
  const REVIEW_FIELDS = Object.freeze(['taskId', 'decision', 'note']);
344
415
 
345
416
  /**