@foldrun/core 21.2.0 → 22.1.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/agent-import.js +3 -0
- package/dist/src/capture.d.ts +3 -6
- package/dist/src/capture.js +7 -5
- package/dist/src/captured-calls.d.ts +30 -0
- package/dist/src/captured-calls.js +219 -0
- package/dist/src/completions.js +2 -0
- package/dist/src/confine.d.ts +6 -0
- package/dist/src/confine.js +33 -0
- package/dist/src/frontmatter-fields.js +1 -0
- package/dist/src/frontmatter-schema.js +2 -0
- package/dist/src/mirror-base.d.ts +24 -0
- package/dist/src/mirror-base.js +82 -0
- package/dist/src/network.d.ts +13 -0
- package/dist/src/network.js +27 -0
- package/dist/src/records.d.ts +6 -1
- package/dist/src/revision-store.d.ts +12 -0
- package/dist/src/revision-store.js +27 -0
- package/dist/src/runner.d.ts +3 -0
- package/dist/src/runner.js +43 -5
- package/dist/src/script-tools.d.ts +4 -0
- package/dist/src/script-tools.js +2 -0
- package/dist/src/starter.js +2 -2
- package/dist/src/store.d.ts +5 -6
- package/dist/src/store.js +53 -30
- package/dist/src/workspace-revisions.d.ts +20 -0
- package/dist/src/workspace-revisions.js +397 -13
- package/package.json +1 -1
- package/src/agent-import.ts +3 -0
- package/src/capture.ts +7 -6
- package/src/captured-calls.ts +226 -0
- package/src/completions.ts +2 -0
- package/src/confine.ts +31 -0
- package/src/frontmatter-fields.ts +1 -0
- package/src/frontmatter-schema.ts +2 -0
- package/src/mirror-base.ts +91 -0
- package/src/network.ts +28 -0
- package/src/records.ts +6 -1
- package/src/revision-store.ts +37 -0
- package/src/runner.ts +45 -5
- package/src/script-tools.ts +6 -0
- package/src/starter.ts +2 -2
- package/src/store.ts +50 -29
- package/src/workspace-revisions.ts +358 -12
package/dist/src/agent-import.js
CHANGED
|
@@ -20,6 +20,7 @@ import { libraryDir, libraryTools } from "./library.js";
|
|
|
20
20
|
import { isRuntimeTool, toolEntryName } from "./tool-names.js";
|
|
21
21
|
import { discoverSkills } from "./runner.js";
|
|
22
22
|
import { listSecrets } from "./secrets.js";
|
|
23
|
+
import { platform } from "./platform.js";
|
|
23
24
|
/** An error the API layer turns into a status rather than a 500. */
|
|
24
25
|
export class AgentImportError extends Error {
|
|
25
26
|
status;
|
|
@@ -90,6 +91,8 @@ function missingFor(tenant, to, name, front) {
|
|
|
90
91
|
[ws, "skills"],
|
|
91
92
|
[ws, ".agents/skills"],
|
|
92
93
|
[libraryDir(tenant), "skills"],
|
|
94
|
+
// The platform's gallery skills are in every account.
|
|
95
|
+
...(platform.galleryDir() ? [[platform.galleryDir(), "skills"]] : []),
|
|
93
96
|
]) {
|
|
94
97
|
for (const s of discoverSkills(base, sub))
|
|
95
98
|
skills.add(s.name);
|
package/dist/src/capture.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CapturedCall } from "./store.ts";
|
|
1
2
|
import type { CallIo } from "./step-exec.ts";
|
|
2
3
|
/** How much past the cap a step sends, so masking sees a secret whole
|
|
3
4
|
* before the cut (a value longer than this is a file secret, which is also
|
|
@@ -21,9 +22,5 @@ export declare function maskCall(text: string, redactSecrets: (text: string) =>
|
|
|
21
22
|
export declare function recordCallIo(workspaceRoot: string, runId: string, callId: string, tool: string, io: CallIo,
|
|
22
23
|
/** The step's own scrub: its resolved secret values → `[redacted:NAME]`. */
|
|
23
24
|
redactSecrets: (text: string) => string,
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
scope?: {
|
|
27
|
-
tenant: string;
|
|
28
|
-
workspace: string;
|
|
29
|
-
}): boolean;
|
|
25
|
+
/** Where the part goes instead of the file beside the run (captured-calls.ts). */
|
|
26
|
+
sink?: (part: CapturedCall) => boolean): boolean;
|
package/dist/src/capture.js
CHANGED
|
@@ -98,13 +98,12 @@ export function maskCall(text, redactSecrets) {
|
|
|
98
98
|
export function recordCallIo(workspaceRoot, runId, callId, tool, io,
|
|
99
99
|
/** The step's own scrub: its resolved secret values → `[redacted:NAME]`. */
|
|
100
100
|
redactSecrets,
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
scope) {
|
|
101
|
+
/** Where the part goes instead of the file beside the run (captured-calls.ts). */
|
|
102
|
+
sink) {
|
|
104
103
|
try {
|
|
105
104
|
const input = io.input === undefined ? null : maskCall(io.input, redactSecrets);
|
|
106
105
|
const output = io.output === undefined ? null : maskCall(io.output, redactSecrets);
|
|
107
|
-
|
|
106
|
+
const part = {
|
|
108
107
|
id: callId,
|
|
109
108
|
tool,
|
|
110
109
|
// Which part was cut, each on its own: in the sandbox (the whole was
|
|
@@ -112,7 +111,10 @@ scope) {
|
|
|
112
111
|
...(input ? { input: input.text, ...(io.inputChars !== undefined ? { inputChars: io.inputChars } : {}), ...(input.cut || (io.inputChars ?? 0) > io.input.length ? { inputCut: true } : {}) } : {}),
|
|
113
112
|
...(output ? { output: output.text, ...(io.outputChars !== undefined ? { outputChars: io.outputChars } : {}), ...(output.cut || (io.outputChars ?? 0) > io.output.length ? { outputCut: true } : {}) } : {}),
|
|
114
113
|
...(io.truncated || input?.cut || output?.cut ? { truncated: true } : {}),
|
|
115
|
-
}
|
|
114
|
+
};
|
|
115
|
+
if (sink)
|
|
116
|
+
return sink(part);
|
|
117
|
+
writeCapturedCall(workspaceRoot, runId, part);
|
|
116
118
|
return true;
|
|
117
119
|
}
|
|
118
120
|
catch (err) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Deps } from "./publish.ts";
|
|
2
|
+
import { type CapturedCall } from "./store.ts";
|
|
3
|
+
/** Registered with the revision backend (workspace-revisions.ts): the blob store and the pins. */
|
|
4
|
+
export declare function setCallsBackend(deps: Deps | null): void;
|
|
5
|
+
/** The call could not be read back from where it was recorded. */
|
|
6
|
+
export declare class CapturedCallUnavailable extends Error {
|
|
7
|
+
constructor(callId: string, cause?: unknown);
|
|
8
|
+
}
|
|
9
|
+
interface Ctx {
|
|
10
|
+
tenant: string;
|
|
11
|
+
workspace: string;
|
|
12
|
+
runId: string;
|
|
13
|
+
workspaceRoot: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The runner's place to put a call's part (input on the call, output on its
|
|
17
|
+
* completion). Returns whether it was taken (the event says `captured`).
|
|
18
|
+
* `owner` is the step: flushCalls(owner) settles what it left.
|
|
19
|
+
*/
|
|
20
|
+
export declare function callSink(owner: object, ctx: Ctx): (part: CapturedCall) => boolean;
|
|
21
|
+
/** The step ended: write the inputs that never got an output, wait for every write. Never throws. */
|
|
22
|
+
export declare function flushCalls(owner: object): Promise<void>;
|
|
23
|
+
/** One recorded call, or null (not recorded). The row first, then the file. */
|
|
24
|
+
export declare function readCapturedCallAsync(tenant: string, workspace: string, runId: string, callId: string): Promise<CapturedCall | null>;
|
|
25
|
+
/** What the run-delete hook started and has not finished (tests, a process that is ending). */
|
|
26
|
+
export declare function settleCalls(): Promise<void>;
|
|
27
|
+
/** A workspace is being deleted (its rows still there): release the pin of every run that has calls
|
|
28
|
+
* in the store. Throws when the pins cannot be reached, so the delete can be retried. */
|
|
29
|
+
export declare function dropWorkspaceCalls(tenant: string, workspace: string): Promise<void>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Captured tool calls in the blob store (FOL-126 phase 7, step 2).
|
|
2
|
+
//
|
|
3
|
+
// A call's masked input and output used to be a file beside its run
|
|
4
|
+
// (runs/<run>/calls/<call>.json — store.ts writeCapturedCall), merged in place
|
|
5
|
+
// when the output arrived. With a database, a blob store and the setting
|
|
6
|
+
// `runs.calls_store` on, each call is ONE blob, written once when the call
|
|
7
|
+
// completes (the input waits in memory for its output: no read-merge-write),
|
|
8
|
+
// pinned by a run holder (`calls:<run>`, no lease — it lives until the run is
|
|
9
|
+
// deleted) before the upload, and indexed by a step-state row (kind "call",
|
|
10
|
+
// ref = the call id → {sha, size}). Masking is capture.ts's and is done before
|
|
11
|
+
// anything gets here; a part over the cap was cut and flagged there.
|
|
12
|
+
//
|
|
13
|
+
// Reads look at the row first, then at the file, so every run stays readable
|
|
14
|
+
// whichever way the switch is set. A row whose blob cannot be read is an error
|
|
15
|
+
// (CapturedCallUnavailable), never "nothing recorded".
|
|
16
|
+
//
|
|
17
|
+
// TEMPORARY, remove at cutover (phase 9): a write that fails with an error
|
|
18
|
+
// (store down, database refuses) falls back to the volume file and logs
|
|
19
|
+
// `captured_calls.fallback`. At cutover that branch becomes "the call is not
|
|
20
|
+
// recorded, and the event says so".
|
|
21
|
+
import { records } from "./records.js";
|
|
22
|
+
import { blobObjectKey, sha256Hex } from "./manifest.js";
|
|
23
|
+
import { opsError } from "./ops-log.js";
|
|
24
|
+
import { BlobNotFound, readAll } from "./blob-store.js";
|
|
25
|
+
import { writeCapturedCall, readCapturedCall, registerRunRemovedHook } from "./store.js";
|
|
26
|
+
import { processState } from "./process-state.js";
|
|
27
|
+
const KIND = "call";
|
|
28
|
+
const SAFE = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
29
|
+
const holderOf = (runId) => ({ kind: "run", id: `calls:${runId}` });
|
|
30
|
+
/** One per process (process-state.ts): the store the boot registered and the
|
|
31
|
+
* clean-ups in flight, whichever copy of this module a route handler holds. */
|
|
32
|
+
const CALLS = processState("captured-calls", () => ({ backend: null, background: new Set() }));
|
|
33
|
+
/** Registered with the revision backend (workspace-revisions.ts): the blob store and the pins. */
|
|
34
|
+
export function setCallsBackend(deps) {
|
|
35
|
+
CALLS.backend = deps;
|
|
36
|
+
registerRunRemovedHook(deps ? runGone : null, "captured-calls");
|
|
37
|
+
}
|
|
38
|
+
/** The call could not be read back from where it was recorded. */
|
|
39
|
+
export class CapturedCallUnavailable extends Error {
|
|
40
|
+
constructor(callId, cause) {
|
|
41
|
+
super(`captured call unavailable: the recorded content of call "${callId}" could not be read from storage`);
|
|
42
|
+
this.name = "CapturedCallUnavailable";
|
|
43
|
+
if (cause !== undefined)
|
|
44
|
+
this.cause = cause;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const portFor = (tenant, workspace) => {
|
|
48
|
+
const p = records(tenant, workspace);
|
|
49
|
+
// stepRuns too: without it a deleted workspace's calls could never be
|
|
50
|
+
// found again to release their pins (Codex review, 13 Nov 2026).
|
|
51
|
+
return p?.async?.stepPut && p.async.stepGet && p.async.stepRuns ? p : null;
|
|
52
|
+
};
|
|
53
|
+
const switchedOn = (p) => {
|
|
54
|
+
try {
|
|
55
|
+
return p.callsStoreOn?.() === true;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/** Where a new call goes: the store (deps + port), or null (the volume). */
|
|
62
|
+
function active(tenant, workspace) {
|
|
63
|
+
const deps = CALLS.backend;
|
|
64
|
+
const port = portFor(tenant, workspace);
|
|
65
|
+
return deps && port && switchedOn(port) ? { deps, port } : null;
|
|
66
|
+
}
|
|
67
|
+
const merge = (prev, part) => {
|
|
68
|
+
const next = { ...prev, ...part, truncated: Boolean(prev?.truncated || part.truncated) || undefined };
|
|
69
|
+
if (!next.truncated)
|
|
70
|
+
delete next.truncated;
|
|
71
|
+
return next;
|
|
72
|
+
};
|
|
73
|
+
const sessions = new WeakMap();
|
|
74
|
+
/** One blob per call: pin, upload, then the row that names it. */
|
|
75
|
+
async function storeCall(ctx, call) {
|
|
76
|
+
const a = active(ctx.tenant, ctx.workspace);
|
|
77
|
+
const fall = (err) => {
|
|
78
|
+
// TEMPORARY (see the header): the volume copy, so the call is not lost.
|
|
79
|
+
opsError("captured_calls.fallback", err, { tenant: ctx.tenant, workspace: ctx.workspace, runId: ctx.runId, callId: call.id });
|
|
80
|
+
try {
|
|
81
|
+
writeCapturedCall(ctx.workspaceRoot, ctx.runId, call);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
opsError("capture.write_failed", e, { runId: ctx.runId });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
if (!a)
|
|
88
|
+
return fall(new Error("the call store went away before the call was written"));
|
|
89
|
+
try {
|
|
90
|
+
const bytes = Buffer.from(JSON.stringify(call));
|
|
91
|
+
const sha = sha256Hex(bytes);
|
|
92
|
+
await a.deps.pins?.pinBlobs(ctx.tenant, [sha], holderOf(ctx.runId));
|
|
93
|
+
await a.deps.blobs.putIfAbsent(blobObjectKey(ctx.tenant, sha), bytes, { contentType: "application/json" });
|
|
94
|
+
await a.port.async.stepPut(ctx.tenant, ctx.workspace, ctx.runId, KIND, call.id, { sha, size: bytes.length });
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
fall(err);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The runner's place to put a call's part (input on the call, output on its
|
|
102
|
+
* completion). Returns whether it was taken (the event says `captured`).
|
|
103
|
+
* `owner` is the step: flushCalls(owner) settles what it left.
|
|
104
|
+
*/
|
|
105
|
+
export function callSink(owner, ctx) {
|
|
106
|
+
const s = { ctx, pending: new Map(), writes: new Set() };
|
|
107
|
+
sessions.set(owner, s);
|
|
108
|
+
return (part) => {
|
|
109
|
+
if (!SAFE.test(part.id) || !SAFE.test(ctx.runId))
|
|
110
|
+
return false;
|
|
111
|
+
const live = active(ctx.tenant, ctx.workspace);
|
|
112
|
+
const waiting = s.pending.get(part.id);
|
|
113
|
+
if (live && part.output === undefined) {
|
|
114
|
+
s.pending.set(part.id, merge(waiting, part));
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
s.pending.delete(part.id);
|
|
118
|
+
// A call whose input went to the volume before the switch flipped, or on another worker.
|
|
119
|
+
const prev = waiting ?? (live ? readCapturedCall(ctx.tenant, ctx.workspace, ctx.runId, part.id) ?? undefined : undefined);
|
|
120
|
+
const whole = merge(prev, part);
|
|
121
|
+
if (!live) {
|
|
122
|
+
writeCapturedCall(ctx.workspaceRoot, ctx.runId, whole);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
const w = storeCall(ctx, whole).finally(() => s.writes.delete(w));
|
|
126
|
+
s.writes.add(w);
|
|
127
|
+
return true;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** The step ended: write the inputs that never got an output, wait for every write. Never throws. */
|
|
131
|
+
export async function flushCalls(owner) {
|
|
132
|
+
const s = sessions.get(owner);
|
|
133
|
+
if (!s)
|
|
134
|
+
return;
|
|
135
|
+
sessions.delete(owner);
|
|
136
|
+
for (const call of s.pending.values()) {
|
|
137
|
+
if (active(s.ctx.tenant, s.ctx.workspace))
|
|
138
|
+
s.writes.add(storeCall(s.ctx, call));
|
|
139
|
+
else {
|
|
140
|
+
try {
|
|
141
|
+
writeCapturedCall(s.ctx.workspaceRoot, s.ctx.runId, call);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
opsError("capture.write_failed", err, { runId: s.ctx.runId });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
s.pending.clear();
|
|
149
|
+
await Promise.allSettled([...s.writes]);
|
|
150
|
+
}
|
|
151
|
+
/** One recorded call, or null (not recorded). The row first, then the file. */
|
|
152
|
+
export async function readCapturedCallAsync(tenant, workspace, runId, callId) {
|
|
153
|
+
if (!SAFE.test(runId) || !SAFE.test(callId) || callId.startsWith(".") || runId.startsWith("."))
|
|
154
|
+
return null;
|
|
155
|
+
const port = portFor(tenant, workspace);
|
|
156
|
+
if (port) {
|
|
157
|
+
let row;
|
|
158
|
+
try {
|
|
159
|
+
row = (await port.async.stepGet(tenant, workspace, runId, KIND, callId));
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
throw new CapturedCallUnavailable(callId, err);
|
|
163
|
+
}
|
|
164
|
+
if (row) {
|
|
165
|
+
try {
|
|
166
|
+
if (!CALLS.backend || typeof row.sha !== "string")
|
|
167
|
+
throw new Error("the call store is not available here");
|
|
168
|
+
const call = JSON.parse((await readAll(CALLS.backend.blobs, blobObjectKey(tenant, row.sha))).toString("utf8"));
|
|
169
|
+
if (!call || typeof call !== "object" || call.id !== callId)
|
|
170
|
+
throw new Error("the stored object is not this call");
|
|
171
|
+
return call;
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
if (!(err instanceof BlobNotFound))
|
|
175
|
+
opsError("captured_calls.read_failed", err, { tenant, workspace, runId, callId });
|
|
176
|
+
throw new CapturedCallUnavailable(callId, err);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return readCapturedCall(tenant, workspace, runId, callId);
|
|
181
|
+
}
|
|
182
|
+
// ---------------------------------------------------------------- lifecycle
|
|
183
|
+
/** What the run-delete hook started and has not finished (tests, a process that is ending). */
|
|
184
|
+
export async function settleCalls() {
|
|
185
|
+
while (CALLS.background.size)
|
|
186
|
+
await Promise.allSettled([...CALLS.background]);
|
|
187
|
+
}
|
|
188
|
+
/** A run was deleted: its calls' pin goes (the rows went with it; the sweeper takes the blobs). */
|
|
189
|
+
function runGone(tenant, _workspace, runId) {
|
|
190
|
+
const deps = CALLS.backend;
|
|
191
|
+
if (!deps?.pins || !SAFE.test(runId))
|
|
192
|
+
return;
|
|
193
|
+
const p = (async () => {
|
|
194
|
+
for (let attempt = 0;; attempt++) {
|
|
195
|
+
try {
|
|
196
|
+
await deps.pins.release(tenant, holderOf(runId));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
// A pin that cannot be released is kept: a leak is safe, a loss is not.
|
|
201
|
+
if (attempt >= 4)
|
|
202
|
+
return opsError("captured_calls.drop_failed", err, { tenant, runId });
|
|
203
|
+
await new Promise((r) => setTimeout(r, 1000 * 2 ** attempt));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
})();
|
|
207
|
+
const q = p.finally(() => CALLS.background.delete(q));
|
|
208
|
+
CALLS.background.add(q);
|
|
209
|
+
}
|
|
210
|
+
/** A workspace is being deleted (its rows still there): release the pin of every run that has calls
|
|
211
|
+
* in the store. Throws when the pins cannot be reached, so the delete can be retried. */
|
|
212
|
+
export async function dropWorkspaceCalls(tenant, workspace) {
|
|
213
|
+
const deps = CALLS.backend;
|
|
214
|
+
const port = records(tenant, workspace);
|
|
215
|
+
if (!deps?.pins || !port?.async?.stepRuns)
|
|
216
|
+
return;
|
|
217
|
+
for (const runId of await port.async.stepRuns(tenant, workspace, KIND))
|
|
218
|
+
await deps.pins.release(tenant, holderOf(runId));
|
|
219
|
+
}
|
package/dist/src/completions.js
CHANGED
|
@@ -36,6 +36,8 @@ const TOOL_GROUPS = [
|
|
|
36
36
|
{ label: "write", hint: "Read, Write, Edit, Glob, Grep" },
|
|
37
37
|
{ label: "code", hint: "Bash — runs anything in the sandbox" },
|
|
38
38
|
{ label: "web", hint: "search, fetch, browse, crawl, map, extract, answer, monitor — providers under web:" },
|
|
39
|
+
{ label: "docs", hint: "a library's current docs and code examples, pinned to a version (Context7) — gallery" },
|
|
40
|
+
{ label: "video", hint: "motion graphics and video from React code: new, compositions, still, render (Remotion) — gallery" },
|
|
39
41
|
{ label: "ask", hint: "ask_person — ask the person running the desk mid-step, and wait for the answer" },
|
|
40
42
|
{ label: "peers", hint: "peers_list + peers_message — the colleagues running beside it in its parallel group, and a message to one of them" },
|
|
41
43
|
{ label: "text", hint: "extract_text — an image, scanned PDF, office file, audio or video as text (Persian + English OCR, speech)" },
|
package/dist/src/confine.d.ts
CHANGED
|
@@ -41,6 +41,12 @@ export declare function expandVirtual(raw: string, roots: Roots): {
|
|
|
41
41
|
readOnly: boolean;
|
|
42
42
|
prefix: string;
|
|
43
43
|
} | null;
|
|
44
|
+
/**
|
|
45
|
+
* The platform shelf's copy of a library skill file the account does not
|
|
46
|
+
* have: `<library>/skills/<rest>` missing on disk, `<gallery>/skills/<rest>`
|
|
47
|
+
* there. Null otherwise — the account's own copy always wins.
|
|
48
|
+
*/
|
|
49
|
+
export declare function gallerySkillFile(abs: string, library: string): string | null;
|
|
44
50
|
export declare function checkPaths(toolName: string, input: Record<string, unknown>, roots: Roots): ConfineVerdict;
|
|
45
51
|
export declare function checkBash(command: string): ConfineVerdict;
|
|
46
52
|
export declare function linkWorkspace(agentDir: string, workspaceRoot: string): {
|
package/dist/src/confine.js
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
import fs from "node:fs";
|
|
31
31
|
import path from "node:path";
|
|
32
32
|
import { refusedBack } from "./copy-back.js";
|
|
33
|
+
import { platform } from "./platform.js";
|
|
33
34
|
/**
|
|
34
35
|
* A path with its symlinks resolved, as far as it exists.
|
|
35
36
|
*
|
|
@@ -193,6 +194,27 @@ function linkedWorkspace(roots) {
|
|
|
193
194
|
return false;
|
|
194
195
|
}
|
|
195
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* The platform shelf's copy of a library skill file the account does not
|
|
199
|
+
* have: `<library>/skills/<rest>` missing on disk, `<gallery>/skills/<rest>`
|
|
200
|
+
* there. Null otherwise — the account's own copy always wins.
|
|
201
|
+
*/
|
|
202
|
+
export function gallerySkillFile(abs, library) {
|
|
203
|
+
const gallery = platform.galleryDir();
|
|
204
|
+
if (!gallery)
|
|
205
|
+
return null;
|
|
206
|
+
const rel = path.relative(library, abs);
|
|
207
|
+
if (rel.startsWith("..") || path.isAbsolute(rel))
|
|
208
|
+
return null;
|
|
209
|
+
const parts = rel.split(path.sep);
|
|
210
|
+
if (parts[0] !== "skills" || parts.length < 2 || fs.existsSync(abs))
|
|
211
|
+
return null;
|
|
212
|
+
const shelfSkills = real(path.resolve(gallery, "skills"));
|
|
213
|
+
const candidate = real(path.resolve(shelfSkills, ...parts.slice(1)));
|
|
214
|
+
if (path.relative(shelfSkills, candidate).startsWith(".."))
|
|
215
|
+
return null;
|
|
216
|
+
return fs.existsSync(candidate) ? candidate : null;
|
|
217
|
+
}
|
|
196
218
|
export function checkPaths(toolName, input, roots) {
|
|
197
219
|
const workspace = real(path.resolve(roots.workspaceRoot));
|
|
198
220
|
const library = real(path.resolve(roots.libraryRoot));
|
|
@@ -214,6 +236,17 @@ export function checkPaths(toolName, input, roots) {
|
|
|
214
236
|
}
|
|
215
237
|
const virtual = expandVirtual(raw, roots);
|
|
216
238
|
const abs = real(virtual ? virtual.abs : path.resolve(roots.agentDir, raw));
|
|
239
|
+
// A gallery skill on a step with no sandbox. The prompt names every
|
|
240
|
+
// gallery skill under the account library (`../../../../library/skills/
|
|
241
|
+
// <name>/…`), because a sandbox has the gallery laid down there; on this
|
|
242
|
+
// host the library holds only the account's own files, so a read that
|
|
243
|
+
// finds nothing there is served from the platform's shelf. Reads only:
|
|
244
|
+
// the shelf is the platform's.
|
|
245
|
+
const shelf = !isWrite ? gallerySkillFile(abs, library) : null;
|
|
246
|
+
if (shelf) {
|
|
247
|
+
rewritten = { ...(rewritten ?? input), [key]: shelf };
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
217
250
|
// Knowledge is given, not learned: an agent that rewrites the price list
|
|
218
251
|
// it was handed has corrupted its own source of truth. What it discovers
|
|
219
252
|
// goes to memory/, which it owns.
|
|
@@ -152,6 +152,7 @@ const TOOL = [
|
|
|
152
152
|
{ key: "test_mode", type: "string", values: ["allow"], help: "script: allow — it may run in a test run" },
|
|
153
153
|
{ key: "secrets", type: ["list", "string"], help: "script: secret names, or proxied | materialised" },
|
|
154
154
|
{ key: "runtime", type: "object", help: "script: packages it needs" },
|
|
155
|
+
{ key: "network", type: ["list", "string"], help: "script: the sites its program reaches, added to the granting step's network: list — [api.example.com]" },
|
|
155
156
|
{ key: "code", type: "string", help: "script: the program inline" },
|
|
156
157
|
{ key: "command", type: "string", help: "mcp: the server's command" },
|
|
157
158
|
{ key: "env", type: "object", help: "mcp: its environment" },
|
|
@@ -11,6 +11,7 @@ import { modelSecretCollision } from "./model-credential.js";
|
|
|
11
11
|
import { resourcesProblem, computeProblem } from "./resources.js";
|
|
12
12
|
import { remotesProblem } from "./a2a-remotes.js";
|
|
13
13
|
import { a2aPublishProblem } from "./a2a-publish.js";
|
|
14
|
+
import { toolSiteProblems } from "./network.js";
|
|
14
15
|
export { FRONTMATTER, schemaKindOf } from "./frontmatter-fields.js";
|
|
15
16
|
/** A value for a message: a scalar as written, anything else by its shape.
|
|
16
17
|
* Never String() of a map — its `toString` is whatever the YAML says. */
|
|
@@ -71,6 +72,7 @@ const CHECKS = {
|
|
|
71
72
|
methods: methodsProblem,
|
|
72
73
|
rate: (v) => (parseRate(v) ? null : `"${shown(v)}" is not a rate — N/s, N/minute, N/hour, or a number per second, above 0`),
|
|
73
74
|
secrets: modelSecretCollision,
|
|
75
|
+
network: (v) => toolSiteProblems(v)[0] ?? null,
|
|
74
76
|
},
|
|
75
77
|
"eval": {
|
|
76
78
|
effort: (v) => (resolveEffort(v) ? null : `"${String(v)}" is not an effort — low, medium, high, xhigh or max; the judge runs at none`),
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface MirrorBase {
|
|
2
|
+
workspaceHead: string | null;
|
|
3
|
+
stateHead: string | null;
|
|
4
|
+
/** path → what the heads held for it at that sync (a path's base when this
|
|
5
|
+
* pod's change to it is published). */
|
|
6
|
+
files: Record<string, {
|
|
7
|
+
sha: string;
|
|
8
|
+
mode: number;
|
|
9
|
+
}>;
|
|
10
|
+
at: string;
|
|
11
|
+
}
|
|
12
|
+
/** The platform says whether this pod's folders are a copy of the heads
|
|
13
|
+
* (`revisions.mirror`). Off on a laptop, in the CLI and until switched on. */
|
|
14
|
+
export declare function setMirrorGate(fn: (() => boolean) | null): void;
|
|
15
|
+
export declare function mirrorOn(): boolean;
|
|
16
|
+
export declare const mirrorBaseFile: (tenant: string, workspace: string) => string | null;
|
|
17
|
+
export declare function readMirrorBase(tenant: string, workspace: string): MirrorBase | null;
|
|
18
|
+
export declare function writeMirrorBase(tenant: string, workspace: string, base: MirrorBase): void;
|
|
19
|
+
export declare function dropMirrorBase(tenant: string, workspace: string): void;
|
|
20
|
+
/** Every workspace this pod holds a copy of, by its base files. */
|
|
21
|
+
export declare function mirroredWorkspaces(): {
|
|
22
|
+
tenant: string;
|
|
23
|
+
workspace: string;
|
|
24
|
+
}[];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// What a pod's copy of a workspace was last brought to (FOL-126, 13 Nov 2026):
|
|
2
|
+
// the two head ids and every file's sha as the heads held them. The mirror
|
|
3
|
+
// (workspace-mirror.ts) writes it after a sync; the reconcile reads it so a
|
|
4
|
+
// file that differs from it is this pod's own change, and one that differs
|
|
5
|
+
// only from the head is someone else's, not yet copied here.
|
|
6
|
+
//
|
|
7
|
+
// Kept on the pod's own disk beside the folders, outside every workspace:
|
|
8
|
+
// <data>/.mirror/<tenant>/<workspace>.json. Lost with the disk, it is rebuilt
|
|
9
|
+
// by the next full sync (a pod starts with an empty disk anyway).
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import crypto from "node:crypto";
|
|
13
|
+
import { dataRoot } from "./paths.js";
|
|
14
|
+
import { processState } from "./process-state.js";
|
|
15
|
+
const GATE = processState("mirror-gate", () => ({ on: (() => false) }));
|
|
16
|
+
/** The platform says whether this pod's folders are a copy of the heads
|
|
17
|
+
* (`revisions.mirror`). Off on a laptop, in the CLI and until switched on. */
|
|
18
|
+
export function setMirrorGate(fn) {
|
|
19
|
+
GATE.on = fn ?? (() => false);
|
|
20
|
+
}
|
|
21
|
+
export function mirrorOn() {
|
|
22
|
+
try {
|
|
23
|
+
return GATE.on();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const SAFE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/;
|
|
30
|
+
export const mirrorBaseFile = (tenant, workspace) => SAFE.test(tenant) && SAFE.test(workspace) ? path.join(dataRoot(), ".mirror", tenant, `${workspace}.json`) : null;
|
|
31
|
+
export function readMirrorBase(tenant, workspace) {
|
|
32
|
+
const f = mirrorBaseFile(tenant, workspace);
|
|
33
|
+
if (!f)
|
|
34
|
+
return null;
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(fs.readFileSync(f, "utf8"));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function writeMirrorBase(tenant, workspace, base) {
|
|
43
|
+
const f = mirrorBaseFile(tenant, workspace);
|
|
44
|
+
if (!f)
|
|
45
|
+
return;
|
|
46
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
47
|
+
const tmp = `${f}.${process.pid}.${crypto.randomBytes(4).toString("hex")}.tmp`;
|
|
48
|
+
fs.writeFileSync(tmp, JSON.stringify(base));
|
|
49
|
+
fs.renameSync(tmp, f);
|
|
50
|
+
}
|
|
51
|
+
export function dropMirrorBase(tenant, workspace) {
|
|
52
|
+
const f = mirrorBaseFile(tenant, workspace);
|
|
53
|
+
if (f)
|
|
54
|
+
fs.rmSync(f, { force: true });
|
|
55
|
+
}
|
|
56
|
+
/** Every workspace this pod holds a copy of, by its base files. */
|
|
57
|
+
export function mirroredWorkspaces() {
|
|
58
|
+
const root = path.join(dataRoot(), ".mirror");
|
|
59
|
+
const out = [];
|
|
60
|
+
let tenants = [];
|
|
61
|
+
try {
|
|
62
|
+
tenants = fs.readdirSync(root);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
for (const tenant of tenants) {
|
|
68
|
+
if (!SAFE.test(tenant))
|
|
69
|
+
continue;
|
|
70
|
+
let files = [];
|
|
71
|
+
try {
|
|
72
|
+
files = fs.readdirSync(path.join(root, tenant));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
for (const f of files)
|
|
78
|
+
if (f.endsWith(".json") && SAFE.test(f.slice(0, -5)))
|
|
79
|
+
out.push({ tenant, workspace: f.slice(0, -5) });
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
package/dist/src/network.d.ts
CHANGED
|
@@ -47,6 +47,19 @@ export declare function siteCovers(site: string, host: string): boolean;
|
|
|
47
47
|
/** May a step under `policy` reach `host`? `open` reaches any public host —
|
|
48
48
|
* the caller still refuses private addresses, which no level opens. */
|
|
49
49
|
export declare function networkAllows(policy: Pick<NetworkPolicy, "level" | "hosts">, host: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The sites a tool's own definition says its program reaches — `network:
|
|
52
|
+
* [context7.com]` in a script tool's tool.md (13 Nov 2026). Granting the tool
|
|
53
|
+
* adds them to the step's list, the way an `apis:` base or a bound secret's
|
|
54
|
+
* site always was: the capability travels with what it needs, and an agent
|
|
55
|
+
* on `trusted` need not learn which hosts a gallery tool calls. A list or
|
|
56
|
+
* one comma-separated line of domains; what is not a site is dropped here
|
|
57
|
+
* and reported by `toolSiteProblems`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function toolSites(raw: unknown): string[];
|
|
60
|
+
/** What is wrong with a tool's `network:` — for check and deploy. A tool
|
|
61
|
+
* names sites only: the level (open, trusted, none) is the agent's to set. */
|
|
62
|
+
export declare function toolSiteProblems(raw: unknown): string[];
|
|
50
63
|
/**
|
|
51
64
|
* One `network:` value, read. Never throws: what cannot be read is a
|
|
52
65
|
* problem `check` and deploy report, and the run treats that level as
|
package/dist/src/network.js
CHANGED
|
@@ -139,6 +139,33 @@ function siteList(v) {
|
|
|
139
139
|
return v.map((x) => x.trim()).filter(Boolean);
|
|
140
140
|
return null;
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* The sites a tool's own definition says its program reaches — `network:
|
|
144
|
+
* [context7.com]` in a script tool's tool.md (13 Nov 2026). Granting the tool
|
|
145
|
+
* adds them to the step's list, the way an `apis:` base or a bound secret's
|
|
146
|
+
* site always was: the capability travels with what it needs, and an agent
|
|
147
|
+
* on `trusted` need not learn which hosts a gallery tool calls. A list or
|
|
148
|
+
* one comma-separated line of domains; what is not a site is dropped here
|
|
149
|
+
* and reported by `toolSiteProblems`.
|
|
150
|
+
*/
|
|
151
|
+
export function toolSites(raw) {
|
|
152
|
+
const list = siteList(raw) ?? [];
|
|
153
|
+
return [...new Set(list.map(normalHost).filter((h) => SITE.test(h) && !NETWORK_LEVELS.includes(h)))];
|
|
154
|
+
}
|
|
155
|
+
/** What is wrong with a tool's `network:` — for check and deploy. A tool
|
|
156
|
+
* names sites only: the level (open, trusted, none) is the agent's to set. */
|
|
157
|
+
export function toolSiteProblems(raw) {
|
|
158
|
+
if (raw === undefined || raw === null)
|
|
159
|
+
return [];
|
|
160
|
+
const list = siteList(raw);
|
|
161
|
+
if (!list)
|
|
162
|
+
return ["a tool's network: is a list of sites, e.g. [api.example.com]"];
|
|
163
|
+
return list.flatMap((x) => NETWORK_LEVELS.includes(normalHost(x))
|
|
164
|
+
? [`a tool's network: names sites, not a level — "${x}" is the agent's to set`]
|
|
165
|
+
: SITE.test(normalHost(x))
|
|
166
|
+
? []
|
|
167
|
+
: [`"${x}" is not a site — a domain or *.domain, no scheme, path or port`]);
|
|
168
|
+
}
|
|
142
169
|
/**
|
|
143
170
|
* One `network:` value, read. Never throws: what cannot be read is a
|
|
144
171
|
* problem `check` and deploy report, and the run treats that level as
|
package/dist/src/records.d.ts
CHANGED
|
@@ -23,11 +23,13 @@ export interface RecordsPortAsync {
|
|
|
23
23
|
stepPut?(tenant: string, workspace: string, runId: string, kind: string, ref: string, data: unknown): Promise<void>;
|
|
24
24
|
/** `ref` null: every ref of the kind. */
|
|
25
25
|
stepDrop?(tenant: string, workspace: string, runId: string, kind: string, ref: string | null): Promise<void>;
|
|
26
|
+
/** The ids of the runs that have rows of this kind in the workspace. */
|
|
27
|
+
stepRuns?(tenant: string, workspace: string, kind: string): Promise<string[]>;
|
|
26
28
|
}
|
|
27
29
|
/** Small per-workspace state that used to be files in the workspace's folder
|
|
28
30
|
* (FOL-126, the last files on the volume): webhook generations and the
|
|
29
31
|
* delivery log, eval results and their history, grades and grader cursors,
|
|
30
|
-
* the deployed commit
|
|
32
|
+
* the deployed commit. Two shapes: a DOCUMENT per
|
|
31
33
|
* (kind, key), and an append-only LOG per kind. Synchronous like the rest of
|
|
32
34
|
* the port; workspace-docs.ts is the only caller. */
|
|
33
35
|
export interface DocsPort {
|
|
@@ -72,6 +74,9 @@ export interface RecordsPort {
|
|
|
72
74
|
* state is written to the run's folder as before (it is still READ from
|
|
73
75
|
* rows first, so switching off mid-run loses nothing). */
|
|
74
76
|
stepStateOn?(): boolean;
|
|
77
|
+
/** The `runs.calls_store` setting, read per call: while false, a captured
|
|
78
|
+
* call is written to the run's folder as before (captured-calls.ts). */
|
|
79
|
+
callsStoreOn?(): boolean;
|
|
75
80
|
/** Insert or replace one run. `live`: queued, running or parked at a gate. Last write wins. */
|
|
76
81
|
runPut(tenant: string, workspace: string, run: RunRecord, summary: RunSummary, live: boolean): void;
|
|
77
82
|
runGet(tenant: string, workspace: string, id: string): RunRecord | null;
|
|
@@ -102,9 +102,21 @@ export interface IndexedFile {
|
|
|
102
102
|
updatedAt: string;
|
|
103
103
|
by: string;
|
|
104
104
|
}
|
|
105
|
+
/** One workspace's head ids (RevisionStore.allHeads). */
|
|
106
|
+
export interface HeadIds {
|
|
107
|
+
tenant: string;
|
|
108
|
+
workspace: string;
|
|
109
|
+
/** The workspace head's revision id; null when only the state head exists. */
|
|
110
|
+
workspaceHead: string | null;
|
|
111
|
+
stateHead: string | null;
|
|
112
|
+
}
|
|
105
113
|
export interface RevisionStore {
|
|
106
114
|
readonly kind: "pg" | "local";
|
|
107
115
|
head(ws: WorkspaceRef): Promise<Revision | null>;
|
|
116
|
+
/** Every workspace that has a head, with the ids of its two heads — what a
|
|
117
|
+
* pod whose folders are a copy of the heads compares itself with
|
|
118
|
+
* (workspace-mirror.ts). Optional: a store without it has no mirror. */
|
|
119
|
+
allHeads?(): Promise<HeadIds[]>;
|
|
108
120
|
revision(ws: WorkspaceRef, id: string): Promise<Revision | null>;
|
|
109
121
|
/** Newest first. `before` is a seq: pass the last page's lowest seq. */
|
|
110
122
|
revisions(ws: WorkspaceRef, opts?: {
|