@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/src/starter.ts
CHANGED
|
@@ -502,9 +502,9 @@ model: default # fast | default | max
|
|
|
502
502
|
effort: low # how hard to think about it
|
|
503
503
|
size: large # small | large | heavy — the sandbox it rents
|
|
504
504
|
resources: { memory: 4Gi } # optional: cpu, memory, disk in numbers, over the size class
|
|
505
|
-
tools: [web, read, ask, peers, text, my-folder-tool] # built-ins and your own tools/, one list; \`ask\` lets it ask you mid-step, \`peers\` lets it message the steps running beside it, \`text\` reads images, PDFs, office files and recordings as text
|
|
505
|
+
tools: [web, read, ask, peers, text, my-folder-tool] # built-ins and your own tools/, one list; \`ask\` lets it ask you mid-step, \`peers\` lets it message the steps running beside it, \`text\` reads images, PDFs, office files and recordings as text, \`docs\` reads a library's current docs, \`video\` renders Remotion video
|
|
506
506
|
disallowedTools: [Bash] # subtract from what it would otherwise have
|
|
507
|
-
skills: [house-style] # from skills
|
|
507
|
+
skills: [house-style] # from skills/, the library, or the platform's gallery (modern-website, motion-video, cloudhost-deploy — by name only)
|
|
508
508
|
hooks: [no-force-push] # from hooks/ or the library: code at every tool call
|
|
509
509
|
scripts: [summarise.py] # from scripts/, each becomes a callable tool
|
|
510
510
|
apis: [{ name: crm }] # an HTTP API, as a tool
|
package/src/store.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
//
|
|
21
21
|
// An account is a named directory (per OKF: tenancy is a hosting concern).
|
|
22
22
|
|
|
23
|
+
import { opsError } from "./ops-log.ts";
|
|
23
24
|
import { readCompute } from "./resources.ts";
|
|
24
25
|
import { expandPlatformVars } from "./host-env.ts";
|
|
25
26
|
import { EFFORT_LEVELS, FLOW_TRIGGERS } from "./frontmatter-fields.ts";
|
|
@@ -31,7 +32,7 @@ import { processState } from "./process-state.ts";
|
|
|
31
32
|
import { dataRoot, singleWorkspace, singleAccountRoot, entriesNoFollow } from "./paths.ts";
|
|
32
33
|
import { platform } from "./platform.ts";
|
|
33
34
|
import { records } from "./records.ts";
|
|
34
|
-
import { docRows,
|
|
35
|
+
import { docRows, quietly } from "./workspace-docs.ts";
|
|
35
36
|
import { toLF, asRaw } from "./eol.ts";
|
|
36
37
|
import type { TestEffect } from "./test-mode.ts";
|
|
37
38
|
import type { OperatorEvent } from "./operator.ts";
|
|
@@ -59,7 +60,7 @@ import { parseBudget, budgetProblem } from "./budget.ts";
|
|
|
59
60
|
import { explainFailure, failureFactsOf, type FailureExplained, type FailureFacts } from "./failure.ts";
|
|
60
61
|
import { timezoneProblem } from "./clock.ts";
|
|
61
62
|
import { parseStepLimits, readLimits } from "./limits.ts";
|
|
62
|
-
import { networkEnforceWanted, networkProblems, resolveNetwork, type NetworkPolicy } from "./network.ts";
|
|
63
|
+
import { networkEnforceWanted, networkProblems, resolveNetwork, toolSites, type NetworkPolicy } from "./network.ts";
|
|
63
64
|
import { browseVendorOf } from "./browse-egress.ts";
|
|
64
65
|
import { searchProvided, type SearchingAction } from "./search-egress.ts";
|
|
65
66
|
import { webProblems, webWarnings, runnerEngines, webConfig } from "./providers.ts";
|
|
@@ -1663,6 +1664,22 @@ export function listAgents(tenant: string, workspace: string): AgentInfo[] {
|
|
|
1663
1664
|
};
|
|
1664
1665
|
const accountFront = frontOf(path.join(accountDir(tenant), "AGENTS.md"));
|
|
1665
1666
|
const workspaceFront = frontOf(path.join(workspaceDir(tenant, workspace), "AGENTS.md"));
|
|
1667
|
+
// The sites each tool's own definition names (`network:` in its tool.md),
|
|
1668
|
+
// nearest copy wins — the gallery's, the account library's, the
|
|
1669
|
+
// workspace's — read once for every agent below, as the runner reads them.
|
|
1670
|
+
let toolSiteMap: Record<string, string[]> | null = null;
|
|
1671
|
+
const sitesOfTools = (names: string[]): string[] => {
|
|
1672
|
+
if (!toolSiteMap) {
|
|
1673
|
+
const gallery = platform.galleryDir();
|
|
1674
|
+
const defs = {
|
|
1675
|
+
...(gallery ? readToolDir(path.join(gallery, "tools"), "account") : {}),
|
|
1676
|
+
...readToolDir(path.join(dataRoot(), tenant, "library", "tools"), "account"),
|
|
1677
|
+
...workspaceTools(tenant, workspace),
|
|
1678
|
+
};
|
|
1679
|
+
toolSiteMap = Object.fromEntries(Object.entries(defs).map(([n, d]) => [n, d.kind === "script" ? toolSites((d.spec as { network?: unknown }).network) : []]));
|
|
1680
|
+
}
|
|
1681
|
+
return names.flatMap((n) => toolSiteMap![n] ?? []);
|
|
1682
|
+
};
|
|
1666
1683
|
return fs
|
|
1667
1684
|
.readdirSync(dir)
|
|
1668
1685
|
.filter((n) => fs.existsSync(path.join(dir, n, "agent.md")))
|
|
@@ -1692,6 +1709,8 @@ export function listAgents(tenant: string, workspace: string): AgentInfo[] {
|
|
|
1692
1709
|
...parseApis(data.apis).map((a) => { try { return new URL(a.base).host; } catch { return ""; } }),
|
|
1693
1710
|
// remotes: — each card's own host, and nothing its card says.
|
|
1694
1711
|
...remoteNetworkHosts(parseRemotes(data.remotes)),
|
|
1712
|
+
// Each granted script tool's own network: list.
|
|
1713
|
+
...sitesOfTools(ownToolNames(data)),
|
|
1695
1714
|
],
|
|
1696
1715
|
}),
|
|
1697
1716
|
readsWeb,
|
|
@@ -4066,7 +4085,9 @@ export interface RunRecord {
|
|
|
4066
4085
|
// runs/<run>/). The runner writes them, secrets already masked.
|
|
4067
4086
|
|
|
4068
4087
|
const SAFE_ID = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
4069
|
-
|
|
4088
|
+
/** Captured calls kept as rows for one day on dev (13 Nov 2026); read and
|
|
4089
|
+
* dropped with their run, never written again. */
|
|
4090
|
+
const LEGACY_CALL_KIND = "call";
|
|
4070
4091
|
|
|
4071
4092
|
function capturedCallFile(workspaceRoot: string, runId: string, callId: string): string | null {
|
|
4072
4093
|
if (!SAFE_ID.test(runId) || !SAFE_ID.test(callId) || callId.startsWith(".") || runId.startsWith(".")) return null;
|
|
@@ -4075,14 +4096,9 @@ function capturedCallFile(workspaceRoot: string, runId: string, callId: string):
|
|
|
4075
4096
|
|
|
4076
4097
|
/** Merge one part (the input, on the call; the output, on its completion)
|
|
4077
4098
|
* into the call's file. */
|
|
4078
|
-
export function writeCapturedCall(workspaceRoot: string, runId: string, part: CapturedCall
|
|
4099
|
+
export function writeCapturedCall(workspaceRoot: string, runId: string, part: CapturedCall): void {
|
|
4079
4100
|
const file = capturedCallFile(workspaceRoot, runId, part.id);
|
|
4080
4101
|
if (!file) return;
|
|
4081
|
-
// A row when the platform keeps them (FOL-126): the two parts of a call
|
|
4082
|
-
// merge in one statement, and the web's copies read it wherever they run.
|
|
4083
|
-
// `truncated` is only ever sent true, so a merge keeps it once set.
|
|
4084
|
-
const store = scope ? docStore(scope.tenant, scope.workspace) : null;
|
|
4085
|
-
if (store && scope) return store.merge(scope.tenant, scope.workspace, CALL_KIND, `${runId}/${part.id}`, part as unknown as Record<string, unknown>);
|
|
4086
4102
|
let prev: Partial<CapturedCall> = {};
|
|
4087
4103
|
try {
|
|
4088
4104
|
prev = JSON.parse(fs.readFileSync(file, "utf8")) as CapturedCall;
|
|
@@ -4101,20 +4117,15 @@ export function writeCapturedCall(workspaceRoot: string, runId: string, part: Ca
|
|
|
4101
4117
|
export function readCapturedCall(tenant: string, workspace: string, runId: string, callId: string): CapturedCall | null {
|
|
4102
4118
|
const file = capturedCallFile(workspaceDir(tenant, workspace), runId, callId);
|
|
4103
4119
|
if (!file) return null;
|
|
4104
|
-
|
|
4105
|
-
|
|
4120
|
+
// A call kept as a workspace_docs row (records.docs_store, 13 Nov 2026,
|
|
4121
|
+
// before calls went to the blob store): still read until its run goes.
|
|
4122
|
+
const legacy = quietly(() => docRows(tenant, workspace)?.get(tenant, workspace, LEGACY_CALL_KIND, `${runId}/${callId}`), undefined) as CapturedCall | undefined;
|
|
4123
|
+
if (legacy) return legacy;
|
|
4106
4124
|
try {
|
|
4107
|
-
|
|
4125
|
+
return JSON.parse(fs.readFileSync(file, "utf8")) as CapturedCall;
|
|
4108
4126
|
} catch {
|
|
4109
|
-
|
|
4110
|
-
}
|
|
4111
|
-
// A switch between a call's two parts leaves one part in each place: both, merged.
|
|
4112
|
-
if (row && onFile) {
|
|
4113
|
-
const merged: CapturedCall = { ...onFile, ...row, truncated: Boolean(onFile.truncated || row.truncated) || undefined };
|
|
4114
|
-
if (!merged.truncated) delete merged.truncated;
|
|
4115
|
-
return merged;
|
|
4127
|
+
return null;
|
|
4116
4128
|
}
|
|
4117
|
-
return row ?? onFile ?? null;
|
|
4118
4129
|
}
|
|
4119
4130
|
|
|
4120
4131
|
export function runFilePath(tenant: string, workspace: string, runId: string) {
|
|
@@ -4154,8 +4165,7 @@ export function deleteRun(tenant: string, workspace: string, runId: string, opts
|
|
|
4154
4165
|
// and finishes — the other order left the content with nothing pointing
|
|
4155
4166
|
// at it (Codex review, FOL-124).
|
|
4156
4167
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
4157
|
-
|
|
4158
|
-
if (SAFE_ID.test(runId)) docRows(tenant, workspace)?.dropPrefix(tenant, workspace, CALL_KIND, `${runId}/`);
|
|
4168
|
+
if (SAFE_ID.test(runId)) quietly(() => docRows(tenant, workspace)?.dropPrefix(tenant, workspace, LEGACY_CALL_KIND, `${runId}/`), undefined);
|
|
4159
4169
|
if (port) port.runDelete(tenant, workspace, runId);
|
|
4160
4170
|
else {
|
|
4161
4171
|
fs.rmSync(file, { force: true });
|
|
@@ -4167,9 +4177,17 @@ export function deleteRun(tenant: string, workspace: string, runId: string, opts
|
|
|
4167
4177
|
if (prior?.inputs?.length) {
|
|
4168
4178
|
void import("./storage.ts").then((m) => m.releaseRunInputs(tenant, workspace, runId)).catch(() => {});
|
|
4169
4179
|
}
|
|
4170
|
-
// Outputs published to the blob store (run-outputs.ts
|
|
4171
|
-
// not files under dir: they go in
|
|
4172
|
-
|
|
4180
|
+
// Outputs and captured calls published to the blob store (run-outputs.ts,
|
|
4181
|
+
// captured-calls.ts) are records and pins, not files under dir: they go in
|
|
4182
|
+
// the background, retried.
|
|
4183
|
+
for (const [name, hook] of RUN_HOOKS.removed) {
|
|
4184
|
+
try {
|
|
4185
|
+
hook(tenant, workspace, runId);
|
|
4186
|
+
} catch (err) {
|
|
4187
|
+
// One store's clean-up failing must not stop the next one's.
|
|
4188
|
+
opsError("run_removed_hook.failed", err, { hook: name, tenant, runId });
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
4173
4191
|
if (!had) return true;
|
|
4174
4192
|
// The retention window's prune (`pruned`) is policy, not a person erasing
|
|
4175
4193
|
// history: no per-run ledger note. The charge stands either way.
|
|
@@ -4177,13 +4195,16 @@ export function deleteRun(tenant: string, workspace: string, runId: string, opts
|
|
|
4177
4195
|
return true;
|
|
4178
4196
|
}
|
|
4179
4197
|
|
|
4180
|
-
/** run-outputs.ts
|
|
4198
|
+
/** run-outputs.ts and captured-calls.ts register here (they import this module). */
|
|
4181
4199
|
type RunHook = (tenant: string, workspace: string, runId: string) => void;
|
|
4182
4200
|
/** One per process (process-state.ts): a run deleted from a route handler must
|
|
4183
4201
|
* reach the hooks the boot registered. */
|
|
4184
|
-
const RUN_HOOKS = processState("run-hooks", () => ({ removed:
|
|
4185
|
-
|
|
4186
|
-
|
|
4202
|
+
const RUN_HOOKS = processState("run-hooks", () => ({ removed: new Map<string, RunHook>(), deleted: undefined as RunHook | undefined }));
|
|
4203
|
+
/** A run's content lives somewhere other than its folder: `name` says whose hook
|
|
4204
|
+
* this is, so one registering (or clearing, with null) never replaces another's. */
|
|
4205
|
+
export function registerRunRemovedHook(fn: RunHook | null, name = "run-outputs") {
|
|
4206
|
+
if (fn) RUN_HOOKS.removed.set(name, fn);
|
|
4207
|
+
else RUN_HOOKS.removed.delete(name);
|
|
4187
4208
|
}
|
|
4188
4209
|
|
|
4189
4210
|
/** ledger.ts registers here — store cannot import it without a cycle, and
|