@tangle-network/agent-provider-tangle 3.1.3 → 3.1.4

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
@@ -40,6 +40,12 @@ Runtime resolves child source files through this reader without copying their co
40
40
  Paths keep the control-plane limit.
41
41
  Live reads require the selected Sandbox workspace capability.
42
42
 
43
+ Evidence capture retains full workspace files that exceed the Sandbox JSON read limit through bounded binary downloads.
44
+ This requires a Sandbox SDK whose filesystem advertises `supportsBoundedDownload`.
45
+ Capture verifies the downloaded size and SHA-256 receipt before adding bytes to the archive.
46
+ Aggregate limits, credential exclusions, and exact native-session proof remain enforced.
47
+ An unsupported downloader or incomplete transfer fails capture and preserves the source environment.
48
+
43
49
  ## Named model credentials at creation
44
50
 
45
51
  `modelCredentials` sends a stored credential reference and explicit endpoint before Sandbox provisions the backend.
@@ -149,17 +149,27 @@ export async function captureTangleSandboxEvidence(box, options) {
149
149
  excludedPaths.push({ ...item, reason: "credential-path" });
150
150
  continue;
151
151
  }
152
+ const remainingBytes = options.maxBytes - capturedBytes;
153
+ if (entry.size > remainingBytes)
154
+ throw new Error("Tangle evidence exceeds byte limit");
152
155
  const result = await fs.readBatch([sourcePath], { encoding: "base64" });
153
- if (result.errors.length || result.files.length !== 1 || result.files[0]?.path !== sourcePath || result.files[0]?.encoding !== "base64") {
154
- throw new Error(`Tangle evidence could not read workspace file ${path}`);
155
- }
156
- const read = result.files[0];
157
- const bytes = Buffer.from(read.content, "base64");
158
- if (bytes.byteLength !== entry.size || read.size !== entry.size || bytes.toString("base64") !== read.content) {
159
- throw new Error(`Tangle evidence workspace file changed or was truncated: ${path}`);
156
+ let bytes;
157
+ if (result.files.length === 0 && result.errors.length === 1 &&
158
+ result.errors[0]?.path === sourcePath && result.errors[0]?.code === "FILE_TOO_LARGE") {
159
+ bytes = await downloadWorkspaceEvidenceFile(fs, sourcePath, entry.size, remainingBytes, options.signal);
160
160
  }
161
- if (read.hash && read.hash.replace(/^sha256:/, "") !== createHash("sha256").update(bytes).digest("hex")) {
162
- throw new Error(`Tangle evidence workspace file hash mismatch: ${path}`);
161
+ else {
162
+ if (result.errors.length || result.files.length !== 1 || result.files[0]?.path !== sourcePath || result.files[0]?.encoding !== "base64") {
163
+ throw new Error(`Tangle evidence could not read workspace file ${path}`);
164
+ }
165
+ const read = result.files[0];
166
+ bytes = Buffer.from(read.content, "base64");
167
+ if (bytes.byteLength !== entry.size || read.size !== entry.size || bytes.toString("base64") !== read.content) {
168
+ throw new Error(`Tangle evidence workspace file changed or was truncated: ${path}`);
169
+ }
170
+ if (read.hash && read.hash.replace(/^sha256:/, "") !== createHash("sha256").update(bytes).digest("hex")) {
171
+ throw new Error(`Tangle evidence workspace file hash mismatch: ${path}`);
172
+ }
163
173
  }
164
174
  files.push({ path, bytes, mode: entry.permissions & 0o777 });
165
175
  capturedBytes += bytes.byteLength;
@@ -664,6 +674,40 @@ export async function captureTangleSandboxEvidence(box, options) {
664
674
  files.push({ path: "__retention__/provenance.json", bytes: provenanceBytes, mode: 0o600 });
665
675
  return { files: files.sort((a, b) => a.path.localeCompare(b.path)), provenance };
666
676
  }
677
+ /** The JSON reader has a smaller transport cap than an evidence archive. */
678
+ async function downloadWorkspaceEvidenceFile(fs, sourcePath, expectedSize, maxBytes, signal) {
679
+ if (fs.supportsBoundedDownload !== true || !fs.download) {
680
+ throw new Error(`Tangle evidence requires bounded binary download for workspace file ${sourcePath}`);
681
+ }
682
+ const local = await import("node:fs/promises");
683
+ const { tmpdir } = await import("node:os");
684
+ const { join } = await import("node:path");
685
+ signal?.throwIfAborted();
686
+ const directory = await local.mkdtemp(join(tmpdir(), "tangle-evidence-"));
687
+ try {
688
+ const target = join(directory, "content");
689
+ const receipt = await fs.download(sourcePath, target, { maxBytes, expectedSize, signal });
690
+ signal?.throwIfAborted();
691
+ if (!receipt || receipt.sizeBytes !== expectedSize || !/^[a-f0-9]{64}$/i.test(receipt.sha256)) {
692
+ throw new Error("Tangle evidence binary download omitted its exact size or digest receipt");
693
+ }
694
+ const metadata = await local.stat(target);
695
+ if (!metadata.isFile() || metadata.size !== expectedSize || metadata.size > maxBytes) {
696
+ throw new Error(`Tangle evidence workspace file changed or was truncated: ${sourcePath}`);
697
+ }
698
+ const bytes = await local.readFile(target, { signal });
699
+ if (bytes.byteLength !== expectedSize || bytes.byteLength > maxBytes) {
700
+ throw new Error(`Tangle evidence workspace file changed or was truncated: ${sourcePath}`);
701
+ }
702
+ if (createHash("sha256").update(bytes).digest("hex") !== receipt.sha256.toLowerCase()) {
703
+ throw new Error(`Tangle evidence workspace file hash mismatch: ${sourcePath}`);
704
+ }
705
+ return bytes;
706
+ }
707
+ finally {
708
+ await local.rm(directory, { recursive: true, force: true });
709
+ }
710
+ }
667
711
  /** Keep every source field; store validated binary content once in the archive. */
668
712
  function withoutNativeContent(source) {
669
713
  const metadata = { ...source };
@@ -435,6 +435,16 @@ export interface SandboxInstanceLike {
435
435
  exec?(command: string, options?: unknown): Promise<SandboxExecResult>;
436
436
  fs?: {
437
437
  supportsWriteMode?: true;
438
+ supportsBoundedDownload?: true;
439
+ download?(remotePath: string, localPath: string, options?: {
440
+ overwrite?: boolean;
441
+ maxBytes?: number;
442
+ expectedSize?: number;
443
+ signal?: AbortSignal;
444
+ }): Promise<void | {
445
+ sizeBytes: number;
446
+ sha256: string;
447
+ }>;
438
448
  stat(path: string): Promise<{
439
449
  size: number;
440
450
  isFile: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",