@foldrun/core 18.3.1 → 18.4.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/joiners.d.ts +4 -1
- package/dist/src/joiners.js +48 -9
- package/dist/src/notify.d.ts +14 -0
- package/dist/src/notify.js +13 -4
- package/dist/src/runner.d.ts +7 -1
- package/dist/src/runner.js +65 -12
- package/package.json +1 -1
- package/src/joiners.ts +43 -6
- package/src/notify.ts +11 -2
- package/src/runner.ts +69 -12
package/dist/src/joiners.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
/** The indices (UTF-16) of every
|
|
1
|
+
/** The indices (UTF-16) of every invisible in `text` that is spelling, not
|
|
2
|
+
* hiding: a joiner of a joining script or emoji; and a run of bidi marks on a
|
|
3
|
+
* LINE with right-to-left letters, not splitting a Latin word (Codex review:
|
|
4
|
+
* judged per line, per whole run, by letters alone). */
|
|
2
5
|
export declare function spellingJoiners(text: string): Set<number>;
|
package/dist/src/joiners.js
CHANGED
|
@@ -19,17 +19,56 @@ const JOINER_SCRIPTS = [
|
|
|
19
19
|
"Tibetan", "Myanmar", "Khmer", "Mongolian",
|
|
20
20
|
];
|
|
21
21
|
const LETTER = `(?:${JOINER_SCRIPTS.map((s) => `[\\p{scx=${s}}&&[\\p{L}\\p{M}]]`).join("|")})`;
|
|
22
|
-
/** A ZWNJ or ZWJ with a letter or mark of a joining script on
|
|
23
|
-
|
|
22
|
+
/** A ZWNJ or ZWJ with a letter or mark of a joining script on one side and
|
|
23
|
+
* a letter or mark on the other — inside a word, or where a Persian suffix
|
|
24
|
+
* follows a Latin word («channelها», «webhooksاند»; cloudhost, 11 Nov). */
|
|
25
|
+
const ANY_LETTER = "[\\p{L}\\p{M}]";
|
|
26
|
+
const IN_WORD = new RegExp(`(?<=${LETTER})[\\u200C\\u200D](?=${ANY_LETTER})|(?<=${ANY_LETTER})[\\u200C\\u200D](?=${LETTER})`, "gv");
|
|
24
27
|
/** A ZWJ between two emoji (a skin tone or VS16 may follow the first). */
|
|
25
|
-
const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)
|
|
26
|
-
/**
|
|
28
|
+
const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)\u200D(?=\p{Extended_Pictographic})/gu;
|
|
29
|
+
/** A right-to-left LETTER (Arabic-script, Hebrew, Syriac, Thaana, N'Ko) —
|
|
30
|
+
* letters only, so a mark (ALM is Arabic-script) is never its own evidence. */
|
|
31
|
+
const RTL_LETTER = new RegExp("[[\\p{scx=Arabic}\\p{scx=Hebrew}\\p{scx=Syriac}\\p{scx=Thaana}\\p{scx=Nko}]&&\\p{L}]", "v");
|
|
32
|
+
/** A run of bidi MARKS — LRM, RLM, ALM. Unlike overrides and isolates they
|
|
33
|
+
* move nothing: they settle where a neutral (a backtick, a dot) sits, which
|
|
34
|
+
* is how a Latin file name stays in order inside Persian text. */
|
|
35
|
+
const MARKS = /[\u200E\u200F\u061C]+/gu;
|
|
36
|
+
const LATIN = /\p{scx=Latin}/u;
|
|
37
|
+
const MARKS_ANY = /[\u200E\u200F\u061C]/u;
|
|
38
|
+
/** The indices (UTF-16) of every invisible in `text` that is spelling, not
|
|
39
|
+
* hiding: a joiner of a joining script or emoji; and a run of bidi marks on a
|
|
40
|
+
* LINE with right-to-left letters, not splitting a Latin word (Codex review:
|
|
41
|
+
* judged per line, per whole run, by letters alone). */
|
|
27
42
|
export function spellingJoiners(text) {
|
|
28
43
|
const at = new Set();
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
if (/[\u200C\u200D]/.test(text))
|
|
45
|
+
for (const re of [IN_WORD, IN_EMOJI])
|
|
46
|
+
for (const m of text.matchAll(re))
|
|
47
|
+
at.add(m.index);
|
|
48
|
+
if (/[\u200E\u200F\u061C]/.test(text)) {
|
|
49
|
+
// Line by line, each line classified once (Codex review: rescanning the
|
|
50
|
+
// line for every run of marks was quadratic on hostile input).
|
|
51
|
+
let lineStart = 0;
|
|
52
|
+
while (lineStart <= text.length) {
|
|
53
|
+
const nl = text.indexOf("\n", lineStart);
|
|
54
|
+
const lineEnd = nl === -1 ? text.length : nl;
|
|
55
|
+
const line = text.slice(lineStart, lineEnd);
|
|
56
|
+
if (MARKS_ANY.test(line) && RTL_LETTER.test(line)) {
|
|
57
|
+
for (const m of line.matchAll(MARKS)) {
|
|
58
|
+
const start = lineStart + m.index;
|
|
59
|
+
const end = start + m[0].length;
|
|
60
|
+
// "ig\u200E\u200Enore": marks between two Latin letters split a
|
|
61
|
+
// word; they order nothing there, so they are still hidden text.
|
|
62
|
+
if (LATIN.test(text[start - 1] ?? "") && LATIN.test(text[end] ?? ""))
|
|
63
|
+
continue;
|
|
64
|
+
for (let k = start; k < end; k++)
|
|
65
|
+
at.add(k);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (nl === -1)
|
|
69
|
+
break;
|
|
70
|
+
lineStart = nl + 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
34
73
|
return at;
|
|
35
74
|
}
|
package/dist/src/notify.d.ts
CHANGED
|
@@ -187,6 +187,13 @@ export declare function sendPlainNotification(tenant: string, workspace: string,
|
|
|
187
187
|
detail: string;
|
|
188
188
|
flow?: string;
|
|
189
189
|
runId?: string;
|
|
190
|
+
},
|
|
191
|
+
/** FOL-159, its own trailing argument so the signature only widened:
|
|
192
|
+
* `asking` — a question an agent asked, which also matches `events: [asking]`;
|
|
193
|
+
* `extra` — fields the webhook body gains (bodies only ever gain fields). */
|
|
194
|
+
opts?: {
|
|
195
|
+
asking?: boolean;
|
|
196
|
+
extra?: Record<string, unknown>;
|
|
190
197
|
}): Promise<boolean>;
|
|
191
198
|
/**
|
|
192
199
|
* The same send, saying what became of it: `ok` when it arrived, `retrying`
|
|
@@ -200,6 +207,13 @@ export declare function sendPlainNotificationOutcome(tenant: string, workspace:
|
|
|
200
207
|
detail: string;
|
|
201
208
|
flow?: string;
|
|
202
209
|
runId?: string;
|
|
210
|
+
},
|
|
211
|
+
/** FOL-159, its own trailing argument so the signature only widened:
|
|
212
|
+
* `asking` — a question an agent asked, which also matches `events: [asking]`;
|
|
213
|
+
* `extra` — fields the webhook body gains (bodies only ever gain fields). */
|
|
214
|
+
opts?: {
|
|
215
|
+
asking?: boolean;
|
|
216
|
+
extra?: Record<string, unknown>;
|
|
203
217
|
}): Promise<{
|
|
204
218
|
ok: boolean;
|
|
205
219
|
retrying: boolean;
|
package/dist/src/notify.js
CHANGED
|
@@ -387,8 +387,12 @@ export function isQuietFlow(flow) {
|
|
|
387
387
|
* so a workspace that wants none of this writes its own list and gets none
|
|
388
388
|
* of it. They are on by default: an alert nobody opted into is the point.
|
|
389
389
|
*/
|
|
390
|
-
export async function sendPlainNotification(tenant, workspace, msg
|
|
391
|
-
|
|
390
|
+
export async function sendPlainNotification(tenant, workspace, msg,
|
|
391
|
+
/** FOL-159, its own trailing argument so the signature only widened:
|
|
392
|
+
* `asking` — a question an agent asked, which also matches `events: [asking]`;
|
|
393
|
+
* `extra` — fields the webhook body gains (bodies only ever gain fields). */
|
|
394
|
+
opts = {}) {
|
|
395
|
+
return (await sendPlainNotificationOutcome(tenant, workspace, msg, opts)).ok;
|
|
392
396
|
}
|
|
393
397
|
/**
|
|
394
398
|
* The same send, saying what became of it: `ok` when it arrived, `retrying`
|
|
@@ -396,7 +400,11 @@ export async function sendPlainNotification(tenant, workspace, msg) {
|
|
|
396
400
|
* another (FOL-58 — a caller that would retry on its own must not start a
|
|
397
401
|
* second chain).
|
|
398
402
|
*/
|
|
399
|
-
export async function sendPlainNotificationOutcome(tenant, workspace, msg
|
|
403
|
+
export async function sendPlainNotificationOutcome(tenant, workspace, msg,
|
|
404
|
+
/** FOL-159, its own trailing argument so the signature only widened:
|
|
405
|
+
* `asking` — a question an agent asked, which also matches `events: [asking]`;
|
|
406
|
+
* `extra` — fields the webhook body gains (bodies only ever gain fields). */
|
|
407
|
+
opts = {}) {
|
|
400
408
|
const no = { ok: false, retrying: false };
|
|
401
409
|
const config = notifyConfig(tenant, workspace);
|
|
402
410
|
if (!config)
|
|
@@ -406,9 +414,10 @@ export async function sendPlainNotificationOutcome(tenant, workspace, msg) {
|
|
|
406
414
|
// happens to produce no failed run for the normal path to report. A
|
|
407
415
|
// destination hearing about failures hears about these; naming one
|
|
408
416
|
// explicitly also turns it on; leaving `failed` out silences them.
|
|
409
|
-
if (!config.events.includes(msg.event) && !config.events.includes("failed"))
|
|
417
|
+
if (!config.events.includes(msg.event) && !(opts.asking && config.events.includes("asking")) && !config.events.includes("failed"))
|
|
410
418
|
return no;
|
|
411
419
|
const body = {
|
|
420
|
+
...(opts.extra ?? {}),
|
|
412
421
|
text: `${msg.headline} — ${msg.detail} · ${workspace}`,
|
|
413
422
|
workspace,
|
|
414
423
|
status: msg.event,
|
package/dist/src/runner.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { type EgressGrant } from "./egress.ts";
|
|
1
2
|
import { type SupplyAnswer } from "./model-supply.ts";
|
|
2
3
|
import { type DelegateSpec, type SubagentSpec } from "./subagents.ts";
|
|
3
|
-
import { type FlowStep, type RunRecord, type StepRecord } from "./store.ts";
|
|
4
|
+
import { type FlowStep, type McpSpec, type RunRecord, type StepRecord } from "./store.ts";
|
|
4
5
|
import { type Catalog } from "./catalog.ts";
|
|
5
6
|
import { type RemoteSpec } from "./a2a-remotes.ts";
|
|
6
7
|
import { type SearchRoot, type RunDigest } from "./context-tools.ts";
|
|
@@ -11,6 +12,11 @@ import { type LanguageChoice } from "./language.ts";
|
|
|
11
12
|
import { type RegionChoice } from "./locale.ts";
|
|
12
13
|
import { type ClockChoice } from "./clock.ts";
|
|
13
14
|
export { localDate } from "./clock.ts";
|
|
15
|
+
/** Remote MCP servers with each bound secret's value put back as its
|
|
16
|
+
* `${NAME}`, granted to that server's host — the sandbox then holds the
|
|
17
|
+
* name and the proxy fills it, as for an http tool. */
|
|
18
|
+
export declare function unbindMcpHeaders(servers: Record<string, McpServerConfig>, bound: string[], values: Record<string, string>, grant: EgressGrant): Record<string, McpServerConfig>;
|
|
19
|
+
export declare function mcpConfig(spec: McpSpec, tenant: string, workspace: string): McpServerConfig;
|
|
14
20
|
/** How much of the earlier groups' output a step is handed, in characters.
|
|
15
21
|
* Newest groups are kept when the total is over it. */
|
|
16
22
|
export declare const CONTEXT_CHARS = 30000;
|
package/dist/src/runner.js
CHANGED
|
@@ -80,37 +80,79 @@ export { localDate } from "./clock.js";
|
|
|
80
80
|
/** Remote MCP servers with each bound secret's value put back as its
|
|
81
81
|
* `${NAME}`, granted to that server's host — the sandbox then holds the
|
|
82
82
|
* name and the proxy fills it, as for an http tool. */
|
|
83
|
-
function unbindMcpHeaders(servers, bound, values, grant) {
|
|
83
|
+
export function unbindMcpHeaders(servers, bound, values, grant) {
|
|
84
84
|
const known = Object.fromEntries(bound.filter((n) => n in values).map((n) => [n, values[n]]));
|
|
85
85
|
const out = {};
|
|
86
86
|
for (const [name, server] of Object.entries(servers)) {
|
|
87
|
-
if (server.type !== "http"
|
|
87
|
+
if (server.type !== "http") {
|
|
88
88
|
out[name] = server;
|
|
89
89
|
continue;
|
|
90
90
|
}
|
|
91
91
|
const host = hostOf(server.url);
|
|
92
|
+
const tpl = MCP_TEMPLATES.get(server);
|
|
93
|
+
if (host && tpl) {
|
|
94
|
+
// From the server's own text, not by finding values in it (FOL-160,
|
|
95
|
+
// Codex): a bound name stays ${NAME} — granted to this host for the
|
|
96
|
+
// proxy to fill — however short its value; every other name is filled
|
|
97
|
+
// exactly as mcpConfig filled it.
|
|
98
|
+
const render = (text) => text.replace(/\$\{([A-Z][A-Z0-9_]*)\}/g, (whole, n) => {
|
|
99
|
+
if (n in known) {
|
|
100
|
+
addGrant(grant, n, known[n], host);
|
|
101
|
+
return whole;
|
|
102
|
+
}
|
|
103
|
+
return getSecret(tpl.tenant, n, tpl.workspace)?.value ?? whole;
|
|
104
|
+
});
|
|
105
|
+
// The address itself — scheme and host — must stay routable: a bound
|
|
106
|
+
// secret there would leave the sandbox a URL it cannot call, and filling
|
|
107
|
+
// it would send the secret in. Refused, saying where it may go (Codex).
|
|
108
|
+
const origin = /^[^:/?#]*:\/\/[^/?#]*/.exec(tpl.url)?.[0] ?? tpl.url;
|
|
109
|
+
const inOrigin = placeholderNames(origin).filter((n) => n in known);
|
|
110
|
+
if (inOrigin.length) {
|
|
111
|
+
throw new Error(`MCP server ${name}: ${inOrigin.join(", ")} is bound to sites and names part of the server's address — bind it to the server's host and put it in a header or the URL's path or query`);
|
|
112
|
+
}
|
|
113
|
+
out[name] = { ...server, url: render(tpl.url), headers: Object.fromEntries(Object.entries(tpl.headers).map(([k, v]) => [k, render(v)])) };
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
// A config made elsewhere (no template): put each bound value back by value.
|
|
92
117
|
out[name] = host
|
|
93
|
-
? {
|
|
118
|
+
? {
|
|
119
|
+
...server,
|
|
120
|
+
url: unsubstitute(server.url, known, host, grant),
|
|
121
|
+
...(server.headers ? { headers: Object.fromEntries(Object.entries(server.headers).map(([k, v]) => [k, unsubstitute(v, known, host, grant)])) } : {}),
|
|
122
|
+
}
|
|
94
123
|
: server;
|
|
95
124
|
}
|
|
96
125
|
return out;
|
|
97
126
|
}
|
|
98
|
-
function
|
|
127
|
+
function remembered(cfg, tpl) {
|
|
128
|
+
MCP_TEMPLATES.set(cfg, tpl);
|
|
129
|
+
return cfg;
|
|
130
|
+
}
|
|
131
|
+
/** The secrets a remote MCP server names in its URL and headers. */
|
|
132
|
+
function mcpSecretNames(spec) {
|
|
133
|
+
return spec.url ? [...placeholderNames(spec.url), ...Object.values(spec.headers ?? {}).flatMap(placeholderNames)] : [];
|
|
134
|
+
}
|
|
135
|
+
/** A remote server's config → the text it was filled from, so a bound secret
|
|
136
|
+
* is put back by NAME (unbindMcpHeaders), never found by its value. */
|
|
137
|
+
const MCP_TEMPLATES = new WeakMap();
|
|
138
|
+
export function mcpConfig(spec, tenant, workspace) {
|
|
139
|
+
const fillOne = (v) => v.replace(/\$\{([A-Z][A-Z0-9_]*)\}/g, (whole, secretName) => {
|
|
140
|
+
const hit = getSecret(tenant, secretName, workspace);
|
|
141
|
+
return hit ? hit.value : whole;
|
|
142
|
+
});
|
|
99
143
|
const fill = (values) => {
|
|
100
144
|
const out = {};
|
|
101
|
-
for (const [k, v] of Object.entries(values))
|
|
102
|
-
out[k] = v
|
|
103
|
-
const hit = getSecret(tenant, secretName, workspace);
|
|
104
|
-
return hit ? hit.value : whole;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
145
|
+
for (const [k, v] of Object.entries(values))
|
|
146
|
+
out[k] = fillOne(v);
|
|
107
147
|
return out;
|
|
108
148
|
};
|
|
109
149
|
// alwaysLoad: the SDK defers MCP tools behind tool search by default, which
|
|
110
150
|
// hides them from an agent whose toolset we've already narrowed. A server
|
|
111
151
|
// the author explicitly granted should be present from turn one.
|
|
112
152
|
return spec.url
|
|
113
|
-
? {
|
|
153
|
+
? // ${NAME} in the URL as in the headers (FOL-160); a site-bound one goes
|
|
154
|
+
// back to its name for the egress proxy (unbindMcpHeaders).
|
|
155
|
+
remembered({ type: "http", url: fillOne(spec.url), headers: fill(spec.headers), alwaysLoad: true }, { url: spec.url, headers: spec.headers, tenant, workspace })
|
|
114
156
|
: {
|
|
115
157
|
type: "stdio",
|
|
116
158
|
command: spec.command,
|
|
@@ -1045,6 +1087,10 @@ grantsOnly = false) {
|
|
|
1045
1087
|
// Does any granted tool act outside the workspace (`outward: true`)? The
|
|
1046
1088
|
// retry policy reads it: see launchStep.
|
|
1047
1089
|
let outward = false;
|
|
1090
|
+
// The secrets a REMOTE MCP server names in its URL or headers (FOL-160,
|
|
1091
|
+
// Codex): resolved and checked for site bindings as an API's are, so a
|
|
1092
|
+
// bound one is put back by name and filled by the proxy, never sent in.
|
|
1093
|
+
const mcpSecretRefs = [];
|
|
1048
1094
|
const grantOwnTool = (name) => {
|
|
1049
1095
|
const def = available[name];
|
|
1050
1096
|
if (!def) {
|
|
@@ -1067,6 +1113,7 @@ grantsOnly = false) {
|
|
|
1067
1113
|
else {
|
|
1068
1114
|
mcpServers[def.name] = mcpConfig(def.spec, tenant, workspace);
|
|
1069
1115
|
mcpNames.push(def.name);
|
|
1116
|
+
mcpSecretRefs.push(...mcpSecretNames(def.spec));
|
|
1070
1117
|
}
|
|
1071
1118
|
};
|
|
1072
1119
|
for (const name of requested)
|
|
@@ -1078,6 +1125,7 @@ grantsOnly = false) {
|
|
|
1078
1125
|
if (def?.kind === "mcp") {
|
|
1079
1126
|
mcpServers[name] = mcpConfig(def.spec, tenant, workspace);
|
|
1080
1127
|
mcpNames.push(name);
|
|
1128
|
+
mcpSecretRefs.push(...mcpSecretNames(def.spec));
|
|
1081
1129
|
}
|
|
1082
1130
|
}
|
|
1083
1131
|
}
|
|
@@ -1176,7 +1224,7 @@ grantsOnly = false) {
|
|
|
1176
1224
|
];
|
|
1177
1225
|
// One name once, however many places asked for it.
|
|
1178
1226
|
declared.splice(0, declared.length, ...new Set(declared));
|
|
1179
|
-
const referenced = [...new Set(apis.flatMap(secretsUsedByApi))];
|
|
1227
|
+
const referenced = [...new Set([...apis.flatMap(secretsUsedByApi), ...mcpSecretRefs])];
|
|
1180
1228
|
// A remote's secret travels with the remote, as an API's does: naming it
|
|
1181
1229
|
// under remotes: is enough. One nothing else in the step uses is resolved
|
|
1182
1230
|
// apart, into remoteSecretEnv, and reaches the a2a tools alone — never
|
|
@@ -1889,6 +1937,11 @@ async function notifyQuestion(tenant, workspace, runId, agent, question, options
|
|
|
1889
1937
|
headline: `${agent} is asking you something`,
|
|
1890
1938
|
detail: `${question}${options?.length ? `\n\nOptions: ${options.join(" · ")}` : ""}\n\nAnswer it on ${where}, or \`foldrun answer ${runId} "…"\`.`,
|
|
1891
1939
|
runId,
|
|
1940
|
+
}, {
|
|
1941
|
+
// A webhook tells a question from a gate (FOL-159), and `events: [asking]`
|
|
1942
|
+
// subscribes to questions alone; awaiting-approval keeps getting them.
|
|
1943
|
+
asking: true,
|
|
1944
|
+
extra: { reason: "question", question: { text: question, ...(options?.length ? { options } : {}), agent } },
|
|
1892
1945
|
}).catch(() => false);
|
|
1893
1946
|
}
|
|
1894
1947
|
/** The local stand-in for a person: the terminal, when there is one. */
|
package/package.json
CHANGED
package/src/joiners.ts
CHANGED
|
@@ -21,15 +21,52 @@ const JOINER_SCRIPTS = [
|
|
|
21
21
|
];
|
|
22
22
|
const LETTER = `(?:${JOINER_SCRIPTS.map((s) => `[\\p{scx=${s}}&&[\\p{L}\\p{M}]]`).join("|")})`;
|
|
23
23
|
|
|
24
|
-
/** A ZWNJ or ZWJ with a letter or mark of a joining script on
|
|
25
|
-
|
|
24
|
+
/** A ZWNJ or ZWJ with a letter or mark of a joining script on one side and
|
|
25
|
+
* a letter or mark on the other — inside a word, or where a Persian suffix
|
|
26
|
+
* follows a Latin word («channelها», «webhooksاند»; cloudhost, 11 Nov). */
|
|
27
|
+
const ANY_LETTER = "[\\p{L}\\p{M}]";
|
|
28
|
+
const IN_WORD = new RegExp(`(?<=${LETTER})[\\u200C\\u200D](?=${ANY_LETTER})|(?<=${ANY_LETTER})[\\u200C\\u200D](?=${LETTER})`, "gv");
|
|
26
29
|
/** A ZWJ between two emoji (a skin tone or VS16 may follow the first). */
|
|
27
|
-
const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)
|
|
30
|
+
const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)\u200D(?=\p{Extended_Pictographic})/gu;
|
|
28
31
|
|
|
29
|
-
/**
|
|
32
|
+
/** A right-to-left LETTER (Arabic-script, Hebrew, Syriac, Thaana, N'Ko) —
|
|
33
|
+
* letters only, so a mark (ALM is Arabic-script) is never its own evidence. */
|
|
34
|
+
const RTL_LETTER = new RegExp("[[\\p{scx=Arabic}\\p{scx=Hebrew}\\p{scx=Syriac}\\p{scx=Thaana}\\p{scx=Nko}]&&\\p{L}]", "v");
|
|
35
|
+
/** A run of bidi MARKS — LRM, RLM, ALM. Unlike overrides and isolates they
|
|
36
|
+
* move nothing: they settle where a neutral (a backtick, a dot) sits, which
|
|
37
|
+
* is how a Latin file name stays in order inside Persian text. */
|
|
38
|
+
const MARKS = /[\u200E\u200F\u061C]+/gu;
|
|
39
|
+
const LATIN = /\p{scx=Latin}/u;
|
|
40
|
+
const MARKS_ANY = /[\u200E\u200F\u061C]/u;
|
|
41
|
+
|
|
42
|
+
/** The indices (UTF-16) of every invisible in `text` that is spelling, not
|
|
43
|
+
* hiding: a joiner of a joining script or emoji; and a run of bidi marks on a
|
|
44
|
+
* LINE with right-to-left letters, not splitting a Latin word (Codex review:
|
|
45
|
+
* judged per line, per whole run, by letters alone). */
|
|
30
46
|
export function spellingJoiners(text: string): Set<number> {
|
|
31
47
|
const at = new Set<number>();
|
|
32
|
-
if (
|
|
33
|
-
|
|
48
|
+
if (/[\u200C\u200D]/.test(text)) for (const re of [IN_WORD, IN_EMOJI]) for (const m of text.matchAll(re)) at.add(m.index!);
|
|
49
|
+
if (/[\u200E\u200F\u061C]/.test(text)) {
|
|
50
|
+
// Line by line, each line classified once (Codex review: rescanning the
|
|
51
|
+
// line for every run of marks was quadratic on hostile input).
|
|
52
|
+
let lineStart = 0;
|
|
53
|
+
while (lineStart <= text.length) {
|
|
54
|
+
const nl = text.indexOf("\n", lineStart);
|
|
55
|
+
const lineEnd = nl === -1 ? text.length : nl;
|
|
56
|
+
const line = text.slice(lineStart, lineEnd);
|
|
57
|
+
if (MARKS_ANY.test(line) && RTL_LETTER.test(line)) {
|
|
58
|
+
for (const m of line.matchAll(MARKS)) {
|
|
59
|
+
const start = lineStart + m.index!;
|
|
60
|
+
const end = start + m[0].length;
|
|
61
|
+
// "ig\u200E\u200Enore": marks between two Latin letters split a
|
|
62
|
+
// word; they order nothing there, so they are still hidden text.
|
|
63
|
+
if (LATIN.test(text[start - 1] ?? "") && LATIN.test(text[end] ?? "")) continue;
|
|
64
|
+
for (let k = start; k < end; k++) at.add(k);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (nl === -1) break;
|
|
68
|
+
lineStart = nl + 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
34
71
|
return at;
|
|
35
72
|
}
|
package/src/notify.ts
CHANGED
|
@@ -450,8 +450,12 @@ export async function sendPlainNotification(
|
|
|
450
450
|
tenant: string,
|
|
451
451
|
workspace: string,
|
|
452
452
|
msg: { event: string; headline: string; detail: string; flow?: string; runId?: string },
|
|
453
|
+
/** FOL-159, its own trailing argument so the signature only widened:
|
|
454
|
+
* `asking` — a question an agent asked, which also matches `events: [asking]`;
|
|
455
|
+
* `extra` — fields the webhook body gains (bodies only ever gain fields). */
|
|
456
|
+
opts: { asking?: boolean; extra?: Record<string, unknown> } = {},
|
|
453
457
|
): Promise<boolean> {
|
|
454
|
-
return (await sendPlainNotificationOutcome(tenant, workspace, msg)).ok;
|
|
458
|
+
return (await sendPlainNotificationOutcome(tenant, workspace, msg, opts)).ok;
|
|
455
459
|
}
|
|
456
460
|
|
|
457
461
|
/**
|
|
@@ -464,6 +468,10 @@ export async function sendPlainNotificationOutcome(
|
|
|
464
468
|
tenant: string,
|
|
465
469
|
workspace: string,
|
|
466
470
|
msg: { event: string; headline: string; detail: string; flow?: string; runId?: string },
|
|
471
|
+
/** FOL-159, its own trailing argument so the signature only widened:
|
|
472
|
+
* `asking` — a question an agent asked, which also matches `events: [asking]`;
|
|
473
|
+
* `extra` — fields the webhook body gains (bodies only ever gain fields). */
|
|
474
|
+
opts: { asking?: boolean; extra?: Record<string, unknown> } = {},
|
|
467
475
|
): Promise<{ ok: boolean; retrying: boolean }> {
|
|
468
476
|
const no = { ok: false, retrying: false };
|
|
469
477
|
const config = notifyConfig(tenant, workspace);
|
|
@@ -473,9 +481,10 @@ export async function sendPlainNotificationOutcome(
|
|
|
473
481
|
// happens to produce no failed run for the normal path to report. A
|
|
474
482
|
// destination hearing about failures hears about these; naming one
|
|
475
483
|
// explicitly also turns it on; leaving `failed` out silences them.
|
|
476
|
-
if (!config.events.includes(msg.event) && !config.events.includes("failed")) return no;
|
|
484
|
+
if (!config.events.includes(msg.event) && !(opts.asking && config.events.includes("asking")) && !config.events.includes("failed")) return no;
|
|
477
485
|
|
|
478
486
|
const body = {
|
|
487
|
+
...(opts.extra ?? {}),
|
|
479
488
|
text: `${msg.headline} — ${msg.detail} · ${workspace}`,
|
|
480
489
|
workspace,
|
|
481
490
|
status: msg.event,
|
package/src/runner.ts
CHANGED
|
@@ -136,7 +136,7 @@ export { localDate } from "./clock.ts";
|
|
|
136
136
|
/** Remote MCP servers with each bound secret's value put back as its
|
|
137
137
|
* `${NAME}`, granted to that server's host — the sandbox then holds the
|
|
138
138
|
* name and the proxy fills it, as for an http tool. */
|
|
139
|
-
function unbindMcpHeaders(
|
|
139
|
+
export function unbindMcpHeaders(
|
|
140
140
|
servers: Record<string, McpServerConfig>,
|
|
141
141
|
bound: string[],
|
|
142
142
|
values: Record<string, string>,
|
|
@@ -145,34 +145,80 @@ function unbindMcpHeaders(
|
|
|
145
145
|
const known = Object.fromEntries(bound.filter((n) => n in values).map((n) => [n, values[n]]));
|
|
146
146
|
const out: Record<string, McpServerConfig> = {};
|
|
147
147
|
for (const [name, server] of Object.entries(servers)) {
|
|
148
|
-
if (server.type !== "http"
|
|
148
|
+
if (server.type !== "http") {
|
|
149
149
|
out[name] = server;
|
|
150
150
|
continue;
|
|
151
151
|
}
|
|
152
152
|
const host = hostOf(server.url);
|
|
153
|
+
const tpl = MCP_TEMPLATES.get(server);
|
|
154
|
+
if (host && tpl) {
|
|
155
|
+
// From the server's own text, not by finding values in it (FOL-160,
|
|
156
|
+
// Codex): a bound name stays ${NAME} — granted to this host for the
|
|
157
|
+
// proxy to fill — however short its value; every other name is filled
|
|
158
|
+
// exactly as mcpConfig filled it.
|
|
159
|
+
const render = (text: string) =>
|
|
160
|
+
text.replace(/\$\{([A-Z][A-Z0-9_]*)\}/g, (whole, n: string) => {
|
|
161
|
+
if (n in known) {
|
|
162
|
+
addGrant(grant, n, known[n]!, host);
|
|
163
|
+
return whole;
|
|
164
|
+
}
|
|
165
|
+
return getSecret(tpl.tenant, n, tpl.workspace)?.value ?? whole;
|
|
166
|
+
});
|
|
167
|
+
// The address itself — scheme and host — must stay routable: a bound
|
|
168
|
+
// secret there would leave the sandbox a URL it cannot call, and filling
|
|
169
|
+
// it would send the secret in. Refused, saying where it may go (Codex).
|
|
170
|
+
const origin = /^[^:/?#]*:\/\/[^/?#]*/.exec(tpl.url)?.[0] ?? tpl.url;
|
|
171
|
+
const inOrigin = placeholderNames(origin).filter((n) => n in known);
|
|
172
|
+
if (inOrigin.length) {
|
|
173
|
+
throw new Error(`MCP server ${name}: ${inOrigin.join(", ")} is bound to sites and names part of the server's address — bind it to the server's host and put it in a header or the URL's path or query`);
|
|
174
|
+
}
|
|
175
|
+
out[name] = { ...server, url: render(tpl.url), headers: Object.fromEntries(Object.entries(tpl.headers).map(([k, v]) => [k, render(v)])) };
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
// A config made elsewhere (no template): put each bound value back by value.
|
|
153
179
|
out[name] = host
|
|
154
|
-
? {
|
|
180
|
+
? {
|
|
181
|
+
...server,
|
|
182
|
+
url: unsubstitute(server.url, known, host, grant),
|
|
183
|
+
...(server.headers ? { headers: Object.fromEntries(Object.entries(server.headers).map(([k, v]) => [k, unsubstitute(v, known, host, grant)])) } : {}),
|
|
184
|
+
}
|
|
155
185
|
: server;
|
|
156
186
|
}
|
|
157
187
|
return out;
|
|
158
188
|
}
|
|
159
189
|
|
|
160
|
-
function
|
|
190
|
+
function remembered(cfg: McpServerConfig, tpl: { url: string; headers: Record<string, string>; tenant: string; workspace: string }): McpServerConfig {
|
|
191
|
+
MCP_TEMPLATES.set(cfg, tpl);
|
|
192
|
+
return cfg;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The secrets a remote MCP server names in its URL and headers. */
|
|
196
|
+
function mcpSecretNames(spec: McpSpec): string[] {
|
|
197
|
+
return spec.url ? [...placeholderNames(spec.url), ...Object.values(spec.headers ?? {}).flatMap(placeholderNames)] : [];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** A remote server's config → the text it was filled from, so a bound secret
|
|
201
|
+
* is put back by NAME (unbindMcpHeaders), never found by its value. */
|
|
202
|
+
const MCP_TEMPLATES = new WeakMap<McpServerConfig, { url: string; headers: Record<string, string>; tenant: string; workspace: string }>();
|
|
203
|
+
|
|
204
|
+
export function mcpConfig(spec: McpSpec, tenant: string, workspace: string): McpServerConfig {
|
|
205
|
+
const fillOne = (v: string) =>
|
|
206
|
+
v.replace(/\$\{([A-Z][A-Z0-9_]*)\}/g, (whole, secretName) => {
|
|
207
|
+
const hit = getSecret(tenant, secretName, workspace);
|
|
208
|
+
return hit ? hit.value : whole;
|
|
209
|
+
});
|
|
161
210
|
const fill = (values: Record<string, string>) => {
|
|
162
211
|
const out: Record<string, string> = {};
|
|
163
|
-
for (const [k, v] of Object.entries(values))
|
|
164
|
-
out[k] = v.replace(/\$\{([A-Z][A-Z0-9_]*)\}/g, (whole, secretName) => {
|
|
165
|
-
const hit = getSecret(tenant, secretName, workspace);
|
|
166
|
-
return hit ? hit.value : whole;
|
|
167
|
-
});
|
|
168
|
-
}
|
|
212
|
+
for (const [k, v] of Object.entries(values)) out[k] = fillOne(v);
|
|
169
213
|
return out;
|
|
170
214
|
};
|
|
171
215
|
// alwaysLoad: the SDK defers MCP tools behind tool search by default, which
|
|
172
216
|
// hides them from an agent whose toolset we've already narrowed. A server
|
|
173
217
|
// the author explicitly granted should be present from turn one.
|
|
174
218
|
return spec.url
|
|
175
|
-
? {
|
|
219
|
+
? // ${NAME} in the URL as in the headers (FOL-160); a site-bound one goes
|
|
220
|
+
// back to its name for the egress proxy (unbindMcpHeaders).
|
|
221
|
+
remembered({ type: "http", url: fillOne(spec.url), headers: fill(spec.headers), alwaysLoad: true }, { url: spec.url, headers: spec.headers, tenant, workspace })
|
|
176
222
|
: {
|
|
177
223
|
type: "stdio",
|
|
178
224
|
command: spec.command!,
|
|
@@ -1190,6 +1236,10 @@ export function agentContext(
|
|
|
1190
1236
|
// Does any granted tool act outside the workspace (`outward: true`)? The
|
|
1191
1237
|
// retry policy reads it: see launchStep.
|
|
1192
1238
|
let outward = false;
|
|
1239
|
+
// The secrets a REMOTE MCP server names in its URL or headers (FOL-160,
|
|
1240
|
+
// Codex): resolved and checked for site bindings as an API's are, so a
|
|
1241
|
+
// bound one is put back by name and filled by the proxy, never sent in.
|
|
1242
|
+
const mcpSecretRefs: string[] = [];
|
|
1193
1243
|
const grantOwnTool = (name: string) => {
|
|
1194
1244
|
const def = available[name];
|
|
1195
1245
|
if (!def) {
|
|
@@ -1208,6 +1258,7 @@ export function agentContext(
|
|
|
1208
1258
|
else {
|
|
1209
1259
|
mcpServers[def.name] = mcpConfig(def.spec, tenant, workspace);
|
|
1210
1260
|
mcpNames.push(def.name);
|
|
1261
|
+
mcpSecretRefs.push(...mcpSecretNames(def.spec));
|
|
1211
1262
|
}
|
|
1212
1263
|
};
|
|
1213
1264
|
|
|
@@ -1220,6 +1271,7 @@ export function agentContext(
|
|
|
1220
1271
|
if (def?.kind === "mcp") {
|
|
1221
1272
|
mcpServers[name] = mcpConfig(def.spec, tenant, workspace);
|
|
1222
1273
|
mcpNames.push(name);
|
|
1274
|
+
mcpSecretRefs.push(...mcpSecretNames(def.spec));
|
|
1223
1275
|
}
|
|
1224
1276
|
}
|
|
1225
1277
|
}
|
|
@@ -1315,7 +1367,7 @@ export function agentContext(
|
|
|
1315
1367
|
];
|
|
1316
1368
|
// One name once, however many places asked for it.
|
|
1317
1369
|
declared.splice(0, declared.length, ...new Set(declared));
|
|
1318
|
-
const referenced = [...new Set(apis.flatMap(secretsUsedByApi))];
|
|
1370
|
+
const referenced = [...new Set([...apis.flatMap(secretsUsedByApi), ...mcpSecretRefs])];
|
|
1319
1371
|
// A remote's secret travels with the remote, as an API's does: naming it
|
|
1320
1372
|
// under remotes: is enough. One nothing else in the step uses is resolved
|
|
1321
1373
|
// apart, into remoteSecretEnv, and reaches the a2a tools alone — never
|
|
@@ -2065,6 +2117,11 @@ async function notifyQuestion(tenant: string, workspace: string, runId: string,
|
|
|
2065
2117
|
headline: `${agent} is asking you something`,
|
|
2066
2118
|
detail: `${question}${options?.length ? `\n\nOptions: ${options.join(" · ")}` : ""}\n\nAnswer it on ${where}, or \`foldrun answer ${runId} "…"\`.`,
|
|
2067
2119
|
runId,
|
|
2120
|
+
}, {
|
|
2121
|
+
// A webhook tells a question from a gate (FOL-159), and `events: [asking]`
|
|
2122
|
+
// subscribes to questions alone; awaiting-approval keeps getting them.
|
|
2123
|
+
asking: true,
|
|
2124
|
+
extra: { reason: "question", question: { text: question, ...(options?.length ? { options } : {}), agent } },
|
|
2068
2125
|
}).catch(() => false);
|
|
2069
2126
|
}
|
|
2070
2127
|
|