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,293 @@
1
+ # DSH conversation placement and task threads
2
+
3
+ Which DSH **Workspace** a delegated run appears in, and which conversation it
4
+ drives. Implementation: `src/runtime/session-placement.js`, wired in
5
+ `src/index.js`, called by `src/runtime/agent-runner.js` and
6
+ `src/jobs/engine.js`.
7
+
8
+ This is unrelated to `docs/workspace-contract.md`: that document is about the
9
+ repository root a run mutates. This one is about the DSH Workspace *group* the
10
+ run's Session is filed under, and about which task thread it continues.
11
+
12
+ ## The rule, in one paragraph
13
+
14
+ **A new submission is a new conversation. A follow-up continues exactly one named
15
+ task thread.** There is no directory-level `new`/`reuse` setting and no
16
+ directory-keyed identity map. `delegate_submit` accepts the optional field
17
+ `continueFromTaskId`; omitting it always creates a fresh DSH Session in the
18
+ Workspace for the run's execution path, and supplying it continues the DSH
19
+ Workspace and Session that *that* task drove. Supplying it is the only way any
20
+ conversation is ever continued.
21
+
22
+ ## The two questions, and the two services that answer them
23
+
24
+ | Question | Native service | Dependency key |
25
+ | --- | --- | --- |
26
+ | Which Workspace group? | `ctx.workspaceController` | `deps.workspaces` |
27
+ | Which Session, and its Agent? | `ctx.sessionController` | `deps.sessionController` |
28
+
29
+ `ctx.sessions` is the native **persistence** service (`flush`). It cannot create
30
+ or resolve a Session, so `deps.sessions` is never used for placement. Reading it
31
+ there was a real defect: it reported a fully composed harness as having no
32
+ session controller, and every worker run failed with
33
+ `SESSION_CONTROLLER_UNAVAILABLE`. The wiring is asserted directly in
34
+ `tests/session-placement.test.js` ("placement reads the session CONTROLLER,
35
+ never the native sessions service").
36
+
37
+ ## Verified native signatures
38
+
39
+ Read from the installed runtime declarations, not guessed:
40
+
41
+ - `WorkspaceController.create(request: { path }): Promise<{ workspace:
42
+ WorkspaceView, created: boolean }>` — create-or-reuse over an existing
43
+ directory; `WorkspaceView` carries `workspaceId` and the canonical `path`.
44
+ - `SessionController.create(request: { workspaceId?, cwd?, sessionId?,
45
+ agentPreset? }): Promise<{ sessionId, agentPreset? }>`.
46
+ - `SessionController.resolveAgent(sessionId): Promise<{ agent } | { error }>`,
47
+ where the error is a `RemoteError` of `session/not-found`,
48
+ `session/agent-busy`, `session/writer-held` or `gateway/internal`.
49
+ - `Agent` carries `id`, `session`, a live `ctx: Context` (`ctx.on(...)`), plus
50
+ `followup`, `cancel`, `whenIdle`.
51
+
52
+ ## Flow
53
+
54
+ 1. **Capability checks first.** A missing controller is a stated refusal
55
+ (`SESSION_WORKSPACES_UNAVAILABLE` / `SESSION_CONTROLLER_UNAVAILABLE`), never a
56
+ fallback to an ungrouped session.
57
+ 2. **Workspace.** `workspaceController.create({ path })` with the run's *actual*
58
+ execution directory (`task.executionPath` — the worktree when isolation
59
+ prepared one, the source checkout otherwise). Repeating a run in one directory
60
+ reuses one group instead of accumulating duplicates.
61
+ 3. **Session.**
62
+ - `continueFromTaskId` **omitted** — `sessionController.create({ workspaceId })`
63
+ creates a fresh Session, then `resolveAgent` attaches its Agent. Nothing is
64
+ read from the identity map, so a directory with a long history still gets a
65
+ new conversation.
66
+ - `continueFromTaskId` **supplied** — that task's recorded identity is loaded
67
+ and every fact a continuation depends on is re-checked (below), including the
68
+ connection that submitted it (from the live record, or from the durable job
69
+ history after a restart), then `resolveAgent` returns the live Agent of the
70
+ *same* Session, so the next turn lands in the same native session log. A
71
+ parent whose ownership cannot be proven is refused before this step.
72
+ 4. **Drive.** Both paths return a resolved `agent`, and the runner drives it.
73
+ `agents.create` is not used for a placed run: the Session already exists, so
74
+ creating an Agent that way would create a *second* Session beside the placed
75
+ one. The runner installs this run's provider/model/effort on the resolved
76
+ Agent's own context, so a per-task selection still governs a continued
77
+ conversation.
78
+ 5. **Cancellation before placement.** An already-aborted signal returns
79
+ `cancelled` before any Workspace or Session is created, so a run that never
80
+ starts cannot leave an orphan group or an empty conversation.
81
+
82
+ ## Validating a continuation (fail-closed)
83
+
84
+ Every check below refuses. None of them falls back to creating a new Session,
85
+ because that would report a continued conversation the operator is not in.
86
+
87
+ Two vocabularies, in this order:
88
+
89
+ - **Ownership.** While it cannot be proven that this caller submitted the parent,
90
+ every answer is the same `JOB_TASK_NOT_FOUND`, with no cause and no thread hint:
91
+ an unknown id, a pruned or truncated record, a record with no owner, a caller
92
+ with no verified identity, no durable history at all, and another connection's
93
+ task are deliberately indistinguishable, so the answer cannot enumerate tasks.
94
+ - **Joinability.** Only a caller that has proven the same owner ever learns *why*
95
+ a chain cannot be joined: `JOB_CONTINUATION_REFUSED` at the job boundary, with
96
+ the specific `SESSION_*` code in `error.details.session`.
97
+
98
+ ## Who owns a task thread (survives a restart)
99
+
100
+ **Strictly the connection that submitted it.** Ownership is compared as two
101
+ identity strings, never as a pattern: the `local-mcp` identity of the local
102
+ switch is a real, fixed identity and is matched exactly like an external
103
+ connection, and "no identity" is never a wildcard in either direction.
104
+
105
+ Two authorities answer this, depending on where the parent came from:
106
+
107
+ | Parent | Authority for ownership | Authority for outcome |
108
+ | --- | --- | --- |
109
+ | Admitted by this process | the live task record's `connectionId`, verified when it was admitted | the live record's state, plus its recorded conversation |
110
+ | Recovered from `sessions.json` after a restart | the durable job history (`history.json`) `connectionId` | the durable record's `state` and its `execution.conversation` block |
111
+
112
+ `sessions.json` is deliberately **not** an authority for either. It records
113
+ where a thread lives — task id, paths, Workspace/Session ids, isolation and tree
114
+ facts — and nothing about who asked for the work or how the run ended. That is
115
+ why resuming from it alone was a defect: after a restart the in-memory check
116
+ disappeared and the map would have answered "yes" to any caller that knew the
117
+ task id. The durable job history is the second authority; the two are checked in
118
+ sequence, and both must agree with the caller.
119
+
120
+ Both checks run **before** placement, and admission runs them **before settings
121
+ are read and before a concurrency slot is claimed**, so a refusal never resolves
122
+ or drives a native Session: the conversation of a task that is not yours is never
123
+ touched. The engine's authority is `JobEngine.assertContinuation`, which decides
124
+ ownership and joinability in one pass; `JobEngine.assertAdmissible` is the same
125
+ rule applied synchronously to a live record, and placement calls it as a re-check
126
+ of a chain admission already proved — including the exact execution directory, so
127
+ placement never resumes a thread whose Workspace id merely looks familiar.
128
+
129
+ ## The admission gate, in order
130
+
131
+ A `continueFromTaskId` submission is decided by one pass in `admit()`, before
132
+ step 3 (settings) and before step 4 (effective config and the concurrency slot):
133
+
134
+ 1. **Ownership first, with one refusal.** The caller must present a verified
135
+ connection id, and it must equal the parent's owner exactly. A live parent
136
+ record states its own `connectionId`; a parent this process no longer holds is
137
+ proven by the **durable job history** row's `connectionId`. No verified caller,
138
+ no history store, an unreadable or malformed history document, no record for
139
+ the id, a truncated record and a record with no owner all answer the same
140
+ `JOB_TASK_NOT_FOUND`.
141
+ 2. **One snapshot, one shape.** History is read **exactly once** and reduced to
142
+ `{ state, sourcePath, executionWorkspacePath, isolation, conversation }`, with
143
+ `conversation` taken from `row.execution.conversation`; a live parent supplies
144
+ the same shape from its own record. There is no second read of history and no
145
+ "the row was null, so skip the checks" branch — a failed read is a refusal,
146
+ never a pass.
147
+ 3. **The identity map** (`sessions.json`) is read exactly once and judged together
148
+ with that snapshot. Its Workspace id, execution dir, source repository and
149
+ isolation must agree with the snapshot; a missing row or an empty Session id is
150
+ refused.
151
+ 4. **The verified result is what steps 4 and 7 read.** Only after every check
152
+ passed is the identity recorded on the task, which is what makes the effective
153
+ isolation the parent's and what makes a worktree parent reuse the original tree
154
+ instead of preparing a new one.
155
+
156
+ | Check | Refusal |
157
+ | --- | --- |
158
+ | Parent task id is unknown, pruned, or was never recorded here | `JOB_TASK_NOT_FOUND` |
159
+ | Parent was submitted by another connection — in this process or, after a restart, according to the durable history | `JOB_TASK_NOT_FOUND` |
160
+ | Ownership cannot be proven at all (no verified caller identity, no durable history, no history record, a truncated record, a record that states no owner) | `JOB_TASK_NOT_FOUND` |
161
+ | Parent has not ended: `pending`/`running` (still running), `interrupted` (live when a previous process stopped), or a state this build does not know | `JOB_CONTINUATION_REFUSED` + `SESSION_CONTINUATION_STATE` |
162
+ | Parent ended without a placement that reached a Session (`kind` not `new`/`continuation`, or an empty Workspace id or Workspace path) — including an admission refusal or policy failure | `JOB_CONTINUATION_REFUSED` + `SESSION_CONTINUATION_STATE` |
163
+ | Parent ran for another source repository, in the snapshot or in the identity map — including a masked or missing source path, which cannot prove which repository it names | `JOB_CONTINUATION_REFUSED` + `SESSION_CONTINUATION_WORKSPACE_MISMATCH` |
164
+ | Snapshot or identity execution path is missing, empty or masked; the snapshot names no recognized isolation | `JOB_CONTINUATION_REFUSED` + `SESSION_CONTINUATION_UNAVAILABLE` |
165
+ | Identity map has no row, no Session id, or a Workspace id / execution dir / isolation that contradicts the snapshot | `JOB_CONTINUATION_REFUSED` + `SESSION_CONTINUATION_UNKNOWN` (no row) / `SESSION_CONTINUATION_UNAVAILABLE` (row contradicts the snapshot) |
166
+ | Parent's execution dir differs from this run's resolved directory (including a different worktree and a recorded conversation placed in another directory), or the parent's Workspace is not this run's | `JOB_CONTINUATION_REFUSED` + `SESSION_CONTINUATION_PATH_MISMATCH` / `SESSION_CONTINUATION_WORKSPACE_MISMATCH` |
167
+ | The build cannot resolve a Session at all | `JOB_CONTINUATION_REFUSED` + `SESSION_RESUME_UNAVAILABLE` |
168
+ | The Session no longer exists | `JOB_CONTINUATION_REFUSED` + `SESSION_RESUME_FAILED` with `cause: session/not-found` |
169
+ | The resolved Agent's own `cwd` header names another directory | `JOB_CONTINUATION_REFUSED` + `SESSION_RESUME_PATH_MISMATCH` |
170
+
171
+ Because the whole gate runs before the slot is claimed, a refusal is stable: a
172
+ parent that is still running is refused for its own state, never masked by
173
+ `JOB_CONCURRENCY_LIMIT`, and a parent's isolation mode is known before any mode is
174
+ resolved.
175
+
176
+ **A new grant is not a new owner.** Authorization tokens do not survive a
177
+ restart, so a returning client obtains a fresh grant; that grant authorizes the
178
+ *connection*, which is the same identity, so the follow-up is admitted. A
179
+ different connection holding its own perfectly valid grant is refused — a valid
180
+ authorization is never an authorization to join somebody else's chain. A
181
+ connection id that DSH re-issues after a restart is a **new** identity, so a
182
+ re-issued id is refused; there is no label or fuzzy matching anywhere in this
183
+ path.
184
+
185
+ **Fail closed, always.** Missing history, an unreadable or malformed history
186
+ document, a truncated record, a record with no owner, a pruned record, an
187
+ `interrupted` run (the job was live when a previous process stopped), a failed or
188
+ cancelled run that never drove a conversation, and a record naming another
189
+ repository are all refusals. None of them falls back to "the map says the thread
190
+ is there, so it must be yours".
191
+
192
+ **Masked paths are a refusal, never a wildcard.** The documents are projected
193
+ through redaction, which rewrites an account-identifying directory segment
194
+ (`masks-user-profile-segment`). A path carrying that segment cannot prove which
195
+ directory it names, so it is treated exactly like a missing path: it never equals
196
+ anything, it is never a pattern that matches a live path, and the continuation is
197
+ refused. Nothing in this path treats a mask as equality, and that holds for both
198
+ documents and for the live re-check.
199
+
200
+ **Equal Workspace ids are not proof of equal placement.** A recorded conversation
201
+ must name a real Workspace *and* a directory this run resolved, and a live parent
202
+ must have executed in this run's directory. A row that keeps the parent's
203
+ Workspace id while pointing the conversation at another directory is refused, and
204
+ so is a parent whose execution dir differs from the one this run resolved.
205
+
206
+ **Task locking.** A continuation chain is serialized by the existing workspace
207
+ locks rather than by a second mechanism: the parent holds the lease on its
208
+ execution path (and on its source path) for the whole run, so a follow-up that
209
+ targets the same path is refused with `JOB_WORKSPACE_BUSY` until the parent has
210
+ finished. A continuation can therefore never drive a thread mid-turn, and two
211
+ follow-ups of one chain cannot run at once.
212
+
213
+ ## Preserving workspace state for a follow-up
214
+
215
+ The execution path is part of the continuation:
216
+
217
+ - a **shared** parent continues in that same source checkout;
218
+ - a **plugin-managed worktree** parent continues in that same tree. The tree is
219
+ where the parent's uncommitted changes are, so a fresh tree would silently hide
220
+ them. The caller continues to authorize the source repository in `workspacePath`;
221
+ the engine restores the parent task's isolation and resolves the exact managed
222
+ tree from its recorded identity. It never asks the caller to authorize an
223
+ internal worktree path or substitutes a fresh tree. A tree that is gone,
224
+ disposed, unregistered, mismatched, or not a real directory is refused with
225
+ `SESSION_CONTINUATION_UNAVAILABLE`. A source checkout becoming dirty after the
226
+ parent run does not redirect the continuation: the follow-up still targets the
227
+ original isolated tree and captures a fresh baseline there.
228
+
229
+ Isolation belongs to the task chain. A follow-up uses the parent's recorded
230
+ `shared` or `worktree` isolation even if global or project settings changed after
231
+ the parent ran. A caller override that explicitly conflicts with that isolation is
232
+ refused. For a shared parent, the same source path is locked and audited again; for
233
+ a worktree parent, both the source and original tree are locked for the follow-up.
234
+
235
+ ## Settings: what was removed, and what remains
236
+
237
+ `conversation.mode` is **retired**. It is still accepted on read so an existing
238
+ document keeps loading, and it is inert: no code path consults it, so a stored
239
+ `"reuse"` cannot cause an implicit reuse. The settings page no longer offers the
240
+ control, `setConversation` refuses with `CONVERSATION_MODE_REMOVED` rather than
241
+ silently accepting a value with no effect, and the effective snapshot carries
242
+ `conversation.policy: "per-task"` — the rule, not a stored choice.
243
+
244
+ ## What is stored
245
+
246
+ `sessions.json` beside the settings document, **one row per task**:
247
+
248
+ ```json
249
+ {
250
+ "taskId": "task-…",
251
+ "sourcePath": "E:\\work\\repo",
252
+ "executionPath": "E:\\dsh\\data\\dsh-delegate\\worktrees\\task-…",
253
+ "workspaceId": "…",
254
+ "sessionId": "session-…",
255
+ "isolation": "worktree",
256
+ "worktreeId": "task-…",
257
+ "worktreeState": "awaiting-host-review",
258
+ "updatedAt": 1767225600000
259
+ }
260
+ ```
261
+
262
+ No prompt, transcript, output, credential or token count. The native session log
263
+ stays the sole owner of conversation content.
264
+
265
+ **Migration.** Rows written by the previous build were keyed by canonical
266
+ execution directory and carried no task id (`{ path, workspaceId, sessionId,
267
+ updatedAt }`). They cannot name a task thread, so they are ignored on read: there
268
+ is nothing to continue and nothing that could act as an implicit source of reuse.
269
+ The document is rewritten as schema 2 on the next save.
270
+
271
+ **After a plugin restart** a continuation still works when all of the following
272
+ hold: the identity map and the native Session both exist, the durable job
273
+ history still has a record for the parent, that record names the SAME connection
274
+ and a terminal state that has a conversation, and its recorded repository agrees
275
+ with this submission. When any of these fails the answer is an explicit
276
+ `JOB_TASK_NOT_FOUND` (ownership) or `SESSION_CONTINUATION_UNKNOWN` /
277
+ `SESSION_CONTINUATION_STATE` / `SESSION_CONTINUATION_UNAVAILABLE` /
278
+ `SESSION_RESUME_FAILED` (everything else) — never a different or a new session,
279
+ and never the parent's Session. A connection identity that DSH re-issues under a
280
+ new id after the restart is a different identity and is refused; there is no
281
+ label or fuzzy matching anywhere in this path.
282
+
283
+ ## Ownership and disposal
284
+
285
+ A resolved Agent belongs to its Session, so the runner never disposes one:
286
+ disposal would end the conversation and make a later `continueFromTaskId`
287
+ follow-up unable to resolve it. Only the unplaced path (`allowUnplaced`, used by
288
+ the additional review) creates an Agent through `agents.create`, and only that
289
+ Agent is disposed.
290
+
291
+ The review sets `allowUnplaced: true` deliberately: it must not join the
292
+ operator's Workspace history, it is not part of the worker thread, and it is not
293
+ resumable by a later continuation.
@@ -0,0 +1,30 @@
1
+ # DSH 插件索引、搜索和更新
2
+
3
+ 本项目发布 **DSH TaskBridge 自定义插件索引**。它不是官方内置市场收录,也不会自动出现在没有订阅该索引的用户的搜索结果中。
4
+
5
+ 索引地址:
6
+
7
+ ```text
8
+ https://ranranyya.github.io/dsh-taskbridge/index.json
9
+ ```
10
+
11
+ ## 在 DSH 中使用
12
+
13
+ 1. 打开“插件”,启用实验性的“自定义插件索引”。
14
+ 2. 在“发现”中选择“添加索引源”,填写上面的 HTTPS 地址。
15
+ 3. 搜索 **DSH TaskBridge** 或 **dsh-taskbridge**。
16
+ 4. 安装确认框应显示本项目 GitHub 仓库和精确提交。核对后安装,不要改填别人的 `dsh-delegate` 或 `dsh-dispatch` npm 包。
17
+
18
+ 当前索引采用固定 Git 提交作为安装来源,不依赖本机 npm 登录。另一种安装方式是直接在“添加插件”中输入 `dsh-taskbridge@1.3.1`,无需添加索引;若中国大陆镜像未同步,改选 npm 官方源。GitHub Release 同时提供 `.tgz` 和 SHA256 文件。
19
+
20
+ ## 新版本
21
+
22
+ 正式 Release 发布后,GitHub Pages 工作流会重新生成索引。支持 Git 来源更新的 DSH 版本可在索引中选择同一仓库的新版本更新;旧 Desktop 若提示第三方插件需要卸载再安装,以客户端实际能力为准。此前从本地 `.tgz` 安装的副本不保证自动转为 Git 来源。1.2.0 或 1.3.0 到 1.3.1 还涉及包名变更,必须先按 [升级说明](taskbridge-upgrade.md)迁移。曾添加旧 TaskDispatch 索引的用户,应改用本页的新索引地址。
23
+
24
+ 工作流或 Pages 尚未部署成功时,不能声称已可搜索。发布报告记录实际公开地址、返回状态、格式校验与所指提交。索引中的 `engines.dsh` 与插件自身一致,不把未验证的宿主版本加进兼容范围。
25
+
26
+ ## 维护发布源
27
+
28
+ `scripts/build-plugin-market.mjs` 从已检出的包元数据、明确的 40 位提交 SHA 和真实发布时间生成索引;不使用分支名或占位提交,不编造下载量或 star 数。`.github/workflows/plugin-market.yml` 在正式发布或手动指定已发布标签时部署 GitHub Pages;不自动发布 npm。
29
+
30
+ 格式与操作依据:[DSH 官方插件索引说明](https://github.com/deepseek-ai/deepseek-harness/blob/master/docs/user/guide/plugin-market.zh.md)。
@@ -0,0 +1,127 @@
1
+ # Redaction contract: what may cross a public surface
2
+
3
+ The rule this module enforces is narrow and checkable:
4
+
5
+ > A stored secret value never leaves the module that read it. A public surface
6
+ > carries a mask at most, and a model usage count is published only when it is a
7
+ > plain finite non-negative number under a known counter name.
8
+
9
+ `src/config/redact.js` is the only component that decides this. Configuration
10
+ surfaces, job history, MCP results, review findings, audit diagnostics and logs
11
+ all funnel through it.
12
+
13
+ ---
14
+
15
+ ## 1. The secret-key rule
16
+
17
+ `isSecretKey(key)` returns true when the key matches:
18
+
19
+ ```
20
+ /(api[_-]?key|apikey|secret|token|password|passwd|credential[_-]?value|authorization)/i
21
+ ```
22
+
23
+ This is a substring test, on purpose: `RELAY_API_KEY`, `access_token`,
24
+ `dbPassword` and `client_secret` are all caught without enumerating them. It also
25
+ means the rule is coarse — it cannot tell a credential from a count that merely
26
+ spells the same word.
27
+
28
+ `redactDeep` therefore masks the value behind such a key, with one exemption
29
+ described next.
30
+
31
+ ## 2. The usage-counter exemption (the narrow fix)
32
+
33
+ Model token counts are named `inputTokens`, `totalTokens`, `reasoningTokens`, …
34
+ Every one of those names contains `token`, so before this contract they were all
35
+ masked and a job record reported nothing about what the run consumed. The
36
+ exemption restores exactly that, and nothing more.
37
+
38
+ `isUsageCounter(key, value)` is true when **both** hold:
39
+
40
+ 1. `key` is one of these exact names:
41
+
42
+ ```
43
+ inputTokens input_tokens
44
+ outputTokens output_tokens
45
+ totalTokens total_tokens
46
+ reasoningTokens reasoning_tokens
47
+ cacheTokens cache_tokens
48
+ cacheReadTokens cache_read_tokens
49
+ cacheWriteTokens cache_write_tokens
50
+ ```
51
+
52
+ (`TokenUsage` in `@deepseek-ai/dsh-llm` uses the camel forms; the snake forms
53
+ cover OpenAI-compatible wire payloads. Both spellings are listed for the same
54
+ seven counters.)
55
+
56
+ 2. `value` is `typeof 'number'`, `Number.isFinite(value)` and `value >= 0`.
57
+
58
+ ### Why this is an allow-list and not a `*Tokens` suffix rule
59
+
60
+ A suffix rule would exempt `refreshTokens`, `approvalTokens` and every credential
61
+ field that will ever end in those letters — a permanent hole for the sake of one
62
+ counter family. The allow-list keeps the hole to the names actually read from a
63
+ model response, and leaves every future unknown name masked by default. That is
64
+ the safe direction for a mistake to point.
65
+
66
+ ### Why the value type matters
67
+
68
+ A counter name proves nothing about the value. `inputTokens: 'sk-abc…'` is a
69
+ credential that happens to sit under a counter name, and
70
+ `inputTokens: { raw: 'sk-abc…' }` is a nested object holding one. Neither is a
71
+ count, so neither is exempt:
72
+
73
+ | value | result |
74
+ | --- | --- |
75
+ | `12`, `0`, `1.5` | published as the number |
76
+ | `-1`, `NaN`, `Infinity` | masked — not a count |
77
+ | `'12'`, `'sk-abc…'` | masked — a string is never a count |
78
+ | `{ raw: 12 }`, `[1, 2]`, `true` | masked |
79
+ | `null` / `undefined` / `''` | passed through as `null` (no value to hide) |
80
+
81
+ The empty/null case is the existing rule for all secret keys, not a new
82
+ exception: an absent credential is not a credential.
83
+
84
+ ## 3. Free text
85
+
86
+ `redactText` is the safety net for values the plugin never intended to see. It
87
+ runs over every string `redactDeep` visits, including strings inside a preserved
88
+ structure:
89
+
90
+ | pattern | replaced with |
91
+ | --- | --- |
92
+ | `Bearer <12+ token chars>` | `Bearer ••••••••` |
93
+ | `sk-…` / `pk-…` / `ak-…` (16+ chars) | `••••••••` |
94
+ | `SOMETHING_TOKEN=value` | `SOMETHING_TOKEN=••••••••` |
95
+
96
+ A preserved usage counter is a number, so it never carries text. A counter-shaped
97
+ key whose value is a string still goes through `redactText` and then is masked
98
+ whole — a credential-shaped string under `total_tokens` is masked, not published.
99
+
100
+ ## 4. `maskSecret` never leaks shape
101
+
102
+ `maskSecret` returns the fixed `MASK` (`••••••••`) for any non-empty string, and
103
+ `''` for empty input. It does not keep a prefix, a suffix or the length, because a
104
+ partial mask is a partial credential.
105
+
106
+ ## 5. What is *not* redacted
107
+
108
+ - Numbers and booleans under names that are not secret keys.
109
+ - `credentialRef` — a reference is a name, not a value; it is expected in public
110
+ settings.
111
+ - The mask itself, which is not a secret.
112
+
113
+ Structural fields are preserved so a host can still act on them: `code`, `phase`,
114
+ `outcome`, `agentId`, `sessionId` and the job's `usage` counters. Nothing in the
115
+ exemption path widens what a caller can learn about a credential.
116
+
117
+ ## 6. Keeping this honest
118
+
119
+ `tests/redact.test.js` covers the reported bug, each known counter spelling, the
120
+ suffix-rule regression (`refreshTokens` and friends must stay masked), every
121
+ invalid-value shape, numeric secret token values, unknown token names, and
122
+ credential-shaped strings under a counter name. `tests/config.test.js` covers the
123
+ public-settings projection end to end.
124
+
125
+ Adding a counter means adding it to `USAGE_COUNTER_KEYS` *and* to the test table.
126
+ Adding a name there widens the one exemption in this module, so it deserves the
127
+ review that any other relaxation of a secret rule would get.