@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/src/core/project.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import { writeJava, javaDiagnostics } from './java-run.mjs';
|
|
|
16
16
|
import { writeReact, reactDiagnostics } from './react-run.mjs';
|
|
17
17
|
import { hasScreens } from './target-react.mjs';
|
|
18
18
|
import { diag } from './diagnostics.mjs';
|
|
19
|
+
import { npmRefusals, dotnetRefusals } from './target-typescript.mjs';
|
|
19
20
|
|
|
20
21
|
/** The languages a Thunder Core project can be compiled to. */
|
|
21
22
|
export const TARGETS = ['python', 'typescript', 'csharp', 'rust', 'go', 'java', 'react'];
|
|
@@ -114,6 +115,8 @@ export function buildProject({ root, single = null, includeTests = false, write
|
|
|
114
115
|
if (tgt === 'csharp') for (const r of results.filter((x) => x.ok)) { const d = csharpDiagnostics(r); if (d.length) { r.diagnostics = [...r.diagnostics, ...d]; r.ok = false; } }
|
|
115
116
|
if (tgt === 'rust') for (const r of results.filter((x) => x.ok)) { const d = rustDiagnostics(r); if (d.length) { r.diagnostics = [...r.diagnostics, ...d]; r.ok = false; } }
|
|
116
117
|
if (tgt === 'go') for (const r of results.filter((x) => x.ok)) { const d = goDiagnostics(r); if (d.length) { r.diagnostics = [...r.diagnostics, ...d]; r.ok = false; } }
|
|
118
|
+
// An npm package (Use "<package>" from npm) exists only for the TypeScript target (TC408).
|
|
119
|
+
if (tgt === 'python') for (const r of results.filter((x) => x.ok)) { const d = [...npmRefusals(r.info, 'Python', diag), ...dotnetRefusals(r.info, 'Python', diag)]; if (d.length) { r.diagnostics = [...r.diagnostics, ...d]; r.ok = false; } }
|
|
117
120
|
// The same for Java: Python modules exist only for the Python target.
|
|
118
121
|
if (tgt === 'java') for (const r of results.filter((x) => x.ok)) { const d = javaDiagnostics(r); if (d.length) { r.diagnostics = [...r.diagnostics, ...d]; r.ok = false; } }
|
|
119
122
|
const entryPath = single ? resolve(single) : cfg?.entry ? join(cfg.root, cfg.entry) : join(base, cfg?.src ?? '.', 'main.thunder');
|
package/src/core/react-run.mjs
CHANGED
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
import { writeFileSync, mkdirSync } from 'node:fs';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { toReact, hasScreens } from './target-react.mjs';
|
|
8
|
-
import { pythonOnlyUses } from './target-typescript.mjs';
|
|
8
|
+
import { pythonOnlyUses, npmRefusals, dotnetRefusals } from './target-typescript.mjs';
|
|
9
9
|
import { REACT_RUNTIME, REACT_RUNTIME_DTS } from './runtime-react.mjs';
|
|
10
10
|
import { diag } from './diagnostics.mjs';
|
|
11
11
|
|
|
12
12
|
/** What stops a file from becoming a React app: a Python module (TC405), or steps outside a screen (TC406). */
|
|
13
13
|
export function reactDiagnostics(result, { entry = false } = {}) {
|
|
14
|
-
const out = pythonOnlyUses(result.info).map((u) => diag('TC405', u.line,
|
|
14
|
+
const out = [...npmRefusals(result.info, 'a React app', diag), ...dotnetRefusals(result.info, 'a React app', diag), ...pythonOnlyUses(result.info).map((u) => diag('TC405', u.line,
|
|
15
15
|
`"${u.module}" is a Python module, and this program is built as a React app, which cannot use it.`,
|
|
16
|
-
'Build for Python (target = "python") to use Python modules. Thunder never swaps in a different library.'));
|
|
16
|
+
'Build for Python (target = "python") to use Python modules. Thunder never swaps in a different library.'))];
|
|
17
17
|
const main = result.program.main ?? [];
|
|
18
18
|
if (main.length && hasScreens(result.info)) {
|
|
19
19
|
out.push(diag('TC406', main[0].line, 'A React app shows its screens; the steps outside a screen have nowhere to run.',
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// npm packages from compiled TypeScript (Use "<package>" from npm as <name>): the boundary between Thunder values
|
|
2
|
+
// and JavaScript values. Appended to thunder_runtime.mjs (runtime-typescript.mjs drops the import line below), so
|
|
3
|
+
// the names it uses are the runtime's own.
|
|
4
|
+
//
|
|
5
|
+
// Thunder -> JavaScript: whole numbers and decimals become JavaScript numbers (a whole number too large for one
|
|
6
|
+
// stays a BigInt), money becomes its amount as a number, text stays text, yes/no stays a boolean, nothing is null,
|
|
7
|
+
// lists become arrays, maps with text keys become plain objects (others a Map), records become plain objects keyed
|
|
8
|
+
// by their field names, and dates become Date at local midnight. A value that came from the library goes back
|
|
9
|
+
// unchanged.
|
|
10
|
+
// JavaScript -> Thunder: a number becomes the exact decimal it is written as (0.1 stays 0.1, never
|
|
11
|
+
// 0.1000000000000000055…), and a whole number a whole number; text, booleans, null and undefined (nothing), arrays
|
|
12
|
+
// (lists), and plain objects (maps with text keys) are turned into Thunder values; anything else (a Date, a class
|
|
13
|
+
// instance, a function) stays a library value that can be handed back to the library.
|
|
14
|
+
import { ThunderErr, ConversionFailed, Dec, Money, PyDate, Tuple, PyDict, RecordVal, NOT_GIVEN } from './engine-values.mjs';
|
|
15
|
+
|
|
16
|
+
const isPlainObject = (v) => v !== null && typeof v === 'object' && (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
|
|
17
|
+
|
|
18
|
+
/** A Thunder value as a JavaScript value, for a call into an npm package. */
|
|
19
|
+
export function toJs(v) {
|
|
20
|
+
if (v === null || v === undefined || v === NOT_GIVEN) return null;
|
|
21
|
+
if (typeof v === 'bigint') return Number.isSafeInteger(Number(v)) ? Number(v) : v;
|
|
22
|
+
if (v instanceof Dec) return Number(v.toString());
|
|
23
|
+
if (v instanceof Money) return Number(v.amount.toString());
|
|
24
|
+
if (v instanceof PyDate) return new Date(v.y, v.m - 1, v.d);
|
|
25
|
+
if (Array.isArray(v)) return v.map(toJs);
|
|
26
|
+
if (v instanceof Tuple) return v.items.map(toJs);
|
|
27
|
+
if (v instanceof PyDict) {
|
|
28
|
+
const keys = v.keys();
|
|
29
|
+
if (keys.every((k) => typeof k === 'string')) return Object.fromEntries(keys.map((k) => [k, toJs(v.get(k))]));
|
|
30
|
+
return new Map(keys.map((k) => [toJs(k), toJs(v.get(k))]));
|
|
31
|
+
}
|
|
32
|
+
if (v instanceof RecordVal) return Object.fromEntries(v.cls.fields.map((f) => [f.py, toJs(v.f.get(f.py))]));
|
|
33
|
+
return v;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A JavaScript value from an npm package, as a Thunder value. */
|
|
37
|
+
export function fromJs(v, what) {
|
|
38
|
+
if (v === null || v === undefined) return null;
|
|
39
|
+
if (typeof v === 'number') {
|
|
40
|
+
if (!Number.isFinite(v)) throw ConversionFailed(`${what} gave back ${v}, which is not a number Thunder can use.`);
|
|
41
|
+
return Number.isInteger(v) && Math.abs(v) <= Number.MAX_SAFE_INTEGER ? BigInt(v) : Dec.parse(String(v));
|
|
42
|
+
}
|
|
43
|
+
if (typeof v === 'bigint' || typeof v === 'string' || typeof v === 'boolean') return v;
|
|
44
|
+
if (Array.isArray(v)) return v.map((x) => fromJs(x, what));
|
|
45
|
+
if (v instanceof Map) { const d = new PyDict(); for (const [k, x] of v) d.set(fromJs(k, what), fromJs(x, what)); return d; }
|
|
46
|
+
if (isPlainObject(v)) { const d = new PyDict(); for (const [k, x] of Object.entries(v)) d.set(k, fromJs(x, what)); return d; }
|
|
47
|
+
if (typeof v.then === 'function') throw new ThunderErr('TC508', `${what} works asynchronously (it gave back a promise), and Thunder Core runs one step after another. Use a function of the package that gives its answer straight away.`, 'LibraryError');
|
|
48
|
+
return v;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The package as Thunder sees it: its named exports, then its default export's members (CommonJS packages). */
|
|
52
|
+
export function library(ns, name) {
|
|
53
|
+
const dflt = ns && ns.default;
|
|
54
|
+
// "default" is the package itself when it exports one thing (module.exports = function …): Use "is-odd" from npm
|
|
55
|
+
// as odd, then odd.default(3).
|
|
56
|
+
return { name, get(attr) { if (attr === 'default') return dflt ?? undefined; if (ns && attr in ns) return ns[attr]; if (dflt != null && attr in Object(dflt)) return dflt[attr]; return undefined; }, bind(attr) { return attr === 'default' || (ns && attr in ns) ? ns : dflt; } };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const describeJsError = (e) => (e instanceof Error ? `${e.name}: ${e.message}` : String(e));
|
|
60
|
+
|
|
61
|
+
/** <library>.<attr>(<args>): call the package with JavaScript values and take its answer as a Thunder value. */
|
|
62
|
+
export function callLibrary(lib, attr, args) {
|
|
63
|
+
const what = `${lib.name}.${attr}`;
|
|
64
|
+
const fn = lib.get(attr);
|
|
65
|
+
if (typeof fn !== 'function') throw new ThunderErr('TC508', fn === undefined ? `The npm package "${lib.name}" has nothing named "${attr}".` : `"${what}" is not something to call.`, 'LibraryError');
|
|
66
|
+
let out;
|
|
67
|
+
try { out = fn.apply(lib.bind(attr), args.map(toJs)); } catch (e) {
|
|
68
|
+
if (e && e.thunder) throw e;
|
|
69
|
+
throw new ThunderErr('TC508', `JavaScript code used by this line failed: ${describeJsError(e)}`, 'LibraryError');
|
|
70
|
+
}
|
|
71
|
+
return fromJs(out, what);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** <library>.<attr> without a call: a value the package exports. */
|
|
75
|
+
export function getLibrary(lib, attr) {
|
|
76
|
+
const v = lib.get(attr);
|
|
77
|
+
if (v === undefined) throw new ThunderErr('TC508', `The npm package "${lib.name}" has nothing named "${attr}".`, 'LibraryError');
|
|
78
|
+
return fromJs(v, `${lib.name}.${attr}`);
|
|
79
|
+
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { readFileSync } from 'node:fs';
|
|
7
7
|
import * as VALUES from './engine-values.mjs';
|
|
8
8
|
import * as SCREEN from './screen-values.mjs';
|
|
9
|
+
import { byText } from '../text-order.mjs';
|
|
9
10
|
|
|
10
11
|
const VALUES_SOURCE = readFileSync(new URL('./engine-values.mjs', import.meta.url), 'utf8');
|
|
11
12
|
// (Its import line names what engine-values.mjs already defined above it.)
|
|
@@ -120,7 +121,7 @@ const isClass = (v) => typeof v === 'function' && /^class\b/.test(Function.proto
|
|
|
120
121
|
|
|
121
122
|
function declarations() {
|
|
122
123
|
const L = ['// thunder_runtime.d.mts: types for thunder_runtime.mjs (written by the Thunder compiler).', '// Thunder values are checked when the program runs; to TypeScript they are of any kind.', ''];
|
|
123
|
-
for (const [name, v] of Object.entries({ ...VALUES, ...SCREEN }).sort(([a], [b]) => a
|
|
124
|
+
for (const [name, v] of Object.entries({ ...VALUES, ...SCREEN }).sort(([a], [b]) => byText(a, b))) {
|
|
124
125
|
if (isClass(v)) L.push(`export declare class ${name} { constructor(...args: any[]); [key: string]: any; static [key: string]: any; }`);
|
|
125
126
|
else if (typeof v === 'function') L.push(`export declare function ${name}(...args: any[]): any;`);
|
|
126
127
|
else L.push(`export declare const ${name}: any;`);
|
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
// Thunder engine, and compiled TypeScript, and requires the same output from all three.
|
|
7
7
|
import { readFileSync } from 'node:fs';
|
|
8
8
|
import * as VALUES from './engine-values.mjs';
|
|
9
|
+
import { byText } from '../text-order.mjs';
|
|
9
10
|
|
|
10
11
|
const VALUES_SOURCE = readFileSync(new URL('./engine-values.mjs', import.meta.url), 'utf8');
|
|
12
|
+
// npm packages (Use "<package>" from npm): the boundary between Thunder values and JavaScript values. Its import
|
|
13
|
+
// line is dropped: in thunder_runtime.mjs the names it uses are the runtime's own.
|
|
14
|
+
const NPM_SOURCE = readFileSync(new URL('./runtime-npm.mjs', import.meta.url), 'utf8').replace(/^import [^\n]*\n/m, '');
|
|
11
15
|
|
|
12
16
|
/** The Node part: everything here is about running, not about what a value means. */
|
|
13
17
|
const NODE_PART = `
|
|
@@ -93,21 +97,21 @@ export function runTests(modules) {
|
|
|
93
97
|
}
|
|
94
98
|
`;
|
|
95
99
|
|
|
96
|
-
const NODE_EXPORTS = { functions: ['enterFrame', 'enterCall', 'leave', 'topFrame', 'fail', 'keyAt', 'say', 'readText', 'recordKind', 'setAttr', 'setField', 'newRecord', 'init', 'isEntry', 'run', 'runTests'] };
|
|
100
|
+
const NODE_EXPORTS = { functions: ['enterFrame', 'enterCall', 'leave', 'topFrame', 'fail', 'keyAt', 'say', 'readText', 'recordKind', 'setAttr', 'setField', 'newRecord', 'init', 'isEntry', 'run', 'runTests', 'toJs', 'fromJs', 'library', 'callLibrary', 'getLibrary'] };
|
|
97
101
|
|
|
98
102
|
const HEADER = `// thunder_runtime.mjs: written by the Thunder compiler next to compiled TypeScript. Standard library only.
|
|
99
103
|
// The values and rules here are the Thunder engine's own (engine-values.mjs), so compiled TypeScript, the Thunder
|
|
100
104
|
// engine, and compiled Python say the same thing for the same program.
|
|
101
105
|
`;
|
|
102
106
|
|
|
103
|
-
export const TS_RUNTIME = `${HEADER}\n${VALUES_SOURCE.trimEnd()}\n${NODE_PART}`;
|
|
107
|
+
export const TS_RUNTIME = `${HEADER}\n${VALUES_SOURCE.trimEnd()}\n${NODE_PART}\n${NPM_SOURCE}`;
|
|
104
108
|
|
|
105
109
|
const isClass = (v) => typeof v === 'function' && /^class\b/.test(Function.prototype.toString.call(v));
|
|
106
110
|
|
|
107
111
|
/** Declarations for the runtime, made from its exports: every function takes and gives values of any kind. */
|
|
108
112
|
function declarations() {
|
|
109
113
|
const L = ['// thunder_runtime.d.mts: types for thunder_runtime.mjs (written by the Thunder compiler).', '// Thunder values are checked when the program runs; to TypeScript they are of any kind.', ''];
|
|
110
|
-
for (const [name, v] of Object.entries(VALUES).sort(([a], [b]) => a
|
|
114
|
+
for (const [name, v] of Object.entries(VALUES).sort(([a], [b]) => byText(a, b))) {
|
|
111
115
|
if (isClass(v)) L.push(`export declare class ${name} { constructor(...args: any[]); [key: string]: any; static [key: string]: any; }`);
|
|
112
116
|
else if (typeof v === 'function') L.push(`export declare function ${name}(...args: any[]): any;`);
|
|
113
117
|
else L.push(`export declare const ${name}: any;`);
|
package/src/core/rust-run.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { createHash } from 'node:crypto';
|
|
|
10
10
|
import { tmpdir } from 'node:os';
|
|
11
11
|
import { fileURLToPath } from 'node:url';
|
|
12
12
|
import { toRust, pythonOnlyUses, exportedRustNames, rs } from './target-rust.mjs';
|
|
13
|
+
import { npmRefusals, dotnetRefusals } from './target-typescript.mjs';
|
|
13
14
|
import { diag } from './diagnostics.mjs';
|
|
14
15
|
|
|
15
16
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
@@ -21,9 +22,9 @@ export const rustModule = (m) => `m_${m}`;
|
|
|
21
22
|
|
|
22
23
|
/** TC405 for every Use in a file: Python modules exist only for the Python target. */
|
|
23
24
|
export function rustDiagnostics(result) {
|
|
24
|
-
return pythonOnlyUses(result.info).map((u) => diag('TC405', u.line,
|
|
25
|
+
return [...npmRefusals(result.info, 'Rust', diag), ...dotnetRefusals(result.info, 'Rust', diag), ...pythonOnlyUses(result.info).map((u) => diag('TC405', u.line,
|
|
25
26
|
`"${u.module}" is a Python module, and this program is compiled to Rust, which cannot use it.`,
|
|
26
|
-
'Build for Python (target = "python") to use Python modules. Thunder never swaps in a different library.'));
|
|
27
|
+
'Build for Python (target = "python") to use Python modules. Thunder never swaps in a different library.'))];
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
/** Compile checked results to Rust: { [rustModule]: text }. Test modules see every src module's names. */
|
|
@@ -25,7 +25,7 @@ const KNOWN_BOOL = new Set(['cmp', 'contains', 'between', 'adj', 'isNothing', 'n
|
|
|
25
25
|
|
|
26
26
|
/** Thunder modules a program uses that only Python has (Use): compiled C# cannot call them. */
|
|
27
27
|
export function pythonOnlyUses(info) {
|
|
28
|
-
return (info.modules ?? []).filter((m) => !info.imported?.has(m)).map((m) => ({ module: m.module, line: m.line }));
|
|
28
|
+
return (info.modules ?? []).filter((m) => !info.imported?.has(m) && (m.ecosystem ?? 'python') === 'python').map((m) => ({ module: m.module, line: m.line }));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -47,6 +47,8 @@ class Gen {
|
|
|
47
47
|
|
|
48
48
|
module(module, namespace, imports) {
|
|
49
49
|
const own = (s) => !this.info.imported?.has(s);
|
|
50
|
+
// .NET types (Use "<type>" from .NET or NuGet): one field each, found by name when the class is first used.
|
|
51
|
+
for (const m of (this.info.modules ?? []).filter((x) => own(x) && (x.ecosystem === 'dotnet' || x.ecosystem === 'nuget'))) this.emit(`public static readonly object ${id(m.py)} = Dotnet.library(${cs(m.module)});`, m.line);
|
|
50
52
|
for (const r of this.info.records.filter(own)) { this.blank(); this.record(r); }
|
|
51
53
|
for (const f of this.info.funcs.filter(own)) { this.blank(); this.func(f); }
|
|
52
54
|
const consts = this.info.consts.filter(own);
|
|
@@ -412,6 +414,8 @@ class Gen {
|
|
|
412
414
|
return id(r.py ?? e.name.replace(/ /g, '_'));
|
|
413
415
|
}
|
|
414
416
|
case 'call': return `${id(e.py)}(${e.args.map(sub).join(', ')})`;
|
|
417
|
+
// <library>.<name>(…): a call into a .NET type, through the boundary (ThunderDotnet.cs).
|
|
418
|
+
case 'dot': return e.args ? `Dotnet.call(${sub(e.obj)}, ${cs(e.attr)}, new object[] { ${e.args.map(sub).join(', ')} })` : `Dotnet.get(${sub(e.obj)}, ${cs(e.attr)})`;
|
|
415
419
|
case 'new': return `T.newRecord(${id(e.py)}${e.fields.map((f) => `, ${cs(f.py)}, ${sub(f.e)}`).join('')})`;
|
|
416
420
|
case 'field': return e.static ? `T.getAttr(${sub(e.obj)}, ${cs(e.py)})` : `T.getField(${sub(e.obj)}, ${cs(e.text)})`;
|
|
417
421
|
case 'at': {
|
package/src/core/target-go.mjs
CHANGED
|
@@ -40,7 +40,7 @@ const KNOWN_BOOL = new Set(['cmp', 'contains', 'between', 'adj', 'isNothing', 'n
|
|
|
40
40
|
|
|
41
41
|
/** Thunder modules a program uses that only Python has (Use): compiled Go cannot call them. */
|
|
42
42
|
export function pythonOnlyUses(info) {
|
|
43
|
-
return (info.modules ?? []).filter((m) => !info.imported?.has(m)).map((m) => ({ module: m.module, line: m.line }));
|
|
43
|
+
return (info.modules ?? []).filter((m) => !info.imported?.has(m) && (m.ecosystem ?? 'python') === 'python').map((m) => ({ module: m.module, line: m.line }));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -93,7 +93,7 @@ class Gen {
|
|
|
93
93
|
if (this.needDataclass) head.push('from dataclasses import dataclass, field');
|
|
94
94
|
if (this.needDate) head.push('from datetime import date');
|
|
95
95
|
if (this.needDecimal) head.push('from decimal import Decimal');
|
|
96
|
-
for (const m of this.info.modules.filter(own)) head.push(m.module === m.py || (m.module.split('.')[0] === m.py && !m.module.includes('.')) ? `import ${m.module}` : `import ${m.module} as ${m.py}`);
|
|
96
|
+
for (const m of this.info.modules.filter((x) => own(x) && (x.ecosystem ?? 'python') === 'python')) head.push(m.module === m.py || (m.module.split('.')[0] === m.py && !m.module.includes('.')) ? `import ${m.module}` : `import ${m.module} as ${m.py}`);
|
|
97
97
|
head.push(`from thunder_runtime import ${[...this.rt].sort().join(', ')}`);
|
|
98
98
|
for (const m of srcModules) head.push(`from ${m} import *`);
|
|
99
99
|
head.push('', `THUNDER_SOURCE = ${py(this.source)}`, '', '');
|
package/src/core/target-rust.mjs
CHANGED
|
@@ -40,7 +40,7 @@ const KNOWN_BOOL = new Set(['cmp', 'contains', 'between', 'adj', 'isNothing', 'n
|
|
|
40
40
|
|
|
41
41
|
/** Thunder modules a program uses that only Python has (Use): compiled Rust cannot call them. */
|
|
42
42
|
export function pythonOnlyUses(info) {
|
|
43
|
-
return (info.modules ?? []).filter((m) => !info.imported?.has(m)).map((m) => ({ module: m.module, line: m.line }));
|
|
43
|
+
return (info.modules ?? []).filter((m) => !info.imported?.has(m) && (m.ecosystem ?? 'python') === 'python').map((m) => ({ module: m.module, line: m.line }));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -48,9 +48,36 @@ export function toTypeScript(program, info, { source = 'main.thunder', imports =
|
|
|
48
48
|
|
|
49
49
|
/** Thunder modules a program uses that only Python has (Use): compiled TypeScript cannot call them. */
|
|
50
50
|
export function pythonOnlyUses(info) {
|
|
51
|
-
return (info.modules ?? []).filter((m) => !info.imported?.has(m)).map((m) => ({ module: m.module, line: m.line }));
|
|
51
|
+
return (info.modules ?? []).filter((m) => !info.imported?.has(m) && (m.ecosystem ?? 'python') === 'python').map((m) => ({ module: m.module, line: m.line }));
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/** npm packages a program uses (Use "<package>" from npm): only compiled TypeScript can call them. */
|
|
55
|
+
export function npmUses(info) {
|
|
56
|
+
return (info.modules ?? []).filter((m) => !info.imported?.has(m) && m.ecosystem === 'npm').map((m) => ({ module: m.module, line: m.line }));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** TC408 for every npm package a file uses, when it is compiled for `target` (anything but TypeScript). */
|
|
60
|
+
export function npmRefusals(info, targetName, diag) {
|
|
61
|
+
return npmUses(info).map((u) => diag('TC408', u.line,
|
|
62
|
+
`"${u.module}" is an npm package, and this program is compiled to ${targetName}, which cannot use it.`,
|
|
63
|
+
'Build for TypeScript to use npm packages: --target typescript, or target = "typescript" under [build] in thunder.toml. Thunder never swaps in a different library.'));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** .NET types a program uses (Use "<type>" from .NET or NuGet): only compiled C# can call them. */
|
|
67
|
+
export function dotnetUses(info) {
|
|
68
|
+
return (info.modules ?? []).filter((m) => !info.imported?.has(m) && (m.ecosystem === 'dotnet' || m.ecosystem === 'nuget')).map((m) => ({ module: m.module, line: m.line, ecosystem: m.ecosystem }));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** TC409 for every .NET type a file uses, when it is compiled for `target` (anything but C#). */
|
|
72
|
+
export function dotnetRefusals(info, targetName, diag) {
|
|
73
|
+
return dotnetUses(info).map((u) => diag('TC409', u.line,
|
|
74
|
+
`"${u.module}" is ${u.ecosystem === 'nuget' ? 'from a NuGet package' : 'a .NET type'}, and this program is compiled to ${targetName}, which cannot use it.`,
|
|
75
|
+
'Build for C# to use .NET libraries: --target csharp, or target = "csharp" under [build] in thunder.toml. Thunder never swaps in a different library.'));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The name of an npm package's namespace import (import * as <it> from "<package>"). */
|
|
79
|
+
const npmNs = (m) => `$npm_${m.py}`;
|
|
80
|
+
|
|
54
81
|
export class Gen {
|
|
55
82
|
constructor(program, info, source) {
|
|
56
83
|
this.p = program; this.info = info; this.source = source;
|
|
@@ -62,6 +89,7 @@ export class Gen {
|
|
|
62
89
|
|
|
63
90
|
module(imports) {
|
|
64
91
|
const own = (s) => !this.info.imported?.has(s);
|
|
92
|
+
const npm = (this.info.modules ?? []).filter((m) => own(m) && m.ecosystem === 'npm');
|
|
65
93
|
const head = [
|
|
66
94
|
`// Generated by the Thunder compiler from ${this.source}.`,
|
|
67
95
|
`// A build artifact: change ${this.source.split('/').pop()} and build again, or keep this file and edit it as TypeScript.`,
|
|
@@ -69,8 +97,10 @@ export class Gen {
|
|
|
69
97
|
'',
|
|
70
98
|
"import * as T from './thunder_runtime.mjs';",
|
|
71
99
|
...imports.filter((m) => m.names.length).map((m) => `import { ${m.names.map(id).join(', ')} } from './${m.module}.ts';`),
|
|
100
|
+
...npm.map((m) => `import * as ${npmNs(m)} from ${js(m.module)}; // thunder:${m.line}`),
|
|
72
101
|
'',
|
|
73
102
|
`const FILE = ${js(this.source)};`,
|
|
103
|
+
...npm.map((m) => `export const ${id(m.py)}: any = T.library(${npmNs(m)}, ${js(m.module)}); // thunder:${m.line}`),
|
|
74
104
|
];
|
|
75
105
|
for (const r of this.info.records.filter(own)) { this.blank(); this.record(r); }
|
|
76
106
|
for (const f of this.info.funcs.filter(own)) { this.blank(); this.func(f); }
|
|
@@ -396,6 +426,8 @@ export class Gen {
|
|
|
396
426
|
return id(r.py ?? e.name.replace(/ /g, '_'));
|
|
397
427
|
}
|
|
398
428
|
case 'call': return `${id(e.py)}(${e.args.map(sub).join(', ')})`;
|
|
429
|
+
// <library>.<name>(…): a call into an npm package, through the runtime's boundary (runtime-npm.mjs).
|
|
430
|
+
case 'dot': return e.args ? `T.callLibrary(${sub(e.obj)}, ${js(e.attr)}, [${e.args.map(sub).join(', ')}])` : `T.getLibrary(${sub(e.obj)}, ${js(e.attr)})`;
|
|
399
431
|
case 'new': return `T.newRecord(${id(e.py)}, [${e.fields.map((f) => `[${js(f.py)}, ${sub(f.e)}]`).join(', ')}])`;
|
|
400
432
|
case 'field': return e.static ? `T.getAttr(${sub(e.obj)}, ${js(e.py)})` : `T.getField(${sub(e.obj)}, ${js(e.text)})`;
|
|
401
433
|
case 'at': {
|
|
@@ -8,18 +8,18 @@ import { join, dirname } from 'node:path';
|
|
|
8
8
|
import { spawnSync } from 'node:child_process';
|
|
9
9
|
import { createRequire } from 'node:module';
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
|
-
import { toTypeScript, pythonOnlyUses } from './target-typescript.mjs';
|
|
11
|
+
import { toTypeScript, pythonOnlyUses, npmUses, dotnetRefusals } from './target-typescript.mjs';
|
|
12
12
|
import { TS_RUNTIME, TS_RUNTIME_DTS } from './runtime-typescript.mjs';
|
|
13
13
|
import { diag } from './diagnostics.mjs';
|
|
14
14
|
|
|
15
15
|
/** The names a src file gives a test file (its records, functions, and kept values). */
|
|
16
|
-
const exportedNames = (r) => [...r.info.records, ...r.info.funcs, ...r.info.consts].filter((s) => !r.info.imported?.has(s)).map((s) => s.py);
|
|
16
|
+
const exportedNames = (r) => [...r.info.records, ...r.info.funcs, ...r.info.consts, ...(r.info.modules ?? []).filter((m) => m.ecosystem === 'npm')].filter((s) => !r.info.imported?.has(s)).map((s) => s.py);
|
|
17
17
|
|
|
18
18
|
/** TC405 for every Use in a file: Python modules exist only for the Python target. */
|
|
19
19
|
export function typescriptDiagnostics(result) {
|
|
20
|
-
return pythonOnlyUses(result.info).map((u) => diag('TC405', u.line,
|
|
20
|
+
return [...dotnetRefusals(result.info, 'TypeScript', diag), ...pythonOnlyUses(result.info).map((u) => diag('TC405', u.line,
|
|
21
21
|
`"${u.module}" is a Python module, and this program is compiled to TypeScript, which cannot use it.`,
|
|
22
|
-
'Build for Python (target = "python") to use Python modules. Thunder never swaps in a different library.'));
|
|
22
|
+
'Build for Python (target = "python") to use Python modules. Thunder never swaps in a different library.'))];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -50,6 +50,11 @@ export function writeTypeScript(results, outDir) {
|
|
|
50
50
|
writeFileSync(join(outDir, 'thunder_runtime.d.mts'), TS_RUNTIME_DTS);
|
|
51
51
|
writeFileSync(join(outDir, 'package.json'), `${JSON.stringify({ type: 'module', private: true }, null, 2)}\n`);
|
|
52
52
|
writeFileSync(join(outDir, 'tsconfig.json'), TSCONFIG);
|
|
53
|
+
// npm packages: Thunder treats them as library values (typed any), so tsc --strict needs no declarations from them.
|
|
54
|
+
// Without this, a package that ships no types (TS7016) would fail the check even though the program is fine.
|
|
55
|
+
const npmPackages = [...new Set(results.flatMap((r) => npmUses(r.info).map((u) => u.module)))].sort();
|
|
56
|
+
if (npmPackages.length) writeFileSync(join(outDir, 'npm_packages.d.ts'), ['// Generated by the Thunder compiler: the npm packages this program uses, as library values.', ...npmPackages.map((m) => `declare module ${JSON.stringify(m)};`), ''].join('\n'));
|
|
57
|
+
else rmSync(join(outDir, 'npm_packages.d.ts'), { force: true });
|
|
53
58
|
writeFileSync(join(outDir, 'run_tests.ts'), [
|
|
54
59
|
'// Generated by the Thunder compiler: runs every Test block in this project.',
|
|
55
60
|
"import * as T from './thunder_runtime.mjs';",
|
package/src/decision.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { byText } from './text-order.mjs';
|
|
1
2
|
// Decisions, rules, process semantics (Gap 4). IL owns rule semantics + DETERMINISTIC
|
|
2
3
|
// conflict/coverage detection on the DECLARED decision. OpenThunder verifies the
|
|
3
4
|
// decision's IMPLEMENTATION (rule coverage, decision impl verification, explanation
|
|
@@ -34,5 +35,5 @@ export function analyzeDecision(dec) {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
return findings.sort((a, b) => `${a.code} ${a.message}
|
|
38
|
+
return findings.sort((a, b) => byText(`${a.code} ${a.message}`, `${b.code} ${b.message}`));
|
|
38
39
|
}
|
package/src/distributed.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { byText } from './text-order.mjs';
|
|
1
2
|
// Distributed + failure semantics (Gap 3). IL owns the failure-policy types and the
|
|
2
3
|
// STATIC declaration checks (a retry needs idempotency, at-least-once needs dedup, a
|
|
3
4
|
// permanent-failure handler needs compensation). OpenThunder verifies these hold in the
|
|
@@ -44,5 +45,5 @@ export function analyzeDistributed(ast) {
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
return findings.sort((a, b) => `${a.code} ${a.target}
|
|
48
|
+
return findings.sort((a, b) => byText(`${a.code} ${a.target}`, `${b.code} ${b.target}`));
|
|
48
49
|
}
|
package/src/emit.mjs
CHANGED
|
@@ -30,7 +30,7 @@ export function notesSummary(ast) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export const COMPILER_VERSION = '1.
|
|
33
|
+
export const COMPILER_VERSION = '1.7.0';
|
|
34
34
|
export const PROOF_SCHEMA_VERSION = '0.1.0';
|
|
35
35
|
// Identifies which ecosystem product emitted this proof. Consumed by SkillsTech
|
|
36
36
|
// Certified to key cert proofs to the compiler. Stable slug per the coordination bus.
|
|
@@ -116,7 +116,7 @@ export function semanticDiagnostics(ast) {
|
|
|
116
116
|
|| (ast.patterns && ast.patterns.length > 0);
|
|
117
117
|
if (!hasSubject) {
|
|
118
118
|
err('missing-subject', 'No mission, service, event, api, database, or experience declared.',
|
|
119
|
-
'Every file must declare one subject so the compiler knows what it is reasoning about.',
|
|
119
|
+
'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).',
|
|
120
120
|
[{ label: 'Add a mission declaration', insert: 'mission MyMission', block: 'top' }]);
|
|
121
121
|
}
|
|
122
122
|
// Only missions warrant a goal; experience/pattern-only files do not.
|
package/src/focus.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { byText } from './text-order.mjs';
|
|
1
2
|
// Intent Lens , Intent Scope + Focus Graph (intent-focus-v1). A Focus Graph is a versioned
|
|
2
3
|
// subgraph of the Intent Atlas around a selected scope (a mission, a set of nodes, a change),
|
|
3
4
|
// with each included node tagged by WHY it is in focus. This is the shared foundation the
|
|
@@ -101,7 +102,7 @@ export function buildFocusGraph(atlas, { seeds = [], depth = 2, scope = null } =
|
|
|
101
102
|
|
|
102
103
|
const focusNodes = [...included.values()]
|
|
103
104
|
.map(({ node, reason, depth: dd }) => ({ id: node.id, type: node.type, title: node.title || node.id, focusReason: reason, depth: dd, confidence: node.confidence || null, provenance: node.provenance || null }))
|
|
104
|
-
.sort((a, b) => a.depth - b.depth || a.id
|
|
105
|
+
.sort((a, b) => a.depth - b.depth || byText(a.id, b.id));
|
|
105
106
|
const idSet = new Set(focusNodes.map((n) => n.id));
|
|
106
107
|
const focusRels = rels.filter((r) => idSet.has(r.from) && idSet.has(r.to));
|
|
107
108
|
|
package/src/intent-atlas.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { byText } from './text-order.mjs';
|
|
1
2
|
// Intent Atlas (founder directive #4). The navigable, expandable, searchable map of a
|
|
2
3
|
// whole software system, built OVER the canonical Intent Graph (intent-graph-v1) , NOT a
|
|
3
4
|
// fork. Missions are the entry points (progressive disclosure: you never start from
|
|
@@ -23,10 +24,10 @@ export function buildAtlas(graphs, opts = {}) {
|
|
|
23
24
|
for (const n of g.nodes) if (!nodes.has(n.id)) nodes.set(n.id, n);
|
|
24
25
|
for (const r of g.relationships) relationships.push(r);
|
|
25
26
|
}
|
|
26
|
-
const nodeList = [...nodes.values()].sort((a, b) => a.id
|
|
27
|
+
const nodeList = [...nodes.values()].sort((a, b) => byText(a.id, b.id));
|
|
27
28
|
const byType = {};
|
|
28
29
|
for (const n of nodeList) byType[n.type] = (byType[n.type] || 0) + 1;
|
|
29
|
-
missions.sort((a, b) => a.id
|
|
30
|
+
missions.sort((a, b) => byText(a.id, b.id));
|
|
30
31
|
return {
|
|
31
32
|
schema: ATLAS_SCHEMA,
|
|
32
33
|
product: opts.product || null,
|
|
@@ -72,6 +73,6 @@ export function searchAtlas(atlas, query, opts = {}) {
|
|
|
72
73
|
};
|
|
73
74
|
let hits = atlas.nodes.filter((n) => `${n.id} ${n.title || ''} ${n.description || ''}`.toLowerCase().includes(q));
|
|
74
75
|
if (opts.type) hits = hits.filter((n) => n.type === opts.type);
|
|
75
|
-
hits.sort((a, b) => score(a) - score(b) || a.type
|
|
76
|
+
hits.sort((a, b) => score(a) - score(b) || byText(a.type, b.type) || byText(a.id, b.id));
|
|
76
77
|
return hits.slice(0, opts.limit || 25);
|
|
77
78
|
}
|
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';
|
|
@@ -287,17 +288,23 @@ const TOOLS = [
|
|
|
287
288
|
},
|
|
288
289
|
{
|
|
289
290
|
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.',
|
|
291
|
+
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
292
|
inputSchema: {
|
|
292
293
|
type: 'object', required: ['files', 'edits'],
|
|
293
294
|
properties: {
|
|
294
295
|
files: { type: 'array', minItems: 1, maxItems: 20, items: { type: 'object', required: ['path', 'source'], properties: { path: str, source: str } } },
|
|
295
296
|
edits: { description: 'one Thunder edit object, or a list applied in order', anyOf: [{ type: 'object' }, { type: 'array', items: { type: 'object' } }] },
|
|
297
|
+
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
298
|
},
|
|
297
299
|
},
|
|
298
|
-
run: ({ files, edits }) => {
|
|
300
|
+
run: ({ files, edits, behaviour }) => {
|
|
299
301
|
if (!Array.isArray(files) || !files.length) throw new Error('Give the files as [{ path, source }].');
|
|
300
|
-
const
|
|
302
|
+
const given = files.map((f) => ({ path: String(f.path), source: String(f.source) }));
|
|
303
|
+
const r = thunderWrite(given, edits);
|
|
304
|
+
if (behaviour && r.status === 'written') {
|
|
305
|
+
const originals = new Map(given.map((f) => [f.path, f.source]));
|
|
306
|
+
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] }));
|
|
307
|
+
}
|
|
301
308
|
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
309
|
},
|
|
303
310
|
},
|
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/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,6 +11,7 @@
|
|
|
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';
|
|
14
15
|
|
|
15
16
|
export const REVIEW_SCHEMA = 'thunder-review-v1';
|
|
16
17
|
export const REVIEW_MARKER = '<!-- thunder-review -->';
|
|
@@ -649,7 +650,7 @@ export function thunderReview(oldFiles, newFiles) {
|
|
|
649
650
|
for (const x of items) if (x.also) x.subject = `${x.subject} and ${x.also.length} more`;
|
|
650
651
|
|
|
651
652
|
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)
|
|
653
|
+
|| byText(String(a.where.file), String(b.where.file)) || (a.where.line ?? 0) - (b.where.line ?? 0));
|
|
653
654
|
const count = (s) => items.filter((x) => x.severity === s).length;
|
|
654
655
|
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
656
|
const onlyNotRead = !items.length && summary.files && notRead.length === summary.files;
|
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
|
}
|