@foldrun/core 21.2.0 → 22.1.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.
Files changed (43) hide show
  1. package/dist/src/agent-import.js +3 -0
  2. package/dist/src/capture.d.ts +3 -6
  3. package/dist/src/capture.js +7 -5
  4. package/dist/src/captured-calls.d.ts +30 -0
  5. package/dist/src/captured-calls.js +219 -0
  6. package/dist/src/completions.js +2 -0
  7. package/dist/src/confine.d.ts +6 -0
  8. package/dist/src/confine.js +33 -0
  9. package/dist/src/frontmatter-fields.js +1 -0
  10. package/dist/src/frontmatter-schema.js +2 -0
  11. package/dist/src/mirror-base.d.ts +24 -0
  12. package/dist/src/mirror-base.js +82 -0
  13. package/dist/src/network.d.ts +13 -0
  14. package/dist/src/network.js +27 -0
  15. package/dist/src/records.d.ts +6 -1
  16. package/dist/src/revision-store.d.ts +12 -0
  17. package/dist/src/revision-store.js +27 -0
  18. package/dist/src/runner.d.ts +3 -0
  19. package/dist/src/runner.js +43 -5
  20. package/dist/src/script-tools.d.ts +4 -0
  21. package/dist/src/script-tools.js +2 -0
  22. package/dist/src/starter.js +2 -2
  23. package/dist/src/store.d.ts +5 -6
  24. package/dist/src/store.js +53 -30
  25. package/dist/src/workspace-revisions.d.ts +20 -0
  26. package/dist/src/workspace-revisions.js +397 -13
  27. package/package.json +1 -1
  28. package/src/agent-import.ts +3 -0
  29. package/src/capture.ts +7 -6
  30. package/src/captured-calls.ts +226 -0
  31. package/src/completions.ts +2 -0
  32. package/src/confine.ts +31 -0
  33. package/src/frontmatter-fields.ts +1 -0
  34. package/src/frontmatter-schema.ts +2 -0
  35. package/src/mirror-base.ts +91 -0
  36. package/src/network.ts +28 -0
  37. package/src/records.ts +6 -1
  38. package/src/revision-store.ts +37 -0
  39. package/src/runner.ts +45 -5
  40. package/src/script-tools.ts +6 -0
  41. package/src/starter.ts +2 -2
  42. package/src/store.ts +50 -29
  43. package/src/workspace-revisions.ts +358 -12
@@ -137,6 +137,33 @@ export function localRevisionStore(root = path.join(dataRoot(), ".revisions")) {
137
137
  async head(ws) {
138
138
  return headOf(ws);
139
139
  },
140
+ async allHeads() {
141
+ const out = [];
142
+ let tenants = [];
143
+ try {
144
+ tenants = fs.readdirSync(root).filter((n) => !n.startsWith("."));
145
+ }
146
+ catch {
147
+ return out;
148
+ }
149
+ for (const tenant of tenants.sort()) {
150
+ let names = [];
151
+ try {
152
+ names = fs.readdirSync(path.join(root, tenant)).filter((n) => !n.startsWith("."));
153
+ }
154
+ catch {
155
+ continue;
156
+ }
157
+ for (const workspace of names.sort()) {
158
+ const ws = { tenant, workspace };
159
+ const w = headOf(ws);
160
+ const st = headOf({ ...ws, scope: "state" });
161
+ if (w || st)
162
+ out.push({ tenant, workspace, workspaceHead: w?.id ?? null, stateHead: st?.id ?? null });
163
+ }
164
+ }
165
+ return out;
166
+ },
140
167
  async revision(ws, id) {
141
168
  for (const seq of seqs(ws).reverse()) {
142
169
  const r = bySeq(ws, seq);
@@ -97,6 +97,9 @@ export interface DiscoveredSkill {
97
97
  /** The rest of the Agent Skills layout: references/ and assets/. */
98
98
  hasReferences: boolean;
99
99
  hasAssets: boolean;
100
+ /** From the platform's gallery, not the account's files: offered only to
101
+ * an agent whose `skills:` names it (applicableSkills). */
102
+ gallery?: boolean;
100
103
  }
101
104
  export declare function discoverSkills(agentDir: string, subdir?: string): DiscoveredSkill[];
102
105
  /**
@@ -6,6 +6,7 @@ import { opsLog, opsError } from "./ops-log.js";
6
6
  import { globMatch } from "./bounded-match.js";
7
7
  import { latestRevisionId } from "./history.js";
8
8
  import { recordCallIo, redactionsFor } from "./capture.js";
9
+ import { callSink, flushCalls } from "./captured-calls.js";
9
10
  import { AUTH_REFUSAL, platformCause } from "./issues.js";
10
11
  import { hookNames } from "./hooks.js";
11
12
  import crypto from "node:crypto";
@@ -65,7 +66,7 @@ import { buildScriptTools, parseScripts } from "./script-tools.js";
65
66
  import { libraryDir, libraryTools, libraryMemoryIndex } from "./library.js";
66
67
  import { fingerprint, mergeRuntimes, parseRuntime, prepareRuntime, stepInstallEnv } from "./runtime.js";
67
68
  import { buildInstallTool, INSTALL_TOOL } from "./install-tool.js";
68
- import { dataRoot, singleWorkspace } from "./paths.js";
69
+ import { dataRoot } from "./paths.js";
69
70
  import { materializeFiles, harvestFiles, storageBaseline } from "./storage.js";
70
71
  import { readStorageBaseline, writeStorageBaseline } from "./step-state.js";
71
72
  import { chooseExecutor, ensureImage } from "./container.js";
@@ -698,8 +699,11 @@ export function sharedInstructions(agentDir, tenant) {
698
699
  * permanently invisible instead of conditionally loaded.
699
700
  */
700
701
  export function applicableSkills(skills, only, tags) {
702
+ // A gallery skill is the platform's, in every account: it reaches an agent
703
+ // only when its `skills:` names it, the way a gallery tool is granted only
704
+ // by `tools:` — so shipping one never grows every other agent's prompt.
701
705
  return skills
702
- .filter((s) => only.length === 0 || only.includes(s.name))
706
+ .filter((s) => (only.length === 0 ? !s.gallery : only.includes(s.name)))
703
707
  .filter((s) => s.when.length === 0 || s.when.some((t) => tags.includes(t)));
704
708
  }
705
709
  /**
@@ -948,7 +952,9 @@ grantsOnly = false) {
948
952
  // it's an allowlist, which is how you keep a focused agent focused.
949
953
  const only = refNames(front.skills);
950
954
  const applicable = applicableSkills(skills, only, tags);
951
- const withheld = skills.length - applicable.length;
955
+ // The gallery's skills an agent did not name are not "withheld" from it —
956
+ // they were never its to have — so they are not counted in the note.
957
+ const withheld = skills.filter((s) => !s.gallery || only.includes(s.name)).length - applicable.length;
952
958
  if (applicable.length) {
953
959
  const lines = applicable.map((s) => {
954
960
  // The rest of the Agent Skills layout, named so the agent knows to look
@@ -2014,7 +2020,16 @@ export function operatorBlock(step, workspaceRoot) {
2014
2020
  }
2015
2021
  return "";
2016
2022
  }
2017
- async function runStep(agentDir, tenant, step, context, save, modelOverride, tags = [], effortOverride, runId,
2023
+ /** A step, and then whatever its captured calls still hold (captured-calls.ts). */
2024
+ async function runStep(...args) {
2025
+ try {
2026
+ return await runStepBody(...args);
2027
+ }
2028
+ finally {
2029
+ await flushCalls(args[2]);
2030
+ }
2031
+ }
2032
+ async function runStepBody(agentDir, tenant, step, context, save, modelOverride, tags = [], effortOverride, runId,
2018
2033
  /** What the previous group returned as DATA (an `output: json` step's
2019
2034
  * value), beside the prose in `context`. Undefined when nothing did. */
2020
2035
  priorData,
@@ -2122,6 +2137,8 @@ conversation) {
2122
2137
  // calls keep their names, sizes and times (FOL-54 step 4).
2123
2138
  let capturedChars = 0;
2124
2139
  let captureFull = false;
2140
+ const callsRoot = path.resolve(agentDir, "..", "..");
2141
+ const sink = runId ? callSink(step, { tenant, workspace: path.basename(callsRoot), runId, workspaceRoot: callsRoot }) : undefined;
2125
2142
  const push = (type, text, extra) => {
2126
2143
  const t = new Date().toISOString();
2127
2144
  // The model has begun its first response: held only in memory, for
@@ -2158,7 +2175,7 @@ conversation) {
2158
2175
  captureFull = true;
2159
2176
  step.events.push({ t, type: "info", text: `capture: this step recorded ${Math.round(capturedChars / 1000)}k characters of tool content — the rest of its calls keep only their names, sizes and times` });
2160
2177
  }
2161
- if (runId && extra.call && capture === "full" && !captureFull && recordCallIo(path.resolve(agentDir, "..", ".."), runId, extra.call, text, io, redact, singleWorkspace() ? undefined : { tenant, workspace: path.basename(path.resolve(agentDir, "..", "..")) })) {
2178
+ if (runId && extra.call && capture === "full" && !captureFull && recordCallIo(callsRoot, runId, extra.call, text, io, redact, sink)) {
2162
2179
  capturedChars += size;
2163
2180
  rest = { ...others, captured: true };
2164
2181
  }
@@ -2922,6 +2939,9 @@ conversation) {
2922
2939
  ...Object.values(boundSites).flat(),
2923
2940
  // remotes: each card's own host — never one its card names.
2924
2941
  ...remoteNetworkHosts(stepRemotes),
2942
+ // A granted script tool's own `network:` — the sites its program
2943
+ // reaches (a gallery `docs` tool reaching context7.com).
2944
+ ...scriptSpecs.flatMap((sc) => sc.network ?? []),
2925
2945
  ],
2926
2946
  });
2927
2947
  grant.network = { level: network.level, hosts: network.hosts };
@@ -6529,6 +6549,24 @@ export function skillsInScope(agentDir, tenant) {
6529
6549
  // The account library keeps its relative path: `account/` is expanded by
6530
6550
  // the file tools only, and a skill's bundled scripts are run from the shell.
6531
6551
  add(path.join(libraryDir(tenant)), "../../../../library/");
6552
+ // Then the platform's gallery: the skills foldrun ships to every account,
6553
+ // under the account library's path, because that is where a sandbox has
6554
+ // them (the staging step lays the gallery down beneath the library) and,
6555
+ // with no sandbox, the file tools serve that path from the shelf
6556
+ // (confine.ts gallerySkillFile). The account's own copy of a name wins.
6557
+ // The prefix is the library's place relative to this agent: the same
6558
+ // `../../../../library/` a sandbox stages in an account folder, and
6559
+ // `../../library/` in a flat single-workspace folder (Codex review).
6560
+ const gallery = platform.galleryDir();
6561
+ if (gallery) {
6562
+ const lib = `${path.relative(agentDir, libraryDir(tenant)).split(path.sep).join("/")}/`;
6563
+ for (const skill of discoverSkills(gallery, "skills")) {
6564
+ if (seen.has(skill.name))
6565
+ continue;
6566
+ seen.add(skill.name);
6567
+ skills.push({ ...skill, gallery: true, path: `${lib}${skill.path}`, dir: skill.dir ? `${lib}${skill.dir}` : null });
6568
+ }
6569
+ }
6532
6570
  return skills;
6533
6571
  }
6534
6572
  /**
@@ -37,6 +37,10 @@ export interface ScriptSpec {
37
37
  * secret's name (a GBP reader on a GBP token): on a test run the step
38
38
  * still gets the real values. An `outward` tool in the same step wins. */
39
39
  testMode?: "allow";
40
+ /** `network: [api.example.com]` in the tool's definition — the sites its
41
+ * program reaches, added to the step's list when the tool is granted
42
+ * (network.ts toolSites). */
43
+ network?: string[];
40
44
  }
41
45
  export declare function parseScripts(raw: unknown): ScriptSpec[];
42
46
  export declare function commandFor(spec: ScriptSpec, abs: string, overrides?: Record<string, string>): {
@@ -23,6 +23,7 @@ import { hostSafeEnv } from "./host-env.js";
23
23
  import { workspaceLinkEnv } from "./confine.js";
24
24
  import { platform } from "./platform.js";
25
25
  import { previewOrKeep, RESULT_KEEP_CHARS } from "./tool-output.js";
26
+ import { toolSites } from "./network.js";
26
27
  // A script's only clock is the `timeout:` its own tool.md declares. There
27
28
  // was a two-minute default and a ten-minute cap here; both were the
28
29
  // platform's opinion about how long a person's script may take, and the
@@ -64,6 +65,7 @@ export function parseScripts(raw) {
64
65
  secrets: e.secrets === "proxied" ? "proxied" : undefined,
65
66
  outward: e.outward === true ? true : undefined,
66
67
  testMode: e.test_mode === "allow" ? "allow" : undefined,
68
+ ...(toolSites(e.network).length ? { network: toolSites(e.network) } : {}),
67
69
  timeout: Number.isFinite(timeout) && timeout > 0 ? timeout : undefined,
68
70
  });
69
71
  }
@@ -486,9 +486,9 @@ model: default # fast | default | max
486
486
  effort: low # how hard to think about it
487
487
  size: large # small | large | heavy — the sandbox it rents
488
488
  resources: { memory: 4Gi } # optional: cpu, memory, disk in numbers, over the size class
489
- tools: [web, read, ask, peers, text, my-folder-tool] # built-ins and your own tools/, one list; \`ask\` lets it ask you mid-step, \`peers\` lets it message the steps running beside it, \`text\` reads images, PDFs, office files and recordings as text
489
+ tools: [web, read, ask, peers, text, my-folder-tool] # built-ins and your own tools/, one list; \`ask\` lets it ask you mid-step, \`peers\` lets it message the steps running beside it, \`text\` reads images, PDFs, office files and recordings as text, \`docs\` reads a library's current docs, \`video\` renders Remotion video
490
490
  disallowedTools: [Bash] # subtract from what it would otherwise have
491
- skills: [house-style] # from skills/
491
+ skills: [house-style] # from skills/, the library, or the platform's gallery (modern-website, motion-video, cloudhost-deploy — by name only)
492
492
  hooks: [no-force-push] # from hooks/ or the library: code at every tool call
493
493
  scripts: [summarise.py] # from scripts/, each becomes a callable tool
494
494
  apis: [{ name: crm }] # an HTTP API, as a tool
@@ -1691,10 +1691,7 @@ export interface RunRecord {
1691
1691
  }
1692
1692
  /** Merge one part (the input, on the call; the output, on its completion)
1693
1693
  * into the call's file. */
1694
- export declare function writeCapturedCall(workspaceRoot: string, runId: string, part: CapturedCall, scope?: {
1695
- tenant: string;
1696
- workspace: string;
1697
- }): void;
1694
+ export declare function writeCapturedCall(workspaceRoot: string, runId: string, part: CapturedCall): void;
1698
1695
  /** One recorded call of a run, or null (not recorded, or not a call). */
1699
1696
  export declare function readCapturedCall(tenant: string, workspace: string, runId: string, callId: string): CapturedCall | null;
1700
1697
  export declare function runFilePath(tenant: string, workspace: string, runId: string): string;
@@ -1716,9 +1713,11 @@ export declare function runFilePath(tenant: string, workspace: string, runId: st
1716
1713
  export declare function deleteRun(tenant: string, workspace: string, runId: string, opts?: {
1717
1714
  pruned?: boolean;
1718
1715
  }): boolean;
1719
- /** run-outputs.ts registers here (it imports this module). */
1716
+ /** run-outputs.ts and captured-calls.ts register here (they import this module). */
1720
1717
  type RunHook = (tenant: string, workspace: string, runId: string) => void;
1721
- export declare function registerRunRemovedHook(fn: RunHook | null): void;
1718
+ /** A run's content lives somewhere other than its folder: `name` says whose hook
1719
+ * this is, so one registering (or clearing, with null) never replaces another's. */
1720
+ export declare function registerRunRemovedHook(fn: RunHook | null, name?: string): void;
1722
1721
  /** ledger.ts registers here — store cannot import it without a cycle, and
1723
1722
  * money must not depend on one. */
1724
1723
  export declare function registerRunDeletionListener(fn: RunHook | undefined): void;
package/dist/src/store.js CHANGED
@@ -19,6 +19,7 @@
19
19
  // or an agent, and belongs in git.
20
20
  //
21
21
  // An account is a named directory (per OKF: tenancy is a hosting concern).
22
+ import { opsError } from "./ops-log.js";
22
23
  import { readCompute } from "./resources.js";
23
24
  import { expandPlatformVars } from "./host-env.js";
24
25
  import { FLOW_TRIGGERS } from "./frontmatter-fields.js";
@@ -29,7 +30,7 @@ import { processState } from "./process-state.js";
29
30
  import { dataRoot, singleWorkspace, singleAccountRoot, entriesNoFollow } from "./paths.js";
30
31
  import { platform } from "./platform.js";
31
32
  import { records } from "./records.js";
32
- import { docRows, docStore, quietly } from "./workspace-docs.js";
33
+ import { docRows, quietly } from "./workspace-docs.js";
33
34
  import { toLF, asRaw } from "./eol.js";
34
35
  import matter, { frontmatterErrorText, configMatter } from "./matter.js";
35
36
  import { readAgentsMdKeys, patchFrontmatter } from "./agents-md.js";
@@ -54,7 +55,7 @@ import { parseBudget, budgetProblem } from "./budget.js";
54
55
  import { explainFailure, failureFactsOf } from "./failure.js";
55
56
  import { timezoneProblem } from "./clock.js";
56
57
  import { parseStepLimits, readLimits } from "./limits.js";
57
- import { networkEnforceWanted, networkProblems, resolveNetwork } from "./network.js";
58
+ import { networkEnforceWanted, networkProblems, resolveNetwork, toolSites } from "./network.js";
58
59
  import { browseVendorOf } from "./browse-egress.js";
59
60
  import { searchProvided } from "./search-egress.js";
60
61
  import { webProblems, webWarnings, runnerEngines, webConfig } from "./providers.js";
@@ -1143,6 +1144,22 @@ export function listAgents(tenant, workspace) {
1143
1144
  };
1144
1145
  const accountFront = frontOf(path.join(accountDir(tenant), "AGENTS.md"));
1145
1146
  const workspaceFront = frontOf(path.join(workspaceDir(tenant, workspace), "AGENTS.md"));
1147
+ // The sites each tool's own definition names (`network:` in its tool.md),
1148
+ // nearest copy wins — the gallery's, the account library's, the
1149
+ // workspace's — read once for every agent below, as the runner reads them.
1150
+ let toolSiteMap = null;
1151
+ const sitesOfTools = (names) => {
1152
+ if (!toolSiteMap) {
1153
+ const gallery = platform.galleryDir();
1154
+ const defs = {
1155
+ ...(gallery ? readToolDir(path.join(gallery, "tools"), "account") : {}),
1156
+ ...readToolDir(path.join(dataRoot(), tenant, "library", "tools"), "account"),
1157
+ ...workspaceTools(tenant, workspace),
1158
+ };
1159
+ toolSiteMap = Object.fromEntries(Object.entries(defs).map(([n, d]) => [n, d.kind === "script" ? toolSites(d.spec.network) : []]));
1160
+ }
1161
+ return names.flatMap((n) => toolSiteMap[n] ?? []);
1162
+ };
1146
1163
  return fs
1147
1164
  .readdirSync(dir)
1148
1165
  .filter((n) => fs.existsSync(path.join(dir, n, "agent.md")))
@@ -1178,6 +1195,8 @@ export function listAgents(tenant, workspace) {
1178
1195
  } }),
1179
1196
  // remotes: — each card's own host, and nothing its card says.
1180
1197
  ...remoteNetworkHosts(parseRemotes(data.remotes)),
1198
+ // Each granted script tool's own network: list.
1199
+ ...sitesOfTools(ownToolNames(data)),
1181
1200
  ],
1182
1201
  }),
1183
1202
  readsWeb,
@@ -2925,7 +2944,9 @@ export function isSplicedRecord(step) {
2925
2944
  // and every page reads whole, and gone with the run (deleteRun removes
2926
2945
  // runs/<run>/). The runner writes them, secrets already masked.
2927
2946
  const SAFE_ID = /^[A-Za-z0-9_.-]{1,128}$/;
2928
- const CALL_KIND = "call";
2947
+ /** Captured calls kept as rows for one day on dev (13 Nov 2026); read and
2948
+ * dropped with their run, never written again. */
2949
+ const LEGACY_CALL_KIND = "call";
2929
2950
  function capturedCallFile(workspaceRoot, runId, callId) {
2930
2951
  if (!SAFE_ID.test(runId) || !SAFE_ID.test(callId) || callId.startsWith(".") || runId.startsWith("."))
2931
2952
  return null;
@@ -2933,16 +2954,10 @@ function capturedCallFile(workspaceRoot, runId, callId) {
2933
2954
  }
2934
2955
  /** Merge one part (the input, on the call; the output, on its completion)
2935
2956
  * into the call's file. */
2936
- export function writeCapturedCall(workspaceRoot, runId, part, scope) {
2957
+ export function writeCapturedCall(workspaceRoot, runId, part) {
2937
2958
  const file = capturedCallFile(workspaceRoot, runId, part.id);
2938
2959
  if (!file)
2939
2960
  return;
2940
- // A row when the platform keeps them (FOL-126): the two parts of a call
2941
- // merge in one statement, and the web's copies read it wherever they run.
2942
- // `truncated` is only ever sent true, so a merge keeps it once set.
2943
- const store = scope ? docStore(scope.tenant, scope.workspace) : null;
2944
- if (store && scope)
2945
- return store.merge(scope.tenant, scope.workspace, CALL_KIND, `${runId}/${part.id}`, part);
2946
2961
  let prev = {};
2947
2962
  try {
2948
2963
  prev = JSON.parse(fs.readFileSync(file, "utf8"));
@@ -2963,22 +2978,17 @@ export function readCapturedCall(tenant, workspace, runId, callId) {
2963
2978
  const file = capturedCallFile(workspaceDir(tenant, workspace), runId, callId);
2964
2979
  if (!file)
2965
2980
  return null;
2966
- const row = quietly(() => docRows(tenant, workspace)?.get(tenant, workspace, CALL_KIND, `${runId}/${callId}`), undefined);
2967
- let onFile;
2981
+ // A call kept as a workspace_docs row (records.docs_store, 13 Nov 2026,
2982
+ // before calls went to the blob store): still read until its run goes.
2983
+ const legacy = quietly(() => docRows(tenant, workspace)?.get(tenant, workspace, LEGACY_CALL_KIND, `${runId}/${callId}`), undefined);
2984
+ if (legacy)
2985
+ return legacy;
2968
2986
  try {
2969
- onFile = JSON.parse(fs.readFileSync(file, "utf8"));
2987
+ return JSON.parse(fs.readFileSync(file, "utf8"));
2970
2988
  }
2971
2989
  catch {
2972
- /* none */
2973
- }
2974
- // A switch between a call's two parts leaves one part in each place: both, merged.
2975
- if (row && onFile) {
2976
- const merged = { ...onFile, ...row, truncated: Boolean(onFile.truncated || row.truncated) || undefined };
2977
- if (!merged.truncated)
2978
- delete merged.truncated;
2979
- return merged;
2990
+ return null;
2980
2991
  }
2981
- return row ?? onFile ?? null;
2982
2992
  }
2983
2993
  export function runFilePath(tenant, workspace, runId) {
2984
2994
  assertSafeName(runId, "run id");
@@ -3018,9 +3028,8 @@ export function deleteRun(tenant, workspace, runId, opts = {}) {
3018
3028
  // and finishes — the other order left the content with nothing pointing
3019
3029
  // at it (Codex review, FOL-124).
3020
3030
  fs.rmSync(dir, { recursive: true, force: true });
3021
- // Its captured calls kept as rows go the same way, before the record.
3022
3031
  if (SAFE_ID.test(runId))
3023
- docRows(tenant, workspace)?.dropPrefix(tenant, workspace, CALL_KIND, `${runId}/`);
3032
+ quietly(() => docRows(tenant, workspace)?.dropPrefix(tenant, workspace, LEGACY_CALL_KIND, `${runId}/`), undefined);
3024
3033
  if (port)
3025
3034
  port.runDelete(tenant, workspace, runId);
3026
3035
  else {
@@ -3033,9 +3042,18 @@ export function deleteRun(tenant, workspace, runId, opts = {}) {
3033
3042
  if (prior?.inputs?.length) {
3034
3043
  void import("./storage.js").then((m) => m.releaseRunInputs(tenant, workspace, runId)).catch(() => { });
3035
3044
  }
3036
- // Outputs published to the blob store (run-outputs.ts) are records and pins,
3037
- // not files under dir: they go in the background, retried.
3038
- RUN_HOOKS.removed?.(tenant, workspace, runId);
3045
+ // Outputs and captured calls published to the blob store (run-outputs.ts,
3046
+ // captured-calls.ts) are records and pins, not files under dir: they go in
3047
+ // the background, retried.
3048
+ for (const [name, hook] of RUN_HOOKS.removed) {
3049
+ try {
3050
+ hook(tenant, workspace, runId);
3051
+ }
3052
+ catch (err) {
3053
+ // One store's clean-up failing must not stop the next one's.
3054
+ opsError("run_removed_hook.failed", err, { hook: name, tenant, runId });
3055
+ }
3056
+ }
3039
3057
  if (!had)
3040
3058
  return true;
3041
3059
  // The retention window's prune (`pruned`) is policy, not a person erasing
@@ -3046,9 +3064,14 @@ export function deleteRun(tenant, workspace, runId, opts = {}) {
3046
3064
  }
3047
3065
  /** One per process (process-state.ts): a run deleted from a route handler must
3048
3066
  * reach the hooks the boot registered. */
3049
- const RUN_HOOKS = processState("run-hooks", () => ({ removed: null, deleted: undefined }));
3050
- export function registerRunRemovedHook(fn) {
3051
- RUN_HOOKS.removed = fn;
3067
+ const RUN_HOOKS = processState("run-hooks", () => ({ removed: new Map(), deleted: undefined }));
3068
+ /** A run's content lives somewhere other than its folder: `name` says whose hook
3069
+ * this is, so one registering (or clearing, with null) never replaces another's. */
3070
+ export function registerRunRemovedHook(fn, name = "run-outputs") {
3071
+ if (fn)
3072
+ RUN_HOOKS.removed.set(name, fn);
3073
+ else
3074
+ RUN_HOOKS.removed.delete(name);
3052
3075
  }
3053
3076
  /** ledger.ts registers here — store cannot import it without a cycle, and
3054
3077
  * money must not depend on one. */
@@ -213,7 +213,27 @@ export declare function reconcileAll(opts?: {
213
213
  * (until 13 Nov 2026: only the text files the editor lists, so a binary file
214
214
  * never reached a head and one the importer had put there was never updated
215
215
  * or removed — a run staged from the head was handed files deleted days ago). */
216
+ /** Bring the heads to this pod's folder (see reconcileNow), in turn with
217
+ * everything else that commits this workspace here: two at once would diff
218
+ * the same folder against the same head and race each other's publish. */
216
219
  export declare function reconcileWorkspace(tenant: string, workspace: string, by?: string): Promise<PublishResult | null>;
220
+ /**
221
+ * Bring this pod's copy of a workspace to its heads (FOL-126, the shared
222
+ * volume retired; revisions.mirror). What changed in the heads since the last
223
+ * sync is written or removed; what changed HERE since then is left as it is
224
+ * and handed to the reconcile, which publishes it against the version it was
225
+ * synced at. Never while this pod has changes of its own still to publish.
226
+ * A workspace whose heads are gone (deleted, renamed away) is removed here
227
+ * only if this pod's copy came from them.
228
+ */
229
+ export declare function syncFromHeads(tenant: string, workspace: string): Promise<"unchanged" | "synced" | "skipped" | "removed" | "absent">;
230
+ /** Every workspace with heads, and every copy here whose heads are gone. One
231
+ * failure does not stop the rest. */
232
+ export declare function syncAllFromHeads(): Promise<{
233
+ synced: number;
234
+ removed: number;
235
+ failed: number;
236
+ }>;
217
237
  /** One file of the workspace as its heads hold it: head → manifest → blob.
218
238
  * Null when there is no such file (or no head yet). */
219
239
  export declare function readAtHead(tenant: string, workspace: string, rel: string): Promise<Buffer | null>;