lawspec 0.29.2 → 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 (79) hide show
  1. package/CHANGELOG.md +407 -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 +100 -102
  6. package/build.json +503 -411
  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/examples/specs/harness_testing.lawspec +1 -1
  38. package/files.mjs +2 -1
  39. package/go.mod +4 -0
  40. package/index.d.ts +145 -8
  41. package/input-files.mjs +47 -0
  42. package/launcher.mjs +33 -13
  43. package/lsp.mjs +10 -5
  44. package/native-evidence.mjs +58 -19
  45. package/native-examples.mjs +8 -7
  46. package/native-host.mjs +71 -0
  47. package/package.json +8 -3
  48. package/proof.d.ts +8 -2
  49. package/proof.mjs +186 -34
  50. package/scala-build-state.mjs +59 -0
  51. package/templates.mjs +242 -2
  52. package/test-command.mjs +193 -61
  53. package/builtin-data-names.mjs +0 -73
  54. package/examples/native-payments/clojure/lawspec.json +0 -62
  55. package/examples/native-payments/csharp/lawspec.json +0 -62
  56. package/examples/native-payments/elixir/lawspec.json +0 -160
  57. package/examples/native-payments/erlang/lawspec.json +0 -159
  58. package/examples/native-payments/fsharp/lawspec.json +0 -178
  59. package/examples/native-payments/gleam/lawspec.json +0 -160
  60. package/examples/native-payments/go/lawspec.json +0 -147
  61. package/examples/native-payments/groovy/lawspec.json +0 -176
  62. package/examples/native-payments/haskell/lawspec.json +0 -160
  63. package/examples/native-payments/java/lawspec.json +0 -176
  64. package/examples/native-payments/javascript/lawspec.json +0 -160
  65. package/examples/native-payments/kotlin/lawspec.json +0 -176
  66. package/examples/native-payments/prolog/lawspec.json +0 -20
  67. package/examples/native-payments/python/lawspec.json +0 -160
  68. package/examples/native-payments/rust/lawspec.json +0 -178
  69. package/examples/native-payments/scala/lawspec.json +0 -176
  70. package/examples/native-payments/swift/lawspec.json +0 -165
  71. package/examples/native-payments/typescript/lawspec.json +0 -160
  72. package/examples/packages/orders/lawspec.json +0 -27
  73. package/examples/packages/shop-domain/lawspec-package.json +0 -7
  74. package/examples/packages/shop-tax-1/lawspec-package.json +0 -5
  75. package/examples/packages/shop-tax-2/lawspec-package.json +0 -5
  76. package/explain.mjs +0 -114
  77. package/expression-presentation.mjs +0 -333
  78. package/positional-fields.mjs +0 -13
  79. package/typed-presentation.mjs +0 -165
@@ -0,0 +1,123 @@
1
+ {
2
+ :manifest-version 1
3
+ :component {
4
+ :name "typescript"
5
+ :version "0.1.0"
6
+ }
7
+ :sources ["laws"]
8
+ :machine-bits 64
9
+ :targets [
10
+ {
11
+ :language :typescript
12
+ :root "."
13
+ :native-bindings {
14
+ :types [
15
+ {
16
+ :type "example.payments::type::Currency"
17
+ :native ["payments_domain" "CurrencyCode"]
18
+ :constructors [
19
+ {
20
+ :constructor "USD"
21
+ :native ["payments_domain" "Dollars"]
22
+ :style "unit"
23
+ :fields []
24
+ }
25
+ {
26
+ :constructor "EUR"
27
+ :native ["payments_domain" "Euros"]
28
+ :style "unit"
29
+ :fields []
30
+ }
31
+ {
32
+ :constructor "GBP"
33
+ :native ["payments_domain" "Pounds"]
34
+ :style "unit"
35
+ :fields []
36
+ }
37
+ ]
38
+ }
39
+ {
40
+ :type "example.payments::type::Money"
41
+ :native ["payments_domain" "Price"]
42
+ :constructors [
43
+ {
44
+ :constructor "Money"
45
+ :native ["payments_domain" "Price"]
46
+ :style "record"
47
+ :fields [
48
+ {
49
+ :field "amount"
50
+ :native "major"
51
+ }
52
+ {
53
+ :field "currency"
54
+ :native "unit"
55
+ }
56
+ ]
57
+ }
58
+ ]
59
+ }
60
+ {
61
+ :type "example.payments::type::Payment"
62
+ :native ["payments_domain" "PaymentStatus"]
63
+ :constructors [
64
+ {
65
+ :constructor "Paid"
66
+ :native ["payments_domain" "Settled"]
67
+ :style "variant"
68
+ :fields [
69
+ {
70
+ :field "value"
71
+ :native "price"
72
+ }
73
+ ]
74
+ }
75
+ {
76
+ :constructor "Declined"
77
+ :native ["payments_domain" "Rejected"]
78
+ :style "variant"
79
+ :fields [
80
+ {
81
+ :field "value"
82
+ :native "explanation"
83
+ }
84
+ ]
85
+ }
86
+ ]
87
+ }
88
+ ]
89
+ :functions [
90
+ {
91
+ :declaration "example.payments::addFee"
92
+ :native ["payments_domain" "apply_fee"]
93
+ }
94
+ {
95
+ :declaration "example.payments::roundTrip"
96
+ :native ["payments_domain" "restore"]
97
+ }
98
+ {
99
+ :declaration "example.payments::archive"
100
+ :native ["payments_domain" "store"]
101
+ }
102
+ ]
103
+ :generators [
104
+ {
105
+ :type "example.payments::type::Money"
106
+ :factory ["lawspec_generators" "prices"]
107
+ }
108
+ ]
109
+ }
110
+ }
111
+ ]
112
+ :language-profile "1.0-rc.2"
113
+ :verification {
114
+ :layers [
115
+ :proof
116
+ :exhaustive
117
+ :property
118
+ :examples
119
+ :runtime
120
+ :model
121
+ ]
122
+ }
123
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ :manifest-version 1
3
+ :component {
4
+ :name "orders"
5
+ :version "0.1.0"
6
+ }
7
+ :sources ["orders.lawspec"]
8
+ :dependencies {
9
+ "shop.domain" "^1.0.0"
10
+ "shop.tax" "^2.0.0"
11
+ }
12
+ :packages ["../shop-domain" "../shop-tax-1" "../shop-tax-2"]
13
+ :targets []
14
+ :language-profile "1.0-rc.2"
15
+ :verification {
16
+ :layers [
17
+ :proof
18
+ :exhaustive
19
+ :property
20
+ :examples
21
+ :runtime
22
+ :model
23
+ ]
24
+ }
25
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ :manifest-version 1
3
+ :package {
4
+ :name "shop.domain"
5
+ :version "1.2.0"
6
+ }
7
+ :language-profile "1.0-rc.2"
8
+ :sources ["src"]
9
+ :dependencies {
10
+ "shop.tax" "^1.0.0"
11
+ }
12
+ :packages ["../shop-tax-1"]
13
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ :manifest-version 1
3
+ :package {
4
+ :name "shop.tax"
5
+ :version "1.0.0"
6
+ }
7
+ :language-profile "1.0-rc.2"
8
+ :sources ["src"]
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ :manifest-version 1
3
+ :package {
4
+ :name "shop.tax"
5
+ :version "2.0.0"
6
+ }
7
+ :language-profile "1.0-rc.2"
8
+ :sources ["src"]
9
+ }
@@ -1,7 +1,7 @@
1
1
  unit example.till
2
2
 
3
3
  -- An ability whose production handler is application code, named in
4
- -- lawspec.json under handlers. Money is bound to a native type there too, so
4
+ -- lawspec.edn under handlers. Money is bound to a native type there too, so
5
5
  -- the handler's operations take and give that type.
6
6
 
7
7
  type Money is a record{ cents :: Int64} end type
@@ -26,7 +26,7 @@ handler fakeDrawer for Drawer is
26
26
  end handler
27
27
 
28
28
  -- A native adapter that fails. Its native code raises the application's own
29
- -- exceptions; lawspec.json maps them to PayError's constructors.
29
+ -- exceptions; lawspec.edn maps them to PayError's constructors.
30
30
  pay :: Int64 -> Money uses Drawer fails with PayError
31
31
 
32
32
  law "|small payments go through| is
@@ -32,7 +32,7 @@ harness example.harness.testing for example.harness is
32
32
 
33
33
  end for law
34
34
  for law "|rounding never lowers a price|
35
- known failing "rounds half down; see PRICE-12"
35
+ known discrepancy "rounds half down; see PRICE-12"
36
36
 
37
37
  end for law
38
38
  for law "|a refund is never booked twice|
package/files.mjs CHANGED
@@ -19,7 +19,8 @@ export const digest = (text) =>
19
19
  export async function collectSources(root,entries,relativeTo=root){
20
20
  const files=[];
21
21
  async function visit(file){
22
- const info=await stat(file);
22
+ const info=await lstat(file);
23
+ if(info.isSymbolicLink())throw new Error(`Symbolic links are not supported in LawSpec sources: ${file}`);
23
24
  if(info.isDirectory())for(const entry of (await readdir(file)).sort())await visit(path.join(file,entry));
24
25
  else if(file.endsWith('.lawspec'))files.push(file);
25
26
  }
package/go.mod ADDED
@@ -0,0 +1,4 @@
1
+ // Generated from templates/npm/go.mod by lawspec-dev generate. Do not edit.
2
+ module github.com/brain-fuel/lawspec/npm
3
+
4
+ go 1.25.0
package/index.d.ts CHANGED
@@ -131,6 +131,13 @@ export type ExprNode =
131
131
  } |
132
132
  {kind: 'match'; value: Expr; cases: MatchCase[];} |
133
133
  {kind: 'allElements'; value: Expr; binder: Binder; predicate: Expr;} |
134
+ {
135
+ kind: 'searchElements';
136
+ universal: boolean;
137
+ value: Expr;
138
+ binder: Binder;
139
+ predicate: Expr;
140
+ } |
134
141
  {kind: 'allPayloads'; value: Expr; predicates: PayloadPredicate[];} |
135
142
  {kind: 'construct'; constructor: string; arguments: Expr[];} |
136
143
  {kind: 'local'; id: string;} |
@@ -238,7 +245,7 @@ export interface LawHarness {
238
245
  unit: string | null;
239
246
  tags: string[];
240
247
  skip: string | null;
241
- knownFailing: string | null;
248
+ knownDiscrepancy: string | null;
242
249
  timeoutMilliseconds: number | null;
243
250
  repeat: number;
244
251
  retries: number;
@@ -427,7 +434,7 @@ export type DischargeStatus =
427
434
  'not-verified' |
428
435
  'incomplete' |
429
436
  'unsupported' |
430
- 'known-failing' |
437
+ 'known-discrepancy' |
431
438
  'flaky' |
432
439
  'skipped' |
433
440
  'pending' |
@@ -455,6 +462,7 @@ export interface ObligationEvidence {
455
462
  plannedEnvironment?: string;
456
463
  plannedEnvironmentRun?: AttestedRun;
457
464
  plannedAgainst?: AttestedDependency[];
465
+ environmentOutcome?: NativeOutcome;
458
466
  nativeEvidence?: NativeConformanceEvidence;
459
467
  adequacy?: NativeAdequacy[];
460
468
  plannedEvidence?: {status: DischargeStatus; reason: string};
@@ -464,6 +472,56 @@ export interface AttestedRun {
464
472
  id: string;
465
473
  startedAt: string;
466
474
  recordedAt: string;
475
+ execution?: AttestedExecution;
476
+ }
477
+
478
+ export interface AttestedExecution {
479
+ status: 'wired' | 'running' | 'completed';
480
+ exitCode?: number;
481
+ finishedAt?: string;
482
+ }
483
+
484
+ export interface AttestedArchitecture {
485
+ document: string;
486
+ digest: string;
487
+ uniqueId?: string;
488
+ decorators?: string;
489
+ decoratorsDigest?: string;
490
+ topologyDigest?: string;
491
+ elements?: string[];
492
+ }
493
+
494
+ export interface AttestedComponent extends PackageVersion {
495
+ fingerprint: string;
496
+ [key: string]: unknown;
497
+ }
498
+
499
+ export interface AttestedCompletion {
500
+ reached: boolean;
501
+ historyDigest?: string;
502
+ historyEntries?: number;
503
+ }
504
+
505
+ export interface AttestedContract {
506
+ package: string;
507
+ version: string;
508
+ abilities?: string[];
509
+ digest?: string;
510
+ }
511
+
512
+ export interface AttestedImplementation {
513
+ kind: string;
514
+ product: string;
515
+ version: string;
516
+ commit?: string;
517
+ imageDigest?: string;
518
+ }
519
+
520
+ export interface AttestedApplication {
521
+ node: string;
522
+ contract?: AttestedContract;
523
+ implementation: AttestedImplementation;
524
+ component?: AttestedComponent;
467
525
  }
468
526
 
469
527
  export interface AttestedStandIn {
@@ -471,6 +529,8 @@ export interface AttestedStandIn {
471
529
  version: string;
472
530
  conformance: string;
473
531
  historyDigest?: string;
532
+ historyEntries?: number;
533
+ standsInFor?: AttestedContract;
474
534
  }
475
535
 
476
536
  export interface AttestedDependency {
@@ -479,12 +539,19 @@ export interface AttestedDependency {
479
539
  reached: boolean;
480
540
  kind: 'real' | 'stand-in';
481
541
  standIn?: AttestedStandIn;
542
+ node?: string;
543
+ edge?: string;
544
+ contract?: AttestedContract;
545
+ implementation?: AttestedImplementation;
546
+ completed?: AttestedCompletion;
482
547
  }
483
548
 
484
549
  export interface AttestationView {
485
550
  environment: string;
486
551
  run: AttestedRun;
487
552
  producer?: PackageVersion;
553
+ application?: AttestedApplication;
554
+ architecture?: AttestedArchitecture;
488
555
  dependencies: (AttestedDependency &
489
556
  {obligations: string[]; plannedObligations: string[];})[];
490
557
  }
@@ -553,6 +620,13 @@ export interface ModelResult {
553
620
  outcome: string;
554
621
  values: string;
555
622
  invariant: string;
623
+ inputs?: string[];
624
+ }
625
+
626
+ export interface ModelAnswerCheck {
627
+ fingerprint: string;
628
+ status: 'confirmed' | 'model-not-confirmed';
629
+ reason: string;
556
630
  }
557
631
 
558
632
  export interface ModelTaskRow {
@@ -563,6 +637,7 @@ export interface ModelTaskRow {
563
637
 
564
638
  export interface ModelTask {
565
639
  fingerprint: string;
640
+ semanticFingerprint: string;
566
641
  kind: string;
567
642
  script: string;
568
643
  inputs: string[];
@@ -579,6 +654,7 @@ export interface AnalysisResult {
579
654
  fingerprint: string;
580
655
  outcome: string;
581
656
  values: string;
657
+ inputs?: string[];
582
658
  }
583
659
 
584
660
  export type AnalysisStage = 'completeness' | 'overlap' | 'conflict' | 'vacuity';
@@ -601,6 +677,7 @@ export type AnalysisTaskRow =
601
677
 
602
678
  export interface AnalysisTask {
603
679
  fingerprint: string;
680
+ semanticFingerprint: string;
604
681
  encoding: 'lawspec-smtlib-v2';
605
682
  script: string;
606
683
  inputs: string[];
@@ -623,6 +700,57 @@ export interface FormatRequest extends CheckRequest {
623
700
  compile?: boolean;
624
701
  }
625
702
 
703
+ export type ExplainView = 'eng' | 'math' | 'dev';
704
+
705
+ export interface ExplainRequest extends CheckRequest {
706
+ view?: ExplainView;
707
+ law?: string;
708
+ evidence?: ObligationEvidence[];
709
+ }
710
+
711
+ export type ExplanationSectionKind =
712
+ 'title' |
713
+ 'documentary' |
714
+ 'description' |
715
+ 'inputs' |
716
+ 'statement' |
717
+ 'reason' |
718
+ 'quantifiers' |
719
+ 'formula' |
720
+ 'law' |
721
+ 'trace' |
722
+ 'strategies' |
723
+ 'restrictions' |
724
+ 'source' |
725
+ 'examples' |
726
+ 'native-evidence';
727
+
728
+ export interface ExplanationCase {
729
+ type: string;
730
+ case: string;
731
+ cases: string[];
732
+ }
733
+
734
+ export interface ExplanationSection {
735
+ kind: ExplanationSectionKind;
736
+ lines: string[];
737
+ cases?: ExplanationCase[];
738
+ }
739
+
740
+ export interface Explanation {
741
+ view: ExplainView;
742
+ law: string;
743
+ name: string;
744
+ sections: ExplanationSection[];
745
+ }
746
+
747
+ export interface ExplainResult {
748
+ schemaVersion?: 5;
749
+ diagnostics: Diagnostic[];
750
+ explanations?: Explanation[];
751
+ text?: string;
752
+ }
753
+
626
754
  export interface GenerationRequest extends CheckRequest {
627
755
  target: Target;
628
756
  sourceDir?: string;
@@ -636,7 +764,7 @@ export type ProofTask =
636
764
  owner: string;
637
765
  declaration: string;
638
766
  at: Location;
639
- programFingerprint: string;
767
+ lawFingerprint: string;
640
768
  machineBits: 32 | 64;
641
769
  status: 'ready';
642
770
  script: string;
@@ -653,7 +781,7 @@ export type ProofTask =
653
781
  owner: string;
654
782
  declaration: string;
655
783
  at: Location;
656
- programFingerprint: string;
784
+ lawFingerprint: string;
657
785
  machineBits: 32 | 64;
658
786
  status: 'unsupported';
659
787
  reason: string;
@@ -706,6 +834,7 @@ export type CounterexampleQuery =
706
834
  encoding: 'lawspec-smtlib-v2';
707
835
  script: string;
708
836
  fingerprint: string;
837
+ semanticFingerprint: string;
709
838
  inputs: {name: string; binder: string}[];
710
839
  };
711
840
 
@@ -730,7 +859,7 @@ export type NativeConformanceStatus =
730
859
  'partial' |
731
860
  'incomplete' |
732
861
  'skipped' |
733
- 'known-failing' |
862
+ 'known-discrepancy' |
734
863
  'not-selected' |
735
864
  'stale' |
736
865
  'unavailable';
@@ -741,7 +870,7 @@ export type NativeOutcome =
741
870
  'skipped' |
742
871
  'incomplete' |
743
872
  'not-run' |
744
- 'known-failing';
873
+ 'known-discrepancy';
745
874
 
746
875
  export interface NativeCompletedTest {
747
876
  name: string;
@@ -791,8 +920,14 @@ export interface NativeExecutionAttempt {
791
920
  invocation: NativeInvocation;
792
921
  verification: 'native-execution';
793
922
  searchCompleteness: 'not-established';
923
+ executionRun?: string;
924
+ environment?: string;
794
925
  }
795
926
 
927
+ export type RecordedNativeExecutionAttempt =
928
+ Omit<NativeExecutionAttempt, 'outcome'> &
929
+ {outcome: NativeOutcome | 'known-failing';};
930
+
796
931
  export interface NativeExecutionObservation {
797
932
  target: string;
798
933
  root: string;
@@ -802,7 +937,7 @@ export interface NativeExecutionObservation {
802
937
  check?: {id: string; obligations: NativeEvidenceTarget[]};
803
938
  obligations?: NativeEvidenceTarget[];
804
939
  coverage?: NativeCheckCoverage;
805
- attempt?: NativeExecutionAttempt;
940
+ attempt?: RecordedNativeExecutionAttempt;
806
941
  harness?: {flaky?: boolean; adequacy?: NativeAdequacy[]};
807
942
  }
808
943
 
@@ -850,7 +985,7 @@ export interface NativeTestEntry {
850
985
  name: string;
851
986
  tags: string[];
852
987
  skip: string | null;
853
- knownFailing: string | null;
988
+ knownDiscrepancy: string | null;
854
989
  parallel: boolean;
855
990
  kind?: 'model';
856
991
  scope?: string;
@@ -882,6 +1017,7 @@ export interface Result {
882
1017
  analysisEvidence?: ObligationEvidence[];
883
1018
  analysisChecks?: AnalysisCheck[];
884
1019
  modelTasks?: ModelTaskRow[];
1020
+ modelChecks?: ModelAnswerCheck[];
885
1021
  modelEvidence?: ObligationEvidence[];
886
1022
  counterexampleChecks?: CounterexampleCheck[];
887
1023
  evidence?: ObligationEvidence[];
@@ -942,6 +1078,7 @@ export interface Compiler {
942
1078
  format(input: FormatRequest): Promise<Result>;
943
1079
  check(input: CheckRequest): Promise<Result>;
944
1080
  expand(input: CheckRequest): Promise<Result>;
1081
+ explain(input: ExplainRequest): Promise<ExplainResult>;
945
1082
  proofTasks(input: CheckRequest): Promise<Result>;
946
1083
  planGeneration(input: GenerationRequest): Promise<Result>;
947
1084
  }
@@ -0,0 +1,47 @@
1
+ // Generated from templates/npm/input-files.mjs by lawspec-dev generate. Do not edit.
2
+ // Native implementations may depend on declared files outside their target
3
+ // directory. Component descriptions and native result keys share this walker.
4
+ import {createHash} from 'node:crypto';
5
+ import {lstat,readFile,readdir} from 'node:fs/promises';
6
+ import path from 'node:path';
7
+
8
+ export const buildDirectories = new Set(['.git','.lawspec','node_modules','dist','build','target','out','.gradle','bin','obj','TestResults',
9
+ '.stack-work','_build','deps','.elixir_ls','__pycache__','.hypothesis','.pytest_cache','.venv','venv','.idea','.vscode',
10
+ '.scala-build','.bsp','.bloop','.metals','.build','.swiftpm','.cpcache']);
11
+
12
+ // These outputs belong to the generated crypto builder; its sources and
13
+ // other priv/ assets still contribute to the native implementation identity.
14
+ export const cryptoBuildOutput = file => /(?:^|\/)priv\/lawspec_crypto_native\.(?:so|dll)(?:\.build|\.\d+\.tmp)?$/.test(file);
15
+
16
+ // Execution reports are observations, independent of implementation inputs.
17
+ // ref:DEC-completed-run-attestation
18
+ export function isAttestation(content) {
19
+ try {
20
+ const value = JSON.parse(content);
21
+ return value !== null && typeof value === 'object' && value.format === 'environment-attestation';
22
+ } catch { return false; }
23
+ }
24
+
25
+ export async function fingerprintInputs(root,inputs,{generated=new Set()}={}) {
26
+ if(!Array.isArray(inputs)||inputs.some(entry=>typeof entry!=='string'||!entry))
27
+ throw new Error('Component inputs must be an array of nonempty paths');
28
+ const rows = new Map();
29
+ async function visit(file,relative) {
30
+ const info = await lstat(file);
31
+ if(info.isSymbolicLink())throw new Error(`Symbolic links are not supported in component inputs: ${relative}`);
32
+ if(info.isDirectory()) {
33
+ for(const entry of (await readdir(file)).sort()) {
34
+ if(buildDirectories.has(entry))continue;
35
+ const next=relative+'/'+entry;
36
+ if(next.endsWith('testdata/rapid'))continue;
37
+ await visit(path.join(file,entry),next);
38
+ }
39
+ } else if(info.isFile()&&!generated.has(path.resolve(file))&&!cryptoBuildOutput(relative)) {
40
+ const content=await readFile(file);
41
+ if(relative.endsWith('.json')&&isAttestation(content.toString('utf8')))return;
42
+ rows.set(relative,createHash('sha256').update(content).digest('hex'));
43
+ }
44
+ }
45
+ for(const entry of inputs)await visit(path.resolve(root,entry),entry.split(path.sep).join('/'));
46
+ return [...rows].sort(([left],[right])=>left<right?-1:left>right?1:0);
47
+ }
package/launcher.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  // Generated from templates/npm/launcher.mjs by lawspec-dev generate. Do not edit.
2
- import { readFile } from "node:fs/promises";
2
+ import { mkdir, readFile } from "node:fs/promises";
3
+ import { createHash } from "node:crypto";
4
+ import path from "node:path";
3
5
  let compiled;
4
6
 
5
7
  // GHC's JSFFI reactor reads these WASI arguments during initialization. Bound
@@ -34,16 +36,34 @@ export async function loadCore() {
34
36
  const { WASI } = await import("node:wasi");
35
37
  if (Number(process.versions.node.split(".")[0]) < 22)
36
38
  throw new Error("LawSpec requires Node 22+");
37
- compiled ??= readFile(new URL("./core.wasm", import.meta.url)).then(
38
- WebAssembly.compile,
39
- );
40
- const wasi = new WASI({
41
- version: "preview1",
42
- args: coreArguments,
43
- env: { PWD: "/" },
44
- preopens: { "/": process.cwd() },
45
- });
46
- return instantiateCore(await compiled, wasi.wasiImport, (instance) =>
47
- wasi.initialize(instance),
48
- );
39
+ compiled ??= readFile(new URL("./core.wasm", import.meta.url)).then(async bytes => ({
40
+ module: await WebAssembly.compile(bytes),
41
+ build: createHash("sha256").update(bytes).digest("hex"),
42
+ }));
43
+ const {module,build}=await compiled;
44
+ let activeRoot, invoke;
45
+ let pending=Promise.resolve();
46
+ const request=async input=>{
47
+ const validCache=typeof input.cacheDirectory==='string';
48
+ let root=validCache&&input.cacheDirectory?path.resolve(input.cacheDirectory):null;
49
+ if(root)try{await mkdir(root,{recursive:true});}catch{root=null;}
50
+ // The requested host directory is an explicit mount, rather than an
51
+ // absolute WASI path accidentally interpreted below cwd. The binary
52
+ // identity separates persisted memos even within one package version.
53
+ if(!invoke||root!==activeRoot){
54
+ const wasi = new WASI({
55
+ version: "preview1", args: coreArguments, env: { PWD: "/" },
56
+ preopens: { "/": process.cwd(), ...(root?{"/lawspec-cache":root}:{}) },
57
+ });
58
+ invoke=await instantiateCore(module,wasi.wasiImport,instance=>wasi.initialize(instance));
59
+ activeRoot=root;
60
+ }
61
+ return invoke({...input,...(validCache?{cacheDirectory:root?`/lawspec-cache/${build}`:undefined}:{})});
62
+ };
63
+ // Cache-root changes are serialized with calls on the active instance.
64
+ return input=>{
65
+ const result=pending.then(()=>request(input));
66
+ pending=result.then(()=>{},()=>{});
67
+ return result;
68
+ };
49
69
  }
package/lsp.mjs CHANGED
@@ -3,6 +3,7 @@ import { readFile, readdir, stat } from 'node:fs/promises';
3
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  import path from 'node:path';
5
5
  import { createCompiler } from './api.mjs';
6
+ import {findManifest, readManifest} from './component.mjs';
6
7
 
7
8
  export function utf16Position(text, location) {
8
9
  const line = Math.max(0, location.line - 1);
@@ -44,11 +45,15 @@ export async function serveLanguage(input = process.stdin, output = process.stdo
44
45
  else if (file.endsWith('.lawspec')) sources.set(file, { path: file, content: await readFile(file, 'utf8') });
45
46
  }
46
47
  let config;
47
- try { config = JSON.parse(await readFile(path.join(workspace, 'lawspec.json'), 'utf8')); }
48
- catch (error) { if (error.code !== 'ENOENT') throw error; }
49
- if(config&&(config.version!==2||config.languageProfile!=='1.0-rc.2'))
50
- throw new Error('The language server requires configuration version 2 and languageProfile 1.0-rc.2.');
51
- for (const entry of config?.sources ?? []) await visit(path.resolve(workspace, entry));
48
+ let root = workspace;
49
+ try {
50
+ const file = await findManifest(workspace);
51
+ config = await readManifest(file);
52
+ root = path.dirname(file);
53
+ } catch (error) {
54
+ if (!/No lawspec\.edn found/.test(error.message)) throw error;
55
+ }
56
+ for (const entry of config?.sources ?? []) await visit(path.resolve(root, entry));
52
57
  for (const [uri, document] of documents) sources.set(fileURLToPath(uri), { path: fileURLToPath(uri), content: document.text });
53
58
  return [...sources.values()];
54
59
  }