@tangle-network/agent-runtime 0.337.2 → 0.339.0
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/dist/{activation-DRHM55Oo.d.ts → activation-CJIIl_Ey.d.ts} +90 -22
- package/dist/activation-CVSFxis9.js +876 -0
- package/dist/activation-CVSFxis9.js.map +1 -0
- package/dist/agent.d.ts +4 -4
- package/dist/agent.js +4 -7
- package/dist/agent.js.map +1 -1
- package/dist/{bundle-BPGjESee.js → bundle-DVOhBTic.js} +2 -2
- package/dist/{bundle-BPGjESee.js.map → bundle-DVOhBTic.js.map} +1 -1
- package/dist/candidate-execution/index.d.ts +4 -63
- package/dist/candidate-execution/index.js +6 -146
- package/dist/candidate-execution/index.js.map +1 -1
- package/dist/content-digest-sBTLujlK.js +9 -0
- package/dist/content-digest-sBTLujlK.js.map +1 -0
- package/dist/{delegate-B-T_ZB50.js → delegate-CCWE_AkU.js} +2 -2
- package/dist/{delegate-B-T_ZB50.js.map → delegate-CCWE_AkU.js.map} +1 -1
- package/dist/{coordination-driver-BHkFVqIq.js → driver-control-acknowledgers-C53ggdJ6.js} +4520 -4442
- package/dist/driver-control-acknowledgers-C53ggdJ6.js.map +1 -0
- package/dist/{durable-file-B_eJr6Mb.js → durable-file-gNI9ILAn.js} +1 -3
- package/dist/durable-file-gNI9ILAn.js.map +1 -0
- package/dist/durable.d.ts +3 -35
- package/dist/durable.js +225 -229
- package/dist/durable.js.map +1 -1
- package/dist/{graph-C4RFlWAJ.js → graph-CI9JXKqO.js} +65 -18
- package/dist/graph-CI9JXKqO.js.map +1 -0
- package/dist/{graph-registry-DAI6KNXB.js → graph-registry-BnO64cn8.js} +18 -17
- package/dist/graph-registry-BnO64cn8.js.map +1 -0
- package/dist/{improvement-cycle-D1I4hQvf.js → improve-BOXTLWJ3.js} +76 -1248
- package/dist/improve-BOXTLWJ3.js.map +1 -0
- package/dist/{improvement-adapter-D5gwwoXQ.d.ts → improvement-adapter-HUt_-cWA.d.ts} +2 -20
- package/dist/index.d.ts +10 -207
- package/dist/index.js +91 -305
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +10 -229
- package/dist/intelligence.js +506 -88
- package/dist/intelligence.js.map +1 -1
- package/dist/{jsonl-file-DBv31uPi.js → jsonl-file-C9Kde_0Z.js} +2 -2
- package/dist/{jsonl-file-DBv31uPi.js.map → jsonl-file-C9Kde_0Z.js.map} +1 -1
- package/dist/kernel.d.ts +4 -3
- package/dist/kernel.js +12 -13
- package/dist/loop-runner-CWzG1bH4.d.ts +32 -0
- package/dist/loop-runner-bin.d.ts +32 -2
- package/dist/loop-runner-bin.js +93 -1
- package/dist/loop-runner-bin.js.map +1 -0
- package/dist/loop-runner-pmPIHFVY.js +59 -0
- package/dist/loop-runner-pmPIHFVY.js.map +1 -0
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +101 -416
- package/dist/mcp/index.js +122 -206
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/memory-bin.js +231 -1
- package/dist/mcp/memory-bin.js.map +1 -1
- package/dist/model-policy-CyCUwHed.js.map +1 -1
- package/dist/placement.d.ts +2 -9
- package/dist/placement.js +1 -1
- package/dist/placement.js.map +1 -1
- package/dist/platform.d.ts +194 -2
- package/dist/platform.js +145 -9
- package/dist/platform.js.map +1 -1
- package/dist/{prepare-CER-ZkPp.js → prepare-bXkvPMJA.js} +1213 -710
- package/dist/prepare-bXkvPMJA.js.map +1 -0
- package/dist/{profile-gNUsHNIJ.js → profile-Dpei_Sq0.js} +89 -3
- package/dist/profile-Dpei_Sq0.js.map +1 -0
- package/dist/{profile-materialization-BnoEf1co.d.ts → profile-materialization-B1wm2SPT.d.ts} +3 -5
- package/dist/profiles.d.ts +2 -2
- package/dist/profiles.js +4 -43
- package/dist/profiles.js.map +1 -1
- package/dist/{protected-model-port-BhpQRTw-.d.ts → protected-model-port-BGgpy2r9.d.ts} +4 -30
- package/dist/protected-redaction-DFCeo4vg.js.map +1 -1
- package/dist/{provision-supervisor-DGegCUH4.js → provision-supervisor-CJ6Zz6dz.js} +13 -10
- package/dist/provision-supervisor-CJ6Zz6dz.js.map +1 -0
- package/dist/record-value-B6bwJxLa.js +12 -0
- package/dist/record-value-B6bwJxLa.js.map +1 -0
- package/dist/{run-layout-Cu8H7aeh.js → run-cancellation-C9oL62sW.js} +175 -100
- package/dist/run-cancellation-C9oL62sW.js.map +1 -0
- package/dist/{runtime-BOGpotnH.js → runtime-B2fjL9Oi.js} +2639 -3187
- package/dist/runtime-B2fjL9Oi.js.map +1 -0
- package/dist/{runtime-hooks-Bj6wJHlH.d.ts → runtime-hooks-nsqxSUFL.d.ts} +2 -6
- package/dist/{sandbox-profile-compat-QTkLe1Z6.js → sandbox-profile-compat-BzVBFqrz.js} +690 -699
- package/dist/sandbox-profile-compat-BzVBFqrz.js.map +1 -0
- package/dist/search-executor-zMumiak_.js +1916 -0
- package/dist/search-executor-zMumiak_.js.map +1 -0
- package/dist/{server-hZWM-G8w.js → server-_4voDNrl.js} +362 -67
- package/dist/server-_4voDNrl.js.map +1 -0
- package/dist/{search-executor-Cm1WZmL-.js → structural-rollout-DpLCXzaL.js} +1680 -3403
- package/dist/structural-rollout-DpLCXzaL.js.map +1 -0
- package/dist/{substrate-B0TYNrXn.js → substrate-CGDFTSRh.js} +2 -9
- package/dist/substrate-CGDFTSRh.js.map +1 -0
- package/dist/{supervise-CvAKVfue.js → supervise-qAwXmPtD.js} +7768 -5360
- package/dist/supervise-qAwXmPtD.js.map +1 -0
- package/dist/{supervisor-Rz8AGpYb.js → supervisor-DHrUJhEZ.js} +26301 -26964
- package/dist/supervisor-DHrUJhEZ.js.map +1 -0
- package/dist/testing.d.ts +227 -2
- package/dist/testing.js +13 -14
- package/dist/testing.js.map +1 -1
- package/dist/tool-loop.d.ts +1 -1
- package/dist/{tool-server-Dqer2M4_.js → tool-server-XV4aJwoQ.js} +2 -2
- package/dist/tool-server-XV4aJwoQ.js.map +1 -0
- package/dist/top-snapshot-CbZE1JsU.js +502 -0
- package/dist/top-snapshot-CbZE1JsU.js.map +1 -0
- package/dist/tui/bin.js +711 -1
- package/dist/tui/bin.js.map +1 -1
- package/dist/tui/index.d.ts +5 -71
- package/dist/tui/index.js +3 -3
- package/dist/{types-Dl5L4r8Z.d.ts → types-CaOXqRTq.d.ts} +16230 -17376
- package/dist/workspace-store/index.d.ts +2 -27
- package/dist/workspace-store/index.js +2 -2
- package/dist/workspace-store/index.js.map +1 -1
- package/dist/{workspace-streams-JLjh5DC6.d.ts → workspace-streams-BiS4ABah.d.ts} +19 -32
- package/package.json +2 -2
- package/skills/agent-graphs/SKILL.md +10 -3
- package/skills/agent-graphs/references/authoring.md +18 -0
- package/skills/profile-authoring/SKILL.md +3 -3
- package/skills/supervise/SKILL.md +2 -2
- package/dist/activation-BDP6Eivv.js +0 -234
- package/dist/activation-BDP6Eivv.js.map +0 -1
- package/dist/coder-yhVWbdWc.js +0 -40
- package/dist/coder-yhVWbdWc.js.map +0 -1
- package/dist/coordination-driver-BHkFVqIq.js.map +0 -1
- package/dist/delegation-status-CF4D0NZ_.js +0 -358
- package/dist/delegation-status-CF4D0NZ_.js.map +0 -1
- package/dist/durable-file-B_eJr6Mb.js.map +0 -1
- package/dist/graph-C4RFlWAJ.js.map +0 -1
- package/dist/graph-registry-DAI6KNXB.js.map +0 -1
- package/dist/improvement-cycle-D1I4hQvf.js.map +0 -1
- package/dist/integrations-DopfCC2a.d.ts +0 -190
- package/dist/integrations-dFi-ALk7.js +0 -132
- package/dist/integrations-dFi-ALk7.js.map +0 -1
- package/dist/kb-gate-C8z2juK8.d.ts +0 -80
- package/dist/kb-gate-DpaSwXVx.js +0 -80
- package/dist/kb-gate-DpaSwXVx.js.map +0 -1
- package/dist/loop-runner-bin-DOuBIJ2O.d.ts +0 -164
- package/dist/loop-runner-bin-Dv5QvYDH.js +0 -246
- package/dist/loop-runner-bin-Dv5QvYDH.js.map +0 -1
- package/dist/memory-server-DXQ8IxGR.js +0 -234
- package/dist/memory-server-DXQ8IxGR.js.map +0 -1
- package/dist/openai-tools-DoQ32vpe.js +0 -44
- package/dist/openai-tools-DoQ32vpe.js.map +0 -1
- package/dist/openai-tools-Oxk4KQrY.d.ts +0 -24
- package/dist/prepare-CER-ZkPp.js.map +0 -1
- package/dist/profile-gNUsHNIJ.js.map +0 -1
- package/dist/protected-model-port-BuRsviSL.js +0 -766
- package/dist/protected-model-port-BuRsviSL.js.map +0 -1
- package/dist/provision-supervisor-DGegCUH4.js.map +0 -1
- package/dist/run-layout-Cu8H7aeh.js.map +0 -1
- package/dist/runtime-BOGpotnH.js.map +0 -1
- package/dist/sandbox-profile-compat-QTkLe1Z6.js.map +0 -1
- package/dist/search-executor-Cm1WZmL-.js.map +0 -1
- package/dist/server-hZWM-G8w.js.map +0 -1
- package/dist/substrate-B0TYNrXn.js.map +0 -1
- package/dist/supervise-CvAKVfue.js.map +0 -1
- package/dist/supervisor-Rz8AGpYb.js.map +0 -1
- package/dist/tool-server-Dqer2M4_.js.map +0 -1
- package/dist/top-app-BaMw1W2z.js +0 -1212
- package/dist/top-app-BaMw1W2z.js.map +0 -1
|
@@ -26,10 +26,8 @@ var __exportAll = (all, no_symbols) => {
|
|
|
26
26
|
var durable_file_exports = /* @__PURE__ */ __exportAll({
|
|
27
27
|
appendDurableFile: () => appendDurableFile,
|
|
28
28
|
assertNoSymlinkDescendant: () => assertNoSymlinkDescendant,
|
|
29
|
-
isAlreadyExistsError: () => isAlreadyExistsError,
|
|
30
29
|
publishExclusiveDurableFile: () => publishExclusiveDurableFile,
|
|
31
30
|
syncDurableDirectory: () => syncDurableDirectory,
|
|
32
|
-
syncDurableFile: () => syncDurableFile,
|
|
33
31
|
writeAtomicDurableFile: () => writeAtomicDurableFile
|
|
34
32
|
});
|
|
35
33
|
/** Publish a new file without replacing a concurrent winner. */
|
|
@@ -160,4 +158,4 @@ function isNoEntryError(error) {
|
|
|
160
158
|
//#endregion
|
|
161
159
|
export { syncDurableDirectory as a, publishExclusiveDurableFile as i, assertNoSymlinkDescendant as n, writeAtomicDurableFile as o, durable_file_exports as r, __exportAll as s, appendDurableFile as t };
|
|
162
160
|
|
|
163
|
-
//# sourceMappingURL=durable-file-
|
|
161
|
+
//# sourceMappingURL=durable-file-gNI9ILAn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable-file-gNI9ILAn.js","names":["fsConstants"],"sources":["../src/runtime/supervise/durable-file.ts"],"sourcesContent":["/**\n * Small filesystem durability primitives for Runtime-owned state.\n *\n * Callers must validate their path and parent directory before invoking these functions.\n * The exclusive writer protects a no-clobber publication race; the atomic writer replaces one\n * state file after its temporary contents reach stable storage.\n *\n * @internal\n */\n\nimport { randomUUID } from 'node:crypto'\nimport {\n closeSync,\n existsSync,\n fchmodSync,\n constants as fsConstants,\n fsyncSync,\n linkSync,\n lstatSync,\n openSync,\n renameSync,\n statSync,\n unlinkSync,\n writeFileSync,\n writeSync,\n} from 'node:fs'\nimport { dirname, join, relative, resolve } from 'node:path'\n\ninterface DurableFileOptions {\n readonly mode?: number\n}\n\n/** Publish a new file without replacing a concurrent winner. */\nexport function publishExclusiveDurableFile(\n filePath: string,\n content: string,\n options: DurableFileOptions = {},\n): boolean {\n const temporaryPath = `${filePath}.${randomUUID()}.tmp`\n let operationFailed = false\n let operationError: unknown\n let published = false\n try {\n writeExclusiveDurableFile(temporaryPath, content, options)\n try {\n linkSync(temporaryPath, filePath)\n syncDurableDirectory(dirname(filePath))\n published = true\n } catch (error) {\n if (!isAlreadyExistsError(error)) throw error\n }\n } catch (error) {\n operationFailed = true\n operationError = error\n }\n let cleanupError: unknown\n try {\n unlinkSync(temporaryPath)\n } catch (error) {\n if (!isNoEntryError(error)) cleanupError = error\n }\n if (operationFailed) throw operationError\n if (cleanupError !== undefined) throw cleanupError\n return published\n}\n\n/** Fsync a directory after publishing a durable file entry. */\nexport function syncDurableDirectory(directoryPath: string): void {\n const fd = openSync(directoryPath, 'r')\n try {\n fsyncSync(fd)\n } finally {\n closeSync(fd)\n }\n}\n\n/** Fsync one durable file after its contents reach stable storage. */\nfunction syncDurableFile(filePath: string, exactMode?: number): void {\n const fd = openSync(filePath, 'r')\n try {\n if (exactMode !== undefined && process.platform !== 'win32') fchmodSync(fd, exactMode)\n fsyncSync(fd)\n } finally {\n closeSync(fd)\n }\n}\n\n/** Append one record with O_APPEND, then fsync the file and containing directory. */\nexport function appendDurableFile(\n filePath: string,\n content: string,\n options: DurableFileOptions = {},\n): void {\n const flags =\n fsConstants.O_APPEND |\n fsConstants.O_CREAT |\n fsConstants.O_WRONLY |\n (typeof fsConstants.O_NOFOLLOW === 'number' ? fsConstants.O_NOFOLLOW : 0)\n const fd = openSync(filePath, flags, options.mode ?? 0o600)\n try {\n if (process.platform !== 'win32') fchmodSync(fd, options.mode ?? 0o600)\n const expectedBytes = Buffer.byteLength(content, 'utf8')\n const writtenBytes = writeSync(fd, content, undefined, 'utf8')\n if (writtenBytes !== expectedBytes) {\n throw new Error(\n `durable append wrote ${writtenBytes} of ${expectedBytes} bytes to '${filePath}'`,\n )\n }\n fsyncSync(fd)\n } finally {\n closeSync(fd)\n }\n syncDurableDirectory(dirname(filePath))\n}\n\n/** Reject a path that escapes its run directory or traverses a symbolic link. */\nexport function assertNoSymlinkDescendant(root: string, target: string, label = 'path'): void {\n const base = resolve(root)\n const exact = resolve(target)\n const rel = relative(base, exact)\n if (rel === '..' || rel.startsWith(`..${process.platform === 'win32' ? '\\\\' : '/'}`)) {\n throw new Error(`${label} path escapes its run directory`)\n }\n if (existsSync(base) && lstatSync(base).isSymbolicLink()) {\n throw new Error(`${label} path contains a symbolic link: ${base}`)\n }\n let current = base\n for (const part of rel.split(/[\\\\/]/u).filter(Boolean)) {\n current = join(current, part)\n if (!existsSync(current)) continue\n if (lstatSync(current).isSymbolicLink()) {\n throw new Error(`${label} path contains a symbolic link: ${current}`)\n }\n }\n}\n\n/** Write, fsync, atomically replace, and fsync one Runtime-owned state file.\n * preserveMode retains ordinary access permissions despite the current umask; a new\n * file keeps normal creation semantics. Callers still own path validation and write exclusion. */\nexport function writeAtomicDurableFile(\n filePath: string,\n content: string,\n options: DurableFileOptions & { readonly preserveMode?: boolean } = {},\n): void {\n const temporaryPath = `${filePath}.${randomUUID()}.tmp`\n let operationFailed = false\n let operationError: unknown\n try {\n let mode = options.mode\n let exactMode = false\n if (options.preserveMode) {\n try {\n mode = statSync(filePath).mode & 0o777\n exactMode = true\n } catch (error) {\n if (!isNoEntryError(error)) throw error\n }\n }\n writeExclusiveDurableFile(temporaryPath, content, { mode }, exactMode)\n renameSync(temporaryPath, filePath)\n syncDurableDirectory(dirname(filePath))\n } catch (error) {\n operationFailed = true\n operationError = error\n }\n let cleanupError: unknown\n try {\n unlinkSync(temporaryPath)\n } catch (error) {\n if (!isNoEntryError(error)) cleanupError = error\n // A successful rename removes the temporary directory entry.\n }\n if (operationFailed) throw operationError\n if (cleanupError !== undefined) throw cleanupError\n}\n\nfunction writeExclusiveDurableFile(\n filePath: string,\n content: string,\n options: DurableFileOptions,\n exactMode = false,\n): void {\n if (options.mode === undefined) {\n writeFileSync(filePath, content, { encoding: 'utf8', flag: 'wx' })\n } else {\n writeFileSync(filePath, content, { encoding: 'utf8', flag: 'wx', mode: options.mode })\n }\n syncDurableFile(filePath, exactMode ? options.mode : undefined)\n}\n\nfunction isAlreadyExistsError(error: unknown): boolean {\n return (\n error !== null &&\n typeof error === 'object' &&\n 'code' in error &&\n (error as { code?: unknown }).code === 'EEXIST'\n )\n}\n\nfunction isNoEntryError(error: unknown): boolean {\n return (\n error !== null &&\n typeof error === 'object' &&\n 'code' in error &&\n (error as { code?: unknown }).code === 'ENOENT'\n )\n}\n"],"mappings":"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"}
|
package/dist/durable.d.ts
CHANGED
|
@@ -1,37 +1,5 @@
|
|
|
1
|
-
import { $
|
|
2
|
-
|
|
3
|
-
/** The root stream: one JSONL line per progress event the root's executor observed. */
|
|
4
|
-
declare const ROOT_STREAM_FILE = "root-stream.jsonl";
|
|
5
|
-
/** One line of `root-stream.jsonl`. */
|
|
6
|
-
type RootStreamRecord = {
|
|
7
|
-
/** 1-based position in the file, continuing across drive attempts and across processes. */
|
|
8
|
-
readonly seq: number;
|
|
9
|
-
/** ISO instant the line was appended, from the run's own clock. */
|
|
10
|
-
readonly at: string;
|
|
11
|
-
/** The 1-based drive attempt of the root that produced it: a driver retry or re-prompt
|
|
12
|
-
* re-enters the harness and continues the same file with the next attempt number. */
|
|
13
|
-
readonly attempt: number;
|
|
14
|
-
} & ({
|
|
15
|
-
readonly event: ExecutorProgressEvent;
|
|
16
|
-
} | {
|
|
17
|
-
/** The event could not be written as JSON; its kind and the reason stand in so the gap
|
|
18
|
-
* is recorded in the file itself instead of silently narrowing the stream. */
|
|
19
|
-
readonly dropped: {
|
|
20
|
-
readonly kind: ExecutorProgressEvent['kind'];
|
|
21
|
-
readonly reason: string;
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
/**
|
|
25
|
-
* The receipt for the root stream a run directory holds, recomputed from the file's bytes, or
|
|
26
|
-
* `undefined` when the directory holds none. This is what a run that never settled — a root that
|
|
27
|
-
* died mid-turn — gets on its failure record, and it equals what `close()` returned for a run
|
|
28
|
-
* that did.
|
|
29
|
-
*/
|
|
30
|
-
declare function readRootStreamReceipt(runDir: string): Promise<RootStreamReceipt | undefined>;
|
|
31
|
-
/** Every committed line of the root stream, in order, or `undefined` when there is no file. A
|
|
32
|
-
* torn final line from a process that died mid-write is not a record and is left out. */
|
|
33
|
-
declare function readRootStream(runDir: string): Promise<RootStreamRecord[] | undefined>;
|
|
34
|
-
//#endregion
|
|
1
|
+
import { $l as PursuitVersions, Bd as RootStreamRecord, Bv as MapOnSettleRoute, Cu as projectPursuit, D as RetainedPendingCause, Dd as DeadlineCheckIn, Du as ObserverRecordKind, Eu as ObserverRecord, Ey as AnalyzeOnSettleRoute, Hd as readRootStreamReceipt, Jf as CoordinationTransportOptions, Jl as JudgedPursuitVersion, Kf as CoordinationPublicAddress, Km as ToolLoopCompactionOptions, Ku as AuthorizedSpawn, Nv as ContinuityMode, Ou as observerRecordDigest, Pv as DownMessageAuthorizationInput, Ql as PursuitVersionStop, Su as PursuitStatus, Tu as ObserverJournal, V as NodeId, Vd as readRootStream, Wf as CoordinationAuthentication, Xf as CoordinationHttpAudit, Xl as NextPursuitVersionInput, Xu as WorkerSlots, Yl as NextPursuitVersion, Zf as CoordinationRejectReason, Zl as PursuitVersionChain, _u as PursuitNodeTiming, au as SupervisePursuitError, bu as PursuitRunProjection, cf as DriveHarnessOwnerContext, cu as superviseGraphPursuit, cv as WorkerWatchOptions, du as RUN_FORK_CORRELATION_KEYS, eu as SettledPursuitVersion, fd as SelectSeat, fu as PursuitObserverDelivery, gu as PursuitNodeProjection, hu as PursuitNodePlatform, it as SupervisedResult, iu as SuperviseGraphPursuitOptions, jv as AuthorizedDownMessage, ld as SeatSelection, lu as supervisePursuit, mu as PursuitNodeCost, nu as VersionVerdict, ou as SupervisePursuitOptions, pu as PursuitCostProvenance, qf as CoordinationReadAccess, qu as AuthorizedSpawnContext, rt as RootStreamReceipt, ru as assertPursuitVersions, su as SupervisedPursuitResult, tu as VersionJudge, ud as SeatSelectionInput, uf as ResolveDriveHarness, uu as PursuitFork, vf as ManagerWakePolicy, vu as PursuitNodeUsage, vv as EscalateQuestion, wu as FileObserverJournal, xu as PursuitRunTotals, xv as QuestionEscalationOutcome, yu as PursuitProjection } from "./types-CaOXqRTq.js";
|
|
2
|
+
import { n as RuntimeDecisionKind, r as RuntimeDecisionPoint, t as RuntimeDecisionEvidenceRef } from "./runtime-hooks-nsqxSUFL.js";
|
|
35
3
|
//#region src/durable/chat-engine.d.ts
|
|
36
4
|
/**
|
|
37
5
|
* `handleChatTurn` is a framework-neutral chat-turn HTTP orchestrator.
|
|
@@ -289,5 +257,5 @@ interface DurableSupervisionDiscovery {
|
|
|
289
257
|
*/
|
|
290
258
|
declare function discoverDurableSupervisionRun(runDir: string): Promise<DurableSupervisionDiscovery>;
|
|
291
259
|
//#endregion
|
|
292
|
-
export { type ChatStreamEvent, type ChatTurnHooks, type ChatTurnIdentity, type ChatTurnProducer, type ChatTurnResult, type DurableCoordinationStreamIdentity, type DurableFailureRecord, type DurableSupervisionDiscovery, FileObserverJournal, type JudgedPursuitVersion, type NextPursuitVersion, type NextPursuitVersionInput, type ObserverJournal, type ObserverRecord, type ObserverRecordKind, type PursuitCostProvenance, type PursuitFork, type PursuitNodeCost, type
|
|
260
|
+
export { type AnalyzeOnSettleRoute, type AuthorizedDownMessage, type AuthorizedSpawn, type AuthorizedSpawnContext, type ChatStreamEvent, type ChatTurnHooks, type ChatTurnIdentity, type ChatTurnProducer, type ChatTurnResult, type ContinuityMode, type CoordinationAuthentication, type CoordinationHttpAudit, type CoordinationPublicAddress, type CoordinationReadAccess, type CoordinationRejectReason, type CoordinationTransportOptions, type DeadlineCheckIn, type DownMessageAuthorizationInput, type DriveHarnessOwnerContext, type DurableCoordinationStreamIdentity, type DurableFailureRecord, type DurableSupervisionDiscovery, type EscalateQuestion, FileObserverJournal, type JudgedPursuitVersion, type ManagerWakePolicy, type MapOnSettleRoute, type NextPursuitVersion, type NextPursuitVersionInput, type ObserverJournal, type ObserverRecord, type ObserverRecordKind, type PursuitCostProvenance, type PursuitFork, type PursuitNodeCost, type PursuitNodePlatform, type PursuitNodeProjection, type PursuitNodeTiming, type PursuitNodeUsage, type PursuitObserverDelivery, type PursuitProjection, type PursuitRunProjection, type PursuitRunTotals, type PursuitStatus, type PursuitVersionChain, type PursuitVersionStop, type PursuitVersions, type QuestionEscalationOutcome, RUN_FORK_CORRELATION_KEYS, type ResolveDriveHarness, type RetainedPendingCause, type RootStreamRecord, type RunChatTurnInput, type RunDirectoryHolderLiveness, type RunDirectoryLock, type RunDirectoryLockHolder, RunDirectoryLockedError, type RuntimeDecisionEvidenceRef, type RuntimeDecisionKind, type RuntimeDecisionPoint, type SeatSelection, type SeatSelectionInput, type SelectSeat, type SettledPursuitVersion, SettledRunDirectoryError, type SuperviseGraphPursuitOptions, SupervisePursuitError, type SupervisePursuitOptions, type SupervisedPursuitResult, type ToolLoopCompactionOptions, type VersionJudge, type VersionVerdict, type WorkerSlots, type WorkerWatchOptions, acquireRunDirectoryLock, assertPursuitVersions, deriveExecutionId, discoverDurableSupervisionRun, handleChatTurn, observerRecordDigest, projectPursuit, readFailureRecord, readRootStream, readRootStreamReceipt, readRunDirectoryLock, readSettleRecord, runDirectoryHolderIsLive, superviseGraphPursuit, supervisePursuit };
|
|
293
261
|
//# sourceMappingURL=durable.d.ts.map
|
package/dist/durable.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { i as publishExclusiveDurableFile, o as writeAtomicDurableFile } from "./durable-file-
|
|
2
|
-
import {
|
|
1
|
+
import { i as publishExclusiveDurableFile, o as writeAtomicDurableFile } from "./durable-file-gNI9ILAn.js";
|
|
2
|
+
import { Di as contentAddress, Ei as detachedSnapshot, S as FileSpawnJournal, ar as isFiniteNumber, ir as failedItems, it as loadSpawnForest, qr as authoredProfileDigest } from "./supervisor-DHrUJhEZ.js";
|
|
3
3
|
import { f as RuntimeRunStateError, m as ValidationError } from "./errors-DodWX-cb.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { t as isRecord } from "./record-value-B6bwJxLa.js";
|
|
5
|
+
import { G as addSpend, J as cloneSpend, Z as errorMessage, pt as zeroSpend } from "./sandbox-profile-compat-BzVBFqrz.js";
|
|
6
6
|
import { a as withPursuitContext, t as composeRuntimeHooks } from "./runtime-hooks-tXpAarhW.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { a as readCommittedJsonLines, n as isNoEntError, t as appendCommittedJsonLine } from "./jsonl-file-C9Kde_0Z.js";
|
|
8
|
+
import { J as readRootStreamReceipt, a as superviseRootProfile, q as readRootStream, t as supervise } from "./supervise-qAwXmPtD.js";
|
|
9
|
+
import { a as applyExactAgentProfileDiff } from "./profile-Dpei_Sq0.js";
|
|
10
|
+
import { g as supervisorRunDir } from "./run-cancellation-C9oL62sW.js";
|
|
11
|
+
import { i as superviseAgentGraph } from "./graph-CI9JXKqO.js";
|
|
11
12
|
import { agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, canonicalCandidateJson, sha256Bytes } from "@tangle-network/agent-interface";
|
|
12
13
|
import { createHash } from "node:crypto";
|
|
13
14
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
@@ -948,13 +949,13 @@ function jsonValue(result) {
|
|
|
948
949
|
function settleRecordJson(result) {
|
|
949
950
|
return canonicalCandidateJson(jsonValue(result));
|
|
950
951
|
}
|
|
951
|
-
/** Publish `
|
|
952
|
+
/** Publish `result.json` in the run directory once. Throws when a record is already there. */
|
|
952
953
|
async function writeSettleRecord(runDir, result) {
|
|
953
954
|
const path = resolve(runDir, SETTLE_RECORD_FILE);
|
|
954
955
|
if (!publishExclusiveDurableFile(path, settleRecordJson(result))) throw new Error(`supervisePursuit: ${path} already exists; a settle record is written once`);
|
|
955
956
|
return path;
|
|
956
957
|
}
|
|
957
|
-
/** Replace `
|
|
958
|
+
/** Replace `failure.json` in the run directory with the most recent throw. */
|
|
958
959
|
async function writeFailureRecord(runDir, record) {
|
|
959
960
|
const path = resolve(runDir, FAILURE_RECORD_FILE);
|
|
960
961
|
writeAtomicDurableFile(path, `${JSON.stringify(record, null, 2)}\n`);
|
|
@@ -1008,6 +1009,214 @@ async function readFailureRecord(runDir) {
|
|
|
1008
1009
|
return parsed;
|
|
1009
1010
|
}
|
|
1010
1011
|
//#endregion
|
|
1012
|
+
//#region src/durable/pursuit-version-evidence.ts
|
|
1013
|
+
/** The chain's directory beside the first version's: the ledger and its content blobs. */
|
|
1014
|
+
function pursuitVersionsLedgerPath(runDir) {
|
|
1015
|
+
return resolve(`${resolve(runDir.trim())}.search`, "ledger.jsonl");
|
|
1016
|
+
}
|
|
1017
|
+
/** The bytes of a version's sealed `result.json` and the record they hold, parsed from the same
|
|
1018
|
+
* bytes that are hashed. */
|
|
1019
|
+
async function readSealed(runDir, version) {
|
|
1020
|
+
const path = resolve(runDir, SETTLE_RECORD_FILE);
|
|
1021
|
+
let bytes;
|
|
1022
|
+
try {
|
|
1023
|
+
bytes = await readFile(path);
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
if (!isNoEntError(error)) throw error;
|
|
1026
|
+
throw new RuntimeRunStateError(`supervisePursuit versions: version ${version} has no settle record in ${runDir}`);
|
|
1027
|
+
}
|
|
1028
|
+
return {
|
|
1029
|
+
bytes,
|
|
1030
|
+
result: parseSettleRecord(Buffer.from(bytes).toString("utf8"), path)
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
/** A profile as the JSON the ledger stores: validated, with undefined entries absent. */
|
|
1034
|
+
function jsonProfile(profile) {
|
|
1035
|
+
canonicalAgentProfileDigest(profile);
|
|
1036
|
+
return JSON.parse(JSON.stringify(agentProfileSchema.parse(profile)));
|
|
1037
|
+
}
|
|
1038
|
+
function loadNode(store, node) {
|
|
1039
|
+
const stored = store.readBlob(node.artifact);
|
|
1040
|
+
if (stored.kind === "agent-profile") {
|
|
1041
|
+
const parsed = agentProfileSchema.safeParse(stored.profile);
|
|
1042
|
+
if (!parsed.success) throw new RuntimeRunStateError(`version node ${node.nodeId} holds an invalid AgentProfile`);
|
|
1043
|
+
return {
|
|
1044
|
+
profile: parsed.data,
|
|
1045
|
+
refusal: null
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
if (stored.kind === "unapplied-change") return {
|
|
1049
|
+
profile: null,
|
|
1050
|
+
...stored.change ? { change: stored.change } : {},
|
|
1051
|
+
...stored.parentDigest ? { parentDigest: stored.parentDigest } : {},
|
|
1052
|
+
refusal: stored.refusal ?? "the change did not apply"
|
|
1053
|
+
};
|
|
1054
|
+
throw new RuntimeRunStateError(`version node ${node.nodeId} holds no version artifact`);
|
|
1055
|
+
}
|
|
1056
|
+
/** The `<runDir>.v<n>` directory and `<runId>.v<n>` id of version `n`, beside the first. */
|
|
1057
|
+
function versionRun(runDir, runId, version) {
|
|
1058
|
+
return version === 1 ? {
|
|
1059
|
+
runDir,
|
|
1060
|
+
runId
|
|
1061
|
+
} : {
|
|
1062
|
+
runDir: `${runDir}.v${version}`,
|
|
1063
|
+
runId: `${runId}.v${version}`
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
/** A version's settled spend as the ledger's accounting. Unknown dollars carry the part a
|
|
1067
|
+
* provider is known to have billed as their floor. */
|
|
1068
|
+
function versionAccounting(spent) {
|
|
1069
|
+
const tokensKnown = spent !== void 0 && spent.tokensKnown !== false && spent.tokens?.tokensKnown !== false && Number.isSafeInteger(spent.tokens?.input) && Number.isSafeInteger(spent.tokens?.output) && Number.isSafeInteger(spent.tokens?.cacheRead);
|
|
1070
|
+
const usdKnown = spent !== void 0 && spent.usdKnown !== false && isFiniteNumber(spent.usd);
|
|
1071
|
+
return {
|
|
1072
|
+
tokens: tokensKnown ? {
|
|
1073
|
+
status: "known",
|
|
1074
|
+
inputTokens: spent.tokens.input,
|
|
1075
|
+
outputTokens: spent.tokens.output,
|
|
1076
|
+
cachedTokens: spent.tokens.cacheRead
|
|
1077
|
+
} : {
|
|
1078
|
+
status: "unknown",
|
|
1079
|
+
reason: `the version's settled spend reports no complete token count with its cache split (input ${spent?.tokens?.input ?? "none"}, output ${spent?.tokens?.output ?? "none"})`
|
|
1080
|
+
},
|
|
1081
|
+
cost: usdKnown ? {
|
|
1082
|
+
status: "known",
|
|
1083
|
+
usd: spent.usd,
|
|
1084
|
+
source: "provider"
|
|
1085
|
+
} : {
|
|
1086
|
+
status: "unknown",
|
|
1087
|
+
knownLowerBoundUsd: Math.max(0, isFiniteNumber(spent?.usd) ? spent.usd - (spent.usdEstimated ?? 0) : 0),
|
|
1088
|
+
reason: "the version's settled spend names unpriced or unreported work"
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
/** How long a version that settled before its chain opened ran, from its settle record. */
|
|
1093
|
+
function settledElapsed(settled) {
|
|
1094
|
+
const elapsed = settled?.spentTotal?.ms;
|
|
1095
|
+
return isFiniteNumber(elapsed) ? elapsed : 0;
|
|
1096
|
+
}
|
|
1097
|
+
const FREE = {
|
|
1098
|
+
tokens: {
|
|
1099
|
+
status: "known",
|
|
1100
|
+
inputTokens: 0,
|
|
1101
|
+
outputTokens: 0,
|
|
1102
|
+
cachedTokens: 0
|
|
1103
|
+
},
|
|
1104
|
+
cost: {
|
|
1105
|
+
status: "known",
|
|
1106
|
+
usd: 0,
|
|
1107
|
+
source: "free"
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
/**
|
|
1111
|
+
* What a version that did no work failed with: a driver error, by its name and its message with
|
|
1112
|
+
* the parts that differ between runs (digits, hex runs, absolute paths) normalized, or an unscored
|
|
1113
|
+
* verdict. Null for a version that ran, won or not.
|
|
1114
|
+
*/
|
|
1115
|
+
function versionFailure(version) {
|
|
1116
|
+
if (version.verdict.score === null) return "unscored by the judge";
|
|
1117
|
+
const { result } = version;
|
|
1118
|
+
if (result.kind !== "no-winner" || result.reason !== "driver-failed") return null;
|
|
1119
|
+
const message = result.error.message.replace(/(?:\/[\w.@~+-]+){2,}/gu, "<path>").replace(/\b[0-9a-f]{8,}\b/giu, "<hex>").replace(/\d+/gu, "<n>").slice(0, 500);
|
|
1120
|
+
return `driver-failed: ${result.error.name}: ${message}`;
|
|
1121
|
+
}
|
|
1122
|
+
function pursuitValueDigest(value, name) {
|
|
1123
|
+
try {
|
|
1124
|
+
return canonicalCandidateDigest(value);
|
|
1125
|
+
} catch (error) {
|
|
1126
|
+
throw new ValidationError(`supervisePursuit versions: the ${name} must be canonical JSON to pin the chain: ${errorMessage(error)}`);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
async function exists(path) {
|
|
1130
|
+
try {
|
|
1131
|
+
await access(path);
|
|
1132
|
+
return true;
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
if (isNoEntError(error)) return false;
|
|
1135
|
+
throw error;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
function isSha256(value) {
|
|
1139
|
+
return typeof value === "string" && /^sha256:[0-9a-f]{64}$/u.test(value);
|
|
1140
|
+
}
|
|
1141
|
+
//#endregion
|
|
1142
|
+
//#region src/durable/pursuit-version-review.ts
|
|
1143
|
+
/** Where `'review-of-best'` mounts a review: `inputs/review/version-<n>.md`. One review lives in
|
|
1144
|
+
* a profile at a time. */
|
|
1145
|
+
const REVIEW_DIR = "inputs/review/";
|
|
1146
|
+
/**
|
|
1147
|
+
* `'review-of-best'`: fork from the kept version with its check's verdict mounted under
|
|
1148
|
+
* {@link REVIEW_DIR} and the profile's review words as one instruction. The previous review's
|
|
1149
|
+
* mount and instruction are removed, so a profile carries one review.
|
|
1150
|
+
*/
|
|
1151
|
+
function reviewOfBest(runId, words) {
|
|
1152
|
+
return ({ best, versions }) => {
|
|
1153
|
+
const n = versions.length + 1;
|
|
1154
|
+
const verdict = best.verdict.check;
|
|
1155
|
+
const path = `${REVIEW_DIR}version-${best.version}.md`;
|
|
1156
|
+
const instruction = words.replaceAll("{version}", String(best.version)).replaceAll("{path}", path).replaceAll("{score}", best.verdict.score === null ? "none" : String(best.verdict.score)).trim();
|
|
1157
|
+
const page = reviewPage(best.version, best.verdict.score, verdict);
|
|
1158
|
+
const earlier = best.change?.set?.prompt?.instructions ?? [];
|
|
1159
|
+
const earlierInstructions = earlier.filter((text) => text !== instruction);
|
|
1160
|
+
const earlierMounts = (best.profile.resources?.files ?? []).map((file) => file.path).filter((mounted) => mounted.startsWith(REVIEW_DIR) && mounted !== path);
|
|
1161
|
+
return {
|
|
1162
|
+
kind: "agent-profile-diff",
|
|
1163
|
+
id: `${runId}-v${n}-review-of-v${best.version}`,
|
|
1164
|
+
title: `Version ${n}: review of version ${best.version}`,
|
|
1165
|
+
source: {
|
|
1166
|
+
kind: "optimizer",
|
|
1167
|
+
notes: [`review-of-best: version ${best.version}`, `judge ${best.verdict.judgeDigest}`]
|
|
1168
|
+
},
|
|
1169
|
+
set: {
|
|
1170
|
+
...earlier.includes(instruction) ? {} : { prompt: { instructions: [instruction] } },
|
|
1171
|
+
resources: { files: [{
|
|
1172
|
+
path,
|
|
1173
|
+
resource: {
|
|
1174
|
+
kind: "inline",
|
|
1175
|
+
name: path,
|
|
1176
|
+
content: page
|
|
1177
|
+
}
|
|
1178
|
+
}] }
|
|
1179
|
+
},
|
|
1180
|
+
...earlierInstructions.length > 0 || earlierMounts.length > 0 ? { remove: {
|
|
1181
|
+
...earlierInstructions.length > 0 ? { prompt: { instructions: [...earlierInstructions] } } : {},
|
|
1182
|
+
...earlierMounts.length > 0 ? { resources: { files: earlierMounts } } : {}
|
|
1183
|
+
} } : {}
|
|
1184
|
+
};
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
/** The review page: facts only, in the check's own lines. */
|
|
1188
|
+
function reviewPage(version, score, verdict) {
|
|
1189
|
+
if (verdict === void 0) return [
|
|
1190
|
+
`# Version ${version}`,
|
|
1191
|
+
"",
|
|
1192
|
+
`Score: ${score ?? "none"}. The judge reported no per-item verdict.`,
|
|
1193
|
+
""
|
|
1194
|
+
].join("\n");
|
|
1195
|
+
const failing = failedItems(verdict);
|
|
1196
|
+
return [
|
|
1197
|
+
`# Version ${version}`,
|
|
1198
|
+
"",
|
|
1199
|
+
`Score: ${score ?? "none"}.${verdict.threshold === void 0 ? "" : ` The check passes at ${verdict.threshold}.`}`,
|
|
1200
|
+
"",
|
|
1201
|
+
"## Items",
|
|
1202
|
+
"",
|
|
1203
|
+
...Object.entries(verdict.items ?? {}).map(([item, value]) => `- ${item}: ${value >= 1 ? "passes" : `fails (${value})`}`),
|
|
1204
|
+
"",
|
|
1205
|
+
...failing.length === 0 ? [] : [
|
|
1206
|
+
"## Failures",
|
|
1207
|
+
"",
|
|
1208
|
+
...verdict.failures ?? [],
|
|
1209
|
+
""
|
|
1210
|
+
],
|
|
1211
|
+
...verdict.review === void 0 ? [] : [
|
|
1212
|
+
"## The check's review",
|
|
1213
|
+
"",
|
|
1214
|
+
verdict.review,
|
|
1215
|
+
""
|
|
1216
|
+
]
|
|
1217
|
+
].join("\n");
|
|
1218
|
+
}
|
|
1219
|
+
//#endregion
|
|
1011
1220
|
//#region src/durable/pursuit-versions.ts
|
|
1012
1221
|
/**
|
|
1013
1222
|
* The pursuit version chain, on Eval's search kernel (`runSearch`).
|
|
@@ -1020,13 +1229,6 @@ async function readFailureRecord(runDir) {
|
|
|
1020
1229
|
* at `<runDir>.search/ledger.jsonl` is the chain's only record and its only checkpoint: a call on
|
|
1021
1230
|
* a closed chain reads it back, and a call on an open chain continues it.
|
|
1022
1231
|
*/
|
|
1023
|
-
/** Where `'review-of-best'` mounts a review: `inputs/review/version-<n>.md`. One review lives in
|
|
1024
|
-
* a profile at a time. */
|
|
1025
|
-
const REVIEW_DIR = "inputs/review/";
|
|
1026
|
-
/** The chain's directory beside the first version's: the ledger and its content blobs. */
|
|
1027
|
-
function pursuitVersionsLedgerPath(runDir) {
|
|
1028
|
-
return resolve(`${resolve(runDir.trim())}.search`, "ledger.jsonl");
|
|
1029
|
-
}
|
|
1030
1232
|
/**
|
|
1031
1233
|
* Validate a `versions` option before any compute. The same check runs inside `supervisePursuit`;
|
|
1032
1234
|
* a caller that records the option as data can run it at preflight.
|
|
@@ -1108,7 +1310,7 @@ async function runPursuitVersions(profile, task, opts, runOne) {
|
|
|
1108
1310
|
const retired = resolve(`${runDir}.versions`, "versions.jsonl");
|
|
1109
1311
|
if (await exists(retired)) throw new ValidationError(`supervisePursuit versions: ${retired} holds a chain in the retired versions.jsonl format; finish it on the agent-runtime release that wrote it, or start a new chain in another runDir`);
|
|
1110
1312
|
const firstProfile = jsonProfile(firstFork === void 0 ? profile : applyExactAgentProfileDiff(profile, firstFork.change, "supervisePursuit versions"));
|
|
1111
|
-
const taskRevision =
|
|
1313
|
+
const taskRevision = pursuitValueDigest(task, "task");
|
|
1112
1314
|
const identity = (nodeProfile) => ({
|
|
1113
1315
|
model: {
|
|
1114
1316
|
provider: "agent-runtime",
|
|
@@ -1606,99 +1808,6 @@ async function runPursuitVersions(profile, task, opts, runOne) {
|
|
|
1606
1808
|
return chain;
|
|
1607
1809
|
}
|
|
1608
1810
|
}
|
|
1609
|
-
/** The bytes of a version's sealed `result.json` and the record they hold, parsed from the same
|
|
1610
|
-
* bytes that are hashed. */
|
|
1611
|
-
async function readSealed(runDir, version) {
|
|
1612
|
-
const path = resolve(runDir, SETTLE_RECORD_FILE);
|
|
1613
|
-
let bytes;
|
|
1614
|
-
try {
|
|
1615
|
-
bytes = await readFile(path);
|
|
1616
|
-
} catch (error) {
|
|
1617
|
-
if (!isNoEntError(error)) throw error;
|
|
1618
|
-
throw new RuntimeRunStateError(`supervisePursuit versions: version ${version} has no settle record in ${runDir}`);
|
|
1619
|
-
}
|
|
1620
|
-
return {
|
|
1621
|
-
bytes,
|
|
1622
|
-
result: parseSettleRecord(Buffer.from(bytes).toString("utf8"), path)
|
|
1623
|
-
};
|
|
1624
|
-
}
|
|
1625
|
-
/** A profile as the JSON the ledger stores: validated, with undefined entries absent. */
|
|
1626
|
-
function jsonProfile(profile) {
|
|
1627
|
-
canonicalAgentProfileDigest(profile);
|
|
1628
|
-
return JSON.parse(JSON.stringify(agentProfileSchema.parse(profile)));
|
|
1629
|
-
}
|
|
1630
|
-
function loadNode(store, node) {
|
|
1631
|
-
const stored = store.readBlob(node.artifact);
|
|
1632
|
-
if (stored.kind === "agent-profile") {
|
|
1633
|
-
const parsed = agentProfileSchema.safeParse(stored.profile);
|
|
1634
|
-
if (!parsed.success) throw new RuntimeRunStateError(`version node ${node.nodeId} holds an invalid AgentProfile`);
|
|
1635
|
-
return {
|
|
1636
|
-
profile: parsed.data,
|
|
1637
|
-
refusal: null
|
|
1638
|
-
};
|
|
1639
|
-
}
|
|
1640
|
-
if (stored.kind === "unapplied-change") return {
|
|
1641
|
-
profile: null,
|
|
1642
|
-
...stored.change ? { change: stored.change } : {},
|
|
1643
|
-
...stored.parentDigest ? { parentDigest: stored.parentDigest } : {},
|
|
1644
|
-
refusal: stored.refusal ?? "the change did not apply"
|
|
1645
|
-
};
|
|
1646
|
-
throw new RuntimeRunStateError(`version node ${node.nodeId} holds no version artifact`);
|
|
1647
|
-
}
|
|
1648
|
-
/** The `<runDir>.v<n>` directory and `<runId>.v<n>` id of version `n`, beside the first. */
|
|
1649
|
-
function versionRun(runDir, runId, version) {
|
|
1650
|
-
return version === 1 ? {
|
|
1651
|
-
runDir,
|
|
1652
|
-
runId
|
|
1653
|
-
} : {
|
|
1654
|
-
runDir: `${runDir}.v${version}`,
|
|
1655
|
-
runId: `${runId}.v${version}`
|
|
1656
|
-
};
|
|
1657
|
-
}
|
|
1658
|
-
/** A version's settled spend as the ledger's accounting. Unknown dollars carry the part a
|
|
1659
|
-
* provider is known to have billed as their floor. */
|
|
1660
|
-
function versionAccounting(spent) {
|
|
1661
|
-
const tokensKnown = spent !== void 0 && spent.tokensKnown !== false && spent.tokens?.tokensKnown !== false && Number.isSafeInteger(spent.tokens?.input) && Number.isSafeInteger(spent.tokens?.output) && Number.isSafeInteger(spent.tokens?.cacheRead);
|
|
1662
|
-
const usdKnown = spent !== void 0 && spent.usdKnown !== false && isFiniteNumber(spent.usd);
|
|
1663
|
-
return {
|
|
1664
|
-
tokens: tokensKnown ? {
|
|
1665
|
-
status: "known",
|
|
1666
|
-
inputTokens: spent.tokens.input,
|
|
1667
|
-
outputTokens: spent.tokens.output,
|
|
1668
|
-
cachedTokens: spent.tokens.cacheRead
|
|
1669
|
-
} : {
|
|
1670
|
-
status: "unknown",
|
|
1671
|
-
reason: `the version's settled spend reports no complete token count with its cache split (input ${spent?.tokens?.input ?? "none"}, output ${spent?.tokens?.output ?? "none"})`
|
|
1672
|
-
},
|
|
1673
|
-
cost: usdKnown ? {
|
|
1674
|
-
status: "known",
|
|
1675
|
-
usd: spent.usd,
|
|
1676
|
-
source: "provider"
|
|
1677
|
-
} : {
|
|
1678
|
-
status: "unknown",
|
|
1679
|
-
knownLowerBoundUsd: Math.max(0, isFiniteNumber(spent?.usd) ? spent.usd - (spent.usdEstimated ?? 0) : 0),
|
|
1680
|
-
reason: "the version's settled spend names unpriced or unreported work"
|
|
1681
|
-
}
|
|
1682
|
-
};
|
|
1683
|
-
}
|
|
1684
|
-
/** How long a version that settled before its chain opened ran, from its settle record. */
|
|
1685
|
-
function settledElapsed(settled) {
|
|
1686
|
-
const elapsed = settled?.spentTotal?.ms;
|
|
1687
|
-
return isFiniteNumber(elapsed) ? elapsed : 0;
|
|
1688
|
-
}
|
|
1689
|
-
const FREE = {
|
|
1690
|
-
tokens: {
|
|
1691
|
-
status: "known",
|
|
1692
|
-
inputTokens: 0,
|
|
1693
|
-
outputTokens: 0,
|
|
1694
|
-
cachedTokens: 0
|
|
1695
|
-
},
|
|
1696
|
-
cost: {
|
|
1697
|
-
status: "known",
|
|
1698
|
-
usd: 0,
|
|
1699
|
-
source: "free"
|
|
1700
|
-
}
|
|
1701
|
-
};
|
|
1702
1811
|
function canonicalStop(stop) {
|
|
1703
1812
|
return {
|
|
1704
1813
|
patience: stop.patience,
|
|
@@ -1710,18 +1819,6 @@ function canonicalStop(stop) {
|
|
|
1710
1819
|
};
|
|
1711
1820
|
}
|
|
1712
1821
|
const DEFAULT_IDENTICAL_FAILURES = 3;
|
|
1713
|
-
/**
|
|
1714
|
-
* What a version that did no work failed with: a driver error, by its name and its message with
|
|
1715
|
-
* the parts that differ between runs (digits, hex runs, absolute paths) normalized, or an unscored
|
|
1716
|
-
* verdict. Null for a version that ran, won or not.
|
|
1717
|
-
*/
|
|
1718
|
-
function versionFailure(version) {
|
|
1719
|
-
if (version.verdict.score === null) return "unscored by the judge";
|
|
1720
|
-
const { result } = version;
|
|
1721
|
-
if (result.kind !== "no-winner" || result.reason !== "driver-failed") return null;
|
|
1722
|
-
const message = result.error.message.replace(/(?:\/[\w.@~+-]+){2,}/gu, "<path>").replace(/\b[0-9a-f]{8,}\b/giu, "<hex>").replace(/\d+/gu, "<n>").slice(0, 500);
|
|
1723
|
-
return `driver-failed: ${result.error.name}: ${message}`;
|
|
1724
|
-
}
|
|
1725
1822
|
/** The failure the last `count` judged versions share, or null when they do not all share one. */
|
|
1726
1823
|
function identicalFailureStreak(versions, count) {
|
|
1727
1824
|
if (versions.length < count) return null;
|
|
@@ -1729,104 +1826,6 @@ function identicalFailureStreak(versions, count) {
|
|
|
1729
1826
|
const [first] = failures;
|
|
1730
1827
|
return first !== null && first !== void 0 && failures.every((failure) => failure === first) ? first : null;
|
|
1731
1828
|
}
|
|
1732
|
-
/**
|
|
1733
|
-
* `'review-of-best'`: fork from the kept version with its check's verdict mounted under
|
|
1734
|
-
* {@link REVIEW_DIR} and the profile's review words as one instruction. The previous review's
|
|
1735
|
-
* mount and instruction are removed, so a profile carries one review.
|
|
1736
|
-
*/
|
|
1737
|
-
function reviewOfBest(runId, words) {
|
|
1738
|
-
return ({ best, versions }) => {
|
|
1739
|
-
const n = versions.length + 1;
|
|
1740
|
-
const verdict = best.verdict.check;
|
|
1741
|
-
const path = `${REVIEW_DIR}version-${best.version}.md`;
|
|
1742
|
-
const instruction = words.replaceAll("{version}", String(best.version)).replaceAll("{path}", path).replaceAll("{score}", best.verdict.score === null ? "none" : String(best.verdict.score)).trim();
|
|
1743
|
-
const page = reviewPage(best.version, best.verdict.score, verdict);
|
|
1744
|
-
const earlier = best.change?.set?.prompt?.instructions ?? [];
|
|
1745
|
-
const earlierInstructions = earlier.filter((text) => text !== instruction);
|
|
1746
|
-
const earlierMounts = (best.profile.resources?.files ?? []).map((file) => file.path).filter((mounted) => mounted.startsWith("inputs/review/") && mounted !== path);
|
|
1747
|
-
return {
|
|
1748
|
-
kind: "agent-profile-diff",
|
|
1749
|
-
id: `${runId}-v${n}-review-of-v${best.version}`,
|
|
1750
|
-
title: `Version ${n}: review of version ${best.version}`,
|
|
1751
|
-
source: {
|
|
1752
|
-
kind: "optimizer",
|
|
1753
|
-
notes: [`review-of-best: version ${best.version}`, `judge ${best.verdict.judgeDigest}`]
|
|
1754
|
-
},
|
|
1755
|
-
set: {
|
|
1756
|
-
...earlier.includes(instruction) ? {} : { prompt: { instructions: [instruction] } },
|
|
1757
|
-
resources: { files: [{
|
|
1758
|
-
path,
|
|
1759
|
-
resource: {
|
|
1760
|
-
kind: "inline",
|
|
1761
|
-
name: path,
|
|
1762
|
-
content: page
|
|
1763
|
-
}
|
|
1764
|
-
}] }
|
|
1765
|
-
},
|
|
1766
|
-
...earlierInstructions.length > 0 || earlierMounts.length > 0 ? { remove: {
|
|
1767
|
-
...earlierInstructions.length > 0 ? { prompt: { instructions: [...earlierInstructions] } } : {},
|
|
1768
|
-
...earlierMounts.length > 0 ? { resources: { files: earlierMounts } } : {}
|
|
1769
|
-
} } : {}
|
|
1770
|
-
};
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
/** The review page: facts only, in the check's own lines. */
|
|
1774
|
-
function reviewPage(version, score, verdict) {
|
|
1775
|
-
if (verdict === void 0) return [
|
|
1776
|
-
`# Version ${version}`,
|
|
1777
|
-
"",
|
|
1778
|
-
`Score: ${score ?? "none"}. The judge reported no per-item verdict.`,
|
|
1779
|
-
""
|
|
1780
|
-
].join("\n");
|
|
1781
|
-
const failing = failedItems(verdict);
|
|
1782
|
-
return [
|
|
1783
|
-
`# Version ${version}`,
|
|
1784
|
-
"",
|
|
1785
|
-
`Score: ${score ?? "none"}.${verdict.threshold === void 0 ? "" : ` The check passes at ${verdict.threshold}.`}`,
|
|
1786
|
-
"",
|
|
1787
|
-
"## Items",
|
|
1788
|
-
"",
|
|
1789
|
-
...Object.entries(verdict.items ?? {}).map(([item, value]) => `- ${item}: ${value >= 1 ? "passes" : `fails (${value})`}`),
|
|
1790
|
-
"",
|
|
1791
|
-
...failing.length === 0 ? [] : [
|
|
1792
|
-
"## Failures",
|
|
1793
|
-
"",
|
|
1794
|
-
...verdict.failures ?? [],
|
|
1795
|
-
""
|
|
1796
|
-
],
|
|
1797
|
-
...verdict.review === void 0 ? [] : [
|
|
1798
|
-
"## The check's review",
|
|
1799
|
-
"",
|
|
1800
|
-
verdict.review,
|
|
1801
|
-
""
|
|
1802
|
-
]
|
|
1803
|
-
].join("\n");
|
|
1804
|
-
}
|
|
1805
|
-
function digestOf(value, name) {
|
|
1806
|
-
try {
|
|
1807
|
-
return canonicalCandidateDigest(value);
|
|
1808
|
-
} catch (error) {
|
|
1809
|
-
throw new ValidationError(`supervisePursuit versions: the ${name} must be canonical JSON to pin the chain: ${errorMessage(error)}`);
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
async function exists(path) {
|
|
1813
|
-
try {
|
|
1814
|
-
await access(path);
|
|
1815
|
-
return true;
|
|
1816
|
-
} catch (error) {
|
|
1817
|
-
if (isNoEntError(error)) return false;
|
|
1818
|
-
throw error;
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
function isSha256(value) {
|
|
1822
|
-
return typeof value === "string" && /^sha256:[0-9a-f]{64}$/u.test(value);
|
|
1823
|
-
}
|
|
1824
|
-
function isFiniteNumber(value) {
|
|
1825
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
1826
|
-
}
|
|
1827
|
-
function errorMessage(error) {
|
|
1828
|
-
return error instanceof Error ? error.message : String(error);
|
|
1829
|
-
}
|
|
1830
1829
|
//#endregion
|
|
1831
1830
|
//#region src/durable/run-fork.ts
|
|
1832
1831
|
/**
|
|
@@ -2235,10 +2234,10 @@ function startPursuitObserverDelivery(delivery, read, warn = (message) => consol
|
|
|
2235
2234
|
var SupervisePursuitError = class extends Error {
|
|
2236
2235
|
pursuit;
|
|
2237
2236
|
observerPath;
|
|
2238
|
-
/** `
|
|
2237
|
+
/** `failure.json` in the run directory: the record of this throw. */
|
|
2239
2238
|
failurePath;
|
|
2240
2239
|
constructor(cause, pursuit, observerPath, failurePath) {
|
|
2241
|
-
super(`supervisePursuit: ${errorMessage
|
|
2240
|
+
super(`supervisePursuit: ${errorMessage(cause)}`, { cause });
|
|
2242
2241
|
this.name = "SupervisePursuitError";
|
|
2243
2242
|
this.pursuit = pursuit;
|
|
2244
2243
|
this.observerPath = observerPath;
|
|
@@ -2341,7 +2340,7 @@ async function runDurablePursuit(opts, execute, settled) {
|
|
|
2341
2340
|
try {
|
|
2342
2341
|
await observer.journal.appendEvent(rootEvent(pursuitId, runId, "error", now(), {
|
|
2343
2342
|
status: "failed",
|
|
2344
|
-
error: errorMessage
|
|
2343
|
+
error: errorMessage(error)
|
|
2345
2344
|
}));
|
|
2346
2345
|
pursuit = projectPursuit(await observer.journal.read());
|
|
2347
2346
|
} catch (failure) {
|
|
@@ -2356,7 +2355,7 @@ async function runDurablePursuit(opts, execute, settled) {
|
|
|
2356
2355
|
at: new Date(now()).toISOString(),
|
|
2357
2356
|
error: {
|
|
2358
2357
|
name: errorName(error),
|
|
2359
|
-
message: errorMessage
|
|
2358
|
+
message: errorMessage(error)
|
|
2360
2359
|
},
|
|
2361
2360
|
...rootStream === void 0 ? {} : { rootStream }
|
|
2362
2361
|
});
|
|
@@ -2461,13 +2460,10 @@ async function discoverDurableSupervisionRun(runDir) {
|
|
|
2461
2460
|
coordinationStreams: Object.freeze(coordinationStreams)
|
|
2462
2461
|
});
|
|
2463
2462
|
}
|
|
2464
|
-
function isRecord(value) {
|
|
2465
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2466
|
-
}
|
|
2467
2463
|
function compareText(left, right) {
|
|
2468
2464
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
2469
2465
|
}
|
|
2470
2466
|
//#endregion
|
|
2471
|
-
export { FileObserverJournal,
|
|
2467
|
+
export { FileObserverJournal, RUN_FORK_CORRELATION_KEYS, RunDirectoryLockedError, SettledRunDirectoryError, SupervisePursuitError, acquireRunDirectoryLock, assertPursuitVersions, deriveExecutionId, discoverDurableSupervisionRun, handleChatTurn, observerRecordDigest, projectPursuit, readFailureRecord, readRootStream, readRootStreamReceipt, readRunDirectoryLock, readSettleRecord, runDirectoryHolderIsLive, superviseGraphPursuit, supervisePursuit };
|
|
2472
2468
|
|
|
2473
2469
|
//# sourceMappingURL=durable.js.map
|