@skillstech/thunderlang 1.2.0 → 1.4.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 (63) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/dist/core.cjs +6718 -1232
  3. package/dist/index.cjs +17490 -12204
  4. package/dist/learn.cjs +5866 -497
  5. package/package.json +6 -2
  6. package/src/cli-home.mjs +1 -1
  7. package/src/cli.mjs +54 -6
  8. package/src/core/ThunderRuntime.cs +1367 -0
  9. package/src/core/check.mjs +158 -2
  10. package/src/core/cli.mjs +148 -8
  11. package/src/core/csharp-run.mjs +184 -0
  12. package/src/core/diagnostics.mjs +13 -1
  13. package/src/core/engine-core.mjs +285 -2
  14. package/src/core/engine-values.mjs +1 -1
  15. package/src/core/format.mjs +191 -3
  16. package/src/core/go-run.mjs +106 -0
  17. package/src/core/index.mjs +2 -1
  18. package/src/core/java/thunder/T.java +6 -0
  19. package/src/core/java/thunder/ThunderRuntime.java +1374 -0
  20. package/src/core/java-run.mjs +89 -0
  21. package/src/core/parser.mjs +331 -5
  22. package/src/core/project.mjs +31 -6
  23. package/src/core/react-run.mjs +96 -0
  24. package/src/core/runtime-go/thunder_runtime.go +3038 -0
  25. package/src/core/runtime-react.mjs +133 -0
  26. package/src/core/rust/thunder_runtime.rs +1645 -0
  27. package/src/core/rust-run.mjs +192 -0
  28. package/src/core/screen-values.mjs +30 -0
  29. package/src/core/target-csharp.mjs +484 -0
  30. package/src/core/target-go.mjs +555 -0
  31. package/src/core/target-java.mjs +587 -0
  32. package/src/core/target-react.mjs +270 -0
  33. package/src/core/target-rust.mjs +534 -0
  34. package/src/core/target-typescript.mjs +2 -2
  35. package/src/core.d.ts +59 -0
  36. package/src/core.mjs +14 -0
  37. package/src/emit.mjs +1 -1
  38. package/src/faithful.mjs +34 -1
  39. package/src/flow/access.mjs +1451 -0
  40. package/src/flow/ts-parse.mjs +772 -0
  41. package/src/index.d.ts +3 -0
  42. package/src/index.mjs +3 -0
  43. package/src/libraries.mjs +32 -4
  44. package/src/model.mjs +72 -9
  45. package/src/passport-cli.mjs +101 -0
  46. package/src/passport-fs.d.mts +9 -0
  47. package/src/passport-fs.mjs +180 -0
  48. package/src/passport.d.mts +46 -0
  49. package/src/passport.mjs +255 -0
  50. package/src/program.d.mts +31 -0
  51. package/src/program.mjs +14 -0
  52. package/src/read-level.mjs +48 -2
  53. package/src/read-repo-fs.mjs +3 -1
  54. package/src/read.mjs +64 -5
  55. package/src/replay-cli.mjs +123 -0
  56. package/src/review.mjs +31 -3
  57. package/src/say-less.mjs +168 -13
  58. package/src/screens.mjs +833 -0
  59. package/src/steps.mjs +443 -20
  60. package/src/term.mjs +43 -0
  61. package/src/things-langs.mjs +20 -3
  62. package/src/write-across-cli.mjs +143 -0
  63. package/src/write-across.mjs +168 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@skillstech/thunderlang",
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.",
3
+ "version": "1.4.0",
4
+ "description": "Thunder\u2122, the human programming language: the deterministic ThunderLang\u2122 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",
@@ -33,6 +33,10 @@
33
33
  "import": "./src/learn.mjs",
34
34
  "require": "./dist/learn.cjs"
35
35
  },
36
+ "./program": {
37
+ "types": "./src/program.d.mts",
38
+ "import": "./src/program.mjs"
39
+ },
36
40
  "./package.json": "./package.json"
37
41
  },
38
42
  "bin": {
package/src/cli-home.mjs CHANGED
@@ -9,7 +9,7 @@ import { findPython, findProjectRoot } from './core/project.mjs';
9
9
  import { paint, useColor } from './term.mjs';
10
10
 
11
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'];
12
+ export const EXTRA_COMMANDS = ['doctor', 'completion', 'plain', 'ai', 'coverage', 'completions', 'hover', 'format', 'help', 'version', 'mission', 'why', 'trace', 'passport', 'graph', 'proof', 'build'];
13
13
 
14
14
  /** Every command name: the ones the full help lists, plus EXTRA_COMMANDS. */
15
15
  export function knownCommands(fullHelp) {
package/src/cli.mjs CHANGED
@@ -27,6 +27,7 @@ import { readCode, searchReading } from './read.mjs';
27
27
  import { readRepo, searchRepo, groupByFile } from './read-repo.mjs';
28
28
  import { promoteDecision } from './promote.mjs';
29
29
  import { collectReadableFiles } from './read-repo-fs.mjs';
30
+ import { accessFlow, accessText } from './flow/access.mjs';
30
31
  import { translateDecisions } from './translate.mjs';
31
32
  import {
32
33
  buildContractGraph, buildArchitectureGraph, buildImplementationPlan,
@@ -51,11 +52,15 @@ import { runtimeOverlay, runtimeText, fromTrace, fromStack, fromLogs, fromOtlp,
51
52
  import { thunderModel } from './model.mjs';
52
53
  import { LEVELS, readLevel, renderLevel, findFocus, nearestLevel } from './read-level.mjs';
53
54
  import { traceMain } from './trace-cli.mjs';
55
+ import { passportMain } from './passport-cli.mjs';
56
+ import { isWriteAcross, writeAcrossMain } from './write-across-cli.mjs';
54
57
  import { whyMain } from './why-cli.mjs';
55
58
  import { tryMain } from './try-cli.mjs';
59
+ import { replayMain } from './replay-cli.mjs';
56
60
  import { homeText, helpFor, knownCommands, unknownCommandText, noProjectText, doctorMain, completionMain } from './cli-home.mjs';
57
- import { paint, paintHelp, useColor } from './term.mjs';
61
+ import { paint, paintHelp, paintThunder, useColor } from './term.mjs';
58
62
  import { coreMain } from './core/cli.mjs';
63
+ import { findProjectRoot } from './core/project.mjs';
59
64
  import { pythonToCore } from './core/from-python.mjs';
60
65
  import { guardSummary } from './guard.mjs';
61
66
  import { draftIntent } from './draft.mjs';
@@ -368,6 +373,7 @@ function parseArgs(argv) {
368
373
  else if (a === '--mission') args.mission = true;
369
374
  else if (a === '--core') args.core = true;
370
375
  else if (a === '--as-core') args.asCore = true;
376
+ else if (a === '--access') args.access = true;
371
377
  else if (a === '--write' || a === '-w') args.write = true;
372
378
  else if (a === '--check') args.check = true;
373
379
  else if (a === '--schema') args.schema = true;
@@ -475,18 +481,23 @@ Write and run programs (Thunder Core, docs/core.md)
475
481
  add --core for a single file with no project. run/test need Python 3.10+, or add
476
482
  --engine thunder to run them on the Thunder engine (no Python; programs that Use a
477
483
  Python module are refused there). --target typescript compiles to TypeScript instead
478
- (generated/typescript/; runs on Node 22.6+, or with the typescript package)
484
+ (generated/typescript/; runs on Node 22.6+, or with the typescript package);
485
+ --target csharp compiles to C# (generated/csharp/; builds and runs with the .NET 8+ SDK)
486
+ --target go compiles to Go (generated/go/; needs the go toolchain to run)
487
+ --target java compiles to Java (generated/java/; runs with a JDK 17+)
479
488
 
480
489
  Read and understand code
481
490
  read <file|dir> [--search q] [--kind decision,function,error,test] [--in <lang>] [--from <lang>] [--json]
482
491
  read <file|dir> --level big-picture|flow|details|text|original [--focus "<action or rule>"] [--json]
483
492
  read at one depth, from the same model OpenThunder shows: the big picture, one action's flow,
484
493
  its exact details, its Thunder Text, or the original lines
494
+ read <dir> --access which web routes limit a record chosen by the request to the caller (TypeScript/JavaScript)
485
495
  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
496
  for a folder also: [--answer <Outcome>] [--input <name>] [--lang go,rust] [--path <prefix>] [--limit n]
487
497
  --promote <decision> [--out <file>] turn a recovered decision into a contract with starter examples
488
498
  read code you don't know: its decision rules as ThunderLang + plain English,
489
499
  optionally rewritten in a language you know (--in typescript|python|go|rust|csharp|java)
500
+ replay <recording.json> [--step n] [--json] the Time Machine: step through a run recorded with thunder run --record
490
501
  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
502
  why <run.json> [--step n] [--json] what an AI agent did and why it stopped, in plain words, from its OpenTelemetry record
492
503
  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)
@@ -495,6 +506,8 @@ Read and understand code
495
506
  when omitted), as Markdown for a pull request comment; read from git, no network
496
507
  trace <folder…> [--json] [--out f] Thunder Trace: routes, requests, and events linked across repositories, cited repo@sha:file:line
497
508
  trace impact <thing | --diff [--base ref]> <folder…> what a change can affect in other repositories (one hop, ranked by risk)
509
+ passport <folder…> [--base ref] [--run "part: cmd"…] [--purpose …] an evidence record: behavior, links, effects, evidence with its limits, what is not verified
510
+ passport check <passport.json> which of its claims are still about the code as it is now (current or stale)
498
511
  repo <owner/repo | github url | folder> [--json] [--max-files n] Thunder a whole repository (read-only; nothing is executed)
499
512
  thunderize <folder | owner/repo> [--out <dir>] [--json] the whole app in Thunder Text: one .thunder-text per file + APP.thunder-text
500
513
 
@@ -508,6 +521,9 @@ Change code
508
521
  write <file> --decision <name> --rule <n|otherwise> [--when "<condition>"] [--answer <Outcome>] [--write] [--json]
509
522
  Thunder write: change a number, comparison, text value, or answer in a recovered rule;
510
523
  previews the exact code change and the cases whose answer changes; --write saves it
524
+ write <folder…> --decision <name> --rule <n> --when "<condition>" [--write] [--run "part: cmd"] [--passport f.json]
525
+ one rule change in every service that implements it (TypeScript, C#, Python…):
526
+ the plan first; --write changes all of them or none; tests and a passport as proof
511
527
 
512
528
  ────────────────────────────────────────────────────────────────────────
513
529
  Advanced: rules and missions (ThunderLang™ intent files), proofs, and tools for editors and CI.
@@ -634,10 +650,13 @@ function main() {
634
650
  if (!known.includes(cmd) && !cmd.startsWith('-') && !existsSync(cmd)) { console.error(paint(unknownCommandText(cmd, known), useColor(process.stderr))); process.exitCode = 2; return; }
635
651
  // Thunder Trace: links between repositories and what a change can affect (src/trace-cli.mjs).
636
652
  if (cmd === 'trace') { process.exitCode = traceMain(restArgv); return; }
653
+ if (cmd === 'passport') { passportMain(restArgv).then((code) => { process.exitCode = code; }); return; }
637
654
  // Thunder Why: an AI agent's run explained in plain words, from its OpenTelemetry record (src/why-cli.mjs).
638
655
  if (cmd === 'why') { process.exitCode = whyMain(restArgv); return; }
639
656
  // Thunder Try: try a rule from your code with your own values, and see the answer and why (src/try-cli.mjs).
640
657
  if (cmd === 'try') { tryMain(restArgv).then((code) => { process.exitCode = code; }); return; }
658
+ // The Thunder Time Machine: step through a recording made with thunder run --record (src/replay-cli.mjs).
659
+ if (cmd === 'replay') { replayMain(restArgv).then((code) => { process.exitCode = code; }); return; }
641
660
  // Thunder Core (programs you write and run): thunder new <dir>, and run/build/test/check/format inside a
642
661
  // project with thunder.toml (or with --core). Mission files fall through unchanged. See src/core/cli.mjs.
643
662
  const coreCode = coreMain(cmd, restArgv);
@@ -653,7 +672,9 @@ function main() {
653
672
  throw new Error(`there is no level "${args.level}". The levels are: ${ids.join(', ')}.${near ? ` Did you mean --level ${near}?` : ''}`);
654
673
  }
655
674
  const isDir = statSync(file).isDirectory();
656
- const files = isDir ? collectReadableFiles(file, { maxFiles: 5000 }).filter((f) => f.source) : [{ path: basename(file), source: readFileSync(file, 'utf8') }];
675
+ const files = isDir ? collectReadableFiles(file, { maxFiles: 5000, templates: true }).filter((f) => f.source) : [{ path: basename(file), source: readFileSync(file, 'utf8') }];
676
+ // One Angular component file: its templateUrl file is read with it, so the screen shows its template.
677
+ 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
678
  const model = thunderModel(files, { name: basename(resolve(file)) });
658
679
  const focus = findFocus(model, args.focus);
659
680
  if (focus.error) throw new Error(focus.error);
@@ -662,13 +683,23 @@ function main() {
662
683
  console.log(paint(renderLevel(r, { sources: Object.fromEntries(files.map((f) => [f.path, f.source])), file })));
663
684
  return;
664
685
  }
686
+ if (args.access) {
687
+ // Ownership on web routes: the same accessFlow() the readings and OpenThunder use (docs/access-flow.md).
688
+ const isDir = statSync(file).isDirectory();
689
+ const files = isDir ? collectReadableFiles(file, { maxFiles: 20000 }).filter((f) => f.source) : [{ path: basename(file), source: readFileSync(file, 'utf8') }];
690
+ const report = accessFlow(files);
691
+ if (args.json) { console.log(JSON.stringify(report, null, 2)); return; }
692
+ console.log(paint(accessText(report)));
693
+ if (report.summary.unguarded) process.exitCode = 1;
694
+ return;
695
+ }
665
696
  if (statSync(file).isDirectory()) { readFolder(file, args); return; }
666
697
  if (args.asCore) {
667
698
  // Reading and writing are one language: the reader's meaning tree printed as Thunder Core (docs/core.md).
668
699
  if (!/\.py$/i.test(file) && (args.from || 'python') !== 'python') throw new Error('--as-core reads Python for now (other languages next).');
669
700
  const r = pythonToCore(readFileSync(file, 'utf8'));
670
701
  if (args.json) { console.log(JSON.stringify(r, null, 2)); return; }
671
- console.log(r.core.trimEnd());
702
+ console.log(paintThunder(r.core.trimEnd()));
672
703
  const all = [...r.module.notTranslated, ...r.functions.flatMap((f) => f.notTranslated)];
673
704
  const exact = r.functions.filter((f) => f.exact);
674
705
  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)` : ''}.`);
@@ -718,6 +749,8 @@ function main() {
718
749
  } catch (e) { console.error(`thunder read: ${e.message}`); process.exitCode = 2; }
719
750
  return;
720
751
  }
752
+ // One rule change written into every service that implements it (src/write-across-cli.mjs).
753
+ if (cmd === 'write' && isWriteAcross(restArgv)) { writeAcrossMain(restArgv).then((code) => { process.exitCode = code; }); return; }
721
754
  if (cmd === 'write' && args.edit) {
722
755
  try {
723
756
  if (!file) throw new Error('Use thunder write <file> --edit \'{"op":"setValue","member":"name","step":"line:12","to":10}\' [--apply] [--test "<cmd>"].');
@@ -947,7 +980,7 @@ function main() {
947
980
  if (opt('--otlp')) evidence.push(...fromOtlp(readFileSync(opt('--otlp'), 'utf8')));
948
981
  } catch (e) { console.error(`thunder runtime: ${e.message}`); process.exit(2); return; }
949
982
  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)) });
983
+ const model = thunderModel(collectReadableFiles(folder, { maxFiles: 5000, templates: true }).filter((f) => f.source), { name: basename(resolve(folder)) });
951
984
  const overlay = runtimeOverlay(model, evidence);
952
985
  const explained = stacks.map((s) => explainError(model, s));
953
986
  if (restArgv.includes('--json')) { console.log(JSON.stringify({ ...overlay, errors: explained }, null, 2)); return; }
@@ -2747,4 +2780,19 @@ test Example
2747
2780
  printDiagnostics(diagnostics);
2748
2781
  }
2749
2782
 
2750
- main();
2783
+ /** A file that is not there is said in words, never as a crash: what was looked for, where, and what to type. */
2784
+ function missingFile(e) {
2785
+ if (!e || e.code !== 'ENOENT' || !e.path) return false;
2786
+ const cmd = process.argv[2] ?? 'thunder';
2787
+ const name = relative(process.cwd(), e.path) || e.path;
2788
+ const lines = [`thunder ${cmd}: there is no file or folder called "${name}" here.`, `You're in: ${process.cwd()}`];
2789
+ let root = null;
2790
+ try { root = findProjectRoot(process.cwd()); } catch { /* none */ }
2791
+ if (root && ['run', 'test', 'build', 'check'].includes(cmd)) lines.push(`You're inside the Thunder project "${basename(root)}". Run it with: thunder ${cmd}`);
2792
+ else lines.push('See the main commands with: thunder help');
2793
+ console.error(paint(lines.join('\n'), useColor(process.stderr)));
2794
+ process.exitCode = 2;
2795
+ return true;
2796
+ }
2797
+ process.on('uncaughtException', (e) => { if (!missingFile(e)) { console.error(e); process.exitCode = 1; } });
2798
+ try { main(); } catch (e) { if (!missingFile(e)) throw e; }