@tangle-network/agent-provider-tangle 3.5.2 → 3.6.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 +10 -2
- package/dist/tangle-evidence.js +64 -7
- package/package.json +1 -1
|
@@ -25,6 +25,13 @@ export interface TangleEnvironmentEvidenceOptions {
|
|
|
25
25
|
requireNativeSessionCapture?: boolean;
|
|
26
26
|
/** Exact Sandbox session id when execution was reattached after provider restart. */
|
|
27
27
|
sandboxSessionId?: string | null;
|
|
28
|
+
/**
|
|
29
|
+
* `none` exports the attributed sessions' native evidence without walking the workspace. A
|
|
30
|
+
* caller uses it to copy a harness session while its turn is still running, or when the
|
|
31
|
+
* workspace is over the byte bound, so neither the workspace's size nor its scan can lose the
|
|
32
|
+
* session. Defaults to `environment`, which captures both.
|
|
33
|
+
*/
|
|
34
|
+
workspace?: "environment" | "none";
|
|
28
35
|
maxBytes: number;
|
|
29
36
|
signal?: AbortSignal;
|
|
30
37
|
}
|
|
@@ -49,19 +56,20 @@ export interface TangleEnvironmentEvidence {
|
|
|
49
56
|
executionId: string;
|
|
50
57
|
controlRef?: AgentExactRunControlRef;
|
|
51
58
|
captureProof?: NativeCaptureProofLike;
|
|
52
|
-
workspaceScope: "environment";
|
|
59
|
+
workspaceScope: "environment" | "none";
|
|
53
60
|
workspaceRoot: string;
|
|
54
61
|
capturedAt: string;
|
|
55
62
|
entries: WorkspaceEntryMetadata[];
|
|
56
63
|
excludedPaths: Array<WorkspaceEntryMetadata & {
|
|
57
64
|
reason: "credential-path" | "symlink" | "runtime-owned";
|
|
58
65
|
}>;
|
|
66
|
+
/** `complete` is false only when `workspaceScope` is `none`: no workspace was scanned. */
|
|
59
67
|
workspace: {
|
|
60
68
|
scannedFiles: number;
|
|
61
69
|
scannedDirectories: number;
|
|
62
70
|
reportedFiles: number;
|
|
63
71
|
reportedDirectories: number;
|
|
64
|
-
complete:
|
|
72
|
+
complete: boolean;
|
|
65
73
|
};
|
|
66
74
|
attempts: TangleEvidenceAttemptLike[];
|
|
67
75
|
sessions: Array<{
|
package/dist/tangle-evidence.js
CHANGED
|
@@ -9,6 +9,54 @@ const handles = new WeakMap();
|
|
|
9
9
|
const blockedNames = new Set([".ssh", ".config", ".claude", ".codex", ".opencode", ".env", ".env.local", ".npmrc", ".sidecar"]);
|
|
10
10
|
const MAX_ENTRIES = 100_000;
|
|
11
11
|
const MAX_EVENTS = 100_000;
|
|
12
|
+
// How long a replay may go without its start marker once the stream is open. The Sidecar sends
|
|
13
|
+
// no replay markers when an execution has buffered nothing yet, so this bounds that case.
|
|
14
|
+
const REPLAY_START_GRACE_MS = 15_000;
|
|
15
|
+
/**
|
|
16
|
+
* The execution's events as the Sidecar had buffered them when this capture started.
|
|
17
|
+
*
|
|
18
|
+
* The Sidecar answers a cursor replay with its buffer between `history.replay.start` and
|
|
19
|
+
* `history.replay.end`, then follows the live turn, and the SDK returns only on the turn's `done`
|
|
20
|
+
* or `error`. Read to the end, a capture of a running turn waited for the turn to finish: in the
|
|
21
|
+
* 2026-10-04 trace proof every 2-minute copy blocked until its turn ended or the Lab's 180 s bound
|
|
22
|
+
* aborted it, and 6.2 minutes of live turns stored no copy at all. A settled execution's buffer
|
|
23
|
+
* already ends with its `done` or `error`, so it replays as before.
|
|
24
|
+
*/
|
|
25
|
+
async function* bufferedExecutionEvents(session, executionId, signal) {
|
|
26
|
+
const replay = new AbortController();
|
|
27
|
+
const forward = () => replay.abort(signal?.reason);
|
|
28
|
+
if (signal?.aborted)
|
|
29
|
+
forward();
|
|
30
|
+
else
|
|
31
|
+
signal?.addEventListener("abort", forward, { once: true });
|
|
32
|
+
let grace;
|
|
33
|
+
let empty = false;
|
|
34
|
+
try {
|
|
35
|
+
for await (const event of session.events({ since: "0", executionId, signal: replay.signal })) {
|
|
36
|
+
if (event.type === "connection.established" && grace === undefined) {
|
|
37
|
+
grace = setTimeout(() => {
|
|
38
|
+
empty = true;
|
|
39
|
+
replay.abort(new DOMException("Tangle replay buffer is empty", "AbortError"));
|
|
40
|
+
}, REPLAY_START_GRACE_MS);
|
|
41
|
+
grace.unref?.();
|
|
42
|
+
}
|
|
43
|
+
if (event.type === "history.replay.start")
|
|
44
|
+
clearTimeout(grace);
|
|
45
|
+
yield event;
|
|
46
|
+
if (event.type === "history.replay.end")
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (!empty || signal?.aborted)
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
clearTimeout(grace);
|
|
56
|
+
signal?.removeEventListener("abort", forward);
|
|
57
|
+
}
|
|
58
|
+
signal?.throwIfAborted();
|
|
59
|
+
}
|
|
12
60
|
// Match the Sidecar request limit without accumulating 100 large JSON payloads.
|
|
13
61
|
const WORKSPACE_BATCH_FILES = 100;
|
|
14
62
|
const WORKSPACE_BATCH_BYTES = 8 * 1024 * 1024;
|
|
@@ -74,6 +122,7 @@ function evidenceContext(environment, options) {
|
|
|
74
122
|
requireNativeSessionCapture: options.requireNativeSessionCapture,
|
|
75
123
|
sandboxSessionIds: [...sessionIds],
|
|
76
124
|
sessionExecutionIds,
|
|
125
|
+
...(options.workspace === undefined ? {} : { workspace: options.workspace }),
|
|
77
126
|
maxBytes: options.maxBytes,
|
|
78
127
|
signal: options.signal,
|
|
79
128
|
} };
|
|
@@ -115,11 +164,19 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
115
164
|
const workspaceRoot = options.workspaceRoot ?? ".";
|
|
116
165
|
if (workspaceRoot !== ".")
|
|
117
166
|
canonicalEntryPath(workspaceRoot);
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
167
|
+
const workspaceScope = options.workspace ?? "environment";
|
|
168
|
+
if (workspaceScope !== "environment" && workspaceScope !== "none")
|
|
169
|
+
throw new Error("Tangle evidence workspace scope is invalid");
|
|
170
|
+
const boxFs = box.fs;
|
|
171
|
+
if (workspaceScope === "environment" && (!boxFs?.list || !boxFs.usage || !boxFs.readBatch)) {
|
|
120
172
|
throw new Error("Tangle evidence requires workspace list, usage, and binary batch read");
|
|
173
|
+
}
|
|
174
|
+
// Only the environment scope reads through it, after the check above.
|
|
175
|
+
const fs = boxFs;
|
|
121
176
|
options.signal?.throwIfAborted();
|
|
122
|
-
const usage =
|
|
177
|
+
const usage = workspaceScope === "none"
|
|
178
|
+
? { complete: true, skippedEntries: 0, sizeBytes: 0, fileCount: 0, directoryCount: 0 }
|
|
179
|
+
: await fs.usage(workspaceRoot);
|
|
123
180
|
if (!usage.complete || usage.skippedEntries !== 0)
|
|
124
181
|
throw new Error("Tangle workspace usage scan is incomplete");
|
|
125
182
|
if (usage.sizeBytes > options.maxBytes)
|
|
@@ -127,7 +184,7 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
127
184
|
const metadata = [];
|
|
128
185
|
const seenPaths = new Set();
|
|
129
186
|
const excludedPaths = [];
|
|
130
|
-
const stack = [workspaceRoot];
|
|
187
|
+
const stack = workspaceScope === "none" ? [] : [workspaceRoot];
|
|
131
188
|
let scannedFiles = 0;
|
|
132
189
|
let scannedDirectories = 0;
|
|
133
190
|
let scannedEntries = 0;
|
|
@@ -286,7 +343,7 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
286
343
|
const events = new EvidenceJsonArray(undefined, async function* () {
|
|
287
344
|
for (const executionId of executionIds) {
|
|
288
345
|
eventCountsByExecutionId[executionId] = 0;
|
|
289
|
-
for await (const event of session
|
|
346
|
+
for await (const event of bufferedExecutionEvents(session, executionId, options.signal)) {
|
|
290
347
|
options.signal?.throwIfAborted();
|
|
291
348
|
if (counts.events >= MAX_EVENTS)
|
|
292
349
|
throw new Error("Tangle event replay limit exceeded");
|
|
@@ -716,12 +773,12 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
716
773
|
executionId: artifactExecutionId,
|
|
717
774
|
...(controlRef === undefined ? {} : { controlRef }),
|
|
718
775
|
...(captureProof ? { captureProof } : {}),
|
|
719
|
-
workspaceScope
|
|
776
|
+
workspaceScope,
|
|
720
777
|
workspaceRoot,
|
|
721
778
|
capturedAt: new Date().toISOString(),
|
|
722
779
|
entries: metadata.sort((a, b) => a.path.localeCompare(b.path)),
|
|
723
780
|
excludedPaths,
|
|
724
|
-
workspace: { scannedFiles, scannedDirectories, reportedFiles: usage.fileCount, reportedDirectories: usage.directoryCount, complete:
|
|
781
|
+
workspace: { scannedFiles, scannedDirectories, reportedFiles: usage.fileCount, reportedDirectories: usage.directoryCount, complete: workspaceScope === "environment" },
|
|
725
782
|
attempts,
|
|
726
783
|
sessions,
|
|
727
784
|
missing,
|