@skillstech/thunderlang 1.7.0 → 1.8.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 +75 -0
- package/README.md +10 -3
- package/dist/core.cjs +234 -20
- package/dist/index.cjs +8853 -1045
- package/dist/learn.cjs +1339 -69
- package/package.json +1 -1
- package/src/cli-main.mjs +312 -115
- package/src/core/check.mjs +312 -6
- package/src/core/cli.mjs +60 -8
- package/src/core/csharp-run.mjs +2 -2
- package/src/core/diagnostics.mjs +9 -0
- package/src/core/engine-core.mjs +141 -19
- package/src/core/engine-values.mjs +1 -0
- package/src/core/engine.mjs +131 -7
- package/src/core/go-run.mjs +2 -2
- package/src/core/index.mjs +6 -2
- package/src/core/java-run.mjs +2 -2
- package/src/core/kind.mjs +3 -0
- package/src/core/lexer.mjs +16 -2
- package/src/core/parser.mjs +200 -15
- package/src/core/project-root.mjs +18 -0
- package/src/core/project.mjs +15 -18
- package/src/core/react-run.mjs +2 -2
- package/src/core/runtime-go/thunder_runtime.go +269 -1
- package/src/core/runtime-python.mjs +365 -3
- package/src/core/runtime-typescript.mjs +150 -5
- package/src/core/rust-run.mjs +2 -2
- package/src/core/serving.mjs +12 -0
- package/src/core/store-format.mjs +110 -0
- package/src/core/target-go.mjs +10 -3
- package/src/core/target-python.mjs +38 -5
- package/src/core/target-typescript.mjs +62 -6
- package/src/core/typescript-run.mjs +6 -4
- package/src/core-changes-fs.mjs +28 -0
- package/src/core-changes.d.mts +67 -0
- package/src/core-changes.mjs +603 -0
- package/src/core-rules.mjs +146 -0
- package/src/core-services.d.mts +4 -0
- package/src/core-services.mjs +49 -0
- package/src/emit.mjs +1 -1
- package/src/evidence.mjs +28 -0
- package/src/examples.d.mts +21 -0
- package/src/examples.mjs +175 -0
- package/src/index.d.ts +4 -0
- package/src/index.mjs +4 -0
- package/src/mcp.mjs +42 -3
- package/src/program.d.mts +4 -0
- package/src/program.mjs +4 -0
- package/src/read-repo-fs.mjs +2 -1
- package/src/review.mjs +69 -3
- package/src/system.mjs +1 -1
- package/src/trace-cli.mjs +8 -3
- package/src/trace-fs.mjs +29 -3
- package/src/trace.mjs +23 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
+
# 1.8.0
|
|
2
|
+
|
|
3
|
+
- **Behaviour changes across services** (roadmap 3.4 + D.5, part 2). Thunder Trace reads Thunder Core programs:
|
|
4
|
+
each endpoint is a route and each `the answer from GET "https://…"` a request, so other services link to them and
|
|
5
|
+
they link to others. A Thunder endpoint also changes when a rule it uses changes: `thunder trace impact --diff` says
|
|
6
|
+
"POST /orders/{number}/refunds changed (through review limit, which changed), and 1 caller in other repositories
|
|
7
|
+
depends on it", and, from running both versions, what changes in its answers. `thunder review --services
|
|
8
|
+
<folder,…>` adds an item for each changed endpoint another service calls, naming the callers. `thunder review
|
|
9
|
+
--evidence` gives the comparison as an `evidence-event-v1` event (`behaviour.compared`, safe-derived). The MCP tool
|
|
10
|
+
`intent_trace` with `diff` carries the same. `buildTrace` stays free of the Core compiler: `readRepoDir` reads
|
|
11
|
+
the Core facts, or pass `buildTrace(repos, { core: coreServiceFacts })`.
|
|
12
|
+
|
|
13
|
+
- **Behaviour changes in Thunder Core programs, and what to look at again** (roadmap 3.4 + D.5, part 1).
|
|
14
|
+
`thunder review` now reads `.thunder` programs instead of listing them as not read. Each rule has a stable name
|
|
15
|
+
from what it is (`function:decide refund`, `keep:review limit`, `endpoint:POST /orders`, a Never rule, a test), so
|
|
16
|
+
moved or re-spaced code is unchanged and a renamed function is a rename. A function whose steps changed, or that
|
|
17
|
+
uses something that changed, is run before and after on the same inputs (made from the numbers and text in both
|
|
18
|
+
versions), and the answers that differ are said in words with the input that decides them: "now a review Refund
|
|
19
|
+
instead of an approved Refund when amount is from $50.00 to $99.99". Tests that reach a change run before and
|
|
20
|
+
after; one that now fails comes first. Every change lists what to look at again. The rest of a changed program's
|
|
21
|
+
project is read from git for this. Tested evidence on the inputs tried, not a proof; programs run on the Thunder
|
|
22
|
+
engine only (no files, network, or saved data; step and time limits), and functions that use saved data or another
|
|
23
|
+
service are not run and say so.
|
|
24
|
+
- **`thunder affected <rule…> [--in <folder>]`**: the functions and endpoints that use a rule, the tests and Expect
|
|
25
|
+
lines that reach it, and the Never rules and stored lists they rely on, each with its file and line. Library:
|
|
26
|
+
`coreChanges(oldFiles, newFiles)` and `affectedBy(files, change)` from `@skillstech/thunderlang/program`
|
|
27
|
+
(`thunder-core-changes-v1`, `thunder-affected-v1`). MCP: `intent_core_changes` and `intent_affected` (local only).
|
|
28
|
+
|
|
29
|
+
- **Faster everyday commands (roadmap 2.0, Speed).** Each command now loads only the parts of the compiler it uses,
|
|
30
|
+
instead of all ~180 files every time. CPU time on Node 22: `thunder check` 80 → 40 ms, `thunder run` and
|
|
31
|
+
`thunder test` 90 → 40 ms, `thunder read` of a small file 110 → 60 ms, of 4,300 lines of Go 350 → 230 ms,
|
|
32
|
+
`thunder --version` 80 → 20 ms. Nothing a command prints changed. (For contributors: `compiler/scripts/lazy-cli.mjs`
|
|
33
|
+
works out, from the code, which modules each command can reach; after adding an import or a command to
|
|
34
|
+
`cli-main.mjs`, run it. A test fails if it is out of date.)
|
|
35
|
+
|
|
36
|
+
- **The reference application: Refund Desk** (`examples/apps/refund-desk`). Products and stock, orders, and refunds
|
|
37
|
+
decided by one rule, with saved data, an HTTP API, and tests, built only from shipped features. Its tests pass, and
|
|
38
|
+
a client session gets the same bytes, on Python, compiled TypeScript, and the Thunder engine. Building it fixed:
|
|
39
|
+
- `Stop … and status 404` can be written in a helper, not only in an endpoint (`Give … with status` stays in the
|
|
40
|
+
endpoint, TC218).
|
|
41
|
+
- Tests in `tests/` can call the endpoints in `src/`.
|
|
42
|
+
- While `src/` has problems, those are reported alone, not again as unknown names in the tests.
|
|
43
|
+
- **New TC219:** inside `where` or `sorted by`, a name that is both each item's field and your own value
|
|
44
|
+
(`orders where number is number` kept every order). The message says which is used and how to rename.
|
|
45
|
+
- JSON for an either/or value carries `which` and only its alternative's fields, and a request may name a two-word
|
|
46
|
+
input the way answers write it (`order_number`).
|
|
47
|
+
|
|
48
|
+
- **HTTP: answer requests and call other services.** `When someone calls GET /habits/{name}:` is an endpoint;
|
|
49
|
+
`thunder run` answers on `http://127.0.0.1:8080` (`--port` to change it), one request at a time, with inputs read by
|
|
50
|
+
kind from the path, query, or JSON body, and answers written as JSON by kind (as in a stored list). `Give … with
|
|
51
|
+
status 201` and `Stop with "…" and status 404` set the status; a broken Never rule answers 422, any other failure 500
|
|
52
|
+
in words. `the answer from GET "…" as Rate` calls another service (TC510 when it fails). Tests call endpoints
|
|
53
|
+
directly (`calling GET /habits/walk`). Python, TypeScript, and the Thunder engine give the same statuses and bytes;
|
|
54
|
+
other targets refuse it for now (TC411).
|
|
55
|
+
- **The CLI refuses an option it doesn't know** instead of ignoring it (`--core --target go` written as one word used
|
|
56
|
+
to run the default target), and suggests the closest one.
|
|
57
|
+
- **Either/or data types.** `A Payment is one of:` with one alternative per line (`Successful with amount as money`,
|
|
58
|
+
`Pending`). Build one with `a successful Payment with amount $5`; choose with `Depending on payment:`, which must
|
|
59
|
+
cover every alternative or say `Otherwise:` (TC215); read an alternative's field only where it is known, inside its
|
|
60
|
+
case or under `If payment is successful:` (TC216); a name that isn't an alternative says which ones are (TC217).
|
|
61
|
+
Alternatives can hold the same type, so trees and lists are written directly. It runs the same on every target.
|
|
62
|
+
- **Drafts with holes.** Write `?` or `?number` (`?money`, `?Habit`, …) where you don't know the value yet. Thunder
|
|
63
|
+
checks the rest, says what each hole needs (written, or expected where it stands) and what in scope already fits,
|
|
64
|
+
and never chooses a value (TC120). A draft never runs or builds; `thunder check` calls it a draft and counts holes
|
|
65
|
+
apart from problems. `compileCore` gives `holes` and `draft` for editors and OpenThunder.
|
|
66
|
+
- **Saved data: stored lists.** `Store habits as a list of Habit` keeps a list of records between runs, in
|
|
67
|
+
`data/habits.json` (plain JSON, each field written by its kind; money and numbers exact). It is filled when the
|
|
68
|
+
program starts and saved only when it finishes well; tests start empty and never save. Python, compiled TypeScript,
|
|
69
|
+
compiled Go, and the Thunder engine read and write the same file, byte for byte; other targets refuse it for now
|
|
70
|
+
(new TC410). A damaged file is reported at the `Store` line with the item and field (TC509), the same on every engine.
|
|
71
|
+
- **`examplesOf(source)`: every example in a file, as data.** From `@skillstech/thunderlang/program` (and the main
|
|
72
|
+
entry): each Core `Expect` and each mission `case` or `scenario`, with its line, the function or decision it checks,
|
|
73
|
+
its inputs as written, and the expected answer (`thunder-examples-v1`). Examples are read even while another part of
|
|
74
|
+
the file does not compile. Tools such as OpenThunder's Check can stop parsing Thunder text.
|
|
75
|
+
|
|
1
76
|
# 1.7.0
|
|
2
77
|
|
|
3
78
|
- **.NET and NuGet from Thunder Core.** `Use "System.IO.Path" from .NET as paths` and `Use "Humanizer.NumberToWordsExtension"
|
package/README.md
CHANGED
|
@@ -55,6 +55,12 @@ thunder diff <before> <after> thunder merge <base> <ours> <theirs>
|
|
|
55
55
|
|
|
56
56
|
# Code <-> intent
|
|
57
57
|
thunder lift <file> thunder approve <file> thunder drift <file>
|
|
58
|
+
|
|
59
|
+
# What a change does
|
|
60
|
+
thunder review main # what changed in meaning since main; Core programs compared rule by rule and run
|
|
61
|
+
thunder review main --services ../web,../billing # also the services that call a changed endpoint
|
|
62
|
+
thunder affected "review limit" --in app/ # what to look at again when a rule changes: functions, tests, Never rules
|
|
63
|
+
thunder trace impact --diff ../web ../orders # what the current changes can affect across repositories
|
|
58
64
|
```
|
|
59
65
|
|
|
60
66
|
Run `thunder help` for the full reference.
|
|
@@ -158,11 +164,12 @@ scannable location: `contract-graph.json`, `architecture-graph.json`,
|
|
|
158
164
|
|
|
159
165
|
## Status
|
|
160
166
|
|
|
161
|
-
Deterministic and tested (
|
|
167
|
+
Deterministic and tested (about 2,000 tests: unit, property, fuzz, composition, and cross-language conformance).
|
|
168
|
+
Each command loads only the parts of the compiler it uses (`thunder check` takes about 40 ms of CPU on Node 22). Five-profile
|
|
162
169
|
language with an executable runtime, first-class tests, outcome contracts, style intent,
|
|
163
170
|
governance/privacy, and security/type checks; nine export adapters
|
|
164
171
|
(DMN/BPMN/NuSMV/JSON-Schema/OpenAPI/Design-Tokens/CSS/Mermaid/Playwright), DMN/BPMN import,
|
|
165
172
|
native graph<->source round-trip, schema migrations, a canonical proof envelope
|
|
166
|
-
(`intent-proof-v1`), and SARIF code-scanning output.
|
|
167
|
-
`intent-graph-v1` schema
|
|
173
|
+
(`intent-proof-v1`), and SARIF code-scanning output. The language may still change before 2.0.0;
|
|
174
|
+
from 2.0.0, programs stay compatible or `thunder upgrade` updates them. The `intent-graph-v1` schema versions on its own. See the
|
|
168
175
|
[docs](https://thunderlang.dev/docs) and the [spec](https://thunderlang.dev/docs/spec).
|
package/dist/core.cjs
CHANGED
|
@@ -19410,7 +19410,7 @@ function notesSummary(ast) {
|
|
|
19410
19410
|
byLens
|
|
19411
19411
|
};
|
|
19412
19412
|
}
|
|
19413
|
-
var COMPILER_VERSION = "1.
|
|
19413
|
+
var COMPILER_VERSION = "1.8.0";
|
|
19414
19414
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
19415
19415
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
19416
19416
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -30327,12 +30327,25 @@ function formatDiagnostic(d, file) {
|
|
|
30327
30327
|
}
|
|
30328
30328
|
|
|
30329
30329
|
// src/core/lexer.mjs
|
|
30330
|
-
var SYMS = ["==", "!=", "<>", "<=", ">=", "+", "-", "*", "/", "(", ")", "[", "]", ",", ":", ".", "=", "<", ">"];
|
|
30330
|
+
var SYMS = ["==", "!=", "<>", "<=", ">=", "+", "-", "*", "/", "(", ")", "[", "]", ",", ":", ".", "=", "<", ">", "?"];
|
|
30331
30331
|
var WORD_START = /[\p{L}_]/u;
|
|
30332
30332
|
var WORD_CHAR = /[\p{L}\p{N}_]/u;
|
|
30333
30333
|
function tokenizeLine(text2, line, colOffset = 0) {
|
|
30334
30334
|
const toks2 = [];
|
|
30335
30335
|
let i = 0;
|
|
30336
|
+
const ep = text2.match(/^(when)(\s+)(someone)(\s+)(calls)(\s+)([A-Za-z]+)(\s+)(\/\S*?)(\s*)(:)(\s*(#.*)?)$/i);
|
|
30337
|
+
if (ep) {
|
|
30338
|
+
let col = colOffset + 1;
|
|
30339
|
+
const out = [];
|
|
30340
|
+
const parts = ep.slice(1, 12);
|
|
30341
|
+
parts.forEach((part, k) => {
|
|
30342
|
+
if (k === 8) out.push({ t: "path", text: part, col, line });
|
|
30343
|
+
else if (k === 10) out.push({ t: "sym", text: ":", col, line });
|
|
30344
|
+
else if (part && !/^\s*$/.test(part)) out.push({ t: "word", text: part, lower: part.toLowerCase(), col, line });
|
|
30345
|
+
col += part.length;
|
|
30346
|
+
});
|
|
30347
|
+
return out;
|
|
30348
|
+
}
|
|
30336
30349
|
const at2 = (k = 0) => text2[i + k];
|
|
30337
30350
|
while (i < text2.length) {
|
|
30338
30351
|
const c = at2();
|
|
@@ -30632,6 +30645,15 @@ var ExprParser = class {
|
|
|
30632
30645
|
}
|
|
30633
30646
|
if (s.word("in")) return wrap({ k: "contains", l: this.add(s, o), r: l, line });
|
|
30634
30647
|
if (s.done()) s.fail('Something is missing after "is".', "For example: is 10, is at least 18, is nothing, is empty.", "TC108");
|
|
30648
|
+
if (this.names.alts?.size && s.peek()?.t === "word") {
|
|
30649
|
+
const run = [];
|
|
30650
|
+
for (let j = s.i; s.ts[j]?.t === "word" && !RESERVED2.has(s.ts[j].lower); j++) run.push(s.ts[j]);
|
|
30651
|
+
const ak = this.longest(run, (key) => this.names.alts.has(key));
|
|
30652
|
+
if (ak && !this.longest(run, (key) => this.names.known.has(key))) {
|
|
30653
|
+
s.i += ak;
|
|
30654
|
+
return wrap({ k: "isAlt", e: l, alt: keyOf(run.slice(0, ak)), text: run.slice(0, ak).map((x) => x.text).join(" "), line });
|
|
30655
|
+
}
|
|
30656
|
+
}
|
|
30635
30657
|
return { k: "cmp", op: neg ? "!=" : "==", l, r: this.add(s, o), line };
|
|
30636
30658
|
}
|
|
30637
30659
|
return l;
|
|
@@ -30786,9 +30808,50 @@ var ExprParser = class {
|
|
|
30786
30808
|
const key = keyOf(run.slice(0, k));
|
|
30787
30809
|
return { k: "record", name: this.names.records.has(key) ? key : key.replace(/s$/, "") };
|
|
30788
30810
|
}
|
|
30811
|
+
/** The fields a record is built with: with name "Ann" and balance $10 (none without "with"). */
|
|
30812
|
+
recordFields(s, line) {
|
|
30813
|
+
const fields = [];
|
|
30814
|
+
if (s.word("with")) {
|
|
30815
|
+
do {
|
|
30816
|
+
const fr = this.wordRun(s);
|
|
30817
|
+
if (!fr.length) s.fail(`I expected a field name after "with" (for example: with name "Ann").`, null, "TC108");
|
|
30818
|
+
const fk = this.longest(fr, (key) => this.names.fields.has(key)) || fr.length;
|
|
30819
|
+
s.i -= fr.length - fk;
|
|
30820
|
+
fields.push({ name: keyOf(fr.slice(0, fk)), text: fr.slice(0, fk).map((x) => x.text).join(" "), e: this.expr(s, { noAnd: true }), line });
|
|
30821
|
+
} while ((isSym(s.peek(), ",") || isWord(s.peek(), "and")) && this.fieldAhead(s, 1) && s.next());
|
|
30822
|
+
}
|
|
30823
|
+
return fields;
|
|
30824
|
+
}
|
|
30789
30825
|
primary(s, o) {
|
|
30790
30826
|
const t = s.peek();
|
|
30791
30827
|
const line = s.line;
|
|
30828
|
+
const METHODS2 = ["get", "post", "put", "patch", "delete"];
|
|
30829
|
+
if (isWord(t, "answer") && isWord(s.peek(1), "from") && METHODS2.includes(s.peek(2)?.lower)) {
|
|
30830
|
+
s.i += 2;
|
|
30831
|
+
const method = s.next().text.toUpperCase();
|
|
30832
|
+
const url = this.primary(s, { ...o, noAnd: true });
|
|
30833
|
+
let body2 = null, as = null;
|
|
30834
|
+
if (s.word("with")) {
|
|
30835
|
+
body2 = this.expr(s, { ...o, noAnd: true });
|
|
30836
|
+
if (body2.k === "conv" && body2.type) {
|
|
30837
|
+
as = body2.type;
|
|
30838
|
+
body2 = body2.e;
|
|
30839
|
+
}
|
|
30840
|
+
}
|
|
30841
|
+
if (!as && s.word("as")) as = this.typeRef(s);
|
|
30842
|
+
return { k: "httpCall", method, url, body: body2, as, line };
|
|
30843
|
+
}
|
|
30844
|
+
if (isWord(t, "calling") && METHODS2.includes(s.peek(1)?.lower) && isSym(s.peek(2), "/")) {
|
|
30845
|
+
s.i += 2;
|
|
30846
|
+
const method = s.ts[s.i - 1].text.toUpperCase();
|
|
30847
|
+
let path = "";
|
|
30848
|
+
let prev = null;
|
|
30849
|
+
while (s.peek() && (prev === null ? isSym(s.peek(), "/") : s.peek().col === prev.col + String(prev.text).length && (isSym(s.peek(), "/") || isSym(s.peek(), "-") || s.peek().t === "word" || s.peek().t === "num"))) {
|
|
30850
|
+
prev = s.next();
|
|
30851
|
+
path += prev.text;
|
|
30852
|
+
}
|
|
30853
|
+
return { k: "callEndpoint", method, path, fields: this.recordFields(s, line), line };
|
|
30854
|
+
}
|
|
30792
30855
|
if (!t) s.fail("A value is missing at the end of this line.", null, "TC108");
|
|
30793
30856
|
if (t.t === "num") {
|
|
30794
30857
|
s.next();
|
|
@@ -30808,6 +30871,13 @@ var ExprParser = class {
|
|
|
30808
30871
|
s.next();
|
|
30809
30872
|
return { k: "str", parts: t.parts.map((p) => typeof p === "string" ? p : { e: this.parse(p.tokens, line), source: p.source }), line };
|
|
30810
30873
|
}
|
|
30874
|
+
if (isSym(t, "?")) {
|
|
30875
|
+
s.next();
|
|
30876
|
+
const next = s.peek();
|
|
30877
|
+
let want = null;
|
|
30878
|
+
if (next && next.t === "word" && t.col != null && next.col === t.col + 1) want = this.typeRef(s);
|
|
30879
|
+
return { k: "draftHole", want, line, col: t.col };
|
|
30880
|
+
}
|
|
30811
30881
|
if (isSym(t, "(")) {
|
|
30812
30882
|
s.next();
|
|
30813
30883
|
const e = this.expr(s, {});
|
|
@@ -30893,22 +30963,31 @@ var ExprParser = class {
|
|
|
30893
30963
|
}
|
|
30894
30964
|
if (RESERVED2.has(w)) s.fail(`"${t.text}" is a Thunder word and can't start a value here.`, null, "TC105");
|
|
30895
30965
|
const run = this.wordRun(s);
|
|
30966
|
+
if (o.article && this.names.alts?.size) {
|
|
30967
|
+
for (let i = 1; i < run.length; i++) {
|
|
30968
|
+
const alt = keyOf(run.slice(0, i));
|
|
30969
|
+
const recs = this.names.alts.get(alt);
|
|
30970
|
+
if (!recs) continue;
|
|
30971
|
+
const rk = this.longest(run.slice(i), (key) => recs.includes(key));
|
|
30972
|
+
if (!rk || i + rk !== run.length) continue;
|
|
30973
|
+
s.i -= run.length - i - rk;
|
|
30974
|
+
const node2 = { k: "new", record: keyOf(run.slice(i, i + rk)), alt, altText: run.slice(0, i).map((x) => x.text).join(" "), fields: this.recordFields(s, line), line };
|
|
30975
|
+
return node2;
|
|
30976
|
+
}
|
|
30977
|
+
for (let i = 1; i < run.length; i++) {
|
|
30978
|
+
const rk = this.longest(run.slice(i), (key) => this.names.altsOf.has(key));
|
|
30979
|
+
if (!rk || i + rk !== run.length) continue;
|
|
30980
|
+
s.i -= run.length - i - rk;
|
|
30981
|
+
return { k: "new", record: keyOf(run.slice(i, i + rk)), alt: keyOf(run.slice(0, i)), altText: run.slice(0, i).map((x) => x.text).join(" "), fields: this.recordFields(s, line), line };
|
|
30982
|
+
}
|
|
30983
|
+
}
|
|
30896
30984
|
let off = run[0]?.lower === "new" && run.length > 1 ? 1 : 0;
|
|
30897
30985
|
const recK = this.longest(run.slice(off), (key) => this.names.records.has(key));
|
|
30898
30986
|
const wantsRecord = o.article || off || isWord(s.peek(), "with") || !this.longest(run, (key) => this.names.known.has(key));
|
|
30899
30987
|
if (recK && wantsRecord && recK + off === run.length) {
|
|
30900
30988
|
s.i -= run.length - off - recK;
|
|
30901
30989
|
const name = keyOf(run.slice(off, off + recK));
|
|
30902
|
-
const fields =
|
|
30903
|
-
if (s.word("with")) {
|
|
30904
|
-
do {
|
|
30905
|
-
const fr = this.wordRun(s);
|
|
30906
|
-
if (!fr.length) s.fail(`I expected a field name after "with" (for example: with name "Ann").`, null, "TC108");
|
|
30907
|
-
const fk2 = this.longest(fr, (key) => this.names.fields.has(key)) || fr.length;
|
|
30908
|
-
s.i -= fr.length - fk2;
|
|
30909
|
-
fields.push({ name: keyOf(fr.slice(0, fk2)), text: fr.slice(0, fk2).map((x) => x.text).join(" "), e: this.expr(s, { noAnd: true }), line });
|
|
30910
|
-
} while ((isSym(s.peek(), ",") || isWord(s.peek(), "and")) && this.fieldAhead(s, 1) && s.next());
|
|
30911
|
-
}
|
|
30990
|
+
const fields = this.recordFields(s, line);
|
|
30912
30991
|
const node2 = { k: "new", record: name, fields, line };
|
|
30913
30992
|
if (!fields.length && this.open) this.open.push(node2);
|
|
30914
30993
|
return node2;
|
|
@@ -41201,22 +41280,26 @@ var end = (repo, at2, extra = {}) => ({ repo: repo.name, member: at2.member, lab
|
|
|
41201
41280
|
var distinctive = (segs) => segs.some((s) => s !== "*");
|
|
41202
41281
|
var lower = (segs) => segs.map((s) => s.toLowerCase());
|
|
41203
41282
|
var pathMatch = (a, b) => segsMatch(lower(a), lower(b));
|
|
41204
|
-
function buildTrace(repos) {
|
|
41283
|
+
function buildTrace(repos, { core = null } = {}) {
|
|
41205
41284
|
const names = /* @__PURE__ */ new Set();
|
|
41206
41285
|
const read = repos.map((r) => {
|
|
41207
41286
|
if (!r.name || names.has(r.name)) throw new Error(`Each repository needs its own name; "${r.name}" is used twice.`);
|
|
41208
41287
|
names.add(r.name);
|
|
41209
|
-
const
|
|
41210
|
-
const
|
|
41288
|
+
const other = r.files.filter((f) => !/\.thunder$/i.test(f.path));
|
|
41289
|
+
const model = thunderModel(other, { name: r.name });
|
|
41290
|
+
const facts = serviceFacts(model, other);
|
|
41291
|
+
const cf = r.coreFacts ?? (core ? core(r.files) : { routes: [], requests: [], unknown: [], files: 0 });
|
|
41292
|
+
for (const k of ["routes", "requests", "unknown"]) facts[k] = [...facts[k], ...cf[k]];
|
|
41293
|
+
const coreFiles = cf.files;
|
|
41211
41294
|
const real = (x) => !isTestFile(x.file);
|
|
41212
|
-
const data = dataFacts(
|
|
41295
|
+
const data = dataFacts(other, model);
|
|
41213
41296
|
const testItems = ["routes", "listeners", "requests", "publishes"].reduce((n, k) => n + facts[k].filter((x) => !real(x)).length, 0) + data.testItems;
|
|
41214
41297
|
return {
|
|
41215
41298
|
name: r.name,
|
|
41216
41299
|
sha: r.sha ?? null,
|
|
41217
41300
|
dirty: !!r.dirty,
|
|
41218
|
-
files: model.files.length,
|
|
41219
|
-
languages: [
|
|
41301
|
+
files: model.files.length + coreFiles,
|
|
41302
|
+
languages: [.../* @__PURE__ */ new Set([...model.files.map((f) => f.language), ...coreFiles ? ["thunder"] : []])].sort(),
|
|
41220
41303
|
routes: facts.routes.filter(real),
|
|
41221
41304
|
listeners: facts.listeners.filter(real),
|
|
41222
41305
|
requests: facts.requests.filter(real),
|
|
@@ -42408,12 +42491,108 @@ function thunderizeFiles(files, { name = "app" } = {}) {
|
|
|
42408
42491
|
` };
|
|
42409
42492
|
}
|
|
42410
42493
|
|
|
42494
|
+
// src/core/kind.mjs
|
|
42495
|
+
var MISSION_KEYWORDS = /* @__PURE__ */ new Set([
|
|
42496
|
+
"mission",
|
|
42497
|
+
"note",
|
|
42498
|
+
"goal",
|
|
42499
|
+
"why",
|
|
42500
|
+
"requires",
|
|
42501
|
+
"requires_skill",
|
|
42502
|
+
"demonstrates",
|
|
42503
|
+
"input",
|
|
42504
|
+
"output",
|
|
42505
|
+
"guarantees",
|
|
42506
|
+
"guarantee",
|
|
42507
|
+
"never",
|
|
42508
|
+
"constraints",
|
|
42509
|
+
"invariant",
|
|
42510
|
+
"assumptions",
|
|
42511
|
+
"risks",
|
|
42512
|
+
"target",
|
|
42513
|
+
"style",
|
|
42514
|
+
"verify",
|
|
42515
|
+
"errors",
|
|
42516
|
+
"examples",
|
|
42517
|
+
"service",
|
|
42518
|
+
"api",
|
|
42519
|
+
"event",
|
|
42520
|
+
"database",
|
|
42521
|
+
"architecture",
|
|
42522
|
+
"selection",
|
|
42523
|
+
"use",
|
|
42524
|
+
"title",
|
|
42525
|
+
"for",
|
|
42526
|
+
"persona",
|
|
42527
|
+
"customer",
|
|
42528
|
+
"problem",
|
|
42529
|
+
"evidence",
|
|
42530
|
+
"outcome",
|
|
42531
|
+
"metric",
|
|
42532
|
+
"scope",
|
|
42533
|
+
"non_goal",
|
|
42534
|
+
"owner",
|
|
42535
|
+
"unknown",
|
|
42536
|
+
"question",
|
|
42537
|
+
"assumption",
|
|
42538
|
+
"experience",
|
|
42539
|
+
"pattern",
|
|
42540
|
+
"style_intent",
|
|
42541
|
+
"decision",
|
|
42542
|
+
"property",
|
|
42543
|
+
"scenario",
|
|
42544
|
+
"evaluation",
|
|
42545
|
+
"capability",
|
|
42546
|
+
"interface",
|
|
42547
|
+
"component",
|
|
42548
|
+
"artifact",
|
|
42549
|
+
"outcome_contract",
|
|
42550
|
+
"release",
|
|
42551
|
+
"result",
|
|
42552
|
+
"learning",
|
|
42553
|
+
"test",
|
|
42554
|
+
"data",
|
|
42555
|
+
"waiver",
|
|
42556
|
+
"command",
|
|
42557
|
+
"on",
|
|
42558
|
+
"lifecycle",
|
|
42559
|
+
"always",
|
|
42560
|
+
"eventually",
|
|
42561
|
+
"until",
|
|
42562
|
+
"conflict",
|
|
42563
|
+
"implement",
|
|
42564
|
+
"requires_skills",
|
|
42565
|
+
"approval",
|
|
42566
|
+
"inferred",
|
|
42567
|
+
"maps_to",
|
|
42568
|
+
"needs_review",
|
|
42569
|
+
"source",
|
|
42570
|
+
"confidence"
|
|
42571
|
+
]);
|
|
42572
|
+
function firstCodeLine(source) {
|
|
42573
|
+
for (const raw of String(source).split(/\r?\n/)) {
|
|
42574
|
+
const line = raw.trim();
|
|
42575
|
+
if (line && !line.startsWith("#")) return { text: line, indented: raw.length > 0 && /^\s/.test(raw) };
|
|
42576
|
+
}
|
|
42577
|
+
return null;
|
|
42578
|
+
}
|
|
42579
|
+
function fileKind(source) {
|
|
42580
|
+
const first = firstCodeLine(source);
|
|
42581
|
+
if (!first) return { kind: "mission", reason: "the file has no lines yet" };
|
|
42582
|
+
const m = /^([a-z_]+)(?:\s+([A-Za-z_][\w.-]*))?\s*$/.exec(first.text);
|
|
42583
|
+
if (!first.indented && m && MISSION_KEYWORDS.has(m[1])) return { kind: "mission", reason: `its first line starts with the mission keyword "${m[1]}"` };
|
|
42584
|
+
return { kind: "program", reason: `its first line ("${first.text.length > 40 ? `${first.text.slice(0, 40)}\u2026` : first.text}") cannot start a mission` };
|
|
42585
|
+
}
|
|
42586
|
+
var isCoreProgram = (path, source) => /\.thunder$/i.test(path) && fileKind(source ?? "").kind === "program";
|
|
42587
|
+
|
|
42411
42588
|
// src/review.mjs
|
|
42412
42589
|
var REVIEW_SCHEMA = "thunder-review-v1";
|
|
42413
42590
|
var REVIEW_MARKER = "<!-- thunder-review -->";
|
|
42414
42591
|
var SEVERITY_ORDER = ["risk", "meaning", "form"];
|
|
42415
42592
|
var KIND_ORDER = [
|
|
42416
42593
|
"unreadable",
|
|
42594
|
+
"test-fails",
|
|
42595
|
+
"callers",
|
|
42417
42596
|
"not-read",
|
|
42418
42597
|
"infrastructure",
|
|
42419
42598
|
"stop-removed",
|
|
@@ -43024,7 +43203,7 @@ function mostlyIn(a, b) {
|
|
|
43024
43203
|
}
|
|
43025
43204
|
return hit / want.length >= 0.75;
|
|
43026
43205
|
}
|
|
43027
|
-
function thunderReview(oldFiles, newFiles) {
|
|
43206
|
+
function thunderReview(oldFiles, newFiles, { core = null, context = null } = {}) {
|
|
43028
43207
|
detailsCache = /* @__PURE__ */ new WeakMap();
|
|
43029
43208
|
const A = side(oldFiles || []), B = side(newFiles || []);
|
|
43030
43209
|
const items = [];
|
|
@@ -43103,11 +43282,14 @@ function thunderReview(oldFiles, newFiles) {
|
|
|
43103
43282
|
{ before: null, after: n.text }
|
|
43104
43283
|
));
|
|
43105
43284
|
compareThings(A, B, items);
|
|
43285
|
+
const coreRead = core ? coreReview(core, oldFiles || [], newFiles || [], context, items) : { paths: /* @__PURE__ */ new Set(), result: null };
|
|
43286
|
+
const corePaths = coreRead.paths;
|
|
43106
43287
|
const paths = [.../* @__PURE__ */ new Set([...A.sources.keys(), ...B.sources.keys()])];
|
|
43107
43288
|
const notRead = [];
|
|
43108
43289
|
for (const p of paths) {
|
|
43109
43290
|
const before = A.sources.get(p), after = B.sources.get(p);
|
|
43110
43291
|
if (before === after) continue;
|
|
43292
|
+
if (corePaths.has(p)) continue;
|
|
43111
43293
|
const lang = !isInfra(p) && readableLanguage(p);
|
|
43112
43294
|
if (!lang) {
|
|
43113
43295
|
if (isInfra(p)) items.push(item2("infrastructure", "risk", p, { file: p, line: 1 }, `${before == null ? "New" : after == null ? "Removed" : "Changed"} infrastructure or pipeline file. Thunder does not read these in this version, so check it yourself.`, before != null && after != null ? lineChanges(before.split("\n"), after.split("\n")) : null));
|
|
@@ -43173,7 +43355,39 @@ function thunderReview(oldFiles, newFiles) {
|
|
|
43173
43355
|
const count2 = (s) => items.filter((x) => x.severity === s).length;
|
|
43174
43356
|
const summary2 = { meaning: count2("meaning"), risk: count2("risk"), form: count2("form"), unchanged, files: paths.filter((p) => A.sources.get(p) !== B.sources.get(p)).length };
|
|
43175
43357
|
const onlyNotRead = !items.length && summary2.files && notRead.length === summary2.files;
|
|
43176
|
-
|
|
43358
|
+
const out = { schema: REVIEW_SCHEMA, summary: summary2, says: onlyNotRead ? "Only files Thunder does not read changed." : summaryLine(summary2), items, notRead };
|
|
43359
|
+
if (coreRead.result) Object.defineProperty(out, "core", { value: coreRead.result, enumerable: false });
|
|
43360
|
+
return out;
|
|
43361
|
+
}
|
|
43362
|
+
function coreKind(c) {
|
|
43363
|
+
if (c.change === "not-compiled") return "unreadable";
|
|
43364
|
+
if (c.kind === "test" && c.severity === "risk" && c.change !== "removed") return "test-fails";
|
|
43365
|
+
if (c.change === "added" || c.change === "removed" || c.change === "renamed") return c.kind === "never" && c.change === "removed" ? "stop-removed" : c.change;
|
|
43366
|
+
if (c.kind === "keep") return "rule-limit";
|
|
43367
|
+
if (c.kind === "function" && c.behaviour?.changed) return "rule-answer";
|
|
43368
|
+
if (c.kind === "never") return "stop-changed";
|
|
43369
|
+
if (c.kind === "record" || c.kind === "store") return "thing";
|
|
43370
|
+
if (c.kind === "main") return "outside";
|
|
43371
|
+
return "steps";
|
|
43372
|
+
}
|
|
43373
|
+
var CORE_SUBJECT = { keep: (c) => `${c.subject} (kept value)`, main: (c) => c.subject };
|
|
43374
|
+
function coreReview(coreChanges, oldFiles, newFiles, context, items) {
|
|
43375
|
+
const core = (fs) => fs.filter((f) => f && isCoreProgram(f.path, f.source));
|
|
43376
|
+
const merge = (changed, extra) => {
|
|
43377
|
+
const have = new Set(changed.map((f) => f.path));
|
|
43378
|
+
return [...changed, ...core(extra ?? []).filter((f) => !have.has(f.path))];
|
|
43379
|
+
};
|
|
43380
|
+
const oldCore = core(oldFiles), newCore = core(newFiles);
|
|
43381
|
+
if (!oldCore.length && !newCore.length) return { paths: /* @__PURE__ */ new Set(), result: null };
|
|
43382
|
+
const r = coreChanges(merge(oldCore, context?.old), merge(newCore, context?.new));
|
|
43383
|
+
for (const c of r.changes) {
|
|
43384
|
+
const look = (c.affects ?? []).slice(0, 6).map((x) => `${x.subject} (\`${x.file}:${x.line}\`${x.test ? `, ${x.test === "fails" ? "**fails now**" : "passes"}` : ""})`);
|
|
43385
|
+
const more = (c.affects?.length ?? 0) > 6 ? `, and ${c.affects.length - 6} more` : "";
|
|
43386
|
+
const says = look.length ? `${c.says} Look again at: ${look.join(", ")}${more}.` : c.says;
|
|
43387
|
+
const evidence2 = c.before || c.after ? { before: c.before, after: c.after } : null;
|
|
43388
|
+
items.push(item2(coreKind(c), c.severity, (CORE_SUBJECT[c.kind] ?? ((x) => x.subject))(c), { file: c.file, line: c.line }, says, evidence2));
|
|
43389
|
+
}
|
|
43390
|
+
return { paths: new Set([...oldCore, ...newCore].map((f) => f.path)), result: r };
|
|
43177
43391
|
}
|
|
43178
43392
|
var plural4 = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
43179
43393
|
function summaryLine(s) {
|