@skillstech/thunderlang 0.5.2 → 0.5.5
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 +132 -0
- package/dist/core.cjs +10204 -6621
- package/dist/index.cjs +3867 -1771
- package/package.json +1 -1
- package/src/anchor.d.mts +12 -0
- package/src/anchor.mjs +127 -0
- package/src/cli.mjs +148 -39
- package/src/codegen.mjs +27 -9
- package/src/core.d.ts +24 -0
- package/src/core.mjs +19 -1
- package/src/emit.mjs +1 -1
- package/src/index.d.ts +26 -0
- package/src/index.mjs +14 -0
- package/src/mcp.mjs +19 -32
- package/src/model.d.mts +18 -0
- package/src/model.mjs +456 -0
- package/src/obligations.d.mts +9 -0
- package/src/obligations.mjs +35 -0
- package/src/plain-contract.d.mts +30 -0
- package/src/plain-contract.mjs +339 -0
- package/src/promote.mjs +19 -5
- package/src/read.d.mts +25 -1
- package/src/read.mjs +415 -23
- package/src/review-atlas.d.mts +19 -0
- package/src/review-atlas.mjs +136 -0
- package/src/same.d.mts +10 -0
- package/src/same.mjs +160 -0
- package/src/steps.d.mts +2 -0
- package/src/steps.mjs +599 -0
- package/src/target-types.mjs +39 -4
- package/src/testing.mjs +12 -9
- package/src/thunder-repo.mjs +96 -0
- package/src/thunderize.d.mts +14 -0
- package/src/thunderize.mjs +82 -0
- package/src/visual.d.mts +40 -0
- package/src/visual.mjs +304 -0
- package/src/write.d.mts +24 -0
- package/src/write.mjs +263 -0
package/src/target-types.mjs
CHANGED
|
@@ -28,13 +28,47 @@ export function buildCases(ast) {
|
|
|
28
28
|
return cases;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
//
|
|
32
|
-
|
|
31
|
+
// A declared input type (`amount: number`, `Money`, `Flag`) as number, bool, or string; null when none.
|
|
32
|
+
const NUMBER_TYPES = /^(number|int|integer|long|short|float|double|decimal|Money|Percentage|Count|Duration)$/i;
|
|
33
|
+
const BOOL_TYPES = /^(boolean|bool|Flag)$/i;
|
|
34
|
+
export function declaredInputType(raw) {
|
|
35
|
+
const m = String(raw).match(/:\s*([A-Za-z][\w<>]*)\s*$/);
|
|
36
|
+
if (!m) return null;
|
|
37
|
+
if (NUMBER_TYPES.test(m[1])) return 'number';
|
|
38
|
+
if (BOOL_TYPES.test(m[1])) return 'bool';
|
|
39
|
+
return 'string';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// How each input is used in the decision's rules: compared with a number, compared with text, or on its own (a yes/no).
|
|
43
|
+
function usageTypes(dec, names) {
|
|
44
|
+
const out = {};
|
|
45
|
+
const NUM = /^-?\d+(\.\d+)?$/, STR = /^"[^"]*"$|^'[^']*'$/, CMP = /^(<|<=|>|>=|==|!=)$/;
|
|
46
|
+
for (const r of dec.rules || []) {
|
|
47
|
+
const toks = String(r.when || '').match(/"[^"]*"|'[^']*'|[A-Za-z_][\w.]*|-?\d+(?:\.\d+)?|<=|>=|==|!=|[<>()]/g) || [];
|
|
48
|
+
toks.forEach((t, i) => {
|
|
49
|
+
if (!names.includes(t)) return;
|
|
50
|
+
const op = CMP.test(toks[i + 1] || '') ? toks[i + 1] : CMP.test(toks[i - 1] || '') ? toks[i - 1] : null;
|
|
51
|
+
const other = op === toks[i + 1] ? toks[i + 2] : op ? toks[i - 2] : null;
|
|
52
|
+
if (op && NUM.test(other || '')) out[t] = 'number';
|
|
53
|
+
else if (op && /^[<>]=?$/.test(op) && names.includes(other || '')) out[t] = out[t] ?? 'number';
|
|
54
|
+
else if (op && STR.test(other || '') && out[t] !== 'number') out[t] = 'string';
|
|
55
|
+
else if (!op && out[t] == null) out[t] = 'bool';
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Infer one type per input for a decision. A declared type wins; then the values the decision's examples give
|
|
62
|
+
// (numeric wins, so a relational comparison compiles, then boolean); then how the rules use the input.
|
|
63
|
+
// Falls back to 'string'.
|
|
33
64
|
export function inferInputTypes(ast, dec) {
|
|
34
65
|
const names = inputNames(dec);
|
|
66
|
+
const declared = Object.fromEntries((dec.inputs || []).map((raw) => [String(raw).split(':')[0].trim(), declaredInputType(raw)]));
|
|
67
|
+
const usage = usageTypes(dec, names);
|
|
35
68
|
const types = {};
|
|
36
69
|
for (const n of names) {
|
|
37
|
-
|
|
70
|
+
if (declared[n]) { types[n] = declared[n]; continue; }
|
|
71
|
+
let t = null;
|
|
38
72
|
for (const test of (ast.tests || []).filter((x) => x.name === dec.name)) {
|
|
39
73
|
for (const c of test.cases || []) {
|
|
40
74
|
const raw = (c.given || {})[n];
|
|
@@ -42,10 +76,11 @@ export function inferInputTypes(ast, dec) {
|
|
|
42
76
|
const cv = coerceVal(raw);
|
|
43
77
|
if (typeof cv === 'number') { t = 'number'; break; }
|
|
44
78
|
if (typeof cv === 'boolean' && t !== 'number') t = 'bool';
|
|
79
|
+
if (typeof cv === 'string' && t == null) t = 'string';
|
|
45
80
|
}
|
|
46
81
|
if (t === 'number') break;
|
|
47
82
|
}
|
|
48
|
-
types[n] = t;
|
|
83
|
+
types[n] = t ?? usage[n] ?? 'string';
|
|
49
84
|
}
|
|
50
85
|
return types;
|
|
51
86
|
}
|
package/src/testing.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// `runTests` executes them through the deterministic Intent Runtime: no AI, no code, the
|
|
4
|
-
// spec proves itself. This is what lets intent be trustworthy , the behavior is asserted.
|
|
1
|
+
// Execute declared cases against the intent runtime. Passing cases are evidence for
|
|
2
|
+
// those inputs, not a proof of every input or of the application's implementation.
|
|
5
3
|
|
|
6
4
|
import { slug } from './parse.mjs';
|
|
7
5
|
import { evaluateDecision, simulateLifecycle } from './runtime.mjs';
|
|
@@ -36,18 +34,23 @@ export function runTests(ast) {
|
|
|
36
34
|
for (const t of ast.tests || []) {
|
|
37
35
|
const dec = decisions.find((d) => slug(d.name) === slug(t.name || ''));
|
|
38
36
|
const lc = lifecycles.find((l) => slug(l.name) === slug(t.name || ''));
|
|
39
|
-
|
|
37
|
+
if (!t.cases?.length) {
|
|
38
|
+
results.push({ target: t.name, case: '(empty test)', kind: 'unknown', pass: false, error: 'test block has no cases' });
|
|
39
|
+
}
|
|
40
|
+
for (const c of t.cases || []) {
|
|
40
41
|
const label = { target: t.name, case: c.name || `case ${results.length + 1}` };
|
|
41
42
|
if (dec) {
|
|
42
43
|
const inputs = coerce(c.given);
|
|
43
44
|
const run = evaluateDecision(dec, inputs);
|
|
44
|
-
const
|
|
45
|
-
|
|
45
|
+
const error = !run.ok ? 'a condition failed to evaluate' : c.expect == null ? 'decision case needs an expect assertion' : null;
|
|
46
|
+
const pass = !error && String(run.result) === String(c.expect);
|
|
47
|
+
results.push({ ...label, kind: 'decision', expected: c.expect, actual: run.result, matched: run.matched, pass, ...(error ? { error, note: error } : {}) });
|
|
46
48
|
} else if (lc) {
|
|
47
49
|
const sim = simulateLifecycle(lc, c.events || []);
|
|
48
50
|
const passState = c.expect == null || sim.finalState === c.expect;
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
+
const hasAssertion = c.expect != null || c.expectValid != null;
|
|
52
|
+
const passValid = sim.valid === (c.expectValid ?? true);
|
|
53
|
+
results.push({ ...label, kind: 'lifecycle', expected: c.expect, actual: sim.finalState, valid: sim.valid, expectValid: c.expectValid, pass: hasAssertion && passState && passValid, ...(!hasAssertion ? { error: 'scenario needs an expect, valid, or invalid assertion' } : {}) });
|
|
51
54
|
} else {
|
|
52
55
|
results.push({ ...label, kind: 'unknown', pass: false, error: `no decision or lifecycle named "${t.name}"` });
|
|
53
56
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Node-only: Thunder a whole repository (a local folder or a public GitHub repo).
|
|
2
|
+
// Read-only by design: files are parsed by the Thunder code reader, never executed, imported, or built.
|
|
3
|
+
// A GitHub URL is shallow-cloned with `git` (argument list, no shell) into a fresh temp folder.
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { mkdtempSync, rmSync, statSync } from 'node:fs';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { collectReadableFiles } from './read-repo-fs.mjs';
|
|
9
|
+
import { readRepo } from './read-repo.mjs';
|
|
10
|
+
import { plainFromReading, conditionText } from './plain-contract.mjs';
|
|
11
|
+
|
|
12
|
+
export const THUNDER_REPO_SCHEMA = 'thunder-repo-v1';
|
|
13
|
+
const GITHUB = /^(?:https:\/\/github\.com\/)?([A-Za-z0-9](?:[A-Za-z0-9-]{0,38}))\/([A-Za-z0-9._-]{1,100}?)(?:\.git)?\/?$/;
|
|
14
|
+
const MONEY = /^(amount|price|total|charge|balance|refund|cost|fee|tax|discount)/i;
|
|
15
|
+
const spaced = (s) => s.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_-]+/g, ' ').toLowerCase().trim();
|
|
16
|
+
|
|
17
|
+
/** Parse "owner/repo" or "https://github.com/owner/repo"; returns null for anything else. */
|
|
18
|
+
export function parseGitHub(target) {
|
|
19
|
+
const m = String(target).trim().match(GITHUB);
|
|
20
|
+
if (!m || m[2] === '.' || m[2] === '..') return null;
|
|
21
|
+
return { owner: m[1], repo: m[2], url: `https://github.com/${m[1]}/${m[2]}.git` };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function cloneGitHub(gh, { timeoutMs = 120000 } = {}) {
|
|
25
|
+
const dir = mkdtempSync(join(tmpdir(), 'thunder-repo-'));
|
|
26
|
+
const res = spawnSync('git', ['clone', '--depth', '1', '--quiet', '--no-tags', gh.url, join(dir, 'repo')], {
|
|
27
|
+
timeout: timeoutMs, encoding: 'utf8', env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
28
|
+
});
|
|
29
|
+
if (res.status !== 0) { rmSync(dir, { recursive: true, force: true }); throw new Error(`Could not clone ${gh.owner}/${gh.repo}: ${(res.stderr || res.error?.message || 'git failed').trim().split('\n')[0]}`); }
|
|
30
|
+
const head = spawnSync('git', ['-C', join(dir, 'repo'), 'rev-parse', 'HEAD'], { encoding: 'utf8' });
|
|
31
|
+
return { root: join(dir, 'repo'), cleanup: () => rmSync(dir, { recursive: true, force: true }), commit: head.stdout.trim() || null };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Thunder a repository: every readable file through the code reader, every drawable decision as a Thunder card. */
|
|
35
|
+
export function thunderRepo(target, { maxFiles = 3000, keep = false, exampleLimit = 8 } = {}) {
|
|
36
|
+
const gh = parseGitHub(target);
|
|
37
|
+
let isDir = false;
|
|
38
|
+
try { isDir = statSync(target).isDirectory(); } catch { /* not a local path */ }
|
|
39
|
+
if (!isDir && !gh) throw new Error('Give a local folder, owner/repo, or https://github.com/owner/repo.');
|
|
40
|
+
const started = Date.now();
|
|
41
|
+
const src = isDir ? { root: target, cleanup: () => {}, commit: null } : cloneGitHub(gh);
|
|
42
|
+
try {
|
|
43
|
+
const files = collectReadableFiles(src.root, { maxFiles });
|
|
44
|
+
const reading = readRepo(files, { maxFiles });
|
|
45
|
+
const decisions = reading.items.filter((i) => i.kind === 'decision');
|
|
46
|
+
const cards = [], errors = [];
|
|
47
|
+
for (const d of decisions) {
|
|
48
|
+
try { const m = plainFromReading(d); if (m) cards.push({ item: d, model: m }); }
|
|
49
|
+
catch (e) { errors.push({ file: d.file, name: d.name, error: e instanceof Error ? e.message : String(e) }); }
|
|
50
|
+
}
|
|
51
|
+
const functions = reading.items.filter((i) => i.kind === 'function');
|
|
52
|
+
const asSteps = functions.filter((f) => f.steps?.length && (f.stepsReadable ?? 0) >= 0.5);
|
|
53
|
+
const unread = [...decisions.filter((d) => !cards.some((c) => c.item === d)), ...functions.filter((f) => !asSteps.includes(f))];
|
|
54
|
+
const money = cards.filter((c) => c.model.inputs.some((i) => MONEY.test(i.id)));
|
|
55
|
+
const examples = [...money, ...cards.filter((c) => !money.includes(c))].slice(0, exampleLimit).map(({ item, model }) => ({
|
|
56
|
+
file: item.file, name: item.name, line: item.line,
|
|
57
|
+
reads: model.rules.map((r) => `${r.outcome} when ${r.conditions.map((c) => conditionText(model, c)).join(r.join === 'all' ? ' and ' : ' or ')}`).concat(`otherwise ${model.otherwise}`),
|
|
58
|
+
}));
|
|
59
|
+
return {
|
|
60
|
+
schema: THUNDER_REPO_SCHEMA,
|
|
61
|
+
source: gh && !isDir ? `github.com/${gh.owner}/${gh.repo}` : target,
|
|
62
|
+
commit: src.commit,
|
|
63
|
+
seconds: Math.round((Date.now() - started) / 100) / 10,
|
|
64
|
+
languages: reading.languages,
|
|
65
|
+
files: reading.files.length,
|
|
66
|
+
skipped: reading.skipped.length,
|
|
67
|
+
counts: { ...reading.counts, cards: cards.length, decisionsNotDrawn: decisions.length - cards.length, functionsAsSteps: asSteps.length, functionsAsStepsMostly: functions.filter((f) => (f.stepsReadable ?? 0) >= 0.8).length, unreadFunctions: unread.length, readerErrors: errors.length },
|
|
68
|
+
focus: [
|
|
69
|
+
...money.slice(0, 5).map(({ item }) => ({ kind: 'money', file: item.file, name: item.name, line: item.line, reason: 'Decides about money; read from code only, so a person should confirm it.' })),
|
|
70
|
+
...unread.slice(0, 5).map((i) => ({ kind: 'unreadable', file: i.file, name: i.name, line: i.line, reason: 'Thunder cannot fully read this yet: read the code.' })),
|
|
71
|
+
],
|
|
72
|
+
examples, errors,
|
|
73
|
+
readOnly: true,
|
|
74
|
+
note: 'Read from code by the Thunder code reader: no code was executed. Cards show what the code does today; a person decides whether that is what the team wants.',
|
|
75
|
+
...(keep ? { localPath: src.root } : {}),
|
|
76
|
+
};
|
|
77
|
+
} finally { if (!keep) src.cleanup(); }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A short Thunder Brief for the terminal. */
|
|
81
|
+
export function renderThunderRepo(r) {
|
|
82
|
+
const langs = Object.entries(r.languages).sort((a, b) => b[1] - a[1]).map(([l, n]) => `${l} ${n}`).join(', ');
|
|
83
|
+
const c = r.counts;
|
|
84
|
+
const out = [
|
|
85
|
+
`Thunder Brief: ${r.source}${r.commit ? ` @ ${r.commit.slice(0, 10)}` : ''}`,
|
|
86
|
+
`${r.files} files read (${langs || 'none'})${r.skipped ? `, ${r.skipped} skipped` : ''}, in ${r.seconds}s. Read-only: nothing was executed.`,
|
|
87
|
+
`${c.decision} decisions found, ${c.cards} drawn as Thunder rule cards. ${c.function} other functions, ${c.functionsAsSteps} read as Thunder steps (${c.functionsAsStepsMostly} at least 80% readable). ${c.unreadFunctions} need a person. ${c.route ?? 0} routes.`,
|
|
88
|
+
];
|
|
89
|
+
if (r.examples.length) {
|
|
90
|
+
out.push('', 'Rules read in Thunder (read from code; confirm with a person):');
|
|
91
|
+
for (const e of r.examples) { out.push(` ${e.file}:${e.line} ${spaced(e.name)}`); for (const line of e.reads) out.push(` ${line}`); }
|
|
92
|
+
}
|
|
93
|
+
if (r.focus.length) { out.push('', 'Thunder Focus (look here first):'); for (const f of r.focus) out.push(` [${f.kind}] ${f.file}:${f.line} ${spaced(f.name)}: ${f.reason}`); }
|
|
94
|
+
if (r.errors.length) { out.push('', `Reader errors (${r.errors.length}):`); for (const e of r.errors.slice(0, 5)) out.push(` ${e.file} ${e.name}: ${e.error}`); }
|
|
95
|
+
return out.join('\n');
|
|
96
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// thunderize-v1: a whole app written in Thunder Text (see src/thunderize.mjs).
|
|
2
|
+
export const THUNDERIZE_SCHEMA: 'thunderize-v1';
|
|
3
|
+
export const THUNDER_TEXT_EXT: '.thunder-text';
|
|
4
|
+
export interface ThunderizedFile {
|
|
5
|
+
path: string; language: string; out: string; text: string;
|
|
6
|
+
counts: { actions: number; rules: number; functions: number; notReadYet: number; failures: number };
|
|
7
|
+
items: { name: string; line: number; element: string; title: string; route?: string }[];
|
|
8
|
+
}
|
|
9
|
+
export function thunderizeFile(path: string, source: string, language?: string): ThunderizedFile;
|
|
10
|
+
export function thunderizeFiles(files: { path: string; source: string; size?: number }[], options?: { name?: string }): {
|
|
11
|
+
schema: 'thunderize-v1'; name: string; languages: string[]; index: string; files: ThunderizedFile[];
|
|
12
|
+
counts: { files: number; actions: number; rules: number; functions: number; notReadYet: number };
|
|
13
|
+
skipped: { path: string; reason: string }[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Thunderize: a whole app written in Thunder Text. Every readable file becomes a Thunder Text file beside a mirror of
|
|
2
|
+
// its path, and an index (APP.thunder-text) reads the app from the top: areas, files, actions, rules. Browser-safe:
|
|
3
|
+
// it takes [{ path, source }] and returns text; the CLI writes the files.
|
|
4
|
+
import { readCode } from './read.mjs';
|
|
5
|
+
import { readableLanguage } from './read-repo.mjs';
|
|
6
|
+
import { thunderText, visualFor } from './visual.mjs';
|
|
7
|
+
|
|
8
|
+
export const THUNDERIZE_SCHEMA = 'thunderize-v1';
|
|
9
|
+
export const THUNDER_TEXT_EXT = '.thunder-text';
|
|
10
|
+
|
|
11
|
+
const LANGUAGE_NAMES = { typescript: 'TypeScript', javascript: 'JavaScript', python: 'Python', go: 'Go', rust: 'Rust', csharp: 'C#', java: 'Java', kotlin: 'Kotlin', php: 'PHP', ruby: 'Ruby' };
|
|
12
|
+
|
|
13
|
+
/** One file in Thunder Text: a header, then every action, rule, and function in order, then how it can fail. */
|
|
14
|
+
export function thunderizeFile(path, source, language = readableLanguage(path)) {
|
|
15
|
+
const reading = readCode(source, { language, file: path });
|
|
16
|
+
const main = reading.items.filter((i) => i.kind === 'decision' || i.kind === 'function');
|
|
17
|
+
const failures = [...new Set(reading.items.filter((i) => i.kind === 'error').map((i) => i.name))];
|
|
18
|
+
const counts = { actions: 0, rules: 0, functions: 0, notReadYet: 0, failures: failures.length };
|
|
19
|
+
const parts = main.map((item) => {
|
|
20
|
+
const v = visualFor(item);
|
|
21
|
+
if (v.element === 'action') counts.actions++;
|
|
22
|
+
else if (v.element === 'decision') counts.rules++;
|
|
23
|
+
else if (v.element === 'not-read') counts.notReadYet++;
|
|
24
|
+
else counts.functions++;
|
|
25
|
+
return `# line ${item.line}${v.line === 'dashed' ? ' · not read yet' : ''}\n${thunderText(item).trimEnd()}`;
|
|
26
|
+
});
|
|
27
|
+
const header = `File ${path} (${LANGUAGE_NAMES[reading.language] || reading.language})\n` +
|
|
28
|
+
`Read from code by the Thunder compiler, no AI. ${summary(counts)}`;
|
|
29
|
+
const footer = failures.length ? `\nCan fail with: ${failures.join(', ')}` : '';
|
|
30
|
+
return { path, language: reading.language, out: `${path}${THUNDER_TEXT_EXT}`, counts, items: main.map((i) => ({ name: i.name, line: i.line, ...pick(visualFor(i)) })), text: `${header}\n\n${parts.join('\n\n')}${footer}\n` };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const pick = (v) => ({ element: v.element, title: v.title, ...(v.badge ? { route: v.badge.text } : {}) });
|
|
34
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
35
|
+
function summary(c) {
|
|
36
|
+
const bits = [c.actions && plural(c.actions, 'action'), c.rules && plural(c.rules, 'rule'), c.functions && plural(c.functions, 'function'), c.notReadYet && `${c.notReadYet} not read yet`].filter(Boolean);
|
|
37
|
+
return bits.length ? `${bits.join(', ')}.` : 'Nothing to read.';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A whole app in Thunder Text. Returns every file's Thunder Text and an index that reads the app top-down.
|
|
42
|
+
* Files Thunder cannot read (unsupported language, empty, or too large) are listed, never silently dropped.
|
|
43
|
+
*/
|
|
44
|
+
export function thunderizeFiles(files, { name = 'app' } = {}) {
|
|
45
|
+
const out = [], skipped = [];
|
|
46
|
+
for (const f of files) {
|
|
47
|
+
const language = readableLanguage(f.path);
|
|
48
|
+
if (!language) { skipped.push({ path: f.path, reason: 'not a language Thunder reads yet' }); continue; }
|
|
49
|
+
if (!f.source) { skipped.push({ path: f.path, reason: f.size ? 'too large to read' : 'empty' }); continue; }
|
|
50
|
+
try { out.push(thunderizeFile(f.path, f.source, language)); }
|
|
51
|
+
catch (e) { skipped.push({ path: f.path, reason: `could not be read: ${e.message}` }); }
|
|
52
|
+
}
|
|
53
|
+
out.sort((a, b) => a.path.localeCompare(b.path));
|
|
54
|
+
const total = { files: out.length, actions: 0, rules: 0, functions: 0, notReadYet: 0 };
|
|
55
|
+
for (const f of out) for (const k of ['actions', 'rules', 'functions', 'notReadYet']) total[k] += f.counts[k];
|
|
56
|
+
const langs = [...new Set(out.map((f) => LANGUAGE_NAMES[f.language] || f.language))].sort();
|
|
57
|
+
|
|
58
|
+
const areas = new Map();
|
|
59
|
+
for (const f of out) {
|
|
60
|
+
const area = f.path.includes('/') ? f.path.slice(0, f.path.lastIndexOf('/')) : '.';
|
|
61
|
+
if (!areas.has(area)) areas.set(area, []);
|
|
62
|
+
areas.get(area).push(f);
|
|
63
|
+
}
|
|
64
|
+
const lines = [
|
|
65
|
+
`App ${name}`,
|
|
66
|
+
` ${plural(total.files, 'file')} read in ${langs.join(', ') || 'no language'}: ${summary(total).replace(/\.$/, '')}.`,
|
|
67
|
+
' Read from code by the Thunder compiler, no AI. Each file has its own Thunder Text beside it.',
|
|
68
|
+
];
|
|
69
|
+
for (const [area, list] of areas) {
|
|
70
|
+
lines.push('', `Area ${area === '.' ? '(top level)' : area}`);
|
|
71
|
+
for (const f of list) {
|
|
72
|
+
const doors = f.items.filter((i) => i.element === 'action' || i.element === 'decision');
|
|
73
|
+
lines.push(` File ${f.path}: ${summary(f.counts)}`);
|
|
74
|
+
for (const d of doors) lines.push(` ${d.element === 'action' ? d.title : `Rule: ${d.title}`}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (skipped.length) {
|
|
78
|
+
lines.push('', 'Not read');
|
|
79
|
+
for (const s of skipped) lines.push(` ${s.path}: ${s.reason}`);
|
|
80
|
+
}
|
|
81
|
+
return { schema: THUNDERIZE_SCHEMA, name, counts: total, languages: langs, files: out, skipped, index: `${lines.join('\n')}\n` };
|
|
82
|
+
}
|
package/src/visual.d.mts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// thunder-visual-v1: the visual grammar of Thunder V1 (see src/visual.mjs and docs/spec.md).
|
|
2
|
+
import type { ReadItem, ReadStep } from './read.mjs';
|
|
3
|
+
|
|
4
|
+
export const VISUAL_SCHEMA: 'thunder-visual-v1';
|
|
5
|
+
export const PRINCIPLE: string;
|
|
6
|
+
export type ColorRole = 'structure' | 'question' | 'fact' | 'comparison' | 'amount' | 'outcome' | 'name' | 'failure' | 'pass' | 'fail' | 'unread';
|
|
7
|
+
export type ElementKind = 'app' | 'area' | 'file' | 'data-shape' | 'action' | 'decision' | 'function' | 'not-read' | 'error' | 'test' | 'event' | 'source';
|
|
8
|
+
export type Provenance = 'from-code' | 'confirmed' | 'authors-note' | 'ai-summary' | 'not-read';
|
|
9
|
+
export type Status = 'available' | 'partial' | 'planned';
|
|
10
|
+
|
|
11
|
+
export const FORMS: { id: 'picture' | 'text' | 'meaning' | 'source'; name: string; role: 'main' | 'detail' | 'model' | 'evidence'; says: string }[];
|
|
12
|
+
export const ZOOM: { level: 0 | 1 | 2 | 3 | 4 | 5; name: string; from: string; element: ElementKind; atlas: 'Z0' | 'Z1' | 'Z2' | 'Z3' | 'Z4' }[];
|
|
13
|
+
export const COLORS: Record<ColorRole, { hex: string; name: string; for: string }>;
|
|
14
|
+
export const LINES: { solid: string; dashed: string };
|
|
15
|
+
export const PROVENANCE: Record<Provenance, { label: string; line: 'solid' | 'dashed'; says: string }>;
|
|
16
|
+
export const STEP_MARKS: Record<ReadStep['kind'] | 'restates', { mark: string; label: string; color: ColorRole; show: 'words' | 'code'; line?: 'dashed' }>;
|
|
17
|
+
export const ELEMENTS: Record<ElementKind, { zoom: number; name: string; shape: string; status: Status; shows: string; text: string; badge?: string; mark?: string; color?: ColorRole; line?: 'dashed' }>;
|
|
18
|
+
export const LANGUAGES: Record<string, { name: string; status: Status; action: string; decision: string; doc: string; 'data-shape': string; event?: string; steps?: string }>;
|
|
19
|
+
export const RULES: string[];
|
|
20
|
+
|
|
21
|
+
export interface Visual {
|
|
22
|
+
element: ElementKind; shape: string; line: 'solid' | 'dashed'; title: string;
|
|
23
|
+
provenance: Provenance; mark?: string; color?: ColorRole; note?: string;
|
|
24
|
+
badge?: { kind: 'route'; text: string };
|
|
25
|
+
doc?: { text: string; provenance: 'authors-note' };
|
|
26
|
+
}
|
|
27
|
+
export function visualFor(item: ReadItem): Visual;
|
|
28
|
+
export function visualForStep(step: ReadStep): { mark: string; label: string; color: ColorRole; show: 'words' | 'code'; line: 'solid' | 'dashed'; text: string };
|
|
29
|
+
export function thunderText(item: ReadItem): string;
|
|
30
|
+
export type SymbolId = 'app' | 'area' | 'file' | 'thing' | 'data' | 'record' | 'choices' | 'action' | 'rule' | 'steps' | 'setup' | 'stop' | 'not-read';
|
|
31
|
+
export const SYMBOLS: Record<SymbolId, { name: string; says: string; color: ColorRole; paths: string[]; circles?: [number, number, number][]; fill?: boolean; dashed?: boolean; beginner?: boolean; group?: string }>;
|
|
32
|
+
export type Does = 'start' | 'find' | 'keep-only' | 'check' | 'decide' | 'calculate' | 'save' | 'send' | 'ask' | 'repeat' | 'answer' | 'stop' | 'do' | 'code';
|
|
33
|
+
export const DOES: Record<Does, { label: string; mark: string; color: ColorRole; dashed?: boolean; symbol?: SymbolId }>;
|
|
34
|
+
export const BEGINNER: SymbolId[];
|
|
35
|
+
export const THUNDER_VISUAL: {
|
|
36
|
+
schema: 'thunder-visual-v1'; principle: string; forms: typeof FORMS; zoom: typeof ZOOM; colors: typeof COLORS; lines: typeof LINES;
|
|
37
|
+
provenance: typeof PROVENANCE; steps: typeof STEP_MARKS; elements: typeof ELEMENTS; languages: typeof LANGUAGES; rules: string[];
|
|
38
|
+
symbols: typeof SYMBOLS; does: typeof DOES; beginner: SymbolId[];
|
|
39
|
+
};
|
|
40
|
+
export function thunderTokens(line: string): { text: string; role: ColorRole | null }[];
|