@skillstech/thunderlang 1.6.1 → 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 +121 -0
- package/README.md +10 -3
- package/dist/core.cjs +264 -47
- package/dist/index.cjs +9118 -1077
- package/dist/learn.cjs +1419 -90
- package/package.json +1 -1
- package/src/ai.mjs +2 -1
- package/src/atlas.mjs +2 -1
- package/src/behaviour.mjs +246 -0
- package/src/cli-main.mjs +3015 -0
- package/src/cli.mjs +9 -2799
- package/src/conflict.mjs +0 -0
- package/src/core/ThunderDotnet.cs +195 -0
- package/src/core/check.mjs +316 -10
- package/src/core/cli.mjs +67 -10
- package/src/core/csharp-run.mjs +29 -8
- package/src/core/diagnostics.mjs +12 -1
- package/src/core/engine-core.mjs +161 -20
- package/src/core/engine-values.mjs +1 -0
- package/src/core/engine.mjs +131 -7
- package/src/core/go-run.mjs +3 -2
- package/src/core/index.mjs +6 -2
- package/src/core/java-run.mjs +3 -3
- package/src/core/kind.mjs +45 -0
- package/src/core/lexer.mjs +16 -2
- package/src/core/parser.mjs +254 -22
- package/src/core/project-root.mjs +18 -0
- package/src/core/project.mjs +18 -18
- package/src/core/react-run.mjs +3 -3
- package/src/core/runtime-go/thunder_runtime.go +269 -1
- package/src/core/runtime-npm.mjs +79 -0
- package/src/core/runtime-python.mjs +365 -3
- package/src/core/runtime-react.mjs +2 -1
- package/src/core/runtime-typescript.mjs +155 -6
- package/src/core/rust-run.mjs +3 -2
- package/src/core/serving.mjs +12 -0
- package/src/core/store-format.mjs +110 -0
- package/src/core/target-csharp.mjs +5 -1
- package/src/core/target-go.mjs +11 -4
- package/src/core/target-python.mjs +39 -6
- package/src/core/target-rust.mjs +1 -1
- package/src/core/target-typescript.mjs +95 -7
- package/src/core/typescript-run.mjs +14 -7
- 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/decision.mjs +2 -1
- package/src/distributed.mjs +2 -1
- package/src/emit.mjs +2 -2
- package/src/evidence.mjs +28 -0
- package/src/examples.d.mts +21 -0
- package/src/examples.mjs +175 -0
- package/src/focus.mjs +2 -1
- package/src/index.d.ts +4 -0
- package/src/index.mjs +4 -0
- package/src/intent-atlas.mjs +4 -3
- package/src/mcp.mjs +52 -6
- package/src/passport-fs.mjs +2 -1
- package/src/passport.mjs +2 -1
- package/src/privacy.mjs +2 -1
- package/src/program.d.mts +4 -0
- package/src/program.mjs +4 -0
- package/src/read-repo-fs.mjs +2 -1
- package/src/read-repo.mjs +3 -2
- package/src/report.mjs +3 -2
- package/src/review.mjs +71 -4
- package/src/select.mjs +2 -1
- package/src/semantic-diff.mjs +7 -6
- package/src/system.mjs +3 -2
- package/src/text-order.mjs +6 -0
- package/src/thunderize.mjs +2 -1
- package/src/trace-cli.mjs +8 -3
- package/src/trace-data.mjs +3 -2
- package/src/trace-fs.mjs +29 -3
- package/src/trace.mjs +27 -10
- package/src/write-across-cli.mjs +22 -4
- package/src/write-across.mjs +2 -1
- package/syntaxes/thunder.tmLanguage.json +196 -0
package/dist/core.cjs
CHANGED
|
@@ -18876,6 +18876,9 @@ var BLOCKABLE_PHASES = [
|
|
|
18876
18876
|
"release"
|
|
18877
18877
|
];
|
|
18878
18878
|
|
|
18879
|
+
// src/text-order.mjs
|
|
18880
|
+
var byText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
18881
|
+
|
|
18879
18882
|
// src/conflict.mjs
|
|
18880
18883
|
var norm = (s) => String(s ?? "").trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
18881
18884
|
var NEG = /\b(no|not|never|forbidden|prohibited|unavailable|disallowed|without)\b/;
|
|
@@ -18917,7 +18920,7 @@ function detectConflicts(ast) {
|
|
|
18917
18920
|
}
|
|
18918
18921
|
}
|
|
18919
18922
|
}
|
|
18920
|
-
return out.sort((a, b) => `${a.type}\0${a.name}
|
|
18923
|
+
return out.sort((a, b) => byText(`${a.type}\0${a.name}`, `${b.type}\0${b.name}`));
|
|
18921
18924
|
}
|
|
18922
18925
|
|
|
18923
18926
|
// src/distributed.mjs
|
|
@@ -18947,7 +18950,7 @@ function analyzeDistributed(ast) {
|
|
|
18947
18950
|
findings2.push({ code: "IL-DIST-005", target: h.trigger, message: `Duplicate handler references undeclared event "${m[1]}".` });
|
|
18948
18951
|
}
|
|
18949
18952
|
}
|
|
18950
|
-
return findings2.sort((a, b) => `${a.code} ${a.target}
|
|
18953
|
+
return findings2.sort((a, b) => byText(`${a.code} ${a.target}`, `${b.code} ${b.target}`));
|
|
18951
18954
|
}
|
|
18952
18955
|
|
|
18953
18956
|
// src/decision.mjs
|
|
@@ -18971,7 +18974,7 @@ function analyzeDecision(dec) {
|
|
|
18971
18974
|
}
|
|
18972
18975
|
}
|
|
18973
18976
|
}
|
|
18974
|
-
return findings2.sort((a, b) => `${a.code} ${a.message}
|
|
18977
|
+
return findings2.sort((a, b) => byText(`${a.code} ${a.message}`, `${b.code} ${b.message}`));
|
|
18975
18978
|
}
|
|
18976
18979
|
|
|
18977
18980
|
// src/privacy.mjs
|
|
@@ -19033,7 +19036,7 @@ function analyzePrivacy(ast) {
|
|
|
19033
19036
|
});
|
|
19034
19037
|
}
|
|
19035
19038
|
}
|
|
19036
|
-
out.sort((a, b) => (a.code + a.path
|
|
19039
|
+
out.sort((a, b) => byText(a.code + a.path, b.code + b.path));
|
|
19037
19040
|
return out;
|
|
19038
19041
|
}
|
|
19039
19042
|
|
|
@@ -19407,7 +19410,7 @@ function notesSummary(ast) {
|
|
|
19407
19410
|
byLens
|
|
19408
19411
|
};
|
|
19409
19412
|
}
|
|
19410
|
-
var COMPILER_VERSION = "1.
|
|
19413
|
+
var COMPILER_VERSION = "1.8.0";
|
|
19411
19414
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
19412
19415
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
19413
19416
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -19480,7 +19483,7 @@ function semanticDiagnostics(ast) {
|
|
|
19480
19483
|
err(
|
|
19481
19484
|
"missing-subject",
|
|
19482
19485
|
"No mission, service, event, api, database, or experience declared.",
|
|
19483
|
-
"Every file must declare one subject so the compiler knows what it is reasoning about.",
|
|
19486
|
+
"Every mission file must declare one subject so the compiler knows what it is reasoning about. If this file is a Thunder program (code that runs), add --core, or put it in a project (thunder new).",
|
|
19484
19487
|
[{ label: "Add a mission declaration", insert: "mission MyMission", block: "top" }]
|
|
19485
19488
|
);
|
|
19486
19489
|
}
|
|
@@ -30324,12 +30327,25 @@ function formatDiagnostic(d, file) {
|
|
|
30324
30327
|
}
|
|
30325
30328
|
|
|
30326
30329
|
// src/core/lexer.mjs
|
|
30327
|
-
var SYMS = ["==", "!=", "<>", "<=", ">=", "+", "-", "*", "/", "(", ")", "[", "]", ",", ":", ".", "=", "<", ">"];
|
|
30330
|
+
var SYMS = ["==", "!=", "<>", "<=", ">=", "+", "-", "*", "/", "(", ")", "[", "]", ",", ":", ".", "=", "<", ">", "?"];
|
|
30328
30331
|
var WORD_START = /[\p{L}_]/u;
|
|
30329
30332
|
var WORD_CHAR = /[\p{L}\p{N}_]/u;
|
|
30330
30333
|
function tokenizeLine(text2, line, colOffset = 0) {
|
|
30331
30334
|
const toks2 = [];
|
|
30332
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
|
+
}
|
|
30333
30349
|
const at2 = (k = 0) => text2[i + k];
|
|
30334
30350
|
while (i < text2.length) {
|
|
30335
30351
|
const c = at2();
|
|
@@ -30629,6 +30645,15 @@ var ExprParser = class {
|
|
|
30629
30645
|
}
|
|
30630
30646
|
if (s.word("in")) return wrap({ k: "contains", l: this.add(s, o), r: l, line });
|
|
30631
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
|
+
}
|
|
30632
30657
|
return { k: "cmp", op: neg ? "!=" : "==", l, r: this.add(s, o), line };
|
|
30633
30658
|
}
|
|
30634
30659
|
return l;
|
|
@@ -30783,9 +30808,50 @@ var ExprParser = class {
|
|
|
30783
30808
|
const key = keyOf(run.slice(0, k));
|
|
30784
30809
|
return { k: "record", name: this.names.records.has(key) ? key : key.replace(/s$/, "") };
|
|
30785
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
|
+
}
|
|
30786
30825
|
primary(s, o) {
|
|
30787
30826
|
const t = s.peek();
|
|
30788
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
|
+
}
|
|
30789
30855
|
if (!t) s.fail("A value is missing at the end of this line.", null, "TC108");
|
|
30790
30856
|
if (t.t === "num") {
|
|
30791
30857
|
s.next();
|
|
@@ -30805,6 +30871,13 @@ var ExprParser = class {
|
|
|
30805
30871
|
s.next();
|
|
30806
30872
|
return { k: "str", parts: t.parts.map((p) => typeof p === "string" ? p : { e: this.parse(p.tokens, line), source: p.source }), line };
|
|
30807
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
|
+
}
|
|
30808
30881
|
if (isSym(t, "(")) {
|
|
30809
30882
|
s.next();
|
|
30810
30883
|
const e = this.expr(s, {});
|
|
@@ -30890,22 +30963,31 @@ var ExprParser = class {
|
|
|
30890
30963
|
}
|
|
30891
30964
|
if (RESERVED2.has(w)) s.fail(`"${t.text}" is a Thunder word and can't start a value here.`, null, "TC105");
|
|
30892
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
|
+
}
|
|
30893
30984
|
let off = run[0]?.lower === "new" && run.length > 1 ? 1 : 0;
|
|
30894
30985
|
const recK = this.longest(run.slice(off), (key) => this.names.records.has(key));
|
|
30895
30986
|
const wantsRecord = o.article || off || isWord(s.peek(), "with") || !this.longest(run, (key) => this.names.known.has(key));
|
|
30896
30987
|
if (recK && wantsRecord && recK + off === run.length) {
|
|
30897
30988
|
s.i -= run.length - off - recK;
|
|
30898
30989
|
const name = keyOf(run.slice(off, off + recK));
|
|
30899
|
-
const fields =
|
|
30900
|
-
if (s.word("with")) {
|
|
30901
|
-
do {
|
|
30902
|
-
const fr = this.wordRun(s);
|
|
30903
|
-
if (!fr.length) s.fail(`I expected a field name after "with" (for example: with name "Ann").`, null, "TC108");
|
|
30904
|
-
const fk2 = this.longest(fr, (key) => this.names.fields.has(key)) || fr.length;
|
|
30905
|
-
s.i -= fr.length - fk2;
|
|
30906
|
-
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 });
|
|
30907
|
-
} while ((isSym(s.peek(), ",") || isWord(s.peek(), "and")) && this.fieldAhead(s, 1) && s.next());
|
|
30908
|
-
}
|
|
30990
|
+
const fields = this.recordFields(s, line);
|
|
30909
30991
|
const node2 = { k: "new", record: name, fields, line };
|
|
30910
30992
|
if (!fields.length && this.open) this.open.push(node2);
|
|
30911
30993
|
return node2;
|
|
@@ -31295,7 +31377,7 @@ function summarize(items, files) {
|
|
|
31295
31377
|
inputs.get(p.name).push(it.id);
|
|
31296
31378
|
}
|
|
31297
31379
|
}
|
|
31298
|
-
const byUse = (m) => [...m].map(([name, ids]) => ({ name, decisions: ids })).sort((a, b) => b.decisions.length - a.decisions.length || a.name
|
|
31380
|
+
const byUse = (m) => [...m].map(([name, ids]) => ({ name, decisions: ids })).sort((a, b) => b.decisions.length - a.decisions.length || byText(a.name, b.name));
|
|
31299
31381
|
return { files, items, counts, languages, folders, answers: byUse(answers), inputs: byUse(inputs) };
|
|
31300
31382
|
}
|
|
31301
31383
|
function searchRepo(index, { query = "", kinds = [], status = [], languages = [], path = "", answer = "", input = "" } = {}) {
|
|
@@ -31319,7 +31401,7 @@ function groupByFile(items) {
|
|
|
31319
31401
|
if (!groups3.has(it.file)) groups3.set(it.file, []);
|
|
31320
31402
|
groups3.get(it.file).push(it);
|
|
31321
31403
|
}
|
|
31322
|
-
return [...groups3].sort(([a], [b]) => a
|
|
31404
|
+
return [...groups3].sort(([a], [b]) => byText(a, b)).map(([file, list3]) => ({ file, language: list3[0].language, items: list3 }));
|
|
31323
31405
|
}
|
|
31324
31406
|
function readFiles(files) {
|
|
31325
31407
|
return files.map((f) => {
|
|
@@ -35015,7 +35097,7 @@ function callsSummary(model) {
|
|
|
35015
35097
|
else p.calls++;
|
|
35016
35098
|
if (p.examples.length < 3) p.examples.push({ from: a.id, to: b.id, says: l.kind === "sends-to" ? `${a.label} sends ${l.method ? `${l.method} ${l.path}` : l.event ? `the event ${l.event}` : `a task`} to ${b.label}` : `${a.label} calls ${b.label}` });
|
|
35017
35099
|
}
|
|
35018
|
-
return [...pairs2.values()].sort((x, y) => y.calls + y.sends - (x.calls + x.sends) || x.from
|
|
35100
|
+
return [...pairs2.values()].sort((x, y) => y.calls + y.sends - (x.calls + x.sends) || byText(x.from, y.from) || byText(x.to, y.to));
|
|
35019
35101
|
}
|
|
35020
35102
|
|
|
35021
35103
|
// src/flow/ts-parse.mjs
|
|
@@ -41110,7 +41192,7 @@ function settingsIn(files) {
|
|
|
41110
41192
|
}
|
|
41111
41193
|
}
|
|
41112
41194
|
}
|
|
41113
|
-
return out.sort((a, b) => a.file
|
|
41195
|
+
return out.sort((a, b) => byText(a.file, b.file) || a.line - b.line || byText(a.key, b.key));
|
|
41114
41196
|
}
|
|
41115
41197
|
var NAME = '((?:[`"\\[]?[A-Za-z_][\\w$]*[`"\\]]?\\.){0,2}[`"\\[]?[A-Za-z_][\\w$]*[`"\\]]?)';
|
|
41116
41198
|
var NOT_TABLES = /* @__PURE__ */ new Set(["select", "set", "where", "values", "dual", "lateral", "unnest", "only", "table", "if", "exists", "not", "the", "a", "an", "my", "your", "this", "that", "each", "all", "json_table", "information_schema", "pg_catalog", "sys"]);
|
|
@@ -41180,7 +41262,7 @@ function tablesIn(files) {
|
|
|
41180
41262
|
if (seen.has(k)) return false;
|
|
41181
41263
|
seen.add(k);
|
|
41182
41264
|
return true;
|
|
41183
|
-
}).sort((a, b) => a.file
|
|
41265
|
+
}).sort((a, b) => byText(a.file, b.file) || a.line - b.line || byText(a.table, b.table));
|
|
41184
41266
|
}
|
|
41185
41267
|
var DEFINES = /* @__PURE__ */ new Set(["creates", "alters", "drops"]);
|
|
41186
41268
|
|
|
@@ -41198,22 +41280,26 @@ var end = (repo, at2, extra = {}) => ({ repo: repo.name, member: at2.member, lab
|
|
|
41198
41280
|
var distinctive = (segs) => segs.some((s) => s !== "*");
|
|
41199
41281
|
var lower = (segs) => segs.map((s) => s.toLowerCase());
|
|
41200
41282
|
var pathMatch = (a, b) => segsMatch(lower(a), lower(b));
|
|
41201
|
-
function buildTrace(repos) {
|
|
41283
|
+
function buildTrace(repos, { core = null } = {}) {
|
|
41202
41284
|
const names = /* @__PURE__ */ new Set();
|
|
41203
41285
|
const read = repos.map((r) => {
|
|
41204
41286
|
if (!r.name || names.has(r.name)) throw new Error(`Each repository needs its own name; "${r.name}" is used twice.`);
|
|
41205
41287
|
names.add(r.name);
|
|
41206
|
-
const
|
|
41207
|
-
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;
|
|
41208
41294
|
const real = (x) => !isTestFile(x.file);
|
|
41209
|
-
const data = dataFacts(
|
|
41295
|
+
const data = dataFacts(other, model);
|
|
41210
41296
|
const testItems = ["routes", "listeners", "requests", "publishes"].reduce((n, k) => n + facts[k].filter((x) => !real(x)).length, 0) + data.testItems;
|
|
41211
41297
|
return {
|
|
41212
41298
|
name: r.name,
|
|
41213
41299
|
sha: r.sha ?? null,
|
|
41214
41300
|
dirty: !!r.dirty,
|
|
41215
|
-
files: model.files.length,
|
|
41216
|
-
languages: [
|
|
41301
|
+
files: model.files.length + coreFiles,
|
|
41302
|
+
languages: [.../* @__PURE__ */ new Set([...model.files.map((f) => f.language), ...coreFiles ? ["thunder"] : []])].sort(),
|
|
41217
41303
|
routes: facts.routes.filter(real),
|
|
41218
41304
|
listeners: facts.listeners.filter(real),
|
|
41219
41305
|
requests: facts.requests.filter(real),
|
|
@@ -41325,8 +41411,8 @@ function linkRepos(read) {
|
|
|
41325
41411
|
return true;
|
|
41326
41412
|
});
|
|
41327
41413
|
};
|
|
41328
|
-
links.splice(0, links.length, ...once(links).sort((a, b) => sortKey(a)
|
|
41329
|
-
notLinked.splice(0, notLinked.length, ...once(notLinked).sort((a, b) => sortKey(a)
|
|
41414
|
+
links.splice(0, links.length, ...once(links).sort((a, b) => byText(sortKey(a), sortKey(b))));
|
|
41415
|
+
notLinked.splice(0, notLinked.length, ...once(notLinked).sort((a, b) => byText(sortKey(a), sortKey(b))));
|
|
41330
41416
|
const repos = read.map(({ unknown, ...r }) => ({ ...r, unknown: unknown ?? [], packages: pk(r), settings: r.settings ?? [], tables: tb(r) }));
|
|
41331
41417
|
const body2 = { schema: TRACE_SCHEMA, rulesVersion: TRACE_RULES_VERSION, repos, links, notLinked, shared };
|
|
41332
41418
|
return { ...body2, fingerprint: sha256(JSON.stringify(body2)) };
|
|
@@ -41474,7 +41560,7 @@ function writeRuleAcross(files, { decision, rule, when }) {
|
|
|
41474
41560
|
}
|
|
41475
41561
|
result.files[k] = source;
|
|
41476
41562
|
}
|
|
41477
|
-
result.plan.sort((a, b) => where(a)
|
|
41563
|
+
result.plan.sort((a, b) => byText(where(a), where(b)) || a.line - b.line);
|
|
41478
41564
|
if (problems.length) return { ...base2, files: {}, plan: [], rule: result.rule, notIncluded: result.notIncluded, tests: result.tests, problems: ["Nothing was changed: every implementation must be written exactly, or none is.", ...problems] };
|
|
41479
41565
|
return { ...result, ok: true };
|
|
41480
41566
|
}
|
|
@@ -42374,7 +42460,7 @@ function thunderizeFiles(files, { name = "app" } = {}) {
|
|
|
42374
42460
|
skipped.push({ path: f.path, reason: `could not be read: ${e.message}` });
|
|
42375
42461
|
}
|
|
42376
42462
|
}
|
|
42377
|
-
out.sort((a, b) => a.path
|
|
42463
|
+
out.sort((a, b) => byText(a.path, b.path));
|
|
42378
42464
|
const total = { files: out.length, actions: 0, rules: 0, functions: 0, notReadYet: 0 };
|
|
42379
42465
|
for (const f of out) for (const k of ["actions", "rules", "functions", "notReadYet"]) total[k] += f.counts[k];
|
|
42380
42466
|
const langs = [...new Set(out.map((f) => LANGUAGE_NAMES[f.language] || f.language))].sort();
|
|
@@ -42405,12 +42491,108 @@ function thunderizeFiles(files, { name = "app" } = {}) {
|
|
|
42405
42491
|
` };
|
|
42406
42492
|
}
|
|
42407
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
|
+
|
|
42408
42588
|
// src/review.mjs
|
|
42409
42589
|
var REVIEW_SCHEMA = "thunder-review-v1";
|
|
42410
42590
|
var REVIEW_MARKER = "<!-- thunder-review -->";
|
|
42411
42591
|
var SEVERITY_ORDER = ["risk", "meaning", "form"];
|
|
42412
42592
|
var KIND_ORDER = [
|
|
42413
42593
|
"unreadable",
|
|
42594
|
+
"test-fails",
|
|
42595
|
+
"callers",
|
|
42414
42596
|
"not-read",
|
|
42415
42597
|
"infrastructure",
|
|
42416
42598
|
"stop-removed",
|
|
@@ -43021,7 +43203,7 @@ function mostlyIn(a, b) {
|
|
|
43021
43203
|
}
|
|
43022
43204
|
return hit / want.length >= 0.75;
|
|
43023
43205
|
}
|
|
43024
|
-
function thunderReview(oldFiles, newFiles) {
|
|
43206
|
+
function thunderReview(oldFiles, newFiles, { core = null, context = null } = {}) {
|
|
43025
43207
|
detailsCache = /* @__PURE__ */ new WeakMap();
|
|
43026
43208
|
const A = side(oldFiles || []), B = side(newFiles || []);
|
|
43027
43209
|
const items = [];
|
|
@@ -43100,11 +43282,14 @@ function thunderReview(oldFiles, newFiles) {
|
|
|
43100
43282
|
{ before: null, after: n.text }
|
|
43101
43283
|
));
|
|
43102
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;
|
|
43103
43287
|
const paths = [.../* @__PURE__ */ new Set([...A.sources.keys(), ...B.sources.keys()])];
|
|
43104
43288
|
const notRead = [];
|
|
43105
43289
|
for (const p of paths) {
|
|
43106
43290
|
const before = A.sources.get(p), after = B.sources.get(p);
|
|
43107
43291
|
if (before === after) continue;
|
|
43292
|
+
if (corePaths.has(p)) continue;
|
|
43108
43293
|
const lang = !isInfra(p) && readableLanguage(p);
|
|
43109
43294
|
if (!lang) {
|
|
43110
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));
|
|
@@ -43166,11 +43351,43 @@ function thunderReview(oldFiles, newFiles) {
|
|
|
43166
43351
|
for (const x of rest2) items.splice(items.indexOf(x), 1);
|
|
43167
43352
|
}
|
|
43168
43353
|
for (const x of items) if (x.also) x.subject = `${x.subject} and ${x.also.length} more`;
|
|
43169
|
-
items.sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity) || KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind) || String(a.where.file)
|
|
43354
|
+
items.sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity) || KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind) || byText(String(a.where.file), String(b.where.file)) || (a.where.line ?? 0) - (b.where.line ?? 0));
|
|
43170
43355
|
const count2 = (s) => items.filter((x) => x.severity === s).length;
|
|
43171
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 };
|
|
43172
43357
|
const onlyNotRead = !items.length && summary2.files && notRead.length === summary2.files;
|
|
43173
|
-
|
|
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 };
|
|
43174
43391
|
}
|
|
43175
43392
|
var plural4 = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
43176
43393
|
function summaryLine(s) {
|
|
@@ -44509,9 +44726,9 @@ function diffGraphs(before, after) {
|
|
|
44509
44726
|
const bn = bNodes.get(id2);
|
|
44510
44727
|
if (bn && contentKey(bn) !== contentKey(an)) changedNodes.push({ id: id2, type: an.type, before: bn, after: an });
|
|
44511
44728
|
}
|
|
44512
|
-
addedNodes.sort((a, b) => a.id
|
|
44513
|
-
removedNodes.sort((a, b) => a.id
|
|
44514
|
-
changedNodes.sort((a, b) => a.id
|
|
44729
|
+
addedNodes.sort((a, b) => byText(a.id, b.id));
|
|
44730
|
+
removedNodes.sort((a, b) => byText(a.id, b.id));
|
|
44731
|
+
changedNodes.sort((a, b) => byText(a.id, b.id));
|
|
44515
44732
|
const bRel = new Set((before.relationships || []).map(relKey));
|
|
44516
44733
|
const aRel = new Set((after.relationships || []).map(relKey));
|
|
44517
44734
|
const addedRelationships = (after.relationships || []).filter((r) => !bRel.has(relKey(r)));
|
|
@@ -44596,11 +44813,11 @@ function mergeGraphs(base2, ours, theirs) {
|
|
|
44596
44813
|
const present = inO !== inB ? inO : inT;
|
|
44597
44814
|
if (present) mergedRels.push(r);
|
|
44598
44815
|
}
|
|
44599
|
-
mergedRels.sort((a, b2) => relKey(a)
|
|
44816
|
+
mergedRels.sort((a, b2) => byText(relKey(a), relKey(b2)));
|
|
44600
44817
|
return {
|
|
44601
44818
|
schema: "intent-merge-v1",
|
|
44602
|
-
merged: { nodes: [...merged.values()].sort((a, b2) => a.id
|
|
44603
|
-
conflicts: conflicts.sort((a, b2) => a.id
|
|
44819
|
+
merged: { nodes: [...merged.values()].sort((a, b2) => byText(a.id, b2.id)), relationships: mergedRels },
|
|
44820
|
+
conflicts: conflicts.sort((a, b2) => byText(a.id, b2.id)),
|
|
44604
44821
|
clean: conflicts.length === 0,
|
|
44605
44822
|
summary: { nodes: merged.size, relationships: mergedRels.length, conflicts: conflicts.length }
|
|
44606
44823
|
};
|
|
@@ -45852,10 +46069,10 @@ function buildAtlas(graphs, opts = {}) {
|
|
|
45852
46069
|
for (const n of g.nodes) if (!nodes2.has(n.id)) nodes2.set(n.id, n);
|
|
45853
46070
|
for (const r of g.relationships) relationships.push(r);
|
|
45854
46071
|
}
|
|
45855
|
-
const nodeList = [...nodes2.values()].sort((a, b) => a.id
|
|
46072
|
+
const nodeList = [...nodes2.values()].sort((a, b) => byText(a.id, b.id));
|
|
45856
46073
|
const byType = {};
|
|
45857
46074
|
for (const n of nodeList) byType[n.type] = (byType[n.type] || 0) + 1;
|
|
45858
|
-
missions.sort((a, b) => a.id
|
|
46075
|
+
missions.sort((a, b) => byText(a.id, b.id));
|
|
45859
46076
|
return {
|
|
45860
46077
|
schema: ATLAS_SCHEMA,
|
|
45861
46078
|
product: opts.product || null,
|
|
@@ -45888,7 +46105,7 @@ function searchAtlas(atlas, query, opts = {}) {
|
|
|
45888
46105
|
};
|
|
45889
46106
|
let hits = atlas.nodes.filter((n) => `${n.id} ${n.title || ""} ${n.description || ""}`.toLowerCase().includes(q2));
|
|
45890
46107
|
if (opts.type) hits = hits.filter((n) => n.type === opts.type);
|
|
45891
|
-
hits.sort((a, b) => score(a) - score(b) || a.type
|
|
46108
|
+
hits.sort((a, b) => score(a) - score(b) || byText(a.type, b.type) || byText(a.id, b.id));
|
|
45892
46109
|
return hits.slice(0, opts.limit || 25);
|
|
45893
46110
|
}
|
|
45894
46111
|
|
|
@@ -45951,7 +46168,7 @@ function buildMissionIndex(files, opts = {}) {
|
|
|
45951
46168
|
reviewed: ast.approval?.reviewed === true
|
|
45952
46169
|
};
|
|
45953
46170
|
}).filter((m) => m.mission);
|
|
45954
|
-
missions.sort((a, b) => a.mission
|
|
46171
|
+
missions.sort((a, b) => byText(a.mission, b.mission));
|
|
45955
46172
|
const byArea = {};
|
|
45956
46173
|
for (const m of missions) {
|
|
45957
46174
|
const a = m.area || "uncategorized";
|
|
@@ -46259,7 +46476,7 @@ function buildFocusGraph(atlas, { seeds = [], depth = 2, scope = null } = {}) {
|
|
|
46259
46476
|
}
|
|
46260
46477
|
frontier = next;
|
|
46261
46478
|
}
|
|
46262
|
-
const focusNodes = [...included.values()].map(({ node: node2, reason, depth: dd }) => ({ id: node2.id, type: node2.type, title: node2.title || node2.id, focusReason: reason, depth: dd, confidence: node2.confidence || null, provenance: node2.provenance || null })).sort((a, b) => a.depth - b.depth || a.id
|
|
46479
|
+
const focusNodes = [...included.values()].map(({ node: node2, reason, depth: dd }) => ({ id: node2.id, type: node2.type, title: node2.title || node2.id, focusReason: reason, depth: dd, confidence: node2.confidence || null, provenance: node2.provenance || null })).sort((a, b) => a.depth - b.depth || byText(a.id, b.id));
|
|
46263
46480
|
const idSet = new Set(focusNodes.map((n) => n.id));
|
|
46264
46481
|
const focusRels = rels2.filter((r) => idSet.has(r.from) && idSet.has(r.to));
|
|
46265
46482
|
const byReason = {};
|
|
@@ -47217,7 +47434,7 @@ function assemblePassport({ parts, change = null, runs = [], purpose = null, ext
|
|
|
47217
47434
|
notRead.push({ part: p.name, file: u.file, line: u.line, what: owner ? `${owner.label}: ${u.why}` : u.why });
|
|
47218
47435
|
}
|
|
47219
47436
|
}
|
|
47220
|
-
const order = (a, b) => `${a.part}/${a.file}
|
|
47437
|
+
const order = (a, b) => byText(`${a.part}/${a.file}`, `${b.part}/${b.file}`) || (a.lines?.[0] ?? a.line ?? 0) - (b.lines?.[0] ?? b.line ?? 0);
|
|
47221
47438
|
behavior.sort(order);
|
|
47222
47439
|
effects.sort(order);
|
|
47223
47440
|
notRead.sort(order);
|