@skillstech/thunderlang 1.7.0 → 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.
Files changed (54) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/README.md +10 -3
  3. package/dist/core.cjs +234 -20
  4. package/dist/index.cjs +8853 -1045
  5. package/dist/learn.cjs +1339 -69
  6. package/package.json +1 -1
  7. package/src/cli-main.mjs +312 -115
  8. package/src/core/check.mjs +312 -6
  9. package/src/core/cli.mjs +60 -8
  10. package/src/core/csharp-run.mjs +2 -2
  11. package/src/core/diagnostics.mjs +9 -0
  12. package/src/core/engine-core.mjs +141 -19
  13. package/src/core/engine-values.mjs +1 -0
  14. package/src/core/engine.mjs +131 -7
  15. package/src/core/go-run.mjs +2 -2
  16. package/src/core/index.mjs +6 -2
  17. package/src/core/java-run.mjs +2 -2
  18. package/src/core/kind.mjs +3 -0
  19. package/src/core/lexer.mjs +16 -2
  20. package/src/core/parser.mjs +200 -15
  21. package/src/core/project-root.mjs +18 -0
  22. package/src/core/project.mjs +15 -18
  23. package/src/core/react-run.mjs +2 -2
  24. package/src/core/runtime-go/thunder_runtime.go +269 -1
  25. package/src/core/runtime-python.mjs +365 -3
  26. package/src/core/runtime-typescript.mjs +150 -5
  27. package/src/core/rust-run.mjs +2 -2
  28. package/src/core/serving.mjs +12 -0
  29. package/src/core/store-format.mjs +110 -0
  30. package/src/core/target-go.mjs +10 -3
  31. package/src/core/target-python.mjs +38 -5
  32. package/src/core/target-typescript.mjs +62 -6
  33. package/src/core/typescript-run.mjs +6 -4
  34. package/src/core-changes-fs.mjs +28 -0
  35. package/src/core-changes.d.mts +67 -0
  36. package/src/core-changes.mjs +603 -0
  37. package/src/core-rules.mjs +146 -0
  38. package/src/core-services.d.mts +4 -0
  39. package/src/core-services.mjs +49 -0
  40. package/src/emit.mjs +1 -1
  41. package/src/evidence.mjs +28 -0
  42. package/src/examples.d.mts +21 -0
  43. package/src/examples.mjs +175 -0
  44. package/src/index.d.ts +4 -0
  45. package/src/index.mjs +4 -0
  46. package/src/mcp.mjs +42 -3
  47. package/src/program.d.mts +4 -0
  48. package/src/program.mjs +4 -0
  49. package/src/read-repo-fs.mjs +2 -1
  50. package/src/review.mjs +69 -3
  51. package/src/system.mjs +1 -1
  52. package/src/trace-cli.mjs +8 -3
  53. package/src/trace-fs.mjs +29 -3
  54. package/src/trace.mjs +23 -7
@@ -0,0 +1,28 @@
1
+ // Reading Thunder Core files from disk for core-changes.mjs (which is browser-safe and reads nothing itself).
2
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
3
+ import { join, relative, sep } from 'node:path';
4
+ import { isCoreProgram } from './core-changes.mjs';
5
+
6
+ const SKIP = new Set(['node_modules', '.git', 'generated', 'data', 'dist', 'build', '.thunder']);
7
+
8
+ /** The Thunder Core programs in a file or folder (recursive), as [{ path, source }] with paths relative to `base`. */
9
+ export function coreFilesIn(target, base = target) {
10
+ const out = [];
11
+ const add = (full) => {
12
+ if (!full.endsWith('.thunder')) return;
13
+ const source = readFileSync(full, 'utf8');
14
+ const path = relative(base, full).split(sep).join('/') || full.split(sep).pop();
15
+ if (isCoreProgram(path, source)) out.push({ path, source });
16
+ };
17
+ const walk = (dir) => {
18
+ for (const name of readdirSync(dir).sort()) {
19
+ if (SKIP.has(name)) continue;
20
+ const full = join(dir, name);
21
+ const st = statSync(full);
22
+ if (st.isDirectory()) walk(full); else add(full);
23
+ if (out.length >= 500) return;
24
+ }
25
+ };
26
+ if (statSync(target).isDirectory()) walk(target); else add(target);
27
+ return out;
28
+ }
@@ -0,0 +1,67 @@
1
+ // Types for core-changes.mjs: behaviour changes in Thunder Core programs, and what to look at again.
2
+
3
+ export const CORE_CHANGES_SCHEMA: 'thunder-core-changes-v1';
4
+ export const AFFECTED_SCHEMA: 'thunder-affected-v1';
5
+
6
+ export interface CoreFile { path: string; source: string }
7
+
8
+ /** A rule another one reaches: where it is, and the rules in between (via). */
9
+ export interface CoreRef { id: string; subject: string; kind: string; file: string; line: number; via?: string[]; test?: 'passes' | 'fails' }
10
+
11
+ export interface CoreBehaviourGroup {
12
+ /** "now a review Refund instead of an approved Refund", or "still a review Refund, but its reason is now …" */
13
+ says: string;
14
+ /** The input that decides it, as the values tried: "amount is from $50.00 to $99.99". Null when no one input does. */
15
+ where: string | null;
16
+ count: number;
17
+ example: string;
18
+ }
19
+
20
+ /** Both versions run on the same inputs: tested evidence on those inputs, not a proof. */
21
+ export type CoreBehaviour = { why: string } | { tried: number; unknown: number; stopped: boolean; changed: number; groups: CoreBehaviourGroup[] };
22
+
23
+ export interface CoreChange {
24
+ /** A stable name from what the rule is: "function:decide refund", "keep:review limit", "endpoint:POST /orders". */
25
+ id: string;
26
+ kind: 'function' | 'endpoint' | 'keep' | 'record' | 'never' | 'store' | 'test' | 'main' | 'file';
27
+ subject: string;
28
+ change: 'added' | 'removed' | 'renamed' | 'changed' | 'affected' | 'not-compiled';
29
+ severity: 'risk' | 'meaning';
30
+ file: string;
31
+ line: number;
32
+ says: string;
33
+ before: string[] | null;
34
+ after: string[] | null;
35
+ behaviour?: CoreBehaviour;
36
+ /** For an affected function: the changed rule it reaches, and the rules in between. */
37
+ through?: string[];
38
+ affects: CoreRef[];
39
+ }
40
+
41
+ export interface CoreChanges {
42
+ schema: 'thunder-core-changes-v1';
43
+ files: string[];
44
+ changes: CoreChange[];
45
+ unchanged: number;
46
+ problems: Array<{ file: string; diagnostics: Array<{ line: number; code: string; message: string }> }>;
47
+ }
48
+
49
+ export interface Affected {
50
+ schema: 'thunder-affected-v1';
51
+ of: CoreRef[];
52
+ unknown: string[];
53
+ functions: CoreRef[];
54
+ endpoints: CoreRef[];
55
+ tests: CoreRef[];
56
+ examples: Array<{ file: string; line: number; test: string; says: string | null; reaches: string }>;
57
+ rules: Array<CoreRef & { usedBy: string }>;
58
+ stored: Array<CoreRef & { usedBy: string }>;
59
+ }
60
+
61
+ export function isCoreProgram(path: string, source: string): boolean;
62
+ export function coreChanges(oldFiles: CoreFile[], newFiles: CoreFile[]): CoreChanges;
63
+ export function affectedBy(files: CoreFile[], change: string | string[]): Affected;
64
+ export function renderAffected(r: Affected): string;
65
+
66
+ /** Thunder Trace impact with what changes in a changed Thunder Core endpoint's answers (`behaviour` on route findings). */
67
+ export function withCoreBehaviour<T extends { findings: unknown[]; note: string }>(impact: T, byRepo: Map<string, CoreChanges>): T;