@foldrun/core 22.0.0 → 22.2.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.
@@ -20,6 +20,7 @@ import { libraryDir, libraryTools } from "./library.js";
20
20
  import { isRuntimeTool, toolEntryName } from "./tool-names.js";
21
21
  import { discoverSkills } from "./runner.js";
22
22
  import { listSecrets } from "./secrets.js";
23
+ import { platform } from "./platform.js";
23
24
  /** An error the API layer turns into a status rather than a 500. */
24
25
  export class AgentImportError extends Error {
25
26
  status;
@@ -90,6 +91,8 @@ function missingFor(tenant, to, name, front) {
90
91
  [ws, "skills"],
91
92
  [ws, ".agents/skills"],
92
93
  [libraryDir(tenant), "skills"],
94
+ // The platform's gallery skills are in every account.
95
+ ...(platform.galleryDir() ? [[platform.galleryDir(), "skills"]] : []),
93
96
  ]) {
94
97
  for (const s of discoverSkills(base, sub))
95
98
  skills.add(s.name);
@@ -22,6 +22,16 @@ export declare function callSink(owner: object, ctx: Ctx): (part: CapturedCall)
22
22
  export declare function flushCalls(owner: object): Promise<void>;
23
23
  /** One recorded call, or null (not recorded). The row first, then the file. */
24
24
  export declare function readCapturedCallAsync(tenant: string, workspace: string, runId: string, callId: string): Promise<CapturedCall | null>;
25
+ /**
26
+ * One call from a run's folder into the store, whatever the switch says
27
+ * (FOL-126: the one-time copy of the runs written before calls went to the
28
+ * store, before the shared volume goes). "stored", "present" (already in the
29
+ * store), or "unavailable": the store is not set up here — never mistaken for
30
+ * present (Codex review).
31
+ */
32
+ export declare function backfillCall(tenant: string, workspace: string, runId: string, call: CapturedCall, opts?: {
33
+ dryRun?: boolean;
34
+ }): Promise<"stored" | "present" | "unavailable">;
25
35
  /** What the run-delete hook started and has not finished (tests, a process that is ending). */
26
36
  export declare function settleCalls(): Promise<void>;
27
37
  /** A workspace is being deleted (its rows still there): release the pin of every run that has calls
@@ -179,6 +179,31 @@ export async function readCapturedCallAsync(tenant, workspace, runId, callId) {
179
179
  }
180
180
  return readCapturedCall(tenant, workspace, runId, callId);
181
181
  }
182
+ /**
183
+ * One call from a run's folder into the store, whatever the switch says
184
+ * (FOL-126: the one-time copy of the runs written before calls went to the
185
+ * store, before the shared volume goes). "stored", "present" (already in the
186
+ * store), or "unavailable": the store is not set up here — never mistaken for
187
+ * present (Codex review).
188
+ */
189
+ export async function backfillCall(tenant, workspace, runId, call, opts = {}) {
190
+ const deps = CALLS.backend;
191
+ const port = portFor(tenant, workspace);
192
+ if (!deps || !port)
193
+ return "unavailable";
194
+ if (!SAFE.test(runId) || !SAFE.test(call.id))
195
+ throw new Error(`not a call id: ${call.id}`);
196
+ if (await port.async.stepGet(tenant, workspace, runId, KIND, call.id))
197
+ return "present";
198
+ if (opts.dryRun)
199
+ return "stored"; // would be
200
+ const bytes = Buffer.from(JSON.stringify(call));
201
+ const sha = sha256Hex(bytes);
202
+ await deps.pins?.pinBlobs(tenant, [sha], holderOf(runId));
203
+ await deps.blobs.putIfAbsent(blobObjectKey(tenant, sha), bytes, { contentType: "application/json" });
204
+ await port.async.stepPut(tenant, workspace, runId, KIND, call.id, { sha, size: bytes.length });
205
+ return "stored";
206
+ }
182
207
  // ---------------------------------------------------------------- lifecycle
183
208
  /** What the run-delete hook started and has not finished (tests, a process that is ending). */
184
209
  export async function settleCalls() {
@@ -36,6 +36,8 @@ const TOOL_GROUPS = [
36
36
  { label: "write", hint: "Read, Write, Edit, Glob, Grep" },
37
37
  { label: "code", hint: "Bash — runs anything in the sandbox" },
38
38
  { label: "web", hint: "search, fetch, browse, crawl, map, extract, answer, monitor — providers under web:" },
39
+ { label: "docs", hint: "a library's current docs and code examples, pinned to a version (Context7) — gallery" },
40
+ { label: "video", hint: "motion graphics and video from React code: new, compositions, still, render (Remotion) — gallery" },
39
41
  { label: "ask", hint: "ask_person — ask the person running the desk mid-step, and wait for the answer" },
40
42
  { label: "peers", hint: "peers_list + peers_message — the colleagues running beside it in its parallel group, and a message to one of them" },
41
43
  { label: "text", hint: "extract_text — an image, scanned PDF, office file, audio or video as text (Persian + English OCR, speech)" },
@@ -41,6 +41,12 @@ export declare function expandVirtual(raw: string, roots: Roots): {
41
41
  readOnly: boolean;
42
42
  prefix: string;
43
43
  } | null;
44
+ /**
45
+ * The platform shelf's copy of a library skill file the account does not
46
+ * have: `<library>/skills/<rest>` missing on disk, `<gallery>/skills/<rest>`
47
+ * there. Null otherwise — the account's own copy always wins.
48
+ */
49
+ export declare function gallerySkillFile(abs: string, library: string): string | null;
44
50
  export declare function checkPaths(toolName: string, input: Record<string, unknown>, roots: Roots): ConfineVerdict;
45
51
  export declare function checkBash(command: string): ConfineVerdict;
46
52
  export declare function linkWorkspace(agentDir: string, workspaceRoot: string): {
@@ -30,6 +30,7 @@
30
30
  import fs from "node:fs";
31
31
  import path from "node:path";
32
32
  import { refusedBack } from "./copy-back.js";
33
+ import { platform } from "./platform.js";
33
34
  /**
34
35
  * A path with its symlinks resolved, as far as it exists.
35
36
  *
@@ -193,6 +194,27 @@ function linkedWorkspace(roots) {
193
194
  return false;
194
195
  }
195
196
  }
197
+ /**
198
+ * The platform shelf's copy of a library skill file the account does not
199
+ * have: `<library>/skills/<rest>` missing on disk, `<gallery>/skills/<rest>`
200
+ * there. Null otherwise — the account's own copy always wins.
201
+ */
202
+ export function gallerySkillFile(abs, library) {
203
+ const gallery = platform.galleryDir();
204
+ if (!gallery)
205
+ return null;
206
+ const rel = path.relative(library, abs);
207
+ if (rel.startsWith("..") || path.isAbsolute(rel))
208
+ return null;
209
+ const parts = rel.split(path.sep);
210
+ if (parts[0] !== "skills" || parts.length < 2 || fs.existsSync(abs))
211
+ return null;
212
+ const shelfSkills = real(path.resolve(gallery, "skills"));
213
+ const candidate = real(path.resolve(shelfSkills, ...parts.slice(1)));
214
+ if (path.relative(shelfSkills, candidate).startsWith(".."))
215
+ return null;
216
+ return fs.existsSync(candidate) ? candidate : null;
217
+ }
196
218
  export function checkPaths(toolName, input, roots) {
197
219
  const workspace = real(path.resolve(roots.workspaceRoot));
198
220
  const library = real(path.resolve(roots.libraryRoot));
@@ -214,6 +236,17 @@ export function checkPaths(toolName, input, roots) {
214
236
  }
215
237
  const virtual = expandVirtual(raw, roots);
216
238
  const abs = real(virtual ? virtual.abs : path.resolve(roots.agentDir, raw));
239
+ // A gallery skill on a step with no sandbox. The prompt names every
240
+ // gallery skill under the account library (`../../../../library/skills/
241
+ // <name>/…`), because a sandbox has the gallery laid down there; on this
242
+ // host the library holds only the account's own files, so a read that
243
+ // finds nothing there is served from the platform's shelf. Reads only:
244
+ // the shelf is the platform's.
245
+ const shelf = !isWrite ? gallerySkillFile(abs, library) : null;
246
+ if (shelf) {
247
+ rewritten = { ...(rewritten ?? input), [key]: shelf };
248
+ continue;
249
+ }
217
250
  // Knowledge is given, not learned: an agent that rewrites the price list
218
251
  // it was handed has corrupted its own source of truth. What it discovers
219
252
  // goes to memory/, which it owns.
@@ -152,6 +152,7 @@ const TOOL = [
152
152
  { key: "test_mode", type: "string", values: ["allow"], help: "script: allow — it may run in a test run" },
153
153
  { key: "secrets", type: ["list", "string"], help: "script: secret names, or proxied | materialised" },
154
154
  { key: "runtime", type: "object", help: "script: packages it needs" },
155
+ { key: "network", type: ["list", "string"], help: "script: the sites its program reaches, added to the granting step's network: list — [api.example.com]" },
155
156
  { key: "code", type: "string", help: "script: the program inline" },
156
157
  { key: "command", type: "string", help: "mcp: the server's command" },
157
158
  { key: "env", type: "object", help: "mcp: its environment" },
@@ -11,6 +11,7 @@ import { modelSecretCollision } from "./model-credential.js";
11
11
  import { resourcesProblem, computeProblem } from "./resources.js";
12
12
  import { remotesProblem } from "./a2a-remotes.js";
13
13
  import { a2aPublishProblem } from "./a2a-publish.js";
14
+ import { toolSiteProblems } from "./network.js";
14
15
  export { FRONTMATTER, schemaKindOf } from "./frontmatter-fields.js";
15
16
  /** A value for a message: a scalar as written, anything else by its shape.
16
17
  * Never String() of a map — its `toString` is whatever the YAML says. */
@@ -71,6 +72,7 @@ const CHECKS = {
71
72
  methods: methodsProblem,
72
73
  rate: (v) => (parseRate(v) ? null : `"${shown(v)}" is not a rate — N/s, N/minute, N/hour, or a number per second, above 0`),
73
74
  secrets: modelSecretCollision,
75
+ network: (v) => toolSiteProblems(v)[0] ?? null,
74
76
  },
75
77
  "eval": {
76
78
  effort: (v) => (resolveEffort(v) ? null : `"${String(v)}" is not an effort — low, medium, high, xhigh or max; the judge runs at none`),
@@ -61,7 +61,9 @@ export const MODE_EXEC = 0o755;
61
61
  // tests/manifest.test.ts compares this list with WORKSPACE_DIRS and fails when
62
62
  // they differ — the failure is the prompt to decide which side the new folder
63
63
  // is on, and whether that needs manifest v2.
64
- export const AUTHORED_DIRS = ["agents", "flows", "evals", "skills", "memory", "knowledge", "tools", "scripts", "hooks"];
64
+ // "library": the account's shelf, kept as the scope "@library" whose folder is
65
+ // the account's (account AGENTS.md + library/**, FOL-126); no workspace has one.
66
+ export const AUTHORED_DIRS = ["agents", "flows", "evals", "skills", "memory", "knowledge", "tools", "scripts", "hooks", "library"];
65
67
  export const STATE_DIRS = ["state"];
66
68
  export const AUTHORED_ROOT_FILES = ["AGENTS.md", "project.md"];
67
69
  /** A conflict copy of a root file (conflictPath) is a root file too. */
@@ -0,0 +1,24 @@
1
+ export interface MirrorBase {
2
+ workspaceHead: string | null;
3
+ stateHead: string | null;
4
+ /** path → what the heads held for it at that sync (a path's base when this
5
+ * pod's change to it is published). */
6
+ files: Record<string, {
7
+ sha: string;
8
+ mode: number;
9
+ }>;
10
+ at: string;
11
+ }
12
+ /** The platform says whether this pod's folders are a copy of the heads
13
+ * (`revisions.mirror`). Off on a laptop, in the CLI and until switched on. */
14
+ export declare function setMirrorGate(fn: (() => boolean) | null): void;
15
+ export declare function mirrorOn(): boolean;
16
+ export declare const mirrorBaseFile: (tenant: string, workspace: string) => string | null;
17
+ export declare function readMirrorBase(tenant: string, workspace: string): MirrorBase | null;
18
+ export declare function writeMirrorBase(tenant: string, workspace: string, base: MirrorBase): void;
19
+ export declare function dropMirrorBase(tenant: string, workspace: string): void;
20
+ /** Every workspace this pod holds a copy of, by its base files. */
21
+ export declare function mirroredWorkspaces(): {
22
+ tenant: string;
23
+ workspace: string;
24
+ }[];
@@ -0,0 +1,82 @@
1
+ // What a pod's copy of a workspace was last brought to (FOL-126, 13 Nov 2026):
2
+ // the two head ids and every file's sha as the heads held them. The mirror
3
+ // (workspace-mirror.ts) writes it after a sync; the reconcile reads it so a
4
+ // file that differs from it is this pod's own change, and one that differs
5
+ // only from the head is someone else's, not yet copied here.
6
+ //
7
+ // Kept on the pod's own disk beside the folders, outside every workspace:
8
+ // <data>/.mirror/<tenant>/<workspace>.json. Lost with the disk, it is rebuilt
9
+ // by the next full sync (a pod starts with an empty disk anyway).
10
+ import fs from "node:fs";
11
+ import path from "node:path";
12
+ import crypto from "node:crypto";
13
+ import { dataRoot } from "./paths.js";
14
+ import { processState } from "./process-state.js";
15
+ const GATE = processState("mirror-gate", () => ({ on: (() => false) }));
16
+ /** The platform says whether this pod's folders are a copy of the heads
17
+ * (`revisions.mirror`). Off on a laptop, in the CLI and until switched on. */
18
+ export function setMirrorGate(fn) {
19
+ GATE.on = fn ?? (() => false);
20
+ }
21
+ export function mirrorOn() {
22
+ try {
23
+ return GATE.on();
24
+ }
25
+ catch {
26
+ return false;
27
+ }
28
+ }
29
+ const SAFE = /^(?:@library|[A-Za-z0-9][A-Za-z0-9_.-]{0,127})$/;
30
+ export const mirrorBaseFile = (tenant, workspace) => SAFE.test(tenant) && SAFE.test(workspace) ? path.join(dataRoot(), ".mirror", tenant, `${workspace}.json`) : null;
31
+ export function readMirrorBase(tenant, workspace) {
32
+ const f = mirrorBaseFile(tenant, workspace);
33
+ if (!f)
34
+ return null;
35
+ try {
36
+ return JSON.parse(fs.readFileSync(f, "utf8"));
37
+ }
38
+ catch {
39
+ return null;
40
+ }
41
+ }
42
+ export function writeMirrorBase(tenant, workspace, base) {
43
+ const f = mirrorBaseFile(tenant, workspace);
44
+ if (!f)
45
+ return;
46
+ fs.mkdirSync(path.dirname(f), { recursive: true });
47
+ const tmp = `${f}.${process.pid}.${crypto.randomBytes(4).toString("hex")}.tmp`;
48
+ fs.writeFileSync(tmp, JSON.stringify(base));
49
+ fs.renameSync(tmp, f);
50
+ }
51
+ export function dropMirrorBase(tenant, workspace) {
52
+ const f = mirrorBaseFile(tenant, workspace);
53
+ if (f)
54
+ fs.rmSync(f, { force: true });
55
+ }
56
+ /** Every workspace this pod holds a copy of, by its base files. */
57
+ export function mirroredWorkspaces() {
58
+ const root = path.join(dataRoot(), ".mirror");
59
+ const out = [];
60
+ let tenants = [];
61
+ try {
62
+ tenants = fs.readdirSync(root);
63
+ }
64
+ catch {
65
+ return out;
66
+ }
67
+ for (const tenant of tenants) {
68
+ if (!SAFE.test(tenant))
69
+ continue;
70
+ let files = [];
71
+ try {
72
+ files = fs.readdirSync(path.join(root, tenant));
73
+ }
74
+ catch {
75
+ continue;
76
+ }
77
+ for (const f of files)
78
+ if (f.endsWith(".json") && SAFE.test(f.slice(0, -5)))
79
+ out.push({ tenant, workspace: f.slice(0, -5) });
80
+ }
81
+ return out;
82
+ }
@@ -47,6 +47,19 @@ export declare function siteCovers(site: string, host: string): boolean;
47
47
  /** May a step under `policy` reach `host`? `open` reaches any public host —
48
48
  * the caller still refuses private addresses, which no level opens. */
49
49
  export declare function networkAllows(policy: Pick<NetworkPolicy, "level" | "hosts">, host: string): boolean;
50
+ /**
51
+ * The sites a tool's own definition says its program reaches — `network:
52
+ * [context7.com]` in a script tool's tool.md (13 Nov 2026). Granting the tool
53
+ * adds them to the step's list, the way an `apis:` base or a bound secret's
54
+ * site always was: the capability travels with what it needs, and an agent
55
+ * on `trusted` need not learn which hosts a gallery tool calls. A list or
56
+ * one comma-separated line of domains; what is not a site is dropped here
57
+ * and reported by `toolSiteProblems`.
58
+ */
59
+ export declare function toolSites(raw: unknown): string[];
60
+ /** What is wrong with a tool's `network:` — for check and deploy. A tool
61
+ * names sites only: the level (open, trusted, none) is the agent's to set. */
62
+ export declare function toolSiteProblems(raw: unknown): string[];
50
63
  /**
51
64
  * One `network:` value, read. Never throws: what cannot be read is a
52
65
  * problem `check` and deploy report, and the run treats that level as
@@ -139,6 +139,33 @@ function siteList(v) {
139
139
  return v.map((x) => x.trim()).filter(Boolean);
140
140
  return null;
141
141
  }
142
+ /**
143
+ * The sites a tool's own definition says its program reaches — `network:
144
+ * [context7.com]` in a script tool's tool.md (13 Nov 2026). Granting the tool
145
+ * adds them to the step's list, the way an `apis:` base or a bound secret's
146
+ * site always was: the capability travels with what it needs, and an agent
147
+ * on `trusted` need not learn which hosts a gallery tool calls. A list or
148
+ * one comma-separated line of domains; what is not a site is dropped here
149
+ * and reported by `toolSiteProblems`.
150
+ */
151
+ export function toolSites(raw) {
152
+ const list = siteList(raw) ?? [];
153
+ return [...new Set(list.map(normalHost).filter((h) => SITE.test(h) && !NETWORK_LEVELS.includes(h)))];
154
+ }
155
+ /** What is wrong with a tool's `network:` — for check and deploy. A tool
156
+ * names sites only: the level (open, trusted, none) is the agent's to set. */
157
+ export function toolSiteProblems(raw) {
158
+ if (raw === undefined || raw === null)
159
+ return [];
160
+ const list = siteList(raw);
161
+ if (!list)
162
+ return ["a tool's network: is a list of sites, e.g. [api.example.com]"];
163
+ return list.flatMap((x) => NETWORK_LEVELS.includes(normalHost(x))
164
+ ? [`a tool's network: names sites, not a level — "${x}" is the agent's to set`]
165
+ : SITE.test(normalHost(x))
166
+ ? []
167
+ : [`"${x}" is not a site — a domain or *.domain, no scheme, path or port`]);
168
+ }
142
169
  /**
143
170
  * One `network:` value, read. Never throws: what cannot be read is a
144
171
  * problem `check` and deploy report, and the run treats that level as
@@ -102,9 +102,21 @@ export interface IndexedFile {
102
102
  updatedAt: string;
103
103
  by: string;
104
104
  }
105
+ /** One workspace's head ids (RevisionStore.allHeads). */
106
+ export interface HeadIds {
107
+ tenant: string;
108
+ workspace: string;
109
+ /** The workspace head's revision id; null when only the state head exists. */
110
+ workspaceHead: string | null;
111
+ stateHead: string | null;
112
+ }
105
113
  export interface RevisionStore {
106
114
  readonly kind: "pg" | "local";
107
115
  head(ws: WorkspaceRef): Promise<Revision | null>;
116
+ /** Every workspace that has a head, with the ids of its two heads — what a
117
+ * pod whose folders are a copy of the heads compares itself with
118
+ * (workspace-mirror.ts). Optional: a store without it has no mirror. */
119
+ allHeads?(): Promise<HeadIds[]>;
108
120
  revision(ws: WorkspaceRef, id: string): Promise<Revision | null>;
109
121
  /** Newest first. `before` is a seq: pass the last page's lowest seq. */
110
122
  revisions(ws: WorkspaceRef, opts?: {
@@ -79,7 +79,8 @@ export function newRevisionId() {
79
79
  export function localRevisionStore(root = path.join(dataRoot(), ".revisions")) {
80
80
  const dirOf = (ws) => {
81
81
  assertSafeName(ws.tenant, "tenant");
82
- assertSafeName(ws.workspace, "workspace");
82
+ if (ws.workspace !== "@library")
83
+ assertSafeName(ws.workspace, "workspace"); // the account shelf's scope
83
84
  // The state head is a separate history in a subfolder of its own; the
84
85
  // workspace head's folder never lists it (seqs reads revs/ only).
85
86
  return scopeOf(ws) === "state" ? path.join(root, ws.tenant, ws.workspace, "state-head") : path.join(root, ws.tenant, ws.workspace);
@@ -137,6 +138,33 @@ export function localRevisionStore(root = path.join(dataRoot(), ".revisions")) {
137
138
  async head(ws) {
138
139
  return headOf(ws);
139
140
  },
141
+ async allHeads() {
142
+ const out = [];
143
+ let tenants = [];
144
+ try {
145
+ tenants = fs.readdirSync(root).filter((n) => !n.startsWith("."));
146
+ }
147
+ catch {
148
+ return out;
149
+ }
150
+ for (const tenant of tenants.sort()) {
151
+ let names = [];
152
+ try {
153
+ names = fs.readdirSync(path.join(root, tenant)).filter((n) => !n.startsWith("."));
154
+ }
155
+ catch {
156
+ continue;
157
+ }
158
+ for (const workspace of names.sort()) {
159
+ const ws = { tenant, workspace };
160
+ const w = headOf(ws);
161
+ const st = headOf({ ...ws, scope: "state" });
162
+ if (w || st)
163
+ out.push({ tenant, workspace, workspaceHead: w?.id ?? null, stateHead: st?.id ?? null });
164
+ }
165
+ }
166
+ return out;
167
+ },
140
168
  async revision(ws, id) {
141
169
  for (const seq of seqs(ws).reverse()) {
142
170
  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
  /**
@@ -699,8 +699,11 @@ export function sharedInstructions(agentDir, tenant) {
699
699
  * permanently invisible instead of conditionally loaded.
700
700
  */
701
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.
702
705
  return skills
703
- .filter((s) => only.length === 0 || only.includes(s.name))
706
+ .filter((s) => (only.length === 0 ? !s.gallery : only.includes(s.name)))
704
707
  .filter((s) => s.when.length === 0 || s.when.some((t) => tags.includes(t)));
705
708
  }
706
709
  /**
@@ -949,7 +952,9 @@ grantsOnly = false) {
949
952
  // it's an allowlist, which is how you keep a focused agent focused.
950
953
  const only = refNames(front.skills);
951
954
  const applicable = applicableSkills(skills, only, tags);
952
- 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;
953
958
  if (applicable.length) {
954
959
  const lines = applicable.map((s) => {
955
960
  // The rest of the Agent Skills layout, named so the agent knows to look
@@ -2934,6 +2939,9 @@ conversation) {
2934
2939
  ...Object.values(boundSites).flat(),
2935
2940
  // remotes: each card's own host — never one its card names.
2936
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 ?? []),
2937
2945
  ],
2938
2946
  });
2939
2947
  grant.network = { level: network.level, hosts: network.hosts };
@@ -6541,6 +6549,24 @@ export function skillsInScope(agentDir, tenant) {
6541
6549
  // The account library keeps its relative path: `account/` is expanded by
6542
6550
  // the file tools only, and a skill's bundled scripts are run from the shell.
6543
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
+ }
6544
6570
  return skills;
6545
6571
  }
6546
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
package/dist/src/store.js CHANGED
@@ -55,7 +55,7 @@ import { parseBudget, budgetProblem } from "./budget.js";
55
55
  import { explainFailure, failureFactsOf } from "./failure.js";
56
56
  import { timezoneProblem } from "./clock.js";
57
57
  import { parseStepLimits, readLimits } from "./limits.js";
58
- import { networkEnforceWanted, networkProblems, resolveNetwork } from "./network.js";
58
+ import { networkEnforceWanted, networkProblems, resolveNetwork, toolSites } from "./network.js";
59
59
  import { browseVendorOf } from "./browse-egress.js";
60
60
  import { searchProvided } from "./search-egress.js";
61
61
  import { webProblems, webWarnings, runnerEngines, webConfig } from "./providers.js";
@@ -1144,6 +1144,22 @@ export function listAgents(tenant, workspace) {
1144
1144
  };
1145
1145
  const accountFront = frontOf(path.join(accountDir(tenant), "AGENTS.md"));
1146
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
+ };
1147
1163
  return fs
1148
1164
  .readdirSync(dir)
1149
1165
  .filter((n) => fs.existsSync(path.join(dir, n, "agent.md")))
@@ -1179,6 +1195,8 @@ export function listAgents(tenant, workspace) {
1179
1195
  } }),
1180
1196
  // remotes: — each card's own host, and nothing its card says.
1181
1197
  ...remoteNetworkHosts(parseRemotes(data.remotes)),
1198
+ // Each granted script tool's own network: list.
1199
+ ...sitesOfTools(ownToolNames(data)),
1182
1200
  ],
1183
1201
  }),
1184
1202
  readsWeb,
@@ -39,6 +39,9 @@ export interface BlobCache {
39
39
  put(tenant: string, sha: string, bytes: Buffer): Promise<void>;
40
40
  }
41
41
  export declare function setBlobCache(c: BlobCache | null): void;
42
+ /** The account's AGENTS.md or library changed outside the journal (a route
43
+ * that writes the file itself): publish it, as any other change of a scope. */
44
+ export declare function noteAccountFilesChanged(tenant: string): void;
42
45
  /** One file a step wrote back to the workspace (run-container.ts
43
46
  * applyContainerChanges): `base` is the sha of the folder's copy before the
44
47
  * write (null: new file), `after` the bytes now on the folder. */
@@ -213,7 +216,27 @@ export declare function reconcileAll(opts?: {
213
216
  * (until 13 Nov 2026: only the text files the editor lists, so a binary file
214
217
  * never reached a head and one the importer had put there was never updated
215
218
  * or removed — a run staged from the head was handed files deleted days ago). */
219
+ /** Bring the heads to this pod's folder (see reconcileNow), in turn with
220
+ * everything else that commits this workspace here: two at once would diff
221
+ * the same folder against the same head and race each other's publish. */
216
222
  export declare function reconcileWorkspace(tenant: string, workspace: string, by?: string): Promise<PublishResult | null>;
223
+ /**
224
+ * Bring this pod's copy of a workspace to its heads (FOL-126, the shared
225
+ * volume retired; revisions.mirror). What changed in the heads since the last
226
+ * sync is written or removed; what changed HERE since then is left as it is
227
+ * and handed to the reconcile, which publishes it against the version it was
228
+ * synced at. Never while this pod has changes of its own still to publish.
229
+ * A workspace whose heads are gone (deleted, renamed away) is removed here
230
+ * only if this pod's copy came from them.
231
+ */
232
+ export declare function syncFromHeads(tenant: string, workspace: string): Promise<"unchanged" | "synced" | "skipped" | "removed" | "absent">;
233
+ /** Every workspace with heads, and every copy here whose heads are gone. One
234
+ * failure does not stop the rest. */
235
+ export declare function syncAllFromHeads(): Promise<{
236
+ synced: number;
237
+ removed: number;
238
+ failed: number;
239
+ }>;
217
240
  /** One file of the workspace as its heads hold it: head → manifest → blob.
218
241
  * Null when there is no such file (or no head yet). */
219
242
  export declare function readAtHead(tenant: string, workspace: string, rel: string): Promise<Buffer | null>;