@tangle-network/agent-provider-tangle 4.4.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tangle-evidence.d.ts +2 -0
- package/dist/tangle-evidence.js +70 -5
- package/package.json +1 -1
|
@@ -127,6 +127,8 @@ export interface TangleEnvironmentEvidence {
|
|
|
127
127
|
sizeBytes: number;
|
|
128
128
|
sha256: string | null;
|
|
129
129
|
linkTarget: string | null;
|
|
130
|
+
/** Metadata only: the bytes are a harness's own install, not session state. */
|
|
131
|
+
contentOmitted?: "harness-install";
|
|
130
132
|
}>;
|
|
131
133
|
excludedPaths: Array<{
|
|
132
134
|
sourceId?: string;
|
package/dist/tangle-evidence.js
CHANGED
|
@@ -352,6 +352,7 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
352
352
|
}
|
|
353
353
|
const counts = { events: 0, messages: 0 };
|
|
354
354
|
const eventCountsByExecutionId = {};
|
|
355
|
+
const transportPartText = new Map();
|
|
355
356
|
const events = new EvidenceJsonArray(undefined, async function* () {
|
|
356
357
|
for (const executionId of executionIds) {
|
|
357
358
|
eventCountsByExecutionId[executionId] = 0;
|
|
@@ -367,7 +368,7 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
367
368
|
}
|
|
368
369
|
counts.events++;
|
|
369
370
|
eventCountsByExecutionId[executionId] += 1;
|
|
370
|
-
yield { executionId, event };
|
|
371
|
+
yield { executionId, event: { ...event, data: withoutRepeatedPartText(event.data, transportPartText) } };
|
|
371
372
|
}
|
|
372
373
|
}
|
|
373
374
|
});
|
|
@@ -389,7 +390,7 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
389
390
|
}
|
|
390
391
|
});
|
|
391
392
|
await writer.writeChunks(`__retention__/sessions/${id}.json`, 0o600, evidenceJsonChunks({ kind: "tangle-session-transport.v1", environmentId: box.id, sessionId: id,
|
|
392
|
-
executionIds, status, events, messages, messageScope: "session" }));
|
|
393
|
+
executionIds, status, events, messages, messageScope: "session", partText: PART_TEXT_ENCODING }));
|
|
393
394
|
capturedBytes = writer.byteLength;
|
|
394
395
|
let nativeSessionId = null;
|
|
395
396
|
let sidecarImageDigest = null;
|
|
@@ -530,13 +531,17 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
530
531
|
nativePaths.add(identity);
|
|
531
532
|
if (!nativeStatMetadata(entry))
|
|
532
533
|
throw new Error("Tangle raw session entry metadata is invalid");
|
|
533
|
-
|
|
534
|
+
const harnessInstall = entry.kind === "file" && harnessInstallPath(path);
|
|
535
|
+
if (entry.kind === "file" && !harnessInstall) {
|
|
534
536
|
const contentPath = "__retention__/sessions/" + id + "/native/" +
|
|
535
537
|
(entry.sourceId === undefined ? "" : entry.sourceId + "/") + entry.rootScope + "/" + path;
|
|
536
538
|
await retainNativeContent(entry, contentPath, entry.mode & 0o777);
|
|
537
539
|
contentRefs.push({ jsonPointer: `/files/${index}/contentBase64`, path: contentPath });
|
|
538
540
|
capturedBytes = writer.byteLength;
|
|
539
541
|
}
|
|
542
|
+
else if (entry.kind === "file") {
|
|
543
|
+
// The entry, its size and its digest stay in the inventory below.
|
|
544
|
+
}
|
|
540
545
|
else if (entry.kind === "directory" || entry.kind === "symlink") {
|
|
541
546
|
if (entry.contentBase64 !== undefined || entry.sha256 !== undefined ||
|
|
542
547
|
(entry.kind === "symlink" && (typeof entry.linkTarget !== "string" || entry.linkTarget.includes("\0")))) {
|
|
@@ -552,6 +557,7 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
552
557
|
rootScope: entry.rootScope, path, kind: entry.kind, mode: entry.mode,
|
|
553
558
|
uid: entry.uid, gid: entry.gid, mtimeMs: entry.mtimeMs, ctimeMs: entry.ctimeMs,
|
|
554
559
|
sizeBytes: entry.sizeBytes, sha256: entry.sha256 ?? null, linkTarget: entry.linkTarget ?? null,
|
|
560
|
+
...(harnessInstall ? { contentOmitted: "harness-install" } : {}),
|
|
555
561
|
});
|
|
556
562
|
}
|
|
557
563
|
for (const exclusion of native.excluded) {
|
|
@@ -725,9 +731,14 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
725
731
|
for (const sourceId of missingSpoolSources) {
|
|
726
732
|
missing.push(`Sandbox session ${id} has no original process source: ${sourceId}`);
|
|
727
733
|
}
|
|
734
|
+
const nativePartText = new Map();
|
|
728
735
|
manifestSource = {
|
|
729
736
|
...native,
|
|
730
|
-
|
|
737
|
+
events: native.events.map((record) => withoutRepeatedFrameText(record, nativePartText)),
|
|
738
|
+
files: native.files.map((entry) => entry.kind !== "file" ? entry
|
|
739
|
+
: harnessInstallPath(entry.path)
|
|
740
|
+
? { ...withoutNativeContent(entry), contentOmitted: "harness-install" }
|
|
741
|
+
: withoutNativeContent(entry)),
|
|
731
742
|
processIo: frameMetadata,
|
|
732
743
|
processSources: native.processSources.map(withoutNativeContent),
|
|
733
744
|
};
|
|
@@ -754,7 +765,9 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
754
765
|
throw new Error("Tangle raw session capture status is invalid");
|
|
755
766
|
}
|
|
756
767
|
await writer.writeChunks("__retention__/sessions/" + id + "/raw-manifest.json", 0o600, evidenceJsonChunks({ kind: "tangle-native-session-evidence.v1", source: manifestSource,
|
|
757
|
-
contentEncoding: "base64", contentRefs
|
|
768
|
+
contentEncoding: "base64", contentRefs,
|
|
769
|
+
// An unavailable capture keeps the producer's record unchanged.
|
|
770
|
+
...(manifestSource === native ? {} : { partText: PART_TEXT_ENCODING }) }));
|
|
758
771
|
capturedBytes = writer.byteLength;
|
|
759
772
|
}
|
|
760
773
|
sessions.push({
|
|
@@ -885,6 +898,58 @@ async function downloadWorkspaceEvidenceFile(fs, sourcePath, expectedSize, maxBy
|
|
|
885
898
|
}
|
|
886
899
|
}
|
|
887
900
|
/** Keep every source field; store validated binary content once in the archive. */
|
|
901
|
+
/**
|
|
902
|
+
* A streamed text part arrives as `message.part.updated` carrying the whole text so far plus
|
|
903
|
+
* its `delta`, so retaining every update stores the text once per update. One 117 KB reasoning
|
|
904
|
+
* part over 12,965 updates made an 802 MB transport file and a 637 MB manifest on 2026-10-19
|
|
905
|
+
* (queens21-h22-malloc2-root-2-20261019b), past what a reader can parse. An update whose text is
|
|
906
|
+
* exactly the part's previous text plus its delta keeps the delta and drops the text, marked
|
|
907
|
+
* `textFromDeltas`. Any other update (the first, a replayed duplicate, a reset) keeps its text.
|
|
908
|
+
* To read it: per part id, in file order, a marked update's text is that part's previous text
|
|
909
|
+
* plus its delta; an unmarked update's text is its own.
|
|
910
|
+
*/
|
|
911
|
+
const PART_TEXT_ENCODING = "delta-when-text-equals-previous-plus-delta";
|
|
912
|
+
function withoutRepeatedPartText(data, previous) {
|
|
913
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
914
|
+
return data;
|
|
915
|
+
const record = data;
|
|
916
|
+
const part = record.part;
|
|
917
|
+
if (record.type !== "message.part.updated" || !part || typeof part !== "object" || Array.isArray(part))
|
|
918
|
+
return data;
|
|
919
|
+
const { id, text } = part;
|
|
920
|
+
if (typeof id !== "string" || typeof text !== "string")
|
|
921
|
+
return data;
|
|
922
|
+
const before = previous.get(id);
|
|
923
|
+
previous.set(id, text);
|
|
924
|
+
if (before === undefined || typeof record.delta !== "string" || before + record.delta !== text)
|
|
925
|
+
return data;
|
|
926
|
+
const { text: _text, ...rest } = part;
|
|
927
|
+
return { ...record, part: { ...rest, textFromDeltas: true } };
|
|
928
|
+
}
|
|
929
|
+
function withoutRepeatedFrameText(record, previous) {
|
|
930
|
+
if (!record || typeof record !== "object" || Array.isArray(record))
|
|
931
|
+
return record;
|
|
932
|
+
const frames = record.frames;
|
|
933
|
+
const compact = (frame) => !frame || typeof frame !== "object" || Array.isArray(frame) ? frame
|
|
934
|
+
: { ...frame, data: withoutRepeatedPartText(frame.data, previous) };
|
|
935
|
+
// A directory capture streams its native frames from disk.
|
|
936
|
+
if (frames instanceof EvidenceJsonArray) {
|
|
937
|
+
return {
|
|
938
|
+
...record,
|
|
939
|
+
frames: new EvidenceJsonArray(frames.count, async function* () {
|
|
940
|
+
for await (const frame of frames.entries())
|
|
941
|
+
yield compact(frame);
|
|
942
|
+
}),
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
if (!Array.isArray(frames))
|
|
946
|
+
return record;
|
|
947
|
+
return { ...record, frames: frames.map(compact) };
|
|
948
|
+
}
|
|
949
|
+
/** A harness's installed packages under its home, e.g. `.config/opencode/node_modules`. */
|
|
950
|
+
function harnessInstallPath(path) {
|
|
951
|
+
return path.split("/").includes("node_modules");
|
|
952
|
+
}
|
|
888
953
|
function withoutNativeContent(source) {
|
|
889
954
|
const metadata = { ...source };
|
|
890
955
|
delete metadata.contentBase64;
|