@foldrun/core 0.3.0 → 0.5.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 (175) hide show
  1. package/README.md +27 -10
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +3 -0
  4. package/dist/src/account.d.ts +45 -0
  5. package/dist/src/account.js +130 -0
  6. package/dist/src/api-tools.d.ts +8 -0
  7. package/dist/src/api-tools.js +22 -4
  8. package/dist/src/approvals.d.ts +104 -1
  9. package/dist/src/approvals.js +192 -2
  10. package/dist/src/browser-pod.d.ts +129 -0
  11. package/dist/src/browser-pod.js +284 -0
  12. package/dist/src/budget.d.ts +32 -0
  13. package/dist/src/budget.js +177 -0
  14. package/dist/src/catalog.js +3 -1
  15. package/dist/src/clock.d.ts +49 -0
  16. package/dist/src/clock.js +121 -0
  17. package/dist/src/completions.js +17 -8
  18. package/dist/src/confine.d.ts +22 -0
  19. package/dist/src/confine.js +224 -4
  20. package/dist/src/deploy.d.ts +33 -0
  21. package/dist/src/deploy.js +145 -6
  22. package/dist/src/egress.d.ts +26 -2
  23. package/dist/src/egress.js +8 -1
  24. package/dist/src/eol.d.ts +2 -0
  25. package/dist/src/eol.js +7 -0
  26. package/dist/src/evals.d.ts +9 -0
  27. package/dist/src/evals.js +26 -13
  28. package/dist/src/flow-lint.d.ts +12 -0
  29. package/dist/src/flow-lint.js +331 -1
  30. package/dist/src/flow-patterns.d.ts +141 -0
  31. package/dist/src/flow-patterns.js +568 -0
  32. package/dist/src/gitrepo.d.ts +18 -0
  33. package/dist/src/gitrepo.js +49 -0
  34. package/dist/src/host-env.d.ts +8 -0
  35. package/dist/src/host-env.js +48 -0
  36. package/dist/src/json-schema.d.ts +12 -0
  37. package/dist/src/json-schema.js +202 -0
  38. package/dist/src/kinds.js +1 -1
  39. package/dist/src/language.d.ts +17 -0
  40. package/dist/src/language.js +55 -0
  41. package/dist/src/layout.d.ts +69 -0
  42. package/dist/src/layout.js +200 -0
  43. package/dist/src/library.d.ts +9 -0
  44. package/dist/src/library.js +43 -4
  45. package/dist/src/limits.d.ts +84 -0
  46. package/dist/src/limits.js +287 -0
  47. package/dist/src/locale.d.ts +47 -0
  48. package/dist/src/locale.js +177 -0
  49. package/dist/src/mail.d.ts +88 -0
  50. package/dist/src/mail.js +245 -0
  51. package/dist/src/model-probe.d.ts +3 -0
  52. package/dist/src/model-probe.js +1 -0
  53. package/dist/src/notify.d.ts +132 -8
  54. package/dist/src/notify.js +360 -58
  55. package/dist/src/openapi.js +5 -3
  56. package/dist/src/operator.d.ts +201 -0
  57. package/dist/src/operator.js +251 -0
  58. package/dist/src/paths.d.ts +33 -0
  59. package/dist/src/paths.js +87 -0
  60. package/dist/src/platform.d.ts +144 -4
  61. package/dist/src/platform.js +27 -3
  62. package/dist/src/provider-health.d.ts +55 -0
  63. package/dist/src/provider-health.js +233 -0
  64. package/dist/src/providers.d.ts +481 -0
  65. package/dist/src/providers.js +1105 -6
  66. package/dist/src/refusal.d.ts +83 -0
  67. package/dist/src/refusal.js +281 -0
  68. package/dist/src/run-container.d.ts +206 -17
  69. package/dist/src/run-container.js +547 -80
  70. package/dist/src/runner.d.ts +179 -10
  71. package/dist/src/runner.js +1423 -169
  72. package/dist/src/runtime.d.ts +52 -0
  73. package/dist/src/runtime.js +493 -58
  74. package/dist/src/script-tools.d.ts +15 -2
  75. package/dist/src/script-tools.js +44 -4
  76. package/dist/src/secret-files.d.ts +6 -5
  77. package/dist/src/secret-files.js +24 -11
  78. package/dist/src/secret-health.d.ts +83 -0
  79. package/dist/src/secret-health.js +177 -0
  80. package/dist/src/secrets.d.ts +38 -1
  81. package/dist/src/secrets.js +197 -96
  82. package/dist/src/starter.d.ts +9 -0
  83. package/dist/src/starter.js +95 -11
  84. package/dist/src/step-exec.d.ts +106 -1
  85. package/dist/src/step-exec.js +558 -85
  86. package/dist/src/step-removal.d.ts +15 -0
  87. package/dist/src/step-removal.js +49 -0
  88. package/dist/src/storage.d.ts +23 -4
  89. package/dist/src/storage.js +125 -23
  90. package/dist/src/store.d.ts +492 -38
  91. package/dist/src/store.js +882 -69
  92. package/dist/src/subagents.d.ts +75 -0
  93. package/dist/src/subagents.js +149 -0
  94. package/dist/src/tar.js +2 -1
  95. package/dist/src/test-mode.d.ts +111 -0
  96. package/dist/src/test-mode.js +285 -0
  97. package/dist/src/tool-names.d.ts +13 -1
  98. package/dist/src/tool-names.js +38 -11
  99. package/dist/src/tool-programs.d.ts +26 -0
  100. package/dist/src/tool-programs.js +172 -0
  101. package/dist/src/tool-test.js +152 -33
  102. package/dist/src/translator.d.ts +8 -2
  103. package/dist/src/translator.js +71 -24
  104. package/dist/src/trigger-log.d.ts +43 -0
  105. package/dist/src/trigger-log.js +122 -0
  106. package/dist/src/triggers.d.ts +23 -0
  107. package/dist/src/triggers.js +101 -12
  108. package/dist/src/untrusted-fetch.d.ts +11 -0
  109. package/dist/src/untrusted-fetch.js +77 -0
  110. package/dist/src/web-actions.d.ts +91 -0
  111. package/dist/src/web-actions.js +199 -0
  112. package/dist/src/webhook.d.ts +19 -3
  113. package/dist/src/webhook.js +50 -11
  114. package/index.ts +3 -0
  115. package/package.json +5 -5
  116. package/src/account.ts +149 -0
  117. package/src/api-tools.ts +32 -4
  118. package/src/approvals.ts +253 -2
  119. package/src/browser-pod.ts +313 -0
  120. package/src/budget.ts +178 -0
  121. package/src/catalog.ts +3 -1
  122. package/src/clock.ts +149 -0
  123. package/src/completions.ts +17 -8
  124. package/src/confine.ts +224 -4
  125. package/src/deploy.ts +137 -6
  126. package/src/egress.ts +32 -4
  127. package/src/eol.ts +7 -0
  128. package/src/evals.ts +36 -11
  129. package/src/flow-lint.ts +371 -1
  130. package/src/flow-patterns.ts +597 -0
  131. package/src/gitrepo.ts +48 -0
  132. package/src/host-env.ts +51 -0
  133. package/src/json-schema.ts +184 -0
  134. package/src/kinds.ts +1 -1
  135. package/src/language.ts +62 -0
  136. package/src/layout.ts +228 -0
  137. package/src/library.ts +50 -4
  138. package/src/limits.ts +290 -0
  139. package/src/locale.ts +217 -0
  140. package/src/mail.ts +316 -0
  141. package/src/model-probe.ts +4 -0
  142. package/src/notify.ts +391 -44
  143. package/src/openapi.ts +5 -3
  144. package/src/operator.ts +300 -0
  145. package/src/paths.ts +83 -0
  146. package/src/platform.ts +158 -5
  147. package/src/provider-health.ts +275 -0
  148. package/src/providers.ts +1368 -6
  149. package/src/refusal.ts +320 -0
  150. package/src/run-container.ts +611 -76
  151. package/src/runner.ts +1463 -165
  152. package/src/runtime.ts +487 -55
  153. package/src/script-tools.ts +55 -6
  154. package/src/secret-files.ts +22 -10
  155. package/src/secret-health.ts +230 -0
  156. package/src/secrets.ts +191 -95
  157. package/src/starter.ts +96 -11
  158. package/src/step-exec.ts +548 -41
  159. package/src/step-removal.ts +59 -0
  160. package/src/storage.ts +149 -24
  161. package/src/store.ts +1227 -74
  162. package/src/subagents.ts +189 -0
  163. package/src/tar.ts +2 -1
  164. package/src/test-mode.ts +311 -0
  165. package/src/tool-names.ts +40 -11
  166. package/src/tool-programs.ts +179 -0
  167. package/src/tool-test.ts +159 -32
  168. package/src/translator.ts +74 -23
  169. package/src/trigger-log.ts +160 -0
  170. package/src/triggers.ts +102 -12
  171. package/src/untrusted-fetch.ts +88 -0
  172. package/src/web-actions.ts +237 -0
  173. package/src/webhook.ts +58 -11
  174. package/templates/hello/agents/curator/agent.md +1 -1
  175. package/templates/hello/agents/notetaker/agent.md +1 -1
package/dist/src/evals.js CHANGED
@@ -39,7 +39,7 @@ import { spawn } from "node:child_process";
39
39
  import { query } from "@anthropic-ai/claude-agent-sdk";
40
40
  import { workspaceDir, readRun, writeWorkspaceFile, resolveModel, resolveEffort, assertSafeName, } from "./store.js";
41
41
  import { startFlowRun, loadFlow } from "./runner.js";
42
- import { platform } from "./platform.js";
42
+ import { platform, platformQueues } from "./platform.js";
43
43
  const ASSERTION_TYPES = ["contains", "not-contains", "matches", "file", "run", "judge"];
44
44
  /**
45
45
  * A scalar that may continue onto following lines.
@@ -138,6 +138,8 @@ export function parseEval(file, raw) {
138
138
  model: resolveModel(data.model ?? "fast"),
139
139
  effort: resolveEffort(data.effort ?? "low"),
140
140
  trigger: data.trigger === "manual" ? "manual" : "deploy",
141
+ live: data.live === true,
142
+ inputs: data.inputs === true,
141
143
  cases,
142
144
  };
143
145
  }
@@ -226,7 +228,9 @@ export function promoteRunToEval(tenant, workspace, runId, opts = {}) {
226
228
  let expect;
227
229
  if (opts.expect && opts.expect.length > 0) {
228
230
  expect = opts.expect.map((line) => {
229
- const m = oneLine(line).match(/^([a-z-]+):\s*(.*)$/);
231
+ const m = oneLine(line).match(/^([a-z-]+):(.*)$/);
232
+ if (m)
233
+ m[2] = m[2].trim();
230
234
  if (!m || !ASSERTION_TYPES.includes(m[1]) || !m[2]) {
231
235
  throw refuse(`"${line}" is not an assertion — expected one of ${ASSERTION_TYPES.map((t) => `${t}:`).join(", ")} followed by a value`, 400);
232
236
  }
@@ -258,7 +262,7 @@ export function promoteRunToEval(tenant, workspace, runId, opts = {}) {
258
262
  if (points.kind !== target.kind || points.name !== target.name) {
259
263
  throw refuse(`${rel} tests ${points.kind} ${points.name ?? "(nothing)"}, not ${target.kind} ${target.name} — pick another evalName`, 409);
260
264
  }
261
- content = `${existing.replace(/\s+$/, "")}\n\n${caseText}`;
265
+ content = `${existing.trimEnd()}\n\n${caseText}`;
262
266
  }
263
267
  else {
264
268
  // A flow eval costs a whole run and touches real systems, so it waits
@@ -285,19 +289,23 @@ export function promoteRunToEval(tenant, workspace, runId, opts = {}) {
285
289
  });
286
290
  return { file: rel, created: !existing, caseName };
287
291
  }
288
- /** Wait for a run to finish, with a ceiling so a hung agent can't hang an eval. */
289
292
  /**
290
293
  * A web replica never drives a run: it has no route to the cluster API and
291
294
  * no right to create a pod, by design — so an eval started there (a push,
292
295
  * the Run button) queues its run for the worker like any other. From 29 Aug
293
296
  * every eval on the split platform died at "pod create failed: connection
294
297
  * refused" for exactly this reason. A single process — the CLI, a laptop,
295
- * FOLDRUN_ROLE unset — still drives it right here, as it always did.
298
+ * no platform registered — still drives it right here, as it always did.
299
+ *
300
+ * The test is whether a platform owns the queue, not which role this
301
+ * process was started as: on a worker the role read "worker", the eval
302
+ * started its run in-process, and the run never passed through the
303
+ * account cap or the lanes the platform enforces on every other run.
296
304
  */
297
- const runsViaQueue = () => process.env.FOLDRUN_ROLE === "web";
298
- async function beginEvalRun(tenant, workspace, steps, flowName, model, effort) {
305
+ const runsViaQueue = () => platformQueues();
306
+ async function beginEvalRun(tenant, workspace, steps, flowName, model, effort, test = true) {
299
307
  if (!runsViaQueue())
300
- return startFlowRun(tenant, workspace, steps, flowName, model, [], effort);
308
+ return startFlowRun(tenant, workspace, steps, flowName, model, [], effort, null, { test });
301
309
  // The job carries a model override but no effort one, and driveRun cannot
302
310
  // re-read a flow called `eval:<name>`. Put the flow's defaults onto the
303
311
  // steps that have none — which is what nearest-wins resolves to anyway.
@@ -306,7 +314,7 @@ async function beginEvalRun(tenant, workspace, steps, flowName, model, effort) {
306
314
  ...(s.model || !model ? {} : { model }),
307
315
  ...(s.effort || !effort ? {} : { effort }),
308
316
  }));
309
- return platform.enqueueFlowRun(tenant, workspace, withDefaults, flowName, model ?? null, []);
317
+ return platform.enqueueFlowRun(tenant, workspace, withDefaults, flowName, model ?? null, [], null, { test });
310
318
  }
311
319
  // Waits for as long as the run runs. There was a cap here (5 minutes, then
312
320
  // 30) and it marked a flow eval "run disappeared" at the cap while the flow
@@ -412,7 +420,10 @@ async function checkAssertion(assertion, output, agentDir, model, effort) {
412
420
  export async function runEval(tenant, workspace, info) {
413
421
  const startedAt = new Date().toISOString();
414
422
  const results = [];
415
- for (const testCase of info.cases) {
423
+ // Saved inputs carry no assertions: running them would start and bill a
424
+ // run per case only to report every one failed. Nothing to grade.
425
+ const cases = info.inputs ? [] : info.cases;
426
+ for (const testCase of cases) {
416
427
  const target = info.flow ? null : info.agent;
417
428
  let runId = null;
418
429
  let output = "";
@@ -428,12 +439,14 @@ export async function runEval(tenant, workspace, info) {
428
439
  const steps = flow.steps.map((s, i) => i === 0
429
440
  ? { ...s, instruction: `${s.instruction}\n\n<run_task>\n${testCase.task}\n</run_task>` }
430
441
  : s);
431
- run = await beginEvalRun(tenant, workspace, steps, `eval:${info.name}`, flow.model, flow.effort);
442
+ // Test unless the eval OR the flow says live: an eval that runs a
443
+ // flow written `live: true` was written by someone who knew.
444
+ run = await beginEvalRun(tenant, workspace, steps, `eval:${info.name}`, flow.model, flow.effort, !(info.live || flow.live));
432
445
  }
433
446
  else {
434
447
  if (!target)
435
448
  throw new Error("this eval names neither an agent nor a flow");
436
- run = await beginEvalRun(tenant, workspace, [{ agent: target, instruction: testCase.task, group: 1, optional: false }], `eval:${info.name}`);
449
+ run = await beginEvalRun(tenant, workspace, [{ agent: target, instruction: testCase.task, group: 1, optional: false }], `eval:${info.name}`, undefined, undefined, !info.live);
437
450
  }
438
451
  runId = run.id;
439
452
  const finished = await waitForRun(tenant, workspace, run.id);
@@ -592,7 +605,7 @@ commit = null) {
592
605
  return { ran: 0, skipped: "no revision to stamp the result with" };
593
606
  // Only the evals that asked to run on deploy — a `trigger: manual` eval is
594
607
  // one a person runs on purpose, because it costs a whole flow run.
595
- const evals = listEvals(tenant, workspace).filter((e) => e.trigger !== "manual");
608
+ const evals = listEvals(tenant, workspace).filter((e) => e.trigger !== "manual" && !e.inputs);
596
609
  if (evals.length === 0)
597
610
  return { ran: 0, skipped: "no evals" };
598
611
  const dir = path.join(workspaceDir(tenant, workspace), "evals", ".results");
@@ -6,11 +6,23 @@ export interface FlowWarning {
6
6
  line?: number;
7
7
  message: string;
8
8
  detail: string;
9
+ /** "error" for a value the parser could not read — `timeout: abc` — which
10
+ * `foldrun check` must fail on rather than note. Absent means advisory,
11
+ * which every structural warning in this file is. */
12
+ level?: "error" | "warn";
13
+ /** A stable tag for warnings a caller wants to single out — the deploy
14
+ * surfaces `kind: "outward"` as a non-blocking warning. */
15
+ kind?: string;
9
16
  }
10
17
  /** What exists in the workspace, when the caller knows. Optional: the lint
11
18
  * is useful without it, and a caller that has the lists gets the reference
12
19
  * checks too. */
13
20
  export interface KnownNames {
14
21
  agents: string[];
22
+ /** Agents that hold a tool declaring `outward: true` — one that sends,
23
+ * posts, buys or publishes. The caller resolves the grants; this file only
24
+ * needs the answer. Absent means the caller did not look, and the outward
25
+ * rule is skipped rather than guessed at. */
26
+ outwardAgents?: string[];
15
27
  }
16
28
  export declare function lintFlow(flow: FlowInfo, known?: KnownNames): FlowWarning[];
@@ -10,13 +10,68 @@
10
10
  // Every check here is *structural*: it reasons about what a step can possibly
11
11
  // have in context, never about whether the model did a good job. Nothing is
12
12
  // blocked — flows still run, warnings are advisory.
13
+ import { whenRowsPath } from "./store.js";
14
+ import { timezoneProblem } from "./clock.js";
15
+ /** What a `[[flow:x]]` step's options are called in a flow file, for the
16
+ * ones expandSubflows does not carry into the nested steps. */
17
+ const SUBFLOW_DROPPED = [
18
+ ["approve", "an approval (!)"], ["when", "when:"], ["case", "case:"], ["else", "else:"],
19
+ ["retry", "retry:"], ["timeout", "timeout:"], ["verify", "verify:"], ["model", "model:"],
20
+ ["effort", "effort:"], ["onFail", "on-fail:"], ["waitSecs", "wait:"], ["waitFor", "wait:"],
21
+ ["ask", "ask:"], ["preview", "preview:"], ["delegate", "delegate:"], ["loop", "loop:"],
22
+ ["until", "until:"], ["each", "each:"], ["max", "max:"], ["output", "output:"],
23
+ ["schema", "schema:"], ["parallel", "parallel:"], ["maxTurns", "max_turns:"], ["limits", "limits:"],
24
+ ];
13
25
  // Anaphora: phrases that only mean something if earlier output exists.
14
26
  // Deliberately conservative — a false warning is worse than a missed one,
15
27
  // because noisy warnings get ignored and then the real one is invisible too.
16
28
  const REFERS_BACK = /\b(both|above|earlier|previous(ly)?|prior|the (changes|draft|research|results|findings|report|article|fixes|work)|what (they|the others?) (found|shipped|wrote|said))\b/i;
29
+ /** One @, something either side, a dot in the domain, no whitespace. Written
30
+ * as string checks rather than a regex: the obvious pattern backtracks
31
+ * polynomially on a domain full of dots, and a lint that can be made slow
32
+ * by a flow file is a lint someone will turn off. */
33
+ function looksLikeAddress(a) {
34
+ const at = a.indexOf("@");
35
+ if (at < 1 || at !== a.lastIndexOf("@") || /\s/.test(a))
36
+ return false;
37
+ const domain = a.slice(at + 1);
38
+ const dot = domain.indexOf(".");
39
+ return dot > 0 && dot < domain.length - 1;
40
+ }
41
+ /** The assertion words a `verify:` may open with. Anything else is handed to
42
+ * a shell — see `checkVerify` in step-exec.ts, which owns this list. */
43
+ const VERIFY_ASSERTION = /^(contains|not-contains|matches|file|judge):\s/;
44
+ /** What a shell command has that a sentence does not: an operator that only
45
+ * means something to a shell, a path or bracket at the very start, or one
46
+ * of the commands these flows actually reach for. Deliberately NOT any
47
+ * punctuation a sentence might carry — the first version disqualified on
48
+ * `;`, `,`, `'` and `"`, so "the reply opens with GOOD; a GOOD reply names
49
+ * the SHA" read as shell and a guaranteed exit 127 sat in fix-desk unseen
50
+ * by the very lint written to catch it. */
51
+ const LOOKS_LIKE_SHELL = /&&|\|\||\s\|\s|\$\(|\$\{|`|\s[<>]\s|\d?>[>&]?\s|^\[|^[.~/]|^\s*\b(test|grep|egrep|find|head|tail|cat|ls|node|npm|npx|bash|sh|zsh|python3?|jq|awk|sed|curl|git|make|exit|n=|[A-Za-z_]+=)/;
52
+ /** A `verify:` that is a claim in English rather than a command. Conservative
53
+ * on purpose, the same bargain as REFERS_BACK: it must have no assertion
54
+ * prefix, nothing shell-shaped anywhere in it, and enough words to be a
55
+ * sentence — so a bare `./check.sh` or a one-word command is left alone and
56
+ * the warning only fires where the author plainly wrote prose. */
57
+ function looksLikeProse(verify) {
58
+ const v = verify.trim();
59
+ if (!v || VERIFY_ASSERTION.test(v))
60
+ return false;
61
+ if (LOOKS_LIKE_SHELL.test(v))
62
+ return false;
63
+ return v.split(/\s+/).length >= 4;
64
+ }
17
65
  export function lintFlow(flow, known) {
18
66
  const warnings = [];
19
67
  const agentNames = known ? new Set(known.agents) : null;
68
+ // A frontmatter enum the parser could not read, or a step line whose
69
+ // `[[target]]` is malformed — recorded by parseFlow, reported here at
70
+ // error level so `foldrun check` fails on it, the way a bad step option
71
+ // does. A value nothing can read is never a silent default.
72
+ for (const fp of flow.frontProblems ?? []) {
73
+ warnings.push({ step: null, level: "error", message: fp, detail: "The line is written but its value cannot be read, so a run would use a silent default instead of what the author meant. Write one of the values the option names, or a target in lower case, digits and dashes." });
74
+ }
20
75
  // Cron's oldest trap, and an expensive one: when day-of-month AND
21
76
  // day-of-week are both restricted they are OR'd, not AND'd — the scheduler
22
77
  // does it too, correctly (`domRestricted && dowRestricted` → `domOk ||
@@ -25,6 +80,82 @@ export function lintFlow(flow, known) {
25
80
  // eleven runs where one was meant. Nothing about the expression looks wrong,
26
81
  // which is exactly why it needs saying here rather than being discovered on
27
82
  // the bill.
83
+ // An approvers list only one word can satisfy. `approvers: [editors]` is
84
+ // a role that is not `admins` and not an address; mayApprove would then
85
+ // refuse every person, and the gate could only ever be answered by an
86
+ // emailed link. Said here rather than discovered at the gate.
87
+ const odd = (flow.approvers ?? []).filter((a) => a !== "admins" && !looksLikeAddress(a));
88
+ if (odd.length) {
89
+ warnings.push({
90
+ step: null,
91
+ message: `approvers: ${odd.join(", ")} — not an email address, and the only role word is admins`,
92
+ detail: "Each entry is an address that may answer this flow's gates, or the word `admins`. Anything else matches nobody, and a list nobody matches locks every gate.",
93
+ });
94
+ }
95
+ // A flow with an approvers list and no gate at all is a rule the author
96
+ // believes is in force and which does nothing — the worst kind of safety
97
+ // control.
98
+ if (flow.approvers?.length && !flow.steps.some((s) => s.approve || s.ask)) {
99
+ warnings.push({
100
+ step: null,
101
+ message: "approvers: is set but no step in this flow is a gate",
102
+ detail: "Nothing here waits for a person, so the list has no effect. Mark the step that needs " +
103
+ "a second pair of eyes with `!` (or `approve: true`), or drop the approvers: line.",
104
+ });
105
+ }
106
+ // A zone nobody can read is two faults at once: the cron fires at the
107
+ // wrong hour, and every step's calendar quietly falls through to the level
108
+ // above. Both are invisible in a green run, so `foldrun check` refuses it.
109
+ const zoneProblem = timezoneProblem(flow.timezone);
110
+ if (zoneProblem) {
111
+ warnings.push({
112
+ step: null,
113
+ level: "error",
114
+ message: zoneProblem,
115
+ detail: "This is the zone the schedule fires in AND the calendar every step in this flow works " +
116
+ "to. Unreadable, the schedule falls back to UTC and each step inherits the workspace's " +
117
+ "zone instead of this one.",
118
+ });
119
+ }
120
+ // A deadline on a gate that does not exist reads as a safety net and is not
121
+ // one. Same reasoning, said separately because the fix is different.
122
+ if (flow.approveWithin && !flow.steps.some((s) => s.approve || s.ask)) {
123
+ warnings.push({
124
+ step: null,
125
+ message: "approve_within: is set but no step in this flow is a gate",
126
+ detail: "Nothing waits for a person, so nothing can expire. Mark a step with `!`, or drop the line.",
127
+ });
128
+ }
129
+ // A throttle no schedule can ever trip: the flow cannot run more often
130
+ // than its cron fires, so a floor below that interval never fires either.
131
+ // Cheap to write, silently pointless, and a reader will believe it.
132
+ if (flow.throttle && flow.trigger === "schedule" && flow.schedule) {
133
+ warnings.push({
134
+ step: null,
135
+ message: `throttle: on a scheduled flow — check it is shorter than the schedule, or it will drop runs you meant to happen`,
136
+ detail: "A schedule already decides how often this runs. A throttle longer than the gap between " +
137
+ "fires silently skips them; if that is what you want, say it in the cron instead.",
138
+ });
139
+ }
140
+ // `idempotency:` only has a delivery to read on a trigger that receives
141
+ // one. On a schedule or a chained flow there is no request and no field,
142
+ // so the key is inert.
143
+ if (flow.idempotency && flow.trigger !== "webhook" && flow.trigger !== "email") {
144
+ warnings.push({
145
+ step: null,
146
+ message: `idempotency: has nothing to read on trigger: ${flow.trigger}`,
147
+ detail: "A delivery id comes off an incoming request, so this only does something for " +
148
+ "trigger: webhook or trigger: email. On any other trigger it is ignored.",
149
+ });
150
+ }
151
+ // `catchup:` is about a fire that was missed, which only a clock can miss.
152
+ if (flow.catchup && flow.trigger !== "schedule") {
153
+ warnings.push({
154
+ step: null,
155
+ message: `catchup: has no effect on trigger: ${flow.trigger}`,
156
+ detail: "Only a schedule can miss a fire. Every other trigger happens when it happens.",
157
+ });
158
+ }
28
159
  if (flow.schedule) {
29
160
  const [, , dom, , dow] = flow.schedule.trim().split(/\s+/);
30
161
  if (dom && dow && dom !== "*" && dow !== "*") {
@@ -39,6 +170,9 @@ export function lintFlow(flow, known) {
39
170
  }
40
171
  // Trigger shapes that can never fire, said at check time rather than
41
172
  // discovered as a flow that "never runs".
173
+ if (flow.budgetProblem) {
174
+ 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." });
175
+ }
42
176
  if (flow.trigger === "once" && !flow.at) {
43
177
  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." });
44
178
  }
@@ -62,6 +196,36 @@ export function lintFlow(flow, known) {
62
196
  const firstGroup = Math.min(...flow.steps.map((s) => s.group));
63
197
  flow.steps.forEach((step, i) => {
64
198
  const inFirstGroup = step.group === firstGroup;
199
+ // A value the parser refused. Not advisory: the run would go ahead on
200
+ // a number the author never wrote — `timeout: 15m` ran as one second
201
+ // for as long as this was a coercion — so the check fails instead.
202
+ for (const problem of step.problems ?? []) {
203
+ warnings.push({
204
+ step: i,
205
+ line: step.line,
206
+ level: "error",
207
+ message: problem,
208
+ detail: "The option is written but its value cannot be read, and a run would not do what the " +
209
+ "line says. Durations are seconds or 90s / 30m / 4h / 3d; counts are whole numbers " +
210
+ "within the key's cap (retry and loop at most 5, max at most 20).",
211
+ });
212
+ }
213
+ // An instruction written over more than one line. It is read in full
214
+ // now, but the parser had to decide where it stopped, and the line
215
+ // below a wrapped instruction is one edit away from being prose. Said
216
+ // out loud so an author who meant to wrap can see it, and one who did
217
+ // not can see what got joined on.
218
+ if (step.wrapped) {
219
+ warnings.push({
220
+ step: i,
221
+ line: step.line,
222
+ message: `"${step.subflow ?? step.agent}" has an instruction spread over more than one line`,
223
+ detail: "A step's instruction ends where the step ends: the indented lines directly under it " +
224
+ "are joined on, and the first blank line, option, heading, bullet or unindented line " +
225
+ "finishes it. Put the whole instruction on the step's own line — one line, however " +
226
+ "long — so what the agent is told does not depend on where the paragraph below begins.",
227
+ });
228
+ }
65
229
  // The first group starts with context = null. An instruction that points
66
230
  // at earlier output therefore points at nothing.
67
231
  if (inFirstGroup && step.instruction && REFERS_BACK.test(step.instruction)) {
@@ -73,6 +237,29 @@ export function lintFlow(flow, known) {
73
237
  "invent what it was asked to review rather than fail. Move it to a later group.",
74
238
  });
75
239
  }
240
+ // `../../storage/…` still works everywhere; `workspace/storage/…` is the
241
+ // spelling that also works in a shell, and the one the docs teach. Said
242
+ // once per step, advisory — never an error on a path that resolves.
243
+ {
244
+ const rowsOf = step.when ? whenRowsPath(step.when) : null;
245
+ const spots = [
246
+ step.eachPath ? ["each: rows of", step.eachPath] : null,
247
+ rowsOf ? ["when: rows of", rowsOf] : null,
248
+ step.verify ? ["verify:", step.verify] : null,
249
+ step.schemaPath ? ["schema:", step.schemaPath] : null,
250
+ step.instruction ? ["the instruction", step.instruction] : null,
251
+ ].filter((x) => !!x && /\.\.\/\.\.\/(storage|state)\b/.test(x[1]));
252
+ if (spots.length) {
253
+ warnings.push({
254
+ step: i,
255
+ line: step.line,
256
+ kind: "spelling",
257
+ message: `"${step.subflow ?? step.agent}" writes ../../storage or ../../state in ${spots.map((x) => x[0]).join(", ")}`,
258
+ detail: "It still works. The documented spelling is workspace/storage/… and workspace/state/… — " +
259
+ "the same place, and it also resolves in the shell and in scripts.",
260
+ });
261
+ }
262
+ }
76
263
  // A gate with no `preview:` shows only the previous step's reply and
77
264
  // whatever files that reply happens to name. The person deciding sees a
78
265
  // summary, not the thing — unless the agent remembered.
@@ -86,6 +273,41 @@ export function lintFlow(flow, known) {
86
273
  "always sees the document, not a pointer, even when the agent forgets to name it.",
87
274
  });
88
275
  }
276
+ // A step that can act on the outside world, with nothing to say whether
277
+ // it did. The two answers are a check the runtime can fail on, or a
278
+ // person; either is fine, neither is not. This is the one lint here that
279
+ // is an error: every other structural warning costs a reread, and this
280
+ // one costs a send nobody can take back.
281
+ if (known?.outwardAgents?.includes(step.agent ?? "") && !step.verify && !step.approve && !step.ask) {
282
+ warnings.push({
283
+ step: step.group,
284
+ line: step.line,
285
+ level: "error",
286
+ kind: "outward",
287
+ message: `[[${step.agent}]] can act outside this workspace and this step has no verify: and no gate`,
288
+ detail: "A step that sends, posts, buys or publishes needs one of two things: a `verify:` the " +
289
+ "runtime can fail the step on — a receipt file, a ledger row, the reply's own verdict " +
290
+ "line — or a person, with `!` or `ask:`. Without either, a step that sent nothing and a " +
291
+ "step that sent everything end the same way: reported as done.",
292
+ });
293
+ }
294
+ // retry: re-runs a failed step from the start. For a step that sends,
295
+ // a failure can come after the send — the verify: or the JSON check
296
+ // failed on a step whose email went — and the retry sends it again. The
297
+ // runner declines that one retry (see actedThenFailedCheck in runner.ts)
298
+ // but a crash mid-send still reruns; the author should know.
299
+ if (known?.outwardAgents?.includes(step.agent ?? "") && step.retry) {
300
+ warnings.push({
301
+ step: i,
302
+ line: step.line,
303
+ kind: "outward",
304
+ message: `[[${step.agent}]] can act outside this workspace and this step has retry: ${step.retry}`,
305
+ detail: "A retry runs the whole step again, sends included. The runner does not retry a failure " +
306
+ "that came from the check after the step's tools ran, but an attempt that failed mid-way — " +
307
+ "a timeout, a crash, a provider error after the first send — is retried and may repeat " +
308
+ "what it already did. Make the send idempotent (check a ledger before sending), or drop retry:.",
309
+ });
310
+ }
89
311
  // `each: items` fans out over DATA, and only an `output: json` step in
90
312
  // an earlier group produces any. Without one the step expands to
91
313
  // nothing every time, quietly — the exact failure this file exists for.
@@ -102,6 +324,59 @@ export function lintFlow(flow, known) {
102
324
  });
103
325
  }
104
326
  }
327
+ // Two options that read another option to mean anything.
328
+ if (step.parallel && !step.each) {
329
+ warnings.push({
330
+ step: i,
331
+ line: step.line,
332
+ message: `"${step.subflow ?? step.agent}" has parallel: but no each:`,
333
+ detail: "parallel: caps how many instances of a fan-out run at once. Without each: there is one instance, and the line does nothing.",
334
+ });
335
+ }
336
+ if ((step.schema !== undefined || step.schemaPath) && step.output !== "json") {
337
+ warnings.push({
338
+ step: i,
339
+ line: step.line,
340
+ message: `"${step.subflow ?? step.agent}" has schema: but no output: json`,
341
+ detail: "schema: describes the JSON value an output: json step returns. Without output: json nothing is parsed, so nothing is checked. Add `output: json`.",
342
+ });
343
+ }
344
+ // The step's own agent. `delegate:` and `on-fail:` are checked below and
345
+ // the step's target was not, which is the reference that stops the run
346
+ // rather than degrading it: the runner reaches the step, finds nothing to
347
+ // run and fails it with `agent "<name>" not found in workspace`. A
348
+ // scheduled flow does that at 3am, three times, before anyone looks.
349
+ if (agentNames && step.agent && !step.subflow && !agentNames.has(step.agent)) {
350
+ warnings.push({
351
+ step: i,
352
+ line: step.line,
353
+ level: "error",
354
+ message: `[[${step.agent}]] is not an agent in this workspace`,
355
+ detail: "This step has nothing to run. Every run of this flow fails here. Check the spelling " +
356
+ "against `agents/<name>/agent.md` — the name is the folder's, not the file's heading — " +
357
+ "or add the agent.",
358
+ });
359
+ }
360
+ // A `verify:` written as a sentence. Two dialects share the key: a line
361
+ // beginning `contains:`, `not-contains:`, `matches:`, `file:` or
362
+ // `judge:` is an assertion, and ANYTHING else is handed to a shell. So
363
+ // `verify: the reply names the clone it made` runs a program called
364
+ // `the`, exits 127, and fails a step that did its job perfectly — every
365
+ // run, with an error about bash that says nothing about the flow. The
366
+ // fix is one word: the same sentence behind `judge:` is graded by a
367
+ // model, which is what the author meant.
368
+ if (step.verify && looksLikeProse(step.verify)) {
369
+ warnings.push({
370
+ step: i,
371
+ line: step.line,
372
+ level: "error",
373
+ message: `verify: reads as a sentence, so it will be run as a shell command`,
374
+ detail: `\`${step.verify.slice(0, 60)}${step.verify.length > 60 ? "…" : ""}\` has no assertion ` +
375
+ "prefix, so the runtime executes it: the first word becomes the program and the step " +
376
+ "fails with `command not found`. Put `judge: ` in front to have a model grade the " +
377
+ "claim, or write it as a shell command that exits 0 when the claim holds.",
378
+ });
379
+ }
105
380
  // A step's OTHER agent references — the ones no parser validates,
106
381
  // because they are options rather than the step's target. Both fail
107
382
  // silently and at the worst possible moment: a misspelled `delegate:`
@@ -141,7 +416,8 @@ export function lintFlow(flow, known) {
141
416
  });
142
417
  }
143
418
  // `when:` tests the previous results, which the first group doesn't have.
144
- if (inFirstGroup && step.when) {
419
+ // `when: rows of` reads a file instead, which may well exist already.
420
+ if (inFirstGroup && step.when && whenRowsPath(step.when) === null) {
145
421
  warnings.push({
146
422
  step: i,
147
423
  line: step.line,
@@ -150,6 +426,23 @@ export function lintFlow(flow, known) {
150
426
  "always be skipped. Move it after the step whose output it depends on.",
151
427
  });
152
428
  }
429
+ // A `[[flow:x]]` step is spliced in as the other flow's own steps, and
430
+ // only its `?` and its instruction survive the splice. Everything else
431
+ // written under it was dropped without a word — a `when:` that never
432
+ // gated, a `!` that never asked.
433
+ if (step.subflow) {
434
+ const dropped = SUBFLOW_DROPPED.filter(([field]) => step[field] !== undefined).map(([, name]) => name);
435
+ if (dropped.length) {
436
+ warnings.push({
437
+ step: i,
438
+ line: step.line,
439
+ message: `"flow:${step.subflow}" has ${dropped.join(", ")}, which a nested flow ignores`,
440
+ detail: "A nested flow runs as its own steps, with their own options; what is written under the " +
441
+ "[[flow:…]] line is not applied to them. Put the option on the steps inside that flow, " +
442
+ "or make this an agent step.",
443
+ });
444
+ }
445
+ }
153
446
  });
154
447
  // The same agent twice in one parallel group gets two identical contexts and
155
448
  // no way to divide the work — almost always a drag that landed wrong.
@@ -172,6 +465,43 @@ export function lintFlow(flow, known) {
172
465
  });
173
466
  }
174
467
  }
468
+ // A gate parks its whole group, and on approval every step in it starts
469
+ // together. So `5. [[editor]]` beside `5! [[publisher]]` does not mean
470
+ // "edit, then ask, then publish": the editor waits for the approval too,
471
+ // and the publisher runs alongside it, reading files the editor has not
472
+ // written yet. medium-desk's publisher did exactly that on 2026-09-28
473
+ // (run-mukdjeh8-cr66): post.json was still empty when it started.
474
+ const gated = (s) => Boolean(s.approve || s.ask || s.waitFor === "event");
475
+ const gates = steps.filter(gated);
476
+ const others = steps.filter((s) => !gated(s));
477
+ if (gates.length && others.length) {
478
+ const name = (s) => (s.subflow ? `flow:${s.subflow}` : s.agent);
479
+ warnings.push({
480
+ step: flow.steps.indexOf(gates[0]),
481
+ line: gates[0].line,
482
+ message: `"${name(gates[0])}" waits for a person but shares number ${group} with "${others.map(name).join('", "')}"`,
483
+ detail: "Steps with the same number run together. The gate holds all of them until it is " +
484
+ "approved, then they start at once — so the gated step cannot use what the others " +
485
+ `produce, and the approver sees none of it. To run the gated step after them, number it ${group + 1}.`,
486
+ });
487
+ }
488
+ }
489
+ // A number with nothing under it is harmless to the runner, which only
490
+ // orders groups, but it is almost always one step numbered twice: 3, 3, 4,
491
+ // 5, 5!, 7 is a renumbering that missed the 5! that was meant to be 6.
492
+ const numbers = [...byGroup.keys()].sort((a, b) => a - b);
493
+ for (let i = 1; i < numbers.length; i++) {
494
+ if (numbers[i] - numbers[i - 1] < 2)
495
+ continue;
496
+ const missing = numbers[i - 1] + 1 === numbers[i] - 1 ? `${numbers[i - 1] + 1}` : `${numbers[i - 1] + 1} to ${numbers[i] - 1}`;
497
+ const shared = [...byGroup.entries()].filter(([, s]) => s.length > 1).map(([g]) => g);
498
+ warnings.push({
499
+ step: null,
500
+ message: `step numbers go from ${numbers[i - 1]} to ${numbers[i]}; nothing is numbered ${missing}`,
501
+ detail: "The same number means \"run together\", so a gap usually means a step kept an old number " +
502
+ "after a renumbering" +
503
+ (shared.length ? ` — ${shared.map((g) => `number ${g}`).join(", ")} has more than one step; check whether one of them belongs in the gap.` : "."),
504
+ });
175
505
  }
176
506
  return warnings;
177
507
  }