@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/CHANGELOG.md CHANGED
@@ -1,3 +1,193 @@
1
+ # 1.4.0
2
+
3
+ **Upgrade note.** Every existing command, flag, exit code, and JSON output is unchanged. New: the Software Passport
4
+ (`thunder passport`, `thunder passport check`; schema `thunder-passport-v1`), ownership checks on TypeScript web routes
5
+ (`thunder read <dir> --access`, `accessFlow()`; schema `thunder-access-v1`), and a public, browser-safe library entry,
6
+ `@skillstech/thunderlang/program` (compile, run, screens, and all seven targets). `./core` now also exports what apps
7
+ used to reach through paths into `src/`; switch to the public entries, since `src/` paths are not part of the API. The
8
+ repository gains a three-language checkout demo (`demo/checkout/`) with its walkthrough.
9
+
10
+ - **One rule change, every service, any language (`thunder write <folder…>`).** When the same rule is written in
11
+ several services (free shipping from $50 in the cart page in TypeScript, the orders service in C#, and billing's
12
+ receipt in Python), `thunder write web orders billing --decision shippingNote --rule 1 --when "subtotal >= 40"`
13
+ finds every copy (same condition, names compared as words), shows the plan, and with `--write` changes all of them
14
+ or none: only the rule's characters, each file read again. Lookalikes (same names with another limit, or the same
15
+ limit with other names) are listed as "check by hand", never changed; tests are never edited, and those that call
16
+ the rule and mention the old value are listed. `--run "part: cmd"` runs the tests on the change and reports every
17
+ failure; `--passport` records it as a Software Passport. API: `writeRuleAcross`, `findSameRule`,
18
+ `writeAcrossEvidence` in `./core` (`thunder-write-across-v1`). The checkout demo gains the shipping rule in all
19
+ three services and `run-demo.sh --change`.
20
+ - **The Thunder Software Passport (`thunder passport`).** An evidence record for a feature or a change
21
+ (`thunder-passport-v1`): purpose (only what you state, else "not stated"), behavior as Thunder Text with lines,
22
+ dependencies (every file by content hash, Trace links, packages, services), effects detected in code, evidence, unknowns,
23
+ and history. Each claim has a basis (a command with its exit code and output digest, or source lines), what it does not
24
+ cover, and the files it depended on. A failed `--run` is recorded as failed (exit 1), never as passed, and "not verified"
25
+ always lists deployment, real external services, more than one process, and load. `thunder passport check` marks each
26
+ claim current or stale when a file it depended on changed, without re-running anything. Ownership-check verdicts join
27
+ as evidence when that check is present. Pure half in `@skillstech/thunderlang/core` (`assemblePassport`,
28
+ `checkPassport`); `buildPassport` in the root entry. The checkout demo has its passport (`run-demo.sh --passport`).
29
+ - **Access flow: does every path limit the record to the caller?** For TypeScript and JavaScript web routes (Express,
30
+ Fastify, Hono, Next.js), Thunder follows the request's values through the handler, the project's helpers,
31
+ repositories, classes, and middleware, and into the database (Prisma, Drizzle, Knex, raw SQL, postgres.js, Mongoose).
32
+ Each path that hands back or changes a record chosen by the request gets one verdict: guarded (a where clause on
33
+ the caller's tenant or owner, a comparison that stops first, or the caller's own record), unguarded (every step was
34
+ followed and none limits it), or cannot tell (exactly what stopped it, with its line). "Unguarded" is never said
35
+ when anything on the path was left unresolved. `thunder read <dir> --access` (`--json`: thunder-access-v1),
36
+ `accessFlow()` in `@skillstech/thunderlang/core`, and one line on each route in readings. A dependency-free
37
+ TypeScript parser comes with it (`src/flow/ts-parse.mjs`). Measured on a 55-route labeled benchmark (every label
38
+ met; no false "unguarded") and on about 14,500 real files (0 called unguarded). See docs/access-flow.md.
39
+ - **Services that talk across languages are read and linked.** Thunder Trace now links:
40
+ - ASP.NET minimal-API routes (`app.MapPost("/orders", …)`);
41
+ - Python standard-library handlers (`do_POST` and the one path it checks);
42
+ - an `HttpClient` under any client-like name (`http.PostAsync("/charges", …)`);
43
+ - a `fetch` whose options object spans lines.
44
+
45
+ A TypeScript → C# → Python app is linked end to end, each end cited.
46
+ - **More of a change is said in words:**
47
+ - C#'s `String.IsNullOrEmpty(x)` ("x is empty or missing"), `Task.FromResult(x)`, and `GetOrAdd` ("made … if it is missing");
48
+ - a JSON body by its fields ("Turns items (cart), coupon and key into JSON text");
49
+ - a new random ID (`crypto.randomUUID()`, `uuid.uuid4()`, `Guid.NewGuid()`).
50
+
51
+ `thunder review` says when a function's steps moved into a new function it now runs, instead of listing each one as "no longer".
52
+ - **Truer C# values:** a filled-in initializer (`= new() { ["a"] = 1 }`) is no longer "empty at first"; `0.08m` reads 0.08; `new()` of an object is not "empty"; a field and the property that shows it are listed once. Words inside text (`$"… bug (…) {x}"`) and a lambda passed as an argument are no longer read as methods. A folder's big picture no longer takes one file's description as the whole app's.
53
+ - **Demo: `demo/checkout/`.** A three-language shop (TypeScript, C#, Python) where a retried checkout charged twice, the fix (one idempotency key end to end), and `run-demo.sh` to reproduce both and what Thunder reads.
54
+ - **`@skillstech/thunderlang/program`: Thunder Core as a library, browser-safe.** One public entry for apps (OpenThunder,
55
+ the site, your own tools) to compile a program (`compileCore`), run it on the Thunder engine (`runInProcess`,
56
+ `recordedRun`, `testInProcess`), show and drive its screens (`screenApp`, `screenOutline`), and write it as Python,
57
+ TypeScript, C#, Java, Go, Rust, or React (`toPython` … `toReact`), plus `pythonToCore`, with types. A test checks
58
+ that nothing it imports needs Node, so it runs in a browser; until now this needed paths into the package's files.
59
+
60
+ # 1.3.0
61
+
62
+ **Upgrade note.** Every existing command, flag, exit code, and JSON output is unchanged. New: Thunder Core compiles to
63
+ C#, Java, Go, and Rust (with Python and TypeScript, six targets, each giving the same output on every Core test
64
+ program); the Time Machine (`thunder run --record`, `thunder replay`); block records and named inputs with a semantic
65
+ formatter (`thunder format` may now rewrite long one-line records as blocks: run `thunder format --write` to adopt it);
66
+ screens: write a `Screen` in Thunder Core and build it as a React app (`thunder build --target react`), and read React
67
+ and Angular components as screens (`model.screens`, with pages marked); the live translator at thunderlang.dev/live;
68
+ and clearer readings of real code, with fewer steps left as code. TC405's wording is now target-neutral.
69
+
70
+ - **Thunder screens, built as React apps.** A `Screen` says what a person sees: `Receive` its inputs, `Remember` the
71
+ values it keeps (`Remember coupon as text, starting at ""`), then `Show` a heading, text, a list (`Show a list with
72
+ each item in items:`), a row, a text box or number box bound to a remembered value, a button (`(off when …)`,
73
+ `that opens Home`, or `When pressed:` with ordinary Thunder steps and `Open Home`), another screen with named inputs,
74
+ and `When` / `Otherwise` choices. A press runs on copies and changes everything or nothing; a failure (or `Stop with
75
+ "…"`) keeps nothing and the screen says why. `thunder run` prints the first screen as an outline;
76
+ `thunder build --target react` writes a Vite app (`<program>.tsx` with one component per screen, `useState` for each
77
+ Remember, `// thunder:N` marks, and a runtime that is the Thunder engine's own value and screen code). The engine and
78
+ React are checked against each other: react-dom/server HTML must equal the engine's screen for every screen program
79
+ in the tests, and 46 scripted presses and typings must give the same screen after each one; the TSX passes
80
+ `tsc --strict` and builds with Vite. New codes: TC118, TC119, TC212–TC214, TC406, TC407. Screens build only for React
81
+ (other targets refuse them with TC406). Design note: docs/screens.md.
82
+
83
+ - **The live translator (thunderlang.dev/live).** Type code in Python, TypeScript, JavaScript, Java, C#, Go, or Rust
84
+ and see Thunder's reading update as you type (for Python, also the Thunder Core you can edit and run). Or write
85
+ Thunder and see it as Python, TypeScript, C#, Java, Go, and Rust, with what it prints, run by the Thunder engine in a
86
+ worker (a program that never ends is stopped and said so). Everything runs in the browser. The Go target's name table
87
+ (`goNamespaces`) moves into target-go.mjs so it can run there.
88
+ - **Fewer steps shown as code when Thunder reads real code.** Text with values reads as its exact text with
89
+ «placeholders» (JavaScript templates and Python f-strings; a worked-out value is «…»). Python counting loops say
90
+ where they start and stop (`range(n)`, `range(a, n + 1)`, `range(len(xs))`, `enumerate(xs)`), imports inside a
91
+ function say what they load, and everyday values are said (`a - b`, `set()`, `[a, b]`, slices such as "the first 3
92
+ of xs", `d.get("k", fallback)` with the fallback). Rust reads `loop`, loops over `.iter()`, `.chars()` and ranges,
93
+ a last `Ok(…)`, and `let y = f(x)?` ("…, and stops here if that fails"); Rust's `Ok(x)` is no longer read as a web
94
+ answer. A TypeScript function whose return type is an object type is read from its body. Every new sentence is
95
+ checked against its code, with tests that a wrong sentence is still shown as code. Also fixed: a `%` followed by a
96
+ letter inside a text could stop a whole Python file from being read. `reading-quality.mjs --shapes N` ranks what is
97
+ still shown as code by its shape (names as x), never printing the code.
98
+ - **React and Angular screens are read as what a person sees and does.** A React component (function or arrow
99
+ returning JSX, `memo`/`forwardRef` too) and an Angular `@Component` are now **screens** in the model
100
+ (`model.screens`; the function or class behind each points to it). A screen says what it receives (props with
101
+ their types; `@Input`/`input()`), what it remembers (`useState`/`useReducer`/hooks; fields, `signal`, `computed`),
102
+ what it shows (JSX or the template, inline or `templateUrl`, in words: headings, lists "one of these per item in
103
+ items", choices "when … / otherwise", text boxes, buttons, links), what happens when someone acts (`onClick`,
104
+ `(click)`, … : sets coupon, runs checkout, sends the checkout event, tells the parent), what runs by itself
105
+ (`useEffect` with its dependencies, `ngOnInit` and the other hooks), what it sends (`@Output`/`output()`), and the
106
+ screens it shows (linked by name or selector). Anything not understood (spread props, other expressions, unknown
107
+ directives) is listed as not read. `thunder read --level` shows screens at every level; the big picture lists the
108
+ app's screens once. `collectReadableFiles` takes `templates: true` to bring `*.component.html` files.
109
+ - **Docs pages look like a polished reference.** Every code block is a small editor window with a title bar
110
+ (Thunder, Terminal, Output, Diagram, Python, thunder.toml…) and a Copy button; Python, TypeScript, JSON, YAML, and
111
+ TOML are colored too. Headings can be linked to, long docs get an "On this page" list that follows your reading,
112
+ and tables, notes, and inline code are calmer.
113
+ - **Thunder Core in color, everywhere it is written.** The site's highlighter (docs, code cards, the editor, the
114
+ tutorial) knows Thunder Core: statement words (Set, When, Give, For each, Test…) bold, joining words softer, function
115
+ names after "To", record names after "A … has:", record kinds, money, percents and yes/no as values, text in green
116
+ with its {holes} marked, and comments after the code dimmed. The VS Code grammar gains the same roles. In the
117
+ terminal, `thunder read --as-core`, `thunder format`, and `thunder replay` print Thunder Core in the same colors (off
118
+ for files, pipes, `NO_COLOR`, and JSON).
119
+ - **Fix: `thunder run hello` inside the hello project crashed** with a raw Node error (it looked for a file named
120
+ hello). Inside a project, its own name now means the project, from any folder in it. A file that is not there is
121
+ said in words everywhere ("there is no file or folder called … here", where you are, and what to type), never a
122
+ stack trace.
123
+ - **Thunder Beautiful Code: records and calls as blocks, and a formatter that knows the program.** A record can be
124
+ written as a block (`Set first trade to a Trade:` then one `field: value` per line), for Set, Give, Add … to,
125
+ Expect … to, and as a call's last value; a function can be called with its inputs by name, in any order, leaving out
126
+ inputs that have defaults (`Set total to taxed price:` / `price: $100`). Both are exactly the same program as the
127
+ one-line forms. Mistakes are reported with the line and a suggestion (new codes TC113–TC117; unknown fields use
128
+ TC206). `thunder format` now writes the Thunder style: short stays short, records with 4+ fields or lines past 100
129
+ columns become blocks, long conditions wrap before `and`/`or`, and one blank line goes around every function,
130
+ record, and test. It never changes meaning: 66 Core programs from the examples, docs, and Core tests are formatted
131
+ in the tests and give the same program, output, and test results. The trading-journal example is in the new style.
132
+ - **The Thunder Time Machine: step through a run.** `thunder run <program> --record run.json` runs it on the Thunder
133
+ engine and saves every step; `thunder replay run.json` steps forward and back (Enter or n, b, j 7, q). Each step shows
134
+ the Thunder line, the values it changed (before → after), what it printed, what a function gave back, which steps a
135
+ call covered, and for a choice whether it went "yes" or "no, so the Otherwise steps". `--step n` and `--json` give one
136
+ step or the whole recording as data (`thunder-time-machine-v1`). It replays a recording: going back never undoes
137
+ anything. Programs that `Use` a Python module cannot be recorded (the Thunder engine does not run them).
138
+ - **Thunder Core compiles to C#.** `thunder build|run|test --target csharp` (or `target = "csharp"` in `thunder.toml`)
139
+ writes an ordinary .NET console project: one static class per Thunder file, `ThunderRuntime.cs` (base class library
140
+ only; a line-by-line port of the engine's value code, with exact decimals on `BigInteger`), `Program.cs`, and
141
+ `ThunderProgram.csproj`, and builds and runs it with the .NET SDK (8 or newer). Every Core test program (136) gives
142
+ the same output, errors, and exit status on Python, the Thunder engine, TypeScript, and C#; the conformance tests
143
+ build them all in one project per test file. `Use` is refused for C# (TC405). Without the SDK, Thunder says what to
144
+ install (exit 2). The site lists C# as Available; Java, Go, and Rust stay Planned.
145
+ - **Thunder Core compiles to Rust.** `thunder build|run|test --target rust` (or `target = "rust"` in `thunder.toml`)
146
+ writes a small Cargo project: one `.rs` per Thunder file, `main.rs`, and `thunder_runtime.rs`, a line-by-line port
147
+ of the Thunder engine's value code that uses only the standard library (exact decimals of any size, money rounded
148
+ half up, positions from 1, the same words for every value and error), so it builds offline. 136 Core test programs
149
+ give the same output, errors, and exit status on Python, the Thunder engine, TypeScript, and Rust; programs that use
150
+ a Python module are refused (TC405). Running needs `rustc` and `cargo`; without them Thunder says what to install.
151
+ - **Fix: JSON `false`.** "the JSON data in" read `false` one character short, so `{"a": false}` failed with
152
+ "Expecting ',' delimiter". It now reads it as Python does (the Thunder engine and every compiled target).
153
+ - **Thunder Core compiles to Go.** `thunder build|run|test --target go` (or `target = "go"` in `thunder.toml`) compiles
154
+ a program to readable Go: one standard-library-only module (`go.mod`, one `.go` per Thunder file, and the runtime in
155
+ `thunder/thunder_runtime.go`, a port of the Thunder engine's value code: exact decimals with `math/big`, money rounded
156
+ half up, positions from 1). `go run .` runs it without Thunder. Every Core test program (136) gives the same output,
157
+ errors included, on Python, the Thunder engine, TypeScript, and Go; the conformance tests now run all four. `Use` (a
158
+ Python module) is refused for Go (TC405). Running needs Go 1.21+; without it, Thunder says so and `build` still works.
159
+ - **Thunder Core compiles to Java.** `thunder build|run|test --target java` (or `target = "java"` in thunder.toml)
160
+ compiles a program to readable Java 17+ (one class per Thunder file, a static method per function, every line marked
161
+ `// thunder:N`) with a JDK-only runtime that follows the Thunder engine's values line for line. Every Core test
162
+ program (136) gives the same output, errors, and exit status on Python, the Thunder engine, TypeScript, and Java.
163
+ Thunder finds the JDK through THUNDER_JAVA_HOME, JAVA_HOME, or the PATH, and says what to install when there is
164
+ none; building needs no JDK. A program that uses a Python module is refused for Java (TC405).
165
+ - **Readings say more, more precisely (a reading-quality sweep on real code).** A message says what it writes
166
+ (`Writes a log or message: "Wrote «opts.out»."`, values in text as «placeholders»); an add says what it adds ("Adds an
167
+ entry (title, rows, source) to out", "Adds the c's id to items"); a call's single argument is named ("Calls add
168
+ command (with the result of rules command)"); everyday calls are said by what they give back (`Object.keys(x)` "the
169
+ keys of x", `Date.parse(t)`, `Buffer.from(b)`, `re.exec(s)` "the first match of re in s", `Schema.parse(body)`,
170
+ `Math.max(a, b)` "the largest of a and b", Python `Settings()` "a new Settings", `list(x)`, `sorted(x)`,
171
+ `xs.index(v)` "the position of v in xs"); callbacks are said by purpose (`program.command('check')` "Defines the
172
+ command "check"", a database transaction, progress shown); a one-expression event handler says when it runs; type
173
+ checks take "a" or "an" by sound ("an Error"); a map key keeps its owner ("the entry for the row's id in seen"); a
174
+ file path reads "at <name>". Fix: a Python variable named `match` was read as a `match` statement. The faithfulness
175
+ checks were taught each new form, so a sentence they cannot verify still falls back to code.
176
+ `compiler/scripts/reading-quality.mjs` measures these patterns on any folders.
177
+ - **TypeScript web routes read as actions, even when the handler is wrapped.** `fastify.post('/x', handle(async
178
+ (request) => { … }))` and one-expression handlers (`fastify.get('/x', handle(async (request) => view(…)))`) are now
179
+ actions ("When someone calls POST /x"), like unwrapped ones. The function that registers them lists each once
180
+ ("Handles POST /x (its steps are in that action)") instead of repeating its steps as "Calls post with these steps".
181
+ TypeScript types are set aside when a statement is read: `(request.body ?? {}) as { … }` reads "Sets b to the
182
+ request's body, or an empty lookup table when that has no value", `ctx.repo!` reads "Sets repo to the ctx's repo",
183
+ and `const reviews: Record<…> = {}` reads "Sets reviews to an empty lookup table". Two loops on one line are no
184
+ longer read as one loop mixing their names.
185
+ - **Reading fixes (reported from OpenThunder).** (1) A helper assigned below a typed variable (`let a: { … } | undefined;`
186
+ then `const approve = (x) => {`) was named after the variable; the type annotation now stops at its statement's end.
187
+ (2) A call named after a preposition no longer leaves a sentence hanging: `changeApprovalFor(x, …)` reads "change
188
+ approval for x" (its first argument, when that is a plain name), or "change approval" otherwise, never "change
189
+ approval for ". (3) "an AgentCheckResult", "an Order", "a User", "a URL": the article follows the sound.
190
+
1
191
  # 1.2.0
2
192
 
3
193
  **Upgrade note.** Every existing command, flag, and exit code is unchanged, with one JSON change: in `thunder why