@skillstech/thunderlang 1.0.3 → 1.1.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 +207 -0
- package/dist/core.cjs +13779 -10043
- package/dist/index.cjs +28500 -24392
- package/dist/learn.cjs +12853 -9579
- package/intent-graph.schema.json +11 -0
- package/package.json +6 -2
- package/src/cli.mjs +141 -58
- package/src/codegen.mjs +145 -55
- package/src/conformance.mjs +15 -6
- package/src/core/check.mjs +725 -0
- package/src/core/cli.mjs +133 -0
- package/src/core/diagnostics.mjs +81 -0
- package/src/core/format.mjs +20 -0
- package/src/core/from-python.mjs +645 -0
- package/src/core/index.mjs +38 -0
- package/src/core/lexer.mjs +115 -0
- package/src/core/parser.mjs +742 -0
- package/src/core/project.mjs +167 -0
- package/src/core/round-trip.mjs +150 -0
- package/src/core/runtime-python.mjs +801 -0
- package/src/core/target-python.mjs +486 -0
- package/src/core.d.ts +5 -2
- package/src/core.mjs +5 -2
- package/src/data-schema.mjs +8 -1
- package/src/emit.mjs +1 -1
- package/src/evidence.mjs +1 -1
- package/src/expr.mjs +81 -4
- package/src/form-words.mjs +2 -0
- package/src/index.d.ts +8 -1
- package/src/index.mjs +5 -1
- package/src/intent-schema.mjs +1 -0
- package/src/libraries.mjs +2 -2
- package/src/mcp.mjs +23 -0
- package/src/meaning.mjs +47 -7
- package/src/model.d.mts +7 -3
- package/src/model.mjs +30 -9
- package/src/money.d.mts +18 -0
- package/src/money.mjs +124 -0
- package/src/plain-contract.mjs +18 -2
- package/src/powershell.mjs +24 -5
- package/src/read-repo.mjs +1 -0
- package/src/read.d.mts +11 -0
- package/src/read.mjs +121 -13
- package/src/review-comment.d.mts +16 -0
- package/src/review-comment.mjs +145 -0
- package/src/rlang.mjs +10 -3
- package/src/say-less.mjs +1432 -0
- package/src/shell.mjs +45 -8
- package/src/sql-proc.mjs +1198 -0
- package/src/sql.mjs +87 -119
- package/src/steps.mjs +188 -37
- package/src/system.mjs +153 -44
- package/src/target-cs.mjs +39 -34
- package/src/target-elixir.mjs +40 -30
- package/src/target-go.mjs +41 -36
- package/src/target-java.mjs +34 -27
- package/src/target-kotlin.mjs +43 -35
- package/src/target-py.mjs +57 -55
- package/src/target-result.d.mts +48 -0
- package/src/target-result.mjs +112 -0
- package/src/target-rust.mjs +42 -38
- package/src/target-scala.mjs +45 -35
- package/src/target-ts.mjs +37 -45
- package/src/target-types.mjs +41 -5
- package/src/target-util.mjs +55 -2
- package/src/trace-cli.mjs +58 -0
- package/src/trace-fs.mjs +76 -0
- package/src/trace.mjs +261 -0
- package/src/translate.d.mts +3 -0
- package/src/translate.mjs +62 -32
- package/src/why-cli.mjs +31 -0
- package/src/why.d.mts +28 -0
- package/src/why.mjs +532 -0
- package/src/write-steps.mjs +22 -5
package/intent-graph.schema.json
CHANGED
|
@@ -577,6 +577,17 @@
|
|
|
577
577
|
"blocks": [],
|
|
578
578
|
"summary": "Field uses an unrecognized (likely mistyped) type."
|
|
579
579
|
},
|
|
580
|
+
{
|
|
581
|
+
"owner": "IL",
|
|
582
|
+
"phase": "author",
|
|
583
|
+
"ruleId": "IL-GEN-001",
|
|
584
|
+
"area": "generation",
|
|
585
|
+
"severity": "error",
|
|
586
|
+
"blocks": [
|
|
587
|
+
"implementation"
|
|
588
|
+
],
|
|
589
|
+
"summary": "A rule condition could not be translated for a target: generation reports it, the generated rule throws, and live runs report it not translated (never a stand-in false)."
|
|
590
|
+
},
|
|
580
591
|
{
|
|
581
592
|
"owner": "IL",
|
|
582
593
|
"phase": "author",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skillstech/thunderlang",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"types": "./src/running.d.mts",
|
|
25
25
|
"import": "./src/running.mjs"
|
|
26
26
|
},
|
|
27
|
+
"./why": {
|
|
28
|
+
"types": "./src/why.d.mts",
|
|
29
|
+
"import": "./src/why.mjs"
|
|
30
|
+
},
|
|
27
31
|
"./learn": {
|
|
28
32
|
"types": "./src/learn.d.mts",
|
|
29
33
|
"import": "./src/learn.mjs",
|
package/src/cli.mjs
CHANGED
|
@@ -49,6 +49,10 @@ 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 { traceMain } from './trace-cli.mjs';
|
|
53
|
+
import { whyMain } from './why-cli.mjs';
|
|
54
|
+
import { coreMain } from './core/cli.mjs';
|
|
55
|
+
import { pythonToCore } from './core/from-python.mjs';
|
|
52
56
|
import { guardSummary } from './guard.mjs';
|
|
53
57
|
import { draftIntent } from './draft.mjs';
|
|
54
58
|
import { liftSource, liftAll, liftRepo, languageForFile } from './lift.mjs';
|
|
@@ -61,7 +65,7 @@ import { buildReviewAtlas, renderReviewBrief, reviewAtlasExitCode } from './revi
|
|
|
61
65
|
import { buildFocusGraph, intentBrief, makeScope } from './focus.mjs';
|
|
62
66
|
import { comprehensionLevel, comprehensionReport, LEVELS as COMPREHENSION_LEVELS } from './comprehension.mjs';
|
|
63
67
|
import { twelveFactorReport } from './twelve-factor.mjs';
|
|
64
|
-
import { GENERATORS } from './codegen.mjs';
|
|
68
|
+
import { GENERATORS, generateWithDiagnostics } from './codegen.mjs';
|
|
65
69
|
import { changeReport } from './changes.mjs';
|
|
66
70
|
import { execSync, execFileSync, spawnSync } from 'node:child_process';
|
|
67
71
|
import { diffGraphs, mergeGraphs } from './semantic-diff.mjs';
|
|
@@ -82,6 +86,7 @@ import { runRustTarget, rustAvailable } from './target-rust.mjs';
|
|
|
82
86
|
import { runKotlinTarget, kotlinAvailable } from './target-kotlin.mjs';
|
|
83
87
|
import { runScalaTarget, scalaAvailable } from './target-scala.mjs';
|
|
84
88
|
import { runElixirTarget, elixirAvailable } from './target-elixir.mjs';
|
|
89
|
+
import { errorResult, runFailure } from './target-result.mjs';
|
|
85
90
|
|
|
86
91
|
// The live-target registry: one entry per canonical target that can be compiled + executed.
|
|
87
92
|
// `available()` is a (cached) toolchain probe; TypeScript/JS runs in-process so it is always live.
|
|
@@ -110,12 +115,42 @@ const TARGET_ALIASES = {
|
|
|
110
115
|
golang: 'go', rs: 'rust', kt: 'kotlin', sc: 'scala', ex: 'elixir',
|
|
111
116
|
};
|
|
112
117
|
const canonicalTarget = (t) => TARGET_ALIASES[String(t).toLowerCase()] || String(t).toLowerCase();
|
|
113
|
-
// Execute a live target. Returns { "Test / case":
|
|
114
|
-
// (e.g. the
|
|
118
|
+
// Execute a live target. Returns { status: 'ok', results: { "Test / case": caseResult } } or a
|
|
119
|
+
// whole-run { status: 'error', kind, message } (e.g. kind 'missing-toolchain' when the SDK is not
|
|
120
|
+
// installed). A failure is never turned into a null answer.
|
|
115
121
|
function runLiveTarget(ast, target) {
|
|
116
122
|
const entry = LIVE_BY_KEY.get(canonicalTarget(target));
|
|
117
|
-
|
|
123
|
+
if (!entry) return runFailure('missing-toolchain', `Thunder has no live runner for "${target}".`);
|
|
124
|
+
return entry.run(ast);
|
|
118
125
|
}
|
|
126
|
+
// Grade a live run against the intent's test cases. A case the target could not produce (not
|
|
127
|
+
// translated, compile failure, crash, timeout) is an error, never a pass and never a null answer.
|
|
128
|
+
function gradeRun(ast, run) {
|
|
129
|
+
const cs = [];
|
|
130
|
+
for (const t of ast.tests || []) {
|
|
131
|
+
if (!(ast.decisions || []).some((d) => d.name === t.name)) continue;
|
|
132
|
+
for (const c of t.cases || []) {
|
|
133
|
+
const key = `${t.name} / ${c.name || 'case'}`;
|
|
134
|
+
const r = run.status === 'ok'
|
|
135
|
+
? (run.results[key] || errorResult('runtime-error', `The target reported no result for ${key}.`))
|
|
136
|
+
: errorResult(run.kind, run.message);
|
|
137
|
+
if (r.status === 'error') { cs.push({ key, expected: c.expect, status: 'error', kind: r.kind, message: r.message, pass: false }); continue; }
|
|
138
|
+
const pass = c.expect == null || String(r.value) === String(c.expect);
|
|
139
|
+
cs.push({ key, expected: c.expect, actual: r.value, status: pass ? 'pass' : 'fail', ...(pass ? {} : { kind: 'assertion-failed' }), pass });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return cs;
|
|
143
|
+
}
|
|
144
|
+
// Per-case results for conformance: the run's own results, or the whole-run failure on every case.
|
|
145
|
+
function caseResultsOf(ast, run) {
|
|
146
|
+
if (run.status === 'ok') return run.results;
|
|
147
|
+
const out = {};
|
|
148
|
+
for (const t of ast.tests || []) for (const c of t.cases || []) out[`${t.name} / ${c.name || 'case'}`] = errorResult(run.kind, run.message);
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
const caseLine = (c) => (c.status === 'error'
|
|
152
|
+
? `ERROR ${c.key} , ${c.kind === 'not-translated' ? 'not translated' : c.kind === 'missing-input' ? 'missing input' : c.kind}: ${c.message}`
|
|
153
|
+
: `FAIL ${c.key} , expected ${c.expected}, got ${c.actual === null ? 'null' : c.actual}`);
|
|
119
154
|
import { importIntent, importReport, detectFormat, IMPORT_FORMATS } from './importers.mjs';
|
|
120
155
|
import { runTests } from './testing.mjs';
|
|
121
156
|
import { resolveObligations } from './obligations.mjs';
|
|
@@ -211,14 +246,16 @@ function collectIntents(root, acc = []) {
|
|
|
211
246
|
* Read the files that changed between two commits (or a commit and the working tree, when head is null) and review
|
|
212
247
|
* them in Thunder. Only git is run (show, diff, ls-files): nothing is fetched and nothing is executed.
|
|
213
248
|
*/
|
|
214
|
-
function reviewGit(base, head) {
|
|
249
|
+
function reviewGit(base, head, paths = []) {
|
|
215
250
|
const git = (...a) => execFileSync('git', a, { encoding: 'utf8', maxBuffer: 256 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
216
251
|
try { git('rev-parse', '--is-inside-work-tree'); } catch { throw new Error('not inside a git repository.'); }
|
|
217
252
|
for (const ref of [base, head].filter(Boolean)) {
|
|
218
253
|
try { git('rev-parse', '--verify', '--quiet', `${ref}^{commit}`); } catch { throw new Error(`${ref} is not a commit in this repository (fetch it first, for example with fetch-depth: 0).`); }
|
|
219
254
|
}
|
|
220
255
|
const root = git('rev-parse', '--show-toplevel').trim();
|
|
221
|
-
|
|
256
|
+
// --paths: git pathspecs with glob magic, so `src/**` and `*.py` mean what they look like.
|
|
257
|
+
const spec = paths.map((p) => `:(glob)${p}`);
|
|
258
|
+
const parts = git('diff', '--name-status', '-z', '-M', base, ...(head ? [head] : []), '--', ...spec).split('\0');
|
|
222
259
|
const changes = [];
|
|
223
260
|
for (let i = 0; i < parts.length && parts[i];) {
|
|
224
261
|
const status = parts[i++];
|
|
@@ -227,7 +264,7 @@ function reviewGit(base, head) {
|
|
|
227
264
|
else if (status === 'D') changes.push({ old: parts[i++], new: null });
|
|
228
265
|
else { const p = parts[i++]; changes.push({ old: p, new: p }); }
|
|
229
266
|
}
|
|
230
|
-
if (!head) for (const p of git('ls-files', '--others', '--exclude-standard', '-z').split('\0').filter(Boolean)) changes.push({ old: null, new: p });
|
|
267
|
+
if (!head) for (const p of git('ls-files', '--others', '--exclude-standard', '-z', '--', ...spec).split('\0').filter(Boolean)) changes.push({ old: null, new: p });
|
|
231
268
|
const text = (s) => (s == null || s.includes('\0') ? null : s); // binary files are not read
|
|
232
269
|
const at = (ref, p) => { try { return text(git('show', `${ref}:${p}`)); } catch { return null; } };
|
|
233
270
|
const disk = (p) => { try { return text(readFileSync(join(root, p), 'utf8')); } catch { return null; } };
|
|
@@ -307,6 +344,9 @@ function parseArgs(argv) {
|
|
|
307
344
|
else if (a === '--expand') args.expand = argv[++i];
|
|
308
345
|
else if (a === '--now') args.now = argv[++i];
|
|
309
346
|
else if (a === '--format') args.format = argv[++i];
|
|
347
|
+
else if (a === '--base') args.base = argv[++i];
|
|
348
|
+
else if (a === '--head') args.head = argv[++i];
|
|
349
|
+
else if (a === '--paths') args.paths = (argv[++i] || '').split(/[,\n]/).map((p) => p.trim()).filter(Boolean);
|
|
310
350
|
else if (a === '--inputs') args.inputs = argv[++i];
|
|
311
351
|
else if (a === '--events') args.events = (argv[++i] || '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
312
352
|
else if (a === '--decision') args.decision = argv[++i];
|
|
@@ -319,6 +359,9 @@ function parseArgs(argv) {
|
|
|
319
359
|
else if (a === '--when') args.when = argv[++i];
|
|
320
360
|
else if (a === '--to') args.to = argv[++i];
|
|
321
361
|
else if (a === '--force') args.force = true;
|
|
362
|
+
else if (a === '--mission') args.mission = true;
|
|
363
|
+
else if (a === '--core') args.core = true;
|
|
364
|
+
else if (a === '--as-core') args.asCore = true;
|
|
322
365
|
else if (a === '--write' || a === '-w') args.write = true;
|
|
323
366
|
else if (a === '--check') args.check = true;
|
|
324
367
|
else if (a === '--schema') args.schema = true;
|
|
@@ -419,8 +462,13 @@ The flow: author intent, inspect it, run and prove it, then keep real code align
|
|
|
419
462
|
usage: thunder <command> <file> [options]
|
|
420
463
|
thunder mission <Name> <command> run any command on a mission by name
|
|
421
464
|
|
|
465
|
+
Write and run programs (Thunder Core, docs/core.md)
|
|
466
|
+
new <dir> create a Thunder Core project: thunder.toml, src/main.thunder, tests/
|
|
467
|
+
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+
|
|
469
|
+
|
|
422
470
|
Author
|
|
423
|
-
|
|
471
|
+
init [Name] scaffold a runnable starter mission (Name.thunder) [alias: new --mission Name]
|
|
424
472
|
mission <Name> [cmd] resolve a mission by name and run a command on it (list | <Name> | <Name> <cmd>)
|
|
425
473
|
draft --brief <json|-> scaffold a rigorous intent draft + gap checklist from a brief
|
|
426
474
|
edit <file> [--edits <json|->] [--set-goal ..] [--add-guarantee ..] [--write] structural edits, comments kept
|
|
@@ -497,13 +545,17 @@ Graph & IR
|
|
|
497
545
|
Thunder write: change a number, comparison, text value, or answer in a recovered rule;
|
|
498
546
|
previews the exact code change and the cases whose answer changes; --write saves it
|
|
499
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)
|
|
500
551
|
thunderize <folder | owner/repo> [--out <dir>] [--json] the whole app in Thunder Text: one .thunder-text per file + APP.thunder-text
|
|
501
|
-
review <base-ref> [head-ref] [--json] [--out <file>]
|
|
552
|
+
review <base-ref> [head-ref] [--format markdown|json] [--paths <glob,...>] [--out <file>]
|
|
502
553
|
review in Thunder: what changed in meaning between two git commits (head: the working tree
|
|
503
554
|
when omitted), as Markdown for a pull request comment; read from git, no network
|
|
504
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)
|
|
505
556
|
text <file> [--json | --format source] experimental Thunder Text rule (.thunder-plain): run its examples [alias: plain]
|
|
506
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
|
|
507
559
|
for a folder also: [--answer <Outcome>] [--input <name>] [--lang go,rust] [--path <prefix>] [--limit n]
|
|
508
560
|
--promote <decision> [--out <file>] turn a recovered decision into a contract with starter examples
|
|
509
561
|
read code you don't know: its decision rules as ThunderLang + plain English,
|
|
@@ -542,10 +594,32 @@ function main() {
|
|
|
542
594
|
process.exitCode = cmd ? 0 : 2;
|
|
543
595
|
return;
|
|
544
596
|
}
|
|
597
|
+
// Thunder Trace: links between repositories and what a change can affect (src/trace-cli.mjs).
|
|
598
|
+
if (cmd === 'trace') { process.exitCode = traceMain(restArgv); return; }
|
|
599
|
+
// Thunder Why: an AI agent's run explained in plain words, from its OpenTelemetry record (src/why-cli.mjs).
|
|
600
|
+
if (cmd === 'why') { process.exitCode = whyMain(restArgv); return; }
|
|
601
|
+
// Thunder Core (programs you write and run): thunder new <dir>, and run/build/test/check/format inside a
|
|
602
|
+
// project with thunder.toml (or with --core). Mission files fall through unchanged. See src/core/cli.mjs.
|
|
603
|
+
const coreCode = coreMain(cmd, restArgv);
|
|
604
|
+
if (coreCode !== null) { process.exitCode = coreCode; return; }
|
|
545
605
|
if (cmd === 'read') {
|
|
546
606
|
try {
|
|
547
607
|
if (!file) throw new Error('Use thunder read <file> [--search q] [--kind decision,function,error,test] [--in <lang>] [--json].');
|
|
548
608
|
if (statSync(file).isDirectory()) { readFolder(file, args); return; }
|
|
609
|
+
if (args.asCore) {
|
|
610
|
+
// Reading and writing are one language: the reader's meaning tree printed as Thunder Core (docs/core.md).
|
|
611
|
+
if (!/\.py$/i.test(file) && (args.from || 'python') !== 'python') throw new Error('--as-core reads Python for now (other languages next).');
|
|
612
|
+
const r = pythonToCore(readFileSync(file, 'utf8'));
|
|
613
|
+
if (args.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
614
|
+
console.log(r.core.trimEnd());
|
|
615
|
+
const all = [...r.module.notTranslated, ...r.functions.flatMap((f) => f.notTranslated)];
|
|
616
|
+
const exact = r.functions.filter((f) => f.exact);
|
|
617
|
+
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)` : ''}.`);
|
|
618
|
+
for (const f of r.functions.filter((x) => !x.exact)) console.error(` ${f.name}: not safely editable: ${f.notTranslated.map((n) => `line ${n.line}: ${n.why}`).join('; ')}`);
|
|
619
|
+
const assumes = r.functions.flatMap((f) => f.assumptions.map((a) => `${f.name}, line ${a.line}: ${a.says}`));
|
|
620
|
+
for (const a of assumes) console.error(` assumes: ${a}`);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
549
623
|
if (args.promote) {
|
|
550
624
|
const items = statSync(file).isDirectory()
|
|
551
625
|
? searchRepo(readRepo(collectReadableFiles(file)), { path: args.pathPrefix || '' })
|
|
@@ -708,10 +782,12 @@ function main() {
|
|
|
708
782
|
}
|
|
709
783
|
if (cmd === 'review') {
|
|
710
784
|
try {
|
|
711
|
-
const [
|
|
712
|
-
if (!base) throw new Error('Use thunder review <base-ref> [head-ref] [--json] [--out <file>]. Without head
|
|
713
|
-
|
|
714
|
-
const
|
|
785
|
+
const base = args.base ?? args._[0], head = args.head ?? (args.base ? null : args._[1]);
|
|
786
|
+
if (!base) throw new Error('Use thunder review <base-ref> [head-ref] (or --base <ref> --head <ref>) [--format markdown|json] [--paths <glob,...>] [--out <file>]. Without a head, the working tree is the new side.');
|
|
787
|
+
if (args.format && !['markdown', 'json'].includes(args.format)) throw new Error(`--format ${args.format} is not one of markdown, json.`);
|
|
788
|
+
const json = args.json || args.format === 'json';
|
|
789
|
+
const r = reviewGit(base, head ?? null, args.paths ?? []);
|
|
790
|
+
const text = json ? JSON.stringify(r, null, 2) : renderReview(r, { footer: `<sub>\`thunder review ${base}${head ? ` ${head}` : ''}\` · Thunder compiler ${COMPILER_VERSION}</sub>` }).trimEnd();
|
|
715
791
|
if (args.outExplicit) { mkdirSync(dirname(resolve(args.out)), { recursive: true }); writeFileSync(args.out, `${text}\n`); console.log(`thunder review: ${r.says} Wrote ${args.out}.`); }
|
|
716
792
|
else console.log(text);
|
|
717
793
|
} catch (e) { console.error(`thunder review: ${e.message}`); process.exitCode = 2; }
|
|
@@ -1052,7 +1128,14 @@ function main() {
|
|
|
1052
1128
|
const generate = GENERATORS[target];
|
|
1053
1129
|
if (!generate) { console.error(`thunder gen: unknown target "${target}" (have: ${Object.keys(GENERATORS).join(', ')})`); process.exit(2); return; }
|
|
1054
1130
|
const ast = parseIntent(readFileSync(file, 'utf8'));
|
|
1055
|
-
|
|
1131
|
+
// IL-GEN-001: a rule condition the target cannot express fails generation for that rule. The code
|
|
1132
|
+
// is still emitted (that rule throws at runtime with the same message), and the command exits 1.
|
|
1133
|
+
const { code, diagnostics } = generateWithDiagnostics(ast, target);
|
|
1134
|
+
const reportGen = () => {
|
|
1135
|
+
for (const d of diagnostics) console.error(`thunder gen: error ${d.code} (decision ${d.decision}, rule ${d.rule}): ${d.message}`);
|
|
1136
|
+
if (diagnostics.length) console.error(`thunder gen: ${diagnostics.length} rule condition(s) not translated; those rules throw instead of deciding. Run "thunder explain ${diagnostics[0].code}".`);
|
|
1137
|
+
};
|
|
1138
|
+
if (args.json) { console.log(JSON.stringify({ schema: 'intent-codegen-v1', target, code, diagnostics }, null, 2)); process.exit(diagnostics.length ? 1 : 0); return; }
|
|
1056
1139
|
if (args.outExplicit) {
|
|
1057
1140
|
const ext = target.startsWith('ts') || target === 'typescript' ? 'ts' : target === 'python' ? 'py' : target === 'csharp' ? 'cs' : target;
|
|
1058
1141
|
// Java requires a public class to live in a file of exactly its name (RefundDecision.java).
|
|
@@ -1060,9 +1143,13 @@ function main() {
|
|
|
1060
1143
|
const fileName = ext === 'java' ? `${(subject[0].toUpperCase() + subject.slice(1)).replace(/[^A-Za-z0-9]/g, '')}.java` : `${slug(subject)}.${ext}`;
|
|
1061
1144
|
const p = writeText(args.out, fileName, code.endsWith('\n') ? code : code + '\n');
|
|
1062
1145
|
console.log(`wrote ${p.replace(process.cwd() + '/', '')}`);
|
|
1146
|
+
reportGen();
|
|
1147
|
+
if (diagnostics.length) process.exit(1);
|
|
1063
1148
|
return;
|
|
1064
1149
|
}
|
|
1065
1150
|
console.log(code);
|
|
1151
|
+
reportGen();
|
|
1152
|
+
if (diagnostics.length) { process.exit(1); return; }
|
|
1066
1153
|
return;
|
|
1067
1154
|
}
|
|
1068
1155
|
|
|
@@ -1665,34 +1752,26 @@ test Example
|
|
|
1665
1752
|
// All-targets mode: run the tests against EVERY target whose toolchain is available, in one
|
|
1666
1753
|
// pass, and report each target's pass count side by side. `thunder test <file> --all-targets`.
|
|
1667
1754
|
if (args.allTargets) {
|
|
1668
|
-
const gradeCases = (actual) => {
|
|
1669
|
-
const cs = [];
|
|
1670
|
-
for (const t of ast.tests || []) {
|
|
1671
|
-
if (!(ast.decisions || []).some((d) => d.name === t.name)) continue;
|
|
1672
|
-
for (const c of t.cases || []) {
|
|
1673
|
-
const key = `${t.name} / ${c.name || 'case'}`;
|
|
1674
|
-
const act = actual[key];
|
|
1675
|
-
cs.push({ key, expected: c.expect, actual: act, pass: c.expect == null || String(act) === String(c.expect) });
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
return cs;
|
|
1679
|
-
};
|
|
1680
1755
|
const report = LIVE_TARGETS.map((t) => {
|
|
1681
|
-
const
|
|
1682
|
-
if (
|
|
1683
|
-
|
|
1756
|
+
const run = t.available() ? t.run(ast) : runFailure('missing-toolchain', `${t.key} toolchain not available`);
|
|
1757
|
+
if (run.status === 'error' && run.kind === 'missing-toolchain') return { target: t.key, status: 'skipped', reason: run.message, kind: run.kind };
|
|
1758
|
+
// A compile failure, crash, or timeout is an error for the whole target, not a skip and not a pass.
|
|
1759
|
+
if (run.status === 'error') return { target: t.key, status: 'error', kind: run.kind, message: run.message, total: 0, passed: 0, cases: gradeRun(ast, run) };
|
|
1760
|
+
const cases = gradeRun(ast, run);
|
|
1684
1761
|
const passed = cases.filter((c) => c.pass).length;
|
|
1685
|
-
|
|
1762
|
+
const errors = cases.filter((c) => c.status === 'error').length;
|
|
1763
|
+
return { target: t.key, status: passed === cases.length ? 'pass' : 'fail', total: cases.length, passed, errors, cases };
|
|
1686
1764
|
});
|
|
1687
|
-
const bad = report.some((r) => r.status === 'fail');
|
|
1765
|
+
const bad = report.some((r) => r.status === 'fail' || r.status === 'error');
|
|
1688
1766
|
if (args.json) { console.log(JSON.stringify({ schema: 'thunder-all-targets-v1', mission: ast.mission, file: basename(file), targets: report }, null, 2)); process.exit(bad ? 1 : 0); return; }
|
|
1689
|
-
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
1767
|
+
const cap = (s) => ({ typescript: 'TypeScript', csharp: 'C#', javascript: 'JavaScript' })[s] ?? s.charAt(0).toUpperCase() + s.slice(1);
|
|
1690
1768
|
const ran = report.filter((r) => r.status !== 'skipped');
|
|
1691
1769
|
console.log(`thunder test ${basename(file)} --all-targets: ${ran.length}/${report.length} target(s) executed`);
|
|
1692
1770
|
for (const r of report) {
|
|
1693
1771
|
if (r.status === 'skipped') { console.log(` SKIP ${cap(r.target).padEnd(12)} (toolchain not available)`); continue; }
|
|
1694
|
-
|
|
1695
|
-
|
|
1772
|
+
if (r.status === 'error') { console.log(` ERROR ${cap(r.target).padEnd(12)} ${r.kind}: ${r.message}`); continue; }
|
|
1773
|
+
console.log(` ${r.status === 'pass' ? 'PASS' : 'FAIL'} ${cap(r.target).padEnd(12)} ${r.passed}/${r.total} passed (executed generated code)${r.errors ? `, ${r.errors} could not run` : ''}`);
|
|
1774
|
+
for (const c of r.cases) if (!c.pass) console.log(` ${caseLine(c)}`);
|
|
1696
1775
|
}
|
|
1697
1776
|
process.exit(bad ? 1 : 0);
|
|
1698
1777
|
return;
|
|
@@ -1703,29 +1782,28 @@ test Example
|
|
|
1703
1782
|
// `thunder test <file> --target typescript`.
|
|
1704
1783
|
if (args.target && RUNNABLE_TARGETS.has(String(args.target).toLowerCase())) {
|
|
1705
1784
|
const targetKey = canonicalTarget(args.target);
|
|
1706
|
-
const
|
|
1707
|
-
// Live target could not run (e.g. python3 not installed) , skip cleanly, don't fail.
|
|
1708
|
-
if (
|
|
1709
|
-
if (args.json) { console.log(JSON.stringify({ schema: 'thunder-target-v1', target: targetKey, skipped: true, reason: `${targetKey} runtime unavailable
|
|
1785
|
+
const run = runLiveTarget(ast, targetKey);
|
|
1786
|
+
// Live target could not run because its toolchain is missing (e.g. python3 not installed) , skip cleanly, don't fail.
|
|
1787
|
+
if (run.status === 'error' && run.kind === 'missing-toolchain') {
|
|
1788
|
+
if (args.json) { console.log(JSON.stringify({ schema: 'thunder-target-v1', target: targetKey, skipped: true, reason: `${targetKey} runtime unavailable`, error: { kind: run.kind, message: run.message } }, null, 2)); return; }
|
|
1710
1789
|
console.log(`thunder test ${basename(file)} --target ${targetKey}: skipped (the ${targetKey} runtime is not available on this machine).`);
|
|
1711
1790
|
return;
|
|
1712
1791
|
}
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
const act = actual[key];
|
|
1720
|
-
cases.push({ key, expected: c.expect, actual: act, pass: c.expect == null || String(act) === String(c.expect) });
|
|
1721
|
-
}
|
|
1792
|
+
// Any other whole-run failure (compile failure, crash, timeout) is an error with its reason, never a null answer.
|
|
1793
|
+
if (run.status === 'error') {
|
|
1794
|
+
if (args.json) { console.log(JSON.stringify({ schema: 'thunder-target-v1', target: targetKey, status: 'error', error: { kind: run.kind, message: run.message }, cases: gradeRun(ast, run) }, null, 2)); process.exit(1); return; }
|
|
1795
|
+
console.log(`thunder test ${basename(file)} --target ${targetKey}: ERROR (${run.kind}) , ${run.message}`);
|
|
1796
|
+
process.exit(1);
|
|
1797
|
+
return;
|
|
1722
1798
|
}
|
|
1799
|
+
const cases = gradeRun(ast, run);
|
|
1723
1800
|
const passed = cases.filter((c) => c.pass).length;
|
|
1801
|
+
const errors = cases.filter((c) => c.status === 'error').length;
|
|
1724
1802
|
const bad = passed !== cases.length;
|
|
1725
|
-
if (args.json) { console.log(JSON.stringify({ schema: 'thunder-target-v1', target: targetKey, total: cases.length, passed, cases }, null, 2)); process.exit(bad ? 1 : 0); return; }
|
|
1803
|
+
if (args.json) { console.log(JSON.stringify({ schema: 'thunder-target-v1', target: targetKey, total: cases.length, passed, errors, cases }, null, 2)); process.exit(bad ? 1 : 0); return; }
|
|
1726
1804
|
if (!cases.length) { console.log(`thunder test ${basename(file)} --target ${targetKey}: no decision test cases to run.`); return; }
|
|
1727
|
-
console.log(`thunder test ${basename(file)} --target ${targetKey}: ${passed}/${cases.length} passed (executed generated code)`);
|
|
1728
|
-
for (const c of cases) console.log(` ${c.pass ?
|
|
1805
|
+
console.log(`thunder test ${basename(file)} --target ${targetKey}: ${passed}/${cases.length} passed (executed generated code)${errors ? `, ${errors} could not run` : ''}`);
|
|
1806
|
+
for (const c of cases) console.log(` ${c.pass ? `PASS ${c.key}` : caseLine(c).replace(/^(FAIL|ERROR) /, (m) => m.trim().padEnd(6))}`);
|
|
1729
1807
|
process.exit(bad ? 1 : 0);
|
|
1730
1808
|
return;
|
|
1731
1809
|
}
|
|
@@ -1953,19 +2031,23 @@ test Example
|
|
|
1953
2031
|
targets = Array.from(new Set([...targets, ...LIVE_TARGETS.map((t) => t.key)]));
|
|
1954
2032
|
for (const t of LIVE_TARGETS) {
|
|
1955
2033
|
if (!t.available()) { skippedTargets.push(t.key); continue; }
|
|
1956
|
-
const
|
|
1957
|
-
if (
|
|
2034
|
+
const run = t.run(ast);
|
|
2035
|
+
if (run.status === 'error' && run.kind === 'missing-toolchain') skippedTargets.push(t.key);
|
|
2036
|
+
else results[t.key] = caseResultsOf(ast, run);
|
|
1958
2037
|
}
|
|
1959
2038
|
}
|
|
1960
2039
|
// --run <targets>: execute specific live targets (TypeScript/JS/Python/C#/Java) and grade real
|
|
1961
|
-
// outputs. A
|
|
2040
|
+
// outputs. A missing toolchain is skipped, leaving it "declared"; any other failure (not
|
|
2041
|
+
// translated, compile failure, crash, timeout) is graded as an error with its reason.
|
|
1962
2042
|
if (args.run && args.run.length) {
|
|
1963
2043
|
results = results || {};
|
|
1964
2044
|
for (const rt of args.run) {
|
|
1965
2045
|
if (!RUNNABLE_TARGETS.has(rt.toLowerCase())) continue;
|
|
1966
2046
|
const key = canonicalTarget(rt);
|
|
1967
|
-
|
|
1968
|
-
|
|
2047
|
+
if (!targets.includes(key)) targets = [...targets, key]; // a target you ran is always shown
|
|
2048
|
+
const run = runLiveTarget(ast, key);
|
|
2049
|
+
if (run.status === 'error' && run.kind === 'missing-toolchain') skippedTargets.push(key);
|
|
2050
|
+
else results[key] = caseResultsOf(ast, run);
|
|
1969
2051
|
}
|
|
1970
2052
|
}
|
|
1971
2053
|
const rep = buildConformance(ast, { targets, results });
|
|
@@ -1979,7 +2061,7 @@ test Example
|
|
|
1979
2061
|
if (args.json) { console.log(JSON.stringify(rep, null, 2)); process.exit(bad ? 1 : 0); return; }
|
|
1980
2062
|
if (!rep.total) { console.log(`thunder conform ${basename(file)}: no test cases to conform.`); return; }
|
|
1981
2063
|
|
|
1982
|
-
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
2064
|
+
const cap = (s) => ({ typescript: 'TypeScript', csharp: 'C#', javascript: 'JavaScript' })[s] ?? s.charAt(0).toUpperCase() + s.slice(1);
|
|
1983
2065
|
const cols = ['Semantic', ...rep.columns.map(cap)];
|
|
1984
2066
|
const labelW = Math.max(12, ...rep.cases.map((c) => c.key.length));
|
|
1985
2067
|
const cw = (h) => Math.max(h.length, 8);
|
|
@@ -1990,7 +2072,7 @@ test Example
|
|
|
1990
2072
|
const sem = c.semanticPass ? 'PASS' : 'FAIL';
|
|
1991
2073
|
const tcells = rep.columns.map((col) => {
|
|
1992
2074
|
const s = c.targets[col].status;
|
|
1993
|
-
return cell(s === 'pass' ? 'PASS' : s === 'fail' ? 'FAIL' : '—', cw(cap(col)));
|
|
2075
|
+
return cell(s === 'pass' ? 'PASS' : s === 'fail' ? 'FAIL' : s === 'error' ? 'ERROR' : '—', cw(cap(col)));
|
|
1994
2076
|
});
|
|
1995
2077
|
console.log(` ${cell(c.key, labelW)} ${cell(sem, cw('Semantic'))} ${tcells.join(' ')}`);
|
|
1996
2078
|
}
|
|
@@ -2000,7 +2082,8 @@ test Example
|
|
|
2000
2082
|
console.log(` Target: ${cap(f.target)}`);
|
|
2001
2083
|
console.log(` Case: ${f.case}`);
|
|
2002
2084
|
console.log(` Expected: ${f.expected}`);
|
|
2003
|
-
console.log(`
|
|
2085
|
+
if (f.kind && f.kind !== 'assertion-failed') console.log(` Result: ${f.kind === 'not-translated' ? 'not translated' : f.kind === 'missing-input' ? 'missing input' : f.kind} , ${f.message}`);
|
|
2086
|
+
else console.log(` Actual: ${f.actual === null ? 'null' : f.actual}`);
|
|
2004
2087
|
}
|
|
2005
2088
|
if (rep.skipped && rep.skipped.length) {
|
|
2006
2089
|
console.log('');
|