@skillstech/thunderlang 1.3.0 → 1.4.1

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.
@@ -0,0 +1,46 @@
1
+ // Types for the Thunder Software Passport (passport.mjs, passport-fs.mjs). Spec: docs/passport.md.
2
+ export const PASSPORT_SCHEMA: 'thunder-passport-v1';
3
+ export const ALWAYS_NOT_VERIFIED: string[];
4
+ export interface PassportInput { part: string; file: string; sha256: string | null }
5
+ export interface PassportEvidence {
6
+ id: string;
7
+ kind: 'test-run' | 'trace-link' | 'review' | 'accuracy-gate' | 'conformance' | 'access-flow' | string;
8
+ /** passed / failed: a command ran; read: read from code, nothing was run. */
9
+ status: 'passed' | 'failed' | 'read';
10
+ claim: string;
11
+ basis: { command?: string; cwd?: string; exitCode?: number; outputDigest?: string; outputTail?: string; from?: string; to?: string; base?: string; head?: string; [k: string]: unknown };
12
+ /** What this evidence does not cover. */
13
+ scope: string;
14
+ /** The files it depended on, by content hash; when one changes, the item is stale. */
15
+ inputs: PassportInput[];
16
+ }
17
+ export interface Passport {
18
+ schema: 'thunder-passport-v1';
19
+ subject: { kind: 'change' | 'feature'; parts: Array<{ name: string; path: string; sha: string | null; dirty: boolean }> };
20
+ purpose: { stated: boolean; text: string; source: string | null };
21
+ behavior: Array<{ part: string; file: string; lines: [number, number]; name: string; kind: string; change?: 'added' | 'changed' | 'removed'; text: string }>;
22
+ dependencies: { files: PassportInput[]; links: Array<{ kind: string; says: string; from: string; to: string }>; packages: Array<{ name: string; version?: string; from: string; dev?: boolean }>; services: Array<{ part: string; calls: string; at: string }> };
23
+ effects: Array<{ part: string; file: string; line: number; in: string; kind: 'reads' | 'writes' | 'sends' | 'deletes' | 'calls another part' | 'sends the person to'; says: string; how: 'detected' | 'observed' | 'declared'; basis: string }>;
24
+ evidence: PassportEvidence[];
25
+ unknowns: { notRead: Array<{ part: string; file: string; line: number; what: string }>; notLinked: Array<{ kind: string; call: string; at: string; why: string }>; untested: Array<{ part: string; what: string }>; notShown?: string; notVerified: string[] };
26
+ history: { base: string | null; head: string | null; changedFiles: Array<{ part: string; file: string; status: string }>; thunder: string | null; builtAt: string };
27
+ summary: { claims: number; passed: number; failed: number; readFromCode: number; unknowns: number; notVerified: number };
28
+ fingerprint: string;
29
+ }
30
+ export interface PassportCheck {
31
+ schema: 'thunder-passport-check-v1'; current: number; stale: number;
32
+ items: Array<{ id: string; kind: string; claim: string; freshness: 'current' | 'stale' | 'unknown'; changed: Array<{ part: string; file: string; now: 'changed' | 'missing' }> }>;
33
+ changedFiles: Array<{ part: string; file: string; now: 'changed' | 'missing' }>;
34
+ }
35
+ export function assemblePassport(input: {
36
+ parts: Array<{ name: string; path?: string; sha?: string | null; dirty?: boolean; files: Array<{ path: string; source: string }>; packages?: Passport['dependencies']['packages']; changes?: Array<{ file: string; status: 'added' | 'changed' | 'removed'; ranges: Array<[number, number]>; old?: string | null }> }>;
37
+ change?: { base: string; head: string | null } | null;
38
+ runs?: Array<{ command: string; part: string | null; cwd: string; exitCode: number; output: string }>;
39
+ purpose?: { text: string; source?: string } | null;
40
+ extra?: Array<Omit<PassportEvidence, 'id'>>;
41
+ builtAt?: string; thunder?: string | null;
42
+ }): Passport;
43
+ export function summarize(passport: Omit<Passport, 'summary' | 'fingerprint'>): Passport['summary'];
44
+ export function checkPassport(passport: Passport, options: { read: (part: string, file: string) => string | null }): PassportCheck;
45
+ export function renderPassportSummary(passport: Passport): string;
46
+ export function renderPassportMarkdown(passport: Passport): string;
@@ -0,0 +1,255 @@
1
+ // Thunder Software Passport (thunder-passport-v1): a portable evidence record for a feature or a change.
2
+ //
3
+ // It is not a certificate that the code is correct. It is an evidence manifest: every claim names its basis (a
4
+ // command and its exit code, or a source location), what it does not cover, and the exact files (by content hash)
5
+ // it depended on. When one of those files changes, the claim is stale, and checkPassport says so.
6
+ //
7
+ // This file is the pure, browser-safe half: it assembles a passport from what was read and run, renders it, and
8
+ // checks it against current file contents. Reading folders, git, and running commands is in passport-fs.mjs.
9
+ import { sha256 } from './hash.mjs';
10
+ import { thunderModel, modelText } from './model.mjs';
11
+ import { buildTrace, isTestFile } from './trace.mjs';
12
+ import { thunderReview } from './review.mjs';
13
+
14
+ export const PASSPORT_SCHEMA = 'thunder-passport-v1';
15
+
16
+ /** What nothing in a passport establishes unless an evidence item says otherwise. Always listed. */
17
+ export const ALWAYS_NOT_VERIFIED = [
18
+ 'Deployment: how it is configured and run in a real environment.',
19
+ 'External services: real providers, their answers, and their outages (tests use what the code was given).',
20
+ 'More than one process or machine: anything kept in memory is not shared between copies.',
21
+ 'Load and timing: behavior under many requests at once, beyond what the tests ran.',
22
+ ];
23
+
24
+ const MAX_BEHAVIOR = 60;
25
+ const fileHash = (source) => sha256(String(source)); // 'sha256:<hex>'
26
+
27
+ const EFFECT = { find: 'reads', save: 'writes', send: 'sends', ask: 'calls another part', redirect: 'sends the person to' };
28
+ function effectKind(node) {
29
+ if (node.does === 'save' && /^(Deletes|Removes)\b/.test(node.text || '')) return 'deletes';
30
+ return EFFECT[node.does] ?? null;
31
+ }
32
+
33
+ /**
34
+ * Assemble a passport from parts already read (and, for a change, their base versions), runs already made, and a
35
+ * purpose. Pure and deterministic: the same inputs (with the same `builtAt`) give the same passport.
36
+ * parts: [{ name, path, sha?, dirty?, files: [{ path, source, manifest? }], packages?: [{ name, version?, from }],
37
+ * changes?: [{ file, status: 'added'|'changed'|'removed', ranges: [[a, b]…], old?: string|null }] }]
38
+ * change: { base, head } when this is a change (each part's `changes` then say what changed); null for a snapshot
39
+ * runs: [{ command, part: name|null, cwd, exitCode, output }] (output: what it printed, both streams)
40
+ * purpose: { text, source } or null
41
+ * extra: evidence items supplied by other tools (an access-flow result, a conformance run…), already in shape
42
+ */
43
+ export function assemblePassport({ parts, change = null, runs = [], purpose = null, extra = [], builtAt = new Date().toISOString(), thunder = null }) {
44
+ const hashes = new Map(); // `${part}/${file}` -> { part, file, sha256 }
45
+ for (const p of parts) for (const f of p.files) hashes.set(`${p.name}/${f.path}`, { part: p.name, file: f.path, sha256: fileHash(f.source) });
46
+ const inputOf = (part, file) => hashes.get(`${part}/${file}`) ?? { part, file, sha256: null };
47
+ const partInputs = (name) => [...hashes.values()].filter((h) => h.part === name);
48
+
49
+ const models = new Map(parts.map((p) => [p.name, thunderModel(p.files.filter((f) => !f.manifest), { name: p.name })]));
50
+ const changed = (p, file) => (p.changes ?? []).find((c) => c.file === file);
51
+
52
+ // Behavior: in a change, the actions and rules whose lines the change touched (or in an added file); in a
53
+ // snapshot, every action and rule. Test code is evidence, not behavior.
54
+ const behavior = [], effects = [], notRead = [];
55
+ for (const p of parts) {
56
+ const model = models.get(p.name);
57
+ for (const m of model.members) {
58
+ if (m.kind === 'setup' || isTestFile(m.file)) continue;
59
+ const c = change ? changed(p, m.file) : null;
60
+ if (change && !(c && (c.status === 'added' || c.ranges.some(([a, b]) => a <= m.lines[1] && b >= m.lines[0])))) continue;
61
+ const item = { part: p.name, file: m.file, lines: m.lines, name: m.label, kind: m.kind, ...(c ? { change: c.status } : {}) };
62
+ if (m.kind === 'not-read') { notRead.push({ part: p.name, file: m.file, line: m.lines[0], what: `${m.label}: Thunder does not read this yet` }); continue; }
63
+ let text = '';
64
+ try { text = modelText(model, m.id).trim(); } catch { text = ''; }
65
+ behavior.push({ ...item, text });
66
+ for (const nd of m.flow?.nodes ?? []) {
67
+ const kind = effectKind(nd);
68
+ if (kind) effects.push({ part: p.name, file: m.file, line: nd.line ?? m.lines[0], in: m.label, kind, says: nd.text, how: 'detected', basis: 'read from code; nothing was run' });
69
+ if (nd.does === 'code' && nd.line != null) notRead.push({ part: p.name, file: m.file, line: nd.line, what: `shown as code: ${String(nd.text).slice(0, 100)}` });
70
+ }
71
+ }
72
+ for (const u of model.unknowns ?? []) {
73
+ if (isTestFile(u.file)) continue;
74
+ const c = change ? changed(p, u.file) : null;
75
+ if (change && !(c && (c.status === 'added' || c.ranges.some(([a, b]) => u.line >= a && u.line <= b)))) continue;
76
+ const owner = model.members.find((m) => m.file === u.file && m.lines[0] <= u.line && m.lines[1] >= u.line);
77
+ notRead.push({ part: p.name, file: u.file, line: u.line, what: owner ? `${owner.label}: ${u.why}` : u.why });
78
+ }
79
+ }
80
+ const order = (a, b) => `${a.part}/${a.file}`.localeCompare(`${b.part}/${b.file}`) || ((a.lines?.[0] ?? a.line ?? 0) - (b.lines?.[0] ?? b.line ?? 0));
81
+ behavior.sort(order); effects.sort(order); notRead.sort(order);
82
+ { const seen = new Set(); notRead.splice(0, notRead.length, ...notRead.filter((x) => { const k = `${x.part}/${x.file}:${x.line}`; if (seen.has(k)) return false; seen.add(k); return true; })); }
83
+ const shownBehavior = behavior.slice(0, MAX_BEHAVIOR);
84
+
85
+ // Dependencies: every file read (with its hash), the links between the parts, packages, and services called.
86
+ const trace = buildTrace(parts.map((p) => ({ name: p.name, sha: p.sha ?? null, dirty: !!p.dirty, files: p.files.filter((f) => !f.manifest) })));
87
+ const links = trace.links.map((l) => ({ kind: l.kind, says: l.kind === 'http' ? `${l.from.repo} calls ${l.to.repo}: ${l.method} ${l.path} (handled by ${l.to.label ?? l.route})` : `${l.from.repo} publishes ${l.event}, and ${l.to.repo} listens`, from: l.from.cite, to: l.to.cite }));
88
+ const services = [];
89
+ for (const r of trace.repos) for (const q of r.requests ?? []) if (q.base && q.base !== 'this app') services.push({ part: r.name, calls: `${q.method} ${q.base}${q.path}`, at: `${r.name}:${q.file}:${q.line}` });
90
+
91
+ // Evidence.
92
+ const evidence = [];
93
+ const add = (x) => evidence.push({ id: `e${evidence.length + 1}`, ...x });
94
+ for (const r of runs) {
95
+ const passed = r.exitCode === 0;
96
+ const tail = String(r.output ?? '').replace(/\s+$/, '').split('\n').slice(-12).join('\n');
97
+ add({
98
+ kind: 'test-run', status: passed ? 'passed' : 'failed',
99
+ claim: `\`${r.command}\`${r.part ? ` in ${r.part}` : ''} exited with ${r.exitCode}${passed ? '' : ' (a failure)'}.`,
100
+ basis: { command: r.command, cwd: r.cwd, exitCode: r.exitCode, outputDigest: fileHash(r.output ?? ''), outputTail: tail },
101
+ scope: 'Only what these tests exercise. Thunder did not measure which lines or paths they cover.',
102
+ inputs: r.part ? partInputs(r.part) : [...hashes.values()],
103
+ });
104
+ }
105
+ for (const l of trace.links) {
106
+ add({
107
+ kind: 'trace-link', status: 'read',
108
+ claim: l.kind === 'http' ? `${l.from.repo} calls ${l.to.repo} with ${l.method} ${l.path}, and ${l.to.repo} handles it.` : `${l.from.repo} publishes "${l.event}", and ${l.to.repo} listens for it.`,
109
+ basis: { from: l.from.cite, to: l.to.cite, rules: `thunder-trace rules v${trace.rulesVersion}` },
110
+ scope: 'Read from code; nothing was run. It does not show that the call succeeds or what it answers.',
111
+ inputs: [inputOf(l.from.repo, l.from.file), inputOf(l.to.repo, l.to.file)],
112
+ });
113
+ }
114
+ let review = null;
115
+ if (change) {
116
+ const oldFiles = [], newFiles = [], changedInputs = [];
117
+ for (const p of parts) for (const c of p.changes ?? []) {
118
+ if (c.old != null) oldFiles.push({ path: `${p.name}/${c.file}`, source: c.old });
119
+ const now = p.files.find((f) => f.path === c.file);
120
+ if (now && c.status !== 'removed') { newFiles.push({ path: `${p.name}/${c.file}`, source: now.source }); changedInputs.push(inputOf(p.name, c.file)); }
121
+ }
122
+ review = thunderReview(oldFiles, newFiles);
123
+ add({
124
+ kind: 'review', status: 'read',
125
+ claim: `What the change does, read from both versions: ${review.says}`,
126
+ basis: { base: change.base, head: change.head, schema: review.schema, meaning: review.summary.meaning, risk: review.summary.risk, form: review.summary.form },
127
+ scope: 'What the code says before and after; not whether it runs or is right.',
128
+ inputs: changedInputs,
129
+ });
130
+ }
131
+ for (const x of extra) add({ ...x, inputs: (x.inputs ?? []).map((i) => (i.sha256 ? i : inputOf(i.part, i.file))) });
132
+
133
+ // Unknowns: what Thunder could not read or link, the parts no test ran in, and what nothing here verified.
134
+ const tested = new Set(runs.filter((r) => r.part).map((r) => r.part));
135
+ const anyUnscoped = runs.some((r) => !r.part);
136
+ const untested = anyUnscoped ? [] : parts.filter((p) => !tested.has(p.name)).map((p) => ({ part: p.name, what: `No tests were run in ${p.name}.` }));
137
+ const notLinked = trace.notLinked.map((n) => ({ kind: n.kind, call: n.call, at: n.from.cite, why: n.why }));
138
+ const unknowns = {
139
+ notRead, notLinked, untested,
140
+ ...(behavior.length > MAX_BEHAVIOR ? { notShown: `${behavior.length - MAX_BEHAVIOR} more actions and rules are not listed (the first ${MAX_BEHAVIOR} are).` } : {}),
141
+ notVerified: [...ALWAYS_NOT_VERIFIED, ...runs.filter((r) => r.exitCode !== 0).map((r) => `\`${r.command}\` failed, so what it tests is not verified.`)],
142
+ };
143
+
144
+ const changedFiles = change ? parts.flatMap((p) => (p.changes ?? []).map((c) => ({ part: p.name, file: c.file, status: c.status }))) : [];
145
+ const body = {
146
+ schema: PASSPORT_SCHEMA,
147
+ subject: { kind: change ? 'change' : 'feature', parts: parts.map((p) => ({ name: p.name, path: p.path ?? p.name, sha: p.sha ?? null, dirty: !!p.dirty })) },
148
+ purpose: purpose?.text ? { stated: true, text: purpose.text, source: purpose.source ?? 'given when the passport was built' } : { stated: false, text: 'not stated', source: null },
149
+ behavior: shownBehavior,
150
+ dependencies: { files: [...hashes.values()], links, packages: parts.flatMap((p) => p.packages ?? []), services },
151
+ effects,
152
+ evidence,
153
+ unknowns,
154
+ history: { base: change?.base ?? null, head: change?.head ?? null, changedFiles, thunder },
155
+ };
156
+ const summary = summarize(body);
157
+ return { ...body, summary, history: { ...body.history, builtAt }, fingerprint: sha256(JSON.stringify({ ...body, summary })) };
158
+ }
159
+
160
+ /** The counts people read first. A claim is an evidence item; nothing counts as verified without one. */
161
+ export function summarize(p) {
162
+ const by = (s) => p.evidence.filter((e) => e.status === s).length;
163
+ const u = p.unknowns;
164
+ return {
165
+ claims: p.evidence.length, passed: by('passed'), failed: by('failed'), readFromCode: by('read'),
166
+ unknowns: u.notRead.length + u.notLinked.length + u.untested.length, notVerified: u.notVerified.length,
167
+ };
168
+ }
169
+
170
+ /**
171
+ * Is each evidence item still about the code as it is now? `read(part, file)` gives a file's current text, or null
172
+ * when it is gone. Nothing is re-run: an item is `current` when every file it depended on is unchanged, else `stale`
173
+ * (naming each changed or missing file). Items with no recorded inputs are `unknown`.
174
+ */
175
+ export function checkPassport(passport, { read }) {
176
+ if (passport?.schema !== PASSPORT_SCHEMA) throw new Error('this is not a Thunder passport (thunder-passport-v1).');
177
+ const cache = new Map();
178
+ const now = (part, file) => {
179
+ const k = `${part}/${file}`;
180
+ if (!cache.has(k)) { const s = read(part, file); cache.set(k, s == null ? null : fileHash(s)); }
181
+ return cache.get(k);
182
+ };
183
+ const items = passport.evidence.map((e) => {
184
+ if (!e.inputs?.length) return { id: e.id, kind: e.kind, claim: e.claim, freshness: 'unknown', changed: [] };
185
+ const changed = [];
186
+ for (const i of e.inputs) {
187
+ const h = now(i.part, i.file);
188
+ if (h == null) changed.push({ part: i.part, file: i.file, now: 'missing' });
189
+ else if (h !== i.sha256) changed.push({ part: i.part, file: i.file, now: 'changed' });
190
+ }
191
+ return { id: e.id, kind: e.kind, claim: e.claim, freshness: changed.length ? 'stale' : 'current', changed };
192
+ });
193
+ const files = passport.dependencies.files.map((f) => ({ ...f, now: now(f.part, f.file) })).filter((f) => f.now !== f.sha256)
194
+ .map((f) => ({ part: f.part, file: f.file, now: f.now == null ? 'missing' : 'changed' }));
195
+ return { schema: 'thunder-passport-check-v1', current: items.filter((x) => x.freshness === 'current').length, stale: items.filter((x) => x.freshness === 'stale').length, items, changedFiles: files };
196
+ }
197
+
198
+ const MARK = { passed: '✓', failed: '✗', read: '○' };
199
+ const STATUS_WORDS = { passed: 'ran and passed', failed: 'ran and failed', read: 'read from code, not run' };
200
+
201
+ /** A passport as short plain text for the terminal: the counts, then each evidence item with a mark and words. */
202
+ export function renderPassportSummary(p) {
203
+ const s = p.summary;
204
+ const L = [`Thunder passport (${p.subject.kind}): ${p.subject.parts.map((x) => x.name).join(', ')}`,
205
+ `Purpose: ${p.purpose.stated ? p.purpose.text : 'not stated'}`,
206
+ `${s.claims} claim${s.claims === 1 ? '' : 's'} with evidence (${s.passed} passed, ${s.failed} failed, ${s.readFromCode} read from code), ${s.unknowns} unknown${s.unknowns === 1 ? '' : 's'}, ${s.notVerified} not verified`, '', 'Evidence'];
207
+ for (const e of p.evidence) L.push(` ${MARK[e.status] ?? '○'} ${STATUS_WORDS[e.status] ?? e.status}: ${e.claim}`);
208
+ if (!p.evidence.length) L.push(' (none: nothing in this passport is verified)');
209
+ L.push('', 'Not verified');
210
+ for (const x of p.unknowns.notVerified) L.push(` ○ ${x}`);
211
+ if (p.unknowns.untested.length) for (const x of p.unknowns.untested) L.push(` ○ ${x.what}`);
212
+ return L.join('\n');
213
+ }
214
+
215
+ /** The whole passport as Markdown, for a pull request or a folder. */
216
+ export function renderPassportMarkdown(p) {
217
+ const s = p.summary;
218
+ const L = [`# Thunder passport: ${p.subject.parts.map((x) => x.name).join(', ')}`, '',
219
+ `A ${p.subject.kind === 'change' ? `change${p.history.base ? ` from \`${String(p.history.base).slice(0, 12)}\`` : ''}` : 'snapshot'}. **${s.claims} claims with evidence** (${s.passed} passed, ${s.failed} failed, ${s.readFromCode} read from code), **${s.unknowns} unknowns**, **${s.notVerified} not verified**. This is an evidence record, not a certificate: each claim says what it rests on and what it does not cover.`, '',
220
+ '## Purpose', '', p.purpose.stated ? `${p.purpose.text}\n\n(Source: ${p.purpose.source}.)` : 'Not stated. Thunder never guesses what a change is for.', ''];
221
+ const evidenceList = (list) => {
222
+ for (const e of list) {
223
+ L.push(`- ${MARK[e.status] ?? '○'} ${e.claim}`);
224
+ const b = e.basis;
225
+ L.push(` - Basis: ${b.command ? `\`${b.command}\` in \`${b.cwd}\`, exit ${b.exitCode}, output ${String(b.outputDigest).slice(0, 19)}…` : b.from ? `${b.from} → ${b.to}` : b.base ? `review of ${String(b.base).slice(0, 12)} → ${String(b.head ?? 'working tree').slice(0, 12)}` : JSON.stringify(b)}`);
226
+ L.push(` - Does not cover: ${e.scope}`);
227
+ L.push(` - Depends on ${e.inputs.length} file${e.inputs.length === 1 ? '' : 's'} (by content hash)`);
228
+ }
229
+ };
230
+ const ran = p.evidence.filter((e) => e.status === 'passed'), failedRuns = p.evidence.filter((e) => e.status === 'failed'), readOnly = p.evidence.filter((e) => e.status !== 'passed' && e.status !== 'failed');
231
+ L.push('## Verified by running (ran and passed)', '');
232
+ if (ran.length) evidenceList(ran); else L.push('Nothing was run, so nothing here is verified by running.');
233
+ if (failedRuns.length) { L.push('', '## Ran and failed', ''); evidenceList(failedRuns); }
234
+ L.push('', '## Read from code (not run)', '');
235
+ if (readOnly.length) evidenceList(readOnly); else L.push('None.');
236
+ L.push('', '## Not verified', '', ...p.unknowns.notVerified.map((x) => `- ${x}`), ...p.unknowns.untested.map((x) => `- ${x.what}`), '');
237
+ L.push('## Behavior', '');
238
+ for (const b of p.behavior) {
239
+ L.push(`### ${b.name} (${b.part}/${b.file}, lines ${b.lines[0]}–${b.lines[1]}${b.change ? `, ${b.change}` : ''})`, '', '```text', b.text || '(no reading)', '```', '');
240
+ }
241
+ if (p.unknowns.notShown) L.push(p.unknowns.notShown, '');
242
+ L.push('## Effects (detected in code, not observed)', '');
243
+ for (const e of p.effects) L.push(`- ${e.in} **${e.kind}**: ${e.says} (${e.part}/${e.file}:${e.line})`);
244
+ if (!p.effects.length) L.push('None detected.');
245
+ L.push('', '## Dependencies', '', ...p.dependencies.links.map((l) => `- ${l.says} (${l.from} → ${l.to})`));
246
+ if (p.dependencies.packages.length) L.push(...p.dependencies.packages.map((x) => `- package ${x.name}${x.version ? ` ${x.version}` : ''} (${x.from})`));
247
+ if (p.dependencies.services.length) L.push(...p.dependencies.services.map((x) => `- calls ${x.calls} (${x.at})`));
248
+ L.push(`- ${p.dependencies.files.length} files read, each recorded by content hash`, '');
249
+ L.push('## Unknowns', '');
250
+ for (const x of p.unknowns.notRead) L.push(`- not read: ${x.what} (${x.part}/${x.file}:${x.line})`);
251
+ for (const x of p.unknowns.notLinked) L.push(`- not linked: ${x.call}: ${x.why} (${x.at})`);
252
+ if (!p.unknowns.notRead.length && !p.unknowns.notLinked.length) L.push('Nothing Thunder failed to read or link.');
253
+ L.push('', '## History', '', `- Base: ${p.history.base ?? '(none: a snapshot)'}`, `- Head: ${p.history.head ?? '(working tree)'}`, ...p.history.changedFiles.map((c) => `- ${c.status}: ${c.part}/${c.file}`), `- Built: ${p.history.builtAt}${p.history.thunder ? ` with Thunder ${p.history.thunder}` : ''}`, `- Fingerprint: ${p.fingerprint}`, '');
254
+ return L.join('\n');
255
+ }
@@ -0,0 +1,31 @@
1
+ // Types for @skillstech/thunderlang/program (src/program.mjs). Results are plain objects; see docs/core.md.
2
+ export interface CoreDiagnostic { code: string; line: number; message: string; hint?: string; [k: string]: unknown }
3
+ export interface CoreResult { ok: boolean; program?: unknown; info?: unknown; diagnostics: CoreDiagnostic[]; file?: string; module?: string; kind?: string; [k: string]: unknown }
4
+ export interface RunOutput { status: number; stdout: string; stderr: string; [k: string]: unknown }
5
+ export type ReadText = ((path: string, cwd: string) => string) | null;
6
+ export const CORE_VERSION: string;
7
+ export const CODES: Record<string, unknown>;
8
+ export function compileCore(source: string, options?: { file?: string; imported?: unknown[]; srcModules?: unknown[] }): CoreResult;
9
+ export function diagnosticsText(result: CoreResult): string;
10
+ export function parseCore(source: string, ...rest: unknown[]): unknown;
11
+ export function checkCore(...args: unknown[]): unknown;
12
+ export function formatCore(source: string, options?: { width?: number }): unknown;
13
+ export function formatDiagnostic(...args: unknown[]): string;
14
+ export function runInProcess(options: { entry: CoreResult; cwd: string; deeper?: boolean; readText?: ReadText }): RunOutput;
15
+ export function recordedRun(options: { entry: CoreResult; cwd: string; readText?: ReadText }): unknown;
16
+ export function testInProcess(options: { results: CoreResult[]; cwd: string; deeper?: boolean; readText?: ReadText }): unknown;
17
+ export interface ScreenAppHandle { render(): unknown; readonly screen: string | null; press(label: string, nth?: number): { off: boolean; tree: unknown }; type(label: string, text: string, nth?: number): { tree: unknown } }
18
+ /** The same handle, by the name apps expect. */
19
+ export type ScreenApp = ScreenAppHandle;
20
+ export function screenApp(options: { entry: CoreResult; cwd?: string; readText?: ReadText }): ScreenAppHandle;
21
+ export function screenOutline(tree: unknown, indent?: string): string;
22
+ export function toPython(program: unknown, info: unknown, options?: { source?: string; imports?: unknown[] }): string;
23
+ export function toTypeScript(program: unknown, info: unknown, options?: { source?: string; imports?: unknown[] }): string;
24
+ export function toCSharp(program: unknown, info: unknown, options?: { source?: string; module?: string; namespace?: string; imports?: unknown[] }): string;
25
+ export function toJava(program: unknown, info: unknown, options?: { source?: string; module?: string; imports?: unknown[]; pkg?: string }): string;
26
+ export function toGo(program: unknown, info: unknown, options: { source?: string; module?: string; ns: unknown }): string;
27
+ export function goNamespaces(results: CoreResult[]): Map<string, unknown>;
28
+ export function toRust(program: unknown, info: unknown, options?: { source?: string; imports?: unknown[] }): string;
29
+ export function toReact(program: unknown, info: unknown, options?: { source?: string }): string;
30
+ export function hasScreens(info: unknown): boolean;
31
+ export function pythonToCore(source: string): { core: string; functions: Array<{ name: string; exact: boolean }>; [k: string]: unknown };
@@ -0,0 +1,14 @@
1
+ // @skillstech/thunderlang/program: write and run Thunder Core anywhere, including in a browser. Compile a program,
2
+ // run it on the Thunder engine, show its screens, and turn it into Python, TypeScript, C#, Java, Go, Rust, or React.
3
+ // Everything here is browser-safe (no node: imports; test/program-entry.test.mjs checks the whole import graph).
4
+ // Files are read only through the `readText` you pass, so a browser can hand in its own.
5
+ export { compileCore, diagnosticsText, parseCore, checkCore, formatCore, CODES, formatDiagnostic, CORE_VERSION } from './core/index.mjs';
6
+ export { runInProcess, recordedRun, testInProcess, screenApp, screenOutline } from './core/engine-core.mjs';
7
+ export { toPython } from './core/target-python.mjs';
8
+ export { toTypeScript } from './core/target-typescript.mjs';
9
+ export { toCSharp } from './core/target-csharp.mjs';
10
+ export { toJava } from './core/target-java.mjs';
11
+ export { toGo, goNamespaces } from './core/target-go.mjs';
12
+ export { toRust } from './core/target-rust.mjs';
13
+ export { toReact, hasScreens } from './core/target-react.mjs';
14
+ export { pythonToCore } from './core/from-python.mjs';
@@ -0,0 +1,119 @@
1
+ /* @skillstech/thunderlang/react/reading.css: the Thunder drawing kit's one stylesheet.
2
+ Every color is a CSS variable: set them on any ancestor (or :root) to fit your app. The defaults are the dark
3
+ Thunder look; add class "tl-light" to an ancestor for the light set. --tl-accent (a Thing's color) follows
4
+ --language-accent when the page sets it. Works from 320px wide up; the "It can" grid is one column below 560px. */
5
+
6
+ .tl-reading, .tl-card {
7
+ --tl-surface: rgba(14, 18, 30, 0.6);
8
+ --tl-surface-raised: rgba(20, 26, 42, 0.7);
9
+ --tl-border: rgba(255, 255, 255, 0.12);
10
+ --tl-border-strong: rgba(255, 255, 255, 0.3);
11
+ --tl-text: #ffffff;
12
+ --tl-text-body: #e7eaf2;
13
+ --tl-text-muted: #aab2c5;
14
+ --tl-text-quiet: #8a93a8;
15
+ --tl-focus: #fcd34d;
16
+ --tl-radius: 24px;
17
+ --tl-radius-small: 12px;
18
+ /* The grammar's colors (thunder-visual-v1). */
19
+ --tl-c-structure: #c4b5fd;
20
+ --tl-c-question: #7fb2ff;
21
+ --tl-c-fact: #fcd34d;
22
+ --tl-c-comparison: #f472b6;
23
+ --tl-c-amount: #fdba74;
24
+ --tl-c-outcome: #67e8f9;
25
+ --tl-c-name: #bef264;
26
+ --tl-c-failure: #fdba74;
27
+ --tl-c-pass: #34d399;
28
+ --tl-c-fail: #f87171;
29
+ --tl-c-unread: #9ca3af;
30
+ --tl-accent: var(--language-accent, var(--tl-c-outcome));
31
+ --tl-knows: var(--tl-c-fact);
32
+ }
33
+
34
+ .tl-light .tl-reading, .tl-light .tl-card, .tl-reading.tl-light, .tl-card.tl-light {
35
+ --tl-surface: #ffffff;
36
+ --tl-surface-raised: #f6f7fb;
37
+ --tl-border: #dde1ea;
38
+ --tl-border-strong: #9aa3b5;
39
+ --tl-text: #111827;
40
+ --tl-text-body: #1f2937;
41
+ --tl-text-muted: #4b5563;
42
+ --tl-text-quiet: #6b7280;
43
+ --tl-focus: #b45309;
44
+ --tl-c-structure: #6d28d9;
45
+ --tl-c-question: #1d4ed8;
46
+ --tl-c-fact: #92400e;
47
+ --tl-c-comparison: #be185d;
48
+ --tl-c-amount: #c2410c;
49
+ --tl-c-outcome: #0e7490;
50
+ --tl-c-name: #4d7c0f;
51
+ --tl-c-failure: #c2410c;
52
+ --tl-c-pass: #047857;
53
+ --tl-c-fail: #b91c1c;
54
+ --tl-c-unread: #6b7280;
55
+ }
56
+
57
+ .tl-reading, .tl-card { box-sizing: border-box; color: var(--tl-text-body); font: inherit; min-width: 0; }
58
+ .tl-reading *, .tl-card * { box-sizing: border-box; }
59
+ .tl-reading :is(h2, h3, h4, h5, p, ul), .tl-card :is(h2, h3, h4, h5, p, ul) { margin: 0; }
60
+ .tl-reading ul, .tl-card ul { list-style: none; padding: 0; }
61
+
62
+ .tl-symbol { flex-shrink: 0; }
63
+ .tl-c-structure { color: var(--tl-c-structure); }
64
+ .tl-c-question { color: var(--tl-c-question); }
65
+ .tl-c-fact { color: var(--tl-c-fact); }
66
+ .tl-c-comparison { color: var(--tl-c-comparison); }
67
+ .tl-c-amount { color: var(--tl-c-amount); }
68
+ .tl-c-outcome { color: var(--tl-c-outcome); }
69
+ .tl-c-name { color: var(--tl-c-name); }
70
+ .tl-c-failure { color: var(--tl-c-failure); }
71
+ .tl-c-pass { color: var(--tl-c-pass); }
72
+ .tl-c-fail { color: var(--tl-c-fail); }
73
+ .tl-c-unread { color: var(--tl-c-unread); }
74
+
75
+ /* Cards */
76
+ .tl-card { border: 1px solid var(--tl-border); border-radius: calc(var(--tl-radius) - 4px); background: var(--tl-surface); padding: 20px; overflow-wrap: anywhere; }
77
+ .tl-card-head { display: flex; align-items: center; gap: 14px; }
78
+ .tl-kicker { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--tl-accent); }
79
+ .tl-kicker-quiet { font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--tl-text-quiet); }
80
+ .tl-card-title { font-size: 24px; line-height: 1.25; font-weight: 700; color: var(--tl-text); }
81
+ .tl-card-title-small { font-size: 18px; font-weight: 600; }
82
+ .tl-doc { margin-top: 12px !important; font-size: 17px; line-height: 1.55; color: var(--tl-text-body); }
83
+ .tl-doc-small { margin-top: 8px !important; font-size: 14px; color: var(--tl-text-muted); }
84
+ .tl-section-label { margin-top: 20px !important; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--tl-text-quiet); }
85
+
86
+ /* A Thing */
87
+ .tl-thing { border: 2px solid color-mix(in srgb, var(--tl-accent) 50%, transparent); border-radius: var(--tl-radius); background: color-mix(in srgb, var(--tl-accent) 4%, transparent); padding: 24px; }
88
+ .tl-thing.tl-selected { border-color: var(--tl-accent); }
89
+ .tl-knows { margin-top: 8px !important; display: grid; gap: 4px; font-size: 16px; }
90
+ .tl-knows-small { margin-top: 12px !important; font-size: 14px; }
91
+ .tl-knows-name { color: var(--tl-knows); }
92
+ .tl-knows-detail { color: var(--tl-text-muted); }
93
+ .tl-abilities { margin-top: 8px !important; display: grid; gap: 8px; grid-template-columns: 1fr; }
94
+ @media (min-width: 560px) { .tl-abilities { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
95
+ .tl-ability { display: flex; width: 100%; min-height: 44px; align-items: center; gap: 12px; border: 1px solid var(--tl-border); border-radius: var(--tl-radius-small); background: var(--tl-surface-raised); padding: 10px 12px; text-align: left; font: inherit; color: inherit; }
96
+ .tl-ability-button { cursor: pointer; }
97
+ .tl-ability-button:hover { border-color: var(--tl-border-strong); }
98
+ .tl-ability-label { font-size: 15px; font-weight: 500; color: var(--tl-text); }
99
+ .tl-ability-go { margin-left: auto; color: var(--tl-text-quiet); }
100
+ .tl-starts { margin-top: 12px !important; display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--tl-text-muted); }
101
+ .tl-starts-button { min-height: 44px; border: 0; background: none; padding: 0; font: inherit; font-size: 14px; color: var(--tl-text-muted); cursor: pointer; text-align: left; }
102
+ .tl-starts-button:hover { color: var(--tl-text); }
103
+ .tl-ability-button:focus-visible, .tl-starts-button:focus-visible { outline: 2px solid var(--tl-focus); outline-offset: 2px; }
104
+
105
+ /* Data */
106
+ .tl-choices { margin-top: 12px !important; display: flex; flex-wrap: wrap; gap: 8px; }
107
+ .tl-choice { border: 1px solid color-mix(in srgb, var(--tl-c-outcome) 50%, transparent); border-radius: 999px; padding: 4px 12px; font-size: 14px; color: var(--tl-c-outcome); }
108
+
109
+ /* The Big Picture */
110
+ .tl-big-picture { display: grid; gap: 24px; }
111
+ .tl-bp-things { display: grid; gap: 20px; }
112
+ .tl-bp-data { display: grid; gap: 16px; grid-template-columns: 1fr; }
113
+ @media (min-width: 760px) { .tl-bp-data { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
114
+ @media (max-width: 420px) {
115
+ .tl-thing { padding: 18px; }
116
+ .tl-card { padding: 16px; }
117
+ .tl-card-title { font-size: 21px; }
118
+ }
119
+ @media (prefers-reduced-motion: no-preference) { .tl-ability-button, .tl-starts-button { transition: border-color 120ms, color 120ms; } }
@@ -0,0 +1,15 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { ThunderModel, Thing } from '../model.d.mts';
3
+ import type { ReadingLayout, ThingCardLayout, DataCardLayout, ThunderSymbolId } from '../reading-layout.d.mts';
4
+
5
+ export { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS } from '../reading-layout.mjs';
6
+ export type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, ThunderSymbolId } from '../reading-layout.d.mts';
7
+
8
+ /** A Thunder symbol; its color is the CSS variable for its grammar color (--tl-c-*). */
9
+ export function ThunderSymbol(props: { id: ThunderSymbolId; size?: number; label?: string }): ReactElement | null;
10
+ /** A Thing card. Pass `card` (from thingCard/readingLayout) or `model` and `thing`. onOpen(memberId) makes abilities buttons. */
11
+ export function ThingCard(props: { card?: ThingCardLayout; model?: ThunderModel; thing?: Thing; onOpen?: (memberId: string) => void; selected?: boolean; headingLevel?: 2 | 3 | 4 }): ReactElement;
12
+ /** A Data card: a record or choices. Pass `card` or `thing`. */
13
+ export function DataCard(props: { card?: DataCardLayout; thing?: Thing; headingLevel?: 2 | 3 | 4 }): ReactElement;
14
+ /** The Big Picture: every Thing, then records and choices. */
15
+ export function BigPicture(props: { model?: ThunderModel; layout?: ReadingLayout; focus?: string | null; onOpen?: (memberId: string) => void; selectedId?: string; headingLevel?: 2 | 3 }): ReactElement;
@@ -0,0 +1,87 @@
1
+ // @skillstech/thunderlang/react: the Thunder drawing kit. One set of components that OpenThunder, thunderlang.dev,
2
+ // and the Skills Tech Talk course all use, so a reading looks and reads the same everywhere. Every word and its
3
+ // order come from readingLayout (../reading-layout.mjs); these components only turn that data into elements.
4
+ // Styling: plain `tl-` class names and one stylesheet (@skillstech/thunderlang/react/reading.css) whose colors are
5
+ // CSS variables, so each app sets its own (STT's --language-accent is honored). No JSX, no build step, no Tailwind:
6
+ // React is the only dependency, and it is the app's own (a peer dependency).
7
+ import { createElement as h, Fragment } from 'react';
8
+ import { THUNDER_VISUAL } from '../visual.mjs';
9
+ import { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS } from '../reading-layout.mjs';
10
+
11
+ export { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS };
12
+
13
+ /** A Thunder symbol, from the grammar's own path data. Its color is the CSS variable for its grammar color. */
14
+ export function ThunderSymbol({ id, size = 28, label }) {
15
+ const s = THUNDER_VISUAL.symbols[id];
16
+ if (!s) return null;
17
+ return h('svg', {
18
+ width: size, height: size, viewBox: '0 0 44 44', fill: 'none', stroke: 'currentColor', strokeWidth: 2.6, strokeLinejoin: 'round', strokeLinecap: 'round',
19
+ strokeDasharray: s.dashed ? '4 4' : undefined, className: `tl-symbol tl-c-${s.color}`,
20
+ role: label ? 'img' : undefined, 'aria-label': label, 'aria-hidden': label ? undefined : true, focusable: 'false',
21
+ },
22
+ ...s.paths.map((d, i) => h('path', { key: `p${i}`, d })),
23
+ ...(s.circles ?? []).map(([cx, cy, r], i) => h('circle', { key: `c${i}`, cx, cy, r, fill: s.fill ? 'currentColor' : 'none' })));
24
+ }
25
+
26
+ const knowsItem = (k) => h('li', { key: k.name, className: 'tl-knows-item' },
27
+ h('span', { className: 'tl-knows-name' }, k.label),
28
+ k.detail ? h('span', { className: 'tl-knows-detail' }, `: ${k.detail}`) : null);
29
+
30
+ /**
31
+ * A Thing (a class): what it knows and what it can do. With `onOpen`, each ability and "How a new … starts" is a
32
+ * button that calls onOpen(memberId); without it they are plain text.
33
+ * card: thingCard(model, thing), or pass `model` and `thing` and it is worked out here.
34
+ */
35
+ export function ThingCard({ card, model, thing, onOpen, selected = false, headingLevel = 2 }) {
36
+ const c = card ?? thingCard(model, thing);
37
+ const hid = `tl-thing-${c.id}`;
38
+ const ability = (m) => h(Fragment, null,
39
+ h(ThunderSymbol, { id: m.symbol, size: 24 }),
40
+ h('span', { className: 'tl-ability-label' }, m.label),
41
+ onOpen ? h('span', { className: 'tl-ability-go', 'aria-hidden': true }, '→') : null);
42
+ return h('section', { 'aria-labelledby': hid, className: `tl-card tl-thing${selected ? ' tl-selected' : ''}` },
43
+ h('div', { className: 'tl-card-head' },
44
+ h(ThunderSymbol, { id: 'thing', size: 44, label: 'Thing' }),
45
+ h('div', null,
46
+ h('p', { className: 'tl-kicker' }, c.heading),
47
+ h(`h${headingLevel}`, { id: hid, className: 'tl-card-title' }, c.label))),
48
+ c.doc ? h('p', { className: 'tl-doc' }, c.doc) : null,
49
+ c.knows.items.length ? h(Fragment, null,
50
+ h(`h${headingLevel + 1}`, { className: 'tl-section-label' }, c.knows.heading),
51
+ h('ul', { className: 'tl-knows' }, c.knows.items.map(knowsItem))) : null,
52
+ c.can.items.length ? h(Fragment, null,
53
+ h(`h${headingLevel + 1}`, { className: 'tl-section-label' }, c.can.heading),
54
+ h('ul', { className: 'tl-abilities' }, c.can.items.map((m) => h('li', { key: m.id },
55
+ onOpen
56
+ ? h('button', { type: 'button', className: 'tl-ability tl-ability-button', onClick: () => onOpen(m.id) }, ability(m))
57
+ : h('div', { className: 'tl-ability' }, ability(m)))))) : null,
58
+ c.starts.id && onOpen
59
+ ? h('button', { type: 'button', className: 'tl-starts tl-starts-button', onClick: () => onOpen(c.starts.id) }, h(ThunderSymbol, { id: 'setup', size: 18 }), c.starts.text)
60
+ : h('p', { className: 'tl-starts' }, h(ThunderSymbol, { id: 'setup', size: 18 }), c.starts.text));
61
+ }
62
+
63
+ /** Data: a record (facts, like an ID card) or choices (one allowed value). */
64
+ export function DataCard({ card, thing, headingLevel = 3 }) {
65
+ const c = card ?? dataCard(thing);
66
+ return h('section', { className: `tl-card tl-data tl-data-${c.kind}` },
67
+ h('div', { className: 'tl-card-head' },
68
+ h(ThunderSymbol, { id: c.symbol, size: 30, label: c.symbolLabel }),
69
+ h('div', null,
70
+ h('p', { className: 'tl-kicker tl-kicker-quiet' }, c.heading),
71
+ h(`h${headingLevel}`, { className: 'tl-card-title tl-card-title-small' }, c.label))),
72
+ c.doc ? h('p', { className: 'tl-doc tl-doc-small' }, c.doc) : null,
73
+ c.choices.length ? h('ul', { className: 'tl-choices' }, c.choices.map((x) => h('li', { key: x, className: 'tl-choice' }, x))) : null,
74
+ c.knows.length ? h('ul', { className: 'tl-knows tl-knows-small' }, c.knows.map(knowsItem)) : null);
75
+ }
76
+
77
+ /**
78
+ * The Big Picture, zoomed by `focus` (see readingLayout). The IO boxes for an action or rule are drawn by IOBoxes,
79
+ * which joins the kit next; until then that section is left to the app.
80
+ */
81
+ export function BigPicture({ model, layout, focus = null, onOpen, selectedId, headingLevel = 2 }) {
82
+ const l = layout ?? readingLayout(model, { focus });
83
+ return h('div', { className: 'tl-reading tl-big-picture' }, l.sections.filter((s) => s.id !== 'io').map((s) => h('section', { key: s.id, className: `tl-bp-section tl-bp-${s.id}`, 'aria-label': s.heading },
84
+ h('div', { className: s.id === 'things' ? 'tl-bp-things' : 'tl-bp-data' }, s.cards.map((c) => (c.kind === 'thing'
85
+ ? h(ThingCard, { key: c.id, card: c, onOpen, selected: c.id === selectedId, headingLevel })
86
+ : h(DataCard, { key: c.id, card: c, headingLevel: headingLevel + 1 })))))));
87
+ }