@tangle-network/agent-runtime 0.189.0 → 0.191.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-DuYIFVQm.js → activation-BpTEBhQR.js} +3 -3
- package/dist/{activation-DuYIFVQm.js.map → activation-BpTEBhQR.js.map} +1 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +3 -3
- package/dist/{authoring-CIE6rF8N.js → authoring-DV0fkyxx.js} +7 -3
- package/dist/{authoring-CIE6rF8N.js.map → authoring-DV0fkyxx.js.map} +1 -1
- package/dist/candidate-execution/index.d.ts +3 -3
- package/dist/candidate-execution/index.js +5 -5
- package/dist/{candidate-execution-CQYU8E5a.js → candidate-execution-BSkZErxD.js} +255 -9
- package/dist/candidate-execution-BSkZErxD.js.map +1 -0
- package/dist/conversation.d.ts +1 -1
- package/dist/{coordination-driver-CtbyZv5d.js → coordination-driver-Bw0Prnim.js} +672 -39
- package/dist/coordination-driver-Bw0Prnim.js.map +1 -0
- package/dist/{durable-file-g3YdfEh4.js → durable-file-D24y9zg7.js} +2 -2
- package/dist/{durable-file-g3YdfEh4.js.map → durable-file-D24y9zg7.js.map} +1 -1
- package/dist/durable.d.ts +2 -2
- package/dist/durable.js +3 -3
- package/dist/{environment-provider-C4AQiUxj.d.ts → environment-provider-CJ43FJfJ.d.ts} +2 -2
- package/dist/{environment-provider-DZxuH3E4.js → environment-provider-DEwsolvi.js} +44 -7
- package/dist/environment-provider-DEwsolvi.js.map +1 -0
- package/dist/environment-provider.d.ts +1 -1
- package/dist/environment-provider.js +1 -1
- package/dist/{graph-DzkWh1BI.js → graph-BzsMtBYp.js} +6 -3
- package/dist/graph-BzsMtBYp.js.map +1 -0
- package/dist/graph.d.ts +3 -3
- package/dist/graph.js +5 -5
- package/dist/{redact-C9EWk1FT.d.ts → improve-Cbbt3jE6.d.ts} +4 -36
- package/dist/{improvement-cycle-DP9zf-IL.js → improvement-cycle-jC89uaRW.js} +7 -7
- package/dist/{improvement-cycle-DP9zf-IL.js.map → improvement-cycle-jC89uaRW.js.map} +1 -1
- package/dist/{index-k5bcID4t.d.ts → index-B2rVjcPT.d.ts} +417 -56
- package/dist/{index-DCqHTdmp.d.ts → index-CUosKU4N.d.ts} +144 -4
- package/dist/{index-DA9jKuJc.d.ts → index-OSRVFARy.d.ts} +2 -2
- package/dist/{index-tf6g2B27.d.ts → index-Y14IrBuB.d.ts} +4 -4
- package/dist/index.d.ts +11 -10
- package/dist/index.js +12 -13
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +6 -5
- package/dist/intelligence.js +6 -7
- package/dist/intelligence.js.map +1 -1
- package/dist/kernel.d.ts +6 -6
- package/dist/kernel.js +12 -12
- package/dist/{knowledge-C5lODZQC.js → knowledge-BuXP5ynd.js} +5 -5
- package/dist/{knowledge-C5lODZQC.js.map → knowledge-BuXP5ynd.js.map} +1 -1
- package/dist/knowledge.d.ts +1 -1
- package/dist/knowledge.js +1 -1
- package/dist/{loop-runner-bin-BKsjoaVu.js → loop-runner-bin-B_Xh4jLi.js} +3 -3
- package/dist/{loop-runner-bin-BKsjoaVu.js.map → loop-runner-bin-B_Xh4jLi.js.map} +1 -1
- package/dist/{loop-runner-bin-ncN_8Msd.d.ts → loop-runner-bin-C2Yw-RBc.d.ts} +3 -3
- 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 +4 -4
- package/dist/mcp/index.js +8 -8
- package/dist/mcp/memory-bin.js +1 -1
- package/dist/{memory-server-DsKOhzGf.js → memory-server-Crkevawz.js} +2 -2
- package/dist/{memory-server-DsKOhzGf.js.map → memory-server-Crkevawz.js.map} +1 -1
- package/dist/{openai-tools-x83CTnJM.js → openai-tools-Dqg8IhKd.js} +2 -2
- package/dist/{openai-tools-x83CTnJM.js.map → openai-tools-Dqg8IhKd.js.map} +1 -1
- package/dist/{prepare-BtXhV0qj.js → prepare-B5fJ7mLS.js} +239 -227
- package/dist/prepare-B5fJ7mLS.js.map +1 -0
- package/dist/primeintellect/index.d.ts +1 -1
- package/dist/primeintellect/index.js +1 -1
- package/dist/profiles.js +1 -1
- package/dist/{protected-model-port-DHrayPt4.js → protected-model-port-B0xFSAjt.js} +2 -2
- package/dist/{protected-model-port-DHrayPt4.js.map → protected-model-port-B0xFSAjt.js.map} +1 -1
- package/dist/{provision-supervisor-B-_4I1In.js → provision-supervisor-DAcTZDQG.js} +8 -8
- package/dist/{provision-supervisor-B-_4I1In.js.map → provision-supervisor-DAcTZDQG.js.map} +1 -1
- package/dist/{supervisor-BSNkaM2a.js → redact-BP8Xn2A3.js} +569 -12
- package/dist/redact-BP8Xn2A3.js.map +1 -0
- package/dist/{run-layout-Cd_l2XWV.js → run-layout-B8I_LXN-.js} +3 -3
- package/dist/{run-layout-Cd_l2XWV.js.map → run-layout-B8I_LXN-.js.map} +1 -1
- package/dist/{runtime-EQgE3942.d.ts → runtime-DI4mJNXI.d.ts} +202 -4
- package/dist/{runtime-C98JsP83.js → runtime-Dm63BrGY.js} +69 -25
- package/dist/{runtime-C98JsP83.js.map → runtime-Dm63BrGY.js.map} +1 -1
- package/dist/{spawn-journal-CxRa-NJ2.js → spawn-journal-B9eTmVAn.js} +2 -2
- package/dist/{spawn-journal-CxRa-NJ2.js.map → spawn-journal-B9eTmVAn.js.map} +1 -1
- package/dist/{stream-agent-turn-BomJ21AK.d.ts → stream-agent-turn-_GgUW49y.d.ts} +35 -3
- package/dist/{structural-rollout-C8sB6B4q.js → structural-rollout-ChpGSR0q.js} +3 -3
- package/dist/{structural-rollout-C8sB6B4q.js.map → structural-rollout-ChpGSR0q.js.map} +1 -1
- package/dist/{supervise-DSu4d0b6.js → supervise-B89x7rgF.js} +287 -23
- package/dist/supervise-B89x7rgF.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +13 -13
- package/dist/{top-app-DIBApkt1.js → top-app-KgIFpD9H.js} +3 -3
- package/dist/{top-app-DIBApkt1.js.map → top-app-KgIFpD9H.js.map} +1 -1
- package/dist/tui/bin.js +1 -1
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +2 -2
- package/dist/{types-BbkiJR1D.d.ts → types-DKA_PDv0.d.ts} +62 -2
- package/dist/{util-BfoW6RU7.js → util-mCNUeboW.js} +21 -2
- package/dist/util-mCNUeboW.js.map +1 -0
- package/dist/{workspace-archive-SVeiWLNE.js → workspace-archive-yAPDklLV.js} +4 -4
- package/dist/{workspace-archive-SVeiWLNE.js.map → workspace-archive-yAPDklLV.js.map} +1 -1
- package/package.json +8 -8
- package/dist/candidate-execution-CQYU8E5a.js.map +0 -1
- package/dist/coordination-driver-CtbyZv5d.js.map +0 -1
- package/dist/environment-provider-DZxuH3E4.js.map +0 -1
- package/dist/graph-DzkWh1BI.js.map +0 -1
- package/dist/prepare-BtXhV0qj.js.map +0 -1
- package/dist/redact-D-u-rrcn.js +0 -82
- package/dist/redact-D-u-rrcn.js.map +0 -1
- package/dist/supervise-DSu4d0b6.js.map +0 -1
- package/dist/supervisor-BSNkaM2a.js.map +0 -1
- package/dist/util-BfoW6RU7.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { x as contentAddress } from "./spawn-journal-
|
|
1
|
+
import { x as contentAddress } from "./spawn-journal-B9eTmVAn.js";
|
|
2
2
|
import { i as redactProtectedValue, n as createProtectedRecordRedactor, r as redactProtectedReason, t as assertNoProtectedBytes } from "./protected-redaction--F3v1oo8.js";
|
|
3
3
|
import { agentCandidateArtifactRefSchema, agentCandidateBenchmarkResultEvidenceSchema, agentCandidateBenchmarkSuiteSchema, agentCandidateBenchmarkTaskSchema, agentCandidateBundleSchema, agentCandidateContainerSchema, agentCandidateExecutionLimitsSchema, agentCandidateExecutionPlanEvidenceSchema, agentCandidateExecutionPlanMaterialSchema, agentCandidateMaterializationReceiptSchema, agentCandidateModelAccessNetworkSchema, agentCandidateModelSettlementEvidenceSchema, agentCandidateProfileActivationSchema, agentCandidateProfilePlanEvidenceSchema, agentCandidateProfileSchema, agentCandidateResolvedModelSchema, agentCandidateRunCellSchema, agentCandidateRunReceiptSchema, agentCandidateTaskOutcomeEvidenceSchema, agentCandidateTaskOutcomeSpecSchema, agentCandidateTerminationSchema, agentCandidateWorkspaceManifestMaterialSchema, agentCandidateWorkspaceSnapshotEvidenceSchema, agentProfileDiffSchema, agentProfileSchema, applyAgentProfileDiff, sha256DigestSchema } from "@tangle-network/agent-interface";
|
|
4
4
|
import { REDACTION_VERSION, canonicalJson, isLlmSpan } from "@tangle-network/agent-eval";
|
|
5
5
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
6
|
+
import { constants } from "node:fs";
|
|
7
|
+
import { lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rm, stat } from "node:fs/promises";
|
|
6
8
|
import { dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
|
|
7
9
|
import { applyAgentCandidateWorkspacePlan, isMaterializerHarness, materializeCandidateProfile, resolvePiRuntimePaths } from "@tangle-network/agent-profile-materialize";
|
|
8
|
-
import { lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rm, stat } from "node:fs/promises";
|
|
9
|
-
import { constants } from "node:fs";
|
|
10
10
|
import { spawn } from "node:child_process";
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import { hashKnowledgeBase } from "@tangle-network/agent-knowledge";
|
|
@@ -64,6 +64,240 @@ function deepFreezeCandidate(value, seen = /* @__PURE__ */ new Set()) {
|
|
|
64
64
|
return Object.freeze(value);
|
|
65
65
|
}
|
|
66
66
|
//#endregion
|
|
67
|
+
//#region src/candidate-execution/artifacts.ts
|
|
68
|
+
function artifactCacheKey(artifact) {
|
|
69
|
+
return `${artifact.sha256}:${artifact.byteLength}`;
|
|
70
|
+
}
|
|
71
|
+
async function readVerifiedArtifact(artifact, port) {
|
|
72
|
+
const bytes = "content" in artifact ? Buffer.from(artifact.content, "base64") : await port.read(artifact);
|
|
73
|
+
verifyBytes(bytes, artifact.sha256, artifact.byteLength, "candidate artifact");
|
|
74
|
+
return Uint8Array.from(bytes);
|
|
75
|
+
}
|
|
76
|
+
function verifyBytes(bytes, digest, byteLength, label) {
|
|
77
|
+
if (bytes.byteLength !== byteLength) throw new Error(`${label} byte length ${bytes.byteLength} does not match ${byteLength}`);
|
|
78
|
+
const actual = sha256Bytes(bytes);
|
|
79
|
+
if (actual !== digest) throw new Error(`${label} digest ${actual} does not match ${digest}`);
|
|
80
|
+
}
|
|
81
|
+
async function verifyWorkspaceSnapshotArtifacts(snapshot, port) {
|
|
82
|
+
const [manifest, archive] = await Promise.all([readVerifiedArtifact(snapshot.manifest, port), readVerifiedArtifact(snapshot.archive, port)]);
|
|
83
|
+
const canonicalManifest = canonicalCandidateBytes(snapshot.material);
|
|
84
|
+
if (!Buffer.from(manifest).equals(Buffer.from(canonicalManifest))) throw new Error("workspace manifest artifact is not the exact canonical manifest material");
|
|
85
|
+
if (sha256Bytes(canonicalManifest) !== snapshot.digest) throw new Error("workspace snapshot digest does not match its canonical manifest material");
|
|
86
|
+
return {
|
|
87
|
+
manifest,
|
|
88
|
+
archive
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Refuse a materialized workspace whose files, modes, or bytes are not the signed manifest.
|
|
93
|
+
*
|
|
94
|
+
* The scan streams, so the size of the largest file does not decide whether the check can run, and
|
|
95
|
+
* the refusal names the one mismatch a caller can produce on its own: a capture and a verify that
|
|
96
|
+
* disagree about `portableTree`.
|
|
97
|
+
*/
|
|
98
|
+
async function verifyMaterializedWorkspace(root, expected, options = {}) {
|
|
99
|
+
assertWorkspaceManifest(await scanMaterializedWorkspaceManifest(root, options), expected);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The canonical manifest of one materialized workspace, read without holding any file.
|
|
103
|
+
*
|
|
104
|
+
* Every file is digested by streaming, so the size of the largest file does not decide whether the
|
|
105
|
+
* workspace can be described. `FileHandle.readFile` refuses anything above 2 GiB with
|
|
106
|
+
* `ERR_FS_FILE_TOO_LARGE`, which made a workspace holding one such artifact impossible to verify
|
|
107
|
+
* against a manifest it already matched. The digest is sha-256 over the same bytes either way, so
|
|
108
|
+
* a manifest a buffered read produced is reproduced exactly.
|
|
109
|
+
*/
|
|
110
|
+
async function scanMaterializedWorkspaceManifest(root, options = {}) {
|
|
111
|
+
return workspaceManifestFromEntries(await walkWorkspace(root, options, false));
|
|
112
|
+
}
|
|
113
|
+
async function captureMaterializedWorkspace(root, options = {}) {
|
|
114
|
+
const entries = await walkWorkspace(root, options, true);
|
|
115
|
+
return {
|
|
116
|
+
manifest: workspaceManifestFromEntries(entries),
|
|
117
|
+
files: entries.map((entry) => ({
|
|
118
|
+
path: entry.path,
|
|
119
|
+
mode: entry.mode,
|
|
120
|
+
bytes: Uint8Array.from(capturedBytes(entry))
|
|
121
|
+
}))
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Capture exact verified regular-file bytes for fresh isolated materialization. */
|
|
125
|
+
async function readMaterializedWorkspaceFiles(root, expected, options = {}) {
|
|
126
|
+
const observed = await captureMaterializedWorkspace(root, options);
|
|
127
|
+
assertWorkspaceManifest(observed.manifest, expected);
|
|
128
|
+
return observed.files.map((file) => Object.freeze({
|
|
129
|
+
path: file.path,
|
|
130
|
+
mode: file.mode,
|
|
131
|
+
bytes: Uint8Array.from(file.bytes)
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Build the canonical manifest for files a caller already holds — the shape a remote executor
|
|
136
|
+
* returns. Pass `portableTree` to record Git's two file modes instead of exact permission bits, and
|
|
137
|
+
* pass the same flag to every verify that reads the result.
|
|
138
|
+
*/
|
|
139
|
+
function candidateWorkspaceManifest(files, options = {}) {
|
|
140
|
+
return workspaceManifestFromEntries(files.map((file) => ({
|
|
141
|
+
path: file.path,
|
|
142
|
+
mode: options.portableTree === true ? portableFileMode(file.mode) : file.mode,
|
|
143
|
+
sha256: sha256Bytes(file.bytes),
|
|
144
|
+
byteLength: file.bytes.byteLength
|
|
145
|
+
})));
|
|
146
|
+
}
|
|
147
|
+
function workspaceManifestFromEntries(entries) {
|
|
148
|
+
return {
|
|
149
|
+
kind: "agent-candidate-workspace-manifest",
|
|
150
|
+
files: entries.map((entry) => ({
|
|
151
|
+
path: entry.path,
|
|
152
|
+
mode: entry.mode,
|
|
153
|
+
sha256: entry.sha256,
|
|
154
|
+
byteLength: entry.byteLength
|
|
155
|
+
})).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/** Git records exactly two file modes, and a portable-tree scan records the same two. */
|
|
159
|
+
function portableFileMode(mode) {
|
|
160
|
+
return (mode & 73) !== 0 ? 493 : 420;
|
|
161
|
+
}
|
|
162
|
+
function capturedBytes(entry) {
|
|
163
|
+
if (!entry.bytes) throw new Error(`workspace file was digested without its bytes: ${entry.path}`);
|
|
164
|
+
return entry.bytes;
|
|
165
|
+
}
|
|
166
|
+
function assertWorkspaceManifest(observed, expected) {
|
|
167
|
+
if (Buffer.from(canonicalCandidateBytes(observed)).equals(canonicalCandidateBytes(expected))) return;
|
|
168
|
+
if (Buffer.from(canonicalCandidateBytes(withPortableModes(observed))).equals(canonicalCandidateBytes(withPortableModes(expected)))) throw new Error("materialized workspace files do not match the signed manifest: only the file modes differ, so the capture and this verify disagree about portableTree");
|
|
169
|
+
throw new Error("materialized workspace files, modes, or bytes do not match the signed manifest");
|
|
170
|
+
}
|
|
171
|
+
function withPortableModes(material) {
|
|
172
|
+
return {
|
|
173
|
+
...material,
|
|
174
|
+
files: material.files.map((file) => ({
|
|
175
|
+
...file,
|
|
176
|
+
mode: portableFileMode(file.mode)
|
|
177
|
+
}))
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
async function verifyMaterializedProfileWorkspace(root, expected, fileRoot = "workspace") {
|
|
181
|
+
const observedProfile = (await scanMaterializedWorkspaceManifest(root)).files.map(({ path, mode, sha256 }) => ({
|
|
182
|
+
relPath: path,
|
|
183
|
+
mode,
|
|
184
|
+
contentSha256: sha256
|
|
185
|
+
}));
|
|
186
|
+
const expectedFiles = expected.files.filter((file) => (file.root ?? "workspace") === fileRoot).map(({ root: _root, ...file }) => file);
|
|
187
|
+
if (!Buffer.from(canonicalCandidateBytes(observedProfile)).equals(canonicalCandidateBytes(expectedFiles))) throw new Error(`profile ${fileRoot} staging files, modes, or bytes do not match the signed profile plan`);
|
|
188
|
+
}
|
|
189
|
+
async function walkWorkspace(root, options, keepBytes) {
|
|
190
|
+
const ignoredProtectedRootEntries = new Set(options.ignoredProtectedRootEntries ?? []);
|
|
191
|
+
const limits = options.limits;
|
|
192
|
+
const requestedRoot = resolve(root);
|
|
193
|
+
const rootStats = await lstat(requestedRoot);
|
|
194
|
+
if (!rootStats.isDirectory() || rootStats.isSymbolicLink()) throw new Error("workspace root must be a real directory");
|
|
195
|
+
const absoluteRoot = await realpath(requestedRoot);
|
|
196
|
+
const resolvedStats = await lstat(absoluteRoot);
|
|
197
|
+
if (!resolvedStats.isDirectory() || resolvedStats.isSymbolicLink()) throw new Error("workspace root must resolve to a real directory");
|
|
198
|
+
const scanned = [];
|
|
199
|
+
let totalBytes = 0;
|
|
200
|
+
async function visit(directory) {
|
|
201
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
202
|
+
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
203
|
+
for (const entry of entries) {
|
|
204
|
+
if (directory === absoluteRoot && ignoredProtectedRootEntries.has(entry.name)) continue;
|
|
205
|
+
const absolute = resolve(directory, entry.name);
|
|
206
|
+
const relPath = relative(absoluteRoot, absolute).split(sep).join("/");
|
|
207
|
+
if (!relPath || relPath.startsWith("../") || relPath.includes("/../")) throw new Error(`workspace entry escapes root: ${relPath}`);
|
|
208
|
+
const stats = await lstat(absolute);
|
|
209
|
+
if (stats.isSymbolicLink()) throw new Error(await symlinkRefusal(absolute, relPath, absoluteRoot));
|
|
210
|
+
if (stats.isDirectory()) {
|
|
211
|
+
await visit(absolute);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (!stats.isFile()) throw new Error(`workspace contains a non-regular entry: ${relPath}`);
|
|
215
|
+
if (limits && scanned.length >= limits.maxFiles) throw new Error("workspace exceeds maxFiles");
|
|
216
|
+
const descriptor = await open(absolute, constants.O_RDONLY | (typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0));
|
|
217
|
+
try {
|
|
218
|
+
const openedStats = await descriptor.stat();
|
|
219
|
+
if (!openedStats.isFile()) throw new Error(`workspace contains a non-regular entry: ${relPath}`);
|
|
220
|
+
if (openedStats.nlink !== 1) throw new Error(`workspace contains a hard-linked file: ${relPath}`);
|
|
221
|
+
const mode = options.portableTree === true ? portableFileMode(openedStats.mode) : openedStats.mode & 511;
|
|
222
|
+
if (limits && openedStats.size > limits.maxFileBytes) throw new Error(`workspace file exceeds maxFileBytes: ${relPath}`);
|
|
223
|
+
const remainingBytes = limits ? limits.maxTotalFileBytes - totalBytes : void 0;
|
|
224
|
+
if (remainingBytes !== void 0 && openedStats.size > remainingBytes) throw new Error("workspace exceeds maxTotalFileBytes");
|
|
225
|
+
const read = await readWorkspaceFile(descriptor, limits ? Math.min(limits.maxFileBytes, remainingBytes ?? limits.maxFileBytes) : void 0, keepBytes, relPath);
|
|
226
|
+
totalBytes += read.byteLength;
|
|
227
|
+
scanned.push({
|
|
228
|
+
path: relPath,
|
|
229
|
+
mode,
|
|
230
|
+
sha256: read.sha256,
|
|
231
|
+
byteLength: read.byteLength,
|
|
232
|
+
...read.bytes === void 0 ? {} : { bytes: read.bytes }
|
|
233
|
+
});
|
|
234
|
+
} finally {
|
|
235
|
+
await descriptor.close();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
await visit(absoluteRoot);
|
|
240
|
+
return scanned;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Why one symbolic link is refused, in the terms that separate a portable link from a link that
|
|
244
|
+
* reaches outside the tree.
|
|
245
|
+
*
|
|
246
|
+
* Every link is refused, in both mode policies. `AgentCandidateWorkspaceManifestMaterial` has no
|
|
247
|
+
* representation for one — `mode`, `sha256` and `byteLength` describe a regular file — so a link
|
|
248
|
+
* recorded as a file would let two different trees share one digest. The reason says which kind of
|
|
249
|
+
* link it was, so a caller can tell a link it can rewrite from one it cannot.
|
|
250
|
+
*/
|
|
251
|
+
async function symlinkRefusal(absolute, relPath, absoluteRoot) {
|
|
252
|
+
const target = await readlink(absolute);
|
|
253
|
+
if (isAbsolute(target)) return `workspace contains an absolute symlink: ${relPath} -> ${target}`;
|
|
254
|
+
if (!isWithin(absoluteRoot, resolve(dirname(absolute), target))) return `workspace contains a symlink that escapes its tree: ${relPath} -> ${target}`;
|
|
255
|
+
let physical;
|
|
256
|
+
try {
|
|
257
|
+
physical = await realpath(absolute);
|
|
258
|
+
} catch {
|
|
259
|
+
return `workspace contains an unresolved symlink: ${relPath} -> ${target}`;
|
|
260
|
+
}
|
|
261
|
+
if (!isWithin(absoluteRoot, physical)) return `workspace contains a symlink that resolves outside its tree: ${relPath} -> ${target}`;
|
|
262
|
+
return `workspace contains a symlink: ${relPath} -> ${target}`;
|
|
263
|
+
}
|
|
264
|
+
function isWithin(root, path) {
|
|
265
|
+
return path === root || path.startsWith(`${root}${sep}`);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Read one open regular file into its digest, keeping the bytes only when the caller needs them.
|
|
269
|
+
*
|
|
270
|
+
* The content reaches the hash in 1 MiB chunks and is never held whole for a digest-only walk, so
|
|
271
|
+
* the size of the largest file does not decide whether a workspace can be described.
|
|
272
|
+
* `FileHandle.readFile` refuses anything above 2 GiB with `ERR_FS_FILE_TOO_LARGE`. Hashing the
|
|
273
|
+
* chunks in order equals hashing the whole buffer, so a manifest a buffered read produced is
|
|
274
|
+
* reproduced byte for byte.
|
|
275
|
+
*/
|
|
276
|
+
async function readWorkspaceFile(descriptor, maxBytes, keepBytes, path) {
|
|
277
|
+
const hash = createHash("sha256");
|
|
278
|
+
const buffer = Buffer.allocUnsafe(1024 * 1024);
|
|
279
|
+
const chunks = [];
|
|
280
|
+
let total = 0;
|
|
281
|
+
while (true) {
|
|
282
|
+
const { bytesRead } = await descriptor.read(buffer, 0, buffer.byteLength, null);
|
|
283
|
+
if (bytesRead === 0) break;
|
|
284
|
+
total += bytesRead;
|
|
285
|
+
if (maxBytes !== void 0 && total > maxBytes) throw new Error(`workspace file exceeds its capture limit: ${path}`);
|
|
286
|
+
const chunk = buffer.subarray(0, bytesRead);
|
|
287
|
+
hash.update(chunk);
|
|
288
|
+
if (keepBytes) chunks.push(Buffer.from(chunk));
|
|
289
|
+
}
|
|
290
|
+
const sha256 = `sha256:${hash.digest("hex")}`;
|
|
291
|
+
return keepBytes ? {
|
|
292
|
+
sha256,
|
|
293
|
+
byteLength: total,
|
|
294
|
+
bytes: Buffer.concat(chunks, total)
|
|
295
|
+
} : {
|
|
296
|
+
sha256,
|
|
297
|
+
byteLength: total
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
67
301
|
//#region src/candidate-execution/system-prompt.ts
|
|
68
302
|
const SYSTEM_PROMPT_FILE = ".tangle/system-prompt.md";
|
|
69
303
|
const APPEND_SYSTEM_PROMPT_FILE = ".tangle/append-system-prompt.md";
|
|
@@ -900,228 +1134,6 @@ function candidateTerminalWindowMs(cleanupTimeoutMs) {
|
|
|
900
1134
|
return windowMs;
|
|
901
1135
|
}
|
|
902
1136
|
//#endregion
|
|
903
|
-
//#region src/candidate-execution/artifacts.ts
|
|
904
|
-
function artifactCacheKey(artifact) {
|
|
905
|
-
return `${artifact.sha256}:${artifact.byteLength}`;
|
|
906
|
-
}
|
|
907
|
-
async function readVerifiedArtifact(artifact, port) {
|
|
908
|
-
const bytes = "content" in artifact ? Buffer.from(artifact.content, "base64") : await port.read(artifact);
|
|
909
|
-
verifyBytes(bytes, artifact.sha256, artifact.byteLength, "candidate artifact");
|
|
910
|
-
return Uint8Array.from(bytes);
|
|
911
|
-
}
|
|
912
|
-
function verifyBytes(bytes, digest, byteLength, label) {
|
|
913
|
-
if (bytes.byteLength !== byteLength) throw new Error(`${label} byte length ${bytes.byteLength} does not match ${byteLength}`);
|
|
914
|
-
const actual = sha256Bytes(bytes);
|
|
915
|
-
if (actual !== digest) throw new Error(`${label} digest ${actual} does not match ${digest}`);
|
|
916
|
-
}
|
|
917
|
-
async function verifyWorkspaceSnapshotArtifacts(snapshot, port) {
|
|
918
|
-
const [manifest, archive] = await Promise.all([readVerifiedArtifact(snapshot.manifest, port), readVerifiedArtifact(snapshot.archive, port)]);
|
|
919
|
-
const canonicalManifest = canonicalCandidateBytes(snapshot.material);
|
|
920
|
-
if (!Buffer.from(manifest).equals(Buffer.from(canonicalManifest))) throw new Error("workspace manifest artifact is not the exact canonical manifest material");
|
|
921
|
-
if (sha256Bytes(canonicalManifest) !== snapshot.digest) throw new Error("workspace snapshot digest does not match its canonical manifest material");
|
|
922
|
-
return {
|
|
923
|
-
manifest,
|
|
924
|
-
archive
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
async function verifyMaterializedWorkspace(root, expected, options = {}) {
|
|
928
|
-
assertWorkspaceManifest(await scanMaterializedWorkspaceManifest(root, options), expected);
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* The canonical manifest of one materialized workspace, read without holding any file.
|
|
932
|
-
*
|
|
933
|
-
* Every file is digested by streaming, so the size of the largest file does not decide whether the
|
|
934
|
-
* workspace can be described. `FileHandle.readFile` refuses anything above 2 GiB with
|
|
935
|
-
* `ERR_FS_FILE_TOO_LARGE`, which made a workspace holding one such artifact impossible to verify
|
|
936
|
-
* against a manifest it already matched. The digest is sha-256 over the same bytes either way, so
|
|
937
|
-
* a manifest a buffered read produced is reproduced exactly.
|
|
938
|
-
*/
|
|
939
|
-
async function scanMaterializedWorkspaceManifest(root, options = {}) {
|
|
940
|
-
return workspaceManifestFromEntries(await walkWorkspace(root, options, false));
|
|
941
|
-
}
|
|
942
|
-
async function captureMaterializedWorkspace(root, options = {}) {
|
|
943
|
-
const entries = await walkWorkspace(root, options, true);
|
|
944
|
-
return {
|
|
945
|
-
manifest: workspaceManifestFromEntries(entries),
|
|
946
|
-
files: entries.map((entry) => ({
|
|
947
|
-
path: entry.path,
|
|
948
|
-
mode: entry.mode,
|
|
949
|
-
bytes: Uint8Array.from(capturedBytes(entry))
|
|
950
|
-
}))
|
|
951
|
-
};
|
|
952
|
-
}
|
|
953
|
-
/** Capture exact verified regular-file bytes for fresh isolated materialization. */
|
|
954
|
-
async function readMaterializedWorkspaceFiles(root, expected, options = {}) {
|
|
955
|
-
const observed = await captureMaterializedWorkspace(root, options);
|
|
956
|
-
assertWorkspaceManifest(observed.manifest, expected);
|
|
957
|
-
return observed.files.map((file) => Object.freeze({
|
|
958
|
-
path: file.path,
|
|
959
|
-
mode: file.mode,
|
|
960
|
-
bytes: Uint8Array.from(file.bytes)
|
|
961
|
-
}));
|
|
962
|
-
}
|
|
963
|
-
function candidateWorkspaceManifest(files, options = {}) {
|
|
964
|
-
return workspaceManifestFromEntries(files.map((file) => ({
|
|
965
|
-
path: file.path,
|
|
966
|
-
mode: options.portableTree === true ? portableFileMode(file.mode) : file.mode,
|
|
967
|
-
sha256: sha256Bytes(file.bytes),
|
|
968
|
-
byteLength: file.bytes.byteLength
|
|
969
|
-
})));
|
|
970
|
-
}
|
|
971
|
-
function workspaceManifestFromEntries(entries) {
|
|
972
|
-
return {
|
|
973
|
-
kind: "agent-candidate-workspace-manifest",
|
|
974
|
-
files: entries.map((entry) => ({
|
|
975
|
-
path: entry.path,
|
|
976
|
-
mode: entry.mode,
|
|
977
|
-
sha256: entry.sha256,
|
|
978
|
-
byteLength: entry.byteLength
|
|
979
|
-
})).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0)
|
|
980
|
-
};
|
|
981
|
-
}
|
|
982
|
-
/** Git records exactly two file modes, and a portable-tree scan records the same two. */
|
|
983
|
-
function portableFileMode(mode) {
|
|
984
|
-
return (mode & 73) !== 0 ? 493 : 420;
|
|
985
|
-
}
|
|
986
|
-
function capturedBytes(entry) {
|
|
987
|
-
if (!entry.bytes) throw new Error(`workspace file was digested without its bytes: ${entry.path}`);
|
|
988
|
-
return entry.bytes;
|
|
989
|
-
}
|
|
990
|
-
function assertWorkspaceManifest(observed, expected) {
|
|
991
|
-
if (Buffer.from(canonicalCandidateBytes(observed)).equals(canonicalCandidateBytes(expected))) return;
|
|
992
|
-
if (Buffer.from(canonicalCandidateBytes(withPortableModes(observed))).equals(canonicalCandidateBytes(withPortableModes(expected)))) throw new Error("materialized workspace files do not match the signed manifest: only the file modes differ, so the capture and this verify disagree about portableTree");
|
|
993
|
-
throw new Error("materialized workspace files, modes, or bytes do not match the signed manifest");
|
|
994
|
-
}
|
|
995
|
-
function withPortableModes(material) {
|
|
996
|
-
return {
|
|
997
|
-
...material,
|
|
998
|
-
files: material.files.map((file) => ({
|
|
999
|
-
...file,
|
|
1000
|
-
mode: portableFileMode(file.mode)
|
|
1001
|
-
}))
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
async function verifyMaterializedProfileWorkspace(root, expected, fileRoot = "workspace") {
|
|
1005
|
-
const observedProfile = (await scanMaterializedWorkspaceManifest(root)).files.map(({ path, mode, sha256 }) => ({
|
|
1006
|
-
relPath: path,
|
|
1007
|
-
mode,
|
|
1008
|
-
contentSha256: sha256
|
|
1009
|
-
}));
|
|
1010
|
-
const expectedFiles = expected.files.filter((file) => (file.root ?? "workspace") === fileRoot).map(({ root: _root, ...file }) => file);
|
|
1011
|
-
if (!Buffer.from(canonicalCandidateBytes(observedProfile)).equals(canonicalCandidateBytes(expectedFiles))) throw new Error(`profile ${fileRoot} staging files, modes, or bytes do not match the signed profile plan`);
|
|
1012
|
-
}
|
|
1013
|
-
async function walkWorkspace(root, options, keepBytes) {
|
|
1014
|
-
const ignoredProtectedRootEntries = new Set(options.ignoredProtectedRootEntries ?? []);
|
|
1015
|
-
const limits = options.limits;
|
|
1016
|
-
const requestedRoot = resolve(root);
|
|
1017
|
-
const rootStats = await lstat(requestedRoot);
|
|
1018
|
-
if (!rootStats.isDirectory() || rootStats.isSymbolicLink()) throw new Error("workspace root must be a real directory");
|
|
1019
|
-
const absoluteRoot = await realpath(requestedRoot);
|
|
1020
|
-
const resolvedStats = await lstat(absoluteRoot);
|
|
1021
|
-
if (!resolvedStats.isDirectory() || resolvedStats.isSymbolicLink()) throw new Error("workspace root must resolve to a real directory");
|
|
1022
|
-
const scanned = [];
|
|
1023
|
-
let totalBytes = 0;
|
|
1024
|
-
async function visit(directory) {
|
|
1025
|
-
const entries = await readdir(directory, { withFileTypes: true });
|
|
1026
|
-
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
1027
|
-
for (const entry of entries) {
|
|
1028
|
-
if (directory === absoluteRoot && ignoredProtectedRootEntries.has(entry.name)) continue;
|
|
1029
|
-
const absolute = resolve(directory, entry.name);
|
|
1030
|
-
const relPath = relative(absoluteRoot, absolute).split(sep).join("/");
|
|
1031
|
-
if (!relPath || relPath.startsWith("../") || relPath.includes("/../")) throw new Error(`workspace entry escapes root: ${relPath}`);
|
|
1032
|
-
const stats = await lstat(absolute);
|
|
1033
|
-
if (stats.isSymbolicLink()) throw new Error(await symlinkRefusal(absolute, relPath, absoluteRoot));
|
|
1034
|
-
if (stats.isDirectory()) {
|
|
1035
|
-
await visit(absolute);
|
|
1036
|
-
continue;
|
|
1037
|
-
}
|
|
1038
|
-
if (!stats.isFile()) throw new Error(`workspace contains a non-regular entry: ${relPath}`);
|
|
1039
|
-
if (limits && scanned.length >= limits.maxFiles) throw new Error("workspace exceeds maxFiles");
|
|
1040
|
-
const descriptor = await open(absolute, constants.O_RDONLY | (typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0));
|
|
1041
|
-
try {
|
|
1042
|
-
const openedStats = await descriptor.stat();
|
|
1043
|
-
if (!openedStats.isFile()) throw new Error(`workspace contains a non-regular entry: ${relPath}`);
|
|
1044
|
-
if (openedStats.nlink !== 1) throw new Error(`workspace contains a hard-linked file: ${relPath}`);
|
|
1045
|
-
const mode = options.portableTree === true ? portableFileMode(openedStats.mode) : openedStats.mode & 511;
|
|
1046
|
-
if (limits && openedStats.size > limits.maxFileBytes) throw new Error(`workspace file exceeds maxFileBytes: ${relPath}`);
|
|
1047
|
-
const remainingBytes = limits ? limits.maxTotalFileBytes - totalBytes : void 0;
|
|
1048
|
-
if (remainingBytes !== void 0 && openedStats.size > remainingBytes) throw new Error("workspace exceeds maxTotalFileBytes");
|
|
1049
|
-
const read = await readWorkspaceFile(descriptor, limits ? Math.min(limits.maxFileBytes, remainingBytes ?? limits.maxFileBytes) : void 0, keepBytes, relPath);
|
|
1050
|
-
totalBytes += read.byteLength;
|
|
1051
|
-
scanned.push({
|
|
1052
|
-
path: relPath,
|
|
1053
|
-
mode,
|
|
1054
|
-
sha256: read.sha256,
|
|
1055
|
-
byteLength: read.byteLength,
|
|
1056
|
-
...read.bytes === void 0 ? {} : { bytes: read.bytes }
|
|
1057
|
-
});
|
|
1058
|
-
} finally {
|
|
1059
|
-
await descriptor.close();
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
await visit(absoluteRoot);
|
|
1064
|
-
return scanned;
|
|
1065
|
-
}
|
|
1066
|
-
/**
|
|
1067
|
-
* Why one symbolic link is refused, in the terms that separate a portable link from a link that
|
|
1068
|
-
* reaches outside the tree.
|
|
1069
|
-
*
|
|
1070
|
-
* Every link is refused, in both mode policies. `AgentCandidateWorkspaceManifestMaterial` has no
|
|
1071
|
-
* representation for one — `mode`, `sha256` and `byteLength` describe a regular file — so a link
|
|
1072
|
-
* recorded as a file would let two different trees share one digest. The reason says which kind of
|
|
1073
|
-
* link it was, so a caller can tell a link it can rewrite from one it cannot.
|
|
1074
|
-
*/
|
|
1075
|
-
async function symlinkRefusal(absolute, relPath, absoluteRoot) {
|
|
1076
|
-
const target = await readlink(absolute);
|
|
1077
|
-
if (isAbsolute(target)) return `workspace contains an absolute symlink: ${relPath} -> ${target}`;
|
|
1078
|
-
if (!isWithin(absoluteRoot, resolve(dirname(absolute), target))) return `workspace contains a symlink that escapes its tree: ${relPath} -> ${target}`;
|
|
1079
|
-
let physical;
|
|
1080
|
-
try {
|
|
1081
|
-
physical = await realpath(absolute);
|
|
1082
|
-
} catch {
|
|
1083
|
-
return `workspace contains an unresolved symlink: ${relPath} -> ${target}`;
|
|
1084
|
-
}
|
|
1085
|
-
if (!isWithin(absoluteRoot, physical)) return `workspace contains a symlink that resolves outside its tree: ${relPath} -> ${target}`;
|
|
1086
|
-
return `workspace contains a symlink: ${relPath} -> ${target}`;
|
|
1087
|
-
}
|
|
1088
|
-
function isWithin(root, path) {
|
|
1089
|
-
return path === root || path.startsWith(`${root}${sep}`);
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* Read one open regular file into its digest, keeping the bytes only when the caller needs them.
|
|
1093
|
-
*
|
|
1094
|
-
* The content reaches the hash in 1 MiB chunks and is never held whole for a digest-only walk, so
|
|
1095
|
-
* the size of the largest file does not decide whether a workspace can be described.
|
|
1096
|
-
* `FileHandle.readFile` refuses anything above 2 GiB with `ERR_FS_FILE_TOO_LARGE`. Hashing the
|
|
1097
|
-
* chunks in order equals hashing the whole buffer, so a manifest a buffered read produced is
|
|
1098
|
-
* reproduced byte for byte.
|
|
1099
|
-
*/
|
|
1100
|
-
async function readWorkspaceFile(descriptor, maxBytes, keepBytes, path) {
|
|
1101
|
-
const hash = createHash("sha256");
|
|
1102
|
-
const buffer = Buffer.allocUnsafe(1024 * 1024);
|
|
1103
|
-
const chunks = [];
|
|
1104
|
-
let total = 0;
|
|
1105
|
-
while (true) {
|
|
1106
|
-
const { bytesRead } = await descriptor.read(buffer, 0, buffer.byteLength, null);
|
|
1107
|
-
if (bytesRead === 0) break;
|
|
1108
|
-
total += bytesRead;
|
|
1109
|
-
if (maxBytes !== void 0 && total > maxBytes) throw new Error(`workspace file exceeds its capture limit: ${path}`);
|
|
1110
|
-
const chunk = buffer.subarray(0, bytesRead);
|
|
1111
|
-
hash.update(chunk);
|
|
1112
|
-
if (keepBytes) chunks.push(Buffer.from(chunk));
|
|
1113
|
-
}
|
|
1114
|
-
const sha256 = `sha256:${hash.digest("hex")}`;
|
|
1115
|
-
return keepBytes ? {
|
|
1116
|
-
sha256,
|
|
1117
|
-
byteLength: total,
|
|
1118
|
-
bytes: Buffer.concat(chunks, total)
|
|
1119
|
-
} : {
|
|
1120
|
-
sha256,
|
|
1121
|
-
byteLength: total
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
//#endregion
|
|
1125
1137
|
//#region src/candidate-execution/execution-roots.ts
|
|
1126
1138
|
/** Validate the canonical identity and isolation boundary for execution roots. */
|
|
1127
1139
|
function assertAgentCandidateExecutionRoots(roots) {
|
|
@@ -4645,6 +4657,6 @@ function errorMessage(error) {
|
|
|
4645
4657
|
return error instanceof Error ? error.message : String(error);
|
|
4646
4658
|
}
|
|
4647
4659
|
//#endregion
|
|
4648
|
-
export {
|
|
4660
|
+
export { parseExactAgentProfile as $, assertRecoveryMatchesStaged as A, assertExactObjectKeys as B, assertNoGitIndirection as C, candidateCleanupDeadline as D, assertAgentCandidateExecutionRoots as E, rejectedFinish as F, applyExactAgentProfileDiff as G, PI_CANDIDATE_AGENT_DIR_ENV as H, rejectedStage as I, createAgentCandidateProfileActivation as J, assertCandidateProfileBinding as K, requireStagedTerminal as L, assertTerminalMatchesClaim as M, assertTerminalMatchesStaged as N, candidateCleanupTimeout as O, recoveredTerminalRecord as P, parseAgentCandidateProfileActivation as Q, sealTerminalDigest as R, CANDIDATE_TRACE_TAGS as S, runCandidateGit as T, PI_CANDIDATE_SESSION_DIR_ENV as U, isWellFormedUnicode as V, agentCandidateProfileAsAgentProfile as W, materializeAgentCandidateProfilePlan as X, freezeGenericAgentCandidateProfile as Y, omitUndefinedObjectFields as Z, candidateExecutionClaim as _, persistCandidateOutputArtifact as a, scanMaterializedWorkspaceManifest as at, consumePreparedCandidateExecution as b, CANDIDATE_KNOWLEDGE_ROOT_ENV as c, canonicalCandidateBytes as ct, verifiedResourceTextByDigest as d, deepFreezeCandidate as dt, parseExactAgentProfileDiff as et, verifyAgentCandidateBundle as f, embeddedCandidateArtifact as ft, candidateClaimFileInternals as g, verifyCanonicalCandidateDocument as gt, InMemoryAgentCandidateExecutionClaimStore as h, sha256Bytes as ht, persistCandidateModelSettlementEvidence as i, readVerifiedArtifact as it, assertTerminalAllowedInPhase as j, withinCandidateCleanupDeadline as k, candidateKnowledgeExecutionPaths as l, canonicalCandidateDigest$1 as lt, usdToNanos as m, omitTopLevelDigest as mt, executePreparedAgentCandidate as n, candidateWorkspaceManifest as nt, sealAgentCandidateExecutorStopAcknowledgement as o, verifyBytes as ot, sealAgentCandidateModelSettlement as p, immutableCandidateValue as pt, candidateProfileAgentPaths as q, RecoveryAgentCandidateTraceStore as r, captureMaterializedWorkspace as rt, CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV as s, verifyMaterializedWorkspace as st, prepareAgentCandidateExecution as t, parseExactCandidateProfile as tt, AGENT_CANDIDATE_EXECUTION_SUPPORT as u, canonicalCandidateDocument as ut, assertPreparedCandidateIntegrity as v, readCandidateGitTreeFiles as w, CANDIDATE_TRACE_ENV as x, beginPreparedCandidateDisposal as y, terminalRecord as z };
|
|
4649
4661
|
|
|
4650
|
-
//# sourceMappingURL=prepare-
|
|
4662
|
+
//# sourceMappingURL=prepare-B5fJ7mLS.js.map
|