@tangle-network/agent-provider-tangle 3.5.1 → 3.6.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/tangle-evidence.d.ts +10 -2
- package/dist/tangle-evidence.js +15 -6
- package/dist/tangle-provider.js +45 -4
- package/dist/tangle-types.d.ts +8 -0
- 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
|
@@ -74,6 +74,7 @@ function evidenceContext(environment, options) {
|
|
|
74
74
|
requireNativeSessionCapture: options.requireNativeSessionCapture,
|
|
75
75
|
sandboxSessionIds: [...sessionIds],
|
|
76
76
|
sessionExecutionIds,
|
|
77
|
+
...(options.workspace === undefined ? {} : { workspace: options.workspace }),
|
|
77
78
|
maxBytes: options.maxBytes,
|
|
78
79
|
signal: options.signal,
|
|
79
80
|
} };
|
|
@@ -115,11 +116,19 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
115
116
|
const workspaceRoot = options.workspaceRoot ?? ".";
|
|
116
117
|
if (workspaceRoot !== ".")
|
|
117
118
|
canonicalEntryPath(workspaceRoot);
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
119
|
+
const workspaceScope = options.workspace ?? "environment";
|
|
120
|
+
if (workspaceScope !== "environment" && workspaceScope !== "none")
|
|
121
|
+
throw new Error("Tangle evidence workspace scope is invalid");
|
|
122
|
+
const boxFs = box.fs;
|
|
123
|
+
if (workspaceScope === "environment" && (!boxFs?.list || !boxFs.usage || !boxFs.readBatch)) {
|
|
120
124
|
throw new Error("Tangle evidence requires workspace list, usage, and binary batch read");
|
|
125
|
+
}
|
|
126
|
+
// Only the environment scope reads through it, after the check above.
|
|
127
|
+
const fs = boxFs;
|
|
121
128
|
options.signal?.throwIfAborted();
|
|
122
|
-
const usage =
|
|
129
|
+
const usage = workspaceScope === "none"
|
|
130
|
+
? { complete: true, skippedEntries: 0, sizeBytes: 0, fileCount: 0, directoryCount: 0 }
|
|
131
|
+
: await fs.usage(workspaceRoot);
|
|
123
132
|
if (!usage.complete || usage.skippedEntries !== 0)
|
|
124
133
|
throw new Error("Tangle workspace usage scan is incomplete");
|
|
125
134
|
if (usage.sizeBytes > options.maxBytes)
|
|
@@ -127,7 +136,7 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
127
136
|
const metadata = [];
|
|
128
137
|
const seenPaths = new Set();
|
|
129
138
|
const excludedPaths = [];
|
|
130
|
-
const stack = [workspaceRoot];
|
|
139
|
+
const stack = workspaceScope === "none" ? [] : [workspaceRoot];
|
|
131
140
|
let scannedFiles = 0;
|
|
132
141
|
let scannedDirectories = 0;
|
|
133
142
|
let scannedEntries = 0;
|
|
@@ -716,12 +725,12 @@ async function captureSandboxEvidence(box, options, writer) {
|
|
|
716
725
|
executionId: artifactExecutionId,
|
|
717
726
|
...(controlRef === undefined ? {} : { controlRef }),
|
|
718
727
|
...(captureProof ? { captureProof } : {}),
|
|
719
|
-
workspaceScope
|
|
728
|
+
workspaceScope,
|
|
720
729
|
workspaceRoot,
|
|
721
730
|
capturedAt: new Date().toISOString(),
|
|
722
731
|
entries: metadata.sort((a, b) => a.path.localeCompare(b.path)),
|
|
723
732
|
excludedPaths,
|
|
724
|
-
workspace: { scannedFiles, scannedDirectories, reportedFiles: usage.fileCount, reportedDirectories: usage.directoryCount, complete:
|
|
733
|
+
workspace: { scannedFiles, scannedDirectories, reportedFiles: usage.fileCount, reportedDirectories: usage.directoryCount, complete: workspaceScope === "environment" },
|
|
725
734
|
attempts,
|
|
726
735
|
sessions,
|
|
727
736
|
missing,
|
package/dist/tangle-provider.js
CHANGED
|
@@ -299,22 +299,31 @@ export function createTangleProvider(options) {
|
|
|
299
299
|
operation?.signal?.throwIfAborted();
|
|
300
300
|
if (!box || boundedIdentifier(box.id, "Tangle environment id") !== id)
|
|
301
301
|
return null;
|
|
302
|
-
if (options.requireNativeSessionCapture)
|
|
302
|
+
if (options.requireNativeSessionCapture) {
|
|
303
303
|
requireNativeCaptureProof(box);
|
|
304
|
+
// Native capture admits only the backend the live container reports, so a
|
|
305
|
+
// suspended sandbox must run again before anything can reconnect to it.
|
|
306
|
+
await resumeForReconnect(box, options.client, readyTimeoutMs, operation?.signal);
|
|
307
|
+
}
|
|
304
308
|
let backendType;
|
|
309
|
+
let backendReadError;
|
|
305
310
|
if (box.status === "running" && box.backend) {
|
|
306
311
|
try {
|
|
307
312
|
const status = await awaitWithSignal(box.backend.status(), operation?.signal);
|
|
308
313
|
backendType = boundedIdentifier(status.type, "Tangle current backend");
|
|
309
314
|
}
|
|
310
|
-
catch {
|
|
315
|
+
catch (error) {
|
|
311
316
|
operation?.signal?.throwIfAborted();
|
|
317
|
+
backendReadError = error;
|
|
312
318
|
}
|
|
313
319
|
}
|
|
314
320
|
let captureCapabilities;
|
|
315
321
|
if (options.requireNativeSessionCapture) {
|
|
316
|
-
if (backendType === undefined)
|
|
317
|
-
|
|
322
|
+
if (backendType === undefined) {
|
|
323
|
+
// The read's own failure (a 429 or 503 while the platform suspends the box)
|
|
324
|
+
// stays the cause, so a caller classifies it as the transport fault it is.
|
|
325
|
+
throw new Error("Tangle native capture requires the current selected backend before reconnect", backendReadError === undefined ? undefined : { cause: backendReadError });
|
|
326
|
+
}
|
|
318
327
|
captureCapabilities = await awaitWithSignal(requireNativeCaptureCapability(box, backendType), operation?.signal);
|
|
319
328
|
}
|
|
320
329
|
const declaredCapabilities = await resolveDeclaredCapabilities(backendType);
|
|
@@ -400,6 +409,38 @@ export function createTangleProvider(options) {
|
|
|
400
409
|
: {}),
|
|
401
410
|
};
|
|
402
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* Bring a suspended sandbox back before a reconnect reads its container.
|
|
414
|
+
*
|
|
415
|
+
* The platform suspends a sandbox after its idle timeout (30 minutes by
|
|
416
|
+
* default) and nothing resumes it on access. A root turn stalled on an
|
|
417
|
+
* upstream 429 for that long comes back to a stopped box; without a resume,
|
|
418
|
+
* every later reconnect finds no live backend and refuses identically until
|
|
419
|
+
* the driver exhausts its attempts. After the resume the sidecar reports the
|
|
420
|
+
* interrupted execution as a terminal failure, so the caller settles that
|
|
421
|
+
* execution and replaces it once instead of dispatching beside it.
|
|
422
|
+
*/
|
|
423
|
+
async function resumeForReconnect(box, client, timeoutMs, signal) {
|
|
424
|
+
if (box.status === "running")
|
|
425
|
+
return;
|
|
426
|
+
if (box.status === "stopped") {
|
|
427
|
+
if (!box.resume) {
|
|
428
|
+
throw new Error(`Tangle sandbox ${box.id} is stopped and the linked client cannot resume it`);
|
|
429
|
+
}
|
|
430
|
+
try {
|
|
431
|
+
await awaitWithSignal(box.resume({ timeoutMs, ...(signal ? { signal } : {}) }), signal);
|
|
432
|
+
}
|
|
433
|
+
catch (error) {
|
|
434
|
+
signal?.throwIfAborted();
|
|
435
|
+
// Another reconnect may have resumed the same box first; its state decides.
|
|
436
|
+
await box.refresh?.(signal).catch(() => undefined);
|
|
437
|
+
const after = statusFromUnknown(box.status);
|
|
438
|
+
if (after !== "running" && after !== "pending" && after !== "provisioning")
|
|
439
|
+
throw error;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
await awaitSandboxRunning(box, client, { timeoutMs, ...(signal ? { signal } : {}) });
|
|
443
|
+
}
|
|
403
444
|
async function resolveBackend(client, backendType) {
|
|
404
445
|
if (backendType === undefined)
|
|
405
446
|
return undefined;
|
package/dist/tangle-types.d.ts
CHANGED
|
@@ -537,6 +537,14 @@ export interface SandboxInstanceLike {
|
|
|
537
537
|
signal?: AbortSignal;
|
|
538
538
|
}): Promise<void>;
|
|
539
539
|
refresh?(signal?: AbortSignal): Promise<void>;
|
|
540
|
+
/**
|
|
541
|
+
* Resume a stopped sandbox. An idle or lifetime suspend stops the container
|
|
542
|
+
* and preserves the workspace; nothing resumes it on access.
|
|
543
|
+
*/
|
|
544
|
+
resume?(options?: {
|
|
545
|
+
timeoutMs?: number;
|
|
546
|
+
signal?: AbortSignal;
|
|
547
|
+
}): Promise<void>;
|
|
540
548
|
delete?(options?: {
|
|
541
549
|
signal?: AbortSignal;
|
|
542
550
|
}): Promise<unknown>;
|