@skillstech/thunderlang 1.2.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/dist/core.cjs +2080 -278
  3. package/dist/index.cjs +12742 -10943
  4. package/dist/learn.cjs +2716 -345
  5. package/package.json +1 -1
  6. package/src/cli.mjs +31 -6
  7. package/src/core/ThunderRuntime.cs +1367 -0
  8. package/src/core/check.mjs +158 -2
  9. package/src/core/cli.mjs +148 -8
  10. package/src/core/csharp-run.mjs +184 -0
  11. package/src/core/diagnostics.mjs +13 -1
  12. package/src/core/engine-core.mjs +285 -2
  13. package/src/core/engine-values.mjs +1 -1
  14. package/src/core/format.mjs +191 -3
  15. package/src/core/go-run.mjs +106 -0
  16. package/src/core/index.mjs +2 -1
  17. package/src/core/java/thunder/T.java +6 -0
  18. package/src/core/java/thunder/ThunderRuntime.java +1374 -0
  19. package/src/core/java-run.mjs +89 -0
  20. package/src/core/parser.mjs +331 -5
  21. package/src/core/project.mjs +31 -6
  22. package/src/core/react-run.mjs +96 -0
  23. package/src/core/runtime-go/thunder_runtime.go +3038 -0
  24. package/src/core/runtime-react.mjs +133 -0
  25. package/src/core/rust/thunder_runtime.rs +1645 -0
  26. package/src/core/rust-run.mjs +192 -0
  27. package/src/core/screen-values.mjs +30 -0
  28. package/src/core/target-csharp.mjs +484 -0
  29. package/src/core/target-go.mjs +555 -0
  30. package/src/core/target-java.mjs +587 -0
  31. package/src/core/target-react.mjs +270 -0
  32. package/src/core/target-rust.mjs +534 -0
  33. package/src/core/target-typescript.mjs +2 -2
  34. package/src/core.d.ts +18 -0
  35. package/src/core.mjs +1 -0
  36. package/src/emit.mjs +1 -1
  37. package/src/faithful.mjs +30 -0
  38. package/src/libraries.mjs +10 -3
  39. package/src/model.mjs +50 -8
  40. package/src/read-level.mjs +48 -2
  41. package/src/read-repo-fs.mjs +3 -1
  42. package/src/read.mjs +28 -5
  43. package/src/replay-cli.mjs +123 -0
  44. package/src/say-less.mjs +152 -11
  45. package/src/screens.mjs +833 -0
  46. package/src/steps.mjs +430 -19
  47. package/src/term.mjs +43 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillstech/thunderlang",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
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",
package/src/cli.mjs CHANGED
@@ -53,9 +53,11 @@ import { LEVELS, readLevel, renderLevel, findFocus, nearestLevel } from './read-
53
53
  import { traceMain } from './trace-cli.mjs';
54
54
  import { whyMain } from './why-cli.mjs';
55
55
  import { tryMain } from './try-cli.mjs';
56
+ import { replayMain } from './replay-cli.mjs';
56
57
  import { homeText, helpFor, knownCommands, unknownCommandText, noProjectText, doctorMain, completionMain } from './cli-home.mjs';
57
- import { paint, paintHelp, useColor } from './term.mjs';
58
+ import { paint, paintHelp, paintThunder, useColor } from './term.mjs';
58
59
  import { coreMain } from './core/cli.mjs';
60
+ import { findProjectRoot } from './core/project.mjs';
59
61
  import { pythonToCore } from './core/from-python.mjs';
60
62
  import { guardSummary } from './guard.mjs';
61
63
  import { draftIntent } from './draft.mjs';
@@ -475,7 +477,10 @@ Write and run programs (Thunder Core, docs/core.md)
475
477
  add --core for a single file with no project. run/test need Python 3.10+, or add
476
478
  --engine thunder to run them on the Thunder engine (no Python; programs that Use a
477
479
  Python module are refused there). --target typescript compiles to TypeScript instead
478
- (generated/typescript/; runs on Node 22.6+, or with the typescript package)
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+)
479
484
 
480
485
  Read and understand code
481
486
  read <file|dir> [--search q] [--kind decision,function,error,test] [--in <lang>] [--from <lang>] [--json]
@@ -487,6 +492,7 @@ Read and understand code
487
492
  --promote <decision> [--out <file>] turn a recovered decision into a contract with starter examples
488
493
  read code you don't know: its decision rules as ThunderLang + plain English,
489
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
490
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)
491
497
  why <run.json> [--step n] [--json] what an AI agent did and why it stopped, in plain words, from its OpenTelemetry record
492
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)
@@ -638,6 +644,8 @@ function main() {
638
644
  if (cmd === 'why') { process.exitCode = whyMain(restArgv); return; }
639
645
  // Thunder Try: try a rule from your code with your own values, and see the answer and why (src/try-cli.mjs).
640
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; }
641
649
  // Thunder Core (programs you write and run): thunder new <dir>, and run/build/test/check/format inside a
642
650
  // project with thunder.toml (or with --core). Mission files fall through unchanged. See src/core/cli.mjs.
643
651
  const coreCode = coreMain(cmd, restArgv);
@@ -653,7 +661,9 @@ function main() {
653
661
  throw new Error(`there is no level "${args.level}". The levels are: ${ids.join(', ')}.${near ? ` Did you mean --level ${near}?` : ''}`);
654
662
  }
655
663
  const isDir = statSync(file).isDirectory();
656
- const files = isDir ? collectReadableFiles(file, { maxFiles: 5000 }).filter((f) => f.source) : [{ path: basename(file), source: readFileSync(file, 'utf8') }];
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 */ } }
657
667
  const model = thunderModel(files, { name: basename(resolve(file)) });
658
668
  const focus = findFocus(model, args.focus);
659
669
  if (focus.error) throw new Error(focus.error);
@@ -668,7 +678,7 @@ function main() {
668
678
  if (!/\.py$/i.test(file) && (args.from || 'python') !== 'python') throw new Error('--as-core reads Python for now (other languages next).');
669
679
  const r = pythonToCore(readFileSync(file, 'utf8'));
670
680
  if (args.json) { console.log(JSON.stringify(r, null, 2)); return; }
671
- console.log(r.core.trimEnd());
681
+ console.log(paintThunder(r.core.trimEnd()));
672
682
  const all = [...r.module.notTranslated, ...r.functions.flatMap((f) => f.notTranslated)];
673
683
  const exact = r.functions.filter((f) => f.exact);
674
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)` : ''}.`);
@@ -947,7 +957,7 @@ function main() {
947
957
  if (opt('--otlp')) evidence.push(...fromOtlp(readFileSync(opt('--otlp'), 'utf8')));
948
958
  } catch (e) { console.error(`thunder runtime: ${e.message}`); process.exit(2); return; }
949
959
  if (!evidence.length) { console.error(`thunder runtime: no evidence given.\n${usage}`); process.exit(2); return; }
950
- 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)) });
951
961
  const overlay = runtimeOverlay(model, evidence);
952
962
  const explained = stacks.map((s) => explainError(model, s));
953
963
  if (restArgv.includes('--json')) { console.log(JSON.stringify({ ...overlay, errors: explained }, null, 2)); return; }
@@ -2747,4 +2757,19 @@ test Example
2747
2757
  printDiagnostics(diagnostics);
2748
2758
  }
2749
2759
 
2750
- main();
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; }