@foldrun/core 15.1.0 → 17.0.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 (52) hide show
  1. package/dist/src/a2a-publish.d.ts +7 -0
  2. package/dist/src/a2a-publish.js +15 -1
  3. package/dist/src/a2a-reach.d.ts +156 -0
  4. package/dist/src/a2a-reach.js +446 -0
  5. package/dist/src/browse-egress.d.ts +1 -1
  6. package/dist/src/browse-egress.js +7 -6
  7. package/dist/src/egress.d.ts +9 -0
  8. package/dist/src/env-names.d.ts +12 -0
  9. package/dist/src/env-names.js +49 -0
  10. package/dist/src/failure.d.ts +92 -0
  11. package/dist/src/failure.js +294 -0
  12. package/dist/src/frontmatter-fields.js +1 -1
  13. package/dist/src/install-helper.js +10 -5
  14. package/dist/src/network.js +1 -1
  15. package/dist/src/ops-log.js +4 -0
  16. package/dist/src/otel.d.ts +16 -1
  17. package/dist/src/otel.js +121 -5
  18. package/dist/src/platform.d.ts +8 -0
  19. package/dist/src/run-container.d.ts +88 -4
  20. package/dist/src/run-container.js +215 -26
  21. package/dist/src/run-event.d.ts +179 -0
  22. package/dist/src/run-event.js +473 -0
  23. package/dist/src/runner.js +35 -1
  24. package/dist/src/runtime.d.ts +116 -16
  25. package/dist/src/runtime.js +531 -44
  26. package/dist/src/scan.js +80 -18
  27. package/dist/src/search-egress.d.ts +58 -0
  28. package/dist/src/search-egress.js +88 -0
  29. package/dist/src/starter.js +4 -1
  30. package/dist/src/store.d.ts +34 -3
  31. package/dist/src/store.js +46 -10
  32. package/package.json +2 -1
  33. package/src/a2a-publish.ts +19 -1
  34. package/src/a2a-reach.ts +503 -0
  35. package/src/browse-egress.ts +8 -7
  36. package/src/egress.ts +7 -0
  37. package/src/env-names.ts +53 -0
  38. package/src/failure.ts +368 -0
  39. package/src/frontmatter-fields.ts +1 -1
  40. package/src/install-helper.ts +10 -5
  41. package/src/network.ts +1 -1
  42. package/src/ops-log.ts +4 -0
  43. package/src/otel.ts +122 -7
  44. package/src/platform.ts +8 -0
  45. package/src/run-container.ts +228 -29
  46. package/src/run-event.ts +563 -0
  47. package/src/runner.ts +32 -1
  48. package/src/runtime.ts +546 -45
  49. package/src/scan.ts +91 -20
  50. package/src/search-egress.ts +116 -0
  51. package/src/starter.ts +4 -1
  52. package/src/store.ts +75 -12
package/dist/src/scan.js CHANGED
@@ -32,7 +32,9 @@ import { resolveNetwork } from "./network.js";
32
32
  import { frontmatterProblems, schemaKindOf } from "./frontmatter-schema.js";
33
33
  import { parseRemotes } from "./a2a-remotes.js";
34
34
  import { isA2aPublished } from "./a2a-publish.js";
35
+ import { a2aTree, flowSecretCode } from "./a2a-reach.js";
35
36
  import { parseFlow, resolveEffort, parseMaxOutputTokens } from "./store.js";
37
+ import { reservedEnvName } from "./env-names.js";
36
38
  export const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
37
39
  export const SCAN_RULES = [
38
40
  {
@@ -90,13 +92,31 @@ export const SCAN_RULES = [
90
92
  id: "security/published-flow-trifecta",
91
93
  category: "security",
92
94
  level: "warn",
93
- title: "A flow published over A2A runs an agent that holds private data and can send it out",
94
- help: "An outside agent's message is untrusted input to every step of a published flow. A step whose agent also holds a secret, " +
95
- "an API or an MCP server, and can reach an open network, an outward tool or an API it may write to, can be told by the caller " +
96
- "where to send what it holds. Take a leg away from that agent (network: { level: trusted, allow: [...] }, split it, a hooks: gate), " +
97
- "or do not publish the flow.",
95
+ title: "A flow published over A2A runs an agent that holds private data — its answer, or its network, can carry it out",
96
+ help: "An outside agent's message is untrusted input to every step of a published flow, and the flow's answer goes back to that caller — " +
97
+ "so the answer is a way out too (5 Nov 2026). A step whose agent holds a secret, an API or an MCP server can be told by the caller " +
98
+ "to put what it holds or reads in its answer, or to send it to an open network, an outward tool or an API it may write to. A hooks: " +
99
+ "gate guards tool calls, not the answer. Give that agent only what a stranger may see, move the private part to a flow that is not " +
100
+ "published, or do not publish the flow.",
98
101
  owasp: ["ASI01", "ASI02", "ASI03"],
99
102
  },
103
+ {
104
+ // 5 Nov 2026 (FOL-112): the answer is a way out. A published flow's last
105
+ // step answers the outside caller, and an agent that holds a secret in
106
+ // its sandbox and may run code can be told to put the secret in it —
107
+ // no network needed. The platform refuses to publish such a flow unless
108
+ // an admin names the agent under `a2a.accept_risk`; this is check's half.
109
+ id: "security/published-flow-secret-code",
110
+ category: "security",
111
+ level: "warn",
112
+ title: "A flow published over A2A runs an agent that holds a secret and can run code",
113
+ help: "Its answer goes back to the outside caller, and code (Bash) can read every secret in the sandbox's environment — so a caller can ask " +
114
+ "for the secret in the reply. Take Bash away from that agent (disallowedTools: [Bash], or a step without code), take the secret away " +
115
+ "(or bind it to its sites with `foldrun secrets sites NAME host` so it never enters the sandbox), or have an admin accept the risk: " +
116
+ "`a2a: { accept_risk: [<agent>] }` (`foldrun a2a publish <flow> --accept-risk <agent>`). Until one of those, the platform refuses to " +
117
+ "publish the flow and refuses new A2A tasks for it.",
118
+ owasp: ["ASI01", "ASI03"],
119
+ },
100
120
  {
101
121
  id: "security/published-flow-ungated",
102
122
  category: "security",
@@ -267,6 +287,19 @@ export const SCAN_RULES = [
267
287
  "and the value itself is deployed and versioned in plain text. Put it in the vault (`foldrun secrets set NAME`), write the name, and rotate it.",
268
288
  owasp: ["ASI03"],
269
289
  },
290
+ {
291
+ // 5 Nov 2026 (FOL-130): a secret is exported to the sandbox under its name.
292
+ id: "secret/reserved-env-name",
293
+ category: "security",
294
+ level: "warn",
295
+ title: "A secret named after a variable that steers every program",
296
+ help: "A secret reaches the sandbox as an environment variable of the same name, so one called LD_PRELOAD, PATH, BASH_ENV, IFS, " +
297
+ "NODE_OPTIONS or PYTHONPATH replaces what every program the agent starts loads or looks up — almost never what was meant, and " +
298
+ "a value pointing into a folder the agent writes runs whatever is put there. Root's start-up never reads the step's environment, " +
299
+ "so this is the agent's own sandbox at stake, not the platform. Give the secret a name of its own (`STRIPE_KEY`, `CRM_TOKEN`) " +
300
+ "and have the script read that.",
301
+ owasp: ["ASI03", "ASI05"],
302
+ },
270
303
  {
271
304
  id: "check/ignore-needs-reason",
272
305
  category: "config",
@@ -689,6 +722,24 @@ function docKind(p) {
689
722
  return "tool";
690
723
  return null;
691
724
  }
725
+ // ── secret names that are not data ─────────────────────────────────────────
726
+ /** secret/reserved-env-name: an agent's or a tool's `secrets:` naming a
727
+ * variable that steers programs (env-names.ts). `${NAME}` reads as NAME. */
728
+ function scanSecretNames(f, data, lines, push) {
729
+ const raw = data.secrets;
730
+ const names = (Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [])
731
+ .filter((n) => typeof n === "string")
732
+ .map((n) => n.trim().replace(/^\$\{(.*)\}$/, "$1"));
733
+ for (const name of new Set(names)) {
734
+ const why = reservedEnvName(name);
735
+ if (!why)
736
+ continue;
737
+ const word = new RegExp(`(^|[^A-Za-z0-9_])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^A-Za-z0-9_]|$)`);
738
+ const from = keyLine(lines, "secrets");
739
+ const at = from ? (lines.slice(from - 1).findIndex((l) => word.test(l)) + from) || from : undefined;
740
+ push("secret/reserved-env-name", f.path, at, `reserved-env ${name}`, `secrets: ${name} — the secret is exported under that name, and ${why}. Rename it (and what reads it) to a name of its own`);
741
+ }
742
+ }
692
743
  // ── agents: what one can reach, taken together ─────────────────────────────
693
744
  const WRITE_METHODS = /\b(?:POST|PUT|PATCH|DELETE)\b/i;
694
745
  function scanAgents(agents, outward, toolDefs, push, networks) {
@@ -771,11 +822,11 @@ function stepAgents(s) {
771
822
  * what it holds (the trifecta, with the caller as the untrusted leg), and a
772
823
  * step that acts outside the workspace with no person before it.
773
824
  */
774
- function scanPublishedFlows(flows, legs, push) {
825
+ function scanPublishedFlows(flows, legs, tree, push) {
775
826
  for (const fl of flows) {
776
827
  let info;
777
828
  try {
778
- info = parseFlow(fl.file, fl.content);
829
+ info = parseFlow(fl.file.replace(/^.*\//, ""), fl.content); // named as the platform names it: leads, not flows/leads
779
830
  }
780
831
  catch {
781
832
  continue; // a flow that does not parse is check's finding
@@ -783,16 +834,25 @@ function scanPublishedFlows(flows, legs, push) {
783
834
  if (!isA2aPublished(info.a2a))
784
835
  continue;
785
836
  const at = keyLine(fl.lines, "a2a");
786
- const said = new Set();
787
- for (const step of info.steps) {
788
- for (const name of stepAgents(step)) {
789
- const l = legs.get(name);
790
- if (!l || said.has(name) || l.gated || !l.privateLeg.length || !l.outLeg.length)
791
- continue;
792
- said.add(name);
793
- push("security/published-flow-trifecta", fl.file, step.line ?? at, `published trifecta ${name}`, `${info.name} is published over A2A, so what an outside caller sends reaches ${name}, which holds ${l.privateLeg.slice(0, 3).join(", ")}${l.privateLeg.length > 3 ? ", …" : ""} ` +
794
- `and can reach ${l.outLeg.slice(0, 2).join(" and ")} — a caller can tell it where to send what it holds. Take a leg away from ${name}, or do not publish the flow`);
795
- }
837
+ // Each agent at the first step line that runs it; a sub-agent or a
838
+ // subflow's agent at the a2a: line.
839
+ const lineOf = (name) => info.steps.find((s) => !s.subflow && [s.agent, s.onFail, ...(s.delegate ?? [])].includes(name))?.line ?? at;
840
+ // The answer goes back to the caller (FOL-112): any private leg is
841
+ // enough, and a hooks: gate (which guards tool calls) does not close it.
842
+ for (const name of tree.flows.get(info.name)?.file === fl.file ? tree.agentsOf(info.name) : []) {
843
+ const l = legs.get(name);
844
+ if (!l || !l.privateLeg.length)
845
+ continue;
846
+ const out = !l.gated && l.outLeg.length ? ` and can reach ${l.outLeg.slice(0, 2).join(" and ")}` : "";
847
+ push("security/published-flow-trifecta", fl.file, lineOf(name), `published trifecta ${name}`, `${info.name} is published over A2A, so what an outside caller sends reaches ${name}, which holds ${l.privateLeg.slice(0, 3).join(", ")}${l.privateLeg.length > 3 ? ", …" : ""}${out} — ` +
848
+ `and the flow's answer goes back to that caller, so a caller can ask for what it holds. Give ${name} only what a stranger may see, or do not publish the flow`);
849
+ }
850
+ for (const e of flowSecretCode(tree, info.name)) {
851
+ const held = `${e.secrets.slice(0, 3).join(", ")}${e.secrets.length > 3 ? ", …" : ""}`;
852
+ push("security/published-flow-secret-code", fl.file, lineOf(e.agent), `published secret-code ${e.agent}`, e.accepted
853
+ ? `${e.agent} holds ${held} and can run code, and ${info.name} is published over A2A — accepted by an admin (a2a: accept_risk: [${e.agent}])`
854
+ : `${e.agent} holds ${held} and can run code (Bash), and ${info.name} is published over A2A — its answer goes back to the outside caller, who can ask for the secret in it. ` +
855
+ `Take Bash or the secret away from ${e.agent}, or have an admin accept it (a2a: accept_risk: [${e.agent}]); until then the platform refuses new A2A tasks for ${info.name}`, e.accepted ? "info" : undefined);
796
856
  }
797
857
  // Groups in order. A gate (an approval, or ask:, which is one with a
798
858
  // question) on any step of a group parks the run before ANY step of that
@@ -1114,6 +1174,8 @@ export function scanFiles(files, options = {}) {
1114
1174
  const kind = docKind(f.path);
1115
1175
  if (!kind)
1116
1176
  continue;
1177
+ if (kind === "agent" || kind === "tool")
1178
+ scanSecretNames(f, data, lines, push);
1117
1179
  if (kind === "agent") {
1118
1180
  const rel = f.path.replace(/^library\//, "");
1119
1181
  const name = /^agents\/([^/]+)\//.exec(rel)?.[1] ?? rel.replace(/^.*\/|\.md$/g, "");
@@ -1133,7 +1195,7 @@ export function scanFiles(files, options = {}) {
1133
1195
  // project.md is the older name the runtime still reads (Codex review, FOL-58).
1134
1196
  const workspaceMd = files.find((f) => f.path === "AGENTS.md") ?? files.find((f) => f.path === "project.md");
1135
1197
  const legs = scanAgents(agents, outward, toolDefs, push, { account: options.accountNetwork, workspace: workspaceMd ? frontOf(workspaceMd.content, "AGENTS.md")?.network : undefined });
1136
- scanPublishedFlows(flows, legs, push);
1198
+ scanPublishedFlows(flows, legs, a2aTree(files.filter((f) => isText(f) && !RUNTIME_WRITTEN.test(f.path)), { accountNetwork: options.accountNetwork }), push);
1137
1199
  // A workspace that names its own provider: does not run on the account's
1138
1200
  // choice, so the account's models say nothing about its efforts.
1139
1201
  const ownWorkspaceProvider = Boolean(workspaceMd && frontOf(workspaceMd.content, "AGENTS.md")?.provider);
@@ -0,0 +1,58 @@
1
+ import type { NetworkLevel } from "./network.ts";
2
+ /** The `web` actions that ask a search engine when no provider answers them. */
3
+ export declare const SEARCHING_ACTIONS: readonly ["search", "answer", "monitor"];
4
+ export type SearchingAction = (typeof SEARCHING_ACTIONS)[number];
5
+ /** The searching actions a provider answers instead of our engine, from an
6
+ * agent's resolved `web:` block (webConfig(...).raw) — the runner's reading
7
+ * of it: a search API or a model provider's own search for `search`, an
8
+ * answer or monitor provider for those. */
9
+ export declare function searchProvided(raw: Record<string, unknown>): SearchingAction[];
10
+ /** What the proxy is told on the grant: the door is open for this step, and
11
+ * at most this many searches go through it. */
12
+ export interface SearchDoorGrant {
13
+ max?: number;
14
+ }
15
+ /**
16
+ * May this step search through the egress proxy's door? The runner asks,
17
+ * from its own resolved config — never the pod's environment — and after
18
+ * the lease, so `enforce` is the effective one (the install's switch too).
19
+ *
20
+ * Only a step held to a restricted list: the others reach the engine as
21
+ * before. Only the actions our engine answers. And where the list was made
22
+ * narrow on purpose — level `none` (only what the step declares) or
23
+ * `defaults: false` (no trusted list) — the action must be written out in
24
+ * `web: {actions: [...]}`: a bare `tools: [web]` does not open a way out for
25
+ * a query that the list's author never named. Every searching action gives
26
+ * any program in the step that same way out (curl can use the door too).
27
+ */
28
+ export declare function searchDoorWanted(o: {
29
+ level: NetworkLevel;
30
+ /** The trusted list is part of the step's list (network: defaults). */
31
+ defaults: boolean;
32
+ /** Will the proxy refuse a site off the list (the lease's enforce)? */
33
+ enforce: boolean;
34
+ /** The step has the web tool. */
35
+ web: boolean;
36
+ /** The `web: {actions: [...]}` in force, or null for all. */
37
+ actions: readonly string[] | null | undefined;
38
+ /** The searching actions a provider answers instead of our engine. */
39
+ provided: readonly SearchingAction[];
40
+ /** The step's `limits:` (cascaded), for the door's own count. */
41
+ limits?: Record<string, number>;
42
+ }): {
43
+ door: SearchDoorGrant | null;
44
+ line?: string;
45
+ };
46
+ /** The trace lines for a held step that is not given the door. */
47
+ export declare const SEARCH_NONE_UNNAMED = "search: not offered \u2014 this step's network: none allows only what it declares, and its web: block names no actions, so search is not one of them. Write web: {actions: [search, \u2026]} to let it search through the egress proxy.";
48
+ export declare const SEARCH_NO_DEFAULTS_UNNAMED = "search: not offered \u2014 this step's network: drops the trusted list (defaults: false), and its web: block names no actions, so search is not one of them. Write web: {actions: [search, \u2026]} to let it search through the egress proxy.";
49
+ /** The trace line a held step that searches carries, at its start. */
50
+ export declare const SEARCH_DOOR_LINE = "search: through the egress proxy \u2014 the account's search engine answers this step's queries from a fixed set of engines; a query's words leave for those engines, and each query is a line in this trace; a result is data, and fetching it is held to network: like any other site";
51
+ /** On a held step's sandbox beside the door's address: the web tool reads
52
+ * it to keep the address's path and to mark results as outside content. */
53
+ export declare const SEARCH_HELD_ENV = "FOLDRUN_SEARCH_HELD";
54
+ /** The runner's word to the platform's driver: the search door's address
55
+ * for this step (its grant carries `search`). The driver takes it out of
56
+ * the sandbox's environment and, for a step it walls, points the web tool
57
+ * there (FOLDRUN_SEARCH_URL, with SEARCH_HELD_ENV). */
58
+ export declare const SEARCH_DOOR_ENV = "FOLDRUN_SEARCH_DOOR";
@@ -0,0 +1,88 @@
1
+ // Web search and `network:` (FOL-128, foldrun-docs/network.md#search).
2
+ //
3
+ // A step held to its list — restricted (trusted or none), enforced, on the
4
+ // k8s tier — runs in a `filtered` pod: Cilium lets it reach the egress proxy
5
+ // and nothing else, and (FOLDRUN_RUN_DNS_WALL) it has no DNS. The account's
6
+ // search pod (SearXNG, which has the world) is not reachable from there. A
7
+ // named search API (`web: {search: brave}`) already works: its host is a
8
+ // site the step declares, and its key is filled at the proxy. foldrun's own
9
+ // engine did not: the tool was pointed at an address the wall drops.
10
+ //
11
+ // The semantics chosen (owner, 5 Nov 2026: search should work there):
12
+ //
13
+ // - The account's engine is a platform service, not a site on the list.
14
+ // A held step reaches it through the egress proxy's search door
15
+ // (`/s/<lease>/search`), lease-authenticated, and only when this
16
+ // module says the step searches our engine (grant.search, which the
17
+ // runner writes and the pod cannot). Nothing is added to the list.
18
+ // - A query is a message out — to the public engines SearXNG asks — so
19
+ // the door holds what it may say: only a fixed set of index engines
20
+ // (none that fetches a URL named in the query, none that federates to
21
+ // instances a query could name), no engine or bang chosen inside the
22
+ // query, no URL and no `${NAME}` placeholder in it. Every query is a
23
+ // line in the run trace, so what left is on the record.
24
+ // - Results are data. Nothing in them widens the list: fetching a result
25
+ // is a CONNECT through the proxy, held to the list like any other.
26
+ //
27
+ // Everything else — a step whose list is open or only reported, a step on
28
+ // an executor that walls nothing — searches exactly as before.
29
+ import { readSearchSettings, resolveSearch } from "./providers.js";
30
+ import { resolveActionApi } from "./web-actions.js";
31
+ /** The `web` actions that ask a search engine when no provider answers them. */
32
+ export const SEARCHING_ACTIONS = ["search", "answer", "monitor"];
33
+ /** The searching actions a provider answers instead of our engine, from an
34
+ * agent's resolved `web:` block (webConfig(...).raw) — the runner's reading
35
+ * of it: a search API or a model provider's own search for `search`, an
36
+ * answer or monitor provider for those. */
37
+ export function searchProvided(raw) {
38
+ const out = [];
39
+ const search = resolveSearch(readSearchSettings(raw.search).rest, "search");
40
+ if (search.provider && !search.error)
41
+ out.push("search");
42
+ for (const a of ["answer", "monitor"])
43
+ if (resolveActionApi(a, raw[a]).provider)
44
+ out.push(a);
45
+ return out;
46
+ }
47
+ /**
48
+ * May this step search through the egress proxy's door? The runner asks,
49
+ * from its own resolved config — never the pod's environment — and after
50
+ * the lease, so `enforce` is the effective one (the install's switch too).
51
+ *
52
+ * Only a step held to a restricted list: the others reach the engine as
53
+ * before. Only the actions our engine answers. And where the list was made
54
+ * narrow on purpose — level `none` (only what the step declares) or
55
+ * `defaults: false` (no trusted list) — the action must be written out in
56
+ * `web: {actions: [...]}`: a bare `tools: [web]` does not open a way out for
57
+ * a query that the list's author never named. Every searching action gives
58
+ * any program in the step that same way out (curl can use the door too).
59
+ */
60
+ export function searchDoorWanted(o) {
61
+ if (o.level === "open" || !o.enforce || !o.web)
62
+ return { door: null };
63
+ const ours = SEARCHING_ACTIONS.filter((a) => (!o.actions || o.actions.includes(a)) && !o.provided.includes(a));
64
+ if (!ours.length)
65
+ return { door: null };
66
+ if ((o.level === "none" || !o.defaults) && !o.actions) {
67
+ return { door: null, line: o.level === "none" ? SEARCH_NONE_UNNAMED : SEARCH_NO_DEFAULTS_UNNAMED };
68
+ }
69
+ // limits: — `web` bounds every action; else each searching action's own
70
+ // key, and only when every one this step may use has one.
71
+ const lim = o.limits ?? {};
72
+ const each = ours.map((a) => lim[`web.${a}`]);
73
+ const max = typeof lim.web === "number" ? lim.web : each.every((n) => typeof n === "number") ? each.reduce((s, n) => s + n, 0) : undefined;
74
+ return { door: max !== undefined ? { max } : {}, line: SEARCH_DOOR_LINE };
75
+ }
76
+ /** The trace lines for a held step that is not given the door. */
77
+ export const SEARCH_NONE_UNNAMED = "search: not offered — this step's network: none allows only what it declares, and its web: block names no actions, so search is not one of them. Write web: {actions: [search, …]} to let it search through the egress proxy.";
78
+ export const SEARCH_NO_DEFAULTS_UNNAMED = "search: not offered — this step's network: drops the trusted list (defaults: false), and its web: block names no actions, so search is not one of them. Write web: {actions: [search, …]} to let it search through the egress proxy.";
79
+ /** The trace line a held step that searches carries, at its start. */
80
+ export const SEARCH_DOOR_LINE = "search: through the egress proxy — the account's search engine answers this step's queries from a fixed set of engines; a query's words leave for those engines, and each query is a line in this trace; a result is data, and fetching it is held to network: like any other site";
81
+ /** On a held step's sandbox beside the door's address: the web tool reads
82
+ * it to keep the address's path and to mark results as outside content. */
83
+ export const SEARCH_HELD_ENV = "FOLDRUN_SEARCH_HELD";
84
+ /** The runner's word to the platform's driver: the search door's address
85
+ * for this step (its grant carries `search`). The driver takes it out of
86
+ * the sandbox's environment and, for a step it walls, points the web tool
87
+ * there (FOLDRUN_SEARCH_URL, with SEARCH_HELD_ENV). */
88
+ export const SEARCH_DOOR_ENV = "FOLDRUN_SEARCH_DOOR";
@@ -326,6 +326,9 @@ agents reference them by name. Bind one to the sites it is for
326
326
  the egress proxy fills \`\${NAME}\` in requests to those sites alone. Which sites
327
327
  a sandbox may reach at all is \`network:\` — open for an agent that reads the web,
328
328
  the trusted list plus what it declares for every other (\`foldrun agent network\`).
329
+ A step held to its list still searches the web through the proxy's search door;
330
+ at \`none\` or \`defaults: false\` write it out — \`web: {actions: [search, fetch]}\` —
331
+ because a query's words leave (\`foldrun docs network\`).
329
332
 
330
333
  ## Talking to a deployed workspace
331
334
 
@@ -423,7 +426,7 @@ effort: low
423
426
  overlap: skip # skip | queue — what a second run does while one is live
424
427
  priority: normal # high | normal | low — where its runs stand in the queue
425
428
  compute: { vcpu: 4, memory: 8Gi, disk: 40Gi } # optional: what one run may hold at once
426
- a2a: { publish: false } # true: outside agents may call it over A2A (admin only; callers need an A2A key)
429
+ a2a: { publish: false } # true: outside agents may call it over A2A (admin only; callers need an A2A key; an agent with a secret and Bash needs accept_risk: [agent])
427
430
  ---
428
431
 
429
432
  1. [[researcher]] — Find three sources on {{topic}}.
@@ -16,7 +16,9 @@ import { frontmatterErrorText } from "./matter.ts";
16
16
  export declare function readFrontmatter(file: string): Record<string, unknown>;
17
17
  import { type A2aPublication } from "./a2a-publish.ts";
18
18
  import { type RemoteSpec } from "./a2a-remotes.ts";
19
+ import { type FailureExplained, type FailureFacts } from "./failure.ts";
19
20
  import { type NetworkPolicy } from "./network.ts";
21
+ import { type SearchingAction } from "./search-egress.ts";
20
22
  import { type WireFormat, type AuthShape } from "./providers.ts";
21
23
  /**
22
24
  * Single-workspace mode. When set, the workspace IS this directory — no
@@ -374,11 +376,19 @@ export interface AgentInfo {
374
376
  * its web providers' and its bound secrets' sites. */
375
377
  /** browses: the step may browse; enforceWanted and browseVendor are what
376
378
  * this folder says toward browseVerdict (FOL-110) — the install says the rest. */
379
+ /** search: this folder's half of search-egress.ts searchDoorWanted — the
380
+ * web tool, the actions written in web: (null: all), and the searching
381
+ * actions a provider answers (FOL-128). */
377
382
  network: NetworkPolicy & {
378
383
  readsWeb: boolean;
379
384
  browses: boolean;
380
385
  enforceWanted: boolean;
381
386
  browseVendor: string | null;
387
+ search: {
388
+ web: boolean;
389
+ actions: string[] | null;
390
+ provided: SearchingAction[];
391
+ };
382
392
  };
383
393
  /** Tools this agent declares inline rather than in `tools:` — `apis:`,
384
394
  * `scripts:` and `mcpServers:` names — which a limit may also name. */
@@ -1015,6 +1025,10 @@ export interface RunEvent {
1015
1025
  /** Set on a tool event a SUB-AGENT made (`subagents:`): its name. The
1016
1026
  * trace labels the call with it; cost stays the step's. */
1017
1027
  subagent?: string;
1028
+ /** Set on the error a platform security control wrote (failure.ts
1029
+ * securityStopEvent) — host-side only, never from a sandbox's output.
1030
+ * The customer is told the generic sentence and nothing else. */
1031
+ security?: true;
1018
1032
  /** Set on an error a failed check wrote — `verify:` (its headline and its
1019
1033
  * detail), `output: json`, a schema. What the runner reads to decline a
1020
1034
  * retry of an outward step whose tools already ran. */
@@ -1398,6 +1412,11 @@ export interface StepRecord {
1398
1412
  * #STARTUP_PHASES). Only the phases this step went through; null from
1399
1413
  * an executor that marks none, absent on steps from before 17 Oct 2026. */
1400
1414
  startup?: Record<string, number> | null;
1415
+ /** When the executor began the attempt those marks belong to — what they
1416
+ * count from, so a mark is an instant (FOL-122's run funnel). Set beside
1417
+ * `startup`; null where it is; absent before 5 Nov 2026, when readers
1418
+ * fall back to the attempt's own start, an estimate. */
1419
+ startupAt?: string | null;
1401
1420
  /** Which reservation class the sandbox held (small | large), and the
1402
1421
  * actual limits it held, as numbers. Facts of the step: a price is per
1403
1422
  * core-second, so what was reserved must come from the record, never
@@ -1409,6 +1428,10 @@ export interface StepRecord {
1409
1428
  memGiB: number;
1410
1429
  diskGiB?: number;
1411
1430
  } | null;
1431
+ /** Only on a record rebuilt from the runs index (runFromSummary), for a
1432
+ * failed step: the figures and refused sites its failure message names,
1433
+ * which a full record carries in `reserved`, `actual` and its events. */
1434
+ failureFacts?: FailureFacts;
1412
1435
  /** The agent's `resources:` as applied (resources.ts), when it set any:
1413
1436
  * why `reserved` differs from the class's figures. Absent before 26 Oct
1414
1437
  * 2026 and on steps of an agent that wrote none. */
@@ -1619,7 +1642,9 @@ export declare function runFilePath(tenant: string, workspace: string, runId: st
1619
1642
  * the same append-only file the charge lives in. The balance is untouched;
1620
1643
  * the story is complete.
1621
1644
  */
1622
- export declare function deleteRun(tenant: string, workspace: string, runId: string): boolean;
1645
+ export declare function deleteRun(tenant: string, workspace: string, runId: string, opts?: {
1646
+ pruned?: boolean;
1647
+ }): boolean;
1623
1648
  /** ledger.ts registers here — store cannot import it without a cycle, and
1624
1649
  * money must not depend on one. */
1625
1650
  declare let onRunDeleted: ((tenant: string, workspace: string, runId: string) => void) | undefined;
@@ -1683,6 +1708,9 @@ export interface RunSummaryStep {
1683
1708
  skipReason?: string;
1684
1709
  /** The last error event, for a failed step — what runFailure reads. */
1685
1710
  error?: string;
1711
+ /** For a failed step: the figures and refused sites runFailure's message
1712
+ * names (failure.ts). Absent before 5 Nov 2026. */
1713
+ failureFacts?: FailureFacts;
1686
1714
  item?: string;
1687
1715
  waitFor?: "event";
1688
1716
  ask?: string;
@@ -1818,10 +1846,13 @@ export declare function runDurationSecs(run: RunRecord): number | null;
1818
1846
  * sentence — "failed" with no reason makes every diagnosis start by opening
1819
1847
  * the run, and the answer was sitting in the record all along.
1820
1848
  */
1821
- export declare function runFailure(run: RunRecord): {
1849
+ export declare function runFailure(run: RunRecord): RunFailure | null;
1850
+ /** Why a failed run failed: the step, its last error, and what that means
1851
+ * for the customer (failure.ts). */
1852
+ export type RunFailure = {
1822
1853
  agent: string;
1823
1854
  reason: string;
1824
- } | null;
1855
+ } & FailureExplained;
1825
1856
  /**
1826
1857
  * The one-line outcome, pulled out of the reply that already says it.
1827
1858
  *
package/dist/src/store.js CHANGED
@@ -48,10 +48,12 @@ import { checkFilter } from "./trigger-filter.js";
48
48
  import { parseA2aPublish } from "./a2a-publish.js";
49
49
  import { parseRemotes, remoteNetworkHosts, A2A_LIMIT_KEY } from "./a2a-remotes.js";
50
50
  import { parseBudget, budgetProblem } from "./budget.js";
51
+ import { explainFailure, failureFactsOf } from "./failure.js";
51
52
  import { timezoneProblem } from "./clock.js";
52
53
  import { parseStepLimits, readLimits } from "./limits.js";
53
54
  import { networkEnforceWanted, networkProblems, resolveNetwork } from "./network.js";
54
55
  import { browseVendorOf } from "./browse-egress.js";
56
+ import { searchProvided } from "./search-egress.js";
55
57
  import { webProblems, webWarnings, runnerEngines, webConfig } from "./providers.js";
56
58
  import { actionProblems } from "./web-actions.js";
57
59
  import { languageProblem } from "./language.js";
@@ -1184,6 +1186,11 @@ export function listAgents(tenant, workspace) {
1184
1186
  enforceWanted: networkEnforceWanted(accountFront.network_enforce, workspaceFront.network_enforce),
1185
1187
  // The vendor its web.browse names, null for foldrun's own browser.
1186
1188
  browseVendor: browseVendorOf(webConfig(data, { ...accountFront, ...workspaceFront }).raw.browse),
1189
+ search: {
1190
+ web: tools.includes("web"),
1191
+ actions: actions ? [...actions] : null,
1192
+ provided: searchProvided(webConfig(data, { ...accountFront, ...workspaceFront }).raw),
1193
+ },
1187
1194
  };
1188
1195
  return {
1189
1196
  network,
@@ -2916,17 +2923,25 @@ export function runFilePath(tenant, workspace, runId) {
2916
2923
  * the same append-only file the charge lives in. The balance is untouched;
2917
2924
  * the story is complete.
2918
2925
  */
2919
- export function deleteRun(tenant, workspace, runId) {
2926
+ export function deleteRun(tenant, workspace, runId, opts = {}) {
2920
2927
  const file = runFilePath(tenant, workspace, runId);
2921
- if (!fs.existsSync(file))
2928
+ const dir = path.join(workspaceDir(tenant, workspace), "runs", runId);
2929
+ const had = fs.existsSync(file);
2930
+ if (!had && !fs.existsSync(dir))
2922
2931
  return false;
2932
+ // The folder first (archived outputs, captured calls), the record last:
2933
+ // a delete that fails halfway leaves the record, so a retry finds the run
2934
+ // and finishes — the other order left the content with nothing pointing
2935
+ // at it (Codex review, FOL-124).
2936
+ fs.rmSync(dir, { recursive: true, force: true });
2923
2937
  fs.rmSync(file, { force: true });
2924
- fs.rmSync(path.join(workspaceDir(tenant, workspace), "runs", runId), {
2925
- recursive: true,
2926
- force: true,
2927
- });
2928
2938
  noteRunDeleted(path.dirname(file), runId);
2929
- onRunDeleted?.(tenant, workspace, runId);
2939
+ if (!had)
2940
+ return true;
2941
+ // The retention window's prune (`pruned`) is policy, not a person erasing
2942
+ // history: no per-run ledger note. The charge stands either way.
2943
+ if (!opts.pruned)
2944
+ onRunDeleted?.(tenant, workspace, runId);
2930
2945
  return true;
2931
2946
  }
2932
2947
  /** ledger.ts registers here — store cannot import it without a cycle, and
@@ -3082,7 +3097,12 @@ export function summarizeRun(run) {
3082
3097
  ...(run.a2a ? { a2a: run.a2a } : {}),
3083
3098
  awaitingApproval: run.steps.some((s) => s.status === "awaiting-approval" && s.waitFor !== "event"),
3084
3099
  steps: run.steps.map((s) => {
3085
- const error = s.status === "failed" ? s.events.filter((e) => e.type === "error").at(-1)?.text : undefined;
3100
+ // A failed step's last error — and, on a run that failed between
3101
+ // groups, the budget's error the runner wrote onto the step before
3102
+ // (runFailure reads it from there; FOL-124, Codex review).
3103
+ const last = s.events.filter((e) => e.type === "error").at(-1)?.text;
3104
+ const error = s.status === "failed" || (run.status === "failed" && last !== undefined && /^over budget/.test(last)) ? last : undefined;
3105
+ const failureFacts = s.status === "failed" ? failureFactsOf(s) : undefined;
3086
3106
  return {
3087
3107
  agent: s.agent,
3088
3108
  group: s.group,
@@ -3092,6 +3112,7 @@ export function summarizeRun(run) {
3092
3112
  ...(s.computeSecs !== undefined ? { computeSecs: s.computeSecs } : {}),
3093
3113
  ...(s.skipReason ? { skipReason: s.skipReason } : {}),
3094
3114
  ...(error ? { error: error.slice(0, 500) } : {}),
3115
+ ...(failureFacts ? { failureFacts } : {}),
3095
3116
  ...(s.item ? { item: s.item } : {}),
3096
3117
  ...(s.waitFor ? { waitFor: s.waitFor } : {}),
3097
3118
  ...(s.ask ? { ask: s.ask } : {}),
@@ -3405,11 +3426,26 @@ export function runFailure(run) {
3405
3426
  if (run.status !== "failed")
3406
3427
  return null;
3407
3428
  const step = run.steps.find((s) => s.status === "failed");
3408
- if (!step)
3429
+ if (!step) {
3430
+ // A run can fail with no failed step: a budget hit or a stop between
3431
+ // groups writes its error onto the last step that ran (FOL-124).
3432
+ if (run.stopRequested) {
3433
+ const reason = `stopped by ${run.stoppedBy ?? "a person"}`;
3434
+ return { agent: run.steps.findLast((s) => s.status === "completed")?.agent ?? run.steps[0]?.agent ?? "run", reason, ...explainFailure(reason, null) };
3435
+ }
3436
+ const holder = run.steps.findLast((s) => s.events.some((e) => e.type === "error" && /^over budget/.test(e.text)));
3437
+ const text = holder?.events.filter((e) => e.type === "error" && /^over budget/.test(e.text)).at(-1)?.text;
3438
+ if (holder && text)
3439
+ return { agent: holder.agent, reason: text, ...explainFailure(text, null) };
3409
3440
  return null;
3441
+ }
3410
3442
  const errors = step.events.filter((e) => e.type === "error");
3411
3443
  const last = errors[errors.length - 1];
3412
- return { agent: step.agent, reason: last?.text ?? "failed without an error event" };
3444
+ const raw = last?.text ?? "failed without an error event";
3445
+ // The customer's sentence, its class and its fix (failure.ts, FOL-124).
3446
+ // A security stop's reason is that sentence too: nothing else is said.
3447
+ const explained = explainFailure(raw, step);
3448
+ return { agent: step.agent, reason: explained.kind === "security" ? explained.message : raw, ...explained };
3413
3449
  }
3414
3450
  /**
3415
3451
  * The one-line outcome, pulled out of the reply that already says it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "15.1.0",
3
+ "version": "17.0.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",
@@ -19,6 +19,7 @@
19
19
  ".",
20
20
  "./a2a-client",
21
21
  "./a2a-publish",
22
+ "./a2a-reach",
22
23
  "./a2a-remotes",
23
24
  "./agents-md",
24
25
  "./browser-pod",
@@ -8,6 +8,7 @@
8
8
  // examples: ["Leads for dentists in Perth"]
9
9
  // public_card: false # true: the card is readable without a key
10
10
  // input: { type: object, required: [city], properties: { city: { type: string } } }
11
+ // accept_risk: [researcher] # agents an admin accepted holding a secret while running code
11
12
  //
12
13
  // Publishing is the owner's decision, so it is written in the flow and nowhere
13
14
  // else, and changing it needs workspace:manage (foldrun-web
@@ -31,6 +32,11 @@ export interface A2aPublication {
31
32
  publicCard: boolean;
32
33
  /** A JSON Schema the request's data part must satisfy; null = any (or none). */
33
34
  input: Record<string, unknown> | boolean | null;
35
+ /** The agents of this flow an admin accepted holding a secret while they
36
+ * can run code (FOL-112): their answer goes back to the caller, so the
37
+ * platform refuses to publish such a flow unless each is named here.
38
+ * Absent when the block does not say `accept_risk:`. */
39
+ acceptRisk?: string[];
34
40
  }
35
41
 
36
42
  /** The bounds on what is published, and on what a caller may send. */
@@ -48,9 +54,14 @@ export const A2A_LIMITS = {
48
54
  /** What a task's answer carries back. */
49
55
  resultChars: 64_000,
50
56
  resultDataBytes: 256_000,
57
+ /** Agents named under accept_risk. */
58
+ acceptRisk: 50,
51
59
  } as const;
52
60
 
53
- const KEYS = ["publish", "name", "description", "examples", "public_card", "input"] as const;
61
+ /** One agent name: one path segment, as an agent's folder is. */
62
+ const ONE_NAME = /^[^/\\\0\s]+$/;
63
+
64
+ const KEYS = ["publish", "name", "description", "examples", "public_card", "input", "accept_risk"] as const;
54
65
 
55
66
  /** What is wrong with an `a2a:` value, each as a sentence. Empty: fine (or absent). */
56
67
  export function a2aPublishProblems(v: unknown): string[] {
@@ -88,6 +99,11 @@ export function a2aPublishProblems(v: unknown): string[] {
88
99
  if (size > A2A_LIMITS.inputSchemaBytes) out.push(`\`input\` is larger than ${A2A_LIMITS.inputSchemaBytes} bytes as JSON`);
89
100
  }
90
101
  }
102
+ if (o.accept_risk !== undefined && o.accept_risk !== null) {
103
+ const v = o.accept_risk;
104
+ if (!Array.isArray(v) || v.some((e) => typeof e !== "string" || !ONE_NAME.test(e.trim()))) out.push("`accept_risk` should be a list of agent names — the agents an admin accepted holding a secret while they can run code");
105
+ else if (v.length > A2A_LIMITS.acceptRisk) out.push(`\`accept_risk\` names more than ${A2A_LIMITS.acceptRisk} agents`);
106
+ }
91
107
  return out;
92
108
  }
93
109
 
@@ -111,6 +127,8 @@ export function parseA2aPublish(v: unknown): A2aPublication | null {
111
127
  examples: Array.isArray(o.examples) ? (o.examples as string[]).map((e) => e.trim()) : [],
112
128
  publicCard: o.public_card === true,
113
129
  input: o.input === undefined || o.input === null ? null : (o.input as Record<string, unknown> | boolean),
130
+ // Only when written: a block without it reads as it did before 5 Nov 2026.
131
+ ...(Array.isArray(o.accept_risk) ? { acceptRisk: [...new Set((o.accept_risk as string[]).map((e) => e.trim()))] } : {}),
114
132
  };
115
133
  }
116
134