@foldrun/core 19.3.0 → 20.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/browser-pod.js +4 -0
- package/dist/src/completions.js +1 -0
- package/dist/src/egress.d.ts +5 -1
- package/dist/src/input-text.d.ts +48 -0
- package/dist/src/input-text.js +212 -0
- package/dist/src/limits.js +2 -1
- package/dist/src/manifest.d.ts +6 -1
- package/dist/src/manifest.js +8 -5
- package/dist/src/ops-log.js +21 -6
- package/dist/src/platform.d.ts +23 -0
- package/dist/src/platform.js +1 -0
- package/dist/src/records.d.ts +11 -0
- package/dist/src/run-container.d.ts +11 -7
- package/dist/src/run-container.js +50 -11
- package/dist/src/run-inputs.d.ts +6 -1
- package/dist/src/run-inputs.js +10 -2
- package/dist/src/run-output-refusal.d.ts +3 -0
- package/dist/src/run-output-refusal.js +16 -0
- package/dist/src/run-outputs.d.ts +134 -0
- package/dist/src/run-outputs.js +521 -0
- package/dist/src/runner.d.ts +1 -0
- package/dist/src/runner.js +59 -11
- package/dist/src/starter.js +1 -1
- package/dist/src/step-state.d.ts +10 -0
- package/dist/src/step-state.js +93 -0
- package/dist/src/store.d.ts +25 -4
- package/dist/src/store.js +15 -4
- package/dist/src/text-tool.d.ts +177 -0
- package/dist/src/text-tool.js +220 -0
- package/dist/src/tool-names.d.ts +3 -1
- package/dist/src/tool-names.js +4 -2
- package/dist/src/workspace-revisions.js +11 -0
- package/package.json +1 -1
- package/src/browser-pod.ts +3 -0
- package/src/completions.ts +1 -0
- package/src/egress.ts +5 -2
- package/src/input-text.ts +215 -0
- package/src/limits.ts +2 -1
- package/src/manifest.ts +12 -5
- package/src/ops-log.ts +22 -6
- package/src/platform.ts +22 -0
- package/src/records.ts +11 -0
- package/src/run-container.ts +49 -11
- package/src/run-inputs.ts +10 -2
- package/src/run-output-refusal.ts +20 -0
- package/src/run-outputs.ts +597 -0
- package/src/runner.ts +55 -10
- package/src/starter.ts +1 -1
- package/src/step-state.ts +97 -0
- package/src/store.ts +32 -4
- package/src/text-tool.ts +267 -0
- package/src/tool-names.ts +4 -2
- package/src/workspace-revisions.ts +11 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// tools: [text] — a file in the sandbox, as text (12 Nov 2026).
|
|
2
|
+
//
|
|
3
|
+
// An agent handed a scanned contract, a photo of a receipt, a slide deck or
|
|
4
|
+
// a voice note used to have two bad choices: Read the bytes (an image goes to
|
|
5
|
+
// the model whole and costs what it costs; a .docx is a zip it cannot read;
|
|
6
|
+
// audio is nothing at all), or install an OCR stack mid-step and hope it
|
|
7
|
+
// knows Persian. `extract_text` hands the file to foldrun's own extraction
|
|
8
|
+
// service — Persian and English OCR, Docling for office files and PDFs,
|
|
9
|
+
// Whisper for speech — and gets text back.
|
|
10
|
+
//
|
|
11
|
+
// The service is not in the sandbox. Like ask_person and the colleagues'
|
|
12
|
+
// tools (operator.ts), the call goes out through the one live door a run pod
|
|
13
|
+
// has: the worker's egress proxy, at the lease address the pod already holds
|
|
14
|
+
// (FOLDRUN_EGRESS = http://<proxy>/e/<lease>). The proxy honours the door
|
|
15
|
+
// only for a lease granted `text: true` — a step whose agent holds the tool —
|
|
16
|
+
// and the lease names the account, so what the service is asked is billed
|
|
17
|
+
// and recorded against the right run.
|
|
18
|
+
//
|
|
19
|
+
// POST {base}/text/{token}?name=<basename>&lang=<fa|en|auto>&ocr=<auto|always|never>
|
|
20
|
+
// body: the file's bytes, application/octet-stream
|
|
21
|
+
// 200: ExtractResult (below) 4xx/5xx: {error: string | {message}}
|
|
22
|
+
//
|
|
23
|
+
// No proxy (a `foldrun run` on a laptop, an in-process step) means no
|
|
24
|
+
// service: the tool says so instead of pretending.
|
|
25
|
+
import fs from "node:fs";
|
|
26
|
+
import path from "node:path";
|
|
27
|
+
import { Readable } from "node:stream";
|
|
28
|
+
import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
|
|
29
|
+
import { z } from "zod";
|
|
30
|
+
import { checkPaths, expandVirtual } from "./confine.js";
|
|
31
|
+
import { operatorEndpoint } from "./operator.js";
|
|
32
|
+
/** The granted name of the tool — the same on every path. */
|
|
33
|
+
export const TEXT_TOOL = "mcp__foldrun_text__extract_text";
|
|
34
|
+
export const TEXT_SERVER = "foldrun_text";
|
|
35
|
+
/** The largest file sent: anything bigger is refused before a byte leaves. */
|
|
36
|
+
export const TEXT_MAX_FILE_BYTES = 200 * 1024 * 1024;
|
|
37
|
+
/** Text up to this many bytes (UTF-8) comes back whole in the tool result. */
|
|
38
|
+
export const TEXT_INLINE_MAX = 200 * 1024;
|
|
39
|
+
/** Longer text is saved to a file; this many characters of it come back. */
|
|
40
|
+
export const TEXT_HEAD_CHARS = 20_000;
|
|
41
|
+
/** Long recordings take minutes; past this the call is given up. */
|
|
42
|
+
export const TEXT_TIMEOUT_MS = 15 * 60_000;
|
|
43
|
+
/** The door's URL for one file. */
|
|
44
|
+
export function textDoorUrl(ep, q) {
|
|
45
|
+
const query = new URLSearchParams({ name: q.name, lang: q.lang, ocr: q.ocr });
|
|
46
|
+
return `${ep.base}/text/${ep.token}?${query.toString()}`;
|
|
47
|
+
}
|
|
48
|
+
/** The one line above the text: what the file was, how much of it, in what
|
|
49
|
+
* language, and anything the service warned about. */
|
|
50
|
+
export function extractHeader(name, r, chars) {
|
|
51
|
+
const parts = [`${r.kind}${r.format && r.format !== r.kind ? ` (${r.format})` : ""}`];
|
|
52
|
+
const ocr = Array.isArray(r.ocrPages) ? r.ocrPages.length : typeof r.ocrPages === "number" ? r.ocrPages : 0;
|
|
53
|
+
if (typeof r.pages === "number")
|
|
54
|
+
parts.push(`${r.pages} page${r.pages === 1 ? "" : "s"}${ocr ? ` (${ocr} by OCR)` : ""}`);
|
|
55
|
+
if (typeof r.seconds === "number")
|
|
56
|
+
parts.push(`${fmtSeconds(r.seconds)}`);
|
|
57
|
+
if (r.language)
|
|
58
|
+
parts.push(`language ${r.language}`);
|
|
59
|
+
if (typeof r.confidence === "number")
|
|
60
|
+
parts.push(`confidence ${Math.round(r.confidence * 100) / 100}`);
|
|
61
|
+
const engine = [r.engine?.parser, r.engine?.speech].filter(Boolean).join(" + ");
|
|
62
|
+
if (engine)
|
|
63
|
+
parts.push(engine);
|
|
64
|
+
parts.push(`${chars.toLocaleString("en-US")} chars`);
|
|
65
|
+
if (r.cached)
|
|
66
|
+
parts.push("cached");
|
|
67
|
+
const warnings = [...(r.warnings ?? []), ...(r.truncated ? ["the service cut the text short"] : [])];
|
|
68
|
+
return `[extract_text] ${name}: ${parts.join(", ")}${warnings.length ? ` — warnings: ${warnings.join("; ")}` : ""}`;
|
|
69
|
+
}
|
|
70
|
+
const fmtSeconds = (s) => (s >= 3600 ? `${Math.floor(s / 3600)} h ${Math.round((s % 3600) / 60)} min` : s >= 60 ? `${Math.floor(s / 60)} min ${Math.round(s % 60)} s` : `${Math.round(s * 10) / 10} s`);
|
|
71
|
+
/** The line the system prompt gets for tools: [text]. */
|
|
72
|
+
export function textPromptLine() {
|
|
73
|
+
return ("`extract_text` turns a file you can reach — an image, a scanned or text PDF, DOCX, PPTX, XLSX, EPUB, HTML, audio or video — " +
|
|
74
|
+
"into text with foldrun's extraction service (Persian and English OCR, document parsing, speech recognition). " +
|
|
75
|
+
"Give it the file's path (`workspace/…` for the workspace's folders); `lang` is fa, en or auto; `save: true` also writes `<path>.txt` beside the file. " +
|
|
76
|
+
"Use it rather than reading a binary file yourself. A long recording can take minutes.");
|
|
77
|
+
}
|
|
78
|
+
/** The `extract_text` tool. `egress` is the step's FOLDRUN_EGRESS (null in
|
|
79
|
+
* process: the tool then refuses); the roots confine which files it may
|
|
80
|
+
* send and where it may write the `.txt`. `fetchImpl` is for tests. */
|
|
81
|
+
export function buildTextTools(opts) {
|
|
82
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
83
|
+
const roots = { agentDir: opts.agentDir, workspaceRoot: opts.workspaceRoot, libraryRoot: opts.libraryRoot };
|
|
84
|
+
const maxBytes = opts.maxFileBytes ?? TEXT_MAX_FILE_BYTES;
|
|
85
|
+
const text = (t) => ({ content: [{ type: "text", text: t }] });
|
|
86
|
+
const fail = (t) => ({ ...text(t), isError: true });
|
|
87
|
+
/** Where `raw` points, or why it may not be read. The file tools' own
|
|
88
|
+
* rule (confine.ts): the workspace and the library, never secrets or the
|
|
89
|
+
* run journal; `workspace/…` from the workspace root. */
|
|
90
|
+
const resolve = (raw) => {
|
|
91
|
+
const verdict = checkPaths("Read", { file_path: raw }, roots);
|
|
92
|
+
if (!verdict.ok)
|
|
93
|
+
return { error: (verdict.reason ?? `"${raw}" may not be read`).replace(/^Read was denied/, "extract_text was refused") };
|
|
94
|
+
return { abs: expandVirtual(raw, roots)?.abs ?? path.resolve(roots.agentDir, raw) };
|
|
95
|
+
};
|
|
96
|
+
/** Write the text where the agent can find it: `<path>.txt` beside the
|
|
97
|
+
* file when the file tools would allow that write, else the agent's own
|
|
98
|
+
* outputs/. Never over an existing file (a person's notes, an earlier
|
|
99
|
+
* save): each place is created new or skipped, the last a stamped name.
|
|
100
|
+
* Returns the path as the agent should write it, or null. */
|
|
101
|
+
const saveText = (raw, abs, body) => {
|
|
102
|
+
const besideRaw = `${raw}.txt`;
|
|
103
|
+
const attempts = [
|
|
104
|
+
{ shown: besideRaw, check: besideRaw },
|
|
105
|
+
{ shown: `outputs/${path.basename(abs)}.txt`, check: `outputs/${path.basename(abs)}.txt` },
|
|
106
|
+
{ shown: `outputs/${path.basename(abs)}.${Date.now()}.txt`, check: `outputs/${path.basename(abs)}.${Date.now()}.txt` },
|
|
107
|
+
];
|
|
108
|
+
for (const a of attempts) {
|
|
109
|
+
const verdict = checkPaths("Write", { file_path: a.check }, roots);
|
|
110
|
+
if (!verdict.ok)
|
|
111
|
+
continue;
|
|
112
|
+
const target = expandVirtual(a.check, roots)?.abs ?? path.resolve(roots.agentDir, a.check);
|
|
113
|
+
try {
|
|
114
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
115
|
+
fs.writeFileSync(target, body, { flag: "wx" });
|
|
116
|
+
return { shown: a.shown, abs: target };
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
/* the next place */
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
};
|
|
124
|
+
const extract = tool("extract_text", "Turn a file into text: an image or a scanned PDF (OCR, Persian and English), a text PDF, DOCX, PPTX, XLSX, EPUB or HTML (document parsing), audio or video (speech recognition). Returns a one-line header (kind, pages or length, language, warnings) and the text. Very long text returns its start; ask again with save: true to keep all of it in <path>.txt (the second call is answered from the cache).", {
|
|
125
|
+
path: z.string().describe("The file, relative to your agent folder, or workspace/… for the workspace (workspace/storage/scan.pdf)"),
|
|
126
|
+
lang: z.enum(["fa", "en", "auto"]).optional().describe("The language of the text or speech: fa, en, or auto (default) to detect it"),
|
|
127
|
+
ocr: z.enum(["auto", "always", "never"]).optional().describe("auto (default): OCR only pages with no text layer; always: OCR every page; never: the text layer only"),
|
|
128
|
+
save: z.boolean().optional().describe("Also write the text to <path>.txt beside the file, never over an existing file (default false)"),
|
|
129
|
+
}, async (args) => {
|
|
130
|
+
const raw = String(args.path ?? "").trim();
|
|
131
|
+
const lang = args.lang === "fa" || args.lang === "en" ? args.lang : "auto";
|
|
132
|
+
const ocr = args.ocr === "always" || args.ocr === "never" ? args.ocr : "auto";
|
|
133
|
+
if (!raw)
|
|
134
|
+
return fail("extract_text needs `path`: the file to turn into text.");
|
|
135
|
+
const ep = operatorEndpoint(opts.egress);
|
|
136
|
+
if (!ep) {
|
|
137
|
+
return fail("Text extraction needs a platform run: it is foldrun's extraction service, reached through the step's egress proxy, and this step has none (a local or in-process run). Nothing was sent.");
|
|
138
|
+
}
|
|
139
|
+
const where = resolve(raw);
|
|
140
|
+
if ("error" in where)
|
|
141
|
+
return fail(where.error);
|
|
142
|
+
let size;
|
|
143
|
+
try {
|
|
144
|
+
const st = fs.statSync(where.abs);
|
|
145
|
+
if (!st.isFile())
|
|
146
|
+
return fail(`extract_text: "${raw}" is not a file.`);
|
|
147
|
+
size = st.size;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return fail(`extract_text: "${raw}" does not exist.`);
|
|
151
|
+
}
|
|
152
|
+
if (size === 0)
|
|
153
|
+
return fail(`extract_text: "${raw}" is empty.`);
|
|
154
|
+
if (size > maxBytes) {
|
|
155
|
+
return fail(`extract_text: "${raw}" is ${fmtMb(size)}; the largest file it takes is ${fmtMb(maxBytes)}. Split it (pages, or a shorter clip) and extract the parts. Nothing was sent.`);
|
|
156
|
+
}
|
|
157
|
+
const name = path.basename(where.abs);
|
|
158
|
+
const started = Date.now();
|
|
159
|
+
let res;
|
|
160
|
+
try {
|
|
161
|
+
res = await fetchImpl(textDoorUrl(ep, { name, lang, ocr }), {
|
|
162
|
+
method: "POST",
|
|
163
|
+
headers: { "content-type": "application/octet-stream", "content-length": String(size) },
|
|
164
|
+
// Streamed, not read whole: a 200 MB recording stays on disk.
|
|
165
|
+
body: Readable.toWeb(fs.createReadStream(where.abs)),
|
|
166
|
+
duplex: "half",
|
|
167
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? TEXT_TIMEOUT_MS),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
const e = err;
|
|
172
|
+
const why = e?.name === "TimeoutError" ? `no answer after ${Math.round((opts.timeoutMs ?? TEXT_TIMEOUT_MS) / 60_000)} min` : (e?.message ?? String(err));
|
|
173
|
+
opts.emit?.("error", `extract_text: ${raw} — ${why}`);
|
|
174
|
+
return fail(`Text extraction failed: ${why}.`);
|
|
175
|
+
}
|
|
176
|
+
const body = (await res.json().catch(() => null));
|
|
177
|
+
if (!res.ok || !body || typeof body.text !== "string") {
|
|
178
|
+
const errField = body?.error;
|
|
179
|
+
const message = typeof errField === "string"
|
|
180
|
+
? errField
|
|
181
|
+
: errField && typeof errField.message === "string"
|
|
182
|
+
? String(errField.message)
|
|
183
|
+
: res.ok
|
|
184
|
+
? "the extraction service answered without text"
|
|
185
|
+
: `the extraction service answered ${res.status}`;
|
|
186
|
+
opts.emit?.("error", `extract_text: ${raw} — ${message}`);
|
|
187
|
+
return fail(`Text extraction failed: ${message}`);
|
|
188
|
+
}
|
|
189
|
+
const r = { ...body, warnings: Array.isArray(body.warnings) ? body.warnings.map(String) : [] };
|
|
190
|
+
const all = r.text;
|
|
191
|
+
const header = extractHeader(name, r, all.length);
|
|
192
|
+
opts.emit?.("info", `extract_text: ${raw} → ${r.kind}, ${all.length} chars in ${Date.now() - started} ms${r.cached ? " (cached)" : ""}`);
|
|
193
|
+
if (Buffer.byteLength(all, "utf8") <= TEXT_INLINE_MAX) {
|
|
194
|
+
if (!args.save)
|
|
195
|
+
return text(`${header}\n\n${all}`);
|
|
196
|
+
const saved = saveText(raw, where.abs, all);
|
|
197
|
+
const note = saved ? `Saved to ${saved.shown}.` : `Could not save it beside the file or in outputs/.`;
|
|
198
|
+
return text(`${header}\n${note}\n\n${all}`);
|
|
199
|
+
}
|
|
200
|
+
// Too long to hand back whole: the start comes back; the whole text is
|
|
201
|
+
// written only when asked (save: true) — a read never writes on its own.
|
|
202
|
+
const saved = args.save ? saveText(raw, where.abs, all) : null;
|
|
203
|
+
const head = all.slice(0, TEXT_HEAD_CHARS);
|
|
204
|
+
const total = all.length.toLocaleString("en-US");
|
|
205
|
+
const note = saved
|
|
206
|
+
? `The text is ${total} characters, too long to return whole: all of it is in ${saved.shown} — read it in parts. The first ${head.length.toLocaleString("en-US")} follow.`
|
|
207
|
+
: args.save
|
|
208
|
+
? `The text is ${total} characters, too long to return whole, and it could not be saved beside the file or in outputs/. The first ${head.length.toLocaleString("en-US")} follow.`
|
|
209
|
+
: `The text is ${total} characters, too long to return whole. The first ${head.length.toLocaleString("en-US")} follow; call extract_text again with save: true to keep all of it in a file (the second call is answered from the cache).`;
|
|
210
|
+
return text(`${header}\n${note}\n\n${head}`);
|
|
211
|
+
});
|
|
212
|
+
return {
|
|
213
|
+
server: createSdkMcpServer({ name: TEXT_SERVER, version: "1.0.0", tools: [extract] }),
|
|
214
|
+
/** The tool's own function, for tests. */
|
|
215
|
+
call: (args) => extract.handler({ path: args.path, lang: args.lang, ocr: args.ocr, save: args.save }, {}),
|
|
216
|
+
toolNames: [TEXT_TOOL],
|
|
217
|
+
promptLines: [textPromptLine()],
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const fmtMb = (n) => `${Math.round((n / (1024 * 1024)) * 10) / 10} MB`;
|
package/dist/src/tool-names.d.ts
CHANGED
|
@@ -14,7 +14,9 @@ export declare const RETIRED_TOOLS: Record<string, string>;
|
|
|
14
14
|
export declare const BUILTIN_TOOLS: Set<string>;
|
|
15
15
|
/** The platform's own groups, served in-process rather than by the SDK.
|
|
16
16
|
* `install` is granted to every agent anyway (install-tool.ts); naming it is
|
|
17
|
-
* accepted so a file that says so is not flagged.
|
|
17
|
+
* accepted so a file that says so is not flagged. `text` is extract_text
|
|
18
|
+
* (text-tool.ts) — named `text`, not `extract`, because `extract` is
|
|
19
|
+
* already one of the web tool's actions (`limits: {web.extract: 5}`). */
|
|
18
20
|
export declare const PLATFORM_GROUPS: Set<string>;
|
|
19
21
|
/** Would this name resolve to something the runtime provides? Built-ins win a
|
|
20
22
|
* clash, so a tool file of the same name is shadowed rather than granted. */
|
package/dist/src/tool-names.js
CHANGED
|
@@ -46,8 +46,10 @@ export const BUILTIN_TOOLS = new Set([
|
|
|
46
46
|
]);
|
|
47
47
|
/** The platform's own groups, served in-process rather than by the SDK.
|
|
48
48
|
* `install` is granted to every agent anyway (install-tool.ts); naming it is
|
|
49
|
-
* accepted so a file that says so is not flagged.
|
|
50
|
-
|
|
49
|
+
* accepted so a file that says so is not flagged. `text` is extract_text
|
|
50
|
+
* (text-tool.ts) — named `text`, not `extract`, because `extract` is
|
|
51
|
+
* already one of the web tool's actions (`limits: {web.extract: 5}`). */
|
|
52
|
+
export const PLATFORM_GROUPS = new Set(["search", "history", "desks", "ask", "peers", "install", "text"]);
|
|
51
53
|
/** Would this name resolve to something the runtime provides? Built-ins win a
|
|
52
54
|
* clash, so a tool file of the same name is shadowed rather than granted. */
|
|
53
55
|
export function isRuntimeTool(name) {
|
|
@@ -44,6 +44,7 @@ import { blobObjectKey, diffManifests, emptyManifest, entryId, EMPTY_MANIFEST_ID
|
|
|
44
44
|
import { headsOf, loadManifest, manifestsAt, manifestsOf, publish, restore, requestDigest, stateOpId, BlobMissing, PublishError } from "./publish.js";
|
|
45
45
|
import { OpIdReused } from "./revision-store.js";
|
|
46
46
|
import { pruneStateRevisions } from "./state-retention.js";
|
|
47
|
+
import { dropTenantOutputs, dropWorkspaceOutputs, moveWorkspaceOutputs, settleRunOutputs } from "./run-outputs.js";
|
|
47
48
|
// ------------------------------------------------------------- the backend
|
|
48
49
|
let backend = null;
|
|
49
50
|
let gate = { journal: () => false, read: () => false };
|
|
@@ -424,6 +425,7 @@ const background = new Set();
|
|
|
424
425
|
export async function settleLifecycle() {
|
|
425
426
|
while (background.size)
|
|
426
427
|
await Promise.allSettled([...background]);
|
|
428
|
+
await settleRunOutputs();
|
|
427
429
|
}
|
|
428
430
|
function inBackground(p) {
|
|
429
431
|
const q = p.finally(() => background.delete(q));
|
|
@@ -472,6 +474,8 @@ export async function dropWorkspaceRevisions(tenant, workspace, remove) {
|
|
|
472
474
|
await before?.catch(() => { });
|
|
473
475
|
try {
|
|
474
476
|
await deps.revisions.drop({ tenant, workspace });
|
|
477
|
+
// The run outputs published to the blob store (run-outputs.ts) are this workspace's too.
|
|
478
|
+
await dropWorkspaceOutputs(tenant, workspace);
|
|
475
479
|
}
|
|
476
480
|
catch (err) {
|
|
477
481
|
// Nothing was removed and the workspace stays: whatever was queued is lost to the queue, so it is reconciled from the folder.
|
|
@@ -482,6 +486,7 @@ export async function dropWorkspaceRevisions(tenant, workspace, remove) {
|
|
|
482
486
|
remove?.();
|
|
483
487
|
dropJournal(tenant, workspace);
|
|
484
488
|
await deps.revisions.drop({ tenant, workspace });
|
|
489
|
+
await dropWorkspaceOutputs(tenant, workspace);
|
|
485
490
|
marked.delete(k);
|
|
486
491
|
verified.delete(k);
|
|
487
492
|
}
|
|
@@ -506,6 +511,7 @@ export async function dropTenantRevisions(tenant) {
|
|
|
506
511
|
verified.delete(k);
|
|
507
512
|
}
|
|
508
513
|
await deps.revisions.drop({ tenant });
|
|
514
|
+
await dropTenantOutputs(tenant);
|
|
509
515
|
await deps.blobs.purgeTenant?.(tenant);
|
|
510
516
|
}
|
|
511
517
|
/** The sync hook: a folder was renamed by a caller that did not wait for us. */
|
|
@@ -539,12 +545,17 @@ export async function moveWorkspaceRevisions(tenant, from, to, rename) {
|
|
|
539
545
|
// process left for it is stale.
|
|
540
546
|
dropJournal(tenant, to);
|
|
541
547
|
await deps.revisions.move(tenant, from, to);
|
|
548
|
+
await moveWorkspaceOutputs(tenant, from, to).catch(async (err) => {
|
|
549
|
+
await deps.revisions.move(tenant, to, from).catch((e) => opsError("revisions.move_back_failed", e, { tenant, workspace: from, to }));
|
|
550
|
+
throw err;
|
|
551
|
+
});
|
|
542
552
|
if (rename) {
|
|
543
553
|
try {
|
|
544
554
|
rename();
|
|
545
555
|
}
|
|
546
556
|
catch (err) {
|
|
547
557
|
await deps.revisions.move(tenant, to, from).catch((e) => opsError("revisions.move_back_failed", e, { tenant, workspace: from, to }));
|
|
558
|
+
await moveWorkspaceOutputs(tenant, to, from).catch((e) => opsError("run_outputs.move_back_failed", e, { tenant, workspace: from, to }));
|
|
548
559
|
throw err;
|
|
549
560
|
}
|
|
550
561
|
}
|
package/package.json
CHANGED
package/src/browser-pod.ts
CHANGED
|
@@ -162,6 +162,9 @@ export function classifyCall(tool: string, input: Record<string, unknown> | unde
|
|
|
162
162
|
// tools: [peers] — reading the roster changes nothing; a message to a
|
|
163
163
|
// colleague is said, and a re-run would say it twice.
|
|
164
164
|
if (server === "foldrun_peers") return name === "peers_list" ? { write: false } : write("a message to a colleague");
|
|
165
|
+
// tools: [text] — reading a file out as text changes nothing, unless it
|
|
166
|
+
// was asked to save that text beside the file.
|
|
167
|
+
if (server === "foldrun_text") return args.save === true ? write(`${String(args.path ?? "a file")}.txt (extract_text)`) : { write: false };
|
|
165
168
|
// remotes: — reading where a request got to changes nothing; a send, a
|
|
166
169
|
// reply or a cancel acts on an outside agent's system.
|
|
167
170
|
if (server === "foldrun_a2a") return name === "a2a_status" ? { write: false } : write(`${name.replace(/^a2a_/, "")} to an outside agent`);
|
package/src/completions.ts
CHANGED
|
@@ -78,6 +78,7 @@ const TOOL_GROUPS: Completion[] = [
|
|
|
78
78
|
{ label: "web", hint: "search, fetch, browse, crawl, map, extract, answer, monitor — providers under web:" },
|
|
79
79
|
{ label: "ask", hint: "ask_person — ask the person running the desk mid-step, and wait for the answer" },
|
|
80
80
|
{ label: "peers", hint: "peers_list + peers_message — the colleagues running beside it in its parallel group, and a message to one of them" },
|
|
81
|
+
{ label: "text", hint: "extract_text — an image, scanned PDF, office file, audio or video as text (Persian + English OCR, speech)" },
|
|
81
82
|
{ label: "install", hint: "install apt, pip or npm packages mid-step — every agent has it; disallowedTools: [install] removes it" },
|
|
82
83
|
];
|
|
83
84
|
|
package/src/egress.ts
CHANGED
|
@@ -192,11 +192,14 @@ export interface EgressHooks {
|
|
|
192
192
|
* addresses a colleague's message to the right inbox.
|
|
193
193
|
* `delegates` — the `sandbox: own` sub-agents this step may hand a job
|
|
194
194
|
* to over the delegate door (delegate-tools.ts); the proxy refuses any
|
|
195
|
-
* other name.
|
|
195
|
+
* other name.
|
|
196
|
+
* `text` — the step's agent holds tools: [text] (text-tool.ts): the proxy
|
|
197
|
+
* serves its `POST /text/<lease>` door to the extraction service, and
|
|
198
|
+
* refuses it on every other lease. */
|
|
196
199
|
/** `job` — a lease for a host-side model call (an eval's judge, a
|
|
197
200
|
* grader, a draft, the assistant) rather than a step: what the model
|
|
198
201
|
* gateway records the call against. */
|
|
199
|
-
lease(args: { tenant: string; runId: string; grant: EgressGrant; test?: boolean; step?: number; agent?: string; peers?: PeerInfo[]; who?: LeaseWho; delegates?: string[]; job?: { kind: "grade" | "judge" | "draft" | "assistant"; name?: string } }): Promise<EgressLease | null>;
|
|
202
|
+
lease(args: { tenant: string; runId: string; grant: EgressGrant; test?: boolean; step?: number; agent?: string; peers?: PeerInfo[]; who?: LeaseWho; delegates?: string[]; text?: boolean; job?: { kind: "grade" | "judge" | "draft" | "assistant"; name?: string } }): Promise<EgressLease | null>;
|
|
200
203
|
/** The run is still being driven: renew its leases' heartbeat. Optional —
|
|
201
204
|
* an install without leases has nothing to renew. */
|
|
202
205
|
renew?(runId: string): Promise<number>;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// Text beside a run's media inputs (12 Nov 2026). A run handed a photo, a
|
|
2
|
+
// scanned PDF, a slide deck or a voice note (FOL-163, run-inputs.ts) gets,
|
|
3
|
+
// at staging, `<file>.txt` beside each one the platform could read — OCR, the
|
|
4
|
+
// document's text, a transcript — so the step starts with text it can read
|
|
5
|
+
// for the price of text, instead of an image block, a zip it cannot open, or
|
|
6
|
+
// nothing at all for audio.
|
|
7
|
+
//
|
|
8
|
+
// Core does not extract anything: the platform does, through
|
|
9
|
+
// platform.extractText (foldrun's own extraction pods). No hook — a laptop,
|
|
10
|
+
// a self-hosted install without the service — means no .txt and no note in
|
|
11
|
+
// the prompt. Best effort and bounded, so staging never stalls a run or
|
|
12
|
+
// fails it: INPUT_TEXT_LIMITS.totalMs across every input (past it, the rest
|
|
13
|
+
// are skipped), a size cap per file, recordings of at most ten minutes
|
|
14
|
+
// (the platform refuses longer before Whisper is asked). A file that yields
|
|
15
|
+
// nothing gets one line in the trail saying why; a `.txt` is never written
|
|
16
|
+
// over an input or a file of that name (`wx`).
|
|
17
|
+
|
|
18
|
+
import fs from "node:fs";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import type { RunInputFile } from "./storage.ts";
|
|
21
|
+
import type { ExtractTextAsk } from "./platform.ts";
|
|
22
|
+
|
|
23
|
+
export const INPUT_TEXT_LIMITS = {
|
|
24
|
+
/** Every input's extraction together, at staging. */
|
|
25
|
+
totalMs: 120_000,
|
|
26
|
+
/** The largest input sent for its text. */
|
|
27
|
+
fileBytes: 50 * 1024 * 1024,
|
|
28
|
+
/** The longest recording transcribed (the platform holds it). */
|
|
29
|
+
speechSeconds: 600,
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
export type MediaKind = "image" | "pdf" | "office" | "audio" | "video";
|
|
33
|
+
|
|
34
|
+
/** The extensions taken, by kind. Text, data and code are not here: the step
|
|
35
|
+
* reads those as they are. */
|
|
36
|
+
const BY_EXT: Record<string, MediaKind> = {
|
|
37
|
+
...Object.fromEntries(["png", "jpg", "jpeg", "gif", "webp", "tif", "tiff", "bmp", "heic", "heif"].map((e) => [e, "image" as const])),
|
|
38
|
+
pdf: "pdf",
|
|
39
|
+
...Object.fromEntries(["docx", "doc", "pptx", "ppt", "xlsx", "xls", "odt", "odp", "ods", "rtf", "epub"].map((e) => [e, "office" as const])),
|
|
40
|
+
...Object.fromEntries(["mp3", "wav", "m4a", "aac", "ogg", "oga", "opus", "flac", "wma", "amr"].map((e) => [e, "audio" as const])),
|
|
41
|
+
...Object.fromEntries(["mp4", "mov", "mkv", "webm", "avi", "m4v", "3gp", "mpeg", "mpg"].map((e) => [e, "video" as const])),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** The kind a file's name says, or null for anything not sent for text. */
|
|
45
|
+
export function mediaKindByName(name: string): MediaKind | null {
|
|
46
|
+
const ext = /\.([a-z0-9]{1,8})$/i.exec(name)?.[1]?.toLowerCase();
|
|
47
|
+
return ext ? (BY_EXT[ext] ?? null) : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** What a file's first bytes say it is — the containers, not the codecs. */
|
|
51
|
+
export type Sniffed = "png" | "jpeg" | "gif" | "webp" | "tiff" | "bmp" | "pdf" | "zip" | "ole" | "rtf" | "mp3" | "wav" | "ogg" | "flac" | "aac" | "amr" | "asf" | "avi" | "isobmff" | "ebml" | "mpeg-ps";
|
|
52
|
+
|
|
53
|
+
export function sniff(head: Buffer): Sniffed | null {
|
|
54
|
+
const at = (off: number, sig: number[]) => head.length >= off + sig.length && sig.every((b, i) => head[off + i] === b);
|
|
55
|
+
const ascii = (off: number, s: string) => head.length >= off + s.length && head.toString("latin1", off, off + s.length) === s;
|
|
56
|
+
if (at(0, [0x89, 0x50, 0x4e, 0x47])) return "png";
|
|
57
|
+
if (at(0, [0xff, 0xd8, 0xff])) return "jpeg";
|
|
58
|
+
if (ascii(0, "GIF8")) return "gif";
|
|
59
|
+
if (ascii(0, "RIFF") && ascii(8, "WEBP")) return "webp";
|
|
60
|
+
if (ascii(0, "RIFF") && ascii(8, "WAVE")) return "wav";
|
|
61
|
+
if (ascii(0, "RIFF") && ascii(8, "AVI ")) return "avi";
|
|
62
|
+
if (at(0, [0x49, 0x49, 0x2a, 0x00]) || at(0, [0x4d, 0x4d, 0x00, 0x2a])) return "tiff";
|
|
63
|
+
if (ascii(0, "BM")) return "bmp";
|
|
64
|
+
if (ascii(0, "%PDF")) return "pdf";
|
|
65
|
+
if (at(0, [0x50, 0x4b, 0x03, 0x04])) return "zip";
|
|
66
|
+
if (at(0, [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1])) return "ole";
|
|
67
|
+
if (ascii(0, "{\\rtf")) return "rtf";
|
|
68
|
+
if (ascii(0, "ID3") || (head.length >= 2 && head[0] === 0xff && (head[1]! & 0xe6) === 0xe2)) return "mp3";
|
|
69
|
+
if (head.length >= 2 && head[0] === 0xff && (head[1]! & 0xf6) === 0xf0) return "aac";
|
|
70
|
+
if (ascii(0, "OggS")) return "ogg";
|
|
71
|
+
if (ascii(0, "fLaC")) return "flac";
|
|
72
|
+
if (ascii(0, "#!AMR")) return "amr";
|
|
73
|
+
if (at(0, [0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11])) return "asf";
|
|
74
|
+
if (ascii(4, "ftyp")) return "isobmff";
|
|
75
|
+
if (at(0, [0x1a, 0x45, 0xdf, 0xa3])) return "ebml";
|
|
76
|
+
if (at(0, [0x00, 0x00, 0x01, 0xba])) return "mpeg-ps";
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The containers each kind may arrive in. */
|
|
81
|
+
const FITS: Record<MediaKind, ReadonlySet<Sniffed>> = {
|
|
82
|
+
image: new Set(["png", "jpeg", "gif", "webp", "tiff", "bmp", "isobmff"]),
|
|
83
|
+
pdf: new Set(["pdf"]),
|
|
84
|
+
office: new Set(["zip", "ole", "rtf"]),
|
|
85
|
+
audio: new Set(["mp3", "wav", "ogg", "flac", "aac", "amr", "asf", "isobmff", "ebml"]),
|
|
86
|
+
video: new Set(["isobmff", "ebml", "avi", "asf", "mpeg-ps", "ogg"]),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** The kind, when the name and the first bytes agree on one; else null. */
|
|
90
|
+
export function mediaKind(name: string, head: Buffer): MediaKind | null {
|
|
91
|
+
const byName = mediaKindByName(name);
|
|
92
|
+
if (!byName) return null;
|
|
93
|
+
const s = sniff(head);
|
|
94
|
+
return s && FITS[byName].has(s) ? byName : null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Inputs whose text may be put beside them: the media ones, small enough,
|
|
98
|
+
* with no input already taking `<path>.txt`. What the prompt's note marks. */
|
|
99
|
+
export function textCandidates(files: RunInputFile[]): RunInputFile[] {
|
|
100
|
+
const names = new Set(files.map((f) => f.path));
|
|
101
|
+
return files.filter((f) => mediaKindByName(f.path) && f.size <= INPUT_TEXT_LIMITS.fileBytes && !names.has(`${f.path}.txt`));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface TextBesideInputs {
|
|
105
|
+
tenant: string;
|
|
106
|
+
workspace: string;
|
|
107
|
+
runId: string;
|
|
108
|
+
files: RunInputFile[];
|
|
109
|
+
/** The staged inputs folder (stageRunInputs' `intoDir`). */
|
|
110
|
+
dir: string;
|
|
111
|
+
extract: (ask: ExtractTextAsk) => Promise<{ text: string; warnings?: string[] }>;
|
|
112
|
+
/** One line for the run's trail. */
|
|
113
|
+
emit: (line: string) => void;
|
|
114
|
+
/** Overrides, for tests. */
|
|
115
|
+
totalMs?: number;
|
|
116
|
+
fileBytes?: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const short = (s: string) => s.replace(/\s+/g, " ").trim().slice(0, 200);
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Write `<file>.txt` beside each media input the platform can read. Never
|
|
123
|
+
* throws for one file, and never runs past `totalMs`: what is left then is
|
|
124
|
+
* named in one line. Returns the .txt paths written (relative to `dir`) and
|
|
125
|
+
* the lines emitted.
|
|
126
|
+
*/
|
|
127
|
+
export async function textBesideInputs(o: TextBesideInputs): Promise<{ wrote: string[]; notes: string[] }> {
|
|
128
|
+
const totalMs = o.totalMs ?? INPUT_TEXT_LIMITS.totalMs;
|
|
129
|
+
const fileBytes = o.fileBytes ?? INPUT_TEXT_LIMITS.fileBytes;
|
|
130
|
+
const notes: string[] = [];
|
|
131
|
+
const note = (line: string) => {
|
|
132
|
+
notes.push(line);
|
|
133
|
+
try {
|
|
134
|
+
o.emit(line);
|
|
135
|
+
} catch {
|
|
136
|
+
/* the trail's problem, not the run's */
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const wrote: string[] = [];
|
|
140
|
+
const late: string[] = [];
|
|
141
|
+
const names = new Set(o.files.map((f) => f.path));
|
|
142
|
+
const clock = new AbortController();
|
|
143
|
+
// NOT unref'd: this function awaits the deadline, so the timer must keep
|
|
144
|
+
// the process alive until it fires (cleared in finally, at most totalMs).
|
|
145
|
+
// Unref'd, a hung extractor in a process with nothing else to do — the
|
|
146
|
+
// CLI's `foldrun run`, a test — let the event loop empty and the await
|
|
147
|
+
// never settle (the dev gate, 12 Nov 2026: "Promise resolution is still
|
|
148
|
+
// pending but the event loop has already resolved").
|
|
149
|
+
const timer = setTimeout(() => clock.abort(), totalMs);
|
|
150
|
+
try {
|
|
151
|
+
for (const f of o.files) {
|
|
152
|
+
const byName = mediaKindByName(f.path);
|
|
153
|
+
if (!byName) continue;
|
|
154
|
+
const target = `${f.path}.txt`;
|
|
155
|
+
if (names.has(target)) {
|
|
156
|
+
note(`inputs: ${f.path} → no text (${target} is an input of its own)`);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (clock.signal.aborted) {
|
|
160
|
+
late.push(f.path);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (f.size > fileBytes) {
|
|
164
|
+
note(`inputs: ${f.path} → no text (larger than ${Math.round(fileBytes / 1048576)} MB)`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const abs = path.join(o.dir, f.path);
|
|
168
|
+
const out = `${abs}.txt`;
|
|
169
|
+
try {
|
|
170
|
+
if (fs.existsSync(out)) {
|
|
171
|
+
note(`inputs: ${f.path} → no text (${target} is already there)`);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const bytes = fs.readFileSync(abs);
|
|
175
|
+
if (!mediaKind(f.path, bytes.subarray(0, 64))) {
|
|
176
|
+
note(`inputs: ${f.path} → no text (its bytes are not ${/^[aeiou]/.test(byName) ? "an" : "a"} ${byName} file)`);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
// Raced against the budget: an extractor that ignores its signal (or
|
|
180
|
+
// hangs) must not hold the step's start past it; an answer arriving
|
|
181
|
+
// after the deadline is dropped, never written.
|
|
182
|
+
const r = await new Promise<Awaited<ReturnType<typeof o.extract>>>((resolve, reject) => {
|
|
183
|
+
if (clock.signal.aborted) return reject(new Error("the budget ran out"));
|
|
184
|
+
const onAbort = () => reject(new Error("the budget ran out"));
|
|
185
|
+
clock.signal.addEventListener("abort", onAbort, { once: true });
|
|
186
|
+
o.extract({ tenant: o.tenant, workspace: o.workspace, runId: o.runId, name: path.basename(f.path), bytes, signal: clock.signal })
|
|
187
|
+
.then(resolve, reject)
|
|
188
|
+
.finally(() => clock.signal.removeEventListener("abort", onAbort));
|
|
189
|
+
});
|
|
190
|
+
if (clock.signal.aborted) {
|
|
191
|
+
late.push(f.path);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (!r.text.trim()) {
|
|
195
|
+
note(`inputs: ${f.path} → no text (none found)`);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
fs.writeFileSync(out, r.text.endsWith("\n") ? r.text : `${r.text}\n`, { flag: "wx" });
|
|
199
|
+
wrote.push(target);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
if (clock.signal.aborted) {
|
|
202
|
+
late.push(f.path);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const code = (err as NodeJS.ErrnoException)?.code;
|
|
206
|
+
note(`inputs: ${f.path} → no text (${code === "EEXIST" ? `${target} is already there` : short((err as Error)?.message ?? String(err)) || "the extraction failed"})`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
} finally {
|
|
210
|
+
clearTimeout(timer);
|
|
211
|
+
}
|
|
212
|
+
if (late.length) note(`inputs: ${late.join(", ")} → no text (the ${Math.round(totalMs / 1000)} s for inputs' text ran out)`);
|
|
213
|
+
if (wrote.length) note(`inputs: text beside ${wrote.length} file${wrote.length === 1 ? "" : "s"} — ${wrote.join(", ")}`);
|
|
214
|
+
return { wrote, notes };
|
|
215
|
+
}
|
package/src/limits.ts
CHANGED
|
@@ -66,6 +66,7 @@ const PLATFORM_SERVERS: Record<string, string> = {
|
|
|
66
66
|
foldrun_desks: "desks",
|
|
67
67
|
foldrun_ask: "ask",
|
|
68
68
|
foldrun_peers: "peers",
|
|
69
|
+
foldrun_text: "text",
|
|
69
70
|
};
|
|
70
71
|
|
|
71
72
|
/** One spelling for comparing: `desk-email` and `desk_email` are the same
|
|
@@ -291,7 +292,7 @@ export function limitKeyProblems(
|
|
|
291
292
|
ctx: { known: Iterable<string>; granted: Iterable<string> },
|
|
292
293
|
): { level: "error" | "warn"; message: string }[] {
|
|
293
294
|
const out: { level: "error" | "warn"; message: string }[] = [];
|
|
294
|
-
const builtinKeys = ["read", "write", "code", ...Object.keys(BUILTIN_GROUP), "TodoWrite", "search", "history", "desks", "ask", "web", A2A_LIMIT_KEY];
|
|
295
|
+
const builtinKeys = ["read", "write", "code", ...Object.keys(BUILTIN_GROUP), "TodoWrite", "search", "history", "desks", "ask", "text", "web", A2A_LIMIT_KEY];
|
|
295
296
|
const known = new Set([...builtinKeys, ...ctx.known].map(normKey));
|
|
296
297
|
const granted = new Set([...ctx.granted].flatMap((g) => {
|
|
297
298
|
const n = normKey(g);
|
package/src/manifest.ts
CHANGED
|
@@ -44,6 +44,11 @@ export interface ManifestEntry {
|
|
|
44
44
|
|
|
45
45
|
export interface Manifest {
|
|
46
46
|
v: 1;
|
|
47
|
+
/** Absent: a workspace manifest (paths under the authored/state roots).
|
|
48
|
+
* "run-output": what one agent of one run left in outputs/ (FOL-126 phase 5):
|
|
49
|
+
* any legal relative path, never a head, never restored. Part of the
|
|
50
|
+
* canonical form, so the two kinds can never share an id. */
|
|
51
|
+
kind?: "run-output";
|
|
47
52
|
/** Forward-slashed paths, relative to the workspace root. */
|
|
48
53
|
files: Record<string, ManifestEntry>;
|
|
49
54
|
}
|
|
@@ -115,7 +120,7 @@ export const MAX_PATH_BYTES = 400;
|
|
|
115
120
|
* are sharded. 50k files is ~5 MB of canonical JSON. */
|
|
116
121
|
export const MAX_MANIFEST_FILES = 50_000;
|
|
117
122
|
|
|
118
|
-
export function assertManifestPath(rel: string): string {
|
|
123
|
+
export function assertManifestPath(rel: string, kind?: Manifest["kind"]): string {
|
|
119
124
|
if (typeof rel !== "string" || !rel || Buffer.byteLength(rel) > MAX_PATH_BYTES) throw new Error(`illegal manifest path: ${String(rel).slice(0, 80)}`);
|
|
120
125
|
if (rel.includes("\\") || rel.startsWith("/") || /^[a-zA-Z]:/.test(rel)) throw new Error(`illegal manifest path: ${rel}`);
|
|
121
126
|
if (rel.split("/").some((s) => s === "" || s === "." || s === "..")) throw new Error(`illegal manifest path: ${rel}`);
|
|
@@ -124,7 +129,7 @@ export function assertManifestPath(rel: string): string {
|
|
|
124
129
|
// name on a Mac and two on Linux. A manifest holds the composed form, so it
|
|
125
130
|
// extracts the same everywhere. (Case is handled per manifest, below.)
|
|
126
131
|
if (rel !== rel.normalize("NFC")) throw new Error(`illegal manifest path (not NFC-normalised): ${rel}`);
|
|
127
|
-
if (sideOf(rel) === null) throw new Error(`${rel} is not workspace content (authored: ${[...AUTHORED_DIRS, ...AUTHORED_ROOT_FILES].join(", ")}; state: state/)`);
|
|
132
|
+
if (kind !== "run-output" && sideOf(rel) === null) throw new Error(`${rel} is not workspace content (authored: ${[...AUTHORED_DIRS, ...AUTHORED_ROOT_FILES].join(", ")}; state: state/)`);
|
|
128
133
|
return rel;
|
|
129
134
|
}
|
|
130
135
|
|
|
@@ -158,7 +163,7 @@ export function assertEntry(p: string, e: ManifestEntry): void {
|
|
|
158
163
|
* to WRITE — a revision must never point at a manifest it cannot read back. */
|
|
159
164
|
export function assertManifest(m: Manifest): void {
|
|
160
165
|
for (const [p, e] of Object.entries(m.files)) {
|
|
161
|
-
assertManifestPath(p);
|
|
166
|
+
assertManifestPath(p, m.kind);
|
|
162
167
|
assertEntry(p, e);
|
|
163
168
|
}
|
|
164
169
|
assertNoCaseCollisions(m);
|
|
@@ -176,12 +181,13 @@ export function modeFor(executable: boolean): number {
|
|
|
176
181
|
/** Sorted keys at every level, no whitespace: one tree, one byte string, one
|
|
177
182
|
* id — whichever machine wrote it. */
|
|
178
183
|
export function canonicalManifest(m: Manifest): string {
|
|
179
|
-
|
|
184
|
+
// No prototype: a path may be `__proto__` (review, 12 Nov 2026).
|
|
185
|
+
const files: Record<string, ManifestEntry> = Object.create(null);
|
|
180
186
|
for (const p of Object.keys(m.files).sort()) {
|
|
181
187
|
const e = m.files[p];
|
|
182
188
|
files[p] = { sha: e.sha, size: e.size, mode: e.mode };
|
|
183
189
|
}
|
|
184
|
-
return JSON.stringify({ v: 1, files });
|
|
190
|
+
return JSON.stringify(m.kind ? { v: 1, kind: m.kind, files } : { v: 1, files });
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
export function manifestId(m: Manifest): ManifestId {
|
|
@@ -201,6 +207,7 @@ export function parseManifest(text: string): Manifest {
|
|
|
201
207
|
if (raw?.v !== 1 || typeof raw.files !== "object" || raw.files === null || Array.isArray(raw.files)) {
|
|
202
208
|
throw new Error("not a manifest (v1)");
|
|
203
209
|
}
|
|
210
|
+
if (raw.kind !== undefined && raw.kind !== "run-output") throw new Error("not a manifest (unknown kind)");
|
|
204
211
|
assertManifest(raw);
|
|
205
212
|
return raw;
|
|
206
213
|
}
|