@skillstech/thunderlang 0.5.6 → 0.5.8
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 +33 -0
- package/dist/core.cjs +246 -10
- package/dist/index.cjs +28 -4
- package/dist/learn.cjs +43 -5
- package/package.json +1 -1
- package/src/core.d.ts +2 -2
- package/src/core.mjs +2 -2
- package/src/emit.mjs +1 -1
- package/src/learn-lessons.mjs +1 -1
- package/src/model.d.mts +43 -0
- package/src/model.mjs +195 -3
- package/src/read.mjs +3 -1
- package/src/steps.mjs +26 -1
- package/src/visual.d.mts +5 -1
- package/src/visual.mjs +20 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
# 0.5.8
|
|
2
|
+
|
|
3
|
+
**Language: Details is a fact sheet.** `readLevel(model, 'details', id)` now gives what you need to check before you
|
|
4
|
+
trust or change an action or rule, computed by the compiler: `stops` (every way it can stop, the error, the message
|
|
5
|
+
people see, and the answers that lead there), `givesBack`, `changes` (data it changes, saves, or sends), `inputs`
|
|
6
|
+
(and the lines where each is used), `reliesOn` (each rule or action it uses, summarized), for rules `answers` (in
|
|
7
|
+
words) and `limits` (exact ranges found by running the rule, e.g. 0 or less: No fee, 1 to 7: Small fee, 8 or more:
|
|
8
|
+
Big fee), and `openQuestions` (what the code cannot tell you). The step list stays as `steps`.
|
|
9
|
+
|
|
10
|
+
**Language: web handlers read the way people think about them.**
|
|
11
|
+
- An HTTP error response is a **Stop** with its status and message: Fastify `reply.code(400).send({ error })`,
|
|
12
|
+
Express `res.status(404).json({ message })`, `new Response(..., { status })`, FastAPI `JSONResponse(...,
|
|
13
|
+
status_code=...)`, Flask `return ..., 400` ("Fails with 400 Bad Request: \"slug is required.\"").
|
|
14
|
+
- Facts a handler unpacks from the request (`const { slug, name } = request.body`, `req.params`, `request.json()`)
|
|
15
|
+
are what goes in; framework plumbing (`request`, `reply`, a database session) is not.
|
|
16
|
+
- A one-line `if (x) return reply.code(400).send({ ... })` keeps its return; the object's braces are not a block
|
|
17
|
+
(found by OpenThunder).
|
|
18
|
+
- `if (!slug)` reads "If slug is not set" (asked as "Is slug set?") instead of "If not slug".
|
|
19
|
+
|
|
20
|
+
# 0.5.7
|
|
21
|
+
|
|
22
|
+
**Language: the five reading levels.** Every Thunder view now offers the same five levels, in this order, with
|
|
23
|
+
these names: **Big Picture** (what is it, and what can it do?), **Flow** (how does it go?), **Details** (exactly
|
|
24
|
+
what happens, and how sure is Thunder?), **Text** (what does it say, in words?), and **Original** (which code says
|
|
25
|
+
so?). They are separate from **places** (App, Area, File, Thing, Action, Rule): where you are versus how deep you
|
|
26
|
+
read. Spec section 3 defines both.
|
|
27
|
+
- `LEVELS` (names, questions, what each shows) and `PLACES` in `THUNDER_VISUAL` and `/core`.
|
|
28
|
+
- `readLevel(model, level, focus)` in `/core`: exactly what a level shows for the whole app, one Thing, or one action
|
|
29
|
+
or rule. Details lists every step in order with its line, its path (Yes, No, For each), what was not explained,
|
|
30
|
+
and what it uses and is used by. Flow and Details without an action or rule give back the list to choose from.
|
|
31
|
+
- thunderlang.dev: the home page and /language lead with "One program. Five ways to read it.", and Semantic Zoom
|
|
32
|
+
(/zoom) uses the same five levels in place of its two separate controls.
|
|
33
|
+
|
|
1
34
|
# 0.5.6
|
|
2
35
|
|
|
3
36
|
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: () =>
|
|
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,
|
|
@@ -2185,6 +2188,16 @@ function sayChain(value) {
|
|
|
2185
2188
|
}
|
|
2186
2189
|
return hit ? hit.c.say(words2(src.split(".").pop().replace(/^#/, ""))) : null;
|
|
2187
2190
|
}
|
|
2191
|
+
var HTTP_STATUS = { 400: "Bad Request", 401: "Unauthorized", 402: "Payment Required", 403: "Forbidden", 404: "Not Found", 405: "Method Not Allowed", 409: "Conflict", 410: "Gone", 413: "Payload Too Large", 415: "Unsupported Media Type", 422: "Unprocessable Content", 429: "Too Many Requests", 500: "Internal Server Error", 501: "Not Implemented", 502: "Bad Gateway", 503: "Service Unavailable", 504: "Gateway Timeout" };
|
|
2192
|
+
function httpErrorOf(head) {
|
|
2193
|
+
const expr = head.replace(/^return\s+/, "").replace(/^await\s+/, "").replace(/;\s*$/, "").trim();
|
|
2194
|
+
let m = expr.match(/^(?:reply|res|response|resp|ctx\.response)\s*\.\s*(?:code|status|statusCode)\s*\(\s*([45]\d\d)\s*\)/) || expr.match(/^(?:new\s+)?(?:Response|NextResponse(?:\.json)?|HttpResponse|JSONResponse|PlainTextResponse|Response\.json)\s*\(.*\bstatus(?:_code)?\s*[:=]\s*([45]\d\d)\b/) || (/^return\b/.test(head) ? expr.match(/^.+,\s*([45]\d\d)\s*$/) : null);
|
|
2195
|
+
if (!m) return null;
|
|
2196
|
+
const status = Number(m[1]);
|
|
2197
|
+
const name = HTTP_STATUS[status] ?? (status >= 500 ? "Server Error" : "Client Error");
|
|
2198
|
+
const msg = (expr.match(/\b(?:error|message|detail|msg)\s*[:=]\s*["'`]([^"'`]{1,80})["'`]/) || expr.match(/\.(?:send|json|end)\(\s*["'`]([^"'`]{1,80})["'`]/) || [])[1];
|
|
2199
|
+
return { kind: "fail", says: `Fails with ${status} ${name}${msg ? `: "${msg}"` : ""}`, error: `${status} ${name}`, ...msg ? { message: msg } : {}, status };
|
|
2200
|
+
}
|
|
2188
2201
|
function classifyStatement(raw, { inner = 0 } = {}) {
|
|
2189
2202
|
const text = String(raw).trim();
|
|
2190
2203
|
const head = text.split("\n")[0].trim().replace(/\(\s*([\w$#.]+)\s+as\s+[^)]+\)/g, "$1").replace(/([\w$\])])!(?=[.(\[])/g, "$1").replace(/\?\.(?=[\w(\[])/g, ".").replace(/\.\(/g, "(").replace(/^\(\*+(self|this)\)\./, "$1.").replace(/\(\(\s*[A-Z][\w.<>\[\]?, ]*\s*\)\s*([\w$.]+)\s*\)/g, "$1").replace(/^(\w[\w.]*\s*=\s*)\(\s*[A-Z][\w.<>\[\]?]*\s*\)\s*/, "$1");
|
|
@@ -2209,6 +2222,8 @@ function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
2209
2222
|
const said = name && /^[a-z]/.test(name) ? `the error made by ${words2(name)}` : name;
|
|
2210
2223
|
return { kind: "fail", says: `Fails${said ? ` with ${said}` : ""}${msg ? `: "${msg}"` : ""}`, code, ...name ? { error: name } : {}, ...msg ? { message: msg } : {} };
|
|
2211
2224
|
}
|
|
2225
|
+
const httpFail = httpErrorOf(head);
|
|
2226
|
+
if (httpFail) return { ...httpFail, code };
|
|
2212
2227
|
if (m = head.match(/^return\b\s*(.*)$/)) {
|
|
2213
2228
|
const expr = stripTail(m[1]);
|
|
2214
2229
|
if (!expr) return { kind: "return", says: "Stops here", code };
|
|
@@ -2435,7 +2450,11 @@ function stepsFrom(statements) {
|
|
|
2435
2450
|
continue;
|
|
2436
2451
|
}
|
|
2437
2452
|
const step = { ...classifyStatement(s.text, { inner: s.inner || 0 }), line: s.line, span: spanOf(s) };
|
|
2438
|
-
if (
|
|
2453
|
+
if (step.inline && !/^\{/.test(step.inline.trim())) {
|
|
2454
|
+
const kid = classifyStatement(step.inline);
|
|
2455
|
+
step.children = [{ ...kid, line: s.line, span: spanOf(s) }];
|
|
2456
|
+
delete step.inline;
|
|
2457
|
+
} else if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
|
|
2439
2458
|
const kids2 = stepsFrom(s.children).steps;
|
|
2440
2459
|
if (kids2.length) {
|
|
2441
2460
|
step.children = kids2;
|
|
@@ -3467,7 +3486,7 @@ function notesSummary(ast) {
|
|
|
3467
3486
|
byLens
|
|
3468
3487
|
};
|
|
3469
3488
|
}
|
|
3470
|
-
var COMPILER_VERSION = "0.5.
|
|
3489
|
+
var COMPILER_VERSION = "0.5.8";
|
|
3471
3490
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
3472
3491
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
3473
3492
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -6779,7 +6798,8 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
|
|
|
6779
6798
|
for (const st of r.steps) {
|
|
6780
6799
|
if (st.kind !== "branch" || !st.cond) continue;
|
|
6781
6800
|
const bareProperty = /^(not\s+|!)?(?:self\.|this\.)?\w+\.\w+(\(\))?$/.test(st.cond.trim()) && !/\./.test(st.says.replace(/\(\d+ steps? inside\)$/, ""));
|
|
6782
|
-
const
|
|
6801
|
+
const bareName = /^(not\s+|!)?(?:self\.|this\.)?\w+$/.test(st.cond.trim()) && /\bis (not )?set\b/.test(st.says);
|
|
6802
|
+
const cond = bareProperty || bareName ? null : toThunderCondition(st.cond, names);
|
|
6783
6803
|
if (cond) st.says = st.says.replace(/^If .*?( \(\d+ steps? inside\))?$/, (_m, inner) => `If ${st.negate ? "not: " : ""}${plainEnums(sayCondition(cond)).replace(/ is not ""/g, " is not empty").replace(/ is ""/g, " is empty")}${inner || ""}`);
|
|
6784
6804
|
delete st.cond;
|
|
6785
6805
|
delete st.negate;
|
|
@@ -7777,6 +7797,13 @@ var FORMS = [
|
|
|
7777
7797
|
{ 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
7798
|
{ id: "source", name: "Original code", role: "evidence", says: "The code in its own language. Always one click away (View original)." }
|
|
7779
7799
|
];
|
|
7800
|
+
var LEVELS = [
|
|
7801
|
+
{ 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" },
|
|
7802
|
+
{ 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" },
|
|
7803
|
+
{ id: "details", name: "Details", question: "Exactly what happens, and how sure is Thunder?", shows: "A fact sheet: every way it can end (each Stop with its message, and what it gives back), the answers that lead there, what it changes, what goes in, what it relies on, a rule's answers and exact limits, and what the code cannot tell you.", form: "picture" },
|
|
7804
|
+
{ 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" },
|
|
7805
|
+
{ 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" }
|
|
7806
|
+
];
|
|
7780
7807
|
var ZOOM = [
|
|
7781
7808
|
{ level: 0, name: "App", from: "A product or a repository", element: "app", atlas: "Z0" },
|
|
7782
7809
|
{ level: 1, name: "Area", from: "A feature area, service, package, or folder (Atlas; optional in Read in Thunder)", element: "area", atlas: "Z1" },
|
|
@@ -7960,7 +7987,8 @@ var DOES = {
|
|
|
7960
7987
|
code: { label: "Not read yet", mark: "\xB7", color: "unread", dashed: true }
|
|
7961
7988
|
};
|
|
7962
7989
|
var BEGINNER = ["thing", "action", "rule", "steps", "data", "stop"];
|
|
7963
|
-
var
|
|
7990
|
+
var PLACES = ZOOM;
|
|
7991
|
+
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
7992
|
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
7993
|
function thunderTokens(line) {
|
|
7966
7994
|
const out = [];
|
|
@@ -8484,6 +8512,27 @@ function flowOf(steps, { start = "Start", memberIndex = /* @__PURE__ */ new Map(
|
|
|
8484
8512
|
return { nodes: nodes2, edges, blocks: blocks2 };
|
|
8485
8513
|
}
|
|
8486
8514
|
var idOf = (...parts) => parts.join("#").replace(/\s+/g, "");
|
|
8515
|
+
function youGiveOf(item2) {
|
|
8516
|
+
const given = (item2.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name) && !p.plumbing).map((p) => words5(p.name));
|
|
8517
|
+
const codes = [];
|
|
8518
|
+
const walk = (steps) => {
|
|
8519
|
+
for (const s of steps || []) {
|
|
8520
|
+
if (s.code) codes.push(s.code);
|
|
8521
|
+
walk(s.children);
|
|
8522
|
+
walk(s.otherwise);
|
|
8523
|
+
}
|
|
8524
|
+
};
|
|
8525
|
+
walk(item2.steps);
|
|
8526
|
+
for (const c of codes) {
|
|
8527
|
+
const m = c.match(/^(?:const|let|var)\s*\{([^}]+)\}\s*=\s*\(?\s*(?:await\s+)?(?:req|request|ctx\.request|c\.req|event)\s*\.\s*(?:body|query|params|json\(\))/);
|
|
8528
|
+
if (!m) continue;
|
|
8529
|
+
for (const part of m[1].split(",")) {
|
|
8530
|
+
const name = part.split(/[:=]/)[0].replace(/^\.\.\./, "").trim();
|
|
8531
|
+
if (/^[A-Za-z_$][\w$]*$/.test(name) && !given.includes(words5(name))) given.push(words5(name));
|
|
8532
|
+
}
|
|
8533
|
+
}
|
|
8534
|
+
return given;
|
|
8535
|
+
}
|
|
8487
8536
|
function thunderModel(files, { name = "app" } = {}) {
|
|
8488
8537
|
const things = [], members = [], links = [], unknowns = [], fileInfo = [];
|
|
8489
8538
|
for (const f of files) {
|
|
@@ -8539,7 +8588,7 @@ function thunderModel(files, { name = "app" } = {}) {
|
|
|
8539
8588
|
lines: [item2.line, bodyEnd2],
|
|
8540
8589
|
...item2.doc ? { doc: item2.doc } : {},
|
|
8541
8590
|
...item2.route ? { route: `${item2.route.method} ${item2.route.path}`.trim() } : {},
|
|
8542
|
-
youGive: (item2
|
|
8591
|
+
youGive: youGiveOf(item2),
|
|
8543
8592
|
...item2.returns && kind !== "rule" ? { youGetBack: kindWords(item2.returns) ?? item2.returns } : {},
|
|
8544
8593
|
...rule ? { rule, question: rule.question } : {},
|
|
8545
8594
|
// A yes/no rule is named as a question ("Can borrow?"); a rule with named answers is not ("Late fee").
|
|
@@ -8630,6 +8679,190 @@ function modelText(model, id2) {
|
|
|
8630
8679
|
return `${lines.join("\n")}
|
|
8631
8680
|
`;
|
|
8632
8681
|
}
|
|
8682
|
+
var SYMBOL_OF = { action: "action", rule: "rule", steps: "steps", setup: "setup", "not-read": "not-read", thing: "thing", record: "record", choices: "choices" };
|
|
8683
|
+
function detailSteps(flow) {
|
|
8684
|
+
const byId = new Map(flow.nodes.map((n) => [n.id, n]));
|
|
8685
|
+
const out = [];
|
|
8686
|
+
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 } : {} });
|
|
8687
|
+
const walk = (blocks2, depth, via) => {
|
|
8688
|
+
for (const b of blocks2 || []) {
|
|
8689
|
+
const n = byId.get(b.id);
|
|
8690
|
+
if (n && n.kind !== "start") {
|
|
8691
|
+
push(n, depth, via);
|
|
8692
|
+
via = null;
|
|
8693
|
+
}
|
|
8694
|
+
walk(b.yes, depth + 1, "Yes");
|
|
8695
|
+
walk(b.no, depth + 1, "No");
|
|
8696
|
+
walk(b.each, depth + 1, "For each");
|
|
8697
|
+
walk(b.body, depth + 1, null);
|
|
8698
|
+
for (const h of b.handlers || []) {
|
|
8699
|
+
const hn = byId.get(h.id);
|
|
8700
|
+
if (hn) push(hn, depth, null, hn.text.replace(/\?$/, ""));
|
|
8701
|
+
walk(h.blocks, depth + 1, null);
|
|
8702
|
+
}
|
|
8703
|
+
if (b.always) {
|
|
8704
|
+
const an = byId.get(b.always.id);
|
|
8705
|
+
if (an) push(an, depth, null);
|
|
8706
|
+
walk(b.always.blocks, depth + 1, null);
|
|
8707
|
+
}
|
|
8708
|
+
}
|
|
8709
|
+
};
|
|
8710
|
+
walk(flow.blocks, 0, null);
|
|
8711
|
+
return out;
|
|
8712
|
+
}
|
|
8713
|
+
var CHANGES = /^(Sets|Adds|Removes|Subtracts|Clears|Marks|Saves|Deletes|Updates|Appends|Increases|Decreases|Sends|Records|Stores|Writes)\b/;
|
|
8714
|
+
function pathsOf(flow) {
|
|
8715
|
+
const byId = new Map(flow.nodes.map((n) => [n.id, n]));
|
|
8716
|
+
const out = [];
|
|
8717
|
+
const walk = (blocks2, when) => {
|
|
8718
|
+
for (const b of blocks2 || []) {
|
|
8719
|
+
const n = byId.get(b.id);
|
|
8720
|
+
if (n && n.kind !== "start") out.push({ node: n, when });
|
|
8721
|
+
const q = n?.text ?? "";
|
|
8722
|
+
walk(b.yes, [...when, { question: q, answer: "Yes" }]);
|
|
8723
|
+
walk(b.no, [...when, { question: q, answer: "No" }]);
|
|
8724
|
+
walk(b.each, [...when, { question: q, answer: "For each" }]);
|
|
8725
|
+
walk(b.body, when);
|
|
8726
|
+
for (const h of b.handlers || []) {
|
|
8727
|
+
const hn = byId.get(h.id);
|
|
8728
|
+
walk(h.blocks, [...when, { question: (hn?.text ?? "").replace(/\?$/, ""), answer: "Yes" }]);
|
|
8729
|
+
}
|
|
8730
|
+
if (b.always) walk(b.always.blocks, when);
|
|
8731
|
+
}
|
|
8732
|
+
};
|
|
8733
|
+
walk(flow.blocks, []);
|
|
8734
|
+
return out;
|
|
8735
|
+
}
|
|
8736
|
+
function ruleAnswers(rule) {
|
|
8737
|
+
const zero = Object.fromEntries(rule.inputs.map((i) => [i.id, i.kind === "yesno" ? true : 0]));
|
|
8738
|
+
let explained;
|
|
8739
|
+
try {
|
|
8740
|
+
explained = explainPlain(rule, zero);
|
|
8741
|
+
} catch {
|
|
8742
|
+
return null;
|
|
8743
|
+
}
|
|
8744
|
+
const answers = explained.rules.map((r) => ({ answer: answerWords(r.outcome), when: r.checks.map((c) => c.text).join(r.join === "any" ? " or " : " and ") }));
|
|
8745
|
+
if (rule.otherwise) answers.push({ answer: answerWords(rule.otherwise), when: "otherwise" });
|
|
8746
|
+
return answers;
|
|
8747
|
+
}
|
|
8748
|
+
function ruleRanges(rule) {
|
|
8749
|
+
if (rule.inputs.length !== 1 || rule.inputs[0].kind === "yesno") return null;
|
|
8750
|
+
const id2 = rule.inputs[0].id;
|
|
8751
|
+
const limits = rule.rules.flatMap((r) => r.conditions).filter((c) => c.input === id2 && typeof c.value === "number").map((c) => c.value);
|
|
8752
|
+
if (!limits.length || !limits.every(Number.isInteger)) return null;
|
|
8753
|
+
const lo = Math.min(...limits) - 1, hi = Math.max(...limits) + 1;
|
|
8754
|
+
const ranges = [];
|
|
8755
|
+
for (let v = lo; v <= hi; v++) {
|
|
8756
|
+
let outcome;
|
|
8757
|
+
try {
|
|
8758
|
+
outcome = answerWords(explainPlain(rule, { [id2]: v }).outcome);
|
|
8759
|
+
} catch {
|
|
8760
|
+
return null;
|
|
8761
|
+
}
|
|
8762
|
+
const last = ranges.at(-1);
|
|
8763
|
+
if (last && last.answer === outcome) last.to = v;
|
|
8764
|
+
else ranges.push({ from: v, to: v, answer: outcome });
|
|
8765
|
+
}
|
|
8766
|
+
ranges[0].from = null;
|
|
8767
|
+
ranges.at(-1).to = null;
|
|
8768
|
+
return { fact: rule.inputs[0].label.replace(/^the /, ""), ranges };
|
|
8769
|
+
}
|
|
8770
|
+
function detailsFacts(model, member) {
|
|
8771
|
+
const paths = pathsOf(member.flow);
|
|
8772
|
+
const memberOf = (id2) => model.members.find((m) => m.id === id2);
|
|
8773
|
+
const inputs = member.youGive.map((label) => {
|
|
8774
|
+
const re = new RegExp(`\\b${label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "i");
|
|
8775
|
+
const lines = [...new Set(paths.filter((p) => re.test(p.node.text) && p.node.line).map((p) => p.node.line))];
|
|
8776
|
+
return { label, lines };
|
|
8777
|
+
});
|
|
8778
|
+
const changes = paths.filter((p) => p.node.kind !== "decision" && p.node.kind !== "stop" && p.node.kind !== "end" && (p.node.does === "save" || p.node.does === "send" || CHANGES.test(p.node.text) && /'s\b|\bto\b|\bfrom\b/.test(p.node.text))).map((p) => ({ text: p.node.text, line: p.node.line ?? null, does: p.node.does, when: p.when }));
|
|
8779
|
+
const stops = paths.filter((p) => p.node.kind === "stop").map((p) => {
|
|
8780
|
+
const m = p.node.text.match(/^Stop:\s*([^:]+?)(?::\s*"(.*)")?$/);
|
|
8781
|
+
return { error: m ? m[1].trim() : p.node.text, ...m?.[2] ? { message: m[2] } : {}, line: p.node.line ?? null, when: p.when };
|
|
8782
|
+
});
|
|
8783
|
+
const givesBack = paths.filter((p) => p.node.kind === "end" || p.node.answer).map((p) => ({ text: p.node.answer ? answerWords(p.node.text) : p.node.text, line: p.node.line ?? null, when: p.node.otherwise ? [{ question: "none of the above", answer: "Otherwise" }] : p.when }));
|
|
8784
|
+
const reliesOn = model.links.filter((l) => l.from === member.id).map((l) => memberOf(l.to)).filter(Boolean).map((t) => {
|
|
8785
|
+
const answers2 = t.rule ? ruleAnswers(t.rule) : null;
|
|
8786
|
+
const flowAnswers = [...new Set(t.flow.nodes.filter((n) => n.answer).map((n) => n.text))];
|
|
8787
|
+
const list = answers2 ? answers2.map((a) => a.answer) : flowAnswers;
|
|
8788
|
+
const says = list.length ? `Answers ${list.join(", ").replace(/, ([^,]*)$/, list.length > 2 ? ", or $1" : " or $1")}.` : t.youGetBack ? `Gives back ${t.youGetBack}.` : t.flow.nodes.some((n) => n.kind === "stop") ? `Can stop with ${t.flow.nodes.filter((n) => n.kind === "stop").map((n) => n.text.replace(/^Stop:\s*/, "").split(":")[0]).join(", ")}.` : `${t.flow.nodes.filter((n) => n.kind !== "start").length} steps.`;
|
|
8789
|
+
return { id: t.id, label: t.label + (t.yesNo ? "?" : ""), symbol: SYMBOL_OF[t.kind], says };
|
|
8790
|
+
});
|
|
8791
|
+
const answers = member.rule ? ruleAnswers(member.rule) : null;
|
|
8792
|
+
const limits = member.rule ? ruleRanges(member.rule) : null;
|
|
8793
|
+
const openQuestions = (member.rule?.needsReview ?? []).filter((q) => !/^No examples yet/.test(q));
|
|
8794
|
+
return { inputs, changes, stops, givesBack, reliesOn, ...answers ? { answers } : {}, ...limits ? { limits } : {}, openQuestions };
|
|
8795
|
+
}
|
|
8796
|
+
function readLevel(model, level, focus) {
|
|
8797
|
+
const lv = LEVELS.find((l) => l.id === level);
|
|
8798
|
+
if (!lv) throw new Error(`Unknown reading level "${level}". Use one of: ${LEVELS.map((l) => l.id).join(", ")}.`);
|
|
8799
|
+
const member = focus ? model.members.find((m) => m.id === focus) : void 0;
|
|
8800
|
+
const thing = focus && !member ? model.things.find((t) => t.id === focus) : void 0;
|
|
8801
|
+
if (focus && !member && !thing) throw new Error(`Nothing in this model has the id "${focus}".`);
|
|
8802
|
+
const owner = member?.owner ? model.things.find((t) => t.id === member.owner) : void 0;
|
|
8803
|
+
const labelOf = (id2) => model.members.find((m) => m.id === id2)?.label ?? id2;
|
|
8804
|
+
const short = (m) => ({ id: m.id, label: m.label + (m.yesNo ? "?" : ""), symbol: SYMBOL_OF[m.kind], ...m.route ? { route: m.route } : {} });
|
|
8805
|
+
const base = { level: lv.id, name: lv.name, question: lv.question };
|
|
8806
|
+
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 };
|
|
8807
|
+
const uses = member ? model.links.filter((l) => l.from === member.id).map((l) => ({ id: l.to, label: labelOf(l.to) })) : [];
|
|
8808
|
+
const usedBy = member ? model.links.filter((l) => l.to === member.id).map((l) => ({ id: l.from, label: labelOf(l.from) })) : [];
|
|
8809
|
+
if (!member && (lv.id === "flow" || lv.id === "details")) {
|
|
8810
|
+
const inScope = model.members.filter((m) => m.kind !== "setup" && (!thing || m.owner === thing.id));
|
|
8811
|
+
return { ...base, ...about, needsFocus: true, says: `${lv.name} shows one action or rule. Choose one.`, choose: inScope.map(short) };
|
|
8812
|
+
}
|
|
8813
|
+
if (lv.id === "big-picture") {
|
|
8814
|
+
if (member) {
|
|
8815
|
+
return {
|
|
8816
|
+
...base,
|
|
8817
|
+
...about,
|
|
8818
|
+
...member.route ? { route: member.route } : {},
|
|
8819
|
+
...member.doc ? { doc: member.doc } : {},
|
|
8820
|
+
...owner ? { owner: { id: owner.id, label: owner.label } } : {},
|
|
8821
|
+
youGive: member.youGive,
|
|
8822
|
+
...member.youGetBack ? { youGetBack: member.youGetBack } : {},
|
|
8823
|
+
uses,
|
|
8824
|
+
usedBy
|
|
8825
|
+
};
|
|
8826
|
+
}
|
|
8827
|
+
const inScope = (m) => m.kind !== "setup" && (thing ? m.owner === thing.id : true);
|
|
8828
|
+
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) });
|
|
8829
|
+
return {
|
|
8830
|
+
...base,
|
|
8831
|
+
...about,
|
|
8832
|
+
...thing?.doc ?? model.files[0]?.purpose ? { purpose: thing?.doc ?? model.files[0]?.purpose } : {},
|
|
8833
|
+
things: (thing ? [thing] : model.things.filter((t) => t.kind === "thing")).map(thingCard),
|
|
8834
|
+
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) })),
|
|
8835
|
+
actions: model.members.filter((m) => inScope(m) && m.kind === "action").map(short),
|
|
8836
|
+
rules: model.members.filter((m) => inScope(m) && m.kind === "rule").map(short),
|
|
8837
|
+
loose: thing ? [] : model.members.filter((m) => !m.owner && m.kind !== "setup" && m.kind !== "action" && m.kind !== "rule").map(short),
|
|
8838
|
+
unknowns: thing ? [] : model.unknowns
|
|
8839
|
+
};
|
|
8840
|
+
}
|
|
8841
|
+
if (lv.id === "flow") return { ...base, ...about, flow: member.flow };
|
|
8842
|
+
if (lv.id === "details") {
|
|
8843
|
+
const steps = detailSteps(member.flow);
|
|
8844
|
+
return {
|
|
8845
|
+
...base,
|
|
8846
|
+
...about,
|
|
8847
|
+
youGive: member.youGive,
|
|
8848
|
+
...member.youGetBack ? { youGetBack: member.youGetBack } : {},
|
|
8849
|
+
...member.doc ? { doc: member.doc } : {},
|
|
8850
|
+
...detailsFacts(model, member),
|
|
8851
|
+
steps,
|
|
8852
|
+
notExplained: steps.filter((s) => s.notExplained).length,
|
|
8853
|
+
uses,
|
|
8854
|
+
usedBy,
|
|
8855
|
+
tryable: !!member.rule,
|
|
8856
|
+
...member.rule ? { rule: member.rule } : {},
|
|
8857
|
+
source: "Read from code by the Thunder compiler, with no AI."
|
|
8858
|
+
};
|
|
8859
|
+
}
|
|
8860
|
+
if (lv.id === "text") {
|
|
8861
|
+
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");
|
|
8862
|
+
return { ...base, ...about, text };
|
|
8863
|
+
}
|
|
8864
|
+
return { ...base, ...about, language: member ?? thing ? member?.language ?? model.files.find((f) => f.path === thing.file)?.language ?? null : model.files[0]?.language ?? null };
|
|
8865
|
+
}
|
|
8633
8866
|
|
|
8634
8867
|
// src/thunderize.mjs
|
|
8635
8868
|
var THUNDERIZE_SCHEMA = "thunderize-v1";
|
|
@@ -11820,7 +12053,7 @@ function intentBrief(focus) {
|
|
|
11820
12053
|
|
|
11821
12054
|
// src/comprehension.mjs
|
|
11822
12055
|
var COMPREHENSION_SCHEMA = "intent-comprehension-v1";
|
|
11823
|
-
var
|
|
12056
|
+
var LEVELS2 = [
|
|
11824
12057
|
{ level: "C0", name: "Unknown", means: "Intent exists with no stated purpose." },
|
|
11825
12058
|
{ level: "C1", name: "Described", means: "Purpose and a summary exist." },
|
|
11826
12059
|
{ level: "C2", name: "Structured", means: "Guarantees, rules, states, failures, or constraints exist." },
|
|
@@ -11899,10 +12132,10 @@ function comprehensionLevel(ast, { observed = false, learningPath = false, gover
|
|
|
11899
12132
|
if (signals[s].met) n += 1;
|
|
11900
12133
|
else break;
|
|
11901
12134
|
}
|
|
11902
|
-
const level =
|
|
12135
|
+
const level = LEVELS2[n];
|
|
11903
12136
|
const missing = [];
|
|
11904
12137
|
for (let i = n; i < ladder.length; i += 1) {
|
|
11905
|
-
const lv =
|
|
12138
|
+
const lv = LEVELS2[i + 1];
|
|
11906
12139
|
missing.push({ level: lv.level, name: lv.name, need: lv.means, owner: signals[ladder[i]].owner });
|
|
11907
12140
|
}
|
|
11908
12141
|
return {
|
|
@@ -11931,7 +12164,7 @@ function comprehensionLevel(ast, { observed = false, learningPath = false, gover
|
|
|
11931
12164
|
function comprehensionReport(asts, opts = {}) {
|
|
11932
12165
|
const missions = (asts || []).map((ast) => comprehensionLevel(ast, opts));
|
|
11933
12166
|
const byLevel = {};
|
|
11934
|
-
for (const lv of
|
|
12167
|
+
for (const lv of LEVELS2) byLevel[lv.level] = 0;
|
|
11935
12168
|
for (const m of missions) byLevel[m.level] += 1;
|
|
11936
12169
|
return { schema: COMPREHENSION_SCHEMA, count: missions.length, byLevel, missions };
|
|
11937
12170
|
}
|
|
@@ -12574,12 +12807,14 @@ function translateDecisions(ast, lang) {
|
|
|
12574
12807
|
IR_RELATIONSHIP_TYPES,
|
|
12575
12808
|
IR_SCHEMA,
|
|
12576
12809
|
KNOWN_LENSES,
|
|
12810
|
+
LEVELS,
|
|
12577
12811
|
MODEL_SCHEMA,
|
|
12578
12812
|
MODE_VALUES,
|
|
12579
12813
|
NODE_FIELDS,
|
|
12580
12814
|
NODE_STATUSES,
|
|
12581
12815
|
NODE_TYPES,
|
|
12582
12816
|
PATCH_SCHEMA,
|
|
12817
|
+
PLACES,
|
|
12583
12818
|
PLAIN_SCHEMA,
|
|
12584
12819
|
PROMOTE_SCHEMA,
|
|
12585
12820
|
PROOF_CHECK_KEYS,
|
|
@@ -12704,6 +12939,7 @@ function translateDecisions(ast, lang) {
|
|
|
12704
12939
|
promoteDecision,
|
|
12705
12940
|
proposeIntent,
|
|
12706
12941
|
readCode,
|
|
12942
|
+
readLevel,
|
|
12707
12943
|
readRepo,
|
|
12708
12944
|
readableLanguage,
|
|
12709
12945
|
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.
|
|
2426
|
+
var COMPILER_VERSION = "0.5.8";
|
|
2427
2427
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
2428
2428
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
2429
2429
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -9399,6 +9399,16 @@ function sayChain(value) {
|
|
|
9399
9399
|
}
|
|
9400
9400
|
return hit ? hit.c.say(words2(src.split(".").pop().replace(/^#/, ""))) : null;
|
|
9401
9401
|
}
|
|
9402
|
+
var HTTP_STATUS = { 400: "Bad Request", 401: "Unauthorized", 402: "Payment Required", 403: "Forbidden", 404: "Not Found", 405: "Method Not Allowed", 409: "Conflict", 410: "Gone", 413: "Payload Too Large", 415: "Unsupported Media Type", 422: "Unprocessable Content", 429: "Too Many Requests", 500: "Internal Server Error", 501: "Not Implemented", 502: "Bad Gateway", 503: "Service Unavailable", 504: "Gateway Timeout" };
|
|
9403
|
+
function httpErrorOf(head) {
|
|
9404
|
+
const expr = head.replace(/^return\s+/, "").replace(/^await\s+/, "").replace(/;\s*$/, "").trim();
|
|
9405
|
+
let m = expr.match(/^(?:reply|res|response|resp|ctx\.response)\s*\.\s*(?:code|status|statusCode)\s*\(\s*([45]\d\d)\s*\)/) || expr.match(/^(?:new\s+)?(?:Response|NextResponse(?:\.json)?|HttpResponse|JSONResponse|PlainTextResponse|Response\.json)\s*\(.*\bstatus(?:_code)?\s*[:=]\s*([45]\d\d)\b/) || (/^return\b/.test(head) ? expr.match(/^.+,\s*([45]\d\d)\s*$/) : null);
|
|
9406
|
+
if (!m) return null;
|
|
9407
|
+
const status = Number(m[1]);
|
|
9408
|
+
const name = HTTP_STATUS[status] ?? (status >= 500 ? "Server Error" : "Client Error");
|
|
9409
|
+
const msg = (expr.match(/\b(?:error|message|detail|msg)\s*[:=]\s*["'`]([^"'`]{1,80})["'`]/) || expr.match(/\.(?:send|json|end)\(\s*["'`]([^"'`]{1,80})["'`]/) || [])[1];
|
|
9410
|
+
return { kind: "fail", says: `Fails with ${status} ${name}${msg ? `: "${msg}"` : ""}`, error: `${status} ${name}`, ...msg ? { message: msg } : {}, status };
|
|
9411
|
+
}
|
|
9402
9412
|
function classifyStatement(raw, { inner = 0 } = {}) {
|
|
9403
9413
|
const text = String(raw).trim();
|
|
9404
9414
|
const head = text.split("\n")[0].trim().replace(/\(\s*([\w$#.]+)\s+as\s+[^)]+\)/g, "$1").replace(/([\w$\])])!(?=[.(\[])/g, "$1").replace(/\?\.(?=[\w(\[])/g, ".").replace(/\.\(/g, "(").replace(/^\(\*+(self|this)\)\./, "$1.").replace(/\(\(\s*[A-Z][\w.<>\[\]?, ]*\s*\)\s*([\w$.]+)\s*\)/g, "$1").replace(/^(\w[\w.]*\s*=\s*)\(\s*[A-Z][\w.<>\[\]?]*\s*\)\s*/, "$1");
|
|
@@ -9423,6 +9433,8 @@ function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
9423
9433
|
const said = name && /^[a-z]/.test(name) ? `the error made by ${words2(name)}` : name;
|
|
9424
9434
|
return { kind: "fail", says: `Fails${said ? ` with ${said}` : ""}${msg ? `: "${msg}"` : ""}`, code, ...name ? { error: name } : {}, ...msg ? { message: msg } : {} };
|
|
9425
9435
|
}
|
|
9436
|
+
const httpFail = httpErrorOf(head);
|
|
9437
|
+
if (httpFail) return { ...httpFail, code };
|
|
9426
9438
|
if (m = head.match(/^return\b\s*(.*)$/)) {
|
|
9427
9439
|
const expr = stripTail(m[1]);
|
|
9428
9440
|
if (!expr) return { kind: "return", says: "Stops here", code };
|
|
@@ -9649,7 +9661,11 @@ function stepsFrom(statements) {
|
|
|
9649
9661
|
continue;
|
|
9650
9662
|
}
|
|
9651
9663
|
const step = { ...classifyStatement(s.text, { inner: s.inner || 0 }), line: s.line, span: spanOf(s) };
|
|
9652
|
-
if (
|
|
9664
|
+
if (step.inline && !/^\{/.test(step.inline.trim())) {
|
|
9665
|
+
const kid = classifyStatement(step.inline);
|
|
9666
|
+
step.children = [{ ...kid, line: s.line, span: spanOf(s) }];
|
|
9667
|
+
delete step.inline;
|
|
9668
|
+
} else if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
|
|
9653
9669
|
const kids2 = stepsFrom(s.children).steps;
|
|
9654
9670
|
if (kids2.length) {
|
|
9655
9671
|
step.children = kids2;
|
|
@@ -11668,7 +11684,8 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
|
|
|
11668
11684
|
for (const st of r.steps) {
|
|
11669
11685
|
if (st.kind !== "branch" || !st.cond) continue;
|
|
11670
11686
|
const bareProperty = /^(not\s+|!)?(?:self\.|this\.)?\w+\.\w+(\(\))?$/.test(st.cond.trim()) && !/\./.test(st.says.replace(/\(\d+ steps? inside\)$/, ""));
|
|
11671
|
-
const
|
|
11687
|
+
const bareName = /^(not\s+|!)?(?:self\.|this\.)?\w+$/.test(st.cond.trim()) && /\bis (not )?set\b/.test(st.says);
|
|
11688
|
+
const cond = bareProperty || bareName ? null : toThunderCondition(st.cond, names);
|
|
11672
11689
|
if (cond) st.says = st.says.replace(/^If .*?( \(\d+ steps? inside\))?$/, (_m, inner) => `If ${st.negate ? "not: " : ""}${plainEnums(sayCondition(cond)).replace(/ is not ""/g, " is not empty").replace(/ is ""/g, " is empty")}${inner || ""}`);
|
|
11673
11690
|
delete st.cond;
|
|
11674
11691
|
delete st.negate;
|
|
@@ -13430,6 +13447,13 @@ var FORMS = [
|
|
|
13430
13447
|
{ 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
13448
|
{ id: "source", name: "Original code", role: "evidence", says: "The code in its own language. Always one click away (View original)." }
|
|
13432
13449
|
];
|
|
13450
|
+
var LEVELS2 = [
|
|
13451
|
+
{ 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" },
|
|
13452
|
+
{ 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" },
|
|
13453
|
+
{ id: "details", name: "Details", question: "Exactly what happens, and how sure is Thunder?", shows: "A fact sheet: every way it can end (each Stop with its message, and what it gives back), the answers that lead there, what it changes, what goes in, what it relies on, a rule's answers and exact limits, and what the code cannot tell you.", form: "picture" },
|
|
13454
|
+
{ 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" },
|
|
13455
|
+
{ 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" }
|
|
13456
|
+
];
|
|
13433
13457
|
var ZOOM = [
|
|
13434
13458
|
{ level: 0, name: "App", from: "A product or a repository", element: "app", atlas: "Z0" },
|
|
13435
13459
|
{ level: 1, name: "Area", from: "A feature area, service, package, or folder (Atlas; optional in Read in Thunder)", element: "area", atlas: "Z1" },
|
|
@@ -13613,7 +13637,7 @@ var DOES = {
|
|
|
13613
13637
|
code: { label: "Not read yet", mark: "\xB7", color: "unread", dashed: true }
|
|
13614
13638
|
};
|
|
13615
13639
|
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 };
|
|
13640
|
+
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
13641
|
|
|
13618
13642
|
// src/thunderize.mjs
|
|
13619
13643
|
var THUNDERIZE_SCHEMA = "thunderize-v1";
|
package/dist/learn.cjs
CHANGED
|
@@ -217,6 +217,16 @@ function sayChain(value) {
|
|
|
217
217
|
}
|
|
218
218
|
return hit ? hit.c.say(words(src.split(".").pop().replace(/^#/, ""))) : null;
|
|
219
219
|
}
|
|
220
|
+
var HTTP_STATUS = { 400: "Bad Request", 401: "Unauthorized", 402: "Payment Required", 403: "Forbidden", 404: "Not Found", 405: "Method Not Allowed", 409: "Conflict", 410: "Gone", 413: "Payload Too Large", 415: "Unsupported Media Type", 422: "Unprocessable Content", 429: "Too Many Requests", 500: "Internal Server Error", 501: "Not Implemented", 502: "Bad Gateway", 503: "Service Unavailable", 504: "Gateway Timeout" };
|
|
221
|
+
function httpErrorOf(head) {
|
|
222
|
+
const expr = head.replace(/^return\s+/, "").replace(/^await\s+/, "").replace(/;\s*$/, "").trim();
|
|
223
|
+
let m = expr.match(/^(?:reply|res|response|resp|ctx\.response)\s*\.\s*(?:code|status|statusCode)\s*\(\s*([45]\d\d)\s*\)/) || expr.match(/^(?:new\s+)?(?:Response|NextResponse(?:\.json)?|HttpResponse|JSONResponse|PlainTextResponse|Response\.json)\s*\(.*\bstatus(?:_code)?\s*[:=]\s*([45]\d\d)\b/) || (/^return\b/.test(head) ? expr.match(/^.+,\s*([45]\d\d)\s*$/) : null);
|
|
224
|
+
if (!m) return null;
|
|
225
|
+
const status = Number(m[1]);
|
|
226
|
+
const name = HTTP_STATUS[status] ?? (status >= 500 ? "Server Error" : "Client Error");
|
|
227
|
+
const msg = (expr.match(/\b(?:error|message|detail|msg)\s*[:=]\s*["'`]([^"'`]{1,80})["'`]/) || expr.match(/\.(?:send|json|end)\(\s*["'`]([^"'`]{1,80})["'`]/) || [])[1];
|
|
228
|
+
return { kind: "fail", says: `Fails with ${status} ${name}${msg ? `: "${msg}"` : ""}`, error: `${status} ${name}`, ...msg ? { message: msg } : {}, status };
|
|
229
|
+
}
|
|
220
230
|
function classifyStatement(raw, { inner = 0 } = {}) {
|
|
221
231
|
const text = String(raw).trim();
|
|
222
232
|
const head = text.split("\n")[0].trim().replace(/\(\s*([\w$#.]+)\s+as\s+[^)]+\)/g, "$1").replace(/([\w$\])])!(?=[.(\[])/g, "$1").replace(/\?\.(?=[\w(\[])/g, ".").replace(/\.\(/g, "(").replace(/^\(\*+(self|this)\)\./, "$1.").replace(/\(\(\s*[A-Z][\w.<>\[\]?, ]*\s*\)\s*([\w$.]+)\s*\)/g, "$1").replace(/^(\w[\w.]*\s*=\s*)\(\s*[A-Z][\w.<>\[\]?]*\s*\)\s*/, "$1");
|
|
@@ -241,6 +251,8 @@ function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
241
251
|
const said = name && /^[a-z]/.test(name) ? `the error made by ${words(name)}` : name;
|
|
242
252
|
return { kind: "fail", says: `Fails${said ? ` with ${said}` : ""}${msg ? `: "${msg}"` : ""}`, code, ...name ? { error: name } : {}, ...msg ? { message: msg } : {} };
|
|
243
253
|
}
|
|
254
|
+
const httpFail = httpErrorOf(head);
|
|
255
|
+
if (httpFail) return { ...httpFail, code };
|
|
244
256
|
if (m = head.match(/^return\b\s*(.*)$/)) {
|
|
245
257
|
const expr = stripTail(m[1]);
|
|
246
258
|
if (!expr) return { kind: "return", says: "Stops here", code };
|
|
@@ -467,7 +479,11 @@ function stepsFrom(statements) {
|
|
|
467
479
|
continue;
|
|
468
480
|
}
|
|
469
481
|
const step = { ...classifyStatement(s.text, { inner: s.inner || 0 }), line: s.line, span: spanOf(s) };
|
|
470
|
-
if (
|
|
482
|
+
if (step.inline && !/^\{/.test(step.inline.trim())) {
|
|
483
|
+
const kid = classifyStatement(step.inline);
|
|
484
|
+
step.children = [{ ...kid, line: s.line, span: spanOf(s) }];
|
|
485
|
+
delete step.inline;
|
|
486
|
+
} else if (s.children?.length && ["branch", "loop", "try"].includes(step.kind)) {
|
|
471
487
|
const kids2 = stepsFrom(s.children).steps;
|
|
472
488
|
if (kids2.length) {
|
|
473
489
|
step.children = kids2;
|
|
@@ -1921,7 +1937,7 @@ var SEMANTIC_TYPES = Object.keys(SEMANTIC);
|
|
|
1921
1937
|
var PRIMITIVE_TYPES = Object.keys(PRIMITIVE);
|
|
1922
1938
|
|
|
1923
1939
|
// src/emit.mjs
|
|
1924
|
-
var COMPILER_VERSION = "0.5.
|
|
1940
|
+
var COMPILER_VERSION = "0.5.8";
|
|
1925
1941
|
|
|
1926
1942
|
// src/lift.mjs
|
|
1927
1943
|
var IR_SCHEMA_VERSION = "0.1.0";
|
|
@@ -4401,7 +4417,8 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
|
|
|
4401
4417
|
for (const st of r.steps) {
|
|
4402
4418
|
if (st.kind !== "branch" || !st.cond) continue;
|
|
4403
4419
|
const bareProperty = /^(not\s+|!)?(?:self\.|this\.)?\w+\.\w+(\(\))?$/.test(st.cond.trim()) && !/\./.test(st.says.replace(/\(\d+ steps? inside\)$/, ""));
|
|
4404
|
-
const
|
|
4420
|
+
const bareName = /^(not\s+|!)?(?:self\.|this\.)?\w+$/.test(st.cond.trim()) && /\bis (not )?set\b/.test(st.says);
|
|
4421
|
+
const cond = bareProperty || bareName ? null : toThunderCondition(st.cond, names);
|
|
4405
4422
|
if (cond) st.says = st.says.replace(/^If .*?( \(\d+ steps? inside\))?$/, (_m, inner) => `If ${st.negate ? "not: " : ""}${plainEnums(sayCondition(cond)).replace(/ is not ""/g, " is not empty").replace(/ is ""/g, " is empty")}${inner || ""}`);
|
|
4406
4423
|
delete st.cond;
|
|
4407
4424
|
delete st.negate;
|
|
@@ -5195,6 +5212,27 @@ function flowOf(steps, { start = "Start", memberIndex = /* @__PURE__ */ new Map(
|
|
|
5195
5212
|
return { nodes, edges, blocks };
|
|
5196
5213
|
}
|
|
5197
5214
|
var idOf = (...parts) => parts.join("#").replace(/\s+/g, "");
|
|
5215
|
+
function youGiveOf(item) {
|
|
5216
|
+
const given = (item.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name) && !p.plumbing).map((p) => words3(p.name));
|
|
5217
|
+
const codes = [];
|
|
5218
|
+
const walk = (steps) => {
|
|
5219
|
+
for (const s of steps || []) {
|
|
5220
|
+
if (s.code) codes.push(s.code);
|
|
5221
|
+
walk(s.children);
|
|
5222
|
+
walk(s.otherwise);
|
|
5223
|
+
}
|
|
5224
|
+
};
|
|
5225
|
+
walk(item.steps);
|
|
5226
|
+
for (const c of codes) {
|
|
5227
|
+
const m = c.match(/^(?:const|let|var)\s*\{([^}]+)\}\s*=\s*\(?\s*(?:await\s+)?(?:req|request|ctx\.request|c\.req|event)\s*\.\s*(?:body|query|params|json\(\))/);
|
|
5228
|
+
if (!m) continue;
|
|
5229
|
+
for (const part of m[1].split(",")) {
|
|
5230
|
+
const name = part.split(/[:=]/)[0].replace(/^\.\.\./, "").trim();
|
|
5231
|
+
if (/^[A-Za-z_$][\w$]*$/.test(name) && !given.includes(words3(name))) given.push(words3(name));
|
|
5232
|
+
}
|
|
5233
|
+
}
|
|
5234
|
+
return given;
|
|
5235
|
+
}
|
|
5198
5236
|
function thunderModel(files, { name = "app" } = {}) {
|
|
5199
5237
|
const things = [], members = [], links = [], unknowns = [], fileInfo = [];
|
|
5200
5238
|
for (const f of files) {
|
|
@@ -5250,7 +5288,7 @@ function thunderModel(files, { name = "app" } = {}) {
|
|
|
5250
5288
|
lines: [item.line, bodyEnd],
|
|
5251
5289
|
...item.doc ? { doc: item.doc } : {},
|
|
5252
5290
|
...item.route ? { route: `${item.route.method} ${item.route.path}`.trim() } : {},
|
|
5253
|
-
youGive: (item
|
|
5291
|
+
youGive: youGiveOf(item),
|
|
5254
5292
|
...item.returns && kind !== "rule" ? { youGetBack: kindWords(item.returns) ?? item.returns } : {},
|
|
5255
5293
|
...rule ? { rule, question: rule.question } : {},
|
|
5256
5294
|
// A yes/no rule is named as a question ("Can borrow?"); a rule with named answers is not ("Late fee").
|
|
@@ -5922,7 +5960,7 @@ def place_order(order, card):
|
|
|
5922
5960
|
slug: "openthunder",
|
|
5923
5961
|
part: "read",
|
|
5924
5962
|
title: "Read a whole app in OpenThunder",
|
|
5925
|
-
idea: "A real app has many files. OpenThunder, the IDE for Thunder, reads a whole repository
|
|
5963
|
+
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
5964
|
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
5965
|
files: [{ language: "python", label: "Python", code: PIZZA_APP }],
|
|
5928
5966
|
focus: "place_order",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skillstech/thunderlang",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
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.
|
|
33
|
+
export const COMPILER_VERSION = '0.5.8';
|
|
34
34
|
export const PROOF_SCHEMA_VERSION = '0.1.0';
|
|
35
35
|
// Identifies which ecosystem product emitted this proof. Consumed by SkillsTech
|
|
36
36
|
// Certified to key cert proofs to the compiler. Stable slug per the coordination bus.
|
package/src/learn-lessons.mjs
CHANGED
|
@@ -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
|
|
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,46 @@ export function ruleFlow(item: unknown, start: string): Flow;
|
|
|
16
16
|
export function askAsQuestion(step: { says: string; code?: string }, ruleLabel?: string): { text: string; flip: boolean };
|
|
17
17
|
export function stepDoes(step: unknown): Does;
|
|
18
18
|
export function modelText(model: ThunderModel, id: string): string;
|
|
19
|
+
/** One answer on the way to a step: the question, and Yes, No, For each, or Otherwise. */
|
|
20
|
+
export interface When { question: string; answer: string }
|
|
21
|
+
export type LevelId = 'big-picture' | 'flow' | 'details' | 'text' | 'original';
|
|
22
|
+
export interface LevelItem { id: string; label: string; symbol: string; route?: string }
|
|
23
|
+
export interface LevelView {
|
|
24
|
+
level: LevelId; name: string; question: string;
|
|
25
|
+
scope: 'app' | 'thing' | 'member'; id: string | null; title: string; symbol: string; file: string | null; lines: [number, number] | null;
|
|
26
|
+
/** Flow and Details without an action or rule: choose one of these. */
|
|
27
|
+
needsFocus?: true; says?: string; choose?: LevelItem[];
|
|
28
|
+
// Big Picture
|
|
29
|
+
purpose?: string; things?: { id: string; label: string; doc?: string; knows: { label: string; start?: string }[]; can: LevelItem[] }[];
|
|
30
|
+
data?: { id: string; label: string; symbol: string; choices?: string[]; knows: string[] }[];
|
|
31
|
+
actions?: LevelItem[]; rules?: LevelItem[]; loose?: LevelItem[]; unknowns?: ThunderModel['unknowns'];
|
|
32
|
+
route?: string; doc?: string; owner?: { id: string; label: string }; youGive?: string[]; youGetBack?: string;
|
|
33
|
+
uses?: { id: string; label: string }[]; usedBy?: { id: string; label: string }[];
|
|
34
|
+
// Flow
|
|
35
|
+
flow?: Flow;
|
|
36
|
+
// Details
|
|
37
|
+
steps?: { id: string; text: string; does: Does; mark: string; line: number | null; depth: number; via?: string; notExplained?: true }[];
|
|
38
|
+
notExplained?: number; tryable?: boolean; rule?: unknown; source?: string;
|
|
39
|
+
/** Details: what goes in, and the lines where each fact is used. */
|
|
40
|
+
inputs?: { label: string; lines: number[] }[];
|
|
41
|
+
/** Details: the data it changes, what it saves or sends, and the answers that lead there. */
|
|
42
|
+
changes?: { text: string; line: number | null; does: Does; when: When[] }[];
|
|
43
|
+
/** Details: every way it can stop, with the error, the message people see, and the answers that lead there. */
|
|
44
|
+
stops?: { error: string; message?: string; line: number | null; when: When[] }[];
|
|
45
|
+
/** Details: what it gives back, and when. */
|
|
46
|
+
givesBack?: { text: string; line: number | null; when: When[] }[];
|
|
47
|
+
/** Details: each action or rule it relies on, summarized. */
|
|
48
|
+
reliesOn?: { id: string; label: string; symbol: string; says: string }[];
|
|
49
|
+
/** Details, for a rule: its answers in words, in order (the last may be "otherwise"). */
|
|
50
|
+
answers?: { answer: string; when: string }[];
|
|
51
|
+
/** Details, for a rule with one whole-number fact: its exact limits, found by running it. from/to null = "or less"/"or more". */
|
|
52
|
+
limits?: { fact: string; ranges: { from: number | null; to: number | null; answer: string }[] };
|
|
53
|
+
/** Details: questions the code can't answer (what a number means, why the rule exists). */
|
|
54
|
+
openQuestions?: string[];
|
|
55
|
+
// Text
|
|
56
|
+
text?: string;
|
|
57
|
+
// Original
|
|
58
|
+
language?: string | null;
|
|
59
|
+
}
|
|
60
|
+
/** What one reading level (LEVELS) shows for the whole model, a Thing, or one action or rule. */
|
|
61
|
+
export function readLevel(model: ThunderModel, level: LevelId, focus?: string): LevelView;
|
package/src/model.mjs
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// them may say more than the model does. Browser-safe: takes [{ path, source }].
|
|
5
5
|
import { readCode } from './read.mjs';
|
|
6
6
|
import { readableLanguage } from './read-repo.mjs';
|
|
7
|
-
import { plainFromReading } from './plain-contract.mjs';
|
|
8
|
-
import { visualFor } from './visual.mjs';
|
|
7
|
+
import { plainFromReading, explainPlain } from './plain-contract.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. */
|
|
@@ -343,6 +343,27 @@ const idOf = (...parts) => parts.join('#').replace(/\s+/g, '');
|
|
|
343
343
|
* Read files into the one Thunder model. Things come from classes in THING_LANGUAGES; every function in every
|
|
344
344
|
* readable language becomes a member with its flow. Unknowns list what could not be read, so no view hides a gap.
|
|
345
345
|
*/
|
|
346
|
+
/**
|
|
347
|
+
* What a person gives an action or function: its inputs, without framework plumbing (self, the request, a database
|
|
348
|
+
* session), plus the facts a handler unpacks from the request: `const { slug, name } = request.body`,
|
|
349
|
+
* `const { id } = req.params`, `{ email } = await request.json()`.
|
|
350
|
+
*/
|
|
351
|
+
function youGiveOf(item) {
|
|
352
|
+
const given = (item.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name) && !p.plumbing).map((p) => words(p.name));
|
|
353
|
+
const codes = [];
|
|
354
|
+
const walk = (steps) => { for (const s of steps || []) { if (s.code) codes.push(s.code); walk(s.children); walk(s.otherwise); } };
|
|
355
|
+
walk(item.steps);
|
|
356
|
+
for (const c of codes) {
|
|
357
|
+
const m = c.match(/^(?:const|let|var)\s*\{([^}]+)\}\s*=\s*\(?\s*(?:await\s+)?(?:req|request|ctx\.request|c\.req|event)\s*\.\s*(?:body|query|params|json\(\))/);
|
|
358
|
+
if (!m) continue;
|
|
359
|
+
for (const part of m[1].split(',')) {
|
|
360
|
+
const name = part.split(/[:=]/)[0].replace(/^\.\.\./, '').trim();
|
|
361
|
+
if (/^[A-Za-z_$][\w$]*$/.test(name) && !given.includes(words(name))) given.push(words(name));
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return given;
|
|
365
|
+
}
|
|
366
|
+
|
|
346
367
|
export function thunderModel(files, { name = 'app' } = {}) {
|
|
347
368
|
const things = [], members = [], links = [], unknowns = [], fileInfo = [];
|
|
348
369
|
for (const f of files) {
|
|
@@ -374,7 +395,7 @@ export function thunderModel(files, { name = 'app' } = {}) {
|
|
|
374
395
|
label: setup ? `A new ${owner.label} starts with` : cap(words(item.name.replace(/^__|__$/g, ''))),
|
|
375
396
|
...(owner ? { owner: owner.id } : {}), file: f.path, language, lines: [item.line, bodyEnd],
|
|
376
397
|
...(item.doc ? { doc: item.doc } : {}), ...(item.route ? { route: `${item.route.method} ${item.route.path}`.trim() } : {}),
|
|
377
|
-
youGive: (item
|
|
398
|
+
youGive: youGiveOf(item),
|
|
378
399
|
...(item.returns && kind !== 'rule' ? { youGetBack: kindWords(item.returns) ?? item.returns } : {}),
|
|
379
400
|
...(rule ? { rule, question: rule.question } : {}),
|
|
380
401
|
// A yes/no rule is named as a question ("Can borrow?"); a rule with named answers is not ("Late fee").
|
|
@@ -454,3 +475,174 @@ export function modelText(model, id) {
|
|
|
454
475
|
lines.push(...flowLines(m.flow));
|
|
455
476
|
return `${lines.join('\n')}\n`;
|
|
456
477
|
}
|
|
478
|
+
|
|
479
|
+
// ── The five reading levels: what each one shows, decided here so every product shows the same thing ─────────
|
|
480
|
+
|
|
481
|
+
const SYMBOL_OF = { action: 'action', rule: 'rule', steps: 'steps', setup: 'setup', 'not-read': 'not-read', thing: 'thing', record: 'record', choices: 'choices' };
|
|
482
|
+
|
|
483
|
+
/** Every step of a flow in reading order, with how deep it sits and which path it is on (Yes, No, For each, …). */
|
|
484
|
+
function detailSteps(flow) {
|
|
485
|
+
const byId = new Map(flow.nodes.map((n) => [n.id, n]));
|
|
486
|
+
const out = [];
|
|
487
|
+
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 } : {}) });
|
|
488
|
+
// `via` (Yes, No, For each) labels only the first step of each path, the way Thunder Text writes "Yes:" once.
|
|
489
|
+
const walk = (blocks, depth, via) => {
|
|
490
|
+
for (const b of blocks || []) {
|
|
491
|
+
const n = byId.get(b.id);
|
|
492
|
+
if (n && n.kind !== 'start') { push(n, depth, via); via = null; }
|
|
493
|
+
walk(b.yes, depth + 1, 'Yes');
|
|
494
|
+
walk(b.no, depth + 1, 'No');
|
|
495
|
+
walk(b.each, depth + 1, 'For each');
|
|
496
|
+
walk(b.body, depth + 1, null);
|
|
497
|
+
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); }
|
|
498
|
+
if (b.always) { const an = byId.get(b.always.id); if (an) push(an, depth, null); walk(b.always.blocks, depth + 1, null); }
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
walk(flow.blocks, 0, null);
|
|
502
|
+
return out;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
// ── Details: what you need to check before you trust or change an action or rule ─────────────────────────
|
|
507
|
+
|
|
508
|
+
const CHANGES = /^(Sets|Adds|Removes|Subtracts|Clears|Marks|Saves|Deletes|Updates|Appends|Increases|Decreases|Sends|Records|Stores|Writes)\b/;
|
|
509
|
+
|
|
510
|
+
/** Each step with the answers that lead to it: [{ question, answer }] from the top of the flow. */
|
|
511
|
+
function pathsOf(flow) {
|
|
512
|
+
const byId = new Map(flow.nodes.map((n) => [n.id, n]));
|
|
513
|
+
const out = [];
|
|
514
|
+
const walk = (blocks, when) => {
|
|
515
|
+
for (const b of blocks || []) {
|
|
516
|
+
const n = byId.get(b.id);
|
|
517
|
+
if (n && n.kind !== 'start') out.push({ node: n, when });
|
|
518
|
+
const q = n?.text ?? '';
|
|
519
|
+
walk(b.yes, [...when, { question: q, answer: 'Yes' }]);
|
|
520
|
+
walk(b.no, [...when, { question: q, answer: 'No' }]);
|
|
521
|
+
walk(b.each, [...when, { question: q, answer: 'For each' }]);
|
|
522
|
+
walk(b.body, when);
|
|
523
|
+
for (const h of b.handlers || []) { const hn = byId.get(h.id); walk(h.blocks, [...when, { question: (hn?.text ?? '').replace(/\?$/, ''), answer: 'Yes' }]); }
|
|
524
|
+
if (b.always) walk(b.always.blocks, when);
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
walk(flow.blocks, []);
|
|
528
|
+
return out;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** A rule's answers in words: [{ answer, when }] in order, then the otherwise answer. */
|
|
532
|
+
function ruleAnswers(rule) {
|
|
533
|
+
const zero = Object.fromEntries(rule.inputs.map((i) => [i.id, i.kind === 'yesno' ? true : 0]));
|
|
534
|
+
let explained;
|
|
535
|
+
try { explained = explainPlain(rule, zero); } catch { return null; }
|
|
536
|
+
const answers = explained.rules.map((r) => ({ answer: answerWords(r.outcome), when: r.checks.map((c) => c.text).join(r.join === 'any' ? ' or ' : ' and ') }));
|
|
537
|
+
if (rule.otherwise) answers.push({ answer: answerWords(rule.otherwise), when: 'otherwise' });
|
|
538
|
+
return answers;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* The exact limits of a rule with one number fact, found by running it on every whole number around each limit:
|
|
543
|
+
* [{ from, to, answer }] where from/to are null for "or less" / "or more". Only when every limit is a whole number,
|
|
544
|
+
* so the ranges are exact rather than approximate.
|
|
545
|
+
*/
|
|
546
|
+
function ruleRanges(rule) {
|
|
547
|
+
if (rule.inputs.length !== 1 || rule.inputs[0].kind === 'yesno') return null;
|
|
548
|
+
const id = rule.inputs[0].id;
|
|
549
|
+
const limits = rule.rules.flatMap((r) => r.conditions).filter((c) => c.input === id && typeof c.value === 'number').map((c) => c.value);
|
|
550
|
+
if (!limits.length || !limits.every(Number.isInteger)) return null;
|
|
551
|
+
const lo = Math.min(...limits) - 1, hi = Math.max(...limits) + 1;
|
|
552
|
+
const ranges = [];
|
|
553
|
+
for (let v = lo; v <= hi; v++) {
|
|
554
|
+
let outcome;
|
|
555
|
+
try { outcome = answerWords(explainPlain(rule, { [id]: v }).outcome); } catch { return null; }
|
|
556
|
+
const last = ranges.at(-1);
|
|
557
|
+
if (last && last.answer === outcome) last.to = v; else ranges.push({ from: v, to: v, answer: outcome });
|
|
558
|
+
}
|
|
559
|
+
ranges[0].from = null;
|
|
560
|
+
ranges.at(-1).to = null;
|
|
561
|
+
return { fact: rule.inputs[0].label.replace(/^the /, ''), ranges };
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function detailsFacts(model, member) {
|
|
565
|
+
const paths = pathsOf(member.flow);
|
|
566
|
+
const memberOf = (id) => model.members.find((m) => m.id === id);
|
|
567
|
+
const inputs = member.youGive.map((label) => {
|
|
568
|
+
const re = new RegExp(`\\b${label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'i');
|
|
569
|
+
const lines = [...new Set(paths.filter((p) => re.test(p.node.text) && p.node.line).map((p) => p.node.line))];
|
|
570
|
+
return { label, lines };
|
|
571
|
+
});
|
|
572
|
+
const changes = paths.filter((p) => p.node.kind !== 'decision' && p.node.kind !== 'stop' && p.node.kind !== 'end' && (p.node.does === 'save' || p.node.does === 'send' || (CHANGES.test(p.node.text) && /'s\b|\bto\b|\bfrom\b/.test(p.node.text))))
|
|
573
|
+
.map((p) => ({ text: p.node.text, line: p.node.line ?? null, does: p.node.does, when: p.when }));
|
|
574
|
+
const stops = paths.filter((p) => p.node.kind === 'stop').map((p) => {
|
|
575
|
+
const m = p.node.text.match(/^Stop:\s*([^:]+?)(?::\s*"(.*)")?$/);
|
|
576
|
+
return { error: m ? m[1].trim() : p.node.text, ...(m?.[2] ? { message: m[2] } : {}), line: p.node.line ?? null, when: p.when };
|
|
577
|
+
});
|
|
578
|
+
const givesBack = paths.filter((p) => p.node.kind === 'end' || p.node.answer).map((p) => ({ text: p.node.answer ? answerWords(p.node.text) : p.node.text, line: p.node.line ?? null, when: p.node.otherwise ? [{ question: 'none of the above', answer: 'Otherwise' }] : p.when }));
|
|
579
|
+
const reliesOn = model.links.filter((l) => l.from === member.id).map((l) => memberOf(l.to)).filter(Boolean).map((t) => {
|
|
580
|
+
const answers = t.rule ? ruleAnswers(t.rule) : null;
|
|
581
|
+
const flowAnswers = [...new Set(t.flow.nodes.filter((n) => n.answer).map((n) => n.text))];
|
|
582
|
+
const list = answers ? answers.map((a) => a.answer) : flowAnswers;
|
|
583
|
+
const says = list.length ? `Answers ${list.join(', ').replace(/, ([^,]*)$/, list.length > 2 ? ', or $1' : ' or $1')}.`
|
|
584
|
+
: t.youGetBack ? `Gives back ${t.youGetBack}.` : t.flow.nodes.some((n) => n.kind === 'stop') ? `Can stop with ${t.flow.nodes.filter((n) => n.kind === 'stop').map((n) => n.text.replace(/^Stop:\s*/, '').split(':')[0]).join(', ')}.` : `${t.flow.nodes.filter((n) => n.kind !== 'start').length} steps.`;
|
|
585
|
+
return { id: t.id, label: t.label + (t.yesNo ? '?' : ''), symbol: SYMBOL_OF[t.kind], says };
|
|
586
|
+
});
|
|
587
|
+
const answers = member.rule ? ruleAnswers(member.rule) : null;
|
|
588
|
+
const limits = member.rule ? ruleRanges(member.rule) : null;
|
|
589
|
+
const openQuestions = (member.rule?.needsReview ?? []).filter((q) => !/^No examples yet/.test(q));
|
|
590
|
+
return { inputs, changes, stops, givesBack, reliesOn, ...(answers ? { answers } : {}), ...(limits ? { limits } : {}), openQuestions };
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* What one reading level shows: `level` is a LEVELS id (big-picture, flow, details, text, original); `focus` is a
|
|
595
|
+
* Thing or member id, or nothing for the whole model. Flow and Details need an action or rule; without one they
|
|
596
|
+
* give back `needsFocus` and the list to choose from. Deterministic; built only from the model.
|
|
597
|
+
*/
|
|
598
|
+
export function readLevel(model, level, focus) {
|
|
599
|
+
const lv = LEVELS.find((l) => l.id === level);
|
|
600
|
+
if (!lv) throw new Error(`Unknown reading level "${level}". Use one of: ${LEVELS.map((l) => l.id).join(', ')}.`);
|
|
601
|
+
const member = focus ? model.members.find((m) => m.id === focus) : undefined;
|
|
602
|
+
const thing = focus && !member ? model.things.find((t) => t.id === focus) : undefined;
|
|
603
|
+
if (focus && !member && !thing) throw new Error(`Nothing in this model has the id "${focus}".`);
|
|
604
|
+
const owner = member?.owner ? model.things.find((t) => t.id === member.owner) : undefined;
|
|
605
|
+
const labelOf = (id) => model.members.find((m) => m.id === id)?.label ?? id;
|
|
606
|
+
const short = (m) => ({ id: m.id, label: m.label + (m.yesNo ? '?' : ''), symbol: SYMBOL_OF[m.kind], ...(m.route ? { route: m.route } : {}) });
|
|
607
|
+
const base = { level: lv.id, name: lv.name, question: lv.question };
|
|
608
|
+
const about = member
|
|
609
|
+
? { scope: 'member', id: member.id, title: member.label + (member.yesNo ? '?' : ''), symbol: SYMBOL_OF[member.kind], file: member.file, lines: member.lines }
|
|
610
|
+
: thing ? { scope: 'thing', id: thing.id, title: thing.label, symbol: SYMBOL_OF[thing.kind], file: thing.file, lines: thing.lines }
|
|
611
|
+
: { scope: 'app', id: null, title: model.name, symbol: 'app', file: model.files[0]?.path ?? null, lines: null };
|
|
612
|
+
const uses = member ? model.links.filter((l) => l.from === member.id).map((l) => ({ id: l.to, label: labelOf(l.to) })) : [];
|
|
613
|
+
const usedBy = member ? model.links.filter((l) => l.to === member.id).map((l) => ({ id: l.from, label: labelOf(l.from) })) : [];
|
|
614
|
+
|
|
615
|
+
if (!member && (lv.id === 'flow' || lv.id === 'details')) {
|
|
616
|
+
const inScope = model.members.filter((m) => m.kind !== 'setup' && (!thing || m.owner === thing.id));
|
|
617
|
+
return { ...base, ...about, needsFocus: true, says: `${lv.name} shows one action or rule. Choose one.`, choose: inScope.map(short) };
|
|
618
|
+
}
|
|
619
|
+
if (lv.id === 'big-picture') {
|
|
620
|
+
if (member) {
|
|
621
|
+
return { ...base, ...about, ...(member.route ? { route: member.route } : {}), ...(member.doc ? { doc: member.doc } : {}),
|
|
622
|
+
...(owner ? { owner: { id: owner.id, label: owner.label } } : {}), youGive: member.youGive, ...(member.youGetBack ? { youGetBack: member.youGetBack } : {}), uses, usedBy };
|
|
623
|
+
}
|
|
624
|
+
const inScope = (m) => m.kind !== 'setup' && (thing ? m.owner === thing.id : true);
|
|
625
|
+
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) });
|
|
626
|
+
return { ...base, ...about,
|
|
627
|
+
...(thing?.doc ?? model.files[0]?.purpose ? { purpose: thing?.doc ?? model.files[0]?.purpose } : {}),
|
|
628
|
+
things: (thing ? [thing] : model.things.filter((t) => t.kind === 'thing')).map(thingCard),
|
|
629
|
+
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) })),
|
|
630
|
+
actions: model.members.filter((m) => inScope(m) && m.kind === 'action').map(short),
|
|
631
|
+
rules: model.members.filter((m) => inScope(m) && m.kind === 'rule').map(short),
|
|
632
|
+
loose: thing ? [] : model.members.filter((m) => !m.owner && m.kind !== 'setup' && m.kind !== 'action' && m.kind !== 'rule').map(short),
|
|
633
|
+
unknowns: thing ? [] : model.unknowns };
|
|
634
|
+
}
|
|
635
|
+
if (lv.id === 'flow') return { ...base, ...about, flow: member.flow };
|
|
636
|
+
if (lv.id === 'details') {
|
|
637
|
+
const steps = detailSteps(member.flow);
|
|
638
|
+
return { ...base, ...about, youGive: member.youGive, ...(member.youGetBack ? { youGetBack: member.youGetBack } : {}), ...(member.doc ? { doc: member.doc } : {}),
|
|
639
|
+
...detailsFacts(model, member), steps,
|
|
640
|
+
notExplained: steps.filter((s) => s.notExplained).length, uses, usedBy, tryable: !!member.rule, ...(member.rule ? { rule: member.rule } : {}),
|
|
641
|
+
source: 'Read from code by the Thunder compiler, with no AI.' };
|
|
642
|
+
}
|
|
643
|
+
if (lv.id === 'text') {
|
|
644
|
+
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');
|
|
645
|
+
return { ...base, ...about, text };
|
|
646
|
+
}
|
|
647
|
+
return { ...base, ...about, language: (member ?? thing) ? (member?.language ?? model.files.find((f) => f.path === thing.file)?.language ?? null) : (model.files[0]?.language ?? null) };
|
|
648
|
+
}
|
package/src/read.mjs
CHANGED
|
@@ -1773,7 +1773,9 @@ function functionSteps(fn, lang, code, names, srcLines = []) {
|
|
|
1773
1773
|
if (st.kind !== 'branch' || !st.cond) continue;
|
|
1774
1774
|
// A bare yes/no property (`order.refunded`) already reads as a sentence from the step itself; keep it.
|
|
1775
1775
|
const bareProperty = /^(not\s+|!)?(?:self\.|this\.)?\w+\.\w+(\(\))?$/.test(st.cond.trim()) && !/\./.test(st.says.replace(/\(\d+ steps? inside\)$/, ''));
|
|
1776
|
-
|
|
1776
|
+
// A plain name used as a yes/no (`if (!slug)`) already reads as "slug is not set"; keep it rather than "not slug".
|
|
1777
|
+
const bareName = /^(not\s+|!)?(?:self\.|this\.)?\w+$/.test(st.cond.trim()) && /\bis (not )?set\b/.test(st.says);
|
|
1778
|
+
const cond = bareProperty || bareName ? null : toThunderCondition(st.cond, names);
|
|
1777
1779
|
if (cond) st.says = st.says.replace(/^If .*?( \(\d+ steps? inside\))?$/, (_m, inner) => `If ${st.negate ? 'not: ' : ''}${plainEnums(sayCondition(cond)).replace(/ is not ""/g, ' is not empty').replace(/ is ""/g, ' is empty')}${inner || ''}`);
|
|
1778
1780
|
delete st.cond; delete st.negate;
|
|
1779
1781
|
}
|
package/src/steps.mjs
CHANGED
|
@@ -223,6 +223,25 @@ function sayChain(value) {
|
|
|
223
223
|
return hit ? hit.c.say(words(src.split('.').pop().replace(/^#/, ''))) : null;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
const HTTP_STATUS = { 400: 'Bad Request', 401: 'Unauthorized', 402: 'Payment Required', 403: 'Forbidden', 404: 'Not Found', 405: 'Method Not Allowed', 409: 'Conflict', 410: 'Gone', 413: 'Payload Too Large', 415: 'Unsupported Media Type', 422: 'Unprocessable Content', 429: 'Too Many Requests', 500: 'Internal Server Error', 501: 'Not Implemented', 502: 'Bad Gateway', 503: 'Service Unavailable', 504: 'Gateway Timeout' };
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* An HTTP error response, returned or sent: Fastify `reply.code(400).send(...)`, Express `res.status(404).json(...)`,
|
|
230
|
+
* `new Response(..., { status: 403 })`, FastAPI `JSONResponse(..., status_code=422)`, Flask `return jsonify(...), 400`.
|
|
231
|
+
* Gives a fail step: { kind: 'fail', says, error: '400 Bad Request', message, status } or null.
|
|
232
|
+
*/
|
|
233
|
+
function httpErrorOf(head) {
|
|
234
|
+
const expr = head.replace(/^return\s+/, '').replace(/^await\s+/, '').replace(/;\s*$/, '').trim();
|
|
235
|
+
let m = expr.match(/^(?:reply|res|response|resp|ctx\.response)\s*\.\s*(?:code|status|statusCode)\s*\(\s*([45]\d\d)\s*\)/)
|
|
236
|
+
|| expr.match(/^(?:new\s+)?(?:Response|NextResponse(?:\.json)?|HttpResponse|JSONResponse|PlainTextResponse|Response\.json)\s*\(.*\bstatus(?:_code)?\s*[:=]\s*([45]\d\d)\b/)
|
|
237
|
+
|| (/^return\b/.test(head) ? expr.match(/^.+,\s*([45]\d\d)\s*$/) : null);
|
|
238
|
+
if (!m) return null;
|
|
239
|
+
const status = Number(m[1]);
|
|
240
|
+
const name = HTTP_STATUS[status] ?? (status >= 500 ? 'Server Error' : 'Client Error');
|
|
241
|
+
const msg = (expr.match(/\b(?:error|message|detail|msg)\s*[:=]\s*["'`]([^"'`]{1,80})["'`]/) || expr.match(/\.(?:send|json|end)\(\s*["'`]([^"'`]{1,80})["'`]/) || [])[1];
|
|
242
|
+
return { kind: 'fail', says: `Fails with ${status} ${name}${msg ? `: "${msg}"` : ''}`, error: `${status} ${name}`, ...(msg ? { message: msg } : {}), status };
|
|
243
|
+
}
|
|
244
|
+
|
|
226
245
|
export function classifyStatement(raw, { inner = 0 } = {}) {
|
|
227
246
|
const text = String(raw).trim();
|
|
228
247
|
// TypeScript-only syntax that changes nothing for a reader: casts, non-null assertions, optional calls.
|
|
@@ -256,6 +275,9 @@ export function classifyStatement(raw, { inner = 0 } = {}) {
|
|
|
256
275
|
const said = name && /^[a-z]/.test(name) ? `the error made by ${words(name)}` : name;
|
|
257
276
|
return { kind: 'fail', says: `Fails${said ? ` with ${said}` : ''}${msg ? `: "${msg}"` : ''}`, code, ...(name ? { error: name } : {}), ...(msg ? { message: msg } : {}) };
|
|
258
277
|
}
|
|
278
|
+
// An HTTP error response (4xx/5xx) is a Stop: the request is refused, with a status and a message.
|
|
279
|
+
const httpFail = httpErrorOf(head);
|
|
280
|
+
if (httpFail) return { ...httpFail, code };
|
|
259
281
|
// Returns (Go/Rust error returns read as failures)
|
|
260
282
|
if ((m = head.match(/^return\b\s*(.*)$/))) {
|
|
261
283
|
const expr = stripTail(m[1]);
|
|
@@ -479,7 +501,10 @@ export function stepsFrom(statements) {
|
|
|
479
501
|
if (/^(?:"""|'''|r"""|\/\*\*|\*)/.test(t0)) { skipped.push(spanOf(s)); continue; } // docstrings and doc comments
|
|
480
502
|
if (/^[)\]}]+[):;,]*$/.test(t0) || /^\.\.\.$/.test(t0) || /^\.[A-Za-z_]/.test(t0) || /^@\w+(?:\(.*\))?$/.test(t0) || /^#?\[[\w:]+(?:\(.*\))?\]$/.test(t0) || /^:(?:param|rtype|return|raises|type)\b/.test(t0)) { skipped.push(spanOf(s)); continue; }
|
|
481
503
|
const step = { ...classifyStatement(s.text, { inner: s.inner || 0 }), line: s.line, span: spanOf(s) };
|
|
482
|
-
if (
|
|
504
|
+
// A one-line `if (x) return reply.code(400).send({ error: 'bad' })` is one statement: its braces belong to the
|
|
505
|
+
// object being sent, not to a block, so read the statement after the condition instead of the braces' inside.
|
|
506
|
+
if (step.inline && !/^\{/.test(step.inline.trim())) { const kid = classifyStatement(step.inline); step.children = [{ ...kid, line: s.line, span: spanOf(s) }]; delete step.inline; }
|
|
507
|
+
else if (s.children?.length && ['branch', 'loop', 'try'].includes(step.kind)) {
|
|
483
508
|
const kids = stepsFrom(s.children).steps;
|
|
484
509
|
if (kids.length) { step.children = kids; step.says = step.says.replace(/ \(\d+ steps? inside\)$/, ''); }
|
|
485
510
|
}
|
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
|
-
*
|
|
24
|
-
*
|
|
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: 'A fact sheet: every way it can end (each Stop with its message, and what it gives back), the answers that lead there, what it changes, what goes in, what it relies on, a rule\'s answers and exact limits, and what the code cannot tell you.', form: 'picture' },
|
|
32
|
+
{ 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
|
|
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
|
|