@skillstech/thunderlang 1.6.1 → 1.7.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 +46 -0
- package/dist/core.cjs +31 -28
- package/dist/index.cjs +292 -59
- package/dist/learn.cjs +81 -22
- 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 +2818 -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 +4 -4
- package/src/core/cli.mjs +7 -2
- package/src/core/csharp-run.mjs +29 -8
- package/src/core/diagnostics.mjs +3 -1
- package/src/core/engine-core.mjs +20 -1
- package/src/core/go-run.mjs +3 -2
- package/src/core/java-run.mjs +3 -3
- package/src/core/kind.mjs +42 -0
- package/src/core/parser.mjs +54 -7
- package/src/core/project.mjs +3 -0
- package/src/core/react-run.mjs +3 -3
- package/src/core/runtime-npm.mjs +79 -0
- package/src/core/runtime-react.mjs +2 -1
- package/src/core/runtime-typescript.mjs +7 -3
- package/src/core/rust-run.mjs +3 -2
- package/src/core/target-csharp.mjs +5 -1
- package/src/core/target-go.mjs +1 -1
- package/src/core/target-python.mjs +1 -1
- package/src/core/target-rust.mjs +1 -1
- package/src/core/target-typescript.mjs +33 -1
- package/src/core/typescript-run.mjs +9 -4
- package/src/decision.mjs +2 -1
- package/src/distributed.mjs +2 -1
- package/src/emit.mjs +2 -2
- package/src/focus.mjs +2 -1
- package/src/intent-atlas.mjs +4 -3
- package/src/mcp.mjs +10 -3
- package/src/passport-fs.mjs +2 -1
- package/src/passport.mjs +2 -1
- package/src/privacy.mjs +2 -1
- package/src/read-repo.mjs +3 -2
- package/src/report.mjs +3 -2
- package/src/review.mjs +2 -1
- package/src/select.mjs +2 -1
- package/src/semantic-diff.mjs +7 -6
- package/src/system.mjs +2 -1
- package/src/text-order.mjs +6 -0
- package/src/thunderize.mjs +2 -1
- package/src/trace-data.mjs +3 -2
- package/src/trace.mjs +4 -3
- package/src/write-across-cli.mjs +22 -4
- package/src/write-across.mjs +2 -1
- package/syntaxes/thunder.tmLanguage.json +196 -0
package/dist/index.cjs
CHANGED
|
@@ -1791,6 +1791,9 @@ var BLOCKABLE_PHASES = [
|
|
|
1791
1791
|
"release"
|
|
1792
1792
|
];
|
|
1793
1793
|
|
|
1794
|
+
// src/text-order.mjs
|
|
1795
|
+
var byText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
1796
|
+
|
|
1794
1797
|
// src/conflict.mjs
|
|
1795
1798
|
var norm = (s) => String(s ?? "").trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
1796
1799
|
var NEG = /\b(no|not|never|forbidden|prohibited|unavailable|disallowed|without)\b/;
|
|
@@ -1837,7 +1840,7 @@ function detectConflicts(ast) {
|
|
|
1837
1840
|
}
|
|
1838
1841
|
}
|
|
1839
1842
|
}
|
|
1840
|
-
return out.sort((a, b) => `${a.type}\0${a.name}
|
|
1843
|
+
return out.sort((a, b) => byText(`${a.type}\0${a.name}`, `${b.type}\0${b.name}`));
|
|
1841
1844
|
}
|
|
1842
1845
|
|
|
1843
1846
|
// src/lifecycle.mjs
|
|
@@ -1909,7 +1912,7 @@ function analyzeDistributed(ast) {
|
|
|
1909
1912
|
findings2.push({ code: "IL-DIST-005", target: h.trigger, message: `Duplicate handler references undeclared event "${m[1]}".` });
|
|
1910
1913
|
}
|
|
1911
1914
|
}
|
|
1912
|
-
return findings2.sort((a, b) => `${a.code} ${a.target}
|
|
1915
|
+
return findings2.sort((a, b) => byText(`${a.code} ${a.target}`, `${b.code} ${b.target}`));
|
|
1913
1916
|
}
|
|
1914
1917
|
|
|
1915
1918
|
// src/decision.mjs
|
|
@@ -1933,7 +1936,7 @@ function analyzeDecision(dec) {
|
|
|
1933
1936
|
}
|
|
1934
1937
|
}
|
|
1935
1938
|
}
|
|
1936
|
-
return findings2.sort((a, b) => `${a.code} ${a.message}
|
|
1939
|
+
return findings2.sort((a, b) => byText(`${a.code} ${a.message}`, `${b.code} ${b.message}`));
|
|
1937
1940
|
}
|
|
1938
1941
|
|
|
1939
1942
|
// src/privacy.mjs
|
|
@@ -1996,7 +1999,7 @@ function analyzePrivacy(ast) {
|
|
|
1996
1999
|
});
|
|
1997
2000
|
}
|
|
1998
2001
|
}
|
|
1999
|
-
out.sort((a, b) => (a.code + a.path
|
|
2002
|
+
out.sort((a, b) => byText(a.code + a.path, b.code + b.path));
|
|
2000
2003
|
return out;
|
|
2001
2004
|
}
|
|
2002
2005
|
|
|
@@ -2585,7 +2588,7 @@ function notesSummary(ast) {
|
|
|
2585
2588
|
byLens
|
|
2586
2589
|
};
|
|
2587
2590
|
}
|
|
2588
|
-
var COMPILER_VERSION = "1.
|
|
2591
|
+
var COMPILER_VERSION = "1.7.0";
|
|
2589
2592
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
2590
2593
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
2591
2594
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -2658,7 +2661,7 @@ function semanticDiagnostics(ast) {
|
|
|
2658
2661
|
err(
|
|
2659
2662
|
"missing-subject",
|
|
2660
2663
|
"No mission, service, event, api, database, or experience declared.",
|
|
2661
|
-
"Every file must declare one subject so the compiler knows what it is reasoning about.",
|
|
2664
|
+
"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).",
|
|
2662
2665
|
[{ label: "Add a mission declaration", insert: "mission MyMission", block: "top" }]
|
|
2663
2666
|
);
|
|
2664
2667
|
}
|
|
@@ -4726,7 +4729,7 @@ function buildMissionIndex(files, opts = {}) {
|
|
|
4726
4729
|
reviewed: ast.approval?.reviewed === true
|
|
4727
4730
|
};
|
|
4728
4731
|
}).filter((m) => m.mission);
|
|
4729
|
-
missions.sort((a, b) => a.mission
|
|
4732
|
+
missions.sort((a, b) => byText(a.mission, b.mission));
|
|
4730
4733
|
const byArea = {};
|
|
4731
4734
|
for (const m of missions) {
|
|
4732
4735
|
const a = m.area || "uncategorized";
|
|
@@ -4801,7 +4804,7 @@ function selectCandidate(candidates2, policy = {}) {
|
|
|
4801
4804
|
if (bv == null) return -1;
|
|
4802
4805
|
if (av !== bv) return p.direction === "max" ? bv - av : av - bv;
|
|
4803
4806
|
}
|
|
4804
|
-
return String(a.id)
|
|
4807
|
+
return byText(String(a.id), String(b.id));
|
|
4805
4808
|
});
|
|
4806
4809
|
return { winner: ranked[0] || null, ranking: ranked, eligibleCount: eligible.length, rejected: (candidates2 || []).length - eligible.length, prefer };
|
|
4807
4810
|
}
|
|
@@ -5136,10 +5139,10 @@ function buildAtlas(graphs, opts = {}) {
|
|
|
5136
5139
|
for (const n of g.nodes) if (!nodes2.has(n.id)) nodes2.set(n.id, n);
|
|
5137
5140
|
for (const r of g.relationships) relationships.push(r);
|
|
5138
5141
|
}
|
|
5139
|
-
const nodeList = [...nodes2.values()].sort((a, b) => a.id
|
|
5142
|
+
const nodeList = [...nodes2.values()].sort((a, b) => byText(a.id, b.id));
|
|
5140
5143
|
const byType = {};
|
|
5141
5144
|
for (const n of nodeList) byType[n.type] = (byType[n.type] || 0) + 1;
|
|
5142
|
-
missions.sort((a, b) => a.id
|
|
5145
|
+
missions.sort((a, b) => byText(a.id, b.id));
|
|
5143
5146
|
return {
|
|
5144
5147
|
schema: ATLAS_SCHEMA,
|
|
5145
5148
|
product: opts.product || null,
|
|
@@ -5172,7 +5175,7 @@ function searchAtlas(atlas, query, opts = {}) {
|
|
|
5172
5175
|
};
|
|
5173
5176
|
let hits = atlas.nodes.filter((n) => `${n.id} ${n.title || ""} ${n.description || ""}`.toLowerCase().includes(q2));
|
|
5174
5177
|
if (opts.type) hits = hits.filter((n) => n.type === opts.type);
|
|
5175
|
-
hits.sort((a, b) => score(a) - score(b) || a.type
|
|
5178
|
+
hits.sort((a, b) => score(a) - score(b) || byText(a.type, b.type) || byText(a.id, b.id));
|
|
5176
5179
|
return hits.slice(0, opts.limit || 25);
|
|
5177
5180
|
}
|
|
5178
5181
|
|
|
@@ -5937,9 +5940,9 @@ function diffGraphs(before, after) {
|
|
|
5937
5940
|
const bn = bNodes.get(id2);
|
|
5938
5941
|
if (bn && contentKey(bn) !== contentKey(an)) changedNodes.push({ id: id2, type: an.type, before: bn, after: an });
|
|
5939
5942
|
}
|
|
5940
|
-
addedNodes.sort((a, b) => a.id
|
|
5941
|
-
removedNodes.sort((a, b) => a.id
|
|
5942
|
-
changedNodes.sort((a, b) => a.id
|
|
5943
|
+
addedNodes.sort((a, b) => byText(a.id, b.id));
|
|
5944
|
+
removedNodes.sort((a, b) => byText(a.id, b.id));
|
|
5945
|
+
changedNodes.sort((a, b) => byText(a.id, b.id));
|
|
5943
5946
|
const bRel = new Set((before.relationships || []).map(relKey));
|
|
5944
5947
|
const aRel = new Set((after.relationships || []).map(relKey));
|
|
5945
5948
|
const addedRelationships = (after.relationships || []).filter((r) => !bRel.has(relKey(r)));
|
|
@@ -6024,11 +6027,11 @@ function mergeGraphs(base2, ours, theirs) {
|
|
|
6024
6027
|
const present = inO !== inB ? inO : inT;
|
|
6025
6028
|
if (present) mergedRels.push(r);
|
|
6026
6029
|
}
|
|
6027
|
-
mergedRels.sort((a, b2) => relKey(a)
|
|
6030
|
+
mergedRels.sort((a, b2) => byText(relKey(a), relKey(b2)));
|
|
6028
6031
|
return {
|
|
6029
6032
|
schema: "intent-merge-v1",
|
|
6030
|
-
merged: { nodes: [...merged.values()].sort((a, b2) => a.id
|
|
6031
|
-
conflicts: conflicts.sort((a, b2) => a.id
|
|
6033
|
+
merged: { nodes: [...merged.values()].sort((a, b2) => byText(a.id, b2.id)), relationships: mergedRels },
|
|
6034
|
+
conflicts: conflicts.sort((a, b2) => byText(a.id, b2.id)),
|
|
6032
6035
|
clean: conflicts.length === 0,
|
|
6033
6036
|
summary: { nodes: merged.size, relationships: mergedRels.length, conflicts: conflicts.length }
|
|
6034
6037
|
};
|
|
@@ -7682,7 +7685,7 @@ function buildReport(files) {
|
|
|
7682
7685
|
}
|
|
7683
7686
|
perFile.push({ file, mission: ast.mission || null, ...counts, ok: counts.error === 0 });
|
|
7684
7687
|
}
|
|
7685
|
-
const topCodes = Object.entries(byCode).sort((a, b) => b[1] - a[1] || a[0]
|
|
7688
|
+
const topCodes = Object.entries(byCode).sort((a, b) => b[1] - a[1] || byText(a[0], b[0])).slice(0, 10).map(([code3, count2]) => ({ code: code3, count: count2, area: AREA_OF.get(code3) || "other" }));
|
|
7686
7689
|
const totalDiagnostics = Object.values(bySeverity).reduce((a, b) => a + b, 0);
|
|
7687
7690
|
return {
|
|
7688
7691
|
schema: REPORT_SCHEMA,
|
|
@@ -7704,7 +7707,7 @@ function buildReport(files) {
|
|
|
7704
7707
|
outcomeContracts,
|
|
7705
7708
|
outcomeContractRate: pct(outcomeContracts, outcomes)
|
|
7706
7709
|
},
|
|
7707
|
-
files: perFile.sort((a, b) => b.error - a.error || b.warning - a.warning || a.file
|
|
7710
|
+
files: perFile.sort((a, b) => b.error - a.error || b.warning - a.warning || byText(a.file, b.file))
|
|
7708
7711
|
};
|
|
7709
7712
|
}
|
|
7710
7713
|
|
|
@@ -8215,7 +8218,7 @@ function buildFocusGraph(atlas, { seeds = [], depth = 2, scope = null } = {}) {
|
|
|
8215
8218
|
}
|
|
8216
8219
|
frontier = next;
|
|
8217
8220
|
}
|
|
8218
|
-
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
|
|
8221
|
+
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));
|
|
8219
8222
|
const idSet = new Set(focusNodes.map((n) => n.id));
|
|
8220
8223
|
const focusRels = rels2.filter((r) => idSet.has(r.from) && idSet.has(r.to));
|
|
8221
8224
|
const byReason = {};
|
|
@@ -9495,8 +9498,232 @@ function verifyDiff(intentText, { before = null, after, language = "typescript"
|
|
|
9495
9498
|
};
|
|
9496
9499
|
}
|
|
9497
9500
|
|
|
9501
|
+
// src/behaviour.mjs
|
|
9502
|
+
var import_node_child_process = require("node:child_process");
|
|
9503
|
+
function findPython() {
|
|
9504
|
+
for (const cmd of [process.env.THUNDER_PYTHON, "python3", "python"].filter(Boolean)) {
|
|
9505
|
+
const r = (0, import_node_child_process.spawnSync)(cmd, ["-c", 'import sys; print("%d.%d" % sys.version_info[:2])'], { encoding: "utf8" });
|
|
9506
|
+
if (r.status !== 0 || !r.stdout) continue;
|
|
9507
|
+
const [maj, min] = r.stdout.trim().split(".").map(Number);
|
|
9508
|
+
if (maj > 3 || maj === 3 && min >= 10) return { cmd, version: r.stdout.trim() };
|
|
9509
|
+
return { error: `the behaviour check needs Python 3.10 or newer, but "${cmd}" is Python ${r.stdout.trim()}` };
|
|
9510
|
+
}
|
|
9511
|
+
return { error: "the behaviour check needs Python 3.10 or newer, and none was found (tried THUNDER_PYTHON, python3, python)" };
|
|
9512
|
+
}
|
|
9513
|
+
var BEHAVIOUR_SCHEMA = "thunder-behaviour-v1";
|
|
9514
|
+
var MAX_INPUTS = 400;
|
|
9515
|
+
function pythonParams(source, name) {
|
|
9516
|
+
const re = new RegExp(`^def\\s+${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\(`, "m");
|
|
9517
|
+
const m = re.exec(source);
|
|
9518
|
+
if (!m) return null;
|
|
9519
|
+
let i = m.index + m[0].length, depth = 1, text2 = "";
|
|
9520
|
+
for (; i < source.length && depth; i++) {
|
|
9521
|
+
const c = source[i];
|
|
9522
|
+
if (c === "(" || c === "[" || c === "{") depth++;
|
|
9523
|
+
else if (c === ")" || c === "]" || c === "}") depth--;
|
|
9524
|
+
if (depth) text2 += c;
|
|
9525
|
+
}
|
|
9526
|
+
const parts = [];
|
|
9527
|
+
depth = 0;
|
|
9528
|
+
let cur = "";
|
|
9529
|
+
for (const c of text2) {
|
|
9530
|
+
if ("([{".includes(c)) depth++;
|
|
9531
|
+
if (")]}".includes(c)) depth--;
|
|
9532
|
+
if (c === "," && !depth) {
|
|
9533
|
+
parts.push(cur);
|
|
9534
|
+
cur = "";
|
|
9535
|
+
} else cur += c;
|
|
9536
|
+
}
|
|
9537
|
+
parts.push(cur);
|
|
9538
|
+
const params = [];
|
|
9539
|
+
for (const raw of parts.map((p) => p.trim()).filter(Boolean)) {
|
|
9540
|
+
if (raw === "/" || raw === "*") continue;
|
|
9541
|
+
if (raw.startsWith("*")) return { unsupported: `it takes ${raw.startsWith("**") ? "named extras" : "extra values"} (${raw})` };
|
|
9542
|
+
const pname = raw.split(/[:=]/)[0].trim();
|
|
9543
|
+
params.push({ name: pname, hasDefault: raw.includes("=") });
|
|
9544
|
+
}
|
|
9545
|
+
return { params };
|
|
9546
|
+
}
|
|
9547
|
+
function pythonBody(source, name) {
|
|
9548
|
+
const lines = source.split("\n");
|
|
9549
|
+
const start = lines.findIndex((l) => new RegExp(`^def\\s+${name}\\s*\\(`).test(l));
|
|
9550
|
+
if (start < 0) return "";
|
|
9551
|
+
let end2 = start + 1;
|
|
9552
|
+
while (end2 < lines.length && (lines[end2].trim() === "" || /^\s/.test(lines[end2]))) end2++;
|
|
9553
|
+
return lines.slice(start, end2).join("\n");
|
|
9554
|
+
}
|
|
9555
|
+
function probeValues(...bodies) {
|
|
9556
|
+
const nums = /* @__PURE__ */ new Set(), strs = /* @__PURE__ */ new Set();
|
|
9557
|
+
for (const body2 of bodies) {
|
|
9558
|
+
const code3 = body2.replace(/#.*$/gm, "");
|
|
9559
|
+
for (const m of code3.matchAll(/(?<![\w.])(\d+(?:\.\d+)?)(?![\w.])/g)) nums.add(m[1]);
|
|
9560
|
+
for (const m of code3.matchAll(/(["'])((?:(?!\1)[^\\\n]){0,40})\1/g)) strs.add(m[2]);
|
|
9561
|
+
}
|
|
9562
|
+
const values = [];
|
|
9563
|
+
values.fromCode = /* @__PURE__ */ new Set();
|
|
9564
|
+
const add = (v, fromCode = false) => {
|
|
9565
|
+
if (!values.some((x) => JSON.stringify(x) === JSON.stringify(v))) values.push(v);
|
|
9566
|
+
if (fromCode) values.fromCode.add(JSON.stringify(v));
|
|
9567
|
+
};
|
|
9568
|
+
for (const n of [...nums].slice(0, 6)) {
|
|
9569
|
+
const isInt = !n.includes(".");
|
|
9570
|
+
const x = Number(n);
|
|
9571
|
+
if (isInt) {
|
|
9572
|
+
add(x - 1, true);
|
|
9573
|
+
add(x, true);
|
|
9574
|
+
add(x + 1, true);
|
|
9575
|
+
} else {
|
|
9576
|
+
add(x, true);
|
|
9577
|
+
add(Math.round((x - 0.01) * 100) / 100, true);
|
|
9578
|
+
add(Math.round((x + 0.01) * 100) / 100, true);
|
|
9579
|
+
}
|
|
9580
|
+
}
|
|
9581
|
+
for (const v of [0, 1, -1, true, false, null]) add(v);
|
|
9582
|
+
for (const s of [...strs].slice(0, 4)) add(s);
|
|
9583
|
+
add("");
|
|
9584
|
+
add([]);
|
|
9585
|
+
return values;
|
|
9586
|
+
}
|
|
9587
|
+
function inputKinds(body2, params) {
|
|
9588
|
+
return Object.fromEntries(params.map((p) => {
|
|
9589
|
+
const n = p.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9590
|
+
if (new RegExp(`\\b${n}\\s*(?:[<>]=?|==|!=)\\s*-?\\d|-?\\d[\\d.]*\\s*(?:[<>]=?|==|!=)\\s*${n}\\b|\\b${n}\\s*[-+*/%]|[-+*/%]\\s*${n}\\b|\\b${n}\\s*[<>]=?\\s*[A-Za-z_]|[A-Za-z_]\\w*\\s*[<>]=?\\s*${n}\\b|range\\([^)]*\\b${n}\\b`).test(body2)) return [p.name, "number"];
|
|
9591
|
+
if (new RegExp(`\\b${n}\\s*(?:==|!=)\\s*["']|["']\\s*(?:==|!=)\\s*${n}\\b|\\b${n}\\s+(?:not\\s+)?in\\s*[(\\[{]\\s*["']`).test(body2)) return [p.name, "text"];
|
|
9592
|
+
if (new RegExp(`(?:\\bif|\\band|\\bor|\\bnot|\\belif)\\s+${n}\\s*(?::|\\band\\b|\\bor\\b|$)`, "m").test(body2)) return [p.name, "bool"];
|
|
9593
|
+
return [p.name, null];
|
|
9594
|
+
}));
|
|
9595
|
+
}
|
|
9596
|
+
function typedInputs(params, values, kinds, { odd = true } = {}) {
|
|
9597
|
+
const pool = (k) => {
|
|
9598
|
+
if (k === "number") return values.filter((v) => typeof v === "number");
|
|
9599
|
+
if (k === "text") return values.filter((v) => typeof v === "string" || v === null);
|
|
9600
|
+
if (k === "bool") return [true, false];
|
|
9601
|
+
return values;
|
|
9602
|
+
};
|
|
9603
|
+
const pools = params.map((p) => pool(kinds[p.name]));
|
|
9604
|
+
const key = (a) => JSON.stringify(a);
|
|
9605
|
+
const seen = /* @__PURE__ */ new Set(), out = [];
|
|
9606
|
+
const push = (a) => {
|
|
9607
|
+
const k = key(a);
|
|
9608
|
+
if (!seen.has(k)) {
|
|
9609
|
+
seen.add(k);
|
|
9610
|
+
out.push(a);
|
|
9611
|
+
}
|
|
9612
|
+
};
|
|
9613
|
+
const total = pools.reduce((n, p) => n * p.length, 1);
|
|
9614
|
+
if (total <= MAX_INPUTS) {
|
|
9615
|
+
for (let k = 0; k < total; k++) {
|
|
9616
|
+
const args = [];
|
|
9617
|
+
let r = k;
|
|
9618
|
+
for (const p of pools) {
|
|
9619
|
+
args.push(p[r % p.length]);
|
|
9620
|
+
r = Math.floor(r / p.length);
|
|
9621
|
+
}
|
|
9622
|
+
push(args);
|
|
9623
|
+
}
|
|
9624
|
+
} else {
|
|
9625
|
+
let seed = 20261127;
|
|
9626
|
+
const rand = () => {
|
|
9627
|
+
seed = (seed * 1103515245 + 12345) % 2147483648;
|
|
9628
|
+
return seed / 2147483648;
|
|
9629
|
+
};
|
|
9630
|
+
for (let j = 0; j < params.length; j++) for (const v of pools[j]) push(pools.map((p, i) => i === j ? v : p[0]));
|
|
9631
|
+
while (out.length < MAX_INPUTS) push(pools.map((p) => p[Math.floor(rand() * p.length)]));
|
|
9632
|
+
}
|
|
9633
|
+
if (odd) {
|
|
9634
|
+
for (let j = 0; j < params.length; j++) for (const v of values) if (!pools[j].some((x) => key(x) === key(v))) push(pools.map((p, i) => i === j ? v : p[0]));
|
|
9635
|
+
}
|
|
9636
|
+
return out;
|
|
9637
|
+
}
|
|
9638
|
+
var HARNESS = String.raw`
|
|
9639
|
+
import json, sys, signal, io, contextlib, types, os
|
|
9640
|
+
job = json.loads(sys.stdin.read())
|
|
9641
|
+
# The file's own folder, so its imports of neighbouring modules work as they would for the program.
|
|
9642
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(job["path"])))
|
|
9643
|
+
class TimeUp(Exception):
|
|
9644
|
+
pass
|
|
9645
|
+
def on_alarm(signum, frame):
|
|
9646
|
+
raise TimeUp()
|
|
9647
|
+
if hasattr(signal, "SIGALRM"):
|
|
9648
|
+
signal.signal(signal.SIGALRM, on_alarm)
|
|
9649
|
+
def limit(seconds):
|
|
9650
|
+
if hasattr(signal, "SIGALRM"):
|
|
9651
|
+
signal.setitimer(signal.ITIMER_REAL, seconds)
|
|
9652
|
+
def unlimit():
|
|
9653
|
+
if hasattr(signal, "SIGALRM"):
|
|
9654
|
+
signal.setitimer(signal.ITIMER_REAL, 0)
|
|
9655
|
+
def load(src):
|
|
9656
|
+
mod = types.ModuleType("thunder_behaviour_subject")
|
|
9657
|
+
mod.__file__ = job["path"]
|
|
9658
|
+
out = io.StringIO()
|
|
9659
|
+
try:
|
|
9660
|
+
limit(5)
|
|
9661
|
+
with contextlib.redirect_stdout(out):
|
|
9662
|
+
exec(compile(src, job["path"], "exec"), mod.__dict__)
|
|
9663
|
+
unlimit()
|
|
9664
|
+
except BaseException as e:
|
|
9665
|
+
unlimit()
|
|
9666
|
+
return None, "%s: %s" % (type(e).__name__, e)
|
|
9667
|
+
fn = getattr(mod, job["name"], None)
|
|
9668
|
+
if not callable(fn):
|
|
9669
|
+
return None, "the file has no function named %s" % job["name"]
|
|
9670
|
+
return fn, None
|
|
9671
|
+
def call(fn, args):
|
|
9672
|
+
out = io.StringIO()
|
|
9673
|
+
try:
|
|
9674
|
+
limit(1)
|
|
9675
|
+
with contextlib.redirect_stdout(out):
|
|
9676
|
+
value = fn(*args)
|
|
9677
|
+
unlimit()
|
|
9678
|
+
return {"value": repr(value), "printed": out.getvalue()}
|
|
9679
|
+
except TimeUp:
|
|
9680
|
+
return {"error": "took longer than a second", "printed": out.getvalue()}
|
|
9681
|
+
except BaseException as e:
|
|
9682
|
+
unlimit()
|
|
9683
|
+
return {"error": "%s: %s" % (type(e).__name__, e), "printed": out.getvalue()}
|
|
9684
|
+
result = {}
|
|
9685
|
+
for side in ("before", "after"):
|
|
9686
|
+
fn, problem = load(job[side])
|
|
9687
|
+
if problem:
|
|
9688
|
+
result[side] = {"problem": problem}
|
|
9689
|
+
continue
|
|
9690
|
+
result[side] = {"results": [call(fn, list(a)) for a in job["inputs"]]}
|
|
9691
|
+
print(json.dumps(result))
|
|
9692
|
+
`;
|
|
9693
|
+
var show = (v) => v === null ? "None" : v === true ? "True" : v === false ? "False" : typeof v === "string" ? JSON.stringify(v) : Array.isArray(v) ? "[]" : String(v);
|
|
9694
|
+
var outcome = (r) => r.error ? `error (${r.error})` : `${r.value}${r.printed ? ` and printed ${JSON.stringify(r.printed.trimEnd())}` : ""}`;
|
|
9695
|
+
function behaviourCheck({ path, name, before, after, python = null, timeoutMs = 6e4 }) {
|
|
9696
|
+
const base2 = { schema: BEHAVIOUR_SCHEMA, function: `${path}#${name}`, inputs: 0, changes: [] };
|
|
9697
|
+
if (!/\.py$/.test(path)) return { ...base2, status: "not-run", reason: "the behaviour check runs Python functions only for now", says: `Behaviour not checked: ${path} is not Python (the behaviour check runs Python only for now).` };
|
|
9698
|
+
const sig = pythonParams(after, name) ?? pythonParams(before, name);
|
|
9699
|
+
if (!sig) return { ...base2, status: "not-run", reason: `${name} is not a top-level function (methods need an object to run on)`, says: `Behaviour not checked: ${name} is not a top-level function.` };
|
|
9700
|
+
if (sig.unsupported) return { ...base2, status: "not-run", reason: sig.unsupported, says: `Behaviour not checked: ${name} ${sig.unsupported}.` };
|
|
9701
|
+
const py = python ?? findPython();
|
|
9702
|
+
if (py.error) return { ...base2, status: "not-run", reason: py.error, says: `Behaviour not checked: ${py.error}` };
|
|
9703
|
+
const values = probeValues(pythonBody(before, name), pythonBody(after, name));
|
|
9704
|
+
const body2 = pythonBody(after, name) || pythonBody(before, name);
|
|
9705
|
+
const kind = inputKinds(body2, sig.params);
|
|
9706
|
+
const inputs2 = typedInputs(sig.params, values, kind);
|
|
9707
|
+
const run = (0, import_node_child_process.spawnSync)(py.cmd, ["-I", "-c", HARNESS], { input: JSON.stringify({ path, name, before, after, inputs: inputs2 }), encoding: "utf8", timeout: timeoutMs, maxBuffer: 64 * 1024 * 1024 });
|
|
9708
|
+
if (run.error || run.status !== 0) return { ...base2, status: "not-run", reason: run.error ? `the run stopped: ${run.error.message}` : `Python failed: ${(run.stderr || "").trim().split("\n").pop()}`, says: "Behaviour not checked: the run did not finish." };
|
|
9709
|
+
const res = JSON.parse(run.stdout);
|
|
9710
|
+
if (res.after.problem) return { ...base2, status: "broken", inputs: 0, reason: res.after.problem, says: `Behaviour: the changed file does not load: ${res.after.problem}.` };
|
|
9711
|
+
if (res.before.problem) return { ...base2, status: "not-run", reason: `the original file does not load: ${res.before.problem}`, says: `Behaviour not checked: the original file does not load (${res.before.problem}).` };
|
|
9712
|
+
const changes = [];
|
|
9713
|
+
inputs2.forEach((args, i) => {
|
|
9714
|
+
const b = res.before.results[i], a = res.after.results[i];
|
|
9715
|
+
if (outcome(b) !== outcome(a)) changes.push({ inputs: Object.fromEntries(sig.params.map((p, j) => [p.name, args[j]])), before: outcome(b), after: outcome(a) });
|
|
9716
|
+
});
|
|
9717
|
+
const fits = (pname, v) => kind[pname] === "bool" ? typeof v === "boolean" : kind[pname] === "text" ? typeof v === "string" && v !== "" : kind[pname] === "number" ? typeof v === "number" && values.fromCode.has(JSON.stringify(v)) : values.fromCode.has(JSON.stringify(v)) || typeof v === "boolean";
|
|
9718
|
+
const likeReal = (c) => Object.entries(c.inputs).filter(([k, v]) => fits(k, v)).length;
|
|
9719
|
+
changes.sort((x, y) => likeReal(y) - likeReal(x));
|
|
9720
|
+
const said = (c) => `${sig.params.length ? sig.params.map((p) => `${p.name} ${show(c.inputs[p.name])}`).join(", ") : "no inputs"}: before ${c.before}, after ${c.after}`;
|
|
9721
|
+
const says = changes.length ? `Behaviour: ran ${name} before and after on ${inputs2.length} inputs made from its code; ${changes.length} gave a different answer, e.g. ${said(changes[0])}.` : `Behaviour: ran ${name} before and after on ${inputs2.length} inputs made from its code; every answer is the same.`;
|
|
9722
|
+
return { ...base2, status: changes.length ? "changed" : "same", inputs: inputs2.length, changes, says, example: changes[0] ? said(changes[0]) : null, examples: changes.slice(0, 5).map(said) };
|
|
9723
|
+
}
|
|
9724
|
+
|
|
9498
9725
|
// src/mcp.mjs
|
|
9499
|
-
var
|
|
9726
|
+
var import_node_child_process3 = require("node:child_process");
|
|
9500
9727
|
var import_node_fs3 = require("node:fs");
|
|
9501
9728
|
var import_node_path3 = require("node:path");
|
|
9502
9729
|
|
|
@@ -35839,7 +36066,7 @@ function summarize(items, files) {
|
|
|
35839
36066
|
inputs2.get(p.name).push(it.id);
|
|
35840
36067
|
}
|
|
35841
36068
|
}
|
|
35842
|
-
const byUse = (m) => [...m].map(([name, ids]) => ({ name, decisions: ids })).sort((a, b) => b.decisions.length - a.decisions.length || a.name
|
|
36069
|
+
const byUse = (m) => [...m].map(([name, ids]) => ({ name, decisions: ids })).sort((a, b) => b.decisions.length - a.decisions.length || byText(a.name, b.name));
|
|
35843
36070
|
return { files, items, counts, languages, folders, answers: byUse(answers), inputs: byUse(inputs2) };
|
|
35844
36071
|
}
|
|
35845
36072
|
function searchRepo(index, { query = "", kinds = [], status = [], languages = [], path = "", answer = "", input = "" } = {}) {
|
|
@@ -35863,7 +36090,7 @@ function groupByFile(items) {
|
|
|
35863
36090
|
if (!groups3.has(it.file)) groups3.set(it.file, []);
|
|
35864
36091
|
groups3.get(it.file).push(it);
|
|
35865
36092
|
}
|
|
35866
|
-
return [...groups3].sort(([a], [b]) => a
|
|
36093
|
+
return [...groups3].sort(([a], [b]) => byText(a, b)).map(([file, list3]) => ({ file, language: list3[0].language, items: list3 }));
|
|
35867
36094
|
}
|
|
35868
36095
|
function readingOf(f, language = readableLanguage(f.path, f.source)) {
|
|
35869
36096
|
if (f.readError) throw new Error(f.readError);
|
|
@@ -35999,7 +36226,7 @@ function plainFromReading(item4) {
|
|
|
35999
36226
|
provenance: "inferred-from-code",
|
|
36000
36227
|
needsReview: []
|
|
36001
36228
|
};
|
|
36002
|
-
const
|
|
36229
|
+
const outcome2 = (t) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(t) || /^-?\d+(\.\d+)?$/.test(t) ? t : null;
|
|
36003
36230
|
const stateFacts = [];
|
|
36004
36231
|
const input = (id2) => inputs2.find((i) => i.id === id2);
|
|
36005
36232
|
const factFor = (path) => {
|
|
@@ -36042,10 +36269,10 @@ function plainFromReading(item4) {
|
|
|
36042
36269
|
conditions.push({ input: f.id, op: "is", value: !m[1] });
|
|
36043
36270
|
} else return null;
|
|
36044
36271
|
}
|
|
36045
|
-
if (!
|
|
36272
|
+
if (!outcome2(r.result)) return null;
|
|
36046
36273
|
model.rules.push({ outcome: r.result, join: join6, conditions });
|
|
36047
36274
|
}
|
|
36048
|
-
if (!
|
|
36275
|
+
if (!outcome2(item4.otherwise.result)) return null;
|
|
36049
36276
|
model.otherwise = item4.otherwise.result;
|
|
36050
36277
|
for (const i of inputs2) {
|
|
36051
36278
|
model.needsReview.push(i.kind === "yesno" ? `What does "${i.yes}" mean in business words?` : `Is ${i.label} money, a count, or something else?`);
|
|
@@ -38007,7 +38234,7 @@ function callsSummary(model) {
|
|
|
38007
38234
|
else p.calls++;
|
|
38008
38235
|
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}` });
|
|
38009
38236
|
}
|
|
38010
|
-
return [...pairs2.values()].sort((x, y) => y.calls + y.sends - (x.calls + x.sends) || x.from
|
|
38237
|
+
return [...pairs2.values()].sort((x, y) => y.calls + y.sends - (x.calls + x.sends) || byText(x.from, y.from) || byText(x.to, y.to));
|
|
38011
38238
|
}
|
|
38012
38239
|
|
|
38013
38240
|
// src/flow/ts-parse.mjs
|
|
@@ -41912,15 +42139,15 @@ function ruleRanges(rule) {
|
|
|
41912
42139
|
const lo = Math.min(...limits) - 1, hi = Math.max(...limits) + 1;
|
|
41913
42140
|
const ranges = [];
|
|
41914
42141
|
for (let v = lo; v <= hi; v++) {
|
|
41915
|
-
let
|
|
42142
|
+
let outcome2;
|
|
41916
42143
|
try {
|
|
41917
|
-
|
|
42144
|
+
outcome2 = answerWords(explainPlain(rule, { [id2]: v }).outcome);
|
|
41918
42145
|
} catch {
|
|
41919
42146
|
return null;
|
|
41920
42147
|
}
|
|
41921
42148
|
const last = ranges.at(-1);
|
|
41922
|
-
if (last && last.answer ===
|
|
41923
|
-
else ranges.push({ from: v, to: v, answer:
|
|
42149
|
+
if (last && last.answer === outcome2) last.to = v;
|
|
42150
|
+
else ranges.push({ from: v, to: v, answer: outcome2 });
|
|
41924
42151
|
}
|
|
41925
42152
|
ranges[0].from = null;
|
|
41926
42153
|
ranges.at(-1).to = null;
|
|
@@ -42189,7 +42416,7 @@ function settingsIn(files) {
|
|
|
42189
42416
|
}
|
|
42190
42417
|
}
|
|
42191
42418
|
}
|
|
42192
|
-
return out.sort((a, b) => a.file
|
|
42419
|
+
return out.sort((a, b) => byText(a.file, b.file) || a.line - b.line || byText(a.key, b.key));
|
|
42193
42420
|
}
|
|
42194
42421
|
var NAME = '((?:[`"\\[]?[A-Za-z_][\\w$]*[`"\\]]?\\.){0,2}[`"\\[]?[A-Za-z_][\\w$]*[`"\\]]?)';
|
|
42195
42422
|
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"]);
|
|
@@ -42259,7 +42486,7 @@ function tablesIn(files) {
|
|
|
42259
42486
|
if (seen.has(k)) return false;
|
|
42260
42487
|
seen.add(k);
|
|
42261
42488
|
return true;
|
|
42262
|
-
}).sort((a, b) => a.file
|
|
42489
|
+
}).sort((a, b) => byText(a.file, b.file) || a.line - b.line || byText(a.table, b.table));
|
|
42263
42490
|
}
|
|
42264
42491
|
var DEFINES = /* @__PURE__ */ new Set(["creates", "alters", "drops"]);
|
|
42265
42492
|
|
|
@@ -42405,8 +42632,8 @@ function linkRepos(read) {
|
|
|
42405
42632
|
return true;
|
|
42406
42633
|
});
|
|
42407
42634
|
};
|
|
42408
|
-
links.splice(0, links.length, ...once(links).sort((a, b) => sortKey(a)
|
|
42409
|
-
notLinked.splice(0, notLinked.length, ...once(notLinked).sort((a, b) => sortKey(a)
|
|
42635
|
+
links.splice(0, links.length, ...once(links).sort((a, b) => byText(sortKey(a), sortKey(b))));
|
|
42636
|
+
notLinked.splice(0, notLinked.length, ...once(notLinked).sort((a, b) => byText(sortKey(a), sortKey(b))));
|
|
42410
42637
|
const repos = read.map(({ unknown, ...r }) => ({ ...r, unknown: unknown ?? [], packages: pk(r), settings: r.settings ?? [], tables: tb(r) }));
|
|
42411
42638
|
const body2 = { schema: TRACE_SCHEMA, rulesVersion: TRACE_RULES_VERSION, repos, links, notLinked, shared };
|
|
42412
42639
|
return { ...body2, fingerprint: sha256(JSON.stringify(body2)) };
|
|
@@ -42522,7 +42749,7 @@ function traceImpact(trace, changes) {
|
|
|
42522
42749
|
if (findings2.length > found || routes.length || listeners.length || requests.length || publishes.length || c.before) touched.push({ repo: c.repo, file: c.file, status: c.status });
|
|
42523
42750
|
}
|
|
42524
42751
|
const rank = { high: 0, medium: 1, low: 2 };
|
|
42525
|
-
findings2.sort((a, b) => rank[a.risk] - rank[b.risk] || a.at.cite
|
|
42752
|
+
findings2.sort((a, b) => rank[a.risk] - rank[b.risk] || byText(a.at.cite, b.at.cite));
|
|
42526
42753
|
return { schema: TRACE_IMPACT_SCHEMA, traceFingerprint: trace.fingerprint, findings: findings2, changed: touched, stopsAt: 1, note: "Stops at the first hop: callers of the callers are not listed. Links are facts read from code (no code was run); a call whose address is worked out when it runs is not linked." };
|
|
42527
42754
|
}
|
|
42528
42755
|
var count = (n, w) => `${n} ${n === 1 ? w : w.endsWith("y") ? `${w.slice(0, -1)}ies` : `${w}s`}`;
|
|
@@ -42850,10 +43077,10 @@ var Stream = class {
|
|
|
42850
43077
|
throw new CoreError(diag(code3, this.line, msg, hint));
|
|
42851
43078
|
}
|
|
42852
43079
|
expectSym(s, what) {
|
|
42853
|
-
if (!this.sym(s)) this.fail(`I expected "${s}" ${what}${this.peek() ? `, but found "${
|
|
43080
|
+
if (!this.sym(s)) this.fail(`I expected "${s}" ${what}${this.peek() ? `, but found "${show2(this.peek())}"` : ""}.`, null, "TC108");
|
|
42854
43081
|
}
|
|
42855
43082
|
};
|
|
42856
|
-
var
|
|
43083
|
+
var show2 = (t) => t.t === "word" ? t.text : t.t === "sym" ? t.text : t.t === "num" ? t.text : t.t === "money" ? `$${t.text}` : t.t === "percent" ? `${t.text}%` : t.t === "poss" ? "'s" : '"\u2026"';
|
|
42857
43084
|
var ExprParser = class {
|
|
42858
43085
|
constructor(names) {
|
|
42859
43086
|
this.names = names;
|
|
@@ -42862,7 +43089,7 @@ var ExprParser = class {
|
|
|
42862
43089
|
const s = new Stream(tokens, line);
|
|
42863
43090
|
if (s.done()) s.fail("A value is missing here.", null, "TC108");
|
|
42864
43091
|
const e = this.expr(s, opts);
|
|
42865
|
-
if (!s.done()) s.fail(`I understood the line up to "${
|
|
43092
|
+
if (!s.done()) s.fail(`I understood the line up to "${show2(s.peek())}", but not from there on.`, opts.extraHint ?? "Check the spelling, or put parentheses around a part to group it.", "TC112");
|
|
42866
43093
|
return e;
|
|
42867
43094
|
}
|
|
42868
43095
|
expr(s, o = {}) {
|
|
@@ -43125,7 +43352,7 @@ var ExprParser = class {
|
|
|
43125
43352
|
}
|
|
43126
43353
|
return { k: "list", items, line };
|
|
43127
43354
|
}
|
|
43128
|
-
if (t.t !== "word") s.fail(`I didn't expect "${
|
|
43355
|
+
if (t.t !== "word") s.fail(`I didn't expect "${show2(t)}" here.`, null, "TC105");
|
|
43129
43356
|
const w = t.lower;
|
|
43130
43357
|
if (w === "true" || w === "yes") {
|
|
43131
43358
|
s.next();
|
|
@@ -45522,7 +45749,7 @@ function followLines(edit, original, current) {
|
|
|
45522
45749
|
}
|
|
45523
45750
|
|
|
45524
45751
|
// src/trace-fs.mjs
|
|
45525
|
-
var
|
|
45752
|
+
var import_node_child_process2 = require("node:child_process");
|
|
45526
45753
|
var import_node_path2 = require("node:path");
|
|
45527
45754
|
var import_node_fs2 = require("node:fs");
|
|
45528
45755
|
|
|
@@ -45583,7 +45810,7 @@ function collectReadableFiles(root, { maxFiles = 5e3, maxFileBytes = 4e5, manife
|
|
|
45583
45810
|
var TRACE_MANIFESTS = /^(go\.mod|package\.json|tsconfig\.json|jsconfig\.json|requirements\.txt|.+\.csproj)$/i;
|
|
45584
45811
|
var git2 = (dir, args) => {
|
|
45585
45812
|
try {
|
|
45586
|
-
return (0,
|
|
45813
|
+
return (0, import_node_child_process2.execFileSync)("git", ["-C", dir, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024 });
|
|
45587
45814
|
} catch {
|
|
45588
45815
|
return null;
|
|
45589
45816
|
}
|
|
@@ -46282,7 +46509,7 @@ var LOCKFILES = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "poetry.loc
|
|
|
46282
46509
|
function proofFreshness(proof, environment) {
|
|
46283
46510
|
let head = null;
|
|
46284
46511
|
try {
|
|
46285
|
-
head = (0,
|
|
46512
|
+
head = (0, import_node_child_process3.execSync)("git rev-parse HEAD", { encoding: "utf8", stdio: ["pipe", "pipe", "ignore"] }).trim() || null;
|
|
46286
46513
|
} catch {
|
|
46287
46514
|
head = null;
|
|
46288
46515
|
}
|
|
@@ -46545,18 +46772,24 @@ var TOOLS = [
|
|
|
46545
46772
|
},
|
|
46546
46773
|
{
|
|
46547
46774
|
name: "intent_write",
|
|
46548
|
-
description: `CHANGE CODE THROUGH THUNDER, WITH PROOF (TypeScript, JavaScript, Python, Go). Give the files ({ path, source }) and one or more Thunder edits; get back a minimal patch, the new file contents, and a proof: the edited function now reads exactly as the edit says, and every other function means the same. Edits: setValue (to, or toValue in Thunder words), setCondition (when: "amount is at least 100 and not member"), addStep / removeStep / moveStep (step: code, "Give \u2026", "Set \u2026 to \u2026", "Stop with "\u2026"", or { if, then, else }), addStop (when, message), removeStop, addInput (name, default), removeInput, setGivesBack (value), rename. Each edit names its function (member: "name" or { file, name, line }) and its step by the line thunder read shows ("line:12"); lines are the original file's lines for every edit in the list. Status is written, refused (with why), or needs-ai (with an instruction for a coding agent). Nothing is written to disk: apply the returned files, then run the project's tests.`,
|
|
46775
|
+
description: `CHANGE CODE THROUGH THUNDER, WITH PROOF (TypeScript, JavaScript, Python, Go). Give the files ({ path, source }) and one or more Thunder edits; get back a minimal patch, the new file contents, and a proof: the edited function now reads exactly as the edit says, and every other function means the same. Edits: setValue (to, or toValue in Thunder words), setCondition (when: "amount is at least 100 and not member"), addStep / removeStep / moveStep (step: code, "Give \u2026", "Set \u2026 to \u2026", "Stop with "\u2026"", or { if, then, else }), addStop (when, message), removeStop, addInput (name, default), removeInput, setGivesBack (value), rename. Each edit names its function (member: "name" or { file, name, line }) and its step by the line thunder read shows ("line:12"); lines are the original file's lines for every edit in the list. Status is written, refused (with why), or needs-ai (with an instruction for a coding agent). Nothing is written to disk: apply the returned files, then run the project's tests. behaviour: true (Python only) also RUNS each edited function before and after on inputs made from its code and lists the inputs whose answer changed: tested evidence on those inputs, not a proof.`,
|
|
46549
46776
|
inputSchema: {
|
|
46550
46777
|
type: "object",
|
|
46551
46778
|
required: ["files", "edits"],
|
|
46552
46779
|
properties: {
|
|
46553
46780
|
files: { type: "array", minItems: 1, maxItems: 20, items: { type: "object", required: ["path", "source"], properties: { path: str3, source: str3 } } },
|
|
46554
|
-
edits: { description: "one Thunder edit object, or a list applied in order", anyOf: [{ type: "object" }, { type: "array", items: { type: "object" } }] }
|
|
46781
|
+
edits: { description: "one Thunder edit object, or a list applied in order", anyOf: [{ type: "object" }, { type: "array", items: { type: "object" } }] },
|
|
46782
|
+
behaviour: { type: "boolean", description: "Python only: run each edited function before and after on inputs made from its code (this runs the code) and report changed answers" }
|
|
46555
46783
|
}
|
|
46556
46784
|
},
|
|
46557
|
-
run: ({ files, edits }) => {
|
|
46785
|
+
run: ({ files, edits, behaviour }) => {
|
|
46558
46786
|
if (!Array.isArray(files) || !files.length) throw new Error("Give the files as [{ path, source }].");
|
|
46559
|
-
const
|
|
46787
|
+
const given = files.map((f) => ({ path: String(f.path), source: String(f.source) }));
|
|
46788
|
+
const r = thunderWrite(given, edits);
|
|
46789
|
+
if (behaviour && r.status === "written") {
|
|
46790
|
+
const originals = new Map(given.map((f) => [f.path, f.source]));
|
|
46791
|
+
r.proof.behaviour = (r.proof.edited.checks ?? []).filter((c) => r.files[c.file] != null).map((c) => behaviourCheck({ path: c.file, name: c.member, before: originals.get(c.file) ?? "", after: r.files[c.file] }));
|
|
46792
|
+
}
|
|
46560
46793
|
return { status: r.status, says: r.says, reason: r.reason ?? null, patch: r.patch ?? null, files: r.files ?? null, before: r.before ?? null, after: r.after ?? null, proof: r.proof ?? null, ...r.prompt ? { prompt: r.prompt } : {} };
|
|
46561
46794
|
}
|
|
46562
46795
|
},
|
|
@@ -46960,7 +47193,7 @@ function buildManifest(files, opts = {}) {
|
|
|
46960
47193
|
mustNotModify: impl.mustNotModify || [`${f.ast.mission}.contract`]
|
|
46961
47194
|
});
|
|
46962
47195
|
}
|
|
46963
|
-
implementations.sort((a, b) => a.id
|
|
47196
|
+
implementations.sort((a, b) => byText(a.id, b.id));
|
|
46964
47197
|
return {
|
|
46965
47198
|
schemaVersion: MANIFEST_SCHEMA_VERSION,
|
|
46966
47199
|
projectId: opts.projectId || null,
|
|
@@ -47182,7 +47415,7 @@ function thunderizeFiles(files, { name = "app" } = {}) {
|
|
|
47182
47415
|
skipped.push({ path: f.path, reason: `could not be read: ${e.message}` });
|
|
47183
47416
|
}
|
|
47184
47417
|
}
|
|
47185
|
-
out.sort((a, b) => a.path
|
|
47418
|
+
out.sort((a, b) => byText(a.path, b.path));
|
|
47186
47419
|
const total = { files: out.length, actions: 0, rules: 0, functions: 0, notReadYet: 0 };
|
|
47187
47420
|
for (const f of out) for (const k of ["actions", "rules", "functions", "notReadYet"]) total[k] += f.counts[k];
|
|
47188
47421
|
const langs = [...new Set(out.map((f) => LANGUAGE_NAMES[f.language] || f.language))].sort();
|
|
@@ -47974,7 +48207,7 @@ function thunderReview(oldFiles, newFiles) {
|
|
|
47974
48207
|
for (const x of rest2) items.splice(items.indexOf(x), 1);
|
|
47975
48208
|
}
|
|
47976
48209
|
for (const x of items) if (x.also) x.subject = `${x.subject} and ${x.also.length} more`;
|
|
47977
|
-
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)
|
|
48210
|
+
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));
|
|
47978
48211
|
const count2 = (s) => items.filter((x) => x.severity === s).length;
|
|
47979
48212
|
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 };
|
|
47980
48213
|
const onlyNotRead = !items.length && summary2.files && notRead.length === summary2.files;
|
|
@@ -48151,7 +48384,7 @@ function renderReviewComment(r, { maxChars = 6e4, fileUrl = null, notes = [], fo
|
|
|
48151
48384
|
}
|
|
48152
48385
|
|
|
48153
48386
|
// src/round-trip.mjs
|
|
48154
|
-
var
|
|
48387
|
+
var import_node_child_process4 = require("node:child_process");
|
|
48155
48388
|
var ROUND_TRIP_LANGUAGES = ["typescript", "javascript", "python", "go"];
|
|
48156
48389
|
var WRAP = {
|
|
48157
48390
|
typescript: (code3) => `function thunderRoundTrip() {
|
|
@@ -48253,7 +48486,7 @@ function inputs(k, n) {
|
|
|
48253
48486
|
return out;
|
|
48254
48487
|
}
|
|
48255
48488
|
function runJs(c) {
|
|
48256
|
-
const
|
|
48489
|
+
const show3 = (f, args) => {
|
|
48257
48490
|
try {
|
|
48258
48491
|
const v = f(...args);
|
|
48259
48492
|
return `= ${typeof v} ${JSON.stringify(v, (k, x) => x === void 0 ? "__undefined__" : Number.isNaN(x) ? "__NaN__" : x)}`;
|
|
@@ -48274,7 +48507,7 @@ function runJs(c) {
|
|
|
48274
48507
|
}
|
|
48275
48508
|
for (const combo of inputs(c.names.length, JS_POOL.length)) {
|
|
48276
48509
|
const args = combo.map((i) => Array.isArray(JS_POOL[i]) ? [...JS_POOL[i]] : JS_POOL[i]);
|
|
48277
|
-
const x =
|
|
48510
|
+
const x = show3(a, args), y = show3(b, args);
|
|
48278
48511
|
if (x !== y) return { result: "different", why: `with ${c.names.map((n, i) => `${n}=${JSON.stringify(args[i])}`).join(", ")}: ${x} before, ${y} after` };
|
|
48279
48512
|
}
|
|
48280
48513
|
return { result: "same", tried: inputs(c.names.length, JS_POOL.length).length };
|
|
@@ -48310,7 +48543,7 @@ function runBehavior(cases, language) {
|
|
|
48310
48543
|
if (language === "typescript" || language === "javascript") return cases.map(runJs);
|
|
48311
48544
|
if (language === "python") {
|
|
48312
48545
|
const payload = JSON.stringify(cases.map((c) => ({ ...c, inputs: inputs(c.names.length, PY_POOL.length) })));
|
|
48313
|
-
const r = (0,
|
|
48546
|
+
const r = (0, import_node_child_process4.spawnSync)("python3", ["-I", "-c", PY_RUNNER], { input: payload, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
48314
48547
|
if (r.status !== 0) return cases.map(() => ({ result: "not-run", why: `Python could not run: ${(r.stderr || r.error?.message || "").split("\n").filter(Boolean).pop() ?? "unknown"}` }));
|
|
48315
48548
|
return JSON.parse(r.stdout);
|
|
48316
48549
|
}
|
|
@@ -48569,7 +48802,7 @@ function joinRuleParts(parts) {
|
|
|
48569
48802
|
}
|
|
48570
48803
|
|
|
48571
48804
|
// src/passport-fs.mjs
|
|
48572
|
-
var
|
|
48805
|
+
var import_node_child_process5 = require("node:child_process");
|
|
48573
48806
|
var import_node_fs4 = require("node:fs");
|
|
48574
48807
|
var import_node_path5 = require("node:path");
|
|
48575
48808
|
|
|
@@ -48628,7 +48861,7 @@ function assemblePassport({ parts, change = null, runs = [], purpose = null, ext
|
|
|
48628
48861
|
notRead.push({ part: p.name, file: u.file, line: u.line, what: owner ? `${owner.label}: ${u.why}` : u.why });
|
|
48629
48862
|
}
|
|
48630
48863
|
}
|
|
48631
|
-
const order = (a, b) => `${a.part}/${a.file}
|
|
48864
|
+
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);
|
|
48632
48865
|
behavior.sort(order);
|
|
48633
48866
|
effects.sort(order);
|
|
48634
48867
|
notRead.sort(order);
|
|
@@ -48831,7 +49064,7 @@ function renderPassportMarkdown(p) {
|
|
|
48831
49064
|
// src/passport-fs.mjs
|
|
48832
49065
|
var git3 = (dir, args) => {
|
|
48833
49066
|
try {
|
|
48834
|
-
return (0,
|
|
49067
|
+
return (0, import_node_child_process5.execFileSync)("git", ["-C", dir, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 256 * 1024 * 1024 });
|
|
48835
49068
|
} catch {
|
|
48836
49069
|
return null;
|
|
48837
49070
|
}
|
|
@@ -48907,7 +49140,7 @@ function changesSince(root, base2) {
|
|
|
48907
49140
|
const old = c.status === "added" ? null : git3(root, ["show", `${base2}:${c.file}`]);
|
|
48908
49141
|
out.push({ file: c.file.slice(prefix.length), status: c.status, ranges: c.ranges, old: old == null || old.includes("\0") ? null : old });
|
|
48909
49142
|
}
|
|
48910
|
-
return out.sort((a, b) => a.file
|
|
49143
|
+
return out.sort((a, b) => byText(a.file, b.file));
|
|
48911
49144
|
}
|
|
48912
49145
|
function accessEvidence(report, partOf = () => null) {
|
|
48913
49146
|
const words14 = { guarded: "checks that the record belongs to the caller on every path", unguarded: "has a path with no ownership check (every step was followed)", "cannot tell": "cannot be told: Thunder could not follow every step", "cannot-tell": "cannot be told: Thunder could not follow every step" };
|
|
@@ -48960,7 +49193,7 @@ function buildPassport({ parts, base: base2 = null, head = null, run = [], purpo
|
|
|
48960
49193
|
const part = m && read.find((p) => p.name === m[1]) ? m[1] : null;
|
|
48961
49194
|
const command = part ? m[2] : String(spec);
|
|
48962
49195
|
const cwd = part ? read.find((p) => p.name === part).root : process.cwd();
|
|
48963
|
-
const r = (0,
|
|
49196
|
+
const r = (0, import_node_child_process5.spawnSync)(`(${command}) 2>&1`, { shell: true, cwd, encoding: "utf8", timeout: timeoutMs, maxBuffer: 64 * 1024 * 1024 });
|
|
48964
49197
|
const exitCode = r.status ?? (r.error || r.signal ? 1 : 0);
|
|
48965
49198
|
const output = `${r.stdout ?? ""}${r.error ? `
|
|
48966
49199
|
(${r.error.message})` : ""}${r.signal ? `
|