@skillstech/thunderlang 1.0.4 → 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.
Files changed (66) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/dist/core.cjs +2568 -462
  3. package/dist/index.cjs +7562 -5084
  4. package/dist/learn.cjs +1963 -315
  5. package/intent-graph.schema.json +11 -0
  6. package/package.json +6 -2
  7. package/src/cli.mjs +141 -58
  8. package/src/codegen.mjs +145 -55
  9. package/src/conformance.mjs +15 -6
  10. package/src/core/check.mjs +725 -0
  11. package/src/core/cli.mjs +133 -0
  12. package/src/core/diagnostics.mjs +81 -0
  13. package/src/core/format.mjs +20 -0
  14. package/src/core/from-python.mjs +645 -0
  15. package/src/core/index.mjs +38 -0
  16. package/src/core/lexer.mjs +115 -0
  17. package/src/core/parser.mjs +742 -0
  18. package/src/core/project.mjs +167 -0
  19. package/src/core/round-trip.mjs +150 -0
  20. package/src/core/runtime-python.mjs +801 -0
  21. package/src/core/target-python.mjs +486 -0
  22. package/src/core.d.ts +5 -2
  23. package/src/core.mjs +5 -2
  24. package/src/data-schema.mjs +8 -1
  25. package/src/emit.mjs +1 -1
  26. package/src/evidence.mjs +1 -1
  27. package/src/expr.mjs +81 -4
  28. package/src/form-words.mjs +2 -0
  29. package/src/index.d.ts +8 -1
  30. package/src/index.mjs +5 -1
  31. package/src/intent-schema.mjs +1 -0
  32. package/src/mcp.mjs +23 -0
  33. package/src/meaning.mjs +45 -6
  34. package/src/model.d.mts +7 -3
  35. package/src/model.mjs +19 -6
  36. package/src/money.d.mts +18 -0
  37. package/src/money.mjs +124 -0
  38. package/src/plain-contract.mjs +18 -2
  39. package/src/read.d.mts +11 -0
  40. package/src/read.mjs +40 -6
  41. package/src/review-comment.d.mts +16 -0
  42. package/src/review-comment.mjs +145 -0
  43. package/src/say-less.mjs +1432 -0
  44. package/src/system.mjs +153 -44
  45. package/src/target-cs.mjs +39 -34
  46. package/src/target-elixir.mjs +40 -30
  47. package/src/target-go.mjs +41 -36
  48. package/src/target-java.mjs +34 -27
  49. package/src/target-kotlin.mjs +43 -35
  50. package/src/target-py.mjs +57 -55
  51. package/src/target-result.d.mts +48 -0
  52. package/src/target-result.mjs +112 -0
  53. package/src/target-rust.mjs +42 -38
  54. package/src/target-scala.mjs +45 -35
  55. package/src/target-ts.mjs +37 -45
  56. package/src/target-types.mjs +41 -5
  57. package/src/target-util.mjs +55 -2
  58. package/src/trace-cli.mjs +58 -0
  59. package/src/trace-fs.mjs +76 -0
  60. package/src/trace.mjs +261 -0
  61. package/src/translate.d.mts +3 -0
  62. package/src/translate.mjs +62 -32
  63. package/src/why-cli.mjs +31 -0
  64. package/src/why.d.mts +28 -0
  65. package/src/why.mjs +532 -0
  66. package/src/write-steps.mjs +22 -5
package/CHANGELOG.md CHANGED
@@ -1,3 +1,143 @@
1
+ # 1.1.0
2
+
3
+ - **Thunder Why: what an AI agent did, in plain words.** `thunder why run.json` reads an agent run's OpenTelemetry
4
+ record and says what the agent was asked and answered, what went wrong, what happened just before, what would have
5
+ changed the outcome, and what it changed, with every step in order. It reads OTLP JSON, the collector's file
6
+ exporter, the Python console exporter, and OpenInference span arrays, with the GenAI, OpenInference, HTTP, and
7
+ database conventions. Retries are one step ("3 tries"); a failed change is never reported as done; a tool whose
8
+ name doesn't say whether it changes anything is listed as "could not judge". Errors are in plain words, with the
9
+ original kept in the details. Values that look like secrets are hidden. `--step n` shows one step in full;
10
+ `--json` gives the same as data. Nothing is run and no AI is used. Also available as `@skillstech/thunderlang/why`.
11
+ - **Inputs with defaults.** `Receive price and rate (7% if not given)`: a call may leave the input out. A default
12
+ is a fixed value: a number, money, a percent, text, yes/no, `nothing`, or a kept value. It comes after the inputs
13
+ without one. A list or map default is an error (TC404), because Python would share it between calls. `--as-core`
14
+ reads Python's fixed defaults (`rate=0.07`, `label="x"`, `flag=None`, `rate=TAX`) this way, and still refuses list,
15
+ dict, and computed defaults. Real Python (150 files): 240 → 261 exact functions. Core text also accepts `\r`.
16
+ - **Core's standard operations for text, lists, numbers, and JSON.** The new forms:
17
+ - text: `names joined with ", "`, `line split at ","`, `the parts of text`, `date replacing "-" with "/"`,
18
+ `name starts with "Dr"`, `file ends with ".csv"`;
19
+ - lists and numbers: `scores sorted` and `sorted descending`, `the absolute value of x`;
20
+ - JSON: `the JSON data in text`, which reads numbers exactly, and `the JSON text of value`.
21
+ Each checks its kinds: before running when known, while running otherwise. Invalid JSON stops with TC509. The
22
+ words `joined`, `split`, `replacing`, `starts`, and `ends` now belong to Thunder and cannot be part of a name.
23
+ `--as-core` reads Python's `join`, `split`, `replace`, `startswith`/`endswith`, `abs`, `max`/`min` of several
24
+ values, `sorted(xs)`, `list()`, `dict()`, and `json.loads`/`json.dumps` (only when the file imports `json`) as
25
+ these forms. A call whose meaning differs is still refused: `maxsplit`, a replace count, a tuple of prefixes, or
26
+ `key=`. The benchmark's exact functions rose to 19 of 20, and all 19 give the same results as the original.
27
+ - **Methods read as Core.** `thunder read <file.py> --as-core` now prints each method of a class as a Core function
28
+ that receives the object first (`To Account withdraw:` / `Receive self and amount`). `self.other()` calls that
29
+ class's own function, and this is written down as an assumption, since a subclass could replace it. Static methods
30
+ are printed as plain functions. Special methods, inner functions, and `self.other()` calls the class does not
31
+ define are refused. The round trip now runs methods too, and compares the object afterwards. Benchmark:
32
+ `Account` 6 of 6 and `Cart` 4 of 5 methods printed exactly, all giving the same results. On 150 real Python
33
+ files, exact functions rose from 66 to 236 (3% to 12%), and every file's Core still compiles.
34
+ - **Fix (Core): changing a field or an entry whose kind is not known.** `Add 3 to box's items`, `Increase box's count
35
+ by 1`, and `Set xs at 1 to v` on a value from Python compiled to invalid Python (`get_field(...) = …`) or set the
36
+ wrong list position (`xs[1]` for Core's position 1). They now read and store through the same helpers as `Set`.
37
+ Reading `pair at 1` works on a Python tuple.
38
+ - **Read Python as Thunder Core: reading and writing are one language.** `thunder read <file.py> --as-core` prints
39
+ the reader's meaning tree as Core you can edit, compile, and run. It never prints from the English. A line Core
40
+ cannot say with the same meaning becomes `# Not translated (line N): <why>` plus a `Stop with` line. Such a
41
+ function is reported as not safely editable; Thunder never rewrites a line into something close. Assumptions are
42
+ written next to the line. The output always compiles. On the 20-function benchmark (`docs/core-read-write.md`),
43
+ the printed Core compiles 20 of 20, is exact 18 of 20, and the 18 exact ones give the same results as the
44
+ original Python on 52 of 52 sample inputs, checked by running both (`verifyRoundTrip`, `compiler/src/core/round-trip.mjs`).
45
+ - **Core is strict about yes/no and exact with Python floats.** A condition, `and`/`or`/`not`, or a comparison with
46
+ `true`/`false` on a value of unknown kind now checks it is yes/no while running. `1` or `"yes"` stops with a
47
+ clear error instead of being treated as true or false. A Python float reaching Core arithmetic or a comparison
48
+ becomes the exact decimal it is written as (`19.99`). Before, `float * Decimal` crashed, and a float `0.1`
49
+ compared as more than `0.1`.
50
+ - **Thunder Trace: how your repositories depend on each other.** `thunder trace <folder…>` links HTTP requests to
51
+ the routes that handle them and published events to their listeners, across repositories, and cites every link
52
+ `repo@sha:file:line`. `thunder trace impact "<route | event | repo:file[:line]>" <folder…>` and
53
+ `thunder trace impact --diff [--base ref] <folder…>` list what a change can affect, ranked high/medium/low, one
54
+ hop out. A route or event that was removed is caught by reading each changed file as it was before. Links are made
55
+ only on a fact: `/health`-style paths, paths with no fixed part, and two equal matches are never linked, and each
56
+ is listed with the reason. The graph (`thunder-trace-v1`) is fingerprinted. The MCP server offers it as
57
+ `intent_trace` (local only). Reference: `docs/trace.md`.
58
+ - **Routes include their controller's prefix.** ASP.NET `[Route("api/[controller]")]` and Spring
59
+ `@RequestMapping("/api")` on a class now prefix each handler's path (`POST /api/Orders`, not `POST`). An ASP.NET
60
+ path with no prefix now starts at the root (`/docs/{id}`).
61
+ - **Thunder Core: write a program in Thunder and run it (Python first).** `thunder new <dir>` creates a project
62
+ (`thunder.toml`, `src/main.thunder`, `tests/`); `thunder run`, `build`, `test`, `check` and `format` work in it,
63
+ or on one file with `--core`. Core has values, kept values, functions, conditions, loops, lists, maps, records with
64
+ `Never allow` rules, `If this fails:`, tests, and `Use <python module>` to reach the Python ecosystem. It compiles
65
+ to readable Python 3.10+ plus a standard-library-only `thunder_runtime.py`: division and money are exact, rounding
66
+ is half up, positions start at 1, `nothing` is never silently a value, and every failure names the Thunder line
67
+ (TC5xx). The site's playground example (several `Receive` lines, `yes or no`, a condition continued on an
68
+ `and …` line) compiles and runs as written. Reference: `docs/core.md`. Demos: `examples/core/`. Python is the only
69
+ target so far.
70
+ - **`thunder new` now creates a Core project.** For an intent mission file, use `thunder init <Name>` (or
71
+ `thunder new --mission <Name>`); `thunder new` says so when it runs.
72
+ - **Fix: a rule Thunder cannot translate never becomes `false`.** The scaffolds (`thunder gen`, all four targets),
73
+ the executable targets (TypeScript, Python, C#, Java, Go, Rust, Kotlin, Scala, Elixir) and the in-browser
74
+ translator used to replace an untranslatable rule condition with `false` (Python with no note at all), so generated
75
+ or executed code silently skipped that rule and returned another answer. Now generation reports the new diagnostic
76
+ **`IL-GEN-001`** ("Thunder could not translate the condition '…' for <target>: <reason>"), `thunder gen` prints it
77
+ on stderr and exits 1, the generated rule throws with that message (`throw new Error(...)`,
78
+ `raise NotImplementedError(...)`), and `thunder test --target`, `--all-targets` and `thunder conform --run` refuse
79
+ to run that decision and report its cases as *not translated*, never as an answer. New API:
80
+ `generateWithDiagnostics(ast, target)` and `translateDecisionsWithDiagnostics(ast, lang)`.
81
+ - **Fix: Money is exact, never binary floating point.** `Money` is a decimal with 2 minor units (or the currency's:
82
+ `Money(JPY)` 0, `Money(KWD)` 3); extra precision is an error, never rounded; rounding, where a spec asks, is half
83
+ up (a half goes away from zero), the same rule as Thunder Core's `round`. TypeScript Money was `number`; it is now `bigint` minor units with a generated zero-dependency
84
+ `parseMoney` / `formatMoney` helper. Python Money was `float`; it is now `decimal.Decimal`. Decision inputs typed
85
+ `Money` were `double`/`float64`/`f64` in every target; they are now `decimal` (C#), `BigDecimal` (Java), `int64`
86
+ (Go) and `i64` (Rust) minor units, and a Money comparison a target cannot do exactly (Kotlin, Scala, Elixir, or
87
+ multiplying Money) is refused with `IL-GEN-001`. The decision engine adds, subtracts and multiplies decimals
88
+ exactly, so `0.1 + 0.2 == 0.3`. Plain contracts read `$12.30` as exact cents (and show `$12.30`, not `$12.3`), and
89
+ reject `$12.305` instead of rounding it. JSON Schema / OpenAPI describe Money as a decimal string, not a number.
90
+ See "Money is exact" in `docs/spec.md`.
91
+ - **Fix: a failed run is never a `null` answer.** The live target runners turned a missing toolchain, a compile
92
+ failure, a crash or a timeout into `null` (and Python turned an exception into `None`), so a real null answer
93
+ looked the same as a failure. Each run now returns `{ status: 'ok', results }` with one
94
+ `{ status: 'ok', value }` or `{ status: 'error', kind, message }` per case (`kind`: `missing-toolchain`,
95
+ `compile-failed`, `runtime-error`, `timeout`, `assertion-failed`, `not-translated`, `missing-input`), or a whole-run
96
+ `{ status: 'error', kind, message }`. `thunder test --target` / `--all-targets` and `thunder conform` show
97
+ `ERROR` with the kind and reason (and fail the run); a missing toolchain is still skipped. Conformance evidence
98
+ counts an error as a failure. Types: `compiler/src/target-result.d.mts`. The playground's Code tab lists any rule
99
+ that was not translated.
100
+ - **Fix: a case is never run with a made-up input.** A test case that left out an input was run in Java, Go, Rust
101
+ and the others with `0`, `false`, `""` (or `$0` for Money), so a typed target answered for a value nobody wrote and
102
+ its FAIL blamed the target (Python crashed instead). Every target now reports such a case as `missing-input`,
103
+ naming the inputs to add. Target names print as TypeScript and C# (not Typescript and Csharp).
104
+ - **Say less: words only where Thunder is sure (`src/say-less.mjs`).** Every worded step is now checked after it is
105
+ read, and a step stays in words only when its form is recognized and the words account for its code (every word from
106
+ the code or Thunder's own wording, every value exact, no negation, and/or, comparison, arithmetic, cast, or named
107
+ argument part dropped, no ambiguous names, recognized endings, certain block structure, inputs from the signature).
108
+ Anything else is shown as its code, exactly as written. On new repositories graded independently the false rate fell
109
+ from 10.4% to 3–4% (target 1% not yet reached; see docs/accuracy.md); steps explained fell from 90.0% to 81.7%.
110
+ - **New fields (OpenThunder):** every step and flow node has `explained` and, when false, `notExplainedWhy`;
111
+ functions and members have `explainedSteps` / `totalSteps`; the model has `explainedSteps` / `totalSteps`.
112
+ - **C and C++ meaning trees:** `->`, unary `*` / `&`, C casts, typed and array declarations, `struct` / `static`
113
+ declarations, C++ template calls (`static_cast<T>(x)` is a call, never a comparison), range-for with `const auto&`.
114
+ Swift `try f()` is an expression, not a try block.
115
+ - **Rules** are drawn only for a certain yes/no answer (`state.copy_ || state.base_` is not a rule); **doc comments**
116
+ only from the `/** … */` right above a function (a `/*#__PURE__*/` no longer pulls in another function's doc).
117
+ - **Reviews:** a question's two sides keep quoted text exactly (`hasattr(fp, "read")`, never `hasattr(fp, 0)`).
118
+ - A length reads one way: "the length of password" (never "how many password").
119
+ - `scripts/form-words.mjs` regenerates the readers' fixed wording list; `SAYLESS_DEBUG=1` prints why each step was
120
+ shown as code.
121
+ - Tests changed only where a reading correctly became code: gin#13 (an `if` with a setup statement other than the
122
+ err idiom), ripgrep#3 (a loop over a pattern), Kingfisher#2 / Alamofire#3 (`guard case`), Rectangle#5 (`for …
123
+ where`), nvm#18 (`test && cmd || other`), neofetch#3 and nvm#2 (`ls` alone is not "the files in ".""), #179
124
+ (`out var`), vapor#8 (a closure with a capture list), the Swift `if let …, cond` reading, httr#19 (quotes inside a
125
+ value), jquery#15 (`queue || []` is not "when that has no value"), #165 (the shown code is the source as written),
126
+ and four expectations of "how many x" that now read "the length of x".
127
+ - **Fix (writing in Thunder):** an inline route handler's own model id (`auth.ts##POST/api/auth/register#3`) now resolves in `thunderWrite`, and `says` names only the changed step, once, when a one-line `if` holds several steps. Reported by OpenThunder.
128
+ - **Thunder review on every pull request (GitHub Action).** `uses: SkillsTechTalk/thunderlang@main` (the repository's
129
+ root `action.yml`) runs `thunder review` on the pull request's two commits with the published compiler, writes the
130
+ review to the job summary, and keeps one pull request comment up to date (found by `<!-- thunder-review -->`), with
131
+ the workflow's own `GITHUB_TOKEN`. Inputs: `base`, `head`, `comment`, `fail-on` (none | risk), `paths` (globs),
132
+ `version`. Pull requests from forks get the job summary only, and it says why; `pull_request_target` is never
133
+ needed. Runs in your CI: no code leaves GitHub, no AI. Docs: `docs/github-action.md`. The `.thunder` check action
134
+ moved to `SkillsTechTalk/thunderlang/check` (the old root action pointed at a package name that does not exist).
135
+ - **`renderReviewComment(review)`** (core, browser-safe): the comment, grouped by changed action, rule, or function,
136
+ risks first, with honest counts (explained in sentences, shown as code, Thunder cannot check), a link to
137
+ thunderlang.dev, and a size cap that leaves out whole entries and says "N more not shown".
138
+ - **`thunder review --base <ref> --head <ref> --format markdown|json --paths <glob,...>`**: flag forms of the existing
139
+ positional arguments and `--json`, and `--paths` to review only matching files.
140
+
1
141
  # 1.0.4
2
142
 
3
143
  - **Fix: no false readings left in the fresh audit outside SQL.** An independent review of 1.0.3 on 32 repositories