@skillstech/thunderlang 1.6.0 → 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 +55 -0
- package/dist/core.cjs +135 -60
- package/dist/index.cjs +394 -89
- 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/src/write-steps.mjs +14 -3
- package/src/write-words.mjs +59 -2
- 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
|
|
|
@@ -5489,7 +5492,7 @@ function literalDecimal(n) {
|
|
|
5489
5492
|
return null;
|
|
5490
5493
|
}
|
|
5491
5494
|
function renderExpr(src, inputs2, D, money = {}, dialect = "js") {
|
|
5492
|
-
const
|
|
5495
|
+
const known2 = new Set(inputs2);
|
|
5493
5496
|
const isMoney = (n) => n.k === "ref" && Object.prototype.hasOwnProperty.call(money, n.path);
|
|
5494
5497
|
const moneyRefs = (n, out = []) => {
|
|
5495
5498
|
if (isMoney(n)) out.push(n.path);
|
|
@@ -5550,7 +5553,7 @@ function renderExpr(src, inputs2, D, money = {}, dialect = "js") {
|
|
|
5550
5553
|
case "lit":
|
|
5551
5554
|
return typeof n.v === "string" ? JSON.stringify(n.v) : typeof n.v === "boolean" ? D.bool(n.v) : D.num ? D.num(n.v) : String(n.v);
|
|
5552
5555
|
case "ref":
|
|
5553
|
-
return
|
|
5556
|
+
return known2.has(n.path) || known2.has(n.path.split(".")[0]) ? n.path : JSON.stringify(n.path);
|
|
5554
5557
|
default:
|
|
5555
5558
|
return D.nil;
|
|
5556
5559
|
}
|
|
@@ -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
|
|
|
@@ -15376,8 +15603,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
15376
15603
|
const everyday = value ? sayPython(value) || sayCommon(value) : null;
|
|
15377
15604
|
if (everyday) return { kind: "set", says: `Sets ${target} to ${everyday}`, code: code3 };
|
|
15378
15605
|
if (c2 && wholeValueCall(value)) {
|
|
15379
|
-
const
|
|
15380
|
-
if (
|
|
15606
|
+
const known2 = sayCall(c2, firstArgs(value));
|
|
15607
|
+
if (known2) return { kind: "call", says: `${known2}, keeping the result as ${target}`, code: code3, callee: c2 };
|
|
15381
15608
|
if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, m[1]))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
|
|
15382
15609
|
return { kind: "set", says: `Works out ${target} from ${callWords(c2, value)}`, code: code3, callee: c2 };
|
|
15383
15610
|
}
|
|
@@ -15449,8 +15676,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
15449
15676
|
if (common) return { kind: "set", says: `Sets ${target} to ${common}`, code: code3 };
|
|
15450
15677
|
const c2 = callee(value);
|
|
15451
15678
|
if (c2 && wholeValueCall(value)) {
|
|
15452
|
-
const
|
|
15453
|
-
if (
|
|
15679
|
+
const known2 = sayCall(c2, firstArgs(value));
|
|
15680
|
+
if (known2) return { kind: "call", says: `${known2}, keeping the result as ${target}`, code: code3, callee: c2 };
|
|
15454
15681
|
if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, declType))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
|
|
15455
15682
|
return { kind: "set", says: `Works out ${target} from ${callWords(c2, value)}`, code: code3, callee: c2 };
|
|
15456
15683
|
}
|
|
@@ -15513,8 +15740,8 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
15513
15740
|
}
|
|
15514
15741
|
const c = callee(head);
|
|
15515
15742
|
if (c) {
|
|
15516
|
-
const
|
|
15517
|
-
if (
|
|
15743
|
+
const known2 = sayCall(c, firstArgs(head));
|
|
15744
|
+
if (known2) return { kind: "call", says: known2, code: code3, callee: c };
|
|
15518
15745
|
const o = head.indexOf("("), cl = o >= 0 ? closeOf(head, o) : -1;
|
|
15519
15746
|
const only = cl > o && /^\s*;?\s*$/.test(head.slice(cl + 1)) ? splitTopArgs(head.slice(o + 1, cl)) : [];
|
|
15520
15747
|
if ((LANG === "typescript" || LANG === "javascript" || LANG === "python") && only.length === 1 && !/^\s*(?:async\s*)?(?:\(|function\b|[A-Za-z_$][\w$]*\s*=>)/.test(only[0]) && !/^(?:exec|eval|compile|__import__|execfile|Function|setTimeout|setInterval)$/.test(c)) {
|
|
@@ -15526,9 +15753,9 @@ function classifyWords(raw, { inner = 0 } = {}) {
|
|
|
15526
15753
|
}
|
|
15527
15754
|
if ((m = head.match(/^([a-z_][\w.]*[?!]?)\s+(?![=<>!+\-*/%]|and\b|or\b|if\b|unless\b)(.+)$/)) && !/^(?:if|for|while|return|else|elsif|when|case|def|class|module|end|not|const|let|var|val|new|await|typeof|delete|void|in|of|throw|import|export|from|as|is)$/.test(m[1])) {
|
|
15528
15755
|
if (/^assert/.test(m[1])) return { kind: "check", says: `Checks: ${clip(head, 60)}`, code: code3 };
|
|
15529
|
-
const
|
|
15756
|
+
const known2 = sayCall(m[1], m[2]);
|
|
15530
15757
|
const named2 = /^[:'"]([\w ]+)['"]?/.exec(m[2].trim())?.[1];
|
|
15531
|
-
return { kind: "call", says:
|
|
15758
|
+
return { kind: "call", says: known2 || (named2 ? `Calls ${lastWords(m[1])}: ${words3(named2)}` : `Calls ${lastWords(m[1])}`), code: code3, callee: m[1] };
|
|
15532
15759
|
}
|
|
15533
15760
|
return { kind: "other", says: clip(head, 70), code: code3 };
|
|
15534
15761
|
}
|
|
@@ -21647,8 +21874,8 @@ function commandSays(cmd) {
|
|
|
21647
21874
|
case "bunx": {
|
|
21648
21875
|
const rest2 = args.filter((a) => a !== "--yes" && a !== "-y" && !a.startsWith("--package"));
|
|
21649
21876
|
const name = (rest2[0] ?? "").replace(/^(@[^/]+\/)?([^@]+).*$/, "$2");
|
|
21650
|
-
const
|
|
21651
|
-
return
|
|
21877
|
+
const known2 = JS_TOOLS[name]?.(rest2.slice(1));
|
|
21878
|
+
return known2 ?? (name ? `Runs ${name}` : null);
|
|
21652
21879
|
}
|
|
21653
21880
|
case "node": {
|
|
21654
21881
|
if (args[0] === "-p" || args[0] === "-e" || args[0] === "--eval" || args[0] === "--print") {
|
|
@@ -23161,7 +23388,7 @@ function actionWords(uses, w) {
|
|
|
23161
23388
|
if (w.cache) s += ", reusing saved downloads";
|
|
23162
23389
|
return s;
|
|
23163
23390
|
}
|
|
23164
|
-
const
|
|
23391
|
+
const known2 = {
|
|
23165
23392
|
"pnpm/action-setup": () => `Sets up pnpm${ver(w.version)}`,
|
|
23166
23393
|
"oven-sh/setup-bun": () => `Sets up Bun${ver(w["bun-version"])}`,
|
|
23167
23394
|
"denoland/setup-deno": () => "Sets up Deno",
|
|
@@ -23198,7 +23425,7 @@ function actionWords(uses, w) {
|
|
|
23198
23425
|
"codecov/codecov-action": () => "Sends test coverage to Codecov",
|
|
23199
23426
|
"actions/dependency-review-action": () => "Checks new dependencies for known problems"
|
|
23200
23427
|
}[key];
|
|
23201
|
-
if (
|
|
23428
|
+
if (known2) return known2();
|
|
23202
23429
|
return `Uses ${repo}`;
|
|
23203
23430
|
}
|
|
23204
23431
|
function readWorkflow(src, file = "workflow.yml") {
|
|
@@ -25688,12 +25915,12 @@ function secretLiteral(name, value) {
|
|
|
25688
25915
|
return !/^(true|false|yes|no|on|off|\d+|enabled|disabled|none|null|changeme|<.*>)$/i.test(v);
|
|
25689
25916
|
}
|
|
25690
25917
|
var HOST_KEY = /(host|hostname|addr|address|url|uri|server|servers|endpoint|dsn|broker|brokers|connection|conn)$/i;
|
|
25691
|
-
function servicesNamed(key, value,
|
|
25918
|
+
function servicesNamed(key, value, known2) {
|
|
25692
25919
|
const out = [];
|
|
25693
25920
|
const v = String(value ?? "").trim();
|
|
25694
25921
|
const add = (h) => {
|
|
25695
25922
|
const host = String(h).toLowerCase();
|
|
25696
|
-
if ((!
|
|
25923
|
+
if ((!known2 || known2.has(host)) && !out.includes(host) && !/^(localhost|0\.0\.0\.0|127\.0\.0\.1)$/.test(host)) out.push(host);
|
|
25697
25924
|
};
|
|
25698
25925
|
for (const part of v.split(/[,\s]+/)) {
|
|
25699
25926
|
if (!part) continue;
|
|
@@ -28797,8 +29024,8 @@ function simpleSaysInner(n, ctx = null) {
|
|
|
28797
29024
|
return { kind: "fail", says: `Fails with exit code ${DIES.get(name)}${msg ? `: "${msg}"` : ""}`, error: `exit code ${DIES.get(name)}`, ...msg ? { message: msg } : {}, callee: name };
|
|
28798
29025
|
}
|
|
28799
29026
|
if (KNOWN_FNS.has(name)) return out(`Runs ${words9(name)}${args.length ? ` with ${list2(args.slice(0, 4).map(sayWord))}${args.length > 4 ? ", \u2026" : ""}` : ""}`, { callee: name });
|
|
28800
|
-
const
|
|
28801
|
-
if (
|
|
29027
|
+
const known2 = sayCommand(name, args, sayWord);
|
|
29028
|
+
if (known2) return out(known2, { callee: name });
|
|
28802
29029
|
if (/^"?\$/.test(name)) return out(`Runs the command in ${sayWord(name)}`, { callee: name });
|
|
28803
29030
|
if (scriptPath(name)) return out(`Runs the script ${sayWord(name)}`, { callee: name });
|
|
28804
29031
|
return out(`Runs ${name}${args[0] && /^[a-z][\w-]*$/.test(args[0]) ? ` ${args[0]}` : ""}`, { callee: name });
|
|
@@ -29998,8 +30225,8 @@ function commandWords(toks, ctx = {}) {
|
|
|
29998
30225
|
return `${VERB[verb]} the ${many ? pluralNoun(noun) : noun}${object ? dup ? ` named by ${object}` : ` ${object}` : ""}${more}`;
|
|
29999
30226
|
}
|
|
30000
30227
|
const raws = argGroups(rest2).map(toksCode);
|
|
30001
|
-
const
|
|
30002
|
-
if (
|
|
30228
|
+
const known2 = sayCommand(raw.replace(/\.exe$/i, ""), raws, (w) => sayValue2(tokenize3(w)) ?? quoteText(w));
|
|
30229
|
+
if (known2) return known2;
|
|
30003
30230
|
if (/[\\/]|\.ps1$/i.test(raw)) return `Runs the script ${quoteText(raw)}${withArgs(a)}`;
|
|
30004
30231
|
return `Runs ${raw}${withArgs(a)}`;
|
|
30005
30232
|
}
|
|
@@ -32992,13 +33219,13 @@ var WRAPS_FUNCTION = /^(?:React\.)?(?:useCallback|useMemo|memo|forwardRef|useEve
|
|
|
32992
33219
|
var TEST_CALLS = /^(?:describe|it|test|context|suite|specify|before|after|beforeEach|afterEach|beforeAll|afterAll|setup|teardown|x?it|f?it|xdescribe|fdescribe|xtest|bench)(?:\.\w+)*$/;
|
|
32993
33220
|
function jsMoreFunctions(src, fns) {
|
|
32994
33221
|
const clean = stripCommentsKeepLayout(src);
|
|
32995
|
-
const
|
|
33222
|
+
const known2 = new Set(fns.map((f) => f.bodyStart));
|
|
32996
33223
|
const found = [];
|
|
32997
33224
|
const add = (fnIdx, paramsOpen, paramsClose, arrowParam, bo) => {
|
|
32998
|
-
if (
|
|
33225
|
+
if (known2.has(bo + 1)) return null;
|
|
32999
33226
|
const bc = matchClose(src, bo);
|
|
33000
33227
|
if (bc < 0) return null;
|
|
33001
|
-
|
|
33228
|
+
known2.add(bo + 1);
|
|
33002
33229
|
const line = lineAt2(src, fnIdx);
|
|
33003
33230
|
const params = arrowParam != null ? parseParams2(arrowParam, "typescript") : parseParams2(src.slice(paramsOpen + 1, paramsClose), "typescript");
|
|
33004
33231
|
const f = { key: `fn@${fnIdx}`, line, params, returns: null, bodyStart: bo + 1, body: src.slice(bo + 1, bc), at: fnIdx, end: bc };
|
|
@@ -33028,7 +33255,7 @@ function jsMoreFunctions(src, fns) {
|
|
|
33028
33255
|
const arrowRe = /=>\s*\{/g;
|
|
33029
33256
|
while (m = arrowRe.exec(clean)) {
|
|
33030
33257
|
const bo = m.index + m[0].length - 1;
|
|
33031
|
-
if (
|
|
33258
|
+
if (known2.has(bo + 1)) continue;
|
|
33032
33259
|
let j = m.index - 1;
|
|
33033
33260
|
while (j >= 0 && /\s/.test(clean[j])) j--;
|
|
33034
33261
|
let start, paramText = null, pOpen = -1, pClose = -1;
|
|
@@ -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();
|
|
@@ -43266,6 +43493,31 @@ var lit3 = (type, value, raw) => ({ kind: "literal", type, value, raw });
|
|
|
43266
43493
|
var NULL_RAW = { python: "None", go: "nil", typescript: "null", javascript: "null" };
|
|
43267
43494
|
var Unsaid = class extends Error {
|
|
43268
43495
|
};
|
|
43496
|
+
var Unknown = class extends Error {
|
|
43497
|
+
constructor(word) {
|
|
43498
|
+
super(word);
|
|
43499
|
+
this.word = word;
|
|
43500
|
+
}
|
|
43501
|
+
};
|
|
43502
|
+
function inputsOf2(scope) {
|
|
43503
|
+
const code3 = codeOnly(scope || ""), open = code3.indexOf("(");
|
|
43504
|
+
if (open < 0) return [];
|
|
43505
|
+
let depth = 0, end2 = open;
|
|
43506
|
+
for (; end2 < code3.length; end2++) {
|
|
43507
|
+
if (code3[end2] === "(") depth++;
|
|
43508
|
+
else if (code3[end2] === ")" && --depth === 0) break;
|
|
43509
|
+
}
|
|
43510
|
+
const out = [];
|
|
43511
|
+
for (const part of code3.slice(open + 1, end2).split(",")) {
|
|
43512
|
+
const id2 = part.replace(/^\s*[*&.]*\s*/, "").match(/^[A-Za-z_]\w*/)?.[0];
|
|
43513
|
+
if (id2 && !KEYWORDS.has(id2) && id2 !== "self" && id2 !== "cls" && !out.includes(id2)) out.push(id2);
|
|
43514
|
+
}
|
|
43515
|
+
return out;
|
|
43516
|
+
}
|
|
43517
|
+
var unknownWord = (word, scope) => {
|
|
43518
|
+
const inputs2 = inputsOf2(scope);
|
|
43519
|
+
return `"${word}" is not a name in this function or file${inputs2.length ? `; its inputs are ${inputs2.map((i) => `"${nameWords2(i) || i}"`).join(", ")}` : ""}. Use one of its names, or add an input first (addInput).`;
|
|
43520
|
+
};
|
|
43269
43521
|
var no2 = (why) => {
|
|
43270
43522
|
throw new Unsaid(why);
|
|
43271
43523
|
};
|
|
@@ -43288,8 +43540,8 @@ function toTree(n, language, names) {
|
|
|
43288
43540
|
case "nothing":
|
|
43289
43541
|
return lit3("null", null, NULL_RAW[language]);
|
|
43290
43542
|
case "name": {
|
|
43291
|
-
const id2 = names.get(n.name)
|
|
43292
|
-
if (!id2)
|
|
43543
|
+
const id2 = names.get(n.name);
|
|
43544
|
+
if (!id2) throw new Unknown(n.name);
|
|
43293
43545
|
return nm(id2);
|
|
43294
43546
|
}
|
|
43295
43547
|
case "field":
|
|
@@ -43359,8 +43611,8 @@ function toTree(n, language, names) {
|
|
|
43359
43611
|
}
|
|
43360
43612
|
function parseThunder(text2, source, scope) {
|
|
43361
43613
|
const names = namesOf(source, scope);
|
|
43362
|
-
const
|
|
43363
|
-
const ep = new ExprParser({ known, fields: new Set(names.keys()), records: /* @__PURE__ */ new Set(), recordFields: /* @__PURE__ */ new Map(), funcInputs: /* @__PURE__ */ new Map(), recordText: /* @__PURE__ */ new Map(), screens: /* @__PURE__ */ new Map() });
|
|
43614
|
+
const known2 = new Map([...names.keys()].map((k) => [k, "var"]));
|
|
43615
|
+
const ep = new ExprParser({ known: known2, fields: new Set(names.keys()), records: /* @__PURE__ */ new Set(), recordFields: /* @__PURE__ */ new Map(), funcInputs: /* @__PURE__ */ new Map(), recordText: /* @__PURE__ */ new Map(), screens: /* @__PURE__ */ new Map() });
|
|
43364
43616
|
const lexed = tokenizeLine(String(text2), 1);
|
|
43365
43617
|
const tokens = Array.isArray(lexed) ? lexed : lexed.tokens;
|
|
43366
43618
|
return { node: ep.parse(tokens, 1), names };
|
|
@@ -43376,6 +43628,7 @@ function thunderTree(text2, language, source, scope = "") {
|
|
|
43376
43628
|
return { tree: toTree(parsed.node, language, parsed.names) };
|
|
43377
43629
|
} catch (e) {
|
|
43378
43630
|
if (e instanceof Unsaid) return { error: `Thunder write cannot say ${e.message} in ${language} yet.` };
|
|
43631
|
+
if (e instanceof Unknown) return { error: unknownWord(e.word, scope), unknown: e.word };
|
|
43379
43632
|
throw e;
|
|
43380
43633
|
}
|
|
43381
43634
|
}
|
|
@@ -43397,6 +43650,42 @@ function thunderStep(text2, language, source, scope = "") {
|
|
|
43397
43650
|
}
|
|
43398
43651
|
return null;
|
|
43399
43652
|
}
|
|
43653
|
+
var BUILTINS = {
|
|
43654
|
+
python: "abs all any ascii bin bool bytearray bytes callable chr dict dir divmod enumerate filter float format frozenset getattr globals hasattr hash hex id int isinstance issubclass iter len list locals map max min next object oct open ord pow print range repr reversed round set setattr slice sorted str sum super tuple type vars zip Exception ValueError TypeError KeyError IndexError RuntimeError AttributeError NotImplementedError StopIteration LookupError ArithmeticError ZeroDivisionError OSError NotImplemented Ellipsis __name__ __file__",
|
|
43655
|
+
typescript: "Math JSON Object Array String Number Boolean Date Error TypeError RangeError Promise Map Set WeakMap Symbol BigInt RegExp console parseInt parseFloat isNaN isFinite undefined NaN Infinity globalThis window document process require module exports",
|
|
43656
|
+
go: "len cap append make new copy delete panic recover print println close complex real imag min max clear error string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 bool byte rune any iota fmt errors strings strconv"
|
|
43657
|
+
};
|
|
43658
|
+
BUILTINS.javascript = BUILTINS.typescript;
|
|
43659
|
+
function unknownName(tree, language, source, scope = "") {
|
|
43660
|
+
const known2 = new Set(BUILTINS[language]?.split(" ") ?? []);
|
|
43661
|
+
for (const text2 of [codeOnly(source), codeOnly(scope)]) for (const m of text2.matchAll(/\b[A-Za-z_][A-Za-z0-9_]*\b/g)) known2.add(m[0]);
|
|
43662
|
+
for (const k of KEYWORDS) known2.add(k);
|
|
43663
|
+
const bound = /* @__PURE__ */ new Set();
|
|
43664
|
+
const all = [];
|
|
43665
|
+
const walk = (n) => {
|
|
43666
|
+
if (Array.isArray(n)) {
|
|
43667
|
+
n.forEach(walk);
|
|
43668
|
+
return;
|
|
43669
|
+
}
|
|
43670
|
+
if (!n || typeof n !== "object") return;
|
|
43671
|
+
if (n.kind === "lambda" || n.kind === "code") {
|
|
43672
|
+
bound.add("*");
|
|
43673
|
+
return;
|
|
43674
|
+
}
|
|
43675
|
+
if (n.kind === "name") all.push(n.name);
|
|
43676
|
+
if ((n.kind === "assign" || n.kind === "declare") && n.target?.kind === "name") bound.add(n.target.name);
|
|
43677
|
+
if (n.kind === "declare" && typeof n.name === "string") bound.add(n.name);
|
|
43678
|
+
if (n.kind === "loop") for (const v of [n.variable, n.var, n.name, n.target]) {
|
|
43679
|
+
if (typeof v === "string") bound.add(v);
|
|
43680
|
+
else if (v?.kind === "name") bound.add(v.name);
|
|
43681
|
+
}
|
|
43682
|
+
for (const [k, v] of Object.entries(n)) if (k !== "raw" && v && typeof v === "object") walk(v);
|
|
43683
|
+
};
|
|
43684
|
+
walk(tree);
|
|
43685
|
+
if (bound.has("*")) return null;
|
|
43686
|
+
return all.find((id2) => !known2.has(id2) && !bound.has(id2)) ?? null;
|
|
43687
|
+
}
|
|
43688
|
+
var unknownNameReason = (word, scope) => unknownWord(word, scope);
|
|
43400
43689
|
|
|
43401
43690
|
// src/same.mjs
|
|
43402
43691
|
var SAME_SCHEMA = "thunder-same-v1";
|
|
@@ -43813,11 +44102,17 @@ function exprFrom(input, language, what = "expression") {
|
|
|
43813
44102
|
if (looksThunder(input) && words14().tree) return words14().tree;
|
|
43814
44103
|
for (const l of PARSE_ORDER(language)) {
|
|
43815
44104
|
const t = parseExpr(input, l);
|
|
43816
|
-
if (t && t.kind !== "code" && !misreadIs(t)) return adapt(t, language);
|
|
44105
|
+
if (t && t.kind !== "code" && !misreadIs(t)) return known(adapt(t, language), language);
|
|
43817
44106
|
}
|
|
43818
44107
|
if (words14().tree) return words14().tree;
|
|
44108
|
+
if (said?.unknown) refuse(`The ${what} "${input}" could not be read: ${said.error}`);
|
|
43819
44109
|
refuse(`The ${what} "${input}" could not be read${said?.error ? ` (${said.error})` : ""}. Write it in Thunder's words, for example "days is more than 10 and not member's vip", or as code.`);
|
|
43820
44110
|
}
|
|
44111
|
+
function known(tree, language) {
|
|
44112
|
+
const word = unknownName(tree, language, wordsSource, wordsScope);
|
|
44113
|
+
if (word) refuse(`It cannot be written: ${unknownNameReason(word, wordsScope)}`);
|
|
44114
|
+
return tree;
|
|
44115
|
+
}
|
|
43821
44116
|
function adapt(tree, language) {
|
|
43822
44117
|
const t = cloneShape(tree);
|
|
43823
44118
|
for (const n of nodesOf(t)) {
|
|
@@ -43847,9 +44142,10 @@ function statementFrom(input, language) {
|
|
|
43847
44142
|
const a = adapt(t, language);
|
|
43848
44143
|
try {
|
|
43849
44144
|
renderStatement(a, language);
|
|
43850
|
-
return a;
|
|
43851
44145
|
} catch {
|
|
44146
|
+
continue;
|
|
43852
44147
|
}
|
|
44148
|
+
return known(a, language);
|
|
43853
44149
|
}
|
|
43854
44150
|
}
|
|
43855
44151
|
refuse(`The step "${input}" could not be read as one statement.`);
|
|
@@ -44846,6 +45142,9 @@ function opAddFunction(state, edit) {
|
|
|
44846
45142
|
if (language === "go" && inputs2.some((p) => !p.type)) refuse("Go needs a type for every input.");
|
|
44847
45143
|
const ctx = { language, source, item: { name, line: 1 } };
|
|
44848
45144
|
if (language === "go" && edit.returns) ctx.goResults = edit.returns;
|
|
45145
|
+
wordsScope = `${name}(${inputs2.map((p) => p.name).join(", ")})`;
|
|
45146
|
+
wordsSource = `${wordsScope}
|
|
45147
|
+
${source}`;
|
|
44849
45148
|
const nodes2 = (edit.steps || []).map((s) => stepSpec(s, { ...ctx, source: `${source}
|
|
44850
45149
|
func ${name}() (${edit.returns || ""}) {}` }));
|
|
44851
45150
|
if (!nodes2.length) refuse("A new function needs at least one step.");
|
|
@@ -45450,7 +45749,7 @@ function followLines(edit, original, current) {
|
|
|
45450
45749
|
}
|
|
45451
45750
|
|
|
45452
45751
|
// src/trace-fs.mjs
|
|
45453
|
-
var
|
|
45752
|
+
var import_node_child_process2 = require("node:child_process");
|
|
45454
45753
|
var import_node_path2 = require("node:path");
|
|
45455
45754
|
var import_node_fs2 = require("node:fs");
|
|
45456
45755
|
|
|
@@ -45511,7 +45810,7 @@ function collectReadableFiles(root, { maxFiles = 5e3, maxFileBytes = 4e5, manife
|
|
|
45511
45810
|
var TRACE_MANIFESTS = /^(go\.mod|package\.json|tsconfig\.json|jsconfig\.json|requirements\.txt|.+\.csproj)$/i;
|
|
45512
45811
|
var git2 = (dir, args) => {
|
|
45513
45812
|
try {
|
|
45514
|
-
return (0,
|
|
45813
|
+
return (0, import_node_child_process2.execFileSync)("git", ["-C", dir, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024 });
|
|
45515
45814
|
} catch {
|
|
45516
45815
|
return null;
|
|
45517
45816
|
}
|
|
@@ -46210,7 +46509,7 @@ var LOCKFILES = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "poetry.loc
|
|
|
46210
46509
|
function proofFreshness(proof, environment) {
|
|
46211
46510
|
let head = null;
|
|
46212
46511
|
try {
|
|
46213
|
-
head = (0,
|
|
46512
|
+
head = (0, import_node_child_process3.execSync)("git rev-parse HEAD", { encoding: "utf8", stdio: ["pipe", "pipe", "ignore"] }).trim() || null;
|
|
46214
46513
|
} catch {
|
|
46215
46514
|
head = null;
|
|
46216
46515
|
}
|
|
@@ -46473,18 +46772,24 @@ var TOOLS = [
|
|
|
46473
46772
|
},
|
|
46474
46773
|
{
|
|
46475
46774
|
name: "intent_write",
|
|
46476
|
-
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.`,
|
|
46477
46776
|
inputSchema: {
|
|
46478
46777
|
type: "object",
|
|
46479
46778
|
required: ["files", "edits"],
|
|
46480
46779
|
properties: {
|
|
46481
46780
|
files: { type: "array", minItems: 1, maxItems: 20, items: { type: "object", required: ["path", "source"], properties: { path: str3, source: str3 } } },
|
|
46482
|
-
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" }
|
|
46483
46783
|
}
|
|
46484
46784
|
},
|
|
46485
|
-
run: ({ files, edits }) => {
|
|
46785
|
+
run: ({ files, edits, behaviour }) => {
|
|
46486
46786
|
if (!Array.isArray(files) || !files.length) throw new Error("Give the files as [{ path, source }].");
|
|
46487
|
-
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
|
+
}
|
|
46488
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 } : {} };
|
|
46489
46794
|
}
|
|
46490
46795
|
},
|
|
@@ -46888,7 +47193,7 @@ function buildManifest(files, opts = {}) {
|
|
|
46888
47193
|
mustNotModify: impl.mustNotModify || [`${f.ast.mission}.contract`]
|
|
46889
47194
|
});
|
|
46890
47195
|
}
|
|
46891
|
-
implementations.sort((a, b) => a.id
|
|
47196
|
+
implementations.sort((a, b) => byText(a.id, b.id));
|
|
46892
47197
|
return {
|
|
46893
47198
|
schemaVersion: MANIFEST_SCHEMA_VERSION,
|
|
46894
47199
|
projectId: opts.projectId || null,
|
|
@@ -47110,7 +47415,7 @@ function thunderizeFiles(files, { name = "app" } = {}) {
|
|
|
47110
47415
|
skipped.push({ path: f.path, reason: `could not be read: ${e.message}` });
|
|
47111
47416
|
}
|
|
47112
47417
|
}
|
|
47113
|
-
out.sort((a, b) => a.path
|
|
47418
|
+
out.sort((a, b) => byText(a.path, b.path));
|
|
47114
47419
|
const total = { files: out.length, actions: 0, rules: 0, functions: 0, notReadYet: 0 };
|
|
47115
47420
|
for (const f of out) for (const k of ["actions", "rules", "functions", "notReadYet"]) total[k] += f.counts[k];
|
|
47116
47421
|
const langs = [...new Set(out.map((f) => LANGUAGE_NAMES[f.language] || f.language))].sort();
|
|
@@ -47902,7 +48207,7 @@ function thunderReview(oldFiles, newFiles) {
|
|
|
47902
48207
|
for (const x of rest2) items.splice(items.indexOf(x), 1);
|
|
47903
48208
|
}
|
|
47904
48209
|
for (const x of items) if (x.also) x.subject = `${x.subject} and ${x.also.length} more`;
|
|
47905
|
-
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));
|
|
47906
48211
|
const count2 = (s) => items.filter((x) => x.severity === s).length;
|
|
47907
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 };
|
|
47908
48213
|
const onlyNotRead = !items.length && summary2.files && notRead.length === summary2.files;
|
|
@@ -48079,7 +48384,7 @@ function renderReviewComment(r, { maxChars = 6e4, fileUrl = null, notes = [], fo
|
|
|
48079
48384
|
}
|
|
48080
48385
|
|
|
48081
48386
|
// src/round-trip.mjs
|
|
48082
|
-
var
|
|
48387
|
+
var import_node_child_process4 = require("node:child_process");
|
|
48083
48388
|
var ROUND_TRIP_LANGUAGES = ["typescript", "javascript", "python", "go"];
|
|
48084
48389
|
var WRAP = {
|
|
48085
48390
|
typescript: (code3) => `function thunderRoundTrip() {
|
|
@@ -48181,7 +48486,7 @@ function inputs(k, n) {
|
|
|
48181
48486
|
return out;
|
|
48182
48487
|
}
|
|
48183
48488
|
function runJs(c) {
|
|
48184
|
-
const
|
|
48489
|
+
const show3 = (f, args) => {
|
|
48185
48490
|
try {
|
|
48186
48491
|
const v = f(...args);
|
|
48187
48492
|
return `= ${typeof v} ${JSON.stringify(v, (k, x) => x === void 0 ? "__undefined__" : Number.isNaN(x) ? "__NaN__" : x)}`;
|
|
@@ -48202,7 +48507,7 @@ function runJs(c) {
|
|
|
48202
48507
|
}
|
|
48203
48508
|
for (const combo of inputs(c.names.length, JS_POOL.length)) {
|
|
48204
48509
|
const args = combo.map((i) => Array.isArray(JS_POOL[i]) ? [...JS_POOL[i]] : JS_POOL[i]);
|
|
48205
|
-
const x =
|
|
48510
|
+
const x = show3(a, args), y = show3(b, args);
|
|
48206
48511
|
if (x !== y) return { result: "different", why: `with ${c.names.map((n, i) => `${n}=${JSON.stringify(args[i])}`).join(", ")}: ${x} before, ${y} after` };
|
|
48207
48512
|
}
|
|
48208
48513
|
return { result: "same", tried: inputs(c.names.length, JS_POOL.length).length };
|
|
@@ -48238,7 +48543,7 @@ function runBehavior(cases, language) {
|
|
|
48238
48543
|
if (language === "typescript" || language === "javascript") return cases.map(runJs);
|
|
48239
48544
|
if (language === "python") {
|
|
48240
48545
|
const payload = JSON.stringify(cases.map((c) => ({ ...c, inputs: inputs(c.names.length, PY_POOL.length) })));
|
|
48241
|
-
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 });
|
|
48242
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"}` }));
|
|
48243
48548
|
return JSON.parse(r.stdout);
|
|
48244
48549
|
}
|
|
@@ -48497,7 +48802,7 @@ function joinRuleParts(parts) {
|
|
|
48497
48802
|
}
|
|
48498
48803
|
|
|
48499
48804
|
// src/passport-fs.mjs
|
|
48500
|
-
var
|
|
48805
|
+
var import_node_child_process5 = require("node:child_process");
|
|
48501
48806
|
var import_node_fs4 = require("node:fs");
|
|
48502
48807
|
var import_node_path5 = require("node:path");
|
|
48503
48808
|
|
|
@@ -48556,7 +48861,7 @@ function assemblePassport({ parts, change = null, runs = [], purpose = null, ext
|
|
|
48556
48861
|
notRead.push({ part: p.name, file: u.file, line: u.line, what: owner ? `${owner.label}: ${u.why}` : u.why });
|
|
48557
48862
|
}
|
|
48558
48863
|
}
|
|
48559
|
-
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);
|
|
48560
48865
|
behavior.sort(order);
|
|
48561
48866
|
effects.sort(order);
|
|
48562
48867
|
notRead.sort(order);
|
|
@@ -48759,7 +49064,7 @@ function renderPassportMarkdown(p) {
|
|
|
48759
49064
|
// src/passport-fs.mjs
|
|
48760
49065
|
var git3 = (dir, args) => {
|
|
48761
49066
|
try {
|
|
48762
|
-
return (0,
|
|
49067
|
+
return (0, import_node_child_process5.execFileSync)("git", ["-C", dir, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 256 * 1024 * 1024 });
|
|
48763
49068
|
} catch {
|
|
48764
49069
|
return null;
|
|
48765
49070
|
}
|
|
@@ -48835,7 +49140,7 @@ function changesSince(root, base2) {
|
|
|
48835
49140
|
const old = c.status === "added" ? null : git3(root, ["show", `${base2}:${c.file}`]);
|
|
48836
49141
|
out.push({ file: c.file.slice(prefix.length), status: c.status, ranges: c.ranges, old: old == null || old.includes("\0") ? null : old });
|
|
48837
49142
|
}
|
|
48838
|
-
return out.sort((a, b) => a.file
|
|
49143
|
+
return out.sort((a, b) => byText(a.file, b.file));
|
|
48839
49144
|
}
|
|
48840
49145
|
function accessEvidence(report, partOf = () => null) {
|
|
48841
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" };
|
|
@@ -48888,7 +49193,7 @@ function buildPassport({ parts, base: base2 = null, head = null, run = [], purpo
|
|
|
48888
49193
|
const part = m && read.find((p) => p.name === m[1]) ? m[1] : null;
|
|
48889
49194
|
const command = part ? m[2] : String(spec);
|
|
48890
49195
|
const cwd = part ? read.find((p) => p.name === part).root : process.cwd();
|
|
48891
|
-
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 });
|
|
48892
49197
|
const exitCode = r.status ?? (r.error || r.signal ? 1 : 0);
|
|
48893
49198
|
const output = `${r.stdout ?? ""}${r.error ? `
|
|
48894
49199
|
(${r.error.message})` : ""}${r.signal ? `
|