@foldrun/core 15.1.0 → 16.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.
- package/dist/src/a2a-publish.d.ts +7 -0
- package/dist/src/a2a-publish.js +15 -1
- package/dist/src/a2a-reach.d.ts +156 -0
- package/dist/src/a2a-reach.js +446 -0
- package/dist/src/browse-egress.d.ts +1 -1
- package/dist/src/browse-egress.js +7 -6
- package/dist/src/env-names.d.ts +12 -0
- package/dist/src/env-names.js +49 -0
- package/dist/src/failure.d.ts +92 -0
- package/dist/src/failure.js +294 -0
- package/dist/src/frontmatter-fields.js +1 -1
- package/dist/src/install-helper.js +10 -5
- package/dist/src/network.js +1 -1
- package/dist/src/ops-log.js +4 -0
- package/dist/src/otel.d.ts +16 -1
- package/dist/src/otel.js +121 -5
- package/dist/src/run-container.d.ts +55 -3
- package/dist/src/run-container.js +109 -17
- package/dist/src/run-event.d.ts +179 -0
- package/dist/src/run-event.js +473 -0
- package/dist/src/runner.js +8 -1
- package/dist/src/runtime.d.ts +113 -16
- package/dist/src/runtime.js +528 -44
- package/dist/src/scan.js +80 -18
- package/dist/src/starter.js +1 -1
- package/dist/src/store.d.ts +25 -3
- package/dist/src/store.js +40 -10
- package/package.json +2 -1
- package/src/a2a-publish.ts +19 -1
- package/src/a2a-reach.ts +503 -0
- package/src/browse-egress.ts +8 -7
- package/src/env-names.ts +53 -0
- package/src/failure.ts +368 -0
- package/src/frontmatter-fields.ts +1 -1
- package/src/install-helper.ts +10 -5
- package/src/network.ts +1 -1
- package/src/ops-log.ts +4 -0
- package/src/otel.ts +122 -7
- package/src/run-container.ts +112 -21
- package/src/run-event.ts +563 -0
- package/src/runner.ts +8 -1
- package/src/runtime.ts +543 -45
- package/src/scan.ts +91 -20
- package/src/starter.ts +1 -1
- package/src/store.ts +59 -11
|
@@ -9,6 +9,11 @@ export interface A2aPublication {
|
|
|
9
9
|
publicCard: boolean;
|
|
10
10
|
/** A JSON Schema the request's data part must satisfy; null = any (or none). */
|
|
11
11
|
input: Record<string, unknown> | boolean | null;
|
|
12
|
+
/** The agents of this flow an admin accepted holding a secret while they
|
|
13
|
+
* can run code (FOL-112): their answer goes back to the caller, so the
|
|
14
|
+
* platform refuses to publish such a flow unless each is named here.
|
|
15
|
+
* Absent when the block does not say `accept_risk:`. */
|
|
16
|
+
acceptRisk?: string[];
|
|
12
17
|
}
|
|
13
18
|
/** The bounds on what is published, and on what a caller may send. */
|
|
14
19
|
export declare const A2A_LIMITS: {
|
|
@@ -25,6 +30,8 @@ export declare const A2A_LIMITS: {
|
|
|
25
30
|
/** What a task's answer carries back. */
|
|
26
31
|
readonly resultChars: 64000;
|
|
27
32
|
readonly resultDataBytes: 256000;
|
|
33
|
+
/** Agents named under accept_risk. */
|
|
34
|
+
readonly acceptRisk: 50;
|
|
28
35
|
};
|
|
29
36
|
/** What is wrong with an `a2a:` value, each as a sentence. Empty: fine (or absent). */
|
|
30
37
|
export declare function a2aPublishProblems(v: unknown): string[];
|
package/dist/src/a2a-publish.js
CHANGED
|
@@ -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
|
|
@@ -33,8 +34,12 @@ export const A2A_LIMITS = {
|
|
|
33
34
|
/** What a task's answer carries back. */
|
|
34
35
|
resultChars: 64_000,
|
|
35
36
|
resultDataBytes: 256_000,
|
|
37
|
+
/** Agents named under accept_risk. */
|
|
38
|
+
acceptRisk: 50,
|
|
36
39
|
};
|
|
37
|
-
|
|
40
|
+
/** One agent name: one path segment, as an agent's folder is. */
|
|
41
|
+
const ONE_NAME = /^[^/\\\0\s]+$/;
|
|
42
|
+
const KEYS = ["publish", "name", "description", "examples", "public_card", "input", "accept_risk"];
|
|
38
43
|
/** What is wrong with an `a2a:` value, each as a sentence. Empty: fine (or absent). */
|
|
39
44
|
export function a2aPublishProblems(v) {
|
|
40
45
|
if (v === undefined || v === null)
|
|
@@ -85,6 +90,13 @@ export function a2aPublishProblems(v) {
|
|
|
85
90
|
out.push(`\`input\` is larger than ${A2A_LIMITS.inputSchemaBytes} bytes as JSON`);
|
|
86
91
|
}
|
|
87
92
|
}
|
|
93
|
+
if (o.accept_risk !== undefined && o.accept_risk !== null) {
|
|
94
|
+
const v = o.accept_risk;
|
|
95
|
+
if (!Array.isArray(v) || v.some((e) => typeof e !== "string" || !ONE_NAME.test(e.trim())))
|
|
96
|
+
out.push("`accept_risk` should be a list of agent names — the agents an admin accepted holding a secret while they can run code");
|
|
97
|
+
else if (v.length > A2A_LIMITS.acceptRisk)
|
|
98
|
+
out.push(`\`accept_risk\` names more than ${A2A_LIMITS.acceptRisk} agents`);
|
|
99
|
+
}
|
|
88
100
|
return out;
|
|
89
101
|
}
|
|
90
102
|
/** One sentence for `foldrun check` (frontmatter-schema.ts), or null. */
|
|
@@ -108,6 +120,8 @@ export function parseA2aPublish(v) {
|
|
|
108
120
|
examples: Array.isArray(o.examples) ? o.examples.map((e) => e.trim()) : [],
|
|
109
121
|
publicCard: o.public_card === true,
|
|
110
122
|
input: o.input === undefined || o.input === null ? null : o.input,
|
|
123
|
+
// Only when written: a block without it reads as it did before 5 Nov 2026.
|
|
124
|
+
...(Array.isArray(o.accept_risk) ? { acceptRisk: [...new Set(o.accept_risk.map((e) => e.trim()))] } : {}),
|
|
111
125
|
};
|
|
112
126
|
}
|
|
113
127
|
/** Is this flow open to A2A callers (who also hold a key naming it)? */
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { type NetworkLevel } from "./network.ts";
|
|
2
|
+
import { type FlowInfo } from "./store.ts";
|
|
3
|
+
/** What one agent may reach, as a run would grant it. Every list sorted. */
|
|
4
|
+
export interface AgentReach {
|
|
5
|
+
/** Tool names granted: built-in groups expanded to the SDK's names, the
|
|
6
|
+
* author's own tools by name; `disallowedTools` taken away (by the names
|
|
7
|
+
* it lists, against the expanded ones — the runner's order); a `{X: ask}`
|
|
8
|
+
* entry (approval mode) is not a grant. `permissionMode: plan` leaves the
|
|
9
|
+
* read group and the author's own tools (the runner keeps API and script
|
|
10
|
+
* tools in plan mode), never Bash. */
|
|
11
|
+
tools: string[];
|
|
12
|
+
/** Bash is granted: it can run any code in its sandbox — read its
|
|
13
|
+
* environment, the files, and put what it found in its answer. */
|
|
14
|
+
runsCode: boolean;
|
|
15
|
+
/** Secrets that reach its sandbox's environment, as runner.ts declares
|
|
16
|
+
* them: its own `secrets:`; the ones its `apis:` name as `${NAME}`; a
|
|
17
|
+
* granted folder tool's `secrets:` and `${NAME}`s, when that tool's file
|
|
18
|
+
* is known; and the key of a web provider its (or its workspace's) `web:`
|
|
19
|
+
* names — `web: {search: exa}` declares EXA_API_KEY. A secret bound to sites is
|
|
20
|
+
* still counted: the scanner cannot see binding, and the binding is the
|
|
21
|
+
* vault's, changed elsewhere. */
|
|
22
|
+
secrets: string[];
|
|
23
|
+
network: {
|
|
24
|
+
level: NetworkLevel;
|
|
25
|
+
hosts: string[];
|
|
26
|
+
};
|
|
27
|
+
/** name → the spec as written (stable JSON): a changed spec can point
|
|
28
|
+
* somewhere new, so it counts as a change. */
|
|
29
|
+
apis: Record<string, string>;
|
|
30
|
+
mcpServers: Record<string, string>;
|
|
31
|
+
/** name → card URL. */
|
|
32
|
+
remotes: Record<string, string>;
|
|
33
|
+
/** name → the entry as written (stable JSON): a new script, or a changed
|
|
34
|
+
* command, is a change. */
|
|
35
|
+
scripts: Record<string, string>;
|
|
36
|
+
/** The author's own folder tools named in `tools:` → their definition as
|
|
37
|
+
* written (stable JSON), when the file is known: a changed base URL or
|
|
38
|
+
* MCP server is a change, as an inline API's is. */
|
|
39
|
+
toolSpecs: Record<string, string>;
|
|
40
|
+
subagents: string[];
|
|
41
|
+
/** Hooks that run at its tool calls — its own and its workspace's. Fewer
|
|
42
|
+
* is wider: a hook is a gate. */
|
|
43
|
+
hooks: string[];
|
|
44
|
+
/** permissionMode: plan — read-only until a person approves. */
|
|
45
|
+
plan: boolean;
|
|
46
|
+
/** sandbox: own — delegated to, it runs in its own sandbox with its own
|
|
47
|
+
* tools, secrets and network rather than inside its parent's caps. */
|
|
48
|
+
ownSandbox: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface ReachContext {
|
|
51
|
+
/** The workspace AGENTS.md frontmatter (network:, hooks:). */
|
|
52
|
+
workspace?: Record<string, unknown> | null;
|
|
53
|
+
/** The account AGENTS.md's `network:`. */
|
|
54
|
+
accountNetwork?: unknown;
|
|
55
|
+
/** A folder tool's frontmatter by name, when known — for its `secrets:`. */
|
|
56
|
+
toolDefs?: ReadonlyMap<string, Record<string, unknown>>;
|
|
57
|
+
}
|
|
58
|
+
/** What this agent's frontmatter grants, read the way runner.ts does. */
|
|
59
|
+
export declare function agentReach(front: Record<string, unknown>, ctx?: ReachContext): AgentReach;
|
|
60
|
+
/**
|
|
61
|
+
* What `after` can reach that `before` could not, one phrase each — empty
|
|
62
|
+
* when nothing widened. `before` null: the agent was not there (or not behind
|
|
63
|
+
* the flow), so everything it can reach is new.
|
|
64
|
+
*/
|
|
65
|
+
export declare function reachWidening(before: AgentReach | null, after: AgentReach): string[];
|
|
66
|
+
/**
|
|
67
|
+
* Every agent a run of this flow may put to work: each step's agent, its
|
|
68
|
+
* `on-fail:` rescuer and its `delegate:` choices; the steps of every
|
|
69
|
+
* `[[flow:…]]` it runs, all the way down; and the sub-agents each of those
|
|
70
|
+
* may delegate to. A sub-agent's tools are capped by its parent's in a shared
|
|
71
|
+
* sandbox but not with `sandbox: own`, so each one counts. `subagentsOf`
|
|
72
|
+
* names an agent's `subagents:` (null: no such agent); `flowOf` reads another
|
|
73
|
+
* flow by name (null: none). Sorted.
|
|
74
|
+
*/
|
|
75
|
+
export declare function flowAgents(flow: Pick<FlowInfo, "steps">, subagentsOf: (agent: string) => string[] | null, flowOf?: (name: string) => Pick<FlowInfo, "steps"> | null): string[];
|
|
76
|
+
/** The agents an admin accepted holding a secret while running code in this
|
|
77
|
+
* published flow (`a2a.accept_risk`). */
|
|
78
|
+
export declare function acceptedRisk(a2a: unknown): string[];
|
|
79
|
+
/** Is this flow open to A2A callers? (Its parsed `a2a:`.) */
|
|
80
|
+
export declare function publishedFlow(flow: Pick<FlowInfo, "a2a">): boolean;
|
|
81
|
+
/** One agent of a published flow that holds a secret and may run code. */
|
|
82
|
+
export interface SecretCodeExposure {
|
|
83
|
+
agent: string;
|
|
84
|
+
secrets: string[];
|
|
85
|
+
accepted: boolean;
|
|
86
|
+
}
|
|
87
|
+
/** The agents of a published flow that hold a secret and run code — each
|
|
88
|
+
* one a way for a caller to have the secret put in the answer. */
|
|
89
|
+
export declare function secretCodeExposures(agents: string[], reachOf: (agent: string) => AgentReach | null, accepted: string[]): SecretCodeExposure[];
|
|
90
|
+
/** The sentence a refusal and the dashboard say about one exposure. */
|
|
91
|
+
export declare function secretCodeSentence(flow: string, e: Pick<SecretCodeExposure, "agent" | "secrets">): string;
|
|
92
|
+
export interface TreeFile {
|
|
93
|
+
/** Workspace-relative (`agents/x/agent.md`), or `library/…` for the
|
|
94
|
+
* account's library. */
|
|
95
|
+
path: string;
|
|
96
|
+
content: string;
|
|
97
|
+
}
|
|
98
|
+
/** The A2A facts of one workspace tree. */
|
|
99
|
+
export interface A2aTree {
|
|
100
|
+
/** Every flow that parses, by name. */
|
|
101
|
+
flows: Map<string, {
|
|
102
|
+
file: string;
|
|
103
|
+
info: FlowInfo;
|
|
104
|
+
}>;
|
|
105
|
+
/** An agent's reach, or null when the tree has no such agent. */
|
|
106
|
+
reachOf: (agent: string) => AgentReach | null;
|
|
107
|
+
/** The agents a run of this flow may put to work (flowAgents). */
|
|
108
|
+
agentsOf: (flow: string) => string[];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Read a workspace tree (and, mixed in under `library/`, the account's
|
|
112
|
+
* library tools) as A2A sees it. An agent at agents/<n>/agent.md wins over a
|
|
113
|
+
* Claude Code file of the same name, as a deploy imports it; a workspace
|
|
114
|
+
* tool wins over the library's.
|
|
115
|
+
*/
|
|
116
|
+
export declare function a2aTree(files: TreeFile[], opts?: {
|
|
117
|
+
accountNetwork?: unknown;
|
|
118
|
+
}): A2aTree;
|
|
119
|
+
/** One published flow's secret-and-code exposures in a tree (empty when it
|
|
120
|
+
* is not published, or has none). */
|
|
121
|
+
export declare function flowSecretCode(tree: A2aTree, flow: string): SecretCodeExposure[];
|
|
122
|
+
/** What a write does to the flows published over A2A, compared tree to tree. */
|
|
123
|
+
export interface A2aWriteEffect {
|
|
124
|
+
/** An agent behind a flow published before or after the write that can
|
|
125
|
+
* reach more after it: an admin's change (N2). */
|
|
126
|
+
widened: {
|
|
127
|
+
flow: string;
|
|
128
|
+
agent: string;
|
|
129
|
+
what: string[];
|
|
130
|
+
}[];
|
|
131
|
+
/** An agent of a flow published after the write that holds a secret and
|
|
132
|
+
* runs code, with no `accept_risk` entry, and did not before the write
|
|
133
|
+
* (a new exposure): refused for everyone (N1). One already there is the
|
|
134
|
+
* serve path's to refuse, not a write's: a deploy that leaves it alone
|
|
135
|
+
* still goes through. */
|
|
136
|
+
unaccepted: {
|
|
137
|
+
flow: string;
|
|
138
|
+
agent: string;
|
|
139
|
+
secrets: string[];
|
|
140
|
+
}[];
|
|
141
|
+
/** `accept_risk` entries the write adds, with what each agent holds then —
|
|
142
|
+
* the audit's record of what was accepted. */
|
|
143
|
+
accepted: {
|
|
144
|
+
flow: string;
|
|
145
|
+
agent: string;
|
|
146
|
+
secrets: string[];
|
|
147
|
+
}[];
|
|
148
|
+
/** `accept_risk` names the write adds that no agent of the flow answers
|
|
149
|
+
* to: refused, so an entry never waits to cover whatever is given that
|
|
150
|
+
* name next. */
|
|
151
|
+
stale: {
|
|
152
|
+
flow: string;
|
|
153
|
+
agents: string[];
|
|
154
|
+
}[];
|
|
155
|
+
}
|
|
156
|
+
export declare function a2aWriteEffect(before: A2aTree, after: A2aTree): A2aWriteEffect;
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
// What an agent behind a published flow can reach, and what a change to it
|
|
2
|
+
// widens (FOL-112, 5 Nov 2026).
|
|
3
|
+
//
|
|
4
|
+
// A flow published over A2A takes its first input from an outside caller,
|
|
5
|
+
// and the last step's answer goes back to that caller. So the answer is a way
|
|
6
|
+
// out: an agent that holds a secret in its sandbox and may run code can be
|
|
7
|
+
// told to `echo $TOKEN` into its reply, with no network at all. Kousha's A2A
|
|
8
|
+
// e2e on dev (v2026.11.01.6) found two gaps around that:
|
|
9
|
+
//
|
|
10
|
+
// N1 check said nothing about such a flow — only the model's refusal kept
|
|
11
|
+
// the test secret in. Now the scanner warns, and the platform refuses
|
|
12
|
+
// to publish a flow (or to make a published one) whose agent holds a
|
|
13
|
+
// secret and runs code, unless an admin lists that agent under the
|
|
14
|
+
// flow's `a2a.accept_risk` (an admin's key, like all of `a2a:`).
|
|
15
|
+
// N2 publishing is an admin's, but an editor could then give the agent
|
|
16
|
+
// behind the flow more tools, secrets or network. Now a change that
|
|
17
|
+
// widens an agent of a published flow is an admin's too.
|
|
18
|
+
//
|
|
19
|
+
// Pure — fronts in, facts out, no fs — so the scanner (files), the platform's
|
|
20
|
+
// write doors (before/after trees) and the dashboard read the same answer.
|
|
21
|
+
import { refList, refNames } from "./refs.js";
|
|
22
|
+
import { TOOL_MAP, ownToolNames } from "./tool-names.js";
|
|
23
|
+
import { resolveNetwork } from "./network.js";
|
|
24
|
+
import { parseRemotes } from "./a2a-remotes.js";
|
|
25
|
+
import { isA2aPublished, parseA2aPublish } from "./a2a-publish.js";
|
|
26
|
+
import { configMatter } from "./matter.js";
|
|
27
|
+
import { readBrowseSettings, readSearchSettings, resolveSearch, webConfig } from "./providers.js";
|
|
28
|
+
import { NEWER_ACTIONS, resolveActionApi } from "./web-actions.js";
|
|
29
|
+
import { parseFlow } from "./store.js";
|
|
30
|
+
const SECRET_NAME = /^[A-Z][A-Z0-9_]*$/;
|
|
31
|
+
/** Same value, whatever order a mapping's keys were written in. */
|
|
32
|
+
function stable(value) {
|
|
33
|
+
if (value === undefined)
|
|
34
|
+
return "undefined";
|
|
35
|
+
if (value === null || typeof value !== "object")
|
|
36
|
+
return JSON.stringify(value);
|
|
37
|
+
if (value instanceof Date)
|
|
38
|
+
return JSON.stringify(value.toISOString());
|
|
39
|
+
if (Array.isArray(value))
|
|
40
|
+
return `[${value.map(stable).join(",")}]`;
|
|
41
|
+
const o = value;
|
|
42
|
+
return `{${Object.keys(o).sort().map((k) => `${JSON.stringify(k)}:${stable(o[k])}`).join(",")}}`;
|
|
43
|
+
}
|
|
44
|
+
const sorted = (xs) => [...new Set(xs)].sort();
|
|
45
|
+
const listOf = (v) => (Array.isArray(v) ? v.map(String) : typeof v === "string" && v.trim() ? v.split(",").map((s) => s.trim()).filter(Boolean) : []);
|
|
46
|
+
/** What this agent's frontmatter grants, read the way runner.ts does. */
|
|
47
|
+
export function agentReach(front, ctx = {}) {
|
|
48
|
+
const plan = front.permissionMode === "plan";
|
|
49
|
+
const denied = new Set(refNames(front.disallowedTools));
|
|
50
|
+
const granted = [];
|
|
51
|
+
const own = [];
|
|
52
|
+
for (const ref of refList(front.tools)) {
|
|
53
|
+
if (ref.mode === "ask")
|
|
54
|
+
continue; // approval mode: the runner does not grant it
|
|
55
|
+
if (!ref.linked && TOOL_MAP[ref.name])
|
|
56
|
+
granted.push(...TOOL_MAP[ref.name]);
|
|
57
|
+
else {
|
|
58
|
+
granted.push(ref.name);
|
|
59
|
+
if (ref.linked || !TOOL_MAP[ref.name])
|
|
60
|
+
own.push(ref.name);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// `install` is every agent's unless plan mode or disallowedTools: [install]
|
|
64
|
+
// takes it away (runner.ts, install-tool.ts): dropping that deny widens.
|
|
65
|
+
if (!plan)
|
|
66
|
+
granted.push("install");
|
|
67
|
+
const tools = plan ? sorted([...TOOL_MAP.read, ...own].filter((t) => !denied.has(t) && t !== "Bash" && t !== "install")) : sorted(granted.filter((t) => !denied.has(t)));
|
|
68
|
+
const runsCode = tools.includes("Bash");
|
|
69
|
+
const apis = {};
|
|
70
|
+
if (Array.isArray(front.apis)) {
|
|
71
|
+
front.apis.forEach((a, i) => {
|
|
72
|
+
const name = a && typeof a === "object" && typeof a.name === "string" ? a.name : `#${i + 1}`;
|
|
73
|
+
apis[name] = stable(a);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const mcpServers = {};
|
|
77
|
+
if (front.mcpServers && typeof front.mcpServers === "object" && !Array.isArray(front.mcpServers)) {
|
|
78
|
+
for (const [k, v] of Object.entries(front.mcpServers))
|
|
79
|
+
mcpServers[k] = stable(v);
|
|
80
|
+
}
|
|
81
|
+
const remotes = {};
|
|
82
|
+
for (const r of parseRemotes(front.remotes))
|
|
83
|
+
remotes[r.name] = r.card;
|
|
84
|
+
const secrets = new Set(listOf(front.secrets));
|
|
85
|
+
const named = (v) => {
|
|
86
|
+
for (const m of (JSON.stringify(v ?? null) ?? "").matchAll(/\$\{([A-Z][A-Z0-9_]*)\}/g))
|
|
87
|
+
secrets.add(m[1]);
|
|
88
|
+
};
|
|
89
|
+
named(front.apis);
|
|
90
|
+
// Every folder tool `tools:` names — ask-mode and disallowed ones too: the
|
|
91
|
+
// runner resolves them (ownToolNames) and loads their secrets into the
|
|
92
|
+
// step's environment before it filters what may be called (Codex review).
|
|
93
|
+
const toolSpecs = {};
|
|
94
|
+
for (const name of ownToolNames(front)) {
|
|
95
|
+
const def = ctx.toolDefs?.get(name);
|
|
96
|
+
if (!def)
|
|
97
|
+
continue;
|
|
98
|
+
toolSpecs[name] = stable(def);
|
|
99
|
+
for (const s of listOf(def.secrets))
|
|
100
|
+
if (SECRET_NAME.test(s))
|
|
101
|
+
secrets.add(s);
|
|
102
|
+
named(def);
|
|
103
|
+
}
|
|
104
|
+
for (const s of webSecrets(front, ctx.workspace ?? undefined))
|
|
105
|
+
secrets.add(s);
|
|
106
|
+
const scripts = {};
|
|
107
|
+
for (const [i, e] of (Array.isArray(front.scripts) ? front.scripts : listOf(front.scripts)).entries()) {
|
|
108
|
+
const name = typeof e === "string" ? e : e && typeof e === "object" && typeof e.name === "string" ? e.name : `#${i + 1}`;
|
|
109
|
+
scripts[name] = stable(e);
|
|
110
|
+
}
|
|
111
|
+
// The runner's own test (runner.ts, the network: lease): the web tool
|
|
112
|
+
// granted, and fetch or browse among its actions (all, when unsaid).
|
|
113
|
+
let actions = null;
|
|
114
|
+
try {
|
|
115
|
+
actions = webConfig(front, ctx.workspace ?? undefined).actions;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
actions = null;
|
|
119
|
+
}
|
|
120
|
+
const readsWeb = tools.includes("web") && (!actions || actions.some((a) => a === "fetch" || a === "browse"));
|
|
121
|
+
// Hosts a grant implies (an API's base, an MCP server's url, a remote's
|
|
122
|
+
// card): the runner adds them to the list, so a new one is a wider list.
|
|
123
|
+
const implied = [];
|
|
124
|
+
const hostOf = (u) => {
|
|
125
|
+
if (typeof u !== "string")
|
|
126
|
+
return;
|
|
127
|
+
try {
|
|
128
|
+
implied.push(new URL(u).hostname);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// not a URL: nothing implied
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
for (const a of Array.isArray(front.apis) ? front.apis : [])
|
|
135
|
+
hostOf(a?.base);
|
|
136
|
+
for (const m of Object.values((front.mcpServers && typeof front.mcpServers === "object" ? front.mcpServers : {})))
|
|
137
|
+
hostOf(m?.url);
|
|
138
|
+
for (const r of Object.values(remotes))
|
|
139
|
+
hostOf(r);
|
|
140
|
+
for (const name of Object.keys(toolSpecs)) {
|
|
141
|
+
const def = ctx.toolDefs?.get(name);
|
|
142
|
+
hostOf(def?.base);
|
|
143
|
+
hostOf(def?.url);
|
|
144
|
+
}
|
|
145
|
+
const net = resolveNetwork({ account: ctx.accountNetwork, workspace: ctx.workspace?.network, agent: front.network, readsWeb, implied });
|
|
146
|
+
return {
|
|
147
|
+
tools,
|
|
148
|
+
runsCode,
|
|
149
|
+
secrets: sorted([...secrets].filter((s) => s.trim())),
|
|
150
|
+
network: { level: net.level, hosts: sorted(net.hosts) },
|
|
151
|
+
apis,
|
|
152
|
+
mcpServers,
|
|
153
|
+
remotes,
|
|
154
|
+
scripts,
|
|
155
|
+
toolSpecs,
|
|
156
|
+
subagents: sorted(refNames(front.subagents)),
|
|
157
|
+
hooks: sorted([...refNames(front.hooks), ...refNames(ctx.workspace?.hooks)]),
|
|
158
|
+
plan,
|
|
159
|
+
ownSandbox: front.sandbox === "own",
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** The vault names a `web:` block declares — runner.ts's `declared` list:
|
|
163
|
+
* a direct search, fetch or browse API's key, a newer action's provider
|
|
164
|
+
* key, your own proxy for a vendor's session. Read loosely: a block that
|
|
165
|
+
* does not resolve declares nothing (check reports it). */
|
|
166
|
+
function webSecrets(front, workspace) {
|
|
167
|
+
try {
|
|
168
|
+
const web = webConfig(front, workspace);
|
|
169
|
+
const out = [];
|
|
170
|
+
const browse = readBrowseSettings(web.raw.browse);
|
|
171
|
+
const proxy = browse.settings.vendor_session?.proxy;
|
|
172
|
+
if (proxy && typeof proxy === "object" && typeof proxy.own === "string")
|
|
173
|
+
out.push(proxy.own);
|
|
174
|
+
for (const c of [resolveSearch(readSearchSettings(web.raw.search).rest, "search"), resolveSearch(web.raw.fetch, "fetch"), resolveSearch(browse.rest, "browse")]) {
|
|
175
|
+
if (c.shape === "direct" && c.secret && !c.error)
|
|
176
|
+
out.push(c.secret);
|
|
177
|
+
}
|
|
178
|
+
for (const action of NEWER_ACTIONS) {
|
|
179
|
+
const c = resolveActionApi(action, web.raw[action]);
|
|
180
|
+
if (c.provider && c.secret)
|
|
181
|
+
out.push(c.secret);
|
|
182
|
+
}
|
|
183
|
+
return out.filter((n) => SECRET_NAME.test(n));
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const OPENNESS = { none: 0, trusted: 1, open: 2 };
|
|
190
|
+
/**
|
|
191
|
+
* What `after` can reach that `before` could not, one phrase each — empty
|
|
192
|
+
* when nothing widened. `before` null: the agent was not there (or not behind
|
|
193
|
+
* the flow), so everything it can reach is new.
|
|
194
|
+
*/
|
|
195
|
+
export function reachWidening(before, after) {
|
|
196
|
+
const out = [];
|
|
197
|
+
const added = (what, a, b) => {
|
|
198
|
+
const extra = b.filter((x) => !a.includes(x));
|
|
199
|
+
if (extra.length)
|
|
200
|
+
out.push(`${what} ${extra.join(", ")}`);
|
|
201
|
+
};
|
|
202
|
+
const b = before;
|
|
203
|
+
if (!b) {
|
|
204
|
+
if (after.tools.length)
|
|
205
|
+
out.push(`tools ${after.tools.join(", ")}`);
|
|
206
|
+
if (after.secrets.length)
|
|
207
|
+
out.push(`secrets ${after.secrets.join(", ")}`);
|
|
208
|
+
if (after.network.level !== "none")
|
|
209
|
+
out.push(`network ${after.network.level}`);
|
|
210
|
+
for (const k of ["apis", "mcpServers", "remotes"])
|
|
211
|
+
if (Object.keys(after[k]).length)
|
|
212
|
+
out.push(`${k} ${Object.keys(after[k]).sort().join(", ")}`);
|
|
213
|
+
if (Object.keys(after.scripts).length)
|
|
214
|
+
out.push(`scripts ${Object.keys(after.scripts).sort().join(", ")}`);
|
|
215
|
+
if (after.subagents.length)
|
|
216
|
+
out.push(`subagents ${after.subagents.join(", ")}`);
|
|
217
|
+
return out.length ? out : ["a new agent behind the flow"];
|
|
218
|
+
}
|
|
219
|
+
added("tools", b.tools, after.tools);
|
|
220
|
+
added("secrets", b.secrets, after.secrets);
|
|
221
|
+
if (OPENNESS[after.network.level] > OPENNESS[b.network.level])
|
|
222
|
+
out.push(`network ${b.network.level} → ${after.network.level}`);
|
|
223
|
+
else if (after.network.level !== "open")
|
|
224
|
+
added("network sites", b.network.hosts, after.network.hosts);
|
|
225
|
+
for (const k of ["apis", "mcpServers", "remotes", "scripts", "toolSpecs"]) {
|
|
226
|
+
const changed = Object.keys(after[k]).filter((n) => b[k][n] !== after[k][n]).sort();
|
|
227
|
+
// A new folder tool is already a new tool above; here only a changed one.
|
|
228
|
+
const said = k === "toolSpecs" ? changed.filter((n) => n in b[k]) : changed;
|
|
229
|
+
if (said.length)
|
|
230
|
+
out.push(`${k === "toolSpecs" ? "tools" : k} ${said.map((n) => (n in b[k] ? `${n} (changed)` : n)).join(", ")}`);
|
|
231
|
+
}
|
|
232
|
+
added("subagents", b.subagents, after.subagents);
|
|
233
|
+
const gone = b.hooks.filter((h) => !after.hooks.includes(h));
|
|
234
|
+
if (gone.length)
|
|
235
|
+
out.push(`hooks removed: ${gone.join(", ")}`);
|
|
236
|
+
if (b.plan && !after.plan)
|
|
237
|
+
out.push("permissionMode: plan removed");
|
|
238
|
+
if (!b.ownSandbox && after.ownSandbox)
|
|
239
|
+
out.push("sandbox: own");
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Every agent a run of this flow may put to work: each step's agent, its
|
|
244
|
+
* `on-fail:` rescuer and its `delegate:` choices; the steps of every
|
|
245
|
+
* `[[flow:…]]` it runs, all the way down; and the sub-agents each of those
|
|
246
|
+
* may delegate to. A sub-agent's tools are capped by its parent's in a shared
|
|
247
|
+
* sandbox but not with `sandbox: own`, so each one counts. `subagentsOf`
|
|
248
|
+
* names an agent's `subagents:` (null: no such agent); `flowOf` reads another
|
|
249
|
+
* flow by name (null: none). Sorted.
|
|
250
|
+
*/
|
|
251
|
+
export function flowAgents(flow, subagentsOf, flowOf = () => null) {
|
|
252
|
+
const seen = new Set();
|
|
253
|
+
const queue = [];
|
|
254
|
+
const flowsSeen = new Set();
|
|
255
|
+
const walk = (f) => {
|
|
256
|
+
for (const s of f.steps ?? []) {
|
|
257
|
+
if (s.subflow) {
|
|
258
|
+
if (flowsSeen.has(s.subflow))
|
|
259
|
+
continue;
|
|
260
|
+
flowsSeen.add(s.subflow);
|
|
261
|
+
const sub = flowOf(s.subflow);
|
|
262
|
+
if (sub)
|
|
263
|
+
walk(sub);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
for (const n of [s.agent, ...(s.onFail ? [s.onFail] : []), ...(s.delegate ?? [])])
|
|
267
|
+
if (n)
|
|
268
|
+
queue.push(n);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
walk(flow);
|
|
272
|
+
while (queue.length) {
|
|
273
|
+
const n = queue.shift();
|
|
274
|
+
if (seen.has(n))
|
|
275
|
+
continue;
|
|
276
|
+
seen.add(n);
|
|
277
|
+
for (const s of subagentsOf(n) ?? [])
|
|
278
|
+
if (!seen.has(s))
|
|
279
|
+
queue.push(s);
|
|
280
|
+
}
|
|
281
|
+
return [...seen].sort();
|
|
282
|
+
}
|
|
283
|
+
/** The agents an admin accepted holding a secret while running code in this
|
|
284
|
+
* published flow (`a2a.accept_risk`). */
|
|
285
|
+
export function acceptedRisk(a2a) {
|
|
286
|
+
return parseA2aPublish(a2a)?.acceptRisk ?? [];
|
|
287
|
+
}
|
|
288
|
+
/** Is this flow open to A2A callers? (Its parsed `a2a:`.) */
|
|
289
|
+
export function publishedFlow(flow) {
|
|
290
|
+
return isA2aPublished(flow.a2a);
|
|
291
|
+
}
|
|
292
|
+
/** The agents of a published flow that hold a secret and run code — each
|
|
293
|
+
* one a way for a caller to have the secret put in the answer. */
|
|
294
|
+
export function secretCodeExposures(agents, reachOf, accepted) {
|
|
295
|
+
const out = [];
|
|
296
|
+
for (const a of agents) {
|
|
297
|
+
const r = reachOf(a);
|
|
298
|
+
if (!r || !r.runsCode || !r.secrets.length)
|
|
299
|
+
continue;
|
|
300
|
+
out.push({ agent: a, secrets: r.secrets, accepted: accepted.includes(a) });
|
|
301
|
+
}
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
304
|
+
/** The sentence a refusal and the dashboard say about one exposure. */
|
|
305
|
+
export function secretCodeSentence(flow, e) {
|
|
306
|
+
const held = `${e.secrets.slice(0, 3).join(", ")}${e.secrets.length > 3 ? ", …" : ""}`;
|
|
307
|
+
return `${e.agent} holds ${held} and can run code (Bash), and ${flow} is published over A2A — its answer goes back to the outside caller, who can ask for the secret in it`;
|
|
308
|
+
}
|
|
309
|
+
/** Frontmatter as the runtime reads an agent, a flow or AGENTS.md (job
|
|
310
|
+
* blocks folded): null when there is none or YAML cannot read it. */
|
|
311
|
+
function frontOf(content) {
|
|
312
|
+
if (!/^\uFEFF?---\r?\n/.test(content))
|
|
313
|
+
return null;
|
|
314
|
+
try {
|
|
315
|
+
const d = configMatter(content).data;
|
|
316
|
+
return d && typeof d === "object" && !Array.isArray(d) ? d : null;
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const AGENT_FILE = /^agents\/([^/]+)\/agent\.md$/;
|
|
323
|
+
const CLAUDE_AGENT = /^\.(?:claude|agents)\/agents\/([^/]+)\.md$/;
|
|
324
|
+
const FLOW_FILE = /^flows\/([^/]+)\.md$/;
|
|
325
|
+
const TOOL_FILE = /^(?:library\/)?tools\/(?:([^/]+)\/tool|([^/]+))\.md$/;
|
|
326
|
+
/**
|
|
327
|
+
* Read a workspace tree (and, mixed in under `library/`, the account's
|
|
328
|
+
* library tools) as A2A sees it. An agent at agents/<n>/agent.md wins over a
|
|
329
|
+
* Claude Code file of the same name, as a deploy imports it; a workspace
|
|
330
|
+
* tool wins over the library's.
|
|
331
|
+
*/
|
|
332
|
+
export function a2aTree(files, opts = {}) {
|
|
333
|
+
const agents = new Map();
|
|
334
|
+
const claude = new Map();
|
|
335
|
+
const tools = new Map();
|
|
336
|
+
const libTools = new Map();
|
|
337
|
+
const flows = new Map();
|
|
338
|
+
let workspace = null;
|
|
339
|
+
let project = null;
|
|
340
|
+
for (const f of files) {
|
|
341
|
+
const rel = f.path.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
342
|
+
let m;
|
|
343
|
+
if (rel === "AGENTS.md")
|
|
344
|
+
workspace = frontOf(f.content) ?? {};
|
|
345
|
+
else if (rel === "project.md")
|
|
346
|
+
project = frontOf(f.content) ?? {};
|
|
347
|
+
else if ((m = AGENT_FILE.exec(rel)))
|
|
348
|
+
agents.set(m[1], frontOf(f.content) ?? {});
|
|
349
|
+
else if ((m = CLAUDE_AGENT.exec(rel)))
|
|
350
|
+
claude.set(m[1], frontOf(f.content) ?? {});
|
|
351
|
+
else if ((m = FLOW_FILE.exec(rel))) {
|
|
352
|
+
try {
|
|
353
|
+
const info = parseFlow(`${m[1]}.md`, f.content);
|
|
354
|
+
if (!flows.has(info.name))
|
|
355
|
+
flows.set(info.name, { file: rel, info });
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
// a flow that does not parse runs nothing; check reports it
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else if ((m = TOOL_FILE.exec(rel))) {
|
|
362
|
+
const d = frontOf(f.content) ?? {};
|
|
363
|
+
const name = typeof d.name === "string" && d.name.trim() ? d.name.trim() : (m[1] ?? m[2]);
|
|
364
|
+
(rel.startsWith("library/") ? libTools : tools).set(name, d);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
for (const [n, d] of claude)
|
|
368
|
+
if (!agents.has(n))
|
|
369
|
+
agents.set(n, d);
|
|
370
|
+
const toolDefs = new Map([...libTools, ...tools]);
|
|
371
|
+
const ws = workspace ?? project;
|
|
372
|
+
const reaches = new Map();
|
|
373
|
+
const reachOf = (agent) => {
|
|
374
|
+
const front = agents.get(agent);
|
|
375
|
+
if (!front)
|
|
376
|
+
return null;
|
|
377
|
+
let r = reaches.get(agent);
|
|
378
|
+
if (!r)
|
|
379
|
+
reaches.set(agent, (r = agentReach(front, { workspace: ws, accountNetwork: opts.accountNetwork, toolDefs })));
|
|
380
|
+
return r;
|
|
381
|
+
};
|
|
382
|
+
const agentsOf = (flow) => {
|
|
383
|
+
const f = flows.get(flow);
|
|
384
|
+
if (!f)
|
|
385
|
+
return [];
|
|
386
|
+
return flowAgents(f.info, (a) => (agents.has(a) ? reachOf(a).subagents : null), (n) => flows.get(n)?.info ?? null);
|
|
387
|
+
};
|
|
388
|
+
return { flows, reachOf, agentsOf };
|
|
389
|
+
}
|
|
390
|
+
/** One published flow's secret-and-code exposures in a tree (empty when it
|
|
391
|
+
* is not published, or has none). */
|
|
392
|
+
export function flowSecretCode(tree, flow) {
|
|
393
|
+
const f = tree.flows.get(flow);
|
|
394
|
+
if (!f || !isA2aPublished(f.info.a2a))
|
|
395
|
+
return [];
|
|
396
|
+
return secretCodeExposures(tree.agentsOf(flow), tree.reachOf, f.info.a2a.acceptRisk ?? []);
|
|
397
|
+
}
|
|
398
|
+
export function a2aWriteEffect(before, after) {
|
|
399
|
+
const out = { widened: [], unaccepted: [], accepted: [], stale: [] };
|
|
400
|
+
const names = [...new Set([...before.flows.keys(), ...after.flows.keys()])].sort();
|
|
401
|
+
for (const flow of names) {
|
|
402
|
+
const b = before.flows.get(flow);
|
|
403
|
+
const a = after.flows.get(flow);
|
|
404
|
+
const pubBefore = Boolean(b && isA2aPublished(b.info.a2a));
|
|
405
|
+
const pubAfter = Boolean(a && isA2aPublished(a.info.a2a));
|
|
406
|
+
if (!pubBefore && !pubAfter)
|
|
407
|
+
continue;
|
|
408
|
+
const agentsBefore = pubBefore ? before.agentsOf(flow) : [];
|
|
409
|
+
const agentsAfter = a ? after.agentsOf(flow) : [];
|
|
410
|
+
// N2 — only a flow that was published already: publishing one is an
|
|
411
|
+
// admin's change by itself (a2a: is policy).
|
|
412
|
+
if (pubBefore && a) {
|
|
413
|
+
for (const agent of agentsAfter) {
|
|
414
|
+
const ra = after.reachOf(agent);
|
|
415
|
+
if (!ra)
|
|
416
|
+
continue;
|
|
417
|
+
const rb = agentsBefore.includes(agent) ? before.reachOf(agent) : null;
|
|
418
|
+
const what = reachWidening(rb, ra);
|
|
419
|
+
if (what.length)
|
|
420
|
+
out.widened.push({ flow, agent, what });
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (!pubAfter || !a)
|
|
424
|
+
continue;
|
|
425
|
+
const accepted = a.info.a2a?.acceptRisk ?? [];
|
|
426
|
+
const acceptedBefore = pubBefore ? (b.info.a2a?.acceptRisk ?? []) : [];
|
|
427
|
+
// Stale: a name the write adds that no agent of the flow answers to. One
|
|
428
|
+
// left behind when a step went is not refused — an editor may remove a
|
|
429
|
+
// step and cannot touch a2a: — and the next agent given that name behind
|
|
430
|
+
// a published flow is a widening, an admin's change by itself.
|
|
431
|
+
const listedBefore = b?.info.a2a?.acceptRisk ?? [];
|
|
432
|
+
const stale = accepted.filter((n) => !agentsAfter.includes(n) && !listedBefore.includes(n));
|
|
433
|
+
if (stale.length)
|
|
434
|
+
out.stale.push({ flow, agents: stale });
|
|
435
|
+
const had = new Set(pubBefore ? secretCodeExposures(agentsBefore, before.reachOf, []).map((e) => e.agent) : []);
|
|
436
|
+
for (const e of secretCodeExposures(agentsAfter, after.reachOf, accepted)) {
|
|
437
|
+
if (e.accepted) {
|
|
438
|
+
if (!acceptedBefore.includes(e.agent))
|
|
439
|
+
out.accepted.push({ flow, agent: e.agent, secrets: e.secrets });
|
|
440
|
+
}
|
|
441
|
+
else if (!had.has(e.agent))
|
|
442
|
+
out.unaccepted.push({ flow, agent: e.agent, secrets: e.secrets });
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return out;
|
|
446
|
+
}
|
|
@@ -20,7 +20,7 @@ export declare function browseTier(vendor: string | null | undefined): {
|
|
|
20
20
|
* report-only install, or an executor that cannot wall the
|
|
21
21
|
* step's network.
|
|
22
22
|
* hosted — enforced: the step gets the forward proxy, its pod is walled
|
|
23
|
-
* to the egress proxy
|
|
23
|
+
* to the egress proxy, and foldrun's browser runs in it.
|
|
24
24
|
* refuse — a vendor's browser under a restricted, enforced list on an
|
|
25
25
|
* install that holds browsing: it browses from the vendor's
|
|
26
26
|
* network, which nothing here can hold to the list, so the step
|