@foldrun/core 18.2.0 → 18.3.1

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.
@@ -22,6 +22,7 @@
22
22
  // exchanges text and JSON only, and a URL in a reply is not an invitation.
23
23
  //
24
24
  // No vault, no MCP: values in, values out. a2a-tools.ts is the agent's side.
25
+ import { spellingJoiners } from "./joiners.js";
25
26
  import crypto from "node:crypto";
26
27
  import { viaEgress } from "./egress.js";
27
28
  import { capBody, ResponseTooLarge } from "./untrusted-fetch.js";
@@ -101,7 +102,12 @@ const HIDDEN = /[​-‏‪-‮⁠-⁤⁦-⁩\u0000-\u0008\u000B\u000C\u000E-
101
102
  /** `text` with hidden characters removed, and how many there were. */
102
103
  export function stripHidden(text) {
103
104
  let removed = 0;
104
- const out = text.replace(HIDDEN, () => {
105
+ // A joiner that is spelling (a Persian half-space, an Indic or emoji
106
+ // joiner — joiners.ts) stays: removing it misspells the word.
107
+ const spelling = spellingJoiners(text);
108
+ const out = text.replace(HIDDEN, (m, at) => {
109
+ if (spelling.has(at))
110
+ return m;
105
111
  removed++;
106
112
  return "";
107
113
  });
@@ -0,0 +1,2 @@
1
+ /** The indices (UTF-16) of every joiner in `text` that is spelling, not hiding. */
2
+ export declare function spellingJoiners(text: string): Set<number>;
@@ -0,0 +1,35 @@
1
+ // ZWNJ (U+200C) and ZWJ (U+200D) are invisible, and they are also spelling.
2
+ //
3
+ // In Persian the half-space is how a word is written: «کانال‌ها», «می‌شود».
4
+ // Arabic-script, Syriac, Thaana and N'Ko, and the Indic and other Brahmic
5
+ // scripts, use both joiners inside words. An emoji sequence (👨‍💻, 🏳️‍🌈) is
6
+ // glued with ZWJ. Flagging those as hidden text (scan.ts
7
+ // content/hidden-unicode) buried real findings under hundreds of false ones
8
+ // on a Persian workspace (cloudhost, 11 Nov 2026), and stripping them from an
9
+ // outside agent's reply (a2a-client.ts) misspelled every such word.
10
+ //
11
+ // So a joiner is spelling when it sits INSIDE a word of a script that uses
12
+ // joiners — a letter or mark of one on BOTH sides — or between two emoji.
13
+ // Anywhere else (between Latin letters, at a word's edge, alone) it is still
14
+ // hidden text. Every other invisible character (zero-width space, bidi
15
+ // overrides and isolates, word joiner, BOM, Unicode tags) is never spelling.
16
+ const JOINER_SCRIPTS = [
17
+ "Arabic", "Syriac", "Thaana", "Nko",
18
+ "Devanagari", "Bengali", "Gurmukhi", "Gujarati", "Oriya", "Tamil", "Telugu", "Kannada", "Malayalam", "Sinhala",
19
+ "Tibetan", "Myanmar", "Khmer", "Mongolian",
20
+ ];
21
+ const LETTER = `(?:${JOINER_SCRIPTS.map((s) => `[\\p{scx=${s}}&&[\\p{L}\\p{M}]]`).join("|")})`;
22
+ /** A ZWNJ or ZWJ with a letter or mark of a joining script on each side. */
23
+ const IN_WORD = new RegExp(`(?<=${LETTER})[\\u200C\\u200D](?=${LETTER})`, "gv");
24
+ /** A ZWJ between two emoji (a skin tone or VS16 may follow the first). */
25
+ const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)‍(?=\p{Extended_Pictographic})/gu;
26
+ /** The indices (UTF-16) of every joiner in `text` that is spelling, not hiding. */
27
+ export function spellingJoiners(text) {
28
+ const at = new Set();
29
+ if (!/[‌‍]/.test(text))
30
+ return at;
31
+ for (const re of [IN_WORD, IN_EMOJI])
32
+ for (const m of text.matchAll(re))
33
+ at.add(m.index);
34
+ return at;
35
+ }
@@ -163,6 +163,11 @@ export interface PlatformHooks {
163
163
  * trace as not enforced.
164
164
  */
165
165
  confinesBrowsing?(isolation: string): boolean;
166
+ /** Can this executor run a snapshot step (RunInContainerArgs.snapshot:
167
+ * stage the folder, give back outputs/ alone, make the patch)? A run with a
168
+ * snapshot on any executor that cannot fails before anything starts.
169
+ * Default: none can. */
170
+ holdsSnapshot?(isolation: string): boolean;
166
171
  /**
167
172
  * Does this isolation mode wall a step whose `network:` is restricted and
168
173
  * enforced to the egress proxy alone (a `filtered` pod)? True: such a
@@ -279,6 +279,10 @@ export declare const APPLY_MTIMES_JS: string;
279
279
  */
280
280
  export declare function mergeAppends(was: Buffer | string | null, host: Buffer, next: Buffer): Buffer | null;
281
281
  export interface ApplyOptions {
282
+ /** Take back only what is under this workspace-relative folder (with its
283
+ * trailing `/`) — a snapshot run's outputs (Part B3): the folder it was
284
+ * given, and anything it copied anywhere else, never reach the workspace. */
285
+ keepOnly?: string;
282
286
  /** What the host handed back into this sandbox mid-step — a `sandbox: own`
283
287
  * job's files (delegate-tools.ts), path → sha256 — as the HOST recorded
284
288
  * it (StepRecord.handedBack). The sandbox's own note of the same is only
@@ -576,6 +580,14 @@ export declare function dockerCpus(cpus: string, available?: number): string | n
576
580
  export declare function heldCores(cpus: string, isolation: string | undefined, available?: number): number;
577
581
  export interface RunInContainerArgs {
578
582
  workspaceRoot: string;
583
+ /** A snapshot run (Part B3): the folder a person sent, by id, for this
584
+ * step to work on. Only an executor that says it can (`supportsSnapshot`
585
+ * on its IsolatedStepRunner) is ever given one: it stages the folder at
586
+ * agents/<name>/snapshot/, takes back only that agent's outputs/, and
587
+ * leaves the patch there as outputs/snapshot.patch. */
588
+ snapshot?: {
589
+ id: string;
590
+ };
579
591
  /** A person approved this step before it ran: configuration and code it
580
592
  * changed are kept, not refused (copy-back.ts, FOL-96). */
581
593
  configWrites?: boolean;
@@ -365,11 +365,17 @@ export function applyContainerChanges(hostWs, containerWs, baseline, note, diver
365
365
  // (kubectl cp already skips symlinks; this makes the two tiers agree.)
366
366
  if (entry.isSymbolicLink())
367
367
  continue;
368
+ const posix = rel.replaceAll("\\", "/");
368
369
  if (entry.isDirectory()) {
370
+ const d = posix + "/";
371
+ if (opts.keepOnly && !(d.startsWith(opts.keepOnly) || opts.keepOnly.startsWith(d)))
372
+ continue;
369
373
  if (allowedBack(rel + "/"))
370
374
  walk(abs);
371
375
  continue;
372
376
  }
377
+ if (opts.keepOnly && !posix.startsWith(opts.keepOnly))
378
+ continue;
373
379
  if (!allowedBack(rel))
374
380
  continue;
375
381
  let next = fs.readFileSync(abs);
@@ -592,7 +592,10 @@ export declare function createFlowRun(tenant: string, workspace: string, steps:
592
592
  a2a?: {
593
593
  task: string;
594
594
  key: string;
595
- }): RunRecord;
595
+ },
596
+ /** A snapshot run's folder (Part B3): the id POST …/snapshots answered.
597
+ * Its own trailing argument, as a2a is, so the signature only widened. */
598
+ snapshot?: string): RunRecord;
596
599
  export declare function startFlowRun(tenant: string, workspace: string, steps: FlowStep[], flowName: string, modelOverride?: string | null, tags?: string[], effortOverride?: string | null, startedBy?: string | null, opts?: {
597
600
  test?: boolean;
598
601
  }): RunRecord;
@@ -388,6 +388,11 @@ export function readAgentsMd(dir) {
388
388
  return null;
389
389
  }
390
390
  const workspaceRootOf = (agentDir) => path.join(agentDir, "..", "..");
391
+ /** What a snapshot step is told (Part B3). */
392
+ const SNAPSHOT_NOTE = "The folder you were sent to work on is in snapshot/ (inside your working directory). Make your changes there, as files: " +
393
+ "when you finish, foldrun turns what changed in snapshot/ into a patch the person applies. " +
394
+ "Only snapshot/ (as that patch) and your outputs/ come back from this step; anything you write elsewhere is not kept. " +
395
+ "Do not create links or a .git folder in snapshot/ — links make the patch refused, and .git is left out.";
391
396
  /**
392
397
  * Configuration from AGENTS.md, nearest-wins: the workspace's overrides the
393
398
  * account's, key by key.
@@ -2704,6 +2709,17 @@ mayDefer) {
2704
2709
  if (stepHookNames.length)
2705
2710
  push("info", `hooks: ${stepHookNames.join(", ")}`);
2706
2711
  const isolation = process.env.FOLDRUN_RUN_ISOLATION;
2712
+ // A snapshot run (Part B3): the folder is on the run record, set when the
2713
+ // run was made. Only an executor that says it can hold one may run it —
2714
+ // in-process, the step would work in the real workspace folder, and no
2715
+ // copy-back stands between what it writes and the workspace (Codex).
2716
+ const snapshotId = runId ? readRun(tenant, path.basename(workspaceRootOf(agentDir)), runId)?.snapshot?.id : undefined;
2717
+ if (snapshotId) {
2718
+ const able = isolatedRun() && isolation !== "container" && Boolean(platform.isolation[isolation]) && platform.holdsSnapshot?.(isolation) === true;
2719
+ if (!able) {
2720
+ throw new Error("this run has a snapshot (a folder sent to work on), and this install cannot hold one: it needs the k8s sandbox (FOLDRUN_RUN_ISOLATION=k8s). Nothing was run.");
2721
+ }
2722
+ }
2707
2723
  if (isolatedRun()) {
2708
2724
  // The isolated path: the whole loop — model, built-in tools, scripts —
2709
2725
  // runs inside a throwaway container (a docker sibling, or a pod), and
@@ -3077,6 +3093,7 @@ mayDefer) {
3077
3093
  const runIsolated = isolation === "container" ? runStepInContainer : platform.isolation[isolation];
3078
3094
  const isolatedArgs = (modelEnv, keyName = MODEL_KEY_NAME) => ({
3079
3095
  workspaceRoot,
3096
+ ...(snapshotId ? { snapshot: { id: snapshotId } } : {}),
3080
3097
  libraryRoot: libraryDir(tenant),
3081
3098
  galleryRoot: platform.galleryDir() ?? undefined,
3082
3099
  // Keys this step's dependency cache. Per-account by design — see
@@ -3086,7 +3103,8 @@ mayDefer) {
3086
3103
  agentRel: path.relative(workspaceRoot, agentDir).replaceAll("\\", "/"),
3087
3104
  // Its file tools inside the sandbox get the same allowance (FOL-96).
3088
3105
  configWrites: step.approve === true && Boolean(step.approvedAt),
3089
- prompt,
3106
+ // A snapshot step is told where its folder is, and what comes back.
3107
+ prompt: snapshotId ? `${prompt}\n\n${SNAPSHOT_NOTE}` : prompt,
3090
3108
  model,
3091
3109
  effort,
3092
3110
  systemPrompt,
@@ -4285,7 +4303,10 @@ export function readSchemaFile(workspaceRoot, rel) {
4285
4303
  export function createFlowRun(tenant, workspace, steps, flowName, status, tags = [], startedBy = null, opts = {},
4286
4304
  /** An A2A task's correlation (foldrun-platform flow-admission.ts) — its
4287
4305
  * own trailing argument, so the signature only widened. */
4288
- a2a) {
4306
+ a2a,
4307
+ /** A snapshot run's folder (Part B3): the id POST …/snapshots answered.
4308
+ * Its own trailing argument, as a2a is, so the signature only widened. */
4309
+ snapshot) {
4289
4310
  let flowMaxOut;
4290
4311
  try {
4291
4312
  flowMaxOut = readFlow(tenant, workspace, flowName)?.maxOutputTokens;
@@ -4302,6 +4323,7 @@ a2a) {
4302
4323
  ...(opts.test ? { test: true } : {}),
4303
4324
  // An outside agent asked, over A2A: the task it serves, and whose key.
4304
4325
  ...(a2a ? { trigger: "a2a", a2a: { task: a2a.task, key: a2a.key } } : {}),
4326
+ ...(snapshot ? { snapshot: { id: snapshot } } : {}),
4305
4327
  startedAt: new Date().toISOString(),
4306
4328
  finishedAt: null,
4307
4329
  steps: steps.map((s) => ({
package/dist/src/scan.js CHANGED
@@ -25,6 +25,7 @@
25
25
  // or `foldrun-ignore-file <rule>: <reason>` anywhere in a file for all of it.
26
26
  // The reason is required: an ignore without one ignores nothing and is itself
27
27
  // reported, because "why is this allowed?" is the question a reviewer asks.
28
+ import { spellingJoiners } from "./joiners.js";
28
29
  import crypto from "node:crypto";
29
30
  import matter, { frontmatterErrorLine, frontmatterErrorText, parseLenient, configMatter } from "./matter.js";
30
31
  import { refNames } from "./refs.js";
@@ -388,6 +389,9 @@ const SECRET_SHAPES = [
388
389
  [/\bnpm_[A-Za-z0-9]{36}\b/g, "an npm token"],
389
390
  [/\bhf_[A-Za-z0-9]{34,}\b/g, "a Hugging Face token"],
390
391
  [/\blin_api_[A-Za-z0-9]{40}\b/g, "a Linear key"],
392
+ // foldrun's own (FOL-154): API, gateway, A2A and deploy keys, and the
393
+ // prefixes before them. 48 hex: the exact shape minted, never `fr_api_…`.
394
+ [/\b(?:fr_(?:api|gw|a2a|dep)|md[ak])_[0-9a-f]{48}\b/g, "a foldrun key"],
391
395
  [/\bdop_v1_[a-f0-9]{64}\b/g, "a DigitalOcean token"],
392
396
  [/\bshp(?:at|ca|pa|ss)_[a-fA-F0-9]{32}\b/g, "a Shopify token"],
393
397
  [/\bre_[A-Za-z0-9]{8,}_[A-Za-z0-9]{16,}\b/g, "a Resend key"],
@@ -563,10 +567,14 @@ function scanContent(file, lines, push, untrusted = false) {
563
567
  const line = i === 0 ? lines[i].replace(/^/, "") : lines[i];
564
568
  if (!untrusted && /^\s*(?:```|~~~)/.test(line))
565
569
  fenced = !fenced;
566
- HIDDEN.lastIndex = 0;
567
- if (HIDDEN.test(line)) {
568
- const kind = HIDDEN_NAMES.find(([re]) => re.test(line))?.[1] ?? "invisible characters";
569
- const n = line.match(HIDDEN)?.length ?? 0;
570
+ // A half-space inside a Persian word, a joiner in an Indic word or an
571
+ // emoji sequence is spelling, not hiding (joiners.ts): not counted.
572
+ const spelling = spellingJoiners(line);
573
+ const hits = [...line.matchAll(HIDDEN)].filter((m) => !spelling.has(m.index));
574
+ if (hits.length) {
575
+ const found = hits.map((m) => m[0]).join("");
576
+ const kind = HIDDEN_NAMES.find(([re]) => re.test(found))?.[1] ?? "invisible characters";
577
+ const n = hits.length;
570
578
  const tagged = /\uDB40[\uDC00-\uDC7F]/.test(line) ? ` that read as: "${decodeTags(line).slice(0, 80)}"` : "";
571
579
  push("content/hidden-unicode", file.path, i + 1, line, `${n} ${kind}${redactText(tagged)} — invisible to a reviewer, read by the model`);
572
580
  }
@@ -50,6 +50,10 @@ export function snapshotPathProblem(p) {
50
50
  return `a path deeper than ${MAX_DEPTH} folders`;
51
51
  if (parts.some((s) => s === "" || s === "." || s === ".."))
52
52
  return "an empty, `.` or `..` segment";
53
+ // The files, never a repository: a `.git` sent in could become git's own
54
+ // configuration (hooks, fsmonitor) wherever git later reads the folder.
55
+ if (parts.some((s) => s.toLowerCase() === ".git"))
56
+ return "a `.git` folder or file — send the files, not the repository";
53
57
  return null;
54
58
  }
55
59
  /**
@@ -1635,6 +1635,13 @@ export interface RunRecord {
1635
1635
  task: string;
1636
1636
  key: string;
1637
1637
  };
1638
+ /** A snapshot run (Part B3): the folder a person sent (its sha256), staged
1639
+ * for the step at agents/<name>/snapshot/; the patch of what the step
1640
+ * changed is outputs/snapshot.patch. Set when the run is made, never by a
1641
+ * step. */
1642
+ snapshot?: {
1643
+ id: string;
1644
+ };
1638
1645
  steps: StepRecord[];
1639
1646
  }
1640
1647
  /** Merge one part (the input, on the call; the output, on its completion)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "18.2.0",
3
+ "version": "18.3.1",
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/a2a-client.ts CHANGED
@@ -23,6 +23,7 @@
23
23
  //
24
24
  // No vault, no MCP: values in, values out. a2a-tools.ts is the agent's side.
25
25
 
26
+ import { spellingJoiners } from "./joiners.ts";
26
27
  import crypto from "node:crypto";
27
28
  import { viaEgress } from "./egress.ts";
28
29
  import { capBody, ResponseTooLarge } from "./untrusted-fetch.ts";
@@ -168,7 +169,11 @@ const HIDDEN = /[​-‏‪-‮⁠-⁤⁦-⁩\u0000-\u0008\u000B\u000C\u000E-
168
169
  /** `text` with hidden characters removed, and how many there were. */
169
170
  export function stripHidden(text: string): { text: string; removed: number } {
170
171
  let removed = 0;
171
- const out = text.replace(HIDDEN, () => {
172
+ // A joiner that is spelling (a Persian half-space, an Indic or emoji
173
+ // joiner — joiners.ts) stays: removing it misspells the word.
174
+ const spelling = spellingJoiners(text);
175
+ const out = text.replace(HIDDEN, (m: string, at: number) => {
176
+ if (spelling.has(at)) return m;
172
177
  removed++;
173
178
  return "";
174
179
  });
package/src/joiners.ts ADDED
@@ -0,0 +1,35 @@
1
+ // ZWNJ (U+200C) and ZWJ (U+200D) are invisible, and they are also spelling.
2
+ //
3
+ // In Persian the half-space is how a word is written: «کانال‌ها», «می‌شود».
4
+ // Arabic-script, Syriac, Thaana and N'Ko, and the Indic and other Brahmic
5
+ // scripts, use both joiners inside words. An emoji sequence (👨‍💻, 🏳️‍🌈) is
6
+ // glued with ZWJ. Flagging those as hidden text (scan.ts
7
+ // content/hidden-unicode) buried real findings under hundreds of false ones
8
+ // on a Persian workspace (cloudhost, 11 Nov 2026), and stripping them from an
9
+ // outside agent's reply (a2a-client.ts) misspelled every such word.
10
+ //
11
+ // So a joiner is spelling when it sits INSIDE a word of a script that uses
12
+ // joiners — a letter or mark of one on BOTH sides — or between two emoji.
13
+ // Anywhere else (between Latin letters, at a word's edge, alone) it is still
14
+ // hidden text. Every other invisible character (zero-width space, bidi
15
+ // overrides and isolates, word joiner, BOM, Unicode tags) is never spelling.
16
+
17
+ const JOINER_SCRIPTS = [
18
+ "Arabic", "Syriac", "Thaana", "Nko",
19
+ "Devanagari", "Bengali", "Gurmukhi", "Gujarati", "Oriya", "Tamil", "Telugu", "Kannada", "Malayalam", "Sinhala",
20
+ "Tibetan", "Myanmar", "Khmer", "Mongolian",
21
+ ];
22
+ const LETTER = `(?:${JOINER_SCRIPTS.map((s) => `[\\p{scx=${s}}&&[\\p{L}\\p{M}]]`).join("|")})`;
23
+
24
+ /** A ZWNJ or ZWJ with a letter or mark of a joining script on each side. */
25
+ const IN_WORD = new RegExp(`(?<=${LETTER})[\\u200C\\u200D](?=${LETTER})`, "gv");
26
+ /** A ZWJ between two emoji (a skin tone or VS16 may follow the first). */
27
+ const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)‍(?=\p{Extended_Pictographic})/gu;
28
+
29
+ /** The indices (UTF-16) of every joiner in `text` that is spelling, not hiding. */
30
+ export function spellingJoiners(text: string): Set<number> {
31
+ const at = new Set<number>();
32
+ if (!/[‌‍]/.test(text)) return at;
33
+ for (const re of [IN_WORD, IN_EMOJI]) for (const m of text.matchAll(re)) at.add(m.index!);
34
+ return at;
35
+ }
package/src/platform.ts CHANGED
@@ -168,6 +168,11 @@ export interface PlatformHooks {
168
168
  * trace as not enforced.
169
169
  */
170
170
  confinesBrowsing?(isolation: string): boolean;
171
+ /** Can this executor run a snapshot step (RunInContainerArgs.snapshot:
172
+ * stage the folder, give back outputs/ alone, make the patch)? A run with a
173
+ * snapshot on any executor that cannot fails before anything starts.
174
+ * Default: none can. */
175
+ holdsSnapshot?(isolation: string): boolean;
171
176
  /**
172
177
  * Does this isolation mode wall a step whose `network:` is restricted and
173
178
  * enforced to the egress proxy alone (a `filtered` pod)? True: such a
@@ -482,6 +482,10 @@ export function mergeAppends(was: Buffer | string | null, host: Buffer, next: Bu
482
482
  }
483
483
 
484
484
  export interface ApplyOptions {
485
+ /** Take back only what is under this workspace-relative folder (with its
486
+ * trailing `/`) — a snapshot run's outputs (Part B3): the folder it was
487
+ * given, and anything it copied anywhere else, never reach the workspace. */
488
+ keepOnly?: string;
485
489
  /** What the host handed back into this sandbox mid-step — a `sandbox: own`
486
490
  * job's files (delegate-tools.ts), path → sha256 — as the HOST recorded
487
491
  * it (StepRecord.handedBack). The sandbox's own note of the same is only
@@ -552,10 +556,14 @@ export function applyContainerChanges(
552
556
  // A link to a directory threw EISDIR and aborted the whole copy-out.
553
557
  // (kubectl cp already skips symlinks; this makes the two tiers agree.)
554
558
  if (entry.isSymbolicLink()) continue;
559
+ const posix = rel.replaceAll("\\", "/");
555
560
  if (entry.isDirectory()) {
561
+ const d = posix + "/";
562
+ if (opts.keepOnly && !(d.startsWith(opts.keepOnly) || opts.keepOnly.startsWith(d))) continue;
556
563
  if (allowedBack(rel + "/")) walk(abs);
557
564
  continue;
558
565
  }
566
+ if (opts.keepOnly && !posix.startsWith(opts.keepOnly)) continue;
559
567
  if (!allowedBack(rel)) continue;
560
568
  let next: Buffer = fs.readFileSync(abs);
561
569
  // What the step was handed: its bytes (a staging dir) or its hash.
@@ -1861,6 +1869,12 @@ export function heldCores(cpus: string, isolation: string | undefined, available
1861
1869
 
1862
1870
  export interface RunInContainerArgs {
1863
1871
  workspaceRoot: string;
1872
+ /** A snapshot run (Part B3): the folder a person sent, by id, for this
1873
+ * step to work on. Only an executor that says it can (`supportsSnapshot`
1874
+ * on its IsolatedStepRunner) is ever given one: it stages the folder at
1875
+ * agents/<name>/snapshot/, takes back only that agent's outputs/, and
1876
+ * leaves the patch there as outputs/snapshot.patch. */
1877
+ snapshot?: { id: string };
1864
1878
  /** A person approved this step before it ran: configuration and code it
1865
1879
  * changed are kept, not refused (copy-back.ts, FOL-96). */
1866
1880
  configWrites?: boolean;
package/src/runner.ts CHANGED
@@ -460,6 +460,13 @@ export function readAgentsMd(dir: string): { data: Record<string, unknown>; body
460
460
 
461
461
  const workspaceRootOf = (agentDir: string) => path.join(agentDir, "..", "..");
462
462
 
463
+ /** What a snapshot step is told (Part B3). */
464
+ const SNAPSHOT_NOTE =
465
+ "The folder you were sent to work on is in snapshot/ (inside your working directory). Make your changes there, as files: " +
466
+ "when you finish, foldrun turns what changed in snapshot/ into a patch the person applies. " +
467
+ "Only snapshot/ (as that patch) and your outputs/ come back from this step; anything you write elsewhere is not kept. " +
468
+ "Do not create links or a .git folder in snapshot/ — links make the patch refused, and .git is left out.";
469
+
463
470
  /**
464
471
  * Configuration from AGENTS.md, nearest-wins: the workspace's overrides the
465
472
  * account's, key by key.
@@ -2904,6 +2911,17 @@ async function runStep(
2904
2911
  if (stepHookNames.length) push("info", `hooks: ${stepHookNames.join(", ")}`);
2905
2912
 
2906
2913
  const isolation = process.env.FOLDRUN_RUN_ISOLATION;
2914
+ // A snapshot run (Part B3): the folder is on the run record, set when the
2915
+ // run was made. Only an executor that says it can hold one may run it —
2916
+ // in-process, the step would work in the real workspace folder, and no
2917
+ // copy-back stands between what it writes and the workspace (Codex).
2918
+ const snapshotId = runId ? readRun(tenant, path.basename(workspaceRootOf(agentDir)), runId)?.snapshot?.id : undefined;
2919
+ if (snapshotId) {
2920
+ const able = isolatedRun() && isolation !== "container" && Boolean(platform.isolation[isolation!]) && platform.holdsSnapshot?.(isolation!) === true;
2921
+ if (!able) {
2922
+ throw new Error("this run has a snapshot (a folder sent to work on), and this install cannot hold one: it needs the k8s sandbox (FOLDRUN_RUN_ISOLATION=k8s). Nothing was run.");
2923
+ }
2924
+ }
2907
2925
  if (isolatedRun()) {
2908
2926
  // The isolated path: the whole loop — model, built-in tools, scripts —
2909
2927
  // runs inside a throwaway container (a docker sibling, or a pod), and
@@ -3285,6 +3303,7 @@ async function runStep(
3285
3303
  const runIsolated = isolation === "container" ? runStepInContainer : platform.isolation[isolation!]!;
3286
3304
  const isolatedArgs = (modelEnv: Record<string, string | undefined>, keyName = MODEL_KEY_NAME) => ({
3287
3305
  workspaceRoot,
3306
+ ...(snapshotId ? { snapshot: { id: snapshotId } } : {}),
3288
3307
  libraryRoot: libraryDir(tenant),
3289
3308
  galleryRoot: platform.galleryDir() ?? undefined,
3290
3309
  // Keys this step's dependency cache. Per-account by design — see
@@ -3294,7 +3313,8 @@ async function runStep(
3294
3313
  agentRel: path.relative(workspaceRoot, agentDir).replaceAll("\\", "/"),
3295
3314
  // Its file tools inside the sandbox get the same allowance (FOL-96).
3296
3315
  configWrites: step.approve === true && Boolean(step.approvedAt),
3297
- prompt,
3316
+ // A snapshot step is told where its folder is, and what comes back.
3317
+ prompt: snapshotId ? `${prompt}\n\n${SNAPSHOT_NOTE}` : prompt,
3298
3318
  model,
3299
3319
  effort,
3300
3320
  systemPrompt,
@@ -4499,6 +4519,9 @@ export function createFlowRun(
4499
4519
  /** An A2A task's correlation (foldrun-platform flow-admission.ts) — its
4500
4520
  * own trailing argument, so the signature only widened. */
4501
4521
  a2a?: { task: string; key: string },
4522
+ /** A snapshot run's folder (Part B3): the id POST …/snapshots answered.
4523
+ * Its own trailing argument, as a2a is, so the signature only widened. */
4524
+ snapshot?: string,
4502
4525
  ): RunRecord {
4503
4526
  let flowMaxOut: number | undefined;
4504
4527
  try {
@@ -4515,6 +4538,7 @@ export function createFlowRun(
4515
4538
  ...(opts.test ? { test: true } : {}),
4516
4539
  // An outside agent asked, over A2A: the task it serves, and whose key.
4517
4540
  ...(a2a ? { trigger: "a2a" as const, a2a: { task: a2a.task, key: a2a.key } } : {}),
4541
+ ...(snapshot ? { snapshot: { id: snapshot } } : {}),
4518
4542
  startedAt: new Date().toISOString(),
4519
4543
  finishedAt: null,
4520
4544
  steps: steps.map((s) => ({
package/src/scan.ts CHANGED
@@ -26,6 +26,7 @@
26
26
  // The reason is required: an ignore without one ignores nothing and is itself
27
27
  // reported, because "why is this allowed?" is the question a reviewer asks.
28
28
 
29
+ import { spellingJoiners } from "./joiners.ts";
29
30
  import crypto from "node:crypto";
30
31
  import matter, { frontmatterErrorLine, frontmatterErrorText, parseLenient, configMatter } from "./matter.ts";
31
32
  import { refNames } from "./refs.ts";
@@ -481,6 +482,9 @@ const SECRET_SHAPES: [RegExp, string][] = [
481
482
  [/\bnpm_[A-Za-z0-9]{36}\b/g, "an npm token"],
482
483
  [/\bhf_[A-Za-z0-9]{34,}\b/g, "a Hugging Face token"],
483
484
  [/\blin_api_[A-Za-z0-9]{40}\b/g, "a Linear key"],
485
+ // foldrun's own (FOL-154): API, gateway, A2A and deploy keys, and the
486
+ // prefixes before them. 48 hex: the exact shape minted, never `fr_api_…`.
487
+ [/\b(?:fr_(?:api|gw|a2a|dep)|md[ak])_[0-9a-f]{48}\b/g, "a foldrun key"],
484
488
  [/\bdop_v1_[a-f0-9]{64}\b/g, "a DigitalOcean token"],
485
489
  [/\bshp(?:at|ca|pa|ss)_[a-fA-F0-9]{32}\b/g, "a Shopify token"],
486
490
  [/\bre_[A-Za-z0-9]{8,}_[A-Za-z0-9]{16,}\b/g, "a Resend key"],
@@ -644,10 +648,14 @@ function scanContent(file: ScanFile, lines: string[], push: Push, untrusted = fa
644
648
  for (let i = 0; i < lines.length; i++) {
645
649
  const line = i === 0 ? lines[i]!.replace(/^/, "") : lines[i]!;
646
650
  if (!untrusted && /^\s*(?:```|~~~)/.test(line)) fenced = !fenced;
647
- HIDDEN.lastIndex = 0;
648
- if (HIDDEN.test(line)) {
649
- const kind = HIDDEN_NAMES.find(([re]) => re.test(line))?.[1] ?? "invisible characters";
650
- const n = line.match(HIDDEN)?.length ?? 0;
651
+ // A half-space inside a Persian word, a joiner in an Indic word or an
652
+ // emoji sequence is spelling, not hiding (joiners.ts): not counted.
653
+ const spelling = spellingJoiners(line);
654
+ const hits = [...line.matchAll(HIDDEN)].filter((m) => !spelling.has(m.index!));
655
+ if (hits.length) {
656
+ const found = hits.map((m) => m[0]).join("");
657
+ const kind = HIDDEN_NAMES.find(([re]) => re.test(found))?.[1] ?? "invisible characters";
658
+ const n = hits.length;
651
659
  const tagged = /\uDB40[\uDC00-\uDC7F]/.test(line) ? ` that read as: "${decodeTags(line).slice(0, 80)}"` : "";
652
660
  push("content/hidden-unicode", file.path, i + 1, line, `${n} ${kind}${redactText(tagged)} — invisible to a reviewer, read by the model`);
653
661
  }
@@ -64,6 +64,9 @@ export function snapshotPathProblem(p: string): string | null {
64
64
  const parts = p.split("/");
65
65
  if (parts.length > MAX_DEPTH) return `a path deeper than ${MAX_DEPTH} folders`;
66
66
  if (parts.some((s) => s === "" || s === "." || s === "..")) return "an empty, `.` or `..` segment";
67
+ // The files, never a repository: a `.git` sent in could become git's own
68
+ // configuration (hooks, fsmonitor) wherever git later reads the folder.
69
+ if (parts.some((s) => s.toLowerCase() === ".git")) return "a `.git` folder or file — send the files, not the repository";
67
70
  return null;
68
71
  }
69
72
 
package/src/store.ts CHANGED
@@ -4002,6 +4002,11 @@ export interface RunRecord {
4002
4002
  * first id, kept across rotations) that asked. A correlation only — the
4003
4003
  * protocol's own state lives in the platform's a2a_tasks. */
4004
4004
  a2a?: { task: string; key: string };
4005
+ /** A snapshot run (Part B3): the folder a person sent (its sha256), staged
4006
+ * for the step at agents/<name>/snapshot/; the patch of what the step
4007
+ * changed is outputs/snapshot.patch. Set when the run is made, never by a
4008
+ * step. */
4009
+ snapshot?: { id: string };
4005
4010
  steps: StepRecord[];
4006
4011
  }
4007
4012