@skillstech/thunderlang 1.6.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +121 -0
- package/README.md +10 -3
- package/dist/core.cjs +264 -47
- package/dist/index.cjs +9118 -1077
- package/dist/learn.cjs +1419 -90
- package/package.json +1 -1
- package/src/ai.mjs +2 -1
- package/src/atlas.mjs +2 -1
- package/src/behaviour.mjs +246 -0
- package/src/cli-main.mjs +3015 -0
- package/src/cli.mjs +9 -2799
- package/src/conflict.mjs +0 -0
- package/src/core/ThunderDotnet.cs +195 -0
- package/src/core/check.mjs +316 -10
- package/src/core/cli.mjs +67 -10
- package/src/core/csharp-run.mjs +29 -8
- package/src/core/diagnostics.mjs +12 -1
- package/src/core/engine-core.mjs +161 -20
- package/src/core/engine-values.mjs +1 -0
- package/src/core/engine.mjs +131 -7
- package/src/core/go-run.mjs +3 -2
- package/src/core/index.mjs +6 -2
- package/src/core/java-run.mjs +3 -3
- package/src/core/kind.mjs +45 -0
- package/src/core/lexer.mjs +16 -2
- package/src/core/parser.mjs +254 -22
- package/src/core/project-root.mjs +18 -0
- package/src/core/project.mjs +18 -18
- package/src/core/react-run.mjs +3 -3
- package/src/core/runtime-go/thunder_runtime.go +269 -1
- package/src/core/runtime-npm.mjs +79 -0
- package/src/core/runtime-python.mjs +365 -3
- package/src/core/runtime-react.mjs +2 -1
- package/src/core/runtime-typescript.mjs +155 -6
- package/src/core/rust-run.mjs +3 -2
- package/src/core/serving.mjs +12 -0
- package/src/core/store-format.mjs +110 -0
- package/src/core/target-csharp.mjs +5 -1
- package/src/core/target-go.mjs +11 -4
- package/src/core/target-python.mjs +39 -6
- package/src/core/target-rust.mjs +1 -1
- package/src/core/target-typescript.mjs +95 -7
- package/src/core/typescript-run.mjs +14 -7
- package/src/core-changes-fs.mjs +28 -0
- package/src/core-changes.d.mts +67 -0
- package/src/core-changes.mjs +603 -0
- package/src/core-rules.mjs +146 -0
- package/src/core-services.d.mts +4 -0
- package/src/core-services.mjs +49 -0
- package/src/decision.mjs +2 -1
- package/src/distributed.mjs +2 -1
- package/src/emit.mjs +2 -2
- package/src/evidence.mjs +28 -0
- package/src/examples.d.mts +21 -0
- package/src/examples.mjs +175 -0
- package/src/focus.mjs +2 -1
- package/src/index.d.ts +4 -0
- package/src/index.mjs +4 -0
- package/src/intent-atlas.mjs +4 -3
- package/src/mcp.mjs +52 -6
- package/src/passport-fs.mjs +2 -1
- package/src/passport.mjs +2 -1
- package/src/privacy.mjs +2 -1
- package/src/program.d.mts +4 -0
- package/src/program.mjs +4 -0
- package/src/read-repo-fs.mjs +2 -1
- package/src/read-repo.mjs +3 -2
- package/src/report.mjs +3 -2
- package/src/review.mjs +71 -4
- package/src/select.mjs +2 -1
- package/src/semantic-diff.mjs +7 -6
- package/src/system.mjs +3 -2
- package/src/text-order.mjs +6 -0
- package/src/thunderize.mjs +2 -1
- package/src/trace-cli.mjs +8 -3
- package/src/trace-data.mjs +3 -2
- package/src/trace-fs.mjs +29 -3
- package/src/trace.mjs +27 -10
- package/src/write-across-cli.mjs +22 -4
- package/src/write-across.mjs +2 -1
- package/syntaxes/thunder.tmLanguage.json +196 -0
package/src/mcp.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
//
|
|
7
7
|
// Start it with `thunder mcp`. Point an MCP client at that command.
|
|
8
8
|
|
|
9
|
+
import { behaviourCheck } from './behaviour.mjs';
|
|
9
10
|
import { execSync } from 'node:child_process';
|
|
10
11
|
import { existsSync, readFileSync } from 'node:fs';
|
|
11
12
|
import { basename, dirname, join } from 'node:path';
|
|
@@ -19,8 +20,10 @@ import { resolveObligations } from './obligations.mjs';
|
|
|
19
20
|
import { buildReviewAtlas, renderReviewBrief, reviewAtlasExitCode } from './review-atlas.mjs';
|
|
20
21
|
import { evaluateDecision } from './runtime.mjs';
|
|
21
22
|
import { buildTrace, traceImpact, traceImpactOf, renderImpact } from './trace.mjs';
|
|
23
|
+
import { coreChanges, affectedBy, withCoreBehaviour } from './core-changes.mjs';
|
|
24
|
+
import { coreFilesIn } from './core-changes-fs.mjs';
|
|
22
25
|
import { thunderWrite } from './write-steps.mjs';
|
|
23
|
-
import { readRepoDir, gitChanges } from './trace-fs.mjs';
|
|
26
|
+
import { readRepoDir, gitChanges, coreBehaviourOf } from './trace-fs.mjs';
|
|
24
27
|
import { buildIntentGraph } from './intent-graph.mjs';
|
|
25
28
|
import { buildConformance } from './conformance.mjs';
|
|
26
29
|
import { checkDrift } from './drift.mjs';
|
|
@@ -266,7 +269,7 @@ const TOOLS = [
|
|
|
266
269
|
},
|
|
267
270
|
{
|
|
268
271
|
name: 'intent_trace',
|
|
269
|
-
description: 'ASK THUNDER TRACE BEFORE CHANGING CODE THAT OTHER REPOSITORIES USE (local only). Give the repository folders. With "thing" (a route like "POST /api/orders", an event name, "table:orders", "setting:ORDERS_URL", "package:@acme/client", or "repo:file[:line]") or "diff": true (the branch and uncommitted changes), it answers what the change can affect in the OTHER repositories: callers of a changed or removed route, listeners of a published event, code that uses a changed, dropped, or removed table, other readers of a setting, dependents of a published package, ranked high/medium/low, one hop out, every item cited repo@sha:file:line. With neither, it gives the links between the repositories (HTTP, events, tables, packages) and what they share (settings, tables, package versions that differ). Read from code; nothing is run; a call whose address is worked out when it runs is listed as not linked, never guessed.',
|
|
272
|
+
description: 'ASK THUNDER TRACE BEFORE CHANGING CODE THAT OTHER REPOSITORIES USE (local only). Give the repository folders. With "thing" (a route like "POST /api/orders", an event name, "table:orders", "setting:ORDERS_URL", "package:@acme/client", or "repo:file[:line]") or "diff": true (the branch and uncommitted changes), it answers what the change can affect in the OTHER repositories: callers of a changed or removed route (for a Thunder Core endpoint, also when a rule it uses changed, with what changes in its answers: diff runs both versions on the Thunder engine), listeners of a published event, code that uses a changed, dropped, or removed table, other readers of a setting, dependents of a published package, ranked high/medium/low, one hop out, every item cited repo@sha:file:line. With neither, it gives the links between the repositories (HTTP, events, tables, packages) and what they share (settings, tables, package versions that differ). Read from code; nothing is run, apart from changed Thunder Core programs with diff (on the Thunder engine: no files, network, or saved data); a call whose address is worked out when it runs is listed as not linked, never guessed.',
|
|
270
273
|
inputSchema: {
|
|
271
274
|
type: 'object', required: ['paths'],
|
|
272
275
|
properties: {
|
|
@@ -281,23 +284,66 @@ const TOOLS = [
|
|
|
281
284
|
const repos = paths.map((p) => readRepoDir(resolve(String(p))));
|
|
282
285
|
const trace = buildTrace(repos);
|
|
283
286
|
if (!thing && !diff) return { trace };
|
|
284
|
-
const r =
|
|
287
|
+
if (thing) { const r = traceImpactOf(trace, String(thing)); return { ...r, text: renderImpact(r) }; }
|
|
288
|
+
// With diff, a changed Thunder Core program is also run before and after, to say what changes in its answers.
|
|
289
|
+
const changes = [], behaviour = new Map();
|
|
290
|
+
for (const repo of repos) {
|
|
291
|
+
const g = gitChanges(repo, base);
|
|
292
|
+
changes.push(...g.changes);
|
|
293
|
+
const cc = g.base ? coreBehaviourOf(repo, g) : null;
|
|
294
|
+
if (cc) behaviour.set(repo.name, cc);
|
|
295
|
+
}
|
|
296
|
+
const r = withCoreBehaviour(traceImpact(trace, changes), behaviour);
|
|
285
297
|
return { ...r, text: renderImpact(r) };
|
|
286
298
|
},
|
|
287
299
|
},
|
|
300
|
+
{
|
|
301
|
+
name: 'intent_core_changes',
|
|
302
|
+
description: 'WHAT A CHANGE TO A THUNDER CORE PROGRAM DOES, RULE BY RULE (runs the program). Give both versions of the .thunder files ({ path, source }; include the project\'s tests). Each rule is paired with its other version by a stable name from what it is ("function:decide refund", "keep:review limit", "endpoint:POST /orders", "never:Product: Never allow a negative stock", "test:…"), never by line. A function whose steps changed, or that uses something that changed, is run before and after on the same inputs (made from the numbers and text in both versions, each number with one step either side) and the answers that differ are grouped, with the input that decides them as the range tried: "now a review Refund instead of an approved Refund when amount is from $50.00 to $99.99". Tests that reach a change are run before and after. Each change lists what to look at again (affects). Tested evidence on the inputs tried, not a proof; functions that read saved data or call another service are not run, and say so.',
|
|
303
|
+
inputSchema: {
|
|
304
|
+
type: 'object', required: ['before', 'after'],
|
|
305
|
+
properties: {
|
|
306
|
+
before: { type: 'array', maxItems: 500, items: { type: 'object', required: ['path', 'source'], properties: { path: str, source: str } } },
|
|
307
|
+
after: { type: 'array', maxItems: 500, items: { type: 'object', required: ['path', 'source'], properties: { path: str, source: str } } },
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
run: ({ before, after }) => coreChanges(before ?? [], after ?? []),
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
name: 'intent_affected',
|
|
314
|
+
description: 'WHAT TO LOOK AT AGAIN WHEN A THUNDER CORE RULE CHANGES (read only, nothing is run). Give a Thunder project folder or file (path) or the files themselves, and what changes: a rule\'s name or id ("decide refund", "review limit", "POST /orders", "keep:review limit"), or a list. Answers the functions and endpoints that use it (all the way up, each with the rules in between), the tests and the Expect examples that reach it, and the Never rules and stored lists they rely on, each cited file:line.',
|
|
315
|
+
inputSchema: {
|
|
316
|
+
type: 'object', required: ['change'],
|
|
317
|
+
properties: {
|
|
318
|
+
path: { ...str, description: 'a Thunder project folder or .thunder file' },
|
|
319
|
+
files: { type: 'array', maxItems: 500, items: { type: 'object', required: ['path', 'source'], properties: { path: str, source: str } } },
|
|
320
|
+
change: { description: 'a rule name or id, or a list of them', anyOf: [str, { type: 'array', items: str }] },
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
run: ({ path, files, change }) => {
|
|
324
|
+
if (!path && !files) throw new Error('Give a Thunder project folder or file in "path", or the files in "files".');
|
|
325
|
+
return affectedBy(files ?? coreFilesIn(resolve(String(path))), change);
|
|
326
|
+
},
|
|
327
|
+
},
|
|
288
328
|
{
|
|
289
329
|
name: 'intent_write',
|
|
290
|
-
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 …", "Set … to …", "Stop with \"…\"", 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.',
|
|
330
|
+
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 …", "Set … to …", "Stop with \"…\"", 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.',
|
|
291
331
|
inputSchema: {
|
|
292
332
|
type: 'object', required: ['files', 'edits'],
|
|
293
333
|
properties: {
|
|
294
334
|
files: { type: 'array', minItems: 1, maxItems: 20, items: { type: 'object', required: ['path', 'source'], properties: { path: str, source: str } } },
|
|
295
335
|
edits: { description: 'one Thunder edit object, or a list applied in order', anyOf: [{ type: 'object' }, { type: 'array', items: { type: 'object' } }] },
|
|
336
|
+
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' },
|
|
296
337
|
},
|
|
297
338
|
},
|
|
298
|
-
run: ({ files, edits }) => {
|
|
339
|
+
run: ({ files, edits, behaviour }) => {
|
|
299
340
|
if (!Array.isArray(files) || !files.length) throw new Error('Give the files as [{ path, source }].');
|
|
300
|
-
const
|
|
341
|
+
const given = files.map((f) => ({ path: String(f.path), source: String(f.source) }));
|
|
342
|
+
const r = thunderWrite(given, edits);
|
|
343
|
+
if (behaviour && r.status === 'written') {
|
|
344
|
+
const originals = new Map(given.map((f) => [f.path, f.source]));
|
|
345
|
+
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] }));
|
|
346
|
+
}
|
|
301
347
|
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 } : {}) };
|
|
302
348
|
},
|
|
303
349
|
},
|
package/src/passport-fs.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { basename, join, resolve, relative } from 'node:path';
|
|
|
7
7
|
import { collectReadableFiles } from './read-repo-fs.mjs';
|
|
8
8
|
import { assemblePassport, checkPassport } from './passport.mjs';
|
|
9
9
|
import { COMPILER_VERSION } from './emit.mjs';
|
|
10
|
+
import { byText } from './text-order.mjs';
|
|
10
11
|
|
|
11
12
|
const git = (dir, args) => {
|
|
12
13
|
try { return execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], maxBuffer: 256 * 1024 * 1024 }); } catch { return null; }
|
|
@@ -73,7 +74,7 @@ function changesSince(root, base) {
|
|
|
73
74
|
const old = c.status === 'added' ? null : git(root, ['show', `${base}:${c.file}`]);
|
|
74
75
|
out.push({ file: c.file.slice(prefix.length), status: c.status, ranges: c.ranges, old: old == null || old.includes('\0') ? null : old });
|
|
75
76
|
}
|
|
76
|
-
return out.sort((a, b) => a.file
|
|
77
|
+
return out.sort((a, b) => byText(a.file, b.file));
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
/**
|
package/src/passport.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { sha256 } from './hash.mjs';
|
|
|
10
10
|
import { thunderModel, modelText } from './model.mjs';
|
|
11
11
|
import { buildTrace, isTestFile } from './trace.mjs';
|
|
12
12
|
import { thunderReview } from './review.mjs';
|
|
13
|
+
import { byText } from './text-order.mjs';
|
|
13
14
|
|
|
14
15
|
export const PASSPORT_SCHEMA = 'thunder-passport-v1';
|
|
15
16
|
|
|
@@ -77,7 +78,7 @@ export function assemblePassport({ parts, change = null, runs = [], purpose = nu
|
|
|
77
78
|
notRead.push({ part: p.name, file: u.file, line: u.line, what: owner ? `${owner.label}: ${u.why}` : u.why });
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
|
-
const order = (a, b) => `${a.part}/${a.file}
|
|
81
|
+
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));
|
|
81
82
|
behavior.sort(order); effects.sort(order); notRead.sort(order);
|
|
82
83
|
{ const seen = new Set(); notRead.splice(0, notRead.length, ...notRead.filter((x) => { const k = `${x.part}/${x.file}:${x.line}`; if (seen.has(k)) return false; seen.add(k); return true; })); }
|
|
83
84
|
const shownBehavior = behavior.slice(0, MAX_BEHAVIOR);
|
package/src/privacy.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { byText } from './text-order.mjs';
|
|
1
2
|
// Data purpose + privacy (founder Gap 6). A `data` element declares what a piece of
|
|
2
3
|
// data IS (classification), WHY it is held (purpose), HOW LONG (retention), and on WHAT
|
|
3
4
|
// LAWFUL BASIS. The privacy analysis enforces purpose limitation: sensitive data may not
|
|
@@ -56,6 +57,6 @@ export function analyzePrivacy(ast) {
|
|
|
56
57
|
message: `Sensitive data "${d.path}" is returned as an output with no "never expose" guard.` });
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
out.sort((a, b) => (a.code + a.path)
|
|
60
|
+
out.sort((a, b) => byText((a.code + a.path), b.code + b.path));
|
|
60
61
|
return out;
|
|
61
62
|
}
|
package/src/program.d.mts
CHANGED
|
@@ -29,3 +29,7 @@ export function toRust(program: unknown, info: unknown, options?: { source?: str
|
|
|
29
29
|
export function toReact(program: unknown, info: unknown, options?: { source?: string }): string;
|
|
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
|
+
export { examplesOf, EXAMPLES_SCHEMA, type ThunderExample, type ThunderExamples } from './examples.mjs';
|
|
33
|
+
export { coreChanges, affectedBy, CORE_CHANGES_SCHEMA, AFFECTED_SCHEMA, type CoreChanges, type CoreChange, type Affected } from './core-changes.mjs';
|
|
34
|
+
export { withCoreBehaviour } from './core-changes.mjs';
|
|
35
|
+
export { coreServiceFacts } from './core-services.mjs';
|
package/src/program.mjs
CHANGED
|
@@ -12,3 +12,7 @@ export { toGo, goNamespaces } from './core/target-go.mjs';
|
|
|
12
12
|
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
|
+
export { examplesOf, EXAMPLES_SCHEMA } from './examples.mjs';
|
|
16
|
+
export { coreChanges, affectedBy, CORE_CHANGES_SCHEMA, AFFECTED_SCHEMA } from './core-changes.mjs';
|
|
17
|
+
export { withCoreBehaviour } from './core-changes.mjs';
|
|
18
|
+
export { coreServiceFacts } from './core-services.mjs';
|
package/src/read-repo-fs.mjs
CHANGED
|
@@ -24,7 +24,7 @@ const MANIFEST = /^(go\.mod|package\.json|tsconfig\.json|jsconfig\.json)$/;
|
|
|
24
24
|
*/
|
|
25
25
|
// manifestNames: which manifest files `manifests` brings (Thunder Trace also wants requirements.txt and *.csproj).
|
|
26
26
|
// templates: also bring Angular component templates (*.component.html), which screens read with their component.
|
|
27
|
-
export function collectReadableFiles(root, { maxFiles = 5000, maxFileBytes = 400000, manifests = false, manifestNames = MANIFEST, templates = false } = {}) {
|
|
27
|
+
export function collectReadableFiles(root, { maxFiles = 5000, maxFileBytes = 400000, manifests = false, manifestNames = MANIFEST, templates = false, thunder = false } = {}) {
|
|
28
28
|
const out = [];
|
|
29
29
|
const walk = (dir) => {
|
|
30
30
|
let names;
|
|
@@ -39,6 +39,7 @@ export function collectReadableFiles(root, { maxFiles = 5000, maxFileBytes = 400
|
|
|
39
39
|
if (st.isDirectory()) walk(full);
|
|
40
40
|
else if (manifests && manifestNames.test(name) && st.size <= maxFileBytes) out.push({ path, source: readFileSync(full, 'utf8'), manifest: true });
|
|
41
41
|
else if (templates && /\.component\.html$/i.test(name) && st.size <= maxFileBytes) out.push({ path, source: readFileSync(full, 'utf8'), template: true });
|
|
42
|
+
else if (thunder && /\.thunder$/i.test(name) && st.size <= maxFileBytes) out.push({ path, source: readFileSync(full, 'utf8') }); // Thunder Core programs (Trace)
|
|
42
43
|
else if (readableLanguage(path) || (!name.includes('.') && shebangShell(full, st.size))) {
|
|
43
44
|
// Oversized files are not loaded; readRepo lists them as skipped from their size.
|
|
44
45
|
out.push(st.size > maxFileBytes ? { path, source: '', size: st.size } : { path, source: readFileSync(full, 'utf8') });
|
package/src/read-repo.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// browser from a folder the person picks; nothing is uploaded). Deterministic, no AI.
|
|
7
7
|
import { readCode, looksCpp } from './read.mjs';
|
|
8
8
|
import { readableFormat } from './file-formats.mjs';
|
|
9
|
+
import { byText } from './text-order.mjs';
|
|
9
10
|
|
|
10
11
|
export const READ_REPO_SCHEMA = 'thunder-repo-reading-v1';
|
|
11
12
|
|
|
@@ -131,7 +132,7 @@ function summarize(items, files) {
|
|
|
131
132
|
inputs.get(p.name).push(it.id);
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
|
-
const byUse = (m) => [...m].map(([name, ids]) => ({ name, decisions: ids })).sort((a, b) => b.decisions.length - a.decisions.length || a.name
|
|
135
|
+
const byUse = (m) => [...m].map(([name, ids]) => ({ name, decisions: ids })).sort((a, b) => b.decisions.length - a.decisions.length || byText(a.name, b.name));
|
|
135
136
|
return { files, items, counts, languages, folders, answers: byUse(answers), inputs: byUse(inputs) };
|
|
136
137
|
}
|
|
137
138
|
|
|
@@ -163,7 +164,7 @@ export function groupByFile(items) {
|
|
|
163
164
|
if (!groups.has(it.file)) groups.set(it.file, []);
|
|
164
165
|
groups.get(it.file).push(it);
|
|
165
166
|
}
|
|
166
|
-
return [...groups].sort(([a], [b]) => a
|
|
167
|
+
return [...groups].sort(([a], [b]) => byText(a, b)).map(([file, list]) => ({ file, language: list[0].language, items: list }));
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
/**
|
package/src/report.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { parseIntent } from './parse.mjs';
|
|
8
8
|
import { semanticDiagnostics } from './emit.mjs';
|
|
9
9
|
import { ALL_DIAGNOSTICS } from './intent-schema.mjs';
|
|
10
|
+
import { byText } from './text-order.mjs';
|
|
10
11
|
|
|
11
12
|
export const REPORT_SCHEMA = 'intent-report-v1';
|
|
12
13
|
|
|
@@ -55,7 +56,7 @@ export function buildReport(files) {
|
|
|
55
56
|
perFile.push({ file, mission: ast.mission || null, ...counts, ok: counts.error === 0 });
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
const topCodes = Object.entries(byCode).sort((a, b) => b[1] - a[1] || a[0]
|
|
59
|
+
const topCodes = Object.entries(byCode).sort((a, b) => b[1] - a[1] || byText(a[0], b[0]))
|
|
59
60
|
.slice(0, 10).map(([code, count]) => ({ code, count, area: AREA_OF.get(code) || 'other' }));
|
|
60
61
|
|
|
61
62
|
const totalDiagnostics = Object.values(bySeverity).reduce((a, b) => a + b, 0);
|
|
@@ -79,6 +80,6 @@ export function buildReport(files) {
|
|
|
79
80
|
outcomeContracts,
|
|
80
81
|
outcomeContractRate: pct(outcomeContracts, outcomes),
|
|
81
82
|
},
|
|
82
|
-
files: perFile.sort((a, b) => (b.error - a.error) || (b.warning - a.warning) || a.file
|
|
83
|
+
files: perFile.sort((a, b) => (b.error - a.error) || (b.warning - a.warning) || byText(a.file, b.file)),
|
|
83
84
|
};
|
|
84
85
|
}
|
package/src/review.mjs
CHANGED
|
@@ -11,13 +11,15 @@
|
|
|
11
11
|
import { thunderModel, readLevel, modelText } from './model.mjs';
|
|
12
12
|
import { comparePlainRules, nameKey } from './same.mjs';
|
|
13
13
|
import { readableLanguage } from './read-repo.mjs';
|
|
14
|
+
import { byText } from './text-order.mjs';
|
|
15
|
+
import { isCoreProgram } from './core/kind.mjs';
|
|
14
16
|
|
|
15
17
|
export const REVIEW_SCHEMA = 'thunder-review-v1';
|
|
16
18
|
export const REVIEW_MARKER = '<!-- thunder-review -->';
|
|
17
19
|
|
|
18
20
|
const SEVERITY_ORDER = ['risk', 'meaning', 'form'];
|
|
19
21
|
// Within a severity, what a reviewer should read first.
|
|
20
|
-
const KIND_ORDER = ['unreadable', 'not-read', 'infrastructure', 'stop-removed', 'stop-changed', 'address', 'effect-added', 'stop-added',
|
|
22
|
+
const KIND_ORDER = ['unreadable', 'test-fails', 'callers', 'not-read', 'infrastructure', 'stop-removed', 'stop-changed', 'address', 'effect-added', 'stop-added',
|
|
21
23
|
'rule-limit', 'rule-answer', 'rule-new-answer', 'rule-removed-answer', 'rule-facts', 'input-added', 'input-removed',
|
|
22
24
|
'gives-back-added', 'gives-back-removed', 'gives-back-changed', 'effect-removed', 'effect-changed', 'relies-on', 'hidden',
|
|
23
25
|
'steps', 'outside', 'added', 'removed', 'thing', 'renamed', 'moved', 'form'];
|
|
@@ -533,7 +535,13 @@ function mostlyIn(a, b) {
|
|
|
533
535
|
return hit / want.length >= 0.75;
|
|
534
536
|
}
|
|
535
537
|
|
|
536
|
-
|
|
538
|
+
/**
|
|
539
|
+
* Review two versions. Thunder Core programs are compared when `core` is given: coreChanges from
|
|
540
|
+
* @skillstech/thunderlang/program (it brings the Core compiler and engine, so this entry stays small without it).
|
|
541
|
+
* `context`: Thunder Core files that did not change but belong to a changed program's project ({ old, new }), so its
|
|
542
|
+
* tests can be run and what uses a change can be found (reviewGit reads them).
|
|
543
|
+
*/
|
|
544
|
+
export function thunderReview(oldFiles, newFiles, { core = null, context = null } = {}) {
|
|
537
545
|
detailsCache = new WeakMap();
|
|
538
546
|
const A = side(oldFiles || []), B = side(newFiles || []);
|
|
539
547
|
const items = [];
|
|
@@ -586,12 +594,17 @@ export function thunderReview(oldFiles, newFiles) {
|
|
|
586
594
|
n.m.kind === 'not-read' ? "New function that Thunder cannot read yet: check the code itself." : `New ${KIND_WORD[n.m.kind] ?? 'function'}: ${subjectOf(n)}${summaryOf(n)}.`, { before: null, after: n.text }));
|
|
587
595
|
compareThings(A, B, items);
|
|
588
596
|
|
|
597
|
+
// Thunder Core programs: rule by rule, with both versions run (core-changes.mjs).
|
|
598
|
+
const coreRead = core ? coreReview(core, oldFiles || [], newFiles || [], context, items) : { paths: new Set(), result: null };
|
|
599
|
+
const corePaths = coreRead.paths;
|
|
600
|
+
|
|
589
601
|
// Files: code outside every action and rule, files Thunder could not read, and files it does not read.
|
|
590
602
|
const paths = [...new Set([...A.sources.keys(), ...B.sources.keys()])];
|
|
591
603
|
const notRead = [];
|
|
592
604
|
for (const p of paths) {
|
|
593
605
|
const before = A.sources.get(p), after = B.sources.get(p);
|
|
594
606
|
if (before === after) continue;
|
|
607
|
+
if (corePaths.has(p)) continue;
|
|
595
608
|
const lang = !isInfra(p) && readableLanguage(p);
|
|
596
609
|
if (!lang) {
|
|
597
610
|
if (isInfra(p)) items.push(item('infrastructure', 'risk', p, { file: p, line: 1 }, `${before == null ? 'New' : after == null ? 'Removed' : 'Changed'} infrastructure or pipeline file. Thunder does not read these in this version, so check it yourself.`, before != null && after != null ? lineChanges(before.split('\n'), after.split('\n')) : null));
|
|
@@ -649,11 +662,65 @@ export function thunderReview(oldFiles, newFiles) {
|
|
|
649
662
|
for (const x of items) if (x.also) x.subject = `${x.subject} and ${x.also.length} more`;
|
|
650
663
|
|
|
651
664
|
items.sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity) || KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind)
|
|
652
|
-
|| String(a.where.file)
|
|
665
|
+
|| byText(String(a.where.file), String(b.where.file)) || (a.where.line ?? 0) - (b.where.line ?? 0));
|
|
653
666
|
const count = (s) => items.filter((x) => x.severity === s).length;
|
|
654
667
|
const summary = { meaning: count('meaning'), risk: count('risk'), form: count('form'), unchanged, files: paths.filter((p) => A.sources.get(p) !== B.sources.get(p)).length };
|
|
655
668
|
const onlyNotRead = !items.length && summary.files && notRead.length === summary.files;
|
|
656
|
-
|
|
669
|
+
const out = { schema: REVIEW_SCHEMA, summary, says: onlyNotRead ? 'Only files Thunder does not read changed.' : summaryLine(summary), items, notRead };
|
|
670
|
+
// The Thunder Core comparison itself (thunder-core-changes-v1), for callers that go on with it (review --services).
|
|
671
|
+
if (coreRead.result) Object.defineProperty(out, 'core', { value: coreRead.result, enumerable: false });
|
|
672
|
+
return out;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// The review kind for a Thunder Core change, so it sorts with the changes like it in other languages.
|
|
676
|
+
function coreKind(c) {
|
|
677
|
+
if (c.change === 'not-compiled') return 'unreadable';
|
|
678
|
+
if (c.kind === 'test' && c.severity === 'risk' && c.change !== 'removed') return 'test-fails';
|
|
679
|
+
if (c.change === 'added' || c.change === 'removed' || c.change === 'renamed') return c.kind === 'never' && c.change === 'removed' ? 'stop-removed' : c.change;
|
|
680
|
+
if (c.kind === 'keep') return 'rule-limit';
|
|
681
|
+
if (c.kind === 'function' && c.behaviour?.changed) return 'rule-answer';
|
|
682
|
+
if (c.kind === 'never') return 'stop-changed';
|
|
683
|
+
if (c.kind === 'record' || c.kind === 'store') return 'thing';
|
|
684
|
+
if (c.kind === 'main') return 'outside';
|
|
685
|
+
return 'steps';
|
|
686
|
+
}
|
|
687
|
+
const CORE_SUBJECT = { keep: (c) => `${c.subject} (kept value)`, main: (c) => c.subject };
|
|
688
|
+
|
|
689
|
+
/** Thunder Core changes as review items. Gives the paths it read, so they are not listed as "not read". */
|
|
690
|
+
function coreReview(coreChanges, oldFiles, newFiles, context, items) {
|
|
691
|
+
const core = (fs) => fs.filter((f) => f && isCoreProgram(f.path, f.source));
|
|
692
|
+
const merge = (changed, extra) => { const have = new Set(changed.map((f) => f.path)); return [...changed, ...core(extra ?? []).filter((f) => !have.has(f.path))]; };
|
|
693
|
+
const oldCore = core(oldFiles), newCore = core(newFiles);
|
|
694
|
+
if (!oldCore.length && !newCore.length) return { paths: new Set(), result: null };
|
|
695
|
+
const r = coreChanges(merge(oldCore, context?.old), merge(newCore, context?.new));
|
|
696
|
+
for (const c of r.changes) {
|
|
697
|
+
const look = (c.affects ?? []).slice(0, 6).map((x) => `${x.subject} (\`${x.file}:${x.line}\`${x.test ? `, ${x.test === 'fails' ? '**fails now**' : 'passes'}` : ''})`);
|
|
698
|
+
const more = (c.affects?.length ?? 0) > 6 ? `, and ${c.affects.length - 6} more` : '';
|
|
699
|
+
const says = look.length ? `${c.says} Look again at: ${look.join(', ')}${more}.` : c.says;
|
|
700
|
+
const evidence = c.before || c.after ? { before: c.before, after: c.after } : null;
|
|
701
|
+
items.push(item(coreKind(c), c.severity, (CORE_SUBJECT[c.kind] ?? ((x) => x.subject))(c), { file: c.file, line: c.line }, says, evidence));
|
|
702
|
+
}
|
|
703
|
+
return { paths: new Set([...oldCore, ...newCore].map((f) => f.path)), result: r };
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Add other services to a review (thunder review --services): each Thunder Trace finding with callers in another
|
|
708
|
+
* repository becomes an item that names them, with what changes in the answers when Thunder Core said so. Mutates
|
|
709
|
+
* and gives back the review, with its summary counted again.
|
|
710
|
+
*/
|
|
711
|
+
export function addServiceCallers(review, impact) {
|
|
712
|
+
for (const f of impact.findings) {
|
|
713
|
+
if (!f.dependents?.length) continue;
|
|
714
|
+
const who = f.dependents.slice(0, 6).map((d) => `${d.repo}: ${d.label} (\`${d.cite}\`)`).join(', ') + (f.dependents.length > 6 ? `, and ${f.dependents.length - 6} more` : '');
|
|
715
|
+
const what = (f.behaviour ?? []).map((x) => x.says).join(' ');
|
|
716
|
+
review.items.push(item('callers', f.risk === 'high' ? 'risk' : 'meaning', f.at.label, { file: f.at.file, line: f.at.line },
|
|
717
|
+
`${cap(f.says)}. Called from: ${who}.${what ? ` What changes: ${what}` : ''}`));
|
|
718
|
+
}
|
|
719
|
+
review.items.sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity) || KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind)
|
|
720
|
+
|| byText(String(a.where.file), String(b.where.file)) || (a.where.line ?? 0) - (b.where.line ?? 0));
|
|
721
|
+
for (const s of ['meaning', 'risk', 'form']) review.summary[s] = review.items.filter((x) => x.severity === s).length;
|
|
722
|
+
review.says = summaryLine(review.summary);
|
|
723
|
+
return review;
|
|
657
724
|
}
|
|
658
725
|
|
|
659
726
|
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
package/src/select.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { byText } from './text-order.mjs';
|
|
1
2
|
// Deterministic candidate selection , the AI generates N candidates; ThunderLang and
|
|
2
3
|
// OpenThunder pick the winner by MEASURABLE rules. An LLM never decides which
|
|
3
4
|
// candidate is best. Pure (no Node deps): browser-safe.
|
|
@@ -74,7 +75,7 @@ export function selectCandidate(candidates, policy = {}) {
|
|
|
74
75
|
if (bv == null) return -1;
|
|
75
76
|
if (av !== bv) return p.direction === 'max' ? bv - av : av - bv;
|
|
76
77
|
}
|
|
77
|
-
return String(a.id)
|
|
78
|
+
return byText(String(a.id), String(b.id)); // stable tiebreak
|
|
78
79
|
});
|
|
79
80
|
return { winner: ranked[0] || null, ranking: ranked, eligibleCount: eligible.length, rejected: (candidates || []).length - eligible.length, prefer };
|
|
80
81
|
}
|
package/src/semantic-diff.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { byText } from './text-order.mjs';
|
|
1
2
|
// Semantic diff over the Intent Graph (founder directive #4, IL owns diff/merge). Diff
|
|
2
3
|
// two versions of a graph/atlas BY MEANING: nodes added/removed/changed, relationships
|
|
3
4
|
// added/removed, and , the load-bearing feature , which approvals a change invalidates.
|
|
@@ -30,9 +31,9 @@ export function diffGraphs(before, after) {
|
|
|
30
31
|
const bn = bNodes.get(id);
|
|
31
32
|
if (bn && contentKey(bn) !== contentKey(an)) changedNodes.push({ id, type: an.type, before: bn, after: an });
|
|
32
33
|
}
|
|
33
|
-
addedNodes.sort((a, b) => a.id
|
|
34
|
-
removedNodes.sort((a, b) => a.id
|
|
35
|
-
changedNodes.sort((a, b) => a.id
|
|
34
|
+
addedNodes.sort((a, b) => byText(a.id, b.id));
|
|
35
|
+
removedNodes.sort((a, b) => byText(a.id, b.id));
|
|
36
|
+
changedNodes.sort((a, b) => byText(a.id, b.id));
|
|
36
37
|
|
|
37
38
|
const bRel = new Set((before.relationships || []).map(relKey));
|
|
38
39
|
const aRel = new Set((after.relationships || []).map(relKey));
|
|
@@ -113,12 +114,12 @@ export function mergeGraphs(base, ours, theirs) {
|
|
|
113
114
|
const present = inO !== inB ? inO : inT; // ours changed presence -> ours; else theirs
|
|
114
115
|
if (present) mergedRels.push(r);
|
|
115
116
|
}
|
|
116
|
-
mergedRels.sort((a, b2) => relKey(a)
|
|
117
|
+
mergedRels.sort((a, b2) => byText(relKey(a), relKey(b2)));
|
|
117
118
|
|
|
118
119
|
return {
|
|
119
120
|
schema: 'intent-merge-v1',
|
|
120
|
-
merged: { nodes: [...merged.values()].sort((a, b2) => a.id
|
|
121
|
-
conflicts: conflicts.sort((a, b2) => a.id
|
|
121
|
+
merged: { nodes: [...merged.values()].sort((a, b2) => byText(a.id, b2.id)), relationships: mergedRels },
|
|
122
|
+
conflicts: conflicts.sort((a, b2) => byText(a.id, b2.id)),
|
|
122
123
|
clean: conflicts.length === 0,
|
|
123
124
|
summary: { nodes: merged.size, relationships: mergedRels.length, conflicts: conflicts.length },
|
|
124
125
|
};
|
package/src/system.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { byText } from './text-order.mjs';
|
|
1
2
|
// The whole system: calls across files and services. Browser-safe, zero dependencies.
|
|
2
3
|
//
|
|
3
4
|
// After every file is read into the model, each step's call (from its meaning tree, `expr`) is followed through the
|
|
@@ -926,7 +927,7 @@ export function serviceFacts(model, files) {
|
|
|
926
927
|
return { routes, listeners, requests, publishes, unknown };
|
|
927
928
|
}
|
|
928
929
|
|
|
929
|
-
export { segsMatch };
|
|
930
|
+
export { segsMatch, routeSegs, requestTarget };
|
|
930
931
|
|
|
931
932
|
// ── The app's map: which areas call which ────────────────────────────────────────────────────────────
|
|
932
933
|
|
|
@@ -950,5 +951,5 @@ export function callsSummary(model) {
|
|
|
950
951
|
if (l.kind === 'sends-to') p.sends++; else p.calls++;
|
|
951
952
|
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}` });
|
|
952
953
|
}
|
|
953
|
-
return [...pairs.values()].sort((x, y) => (y.calls + y.sends) - (x.calls + x.sends) || x.from
|
|
954
|
+
return [...pairs.values()].sort((x, y) => (y.calls + y.sends) - (x.calls + x.sends) || byText(x.from, y.from) || byText(x.to, y.to));
|
|
954
955
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// One order for text everywhere in the compiler: by character code, the same on every machine.
|
|
2
|
+
// Not localeCompare: its order depends on the machine's locale (so the same input could sort differently), and its
|
|
3
|
+
// first call loads the whole Unicode collation data (about a quarter of a second at every start).
|
|
4
|
+
|
|
5
|
+
/** Compare two texts by character code: a negative number, 0, or a positive number, for Array.prototype.sort. */
|
|
6
|
+
export const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
package/src/thunderize.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { readCode } from './read.mjs';
|
|
5
5
|
import { readableLanguage, readingOf } from './read-repo.mjs';
|
|
6
6
|
import { thunderText, visualFor } from './visual.mjs';
|
|
7
|
+
import { byText } from './text-order.mjs';
|
|
7
8
|
|
|
8
9
|
export const THUNDERIZE_SCHEMA = 'thunderize-v1';
|
|
9
10
|
export const THUNDER_TEXT_EXT = '.thunder-text';
|
|
@@ -49,7 +50,7 @@ export function thunderizeFiles(files, { name = 'app' } = {}) {
|
|
|
49
50
|
try { out.push(thunderizeFile(f.path, f.source, language, readingOf(f, language))); }
|
|
50
51
|
catch (e) { skipped.push({ path: f.path, reason: `could not be read: ${e.message}` }); }
|
|
51
52
|
}
|
|
52
|
-
out.sort((a, b) => a.path
|
|
53
|
+
out.sort((a, b) => byText(a.path, b.path));
|
|
53
54
|
const total = { files: out.length, actions: 0, rules: 0, functions: 0, notReadYet: 0 };
|
|
54
55
|
for (const f of out) for (const k of ['actions', 'rules', 'functions', 'notReadYet']) total[k] += f.counts[k];
|
|
55
56
|
const langs = [...new Set(out.map((f) => LANGUAGE_NAMES[f.language] || f.language))].sort();
|
package/src/trace-cli.mjs
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// thunder trace impact --diff [--base <ref>] <folder…> what the current changes (branch + uncommitted) can affect
|
|
5
5
|
import { writeFileSync } from 'node:fs';
|
|
6
6
|
import { buildTrace, renderTrace, traceImpact, traceImpactOf, renderImpact } from './trace.mjs';
|
|
7
|
-
import { readRepoDir, gitChanges } from './trace-fs.mjs';
|
|
7
|
+
import { readRepoDir, gitChanges, coreBehaviourOf } from './trace-fs.mjs';
|
|
8
|
+
import { withCoreBehaviour } from './core-changes.mjs';
|
|
8
9
|
|
|
9
10
|
const USAGE = `usage: thunder trace <folder> <folder> … [--json] [--out graph.json]
|
|
10
11
|
thunder trace impact "<POST /api/orders | event name | table:orders | setting:KEY | package:name | repo:file[:line]>" <folder> … [--json]
|
|
@@ -43,11 +44,15 @@ export function traceMain(argv) {
|
|
|
43
44
|
return r.matched.length ? 0 : 1;
|
|
44
45
|
}
|
|
45
46
|
const changes = [], notes = [];
|
|
47
|
+
const behaviour = new Map();
|
|
46
48
|
for (const repo of repos) {
|
|
47
49
|
const g = gitChanges(repo, a.base);
|
|
48
|
-
if (!g.base) notes.push(g.why);
|
|
50
|
+
if (!g.base) { notes.push(g.why); continue; }
|
|
51
|
+
changes.push(...g.changes);
|
|
52
|
+
const cc = coreBehaviourOf(repo, g);
|
|
53
|
+
if (cc) behaviour.set(repo.name, cc);
|
|
49
54
|
}
|
|
50
|
-
const r = traceImpact(trace, changes);
|
|
55
|
+
const r = withCoreBehaviour(traceImpact(trace, changes), behaviour);
|
|
51
56
|
if (a.json) console.log(JSON.stringify({ ...r, notes }, null, 2));
|
|
52
57
|
else {
|
|
53
58
|
console.log(`${changes.length ? `${changes.length} changed file${changes.length === 1 ? '' : 's'} across ${new Set(changes.map((c) => c.repo)).size} of ${repos.length} repositories.` : 'No changes found.'}`);
|
package/src/trace-data.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { byText } from './text-order.mjs';
|
|
1
2
|
// Thunder Trace, the data side: packages, settings, and tables each repository declares or uses. Browser-safe, no
|
|
2
3
|
// Node APIs. trace.mjs links them across repositories; this file only reads them, with the line each one is on.
|
|
3
4
|
//
|
|
@@ -126,7 +127,7 @@ export function settingsIn(files) {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
|
-
return out.sort((a, b) => a.file
|
|
130
|
+
return out.sort((a, b) => byText(a.file, b.file) || a.line - b.line || byText(a.key, b.key));
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
// ── Tables ─────────────────────────────────────────────────────────────────────────────────────────────
|
|
@@ -212,7 +213,7 @@ export function tablesIn(files) {
|
|
|
212
213
|
// The same table, file, line, and access once (a statement like UPDATE t … FROM t names it twice).
|
|
213
214
|
const seen = new Set();
|
|
214
215
|
return out.filter((t) => { const k = `${t.file}|${t.line}|${t.table}|${t.access}`; if (seen.has(k)) return false; seen.add(k); return true; })
|
|
215
|
-
.sort((a, b) => a.file
|
|
216
|
+
.sort((a, b) => byText(a.file, b.file) || a.line - b.line || byText(a.table, b.table));
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
/** Does this access define the table (rather than use it)? */
|
package/src/trace-fs.mjs
CHANGED
|
@@ -5,6 +5,8 @@ import { basename, resolve } from 'node:path';
|
|
|
5
5
|
import { statSync } from 'node:fs';
|
|
6
6
|
import { collectReadableFiles } from './read-repo-fs.mjs';
|
|
7
7
|
import { thunderModel } from './model.mjs';
|
|
8
|
+
import { coreServiceFacts } from './core-services.mjs';
|
|
9
|
+
import { coreChanges } from './core-changes.mjs';
|
|
8
10
|
import { serviceFacts } from './system.mjs';
|
|
9
11
|
import { tablesIn } from './trace-data.mjs';
|
|
10
12
|
|
|
@@ -25,7 +27,9 @@ export function readRepoDir(dir, { maxFiles = 5000 } = {}) {
|
|
|
25
27
|
const dirty = top ? !!git(root, ['status', '--porcelain'])?.trim() : false;
|
|
26
28
|
// Manifests come too: package.json, go.mod, requirements.txt, and *.csproj say which packages a repository
|
|
27
29
|
// publishes and depends on (they are not read as code).
|
|
28
|
-
|
|
30
|
+
const files = collectReadableFiles(root, { maxFiles, manifests: true, manifestNames: TRACE_MANIFESTS, thunder: true });
|
|
31
|
+
// Thunder Core programs' endpoints and calls, read here so buildTrace (in the small /core entry) needs no compiler.
|
|
32
|
+
return { name: basename(root), root, sha, dirty, files, coreFacts: coreServiceFacts(files) };
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
/** The commit a branch started from: --base if given, else where HEAD left main/master (origin first), else HEAD. */
|
|
@@ -67,6 +71,7 @@ export function gitChanges(repo, base) {
|
|
|
67
71
|
if (!byFile.has(file)) byFile.set(file, { file, ranges: [], status: 'added' });
|
|
68
72
|
}
|
|
69
73
|
const changes = [];
|
|
74
|
+
const oldSources = new Map();
|
|
70
75
|
for (const c of byFile.values()) {
|
|
71
76
|
if (!c.file.startsWith(prefix)) continue;
|
|
72
77
|
const file = c.file.slice(prefix.length); // paths relative to the folder that was traced
|
|
@@ -74,10 +79,31 @@ export function gitChanges(repo, base) {
|
|
|
74
79
|
if (c.status !== 'added') {
|
|
75
80
|
const old = git(dir, ['show', `${b}:${c.file}`]);
|
|
76
81
|
if (old != null) {
|
|
77
|
-
|
|
82
|
+
const thunder = /\.thunder$/i.test(file);
|
|
83
|
+
try {
|
|
84
|
+
const files = [{ path: file, source: old }];
|
|
85
|
+
const f = thunder ? { ...coreServiceFacts(files), listeners: [], publishes: [] } : serviceFacts(thunderModel(files), files);
|
|
86
|
+
before = { routes: f.routes, listeners: f.listeners, publishes: f.publishes, tables: thunder ? [] : tablesIn(files) };
|
|
87
|
+
} catch { before = null; }
|
|
88
|
+
// A Thunder Core program's old text, so both versions can be compared (coreBehaviourOf).
|
|
89
|
+
if (thunder) oldSources.set(file, old);
|
|
78
90
|
}
|
|
79
91
|
}
|
|
80
92
|
changes.push({ repo: repo.name, file, ranges: c.ranges, status: c.status, ...(before ? { before } : {}) });
|
|
81
93
|
}
|
|
82
|
-
return { base: b, changes };
|
|
94
|
+
return { base: b, changes, oldSources };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Both versions of a repository's Thunder Core programs compared (core-changes.mjs; this runs them on the Thunder
|
|
99
|
+
* engine), when any changed: the new side from the folder, the old side with the changed files as they were at the
|
|
100
|
+
* base. Null when no Thunder Core program changed.
|
|
101
|
+
*/
|
|
102
|
+
export function coreBehaviourOf(repo, g) {
|
|
103
|
+
const changed = (g.changes ?? []).filter((c) => /\.thunder$/i.test(c.file));
|
|
104
|
+
if (!changed.length) return null;
|
|
105
|
+
const now = repo.files.filter((f) => /\.thunder$/i.test(f.path));
|
|
106
|
+
const gone = new Set(changed.map((c) => c.file));
|
|
107
|
+
const before = [...now.filter((f) => !gone.has(f.path)), ...changed.filter((c) => g.oldSources?.has(c.file)).map((c) => ({ path: c.file, source: g.oldSources.get(c.file) }))];
|
|
108
|
+
return coreChanges(before, now);
|
|
83
109
|
}
|