@skillstech/thunderlang 1.1.0 → 1.2.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 +81 -0
- package/README.md +4 -1
- package/dist/core.cjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/learn.cjs +7510 -503
- package/package.json +2 -2
- package/src/cli-home.mjs +242 -0
- package/src/cli.mjs +107 -38
- package/src/core/cli.mjs +65 -14
- package/src/core/diagnostics.mjs +1 -0
- package/src/core/engine-core.mjs +572 -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/index.mjs +1 -0
- package/src/core/project.mjs +16 -6
- package/src/core/runtime-typescript.mjs +119 -0
- package/src/core/target-python.mjs +2 -1
- package/src/core/target-typescript.mjs +466 -0
- package/src/core/typescript-run.mjs +114 -0
- package/src/emit.mjs +1 -1
- package/src/learn-lessons.mjs +245 -1
- package/src/learn.d.mts +8 -0
- package/src/learn.mjs +40 -4
- package/src/read-level.mjs +146 -0
- package/src/term.mjs +89 -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.2.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,8 +49,12 @@ 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 { homeText, helpFor, knownCommands, unknownCommandText, noProjectText, doctorMain, completionMain } from './cli-home.mjs';
|
|
57
|
+
import { paint, paintHelp, useColor } from './term.mjs';
|
|
54
58
|
import { coreMain } from './core/cli.mjs';
|
|
55
59
|
import { pythonToCore } from './core/from-python.mjs';
|
|
56
60
|
import { guardSummary } from './guard.mjs';
|
|
@@ -333,6 +337,8 @@ function parseArgs(argv) {
|
|
|
333
337
|
else if (a === '--role') args.role = argv[++i];
|
|
334
338
|
else if (a === '--note') args.note = argv[++i];
|
|
335
339
|
else if (a === '--search') args.search = argv[++i];
|
|
340
|
+
else if (a === '--level') args.level = argv[++i] ?? '';
|
|
341
|
+
else if (a === '--focus') args.focus = argv[++i];
|
|
336
342
|
else if (a === '--kind') args.kind = (argv[++i] || '').split(',').map((k) => k.trim()).filter(Boolean);
|
|
337
343
|
else if (a === '--in') args.inLang = argv[++i];
|
|
338
344
|
else if (a === '--answer') args.answer = argv[++i];
|
|
@@ -455,17 +461,58 @@ function printDiagnostics(diags) {
|
|
|
455
461
|
return errors;
|
|
456
462
|
}
|
|
457
463
|
|
|
458
|
-
const HELP =
|
|
464
|
+
const HELP = `⚡ Thunder™: every command. Most people only need the first four groups.
|
|
459
465
|
|
|
460
|
-
|
|
466
|
+
usage: thunder <command> [file] [options] Help for one command: thunder help <command>
|
|
461
467
|
|
|
462
|
-
|
|
463
|
-
|
|
468
|
+
Start
|
|
469
|
+
doctor [--json] is this computer ready? Thunder, Node.js, Python, PATH, and optional toolchains (offline)
|
|
470
|
+
completion <zsh|bash|fish> a script that completes thunder commands when you press Tab
|
|
464
471
|
|
|
465
472
|
Write and run programs (Thunder Core, docs/core.md)
|
|
466
473
|
new <dir> create a Thunder Core project: thunder.toml, src/main.thunder, tests/
|
|
467
474
|
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
|
|
475
|
+
add --core for a single file with no project. run/test need Python 3.10+, or add
|
|
476
|
+
--engine thunder to run them on the Thunder engine (no Python; programs that Use a
|
|
477
|
+
Python module are refused there). --target typescript compiles to TypeScript instead
|
|
478
|
+
(generated/typescript/; runs on Node 22.6+, or with the typescript package)
|
|
479
|
+
|
|
480
|
+
Read and understand code
|
|
481
|
+
read <file|dir> [--search q] [--kind decision,function,error,test] [--in <lang>] [--from <lang>] [--json]
|
|
482
|
+
read <file|dir> --level big-picture|flow|details|text|original [--focus "<action or rule>"] [--json]
|
|
483
|
+
read at one depth, from the same model OpenThunder shows: the big picture, one action's flow,
|
|
484
|
+
its exact details, its Thunder Text, or the original lines
|
|
485
|
+
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
|
|
486
|
+
for a folder also: [--answer <Outcome>] [--input <name>] [--lang go,rust] [--path <prefix>] [--limit n]
|
|
487
|
+
--promote <decision> [--out <file>] turn a recovered decision into a contract with starter examples
|
|
488
|
+
read code you don't know: its decision rules as ThunderLang + plain English,
|
|
489
|
+
optionally rewritten in a language you know (--in typescript|python|go|rust|csharp|java)
|
|
490
|
+
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)
|
|
491
|
+
why <run.json> [--step n] [--json] what an AI agent did and why it stopped, in plain words, from its OpenTelemetry record
|
|
492
|
+
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)
|
|
493
|
+
review <base-ref> [head-ref] [--format markdown|json] [--paths <glob,...>] [--out <file>]
|
|
494
|
+
review in Thunder: what changed in meaning between two git commits (head: the working tree
|
|
495
|
+
when omitted), as Markdown for a pull request comment; read from git, no network
|
|
496
|
+
trace <folder…> [--json] [--out f] Thunder Trace: routes, requests, and events linked across repositories, cited repo@sha:file:line
|
|
497
|
+
trace impact <thing | --diff [--base ref]> <folder…> what a change can affect in other repositories (one hop, ranked by risk)
|
|
498
|
+
repo <owner/repo | github url | folder> [--json] [--max-files n] Thunder a whole repository (read-only; nothing is executed)
|
|
499
|
+
thunderize <folder | owner/repo> [--out <dir>] [--json] the whole app in Thunder Text: one .thunder-text per file + APP.thunder-text
|
|
500
|
+
|
|
501
|
+
Change code
|
|
502
|
+
write <file> --edit '<json>' [--edit …] [--also <file>] [--apply] [--test "<cmd>"] [--candidate <file>] [--json]
|
|
503
|
+
Writing in Thunder: change a step, question, Stop, input, or function in Thunder; the code is
|
|
504
|
+
written as a minimal patch (TS/JS, Python, Go) and proven (the edited steps mean exactly
|
|
505
|
+
the edit; everything else means the same). Dry run by default; --apply saves; --test runs a
|
|
506
|
+
command on the changed code. Other cases print an instruction for an AI coding agent;
|
|
507
|
+
--candidate checks code it wrote (labeled AI-written).
|
|
508
|
+
write <file> --decision <name> --rule <n|otherwise> [--when "<condition>"] [--answer <Outcome>] [--write] [--json]
|
|
509
|
+
Thunder write: change a number, comparison, text value, or answer in a recovered rule;
|
|
510
|
+
previews the exact code change and the cases whose answer changes; --write saves it
|
|
511
|
+
|
|
512
|
+
────────────────────────────────────────────────────────────────────────
|
|
513
|
+
Advanced: rules and missions (ThunderLang™ intent files), proofs, and tools for editors and CI.
|
|
514
|
+
The flow: author intent, inspect it, run and prove it, then keep real code aligned with it.
|
|
515
|
+
thunder mission <Name> <command> run any command on a mission by name
|
|
469
516
|
|
|
470
517
|
Author
|
|
471
518
|
init [Name] scaffold a runnable starter mission (Name.thunder) [alias: new --mission Name]
|
|
@@ -535,31 +582,7 @@ Graph & IR
|
|
|
535
582
|
human <file> [--json | --format source] experimental compact authoring and a decision reading view
|
|
536
583
|
--version print the Thunder compiler version
|
|
537
584
|
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
585
|
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
586
|
graph <file> [--safe] the canonical Intent Graph (intent-graph-v1); --safe = display-safe on stdout
|
|
564
587
|
migrate <graph.json> [--to <version>] upgrade a persisted graph
|
|
565
588
|
validate <graph.json> [--json] check a graph is canonical (anti-fork)
|
|
@@ -585,19 +608,36 @@ function main() {
|
|
|
585
608
|
const args = parseArgs(restArgv);
|
|
586
609
|
const file = args._[0];
|
|
587
610
|
if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
|
|
588
|
-
console.log(`thunder ${COMPILER_VERSION} (the Thunder compiler, also called ThunderLang)`);
|
|
611
|
+
console.log(`thunder ${COMPILER_VERSION} (the Thunder™ compiler, also called ThunderLang™)`);
|
|
589
612
|
return;
|
|
590
613
|
}
|
|
614
|
+
const known = [...new Set([...knownCommands(HELP), ...Object.keys(VIEWS)])].sort();
|
|
591
615
|
if (!cmd || cmd === 'help' || cmd === '--help' || cmd === '-h') {
|
|
592
|
-
|
|
593
|
-
|
|
616
|
+
// `thunder help <command>`: just that command's lines from the full list.
|
|
617
|
+
const topic = cmd === 'help' ? restArgv.find((x) => !x.startsWith('-')) : null;
|
|
618
|
+
if (topic) {
|
|
619
|
+
const h = helpFor(topic, HELP);
|
|
620
|
+
if (h) { console.log(`${paintHelp(h)}\n\n${paint('All commands: thunder help --all')}`); process.exitCode = 0; }
|
|
621
|
+
else { console.error(paint(unknownCommandText(topic, known), useColor(process.stderr))); process.exitCode = 2; }
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
// The short home screen first; every command with --all. Exit codes are unchanged (2 with no command at all).
|
|
625
|
+
// exitCode, not exit(): the full help is longer than a pipe's buffer, and exit() would cut it off when piped.
|
|
626
|
+
console.log(restArgv.includes('--all') ? paintHelp(HELP) : paint(homeText(COMPILER_VERSION, known.length)));
|
|
594
627
|
process.exitCode = cmd ? 0 : 2;
|
|
595
628
|
return;
|
|
596
629
|
}
|
|
630
|
+
// thunder doctor: is this computer ready? Offline; changes nothing (src/cli-home.mjs).
|
|
631
|
+
if (cmd === 'completion') { process.exitCode = completionMain(restArgv, known); return; }
|
|
632
|
+
if (cmd === 'doctor') { process.exitCode = doctorMain(restArgv, { version: COMPILER_VERSION, cliPath: process.argv[1] }); return; }
|
|
633
|
+
// A command Thunder doesn't have (and not a file): say so, and suggest the closest ones, instead of failing later.
|
|
634
|
+
if (!known.includes(cmd) && !cmd.startsWith('-') && !existsSync(cmd)) { console.error(paint(unknownCommandText(cmd, known), useColor(process.stderr))); process.exitCode = 2; return; }
|
|
597
635
|
// Thunder Trace: links between repositories and what a change can affect (src/trace-cli.mjs).
|
|
598
636
|
if (cmd === 'trace') { process.exitCode = traceMain(restArgv); return; }
|
|
599
637
|
// Thunder Why: an AI agent's run explained in plain words, from its OpenTelemetry record (src/why-cli.mjs).
|
|
600
638
|
if (cmd === 'why') { process.exitCode = whyMain(restArgv); return; }
|
|
639
|
+
// Thunder Try: try a rule from your code with your own values, and see the answer and why (src/try-cli.mjs).
|
|
640
|
+
if (cmd === 'try') { tryMain(restArgv).then((code) => { process.exitCode = code; }); return; }
|
|
601
641
|
// Thunder Core (programs you write and run): thunder new <dir>, and run/build/test/check/format inside a
|
|
602
642
|
// project with thunder.toml (or with --core). Mission files fall through unchanged. See src/core/cli.mjs.
|
|
603
643
|
const coreCode = coreMain(cmd, restArgv);
|
|
@@ -605,6 +645,23 @@ function main() {
|
|
|
605
645
|
if (cmd === 'read') {
|
|
606
646
|
try {
|
|
607
647
|
if (!file) throw new Error('Use thunder read <file> [--search q] [--kind decision,function,error,test] [--in <lang>] [--json].');
|
|
648
|
+
if (args.level != null) {
|
|
649
|
+
// The five reading levels, from the same model OpenThunder shows (src/read-level.mjs).
|
|
650
|
+
const ids = LEVELS.map((l) => l.id);
|
|
651
|
+
if (!ids.includes(args.level)) {
|
|
652
|
+
const near = nearestLevel(args.level);
|
|
653
|
+
throw new Error(`there is no level "${args.level}". The levels are: ${ids.join(', ')}.${near ? ` Did you mean --level ${near}?` : ''}`);
|
|
654
|
+
}
|
|
655
|
+
const isDir = statSync(file).isDirectory();
|
|
656
|
+
const files = isDir ? collectReadableFiles(file, { maxFiles: 5000 }).filter((f) => f.source) : [{ path: basename(file), source: readFileSync(file, 'utf8') }];
|
|
657
|
+
const model = thunderModel(files, { name: basename(resolve(file)) });
|
|
658
|
+
const focus = findFocus(model, args.focus);
|
|
659
|
+
if (focus.error) throw new Error(focus.error);
|
|
660
|
+
const r = readLevel(model, args.level, focus.id);
|
|
661
|
+
if (args.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
662
|
+
console.log(paint(renderLevel(r, { sources: Object.fromEntries(files.map((f) => [f.path, f.source])), file })));
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
608
665
|
if (statSync(file).isDirectory()) { readFolder(file, args); return; }
|
|
609
666
|
if (args.asCore) {
|
|
610
667
|
// Reading and writing are one language: the reader's meaning tree printed as Thunder Core (docs/core.md).
|
|
@@ -1206,7 +1263,10 @@ function main() {
|
|
|
1206
1263
|
console.error(`thunder init: ${target} already exists (use --force to overwrite).`);
|
|
1207
1264
|
process.exit(1); return;
|
|
1208
1265
|
}
|
|
1209
|
-
const starter =
|
|
1266
|
+
const starter = `# A mission: what one part of your product must do, the rules it follows, and examples that prove them.
|
|
1267
|
+
# Run the examples: thunder test ${basename(target)}
|
|
1268
|
+
# Try the rule: thunder try ${basename(target)}
|
|
1269
|
+
mission ${name}
|
|
1210
1270
|
use product
|
|
1211
1271
|
|
|
1212
1272
|
goal
|
|
@@ -1219,7 +1279,7 @@ guarantee an example property that must always hold
|
|
|
1219
1279
|
never
|
|
1220
1280
|
do something this mission must never do
|
|
1221
1281
|
|
|
1222
|
-
# A
|
|
1282
|
+
# A rule that decides: people 18 or older are allowed. Try it: thunder try ${basename(target)}
|
|
1223
1283
|
decision Example
|
|
1224
1284
|
inputs
|
|
1225
1285
|
age
|
|
@@ -1229,7 +1289,7 @@ decision Example
|
|
|
1229
1289
|
default
|
|
1230
1290
|
return Blocked
|
|
1231
1291
|
|
|
1232
|
-
#
|
|
1292
|
+
# Examples that prove the rule. Run them: thunder test ${basename(target)}
|
|
1233
1293
|
test Example
|
|
1234
1294
|
case adult
|
|
1235
1295
|
given age 20
|
|
@@ -1240,13 +1300,22 @@ test Example
|
|
|
1240
1300
|
`;
|
|
1241
1301
|
if (target.includes('/')) mkdirSync(dirname(target), { recursive: true });
|
|
1242
1302
|
writeFileSync(target, starter);
|
|
1243
|
-
console.log(
|
|
1244
|
-
|
|
1303
|
+
console.log(paint([
|
|
1304
|
+
`Created ${target}: a starter mission, the ThunderLang™ format for a product's rules and the examples that prove them.`,
|
|
1305
|
+
'',
|
|
1306
|
+
'Try it:',
|
|
1307
|
+
` thunder test ${target} run the examples written in the file`,
|
|
1308
|
+
` thunder try ${target} try the rule with your own values`,
|
|
1309
|
+
` thunder check ${target} look for mistakes, explained in plain words`,
|
|
1310
|
+
'',
|
|
1311
|
+
'Just starting out? A program in plain words is easier: thunder new hello',
|
|
1312
|
+
].join('\n')));
|
|
1245
1313
|
return;
|
|
1246
1314
|
}
|
|
1247
1315
|
|
|
1248
1316
|
if (!file && cmd !== 'draft' && cmd !== 'mission' && !(cmd === 'test' && args.changed)) {
|
|
1249
|
-
console.error(
|
|
1317
|
+
if (['run', 'test', 'build', 'check'].includes(cmd)) console.error(paint(noProjectText(cmd, process.cwd()), useColor(process.stderr)));
|
|
1318
|
+
else console.error(`thunder ${cmd}: missing a file argument. See: thunder help ${cmd}`);
|
|
1250
1319
|
process.exit(2);
|
|
1251
1320
|
}
|
|
1252
1321
|
|
package/src/core/cli.mjs
CHANGED
|
@@ -10,21 +10,30 @@
|
|
|
10
10
|
|
|
11
11
|
import { readFileSync, writeFileSync, existsSync, statSync } from 'node:fs';
|
|
12
12
|
import { resolve, relative, join } from 'node:path';
|
|
13
|
-
import { findProjectRoot, buildProject, findPython, runPython, newProject } from './project.mjs';
|
|
13
|
+
import { findProjectRoot, buildProject, findPython, runPython, newProject, TARGETS } from './project.mjs';
|
|
14
|
+
import { runTypeScript } from './typescript-run.mjs';
|
|
14
15
|
import { formatDiagnostic } from './diagnostics.mjs';
|
|
15
16
|
import { formatCore } from './format.mjs';
|
|
17
|
+
import { paint } from '../term.mjs';
|
|
18
|
+
import { runWithEngine, testWithEngine, ENGINES } from './engine.mjs';
|
|
16
19
|
|
|
17
20
|
const CORE_COMMANDS = new Set(['new', 'run', 'build', 'test', 'check', 'format', 'fmt']);
|
|
18
21
|
|
|
19
22
|
function parse(argv) {
|
|
20
|
-
const a = { _: [], core: false, json: false, write: false, check: false, force: false, mission: false };
|
|
21
|
-
for (
|
|
22
|
-
|
|
23
|
+
const a = { _: [], core: false, json: false, write: false, check: false, force: false, mission: false, engine: null, target: null };
|
|
24
|
+
for (let i = 0; i < argv.length; i++) {
|
|
25
|
+
const x = argv[i];
|
|
26
|
+
if (x === '--target') a.target = argv[++i] ?? '';
|
|
27
|
+
else if (x.startsWith('--target=')) a.target = x.slice('--target='.length);
|
|
28
|
+
else if (x === '--engine') a.engine = argv[++i] ?? '';
|
|
29
|
+
else if (x.startsWith('--engine=')) a.engine = x.slice('--engine='.length);
|
|
30
|
+
else if (x === '--core') a.core = true;
|
|
23
31
|
else if (x === '--json') a.json = true;
|
|
24
32
|
else if (x === '--write' || x === '-w') a.write = true;
|
|
25
33
|
else if (x === '--check') a.check = true;
|
|
26
34
|
else if (x === '--force') a.force = true;
|
|
27
35
|
else if (x === '--mission') a.mission = true;
|
|
36
|
+
else if (x === '--run') a.run = true;
|
|
28
37
|
else if (x.startsWith('--')) a.other = true;
|
|
29
38
|
else a._.push(x);
|
|
30
39
|
}
|
|
@@ -46,7 +55,7 @@ export function coreTarget(cmd, argv, cwd = process.cwd()) {
|
|
|
46
55
|
return null;
|
|
47
56
|
}
|
|
48
57
|
|
|
49
|
-
const say = (s = '') => process.stdout.write(`${s}\n`);
|
|
58
|
+
const say = (s = '') => process.stdout.write(`${paint(s)}\n`);
|
|
50
59
|
const warn = (s = '') => process.stderr.write(`${s}\n`);
|
|
51
60
|
|
|
52
61
|
function report(build, cwd) {
|
|
@@ -64,16 +73,23 @@ export function coreMain(cmd, argv, cwd = process.cwd()) {
|
|
|
64
73
|
if (cmd === 'new') {
|
|
65
74
|
const root = newProject(resolve(cwd, t.new), { force: a.force });
|
|
66
75
|
const rel = relative(cwd, root) || '.';
|
|
67
|
-
say(`
|
|
68
|
-
say(
|
|
69
|
-
say(
|
|
70
|
-
say(` ${rel}
|
|
71
|
-
say(
|
|
72
|
-
say(`
|
|
73
|
-
|
|
76
|
+
say(`Created ${rel}, a new Thunder program.`);
|
|
77
|
+
say('');
|
|
78
|
+
say('Run it:');
|
|
79
|
+
say(` thunder run ${rel}`);
|
|
80
|
+
say('');
|
|
81
|
+
say(`Then change ${join(rel, 'src', 'main.thunder')} and run it again. Check it works with: thunder test ${rel}`);
|
|
82
|
+
say(`(Wanted a mission file instead? thunder init ${t.new})`);
|
|
83
|
+
if (!a.run) return 0;
|
|
84
|
+
say('');
|
|
85
|
+
return coreMain('run', [root], cwd);
|
|
74
86
|
}
|
|
75
87
|
if (cmd === 'format' || cmd === 'fmt') return format(t, a, cwd);
|
|
76
|
-
|
|
88
|
+
if (a.engine !== null && !ENGINES.includes(a.engine)) { warn(`thunder ${cmd}: there is no engine "${a.engine}". Use --engine python (the default) or --engine thunder.`); return 2; }
|
|
89
|
+
if (a.engine !== null && cmd !== 'run' && cmd !== 'test') { warn(`thunder ${cmd}: --engine is for thunder run and thunder test.`); return 2; }
|
|
90
|
+
if (a.target !== null && !TARGETS.includes(a.target)) { warn(`thunder ${cmd}: there is no target "${a.target}". Use --target python (the default) or --target typescript.`); return 2; }
|
|
91
|
+
if (a.target === 'typescript' && a.engine === 'thunder') { warn(`thunder ${cmd}: choose one: --target typescript runs compiled TypeScript, --engine thunder runs Thunder directly.`); return 2; }
|
|
92
|
+
const build = buildProject({ root: t.root, single: t.file, includeTests: cmd === 'test' || cmd === 'check', write: cmd !== 'check', target: a.target });
|
|
77
93
|
if (cmd === 'check') {
|
|
78
94
|
if (a.json) { say(JSON.stringify({ ok: build.ok, files: build.results.map((r) => ({ file: relative(cwd, r.path), diagnostics: r.diagnostics })) }, null, 2)); return build.ok ? 0 : 1; }
|
|
79
95
|
const n = report(build, cwd);
|
|
@@ -83,6 +99,13 @@ export function coreMain(cmd, argv, cwd = process.cwd()) {
|
|
|
83
99
|
}
|
|
84
100
|
if (!build.ok) { const n = report(build, cwd); warn(`thunder ${cmd}: ${n} problem${n === 1 ? '' : 's'}; nothing was ${cmd === 'build' ? 'built' : 'run'}.`); return 1; }
|
|
85
101
|
const out = relative(cwd, build.outDir) || '.';
|
|
102
|
+
if (cmd === 'build' && build.target === 'typescript') {
|
|
103
|
+
say(`thunder build: ${build.results.length} file${build.results.length === 1 ? '' : 's'} -> ${out}/ (TypeScript)`);
|
|
104
|
+
for (const r of build.results) say(` ${relative(cwd, r.path)} -> ${out}/${r.module}.ts`);
|
|
105
|
+
say(` ${out}/thunder_runtime.mjs (the small runtime the generated code uses), with its types and a tsconfig.json`);
|
|
106
|
+
say(` run it without Thunder: node ${out}/${build.entryModule}.ts (Node 22.6 or newer; check the types with: tsc -p ${out})`);
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
86
109
|
if (cmd === 'build') {
|
|
87
110
|
say(`thunder build: ${build.results.length} file${build.results.length === 1 ? '' : 's'} -> ${out}/ (Python 3.10+)`);
|
|
88
111
|
for (const r of build.results) say(` ${relative(cwd, r.path)} -> ${out}/${r.module}.py`);
|
|
@@ -90,8 +113,10 @@ export function coreMain(cmd, argv, cwd = process.cwd()) {
|
|
|
90
113
|
say(` run it without Thunder: cd ${build.base === cwd ? '.' : relative(cwd, build.base)} && python3 ${relative(build.base, build.outDir)}/${build.entryModule}.py`);
|
|
91
114
|
return 0;
|
|
92
115
|
}
|
|
116
|
+
if (a.engine === 'thunder') return runOnEngine(cmd, build, warn, say);
|
|
117
|
+
if (build.target === 'typescript') return runCompiledTypeScript(cmd, build, warn, say);
|
|
93
118
|
const python = findPython();
|
|
94
|
-
if (python.error) { warn(`thunder ${cmd}: ${python.error}`); return 2; }
|
|
119
|
+
if (python.error) { warn(`thunder ${cmd}: ${python.error}${['run', 'test'].includes(cmd) ? `\nOr run it without Python, on the Thunder engine: thunder ${cmd} ${argv.filter((x) => !x.startsWith('--engine')).join(' ')}${argv.length ? ' ' : ''}--engine thunder`.replace(/ +/g, ' ') : ''}`); return 2; }
|
|
95
120
|
if (cmd === 'run') {
|
|
96
121
|
if (!build.entryModule) { warn('thunder run: there is no program to run (no .thunder files in src/).'); return 1; }
|
|
97
122
|
const r = runPython(python, build.outDir, `${build.entryModule}.py`, build.base);
|
|
@@ -110,6 +135,32 @@ export function coreMain(cmd, argv, cwd = process.cwd()) {
|
|
|
110
135
|
return null;
|
|
111
136
|
}
|
|
112
137
|
|
|
138
|
+
/** thunder run / test with the TypeScript target: the compiled TypeScript runs on Node. */
|
|
139
|
+
function runCompiledTypeScript(cmd, build, warn, say) {
|
|
140
|
+
if (cmd === 'run' && !build.entryModule) { warn('thunder run: there is no program to run (no .thunder files in src/).'); return 1; }
|
|
141
|
+
if (cmd === 'test' && !build.results.reduce((n, r) => n + r.info.tests.length, 0)) { say('thunder test: no Test blocks found. Write one: Test "what it checks": then Expect … lines.'); return 0; }
|
|
142
|
+
const r = runTypeScript(build.outDir, cmd === 'run' ? `${build.entryModule}.ts` : 'run_tests.ts', { cwd: build.base, stdio: 'inherit' });
|
|
143
|
+
if (r.error && typeof r.error === 'string') { warn(`thunder ${cmd}: ${r.error}`); return 2; }
|
|
144
|
+
return r.status ?? 1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** thunder run / test --engine thunder: the program runs on the Thunder engine, with no Python. */
|
|
148
|
+
function runOnEngine(cmd, build, warn, say) {
|
|
149
|
+
if (cmd === 'run') {
|
|
150
|
+
if (!build.entry) { warn('thunder run: there is no program to run (no .thunder files in src/).'); return 1; }
|
|
151
|
+
const r = runWithEngine({ entry: build.entry, cwd: build.base });
|
|
152
|
+
if (r.stdout) process.stdout.write(r.stdout);
|
|
153
|
+
if (r.stderr) process.stderr.write(r.stderr.startsWith('This program uses') ? `thunder run: ${r.stderr}` : r.stderr);
|
|
154
|
+
return r.status;
|
|
155
|
+
}
|
|
156
|
+
const tests = build.results.reduce((n, r) => n + r.info.tests.length, 0);
|
|
157
|
+
if (!tests) { say('thunder test: no Test blocks found. Write one: Test "what it checks": then Expect … lines.'); return 0; }
|
|
158
|
+
const r = testWithEngine({ results: build.results, cwd: build.base });
|
|
159
|
+
if (r.stdout) process.stdout.write(r.stdout);
|
|
160
|
+
if (r.stderr) process.stderr.write(`thunder test: ${r.stderr}`);
|
|
161
|
+
return r.status;
|
|
162
|
+
}
|
|
163
|
+
|
|
113
164
|
function format(t, a, cwd) {
|
|
114
165
|
let files = [];
|
|
115
166
|
if (t.file) files = [t.file];
|
package/src/core/diagnostics.mjs
CHANGED
|
@@ -38,6 +38,7 @@ export const CODES = {
|
|
|
38
38
|
TC402: 'Thunder Core does not support this yet',
|
|
39
39
|
TC403: 'A "Never" rule names more than one changing value',
|
|
40
40
|
TC404: 'A default for an input must be a fixed value, after the inputs without one',
|
|
41
|
+
TC405: 'A Python module ("Use") cannot be used when compiling to TypeScript',
|
|
41
42
|
TC501: 'Divided by zero (runtime)',
|
|
42
43
|
TC502: 'Nothing used where a value was needed (runtime)',
|
|
43
44
|
TC503: 'A field or entry is missing (runtime)',
|