@tangle-network/agent-runtime 0.249.1 → 0.252.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-ygjQvYwG.js → activation-BSLatbiJ.js} +3 -3
- package/dist/{activation-ygjQvYwG.js.map → activation-BSLatbiJ.js.map} +1 -1
- package/dist/{activation-CZz7kkgd.d.ts → activation-BykUtuec.d.ts} +2 -2
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +2 -2
- package/dist/bundle-DXrBPEFw.js +17 -0
- package/dist/bundle-DXrBPEFw.js.map +1 -0
- package/dist/candidate-execution/index.js +4 -4
- package/dist/{coordination-driver-B61Hh6B1.js → coordination-driver-QxitIuva.js} +21 -8
- package/dist/coordination-driver-QxitIuva.js.map +1 -0
- package/dist/{delegate-A6EYmMxy.js → delegate-BB90iDo7.js} +2 -2
- package/dist/{delegate-A6EYmMxy.js.map → delegate-BB90iDo7.js.map} +1 -1
- package/dist/durable.d.ts +1 -1
- package/dist/durable.js +2 -2
- package/dist/{graph-CXwmMtTx.js → graph-yC6wqOIt.js} +3 -3
- package/dist/{graph-CXwmMtTx.js.map → graph-yC6wqOIt.js.map} +1 -1
- package/dist/{improvement-cycle-B049YmQ8.js → improvement-cycle-on_u94aK.js} +5 -5
- package/dist/{improvement-cycle-B049YmQ8.js.map → improvement-cycle-on_u94aK.js.map} +1 -1
- package/dist/{index-BV5EmjCL.d.ts → index-DGWG7wSS.d.ts} +14 -6
- package/dist/index.d.ts +4 -4
- package/dist/index.js +9 -10
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +2 -2
- package/dist/intelligence.js +6 -6
- package/dist/kernel.d.ts +3 -3
- package/dist/kernel.js +9 -9
- package/dist/{loop-runner-bin-q0akFXYX.d.ts → loop-runner-bin-CsVNUclF.d.ts} +2 -2
- package/dist/{loop-runner-bin-C1O16oIq.js → loop-runner-bin-PL0dItet.js} +3 -3
- package/dist/{loop-runner-bin-C1O16oIq.js.map → loop-runner-bin-PL0dItet.js.map} +1 -1
- 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 +2 -2
- package/dist/mcp/index.js +4 -4
- package/dist/{prepare-CibQrhfi.js → prepare-RuaAclli.js} +8 -598
- package/dist/prepare-RuaAclli.js.map +1 -0
- package/dist/{protected-model-port-Dhdi5mDl.js → protected-model-port-BFhSgMAy.js} +3 -3
- package/dist/{protected-model-port-Dhdi5mDl.js.map → protected-model-port-BFhSgMAy.js.map} +1 -1
- package/dist/{protected-redaction-Fn1ETfJ-.js → protected-redaction--F3v1oo8.js} +3 -54
- package/dist/protected-redaction--F3v1oo8.js.map +1 -0
- package/dist/{provision-supervisor-D7gC-Veu.js → provision-supervisor-DsAhgOpn.js} +4 -4
- package/dist/{provision-supervisor-D7gC-Veu.js.map → provision-supervisor-DsAhgOpn.js.map} +1 -1
- package/dist/{run-layout-hKAJGF4g.js → run-layout-vwd4SwX_.js} +15 -9
- package/dist/run-layout-vwd4SwX_.js.map +1 -0
- package/dist/{runtime-BVZIbtyL.js → runtime-CMNTa7Rw.js} +11 -10
- package/dist/{runtime-BVZIbtyL.js.map → runtime-CMNTa7Rw.js.map} +1 -1
- package/dist/{server-DHS1Gxt2.js → server-2fL_QElQ.js} +3 -3
- package/dist/{server-DHS1Gxt2.js.map → server-2fL_QElQ.js.map} +1 -1
- package/dist/{stream-agent-turn-D9IbZMys.d.ts → stream-agent-turn-oeWkjxMi.d.ts} +31 -4
- package/dist/{structural-rollout-z1A0okaB.js → structural-rollout-DRD-WnV-.js} +2 -2
- package/dist/{structural-rollout-z1A0okaB.js.map → structural-rollout-DRD-WnV-.js.map} +1 -1
- package/dist/{supervise-CnFk7_wb.js → supervise-BXzkqfTE.js} +9 -6
- package/dist/supervise-BXzkqfTE.js.map +1 -0
- package/dist/{supervisor-BIBWUFUr.js → supervisor-OJwKAnFd.js} +391 -187
- package/dist/supervisor-OJwKAnFd.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +14 -14
- package/dist/{top-app-d-bmwO7O.js → top-app-VAOrBskv.js} +2 -2
- package/dist/{top-app-d-bmwO7O.js.map → top-app-VAOrBskv.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/workspace-archive-DQGFwvM6.js +1209 -0
- package/dist/workspace-archive-DQGFwvM6.js.map +1 -0
- package/package.json +1 -1
- package/dist/coordination-driver-B61Hh6B1.js.map +0 -1
- package/dist/prepare-CibQrhfi.js.map +0 -1
- package/dist/protected-redaction-Fn1ETfJ-.js.map +0 -1
- package/dist/run-layout-hKAJGF4g.js.map +0 -1
- package/dist/supervise-CnFk7_wb.js.map +0 -1
- package/dist/supervisor-BIBWUFUr.js.map +0 -1
- package/dist/workspace-archive-DSRT4Tro.js +0 -572
- package/dist/workspace-archive-DSRT4Tro.js.map +0 -1
|
@@ -1,40 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as canonicalCandidateDocument, D as omitTopLevelDigest, E as immutableCandidateValue, O as sha256Bytes, S as canonicalCandidateDigest$1, T as embeddedCandidateArtifact, _ as verifyBytes, a as persistCandidateOutputArtifact, b as verifyWorkspaceSnapshotArtifacts, c as verifyTaskCheckout, d as isWellFormedUnicode, f as artifactCacheKey, h as readVerifiedArtifact, l as verifyTaskOutcomePatch, m as readMaterializedWorkspaceFiles, o as readCandidateGitHubResource, s as verifyCandidateCode, u as assertExactObjectKeys, v as verifyMaterializedProfileWorkspace, w as deepFreezeCandidate, x as canonicalCandidateBytes$1, y as verifyMaterializedWorkspace } from "./workspace-archive-DQGFwvM6.js";
|
|
2
|
+
import { i as redactProtectedValue, n as createProtectedRecordRedactor, r as redactProtectedReason, t as assertNoProtectedBytes } from "./protected-redaction--F3v1oo8.js";
|
|
2
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";
|
|
3
4
|
import { REDACTION_VERSION, isLlmSpan } from "@tangle-network/agent-eval";
|
|
4
5
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
|
|
8
|
-
import { lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rm, stat } from "node:fs/promises";
|
|
6
|
+
import { isAbsolute, join, posix, relative, resolve } from "node:path";
|
|
7
|
+
import { lstat, mkdtemp, readFile, readdir, rm } from "node:fs/promises";
|
|
9
8
|
import { applyAgentCandidateWorkspacePlan, isMaterializerHarness, materializeCandidateProfile, resolvePiRuntimePaths } from "@tangle-network/agent-profile-materialize";
|
|
10
9
|
import { tmpdir } from "node:os";
|
|
11
10
|
import { hashKnowledgeBase } from "@tangle-network/agent-knowledge";
|
|
12
|
-
//#region src/candidate-execution/exact-object.ts
|
|
13
|
-
/** Reject unknown fields while requiring every declared non-optional field. */
|
|
14
|
-
function assertExactObjectKeys(value, required, label, optional = []) {
|
|
15
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must be an object`);
|
|
16
|
-
const allowed = /* @__PURE__ */ new Set([...required, ...optional]);
|
|
17
|
-
if (allowed.size !== required.length + optional.length) throw new Error(`${label} exact-key contract contains duplicate fields`);
|
|
18
|
-
for (const key of Object.keys(value)) if (!allowed.has(key)) throw new Error(`${label} contains unknown field ${key}`);
|
|
19
|
-
for (const key of required) if (!(key in value)) throw new Error(`${label} is missing field ${key}`);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Reject a string carrying a lone surrogate. A well-formed UTF-16 string round-trips through UTF-8
|
|
23
|
-
* unchanged; a lone surrogate does not, so a value that passes here is safe to persist and re-read
|
|
24
|
-
* as the same bytes.
|
|
25
|
-
*/
|
|
26
|
-
function isWellFormedUnicode(value) {
|
|
27
|
-
for (let index = 0; index < value.length; index++) {
|
|
28
|
-
const code = value.charCodeAt(index);
|
|
29
|
-
if (code >= 55296 && code <= 56319) {
|
|
30
|
-
const next = value.charCodeAt(index + 1);
|
|
31
|
-
if (!(next >= 56320 && next <= 57343)) return false;
|
|
32
|
-
index++;
|
|
33
|
-
} else if (code >= 56320 && code <= 57343) return false;
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
11
|
//#region src/candidate-execution/claim-file-formats.ts
|
|
39
12
|
function sealCandidatePreparationEvidence(value, executionPlanDigest) {
|
|
40
13
|
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error("candidate execution preparation evidence must be an object");
|
|
@@ -791,9 +764,9 @@ function assertExecutionId(value) {
|
|
|
791
764
|
if (typeof value !== "string" || !/^[A-Za-z0-9._:-]{1,200}$/.test(value)) throw new Error("candidate execution claim executionId is invalid");
|
|
792
765
|
}
|
|
793
766
|
function assertBoundedIdentifier(value, label, maxLength) {
|
|
794
|
-
if (typeof value !== "string" || value.length === 0 || value.length > maxLength || hasControlCharacter
|
|
767
|
+
if (typeof value !== "string" || value.length === 0 || value.length > maxLength || hasControlCharacter(value)) throw new Error(`candidate execution ${label} is invalid`);
|
|
795
768
|
}
|
|
796
|
-
function hasControlCharacter
|
|
769
|
+
function hasControlCharacter(value) {
|
|
797
770
|
for (let index = 0; index < value.length; index++) {
|
|
798
771
|
const code = value.charCodeAt(index);
|
|
799
772
|
if (code < 32 || code === 127) return true;
|
|
@@ -867,240 +840,6 @@ function candidateTerminalWindowMs(cleanupTimeoutMs) {
|
|
|
867
840
|
return windowMs;
|
|
868
841
|
}
|
|
869
842
|
//#endregion
|
|
870
|
-
//#region src/candidate-execution/artifacts.ts
|
|
871
|
-
function artifactCacheKey(artifact) {
|
|
872
|
-
return `${artifact.sha256}:${artifact.byteLength}`;
|
|
873
|
-
}
|
|
874
|
-
async function readVerifiedArtifact(artifact, port) {
|
|
875
|
-
const bytes = "content" in artifact ? Buffer.from(artifact.content, "base64") : await port.read(artifact);
|
|
876
|
-
verifyBytes(bytes, artifact.sha256, artifact.byteLength, "candidate artifact");
|
|
877
|
-
return Uint8Array.from(bytes);
|
|
878
|
-
}
|
|
879
|
-
function verifyBytes(bytes, digest, byteLength, label) {
|
|
880
|
-
if (bytes.byteLength !== byteLength) throw new Error(`${label} byte length ${bytes.byteLength} does not match ${byteLength}`);
|
|
881
|
-
const actual = sha256Bytes(bytes);
|
|
882
|
-
if (actual !== digest) throw new Error(`${label} digest ${actual} does not match ${digest}`);
|
|
883
|
-
}
|
|
884
|
-
async function verifyWorkspaceSnapshotArtifacts(snapshot, port) {
|
|
885
|
-
const [manifest, archive] = await Promise.all([readVerifiedArtifact(snapshot.manifest, port), readVerifiedArtifact(snapshot.archive, port)]);
|
|
886
|
-
const canonicalManifest = canonicalCandidateBytes$1(snapshot.material);
|
|
887
|
-
if (!Buffer.from(manifest).equals(Buffer.from(canonicalManifest))) throw new Error("workspace manifest artifact is not the exact canonical manifest material");
|
|
888
|
-
if (sha256Bytes(canonicalManifest) !== snapshot.digest) throw new Error("workspace snapshot digest does not match its canonical manifest material");
|
|
889
|
-
return {
|
|
890
|
-
manifest,
|
|
891
|
-
archive
|
|
892
|
-
};
|
|
893
|
-
}
|
|
894
|
-
/**
|
|
895
|
-
* Refuse a materialized workspace whose files, modes, or bytes are not the signed manifest.
|
|
896
|
-
*
|
|
897
|
-
* The scan streams, so the size of the largest file does not decide whether the check can run, and
|
|
898
|
-
* the refusal names the one mismatch a caller can produce on its own: a capture and a verify that
|
|
899
|
-
* disagree about `portableTree`.
|
|
900
|
-
*/
|
|
901
|
-
async function verifyMaterializedWorkspace(root, expected, options = {}) {
|
|
902
|
-
assertWorkspaceManifest(await scanMaterializedWorkspaceManifest(root, options), expected);
|
|
903
|
-
}
|
|
904
|
-
/**
|
|
905
|
-
* The canonical manifest of one materialized workspace, read without holding any file.
|
|
906
|
-
*
|
|
907
|
-
* Every file is digested by streaming, so the size of the largest file does not decide whether the
|
|
908
|
-
* workspace can be described. `FileHandle.readFile` refuses anything above 2 GiB with
|
|
909
|
-
* `ERR_FS_FILE_TOO_LARGE`, which made a workspace holding one such artifact impossible to verify
|
|
910
|
-
* against a manifest it already matched. The digest is sha-256 over the same bytes either way, so
|
|
911
|
-
* a manifest a buffered read produced is reproduced exactly.
|
|
912
|
-
*/
|
|
913
|
-
async function scanMaterializedWorkspaceManifest(root, options = {}) {
|
|
914
|
-
return workspaceManifestFromEntries(await walkWorkspace(root, options, false));
|
|
915
|
-
}
|
|
916
|
-
async function captureMaterializedWorkspace(root, options = {}) {
|
|
917
|
-
const entries = await walkWorkspace(root, options, true);
|
|
918
|
-
return {
|
|
919
|
-
manifest: workspaceManifestFromEntries(entries),
|
|
920
|
-
files: entries.map((entry) => ({
|
|
921
|
-
path: entry.path,
|
|
922
|
-
mode: entry.mode,
|
|
923
|
-
bytes: Uint8Array.from(capturedBytes(entry))
|
|
924
|
-
}))
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
/** Capture exact verified regular-file bytes for fresh isolated materialization. */
|
|
928
|
-
async function readMaterializedWorkspaceFiles(root, expected, options = {}) {
|
|
929
|
-
const observed = await captureMaterializedWorkspace(root, options);
|
|
930
|
-
assertWorkspaceManifest(observed.manifest, expected);
|
|
931
|
-
return observed.files.map((file) => Object.freeze({
|
|
932
|
-
path: file.path,
|
|
933
|
-
mode: file.mode,
|
|
934
|
-
bytes: Uint8Array.from(file.bytes)
|
|
935
|
-
}));
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* Build the canonical manifest for files a caller already holds — the shape a remote executor
|
|
939
|
-
* returns. Pass `portableTree` to record Git's two file modes instead of exact permission bits, and
|
|
940
|
-
* pass the same flag to every verify that reads the result.
|
|
941
|
-
*/
|
|
942
|
-
function candidateWorkspaceManifest(files, options = {}) {
|
|
943
|
-
return workspaceManifestFromEntries(files.map((file) => ({
|
|
944
|
-
path: file.path,
|
|
945
|
-
mode: options.portableTree === true ? portableFileMode(file.mode) : file.mode,
|
|
946
|
-
sha256: sha256Bytes(file.bytes),
|
|
947
|
-
byteLength: file.bytes.byteLength
|
|
948
|
-
})));
|
|
949
|
-
}
|
|
950
|
-
function workspaceManifestFromEntries(entries) {
|
|
951
|
-
return {
|
|
952
|
-
kind: "agent-candidate-workspace-manifest",
|
|
953
|
-
files: entries.map((entry) => ({
|
|
954
|
-
path: entry.path,
|
|
955
|
-
mode: entry.mode,
|
|
956
|
-
sha256: entry.sha256,
|
|
957
|
-
byteLength: entry.byteLength
|
|
958
|
-
})).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0)
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
/** Git records exactly two file modes, and a portable-tree scan records the same two. */
|
|
962
|
-
function portableFileMode(mode) {
|
|
963
|
-
return (mode & 73) !== 0 ? 493 : 420;
|
|
964
|
-
}
|
|
965
|
-
function capturedBytes(entry) {
|
|
966
|
-
if (!entry.bytes) throw new Error(`workspace file was digested without its bytes: ${entry.path}`);
|
|
967
|
-
return entry.bytes;
|
|
968
|
-
}
|
|
969
|
-
function assertWorkspaceManifest(observed, expected) {
|
|
970
|
-
if (Buffer.from(canonicalCandidateBytes$1(observed)).equals(canonicalCandidateBytes$1(expected))) return;
|
|
971
|
-
if (Buffer.from(canonicalCandidateBytes$1(withPortableModes(observed))).equals(canonicalCandidateBytes$1(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");
|
|
972
|
-
throw new Error("materialized workspace files, modes, or bytes do not match the signed manifest");
|
|
973
|
-
}
|
|
974
|
-
function withPortableModes(material) {
|
|
975
|
-
return {
|
|
976
|
-
...material,
|
|
977
|
-
files: material.files.map((file) => ({
|
|
978
|
-
...file,
|
|
979
|
-
mode: portableFileMode(file.mode)
|
|
980
|
-
}))
|
|
981
|
-
};
|
|
982
|
-
}
|
|
983
|
-
async function verifyMaterializedProfileWorkspace(root, expected, fileRoot = "workspace") {
|
|
984
|
-
const observedProfile = (await scanMaterializedWorkspaceManifest(root)).files.map(({ path, mode, sha256 }) => ({
|
|
985
|
-
relPath: path,
|
|
986
|
-
mode,
|
|
987
|
-
contentSha256: sha256
|
|
988
|
-
}));
|
|
989
|
-
const expectedFiles = expected.files.filter((file) => (file.root ?? "workspace") === fileRoot).map(({ root: _root, ...file }) => file);
|
|
990
|
-
if (!Buffer.from(canonicalCandidateBytes$1(observedProfile)).equals(canonicalCandidateBytes$1(expectedFiles))) throw new Error(`profile ${fileRoot} staging files, modes, or bytes do not match the signed profile plan`);
|
|
991
|
-
}
|
|
992
|
-
async function walkWorkspace(root, options, keepBytes) {
|
|
993
|
-
const ignoredProtectedRootEntries = new Set(options.ignoredProtectedRootEntries ?? []);
|
|
994
|
-
const limits = options.limits;
|
|
995
|
-
const requestedRoot = resolve(root);
|
|
996
|
-
const rootStats = await lstat(requestedRoot);
|
|
997
|
-
if (!rootStats.isDirectory() || rootStats.isSymbolicLink()) throw new Error("workspace root must be a real directory");
|
|
998
|
-
const absoluteRoot = await realpath(requestedRoot);
|
|
999
|
-
const resolvedStats = await lstat(absoluteRoot);
|
|
1000
|
-
if (!resolvedStats.isDirectory() || resolvedStats.isSymbolicLink()) throw new Error("workspace root must resolve to a real directory");
|
|
1001
|
-
const scanned = [];
|
|
1002
|
-
let totalBytes = 0;
|
|
1003
|
-
async function visit(directory) {
|
|
1004
|
-
const entries = await readdir(directory, { withFileTypes: true });
|
|
1005
|
-
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
1006
|
-
for (const entry of entries) {
|
|
1007
|
-
if (directory === absoluteRoot && ignoredProtectedRootEntries.has(entry.name)) continue;
|
|
1008
|
-
const absolute = resolve(directory, entry.name);
|
|
1009
|
-
const relPath = relative(absoluteRoot, absolute).split(sep).join("/");
|
|
1010
|
-
if (!relPath || relPath.startsWith("../") || relPath.includes("/../")) throw new Error(`workspace entry escapes root: ${relPath}`);
|
|
1011
|
-
const stats = await lstat(absolute);
|
|
1012
|
-
if (stats.isSymbolicLink()) throw new Error(await symlinkRefusal(absolute, relPath, absoluteRoot));
|
|
1013
|
-
if (stats.isDirectory()) {
|
|
1014
|
-
await visit(absolute);
|
|
1015
|
-
continue;
|
|
1016
|
-
}
|
|
1017
|
-
if (!stats.isFile()) throw new Error(`workspace contains a non-regular entry: ${relPath}`);
|
|
1018
|
-
if (limits && scanned.length >= limits.maxFiles) throw new Error("workspace exceeds maxFiles");
|
|
1019
|
-
const descriptor = await open(absolute, constants.O_RDONLY | (typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0));
|
|
1020
|
-
try {
|
|
1021
|
-
const openedStats = await descriptor.stat();
|
|
1022
|
-
if (!openedStats.isFile()) throw new Error(`workspace contains a non-regular entry: ${relPath}`);
|
|
1023
|
-
if (openedStats.nlink !== 1) throw new Error(`workspace contains a hard-linked file: ${relPath}`);
|
|
1024
|
-
const mode = options.portableTree === true ? portableFileMode(openedStats.mode) : openedStats.mode & 511;
|
|
1025
|
-
if (limits && openedStats.size > limits.maxFileBytes) throw new Error(`workspace file exceeds maxFileBytes: ${relPath}`);
|
|
1026
|
-
const remainingBytes = limits ? limits.maxTotalFileBytes - totalBytes : void 0;
|
|
1027
|
-
if (remainingBytes !== void 0 && openedStats.size > remainingBytes) throw new Error("workspace exceeds maxTotalFileBytes");
|
|
1028
|
-
const read = await readWorkspaceFile(descriptor, limits ? Math.min(limits.maxFileBytes, remainingBytes ?? limits.maxFileBytes) : void 0, keepBytes, relPath);
|
|
1029
|
-
totalBytes += read.byteLength;
|
|
1030
|
-
scanned.push({
|
|
1031
|
-
path: relPath,
|
|
1032
|
-
mode,
|
|
1033
|
-
sha256: read.sha256,
|
|
1034
|
-
byteLength: read.byteLength,
|
|
1035
|
-
...read.bytes === void 0 ? {} : { bytes: read.bytes }
|
|
1036
|
-
});
|
|
1037
|
-
} finally {
|
|
1038
|
-
await descriptor.close();
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
await visit(absoluteRoot);
|
|
1043
|
-
return scanned;
|
|
1044
|
-
}
|
|
1045
|
-
/**
|
|
1046
|
-
* Why one symbolic link is refused, in the terms that separate a portable link from a link that
|
|
1047
|
-
* reaches outside the tree.
|
|
1048
|
-
*
|
|
1049
|
-
* Every link is refused, in both mode policies. `AgentCandidateWorkspaceManifestMaterial` has no
|
|
1050
|
-
* representation for one — `mode`, `sha256` and `byteLength` describe a regular file — so a link
|
|
1051
|
-
* recorded as a file would let two different trees share one digest. The reason says which kind of
|
|
1052
|
-
* link it was, so a caller can tell a link it can rewrite from one it cannot.
|
|
1053
|
-
*/
|
|
1054
|
-
async function symlinkRefusal(absolute, relPath, absoluteRoot) {
|
|
1055
|
-
const target = await readlink(absolute);
|
|
1056
|
-
if (isAbsolute(target)) return `workspace contains an absolute symlink: ${relPath} -> ${target}`;
|
|
1057
|
-
if (!isWithin(absoluteRoot, resolve(dirname(absolute), target))) return `workspace contains a symlink that escapes its tree: ${relPath} -> ${target}`;
|
|
1058
|
-
let physical;
|
|
1059
|
-
try {
|
|
1060
|
-
physical = await realpath(absolute);
|
|
1061
|
-
} catch {
|
|
1062
|
-
return `workspace contains an unresolved symlink: ${relPath} -> ${target}`;
|
|
1063
|
-
}
|
|
1064
|
-
if (!isWithin(absoluteRoot, physical)) return `workspace contains a symlink that resolves outside its tree: ${relPath} -> ${target}`;
|
|
1065
|
-
return `workspace contains a symlink: ${relPath} -> ${target}`;
|
|
1066
|
-
}
|
|
1067
|
-
function isWithin(root, path) {
|
|
1068
|
-
return path === root || path.startsWith(`${root}${sep}`);
|
|
1069
|
-
}
|
|
1070
|
-
/**
|
|
1071
|
-
* Read one open regular file into its digest, keeping the bytes only when the caller needs them.
|
|
1072
|
-
*
|
|
1073
|
-
* The content reaches the hash in 1 MiB chunks and is never held whole for a digest-only walk, so
|
|
1074
|
-
* the size of the largest file does not decide whether a workspace can be described.
|
|
1075
|
-
* `FileHandle.readFile` refuses anything above 2 GiB with `ERR_FS_FILE_TOO_LARGE`. Hashing the
|
|
1076
|
-
* chunks in order equals hashing the whole buffer, so a manifest a buffered read produced is
|
|
1077
|
-
* reproduced byte for byte.
|
|
1078
|
-
*/
|
|
1079
|
-
async function readWorkspaceFile(descriptor, maxBytes, keepBytes, path) {
|
|
1080
|
-
const hash = createHash("sha256");
|
|
1081
|
-
const buffer = Buffer.allocUnsafe(1024 * 1024);
|
|
1082
|
-
const chunks = [];
|
|
1083
|
-
let total = 0;
|
|
1084
|
-
while (true) {
|
|
1085
|
-
const { bytesRead } = await descriptor.read(buffer, 0, buffer.byteLength, null);
|
|
1086
|
-
if (bytesRead === 0) break;
|
|
1087
|
-
total += bytesRead;
|
|
1088
|
-
if (maxBytes !== void 0 && total > maxBytes) throw new Error(`workspace file exceeds its capture limit: ${path}`);
|
|
1089
|
-
const chunk = buffer.subarray(0, bytesRead);
|
|
1090
|
-
hash.update(chunk);
|
|
1091
|
-
if (keepBytes) chunks.push(Buffer.from(chunk));
|
|
1092
|
-
}
|
|
1093
|
-
const sha256 = `sha256:${hash.digest("hex")}`;
|
|
1094
|
-
return keepBytes ? {
|
|
1095
|
-
sha256,
|
|
1096
|
-
byteLength: total,
|
|
1097
|
-
bytes: Buffer.concat(chunks, total)
|
|
1098
|
-
} : {
|
|
1099
|
-
sha256,
|
|
1100
|
-
byteLength: total
|
|
1101
|
-
};
|
|
1102
|
-
}
|
|
1103
|
-
//#endregion
|
|
1104
843
|
//#region src/candidate-execution/execution-roots.ts
|
|
1105
844
|
/** Validate the canonical identity and isolation boundary for execution roots. */
|
|
1106
845
|
function assertAgentCandidateExecutionRoots(roots) {
|
|
@@ -1132,315 +871,6 @@ function executionPathsOverlap(left, right) {
|
|
|
1132
871
|
return a === b || b.startsWith(a === "/" ? "/" : `${a}/`) || a.startsWith(b === "/" ? "/" : `${b}/`);
|
|
1133
872
|
}
|
|
1134
873
|
//#endregion
|
|
1135
|
-
//#region src/candidate-execution/git-materialize.ts
|
|
1136
|
-
async function verifyCandidateCode(code, repositories, patchBytes) {
|
|
1137
|
-
if (code.kind === "disabled") return void 0;
|
|
1138
|
-
const repositoryRoot = await verifiedRepositoryRoot(code.repository, repositories);
|
|
1139
|
-
await assertCommitAndBaseTree(repositoryRoot, code.baseCommit, code.baseTree);
|
|
1140
|
-
if (code.kind === "no-op") {
|
|
1141
|
-
await assertSafeTree(repositoryRoot, code.baseTree);
|
|
1142
|
-
return code.baseTree;
|
|
1143
|
-
}
|
|
1144
|
-
if (!patchBytes) throw new Error("git-patch candidate is missing verified patch bytes");
|
|
1145
|
-
const temporary = await mkdtemp(join(tmpdir(), "agent-candidate-git-"));
|
|
1146
|
-
try {
|
|
1147
|
-
const indexFile = join(temporary, "index");
|
|
1148
|
-
await runCandidateGit(repositoryRoot, ["read-tree", code.baseTree], void 0, { GIT_INDEX_FILE: indexFile });
|
|
1149
|
-
await runCandidateGit(repositoryRoot, [
|
|
1150
|
-
"apply",
|
|
1151
|
-
"--cached",
|
|
1152
|
-
"--binary",
|
|
1153
|
-
"--whitespace=nowarn",
|
|
1154
|
-
"-"
|
|
1155
|
-
], patchBytes, { GIT_INDEX_FILE: indexFile });
|
|
1156
|
-
const candidateTree = (await runCandidateGit(repositoryRoot, ["write-tree"], void 0, { GIT_INDEX_FILE: indexFile })).stdout.toString("utf8").trim();
|
|
1157
|
-
if (candidateTree !== code.candidateTree) throw new Error(`git patch materialized tree ${candidateTree} does not match ${code.candidateTree}`);
|
|
1158
|
-
await assertSafeTree(repositoryRoot, candidateTree);
|
|
1159
|
-
return candidateTree;
|
|
1160
|
-
} finally {
|
|
1161
|
-
await rm(temporary, {
|
|
1162
|
-
recursive: true,
|
|
1163
|
-
force: true
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
async function readCandidateGitHubResource(resource, repositories) {
|
|
1168
|
-
const repositoryRoot = await verifiedRepositoryRoot(resource.repository, repositories);
|
|
1169
|
-
if ((await runCandidateGit(repositoryRoot, [
|
|
1170
|
-
"cat-file",
|
|
1171
|
-
"-t",
|
|
1172
|
-
resource.commit
|
|
1173
|
-
])).stdout.toString("utf8").trim() !== "commit") throw new Error(`GitHub resource commit is not a commit object: ${resource.commit}`);
|
|
1174
|
-
const listing = (await runCandidateGit(repositoryRoot, [
|
|
1175
|
-
"ls-tree",
|
|
1176
|
-
"-z",
|
|
1177
|
-
resource.commit,
|
|
1178
|
-
"--",
|
|
1179
|
-
resource.path
|
|
1180
|
-
])).stdout;
|
|
1181
|
-
const entries = parseTreeEntries(listing);
|
|
1182
|
-
if (entries.length !== 1 || entries[0]?.path !== resource.path) throw new Error(`GitHub resource path is not one exact file: ${resource.path}`);
|
|
1183
|
-
const entry = entries[0];
|
|
1184
|
-
if (entry?.type !== "blob" || entry.mode !== "100644" && entry.mode !== "100755") throw new Error(`GitHub resource path is not a regular Git blob: ${resource.path}`);
|
|
1185
|
-
const bytes = (await runCandidateGit(repositoryRoot, [
|
|
1186
|
-
"cat-file",
|
|
1187
|
-
"blob",
|
|
1188
|
-
entry.object
|
|
1189
|
-
])).stdout;
|
|
1190
|
-
verifyBytes(bytes, resource.sha256, resource.byteLength, `GitHub resource ${resource.path}`);
|
|
1191
|
-
return Uint8Array.from(bytes);
|
|
1192
|
-
}
|
|
1193
|
-
async function verifyTaskCheckout(taskRoot, expected) {
|
|
1194
|
-
const root = resolve(taskRoot);
|
|
1195
|
-
const head = (await runCandidateGit(root, ["rev-parse", "HEAD"])).stdout.toString("utf8").trim();
|
|
1196
|
-
if (head !== expected.baseCommit) throw new Error(`task checkout HEAD ${head} does not match ${expected.baseCommit}`);
|
|
1197
|
-
const tree = (await runCandidateGit(root, ["rev-parse", "HEAD^{tree}"])).stdout.toString("utf8").trim();
|
|
1198
|
-
if (tree !== expected.baseTree) throw new Error(`task checkout base tree ${tree} does not match ${expected.baseTree}`);
|
|
1199
|
-
}
|
|
1200
|
-
/**
|
|
1201
|
-
* Apply an evaluator-captured binary diff in a detached object database and
|
|
1202
|
-
* prove its result tree exactly matches the captured after-state manifest.
|
|
1203
|
-
*/
|
|
1204
|
-
async function verifyTaskOutcomePatch(input) {
|
|
1205
|
-
const repositoryRoot = resolve(input.repositoryRoot);
|
|
1206
|
-
await verifyTaskCheckout(repositoryRoot, input);
|
|
1207
|
-
const gitDir = resolve((await runCandidateGit(repositoryRoot, ["rev-parse", "--absolute-git-dir"])).stdout.toString("utf8").trim());
|
|
1208
|
-
if (await realpath(gitDir) !== gitDir || gitDir.includes(":")) throw new Error("task Git object store has an unsupported path");
|
|
1209
|
-
await assertNoGitIndirection(repositoryRoot, gitDir, "task repository");
|
|
1210
|
-
const temporary = await mkdtemp(join(tmpdir(), "agent-candidate-task-outcome-"));
|
|
1211
|
-
try {
|
|
1212
|
-
const objectDirectory = join(temporary, "objects");
|
|
1213
|
-
const indexFile = join(temporary, "index");
|
|
1214
|
-
await mkdir(objectDirectory);
|
|
1215
|
-
const gitEnvironment = {
|
|
1216
|
-
GIT_INDEX_FILE: indexFile,
|
|
1217
|
-
GIT_OBJECT_DIRECTORY: objectDirectory,
|
|
1218
|
-
GIT_ALTERNATE_OBJECT_DIRECTORIES: join(gitDir, "objects")
|
|
1219
|
-
};
|
|
1220
|
-
await runCandidateGit(repositoryRoot, ["read-tree", input.baseTree], void 0, gitEnvironment);
|
|
1221
|
-
if (input.patch.byteLength > 0) await runCandidateGit(repositoryRoot, [
|
|
1222
|
-
"apply",
|
|
1223
|
-
"--cached",
|
|
1224
|
-
"--binary",
|
|
1225
|
-
"--whitespace=nowarn",
|
|
1226
|
-
"-"
|
|
1227
|
-
], input.patch, gitEnvironment);
|
|
1228
|
-
const resultTree = (await runCandidateGit(repositoryRoot, ["write-tree"], void 0, gitEnvironment)).stdout.toString("utf8").trim();
|
|
1229
|
-
if (resultTree !== input.resultTree) throw new Error(`task outcome patch materialized tree ${resultTree} does not match ${input.resultTree}`);
|
|
1230
|
-
await assertSafeTree(repositoryRoot, resultTree, gitEnvironment);
|
|
1231
|
-
const observed = await workspaceManifestFromGitTree(repositoryRoot, resultTree, gitEnvironment);
|
|
1232
|
-
if (!Buffer.from(canonicalCandidateBytes$1(observed)).equals(Buffer.from(canonicalCandidateBytes$1(input.afterState)))) throw new Error("task outcome after-state does not match the materialized result tree");
|
|
1233
|
-
const resultCommit = (await runCandidateGit(repositoryRoot, [
|
|
1234
|
-
"commit-tree",
|
|
1235
|
-
resultTree,
|
|
1236
|
-
"-p",
|
|
1237
|
-
input.baseCommit
|
|
1238
|
-
], Buffer.from("candidate task outcome\n", "utf8"), {
|
|
1239
|
-
...gitEnvironment,
|
|
1240
|
-
GIT_AUTHOR_NAME: "Tangle Evaluator",
|
|
1241
|
-
GIT_AUTHOR_EMAIL: "evaluator@tangle.tools",
|
|
1242
|
-
GIT_AUTHOR_DATE: "2000-01-01T00:00:00Z",
|
|
1243
|
-
GIT_COMMITTER_NAME: "Tangle Evaluator",
|
|
1244
|
-
GIT_COMMITTER_EMAIL: "evaluator@tangle.tools",
|
|
1245
|
-
GIT_COMMITTER_DATE: "2000-01-01T00:00:00Z"
|
|
1246
|
-
})).stdout.toString("utf8").trim();
|
|
1247
|
-
if ((await runCandidateGit(repositoryRoot, ["rev-parse", `${resultCommit}^{tree}`], void 0, gitEnvironment)).stdout.toString("utf8").trim() !== resultTree) throw new Error("task outcome evaluator commit does not bind the verified result tree");
|
|
1248
|
-
return {
|
|
1249
|
-
resultTree,
|
|
1250
|
-
resultCommit
|
|
1251
|
-
};
|
|
1252
|
-
} finally {
|
|
1253
|
-
await rm(temporary, {
|
|
1254
|
-
recursive: true,
|
|
1255
|
-
force: true
|
|
1256
|
-
});
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
async function verifiedRepositoryRoot(repository, repositories) {
|
|
1260
|
-
const repositoryRoot = resolve(await repositories.resolve(repository));
|
|
1261
|
-
if (!(await stat(repositoryRoot)).isDirectory()) throw new Error("candidate repository path is not a directory");
|
|
1262
|
-
const origin = (await runCandidateGit(repositoryRoot, [
|
|
1263
|
-
"remote",
|
|
1264
|
-
"get-url",
|
|
1265
|
-
"origin"
|
|
1266
|
-
])).stdout.toString("utf8").trim();
|
|
1267
|
-
const actual = parseGitHubRemote(origin);
|
|
1268
|
-
if (!actual || actual.owner !== repository.owner || actual.repo !== repository.repo) throw new Error(`local repository origin ${origin || "<missing>"} does not match github.com/${repository.owner}/${repository.repo}`);
|
|
1269
|
-
await assertNoGitIndirection(repositoryRoot, resolve((await runCandidateGit(repositoryRoot, ["rev-parse", "--absolute-git-dir"])).stdout.toString("utf8").trim()), "candidate repository");
|
|
1270
|
-
return repositoryRoot;
|
|
1271
|
-
}
|
|
1272
|
-
async function assertNoGitIndirection(repositoryRoot, gitDir, label) {
|
|
1273
|
-
if ((await runCandidateGit(repositoryRoot, [
|
|
1274
|
-
"for-each-ref",
|
|
1275
|
-
"--format=%(refname)",
|
|
1276
|
-
"refs/replace"
|
|
1277
|
-
])).stdout.toString("utf8").trim()) throw new Error(`${label} contains Git replace refs`);
|
|
1278
|
-
const commonDir = await realpath(resolve(repositoryRoot, (await runCandidateGit(repositoryRoot, ["rev-parse", "--git-common-dir"])).stdout.toString("utf8").trim()));
|
|
1279
|
-
if (commonDir.includes(":")) throw new Error(`${label} Git common directory has an unsupported path`);
|
|
1280
|
-
for (const objectRoot of /* @__PURE__ */ new Set([gitDir, commonDir])) for (const name of ["alternates", "http-alternates"]) {
|
|
1281
|
-
const path = join(objectRoot, "objects", "info", name);
|
|
1282
|
-
try {
|
|
1283
|
-
if ((await readFile(path, "utf8")).trim()) throw new Error(`${label} uses forbidden Git ${name}`);
|
|
1284
|
-
} catch (error) {
|
|
1285
|
-
if (!isNoEntry(error)) throw error;
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
async function assertCommitAndBaseTree(repositoryRoot, commit, expectedTree) {
|
|
1290
|
-
if ((await runCandidateGit(repositoryRoot, [
|
|
1291
|
-
"cat-file",
|
|
1292
|
-
"-t",
|
|
1293
|
-
commit
|
|
1294
|
-
])).stdout.toString("utf8").trim() !== "commit") throw new Error(`candidate base object is not a commit: ${commit}`);
|
|
1295
|
-
const actualTree = (await runCandidateGit(repositoryRoot, ["rev-parse", `${commit}^{tree}`])).stdout.toString("utf8").trim();
|
|
1296
|
-
if (actualTree !== expectedTree) throw new Error(`candidate base commit tree ${actualTree} does not match ${expectedTree}`);
|
|
1297
|
-
}
|
|
1298
|
-
async function assertSafeTree(repositoryRoot, tree, environment = {}) {
|
|
1299
|
-
const listing = (await runCandidateGit(repositoryRoot, [
|
|
1300
|
-
"ls-tree",
|
|
1301
|
-
"-rz",
|
|
1302
|
-
"--full-tree",
|
|
1303
|
-
tree
|
|
1304
|
-
], void 0, environment)).stdout;
|
|
1305
|
-
const entries = parseTreeEntries(listing);
|
|
1306
|
-
if (entries.length === 0) throw new Error("candidate Git tree cannot be empty");
|
|
1307
|
-
for (const entry of entries) {
|
|
1308
|
-
if (entry.type !== "blob" || entry.mode !== "100644" && entry.mode !== "100755") throw new Error(`candidate Git tree contains a symlink, submodule, or non-blob: ${entry.path}`);
|
|
1309
|
-
assertSafeGitPath(entry.path);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
async function workspaceManifestFromGitTree(repositoryRoot, tree, environment) {
|
|
1313
|
-
return candidateWorkspaceManifest(await readCandidateGitTreeFiles(repositoryRoot, tree, environment));
|
|
1314
|
-
}
|
|
1315
|
-
async function readCandidateGitTreeFiles(repositoryRoot, tree, environment = {}, limits) {
|
|
1316
|
-
const listing = (await runCandidateGit(repositoryRoot, [
|
|
1317
|
-
"ls-tree",
|
|
1318
|
-
"-rzl",
|
|
1319
|
-
"--full-tree",
|
|
1320
|
-
tree
|
|
1321
|
-
], void 0, environment)).stdout;
|
|
1322
|
-
const files = [];
|
|
1323
|
-
const entries = parseTreeEntries(listing);
|
|
1324
|
-
if (limits && entries.length > limits.maxFiles) throw new Error("candidate Git tree exceeds maxFiles");
|
|
1325
|
-
let totalBytes = 0;
|
|
1326
|
-
for (const entry of entries) {
|
|
1327
|
-
if (entry.type !== "blob" || entry.mode !== "100644" && entry.mode !== "100755") throw new Error(`candidate Git tree contains a non-regular file: ${entry.path}`);
|
|
1328
|
-
assertSafeGitPath(entry.path);
|
|
1329
|
-
if (entry.size === void 0) throw new Error(`candidate Git tree is missing blob size: ${entry.path}`);
|
|
1330
|
-
if (limits && entry.size > limits.maxFileBytes) throw new Error(`candidate Git tree file exceeds maxFileBytes: ${entry.path}`);
|
|
1331
|
-
totalBytes += entry.size;
|
|
1332
|
-
if (limits && totalBytes > limits.maxTotalFileBytes) throw new Error("candidate Git tree exceeds maxTotalFileBytes");
|
|
1333
|
-
const bytes = (await runCandidateGit(repositoryRoot, [
|
|
1334
|
-
"cat-file",
|
|
1335
|
-
"blob",
|
|
1336
|
-
entry.object
|
|
1337
|
-
], void 0, environment)).stdout;
|
|
1338
|
-
if (bytes.byteLength !== entry.size) throw new Error(`candidate Git blob size changed: ${entry.path}`);
|
|
1339
|
-
files.push({
|
|
1340
|
-
path: entry.path,
|
|
1341
|
-
mode: entry.mode === "100755" ? 493 : 420,
|
|
1342
|
-
bytes: Uint8Array.from(bytes)
|
|
1343
|
-
});
|
|
1344
|
-
}
|
|
1345
|
-
return files.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
1346
|
-
}
|
|
1347
|
-
function parseTreeEntries(bytes) {
|
|
1348
|
-
const raw = Buffer.from(bytes);
|
|
1349
|
-
const decoded = raw.toString("utf8");
|
|
1350
|
-
if (!Buffer.from(decoded, "utf8").equals(raw)) throw new Error("candidate Git tree contains a non-UTF-8 path");
|
|
1351
|
-
return decoded.split("\0").filter(Boolean).map((row) => {
|
|
1352
|
-
const tab = row.indexOf(" ");
|
|
1353
|
-
const header = row.slice(0, tab).split(" ").filter(Boolean);
|
|
1354
|
-
const path = row.slice(tab + 1);
|
|
1355
|
-
const [mode, type, object, sizeText] = header;
|
|
1356
|
-
if (tab < 1 || !mode || !type || !object || !path) throw new Error("malformed Git tree entry");
|
|
1357
|
-
const size = sizeText && /^\d+$/.test(sizeText) ? Number(sizeText) : void 0;
|
|
1358
|
-
if (size !== void 0 && !Number.isSafeInteger(size)) throw new Error("candidate Git tree entry size exceeds the safe integer range");
|
|
1359
|
-
return {
|
|
1360
|
-
mode,
|
|
1361
|
-
type,
|
|
1362
|
-
object,
|
|
1363
|
-
...size === void 0 ? {} : { size },
|
|
1364
|
-
path
|
|
1365
|
-
};
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
|
-
function assertSafeGitPath(path) {
|
|
1369
|
-
if (!path || path.startsWith("/") || path.includes("\\") || path.includes("\0") || hasControlCharacter(path) || path.split("/").some((part) => !part || part === "." || part === "..") || path.split("/")[0]?.toLowerCase() === ".git") throw new Error(`candidate Git tree contains an unsafe path: ${path}`);
|
|
1370
|
-
}
|
|
1371
|
-
function hasControlCharacter(value) {
|
|
1372
|
-
for (let index = 0; index < value.length; index++) {
|
|
1373
|
-
const code = value.charCodeAt(index);
|
|
1374
|
-
if (code < 32 || code === 127) return true;
|
|
1375
|
-
}
|
|
1376
|
-
return false;
|
|
1377
|
-
}
|
|
1378
|
-
function parseGitHubRemote(value) {
|
|
1379
|
-
const match = value.match(/^(?:https?:\/\/github\.com\/|ssh:\/\/git@github\.com\/|git@github\.com:)([^/]+)\/([^/]+?)(?:\.git)?$/);
|
|
1380
|
-
if (!match?.[1] || !match[2]) return void 0;
|
|
1381
|
-
return {
|
|
1382
|
-
owner: match[1],
|
|
1383
|
-
repo: match[2]
|
|
1384
|
-
};
|
|
1385
|
-
}
|
|
1386
|
-
async function runCandidateGit(repositoryRoot, args, input, extraEnv = {}) {
|
|
1387
|
-
const env = Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith("GIT_")));
|
|
1388
|
-
Object.assign(env, {
|
|
1389
|
-
GIT_CONFIG_NOSYSTEM: "1",
|
|
1390
|
-
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
1391
|
-
GIT_CONFIG_SYSTEM: "/dev/null",
|
|
1392
|
-
GIT_TERMINAL_PROMPT: "0",
|
|
1393
|
-
GIT_NO_REPLACE_OBJECTS: "1",
|
|
1394
|
-
LC_ALL: "C",
|
|
1395
|
-
...extraEnv
|
|
1396
|
-
});
|
|
1397
|
-
const fullArgs = [
|
|
1398
|
-
"-c",
|
|
1399
|
-
"core.hooksPath=/dev/null",
|
|
1400
|
-
"-c",
|
|
1401
|
-
"core.fsmonitor=false",
|
|
1402
|
-
"-c",
|
|
1403
|
-
"core.untrackedCache=false",
|
|
1404
|
-
"-c",
|
|
1405
|
-
"protocol.file.allow=never",
|
|
1406
|
-
"-C",
|
|
1407
|
-
repositoryRoot,
|
|
1408
|
-
...args
|
|
1409
|
-
];
|
|
1410
|
-
return await new Promise((resolveResult, reject) => {
|
|
1411
|
-
const child = spawn("git", fullArgs, {
|
|
1412
|
-
env,
|
|
1413
|
-
stdio: [
|
|
1414
|
-
"pipe",
|
|
1415
|
-
"pipe",
|
|
1416
|
-
"pipe"
|
|
1417
|
-
]
|
|
1418
|
-
});
|
|
1419
|
-
const stdout = [];
|
|
1420
|
-
const stderr = [];
|
|
1421
|
-
child.stdout.on("data", (chunk) => stdout.push(chunk));
|
|
1422
|
-
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
1423
|
-
child.on("error", reject);
|
|
1424
|
-
child.on("close", (code, signal) => {
|
|
1425
|
-
const out = Buffer.concat(stdout);
|
|
1426
|
-
const err = Buffer.concat(stderr);
|
|
1427
|
-
if (code !== 0) {
|
|
1428
|
-
reject(/* @__PURE__ */ new Error(`git ${args[0] ?? "<command>"} failed (${signal ?? code}): ${err.toString("utf8").trim()}`));
|
|
1429
|
-
return;
|
|
1430
|
-
}
|
|
1431
|
-
resolveResult({
|
|
1432
|
-
stdout: out,
|
|
1433
|
-
stderr: err
|
|
1434
|
-
});
|
|
1435
|
-
});
|
|
1436
|
-
if (input) child.stdin.end(input);
|
|
1437
|
-
else child.stdin.end();
|
|
1438
|
-
});
|
|
1439
|
-
}
|
|
1440
|
-
function isNoEntry(error) {
|
|
1441
|
-
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
1442
|
-
}
|
|
1443
|
-
//#endregion
|
|
1444
874
|
//#region src/candidate-execution/system-prompt.ts
|
|
1445
875
|
const SYSTEM_PROMPT_FILE = ".tangle/system-prompt.md";
|
|
1446
876
|
const APPEND_SYSTEM_PROMPT_FILE = ".tangle/append-system-prompt.md";
|
|
@@ -2603,26 +2033,6 @@ function safeAdd(left, right, label) {
|
|
|
2603
2033
|
return total;
|
|
2604
2034
|
}
|
|
2605
2035
|
//#endregion
|
|
2606
|
-
//#region src/candidate-execution/output-artifacts.ts
|
|
2607
|
-
/** Persist evaluator evidence, read it back, and bind the returned locator to the exact bytes. */
|
|
2608
|
-
async function persistCandidateOutputArtifact(port, input) {
|
|
2609
|
-
input.signal?.throwIfAborted();
|
|
2610
|
-
const bytes = Uint8Array.from(input.bytes);
|
|
2611
|
-
const expectedDigest = sha256Bytes(bytes);
|
|
2612
|
-
const ref = agentCandidateArtifactRefSchema.parse(await port.put({
|
|
2613
|
-
executionId: input.executionId,
|
|
2614
|
-
purpose: input.purpose,
|
|
2615
|
-
bytes: Uint8Array.from(bytes),
|
|
2616
|
-
...input.signal ? { signal: input.signal } : {}
|
|
2617
|
-
}));
|
|
2618
|
-
input.signal?.throwIfAborted();
|
|
2619
|
-
if (ref.sha256 !== expectedDigest || ref.byteLength !== bytes.byteLength) throw new Error("candidate output locator does not identify the submitted bytes");
|
|
2620
|
-
const stored = await port.read(ref);
|
|
2621
|
-
input.signal?.throwIfAborted();
|
|
2622
|
-
verifyBytes(stored, expectedDigest, bytes.byteLength, "persisted candidate output");
|
|
2623
|
-
return immutableCandidateValue(ref);
|
|
2624
|
-
}
|
|
2625
|
-
//#endregion
|
|
2626
2036
|
//#region src/candidate-execution/finalize.ts
|
|
2627
2037
|
/** Builds a candidate run receipt exclusively from protected trace and memory evidence. */
|
|
2628
2038
|
async function finalizeAgentCandidateRun(state, capture, traceStore, traceIdentity, settlement, evidence, protectedValues, writeRedactionReport, signal) {
|
|
@@ -4605,6 +4015,6 @@ function errorMessage(error) {
|
|
|
4605
4015
|
return error instanceof Error ? error.message : String(error);
|
|
4606
4016
|
}
|
|
4607
4017
|
//#endregion
|
|
4608
|
-
export {
|
|
4018
|
+
export { parseAgentCandidateProfileActivation as A, assertRecoveryMatchesStaged as B, applyExactAgentProfileDiff as C, freezeGenericAgentCandidateProfile as D, createAgentCandidateProfileActivation as E, InMemoryAgentCandidateExecutionClaimStore as F, rejectedFinish as G, assertTerminalMatchesClaim as H, candidateClaimFileInternals as I, sealTerminalDigest as J, rejectedStage as K, candidateCleanupDeadline as L, parseExactAgentProfileDiff as M, parseExactCandidateProfile as N, materializeAgentCandidateProfilePlan as O, assertAgentCandidateExecutionRoots as P, candidateCleanupTimeout as R, agentCandidateProfileAsAgentProfile as S, candidateProfileAgentPaths as T, assertTerminalMatchesStaged as U, assertTerminalAllowedInPhase as V, recoveredTerminalRecord as W, terminalRecord as Y, consumePreparedCandidateExecution as _, AGENT_CANDIDATE_EXECUTION_SUPPORT as a, PI_CANDIDATE_AGENT_DIR_ENV as b, executePreparedAgentCandidate as c, sealAgentCandidateModelSettlement as d, usdToNanos as f, beginPreparedCandidateDisposal as g, assertPreparedCandidateIntegrity as h, candidateKnowledgeExecutionPaths as i, parseExactAgentProfile as j, omitUndefinedObjectFields as k, RecoveryAgentCandidateTraceStore as l, candidateExecutionClaim as m, CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV as n, verifiedResourceTextByDigest as o, sealAgentCandidateExecutorStopAcknowledgement as p, requireStagedTerminal as q, CANDIDATE_KNOWLEDGE_ROOT_ENV as r, verifyAgentCandidateBundle as s, prepareAgentCandidateExecution as t, persistCandidateModelSettlementEvidence as u, CANDIDATE_TRACE_ENV as v, assertCandidateProfileBinding as w, PI_CANDIDATE_SESSION_DIR_ENV as x, CANDIDATE_TRACE_TAGS as y, withinCandidateCleanupDeadline as z };
|
|
4609
4019
|
|
|
4610
|
-
//# sourceMappingURL=prepare-
|
|
4020
|
+
//# sourceMappingURL=prepare-RuaAclli.js.map
|