dsh-taskbridge 0.0.0-stage → 1.3.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 (74) hide show
  1. package/CHANGELOG.md +754 -0
  2. package/LICENSE +21 -0
  3. package/README.md +624 -3
  4. package/bin/dsh-delegate-codex-agent.js +115 -0
  5. package/bin/dsh-delegate-control.d.ts +90 -0
  6. package/bin/dsh-delegate-control.js +450 -0
  7. package/bin/dsh-delegate-mcp.d.ts +121 -0
  8. package/bin/dsh-delegate-mcp.js +273 -0
  9. package/codex/dsh-delegate.toml +245 -0
  10. package/cordis.patch.yml +6 -0
  11. package/docs/INTRODUCTION.md +15 -0
  12. package/docs/INTRODUCTION.zh.md +32 -0
  13. package/docs/auth-contract.md +138 -0
  14. package/docs/claude-code.md +31 -0
  15. package/docs/codex-integration.md +922 -0
  16. package/docs/contracts-stage-b.md +443 -0
  17. package/docs/conversation-placement.md +293 -0
  18. package/docs/plugin-market.md +30 -0
  19. package/docs/redaction-contract.md +127 -0
  20. package/docs/runtime-compatibility.md +220 -0
  21. package/docs/silent-wait.md +191 -0
  22. package/docs/taskbridge-upgrade.md +28 -0
  23. package/docs/taskdispatch-upgrade.md +25 -0
  24. package/docs/worker-permissions.md +347 -0
  25. package/docs/workspace-contract.md +538 -0
  26. package/icon.svg +1 -0
  27. package/lib/client.d.ts +118 -0
  28. package/lib/client.js +3232 -0
  29. package/locale/en.json +7 -0
  30. package/locale/zh.json +7 -0
  31. package/package.json +135 -4
  32. package/src/auth/fence.js +361 -0
  33. package/src/auth/grants.js +789 -0
  34. package/src/client/api.js +2322 -0
  35. package/src/client/index.jsx +2333 -0
  36. package/src/client/styles.js +251 -0
  37. package/src/codex/installer.js +3260 -0
  38. package/src/codex/seam.js +429 -0
  39. package/src/codex/toml.js +784 -0
  40. package/src/config/defaults.js +164 -0
  41. package/src/config/redact.js +184 -0
  42. package/src/config/settings.js +629 -0
  43. package/src/config/store.js +186 -0
  44. package/src/config/validate.js +763 -0
  45. package/src/credentials/seam.js +202 -0
  46. package/src/http/execution-plane.js +454 -0
  47. package/src/http/respond.js +175 -0
  48. package/src/http/user-plane.js +1122 -0
  49. package/src/index.d.ts +332 -0
  50. package/src/index.js +657 -0
  51. package/src/jobs/activity.js +1008 -0
  52. package/src/jobs/engine.js +3609 -0
  53. package/src/jobs/history.js +1467 -0
  54. package/src/mcp/server.js +1820 -0
  55. package/src/mcp/wait.js +536 -0
  56. package/src/model/connectivity.js +371 -0
  57. package/src/model/discovery.js +582 -0
  58. package/src/model/native-catalog.js +68 -0
  59. package/src/model/openai-adapter.js +671 -0
  60. package/src/model/probe.js +264 -0
  61. package/src/model/providers.js +756 -0
  62. package/src/model/routing.js +321 -0
  63. package/src/review/preset.js +868 -0
  64. package/src/review/prompts.js +126 -0
  65. package/src/review/reviewer.js +933 -0
  66. package/src/runtime/agent-runner.js +1738 -0
  67. package/src/runtime/endpoint-discovery.js +118 -0
  68. package/src/runtime/permissions.js +1429 -0
  69. package/src/runtime/sandbox.js +358 -0
  70. package/src/runtime/session-placement.js +1103 -0
  71. package/src/workspace/audit.js +775 -0
  72. package/src/workspace/locks.js +167 -0
  73. package/src/workspace/preflight.js +424 -0
  74. package/src/workspace/worktrees.js +613 -0
@@ -0,0 +1,347 @@
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
+
16
+ ## The policy
17
+
18
+ Every delegated worker run drives a DSH session whose policy is fixed by this
19
+ plugin before the first prompt is delivered:
20
+
21
+ | Fact | Value | Event | Read back through |
22
+ | --- | --- | --- | --- |
23
+ | Sandbox mode | `workspace-write` | `sandbox/mode` | `ctx.sandboxPolicy.resolve({ session })` |
24
+ | Approval stance | `never` (no bridge) / `ask` (armed bridge) | `approval/policy` | `ctx.approval.effectivePolicy(session)` |
25
+
26
+ - **`workspace-write`** means the worker may modify files inside the session's own
27
+ workspace root. Writes outside it are refused by the native sandbox. This value
28
+ is installed for the whole run and **is never widened by a permission decision**:
29
+ nothing here ever writes `danger-full-access` into a Session.
30
+ - **`never`** is the stance of every run WITHOUT a permission bridge. It is
31
+ deterministic rejection, not automatic approval: an escalation asked by the
32
+ worker session is refused without reaching any approval answerer.
33
+ - **`ask`** is installed for ONE run, and only when that run carries an armed
34
+ permission bridge bound to the Agent it drives (see below). With `ask`, the
35
+ native approval service dispatches the question to the composed answerers, of
36
+ which this run's bridge is one. If the bridge cannot answer (not its request, a
37
+ question already outstanding, a bridge that has been disposed), the question
38
+ still fails closed.
39
+
40
+ ## The per-call permission bridge
41
+
42
+ This build adds the narrowest possible way for a delegated worker to ask for
43
+ wider access **for one call**, and nothing more:
44
+
45
+ 1. A native tool asks for an escalation through `ctx.approval.request(...)`
46
+ (`@deepseek-ai/dsh-sandbox`'s `approveEscalation` is that caller). That tool
47
+ call **pauses** — nothing executes.
48
+ 2. The request is surfaced through the existing `delegate_result` view as
49
+ `permission.pending`, while the task stays `running` with phase
50
+ `awaiting-permission`. The call's **real arguments** are read from the native
51
+ Session log by matching the request's `callId` to the committed `tool/call`
52
+ event, redacted and bounded. The worker's own `reason` text is carried beside
53
+ them, labelled `reasonSource: "asker-claim"`, and is never treated as the
54
+ operation.
55
+ 3. The commander answers with the bounded MCP tool `delegate_permission_decide`:
56
+ `allow-once` or `reject`, optionally quoting the request's `fingerprint`.
57
+ 4. `allow-once` resumes **that one call** with the native `allowed-once` outcome.
58
+ The next escalation asks again. `reject` keeps the call denied.
59
+
60
+ What the bridge cannot do, stated as the contract:
61
+
62
+ - it cannot create a request; with nothing pending the tool refuses;
63
+ - it cannot create or widen any account, workspace or session grant, change
64
+ settings, credentials, the local-call switch, the provider/model, the reasoning
65
+ effort or the isolation;
66
+ - it cannot pre-approve a future operation: the request is single-use, bound to a
67
+ non-reusable request id, one task, one Session, one `callId` and an exact
68
+ fingerprint of the real arguments;
69
+ - it is not an automatic allow-all rule, an LLM/API reviewer, or a human-click
70
+ workflow. There is no second model in the loop and no required click;
71
+ - it is **not part of the native worker's preset tool surface**, so the worker's model
72
+ is never handed it. That is a *tool-surface restriction*, and it is the only claim
73
+ made here: it is **not** a hard boundary against arbitrary code running as the same
74
+ OS user. Switch mode deliberately uses one shared `local-mcp` connection identity and
75
+ issues no user-managed token, so a local process can present itself as the commander.
76
+ Nothing in this contract depends on a caller-supplied role label.
77
+
78
+ ## What a decision actually requires (and what it never grants)
79
+
80
+ An `allow-once` is accepted only when ALL of these hold at the moment of the decision:
81
+
82
+ | Check | Refusal if it fails |
83
+ | --- | --- |
84
+ | the decision names the request's exact `fingerprint` | `PERMISSION_DECISION_INVALID` |
85
+ | the published operation was **complete** — no bound fired | `PERMISSION_EVIDENCE_INCOMPLETE` |
86
+ | the recorded `tool/call` is re-read at its stored offset and is byte-identical | `PERMISSION_REQUEST_CHANGED` |
87
+ | the turn that asked for the call has not ended | `PERMISSION_REQUEST_CHANGED` |
88
+ | the request is still pending and inside its deadline | `PERMISSION_REQUEST_NOT_PENDING` / `PERMISSION_REQUEST_EXPIRED` |
89
+
90
+ A projection that was shortened by a bound (a long `bash.command` whose tail was cut, a
91
+ large `write` body) is reported as `permission.pending.completeness: "truncated"` and
92
+ **cannot be allowed** — an allow would grant a call whose executable material the
93
+ commander never saw. `reject` needs no fingerprint and no completeness, because refusing
94
+ is always safe.
95
+
96
+ A decision is refused when the request is unknown, already settled, past its
97
+ deadline, or carries a fingerprint that does not match the pending operation; and
98
+ a task of another connection is answered as absent, so the reply cannot be used to
99
+ discover other tasks' pending requests.
100
+
101
+ ## Lifetimes: two separate budgets
102
+
103
+ The approval wait does **not** consume the worker's execution budget:
104
+
105
+ | Bound | Value | Whose |
106
+ | --- | --- | --- |
107
+ | Execution timeout | `worker.timeoutSeconds` | the run |
108
+ | Permission request deadline | fixed default **10 minutes**, capped at 30 | the request |
109
+
110
+ The execution deadline is **really paused**, not merely reported as paused. When a request
111
+ arrives the run's timer is disarmed and the elapsed span is charged against the remaining
112
+ budget; when the request settles the remaining budget is re-armed. A wait that lasts longer
113
+ than the whole remaining budget therefore does **not** time the run out, while a run that
114
+ keeps executing afterwards still expires on its remaining budget — and repeated waits
115
+ accumulate correctly, because each one charges only the execution it actually consumed. The
116
+ task's `permission.pausedExecutionMs` reports the total wait for evidence.
117
+
118
+ Cancellation, switch-off, revocation, agent disposal, plugin teardown and the request's own
119
+ deadline all settle the outstanding waiter with a refusal (`cancelled` for a stop,
120
+ `unavailable` for a teardown, `rejected` for the deadline), remove the request's timer and
121
+ abort listener, and leave the task to reach its own outcome. While any of that is in
122
+ progress the task keeps its workspace lock and concurrency slot, because the native
123
+ executor has not confirmed it stopped. A restart begins with no tasks, no bridge and no
124
+ request: a stored pending request is rewritten as `unavailable` / `decidedBy: "restart"`
125
+ history and can never be replayed or decided as an allow.
126
+
127
+ ## Why it is written *and read back*
128
+
129
+ Appending the two events is only half the job. DSH folds them through
130
+ `ctx.sandboxPolicy` and `ctx.approval`, and those two services are what an enforcing
131
+ tool layer consults. A session that merely carries the events, without those services
132
+ resolving them, would be *reported* as confined while running unconfined. The plugin
133
+ therefore:
134
+
135
+ 1. checks that both services and the session's `append` exist **before writing
136
+ anything**, so a refused run never leaves a half-installed policy behind;
137
+ 2. appends the two events;
138
+ 3. reads the policy back through both services and compares the resolved mode, the
139
+ effective approval stance, and the resolved workspace root against the session's
140
+ own directory. The stance compared is the one the bridge's own capability
141
+ justifies: `ask` for an armed bridge bound to this Agent, `never` otherwise.
142
+
143
+ Any missing service, refused read, or disagreement is a fail-closed refusal raised
144
+ **before** the prompt is delivered:
145
+
146
+ ```
147
+ RUN_SANDBOX_POLICY_UNAVAILABLE
148
+ ```
149
+
150
+ with a bounded `details.reason` naming which capability was missing. The worker run
151
+ does not start. There is no fallback to a permissive default and no "retry without
152
+ the policy". A bridge that was handed to a run but cannot be armed for the Agent it
153
+ would have to answer for is refused separately, before the prompt, as:
154
+
155
+ ```
156
+ RUN_PERMISSION_BRIDGE_UNAVAILABLE
157
+ ```
158
+
159
+ The comparison of the resolved workspace root with the session header's own
160
+ directory reuses the plugin's single canonical-directory identity
161
+ (`sameSessionPath` from `src/runtime/session-placement.js`), so a separator, a
162
+ trailing slash or a letter case on Windows cannot make one directory be mistaken for
163
+ another in either direction.
164
+
165
+ ## Per run, including continuations
166
+
167
+ The policy is applied on **every** worker run, including a `continueFromTaskId`
168
+ follow-up. A resumed thread therefore converges on the current contract instead of
169
+ inheriting an older, possibly interactive policy. Nothing here touches the
170
+ operator's ordinary DSH sessions: the policy is installed only for a delegated
171
+ worker session.
172
+
173
+ ## Reviews: the sandbox policy and the bridge do not apply
174
+
175
+ The optional read-only review agent uses its own composition (its own provider,
176
+ model and effort, read-only tools and its own workspace). It does **not** run through
177
+ the worker sandbox path, it gets **no permission bridge**, and this release does not
178
+ change its tool surface or its permissions. **Only the sandbox policy and the bridge
179
+ are excluded here.** Model selection is a different contract: on `0.2.2-rc.1` the
180
+ reviewer's provider/model/effort are applied through the same durable
181
+ `agent.model.select(...)` surface and read back like the worker's, because a recorded
182
+ route is what makes the reviewer's own composition provable. The exclusion in this
183
+ section is about `workspace-write` / `never` / `ask` and the per-call decision, not
184
+ about how a model is chosen.
185
+
186
+ An ordinary DSH session is untouched for the same reason: the bridge is armed only
187
+ inside a delegated worker run, it is registered as an answerer on that Agent's own
188
+ scoped context, and it declines (falls through to the next answerer) every request
189
+ that is not its own Agent's.
190
+
191
+ ## Continuations: same verified connection, proven ownership
192
+
193
+ A `continueFromTaskId` follow-up is a request to join *one already verified*
194
+ connection's own thread. The rule is a rule about identity and evidence, not a
195
+ pending hand-off feature:
196
+
197
+ - **The caller's connection identity comes from authentication.** It is the
198
+ connection record the request was authenticated as
199
+ (`local-mcp` on the local-switch path, a verified connection on the grant path),
200
+ never a value the request body states about itself.
201
+ - **Only the same verified `connectionId` may continue the parent.** Another
202
+ connection naming that task id is answered `JOB_TASK_NOT_FOUND` — the same
203
+ answer an unknown id gets — so the reply cannot be used to learn which task ids
204
+ exist for other connections. A different connection **cannot take over** the
205
+ thread. There is **no permission hand-off** between connections, and ownership is
206
+ **never** matched by a connection label or any other visible name.
207
+ - **Same process: the live record.** While this process admitted the parent, its own
208
+ record states the connection and the outcome, and the two ids are compared
209
+ exactly.
210
+ - **After a restart: the durable history corroborates.** The persisted task→session
211
+ map says only *where* a thread lives — never who owns it, never how the run
212
+ ended. The second authority is therefore the durable job history
213
+ (`HistoryStore`), and the continuation proceeds only when that record states the
214
+ **same** owner, a **terminal state a thread can be continued from**, and the same
215
+ source repository and execution directory.
216
+ - **Unprovable ownership and a missing task are one answer.** An id this
217
+ deployment cannot prove belongs to the caller's own connection — an unknown id,
218
+ a record already dropped by the history bounds, unreadable history, a record cut
219
+ to fit its byte budget, a record that states no owner, another connection's task,
220
+ or a request with no verified identity — is answered `JOB_TASK_NOT_FOUND` with
221
+ one message and one set of details. It carries only the id the caller itself
222
+ supplied, so the reply cannot be used to learn which task ids exist for other
223
+ connections, and it never names a Session, a state or any other reason.
224
+ - **Only a proven owner is told the reason.** Once the caller's ownership is
225
+ established, a parent that still cannot be continued is a
226
+ `JOB_CONTINUATION_REFUSED` whose cause is a `SESSION_*` code in
227
+ `error.details.session`: a parent left `interrupted` by an earlier process, one
228
+ still `pending`/`running`, a run that never drove a conversation, a recorded path
229
+ that does not match this submission, another source repository, another execution
230
+ directory, a disposed or mismatched worktree, or a Session that no longer exists.
231
+ Each is refused instead of quietly starting a new Session.
232
+ - **`local-mcp` is a fixed identity, not a wildcard.** Under the local switch the
233
+ connection is exactly `local-mcp` and is compared like any other id. It is not
234
+ `null`, and it does not stand for "every remote connection". A request with no
235
+ verified identity cannot prove ownership of a persisted parent, so it is refused
236
+ rather than admitted as "anyone's".
237
+
238
+ This capability is implemented in the released build. Its acceptance is
239
+ reported separately by Codex; this document does **not** claim a passing real
240
+ install on DSH Desktop, and does **not** claim that a real attack was reproduced.
241
+
242
+ ## DSH 0.2.2: the services are ready only after initialization
243
+
244
+ In DSH `0.2.2-rc.1` both services this contract depends on register their Session
245
+ projections during service initialization: `ctx.sandboxPolicy` for `sandbox/mode` and
246
+ `ctx.approval` for `approval/policy`. A plugin that read them during *activation* would
247
+ observe services that exist but cannot yet fold a session's events, and would either
248
+ misread the policy or fail for the wrong reason.
249
+
250
+ What that changes here:
251
+
252
+ - the policy is still **written then read back**, and the read-back is what proves the
253
+ fold happened — it is not replaced by an assumption about ordering;
254
+ - the read-back happens **per run**, after the services are able to answer, so a run
255
+ started late in the host's boot is treated the same as one started early;
256
+ - a service that cannot answer is still the fail-closed
257
+ `RUN_SANDBOX_POLICY_UNAVAILABLE` raised **before** the prompt, on every supported
258
+ runtime — `0.2.2-rc.1` does not get a more permissive path, and the older runtimes do
259
+ not get a more permissive one either.
260
+
261
+ `docs/runtime-compatibility.md` states the capability-based modern/legacy split; the
262
+ runtime code that implements it lives in `src/runtime/` and is reviewed separately
263
+ from this document, which claims only the contract.
264
+
265
+ ## Known limits — not resolved in 1.0.0
266
+
267
+ - **No process authentication against arbitrary same-user code.** The execution
268
+ plane's switch mode deliberately uses one shared `local-mcp` connection identity,
269
+ and the per-call decision is reached through that identity. The decision is bound
270
+ to the deciding caller's OWN task, so another task's pending request is not
271
+ addressable, but any local process that presents itself as the commander can
272
+ decide that connection's own pending requests. **The switch remains an operator
273
+ control, not a per-process security boundary**, and the bridge does not change
274
+ that. A caller-supplied role label is not used as an identity anywhere.
275
+ - **The OS temporary area is a native platform exception.** DSH's own sandbox layer
276
+ admits the platform temp directory in some configurations. That is a property of
277
+ the native platform, **not** a write permission this plugin grants, and it is not a
278
+ statement that a worker may write arbitrary temp paths.
279
+ - **A native `reason` string is the asker's claim, not the operation.** The bridge
280
+ binds a decision to the arguments read from the Session log, not to the prose the
281
+ asking tool wrote, precisely because the prose is model-generated.
282
+ - **Desktop real-install acceptance is not complete.** Installing this build into the
283
+ DSH Desktop *production* profile and exercising the permission and continuation
284
+ behaviour there has not been performed.
285
+
286
+ These points are open work, not released features.
287
+
288
+ ### What 1.2.0 changes here: nothing, and that is the point
289
+
290
+ The 1.2.0 release fixes waiting semantics, adds an independent local control channel and
291
+ upgrades installed Codex integrations. None of those widens a permission:
292
+
293
+ - the control CLI (`bin/dsh-delegate-control.js`) has exactly two verbs, `status <taskId>`
294
+ and `cancel <taskId>`, uses the SAME loopback execution plane as the MCP server, and
295
+ adds no token, grant, switch, settings or configuration surface. It cannot submit a
296
+ task, approve anything, or act on a task other than the one named; the per-call
297
+ permission decision is still made only by `delegate_permission_decide`;
298
+ - the startup upgrade of an installed Codex MCP entry writes only values this plugin can
299
+ prove it wrote before (marker + its own Node command + its own `dsh-delegate-mcp.js`
300
+ file name) and only when they are stale. It cannot create the entry, adopt a same-name
301
+ entry, follow a link at `$CODEX_HOME`/`agents`, or edit any other Codex setting;
302
+ - the `interrupted` fix is a reporting correction: an interrupted OBSERVATION is no longer
303
+ reported as an ended execution. It changes what a host is told, not what a worker may
304
+ do — the standing sandbox mode stays `workspace-write` and the approval stance is
305
+ unchanged.
306
+
307
+ The two limitations above that matter for this release are unchanged and restated: the
308
+ switch and the per-call bridge are **not** per-process authentication against arbitrary
309
+ same-user code, and Desktop production-profile acceptance has still not been performed.
310
+
311
+ ## What *was* verified
312
+
313
+ With the real native `SandboxPolicyService` and `ApprovalService` (the installed
314
+ `0.2.0-rc.2` peers in this repository; the `0.2.2-rc.1` reference sources have the
315
+ same `request`/`decide` and `approveEscalation` call shapes), in disposable fixtures
316
+ rather than the production Desktop profile:
317
+
318
+ - the installed `sandbox/mode` and `approval/policy` events read back through both
319
+ services as `workspace-write` and `never`/`ask`, and the resolved workspace root is
320
+ the Session's own directory (a different spelling of the same directory is accepted;
321
+ a genuinely different one is refused);
322
+ - an escalation inside a valid turn under `never` is rejected immediately, without
323
+ reaching any approval answerer; under an armed bridge it is answered
324
+ `allowed-once`/`rejected` by that bridge and the paused call resumes with the
325
+ native outcome;
326
+ - an unarmed bridge, a disposed bridge and a bridge bound to another Agent all leave
327
+ the run at `never`, so no run installs an `ask` nobody services;
328
+ - a second escalation asks again, and the first grant cannot decide it (a
329
+ non-reusable request identity and a per-arguments fingerprint);
330
+ - a missing service, a refusing service, or a read-back that disagrees is
331
+ `RUN_SANDBOX_POLICY_UNAVAILABLE` raised before the prompt — no prompt is delivered;
332
+ a bridge that cannot be armed is `RUN_PERMISSION_BRIDGE_UNAVAILABLE`, also before
333
+ the prompt;
334
+ - ownership of a continuation is refused across connections and across a restart,
335
+ and the refusal touches nothing native (no Session resolved, none created, no
336
+ Agent driven).
337
+
338
+ Prompt delivery in those checks was **intercepted inside the fixture**; no real provider
339
+ was called and no worker command was executed under the policy. No independent native
340
+ boot on `0.2.1-rc.3` was performed for this task, and no real Desktop-process approval
341
+ was exercised.
342
+
343
+ The worker permission contract and the per-call bridge are covered by
344
+ `tests/sandbox.test.js` and `tests/permissions.test.js`; continuation ownership by
345
+ `tests/continuation-auth.test.js`; the placement and lifecycle behaviour around both
346
+ by `tests/controller-lifecycle.test.js`; the MCP surface and the plane route by
347
+ `tests/mcp.test.js`.