@skillstech/thunderlang 0.5.7 → 0.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ # 0.5.9
2
+
3
+ **Language: redirects say where the person goes.** A redirect reads "Sends the person to /login" (or "the Google
4
+ auth URL", "the dashboard page") instead of "Gives back the result of redirect", and has its own step kind,
5
+ `redirect` (mark ↪), in `THUNDER_VISUAL.does`. Fastify and Express `redirect`, `Response`/`NextResponse.redirect`,
6
+ Flask/Django/Next `redirect(...)`, `HttpResponseRedirect`, FastAPI `RedirectResponse`, Laravel `redirect()->route()`.
7
+ Found by OpenThunder on its own sign-in route.
8
+
9
+ # 0.5.8
10
+
11
+ **Language: Details is a fact sheet.** `readLevel(model, 'details', id)` now gives what you need to check before you
12
+ trust or change an action or rule, computed by the compiler: `stops` (every way it can stop, the error, the message
13
+ people see, and the answers that lead there), `givesBack`, `changes` (data it changes, saves, or sends), `inputs`
14
+ (and the lines where each is used), `reliesOn` (each rule or action it uses, summarized), for rules `answers` (in
15
+ words) and `limits` (exact ranges found by running the rule, e.g. 0 or less: No fee, 1 to 7: Small fee, 8 or more:
16
+ Big fee), and `openQuestions` (what the code cannot tell you). The step list stays as `steps`.
17
+
18
+ **Language: web handlers read the way people think about them.**
19
+ - An HTTP error response is a **Stop** with its status and message: Fastify `reply.code(400).send({ error })`,
20
+ Express `res.status(404).json({ message })`, `new Response(..., { status })`, FastAPI `JSONResponse(...,
21
+ status_code=...)`, Flask `return ..., 400` ("Fails with 400 Bad Request: \"slug is required.\"").
22
+ - Facts a handler unpacks from the request (`const { slug, name } = request.body`, `req.params`, `request.json()`)
23
+ are what goes in; framework plumbing (`request`, `reply`, a database session) is not.
24
+ - A one-line `if (x) return reply.code(400).send({ ... })` keeps its return; the object's braces are not a block
25
+ (found by OpenThunder).
26
+ - `if (!slug)` reads "If slug is not set" (asked as "Is slug set?") instead of "If not slug".
27
+
1
28
  # 0.5.7
2
29
 
3
30
  **Language: the five reading levels.** Every Thunder view now offers the same five levels, in this order, with
package/dist/core.cjs CHANGED
@@ -2188,6 +2188,33 @@ function sayChain(value) {
2188
2188
  }
2189
2189
  return hit ? hit.c.say(words2(src.split(".").pop().replace(/^#/, ""))) : null;
2190
2190
  }
2191
+ var HTTP_STATUS = { 400: "Bad Request", 401: "Unauthorized", 402: "Payment Required", 403: "Forbidden", 404: "Not Found", 405: "Method Not Allowed", 409: "Conflict", 410: "Gone", 413: "Payload Too Large", 415: "Unsupported Media Type", 422: "Unprocessable Content", 429: "Too Many Requests", 500: "Internal Server Error", 501: "Not Implemented", 502: "Bad Gateway", 503: "Service Unavailable", 504: "Gateway Timeout" };
2192
+ function httpErrorOf(head) {
2193
+ const expr = head.replace(/^return\s+/, "").replace(/^await\s+/, "").replace(/;\s*$/, "").trim();
2194
+ let m = expr.match(/^(?:reply|res|response|resp|ctx\.response)\s*\.\s*(?:code|status|statusCode)\s*\(\s*([45]\d\d)\s*\)/) || expr.match(/^(?:new\s+)?(?:Response|NextResponse(?:\.json)?|HttpResponse|JSONResponse|PlainTextResponse|Response\.json)\s*\(.*\bstatus(?:_code)?\s*[:=]\s*([45]\d\d)\b/) || (/^return\b/.test(head) ? expr.match(/^.+,\s*([45]\d\d)\s*$/) : null);
2195
+ if (!m) return null;
2196
+ const status = Number(m[1]);
2197
+ const name = HTTP_STATUS[status] ?? (status >= 500 ? "Server Error" : "Client Error");
2198
+ const msg = (expr.match(/\b(?:error|message|detail|msg)\s*[:=]\s*["'`]([^"'`]{1,80})["'`]/) || expr.match(/\.(?:send|json|end)\(\s*["'`]([^"'`]{1,80})["'`]/) || [])[1];
2199
+ return { kind: "fail", says: `Fails with ${status} ${name}${msg ? `: "${msg}"` : ""}`, error: `${status} ${name}`, ...msg ? { message: msg } : {}, status };
2200
+ }
2201
+ function redirectTarget(arg) {
2202
+ const a = String(arg || "").trim().replace(/^(?:url|to|location|redirect_to)\s*=\s*/, "");
2203
+ let m;
2204
+ if (m = a.match(/^(?:new\s+URL\(\s*)?["'`](\/[^"'`$?#]*|https?:\/\/[^"'`$/?#]+[^"'`$?#]*)/)) return m[1];
2205
+ if (m = a.match(/^`\$\{\s*([A-Za-z_][\w.]*)\s*\}/)) return `the ${words2(m[1].split(".").pop()).replace(/\burl\b/i, "URL")}`;
2206
+ if (m = a.match(/\b(?:url_for|reverse|route|url)\(\s*["']([\w.:-]+)["']/)) return `the ${words2(m[1].split(/[.:]/).pop())} page`;
2207
+ if (m = a.match(/^([A-Za-z_][\w.]*)$/)) return `the ${words2(m[1].split(".").pop()).replace(/\burl\b/i, "URL")}`;
2208
+ return "another page";
2209
+ }
2210
+ function redirectOf(head) {
2211
+ const isReturn = /^return\b/.test(head);
2212
+ const expr = head.replace(/^return\s+/, "").replace(/^await\s+/, "").replace(/;\s*$/, "").trim();
2213
+ let m = expr.match(/^(?:reply|res|response|resp|ctx|c)\s*\.\s*redirect\s*\(\s*(?:\d{3}\s*,\s*)?(.*)\)\s*$/) || expr.match(/^(?:Response|NextResponse)\s*\.\s*redirect\s*\(\s*(.*?)\s*(?:,\s*\d{3}\s*)?\)\s*$/) || expr.match(/^(?:HttpResponseRedirect|HttpResponsePermanentRedirect|RedirectResponse|redirect)\s*\(\s*(.*?)\s*(?:,\s*(?:\d{3}|status(?:_code)?\s*=\s*\d{3}|permanent\s*=\s*\w+)\s*)?\)\s*$/) || expr.match(/^redirect\(\s*\)\s*->\s*(route\(.*\))\s*$/);
2214
+ if (!m) return null;
2215
+ const to = redirectTarget(m[1]);
2216
+ return { kind: isReturn ? "return" : "call", says: `Sends the person to ${to}`, redirect: to };
2217
+ }
2191
2218
  function classifyStatement(raw, { inner = 0 } = {}) {
2192
2219
  const text = String(raw).trim();
2193
2220
  const head = text.split("\n")[0].trim().replace(/\(\s*([\w$#.]+)\s+as\s+[^)]+\)/g, "$1").replace(/([\w$\])])!(?=[.(\[])/g, "$1").replace(/\?\.(?=[\w(\[])/g, ".").replace(/\.\(/g, "(").replace(/^\(\*+(self|this)\)\./, "$1.").replace(/\(\(\s*[A-Z][\w.<>\[\]?, ]*\s*\)\s*([\w$.]+)\s*\)/g, "$1").replace(/^(\w[\w.]*\s*=\s*)\(\s*[A-Z][\w.<>\[\]?]*\s*\)\s*/, "$1");
@@ -2212,6 +2239,10 @@ function classifyStatement(raw, { inner = 0 } = {}) {
2212
2239
  const said = name && /^[a-z]/.test(name) ? `the error made by ${words2(name)}` : name;
2213
2240
  return { kind: "fail", says: `Fails${said ? ` with ${said}` : ""}${msg ? `: "${msg}"` : ""}`, code, ...name ? { error: name } : {}, ...msg ? { message: msg } : {} };
2214
2241
  }
2242
+ const httpFail = httpErrorOf(head);
2243
+ if (httpFail) return { ...httpFail, code };
2244
+ const redirect = redirectOf(head);
2245
+ if (redirect) return { ...redirect, code };
2215
2246
  if (m = head.match(/^return\b\s*(.*)$/)) {
2216
2247
  const expr = stripTail(m[1]);
2217
2248
  if (!expr) return { kind: "return", says: "Stops here", code };
@@ -2438,7 +2469,11 @@ function stepsFrom(statements) {
2438
2469
  continue;
2439
2470
  }
2440
2471
  const step = { ...classifyStatement(s.text, { inner: s.inner || 0 }), line: s.line, span: spanOf(s) };
2441
- if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
2472
+ if (step.inline && !/^\{/.test(step.inline.trim())) {
2473
+ const kid = classifyStatement(step.inline);
2474
+ step.children = [{ ...kid, line: s.line, span: spanOf(s) }];
2475
+ delete step.inline;
2476
+ } else if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
2442
2477
  const kids2 = stepsFrom(s.children).steps;
2443
2478
  if (kids2.length) {
2444
2479
  step.children = kids2;
@@ -3470,7 +3505,7 @@ function notesSummary(ast) {
3470
3505
  byLens
3471
3506
  };
3472
3507
  }
3473
- var COMPILER_VERSION = "0.5.7";
3508
+ var COMPILER_VERSION = "0.5.9";
3474
3509
  var PROOF_SCHEMA_VERSION = "0.1.0";
3475
3510
  var SOURCE_PRODUCT = "skillstech-compiler";
3476
3511
  function buildContractGraph(ast, generatedAt) {
@@ -6782,7 +6817,8 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
6782
6817
  for (const st of r.steps) {
6783
6818
  if (st.kind !== "branch" || !st.cond) continue;
6784
6819
  const bareProperty = /^(not\s+|!)?(?:self\.|this\.)?\w+\.\w+(\(\))?$/.test(st.cond.trim()) && !/\./.test(st.says.replace(/\(\d+ steps? inside\)$/, ""));
6785
- const cond = bareProperty ? null : toThunderCondition(st.cond, names);
6820
+ const bareName = /^(not\s+|!)?(?:self\.|this\.)?\w+$/.test(st.cond.trim()) && /\bis (not )?set\b/.test(st.says);
6821
+ const cond = bareProperty || bareName ? null : toThunderCondition(st.cond, names);
6786
6822
  if (cond) st.says = st.says.replace(/^If .*?( \(\d+ steps? inside\))?$/, (_m, inner) => `If ${st.negate ? "not: " : ""}${plainEnums(sayCondition(cond)).replace(/ is not ""/g, " is not empty").replace(/ is ""/g, " is empty")}${inner || ""}`);
6787
6823
  delete st.cond;
6788
6824
  delete st.negate;
@@ -7783,7 +7819,7 @@ var FORMS = [
7783
7819
  var LEVELS = [
7784
7820
  { id: "big-picture", name: "Big Picture", question: "What is it, and what can it do?", shows: "The Things, what each knows and can do, its doors (actions), its rules, and its data. For one action or rule: what you give it, what you get back, and what it uses.", form: "picture" },
7785
7821
  { id: "flow", name: "Flow", question: "How does it go?", shows: "One action or rule as a path: questions with Yes and No, repeats, the Stops, what happens if something goes wrong, and what always happens at the end.", form: "picture" },
7786
- { id: "details", name: "Details", question: "Exactly what happens, and how sure is Thunder?", shows: "Every step with its line, what goes in and comes out, what it uses and what uses it, anything Thunder could not explain, and a rule you can try.", form: "picture" },
7822
+ { id: "details", name: "Details", question: "Exactly what happens, and how sure is Thunder?", shows: "A fact sheet: every way it can end (each Stop with its message, and what it gives back), the answers that lead there, what it changes, what goes in, what it relies on, a rule's answers and exact limits, and what the code cannot tell you.", form: "picture" },
7787
7823
  { id: "text", name: "Text", question: "What does it say, in words?", shows: "Thunder Text: the same meaning in structured words, for reading closely, reviewing a change, and keeping a copy.", form: "words" },
7788
7824
  { id: "original", name: "Original", question: "Which code says so?", shows: "The exact lines in the original language that Thunder read. The evidence, one click away.", form: "evidence" }
7789
7825
  ];
@@ -7962,6 +7998,7 @@ var DOES = {
7962
7998
  calculate: { label: "Works out", mark: "=", color: "fact" },
7963
7999
  save: { label: "Saves", mark: "\u2913", color: "outcome" },
7964
8000
  send: { label: "Tells someone", mark: "\u2709", color: "outcome" },
8001
+ redirect: { label: "Sends the person to", mark: "\u21AA", color: "outcome" },
7965
8002
  ask: { label: "Asks another part", mark: "\u21C4", color: "outcome" },
7966
8003
  repeat: { label: "For each", mark: "\u21BB", color: "structure" },
7967
8004
  answer: { label: "Gives back", mark: "\u21E5", color: "outcome" },
@@ -8338,6 +8375,7 @@ function stepDoes(step) {
8338
8375
  const s = step.says || "", c = step.callee || "";
8339
8376
  if (step.restates || step.kind === "other") return "code";
8340
8377
  if (step.kind === "fail") return "stop";
8378
+ if (step.redirect) return "redirect";
8341
8379
  if (step.kind === "loop") return "repeat";
8342
8380
  if (step.kind === "return") return "answer";
8343
8381
  if (step.kind === "check") return "check";
@@ -8495,6 +8533,27 @@ function flowOf(steps, { start = "Start", memberIndex = /* @__PURE__ */ new Map(
8495
8533
  return { nodes: nodes2, edges, blocks: blocks2 };
8496
8534
  }
8497
8535
  var idOf = (...parts) => parts.join("#").replace(/\s+/g, "");
8536
+ function youGiveOf(item2) {
8537
+ const given = (item2.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name) && !p.plumbing).map((p) => words5(p.name));
8538
+ const codes = [];
8539
+ const walk = (steps) => {
8540
+ for (const s of steps || []) {
8541
+ if (s.code) codes.push(s.code);
8542
+ walk(s.children);
8543
+ walk(s.otherwise);
8544
+ }
8545
+ };
8546
+ walk(item2.steps);
8547
+ for (const c of codes) {
8548
+ const m = c.match(/^(?:const|let|var)\s*\{([^}]+)\}\s*=\s*\(?\s*(?:await\s+)?(?:req|request|ctx\.request|c\.req|event)\s*\.\s*(?:body|query|params|json\(\))/);
8549
+ if (!m) continue;
8550
+ for (const part of m[1].split(",")) {
8551
+ const name = part.split(/[:=]/)[0].replace(/^\.\.\./, "").trim();
8552
+ if (/^[A-Za-z_$][\w$]*$/.test(name) && !given.includes(words5(name))) given.push(words5(name));
8553
+ }
8554
+ }
8555
+ return given;
8556
+ }
8498
8557
  function thunderModel(files, { name = "app" } = {}) {
8499
8558
  const things = [], members = [], links = [], unknowns = [], fileInfo = [];
8500
8559
  for (const f of files) {
@@ -8550,7 +8609,7 @@ function thunderModel(files, { name = "app" } = {}) {
8550
8609
  lines: [item2.line, bodyEnd2],
8551
8610
  ...item2.doc ? { doc: item2.doc } : {},
8552
8611
  ...item2.route ? { route: `${item2.route.method} ${item2.route.path}`.trim() } : {},
8553
- youGive: (item2.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name)).map((p) => words5(p.name)),
8612
+ youGive: youGiveOf(item2),
8554
8613
  ...item2.returns && kind !== "rule" ? { youGetBack: kindWords(item2.returns) ?? item2.returns } : {},
8555
8614
  ...rule ? { rule, question: rule.question } : {},
8556
8615
  // A yes/no rule is named as a question ("Can borrow?"); a rule with named answers is not ("Late fee").
@@ -8672,6 +8731,89 @@ function detailSteps(flow) {
8672
8731
  walk(flow.blocks, 0, null);
8673
8732
  return out;
8674
8733
  }
8734
+ var CHANGES = /^(Sets|Adds|Removes|Subtracts|Clears|Marks|Saves|Deletes|Updates|Appends|Increases|Decreases|Sends|Records|Stores|Writes)\b/;
8735
+ function pathsOf(flow) {
8736
+ const byId = new Map(flow.nodes.map((n) => [n.id, n]));
8737
+ const out = [];
8738
+ const walk = (blocks2, when) => {
8739
+ for (const b of blocks2 || []) {
8740
+ const n = byId.get(b.id);
8741
+ if (n && n.kind !== "start") out.push({ node: n, when });
8742
+ const q = n?.text ?? "";
8743
+ walk(b.yes, [...when, { question: q, answer: "Yes" }]);
8744
+ walk(b.no, [...when, { question: q, answer: "No" }]);
8745
+ walk(b.each, [...when, { question: q, answer: "For each" }]);
8746
+ walk(b.body, when);
8747
+ for (const h of b.handlers || []) {
8748
+ const hn = byId.get(h.id);
8749
+ walk(h.blocks, [...when, { question: (hn?.text ?? "").replace(/\?$/, ""), answer: "Yes" }]);
8750
+ }
8751
+ if (b.always) walk(b.always.blocks, when);
8752
+ }
8753
+ };
8754
+ walk(flow.blocks, []);
8755
+ return out;
8756
+ }
8757
+ function ruleAnswers(rule) {
8758
+ const zero = Object.fromEntries(rule.inputs.map((i) => [i.id, i.kind === "yesno" ? true : 0]));
8759
+ let explained;
8760
+ try {
8761
+ explained = explainPlain(rule, zero);
8762
+ } catch {
8763
+ return null;
8764
+ }
8765
+ const answers = explained.rules.map((r) => ({ answer: answerWords(r.outcome), when: r.checks.map((c) => c.text).join(r.join === "any" ? " or " : " and ") }));
8766
+ if (rule.otherwise) answers.push({ answer: answerWords(rule.otherwise), when: "otherwise" });
8767
+ return answers;
8768
+ }
8769
+ function ruleRanges(rule) {
8770
+ if (rule.inputs.length !== 1 || rule.inputs[0].kind === "yesno") return null;
8771
+ const id2 = rule.inputs[0].id;
8772
+ const limits = rule.rules.flatMap((r) => r.conditions).filter((c) => c.input === id2 && typeof c.value === "number").map((c) => c.value);
8773
+ if (!limits.length || !limits.every(Number.isInteger)) return null;
8774
+ const lo = Math.min(...limits) - 1, hi = Math.max(...limits) + 1;
8775
+ const ranges = [];
8776
+ for (let v = lo; v <= hi; v++) {
8777
+ let outcome;
8778
+ try {
8779
+ outcome = answerWords(explainPlain(rule, { [id2]: v }).outcome);
8780
+ } catch {
8781
+ return null;
8782
+ }
8783
+ const last = ranges.at(-1);
8784
+ if (last && last.answer === outcome) last.to = v;
8785
+ else ranges.push({ from: v, to: v, answer: outcome });
8786
+ }
8787
+ ranges[0].from = null;
8788
+ ranges.at(-1).to = null;
8789
+ return { fact: rule.inputs[0].label.replace(/^the /, ""), ranges };
8790
+ }
8791
+ function detailsFacts(model, member) {
8792
+ const paths = pathsOf(member.flow);
8793
+ const memberOf = (id2) => model.members.find((m) => m.id === id2);
8794
+ const inputs = member.youGive.map((label) => {
8795
+ const re = new RegExp(`\\b${label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "i");
8796
+ const lines = [...new Set(paths.filter((p) => re.test(p.node.text) && p.node.line).map((p) => p.node.line))];
8797
+ return { label, lines };
8798
+ });
8799
+ const changes = paths.filter((p) => p.node.kind !== "decision" && p.node.kind !== "stop" && p.node.kind !== "end" && (p.node.does === "save" || p.node.does === "send" || CHANGES.test(p.node.text) && /'s\b|\bto\b|\bfrom\b/.test(p.node.text))).map((p) => ({ text: p.node.text, line: p.node.line ?? null, does: p.node.does, when: p.when }));
8800
+ const stops = paths.filter((p) => p.node.kind === "stop").map((p) => {
8801
+ const m = p.node.text.match(/^Stop:\s*([^:]+?)(?::\s*"(.*)")?$/);
8802
+ return { error: m ? m[1].trim() : p.node.text, ...m?.[2] ? { message: m[2] } : {}, line: p.node.line ?? null, when: p.when };
8803
+ });
8804
+ const givesBack = paths.filter((p) => p.node.kind === "end" || p.node.answer).map((p) => ({ text: p.node.answer ? answerWords(p.node.text) : p.node.text, line: p.node.line ?? null, when: p.node.otherwise ? [{ question: "none of the above", answer: "Otherwise" }] : p.when }));
8805
+ const reliesOn = model.links.filter((l) => l.from === member.id).map((l) => memberOf(l.to)).filter(Boolean).map((t) => {
8806
+ const answers2 = t.rule ? ruleAnswers(t.rule) : null;
8807
+ const flowAnswers = [...new Set(t.flow.nodes.filter((n) => n.answer).map((n) => n.text))];
8808
+ const list = answers2 ? answers2.map((a) => a.answer) : flowAnswers;
8809
+ const says = list.length ? `Answers ${list.join(", ").replace(/, ([^,]*)$/, list.length > 2 ? ", or $1" : " or $1")}.` : t.youGetBack ? `Gives back ${t.youGetBack}.` : t.flow.nodes.some((n) => n.kind === "stop") ? `Can stop with ${t.flow.nodes.filter((n) => n.kind === "stop").map((n) => n.text.replace(/^Stop:\s*/, "").split(":")[0]).join(", ")}.` : `${t.flow.nodes.filter((n) => n.kind !== "start").length} steps.`;
8810
+ return { id: t.id, label: t.label + (t.yesNo ? "?" : ""), symbol: SYMBOL_OF[t.kind], says };
8811
+ });
8812
+ const answers = member.rule ? ruleAnswers(member.rule) : null;
8813
+ const limits = member.rule ? ruleRanges(member.rule) : null;
8814
+ const openQuestions = (member.rule?.needsReview ?? []).filter((q) => !/^No examples yet/.test(q));
8815
+ return { inputs, changes, stops, givesBack, reliesOn, ...answers ? { answers } : {}, ...limits ? { limits } : {}, openQuestions };
8816
+ }
8675
8817
  function readLevel(model, level, focus) {
8676
8818
  const lv = LEVELS.find((l) => l.id === level);
8677
8819
  if (!lv) throw new Error(`Unknown reading level "${level}". Use one of: ${LEVELS.map((l) => l.id).join(", ")}.`);
@@ -8725,6 +8867,8 @@ function readLevel(model, level, focus) {
8725
8867
  ...about,
8726
8868
  youGive: member.youGive,
8727
8869
  ...member.youGetBack ? { youGetBack: member.youGetBack } : {},
8870
+ ...member.doc ? { doc: member.doc } : {},
8871
+ ...detailsFacts(model, member),
8728
8872
  steps,
8729
8873
  notExplained: steps.filter((s) => s.notExplained).length,
8730
8874
  uses,
package/dist/index.cjs CHANGED
@@ -2423,7 +2423,7 @@ function notesSummary(ast) {
2423
2423
  byLens
2424
2424
  };
2425
2425
  }
2426
- var COMPILER_VERSION = "0.5.7";
2426
+ var COMPILER_VERSION = "0.5.9";
2427
2427
  var PROOF_SCHEMA_VERSION = "0.1.0";
2428
2428
  var SOURCE_PRODUCT = "skillstech-compiler";
2429
2429
  function buildContractGraph(ast, generatedAt) {
@@ -9399,6 +9399,33 @@ function sayChain(value) {
9399
9399
  }
9400
9400
  return hit ? hit.c.say(words2(src.split(".").pop().replace(/^#/, ""))) : null;
9401
9401
  }
9402
+ var HTTP_STATUS = { 400: "Bad Request", 401: "Unauthorized", 402: "Payment Required", 403: "Forbidden", 404: "Not Found", 405: "Method Not Allowed", 409: "Conflict", 410: "Gone", 413: "Payload Too Large", 415: "Unsupported Media Type", 422: "Unprocessable Content", 429: "Too Many Requests", 500: "Internal Server Error", 501: "Not Implemented", 502: "Bad Gateway", 503: "Service Unavailable", 504: "Gateway Timeout" };
9403
+ function httpErrorOf(head) {
9404
+ const expr = head.replace(/^return\s+/, "").replace(/^await\s+/, "").replace(/;\s*$/, "").trim();
9405
+ let m = expr.match(/^(?:reply|res|response|resp|ctx\.response)\s*\.\s*(?:code|status|statusCode)\s*\(\s*([45]\d\d)\s*\)/) || expr.match(/^(?:new\s+)?(?:Response|NextResponse(?:\.json)?|HttpResponse|JSONResponse|PlainTextResponse|Response\.json)\s*\(.*\bstatus(?:_code)?\s*[:=]\s*([45]\d\d)\b/) || (/^return\b/.test(head) ? expr.match(/^.+,\s*([45]\d\d)\s*$/) : null);
9406
+ if (!m) return null;
9407
+ const status = Number(m[1]);
9408
+ const name = HTTP_STATUS[status] ?? (status >= 500 ? "Server Error" : "Client Error");
9409
+ const msg = (expr.match(/\b(?:error|message|detail|msg)\s*[:=]\s*["'`]([^"'`]{1,80})["'`]/) || expr.match(/\.(?:send|json|end)\(\s*["'`]([^"'`]{1,80})["'`]/) || [])[1];
9410
+ return { kind: "fail", says: `Fails with ${status} ${name}${msg ? `: "${msg}"` : ""}`, error: `${status} ${name}`, ...msg ? { message: msg } : {}, status };
9411
+ }
9412
+ function redirectTarget(arg) {
9413
+ const a = String(arg || "").trim().replace(/^(?:url|to|location|redirect_to)\s*=\s*/, "");
9414
+ let m;
9415
+ if (m = a.match(/^(?:new\s+URL\(\s*)?["'`](\/[^"'`$?#]*|https?:\/\/[^"'`$/?#]+[^"'`$?#]*)/)) return m[1];
9416
+ if (m = a.match(/^`\$\{\s*([A-Za-z_][\w.]*)\s*\}/)) return `the ${words2(m[1].split(".").pop()).replace(/\burl\b/i, "URL")}`;
9417
+ if (m = a.match(/\b(?:url_for|reverse|route|url)\(\s*["']([\w.:-]+)["']/)) return `the ${words2(m[1].split(/[.:]/).pop())} page`;
9418
+ if (m = a.match(/^([A-Za-z_][\w.]*)$/)) return `the ${words2(m[1].split(".").pop()).replace(/\burl\b/i, "URL")}`;
9419
+ return "another page";
9420
+ }
9421
+ function redirectOf(head) {
9422
+ const isReturn = /^return\b/.test(head);
9423
+ const expr = head.replace(/^return\s+/, "").replace(/^await\s+/, "").replace(/;\s*$/, "").trim();
9424
+ let m = expr.match(/^(?:reply|res|response|resp|ctx|c)\s*\.\s*redirect\s*\(\s*(?:\d{3}\s*,\s*)?(.*)\)\s*$/) || expr.match(/^(?:Response|NextResponse)\s*\.\s*redirect\s*\(\s*(.*?)\s*(?:,\s*\d{3}\s*)?\)\s*$/) || expr.match(/^(?:HttpResponseRedirect|HttpResponsePermanentRedirect|RedirectResponse|redirect)\s*\(\s*(.*?)\s*(?:,\s*(?:\d{3}|status(?:_code)?\s*=\s*\d{3}|permanent\s*=\s*\w+)\s*)?\)\s*$/) || expr.match(/^redirect\(\s*\)\s*->\s*(route\(.*\))\s*$/);
9425
+ if (!m) return null;
9426
+ const to = redirectTarget(m[1]);
9427
+ return { kind: isReturn ? "return" : "call", says: `Sends the person to ${to}`, redirect: to };
9428
+ }
9402
9429
  function classifyStatement(raw, { inner = 0 } = {}) {
9403
9430
  const text = String(raw).trim();
9404
9431
  const head = text.split("\n")[0].trim().replace(/\(\s*([\w$#.]+)\s+as\s+[^)]+\)/g, "$1").replace(/([\w$\])])!(?=[.(\[])/g, "$1").replace(/\?\.(?=[\w(\[])/g, ".").replace(/\.\(/g, "(").replace(/^\(\*+(self|this)\)\./, "$1.").replace(/\(\(\s*[A-Z][\w.<>\[\]?, ]*\s*\)\s*([\w$.]+)\s*\)/g, "$1").replace(/^(\w[\w.]*\s*=\s*)\(\s*[A-Z][\w.<>\[\]?]*\s*\)\s*/, "$1");
@@ -9423,6 +9450,10 @@ function classifyStatement(raw, { inner = 0 } = {}) {
9423
9450
  const said = name && /^[a-z]/.test(name) ? `the error made by ${words2(name)}` : name;
9424
9451
  return { kind: "fail", says: `Fails${said ? ` with ${said}` : ""}${msg ? `: "${msg}"` : ""}`, code, ...name ? { error: name } : {}, ...msg ? { message: msg } : {} };
9425
9452
  }
9453
+ const httpFail = httpErrorOf(head);
9454
+ if (httpFail) return { ...httpFail, code };
9455
+ const redirect = redirectOf(head);
9456
+ if (redirect) return { ...redirect, code };
9426
9457
  if (m = head.match(/^return\b\s*(.*)$/)) {
9427
9458
  const expr = stripTail(m[1]);
9428
9459
  if (!expr) return { kind: "return", says: "Stops here", code };
@@ -9649,7 +9680,11 @@ function stepsFrom(statements) {
9649
9680
  continue;
9650
9681
  }
9651
9682
  const step = { ...classifyStatement(s.text, { inner: s.inner || 0 }), line: s.line, span: spanOf(s) };
9652
- if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
9683
+ if (step.inline && !/^\{/.test(step.inline.trim())) {
9684
+ const kid = classifyStatement(step.inline);
9685
+ step.children = [{ ...kid, line: s.line, span: spanOf(s) }];
9686
+ delete step.inline;
9687
+ } else if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
9653
9688
  const kids2 = stepsFrom(s.children).steps;
9654
9689
  if (kids2.length) {
9655
9690
  step.children = kids2;
@@ -11668,7 +11703,8 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
11668
11703
  for (const st of r.steps) {
11669
11704
  if (st.kind !== "branch" || !st.cond) continue;
11670
11705
  const bareProperty = /^(not\s+|!)?(?:self\.|this\.)?\w+\.\w+(\(\))?$/.test(st.cond.trim()) && !/\./.test(st.says.replace(/\(\d+ steps? inside\)$/, ""));
11671
- const cond = bareProperty ? null : toThunderCondition(st.cond, names);
11706
+ const bareName = /^(not\s+|!)?(?:self\.|this\.)?\w+$/.test(st.cond.trim()) && /\bis (not )?set\b/.test(st.says);
11707
+ const cond = bareProperty || bareName ? null : toThunderCondition(st.cond, names);
11672
11708
  if (cond) st.says = st.says.replace(/^If .*?( \(\d+ steps? inside\))?$/, (_m, inner) => `If ${st.negate ? "not: " : ""}${plainEnums(sayCondition(cond)).replace(/ is not ""/g, " is not empty").replace(/ is ""/g, " is empty")}${inner || ""}`);
11673
11709
  delete st.cond;
11674
11710
  delete st.negate;
@@ -13433,7 +13469,7 @@ var FORMS = [
13433
13469
  var LEVELS2 = [
13434
13470
  { id: "big-picture", name: "Big Picture", question: "What is it, and what can it do?", shows: "The Things, what each knows and can do, its doors (actions), its rules, and its data. For one action or rule: what you give it, what you get back, and what it uses.", form: "picture" },
13435
13471
  { id: "flow", name: "Flow", question: "How does it go?", shows: "One action or rule as a path: questions with Yes and No, repeats, the Stops, what happens if something goes wrong, and what always happens at the end.", form: "picture" },
13436
- { id: "details", name: "Details", question: "Exactly what happens, and how sure is Thunder?", shows: "Every step with its line, what goes in and comes out, what it uses and what uses it, anything Thunder could not explain, and a rule you can try.", form: "picture" },
13472
+ { id: "details", name: "Details", question: "Exactly what happens, and how sure is Thunder?", shows: "A fact sheet: every way it can end (each Stop with its message, and what it gives back), the answers that lead there, what it changes, what goes in, what it relies on, a rule's answers and exact limits, and what the code cannot tell you.", form: "picture" },
13437
13473
  { id: "text", name: "Text", question: "What does it say, in words?", shows: "Thunder Text: the same meaning in structured words, for reading closely, reviewing a change, and keeping a copy.", form: "words" },
13438
13474
  { id: "original", name: "Original", question: "Which code says so?", shows: "The exact lines in the original language that Thunder read. The evidence, one click away.", form: "evidence" }
13439
13475
  ];
@@ -13612,6 +13648,7 @@ var DOES = {
13612
13648
  calculate: { label: "Works out", mark: "=", color: "fact" },
13613
13649
  save: { label: "Saves", mark: "\u2913", color: "outcome" },
13614
13650
  send: { label: "Tells someone", mark: "\u2709", color: "outcome" },
13651
+ redirect: { label: "Sends the person to", mark: "\u21AA", color: "outcome" },
13615
13652
  ask: { label: "Asks another part", mark: "\u21C4", color: "outcome" },
13616
13653
  repeat: { label: "For each", mark: "\u21BB", color: "structure" },
13617
13654
  answer: { label: "Gives back", mark: "\u21E5", color: "outcome" },
package/dist/learn.cjs CHANGED
@@ -217,6 +217,33 @@ function sayChain(value) {
217
217
  }
218
218
  return hit ? hit.c.say(words(src.split(".").pop().replace(/^#/, ""))) : null;
219
219
  }
220
+ var HTTP_STATUS = { 400: "Bad Request", 401: "Unauthorized", 402: "Payment Required", 403: "Forbidden", 404: "Not Found", 405: "Method Not Allowed", 409: "Conflict", 410: "Gone", 413: "Payload Too Large", 415: "Unsupported Media Type", 422: "Unprocessable Content", 429: "Too Many Requests", 500: "Internal Server Error", 501: "Not Implemented", 502: "Bad Gateway", 503: "Service Unavailable", 504: "Gateway Timeout" };
221
+ function httpErrorOf(head) {
222
+ const expr = head.replace(/^return\s+/, "").replace(/^await\s+/, "").replace(/;\s*$/, "").trim();
223
+ let m = expr.match(/^(?:reply|res|response|resp|ctx\.response)\s*\.\s*(?:code|status|statusCode)\s*\(\s*([45]\d\d)\s*\)/) || expr.match(/^(?:new\s+)?(?:Response|NextResponse(?:\.json)?|HttpResponse|JSONResponse|PlainTextResponse|Response\.json)\s*\(.*\bstatus(?:_code)?\s*[:=]\s*([45]\d\d)\b/) || (/^return\b/.test(head) ? expr.match(/^.+,\s*([45]\d\d)\s*$/) : null);
224
+ if (!m) return null;
225
+ const status = Number(m[1]);
226
+ const name = HTTP_STATUS[status] ?? (status >= 500 ? "Server Error" : "Client Error");
227
+ const msg = (expr.match(/\b(?:error|message|detail|msg)\s*[:=]\s*["'`]([^"'`]{1,80})["'`]/) || expr.match(/\.(?:send|json|end)\(\s*["'`]([^"'`]{1,80})["'`]/) || [])[1];
228
+ return { kind: "fail", says: `Fails with ${status} ${name}${msg ? `: "${msg}"` : ""}`, error: `${status} ${name}`, ...msg ? { message: msg } : {}, status };
229
+ }
230
+ function redirectTarget(arg) {
231
+ const a = String(arg || "").trim().replace(/^(?:url|to|location|redirect_to)\s*=\s*/, "");
232
+ let m;
233
+ if (m = a.match(/^(?:new\s+URL\(\s*)?["'`](\/[^"'`$?#]*|https?:\/\/[^"'`$/?#]+[^"'`$?#]*)/)) return m[1];
234
+ if (m = a.match(/^`\$\{\s*([A-Za-z_][\w.]*)\s*\}/)) return `the ${words(m[1].split(".").pop()).replace(/\burl\b/i, "URL")}`;
235
+ if (m = a.match(/\b(?:url_for|reverse|route|url)\(\s*["']([\w.:-]+)["']/)) return `the ${words(m[1].split(/[.:]/).pop())} page`;
236
+ if (m = a.match(/^([A-Za-z_][\w.]*)$/)) return `the ${words(m[1].split(".").pop()).replace(/\burl\b/i, "URL")}`;
237
+ return "another page";
238
+ }
239
+ function redirectOf(head) {
240
+ const isReturn = /^return\b/.test(head);
241
+ const expr = head.replace(/^return\s+/, "").replace(/^await\s+/, "").replace(/;\s*$/, "").trim();
242
+ let m = expr.match(/^(?:reply|res|response|resp|ctx|c)\s*\.\s*redirect\s*\(\s*(?:\d{3}\s*,\s*)?(.*)\)\s*$/) || expr.match(/^(?:Response|NextResponse)\s*\.\s*redirect\s*\(\s*(.*?)\s*(?:,\s*\d{3}\s*)?\)\s*$/) || expr.match(/^(?:HttpResponseRedirect|HttpResponsePermanentRedirect|RedirectResponse|redirect)\s*\(\s*(.*?)\s*(?:,\s*(?:\d{3}|status(?:_code)?\s*=\s*\d{3}|permanent\s*=\s*\w+)\s*)?\)\s*$/) || expr.match(/^redirect\(\s*\)\s*->\s*(route\(.*\))\s*$/);
243
+ if (!m) return null;
244
+ const to = redirectTarget(m[1]);
245
+ return { kind: isReturn ? "return" : "call", says: `Sends the person to ${to}`, redirect: to };
246
+ }
220
247
  function classifyStatement(raw, { inner = 0 } = {}) {
221
248
  const text = String(raw).trim();
222
249
  const head = text.split("\n")[0].trim().replace(/\(\s*([\w$#.]+)\s+as\s+[^)]+\)/g, "$1").replace(/([\w$\])])!(?=[.(\[])/g, "$1").replace(/\?\.(?=[\w(\[])/g, ".").replace(/\.\(/g, "(").replace(/^\(\*+(self|this)\)\./, "$1.").replace(/\(\(\s*[A-Z][\w.<>\[\]?, ]*\s*\)\s*([\w$.]+)\s*\)/g, "$1").replace(/^(\w[\w.]*\s*=\s*)\(\s*[A-Z][\w.<>\[\]?]*\s*\)\s*/, "$1");
@@ -241,6 +268,10 @@ function classifyStatement(raw, { inner = 0 } = {}) {
241
268
  const said = name && /^[a-z]/.test(name) ? `the error made by ${words(name)}` : name;
242
269
  return { kind: "fail", says: `Fails${said ? ` with ${said}` : ""}${msg ? `: "${msg}"` : ""}`, code, ...name ? { error: name } : {}, ...msg ? { message: msg } : {} };
243
270
  }
271
+ const httpFail = httpErrorOf(head);
272
+ if (httpFail) return { ...httpFail, code };
273
+ const redirect = redirectOf(head);
274
+ if (redirect) return { ...redirect, code };
244
275
  if (m = head.match(/^return\b\s*(.*)$/)) {
245
276
  const expr = stripTail(m[1]);
246
277
  if (!expr) return { kind: "return", says: "Stops here", code };
@@ -467,7 +498,11 @@ function stepsFrom(statements) {
467
498
  continue;
468
499
  }
469
500
  const step = { ...classifyStatement(s.text, { inner: s.inner || 0 }), line: s.line, span: spanOf(s) };
470
- if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
501
+ if (step.inline && !/^\{/.test(step.inline.trim())) {
502
+ const kid = classifyStatement(step.inline);
503
+ step.children = [{ ...kid, line: s.line, span: spanOf(s) }];
504
+ delete step.inline;
505
+ } else if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
471
506
  const kids2 = stepsFrom(s.children).steps;
472
507
  if (kids2.length) {
473
508
  step.children = kids2;
@@ -1921,7 +1956,7 @@ var SEMANTIC_TYPES = Object.keys(SEMANTIC);
1921
1956
  var PRIMITIVE_TYPES = Object.keys(PRIMITIVE);
1922
1957
 
1923
1958
  // src/emit.mjs
1924
- var COMPILER_VERSION = "0.5.7";
1959
+ var COMPILER_VERSION = "0.5.9";
1925
1960
 
1926
1961
  // src/lift.mjs
1927
1962
  var IR_SCHEMA_VERSION = "0.1.0";
@@ -4401,7 +4436,8 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
4401
4436
  for (const st of r.steps) {
4402
4437
  if (st.kind !== "branch" || !st.cond) continue;
4403
4438
  const bareProperty = /^(not\s+|!)?(?:self\.|this\.)?\w+\.\w+(\(\))?$/.test(st.cond.trim()) && !/\./.test(st.says.replace(/\(\d+ steps? inside\)$/, ""));
4404
- const cond = bareProperty ? null : toThunderCondition(st.cond, names);
4439
+ const bareName = /^(not\s+|!)?(?:self\.|this\.)?\w+$/.test(st.cond.trim()) && /\bis (not )?set\b/.test(st.says);
4440
+ const cond = bareProperty || bareName ? null : toThunderCondition(st.cond, names);
4405
4441
  if (cond) st.says = st.says.replace(/^If .*?( \(\d+ steps? inside\))?$/, (_m, inner) => `If ${st.negate ? "not: " : ""}${plainEnums(sayCondition(cond)).replace(/ is not ""/g, " is not empty").replace(/ is ""/g, " is empty")}${inner || ""}`);
4406
4442
  delete st.cond;
4407
4443
  delete st.negate;
@@ -5038,6 +5074,7 @@ function stepDoes(step) {
5038
5074
  const s = step.says || "", c = step.callee || "";
5039
5075
  if (step.restates || step.kind === "other") return "code";
5040
5076
  if (step.kind === "fail") return "stop";
5077
+ if (step.redirect) return "redirect";
5041
5078
  if (step.kind === "loop") return "repeat";
5042
5079
  if (step.kind === "return") return "answer";
5043
5080
  if (step.kind === "check") return "check";
@@ -5195,6 +5232,27 @@ function flowOf(steps, { start = "Start", memberIndex = /* @__PURE__ */ new Map(
5195
5232
  return { nodes, edges, blocks };
5196
5233
  }
5197
5234
  var idOf = (...parts) => parts.join("#").replace(/\s+/g, "");
5235
+ function youGiveOf(item) {
5236
+ const given = (item.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name) && !p.plumbing).map((p) => words3(p.name));
5237
+ const codes = [];
5238
+ const walk = (steps) => {
5239
+ for (const s of steps || []) {
5240
+ if (s.code) codes.push(s.code);
5241
+ walk(s.children);
5242
+ walk(s.otherwise);
5243
+ }
5244
+ };
5245
+ walk(item.steps);
5246
+ for (const c of codes) {
5247
+ const m = c.match(/^(?:const|let|var)\s*\{([^}]+)\}\s*=\s*\(?\s*(?:await\s+)?(?:req|request|ctx\.request|c\.req|event)\s*\.\s*(?:body|query|params|json\(\))/);
5248
+ if (!m) continue;
5249
+ for (const part of m[1].split(",")) {
5250
+ const name = part.split(/[:=]/)[0].replace(/^\.\.\./, "").trim();
5251
+ if (/^[A-Za-z_$][\w$]*$/.test(name) && !given.includes(words3(name))) given.push(words3(name));
5252
+ }
5253
+ }
5254
+ return given;
5255
+ }
5198
5256
  function thunderModel(files, { name = "app" } = {}) {
5199
5257
  const things = [], members = [], links = [], unknowns = [], fileInfo = [];
5200
5258
  for (const f of files) {
@@ -5250,7 +5308,7 @@ function thunderModel(files, { name = "app" } = {}) {
5250
5308
  lines: [item.line, bodyEnd],
5251
5309
  ...item.doc ? { doc: item.doc } : {},
5252
5310
  ...item.route ? { route: `${item.route.method} ${item.route.path}`.trim() } : {},
5253
- youGive: (item.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name)).map((p) => words3(p.name)),
5311
+ youGive: youGiveOf(item),
5254
5312
  ...item.returns && kind !== "rule" ? { youGetBack: kindWords(item.returns) ?? item.returns } : {},
5255
5313
  ...rule ? { rule, question: rule.question } : {},
5256
5314
  // A yes/no rule is named as a question ("Can borrow?"); a rule with named answers is not ("Late fee").
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillstech/thunderlang",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "description": "Deterministic ThunderLang compiler, CLI, and Language Server. No AI required. Turns .thunder files into the canonical Intent Graph, docs, and a proof, and EXECUTES the intent: run decisions, simulate lifecycles, and check outcome contracts. Interops with DMN, BPMN, JSON Schema, and OpenAPI.",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
package/src/emit.mjs CHANGED
@@ -30,7 +30,7 @@ export function notesSummary(ast) {
30
30
  };
31
31
  }
32
32
 
33
- export const COMPILER_VERSION = '0.5.7';
33
+ export const COMPILER_VERSION = '0.5.9';
34
34
  export const PROOF_SCHEMA_VERSION = '0.1.0';
35
35
  // Identifies which ecosystem product emitted this proof. Consumed by SkillsTech
36
36
  // Certified to key cert proofs to the compiler. Stable slug per the coordination bus.
package/src/model.d.mts CHANGED
@@ -16,6 +16,8 @@ export function ruleFlow(item: unknown, start: string): Flow;
16
16
  export function askAsQuestion(step: { says: string; code?: string }, ruleLabel?: string): { text: string; flip: boolean };
17
17
  export function stepDoes(step: unknown): Does;
18
18
  export function modelText(model: ThunderModel, id: string): string;
19
+ /** One answer on the way to a step: the question, and Yes, No, For each, or Otherwise. */
20
+ export interface When { question: string; answer: string }
19
21
  export type LevelId = 'big-picture' | 'flow' | 'details' | 'text' | 'original';
20
22
  export interface LevelItem { id: string; label: string; symbol: string; route?: string }
21
23
  export interface LevelView {
@@ -34,6 +36,22 @@ export interface LevelView {
34
36
  // Details
35
37
  steps?: { id: string; text: string; does: Does; mark: string; line: number | null; depth: number; via?: string; notExplained?: true }[];
36
38
  notExplained?: number; tryable?: boolean; rule?: unknown; source?: string;
39
+ /** Details: what goes in, and the lines where each fact is used. */
40
+ inputs?: { label: string; lines: number[] }[];
41
+ /** Details: the data it changes, what it saves or sends, and the answers that lead there. */
42
+ changes?: { text: string; line: number | null; does: Does; when: When[] }[];
43
+ /** Details: every way it can stop, with the error, the message people see, and the answers that lead there. */
44
+ stops?: { error: string; message?: string; line: number | null; when: When[] }[];
45
+ /** Details: what it gives back, and when. */
46
+ givesBack?: { text: string; line: number | null; when: When[] }[];
47
+ /** Details: each action or rule it relies on, summarized. */
48
+ reliesOn?: { id: string; label: string; symbol: string; says: string }[];
49
+ /** Details, for a rule: its answers in words, in order (the last may be "otherwise"). */
50
+ answers?: { answer: string; when: string }[];
51
+ /** Details, for a rule with one whole-number fact: its exact limits, found by running it. from/to null = "or less"/"or more". */
52
+ limits?: { fact: string; ranges: { from: number | null; to: number | null; answer: string }[] };
53
+ /** Details: questions the code can't answer (what a number means, why the rule exists). */
54
+ openQuestions?: string[];
37
55
  // Text
38
56
  text?: string;
39
57
  // Original
package/src/model.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  // them may say more than the model does. Browser-safe: takes [{ path, source }].
5
5
  import { readCode } from './read.mjs';
6
6
  import { readableLanguage } from './read-repo.mjs';
7
- import { plainFromReading } from './plain-contract.mjs';
7
+ import { plainFromReading, explainPlain } from './plain-contract.mjs';
8
8
  import { visualFor, LEVELS, DOES } from './visual.mjs';
9
9
 
10
10
  export const MODEL_SCHEMA = 'thunder-model-v1';
@@ -173,6 +173,7 @@ export function stepDoes(step) {
173
173
  const s = step.says || '', c = step.callee || '';
174
174
  if (step.restates || step.kind === 'other') return 'code';
175
175
  if (step.kind === 'fail') return 'stop';
176
+ if (step.redirect) return 'redirect';
176
177
  if (step.kind === 'loop') return 'repeat';
177
178
  if (step.kind === 'return') return 'answer';
178
179
  if (step.kind === 'check') return 'check';
@@ -343,6 +344,27 @@ const idOf = (...parts) => parts.join('#').replace(/\s+/g, '');
343
344
  * Read files into the one Thunder model. Things come from classes in THING_LANGUAGES; every function in every
344
345
  * readable language becomes a member with its flow. Unknowns list what could not be read, so no view hides a gap.
345
346
  */
347
+ /**
348
+ * What a person gives an action or function: its inputs, without framework plumbing (self, the request, a database
349
+ * session), plus the facts a handler unpacks from the request: `const { slug, name } = request.body`,
350
+ * `const { id } = req.params`, `{ email } = await request.json()`.
351
+ */
352
+ function youGiveOf(item) {
353
+ const given = (item.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name) && !p.plumbing).map((p) => words(p.name));
354
+ const codes = [];
355
+ const walk = (steps) => { for (const s of steps || []) { if (s.code) codes.push(s.code); walk(s.children); walk(s.otherwise); } };
356
+ walk(item.steps);
357
+ for (const c of codes) {
358
+ const m = c.match(/^(?:const|let|var)\s*\{([^}]+)\}\s*=\s*\(?\s*(?:await\s+)?(?:req|request|ctx\.request|c\.req|event)\s*\.\s*(?:body|query|params|json\(\))/);
359
+ if (!m) continue;
360
+ for (const part of m[1].split(',')) {
361
+ const name = part.split(/[:=]/)[0].replace(/^\.\.\./, '').trim();
362
+ if (/^[A-Za-z_$][\w$]*$/.test(name) && !given.includes(words(name))) given.push(words(name));
363
+ }
364
+ }
365
+ return given;
366
+ }
367
+
346
368
  export function thunderModel(files, { name = 'app' } = {}) {
347
369
  const things = [], members = [], links = [], unknowns = [], fileInfo = [];
348
370
  for (const f of files) {
@@ -374,7 +396,7 @@ export function thunderModel(files, { name = 'app' } = {}) {
374
396
  label: setup ? `A new ${owner.label} starts with` : cap(words(item.name.replace(/^__|__$/g, ''))),
375
397
  ...(owner ? { owner: owner.id } : {}), file: f.path, language, lines: [item.line, bodyEnd],
376
398
  ...(item.doc ? { doc: item.doc } : {}), ...(item.route ? { route: `${item.route.method} ${item.route.path}`.trim() } : {}),
377
- youGive: (item.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name)).map((p) => words(p.name)),
399
+ youGive: youGiveOf(item),
378
400
  ...(item.returns && kind !== 'rule' ? { youGetBack: kindWords(item.returns) ?? item.returns } : {}),
379
401
  ...(rule ? { rule, question: rule.question } : {}),
380
402
  // A yes/no rule is named as a question ("Can borrow?"); a rule with named answers is not ("Late fee").
@@ -481,6 +503,94 @@ function detailSteps(flow) {
481
503
  return out;
482
504
  }
483
505
 
506
+
507
+ // ── Details: what you need to check before you trust or change an action or rule ─────────────────────────
508
+
509
+ const CHANGES = /^(Sets|Adds|Removes|Subtracts|Clears|Marks|Saves|Deletes|Updates|Appends|Increases|Decreases|Sends|Records|Stores|Writes)\b/;
510
+
511
+ /** Each step with the answers that lead to it: [{ question, answer }] from the top of the flow. */
512
+ function pathsOf(flow) {
513
+ const byId = new Map(flow.nodes.map((n) => [n.id, n]));
514
+ const out = [];
515
+ const walk = (blocks, when) => {
516
+ for (const b of blocks || []) {
517
+ const n = byId.get(b.id);
518
+ if (n && n.kind !== 'start') out.push({ node: n, when });
519
+ const q = n?.text ?? '';
520
+ walk(b.yes, [...when, { question: q, answer: 'Yes' }]);
521
+ walk(b.no, [...when, { question: q, answer: 'No' }]);
522
+ walk(b.each, [...when, { question: q, answer: 'For each' }]);
523
+ walk(b.body, when);
524
+ for (const h of b.handlers || []) { const hn = byId.get(h.id); walk(h.blocks, [...when, { question: (hn?.text ?? '').replace(/\?$/, ''), answer: 'Yes' }]); }
525
+ if (b.always) walk(b.always.blocks, when);
526
+ }
527
+ };
528
+ walk(flow.blocks, []);
529
+ return out;
530
+ }
531
+
532
+ /** A rule's answers in words: [{ answer, when }] in order, then the otherwise answer. */
533
+ function ruleAnswers(rule) {
534
+ const zero = Object.fromEntries(rule.inputs.map((i) => [i.id, i.kind === 'yesno' ? true : 0]));
535
+ let explained;
536
+ try { explained = explainPlain(rule, zero); } catch { return null; }
537
+ const answers = explained.rules.map((r) => ({ answer: answerWords(r.outcome), when: r.checks.map((c) => c.text).join(r.join === 'any' ? ' or ' : ' and ') }));
538
+ if (rule.otherwise) answers.push({ answer: answerWords(rule.otherwise), when: 'otherwise' });
539
+ return answers;
540
+ }
541
+
542
+ /**
543
+ * The exact limits of a rule with one number fact, found by running it on every whole number around each limit:
544
+ * [{ from, to, answer }] where from/to are null for "or less" / "or more". Only when every limit is a whole number,
545
+ * so the ranges are exact rather than approximate.
546
+ */
547
+ function ruleRanges(rule) {
548
+ if (rule.inputs.length !== 1 || rule.inputs[0].kind === 'yesno') return null;
549
+ const id = rule.inputs[0].id;
550
+ const limits = rule.rules.flatMap((r) => r.conditions).filter((c) => c.input === id && typeof c.value === 'number').map((c) => c.value);
551
+ if (!limits.length || !limits.every(Number.isInteger)) return null;
552
+ const lo = Math.min(...limits) - 1, hi = Math.max(...limits) + 1;
553
+ const ranges = [];
554
+ for (let v = lo; v <= hi; v++) {
555
+ let outcome;
556
+ try { outcome = answerWords(explainPlain(rule, { [id]: v }).outcome); } catch { return null; }
557
+ const last = ranges.at(-1);
558
+ if (last && last.answer === outcome) last.to = v; else ranges.push({ from: v, to: v, answer: outcome });
559
+ }
560
+ ranges[0].from = null;
561
+ ranges.at(-1).to = null;
562
+ return { fact: rule.inputs[0].label.replace(/^the /, ''), ranges };
563
+ }
564
+
565
+ function detailsFacts(model, member) {
566
+ const paths = pathsOf(member.flow);
567
+ const memberOf = (id) => model.members.find((m) => m.id === id);
568
+ const inputs = member.youGive.map((label) => {
569
+ const re = new RegExp(`\\b${label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'i');
570
+ const lines = [...new Set(paths.filter((p) => re.test(p.node.text) && p.node.line).map((p) => p.node.line))];
571
+ return { label, lines };
572
+ });
573
+ const changes = paths.filter((p) => p.node.kind !== 'decision' && p.node.kind !== 'stop' && p.node.kind !== 'end' && (p.node.does === 'save' || p.node.does === 'send' || (CHANGES.test(p.node.text) && /'s\b|\bto\b|\bfrom\b/.test(p.node.text))))
574
+ .map((p) => ({ text: p.node.text, line: p.node.line ?? null, does: p.node.does, when: p.when }));
575
+ const stops = paths.filter((p) => p.node.kind === 'stop').map((p) => {
576
+ const m = p.node.text.match(/^Stop:\s*([^:]+?)(?::\s*"(.*)")?$/);
577
+ return { error: m ? m[1].trim() : p.node.text, ...(m?.[2] ? { message: m[2] } : {}), line: p.node.line ?? null, when: p.when };
578
+ });
579
+ const givesBack = paths.filter((p) => p.node.kind === 'end' || p.node.answer).map((p) => ({ text: p.node.answer ? answerWords(p.node.text) : p.node.text, line: p.node.line ?? null, when: p.node.otherwise ? [{ question: 'none of the above', answer: 'Otherwise' }] : p.when }));
580
+ const reliesOn = model.links.filter((l) => l.from === member.id).map((l) => memberOf(l.to)).filter(Boolean).map((t) => {
581
+ const answers = t.rule ? ruleAnswers(t.rule) : null;
582
+ const flowAnswers = [...new Set(t.flow.nodes.filter((n) => n.answer).map((n) => n.text))];
583
+ const list = answers ? answers.map((a) => a.answer) : flowAnswers;
584
+ const says = list.length ? `Answers ${list.join(', ').replace(/, ([^,]*)$/, list.length > 2 ? ', or $1' : ' or $1')}.`
585
+ : t.youGetBack ? `Gives back ${t.youGetBack}.` : t.flow.nodes.some((n) => n.kind === 'stop') ? `Can stop with ${t.flow.nodes.filter((n) => n.kind === 'stop').map((n) => n.text.replace(/^Stop:\s*/, '').split(':')[0]).join(', ')}.` : `${t.flow.nodes.filter((n) => n.kind !== 'start').length} steps.`;
586
+ return { id: t.id, label: t.label + (t.yesNo ? '?' : ''), symbol: SYMBOL_OF[t.kind], says };
587
+ });
588
+ const answers = member.rule ? ruleAnswers(member.rule) : null;
589
+ const limits = member.rule ? ruleRanges(member.rule) : null;
590
+ const openQuestions = (member.rule?.needsReview ?? []).filter((q) => !/^No examples yet/.test(q));
591
+ return { inputs, changes, stops, givesBack, reliesOn, ...(answers ? { answers } : {}), ...(limits ? { limits } : {}), openQuestions };
592
+ }
593
+
484
594
  /**
485
595
  * What one reading level shows: `level` is a LEVELS id (big-picture, flow, details, text, original); `focus` is a
486
596
  * Thing or member id, or nothing for the whole model. Flow and Details need an action or rule; without one they
@@ -526,7 +636,8 @@ export function readLevel(model, level, focus) {
526
636
  if (lv.id === 'flow') return { ...base, ...about, flow: member.flow };
527
637
  if (lv.id === 'details') {
528
638
  const steps = detailSteps(member.flow);
529
- return { ...base, ...about, youGive: member.youGive, ...(member.youGetBack ? { youGetBack: member.youGetBack } : {}), steps,
639
+ return { ...base, ...about, youGive: member.youGive, ...(member.youGetBack ? { youGetBack: member.youGetBack } : {}), ...(member.doc ? { doc: member.doc } : {}),
640
+ ...detailsFacts(model, member), steps,
530
641
  notExplained: steps.filter((s) => s.notExplained).length, uses, usedBy, tryable: !!member.rule, ...(member.rule ? { rule: member.rule } : {}),
531
642
  source: 'Read from code by the Thunder compiler, with no AI.' };
532
643
  }
package/src/read.mjs CHANGED
@@ -1773,7 +1773,9 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
1773
1773
  if (st.kind !== 'branch' || !st.cond) continue;
1774
1774
  // A bare yes/no property (`order.refunded`) already reads as a sentence from the step itself; keep it.
1775
1775
  const bareProperty = /^(not\s+|!)?(?:self\.|this\.)?\w+\.\w+(\(\))?$/.test(st.cond.trim()) && !/\./.test(st.says.replace(/\(\d+ steps? inside\)$/, ''));
1776
- const cond = bareProperty ? null : toThunderCondition(st.cond, names);
1776
+ // A plain name used as a yes/no (`if (!slug)`) already reads as "slug is not set"; keep it rather than "not slug".
1777
+ const bareName = /^(not\s+|!)?(?:self\.|this\.)?\w+$/.test(st.cond.trim()) && /\bis (not )?set\b/.test(st.says);
1778
+ const cond = bareProperty || bareName ? null : toThunderCondition(st.cond, names);
1777
1779
  if (cond) st.says = st.says.replace(/^If .*?( \(\d+ steps? inside\))?$/, (_m, inner) => `If ${st.negate ? 'not: ' : ''}${plainEnums(sayCondition(cond)).replace(/ is not ""/g, ' is not empty').replace(/ is ""/g, ' is empty')}${inner || ''}`);
1778
1780
  delete st.cond; delete st.negate;
1779
1781
  }
package/src/steps.mjs CHANGED
@@ -223,6 +223,53 @@ function sayChain(value) {
223
223
  return hit ? hit.c.say(words(src.split('.').pop().replace(/^#/, ''))) : null;
224
224
  }
225
225
 
226
+ const HTTP_STATUS = { 400: 'Bad Request', 401: 'Unauthorized', 402: 'Payment Required', 403: 'Forbidden', 404: 'Not Found', 405: 'Method Not Allowed', 409: 'Conflict', 410: 'Gone', 413: 'Payload Too Large', 415: 'Unsupported Media Type', 422: 'Unprocessable Content', 429: 'Too Many Requests', 500: 'Internal Server Error', 501: 'Not Implemented', 502: 'Bad Gateway', 503: 'Service Unavailable', 504: 'Gateway Timeout' };
227
+
228
+ /**
229
+ * An HTTP error response, returned or sent: Fastify `reply.code(400).send(...)`, Express `res.status(404).json(...)`,
230
+ * `new Response(..., { status: 403 })`, FastAPI `JSONResponse(..., status_code=422)`, Flask `return jsonify(...), 400`.
231
+ * Gives a fail step: { kind: 'fail', says, error: '400 Bad Request', message, status } or null.
232
+ */
233
+ function httpErrorOf(head) {
234
+ const expr = head.replace(/^return\s+/, '').replace(/^await\s+/, '').replace(/;\s*$/, '').trim();
235
+ let m = expr.match(/^(?:reply|res|response|resp|ctx\.response)\s*\.\s*(?:code|status|statusCode)\s*\(\s*([45]\d\d)\s*\)/)
236
+ || expr.match(/^(?:new\s+)?(?:Response|NextResponse(?:\.json)?|HttpResponse|JSONResponse|PlainTextResponse|Response\.json)\s*\(.*\bstatus(?:_code)?\s*[:=]\s*([45]\d\d)\b/)
237
+ || (/^return\b/.test(head) ? expr.match(/^.+,\s*([45]\d\d)\s*$/) : null);
238
+ if (!m) return null;
239
+ const status = Number(m[1]);
240
+ const name = HTTP_STATUS[status] ?? (status >= 500 ? 'Server Error' : 'Client Error');
241
+ const msg = (expr.match(/\b(?:error|message|detail|msg)\s*[:=]\s*["'`]([^"'`]{1,80})["'`]/) || expr.match(/\.(?:send|json|end)\(\s*["'`]([^"'`]{1,80})["'`]/) || [])[1];
242
+ return { kind: 'fail', says: `Fails with ${status} ${name}${msg ? `: "${msg}"` : ''}`, error: `${status} ${name}`, ...(msg ? { message: msg } : {}), status };
243
+ }
244
+
245
+ /** Where a redirect goes, in words: '/login' stays a path, `${GOOGLE_AUTH_URL}?…` -> "the Google auth URL", url_for('home') -> "the home page". */
246
+ function redirectTarget(arg) {
247
+ const a = String(arg || '').trim().replace(/^(?:url|to|location|redirect_to)\s*=\s*/, '');
248
+ let m;
249
+ if ((m = a.match(/^(?:new\s+URL\(\s*)?["'`](\/[^"'`$?#]*|https?:\/\/[^"'`$/?#]+[^"'`$?#]*)/))) return m[1];
250
+ if ((m = a.match(/^`\$\{\s*([A-Za-z_][\w.]*)\s*\}/))) return `the ${words(m[1].split('.').pop()).replace(/\burl\b/i, 'URL')}`;
251
+ if ((m = a.match(/\b(?:url_for|reverse|route|url)\(\s*["']([\w.:-]+)["']/))) return `the ${words(m[1].split(/[.:]/).pop())} page`;
252
+ if ((m = a.match(/^([A-Za-z_][\w.]*)$/))) return `the ${words(m[1].split('.').pop()).replace(/\burl\b/i, 'URL')}`;
253
+ return 'another page';
254
+ }
255
+
256
+ /**
257
+ * A redirect: Fastify/Express `reply.redirect(url)` / `res.redirect(302, url)`, `Response.redirect(url)`,
258
+ * `NextResponse.redirect(...)`, Flask/Django/Next `redirect(url)`, `HttpResponseRedirect(url)`,
259
+ * FastAPI `RedirectResponse(url)`, Laravel `redirect()->route('home')`. Gives a step that says where the person goes.
260
+ */
261
+ function redirectOf(head) {
262
+ const isReturn = /^return\b/.test(head);
263
+ const expr = head.replace(/^return\s+/, '').replace(/^await\s+/, '').replace(/;\s*$/, '').trim();
264
+ let m = expr.match(/^(?:reply|res|response|resp|ctx|c)\s*\.\s*redirect\s*\(\s*(?:\d{3}\s*,\s*)?(.*)\)\s*$/)
265
+ || expr.match(/^(?:Response|NextResponse)\s*\.\s*redirect\s*\(\s*(.*?)\s*(?:,\s*\d{3}\s*)?\)\s*$/)
266
+ || expr.match(/^(?:HttpResponseRedirect|HttpResponsePermanentRedirect|RedirectResponse|redirect)\s*\(\s*(.*?)\s*(?:,\s*(?:\d{3}|status(?:_code)?\s*=\s*\d{3}|permanent\s*=\s*\w+)\s*)?\)\s*$/)
267
+ || expr.match(/^redirect\(\s*\)\s*->\s*(route\(.*\))\s*$/);
268
+ if (!m) return null;
269
+ const to = redirectTarget(m[1]);
270
+ return { kind: isReturn ? 'return' : 'call', says: `Sends the person to ${to}`, redirect: to };
271
+ }
272
+
226
273
  export function classifyStatement(raw, { inner = 0 } = {}) {
227
274
  const text = String(raw).trim();
228
275
  // TypeScript-only syntax that changes nothing for a reader: casts, non-null assertions, optional calls.
@@ -256,6 +303,12 @@ export function classifyStatement(raw, { inner = 0 } = {}) {
256
303
  const said = name && /^[a-z]/.test(name) ? `the error made by ${words(name)}` : name;
257
304
  return { kind: 'fail', says: `Fails${said ? ` with ${said}` : ''}${msg ? `: "${msg}"` : ''}`, code, ...(name ? { error: name } : {}), ...(msg ? { message: msg } : {}) };
258
305
  }
306
+ // An HTTP error response (4xx/5xx) is a Stop: the request is refused, with a status and a message.
307
+ const httpFail = httpErrorOf(head);
308
+ if (httpFail) return { ...httpFail, code };
309
+ // A redirect sends the person somewhere else: "Sends the person to the Google auth URL".
310
+ const redirect = redirectOf(head);
311
+ if (redirect) return { ...redirect, code };
259
312
  // Returns (Go/Rust error returns read as failures)
260
313
  if ((m = head.match(/^return\b\s*(.*)$/))) {
261
314
  const expr = stripTail(m[1]);
@@ -479,7 +532,10 @@ export function stepsFrom(statements) {
479
532
  if (/^(?:"""|'''|r"""|\/\*\*|\*)/.test(t0)) { skipped.push(spanOf(s)); continue; } // docstrings and doc comments
480
533
  if (/^[)\]}]+[):;,]*$/.test(t0) || /^\.\.\.$/.test(t0) || /^\.[A-Za-z_]/.test(t0) || /^@\w+(?:\(.*\))?$/.test(t0) || /^#?\[[\w:]+(?:\(.*\))?\]$/.test(t0) || /^:(?:param|rtype|return|raises|type)\b/.test(t0)) { skipped.push(spanOf(s)); continue; }
481
534
  const step = { ...classifyStatement(s.text, { inner: s.inner || 0 }), line: s.line, span: spanOf(s) };
482
- if (s.children?.length && ['branch', 'loop', 'try'].includes(step.kind)) {
535
+ // A one-line `if (x) return reply.code(400).send({ error: 'bad' })` is one statement: its braces belong to the
536
+ // object being sent, not to a block, so read the statement after the condition instead of the braces' inside.
537
+ if (step.inline && !/^\{/.test(step.inline.trim())) { const kid = classifyStatement(step.inline); step.children = [{ ...kid, line: s.line, span: spanOf(s) }]; delete step.inline; }
538
+ else if (s.children?.length && ['branch', 'loop', 'try'].includes(step.kind)) {
483
539
  const kids = stepsFrom(s.children).steps;
484
540
  if (kids.length) { step.children = kids; step.says = step.says.replace(/ \(\d+ steps? inside\)$/, ''); }
485
541
  }
package/src/visual.d.mts CHANGED
@@ -29,7 +29,7 @@ export function visualForStep(step: ReadStep): { mark: string; label: string; co
29
29
  export function thunderText(item: ReadItem): string;
30
30
  export type SymbolId = 'app' | 'area' | 'file' | 'thing' | 'data' | 'record' | 'choices' | 'action' | 'rule' | 'steps' | 'setup' | 'stop' | 'not-read';
31
31
  export const SYMBOLS: Record<SymbolId, { name: string; says: string; color: ColorRole; paths: string[]; circles?: [number, number, number][]; fill?: boolean; dashed?: boolean; beginner?: boolean; group?: string }>;
32
- export type Does = 'start' | 'find' | 'keep-only' | 'check' | 'decide' | 'calculate' | 'save' | 'send' | 'ask' | 'repeat' | 'answer' | 'stop' | 'do' | 'code';
32
+ export type Does = 'start' | 'find' | 'keep-only' | 'check' | 'decide' | 'calculate' | 'save' | 'send' | 'redirect' | 'ask' | 'repeat' | 'answer' | 'stop' | 'do' | 'code';
33
33
  export const DOES: Record<Does, { label: string; mark: string; color: ColorRole; dashed?: boolean; symbol?: SymbolId }>;
34
34
  export const BEGINNER: SymbolId[];
35
35
  /** The five reading levels, in order: how deep you read something. */
package/src/visual.mjs CHANGED
@@ -28,7 +28,7 @@ export const FORMS = [
28
28
  export const LEVELS = [
29
29
  { id: 'big-picture', name: 'Big Picture', question: 'What is it, and what can it do?', shows: 'The Things, what each knows and can do, its doors (actions), its rules, and its data. For one action or rule: what you give it, what you get back, and what it uses.', form: 'picture' },
30
30
  { id: 'flow', name: 'Flow', question: 'How does it go?', shows: 'One action or rule as a path: questions with Yes and No, repeats, the Stops, what happens if something goes wrong, and what always happens at the end.', form: 'picture' },
31
- { id: 'details', name: 'Details', question: 'Exactly what happens, and how sure is Thunder?', shows: 'Every step with its line, what goes in and comes out, what it uses and what uses it, anything Thunder could not explain, and a rule you can try.', form: 'picture' },
31
+ { id: 'details', name: 'Details', question: 'Exactly what happens, and how sure is Thunder?', shows: 'A fact sheet: every way it can end (each Stop with its message, and what it gives back), the answers that lead there, what it changes, what goes in, what it relies on, a rule\'s answers and exact limits, and what the code cannot tell you.', form: 'picture' },
32
32
  { id: 'text', name: 'Text', question: 'What does it say, in words?', shows: 'Thunder Text: the same meaning in structured words, for reading closely, reviewing a change, and keeping a copy.', form: 'words' },
33
33
  { id: 'original', name: 'Original', question: 'Which code says so?', shows: 'The exact lines in the original language that Thunder read. The evidence, one click away.', form: 'evidence' },
34
34
  ];
@@ -250,6 +250,7 @@ export const DOES = {
250
250
  calculate: { label: 'Works out', mark: '=', color: 'fact' },
251
251
  save: { label: 'Saves', mark: '⤓', color: 'outcome' },
252
252
  send: { label: 'Tells someone', mark: '✉', color: 'outcome' },
253
+ redirect: { label: 'Sends the person to', mark: '↪', color: 'outcome' },
253
254
  ask: { label: 'Asks another part', mark: '⇄', color: 'outcome' },
254
255
  repeat: { label: 'For each', mark: '↻', color: 'structure' },
255
256
  answer: { label: 'Gives back', mark: '⇥', color: 'outcome' },