@foldrun/core 23.3.0 → 23.4.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.
@@ -19,6 +19,17 @@ export declare function redactionsFor(secrets: Record<string, string | undefined
19
19
  * bytes alone at each alignment, so the form matches inside a longer
20
20
  * encoding whatever came before or after the value. */
21
21
  export declare function encodedForms(v: string): string[];
22
+ /**
23
+ * Every secret value in `text` → `[redacted:NAME]` (the runner's scrub), and
24
+ * also the piece of one a cut left at an end of the text. A sandbox cuts what
25
+ * it sends (a tool's output, a reply, an error line, the stderr tail) before
26
+ * the host sees it, so a secret on the cut arrives as a prefix at the end
27
+ * (or a suffix at the start), which no whole-value match recognises — and
28
+ * masking first and cutting second cannot help what was cut before it got
29
+ * here. An end that is the start of a value (8+ characters, `EDGE_MIN`) is
30
+ * masked as that value, plain or in any of the encoded forms in the list.
31
+ */
32
+ export declare function scrubWith(redactions: [string, string][], text: string): string;
22
33
  /** Masked, then cut to the cap. */
23
34
  export declare function maskCall(text: string, redactSecrets: (text: string) => string): {
24
35
  text: string;
@@ -129,6 +129,54 @@ export function encodedForms(v) {
129
129
  forms.delete(v);
130
130
  return [...forms].filter((f) => f.length >= 12);
131
131
  }
132
+ /** The shortest piece of a secret that is masked when a cut left only that
133
+ * much of it at an edge of a text. The same floor as a whole secret (8):
134
+ * fewer characters than that is no key. */
135
+ const EDGE_MIN = 8;
136
+ /**
137
+ * Every secret value in `text` → `[redacted:NAME]` (the runner's scrub), and
138
+ * also the piece of one a cut left at an end of the text. A sandbox cuts what
139
+ * it sends (a tool's output, a reply, an error line, the stderr tail) before
140
+ * the host sees it, so a secret on the cut arrives as a prefix at the end
141
+ * (or a suffix at the start), which no whole-value match recognises — and
142
+ * masking first and cutting second cannot help what was cut before it got
143
+ * here. An end that is the start of a value (8+ characters, `EDGE_MIN`) is
144
+ * masked as that value, plain or in any of the encoded forms in the list.
145
+ */
146
+ export function scrubWith(redactions, text) {
147
+ let out = text;
148
+ for (const [value, name] of redactions)
149
+ out = out.split(value).join(`[redacted:${name}]`);
150
+ if (out.length < EDGE_MIN)
151
+ return out;
152
+ for (const [value, name] of redactions) {
153
+ if (value.length <= EDGE_MIN)
154
+ continue;
155
+ const mark = `[redacted:${name}]`;
156
+ // the end of the text begins the value: look only where a piece shorter
157
+ // than the whole value can fit
158
+ const tail = out.slice(-(value.length - 1));
159
+ const head8 = value.slice(0, EDGE_MIN);
160
+ for (let at = tail.indexOf(head8); at >= 0; at = tail.indexOf(head8, at + 1)) {
161
+ if (value.startsWith(tail.slice(at))) {
162
+ out = out.slice(0, out.length - (tail.length - at)) + mark;
163
+ break;
164
+ }
165
+ }
166
+ // the start of the text ends the value
167
+ const lead = out.slice(0, value.length - 1);
168
+ const first8 = lead.slice(0, EDGE_MIN);
169
+ if (first8.length === EDGE_MIN) {
170
+ for (let j = value.indexOf(first8, 1); j >= 0 && value.length - j >= EDGE_MIN; j = value.indexOf(first8, j + 1)) {
171
+ if (out.startsWith(value.slice(j))) {
172
+ out = mark + out.slice(value.length - j);
173
+ break;
174
+ }
175
+ }
176
+ }
177
+ }
178
+ return out;
179
+ }
132
180
  // A private key's whole block — scan.ts names a key header and leaves the
133
181
  // body, which is right for a finding and wrong for a stored output.
134
182
  // Unterminated too: a key cut short, or printed without its END line, is
@@ -57,6 +57,14 @@ export declare const runOutputsOn: () => boolean;
57
57
  * holder, so a re-archive (a resumed run) can pin the new manifest before it
58
58
  * releases the old one. */
59
59
  export declare function outputsHolder(runId: string, agent: string, manifest: ManifestId): PinHolder;
60
+ /** Up to this size a file is read whole (4 lanes at most, so at most 4 x this in
61
+ * memory); past it, it is hashed and uploaded from disk in chunks. */
62
+ export declare const SMALL_OUTPUT_FILE_BYTES: number;
63
+ /** No output is kept past this, whatever `runs.output_file_mb` says (0 = no
64
+ * setting, which is what the backfill uses): the streamed path bounds memory,
65
+ * not time or storage, and a file this big is not an output an agent should
66
+ * leave. Refused as "file-cap", so it is named, never silent. */
67
+ export declare const HARD_OUTPUT_FILE_BYTES: number;
60
68
  export interface PublishedOutputs {
61
69
  record: RunOutputRecord | null;
62
70
  refused: RefusedOutput[];
@@ -96,6 +104,16 @@ export declare function archiveRunOutputs(tenant: string, workspace: string, run
96
104
  /** What a run archived, from the store and from the volume (an agent the store
97
105
  * has wins). Sorted by agent, then path. */
98
106
  export declare function listRunOutputs(tenant: string, workspace: string, runId: string): Promise<RunOutputFile[]>;
107
+ /** What the STORE holds for a run, with each file's hash — the volume is not
108
+ * asked (the backfill's verify compares these to the folder's bytes). */
109
+ export declare function storedRunOutputs(tenant: string, workspace: string, runId: string): Promise<{
110
+ agent: string;
111
+ path: string;
112
+ sha: string;
113
+ size: number;
114
+ }[]>;
115
+ /** The blob is in the store at the size the manifest says (a head, no bytes read). */
116
+ export declare function storedBlobIntact(tenant: string, sha: string, size: number): Promise<boolean>;
99
117
  export interface OpenedOutput {
100
118
  size: number;
101
119
  /** The bytes, or one inclusive range of them. */
@@ -42,7 +42,7 @@ import path from "node:path";
42
42
  import crypto from "node:crypto";
43
43
  import { dataRoot } from "./paths.js";
44
44
  import { processState } from "./process-state.js";
45
- import { BlobNotFound } from "./blob-store.js";
45
+ import { BlobNotFound, fileSource, hashRange } from "./blob-store.js";
46
46
  import { PUBLISH_PIN_TTL_MS, noPins } from "./blob-pins.js";
47
47
  import { MAX_MANIFEST_FILES, MODE_EXEC, MODE_FILE, assertManifest, assertManifestPath, blobObjectKey, canonicalManifest, manifestId, manifestObjectKey, sha256Hex, } from "./manifest.js";
48
48
  import { BlobMissing, loadManifest } from "./publish.js";
@@ -165,6 +165,14 @@ const releaseRecords = async (b, recs) => {
165
165
  // ------------------------------------------------------------------ publishing
166
166
  /** How many files are in flight at once, and so at most this many buffered. */
167
167
  const UPLOAD_CONCURRENCY = 4;
168
+ /** Up to this size a file is read whole (4 lanes at most, so at most 4 x this in
169
+ * memory); past it, it is hashed and uploaded from disk in chunks. */
170
+ export const SMALL_OUTPUT_FILE_BYTES = 8 * 1024 * 1024;
171
+ /** No output is kept past this, whatever `runs.output_file_mb` says (0 = no
172
+ * setting, which is what the backfill uses): the streamed path bounds memory,
173
+ * not time or storage, and a file this big is not an output an agent should
174
+ * leave. Refused as "file-cap", so it is named, never silent. */
175
+ export const HARD_OUTPUT_FILE_BYTES = 32 * 1024 * 1024 * 1024;
168
176
  const MAX_REFUSALS_ON_RECORD = 100;
169
177
  function walk(root) {
170
178
  const out = [];
@@ -194,6 +202,7 @@ function walk(root) {
194
202
  export async function publishRunOutputs(b, tenant, workspace, runId, agent, dir) {
195
203
  safeName(agent, "agent");
196
204
  const fileMax = b.fileMaxBytes();
205
+ const fileCap = fileMax > 0 ? Math.min(fileMax, HARD_OUTPUT_FILE_BYTES) : HARD_OUTPUT_FILE_BYTES;
197
206
  const runMax = b.runMaxBytes();
198
207
  const refused = [];
199
208
  // What the run's other agents already hold counts against the run's cap.
@@ -219,8 +228,8 @@ export async function publishRunOutputs(b, tenant, workspace, runId, agent, dir)
219
228
  refuse("count", MAX_MANIFEST_FILES);
220
229
  continue;
221
230
  }
222
- if (fileMax > 0 && c.size > fileMax) {
223
- refuse("file-cap", fileMax);
231
+ if (c.size > fileCap) {
232
+ refuse("file-cap", fileCap);
224
233
  continue;
225
234
  }
226
235
  if (runMax > 0 && used + c.size > runMax) {
@@ -242,8 +251,10 @@ export async function publishRunOutputs(b, tenant, workspace, runId, agent, dir)
242
251
  let id = null;
243
252
  try {
244
253
  // Pin BEFORE the objects exist: a sweeper that looks now sees the pin.
245
- // Read each file once for its hash (a file can only be named by its
246
- // bytes), then upload; at most UPLOAD_CONCURRENCY buffers are live.
254
+ // A file can only be named by its bytes, so each is hashed first, then
255
+ // uploaded. A small one is read whole (as always); a bigger one is hashed
256
+ // and uploaded from disk in chunks, so at most UPLOAD_CONCURRENCY small
257
+ // buffers (and some 1 MiB chunks) are live, whatever the file's size.
247
258
  let next = 0;
248
259
  const lane = async () => {
249
260
  for (;;) {
@@ -251,17 +262,36 @@ export async function publishRunOutputs(b, tenant, workspace, runId, agent, dir)
251
262
  if (i >= kept.length)
252
263
  return;
253
264
  const c = kept[i];
254
- const body = fs.readFileSync(c.abs);
255
- // Grew since it was measured (an agent still writing): same rule, same cap.
256
- if (fileMax > 0 && body.length > fileMax) {
257
- refused.push({ agent, path: c.rel, bytes: body.length, reason: "file-cap", limit: fileMax });
258
- continue;
265
+ let sha;
266
+ let size;
267
+ if (c.size <= SMALL_OUTPUT_FILE_BYTES) {
268
+ const body = fs.readFileSync(c.abs);
269
+ // Grew since it was measured (an agent still writing): same rule, same cap.
270
+ if (body.length > fileCap) {
271
+ refused.push({ agent, path: c.rel, bytes: body.length, reason: "file-cap", limit: fileCap });
272
+ continue;
273
+ }
274
+ sha = sha256Hex(body);
275
+ size = body.length;
276
+ // Pin each blob before its put; a repeat extends the lease.
277
+ await pins.pinBlobs(tenant, [sha], publishHolder, { ttlMs: PUBLISH_PIN_TTL_MS });
278
+ await b.blobs.putIfAbsent(blobObjectKey(tenant, sha), body);
259
279
  }
260
- const sha = sha256Hex(body);
261
- // Pin each blob before its put; a repeat extends the lease.
262
- await pins.pinBlobs(tenant, [sha], publishHolder, { ttlMs: PUBLISH_PIN_TTL_MS });
263
- await b.blobs.putIfAbsent(blobObjectKey(tenant, sha), body);
264
- files[c.rel] = { sha, size: body.length, mode: c.mode };
280
+ else {
281
+ const source = fileSource(c.abs);
282
+ if (source.size > fileCap) {
283
+ refused.push({ agent, path: c.rel, bytes: source.size, reason: "file-cap", limit: fileCap });
284
+ continue;
285
+ }
286
+ // A file that changes under the read throws BlobSourceError (and the
287
+ // store checks the hash it is given): the publish fails, never stores
288
+ // bytes under a name they do not have.
289
+ sha = (await hashRange(source, 0, source.size)).sha256;
290
+ size = source.size;
291
+ await pins.pinBlobs(tenant, [sha], publishHolder, { ttlMs: PUBLISH_PIN_TTL_MS });
292
+ await b.blobs.putSourceIfAbsent(blobObjectKey(tenant, sha), source, { sha256: sha });
293
+ }
294
+ files[c.rel] = { sha, size, mode: c.mode };
265
295
  }
266
296
  };
267
297
  await Promise.all(Array.from({ length: Math.min(UPLOAD_CONCURRENCY, kept.length) }, lane));
@@ -384,6 +414,26 @@ export async function listRunOutputs(tenant, workspace, runId) {
384
414
  out.push(f);
385
415
  return out.sort((a, b) => a.agent.localeCompare(b.agent) || a.path.localeCompare(b.path));
386
416
  }
417
+ /** What the STORE holds for a run, with each file's hash — the volume is not
418
+ * asked (the backfill's verify compares these to the folder's bytes). */
419
+ export async function storedRunOutputs(tenant, workspace, runId) {
420
+ const out = [];
421
+ if (!OUT.backend)
422
+ return out;
423
+ for (const r of await recordsOf(tenant, workspace, runId)) {
424
+ const m = await loadManifest(readDeps(OUT.backend), tenant, r.manifest);
425
+ for (const [p, e] of Object.entries(m.files))
426
+ out.push({ agent: r.agent, path: p, sha: e.sha, size: e.size });
427
+ }
428
+ return out;
429
+ }
430
+ /** The blob is in the store at the size the manifest says (a head, no bytes read). */
431
+ export async function storedBlobIntact(tenant, sha, size) {
432
+ if (!OUT.backend)
433
+ return false;
434
+ const h = await OUT.backend.blobs.head(blobObjectKey(tenant, sha));
435
+ return !!h && h.size === size;
436
+ }
387
437
  /** One archived output, or null when the name escapes the archive or names
388
438
  * nothing — the API serves only what this returns. */
389
439
  export async function openRunOutput(tenant, workspace, runId, agent, rel) {
@@ -5,7 +5,7 @@
5
5
  import { opsLog, opsError } from "./ops-log.js";
6
6
  import { globMatch } from "./bounded-match.js";
7
7
  import { latestRevisionId } from "./history.js";
8
- import { recordCallIo, redactionsFor } from "./capture.js";
8
+ import { recordCallIo, redactionsFor, scrubWith } from "./capture.js";
9
9
  import { callSink, flushCalls } from "./captured-calls.js";
10
10
  import { AUTH_REFUSAL, platformCause } from "./issues.js";
11
11
  import { hookNames } from "./hooks.js";
@@ -2099,12 +2099,7 @@ conversation) {
2099
2099
  // read; the verdict at the end of this function reads it.
2100
2100
  let canActOutward = false;
2101
2101
  const eventsAtStart = step.events.length;
2102
- const redact = (text) => {
2103
- let out = text;
2104
- for (const [value, name] of redactions)
2105
- out = out.split(value).join(`[redacted:${name}]`);
2106
- return out;
2107
- };
2102
+ const redact = (text) => scrubWith(redactions, text);
2108
2103
  // The reply, the conclusion and an `output: json` value land on the same
2109
2104
  // record the events do, and a model that quotes a script's stdout puts
2110
2105
  // the credential in its answer rather than in a tool event. Same scrub,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "23.3.0",
3
+ "version": "23.4.0",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
package/src/capture.ts CHANGED
@@ -122,6 +122,53 @@ export function encodedForms(v: string): string[] {
122
122
  return [...forms].filter((f) => f.length >= 12);
123
123
  }
124
124
 
125
+ /** The shortest piece of a secret that is masked when a cut left only that
126
+ * much of it at an edge of a text. The same floor as a whole secret (8):
127
+ * fewer characters than that is no key. */
128
+ const EDGE_MIN = 8;
129
+
130
+ /**
131
+ * Every secret value in `text` → `[redacted:NAME]` (the runner's scrub), and
132
+ * also the piece of one a cut left at an end of the text. A sandbox cuts what
133
+ * it sends (a tool's output, a reply, an error line, the stderr tail) before
134
+ * the host sees it, so a secret on the cut arrives as a prefix at the end
135
+ * (or a suffix at the start), which no whole-value match recognises — and
136
+ * masking first and cutting second cannot help what was cut before it got
137
+ * here. An end that is the start of a value (8+ characters, `EDGE_MIN`) is
138
+ * masked as that value, plain or in any of the encoded forms in the list.
139
+ */
140
+ export function scrubWith(redactions: [string, string][], text: string): string {
141
+ let out = text;
142
+ for (const [value, name] of redactions) out = out.split(value).join(`[redacted:${name}]`);
143
+ if (out.length < EDGE_MIN) return out;
144
+ for (const [value, name] of redactions) {
145
+ if (value.length <= EDGE_MIN) continue;
146
+ const mark = `[redacted:${name}]`;
147
+ // the end of the text begins the value: look only where a piece shorter
148
+ // than the whole value can fit
149
+ const tail = out.slice(-(value.length - 1));
150
+ const head8 = value.slice(0, EDGE_MIN);
151
+ for (let at = tail.indexOf(head8); at >= 0; at = tail.indexOf(head8, at + 1)) {
152
+ if (value.startsWith(tail.slice(at))) {
153
+ out = out.slice(0, out.length - (tail.length - at)) + mark;
154
+ break;
155
+ }
156
+ }
157
+ // the start of the text ends the value
158
+ const lead = out.slice(0, value.length - 1);
159
+ const first8 = lead.slice(0, EDGE_MIN);
160
+ if (first8.length === EDGE_MIN) {
161
+ for (let j = value.indexOf(first8, 1); j >= 0 && value.length - j >= EDGE_MIN; j = value.indexOf(first8, j + 1)) {
162
+ if (out.startsWith(value.slice(j))) {
163
+ out = mark + out.slice(value.length - j);
164
+ break;
165
+ }
166
+ }
167
+ }
168
+ }
169
+ return out;
170
+ }
171
+
125
172
  // A private key's whole block — scan.ts names a key header and leaves the
126
173
  // body, which is right for a finding and wrong for a stored output.
127
174
  // Unterminated too: a key cut short, or printed without its END line, is
@@ -43,7 +43,7 @@ import path from "node:path";
43
43
  import crypto from "node:crypto";
44
44
  import { dataRoot } from "./paths.ts";
45
45
  import { processState } from "./process-state.ts";
46
- import { BlobNotFound, type BlobStore } from "./blob-store.ts";
46
+ import { BlobNotFound, fileSource, hashRange, type BlobStore } from "./blob-store.ts";
47
47
  import { PUBLISH_PIN_TTL_MS, noPins, type BlobPins, type PinHolder } from "./blob-pins.ts";
48
48
  import {
49
49
  MAX_MANIFEST_FILES,
@@ -222,6 +222,14 @@ const releaseRecords = async (b: RunOutputsBackend, recs: readonly RunOutputReco
222
222
 
223
223
  /** How many files are in flight at once, and so at most this many buffered. */
224
224
  const UPLOAD_CONCURRENCY = 4;
225
+ /** Up to this size a file is read whole (4 lanes at most, so at most 4 x this in
226
+ * memory); past it, it is hashed and uploaded from disk in chunks. */
227
+ export const SMALL_OUTPUT_FILE_BYTES = 8 * 1024 * 1024;
228
+ /** No output is kept past this, whatever `runs.output_file_mb` says (0 = no
229
+ * setting, which is what the backfill uses): the streamed path bounds memory,
230
+ * not time or storage, and a file this big is not an output an agent should
231
+ * leave. Refused as "file-cap", so it is named, never silent. */
232
+ export const HARD_OUTPUT_FILE_BYTES = 32 * 1024 * 1024 * 1024;
225
233
  const MAX_REFUSALS_ON_RECORD = 100;
226
234
 
227
235
  interface Candidate {
@@ -271,6 +279,7 @@ export async function publishRunOutputs(
271
279
  ): Promise<PublishedOutputs> {
272
280
  safeName(agent, "agent");
273
281
  const fileMax = b.fileMaxBytes();
282
+ const fileCap = fileMax > 0 ? Math.min(fileMax, HARD_OUTPUT_FILE_BYTES) : HARD_OUTPUT_FILE_BYTES;
274
283
  const runMax = b.runMaxBytes();
275
284
  const refused: RefusedOutput[] = [];
276
285
  // What the run's other agents already hold counts against the run's cap.
@@ -296,8 +305,8 @@ export async function publishRunOutputs(
296
305
  refuse("count", MAX_MANIFEST_FILES);
297
306
  continue;
298
307
  }
299
- if (fileMax > 0 && c.size > fileMax) {
300
- refuse("file-cap", fileMax);
308
+ if (c.size > fileCap) {
309
+ refuse("file-cap", fileCap);
301
310
  continue;
302
311
  }
303
312
  if (runMax > 0 && used + c.size > runMax) {
@@ -319,25 +328,45 @@ export async function publishRunOutputs(
319
328
  let id: ManifestId | null = null;
320
329
  try {
321
330
  // Pin BEFORE the objects exist: a sweeper that looks now sees the pin.
322
- // Read each file once for its hash (a file can only be named by its
323
- // bytes), then upload; at most UPLOAD_CONCURRENCY buffers are live.
331
+ // A file can only be named by its bytes, so each is hashed first, then
332
+ // uploaded. A small one is read whole (as always); a bigger one is hashed
333
+ // and uploaded from disk in chunks, so at most UPLOAD_CONCURRENCY small
334
+ // buffers (and some 1 MiB chunks) are live, whatever the file's size.
324
335
  let next = 0;
325
336
  const lane = async () => {
326
337
  for (;;) {
327
338
  const i = next++;
328
339
  if (i >= kept.length) return;
329
340
  const c = kept[i];
330
- const body = fs.readFileSync(c.abs);
331
- // Grew since it was measured (an agent still writing): same rule, same cap.
332
- if (fileMax > 0 && body.length > fileMax) {
333
- refused.push({ agent, path: c.rel, bytes: body.length, reason: "file-cap", limit: fileMax });
334
- continue;
341
+ let sha: string;
342
+ let size: number;
343
+ if (c.size <= SMALL_OUTPUT_FILE_BYTES) {
344
+ const body = fs.readFileSync(c.abs);
345
+ // Grew since it was measured (an agent still writing): same rule, same cap.
346
+ if (body.length > fileCap) {
347
+ refused.push({ agent, path: c.rel, bytes: body.length, reason: "file-cap", limit: fileCap });
348
+ continue;
349
+ }
350
+ sha = sha256Hex(body);
351
+ size = body.length;
352
+ // Pin each blob before its put; a repeat extends the lease.
353
+ await pins.pinBlobs(tenant, [sha], publishHolder, { ttlMs: PUBLISH_PIN_TTL_MS });
354
+ await b.blobs.putIfAbsent(blobObjectKey(tenant, sha), body);
355
+ } else {
356
+ const source = fileSource(c.abs);
357
+ if (source.size > fileCap) {
358
+ refused.push({ agent, path: c.rel, bytes: source.size, reason: "file-cap", limit: fileCap });
359
+ continue;
360
+ }
361
+ // A file that changes under the read throws BlobSourceError (and the
362
+ // store checks the hash it is given): the publish fails, never stores
363
+ // bytes under a name they do not have.
364
+ sha = (await hashRange(source, 0, source.size)).sha256;
365
+ size = source.size;
366
+ await pins.pinBlobs(tenant, [sha], publishHolder, { ttlMs: PUBLISH_PIN_TTL_MS });
367
+ await b.blobs.putSourceIfAbsent(blobObjectKey(tenant, sha), source, { sha256: sha });
335
368
  }
336
- const sha = sha256Hex(body);
337
- // Pin each blob before its put; a repeat extends the lease.
338
- await pins.pinBlobs(tenant, [sha], publishHolder, { ttlMs: PUBLISH_PIN_TTL_MS });
339
- await b.blobs.putIfAbsent(blobObjectKey(tenant, sha), body);
340
- files[c.rel] = { sha, size: body.length, mode: c.mode };
369
+ files[c.rel] = { sha, size, mode: c.mode };
341
370
  }
342
371
  };
343
372
  await Promise.all(Array.from({ length: Math.min(UPLOAD_CONCURRENCY, kept.length) }, lane));
@@ -462,6 +491,25 @@ export async function listRunOutputs(tenant: string, workspace: string, runId: s
462
491
  return out.sort((a, b) => a.agent.localeCompare(b.agent) || a.path.localeCompare(b.path));
463
492
  }
464
493
 
494
+ /** What the STORE holds for a run, with each file's hash — the volume is not
495
+ * asked (the backfill's verify compares these to the folder's bytes). */
496
+ export async function storedRunOutputs(tenant: string, workspace: string, runId: string): Promise<{ agent: string; path: string; sha: string; size: number }[]> {
497
+ const out: { agent: string; path: string; sha: string; size: number }[] = [];
498
+ if (!OUT.backend) return out;
499
+ for (const r of await recordsOf(tenant, workspace, runId)) {
500
+ const m = await loadManifest(readDeps(OUT.backend), tenant, r.manifest);
501
+ for (const [p, e] of Object.entries(m.files)) out.push({ agent: r.agent, path: p, sha: e.sha, size: e.size });
502
+ }
503
+ return out;
504
+ }
505
+
506
+ /** The blob is in the store at the size the manifest says (a head, no bytes read). */
507
+ export async function storedBlobIntact(tenant: string, sha: string, size: number): Promise<boolean> {
508
+ if (!OUT.backend) return false;
509
+ const h = await OUT.backend.blobs.head(blobObjectKey(tenant, sha));
510
+ return !!h && h.size === size;
511
+ }
512
+
465
513
  export interface OpenedOutput {
466
514
  size: number;
467
515
  /** The bytes, or one inclusive range of them. */
package/src/runner.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  import { opsLog, opsError } from "./ops-log.ts";
7
7
  import { globMatch } from "./bounded-match.ts";
8
8
  import { latestRevisionId } from "./history.ts";
9
- import { recordCallIo, redactionsFor } from "./capture.ts";
9
+ import { recordCallIo, redactionsFor, scrubWith } from "./capture.ts";
10
10
  import { callSink, flushCalls } from "./captured-calls.ts";
11
11
  import { AUTH_REFUSAL, platformCause } from "./issues.ts";
12
12
  import { hookNames } from "./hooks.ts";
@@ -2292,11 +2292,7 @@ async function runStepBody(
2292
2292
  // read; the verdict at the end of this function reads it.
2293
2293
  let canActOutward = false;
2294
2294
  const eventsAtStart = step.events.length;
2295
- const redact = (text: string) => {
2296
- let out = text;
2297
- for (const [value, name] of redactions) out = out.split(value).join(`[redacted:${name}]`);
2298
- return out;
2299
- };
2295
+ const redact = (text: string) => scrubWith(redactions, text);
2300
2296
 
2301
2297
  // The reply, the conclusion and an `output: json` value land on the same
2302
2298
  // record the events do, and a model that quotes a script's stdout puts