@tangle-network/agent-provider-tangle 2.0.0 → 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.
package/README.md CHANGED
@@ -455,12 +455,19 @@ The adapter rejects ordinary sandboxes during create, recovery, and list operati
455
455
 
456
456
  ## Private session evidence
457
457
 
458
- Call `readTangleEvidenceCapabilities(client)` before creating a sandbox when complete evidence is required.
459
- It requires workspace capture, an explicit native capture harness list, and the next-create sidecar image digest.
460
- A global capture flag cannot admit a profile whose harness is absent from that list.
461
- Unprofiled exact-process and checkpoint restores retain the stricter global guarantee.
462
- Apply `assertTangleEvidenceProfileCapability(proof, profile)` to the exact profile in each create hook.
463
- An unavailable or unproven capability fails before the sandbox spends resources.
458
+ Set `requireNativeSessionCapture: true` when the provider must retain complete native evidence.
459
+ Sandbox selects a host with fresh capture proof and returns proof for the created container.
460
+ The provider matches that proof to the create receipt before returning the environment.
461
+ Agent creation and reconnect check the selected container's capture protocol and exact backend through `box.capabilities()`.
462
+ Unsupported agent capture refuses before a model turn.
463
+ A newly created container is cleaned up when its required proof is missing.
464
+ An unrelated host or pending fleet update does not determine this container's admission.
465
+
466
+ Exact-process creation retains its container proof and existing managed-process output and terminal contracts.
467
+ Checkpoint restoration requires its container proof and exact source/checkpoint identity.
468
+ A restored agent environment verifies its actual backend when reconnected.
469
+ The capture requirement also reaches checkpoint operations exposed by an environment.
470
+ Fleet capability summaries are diagnostic observations, not placement admission.
464
471
 
465
472
  Call `captureTangleEnvironmentEvidence(environment, options)` before destroying a provider environment.
466
473
  For a Runtime-owned box, call `captureTangleSandboxEvidence(box, options)` with exact session and execution IDs.
@@ -1,7 +1,7 @@
1
1
  import { assertBoundedJson, attachCleanupHandle, awaitWithSignal, boundedIdentifier, boundedString, exactProcessRequestDigest, isBoundedJson, MAX_LIST_RESULTS, SANDBOX_LIST_PAGE_SIZE, } from "./tangle-contract-safety.js";
2
2
  import { sandboxInstanceAsExactProcessEnvironment } from "./tangle-exact-process-environment.js";
3
3
  import { awaitSandboxRunning } from "./tangle-readiness.js";
4
- import { requireNativeCaptureCapability, requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
4
+ import { requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
5
5
  import { assertExactProcessSandbox, assertSupportedProviderOptions, assertUnreservedMetadata, EXACT_PROCESS_METADATA_KEY, isExactProcessRequestConflict, isExactProcessSandbox, metadataMatches, assertSignalOptions, } from "./tangle-exact-process-validation.js";
6
6
  const IMMUTABLE_TANGLE_IMAGE = /^(?:sha256:[a-f0-9]{64}|\S+@sha256:[a-f0-9]{64})$/i;
7
7
  export function createTangleExactProcessProvider(input) {
@@ -22,8 +22,6 @@ export function createTangleExactProcessProvider(input) {
22
22
  assertUnreservedMetadata(createInput.metadata);
23
23
  const identityDigest = exactProcessRequestDigest(createInput, providerName, options);
24
24
  createInput.signal?.throwIfAborted();
25
- if (input.requireNativeSessionCapture)
26
- await requireNativeCaptureCapability(client);
27
25
  const createPromise = client.create({
28
26
  ...exactSandboxOptions(createInput, options, providerName, identityDigest),
29
27
  ...(input.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
@@ -41,7 +39,7 @@ export function createTangleExactProcessProvider(input) {
41
39
  if (createInput.signal?.aborted) {
42
40
  void createPromise
43
41
  .then(async (lateBox) => {
44
- if (!lateBox.delete) {
42
+ if (lateBox.createReceipt?.()?.outcome !== "created" || !lateBox.delete) {
45
43
  attachCleanupHandle(error, lateBox);
46
44
  return;
47
45
  }
@@ -80,6 +78,10 @@ export function createTangleExactProcessProvider(input) {
80
78
  if (isExactProcessRequestConflict(box, providerName, options.teamId, createInput.idempotencyKey, identityDigest)) {
81
79
  throw new Error("Tangle exact process idempotency key conflicts with an existing request", { cause: error });
82
80
  }
81
+ if (box.createReceipt?.()?.outcome !== "created") {
82
+ attachCleanupHandle(error, box);
83
+ throw error;
84
+ }
83
85
  if (!box.delete) {
84
86
  const baseError = error instanceof Error ? error : new Error(String(error));
85
87
  throw Object.assign(baseError, {
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@ export { JsonBoundError, MAX_INLINE_PAYLOAD_BYTES, MAX_PAYLOAD_STRING_BYTES, MAX
3
3
  export type { JsonBoundRule, JsonBoundViolation } from "./tangle-contract-safety.js";
4
4
  export * from "./tangle-types.js";
5
5
  export { createTangleProvider } from "./tangle-provider.js";
6
- export { assertTangleEvidenceCapability, assertTangleEvidenceProfileCapability, readTangleEvidenceCapabilities, captureTangleEnvironmentEvidence, captureTangleSandboxEvidence } from "./tangle-evidence.js";
7
- export type { TangleEvidenceCapabilities, TangleEnvironmentEvidence, TangleEnvironmentEvidenceOptions, TangleSandboxEvidenceOptions } from "./tangle-evidence.js";
6
+ export { captureTangleEnvironmentEvidence, captureTangleSandboxEvidence } from "./tangle-evidence.js";
7
+ export type { TangleEnvironmentEvidence, TangleEnvironmentEvidenceOptions, TangleSandboxEvidenceOptions } from "./tangle-evidence.js";
8
8
  export { DEFAULT_TANGLE_READY_TIMEOUT_MS } from "./tangle-readiness.js";
9
9
  export { defaultTangleSandboxCapabilities } from "./tangle-capabilities.js";
10
10
  export { createTangleWorkspaceBranching, supportsWorkspaceBranching, } from "./tangle-workspace-branching.js";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { JsonBoundError, MAX_INLINE_PAYLOAD_BYTES, MAX_PAYLOAD_STRING_BYTES, MAX_TOTAL_PAYLOAD_BYTES, } from "./tangle-contract-safety.js";
2
2
  export * from "./tangle-types.js";
3
3
  export { createTangleProvider } from "./tangle-provider.js";
4
- export { assertTangleEvidenceCapability, assertTangleEvidenceProfileCapability, readTangleEvidenceCapabilities, captureTangleEnvironmentEvidence, captureTangleSandboxEvidence } from "./tangle-evidence.js";
4
+ export { captureTangleEnvironmentEvidence, captureTangleSandboxEvidence } from "./tangle-evidence.js";
5
5
  export { DEFAULT_TANGLE_READY_TIMEOUT_MS } from "./tangle-readiness.js";
6
6
  export { defaultTangleSandboxCapabilities } from "./tangle-capabilities.js";
7
7
  export { createTangleWorkspaceBranching, supportsWorkspaceBranching, } from "./tangle-workspace-branching.js";
@@ -23,5 +23,5 @@ type ExactExecutionEventStream = (options: {
23
23
  * environment observation reads it, because Sandbox reports usage per
24
24
  * execution result and never for the environment.
25
25
  */
26
- export declare function sandboxSessionAsAgentSession(session: SandboxSessionLike, controlRef: AgentRunControlRef | undefined, provider: string, environmentId: string, dispatch: ((input: AgentTurnInput) => Promise<AgentSessionRef>) | undefined, exactExecutionEvents: ExactExecutionEventStream | undefined, retainedControl: boolean, interactionResponses: boolean, usageLog?: ExecutionUsageLog, nativeContinuation?: boolean, onExecution?: (executionId: string) => void): AgentSession;
26
+ export declare function sandboxSessionAsAgentSession(session: SandboxSessionLike, controlRef: AgentRunControlRef | undefined, provider: string, environmentId: string, dispatch: ((input: AgentTurnInput) => Promise<AgentSessionRef>) | undefined, exactExecutionEvents: ExactExecutionEventStream | undefined, retainedControl: boolean, interactionResponses: boolean, usageLog?: ExecutionUsageLog, nativeContinuation?: boolean, beforePrompt?: (input: AgentTurnInput) => void, onExecution?: (executionId: string) => void): AgentSession;
27
27
  export {};
@@ -24,7 +24,7 @@ import { hasReplayPayload, interruptExecutionAfterAbort, sessionPromptRequestDig
24
24
  * environment observation reads it, because Sandbox reports usage per
25
25
  * execution result and never for the environment.
26
26
  */
27
- export function sandboxSessionAsAgentSession(session, controlRef, provider, environmentId, dispatch, exactExecutionEvents, retainedControl, interactionResponses, usageLog, nativeContinuation = false, onExecution) {
27
+ export function sandboxSessionAsAgentSession(session, controlRef, provider, environmentId, dispatch, exactExecutionEvents, retainedControl, interactionResponses, usageLog, nativeContinuation = false, beforePrompt, onExecution) {
28
28
  const measured = (executionId, result) => {
29
29
  usageLog?.record(executionId, result.usage);
30
30
  return result;
@@ -317,6 +317,7 @@ export function sandboxSessionAsAgentSession(session, controlRef, provider, envi
317
317
  }));
318
318
  },
319
319
  async prompt(input) {
320
+ beforePrompt?.(input);
320
321
  AgentTurnInputSchema.parse(input);
321
322
  input.signal?.throwIfAborted();
322
323
  if (promptInFlight) {
@@ -1,5 +1,5 @@
1
1
  import type { AgentEnvironment, AgentEnvironmentCapabilities, ResourceProfile } from "@tangle-network/agent-interface/environment-provider";
2
- import type { SandboxClientLike, SandboxInstanceLike } from "./tangle-types.js";
2
+ import type { SandboxClientLike, SandboxInstanceLike, SandboxRuntimeCapabilityDocument } from "./tangle-types.js";
3
3
  import type { TangleConfidentialAttestationVerifier } from "./tangle-types.js";
4
4
  /**
5
5
  * Compose one concrete sandbox into an environment.
@@ -29,4 +29,7 @@ export declare function sandboxInstanceAsEnvironment(box: SandboxInstanceLike, p
29
29
  }, request?: {
30
30
  resources?: ResourceProfile;
31
31
  confidentialAttestationVerifier?: TangleConfidentialAttestationVerifier;
32
+ requireNativeSessionCapture?: boolean;
33
+ captureCapabilities?: SandboxRuntimeCapabilityDocument;
34
+ captureHarness?: string;
32
35
  }): Promise<AgentEnvironment>;
@@ -5,7 +5,7 @@ import { executionIdFromTurnInput, promptFromTurnInput, promptOptionsFromTurnInp
5
5
  import { creationFromSandboxCreateReceipt, placementInfoFromLoopPlacement, statusFromUnknown, } from "./tangle-environment-values.js";
6
6
  import { execResultFromSandboxExecResult } from "./tangle-result-values.js";
7
7
  import { capabilitiesForSandbox, frozenCapabilityDocument, sandboxCapabilitySupport, } from "./tangle-capabilities.js";
8
- import { readDeploymentCapabilitySupport } from "./tangle-deployment-capabilities.js";
8
+ import { deploymentCapabilitySupport, readDeploymentCapabilitySupport } from "./tangle-deployment-capabilities.js";
9
9
  import { awaitWithSignal, assertBoundedJson, boundedIdentifier, boundedString, } from "./tangle-contract-safety.js";
10
10
  import { assertExecOptions, assertOptionKeys, } from "./tangle-environment-validation.js";
11
11
  import { interruptExecutionAfterAbort, } from "./tangle-environment-control.js";
@@ -19,6 +19,7 @@ import { createTangleTerminalRegistry } from "./tangle-terminal.js";
19
19
  import { createTangleInteractiveAgentRegistry } from "./tangle-interactive.js";
20
20
  import { confidentialVerifierOption, createTangleWorkspaceBranching, } from "./tangle-workspace-branching.js";
21
21
  import { bindTangleEvidenceEnvironment, noteTangleSession } from "./tangle-evidence.js";
22
+ import { assertNativeCaptureHarness } from "./tangle-native-capture-proof.js";
22
23
  /**
23
24
  * Compose one concrete sandbox into an environment.
24
25
  *
@@ -52,7 +53,9 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
52
53
  assertBoundedJson(box.metadata, "Tangle environment metadata");
53
54
  }
54
55
  const support = sandboxCapabilitySupport(box, client, request?.resources);
55
- const deployment = await readDeploymentCapabilitySupport(box, operation);
56
+ const deployment = request?.captureCapabilities === undefined
57
+ ? await readDeploymentCapabilitySupport(box, operation)
58
+ : deploymentCapabilitySupport(request.captureCapabilities);
56
59
  const capabilities = frozenCapabilityDocument(AgentEnvironmentCapabilitiesSchema.parse(capabilitiesForSandbox(declaredCapabilities, support, deployment, confidentialVerifierOption(request?.confidentialAttestationVerifier))));
57
60
  const workspaceBranching = capabilities.branching.checkpoint &&
58
61
  capabilities.branching.fork &&
@@ -63,6 +66,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
63
66
  client,
64
67
  provider: providerName,
65
68
  ...confidentialVerifierOption(request?.confidentialAttestationVerifier),
69
+ ...(request?.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
66
70
  })
67
71
  : undefined;
68
72
  // The published document is the single source for what this environment
@@ -72,6 +76,18 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
72
76
  // Usage is measured per execution, so the log collects what runs through
73
77
  // this handle and the observation reports the newest record it holds.
74
78
  const usageLog = createExecutionUsageLog();
79
+ const assertCaptureInput = (input) => {
80
+ if (!request?.requireNativeSessionCapture)
81
+ return;
82
+ if (!request.captureCapabilities)
83
+ throw new Error("Tangle native capture has no measured container capability document");
84
+ const backend = promptOptionsFromTurnInput(input, { provider: providerName, environmentId }).backend;
85
+ const profileHarness = typeof backend?.profile === "object" ? backend.profile.harness : undefined;
86
+ if (backend?.type !== undefined && profileHarness !== undefined && backend.type !== profileHarness) {
87
+ throw new Error("Tangle native capture turn backend differs from its exact profile harness");
88
+ }
89
+ assertNativeCaptureHarness(request.captureCapabilities, backend?.type ?? profileHarness ?? request.captureHarness);
90
+ };
75
91
  // The single destroy this handle performs, once it has been asked for.
76
92
  let destruction;
77
93
  const terminals = capabilities.interactiveTerminal?.attach === true
@@ -81,9 +97,13 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
81
97
  capabilities.interactiveAgent.control === true
82
98
  ? createTangleInteractiveAgentRegistry(box, providerName, environmentId)
83
99
  : undefined;
84
- const dispatch = capabilities.streaming.detach && box.dispatchPrompt
100
+ const dispatchRun = capabilities.streaming.detach && box.dispatchPrompt
85
101
  ? dispatchEnvironmentRun(box, providerName, environmentId)
86
102
  : undefined;
103
+ const dispatch = dispatchRun === undefined ? undefined : (input) => {
104
+ assertCaptureInput(input);
105
+ return dispatchRun(input);
106
+ };
87
107
  const exactExecutionEvents = (options) => box.streamPrompt("", {
88
108
  sessionId: options.sessionId,
89
109
  executionId: options.executionId,
@@ -112,6 +132,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
112
132
  async *stream(input) {
113
133
  AgentTurnInputSchema.parse(input);
114
134
  input.signal?.throwIfAborted();
135
+ assertCaptureInput(input);
115
136
  const expectedExecutionId = executionIdFromTurnInput(input);
116
137
  const expectedSessionId = input.sessionId ?? input.controlRef?.sessionId;
117
138
  if (expectedSessionId)
@@ -184,7 +205,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
184
205
  if (session.id !== id) {
185
206
  throw new Error("sandbox session(id) returned an unrelated session");
186
207
  }
187
- const agentSession = sandboxSessionAsAgentSession(session, options?.controlRef, providerName, environmentId, dispatch, exactExecutionEvents, retainedControl, interactionResponses, usageLog, capabilities.nativeContinuation !== undefined, (executionId) => noteTangleSession(environment, id, executionId));
208
+ const agentSession = sandboxSessionAsAgentSession(session, options?.controlRef, providerName, environmentId, dispatch, exactExecutionEvents, retainedControl, interactionResponses, usageLog, capabilities.nativeContinuation !== undefined, assertCaptureInput, (executionId) => noteTangleSession(environment, id, executionId));
188
209
  // sessions.continue was granted from the probe session and the
189
210
  // deployment document together; this backstop holds every
190
211
  // concrete session to that grant, so a client whose sessions
@@ -1,19 +1,6 @@
1
- import type { AgentProfile, HarnessType } from "@tangle-network/agent-interface";
1
+ import type { AgentProfile } from "@tangle-network/agent-interface";
2
2
  import type { AgentEnvironment } from "@tangle-network/agent-interface/environment-provider";
3
- import type { NativeCaptureProofLike, SandboxClientLike, SandboxInstanceLike, TangleEvidenceAttemptLike, TangleEvidenceSourceLike } from "./tangle-types.js";
4
- export interface TangleEvidenceCapabilities {
5
- readonly workspaceCaptureV1: true;
6
- readonly nativeSessionCaptureV1: boolean;
7
- readonly nativeSessionCaptureVersion: 2;
8
- readonly nativeSessionCaptureHarnesses: readonly HarnessType[];
9
- readonly sidecarImageDigest: string;
10
- }
11
- /** Read a deployment guarantee once, before Runtime starts creating environments. */
12
- export declare function readTangleEvidenceCapabilities(client: SandboxClientLike): Promise<TangleEvidenceCapabilities>;
13
- /** Require the exact profile harness in the deployment's verified admission list. */
14
- export declare function assertTangleEvidenceProfileCapability(document: TangleEvidenceCapabilities, profile: AgentProfile): void;
15
- /** Refuse unsupported or unproven native trace retention before Sandbox create. */
16
- export declare function assertTangleEvidenceCapability(client: SandboxClientLike, profile: AgentProfile): Promise<void>;
3
+ import type { NativeCaptureProofLike, SandboxInstanceLike, TangleEvidenceAttemptLike, TangleEvidenceSourceLike } from "./tangle-types.js";
17
4
  interface WorkspaceEntryMetadata {
18
5
  path: string;
19
6
  type: "file" | "directory" | "symlink";
@@ -1,47 +1,9 @@
1
1
  import { createHash } from "node:crypto";
2
- import { parseBackendType } from "@tangle-network/sandbox";
3
- import { nativeCaptureHarnesses, requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
2
+ import { requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
4
3
  const handles = new WeakMap();
5
4
  const blockedNames = new Set([".ssh", ".config", ".claude", ".codex", ".opencode", ".env", ".env.local", ".npmrc", ".sidecar"]);
6
5
  const MAX_ENTRIES = 100_000;
7
6
  const MAX_EVENTS = 100_000;
8
- const verifiedCapabilities = new WeakSet();
9
- /** Read a deployment guarantee once, before Runtime starts creating environments. */
10
- export async function readTangleEvidenceCapabilities(client) {
11
- if (typeof client.evidenceCapabilities !== "function")
12
- throw new Error("Tangle deployment has no pre-create evidence capability query");
13
- const document = await client.evidenceCapabilities();
14
- if (document?.workspaceCaptureV1 !== true || typeof document.nativeSessionCaptureV1 !== "boolean" ||
15
- document.nativeSessionCaptureVersion !== 2 ||
16
- !/^sha256:[0-9a-f]{64}$/.test(document.sidecarImageDigest ?? "")) {
17
- throw new Error("Tangle deployment has not proven complete workspace and native session capture for next-create placement");
18
- }
19
- const verified = Object.freeze({
20
- workspaceCaptureV1: true,
21
- nativeSessionCaptureV1: document.nativeSessionCaptureV1,
22
- nativeSessionCaptureVersion: 2,
23
- nativeSessionCaptureHarnesses: nativeCaptureHarnesses(document.nativeSessionCaptureHarnesses),
24
- sidecarImageDigest: document.sidecarImageDigest,
25
- });
26
- verifiedCapabilities.add(verified);
27
- return verified;
28
- }
29
- /** Require the exact profile harness in the deployment's verified admission list. */
30
- export function assertTangleEvidenceProfileCapability(document, profile) {
31
- if (!verifiedCapabilities.has(document))
32
- throw new Error("Tangle evidence capability was not read from the deployment");
33
- if (!profile.harness)
34
- throw new Error("Tangle complete native session capture requires an exact profile harness");
35
- parseBackendType(profile.harness);
36
- if (!document.nativeSessionCaptureHarnesses.includes(profile.harness)) {
37
- throw new Error(`Tangle deployment has not proven native session capture for harness ${JSON.stringify(profile.harness)}`);
38
- }
39
- }
40
- /** Refuse unsupported or unproven native trace retention before Sandbox create. */
41
- export async function assertTangleEvidenceCapability(client, profile) {
42
- const document = await readTangleEvidenceCapabilities(client);
43
- assertTangleEvidenceProfileCapability(document, profile);
44
- }
45
7
  export function bindTangleEvidenceEnvironment(environment, box) {
46
8
  handles.set(environment, { box, sessions: new Map() });
47
9
  }
@@ -1,9 +1,10 @@
1
1
  import { type HarnessType } from "@tangle-network/agent-interface";
2
- import type { NativeCaptureProofLike, SandboxClientLike, SandboxInstanceLike } from "./tangle-types.js";
2
+ import type { NativeCaptureProofLike, SandboxInstanceLike, SandboxRuntimeCapabilityDocument } from "./tangle-types.js";
3
3
  /** Require a current host proof; a create must also prove its receipt names that same container. */
4
4
  export declare function requireNativeCaptureProof(box: SandboxInstanceLike, create?: boolean): NativeCaptureProofLike;
5
5
  /** Parse the deployment's explicit per-harness admission without inferring from a global flag. */
6
6
  export declare function nativeCaptureHarnesses(raw: unknown): readonly HarnessType[];
7
- /** Refuse an unsupported deployment before creating a billable sandbox.
8
- * Unprofiled exact-process and checkpoint restores retain the stricter universal guarantee. */
9
- export declare function requireNativeCaptureCapability(client: SandboxClientLike, harness?: string): Promise<void>;
7
+ /** Require the selected container's native protocol and exact agent backend before dispatch. */
8
+ export declare function requireNativeCaptureCapability(box: SandboxInstanceLike, harness: string): Promise<SandboxRuntimeCapabilityDocument>;
9
+ /** Validate each newly dispatched backend against this container's measured document. */
10
+ export declare function assertNativeCaptureHarness(document: SandboxRuntimeCapabilityDocument, harness: string | undefined): void;
@@ -33,24 +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 (document.nativeSessionCaptureVersion !== 2) {
44
- throw new Error("Tangle deployment has not proven native session capture protocol 2 for next-create placement");
45
- }
46
- if (harness === undefined) {
47
- if (document.nativeSessionCaptureV1 !== true) {
48
- throw new Error("Tangle deployment has not proven native session capture for unprofiled next-create placement");
49
- }
50
- 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");
51
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) {
52
51
  const selected = harnessTypeSchema.safeParse(harness);
53
52
  if (!selected.success || !nativeCaptureHarnesses(document.nativeSessionCaptureHarnesses).includes(selected.data)) {
54
- 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)}`);
55
54
  }
56
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,14 +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
- nativeSessionCaptureVersion?: number;
30
- nativeSessionCaptureHarnesses?: readonly HarnessType[];
31
- workspaceCaptureV1?: boolean;
32
- sidecarImageDigest?: string;
33
- }>;
34
26
  create(options?: CreateSandboxOptions, requestOptions?: {
35
27
  signal?: AbortSignal;
36
28
  timeoutMs?: number;
@@ -109,6 +101,8 @@ export interface SandboxSubscriptionLike {
109
101
  */
110
102
  export interface SandboxRuntimeCapabilityDocument {
111
103
  schema?: number;
104
+ nativeSessionCaptureVersion?: number;
105
+ nativeSessionCaptureHarnesses?: readonly string[];
112
106
  agentInterface?: string;
113
107
  sidecarVersion?: string;
114
108
  image?: 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": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",