dsh-taskbridge 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +9 -8
- package/codex/dsh-taskbridge.toml +107 -12
- package/docs/INTRODUCTION.md +2 -2
- package/docs/INTRODUCTION.zh.md +2 -2
- package/docs/codex-integration.md +9 -13
- package/docs/plugin-market.md +1 -1
- package/docs/releases/1.5.1.zh.md +70 -0
- package/docs/runtime-compatibility.md +4 -4
- package/docs/silent-wait.md +75 -5
- package/docs/taskbridge-upgrade.md +1 -1
- package/docs/worker-permissions.md +1 -1
- package/lib/client.js +295 -103
- package/package.json +7 -3
- package/src/client/api.js +289 -34
- package/src/client/index.jsx +151 -67
- package/src/codex/installer.js +236 -11
- package/src/http/execution-plane.js +48 -5
- package/src/index.d.ts +62 -0
- package/src/index.js +18 -5
- package/src/jobs/activity.js +92 -9
- package/src/jobs/continuation-identity.js +283 -278
- package/src/jobs/engine.js +165 -19
- package/src/jobs/history.js +43 -0
- package/src/mcp/metrics.js +366 -343
- package/src/mcp/server.js +127 -9
- package/src/mcp/wait.js +77 -4
- package/src/runtime/agent-runner.js +165 -0
- package/src/runtime/sandbox.js +363 -358
- package/src/runtime/session-placement.js +1207 -1194
- package/src/version.js +121 -99
- package/src/workspace/worktrees.js +70 -4
package/src/codex/installer.js
CHANGED
|
@@ -365,6 +365,61 @@ 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' },
|
|
368
423
|
];
|
|
369
424
|
|
|
370
425
|
/** The `version = "…"` line of an agent file, at column 0. */
|
|
@@ -482,6 +537,123 @@ export function requireCodexHome(codexHome) {
|
|
|
482
537
|
return resolve(codexHome);
|
|
483
538
|
}
|
|
484
539
|
|
|
540
|
+
/**
|
|
541
|
+
* Resolve the SELECTED Codex home to the REAL directory it names, pinning it once.
|
|
542
|
+
*
|
|
543
|
+
* Why this exists: a migrated machine commonly keeps `~/.codex` as a junction (Windows) or
|
|
544
|
+
* symlink pointing at the real store (for example `E:\Codex\Data\.codex`). That root link
|
|
545
|
+
* is the operator's own layout, not a hostile indirection: refusing it made every update
|
|
546
|
+
* report a false conflict and forced a manual fix. So the ROOT may be a link — it is
|
|
547
|
+
* resolved ONCE here and every later read, classification, write, repair, refresh and
|
|
548
|
+
* removal uses the resolved target, which means an alias retargeted mid-operation can
|
|
549
|
+
* never redirect a write to a new place.
|
|
550
|
+
*
|
|
551
|
+
* What is NOT relaxed:
|
|
552
|
+
* * `<home>/agents`, the agent file and `config.toml` are still inspected and refused
|
|
553
|
+
* when THEY are links (see {@link inspectCodexBoundary});
|
|
554
|
+
* * a target that is missing, not a directory, or unreadable is refused with a clear
|
|
555
|
+
* reason rather than created or followed further;
|
|
556
|
+
* * the root link itself is never deleted, moved or rewritten.
|
|
557
|
+
* @param {string} selected - the selected home (already absolute; may be a link).
|
|
558
|
+
* @returns {Promise<{ selected: string, real: string, linked: boolean, linkTarget: string | null,
|
|
559
|
+
* error: null | { code: string, reason: string, message: string } }>} pinned home facts.
|
|
560
|
+
*/
|
|
561
|
+
async function pinCodexHome(selected) {
|
|
562
|
+
const selectedPath = selected;
|
|
563
|
+
const linkedInfo = await inspectDirectory(selectedPath).catch(() => ({ kind: 'unknown' }));
|
|
564
|
+
// A missing root is the ordinary first-install case: it is created by the writer, and
|
|
565
|
+
// its parent is what must be a real directory.
|
|
566
|
+
if (linkedInfo.kind === 'missing') {
|
|
567
|
+
return { selected: selectedPath, real: selectedPath, linked: false, linkTarget: null, error: null };
|
|
568
|
+
}
|
|
569
|
+
if (linkedInfo.kind === 'unknown') {
|
|
570
|
+
// The platform could not classify the root. That is NOT "unusable": it is the
|
|
571
|
+
// existing `boundary-unverified` diagnosis, which the boundary inspection below owns.
|
|
572
|
+
// Pinning leaves the path alone and lets that check report the refusal.
|
|
573
|
+
return { selected: selectedPath, real: selectedPath, linked: false, linkTarget: null, error: null };
|
|
574
|
+
}
|
|
575
|
+
if (linkedInfo.kind !== 'link') {
|
|
576
|
+
// A real directory (including a junction that `lstat`/attributes prove is one is
|
|
577
|
+
// handled by the link branch below): nothing to resolve.
|
|
578
|
+
if (linkedInfo.kind === 'directory') {
|
|
579
|
+
return { selected: selectedPath, real: selectedPath, linked: false, linkTarget: null, error: null };
|
|
580
|
+
}
|
|
581
|
+
// A DANGLING Windows junction is the awkward case: `lstat` reports an ordinary
|
|
582
|
+
// directory (the target is never reached), so it lands here as `directory`-less and
|
|
583
|
+
// `realpath` fails. Resolve it as a link attempt: if `realpath` cannot answer, the
|
|
584
|
+
// selected root exists but does not lead to a usable directory, and nothing may be
|
|
585
|
+
// created at the alias.
|
|
586
|
+
let dangling = null;
|
|
587
|
+
try {
|
|
588
|
+
dangling = await realpath(selectedPath);
|
|
589
|
+
} catch {
|
|
590
|
+
dangling = null;
|
|
591
|
+
}
|
|
592
|
+
if (dangling === null) {
|
|
593
|
+
return {
|
|
594
|
+
selected: selectedPath,
|
|
595
|
+
real: selectedPath,
|
|
596
|
+
linked: false,
|
|
597
|
+
linkTarget: null,
|
|
598
|
+
error: {
|
|
599
|
+
code: 'CODEX_HOME_UNUSABLE',
|
|
600
|
+
reason: 'codex-home-link-unresolvable',
|
|
601
|
+
message: 'the Codex home cannot be resolved to a real directory (its target is missing)',
|
|
602
|
+
},
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
return {
|
|
606
|
+
selected: selectedPath,
|
|
607
|
+
real: selectedPath,
|
|
608
|
+
linked: false,
|
|
609
|
+
linkTarget: null,
|
|
610
|
+
error: {
|
|
611
|
+
code: 'CODEX_HOME_UNUSABLE',
|
|
612
|
+
reason: 'codex-home-not-a-directory',
|
|
613
|
+
message: 'the Codex home exists but is not a directory, so nothing was read or written',
|
|
614
|
+
},
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
// The ROOT is a link/junction: resolve it once and classify what it really names.
|
|
618
|
+
let resolved;
|
|
619
|
+
try {
|
|
620
|
+
resolved = await realpath(selectedPath);
|
|
621
|
+
} catch {
|
|
622
|
+
return {
|
|
623
|
+
selected: selectedPath,
|
|
624
|
+
real: selectedPath,
|
|
625
|
+
linked: true,
|
|
626
|
+
linkTarget: null,
|
|
627
|
+
error: {
|
|
628
|
+
code: 'CODEX_HOME_UNUSABLE',
|
|
629
|
+
reason: 'codex-home-link-unresolvable',
|
|
630
|
+
message: 'the Codex home is a link whose target cannot be resolved (missing or dangling)',
|
|
631
|
+
},
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
const realInfo = await inspectDirectory(resolved).catch(() => ({ kind: 'unknown' }));
|
|
635
|
+
if (realInfo.kind !== 'directory') {
|
|
636
|
+
return {
|
|
637
|
+
selected: selectedPath,
|
|
638
|
+
real: resolved,
|
|
639
|
+
linked: true,
|
|
640
|
+
linkTarget: linkedInfo.target ?? null,
|
|
641
|
+
error: {
|
|
642
|
+
code: 'CODEX_HOME_UNUSABLE',
|
|
643
|
+
reason: 'codex-home-target-not-a-directory',
|
|
644
|
+
message: 'the Codex home link does not point at a real directory, so nothing was read or written',
|
|
645
|
+
},
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
selected: selectedPath,
|
|
650
|
+
real: resolved,
|
|
651
|
+
linked: true,
|
|
652
|
+
linkTarget: linkedInfo.target ?? null,
|
|
653
|
+
error: null,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
485
657
|
/**
|
|
486
658
|
* Read the shipped agent template.
|
|
487
659
|
* @returns {Promise<string>} template text exactly as published.
|
|
@@ -990,8 +1162,11 @@ export async function inspectCodexBoundary(home) {
|
|
|
990
1162
|
const agentsPath = join(home, 'agents');
|
|
991
1163
|
const homeInfo = await inspectDirectory(home);
|
|
992
1164
|
if (homeInfo.kind === 'link') {
|
|
993
|
-
//
|
|
994
|
-
//
|
|
1165
|
+
// Reached only when the caller did NOT pin the root first (a direct caller of this
|
|
1166
|
+
// public helper). The installer's own entries resolve a selected root link through
|
|
1167
|
+
// {@link pinCodexHome} and then inspect the REAL directory, so this branch keeps the
|
|
1168
|
+
// conservative answer for an unpinned call: below an unresolved link nothing is
|
|
1169
|
+
// written and nothing below it is even inspected.
|
|
995
1170
|
return { blocked: true, link: 'codex-home', unknown: false, home: homeInfo, agents: { kind: 'unchecked' } };
|
|
996
1171
|
}
|
|
997
1172
|
const agentsInfo = homeInfo.kind === 'directory'
|
|
@@ -2069,21 +2244,33 @@ export async function readCodexStatus({
|
|
|
2069
2244
|
version = null,
|
|
2070
2245
|
hostNode = null,
|
|
2071
2246
|
} = {}) {
|
|
2072
|
-
const
|
|
2247
|
+
const selected = codexHome === null ? resolveCodexHome({ env }) : requireCodexHome(codexHome);
|
|
2248
|
+
// A link/JUNCTION at the ROOT is the operator's own layout and is allowed: it is pinned
|
|
2249
|
+
// to its real directory ONCE here, and everything below reads, classifies and writes
|
|
2250
|
+
// against that real path.
|
|
2251
|
+
const pinned = await pinCodexHome(selected);
|
|
2252
|
+
const home = pinned.real;
|
|
2073
2253
|
const agentPath = join(home, 'agents', AGENT_FILENAME);
|
|
2074
2254
|
const configPath = join(home, 'config.toml');
|
|
2075
2255
|
const packageVersionValue = version ?? await readPackageVersion();
|
|
2076
2256
|
const template = renderAgentFile(await readAgentTemplate(), packageVersionValue);
|
|
2077
2257
|
// The boundary first: a link at the Codex home or at `agents` means the agent path
|
|
2078
2258
|
// does not name a file this plugin may touch, whatever `lstat` would say about it.
|
|
2079
|
-
const boundary =
|
|
2259
|
+
const boundary = pinned.error === null
|
|
2260
|
+
? await inspectCodexBoundary(home)
|
|
2261
|
+
// A root that could not be pinned is refused WITHOUT inspecting anything below it:
|
|
2262
|
+
// the alias does not lead to a usable directory, so there is nothing to classify and
|
|
2263
|
+
// nothing may be created through it.
|
|
2264
|
+
: { blocked: true, link: null, unknown: false, home: { kind: 'link' }, agents: { kind: 'unchecked' } };
|
|
2080
2265
|
const agent = boundary.blocked
|
|
2081
2266
|
? {
|
|
2082
2267
|
state: AGENT_STATES.conflict,
|
|
2083
2268
|
present: false,
|
|
2084
2269
|
reason: boundary.unknown === true
|
|
2085
2270
|
? 'boundary-unverified'
|
|
2086
|
-
|
|
2271
|
+
// A selected ROOT that could not be pinned reports WHY (missing target, not a
|
|
2272
|
+
// directory) instead of the generic "is a link".
|
|
2273
|
+
: (pinned.error?.reason ?? (boundary.link === 'codex-home' ? 'codex-home-is-link' : 'agents-dir-is-link')),
|
|
2087
2274
|
contents: null,
|
|
2088
2275
|
}
|
|
2089
2276
|
: await readAgentState(agentPath, template);
|
|
@@ -2168,7 +2355,13 @@ export async function readCodexStatus({
|
|
|
2168
2355
|
}
|
|
2169
2356
|
|
|
2170
2357
|
return buildStatus({
|
|
2358
|
+
// The REAL directory every action uses, plus the selected spelling so an operator who
|
|
2359
|
+
// configured a junction can recognise it. `codexHome` is always the path actually
|
|
2360
|
+
// read and written.
|
|
2171
2361
|
codexHome: home,
|
|
2362
|
+
codexHomeSelected: pinned.selected,
|
|
2363
|
+
codexHomeLinked: pinned.linked,
|
|
2364
|
+
codexHomeLinkTarget: pinned.linkTarget,
|
|
2172
2365
|
agentPath,
|
|
2173
2366
|
configPath,
|
|
2174
2367
|
packageVersionValue,
|
|
@@ -2204,6 +2397,9 @@ function defaultDiscoveryPath(env) {
|
|
|
2204
2397
|
*/
|
|
2205
2398
|
function buildStatus({
|
|
2206
2399
|
codexHome,
|
|
2400
|
+
codexHomeSelected = null,
|
|
2401
|
+
codexHomeLinked = false,
|
|
2402
|
+
codexHomeLinkTarget = null,
|
|
2207
2403
|
agentPath,
|
|
2208
2404
|
configPath,
|
|
2209
2405
|
packageVersionValue,
|
|
@@ -2223,6 +2419,11 @@ function buildStatus({
|
|
|
2223
2419
|
const mcpOk = mcp.state === MCP_STATES.configured;
|
|
2224
2420
|
return {
|
|
2225
2421
|
codexHome,
|
|
2422
|
+
// The selected spelling and whether it was a root link, kept beside the REAL path so
|
|
2423
|
+
// an operator who configured a junction recognises the answer without guessing.
|
|
2424
|
+
codexHomeSelected: codexHomeSelected ?? codexHome,
|
|
2425
|
+
codexHomeLinked: codexHomeLinked === true,
|
|
2426
|
+
codexHomeLinkTarget,
|
|
2226
2427
|
packageVersion: packageVersionValue,
|
|
2227
2428
|
// Whether the two directories that bound every write are real directories. A link
|
|
2228
2429
|
// at either one is a stable diagnosis, not an installation state: install, repair
|
|
@@ -2404,10 +2605,28 @@ export async function runCodexAction(action, {
|
|
|
2404
2605
|
if (codexHome !== null && (typeof codexHome !== 'string' || codexHome.trim() === '' || !isAbsolute(codexHome))) {
|
|
2405
2606
|
throw new CodexInstallError('CODEX_HOME_INVALID', 'the Codex home must be an absolute path');
|
|
2406
2607
|
}
|
|
2407
|
-
const
|
|
2608
|
+
const selected = codexHome === null ? resolveCodexHome({ env }) : requireCodexHome(codexHome);
|
|
2609
|
+
// Pin the selected root ONCE, so install, repair and remove all act on the same real
|
|
2610
|
+
// directory even if the alias is retargeted while this action runs.
|
|
2611
|
+
const pinned = await pinCodexHome(selected);
|
|
2612
|
+
const home = pinned.real;
|
|
2613
|
+
/**
|
|
2614
|
+
* Attach the SELECTED spelling to a status document read from the pinned real path.
|
|
2615
|
+
*
|
|
2616
|
+
* `readCodexStatus` was handed the real directory, so its own "selected" is that
|
|
2617
|
+
* directory; the operator's spelling comes from here.
|
|
2618
|
+
* @param {object} status - status read against `home`.
|
|
2619
|
+
* @returns {object} the same status, annotated.
|
|
2620
|
+
*/
|
|
2621
|
+
const annotated = (status) => ({
|
|
2622
|
+
...status,
|
|
2623
|
+
codexHomeSelected: pinned.selected,
|
|
2624
|
+
codexHomeLinked: pinned.linked,
|
|
2625
|
+
codexHomeLinkTarget: pinned.linkTarget,
|
|
2626
|
+
});
|
|
2408
2627
|
if (action === 'status') {
|
|
2409
2628
|
const status = await readCodexStatus({ codexHome: home, env, discoveryFile, version, hostNode });
|
|
2410
|
-
return { action, changed: [], refused: [], status };
|
|
2629
|
+
return { action, changed: [], refused: [], status: annotated(status) };
|
|
2411
2630
|
}
|
|
2412
2631
|
|
|
2413
2632
|
const before = await readCodexStatus({ codexHome: home, env, discoveryFile, version, hostNode });
|
|
@@ -2424,7 +2643,7 @@ export async function runCodexAction(action, {
|
|
|
2424
2643
|
: null;
|
|
2425
2644
|
if (linked !== null) {
|
|
2426
2645
|
refused.push(linked);
|
|
2427
|
-
return { action, changed, refused, status: before };
|
|
2646
|
+
return { action, changed, refused, status: annotated(before) };
|
|
2428
2647
|
}
|
|
2429
2648
|
|
|
2430
2649
|
if (action === 'remove') {
|
|
@@ -2440,7 +2659,7 @@ export async function runCodexAction(action, {
|
|
|
2440
2659
|
}
|
|
2441
2660
|
|
|
2442
2661
|
const status = await readCodexStatus({ codexHome: home, env, discoveryFile, version, hostNode });
|
|
2443
|
-
return { action, changed, refused, status };
|
|
2662
|
+
return { action, changed, refused, status: annotated(status) };
|
|
2444
2663
|
}
|
|
2445
2664
|
|
|
2446
2665
|
/**
|
|
@@ -2501,8 +2720,14 @@ export async function refreshKnownAgentTemplate(options = {}) {
|
|
|
2501
2720
|
if (codexHome !== null && (typeof codexHome !== 'string' || codexHome.trim() === '' || !isAbsolute(codexHome))) {
|
|
2502
2721
|
throw new CodexInstallError('CODEX_HOME_INVALID', 'the Codex home must be an absolute path');
|
|
2503
2722
|
}
|
|
2504
|
-
|
|
2505
|
-
|
|
2723
|
+
// A selected ROOT link is allowed and pinned here too, so a startup refresh migrates the
|
|
2724
|
+
// same real directory the settings page installs into (and a `plan` captured by the
|
|
2725
|
+
// caller was itself read through the same pin).
|
|
2726
|
+
const selectedRoot = codexHome === null ? resolveCodexHome({ env }) : requireCodexHome(codexHome);
|
|
2727
|
+
const home = (await pinCodexHome(selectedRoot)).real;
|
|
2728
|
+
const before = (plan === undefined || plan === null)
|
|
2729
|
+
? await readCodexStatus({ codexHome: home, env, discoveryFile, version, hostNode })
|
|
2730
|
+
: plan;
|
|
2506
2731
|
const changed = [];
|
|
2507
2732
|
const refused = [];
|
|
2508
2733
|
|
|
@@ -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
|
-
/**
|
|
40
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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:
|
|
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 ${
|
|
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:
|
|
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.
|