dsh-taskbridge 0.0.0-stage → 1.3.2

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