@tangle-network/agent-provider-tangle 1.9.2 → 3.0.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.
@@ -33,21 +33,23 @@ export function nativeCaptureHarnesses(raw) {
33
33
  }
34
34
  return Object.freeze(parsed.data);
35
35
  }
36
- /** Refuse an unsupported deployment before creating a billable sandbox.
37
- * Unprofiled exact-process and checkpoint restores retain the stricter universal guarantee. */
38
- export async function requireNativeCaptureCapability(client, harness) {
39
- if (!client.evidenceCapabilities) {
40
- throw new Error("Tangle deployment has not proven native session capture for next-create placement");
36
+ /** Require the selected container's native protocol and exact agent backend before dispatch. */
37
+ export async function requireNativeCaptureCapability(box, harness) {
38
+ requireNativeCaptureProof(box);
39
+ if (!box.capabilities) {
40
+ throw new Error("Tangle selected container has no native capture capability document");
41
41
  }
42
- const document = await client.evidenceCapabilities();
43
- if (harness === undefined) {
44
- if (document.nativeSessionCaptureV1 !== true) {
45
- throw new Error("Tangle deployment has not proven native session capture for unprofiled next-create placement");
46
- }
47
- return;
42
+ const document = await box.capabilities();
43
+ if (document?.schema !== 1 || document.nativeSessionCaptureVersion !== 2) {
44
+ throw new Error("Tangle selected container has not proven native session capture protocol 2");
48
45
  }
46
+ assertNativeCaptureHarness(document, harness);
47
+ return document;
48
+ }
49
+ /** Validate each newly dispatched backend against this container's measured document. */
50
+ export function assertNativeCaptureHarness(document, harness) {
49
51
  const selected = harnessTypeSchema.safeParse(harness);
50
52
  if (!selected.success || !nativeCaptureHarnesses(document.nativeSessionCaptureHarnesses).includes(selected.data)) {
51
- throw new Error(`Tangle deployment has not proven native session capture for harness ${JSON.stringify(harness)}`);
53
+ throw new Error(`Tangle selected container has not proven native session capture for harness ${JSON.stringify(harness)}`);
52
54
  }
53
55
  }
@@ -113,14 +113,14 @@ export function createTangleProvider(options) {
113
113
  }
114
114
  }
115
115
  input.signal?.throwIfAborted();
116
+ const captureHarness = options.requireNativeSessionCapture ? createOptions.backend?.type : undefined;
116
117
  if (options.requireNativeSessionCapture) {
117
- if (createOptions.backend?.type === undefined) {
118
+ if (captureHarness === undefined) {
118
119
  throw new Error("Tangle complete native session capture requires an explicit selected backend before create");
119
120
  }
120
- if (typeof input.profile !== "string" && input.profile.harness !== undefined && input.profile.harness !== createOptions.backend.type) {
121
+ if (typeof input.profile !== "string" && input.profile.harness !== undefined && input.profile.harness !== captureHarness) {
121
122
  throw new Error("Tangle native capture selected backend differs from the exact profile harness");
122
123
  }
123
- await requireNativeCaptureCapability(options.client, createOptions.backend.type);
124
124
  }
125
125
  const createPromise = options.client.create(createOptions, input.signal ? { signal: input.signal } : undefined);
126
126
  let box;
@@ -131,7 +131,7 @@ export function createTangleProvider(options) {
131
131
  if (input.signal?.aborted) {
132
132
  void createPromise
133
133
  .then(async (lateBox) => {
134
- if (!lateBox.delete) {
134
+ if (lateBox.createReceipt?.()?.outcome !== "created" || !lateBox.delete) {
135
135
  attachCleanupHandle(error, lateBox);
136
136
  return;
137
137
  }
@@ -160,17 +160,26 @@ export function createTangleProvider(options) {
160
160
  input.signal?.throwIfAborted();
161
161
  if (options.requireNativeSessionCapture)
162
162
  requireNativeCaptureProof(box, true);
163
+ const captureCapabilities = captureHarness === undefined ? undefined
164
+ : await awaitWithSignal(requireNativeCaptureCapability(box, captureHarness), input.signal);
163
165
  const requestedResources = requestedResourceProfile(input.resources);
164
166
  const environment = await sandboxInstanceAsEnvironment(box, providerName, options.client, declaredCapabilities, input.signal ? { signal: input.signal } : undefined, {
165
167
  ...(requestedResources === undefined
166
168
  ? {}
167
169
  : { resources: requestedResources }),
170
+ ...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
171
+ ...(captureCapabilities === undefined ? {} : { captureCapabilities }),
172
+ ...(captureHarness === undefined ? {} : { captureHarness }),
168
173
  ...confidentialVerifierOption(options.confidentialAttestationVerifier),
169
174
  });
170
175
  input.signal?.throwIfAborted();
171
176
  return environment;
172
177
  }
173
178
  catch (error) {
179
+ if (box.createReceipt?.()?.outcome !== "created") {
180
+ attachCleanupHandle(error, box);
181
+ throw error;
182
+ }
174
183
  if (!box.delete) {
175
184
  const baseError = error instanceof Error ? error : new Error(String(error));
176
185
  throw Object.assign(baseError, { cleanupHandle: box });
@@ -256,8 +265,19 @@ export function createTangleProvider(options) {
256
265
  operation?.signal?.throwIfAborted();
257
266
  }
258
267
  }
268
+ let captureCapabilities;
269
+ if (options.requireNativeSessionCapture) {
270
+ if (backendType === undefined)
271
+ throw new Error("Tangle native capture requires the current selected backend before reconnect");
272
+ captureCapabilities = await awaitWithSignal(requireNativeCaptureCapability(box, backendType), operation?.signal);
273
+ }
259
274
  const declaredCapabilities = await resolveDeclaredCapabilities(backendType);
260
- return await sandboxInstanceAsEnvironment(box, providerName, options.client, declaredCapabilities, operation?.signal ? { signal: operation.signal } : undefined, confidentialVerifierOption(options.confidentialAttestationVerifier));
275
+ return await sandboxInstanceAsEnvironment(box, providerName, options.client, declaredCapabilities, operation?.signal ? { signal: operation.signal } : undefined, {
276
+ ...confidentialVerifierOption(options.confidentialAttestationVerifier),
277
+ ...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
278
+ ...(captureCapabilities === undefined ? {} : { captureCapabilities }),
279
+ ...(backendType === undefined ? {} : { captureHarness: backendType }),
280
+ });
261
281
  },
262
282
  }
263
283
  : {}),
@@ -1,5 +1,5 @@
1
1
  import type { BackendRegistryEntry, BackendRegistryResponse, BackendType, CreateSandboxOptions, ExecResult as SandboxExecResult, PromptOptions, PromptResult, SandboxEvent } from "@tangle-network/sandbox";
2
- import type { AgentRunCancellationAcknowledgement, AgentRunCancellationRequest, AgentInteractiveSessionControlClaim, AgentInteractiveSessionControlClaimAcknowledgement, AgentInteractiveSessionControlClaimRequest, AgentInteractiveSessionAttach, AgentInteractiveSessionPromptAcknowledgement, AgentInteractiveSessionPromptCommand, AgentInteractiveSessionRef, AgentInteractiveSessionStart, AgentInteractiveSessionStatus, AgentInteractiveSessionStopAcknowledgement, AgentInteractiveSessionStopCommand, AgentInteractiveTerminalSession, ConfidentialAttestation, ConfidentialExecutionEnvironment, HarnessType, InputPart, InteractionRequest, InteractionResponseCommand } from "@tangle-network/agent-interface";
2
+ import type { AgentRunCancellationAcknowledgement, AgentRunCancellationRequest, AgentInteractiveSessionControlClaim, AgentInteractiveSessionControlClaimAcknowledgement, AgentInteractiveSessionControlClaimRequest, AgentInteractiveSessionAttach, AgentInteractiveSessionPromptAcknowledgement, AgentInteractiveSessionPromptCommand, AgentInteractiveSessionRef, AgentInteractiveSessionStart, AgentInteractiveSessionStatus, AgentInteractiveSessionStopAcknowledgement, AgentInteractiveSessionStopCommand, AgentInteractiveTerminalSession, ConfidentialAttestation, ConfidentialExecutionEnvironment, InputPart, InteractionRequest, InteractionResponseCommand } from "@tangle-network/agent-interface";
3
3
  import type { AgentEnvironmentCapabilities, AgentEnvironmentProvider, CreateAgentEnvironmentInput } from "@tangle-network/agent-interface/environment-provider";
4
4
  /**
5
5
  * The platform verdict for the create call that returned a sandbox.
@@ -23,13 +23,6 @@ export interface TangleExactProcessOptions {
23
23
  teamId?: string;
24
24
  }
25
25
  export interface SandboxClientLike {
26
- /** Deployment-scoped evidence guarantees for a new sandbox on this client. */
27
- evidenceCapabilities?(): Promise<{
28
- nativeSessionCaptureV1?: boolean;
29
- nativeSessionCaptureHarnesses?: readonly HarnessType[];
30
- workspaceCaptureV1?: boolean;
31
- sidecarImageDigest?: string;
32
- }>;
33
26
  create(options?: CreateSandboxOptions, requestOptions?: {
34
27
  signal?: AbortSignal;
35
28
  timeoutMs?: number;
@@ -108,6 +101,8 @@ export interface SandboxSubscriptionLike {
108
101
  */
109
102
  export interface SandboxRuntimeCapabilityDocument {
110
103
  schema?: number;
104
+ nativeSessionCaptureVersion?: number;
105
+ nativeSessionCaptureHarnesses?: readonly string[];
111
106
  agentInterface?: string;
112
107
  sidecarVersion?: string;
113
108
  image?: string;
@@ -554,22 +549,42 @@ export interface SandboxInstanceLike {
554
549
  attestationNonce?: string;
555
550
  }): Promise<SandboxTeeAttestationResponseLike>;
556
551
  }
552
+ /** Exact observed attempts within one Sidecar execution. */
553
+ export interface TangleEvidenceAttemptLike {
554
+ executionId: string;
555
+ ordinal: number;
556
+ providerSessionId: string;
557
+ nativeSessionIds: string[];
558
+ processIds: string[];
559
+ outcome: "succeeded" | "failed" | "cancelled" | "unknown";
560
+ missingReasons: string[];
561
+ }
562
+ export interface TangleEvidenceSourceLike {
563
+ executionId: string;
564
+ sourceId: string;
565
+ backendType: string;
566
+ runtimeHome: string;
567
+ credentialPaths: string[];
568
+ }
557
569
  export type TangleRawEvidenceLike = {
558
- status: "captured";
570
+ status: "captured" | "partial";
559
571
  sessionId: string;
560
572
  backendType: string;
561
- nativeSessionId?: string;
573
+ nativeSessionId?: string | null;
562
574
  proofStatus?: "verified" | "unverified";
563
575
  containerId?: string;
564
576
  sidecarImageDigest: string;
565
577
  sidecarBundleRevision: string;
566
578
  sidecarBundleChecksum?: string;
579
+ evidenceSources: TangleEvidenceSourceLike[];
567
580
  nativeRoots: Array<{
568
581
  rootScope: "session-home" | "workspace-session";
569
582
  path: string;
583
+ sourceId?: string;
570
584
  }>;
571
585
  inventory: Record<string, number>;
572
586
  files: Array<{
587
+ sourceId?: string;
573
588
  rootScope: "session-home" | "workspace-session";
574
589
  path: string;
575
590
  kind: "file" | "directory" | "symlink";
@@ -584,7 +599,11 @@ export type TangleRawEvidenceLike = {
584
599
  linkTarget?: string;
585
600
  }>;
586
601
  processIo: Array<{
602
+ sourceId?: string;
587
603
  processId: string;
604
+ executionId?: string;
605
+ ordinal?: number;
606
+ providerSessionId?: string;
588
607
  sequence: number;
589
608
  at: string;
590
609
  stream: "stdin" | "stdout" | "stderr" | "protocol";
@@ -593,8 +612,19 @@ export type TangleRawEvidenceLike = {
593
612
  contentBase64: string;
594
613
  metadata?: unknown;
595
614
  }>;
615
+ /** Exact original spool for every readable source. */
616
+ processSources: Array<{
617
+ sourceId: string;
618
+ contentBase64: string;
619
+ sizeBytes: number;
620
+ sha256: string;
621
+ }>;
596
622
  processTerminals: Array<{
623
+ sourceId?: string;
597
624
  processId: string;
625
+ executionId?: string;
626
+ ordinal?: number;
627
+ providerSessionId?: string;
598
628
  sequence: number;
599
629
  at: string;
600
630
  result: {
@@ -602,12 +632,13 @@ export type TangleRawEvidenceLike = {
602
632
  signal: string | null;
603
633
  timedOut: boolean;
604
634
  timeoutReason: string | null;
605
- captureError: null;
635
+ captureError: string | null;
606
636
  spawnError?: string;
607
637
  };
608
638
  }>;
609
639
  events: unknown[];
610
640
  excluded: Array<{
641
+ sourceId?: string;
611
642
  rootScope: "session-home" | "workspace-session";
612
643
  path: string;
613
644
  kind: "file" | "directory" | "symlink";
@@ -619,12 +650,20 @@ export type TangleRawEvidenceLike = {
619
650
  sizeBytes: number;
620
651
  reason: "credential";
621
652
  }>;
653
+ attempts: TangleEvidenceAttemptLike[];
654
+ skipped?: Array<{
655
+ rootScope: "session-home" | "workspace-session";
656
+ path: string;
657
+ reason: string;
658
+ sourceId?: string;
659
+ }>;
622
660
  completeness: {
623
- nativeStore: true;
624
- processIo: true;
625
- events: true;
661
+ nativeStore: boolean;
662
+ processIo: boolean;
663
+ events: boolean;
626
664
  };
627
- coverageComplete: true;
665
+ coverageComplete: boolean;
666
+ missingReasons: string[];
628
667
  } | {
629
668
  status: "unavailable";
630
669
  sessionId: string;
@@ -1,4 +1,4 @@
1
- import { requireNativeCaptureCapability, requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
1
+ import { requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
2
2
  import { ConfidentialAttestationSchema, ConfidentialExecutionRequestSchema, ForkedEnvironmentRefSchema, WorkspaceCheckpointRequestSchema, WorkspaceCleanupAcknowledgementSchema, WorkspaceCleanupRequestSchema, WorkspaceForkRequestSchema, WorkspaceOperationLookupRequestSchema, WorkspaceCheckpointResultSchema, WorkspaceCheckpointLookupResultSchema, WorkspaceForkResultSchema, WorkspaceForkLookupResultSchema, canonicalCandidateDigest, confidentialExecutionVerified, sha256Bytes, } from "@tangle-network/agent-interface";
3
3
  import { awaitWithSignal, boundedIdentifier, boundedString, MAX_STRING_LENGTH, cloneJson, safeIdentifier, safeString, } from "./tangle-contract-safety.js";
4
4
  import { encodeTangleConfidentialAttestationQuote } from "./tangle-confidential-attestation.js";
@@ -314,8 +314,6 @@ export function createTangleWorkspaceBranching(options) {
314
314
  : "Sandbox checkpoint inventory is unavailable", true);
315
315
  }
316
316
  const metadata = forkMarkerMetadata(request);
317
- if (options.requireNativeSessionCapture)
318
- await requireNativeCaptureCapability(client);
319
317
  let returnedChild;
320
318
  let outcome;
321
319
  try {
@@ -331,8 +329,6 @@ export function createTangleWorkspaceBranching(options) {
331
329
  }, operation?.signal === undefined
332
330
  ? undefined
333
331
  : { signal: operation.signal }), operation?.signal);
334
- if (options.requireNativeSessionCapture)
335
- requireNativeCaptureProof(returnedChild, true);
336
332
  const receipt = returnedChild.createReceipt?.();
337
333
  if (!receipt ||
338
334
  receipt.idempotencyKeyApplied !== true ||
@@ -346,6 +342,16 @@ export function createTangleWorkspaceBranching(options) {
346
342
  }
347
343
  outcome =
348
344
  receipt.outcome === "idempotent_replay" ? "replayed" : "created";
345
+ if (options.requireNativeSessionCapture) {
346
+ try {
347
+ requireNativeCaptureProof(returnedChild, true);
348
+ }
349
+ catch (error) {
350
+ const compensation = await compensateCreatedForkChild(returnedChild, outcome, operation?.signal);
351
+ const removed = compensation === "destroyed" || compensation === "already_absent";
352
+ return forkUnknown(request, `Sandbox snapshot restore capture proof failed: ${safeError(error)}; cleanup ${compensation}`, !removed);
353
+ }
354
+ }
349
355
  }
350
356
  catch (error) {
351
357
  operation?.signal?.throwIfAborted();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "1.9.2",
3
+ "version": "3.0.0",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -106,7 +106,7 @@
106
106
  "@tangle-network/agent-interface": "^2.15.0"
107
107
  },
108
108
  "peerDependencies": {
109
- "@tangle-network/sandbox": ">=0.58.0 <1.0.0"
109
+ "@tangle-network/sandbox": ">=0.58.4 <1.0.0"
110
110
  },
111
111
  "peerDependenciesMeta": {
112
112
  "@tangle-network/sandbox": {
@@ -115,8 +115,8 @@
115
115
  },
116
116
  "devDependencies": {
117
117
  "@tangle-network/agent-provider-testkit": "0.10.0",
118
- "@tangle-network/agent-runtime": "0.282.2",
119
- "@tangle-network/sandbox": "0.58.0",
118
+ "@tangle-network/agent-runtime": "0.286.0",
119
+ "@tangle-network/sandbox": "0.58.4",
120
120
  "@types/node": "26.6.3",
121
121
  "typescript": "7.0.2",
122
122
  "vitest": "5.0.2"