dsh-taskbridge 1.8.1 → 1.9.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 (40) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +139 -121
  3. package/antigravity/agents/dsh-taskbridge.md +14 -12
  4. package/antigravity/skills/dsh-taskbridge/SKILL.md +32 -19
  5. package/bin/dsh-delegate-codex-agent.js +9 -4
  6. package/codex/skills/dsh-taskbridge/SKILL.md +131 -0
  7. package/codex/skills/dsh-taskbridge/rules-reference-96027c387cb9b7587efa4aa3836235d86db1108068e007dc08196e807ca25e5d.md +114 -0
  8. package/docs/INTRODUCTION.md +94 -68
  9. package/docs/INTRODUCTION.zh.md +94 -77
  10. package/docs/antigravity-integration.md +6 -1
  11. package/docs/assets/taskbridge-workflow.en.svg +72 -0
  12. package/docs/assets/taskbridge-workflow.zh.png +0 -0
  13. package/docs/claude-code.md +5 -5
  14. package/docs/codex-integration.md +1102 -1076
  15. package/docs/releases/1.9.0.zh.md +31 -0
  16. package/docs/releases/1.9.1.zh.md +14 -0
  17. package/docs/runtime-compatibility.md +7 -9
  18. package/docs/silent-wait.md +17 -26
  19. package/docs/taskbridge-upgrade.md +4 -4
  20. package/lib/client.d.ts +2 -2
  21. package/lib/client.js +7 -7
  22. package/locale/en.json +1 -1
  23. package/locale/zh.json +1 -1
  24. package/package.json +157 -150
  25. package/src/antigravity/installer.js +33 -2
  26. package/src/client/api.js +139 -17
  27. package/src/client/index.jsx +20 -19
  28. package/src/codex/agent-ownership.js +72 -12
  29. package/src/codex/installer.js +4613 -4190
  30. package/src/http/execution-plane.js +17 -0
  31. package/src/http/user-plane.js +6 -0
  32. package/src/index.d.ts +9 -1
  33. package/src/index.js +86 -64
  34. package/src/jobs/engine.js +278 -5
  35. package/src/jobs/history.js +17 -1
  36. package/src/jobs/record-cleanup.js +76 -2
  37. package/src/mcp/server.js +241 -12
  38. package/src/runtime/permissions.js +18 -0
  39. package/src/runtime/worker-prompt.js +13 -9
  40. package/codex/dsh-taskbridge.toml +0 -181
@@ -1,1076 +1,1102 @@
1
- # Codex integration contract
2
-
3
- Status: implemented in 1.8.1 (Codex and Antigravity integrations both supported, with full 1.8.0 and earlier upgrade recognition). This automatic installer covers Codex; Antigravity integration is documented in `docs/antigravity-integration.md`, and Claude Code / Claude Desktop integration is planned for 2.0.
4
-
5
- The 1.7.0 release also makes future managed upgrades self-recognising: the two exact
6
- companions this machine really held (`1.6.1` in both terminator spellings and the local
7
- `1.6.1-test.5` prerelease) are now enumerated, and an explicit install or the startup refresh
8
- records the LF-normalized digest of the template it wrote, in one small file per real Codex
9
- home. A LATER release therefore recognises the template the previous one wrote without
10
- appending another digest by hand, while an edited file — one changed character, or only the
11
- `version` line — still stays the operator's and is never rewritten. See section 5.
12
-
13
- 1.5.1 refreshes the manifest on each activation, resolves a normal linked home root, and upgrades exact shipped/candidate templates while preserving custom content. See [1.5.1 notes](https://github.com/ranranyya/dsh-taskbridge/blob/master/docs/releases/1.5.1.zh.md).
14
-
15
- 1.5.0 adds `delegate_question_answer`, combined decision/answer-and-wait flows and program metrics. Managed upgrades recognize the exact published 1.4.2 and verified local test.1/test.2 companions; customized files remain operator-owned. See the [1.5.0 release notes](https://github.com/ranranyya/dsh-taskbridge/blob/master/docs/releases/1.5.0.zh.md).
16
-
17
- 1.4.2 also recognizes the exact published 1.4.1 companion for managed upgrades.
18
- The review behavior introduced in 1.4.1 recognizes the exact unmodified
19
- 1.4.0 companion in LF and CRLF forms, and updates the review contract: a completed
20
- task may be read and reviewed by its original identity after a restart. History
21
- does not restore execution or old permissions. Reviews are confirmed only when
22
- `reviewPersistence.durable` is true (`state: "saved"`); `saving` or `timed-out`
23
- means the write is still unconfirmed, and `failed` permits a retry. Ordinary waits
24
- omit review prose. A result that reports `noteOmitted: true` can be read with
25
- `delegate_result` plus `reviewNoteOffset` and optional `reviewNoteLimit` (1–2000
26
- Unicode code points per page, default 2000); follow `nextOffset` until `complete`.
27
- Review notes accept up to 8000 code points after trimming and are stored redacted.
28
- See the [release notes](https://github.com/ranranyya/dsh-taskbridge/blob/master/docs/releases/1.4.1.zh.md) for validation boundaries.
29
-
30
- This document is the contract between the plugin's settings page (browser half),
31
- the host-side installer (`src/codex/installer.js`) and the two files it manages.
32
- It is written so a reviewer can check the code against it without reading the
33
- README.
34
-
35
- ## TaskBridge companion migration (1.3.2)
36
-
37
- The public companion is now `dsh-taskbridge`, installed as
38
- `agents/dsh-taskbridge.toml`. An explicit install or the startup refresh migrates
39
- an unchanged, recognized published `agents/dsh-delegate.toml` and removes the old
40
- managed file after the new managed template is present. Edited files and an
41
- operator-owned destination remain untouched; startup does not perform a first
42
- installation when no previous managed companion exists. The MCP table remains
43
- `mcp_servers.dsh-delegate`, and `delegate_*` tool names remain compatible.
44
-
45
- 1.4.0 recognizes the exact published 1.3.2 companion and refreshes its waiting rules
46
- on plugin startup. After examining a delivered result, the companion records its own
47
- accepted or changes-requested conclusion with `delegate_review`; the plugin never
48
- derives acceptance from completion. A client may need reloading to see the refreshed
49
- agent and tool catalog. Edited companion files remain operator-owned.
50
-
51
- Explicit install/repair can also adopt a marked standard legacy MCP path after
52
- the old `dsh-delegate` or `dsh-taskdispatch` package has been uninstalled from the
53
- same `node_modules` as the current `dsh-taskbridge`. This narrow exception does
54
- not apply to custom wrappers, other directories, or automatic startup refresh.
55
- `repair` remains MCP-only. TaskBridge CLI aliases point at the existing bin files.
56
-
57
- ---
58
-
59
- ## Explicit task descriptions (1.5.4)
60
-
61
- `delegate_submit` and `POST /tasks` accept optional `goalDescription`; `delegate_review` and `POST /tasks/review` accept optional `completionSummary`. Both trim surrounding whitespace, preserve internal newlines, and allow at most 2000 Unicode code points before and after redaction. Missing or blank strings are absent; explicit null and other non-strings are refused. No value is inferred from prompts or earlier tasks.
62
-
63
- The goal is fixed at task creation. The completion summary exists only under `hostAcceptance.completionSummary`, is part of the review identity with decision and note, and becomes public only after the same review write is durable. A saved review cannot gain or change a summary. Compact waits return only its character count and an omission flag; full results contain the prose. History retains titles and explicit continuation references without inventing missing old data.
64
-
65
- ## 1. What is owned, and what is not
66
-
67
- | Path | Owner | The plugin may | The plugin may never |
68
- | --- | --- | --- | --- |
69
- | `$CODEX_HOME/agents/dsh-taskbridge.toml` | managed copy of `codex/dsh-taskbridge.toml` | create it **exclusively** on explicit install when absent; refresh a byte-exact known build during plugin startup or explicit install; delete it on `remove` only after re-reading it and finding the same bytes it classified | overwrite or delete a file that is not that exact build — including a file with an old version line whose body was edited, and including a file that changed in the window between the status read and the write/removal |
70
- | `$CODEX_HOME/config.toml`, table `mcp_servers.dsh-delegate` | operator, with one managed entry | add the entry when absent; update `command`/`args`/its own `env.DSH_DELEGATE_DISCOVERY_FILE` when the entry carries **the plugin marker** *and* is the exact shape this plugin writes; on an explicit `install`/`repair` only, adopt a recorded `args[0]` that is a PROVED real installation of this package (manifest `name` + `bin["dsh-delegate-mcp"]` mapping) | touch any other key, table, comment or ordering; adopt, update or delete an unmarked same-name entry, even one whose values coincide; adopt a differing script path from the automatic startup check |
71
- | `$CODEX_HOME` and `$CODEX_HOME/agents` | Codex | resolve and pin a normal root symlink/junction to its real directory; inspect the real root and agents directory; create missing agents (`0700`) | retarget or delete the root alias; follow a link in the agents subdirectory or final file; write through an unusable or unverified target |
72
- | DSH local-call switch | operator | report it | change it |
73
-
74
- `$CODEX_HOME` resolution: `CODEX_HOME` when set and absolute; otherwise
75
- `~/.codex`. A relative override is refused (`CODEX_HOME_INVALID`), because
76
- resolving it against the harness's cwd would report on, and write to, a directory
77
- nobody named.
78
-
79
- ### 1.1 Link boundaries
80
-
81
- `lstat` on the final file is not enough: if `$CODEX_HOME/agents` is a junction,
82
- `mkdir -p` and the file create walk *through* it and write
83
- `agents/dsh-taskbridge.toml` outside the Codex home entirely. Since 1.5.1 the selected HOME root is first pinned to its real directory; that real root and the agents subdirectory are then inspected as boundaries:
84
-
85
- | `$CODEX_HOME` | `$CODEX_HOME/agents` | result |
86
- | --- | --- | --- |
87
- | real directory | missing | normal: install creates `agents` (`0700`) |
88
- | real directory | real directory | normal |
89
- | real directory | link (symlink or junction) | `agent.state = conflict`, `reason = agents-dir-is-link`; install/repair/remove all refuse with `AGENT_PATH_CONFLICT` |
90
- | root symlink/junction with a real directory target | checked under the pinned real target | normal root alias; alias preserved, agents/file links still refused |
91
- | could not be verified | — | `agent.state = conflict`, `reason = boundary-unverified`; same refusal |
92
-
93
- A **junction** is the case `lstat` cannot see: Windows reports it as an ordinary
94
- directory. On Windows the `ReparsePoint` file attribute is read through one
95
- `powershell.exe` child (`-NoProfile -NonInteractive`, hidden, 15 s bound), with the
96
- paths passed in an environment variable rather than interpolated into script text.
97
- The child answers one comma-separated verdict per path — `dir/<bool>`, `other/<bool>`
98
- or `missing` — and the boolean is PowerShell's `Boolean.ToString()` output, whose
99
- spelling is **not** stable (`True`/`False` on Windows PowerShell 5.1, `true`/`false`
100
- under other hosts/cultures). The verdict is therefore parsed case-insensitively
101
- (`parseDirectoryVerdict`), the script emits lower case via `ToLowerInvariant()`, and
102
- anything that is not a recognised `dir/`/`other/`/`missing` answer is treated as
103
- `other` (a path this plugin will not write under), never as a missing answer.
104
- A regular directory — `dir/false` in any spelling — is `directory`, so the ordinary
105
- Windows layout is unaffected; only `dir/true` / `other/true` are reported as a link.
106
- This is pinned by a real-directory probe test that runs the actual PowerShell child on
107
- a temporary directory on Windows (and skips elsewhere), not only through the test
108
- classifier hook.
109
-
110
- The status document reports this as `boundary: { blocked, link, unknown, home,
111
- agents }`. A **failed** verification is a refusal, not a pass: if the platform
112
- answer cannot be obtained (no spawnable shell, no PowerShell), the boundary is
113
- `unknown` and every action refuses, because "could not check" must never be read
114
- as "safe". The check is re-done at the start of every writing action from the
115
- freshly read status, so a link that replaced either directory after the operator
116
- last looked is still refused.
117
-
118
-
119
- ---
120
-
121
- ## 2. The MCP entry
122
-
123
- The owned shape, written as a marked block:
124
-
125
- ```toml
126
- # dsh-delegate: managed by the DSH Delegate plugin settings page
127
- [mcp_servers.dsh-delegate]
128
- command = "<a Node.js executable, resolved as described in 2.1>"
129
- args = ["<installed package>/bin/dsh-delegate-mcp.js"]
130
- tool_timeout_sec = 3660
131
- ```
132
-
133
- * `command` is an **absolute path to a Node.js executable**, never a bare `node` and
134
- never the desktop application. A GUI-launched Codex often has a narrower `PATH`
135
- than the shell that started DSH, so a bare `node` fails at spawn time; and in the
136
- DSH Desktop (Electron) host `process.execPath` is `DeepSeek Harness.exe`, which
137
- would make Codex launch a second GUI instead of an MCP server. Section 2.1 states
138
- how the executable is chosen and what happens when no candidate can be proved.
139
- * `args[0]` is derived from `import.meta.url` of the running module, so it names
140
- the *installed* package — never a repository checkout and never a path captured
141
- when the tarball was built.
142
- * `tool_timeout_sec = 3660` (1.1.0) is an **owned scalar on this entry only**. The
143
- `delegate_wait` tool defaults to a 3600-second wait and caps it there, so a client that
144
- honours this field is allowed to let one call run that long. The plugin cannot prove that
145
- every client honours it: a client that applies its own tool timeout may still end the
146
- wait earlier. That is an OUTER limit and is not a `wait-limit` answer. The managed entry
147
- therefore *requests* 3660 s — the 3600-second wait plus one minute of slack, never a
148
- second wait window — while a client-side cap that ignores the field remains a client
149
- limit the plugin cannot lift. This is not a Codex-wide setting and the plugin writes it
150
- nowhere else.
151
- * When a client exposes a yield/pragmas parameter, an ordinary wait should request
152
- roughly `1200000` ms (20 minutes), not one minute. A one-minute return is a caller
153
- choice, not a documented hard maximum, and not every client supports the same long
154
- yield — the agent is told to state what its client actually offers rather than
155
- describe one minute as inherent.
156
- * A managed entry written by an earlier release has no such field. It is classified
157
- `outdated` and repaired **in place** (the line is inserted inside our table), so an
158
- existing installation updates through the settings page instead of being reported as
159
- somebody else's file.
160
- * A managed entry with a different integer is likewise `outdated` and rewritten to
161
- 3660. A non-integer value is not a value this plugin writes, so the whole entry is
162
- treated as operator-owned and left untouched (`timeout-not-an-integer`).
163
- * An unmarked same-name entry stays a conflict regardless of its values: the marker
164
- comment is the only authorship proof this format carries.
165
- * `env.DSH_DELEGATE_DISCOVERY_FILE` is written only when DSH uses a non-default
166
- discovery location (`DSH_HOME` set, or `DSH_DELEGATE_DISCOVERY_FILE` set). The
167
- default stays implicit so a later `DSH_HOME` change is not silently overridden.
168
-
169
- ### 2.1 The `command` executable (`resolveNodeExecutable`)
170
-
171
- The host is classified first (`hostRuntimeKind`): `process.versions.electron` makes
172
- it an **electron** host; `process.resourcesPath` (set by Electron and by nothing in
173
- plain Node.js) is an equivalent desktop signal; otherwise it is a **node** host.
174
-
175
- | host | `process.execPath` | selected `command` |
176
- | --- | --- | --- |
177
- | plain Node.js | `node`/`node.exe` | that path, unchanged — it is the runtime that loaded this plugin |
178
- | plain Node.js, `execPath` is not a Node binary | an embedded host binary | falls through to the desktop rules below, never `execPath` |
179
- | DSH Desktop (Electron) | `DeepSeek Harness.exe` | the DSH **bundled runtime**, below |
180
-
181
- The bundled runtime is
182
- `<resources>/runtime/primary-runtime/dependencies/node/bin/node.exe` on Windows and
183
- `…/bin/node` elsewhere (`packagedNodePath`). `<resources>` is `process.resourcesPath`
184
- when the host exposes it; otherwise it is derived from the application executable as
185
- `<dirname(execPath)>/resources` — the layout DSH Desktop installs into
186
- (`…\DeepSeek Harness\resources\…` beside `…\DeepSeek Harness\DeepSeek Harness.exe`).
187
-
188
- If the bundled runtime is not there, these environment variables are consulted **in
189
- this order**, and the first usable one wins:
190
-
191
- | variable | accepted when |
192
- | --- | --- |
193
- | `DSH_NODE_PATH` | an absolute path |
194
- | `DSH_NODE_EXECUTABLE` | an absolute path |
195
- | `CODEX_MCP_NODE_PATH` | an absolute path |
196
-
197
- "Usable" is strict: the value must be **absolute**, its basename must be a Node
198
- binary (`node`, `node.exe`, or a versioned `node-*.exe`), and `lstat` must report an
199
- existing **regular file**. A relative path, a directory, a link and a missing file
200
- are each rejected with a reason, and their rejection does not stop the next
201
- candidate from being tried.
202
-
203
- **Fail closed.** When no candidate is usable, `resolveNodeExecutable` throws
204
- `CodexInstallError('MCP_EXECUTABLE_UNRESOLVED')`. The desktop application executable
205
- and a bare `node` are never substituted. The status document reports this instead of
206
- throwing: `mcp.node = null`, `mcp.nodeResolved = false`, `mcp.nodeError = { code,
207
- message, details }`, `mcp.state = unreadable` (`reason: no-executable`), `ready =
208
- false`, plus an `MCP_EXECUTABLE_UNRESOLVED` note. `install` and `repair` refuse the
209
- MCP target with `MCP_EXECUTABLE_UNRESOLVED` and leave `config.toml` byte-identical;
210
- the agent file is an independent target and is still installed.
211
-
212
- ### 2.1 Classification
213
-
214
- `classifyMcpEntry` locates the definition (block or inline), then decides:
215
-
216
- | state | meaning | install |
217
- | --- | --- | --- |
218
- | `not-configured` | no `mcp_servers.dsh-delegate` at all | writes the block |
219
- | `configured` | the marker is present **and** the values are exactly the owned shape | no change |
220
- | `outdated` | marked owned command, but stale `args`/discovery/`tool_timeout_sec`; or the narrowly recognised 0.1.6 Desktop command with the current package `args` and owned env shape | rewrites only those values in place |
221
- | `conflict` | anything else (`unmanaged-entry`, `unmanaged-entry-exact`, `command-not-ours`, `legacy-command-shape`, `url`, `unknown-field`, `extra-env`, `args-not-an-array`, `command-not-a-string`, `not-a-table`, `array-table`, and the boundary reasons below) | **refuses** with `MCP_ENTRY_CONFLICT` and a note explaining why; `repair` adds the marker for `unmanaged-entry-exact` only |
222
-
223
- Every classification also reports **`drift`**: the list of owned facts that are stale
224
- (`tool_timeout_sec`, `args`, `command`, `env`), or `null` when nothing is. The status
225
- document publishes it as `mcp.drift`, and the note for an `outdated` entry names each
226
- one, so neither the page nor a log line has to infer what a repair would change.
227
-
228
- An `args[0]` that names `dsh-delegate-mcp.js` somewhere ELSE is a `conflict`
229
- (`args-shape-not-ours`) in a bare status read: the synchronous classifier cannot prove that
230
- a different path is this package, so it never labels one `outdated`. Only an explicit
231
- `install`/`repair` may adopt it, after the asynchronous proof below — and only with the
232
- config digest, the `$CODEX_HOME`/`agents` boundary and the current entry re-checked
233
- immediately before the write. A different script name, a different command or an extra
234
- argument stays `conflict` everywhere.
235
-
236
- When `$CODEX_HOME` or `$CODEX_HOME/agents` is a link (or cannot be verified), the MCP
237
- target is reported as `conflict` with `reason` `codex-home-is-link`,
238
- `agents-dir-is-link` or `boundary-unverified` — the same verdict the agent target gets.
239
- The entry is **not** read through the link, because a link bounds every write this
240
- module makes, not only the agent file.
241
-
242
- Two rules are deliberate:
243
-
244
- * **`unmanaged-entry`.** Values alone never establish ownership. An entry without
245
- the marker comment — even one whose `command`/`args` are byte-identical to what
246
- the plugin would write — is the operator's. It is reported as a conflict, and
247
- `install`, `repair` and `remove` all leave it byte-identical. The marker must be
248
- the comment line directly above the definition (or above the `[mcp_servers]`
249
- header when the definition is the inline `dsh-delegate = { … }` spelling); a
250
- marker elsewhere in the file does not count.
251
- * **`unmanaged-entry-exact`.** The same unmarked definition, but it already IS this
252
- build's entry in every owned fact: `command` is the resolved Node executable, `args` is
253
- exactly this installation's entry script, `tool_timeout_sec` is the owned integer, and
254
- the `env` map is exactly the owned one (no additional key, none missing) — and the
255
- definition is ONE unambiguous standard `[mcp_servers.dsh-delegate]` table with unique
256
- keys. This is the configuration the settings page shows, entered by hand without the marker
257
- comment. It stays a `conflict` for `status`, plugin startup and `remove`, but the reason
258
- names it so that “仅修复 MCP 配置” (`repair`) may make ONE edit: insert the marker line
259
- directly above the server's OWN header and change no other byte.
260
- The write re-reads `config.toml`, requires the plan's digest, the boundary verdict, the
261
- whole owned shape and this installation's exact script to still hold, and splices the
262
- marker into the original text at the header line's character offset — so a BOM, mixed
263
- CRLF/LF endings, an indented header, an operator comment above it and a missing final
264
- newline all survive, and deleting the new line restores the file byte for byte. It then
265
- verifies the marker is adjacent to the server's own header (never to a shared
266
- `[mcp_servers]` parent, which would claim sibling entries), that the result classifies as
267
- `configured`, and that the change is exactly that one line.
268
- Refused, with the plain `unmanaged-entry` reason and a byte-identical file: any owned value
269
- that differs; a duplicated key (the parser keeps every entry, so a merge would let the last
270
- value win); an inline table beside or instead of the header; an extra or empty sub-table
271
- such as `[mcp_servers.dsh-delegate.custom]`; a nested inline table value; an array table.
272
- `install` never adds the marker.
273
- * **`command-not-ours`.** A different command is a different program, so even
274
- identical arguments do not make the entry ours. `extra-env` is symmetrical — an
275
- `env` key the plugin did not write is the operator's data, and an entry carrying
276
- one is reported as a conflict rather than pruned.
277
-
278
- * **0.1.6 Desktop migration.** Version 0.1.6 could write the DSH Desktop GUI as
279
- `command`. A marked entry is eligible for one automatic migration only when its
280
- command has a path whose case-insensitive basename is exactly `DeepSeek Harness.exe`,
281
- its `args` already name this installed package's `bin/dsh-delegate-mcp.js`, and its
282
- env keys and values exactly match the currently owned shape. The installer then
283
- reports `outdated` and replaces only the command with the proven Node runtime.
284
- A bare GUI name, a similarly named executable, stale args, extra env or any other
285
- command remains `conflict` and is left byte-identical.
286
-
287
- ### 2.2 Merge mechanics
288
-
289
- `src/codex/toml.js` locates structure by line and column ranges and edits only
290
- those ranges. It is a locator, not a validating TOML implementation, and it
291
- refuses (`TomlSyntaxError`, carrying a line number) rather than guess:
292
-
293
- * an unterminated single-line string, array or inline table;
294
- * a table header with trailing text;
295
- * a raw control character (0x00–0x08, 0x0A–0x1F except tab) **anywhere other than
296
- as a line ending** — see below;
297
- * text after a table header, an unbalanced bracket, a key without `=`.
298
-
299
- **CRLF.** A Codex config touched by a Windows editor is normally CRLF. The locator
300
- splits on `\n` only, treats a *terminal* `\r` as the second byte of a line ending
301
- (it is skipped wherever whitespace would end a token), and every mutation re-joins
302
- with the document's detected ending. Installing, updating and removing an entry in
303
- a CRLF file therefore preserves CRLF and leaves every unrelated byte — comments,
304
- settings, table order — exactly as it was. A `\r` **inside** a line (a broken or
305
- mixed-ending file) is still a control character and still refuses the document as
306
- a whole.
307
-
308
- A refusal makes the whole action refuse (`CODEX_CONFIG_UNSUPPORTED`) and leaves
309
- the file byte-identical. Nothing is ever written with a parsed-then-serialized
310
- round trip, so comments and ordering cannot be lost.
311
-
312
- Writes land through `writeFileAtomic` (temp file + rename), so a crash leaves the
313
- previous or the new full document, never a partial one. A *first* agent file is
314
- created with `link`, which fails when the target exists: a file that appears
315
- between the status read and the write is reported (`AGENT_PATH_CONFLICT`,
316
- `created-concurrently`) instead of being replaced.
317
-
318
- ### 2.3 Removal
319
-
320
- `remove` deletes the `mcp_servers.dsh-delegate` table (header, assignments, child
321
- tables and the plugin marker line) and the agent file when — and only when — that
322
- file is the managed template or a byte-exact known prior build. Comments the
323
- operator wrote *above* the marker stay; the marker itself is the plugin's line.
324
- A `conflict` or `modified` target is reported and left untouched, including an
325
- unmarked same-name entry. Removing twice is a no-op.
326
-
327
- **The agent file is re-proved immediately before it is unlinked.** The status read
328
- is stale by the time a removal runs: the operator, an editor or another tool may
329
- have rewritten the file after the verdict. Deleting on the strength of that verdict
330
- would destroy the new content, so `removeManagedAgentFile` reads the file again and
331
- requires all of:
332
-
333
- * it is still a **regular file** (not a link, not a directory) — otherwise
334
- `AGENT_PATH_CONFLICT` (`reason: not-a-regular-file`);
335
- * it still exists — otherwise `AGENT_PATH_CONFLICT`
336
- (`reason: missing-before-removal`), reported as "no change", never as a deletion;
337
- * its bytes are **exactly** the content the status derived its verdict from
338
- (`agent.expect`) — otherwise `AGENT_USER_MODIFIED`
339
- (`reason: modified-before-removal`) and the file is kept.
340
-
341
- Only then is `unlink` called. A file that *looks* managed but differs by one
342
- character is therefore refused, and an unlink the filesystem refuses (`EPERM`,
343
- `EACCES`, `EBUSY`) is reported as `AGENT_PATH_CONFLICT` (`reason: unlink-refused`)
344
- rather than thrown at the operator.
345
-
346
- ### 2.4 The startup upgrade of an installed integration (1.2.0)
347
-
348
- `refreshKnownAgentTemplate({ refreshMcp: true })` — reached through the seam as
349
- `refreshManagedIntegration({ startupTarget, backupDir })` and called once by plugin
350
- activation — performs two independent upgrades:
351
-
352
- | target | condition | write |
353
- | --- | --- | --- |
354
- | agent file | `outdated` (byte-exact published build) | replaced with this build's template |
355
- | MCP entry | `outdated` **and** passing the write gate below | the owned values rewritten in place, in ONE atomic write |
356
-
357
- The automatic check only ever accepts THIS installation's exact entry point. The
358
- moved-install case (a recorded `args[0]` that is a different, provable installation of the
359
- same package) is described below but is performed only by an explicit `install`/`repair`;
360
- startup leaves it byte-identical and reports `conflict`.
361
-
362
- #### The write gate (`isOwnedStaleEntry`)
363
-
364
- "The classifier said `outdated`" is not permission to write. An automatic, unreviewed
365
- write additionally requires that the entry is provably this plugin's in EVERY owned fact:
366
-
367
- | fact | required |
368
- | --- | --- |
369
- | marker comment | present (authorship proof) |
370
- | `command` | exactly this package's Node command (or the narrowed 0.1.6 Desktop command) |
371
- | `args` length | exactly 1 — no wrapper flags, no extra arguments |
372
- | `args[0]` | **provably** this package's entry point (see below) |
373
- | `env` keys | none that this plugin did not write |
374
-
375
- **`args[0]` must be PROVED, not pattern-matched** (`isOwnedEntryScript`, asynchronous
376
- because the proof is a filesystem one). There are exactly two accepted proofs:
377
-
378
- 1. **This installation's own file** — an absolute path that is the same location as this
379
- package's `bin/dsh-delegate-mcp.js`, compared under the PLATFORM's case rules
380
- (`samePlatformPath`). Linux compares exactly: two case variants are different programs
381
- there. Windows is case-insensitive; macOS is treated the same way because its default
382
- volumes are, which is an assumption rather than a promise on a case-sensitive volume. A
383
- RELATIVE path is never equivalent: `relative/bin/dsh-delegate-mcp.js` names no location.
384
- 2. **A different, real installation of this package** — an absolute path ending in
385
- `<root>/bin/dsh-delegate-mcp.js` with ALL of:
386
- * `<root>` and `<root>/bin` are real directories and not links (a junction is caught by
387
- the same attribute read the boundary check uses);
388
- * `<root>/bin/dsh-delegate-mcp.js` is a regular, non-link file that IS the candidate
389
- (compared by `realpath`, so a link cannot smuggle in another program);
390
- * `<root>/package.json` is a regular, non-link file that BOTH declares
391
- `"name": "dsh-delegate"` AND maps `bin["dsh-delegate-mcp"]` to that very entry. A
392
- `./` prefix is allowed; an absolute path, a `..` segment, a trailing slash, a wrong
393
- mapping, a missing mapping or no `bin` object is refused.
394
-
395
- The `<root>` is derived with the host's `dirname`/`basename` rules (`packageEntryRoot`), so
396
- a POSIX leading `/` is preserved: splitting on `/` and rejoining would turn
397
- `/opt/pkg/bin/dsh-delegate-mcp.js` into the relative `opt/pkg/...`, and no real Linux or
398
- macOS installation could ever be proved.
399
-
400
- Everything else — a wrapper that reuses the marker, the command or even the file name; a
401
- same-layout script whose manifest maps its bin elsewhere; a missing path; a link; a
402
- directory that declares another package — is **not** claimed. The synchronous classifier is
403
- even stricter: only proof 1 can make an entry `outdated`, so a differing script is always a
404
- `conflict` (`args-shape-not-ours`) and a bare status read can never authorize a write. Proof
405
- 2 is attempted **only by an explicit `install`/`repair`**, never by the unattended startup
406
- check, and it is re-run immediately before the write together with the plan's config digest
407
- and the boundary re-check; an edit in that window is refused (`config-changed`).
408
-
409
- An unprovable path is therefore KEPT and reported, with a note pointing at the explicit
410
- button: this is the intended outcome, not a gap. The core upgrade — an exact `args` match
411
- with only `tool_timeout_sec` missing — always succeeds automatically.
412
-
413
- #### No concurrent change (`config-changed`)
414
-
415
- The plan records a SHA-256 of the WHOLE `config.toml` (`mcp.fingerprint`, stripped from the
416
- public status by `publicCodexStatus`). Immediately before the write the file is re-read and
417
- the digest must match. Re-classifying alone is not enough: an operator can change an owned
418
- value and leave an entry that still looks stale and managed, which is exactly the overwrite
419
- this refuses. The result is `MCP_ENTRY_CONFLICT` with `reason: config-changed` and the file
420
- is kept byte-identical. This is covered by a deterministic test that changes the file
421
- between the plan and the write.
422
-
423
- #### The backup is a PRECONDITION (`MCP_ENTRY_BACKUP_UNAVAILABLE` / `_FAILED`)
424
-
425
- Before any automatic MCP write the current document is copied to a protected location, and
426
- that copy is **verified**. It is not best-effort:
427
-
428
- * no destination supplied → `MCP_ENTRY_BACKUP_UNAVAILABLE`, nothing written; a RELATIVE
429
- destination is refused as well, because it would be resolved against the harness cwd;
430
- * EVERY ancestor of the destination is proved to be a real directory — a symbolic link, a
431
- Windows junction/reparse point, a component the platform cannot verify, or a file in the
432
- chain refuses the whole backup, so a complete `config.toml` is never written through a
433
- linked parent (a leaf-only check is not enough: `/safe/backup` can be a plain directory
434
- below a junction);
435
- * missing levels are created ONE at a time and each is inspected immediately afterwards; a
436
- recursive `mkdir` would follow a link that appeared at any depth in the window;
437
- * the chain is re-checked immediately before the copy is written, then the copy is written
438
- atomically with owner-only permissions and RE-READ; a mismatch or a write failure →
439
- `MCP_ENTRY_BACKUP_FAILED`, nothing written;
440
- * an existing destination that is a link, a non-file, or holds different bytes is refused
441
- rather than overwritten.
442
-
443
- The seam supplies `<plugin dataDir>/codex-config-backup` by default, so a caller that passes
444
- no location still gets one; a direct `refreshMcp` call with no trusted location refuses
445
- instead of writing. The original file is always left exactly as it was on any refusal.
446
-
447
- #### The rest of the guarantees
448
-
449
- * an absent entry stays absent — the plugin never creates `config.toml` or the table at
450
- startup, so an upgrade can never turn a non-installation into an installation, and the
451
- same is true of `agents/` and the agent file;
452
- * an unmarked entry, an operator-edited shape and any `conflict` are refused and left
453
- byte-identical (the outcome carries `MCP_ENTRY_CONFLICT` with the reason);
454
- * a link or unverifiable directory at `$CODEX_HOME` / `agents` is re-inspected immediately
455
- before the write and produces ONE `AGENT_PATH_CONFLICT` refusal for the whole check, even
456
- when the visible state shows nothing stale: an upgrade that cannot be proved safe must not
457
- look successful;
458
- * the pre-write document is copied to `backupDir` (the plugin data directory) first — never
459
- into the package, never into the Codex home, and never returned in a response;
460
- * nothing else in `config.toml` is touched: comments, ordering, other MCP tables, CRLF
461
- line endings and every unrelated setting survive byte for byte.
462
-
463
- #### Which home is targeted — ONE precedence for every seam call
464
-
465
- `resolveHomePreference` is the single implementation, and `status()`, the explicit actions
466
- and the automatic check all use it. Before that, the check consulted the recorded directory
467
- while `status()` and the buttons consulted only `CODEX_HOME`/default, so removing
468
- `CODEX_HOME` made the page report — and the buttons write — a different tree than the one
469
- startup had just upgraded. The order is:
470
-
471
- | precedence | target |
472
- | --- | --- |
473
- | 1 | an explicit `CODEX_HOME` (or the seam's explicit `codexHome`) |
474
- | 2 | the home a SUCCESSFUL explicit install recorded in `<dataDir>/codex-installation.json` |
475
- | 3 | the default (`~/.codex`), only when it exists and is a real directory |
476
-
477
- A successful `install` records the directory even when it wrote nothing because the
478
- installation was already exactly right: `changed: []` is a success, not "nothing happened".
479
- A REFUSED install records nothing, so a refusal cannot become the remembered target.
480
-
481
- In 1.5.1 the selected home root is pinned by the installer to its real target after this precedence resolution. A normal root symlink/junction is supported; an unresolvable or unverifiable target is refused. A missing home remains `no-codex-home`; a null startup target does not silently fall back to another tree. The root alias is preserved, and links below it in agents or the final files remain forbidden.
482
-
483
- The explicit 安装 / 更新 TaskBridge 智能体 button (action `install`) is unchanged and remains
484
- the way to *create* the two managed targets. `status` reports the drift (`mcp.drift`)
485
- and, when an entry is `outdated`, a note naming exactly which owned facts are stale.
486
-
487
- ---
488
-
489
- ## 3. Actions and their guarantees
490
-
491
- Reachable only through the authenticated user plane (section 4) or the CLI
492
- `bin/dsh-delegate-codex-agent.js`.
493
-
494
- | action | writes | never writes |
495
- | --- | --- | --- |
496
- | `status` | nothing | anything |
497
- | `install` | agent file (absent / older managed build) + MCP entry (absent / `outdated`) | a user's agent file, a conflicting MCP entry, the DSH switch |
498
- | `repair` | the MCP entry only (absent / `outdated`), exactly as `install` would; plus the marker line for an `unmanaged-entry-exact` definition | the agent file: it is **not created, not refreshed and not deleted**, nor is `agents/` created; no owned value of an unmarked entry is ever rewritten |
499
- | `remove` | deletes only owned targets | a user's agent file, a conflicting entry |
500
-
501
- `install` is idempotent: a second run with nothing changed reports
502
- `changed: []` and does not rewrite either file.
503
-
504
- `install` reports the agent and MCP targets independently. One may succeed while
505
- the other is refused (for example: no agent file yet, but a conflicting entry), and
506
- the response says exactly which. The same holds for an unresolvable executable:
507
- the agent file is still installed, and the MCP half is refused with
508
- `MCP_EXECUTABLE_UNRESOLVED` (section 2.1).
509
-
510
- **`repair` is MCP-only.** It is the action behind the settings page's
511
- 「仅修复 MCP 配置」 button and is the same code path `install` uses for its MCP half.
512
- It never touches the agent file, so with a missing agent it reports
513
- `agent.state = not-installed` and changes nothing, with an `outdated` agent it leaves
514
- that file byte-identical (it stays `outdated`), and with a `modified`/`conflict` agent
515
- it does not even report an agent refusal — the agent is simply out of this action's
516
- scope. Concretely, `repair`:
517
-
518
- * returns `changed` containing `mcp` (or nothing) and never `agent`;
519
- * does not create `$CODEX_HOME/agents` when it is missing;
520
- * still refuses a `conflict` MCP entry with `MCP_ENTRY_CONFLICT`, exactly like `install`.
521
-
522
- Updating a stale agent is an explicit `install`, or the byte-exact startup refresh
523
- described below.
524
-
525
- **No action runs when the settings page opens, and package install writes nothing.**
526
- The page's `init()` issues a `GET`; the three buttons are the only callers of the
527
- `POST`.
528
-
529
- **The single write at plugin load is the integration refresh.** `apply()` calls the
530
- seam's `refreshManagedIntegration()` once — only when a Codex home directory exists — which
531
- refreshes `agents/dsh-taskbridge.toml` when its complete bytes equal one of the enumerated
532
- `KNOWN_AGENT_TEMPLATES` digests (section 5) **and** upgrades an already installed
533
- `mcp_servers.dsh-delegate` entry that is provably this plugin's and merely stale
534
- (section 2.4). Apart from migrating an existing recognized legacy companion to its new name in 1.3.2, it never creates a missing agent, never creates `agents/`, never creates
535
- the MCP entry, and never touches a `modified`/`conflict` file: everything else stays an
536
- explicit `install`. A refusal or failure is logged and startup continues, so a Codex
537
- problem cannot stop the plugin from loading.
538
-
539
- ---
540
-
541
- ## 4. Routes
542
-
543
- One exact path, two methods, registered on `ctx.connection.fetch` (the
544
- authenticated operator channel):
545
-
546
- | method | path | body | result |
547
- | --- | --- | --- | --- |
548
- | `GET` | `/api/dsh-delegate/codex` | — | `{ ok, action: 'status', changed: [], refused: [], codex, switch }` |
549
- | `POST` | `/api/dsh-delegate/codex` | `{ "action": "install" \| "repair" \| "remove" }` | `{ ok, action, changed, refused, codex, switch }` |
550
-
551
- Refusals use the standard envelope and these codes: `CODEX_ACTION_INVALID` (400),
552
- `CODEX_HOME_INVALID` (400), `CODEX_CONFIG_UNSUPPORTED` (409),
553
- `CODEX_CONFIG_UNREADABLE` (409), `CODEX_INTEGRATION_UNAVAILABLE` (503). A refusal
554
- *per target* is not an HTTP error: it appears in `refused[]` with a stable `code`
555
- (`AGENT_USER_MODIFIED`, `AGENT_PATH_CONFLICT`, `MCP_ENTRY_CONFLICT`,
556
- `MCP_SCRIPT_MISSING`, `CODEX_CONFIG_UNSUPPORTED`) and the action still answers 200
557
- with the fresh status, because "I did not touch your file, and here is why" is a
558
- successful diagnosis.
559
-
560
- `codex` (status document):
561
-
562
- ```jsonc
563
- {
564
- "codexHome": "…",
565
- "packageVersion": "1.8.1",
566
- "boundary": { "blocked": false, "link": null, "unknown": false, "home": "directory", "agents": "directory" },
567
- "agent": {
568
- "path": "…", "state": "installed", "installed": true, "managed": true,
569
- "reason": null, "expect": "<the exact bytes a refresh may replace>"
570
- },
571
- "mcp": {
572
- "path": "…", "exists": true, "serverName": "dsh-delegate",
573
- "state": "configured", "configured": true,
574
- "previous": { "command": "…", "args": ["…"], "envKeys": [] },
575
- "reason": null,
576
- "marked": true,
577
- "desired": { "command": "…", "args": ["…"], "env": {} },
578
- "node": "…", "nodeResolved": true, "nodeError": null,
579
- "script": "…", "scriptExists": true,
580
- "discoveryFile": "…", "discoveryPinned": false
581
- },
582
- "config": { "readable": true, "error": null },
583
- "ready": true,
584
- "notes": [{ "code": "…", "text": "…" }]
585
- }
586
- ```
587
-
588
- Agent states: `not-installed`, `installed`, `outdated`, `modified`, `conflict`.
589
- MCP states: `not-configured`, `configured`, `outdated`, `conflict`, `unreadable`.
590
- `unreadable` covers both "the config cannot be read safely" and — as of 0.1.7 —
591
- "no Node.js executable could be proved" (`reason: no-executable`), in which case
592
- `desired` is `null`, `node` is `null`, `nodeResolved` is `false` and `nodeError`
593
- carries the `MCP_EXECUTABLE_UNRESOLVED` diagnosis (section 2.1).
594
- Boundary kinds: `directory`, `missing`, `link`, `other`, `unchecked` (for the level
595
- below a link, which is deliberately not inspected), and `unknown` when the platform
596
- answer could not be obtained.
597
-
598
- `boundary.blocked` is true when either directory is a link or could not be verified;
599
- `boundary.link` names the level (`codex-home` or `agents`) and is `null` otherwise.
600
- `agent.reason` carries `codex-home-is-link`, `agents-dir-is-link` or
601
- `boundary-unverified` in that case, so the page can say which boundary it refused.
602
-
603
- `agent.expect` and `mcp.marked` are the two ownership facts: `expect` is what a
604
- refresh compares against immediately before its rename, and `marked` is true only
605
- when the entry carries the plugin marker (i.e. when a `remove` may delete it).
606
-
607
- `switch` reports the DSH posture and always carries
608
- `changedByThisAction: false`: no Codex action can authorize dispatch.
609
-
610
- ---
611
-
612
- ## 4.1 The preflight tool the agent depends on
613
-
614
- `delegate_preflight` is the fifth MCP tool and the only one that is not an
615
- authorization at all: it is a read-only measurement of one workspace, added so a
616
- dispatcher learns *before* submitting that a checkout is dirty, is not a
617
- repository, or needs an isolation decision — instead of learning it from a job that
618
- failed after admission.
619
-
620
- | property | value |
621
- |---|---|
622
- | tool | `delegate_preflight` |
623
- | arguments | `workspacePath` (string, required, absolute), `allowShared` (boolean, optional) |
624
- | schema | closed: `additionalProperties: false`; `allowShared` must be a real boolean (`MCP_ARGUMENT_TYPE` otherwise, and the plane is never reached) |
625
- | execution-plane route | `POST /dsh-delegate/x/workspace/preflight` |
626
- | writes | nothing: no commit, stash, branch, worktree, lock, task, grant or setting |
627
- | gate | transport fence + connection identity only — **not** the switch, because it authorizes nothing |
628
-
629
- The answer is `{ ok, readOnly, workspacePath, isolation, reason, sharedExplicit,
630
- decisionRequired, facts, guidance, checkedAt }` with `isolation` one of
631
- `worktree` / `shared` / `block` and `reason` a stable `PREFLIGHT_*` code. The full
632
- shape, the decision table and the four git reads it is allowed to issue are stated
633
- in `docs/workspace-contract.md` §3.5; this document only records the contract the
634
- agent file depends on.
635
-
636
- The one rule a reviewer should check: **a dirty repository is never downgraded
637
- automatically.** Without `allowShared` the answer is `block` with
638
- `decisionRequired: true`; with `allowShared: true` — a per-call decision record,
639
- never a stored preference — it is `shared` with `sharedExplicit: true`. The Codex
640
- coordinator evaluates the requested task and changed paths and may decide to use
641
- shared isolation without asking on every dispatch; it pauses when ownership or risk
642
- is unclear. To make the actual job match that decision, `delegate_submit` passes
643
- only `{ isolation: "shared" }` as an override. Provider, model, effort and timeout
644
- remain those selected in the plugin settings.
645
-
646
- ---
647
-
648
- ## 5. The agent file
649
-
650
- ```toml
651
- version = "1.0.0" # stamped from package.json when written
652
- name = "dsh-delegate"
653
- description = "…"
654
- developer_instructions = """…"""
655
- ```
656
-
657
- The file is a custom-agent definition, not an MCP registration: it deliberately
658
- contains no `[mcp_servers.*]` table, because the agent inherits the parent Codex
659
- session's MCP tools, and a second definition would start a second server.
660
-
661
- **Ownership is content identity, not a heuristic.** `readAgentState` reports:
662
-
663
- * `installed` — byte-identical to the file this build would write;
664
- * `outdated` — byte-identical to one of the enumerated `KNOWN_AGENT_TEMPLATES`
665
- digests (published builds only: `0.1.6`, both `0.1.7` builds, `0.1.8`, `0.1.9`,
666
- `0.1.10` in both its CRLF and LF byte forms, `0.1.11`, `0.1.12`, `0.1.13`, `0.1.14`,
667
- `1.0.0` and `1.1.0` in both byte forms, plus any later build listed when it is packed
668
- and verified) **or** byte-identical to a template this plugin recorded writing into THIS
669
- Codex home (section 5.0);
670
- * `modified`/`conflict` — everything else.
671
-
672
- Every release from `0.1.10` through `0.1.13` changes only the version line in the
673
- companion file, so those templates share one body and differ only in that stamped line.
674
- `0.1.14` changes the body as well (the per-call decision rules below), which is why its
675
- predecessor is enumerated as a pinned identity rather than rebuilt. The bytes are what
676
- ownership is proved against, so every release is enumerated on its own:
677
-
678
- | Release | Digest enumerated in `KNOWN_AGENT_TEMPLATES` |
679
- | --- | --- |
680
- | `0.1.10` | `fc7b27104dbb50f4e614cd4fd8df8db87fd8f59fcf2b3c27b412b49f8b89fbba` (packed CRLF) |
681
- | `0.1.10` | `6583f08a3ec4912a875249e6b127357b41cc3f8bf388b8e5cadbbeff469349be` (same template, LF) |
682
- | `0.1.11` | `b6ca7c3258fc00c1c1682abf099994b9f5abe650acc3ecf9635eec4a35520151` (packed) |
683
- | `0.1.12` | `ff04a4bf2c09b97747f835770c837637869581bb13bad3b8a870a3e92218514f` (packed) |
684
- | `0.1.13` | `b3a1d2f0520774c0066ea733f27fd47c67c5f5ac44394d0eec2564c7959700aa` (packed, 9191 bytes, CRLF) |
685
- | `0.1.14` | `11379c0152f3fb2bd4da1170812e51fe68006d98f6378c720cbadcee9ee4750c` (packed) |
686
- | `1.0.0` | `b1fd531598087564b26df14d3261515e961012f3fd010ea493f222da7bbaf415` (git release bytes, CRLF) |
687
- | `1.0.0` | `0cce75574107049413f4ddbdf7d8e6cddea92d45a0c4e0fa41b169cb790e5e13` (same template, LF) |
688
- | `1.0.0` | `a8c888afaa0a1a6a0abfcb56670ffbdb67697f07e54871ece78c8adffb15c149` (**legacy** pinned identity) |
689
- | `1.0.0` | `f51831e2ff265c9ba63a4760e245787060de7bd91dcc9663a11729fb472e5f62` (**legacy** pinned identity) |
690
- | `1.1.0` | `7d3ea5c54647a92cebaa0521741eb27f5141f7b2127b47009195fdb976dae4fb` (git release bytes, CRLF) |
691
- | `1.1.0` | `93d580bd849bb6d2c30c2db6286695ef3e0356896a88e552abae5f03eafc7601` (same template, LF) |
692
-
693
- The `1.0.0` and `1.1.0` **git-verified** identities come from the release commits
694
- themselves — `git show 2750047:codex/dsh-delegate.toml` and
695
- `git show 2d71708:codex/dsh-delegate.toml` — and are kept as fixtures
696
- (`tests/fixtures/codex-agent-1.0.0.toml`, `…-1.1.0.toml`) that are never packed.
697
-
698
- The two **legacy** `1.0.0` entries are NOT claimed to be the Git bytes: the fixture above
699
- is what the release commit contains, and these digests do not match it. They are retained
700
- because a released build enumerated them, so an installation created by that build stays
701
- structurally refreshable instead of flipping to "somebody else's file". Labelling them
702
- `legacy` is the point: keeping an old identity is conservative (an unrecognised file is
703
- never adopted and never removable), while pretending it came from Git would be a false
704
- claim.
705
-
706
- `0.1.10` therefore carries **two** entries, because that release exists in two byte forms
707
- and either one can be on disk: the CRLF file inside the packed
708
- `dsh-delegate-0.1.10.tgz`, and the same template kept as LF text. Both are hashes of
709
- actual published bytes — the LF digest is an exact identity, not a normalized comparison.
710
- `0.1.11` was delivered as an uncommitted candidate plus a verified tarball (the last
711
- commit, `a750c0b`, is `0.1.10`), so that digest is cited from the tarball and the saved
712
- baseline rather than from a `0.1.11` commit. The `0.1.12` digest is likewise verified
713
- against the `package/codex/dsh-delegate.toml` inside the packed
714
- `dsh-delegate-0.1.12.tgz` and against the saved release baseline. No earlier digest was
715
- removed or replaced when a later release was added, so a machine that skipped a release is
716
- still migrated directly to this build.
717
-
718
- `0.1.13` is the last release whose companion body is the older one: `0.1.14` added the
719
- per-call permission decision rules, so the `0.1.13` bytes are **not** recoverable by
720
- relabelling the current template and are enumerated as an exact identity instead. The
721
- digest was verified against `package/codex/dsh-delegate.toml` inside the packed
722
- `dsh-delegate-0.1.13.tgz` (9191 bytes, CRLF) and the file is kept as
723
- `tests/fixtures/codex-agent-0.1.13.toml`, so the "unchanged `0.1.13` is refreshed" and
724
- "edited `0.1.13` is preserved" cases are both driven by real published bytes.
725
-
726
- **What the product does with line endings: nothing.** `readAgentState` and
727
- `refreshKnownAgent` read the file and hash it as it is; they never normalize CRLF to LF or
728
- the reverse, and never rewrite a file to change its endings. A digest taken over
729
- normalized text would not be an identity at all — it would let an edited file match a
730
- known build — so normalization is a defect, not a convenience. The earlier `0.1.10`
731
- entry `6583f08a…` was reported as a normalized digest; it is in fact the digest of the
732
- LF form of that release, which is why it is retained (not replaced) alongside the CRLF
733
- value. `tests/codex-integration.test.js` constructs both forms explicitly, pins each
734
- digest, and proves for each that a byte-exact file is refreshed while an edited one is
735
- refused.
736
-
737
- A digest is added only for a build that was actually packed and verified, and the
738
- current template's digest is never in the list under an older label; the tests assert
739
- both facts (`tests/codex-integration.test.js`, `tests/package.test.js`).
740
-
741
- The 1.7.0 package recognizes these two earlier companion versions, each in both
742
- terminator spellings, and all four are exact identities like every entry above:
743
-
744
- | Release | Digest enumerated in `KNOWN_AGENT_TEMPLATES` |
745
- | --- | --- |
746
- | `1.6.1` | `efdef5f6e6ebcb26590ca929e674391b3c4fcdb3c017714d2322615783fdf712` (all LF) |
747
- | `1.6.1` | `5da9fd5eb5a89fd3c76365faca78b51e34233d993605f1b55dff4b07ceb88b80` (same template, CRLF) |
748
- | `1.6.1-test.5` | `bf698c861e7e560c555f8350b711db88627dce4a8752b2cbebe8748b6d640d37` (the packed agent, LF) |
749
- | `1.6.1-test.5` | `a45e12d0b234e80854e69429518a2def2d00338f968c2ecfc689307b792e4426` (same file, CRLF) |
750
-
751
- Both carry the SAME instruction body — the one `codex/dsh-taskbridge.toml` still holds —
752
- and differ only in the stamped `version` line, which is exactly why each needs its own
753
- exact identity: without them an untouched `1.6.1` or `1.6.1-test.5` installation hashes to
754
- "unknown content" and is reported `modified`, i.e. "somebody else's file", which is the
755
- false conflict this package removes.
756
-
757
- At plugin startup, an `outdated` agent is refreshed automatically only when its
758
- bytes still match a known shipped build. This does not create a missing agent or
759
- edit `config.toml`. A file with any other content is preserved, even when its
760
- version line names an older release.
761
-
762
- Since 1.2.0 the startup check has a second half: an **already installed** managed
763
- `mcp_servers.dsh-delegate` entry that is merely `outdated` is upgraded in place (see
764
- section 2.4). It is still not an install: no entry is created, and no entry the plugin
765
- cannot prove it wrote is adopted or rewritten.
766
-
767
- The version line is *never* the proof. A file that still starts with the managed
768
- header, still contains the dispatch rules, but has an old or invented version line
769
- and one edited body byte is the operator's: the digest no longer matches, so it is
770
- `modified`, it is never refreshed, and it is never removed. Conversely a
771
- byte-exact published build is refreshed and removable, as documented.
772
-
773
- ### 5.0 The recorded template digest (future releases)
774
-
775
- Enumerating every future release by hand does not scale, so one small record exists beside the
776
- table: after an **explicit `install`** or the startup **`refreshKnownAgentTemplate`** has written
777
- the agent file, and only when the file it re-reads is exactly the template this build renders,
778
- the plugin stores the digest of those bytes.
779
-
780
- * Path: `<DSH_HOME>/data/dsh-delegate/codex-agent-ownership/<sha256 of the real home>.json` — one
781
- file per pinned Codex home, named by a digest of that home so no case equivalence is ever
782
- inferred and two homes can never collide.
783
- * Content: `{ "schemaVersion": 1, "codexHome": "<real home>", "templateLfSha256": "<64 hex>" }`.
784
- The digest is **LF-normalized** (the CRLF/LF spelling is not content, exactly as the table
785
- treats it), and it is the only digest. No template body, no `config.toml`, no model
786
- setting, no version, no timestamp, no credential.
787
- * A file whose digest equals that value is `outdated`. One changed character — an added line, a
788
- tab, or a rewritten `version` line — hashes differently and stays `modified`.
789
- * The record is read only: `status`, `repair` and `remove` never write it. A record reached
790
- through a link or reparse point, missing, unreadable, malformed, over 4 KB, or naming a
791
- different home is **no record** — the file is then classified by its content alone. A read
792
- never creates the record directory; a write proves each level first and is atomic, owner-only,
793
- and read back. An unchanged record is not rewritten. A `DSH_HOME` override must be absolute;
794
- without one the `~/.dsh` default applies.
795
- * A failure to record costs the next release one enumeration. It never fails an install and
796
- never changes how a file is classified.
797
-
798
- The version line is *never* the proof. A file that still starts with the managed
799
- header, still contains the dispatch rules, but has an old or invented version line
800
- and one edited body byte is the operator's: the digest no longer matches, so it is
801
- `modified`, it is never refreshed, and it is never removed. Conversely a
802
- byte-exact published build is refreshed and removable, as documented.
803
-
804
- ### From the project plan to a DSH assignment
805
-
806
- Codex checks the relevant code and earlier deliverables before deciding the next
807
- step. It tells the operator which packet is ready, how it will work, and what it
808
- will reuse. The `delegate_submit.prompt` carries the plan DSH executes. Include the
809
- starting point, implementation order, scope and evidence for acceptance. For
810
- multi-stage work, keep dependencies and reviewed progress in the existing plan tree.
811
- The worker handles routine implementation choices and reports verified facts that
812
- would change the agreed approach. Codex reviews the evidence before advancing
813
- work that depends on it.
814
-
815
- ### 5.1 Required dispatch semantics
816
-
817
- The instructions must state all of the following. They are asserted in
818
- `tests/codex-integration.test.js` and `tests/package.test.js`, so an edit that drops
819
- one fails the build:
820
-
821
- 1. **Explicit assignment only.** Dispatch only when the parent request explicitly
822
- selects this agent (the exact mention `@dsh-taskbridge`, the agent picker, or an
823
- explicit instruction to delegate this implementation task to DSH).
824
- 2. **Mention is not dispatch.** Text that merely mentions DSH, DeepSeek,
825
- dsh-delegate, delegation or the agent while asking something else is not a
826
- dispatch request, and neither is a question about the plugin, its settings or
827
- its status.
828
- 3. **No dispatch for non-implementation work.** Explanation, planning,
829
- review-only, summarising and status questions are answered in Codex.
830
- 4. **Ambiguity is a question.** If it is unclear whether the task was assigned, ask
831
- once instead of dispatching.
832
- 5. **Switch first, facts second.** Call `delegate_status` first; then call
833
- `delegate_preflight` with the exact authorized workspace path. If either fails,
834
- the tool is missing, the switch is off, or the answer is ambiguous, stop and
835
- report the bounded refusal. Leave the switch as set and use only the authorized
836
- TaskBridge execution path.
837
- 6. **The isolation is decided from the measured facts, and never downgraded.**
838
- `delegate_preflight` returns `isolation` (`worktree` / `shared` / `block`) and a
839
- stable `reason` code:
840
- * `worktree` (`PREFLIGHT_CLEAN_REPOSITORY`) — a clean repository; dispatch with
841
- the worktree isolation selected in the plugin settings, unchanged.
842
- * `block` + `decisionRequired: true` (`PREFLIGHT_DIRTY_NEEDS_DECISION`) — the
843
- checkout is dirty, so a worktree cannot be prepared from a commit. The agent
844
- must **not** silently downgrade and must **not** probe by submitting. As
845
- coordinator, it inspects the changed-file count and bounded path list and
846
- decides whether this authorized task can safely run in place while preserving
847
- the existing changes. It need not ask the operator to choose on every dispatch:
848
- it states a safe shared decision and its reason before dispatch, re-runs the
849
- preflight with `allowShared: true`, and proceeds only if the answer is `shared`
850
- (`PREFLIGHT_DIRTY_SHARED_EXPLICIT`). If ownership, overlap or risk is unclear,
851
- it pauses for one focused question.
852
- * `block` for any other reason (`PREFLIGHT_GIT_UNAVAILABLE`,
853
- `PREFLIGHT_NOT_A_REPOSITORY`, `PREFLIGHT_NO_COMMITS`, `PREFLIGHT_GIT_FAILED`,
854
- `PREFLIGHT_WORKSPACE_INVALID`, `PREFLIGHT_NOT_A_DIRECTORY`) — stop and report
855
- the code; no fallback exists.
856
- 7. **The dispatch text carries the workspace facts and the isolation reason.** A
857
- shared run is named as such, because the worker writes into a checkout that
858
- already has uncommitted work.
859
- 8. **Route settings stay in the plugin.** For `worktree`, call `delegate_submit`
860
- without `overrides` so the configured isolation applies. For an explicitly chosen
861
- `shared` run, pass only `{ isolation: "shared" }` as the per-task override because
862
- the plugin may still be configured for `worktree`. Never override provider,
863
- model, effort or timeout, and never encode a route in the prompt. `allowShared`
864
- on preflight records the decision but does not change the submitted job's
865
- isolation by itself.
866
- 9. **One task, WAITED — not polled (1.1.0).** Keep the returned `taskId` and call
867
- `delegate_wait({ taskId })` — with no `waitSeconds` argument — repeating it until it
868
- returns a reason that needs the host. `delegate_result` is **not** a polling loop: one
869
- `delegate_wait` blocks internally and re-issues its own bounded observation requests,
870
- which is the waiting loop. Never submit a duplicate because a task is still running;
871
- `delegate_cancel` stops it. The wait defaults to 3600 seconds and the tool caps it
872
- there, so there is nothing to raise: when a wait ends, call it again on the same task.
873
- A shorter explicit `waitSeconds` stays legal but is only for a one-off diagnostic the
874
- operator explicitly asked for.
875
- While the wait runs, stay silent: do not read intermediate code or diffs, do not run
876
- parallel implementation or research, and do not narrate unchanged snapshots. The only
877
- exceptions are work explicitly assigned as independent of the task, an inspection the
878
- operator explicitly asked for, a decision or diagnosis that genuinely needs a fact the
879
- wait did not return, and an explicit user-authorized takeover. Review happens once, on
880
- delivery.
881
- `heartbeat` means "nothing to report" and is internal: the tool re-waits rather than
882
- handing it to the model, so normal progress never wakes Codex.
883
- The roughly 25-second internal observation cadence belongs to the program, not to the
884
- agent: it is not a polling rate the model should imitate.
885
- 10. **Each wait reason has a stated policy (1.1.0).**
886
- - `attention` — the run has been completely silent past the configured attention
887
- interval (ten minutes by default). It does **not** mean an ordinary wait ended: a
888
- wait ending is `wait-limit`. It is a QUESTION, not a verdict: read the compact
889
- diagnostic (phase, last activity, current tool and its elapsed time, self-check
890
- verdict) and **default to waiting again** on the same task. Never cancel, never mark
891
- failed, and never resubmit merely because a task is quiet or one tool or test is
892
- slow. Only a concrete, stated error justifies anything else, and then it is reported
893
- rather than silently restarted.
894
- - `permission` — a per-call decision is outstanding; see item 12. After deciding,
895
- wait the SAME task again.
896
- - `ready` — execution finished and the task awaits **host review**; that is not
897
- acceptance. Read `delegate_result` **once** for full evidence and review it in
898
- Codex. A large diff is inspected file by relevant file, once each, not re-read.
899
- - `failed` / `cancelled` — read `delegate_result` once for the recorded reason and
900
- report it; do not resubmit identical work hoping for a different outcome.
901
- - `wait-limit` — this call's own wait budget ran out with nothing changed. The answer
902
- carries `actionable: false` and `terminal: false`: it is not a result, requires no
903
- business decision, and ends nothing. Immediately `delegate_wait` the same task
904
- again (no `waitSeconds`). It is not a failure, a stall, or a reason to submit
905
- anything new or to check the implementation locally.
906
- A **client-side tool timeout** is a different event and is *not* `wait-limit`: the
907
- host's own limit ending the call does not prove the execution stopped, and does not
908
- prove it is alive. Keep the `taskId` and wait again; if a compact fact is genuinely
909
- needed, read it with `delegate_result`. Never duplicate, restart or cancel a task
910
- because a wait or a client timeout ended.
911
- - `interrupted` — **the wait was cut off; that is not by itself a finished
912
- execution.** One call answers it at once (it does not loop), so the answer's own
913
- fields decide the response (1.2.0):
914
- * `terminal: false` with a live `state` (`running`/`pending`): the task is running.
915
- `delegate_wait` the same task; never resubmit, never implement locally, never
916
- cancel for this reason.
917
- * `terminal: true` and `state: "interrupted"`: the TASK record itself is a restart
918
- history and will not resume. Read `delegate_result` once and report; do not keep
919
- calling `delegate_wait` on it.
920
- * `terminal: false` with no state, an unrecognized state, or a state that
921
- contradicts the record (for example `running` with an end time): neither
922
- "running" nor "stopped" may be assumed. Keep the task id and check one fact with
923
- `delegate_result` before deciding — and do not re-wait indefinitely on a task the
924
- host cannot classify.
925
- A settled state carried by an `interrupted` observation is reported as that real
926
- outcome (`awaiting-host-review` → `ready`), so a completed run always reaches review.
927
- 10b. **When the host blocks the connection, the control channel is separate (1.2.0).**
928
- Some hosts forward one tool call at a time, so a long `delegate_wait` blocks
929
- `delegate_status`/`delegate_cancel` on that same MCP connection. When — and only
930
- when — the operator asks to stop or inspect that task in that situation, the agent
931
- may run `dsh-delegate-control status <taskId>` or
932
- `dsh-delegate-control cancel <taskId>` from the SAME package directory as the
933
- configured MCP script (derived from this plugin's own MCP `args[0]`, never another
934
- script), using the same `node` executable. It cannot submit, change a setting or
935
- the switch, act on another task, resubmit the work or switch models, and during a
936
- normal wait it stays silent instead of polling that binary.
937
-
938
- What the command guarantees, so the expected output is never mistaken for a hang:
939
- `status` reads the task's CURRENT compact state through ONE observation with the
940
- smallest positive wait (`waitMs: 1`) — not `waitMs: 0`, which the engine reads as
941
- "no bound requested" and replaces with a 25-second long poll. The commands answer
942
- inside a single budget (10 s by default; `DSH_DELEGATE_CONTROL_TIMEOUT_MS` may only
943
- lower it), enforced through one caller `AbortSignal` with the observation retry
944
- disabled for that call, so a dead endpoint cannot spend a backoff schedule after
945
- the answer. A failure — including an exhausted budget, `CONTROL_TIMEOUT` — is one
946
- bounded JSON document on stdout plus a non-zero exit code, never a stack trace.
947
- 11. **Evidence, not approval.** Return state, the actual provider/model/effort,
948
- changed-file summary, verification evidence, limitations, and the preflight
949
- facts with the isolation reason actually used. Executing is not accepting:
950
- Codex remains responsible for review. Do not claim a check passed without
951
- evidence, and never commit or push.
952
- 12. **The workspace is not tidied up to pass a check.** No commit, stash, branch,
953
- worktree creation, `clean`, `reset` or revert on the operator's behalf. A dirty
954
- workspace is an isolation decision for the coordinator; pause only when the
955
- existing edits' ownership or risk is unclear.
956
- 13. **A task awaiting a permission decision is still running, and the coordinating
957
- Codex decides it.** A wait reporting `permission` (with the full redacted request
958
- at the top level) is the worker paused on one native tool call, not a
959
- stall: never submit a duplicate, mark it failed, or cancel it merely because it
960
- waits, and keep waiting the SAME task. The agent does **not** invoke a second
961
- approval/review model, does **not** ask the operator to choose routine within-task
962
- decisions, and does **not** delegate the decision to the worker. The worker's own
963
- `reason` is a claim, never authority. It checks the actual tool, redacted
964
- arguments, call identity, session and repository against the authorized task,
965
- reading local evidence when it needs to understand an executable script or target,
966
- and approves only the specific operation the task needs — refusing anything
967
- unrelated, destructive or exfiltrating, any credential or configuration change, and
968
- any request whose evidence is unknown or materially incomplete. An allow requires
969
- `argumentsComplete: true`, `completeness: complete`, `allowBlocked: null`, no
970
- transport truncation affecting the pending operation, a still-pending request and
971
- its exact `fingerprint`, passed to `delegate_permission_decide` with the `taskId`,
972
- `requestId`, `decision` (`allow-once`/`reject`) and a bounded `reason`. An invalid or
973
- stale allow grants nothing: re-read the current request and decide safely, and never
974
- retry under broader settings. Waiting the SAME task continues after the decision, a
975
- later request needs a fresh check, and an approval is one call only — never host
976
- acceptance and never a standing sandbox grant. When dispatching on behalf of a
977
- parent commander, the complete request evidence is preserved for that commander
978
- rather than involving a separate review model.
979
- 14. **No local implementation while a delegated worker runs (1.1.0).** Neither the
980
- dispatch companion nor the parent commander writes, patches or "just fixes" the
981
- implementation while a delegated task is running, waiting, or awaiting review: that
982
- would make the reviewer a second implementer of the same change, produce conflicting
983
- edits in one workspace, and break the single-writer property the isolation mode
984
- provides. The only exception is an explicit, user-authorized takeover — the operator
985
- saying to take over and implement it here. A long silence, a permission refusal, a
986
- failed run, a wait-limit or the commander's own opinion of the plan is **not** that
987
- authorization. Permitted local actions while a task runs are: reading status and
988
- diagnostics, waiting, reading evidence, deciding a pending permission, cancelling,
989
- and writing the follow-up prompt. A believed-wrong result is reported and proposed
990
- as a follow-up in the same chain, never applied locally.
991
- 15. **No secrets.** Never read, request, store or relay provider credentials or
992
- connection tokens.
993
- 16. **Task threads are explicit.** A submission starts a NEW DSH task conversation
994
- by default; a directory-level reuse setting no longer exists. `continueFromTaskId`
995
- is passed **only** for a follow-up change, correction or retry that belongs to one
996
- earlier delegated task, and its value is the latest prior task id of that chain.
997
- An unrelated task, a new topic or a different workspace omits the field entirely:
998
- an id is never reused "to keep context" and never guessed. A follow-up to a
999
- `worktree` task keeps its original source `workspacePath` for preflight and
1000
- submit; the plugin resolves the same internal tree and continues its earlier
1001
- uncommitted changes there. Never send the tree's internal execution path as the
1002
- authorization path or choose a new isolation override. A refusal naming an
1003
- unavailable or mismatched tree is reported and escalated, never worked around
1004
- by re-submitting as a new task. The run's report states which of the two happened.
1005
- Corrections are consolidated into one follow-up submission rather than a scatter of
1006
- new tasks.
1007
-
1008
- ### 5.2 What the file cannot guarantee: `@` selection
1009
-
1010
- **This plugin does not claim that any Codex surface supports selecting the agent by
1011
- typing `@dsh-taskbridge`.** Only verified facts are stated:
1012
-
1013
- * A custom-agent file at `$CODEX_HOME/agents/<name>.toml` is a Codex-recognised
1014
- definition, and the parent session's MCP tools are inherited by it — this is what
1015
- the installation relies on.
1016
- * Whether the *current* Codex Desktop / CLI input box offers an `@`-mention picker
1017
- for that file is a property of the Codex build, not of this plugin. No official
1018
- documentation or runtime evidence in this repository establishes it for the
1019
- versions under test, so the wording here (and in the settings page) says the
1020
- mention *may* select the agent, and claims no more.
1021
-
1022
- Consequently the agent's own instructions treat `@dsh-taskbridge` as **one example**
1023
- of an explicit selection, alongside the agent picker and an explicit instruction to
1024
- delegate. If a Codex build does not offer `@` selection, the agent still works when
1025
- chosen through whatever selection mechanism that build does provide. A new Codex
1026
- session (or a restart) is required to load the new file and the new MCP entry.
1027
-
1028
- ---
1029
-
1030
- ## 6. Failure modes a reviewer should check
1031
-
1032
- | Situation | Expected |
1033
- | --- | --- |
1034
- | `CODEX_HOME` relative | 400 `CODEX_HOME_INVALID`; nothing read or written |
1035
- | `CODEX_HOME` unset | diagnosed against `~/.codex` |
1036
- | `$CODEX_HOME` is a normal symlink or Windows junction | pin and verify its real directory target, preserve the root alias, then apply the same managed-content checks; broken or unverifiable targets are refused |
1037
- | `$CODEX_HOME/agents` is a symlink or a Windows junction | `conflict` (`agents-dir-is-link`); install/repair/remove refuse with `AGENT_PATH_CONFLICT` and no file is created outside the home |
1038
- | an ordinary real Windows directory | `directory` in every spelling of the helper's boolean (`dir/False`, `dir/false`); never reported as a link |
1039
- | `repair` with the agent file missing or `outdated` | `changed: ["mcp"]` or `[]`; the agent file is not created and not refreshed, and `agents/` is not created |
1040
- | the boundary cannot be verified (no spawnable shell / no PowerShell) | `conflict` (`boundary-unverified`); everything refused, nothing assumed safe |
1041
- | agents dir missing | created on install (`0700`) when the boundary is clean |
1042
- | `agents/dsh-taskbridge.toml` is a symlink or a directory | `conflict`; untouched |
1043
- | a different agent file appears between status and install | `modified`; untouched (first install is exclusive) |
1044
- | an agent file is rewritten between the status read and `remove` | `AGENT_USER_MODIFIED` (`modified-before-removal`); the new bytes are kept |
1045
- | the agent path is replaced by a directory / a link before `remove` | `AGENT_PATH_CONFLICT`; the entry is left in place |
1046
- | an edited agent file with an old version line | `modified`; never refreshed, never removed |
1047
- | a byte-exact previously published agent file | `outdated`; refreshed on install, removed on remove |
1048
- | `config.toml` is a symlink | `unreadable`; refused |
1049
- | `config.toml` > 1 MiB | refused (`other`), untouched |
1050
- | `config.toml` contains a NUL / control character | `CODEX_CONFIG_UNSUPPORTED`, untouched |
1051
- | `config.toml` uses CRLF | edited in place; CRLF and every unrelated byte preserved |
1052
- | an unmarked same-name `mcp_servers.dsh-delegate` entry | `conflict` (`unmanaged-entry`); byte-identical after install/repair/remove |
1053
- | an unmarked entry that is EXACTLY the owned entry (same command, single script argument, timeout and env) in one unambiguous standard table | `conflict` (`unmanaged-entry-exact`); byte-identical after install/remove, and `repair` adds the one marker line |
1054
- | an unmarked entry with a duplicated key, an inline table beside the header, or an extra/empty sub-table | `conflict` (`unmanaged-entry`); byte-identical after install/repair/remove |
1055
- | entry added between the read and the write | re-classified; refused if it stopped being ours |
1056
- | package `bin/dsh-delegate-mcp.js` missing | MCP refused (`MCP_SCRIPT_MISSING`), agent still installed |
1057
- | plain Node.js host (`process.execPath` is a Node binary) | `command` is that path; no override is consulted |
1058
- | DSH Desktop host (`process.versions.electron` set) | `command` is the bundled runtime, **never** `DeepSeek Harness.exe` |
1059
- | desktop host that exposes no `resourcesPath` | `<dirname(execPath)>/resources` is derived and the bundled runtime is used |
1060
- | bundled runtime missing, `DSH_NODE_PATH` set to an absolute existing file | that file is written as `command` |
1061
- | an override that is relative / a directory / a link / missing | ignored; the next candidate is tried, and the reason is kept in `nodeError.details.rejected` |
1062
- | no candidate can be proved | status: `mcp.node = null`, `nodeResolved: false`, `ready: false`; install/repair refuse `MCP_EXECUTABLE_UNRESOLVED`; `config.toml` byte-identical; agent file still installed |
1063
- | no candidate can be proved, an owned entry already points at a stale command | left as written (nothing is guessed); the note names the environment variable to set |
1064
- | DSH has no execution plane (public bind) | unchanged by this feature; delegation still refuses |
1065
- | the agent is asked to dispatch into a dirty repository | `delegate_preflight` answers `block` / `PREFLIGHT_DIRTY_NEEDS_DECISION`; the coordinator evaluates the listed paths and task, then either reports and dispatches with an isolation-only `shared` override or pauses when risk/ownership is unclear |
1066
- | the agent is asked to dispatch into a non-repository or commit-less directory | `block` with the matching `PREFLIGHT_*` code; the agent stops and reports it rather than submitting |
1067
- | the workspace path is relative, missing or a file | `block` / `PREFLIGHT_WORKSPACE_INVALID` or `PREFLIGHT_NOT_A_DIRECTORY`; nothing is resolved against the process cwd |
1068
- | `delegate_preflight` is called while the switch is off | answered normally: it authorizes nothing, and that is when a coordinator needs it most |
1069
- | `delegate_preflight` is sent `allowShared: "true"` | `MCP_ARGUMENT_TYPE`; the plane is not called |
1070
- | `delegate_submit` is called twice for one directory | two Sessions in one Workspace: a new submission never continues a previous one |
1071
- | `delegate_submit` sends `continueFromTaskId` for an unknown, pruned or live parent | the run fails with `JOB_CONTINUATION_REFUSED` and `error.details.session` = `SESSION_CONTINUATION_UNKNOWN` / `SESSION_CONTINUATION_STATE`; no conversation is started |
1072
- | a follow-up names a parent that ran elsewhere (another directory, another worktree, another repository) | `JOB_CONTINUATION_REFUSED` with `SESSION_CONTINUATION_PATH_MISMATCH` / `SESSION_CONTINUATION_WORKSPACE_MISMATCH`; nothing runs |
1073
- | a follow-up to a `worktree` task is submitted with the source checkout | accepted: the source path remains the authorization/preflight path, and the engine restores the parent's exact managed tree internally |
1074
- | a follow-up's recorded tree was removed or belongs to another run | `SESSION_CONTINUATION_UNAVAILABLE` with the stated reason; no fresh tree is prepared |
1075
- | `continueFromTaskId` is not a string | refused at the MCP schema (`MCP_ARGUMENT_TYPE`) and again by the engine (`JOB_CONTINUATION_REFUSED`) |
1076
- | the settings page is asked to save a conversation mode | `setConversation` refuses with `CONVERSATION_MODE_REMOVED`; the stored legacy value is untouched and still inert |
1
+ # Codex integration contract
2
+
3
+ Status: implemented in 1.9.1 (retaining the 1.9.0 native skill migration from legacy subagent `agents/dsh-taskbridge.toml` to `skills/dsh-taskbridge/SKILL.md`, with safe automatic retirement of untouched 0.1.6–1.8.x legacy subagents and automatic refresh of untouched 1.9.0 skills; Antigravity integration is documented in `docs/antigravity-integration.md`, and Claude Code / Claude Desktop integration is planned for 2.0).
4
+
5
+ The 1.7.0 release also makes future managed upgrades self-recognising: the two exact
6
+ companions this machine really held (`1.6.1` in both terminator spellings and the local
7
+ `1.6.1-test.5` prerelease) are now enumerated, and an explicit install or the startup refresh
8
+ records the LF-normalized digest of the template it wrote, in one small file per real Codex
9
+ home. A LATER release therefore recognises the template the previous one wrote without
10
+ appending another digest by hand, while an edited file — one changed character, or only the
11
+ `version` line — still stays the operator's and is never rewritten. See section 5.
12
+
13
+ 1.5.1 refreshes the manifest on each activation, resolves a normal linked home root, and upgrades exact shipped/candidate templates while preserving custom content. See [1.5.1 notes](https://github.com/ranranyya/dsh-taskbridge/blob/master/docs/releases/1.5.1.zh.md).
14
+
15
+ 1.5.0 adds `delegate_question_answer`, combined decision/answer-and-wait flows and program metrics. Managed upgrades recognize the exact published 1.4.2 and verified local test.1/test.2 companions; customized files remain operator-owned. See the [1.5.0 release notes](https://github.com/ranranyya/dsh-taskbridge/blob/master/docs/releases/1.5.0.zh.md).
16
+
17
+ 1.4.2 also recognizes the exact published 1.4.1 companion for managed upgrades.
18
+ The review behavior introduced in 1.4.1 recognizes the exact unmodified
19
+ 1.4.0 companion in LF and CRLF forms, and updates the review contract: a completed
20
+ task may be read and reviewed by its original identity after a restart. History
21
+ does not restore execution or old permissions. Reviews are confirmed only when
22
+ `reviewPersistence.durable` is true (`state: "saved"`); `saving` or `timed-out`
23
+ means the write is still unconfirmed, and `failed` permits a retry. Ordinary waits
24
+ omit review prose. A result that reports `noteOmitted: true` can be read with
25
+ `delegate_result` plus `reviewNoteOffset` and optional `reviewNoteLimit` (1–2000
26
+ Unicode code points per page, default 2000); follow `nextOffset` until `complete`.
27
+ Review notes accept up to 8000 code points after trimming and are stored redacted.
28
+ See the [release notes](https://github.com/ranranyya/dsh-taskbridge/blob/master/docs/releases/1.4.1.zh.md) for validation boundaries.
29
+
30
+ This document is the contract between the plugin's settings page (browser half),
31
+ the host-side installer (`src/codex/installer.js`) and the skill files and MCP entry it manages.
32
+ It is written so a reviewer can check the code against it without reading the
33
+ README.
34
+
35
+ ## Native Codex Skill migration (1.9.0)
36
+
37
+ Starting in `1.9.0`, the managed Codex target is the native skill
38
+ `$CODEX_HOME/skills/dsh-taskbridge/SKILL.md` (with independent ownership digests in
39
+ `codex-skill-ownership`). Installing a native skill instead of a subagent allows the active
40
+ Codex session to read the workflow directly and drive one `delegate_submit` +
41
+ `delegate_wait` chain (using `tool_timeout_sec = 3660`) instead of wrapping dispatch in
42
+ `spawn_agent` + short-timeout `wait_agent` polling loops.
43
+
44
+ The generated entry carries the ordinary flow and links a same-directory rules reference for
45
+ multi-stage planning and uncommon events. Installation publishes the reference before switching
46
+ `SKILL.md`. Older references remain available to Codex sessions that already loaded a previous
47
+ entry. Startup restores a missing reference for an unchanged entry. An edited reference makes
48
+ both files operator-managed. Uninstall removes the unchanged active pair after proving ownership.
49
+
50
+ An explicit `install`, startup refresh, or `remove` inspects `$CODEX_HOME/agents/dsh-taskbridge.toml`
51
+ and `$CODEX_HOME/agents/dsh-delegate.toml` against both `KNOWN_AGENT_TEMPLATES` (`0.1.6`–`1.8.x`)
52
+ and historical `codex-agent-ownership` records. Untouched legacy managed subagent files are
53
+ unlinked ONLY after re-proving their exact bytes (and, on install/refresh, after confirming
54
+ `skills/dsh-taskbridge/SKILL.md` is ready). Any user-modified legacy file is preserved untouched
55
+ and surfaced via `LEGACY_AGENT_USER_MODIFIED`. Boundary checks cover `$CODEX_HOME`, `skills/`,
56
+ `skills/dsh-taskbridge/`, and `agents/`.
57
+
58
+ The action result's `changed` array reports `agent` for a write or removal of
59
+ `SKILL.md`, `legacyAgent` for removal of one or more managed legacy TOML files,
60
+ and `mcp` for a change to the MCP entry. An install that writes the skill and
61
+ retires a legacy file includes both `agent` and `legacyAgent`.
62
+
63
+ ## TaskBridge companion migration (1.3.2)
64
+
65
+ The public companion is now `dsh-taskbridge`, installed as
66
+ `agents/dsh-taskbridge.toml`. An explicit install or the startup refresh migrates
67
+ an unchanged, recognized published `agents/dsh-delegate.toml` and removes the old
68
+ managed file after the new managed template is present. Edited files and an
69
+ operator-owned destination remain untouched; startup does not perform a first
70
+ installation when no previous managed companion exists. The MCP table remains
71
+ `mcp_servers.dsh-delegate`, and `delegate_*` tool names remain compatible.
72
+
73
+ 1.4.0 recognizes the exact published 1.3.2 companion and refreshes its waiting rules
74
+ on plugin startup. After examining a delivered result, the companion records its own
75
+ accepted or changes-requested conclusion with `delegate_review`; the plugin never
76
+ derives acceptance from completion. A client may need reloading to see the refreshed
77
+ agent and tool catalog. Edited companion files remain operator-owned.
78
+
79
+ Explicit install/repair can also adopt a marked standard legacy MCP path after
80
+ the old `dsh-delegate` or `dsh-taskdispatch` package has been uninstalled from the
81
+ same `node_modules` as the current `dsh-taskbridge`. This narrow exception does
82
+ not apply to custom wrappers, other directories, or automatic startup refresh.
83
+ `repair` remains MCP-only. TaskBridge CLI aliases point at the existing bin files.
84
+
85
+ ---
86
+
87
+ ## Explicit task descriptions (1.5.4)
88
+
89
+ `delegate_submit` and `POST /tasks` accept optional `goalDescription`; `delegate_review` and `POST /tasks/review` accept optional `completionSummary`. Both trim surrounding whitespace, preserve internal newlines, and allow at most 2000 Unicode code points before and after redaction. Missing or blank strings are absent; explicit null and other non-strings are refused. No value is inferred from prompts or earlier tasks.
90
+
91
+ The goal is fixed at task creation. The completion summary exists only under `hostAcceptance.completionSummary`, is part of the review identity with decision and note, and becomes public only after the same review write is durable. A saved review cannot gain or change a summary. Compact waits return only its character count and an omission flag; full results contain the prose. History retains titles and explicit continuation references without inventing missing old data.
92
+
93
+ ## 1. What is owned, and what is not
94
+
95
+ | Path | Owner | The plugin may | The plugin may never |
96
+ | --- | --- | --- | --- |
97
+ | `$CODEX_HOME/skills/dsh-taskbridge/SKILL.md` | managed copy of `codex/skills/dsh-taskbridge/SKILL.md` | create it **exclusively** on explicit install (or legacy migration) when absent; refresh a byte-exact known build during plugin startup or explicit install; delete it on `remove` only after re-reading it and finding the same bytes it classified (and unlink untouched legacy `agents/dsh-taskbridge.toml` / `agents/dsh-delegate.toml` after re-proving their bytes) | overwrite or delete a file that is not that exact build — including a skill or legacy agent file whose body was edited, and including a file that changed in the window between the status read and the write/removal |
98
+ | `$CODEX_HOME/config.toml`, table `mcp_servers.dsh-delegate` | operator, with one managed entry | add the entry when absent; update `command`/`args`/its own `env.DSH_DELEGATE_DISCOVERY_FILE` when the entry carries **the plugin marker** *and* is the exact shape this plugin writes; on an explicit `install`/`repair` only, adopt a recorded `args[0]` that is a PROVED real installation of this package (manifest `name` + `bin["dsh-delegate-mcp"]` mapping) | touch any other key, table, comment or ordering; adopt, update or delete an unmarked same-name entry, even one whose values coincide; adopt a differing script path from the automatic startup check |
99
+ | `$CODEX_HOME`, `$CODEX_HOME/skills`, `$CODEX_HOME/skills/dsh-taskbridge` and `$CODEX_HOME/agents` | Codex | resolve and pin a normal root symlink/junction to its real directory; inspect all 4 boundary levels in one batched Windows check; create missing `skills/dsh-taskbridge` (`0700`) on explicit install | retarget or delete the root alias; follow a link in `skills/`, `skills/dsh-taskbridge/`, `agents/` or the final file; write through an unusable or unverified target |
100
+ | DSH local-call switch | operator | report it | change it |
101
+
102
+ `$CODEX_HOME` resolution: `CODEX_HOME` when set and absolute; otherwise
103
+ `~/.codex`. A relative override is refused (`CODEX_HOME_INVALID`), because
104
+ resolving it against the harness's cwd would report on, and write to, a directory
105
+ nobody named.
106
+
107
+ ### 1.1 Link boundaries
108
+
109
+ `lstat` on the final file is not enough: if `$CODEX_HOME/skills`, `$CODEX_HOME/skills/dsh-taskbridge`, or `$CODEX_HOME/agents` is a junction,
110
+ `mkdir -p` and the file create would walk *through* it and write outside the Codex home entirely. Since 1.5.1 the selected HOME root is first pinned to its real directory; since 1.9.0 that real root plus `skills/`, `skills/dsh-taskbridge/` and `agents/` are inspected together as boundaries:
111
+
112
+ | `$CODEX_HOME` | `skills/` · `skills/dsh-taskbridge/` · `agents/` | result |
113
+ | --- | --- | --- |
114
+ | real directory | missing | normal: explicit `install` creates `skills/dsh-taskbridge` (`0700`) |
115
+ | real directory | real directory | normal |
116
+ | real directory | link (symlink or junction) | `agent.state = conflict`, `reason = skills-dir-is-link` / `skill-dir-is-link` / `agents-dir-is-link`; install/repair/remove all refuse with `AGENT_PATH_CONFLICT` |
117
+ | root symlink/junction with a real directory target | checked under the pinned real target | normal root alias; alias preserved, subdirectory/file links still refused |
118
+ | could not be verified | — | `agent.state = conflict`, `reason = boundary-unverified`; same refusal |
119
+
120
+ A **junction** is the case `lstat` cannot see: Windows reports it as an ordinary
121
+ directory. On Windows the `ReparsePoint` file attribute is read through one
122
+ `powershell.exe` child (`-NoProfile -NonInteractive`, hidden, 15 s bound), with the
123
+ paths passed in an environment variable rather than interpolated into script text.
124
+ The child answers one comma-separated verdict per path — `dir/<bool>`, `other/<bool>`
125
+ or `missing` — and the boolean is PowerShell's `Boolean.ToString()` output, whose
126
+ spelling is **not** stable (`True`/`False` on Windows PowerShell 5.1, `true`/`false`
127
+ under other hosts/cultures). The verdict is therefore parsed case-insensitively
128
+ (`parseDirectoryVerdict`), the script emits lower case via `ToLowerInvariant()`, and
129
+ anything that is not a recognised `dir/`/`other/`/`missing` answer is treated as
130
+ `other` (a path this plugin will not write under), never as a missing answer.
131
+ A regular directory — `dir/false` in any spelling — is `directory`, so the ordinary
132
+ Windows layout is unaffected; only `dir/true` / `other/true` are reported as a link.
133
+ This is pinned by a real-directory probe test that runs the actual PowerShell child on
134
+ a temporary directory on Windows (and skips elsewhere), not only through the test
135
+ classifier hook.
136
+
137
+ The status document reports this as `boundary: { blocked, link, unknown, home,
138
+ skills, skillDir, agents }`. A **failed** verification is a refusal, not a pass: if the platform
139
+ answer cannot be obtained (no spawnable shell, no PowerShell), the boundary is
140
+ `unknown` and every action refuses, because "could not check" must never be read
141
+ as "safe". The check is re-done at the start of every writing action from the
142
+ freshly read status, so a link that replaced either directory after the operator
143
+ last looked is still refused.
144
+
145
+
146
+ ---
147
+
148
+ ## 2. The MCP entry
149
+
150
+ The owned shape, written as a marked block:
151
+
152
+ ```toml
153
+ # dsh-delegate: managed by the DSH Delegate plugin settings page
154
+ [mcp_servers.dsh-delegate]
155
+ command = "<a Node.js executable, resolved as described in 2.1>"
156
+ args = ["<installed package>/bin/dsh-delegate-mcp.js"]
157
+ tool_timeout_sec = 3660
158
+ ```
159
+
160
+ * `command` is an **absolute path to a Node.js executable**, never a bare `node` and
161
+ never the desktop application. A GUI-launched Codex often has a narrower `PATH`
162
+ than the shell that started DSH, so a bare `node` fails at spawn time; and in the
163
+ DSH Desktop (Electron) host `process.execPath` is `DeepSeek Harness.exe`, which
164
+ would make Codex launch a second GUI instead of an MCP server. Section 2.1 states
165
+ how the executable is chosen and what happens when no candidate can be proved.
166
+ * `args[0]` is derived from `import.meta.url` of the running module, so it names
167
+ the *installed* package — never a repository checkout and never a path captured
168
+ when the tarball was built.
169
+ * `tool_timeout_sec = 3660` (1.1.0) is an **owned scalar on this entry only**. The
170
+ `delegate_wait` tool defaults to a 3600-second wait and caps it there, so a client that
171
+ honours this field is allowed to let one call run that long. The plugin cannot prove that
172
+ every client honours it: a client that applies its own tool timeout may still end the
173
+ wait earlier. That is an OUTER limit and is not a `wait-limit` answer. The managed entry
174
+ therefore *requests* 3660 s — the 3600-second wait plus one minute of slack, never a
175
+ second wait window — while a client-side cap that ignores the field remains a client
176
+ limit the plugin cannot lift. This is not a Codex-wide setting and the plugin writes it
177
+ nowhere else.
178
+ * When a client exposes a yield/pragmas parameter, an ordinary wait should request
179
+ roughly `1200000` ms (20 minutes), not one minute. A one-minute return is a caller
180
+ choice, not a documented hard maximum, and not every client supports the same long
181
+ yield — the agent is told to state what its client actually offers rather than
182
+ describe one minute as inherent.
183
+ * A managed entry written by an earlier release has no such field. It is classified
184
+ `outdated` and repaired **in place** (the line is inserted inside our table), so an
185
+ existing installation updates through the settings page instead of being reported as
186
+ somebody else's file.
187
+ * A managed entry with a different integer is likewise `outdated` and rewritten to
188
+ 3660. A non-integer value is not a value this plugin writes, so the whole entry is
189
+ treated as operator-owned and left untouched (`timeout-not-an-integer`).
190
+ * An unmarked same-name entry stays a conflict regardless of its values: the marker
191
+ comment is the only authorship proof this format carries.
192
+ * `env.DSH_DELEGATE_DISCOVERY_FILE` is written only when DSH uses a non-default
193
+ discovery location (`DSH_HOME` set, or `DSH_DELEGATE_DISCOVERY_FILE` set). The
194
+ default stays implicit so a later `DSH_HOME` change is not silently overridden.
195
+
196
+ ### 2.1 The `command` executable (`resolveNodeExecutable`)
197
+
198
+ The host is classified first (`hostRuntimeKind`): `process.versions.electron` makes
199
+ it an **electron** host; `process.resourcesPath` (set by Electron and by nothing in
200
+ plain Node.js) is an equivalent desktop signal; otherwise it is a **node** host.
201
+
202
+ | host | `process.execPath` | selected `command` |
203
+ | --- | --- | --- |
204
+ | plain Node.js | `node`/`node.exe` | that path, unchanged — it is the runtime that loaded this plugin |
205
+ | plain Node.js, `execPath` is not a Node binary | an embedded host binary | falls through to the desktop rules below, never `execPath` |
206
+ | DSH Desktop (Electron) | `DeepSeek Harness.exe` | the DSH **bundled runtime**, below |
207
+
208
+ The bundled runtime is
209
+ `<resources>/runtime/primary-runtime/dependencies/node/bin/node.exe` on Windows and
210
+ `…/bin/node` elsewhere (`packagedNodePath`). `<resources>` is `process.resourcesPath`
211
+ when the host exposes it; otherwise it is derived from the application executable as
212
+ `<dirname(execPath)>/resources` — the layout DSH Desktop installs into
213
+ (`…\DeepSeek Harness\resources\…` beside `…\DeepSeek Harness\DeepSeek Harness.exe`).
214
+
215
+ If the bundled runtime is not there, these environment variables are consulted **in
216
+ this order**, and the first usable one wins:
217
+
218
+ | variable | accepted when |
219
+ | --- | --- |
220
+ | `DSH_NODE_PATH` | an absolute path |
221
+ | `DSH_NODE_EXECUTABLE` | an absolute path |
222
+ | `CODEX_MCP_NODE_PATH` | an absolute path |
223
+
224
+ "Usable" is strict: the value must be **absolute**, its basename must be a Node
225
+ binary (`node`, `node.exe`, or a versioned `node-*.exe`), and `lstat` must report an
226
+ existing **regular file**. A relative path, a directory, a link and a missing file
227
+ are each rejected with a reason, and their rejection does not stop the next
228
+ candidate from being tried.
229
+
230
+ **Fail closed.** When no candidate is usable, `resolveNodeExecutable` throws
231
+ `CodexInstallError('MCP_EXECUTABLE_UNRESOLVED')`. The desktop application executable
232
+ and a bare `node` are never substituted. The status document reports this instead of
233
+ throwing: `mcp.node = null`, `mcp.nodeResolved = false`, `mcp.nodeError = { code,
234
+ message, details }`, `mcp.state = unreadable` (`reason: no-executable`), `ready =
235
+ false`, plus an `MCP_EXECUTABLE_UNRESOLVED` note. `install` and `repair` refuse the
236
+ MCP target with `MCP_EXECUTABLE_UNRESOLVED` and leave `config.toml` byte-identical;
237
+ the agent file is an independent target and is still installed.
238
+
239
+ ### 2.1 Classification
240
+
241
+ `classifyMcpEntry` locates the definition (block or inline), then decides:
242
+
243
+ | state | meaning | install |
244
+ | --- | --- | --- |
245
+ | `not-configured` | no `mcp_servers.dsh-delegate` at all | writes the block |
246
+ | `configured` | the marker is present **and** the values are exactly the owned shape | no change |
247
+ | `outdated` | marked owned command, but stale `args`/discovery/`tool_timeout_sec`; or the narrowly recognised 0.1.6 Desktop command with the current package `args` and owned env shape | rewrites only those values in place |
248
+ | `conflict` | anything else (`unmanaged-entry`, `unmanaged-entry-exact`, `command-not-ours`, `legacy-command-shape`, `url`, `unknown-field`, `extra-env`, `args-not-an-array`, `command-not-a-string`, `not-a-table`, `array-table`, and the boundary reasons below) | **refuses** with `MCP_ENTRY_CONFLICT` and a note explaining why; `repair` adds the marker for `unmanaged-entry-exact` only |
249
+
250
+ Every classification also reports **`drift`**: the list of owned facts that are stale
251
+ (`tool_timeout_sec`, `args`, `command`, `env`), or `null` when nothing is. The status
252
+ document publishes it as `mcp.drift`, and the note for an `outdated` entry names each
253
+ one, so neither the page nor a log line has to infer what a repair would change.
254
+
255
+ An `args[0]` that names `dsh-delegate-mcp.js` somewhere ELSE is a `conflict`
256
+ (`args-shape-not-ours`) in a bare status read: the synchronous classifier cannot prove that
257
+ a different path is this package, so it never labels one `outdated`. Only an explicit
258
+ `install`/`repair` may adopt it, after the asynchronous proof below — and only with the
259
+ config digest, the `$CODEX_HOME`/`skills`/`skills/dsh-taskbridge`/`agents` boundary and the current entry re-checked
260
+ immediately before the write. A different script name, a different command or an extra
261
+ argument stays `conflict` everywhere.
262
+
263
+ When `$CODEX_HOME`, `$CODEX_HOME/skills`, `$CODEX_HOME/skills/dsh-taskbridge` or `$CODEX_HOME/agents` is a link (or cannot be verified), the MCP
264
+ target is reported as `conflict` with `reason` `codex-home-is-link`, `skills-dir-is-link`, `skill-dir-is-link`,
265
+ `agents-dir-is-link` or `boundary-unverified` — the same verdict the skill target gets.
266
+ The entry is **not** read through the link, because a link bounds every write this
267
+ module makes, not only the skill file.
268
+
269
+ Two rules are deliberate:
270
+
271
+ * **`unmanaged-entry`.** Values alone never establish ownership. An entry without
272
+ the marker comment — even one whose `command`/`args` are byte-identical to what
273
+ the plugin would write — is the operator's. It is reported as a conflict, and
274
+ `install`, `repair` and `remove` all leave it byte-identical. The marker must be
275
+ the comment line directly above the definition (or above the `[mcp_servers]`
276
+ header when the definition is the inline `dsh-delegate = { … }` spelling); a
277
+ marker elsewhere in the file does not count.
278
+ * **`unmanaged-entry-exact`.** The same unmarked definition, but it already IS this
279
+ build's entry in every owned fact: `command` is the resolved Node executable, `args` is
280
+ exactly this installation's entry script, `tool_timeout_sec` is the owned integer, and
281
+ the `env` map is exactly the owned one (no additional key, none missing) — and the
282
+ definition is ONE unambiguous standard `[mcp_servers.dsh-delegate]` table with unique
283
+ keys. This is the configuration the settings page shows, entered by hand without the marker
284
+ comment. It stays a `conflict` for `status`, plugin startup and `remove`, but the reason
285
+ names it so that “仅修复 MCP 配置” (`repair`) may make ONE edit: insert the marker line
286
+ directly above the server's OWN header and change no other byte.
287
+ The write re-reads `config.toml`, requires the plan's digest, the boundary verdict, the
288
+ whole owned shape and this installation's exact script to still hold, and splices the
289
+ marker into the original text at the header line's character offset — so a BOM, mixed
290
+ CRLF/LF endings, an indented header, an operator comment above it and a missing final
291
+ newline all survive, and deleting the new line restores the file byte for byte. It then
292
+ verifies the marker is adjacent to the server's own header (never to a shared
293
+ `[mcp_servers]` parent, which would claim sibling entries), that the result classifies as
294
+ `configured`, and that the change is exactly that one line.
295
+ Refused, with the plain `unmanaged-entry` reason and a byte-identical file: any owned value
296
+ that differs; a duplicated key (the parser keeps every entry, so a merge would let the last
297
+ value win); an inline table beside or instead of the header; an extra or empty sub-table
298
+ such as `[mcp_servers.dsh-delegate.custom]`; a nested inline table value; an array table.
299
+ `install` never adds the marker.
300
+ * **`command-not-ours`.** A different command is a different program, so even
301
+ identical arguments do not make the entry ours. `extra-env` is symmetrical — an
302
+ `env` key the plugin did not write is the operator's data, and an entry carrying
303
+ one is reported as a conflict rather than pruned.
304
+
305
+ * **0.1.6 Desktop migration.** Version 0.1.6 could write the DSH Desktop GUI as
306
+ `command`. A marked entry is eligible for one automatic migration only when its
307
+ command has a path whose case-insensitive basename is exactly `DeepSeek Harness.exe`,
308
+ its `args` already name this installed package's `bin/dsh-delegate-mcp.js`, and its
309
+ env keys and values exactly match the currently owned shape. The installer then
310
+ reports `outdated` and replaces only the command with the proven Node runtime.
311
+ A bare GUI name, a similarly named executable, stale args, extra env or any other
312
+ command remains `conflict` and is left byte-identical.
313
+
314
+ ### 2.2 Merge mechanics
315
+
316
+ `src/codex/toml.js` locates structure by line and column ranges and edits only
317
+ those ranges. It is a locator, not a validating TOML implementation, and it
318
+ refuses (`TomlSyntaxError`, carrying a line number) rather than guess:
319
+
320
+ * an unterminated single-line string, array or inline table;
321
+ * a table header with trailing text;
322
+ * a raw control character (0x00–0x08, 0x0A–0x1F except tab) **anywhere other than
323
+ as a line ending** — see below;
324
+ * text after a table header, an unbalanced bracket, a key without `=`.
325
+
326
+ **CRLF.** A Codex config touched by a Windows editor is normally CRLF. The locator
327
+ splits on `\n` only, treats a *terminal* `\r` as the second byte of a line ending
328
+ (it is skipped wherever whitespace would end a token), and every mutation re-joins
329
+ with the document's detected ending. Installing, updating and removing an entry in
330
+ a CRLF file therefore preserves CRLF and leaves every unrelated byte — comments,
331
+ settings, table order — exactly as it was. A `\r` **inside** a line (a broken or
332
+ mixed-ending file) is still a control character and still refuses the document as
333
+ a whole.
334
+
335
+ A refusal makes the whole action refuse (`CODEX_CONFIG_UNSUPPORTED`) and leaves
336
+ the file byte-identical. Nothing is ever written with a parsed-then-serialized
337
+ round trip, so comments and ordering cannot be lost.
338
+
339
+ Writes land through `writeFileAtomic` (temp file + rename), so a crash leaves the
340
+ previous or the new full document, never a partial one. A *first* agent file is
341
+ created with `link`, which fails when the target exists: a file that appears
342
+ between the status read and the write is reported (`AGENT_PATH_CONFLICT`,
343
+ `created-concurrently`) instead of being replaced.
344
+
345
+ ### 2.3 Removal
346
+
347
+ `remove` deletes the `mcp_servers.dsh-delegate` table (header, assignments, child
348
+ tables and the plugin marker line) and the agent file when — and only when — that
349
+ file is the managed template or a byte-exact known prior build. Comments the
350
+ operator wrote *above* the marker stay; the marker itself is the plugin's line.
351
+ A `conflict` or `modified` target is reported and left untouched, including an
352
+ unmarked same-name entry. Removing twice is a no-op.
353
+
354
+ **The agent file is re-proved immediately before it is unlinked.** The status read
355
+ is stale by the time a removal runs: the operator, an editor or another tool may
356
+ have rewritten the file after the verdict. Deleting on the strength of that verdict
357
+ would destroy the new content, so `removeManagedAgentFile` reads the file again and
358
+ requires all of:
359
+
360
+ * it is still a **regular file** (not a link, not a directory) — otherwise
361
+ `AGENT_PATH_CONFLICT` (`reason: not-a-regular-file`);
362
+ * it still exists — otherwise `AGENT_PATH_CONFLICT`
363
+ (`reason: missing-before-removal`), reported as "no change", never as a deletion;
364
+ * its bytes are **exactly** the content the status derived its verdict from
365
+ (`agent.expect`) — otherwise `AGENT_USER_MODIFIED`
366
+ (`reason: modified-before-removal`) and the file is kept.
367
+
368
+ Only then is `unlink` called. A file that *looks* managed but differs by one
369
+ character is therefore refused, and an unlink the filesystem refuses (`EPERM`,
370
+ `EACCES`, `EBUSY`) is reported as `AGENT_PATH_CONFLICT` (`reason: unlink-refused`)
371
+ rather than thrown at the operator.
372
+
373
+ ### 2.4 The startup upgrade of an installed integration (1.2.0)
374
+
375
+ `refreshKnownAgentTemplate({ refreshMcp: true })` — reached through the seam as
376
+ `refreshManagedIntegration({ startupTarget, backupDir })` and called once by plugin
377
+ activation — checks the managed skill, legacy subagents and the MCP entry:
378
+
379
+ | target | condition | write |
380
+ | --- | --- | --- |
381
+ | Codex skill | `outdated` (known template or matching ownership record) | replaced with this build's template |
382
+ | Legacy subagents | a `managed-legacy` file still matches the bytes read during inspection | installs the skill if absent, then retires the legacy file once the current or user-edited skill is present |
383
+ | MCP entry | `outdated` **and** passing the write gate below | the owned values rewritten in place, in ONE atomic write |
384
+
385
+ The automatic check only ever accepts THIS installation's exact entry point. The
386
+ moved-install case (a recorded `args[0]` that is a different, provable installation of the
387
+ same package) is described below but is performed only by an explicit `install`/`repair`;
388
+ startup leaves it byte-identical and reports `conflict`.
389
+
390
+ #### The write gate (`isOwnedStaleEntry`)
391
+
392
+ "The classifier said `outdated`" is not permission to write. An automatic, unreviewed
393
+ write additionally requires that the entry is provably this plugin's in EVERY owned fact:
394
+
395
+ | fact | required |
396
+ | --- | --- |
397
+ | marker comment | present (authorship proof) |
398
+ | `command` | exactly this package's Node command (or the narrowed 0.1.6 Desktop command) |
399
+ | `args` length | exactly 1 — no wrapper flags, no extra arguments |
400
+ | `args[0]` | **provably** this package's entry point (see below) |
401
+ | `env` keys | none that this plugin did not write |
402
+
403
+ **`args[0]` must be PROVED, not pattern-matched** (`isOwnedEntryScript`, asynchronous
404
+ because the proof is a filesystem one). There are exactly two accepted proofs:
405
+
406
+ 1. **This installation's own file** — an absolute path that is the same location as this
407
+ package's `bin/dsh-delegate-mcp.js`, compared under the PLATFORM's case rules
408
+ (`samePlatformPath`). Linux compares exactly: two case variants are different programs
409
+ there. Windows is case-insensitive; macOS is treated the same way because its default
410
+ volumes are, which is an assumption rather than a promise on a case-sensitive volume. A
411
+ RELATIVE path is never equivalent: `relative/bin/dsh-delegate-mcp.js` names no location.
412
+ 2. **A different, real installation of this package** — an absolute path ending in
413
+ `<root>/bin/dsh-delegate-mcp.js` with ALL of:
414
+ * `<root>` and `<root>/bin` are real directories and not links (a junction is caught by
415
+ the same attribute read the boundary check uses);
416
+ * `<root>/bin/dsh-delegate-mcp.js` is a regular, non-link file that IS the candidate
417
+ (compared by `realpath`, so a link cannot smuggle in another program);
418
+ * `<root>/package.json` is a regular, non-link file that declares one of this project's
419
+ own package names (`"dsh-taskbridge"`, `"dsh-taskdispatch"`, or `"dsh-delegate"`),
420
+ carries this project's GitHub repository provenance (`https://github.com/ranranyya/{dsh-taskbridge,dsh-taskdispatch,dsh-delegate}`),
421
+ AND maps `bin["dsh-delegate-mcp"]` to that very entry. A
422
+ `./` prefix is allowed; an absolute path, a `..` segment, a trailing slash, a wrong
423
+ mapping, a missing mapping, a foreign repository or no `bin` object is refused.
424
+
425
+ The `<root>` is derived with the host's `dirname`/`basename` rules (`packageEntryRoot`), so
426
+ a POSIX leading `/` is preserved: splitting on `/` and rejoining would turn
427
+ `/opt/pkg/bin/dsh-delegate-mcp.js` into the relative `opt/pkg/...`, and no real Linux or
428
+ macOS installation could ever be proved.
429
+
430
+ Everything else — a wrapper that reuses the marker, the command or even the file name; a
431
+ same-layout script whose manifest maps its bin elsewhere; a missing path; a link; a
432
+ directory that declares another package — is **not** claimed. The synchronous classifier is
433
+ even stricter: only proof 1 can make an entry `outdated`, so a differing script is always a
434
+ `conflict` (`args-shape-not-ours`) and a bare status read can never authorize a write. Proof
435
+ 2 is attempted **only by an explicit `install`/`repair`**, never by the unattended startup
436
+ check, and it is re-run immediately before the write together with the plan's config digest
437
+ and the boundary re-check; an edit in that window is refused (`config-changed`).
438
+
439
+ An unprovable path is therefore KEPT and reported, with a note pointing at the explicit
440
+ button: this is the intended outcome, not a gap. The core upgrade — an exact `args` match
441
+ with only `tool_timeout_sec` missing — always succeeds automatically.
442
+
443
+ #### No concurrent change (`config-changed`)
444
+
445
+ The plan records a SHA-256 of the WHOLE `config.toml` (`mcp.fingerprint`, stripped from the
446
+ public status by `publicCodexStatus`). Immediately before the write the file is re-read and
447
+ the digest must match. Re-classifying alone is not enough: an operator can change an owned
448
+ value and leave an entry that still looks stale and managed, which is exactly the overwrite
449
+ this refuses. The result is `MCP_ENTRY_CONFLICT` with `reason: config-changed` and the file
450
+ is kept byte-identical. This is covered by a deterministic test that changes the file
451
+ between the plan and the write.
452
+
453
+ #### The backup is a PRECONDITION (`MCP_ENTRY_BACKUP_UNAVAILABLE` / `_FAILED`)
454
+
455
+ Before any automatic MCP write the current document is copied to a protected location, and
456
+ that copy is **verified**. It is not best-effort:
457
+
458
+ * no destination supplied → `MCP_ENTRY_BACKUP_UNAVAILABLE`, nothing written; a RELATIVE
459
+ destination is refused as well, because it would be resolved against the harness cwd;
460
+ * EVERY ancestor of the destination is proved to be a real directory — a symbolic link, a
461
+ Windows junction/reparse point, a component the platform cannot verify, or a file in the
462
+ chain refuses the whole backup, so a complete `config.toml` is never written through a
463
+ linked parent (a leaf-only check is not enough: `/safe/backup` can be a plain directory
464
+ below a junction);
465
+ * missing levels are created ONE at a time and each is inspected immediately afterwards; a
466
+ recursive `mkdir` would follow a link that appeared at any depth in the window;
467
+ * the chain is re-checked immediately before the copy is written, then the copy is written
468
+ atomically with owner-only permissions and RE-READ; a mismatch or a write failure →
469
+ `MCP_ENTRY_BACKUP_FAILED`, nothing written;
470
+ * an existing destination that is a link, a non-file, or holds different bytes is refused
471
+ rather than overwritten.
472
+
473
+ The seam supplies `<plugin dataDir>/codex-config-backup` by default, so a caller that passes
474
+ no location still gets one; a direct `refreshMcp` call with no trusted location refuses
475
+ instead of writing. The original file is always left exactly as it was on any refusal.
476
+
477
+ #### The rest of the guarantees
478
+
479
+ * an absent entry stays absent — the plugin never creates `config.toml` or the table at
480
+ startup, so an upgrade can never turn a non-installation into an installation, and the
481
+ same is true of `skills/` when neither the skill nor a recognized legacy companion is present;
482
+ * an unmarked entry, an operator-edited shape and any `conflict` are refused and left
483
+ byte-identical (the outcome carries `MCP_ENTRY_CONFLICT` with the reason);
484
+ * a link or unverifiable directory at `$CODEX_HOME` / `skills` / `skills/dsh-taskbridge` / `agents` is re-inspected immediately
485
+ before the write and produces ONE `AGENT_PATH_CONFLICT` refusal for the whole check, even
486
+ when the visible state shows nothing stale: an upgrade that cannot be proved safe must not
487
+ look successful;
488
+ * the pre-write document is copied to `backupDir` (the plugin data directory) first — never
489
+ into the package, never into the Codex home, and never returned in a response;
490
+ * nothing else in `config.toml` is touched: comments, ordering, other MCP tables, CRLF
491
+ line endings and every unrelated setting survive byte for byte.
492
+
493
+ #### Which home is targeted — ONE precedence for every seam call
494
+
495
+ `resolveHomePreference` is the single implementation, and `status()`, the explicit actions
496
+ and the automatic check all use it. Before that, the check consulted the recorded directory
497
+ while `status()` and the buttons consulted only `CODEX_HOME`/default, so removing
498
+ `CODEX_HOME` made the page report — and the buttons write — a different tree than the one
499
+ startup had just upgraded. The order is:
500
+
501
+ | precedence | target |
502
+ | --- | --- |
503
+ | 1 | an explicit `CODEX_HOME` (or the seam's explicit `codexHome`) |
504
+ | 2 | the home a SUCCESSFUL explicit install recorded in `<dataDir>/codex-installation.json` |
505
+ | 3 | the default (`~/.codex`), only when it exists and is a real directory |
506
+
507
+ A successful `install` records the directory even when it wrote nothing because the
508
+ installation was already exactly right: `changed: []` is a success, not "nothing happened".
509
+ A REFUSED install records nothing, so a refusal cannot become the remembered target.
510
+
511
+ In 1.5.1 the selected home root is pinned by the installer to its real target after this precedence resolution. A normal root symlink/junction is supported; an unresolvable or unverifiable target is refused. A missing home remains `no-codex-home`; a null startup target does not silently fall back to another tree. The root alias is preserved, and links below it in agents or the final files remain forbidden.
512
+
513
+ The explicit 「安装 / 更新 TaskBridge 技能」 button (action `install`) remains
514
+ the way to *create* the managed native skill (`skills/dsh-taskbridge/SKILL.md`) and MCP entry (and safely retire untouched legacy `agents/dsh-taskbridge.toml` / `agents/dsh-delegate.toml`). `status` reports the drift (`mcp.drift`)
515
+ and, when an entry is `outdated`, a note naming exactly which owned facts are stale.
516
+
517
+ ---
518
+
519
+ ## 3. Actions and their guarantees
520
+
521
+ Reachable only through the authenticated user plane (section 4) or the CLI
522
+ `bin/dsh-delegate-codex-agent.js`.
523
+
524
+ | action | writes | never writes |
525
+ | --- | --- | --- |
526
+ | `status` | nothing | anything |
527
+ | `install` | native skill `skills/dsh-taskbridge/SKILL.md` (absent / older managed build) + retires untouched legacy `.toml` subagents + MCP entry (absent / `outdated`) | a user-modified skill or legacy agent file, a conflicting MCP entry, the DSH switch |
528
+ | `repair` | the MCP entry only (absent / `outdated`), exactly as `install` would; plus the marker line for an `unmanaged-entry-exact` definition | the skill or legacy agent files: they are **not created, not refreshed and not deleted**, nor is `skills/` or `agents/` created; no owned value of an unmarked entry is ever rewritten |
529
+ | `remove` | deletes only owned skill, untouched legacy `.toml` files and owned MCP entry | a user-modified skill or legacy agent file, a conflicting entry |
530
+
531
+ `install` is idempotent: a second run with nothing changed reports
532
+ `changed: []` and does not rewrite either file.
533
+
534
+ `install` reports the agent and MCP targets independently. One may succeed while
535
+ the other is refused (for example: no agent file yet, but a conflicting entry), and
536
+ the response says exactly which. The same holds for an unresolvable executable:
537
+ the agent file is still installed, and the MCP half is refused with
538
+ `MCP_EXECUTABLE_UNRESOLVED` (section 2.1).
539
+
540
+ **`repair` is MCP-only.** It is the action behind the settings page's
541
+ 「仅修复 MCP 配置」 button and is the same code path `install` uses for its MCP half.
542
+ It never touches the agent file, so with a missing agent it reports
543
+ `agent.state = not-installed` and changes nothing, with an `outdated` agent it leaves
544
+ that file byte-identical (it stays `outdated`), and with a `modified`/`conflict` agent
545
+ it does not even report an agent refusal — the agent is simply out of this action's
546
+ scope. Concretely, `repair`:
547
+
548
+ * returns `changed` containing `mcp` (or nothing) and never `agent`;
549
+ * does not create `$CODEX_HOME/agents` when it is missing;
550
+ * still refuses a `conflict` MCP entry with `MCP_ENTRY_CONFLICT`, exactly like `install`.
551
+
552
+ Updating a stale agent is an explicit `install`, or the byte-exact startup refresh
553
+ described below.
554
+
555
+ **No action runs when the settings page opens, and package install writes nothing.**
556
+ The page's `init()` issues a `GET`; the three buttons are the only callers of the
557
+ `POST`.
558
+
559
+ **The single write at plugin load is the integration refresh.** `apply()` calls the
560
+ seam's `refreshManagedIntegration()` once — only when a Codex home directory exists — which
561
+ refreshes `skills/dsh-taskbridge/SKILL.md` when its complete bytes match a known prior build or recorded digest (and migrates/retires untouched legacy `agents/dsh-taskbridge.toml` / `agents/dsh-delegate.toml` matching `KNOWN_AGENT_TEMPLATES` or `codex-agent-ownership`), **and** upgrades an already installed
562
+ `mcp_servers.dsh-delegate` entry that is provably this plugin's and merely stale
563
+ (section 2.4). It never performs a first-time install when neither the skill nor a recognized legacy companion is present, never creates
564
+ the MCP entry, and never touches a `modified`/`conflict` file: everything else stays an
565
+ explicit `install`. A refusal or failure is logged and startup continues, so a Codex
566
+ problem cannot stop the plugin from loading.
567
+
568
+ ---
569
+
570
+ ## 4. Routes
571
+
572
+ One exact path, two methods, registered on `ctx.connection.fetch` (the
573
+ authenticated operator channel):
574
+
575
+ | method | path | body | result |
576
+ | --- | --- | --- | --- |
577
+ | `GET` | `/api/dsh-delegate/codex` | — | `{ ok, action: 'status', changed: [], refused: [], codex, switch }` |
578
+ | `POST` | `/api/dsh-delegate/codex` | `{ "action": "install" \| "repair" \| "remove" }` | `{ ok, action, changed, refused, codex, switch }` |
579
+
580
+ Refusals use the standard envelope and these codes: `CODEX_ACTION_INVALID` (400),
581
+ `CODEX_HOME_INVALID` (400), `CODEX_CONFIG_UNSUPPORTED` (409),
582
+ `CODEX_CONFIG_UNREADABLE` (409), `CODEX_INTEGRATION_UNAVAILABLE` (503). A refusal
583
+ *per target* is not an HTTP error: it appears in `refused[]` with a stable `code`
584
+ (`AGENT_USER_MODIFIED`, `AGENT_PATH_CONFLICT`, `MCP_ENTRY_CONFLICT`,
585
+ `MCP_SCRIPT_MISSING`, `CODEX_CONFIG_UNSUPPORTED`) and the action still answers 200
586
+ with the fresh status, because "I did not touch your file, and here is why" is a
587
+ successful diagnosis.
588
+
589
+ `codex` (status document):
590
+
591
+ ```jsonc
592
+ {
593
+ "codexHome": "…",
594
+ "packageVersion": "1.9.1",
595
+ "boundary": {
596
+ "blocked": false, "link": null, "unknown": false,
597
+ "home": "directory", "skills": "directory", "skillDir": "directory", "agents": "directory"
598
+ },
599
+ "skill": {
600
+ "path": "…/skills/dsh-taskbridge/SKILL.md", "state": "installed", "installed": true, "managed": true,
601
+ "reason": null, "expect": "<the exact bytes a refresh may replace>"
602
+ },
603
+ "agent": {
604
+ "path": "…/skills/dsh-taskbridge/SKILL.md", "state": "installed", "installed": true, "managed": true,
605
+ "reason": null, "expect": "<compatibility alias of skill>"
606
+ },
607
+ "legacyAgents": { "state": "absent", "entries": [] },
608
+ "mcp": {
609
+ "path": "…", "exists": true, "serverName": "dsh-delegate",
610
+ "state": "configured", "configured": true,
611
+ "previous": { "command": "…", "args": ["…"], "envKeys": [] },
612
+ "reason": null,
613
+ "marked": true,
614
+ "desired": { "command": "…", "args": ["…"], "env": {} },
615
+ "node": "…", "nodeResolved": true, "nodeError": null,
616
+ "script": "…", "scriptExists": true,
617
+ "discoveryFile": "…", "discoveryPinned": false
618
+ },
619
+ "config": { "readable": true, "error": null },
620
+ "ready": true,
621
+ "notes": [{ "code": "…", "text": "…" }]
622
+ }
623
+ ```
624
+
625
+ Agent states: `not-installed`, `installed`, `outdated`, `modified`, `conflict`.
626
+ MCP states: `not-configured`, `configured`, `outdated`, `conflict`, `unreadable`.
627
+ `unreadable` covers both "the config cannot be read safely" and — as of 0.1.7 —
628
+ "no Node.js executable could be proved" (`reason: no-executable`), in which case
629
+ `desired` is `null`, `node` is `null`, `nodeResolved` is `false` and `nodeError`
630
+ carries the `MCP_EXECUTABLE_UNRESOLVED` diagnosis (section 2.1).
631
+ Boundary kinds: `directory`, `missing`, `link`, `other`, `unchecked` (for the level
632
+ below a link, which is deliberately not inspected), and `unknown` when the platform
633
+ answer could not be obtained.
634
+
635
+ `boundary.blocked` is true when any checked boundary directory is a link or could not be verified;
636
+ `boundary.link` names the level (`codex-home`, `skills`, `skillDir` or `agents`) and is `null` otherwise.
637
+ `agent.reason` carries `codex-home-is-link`, `skills-dir-is-link`, `skill-dir-is-link`, `agents-dir-is-link` or
638
+ `boundary-unverified` in that case, so the page can say which boundary it refused.
639
+
640
+ `agent.expect` and `mcp.marked` are the two ownership facts: `expect` is what a
641
+ refresh compares against immediately before its rename, and `marked` is true only
642
+ when the entry carries the plugin marker (i.e. when a `remove` may delete it).
643
+
644
+ `switch` reports the DSH posture and always carries
645
+ `changedByThisAction: false`: no Codex action can authorize dispatch.
646
+
647
+ ---
648
+
649
+ ## 4.1 The preflight tool the skill depends on
650
+
651
+ `delegate_preflight` is a strictly read-only MCP tool that is not an
652
+ authorization at all: it is a read-only measurement of one workspace, added so a
653
+ dispatcher learns *before* submitting that a checkout is dirty, is not a
654
+ repository, or needs an isolation decision — instead of learning it from a job that
655
+ failed after admission.
656
+
657
+ | property | value |
658
+ |---|---|
659
+ | tool | `delegate_preflight` |
660
+ | arguments | `workspacePath` (string, required, absolute), `allowShared` (boolean, optional) |
661
+ | schema | closed: `additionalProperties: false`; `allowShared` must be a real boolean (`MCP_ARGUMENT_TYPE` otherwise, and the plane is never reached) |
662
+ | execution-plane route | `POST /dsh-delegate/x/workspace/preflight` |
663
+ | writes | nothing: no commit, stash, branch, worktree, lock, task, grant or setting |
664
+ | gate | transport fence + connection identity only — **not** the switch, because it authorizes nothing |
665
+
666
+ The answer is `{ ok, readOnly, workspacePath, isolation, reason, sharedExplicit,
667
+ decisionRequired, facts, guidance, checkedAt }` with `isolation` one of
668
+ `worktree` / `shared` / `block` and `reason` a stable `PREFLIGHT_*` code. The full
669
+ shape, the decision table and the four git reads it is allowed to issue are stated
670
+ in `docs/workspace-contract.md` §3.5; this document only records the contract the
671
+ agent file depends on.
672
+
673
+ The one rule a reviewer should check: **a dirty repository is never downgraded
674
+ automatically.** Without `allowShared` the answer is `block` with
675
+ `decisionRequired: true`; with `allowShared: true` — a per-call decision record,
676
+ never a stored preference — it is `shared` with `sharedExplicit: true`. The Codex
677
+ coordinator evaluates the requested task and changed paths and may decide to use
678
+ shared isolation without asking on every dispatch; it pauses when ownership or risk
679
+ is unclear. To make the actual job match that decision, `delegate_submit` passes
680
+ only `{ isolation: "shared" }` as an override. Provider, model, effort and timeout
681
+ remain those selected in the plugin settings.
682
+
683
+ ---
684
+
685
+ ## 5. Skill ownership & historical legacy TOML identities
686
+
687
+ From `1.9.0`, the active shipped file is the Markdown skill `$CODEX_HOME/skills/dsh-taskbridge/SKILL.md`
688
+ (with `<!-- dsh-taskbridge-version: 1.9.1 -->` and its content-addressed `rules-reference-<sha256>.md`).
689
+ Earlier `0.1.6`–`1.8.x` releases shipped a custom-agent TOML file:
690
+
691
+ ```toml
692
+ version = "1.0.0" # stamped from package.json in 0.1.6–1.8.x legacy builds
693
+ name = "dsh-delegate"
694
+ description = "…"
695
+ developer_instructions = """…"""
696
+ ```
697
+
698
+ Neither the active `SKILL.md` nor the historical `.toml` files contain an `[mcp_servers.*]`
699
+ table, because the session/agent uses the parent Codex `config.toml` MCP registration, and a
700
+ second definition would start a second server.
701
+
702
+ **Ownership is content identity, not a heuristic.** `readAgentState` reports:
703
+
704
+ * `installed` — same text (admitting only `\r\n` vs `\n` line-terminator spelling, rejecting lone `\r`) as the `SKILL.md` this build renders, with an intact matching reference file;
705
+ * `outdated` — same text as one of the enumerated `KNOWN_SKILL_TEMPLATES` (`1.9.0` prereleases) or a recorded `codex-skill-ownership` digest for THIS Codex home (section 5.0); meanwhile `legacyAgents` classifies untouched `0.1.6`–`1.8.x` `.toml` files against `KNOWN_AGENT_TEMPLATES` and historical `codex-agent-ownership` records as `managed-legacy` for automatic retirement;
706
+ * `modified`/`conflict` — everything else.
707
+
708
+ Every release from `0.1.10` through `0.1.13` changes only the version line in the
709
+ companion file, so those templates share one body and differ only in that stamped line.
710
+ `0.1.14` changes the body as well (the per-call decision rules below), which is why its
711
+ predecessor is enumerated as a pinned identity rather than rebuilt. The bytes are what
712
+ ownership is proved against, so every release is enumerated on its own:
713
+
714
+ | Release | Digest enumerated in `KNOWN_AGENT_TEMPLATES` |
715
+ | --- | --- |
716
+ | `0.1.10` | `fc7b27104dbb50f4e614cd4fd8df8db87fd8f59fcf2b3c27b412b49f8b89fbba` (packed CRLF) |
717
+ | `0.1.10` | `6583f08a3ec4912a875249e6b127357b41cc3f8bf388b8e5cadbbeff469349be` (same template, LF) |
718
+ | `0.1.11` | `b6ca7c3258fc00c1c1682abf099994b9f5abe650acc3ecf9635eec4a35520151` (packed) |
719
+ | `0.1.12` | `ff04a4bf2c09b97747f835770c837637869581bb13bad3b8a870a3e92218514f` (packed) |
720
+ | `0.1.13` | `b3a1d2f0520774c0066ea733f27fd47c67c5f5ac44394d0eec2564c7959700aa` (packed, 9191 bytes, CRLF) |
721
+ | `0.1.14` | `11379c0152f3fb2bd4da1170812e51fe68006d98f6378c720cbadcee9ee4750c` (packed) |
722
+ | `1.0.0` | `b1fd531598087564b26df14d3261515e961012f3fd010ea493f222da7bbaf415` (git release bytes, CRLF) |
723
+ | `1.0.0` | `0cce75574107049413f4ddbdf7d8e6cddea92d45a0c4e0fa41b169cb790e5e13` (same template, LF) |
724
+ | `1.0.0` | `a8c888afaa0a1a6a0abfcb56670ffbdb67697f07e54871ece78c8adffb15c149` (**legacy** pinned identity) |
725
+ | `1.0.0` | `f51831e2ff265c9ba63a4760e245787060de7bd91dcc9663a11729fb472e5f62` (**legacy** pinned identity) |
726
+ | `1.1.0` | `7d3ea5c54647a92cebaa0521741eb27f5141f7b2127b47009195fdb976dae4fb` (git release bytes, CRLF) |
727
+ | `1.1.0` | `93d580bd849bb6d2c30c2db6286695ef3e0356896a88e552abae5f03eafc7601` (same template, LF) |
728
+
729
+ The `1.0.0` and `1.1.0` **git-verified** identities come from the release commits
730
+ themselves — `git show 2750047:codex/dsh-delegate.toml` and
731
+ `git show 2d71708:codex/dsh-delegate.toml` — and are kept as fixtures
732
+ (`tests/fixtures/codex-agent-1.0.0.toml`, `…-1.1.0.toml`) that are never packed.
733
+
734
+ The two **legacy** `1.0.0` entries are NOT claimed to be the Git bytes: the fixture above
735
+ is what the release commit contains, and these digests do not match it. They are retained
736
+ because a released build enumerated them, so an installation created by that build stays
737
+ structurally refreshable instead of flipping to "somebody else's file". Labelling them
738
+ `legacy` is the point: keeping an old identity is conservative (an unrecognised file is
739
+ never adopted and never removable), while pretending it came from Git would be a false
740
+ claim.
741
+
742
+ `0.1.10` therefore carries **two** entries, because that release exists in two byte forms
743
+ and either one can be on disk: the CRLF file inside the packed
744
+ `dsh-delegate-0.1.10.tgz`, and the same template kept as LF text. Both are hashes of
745
+ actual published bytes — the LF digest is an exact identity, not a normalized comparison.
746
+ `0.1.11` was delivered as an uncommitted candidate plus a verified tarball (the last
747
+ commit, `a750c0b`, is `0.1.10`), so that digest is cited from the tarball and the saved
748
+ baseline rather than from a `0.1.11` commit. The `0.1.12` digest is likewise verified
749
+ against the `package/codex/dsh-delegate.toml` inside the packed
750
+ `dsh-delegate-0.1.12.tgz` and against the saved release baseline. No earlier digest was
751
+ removed or replaced when a later release was added, so a machine that skipped a release is
752
+ still migrated directly to this build.
753
+
754
+ `0.1.13` is the last release whose companion body is the older one: `0.1.14` added the
755
+ per-call permission decision rules, so the `0.1.13` bytes are **not** recoverable by
756
+ relabelling the current template and are enumerated as an exact identity instead. The
757
+ digest was verified against `package/codex/dsh-delegate.toml` inside the packed
758
+ `dsh-delegate-0.1.13.tgz` (9191 bytes, CRLF) and the file is kept as
759
+ `tests/fixtures/codex-agent-0.1.13.toml`, so the "unchanged `0.1.13` is refreshed" and
760
+ "edited `0.1.13` is preserved" cases are both driven by real published bytes.
761
+
762
+ **Line endings in classification vs. write/delete verification (`1.5.3+`).** Classification
763
+ (`sameAgentText` and `isKnownPriorTemplate`) folds `\r\n` to `\n` (while rejecting any leftover
764
+ lone `\r`, BOM, tab, trailing space, blank line or version edit) so uniform LF, uniform CRLF, and
765
+ mixed CRLF/LF spellings of the exact same published template are recognized without false conflicts;
766
+ new managed files are written in LF, and every overwrite or unlink still re-reads the file and
767
+ requires its exact raw bytes to match `expect`. Both LF and CRLF digests of historical releases
768
+ remain enumerated in `KNOWN_AGENT_TEMPLATES` / `KNOWN_SKILL_TEMPLATES` and pinned by
769
+ `tests/codex-integration.test.js` and `tests/codex-agent-line-endings.test.js`.
770
+
771
+ A digest is added only for a build that was actually packed and verified, and the
772
+ current template's digest is never in the list under an older label; the tests assert
773
+ both facts (`tests/codex-integration.test.js`, `tests/package.test.js`).
774
+
775
+ The 1.7.0 package recognized these two earlier companion versions, each in both
776
+ terminator spellings, and all four are exact identities like every entry above:
777
+
778
+ | Release | Digest enumerated in `KNOWN_AGENT_TEMPLATES` |
779
+ | --- | --- |
780
+ | `1.6.1` | `efdef5f6e6ebcb26590ca929e674391b3c4fcdb3c017714d2322615783fdf712` (all LF) |
781
+ | `1.6.1` | `5da9fd5eb5a89fd3c76365faca78b51e34233d993605f1b55dff4b07ceb88b80` (same template, CRLF) |
782
+ | `1.6.1-test.5` | `bf698c861e7e560c555f8350b711db88627dce4a8752b2cbebe8748b6d640d37` (the packed agent, LF) |
783
+ | `1.6.1-test.5` | `a45e12d0b234e80854e69429518a2def2d00338f968c2ecfc689307b792e4426` (same file, CRLF) |
784
+
785
+ Both carried the SAME instruction body in the 1.6.1 sources and differed only in the
786
+ stamped `version` line, so enumerating both avoided false `modified` conflicts on upgrade.
787
+
788
+ At plugin startup, an `outdated` agent is refreshed automatically only when its
789
+ bytes still match a known shipped build. This does not create a missing agent or
790
+ edit `config.toml`. A file with any other content is preserved, even when its
791
+ version line names an older release.
792
+
793
+ Since 1.2.0 the startup check has a second half: an **already installed** managed
794
+ `mcp_servers.dsh-delegate` entry that is merely `outdated` is upgraded in place (see
795
+ section 2.4). It is still not an install: no entry is created, and no entry the plugin
796
+ cannot prove it wrote is adopted or rewritten.
797
+
798
+ The version line is *never* the proof. A file that still starts with the managed
799
+ header, still contains the dispatch rules, but has an old or invented version line
800
+ and one edited body byte is the operator's: the digest no longer matches, so it is
801
+ `modified`, it is never refreshed, and it is never removed. Conversely a
802
+ byte-exact published build is refreshed and removable, as documented.
803
+
804
+ ### 5.0 The recorded template digest (future releases)
805
+
806
+ Enumerating every future release by hand does not scale, so one small record exists beside the
807
+ table: after an **explicit `install`** or the startup **`refreshKnownAgentTemplate`** has written
808
+ the agent file, and only when the file it re-reads is exactly the template this build renders,
809
+ the plugin stores the digest of those bytes.
810
+
811
+ * Path (1.9.0+ native skill): `<DSH_HOME>/data/dsh-delegate/codex-skill-ownership/<sha256 of the real home>.json` — one
812
+ file per pinned Codex home, named by a digest of that home so no case equivalence is ever
813
+ inferred and two homes can never collide. Legacy `<DSH_HOME>/data/dsh-delegate/codex-agent-ownership/`
814
+ records remain readable so untouched pre-1.9.0 `.toml` subagents migrate cleanly.
815
+ * `npm run build:integrations` assembles `SKILL.md` and its rules reference from the shared
816
+ Layer 2 rules in `integrations/core/` through the Layer 1 Codex adapters.
817
+ * Content: `{ "schemaVersion": 1, "codexHome": "<real home>", "templateLfSha256": "<64 hex>" }`.
818
+ The digest is **LF-normalized** (the CRLF/LF spelling is not content, exactly as the table
819
+ treats it), and it is the only digest. No template body, no `config.toml`, no model
820
+ setting, no version, no timestamp, no credential.
821
+ * A file whose digest equals that value is `outdated`. One changed character — an added line, a
822
+ tab, or a rewritten `version` line — hashes differently and stays `modified`.
823
+ * The record is read only: `status`, `repair` and `remove` never write it. A record reached
824
+ through a link or reparse point, missing, unreadable, malformed, over 4 KB, or naming a
825
+ different home is **no record** — the file is then classified by its content alone. A read
826
+ never creates the record directory; a write proves each level first and is atomic, owner-only,
827
+ and read back. An unchanged record is not rewritten. A `DSH_HOME` override must be absolute;
828
+ without one the `~/.dsh` default applies.
829
+ * A failure to record costs the next release one enumeration. It never fails an install and
830
+ never changes how a file is classified.
831
+
832
+ The version line is *never* the proof. A file that still starts with the managed
833
+ header, still contains the dispatch rules, but has an old or invented version line
834
+ and one edited body byte is the operator's: the digest no longer matches, so it is
835
+ `modified`, it is never refreshed, and it is never removed. Conversely a
836
+ byte-exact published build is refreshed and removable, as documented.
837
+
838
+ ### From the project plan to a DSH assignment
839
+
840
+ Codex checks the relevant code and earlier deliverables before deciding the next
841
+ step. It tells the operator which packet is ready, how it will work, and what it
842
+ will reuse. The `delegate_submit.prompt` carries the plan DSH executes. Include the
843
+ starting point, implementation order, scope and evidence for acceptance. For
844
+ multi-stage work, keep dependencies and reviewed progress in the existing plan tree.
845
+ The worker handles routine implementation choices and reports verified facts that
846
+ would change the agreed approach. Codex reviews the evidence before advancing
847
+ work that depends on it.
848
+
849
+ ### 5.1 Required dispatch semantics
850
+
851
+ The instructions must state all of the following. They are asserted in
852
+ `tests/codex-integration.test.js` and `tests/package.test.js`, so an edit that drops
853
+ one fails the build:
854
+
855
+ 1. **Explicit assignment only.** Dispatch only when the user explicitly
856
+ selects this skill (`$dsh-taskbridge`) or explicitly asks to delegate a Git
857
+ repository code implementation or verification task to DSH / TaskBridge.
858
+ 2. **Mention is not dispatch.** Text that merely mentions DSH, DeepSeek,
859
+ dsh-delegate, delegation or the agent while asking something else is not a
860
+ dispatch request, and neither is a question about the plugin, its settings or
861
+ its status.
862
+ 3. **No dispatch for non-implementation work.** Explanation, planning,
863
+ review-only, summarising and status questions are answered in Codex.
864
+ 4. **Ambiguity is a question.** If it is unclear whether the task was assigned, ask
865
+ once instead of dispatching.
866
+ 5. **Switch first, facts second.** Call `delegate_status` first (once per session); then call
867
+ `delegate_preflight` with the exact authorized workspace path (or pass `autoPreflight: true, wait: true` on `delegate_submit` for a normal single-repo dispatch, resuming via `delegate_wait` on `submitReceipt.taskId` if `submitted: true` returns with `waitError`). If either fails,
868
+ the tool is missing, the switch is off, or the answer is ambiguous, stop and
869
+ report the bounded refusal. Leave the switch as set and use only the authorized
870
+ TaskBridge execution path.
871
+ 6. **The isolation is decided from the measured facts, and never downgraded.**
872
+ `delegate_preflight` returns `isolation` (`worktree` / `shared` / `block`) and a
873
+ stable `reason` code:
874
+ * `worktree` (`PREFLIGHT_CLEAN_REPOSITORY`) — a clean repository; dispatch with
875
+ the worktree isolation selected in the plugin settings, unchanged.
876
+ * `block` + `decisionRequired: true` (`PREFLIGHT_DIRTY_NEEDS_DECISION`) — the
877
+ checkout is dirty, so a worktree cannot be prepared from a commit. The agent
878
+ must **not** silently downgrade and must **not** probe by submitting. As
879
+ coordinator, it inspects the changed-file count and bounded path list and
880
+ decides whether this authorized task can safely run in place while preserving
881
+ the existing changes. It need not ask the operator to choose on every dispatch:
882
+ it states a safe shared decision and its reason before dispatch, re-runs the
883
+ preflight with `allowShared: true`, and proceeds only if the answer is `shared`
884
+ (`PREFLIGHT_DIRTY_SHARED_EXPLICIT`). If ownership, overlap or risk is unclear,
885
+ it pauses for one focused question.
886
+ * `block` for any other reason (`PREFLIGHT_GIT_UNAVAILABLE`,
887
+ `PREFLIGHT_NOT_A_REPOSITORY`, `PREFLIGHT_NO_COMMITS`, `PREFLIGHT_GIT_FAILED`,
888
+ `PREFLIGHT_WORKSPACE_INVALID`, `PREFLIGHT_NOT_A_DIRECTORY`) — stop and report
889
+ the code; no fallback exists.
890
+ 7. **The dispatch text carries the workspace facts and the isolation reason.** A
891
+ shared run is named as such, because the worker writes into a checkout that
892
+ already has uncommitted work.
893
+ 8. **Route settings stay in the plugin.** For `worktree`, call `delegate_submit`
894
+ without `overrides` so the configured isolation applies. For an explicitly chosen
895
+ `shared` run, pass only `{ isolation: "shared" }` as the per-task override because
896
+ the plugin may still be configured for `worktree`. Never override provider,
897
+ model, effort or timeout, and never encode a route in the prompt. `allowShared`
898
+ on preflight records the decision but does not change the submitted job's
899
+ isolation by itself.
900
+ 9. **One task, WAITED — not polled (1.1.0).** Keep the returned `taskId` and call
901
+ `delegate_wait({ taskId })` — with no `waitSeconds` argument — repeating it until it
902
+ returns a reason that needs the host. `delegate_result` is **not** a polling loop: one
903
+ `delegate_wait` blocks internally and re-issues its own bounded observation requests,
904
+ which is the waiting loop. Never submit a duplicate because a task is still running;
905
+ `delegate_cancel` stops it. The wait defaults to 3600 seconds and the tool caps it
906
+ there, so there is nothing to raise: when a wait ends, call it again on the same task.
907
+ A shorter explicit `waitSeconds` stays legal but is only for a one-off diagnostic the
908
+ operator explicitly asked for.
909
+ While the wait runs, stay silent: do not read intermediate code or diffs, do not run
910
+ parallel implementation or research, and do not narrate unchanged snapshots. The only
911
+ exceptions are work explicitly assigned as independent of the task, an inspection the
912
+ operator explicitly asked for, a decision or diagnosis that genuinely needs a fact the
913
+ wait did not return, and an explicit user-authorized takeover. Review happens once, on
914
+ delivery.
915
+ `heartbeat` means "nothing to report" and is internal: the tool re-waits rather than
916
+ handing it to the model, so normal progress never wakes Codex.
917
+ The roughly 25-second internal observation cadence belongs to the program, not to the
918
+ agent: it is not a polling rate the model should imitate.
919
+ 10. **Each wait reason has a stated policy (1.1.0+; delivery interval 40 min default from 1.7.0).**
920
+ - `attention` — either the run progress check (no new result delivered back to the host for the
921
+ operator-configured progress-check interval — **40 minutes by default**, adjustable or
922
+ disableable) or a `repeated-tool-failure` reminder. It does **not** mean an ordinary wait
923
+ ended: a wait ending is `wait-limit`. It is a QUESTION, not a verdict: read the compact
924
+ diagnostic (phase, last activity, current tool and its elapsed time, self-check
925
+ verdict) and **default to waiting again** on the same task. Never cancel, never mark
926
+ failed, and never resubmit merely because a task is quiet or one tool or test is
927
+ slow. Only a concrete, stated error justifies anything else, and then it is reported
928
+ rather than silently restarted.
929
+ - `permission` — a per-call decision is outstanding; see item 12. After deciding,
930
+ wait the SAME task again.
931
+ - `ready` — execution finished and the task awaits **host review**; that is not
932
+ acceptance. Read `delegate_result` **once** for full evidence and review it in
933
+ Codex. A large diff is inspected file by relevant file, once each, not re-read.
934
+ - `failed` / `cancelled` — read `delegate_result` once for the recorded reason and
935
+ report it; do not resubmit identical work hoping for a different outcome.
936
+ - `wait-limit` — this call's own wait budget ran out with nothing changed. The answer
937
+ carries `actionable: false` and `terminal: false`: it is not a result, requires no
938
+ business decision, and ends nothing. Immediately `delegate_wait` the same task
939
+ again (no `waitSeconds`). It is not a failure, a stall, or a reason to submit
940
+ anything new or to check the implementation locally.
941
+ A **client-side tool timeout** is a different event and is *not* `wait-limit`: the
942
+ host's own limit ending the call does not prove the execution stopped, and does not
943
+ prove it is alive. Keep the `taskId` and wait again; if a compact fact is genuinely
944
+ needed, read it with `delegate_result`. Never duplicate, restart or cancel a task
945
+ because a wait or a client timeout ended.
946
+ - `interrupted` — **the wait was cut off; that is not by itself a finished
947
+ execution.** One call answers it at once (it does not loop), so the answer's own
948
+ fields decide the response (1.2.0):
949
+ * `terminal: false` with a live `state` (`running`/`pending`): the task is running.
950
+ `delegate_wait` the same task; never resubmit, never implement locally, never
951
+ cancel for this reason.
952
+ * `terminal: true` and `state: "interrupted"`: the TASK record itself is a restart
953
+ history and will not resume. Read `delegate_result` once and report; do not keep
954
+ calling `delegate_wait` on it.
955
+ * `terminal: false` with no state, an unrecognized state, or a state that
956
+ contradicts the record (for example `running` with an end time): neither
957
+ "running" nor "stopped" may be assumed. Keep the task id and check one fact with
958
+ `delegate_result` before deciding — and do not re-wait indefinitely on a task the
959
+ host cannot classify.
960
+ A settled state carried by an `interrupted` observation is reported as that real
961
+ outcome (`awaiting-host-review` → `ready`), so a completed run always reaches review.
962
+ 10b. **When the host blocks the connection, the control channel is separate (1.2.0).**
963
+ Some hosts forward one tool call at a time, so a long `delegate_wait` blocks
964
+ `delegate_status`/`delegate_cancel` on that same MCP connection. When — and only
965
+ when — the operator asks to stop or inspect that task in that situation, the agent
966
+ may run `dsh-delegate-control status <taskId>` or
967
+ `dsh-delegate-control cancel <taskId>` from the SAME package directory as the
968
+ configured MCP script (derived from this plugin's own MCP `args[0]`, never another
969
+ script), using the same `node` executable. It cannot submit, change a setting or
970
+ the switch, act on another task, resubmit the work or switch models, and during a
971
+ normal wait it stays silent instead of polling that binary.
972
+
973
+ What the command guarantees, so the expected output is never mistaken for a hang:
974
+ `status` reads the task's CURRENT compact state through ONE observation with the
975
+ smallest positive wait (`waitMs: 1`) — not `waitMs: 0`, which the engine reads as
976
+ "no bound requested" and replaces with a 25-second long poll. The commands answer
977
+ inside a single budget (10 s by default; `DSH_DELEGATE_CONTROL_TIMEOUT_MS` may only
978
+ lower it), enforced through one caller `AbortSignal` with the observation retry
979
+ disabled for that call, so a dead endpoint cannot spend a backoff schedule after
980
+ the answer. A failure — including an exhausted budget, `CONTROL_TIMEOUT` — is one
981
+ bounded JSON document on stdout plus a non-zero exit code, never a stack trace.
982
+ 11. **Evidence, not approval.** Return state, the actual provider/model/effort,
983
+ changed-file summary, verification evidence, limitations, and the preflight
984
+ facts with the isolation reason actually used. Executing is not accepting:
985
+ Codex remains responsible for review. Do not claim a check passed without
986
+ evidence, and never commit or push.
987
+ 12. **The workspace is not tidied up to pass a check.** No commit, stash, branch,
988
+ worktree creation, `clean`, `reset` or revert on the operator's behalf. A dirty
989
+ workspace is an isolation decision for the coordinator; pause only when the
990
+ existing edits' ownership or risk is unclear.
991
+ 13. **A task awaiting a permission decision is still running, and the coordinating
992
+ Codex decides it.** A wait reporting `permission` (with the full redacted request
993
+ at the top level) is the worker paused on one native tool call, not a
994
+ stall: never submit a duplicate, mark it failed, or cancel it merely because it
995
+ waits, and keep waiting the SAME task. The agent does **not** invoke a second
996
+ approval/review model, does **not** ask the operator to choose routine within-task
997
+ decisions, and does **not** delegate the decision to the worker. The worker's own
998
+ `reason` is a claim, never authority. It checks the actual tool, redacted
999
+ arguments, call identity, session and repository against the authorized task,
1000
+ reading local evidence when it needs to understand an executable script or target,
1001
+ and approves only the specific operation the task needs — refusing anything
1002
+ unrelated, destructive or exfiltrating, any credential or configuration change, and
1003
+ any request whose evidence is unknown or materially incomplete. An allow requires
1004
+ `argumentsComplete: true`, `completeness: complete`, `allowBlocked: null`, no
1005
+ transport truncation affecting the pending operation, a still-pending request and
1006
+ its exact `fingerprint`, passed to `delegate_permission_decide` with the `taskId`,
1007
+ `requestId`, `decision` (`allow-once`/`reject`) and a bounded `reason`. An invalid or
1008
+ stale allow grants nothing: re-read the current request and decide safely, and never
1009
+ retry under broader settings. Resume waiting on the same task after the decision.
1010
+ Each approval covers one call (`scope: "once"`). The release treats the preview
1011
+ value `scope: "task-command"` on an `allow-once` request as a single-call approval.
1012
+ Make a fresh decision for each subsequent approval request. When dispatching on
1013
+ behalf of a parent commander, preserve the complete request evidence for that commander.
1014
+ 14. **No local implementation while a delegated worker runs (1.1.0).** Neither the
1015
+ dispatch companion nor the parent commander writes, patches or "just fixes" the
1016
+ implementation while a delegated task is running, waiting, or awaiting review: that
1017
+ would make the reviewer a second implementer of the same change, produce conflicting
1018
+ edits in one workspace, and break the single-writer property the isolation mode
1019
+ provides. The only exception is an explicit, user-authorized takeover — the operator
1020
+ saying to take over and implement it here. A long silence, a permission refusal, a
1021
+ failed run, a wait-limit or the commander's own opinion of the plan is **not** that
1022
+ authorization. Permitted local actions while a task runs are: reading status and
1023
+ diagnostics, waiting, reading evidence, deciding a pending permission, cancelling,
1024
+ and writing the follow-up prompt. A believed-wrong result is reported and proposed
1025
+ as a follow-up in the same chain, never applied locally.
1026
+ 15. **No secrets.** Never read, request, store or relay provider credentials or
1027
+ connection tokens.
1028
+ 16. **Task threads are explicit.** A submission starts a NEW DSH task conversation
1029
+ by default; a directory-level reuse setting no longer exists. `continueFromTaskId`
1030
+ is passed **only** for a follow-up change, correction or retry that belongs to one
1031
+ earlier delegated task, and its value is the latest prior task id of that chain.
1032
+ An unrelated task, a new topic or a different workspace omits `continueFromTaskId` entirely:
1033
+ an id is never reused "to keep context" and never guessed. For a new dependent multi-stage subtask that starts a fresh DSH Session directly on an earlier accepted isolated worktree under the same source repository, pass `reuseWorktreeFromTaskId` instead (never combined with `continueFromTaskId`). A follow-up to a
1034
+ `worktree` task keeps its original source `workspacePath` for preflight and
1035
+ submit; the plugin resolves the same internal tree and continues its earlier
1036
+ uncommitted changes there. Never send the tree's internal execution path as the
1037
+ authorization path or choose a new isolation override. A refusal naming an
1038
+ unavailable or mismatched tree is reported and escalated, never worked around
1039
+ by re-submitting as a new task. The run's report states which of the two happened.
1040
+ Corrections are consolidated into one follow-up submission rather than a scatter of
1041
+ new tasks.
1042
+
1043
+ ### 5.2 Native Skill invocation (`$dsh-taskbridge`, 1.9.0+) vs. legacy `@` selection
1044
+
1045
+ From `1.9.0`, TaskBridge installs a **native Codex Skill** at
1046
+ `$CODEX_HOME/skills/dsh-taskbridge/SKILL.md`. An explicit `$dsh-taskbridge` activation or request
1047
+ to delegate to DSH / TaskBridge loads the entry. The active Codex session calls `delegate_submit` + a single direct `delegate_wait` chain without spawning
1048
+ a `spawn_agent` / `wait_agent` polling wrapper.
1049
+
1050
+ For pre-1.9.0 legacy subagent installations (`$CODEX_HOME/agents/dsh-taskbridge.toml`), this
1051
+ plugin never claimed `@dsh-taskbridge` picker support across all Codex builds. A new Codex session
1052
+ (or restart) is required after install or migration so Codex reloads the native skill and MCP entry.
1053
+
1054
+ ---
1055
+
1056
+ ## 6. Failure modes a reviewer should check
1057
+
1058
+ | Situation | Expected |
1059
+ | --- | --- |
1060
+ | `CODEX_HOME` relative | 400 `CODEX_HOME_INVALID`; nothing read or written |
1061
+ | `CODEX_HOME` unset | diagnosed against `~/.codex` |
1062
+ | `$CODEX_HOME` is a normal symlink or Windows junction | pin and verify its real directory target, preserve the root alias, then apply the same managed-content checks; broken or unverifiable targets are refused |
1063
+ | `$CODEX_HOME/skills`, `skills/dsh-taskbridge`, or `agents` is a symlink or Windows junction | `conflict` (`skills-dir-is-link` / `skill-dir-is-link` / `agents-dir-is-link`); install/repair/remove refuse with `AGENT_PATH_CONFLICT` and no file is created outside the home |
1064
+ | an ordinary real Windows directory | `directory` in every spelling of the helper's boolean (`dir/False`, `dir/false`); never reported as a link |
1065
+ | `repair` with the skill file missing or `outdated` | `changed: ["mcp"]` or `[]`; the skill file is not created and not refreshed, and neither `skills/` nor `agents/` is created |
1066
+ | the boundary cannot be verified (no spawnable shell / no PowerShell) | `conflict` (`boundary-unverified`); everything refused, nothing assumed safe |
1067
+ | `skills/dsh-taskbridge` dir missing | created on explicit `install` (`0700`) when the boundary is clean |
1068
+ | `skills/dsh-taskbridge/SKILL.md` is a symlink or a directory | `conflict`; untouched |
1069
+ | a different skill file appears between status and install | `modified`; untouched (first install is exclusive) |
1070
+ | a skill file is rewritten between the status read and `remove` | `AGENT_USER_MODIFIED` (`modified-before-removal`); the new bytes are kept |
1071
+ | the skill path is replaced by a directory / a link before `remove` | `AGENT_PATH_CONFLICT`; the entry is left in place |
1072
+ | an edited skill file with an old version comment | `modified` (`reason: edited` if body matches current template); never refreshed, never removed |
1073
+ | a byte-exact previously published skill or legacy `.toml` | `outdated` / `managed-legacy`; refreshed/migrated on install or startup refresh, removed on `remove` |
1074
+ | `config.toml` is a symlink | `unreadable`; refused |
1075
+ | `config.toml` > 1 MiB | refused (`other`), untouched |
1076
+ | `config.toml` contains a NUL / control character | `CODEX_CONFIG_UNSUPPORTED`, untouched |
1077
+ | `config.toml` uses CRLF | edited in place; CRLF and every unrelated byte preserved |
1078
+ | an unmarked same-name `mcp_servers.dsh-delegate` entry | `conflict` (`unmanaged-entry`); byte-identical after install/repair/remove |
1079
+ | an unmarked entry that is EXACTLY the owned entry (same command, single script argument, timeout and env) in one unambiguous standard table | `conflict` (`unmanaged-entry-exact`); byte-identical after install/remove, and `repair` adds the one marker line |
1080
+ | an unmarked entry with a duplicated key, an inline table beside the header, or an extra/empty sub-table | `conflict` (`unmanaged-entry`); byte-identical after install/repair/remove |
1081
+ | entry added between the read and the write | re-classified; refused if it stopped being ours |
1082
+ | package `bin/dsh-delegate-mcp.js` missing | MCP refused (`MCP_SCRIPT_MISSING`), agent still installed |
1083
+ | plain Node.js host (`process.execPath` is a Node binary) | `command` is that path; no override is consulted |
1084
+ | DSH Desktop host (`process.versions.electron` set) | `command` is the bundled runtime, **never** `DeepSeek Harness.exe` |
1085
+ | desktop host that exposes no `resourcesPath` | `<dirname(execPath)>/resources` is derived and the bundled runtime is used |
1086
+ | bundled runtime missing, `DSH_NODE_PATH` set to an absolute existing file | that file is written as `command` |
1087
+ | an override that is relative / a directory / a link / missing | ignored; the next candidate is tried, and the reason is kept in `nodeError.details.rejected` |
1088
+ | no candidate can be proved | status: `mcp.node = null`, `nodeResolved: false`, `ready: false`; install/repair refuse `MCP_EXECUTABLE_UNRESOLVED`; `config.toml` byte-identical; agent file still installed |
1089
+ | no candidate can be proved, an owned entry already points at a stale command | left as written (nothing is guessed); the note names the environment variable to set |
1090
+ | DSH has no execution plane (public bind) | unchanged by this feature; delegation still refuses |
1091
+ | the agent is asked to dispatch into a dirty repository | `delegate_preflight` answers `block` / `PREFLIGHT_DIRTY_NEEDS_DECISION`; the coordinator evaluates the listed paths and task, then either reports and dispatches with an isolation-only `shared` override or pauses when risk/ownership is unclear |
1092
+ | the agent is asked to dispatch into a non-repository or commit-less directory | `block` with the matching `PREFLIGHT_*` code; the agent stops and reports it rather than submitting |
1093
+ | the workspace path is relative, missing or a file | `block` / `PREFLIGHT_WORKSPACE_INVALID` or `PREFLIGHT_NOT_A_DIRECTORY`; nothing is resolved against the process cwd |
1094
+ | `delegate_preflight` is called while the switch is off | answered normally: it authorizes nothing, and that is when a coordinator needs it most |
1095
+ | `delegate_preflight` is sent `allowShared: "true"` | `MCP_ARGUMENT_TYPE`; the plane is not called |
1096
+ | `delegate_submit` is called twice for one directory | two Sessions in one Workspace: a new submission never continues a previous one |
1097
+ | `delegate_submit` sends `continueFromTaskId` for an unknown, pruned or live parent | the run fails with `JOB_CONTINUATION_REFUSED` and `error.details.session` = `SESSION_CONTINUATION_UNKNOWN` / `SESSION_CONTINUATION_STATE`; no conversation is started |
1098
+ | a follow-up names a parent that ran elsewhere (another directory, another worktree, another repository) | `JOB_CONTINUATION_REFUSED` with `SESSION_CONTINUATION_PATH_MISMATCH` / `SESSION_CONTINUATION_WORKSPACE_MISMATCH`; nothing runs |
1099
+ | a follow-up to a `worktree` task is submitted with the source checkout | accepted: the source path remains the authorization/preflight path, and the engine restores the parent's exact managed tree internally |
1100
+ | a follow-up's recorded tree was removed or belongs to another run | `SESSION_CONTINUATION_UNAVAILABLE` with the stated reason; no fresh tree is prepared |
1101
+ | `continueFromTaskId` is not a string | refused at the MCP schema (`MCP_ARGUMENT_TYPE`) and again by the engine (`JOB_CONTINUATION_REFUSED`) |
1102
+ | the settings page is asked to save a conversation mode | `setConversation` refuses with `CONVERSATION_MODE_REMOVED`; the stored legacy value is untouched and still inert |