@skillstech/thunderlang 1.1.0 → 1.3.0
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 +212 -0
- package/README.md +4 -1
- package/dist/core.cjs +2080 -278
- package/dist/index.cjs +12742 -10943
- package/dist/learn.cjs +12976 -3598
- package/package.json +2 -2
- package/src/cli-home.mjs +242 -0
- package/src/cli.mjs +135 -41
- package/src/core/ThunderRuntime.cs +1367 -0
- package/src/core/check.mjs +158 -2
- package/src/core/cli.mjs +208 -17
- package/src/core/csharp-run.mjs +184 -0
- package/src/core/diagnostics.mjs +13 -0
- package/src/core/engine-core.mjs +855 -0
- package/src/core/engine-values.mjs +1054 -0
- package/src/core/engine-worker.mjs +15 -0
- package/src/core/engine.mjs +63 -0
- package/src/core/format.mjs +191 -3
- package/src/core/go-run.mjs +106 -0
- package/src/core/index.mjs +3 -1
- package/src/core/java/thunder/T.java +6 -0
- package/src/core/java/thunder/ThunderRuntime.java +1374 -0
- package/src/core/java-run.mjs +89 -0
- package/src/core/parser.mjs +331 -5
- package/src/core/project.mjs +43 -8
- package/src/core/react-run.mjs +96 -0
- package/src/core/runtime-go/thunder_runtime.go +3038 -0
- package/src/core/runtime-react.mjs +133 -0
- package/src/core/runtime-typescript.mjs +119 -0
- package/src/core/rust/thunder_runtime.rs +1645 -0
- package/src/core/rust-run.mjs +192 -0
- package/src/core/screen-values.mjs +30 -0
- package/src/core/target-csharp.mjs +484 -0
- package/src/core/target-go.mjs +555 -0
- package/src/core/target-java.mjs +587 -0
- package/src/core/target-python.mjs +2 -1
- package/src/core/target-react.mjs +270 -0
- package/src/core/target-rust.mjs +534 -0
- package/src/core/target-typescript.mjs +466 -0
- package/src/core/typescript-run.mjs +114 -0
- package/src/core.d.ts +18 -0
- package/src/core.mjs +1 -0
- package/src/emit.mjs +1 -1
- package/src/faithful.mjs +30 -0
- package/src/learn-lessons.mjs +245 -1
- package/src/learn.d.mts +8 -0
- package/src/learn.mjs +40 -4
- package/src/libraries.mjs +10 -3
- package/src/model.mjs +50 -8
- package/src/read-level.mjs +192 -0
- package/src/read-repo-fs.mjs +3 -1
- package/src/read.mjs +28 -5
- package/src/replay-cli.mjs +123 -0
- package/src/say-less.mjs +152 -11
- package/src/screens.mjs +833 -0
- package/src/steps.mjs +430 -19
- package/src/term.mjs +132 -0
- package/src/try-cli.mjs +225 -0
- package/src/why-cli.mjs +17 -7
- package/src/why.d.mts +17 -7
- package/src/why.mjs +114 -33
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skillstech/thunderlang",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Thunder
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Thunder™, the human programming language: the deterministic ThunderLang™ compiler, CLI, and Language Server. No AI required. Reads code in seventeen languages into Thunder, changes TypeScript, JavaScript, Python, and Go code from Thunder with a proof, compiles rules to six languages, and executes them: 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",
|
|
7
7
|
"types": "./src/index.d.ts",
|
package/src/cli-home.mjs
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// The human front door of the thunder CLI: the short home screen, help for one command, typo suggestions,
|
|
2
|
+
// a friendly message when a Core command runs outside a project, and `thunder doctor`.
|
|
3
|
+
// Every existing command, flag, exit code, and JSON output is unchanged; this file only adds words around them.
|
|
4
|
+
import { existsSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
5
|
+
import { delimiter, join, relative, resolve } from 'node:path';
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import { homedir } from 'node:os';
|
|
8
|
+
import { findPython, findProjectRoot } from './core/project.mjs';
|
|
9
|
+
import { paint, useColor } from './term.mjs';
|
|
10
|
+
|
|
11
|
+
/** The commands `thunder` understands besides those listed in the full help (kept in sync by a test). */
|
|
12
|
+
export const EXTRA_COMMANDS = ['doctor', 'completion', 'plain', 'ai', 'coverage', 'completions', 'hover', 'format', 'help', 'version', 'mission', 'why', 'trace', 'graph', 'proof', 'build'];
|
|
13
|
+
|
|
14
|
+
/** Every command name: the ones the full help lists, plus EXTRA_COMMANDS. */
|
|
15
|
+
export function knownCommands(fullHelp) {
|
|
16
|
+
const listed = [...fullHelp.matchAll(/^ {2}([a-z][a-z0-9-]*(?: \| [a-z][a-z0-9-]*)*)(?=[\s<[]|$)/gm)].flatMap((m) => m[1].split(' | '));
|
|
17
|
+
return [...new Set([...listed, ...EXTRA_COMMANDS])].sort();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The home screen: the few things most people need, with real examples. */
|
|
21
|
+
export function homeText(version, commandCount) {
|
|
22
|
+
return `⚡ Thunder™ ${version}: programming, made human.
|
|
23
|
+
|
|
24
|
+
Start here
|
|
25
|
+
thunder new hello create a program
|
|
26
|
+
thunder run hello run it
|
|
27
|
+
thunder test hello check that it works
|
|
28
|
+
thunder read app.py understand code you already have
|
|
29
|
+
thunder try rules.py try a rule with your own values: the answer, and why
|
|
30
|
+
thunder why run.json see what an AI agent did, and why
|
|
31
|
+
|
|
32
|
+
More
|
|
33
|
+
thunder help <command> help for one command, like: thunder help read
|
|
34
|
+
thunder help --all all ${commandCount} commands
|
|
35
|
+
thunder doctor check that your computer is ready
|
|
36
|
+
thunder completion zsh press Tab to complete commands (also bash, fish)
|
|
37
|
+
|
|
38
|
+
Programs you write in Thunder run as Python today. Docs: https://thunderlang.dev/docs`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The full help's lines for one command (its line and the indented lines under it), or null. */
|
|
42
|
+
export function helpFor(cmd, fullHelp) {
|
|
43
|
+
const lines = fullHelp.split('\n');
|
|
44
|
+
const out = [];
|
|
45
|
+
let section = null;
|
|
46
|
+
for (let i = 0; i < lines.length; i++) {
|
|
47
|
+
const l = lines[i];
|
|
48
|
+
if (/^\S/.test(l) && !l.startsWith('usage')) section = l.trim();
|
|
49
|
+
const m = l.match(/^ {2}([a-z][a-z0-9-]*(?: \| [a-z][a-z0-9-]*)*)/);
|
|
50
|
+
if (m && m[1].split(' | ').includes(cmd)) {
|
|
51
|
+
if (!out.length && section) out.push(section);
|
|
52
|
+
out.push(l);
|
|
53
|
+
while (lines[i + 1] && /^ {6,}\S/.test(lines[i + 1])) out.push(lines[++i]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out.length ? out.join('\n') : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Edit distance, for "did you mean". */
|
|
60
|
+
function distance(a, b) {
|
|
61
|
+
const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
|
62
|
+
for (let j = 1; j <= b.length; j++) d[0][j] = j;
|
|
63
|
+
for (let i = 1; i <= a.length; i++) for (let j = 1; j <= b.length; j++) {
|
|
64
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
65
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
66
|
+
}
|
|
67
|
+
return d[a.length][b.length];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Commands close to a mistyped one, closest first. */
|
|
71
|
+
export function suggest(word, known) {
|
|
72
|
+
const w = String(word).toLowerCase();
|
|
73
|
+
const limit = w.length <= 4 ? 1 : 2;
|
|
74
|
+
const scored = known.map((k) => [k, distance(w, k)]).filter(([, n]) => n <= limit);
|
|
75
|
+
const best = Math.min(...scored.map(([, n]) => n));
|
|
76
|
+
return scored.filter(([, n]) => n === best).map(([k]) => k).sort().slice(0, 3);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function unknownCommandText(cmd, known) {
|
|
80
|
+
const s = suggest(cmd, known);
|
|
81
|
+
return `thunder: there is no command "${cmd}".${s.length ? ` Did you mean ${s.map((x) => `thunder ${x}`).join(' or ')}?` : ''}\nSee the main commands with: thunder help`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Thunder Core projects (folders with thunder.toml) up to two levels below `dir`. */
|
|
85
|
+
export function nearbyProjects(dir) {
|
|
86
|
+
const found = [];
|
|
87
|
+
const walk = (d, depth) => {
|
|
88
|
+
let entries = [];
|
|
89
|
+
try { entries = readdirSync(d, { withFileTypes: true }); } catch { return; }
|
|
90
|
+
for (const e of entries) {
|
|
91
|
+
if (!e.isDirectory() || e.name.startsWith('.') || e.name === 'node_modules' || e.name === 'generated') continue;
|
|
92
|
+
const p = join(d, e.name);
|
|
93
|
+
if (existsSync(join(p, 'thunder.toml'))) found.push(p);
|
|
94
|
+
else if (depth < 2) walk(p, depth + 1);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
walk(dir, 1);
|
|
98
|
+
return found.sort();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** What to say when a Core command (run, test, build, check) is given no file outside a project. */
|
|
102
|
+
export function noProjectText(cmd, cwd) {
|
|
103
|
+
const near = nearbyProjects(cwd);
|
|
104
|
+
const L = [`thunder ${cmd}: there is no Thunder project in this folder.`, '', `You're in: ${cwd}`];
|
|
105
|
+
if (near.length) {
|
|
106
|
+
L.push('', near.length === 1 ? 'There is one here:' : 'There are some here:');
|
|
107
|
+
for (const p of near.slice(0, 5)) L.push(` thunder ${cmd} ${relative(cwd, p)}`);
|
|
108
|
+
} else {
|
|
109
|
+
L.push('', 'Make one with:', ' thunder new hello', ` thunder ${cmd} hello`);
|
|
110
|
+
}
|
|
111
|
+
L.push('', '(For a mission file, name it: thunder ' + cmd + ' <file>.thunder)');
|
|
112
|
+
return L.join('\n');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ── thunder completion ────────────────────────────────────────────────────────────────────────────────────────
|
|
116
|
+
|
|
117
|
+
/** A shell completion script: command names first, then files. */
|
|
118
|
+
export function completionScript(shell, commands) {
|
|
119
|
+
const words = commands.join(' ');
|
|
120
|
+
if (shell === 'bash') return `# thunder completion for bash. Add to ~/.bashrc: eval "$(thunder completion bash)"
|
|
121
|
+
_thunder() {
|
|
122
|
+
local cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
123
|
+
if [ "$COMP_CWORD" -eq 1 ]; then COMPREPLY=( $(compgen -W "${words}" -- "$cur") ); fi
|
|
124
|
+
}
|
|
125
|
+
complete -o default -F _thunder thunder`;
|
|
126
|
+
if (shell === 'zsh') return `# thunder completion for zsh. Add to ~/.zshrc: eval "$(thunder completion zsh)"
|
|
127
|
+
(( $+functions[compdef] )) || { autoload -Uz compinit && compinit }
|
|
128
|
+
_thunder() { if (( CURRENT == 2 )); then compadd -- ${words}; else _files; fi }
|
|
129
|
+
compdef _thunder thunder`;
|
|
130
|
+
if (shell === 'fish') return `# thunder completion for fish. Save as ~/.config/fish/completions/thunder.fish: thunder completion fish > ~/.config/fish/completions/thunder.fish
|
|
131
|
+
complete -c thunder -n "__fish_use_subcommand" -a "${words}"`;
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function completionMain(argv, commands) {
|
|
136
|
+
const shell = argv[0];
|
|
137
|
+
const s = completionScript(shell, commands);
|
|
138
|
+
if (!s) { console.error(`thunder completion: name your shell: thunder completion zsh, bash, or fish.${shell ? ` (There is no "${shell}".)` : ''}`); return 2; }
|
|
139
|
+
console.log(s);
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ── thunder doctor ────────────────────────────────────────────────────────────────────────────────────────────
|
|
144
|
+
|
|
145
|
+
const quiet = (cmd, args) => {
|
|
146
|
+
try {
|
|
147
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8', timeout: 4000 });
|
|
148
|
+
if (r.error || r.status !== 0) return null;
|
|
149
|
+
return `${r.stdout || ''}${r.stderr || ''}`.trim();
|
|
150
|
+
} catch { return null; }
|
|
151
|
+
};
|
|
152
|
+
const firstVersion = (s) => (s && s.match(/\d+\.\d+(\.\d+)?/)?.[0]) || null;
|
|
153
|
+
|
|
154
|
+
function onPath(name) {
|
|
155
|
+
const hits = [];
|
|
156
|
+
for (const dir of String(process.env.PATH || '').split(delimiter)) {
|
|
157
|
+
if (!dir) continue;
|
|
158
|
+
const p = join(dir, name);
|
|
159
|
+
try { if (statSync(p).isFile()) hits.push(p); } catch { /* not here */ }
|
|
160
|
+
}
|
|
161
|
+
return hits;
|
|
162
|
+
}
|
|
163
|
+
const real = (p) => { try { return realpathSync(p); } catch { return p; } };
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Check this computer: offline, nothing installed or changed. Returns { ok, checks, optional, project }.
|
|
167
|
+
* `ok` is false only when something needed to write and run Thunder programs is missing.
|
|
168
|
+
*/
|
|
169
|
+
export function doctor({ version, cliPath, cwd = process.cwd(), env = process.env } = {}) {
|
|
170
|
+
const checks = [];
|
|
171
|
+
const add = (ok, what, detail, fix) => checks.push({ ok, what, ...(detail ? { detail } : {}), ...(fix ? { fix } : {}) });
|
|
172
|
+
|
|
173
|
+
add(true, `Thunder ${version}`, cliPath ? real(cliPath) : null);
|
|
174
|
+
|
|
175
|
+
const nodeMajor = Number(process.versions.node.split('.')[0]);
|
|
176
|
+
add(nodeMajor >= 18, `Node.js ${process.versions.node}`, 'Thunder needs Node.js 18 or newer', nodeMajor >= 18 ? null : 'Install Node.js 18 or newer from https://nodejs.org');
|
|
177
|
+
|
|
178
|
+
const py = findPython();
|
|
179
|
+
if (py.error) add(false, 'Python 3.10 or newer', 'Programs you write in Thunder run with Python', py.error);
|
|
180
|
+
else add(true, `Python ${py.version}`, `runs the programs you write in Thunder; found as ${py.cmd}`);
|
|
181
|
+
|
|
182
|
+
const hits = onPath('thunder');
|
|
183
|
+
const mine = cliPath ? real(cliPath) : null;
|
|
184
|
+
if (!hits.length) add(false, 'thunder is not on your PATH', 'A new terminal may say "command not found: thunder"', 'Install it for this shell: npm install -g @skillstech/thunderlang');
|
|
185
|
+
else if (mine && !hits.some((h) => real(h) === mine)) add('warn', 'Another thunder comes first on your PATH', real(hits[0]), 'Check which one you want with: which -a thunder');
|
|
186
|
+
else add(true, 'thunder is on your PATH');
|
|
187
|
+
|
|
188
|
+
// nvm installs global commands per Node version: switching versions (an .nvmrc in a folder) can lose `thunder`.
|
|
189
|
+
const nvmDir = env.NVM_DIR || join(homedir(), '.nvm');
|
|
190
|
+
const versionsDir = join(nvmDir, 'versions', 'node');
|
|
191
|
+
if (existsSync(versionsDir)) {
|
|
192
|
+
let versions = [];
|
|
193
|
+
try { versions = readdirSync(versionsDir).filter((v) => /^v\d/.test(v)); } catch { /* unreadable */ }
|
|
194
|
+
const missing = versions.filter((v) => !existsSync(join(versionsDir, v, 'bin', 'thunder')));
|
|
195
|
+
if (missing.length) {
|
|
196
|
+
add('warn', `Thunder isn't installed for Node ${missing.join(', ')}`,
|
|
197
|
+
'When your shell switches to one of these (nvm, .nvmrc), "thunder" will say "command not found"',
|
|
198
|
+
`Install it there too: ${missing.map((v) => `nvm exec ${v.slice(1)} npm install -g @skillstech/thunderlang`).join('; ')}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const root = findProjectRoot(cwd);
|
|
203
|
+
const project = root
|
|
204
|
+
? { in: true, root, say: `You're in the Thunder project ${relative(cwd, root) || '.'}: thunder run` }
|
|
205
|
+
: (() => { const near = nearbyProjects(cwd); return { in: false, nearby: near, say: near.length ? `Not in a Thunder project. Nearby: ${near.slice(0, 3).map((p) => `thunder run ${relative(cwd, p)}`).join(', ')}` : 'Not in a Thunder project. Make one: thunder new hello' }; })();
|
|
206
|
+
|
|
207
|
+
// Only needed to compile rules to these languages (thunder gen / test --target).
|
|
208
|
+
const optional = [
|
|
209
|
+
['Java', 'javac', ['-version']],
|
|
210
|
+
['.NET (C#)', 'dotnet', ['--version']],
|
|
211
|
+
['Go', 'go', ['version']],
|
|
212
|
+
['Rust', 'rustc', ['--version']],
|
|
213
|
+
['TypeScript (tsc)', 'tsc', ['--version']],
|
|
214
|
+
].map(([name, cmd, args]) => { const v = firstVersion(quiet(cmd, args)); return { name, ok: !!v, ...(v ? { version: v } : {}) }; });
|
|
215
|
+
|
|
216
|
+
return { ok: checks.every((c) => c.ok !== false), checks, project, optional };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function renderDoctor(r) {
|
|
220
|
+
const mark = (ok) => (ok === true ? '✓' : ok === 'warn' ? '!' : '✗');
|
|
221
|
+
const L = ['Thunder™ doctor', ''];
|
|
222
|
+
for (const c of r.checks) {
|
|
223
|
+
L.push(` ${mark(c.ok)} ${c.what}${c.detail ? ` (${c.detail})` : ''}`);
|
|
224
|
+
if (c.fix && c.ok !== true) L.push(` ${c.fix}`);
|
|
225
|
+
}
|
|
226
|
+
L.push(` · ${r.project.say}`);
|
|
227
|
+
L.push('', 'Optional: only to compile rules to these languages');
|
|
228
|
+
L.push(` ${r.optional.map((o) => `${o.ok ? '✓' : '·'} ${o.name}${o.version ? ` ${o.version}` : ''}`).join(' ')}`);
|
|
229
|
+
L.push('', r.ok
|
|
230
|
+
? (r.checks.some((c) => c.ok === 'warn') ? 'Ready to write and run Thunder programs. The ! lines are worth fixing.' : 'Ready to write and run Thunder programs.')
|
|
231
|
+
: 'Not ready yet: fix the ✗ lines above, then run thunder doctor again.');
|
|
232
|
+
return L.join('\n');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function doctorMain(argv, { version, cliPath }) {
|
|
236
|
+
const json = argv.includes('--json');
|
|
237
|
+
const bad = argv.find((a) => a !== '--json');
|
|
238
|
+
if (bad) { console.error(`thunder doctor: there is no option ${bad}. It takes only --json.`); return 2; }
|
|
239
|
+
const r = doctor({ version, cliPath, cwd: resolve(process.cwd()) });
|
|
240
|
+
console.log(json ? JSON.stringify(r, null, 2) : paint(renderDoctor(r)));
|
|
241
|
+
return r.ok ? 0 : 1;
|
|
242
|
+
}
|
package/src/cli.mjs
CHANGED
|
@@ -49,9 +49,15 @@ import { verifyDiff } from './verify-diff.mjs';
|
|
|
49
49
|
import { verifyRun, executedText, mergeTraces } from './executed.mjs';
|
|
50
50
|
import { runtimeOverlay, runtimeText, fromTrace, fromStack, fromLogs, fromOtlp, parseStacks, explainError, countWords } from './running.mjs';
|
|
51
51
|
import { thunderModel } from './model.mjs';
|
|
52
|
+
import { LEVELS, readLevel, renderLevel, findFocus, nearestLevel } from './read-level.mjs';
|
|
52
53
|
import { traceMain } from './trace-cli.mjs';
|
|
53
54
|
import { whyMain } from './why-cli.mjs';
|
|
55
|
+
import { tryMain } from './try-cli.mjs';
|
|
56
|
+
import { replayMain } from './replay-cli.mjs';
|
|
57
|
+
import { homeText, helpFor, knownCommands, unknownCommandText, noProjectText, doctorMain, completionMain } from './cli-home.mjs';
|
|
58
|
+
import { paint, paintHelp, paintThunder, useColor } from './term.mjs';
|
|
54
59
|
import { coreMain } from './core/cli.mjs';
|
|
60
|
+
import { findProjectRoot } from './core/project.mjs';
|
|
55
61
|
import { pythonToCore } from './core/from-python.mjs';
|
|
56
62
|
import { guardSummary } from './guard.mjs';
|
|
57
63
|
import { draftIntent } from './draft.mjs';
|
|
@@ -333,6 +339,8 @@ function parseArgs(argv) {
|
|
|
333
339
|
else if (a === '--role') args.role = argv[++i];
|
|
334
340
|
else if (a === '--note') args.note = argv[++i];
|
|
335
341
|
else if (a === '--search') args.search = argv[++i];
|
|
342
|
+
else if (a === '--level') args.level = argv[++i] ?? '';
|
|
343
|
+
else if (a === '--focus') args.focus = argv[++i];
|
|
336
344
|
else if (a === '--kind') args.kind = (argv[++i] || '').split(',').map((k) => k.trim()).filter(Boolean);
|
|
337
345
|
else if (a === '--in') args.inLang = argv[++i];
|
|
338
346
|
else if (a === '--answer') args.answer = argv[++i];
|
|
@@ -455,17 +463,62 @@ function printDiagnostics(diags) {
|
|
|
455
463
|
return errors;
|
|
456
464
|
}
|
|
457
465
|
|
|
458
|
-
const HELP =
|
|
466
|
+
const HELP = `⚡ Thunder™: every command. Most people only need the first four groups.
|
|
459
467
|
|
|
460
|
-
|
|
468
|
+
usage: thunder <command> [file] [options] Help for one command: thunder help <command>
|
|
461
469
|
|
|
462
|
-
|
|
463
|
-
|
|
470
|
+
Start
|
|
471
|
+
doctor [--json] is this computer ready? Thunder, Node.js, Python, PATH, and optional toolchains (offline)
|
|
472
|
+
completion <zsh|bash|fish> a script that completes thunder commands when you press Tab
|
|
464
473
|
|
|
465
474
|
Write and run programs (Thunder Core, docs/core.md)
|
|
466
475
|
new <dir> create a Thunder Core project: thunder.toml, src/main.thunder, tests/
|
|
467
476
|
run | build | test | check | format in a project (a folder with thunder.toml), or on a .thunder file in one;
|
|
468
|
-
add --core for a single file with no project. run/test need Python 3.10
|
|
477
|
+
add --core for a single file with no project. run/test need Python 3.10+, or add
|
|
478
|
+
--engine thunder to run them on the Thunder engine (no Python; programs that Use a
|
|
479
|
+
Python module are refused there). --target typescript compiles to TypeScript instead
|
|
480
|
+
(generated/typescript/; runs on Node 22.6+, or with the typescript package);
|
|
481
|
+
--target csharp compiles to C# (generated/csharp/; builds and runs with the .NET 8+ SDK)
|
|
482
|
+
--target go compiles to Go (generated/go/; needs the go toolchain to run)
|
|
483
|
+
--target java compiles to Java (generated/java/; runs with a JDK 17+)
|
|
484
|
+
|
|
485
|
+
Read and understand code
|
|
486
|
+
read <file|dir> [--search q] [--kind decision,function,error,test] [--in <lang>] [--from <lang>] [--json]
|
|
487
|
+
read <file|dir> --level big-picture|flow|details|text|original [--focus "<action or rule>"] [--json]
|
|
488
|
+
read at one depth, from the same model OpenThunder shows: the big picture, one action's flow,
|
|
489
|
+
its exact details, its Thunder Text, or the original lines
|
|
490
|
+
read <file.py> --as-core the same code as Thunder Core you can edit and run (Python for now); lines it cannot say exactly are marked
|
|
491
|
+
for a folder also: [--answer <Outcome>] [--input <name>] [--lang go,rust] [--path <prefix>] [--limit n]
|
|
492
|
+
--promote <decision> [--out <file>] turn a recovered decision into a contract with starter examples
|
|
493
|
+
read code you don't know: its decision rules as ThunderLang + plain English,
|
|
494
|
+
optionally rewritten in a language you know (--in typescript|python|go|rust|csharp|java)
|
|
495
|
+
replay <recording.json> [--step n] [--json] the Time Machine: step through a run recorded with thunder run --record
|
|
496
|
+
try <file> [--focus "<rule>"] [--with "name=value, …"] [--json] try a rule from your code with your own values: the answer and why (rules only; nothing changes)
|
|
497
|
+
why <run.json> [--step n] [--json] what an AI agent did and why it stopped, in plain words, from its OpenTelemetry record
|
|
498
|
+
same <old> <new> [--json] does the new code mean the same as the old? (files or folders, any languages; rules are run on every edge case)
|
|
499
|
+
review <base-ref> [head-ref] [--format markdown|json] [--paths <glob,...>] [--out <file>]
|
|
500
|
+
review in Thunder: what changed in meaning between two git commits (head: the working tree
|
|
501
|
+
when omitted), as Markdown for a pull request comment; read from git, no network
|
|
502
|
+
trace <folder…> [--json] [--out f] Thunder Trace: routes, requests, and events linked across repositories, cited repo@sha:file:line
|
|
503
|
+
trace impact <thing | --diff [--base ref]> <folder…> what a change can affect in other repositories (one hop, ranked by risk)
|
|
504
|
+
repo <owner/repo | github url | folder> [--json] [--max-files n] Thunder a whole repository (read-only; nothing is executed)
|
|
505
|
+
thunderize <folder | owner/repo> [--out <dir>] [--json] the whole app in Thunder Text: one .thunder-text per file + APP.thunder-text
|
|
506
|
+
|
|
507
|
+
Change code
|
|
508
|
+
write <file> --edit '<json>' [--edit …] [--also <file>] [--apply] [--test "<cmd>"] [--candidate <file>] [--json]
|
|
509
|
+
Writing in Thunder: change a step, question, Stop, input, or function in Thunder; the code is
|
|
510
|
+
written as a minimal patch (TS/JS, Python, Go) and proven (the edited steps mean exactly
|
|
511
|
+
the edit; everything else means the same). Dry run by default; --apply saves; --test runs a
|
|
512
|
+
command on the changed code. Other cases print an instruction for an AI coding agent;
|
|
513
|
+
--candidate checks code it wrote (labeled AI-written).
|
|
514
|
+
write <file> --decision <name> --rule <n|otherwise> [--when "<condition>"] [--answer <Outcome>] [--write] [--json]
|
|
515
|
+
Thunder write: change a number, comparison, text value, or answer in a recovered rule;
|
|
516
|
+
previews the exact code change and the cases whose answer changes; --write saves it
|
|
517
|
+
|
|
518
|
+
────────────────────────────────────────────────────────────────────────
|
|
519
|
+
Advanced: rules and missions (ThunderLang™ intent files), proofs, and tools for editors and CI.
|
|
520
|
+
The flow: author intent, inspect it, run and prove it, then keep real code aligned with it.
|
|
521
|
+
thunder mission <Name> <command> run any command on a mission by name
|
|
469
522
|
|
|
470
523
|
Author
|
|
471
524
|
init [Name] scaffold a runnable starter mission (Name.thunder) [alias: new --mission Name]
|
|
@@ -535,31 +588,7 @@ Graph & IR
|
|
|
535
588
|
human <file> [--json | --format source] experimental compact authoring and a decision reading view
|
|
536
589
|
--version print the Thunder compiler version
|
|
537
590
|
anchor <file> [--json] show every Thunder step with its exact place in the file, and line coverage
|
|
538
|
-
write <file> --edit '<json>' [--edit …] [--also <file>] [--apply] [--test "<cmd>"] [--candidate <file>] [--json]
|
|
539
|
-
Writing in Thunder: change a step, question, Stop, input, or function in Thunder; the code is
|
|
540
|
-
written as a minimal patch (TS/JS, Python, Go) and proven (the edited steps mean exactly
|
|
541
|
-
the edit; everything else means the same). Dry run by default; --apply saves; --test runs a
|
|
542
|
-
command on the changed code. Other cases print an instruction for an AI coding agent;
|
|
543
|
-
--candidate checks code it wrote (labeled AI-written).
|
|
544
|
-
write <file> --decision <name> --rule <n|otherwise> [--when "<condition>"] [--answer <Outcome>] [--write] [--json]
|
|
545
|
-
Thunder write: change a number, comparison, text value, or answer in a recovered rule;
|
|
546
|
-
previews the exact code change and the cases whose answer changes; --write saves it
|
|
547
|
-
repo <owner/repo | github url | folder> [--json] [--max-files n] Thunder a whole repository (read-only; nothing is executed)
|
|
548
|
-
trace <folder…> [--json] [--out f] Thunder Trace: routes, requests, and events linked across repositories, cited repo@sha:file:line
|
|
549
|
-
why <run.json> [--step n] [--json] what an AI agent did and why it stopped, in plain words, from its OpenTelemetry record
|
|
550
|
-
trace impact <thing | --diff [--base ref]> <folder…> what a change can affect in other repositories (one hop, ranked by risk)
|
|
551
|
-
thunderize <folder | owner/repo> [--out <dir>] [--json] the whole app in Thunder Text: one .thunder-text per file + APP.thunder-text
|
|
552
|
-
review <base-ref> [head-ref] [--format markdown|json] [--paths <glob,...>] [--out <file>]
|
|
553
|
-
review in Thunder: what changed in meaning between two git commits (head: the working tree
|
|
554
|
-
when omitted), as Markdown for a pull request comment; read from git, no network
|
|
555
|
-
same <old> <new> [--json] does the new code mean the same as the old? (files or folders, any languages; rules are run on every edge case)
|
|
556
591
|
text <file> [--json | --format source] experimental Thunder Text rule (.thunder-plain): run its examples [alias: plain]
|
|
557
|
-
read <file|dir> [--search q] [--kind decision,function,error,test] [--in <lang>] [--from <lang>] [--json]
|
|
558
|
-
read <file.py> --as-core the same code as Thunder Core you can edit and run (Python for now); lines it cannot say exactly are marked
|
|
559
|
-
for a folder also: [--answer <Outcome>] [--input <name>] [--lang go,rust] [--path <prefix>] [--limit n]
|
|
560
|
-
--promote <decision> [--out <file>] turn a recovered decision into a contract with starter examples
|
|
561
|
-
read code you don't know: its decision rules as ThunderLang + plain English,
|
|
562
|
-
optionally rewritten in a language you know (--in typescript|python|go|rust|csharp|java)
|
|
563
592
|
graph <file> [--safe] the canonical Intent Graph (intent-graph-v1); --safe = display-safe on stdout
|
|
564
593
|
migrate <graph.json> [--to <version>] upgrade a persisted graph
|
|
565
594
|
validate <graph.json> [--json] check a graph is canonical (anti-fork)
|
|
@@ -585,19 +614,38 @@ function main() {
|
|
|
585
614
|
const args = parseArgs(restArgv);
|
|
586
615
|
const file = args._[0];
|
|
587
616
|
if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
|
|
588
|
-
console.log(`thunder ${COMPILER_VERSION} (the Thunder compiler, also called ThunderLang)`);
|
|
617
|
+
console.log(`thunder ${COMPILER_VERSION} (the Thunder™ compiler, also called ThunderLang™)`);
|
|
589
618
|
return;
|
|
590
619
|
}
|
|
620
|
+
const known = [...new Set([...knownCommands(HELP), ...Object.keys(VIEWS)])].sort();
|
|
591
621
|
if (!cmd || cmd === 'help' || cmd === '--help' || cmd === '-h') {
|
|
592
|
-
|
|
593
|
-
|
|
622
|
+
// `thunder help <command>`: just that command's lines from the full list.
|
|
623
|
+
const topic = cmd === 'help' ? restArgv.find((x) => !x.startsWith('-')) : null;
|
|
624
|
+
if (topic) {
|
|
625
|
+
const h = helpFor(topic, HELP);
|
|
626
|
+
if (h) { console.log(`${paintHelp(h)}\n\n${paint('All commands: thunder help --all')}`); process.exitCode = 0; }
|
|
627
|
+
else { console.error(paint(unknownCommandText(topic, known), useColor(process.stderr))); process.exitCode = 2; }
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
// The short home screen first; every command with --all. Exit codes are unchanged (2 with no command at all).
|
|
631
|
+
// exitCode, not exit(): the full help is longer than a pipe's buffer, and exit() would cut it off when piped.
|
|
632
|
+
console.log(restArgv.includes('--all') ? paintHelp(HELP) : paint(homeText(COMPILER_VERSION, known.length)));
|
|
594
633
|
process.exitCode = cmd ? 0 : 2;
|
|
595
634
|
return;
|
|
596
635
|
}
|
|
636
|
+
// thunder doctor: is this computer ready? Offline; changes nothing (src/cli-home.mjs).
|
|
637
|
+
if (cmd === 'completion') { process.exitCode = completionMain(restArgv, known); return; }
|
|
638
|
+
if (cmd === 'doctor') { process.exitCode = doctorMain(restArgv, { version: COMPILER_VERSION, cliPath: process.argv[1] }); return; }
|
|
639
|
+
// A command Thunder doesn't have (and not a file): say so, and suggest the closest ones, instead of failing later.
|
|
640
|
+
if (!known.includes(cmd) && !cmd.startsWith('-') && !existsSync(cmd)) { console.error(paint(unknownCommandText(cmd, known), useColor(process.stderr))); process.exitCode = 2; return; }
|
|
597
641
|
// Thunder Trace: links between repositories and what a change can affect (src/trace-cli.mjs).
|
|
598
642
|
if (cmd === 'trace') { process.exitCode = traceMain(restArgv); return; }
|
|
599
643
|
// Thunder Why: an AI agent's run explained in plain words, from its OpenTelemetry record (src/why-cli.mjs).
|
|
600
644
|
if (cmd === 'why') { process.exitCode = whyMain(restArgv); return; }
|
|
645
|
+
// Thunder Try: try a rule from your code with your own values, and see the answer and why (src/try-cli.mjs).
|
|
646
|
+
if (cmd === 'try') { tryMain(restArgv).then((code) => { process.exitCode = code; }); return; }
|
|
647
|
+
// The Thunder Time Machine: step through a recording made with thunder run --record (src/replay-cli.mjs).
|
|
648
|
+
if (cmd === 'replay') { replayMain(restArgv).then((code) => { process.exitCode = code; }); return; }
|
|
601
649
|
// Thunder Core (programs you write and run): thunder new <dir>, and run/build/test/check/format inside a
|
|
602
650
|
// project with thunder.toml (or with --core). Mission files fall through unchanged. See src/core/cli.mjs.
|
|
603
651
|
const coreCode = coreMain(cmd, restArgv);
|
|
@@ -605,13 +653,32 @@ function main() {
|
|
|
605
653
|
if (cmd === 'read') {
|
|
606
654
|
try {
|
|
607
655
|
if (!file) throw new Error('Use thunder read <file> [--search q] [--kind decision,function,error,test] [--in <lang>] [--json].');
|
|
656
|
+
if (args.level != null) {
|
|
657
|
+
// The five reading levels, from the same model OpenThunder shows (src/read-level.mjs).
|
|
658
|
+
const ids = LEVELS.map((l) => l.id);
|
|
659
|
+
if (!ids.includes(args.level)) {
|
|
660
|
+
const near = nearestLevel(args.level);
|
|
661
|
+
throw new Error(`there is no level "${args.level}". The levels are: ${ids.join(', ')}.${near ? ` Did you mean --level ${near}?` : ''}`);
|
|
662
|
+
}
|
|
663
|
+
const isDir = statSync(file).isDirectory();
|
|
664
|
+
const files = isDir ? collectReadableFiles(file, { maxFiles: 5000, templates: true }).filter((f) => f.source) : [{ path: basename(file), source: readFileSync(file, 'utf8') }];
|
|
665
|
+
// One Angular component file: its templateUrl file is read with it, so the screen shows its template.
|
|
666
|
+
if (!isDir) for (const tu of files[0].source.matchAll(/templateUrl\s*:\s*['"`]([^'"`]+)['"`]/g)) { try { files.push({ path: tu[1].replace(/^\.\//, ''), source: readFileSync(join(dirname(file), tu[1]), 'utf8') }); } catch { /* not there: the screen says so */ } }
|
|
667
|
+
const model = thunderModel(files, { name: basename(resolve(file)) });
|
|
668
|
+
const focus = findFocus(model, args.focus);
|
|
669
|
+
if (focus.error) throw new Error(focus.error);
|
|
670
|
+
const r = readLevel(model, args.level, focus.id);
|
|
671
|
+
if (args.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
672
|
+
console.log(paint(renderLevel(r, { sources: Object.fromEntries(files.map((f) => [f.path, f.source])), file })));
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
608
675
|
if (statSync(file).isDirectory()) { readFolder(file, args); return; }
|
|
609
676
|
if (args.asCore) {
|
|
610
677
|
// Reading and writing are one language: the reader's meaning tree printed as Thunder Core (docs/core.md).
|
|
611
678
|
if (!/\.py$/i.test(file) && (args.from || 'python') !== 'python') throw new Error('--as-core reads Python for now (other languages next).');
|
|
612
679
|
const r = pythonToCore(readFileSync(file, 'utf8'));
|
|
613
680
|
if (args.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
614
|
-
console.log(r.core.trimEnd());
|
|
681
|
+
console.log(paintThunder(r.core.trimEnd()));
|
|
615
682
|
const all = [...r.module.notTranslated, ...r.functions.flatMap((f) => f.notTranslated)];
|
|
616
683
|
const exact = r.functions.filter((f) => f.exact);
|
|
617
684
|
console.error(`\nthunder read --as-core: ${exact.length} of ${r.functions.length} function${r.functions.length === 1 ? '' : 's'} printed exactly as Thunder Core${all.length ? `; ${all.length} line${all.length === 1 ? '' : 's'} not translated (each stops with a clear error if it runs)` : ''}.`);
|
|
@@ -890,7 +957,7 @@ function main() {
|
|
|
890
957
|
if (opt('--otlp')) evidence.push(...fromOtlp(readFileSync(opt('--otlp'), 'utf8')));
|
|
891
958
|
} catch (e) { console.error(`thunder runtime: ${e.message}`); process.exit(2); return; }
|
|
892
959
|
if (!evidence.length) { console.error(`thunder runtime: no evidence given.\n${usage}`); process.exit(2); return; }
|
|
893
|
-
const model = thunderModel(collectReadableFiles(folder, { maxFiles: 5000 }).filter((f) => f.source), { name: basename(resolve(folder)) });
|
|
960
|
+
const model = thunderModel(collectReadableFiles(folder, { maxFiles: 5000, templates: true }).filter((f) => f.source), { name: basename(resolve(folder)) });
|
|
894
961
|
const overlay = runtimeOverlay(model, evidence);
|
|
895
962
|
const explained = stacks.map((s) => explainError(model, s));
|
|
896
963
|
if (restArgv.includes('--json')) { console.log(JSON.stringify({ ...overlay, errors: explained }, null, 2)); return; }
|
|
@@ -1206,7 +1273,10 @@ function main() {
|
|
|
1206
1273
|
console.error(`thunder init: ${target} already exists (use --force to overwrite).`);
|
|
1207
1274
|
process.exit(1); return;
|
|
1208
1275
|
}
|
|
1209
|
-
const starter =
|
|
1276
|
+
const starter = `# A mission: what one part of your product must do, the rules it follows, and examples that prove them.
|
|
1277
|
+
# Run the examples: thunder test ${basename(target)}
|
|
1278
|
+
# Try the rule: thunder try ${basename(target)}
|
|
1279
|
+
mission ${name}
|
|
1210
1280
|
use product
|
|
1211
1281
|
|
|
1212
1282
|
goal
|
|
@@ -1219,7 +1289,7 @@ guarantee an example property that must always hold
|
|
|
1219
1289
|
never
|
|
1220
1290
|
do something this mission must never do
|
|
1221
1291
|
|
|
1222
|
-
# A
|
|
1292
|
+
# A rule that decides: people 18 or older are allowed. Try it: thunder try ${basename(target)}
|
|
1223
1293
|
decision Example
|
|
1224
1294
|
inputs
|
|
1225
1295
|
age
|
|
@@ -1229,7 +1299,7 @@ decision Example
|
|
|
1229
1299
|
default
|
|
1230
1300
|
return Blocked
|
|
1231
1301
|
|
|
1232
|
-
#
|
|
1302
|
+
# Examples that prove the rule. Run them: thunder test ${basename(target)}
|
|
1233
1303
|
test Example
|
|
1234
1304
|
case adult
|
|
1235
1305
|
given age 20
|
|
@@ -1240,13 +1310,22 @@ test Example
|
|
|
1240
1310
|
`;
|
|
1241
1311
|
if (target.includes('/')) mkdirSync(dirname(target), { recursive: true });
|
|
1242
1312
|
writeFileSync(target, starter);
|
|
1243
|
-
console.log(
|
|
1244
|
-
|
|
1313
|
+
console.log(paint([
|
|
1314
|
+
`Created ${target}: a starter mission, the ThunderLang™ format for a product's rules and the examples that prove them.`,
|
|
1315
|
+
'',
|
|
1316
|
+
'Try it:',
|
|
1317
|
+
` thunder test ${target} run the examples written in the file`,
|
|
1318
|
+
` thunder try ${target} try the rule with your own values`,
|
|
1319
|
+
` thunder check ${target} look for mistakes, explained in plain words`,
|
|
1320
|
+
'',
|
|
1321
|
+
'Just starting out? A program in plain words is easier: thunder new hello',
|
|
1322
|
+
].join('\n')));
|
|
1245
1323
|
return;
|
|
1246
1324
|
}
|
|
1247
1325
|
|
|
1248
1326
|
if (!file && cmd !== 'draft' && cmd !== 'mission' && !(cmd === 'test' && args.changed)) {
|
|
1249
|
-
console.error(
|
|
1327
|
+
if (['run', 'test', 'build', 'check'].includes(cmd)) console.error(paint(noProjectText(cmd, process.cwd()), useColor(process.stderr)));
|
|
1328
|
+
else console.error(`thunder ${cmd}: missing a file argument. See: thunder help ${cmd}`);
|
|
1250
1329
|
process.exit(2);
|
|
1251
1330
|
}
|
|
1252
1331
|
|
|
@@ -2678,4 +2757,19 @@ test Example
|
|
|
2678
2757
|
printDiagnostics(diagnostics);
|
|
2679
2758
|
}
|
|
2680
2759
|
|
|
2681
|
-
|
|
2760
|
+
/** A file that is not there is said in words, never as a crash: what was looked for, where, and what to type. */
|
|
2761
|
+
function missingFile(e) {
|
|
2762
|
+
if (!e || e.code !== 'ENOENT' || !e.path) return false;
|
|
2763
|
+
const cmd = process.argv[2] ?? 'thunder';
|
|
2764
|
+
const name = relative(process.cwd(), e.path) || e.path;
|
|
2765
|
+
const lines = [`thunder ${cmd}: there is no file or folder called "${name}" here.`, `You're in: ${process.cwd()}`];
|
|
2766
|
+
let root = null;
|
|
2767
|
+
try { root = findProjectRoot(process.cwd()); } catch { /* none */ }
|
|
2768
|
+
if (root && ['run', 'test', 'build', 'check'].includes(cmd)) lines.push(`You're inside the Thunder project "${basename(root)}". Run it with: thunder ${cmd}`);
|
|
2769
|
+
else lines.push('See the main commands with: thunder help');
|
|
2770
|
+
console.error(paint(lines.join('\n'), useColor(process.stderr)));
|
|
2771
|
+
process.exitCode = 2;
|
|
2772
|
+
return true;
|
|
2773
|
+
}
|
|
2774
|
+
process.on('uncaughtException', (e) => { if (!missingFile(e)) { console.error(e); process.exitCode = 1; } });
|
|
2775
|
+
try { main(); } catch (e) { if (!missingFile(e)) throw e; }
|