@skillstech/thunderlang 1.7.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +153 -1
  2. package/README.md +15 -3
  3. package/dist/core.cjs +303 -41
  4. package/dist/index.cjs +9906 -1387
  5. package/dist/learn.cjs +1420 -93
  6. package/package.json +17 -15
  7. package/src/cli-main.mjs +381 -149
  8. package/src/core/ThunderRuntime.cs +22 -1
  9. package/src/core/check.mjs +320 -6
  10. package/src/core/cli.mjs +60 -8
  11. package/src/core/csharp-run.mjs +2 -2
  12. package/src/core/diagnostics.mjs +9 -0
  13. package/src/core/engine-core.mjs +148 -19
  14. package/src/core/engine-values.mjs +3 -0
  15. package/src/core/engine.mjs +131 -7
  16. package/src/core/from-python.mjs +1 -1
  17. package/src/core/go-run.mjs +5 -3
  18. package/src/core/index.mjs +12 -3
  19. package/src/core/java/thunder/ThunderRuntime.java +1 -0
  20. package/src/core/java-run.mjs +2 -2
  21. package/src/core/kind.mjs +6 -0
  22. package/src/core/lexer.mjs +16 -2
  23. package/src/core/parser.mjs +215 -29
  24. package/src/core/project-root.mjs +18 -0
  25. package/src/core/project.mjs +34 -16
  26. package/src/core/react-run.mjs +2 -2
  27. package/src/core/runtime-go/thunder_runtime.go +310 -2
  28. package/src/core/runtime-python.mjs +365 -3
  29. package/src/core/runtime-typescript.mjs +150 -5
  30. package/src/core/rust/thunder_runtime.rs +1 -0
  31. package/src/core/rust-run.mjs +2 -2
  32. package/src/core/serving.mjs +12 -0
  33. package/src/core/store-format.mjs +110 -0
  34. package/src/core/target-csharp.mjs +14 -0
  35. package/src/core/target-go.mjs +24 -3
  36. package/src/core/target-java.mjs +14 -0
  37. package/src/core/target-python.mjs +46 -5
  38. package/src/core/target-rust.mjs +14 -0
  39. package/src/core/target-typescript.mjs +76 -6
  40. package/src/core/typescript-run.mjs +6 -4
  41. package/src/core-changes-fs.mjs +28 -0
  42. package/src/core-changes.d.mts +67 -0
  43. package/src/core-changes.mjs +603 -0
  44. package/src/core-rules.mjs +146 -0
  45. package/src/core-services.d.mts +4 -0
  46. package/src/core-services.mjs +49 -0
  47. package/src/emit.mjs +3 -3
  48. package/src/evidence-words.d.mts +6 -0
  49. package/src/evidence-words.mjs +47 -0
  50. package/src/evidence.mjs +36 -1
  51. package/src/examples.d.mts +21 -0
  52. package/src/examples.mjs +175 -0
  53. package/src/index.d.ts +19 -0
  54. package/src/index.mjs +8 -1
  55. package/src/learn-lessons.mjs +1 -1
  56. package/src/lsp.mjs +110 -0
  57. package/src/mcp.mjs +47 -12
  58. package/src/obligations.d.mts +5 -0
  59. package/src/obligations.mjs +30 -2
  60. package/src/program.d.mts +7 -0
  61. package/src/program.mjs +7 -0
  62. package/src/read-repo-fs.mjs +2 -1
  63. package/src/review.mjs +75 -6
  64. package/src/same.mjs +16 -6
  65. package/src/scan-queries.mjs +2 -1
  66. package/src/symbols.d.mts +23 -0
  67. package/src/symbols.mjs +351 -0
  68. package/src/system.mjs +1 -1
  69. package/src/template.d.mts +31 -0
  70. package/src/template.mjs +189 -0
  71. package/src/trace-cli.mjs +8 -3
  72. package/src/trace-fs.mjs +29 -3
  73. package/src/trace.mjs +23 -7
package/src/cli-main.mjs CHANGED
@@ -13,103 +13,250 @@
13
13
 
14
14
  import { readFileSync, writeFileSync, mkdirSync, readdirSync, statSync, existsSync } from 'node:fs';
15
15
  import { basename, join, relative, dirname, resolve } from 'node:path';
16
- import { parseIntent, slug, subjectName, KNOWN_LENSES } from './parse.mjs';
17
- import { previewHumanContract, renderHumanContract } from './human-contract.mjs';
18
- import { previewPlainContract } from './plain-contract.mjs';
19
- import { thunderRepo, renderThunderRepo, parseGitHub, cloneGitHub } from './thunder-repo.mjs';
20
- import { thunderizeFiles, THUNDER_TEXT_EXT } from './thunderize.mjs';
21
- import { sameMeaning, renderSame } from './same.mjs';
22
- import { anchorReport } from './anchor.mjs';
23
- import { writeRule } from './write.mjs';
24
- import { thunderWrite } from './write-steps.mjs';
25
- import { readCode, searchReading } from './read.mjs';
26
- import { readRepo, searchRepo, groupByFile } from './read-repo.mjs';
27
- import { promoteDecision } from './promote.mjs';
28
- import { collectReadableFiles } from './read-repo-fs.mjs';
29
- import { accessFlow, accessText } from './flow/access.mjs';
30
- import { translateDecisions } from './translate.mjs';
31
- import {
32
- buildContractGraph, buildArchitectureGraph, buildImplementationPlan,
33
- semanticDiagnostics, buildProof, sha256, COMPILER_VERSION,
34
- } from './emit.mjs';
35
- import { toSarif } from './sarif.mjs';
36
- import { renderMarkdown, renderLensDoc, renderMermaid, renderTestplan } from './compile.mjs';
37
- import { getCompletions, getHover, getCodeActions, autocorrectSource } from './intellisense.mjs';
38
- import { startLspServer } from './lsp.mjs';
39
- import { startMcpServer } from './mcp.mjs';
40
- import { formatSource } from './format.mjs';
41
- import { applyEdits } from './patch.mjs';
42
- import { buildReport } from './report.mjs';
43
- import { scanProject } from './scan.mjs';
44
- import { VIEWS } from './scan-queries.mjs';
45
- import { guardianReport } from './guardian.mjs';
46
- import { simulateChange } from './simulate.mjs';
47
- import { verifyLedger, explain as ledgerExplain } from './ledger.mjs';
48
- import { verifyDiff } from './verify-diff.mjs';
49
- import { verifyRun, executedText, mergeTraces } from './executed.mjs';
50
- import { runtimeOverlay, runtimeText, fromTrace, fromStack, fromLogs, fromOtlp, parseStacks, explainError, countWords } from './running.mjs';
51
- import { thunderModel } from './model.mjs';
52
- import { LEVELS, readLevel, renderLevel, findFocus, nearestLevel } from './read-level.mjs';
53
- import { traceMain } from './trace-cli.mjs';
54
- import { passportMain } from './passport-cli.mjs';
55
- import { isWriteAcross, writeAcrossMain } from './write-across-cli.mjs';
56
- import { whyMain } from './why-cli.mjs';
57
- import { tryMain } from './try-cli.mjs';
58
- import { replayMain } from './replay-cli.mjs';
59
- import { homeText, helpFor, knownCommands, unknownCommandText, noProjectText, doctorMain, completionMain } from './cli-home.mjs';
60
- import { paint, paintHelp, paintThunder, useColor } from './term.mjs';
61
- import { coreMain } from './core/cli.mjs';
62
- import { behaviourCheck } from './behaviour.mjs';
63
- import { findProjectRoot } from './core/project.mjs';
64
- import { pythonToCore } from './core/from-python.mjs';
65
- import { guardSummary } from './guard.mjs';
66
- import { draftIntent } from './draft.mjs';
67
- import { liftSource, liftAll, liftRepo, languageForFile } from './lift.mjs';
68
- import { approveIntent, checkDrift, buildDriftHandoff } from './drift.mjs';
69
- import { buildMissionIndex } from './atlas.mjs';
70
- import { parseSelection, regionMetrics, selectCandidate } from './select.mjs';
71
- import { buildIntentGraph, safeGraph } from './intent-graph.mjs';
72
- import { buildAtlas, searchAtlas, expandNode } from './intent-atlas.mjs';
73
- import { buildReviewAtlas, renderReviewBrief, reviewAtlasExitCode } from './review-atlas.mjs';
74
- import { buildFocusGraph, intentBrief, makeScope } from './focus.mjs';
75
- import { comprehensionLevel, comprehensionReport, LEVELS as COMPREHENSION_LEVELS } from './comprehension.mjs';
76
- import { twelveFactorReport } from './twelve-factor.mjs';
77
- import { GENERATORS, generateWithDiagnostics } from './codegen.mjs';
78
- import { changeReport } from './changes.mjs';
79
16
  import { execSync, execFileSync, spawnSync } from 'node:child_process';
80
- import { diffGraphs, mergeGraphs } from './semantic-diff.mjs';
81
- import { applyWaivers, governanceDiagnostics } from './governance.mjs';
82
- import { exportIntent, EXPORT_FORMATS } from './exporters.mjs';
83
- import { evaluateDecision, simulateLifecycle } from './runtime.mjs';
84
- import { runProperties } from './property.mjs';
85
- import { runMutations } from './mutate.mjs';
86
- import { thunderReview, renderReview } from './review.mjs';
87
- import { buildConformance } from './conformance.mjs';
88
- import { semanticCoverage } from './coverage.mjs';
89
- import { runTypescriptTarget } from './target-ts.mjs';
90
- import { runPythonTarget, pythonAvailable } from './target-py.mjs';
91
- import { runCSharpTarget, csharpAvailable } from './target-cs.mjs';
92
- import { runJavaTarget, javaAvailable } from './target-java.mjs';
93
- import { runGoTarget, goAvailable } from './target-go.mjs';
94
- import { runRustTarget, rustAvailable } from './target-rust.mjs';
95
- import { runKotlinTarget, kotlinAvailable } from './target-kotlin.mjs';
96
- import { runScalaTarget, scalaAvailable } from './target-scala.mjs';
97
- import { runElixirTarget, elixirAvailable } from './target-elixir.mjs';
98
- import { errorResult, runFailure } from './target-result.mjs';
99
- import { byText } from './text-order.mjs';
17
+ // <lazy-imports> generated by scripts/lazy-cli.mjs: run it after changing imports or commands
18
+ // Thunder's own modules, loaded by preload(cmd) only for the commands that use them (see that script for how).
19
+ let LANGUAGE_VERSION, foldObligations, resolveObligations, templateOf, parseIntent, slug, subjectName,
20
+ KNOWN_LENSES, previewHumanContract, renderHumanContract, previewPlainContract, thunderRepo,
21
+ renderThunderRepo, parseGitHub, cloneGitHub, thunderizeFiles, THUNDER_TEXT_EXT, sameMeaning, renderSame,
22
+ anchorReport, writeRule, thunderWrite, readCode, searchReading, readRepo, searchRepo, groupByFile,
23
+ promoteDecision, collectReadableFiles, accessFlow, accessText, translateDecisions, buildContractGraph,
24
+ buildArchitectureGraph, buildImplementationPlan, semanticDiagnostics, buildProof, sha256,
25
+ COMPILER_VERSION, toSarif, renderMarkdown, renderLensDoc, renderMermaid, renderTestplan, getCompletions,
26
+ getHover, getCodeActions, autocorrectSource, startLspServer, startMcpServer, formatSource, applyEdits,
27
+ buildReport, scanProject, VIEWS, guardianReport, simulateChange, verifyLedger, ledgerExplain, verifyDiff,
28
+ verifyRun, executedText, mergeTraces, runtimeOverlay, runtimeText, fromTrace, fromStack, fromLogs,
29
+ fromOtlp, parseStacks, explainError, countWords, thunderModel, LEVELS, readLevel, renderLevel, findFocus,
30
+ nearestLevel, traceMain, passportMain, isWriteAcross, writeAcrossMain, whyMain, tryMain, replayMain,
31
+ homeText, helpFor, knownCommands, unknownCommandText, noProjectText, doctorMain, completionMain, paint,
32
+ paintHelp, paintThunder, useColor, coreMain, behaviourCheck, findProjectRoot, pythonToCore, guardSummary,
33
+ draftIntent, liftSource, liftAll, liftRepo, languageForFile, approveIntent, checkDrift, buildDriftHandoff,
34
+ buildMissionIndex, parseSelection, regionMetrics, selectCandidate, buildIntentGraph, safeGraph,
35
+ buildAtlas, searchAtlas, expandNode, buildReviewAtlas, renderReviewBrief, reviewAtlasExitCode,
36
+ buildFocusGraph, intentBrief, makeScope, comprehensionLevel, comprehensionReport, COMPREHENSION_LEVELS,
37
+ twelveFactorReport, GENERATORS, generateWithDiagnostics, changeReport, diffGraphs, mergeGraphs,
38
+ applyWaivers, governanceDiagnostics, exportIntent, EXPORT_FORMATS, evaluateDecision, simulateLifecycle,
39
+ runProperties, runMutations, thunderReview, renderReview, addServiceCallers, buildTrace, traceImpact,
40
+ readRepoDir, gitChanges, coreChanges, affectedBy, renderAffected, withCoreBehaviour, coreFilesIn,
41
+ buildConformance, semanticCoverage, runTypescriptTarget, runPythonTarget, pythonAvailable,
42
+ runCSharpTarget, csharpAvailable, runJavaTarget, javaAvailable, runGoTarget, goAvailable, runRustTarget,
43
+ rustAvailable, runKotlinTarget, kotlinAvailable, runScalaTarget, scalaAvailable, runElixirTarget,
44
+ elixirAvailable, errorResult, runFailure, byText, importIntent, importReport, detectFormat,
45
+ IMPORT_FORMATS, runTests, toEvidenceEvents, verifyDiffToEvidence, conformToEvidence, driftToEvidence,
46
+ behaviourToEvidence, evaluateOutcomes, analyzeStyle, intentProofJsonSchema, validateProof, graphToSource,
47
+ migrateGraph, validateGraph, SCHEMA_VERSION, NODE_TYPES, RELATIONSHIP_TYPES, DIAGNOSTIC_RULES,
48
+ ALL_DIAGNOSTICS, intentGraphJsonSchema, CLASSIFICATIONS, buildManifest, buildImplementationPrompt,
49
+ resolveState, productionGate, adoptRegion, parseMarkers, contractHash, implementationHash, recordDecision,
50
+ approvalFor, emptyApprovals, makeEvent, parseEventLog, serializeEventLog, recordEvent, timeline;
51
+ const LAZY = {
52
+ './core/kind.mjs': (m) => ({ LANGUAGE_VERSION } = m),
53
+ './obligations.mjs': (m) => ({ foldObligations, resolveObligations } = m),
54
+ './template.mjs': (m) => ({ templateOf } = m),
55
+ './parse.mjs': (m) => ({ parseIntent, slug, subjectName, KNOWN_LENSES } = m),
56
+ './human-contract.mjs': (m) => ({ previewHumanContract, renderHumanContract } = m),
57
+ './plain-contract.mjs': (m) => ({ previewPlainContract } = m),
58
+ './thunder-repo.mjs': (m) => ({ thunderRepo, renderThunderRepo, parseGitHub, cloneGitHub } = m),
59
+ './thunderize.mjs': (m) => ({ thunderizeFiles, THUNDER_TEXT_EXT } = m),
60
+ './same.mjs': (m) => ({ sameMeaning, renderSame } = m),
61
+ './anchor.mjs': (m) => ({ anchorReport } = m),
62
+ './write.mjs': (m) => ({ writeRule } = m),
63
+ './write-steps.mjs': (m) => ({ thunderWrite } = m),
64
+ './read.mjs': (m) => ({ readCode, searchReading } = m),
65
+ './read-repo.mjs': (m) => ({ readRepo, searchRepo, groupByFile } = m),
66
+ './promote.mjs': (m) => ({ promoteDecision } = m),
67
+ './read-repo-fs.mjs': (m) => ({ collectReadableFiles } = m),
68
+ './flow/access.mjs': (m) => ({ accessFlow, accessText } = m),
69
+ './translate.mjs': (m) => ({ translateDecisions } = m),
70
+ './emit.mjs': (m) => ({ buildContractGraph, buildArchitectureGraph, buildImplementationPlan, semanticDiagnostics, buildProof, sha256, COMPILER_VERSION } = m),
71
+ './sarif.mjs': (m) => ({ toSarif } = m),
72
+ './compile.mjs': (m) => ({ renderMarkdown, renderLensDoc, renderMermaid, renderTestplan } = m),
73
+ './intellisense.mjs': (m) => ({ getCompletions, getHover, getCodeActions, autocorrectSource } = m),
74
+ './lsp.mjs': (m) => ({ startLspServer } = m),
75
+ './mcp.mjs': (m) => ({ startMcpServer } = m),
76
+ './format.mjs': (m) => ({ formatSource } = m),
77
+ './patch.mjs': (m) => ({ applyEdits } = m),
78
+ './report.mjs': (m) => ({ buildReport } = m),
79
+ './scan.mjs': (m) => ({ scanProject } = m),
80
+ './scan-queries.mjs': (m) => ({ VIEWS } = m),
81
+ './guardian.mjs': (m) => ({ guardianReport } = m),
82
+ './simulate.mjs': (m) => ({ simulateChange } = m),
83
+ './ledger.mjs': (m) => ({ verifyLedger, explain: ledgerExplain } = m),
84
+ './verify-diff.mjs': (m) => ({ verifyDiff } = m),
85
+ './executed.mjs': (m) => ({ verifyRun, executedText, mergeTraces } = m),
86
+ './running.mjs': (m) => ({ runtimeOverlay, runtimeText, fromTrace, fromStack, fromLogs, fromOtlp, parseStacks, explainError, countWords } = m),
87
+ './model.mjs': (m) => ({ thunderModel } = m),
88
+ './read-level.mjs': (m) => ({ LEVELS, readLevel, renderLevel, findFocus, nearestLevel } = m),
89
+ './trace-cli.mjs': (m) => ({ traceMain } = m),
90
+ './passport-cli.mjs': (m) => ({ passportMain } = m),
91
+ './write-across-cli.mjs': (m) => ({ isWriteAcross, writeAcrossMain } = m),
92
+ './why-cli.mjs': (m) => ({ whyMain } = m),
93
+ './try-cli.mjs': (m) => ({ tryMain } = m),
94
+ './replay-cli.mjs': (m) => ({ replayMain } = m),
95
+ './cli-home.mjs': (m) => ({ homeText, helpFor, knownCommands, unknownCommandText, noProjectText, doctorMain, completionMain } = m),
96
+ './term.mjs': (m) => ({ paint, paintHelp, paintThunder, useColor } = m),
97
+ './core/cli.mjs': (m) => ({ coreMain } = m),
98
+ './behaviour.mjs': (m) => ({ behaviourCheck } = m),
99
+ './core/project-root.mjs': (m) => ({ findProjectRoot } = m),
100
+ './core/from-python.mjs': (m) => ({ pythonToCore } = m),
101
+ './guard.mjs': (m) => ({ guardSummary } = m),
102
+ './draft.mjs': (m) => ({ draftIntent } = m),
103
+ './lift.mjs': (m) => ({ liftSource, liftAll, liftRepo, languageForFile } = m),
104
+ './drift.mjs': (m) => ({ approveIntent, checkDrift, buildDriftHandoff } = m),
105
+ './atlas.mjs': (m) => ({ buildMissionIndex } = m),
106
+ './select.mjs': (m) => ({ parseSelection, regionMetrics, selectCandidate } = m),
107
+ './intent-graph.mjs': (m) => ({ buildIntentGraph, safeGraph } = m),
108
+ './intent-atlas.mjs': (m) => ({ buildAtlas, searchAtlas, expandNode } = m),
109
+ './review-atlas.mjs': (m) => ({ buildReviewAtlas, renderReviewBrief, reviewAtlasExitCode } = m),
110
+ './focus.mjs': (m) => ({ buildFocusGraph, intentBrief, makeScope } = m),
111
+ './comprehension.mjs': (m) => ({ comprehensionLevel, comprehensionReport, LEVELS: COMPREHENSION_LEVELS } = m),
112
+ './twelve-factor.mjs': (m) => ({ twelveFactorReport } = m),
113
+ './codegen.mjs': (m) => ({ GENERATORS, generateWithDiagnostics } = m),
114
+ './changes.mjs': (m) => ({ changeReport } = m),
115
+ './semantic-diff.mjs': (m) => ({ diffGraphs, mergeGraphs } = m),
116
+ './governance.mjs': (m) => ({ applyWaivers, governanceDiagnostics } = m),
117
+ './exporters.mjs': (m) => ({ exportIntent, EXPORT_FORMATS } = m),
118
+ './runtime.mjs': (m) => ({ evaluateDecision, simulateLifecycle } = m),
119
+ './property.mjs': (m) => ({ runProperties } = m),
120
+ './mutate.mjs': (m) => ({ runMutations } = m),
121
+ './review.mjs': (m) => ({ thunderReview, renderReview, addServiceCallers } = m),
122
+ './trace.mjs': (m) => ({ buildTrace, traceImpact } = m),
123
+ './trace-fs.mjs': (m) => ({ readRepoDir, gitChanges } = m),
124
+ './core-changes.mjs': (m) => ({ coreChanges, affectedBy, renderAffected, withCoreBehaviour } = m),
125
+ './core-changes-fs.mjs': (m) => ({ coreFilesIn } = m),
126
+ './conformance.mjs': (m) => ({ buildConformance } = m),
127
+ './coverage.mjs': (m) => ({ semanticCoverage } = m),
128
+ './target-ts.mjs': (m) => ({ runTypescriptTarget } = m),
129
+ './target-py.mjs': (m) => ({ runPythonTarget, pythonAvailable } = m),
130
+ './target-cs.mjs': (m) => ({ runCSharpTarget, csharpAvailable } = m),
131
+ './target-java.mjs': (m) => ({ runJavaTarget, javaAvailable } = m),
132
+ './target-go.mjs': (m) => ({ runGoTarget, goAvailable } = m),
133
+ './target-rust.mjs': (m) => ({ runRustTarget, rustAvailable } = m),
134
+ './target-kotlin.mjs': (m) => ({ runKotlinTarget, kotlinAvailable } = m),
135
+ './target-scala.mjs': (m) => ({ runScalaTarget, scalaAvailable } = m),
136
+ './target-elixir.mjs': (m) => ({ runElixirTarget, elixirAvailable } = m),
137
+ './target-result.mjs': (m) => ({ errorResult, runFailure } = m),
138
+ './text-order.mjs': (m) => ({ byText } = m),
139
+ './importers.mjs': (m) => ({ importIntent, importReport, detectFormat, IMPORT_FORMATS } = m),
140
+ './testing.mjs': (m) => ({ runTests } = m),
141
+ './evidence.mjs': (m) => ({ toEvidenceEvents, verifyDiffToEvidence, conformToEvidence, driftToEvidence, behaviourToEvidence } = m),
142
+ './outcome.mjs': (m) => ({ evaluateOutcomes } = m),
143
+ './style.mjs': (m) => ({ analyzeStyle } = m),
144
+ './proof-schema.mjs': (m) => ({ intentProofJsonSchema, validateProof } = m),
145
+ './graph-source.mjs': (m) => ({ graphToSource } = m),
146
+ './migrate.mjs': (m) => ({ migrateGraph, validateGraph } = m),
147
+ './intent-schema.mjs': (m) => ({ SCHEMA_VERSION, NODE_TYPES, RELATIONSHIP_TYPES, DIAGNOSTIC_RULES, ALL_DIAGNOSTICS, intentGraphJsonSchema } = m),
148
+ './classification.mjs': (m) => ({ CLASSIFICATIONS } = m),
149
+ './ai.mjs': (m) => ({ buildManifest, buildImplementationPrompt, resolveState, productionGate, adoptRegion, parseMarkers, contractHash, implementationHash, recordDecision, approvalFor, emptyApprovals, makeEvent } = m),
150
+ './ai-events.mjs': (m) => ({ parseEventLog, serializeEventLog, recordEvent, timeline } = m),
151
+ };
152
+ // The modules each command can reach. A command that is not listed loads them all.
153
+ const COMMAND_MODULES = {
154
+ "": [18, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
155
+ "--help": [18, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
156
+ "--version": [0, 18, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
157
+ "-h": [18, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
158
+ "-v": [0, 18, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
159
+ "12factor": [3, 28, 43, 44, 47, 60, 76, 77, 78, 79, 80, 81, 82, 83, 84],
160
+ "affected": [28, 43, 44, 47, 72, 73, 76, 77, 78, 79, 80, 81, 82, 83, 84],
161
+ "ai": [3, 28, 43, 44, 47, 51, 54, 76, 77, 78, 79, 80, 81, 82, 83, 84, 97, 98],
162
+ "anchor": [9, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
163
+ "apply-fix": [3, 18, 21, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
164
+ "approve": [28, 43, 44, 47, 52, 76, 77, 78, 79, 80, 81, 82, 83, 84],
165
+ "atlas": [3, 28, 43, 44, 47, 55, 56, 57, 76, 77, 78, 79, 80, 81, 82, 83, 84],
166
+ "build": [3, 18, 20, 27, 28, 43, 44, 45, 47, 55, 76, 77, 78, 79, 80, 81, 82, 83, 84, 97],
167
+ "changes": [3, 28, 43, 44, 47, 55, 62, 76, 77, 78, 79, 80, 81, 82, 83, 84],
168
+ "check": [3, 18, 19, 27, 28, 43, 44, 45, 47, 64, 76, 77, 78, 79, 80, 81, 82, 83, 84],
169
+ "code-actions": [3, 18, 21, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
170
+ "completion": [28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
171
+ "completions": [3, 18, 21, 27, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
172
+ "comprehension": [3, 28, 43, 44, 47, 59, 76, 77, 78, 79, 80, 81, 82, 83, 84],
173
+ "conform": [3, 18, 28, 43, 44, 47, 74, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 89],
174
+ "diff": [3, 28, 43, 44, 47, 55, 56, 63, 76, 77, 78, 79, 80, 81, 82, 83, 84],
175
+ "docs": [3, 20, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
176
+ "doctor": [18, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
177
+ "draft": [28, 43, 44, 47, 50, 76, 77, 78, 79, 80, 81, 82, 83, 84],
178
+ "drift": [3, 18, 28, 43, 44, 47, 51, 52, 76, 77, 78, 79, 80, 81, 82, 83, 84, 89],
179
+ "edit": [25, 27, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
180
+ "evidence": [1, 3, 18, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 89],
181
+ "explain": [28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 95],
182
+ "export": [3, 28, 43, 44, 47, 65, 76, 77, 78, 79, 80, 81, 82, 83, 84],
183
+ "fmt": [24, 27, 28, 43, 44, 45, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
184
+ "focus": [3, 28, 43, 44, 47, 55, 56, 58, 76, 77, 78, 79, 80, 81, 82, 83, 84],
185
+ "format": [3, 18, 27, 28, 43, 44, 45, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
186
+ "gen": [3, 28, 43, 44, 47, 61, 76, 77, 78, 79, 80, 81, 82, 83, 84],
187
+ "graph": [3, 18, 27, 28, 43, 44, 47, 55, 76, 77, 78, 79, 80, 81, 82, 83, 84],
188
+ "guard": [3, 28, 43, 44, 47, 49, 76, 77, 78, 79, 80, 81, 82, 83, 84],
189
+ "guardian": [28, 29, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
190
+ "handoff": [3, 28, 43, 44, 47, 52, 76, 77, 78, 79, 80, 81, 82, 83, 84],
191
+ "help": [18, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
192
+ "hover": [3, 18, 21, 27, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
193
+ "human": [4, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
194
+ "impact": [28, 30, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
195
+ "import": [3, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 87],
196
+ "index": [28, 43, 44, 47, 53, 76, 77, 78, 79, 80, 81, 82, 83, 84],
197
+ "init": [28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
198
+ "ledger": [28, 31, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
199
+ "lift": [3, 28, 43, 44, 47, 51, 76, 77, 78, 79, 80, 81, 82, 83, 84],
200
+ "lsp": [22, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
201
+ "mcp": [23, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
202
+ "merge": [3, 28, 43, 44, 47, 55, 56, 63, 76, 77, 78, 79, 80, 81, 82, 83, 84],
203
+ "migrate": [3, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 94],
204
+ "mission": [3, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86],
205
+ "new": [28, 43, 44, 45, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
206
+ "notes": [3, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
207
+ "outcomes": [3, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 90],
208
+ "passport": [28, 38, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
209
+ "plain": [5, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
210
+ "proof": [3, 18, 27, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 92],
211
+ "prove": [1, 3, 18, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
212
+ "read": [3, 4, 12, 13, 14, 15, 16, 17, 28, 35, 36, 43, 44, 47, 48, 76, 77, 78, 79, 80, 81, 82, 83, 84],
213
+ "replay": [28, 42, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
214
+ "repo": [6, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
215
+ "report": [26, 27, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
216
+ "review": [18, 28, 43, 44, 47, 69, 70, 71, 72, 76, 77, 78, 79, 80, 81, 82, 83, 84, 89],
217
+ "rules": [28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 95],
218
+ "run": [3, 28, 43, 44, 45, 47, 66, 76, 77, 78, 79, 80, 81, 82, 83, 84],
219
+ "runtime": [15, 28, 33, 34, 35, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
220
+ "same": [3, 8, 15, 18, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
221
+ "scan": [27, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
222
+ "schema": [28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 95, 96],
223
+ "simulate": [3, 28, 43, 44, 47, 66, 76, 77, 78, 79, 80, 81, 82, 83, 84],
224
+ "source": [3, 28, 43, 44, 47, 55, 76, 77, 78, 79, 80, 81, 82, 83, 84, 93],
225
+ "style": [3, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 91],
226
+ "template": [2, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
227
+ "test": [1, 3, 28, 43, 44, 45, 47, 67, 68, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 88],
228
+ "text": [5, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
229
+ "thunderize": [6, 7, 15, 28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
230
+ "trace": [28, 37, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
231
+ "try": [28, 41, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
232
+ "twelve-factor": [3, 28, 43, 44, 47, 60, 76, 77, 78, 79, 80, 81, 82, 83, 84],
233
+ "validate": [28, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 94],
234
+ "verify": [3, 18, 28, 33, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84, 92],
235
+ "verify-diff": [3, 18, 28, 32, 43, 44, 47, 51, 76, 77, 78, 79, 80, 81, 82, 83, 84, 89],
236
+ "version": [0, 18, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
237
+ "why": [28, 40, 43, 44, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
238
+ "write": [10, 11, 28, 39, 43, 44, 46, 47, 76, 77, 78, 79, 80, 81, 82, 83, 84],
239
+ };
240
+ async function preload(cmd) {
241
+ const specs = Object.keys(LAZY);
242
+ const wanted = COMMAND_MODULES[cmd ?? '']?.map((i) => specs[i]) ?? specs;
243
+ await Promise.all(wanted.map(async (s) => LAZY[s](await import(s))));
244
+ }
245
+ // </lazy-imports>
100
246
 
101
247
  // The live-target registry: one entry per canonical target that can be compiled + executed.
102
248
  // `available()` is a (cached) toolchain probe; TypeScript/JS runs in-process so it is always live.
249
+ // Each entry calls through an arrow, so a runner's module loads only for the commands that run targets.
103
250
  const LIVE_TARGETS = [
104
- { key: 'typescript', run: runTypescriptTarget, available: () => true },
105
- { key: 'python', run: runPythonTarget, available: pythonAvailable },
106
- { key: 'csharp', run: runCSharpTarget, available: csharpAvailable },
107
- { key: 'java', run: runJavaTarget, available: javaAvailable },
108
- { key: 'go', run: runGoTarget, available: goAvailable },
109
- { key: 'rust', run: runRustTarget, available: rustAvailable },
110
- { key: 'kotlin', run: runKotlinTarget, available: kotlinAvailable },
111
- { key: 'scala', run: runScalaTarget, available: scalaAvailable },
112
- { key: 'elixir', run: runElixirTarget, available: elixirAvailable },
251
+ { key: 'typescript', run: (ast) => runTypescriptTarget(ast), available: () => true },
252
+ { key: 'python', run: (ast) => runPythonTarget(ast), available: () => pythonAvailable() },
253
+ { key: 'csharp', run: (ast) => runCSharpTarget(ast), available: () => csharpAvailable() },
254
+ { key: 'java', run: (ast) => runJavaTarget(ast), available: () => javaAvailable() },
255
+ { key: 'go', run: (ast) => runGoTarget(ast), available: () => goAvailable() },
256
+ { key: 'rust', run: (ast) => runRustTarget(ast), available: () => rustAvailable() },
257
+ { key: 'kotlin', run: (ast) => runKotlinTarget(ast), available: () => kotlinAvailable() },
258
+ { key: 'scala', run: (ast) => runScalaTarget(ast), available: () => scalaAvailable() },
259
+ { key: 'elixir', run: (ast) => runElixirTarget(ast), available: () => elixirAvailable() },
113
260
  ];
114
261
  const LIVE_BY_KEY = new Map(LIVE_TARGETS.map((t) => [t.key, t]));
115
262
  LIVE_BY_KEY.set('javascript', LIVE_BY_KEY.get('typescript')); // js is the same in-process runner
@@ -161,22 +308,6 @@ function caseResultsOf(ast, run) {
161
308
  const caseLine = (c) => (c.status === 'error'
162
309
  ? `ERROR ${c.key} , ${c.kind === 'not-translated' ? 'not translated' : c.kind === 'missing-input' ? 'missing input' : c.kind}: ${c.message}`
163
310
  : `FAIL ${c.key} , expected ${c.expected}, got ${c.actual === null ? 'null' : c.actual}`);
164
- import { importIntent, importReport, detectFormat, IMPORT_FORMATS } from './importers.mjs';
165
- import { runTests } from './testing.mjs';
166
- import { resolveObligations } from './obligations.mjs';
167
- import { toEvidenceEvents, verifyDiffToEvidence, conformToEvidence, driftToEvidence } from './evidence.mjs';
168
- import { evaluateOutcomes } from './outcome.mjs';
169
- import { analyzeStyle } from './style.mjs';
170
- import { intentProofJsonSchema, validateProof } from './proof-schema.mjs';
171
- import { graphToSource } from './graph-source.mjs';
172
- import { migrateGraph, validateGraph } from './migrate.mjs';
173
- import { SCHEMA_VERSION, NODE_TYPES, RELATIONSHIP_TYPES, DIAGNOSTIC_RULES, ALL_DIAGNOSTICS, intentGraphJsonSchema } from './intent-schema.mjs';
174
- import { CLASSIFICATIONS } from './classification.mjs';
175
- import {
176
- buildManifest, buildImplementationPrompt, resolveState, productionGate, adoptRegion, parseMarkers,
177
- contractHash, implementationHash, recordDecision, approvalFor, emptyApprovals, makeEvent,
178
- } from './ai.mjs';
179
- import { parseEventLog, serializeEventLog, recordEvent, timeline } from './ai-events.mjs';
180
311
 
181
312
  // Recursively collect supported source files, skipping vendored / build dirs.
182
313
  // Kept in sync with lift.mjs languageForFile(): every language the lift adapters support,
@@ -254,7 +385,8 @@ function collectIntents(root, acc = []) {
254
385
  // compiler, environment) tuple. These helpers capture that tuple so `verify` can mark a proof STALE.
255
386
  /**
256
387
  * Read the files that changed between two commits (or a commit and the working tree, when head is null) and review
257
- * them in Thunder. Only git is run (show, diff, ls-files): nothing is fetched and nothing is executed.
388
+ * them in Thunder. Only git is run (show, diff, ls-files, ls-tree) and nothing is fetched. Thunder Core programs are run
389
+ * on the Thunder engine inside the review (no files, network, or saved data; step and time limits) to compare answers.
258
390
  */
259
391
  function reviewGit(base, head, paths = []) {
260
392
  const git = (...a) => execFileSync('git', a, { encoding: 'utf8', maxBuffer: 256 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] });
@@ -283,7 +415,45 @@ function reviewGit(base, head, paths = []) {
283
415
  if (c.old) { const s = at(base, c.old); if (s != null) oldFiles.push({ path: c.old, source: s }); }
284
416
  if (c.new) { const s = head ? at(head, c.new) : disk(c.new); if (s != null) newFiles.push({ path: c.new, source: s }); }
285
417
  }
286
- return { ...thunderReview(oldFiles, newFiles), base, head: head ?? 'working tree' };
418
+ // A changed Thunder Core program is compared with the rest of its project (the folder above src/ or tests/, or its
419
+ // own folder): its tests are run before and after, and what uses a change is listed.
420
+ const context = { old: [], new: [] };
421
+ const changed = new Set(changes.flatMap((c) => [c.old, c.new]).filter(Boolean));
422
+ const roots = new Set(changes.flatMap((c) => [c.old, c.new]).filter((p) => p && p.endsWith('.thunder')).map((p) => {
423
+ const m = /(^|\/)(src|tests)\//.exec(p);
424
+ return m ? p.slice(0, m.index + m[1].length) : p.includes('/') ? p.slice(0, p.lastIndexOf('/') + 1) : '';
425
+ }));
426
+ const list = (args) => { try { return git(...args).split('\0').filter((p) => p.endsWith('.thunder')); } catch { return []; } };
427
+ for (const root of roots) {
428
+ const where = root ? [root] : ['.'];
429
+ const before = list(['ls-tree', '-r', '-z', '--name-only', base, '--', ...where]);
430
+ const after = head ? list(['ls-tree', '-r', '-z', '--name-only', head, '--', ...where]) : list(['ls-files', '-z', '--cached', '--others', '--exclude-standard', '--', ...where]);
431
+ for (const p of before.filter((x) => !changed.has(x)).slice(0, 300)) { const s = at(base, p); if (s != null) context.old.push({ path: p, source: s }); }
432
+ for (const p of after.filter((x) => !changed.has(x)).slice(0, 300)) { const s = head ? at(head, p) : disk(p); if (s != null) context.new.push({ path: p, source: s }); }
433
+ }
434
+ const review = Object.assign(thunderReview(oldFiles, newFiles, { core: coreChanges, context }), { base, head: head ?? 'working tree' });
435
+ Object.defineProperty(review, 'root', { value: root, enumerable: false }); // for --services; not in the JSON
436
+ return review;
437
+ }
438
+
439
+ /**
440
+ * thunder review --services <folder,…>: the other services are read and linked with Thunder Trace, and each changed
441
+ * endpoint (or a Thunder Core endpoint whose rules changed) that one of them calls becomes an item naming the callers.
442
+ * Trace reads the folders as they are on disk, so the new side must be the working tree (or the commit checked out).
443
+ */
444
+ function withServices(review, base, head, folders) {
445
+ if (head) {
446
+ const at = (ref) => execFileSync('git', ['rev-parse', `${ref}^{commit}`], { encoding: 'utf8' }).trim();
447
+ if (at(head) !== at('HEAD')) throw new Error(`--services reads the folders as they are on disk, so check out ${head} first (or leave out the head to review the working tree).`);
448
+ }
449
+ const self = readRepoDir(review.root);
450
+ const others = folders.map((d) => readRepoDir(d));
451
+ if (others.some((o) => o.root === self.root)) throw new Error('--services lists other services; this repository is already the one reviewed.');
452
+ const trace = buildTrace([self, ...others]);
453
+ const g = gitChanges(self, base);
454
+ const impact = withCoreBehaviour(traceImpact(trace, g.changes ?? []), new Map(review.core ? [[self.name, review.core]] : []));
455
+ addServiceCallers(review, impact);
456
+ review.services = { repos: [self, ...others].map((x) => x.name), links: trace.links.length, findings: impact.findings.length };
287
457
  }
288
458
 
289
459
  const gitCmd = (c) => { try { return execSync(`git ${c}`, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] }).trim() || null; } catch { return null; } };
@@ -347,6 +517,8 @@ function parseArgs(argv) {
347
517
  else if (a === '--focus') args.focus = argv[++i];
348
518
  else if (a === '--kind') args.kind = (argv[++i] || '').split(',').map((k) => k.trim()).filter(Boolean);
349
519
  else if (a === '--in') args.inLang = argv[++i];
520
+ else if (a === '--name') args.name = argv[++i];
521
+ else if (a === '--gives') args.gives = argv[++i];
350
522
  else if (a === '--answer') args.answer = argv[++i];
351
523
  else if (a === '--promote') args.promote = argv[++i];
352
524
  else if (a === '--input') args.input = argv[++i];
@@ -359,6 +531,7 @@ function parseArgs(argv) {
359
531
  else if (a === '--base') args.base = argv[++i];
360
532
  else if (a === '--head') args.head = argv[++i];
361
533
  else if (a === '--paths') args.paths = (argv[++i] || '').split(/[,\n]/).map((p) => p.trim()).filter(Boolean);
534
+ else if (a === '--services') args.services = (argv[++i] || '').split(/[,\n]/).map((p) => p.trim()).filter(Boolean);
362
535
  else if (a === '--inputs') args.inputs = argv[++i];
363
536
  else if (a === '--events') args.events = (argv[++i] || '').split(',').map((s) => s.trim()).filter(Boolean);
364
537
  else if (a === '--decision') args.decision = argv[++i];
@@ -488,6 +661,10 @@ Write and run programs (Thunder Core, docs/core.md)
488
661
  --target csharp compiles to C# (generated/csharp/; builds and runs with the .NET 8+ SDK)
489
662
  --target go compiles to Go (generated/go/; needs the go toolchain to run)
490
663
  --target java compiles to Java (generated/java/; runs with a JDK 17+)
664
+ template <file> <data type> [--name "<function>"] [--gives <kind>] [--write] [--json]
665
+ the Design Recipe's template: the shape of a function that takes the data type, written
666
+ from its definition (a case per alternative, each field by name, the call to itself for
667
+ recursive parts, and holes for the answers you fill in); --write adds it to the file
491
668
 
492
669
  Read and understand code
493
670
  read <file|dir> [--search q] [--kind decision,function,error,test] [--in <lang>] [--from <lang>] [--json]
@@ -504,9 +681,16 @@ Read and understand code
504
681
  try <file> [--focus "<rule>"] [--with "name=value, …"] [--json] try a rule from your code with your own values: the answer and why (rules only; nothing changes)
505
682
  why <run.json> [--step n] [--json] what an AI agent did and why it stopped, in plain words, from its OpenTelemetry record
506
683
  same <old> <new> [--json] does the new code mean the same as the old? (files or folders, any languages; rules are run on every edge case)
507
- review <base-ref> [head-ref] [--format markdown|json] [--paths <glob,...>] [--out <file>]
684
+ review <base-ref> [head-ref] [--format markdown|json] [--paths <glob,...>] [--services <folder,...>] [--out <file>]
508
685
  review in Thunder: what changed in meaning between two git commits (head: the working tree
509
- when omitted), as Markdown for a pull request comment; read from git, no network
686
+ when omitted), as Markdown for a pull request comment; read from git, no network.
687
+ Thunder Core programs are compared rule by rule, and run before and after.
688
+ --services: other services' folders; a changed endpoint they call is named, with its callers.
689
+ --evidence: the Thunder Core comparison as evidence-event-v1 (behaviour.compared)
690
+ affected <rule…> [--in <folder|file>] [--json]
691
+ what to look at again when a Thunder Core rule changes ("decide refund", "review limit",
692
+ "POST /orders"): the functions and endpoints that use it, the tests and examples that reach
693
+ it, the Never rules and stored lists they rely on; read only, nothing is run
510
694
  trace <folder…> [--json] [--out f] Thunder Trace: routes, events, tables, and packages linked across repositories, cited repo@sha:file:line
511
695
  trace impact <thing | --diff [--base ref]> <folder…> what a change can affect in other repositories (one hop, ranked by risk)
512
696
  passport <folder…> [--base ref] [--run "part: cmd"…] [--purpose …] an evidence record: behavior, links, effects, evidence with its limits, what is not verified
@@ -517,8 +701,9 @@ Read and understand code
517
701
  Change code
518
702
  write <file> --edit '<json>' [--edit …] | --edits <list.json|-> [--also <file>] [--apply] [--test "<cmd>"] [--candidate <file>] [--json]
519
703
  Writing in Thunder: change a step, question, Stop, input, or function in Thunder; the code is
520
- written as a minimal patch (TS/JS, Python, Go) and proven (the edited steps mean exactly
521
- the edit; everything else means the same). Conditions and values in Thunder's words
704
+ written as a minimal patch (TS/JS, Python, Go) and checked by comparing the code's trees:
705
+ the edited steps read exactly as the edit says and the rest is unchanged (Proven, about the
706
+ code's shape; --test runs your tests on its behaviour: Tested). Conditions and values in Thunder's words
522
707
  ("amount is at least 100", "name is nothing") or as code; steps by their line in thunder read.
523
708
  Dry run by default; --apply saves; --test runs a command on the changed code. Other cases
524
709
  print an instruction for an AI coding agent; --candidate checks code it wrote (AI-written).
@@ -628,7 +813,7 @@ function main() {
628
813
  const args = parseArgs(restArgv);
629
814
  const file = args._[0];
630
815
  if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
631
- console.log(`thunder ${COMPILER_VERSION} (the Thunder™ compiler, also called ThunderLang™)`);
816
+ console.log(`thunder ${COMPILER_VERSION} (the Thunder™ compiler, also called ThunderLang™), language ${LANGUAGE_VERSION}`);
632
817
  return;
633
818
  }
634
819
  const known = [...new Set([...knownCommands(HELP), ...Object.keys(VIEWS)])].sort();
@@ -663,8 +848,12 @@ function main() {
663
848
  if (cmd === 'replay') { replayMain(restArgv).then((code) => { process.exitCode = code; }); return; }
664
849
  // Thunder Core (programs you write and run): thunder new <dir>, and run/build/test/check/format inside a
665
850
  // project with thunder.toml (or with --core). Mission files fall through unchanged. See src/core/cli.mjs.
666
- const coreCode = coreMain(cmd, restArgv);
667
- if (coreCode !== null) { process.exitCode = coreCode; return; }
851
+ // (Only Core's own commands can be Core programs: the list is core/cli.mjs CORE_COMMANDS, kept equal by a test, and
852
+ // written out here so other commands don't load Thunder Core at all.)
853
+ if (['new', 'run', 'build', 'test', 'check', 'format', 'fmt'].includes(cmd)) {
854
+ const coreCode = coreMain(cmd, restArgv);
855
+ if (coreCode !== null) { process.exitCode = coreCode; return; }
856
+ }
668
857
  if (cmd === 'read') {
669
858
  try {
670
859
  if (!file) throw new Error('Use thunder read <file> [--search q] [--kind decision,function,error,test] [--in <lang>] [--json].');
@@ -800,16 +989,16 @@ function main() {
800
989
  if (r.after) { console.log('Thunder after:'); for (const l of r.after.split('\n')) console.log(` ${l}`); }
801
990
  console.log(`\n${r.author === 'ai' ? 'AI-written change (checked):' : 'Code change:'}\n`);
802
991
  process.stdout.write(r.patch);
803
- console.log('\nProof:');
804
- for (const c of r.proof.edited.checks) console.log(` edited ${c.member}: ${c.result === 'exact' ? 'reads exactly as the edit says' : c.result}`);
992
+ console.log('\nChecks (docs/evidence-words.md):');
993
+ for (const c of r.proof.edited.checks) console.log(` edited ${c.member}: ${c.result === 'exact' ? 'Proven: reads exactly as the edit says (its tree matches)' : `Violated: ${c.result}`}`);
805
994
  const u = r.proof.unchanged;
806
- console.log(` unchanged ${u.checked} other function${u.checked === 1 ? '' : 's'} in the changed file${Object.keys(r.files).length === 1 ? '' : 's'}: ${u.status === 'same' ? 'all mean the same' : u.status}`);
807
- if (r.proof.run) console.log(` run ${r.proof.run.command}: ${r.proof.run.passed ? 'passed' : `failed (exit ${r.proof.run.exit})`}`);
995
+ console.log(` unchanged ${u.checked} other function${u.checked === 1 ? '' : 's'} in the changed file${Object.keys(r.files).length === 1 ? '' : 's'}: ${u.status === 'same' ? 'Proven: unchanged (the same trees)' : `Violated: ${u.status}`}`);
996
+ if (r.proof.run) console.log(` run ${r.proof.run.command}: ${r.proof.run.passed ? 'Tested: passed' : `Violated: failed (exit ${r.proof.run.exit})`}`);
808
997
  if (r.proof.run && !r.proof.run.passed) console.log(r.proof.run.output);
809
998
  for (const b of r.proof.behaviour ?? []) {
810
999
  console.log(` behaviour ${b.function ?? ''}${b.function ? ': ' : ''}${b.status === 'changed' ? `${b.changes.length} of ${b.inputs} inputs give a different answer` : b.status === 'same' ? `all ${b.inputs} inputs give the same answer` : b.status === 'broken' ? `the changed file does not load (${b.reason})` : `not checked (${b.reason ?? b.says})`}`);
811
1000
  for (const ex of b.examples ?? []) console.log(` ${ex}`);
812
- if (b.status === 'same' || b.status === 'changed') console.log(' (tested on these inputs only; not a proof)');
1001
+ if (b.status === 'same' || b.status === 'changed') console.log(' (Tested: on these inputs only, not every input)');
813
1002
  }
814
1003
  console.log(`\n${r.says}`);
815
1004
  console.log(applied ? `\nSaved ${Object.keys(r.files).join(', ')}.` : broken ? '\nNot saved: the changed file does not load.' : r.proof?.run && !r.proof.run.passed ? '\nNot saved: the test command failed.' : '\nDry run; nothing was saved. Add --apply to save the change.');
@@ -897,12 +1086,59 @@ function main() {
897
1086
  if (args.format && !['markdown', 'json'].includes(args.format)) throw new Error(`--format ${args.format} is not one of markdown, json.`);
898
1087
  const json = args.json || args.format === 'json';
899
1088
  const r = reviewGit(base, head ?? null, args.paths ?? []);
1089
+ if (args.services) withServices(r, base, head, args.services);
1090
+ if (args.evidence) {
1091
+ // evidence-event-v1 for the shared proof spine: what the Thunder Core comparison found, safe-derived.
1092
+ console.log(JSON.stringify(behaviourToEvidence(r.core ?? { changes: [] }, { compilerVersion: COMPILER_VERSION, occurredAt: new Date().toISOString(), base, head: head ?? 'working tree' }), null, 2));
1093
+ return;
1094
+ }
900
1095
  const text = json ? JSON.stringify(r, null, 2) : renderReview(r, { footer: `<sub>\`thunder review ${base}${head ? ` ${head}` : ''}\` · Thunder compiler ${COMPILER_VERSION}</sub>` }).trimEnd();
901
1096
  if (args.outExplicit) { mkdirSync(dirname(resolve(args.out)), { recursive: true }); writeFileSync(args.out, `${text}\n`); console.log(`thunder review: ${r.says} Wrote ${args.out}.`); }
902
1097
  else console.log(text);
903
1098
  } catch (e) { console.error(`thunder review: ${e.message}`); process.exitCode = 2; }
904
1099
  return;
905
1100
  }
1101
+ if (cmd === 'template') {
1102
+ try {
1103
+ const [file, ...type] = args._;
1104
+ if (!file || !type.length) throw new Error('Use thunder template <file> <data type> [--name "<function>"] [--gives <kind>] [--json] [--write], for example: thunder template main.thunder Payment');
1105
+ if (!existsSync(file)) throw new Error(`${file} does not exist.`);
1106
+ const source = readFileSync(file, 'utf8');
1107
+ const r = templateOf(source, type.join(' '), { name: args.name ?? null, gives: args.gives ?? null, file });
1108
+ if (!r.ok) throw new Error(r.problem);
1109
+ if (args.json) console.log(JSON.stringify(r, null, 2));
1110
+ else if (args.write) {
1111
+ if (!r.check.draft) throw new Error(`nothing written: added to ${file}, the template would have problems: ${r.check.problems.map((p) => `line ${p.line}: ${p.message}`).join(' ')} Use --name to give the function another name.`);
1112
+ writeFileSync(file, `${source.replace(/\s+$/, '')}\n\n${r.text}`);
1113
+ console.log(`thunder template: added "To ${r.function.name}:" to ${file}, a draft with ${r.check.holes} ${r.check.holes === 1 ? 'hole' : 'holes'} to fill in. thunder check ${file} says what each needs.`);
1114
+ } else {
1115
+ process.stdout.write(r.text);
1116
+ const why = r.type.form === 'atomic' ? `${r.type.text} has no parts, so the template is the input and a hole`
1117
+ : r.type.form === 'compound' ? `a ${r.type.text} has ${r.cases[0].fields.length} ${r.cases[0].fields.length === 1 ? 'field' : 'fields'}, each taken out by name`
1118
+ : `a ${r.type.text} is one of ${r.cases.length} alternatives, so there is a case for each`;
1119
+ const notes = [why];
1120
+ if (r.type.recursive) notes.push(`it holds a ${r.type.text} again, so the function calls itself for that part`);
1121
+ if (r.related.length) notes.push(`it uses ${r.related.join(', ')}: thunder template ${file} ${r.related[0]} writes ${r.related.length === 1 ? 'its' : 'their'} own`);
1122
+ console.error(`\n# ${notes.join('; ')}.`);
1123
+ console.error(r.check.draft ? `# Checked: added to ${file}, it is a draft with ${r.check.holes} ${r.check.holes === 1 ? 'hole' : 'holes'} and nothing else to fix. Fill in each ? (Thunder won't choose for you).`
1124
+ : `# Added to ${file}, it would have problems: ${r.check.problems.map((p) => `line ${p.line}: ${p.message}`).join(' ')}`);
1125
+ }
1126
+ process.exitCode = r.check.draft ? 0 : 1;
1127
+ } catch (e) { console.error(`thunder template: ${e.message}`); process.exitCode = 2; }
1128
+ return;
1129
+ }
1130
+ if (cmd === 'affected') {
1131
+ try {
1132
+ if (!args._.length) throw new Error('Use thunder affected <rule…> [--in <folder|file>] [--json], for example: thunder affected "review limit" --in examples/apps/refund-desk');
1133
+ const target = resolve(args.inLang ?? ".");
1134
+ if (!existsSync(target)) throw new Error(`${args.inLang} does not exist.`);
1135
+ const r = affectedBy(coreFilesIn(target), args._);
1136
+ if (args.json) console.log(JSON.stringify(r, null, 2));
1137
+ else console.log(renderAffected(r));
1138
+ process.exitCode = r.of.length ? 0 : 2;
1139
+ } catch (e) { console.error(`thunder affected: ${e.message}`); process.exitCode = 2; }
1140
+ return;
1141
+ }
906
1142
  if (cmd === 'same') {
907
1143
  try {
908
1144
  const [a, b] = args._;
@@ -1327,7 +1563,7 @@ goal
1327
1563
 
1328
1564
  guarantee an example property that must always hold
1329
1565
  because state why it matters
1330
- verify a test that proves it
1566
+ verify a test that checks it
1331
1567
 
1332
1568
  never
1333
1569
  do something this mission must never do
@@ -2014,14 +2250,17 @@ test Example
2014
2250
  const bad = rep.failed > 0 || (args.strict && rep.unverified > 0);
2015
2251
  if (args.json) { console.log(JSON.stringify(rep, null, 2)); process.exit(bad ? 1 : 0); return; }
2016
2252
  if (!rep.total) { console.log(`thunder test ${basename(file)} --contracts: no guarantees or prohibitions declared.`); return; }
2017
- console.log(`thunder test ${basename(file)} --contracts: ${rep.total} obligation(s), ${rep.verified} verified, ${rep.declared} declared, ${rep.unverified} unverified${rep.failed ? `, ${rep.failed} failed` : ''}`);
2018
- const LABEL = { verified: 'PASS', failed: 'FAIL', declared: 'DECLARED', unverified: 'UNVERIFIED' };
2253
+ const ev = res.evidence;
2254
+ console.log(`thunder test ${basename(file)} --contracts: ${rep.total} obligation(s): ${ev.tested} Tested, ${ev.partial} Partially checked, ${ev.unverified} Unverified${ev.violated ? `, ${ev.violated} Violated` : ''}`);
2019
2255
  for (const o of obligations) {
2020
2256
  const by = o.kinds.length ? ` by ${o.kinds.join('+')}` : '';
2021
- const detail = o.provenBy ? ` proven by test ${o.provenBy}`
2022
- : o.status === 'declared' ? ' (declared, runs in target mode)'
2023
- : o.status === 'unverified' ? ' (nothing verifies this)' : '';
2024
- console.log(` ${LABEL[o.status].padEnd(10)} ${o.kind} ${o.id}: ${o.text}${by}${detail}`);
2257
+ const ran = o.evidence.filter((e) => e.pass !== null).map((e) => e.name);
2258
+ const detail = o.evidenceLevel === 'violated' ? ` (test ${o.evidence.filter((e) => e.pass === false).map((e) => e.name).join(', ')} failed)`
2259
+ : o.evidenceLevel === 'tested' ? ` (passed test ${ran.join(', ')}; only its cases)`
2260
+ : o.evidenceLevel === 'partial' ? ` (passed ${ran.join(', ')}; ${o.unresolved.join(', ')} runs in target mode, not here)`
2261
+ : o.status === 'declared' ? ` (${o.unresolved.join(', ')} runs in target mode, not here)`
2262
+ : ' (nothing checks this yet)';
2263
+ console.log(` ${o.evidenceWord.padEnd(17)} ${o.kind} ${o.id}: ${o.text}${by}${detail}`);
2025
2264
  }
2026
2265
  if (args.strict && rep.unverified) console.log(`\n strict: ${rep.unverified} unverified obligation(s) , run fails until every claim carries a verification.`);
2027
2266
  process.exit(bad ? 1 : 0);
@@ -2061,11 +2300,7 @@ test Example
2061
2300
  generatedAt: new Date().toISOString(),
2062
2301
  });
2063
2302
  // Fold per-claim verdicts into the proof so it records real status, not just planned/needs_verification.
2064
- const CLAIM_MAP = { verified: 'verified', failed: 'failed', declared: 'planned', unverified: 'needs_verification' };
2065
- const byId = new Map(resolved.obligations.map((o) => [o.id, o]));
2066
- const applyStatus = (claim) => { const o = byId.get(claim.id); return o ? { ...claim, status: CLAIM_MAP[o.status], provenBy: o.provenBy || null } : claim; };
2067
- proof.guarantees = proof.guarantees.map(applyStatus);
2068
- proof.neverRules = proof.neverRules.map(applyStatus);
2303
+ foldObligations(proof, resolved);
2069
2304
  // Freshness tuple: what `thunder verify` recomputes to mark this proof STALE later.
2070
2305
  proof.freshness = freshnessFor(file, proof, args.env);
2071
2306
  const proofId = `proof-${proof.sourceHash.replace('sha256:', '').slice(0, 6)}`;
@@ -2077,7 +2312,7 @@ test Example
2077
2312
  return;
2078
2313
  }
2079
2314
 
2080
- console.log(`Proof created: ${proofId}`);
2315
+ console.log(`Evidence record created: ${proofId} (what was checked, and how: docs/evidence-words.md)`);
2081
2316
  console.log('');
2082
2317
  console.log(` Intent: ${proof.missionName || stripSourceExt(basename(file))}`);
2083
2318
  console.log(` Intent hash: ${proof.sourceHash}`);
@@ -2086,15 +2321,16 @@ test Example
2086
2321
  console.log(` Syntax: ${proof.verification.syntaxPassed ? 'PASS' : 'FAIL'}`);
2087
2322
  console.log(` Semantics: ${proof.verification.semanticPassed ? 'PASS' : 'FAIL'}`);
2088
2323
  console.log(` Tests: ${tests.total ? `${tests.passed}/${tests.total} passed` : 'none'}`);
2089
- console.log(` Claims: ${resolved.verified} verified, ${resolved.declared} declared, ${resolved.unverified} UNVERIFIED${resolved.failed ? `, ${resolved.failed} FAILED` : ''} (of ${resolved.obligations.length})`);
2090
- console.log(` Proof status: ${String(proof.proofStatus).toUpperCase()}${(resolved.unverified || resolved.failed) ? ' (not fully proven)' : ''}`);
2324
+ const ev = resolved.evidence;
2325
+ console.log(` Claims: ${ev.tested} Tested, ${ev.partial} Partially checked, ${ev.unverified} Unverified${ev.violated ? `, ${ev.violated} VIOLATED` : ''} (of ${resolved.obligations.length}; Tested = passed its named cases, only those)`);
2326
+ console.log(` Status: ${String(proof.proofStatus).toUpperCase()}${(ev.unverified || ev.partial || ev.violated) ? ` (${ev.unverified + ev.partial + ev.violated} not fully tested)` : ''}`);
2091
2327
  const fr = proof.freshness;
2092
2328
  console.log(` Bound to: commit ${fr.implementation ? fr.implementation.slice(0, 7) : 'n/a'}${fr.dependencies ? ` · deps ${fr.dependencies.hash.replace('sha256:', '').slice(0, 7)} (${fr.dependencies.file})` : ''}${fr.environment ? ` · env ${fr.environment}` : ''}`);
2093
- const problems = resolved.obligations.filter((o) => o.status === 'unverified' || o.status === 'failed');
2329
+ const problems = resolved.obligations.filter((o) => o.evidenceLevel !== 'tested');
2094
2330
  if (problems.length) {
2095
2331
  console.log('');
2096
- console.log(' Not proven (this is where drift hides , a claim like this never counts as proven):');
2097
- for (const o of problems) console.log(` - ${o.status === 'failed' ? 'FAILED ' : 'UNVERIFIED'} ${o.kind} ${o.id}: ${o.text}`);
2332
+ console.log(' Not tested yet, or Violated (this is where drift hides):');
2333
+ for (const o of problems) console.log(` - ${o.evidenceWord.padEnd(17)} ${o.kind} ${o.id}: ${o.text}`);
2098
2334
  }
2099
2335
  const outName = `${slug(ast.mission || stripSourceExt(basename(file)))}.thunder-proof.json`;
2100
2336
  const outDir = args.out && args.out !== '.intent' ? args.out : dirname(file);
@@ -2123,11 +2359,7 @@ test Example
2123
2359
  diagnostics,
2124
2360
  generatedAt: new Date().toISOString(),
2125
2361
  });
2126
- const CLAIM_MAP = { verified: 'verified', failed: 'failed', declared: 'planned', unverified: 'needs_verification' };
2127
- const byId = new Map(resolved.obligations.map((o) => [o.id, o]));
2128
- const applyStatus = (claim) => { const o = byId.get(claim.id); return o ? { ...claim, status: CLAIM_MAP[o.status], provenBy: o.provenBy || null } : claim; };
2129
- proof.guarantees = proof.guarantees.map(applyStatus);
2130
- proof.neverRules = proof.neverRules.map(applyStatus);
2362
+ foldObligations(proof, resolved);
2131
2363
  proof.freshness = freshnessFor(file, proof, args.env);
2132
2364
  const events = toEvidenceEvents(proof);
2133
2365
  console.log(JSON.stringify(events, null, 2));
@@ -2526,8 +2758,8 @@ test Example
2526
2758
  const v = VIEWS[cmd](scan);
2527
2759
  if (args.json) { console.log(JSON.stringify(v, null, 2)); return; }
2528
2760
  if (cmd === 'coverage') {
2529
- console.log(`thunder coverage ${root}: ${v.verified}/${v.total} claims verified (${v.coverage}%)`);
2530
- for (const c of v.unverified) console.log(` unverified [${c.type}] ${c.title}`);
2761
+ console.log(`thunder coverage ${root}: ${v.verified}/${v.total} claims name a check (${v.coverage}%). Naming a check is not running it: thunder test <file> --contracts says which are Tested.`);
2762
+ for (const c of v.unverified) console.log(` Unverified [${c.type}] ${c.title} (no check named)`);
2531
2763
  process.exit(v.coverage === 100 ? 0 : 1); return;
2532
2764
  }
2533
2765
  if (cmd === 'risks') {
@@ -2581,7 +2813,7 @@ test Example
2581
2813
  console.log(`thunder report ${root}: ${rep.totals.missions} mission(s) in ${rep.totals.files} file(s), ${rep.totals.diagnostics} diagnostic(s)`);
2582
2814
  console.log(` severity ${rep.bySeverity.blocker} blocker, ${rep.bySeverity.error} error, ${rep.bySeverity.warning} warning, ${rep.bySeverity.info} info`);
2583
2815
  console.log(' coverage '
2584
- + `guarantees verified ${c.guaranteesVerified}/${c.guarantees}${c.guaranteeVerifyRate != null ? ` (${c.guaranteeVerifyRate}%)` : ''}, `
2816
+ + `guarantees with a check named ${c.guaranteesVerified}/${c.guarantees}${c.guaranteeVerifyRate != null ? ` (${c.guaranteeVerifyRate}%)` : ''} (named, not run), `
2585
2817
  + `missions with tests ${c.missionsWithTests}/${rep.totals.missions}${c.testCoverageRate != null ? ` (${c.testCoverageRate}%)` : ''}, `
2586
2818
  + `outcomes contracted ${c.outcomeContracts}/${c.outcomes}${c.outcomeContractRate != null ? ` (${c.outcomeContractRate}%)` : ''}`);
2587
2819
  if (rep.topCodes.length) {
@@ -2815,4 +3047,4 @@ function missingFile(e) {
2815
3047
  return true;
2816
3048
  }
2817
3049
  process.on('uncaughtException', (e) => { if (!missingFile(e)) { console.error(e); process.exitCode = 1; } });
2818
- try { main(); } catch (e) { if (!missingFile(e)) throw e; }
3050
+ try { await preload(process.argv[2]); main(); } catch (e) { if (!missingFile(e)) throw e; }