@skillstech/thunderlang 0.5.5 → 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 +30 -0
- package/README.md +3 -0
- package/dist/core.cjs +120 -7
- package/dist/index.cjs +9 -2
- package/dist/learn.cjs +6066 -0
- package/package.json +10 -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 +458 -0
- package/src/learn.d.mts +34 -0
- package/src/learn.mjs +77 -0
- package/src/model.d.mts +25 -0
- package/src/model.mjs +83 -1
- package/src/visual.d.mts +5 -1
- package/src/visual.mjs +20 -3
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
|
-
*
|
|
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: '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
|
|
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
|
|