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,443 @@
1
+ # Historical Stage B contract: user plane and execution plane
2
+
3
+ > Superseded: this document describes the earlier per-connection grant/token
4
+ > design. The current product uses one persisted local-call switch, requires no
5
+ > MCP connection token and hides grant-control routes in switch mode. See
6
+ > `README.md`, `SPEC.md` and `docs/auth-contract.md` for the current contract.
7
+
8
+ This document is the contract a later Chinese-language native DSH settings UI
9
+ ("Stage B UI") codes against. It records the exact routes, methods, request
10
+ bodies and response shapes that exist in this repository today, and it
11
+ distinguishes the two planes because they have different credentials, different
12
+ carriers and different authority.
13
+
14
+ Nothing here has to be renegotiated by the UI: the UI drives only the **user
15
+ plane**. The execution plane is documented for completeness because connection
16
+ tokens and task ids appear in both, and mixing them up is the one way the UI can
17
+ produce a security bug.
18
+
19
+ ---
20
+
21
+ ## 1. Two planes, two credentials
22
+
23
+ | | User plane | Execution plane |
24
+ |---|---|---|
25
+ | Full URL | `/api/dsh-delegate/<route>` | `/dsh-delegate/x/<route>` |
26
+ | Carrier | `ctx.connection.fetch` (native exact fetch routes) | `ctx.webServer.register` (plain node:http) |
27
+ | Transport fence | the harness's own `/api` Host/Origin fence | loopback socket + loopback Host + same-origin browser marker |
28
+ | Who is admitted | the operator's authenticated browser session, proven by the native `connection` service *before* any handler runs | one registered connection, proven by `Authorization: Bearer <connection token>` on each request |
29
+ | What it may do | issue and revoke connections and grants, read/write settings, read the catalog, read/cancel tasks | submit a task, read tasks, cancel tasks — it can only *exercise* an authorization, never create one |
30
+ | Adds its own auth header | **no** | yes: `authorization: Bearer <token>` |
31
+ | Method vocabulary | `GET`, `HEAD`, `POST` only | `GET`, `POST` |
32
+
33
+ Two rules follow and neither is negotiable in the UI:
34
+
35
+ 1. **The user plane never inspects an `authorization` header.** Presenting a
36
+ connection token to a user-plane route changes nothing; admission already
37
+ happened in the carrier. A UI that works because "the browser has a cookie" is
38
+ correct; a UI that works because "we sent a token" is relying on something the
39
+ user plane does not implement.
40
+ 2. **The execution plane cannot issue authorization.** No route there creates a
41
+ connection, issues a grant, writes settings or changes policy.
42
+
43
+ ### Native registration constraints (why the routes look like this)
44
+
45
+ From the installed `@deepseek-ai/dsh-client-connection` 0.2.0-rc.2
46
+ (`lib/index.js`, `lib/types/rpc.d.ts`):
47
+
48
+ - `path` must resolve below `/api` (`endpointFromPath(channel, pathname)` at
49
+ `lib/index.js:711`, called with `"/api"`).
50
+ - `methods` may only be `GET`, `HEAD`, `POST`
51
+ (`type ConnectionFetchMethod`).
52
+ - `requestBody` may only be `buffered` or `streaming`
53
+ (`type ConnectionRequestBodyMode`). There is **no** `none` mode.
54
+ - Routes are keyed by exact path (`this.fetchRoutes.get(url.pathname)`); a second
55
+ registration of one path throws
56
+ (`connection: exact Fetch route "…" is already registered`, `lib/index.js:634`).
57
+
58
+ Therefore: one exact path per route, methods combined, and dispatch on
59
+ `request.method` inside handlers that own more than one method. All user-plane
60
+ routes declare `requestBody: 'buffered'` — the bodies are small JSON control
61
+ documents and streaming would only add an unbounded read. The plugin asserts
62
+ these properties itself before registering (`assertUserPlaneRoutes` in
63
+ `src/http/user-plane.js`), so a future edit cannot half-register the surface.
64
+
65
+ ---
66
+
67
+ ## 2. Common response conventions
68
+
69
+ Success bodies always carry `ok: true`. Refusals always carry:
70
+
71
+ ```json
72
+ { "ok": false, "error": { "code": "STABLE_CODE", "message": "human text", "details": {} } }
73
+ ```
74
+
75
+ - `code` is stable and machine-checkable; the UI should switch on it and render
76
+ its own Chinese label. `message` is English and may change.
77
+ - `details` is bounded, redacted, and may be `{}`.
78
+ - Responses are `cache-control: no-store` and `x-content-type-options: nosniff`.
79
+ - Nothing in any response contains a credential value, a credential hash, a
80
+ provider endpoint's secret material or a connection token except at the single
81
+ documented issuance moment (§3.6).
82
+
83
+ Status codes used: `200` read/commit, `201` issued, `202` accepted (execution
84
+ plane only), `400` malformed/validation, `401` execution-plane token missing or
85
+ invalid, `403` transport fence, `404` unknown route or unknown id, `405` method not
86
+ owned by the path, `409` conflict/refusal (grant consumed, workspace busy), `413`
87
+ body too large, `500` unexpected (message replaced by a generic one).
88
+
89
+ ### Methods a path does not own
90
+
91
+ A path that declares `GET` and `POST` refuses anything else with:
92
+
93
+ ```
94
+ 405 allow: GET, POST
95
+ { "ok": false, "error": { "code": "USER_PLANE_METHOD_NOT_ALLOWED",
96
+ "message": "DELETE is not allowed on /api/dsh-delegate/settings",
97
+ "details": { "method": "DELETE", "allowed": ["GET", "POST"] } } }
98
+ ```
99
+
100
+ Note that the native carrier only forwards methods a route declared, so an
101
+ undeclared method normally never reaches the handler at all. The 405 exists for
102
+ direct and future in-process callers; the UI should treat a non-declared method
103
+ as a client bug rather than as a documented path.
104
+
105
+ ---
106
+
107
+ ## 3. User plane (authenticated; the UI's whole surface)
108
+
109
+ Prefix: `/api/dsh-delegate`. Eleven exact paths, one route each; `settings`,
110
+ `connections` and `grants` each carry both `GET` and `POST` on a single route and
111
+ dispatch on `request.method`.
112
+
113
+ | Path | Methods | Body | Purpose |
114
+ |---|---|---|---|
115
+ | `/api/dsh-delegate/status` | GET | — | plugin and delegation posture |
116
+ | `/api/dsh-delegate/settings` | GET, POST | — / `{settings}` | read / replace settings |
117
+ | `/api/dsh-delegate/catalog` | POST | `{}` or `{projectPath}` | provider model/effort catalog + effective config |
118
+ | `/api/dsh-delegate/connections` | GET, POST | — / `{label?}` | list / issue a connection |
119
+ | `/api/dsh-delegate/connections/revoke` | POST | `{connectionId}` | revoke one connection and its grants |
120
+ | `/api/dsh-delegate/grants` | GET, POST | — / `{connectionId,kind,workspacePath,ttlSeconds?,overrides?}` | list / issue a grant |
121
+ | `/api/dsh-delegate/grants/revoke` | POST | `{grantId}` | revoke one grant |
122
+ | `/api/dsh-delegate/authorization/revoke-all` | POST | `{}` | revoke every grant and connection |
123
+ | `/api/dsh-delegate/tasks` | GET | — | list tasks, optional `?connectionId=` |
124
+ | `/api/dsh-delegate/tasks/get` | POST | `{taskId}` | one task **with** its prompt |
125
+ | `/api/dsh-delegate/tasks/cancel` | POST | `{taskId}` | cancel, recorded as `cancelledBy: "operator"` |
126
+
127
+ (That table lists eleven paths: the count that matters is that every path appears
128
+ exactly once, and that `settings`, `connections` and `grants` each carry both
129
+ `GET` and `POST` rather than being split across two registrations of one path.)
130
+
131
+ ### 3.1 `GET /api/dsh-delegate/status`
132
+
133
+ ```json
134
+ { "ok": true,
135
+ "delegation": { "authorized": false, "reason": "no live delegation authorization exists" },
136
+ "runtime": { "plugin": "dsh-delegate", "version": "0.1.0", "schemaVersion": 1,
137
+ "bind": "127.0.0.1", "port": 3210,
138
+ "executionPlane": "/dsh-delegate/x", "executionPlaneLocalOnly": true } }
139
+ ```
140
+
141
+ `delegation.authorized` is the plugin's single "is delegation on" oracle. It is
142
+ `false` in a fresh process and after every restart, because authorization is held
143
+ only in memory. `runtime` is diagnostic: the UI should show `version` and may show
144
+ the bind facts, but must not build logic on them.
145
+
146
+ ### 3.2 `GET /api/dsh-delegate/settings`
147
+
148
+ ```json
149
+ { "ok": true,
150
+ "settings": {
151
+ "schemaVersion": 1,
152
+ "providers": [{ "id": "relay", "name": "Local relay", "protocol": "openai-chat",
153
+ "baseUrl": "http://127.0.0.1:8443/v1",
154
+ "credentialRef": "DSH_DELEGATE_RELAY_KEY", "models": [{ "id": "deepseek-chat", "efforts": ["low","medium","high"] }] }],
155
+ "worker": { "providerId": "relay", "model": "deepseek-chat", "reasoningEffort": "medium",
156
+ "timeoutSeconds": 1800, "maxParallelism": 1, "isolation": "shared" },
157
+ "review": { "enabled": false, "providerId": null, "model": null, "reasoningEffort": null },
158
+ "authorization": { "taskGrantTtlSeconds": 900, "sessionGrantTtlSeconds": 14400 },
159
+ "projectOverrides": {}
160
+ },
161
+ "secrets": { "stored": "credential-seam-only", "values_returned": false } }
162
+ ```
163
+
164
+ `credentialRef` is the *name* of a credential, not a credential. There is no field
165
+ in this document that ever carries a secret value; `secrets` says so explicitly so
166
+ the UI does not have to infer it. A masked secret the operator types belongs in the
167
+ credential seam, not in this document — settings validation refuses a provider that
168
+ carries a secret-shaped field (`PROVIDER_SECRET_IN_SETTINGS`).
169
+
170
+ ### 3.3 `POST /api/dsh-delegate/settings`
171
+
172
+ Request: `{ "settings": <the full document above, minus `secrets`> }`.
173
+
174
+ Response `200`: `{ "ok": true, "settings": <committed public document> }`.
175
+
176
+ The document is replaced wholesale after full validation; there is no partial
177
+ patch on this path. Refusals:
178
+
179
+ | Code | Status | Meaning |
180
+ |---|---|---|
181
+ | `SETTINGS_MISSING` | 400 | no `settings` property in the body |
182
+ | `SETTINGS_INVALID` | 400 | envelope/schema problem |
183
+ | `SETTINGS_NO_PROVIDERS` | 400 | a document that needs a provider has none |
184
+ | `PROVIDER_*` | 400 | provider profile refused (`ID_INVALID`, `DUPLICATE`, `BASE_URL_INVALID`, `CREDENTIAL_REF_INVALID`, `PROTOCOL_UNSUPPORTED`, `SECRET_IN_SETTINGS`, …) |
185
+ | `MODEL_*` | 400 | model list refused (`INVALID`, `DUPLICATE`, `EFFORTS_INVALID`) |
186
+ | `SELECTION_*` | 409 | worker/review selection refused (`PROVIDER_REQUIRED`, `PROVIDER_UNKNOWN`, `MODEL_REQUIRED`, `MODEL_UNKNOWN`, `EFFORT_UNKNOWN`, `EFFORT_UNSUPPORTED`) |
187
+ | `BODY_INVALID_JSON`, `BODY_NOT_OBJECT`, `BODY_TOO_LARGE` | 400/413 | transport-level body problem |
188
+
189
+ A refused write leaves the stored document untouched; the UI can simply re-read
190
+ `GET` to recover. There is no `PUT` on this route and none should be added: the
191
+ native registry cannot carry it.
192
+
193
+ ### 3.4 `POST /api/dsh-delegate/catalog`
194
+
195
+ Request: `{}` or `{ "projectPath": "C:\\work\\project" }` (`projectPath` is
196
+ optional and only affects the `effective` block).
197
+
198
+ ```json
199
+ { "ok": true,
200
+ "catalog": [{ "providerId": "relay", "route": "relay",
201
+ "models": [{ "id": "deepseek-chat", "efforts": ["low","medium","high"], "defaultEffort": null }],
202
+ "error": null }],
203
+ "effective": { "schemaVersion": 1,
204
+ "worker": { "providerId": "relay", "model": "deepseek-chat", "reasoningEffort": "medium",
205
+ "timeoutSeconds": 1800, "maxParallelism": 1, "isolation": "shared", "providerRoute": "relay" },
206
+ "review": { "enabled": false, "providerId": null, "model": null, "reasoningEffort": null, "providerRoute": null },
207
+ "provenance": { "projectPath": null, "applied": [] } } }
208
+ ```
209
+
210
+ - `catalog[].models[].efforts` is the *authority* for which efforts the UI may
211
+ offer. An effort absent here must not be selectable, and the server will refuse
212
+ it anyway (`SELECTION_EFFORT_UNSUPPORTED`).
213
+ - `catalog[].error` is `null` or `{ code, message, detail? }`; a provider that
214
+ cannot resolve models is reported, not hidden.
215
+ - `effective` is `null` when no provider is configured.
216
+ - `catalog` may be slow (it asks the routing layer per model). The UI must show a
217
+ loading state and must not block the authorization controls on it.
218
+
219
+ ### 3.5 `GET /api/dsh-delegate/connections`
220
+
221
+ ```json
222
+ { "ok": true,
223
+ "connections": [{ "connectionId": "conn-<uuid>", "label": "codex",
224
+ "createdAt": 1730000000000, "lastSeenAt": 1730000000000,
225
+ "revoked": false, "revokedAt": null, "peer": { "address": "operator-session" } }] }
226
+ ```
227
+
228
+ No token, no hash. A revoked connection stays listed so the operator can see what
229
+ happened; `revoked: true` means it can no longer authenticate on the execution
230
+ plane.
231
+
232
+ ### 3.6 `POST /api/dsh-delegate/connections`
233
+
234
+ Request: `{ "label": "codex" }` (`label` optional; trimmed, max 80 chars).
235
+
236
+ ```json
237
+ { "ok": true,
238
+ "connection": { "connectionId": "conn-<uuid>", "label": "codex", "createdAt": 1730000000000 },
239
+ "token": "<base64url secret>",
240
+ "tokenReturnedOnce": true }
241
+ ```
242
+
243
+ **This is the only response in either plane that carries a secret.** The UI must
244
+ show it once, offer copy, and never persist it or request it again — a later
245
+ `GET` cannot return it. Refusal: `CONNECTION_LIMIT` (403) at the registry cap.
246
+
247
+ ### 3.7 `POST /api/dsh-delegate/connections/revoke`
248
+
249
+ Request: `{ "connectionId": "conn-…" }` →
250
+ `{ "ok": true, "grantsRevoked": 2 }`.
251
+
252
+ Revoking a connection revokes every grant it holds in the same step. Refusals:
253
+ `CONNECTION_ID_REQUIRED` (400), `CONNECTION_UNKNOWN` (403 — the shared
254
+ `CONNECTION_` prefix maps to a transport-style refusal; the UI should read `code`,
255
+ not the status, to tell "unknown id" from "fence refused").
256
+
257
+ ### 3.8 `GET /api/dsh-delegate/grants?connectionId=conn-…`
258
+
259
+ ```json
260
+ { "ok": true,
261
+ "grants": [{ "grantId": "grant-<uuid>", "kind": "task", "workspacePath": "C:\\work\\project",
262
+ "createdAt": 1730000000000, "expiresAt": 1730000900000,
263
+ "consumedAt": null, "consumedByTaskId": null, "revokedAt": null, "overrides": null }] }
264
+ ```
265
+
266
+ `connectionId` is a required query parameter (`CONNECTION_ID_REQUIRED`, 400).
267
+ The UI renders state from the four timestamps: `revokedAt !== null` → revoked;
268
+ `consumedAt !== null` → spent (task grants are single-use); `expiresAt <= now` →
269
+ expired; otherwise live.
270
+
271
+ ### 3.9 `POST /api/dsh-delegate/grants`
272
+
273
+ ```json
274
+ { "connectionId": "conn-…", "kind": "task" | "session",
275
+ "workspacePath": "C:\\work\\project",
276
+ "ttlSeconds": 900, // optional; defaults from settings.authorization
277
+ "overrides": null } // optional; providerId/model/reasoningEffort/timeoutSeconds/isolation
278
+ ```
279
+
280
+ Response `201`:
281
+
282
+ ```json
283
+ { "ok": true,
284
+ "grant": { "grantId": "grant-<uuid>", "kind": "task", "workspacePath": "C:\\work\\project",
285
+ "createdAt": 1730000000000, "expiresAt": 1730000900000,
286
+ "consumedAt": null, "consumedByTaskId": null, "revokedAt": null, "overrides": null } }
287
+ ```
288
+
289
+ `kind` defaults to nothing: it must be `task` or `session` (`GRANT_KIND_INVALID`,
290
+ 409). A grant always names exactly one connection and one absolute workspace, so it
291
+ cannot be spent elsewhere (`GRANT_MISMATCH`, 409). TTL defaults come from
292
+ `settings.authorization` (`taskGrantTtlSeconds` / `sessionGrantTtlSeconds`) and are
293
+ validated (`GRANT_TTL_INVALID`, 409). Other refusals: `GRANT_LIMIT` (409),
294
+ `CONNECTION_UNKNOWN` (403). This response contains **no** token — the operator
295
+ issues the grant, the connection already holds the credential.
296
+
297
+ ### 3.10 `POST /api/dsh-delegate/grants/revoke`
298
+
299
+ Request: `{ "grantId": "grant-…" }` →
300
+ `{ "ok": true, "grant": { …grant snapshot with revokedAt set… } }`.
301
+
302
+ Operator-only: this path passes `allowOperator: true`, so it can revoke a grant
303
+ belonging to any connection. Refusals: `GRANT_ID_REQUIRED` (400),
304
+ `GRANT_UNKNOWN` (404). Revoking a grant takes effect immediately for session
305
+ grants (checked per execution) and permanently ends a task grant.
306
+
307
+ ### 3.11 `POST /api/dsh-delegate/authorization/revoke-all`
308
+
309
+ Request: `{}` → `{ "ok": true, "grantsRevoked": 3 }`. Revokes every grant and every
310
+ connection. This is the "stop everything now" control, and `status.delegation`
311
+ must flip to `authorized: false` immediately after; the UI should re-read `status`.
312
+
313
+ ### 3.12 `GET /api/dsh-delegate/tasks[?connectionId=conn-…]`
314
+
315
+ `{ "ok": true, "tasks": [ <task view> ] }`, newest first. Omitting the query
316
+ parameter lists across all connections. The task view is described once in §5.
317
+
318
+ ### 3.13 `POST /api/dsh-delegate/tasks/get`
319
+
320
+ Request: `{ "taskId": "task-…" }` → `{ "ok": true, "task": <task view with prompt> }`.
321
+ Refusal: `JOB_TASK_NOT_FOUND` (404).
322
+
323
+ ### 3.14 `POST /api/dsh-delegate/tasks/cancel`
324
+
325
+ Request: `{ "taskId": "task-…" }` → `{ "ok": true, "task": <task view> }`, with
326
+ `cancelledBy: "operator"`. A task already terminal is returned unchanged rather
327
+ than refused, so a double-click is harmless. Refusal: `JOB_TASK_NOT_FOUND` (404).
328
+
329
+ ---
330
+
331
+ ## 4. Execution plane (bearer token; not the UI's surface)
332
+
333
+ Prefix: `/dsh-delegate/x`. Plain node:http, **not** under `/api`, registered only
334
+ when the webserver binds `127.0.0.1`; otherwise it is not registered at all and
335
+ external submissions are refused.
336
+
337
+ Every request needs `Authorization: Bearer <connection token>`. The transport fence
338
+ (loopback socket, loopback Host, same-origin marker for browser-flagged requests)
339
+ runs first and is a filter, never proof: any local program can send those headers.
340
+ One refusal answers every authentication failure — `401` with
341
+ `CONNECTION_UNKNOWN` — because distinguishing "no token" from "bad token" from
342
+ "revoked" helps an attacker and not an operator.
343
+
344
+ | Path | Method | Body | Purpose |
345
+ |---|---|---|---|
346
+ | `/dsh-delegate/x/status` | GET | — | this connection, its live grants, delegation posture |
347
+ | `/dsh-delegate/x/tasks` | POST | `{grantId?, authorization?, workspacePath, prompt, overrides?}` | submit one task → `202` |
348
+ | `/dsh-delegate/x/tasks` | GET | — | list only this connection's tasks |
349
+ | `/dsh-delegate/x/tasks/get` | POST | `{taskId}` | one task; another connection's task reads as absent (`JOB_TASK_NOT_FOUND`) |
350
+ | `/dsh-delegate/x/tasks/cancel` | POST | `{taskId}` | cancel; cross-connection reads as absent |
351
+
352
+ `authorization` is `"task"` (default; consumes `grantId` exactly once) or
353
+ `"session"` (re-checks a live session grant covering the workspace). The
354
+ connection identity comes from the verified token, never from the body.
355
+
356
+ The UI never calls this plane. Its only overlap with the UI is that the token it
357
+ displays once becomes this plane's credential, and the `connectionId` is a
358
+ read-only join key in both planes.
359
+
360
+ ---
361
+
362
+ ## 5. Task view (shared shape, both planes)
363
+
364
+ ```json
365
+ {
366
+ "taskId": "task-<uuid>",
367
+ "state": "pending | running | awaiting-host-review | failed | cancelled",
368
+ "createdAt": 1730000000000, "startedAt": 1730000000100, "endedAt": 1730000000900,
369
+ "workspacePath": "C:\\work\\project",
370
+ "connectionId": "conn-<uuid>", "grantId": "grant-<uuid>",
371
+ "effective": {
372
+ "worker": { "providerId": "relay", "model": "deepseek-chat", "reasoningEffort": "medium",
373
+ "timeoutSeconds": 1800, "maxParallelism": 1, "isolation": "shared", "providerRoute": "relay" },
374
+ "review": { "enabled": false, "providerId": null, "model": null, "reasoningEffort": null, "providerRoute": null },
375
+ "provenance": { "projectPath": null, "applied": [] }
376
+ },
377
+ "route": { "providerId": "relay", "model": "deepseek-chat", "reasoningEffort": "medium" },
378
+ "baseline": {}, "diff": {},
379
+ "execution": { "outcome": "completed", "text": "…", "reasoningOnly": false,
380
+ "usage": { "inputTokens": 10, "outputTokens": 5, "totalTokens": 15 },
381
+ "turnEnd": {}, "agentId": "…", "sessionId": "…", "cancelCause": null, "error": null },
382
+ "review": { "state": "disabled | not_run | completed | failed",
383
+ "verdict": "approve | changes-requested | unknown | null", "text": "", "error": null },
384
+ "error": null, "cancelledBy": null,
385
+ "hostAcceptance": null,
386
+ "selfApproved": false,
387
+ "prompt": "…" // present only on tasks/get, never in tasks list
388
+ }
389
+ ```
390
+
391
+ Rules the UI must honour when rendering this:
392
+
393
+ - `awaiting-host-review` means **executed**, not **approved**. `selfApproved` is
394
+ always `false`, and `hostAcceptance` is `null` until the host records an
395
+ acceptance of its own. The UI must not render "done" or "accepted" for either
396
+ state.
397
+ - `effective` is the immutable snapshot taken when the task started; a later
398
+ settings change does not apply to it. Show it as the task's actual configuration.
399
+ - `review` is separate from `state`. A review failure is not a task failure.
400
+ - `prompt` is only on `tasks/get`; the list view omits it. Prompt and error text
401
+ are redacted before they leave the engine.
402
+
403
+ ---
404
+
405
+ ## 6. Settings surface mapping (four areas)
406
+
407
+ The Chinese UI's four areas map onto the contract as follows; no area needs a
408
+ route that does not exist.
409
+
410
+ 1. **API 管理** — `GET`/`POST /api/dsh-delegate/settings` for the document,
411
+ `POST /api/dsh-delegate/catalog` for model ids and effort capabilities.
412
+ Credential references are names resolved by the DSH credential seam; masked
413
+ input never round-trips through this API.
414
+ 2. **执行设置** — `settings.worker` inside the same document, bounded by
415
+ `catalog[].models[].efforts` for effort and by the validator for
416
+ timeout/parallelism/isolation. `catalog.effective` previews the composed result.
417
+ 3. **附加审查** — `settings.review`, independent of authorization and off by
418
+ default.
419
+ 4. **任务记录** — `GET /api/dsh-delegate/tasks`, `POST …/tasks/get`,
420
+ `POST …/tasks/cancel`.
421
+
422
+ Authorization controls sit **above** those four areas and use only
423
+ `/connections*`, `/grants*`, `/authorization/revoke-all` and `/status`. A UI that
424
+ places grant issuance inside "执行设置" would misrepresent it: execution settings do
425
+ not authorize anything, and delegation stays off until a grant exists.
426
+
427
+ ---
428
+
429
+ ## 7. What this slice does not promise
430
+
431
+ - No admission test is claimed at this layer. Browser authentication and the
432
+ Host/Origin fence belong to the native `connection` service and are exercised
433
+ there; a unit test that hand-fed a cookie would assert a guarantee this module
434
+ does not provide.
435
+ - CSRF for the user plane is the carrier's same-origin fence plus the
436
+ browser-session cookie policy. This document does not add a second mechanism.
437
+ - `HEAD` is accepted by the registry but declared on no route here; a `HEAD`
438
+ request therefore falls through to the carrier's `404`. If a future health check
439
+ needs it, add it to the declared methods of `/status` — do not add a new route
440
+ with the same path, which would throw at registration.
441
+ - The execution plane's `GET /tasks` and `POST /tasks` are two different routes on
442
+ two different carriers (node:http prefix routing), unlike the `/api` exact-path
443
+ registry; they are listed together only because they share a suffix.