@skillstech/thunderlang 1.8.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -1
- package/README.md +5 -0
- package/dist/core.cjs +73 -25
- package/dist/index.cjs +1230 -519
- package/dist/learn.cjs +89 -32
- package/package.json +17 -15
- package/src/cli-main.mjs +186 -151
- package/src/core/ThunderRuntime.cs +22 -1
- package/src/core/check.mjs +8 -0
- package/src/core/engine-core.mjs +7 -0
- package/src/core/engine-values.mjs +2 -0
- package/src/core/from-python.mjs +1 -1
- package/src/core/go-run.mjs +3 -1
- package/src/core/index.mjs +7 -2
- package/src/core/java/thunder/ThunderRuntime.java +1 -0
- package/src/core/kind.mjs +3 -0
- package/src/core/parser.mjs +22 -21
- package/src/core/project.mjs +21 -0
- package/src/core/runtime-go/thunder_runtime.go +41 -1
- package/src/core/rust/thunder_runtime.rs +1 -0
- package/src/core/target-csharp.mjs +14 -0
- package/src/core/target-go.mjs +14 -0
- package/src/core/target-java.mjs +14 -0
- package/src/core/target-python.mjs +8 -0
- package/src/core/target-rust.mjs +14 -0
- package/src/core/target-typescript.mjs +14 -0
- package/src/core-changes-fs.mjs +1 -1
- package/src/emit.mjs +3 -3
- package/src/evidence-words.d.mts +6 -0
- package/src/evidence-words.mjs +47 -0
- package/src/evidence.mjs +8 -1
- package/src/index.d.ts +15 -0
- package/src/index.mjs +4 -1
- package/src/learn-lessons.mjs +1 -1
- package/src/lsp.mjs +110 -0
- package/src/mcp.mjs +5 -9
- package/src/obligations.d.mts +5 -0
- package/src/obligations.mjs +30 -2
- package/src/program.d.mts +3 -0
- package/src/program.mjs +3 -0
- package/src/review.mjs +6 -3
- package/src/same.mjs +16 -6
- package/src/scan-queries.mjs +2 -1
- package/src/symbols.d.mts +23 -0
- package/src/symbols.mjs +351 -0
- package/src/template.d.mts +31 -0
- package/src/template.mjs +189 -0
package/src/index.mjs
CHANGED
|
@@ -189,7 +189,8 @@ export { startLspServer } from "./lsp.mjs";
|
|
|
189
189
|
// Formatter , canonical .intent formatting (whitespace only)
|
|
190
190
|
export { formatSource, isFormatted } from "./format.mjs";
|
|
191
191
|
|
|
192
|
-
export { resolveObligations } from './obligations.mjs';
|
|
192
|
+
export { resolveObligations, CLAIM_STATUS, claimStatus } from './obligations.mjs';
|
|
193
|
+
export { EVIDENCE_LEVELS, EVIDENCE_WORDS, evidenceWord, evidenceMeaning, combineEvidence } from './evidence-words.mjs';
|
|
193
194
|
// Read code you don't know: one file, a whole repository, files from disk, and promotion of a recovered decision
|
|
194
195
|
// into a contract with edge-case examples.
|
|
195
196
|
export { readCode, searchReading, detectLanguage, READ_SCHEMA, READ_LANGUAGES } from "./read.mjs";
|
|
@@ -208,6 +209,8 @@ export { promoteDecision, PROMOTE_SCHEMA } from "./promote.mjs";
|
|
|
208
209
|
export { WRITE_SCHEMA, writeRule, changedCases, ruleParts, joinRuleParts, COMPARISON_CHOICES } from "./write.mjs";
|
|
209
210
|
export { WRITE_STEPS_SCHEMA, WRITE_STEPS_LANGUAGES, EDIT_OPS, thunderWrite, proveChange, describeEdit, unifiedDiff } from "./write-steps.mjs";
|
|
210
211
|
export { examplesOf, EXAMPLES_SCHEMA } from "./examples.mjs";
|
|
212
|
+
export { templateOf, TEMPLATE_SCHEMA } from "./template.mjs";
|
|
213
|
+
export { symbolAt, definitionsAt, referencesAt, renameAt, applyRename } from "./symbols.mjs";
|
|
211
214
|
export { coreChanges, affectedBy, CORE_CHANGES_SCHEMA, AFFECTED_SCHEMA } from "./core-changes.mjs";
|
|
212
215
|
export { withCoreBehaviour } from "./core-changes.mjs";
|
|
213
216
|
export { coreServiceFacts } from "./core-services.mjs";
|
package/src/learn-lessons.mjs
CHANGED
|
@@ -837,7 +837,7 @@ export const WRITE_LESSONS = [
|
|
|
837
837
|
explain: "Only the web tests depended on shipping.ts. Billing's claim depended on receipt.py, which did not change, so it stays current. Nothing is re-run: check compares fingerprints.",
|
|
838
838
|
check: ({ passportCheck }) => { const c = passportCheck({ 'web/shipping.ts': SHIP_WEB.replace('50', '45') }); const stale = c.items.filter((i) => i.freshness === 'stale'); return stale.length === 2 ? 'Both' : /in web/.test(stale[0]?.claim) ? 'The web test run' : 'The billing test run'; } },
|
|
839
839
|
{ prompt: "Every test passed. Does the passport say the change works in production?", choices: ["No: deployment is always listed as not verified", "Yes"], expect: "No: deployment is always listed as not verified",
|
|
840
|
-
explain: "Tests
|
|
840
|
+
explain: "Tests show what they ran, on the machine they ran on. How it is deployed, real outside services, more than one machine, and heavy load are listed as not verified unless a claim covers them.",
|
|
841
841
|
check: ({ passport }) => (passport.unknowns.notVerified.some((x) => /^Deployment/.test(x)) ? 'No: deployment is always listed as not verified' : 'Yes') },
|
|
842
842
|
],
|
|
843
843
|
questions: [
|
package/src/lsp.mjs
CHANGED
|
@@ -2,11 +2,61 @@
|
|
|
2
2
|
// diagnostics + IntelliSense so ANY LSP-capable editor (VS Code, Neovim, Helix, ...) gets
|
|
3
3
|
// live ThunderLang intelligence: diagnostics on open/change, keyword/type completions, and
|
|
4
4
|
// hover docs for semantic types and note lenses. Deterministic; no AI. `thunder lsp` starts it.
|
|
5
|
+
//
|
|
6
|
+
// Go to definition, find references, and rename (src/symbols.mjs) work in Thunder Core programs and missions. For
|
|
7
|
+
// a Core program in a project (a folder with thunder.toml), every .thunder file of the project is read, with the
|
|
8
|
+
// editor's unsaved text in place of what is on disk, so a function's references include its tests. Core programs
|
|
9
|
+
// get the Core compiler's diagnostics, at their own lines; missions keep the mission checks.
|
|
5
10
|
|
|
6
11
|
import { parseIntent } from './parse.mjs';
|
|
7
12
|
import { semanticDiagnostics } from './emit.mjs';
|
|
8
13
|
import { getCompletions, getHover } from './intellisense.mjs';
|
|
9
14
|
import { COMPILER_VERSION } from './emit.mjs';
|
|
15
|
+
import { symbolIndex, symbolAt, renameAt } from './symbols.mjs';
|
|
16
|
+
import { fileKind } from './core/kind.mjs';
|
|
17
|
+
import { findProjectRoot } from './core/project-root.mjs';
|
|
18
|
+
import { coreFilesIn } from './core-changes-fs.mjs';
|
|
19
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
20
|
+
import { relative, join, basename, sep } from 'node:path';
|
|
21
|
+
|
|
22
|
+
const isCoreText = (uri, text) => /\.thunder$/i.test(uri) && fileKind(text).kind === 'program';
|
|
23
|
+
const pathOf = (uri) => { try { return fileURLToPath(uri); } catch { return null; } };
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The files a request about `uri` needs: for a Core program in a project, every .thunder file of the project
|
|
27
|
+
* (open documents in place of their saved text); otherwise the document alone. Paths are relative to `base`.
|
|
28
|
+
*/
|
|
29
|
+
function workspaceFor(uri, docs) {
|
|
30
|
+
const text = docs.get(uri) ?? '';
|
|
31
|
+
const file = pathOf(uri);
|
|
32
|
+
const root = file && isCoreText(uri, text) ? findProjectRoot(file) : null;
|
|
33
|
+
if (!root) {
|
|
34
|
+
const path = file ? basename(file) : uri;
|
|
35
|
+
return { files: [{ path, source: text }], path, uriOf: (p) => (p === path ? uri : null) };
|
|
36
|
+
}
|
|
37
|
+
const open = new Map([...docs].map(([u, t]) => [pathOf(u), t]).filter(([p]) => p));
|
|
38
|
+
let files = [];
|
|
39
|
+
try { files = coreFilesIn(root, root); } catch { files = []; }
|
|
40
|
+
files = files.map((f) => ({ ...f, source: open.get(join(root, f.path)) ?? f.source }));
|
|
41
|
+
const path = relative(root, file).split(sep).join('/');
|
|
42
|
+
if (!files.some((f) => f.path === path)) files.push({ path, source: text });
|
|
43
|
+
return { files, path, uriOf: (p) => pathToFileURL(join(root, p)).href };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const range = (o) => ({ start: { line: o.line - 1, character: o.col - 1 }, end: { line: o.line - 1, character: o.col - 1 + o.length } });
|
|
47
|
+
|
|
48
|
+
function toCoreDiagnostic(d, lines) {
|
|
49
|
+
const line = Math.max(0, (d.line ?? 1) - 1);
|
|
50
|
+
const text = lines[line] ?? '';
|
|
51
|
+
const start = d.hole?.col ? d.hole.col - 1 : Math.max(0, text.length - text.trimStart().length);
|
|
52
|
+
return {
|
|
53
|
+
range: { start: { line, character: start }, end: { line, character: Math.max(start + 1, text.length) } },
|
|
54
|
+
severity: d.severity === 'warning' ? 2 : 1,
|
|
55
|
+
code: d.code,
|
|
56
|
+
source: 'thunder',
|
|
57
|
+
message: d.message + (d.hint ? `\n\n${d.hint}` : ''),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
10
60
|
|
|
11
61
|
// LSP CompletionItemKind numbers for the kinds IntelliSense returns.
|
|
12
62
|
const COMPLETION_KIND = { keyword: 14, semantic_type: 7, field: 5, snippet: 15, value: 12, block: 14 };
|
|
@@ -68,10 +118,22 @@ export function startLspServer({ readable = process.stdin, writable = process.st
|
|
|
68
118
|
writable.write(payload);
|
|
69
119
|
};
|
|
70
120
|
const respond = (id, result) => send({ jsonrpc: '2.0', id, result });
|
|
121
|
+
// A request Thunder answers with a reason instead of a result (a rename it refuses): the editor shows the message.
|
|
122
|
+
const refuse = (id, message) => send({ jsonrpc: '2.0', id, error: { code: -32803, message } });
|
|
71
123
|
const notify = (method, params) => send({ jsonrpc: '2.0', method, params });
|
|
72
124
|
|
|
73
125
|
const publish = (uri) => {
|
|
74
126
|
const lines = (docs.get(uri) || '').split('\n');
|
|
127
|
+
if (isCoreText(uri, docs.get(uri) || '')) {
|
|
128
|
+
let diags = [];
|
|
129
|
+
try {
|
|
130
|
+
const w = workspaceFor(uri, docs);
|
|
131
|
+
const r = symbolIndex(w.files).results.find((x) => x.path === w.path);
|
|
132
|
+
diags = (r?.diagnostics ?? []).map((d) => toCoreDiagnostic(d, lines));
|
|
133
|
+
} catch { diags = []; }
|
|
134
|
+
notify('textDocument/publishDiagnostics', { uri, diagnostics: diags });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
75
137
|
let diags;
|
|
76
138
|
try { diags = semanticDiagnostics(parseIntent(docs.get(uri) || '')); } catch { diags = []; }
|
|
77
139
|
notify('textDocument/publishDiagnostics', { uri, diagnostics: diags.map((d) => toLspDiagnostic(d, lines)) });
|
|
@@ -85,6 +147,9 @@ export function startLspServer({ readable = process.stdin, writable = process.st
|
|
|
85
147
|
textDocumentSync: 1, // full document sync
|
|
86
148
|
completionProvider: { triggerCharacters: [' '] },
|
|
87
149
|
hoverProvider: true,
|
|
150
|
+
definitionProvider: true,
|
|
151
|
+
referencesProvider: true,
|
|
152
|
+
renameProvider: { prepareProvider: true },
|
|
88
153
|
},
|
|
89
154
|
serverInfo: { name: 'thunderlang-lsp', version: COMPILER_VERSION },
|
|
90
155
|
});
|
|
@@ -126,6 +191,51 @@ export function startLspServer({ readable = process.stdin, writable = process.st
|
|
|
126
191
|
respond(msg.id, hover);
|
|
127
192
|
break;
|
|
128
193
|
}
|
|
194
|
+
case 'textDocument/definition':
|
|
195
|
+
case 'textDocument/references': {
|
|
196
|
+
const uri = msg.params.textDocument.uri;
|
|
197
|
+
const p = msg.params.position;
|
|
198
|
+
let out = [];
|
|
199
|
+
try {
|
|
200
|
+
const w = workspaceFor(uri, docs);
|
|
201
|
+
const s = symbolAt(w.files, w.path, { line: p.line + 1, col: p.character + 1 });
|
|
202
|
+
const list = !s ? [] : msg.method === 'textDocument/definition' ? s.definitions
|
|
203
|
+
: s.references.filter((o) => msg.params.context?.includeDeclaration !== false || !o.def);
|
|
204
|
+
out = list.map((o) => ({ uri: w.uriOf(o.path), range: range(o) })).filter((l) => l.uri);
|
|
205
|
+
} catch { out = []; }
|
|
206
|
+
respond(msg.id, out);
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case 'textDocument/prepareRename': {
|
|
210
|
+
const uri = msg.params.textDocument.uri;
|
|
211
|
+
const p = msg.params.position;
|
|
212
|
+
try {
|
|
213
|
+
const w = workspaceFor(uri, docs);
|
|
214
|
+
const s = symbolAt(w.files, w.path, { line: p.line + 1, col: p.character + 1 });
|
|
215
|
+
if (!s) { refuse(msg.id, 'There is no name here that Thunder can rename: put the cursor on a function, data type, alternative, value, or input (in a mission: a decision, rule, field, or other named block).'); break; }
|
|
216
|
+
const endpoint = s.references.find((o) => o.endpoint)?.endpoint;
|
|
217
|
+
if (endpoint) { refuse(msg.id, `${s.at.written} is what callers send to ${endpoint}, so renaming it here would change the API.`); break; }
|
|
218
|
+
respond(msg.id, { range: range(s.at), placeholder: s.at.written });
|
|
219
|
+
} catch { respond(msg.id, null); }
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
case 'textDocument/rename': {
|
|
223
|
+
const uri = msg.params.textDocument.uri;
|
|
224
|
+
const p = msg.params.position;
|
|
225
|
+
try {
|
|
226
|
+
const w = workspaceFor(uri, docs);
|
|
227
|
+
const r = renameAt(w.files, w.path, { line: p.line + 1, col: p.character + 1 }, msg.params.newName);
|
|
228
|
+
if (!r.ok) { refuse(msg.id, r.problem); break; }
|
|
229
|
+
const changes = {};
|
|
230
|
+
for (const e of r.edits) {
|
|
231
|
+
const u = w.uriOf(e.path);
|
|
232
|
+
if (!u) continue;
|
|
233
|
+
(changes[u] ??= []).push({ range: range(e), newText: e.newText });
|
|
234
|
+
}
|
|
235
|
+
respond(msg.id, { changes });
|
|
236
|
+
} catch (e) { refuse(msg.id, `Thunder could not rename this: ${e.message}`); }
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
129
239
|
default:
|
|
130
240
|
if (msg.id != null) respond(msg.id, null); // unknown request -> empty result, keep alive
|
|
131
241
|
}
|
package/src/mcp.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import { sha256 } from './hash.mjs';
|
|
|
16
16
|
import { verifyDiff } from './verify-diff.mjs';
|
|
17
17
|
import { liftSource, SUPPORTED_LANGUAGES } from './lift.mjs';
|
|
18
18
|
import { runTests } from './testing.mjs';
|
|
19
|
-
import { resolveObligations } from './obligations.mjs';
|
|
19
|
+
import { resolveObligations, foldObligations } from './obligations.mjs';
|
|
20
20
|
import { buildReviewAtlas, renderReviewBrief, reviewAtlasExitCode } from './review-atlas.mjs';
|
|
21
21
|
import { evaluateDecision } from './runtime.mjs';
|
|
22
22
|
import { buildTrace, traceImpact, traceImpactOf, renderImpact } from './trace.mjs';
|
|
@@ -94,7 +94,7 @@ const TOOLS = [
|
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
96
|
name: 'intent_verify_diff',
|
|
97
|
-
description: 'THE AI-LOOP GATE.
|
|
97
|
+
description: 'THE AI-LOOP GATE. Check, deterministically, which of an intent\'s guarantees and never-rules a code change upholds or breaks, by matching patterns in the code (a check, not a proof; tests and people still own correctness). Returns verdict PASS or BLOCK. Blocks on regressions (a claim that held on `before` and broke on `after`) and guardrail hits (an added line pushing a protected secret into a log/response). Call this on your own proposed change before shipping it.',
|
|
98
98
|
inputSchema: {
|
|
99
99
|
type: 'object', required: ['intent', 'after'],
|
|
100
100
|
properties: {
|
|
@@ -108,7 +108,7 @@ const TOOLS = [
|
|
|
108
108
|
},
|
|
109
109
|
{
|
|
110
110
|
name: 'intent_prove',
|
|
111
|
-
description: 'Emit the durable intent-proof-v1 artifact for .intent source: per-claim verdicts (verified / failed / planned / needs_verification, each bound to the named test that
|
|
111
|
+
description: 'Emit the durable intent-proof-v1 artifact for .intent source: per-claim verdicts (verified / failed / planned / needs_verification, each bound to the named test that checks it, with its evidence word: Tested, Partially checked, Unverified, or Violated) plus the freshness tuple (intent hash, compiler version, commit, dependency lockfile) that lets `thunder verify` mark the proof STALE later. Mirrors `thunder prove`; an unverified claim never reads as passed. Call it after the gate passes to record what was checked, and how.',
|
|
112
112
|
inputSchema: {
|
|
113
113
|
type: 'object', required: ['source'],
|
|
114
114
|
properties: {
|
|
@@ -131,11 +131,7 @@ const TOOLS = [
|
|
|
131
131
|
generatedAt: new Date().toISOString(),
|
|
132
132
|
});
|
|
133
133
|
// Fold per-claim verdicts into the proof so it records real status, not just planned/needs_verification.
|
|
134
|
-
|
|
135
|
-
const byId = new Map(resolved.obligations.map((o) => [o.id, o]));
|
|
136
|
-
const applyStatus = (claim) => { const o = byId.get(claim.id); return o ? { ...claim, status: CLAIM_MAP[o.status], provenBy: o.provenBy || null } : claim; };
|
|
137
|
-
proof.guarantees = proof.guarantees.map(applyStatus);
|
|
138
|
-
proof.neverRules = proof.neverRules.map(applyStatus);
|
|
134
|
+
foldObligations(proof, resolved);
|
|
139
135
|
proof.freshness = proofFreshness(proof, environment);
|
|
140
136
|
const ok = proof.verification.semanticPassed && resolved.tests.ok !== false && resolved.failed === 0;
|
|
141
137
|
return { ok, proofId: `proof-${proof.sourceHash.replace('sha256:', '').slice(0, 6)}`, ...proof, tests: resolved.tests };
|
|
@@ -207,7 +203,7 @@ const TOOLS = [
|
|
|
207
203
|
},
|
|
208
204
|
{
|
|
209
205
|
name: 'intent_test',
|
|
210
|
-
description: 'Run the in-file test blocks (case/scenario) in .intent source through the deterministic runtime.
|
|
206
|
+
description: 'Run the in-file test blocks (case/scenario) in .intent source through the deterministic runtime. A passing case is Tested evidence for its own inputs, not a proof of every input.',
|
|
211
207
|
inputSchema: { type: 'object', required: ['source'], properties: { source: str } },
|
|
212
208
|
run: ({ source }) => runTests(parseIntent(String(source))),
|
|
213
209
|
},
|
package/src/obligations.d.mts
CHANGED
|
@@ -6,4 +6,9 @@ export function resolveObligations(ast: unknown): {
|
|
|
6
6
|
declared: number;
|
|
7
7
|
unverified: number;
|
|
8
8
|
failed: number;
|
|
9
|
+
evidence: { tested: number; partial: number; unverified: number; violated: number };
|
|
9
10
|
};
|
|
11
|
+
export const CLAIM_STATUS: Record<string, string>;
|
|
12
|
+
export function claimStatus(status: string): 'verified' | 'failed' | 'planned' | 'needs_verification';
|
|
13
|
+
/** Fold resolved obligations into an intent-proof-v1 artifact, in place: status, provenBy, evidenceLevel, evidenceWord per claim. */
|
|
14
|
+
export function foldObligations<P>(proof: P, resolved: ReturnType<typeof resolveObligations>): P;
|
package/src/obligations.mjs
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
import { runTests } from './testing.mjs';
|
|
2
|
+
import { combineEvidence, evidenceWord } from './evidence-words.mjs';
|
|
3
|
+
|
|
4
|
+
/** The intent-proof-v1 claim status for an obligation status: one table for the CLI, MCP, and the website. */
|
|
5
|
+
export const CLAIM_STATUS = { verified: 'verified', failed: 'failed', declared: 'planned', unverified: 'needs_verification' };
|
|
6
|
+
export const claimStatus = (status) => CLAIM_STATUS[status] ?? 'needs_verification';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Fold resolved obligations into an intent-proof-v1 artifact (in place): each claim gets its real status, the names
|
|
10
|
+
* of the tests that ran for it, and its evidence word. Claims are matched by id, then by order.
|
|
11
|
+
*/
|
|
12
|
+
export function foldObligations(proof, resolved) {
|
|
13
|
+
const byId = new Map(resolved.obligations.filter((o) => o.id).map((o) => [o.id, o]));
|
|
14
|
+
const fold = (claims, kind) => {
|
|
15
|
+
const ofKind = resolved.obligations.filter((o) => o.kind === kind);
|
|
16
|
+
return claims.map((claim, i) => {
|
|
17
|
+
const o = (claim.id && byId.get(claim.id)) || ofKind[i];
|
|
18
|
+
return o ? { ...claim, status: claimStatus(o.status), provenBy: o.provenBy || null, evidenceLevel: o.evidenceLevel, evidenceWord: o.evidenceWord } : claim;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
proof.guarantees = fold(proof.guarantees, 'guarantee');
|
|
22
|
+
proof.neverRules = fold(proof.neverRules, 'prohibition');
|
|
23
|
+
return proof;
|
|
24
|
+
}
|
|
2
25
|
|
|
3
26
|
// One binding policy for CLI, MCP, website, and embedding products. A reference
|
|
4
27
|
// names a complete test target, not a substring, prose description, or similar name.
|
|
@@ -19,8 +42,11 @@ export function resolveObligations(ast) {
|
|
|
19
42
|
const status = !names.length ? 'unverified'
|
|
20
43
|
: evidence.some((e) => e.pass === false) ? 'failed'
|
|
21
44
|
: unresolved.length ? 'declared' : 'verified';
|
|
45
|
+
// The evidence word (src/evidence-words.mjs): passing named cases are Tested, never Proven; a failed one is
|
|
46
|
+
// Violated; some named cases that ran and some that can't run here is Partially checked.
|
|
47
|
+
const evidenceLevel = combineEvidence(evidence.map((e) => (e.pass === true ? 'tested' : e.pass === false ? 'violated' : 'unverified')));
|
|
22
48
|
return {
|
|
23
|
-
kind, id: claim.id, text: claim.statement, status, verify,
|
|
49
|
+
kind, id: claim.id, text: claim.statement, status, evidenceLevel, evidenceWord: evidenceWord(evidenceLevel), verify,
|
|
24
50
|
kinds: [...new Set((claim.verifications || []).map((v) => v.kind).filter((k) => k && k !== 'unclassified'))],
|
|
25
51
|
provenBy: status === 'verified' || status === 'failed' ? evidence.filter((e) => e.pass !== null).map((e) => e.name).join(', ') : null,
|
|
26
52
|
evidence, unresolved,
|
|
@@ -31,5 +57,7 @@ export function resolveObligations(ast) {
|
|
|
31
57
|
...(ast.neverRules || []).map((n) => build('prohibition', n)),
|
|
32
58
|
];
|
|
33
59
|
const count = (s) => obligations.filter((o) => o.status === s).length;
|
|
34
|
-
|
|
60
|
+
const byLevel = (l) => obligations.filter((o) => o.evidenceLevel === l).length;
|
|
61
|
+
return { obligations, tests, verified: count('verified'), declared: count('declared'), unverified: count('unverified'), failed: count('failed'),
|
|
62
|
+
evidence: { tested: byLevel('tested'), partial: byLevel('partial'), unverified: byLevel('unverified'), violated: byLevel('violated') } };
|
|
35
63
|
}
|
package/src/program.d.mts
CHANGED
|
@@ -30,6 +30,9 @@ export function toReact(program: unknown, info: unknown, options?: { source?: st
|
|
|
30
30
|
export function hasScreens(info: unknown): boolean;
|
|
31
31
|
export function pythonToCore(source: string): { core: string; functions: Array<{ name: string; exact: boolean }>; [k: string]: unknown };
|
|
32
32
|
export { examplesOf, EXAMPLES_SCHEMA, type ThunderExample, type ThunderExamples } from './examples.mjs';
|
|
33
|
+
export { templateOf, TEMPLATE_SCHEMA, type ThunderTemplate, type ThunderTemplateField, type ThunderTemplateMissing } from './template.mjs';
|
|
34
|
+
export { EVIDENCE_LEVELS, EVIDENCE_WORDS, evidenceWord, evidenceMeaning, combineEvidence } from './evidence-words.mjs';
|
|
35
|
+
export { symbolAt, definitionsAt, referencesAt, renameAt, applyRename, type ThunderFile, type ThunderLocation, type ThunderSymbol, type ThunderRename } from './symbols.mjs';
|
|
33
36
|
export { coreChanges, affectedBy, CORE_CHANGES_SCHEMA, AFFECTED_SCHEMA, type CoreChanges, type CoreChange, type Affected } from './core-changes.mjs';
|
|
34
37
|
export { withCoreBehaviour } from './core-changes.mjs';
|
|
35
38
|
export { coreServiceFacts } from './core-services.mjs';
|
package/src/program.mjs
CHANGED
|
@@ -13,6 +13,9 @@ export { toRust } from './core/target-rust.mjs';
|
|
|
13
13
|
export { toReact, hasScreens } from './core/target-react.mjs';
|
|
14
14
|
export { pythonToCore } from './core/from-python.mjs';
|
|
15
15
|
export { examplesOf, EXAMPLES_SCHEMA } from './examples.mjs';
|
|
16
|
+
export { templateOf, TEMPLATE_SCHEMA } from './template.mjs';
|
|
17
|
+
export { EVIDENCE_LEVELS, EVIDENCE_WORDS, evidenceWord, evidenceMeaning, combineEvidence } from './evidence-words.mjs';
|
|
18
|
+
export { symbolAt, definitionsAt, referencesAt, renameAt, applyRename } from './symbols.mjs';
|
|
16
19
|
export { coreChanges, affectedBy, CORE_CHANGES_SCHEMA, AFFECTED_SCHEMA } from './core-changes.mjs';
|
|
17
20
|
export { withCoreBehaviour } from './core-changes.mjs';
|
|
18
21
|
export { coreServiceFacts } from './core-services.mjs';
|
package/src/review.mjs
CHANGED
|
@@ -412,7 +412,10 @@ function compareMember(o, n, items, { extracted = false } = {}) {
|
|
|
412
412
|
if (o.m.rule && n.m.rule && !o.m.rule.partial && !n.m.rule.partial) {
|
|
413
413
|
const r = comparePlainRules(o.m.rule, n.m.rule);
|
|
414
414
|
if (r.same) {
|
|
415
|
-
|
|
415
|
+
// Not "only the form": the code changed and the answers matched where they were tried. That is Tested evidence
|
|
416
|
+
// (docs/evidence-words.md), so it says how many cases, and that other inputs were not tried.
|
|
417
|
+
items.push(item(renamedOrMoved.length ? moveKind : 'form', 'form', subject, whereOf(n),
|
|
418
|
+
`${renamedOrMoved.length ? `${cap(renamedOrMoved.join(' and '))}. ` : ''}The code changed, but the answers are the same: Tested on ${r.capped ? `the first ${r.tried} of ${r.total}` : `all ${r.tried}`} edge cases, run on both versions (not every input).`));
|
|
416
419
|
return 'form';
|
|
417
420
|
}
|
|
418
421
|
noteMove();
|
|
@@ -744,7 +747,7 @@ function evidenceBlock(ev) {
|
|
|
744
747
|
/** The review as Markdown for a pull request comment, starting with REVIEW_MARKER so a bot can find and update it. */
|
|
745
748
|
export function renderReview(r, { title = 'Thunder review', maxChars = 60000, footer = '' } = {}) {
|
|
746
749
|
const out = [REVIEW_MARKER, `### ${title}`, '', `**${r.says}**`, ''];
|
|
747
|
-
out.push('Read from the code by the Thunder compiler, with no AI. "Only the form changed" is said only when it is shown: the code is identical apart from spacing, comments, or names it declares itself
|
|
750
|
+
out.push('Read from the code by the Thunder compiler, with no AI. "Only the form changed" is said only when it is shown: the code is identical apart from spacing, comments, or names it declares itself. A rule whose code changed but whose answers match on every edge case tried is listed here too, marked Tested: other inputs were not tried.', '');
|
|
748
751
|
const alsoIn = (x) => (x.also?.length ? [` <details><summary>Also in ${x.also.length} more</summary>`, '', ...x.also.slice(0, 50).map((a) => ` - **${a.subject}** · \`${a.where.file}:${a.where.line}\``), ...(x.also.length > 50 ? [` - and ${x.also.length - 50} more`] : []), '', ' </details>'] : []);
|
|
749
752
|
const line = (x) => [`- **${x.subject}** · \`${x.where.file}:${x.where.line}\`: ${x.says}`, ...evidenceBlock(x.evidence).map((l) => (l ? ` ${l}` : '')), ...alsoIn(x)];
|
|
750
753
|
const section = (sev, head) => {
|
|
@@ -757,7 +760,7 @@ export function renderReview(r, { title = 'Thunder review', maxChars = 60000, fo
|
|
|
757
760
|
};
|
|
758
761
|
section('risk', 'Needs a careful look');
|
|
759
762
|
section('meaning', 'Changes in meaning');
|
|
760
|
-
section('form', 'Only the form changed');
|
|
763
|
+
section('form', 'Only the form changed, or the same answers where tested');
|
|
761
764
|
if (r.notRead.length) out.push(`Also changed, not read by Thunder: ${r.notRead.slice(0, 20).map((f) => `\`${f.path}\``).join(', ')}${r.notRead.length > 20 ? `, and ${r.notRead.length - 20} more` : ''}.`, '');
|
|
762
765
|
if (footer) out.push(footer, '');
|
|
763
766
|
let text = out.join('\n');
|
package/src/same.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// functions by name, and compares their Thunder. Rules are compared by RUNNING both on the same inputs (every edge
|
|
3
3
|
// value either rule mentions), not by comparing text, so a rewritten condition that gives the same answers counts as
|
|
4
4
|
// the same, and a changed limit is caught with a counterexample. Browser-safe: takes [{ path, source }].
|
|
5
|
+
import { combineEvidence, evidenceWord } from './evidence-words.mjs';
|
|
5
6
|
import { readCode } from './read.mjs';
|
|
6
7
|
import { readableLanguage, readingOf } from './read-repo.mjs';
|
|
7
8
|
import { plainFromReading, explainPlain } from './plain-contract.mjs';
|
|
@@ -86,12 +87,14 @@ export function comparePlainRules(a, b) {
|
|
|
86
87
|
}
|
|
87
88
|
const bAsA = { ...b, inputs: b.inputs.map((i) => ({ ...i, id: toA.get(key(i)) })), rules: b.rules.map((r) => ({ ...r, conditions: r.conditions.map((c) => ({ ...c, input: toA.get(key(b.inputs.find((i) => i.id === c.input))) })) })) };
|
|
88
89
|
let tried = 0;
|
|
89
|
-
|
|
90
|
+
const axes = caseValues([a, bAsA]);
|
|
91
|
+
const total = axes.reduce((n, [, vs]) => n * Math.max(1, vs.length), 1);
|
|
92
|
+
for (const values of product(axes)) {
|
|
90
93
|
if (++tried > MAX_CASES) { tried--; break; }
|
|
91
94
|
const x = explainPlain(a, values).outcome, y = explainPlain(bAsA, values).outcome;
|
|
92
95
|
if (x !== y) return { same: false, tried, counterexample: { values: { ...values }, facts: a.inputs.map((i) => `${i.label} ${i.kind === 'yesno' ? (values[i.id] ? i.yes ?? 'yes' : i.no ?? 'no') : values[i.id]}`).join(', '), old: x, new: y } };
|
|
93
96
|
}
|
|
94
|
-
return { same: true, tried };
|
|
97
|
+
return { same: true, tried, total, ...(total > tried ? { capped: true } : {}) };
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
// Each step flattened in reading order: `sig` is what is compared (kind and wording, case- and punctuation-blind),
|
|
@@ -123,7 +126,7 @@ function compareItems(o, n) {
|
|
|
123
126
|
if (o.kind === 'decision') {
|
|
124
127
|
const r = compareRules(o, n);
|
|
125
128
|
if (!r) return { status: 'cannot-check', reason: 'One rule could not be drawn as a card, so its answers could not be compared.', ...where };
|
|
126
|
-
if (r.same) return { status: 'same', reason: `Same answer on all ${r.tried} edge cases.`, ...where };
|
|
129
|
+
if (r.same) return { status: 'same', reason: r.capped ? `Same answer on the first ${r.tried} of ${r.total} edge cases (the rest were not tried).` : `Same answer on all ${r.tried} edge cases.`, ...where };
|
|
127
130
|
if (r.counterexample) {
|
|
128
131
|
const facts = r.counterexample.facts;
|
|
129
132
|
return { status: 'different', reason: `Different answer for ${facts}: ${r.counterexample.old} before, ${r.counterexample.new} after.`, counterexample: r.counterexample, ...where };
|
|
@@ -163,14 +166,21 @@ export function sameMeaning(oldFiles, newFiles) {
|
|
|
163
166
|
}
|
|
164
167
|
for (const [key, n] of B.items) if (!used.has(key)) items.push({ name: n.name, status: 'only-new', reason: 'New: not in the old code.', new: { file: n.file, line: n.line, language: n.language } });
|
|
165
168
|
const counts = { same: 0, different: 0, 'only-old': 0, 'only-new': 0, 'cannot-check': 0 };
|
|
166
|
-
for (const it of items)
|
|
169
|
+
for (const it of items) {
|
|
170
|
+
counts[it.status]++;
|
|
171
|
+
// The evidence word (docs/evidence-words.md): a rule compared by running both on edge cases is Tested; steps whose
|
|
172
|
+
// wording and code match were not run, so only part of the claim is checked; a difference is Violated.
|
|
173
|
+
it.evidence = it.status === 'same' ? (/edge cases/.test(it.reason) ? 'tested' : 'partial') : it.status === 'cannot-check' ? 'unverified' : 'violated';
|
|
174
|
+
}
|
|
167
175
|
const verdict = counts.different || counts['only-old'] || counts['only-new'] ? 'different' : counts['cannot-check'] ? 'partly-checked' : 'same';
|
|
168
|
-
|
|
176
|
+
const evidence = combineEvidence(items.map((it) => it.evidence));
|
|
177
|
+
return { schema: SAME_SCHEMA, verdict, evidence, counts, items, unreadable: [...A.unreadable, ...B.unreadable] };
|
|
169
178
|
}
|
|
170
179
|
|
|
171
180
|
export function renderSame(r) {
|
|
172
181
|
const head = r.verdict === 'same' ? 'Same meaning.' : r.verdict === 'partly-checked' ? 'No differences found, but some parts could not be checked.' : 'Different meaning.';
|
|
173
|
-
const
|
|
182
|
+
const how = r.evidence ? ` ${evidenceWord(r.evidence)}${r.evidence === 'tested' ? ' (answers compared on edge cases, not every input)' : r.evidence === 'partial' ? ' (some parts compared by running, others only by reading)' : ''}.` : '';
|
|
183
|
+
const lines = [`${head}${how} ${r.counts.same} same, ${r.counts.different} different, ${r.counts['only-old']} only in the old code, ${r.counts['only-new']} only in the new code, ${r.counts['cannot-check']} not checked.`];
|
|
174
184
|
const order = ['different', 'only-old', 'only-new', 'cannot-check', 'same'];
|
|
175
185
|
const label = { different: 'different', 'only-old': 'only old', 'only-new': 'only new', 'cannot-check': 'not checked', same: 'same' };
|
|
176
186
|
for (const st of order) for (const it of r.items.filter((x) => x.status === st)) {
|
package/src/scan-queries.mjs
CHANGED
|
@@ -54,7 +54,8 @@ export function unverifiedView(scan) {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
/** Verification coverage: share of guarantees + never-rules that
|
|
57
|
+
/** Verification coverage: share of guarantees + never-rules that NAME a verification. Nothing is run here, so
|
|
58
|
+
* `verified` counts claims with a check named (a declaration), not Tested ones (see docs/evidence-words.md). */
|
|
58
59
|
export function coverageView(scan) {
|
|
59
60
|
const claims = claimNodes(scan);
|
|
60
61
|
const verified = verifiedIds(scan);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ThunderFile { path: string; source: string }
|
|
2
|
+
/** A place in a file: 1-based line and column, and the length of the name as written there. */
|
|
3
|
+
export interface ThunderLocation { path: string; line: number; col: number; length: number }
|
|
4
|
+
export interface ThunderSymbol {
|
|
5
|
+
id: string;
|
|
6
|
+
kind: 'function' | 'type' | 'alternative' | 'value' | 'local' | 'input' | 'mission';
|
|
7
|
+
/** In words: "function", "data type", "input field", "rule", … */
|
|
8
|
+
what: string;
|
|
9
|
+
name: string;
|
|
10
|
+
definitions: ThunderLocation[];
|
|
11
|
+
references: ThunderLocation[];
|
|
12
|
+
}
|
|
13
|
+
export type ThunderRename =
|
|
14
|
+
| { ok: true; symbol: { id: string; kind: string; what: string; name: string }; edits: Array<ThunderLocation & { newText: string }> }
|
|
15
|
+
| { ok: false; problem: string };
|
|
16
|
+
/** The name at a position (1-based line and col), with where it is defined and used, or null. */
|
|
17
|
+
export function symbolAt(files: ThunderFile[], path: string, pos: { line: number; col: number }): (ThunderSymbol & { at: ThunderLocation }) | null;
|
|
18
|
+
export function definitionsAt(files: ThunderFile[], path: string, pos: { line: number; col: number }): ThunderLocation[];
|
|
19
|
+
export function referencesAt(files: ThunderFile[], path: string, pos: { line: number; col: number }, options?: { declaration?: boolean }): ThunderLocation[];
|
|
20
|
+
/** Every edit a rename needs, or why Thunder refuses it. Nothing is changed. */
|
|
21
|
+
export function renameAt(files: ThunderFile[], path: string, pos: { line: number; col: number }, newName: string): ThunderRename;
|
|
22
|
+
export function applyRename(files: ThunderFile[], edits: Array<ThunderLocation & { newText: string }>): ThunderFile[];
|
|
23
|
+
export function symbolIndex(files: ThunderFile[]): { occurrences: Array<ThunderLocation & { id: string; kind: string; name: string; def: boolean }>; results: unknown[] };
|