@tangle-network/agent-runtime 9.0.9 → 9.0.11
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 +20 -0
- package/dist/{activation-CjS7d4_x.js → activation-B_10QJ3D.js} +4 -4
- package/dist/{activation-CjS7d4_x.js.map → activation-B_10QJ3D.js.map} +1 -1
- package/dist/{activation-OSYxeVWi.d.ts → activation-emYXDX7T.d.ts} +2 -2
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +4 -4
- package/dist/{bundle-CcpL2lfr.js → bundle-9NLb1WO3.js} +2 -2
- package/dist/{bundle-CcpL2lfr.js.map → bundle-9NLb1WO3.js.map} +1 -1
- package/dist/candidate-execution/index.js +5 -4
- package/dist/candidate-execution/index.js.map +1 -1
- package/dist/{continuation-DDPfLw2w.js → continuation-CZaeHEzQ.js} +2 -2
- package/dist/{continuation-DDPfLw2w.js.map → continuation-CZaeHEzQ.js.map} +1 -1
- package/dist/{coordination-manager-C0OJ1T9V.js → coordination-manager-BUct8qFe.js} +6 -6
- package/dist/{coordination-manager-C0OJ1T9V.js.map → coordination-manager-BUct8qFe.js.map} +1 -1
- package/dist/deadline-CySmJ_0S.js +134 -0
- package/dist/deadline-CySmJ_0S.js.map +1 -0
- package/dist/{delegate-Ct_KCtwW.js → delegate-DHtsLCyr.js} +2 -2
- package/dist/{delegate-Ct_KCtwW.js.map → delegate-DHtsLCyr.js.map} +1 -1
- package/dist/durable.d.ts +1 -1
- package/dist/durable.js +13 -13
- package/dist/{failure-cause-W0o778qO.js → failure-cause-WifbY42M.js} +2 -2
- package/dist/{failure-cause-W0o778qO.js.map → failure-cause-WifbY42M.js.map} +1 -1
- package/dist/{graph-DHvP4C1q.js → graph-D6KJ6wxN.js} +239 -306
- package/dist/graph-D6KJ6wxN.js.map +1 -0
- package/dist/{graph-registry-Dbm8QhbA.js → graph-registry-B_1C7qye.js} +1 -1
- package/dist/{graph-registry-D0FE9VpR.js → graph-registry-BbZN5deo.js} +282 -6
- package/dist/graph-registry-BbZN5deo.js.map +1 -0
- package/dist/{improve-DIsur006.js → improve-CUqmH45C.js} +8 -9
- package/dist/{improve-DIsur006.js.map → improve-CUqmH45C.js.map} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +15 -102
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +2 -2
- package/dist/intelligence.js +7 -7
- package/dist/{jsonl-file-DsxVI0E_.js → jsonl-file-BhuxeejY.js} +114 -2
- package/dist/jsonl-file-BhuxeejY.js.map +1 -0
- package/dist/kernel.d.ts +2 -2
- package/dist/kernel.js +17 -16
- package/dist/{loop-runner-ku4_lGxf.js → loop-runner-CCeBurqG.js} +2 -2
- package/dist/{loop-runner-ku4_lGxf.js.map → loop-runner-CCeBurqG.js.map} +1 -1
- package/dist/{loop-runner-CCdQ1pmE.d.ts → loop-runner-Q9nlHcEH.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +7 -7
- package/dist/mcp/memory-bin.js +1 -1
- package/dist/output-artifacts-AqkZ8lO2.js +331 -0
- package/dist/output-artifacts-AqkZ8lO2.js.map +1 -0
- package/dist/{prepare-D7WwIddG.js → prepare-Cw4ZaN01.js} +5 -4
- package/dist/{prepare-D7WwIddG.js.map → prepare-Cw4ZaN01.js.map} +1 -1
- package/dist/{profile-BT0X-dm5.js → profile-Cxl_Ajl2.js} +2 -2
- package/dist/{profile-BT0X-dm5.js.map → profile-Cxl_Ajl2.js.map} +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{provision-supervisor-la7aXbs3.js → provision-supervisor-CNTBbuDV.js} +8 -6
- package/dist/{provision-supervisor-la7aXbs3.js.map → provision-supervisor-CNTBbuDV.js.map} +1 -1
- package/dist/{run-cancellation-CfwQmkeG.js → run-cancellation-Cy9ie5cQ.js} +3 -3
- package/dist/{run-cancellation-CfwQmkeG.js.map → run-cancellation-Cy9ie5cQ.js.map} +1 -1
- package/dist/{run-state-BCfmjm6a.js → run-state-C0nr4O7P.js} +6 -6
- package/dist/{run-state-BCfmjm6a.js.map → run-state-C0nr4O7P.js.map} +1 -1
- package/dist/{runtime-DXkdY7VT.js → runtime-C5yB7Vkk.js} +50 -25
- package/dist/{runtime-DXkdY7VT.js.map → runtime-C5yB7Vkk.js.map} +1 -1
- package/dist/{search-executor-DQH_PWxu.js → search-executor-BgEY5MKQ.js} +6 -6
- package/dist/{search-executor-DQH_PWxu.js.map → search-executor-BgEY5MKQ.js.map} +1 -1
- package/dist/{server-D4nCyP5N.js → server-X67SS4r8.js} +5 -5
- package/dist/{server-D4nCyP5N.js.map → server-X67SS4r8.js.map} +1 -1
- package/dist/{settle-record-soq9tzaX.js → settle-record-tgpwk6QF.js} +3 -3
- package/dist/{settle-record-soq9tzaX.js.map → settle-record-tgpwk6QF.js.map} +1 -1
- package/dist/{structural-rollout-D5rtwNgB.js → structural-rollout-BSzN8a0T.js} +7 -6
- package/dist/{structural-rollout-D5rtwNgB.js.map → structural-rollout-BSzN8a0T.js.map} +1 -1
- package/dist/{supervise-G9tWVS7d.js → supervise-RJG2ruTF.js} +189 -210
- package/dist/supervise-RJG2ruTF.js.map +1 -0
- package/dist/{supervision-discovery-DgkhVixZ.js → supervision-discovery-Hekh50FG.js} +5 -5
- package/dist/{supervision-discovery-DgkhVixZ.js.map → supervision-discovery-Hekh50FG.js.map} +1 -1
- package/dist/{supervisor-ByKjr-4D.js → supervisor-DbtgkJyr.js} +24 -12
- package/dist/supervisor-DbtgkJyr.js.map +1 -0
- package/dist/{supervisor-accounting-CvpkFhZU.js → supervisor-accounting-us4w7tG6.js} +8 -118
- package/dist/supervisor-accounting-us4w7tG6.js.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +13 -13
- package/dist/{tool-server-Df-Uy99W.js → tool-server-CirrqFlr.js} +2 -2
- package/dist/{tool-server-Df-Uy99W.js.map → tool-server-CirrqFlr.js.map} +1 -1
- package/dist/{top-web-Cg5nyWlg.js → top-web-xSGEh02D.js} +7 -7
- package/dist/{top-web-Cg5nyWlg.js.map → top-web-xSGEh02D.js.map} +1 -1
- package/dist/tui/bin.js +3 -3
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +2 -2
- package/dist/{types-KQkbyDmn.d.ts → types-DMqr8Tmx.d.ts} +204 -165
- package/dist/{util-fcckrkKp.js → util-qsH5cC9S.js} +3 -132
- package/dist/util-qsH5cC9S.js.map +1 -0
- package/dist/{workspace-streams-DA9R3j-p.js → workspace-streams-BakRr-Pl.js} +9 -330
- package/dist/workspace-streams-BakRr-Pl.js.map +1 -0
- package/package.json +1 -1
- package/dist/graph-DHvP4C1q.js.map +0 -1
- package/dist/graph-registry-D0FE9VpR.js.map +0 -1
- package/dist/jsonl-file-DsxVI0E_.js.map +0 -1
- package/dist/supervise-G9tWVS7d.js.map +0 -1
- package/dist/supervisor-ByKjr-4D.js.map +0 -1
- package/dist/supervisor-accounting-CvpkFhZU.js.map +0 -1
- package/dist/util-fcckrkKp.js.map +0 -1
- package/dist/workspace-streams-DA9R3j-p.js.map +0 -1
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { i as ConfigError, m as ValidationError } from "./errors-DG8yufqX.js";
|
|
2
2
|
import { t as composeRuntimeHooks } from "./runtime-hooks-CsW2pfFk.js";
|
|
3
3
|
import { v as harnessRunsAgent } from "./model-policy-CZwhXp8O.js";
|
|
4
|
-
import {
|
|
5
|
-
import { Qr as runtimeFlowBrain, Xr as runtimeCheckFactory
|
|
6
|
-
import { C as journaledGateDecider, D as graphRootProfile, F as kernelPromptRegistry, O as validateGraphTopology, S as flowRootProfile, T as validateFlowGraph, b as GraphRouteError, i as profileGuidanceComposer, r as superviseWithTestBrain, t as supervise, w as routeFlowOf, x as createFlowRun, y as createGraphOverlay } from "./supervise-
|
|
7
|
-
import { f as createFileRunContext, m as withRunContext, p as createInMemoryRunContext } from "./coordination-manager-
|
|
8
|
-
import {
|
|
9
|
-
import { a as
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
4
|
+
import { A as portableContinuationPolicySchema, C as boxCheckOutputReader, D as stopCheckBoxForRecovery, E as retainIsolatedCheckOutputs, O as stopCheckProcess, T as prepareIsolatedCheckOutputs, k as validateIsolatedCheckOutputs, w as localCheckOutputReader } from "./graph-registry-BbZN5deo.js";
|
|
5
|
+
import { Qr as runtimeFlowBrain, Xr as runtimeCheckFactory } from "./supervisor-accounting-us4w7tG6.js";
|
|
6
|
+
import { C as journaledGateDecider, D as graphRootProfile, F as kernelPromptRegistry, O as validateGraphTopology, S as flowRootProfile, T as validateFlowGraph, b as GraphRouteError, i as profileGuidanceComposer, r as superviseWithTestBrain, t as supervise, w as routeFlowOf, x as createFlowRun, y as createGraphOverlay } from "./supervise-RJG2ruTF.js";
|
|
7
|
+
import { f as createFileRunContext, m as withRunContext, p as createInMemoryRunContext } from "./coordination-manager-BUct8qFe.js";
|
|
8
|
+
import { n as detachedSnapshot } from "./snapshot-BKI_w3JD.js";
|
|
9
|
+
import { a as captureMaterializedWorkspace, c as scanMaterializedWorkspaceManifest, n as WorkspaceScanLimitError, p as canonicalCandidateBytes$1 } from "./output-artifacts-AqkZ8lO2.js";
|
|
10
|
+
import { N as contentAddress, v as retainedExecutorContext } from "./failure-cause-WifbY42M.js";
|
|
11
|
+
import { a as readCommittedJsonLines, c as appendCommittedJsonLine, m as runAbortable, s as withJsonlFileLock } from "./jsonl-file-BhuxeejY.js";
|
|
12
|
+
import { Nt as defaultRunCommand, Pt as runSettledCommand } from "./supervisor-DbtgkJyr.js";
|
|
13
|
+
import { o as armDeadlineTimer } from "./deadline-CySmJ_0S.js";
|
|
14
|
+
import { agentCandidateArtifactRefSchema, agentCandidateWorkspaceManifestMaterialSchema, canonicalCandidateDigest, sha256DigestSchema } from "@tangle-network/agent-interface";
|
|
15
|
+
import { z } from "zod";
|
|
14
16
|
import { randomUUID } from "node:crypto";
|
|
15
17
|
import { constants, mkdirSync, realpathSync } from "node:fs";
|
|
16
18
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
@@ -18,267 +20,6 @@ import { execFile, spawn } from "node:child_process";
|
|
|
18
20
|
import { chmod, cp, lstat, mkdir, mkdtemp, open, opendir, readlink, realpath, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
19
21
|
import { promisify } from "node:util";
|
|
20
22
|
import { tmpdir } from "node:os";
|
|
21
|
-
// src/runtime/isolated-checker-outputs.ts
|
|
22
|
-
const MAX_FILES = 16;
|
|
23
|
-
const MAX_BYTES = 67108864;
|
|
24
|
-
const MAX_TIMEOUT_MS = 12e4;
|
|
25
|
-
/** Validate authored declarations before starting a check. The returned paths are detached and frozen. */
|
|
26
|
-
function validateIsolatedCheckOutputs(value) {
|
|
27
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new ValidationError("check outputs must be a declaration object");
|
|
28
|
-
const item = value;
|
|
29
|
-
if (Object.keys(item).some((key) => ![
|
|
30
|
-
"paths",
|
|
31
|
-
"maxFileBytes",
|
|
32
|
-
"maxTotalBytes",
|
|
33
|
-
"timeoutMs"
|
|
34
|
-
].includes(key))) throw new ValidationError("check outputs has an unknown field");
|
|
35
|
-
if (!Array.isArray(item.paths) || item.paths.length < 1 || item.paths.length > MAX_FILES) throw new ValidationError("check outputs must name between 1 and 16 files");
|
|
36
|
-
const paths = [];
|
|
37
|
-
for (const path of item.paths) {
|
|
38
|
-
if (typeof path !== "string" || path.length > 512 || !/^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/u.test(path) || path.split("/").some((part) => part === "." || part === ".." || part === ".git" || part === ".sidecar") || paths.some((prior) => prior === path || prior.startsWith(`${path}/`) || path.startsWith(`${prior}/`))) throw new ValidationError("check outputs paths must be distinct portable relative files");
|
|
39
|
-
paths.push(path);
|
|
40
|
-
}
|
|
41
|
-
for (const key of ["maxFileBytes", "maxTotalBytes"]) if (typeof item[key] !== "number" || !Number.isSafeInteger(item[key]) || item[key] < 1 || item[key] > MAX_BYTES) throw new ValidationError("check output byte limits must be positive integers at most 64 MiB");
|
|
42
|
-
const maxFileBytes = item.maxFileBytes;
|
|
43
|
-
const maxTotalBytes = item.maxTotalBytes;
|
|
44
|
-
if (maxFileBytes > maxTotalBytes) throw new ValidationError("check outputs maxFileBytes must not exceed maxTotalBytes");
|
|
45
|
-
if (item.timeoutMs !== void 0 && (typeof item.timeoutMs !== "number" || !Number.isSafeInteger(item.timeoutMs) || item.timeoutMs < 1 || item.timeoutMs > MAX_TIMEOUT_MS)) throw new ValidationError("check outputs timeoutMs must be a positive integer at most 120000");
|
|
46
|
-
return Object.freeze({
|
|
47
|
-
paths: Object.freeze(paths),
|
|
48
|
-
maxFileBytes,
|
|
49
|
-
maxTotalBytes,
|
|
50
|
-
...item.timeoutMs === void 0 ? {} : { timeoutMs: item.timeoutMs }
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/** Resolve and validate trusted ports before any isolated work starts. */
|
|
54
|
-
function prepareIsolatedCheckOutputs(options) {
|
|
55
|
-
if (options === void 0) return void 0;
|
|
56
|
-
const { executionId, artifacts, ...declaration } = options;
|
|
57
|
-
const validated = validateIsolatedCheckOutputs(declaration);
|
|
58
|
-
if (typeof executionId !== "string" || executionId.trim() === "" || executionId.length > 200 || /\p{Cc}/u.test(executionId)) throw new ValidationError("check outputs executionId must be a nonempty bounded identifier");
|
|
59
|
-
if (typeof artifacts?.put !== "function" || typeof artifacts?.read !== "function") throw new ValidationError("check outputs requires a readable output artifact port");
|
|
60
|
-
return Object.freeze({
|
|
61
|
-
...validated,
|
|
62
|
-
executionId,
|
|
63
|
-
artifacts
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
var OutputCaptureError = class extends Error {
|
|
67
|
-
reason;
|
|
68
|
-
constructor(reason) {
|
|
69
|
-
super(reason);
|
|
70
|
-
this.reason = reason;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
/** Capture runs after command settlement, even on command failure or cancellation. There are no retries. */
|
|
74
|
-
async function retainIsolatedCheckOutputs(options, inputDigest, read) {
|
|
75
|
-
const controller = new AbortController();
|
|
76
|
-
const clearTimer = armDeadlineTimer(options.timeoutMs ?? 3e4, () => controller.abort(), true);
|
|
77
|
-
const files = [];
|
|
78
|
-
const missing = [];
|
|
79
|
-
let totalBytes = 0;
|
|
80
|
-
try {
|
|
81
|
-
for (const path of options.paths) {
|
|
82
|
-
let phase = "capture-failed";
|
|
83
|
-
try {
|
|
84
|
-
const bytes = await runAbortable(() => read(path, Math.min(options.maxFileBytes, options.maxTotalBytes - totalBytes), controller.signal), controller.signal, "output capture deadline exceeded");
|
|
85
|
-
totalBytes += bytes.byteLength;
|
|
86
|
-
phase = "store-failed";
|
|
87
|
-
const artifact = await runAbortable(() => persistCandidateOutputArtifact(options.artifacts, {
|
|
88
|
-
executionId: options.executionId,
|
|
89
|
-
purpose: "grader-evidence",
|
|
90
|
-
bytes,
|
|
91
|
-
signal: controller.signal
|
|
92
|
-
}), controller.signal, "output persistence deadline exceeded");
|
|
93
|
-
files.push({
|
|
94
|
-
path,
|
|
95
|
-
artifact
|
|
96
|
-
});
|
|
97
|
-
} catch (error) {
|
|
98
|
-
missing.push({
|
|
99
|
-
path,
|
|
100
|
-
reason: controller.signal.aborted ? "timeout" : error instanceof OutputCaptureError ? error.reason : phase
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
} finally {
|
|
105
|
-
clearTimer();
|
|
106
|
-
}
|
|
107
|
-
return Object.freeze({
|
|
108
|
-
executionId: options.executionId,
|
|
109
|
-
inputDigest,
|
|
110
|
-
status: missing.length === 0 ? "retained" : "incomplete",
|
|
111
|
-
files: Object.freeze(files.map((file) => Object.freeze(file))),
|
|
112
|
-
missing: Object.freeze(missing.map((file) => Object.freeze(file)))
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/** The local namespace has exited; the trusted host must keep its private copy stable. */
|
|
116
|
-
function localCheckOutputReader(root) {
|
|
117
|
-
return async (path, maxBytes, signal) => {
|
|
118
|
-
try {
|
|
119
|
-
const rootInfo = await lstat(root);
|
|
120
|
-
if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink()) throw new OutputCaptureError("unsafe-path");
|
|
121
|
-
let current = root;
|
|
122
|
-
const parts = path.split("/");
|
|
123
|
-
let expected;
|
|
124
|
-
for (let index = 0; index < parts.length; index++) {
|
|
125
|
-
current = join(current, parts[index]);
|
|
126
|
-
const info = await lstat(current, { bigint: true });
|
|
127
|
-
if (info.isSymbolicLink() || (index < parts.length - 1 ? !info.isDirectory() : !info.isFile() || info.nlink !== 1n)) throw new OutputCaptureError("unsafe-path");
|
|
128
|
-
expected = info;
|
|
129
|
-
}
|
|
130
|
-
signal.throwIfAborted();
|
|
131
|
-
const file = await open(current, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
132
|
-
try {
|
|
133
|
-
const before = await file.stat({ bigint: true });
|
|
134
|
-
if (!before.isFile() || before.nlink !== 1n || before.dev !== expected?.dev || before.ino !== expected?.ino) throw new OutputCaptureError("unsafe-path");
|
|
135
|
-
if (before.size > BigInt(maxBytes)) throw new OutputCaptureError("size-limit");
|
|
136
|
-
const chunks = [];
|
|
137
|
-
let total = 0;
|
|
138
|
-
const buffer = Buffer.allocUnsafe(Math.min(65536, maxBytes + 1));
|
|
139
|
-
while (true) {
|
|
140
|
-
signal.throwIfAborted();
|
|
141
|
-
const { bytesRead } = await file.read(buffer, 0, Math.min(buffer.length, maxBytes - total + 1), null);
|
|
142
|
-
if (bytesRead === 0) break;
|
|
143
|
-
total += bytesRead;
|
|
144
|
-
if (total > maxBytes) throw new OutputCaptureError("size-limit");
|
|
145
|
-
chunks.push(Buffer.from(buffer.subarray(0, bytesRead)));
|
|
146
|
-
}
|
|
147
|
-
const after = await file.stat({ bigint: true });
|
|
148
|
-
if (before.size !== BigInt(total) || before.size !== after.size || before.mtimeNs !== after.mtimeNs || before.ctimeNs !== after.ctimeNs || after.nlink !== 1n) throw new OutputCaptureError("capture-failed");
|
|
149
|
-
return Buffer.concat(chunks, total);
|
|
150
|
-
} finally {
|
|
151
|
-
await file.close();
|
|
152
|
-
}
|
|
153
|
-
} catch (error) {
|
|
154
|
-
if (error?.code === "ENOENT") throw new OutputCaptureError("missing");
|
|
155
|
-
if (["ELOOP", "ENOTDIR"].includes(error?.code ?? "")) throw new OutputCaptureError("unsafe-path");
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
/** Preserve a whole box only after its native lifecycle owner confirms stopped state. */
|
|
161
|
-
async function stopCheckBoxForRecovery(box) {
|
|
162
|
-
const controller = new AbortController();
|
|
163
|
-
const clearTimer = armDeadlineTimer(3e4, () => controller.abort(), true);
|
|
164
|
-
try {
|
|
165
|
-
await runAbortable(() => box.stop({
|
|
166
|
-
wait: true,
|
|
167
|
-
signal: controller.signal
|
|
168
|
-
}), controller.signal, "check recovery stop deadline exceeded");
|
|
169
|
-
return true;
|
|
170
|
-
} catch {
|
|
171
|
-
return false;
|
|
172
|
-
} finally {
|
|
173
|
-
clearTimer();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
/** Whether kill and process exit were confirmed; recovery custody still needs a whole-box stop. */
|
|
177
|
-
async function stopCheckProcess(child) {
|
|
178
|
-
const controller = new AbortController();
|
|
179
|
-
const clearTimer = armDeadlineTimer(5e3, () => controller.abort(), true);
|
|
180
|
-
try {
|
|
181
|
-
await runAbortable(async () => {
|
|
182
|
-
await child.kill("SIGKILL", { tree: true });
|
|
183
|
-
await child.wait();
|
|
184
|
-
}, controller.signal, "check process stop deadline exceeded");
|
|
185
|
-
return true;
|
|
186
|
-
} catch {
|
|
187
|
-
return false;
|
|
188
|
-
} finally {
|
|
189
|
-
clearTimer();
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const isolatedCheckOutputCaptureProgram = `import base64, errno, hashlib, json, os, stat, sys
|
|
193
|
-
fds=[]
|
|
194
|
-
def fail(reason):
|
|
195
|
-
print(json.dumps({'error':reason})); sys.exit(0)
|
|
196
|
-
try:
|
|
197
|
-
root,path,limit=sys.argv[1],sys.argv[2],int(sys.argv[3])
|
|
198
|
-
directory=os.open(root,os.O_RDONLY|os.O_DIRECTORY|os.O_NOFOLLOW); fds.append(directory)
|
|
199
|
-
parts=path.split('/')
|
|
200
|
-
for part in parts[:-1]:
|
|
201
|
-
directory=os.open(part,os.O_RDONLY|os.O_DIRECTORY|os.O_NOFOLLOW,dir_fd=directory); fds.append(directory)
|
|
202
|
-
before=os.stat(parts[-1],dir_fd=directory,follow_symlinks=False)
|
|
203
|
-
if not stat.S_ISREG(before.st_mode) or before.st_nlink!=1: fail('unsafe-path')
|
|
204
|
-
fd=os.open(parts[-1],os.O_RDONLY|os.O_NOFOLLOW|os.O_NONBLOCK,dir_fd=directory); fds.append(fd)
|
|
205
|
-
opened=os.fstat(fd)
|
|
206
|
-
if not stat.S_ISREG(opened.st_mode) or opened.st_nlink!=1 or (before.st_dev,before.st_ino)!=(opened.st_dev,opened.st_ino): fail('unsafe-path')
|
|
207
|
-
if opened.st_size>limit: fail('size-limit')
|
|
208
|
-
chunks=[]; total=0
|
|
209
|
-
while True:
|
|
210
|
-
chunk=os.read(fd,min(1048576,limit-total+1))
|
|
211
|
-
if not chunk: break
|
|
212
|
-
total+=len(chunk)
|
|
213
|
-
if total>limit: fail('size-limit')
|
|
214
|
-
chunks.append(chunk)
|
|
215
|
-
after=os.fstat(fd)
|
|
216
|
-
if (opened.st_size,opened.st_mtime_ns,opened.st_ctime_ns,opened.st_nlink)!=(after.st_size,after.st_mtime_ns,after.st_ctime_ns,after.st_nlink) or total!=opened.st_size: fail('capture-failed')
|
|
217
|
-
data=b''.join(chunks)
|
|
218
|
-
print(json.dumps({'content':base64.b64encode(data).decode('ascii'),'sha256':'sha256:'+hashlib.sha256(data).hexdigest()}))
|
|
219
|
-
except OSError as error:
|
|
220
|
-
fail('missing' if error.errno==errno.ENOENT else 'unsafe-path' if error.errno in (errno.ELOOP,errno.ENOTDIR) else 'capture-failed')
|
|
221
|
-
finally:
|
|
222
|
-
for fd in reversed(fds): os.close(fd)
|
|
223
|
-
`;
|
|
224
|
-
/** A box with declared outputs needs python3; missing capture tooling fails closed and keeps custody. */
|
|
225
|
-
function boxCheckOutputReader(box, root, timeoutMs) {
|
|
226
|
-
return async (path, maxBytes, signal) => {
|
|
227
|
-
const child = await box.process.spawnExact("/usr/bin/python3", [
|
|
228
|
-
"-I",
|
|
229
|
-
"-S",
|
|
230
|
-
"-c",
|
|
231
|
-
isolatedCheckOutputCaptureProgram,
|
|
232
|
-
root,
|
|
233
|
-
path,
|
|
234
|
-
String(maxBytes)
|
|
235
|
-
], {
|
|
236
|
-
env: {
|
|
237
|
-
PATH: "/usr/bin:/bin",
|
|
238
|
-
LANG: "C"
|
|
239
|
-
},
|
|
240
|
-
inheritEnv: false,
|
|
241
|
-
timeoutMs
|
|
242
|
-
});
|
|
243
|
-
let stopping;
|
|
244
|
-
const stop = () => {
|
|
245
|
-
stopping ??= stopCheckProcess(child);
|
|
246
|
-
};
|
|
247
|
-
signal.addEventListener("abort", stop, { once: true });
|
|
248
|
-
if (signal.aborted) stop();
|
|
249
|
-
const chunks = [];
|
|
250
|
-
const limit = Math.ceil(maxBytes / 3) * 4 + 2048;
|
|
251
|
-
let length = 0;
|
|
252
|
-
let overflow = false;
|
|
253
|
-
const collect = async (stream, keep) => {
|
|
254
|
-
for await (const text of stream) {
|
|
255
|
-
length += Buffer.byteLength(text);
|
|
256
|
-
if (length > limit) {
|
|
257
|
-
overflow = true;
|
|
258
|
-
stop();
|
|
259
|
-
} else if (keep) chunks.push(text);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
try {
|
|
263
|
-
await Promise.all([collect(child.stdout(), true), collect(child.stderr(), false)]);
|
|
264
|
-
if (overflow || await child.wait() !== 0) throw new OutputCaptureError("capture-failed");
|
|
265
|
-
signal.throwIfAborted();
|
|
266
|
-
const value = JSON.parse(chunks.join(""));
|
|
267
|
-
if (value.error === "missing" || value.error === "unsafe-path" || value.error === "size-limit" || value.error === "capture-failed") throw new OutputCaptureError(value.error);
|
|
268
|
-
if (typeof value.content !== "string" || typeof value.sha256 !== "string") throw new OutputCaptureError("capture-failed");
|
|
269
|
-
const bytes = Buffer.from(value.content, "base64");
|
|
270
|
-
if (bytes.byteLength > maxBytes) throw new OutputCaptureError("size-limit");
|
|
271
|
-
if (sha256Bytes$1(bytes) !== value.sha256) throw new OutputCaptureError("capture-failed");
|
|
272
|
-
return bytes;
|
|
273
|
-
} catch (error) {
|
|
274
|
-
stop();
|
|
275
|
-
throw error;
|
|
276
|
-
} finally {
|
|
277
|
-
signal.removeEventListener("abort", stop);
|
|
278
|
-
await stopping;
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
23
|
// src/runtime/isolated-checker.ts
|
|
283
24
|
const toolchains = [
|
|
284
25
|
"/usr",
|
|
@@ -407,7 +148,8 @@ async function runIsolatedCheck(options) {
|
|
|
407
148
|
diagnostic: cleanupDiagnostic,
|
|
408
149
|
stdout: result.value.stdout,
|
|
409
150
|
stderr: result.value.stderr,
|
|
410
|
-
exitCode: 0
|
|
151
|
+
exitCode: 0,
|
|
152
|
+
...result.command ? { command: result.command } : {}
|
|
411
153
|
} : {
|
|
412
154
|
...result,
|
|
413
155
|
cleanupDiagnostic
|
|
@@ -434,6 +176,7 @@ function withRetainedOutputs(result, outputs) {
|
|
|
434
176
|
stdout: result.value.stdout,
|
|
435
177
|
stderr: result.value.stderr,
|
|
436
178
|
exitCode: 0,
|
|
179
|
+
...result.command ? { command: result.command } : {},
|
|
437
180
|
outputs
|
|
438
181
|
};
|
|
439
182
|
}
|
|
@@ -641,7 +384,8 @@ async function runInBox(options, placement) {
|
|
|
641
384
|
diagnostic: cleanupDiagnostic,
|
|
642
385
|
stdout: result.value.stdout,
|
|
643
386
|
stderr: result.value.stderr,
|
|
644
|
-
exitCode: 0
|
|
387
|
+
exitCode: 0,
|
|
388
|
+
...result.command ? { command: result.command } : {}
|
|
645
389
|
} : {
|
|
646
390
|
...result,
|
|
647
391
|
cleanupDiagnostic: [result.cleanupDiagnostic, cleanupDiagnostic].filter(Boolean).join("; ")
|
|
@@ -795,6 +539,7 @@ async function executeInBox(box, command, timeoutMs, limit, env, signal) {
|
|
|
795
539
|
}
|
|
796
540
|
function execute(args, timeoutMs, limit, signal) {
|
|
797
541
|
return new Promise((done) => {
|
|
542
|
+
const began = performance.now();
|
|
798
543
|
const child = spawn("/usr/bin/bwrap", [
|
|
799
544
|
"--json-status-fd",
|
|
800
545
|
"3",
|
|
@@ -848,12 +593,21 @@ function execute(args, timeoutMs, limit, signal) {
|
|
|
848
593
|
child.on("close", (code) => {
|
|
849
594
|
clearTimer();
|
|
850
595
|
signal?.removeEventListener("abort", cancel);
|
|
851
|
-
const
|
|
852
|
-
const
|
|
596
|
+
const outBytes = Buffer.concat(stdout);
|
|
597
|
+
const errBytes = Buffer.concat(stderr);
|
|
598
|
+
const out = outBytes.toString();
|
|
599
|
+
const err = errBytes.toString();
|
|
600
|
+
const command = {
|
|
601
|
+
wallMs: performance.now() - began,
|
|
602
|
+
stdoutBase64: outBytes.toString("base64"),
|
|
603
|
+
stderrBase64: errBytes.toString("base64"),
|
|
604
|
+
outputComplete: bytes <= limit
|
|
605
|
+
};
|
|
853
606
|
const evidence = {
|
|
854
607
|
stdout: out,
|
|
855
608
|
stderr: err,
|
|
856
|
-
exitCode: code
|
|
609
|
+
exitCode: code,
|
|
610
|
+
command
|
|
857
611
|
};
|
|
858
612
|
const executed = status.split("\n").some((line) => {
|
|
859
613
|
try {
|
|
@@ -892,7 +646,8 @@ function execute(args, timeoutMs, limit, signal) {
|
|
|
892
646
|
value: {
|
|
893
647
|
stdout: out,
|
|
894
648
|
stderr: err
|
|
895
|
-
}
|
|
649
|
+
},
|
|
650
|
+
command
|
|
896
651
|
});
|
|
897
652
|
});
|
|
898
653
|
});
|
|
@@ -956,6 +711,101 @@ function graphExecutionOptions(options) {
|
|
|
956
711
|
}
|
|
957
712
|
};
|
|
958
713
|
}
|
|
714
|
+
// src/runtime/isolated-check-result.ts
|
|
715
|
+
const isolatedCheckOutputEvidenceSchema = z.object({
|
|
716
|
+
executionId: z.string().max(200).refine((value) => value.trim() !== "" && !/\p{Cc}/u.test(value)),
|
|
717
|
+
inputDigest: sha256DigestSchema,
|
|
718
|
+
status: z.enum(["retained", "incomplete"]),
|
|
719
|
+
files: z.array(z.object({
|
|
720
|
+
path: z.string(),
|
|
721
|
+
artifact: agentCandidateArtifactRefSchema
|
|
722
|
+
}).strict()).max(16),
|
|
723
|
+
missing: z.array(z.object({
|
|
724
|
+
path: z.string(),
|
|
725
|
+
reason: z.enum([
|
|
726
|
+
"missing",
|
|
727
|
+
"unsafe-path",
|
|
728
|
+
"size-limit",
|
|
729
|
+
"capture-failed",
|
|
730
|
+
"store-failed",
|
|
731
|
+
"timeout"
|
|
732
|
+
])
|
|
733
|
+
}).strict()).max(16),
|
|
734
|
+
source: z.discriminatedUnion("kind", [z.object({
|
|
735
|
+
kind: z.literal("local"),
|
|
736
|
+
path: z.string().min(1)
|
|
737
|
+
}).strict(), z.object({
|
|
738
|
+
kind: z.literal("sandbox"),
|
|
739
|
+
sandboxId: z.string().min(1),
|
|
740
|
+
state: z.literal("stopped")
|
|
741
|
+
}).strict()]).optional()
|
|
742
|
+
}).strict().superRefine((value, context) => {
|
|
743
|
+
try {
|
|
744
|
+
validateIsolatedCheckOutputs({
|
|
745
|
+
paths: [...value.files, ...value.missing].map((file) => file.path),
|
|
746
|
+
maxFileBytes: 67108864,
|
|
747
|
+
maxTotalBytes: 67108864
|
|
748
|
+
});
|
|
749
|
+
} catch {
|
|
750
|
+
context.addIssue({
|
|
751
|
+
code: "custom",
|
|
752
|
+
message: "Check output evidence has invalid paths"
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
if (value.status === "retained" !== (value.missing.length === 0) || value.status === "retained" && value.source !== void 0 || value.files.reduce((bytes, file) => bytes + file.artifact.byteLength, 0) > 67108864) context.addIssue({
|
|
756
|
+
code: "custom",
|
|
757
|
+
message: "Check output evidence is inconsistent"
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
/** Decode the existing execution contract without widening or reinterpreting its evidence. */
|
|
761
|
+
const isolatedCheckBoxEvidenceSchema = z.object({
|
|
762
|
+
sandboxId: z.string().min(1),
|
|
763
|
+
account: z.string().min(1),
|
|
764
|
+
memoryMB: z.number().finite().positive().optional(),
|
|
765
|
+
input: agentCandidateWorkspaceManifestMaterialSchema,
|
|
766
|
+
inputDigest: sha256DigestSchema
|
|
767
|
+
}).strict().superRefine((value, context) => {
|
|
768
|
+
if (canonicalCandidateDigest(value.input) !== value.inputDigest) context.addIssue({
|
|
769
|
+
code: "custom",
|
|
770
|
+
message: "Check input digest does not match its manifest"
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
const isolatedCheckCommandEvidenceSchema = z.object({
|
|
774
|
+
wallMs: z.number().finite().nonnegative(),
|
|
775
|
+
stdoutBase64: z.base64(),
|
|
776
|
+
stderrBase64: z.base64(),
|
|
777
|
+
outputComplete: z.boolean()
|
|
778
|
+
}).strict();
|
|
779
|
+
/** Execution evidence, not a verdict about task correctness or permission to execute again. */
|
|
780
|
+
const isolatedCheckResultSchema = z.discriminatedUnion("succeeded", [z.object({
|
|
781
|
+
succeeded: z.literal(true),
|
|
782
|
+
value: z.object({
|
|
783
|
+
stdout: z.string(),
|
|
784
|
+
stderr: z.string()
|
|
785
|
+
}).strict(),
|
|
786
|
+
box: isolatedCheckBoxEvidenceSchema.optional(),
|
|
787
|
+
outputs: isolatedCheckOutputEvidenceSchema.optional(),
|
|
788
|
+
command: isolatedCheckCommandEvidenceSchema.optional()
|
|
789
|
+
}).strict(), z.object({
|
|
790
|
+
succeeded: z.literal(false),
|
|
791
|
+
reason: z.enum([
|
|
792
|
+
"refused",
|
|
793
|
+
"failed",
|
|
794
|
+
"timeout",
|
|
795
|
+
"cancelled",
|
|
796
|
+
"output-limit",
|
|
797
|
+
"input-limit",
|
|
798
|
+
"cleanup-failed"
|
|
799
|
+
]),
|
|
800
|
+
diagnostic: z.string(),
|
|
801
|
+
stdout: z.string().optional(),
|
|
802
|
+
stderr: z.string().optional(),
|
|
803
|
+
exitCode: z.number().int().nullable().optional(),
|
|
804
|
+
cleanupDiagnostic: z.string().optional(),
|
|
805
|
+
box: isolatedCheckBoxEvidenceSchema.optional(),
|
|
806
|
+
outputs: isolatedCheckOutputEvidenceSchema.optional(),
|
|
807
|
+
command: isolatedCheckCommandEvidenceSchema.optional()
|
|
808
|
+
}).strict()]);
|
|
959
809
|
// src/runtime/supervise/stored-graph-check.ts
|
|
960
810
|
/** Driver-owned journal identity. Worker output never supplies any part of this authority. */
|
|
961
811
|
function receiptKey(receipt) {
|
|
@@ -981,8 +831,9 @@ function isReceipt(value) {
|
|
|
981
831
|
"outputDigest",
|
|
982
832
|
"output"
|
|
983
833
|
].every((key) => typeof row[key] === "string") || !row.nodeName || !row.nodeId || !row.attemptId || !(row.exitCode === null || Number.isSafeInteger(row.exitCode)) || typeof row.outputTruncated !== "boolean" || typeof row.nativeValid !== "boolean" || typeof row.valid !== "boolean") return false;
|
|
834
|
+
if (row.outputs !== void 0 && !isolatedCheckOutputEvidenceSchema.safeParse(row.outputs).success) return false;
|
|
984
835
|
const receipt = value;
|
|
985
|
-
return receipt.key === receiptKey(receipt) && receipt.valid === (receipt.exitCode === 0 && receipt.nativeValid);
|
|
836
|
+
return receipt.key === receiptKey(receipt) && receipt.valid === (receipt.exitCode === 0 && receipt.nativeValid && receipt.outputs?.status !== "incomplete");
|
|
986
837
|
}
|
|
987
838
|
async function appendReceipt(file, workspace, receipt) {
|
|
988
839
|
await withJsonlFileLock(file, async (canonicalPath) => {
|
|
@@ -1153,12 +1004,17 @@ function evidenceOf(task) {
|
|
|
1153
1004
|
if (evidence && typeof evidence === "object" && !Array.isArray(evidence)) for (const [id, result] of Object.entries(evidence)) entries.set(id, result);
|
|
1154
1005
|
return [...entries];
|
|
1155
1006
|
}
|
|
1156
|
-
async function writeEvidence(directory, task) {
|
|
1007
|
+
async function writeEvidence(directory, task, trigger) {
|
|
1157
1008
|
await mkdir(directory, { recursive: true });
|
|
1158
1009
|
for (const [id, result] of evidenceOf(task)) {
|
|
1159
1010
|
if (!safeNodeFile.test(id)) throw new ValidationError(`runGraph: evidence node id ${id}`);
|
|
1160
1011
|
await writeFile(join(directory, `${id}.json`), `${JSON.stringify(result)}\n`);
|
|
1161
1012
|
}
|
|
1013
|
+
await mkdir(join(directory, "_input"), { recursive: true });
|
|
1014
|
+
await writeFile(join(directory, "_input", "task.json"), canonicalCandidateBytes$1({
|
|
1015
|
+
task,
|
|
1016
|
+
...trigger === void 0 ? {} : { trigger }
|
|
1017
|
+
}));
|
|
1162
1018
|
}
|
|
1163
1019
|
async function readSecrets(names, environment, node) {
|
|
1164
1020
|
const secrets = {};
|
|
@@ -1170,7 +1026,11 @@ async function readSecrets(names, environment, node) {
|
|
|
1170
1026
|
return secrets;
|
|
1171
1027
|
}
|
|
1172
1028
|
/** Run one check node's command locally, in the run's working directory. */
|
|
1173
|
-
async function runLocalCheck(check, cwd, evidence, signal, secrets) {
|
|
1029
|
+
async function runLocalCheck(check, cwd, evidence, signal, secrets, retention) {
|
|
1030
|
+
const prior = new Map(await Promise.all((retention?.paths ?? []).map(async (path) => [path, await lstat(join(cwd, path), { bigint: true }).catch((error) => {
|
|
1031
|
+
if (error.code !== "ENOENT") throw error;
|
|
1032
|
+
})])));
|
|
1033
|
+
const inputDigest = retention ? canonicalCandidateDigest(await scanMaterializedWorkspaceManifest(evidence)) : void 0;
|
|
1174
1034
|
const timeoutMs = check.timeoutMs ?? CHECK_TIMEOUT_MS;
|
|
1175
1035
|
const result = await runSettledCommand({
|
|
1176
1036
|
command: "/bin/sh",
|
|
@@ -1180,18 +1040,42 @@ async function runLocalCheck(check, cwd, evidence, signal, secrets) {
|
|
|
1180
1040
|
signal,
|
|
1181
1041
|
env: {
|
|
1182
1042
|
...secrets,
|
|
1183
|
-
GRAPH_EVIDENCE: evidence
|
|
1043
|
+
GRAPH_EVIDENCE: evidence,
|
|
1044
|
+
GRAPH_INPUT: join(evidence, "_input", "task.json")
|
|
1184
1045
|
}
|
|
1185
1046
|
});
|
|
1186
1047
|
const timedOut = result.timedOut ? `\n[check timed out after ${timeoutMs} ms]` : "";
|
|
1048
|
+
const readOutput = localCheckOutputReader(cwd);
|
|
1049
|
+
const captured = retention ? await retainIsolatedCheckOutputs(retention, inputDigest, async (path, maxBytes, signal) => {
|
|
1050
|
+
const before = prior.get(path);
|
|
1051
|
+
if (before) {
|
|
1052
|
+
const after = await lstat(join(cwd, path), { bigint: true });
|
|
1053
|
+
if ([
|
|
1054
|
+
"dev",
|
|
1055
|
+
"ino",
|
|
1056
|
+
"size",
|
|
1057
|
+
"mtimeNs",
|
|
1058
|
+
"ctimeNs"
|
|
1059
|
+
].every((key) => before[key] === after[key])) throw new Error("Declared local check output was not changed by this command");
|
|
1060
|
+
}
|
|
1061
|
+
return readOutput(path, maxBytes, signal);
|
|
1062
|
+
}) : void 0;
|
|
1063
|
+
const outputs = captured?.status === "incomplete" ? {
|
|
1064
|
+
...captured,
|
|
1065
|
+
source: {
|
|
1066
|
+
kind: "local",
|
|
1067
|
+
path: cwd
|
|
1068
|
+
}
|
|
1069
|
+
} : captured;
|
|
1187
1070
|
return {
|
|
1188
1071
|
exitCode: result.timedOut ? null : result.exitCode,
|
|
1189
1072
|
stdout: result.stdout,
|
|
1190
|
-
output: result.stdout + result.stderr + timedOut
|
|
1073
|
+
output: result.stdout + result.stderr + timedOut,
|
|
1074
|
+
...outputs && { outputs }
|
|
1191
1075
|
};
|
|
1192
1076
|
}
|
|
1193
1077
|
/** Run one check node's command in a fresh box on the check account, as a declared check does. */
|
|
1194
|
-
async function runBoxCheck(check, node, placement, evidence, signal, secrets) {
|
|
1078
|
+
async function runBoxCheck(check, node, placement, evidence, signal, secrets, outputs) {
|
|
1195
1079
|
const workspaceRoot = await mkdtemp(join(evidence, "..", "box-"));
|
|
1196
1080
|
try {
|
|
1197
1081
|
const tree = join(workspaceRoot, "tree");
|
|
@@ -1203,12 +1087,13 @@ async function runBoxCheck(check, node, placement, evidence, signal, secrets) {
|
|
|
1203
1087
|
command: [
|
|
1204
1088
|
"/bin/sh",
|
|
1205
1089
|
"-c",
|
|
1206
|
-
`GRAPH_EVIDENCE="$PWD/_evidence"; export GRAPH_EVIDENCE; ${check.command}`
|
|
1090
|
+
`GRAPH_EVIDENCE="$PWD/_evidence"; GRAPH_INPUT="$GRAPH_EVIDENCE/_input/task.json"; export GRAPH_EVIDENCE GRAPH_INPUT; ${check.command}`
|
|
1207
1091
|
],
|
|
1208
1092
|
timeoutMs: check.timeoutMs ?? CHECK_TIMEOUT_MS,
|
|
1209
1093
|
maxOutputBytes: 16 * CHECK_OUTPUT_LIMIT,
|
|
1210
1094
|
env: secrets,
|
|
1211
1095
|
signal,
|
|
1096
|
+
...outputs && { outputs },
|
|
1212
1097
|
box: {
|
|
1213
1098
|
client: placement.client,
|
|
1214
1099
|
builderAccounts: placement.builderAccounts ?? ["run-owner"],
|
|
@@ -1222,19 +1107,17 @@ async function runBoxCheck(check, node, placement, evidence, signal, secrets) {
|
|
|
1222
1107
|
if (result.succeeded) return {
|
|
1223
1108
|
exitCode: 0,
|
|
1224
1109
|
stdout: result.value.stdout,
|
|
1225
|
-
output: result.value.stdout + result.value.stderr
|
|
1110
|
+
output: result.value.stdout + result.value.stderr,
|
|
1111
|
+
...result.outputs && { outputs: result.outputs }
|
|
1226
1112
|
};
|
|
1227
1113
|
const stdout = result.stdout ?? "";
|
|
1228
1114
|
const output = stdout + (result.stderr ?? "");
|
|
1229
|
-
if (result.reason === "failed"
|
|
1230
|
-
exitCode: result.exitCode,
|
|
1231
|
-
stdout,
|
|
1232
|
-
output
|
|
1233
|
-
};
|
|
1234
|
-
if (result.reason === "timeout") return {
|
|
1235
|
-
exitCode: null,
|
|
1115
|
+
if (result.outputs || result.reason === "failed" || result.reason === "timeout") return {
|
|
1116
|
+
exitCode: result.exitCode ?? null,
|
|
1236
1117
|
stdout,
|
|
1237
|
-
output: `${output}\n[check
|
|
1118
|
+
output: `${output}\n[check ${result.reason}: ${result.diagnostic}]`,
|
|
1119
|
+
nativeValid: result.reason === "failed" || result.reason === "timeout",
|
|
1120
|
+
...result.outputs && { outputs: result.outputs }
|
|
1238
1121
|
};
|
|
1239
1122
|
throw new Error(redact(`runGraph: check node ${node} box ${result.reason}: ${result.diagnostic}`, secrets));
|
|
1240
1123
|
} finally {
|
|
@@ -1246,14 +1129,39 @@ async function runBoxCheck(check, node, placement, evidence, signal, secrets) {
|
|
|
1246
1129
|
}
|
|
1247
1130
|
/** Every resolved secret value becomes `[redacted:NAME]` before output leaves the check. */
|
|
1248
1131
|
function redact(text, secrets) {
|
|
1249
|
-
return
|
|
1132
|
+
return redactBytes(Buffer.from(text), secrets).toString("utf8");
|
|
1133
|
+
}
|
|
1134
|
+
function redactBytes(bytes, secrets, maxBytes = Number.MAX_SAFE_INTEGER) {
|
|
1135
|
+
let out = Buffer.from(bytes);
|
|
1136
|
+
for (const [name, value] of Object.entries(secrets).sort(([, a], [, b]) => b.length - a.length)) {
|
|
1137
|
+
const needle = Buffer.from(value);
|
|
1138
|
+
const replacement = Buffer.from(`[redacted:${name}]`);
|
|
1139
|
+
let length = out.length;
|
|
1140
|
+
for (let at = out.indexOf(needle); at !== -1; at = out.indexOf(needle, at + needle.length)) {
|
|
1141
|
+
length += replacement.length - needle.length;
|
|
1142
|
+
if (length > maxBytes) throw new Error("Redacted check output exceeds its byte limit");
|
|
1143
|
+
}
|
|
1144
|
+
if (length === out.length && !out.includes(needle)) continue;
|
|
1145
|
+
const redacted = Buffer.allocUnsafe(length);
|
|
1146
|
+
let start = 0;
|
|
1147
|
+
let offset = 0;
|
|
1148
|
+
for (let at = out.indexOf(needle); at !== -1; at = out.indexOf(needle, start)) {
|
|
1149
|
+
offset += out.copy(redacted, offset, start, at);
|
|
1150
|
+
offset += replacement.copy(redacted, offset);
|
|
1151
|
+
start = at + needle.length;
|
|
1152
|
+
}
|
|
1153
|
+
out.copy(redacted, offset, start);
|
|
1154
|
+
out = redacted;
|
|
1155
|
+
}
|
|
1156
|
+
return out;
|
|
1250
1157
|
}
|
|
1251
1158
|
function checkOutput(receipt) {
|
|
1252
1159
|
return {
|
|
1253
1160
|
pass: receipt.valid,
|
|
1254
1161
|
exitCode: receipt.exitCode,
|
|
1255
1162
|
output: receipt.output,
|
|
1256
|
-
...receipt.json === void 0 ? {} : { json: receipt.json }
|
|
1163
|
+
...receipt.json === void 0 ? {} : { json: receipt.json },
|
|
1164
|
+
...receipt.outputs === void 0 ? {} : { outputs: (({ source: _source, ...outputs }) => outputs)(receipt.outputs) }
|
|
1257
1165
|
};
|
|
1258
1166
|
}
|
|
1259
1167
|
/** The receipt a run context's journal holds for this binding, as executor evidence. */
|
|
@@ -1287,6 +1195,14 @@ function bindGraphCheckNodes(graph, options) {
|
|
|
1287
1195
|
const timeoutMs = check.timeoutMs ?? CHECK_TIMEOUT_MS;
|
|
1288
1196
|
if (!check.command.trim() || !Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) throw new ValidationError(`runGraph: check node ${id} needs a command and positive timeoutMs`);
|
|
1289
1197
|
if (placement && !check.environment?.trim()) throw new ValidationError(`runGraph: check node ${id} needs environment for box placement`);
|
|
1198
|
+
if (check.outputs !== void 0) {
|
|
1199
|
+
if (!options.checkArtifacts) throw new ValidationError(`runGraph: check node ${id} outputs require checkArtifacts`);
|
|
1200
|
+
prepareIsolatedCheckOutputs({
|
|
1201
|
+
...check.outputs,
|
|
1202
|
+
executionId: "graph-check-preflight",
|
|
1203
|
+
artifacts: options.checkArtifacts
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1290
1206
|
}
|
|
1291
1207
|
const local = placement === void 0 ? localCheckDirectories(options) : void 0;
|
|
1292
1208
|
const workspace = local?.cwd ?? backendWorkspace(options);
|
|
@@ -1307,7 +1223,8 @@ function bindGraphCheckNodes(graph, options) {
|
|
|
1307
1223
|
runId,
|
|
1308
1224
|
node: id,
|
|
1309
1225
|
checkDigest,
|
|
1310
|
-
at: spawn?.assignmentId
|
|
1226
|
+
at: spawn?.assignmentId,
|
|
1227
|
+
...options.trigger === void 0 ? {} : { trigger: options.trigger }
|
|
1311
1228
|
});
|
|
1312
1229
|
const executorFactory = (_spec, context_) => {
|
|
1313
1230
|
let artifact;
|
|
@@ -1353,10 +1270,16 @@ function bindGraphCheckNodes(graph, options) {
|
|
|
1353
1270
|
secrets: check.secrets ?? [],
|
|
1354
1271
|
signal
|
|
1355
1272
|
}) : box.env ?? {}, id);
|
|
1273
|
+
const retention = check.outputs && {
|
|
1274
|
+
...check.outputs,
|
|
1275
|
+
executionId: binding,
|
|
1276
|
+
artifacts: options.checkArtifacts,
|
|
1277
|
+
redact: (bytes) => redactBytes(bytes, secrets, check.outputs.maxFileBytes)
|
|
1278
|
+
};
|
|
1356
1279
|
let ran;
|
|
1357
1280
|
try {
|
|
1358
|
-
await writeEvidence(evidence, task);
|
|
1359
|
-
ran = local ? await runLocalCheck(check, local.cwd, evidence, signal, secrets) : await runBoxCheck(check, id, placement, evidence, signal, secrets);
|
|
1281
|
+
await writeEvidence(evidence, task, options.trigger);
|
|
1282
|
+
ran = local ? await runLocalCheck(check, local.cwd, evidence, signal, secrets, retention) : await runBoxCheck(check, id, placement, evidence, signal, secrets, retention);
|
|
1360
1283
|
} finally {
|
|
1361
1284
|
if (staged) await rm(staged, {
|
|
1362
1285
|
recursive: true,
|
|
@@ -1373,9 +1296,10 @@ function bindGraphCheckNodes(graph, options) {
|
|
|
1373
1296
|
exitCode: ran.exitCode,
|
|
1374
1297
|
output,
|
|
1375
1298
|
outputTruncated: truncated,
|
|
1376
|
-
nativeValid:
|
|
1377
|
-
valid: ran.exitCode === 0,
|
|
1378
|
-
...json === void 0 ? {} : { json }
|
|
1299
|
+
nativeValid: ran.nativeValid !== false,
|
|
1300
|
+
valid: ran.exitCode === 0 && ran.nativeValid !== false && ran.outputs?.status !== "incomplete",
|
|
1301
|
+
...json === void 0 ? {} : { json },
|
|
1302
|
+
...ran.outputs === void 0 ? {} : { outputs: ran.outputs }
|
|
1379
1303
|
};
|
|
1380
1304
|
if (file) await appendReceipt(file, workspace, receipt);
|
|
1381
1305
|
else await retainedExecutorContext(context_)?.onEvidence?.({ graphCheckReceipt: {
|
|
@@ -1528,6 +1452,7 @@ const GRAPH_FORWARDED_SUPERVISE_OPTIONS = [
|
|
|
1528
1452
|
"resolveDriveHarness",
|
|
1529
1453
|
"driveHarnessMaterialization",
|
|
1530
1454
|
"resolveSupervisorTools",
|
|
1455
|
+
"servesToolNames",
|
|
1531
1456
|
"extraTools",
|
|
1532
1457
|
"executeExtraTool",
|
|
1533
1458
|
"recoverExecutor",
|
|
@@ -1569,7 +1494,9 @@ const runGraphOptionKeys = [
|
|
|
1569
1494
|
...GRAPH_TRANSFORMED_SUPERVISE_OPTIONS,
|
|
1570
1495
|
...GRAPH_REFUSED_SUPERVISE_OPTIONS,
|
|
1571
1496
|
"brain",
|
|
1572
|
-
"checkPlacement"
|
|
1497
|
+
"checkPlacement",
|
|
1498
|
+
"checkArtifacts",
|
|
1499
|
+
"trigger"
|
|
1573
1500
|
];
|
|
1574
1501
|
const runGraphOptionKeySet = new Set(runGraphOptionKeys);
|
|
1575
1502
|
const graphOwnedOptionKeySet = new Set(GRAPH_OWNED_SUPERVISE_OPTIONS);
|
|
@@ -1693,6 +1620,7 @@ function superviseAgentGraph(graph, opts, brain) {
|
|
|
1693
1620
|
...signal === void 0 ? {} : { signal }
|
|
1694
1621
|
}, brain));
|
|
1695
1622
|
const validated = assertRunGraphAuthoring(graph, opts, brain);
|
|
1623
|
+
const trigger = opts.trigger === void 0 ? void 0 : detachedSnapshot(opts.trigger, "runGraph trigger");
|
|
1696
1624
|
const context = opts.runContext ?? (opts.runDir === void 0 ? createInMemoryRunContext() : createFileRunContext(resolve(opts.runDir)));
|
|
1697
1625
|
const journal = opts.journal ?? context.journal;
|
|
1698
1626
|
const blobs = opts.blobs ?? context.blobs;
|
|
@@ -1700,7 +1628,8 @@ function superviseAgentGraph(graph, opts, brain) {
|
|
|
1700
1628
|
const now = opts.now ?? Date.now;
|
|
1701
1629
|
const checkNodes = bindGraphCheckNodes(graph, {
|
|
1702
1630
|
...opts,
|
|
1703
|
-
runId
|
|
1631
|
+
runId,
|
|
1632
|
+
trigger
|
|
1704
1633
|
});
|
|
1705
1634
|
const guidance = profileGuidanceComposer(opts.profileGuidance);
|
|
1706
1635
|
const overlay = createGraphOverlay(validated, {
|
|
@@ -1722,7 +1651,11 @@ function superviseAgentGraph(graph, opts, brain) {
|
|
|
1722
1651
|
} }, opts.hooks);
|
|
1723
1652
|
const rootProfile = flow === void 0 ? graphRootProfile(validated, registry) : flowRootProfile;
|
|
1724
1653
|
const rootBrain = flow === void 0 ? brain : runtimeFlowBrain();
|
|
1725
|
-
const
|
|
1654
|
+
const description = flow === void 0 ? graph.deliverable.describe ?? `Deliver the graph's deliverable by driving your worker nodes (root: '${validated.root.id}').` : graph.deliverable.describe ?? "Runtime runs this flow graph from its entries.";
|
|
1655
|
+
const task = trigger === void 0 ? description : {
|
|
1656
|
+
task: description,
|
|
1657
|
+
trigger
|
|
1658
|
+
};
|
|
1726
1659
|
const start = async () => {
|
|
1727
1660
|
const superviseOptions = {
|
|
1728
1661
|
...forwardedSuperviseOptions(opts),
|
|
@@ -1783,6 +1716,6 @@ function superviseAgentGraph(graph, opts, brain) {
|
|
|
1783
1716
|
};
|
|
1784
1717
|
return start();
|
|
1785
1718
|
}
|
|
1786
|
-
export {
|
|
1719
|
+
export { isolatedCheckBoxEvidenceSchema as a, runIsolatedCheck as c, superviseAgentGraph as i, runGraph as n, isolatedCheckResultSchema as o, runGraphWithTestBrain as r, graphExecutionOptions as s, GraphEdgeCapError as t };
|
|
1787
1720
|
|
|
1788
|
-
//# sourceMappingURL=graph-
|
|
1721
|
+
//# sourceMappingURL=graph-D6KJ6wxN.js.map
|