@skillstech/thunderlang 1.7.0 → 2.0.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 (73) hide show
  1. package/CHANGELOG.md +153 -1
  2. package/README.md +15 -3
  3. package/dist/core.cjs +303 -41
  4. package/dist/index.cjs +9906 -1387
  5. package/dist/learn.cjs +1420 -93
  6. package/package.json +17 -15
  7. package/src/cli-main.mjs +381 -149
  8. package/src/core/ThunderRuntime.cs +22 -1
  9. package/src/core/check.mjs +320 -6
  10. package/src/core/cli.mjs +60 -8
  11. package/src/core/csharp-run.mjs +2 -2
  12. package/src/core/diagnostics.mjs +9 -0
  13. package/src/core/engine-core.mjs +148 -19
  14. package/src/core/engine-values.mjs +3 -0
  15. package/src/core/engine.mjs +131 -7
  16. package/src/core/from-python.mjs +1 -1
  17. package/src/core/go-run.mjs +5 -3
  18. package/src/core/index.mjs +12 -3
  19. package/src/core/java/thunder/ThunderRuntime.java +1 -0
  20. package/src/core/java-run.mjs +2 -2
  21. package/src/core/kind.mjs +6 -0
  22. package/src/core/lexer.mjs +16 -2
  23. package/src/core/parser.mjs +215 -29
  24. package/src/core/project-root.mjs +18 -0
  25. package/src/core/project.mjs +34 -16
  26. package/src/core/react-run.mjs +2 -2
  27. package/src/core/runtime-go/thunder_runtime.go +310 -2
  28. package/src/core/runtime-python.mjs +365 -3
  29. package/src/core/runtime-typescript.mjs +150 -5
  30. package/src/core/rust/thunder_runtime.rs +1 -0
  31. package/src/core/rust-run.mjs +2 -2
  32. package/src/core/serving.mjs +12 -0
  33. package/src/core/store-format.mjs +110 -0
  34. package/src/core/target-csharp.mjs +14 -0
  35. package/src/core/target-go.mjs +24 -3
  36. package/src/core/target-java.mjs +14 -0
  37. package/src/core/target-python.mjs +46 -5
  38. package/src/core/target-rust.mjs +14 -0
  39. package/src/core/target-typescript.mjs +76 -6
  40. package/src/core/typescript-run.mjs +6 -4
  41. package/src/core-changes-fs.mjs +28 -0
  42. package/src/core-changes.d.mts +67 -0
  43. package/src/core-changes.mjs +603 -0
  44. package/src/core-rules.mjs +146 -0
  45. package/src/core-services.d.mts +4 -0
  46. package/src/core-services.mjs +49 -0
  47. package/src/emit.mjs +3 -3
  48. package/src/evidence-words.d.mts +6 -0
  49. package/src/evidence-words.mjs +47 -0
  50. package/src/evidence.mjs +36 -1
  51. package/src/examples.d.mts +21 -0
  52. package/src/examples.mjs +175 -0
  53. package/src/index.d.ts +19 -0
  54. package/src/index.mjs +8 -1
  55. package/src/learn-lessons.mjs +1 -1
  56. package/src/lsp.mjs +110 -0
  57. package/src/mcp.mjs +47 -12
  58. package/src/obligations.d.mts +5 -0
  59. package/src/obligations.mjs +30 -2
  60. package/src/program.d.mts +7 -0
  61. package/src/program.mjs +7 -0
  62. package/src/read-repo-fs.mjs +2 -1
  63. package/src/review.mjs +75 -6
  64. package/src/same.mjs +16 -6
  65. package/src/scan-queries.mjs +2 -1
  66. package/src/symbols.d.mts +23 -0
  67. package/src/symbols.mjs +351 -0
  68. package/src/system.mjs +1 -1
  69. package/src/template.d.mts +31 -0
  70. package/src/template.mjs +189 -0
  71. package/src/trace-cli.mjs +8 -3
  72. package/src/trace-fs.mjs +29 -3
  73. package/src/trace.mjs +23 -7
package/dist/core.cjs CHANGED
@@ -19410,7 +19410,7 @@ function notesSummary(ast) {
19410
19410
  byLens
19411
19411
  };
19412
19412
  }
19413
- var COMPILER_VERSION = "1.7.0";
19413
+ var COMPILER_VERSION = "2.0.0";
19414
19414
  var PROOF_SCHEMA_VERSION = "0.1.0";
19415
19415
  var SOURCE_PRODUCT = "skillstech-compiler";
19416
19416
  function buildContractGraph(ast, generatedAt) {
@@ -19884,7 +19884,6 @@ function semanticDiagnostics(ast) {
19884
19884
  }
19885
19885
  function buildProof(ast, { sourceFile, sourceHash, targetsRequested, targetsGenerated, diagnostics, generatedAt, origin = "authored" }) {
19886
19886
  const passedSemantic = !diagnostics.some((x) => x.level === "error");
19887
- const verifiedText = ast.verify.join(" ").toLowerCase();
19888
19887
  return {
19889
19888
  schemaVersion: PROOF_SCHEMA_VERSION,
19890
19889
  sourceProduct: SOURCE_PRODUCT,
@@ -19902,7 +19901,8 @@ function buildProof(ast, { sourceFile, sourceHash, targetsRequested, targetsGene
19902
19901
  guarantees: ast.guarantees.map((g) => ({
19903
19902
  id: g.id,
19904
19903
  text: g.statement,
19905
- status: g.verify.length > 0 || verifiedText ? "planned" : "needs_verification",
19904
+ // planned only when this guarantee names its own check; a verify block elsewhere in the mission doesn't count.
19905
+ status: g.verify.length > 0 ? "planned" : "needs_verification",
19906
19906
  evidence: g.verify,
19907
19907
  verifications: g.verifications || []
19908
19908
  })),
@@ -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(" "), col: run[0].col, line });
30655
+ }
30656
+ }
30635
30657
  return { k: "cmp", op: neg ? "!=" : "==", l, r: this.add(s, o), line };
30636
30658
  }
30637
30659
  return l;
@@ -30682,7 +30704,7 @@ var ExprParser = class {
30682
30704
  if (!run.length) s.fail(`I expected a field name after "'s".`, null, "TC108");
30683
30705
  const k = this.longest(run, (key) => this.names.fields.has(key)) || run.length;
30684
30706
  s.i -= run.length - k;
30685
- e = { k: "field", obj: e, name: keyOf(run.slice(0, k)), text: run.slice(0, k).map((w) => w.text).join(" "), line: s.line };
30707
+ e = { k: "field", obj: e, name: keyOf(run.slice(0, k)), text: run.slice(0, k).map((w) => w.text).join(" "), col: run[0].col, line: s.line };
30686
30708
  } else if (isWord(t, "at") && !isWord(s.peek(1), "least") && !isWord(s.peek(1), "most")) {
30687
30709
  s.next();
30688
30710
  const key = this.unary(s, { ...o, noAnd: true });
@@ -30784,11 +30806,52 @@ var ExprParser = class {
30784
30806
  if (!k) s.fail(`I don't know the kind of value "${run.map((x) => x.text).join(" ")}".`, 'Kinds: number, whole number, text, yes/no, money, date, list of \u2026, map of \u2026 to \u2026, optional \u2026, or a record you defined with "A \u2026 has:".', "TC306");
30785
30807
  s.i -= run.length - k;
30786
30808
  const key = keyOf(run.slice(0, k));
30787
- return { k: "record", name: this.names.records.has(key) ? key : key.replace(/s$/, "") };
30809
+ return { k: "record", name: this.names.records.has(key) ? key : key.replace(/s$/, ""), col: run[0].col, line: s.line };
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;
30788
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,23 +30963,32 @@ 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(" "), altCol: run[0].col, recordCol: run[i].col, 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(" "), altCol: run[0].col, recordCol: run[i].col, 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
- }
30912
- const node2 = { k: "new", record: name, fields, line };
30990
+ const fields = this.recordFields(s, line);
30991
+ const node2 = { k: "new", record: name, recordCol: run[off].col, fields, line };
30913
30992
  if (!fields.length && this.open) this.open.push(node2);
30914
30993
  return node2;
30915
30994
  }
@@ -30924,20 +31003,21 @@ var ExprParser = class {
30924
31003
  const key = keyOf(run.slice(0, k));
30925
31004
  const text2 = run.slice(0, k).map((x) => x.text).join(" ");
30926
31005
  if (this.names.known.get(key) === "func") {
30927
- if (isSym(s.peek(), "(")) return { k: "call", name: key, text: text2, args: this.parenArgs(s), line };
30928
- if (s.word("with")) return { k: "call", name: key, text: text2, args: this.withArgs(s), line };
30929
- const node2 = { k: "call", name: key, text: text2, args: [], line, bare: true };
31006
+ const col = run[0].col;
31007
+ if (isSym(s.peek(), "(")) return { k: "call", name: key, text: text2, col, args: this.parenArgs(s), line };
31008
+ if (s.word("with")) return { k: "call", name: key, text: text2, col, args: this.withArgs(s), line };
31009
+ const node2 = { k: "call", name: key, text: text2, col, args: [], line, bare: true };
30930
31010
  if (this.open) this.open.push(node2);
30931
31011
  return node2;
30932
31012
  }
30933
- return { k: "name", name: key, text: text2, line };
31013
+ return { k: "name", name: key, text: text2, col: run[0].col, line };
30934
31014
  }
30935
31015
  const fk = this.longest(run, (key) => this.names.fields.has(key));
30936
31016
  if (fk) {
30937
31017
  s.i -= run.length - fk;
30938
- return { k: "name", name: keyOf(run.slice(0, fk)), text: run.slice(0, fk).map((x) => x.text).join(" "), line, unknown: true };
31018
+ return { k: "name", name: keyOf(run.slice(0, fk)), text: run.slice(0, fk).map((x) => x.text).join(" "), col: run[0].col, line, unknown: true };
30939
31019
  }
30940
- return { k: "name", name: keyOf(run), text: run.map((x) => x.text).join(" "), line, unknown: true };
31020
+ return { k: "name", name: keyOf(run), text: run.map((x) => x.text).join(" "), col: run[0]?.col, line, unknown: true };
30941
31021
  }
30942
31022
  };
30943
31023
 
@@ -31340,6 +31420,28 @@ function readingOf(f, language = readableLanguage(f.path, f.source)) {
31340
31420
  return f.reading ?? readCode(f.source, { language, file: f.path });
31341
31421
  }
31342
31422
 
31423
+ // src/evidence-words.mjs
31424
+ var EVIDENCE_LEVELS = ["proven", "tested", "partial", "unverified", "violated"];
31425
+ var EVIDENCE_WORDS = {
31426
+ proven: { word: "Proven", means: "holds for every possible input: checked exhaustively, or proved by a solver" },
31427
+ tested: { word: "Tested", means: "passed on the cases that ran, and only on those" },
31428
+ partial: { word: "Partially checked", means: "some parts are checked and passed; others are not checked yet" },
31429
+ unverified: { word: "Unverified", means: "nothing checks it yet" },
31430
+ violated: { word: "Violated", means: "a check failed: there is a case where it does not hold" }
31431
+ };
31432
+ function evidenceWord(level) {
31433
+ return EVIDENCE_WORDS[level]?.word ?? null;
31434
+ }
31435
+ function combineEvidence(levels) {
31436
+ const ls = [...levels].filter((l) => EVIDENCE_LEVELS.includes(l));
31437
+ if (!ls.length) return "unverified";
31438
+ if (ls.includes("violated")) return "violated";
31439
+ if (ls.every((l) => l === "proven")) return "proven";
31440
+ if (ls.every((l) => l === "proven" || l === "tested")) return "tested";
31441
+ if (ls.every((l) => l === "unverified")) return "unverified";
31442
+ return "partial";
31443
+ }
31444
+
31343
31445
  // src/plain-contract.mjs
31344
31446
  var PLAIN_SCHEMA = "thunder-plain-v1";
31345
31447
  var COMPARISONS = [
@@ -32078,7 +32180,9 @@ function comparePlainRules(a, b) {
32078
32180
  }
32079
32181
  const bAsA = { ...b, inputs: b.inputs.map((i) => ({ ...i, id: toA.get(key(i)) })), rules: b.rules.map((r) => ({ ...r, conditions: r.conditions.map((c) => ({ ...c, input: toA.get(key(b.inputs.find((i) => i.id === c.input))) })) })) };
32080
32182
  let tried = 0;
32081
- for (const values of product(caseValues([a, bAsA]))) {
32183
+ const axes = caseValues([a, bAsA]);
32184
+ const total = axes.reduce((n, [, vs]) => n * Math.max(1, vs.length), 1);
32185
+ for (const values of product(axes)) {
32082
32186
  if (++tried > MAX_CASES) {
32083
32187
  tried--;
32084
32188
  break;
@@ -32086,7 +32190,7 @@ function comparePlainRules(a, b) {
32086
32190
  const x = explainPlain(a, values).outcome, y = explainPlain(bAsA, values).outcome;
32087
32191
  if (x !== y) return { same: false, tried, counterexample: { values: { ...values }, facts: a.inputs.map((i) => `${i.label} ${i.kind === "yesno" ? values[i.id] ? i.yes ?? "yes" : i.no ?? "no" : values[i.id]}`).join(", "), old: x, new: y } };
32088
32192
  }
32089
- return { same: true, tried };
32193
+ return { same: true, tried, total, ...total > tried ? { capped: true } : {} };
32090
32194
  }
32091
32195
  var SYNTAX = new Set("const let var val final auto def fn func function return await async new public private protected static self this my local export mut ref out in of for foreach if elif elsif while do then end each as range".split(" "));
32092
32196
  var OPS5 = { "&&": "and", "||": "or", "!": "not", "===": "==", "!==": "!=", "<>": "!=", "**": "^", and: "and", or: "or", not: "not", is: "==", None: "null", nil: "null", undefined: "null", NULL: "null", nullptr: "null", True: "true", False: "false" };
@@ -32109,7 +32213,7 @@ function compareItems(o, n) {
32109
32213
  if (o.kind === "decision") {
32110
32214
  const r = compareRules(o, n);
32111
32215
  if (!r) return { status: "cannot-check", reason: "One rule could not be drawn as a card, so its answers could not be compared.", ...where2 };
32112
- if (r.same) return { status: "same", reason: `Same answer on all ${r.tried} edge cases.`, ...where2 };
32216
+ if (r.same) return { status: "same", reason: r.capped ? `Same answer on the first ${r.tried} of ${r.total} edge cases (the rest were not tried).` : `Same answer on all ${r.tried} edge cases.`, ...where2 };
32113
32217
  if (r.counterexample) {
32114
32218
  const facts = r.counterexample.facts;
32115
32219
  return { status: "different", reason: `Different answer for ${facts}: ${r.counterexample.old} before, ${r.counterexample.new} after.`, counterexample: r.counterexample, ...where2 };
@@ -32142,13 +32246,18 @@ function sameMeaning(oldFiles, newFiles) {
32142
32246
  }
32143
32247
  for (const [key, n] of B.items) if (!used.has(key)) items.push({ name: n.name, status: "only-new", reason: "New: not in the old code.", new: { file: n.file, line: n.line, language: n.language } });
32144
32248
  const counts = { same: 0, different: 0, "only-old": 0, "only-new": 0, "cannot-check": 0 };
32145
- for (const it of items) counts[it.status]++;
32249
+ for (const it of items) {
32250
+ counts[it.status]++;
32251
+ it.evidence = it.status === "same" ? /edge cases/.test(it.reason) ? "tested" : "partial" : it.status === "cannot-check" ? "unverified" : "violated";
32252
+ }
32146
32253
  const verdict = counts.different || counts["only-old"] || counts["only-new"] ? "different" : counts["cannot-check"] ? "partly-checked" : "same";
32147
- return { schema: SAME_SCHEMA, verdict, counts, items, unreadable: [...A.unreadable, ...B.unreadable] };
32254
+ const evidence2 = combineEvidence(items.map((it) => it.evidence));
32255
+ return { schema: SAME_SCHEMA, verdict, evidence: evidence2, counts, items, unreadable: [...A.unreadable, ...B.unreadable] };
32148
32256
  }
32149
32257
  function renderSame(r) {
32150
32258
  const head = r.verdict === "same" ? "Same meaning." : r.verdict === "partly-checked" ? "No differences found, but some parts could not be checked." : "Different meaning.";
32151
- const lines = [`${head} ${r.counts.same} same, ${r.counts.different} different, ${r.counts["only-old"]} only in the old code, ${r.counts["only-new"]} only in the new code, ${r.counts["cannot-check"]} not checked.`];
32259
+ const how = r.evidence ? ` ${evidenceWord(r.evidence)}${r.evidence === "tested" ? " (answers compared on edge cases, not every input)" : r.evidence === "partial" ? " (some parts compared by running, others only by reading)" : ""}.` : "";
32260
+ const lines = [`${head}${how} ${r.counts.same} same, ${r.counts.different} different, ${r.counts["only-old"]} only in the old code, ${r.counts["only-new"]} only in the new code, ${r.counts["cannot-check"]} not checked.`];
32152
32261
  const order = ["different", "only-old", "only-new", "cannot-check", "same"];
32153
32262
  const label = { different: "different", "only-old": "only old", "only-new": "only new", "cannot-check": "not checked", same: "same" };
32154
32263
  for (const st of order) for (const it of r.items.filter((x) => x.status === st)) {
@@ -41201,22 +41310,26 @@ var end = (repo, at2, extra = {}) => ({ repo: repo.name, member: at2.member, lab
41201
41310
  var distinctive = (segs) => segs.some((s) => s !== "*");
41202
41311
  var lower = (segs) => segs.map((s) => s.toLowerCase());
41203
41312
  var pathMatch = (a, b) => segsMatch(lower(a), lower(b));
41204
- function buildTrace(repos) {
41313
+ function buildTrace(repos, { core = null } = {}) {
41205
41314
  const names = /* @__PURE__ */ new Set();
41206
41315
  const read = repos.map((r) => {
41207
41316
  if (!r.name || names.has(r.name)) throw new Error(`Each repository needs its own name; "${r.name}" is used twice.`);
41208
41317
  names.add(r.name);
41209
- const model = thunderModel(r.files, { name: r.name });
41210
- const facts = serviceFacts(model, r.files);
41318
+ const other = r.files.filter((f) => !/\.thunder$/i.test(f.path));
41319
+ const model = thunderModel(other, { name: r.name });
41320
+ const facts = serviceFacts(model, other);
41321
+ const cf = r.coreFacts ?? (core ? core(r.files) : { routes: [], requests: [], unknown: [], files: 0 });
41322
+ for (const k of ["routes", "requests", "unknown"]) facts[k] = [...facts[k], ...cf[k]];
41323
+ const coreFiles = cf.files;
41211
41324
  const real = (x) => !isTestFile(x.file);
41212
- const data = dataFacts(r.files, model);
41325
+ const data = dataFacts(other, model);
41213
41326
  const testItems = ["routes", "listeners", "requests", "publishes"].reduce((n, k) => n + facts[k].filter((x) => !real(x)).length, 0) + data.testItems;
41214
41327
  return {
41215
41328
  name: r.name,
41216
41329
  sha: r.sha ?? null,
41217
41330
  dirty: !!r.dirty,
41218
- files: model.files.length,
41219
- languages: [...new Set(model.files.map((f) => f.language))].sort(),
41331
+ files: model.files.length + coreFiles,
41332
+ languages: [.../* @__PURE__ */ new Set([...model.files.map((f) => f.language), ...coreFiles ? ["thunder"] : []])].sort(),
41220
41333
  routes: facts.routes.filter(real),
41221
41334
  listeners: facts.listeners.filter(real),
41222
41335
  requests: facts.requests.filter(real),
@@ -42408,12 +42521,108 @@ function thunderizeFiles(files, { name = "app" } = {}) {
42408
42521
  ` };
42409
42522
  }
42410
42523
 
42524
+ // src/core/kind.mjs
42525
+ var MISSION_KEYWORDS = /* @__PURE__ */ new Set([
42526
+ "mission",
42527
+ "note",
42528
+ "goal",
42529
+ "why",
42530
+ "requires",
42531
+ "requires_skill",
42532
+ "demonstrates",
42533
+ "input",
42534
+ "output",
42535
+ "guarantees",
42536
+ "guarantee",
42537
+ "never",
42538
+ "constraints",
42539
+ "invariant",
42540
+ "assumptions",
42541
+ "risks",
42542
+ "target",
42543
+ "style",
42544
+ "verify",
42545
+ "errors",
42546
+ "examples",
42547
+ "service",
42548
+ "api",
42549
+ "event",
42550
+ "database",
42551
+ "architecture",
42552
+ "selection",
42553
+ "use",
42554
+ "title",
42555
+ "for",
42556
+ "persona",
42557
+ "customer",
42558
+ "problem",
42559
+ "evidence",
42560
+ "outcome",
42561
+ "metric",
42562
+ "scope",
42563
+ "non_goal",
42564
+ "owner",
42565
+ "unknown",
42566
+ "question",
42567
+ "assumption",
42568
+ "experience",
42569
+ "pattern",
42570
+ "style_intent",
42571
+ "decision",
42572
+ "property",
42573
+ "scenario",
42574
+ "evaluation",
42575
+ "capability",
42576
+ "interface",
42577
+ "component",
42578
+ "artifact",
42579
+ "outcome_contract",
42580
+ "release",
42581
+ "result",
42582
+ "learning",
42583
+ "test",
42584
+ "data",
42585
+ "waiver",
42586
+ "command",
42587
+ "on",
42588
+ "lifecycle",
42589
+ "always",
42590
+ "eventually",
42591
+ "until",
42592
+ "conflict",
42593
+ "implement",
42594
+ "requires_skills",
42595
+ "approval",
42596
+ "inferred",
42597
+ "maps_to",
42598
+ "needs_review",
42599
+ "source",
42600
+ "confidence"
42601
+ ]);
42602
+ function firstCodeLine(source) {
42603
+ for (const raw of String(source).split(/\r?\n/)) {
42604
+ const line = raw.trim();
42605
+ if (line && !line.startsWith("#")) return { text: line, indented: raw.length > 0 && /^\s/.test(raw) };
42606
+ }
42607
+ return null;
42608
+ }
42609
+ function fileKind(source) {
42610
+ const first = firstCodeLine(source);
42611
+ if (!first) return { kind: "mission", reason: "the file has no lines yet" };
42612
+ const m = /^([a-z_]+)(?:\s+([A-Za-z_][\w.-]*))?\s*$/.exec(first.text);
42613
+ if (!first.indented && m && MISSION_KEYWORDS.has(m[1])) return { kind: "mission", reason: `its first line starts with the mission keyword "${m[1]}"` };
42614
+ return { kind: "program", reason: `its first line ("${first.text.length > 40 ? `${first.text.slice(0, 40)}\u2026` : first.text}") cannot start a mission` };
42615
+ }
42616
+ var isCoreProgram = (path, source) => /\.thunder$/i.test(path) && fileKind(source ?? "").kind === "program";
42617
+
42411
42618
  // src/review.mjs
42412
42619
  var REVIEW_SCHEMA = "thunder-review-v1";
42413
42620
  var REVIEW_MARKER = "<!-- thunder-review -->";
42414
42621
  var SEVERITY_ORDER = ["risk", "meaning", "form"];
42415
42622
  var KIND_ORDER = [
42416
42623
  "unreadable",
42624
+ "test-fails",
42625
+ "callers",
42417
42626
  "not-read",
42418
42627
  "infrastructure",
42419
42628
  "stop-removed",
@@ -42898,7 +43107,13 @@ function compareMember(o, n, items, { extracted = false } = {}) {
42898
43107
  if (o.m.rule && n.m.rule && !o.m.rule.partial && !n.m.rule.partial) {
42899
43108
  const r = comparePlainRules(o.m.rule, n.m.rule);
42900
43109
  if (r.same) {
42901
- formOnly(`same answer on all ${r.tried} edge cases, run on both versions.`);
43110
+ items.push(item2(
43111
+ renamedOrMoved.length ? moveKind : "form",
43112
+ "form",
43113
+ subject,
43114
+ whereOf2(n),
43115
+ `${renamedOrMoved.length ? `${cap5(renamedOrMoved.join(" and "))}. ` : ""}The code changed, but the answers are the same: Tested on ${r.capped ? `the first ${r.tried} of ${r.total}` : `all ${r.tried}`} edge cases, run on both versions (not every input).`
43116
+ ));
42902
43117
  return "form";
42903
43118
  }
42904
43119
  noteMove();
@@ -43024,7 +43239,7 @@ function mostlyIn(a, b) {
43024
43239
  }
43025
43240
  return hit / want.length >= 0.75;
43026
43241
  }
43027
- function thunderReview(oldFiles, newFiles) {
43242
+ function thunderReview(oldFiles, newFiles, { core = null, context = null } = {}) {
43028
43243
  detailsCache = /* @__PURE__ */ new WeakMap();
43029
43244
  const A = side(oldFiles || []), B = side(newFiles || []);
43030
43245
  const items = [];
@@ -43103,11 +43318,14 @@ function thunderReview(oldFiles, newFiles) {
43103
43318
  { before: null, after: n.text }
43104
43319
  ));
43105
43320
  compareThings(A, B, items);
43321
+ const coreRead = core ? coreReview(core, oldFiles || [], newFiles || [], context, items) : { paths: /* @__PURE__ */ new Set(), result: null };
43322
+ const corePaths = coreRead.paths;
43106
43323
  const paths = [.../* @__PURE__ */ new Set([...A.sources.keys(), ...B.sources.keys()])];
43107
43324
  const notRead = [];
43108
43325
  for (const p of paths) {
43109
43326
  const before = A.sources.get(p), after = B.sources.get(p);
43110
43327
  if (before === after) continue;
43328
+ if (corePaths.has(p)) continue;
43111
43329
  const lang = !isInfra(p) && readableLanguage(p);
43112
43330
  if (!lang) {
43113
43331
  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 +43391,39 @@ function thunderReview(oldFiles, newFiles) {
43173
43391
  const count2 = (s) => items.filter((x) => x.severity === s).length;
43174
43392
  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
43393
  const onlyNotRead = !items.length && summary2.files && notRead.length === summary2.files;
43176
- return { schema: REVIEW_SCHEMA, summary: summary2, says: onlyNotRead ? "Only files Thunder does not read changed." : summaryLine(summary2), items, notRead };
43394
+ const out = { schema: REVIEW_SCHEMA, summary: summary2, says: onlyNotRead ? "Only files Thunder does not read changed." : summaryLine(summary2), items, notRead };
43395
+ if (coreRead.result) Object.defineProperty(out, "core", { value: coreRead.result, enumerable: false });
43396
+ return out;
43397
+ }
43398
+ function coreKind(c) {
43399
+ if (c.change === "not-compiled") return "unreadable";
43400
+ if (c.kind === "test" && c.severity === "risk" && c.change !== "removed") return "test-fails";
43401
+ if (c.change === "added" || c.change === "removed" || c.change === "renamed") return c.kind === "never" && c.change === "removed" ? "stop-removed" : c.change;
43402
+ if (c.kind === "keep") return "rule-limit";
43403
+ if (c.kind === "function" && c.behaviour?.changed) return "rule-answer";
43404
+ if (c.kind === "never") return "stop-changed";
43405
+ if (c.kind === "record" || c.kind === "store") return "thing";
43406
+ if (c.kind === "main") return "outside";
43407
+ return "steps";
43408
+ }
43409
+ var CORE_SUBJECT = { keep: (c) => `${c.subject} (kept value)`, main: (c) => c.subject };
43410
+ function coreReview(coreChanges, oldFiles, newFiles, context, items) {
43411
+ const core = (fs) => fs.filter((f) => f && isCoreProgram(f.path, f.source));
43412
+ const merge = (changed, extra) => {
43413
+ const have = new Set(changed.map((f) => f.path));
43414
+ return [...changed, ...core(extra ?? []).filter((f) => !have.has(f.path))];
43415
+ };
43416
+ const oldCore = core(oldFiles), newCore = core(newFiles);
43417
+ if (!oldCore.length && !newCore.length) return { paths: /* @__PURE__ */ new Set(), result: null };
43418
+ const r = coreChanges(merge(oldCore, context?.old), merge(newCore, context?.new));
43419
+ for (const c of r.changes) {
43420
+ const look = (c.affects ?? []).slice(0, 6).map((x) => `${x.subject} (\`${x.file}:${x.line}\`${x.test ? `, ${x.test === "fails" ? "**fails now**" : "passes"}` : ""})`);
43421
+ const more = (c.affects?.length ?? 0) > 6 ? `, and ${c.affects.length - 6} more` : "";
43422
+ const says = look.length ? `${c.says} Look again at: ${look.join(", ")}${more}.` : c.says;
43423
+ const evidence2 = c.before || c.after ? { before: c.before, after: c.after } : null;
43424
+ items.push(item2(coreKind(c), c.severity, (CORE_SUBJECT[c.kind] ?? ((x) => x.subject))(c), { file: c.file, line: c.line }, says, evidence2));
43425
+ }
43426
+ return { paths: new Set([...oldCore, ...newCore].map((f) => f.path)), result: r };
43177
43427
  }
43178
43428
  var plural4 = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
43179
43429
  function summaryLine(s) {
@@ -43191,7 +43441,7 @@ function evidenceBlock(ev) {
43191
43441
  }
43192
43442
  function renderReview(r, { title = "Thunder review", maxChars = 6e4, footer = "" } = {}) {
43193
43443
  const out = [REVIEW_MARKER, `### ${title}`, "", `**${r.says}**`, ""];
43194
- out.push('Read from the code by the Thunder compiler, with no AI. "Only the form changed" is said only when it is shown: the code is identical apart from spacing, comments, or names it declares itself, or a rule gives the same answer on every edge case.', "");
43444
+ out.push('Read from the code by the Thunder compiler, with no AI. "Only the form changed" is said only when it is shown: the code is identical apart from spacing, comments, or names it declares itself. A rule whose code changed but whose answers match on every edge case tried is listed here too, marked Tested: other inputs were not tried.', "");
43195
43445
  const alsoIn = (x) => x.also?.length ? [` <details><summary>Also in ${x.also.length} more</summary>`, "", ...x.also.slice(0, 50).map((a) => ` - **${a.subject}** \xB7 \`${a.where.file}:${a.where.line}\``), ...x.also.length > 50 ? [` - and ${x.also.length - 50} more`] : [], "", " </details>"] : [];
43196
43446
  const line = (x) => [`- **${x.subject}** \xB7 \`${x.where.file}:${x.where.line}\`: ${x.says}`, ...evidenceBlock(x.evidence).map((l) => l ? ` ${l}` : ""), ...alsoIn(x)];
43197
43447
  const section = (sev, head) => {
@@ -43207,7 +43457,7 @@ function renderReview(r, { title = "Thunder review", maxChars = 6e4, footer = ""
43207
43457
  };
43208
43458
  section("risk", "Needs a careful look");
43209
43459
  section("meaning", "Changes in meaning");
43210
- section("form", "Only the form changed");
43460
+ section("form", "Only the form changed, or the same answers where tested");
43211
43461
  if (r.notRead.length) out.push(`Also changed, not read by Thunder: ${r.notRead.slice(0, 20).map((f) => `\`${f.path}\``).join(", ")}${r.notRead.length > 20 ? `, and ${r.notRead.length - 20} more` : ""}.`, "");
43212
43462
  if (footer) out.push(footer, "");
43213
43463
  let text2 = out.join("\n");
@@ -45992,11 +46242,14 @@ function resolveObligations(ast) {
45992
46242
  const evidence2 = names.map((name) => byTarget.get(name) || (name.startsWith("test ") ? byTarget.get(name.slice(5).trim()) : null) || { name, pass: null, cases: 0 });
45993
46243
  const unresolved = evidence2.filter((e) => e.pass === null).map((e) => e.name);
45994
46244
  const status = !names.length ? "unverified" : evidence2.some((e) => e.pass === false) ? "failed" : unresolved.length ? "declared" : "verified";
46245
+ const evidenceLevel = combineEvidence(evidence2.map((e) => e.pass === true ? "tested" : e.pass === false ? "violated" : "unverified"));
45995
46246
  return {
45996
46247
  kind,
45997
46248
  id: claim.id,
45998
46249
  text: claim.statement,
45999
46250
  status,
46251
+ evidenceLevel,
46252
+ evidenceWord: evidenceWord(evidenceLevel),
46000
46253
  verify,
46001
46254
  kinds: [...new Set((claim.verifications || []).map((v) => v.kind).filter((k) => k && k !== "unclassified"))],
46002
46255
  provenBy: status === "verified" || status === "failed" ? evidence2.filter((e) => e.pass !== null).map((e) => e.name).join(", ") : null,
@@ -46009,7 +46262,16 @@ function resolveObligations(ast) {
46009
46262
  ...(ast.neverRules || []).map((n) => build("prohibition", n))
46010
46263
  ];
46011
46264
  const count2 = (s) => obligations.filter((o) => o.status === s).length;
46012
- return { obligations, tests, verified: count2("verified"), declared: count2("declared"), unverified: count2("unverified"), failed: count2("failed") };
46265
+ const byLevel = (l) => obligations.filter((o) => o.evidenceLevel === l).length;
46266
+ return {
46267
+ obligations,
46268
+ tests,
46269
+ verified: count2("verified"),
46270
+ declared: count2("declared"),
46271
+ unverified: count2("unverified"),
46272
+ failed: count2("failed"),
46273
+ evidence: { tested: byLevel("tested"), partial: byLevel("partial"), unverified: byLevel("unverified"), violated: byLevel("violated") }
46274
+ };
46013
46275
  }
46014
46276
 
46015
46277
  // src/review-atlas.mjs