@tangle-network/agent-provider-tangle 4.4.0 → 4.4.2
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 +3 -0
- package/dist/tangle-evidence.js +83 -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 or cache, which it rebuilds on start. */
|
|
131
|
+
contentOmitted?: HarnessContentOmission;
|
|
130
132
|
}>;
|
|
131
133
|
excludedPaths: Array<{
|
|
132
134
|
sourceId?: string;
|
|
@@ -197,4 +199,5 @@ export declare function captureTangleEnvironmentEvidenceToDirectory(environment:
|
|
|
197
199
|
export declare function captureTangleSandboxEvidenceToDirectory(box: SandboxInstanceLike, options: TangleSandboxEvidenceOptions & TangleDirectoryEvidenceOptions): Promise<TangleDirectoryEvidence>;
|
|
198
200
|
/** Export exact Sandbox session and workspace evidence before its owning box is deleted. */
|
|
199
201
|
export declare function captureTangleSandboxEvidence(box: SandboxInstanceLike, options: TangleSandboxEvidenceOptions): Promise<TangleEnvironmentEvidence>;
|
|
202
|
+
type HarnessContentOmission = "harness-install" | "harness-cache";
|
|
200
203
|
export {};
|
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 omitted = entry.kind === "file" ? harnessContentOmission(entry.rootScope, path) : undefined;
|
|
535
|
+
if (entry.kind === "file" && !omitted) {
|
|
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
|
+
...(omitted ? { contentOmitted: omitted } : {}),
|
|
555
561
|
});
|
|
556
562
|
}
|
|
557
563
|
for (const exclusion of native.excluded) {
|
|
@@ -725,9 +731,16 @@ 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) => {
|
|
739
|
+
if (entry.kind !== "file")
|
|
740
|
+
return entry;
|
|
741
|
+
const omitted = harnessContentOmission(entry.rootScope, entry.path);
|
|
742
|
+
return omitted ? { ...withoutNativeContent(entry), contentOmitted: omitted } : withoutNativeContent(entry);
|
|
743
|
+
}),
|
|
731
744
|
processIo: frameMetadata,
|
|
732
745
|
processSources: native.processSources.map(withoutNativeContent),
|
|
733
746
|
};
|
|
@@ -754,7 +767,9 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
754
767
|
throw new Error("Tangle raw session capture status is invalid");
|
|
755
768
|
}
|
|
756
769
|
await writer.writeChunks("__retention__/sessions/" + id + "/raw-manifest.json", 0o600, evidenceJsonChunks({ kind: "tangle-native-session-evidence.v1", source: manifestSource,
|
|
757
|
-
contentEncoding: "base64", contentRefs
|
|
770
|
+
contentEncoding: "base64", contentRefs,
|
|
771
|
+
// An unavailable capture keeps the producer's record unchanged.
|
|
772
|
+
...(manifestSource === native ? {} : { partText: PART_TEXT_ENCODING }) }));
|
|
758
773
|
capturedBytes = writer.byteLength;
|
|
759
774
|
}
|
|
760
775
|
sessions.push({
|
|
@@ -885,6 +900,69 @@ async function downloadWorkspaceEvidenceFile(fs, sourcePath, expectedSize, maxBy
|
|
|
885
900
|
}
|
|
886
901
|
}
|
|
887
902
|
/** Keep every source field; store validated binary content once in the archive. */
|
|
903
|
+
/**
|
|
904
|
+
* A streamed text part arrives as `message.part.updated` carrying the whole text so far plus
|
|
905
|
+
* its `delta`, so retaining every update stores the text once per update. One 117 KB reasoning
|
|
906
|
+
* part over 12,965 updates made an 802 MB transport file and a 637 MB manifest on 2026-10-19
|
|
907
|
+
* (queens21-h22-malloc2-root-2-20261019b), past what a reader can parse. An update whose text is
|
|
908
|
+
* exactly the part's previous text plus its delta keeps the delta and drops the text, marked
|
|
909
|
+
* `textFromDeltas`. Any other update (the first, a replayed duplicate, a reset) keeps its text.
|
|
910
|
+
* To read it: per part id, in file order, a marked update's text is that part's previous text
|
|
911
|
+
* plus its delta; an unmarked update's text is its own.
|
|
912
|
+
*/
|
|
913
|
+
const PART_TEXT_ENCODING = "delta-when-text-equals-previous-plus-delta";
|
|
914
|
+
function withoutRepeatedPartText(data, previous) {
|
|
915
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
916
|
+
return data;
|
|
917
|
+
const record = data;
|
|
918
|
+
const part = record.part;
|
|
919
|
+
if (record.type !== "message.part.updated" || !part || typeof part !== "object" || Array.isArray(part))
|
|
920
|
+
return data;
|
|
921
|
+
const { id, text } = part;
|
|
922
|
+
if (typeof id !== "string" || typeof text !== "string")
|
|
923
|
+
return data;
|
|
924
|
+
const before = previous.get(id);
|
|
925
|
+
previous.set(id, text);
|
|
926
|
+
if (before === undefined || typeof record.delta !== "string" || before + record.delta !== text)
|
|
927
|
+
return data;
|
|
928
|
+
const { text: _text, ...rest } = part;
|
|
929
|
+
return { ...record, part: { ...rest, textFromDeltas: true } };
|
|
930
|
+
}
|
|
931
|
+
function withoutRepeatedFrameText(record, previous) {
|
|
932
|
+
if (!record || typeof record !== "object" || Array.isArray(record))
|
|
933
|
+
return record;
|
|
934
|
+
const frames = record.frames;
|
|
935
|
+
const compact = (frame) => !frame || typeof frame !== "object" || Array.isArray(frame) ? frame
|
|
936
|
+
: { ...frame, data: withoutRepeatedPartText(frame.data, previous) };
|
|
937
|
+
// A directory capture streams its native frames from disk.
|
|
938
|
+
if (frames instanceof EvidenceJsonArray) {
|
|
939
|
+
return {
|
|
940
|
+
...record,
|
|
941
|
+
frames: new EvidenceJsonArray(frames.count, async function* () {
|
|
942
|
+
for await (const frame of frames.entries())
|
|
943
|
+
yield compact(frame);
|
|
944
|
+
}),
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
if (!Array.isArray(frames))
|
|
948
|
+
return record;
|
|
949
|
+
return { ...record, frames: frames.map(compact) };
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Codex caches under its home that it downloads again on start: plugin template assets and
|
|
953
|
+
* the remote plugin and apps catalogs. Session state (`.codex/sessions`, the thread sqlite,
|
|
954
|
+
* config) stays. One canary's capture was 84% these directories (186.8 MB of evidence).
|
|
955
|
+
*/
|
|
956
|
+
const HARNESS_CACHE_DIRECTORIES = [".codex/plugins/cache/", ".codex/cache/remote_plugin_catalog/", ".codex/cache/codex_apps_tools/"];
|
|
957
|
+
/** Why a native file keeps only its metadata, or undefined when its bytes are session state. */
|
|
958
|
+
function harnessContentOmission(rootScope, path) {
|
|
959
|
+
// A harness's installed packages, e.g. `.config/opencode/node_modules`.
|
|
960
|
+
if (path.split("/").includes("node_modules"))
|
|
961
|
+
return "harness-install";
|
|
962
|
+
if (rootScope === "session-home" && HARNESS_CACHE_DIRECTORIES.some((directory) => path.startsWith(directory)))
|
|
963
|
+
return "harness-cache";
|
|
964
|
+
return undefined;
|
|
965
|
+
}
|
|
888
966
|
function withoutNativeContent(source) {
|
|
889
967
|
const metadata = { ...source };
|
|
890
968
|
delete metadata.contentBase64;
|