Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/skillflow/evals/fixtures/expense-report.kdl.fixture
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
62 changes: 31 additions & 31 deletions build/skillflow/tests/data-paths.cases.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -327,21 +327,21 @@ step u by=llm {
}
step s by=code {
input req
on-fail {
catch {
step h by=llm {
input req
}
}
}
`,
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"
}
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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"
}
}
Expand All @@ -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
}
Expand All @@ -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
}
}
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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"
}
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions build/skillflow/tests/data-paths.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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"]);
Expand Down
12 changes: 6 additions & 6 deletions build/skillflow/tests/edge-inputs.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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/);
Expand Down
10 changes: 5 additions & 5 deletions build/skillflow/tests/editor-pure.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: []});
});
Expand All @@ -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 {
Expand Down Expand Up @@ -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]]});
Expand Down
4 changes: 2 additions & 2 deletions build/skillflow/tests/fixtures/release-notes.fixture
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions build/skillflow/tests/fmt.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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", () => {
Expand Down
4 changes: 2 additions & 2 deletions build/skillflow/tests/generated-paths.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand All @@ -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"]]);
Expand Down
Loading