@skillstech/thunderlang 1.4.1 → 1.4.3

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,35 @@
1
+ # 1.4.3
2
+
3
+ **Upgrade note.** No command, flag, exit code, or JSON shape changed. `readingLayout` can now end with a new
4
+ `actions` section (`id: 'actions'`); apps that switch on section ids should draw it or skip it.
5
+
6
+ - **The drawing kit: a file of plain functions is no longer an empty Big Picture.** With no focus, or a file in focus,
7
+ `readingLayout` now ends with an "Actions and rules" section (`id: 'actions'`, `READING_LABELS.actions`): every
8
+ action or rule that belongs to no Thing, with its symbol and doc, and `BigPicture` draws each as a door to open
9
+ (`onOpen`). A Thing's own abilities stay on its card. Before, a file with only functions drew nothing.
10
+ - **Fix: the kit on phones and in panels.** The Yes / No / Otherwise tags in Flow and Details no longer break inside
11
+ a word on a narrow screen, and the Data cards size their columns from the space they are given instead of the
12
+ window's width, so they are no longer cramped inside a side panel.
13
+
14
+ # 1.4.2
15
+
16
+ **Upgrade note.** No command, flag, exit code, or JSON shape changed. New in `@skillstech/thunderlang/react`:
17
+ `IOBoxes`, `Flow`, and `Details` (`BigPicture` now draws the IO boxes when an action or rule is in focus). New in
18
+ `./core`: `flowEdgeLabel()` and `detailsLayout()`. `ioBoxes()` gains `getBack.items`; `getBack.text` is unchanged.
19
+
20
+ - **The drawing kit, second part: the IO boxes, Flow, and Details.** `@skillstech/thunderlang/react` now draws the
21
+ whole reading of one action or rule, so the three products show it the same way. `IOBoxes` ("You give it", "You get
22
+ back", "It can stop with" with each stop's line, and "Part of …" back to its Thing), which `BigPicture` now draws when
23
+ an action or rule is in focus. `Flow` (every step at the compiler's lane and row, its Yes / No / For each / Done / If
24
+ it fails edges, marks and colors from DOES, steps not read yet dashed, optional New / Gone marks for Thunder Diff).
25
+ `Details` (the counts at a glance, then You give it / You get back, When it stops, What it changes, Its answers,
26
+ Exact limits, Every step, It relies on, Used by, Questions the code cannot answer). The words come from
27
+ `./core`: `flowEdgeLabel(edge)` and `detailsLayout(readLevel(model, 'details', id))`, which keeps a section only when
28
+ the compiler gave it. Callbacks only (`onLine`, `onUse`, `onThing`); no buttons without them. The stylesheet gains
29
+ the matching `tl-` classes, all on the same color variables. `ioBoxes` gains `getBack.items`: the declared result,
30
+ else the Flow's end steps, so the Big Picture no longer says "Nothing it hands back" for a function whose returns
31
+ have no type (`getBack.text` is unchanged).
32
+
1
33
  # 1.4.1
2
34
 
3
35
  **Upgrade note.** No command, flag, exit code, or JSON shape changed. New: the drawing kit entry
package/dist/core.cjs CHANGED
@@ -186,6 +186,7 @@ __export(core_exports, {
186
186
  describeEdit: () => describeEdit,
187
187
  detailOf: () => detailOf,
188
188
  detailParts: () => detailParts,
189
+ detailsLayout: () => detailsLayout,
189
190
  detectLanguage: () => detectLanguage,
190
191
  diffGraphs: () => diffGraphs,
191
192
  displayLabel: () => displayLabel,
@@ -198,6 +199,7 @@ __export(core_exports, {
198
199
  explainPlain: () => explainPlain,
199
200
  exprCounts: () => exprCounts,
200
201
  findSameRule: () => findSameRule,
202
+ flowEdgeLabel: () => flowEdgeLabel,
201
203
  flowOf: () => flowOf,
202
204
  formatMoney: () => formatMoney,
203
205
  formatValue: () => formatValue,
@@ -3820,9 +3822,9 @@ var Parser = class {
3820
3822
  }
3821
3823
  if (this.fam === "rs" && this.isOp(";")) {
3822
3824
  this.next();
3823
- const count = this.expr(0.6);
3825
+ const count2 = this.expr(0.6);
3824
3826
  this.eat("]");
3825
- return { kind: "array", items, repeat: count };
3827
+ return { kind: "array", items, repeat: count2 };
3826
3828
  }
3827
3829
  if (!this.isOp("]")) fail2("expected , or ]");
3828
3830
  }
@@ -13343,16 +13345,16 @@ function readTerraform(src, file = "main.tf") {
13343
13345
  const what = d.kind === "module" ? `the module ${name}${src2 ? ` (${valueText(src2.value, refWords).text})` : ""}` : named(typeWords2(type), name);
13344
13346
  const verb = d.kind === "data" ? "Looks up" : d.kind === "module" ? "Uses" : "Creates";
13345
13347
  let step = { kind: "call", says: `${verb} ${what}${inWords}`, code: head, line: b.line };
13346
- const count = attrOf(b.body, "count"), fe = attrOf(b.body, "for_each");
13347
- if (count) {
13348
- const c = count.value;
13348
+ const count2 = attrOf(b.body, "count"), fe = attrOf(b.body, "for_each");
13349
+ if (count2) {
13350
+ const c = count2.value;
13349
13351
  const cond = c.t === "cond" ? c : null;
13350
- if (cond && isZero2(cond.no)) step = { kind: "branch", says: question(conditionWords(cond.test, refWords)), code: `count = ${parsed.src.slice(c.s, c.e)}`, line: count.line, children: [step] };
13351
- else if (cond && isZero2(cond.yes)) step = { kind: "branch", says: question(conditionWords({ t: "unary", op: "!", x: cond.test }, refWords)), code: `count = ${parsed.src.slice(c.s, c.e)}`, line: count.line, children: [step] };
13352
+ if (cond && isZero2(cond.no)) step = { kind: "branch", says: question(conditionWords(cond.test, refWords)), code: `count = ${parsed.src.slice(c.s, c.e)}`, line: count2.line, children: [step] };
13353
+ else if (cond && isZero2(cond.yes)) step = { kind: "branch", says: question(conditionWords({ t: "unary", op: "!", x: cond.test }, refWords)), code: `count = ${parsed.src.slice(c.s, c.e)}`, line: count2.line, children: [step] };
13352
13354
  else if (c.t === "num") {
13353
13355
  if (c.v === 0) step.says += " (none: count is 0)";
13354
13356
  else if (c.v !== 1) step.says = `${verb} ${c.v} of ${what}${inWords}`;
13355
- } else step = { kind: "loop", says: `As many times as ${valueText(c, refWords).text.replace(` (${APPLIED})`, "")}`, code: `count = ${parsed.src.slice(c.s, c.e)}`, line: count.line, children: [step] };
13357
+ } else step = { kind: "loop", says: `As many times as ${valueText(c, refWords).text.replace(` (${APPLIED})`, "")}`, code: `count = ${parsed.src.slice(c.s, c.e)}`, line: count2.line, children: [step] };
13356
13358
  } else if (fe) step = { kind: "loop", says: `For each ${forEachWords(fe.value, refWords).replace(/^one for each /, "")}`, code: `for_each = ${parsed.src.slice(fe.value.s, fe.value.e)}`, line: fe.line, children: [step] };
13357
13359
  steps.push(step);
13358
13360
  }
@@ -16344,13 +16346,13 @@ var CALLOC = new RegExp(String.raw`^${CAST}(?:z|x|je_|ck_)?calloc\(\s*([\w.]+)\s
16344
16346
  function memoryFor(value) {
16345
16347
  const v = String(value).trim().replace(/;$/, "");
16346
16348
  const ofType = (t) => words7(String(t).replace(/\b(?:struct|const|unsigned)\s+/g, "").replace(/\s*\*+$/, "").trim().split("::").pop());
16347
- const count = (n) => /^\d+$/.test(n.trim()) ? n.trim() : words7(n.trim());
16349
+ const count2 = (n) => /^\d+$/.test(n.trim()) ? n.trim() : words7(n.trim());
16348
16350
  let m;
16349
16351
  if (m = v.match(ALLOC_ONE)) return `memory for one ${ofType(m[1])}`;
16350
- if (m = v.match(ALLOC_N)) return `memory for ${count(m[1])} ${pluralOf(ofType(m[2]))}`;
16351
- if (m = v.match(ALLOC_N2)) return `memory for ${count(m[2])} ${pluralOf(ofType(m[1]))}`;
16352
- if (m = v.match(CALLOC)) return m[1].trim() === "1" ? `memory for one ${ofType(m[2])}` : `memory for ${count(m[1])} ${pluralOf(ofType(m[2]))}`;
16353
- if (m = v.match(/^new\s+([\w:<>]+)\s*\[\s*([^\]]+?)\s*\]$/)) return `memory for ${count(m[2])} ${pluralOf(ofType(m[1]))}`;
16352
+ if (m = v.match(ALLOC_N)) return `memory for ${count2(m[1])} ${pluralOf(ofType(m[2]))}`;
16353
+ if (m = v.match(ALLOC_N2)) return `memory for ${count2(m[2])} ${pluralOf(ofType(m[1]))}`;
16354
+ if (m = v.match(CALLOC)) return m[1].trim() === "1" ? `memory for one ${ofType(m[2])}` : `memory for ${count2(m[1])} ${pluralOf(ofType(m[2]))}`;
16355
+ if (m = v.match(/^new\s+([\w:<>]+)\s*\[\s*([^\]]+?)\s*\]$/)) return `memory for ${count2(m[2])} ${pluralOf(ofType(m[1]))}`;
16354
16356
  if (new RegExp(String.raw`^${CAST}(?:z|x|je_|ck_)?(?:malloc|calloc|alloca|aligned_alloc)\(`).test(v)) return "memory";
16355
16357
  return null;
16356
16358
  }
@@ -19405,7 +19407,7 @@ function notesSummary(ast) {
19405
19407
  byLens
19406
19408
  };
19407
19409
  }
19408
- var COMPILER_VERSION = "1.4.1";
19410
+ var COMPILER_VERSION = "1.4.3";
19409
19411
  var PROOF_SCHEMA_VERSION = "0.1.0";
19410
19412
  var SOURCE_PRODUCT = "skillstech-compiler";
19411
19413
  function buildContractGraph(ast, generatedAt) {
@@ -37033,11 +37035,11 @@ function accessFlow(files, { maxRoutes = 2e3 } = {}) {
37033
37035
  paths
37034
37036
  });
37035
37037
  }
37036
- const count = (v) => out.filter((x) => x.verdict === v).length;
37038
+ const count2 = (v) => out.filter((x) => x.verdict === v).length;
37037
37039
  return {
37038
37040
  schema: ACCESS_SCHEMA,
37039
37041
  routes: out,
37040
- summary: { routes: out.length, guarded: count("guarded"), unguarded: count("unguarded"), cannotTell: count("cannot tell"), noLookup: count(null) },
37042
+ summary: { routes: out.length, guarded: count2("guarded"), unguarded: count2("unguarded"), cannotTell: count2("cannot tell"), noLookup: count2(null) },
37041
37043
  unread: project.failures
37042
37044
  };
37043
37045
  }
@@ -40302,11 +40304,11 @@ function fromTrace(trace) {
40302
40304
  const out = [];
40303
40305
  for (const [file, f] of Object.entries(trace?.files || {})) {
40304
40306
  for (const [L, d] of Object.entries(f.decisions || {})) {
40305
- for (const [k, count] of Object.entries(d.obs || {})) {
40307
+ for (const [k, count2] of Object.entries(d.obs || {})) {
40306
40308
  const [where2, nRaw] = k.split("|");
40307
40309
  const next = nRaw === "" || nRaw == null ? null : Number(nRaw);
40308
40310
  const side2 = d.kind === "handler" ? "handled" : where2.startsWith("case:") ? where2 : d.kind === "for" ? where2 === "body" ? "each" : "done" : where2 === "body" ? "held" : "not held";
40309
- out.push({ source: "trace", kind: "decision", file, line: Number(L), side: side2, count, question: d.kind, ...next != null ? { next } : {} });
40311
+ out.push({ source: "trace", kind: "decision", file, line: Number(L), side: side2, count: count2, question: d.kind, ...next != null ? { next } : {} });
40310
40312
  }
40311
40313
  }
40312
40314
  for (const [L, fn] of Object.entries(f.functions || {})) {
@@ -40512,8 +40514,8 @@ function parseStacks(text2) {
40512
40514
  }
40513
40515
  return out;
40514
40516
  }
40515
- function fromStack(text2, { count = 1 } = {}) {
40516
- return parseStacks(text2).map((s) => ({ source: "stack", kind: "raise", file: s.frames[0]?.file ?? null, line: s.frames[0]?.line ?? null, error: s.error, message: s.message, frames: s.frames, language: s.language, count, ends: true }));
40517
+ function fromStack(text2, { count: count2 = 1 } = {}) {
40518
+ return parseStacks(text2).map((s) => ({ source: "stack", kind: "raise", file: s.frames[0]?.file ?? null, line: s.frames[0]?.line ?? null, error: s.error, message: s.message, frames: s.frames, language: s.language, count: count2, ends: true }));
40517
40519
  }
40518
40520
  var LEVEL_NUM = { 10: "trace", 20: "debug", 30: "info", 40: "warn", 50: "error", 60: "fatal" };
40519
40521
  var pick = (o, keys) => {
@@ -40953,8 +40955,8 @@ function hotPath(m, r) {
40953
40955
  continue;
40954
40956
  }
40955
40957
  if (nr.sides) {
40956
- const [label, count] = Object.entries(nr.sides).sort((a, b2) => b2[1] - a[1])[0];
40957
- out.push({ id: n.id, text: n.text, side: label, count });
40958
+ const [label, count2] = Object.entries(nr.sides).sort((a, b2) => b2[1] - a[1])[0];
40959
+ out.push({ id: n.id, text: n.text, side: label, count: count2 });
40958
40960
  const key = label === "Yes" ? "yes" : label === "No" ? "no" : label === "For each" ? "each" : null;
40959
40961
  const next = key ? b[key] : (b.cases || []).find((c) => c.label === label)?.blocks;
40960
40962
  if (next?.length) {
@@ -41714,13 +41716,13 @@ function summaryOf(e) {
41714
41716
  function compareThings(A, B, items) {
41715
41717
  const key = (t) => `${stemKey2(t.file)}#${nameKey(t.name)}`;
41716
41718
  let pairs2 = pairBy(A.model.things, B.model.things, key);
41717
- const count = (list3) => {
41719
+ const count2 = (list3) => {
41718
41720
  const c = /* @__PURE__ */ new Map();
41719
41721
  for (const t of list3) c.set(nameKey(t.name), (c.get(nameKey(t.name)) || 0) + 1);
41720
41722
  return c;
41721
41723
  };
41722
41724
  const lonelyA = pairs2.filter(([a, b]) => a && !b).map(([a]) => a), lonelyB = pairs2.filter(([a, b]) => b && !a).map(([, b]) => b);
41723
- const ca = count(lonelyA), cb = count(lonelyB);
41725
+ const ca = count2(lonelyA), cb = count2(lonelyB);
41724
41726
  for (const a of lonelyA) {
41725
41727
  if (ca.get(nameKey(a.name)) !== 1 || cb.get(nameKey(a.name)) !== 1) continue;
41726
41728
  const b = lonelyB.find((t) => nameKey(t.name) === nameKey(a.name));
@@ -41949,8 +41951,8 @@ function thunderReview(oldFiles, newFiles) {
41949
41951
  }
41950
41952
  for (const x of items) if (x.also) x.subject = `${x.subject} and ${x.also.length} more`;
41951
41953
  items.sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity) || KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind) || String(a.where.file).localeCompare(String(b.where.file)) || (a.where.line ?? 0) - (b.where.line ?? 0));
41952
- const count = (s) => items.filter((x) => x.severity === s).length;
41953
- const summary2 = { meaning: count("meaning"), risk: count("risk"), form: count("form"), unchanged, files: paths.filter((p) => A.sources.get(p) !== B.sources.get(p)).length };
41954
+ const count2 = (s) => items.filter((x) => x.severity === s).length;
41955
+ const summary2 = { meaning: count2("meaning"), risk: count2("risk"), form: count2("form"), unchanged, files: paths.filter((p) => A.sources.get(p) !== B.sources.get(p)).length };
41954
41956
  const onlyNotRead = !items.length && summary2.files && notRead.length === summary2.files;
41955
41957
  return { schema: REVIEW_SCHEMA, summary: summary2, says: onlyNotRead ? "Only files Thunder does not read changed." : summaryLine(summary2), items, notRead };
41956
41958
  }
@@ -44268,8 +44270,8 @@ function renderLensDoc(ast, lens) {
44268
44270
  };
44269
44271
  ruleSection("Guarantees", ast.guarantees, "guarantee");
44270
44272
  ruleSection("Never", ast.neverRules, "never");
44271
- const count = (ast.notes || []).filter((n) => n.lens === lens).length;
44272
- L.push("---", `${count} \`${lens}\` note${count === 1 ? "" : "s"} in this mission.`);
44273
+ const count2 = (ast.notes || []).filter((n) => n.lens === lens).length;
44274
+ L.push("---", `${count2} \`${lens}\` note${count2 === 1 ? "" : "s"} in this mission.`);
44273
44275
  return L.join("\n");
44274
44276
  }
44275
44277
  function renderMermaid(ast) {
@@ -44787,8 +44789,8 @@ function resolveObligations(ast) {
44787
44789
  ...(ast.guarantees || []).map((g) => build("guarantee", g)),
44788
44790
  ...(ast.neverRules || []).map((n) => build("prohibition", n))
44789
44791
  ];
44790
- const count = (s) => obligations.filter((o) => o.status === s).length;
44791
- return { obligations, tests, verified: count("verified"), declared: count("declared"), unverified: count("unverified"), failed: count("failed") };
44792
+ const count2 = (s) => obligations.filter((o) => o.status === s).length;
44793
+ return { obligations, tests, verified: count2("verified"), declared: count2("declared"), unverified: count2("unverified"), failed: count2("failed") };
44792
44794
  }
44793
44795
 
44794
44796
  // src/review-atlas.mjs
@@ -46218,7 +46220,32 @@ var READING_LABELS = Object.freeze({
46218
46220
  givesNothing: "Nothing",
46219
46221
  getsNothing: "Nothing it hands back",
46220
46222
  partOf: (label) => `Part of ${label}`,
46221
- io: "What goes in and out"
46223
+ io: "What goes in and out",
46224
+ actions: "Actions and rules",
46225
+ // Flow: the words on each kind of edge. An edge label not listed here is shown as the compiler wrote it.
46226
+ edges: Object.freeze({ yes: "Yes", no: "No", each: "For each", done: "Done", error: "If it fails", nested: "Runs on its own", case: "When" }),
46227
+ openLine: (line) => `line ${line}`,
46228
+ openRule: "Open the rule",
46229
+ // Details: what each section is called.
46230
+ details: Object.freeze({
46231
+ stops: "When it stops",
46232
+ noStops: "Thunder found no place where it stops early.",
46233
+ noInputs: "Thunder found no inputs. Check Original if it reads a request or a file.",
46234
+ nothingBack: "Thunder found nothing it gives back.",
46235
+ changes: "What it changes, saves or sends",
46236
+ answers: "Its answers",
46237
+ limits: (fact) => `Exact limits for ${fact}`,
46238
+ limitsHow: "Found by running the rule on every whole number around each limit.",
46239
+ steps: "Every step, with its line",
46240
+ reliesOn: "It relies on",
46241
+ usedBy: "Used by",
46242
+ openQuestions: "Questions the code cannot answer",
46243
+ always: "Always",
46244
+ otherwise: "otherwise",
46245
+ when: (w) => `when ${w}`,
46246
+ usedOn: "used on",
46247
+ atAGlance: "At a glance"
46248
+ })
46222
46249
  });
46223
46250
  var memberSymbolId = (m) => m.kind === "action" || m.kind === "pipeline" ? "action" : m.kind === "rule" ? "rule" : m.kind === "setup" ? "setup" : m.kind === "not-read" ? "not-read" : "steps";
46224
46251
  var knowsLine = (k) => {
@@ -46255,6 +46282,10 @@ function dataCard(thing) {
46255
46282
  knows: thing.knows.map(knowsLine)
46256
46283
  };
46257
46284
  }
46285
+ var givesBackOf = (member) => {
46286
+ const list3 = member.youGetBack ? [member.youGetBack] : (member.flow?.nodes ?? []).filter((n) => n.kind === "end").map((n) => n.text.replace(/^Gives back\s+/i, ""));
46287
+ return [...new Set(list3.filter(Boolean))];
46288
+ };
46258
46289
  function ioBoxes(model, member) {
46259
46290
  const owner = member.owner ? model.things.find((t) => t.id === member.owner) : null;
46260
46291
  const kinds = member.inputKinds ?? {};
@@ -46266,22 +46297,67 @@ function ioBoxes(model, member) {
46266
46297
  doc: member.doc ?? null,
46267
46298
  symbol: memberSymbolId(member),
46268
46299
  give: { heading: READING_LABELS.give, items: member.youGive.map((label) => ({ label, kind: kinds[label] ?? null })), empty: READING_LABELS.givesNothing },
46269
- getBack: { heading: READING_LABELS.getBack, text: member.youGetBack ?? null, empty: READING_LABELS.getsNothing },
46300
+ // What it gives back: what the code declares, else the Flow's end steps (the same facts Flow and Details show).
46301
+ getBack: { heading: READING_LABELS.getBack, text: member.youGetBack ?? null, items: givesBackOf(member), empty: READING_LABELS.getsNothing },
46270
46302
  stops: { heading: READING_LABELS.stops, items: stops },
46271
46303
  partOf: owner ? { id: owner.id, text: READING_LABELS.partOf(owner.label) } : null
46272
46304
  };
46273
46305
  }
46274
- var sectionsFor = (model, things) => {
46306
+ function flowEdgeLabel(edge) {
46307
+ if (!edge.label || edge.label === "next") return null;
46308
+ if (edge.label === "case") return edge.text ?? READING_LABELS.edges.case;
46309
+ return READING_LABELS.edges[edge.label] ?? edge.text ?? edge.label;
46310
+ }
46311
+ var count = (n, one, many) => ({ count: n, text: n === 1 ? one : many });
46312
+ function detailsLayout(view2) {
46313
+ const L = READING_LABELS.details;
46314
+ const inputs = view2.inputs ?? (view2.youGive ?? []).map((label) => ({ label, lines: [] }));
46315
+ const givesBack = view2.givesBack?.length ? view2.givesBack.map((g) => ({ text: g.text, line: g.line ?? null, when: g.when ?? null })) : view2.youGetBack ? [{ text: view2.youGetBack, line: null, when: null }] : (view2.flow?.nodes ?? []).filter((n) => n.kind === "end").map((n) => ({ text: n.text, line: n.line ?? null, when: null }));
46316
+ const steps = view2.steps ?? [];
46317
+ const stops = view2.stops ?? null;
46318
+ const changes = view2.changes ?? null;
46319
+ const reliesOn = view2.reliesOn ?? (view2.uses ?? []).map((u) => ({ id: u.id, label: u.label, symbol: "rule", says: "" }));
46320
+ const stats = [
46321
+ ...inputs.length ? [{ id: "inputs", ...count(inputs.length, "thing you give it", "things you give it") }] : [],
46322
+ { id: "steps", ...count(steps.length, "step", "steps") },
46323
+ ...stops ? [{ id: "stops", ...count(stops.length, "way to stop", "ways to stop") }] : [],
46324
+ ...changes ? [{ id: "changes", ...count(changes.length, "change", "changes") }] : [],
46325
+ ...reliesOn.length ? [{ id: "reliesOn", count: reliesOn.length, text: "relies on" }] : [],
46326
+ ...(view2.notExplained ?? 0) > 0 ? [{ id: "notExplained", count: view2.notExplained, text: "not explained yet" }] : []
46327
+ ];
46328
+ return {
46329
+ id: view2.id ?? null,
46330
+ title: view2.title ?? null,
46331
+ heading: L.atAGlance,
46332
+ stats,
46333
+ give: inputs.length || givesBack.length ? { heading: READING_LABELS.give, items: inputs.map((i) => ({ label: i.label, lines: i.lines ?? [] })), empty: L.noInputs } : null,
46334
+ getBack: inputs.length || givesBack.length ? { heading: READING_LABELS.getBack, items: givesBack, empty: L.nothingBack } : null,
46335
+ stops: stops ? { heading: L.stops, items: stops.map((s) => ({ error: s.error, message: s.message ?? null, line: s.line ?? null, when: s.when ?? [] })), empty: L.noStops } : null,
46336
+ changes: changes?.length ? { heading: L.changes, items: changes.map((c) => ({ text: c.text, does: c.does ?? null, line: c.line ?? null, when: c.when ?? [] })) } : null,
46337
+ answers: view2.answers?.length ? { heading: L.answers, items: view2.answers.map((a) => ({ answer: a.answer, when: a.when === "otherwise" ? L.otherwise : L.when(a.when) })) } : null,
46338
+ limits: view2.limits ? { heading: L.limits(view2.limits.fact), note: L.limitsHow, items: view2.limits.ranges.map((r) => ({ range: r.from == null ? `${r.to} or less` : r.to == null ? `${r.from} or more` : r.from === r.to ? `${r.from}` : `${r.from} to ${r.to}`, answer: r.answer })) } : null,
46339
+ steps: steps.length ? { heading: L.steps, items: steps.map((s) => ({ id: s.id, text: s.text, does: s.does ?? null, mark: s.mark ?? null, depth: s.depth ?? 0, line: s.line ?? null, notExplained: !!s.notExplained, via: s.via ?? null })) } : null,
46340
+ reliesOn: reliesOn.length ? { heading: L.reliesOn, items: reliesOn.map((r) => ({ id: r.id, label: r.label, symbol: r.symbol ?? "rule", says: r.says ?? "" })) } : null,
46341
+ usedBy: view2.usedBy?.length ? { heading: L.usedBy, items: view2.usedBy.map((u) => ({ id: u.id, label: u.label })) } : null,
46342
+ openQuestions: view2.openQuestions?.length ? { heading: L.openQuestions, items: [...view2.openQuestions] } : null,
46343
+ source: view2.source ?? null
46344
+ };
46345
+ }
46346
+ var memberEntry = (m) => ({ kind: "member", id: m.id, label: `${m.label}${m.yesNo ? "?" : ""}`, symbol: memberSymbolId(m), doc: m.doc ?? null });
46347
+ var sectionsFor = (model, things, loose = []) => {
46275
46348
  const cards = things.filter((t) => t.kind === "thing").map((t) => thingCard(model, t));
46276
46349
  const data = [...things.filter((t) => t.kind === "record"), ...things.filter((t) => t.kind === "choices")].map(dataCard);
46350
+ const actions = loose.map(memberEntry);
46277
46351
  return [
46278
46352
  ...cards.length ? [{ id: "things", heading: READING_LABELS.things, cards }] : [],
46279
- ...data.length ? [{ id: "data", heading: READING_LABELS.data, cards: data }] : []
46353
+ ...data.length ? [{ id: "data", heading: READING_LABELS.data, cards: data }] : [],
46354
+ ...actions.length ? [{ id: "actions", heading: READING_LABELS.actions, cards: actions }] : []
46280
46355
  ];
46281
46356
  };
46357
+ var ownerless = (model, file) => model.members.filter((m) => !m.owner && (file == null || m.file === file));
46282
46358
  function readingLayout(model, { focus = null } = {}) {
46283
46359
  const base2 = { schema: READING_LAYOUT_SCHEMA };
46284
- if (focus == null) return { ...base2, focus: { kind: "app", id: null }, sections: sectionsFor(model, model.things) };
46360
+ if (focus == null) return { ...base2, focus: { kind: "app", id: null }, sections: sectionsFor(model, model.things, ownerless(model)) };
46285
46361
  const member = model.members.find((m) => m.id === focus);
46286
46362
  if (member) return { ...base2, focus: { kind: "member", id: focus }, sections: [{ id: "io", heading: READING_LABELS.io, cards: [ioBoxes(model, member)] }] };
46287
46363
  const thing = model.things.find((t) => t.id === focus);
@@ -46289,7 +46365,7 @@ function readingLayout(model, { focus = null } = {}) {
46289
46365
  const rest2 = model.things.filter((t) => t !== thing && t.file === thing.file && t.kind !== "thing");
46290
46366
  return { ...base2, focus: { kind: "thing", id: focus }, sections: sectionsFor(model, [thing, ...rest2]) };
46291
46367
  }
46292
- if (model.files.some((f) => f.path === focus)) return { ...base2, focus: { kind: "file", id: focus }, sections: sectionsFor(model, model.things.filter((t) => t.file === focus)) };
46368
+ if (model.files.some((f) => f.path === focus)) return { ...base2, focus: { kind: "file", id: focus }, sections: sectionsFor(model, model.things.filter((t) => t.file === focus), ownerless(model, focus)) };
46293
46369
  return { ...base2, focus: { kind: "unknown", id: focus }, sections: [] };
46294
46370
  }
46295
46371
  // Annotate the CommonJS export names for ESM import in node:
@@ -46460,6 +46536,7 @@ function readingLayout(model, { focus = null } = {}) {
46460
46536
  describeEdit,
46461
46537
  detailOf,
46462
46538
  detailParts,
46539
+ detailsLayout,
46463
46540
  detectLanguage,
46464
46541
  diffGraphs,
46465
46542
  displayLabel,
@@ -46472,6 +46549,7 @@ function readingLayout(model, { focus = null } = {}) {
46472
46549
  explainPlain,
46473
46550
  exprCounts,
46474
46551
  findSameRule,
46552
+ flowEdgeLabel,
46475
46553
  flowOf,
46476
46554
  formatMoney,
46477
46555
  formatValue,
package/dist/index.cjs CHANGED
@@ -2585,7 +2585,7 @@ function notesSummary(ast) {
2585
2585
  byLens
2586
2586
  };
2587
2587
  }
2588
- var COMPILER_VERSION = "1.4.1";
2588
+ var COMPILER_VERSION = "1.4.3";
2589
2589
  var PROOF_SCHEMA_VERSION = "0.1.0";
2590
2590
  var SOURCE_PRODUCT = "skillstech-compiler";
2591
2591
  function buildContractGraph(ast, generatedAt) {
package/dist/learn.cjs CHANGED
@@ -17250,7 +17250,7 @@ var SEMANTIC_TYPES = Object.keys(SEMANTIC);
17250
17250
  var PRIMITIVE_TYPES = Object.keys(PRIMITIVE);
17251
17251
 
17252
17252
  // src/emit.mjs
17253
- var COMPILER_VERSION = "1.4.1";
17253
+ var COMPILER_VERSION = "1.4.3";
17254
17254
 
17255
17255
  // src/lift.mjs
17256
17256
  var IR_SCHEMA_VERSION = "0.1.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillstech/thunderlang",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "Thunder™, the human programming language: the deterministic ThunderLang™ compiler, CLI, and Language Server. No AI required. Reads code in seventeen languages into Thunder, changes TypeScript, JavaScript, Python, and Go code from Thunder with a proof, compiles rules to six languages, and executes them: 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/core.d.ts CHANGED
@@ -202,5 +202,5 @@ export function writeRuleAcross(files: WriteAcrossFile[], options: { decision: s
202
202
  export function writeAcrossEvidence(result: WriteAcrossResult | { ok: false }): Array<{ kind: 'rule-write'; status: 'read'; claim: string; basis: unknown; scope: string; inputs: Array<{ part?: string; file: string }> }>;
203
203
 
204
204
  // What a reading shows and in what order (src/reading-layout.mjs).
205
- export { READING_LAYOUT_SCHEMA, READING_LABELS, readingLayout, thingCard, dataCard, ioBoxes, memberSymbolId } from './reading-layout.mjs';
206
- export type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, KnowsLine, ThunderSymbolId } from './reading-layout.d.mts';
205
+ export { READING_LAYOUT_SCHEMA, READING_LABELS, readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, memberSymbolId } from './reading-layout.mjs';
206
+ export type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, MemberEntryLayout, DetailsLayout, When, KnowsLine, ThunderSymbolId } from './reading-layout.d.mts';
package/src/core.mjs CHANGED
@@ -139,4 +139,4 @@ export { stepShape } from './write-steps.mjs';
139
139
  export { PASSPORT_SCHEMA, ALWAYS_NOT_VERIFIED, assemblePassport, summarize, checkPassport, renderPassportSummary, renderPassportMarkdown } from './passport.mjs';
140
140
  export { formatValue } from './plain-contract.mjs';
141
141
  // What a reading shows and in what order (the drawing kit, @skillstech/thunderlang/react, draws from it).
142
- export { READING_LAYOUT_SCHEMA, READING_LABELS, readingLayout, thingCard, dataCard, ioBoxes, memberSymbolId } from './reading-layout.mjs';
142
+ export { READING_LAYOUT_SCHEMA, READING_LABELS, readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, memberSymbolId } from './reading-layout.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 = '1.4.1';
33
+ export const COMPILER_VERSION = '1.4.3';
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.
@@ -109,11 +109,116 @@
109
109
  /* The Big Picture */
110
110
  .tl-big-picture { display: grid; gap: 24px; }
111
111
  .tl-bp-things { display: grid; gap: 20px; }
112
- .tl-bp-data { display: grid; gap: 16px; grid-template-columns: 1fr; }
113
- @media (min-width: 760px) { .tl-bp-data { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
112
+ .tl-bp-data { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
113
+ .tl-bp-heading { margin: 0 0 8px !important; }
114
+ .tl-door-text { display: grid; gap: 2px; min-width: 0; }
115
+ .tl-door-doc { font-size: 13px; color: var(--tl-text-muted); }
116
+ .tl-ability.tl-selected { border-color: var(--tl-accent); }
114
117
  @media (max-width: 420px) {
115
118
  .tl-thing { padding: 18px; }
116
119
  .tl-card { padding: 16px; }
117
120
  .tl-card-title { font-size: 21px; }
118
121
  }
119
122
  @media (prefers-reduced-motion: no-preference) { .tl-ability-button, .tl-starts-button { transition: border-color 120ms, color 120ms; } }
123
+
124
+ /* Shared small parts */
125
+ .tl-quiet { font-size: 13px; color: var(--tl-text-quiet); }
126
+ .tl-strong { font-size: 15px; color: var(--tl-text); }
127
+ .tl-line { flex: none; margin-left: auto; min-height: 28px; background: none; border: 0; padding: 2px 6px; border-radius: 6px; font: 12px ui-monospace, Menlo, monospace; color: var(--tl-text-quiet); cursor: pointer; }
128
+ .tl-line-inline { margin-left: 0; min-height: 0; padding: 0 2px; }
129
+ .tl-line:hover { background: color-mix(in srgb, var(--tl-text) 6%, transparent); color: var(--tl-text); }
130
+ .tl-line:focus-visible, .tl-node-use:focus-visible, .tl-part-of-button:focus-visible { outline: 2px solid var(--tl-focus); outline-offset: 2px; }
131
+ .tl-pills { display: flex; flex-wrap: wrap; gap: 8px; }
132
+ .tl-pill { display: inline-block; border-radius: 8px; padding: 4px 10px; font-size: 14px; border: 1px solid; }
133
+ .tl-pill-fact { color: var(--tl-c-fact); border-color: color-mix(in srgb, var(--tl-c-fact) 30%, transparent); background: color-mix(in srgb, var(--tl-c-fact) 8%, transparent); }
134
+ .tl-pill-outcome { color: var(--tl-c-outcome); border-color: color-mix(in srgb, var(--tl-c-outcome) 30%, transparent); background: color-mix(in srgb, var(--tl-c-outcome) 8%, transparent); }
135
+ .tl-pill-kind { color: var(--tl-text-muted); }
136
+
137
+ /* What goes in and out (the Big Picture of one action or rule) */
138
+ .tl-io-card { display: grid; gap: 14px; }
139
+ .tl-io-doc { margin-top: 0 !important; }
140
+ .tl-io { display: grid; gap: 14px; grid-template-columns: 1fr; }
141
+ @media (min-width: 560px) { .tl-io { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
142
+ .tl-io-box { border: 1px solid var(--tl-border); border-radius: var(--tl-radius-small); background: var(--tl-surface-raised); padding: 14px 16px; }
143
+ .tl-io-give { border-left: 3px solid var(--tl-c-fact); }
144
+ .tl-io-back { border-left: 3px solid var(--tl-c-outcome); }
145
+ .tl-io-stops, .tl-details-stops { border-left: 3px solid var(--tl-c-failure); }
146
+ .tl-io-label, .tl-details-h { display: flex; align-items: center; gap: 6px; margin: 0 0 10px !important; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--tl-text-muted); }
147
+ .tl-stop-list { display: grid; gap: 6px; }
148
+ .tl-stop-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--tl-text-body); }
149
+ .tl-stop-row .tl-symbol, .tl-io-stops .tl-io-label .tl-symbol { color: var(--tl-c-failure); }
150
+ .tl-stop-text { min-width: 0; }
151
+ .tl-part-of { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--tl-text-muted); }
152
+ .tl-part-of-button { min-height: 44px; border: 0; background: none; padding: 0; font: inherit; font-size: 14px; color: var(--tl-text-muted); cursor: pointer; text-align: left; }
153
+ .tl-part-of-button:hover { color: var(--tl-text); }
154
+
155
+ /* Flow */
156
+ .tl-flow { position: relative; display: grid; column-gap: 56px; row-gap: 22px; padding: 6px 4px 12px; overflow-x: auto; }
157
+ .tl-edges { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
158
+ .tl-edges marker path { fill: var(--tl-text-quiet); }
159
+ .tl-edge path { fill: none; stroke: var(--tl-text-quiet); stroke-width: 1.6; }
160
+ .tl-edge-yes path { stroke: var(--tl-c-question); }
161
+ .tl-edge-no path { stroke: var(--tl-c-unread); stroke-dasharray: 5 4; }
162
+ .tl-edge-error path { stroke: var(--tl-c-failure); }
163
+ .tl-edge text { font-size: 11px; font-weight: 600; fill: var(--tl-text-muted); paint-order: stroke; stroke: var(--tl-surface); stroke-width: 4px; }
164
+ .tl-edge-yes text { fill: var(--tl-c-question); }
165
+ .tl-node { --tl-tone: var(--tl-text-quiet); position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 9px 12px; border-radius: var(--tl-radius-small); border: 1px solid var(--tl-border); border-left: 3px solid var(--tl-tone); background: var(--tl-surface-raised); font-size: 14px; color: var(--tl-text-body); }
166
+ .tl-tone-structure { --tl-tone: var(--tl-c-structure); } .tl-tone-question { --tl-tone: var(--tl-c-question); } .tl-tone-fact { --tl-tone: var(--tl-c-fact); }
167
+ .tl-tone-comparison { --tl-tone: var(--tl-c-comparison); } .tl-tone-outcome { --tl-tone: var(--tl-c-outcome); } .tl-tone-failure { --tl-tone: var(--tl-c-failure); }
168
+ .tl-tone-unread { --tl-tone: var(--tl-c-unread); } .tl-tone-amount { --tl-tone: var(--tl-c-amount); }
169
+ .tl-node-mark { flex: none; width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; color: var(--tl-tone); background: color-mix(in srgb, var(--tl-text) 5%, transparent); font-weight: 700; }
170
+ .tl-node-mark .tl-symbol { color: var(--tl-tone); }
171
+ .tl-node-text { flex: 1; min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
172
+ .tl-node-decision { background: color-mix(in srgb, var(--tl-c-question) 7%, var(--tl-surface-raised)); }
173
+ .tl-node-decision .tl-node-text { font-weight: 600; }
174
+ .tl-node-stop { background: color-mix(in srgb, var(--tl-c-failure) 8%, var(--tl-surface-raised)); }
175
+ .tl-node-start { background: color-mix(in srgb, var(--tl-c-fact) 6%, var(--tl-surface-raised)); }
176
+ .tl-node-code { border-style: dashed; }
177
+ .tl-node-code code { font-size: 12px; color: var(--tl-text-muted); }
178
+ .tl-node-use { flex: none; min-height: 28px; background: none; border: 0; padding: 2px 6px; border-radius: 6px; font: inherit; font-size: 12px; color: var(--tl-c-question); cursor: pointer; }
179
+ .tl-node-use:hover { background: color-mix(in srgb, var(--tl-text) 6%, transparent); }
180
+ .tl-mark-added { box-shadow: 0 0 0 2px color-mix(in srgb, var(--tl-c-pass) 60%, transparent); }
181
+ .tl-mark-removed { box-shadow: 0 0 0 2px color-mix(in srgb, var(--tl-c-fail) 60%, transparent); opacity: 0.85; }
182
+ .tl-badge { flex: none; border-radius: 6px; padding: 1px 6px; font-size: 11px; font-weight: 700; }
183
+ .tl-badge-added { color: var(--tl-c-pass); background: color-mix(in srgb, var(--tl-c-pass) 14%, transparent); }
184
+ .tl-badge-removed { color: var(--tl-c-fail); background: color-mix(in srgb, var(--tl-c-fail) 14%, transparent); }
185
+
186
+ /* Details */
187
+ .tl-details { display: flex; flex-direction: column; gap: 14px; }
188
+ .tl-details-card { padding: 14px 16px; border-radius: var(--tl-radius-small); }
189
+ .tl-details .tl-io-give, .tl-details .tl-io-back { border-left-width: 3px; }
190
+ .tl-stats { display: flex; flex-wrap: wrap; gap: 8px; }
191
+ .tl-stat { padding: 6px 12px; border-radius: 999px; background: var(--tl-surface-raised); border: 1px solid var(--tl-border); font-size: 13px; color: var(--tl-text-muted); }
192
+ .tl-stat b { color: var(--tl-text); font-size: 14px; margin-right: 2px; }
193
+ .tl-stat-stops b { color: var(--tl-c-failure); }
194
+ .tl-stat-notExplained b { color: var(--tl-c-unread); }
195
+ .tl-rows { display: grid; gap: 10px; }
196
+ .tl-row-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
197
+ .tl-message { color: var(--tl-text-muted); font-size: 14px; }
198
+ .tl-inputs { display: grid; gap: 8px; }
199
+ .tl-inputs li { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
200
+ .tl-used { font-size: 12px; color: var(--tl-text-quiet); }
201
+ .tl-when { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; }
202
+ .tl-cond { display: inline-flex; align-items: center; gap: 6px; }
203
+ .tl-cond-q { color: var(--tl-text-body); }
204
+ .tl-cond-and { color: var(--tl-text-quiet); margin-left: 2px; }
205
+ .tl-ans { display: inline-block; flex: none; white-space: nowrap; padding: 1px 7px; border-radius: 6px; font-size: 12px; font-weight: 700; }
206
+ .tl-ans-yes { color: var(--tl-c-question); background: color-mix(in srgb, var(--tl-c-question) 12%, transparent); }
207
+ .tl-ans-no { color: var(--tl-text-muted); background: color-mix(in srgb, var(--tl-c-unread) 14%, transparent); }
208
+ .tl-ans-each { color: var(--tl-c-structure); background: color-mix(in srgb, var(--tl-c-structure) 12%, transparent); }
209
+ .tl-does { flex: none; width: 22px; text-align: center; font-weight: 700; }
210
+ .tl-answers { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
211
+ .tl-limits-note { margin: -4px 0 10px !important; }
212
+ .tl-limits { display: flex; flex-wrap: wrap; gap: 8px; }
213
+ .tl-limit { display: flex; gap: 8px; align-items: baseline; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--tl-border); }
214
+ .tl-range { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--tl-c-amount); }
215
+ .tl-steps { display: grid; gap: 2px; }
216
+ .tl-steps li { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-bottom: 1px solid var(--tl-border); font-size: 14px; }
217
+ .tl-steps li:last-child { border-bottom: 0; }
218
+ .tl-step-text { flex: 1; min-width: 0; }
219
+ .tl-step-code code, .tl-step-text code { font-size: 12px; color: var(--tl-text-muted); }
220
+ .tl-source { font-size: 12px; color: var(--tl-text-quiet); }
221
+ @media (max-width: 420px) {
222
+ .tl-io-box, .tl-details-card { padding: 12px; }
223
+ .tl-flow { column-gap: 32px; }
224
+ }
@@ -1,9 +1,9 @@
1
- import type { ReactElement } from 'react';
2
- import type { ThunderModel, Thing } from '../model.d.mts';
3
- import type { ReadingLayout, ThingCardLayout, DataCardLayout, ThunderSymbolId } from '../reading-layout.d.mts';
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ import type { ThunderModel, Thing, Member } from '../model.d.mts';
3
+ import type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, MemberEntryLayout, DetailsLayout, ThunderSymbolId } from '../reading-layout.d.mts';
4
4
 
5
- export { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS } from '../reading-layout.mjs';
6
- export type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, ThunderSymbolId } from '../reading-layout.d.mts';
5
+ export { readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, READING_LABELS } from '../reading-layout.mjs';
6
+ export type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, DetailsLayout, When, ThunderSymbolId } from '../reading-layout.d.mts';
7
7
 
8
8
  /** A Thunder symbol; its color is the CSS variable for its grammar color (--tl-c-*). */
9
9
  export function ThunderSymbol(props: { id: ThunderSymbolId; size?: number; label?: string }): ReactElement | null;
@@ -11,5 +11,15 @@ export function ThunderSymbol(props: { id: ThunderSymbolId; size?: number; label
11
11
  export function ThingCard(props: { card?: ThingCardLayout; model?: ThunderModel; thing?: Thing; onOpen?: (memberId: string) => void; selected?: boolean; headingLevel?: 2 | 3 | 4 }): ReactElement;
12
12
  /** A Data card: a record or choices. Pass `card` or `thing`. */
13
13
  export function DataCard(props: { card?: DataCardLayout; thing?: Thing; headingLevel?: 2 | 3 | 4 }): ReactElement;
14
- /** The Big Picture: every Thing, then records and choices. */
15
- export function BigPicture(props: { model?: ThunderModel; layout?: ReadingLayout; focus?: string | null; onOpen?: (memberId: string) => void; selectedId?: string; headingLevel?: 2 | 3 }): ReactElement;
14
+ /** You give it / You get back / It can stop with, and "Part of <Thing>". Pass `card` or `model` and `member`. */
15
+ export function IOBoxes(props: { card?: IOBoxesLayout; model?: ThunderModel; member?: Member; onLine?: (line: number) => void; onThing?: (thingId: string) => void; headingLevel?: 2 | 3 | 4; children?: ReactNode }): ReactElement;
16
+ /** The Big Picture, zoomed by focus: Things then Data, or an action's or rule's IO boxes (children go under them). */
17
+ export function BigPicture(props: { model?: ThunderModel; layout?: ReadingLayout; focus?: string | null; onOpen?: (memberId: string) => void; onLine?: (line: number) => void; onThing?: (thingId: string) => void; selectedId?: string; headingLevel?: 2 | 3; children?: ReactNode }): ReactElement;
18
+ export interface FlowGraph {
19
+ nodes: { id: string; kind: string; text: string; lane: number; row: number; line?: number | null; does?: string; uses?: string; code?: boolean }[];
20
+ edges: { from: string; to: string; label?: string | null; text?: string }[];
21
+ }
22
+ /** Flow: every step at the compiler's lane and row, with its edges. */
23
+ export function Flow(props: { flow: FlowGraph; onLine?: (line: number) => void; onUse?: (memberId: string) => void; useLabel?: (memberId: string) => string | undefined; marks?: Set<string>; markAs?: 'added' | 'removed' }): ReactElement;
24
+ /** Details: the same action sorted into facts, each with its line. Pass `view` (readLevel details) or `layout`. */
25
+ export function Details(props: { view?: Record<string, any>; layout?: DetailsLayout; onLine?: (line: number) => void; rules?: ReactNode; headingLevel?: 2 | 3 | 4 }): ReactElement;
@@ -4,11 +4,11 @@
4
4
  // Styling: plain `tl-` class names and one stylesheet (@skillstech/thunderlang/react/reading.css) whose colors are
5
5
  // CSS variables, so each app sets its own (STT's --language-accent is honored). No JSX, no build step, no Tailwind:
6
6
  // React is the only dependency, and it is the app's own (a peer dependency).
7
- import { createElement as h, Fragment } from 'react';
7
+ import { createElement as h, Fragment, useLayoutEffect, useRef, useState } from 'react';
8
8
  import { THUNDER_VISUAL } from '../visual.mjs';
9
- import { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS } from '../reading-layout.mjs';
9
+ import { readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, READING_LABELS } from '../reading-layout.mjs';
10
10
 
11
- export { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS };
11
+ export { readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, READING_LABELS };
12
12
 
13
13
  /** A Thunder symbol, from the grammar's own path data. Its color is the CSS variable for its grammar color. */
14
14
  export function ThunderSymbol({ id, size = 28, label }) {
@@ -74,14 +74,188 @@ export function DataCard({ card, thing, headingLevel = 3 }) {
74
74
  c.knows.length ? h('ul', { className: 'tl-knows tl-knows-small' }, c.knows.map(knowsItem)) : null);
75
75
  }
76
76
 
77
+ /** A "line N" button that opens the original code there, or nothing without onLine or a line. */
78
+ const LineButton = ({ line, onLine, className = 'tl-line' }) => (line == null || !onLine ? null
79
+ : h('button', { type: 'button', className, onClick: () => onLine(line), title: 'See the original code at this line' }, READING_LABELS.openLine(line)));
80
+
81
+ /**
82
+ * What goes in and out of one action or rule: You give it, You get back, It can stop with, and "Part of <Thing>".
83
+ * card: ioBoxes(model, member), or pass `model` and `member`.
84
+ * onLine(line) makes each stop's line a button; onThing(thingId) makes "Part of …" a button back to its card.
85
+ * children: anything the app adds under the boxes (an AI summary, nearby rules).
86
+ */
87
+ export function IOBoxes({ card, model, member, onLine, onThing, headingLevel = 3, children }) {
88
+ const c = card ?? ioBoxes(model, member);
89
+ const H = `h${headingLevel}`;
90
+ return h('section', { className: 'tl-card tl-io-card', 'aria-label': READING_LABELS.io },
91
+ c.doc ? h('p', { className: 'tl-doc tl-io-doc' }, c.doc) : null,
92
+ h('div', { className: 'tl-io' },
93
+ h('section', { className: 'tl-io-box tl-io-give' },
94
+ h(H, { className: 'tl-io-label' }, h('span', { 'aria-hidden': true }, '→ '), c.give.heading),
95
+ c.give.items.length
96
+ ? h('ul', { className: 'tl-pills' }, c.give.items.map((g) => h('li', { key: g.label, className: 'tl-pill tl-pill-fact' }, g.label, g.kind ? h('span', { className: 'tl-pill-kind' }, `: ${g.kind}`) : null)))
97
+ : h('p', { className: 'tl-quiet' }, c.give.empty)),
98
+ h('section', { className: 'tl-io-box tl-io-back' },
99
+ h(H, { className: 'tl-io-label' }, h('span', { 'aria-hidden': true }, '⇥ '), c.getBack.heading),
100
+ c.getBack.items.length ? h('ul', { className: 'tl-pills' }, c.getBack.items.map((t) => h('li', { key: t, className: 'tl-pill tl-pill-outcome' }, t))) : h('p', { className: 'tl-quiet' }, c.getBack.empty))),
101
+ c.stops.items.length ? h('section', { className: 'tl-io-box tl-io-stops' },
102
+ h(H, { className: 'tl-io-label' }, h(ThunderSymbol, { id: 'stop', size: 14 }), ' ', c.stops.heading),
103
+ h('ul', { className: 'tl-stop-list' }, c.stops.items.map((x, i) => h('li', { key: i, className: 'tl-stop-row' },
104
+ h(ThunderSymbol, { id: 'stop', size: 14 }), h('span', { className: 'tl-stop-text' }, x.text), h(LineButton, { line: x.line, onLine }))))) : null,
105
+ children ?? null,
106
+ c.partOf ? (onThing
107
+ ? h('button', { type: 'button', className: 'tl-part-of tl-part-of-button', onClick: () => onThing(c.partOf.id) }, h(ThunderSymbol, { id: 'thing', size: 18 }), c.partOf.text)
108
+ : h('p', { className: 'tl-part-of' }, h(ThunderSymbol, { id: 'thing', size: 18 }), c.partOf.text)) : null);
109
+ }
110
+
111
+ /** One action or rule on its own: its symbol, name, and doc; a button when the app can open it. */
112
+ function MemberDoor({ m, onOpen, selected }) {
113
+ const inner = h(Fragment, null,
114
+ h(ThunderSymbol, { id: m.symbol, size: 24 }),
115
+ h('span', { className: 'tl-door-text' }, h('span', { className: 'tl-ability-label' }, m.label), m.doc ? h('span', { className: 'tl-door-doc' }, m.doc) : null),
116
+ onOpen ? h('span', { className: 'tl-ability-go', 'aria-hidden': true }, '→') : null);
117
+ const cls = `tl-ability${selected ? ' tl-selected' : ''}`;
118
+ return onOpen ? h('button', { type: 'button', className: `${cls} tl-ability-button`, onClick: () => onOpen(m.id) }, inner) : h('div', { className: cls }, inner);
119
+ }
120
+
77
121
  /**
78
- * The Big Picture, zoomed by `focus` (see readingLayout). The IO boxes for an action or rule are drawn by IOBoxes,
79
- * which joins the kit next; until then that section is left to the app.
122
+ * The Big Picture, zoomed by `focus` (see readingLayout): Things and Data, or, for an action or rule, its IO boxes.
80
123
  */
81
- export function BigPicture({ model, layout, focus = null, onOpen, selectedId, headingLevel = 2 }) {
124
+ export function BigPicture({ model, layout, focus = null, onOpen, onLine, onThing, selectedId, headingLevel = 2, children }) {
82
125
  const l = layout ?? readingLayout(model, { focus });
83
- return h('div', { className: 'tl-reading tl-big-picture' }, l.sections.filter((s) => s.id !== 'io').map((s) => h('section', { key: s.id, className: `tl-bp-section tl-bp-${s.id}`, 'aria-label': s.heading },
84
- h('div', { className: s.id === 'things' ? 'tl-bp-things' : 'tl-bp-data' }, s.cards.map((c) => (c.kind === 'thing'
85
- ? h(ThingCard, { key: c.id, card: c, onOpen, selected: c.id === selectedId, headingLevel })
86
- : h(DataCard, { key: c.id, card: c, headingLevel: headingLevel + 1 })))))));
126
+ return h('div', { className: 'tl-reading tl-big-picture' }, l.sections.map((s) => h('section', { key: s.id, className: `tl-bp-section tl-bp-${s.id}`, 'aria-label': s.heading },
127
+ s.id === 'io'
128
+ ? s.cards.map((c) => h(IOBoxes, { key: c.id, card: c, onLine, onThing, headingLevel: headingLevel + 1 }, children))
129
+ : s.id === 'actions'
130
+ ? h(Fragment, null, h(`h${headingLevel}`, { className: 'tl-section-label tl-bp-heading' }, s.heading), h('ul', { className: 'tl-abilities tl-bp-actions-list' }, s.cards.map((m) => h('li', { key: m.id }, h(MemberDoor, { m, onOpen, selected: m.id === selectedId })))))
131
+ : h('div', { className: s.id === 'things' ? 'tl-bp-things' : 'tl-bp-data' }, s.cards.map((c) => (c.kind === 'thing'
132
+ ? h(ThingCard, { key: c.id, card: c, onOpen, selected: c.id === selectedId, headingLevel })
133
+ : h(DataCard, { key: c.id, card: c, headingLevel: headingLevel + 1 })))))));
134
+ }
135
+
136
+ const doesOf = (does) => THUNDER_VISUAL.does[does ?? ''] ?? { mark: '·', label: 'Does', color: 'structure' };
137
+
138
+ /**
139
+ * Flow: one action or rule, step by step. Every node sits at the lane and row the compiler gives it, every edge is
140
+ * the compiler's (Yes / No / For each / Done / If it fails), each node's mark and color come from DOES. Steps Thunder
141
+ * could only show as code are dashed. The app adds only the interaction:
142
+ * flow: member.flow (or readLevel(model, 'flow', id).flow)
143
+ * onLine(line): each node's line opens the original code. onUse(memberId): a step that uses a rule opens it.
144
+ * marks + markAs: Thunder Diff highlights nodes as 'added' (New) or 'removed' (Gone).
145
+ * Edges are measured from the drawn nodes, so they appear after the first paint (none in server rendering).
146
+ */
147
+ export function Flow({ flow, onLine, onUse, useLabel, marks, markAs }) {
148
+ const box = useRef(null);
149
+ const refs = useRef(new Map());
150
+ const [pos, setPos] = useState(() => new Map());
151
+ const [size, setSize] = useState({ w: 0, h: 0 });
152
+ const lanes = Math.max(1, ...flow.nodes.map((n) => n.lane + 1));
153
+ useLayoutEffect(() => {
154
+ const measure = () => {
155
+ const root = box.current?.getBoundingClientRect();
156
+ if (!root) return;
157
+ const next = new Map();
158
+ for (const [id, el] of refs.current) { const r = el.getBoundingClientRect(); next.set(id, { x: r.left - root.left, y: r.top - root.top, w: r.width, h: r.height }); }
159
+ setPos(next);
160
+ setSize({ w: box.current.clientWidth, h: box.current.scrollHeight });
161
+ };
162
+ measure();
163
+ const ro = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(measure) : null;
164
+ if (ro && box.current) ro.observe(box.current);
165
+ return () => ro?.disconnect();
166
+ }, [flow]);
167
+ const edges = flow.edges.map((e, i) => {
168
+ const a = pos.get(e.from), b = pos.get(e.to);
169
+ if (!a || !b) return null;
170
+ const same = Math.abs(a.x - b.x) < 4;
171
+ const x1 = same ? a.x + a.w / 2 : a.x + a.w, y1 = same ? a.y + a.h : a.y + a.h / 2;
172
+ const x2 = same ? b.x + b.w / 2 : b.x + (b.x > a.x ? 0 : b.w), y2 = same ? b.y : b.y + b.h / 2;
173
+ const d = same ? `M${x1} ${y1} L${x2} ${y2 - 2}` : `M${x1} ${y1} C${(x1 + x2) / 2} ${y1}, ${(x1 + x2) / 2} ${y2}, ${x2 + (b.x > a.x ? -2 : 2)} ${y2}`;
174
+ const label = flowEdgeLabel(e);
175
+ const lx = same ? x1 + 8 : (x1 + x2) / 2, ly = same ? (y1 + y2) / 2 + 4 : Math.min(y1, y2) - 6 + Math.abs(y2 - y1) / 2;
176
+ return h('g', { key: i, className: `tl-edge tl-edge-${e.label ?? 'next'}` }, h('path', { d, markerEnd: 'url(#tl-arrow)' }), label ? h('text', { x: lx, y: ly }, label) : null);
177
+ });
178
+ return h('div', { className: 'tl-reading tl-flow', ref: box, style: { gridTemplateColumns: `repeat(${lanes}, minmax(200px, 1fr))` } },
179
+ h('svg', { className: 'tl-edges', width: size.w, height: size.h, 'aria-hidden': true },
180
+ h('defs', null, h('marker', { id: 'tl-arrow', viewBox: '0 0 10 10', refX: 9, refY: 5, markerWidth: 7, markerHeight: 7, orient: 'auto-start-reverse' }, h('path', { d: 'M0 0 L10 5 L0 10 z' }))),
181
+ edges),
182
+ flow.nodes.map((n) => {
183
+ const does = doesOf(n.does);
184
+ const color = n.kind === 'stop' ? 'failure' : n.kind === 'decision' ? 'question' : does.color;
185
+ const symbol = n.kind === 'stop' ? 'stop' : n.kind === 'decision' ? 'rule' : n.kind === 'start' ? 'action' : null;
186
+ const mark = marks?.has(n.id) ? markAs : undefined;
187
+ return h('div', {
188
+ key: n.id, ref: (el) => { if (el) refs.current.set(n.id, el); else refs.current.delete(n.id); },
189
+ className: `tl-node tl-node-${n.kind} tl-tone-${color}${n.code || n.kind === 'code' ? ' tl-node-code' : ''}${mark ? ` tl-mark-${mark}` : ''}`,
190
+ style: { gridRow: n.row + 1, gridColumn: n.lane + 1 },
191
+ },
192
+ h('span', { className: 'tl-node-mark', 'aria-hidden': true, title: does.label }, symbol ? h(ThunderSymbol, { id: symbol, size: 15 }) : does.mark),
193
+ mark ? h('span', { className: `tl-badge tl-badge-${mark}` }, mark === 'added' ? 'New' : 'Gone') : null,
194
+ h('span', { className: 'tl-node-text', title: n.text }, n.kind === 'code' ? h('code', null, n.text) : n.text),
195
+ n.uses && onUse ? h('button', { type: 'button', className: 'tl-node-use', onClick: () => onUse(n.uses), title: 'Open the rule this step uses, and try it' }, `${useLabel?.(n.uses) ?? READING_LABELS.openRule} →`) : null,
196
+ h(LineButton, { line: n.line, onLine }));
197
+ }));
198
+ }
199
+
200
+ function Whens({ when }) {
201
+ if (!when.length) return h('span', { className: 'tl-quiet' }, READING_LABELS.details.always);
202
+ return h(Fragment, null, when.map((w, k) => h('span', { key: k, className: 'tl-cond' },
203
+ h('span', { className: 'tl-cond-q' }, w.question), ' ',
204
+ h('span', { className: `tl-ans tl-ans-${w.answer === 'Yes' ? 'yes' : w.answer === 'No' ? 'no' : 'each'}` }, w.answer),
205
+ k < when.length - 1 ? h('span', { className: 'tl-cond-and', 'aria-hidden': true }, '·') : null)));
206
+ }
207
+
208
+ /**
209
+ * Details: the same action sorted into facts, each with its line. `view` is readLevel(model, 'details', memberId)
210
+ * (or pass `layout` from detailsLayout). Sections appear only when the compiler gives them.
211
+ * onLine(line) opens the original code. rules: the app's own cards for the rules it relies on, drawn in place of
212
+ * the plain "It relies on" list (OpenThunder's try-it cards).
213
+ */
214
+ export function Details({ view, layout, onLine, rules, headingLevel = 3 }) {
215
+ const d = layout ?? detailsLayout(view);
216
+ const H = `h${headingLevel}`;
217
+ const card = (cls, heading, icon, ...body) => h('section', { className: `tl-card tl-details-card${cls ? ` ${cls}` : ''}` },
218
+ h(H, { className: 'tl-details-h' }, icon, heading), ...body);
219
+ const doesMark = (does, mark) => { const x = doesOf(does); return h('span', { className: `tl-does tl-c-${x.color}`, title: x.label }, mark || x.mark); };
220
+ return h('div', { className: 'tl-reading tl-details' },
221
+ h('div', { className: 'tl-stats', 'aria-label': d.heading }, d.stats.map((s) => h('span', { key: s.id, className: `tl-stat tl-stat-${s.id}` }, h('b', null, s.count), ` ${s.text}`))),
222
+ d.give ? h('div', { className: 'tl-io' },
223
+ card('tl-io-give', d.give.heading, h('span', { 'aria-hidden': true }, '→ '),
224
+ d.give.items.length ? h('ul', { className: 'tl-inputs' }, d.give.items.map((i) => h('li', { key: i.label },
225
+ h('span', { className: 'tl-pill tl-pill-fact' }, i.label),
226
+ i.lines.length && onLine ? h('span', { className: 'tl-used' }, `${READING_LABELS.details.usedOn} `, i.lines.map((l, k) => h(Fragment, { key: l }, k > 0 ? ', ' : null,
227
+ h('button', { type: 'button', className: 'tl-line tl-line-inline', onClick: () => onLine(l), title: 'See this line' }, l)))) : null)))
228
+ : h('p', { className: 'tl-quiet' }, d.give.empty)),
229
+ card('tl-io-back', d.getBack.heading, h('span', { 'aria-hidden': true }, '⇥ '),
230
+ d.getBack.items.length ? h('ul', { className: 'tl-rows' }, d.getBack.items.map((g, i) => h('li', { key: i },
231
+ h('div', { className: 'tl-row-top' }, h('span', { className: 'tl-strong' }, g.text), h(LineButton, { line: g.line, onLine })),
232
+ g.when ? h('div', { className: 'tl-when' }, h(Whens, { when: g.when })) : null)))
233
+ : h('p', { className: 'tl-quiet' }, d.getBack.empty))) : null,
234
+ d.stops ? card('tl-details-stops', d.stops.heading, h(ThunderSymbol, { id: 'stop', size: 15 }),
235
+ d.stops.items.length ? h('ul', { className: 'tl-rows' }, d.stops.items.map((s, i) => h('li', { key: i, className: 'tl-stop-row-detail' },
236
+ h('div', { className: 'tl-row-top' }, h('b', null, s.error), s.message ? h('span', { className: 'tl-message' }, `"${s.message}"`) : null, h(LineButton, { line: s.line, onLine })),
237
+ h('div', { className: 'tl-when' }, h(Whens, { when: s.when })))))
238
+ : h('p', { className: 'tl-quiet' }, d.stops.empty)) : null,
239
+ d.changes ? card(null, d.changes.heading, h('span', { 'aria-hidden': true }, '= '),
240
+ h('ul', { className: 'tl-rows' }, d.changes.items.map((c, i) => h('li', { key: i },
241
+ h('div', { className: 'tl-row-top' }, doesMark(c.does), h('span', { className: 'tl-strong' }, c.text), h(LineButton, { line: c.line, onLine })),
242
+ c.when.length ? h('div', { className: 'tl-when' }, h(Whens, { when: c.when })) : null)))) : null,
243
+ d.answers ? card(null, d.answers.heading, h(ThunderSymbol, { id: 'rule', size: 15 }),
244
+ h('ol', { className: 'tl-answers' }, d.answers.items.map((a, i) => h('li', { key: i }, h('b', null, a.answer), ' ', h('span', { className: 'tl-quiet' }, a.when))))) : null,
245
+ d.limits ? card(null, d.limits.heading, h(ThunderSymbol, { id: 'rule', size: 15 }),
246
+ h('p', { className: 'tl-quiet tl-limits-note' }, d.limits.note),
247
+ h('div', { className: 'tl-limits' }, d.limits.items.map((r, i) => h('div', { key: i, className: 'tl-limit' }, h('span', { className: 'tl-range' }, r.range), h('b', null, r.answer))))) : null,
248
+ d.steps ? card(null, d.steps.heading, h('span', { 'aria-hidden': true }, '≡ '),
249
+ h('ul', { className: 'tl-steps' }, d.steps.items.map((s) => h('li', { key: s.id, className: s.notExplained ? 'tl-step-code' : undefined, style: { paddingLeft: 4 + s.depth * 18 } },
250
+ doesMark(s.does, s.mark),
251
+ h('span', { className: 'tl-step-text' }, s.notExplained ? h('code', null, s.text) : s.text, s.via ? h('span', { className: 'tl-quiet' }, ` · ${s.via}`) : null),
252
+ h(LineButton, { line: s.line, onLine }))))) : null,
253
+ d.reliesOn && !rules ? card(null, d.reliesOn.heading, h(ThunderSymbol, { id: 'rule', size: 15 }),
254
+ h('ul', { className: 'tl-rows' }, d.reliesOn.items.map((r) => h('li', { key: r.id },
255
+ h('div', { className: 'tl-row-top' }, h(ThunderSymbol, { id: r.symbol, size: 14 }), h('b', null, r.label)),
256
+ r.says ? h('div', { className: 'tl-quiet' }, r.says) : null)))) : null,
257
+ rules ?? null,
258
+ d.usedBy ? h('p', { className: 'tl-quiet' }, `${d.usedBy.heading}: ${d.usedBy.items.map((u) => u.label).join(', ')}.`) : null,
259
+ d.openQuestions ? card('tl-details-open', d.openQuestions.heading, null, h('ul', { className: 'tl-rows' }, d.openQuestions.items.map((q) => h('li', { key: q }, q)))) : null,
260
+ d.source ? h('p', { className: 'tl-source' }, d.source) : null);
87
261
  }
@@ -4,7 +4,14 @@ export const READING_LAYOUT_SCHEMA: 'thunder-reading-layout-v1';
4
4
  export const READING_LABELS: Readonly<{
5
5
  thing: string; knows: string; can: string; starts: (label: string) => string; startsWithKnows: (label: string) => string;
6
6
  record: string; choices: string; recordSymbol: string; choicesSymbol: string; things: string; data: string;
7
- give: string; getBack: string; stops: string; givesNothing: string; getsNothing: string; partOf: (label: string) => string; io: string;
7
+ give: string; getBack: string; stops: string; givesNothing: string; getsNothing: string; partOf: (label: string) => string; io: string; actions: string;
8
+ edges: Readonly<Record<'yes' | 'no' | 'each' | 'done' | 'error' | 'nested' | 'case', string>>;
9
+ openLine: (line: number) => string; openRule: string;
10
+ details: Readonly<{
11
+ stops: string; noStops: string; noInputs: string; nothingBack: string; changes: string; answers: string; limits: (fact: string) => string;
12
+ limitsHow: string; steps: string; reliesOn: string; usedBy: string; openQuestions: string; always: string; otherwise: string;
13
+ when: (w: string) => string; usedOn: string; atAGlance: string;
14
+ }>;
8
15
  }>;
9
16
  export type ThunderSymbolId = 'app' | 'area' | 'file' | 'thing' | 'data' | 'record' | 'choices' | 'action' | 'rule' | 'steps' | 'setup' | 'stop' | 'not-read' | 'resource' | 'permission';
10
17
  export interface KnowsLine { name: string; label: string; detail: string | null; secret?: true; line: number | null }
@@ -22,16 +29,39 @@ export interface DataCardLayout {
22
29
  export interface IOBoxesLayout {
23
30
  kind: 'io'; id: string; label: string; doc: string | null; symbol: ThunderSymbolId;
24
31
  give: { heading: string; items: { label: string; kind: string | null }[]; empty: string };
25
- getBack: { heading: string; text: string | null; empty: string };
32
+ /** text: what the code declares; items: that, else the Flow's end steps (what to draw). */
33
+ getBack: { heading: string; text: string | null; items: string[]; empty: string };
26
34
  stops: { heading: string; items: { text: string; line: number | null }[] };
27
35
  /** The Thing it belongs to, to link back to its card. */
28
36
  partOf: { id: string; text: string } | null;
29
37
  }
38
+ /** An action or rule that belongs to no Thing (a plain function), listed in the Big Picture as a door to open. */
39
+ export interface MemberEntryLayout { kind: 'member'; id: string; label: string; symbol: ThunderSymbolId; doc: string | null }
30
40
  export interface ReadingLayout {
31
41
  schema: 'thunder-reading-layout-v1';
32
42
  focus: { kind: 'app' | 'file' | 'thing' | 'member' | 'unknown'; id: string | null };
33
- sections: Array<{ id: 'things'; heading: string; cards: ThingCardLayout[] } | { id: 'data'; heading: string; cards: DataCardLayout[] } | { id: 'io'; heading: string; cards: IOBoxesLayout[] }>;
43
+ sections: Array<{ id: 'things'; heading: string; cards: ThingCardLayout[] } | { id: 'data'; heading: string; cards: DataCardLayout[] } | { id: 'io'; heading: string; cards: IOBoxesLayout[] } | { id: 'actions'; heading: string; cards: MemberEntryLayout[] }>;
34
44
  }
45
+ export interface When { question: string; answer: string }
46
+ export interface DetailsLayout {
47
+ id: string | null; title: string | null; heading: string;
48
+ stats: { id: 'inputs' | 'steps' | 'stops' | 'changes' | 'reliesOn' | 'notExplained'; count: number; text: string }[];
49
+ give: { heading: string; items: { label: string; lines: number[] }[]; empty: string } | null;
50
+ getBack: { heading: string; items: { text: string; line: number | null; when: When[] | null }[]; empty: string } | null;
51
+ stops: { heading: string; items: { error: string; message: string | null; line: number | null; when: When[] }[]; empty: string } | null;
52
+ changes: { heading: string; items: { text: string; does: string | null; line: number | null; when: When[] }[] } | null;
53
+ answers: { heading: string; items: { answer: string; when: string }[] } | null;
54
+ limits: { heading: string; note: string; items: { range: string; answer: string }[] } | null;
55
+ steps: { heading: string; items: { id: string; text: string; does: string | null; mark: string | null; depth: number; line: number | null; notExplained: boolean; via: string | null }[] } | null;
56
+ reliesOn: { heading: string; items: { id: string; label: string; symbol: ThunderSymbolId; says: string }[] } | null;
57
+ usedBy: { heading: string; items: { id: string; label: string }[] } | null;
58
+ openQuestions: { heading: string; items: string[] } | null;
59
+ source: string | null;
60
+ }
61
+ /** What a Flow edge says, or null for a plain next step. */
62
+ export function flowEdgeLabel(edge: { label?: string | null; text?: string }): string | null;
63
+ /** Details sorted for drawing; `view` is readLevel(model, 'details', memberId). */
64
+ export function detailsLayout(view: Record<string, any>): DetailsLayout;
35
65
  export function memberSymbolId(member: { kind: string }): ThunderSymbolId;
36
66
  export function thingCard(model: ThunderModel, thing: Thing): ThingCardLayout;
37
67
  export function dataCard(thing: Thing): DataCardLayout;
@@ -25,6 +25,20 @@ export const READING_LABELS = Object.freeze({
25
25
  getsNothing: 'Nothing it hands back',
26
26
  partOf: (label) => `Part of ${label}`,
27
27
  io: 'What goes in and out',
28
+ actions: 'Actions and rules',
29
+ // Flow: the words on each kind of edge. An edge label not listed here is shown as the compiler wrote it.
30
+ edges: Object.freeze({ yes: 'Yes', no: 'No', each: 'For each', done: 'Done', error: 'If it fails', nested: 'Runs on its own', case: 'When' }),
31
+ openLine: (line) => `line ${line}`,
32
+ openRule: 'Open the rule',
33
+ // Details: what each section is called.
34
+ details: Object.freeze({
35
+ stops: 'When it stops', noStops: 'Thunder found no place where it stops early.',
36
+ noInputs: 'Thunder found no inputs. Check Original if it reads a request or a file.', nothingBack: 'Thunder found nothing it gives back.',
37
+ changes: 'What it changes, saves or sends', answers: 'Its answers', limits: (fact) => `Exact limits for ${fact}`,
38
+ limitsHow: 'Found by running the rule on every whole number around each limit.',
39
+ steps: 'Every step, with its line', reliesOn: 'It relies on', usedBy: 'Used by', openQuestions: 'Questions the code cannot answer',
40
+ always: 'Always', otherwise: 'otherwise', when: (w) => `when ${w}`, usedOn: 'used on', atAGlance: 'At a glance',
41
+ }),
28
42
  });
29
43
 
30
44
  /** The symbol (thunder-visual-v1) for a member, as every view draws it. */
@@ -62,6 +76,12 @@ export function dataCard(thing) {
62
76
  };
63
77
  }
64
78
 
79
+ /** What an action gives back: its declared result, else the end steps of its Flow, each once. */
80
+ const givesBackOf = (member) => {
81
+ const list = member.youGetBack ? [member.youGetBack] : (member.flow?.nodes ?? []).filter((n) => n.kind === 'end').map((n) => n.text.replace(/^Gives back\s+/i, ''));
82
+ return [...new Set(list.filter(Boolean))];
83
+ };
84
+
65
85
  /**
66
86
  * What goes in and out of one action or rule: "You give it" (each input, with its kind when the code says it), "You
67
87
  * get back", "It can stop with" (every Stop in its flow, with its line), and "Part of <Thing>" back to its card.
@@ -73,24 +93,82 @@ export function ioBoxes(model, member) {
73
93
  return {
74
94
  kind: 'io', id: member.id, label: `${member.label}${member.yesNo ? '?' : ''}`, doc: member.doc ?? null, symbol: memberSymbolId(member),
75
95
  give: { heading: READING_LABELS.give, items: member.youGive.map((label) => ({ label, kind: kinds[label] ?? null })), empty: READING_LABELS.givesNothing },
76
- getBack: { heading: READING_LABELS.getBack, text: member.youGetBack ?? null, empty: READING_LABELS.getsNothing },
96
+ // What it gives back: what the code declares, else the Flow's end steps (the same facts Flow and Details show).
97
+ getBack: { heading: READING_LABELS.getBack, text: member.youGetBack ?? null, items: givesBackOf(member), empty: READING_LABELS.getsNothing },
77
98
  stops: { heading: READING_LABELS.stops, items: stops },
78
99
  partOf: owner ? { id: owner.id, text: READING_LABELS.partOf(owner.label) } : null,
79
100
  };
80
101
  }
81
102
 
82
- const sectionsFor = (model, things) => {
103
+ /** What a Flow edge says ("Yes", "For each", a case's own words), or null for a plain next step. */
104
+ export function flowEdgeLabel(edge) {
105
+ if (!edge.label || edge.label === 'next') return null;
106
+ if (edge.label === 'case') return edge.text ?? READING_LABELS.edges.case;
107
+ return READING_LABELS.edges[edge.label] ?? edge.text ?? edge.label;
108
+ }
109
+
110
+ const count = (n, one, many) => ({ count: n, text: n === 1 ? one : many });
111
+
112
+ /**
113
+ * Details, sorted for drawing: the counts at a glance, then You give it / You get back, When it stops, What it
114
+ * changes, Its answers, Exact limits, Every step, It relies on, Used by, and Questions the code cannot answer.
115
+ * `view` is readLevel(model, 'details', memberId). A section is present only when the compiler gave it (null when
116
+ * not), so nothing is invented. What it gives back comes from the same facts as the Big Picture: givesBack, else
117
+ * youGetBack, else the Flow's end steps.
118
+ */
119
+ export function detailsLayout(view) {
120
+ const L = READING_LABELS.details;
121
+ const inputs = view.inputs ?? (view.youGive ?? []).map((label) => ({ label, lines: [] }));
122
+ const givesBack = view.givesBack?.length ? view.givesBack.map((g) => ({ text: g.text, line: g.line ?? null, when: g.when ?? null }))
123
+ : view.youGetBack ? [{ text: view.youGetBack, line: null, when: null }]
124
+ : (view.flow?.nodes ?? []).filter((n) => n.kind === 'end').map((n) => ({ text: n.text, line: n.line ?? null, when: null }));
125
+ const steps = view.steps ?? [];
126
+ const stops = view.stops ?? null;
127
+ const changes = view.changes ?? null;
128
+ const reliesOn = view.reliesOn ?? (view.uses ?? []).map((u) => ({ id: u.id, label: u.label, symbol: 'rule', says: '' }));
129
+ const stats = [
130
+ ...(inputs.length ? [{ id: 'inputs', ...count(inputs.length, 'thing you give it', 'things you give it') }] : []),
131
+ { id: 'steps', ...count(steps.length, 'step', 'steps') },
132
+ ...(stops ? [{ id: 'stops', ...count(stops.length, 'way to stop', 'ways to stop') }] : []),
133
+ ...(changes ? [{ id: 'changes', ...count(changes.length, 'change', 'changes') }] : []),
134
+ ...(reliesOn.length ? [{ id: 'reliesOn', count: reliesOn.length, text: 'relies on' }] : []),
135
+ ...((view.notExplained ?? 0) > 0 ? [{ id: 'notExplained', count: view.notExplained, text: 'not explained yet' }] : []),
136
+ ];
137
+ return {
138
+ id: view.id ?? null, title: view.title ?? null, heading: L.atAGlance, stats,
139
+ give: inputs.length || givesBack.length ? { heading: READING_LABELS.give, items: inputs.map((i) => ({ label: i.label, lines: i.lines ?? [] })), empty: L.noInputs } : null,
140
+ getBack: inputs.length || givesBack.length ? { heading: READING_LABELS.getBack, items: givesBack, empty: L.nothingBack } : null,
141
+ stops: stops ? { heading: L.stops, items: stops.map((s) => ({ error: s.error, message: s.message ?? null, line: s.line ?? null, when: s.when ?? [] })), empty: L.noStops } : null,
142
+ changes: changes?.length ? { heading: L.changes, items: changes.map((c) => ({ text: c.text, does: c.does ?? null, line: c.line ?? null, when: c.when ?? [] })) } : null,
143
+ answers: view.answers?.length ? { heading: L.answers, items: view.answers.map((a) => ({ answer: a.answer, when: a.when === 'otherwise' ? L.otherwise : L.when(a.when) })) } : null,
144
+ limits: view.limits ? { heading: L.limits(view.limits.fact), note: L.limitsHow, items: view.limits.ranges.map((r) => ({ range: r.from == null ? `${r.to} or less` : r.to == null ? `${r.from} or more` : r.from === r.to ? `${r.from}` : `${r.from} to ${r.to}`, answer: r.answer })) } : null,
145
+ steps: steps.length ? { heading: L.steps, items: steps.map((s) => ({ id: s.id, text: s.text, does: s.does ?? null, mark: s.mark ?? null, depth: s.depth ?? 0, line: s.line ?? null, notExplained: !!s.notExplained, via: s.via ?? null })) } : null,
146
+ reliesOn: reliesOn.length ? { heading: L.reliesOn, items: reliesOn.map((r) => ({ id: r.id, label: r.label, symbol: r.symbol ?? 'rule', says: r.says ?? '' })) } : null,
147
+ usedBy: view.usedBy?.length ? { heading: L.usedBy, items: view.usedBy.map((u) => ({ id: u.id, label: u.label })) } : null,
148
+ openQuestions: view.openQuestions?.length ? { heading: L.openQuestions, items: [...view.openQuestions] } : null,
149
+ source: view.source ?? null,
150
+ };
151
+ }
152
+
153
+ /** An action or rule that belongs to no Thing (a plain function): a door to open, with its symbol and doc. */
154
+ const memberEntry = (m) => ({ kind: 'member', id: m.id, label: `${m.label}${m.yesNo ? '?' : ''}`, symbol: memberSymbolId(m), doc: m.doc ?? null });
155
+
156
+ const sectionsFor = (model, things, loose = []) => {
83
157
  const cards = things.filter((t) => t.kind === 'thing').map((t) => thingCard(model, t));
84
158
  const data = [...things.filter((t) => t.kind === 'record'), ...things.filter((t) => t.kind === 'choices')].map(dataCard);
159
+ const actions = loose.map(memberEntry);
85
160
  return [
86
161
  ...(cards.length ? [{ id: 'things', heading: READING_LABELS.things, cards }] : []),
87
162
  ...(data.length ? [{ id: 'data', heading: READING_LABELS.data, cards: data }] : []),
163
+ ...(actions.length ? [{ id: 'actions', heading: READING_LABELS.actions, cards: actions }] : []),
88
164
  ];
89
165
  };
166
+ const ownerless = (model, file) => model.members.filter((m) => !m.owner && (file == null || m.file === file));
90
167
 
91
168
  /**
92
169
  * The Big Picture, which zooms with what is in focus (the tabs stay Big Picture / Flow / Details / Text / Original):
93
- * no focus: every Thing, then every record, then every set of choices
170
+ * no focus: every Thing, then every record, then every set of choices, then the actions and rules that
171
+ * belong to no Thing (plain functions), each a door to open
94
172
  * a file's path: the same, for that file
95
173
  * a Thing's id: its card, then the Data in its file
96
174
  * an action or rule: its "You give it / You get back / It can stop with" boxes, with "Part of <Thing>"
@@ -99,7 +177,7 @@ const sectionsFor = (model, things) => {
99
177
  */
100
178
  export function readingLayout(model, { focus = null } = {}) {
101
179
  const base = { schema: READING_LAYOUT_SCHEMA };
102
- if (focus == null) return { ...base, focus: { kind: 'app', id: null }, sections: sectionsFor(model, model.things) };
180
+ if (focus == null) return { ...base, focus: { kind: 'app', id: null }, sections: sectionsFor(model, model.things, ownerless(model)) };
103
181
  const member = model.members.find((m) => m.id === focus);
104
182
  if (member) return { ...base, focus: { kind: 'member', id: focus }, sections: [{ id: 'io', heading: READING_LABELS.io, cards: [ioBoxes(model, member)] }] };
105
183
  const thing = model.things.find((t) => t.id === focus);
@@ -107,6 +185,6 @@ export function readingLayout(model, { focus = null } = {}) {
107
185
  const rest = model.things.filter((t) => t !== thing && t.file === thing.file && t.kind !== 'thing');
108
186
  return { ...base, focus: { kind: 'thing', id: focus }, sections: sectionsFor(model, [thing, ...rest]) };
109
187
  }
110
- if (model.files.some((f) => f.path === focus)) return { ...base, focus: { kind: 'file', id: focus }, sections: sectionsFor(model, model.things.filter((t) => t.file === focus)) };
188
+ if (model.files.some((f) => f.path === focus)) return { ...base, focus: { kind: 'file', id: focus }, sections: sectionsFor(model, model.things.filter((t) => t.file === focus), ownerless(model, focus)) };
111
189
  return { ...base, focus: { kind: 'unknown', id: focus }, sections: [] };
112
190
  }