dsh-taskbridge 1.4.2 → 1.5.1

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 (44) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/README.md +10 -8
  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 +180 -16
  6. package/docs/INTRODUCTION.md +2 -2
  7. package/docs/INTRODUCTION.zh.md +2 -2
  8. package/docs/codex-integration.md +11 -13
  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/releases/1.5.1.zh.md +70 -0
  15. package/docs/runtime-compatibility.md +4 -4
  16. package/docs/silent-wait.md +157 -3
  17. package/docs/taskbridge-upgrade.md +1 -1
  18. package/docs/worker-permissions.md +154 -17
  19. package/lib/client.js +298 -103
  20. package/package.json +9 -3
  21. package/src/client/api.js +315 -34
  22. package/src/client/index.jsx +151 -67
  23. package/src/codex/installer.js +251 -11
  24. package/src/config/redact.js +72 -11
  25. package/src/http/execution-plane.js +124 -10
  26. package/src/index.d.ts +347 -0
  27. package/src/index.js +88 -5
  28. package/src/jobs/activity.js +102 -9
  29. package/src/jobs/continuation-identity.js +283 -0
  30. package/src/jobs/engine.js +491 -55
  31. package/src/jobs/history.js +96 -0
  32. package/src/mcp/continuation.js +317 -0
  33. package/src/mcp/metrics.js +366 -0
  34. package/src/mcp/server.js +1203 -53
  35. package/src/mcp/wait.js +338 -73
  36. package/src/review/prompts.js +145 -126
  37. package/src/runtime/agent-runner.js +330 -0
  38. package/src/runtime/permissions.js +192 -2
  39. package/src/runtime/question-call.js +162 -0
  40. package/src/runtime/questions.js +909 -0
  41. package/src/runtime/sandbox.js +363 -358
  42. package/src/runtime/session-placement.js +1207 -1121
  43. package/src/version.js +121 -0
  44. package/src/workspace/worktrees.js +70 -4
@@ -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.1; 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