dsh-taskbridge 0.0.0-stage → 1.3.2

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 (75) hide show
  1. package/CHANGELOG.md +763 -0
  2. package/LICENSE +21 -0
  3. package/README.md +622 -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-taskbridge.toml +247 -0
  10. package/cordis.patch.yml +6 -0
  11. package/docs/INTRODUCTION.md +15 -0
  12. package/docs/INTRODUCTION.zh.md +34 -0
  13. package/docs/auth-contract.md +138 -0
  14. package/docs/claude-code.md +31 -0
  15. package/docs/codex-integration.md +937 -0
  16. package/docs/contracts-stage-b.md +443 -0
  17. package/docs/conversation-placement.md +304 -0
  18. package/docs/plugin-market.md +30 -0
  19. package/docs/redaction-contract.md +127 -0
  20. package/docs/runtime-compatibility.md +223 -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 +138 -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 +3299 -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 +456 -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 +3614 -0
  53. package/src/jobs/history.js +1467 -0
  54. package/src/jobs/title.js +17 -0
  55. package/src/mcp/server.js +1821 -0
  56. package/src/mcp/wait.js +536 -0
  57. package/src/model/connectivity.js +371 -0
  58. package/src/model/discovery.js +582 -0
  59. package/src/model/native-catalog.js +68 -0
  60. package/src/model/openai-adapter.js +671 -0
  61. package/src/model/probe.js +264 -0
  62. package/src/model/providers.js +756 -0
  63. package/src/model/routing.js +321 -0
  64. package/src/review/preset.js +868 -0
  65. package/src/review/prompts.js +126 -0
  66. package/src/review/reviewer.js +933 -0
  67. package/src/runtime/agent-runner.js +1740 -0
  68. package/src/runtime/endpoint-discovery.js +118 -0
  69. package/src/runtime/permissions.js +1429 -0
  70. package/src/runtime/sandbox.js +358 -0
  71. package/src/runtime/session-placement.js +1121 -0
  72. package/src/workspace/audit.js +775 -0
  73. package/src/workspace/locks.js +167 -0
  74. package/src/workspace/preflight.js +424 -0
  75. package/src/workspace/worktrees.js +613 -0
@@ -0,0 +1,304 @@
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
+ ## Workspace display names (1.3.2)
23
+
24
+ `delegate_submit.title` is an optional, short description of the actual work in
25
+ the operator's language. The engine derives a title from the prompt's goal when
26
+ older callers omit it. Only newly created Workspace groups are renamed through
27
+ `workspaceController.rename({ workspaceId, title })`; an existing Workspace or
28
+ an explicit follow-up retains its current name. Conflicting names receive a short
29
+ task-id suffix. Naming needs no model call and does not change the execution
30
+ directory, Git branch or task identity. Historical Workspaces are not renamed in
31
+ bulk.
32
+
33
+ ## The two questions, and the two services that answer them
34
+
35
+ | Question | Native service | Dependency key |
36
+ | --- | --- | --- |
37
+ | Which Workspace group? | `ctx.workspaceController` | `deps.workspaces` |
38
+ | Which Session, and its Agent? | `ctx.sessionController` | `deps.sessionController` |
39
+
40
+ `ctx.sessions` is the native **persistence** service (`flush`). It cannot create
41
+ or resolve a Session, so `deps.sessions` is never used for placement. Reading it
42
+ there was a real defect: it reported a fully composed harness as having no
43
+ session controller, and every worker run failed with
44
+ `SESSION_CONTROLLER_UNAVAILABLE`. The wiring is asserted directly in
45
+ `tests/session-placement.test.js` ("placement reads the session CONTROLLER,
46
+ never the native sessions service").
47
+
48
+ ## Verified native signatures
49
+
50
+ Read from the installed runtime declarations, not guessed:
51
+
52
+ - `WorkspaceController.create(request: { path }): Promise<{ workspace:
53
+ WorkspaceView, created: boolean }>` — create-or-reuse over an existing
54
+ directory; `WorkspaceView` carries `workspaceId` and the canonical `path`.
55
+ - `SessionController.create(request: { workspaceId?, cwd?, sessionId?,
56
+ agentPreset? }): Promise<{ sessionId, agentPreset? }>`.
57
+ - `SessionController.resolveAgent(sessionId): Promise<{ agent } | { error }>`,
58
+ where the error is a `RemoteError` of `session/not-found`,
59
+ `session/agent-busy`, `session/writer-held` or `gateway/internal`.
60
+ - `Agent` carries `id`, `session`, a live `ctx: Context` (`ctx.on(...)`), plus
61
+ `followup`, `cancel`, `whenIdle`.
62
+
63
+ ## Flow
64
+
65
+ 1. **Capability checks first.** A missing controller is a stated refusal
66
+ (`SESSION_WORKSPACES_UNAVAILABLE` / `SESSION_CONTROLLER_UNAVAILABLE`), never a
67
+ fallback to an ungrouped session.
68
+ 2. **Workspace.** `workspaceController.create({ path })` with the run's *actual*
69
+ execution directory (`task.executionPath` — the worktree when isolation
70
+ prepared one, the source checkout otherwise). Repeating a run in one directory
71
+ reuses one group instead of accumulating duplicates.
72
+ 3. **Session.**
73
+ - `continueFromTaskId` **omitted** — `sessionController.create({ workspaceId })`
74
+ creates a fresh Session, then `resolveAgent` attaches its Agent. Nothing is
75
+ read from the identity map, so a directory with a long history still gets a
76
+ new conversation.
77
+ - `continueFromTaskId` **supplied** — that task's recorded identity is loaded
78
+ and every fact a continuation depends on is re-checked (below), including the
79
+ connection that submitted it (from the live record, or from the durable job
80
+ history after a restart), then `resolveAgent` returns the live Agent of the
81
+ *same* Session, so the next turn lands in the same native session log. A
82
+ parent whose ownership cannot be proven is refused before this step.
83
+ 4. **Drive.** Both paths return a resolved `agent`, and the runner drives it.
84
+ `agents.create` is not used for a placed run: the Session already exists, so
85
+ creating an Agent that way would create a *second* Session beside the placed
86
+ one. The runner installs this run's provider/model/effort on the resolved
87
+ Agent's own context, so a per-task selection still governs a continued
88
+ conversation.
89
+ 5. **Cancellation before placement.** An already-aborted signal returns
90
+ `cancelled` before any Workspace or Session is created, so a run that never
91
+ starts cannot leave an orphan group or an empty conversation.
92
+
93
+ ## Validating a continuation (fail-closed)
94
+
95
+ Every check below refuses. None of them falls back to creating a new Session,
96
+ because that would report a continued conversation the operator is not in.
97
+
98
+ Two vocabularies, in this order:
99
+
100
+ - **Ownership.** While it cannot be proven that this caller submitted the parent,
101
+ every answer is the same `JOB_TASK_NOT_FOUND`, with no cause and no thread hint:
102
+ an unknown id, a pruned or truncated record, a record with no owner, a caller
103
+ with no verified identity, no durable history at all, and another connection's
104
+ task are deliberately indistinguishable, so the answer cannot enumerate tasks.
105
+ - **Joinability.** Only a caller that has proven the same owner ever learns *why*
106
+ a chain cannot be joined: `JOB_CONTINUATION_REFUSED` at the job boundary, with
107
+ the specific `SESSION_*` code in `error.details.session`.
108
+
109
+ ## Who owns a task thread (survives a restart)
110
+
111
+ **Strictly the connection that submitted it.** Ownership is compared as two
112
+ identity strings, never as a pattern: the `local-mcp` identity of the local
113
+ switch is a real, fixed identity and is matched exactly like an external
114
+ connection, and "no identity" is never a wildcard in either direction.
115
+
116
+ Two authorities answer this, depending on where the parent came from:
117
+
118
+ | Parent | Authority for ownership | Authority for outcome |
119
+ | --- | --- | --- |
120
+ | Admitted by this process | the live task record's `connectionId`, verified when it was admitted | the live record's state, plus its recorded conversation |
121
+ | Recovered from `sessions.json` after a restart | the durable job history (`history.json`) `connectionId` | the durable record's `state` and its `execution.conversation` block |
122
+
123
+ `sessions.json` is deliberately **not** an authority for either. It records
124
+ where a thread lives — task id, paths, Workspace/Session ids, isolation and tree
125
+ facts — and nothing about who asked for the work or how the run ended. That is
126
+ why resuming from it alone was a defect: after a restart the in-memory check
127
+ disappeared and the map would have answered "yes" to any caller that knew the
128
+ task id. The durable job history is the second authority; the two are checked in
129
+ sequence, and both must agree with the caller.
130
+
131
+ Both checks run **before** placement, and admission runs them **before settings
132
+ are read and before a concurrency slot is claimed**, so a refusal never resolves
133
+ or drives a native Session: the conversation of a task that is not yours is never
134
+ touched. The engine's authority is `JobEngine.assertContinuation`, which decides
135
+ ownership and joinability in one pass; `JobEngine.assertAdmissible` is the same
136
+ rule applied synchronously to a live record, and placement calls it as a re-check
137
+ of a chain admission already proved — including the exact execution directory, so
138
+ placement never resumes a thread whose Workspace id merely looks familiar.
139
+
140
+ ## The admission gate, in order
141
+
142
+ A `continueFromTaskId` submission is decided by one pass in `admit()`, before
143
+ step 3 (settings) and before step 4 (effective config and the concurrency slot):
144
+
145
+ 1. **Ownership first, with one refusal.** The caller must present a verified
146
+ connection id, and it must equal the parent's owner exactly. A live parent
147
+ record states its own `connectionId`; a parent this process no longer holds is
148
+ proven by the **durable job history** row's `connectionId`. No verified caller,
149
+ no history store, an unreadable or malformed history document, no record for
150
+ the id, a truncated record and a record with no owner all answer the same
151
+ `JOB_TASK_NOT_FOUND`.
152
+ 2. **One snapshot, one shape.** History is read **exactly once** and reduced to
153
+ `{ state, sourcePath, executionWorkspacePath, isolation, conversation }`, with
154
+ `conversation` taken from `row.execution.conversation`; a live parent supplies
155
+ the same shape from its own record. There is no second read of history and no
156
+ "the row was null, so skip the checks" branch — a failed read is a refusal,
157
+ never a pass.
158
+ 3. **The identity map** (`sessions.json`) is read exactly once and judged together
159
+ with that snapshot. Its Workspace id, execution dir, source repository and
160
+ isolation must agree with the snapshot; a missing row or an empty Session id is
161
+ refused.
162
+ 4. **The verified result is what steps 4 and 7 read.** Only after every check
163
+ passed is the identity recorded on the task, which is what makes the effective
164
+ isolation the parent's and what makes a worktree parent reuse the original tree
165
+ instead of preparing a new one.
166
+
167
+ | Check | Refusal |
168
+ | --- | --- |
169
+ | Parent task id is unknown, pruned, or was never recorded here | `JOB_TASK_NOT_FOUND` |
170
+ | Parent was submitted by another connection — in this process or, after a restart, according to the durable history | `JOB_TASK_NOT_FOUND` |
171
+ | 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` |
172
+ | 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` |
173
+ | 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` |
174
+ | 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` |
175
+ | Snapshot or identity execution path is missing, empty or masked; the snapshot names no recognized isolation | `JOB_CONTINUATION_REFUSED` + `SESSION_CONTINUATION_UNAVAILABLE` |
176
+ | 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) |
177
+ | 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` |
178
+ | The build cannot resolve a Session at all | `JOB_CONTINUATION_REFUSED` + `SESSION_RESUME_UNAVAILABLE` |
179
+ | The Session no longer exists | `JOB_CONTINUATION_REFUSED` + `SESSION_RESUME_FAILED` with `cause: session/not-found` |
180
+ | The resolved Agent's own `cwd` header names another directory | `JOB_CONTINUATION_REFUSED` + `SESSION_RESUME_PATH_MISMATCH` |
181
+
182
+ Because the whole gate runs before the slot is claimed, a refusal is stable: a
183
+ parent that is still running is refused for its own state, never masked by
184
+ `JOB_CONCURRENCY_LIMIT`, and a parent's isolation mode is known before any mode is
185
+ resolved.
186
+
187
+ **A new grant is not a new owner.** Authorization tokens do not survive a
188
+ restart, so a returning client obtains a fresh grant; that grant authorizes the
189
+ *connection*, which is the same identity, so the follow-up is admitted. A
190
+ different connection holding its own perfectly valid grant is refused — a valid
191
+ authorization is never an authorization to join somebody else's chain. A
192
+ connection id that DSH re-issues after a restart is a **new** identity, so a
193
+ re-issued id is refused; there is no label or fuzzy matching anywhere in this
194
+ path.
195
+
196
+ **Fail closed, always.** Missing history, an unreadable or malformed history
197
+ document, a truncated record, a record with no owner, a pruned record, an
198
+ `interrupted` run (the job was live when a previous process stopped), a failed or
199
+ cancelled run that never drove a conversation, and a record naming another
200
+ repository are all refusals. None of them falls back to "the map says the thread
201
+ is there, so it must be yours".
202
+
203
+ **Masked paths are a refusal, never a wildcard.** The documents are projected
204
+ through redaction, which rewrites an account-identifying directory segment
205
+ (`masks-user-profile-segment`). A path carrying that segment cannot prove which
206
+ directory it names, so it is treated exactly like a missing path: it never equals
207
+ anything, it is never a pattern that matches a live path, and the continuation is
208
+ refused. Nothing in this path treats a mask as equality, and that holds for both
209
+ documents and for the live re-check.
210
+
211
+ **Equal Workspace ids are not proof of equal placement.** A recorded conversation
212
+ must name a real Workspace *and* a directory this run resolved, and a live parent
213
+ must have executed in this run's directory. A row that keeps the parent's
214
+ Workspace id while pointing the conversation at another directory is refused, and
215
+ so is a parent whose execution dir differs from the one this run resolved.
216
+
217
+ **Task locking.** A continuation chain is serialized by the existing workspace
218
+ locks rather than by a second mechanism: the parent holds the lease on its
219
+ execution path (and on its source path) for the whole run, so a follow-up that
220
+ targets the same path is refused with `JOB_WORKSPACE_BUSY` until the parent has
221
+ finished. A continuation can therefore never drive a thread mid-turn, and two
222
+ follow-ups of one chain cannot run at once.
223
+
224
+ ## Preserving workspace state for a follow-up
225
+
226
+ The execution path is part of the continuation:
227
+
228
+ - a **shared** parent continues in that same source checkout;
229
+ - a **plugin-managed worktree** parent continues in that same tree. The tree is
230
+ where the parent's uncommitted changes are, so a fresh tree would silently hide
231
+ them. The caller continues to authorize the source repository in `workspacePath`;
232
+ the engine restores the parent task's isolation and resolves the exact managed
233
+ tree from its recorded identity. It never asks the caller to authorize an
234
+ internal worktree path or substitutes a fresh tree. A tree that is gone,
235
+ disposed, unregistered, mismatched, or not a real directory is refused with
236
+ `SESSION_CONTINUATION_UNAVAILABLE`. A source checkout becoming dirty after the
237
+ parent run does not redirect the continuation: the follow-up still targets the
238
+ original isolated tree and captures a fresh baseline there.
239
+
240
+ Isolation belongs to the task chain. A follow-up uses the parent's recorded
241
+ `shared` or `worktree` isolation even if global or project settings changed after
242
+ the parent ran. A caller override that explicitly conflicts with that isolation is
243
+ refused. For a shared parent, the same source path is locked and audited again; for
244
+ a worktree parent, both the source and original tree are locked for the follow-up.
245
+
246
+ ## Settings: what was removed, and what remains
247
+
248
+ `conversation.mode` is **retired**. It is still accepted on read so an existing
249
+ document keeps loading, and it is inert: no code path consults it, so a stored
250
+ `"reuse"` cannot cause an implicit reuse. The settings page no longer offers the
251
+ control, `setConversation` refuses with `CONVERSATION_MODE_REMOVED` rather than
252
+ silently accepting a value with no effect, and the effective snapshot carries
253
+ `conversation.policy: "per-task"` — the rule, not a stored choice.
254
+
255
+ ## What is stored
256
+
257
+ `sessions.json` beside the settings document, **one row per task**:
258
+
259
+ ```json
260
+ {
261
+ "taskId": "task-…",
262
+ "sourcePath": "E:\\work\\repo",
263
+ "executionPath": "E:\\dsh\\data\\dsh-delegate\\worktrees\\task-…",
264
+ "workspaceId": "…",
265
+ "sessionId": "session-…",
266
+ "isolation": "worktree",
267
+ "worktreeId": "task-…",
268
+ "worktreeState": "awaiting-host-review",
269
+ "updatedAt": 1767225600000
270
+ }
271
+ ```
272
+
273
+ No prompt, transcript, output, credential or token count. The native session log
274
+ stays the sole owner of conversation content.
275
+
276
+ **Migration.** Rows written by the previous build were keyed by canonical
277
+ execution directory and carried no task id (`{ path, workspaceId, sessionId,
278
+ updatedAt }`). They cannot name a task thread, so they are ignored on read: there
279
+ is nothing to continue and nothing that could act as an implicit source of reuse.
280
+ The document is rewritten as schema 2 on the next save.
281
+
282
+ **After a plugin restart** a continuation still works when all of the following
283
+ hold: the identity map and the native Session both exist, the durable job
284
+ history still has a record for the parent, that record names the SAME connection
285
+ and a terminal state that has a conversation, and its recorded repository agrees
286
+ with this submission. When any of these fails the answer is an explicit
287
+ `JOB_TASK_NOT_FOUND` (ownership) or `SESSION_CONTINUATION_UNKNOWN` /
288
+ `SESSION_CONTINUATION_STATE` / `SESSION_CONTINUATION_UNAVAILABLE` /
289
+ `SESSION_RESUME_FAILED` (everything else) — never a different or a new session,
290
+ and never the parent's Session. A connection identity that DSH re-issues under a
291
+ new id after the restart is a different identity and is refused; there is no
292
+ label or fuzzy matching anywhere in this path.
293
+
294
+ ## Ownership and disposal
295
+
296
+ A resolved Agent belongs to its Session, so the runner never disposes one:
297
+ disposal would end the conversation and make a later `continueFromTaskId`
298
+ follow-up unable to resolve it. Only the unplaced path (`allowUnplaced`, used by
299
+ the additional review) creates an Agent through `agents.create`, and only that
300
+ Agent is disposed.
301
+
302
+ The review sets `allowUnplaced: true` deliberately: it must not join the
303
+ operator's Workspace history, it is not part of the worker thread, and it is not
304
+ 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.2`,无需添加索引;若中国大陆镜像未同步,改选 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.