lawspec 0.30.0 → 0.31.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 (78) hide show
  1. package/CHANGELOG.md +377 -1
  2. package/README.md +9 -3
  3. package/api.mjs +1 -0
  4. package/beam-doctor.mjs +2 -2
  5. package/bin/lawspec.mjs +93 -95
  6. package/build.json +497 -405
  7. package/component-packages.mjs +339 -0
  8. package/component.d.ts +46 -0
  9. package/component.mjs +208 -0
  10. package/core.wasm +2 -2
  11. package/core_jsffi.js +5 -5
  12. package/examples/native-payments/clojure/lawspec.edn +48 -0
  13. package/examples/native-payments/clojure/src/domain/payments.clj +1 -1
  14. package/examples/native-payments/clojure/test/domain/payment_generators.clj +1 -1
  15. package/examples/native-payments/csharp/lawspec.edn +48 -0
  16. package/examples/native-payments/elixir/lawspec.edn +123 -0
  17. package/examples/native-payments/erlang/lawspec.edn +128 -0
  18. package/examples/native-payments/fsharp/lawspec.edn +123 -0
  19. package/examples/native-payments/gleam/lawspec.edn +123 -0
  20. package/examples/native-payments/go/lawspec.edn +123 -0
  21. package/examples/native-payments/groovy/lawspec.edn +123 -0
  22. package/examples/native-payments/haskell/lawspec.edn +123 -0
  23. package/examples/native-payments/java/lawspec.edn +123 -0
  24. package/examples/native-payments/javascript/lawspec.edn +123 -0
  25. package/examples/native-payments/kotlin/lawspec.edn +123 -0
  26. package/examples/native-payments/prolog/lawspec.edn +48 -0
  27. package/examples/native-payments/python/lawspec.edn +123 -0
  28. package/examples/native-payments/rust/lawspec.edn +124 -0
  29. package/examples/native-payments/scala/lawspec.edn +123 -0
  30. package/examples/native-payments/swift/lawspec.edn +123 -0
  31. package/examples/native-payments/typescript/lawspec.edn +123 -0
  32. package/examples/packages/orders/lawspec.edn +25 -0
  33. package/examples/packages/shop-domain/lawspec.edn +13 -0
  34. package/examples/packages/shop-tax-1/lawspec.edn +9 -0
  35. package/examples/packages/shop-tax-2/lawspec.edn +9 -0
  36. package/examples/specs/handler_bindings.lawspec +2 -2
  37. package/files.mjs +2 -1
  38. package/go.mod +4 -0
  39. package/index.d.ts +135 -2
  40. package/input-files.mjs +47 -0
  41. package/launcher.mjs +33 -13
  42. package/lsp.mjs +10 -5
  43. package/native-evidence.mjs +50 -15
  44. package/native-examples.mjs +8 -7
  45. package/native-host.mjs +71 -0
  46. package/package.json +8 -3
  47. package/proof.d.ts +8 -2
  48. package/proof.mjs +183 -31
  49. package/scala-build-state.mjs +59 -0
  50. package/templates.mjs +242 -2
  51. package/test-command.mjs +192 -60
  52. package/builtin-data-names.mjs +0 -73
  53. package/examples/native-payments/clojure/lawspec.json +0 -62
  54. package/examples/native-payments/csharp/lawspec.json +0 -62
  55. package/examples/native-payments/elixir/lawspec.json +0 -160
  56. package/examples/native-payments/erlang/lawspec.json +0 -159
  57. package/examples/native-payments/fsharp/lawspec.json +0 -178
  58. package/examples/native-payments/gleam/lawspec.json +0 -160
  59. package/examples/native-payments/go/lawspec.json +0 -147
  60. package/examples/native-payments/groovy/lawspec.json +0 -176
  61. package/examples/native-payments/haskell/lawspec.json +0 -160
  62. package/examples/native-payments/java/lawspec.json +0 -176
  63. package/examples/native-payments/javascript/lawspec.json +0 -160
  64. package/examples/native-payments/kotlin/lawspec.json +0 -176
  65. package/examples/native-payments/prolog/lawspec.json +0 -20
  66. package/examples/native-payments/python/lawspec.json +0 -160
  67. package/examples/native-payments/rust/lawspec.json +0 -178
  68. package/examples/native-payments/scala/lawspec.json +0 -176
  69. package/examples/native-payments/swift/lawspec.json +0 -165
  70. package/examples/native-payments/typescript/lawspec.json +0 -160
  71. package/examples/packages/orders/lawspec.json +0 -27
  72. package/examples/packages/shop-domain/lawspec-package.json +0 -7
  73. package/examples/packages/shop-tax-1/lawspec-package.json +0 -5
  74. package/examples/packages/shop-tax-2/lawspec-package.json +0 -5
  75. package/explain.mjs +0 -114
  76. package/expression-presentation.mjs +0 -333
  77. package/positional-fields.mjs +0 -13
  78. package/typed-presentation.mjs +0 -165
@@ -5,7 +5,7 @@ import path from 'node:path';
5
5
  import {doctor} from './doctor.mjs';
6
6
  import {planWrites} from './files.mjs';
7
7
  import {projectKey} from './failure-database.mjs';
8
- import {lawKeys,environmentDigest,recordedDigest,projectDigest,invocations} from './test-command.mjs';
8
+ import {lawKeys,presentationDigest,environmentDigest,recordedDigest,projectDigest,invocations} from './test-command.mjs';
9
9
 
10
10
  // Native execution observations are scoped to actual completed test slots.
11
11
  // They never establish a universal model proof or a witness-search completeness claim.
@@ -48,6 +48,8 @@ export function recordNativeAttempts(run, tests, {keys,seed,ok,profile,output,al
48
48
  // reported beside it are not inputs, so they change no key.
49
49
  export function attestedKeys(result) {
50
50
  const wiring=d=>[d.dependency,d.endpoint,d.kind,
51
+ ...(d.implementation?[[d.implementation.kind,d.implementation.product,d.implementation.version,
52
+ d.implementation.commit??null,d.implementation.digest??null]]:[]),
51
53
  ...(d.standIn?[d.standIn.identity,d.standIn.version,d.standIn.conformance]:[])];
52
54
  return new Map((result.evidence??[]).filter(item=>item.against||item.plannedAgainst)
53
55
  .map(item=>[item.declaration,JSON.stringify([
@@ -65,17 +67,17 @@ const observationOutcome=outcome=>outcome==='known-failing'?'known-discrepancy':
65
67
 
66
68
  // Only observations with matching current compiler/configuration/source/native
67
69
  // inputs are eligible for completed evidence. A stored timestamp alone is not.
68
- export async function readNativeObservations({compiler,input,selected,roots,configRoot,build,evidence,attestation}) {
70
+ export async function readNativeObservations({compiler,input,selected,roots,configRoot,config={},build,evidence,attestation}) {
69
71
  const records=await Promise.all(selected.map(async(target,index)=>{
70
72
  const root=roots[index],file=path.join(configRoot,'.lawspec/results',`${target.language}-${projectKey(root)}.json`);
71
73
  const record=JSON.parse(await readFile(file,'utf8').catch(error=>{
72
74
  if(error.code==='ENOENT')return '{}';throw error;
73
75
  }));
74
- return {target,root,attempts:record.attempts??{},runs:record.laws??{},attestations:record.attestations??{}};
76
+ return {target,root,attempts:record.attempts??{},runs:record.laws??{},presentation:record.presentation,attestations:record.attestations??{}};
75
77
  }));
76
78
  if(!records.some(record=>Object.keys(record.attempts).length))return [];
77
79
  const observations=[];
78
- for(const {target,root,attempts,runs,attestations}of records){
80
+ for(const {target,root,attempts,runs,presentation,attestations}of records){
79
81
  const plans=new Map(),contexts=new Map();
80
82
  // An attempt is keyed by the wiring of the attestation it ran under: the
81
83
  // one named now, or else the one lawspec test stored for its run.
@@ -112,10 +114,15 @@ export async function readNativeObservations({compiler,input,selected,roots,conf
112
114
  const report=await doctor(target,root,generated.files);
113
115
  if(!report.ok)result={reason:'The current native environment could not be checked: '+report.message};
114
116
  else {
117
+ const environment=await environmentDigest(root,report,target.language);
118
+ if(presentation!==presentationDigest(generated.files,environment)){
119
+ result={reason:'Current generated presentation has not passed native validation; run lawspec test'};
120
+ contexts.set(key,result);return result;
121
+ }
115
122
  const owned=new Set(generated.files.filter(file=>file.ownership==='generated').map(file=>file.path));
116
123
  const keys=lawKeys({build,target,machineBits:input.machineBits,minify,tests:generated.tests,files:generated.files,
117
- environment:await environmentDigest(root,report)+await recordedDigest(path.join(configRoot,'recorded')),
118
- project:await projectDigest(root,owned),attested:attestedKeys(generated)});
124
+ environment,recorded:await recordedDigest(path.join(configRoot,'recorded')),
125
+ project:await projectDigest(root,owned,target.language,{inputRoot:configRoot,inputs:config.inputs??[]}),attested:attestedKeys(generated)});
119
126
  result={generated,keys};
120
127
  }
121
128
  }
@@ -123,7 +130,19 @@ export async function readNativeObservations({compiler,input,selected,roots,conf
123
130
  contexts.set(key,result);return result;
124
131
  }
125
132
  for(const [id,baseline]of expected){
126
- const attempt=attempts[id];
133
+ let attempt=attempts[id],reuse;
134
+ if(!attempt)for(const original of Object.values(attempts)){
135
+ // Only a single ordinary-law observation can be re-associated here.
136
+ // Combined model methods keep their exact group identities.
137
+ if(original.outcome!=='passed'||original.check?.nativeGroup?.length!==1||
138
+ !isDeepStrictEqual(original.check.obligations,[{declaration:original.check.id,stage:'law'}])||
139
+ !isDeepStrictEqual(obligationTargets(baseline),[{declaration:id,stage:'law'}]))continue;
140
+ let candidate=await context(original.profile?.minify??false,wiredBy(original));
141
+ if(candidate.reason&&candidate.stale)candidate=await context(!original.profile?.minify,wiredBy(original));
142
+ if(!candidate.reason&&candidate.keys.get(id)===original.key&&baseline.key===original.planKey){
143
+ attempt=original;reuse={check:original.check.id,key:original.key,at:original.at};break;
144
+ }
145
+ }
127
146
  const row={target:target.language,root,check:{id,obligations:obligationTargets(baseline)},
128
147
  outcome:observationOutcome(attempt?.outcome??'not-run'),coverage:baseline.coverage,attempt};
129
148
  if(!attempt){observations.push({...row,freshness:'not-run',reason:'No completed native observation was recorded'});continue;}
@@ -132,29 +151,34 @@ export async function readNativeObservations({compiler,input,selected,roots,conf
132
151
  typeof profile.minify!=='boolean'){
133
152
  observations.push({...row,freshness:'stale',reason:'Compiler, target or machine profile differs'});continue;
134
153
  }
135
- const current=await context(profile.minify,wiredBy(attempt));
154
+ let current=await context(profile.minify,wiredBy(attempt));
155
+ // Layout belongs to the artifact, not to the meaning of its old run.
156
+ // Accept the other canonical layout only when it exactly matches disk.
157
+ if(current.reason&&current.stale)current=await context(!profile.minify,wiredBy(attempt));
136
158
  if(current.reason){observations.push({...row,freshness:current.stale?'stale':'unavailable',reason:current.reason});continue;}
137
159
  const entry=current.generated.tests.find(entry=>entry.law===id);
138
160
  if(!entry||attempt.key!==current.keys.get(id)||attempt.planKey!==entry.key||
139
- !isDeepStrictEqual(attempt.check?.obligations,obligationTargets(entry))||
161
+ (!reuse&&!isDeepStrictEqual(attempt.check?.obligations,obligationTargets(entry)))||
140
162
  !isDeepStrictEqual(attempt.coverage,entry.coverage)){
141
163
  observations.push({...row,freshness:'stale',reason:'Specification, selection, bindings, native source or toolchain inputs differ'});continue;
142
164
  }
143
- const invocation=invocations(target,[entry],{root}).find(run=>run.laws?.includes(entry));
165
+ const observedEntry=reuse?{...entry,...attempt.check,law:attempt.check.id,key:attempt.planKey}:entry;
166
+ const invocation=invocations(target,[observedEntry],{root}).find(run=>run.laws?.includes(observedEntry));
167
+ const observedKeys=reuse?new Map([[observedEntry.law,attempt.key]]):current.keys;
144
168
  const validSeed=(typeof attempt.seed==='number'&&Number.isSafeInteger(attempt.seed)&&attempt.seed>=0)||
145
169
  (typeof attempt.seed==='string'&&/^[0-9]+$/.test(attempt.seed));
146
170
  const recomputed=validSeed&&Number.isFinite(Date.parse(attempt.at))&&invocation&&Array.isArray(attempt.tests)&&recordNativeAttempts(invocation,attempt.tests,
147
- {keys:current.keys,seed:attempt.seed,ok:attempt.invocation?.ok===true,profile,at:attempt.at,
148
- allEntries:current.generated.tests})[id];
171
+ {keys:observedKeys,seed:attempt.seed,ok:attempt.invocation?.ok===true,profile,at:attempt.at,
172
+ allEntries:reuse?[observedEntry]:current.generated.tests})[observedEntry.law];
149
173
  if(!recomputed||recomputed.outcome!==attempt.outcome||
150
174
  !isDeepStrictEqual(recomputed.check.nativeGroup,attempt.check?.nativeGroup)){
151
175
  observations.push({...row,freshness:'unavailable',reason:'The stored observation does not establish the current native completion'});continue;
152
176
  }
153
177
  const run=runs[id];
154
- observations.push({...row,freshness:'matching-inputs',
178
+ observations.push({...row,freshness:'matching-inputs',...(reuse?{reused:reuse}:{}),
155
179
  ...(attempt.outcome==='passed'&&run?.key===attempt.key&&(run.flaky||run.adequacy)?
156
180
  {harness:{...(run.flaky?{flaky:true}:{}),...(run.adequacy?{adequacy:run.adequacy}:{})}}:{}),
157
- reason:attempt.outcome==='passed'?'Recorded native completion matches the current inputs':'Recorded native attempt matches the current inputs'});
181
+ reason:reuse?'Original native completion reused for the current semantic law; no fresh invocation is claimed':attempt.outcome==='passed'?'Recorded native completion matches the current inputs':'Recorded native attempt matches the current inputs'});
158
182
  }
159
183
  for(const [id,attempt]of Object.entries(attempts))if(!expected.has(id)&&Array.isArray(attempt.check?.obligations))
160
184
  observations.push({target:target.language,root,check:attempt.check,attempt,outcome:observationOutcome(attempt.outcome),
@@ -201,4 +225,15 @@ export function attachNativeEvidence(evidence,observations){
201
225
  });
202
226
  }
203
227
 
204
- export {nativeEvidenceText} from './explain.mjs';
228
+ // Native conformance a law's evidence row carries, for lawspec evidence.
229
+ export function nativeEvidenceText(item){
230
+ if(!item.nativeEvidence)return '';
231
+ const summary=item.nativeEvidence;
232
+ return [`Native conformance: ${summary.status}; search completeness: ${summary.searchCompleteness}`,
233
+ ...summary.observations.map(row=>`${row.target} (${row.root}): ${row.outcome}; ${row.freshness}`+
234
+ (row.attempt?`; seed ${row.attempt.seed}; ${row.attempt.at}`:'')+`; ${row.reason}`),
235
+ ...summary.observations.flatMap(row=>(row.attempt?.tests??[]).filter(test=>test.status==='failed')
236
+ .map(test=>`${test.name}: ${test.reason??test.failure??test.message??'native test failed'}`)),
237
+ ...summary.observations.filter(row=>row.attempt?.invocation.output)
238
+ .map(row=>'Native invocation output (scoped to that invocation):\n'+row.attempt.invocation.output)].join('\n');
239
+ }
@@ -3,6 +3,7 @@ import {readFile, readdir, mkdir} from 'node:fs/promises';
3
3
  import path from 'node:path';
4
4
  import {templates, commands, setup} from './templates.mjs';
5
5
  import {safePath, planWrites, applyWrites} from './files.mjs';
6
+ import {parseManifest, writeManifest} from './component.mjs';
6
7
 
7
8
  async function projectFiles(directory, prefix = '') {
8
9
  const files = {};
@@ -30,11 +31,11 @@ export async function exportNativePayments(options, selected) {
30
31
  ...await projectFiles(new URL(`./examples/native-payments/${target}/`, import.meta.url)),
31
32
  'laws/payments.lawspec': law,
32
33
  };
33
- const config = JSON.parse(files['lawspec.json']);
34
- if(config.version!==2||config.languageProfile!=='1.0-rc.2')
35
- throw new Error(`Bundled native payments configuration for ${target} must use version 2 and languageProfile 1.0-rc.2`);
34
+ const config = parseManifest(files['lawspec.edn']);
35
+ if(config.manifestVersion!==1||config.languageProfile!=='1.0-rc.2')
36
+ throw new Error(`Bundled native payments configuration for ${target} must use lawspec.edn and languageProfile 1.0-rc.2`);
36
37
  config.machineBits = options.machineBits ?? 64;
37
- files['lawspec.json'] = JSON.stringify(config, null, options.minify ? undefined : 2) + '\n';
38
+ files['lawspec.edn'] = writeManifest(config, {compact: options.minify === true});
38
39
  const instructions = target === 'gleam' ? setup[target].replace(
39
40
  'Prepare dependencies with gleam build, then run gleam test.',
40
41
  'Prepare dependencies with node prepare.mjs before generation, then run gleam test.') : setup[target];
@@ -44,8 +45,8 @@ This project checks application-owned payment types against the shared LawSpec
44
45
  model. Money maps to Price, currency variants have application names, and the
45
46
  archive preserves distinct present and absent payments.
46
47
 
47
- The specification uses the canonical language profile. The version 2 project
48
- configuration selects its verification layers explicitly. Most targets bind
48
+ The specification uses the canonical language profile. The component manifest
49
+ selects its verification layers explicitly. Most targets bind
49
50
  application-owned domain types; C#, Clojure and Prolog use the generated model data
50
51
  and bind the application's functions and generators.
51
52
 
@@ -77,7 +78,7 @@ the application so that runtime support is present.
77
78
 
78
79
  Edit the domain implementation or generator, then run the native tests again.
79
80
  For example, change the fee from 0.2 to 0.3: the exact-decimal law must fail.
80
- Edit \`lawspec.json\` to change native bindings and rerun \`lawspec generate\`.
81
+ Edit \`lawspec.edn\` to change native bindings and rerun \`lawspec generate\`.
81
82
 
82
83
  All exported project files are user-owned. Re-exporting preserves your edits;
83
84
  it reports changed bundled versions for review. Compiler-generated files use a
@@ -0,0 +1,71 @@
1
+ // Generated from templates/npm/native-host.mjs by lawspec-dev generate. Do not edit.
2
+ // Native execution identity is separate from the WebAssembly compiler cache
3
+ // and from the solver host. Conservatively bind the executable SDK bundle,
4
+ // its installed dependency closure, and the Node binary which runs it.
5
+ import {createHash} from 'node:crypto';
6
+ import {createRequire} from 'node:module';
7
+ import {readFile,readdir,realpath} from 'node:fs/promises';
8
+ import {fileURLToPath} from 'node:url';
9
+ import path from 'node:path';
10
+
11
+ const sdkRoot=fileURLToPath(new URL('.',import.meta.url));
12
+ // These modules only render explanations, serve editors, create examples or
13
+ // execute optional proofs. They do not select or certify native completion.
14
+ const separate=new Set(['proof.mjs','lsp.mjs','explain.mjs','scalars.mjs','examples-command.mjs']);
15
+ let nodeIdentityValue;
16
+ async function nodeIdentity(){
17
+ nodeIdentityValue??=(async()=>createHash('sha256').update(await readFile(process.execPath)).digest('hex'))();
18
+ return nodeIdentityValue;
19
+ }
20
+
21
+ export async function fingerprintNativeHost(root=sdkRoot){
22
+ const hash=createHash('sha256').update('lawspec-native-host-v1\0');
23
+ hash.update(JSON.stringify([await nodeIdentity(),process.version,process.platform,process.arch,process.execArgv,process.env.NODE_OPTIONS??'']));
24
+ const add=async(file,label)=>hash.update(label+'\0').update(await readFile(file)).update('\0');
25
+ // New SDK helper modules enter the identity automatically. Project output,
26
+ // declarations, documentation and core.wasm are deliberately outside it.
27
+ for(const entry of (await readdir(root,{withFileTypes:true})).sort((a,b)=>a.name<b.name?-1:a.name>b.name?1:0))
28
+ if(entry.isFile()&&((entry.name.endsWith('.mjs')&&!separate.has(entry.name))||entry.name==='core_jsffi.js'))
29
+ await add(path.join(root,entry.name),entry.name);
30
+ for(const entry of (await readdir(path.join(root,'bin'),{withFileTypes:true})).sort((a,b)=>a.name<b.name?-1:a.name>b.name?1:0))
31
+ if(entry.isFile()&&entry.name.endsWith('.mjs'))await add(path.join(root,'bin',entry.name),'bin/'+entry.name);
32
+ const manifest=JSON.parse(await readFile(path.join(root,'package.json'),'utf8'));
33
+ await add(path.join(root,'package.json'),'package.json');
34
+ const seen=new Set();
35
+ async function packageRoot(name,from){
36
+ let directory=path.dirname(createRequire(path.join(from,'package.json')).resolve(name));
37
+ while(true){
38
+ const candidate=path.join(directory,'package.json');
39
+ const value=await readFile(candidate,'utf8').then(JSON.parse,error=>{if(error.code==='ENOENT')return null;throw error;});
40
+ if(value?.name===name)return {directory:await realpath(directory),value};
41
+ const parent=path.dirname(directory);if(parent===directory)throw new Error('Cannot identify native host dependency '+name);
42
+ directory=parent;
43
+ }
44
+ }
45
+ async function dependency(name,from,optional=false){
46
+ let selected;
47
+ try{selected=await packageRoot(name,from);}catch(error){
48
+ if(optional&&error.code==='MODULE_NOT_FOUND'){hash.update('absent-optional:'+name+'\0');return;}throw error;
49
+ }
50
+ const {directory,value}=selected,label=path.relative(root,directory).split(path.sep).join('/');
51
+ hash.update('dependency:'+name+'\0'+label+'\0');
52
+ if(seen.has(directory))return;seen.add(directory);
53
+ async function walk(folder,relative=''){
54
+ for(const entry of (await readdir(folder,{withFileTypes:true})).sort((a,b)=>a.name<b.name?-1:a.name>b.name?1:0)){
55
+ const next=relative?relative+'/'+entry.name:entry.name;
56
+ if(entry.isSymbolicLink())throw new Error('Cannot fingerprint symbolic-link content in native host dependency: '+label+'/'+next);
57
+ if(entry.isDirectory()&&!['node_modules','.git'].includes(entry.name))await walk(path.join(folder,entry.name),next);
58
+ else if(entry.isFile())await add(path.join(folder,entry.name),label+'/'+next);
59
+ }
60
+ }
61
+ await walk(directory);
62
+ for(const child of Object.keys({...value.dependencies,...value.optionalDependencies}).sort())
63
+ await dependency(child,directory,Object.hasOwn(value.optionalDependencies??{},child));
64
+ }
65
+ for(const name of Object.keys({...manifest.dependencies,...manifest.optionalDependencies}).sort())
66
+ await dependency(name,root,Object.hasOwn(manifest.optionalDependencies??{},name));
67
+ return hash.digest('hex');
68
+ }
69
+
70
+ let identity;
71
+ export function nativeHostIdentity(){return identity??=fingerprintNativeHost();}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lawspec",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "State the law once. Check it everywhere.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,17 +22,22 @@
22
22
  "./proof": {
23
23
  "types": "./proof.d.ts",
24
24
  "import": "./proof.mjs"
25
+ },
26
+ "./component": {
27
+ "types": "./component.d.ts",
28
+ "import": "./component.mjs"
25
29
  }
26
30
  },
27
31
  "types": "index.d.ts",
32
+ "dependencies": {"edn-data": "1.2.2", "tar": "7.5.22"},
28
33
  "files": [
29
34
  "*.mjs",
30
35
  "*.json",
31
- "index.d.ts",
32
- "proof.d.ts",
36
+ "*.d.ts",
33
37
  "bin",
34
38
  "core.wasm",
35
39
  "core_jsffi.js",
40
+ "go.mod",
36
41
  "README.md",
37
42
  "CHANGELOG.md",
38
43
  "LICENSE",
package/proof.d.ts CHANGED
@@ -11,6 +11,10 @@ export interface Z3Options {
11
11
  }
12
12
  /** How a solver run went: shared by law and law-set evidence. */
13
13
  interface SolverRun {
14
+ /** Current task binding when a semantic result reuses an earlier execution. */
15
+ currentTaskFingerprint?: string;
16
+ /** Provenance of the completed execution reused; no fresh solver run occurred. */
17
+ reused?: {key:string; owner:string; declaration:string; taskFingerprint:string; runFingerprint:string};
14
18
  outcome: 'unsat' | 'sat' | 'unknown' | 'timeout' | 'resource-limit' | 'out-of-memory' | 'unavailable' | 'failed' | 'unsupported';
15
19
  reason: string;
16
20
  stdout?: string;
@@ -30,8 +34,10 @@ export interface LawSolverEvidence extends SolverRun {
30
34
  at: Location;
31
35
  encoding: 'lawspec-smtlib-v1' | 'lawspec-smtlib-v2';
32
36
  machineBits: 32 | 64;
33
- programFingerprint: string;
37
+ lawFingerprint: string;
34
38
  taskFingerprint?: string;
39
+ /** Current names for the same semantic induction plan; original cases remain in induction. */
40
+ currentInduction?: {on:string; using:string[]};
35
41
  status: 'proved' | 'refuted' | 'incomplete' | 'unsupported';
36
42
  model?: string;
37
43
  modelValidated?: boolean;
@@ -76,5 +82,5 @@ export interface ModelSolverEvidence extends SolverRun {
76
82
  counterexample?: undefined;
77
83
  }
78
84
  export type SolverEvidence = LawSolverEvidence | AnalysisSolverEvidence | ModelSolverEvidence;
79
- export function proofTaskFingerprint(task: {encoding:string;programFingerprint:string;machineBits:number;owner:string;declaration:string;script:string}):string;
85
+ export function proofTaskFingerprint(task: {encoding:string;lawFingerprint:string;machineBits:number;owner:string;declaration:string;script:string}):string;
80
86
  export function proveWithZ3(compiler:Compiler,request:CheckRequest,options?:Z3Options):Promise<Result & {solverEvidence:SolverEvidence[]}>;
package/proof.mjs CHANGED
@@ -2,19 +2,19 @@
2
2
  // Host execution of compiler-produced tasks. The browser/WASM compiler stays
3
3
  // pure; this Node host invokes Z3's SMT-LIB interface without a shell.
4
4
  import {spawn} from 'node:child_process';
5
- import {createHash} from 'node:crypto';
6
- import {access,readFile,realpath} from 'node:fs/promises';
5
+ import {createHash,randomUUID} from 'node:crypto';
6
+ import {access,mkdir,readFile,realpath,rename,rm,writeFile} from 'node:fs/promises';
7
7
  import {constants} from 'node:fs';
8
8
  import path from 'node:path';
9
9
 
10
10
  const hash=value=>createHash('sha256').update(value).digest('hex');
11
11
  const frame=value=>Buffer.byteLength(value,'utf8')+':'+value;
12
12
  const fingerprint=values=>hash(values.map(frame).join(''));
13
- // v1 is frozen byte for byte; tasks that need later features are v2.
13
+ // A task names its encoding; tasks that need later features are v2.
14
14
  const encodings=['lawspec-smtlib-v1','lawspec-smtlib-v2'];
15
15
 
16
16
  export function proofTaskFingerprint(task) {
17
- return fingerprint([task.encoding,task.programFingerprint,String(task.machineBits),
17
+ return fingerprint([task.encoding,task.lawFingerprint,String(task.machineBits),
18
18
  task.owner,task.declaration,task.script]);
19
19
  }
20
20
 
@@ -103,11 +103,107 @@ async function prover(config) {
103
103
 
104
104
  function validTask(task) {
105
105
  return encodings.includes(task.encoding)&&[32,64].includes(task.machineBits)&&
106
- ['owner','declaration','programFingerprint','script','taskFingerprint'].every(key=>typeof task[key]==='string')&&
107
- /^[0-9a-f]{64}$/.test(task.programFingerprint)&&
106
+ ['owner','declaration','lawFingerprint','script','taskFingerprint'].every(key=>typeof task[key]==='string')&&
107
+ /^[0-9a-f]{64}$/.test(task.lawFingerprint)&&
108
108
  proofTaskFingerprint(task)===task.taskFingerprint;
109
109
  }
110
110
 
111
+ // A semantic receipt may be reused after the compiler has admitted and
112
+ // planned the current source again. Its exact original task/run binding is
113
+ // retained; reuse is never presented as another solver execution. The local
114
+ // cache has the same trust boundary as the compiler's other persisted memos.
115
+ // Only completed unsat laws are reused. Counterexamples must be replayed by
116
+ // the current evaluator, and unknown/unsupported/incomplete work is retried.
117
+ async function receiptCache(request,selected) {
118
+ if(typeof request.cacheDirectory!=='string'||!request.cacheDirectory||selected.error)return null;
119
+ try {
120
+ const build=await readFile(new URL('./build.json',import.meta.url));
121
+ const host=await readFile(new URL('./proof.mjs',import.meta.url));
122
+ return {folder:path.join(request.cacheDirectory,'solver-goals-v1'),
123
+ identity:fingerprint(['lawspec.solver-cache.v1',hash(build),hash(host),selected.fingerprint])};
124
+ } catch {return null;}
125
+ }
126
+
127
+ async function cachedSolve(task,selected,config,cache) {
128
+ if(!cache||task.status!=='ready'||!validTask(task))return solve(task,selected,config);
129
+ const key=fingerprint([cache.identity,task.encoding,task.lawFingerprint,String(task.machineBits)]);
130
+ const filename=path.join(cache.folder,key+'.json');
131
+ try {
132
+ const saved=JSON.parse(await readFile(filename,'utf8'));
133
+ const receipt=saved.receipt;
134
+ const complete=saved.version===1&&saved.key===key&&validTask(saved.task)&&
135
+ saved.task.lawFingerprint===task.lawFingerprint&&saved.task.encoding===task.encoding&&
136
+ saved.task.machineBits===task.machineBits&&receipt?.status==='proved'&&receipt.outcome==='unsat'&&
137
+ receipt.exitCode===0&&receipt.lawFingerprint===task.lawFingerprint&&
138
+ /^[0-9a-f]{64}$/.test(receipt.runFingerprint??'')&&
139
+ receipt.prover?.fingerprint===selected.fingerprint&&
140
+ saved.digest===hash(JSON.stringify([saved.task,receipt]));
141
+ if(complete&&hash(await readFile(selected.binary))===selected.binaryFingerprint)
142
+ return {...receipt,owner:task.owner,declaration:task.declaration,at:task.at,
143
+ currentTaskFingerprint:task.taskFingerprint,
144
+ ...(receipt.induction&&task.induction?{currentInduction:{on:task.induction.on,using:task.induction.using}}:{}),
145
+ reused:{key,owner:saved.task.owner,declaration:saved.task.declaration,
146
+ taskFingerprint:receipt.taskFingerprint,runFingerprint:receipt.runFingerprint},
147
+ reason:receipt.reason+'; reused a completed semantic proof receipt; no new solver task ran'};
148
+ } catch {}
149
+ const receipt=await solve(task,selected,config);
150
+ if(receipt.status==='proved'&&receipt.outcome==='unsat'&&receipt.exitCode===0) {
151
+ const temporary=filename+'.'+randomUUID()+'.tmp';
152
+ try {
153
+ await mkdir(cache.folder,{recursive:true});
154
+ await writeFile(temporary,JSON.stringify({version:1,key,task,receipt,
155
+ digest:hash(JSON.stringify([task,receipt]))})+'\n',{mode:0o600});
156
+ await rename(temporary,filename);
157
+ } catch {} finally {await rm(temporary,{force:true}).catch(()=>{});}
158
+ }
159
+ return receipt;
160
+ }
161
+
162
+ // Law-set queries have a stable logical-goal identity beside their exact
163
+ // script fingerprint. Reused SAT values are passed unchanged, with the
164
+ // original ordered constant names, to the compiler for positional decoding
165
+ // and full validation against the current binders/claim. The host never
166
+ // rewrites solver/model text. Only compiler-confirmed outcomes are saved.
167
+ function queryFingerprint(row,task) {
168
+ return row.kind==='model'?hash(row.declaration+'\0'+task.kind+'\0'+task.script):fingerprint([row.declaration,row.stage,task.script]);
169
+ }
170
+ async function analysisQuery(cache,row,task,selected,executeQuery,fresh=false) {
171
+ const eligible=cache&&/^[0-9a-f]{64}$/.test(task.semanticFingerprint??'')&&
172
+ task.fingerprint===queryFingerprint(row,task);
173
+ const key=eligible?fingerprint([cache.identity,row.kind==='model'?'model':'analysis',row.kind==='model'?'':row.stage,task.semanticFingerprint]):null;
174
+ const filename=eligible?path.join(cache.folder,key+'.json'):null;
175
+ if(eligible&&!fresh)try {
176
+ const saved=JSON.parse(await readFile(filename,'utf8'));
177
+ const record=saved.record;
178
+ if(saved.version===1&&saved.key===key&&saved.digest===hash(JSON.stringify(record))&&
179
+ record?.semanticFingerprint===task.semanticFingerprint&&record.solverFingerprint===selected.fingerprint&&
180
+ ['sat','unsat'].includes(record.outcome)&&record.completed===true&&record.run?.exitCode===0&&
181
+ record.taskFingerprint===queryFingerprint(record,{kind:record.taskKind,script:record.script})&&
182
+ hash(await readFile(selected.binary))===selected.binaryFingerprint)
183
+ return {...record,row,cacheFile:filename,
184
+ reused:{key,owner:record.owner,declaration:record.declaration,
185
+ taskFingerprint:record.taskFingerprint,runFingerprint:record.runFingerprint},
186
+ rerun:()=>analysisQuery(cache,row,task,selected,executeQuery,true)};
187
+ } catch {}
188
+ const done=await executeQuery();
189
+ return {...done,row,inputs:task.inputs,
190
+ ...(eligible?{pendingCache:{filename,key,record:{kind:row.kind,taskKind:task.kind,owner:row.owner,declaration:row.declaration,stage:row.stage,
191
+ taskFingerprint:task.fingerprint,semanticFingerprint:task.semanticFingerprint,script:task.script,
192
+ solverFingerprint:selected.fingerprint,inputs:task.inputs,outcome:done.outcome,values:done.values,invariant:done.invariant,
193
+ run:done.run,runFingerprint:done.runFingerprint,completed:true}}}:{})};
194
+ }
195
+
196
+ async function saveQuery(done) {
197
+ if(!done.pendingCache||!['sat','unsat'].includes(done.outcome)||done.run?.exitCode!==0)return;
198
+ const {filename,key,record}=done.pendingCache;
199
+ const temporary=filename+'.'+randomUUID()+'.tmp';
200
+ try {
201
+ await mkdir(path.dirname(filename),{recursive:true});
202
+ await writeFile(temporary,JSON.stringify({version:1,key,record,digest:hash(JSON.stringify(record))})+'\n',{mode:0o600});
203
+ await rename(temporary,filename);
204
+ } catch {} finally {await rm(temporary,{force:true}).catch(()=>{});}
205
+ }
206
+
111
207
  // Law-set and model tasks need the same process and executable checks as
112
208
  // ordinary laws; a protocol token alone is not a completed solver run.
113
209
  async function verifiedOutcome(run,selected) {
@@ -184,7 +280,7 @@ async function solve(task,selected,config) {
184
280
 
185
281
  async function attempt(task,script,taskFingerprint,selected,config,names=null) {
186
282
  const common={owner:task.owner,declaration:task.declaration,at:task.at,
187
- programFingerprint:task.programFingerprint,taskFingerprint:task.taskFingerprint,
283
+ lawFingerprint:task.lawFingerprint,taskFingerprint:task.taskFingerprint,
188
284
  encoding:task.encoding,machineBits:task.machineBits,configuration:config};
189
285
  if(task.status==='unsupported')return {...common,status:'unsupported',outcome:'unsupported',reason:task.reason};
190
286
  if(task.status!=='ready'||!validTask(task))
@@ -232,7 +328,7 @@ async function attempt(task,script,taskFingerprint,selected,config,names=null) {
232
328
  async function counterexampleValues(task,selected,config) {
233
329
  const query=task.counterexample;
234
330
  if(!query||typeof query.script!=='string'||!Array.isArray(query.inputs))return null;
235
- if(fingerprint(['lawspec-smtlib-v2',task.programFingerprint,String(task.machineBits),task.owner,task.declaration,
331
+ if(fingerprint(['lawspec-smtlib-v2',task.lawFingerprint,String(task.machineBits),task.owner,task.declaration,
236
332
  query.script])!==query.fingerprint)return null;
237
333
  const names=query.inputs.map(input=>input.name);
238
334
  // A law with no inputs needs no search: the evaluator decides it.
@@ -267,7 +363,8 @@ export async function proveWithZ3(compiler,request,options={}) {
267
363
  catch(error){selected={error:error.message,outcome:error.code==='ENOENT'?'unavailable':error.outcome??'failed'};}
268
364
  }
269
365
  const solverEvidence=[];
270
- for(const task of tasks)solverEvidence.push(await solve(task,selected,config));
366
+ const cache=await receiptCache(request,selected);
367
+ for(const task of tasks)solverEvidence.push(await cachedSolve(task,selected,config,cache));
271
368
  const diagnostics=[...(result.diagnostics??[])];
272
369
  // Values to check as each unproved law's counterexample: the
273
370
  // counterexample query's (run whenever a law's task was satisfiable, and
@@ -324,7 +421,7 @@ export async function proveWithZ3(compiler,request,options={}) {
324
421
  while(changed) {
325
422
  changed=false;
326
423
  solverEvidence.forEach((item,index)=>{
327
- const cited=item.induction?.using??[];
424
+ const cited=(item.currentInduction??item.induction)?.using??[];
328
425
  if(item.status!=='proved'||!cited.length)return;
329
426
  const open=cited.filter(law=>!['proved','exhaustively-checked'].includes(current.get(law)));
330
427
  if(!open.length)return;
@@ -351,7 +448,8 @@ export async function proveWithZ3(compiler,request,options={}) {
351
448
  // model with its reference evaluator before a check is refuted.
352
449
  let settled=evidence,found=diagnostics;
353
450
  if(analysis.length) {
354
- const answers=[],ran=new Map();
451
+ let answers=[];
452
+ const ran=new Map();
355
453
  for(const row of analysis) {
356
454
  if(row.status!=='ready') {
357
455
  solverEvidence.push({owner:row.owner,declaration:row.declaration,stage:row.stage,kind:'analysis',
@@ -360,25 +458,47 @@ export async function proveWithZ3(compiler,request,options={}) {
360
458
  }
361
459
  for(const task of row.tasks) {
362
460
  if(selected.error) {ran.set(task.fingerprint,{row,outcome:selected.outcome,error:selected.error});continue;}
363
- const input=`(set-option :print-success false)\n(set-option :produce-models true)\n`+
364
- `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n`+task.script+'(check-sat)\n';
365
- const run=await execute(selected.binary,selected.args,input,config,true,
366
- token=>token==='sat'&&task.inputs.length?`(get-value (${task.inputs.join(' ')}))\n(exit)\n`:'(exit)\n');
367
- const outcome=await verifiedOutcome(run,selected);
368
- const values=outcome==='sat'&&task.inputs.length?run.stdout.slice(run.stdout.indexOf('\n')+1).trim():'';
369
- ran.set(task.fingerprint,{row,outcome,run,runFingerprint:fingerprint([task.fingerprint,selected.fingerprint,run.input])});
370
- answers.push({fingerprint:task.fingerprint,outcome,values});
461
+ const executeQuery=async()=>{
462
+ const input=`(set-option :print-success false)\n(set-option :produce-models true)\n`+
463
+ `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n`+task.script+'(check-sat)\n';
464
+ const run=await execute(selected.binary,selected.args,input,config,true,
465
+ token=>token==='sat'&&task.inputs.length?`(get-value (${task.inputs.join(' ')}))\n(exit)\n`:'(exit)\n');
466
+ const outcome=await verifiedOutcome(run,selected);
467
+ const values=outcome==='sat'&&task.inputs.length?run.stdout.slice(run.stdout.indexOf('\n')+1).trim():'';
468
+ return {outcome,run,values,runFingerprint:fingerprint([task.fingerprint,selected.fingerprint,run.input])};
469
+ };
470
+ const done=await analysisQuery(cache,row,task,selected,executeQuery);
471
+ ran.set(task.fingerprint,done);
472
+ answers.push({fingerprint:task.fingerprint,outcome:done.outcome,values:done.values,inputs:done.inputs});
473
+ }
474
+ }
475
+ let checked=answers.length?await compiler.proofTasks({...request,analysisResults:answers}):{};
476
+ // A stored SAT model can stop decoding after a public constructor rename.
477
+ // Revalidation fails closed; retry that query once with the current names.
478
+ let retried=false;
479
+ for(const verdict of checked.analysisChecks??[]) {
480
+ const done=ran.get(verdict.fingerprint);
481
+ if(verdict.status==='incomplete'&&done?.reused&&done.rerun) {
482
+ await rm(done.cacheFile,{force:true}).catch(()=>{});
483
+ ran.set(verdict.fingerprint,await done.rerun());retried=true;
371
484
  }
372
485
  }
373
- const checked=answers.length?await compiler.proofTasks({...request,analysisResults:answers}):{};
486
+ if(retried) {
487
+ answers=answers.map(answer=>{const done=ran.get(answer.fingerprint);return {...answer,
488
+ outcome:done.outcome,values:done.values,inputs:done.inputs};});
489
+ checked=await compiler.proofTasks({...request,analysisResults:answers});
490
+ }
374
491
  const rows=new Map((checked.analysisEvidence??[]).map(row=>[row.declaration+'\u0000'+row.stage,row]));
375
492
  settled=evidence.map(row=>rows.get(row.declaration+'\u0000'+row.stage)??row);
376
493
  found=[...diagnostics,...(checked.diagnostics??[]).filter(row=>row.code==='refuted')];
377
494
  for(const verdict of checked.analysisChecks??[]) {
378
495
  const done=ran.get(verdict.fingerprint)??{};
496
+ if(['proved','refuted','exempted'].includes(verdict.status))await saveQuery(done);
379
497
  solverEvidence.push({owner:verdict.owner,declaration:verdict.declaration,stage:verdict.stage,kind:'analysis',
380
- encoding:'lawspec-smtlib-v2',taskFingerprint:verdict.fingerprint,status:verdict.status,
381
- outcome:done.outcome??'failed',reason:verdict.reason,check:verdict.check,configuration:config,
498
+ encoding:'lawspec-smtlib-v2',taskFingerprint:done.reused?.taskFingerprint??verdict.fingerprint,status:verdict.status,
499
+ ...(done.reused?{currentTaskFingerprint:verdict.fingerprint,reused:done.reused}:{}),
500
+ outcome:done.outcome??'failed',reason:verdict.reason+(done.reused?'; reused a completed query; model revalidated by the current evaluator':''),
501
+ check:verdict.check,configuration:config,
382
502
  ...(done.run?{prover:{name:'z3',version:selected.version,binary:selected.binary,binaryFingerprint:selected.binaryFingerprint,
383
503
  fingerprint:selected.fingerprint,arguments:selected.args},runFingerprint:done.runFingerprint,
384
504
  elapsedMs:done.run.elapsedMs,exitCode:done.run.exitCode,stdout:done.run.stdout,stderr:done.run.stderr}:{})});
@@ -399,13 +519,14 @@ export async function proveWithZ3(compiler,request,options={}) {
399
519
  outcome:selected.outcome,reason:selected.error,configuration:config});
400
520
  }
401
521
  if(modelTasks.length&&!selected.error) {
402
- const answered=new Map(),modelAnswers=[],modelRows=new Map();
522
+ const answered=new Map(),modelAnswers=[],modelRows=new Map(),runs=new Map();
403
523
  let pending=modelTasks;
404
524
  for(let round=0;round<4;round++) {
405
525
  let fresh=0;
406
526
  for(const law of pending) for(const task of law.tasks) {
407
527
  if(answered.has(task.fingerprint))continue;
408
528
  fresh++;
529
+ const executeQuery=async()=>{
409
530
  const input=`(set-option :print-success false)\n(set-option :produce-models true)\n`+
410
531
  `(set-option :random-seed ${config.seed})\n(set-option :rlimit ${config.resourceLimit})\n`+task.script+'(check-sat)\n';
411
532
  const run=await execute(selected.binary,selected.args,input,config,true,token=>token!=='sat'?'(exit)\n':
@@ -417,21 +538,52 @@ export async function proveWithZ3(compiler,request,options={}) {
417
538
  const at=body.indexOf('(define-fun Inv ');
418
539
  if(at>=0) {let depth=0;for(let i=at;i<body.length;i++){if(body[i]==='(')depth++;if(body[i]===')'){depth--;if(depth===0){invariant=body.slice(at,i+1);break;}}}}
419
540
  }
420
- const answer={fingerprint:task.fingerprint,outcome,values:task.kind==='spacer'?'':body.trim(),invariant};
541
+
542
+ return {run,outcome,values:task.kind==='spacer'?'':body.trim(),invariant,
543
+ runFingerprint:fingerprint([task.fingerprint,selected.fingerprint,run.input])};
544
+ };
545
+ const row={kind:'model',owner:law.owner,declaration:law.declaration,stage:task.kind};
546
+ const done=await analysisQuery(cache,row,task,selected,executeQuery);
547
+ const answer={fingerprint:task.fingerprint,outcome:done.outcome,values:done.values,invariant:done.invariant??'',inputs:done.inputs??task.inputs};
421
548
  answered.set(task.fingerprint,answer);modelAnswers.push(answer);
422
- solverEvidence.push({kind:'model',owner:law.owner,declaration:law.declaration,task:task.kind,taskFingerprint:task.fingerprint,
423
- encoding:'lawspec-smtlib-v2',status:outcome==='unsat'?'proved':'incomplete',outcome,reason:task.kind+': '+outcome,
424
- prover:{name:'z3',version:selected.version,binary:selected.binary,binaryFingerprint:selected.binaryFingerprint,
425
- fingerprint:selected.fingerprint,arguments:selected.args},
426
- runFingerprint:fingerprint([task.fingerprint,selected.fingerprint,run.input]),elapsedMs:run.elapsedMs,
427
- exitCode:run.exitCode,signal:run.signal,stdout:run.stdout,stderr:run.stderr,configuration:config});
549
+ runs.set(task.fingerprint,{row,task,done});
428
550
  }
429
551
  if(!fresh)break;
430
- const checked=await compiler.proofTasks({...request,modelResults:modelAnswers});
552
+ let checked=await compiler.proofTasks({...request,modelResults:modelAnswers});
553
+ let retry=false;
554
+ for(const check of checked.modelChecks??[]){
555
+ const observation=runs.get(check.fingerprint);
556
+ if(check.status!=='model-not-confirmed'||!observation?.done.reused||!observation.done.rerun)continue;
557
+ await rm(observation.done.cacheFile,{force:true}).catch(()=>{});
558
+ observation.done=await observation.done.rerun();
559
+ const {task,done}=observation;
560
+ const answer={fingerprint:task.fingerprint,outcome:done.outcome,values:done.values,
561
+ invariant:done.invariant??'',inputs:done.inputs??task.inputs};
562
+ answered.set(task.fingerprint,answer);
563
+ modelAnswers[modelAnswers.findIndex(value=>value.fingerprint===task.fingerprint)]=answer;
564
+ retry=true;
565
+ }
566
+ if(retry)checked=await compiler.proofTasks({...request,modelResults:modelAnswers});
431
567
  for(const row of checked.modelEvidence??[])modelRows.set(row.declaration,row);
432
568
  for(const d of checked.diagnostics??[])if(d.code==='refuted'&&!found.some(e=>e.message===d.message))found=[...found,d];
433
569
  pending=checked.modelTasks??[];
434
570
  }
571
+ for(const {row,task,done} of runs.values()){
572
+ // Current model settlement still checks every proof/replay obligation.
573
+ // A reused raw query never substitutes for that compiler decision.
574
+ if(task.kind!=='bounded search'||done.outcome!=='sat'||modelRows.get(row.declaration)?.status==='refuted')
575
+ await saveQuery(done);
576
+ const run=done.run,outcome=done.outcome;
577
+ solverEvidence.push({kind:'model',owner:row.owner,declaration:row.declaration,task:task.kind,
578
+ taskFingerprint:done.reused?.taskFingerprint??task.fingerprint,
579
+ ...(done.reused?{currentTaskFingerprint:task.fingerprint,reused:done.reused}:{}),
580
+ encoding:'lawspec-smtlib-v2',status:outcome==='unsat'?'proved':'incomplete',outcome,reason:task.kind+': '+outcome+
581
+ (done.reused?'; reused original solver query; current compiler rechecks the model evidence':''),
582
+ prover:{name:'z3',version:selected.version,binary:selected.binary,binaryFingerprint:selected.binaryFingerprint,
583
+ fingerprint:selected.fingerprint,arguments:selected.args},
584
+ runFingerprint:done.runFingerprint,elapsedMs:run.elapsedMs,
585
+ exitCode:run.exitCode,signal:run.signal,stdout:run.stdout,stderr:run.stderr,configuration:config});
586
+ }
435
587
  settled=settled.map(row=>row.stage==='law'&&modelRows.has(row.declaration)?{...row,...modelRows.get(row.declaration)}:row);
436
588
  }
437
589
  return {...result,diagnostics:found,evidence:settled,solverEvidence};