@skillstech/thunderlang 0.5.6 → 0.5.7

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,17 @@
1
+ # 0.5.7
2
+
3
+ **Language: the five reading levels.** Every Thunder view now offers the same five levels, in this order, with
4
+ these names: **Big Picture** (what is it, and what can it do?), **Flow** (how does it go?), **Details** (exactly
5
+ what happens, and how sure is Thunder?), **Text** (what does it say, in words?), and **Original** (which code says
6
+ so?). They are separate from **places** (App, Area, File, Thing, Action, Rule): where you are versus how deep you
7
+ read. Spec section 3 defines both.
8
+ - `LEVELS` (names, questions, what each shows) and `PLACES` in `THUNDER_VISUAL` and `/core`.
9
+ - `readLevel(model, level, focus)` in `/core`: exactly what a level shows for the whole app, one Thing, or one action
10
+ or rule. Details lists every step in order with its line, its path (Yes, No, For each), what was not explained,
11
+ and what it uses and is used by. Flow and Details without an action or rule give back the list to choose from.
12
+ - thunderlang.dev: the home page and /language lead with "One program. Five ways to read it.", and Semantic Zoom
13
+ (/zoom) uses the same five levels in place of its two separate controls.
14
+
1
15
  # 0.5.6
2
16
 
3
17
  Entries that change what Thunder means or how it reads (the language itself) start with **Language:**. Courses and
package/dist/core.cjs CHANGED
@@ -33,7 +33,7 @@ __export(core_exports, {
33
33
  CODEGEN_SCHEMA: () => CODEGEN_SCHEMA,
34
34
  COMMENT_PREFIX: () => COMMENT_PREFIX,
35
35
  COMPARISON_CHOICES: () => COMPARISON_CHOICES,
36
- COMPREHENSION_LEVELS: () => LEVELS,
36
+ COMPREHENSION_LEVELS: () => LEVELS2,
37
37
  COMPREHENSION_SCHEMA: () => COMPREHENSION_SCHEMA,
38
38
  CONFIDENCE: () => CONFIDENCE,
39
39
  CORE_DIAGNOSTICS: () => CORE_DIAGNOSTICS,
@@ -58,12 +58,14 @@ __export(core_exports, {
58
58
  IR_RELATIONSHIP_TYPES: () => IR_RELATIONSHIP_TYPES,
59
59
  IR_SCHEMA: () => IR_SCHEMA,
60
60
  KNOWN_LENSES: () => KNOWN_LENSES,
61
+ LEVELS: () => LEVELS,
61
62
  MODEL_SCHEMA: () => MODEL_SCHEMA,
62
63
  MODE_VALUES: () => MODE_VALUES,
63
64
  NODE_FIELDS: () => NODE_FIELDS,
64
65
  NODE_STATUSES: () => NODE_STATUSES,
65
66
  NODE_TYPES: () => NODE_TYPES,
66
67
  PATCH_SCHEMA: () => PATCH_SCHEMA,
68
+ PLACES: () => PLACES,
67
69
  PLAIN_SCHEMA: () => PLAIN_SCHEMA,
68
70
  PROMOTE_SCHEMA: () => PROMOTE_SCHEMA,
69
71
  PROOF_CHECK_KEYS: () => PROOF_CHECK_KEYS,
@@ -188,6 +190,7 @@ __export(core_exports, {
188
190
  promoteDecision: () => promoteDecision,
189
191
  proposeIntent: () => proposeIntent,
190
192
  readCode: () => readCode,
193
+ readLevel: () => readLevel,
191
194
  readRepo: () => readRepo,
192
195
  readableLanguage: () => readableLanguage,
193
196
  renderExampleTable: () => renderExampleTable,
@@ -3467,7 +3470,7 @@ function notesSummary(ast) {
3467
3470
  byLens
3468
3471
  };
3469
3472
  }
3470
- var COMPILER_VERSION = "0.5.6";
3473
+ var COMPILER_VERSION = "0.5.7";
3471
3474
  var PROOF_SCHEMA_VERSION = "0.1.0";
3472
3475
  var SOURCE_PRODUCT = "skillstech-compiler";
3473
3476
  function buildContractGraph(ast, generatedAt) {
@@ -7777,6 +7780,13 @@ var FORMS = [
7777
7780
  { id: "meaning", name: "The meaning", role: "model", says: "The one reading both views are made from. The picture and Thunder Text are two views of it, never translations of each other." },
7778
7781
  { id: "source", name: "Original code", role: "evidence", says: "The code in its own language. Always one click away (View original)." }
7779
7782
  ];
7783
+ var LEVELS = [
7784
+ { 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
+ { 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" },
7787
+ { 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
+ { 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
+ ];
7780
7790
  var ZOOM = [
7781
7791
  { level: 0, name: "App", from: "A product or a repository", element: "app", atlas: "Z0" },
7782
7792
  { level: 1, name: "Area", from: "A feature area, service, package, or folder (Atlas; optional in Read in Thunder)", element: "area", atlas: "Z1" },
@@ -7960,7 +7970,8 @@ var DOES = {
7960
7970
  code: { label: "Not read yet", mark: "\xB7", color: "unread", dashed: true }
7961
7971
  };
7962
7972
  var BEGINNER = ["thing", "action", "rule", "steps", "data", "stop"];
7963
- var THUNDER_VISUAL = { schema: VISUAL_SCHEMA, principle: PRINCIPLE, forms: FORMS, zoom: ZOOM, colors: COLORS, lines: LINES, provenance: PROVENANCE, steps: STEP_MARKS, elements: ELEMENTS, languages: LANGUAGES, rules: RULES, symbols: SYMBOLS, does: DOES, beginner: BEGINNER };
7973
+ var PLACES = ZOOM;
7974
+ var THUNDER_VISUAL = { schema: VISUAL_SCHEMA, principle: PRINCIPLE, forms: FORMS, levels: LEVELS, places: ZOOM, zoom: ZOOM, colors: COLORS, lines: LINES, provenance: PROVENANCE, steps: STEP_MARKS, elements: ELEMENTS, languages: LANGUAGES, rules: RULES, symbols: SYMBOLS, does: DOES, beginner: BEGINNER };
7964
7975
  var STRUCTURE_WORDS = /^(?:Ask:|Yes:|No:|Otherwise:|Otherwise,|Always, at the end:|For each:|When done:|You give it:|You get back:|Takes|Author's note:|It knows|It can|One of:|We need|Examples|Why:|When someone calls|What|Thing|Record|Choices|Area|File|App|Not read)(?=\s|$)/;
7965
7976
  function thunderTokens(line) {
7966
7977
  const out = [];
@@ -8630,6 +8641,105 @@ function modelText(model, id2) {
8630
8641
  return `${lines.join("\n")}
8631
8642
  `;
8632
8643
  }
8644
+ var SYMBOL_OF = { action: "action", rule: "rule", steps: "steps", setup: "setup", "not-read": "not-read", thing: "thing", record: "record", choices: "choices" };
8645
+ function detailSteps(flow) {
8646
+ const byId = new Map(flow.nodes.map((n) => [n.id, n]));
8647
+ const out = [];
8648
+ const push = (n, depth, via, text = n.text) => out.push({ id: n.id, text, does: n.does, mark: DOES[n.does]?.mark ?? "\xB7", line: n.line ?? null, depth, ...via ? { via } : {}, ...n.kind === "code" ? { notExplained: true } : {} });
8649
+ const walk = (blocks2, depth, via) => {
8650
+ for (const b of blocks2 || []) {
8651
+ const n = byId.get(b.id);
8652
+ if (n && n.kind !== "start") {
8653
+ push(n, depth, via);
8654
+ via = null;
8655
+ }
8656
+ walk(b.yes, depth + 1, "Yes");
8657
+ walk(b.no, depth + 1, "No");
8658
+ walk(b.each, depth + 1, "For each");
8659
+ walk(b.body, depth + 1, null);
8660
+ for (const h of b.handlers || []) {
8661
+ const hn = byId.get(h.id);
8662
+ if (hn) push(hn, depth, null, hn.text.replace(/\?$/, ""));
8663
+ walk(h.blocks, depth + 1, null);
8664
+ }
8665
+ if (b.always) {
8666
+ const an = byId.get(b.always.id);
8667
+ if (an) push(an, depth, null);
8668
+ walk(b.always.blocks, depth + 1, null);
8669
+ }
8670
+ }
8671
+ };
8672
+ walk(flow.blocks, 0, null);
8673
+ return out;
8674
+ }
8675
+ function readLevel(model, level, focus) {
8676
+ const lv = LEVELS.find((l) => l.id === level);
8677
+ if (!lv) throw new Error(`Unknown reading level "${level}". Use one of: ${LEVELS.map((l) => l.id).join(", ")}.`);
8678
+ const member = focus ? model.members.find((m) => m.id === focus) : void 0;
8679
+ const thing = focus && !member ? model.things.find((t) => t.id === focus) : void 0;
8680
+ if (focus && !member && !thing) throw new Error(`Nothing in this model has the id "${focus}".`);
8681
+ const owner = member?.owner ? model.things.find((t) => t.id === member.owner) : void 0;
8682
+ const labelOf = (id2) => model.members.find((m) => m.id === id2)?.label ?? id2;
8683
+ const short = (m) => ({ id: m.id, label: m.label + (m.yesNo ? "?" : ""), symbol: SYMBOL_OF[m.kind], ...m.route ? { route: m.route } : {} });
8684
+ const base = { level: lv.id, name: lv.name, question: lv.question };
8685
+ const about = member ? { scope: "member", id: member.id, title: member.label + (member.yesNo ? "?" : ""), symbol: SYMBOL_OF[member.kind], file: member.file, lines: member.lines } : thing ? { scope: "thing", id: thing.id, title: thing.label, symbol: SYMBOL_OF[thing.kind], file: thing.file, lines: thing.lines } : { scope: "app", id: null, title: model.name, symbol: "app", file: model.files[0]?.path ?? null, lines: null };
8686
+ const uses = member ? model.links.filter((l) => l.from === member.id).map((l) => ({ id: l.to, label: labelOf(l.to) })) : [];
8687
+ const usedBy = member ? model.links.filter((l) => l.to === member.id).map((l) => ({ id: l.from, label: labelOf(l.from) })) : [];
8688
+ if (!member && (lv.id === "flow" || lv.id === "details")) {
8689
+ const inScope = model.members.filter((m) => m.kind !== "setup" && (!thing || m.owner === thing.id));
8690
+ return { ...base, ...about, needsFocus: true, says: `${lv.name} shows one action or rule. Choose one.`, choose: inScope.map(short) };
8691
+ }
8692
+ if (lv.id === "big-picture") {
8693
+ if (member) {
8694
+ return {
8695
+ ...base,
8696
+ ...about,
8697
+ ...member.route ? { route: member.route } : {},
8698
+ ...member.doc ? { doc: member.doc } : {},
8699
+ ...owner ? { owner: { id: owner.id, label: owner.label } } : {},
8700
+ youGive: member.youGive,
8701
+ ...member.youGetBack ? { youGetBack: member.youGetBack } : {},
8702
+ uses,
8703
+ usedBy
8704
+ };
8705
+ }
8706
+ const inScope = (m) => m.kind !== "setup" && (thing ? m.owner === thing.id : true);
8707
+ const thingCard = (t) => ({ id: t.id, label: t.label, ...t.doc ? { doc: t.doc } : {}, knows: t.knows.map((k) => ({ label: k.label, ...k.start ? { start: k.start } : {} })), can: model.members.filter((m) => m.owner === t.id && m.kind !== "setup").map(short) });
8708
+ return {
8709
+ ...base,
8710
+ ...about,
8711
+ ...thing?.doc ?? model.files[0]?.purpose ? { purpose: thing?.doc ?? model.files[0]?.purpose } : {},
8712
+ things: (thing ? [thing] : model.things.filter((t) => t.kind === "thing")).map(thingCard),
8713
+ data: thing ? [] : model.things.filter((t) => t.kind !== "thing").map((t) => ({ id: t.id, label: t.label, symbol: SYMBOL_OF[t.kind], ...t.choices.length ? { choices: t.choices } : {}, knows: t.knows.map((k) => k.label) })),
8714
+ actions: model.members.filter((m) => inScope(m) && m.kind === "action").map(short),
8715
+ rules: model.members.filter((m) => inScope(m) && m.kind === "rule").map(short),
8716
+ loose: thing ? [] : model.members.filter((m) => !m.owner && m.kind !== "setup" && m.kind !== "action" && m.kind !== "rule").map(short),
8717
+ unknowns: thing ? [] : model.unknowns
8718
+ };
8719
+ }
8720
+ if (lv.id === "flow") return { ...base, ...about, flow: member.flow };
8721
+ if (lv.id === "details") {
8722
+ const steps = detailSteps(member.flow);
8723
+ return {
8724
+ ...base,
8725
+ ...about,
8726
+ youGive: member.youGive,
8727
+ ...member.youGetBack ? { youGetBack: member.youGetBack } : {},
8728
+ steps,
8729
+ notExplained: steps.filter((s) => s.notExplained).length,
8730
+ uses,
8731
+ usedBy,
8732
+ tryable: !!member.rule,
8733
+ ...member.rule ? { rule: member.rule } : {},
8734
+ source: "Read from code by the Thunder compiler, with no AI."
8735
+ };
8736
+ }
8737
+ if (lv.id === "text") {
8738
+ const text = focus ? modelText(model, focus) : [...model.things.map((t) => modelText(model, t.id)), ...model.members.filter((m) => !m.owner && m.kind !== "setup").map((m) => modelText(model, m.id))].join("\n");
8739
+ return { ...base, ...about, text };
8740
+ }
8741
+ return { ...base, ...about, language: member ?? thing ? member?.language ?? model.files.find((f) => f.path === thing.file)?.language ?? null : model.files[0]?.language ?? null };
8742
+ }
8633
8743
 
8634
8744
  // src/thunderize.mjs
8635
8745
  var THUNDERIZE_SCHEMA = "thunderize-v1";
@@ -11820,7 +11930,7 @@ function intentBrief(focus) {
11820
11930
 
11821
11931
  // src/comprehension.mjs
11822
11932
  var COMPREHENSION_SCHEMA = "intent-comprehension-v1";
11823
- var LEVELS = [
11933
+ var LEVELS2 = [
11824
11934
  { level: "C0", name: "Unknown", means: "Intent exists with no stated purpose." },
11825
11935
  { level: "C1", name: "Described", means: "Purpose and a summary exist." },
11826
11936
  { level: "C2", name: "Structured", means: "Guarantees, rules, states, failures, or constraints exist." },
@@ -11899,10 +12009,10 @@ function comprehensionLevel(ast, { observed = false, learningPath = false, gover
11899
12009
  if (signals[s].met) n += 1;
11900
12010
  else break;
11901
12011
  }
11902
- const level = LEVELS[n];
12012
+ const level = LEVELS2[n];
11903
12013
  const missing = [];
11904
12014
  for (let i = n; i < ladder.length; i += 1) {
11905
- const lv = LEVELS[i + 1];
12015
+ const lv = LEVELS2[i + 1];
11906
12016
  missing.push({ level: lv.level, name: lv.name, need: lv.means, owner: signals[ladder[i]].owner });
11907
12017
  }
11908
12018
  return {
@@ -11931,7 +12041,7 @@ function comprehensionLevel(ast, { observed = false, learningPath = false, gover
11931
12041
  function comprehensionReport(asts, opts = {}) {
11932
12042
  const missions = (asts || []).map((ast) => comprehensionLevel(ast, opts));
11933
12043
  const byLevel = {};
11934
- for (const lv of LEVELS) byLevel[lv.level] = 0;
12044
+ for (const lv of LEVELS2) byLevel[lv.level] = 0;
11935
12045
  for (const m of missions) byLevel[m.level] += 1;
11936
12046
  return { schema: COMPREHENSION_SCHEMA, count: missions.length, byLevel, missions };
11937
12047
  }
@@ -12574,12 +12684,14 @@ function translateDecisions(ast, lang) {
12574
12684
  IR_RELATIONSHIP_TYPES,
12575
12685
  IR_SCHEMA,
12576
12686
  KNOWN_LENSES,
12687
+ LEVELS,
12577
12688
  MODEL_SCHEMA,
12578
12689
  MODE_VALUES,
12579
12690
  NODE_FIELDS,
12580
12691
  NODE_STATUSES,
12581
12692
  NODE_TYPES,
12582
12693
  PATCH_SCHEMA,
12694
+ PLACES,
12583
12695
  PLAIN_SCHEMA,
12584
12696
  PROMOTE_SCHEMA,
12585
12697
  PROOF_CHECK_KEYS,
@@ -12704,6 +12816,7 @@ function translateDecisions(ast, lang) {
12704
12816
  promoteDecision,
12705
12817
  proposeIntent,
12706
12818
  readCode,
12819
+ readLevel,
12707
12820
  readRepo,
12708
12821
  readableLanguage,
12709
12822
  renderExampleTable,
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.6";
2426
+ var COMPILER_VERSION = "0.5.7";
2427
2427
  var PROOF_SCHEMA_VERSION = "0.1.0";
2428
2428
  var SOURCE_PRODUCT = "skillstech-compiler";
2429
2429
  function buildContractGraph(ast, generatedAt) {
@@ -13430,6 +13430,13 @@ var FORMS = [
13430
13430
  { id: "meaning", name: "The meaning", role: "model", says: "The one reading both views are made from. The picture and Thunder Text are two views of it, never translations of each other." },
13431
13431
  { id: "source", name: "Original code", role: "evidence", says: "The code in its own language. Always one click away (View original)." }
13432
13432
  ];
13433
+ var LEVELS2 = [
13434
+ { 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
+ { 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" },
13437
+ { 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
+ { 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
+ ];
13433
13440
  var ZOOM = [
13434
13441
  { level: 0, name: "App", from: "A product or a repository", element: "app", atlas: "Z0" },
13435
13442
  { level: 1, name: "Area", from: "A feature area, service, package, or folder (Atlas; optional in Read in Thunder)", element: "area", atlas: "Z1" },
@@ -13613,7 +13620,7 @@ var DOES = {
13613
13620
  code: { label: "Not read yet", mark: "\xB7", color: "unread", dashed: true }
13614
13621
  };
13615
13622
  var BEGINNER = ["thing", "action", "rule", "steps", "data", "stop"];
13616
- var THUNDER_VISUAL = { schema: VISUAL_SCHEMA, principle: PRINCIPLE, forms: FORMS, zoom: ZOOM, colors: COLORS, lines: LINES, provenance: PROVENANCE2, steps: STEP_MARKS, elements: ELEMENTS, languages: LANGUAGES, rules: RULES, symbols: SYMBOLS, does: DOES, beginner: BEGINNER };
13623
+ var THUNDER_VISUAL = { schema: VISUAL_SCHEMA, principle: PRINCIPLE, forms: FORMS, levels: LEVELS2, places: ZOOM, zoom: ZOOM, colors: COLORS, lines: LINES, provenance: PROVENANCE2, steps: STEP_MARKS, elements: ELEMENTS, languages: LANGUAGES, rules: RULES, symbols: SYMBOLS, does: DOES, beginner: BEGINNER };
13617
13624
 
13618
13625
  // src/thunderize.mjs
13619
13626
  var THUNDERIZE_SCHEMA = "thunderize-v1";
package/dist/learn.cjs CHANGED
@@ -1921,7 +1921,7 @@ var SEMANTIC_TYPES = Object.keys(SEMANTIC);
1921
1921
  var PRIMITIVE_TYPES = Object.keys(PRIMITIVE);
1922
1922
 
1923
1923
  // src/emit.mjs
1924
- var COMPILER_VERSION = "0.5.6";
1924
+ var COMPILER_VERSION = "0.5.7";
1925
1925
 
1926
1926
  // src/lift.mjs
1927
1927
  var IR_SCHEMA_VERSION = "0.1.0";
@@ -5922,7 +5922,7 @@ def place_order(order, card):
5922
5922
  slug: "openthunder",
5923
5923
  part: "read",
5924
5924
  title: "Read a whole app in OpenThunder",
5925
- idea: "A real app has many files. OpenThunder, the IDE for Thunder, reads a whole repository and lets you zoom: the App, then a File, then an Action (a door), then one Rule. Every picture is drawn from the code, and the original code is always one click away.",
5925
+ idea: "A real app has many files. OpenThunder, the IDE for Thunder, reads a whole repository. You move from the App to a File, then an Action (a door), then one Rule, and you can read each of them at five levels: Big Picture, Flow, Details, Text, and Original. Every picture is drawn from the code, and the original code is always one click away.",
5926
5926
  picture: "A map app: zoom out to see the whole city, zoom in to one street, then one house. It is the same map at every level.",
5927
5927
  files: [{ language: "python", label: "Python", code: PIZZA_APP }],
5928
5928
  focus: "place_order",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillstech/thunderlang",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
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/core.d.ts CHANGED
@@ -11,8 +11,8 @@ export { HumanContractPreview, compileHumanContract, previewHumanContract, rende
11
11
  export { ANCHOR_SCHEMA, spanRange, spanText, replaceSpan, editStep, anchorReport } from './anchor.mjs';
12
12
  export { WRITE_SCHEMA, writeRule, changedCases, ruleParts, joinRuleParts, COMPARISON_CHOICES } from './write.mjs';
13
13
  export { STEPS_SCHEMA, classifyStatement } from './steps.mjs';
14
- export { VISUAL_SCHEMA, THUNDER_VISUAL, visualFor, visualForStep, thunderText, thunderTokens } from './visual.mjs';
15
- export { MODEL_SCHEMA, THING_LANGUAGES, thunderModel, modelText, flowOf, ruleFlow, askAsQuestion, stepDoes } from './model.mjs';
14
+ export { VISUAL_SCHEMA, THUNDER_VISUAL, LEVELS, PLACES, visualFor, visualForStep, thunderText, thunderTokens } from './visual.mjs';
15
+ export { MODEL_SCHEMA, THING_LANGUAGES, thunderModel, modelText, readLevel, flowOf, ruleFlow, askAsQuestion, stepDoes } from './model.mjs';
16
16
  export { THUNDERIZE_SCHEMA, THUNDER_TEXT_EXT, thunderizeFile, thunderizeFiles } from './thunderize.mjs';
17
17
  export { SAME_SCHEMA, sameMeaning, compareRules, renderSame } from './same.mjs';
18
18
  export type { ColorRole, ElementKind, Provenance as VisualProvenance, Visual } from './visual.mjs';
package/src/core.mjs CHANGED
@@ -10,8 +10,8 @@ export { compileHumanContract, previewHumanContract, renderHumanContract, render
10
10
  export { ANCHOR_SCHEMA, spanRange, spanText, replaceSpan, editStep, anchorReport } from './anchor.mjs';
11
11
  export { WRITE_SCHEMA, writeRule, changedCases, ruleParts, joinRuleParts, COMPARISON_CHOICES } from './write.mjs';
12
12
  export { STEPS_SCHEMA, classifyStatement } from './steps.mjs';
13
- export { VISUAL_SCHEMA, THUNDER_VISUAL, visualFor, visualForStep, thunderText, thunderTokens } from './visual.mjs';
14
- export { MODEL_SCHEMA, THING_LANGUAGES, thunderModel, modelText, flowOf, ruleFlow, askAsQuestion, stepDoes } from './model.mjs';
13
+ export { VISUAL_SCHEMA, THUNDER_VISUAL, LEVELS, PLACES, visualFor, visualForStep, thunderText, thunderTokens } from './visual.mjs';
14
+ export { MODEL_SCHEMA, THING_LANGUAGES, thunderModel, modelText, readLevel, flowOf, ruleFlow, askAsQuestion, stepDoes } from './model.mjs';
15
15
  export { THUNDERIZE_SCHEMA, THUNDER_TEXT_EXT, thunderizeFile, thunderizeFiles } from './thunderize.mjs';
16
16
  export { SAME_SCHEMA, sameMeaning, compareRules, renderSame } from './same.mjs';
17
17
  export { plainFromReading, conditionText } from './plain-contract.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.6';
33
+ export const COMPILER_VERSION = '0.5.7';
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.
@@ -410,7 +410,7 @@ def place_order(order, card):
410
410
  slug: "openthunder",
411
411
  part: "read",
412
412
  title: "Read a whole app in OpenThunder",
413
- idea: "A real app has many files. OpenThunder, the IDE for Thunder, reads a whole repository and lets you zoom: the App, then a File, then an Action (a door), then one Rule. Every picture is drawn from the code, and the original code is always one click away.",
413
+ idea: "A real app has many files. OpenThunder, the IDE for Thunder, reads a whole repository. You move from the App to a File, then an Action (a door), then one Rule, and you can read each of them at five levels: Big Picture, Flow, Details, Text, and Original. Every picture is drawn from the code, and the original code is always one click away.",
414
414
  picture: "A map app: zoom out to see the whole city, zoom in to one street, then one house. It is the same map at every level.",
415
415
  files: [{ language: "python", label: "Python", code: PIZZA_APP }],
416
416
  focus: "place_order",
package/src/model.d.mts CHANGED
@@ -16,3 +16,28 @@ 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
+ export type LevelId = 'big-picture' | 'flow' | 'details' | 'text' | 'original';
20
+ export interface LevelItem { id: string; label: string; symbol: string; route?: string }
21
+ export interface LevelView {
22
+ level: LevelId; name: string; question: string;
23
+ scope: 'app' | 'thing' | 'member'; id: string | null; title: string; symbol: string; file: string | null; lines: [number, number] | null;
24
+ /** Flow and Details without an action or rule: choose one of these. */
25
+ needsFocus?: true; says?: string; choose?: LevelItem[];
26
+ // Big Picture
27
+ purpose?: string; things?: { id: string; label: string; doc?: string; knows: { label: string; start?: string }[]; can: LevelItem[] }[];
28
+ data?: { id: string; label: string; symbol: string; choices?: string[]; knows: string[] }[];
29
+ actions?: LevelItem[]; rules?: LevelItem[]; loose?: LevelItem[]; unknowns?: ThunderModel['unknowns'];
30
+ route?: string; doc?: string; owner?: { id: string; label: string }; youGive?: string[]; youGetBack?: string;
31
+ uses?: { id: string; label: string }[]; usedBy?: { id: string; label: string }[];
32
+ // Flow
33
+ flow?: Flow;
34
+ // Details
35
+ steps?: { id: string; text: string; does: Does; mark: string; line: number | null; depth: number; via?: string; notExplained?: true }[];
36
+ notExplained?: number; tryable?: boolean; rule?: unknown; source?: string;
37
+ // Text
38
+ text?: string;
39
+ // Original
40
+ language?: string | null;
41
+ }
42
+ /** What one reading level (LEVELS) shows for the whole model, a Thing, or one action or rule. */
43
+ export function readLevel(model: ThunderModel, level: LevelId, focus?: string): LevelView;
package/src/model.mjs CHANGED
@@ -5,7 +5,7 @@
5
5
  import { readCode } from './read.mjs';
6
6
  import { readableLanguage } from './read-repo.mjs';
7
7
  import { plainFromReading } from './plain-contract.mjs';
8
- import { visualFor } from './visual.mjs';
8
+ import { visualFor, LEVELS, DOES } from './visual.mjs';
9
9
 
10
10
  export const MODEL_SCHEMA = 'thunder-model-v1';
11
11
  /** Languages whose classes, records, and choices are read today. Others still get every function. */
@@ -454,3 +454,85 @@ export function modelText(model, id) {
454
454
  lines.push(...flowLines(m.flow));
455
455
  return `${lines.join('\n')}\n`;
456
456
  }
457
+
458
+ // ── The five reading levels: what each one shows, decided here so every product shows the same thing ─────────
459
+
460
+ const SYMBOL_OF = { action: 'action', rule: 'rule', steps: 'steps', setup: 'setup', 'not-read': 'not-read', thing: 'thing', record: 'record', choices: 'choices' };
461
+
462
+ /** Every step of a flow in reading order, with how deep it sits and which path it is on (Yes, No, For each, …). */
463
+ function detailSteps(flow) {
464
+ const byId = new Map(flow.nodes.map((n) => [n.id, n]));
465
+ const out = [];
466
+ const push = (n, depth, via, text = n.text) => out.push({ id: n.id, text, does: n.does, mark: DOES[n.does]?.mark ?? '·', line: n.line ?? null, depth, ...(via ? { via } : {}), ...(n.kind === 'code' ? { notExplained: true } : {}) });
467
+ // `via` (Yes, No, For each) labels only the first step of each path, the way Thunder Text writes "Yes:" once.
468
+ const walk = (blocks, depth, via) => {
469
+ for (const b of blocks || []) {
470
+ const n = byId.get(b.id);
471
+ if (n && n.kind !== 'start') { push(n, depth, via); via = null; }
472
+ walk(b.yes, depth + 1, 'Yes');
473
+ walk(b.no, depth + 1, 'No');
474
+ walk(b.each, depth + 1, 'For each');
475
+ walk(b.body, depth + 1, null);
476
+ for (const h of b.handlers || []) { const hn = byId.get(h.id); if (hn) push(hn, depth, null, hn.text.replace(/\?$/, '')); walk(h.blocks, depth + 1, null); }
477
+ if (b.always) { const an = byId.get(b.always.id); if (an) push(an, depth, null); walk(b.always.blocks, depth + 1, null); }
478
+ }
479
+ };
480
+ walk(flow.blocks, 0, null);
481
+ return out;
482
+ }
483
+
484
+ /**
485
+ * What one reading level shows: `level` is a LEVELS id (big-picture, flow, details, text, original); `focus` is a
486
+ * Thing or member id, or nothing for the whole model. Flow and Details need an action or rule; without one they
487
+ * give back `needsFocus` and the list to choose from. Deterministic; built only from the model.
488
+ */
489
+ export function readLevel(model, level, focus) {
490
+ const lv = LEVELS.find((l) => l.id === level);
491
+ if (!lv) throw new Error(`Unknown reading level "${level}". Use one of: ${LEVELS.map((l) => l.id).join(', ')}.`);
492
+ const member = focus ? model.members.find((m) => m.id === focus) : undefined;
493
+ const thing = focus && !member ? model.things.find((t) => t.id === focus) : undefined;
494
+ if (focus && !member && !thing) throw new Error(`Nothing in this model has the id "${focus}".`);
495
+ const owner = member?.owner ? model.things.find((t) => t.id === member.owner) : undefined;
496
+ const labelOf = (id) => model.members.find((m) => m.id === id)?.label ?? id;
497
+ const short = (m) => ({ id: m.id, label: m.label + (m.yesNo ? '?' : ''), symbol: SYMBOL_OF[m.kind], ...(m.route ? { route: m.route } : {}) });
498
+ const base = { level: lv.id, name: lv.name, question: lv.question };
499
+ const about = member
500
+ ? { scope: 'member', id: member.id, title: member.label + (member.yesNo ? '?' : ''), symbol: SYMBOL_OF[member.kind], file: member.file, lines: member.lines }
501
+ : thing ? { scope: 'thing', id: thing.id, title: thing.label, symbol: SYMBOL_OF[thing.kind], file: thing.file, lines: thing.lines }
502
+ : { scope: 'app', id: null, title: model.name, symbol: 'app', file: model.files[0]?.path ?? null, lines: null };
503
+ const uses = member ? model.links.filter((l) => l.from === member.id).map((l) => ({ id: l.to, label: labelOf(l.to) })) : [];
504
+ const usedBy = member ? model.links.filter((l) => l.to === member.id).map((l) => ({ id: l.from, label: labelOf(l.from) })) : [];
505
+
506
+ if (!member && (lv.id === 'flow' || lv.id === 'details')) {
507
+ const inScope = model.members.filter((m) => m.kind !== 'setup' && (!thing || m.owner === thing.id));
508
+ return { ...base, ...about, needsFocus: true, says: `${lv.name} shows one action or rule. Choose one.`, choose: inScope.map(short) };
509
+ }
510
+ if (lv.id === 'big-picture') {
511
+ if (member) {
512
+ return { ...base, ...about, ...(member.route ? { route: member.route } : {}), ...(member.doc ? { doc: member.doc } : {}),
513
+ ...(owner ? { owner: { id: owner.id, label: owner.label } } : {}), youGive: member.youGive, ...(member.youGetBack ? { youGetBack: member.youGetBack } : {}), uses, usedBy };
514
+ }
515
+ const inScope = (m) => m.kind !== 'setup' && (thing ? m.owner === thing.id : true);
516
+ const thingCard = (t) => ({ id: t.id, label: t.label, ...(t.doc ? { doc: t.doc } : {}), knows: t.knows.map((k) => ({ label: k.label, ...(k.start ? { start: k.start } : {}) })), can: model.members.filter((m) => m.owner === t.id && m.kind !== 'setup').map(short) });
517
+ return { ...base, ...about,
518
+ ...(thing?.doc ?? model.files[0]?.purpose ? { purpose: thing?.doc ?? model.files[0]?.purpose } : {}),
519
+ things: (thing ? [thing] : model.things.filter((t) => t.kind === 'thing')).map(thingCard),
520
+ data: thing ? [] : model.things.filter((t) => t.kind !== 'thing').map((t) => ({ id: t.id, label: t.label, symbol: SYMBOL_OF[t.kind], ...(t.choices.length ? { choices: t.choices } : {}), knows: t.knows.map((k) => k.label) })),
521
+ actions: model.members.filter((m) => inScope(m) && m.kind === 'action').map(short),
522
+ rules: model.members.filter((m) => inScope(m) && m.kind === 'rule').map(short),
523
+ loose: thing ? [] : model.members.filter((m) => !m.owner && m.kind !== 'setup' && m.kind !== 'action' && m.kind !== 'rule').map(short),
524
+ unknowns: thing ? [] : model.unknowns };
525
+ }
526
+ if (lv.id === 'flow') return { ...base, ...about, flow: member.flow };
527
+ if (lv.id === 'details') {
528
+ const steps = detailSteps(member.flow);
529
+ return { ...base, ...about, youGive: member.youGive, ...(member.youGetBack ? { youGetBack: member.youGetBack } : {}), steps,
530
+ notExplained: steps.filter((s) => s.notExplained).length, uses, usedBy, tryable: !!member.rule, ...(member.rule ? { rule: member.rule } : {}),
531
+ source: 'Read from code by the Thunder compiler, with no AI.' };
532
+ }
533
+ if (lv.id === 'text') {
534
+ const text = focus ? modelText(model, focus) : [...model.things.map((t) => modelText(model, t.id)), ...model.members.filter((m) => !m.owner && m.kind !== 'setup').map((m) => modelText(model, m.id))].join('\n');
535
+ return { ...base, ...about, text };
536
+ }
537
+ return { ...base, ...about, language: (member ?? thing) ? (member?.language ?? model.files.find((f) => f.path === thing.file)?.language ?? null) : (model.files[0]?.language ?? null) };
538
+ }
package/src/visual.d.mts CHANGED
@@ -32,8 +32,12 @@ export const SYMBOLS: Record<SymbolId, { name: string; says: string; color: Colo
32
32
  export type Does = 'start' | 'find' | 'keep-only' | 'check' | 'decide' | 'calculate' | 'save' | 'send' | '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
+ /** The five reading levels, in order: how deep you read something. */
36
+ export const LEVELS: { id: 'big-picture' | 'flow' | 'details' | 'text' | 'original'; name: string; question: string; shows: string; form: 'picture' | 'words' | 'evidence' }[];
37
+ /** Places: where you are in an app (App, Area, File, Action, Rule, Original). Same as ZOOM. */
38
+ export const PLACES: typeof ZOOM;
35
39
  export const THUNDER_VISUAL: {
36
- schema: 'thunder-visual-v1'; principle: string; forms: typeof FORMS; zoom: typeof ZOOM; colors: typeof COLORS; lines: typeof LINES;
40
+ schema: 'thunder-visual-v1'; principle: string; forms: typeof FORMS; levels: typeof LEVELS; places: typeof ZOOM; zoom: typeof ZOOM; colors: typeof COLORS; lines: typeof LINES;
37
41
  provenance: typeof PROVENANCE; steps: typeof STEP_MARKS; elements: typeof ELEMENTS; languages: typeof LANGUAGES; rules: string[];
38
42
  symbols: typeof SYMBOLS; does: typeof DOES; beginner: SymbolId[];
39
43
  };
package/src/visual.mjs CHANGED
@@ -20,8 +20,23 @@ export const FORMS = [
20
20
  ];
21
21
 
22
22
  /**
23
- * Zoom levels. Read in Thunder (OpenThunder ADR 0035) walks App > File > Action > Rule > Original; the Thunder Atlas
24
- * (ADR 0033) adds Area between App and File for large apps. `atlas` gives the Atlas level for each.
23
+ * The five reading levels: HOW DEEP you read whatever you are looking at. Every Thunder view offers the same five, in
24
+ * this order, with these names: from what something means down to the code that proves it. Big Picture, Flow, and
25
+ * Details are pictures; Text is the same meaning in words; Original is the evidence. `readLevel(model, level, focus)`
26
+ * (model.mjs) gives exactly what each level shows, so every product shows the same thing at the same level.
27
+ */
28
+ export const LEVELS = [
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
+ { 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' },
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
+ { 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
+ ];
35
+
36
+ /**
37
+ * Places: WHERE you are in an app (App > Area > File > Action or Rule), as opposed to how deep you read it (LEVELS).
38
+ * Read in Thunder (OpenThunder ADR 0035) walks App > File > Action > Rule; the Thunder Atlas (ADR 0033) adds Area
39
+ * between App and File for large apps. `atlas` gives the Atlas level for each. (Kept as ZOOM for compatibility.)
25
40
  */
26
41
  export const ZOOM = [
27
42
  { level: 0, name: 'App', from: 'A product or a repository', element: 'app', atlas: 'Z0' },
@@ -247,7 +262,9 @@ export const DOES = {
247
262
  export const BEGINNER = ['thing', 'action', 'rule', 'steps', 'data', 'stop'];
248
263
 
249
264
  /** The whole grammar in one object, for views that want to render a legend or validate themselves against it. */
250
- export const THUNDER_VISUAL = { schema: VISUAL_SCHEMA, principle: PRINCIPLE, forms: FORMS, zoom: ZOOM, colors: COLORS, lines: LINES, provenance: PROVENANCE, steps: STEP_MARKS, elements: ELEMENTS, languages: LANGUAGES, rules: RULES, symbols: SYMBOLS, does: DOES, beginner: BEGINNER };
265
+ export const PLACES = ZOOM;
266
+
267
+ export const THUNDER_VISUAL = { schema: VISUAL_SCHEMA, principle: PRINCIPLE, forms: FORMS, levels: LEVELS, places: ZOOM, zoom: ZOOM, colors: COLORS, lines: LINES, provenance: PROVENANCE, steps: STEP_MARKS, elements: ELEMENTS, languages: LANGUAGES, rules: RULES, symbols: SYMBOLS, does: DOES, beginner: BEGINNER };
251
268
 
252
269
  // ── Thunder Text colors: each word's role, decided by the compiler so every view colors it the same way ──────
253
270