From 14c8f796238392ea4f4495d20e44e0d43754810a Mon Sep 17 00:00:00 2001 From: skovtunenko <14869404+skovtunenko@users.noreply.github.com> Date: Thu, 26 Nov 2026 01:04:29 +0100 Subject: [PATCH] Release v2026.11.26.2 --- .../evals/fixtures/expense-report.kdl.fixture | 2 +- build/skillflow/tests/data-paths.cases.mjs | 62 +++--- build/skillflow/tests/data-paths.test.mjs | 6 +- build/skillflow/tests/edge-inputs.test.mjs | 12 +- build/skillflow/tests/editor-pure.test.mjs | 10 +- .../tests/fixtures/release-notes.fixture | 4 +- build/skillflow/tests/fmt.test.mjs | 6 +- .../skillflow/tests/generated-paths.test.mjs | 4 +- build/skillflow/tests/reference-model.mjs | 10 +- build/skillflow/tests/rule-guards.test.mjs | 3 +- build/skillflow/tests/skillflow.test.mjs | 58 +++--- build/skillflow/tests/snapshots.test.mjs | 6 +- ...cate-name.txt => catch-duplicate-name.txt} | 0 .../{empty-on-fail.txt => empty-catch.txt} | 2 +- .../tests/snapshots/example.model.json | 22 +- .../tests/snapshots/header-plain.model.json | 2 +- .../snapshots/header-version-stamp.model.json | 2 +- .../snapshots/html-escape-prose.model.json | 2 +- .../tests/snapshots/input-read.model.json | 2 +- .../{two-on-fail.txt => two-catch.txt} | 2 +- .../tests/snapshots/unicode-names.model.json | 4 +- build/skillflow/tests/viewer-pure.test.mjs | 2 +- .../skillflow/tests/viewer.browser.suite.mjs | 42 ++-- site/build.mjs | 23 ++- site/examples/{on-fail.kdl => catch.kdl} | 2 +- site/examples/release-notes.kdl | 2 +- site/examples/why.kdl | 2 +- site/index.html | 190 ++++++++++-------- site/tutorial/{3-on-fail.kdl => 3-catch.kdl} | 4 +- site/tutorial/4-gate.kdl | 2 +- site/tutorial/5-decide.kdl | 2 +- site/tutorial/6-phases.kdl | 2 +- site/tutorial/7-context.kdl | 2 +- skills/skillflow/SKILL.md | 6 +- skills/skillflow/assets/editor/complete.mjs | 2 +- skills/skillflow/assets/editor/graph-diff.mjs | 2 +- skills/skillflow/assets/help.html | 22 +- skills/skillflow/assets/viewer-lib/text.js | 2 +- skills/skillflow/assets/viewer.css | 10 +- skills/skillflow/assets/viewer/canvas.js | 2 +- .../skillflow/assets/viewer/comment-store.js | 2 +- skills/skillflow/assets/viewer/helpers.js | 2 +- skills/skillflow/assets/viewer/layout.js | 22 +- skills/skillflow/assets/viewer/model.js | 18 +- skills/skillflow/assets/viewer/panels.js | 16 +- skills/skillflow/assets/viewer/scenario-ui.js | 8 +- skills/skillflow/assets/viewer/scenario.js | 18 +- skills/skillflow/assets/viewer/shell.js | 6 +- skills/skillflow/flow.kdl | 8 +- skills/skillflow/references/authoring.md | 20 +- skills/skillflow/references/example.md | 8 +- skills/skillflow/references/grammar.md | 34 ++-- skills/skillflow/references/help.md | 22 +- skills/skillflow/scripts/render.mjs | 16 +- skills/skillflow/scripts/validate.mjs | 58 +++--- 55 files changed, 414 insertions(+), 386 deletions(-) rename build/skillflow/tests/snapshots/{on-fail-duplicate-name.txt => catch-duplicate-name.txt} (100%) rename build/skillflow/tests/snapshots/{empty-on-fail.txt => empty-catch.txt} (75%) rename build/skillflow/tests/snapshots/{two-on-fail.txt => two-catch.txt} (70%) rename site/examples/{on-fail.kdl => catch.kdl} (88%) rename site/tutorial/{3-on-fail.kdl => 3-catch.kdl} (75%) diff --git a/build/skillflow/evals/fixtures/expense-report.kdl.fixture b/build/skillflow/evals/fixtures/expense-report.kdl.fixture index a2477d7..4cbfc2f 100644 --- a/build/skillflow/evals/fixtures/expense-report.kdl.fixture +++ b/build/skillflow/evals/fixtures/expense-report.kdl.fixture @@ -16,7 +16,7 @@ phase scan ref="S1" { step scan-receipts by=code file="scripts/scan.sh" { output receipts "the file, date, amount, and currency of each receipt" - on-fail { + catch { end "tell the user that the folder has no receipts" } } diff --git a/build/skillflow/tests/data-paths.cases.mjs b/build/skillflow/tests/data-paths.cases.mjs index ad474f2..9baf318 100644 --- a/build/skillflow/tests/data-paths.cases.mjs +++ b/build/skillflow/tests/data-paths.cases.mjs @@ -4,7 +4,7 @@ // every other input reached is a read that gets a warning; unreachable: "kind:name"; end: names available where the flow // ends normally (null when every path stops at `end`); unused: outputs that no input names; flowOutputs: named flow // outputs that must be reported as not produced; recovery (optional): "output:data" flow outputs that exist only when a -// step succeeds, because its on-fail continues without them (a warning); +// step succeeds, because its catch continues without them (a warning); // terminates (optional): blocks that no path leaves. // Each text gets the first line `skillflow 1.0`. @@ -285,7 +285,7 @@ step after by=llm { flowOutputs: [], text: `step s by=code { output x - on-fail "Retry once, then continue." + catch "Retry once, then continue." } step u by=llm { input x @@ -296,7 +296,7 @@ step u by=llm { flowOutputs: [], text: `step s by=code { output x - on-fail { + catch { step h by=human { output note } @@ -312,7 +312,7 @@ step u by=llm { flowOutputs: [], text: `step s by=code { output x - on-fail { + catch { step h by=llm { input x } @@ -327,7 +327,7 @@ step u by=llm { } step s by=code { input req - on-fail { + catch { step h by=llm { input req } @@ -335,13 +335,13 @@ step s by=code { } `, expect: {missing: [], unreachable: [], end: ["req"], unused: []}}, - {name: "nested-termination-onfail", why: "on-fail end inside a branch; success path continues", + {name: "nested-termination-catch", why: "catch end inside a branch; success path continues", flowOutputs: [], text: `decide d "go?" by=llm { when a { step t by=code { output r - on-fail { + catch { end "t failed" } } @@ -445,23 +445,23 @@ decide d "which?" by=llm { } `, expect: {missing: [], unreachable: [], end: [], unused: []}}, - // declared recovery (grammar rule 5): an on-fail output says which data the recovery restores - {name: "recovery-silent-gap", why: "the on-fail continues without the report: the flow output depends on success", + // declared recovery (grammar rule 5): a catch output says which data the recovery restores + {name: "recovery-silent-gap", why: "the catch continues without the report: the flow output depends on success", flowOutputs: [], recovery: ["output:report"], text: `context { output report "the report" } step generate by=code { output report - on-fail "Continue without a report." + catch "Continue without a report." } `, expect: {missing: [], unreachable: [], end: ["report"], unused: []}}, - {name: "recovery-declared", why: "the on-fail says it restores the report: no warning", + {name: "recovery-declared", why: "the catch says it restores the report: no warning", flowOutputs: [], text: `step generate by=code { output report - on-fail "Retry twice, then use the cached report." { + catch "Retry twice, then use the cached report." { output report } } @@ -470,11 +470,11 @@ step publish by=code { } `, expect: {missing: [], unreachable: [], end: ["report"], unused: []}}, - {name: "recovery-ends", why: "an on-fail that ends needs no recovery output", + {name: "recovery-ends", why: "a catch that ends needs no recovery output", flowOutputs: [], text: `step generate by=code { output report - on-fail { + catch { end "no report" } } @@ -487,7 +487,7 @@ step publish by=code { flowOutputs: [], text: `step generate by=code { output report - on-fail { + catch { step write-by-hand by=human { output report } @@ -502,7 +502,7 @@ step publish by=code { flowOutputs: [], text: `step generate by=code { output report - on-fail "Keep the partial report." { + catch "Keep the partial report." { output partial } } @@ -512,11 +512,11 @@ step publish by=code { } `, expect: {missing: ["publish:partial"], unreachable: [], end: ["partial","report"], unused: []}}, - {name: "recovery-in-handler", why: "the restored data is available inside the on-fail, as an outcome's output is inside its when", + {name: "recovery-in-handler", why: "the restored data is available inside the catch, as an outcome's output is inside its when", flowOutputs: [], text: `step generate by=code { output report - on-fail "Use the cached report." { + catch "Use the cached report." { output report step note-fallback by=llm { input report @@ -528,7 +528,7 @@ step publish by=code { } `, expect: {missing: [], unreachable: [], end: ["report"], unused: []}}, - // control flow: `terminates` lists, by hand, every block that no path leaves: "phase", "decision/outcome", "step/on-fail" + // control flow: `terminates` lists, by hand, every block that no path leaves: "phase", "decision/outcome", "step/catch" {name: "phase-gate-approved-ends", why: "approved ends inside a phase; rejected continues past it", flowOutputs: [], terminates: {review: false, "approval/approved": true, "approval/rejected": false}, text: `context { @@ -601,11 +601,11 @@ step finish by=llm step finish by=llm `, expect: {missing: [], unreachable: [], end: [], unused: []}}, - {name: "phase-on-fail-ends", why: "an on-fail that ends does not end the phase: success continues", - flowOutputs: [], terminates: {work: false, "run/on-fail": true}, + {name: "phase-catch-ends", why: "a catch that ends does not end the phase: success continues", + flowOutputs: [], terminates: {work: false, "run/catch": true}, text: `phase work { step run by=code { - on-fail { + catch { end "failed" } } @@ -623,26 +623,26 @@ export const formCases = [ } } `, errors: [/`input` is not allowed inside `when`/]}, - {name: "output-in-on-fail", text: `step s by=code { + {name: "output-in-catch", text: `step s by=code { output x - on-fail "Retry once." { + catch "Retry once." { output x } } `, errors: []}, - {name: "on-fail-only-output", why: "an output says what the recovery restores, not what happens", text: `step s by=code { + {name: "catch-only-output", why: "an output says what the recovery restores, not what happens", text: `step s by=code { output x - on-fail { + catch { output x } } -`, errors: [/`on-fail` is empty/]}, - {name: "input-in-on-fail", text: `step s by=code { - on-fail "Retry once." { +`, errors: [/`catch` is empty/]}, + {name: "input-in-catch", text: `step s by=code { + catch "Retry once." { input x } } -`, errors: [/`input` is not allowed inside `on-fail`/]}, +`, errors: [/`input` is not allowed inside `catch`/]}, {name: "input-in-phase", text: `phase p { input x } @@ -688,7 +688,7 @@ step s by=llm { step s by=llm { note x } -`, errors: [/`note` is not allowed inside `step`.*allowed here: input, on-fail, output, tools/]}, +`, errors: [/`note` is not allowed inside `step`.*allowed here: catch, input, output, tools/]}, {name: "unknown-in-when", text: `decide d "?" by=llm { when a { note x diff --git a/build/skillflow/tests/data-paths.test.mjs b/build/skillflow/tests/data-paths.test.mjs index e74be5f..a92b11b 100644 --- a/build/skillflow/tests/data-paths.test.mjs +++ b/build/skillflow/tests/data-paths.test.mjs @@ -77,7 +77,7 @@ function* cards(nodes) { for (const n of nodes) { yield n; yield* cards(n.children ?? []); - if (n.onfail) yield* cards(n.onfail.children); + if (n.catch) yield* cards(n.catch.children); for (const w of n.whens ?? []) yield* cards(w.children); } } @@ -87,7 +87,7 @@ function modelTerminates(model) { const out = {}; for (const n of cards(model.flow)) { if (n.kind === "phase") out[n.name] = n.ends; - if (n.onfail) out[`${n.name}/on-fail`] = n.onfail.ends; + if (n.catch) out[`${n.name}/catch`] = n.catch.ends; for (const w of n.whens ?? []) out[`${n.name}/${w.outcome}`] = w.ends; } return out; @@ -119,7 +119,7 @@ describe("data forms", () => { }); test("a recovery warning names the step on the path that reaches the end, not one on an ended branch", () => { - const branch = (outcome, step, tail) => ` when ${outcome} {\n step ${step} by=code {\n output report\n on-fail "Continue without a report."\n }\n${tail} }\n`; + const branch = (outcome, step, tail) => ` when ${outcome} {\n step ${step} by=code {\n output report\n catch "Continue without a report."\n }\n${tail} }\n`; const report = validate(flowText(`decide route "Which?" by=human {\n${branch("archived", "obsolete", ' end "archived"\n')}${branch("active", "current", "")}}\n`.replace(/^/, 'context {\n output report "the report"\n}\n'))); assert.deepEqual(report.errors, []); assert.deepEqual(report.warnings.filter(([, m]) => m.includes("exists only when")).map(([, m]) => m.match(/step `(.+?)`/)[1]), ["current"]); diff --git a/build/skillflow/tests/edge-inputs.test.mjs b/build/skillflow/tests/edge-inputs.test.mjs index 3b621cd..3e564b5 100644 --- a/build/skillflow/tests/edge-inputs.test.mjs +++ b/build/skillflow/tests/edge-inputs.test.mjs @@ -26,8 +26,8 @@ test("a decide outcome named like an Object key keeps its implied outcome", () = assert.ok(fs.readFileSync(page, "utf8").includes('"implied":[{"outcome":"other"')); }); -test("on-fail with an end and continuing prose points to a decide, not to dropping the end", () => { - const file = flow(tmp(), 'step a "Do it." by=llm {\n on-fail "If the token is absent, end. If the request times out, continue." {\n end "missing token"\n }\n}\n'); +test("catch with an end and continuing prose points to a decide, not to dropping the end", () => { + const file = flow(tmp(), 'step a "Do it." by=llm {\n catch "If the token is absent, end. If the request times out, continue." {\n end "missing token"\n }\n}\n'); const out = run("validate", file).stdout; assert.match(out, /holds an `end`, but its prose says the flow continues/); assert.match(out, /decide/); @@ -56,7 +56,7 @@ test("render refuses a page it cannot read and leaves it unchanged", {skip: proc assert.equal(fs.readFileSync(page, "utf8"), before); }); -// Feedback from 20 reverse runs (2026-11-14): page name and version, closing end, library writes, depth in on-fail, router size base. +// Feedback from 20 reverse runs (2026-11-14): page name and version, closing end, library writes, depth in catch, router size base. const skill = (dir, md, files = {}) => { const root = path.join(dir, "sk"); fs.mkdirSync(path.join(root, "references"), {recursive: true}); @@ -100,11 +100,11 @@ test("rules marks library saves as writes", () => { assert.deepEqual(writes, [1, 2, 3]); }); -test("a decide inside on-fail and a top-level phase add no depth warning; nested phases and deeper logic still do", () => { +test("a decide inside catch and a top-level phase add no depth warning; nested phases and deeper logic still do", () => { const deep = (inner) => `phase outer {\n phase inner {\n decide d "Q?" by=llm {\n when yes {\n step s "Do it." by=llm {\n${inner} }\n }\n }\n }\n}\n`; - const recovery = ' on-fail "If X, end." {\n decide x "Is it X?" by=llm {\n when yes {\n step tell "Tell." by=human\n end "x"\n }\n }\n }\n'; + const recovery = ' catch "If X, end." {\n decide x "Is it X?" by=llm {\n when yes {\n step tell "Tell." by=human\n end "x"\n }\n }\n }\n'; assert.doesNotMatch(run("validate", flow(tmp(), deep(recovery))).stdout, /levels deep/); - const main = ' on-fail "Stop." {\n end "stop"\n }\n'; + const main = ' catch "Stop." {\n end "stop"\n }\n'; assert.doesNotMatch(run("validate", flow(tmp(), deep(main))).stdout, /levels deep/); assert.doesNotMatch(run("validate", flow(tmp(), 'phase p {\n decide d "Q?" by=llm {\n when yes {\n decide e "R?" by=llm {\n when yes {\n step s "Do." by=llm\n }\n }\n }\n }\n}\n')).stdout, /levels deep/); assert.match(run("validate", flow(tmp(), 'phase outer {\n phase inner {\n decide d "Q?" by=llm {\n when yes {\n decide e "R?" by=llm {\n when yes {\n step s "Do." by=llm\n }\n }\n }\n }\n }\n}\n')).stdout, /4 levels deep/); diff --git a/build/skillflow/tests/editor-pure.test.mjs b/build/skillflow/tests/editor-pure.test.mjs index f7b9c71..231a791 100644 --- a/build/skillflow/tests/editor-pure.test.mjs +++ b/build/skillflow/tests/editor-pure.test.mjs @@ -158,10 +158,10 @@ test("htmlLines gives one escaped line of spans for each text line", () => { test("graph changes: new and changed cards by a key that survives a redraw", () => { const model = (flow) => ({flow}); const before = model([{id: "n1", kind: "step", name: "read", prose: "Read.", line: 3, children: []}, - {id: "n2", kind: "decide", name: "ok", line: 5, whens: [{outcome: "no", children: [{id: "n3", kind: "end", text: "stop", line: 7}]}], onfail: {id: "n4", kind: "onfail", children: []}}]); + {id: "n2", kind: "decide", name: "ok", line: 5, whens: [{outcome: "no", children: [{id: "n3", kind: "end", text: "stop", line: 7}]}], catch: {id: "n4", kind: "catch", children: []}}]); const after = model([{id: "m1", kind: "step", name: "added", prose: "New.", line: 2, children: []}, {id: "m2", kind: "step", name: "read", prose: "Read it all.", line: 6, children: []}, - {id: "m3", kind: "decide", name: "ok", line: 9, whens: [{outcome: "no", children: [{id: "m4", kind: "end", text: "stop", line: 11}]}], onfail: {id: "m5", kind: "onfail", children: []}}]); + {id: "m3", kind: "decide", name: "ok", line: 9, whens: [{outcome: "no", children: [{id: "m4", kind: "end", text: "stop", line: 11}]}], catch: {id: "m5", kind: "catch", children: []}}]); assert.deepEqual(diff.changes(before, after), {added: ["m1"], changed: ["m2"]}, "a card that only moved to another line is not changed"); assert.deepEqual(diff.changes(before, before), {added: [], changed: []}); }); @@ -183,7 +183,7 @@ context { step collect by=code file="scripts/collect.mjs" "Collect the changed files." { tools git rg output files "the changed files" - on-fail "Report the error; the run ends." + catch "Report the error; the run ends." } decide risky "Does the change touch a public API?" by=llm { @@ -233,8 +233,8 @@ test("the place of the cursor selects what fits: a node of the parent, a propert }); test("rank puts a start match first and keeps letters in order; expand gives a template its indent and its fields", () => { - const items = ["output", "on-fail", "tools", "input"].map((label) => ({label})); - assert.deepEqual(rank(items, "o").map((item) => item.label), ["output", "on-fail", "tools"]); + const items = ["output", "skillflow", "tools", "input"].map((label) => ({label})); + assert.deepEqual(rank(items, "o").map((item) => item.label), ["output", "skillflow", "tools"]); assert.deepEqual(rank(items, "ot").map((item) => item.label), ["output"], "o then t, in this order"); assert.deepEqual(rank(items, "").length, 4); assert.deepEqual(expand("a ${b}\nc", "\t"), {text: "a b\n\tc", stops: [[2, 3]]}); diff --git a/build/skillflow/tests/fixtures/release-notes.fixture b/build/skillflow/tests/fixtures/release-notes.fixture index fb517eb..dad3cf9 100644 --- a/build/skillflow/tests/fixtures/release-notes.fixture +++ b/build/skillflow/tests/fixtures/release-notes.fixture @@ -11,7 +11,7 @@ phase gather { step collect-changes by=code file="scripts/collect.sh" { tools gh output changes "the commits and pull requests since the last tag" - on-fail { + catch { end "report that the tag does not exist" } } @@ -32,7 +32,7 @@ phase write { } step publish by=code { output changelog - on-fail { + catch { step report-error by=llm "Show the error and leave CHANGELOG.md unchanged." end "CHANGELOG.md stays unchanged" } diff --git a/build/skillflow/tests/fmt.test.mjs b/build/skillflow/tests/fmt.test.mjs index dc32801..5c128ba 100644 --- a/build/skillflow/tests/fmt.test.mjs +++ b/build/skillflow/tests/fmt.test.mjs @@ -63,8 +63,8 @@ describe("formatFlow: layout", () => { }); test("a continued line is one level deeper; a block on one line stays on its line", () => { - assert.equal(formatFlow('skillflow 1.0\nstep a by=llm \\\n"Prose."\nstep b by=llm { on-fail { end "x" } }\n'), - 'skillflow 1.0\n\nstep a by=llm \\\n\t"Prose."\n\nstep b by=llm { on-fail { end "x" } }\n'); + assert.equal(formatFlow('skillflow 1.0\nstep a by=llm \\\n"Prose."\nstep b by=llm { catch { end "x" } }\n'), + 'skillflow 1.0\n\nstep a by=llm \\\n\t"Prose."\n\nstep b by=llm { catch { end "x" } }\n'); }); test("Windows line ends and a byte order mark go; a slashdashed node keeps its block", () => { @@ -86,7 +86,7 @@ describe("formatFlow: layout", () => { for (const [flow, line] of [['skillflow 1.0\nstep a by=llm \\\n\nstep b by=llm\n', 2], ['skillflow 1.0\nphase p {\n\tstep b by=llm\n}\nstep a by=llm \\\n', 5], ['skillflow 1.0\nphase p {\n\tstep x by=llm\n\tstep a by=llm \\\n}\n', 4]]) assert.throws(() => formatFlow(flow), (error) => error instanceof FormatError && error.line === line && /remove it/.test(error.hint), flow); // a `\\` that does continue its node is not the fault of a line with two `{`: the hint names the braces - assert.throws(() => formatFlow('skillflow 1.0\nstep a \\\n by=llm "x" { on-fail {\n end "y"\n }\n}\n'), (error) => error instanceof FormatError && error.line === 2 && /own line/.test(error.hint)); + assert.throws(() => formatFlow('skillflow 1.0\nstep a \\\n by=llm "x" { catch {\n end "y"\n }\n}\n'), (error) => error instanceof FormatError && error.line === 2 && /own line/.test(error.hint)); }); test("a string that spans lines keeps a row that a `\\` continues with other indentation", () => { diff --git a/build/skillflow/tests/generated-paths.test.mjs b/build/skillflow/tests/generated-paths.test.mjs index c31ec20..454a083 100644 --- a/build/skillflow/tests/generated-paths.test.mjs +++ b/build/skillflow/tests/generated-paths.test.mjs @@ -11,7 +11,7 @@ import {reference} from "./reference-model.mjs"; import {skillUrl} from "./skill-path.mjs"; const {argsProps, check, follow, kids, lineOf, parseFlow, Report} = await import(skillUrl("scripts/validate.mjs")); -// a profile sets how often each shape appears: "mixed" covers all structure; "recovery" makes continuing on-fail +// a profile sets how often each shape appears: "mixed" covers all structure; "recovery" makes continuing catch // handlers common, so the recovery warnings get real coverage. min: cases each run must reach. const PROFILES = { mixed: {seed: 20261108, cases: 1500, names: ["a", "b", "c"], output: 0.65, input: 0.5, fail: 0.4, handlerOutput: 0.4, handlerEnd: 0.2, more: 0.5, min: {missing: 500, recovery: 40, ended: 50}}, @@ -29,7 +29,7 @@ function action(depth = 0, handler = false) { if (kind === "phase") return `phase ${name} {\n${block(depth + 1)}\n}\n`; if (kind === "step") { const fail = depth < 3 && random() < P.fail - ? `on-fail "Recover." {\n${random() < P.handlerOutput ? `output ${data()}\n` : ""}${random() < 0.65 ? action(depth + 1, true) : ""}${random() < P.handlerEnd ? 'end "stopped"\n' : ""}}\n` : ""; + ? `catch "Recover." {\n${random() < P.handlerOutput ? `output ${data()}\n` : ""}${random() < 0.65 ? action(depth + 1, true) : ""}${random() < P.handlerEnd ? 'end "stopped"\n' : ""}}\n` : ""; return `step ${name} by=code {\n${ports()}${fail}}\n`; } const outcomes = kind === "gate" ? pick([["rejected"], ["approved", "rejected"], ["approved"], ["revise", "rejected"]]) : pick([["yes"], ["yes", "no"]]); diff --git a/build/skillflow/tests/reference-model.mjs b/build/skillflow/tests/reference-model.mjs index d474cb8..ecc273b 100644 --- a/build/skillflow/tests/reference-model.mjs +++ b/build/skillflow/tests/reference-model.mjs @@ -16,11 +16,11 @@ const named = (n) => String(argv(n)[0] ?? ""); const items = (n, names) => kidsOf(n).filter((k) => names.includes(k.getName())).flatMap((k) => argv(k).map(String)); const key = (set) => [...set].sort().join("\u0000"); -/** strict: a failed step whose on-fail continues has only what the handler path has (declared recovery, rule 5). */ +/** strict: a failed step whose catch continues has only what the handler path has (declared recovery, rule 5). */ export function reference(text, strict = false) { const doc = parse(text); const missing = new Set(), unreachable = new Set(), produced = new Set(), required = new Set(), reached = new Set(); - // terminates: "phase", "decision/outcome", or "step/on-fail" -> true when no path falls through that block + // terminates: "phase", "decision/outcome", or "step/catch" -> true when no path falls through that block const terminates = {}; const sub = (label, nodes, states) => { const out = block(nodes, states); terminates[label] = (terminates[label] ?? true) && !out.length; return out; }; const ctx = doc.nodes.find((n) => n.getName() === "context"); @@ -45,10 +45,10 @@ export function reference(text, strict = false) { const base = new Set([...s, ...made, ...asked]); if (kind === "step") { next.push(base); - const fail = kidsOf(node).find((k) => k.getName() === "on-fail"); + const fail = kidsOf(node).find((k) => k.getName() === "catch"); // the handler runs without the failed step's data, with what it declares it restores; a handler that continues // counts as recovered: the step's data stays (lenient), or the path carries on with what the handler has (strict) - const handled = fail ? sub(`${named(node)}/on-fail`, kidsOf(fail), [new Set([...s, ...items(fail, MAKE)])]) : []; + const handled = fail ? sub(`${named(node)}/catch`, kidsOf(fail), [new Set([...s, ...items(fail, MAKE)])]) : []; if (handled.length) next.push(...(strict ? handled : [new Set(base)])); continue; } @@ -70,7 +70,7 @@ export function reference(text, strict = false) { } // guarantee 9 is global: count every input and output, reachable or not - const all = (n) => { if (ACTION.has(n.getName()) || n.getName() === "when" || n.getName() === "on-fail") { items(n, NEED).forEach((r) => required.add(r)); items(n, MAKE).forEach((m) => produced.add(m)); } kidsOf(n).forEach(all); }; + const all = (n) => { if (ACTION.has(n.getName()) || n.getName() === "when" || n.getName() === "catch") { items(n, NEED).forEach((r) => required.add(r)); items(n, MAKE).forEach((m) => produced.add(m)); } kidsOf(n).forEach(all); }; doc.nodes.forEach(all); const finals = block(doc.nodes, [new Set(inputs)]); const end = finals.length ? [...finals.reduce((a, b) => a.intersection(b))].sort() : null; diff --git a/build/skillflow/tests/rule-guards.test.mjs b/build/skillflow/tests/rule-guards.test.mjs index 0fda73d..e23dcb6 100644 --- a/build/skillflow/tests/rule-guards.test.mjs +++ b/build/skillflow/tests/rule-guards.test.mjs @@ -26,6 +26,7 @@ const errors = (body, dir) => run(body, dir).errors.map(([line, message]) => `${ test("rules that only this file guards", () => { const cases = [ + ['step a by=llm {\n on-fail "x"\n}\n', "3 `on-fail` is not allowed inside `step`"], ['step a by=llm {\n tools\n}\n', "3 `tools` lists nothing"], ['step a by=llm {\n tools "two words"\n}\n', "3 `two words` in `tools` is not a bare word"], ['context {\n output 5\n}\n', "3 `output` takes a sentence, or a name and a sentence"], @@ -117,7 +118,7 @@ test("syntax and placement hints name the cause", () => { assert.match(hints('step a by=llm "x\nmore"\n'), /^a "…" string ends on its line/); assert.match(hints('step a by=llm """x"""\n'), /^a """ string spans lines/); // a node indented under another without { } is read at the top level: the hint says where it belongs - assert.match(hints('step a by=llm "x"\n output notes "n"\n'), /`output` belongs in context, step, decide, gate, when, on-fail: put it in the \{ \} block of such a node$/); + assert.match(hints('step a by=llm "x"\n output notes "n"\n'), /`output` belongs in context, step, decide, gate, when, catch: put it in the \{ \} block of such a node$/); assert.doesNotMatch(hints("phase p {\n loop x\n}\n"), /belongs in/); }); diff --git a/build/skillflow/tests/skillflow.test.mjs b/build/skillflow/tests/skillflow.test.mjs index b1ede80..3520be3 100644 --- a/build/skillflow/tests/skillflow.test.mjs +++ b/build/skillflow/tests/skillflow.test.mjs @@ -110,9 +110,9 @@ describe("CheckTest", () => { for (const key of new Set(Object.values(PROPS).flat())) has(new RegExp(`\\s${key}=`), `property ${key}`); for (const who of EXECUTORS) for (const node of ["step", "invariant"]) has(new RegExp(`^\\s*${node}\\b.*\\sby=${who}\\b`, "m"), `${node} by=${who}`); for (const kind of TOOL_KINDS) has(new RegExp(`^\\s*tools\\b.*\\(${kind}\\)`, "m"), `tool kind ${kind}`); - // the forms of a string and of a comment, and each form of `when` and `on-fail` + // the forms of a string and of a comment, and each form of `when` and `catch` for (const [pattern, what] of [[/"""\n/, 'multi-line string'], [/#"/, "raw string"], [/^\s*\/\/ \?/m, "// ? line"], [/^\s*\/\/ [^?]/m, "// comment"], [/\/\*/, "/* */ comment"], [/^\s*\/-/m, "/- node"], - [/^\s*when \S+ "/m, "when with prose"], [/^\s*when \S+ \{/m, "when with a block"], [/^\s*on-fail "/m, "on-fail with prose"], [/^\s*on-fail \{/m, "on-fail with a block"], + [/^\s*when \S+ "/m, "when with prose"], [/^\s*when \S+ \{/m, "when with a block"], [/^\s*catch "/m, "catch with prose"], [/^\s*catch \{/m, "catch with a block"], [/^\s*output "/m, "flow output without a name"], [/^context "/m, "context with a purpose"]]) has(pattern, what); }); @@ -250,22 +250,22 @@ describe("CheckTest", () => { assert.match(stats('context {\n invariant by=human "a"\n invariant by=robot "b"\n invariant "c"\n}\n'), /\n invariants: code 0 · human 1 · llm 0 · unstated 1\n/); }); - test("three on-fail blocks that only end with one reason give one warning", () => { - const step = (name, inner) => `step ${name} by=code file="scripts/collect.sh" {\n on-fail "It fails." {\n${inner} }\n}\n`; + test("three catch blocks that only end with one reason give one warning", () => { + const step = (name, inner) => `step ${name} by=code file="scripts/collect.sh" {\n catch "It fails." {\n${inner} }\n}\n`; const end = (reason) => ` end "${reason}"\n`; const same = (flow) => runCheck(flow, undefined, false).report.warnings.filter(([, message]) => message.includes("end the flow with the same reason")); const three = same(step("a", end("Report the error and stop.")) + step("b", end("report the error and stop")) + step("c", end("Report the error and stop!"))); - assert.deepEqual(three.map(([line, message]) => [line, message]), [[3, "3 `on-fail` blocks (lines 3, 8, 13) end the flow with the same reason"]]); + assert.deepEqual(three.map(([line, message]) => [line, message]), [[3, "3 `catch` blocks (lines 3, 8, 13) end the flow with the same reason"]]); assert.ok(three[0][2].includes("naming scripts/collect.sh"), three[0][2]); assert.deepEqual(same(step("a", end("Stop.")) + step("b", end("Stop."))), [], "two are not a repeat"); - assert.deepEqual(same(step("a", end("Stop.")) + step("b", end("Stop.")) + step("c", ' step tell by=llm "Say it."\n' + end("Stop."))), [], "an on-fail with a step of its own does not count"); + assert.deepEqual(same(step("a", end("Stop.")) + step("b", end("Stop.")) + step("c", ' step tell by=llm "Say it."\n' + end("Stop."))), [], "a catch with a step of its own does not count"); }); test("a flow input does not stand for the flow output of the same name", () => { const ctx = 'context {\n input log "the old log"\n output log "the new log"\n}\n'; const none = runCheck(ctx + 'step s by=llm\n', undefined, false).report; assert.ok(none.errors.some(([, message]) => message.startsWith("flow output `log` is not produced")), JSON.stringify(none.errors)); - const lost = runCheck(ctx + 'step w by=code {\n output log\n on-fail "Report it."\n}\n', undefined, false).report; + const lost = runCheck(ctx + 'step w by=code {\n output log\n catch "Report it."\n}\n', undefined, false).report; assert.deepEqual(lost.errors, []); assert.ok(lost.warnings.some(([, message]) => message.includes("exists only when step `w` succeeds")), JSON.stringify(lost.warnings)); }); @@ -315,59 +315,59 @@ describe("CheckTest", () => { assert.deepEqual(report.errors, []); }); - test("script without on-fail warns", () => { + test("script without catch warns", () => { write(path.join(skill, "scripts", "render.sh"), "exit 2\n"); - const body = 'step a by=llm "Run render.sh --new for a path."\nstep b by=code file="scripts/render.sh"\nstep c by=code file="scripts/collect.sh"\nstep d by=code file="scripts/render.sh" {\n on-fail "Fix and retry."\n}\n'; + const body = 'step a by=llm "Run render.sh --new for a path."\nstep b by=code file="scripts/render.sh"\nstep c by=code file="scripts/collect.sh"\nstep d by=code file="scripts/render.sh" {\n catch "Fix and retry."\n}\n'; const {report} = runCheck(body); - assert.deepEqual(report.warnings.filter(([, m]) => m.includes("no `on-fail`")).map(([at]) => at), [2, 3]); - // a failure that several steps share is one invariant that names the script: the steps that run it need no on-fail - const shared = (script) => runCheck(`context {\n invariant "When ${script} exits 2, report the path and end."\n}\n` + body).report.warnings.filter(([, m]) => m.includes("no `on-fail`")).map(([at]) => at); + assert.deepEqual(report.warnings.filter(([, m]) => m.includes("no `catch`")).map(([at]) => at), [2, 3]); + // a failure that several steps share is one invariant that names the script: the steps that run it need no catch + const shared = (script) => runCheck(`context {\n invariant "When ${script} exits 2, report the path and end."\n}\n` + body).report.warnings.filter(([, m]) => m.includes("no `catch`")).map(([at]) => at); assert.deepEqual(shared("scripts/render.sh"), []); assert.deepEqual(shared("scripts/other.sh"), [5, 6]); // a script in a subfolder of scripts/ is named by its path too write(path.join(skill, "scripts", "sub", "run.py"), "sys.exit(2)\n"); - const nested = (script) => runCheck(`context {\n invariant "When ${script} exits 2, report it and end."\n}\nstep r by=code file="scripts/sub/run.py"\n`).report.warnings.filter(([, m]) => m.includes("no `on-fail`")).map(([at]) => at); + const nested = (script) => runCheck(`context {\n invariant "When ${script} exits 2, report it and end."\n}\nstep r by=code file="scripts/sub/run.py"\n`).report.warnings.filter(([, m]) => m.includes("no `catch`")).map(([at]) => at); assert.deepEqual(nested("scripts/sub/run.py"), []); assert.deepEqual(nested("scripts/run.py"), [5]); }); test("end beside continue warns", () => { - const body = 'step a by=llm {\n on-fail "Markdown fails: stop. HTML fails: continue." {\n end "no article"\n }\n}\nstep b by=llm {\n on-fail "Both fail: stop." {\n end "no article"\n }\n}\n'; + const body = 'step a by=llm {\n catch "Markdown fails: stop. HTML fails: continue." {\n end "no article"\n }\n}\nstep b by=llm {\n catch "Both fail: stop." {\n end "no article"\n }\n}\n'; const {report} = runCheck(body); assert.deepEqual(report.warnings.filter(([, m]) => m.includes("says the flow continues")).map(([at]) => at), [3]); }); - test("stopping on-fail without end warns", () => { + test("stopping catch without end warns", () => { const body = `step a by=llm { - on-fail "Exit 2: report the stderr, then end." + catch "Exit 2: report the stderr, then end." } step b by=llm { - on-fail { + catch { step say by=llm "Refused path: report it and stop." } } step c by=llm { - on-fail "Exit 2: report the stderr, then end." { + catch "Exit 2: report the stderr, then end." { end "allocation failed" } } step d by=llm { - on-fail "Exit 2: stop. Missing page: retry." + catch "Exit 2: stop. Missing page: retry." } step e by=llm { - on-fail { + catch { step say-again by=llm "One cause: stop. Other cause: continue." end "stopped" } } step f by=llm { - on-fail "Report the failure, and the run ends." + catch "Report the failure, and the run ends." } step g by=llm { - on-fail "Report it, and the flow stops." + catch "Report it, and the flow stops." } step h by=llm { - on-fail "Send nothing." + catch "Send nothing." } `; const {report} = runCheck(body); @@ -395,7 +395,7 @@ step h by=llm { assert.deepEqual(messages(report.errors).map((m) => m.split("`")[1]), ["y"]); }); - test("on-fail data stays inside", () => { + test("catch data stays inside", () => { const body = `\ context { output x "x" @@ -403,7 +403,7 @@ step h by=llm { } step make by=llm { output x - on-fail { + catch { step log by=llm { output note } @@ -539,10 +539,10 @@ step h by=llm { assert.deepEqual(report.warnings.map((w) => w[0]), [7]); }); - test("phase in when but not in on-fail", () => { + test("phase in when but not in catch", () => { const {report} = runCheck('decide mode "Which?" by=llm {\n when a {\n phase p {\n step s by=llm\n }\n }\n}\n'); assert.deepEqual(report.errors, []); - assertError('step s by=llm {\n on-fail {\n phase p\n }\n}\n', "`phase` is not allowed inside `on-fail`", 4); + assertError('step s by=llm {\n catch {\n phase p\n }\n}\n', "`phase` is not allowed inside `catch`", 4); }); test("render shows gate implied outcomes", () => { @@ -608,11 +608,11 @@ step h by=llm { assert.deepEqual(report.errors, []); }); - test("depth warning and on-fail level", () => { + test("depth warning and catch level", () => { const nested = 'phase a {\n phase b {\n phase c {\n decide d "Q?" by=llm {\n when yes {\n step e by=llm\n }\n }\n }\n }\n}\n'; let {report} = runCheck(nested); assert.deepEqual(report.warnings.map((w) => w[0]), [7]); - const handled = "phase a {\n phase b {\n phase c {\n step d by=llm {\n on-fail {\n step e by=llm\n }\n }\n }\n }\n}\n"; + const handled = "phase a {\n phase b {\n phase c {\n step d by=llm {\n catch {\n step e by=llm\n }\n }\n }\n }\n}\n"; ({report} = runCheck(handled)); assert.deepEqual(report.warnings, []); }); diff --git a/build/skillflow/tests/snapshots.test.mjs b/build/skillflow/tests/snapshots.test.mjs index 92b6328..6ae6a88 100644 --- a/build/skillflow/tests/snapshots.test.mjs +++ b/build/skillflow/tests/snapshots.test.mjs @@ -31,14 +31,14 @@ const flows = { "end-with-children": 'skillflow 1.0\nend "x" {\n step y by=llm\n}\n', "when-twice": 'skillflow 1.0\ndecide d "Q?" by=llm {\n when a "one"\n when a {\n end "two"\n }\n}\n', "decide-no-fork": 'skillflow 1.0\ndecide scope "Project or user?" by=human {\n when project "the workspace folder"\n when user "the home folder"\n}\n', - "empty-on-fail": "skillflow 1.0\nstep x by=llm {\n on-fail\n}\n", + "empty-catch": "skillflow 1.0\nstep x by=llm {\n catch\n}\n", "unreachable-step": 'skillflow 1.0\nend "stop"\nstep x by=llm\n', "context-late": 'skillflow 1.0\nphase p {\n step a by=llm\n}\ncontext {\n invariant "x"\n}\n', - "on-fail-duplicate-name": 'skillflow 1.0\nstep a by=llm { on-fail { end "x" } }\nstep a by=llm\n', + "catch-duplicate-name": 'skillflow 1.0\nstep a by=llm { catch { end "x" } }\nstep a by=llm\n', "extra-argument": 'skillflow 1.0\nstep a by=llm "one" "two"\n', "number-prose": "skillflow 1.0\nstep a by=llm 42\n", "skill-not-name": "skillflow 1.0\nstep a by=llm skill=#true\n", - "two-on-fail": 'skillflow 1.0\nstep a by=llm {\n on-fail "x"\n on-fail "y"\n}\n', + "two-catch": 'skillflow 1.0\nstep a by=llm {\n catch "x"\n catch "y"\n}\n', "output-not-bare": 'skillflow 1.0\nstep a by=llm {\n output "two words"\n}\n', "header-version-stamp": 'skillflow 1.0 skill-version="0.3"\nstep x by=llm\n', "header-bad-stamp": "skillflow 1.0 skill-version=2\nstep x by=llm\n", diff --git a/build/skillflow/tests/snapshots/on-fail-duplicate-name.txt b/build/skillflow/tests/snapshots/catch-duplicate-name.txt similarity index 100% rename from build/skillflow/tests/snapshots/on-fail-duplicate-name.txt rename to build/skillflow/tests/snapshots/catch-duplicate-name.txt diff --git a/build/skillflow/tests/snapshots/empty-on-fail.txt b/build/skillflow/tests/snapshots/empty-catch.txt similarity index 75% rename from build/skillflow/tests/snapshots/empty-on-fail.txt rename to build/skillflow/tests/snapshots/empty-catch.txt index 1287e4f..378c086 100644 --- a/build/skillflow/tests/snapshots/empty-on-fail.txt +++ b/build/skillflow/tests/snapshots/empty-catch.txt @@ -3,5 +3,5 @@ FAIL /flow.kdl · 1 error tools: - invariants: - versions: skill-version - · skillflow-version - · installed SkillFlow - /flow.kdl:3: error: `on-fail` is empty (hint: say what happens: prose, steps, or end "reason") + /flow.kdl:3: error: `catch` is empty (hint: say what happens: prose, steps, or end "reason") next: this error is a draft gap: fix it by its hint, or run `validate --draft` while you sketch diff --git a/build/skillflow/tests/snapshots/example.model.json b/build/skillflow/tests/snapshots/example.model.json index 1e4fdce..187ae6c 100644 --- a/build/skillflow/tests/snapshots/example.model.json +++ b/build/skillflow/tests/snapshots/example.model.json @@ -97,9 +97,9 @@ "outputs": [ "changes" ], - "onfail": { + "catch": { "id": "n3", - "kind": "onfail", + "kind": "catch", "line": 20, "prose": "", "unclear": [], @@ -158,7 +158,7 @@ "highlights" ], "outputs": [], - "onfail": null + "catch": null } ], "ends": false @@ -206,7 +206,7 @@ "outputs": [ "draft" ], - "onfail": null + "catch": null }, { "id": "n11", @@ -222,7 +222,7 @@ "tools": [], "inputs": [], "outputs": [], - "onfail": null + "catch": null }, { "id": "n12", @@ -287,9 +287,9 @@ "outputs": [ "changelog" ], - "onfail": { + "catch": { "id": "n16", - "kind": "onfail", + "kind": "catch", "line": 63, "prose": "", "unclear": [], @@ -310,7 +310,7 @@ "tools": [], "inputs": [], "outputs": [], - "onfail": null + "catch": null }, { "id": "n18", @@ -337,9 +337,9 @@ "tools": [], "inputs": [], "outputs": [], - "onfail": { + "catch": { "id": "n20", - "kind": "onfail", + "kind": "catch", "line": 72, "prose": "The notes stay in CHANGELOG.md only.", "unclear": [], @@ -488,6 +488,6 @@ "node": "n12" } ], - "sourceText": "skillflow 1.0 skill-version=\"1.2\" skillflow-version=\"2026.11.20.1\"\n\ncontext \"Drafts release notes for a git tag and adds them to CHANGELOG.md.\" {\n\tinput tag \"the git tag to describe\"\n\tinput changelog \"the project's existing CHANGELOG.md\"\n\n\toutput changelog \"a new section in CHANGELOG.md\"\n\toutput \"a one-line summary in the chat\"\n\n\tinvariant by=human \"nothing is published without the user's approval\"\n\tinvariant by=code \"collect.sh stops the flow when the tag does not exist\"\n\tinvariant by=llm \"no commit is changed during the flow\"\n}\n\nphase gather \"Find what changed since the last tag.\" {\n\tstep collect-changes by=code file=\"scripts/collect.sh\" {\n\t\ttools gh /* the GitHub CLI */\n\t\toutput changes \"the commits and pull requests since the last tag\"\n\n\t\ton-fail {\n\t\t\tend \"report that the tag does not exist\"\n\t\t}\n\t}\n\n\tdecide size \"Is this a major release?\" by=llm {\n\t\toutput size \"major or regular\"\n\n\t\twhen major {\n\t\t\tstep ask-highlights by=llm \"Ask which changes come first.\" {\n\t\t\t\tinput highlights \"the changes that the user wants at the top\"\n\t\t\t}\n\t\t}\n\n\t\twhen regular \"The notes have no highlights.\"\n\t}\n}\n\nphase write ref=\"S2\" {\n\tstep draft by=llm \"\"\"\n\t\tGroup the changes **by type**:\n\t\t- features\n\t\t- fixes\n\n\t\tLeave out internal refactors. Revise the draft until the user approves it or stops.\n\t\t\"\"\" {\n\t\ttools (agent)editor (mcp)jira\n\t\toutput draft \"the release notes before approval\"\n\t}\n\n\tstep polish by=llm skill=style-guide \"Apply the style guide to the draft.\"\n\n\t// ? The skill does not say how many revision rounds are allowed (SKILL.md:24).\n\tgate approved \"Did the user approve the draft?\" {\n\t\twhen rejected {\n\t\t\tend \"the user stopped without approval\"\n\t\t}\n\t}\n\n\t// From here on the flow writes files.\n\tstep publish by=code {\n\t\toutput changelog\n\n\t\ton-fail {\n\t\t\tstep report-error by=llm \"Show the error and leave CHANGELOG.md unchanged.\"\n\t\t\tend \"CHANGELOG.md stays unchanged\"\n\t\t}\n\t}\n\n\t/- step tweet by=llm \"Post the notes.\"\n\n\tstep announce by=human #\"The user posts the \"What's new\" section to the team channel.\"# {\n\t\ton-fail \"The notes stay in CHANGELOG.md only.\"\n\t}\n}\n", + "sourceText": "skillflow 1.0 skill-version=\"1.2\" skillflow-version=\"2026.11.20.1\"\n\ncontext \"Drafts release notes for a git tag and adds them to CHANGELOG.md.\" {\n\tinput tag \"the git tag to describe\"\n\tinput changelog \"the project's existing CHANGELOG.md\"\n\n\toutput changelog \"a new section in CHANGELOG.md\"\n\toutput \"a one-line summary in the chat\"\n\n\tinvariant by=human \"nothing is published without the user's approval\"\n\tinvariant by=code \"collect.sh stops the flow when the tag does not exist\"\n\tinvariant by=llm \"no commit is changed during the flow\"\n}\n\nphase gather \"Find what changed since the last tag.\" {\n\tstep collect-changes by=code file=\"scripts/collect.sh\" {\n\t\ttools gh /* the GitHub CLI */\n\t\toutput changes \"the commits and pull requests since the last tag\"\n\n\t\tcatch {\n\t\t\tend \"report that the tag does not exist\"\n\t\t}\n\t}\n\n\tdecide size \"Is this a major release?\" by=llm {\n\t\toutput size \"major or regular\"\n\n\t\twhen major {\n\t\t\tstep ask-highlights by=llm \"Ask which changes come first.\" {\n\t\t\t\tinput highlights \"the changes that the user wants at the top\"\n\t\t\t}\n\t\t}\n\n\t\twhen regular \"The notes have no highlights.\"\n\t}\n}\n\nphase write ref=\"S2\" {\n\tstep draft by=llm \"\"\"\n\t\tGroup the changes **by type**:\n\t\t- features\n\t\t- fixes\n\n\t\tLeave out internal refactors. Revise the draft until the user approves it or stops.\n\t\t\"\"\" {\n\t\ttools (agent)editor (mcp)jira\n\t\toutput draft \"the release notes before approval\"\n\t}\n\n\tstep polish by=llm skill=style-guide \"Apply the style guide to the draft.\"\n\n\t// ? The skill does not say how many revision rounds are allowed (SKILL.md:24).\n\tgate approved \"Did the user approve the draft?\" {\n\t\twhen rejected {\n\t\t\tend \"the user stopped without approval\"\n\t\t}\n\t}\n\n\t// From here on the flow writes files.\n\tstep publish by=code {\n\t\toutput changelog\n\n\t\tcatch {\n\t\t\tstep report-error by=llm \"Show the error and leave CHANGELOG.md unchanged.\"\n\t\t\tend \"CHANGELOG.md stays unchanged\"\n\t\t}\n\t}\n\n\t/- step tweet by=llm \"Post the notes.\"\n\n\tstep announce by=human #\"The user posts the \"What's new\" section to the team channel.\"# {\n\t\tcatch \"The notes stay in CHANGELOG.md only.\"\n\t}\n}\n", "example": null } diff --git a/build/skillflow/tests/snapshots/header-plain.model.json b/build/skillflow/tests/snapshots/header-plain.model.json index a2437b8..f37091a 100644 --- a/build/skillflow/tests/snapshots/header-plain.model.json +++ b/build/skillflow/tests/snapshots/header-plain.model.json @@ -36,7 +36,7 @@ "tools": [], "inputs": [], "outputs": [], - "onfail": null + "catch": null } ], "data": {}, diff --git a/build/skillflow/tests/snapshots/header-version-stamp.model.json b/build/skillflow/tests/snapshots/header-version-stamp.model.json index 4694ab2..2f26ca5 100644 --- a/build/skillflow/tests/snapshots/header-version-stamp.model.json +++ b/build/skillflow/tests/snapshots/header-version-stamp.model.json @@ -36,7 +36,7 @@ "tools": [], "inputs": [], "outputs": [], - "onfail": null + "catch": null } ], "data": {}, diff --git a/build/skillflow/tests/snapshots/html-escape-prose.model.json b/build/skillflow/tests/snapshots/html-escape-prose.model.json index 8fa8c5b..3f8226f 100644 --- a/build/skillflow/tests/snapshots/html-escape-prose.model.json +++ b/build/skillflow/tests/snapshots/html-escape-prose.model.json @@ -36,7 +36,7 @@ "tools": [], "inputs": [], "outputs": [], - "onfail": null + "catch": null } ], "data": {}, diff --git a/build/skillflow/tests/snapshots/input-read.model.json b/build/skillflow/tests/snapshots/input-read.model.json index 9ac1a61..8ef4ce9 100644 --- a/build/skillflow/tests/snapshots/input-read.model.json +++ b/build/skillflow/tests/snapshots/input-read.model.json @@ -44,7 +44,7 @@ "ghost" ], "outputs": [], - "onfail": null + "catch": null } ], "data": { diff --git a/build/skillflow/tests/snapshots/two-on-fail.txt b/build/skillflow/tests/snapshots/two-catch.txt similarity index 70% rename from build/skillflow/tests/snapshots/two-on-fail.txt rename to build/skillflow/tests/snapshots/two-catch.txt index c2f7eeb..5e63885 100644 --- a/build/skillflow/tests/snapshots/two-on-fail.txt +++ b/build/skillflow/tests/snapshots/two-catch.txt @@ -3,4 +3,4 @@ FAIL /flow.kdl · 1 error tools: - invariants: - versions: skill-version - · skillflow-version - · installed SkillFlow - /flow.kdl:2: error: `step` has more than one `on-fail` (hint: merge them into one) + /flow.kdl:2: error: `step` has more than one `catch` (hint: merge them into one) diff --git a/build/skillflow/tests/snapshots/unicode-names.model.json b/build/skillflow/tests/snapshots/unicode-names.model.json index d45b740..bb3fcc8 100644 --- a/build/skillflow/tests/snapshots/unicode-names.model.json +++ b/build/skillflow/tests/snapshots/unicode-names.model.json @@ -38,7 +38,7 @@ "outputs": [ "данные" ], - "onfail": null + "catch": null }, { "id": "n2", @@ -56,7 +56,7 @@ "ответ" ], "outputs": [], - "onfail": null + "catch": null } ], "data": { diff --git a/build/skillflow/tests/viewer-pure.test.mjs b/build/skillflow/tests/viewer-pure.test.mjs index d899f51..c02190d 100644 --- a/build/skillflow/tests/viewer-pure.test.mjs +++ b/build/skillflow/tests/viewer-pure.test.mjs @@ -77,7 +77,7 @@ test("kdl: tokenize keeps every character and classes the tutorial flow, edge sy }); test("comments: hash, stamp, and readEnvelope on malformed and hostile envelopes", () => { - assert.deepEqual([sfComments.hash(M.sourceText), sfComments.hash(HOSTILE), sfComments.hash("")], ["botn70", "14qsx8h", "ztntfp"]); + assert.deepEqual([sfComments.hash(M.sourceText), sfComments.hash(HOSTILE), sfComments.hash("")], ["aa0002", "14qsx8h", "ztntfp"]); assert.deepEqual([sfComments.stamp("2026-11-08T21:31:00+02:00"), sfComments.stamp("garbage"), sfComments.stamp(5), sfComments.stamp("")], ["2026-11-08T19:31:00.000Z", "", "", ""]); assert.deepEqual([sfComments.readEnvelope(null), sfComments.readEnvelope("x"), sfComments.readEnvelope(42)], [null, null, null]); // version 0.3: a bare list diff --git a/build/skillflow/tests/viewer.browser.suite.mjs b/build/skillflow/tests/viewer.browser.suite.mjs index 6d74507..5796818 100644 --- a/build/skillflow/tests/viewer.browser.suite.mjs +++ b/build/skillflow/tests/viewer.browser.suite.mjs @@ -506,15 +506,15 @@ describe("viewer in Chrome", {skip: CHROME ? false : "no Chrome: set CHROME_BIN assert.deepEqual(got, {closed: true, focused: true, badge: "var(--fail)", filtered: 1, deleted: 1, restored: 2, draft: "keep me"}); }); - test("a one-line on-fail is a footnote until Failures is on; zooming out shows names, then phase tiles", async (t) => { + test("a one-line catch is a footnote until Failures is on; zooming out shows names, then phase tiles", async (t) => { if (unavailable) return t.skip(unavailable); - const flow = 'skillflow 1.0\n\nphase work {\n step run by=code "Run the full verification command: type-check, build, run every check, and report each failure with its file, its line, and the fix it needs." {\n on-fail "- Retry once, then continue."\n }\n step next by=llm "Go on."\n}\n'; + const flow = 'skillflow 1.0\n\nphase work {\n step run by=code "Run the full verification command: type-check, build, run every check, and report each failure with its file, its line, and the fix it needs." {\n catch "- Retry once, then continue."\n }\n step next by=llm "Go on."\n}\n'; const page = await (await fresh()).open(url(render(tmp, flow, "footnote"))); const got = await page.eval(`(() => { const q = (s) => document.querySelectorAll(s).length, out = {}; - out.off = { cards: q('.node.k-onfail'), note: document.querySelector('.nfail .ft').textContent }; + out.off = { cards: q('.node.k-catch'), note: document.querySelector('.nfail .ft').textContent }; const btn = [...document.querySelectorAll('.tools .tb, .tmenu .tb')].find((b) => b.textContent.startsWith('Failures')); btn.click(); - out.on = { cards: q('.node.k-onfail'), notes: q('.nfail'), pressed: btn.getAttribute('aria-pressed') }; + out.on = { cards: q('.node.k-catch'), notes: q('.nfail'), pressed: btn.getAttribute('aria-pressed') }; btn.click(); const vp = document.querySelector('.viewport'), canvas = document.querySelector('.canvas'), seen = [canvas.dataset.lod]; for (let i = 0; i < 12; i++) { vp.dispatchEvent(new KeyboardEvent('keydown', { key: '-', bubbles: true })); if (seen[seen.length - 1] !== canvas.dataset.lod) seen.push(canvas.dataset.lod); } @@ -527,22 +527,22 @@ describe("viewer in Chrome", {skip: CHROME ? false : "no Chrome: set CHROME_BIN assert.deepEqual(got, {off: {cards: 0, note: "Retry once, then continue."}, on: {cards: 1, notes: 0, pressed: "true"}, levels: ["full", "name", "phase"], far: {tile: "grid", card: "hidden"}, near: true}); }); - test("an on-fail that holds only an end is a stop footnote; Failures draws its on-fail and end cards", async (t) => { + test("a catch that holds only an end is a stop footnote; Failures draws its catch and end cards", async (t) => { if (unavailable) return t.skip(unavailable); - const flow = 'skillflow 1.0\n\nstep fetch by=code "Fetch the data." {\n on-fail "The network is down." {\n end "Report the outage."\n }\n}\nstep bare by=code "Check it." {\n on-fail {\n end\n }\n}\nstep next by=llm "Go on." {\n on-fail "Stop." {\n step tell by=llm "Tell the user."\n end "told"\n }\n}\n'; + const flow = 'skillflow 1.0\n\nstep fetch by=code "Fetch the data." {\n catch "The network is down." {\n end "Report the outage."\n }\n}\nstep bare by=code "Check it." {\n catch {\n end\n }\n}\nstep next by=llm "Go on." {\n catch "Stop." {\n step tell by=llm "Tell the user."\n end "told"\n }\n}\n'; const page = await (await fresh()).open(url(render(tmp, flow, "footnote-end"))); const got = await page.eval(`(() => { const q = (s) => document.querySelectorAll(s).length, out = {}; const notes = () => [...document.querySelectorAll('.nfail')].map((d) => d.querySelector('.how').textContent + ' | ' + d.querySelector('.ft').textContent); const btn = [...document.querySelectorAll('.tools .tb, .tmenu .tb')].find((b) => b.textContent.startsWith('Failures')); - out.off = { fails: q('.node.k-onfail'), ends: q('.node.k-end'), notes: notes(), count: btn.textContent }; + out.off = { fails: q('.node.k-catch'), ends: q('.node.k-end'), notes: notes(), count: btn.textContent }; btn.click(); - out.on = { fails: q('.node.k-onfail'), ends: q('.node.k-end'), notes: notes().length }; + out.on = { fails: q('.node.k-catch'), ends: q('.node.k-end'), notes: notes().length }; btn.click(); // the footnoted end still has a place: a link to it lands on its step out.check = Object.keys(window.skillflow.check()).filter((k) => k !== 'size' && window.skillflow.check()[k].length); return out; })()`); - assert.deepEqual(got, {off: {fails: 1, ends: 1, notes: ["■ on fail → stop | Report the outage.", "■ on fail → stop | the flow stops"], count: "Failures2"}, + assert.deepEqual(got, {off: {fails: 1, ends: 1, notes: ["■ catch → stop | Report the outage.", "■ catch → stop | the flow stops"], count: "Failures2"}, on: {fails: 3, ends: 3, notes: 0}, check: []}); }); @@ -743,7 +743,7 @@ describe("viewer in Chrome", {skip: CHROME ? false : "no Chrome: set CHROME_BIN } }); - const SCENARIO = 'skillflow 1.0\n\ndecide mode "Help or build?" by=llm {\n when help {\n step explain by=llm "Explain."\n end "answered"\n }\n when build "Go straight on."\n}\nstep draft by=llm "Draft it."\ngate approve "Approve the draft?"\nstep ship by=code "Ship." {\n on-fail "Stop and report." {\n end "shipping failed"\n }\n}\n'; + const SCENARIO = 'skillflow 1.0\n\ndecide mode "Help or build?" by=llm {\n when help {\n step explain by=llm "Explain."\n end "answered"\n }\n when build "Go straight on."\n}\nstep draft by=llm "Draft it."\ngate approve "Approve the draft?"\nstep ship by=code "Ship." {\n catch "Stop and report." {\n end "shipping failed"\n }\n}\n'; // the run, its summary, and the graph after each pick; a pick comes from the panel or from an outcome label in the graph const RUN = `(() => { const q = (s) => [...document.querySelectorAll(s)]; return { rows: q('.scl .sc-row').map((r) => r.querySelector('.sc-n').textContent + ':' + r.querySelector('.sc-t').textContent), @@ -755,7 +755,7 @@ describe("viewer in Chrome", {skip: CHROME ? false : "no Chrome: set CHROME_BIN test("Scenario: one run with a pick at each branch point; the graph numbers the run and dims the rest", async (t) => { if (unavailable) return t.skip(unavailable); const page = await (await fresh()).open(url(render(tmp, SCENARIO, "scenario"))); - // Failures on: the on-fail of ship draws its own lane, so the graph has its ok and on fail labels + // Failures on: the catch of ship draws its own lane, so the graph has its ok and catch labels await page.eval(`[...document.querySelectorAll('.tools .tb, .tmenu .tb')].find((b) => b.textContent.startsWith('Failures')).click(); document.querySelector('.scnbtn').click()`); // default: the first outcome that goes on; a step does not fail assert.deepEqual(await page.eval(RUN), {rows: ["1:mode", "2:draft", "3:approve", "4:ship", ":done"], facts: "4 steps · 1 asks you · reaches DONE", @@ -766,16 +766,16 @@ describe("viewer in Chrome", {skip: CHROME ? false : "no Chrome: set CHROME_BIN // the outcome label in the graph picks too await page.eval(`[...document.querySelectorAll('.elabel.alt')].find((l) => l.textContent === 'build').click()`); await page.eval(pick("revise")); - await page.eval(pick("on fail")); - assert.deepEqual(await page.eval(RUN), {rows: ["1:mode", "2:draft", "3:approve", ":revise", "4:ship", "5:on fail", ":end"], facts: "5 steps · 2 ask you · 1 repeat · stops on a failure", - nums: ["1", "2", "3", "4", "5"], picked: ["build", "approved", "revise", "on fail"], dimmed: ["explain"], lit: true}); + await page.eval(pick("catch")); + assert.deepEqual(await page.eval(RUN), {rows: ["1:mode", "2:draft", "3:approve", ":revise", "4:ship", "5:catch", ":end"], facts: "5 steps · 2 ask you · 1 repeat · stops on a failure", + nums: ["1", "2", "3", "4", "5"], picked: ["build", "approved", "revise", "catch"], dimmed: ["explain"], lit: true}); assert.equal(await page.eval(`document.querySelector('.sc-rep .sc-p').textContent`), "Redo the work before approve, then approve asks again."); - // with Failures off, an on-fail that holds only an end is a footnote of its step: the step's card stands for both numbers + // with Failures off, a catch that holds only an end is a footnote of its step: the step's card stands for both numbers const foot = await chrome.open(url(render(tmp, SCENARIO, "scenario-foot"))); - await foot.eval(`document.querySelector('.scnbtn').click(); ${pick("on fail")}`); + await foot.eval(`document.querySelector('.scnbtn').click(); ${pick("catch")}`); assert.deepEqual((await foot.eval(RUN)).nums, ["1", "2", "3", "4–5"]); // the choice keeps keyboard focus; arrows move it like any radio group - assert.equal(await page.eval(`document.activeElement.getAttribute('aria-checked') + ':' + document.activeElement.textContent`), "true:on fail"); + assert.equal(await page.eval(`document.activeElement.getAttribute('aria-checked') + ':' + document.activeElement.textContent`), "true:catch"); await page.eval(`document.activeElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft', bubbles: true }))`); assert.equal(await page.eval(`document.querySelector('.rs-facts').textContent`), "4 steps · 2 ask you · 1 repeat · reaches DONE"); // closing the scenario restores the graph @@ -787,7 +787,7 @@ describe("viewer in Chrome", {skip: CHROME ? false : "no Chrome: set CHROME_BIN test("Scenario address: #scenario=name=outcome opens that run; picks and closing keep the address in step", async (t) => { if (unavailable) return t.skip(unavailable); - // unknown names and outcomes are skipped; the step's on-fail is picked by the step's name + // unknown names and outcomes are skipped; the step's catch is picked by the step's name const page = await (await fresh()).open(url(render(tmp, SCENARIO, "scenario-link")) + "#scenario=mode=build,approve=nope,ghost=x,ship=fails"); const state = `({ hash: location.hash, pressed: document.querySelector('.scnbtn').getAttribute('aria-pressed'), end: document.querySelector('.rs-facts') && document.querySelector('.rs-facts').textContent })`; assert.deepEqual(await page.eval(state), {hash: "#scenario=mode=build,ship=fails", pressed: "true", end: "5 steps · 1 asks you · stops on a failure"}); @@ -1654,7 +1654,7 @@ describe("viewer in Chrome", {skip: CHROME ? false : "no Chrome: set CHROME_BIN test("a data highlight: cards that name the data in prose, counts by role, steps through the hits, and dims nothing when no card has it", async (t) => { if (unavailable) return t.skip(unavailable); - const flow = 'skillflow 1.0\n\ncontext "x" {\n\tinput feature "The goal."\n\tinput unused "Never named."\n}\n\nstep plan by=llm "Restate the feature goal." {\n\toutput report "r"\n}\nstep build by=code "Build it." {\n\tinput report\n\ton-fail "Stop."\n}\nstep tell by=llm "Say how the Feature went."\n'; + const flow = 'skillflow 1.0\n\ncontext "x" {\n\tinput feature "The goal."\n\tinput unused "Never named."\n}\n\nstep plan by=llm "Restate the feature goal." {\n\toutput report "r"\n}\nstep build by=code "Build it." {\n\tinput report\n\tcatch "Stop."\n}\nstep tell by=llm "Say how the Feature went."\n'; const page = await (await fresh()).open(url(render(tmp, flow, "data-mentions"))); await page.size(1280, 900); const got = await page.eval(`(() => { const name = (e) => e && e.querySelector('.nm') && e.querySelector('.nm').textContent; @@ -1973,7 +1973,7 @@ describe("viewer in Chrome", {skip: CHROME ? false : "no Chrome: set CHROME_BIN test("generated layouts: every end is outside every frame and reached, with no geometry problem", async (t) => { if (unavailable) return t.skip(unavailable); - // seeded flows with phases, branches, gates, on-fail paths, and ends in every position the grammar allows + // seeded flows with phases, branches, gates, catch paths, and ends in every position the grammar allows let seed = 20261110, id = 0; const random = () => ((seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0) / 2 ** 32); const pick = (list) => list[Math.floor(random() * list.length)]; @@ -1989,7 +1989,7 @@ describe("viewer in Chrome", {skip: CHROME ? false : "no Chrome: set CHROME_BIN if (kind === "step") { if (random() > 0.3) return `step ${name} by=llm\n`; const handler = (random() < 0.5 ? `step h${name} by=human\n` : "") + (random() < 0.6 ? end() : ""); - return `step ${name} by=code {\n on-fail "Recover." {\n${handler} }\n}\n`; + return `step ${name} by=code {\n catch "Recover." {\n${handler} }\n}\n`; } const outcomes = kind === "gate" ? pick([["rejected"], ["approved", "rejected"], ["rejected", "later"]]) : pick([["yes"], ["a", "b"], ["a", "b", "c"], ["a", "b", "c", "d"]]); // an outcome with nothing in it carries prose: a bare `when` is an error diff --git a/site/build.mjs b/site/build.mjs index fbb9056..2362ad0 100644 --- a/site/build.mjs +++ b/site/build.mjs @@ -40,10 +40,11 @@ const run = (...argv) => spawnSync(process.execPath, [cli, ...argv], {encoding: const examples = readdirSync(join(SITE, "examples")).filter((name) => name.endsWith(".kdl")).sort(); const lint = {}; for (const name of examples) { - const result = run("lint", join(SITE, "examples", name)), lines = result.stdout.split("\n"); + // run from examples/, so lint prints the file name, not a path + const result = spawnSync(process.execPath, [cli, "lint", name], {encoding: "utf8", cwd: join(SITE, "examples")}), lines = result.stdout.split("\n"); if (result.status !== 0 || !/^unchanged /.test(lines[0]) || !/^OK [^·]*$/.test(lines[1] ?? "")) fail(`example ${name} does not pass lint:\n${result.stdout}${result.stderr}`); - // the Modes section shows the real output of lint: the format line, the OK line, its counts, tools, and invariants (not the versions, which change with each release), with the file name only - lint[name] = lines.slice(0, 5).join("\n").replaceAll(join(SITE, "examples", name), name); + // the Modes section shows the real output of lint: the format line, the OK line, its counts, tools, and invariants (not the versions, which change with each release) + lint[name] = lines.slice(0, 5).join("\n"); } // 2. the single sources @@ -73,7 +74,7 @@ function example(name) { } return models.get(name); } -const children = (node) => [...(node.children ?? []), ...(node.whens ?? []).flatMap((branch) => branch.children), ...(node.onfail?.children ?? [])]; +const children = (node) => [...(node.children ?? []), ...(node.whens ?? []).flatMap((branch) => branch.children), ...(node.catch?.children ?? [])]; const walk = (nodes) => nodes.flatMap((node) => [node, ...walk(children(node))]); /** The highlighted lines of an example. With `pair`, a line that starts a node or an invariant carries its name and executor; @@ -104,10 +105,10 @@ function graphHtml(name, pair, marks) { const end = (node, cls = "ep") => `${e(node.text || "end")}`; const fork = (branches) => `
` + branches.map((b) => `
${ED}${e(b.outcome)}${block(b.children ?? [])}${b.ends ? "" : ED}
`).join("") + "
"; - const failRow = (onfail) => { - const ends = onfail.children.filter((kid) => kid.kind === "end"), rest = onfail.children.filter((kid) => kid.kind !== "end"); + const failRow = (caught) => { + const ends = caught.children.filter((kid) => kid.kind === "end"), rest = caught.children.filter((kid) => kid.kind !== "end"); return (rest.length ? `
${block(rest)}
` : "") + - `fail ${ends.length ? ends.map((kid) => end(kid, "ep fail")).join("") : `${e(onfail.prose || "continues")}`}`; + `fail ${ends.length ? ends.map((kid) => end(kid, "ep fail")).join("") : `${e(caught.prose || "continues")}`}`; }; const one = (node) => { // the spaces keep the words apart in the accessible name; a flex container does not draw them @@ -116,10 +117,10 @@ function graphHtml(name, pair, marks) { switch (node.kind) { case "phase": return `
${pair ? card(node, "a", `phase ${e(node.name)}`) : `
phase ${e(node.name)}
`}
${block(node.children)}
`; case "step": { - // an on-fail that only ends the flow is a footnote of its card, as on the flow page, so the line of the flow stays whole - const stop = node.onfail && node.onfail.children.length && node.onfail.children.every((kid) => kid.kind === "end"); - const foot = stop ? ` fail ${node.onfail.children.map((kid) => end(kid, "ep fail")).join("")}` : ""; - return card(node, `n ${node.by}`, head + foot) + (node.onfail && !stop ? failRow(node.onfail) : ""); + // a catch that only ends the flow is a footnote of its card, as on the flow page, so the line of the flow stays whole + const stop = node.catch && node.catch.children.length && node.catch.children.every((kid) => kid.kind === "end"); + const foot = stop ? ` fail ${node.catch.children.map((kid) => end(kid, "ep fail")).join("")}` : ""; + return card(node, `n ${node.by}`, head + foot) + (node.catch && !stop ? failRow(node.catch) : ""); } case "decide": return card(node, `n ${node.by} dec`, head + q) + ED + fork([...node.whens, ...(node.implied ?? [])]); case "gate": { diff --git a/site/examples/on-fail.kdl b/site/examples/catch.kdl similarity index 88% rename from site/examples/on-fail.kdl rename to site/examples/catch.kdl index 9e17510..43ace7e 100644 --- a/site/examples/on-fail.kdl +++ b/site/examples/catch.kdl @@ -1,7 +1,7 @@ skillflow 1.0 step collect-changes by=code { - on-fail { + catch { end "the tag does not exist" } } diff --git a/site/examples/release-notes.kdl b/site/examples/release-notes.kdl index 41161f3..decfe83 100644 --- a/site/examples/release-notes.kdl +++ b/site/examples/release-notes.kdl @@ -12,7 +12,7 @@ phase gather { step collect-changes by=code "Run collect.sh for the tag." { output changes "the commits since the last tag" - on-fail { + catch { end "the tag does not exist" } } diff --git a/site/examples/why.kdl b/site/examples/why.kdl index 19c925b..351e971 100644 --- a/site/examples/why.kdl +++ b/site/examples/why.kdl @@ -1,7 +1,7 @@ skillflow 1.0 step collect-changes by=code "Run collect.sh for the tag." { - on-fail { + catch { end "the tag does not exist" } } diff --git a/site/index.html b/site/index.html index af2f572..e8595dd 100644 --- a/site/index.html +++ b/site/index.html @@ -5,7 +5,7 @@ SkillFlow - +