@tangle-network/agent-provider-tangle 3.1.0 → 3.1.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/README.md CHANGED
@@ -30,6 +30,9 @@ const provider = createTangleProvider({
30
30
  `Sandbox` requires an explicit `baseUrl`.
31
31
  Set `TANGLE_SANDBOX_URL` to use another deployment.
32
32
 
33
+ Exact execution replay preserves the admitted request and its digest.
34
+ An explicit replay override cannot replace the selected account, credential channel, or harness.
35
+
33
36
  ## Named model credentials at creation
34
37
 
35
38
  `modelCredentials` sends a stored credential reference and explicit endpoint before Sandbox provisions the backend.
@@ -123,7 +126,12 @@ Sandbox metadata records the public selection under `modelCredentials`.
123
126
  This metadata key is reserved for the Provider selection.
124
127
  Account labels are supplied bindings, not verified native principals.
125
128
  Token values and native credential files never enter that selection or receipt.
126
- The same public native reference can travel in a per-turn `backend.model.cliAuth` with an explicit matching backend type.
129
+ The Provider carries the selected native reference in every new stream, detached dispatch, and session prompt.
130
+ Model-only or profile-only turns retain that exact account and harness.
131
+ The bound reference participates in the admitted request digest before dispatch.
132
+ Reconstructed environments recover it from persisted metadata and the observed backend.
133
+ Replacing the account, harness, or credential channel requires a separate environment.
134
+ Exact replay preserves the already admitted request without adding new credential fields.
127
135
  A turn carrying a profile must preserve its environment's credential source, including after recovery.
128
136
  Changing credential sources requires a separate environment because retained Sandbox defaults cannot safely clear a native binding.
129
137
 
@@ -593,3 +601,13 @@ The caller's attempt projection includes only its known execution IDs.
593
601
  The capture records the running sidecar image digest and the served Sidecar bundle revision.
594
602
  The image digest can be compared with the pre-create proof only when that proof identifies the actual placement image.
595
603
  An incomplete inventory, missing stream, unrelated backend, or mismatched digest does not produce complete evidence.
604
+
605
+ ## Exact retained workspace capture
606
+
607
+ Pass the admitted `controlRef` to `captureTangleEnvironmentEvidence`.
608
+ Keep `executionId` as the Runtime artifact identity.
609
+ The control reference supplies the exact native environment, session, and execution identifiers.
610
+ Capture validates those coordinates before reading files.
611
+ A reconstructed environment does not need the original in-memory session cache.
612
+ The returned provenance retains both identities and reports incomplete native coverage explicitly.
613
+ Missing native session evidence preserves the source under Runtime's complete-provenance policy.
@@ -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, beforePrompt?: (input: AgentTurnInput) => void, 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) => AgentTurnInput | void, onExecution?: (executionId: string) => void): AgentSession;
27
27
  export {};
@@ -317,7 +317,7 @@ export function sandboxSessionAsAgentSession(session, controlRef, provider, envi
317
317
  }));
318
318
  },
319
319
  async prompt(input) {
320
- beforePrompt?.(input);
320
+ input = beforePrompt?.(input) ?? input;
321
321
  AgentTurnInputSchema.parse(input);
322
322
  input.signal?.throwIfAborted();
323
323
  if (promptInFlight) {
@@ -1,3 +1,4 @@
1
+ import { type CliAuthReference } from "@tangle-network/sandbox/auth";
1
2
  import type { AgentEnvironment, AgentEnvironmentCapabilities, ResourceProfile } from "@tangle-network/agent-interface/environment-provider";
2
3
  import type { SandboxClientLike, SandboxInstanceLike, SandboxRuntimeCapabilityDocument } from "./tangle-types.js";
3
4
  import { type ProfileCredentialSource } from "./model-credential-source.js";
@@ -33,6 +34,11 @@ export declare function sandboxInstanceAsEnvironment(box: SandboxInstanceLike, p
33
34
  requireNativeSessionCapture?: boolean;
34
35
  requireCliAuthReferences?: boolean;
35
36
  credentialSource?: ProfileCredentialSource;
37
+ credentialHarness?: string;
38
+ nativeAuth?: {
39
+ harness: string;
40
+ cliAuth: CliAuthReference;
41
+ };
36
42
  captureCapabilities?: SandboxRuntimeCapabilityDocument;
37
43
  captureHarness?: string;
38
44
  }): Promise<AgentEnvironment>;
@@ -1,3 +1,6 @@
1
+ import { assertCliAuthReferenceSupported } from "@tangle-network/sandbox/auth";
2
+ import { canonicalCandidateDigest } from "@tangle-network/agent-interface";
3
+ import { captureModelCredentials } from "./tangle-create-options.js";
1
4
  import { AgentTurnInputSchema, deepFreeze } from "@tangle-network/agent-interface";
2
5
  import { AgentEnvironmentCapabilitiesSchema } from "@tangle-network/agent-interface/environment-provider";
3
6
  import { environmentEventFromSandboxEvent } from "./tangle-events.js";
@@ -63,6 +66,17 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
63
66
  if ((request?.requireCliAuthReferences || recordedNativeReference) && !deployment.cliAuthReferences) {
64
67
  throw new Error("Tangle selected sandbox does not prove native credential reference support");
65
68
  }
69
+ const persistedNative = recordedNativeReference
70
+ ? captureModelCredentials(recordedCredentials)
71
+ : undefined;
72
+ const persistedReference = persistedNative !== undefined && "cliAuth" in persistedNative
73
+ ? persistedNative.cliAuth : undefined;
74
+ if (request?.nativeAuth !== undefined && persistedReference !== undefined &&
75
+ canonicalCandidateDigest(request.nativeAuth.cliAuth) !== canonicalCandidateDigest(persistedReference)) {
76
+ throw new Error("Tangle persisted native credential differs from its selected creation reference");
77
+ }
78
+ const nativeReference = request?.nativeAuth?.cliAuth ?? persistedReference;
79
+ const credentialHarness = request?.nativeAuth?.harness ?? request?.credentialHarness;
66
80
  const boundCredentialSource = request?.credentialSource ??
67
81
  (recordedCredentials !== undefined ? "subscription" : "managed");
68
82
  const capabilities = frozenCapabilityDocument(AgentEnvironmentCapabilitiesSchema.parse(capabilitiesForSandbox(declaredCapabilities, support, deployment, confidentialVerifierOption(request?.confidentialAttestationVerifier))));
@@ -107,6 +121,38 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
107
121
  }
108
122
  assertNativeCaptureHarness(request.captureCapabilities, backend?.type ?? profileHarness ?? request.captureHarness);
109
123
  };
124
+ const prepareTurn = (input) => {
125
+ assertCaptureInput(input);
126
+ if (nativeReference === undefined)
127
+ return input;
128
+ const replay = input.lastEventId !== undefined || input.controlRef !== undefined;
129
+ const backend = promptOptionsFromTurnInput(input, { provider: providerName, environmentId }).backend;
130
+ // A plain exact read supplies no backend override and keeps its admitted request unchanged.
131
+ if (replay && backend === undefined)
132
+ return input;
133
+ const harness = backend?.type ?? backend?.profile?.harness ?? credentialHarness;
134
+ if (credentialHarness === undefined || harness !== credentialHarness ||
135
+ (backend?.profile?.harness !== undefined && backend.profile.harness !== harness)) {
136
+ throw new Error("Tangle native credential turn must preserve its selected environment harness");
137
+ }
138
+ const model = backend?.model ?? {};
139
+ if (model.cliAuth !== undefined &&
140
+ canonicalCandidateDigest(model.cliAuth) !== canonicalCandidateDigest(nativeReference)) {
141
+ throw new Error("Tangle native credential turn cannot replace its selected account reference");
142
+ }
143
+ const selectedModel = { ...model, cliAuth: nativeReference };
144
+ assertCliAuthReferenceSupported(harness, selectedModel);
145
+ // Validate explicit substitutions even on replay, without rewriting its admitted digest.
146
+ if (replay)
147
+ return input;
148
+ return {
149
+ ...input,
150
+ providerOptions: {
151
+ ...input.providerOptions,
152
+ backend: { ...backend, type: harness, model: { ...selectedModel, authMode: "oauth" } },
153
+ },
154
+ };
155
+ };
110
156
  // The single destroy this handle performs, once it has been asked for.
111
157
  let destruction;
112
158
  const terminals = capabilities.interactiveTerminal?.attach === true
@@ -120,8 +166,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
120
166
  ? dispatchEnvironmentRun(box, providerName, environmentId)
121
167
  : undefined;
122
168
  const dispatch = dispatchRun === undefined ? undefined : (input) => {
123
- assertCaptureInput(input);
124
- return dispatchRun(input);
169
+ return dispatchRun(prepareTurn(input));
125
170
  };
126
171
  const exactExecutionEvents = (options) => box.streamPrompt("", {
127
172
  sessionId: options.sessionId,
@@ -151,7 +196,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
151
196
  async *stream(input) {
152
197
  AgentTurnInputSchema.parse(input);
153
198
  input.signal?.throwIfAborted();
154
- assertCaptureInput(input);
199
+ input = prepareTurn(input);
155
200
  const expectedExecutionId = executionIdFromTurnInput(input);
156
201
  const expectedSessionId = input.sessionId ?? input.controlRef?.sessionId;
157
202
  if (expectedSessionId)
@@ -224,7 +269,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
224
269
  if (session.id !== id) {
225
270
  throw new Error("sandbox session(id) returned an unrelated session");
226
271
  }
227
- const agentSession = sandboxSessionAsAgentSession(session, options?.controlRef, providerName, environmentId, dispatch, exactExecutionEvents, retainedControl, interactionResponses, usageLog, capabilities.nativeContinuation !== undefined, assertCaptureInput, (executionId) => noteTangleSession(environment, id, executionId));
272
+ const agentSession = sandboxSessionAsAgentSession(session, options?.controlRef, providerName, environmentId, dispatch, exactExecutionEvents, retainedControl, interactionResponses, usageLog, capabilities.nativeContinuation !== undefined, prepareTurn, (executionId) => noteTangleSession(environment, id, executionId));
228
273
  // sessions.continue was granted from the probe session and the
229
274
  // deployment document together; this backstop holds every
230
275
  // concrete session to that grant, so a client whose sessions
@@ -1,4 +1,4 @@
1
- import type { AgentProfile } from "@tangle-network/agent-interface";
1
+ import { type AgentExactRunControlRef, type AgentProfile } from "@tangle-network/agent-interface";
2
2
  import type { AgentEnvironment } from "@tangle-network/agent-interface/environment-provider";
3
3
  import type { NativeCaptureProofLike, SandboxInstanceLike, TangleEvidenceAttemptLike, TangleEvidenceSourceLike } from "./tangle-types.js";
4
4
  interface WorkspaceEntryMetadata {
@@ -14,7 +14,10 @@ interface WorkspaceEntryMetadata {
14
14
  symlinkTarget: null;
15
15
  }
16
16
  export interface TangleEnvironmentEvidenceOptions {
17
+ /** Runtime artifact identity when controlRef is supplied; otherwise the native execution id. */
17
18
  executionId: string;
19
+ /** Durable admitted coordinates, including when a reconstructed environment has no session cache. */
20
+ controlRef?: AgentExactRunControlRef;
18
21
  harness: NonNullable<AgentProfile["harness"]>;
19
22
  /** Optional local image ID to compare with the running sidecar image. */
20
23
  expectedSidecarImageDigest?: string;
@@ -26,6 +29,8 @@ export interface TangleEnvironmentEvidenceOptions {
26
29
  signal?: AbortSignal;
27
30
  }
28
31
  export interface TangleSandboxEvidenceOptions extends Omit<TangleEnvironmentEvidenceOptions, "sandboxSessionId"> {
32
+ /** Runtime artifact identity; native executionId remains subject to path-safe validation. */
33
+ runtimeExecutionId?: string;
29
34
  sandboxSessionIds: readonly string[];
30
35
  /** Every observed execution on each retained Sandbox session. */
31
36
  sessionExecutionIds?: Readonly<Record<string, readonly string[]>>;
@@ -42,6 +47,7 @@ export interface TangleEnvironmentEvidence {
42
47
  provider: string;
43
48
  environmentId: string;
44
49
  executionId: string;
50
+ controlRef?: AgentExactRunControlRef;
45
51
  captureProof?: NativeCaptureProofLike;
46
52
  workspaceScope: "environment";
47
53
  workspaceRoot: string;
@@ -1,4 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { AgentExactRunControlRefSchema } from "@tangle-network/agent-interface";
2
3
  import { requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
3
4
  const handles = new WeakMap();
4
5
  const blockedNames = new Set([".ssh", ".config", ".claude", ".codex", ".opencode", ".env", ".env.local", ".npmrc", ".sidecar"]);
@@ -20,19 +21,31 @@ export async function captureTangleEnvironmentEvidence(environment, options) {
20
21
  const state = handles.get(environment);
21
22
  if (!state || state.box.id !== environment.id)
22
23
  throw new Error("Tangle evidence requires a live provider environment handle");
23
- const sessionIds = new Set([...state.sessions.entries()]
24
- .filter(([, executions]) => executions.has(options.executionId))
24
+ const controlRef = options.controlRef === undefined ? undefined : AgentExactRunControlRefSchema.parse(options.controlRef);
25
+ if (controlRef && (controlRef.environmentId !== environment.id || controlRef.provider !== environment.provider ||
26
+ (options.sandboxSessionId != null && options.sandboxSessionId !== controlRef.sessionId))) {
27
+ throw new Error("Tangle evidence control reference names another environment or session");
28
+ }
29
+ const executionId = controlRef?.executionId ?? options.executionId;
30
+ const sessionIds = controlRef ? new Set([controlRef.sessionId]) : new Set([...state.sessions.entries()]
31
+ .filter(([, executions]) => executions.has(executionId))
25
32
  .map(([id]) => id));
26
33
  if (options.sandboxSessionId != null)
27
34
  sessionIds.add(options.sandboxSessionId);
35
+ const sessionExecutionIds = Object.fromEntries([...sessionIds].filter((id) => state.sessions.has(id))
36
+ .map((id) => [id, [...state.sessions.get(id)]]));
37
+ if (controlRef)
38
+ sessionExecutionIds[controlRef.sessionId] = [...new Set([
39
+ ...(sessionExecutionIds[controlRef.sessionId] ?? []), controlRef.executionId,
40
+ ])];
28
41
  return captureTangleSandboxEvidence(state.box, {
29
- executionId: options.executionId,
42
+ executionId,
43
+ ...(controlRef === undefined ? {} : { runtimeExecutionId: options.executionId, controlRef }),
30
44
  harness: options.harness,
31
45
  expectedSidecarImageDigest: options.expectedSidecarImageDigest,
32
46
  requireNativeSessionCapture: options.requireNativeSessionCapture,
33
47
  sandboxSessionIds: [...sessionIds],
34
- sessionExecutionIds: Object.fromEntries([...sessionIds].filter((id) => state.sessions.has(id))
35
- .map((id) => [id, [...state.sessions.get(id)]])),
48
+ sessionExecutionIds,
36
49
  maxBytes: options.maxBytes,
37
50
  signal: options.signal,
38
51
  });
@@ -41,6 +54,16 @@ export async function captureTangleEnvironmentEvidence(environment, options) {
41
54
  export async function captureTangleSandboxEvidence(box, options) {
42
55
  if (!safeIdentifier(box.id) || !safeIdentifier(options.executionId))
43
56
  throw new Error("Tangle evidence requires exact box and execution ids");
57
+ const controlRef = options.controlRef === undefined ? undefined : AgentExactRunControlRefSchema.parse(options.controlRef);
58
+ if (controlRef && (controlRef.environmentId !== box.id ||
59
+ controlRef.executionId !== options.executionId || !options.sandboxSessionIds?.includes(controlRef.sessionId))) {
60
+ throw new Error("Tangle evidence control reference does not bind the exact native capture");
61
+ }
62
+ if (options.runtimeExecutionId !== undefined && (!controlRef || typeof options.runtimeExecutionId !== "string" ||
63
+ !options.runtimeExecutionId.length || options.runtimeExecutionId.length > 2048 || /[\u0000-\u001f\u007f]/.test(options.runtimeExecutionId))) {
64
+ throw new Error("Tangle evidence Runtime artifact identity requires an exact admitted control reference");
65
+ }
66
+ const artifactExecutionId = options.runtimeExecutionId ?? options.executionId;
44
67
  if (!safeIdentifier(options.harness))
45
68
  throw new Error("Tangle evidence requires an exact profile harness");
46
69
  if (options.expectedSidecarImageDigest !== undefined &&
@@ -603,7 +626,7 @@ export async function captureTangleSandboxEvidence(box, options) {
603
626
  capturedBytes += manifest.byteLength;
604
627
  }
605
628
  sessions.push({
606
- id, executionId: options.executionId, executionIds: [...executionIds], eventCountsByExecutionId,
629
+ id, executionId: artifactExecutionId, executionIds: [...executionIds], eventCountsByExecutionId,
607
630
  backendType: options.harness, sidecarImageDigest, sidecarBundleRevision,
608
631
  transportEvents: executionIds.every((executionId) => eventCountsByExecutionId[executionId] > 0) ? "complete" : "unavailable",
609
632
  eventCount: events.length, messageCount: messages.length, messageScope: "session",
@@ -620,9 +643,10 @@ export async function captureTangleSandboxEvidence(box, options) {
620
643
  }
621
644
  }
622
645
  const provenance = {
623
- provider: "tangle-sandbox",
646
+ provider: controlRef?.provider ?? "tangle-sandbox",
624
647
  environmentId: box.id,
625
- executionId: options.executionId,
648
+ executionId: artifactExecutionId,
649
+ ...(controlRef === undefined ? {} : { controlRef }),
626
650
  ...(captureProof ? { captureProof } : {}),
627
651
  workspaceScope: "environment",
628
652
  workspaceRoot,
@@ -208,6 +208,9 @@ export function createTangleProvider(options) {
208
208
  ? {}
209
209
  : { resources: requestedResources }),
210
210
  credentialSource,
211
+ ...(createOptions.backend?.model?.cliAuth === undefined ? {} : {
212
+ nativeAuth: { harness: createOptions.backend.type, cliAuth: createOptions.backend.model.cliAuth },
213
+ }),
211
214
  ...(createOptions.backend?.model?.cliAuth === undefined ? {} : { requireCliAuthReferences: true }),
212
215
  ...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
213
216
  ...(captureCapabilities === undefined ? {} : { captureCapabilities }),
@@ -318,7 +321,7 @@ export function createTangleProvider(options) {
318
321
  ...confidentialVerifierOption(options.confidentialAttestationVerifier),
319
322
  ...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
320
323
  ...(captureCapabilities === undefined ? {} : { captureCapabilities }),
321
- ...(backendType === undefined ? {} : { captureHarness: backendType }),
324
+ ...(backendType === undefined ? {} : { captureHarness: backendType, credentialHarness: backendType }),
322
325
  });
323
326
  },
324
327
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",