dsh-taskbridge 1.5.0 → 1.5.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.
@@ -365,6 +365,64 @@ export const KNOWN_AGENT_TEMPLATES = [
365
365
  // Exact installed test.2 package verified by the coordinator before 1.5.0.
366
366
  { version: '1.4.3-test.2', sha256: 'a761461a769b8f297be0e4b7bb68de591918d5afa74a8348e9d475c87011a967' },
367
367
  { version: '1.4.3-test.2', sha256: '75ee69400e040d8e18542121a0a49467539368cc0205cc120785b62b6692e16d' },
368
+ // Exact published 1.5.0 template — the file an existing 1.5.0 installation holds when
369
+ // the build that teaches the repeated-failure acknowledgment starts. The instruction
370
+ // body changed in this working tree (the `failure` block gained its `eventId`, the
371
+ // redelivery rule and the `ackFailureEventId` acknowledgment), so 1.5.0's bytes are a
372
+ // DISTINCT published build that has to be enumerated: without them every untouched
373
+ // 1.5.0 install would be reported `modified` ("somebody else's file") and never
374
+ // refreshed. Both byte forms are enumerated, exactly like every other release:
375
+ //
376
+ // * `4af78cd2…` — the LF form as the release committed it (`git show
377
+ // 6d1eef9:codex/dsh-taskbridge.toml`, 32100 bytes, version = "1.5.0").
378
+ // * `253a6958…` — the same text with every `\n` turned into `\r\n` (32521 bytes), the
379
+ // uniform CRLF form a Windows install writes.
380
+ //
381
+ // Both are exact content identities computed from the committed blob, never derived
382
+ // from the NEW template: an operator-edited file still hashes to something unknown and
383
+ // is left alone.
384
+ { version: '1.5.0', sha256: '4af78cd2afb3d739d2f73ad8c21893b7e6434d0d06508b19fe36e9ba8012667b' },
385
+ { version: '1.5.0', sha256: '253a695842e9634e28e86030c7ffb10d21b338f09451a8c13849cfce1d9d9364' },
386
+ // The INSTALLED local test build `1.5.1-test.1`. Its identity is not a guess: the bytes
387
+ // are the template that build's own product package shipped, rendered by the SAME
388
+ // renderer this module uses, and they were compared byte-for-byte with the file actually
389
+ // installed on the operator's machine.
390
+ //
391
+ // * `1995032a…` — the LF form (40220 bytes, `version = "1.5.1-test.1"`).
392
+ // * `287be66f…` — the same text with every `\n` turned into `\r\n` (40266 bytes), which
393
+ // is exactly what is installed on Windows.
394
+ //
395
+ // Without these two, an untouched test.1 install hashes to "unknown content" and is
396
+ // reported `modified`, which is what made the upgrade to test.2 impossible. Only these
397
+ // exact bytes qualify: a single edited character still hashes to something unknown and
398
+ // stays the operator's file.
399
+ { version: '1.5.1-test.1', sha256: '1995032ab0794404d243f34d97478021c435fda1d584254cb1b70fcbe5432970' },
400
+ { version: '1.5.1-test.1', sha256: '287be66fb4e9d4623d4384545a990c267bf5f5aeede68acc9965c1b442d38ceb' },
401
+ // A LOCAL artifact of this operator's machine, NOT a published release identity.
402
+ //
403
+ // What it is: when this machine's plugin was upgraded to `1.5.1-test.2`, the running
404
+ // module still answered the CACHED old version, so the integration was written with the
405
+ // CURRENT template body but `version = "1.5.0"` stamped in it. The reference is that
406
+ // product template rendered by this module's own renderer with that stale version, and
407
+ // it was compared byte-for-byte with the file actually installed here.
408
+ //
409
+ // Why it must be enumerated: the next start reads the REAL manifest, so without these
410
+ // bytes the operator's freshly written file would be classified `modified` — a
411
+ // self-inflicted false conflict after every update. The version line is the ONLY thing
412
+ // that makes it distinct from a real 1.5.0 build, which is exactly why it is matched by
413
+ // exact content and nothing else: any edit (or any other template) still hashes to an
414
+ // unknown value and stays the operator's file.
415
+ //
416
+ // * `da2f428f…` — LF form (39,743 bytes).
417
+ // * `f55893e7…` — the installed CRLF form (40,259 bytes).
418
+ { version: '1.5.0', sha256: 'da2f428f726ae64b6895941d5238516346af91b63b038b1d57787be327fb28ee' },
419
+ { version: '1.5.0', sha256: 'f55893e7605627c6f0c9a4c55f58a5a1956d4c11b8c03c99569dca241842d8bb' },
420
+ // Exact locally installed test.3 product template, verified before preparing 1.5.1.
421
+ { version: '1.5.1-test.3', sha256: 'dc1c17f3bdfe171d3c1e7f943d569b12ffe12d6b25190fffe1c8c9550446f29d' },
422
+ { version: '1.5.1-test.3', sha256: '06e13895f6df3ec9fbf48b1b40af42940f3ddf2b3afad356751dbd11e1205ff4' },
423
+ // Exact published v1.5.1 template; only the version stamp changes in 1.5.2.
424
+ { version: '1.5.1', sha256: '3d4fa9d8543306a10a5ac7d337d1538ebf57a20104674192de16ba13f580c0e6' },
425
+ { version: '1.5.1', sha256: 'ad0c09209e60234d369a0589fdc61477efa20b95b02d66534901d6fbc0f4d673' },
368
426
  ];
369
427
 
370
428
  /** The `version = "…"` line of an agent file, at column 0. */
@@ -482,6 +540,123 @@ export function requireCodexHome(codexHome) {
482
540
  return resolve(codexHome);
483
541
  }
484
542
 
543
+ /**
544
+ * Resolve the SELECTED Codex home to the REAL directory it names, pinning it once.
545
+ *
546
+ * Why this exists: a migrated machine commonly keeps `~/.codex` as a junction (Windows) or
547
+ * symlink pointing at the real store (for example `E:\Codex\Data\.codex`). That root link
548
+ * is the operator's own layout, not a hostile indirection: refusing it made every update
549
+ * report a false conflict and forced a manual fix. So the ROOT may be a link — it is
550
+ * resolved ONCE here and every later read, classification, write, repair, refresh and
551
+ * removal uses the resolved target, which means an alias retargeted mid-operation can
552
+ * never redirect a write to a new place.
553
+ *
554
+ * What is NOT relaxed:
555
+ * * `<home>/agents`, the agent file and `config.toml` are still inspected and refused
556
+ * when THEY are links (see {@link inspectCodexBoundary});
557
+ * * a target that is missing, not a directory, or unreadable is refused with a clear
558
+ * reason rather than created or followed further;
559
+ * * the root link itself is never deleted, moved or rewritten.
560
+ * @param {string} selected - the selected home (already absolute; may be a link).
561
+ * @returns {Promise<{ selected: string, real: string, linked: boolean, linkTarget: string | null,
562
+ * error: null | { code: string, reason: string, message: string } }>} pinned home facts.
563
+ */
564
+ async function pinCodexHome(selected) {
565
+ const selectedPath = selected;
566
+ const linkedInfo = await inspectDirectory(selectedPath).catch(() => ({ kind: 'unknown' }));
567
+ // A missing root is the ordinary first-install case: it is created by the writer, and
568
+ // its parent is what must be a real directory.
569
+ if (linkedInfo.kind === 'missing') {
570
+ return { selected: selectedPath, real: selectedPath, linked: false, linkTarget: null, error: null };
571
+ }
572
+ if (linkedInfo.kind === 'unknown') {
573
+ // The platform could not classify the root. That is NOT "unusable": it is the
574
+ // existing `boundary-unverified` diagnosis, which the boundary inspection below owns.
575
+ // Pinning leaves the path alone and lets that check report the refusal.
576
+ return { selected: selectedPath, real: selectedPath, linked: false, linkTarget: null, error: null };
577
+ }
578
+ if (linkedInfo.kind !== 'link') {
579
+ // A real directory (including a junction that `lstat`/attributes prove is one is
580
+ // handled by the link branch below): nothing to resolve.
581
+ if (linkedInfo.kind === 'directory') {
582
+ return { selected: selectedPath, real: selectedPath, linked: false, linkTarget: null, error: null };
583
+ }
584
+ // A DANGLING Windows junction is the awkward case: `lstat` reports an ordinary
585
+ // directory (the target is never reached), so it lands here as `directory`-less and
586
+ // `realpath` fails. Resolve it as a link attempt: if `realpath` cannot answer, the
587
+ // selected root exists but does not lead to a usable directory, and nothing may be
588
+ // created at the alias.
589
+ let dangling = null;
590
+ try {
591
+ dangling = await realpath(selectedPath);
592
+ } catch {
593
+ dangling = null;
594
+ }
595
+ if (dangling === null) {
596
+ return {
597
+ selected: selectedPath,
598
+ real: selectedPath,
599
+ linked: false,
600
+ linkTarget: null,
601
+ error: {
602
+ code: 'CODEX_HOME_UNUSABLE',
603
+ reason: 'codex-home-link-unresolvable',
604
+ message: 'the Codex home cannot be resolved to a real directory (its target is missing)',
605
+ },
606
+ };
607
+ }
608
+ return {
609
+ selected: selectedPath,
610
+ real: selectedPath,
611
+ linked: false,
612
+ linkTarget: null,
613
+ error: {
614
+ code: 'CODEX_HOME_UNUSABLE',
615
+ reason: 'codex-home-not-a-directory',
616
+ message: 'the Codex home exists but is not a directory, so nothing was read or written',
617
+ },
618
+ };
619
+ }
620
+ // The ROOT is a link/junction: resolve it once and classify what it really names.
621
+ let resolved;
622
+ try {
623
+ resolved = await realpath(selectedPath);
624
+ } catch {
625
+ return {
626
+ selected: selectedPath,
627
+ real: selectedPath,
628
+ linked: true,
629
+ linkTarget: null,
630
+ error: {
631
+ code: 'CODEX_HOME_UNUSABLE',
632
+ reason: 'codex-home-link-unresolvable',
633
+ message: 'the Codex home is a link whose target cannot be resolved (missing or dangling)',
634
+ },
635
+ };
636
+ }
637
+ const realInfo = await inspectDirectory(resolved).catch(() => ({ kind: 'unknown' }));
638
+ if (realInfo.kind !== 'directory') {
639
+ return {
640
+ selected: selectedPath,
641
+ real: resolved,
642
+ linked: true,
643
+ linkTarget: linkedInfo.target ?? null,
644
+ error: {
645
+ code: 'CODEX_HOME_UNUSABLE',
646
+ reason: 'codex-home-target-not-a-directory',
647
+ message: 'the Codex home link does not point at a real directory, so nothing was read or written',
648
+ },
649
+ };
650
+ }
651
+ return {
652
+ selected: selectedPath,
653
+ real: resolved,
654
+ linked: true,
655
+ linkTarget: linkedInfo.target ?? null,
656
+ error: null,
657
+ };
658
+ }
659
+
485
660
  /**
486
661
  * Read the shipped agent template.
487
662
  * @returns {Promise<string>} template text exactly as published.
@@ -990,8 +1165,11 @@ export async function inspectCodexBoundary(home) {
990
1165
  const agentsPath = join(home, 'agents');
991
1166
  const homeInfo = await inspectDirectory(home);
992
1167
  if (homeInfo.kind === 'link') {
993
- // The agents path is resolved through the link; do not inspect it further, and
994
- // do not report whether anything below it exists.
1168
+ // Reached only when the caller did NOT pin the root first (a direct caller of this
1169
+ // public helper). The installer's own entries resolve a selected root link through
1170
+ // {@link pinCodexHome} and then inspect the REAL directory, so this branch keeps the
1171
+ // conservative answer for an unpinned call: below an unresolved link nothing is
1172
+ // written and nothing below it is even inspected.
995
1173
  return { blocked: true, link: 'codex-home', unknown: false, home: homeInfo, agents: { kind: 'unchecked' } };
996
1174
  }
997
1175
  const agentsInfo = homeInfo.kind === 'directory'
@@ -2069,21 +2247,33 @@ export async function readCodexStatus({
2069
2247
  version = null,
2070
2248
  hostNode = null,
2071
2249
  } = {}) {
2072
- const home = codexHome === null ? resolveCodexHome({ env }) : requireCodexHome(codexHome);
2250
+ const selected = codexHome === null ? resolveCodexHome({ env }) : requireCodexHome(codexHome);
2251
+ // A link/JUNCTION at the ROOT is the operator's own layout and is allowed: it is pinned
2252
+ // to its real directory ONCE here, and everything below reads, classifies and writes
2253
+ // against that real path.
2254
+ const pinned = await pinCodexHome(selected);
2255
+ const home = pinned.real;
2073
2256
  const agentPath = join(home, 'agents', AGENT_FILENAME);
2074
2257
  const configPath = join(home, 'config.toml');
2075
2258
  const packageVersionValue = version ?? await readPackageVersion();
2076
2259
  const template = renderAgentFile(await readAgentTemplate(), packageVersionValue);
2077
2260
  // The boundary first: a link at the Codex home or at `agents` means the agent path
2078
2261
  // does not name a file this plugin may touch, whatever `lstat` would say about it.
2079
- const boundary = await inspectCodexBoundary(home);
2262
+ const boundary = pinned.error === null
2263
+ ? await inspectCodexBoundary(home)
2264
+ // A root that could not be pinned is refused WITHOUT inspecting anything below it:
2265
+ // the alias does not lead to a usable directory, so there is nothing to classify and
2266
+ // nothing may be created through it.
2267
+ : { blocked: true, link: null, unknown: false, home: { kind: 'link' }, agents: { kind: 'unchecked' } };
2080
2268
  const agent = boundary.blocked
2081
2269
  ? {
2082
2270
  state: AGENT_STATES.conflict,
2083
2271
  present: false,
2084
2272
  reason: boundary.unknown === true
2085
2273
  ? 'boundary-unverified'
2086
- : boundary.link === 'codex-home' ? 'codex-home-is-link' : 'agents-dir-is-link',
2274
+ // A selected ROOT that could not be pinned reports WHY (missing target, not a
2275
+ // directory) instead of the generic "is a link".
2276
+ : (pinned.error?.reason ?? (boundary.link === 'codex-home' ? 'codex-home-is-link' : 'agents-dir-is-link')),
2087
2277
  contents: null,
2088
2278
  }
2089
2279
  : await readAgentState(agentPath, template);
@@ -2168,7 +2358,13 @@ export async function readCodexStatus({
2168
2358
  }
2169
2359
 
2170
2360
  return buildStatus({
2361
+ // The REAL directory every action uses, plus the selected spelling so an operator who
2362
+ // configured a junction can recognise it. `codexHome` is always the path actually
2363
+ // read and written.
2171
2364
  codexHome: home,
2365
+ codexHomeSelected: pinned.selected,
2366
+ codexHomeLinked: pinned.linked,
2367
+ codexHomeLinkTarget: pinned.linkTarget,
2172
2368
  agentPath,
2173
2369
  configPath,
2174
2370
  packageVersionValue,
@@ -2204,6 +2400,9 @@ function defaultDiscoveryPath(env) {
2204
2400
  */
2205
2401
  function buildStatus({
2206
2402
  codexHome,
2403
+ codexHomeSelected = null,
2404
+ codexHomeLinked = false,
2405
+ codexHomeLinkTarget = null,
2207
2406
  agentPath,
2208
2407
  configPath,
2209
2408
  packageVersionValue,
@@ -2223,6 +2422,11 @@ function buildStatus({
2223
2422
  const mcpOk = mcp.state === MCP_STATES.configured;
2224
2423
  return {
2225
2424
  codexHome,
2425
+ // The selected spelling and whether it was a root link, kept beside the REAL path so
2426
+ // an operator who configured a junction recognises the answer without guessing.
2427
+ codexHomeSelected: codexHomeSelected ?? codexHome,
2428
+ codexHomeLinked: codexHomeLinked === true,
2429
+ codexHomeLinkTarget,
2226
2430
  packageVersion: packageVersionValue,
2227
2431
  // Whether the two directories that bound every write are real directories. A link
2228
2432
  // at either one is a stable diagnosis, not an installation state: install, repair
@@ -2404,10 +2608,28 @@ export async function runCodexAction(action, {
2404
2608
  if (codexHome !== null && (typeof codexHome !== 'string' || codexHome.trim() === '' || !isAbsolute(codexHome))) {
2405
2609
  throw new CodexInstallError('CODEX_HOME_INVALID', 'the Codex home must be an absolute path');
2406
2610
  }
2407
- const home = codexHome === null ? resolveCodexHome({ env }) : requireCodexHome(codexHome);
2611
+ const selected = codexHome === null ? resolveCodexHome({ env }) : requireCodexHome(codexHome);
2612
+ // Pin the selected root ONCE, so install, repair and remove all act on the same real
2613
+ // directory even if the alias is retargeted while this action runs.
2614
+ const pinned = await pinCodexHome(selected);
2615
+ const home = pinned.real;
2616
+ /**
2617
+ * Attach the SELECTED spelling to a status document read from the pinned real path.
2618
+ *
2619
+ * `readCodexStatus` was handed the real directory, so its own "selected" is that
2620
+ * directory; the operator's spelling comes from here.
2621
+ * @param {object} status - status read against `home`.
2622
+ * @returns {object} the same status, annotated.
2623
+ */
2624
+ const annotated = (status) => ({
2625
+ ...status,
2626
+ codexHomeSelected: pinned.selected,
2627
+ codexHomeLinked: pinned.linked,
2628
+ codexHomeLinkTarget: pinned.linkTarget,
2629
+ });
2408
2630
  if (action === 'status') {
2409
2631
  const status = await readCodexStatus({ codexHome: home, env, discoveryFile, version, hostNode });
2410
- return { action, changed: [], refused: [], status };
2632
+ return { action, changed: [], refused: [], status: annotated(status) };
2411
2633
  }
2412
2634
 
2413
2635
  const before = await readCodexStatus({ codexHome: home, env, discoveryFile, version, hostNode });
@@ -2424,7 +2646,7 @@ export async function runCodexAction(action, {
2424
2646
  : null;
2425
2647
  if (linked !== null) {
2426
2648
  refused.push(linked);
2427
- return { action, changed, refused, status: before };
2649
+ return { action, changed, refused, status: annotated(before) };
2428
2650
  }
2429
2651
 
2430
2652
  if (action === 'remove') {
@@ -2440,7 +2662,7 @@ export async function runCodexAction(action, {
2440
2662
  }
2441
2663
 
2442
2664
  const status = await readCodexStatus({ codexHome: home, env, discoveryFile, version, hostNode });
2443
- return { action, changed, refused, status };
2665
+ return { action, changed, refused, status: annotated(status) };
2444
2666
  }
2445
2667
 
2446
2668
  /**
@@ -2501,8 +2723,14 @@ export async function refreshKnownAgentTemplate(options = {}) {
2501
2723
  if (codexHome !== null && (typeof codexHome !== 'string' || codexHome.trim() === '' || !isAbsolute(codexHome))) {
2502
2724
  throw new CodexInstallError('CODEX_HOME_INVALID', 'the Codex home must be an absolute path');
2503
2725
  }
2504
- const home = codexHome === null ? resolveCodexHome({ env }) : requireCodexHome(codexHome);
2505
- const before = plan ?? await readCodexStatus({ codexHome: home, env, discoveryFile, version, hostNode });
2726
+ // A selected ROOT link is allowed and pinned here too, so a startup refresh migrates the
2727
+ // same real directory the settings page installs into (and a `plan` captured by the
2728
+ // caller was itself read through the same pin).
2729
+ const selectedRoot = codexHome === null ? resolveCodexHome({ env }) : requireCodexHome(codexHome);
2730
+ const home = (await pinCodexHome(selectedRoot)).real;
2731
+ const before = (plan === undefined || plan === null)
2732
+ ? await readCodexStatus({ codexHome: home, env, discoveryFile, version, hostNode })
2733
+ : plan;
2506
2734
  const changed = [];
2507
2735
  const refused = [];
2508
2736
 
@@ -36,8 +36,16 @@ export const EXECUTION_PREFIX = '/dsh-delegate/x';
36
36
  */
37
37
  export const MAX_OBSERVE_WAIT_MS = 25_000;
38
38
 
39
- /** Body fields `POST /tasks/observe` accepts. Everything else is refused. */
40
- const OBSERVE_FIELDS = Object.freeze(['taskId', 'waitMs']);
39
+ /**
40
+ * Body fields `POST /tasks/observe` accepts. Everything else is refused.
41
+ *
42
+ * `ackFailureEventId` acknowledges one delivered repeated-failure reminder by its
43
+ * exact `eventId`; the acknowledgment result is echoed back as `failureAck`. It is
44
+ * OPTIONAL and was added after 1.5.0: a caller that does not send it gets exactly
45
+ * the old body shape and the old answer shape (no `failureAck` field), and its
46
+ * absence never acknowledges anything.
47
+ */
48
+ const OBSERVE_FIELDS = Object.freeze(['taskId', 'waitMs', 'ackFailureEventId']);
41
49
 
42
50
  /**
43
51
  * Build a node-style handler for the execution plane.
@@ -221,13 +229,22 @@ async function submitTask({ req, res, connection, deps }) {
221
229
  const continueFromTaskId = body.continueFromTaskId === undefined || body.continueFromTaskId === null
222
230
  ? undefined
223
231
  : body.continueFromTaskId;
232
+ // The Agent Teams decision travels as the commander's own field and is folded into the
233
+ // existing overrides channel (the engine's per-task choice path). A non-boolean is
234
+ // refused here rather than reaching the engine's sanitiser as a coercible value.
235
+ if (body.agentTeams !== undefined && typeof body.agentTeams !== 'boolean') {
236
+ throw new HttpError(400, 'AGENT_TEAMS_INVALID', 'agentTeams must be a boolean');
237
+ }
238
+ const overrides = body.agentTeams === undefined
239
+ ? body.overrides
240
+ : { ...(body.overrides ?? {}), agentTeams: body.agentTeams };
224
241
  if (deps.engine.authorizationMode === 'switch') {
225
242
  const task = await deps.engine.start({
226
243
  connectionId: connection.connectionId,
227
244
  workspacePath: body.workspacePath,
228
245
  prompt: body.prompt,
229
246
  ...(body.title === undefined ? {} : { title: body.title }),
230
- overrides: body.overrides,
247
+ overrides,
231
248
  ...(continueFromTaskId === undefined ? {} : { continueFromTaskId }),
232
249
  });
233
250
  sendJson(res, 202, { ok: true, task });
@@ -245,7 +262,7 @@ async function submitTask({ req, res, connection, deps }) {
245
262
  workspacePath: body.workspacePath,
246
263
  prompt: body.prompt,
247
264
  ...(body.title === undefined ? {} : { title: body.title }),
248
- overrides: body.overrides,
265
+ overrides,
249
266
  ...(continueFromTaskId === undefined ? {} : { continueFromTaskId }),
250
267
  });
251
268
  sendJson(res, 202, { ok: true, task });
@@ -519,6 +536,19 @@ async function observeTask({ req, res, connection, deps }) {
519
536
  if (typeof body.taskId !== 'string' || body.taskId.trim() === '') {
520
537
  throw new HttpError(400, 'TASK_ID_REQUIRED', 'taskId is required');
521
538
  }
539
+ // An ack is optional; when the field is present it must be a NON-EMPTY bounded
540
+ // string so a caller cannot smuggle an unbounded or meaningless value into the
541
+ // engine. A wrong type, an empty string, or an overlong value is REFUSED — the
542
+ // same policy the MCP schema enforces (`minLength: 1`) — never silently treated
543
+ // as absent. A `null` ack is read as "the field was not supplied" (the JSON way
544
+ // to omit an optional value), which keeps old callers unaffected.
545
+ let ackFailureEventId;
546
+ if (body.ackFailureEventId !== undefined && body.ackFailureEventId !== null) {
547
+ if (typeof body.ackFailureEventId !== 'string' || body.ackFailureEventId === '' || body.ackFailureEventId.length > 64) {
548
+ throw new HttpError(400, 'OBSERVE_ACK_INVALID', 'ackFailureEventId must be a non-empty string of at most 64 characters');
549
+ }
550
+ ackFailureEventId = body.ackFailureEventId;
551
+ }
522
552
  let waitMs = MAX_OBSERVE_WAIT_MS;
523
553
  if (body.waitMs !== undefined && body.waitMs !== null) {
524
554
  if (!Number.isInteger(body.waitMs) || body.waitMs < 0) {
@@ -534,6 +564,9 @@ async function observeTask({ req, res, connection, deps }) {
534
564
  connectionId: connection.connectionId,
535
565
  waitMs,
536
566
  signal: abandonment.signal,
567
+ // The exact event the caller observed and now acknowledges. Ownership is
568
+ // proven by the connection above; the eventId binding is the engine's.
569
+ ...(ackFailureEventId === undefined ? {} : { ackFailureEventId }),
537
570
  });
538
571
  // The reader left while the engine was settling: there is nothing to answer,
539
572
  // and writing to a closed response would only throw into the refusal path.
@@ -546,7 +579,17 @@ async function observeTask({ req, res, connection, deps }) {
546
579
  // request can never be decided, so this must not enter a wait loop.
547
580
  const observation = await historyObservation(deps, body.taskId, connection);
548
581
  if (abandonment.abandoned() || !isWritable(res)) return;
549
- sendJson(res, 200, { ok: true, wait: { waitMs, waitedMs: 0, activitySinceWait: false }, ...observation });
582
+ // A settled stored task has no live reminder to acknowledge; an ack against one
583
+ // is answered honestly as not-acknowledged instead of pretending success.
584
+ const failureAck = ackFailureEventId === undefined
585
+ ? undefined
586
+ : { acknowledged: false, eventId: ackFailureEventId, reason: 'no-pending' };
587
+ sendJson(res, 200, {
588
+ ok: true,
589
+ wait: { waitMs, waitedMs: 0, activitySinceWait: false },
590
+ ...observation,
591
+ ...(failureAck === undefined ? {} : { failureAck }),
592
+ });
550
593
  } finally {
551
594
  abandonment.dispose();
552
595
  }
package/src/index.d.ts CHANGED
@@ -381,6 +381,15 @@ export interface DelegateTaskActivity {
381
381
  export interface DelegateRepeatedFailure {
382
382
  /** Fixed discriminator, so a client can tell this apart from a silence report. */
383
383
  kind: 'repeated-tool-failure';
384
+ /**
385
+ * The stable identity of THIS notification: 16 hex chars digesting the episode's
386
+ * own hashed identity under a per-monitor 16-byte random nonce — never the raw
387
+ * arguments or error prose. The reminder is redelivered with the SAME eventId
388
+ * until the receiver acknowledges it by this id, so a lost answer is recoverable
389
+ * and one repeated failure is one notification; two tasks failing identically at
390
+ * the same instant never share an identity.
391
+ */
392
+ eventId: string;
384
393
  /** The native tool name. */
385
394
  toolName: string;
386
395
  /**
@@ -453,11 +462,41 @@ export interface DelegateObservationSummary {
453
462
  connectionId: string | null;
454
463
  /** Always false: execution completion is not host acceptance. */
455
464
  selfApproved: false;
465
+ /**
466
+ * The commander's DSH Agent Teams decision frozen on the task at admission
467
+ * (`true`/`false`), or `null` when they made no choice (the Session keeps its own
468
+ * mode). This is the REQUEST, never the applied state — read `team` for that.
469
+ */
470
+ agentTeams: boolean | null;
471
+ /** What DSH's own Agent Teams service confirmed for the run, or `null` when unasked. */
472
+ team: DelegateAgentTeamsOutcome | null;
456
473
  /** The commander's recorded delivery review, or null while none exists. */
457
474
  hostAcceptance: DelegateCompactHostAcceptance | null;
458
475
  reviewPersistence: DelegateReviewPersistence;
459
476
  }
460
477
 
478
+ /**
479
+ * The outcome of one run's Agent Teams selection.
480
+ *
481
+ * DSH owns the switch: the run's own root Session stores `team/mode`, the same selection
482
+ * the model menu's「Use Agent Teams」control writes. `requested` is what the dispatcher
483
+ * asked for, `applied` is what the service CONFIRMED by reading the saved selection back,
484
+ * and `reason` explains every non-application (`not-requested`,
485
+ * `agent-teams-unavailable`, `agent-teams-failed: …`, `agent-teams-unconfirmed`,
486
+ * `agent-teams-mismatch: …`, `aborted`) so an operator can tell "asked and on" from
487
+ * "asked and could not be applied".
488
+ */
489
+ export interface DelegateAgentTeamsOutcome {
490
+ requested: boolean | null;
491
+ /** Whether this harness composed the Agent Teams service at all. */
492
+ supported: boolean;
493
+ /** True only after the service's own read-back agreed with the request. */
494
+ applied: boolean;
495
+ /** The selection the Session reports, or `null` when it could not be read. */
496
+ enabled: boolean | null;
497
+ reason: string | null;
498
+ }
499
+
461
500
  /**
462
501
  * A replayed (idempotent) review request and its answer.
463
502
  *
@@ -731,6 +770,29 @@ export interface DelegateObservation {
731
770
  * keeps the two distinguishable without a new reason value.
732
771
  */
733
772
  failure?: DelegateRepeatedFailure | null;
773
+ /**
774
+ * Present only when the caller asked to acknowledge one delivered reminder by its
775
+ * `eventId` (an `ackFailureEventId` on the observe/wait call). `acknowledged` is
776
+ * `true` when the exact pending event was cleared (or had already been cleared by
777
+ * an idempotent repeat); `false` with a `reason` (`unknown-event`, `superseded`,
778
+ * `no-pending`, `event-id-required`) when nothing was cleared — a wrong ack never
779
+ * silences a live reminder.
780
+ */
781
+ /**
782
+ * Present only when the caller asked to acknowledge one delivered reminder by its
783
+ * `eventId` (an `ackFailureEventId` on the observe/wait call). `acknowledged` is
784
+ * `true` when the exact pending event was cleared (or had already been cleared by
785
+ * an idempotent repeat); `false` with a `reason` (`unknown-event`, `superseded`,
786
+ * `no-pending`, `event-id-required`) when nothing was cleared — a wrong ack never
787
+ * silences a live reminder, and an empty id is refused, not ignored. The FIRST
788
+ * verdict reported on a wait is frozen for that call: later observations do not
789
+ * overwrite it with an `unknown-event` from a disposed monitor or a settled task.
790
+ */
791
+ failureAck?: {
792
+ acknowledged: boolean;
793
+ eventId: string | null;
794
+ reason: string | null;
795
+ };
734
796
  activity: DelegateTaskActivity | null;
735
797
  selfCheck: { episode: number | null; checkedAt: number | null; verdict: string | null } | null;
736
798
  /**
package/src/index.js CHANGED
@@ -112,6 +112,15 @@ export const Config = z.object({
112
112
  export async function apply(ctx, config = {}) {
113
113
  const logger = ctx.logger;
114
114
  const dataDir = await resolveDataDir(ctx, config);
115
+ // Re-read THIS build's manifest on every activation.
116
+ //
117
+ // A host can replace the installed package on disk while this module stays loaded (a
118
+ // DSH hot update: `package.json` becomes 1.5.1-test.2, the code that is running is the
119
+ // new one). The process-lifetime manifest memo then still answers the PREVIOUS version,
120
+ // and this activation would stamp the Codex integration with it — so the next start,
121
+ // reading the real manifest, sees a freshly written file as operator-customised. One
122
+ // forced read per activation is the whole fix; nothing else bypasses the cache.
123
+ const pluginVersion = reportedVersion({ refresh: true }).version;
115
124
 
116
125
  const settings = new SettingsService(dataDir);
117
126
  // Read once at load so an unusable document fails the plugin loudly instead of
@@ -234,7 +243,7 @@ export async function apply(ctx, config = {}) {
234
243
  // Startup only refreshes an agent file whose bytes match a shipped template.
235
244
  // Agent creation and MCP registration remain explicit settings-page actions.
236
245
  codex: resolveCodexActionSeam({
237
- version: PLUGIN_VERSION,
246
+ version: pluginVersion,
238
247
  // The automatic upgrade's protected backup location, inside this activation's own
239
248
  // data directory: never the package, never the Codex home, never a user home. The
240
249
  // seam supplies it to a caller that does not pass one, so the unattended MCP write
@@ -296,7 +305,7 @@ export async function apply(ctx, config = {}) {
296
305
  logger?.info?.(`dsh-delegate: Codex integration check skipped (${target.reason})`);
297
306
  }
298
307
  if (migration?.changed.includes('agent')) {
299
- logger?.info?.(`dsh-delegate: refreshed a managed Codex agent template to ${PLUGIN_VERSION}`);
308
+ logger?.info?.(`dsh-delegate: refreshed a managed Codex agent template to ${pluginVersion}`);
300
309
  }
301
310
  if (migration?.changed.includes('mcp')) {
302
311
  logger?.info?.('dsh-delegate: upgraded a stale managed Codex MCP entry in place');
@@ -421,7 +430,7 @@ export async function apply(ctx, config = {}) {
421
430
  deps.engine = engine;
422
431
  deps.describeRuntime = () => ({
423
432
  plugin: name,
424
- version: PLUGIN_VERSION,
433
+ version: pluginVersion,
425
434
  schemaVersion: SCHEMA_VERSION,
426
435
  // Facts an operator needs to reason about exposure. Never a secret.
427
436
  bind: ctx.webServer?.host ?? null,
@@ -523,13 +532,17 @@ export async function apply(ctx, config = {}) {
523
532
  }
524
533
 
525
534
  /**
526
- * Version reported by the runtime facts block.
535
+ * Version reported by the runtime facts block and stamped into the Codex integration.
527
536
  *
528
537
  * Read from the package manifest this build ships in, never written as a literal: two
529
538
  * copies of one fact drift, and a host asking a pre-release build which version it is
530
539
  * must not be told the last released number.
540
+ *
541
+ * There is deliberately NO module-level constant: a host hot update replaces the manifest
542
+ * under a running instance, so the value is taken per activation
543
+ * (`reportedVersion({ refresh: true })` at the top of {@link apply}) rather than frozen
544
+ * when this module was first loaded.
531
545
  */
532
- const PLUGIN_VERSION = reportedVersion().version;
533
546
 
534
547
  /**
535
548
  * Read the native approval service without turning absence into a throw.