@foldrun/core 24.2.2 → 24.3.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.
Files changed (64) hide show
  1. package/dist/src/account.js +2 -2
  2. package/dist/src/agent-import.js +2 -2
  3. package/dist/src/budget.js +1 -1
  4. package/dist/src/copy-back.js +2 -2
  5. package/dist/src/data-import.js +9 -9
  6. package/dist/src/deploy.js +2 -2
  7. package/dist/src/engine-loop.d.ts +45 -0
  8. package/dist/src/engine-loop.js +480 -0
  9. package/dist/src/engine-tools.d.ts +41 -0
  10. package/dist/src/engine-tools.js +579 -0
  11. package/dist/src/evals.js +1 -1
  12. package/dist/src/failure.js +1 -1
  13. package/dist/src/flow-lint.js +8 -8
  14. package/dist/src/frontmatter-fields.js +8 -8
  15. package/dist/src/mail.js +1 -1
  16. package/dist/src/manifest.js +1 -1
  17. package/dist/src/notify.js +2 -2
  18. package/dist/src/oauth-capabilities.js +1 -1
  19. package/dist/src/openapi.js +3 -3
  20. package/dist/src/package.js +2 -2
  21. package/dist/src/providers.js +2 -2
  22. package/dist/src/publish.js +2 -2
  23. package/dist/src/run-container.js +3 -3
  24. package/dist/src/scan.js +7 -7
  25. package/dist/src/secrets.js +7 -7
  26. package/dist/src/starter.js +18 -18
  27. package/dist/src/step-exec.d.ts +12 -1
  28. package/dist/src/step-exec.js +6 -2
  29. package/dist/src/storage.js +6 -6
  30. package/dist/src/store.js +16 -16
  31. package/dist/src/tool-test.js +1 -1
  32. package/dist/src/webhook.js +1 -1
  33. package/dist/src/workspace-revisions.js +2 -2
  34. package/package.json +1 -1
  35. package/src/account.ts +2 -2
  36. package/src/agent-import.ts +2 -2
  37. package/src/budget.ts +1 -1
  38. package/src/copy-back.ts +2 -2
  39. package/src/data-import.ts +9 -9
  40. package/src/deploy.ts +2 -2
  41. package/src/engine-loop.ts +495 -0
  42. package/src/engine-tools.ts +566 -0
  43. package/src/evals.ts +1 -1
  44. package/src/failure.ts +1 -1
  45. package/src/flow-lint.ts +8 -8
  46. package/src/frontmatter-fields.ts +8 -8
  47. package/src/mail.ts +1 -1
  48. package/src/manifest.ts +1 -1
  49. package/src/notify.ts +2 -2
  50. package/src/oauth-capabilities.ts +1 -1
  51. package/src/openapi.ts +3 -3
  52. package/src/package.ts +2 -2
  53. package/src/providers.ts +2 -2
  54. package/src/publish.ts +2 -2
  55. package/src/run-container.ts +3 -3
  56. package/src/scan.ts +7 -7
  57. package/src/secrets.ts +7 -7
  58. package/src/starter.ts +19 -19
  59. package/src/step-exec.ts +14 -2
  60. package/src/storage.ts +6 -6
  61. package/src/store.ts +16 -16
  62. package/src/tool-test.ts +1 -1
  63. package/src/webhook.ts +1 -1
  64. package/src/workspace-revisions.ts +2 -2
@@ -135,7 +135,7 @@ export function lintFlow(flow, known) {
135
135
  level: "error",
136
136
  message: zoneProblem,
137
137
  detail: "This is the zone the schedule fires in AND the calendar every step in this flow works " +
138
- "to. Unreadable, the schedule falls back to UTC and each step inherits the workspace's " +
138
+ "to. Unreadable, the schedule falls back to UTC and each step inherits the project's " +
139
139
  "zone instead of this one.",
140
140
  });
141
141
  }
@@ -193,7 +193,7 @@ export function lintFlow(flow, known) {
193
193
  // Trigger shapes that can never fire, said at check time rather than
194
194
  // discovered as a flow that "never runs".
195
195
  if (flow.budgetProblem) {
196
- warnings.push({ step: null, message: flow.budgetProblem, detail: "A flow's `budget:` is the most one run may spend — a number in USD, or `unlimited`. A cap over a day, week or month belongs in the workspace's or the account's AGENTS.md, where it means every run put together." });
196
+ warnings.push({ step: null, message: flow.budgetProblem, detail: "A flow's `budget:` is the most one run may spend — a number in USD, or `unlimited`. A cap over a day, week or month belongs in the project's or the account's AGENTS.md, where it means every run put together." });
197
197
  }
198
198
  if (flow.trigger === "once" && !flow.at) {
199
199
  warnings.push({ step: null, message: "trigger: once needs an `at:` instant", detail: "Write `at: 2026-09-05T09:00:00+10:00` (ISO 8601). Without a readable instant this flow never fires." });
@@ -203,7 +203,7 @@ export function lintFlow(flow, known) {
203
203
  }
204
204
  if (flow.trigger === "flow") {
205
205
  if (!flow.after)
206
- warnings.push({ step: null, message: "trigger: flow needs `after: <flow>`", detail: "Name the flow of this workspace whose finishing starts this one." });
206
+ warnings.push({ step: null, message: "trigger: flow needs `after: <flow>`", detail: "Name the flow of this project whose finishing starts this one." });
207
207
  else if (flow.after === flow.name)
208
208
  warnings.push({ step: null, message: "trigger: flow — a flow cannot chain on itself", detail: "That is a loop with no bound. Chain on the flow that produces what this one needs." });
209
209
  }
@@ -309,7 +309,7 @@ export function lintFlow(flow, known) {
309
309
  line: step.line,
310
310
  level: "error",
311
311
  kind: "outward",
312
- message: `[[${step.agent}]] can act outside this workspace and this step has no verify: and no gate`,
312
+ message: `[[${step.agent}]] can act outside this project and this step has no verify: and no gate`,
313
313
  detail: "A step that sends, posts, buys or publishes needs one of two things: a `verify:` the " +
314
314
  "runtime can fail the step on — a receipt file, a ledger row, the reply's own verdict " +
315
315
  "line — or a person, with `!` or `ask:`. Without either, a step that sent nothing and a " +
@@ -326,7 +326,7 @@ export function lintFlow(flow, known) {
326
326
  step: i,
327
327
  line: step.line,
328
328
  kind: "outward",
329
- message: `[[${step.agent}]] can act outside this workspace and this step has retry: ${step.retry}`,
329
+ message: `[[${step.agent}]] can act outside this project and this step has retry: ${step.retry}`,
330
330
  detail: "A retry runs the whole step again, sends included. The runner does not retry a failure " +
331
331
  "that came from the check after the step's tools ran, but an attempt that failed mid-way — " +
332
332
  "a timeout, a crash, a provider error after the first send — is retried and may repeat " +
@@ -376,7 +376,7 @@ export function lintFlow(flow, known) {
376
376
  step: i,
377
377
  line: step.line,
378
378
  level: "error",
379
- message: `[[${step.agent}]] is not an agent in this workspace`,
379
+ message: `[[${step.agent}]] is not an agent in this project`,
380
380
  detail: "This step has nothing to run. Every run of this flow fails here. Check the spelling " +
381
381
  "against `agents/<name>/agent.md` — the name is the folder's, not the file's heading — " +
382
382
  "or add the agent.",
@@ -428,7 +428,7 @@ export function lintFlow(flow, known) {
428
428
  warnings.push({
429
429
  step: i,
430
430
  line: step.line,
431
- message: `delegate: "${name}" is not an agent in this workspace`,
431
+ message: `delegate: "${name}" is not an agent in this project`,
432
432
  detail: "The runner only accepts picks from the declared set, so this name can never be " +
433
433
  "chosen — the step silently has one fewer colleague to call on. Fix the spelling, " +
434
434
  "or drop the name.",
@@ -439,7 +439,7 @@ export function lintFlow(flow, known) {
439
439
  warnings.push({
440
440
  step: i,
441
441
  line: step.line,
442
- message: `on-fail: "${step.onFail}" is not an agent in this workspace`,
442
+ message: `on-fail: "${step.onFail}" is not an agent in this project`,
443
443
  detail: "The recovery path is the one you cannot test by running the flow successfully. As " +
444
444
  "written, a failure here has nowhere to go and the step just fails.",
445
445
  });
@@ -30,7 +30,7 @@ const LOCALE = { validated: true };
30
30
  const AGENT = [
31
31
  { key: "name", type: "string", help: "kebab-case; the folder is the identity" },
32
32
  { key: "description", type: "string", help: "what it does and when — other agents and people read it" },
33
- { key: "owner", type: "string", help: "the person accountable for it — an email or a name; else the workspace's, else the account's" },
33
+ { key: "owner", type: "string", help: "the person accountable for it — an email or a name; else the project's, else the account's" },
34
34
  { key: "model", type: "string", help: "fast | default | max, an alias, or a full model id" },
35
35
  { key: "effort", type: "string", values: EFFORT_LEVELS, help: "how long it thinks" },
36
36
  { key: "max_output_tokens", type: ["number", "string"], help: "the most tokens one model reply may have, 1 to 1048576; on foldrun's models the price list's ceiling applies too" },
@@ -68,8 +68,8 @@ const AGENT = [
68
68
  const AGENTS_MD = [
69
69
  { key: "foldrun_version", type: ["string", "number"], help: "the format version this account targets" },
70
70
  { key: "mdagent_version", type: ["string", "number"], legacy: true, help: "older spelling of foldrun_version" },
71
- { key: "name", type: "string", help: "the workspace's name" },
72
- { key: "description", type: "string", help: "shown in the workspace list" },
71
+ { key: "name", type: "string", help: "the project's name" },
72
+ { key: "description", type: "string", help: "shown in the project list" },
73
73
  { key: "owner", type: "string", help: "the person accountable for every agent and flow here that names none" },
74
74
  { key: "provider", type: "object", help: "the model endpoint every agent here uses unless it names its own" },
75
75
  { key: "runtime", type: "object", help: "packages for agents that declare none" },
@@ -87,10 +87,10 @@ const AGENTS_MD = [
87
87
  { key: "budget", type: ["number", "string"], help: "USD per month, or N/day | N/week | N/month" },
88
88
  { key: "priority", type: "string", values: ["high", "normal", "low"], help: "account: where its runs stand in the queue" },
89
89
  { key: "concurrency", type: ["number", "string"], help: "account: runs at once" },
90
- { key: "compute", type: "object", help: "{vcpu, memory, disk} the running steps here may hold together — the account's pool, or this workspace's; only narrows the level above" },
90
+ { key: "compute", type: "object", help: "{vcpu, memory, disk} the running steps here may hold together — the account's pool, or this project's; only narrows the level above" },
91
91
  { key: "alerts", type: "object", validated: true, help: "thresholds that tell notify: — failure_rate (30%), min_runs, credits_day, run_minutes, stale_days, cost_spike, runs_per_hour, new_host" },
92
92
  { key: "capture", type: "string", values: ["full", "metadata"], help: "what runs record of each tool call: full (its input and output, secrets masked) or metadata (name, size and time only)" },
93
- { key: "network_enforce", type: "boolean", help: "true: a site off a step's network: list is refused, not only named in the trace. The account's or the workspace's true is enough" },
93
+ { key: "network_enforce", type: "boolean", help: "true: a site off a step's network: list is refused, not only named in the trace. The account's or the project's true is enough" },
94
94
  { key: "telemetry", type: "object", validated: true, help: "send each run as an OpenTelemetry trace — otlp: <https …/v1/traces>, headers: { authorization: ${SECRET} }" },
95
95
  { key: "deploy_block", type: "string", values: ["none", "secrets", "security"], help: "refuse a deploy on scanner findings: secrets (a key written in) or security (any security warning)" },
96
96
  { key: "judge", type: "object", validated: true, help: "the model every judge: here grades with — {model: fast | default | max, effort}; an eval's own model: wins" },
@@ -99,7 +99,7 @@ const AGENTS_MD = [
99
99
  const FLOW = [
100
100
  { key: "name", type: "string", help: "the flow's name" },
101
101
  { key: "description", type: "string", help: "what it is for" },
102
- { key: "owner", type: "string", help: "the person accountable for it — an email or a name; else the workspace's, else the account's" },
102
+ { key: "owner", type: "string", help: "the person accountable for it — an email or a name; else the project's, else the account's" },
103
103
  { key: "trigger", type: "string", values: FLOW_TRIGGERS, help: "what starts it; any other value never fires" },
104
104
  { key: "schedule", type: "string", help: "cron, when trigger: schedule" },
105
105
  { key: "timezone", type: "string", validated: true, help: "the zone its schedule reads in" },
@@ -128,7 +128,7 @@ const FLOW = [
128
128
  { key: "pause_when", type: "string", help: "a marker that pauses the flow when a run's result says it" },
129
129
  { key: "approvers", type: ["list", "string"], help: "who may approve its gates" },
130
130
  { key: "budget", type: ["number", "string"], help: "USD per run" },
131
- { key: "compute", type: "object", help: "{vcpu, memory, disk} one run's steps may hold together at once — only narrows the workspace's and account's" },
131
+ { key: "compute", type: "object", help: "{vcpu, memory, disk} one run's steps may hold together at once — only narrows the project's and account's" },
132
132
  { key: "live", type: "boolean", help: "true: steps may act for real in a test run" },
133
133
  { key: "a2a", type: "object", help: "serve this flow to outside agents over A2A 1.0 — {publish: true, name?, description?, examples?, public_card?, input?, accept_risk?: [agent]}; changing it needs workspace:manage" },
134
134
  ];
@@ -137,7 +137,7 @@ const TOOL = [
137
137
  { key: "description", type: "string", help: "what it does — the model chooses by it" },
138
138
  { key: "transport", type: "string", values: ["http", "script", "mcp"], help: "http | script | mcp" },
139
139
  { key: "type", type: "string", legacy: true, help: "older spelling of transport" },
140
- { key: "outward", type: "boolean", help: "true: it changes something outside the workspace" },
140
+ { key: "outward", type: "boolean", help: "true: it changes something outside the project" },
141
141
  { key: "base", type: "string", help: "http: the API's base URL" },
142
142
  { key: "headers", type: "object", help: "http or mcp: request headers; ${SECRET} is filled server-side" },
143
143
  { key: "query", type: "object", help: "http: query parameters on every call" },
package/dist/src/mail.js CHANGED
@@ -65,7 +65,7 @@ export const MAIL_CATEGORIES = [
65
65
  label: "Run alerts",
66
66
  required: false,
67
67
  perWorkspace: true,
68
- description: "A run failed, finished, or was blocked; a flow was quarantined, a run passed its SLA, a budget is nearly spent — mail from a workspace's notify: email.",
68
+ description: "A run failed, finished, or was blocked; a flow was quarantined, a run passed its SLA, a budget is nearly spent — mail from a project's notify: email.",
69
69
  },
70
70
  {
71
71
  id: "approvals",
@@ -114,7 +114,7 @@ export function assertManifestPath(rel, kind) {
114
114
  if (rel !== rel.normalize("NFC"))
115
115
  throw new Error(`illegal manifest path (not NFC-normalised): ${rel}`);
116
116
  if (kind !== "run-output" && sideOf(rel) === null)
117
- throw new Error(`${rel} is not workspace content (authored: ${[...AUTHORED_DIRS, ...AUTHORED_ROOT_FILES].join(", ")}; state: state/)`);
117
+ throw new Error(`${rel} is not project content (authored: ${[...AUTHORED_DIRS, ...AUTHORED_ROOT_FILES].join(", ")}; state: state/)`);
118
118
  return rel;
119
119
  }
120
120
  /** Two paths that differ only by case cannot both be extracted on a
@@ -282,7 +282,7 @@ export async function attemptWebhook(tenant, workspace, d) {
282
282
  const config = notifyConfig(tenant, workspace);
283
283
  const base = { n: d.attempt, at, ...(d.manual ? { manual: true } : {}) };
284
284
  if (!config?.url) {
285
- return { ...base, ok: false, statusCode: null, durationMs: 0, response: null, error: "this workspace's notify: has no url any more" };
285
+ return { ...base, ok: false, statusCode: null, durationMs: 0, response: null, error: "this project's notify: has no url any more" };
286
286
  }
287
287
  const { url, refused, filled } = webhookTarget(tenant, workspace, config);
288
288
  if (!url) {
@@ -471,7 +471,7 @@ export async function sendTestNotification(tenant, workspace) {
471
471
  return {
472
472
  ok: false,
473
473
  destination: "none",
474
- detail: "no notify: in this workspace's AGENTS.md or the account's — nothing would be sent for a failure or a gate either",
474
+ detail: "no notify: in this project's AGENTS.md or the account's — nothing would be sent for a failure or a gate either",
475
475
  };
476
476
  }
477
477
  const sent = new Date().toISOString();
@@ -153,7 +153,7 @@ export const OAUTH_CAPABILITIES = [
153
153
  },
154
154
  {
155
155
  id: "server.client-credentials", role: "server", title: "Client credentials for machine clients", spec: "RFC 6749 §4.4",
156
- status: "supported", note: "An admin registers a machine client (Settings, or `foldrun mcp clients add`) with a role, workspaces and access; no refresh token; disconnecting it makes it `invalid_client`.",
156
+ status: "supported", note: "An admin registers a machine client (Settings, or `foldrun mcp clients add`) with a role, projects and access; no refresh token; disconnecting it makes it `invalid_client`.",
157
157
  proof: [web("tests/mcp-oauth.test.ts", "machine clients (client credentials, part G)"), web("tests/mcp-oauth.test.ts", "a machine client can sign in with private_key_jwt"), cli("tests/cli-mcp.test.ts", "mcp clients add")],
158
158
  },
159
159
  {
@@ -250,7 +250,7 @@ export function loadOpenApiDocument(tenant, workspaceRoot, source) {
250
250
  const abs = path.resolve(root, source);
251
251
  const inside = (p, r) => p === r || p.startsWith(r + path.sep);
252
252
  if (!inside(abs, root))
253
- return { doc: null, error: `${source} escapes the workspace` };
253
+ return { doc: null, error: `${source} escapes the project` };
254
254
  let text;
255
255
  try {
256
256
  // The real path too: a symlink out of the workspace is still out. Both
@@ -258,12 +258,12 @@ export function loadOpenApiDocument(tenant, workspaceRoot, source) {
258
258
  // macOS is /private/var).
259
259
  const real = fs.realpathSync(abs);
260
260
  if (!inside(real, fs.realpathSync(root)))
261
- return { doc: null, error: `${source} escapes the workspace` };
261
+ return { doc: null, error: `${source} escapes the project` };
262
262
  text = fs.readFileSync(real, "utf8");
263
263
  }
264
264
  catch (err) {
265
265
  const code = err.code;
266
- return { doc: null, error: code === "ENOENT" ? `${source}: no such file in the workspace` : `${source}: ${err.message}` };
266
+ return { doc: null, error: code === "ENOENT" ? `${source}: no such file in the project` : `${source}: ${err.message}` };
267
267
  }
268
268
  try {
269
269
  return { doc: parseDocumentText(text), error: null };
@@ -69,7 +69,7 @@ const MAX_PACKAGE_FILE = 10 * 1024 * 1024;
69
69
  export function packageOf(tenant, workspace, kind, name) {
70
70
  assertSafeName(workspace, "workspace");
71
71
  if (!listWorkspaces(tenant).some((w) => w.name === workspace)) {
72
- throw new PackageError(`no workspace called "${workspace}" in this account`, 404);
72
+ throw new PackageError(`no project called "${workspace}" in this account`, 404);
73
73
  }
74
74
  const all = listWorkspaceFiles(tenant, workspace).filter(isPackagedPath);
75
75
  const read = (p) => readWorkspaceFile(tenant, workspace, p);
@@ -275,7 +275,7 @@ export function planImport(tenant, workspace, pkg) {
275
275
  assertSafeName(workspace, "workspace");
276
276
  const exists = listWorkspaces(tenant).some((w) => w.name === workspace);
277
277
  if (!exists && pkg.manifest.kind !== "workspace") {
278
- throw new PackageError(`no workspace called "${workspace}" — a ${pkg.manifest.kind} imports into one that exists`, 404);
278
+ throw new PackageError(`no project called "${workspace}" — a ${pkg.manifest.kind} imports into one that exists`, 404);
279
279
  }
280
280
  const dir = workspaceDir(tenant, workspace);
281
281
  const added = [];
@@ -689,10 +689,10 @@ export function readBrowseSettings(raw) {
689
689
  if (k === "init" || k === "extensions") {
690
690
  const list = browseList(v);
691
691
  if (!list)
692
- return { settings, rest: left(rest), error: `web.browse.${k} is a list of workspace paths, like [${k === "init" ? "scripts/stub.js" : "library/extensions/my-ext"}].` };
692
+ return { settings, rest: left(rest), error: `web.browse.${k} is a list of project paths, like [${k === "init" ? "scripts/stub.js" : "library/extensions/my-ext"}].` };
693
693
  const bad = list.find((p) => p.startsWith("/") || p.split(/[\\/]/).includes("..") || p.includes(","));
694
694
  if (bad)
695
- return { settings, rest: left(rest), error: `web.browse.${k}: ${bad} must be a path inside the workspace (no leading /, no .., no comma).` };
695
+ return { settings, rest: left(rest), error: `web.browse.${k}: ${bad} must be a path inside the project (no leading /, no .., no comma).` };
696
696
  if (list.length)
697
697
  settings[k] = list;
698
698
  continue;
@@ -329,7 +329,7 @@ async function publishScope(deps, input, scope, changes, opId) {
329
329
  return { status: "duplicate", revision: res.revision, conflicts: [] };
330
330
  // stale: the head moved. Fold again onto it.
331
331
  }
332
- throw new PublishError("the workspace changed too often while publishing; try again", "too_many_replays");
332
+ throw new PublishError("the project changed too often while publishing; try again", "too_many_replays");
333
333
  }
334
334
  /** Combine the two heads' answers: the workspace revision is `revision`, the
335
335
  * state one `stateRevision`; the status is the strongest of the two. */
@@ -412,7 +412,7 @@ async function restoreScope(deps, input, scope, toId, opId) {
412
412
  if (res.status === "duplicate")
413
413
  return { status: "duplicate", revision: res.revision, conflicts: [] };
414
414
  }
415
- throw new PublishError("the workspace changed too often while restoring; try again", "too_many_replays");
415
+ throw new PublishError("the project changed too often while restoring; try again", "too_many_replays");
416
416
  }
417
417
  /** A new revision with an old one's content. History is untouched. Refuses,
418
418
  * before committing anything, when a blob the old revision names is gone. */
@@ -479,8 +479,8 @@ export function applyContainerChanges(hostWs, containerWs, baseline, note, diver
479
479
  fs.writeFileSync(conflictAbs, next);
480
480
  applied.push(conflictRel);
481
481
  written.push({ path: conflictRel.replaceAll("\\", "/"), base: null, after: next });
482
- note?.(`write-back conflict on ${rel.replaceAll("\\", "/")}: it changed on the workspace while this step ran, ` +
483
- `and not only by appending — kept the workspace's version; this step's version is ${conflictRel.replaceAll("\\", "/")}`);
482
+ note?.(`write-back conflict on ${rel.replaceAll("\\", "/")}: it changed on the project while this step ran, ` +
483
+ `and not only by appending — kept the project's version; this step's version is ${conflictRel.replaceAll("\\", "/")}`);
484
484
  continue;
485
485
  }
486
486
  }
@@ -512,7 +512,7 @@ export function applyContainerChanges(hostWs, containerWs, baseline, note, diver
512
512
  recordStepOutputs(opts.revision.tenant, path.basename(hostWs), written, { runId: opts.revision.runId, step: opts.revision.step, base: opts.revision.base });
513
513
  }
514
514
  catch (err) {
515
- note?.(`the step's files were written to the workspace but not recorded as a revision yet: ${err instanceof Error ? err.message : String(err)}`);
515
+ note?.(`the step's files were written to the project but not recorded as a revision yet: ${err instanceof Error ? err.message : String(err)}`);
516
516
  }
517
517
  }
518
518
  return applied;
package/dist/src/scan.js CHANGED
@@ -122,7 +122,7 @@ export const SCAN_RULES = [
122
122
  id: "security/published-flow-ungated",
123
123
  category: "security",
124
124
  level: "warn",
125
- title: "A flow published over A2A acts outside the workspace with no person in the way",
125
+ title: "A flow published over A2A acts outside the project with no person in the way",
126
126
  help: "An outside caller can start a published flow as often as its key allows. A step that posts, sends, writes to an API or calls " +
127
127
  "another outside agent, with no approval (`!`) or `ask:` before it or on it, does what any caller asked. Put a gate before the " +
128
128
  "first such step — an approval is a person reading what it will do.",
@@ -152,7 +152,7 @@ export const SCAN_RULES = [
152
152
  category: "supply-chain",
153
153
  level: "warn",
154
154
  title: "A download piped straight into a shell",
155
- help: "`curl … | sh` runs whatever the server returns today, unreviewed, in the sandbox that holds this workspace. " +
155
+ help: "`curl … | sh` runs whatever the server returns today, unreviewed, in the sandbox that holds this project. " +
156
156
  "Declare the package under `runtime: system:` or `packages:`, or download, verify a checksum, then run.",
157
157
  owasp: ["ASI04", "ASI05"],
158
158
  },
@@ -321,15 +321,15 @@ const OWN_RULES = "checks-own-rules";
321
321
  export const CHECK_RULES = [
322
322
  { id: "agent/config", anchor: OWN_RULES, category: "config", title: "An agent's frontmatter or references are wrong", help: "A field foldrun cannot read, or a tool, skill, colleague or hook it names that does not exist. The message says which and what to write." },
323
323
  { id: "flow/config", anchor: OWN_RULES, category: "config", title: "A flow's steps or options are wrong", help: "A step naming no agent, an option value the parser cannot read, a verify: written as prose, or an arrangement that cannot have what its instruction asks for." },
324
- { id: "flow/outward-ungated", category: "security", title: "A step that acts outside the workspace with no check and no approval", help: "Give the step a verify: that reads what it did, or an approval (`!`), so a wrong post or send is caught before it repeats.", owasp: ["ASI02", "ASI09"] },
324
+ { id: "flow/outward-ungated", category: "security", title: "A step that acts outside the project with no check and no approval", help: "Give the step a verify: that reads what it did, or an approval (`!`), so a wrong post or send is caught before it repeats.", owasp: ["ASI02", "ASI09"] },
325
325
  { id: "tool/config", anchor: OWN_RULES, category: "config", title: "A tool's definition or program is wrong", help: "A run: program that does not exist, a package it imports that nothing declares, or a leftover type: field." },
326
326
  { id: "skill/config", anchor: OWN_RULES, category: "config", title: "A skill does not follow the skill format", help: "SKILL.md needs a name and a description the model can choose it by." },
327
327
  { id: "eval/config", anchor: OWN_RULES, category: "config", title: "An eval names nothing, or has no cases", help: "An eval names one agent or flow that exists and holds at least one case." },
328
328
  { id: "hook/config", anchor: OWN_RULES, category: "config", title: "A hook is not a valid hook, or a hooks: name resolves to nothing", help: "hooks/<name>/hook.md with on:, and run.mjs beside it; a run refuses a step whose hook is missing rather than run it unguarded." },
329
329
  { id: "knowledge/okf", anchor: OWN_RULES, category: "config", title: "A knowledge or memory document is not a conformant OKF bundle entry", help: "Each document needs a type:; dates are YYYY-MM-DD; stale documents are flagged so an agent does not treat them as current." },
330
- { id: "workspace/config", anchor: OWN_RULES, category: "config", title: "A workspace or account setting cannot be read", help: "AGENTS.md defaults — limits:, network:, foldrun_version: — that would leave every agent on the level above, and paths a deploy refuses." },
331
- { id: "library/config", anchor: OWN_RULES, category: "config", title: "A library entry is wrong", help: "The same rules as in a workspace, for the account's shared library." },
332
- { id: "paths/workspace-spelling", anchor: OWN_RULES, category: "config", title: "An older spelling of a workspace path", help: "`../../storage/x` still works; `workspace/storage/x` reads the same in every tool, script and check." },
330
+ { id: "workspace/config", anchor: OWN_RULES, category: "config", title: "A project or account setting cannot be read", help: "AGENTS.md defaults — limits:, network:, foldrun_version: — that would leave every agent on the level above, and paths a deploy refuses." },
331
+ { id: "library/config", anchor: OWN_RULES, category: "config", title: "A library entry is wrong", help: "The same rules as in a project, for the account's shared library." },
332
+ { id: "paths/workspace-spelling", anchor: OWN_RULES, category: "config", title: "An older spelling of a project path", help: "`../../storage/x` still works; `workspace/storage/x` reads the same in every tool, script and check." },
333
333
  ];
334
334
  /** The rule id of a check or deploy problem, from where it was found and
335
335
  * the flow lint's tag when it has one. */
@@ -906,7 +906,7 @@ function scanPublishedFlows(flows, legs, tree, push) {
906
906
  const writes = [...new Set(stepAgents(s).flatMap((n) => legs.get(n)?.writes ?? []))];
907
907
  if (!writes.length)
908
908
  continue;
909
- push("security/published-flow-ungated", fl.file, s.line ?? at, `published ungated ${g} ${s.agent}`, `step ${g} ([[${s.agent}]]) can act outside the workspace (${writes.slice(0, 2).join(", ")}${writes.length > 2 ? ", …" : ""}) and ${info.name} is published over A2A, ` +
909
+ push("security/published-flow-ungated", fl.file, s.line ?? at, `published ungated ${g} ${s.agent}`, `step ${g} ([[${s.agent}]]) can act outside the project (${writes.slice(0, 2).join(", ")}${writes.length > 2 ? ", …" : ""}) and ${info.name} is published over A2A, ` +
910
910
  `with no approval or ask: before it — any caller with a key starts it. Put a gate (\`${g}!.\`) on it or before it`);
911
911
  }
912
912
  }
@@ -129,7 +129,7 @@ function vaultAad(tenant, workspace, name, rec) {
129
129
  throw new Error("malformed sites");
130
130
  }
131
131
  if (rec.workspaces !== undefined && (!Array.isArray(rec.workspaces) || rec.workspaces.some((x) => typeof x !== "string"))) {
132
- throw new Error("malformed workspaces");
132
+ throw new Error("malformed projects");
133
133
  }
134
134
  return Buffer.from(JSON.stringify([
135
135
  "foldrun-vault/2",
@@ -335,7 +335,7 @@ function cleanWorkspaceList(workspaces) {
335
335
  if (workspaces === null)
336
336
  return null;
337
337
  if (!Array.isArray(workspaces) || workspaces.some((w) => typeof w !== "string")) {
338
- throw new Error("workspaces is a list of workspace names, or null for every workspace");
338
+ throw new Error("projects is a list of project names, or null for every project");
339
339
  }
340
340
  const clean = [...new Set(workspaces.map((w) => w.trim()).filter(Boolean))].sort();
341
341
  for (const w of clean)
@@ -347,7 +347,7 @@ function assertWorkspacesExist(list, exists) {
347
347
  return;
348
348
  const missing = list.filter((w) => !exists(w));
349
349
  if (missing.length)
350
- throw Object.assign(new Error(`no workspace ${missing.join(", ")} in this account`), { status: 400 });
350
+ throw Object.assign(new Error(`no project ${missing.join(", ")} in this account`), { status: 400 });
351
351
  }
352
352
  export function setSecret(tenant, name, value, workspace, kind, limit = {}) {
353
353
  // A string, not anything that prints as one: RegExp.test and the vault's
@@ -384,7 +384,7 @@ function limitFor(workspace, limit) {
384
384
  if (limit.workspaces === undefined)
385
385
  return undefined;
386
386
  if (workspace)
387
- throw new Error("a workspace's own secret is that workspace's already — only an account secret is limited to workspaces");
387
+ throw new Error("a project's own secret is that project's already — only an account secret is limited to projects");
388
388
  return cleanWorkspaceList(limit.workspaces);
389
389
  }
390
390
  /**
@@ -436,7 +436,7 @@ export function setSecretSites(tenant, name, sites, workspace) {
436
436
  return all;
437
437
  });
438
438
  if (!found)
439
- throw new Error(`no secret ${name}${workspace ? ` in workspace ${workspace}` : " in the account"}`);
439
+ throw new Error(`no secret ${name}${workspace ? ` in project ${workspace}` : " in the account"}`);
440
440
  return clean;
441
441
  }
442
442
  /**
@@ -588,7 +588,7 @@ export function setSecretWorkspaces(tenant, name, workspaces, opts = {}) {
588
588
  if (expected !== undefined) {
589
589
  const now = Array.isArray(rec.workspaces) ? [...rec.workspaces].sort() : null;
590
590
  if (JSON.stringify(now) !== JSON.stringify(expected)) {
591
- throw Object.assign(new Error(`${name}'s workspaces changed since you loaded them (now ${now === null ? "every workspace" : now.length ? now.join(", ") : "none"}) — reload and try again`), { status: 409 });
591
+ throw Object.assign(new Error(`${name}'s projects changed since you loaded them (now ${now === null ? "every project" : now.length ? now.join(", ") : "none"}) — reload and try again`), { status: 409 });
592
592
  }
593
593
  }
594
594
  assertWorkspacesExist(clean, opts.exists);
@@ -605,7 +605,7 @@ export function setSecretWorkspaces(tenant, name, workspaces, opts = {}) {
605
605
  function withWorkspaces(tenant, name, rec, workspaces) {
606
606
  const value = openRecord(tenant, undefined, name, rec);
607
607
  if (value === null)
608
- throw new Error(`${name} cannot be read with this install's keys — set its value again before changing its workspaces`);
608
+ throw new Error(`${name} cannot be read with this install's keys — set its value again before changing its projects`);
609
609
  return sealRecord(tenant, undefined, name, value, { kind: rec.kind, sites: rec.sites, workspaces: workspaces ?? undefined, updatedAt: rec.updatedAt }, true);
610
610
  }
611
611
  /**
@@ -36,7 +36,7 @@ export function accountFiles(account) {
36
36
  path: "AGENTS.md",
37
37
  content: `---
38
38
  foldrun_version: "0.1"
39
- # Config here applies to every workspace under this account, and a workspace
39
+ # Config here applies to every project under this account, and a project
40
40
  # that declares the same key replaces it *whole* — base_url and token never
41
41
  # merge across scopes, so a provider block belongs entirely at one level.
42
42
  #
@@ -77,9 +77,9 @@ foldrun_version: "0.1"
77
77
 
78
78
  # ${account}
79
79
 
80
- Context every agent in every workspace here shares.
80
+ Context every agent in every project here shares.
81
81
 
82
- Unlike the frontmatter above, this prose **accumulates**: a workspace's
82
+ Unlike the frontmatter above, this prose **accumulates**: a project's
83
83
  AGENTS.md is added to it, not swapped for it, so a rule written here cannot be
84
84
  dropped further down.
85
85
  `,
@@ -126,7 +126,7 @@ export function starterFiles(workspace) {
126
126
  path: "AGENTS.md",
127
127
  content: `---
128
128
  name: ${workspace}
129
- description: A starter workspace — edit the agents, then run the flow.
129
+ description: A starter project — edit the agents, then run the flow.
130
130
  foldrun_version: "0.1"
131
131
  ---
132
132
 
@@ -143,7 +143,7 @@ Context every agent here shares. Prices, rules, anything they should all know.
143
143
  // every secret *inside the workspace*, and without this file the first
144
144
  // `git add -A` after setting a secret commits it.
145
145
  path: ".gitignore",
146
- content: `# The key that decrypts every secret in this workspace, plus the
146
+ content: `# The key that decrypts every secret in this project, plus the
147
147
  # local run store. Never commit these.
148
148
  .foldrun/
149
149
 
@@ -282,7 +282,7 @@ only when they asked for exactly that deletion.
282
282
 
283
283
  | Path | What |
284
284
  |---|---|
285
- | \`AGENTS.md\` | shared context every agent in this workspace sees |
285
+ | \`AGENTS.md\` | shared context every agent in this project sees |
286
286
  | \`agents/<name>/agent.md\` | one role: its persona, model, tools |
287
287
  | \`flows/<name>.md\` | steps, in order, naming the agents that run them |
288
288
  | \`knowledge/\` | reference material agents read |
@@ -301,10 +301,10 @@ Regenerated every run means a file; accumulated across runs means \`state/\`.
301
301
  That last row is worth knowing: a subagent you write in Claude Code is imported
302
302
  as \`agents/<name>/agent.md\` at deploy, no conversion. Write it either way.
303
303
 
304
- ## Paths inside a workspace
304
+ ## Paths inside a project
305
305
 
306
306
  An agent's working directory is \`agents/<name>/\`. Write every path to the
307
- workspace's own folders as \`workspace/…\` — \`workspace/storage/report.csv\`,
307
+ project's own folders as \`workspace/…\` — \`workspace/storage/report.csv\`,
308
308
  \`workspace/state/cursor.json\` — in an agent's prose, in flow options
309
309
  (\`each: rows of\`, \`when: rows of\`, \`verify:\`, \`preview:\`, \`schema:\`) and in
310
310
  script arguments. It resolves the same in the file tools, the shell, scripts
@@ -330,9 +330,9 @@ A step held to its list still searches the web through the proxy's search door;
330
330
  at \`none\` or \`defaults: false\` write it out — \`web: {actions: [search, fetch]}\` —
331
331
  because a query's words leave (\`foldrun docs network\`).
332
332
 
333
- ## Talking to a deployed workspace
333
+ ## Talking to a deployed project
334
334
 
335
- The CLI is local except for \`deploy\`. To inspect or drive a workspace running
335
+ The CLI is local except for \`deploy\`. To inspect or drive a project running
336
336
  on a server, use the HTTP API — every route takes the same API key
337
337
  (\`Authorization: Bearer $FOLDRUN_TOKEN\`, from Settings → API keys) or a browser
338
338
  session, and refuses without one.
@@ -351,7 +351,7 @@ All of it, \`/api/workspaces/<workspace>\` unless noted:
351
351
 
352
352
  | Route | Methods | For |
353
353
  |---|---|---|
354
- | \`/\` | GET DELETE PATCH | the workspace itself |
354
+ | \`/\` | GET DELETE PATCH | the project itself |
355
355
  | \`/deploy\` | POST | what \`foldrun deploy\` calls |
356
356
  | \`/source\` | GET PUT PATCH DELETE | read and write single files |
357
357
  | \`/runs\` | GET | list runs |
@@ -365,19 +365,19 @@ All of it, \`/api/workspaces/<workspace>\` unless noted:
365
365
  | \`/flows\` · \`/flows/<f>\` | GET POST · POST DELETE PATCH | list, create, edit |
366
366
  | \`/flows/<f>/run\` | POST | start a flow |
367
367
  | \`/flows/<f>/filter\` | POST | would this delivery start it? its \`filter:\` against a payload — nothing starts |
368
- | \`/agents\` · \`/agents/<a>/run\` · \`/agents/import\` | GET POST · POST · GET POST | list agents, run one, copy one in from another workspace |
368
+ | \`/agents\` · \`/agents/<a>/run\` · \`/agents/import\` | GET POST · POST · GET POST | list agents, run one, copy one in from another project |
369
369
  | \`/evals\` · \`/evals/<e>/run\` | GET POST · POST | list evals, run one |
370
370
  | \`/evals/<e>/compare\` | GET POST | its cases under two to four models, side by side — test runs, a spend limit |
371
371
  | \`/evals/<e>/grades\` · \`/evals/<e>/grade\` | GET · POST | a grader's grades (\`trigger: runs\`); grade one finished run now |
372
372
  | \`/evals/<e>/improve\` · \`/proposals\` · \`/proposals/<id>\` | POST · GET · GET POST | ask for a proposed fix; list them; apply or dismiss one |
373
373
  | \`/tools/<t>/test\` | POST | exercise one tool alone |
374
- | \`/storage\` · \`/storage/download\` · \`/storage/upload-url\` · \`/storage/preview\` | GET POST PUT DELETE · GET · POST · GET | workspace files, any type; \`preview\` returns one parsed for reading |
374
+ | \`/storage\` · \`/storage/download\` · \`/storage/upload-url\` · \`/storage/preview\` | GET POST PUT DELETE · GET · POST · GET | project files, any type; \`preview\` returns one parsed for reading |
375
375
  | \`/assets\` | POST | upload an asset |
376
376
  | \`/hooks/<f>/rotate\` | POST | new webhook token for a flow |
377
377
  | \`/notify/deliveries\` · \`/notify/deliveries/<id>/redeliver\` | GET · POST | every notify: webhook sent and each attempt; send one again |
378
- | \`/export\` · \`/import\` | GET · POST | the workspace, a flow (\`?kind=flow&name=\`) or an agent as a .zip; take one in (\`?dryRun=1\` first, \`?overwrite=1\` to replace) |
379
- | \`/restore\` | POST | the workspace's source back to a point in its history — \`dryRun\` first, then \`confirm\` |
380
- | \`/vocabulary\` | GET | what this workspace's documents may say |
378
+ | \`/export\` · \`/import\` | GET · POST | the project, a flow (\`?kind=flow&name=\`) or an agent as a .zip; take one in (\`?dryRun=1\` first, \`?overwrite=1\` to replace) |
379
+ | \`/restore\` | POST | the project's source back to a point in its history — \`dryRun\` first, then \`confirm\` |
380
+ | \`/vocabulary\` | GET | what this project's documents may say |
381
381
  | \`/a2a\` | GET | what it serves to outside agents over A2A: flows that say \`a2a:\`, card URLs, recent tasks |
382
382
  | \`/check\` | GET | what \`foldrun check\` says about the deployed copy, as findings with rule ids (\`?security=1\`) |
383
383
  | \`/assistant\` | POST | ask the assistant, or have it write agents, flows, tools and skills — from the docs only; proposals come back, nothing is written |
@@ -522,7 +522,7 @@ Only \`name\` and the prose are required. Every other field widens or narrows
522
522
  what the agent can reach, and the default is narrow.
523
523
 
524
524
  \`timezone:\` is nearest-wins all the way down: the agent's own, else its
525
- flow's, else the workspace's AGENTS.md, else the account's, else UTC. It sets
525
+ flow's, else the project's AGENTS.md, else the account's, else UTC. It sets
526
526
  \`TZ\` and the date the agent is told, so a Sydney desk stamps the Sydney date.
527
527
 
528
528
  \`runtime:\` installs pip/npm packages in the sandbox each agent runs in. Pin
@@ -571,7 +571,7 @@ export function blankWorkspaceFiles(workspace) {
571
571
  .map((f) => f.path === "AGENTS.md"
572
572
  ? {
573
573
  ...f,
574
- content: f.content.replace("description: A starter workspace — edit the agents, then run the flow.", "description: A new workspace — add an agent or import one from another workspace, then write a flow."),
574
+ content: f.content.replace("description: A starter project — edit the agents, then run the flow.", "description: A new project — add an agent or import one from another project, then write a flow."),
575
575
  }
576
576
  : f);
577
577
  }
@@ -1,4 +1,5 @@
1
1
  import { type HookDef, type HookRecord } from "./hooks.ts";
2
+ import { type Engine } from "./engine-loop.ts";
2
3
  import type { McpServerConfig } from "@anthropic-ai/claude-agent-sdk";
3
4
  import { type Effort, type ModelCall } from "./store.ts";
4
5
  import { type TokenPrice } from "./catalog.ts";
@@ -73,6 +74,14 @@ export interface ExecOptions {
73
74
  * host's paths. A name that resolves to nothing refuses the step. */
74
75
  hookNames?: string[];
75
76
  hookBase?: Record<string, unknown>;
77
+ /** Which loop runs the turns: the SDK (the default) or foldrun's own
78
+ * (engine-loop.ts). The caller's choice, from configuration it trusts —
79
+ * never read from `env`, which carries the tenant's secrets by name. */
80
+ engine?: Engine;
81
+ /** With foldrun's engine on a host: run the shell with no OS sandbox.
82
+ * Only for a person's own machine, on their word; a run container is
83
+ * its own boundary and needs nothing said (`sandboxBash: false`). */
84
+ engineHostShell?: boolean;
76
85
  agentDir: string;
77
86
  workspaceRoot: string;
78
87
  libraryRoot: string;
@@ -266,7 +275,9 @@ export declare function stepCeilingFor(flowShareUsd: number | null, agentBudgetU
266
275
  };
267
276
  export declare function executeStep(opts: ExecOptions,
268
277
  /** The model loop. Injected so the clock and the stop can be tested
269
- * without a model; production passes nothing and gets the SDK. */
278
+ * without a model; production passes nothing and gets the SDK — or
279
+ * foldrun's own loop when the caller asked for it (`opts.engine`,
280
+ * engine-loop.ts). */
270
281
  runQuery?: QueryFn): Promise<ExecOutcome>;
271
282
  /**
272
283
  * The one JSON value a reply carries. A ```json fence wins — it is what the
@@ -14,6 +14,7 @@ import fs from "node:fs";
14
14
  import os from "node:os";
15
15
  import path from "node:path";
16
16
  import { query } from "@anthropic-ai/claude-agent-sdk";
17
+ import { foldrunQuery } from "./engine-loop.js";
17
18
  import { CAPTURE_CAP } from "./store.js";
18
19
  import { costOf } from "./catalog.js";
19
20
  import { spawn } from "node:child_process";
@@ -141,8 +142,10 @@ export function stepCeilingFor(flowShareUsd, agentBudgetUsd, agentSpentUsd, agen
141
142
  }
142
143
  export async function executeStep(opts,
143
144
  /** The model loop. Injected so the clock and the stop can be tested
144
- * without a model; production passes nothing and gets the SDK. */
145
- runQuery = query) {
145
+ * without a model; production passes nothing and gets the SDK — or
146
+ * foldrun's own loop when the caller asked for it (`opts.engine`,
147
+ * engine-loop.ts). */
148
+ runQuery = opts.engine === "foldrun" ? foldrunQuery : query) {
146
149
  // `workspace/…` for the shell, the scripts and a shell `verify:` — the
147
150
  // file tools expand the prefix themselves. Held for the step, verify
148
151
  // included, and gone before anyone reads the step's files back
@@ -270,6 +273,7 @@ async function executeStepInner(opts, runQuery) {
270
273
  // false) and the container's walls do the containing; the in-process
271
274
  // path (the CLI on someone's laptop, and the host executor) keeps it,
272
275
  // because there a shell escape reaches the real machine.
276
+ ...(opts.engineHostShell ? { engineHostShell: true } : {}),
273
277
  sandbox: {
274
278
  enabled: opts.sandboxBash !== false,
275
279
  // Must stay false. Auto-allowing bash because it's sandboxed skips