@sublang/spex 6.0.0 → 7.0.0-beta.2

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 (108) hide show
  1. package/README.md +419 -12
  2. package/dist/cli.js +12 -1
  3. package/dist/commands/add.d.ts +1 -1
  4. package/dist/commands/add.js +2 -2
  5. package/dist/commands/environment.d.ts +3 -3
  6. package/dist/commands/environment.js +5 -7
  7. package/dist/commands/export.js +2 -2
  8. package/dist/commands/home.d.ts +2 -2
  9. package/dist/commands/home.js +3 -3
  10. package/dist/commands/list.js +1 -1
  11. package/dist/commands/login.js +12 -7
  12. package/dist/commands/logout.js +2 -3
  13. package/dist/commands/publish.js +1 -1
  14. package/dist/commands/remove.js +1 -1
  15. package/dist/commands/run.d.ts +1 -1
  16. package/dist/commands/run.js +16 -0
  17. package/dist/commands/settle.d.ts +1 -1
  18. package/dist/commands/settle.js +1 -1
  19. package/dist/guards/approval.d.ts +56 -0
  20. package/dist/guards/approval.js +158 -0
  21. package/dist/guards/checks.d.ts +207 -0
  22. package/dist/guards/checks.js +681 -0
  23. package/dist/guards/commands.d.ts +15 -0
  24. package/dist/guards/commands.js +313 -0
  25. package/dist/guards/copy.d.ts +67 -0
  26. package/dist/guards/copy.js +306 -0
  27. package/dist/guards/declaration.d.ts +45 -0
  28. package/dist/guards/declaration.js +224 -0
  29. package/dist/guards/files.d.ts +137 -0
  30. package/dist/guards/files.js +544 -0
  31. package/dist/guards/harness.d.ts +58 -0
  32. package/dist/guards/harness.js +420 -0
  33. package/dist/guards/items.d.ts +61 -0
  34. package/dist/guards/items.js +161 -0
  35. package/dist/guards/patch.d.ts +55 -0
  36. package/dist/guards/patch.js +258 -0
  37. package/dist/guards/processes.d.ts +49 -0
  38. package/dist/guards/processes.js +233 -0
  39. package/dist/guards/proofs.d.ts +88 -0
  40. package/dist/guards/proofs.js +503 -0
  41. package/dist/guards/records.d.ts +176 -0
  42. package/dist/guards/records.js +513 -0
  43. package/dist/guards/report.d.ts +26 -0
  44. package/dist/guards/report.js +492 -0
  45. package/dist/guards/runner.d.ts +42 -0
  46. package/dist/guards/runner.js +167 -0
  47. package/dist/guards/tla.d.ts +51 -0
  48. package/dist/guards/tla.js +352 -0
  49. package/dist/guards/tlapm.d.ts +81 -0
  50. package/dist/guards/tlapm.js +172 -0
  51. package/dist/guards/tlc.d.ts +191 -0
  52. package/dist/guards/tlc.js +457 -0
  53. package/dist/guards/translation.d.ts +66 -0
  54. package/dist/guards/translation.js +202 -0
  55. package/dist/guards/types.d.ts +185 -0
  56. package/dist/guards/types.js +437 -0
  57. package/dist/guards/verify.d.ts +290 -0
  58. package/dist/guards/verify.js +1191 -0
  59. package/dist/guards/xml.d.ts +18 -0
  60. package/dist/guards/xml.js +105 -0
  61. package/dist/lib/environment/archive.d.ts +2 -2
  62. package/dist/lib/environment/archive.js +1 -1
  63. package/dist/lib/environment/builtins.d.ts +10 -12
  64. package/dist/lib/environment/builtins.js +17 -19
  65. package/dist/lib/environment/exports.d.ts +14 -13
  66. package/dist/lib/environment/exports.js +31 -16
  67. package/dist/lib/environment/format.d.ts +2 -2
  68. package/dist/lib/environment/format.js +3 -3
  69. package/dist/lib/environment/git-source.js +6 -3
  70. package/dist/lib/environment/install.d.ts +14 -16
  71. package/dist/lib/environment/install.js +66 -61
  72. package/dist/lib/environment/lock.d.ts +4 -3
  73. package/dist/lib/environment/lock.js +6 -5
  74. package/dist/lib/environment/marker.js +1 -2
  75. package/dist/lib/environment/own-paths.d.ts +7 -10
  76. package/dist/lib/environment/own-paths.js +10 -13
  77. package/dist/lib/environment/placed-record.d.ts +3 -2
  78. package/dist/lib/environment/placed-record.js +5 -4
  79. package/dist/lib/environment/registry.d.ts +1 -1
  80. package/dist/lib/environment/registry.js +1 -1
  81. package/dist/lib/environment/requests.d.ts +2 -2
  82. package/dist/lib/environment/requests.js +2 -2
  83. package/dist/lib/environment/resolve.d.ts +4 -4
  84. package/dist/lib/environment/resolve.js +3 -4
  85. package/dist/lib/environment/store.d.ts +34 -8
  86. package/dist/lib/environment/store.js +138 -43
  87. package/dist/lib/files.d.ts +72 -12
  88. package/dist/lib/files.js +200 -65
  89. package/dist/lib/git-host.d.ts +52 -258
  90. package/dist/lib/git-host.js +52 -265
  91. package/dist/lib/home-file.d.ts +13 -10
  92. package/dist/lib/home-file.js +28 -18
  93. package/dist/lib/instance.d.ts +1 -1
  94. package/dist/lib/instance.js +1 -1
  95. package/dist/lint.d.ts +22 -0
  96. package/dist/lint.js +36 -0
  97. package/dist/testing/standin-registry.js +1 -1
  98. package/package.json +7 -3
  99. package/scaffold/.file-history.json +14 -7
  100. package/scaffold/i18n/zh/source-pins.json +41 -0
  101. package/scaffold/i18n/zh/specs/decisions/000-spec-structure-format.md +0 -1
  102. package/scaffold/i18n/zh/specs/intents/000-spdx-headers.md +0 -1
  103. package/scaffold/i18n/zh/specs/map.md +0 -1
  104. package/scaffold/i18n/zh/specs/meta.md +18 -35
  105. package/scaffold/i18n/zh/specs/packages/git.md +0 -1
  106. package/scaffold/i18n/zh/specs/packages/licensing.md +0 -1
  107. package/scaffold/specs/meta.md +18 -3
  108. package/scripts/test-exit-guard.mjs +28 -0
package/README.md CHANGED
@@ -12,11 +12,14 @@
12
12
  Scaffolds a `specs/` directory so AI coding agents can read and follow
13
13
  your project's requirements and design. It also manages spec packages:
14
14
  it adds, installs and publishes specs, skills and playbooks in a
15
- folder, with no running app. Requires Node.js 22 or later.
15
+ folder, with no running app. And it checks guards, which protect a
16
+ critical behavior on every change. Requires Node.js 22.15 or later;
17
+ `spex verify` alone also needs Java 11 or later and the TLA+ proof
18
+ system.
16
19
 
17
20
  ## Install
18
21
 
19
- Install Spex CLI 5.0 with Node.js 22 or later:
22
+ Install Spex CLI 5.0 with Node.js 22.15 or later:
20
23
 
21
24
  ```sh
22
25
  npm install -g @sublang/spex
@@ -90,9 +93,8 @@ refreshes the copy. The dry run shows the registry, the version and the
90
93
  files, and publishes nothing. Replace `my-org` with a namespace your
91
94
  registry account can use; check
92
95
  [Your orgs](https://spex.sublang.ai/account/orgs?scope=registry) when using
93
- Spex Space. Your personal namespace may already be available after
94
- sign-in, so creating a Space group or claiming an organization is not a
95
- prerequisite.
96
+ Spex Space. You can publish under your personal namespace when it is
97
+ available after registry sign-in.
96
98
 
97
99
  ## spex.yaml and spex.lock
98
100
 
@@ -151,7 +153,8 @@ file is missing or out of date: `spex.yaml` changed since, or a folder
151
153
  package's `meta.yaml` no longer matches it. `spex update` moves to the
152
154
  newest versions `spex.yaml` allows, on purpose. Downloaded files are
153
155
  checked against the digests in `spex.lock` and kept once in the home's
154
- `store/`, then linked or copied into `.spex/packages/`.
156
+ `store/`, then copied into `.spex/packages/`, as npm copies from its
157
+ cache, so a folder's installed files are its own.
155
158
 
156
159
  Only what a package's `meta.yaml` `provides` is placed: a playbook's
157
160
  source spec, or a skill the playbook requires, is installed but placed
@@ -224,6 +227,16 @@ installed version.
224
227
  [Scaffolding specs](#scaffolding-specs) and [Linting](#linting) describe
225
228
  them in full.
226
229
 
230
+ ### Guards
231
+
232
+ | Command | What it does |
233
+ | --- | --- |
234
+ | `spex verify [--keep <folder>] [<guard>…]` | Check that each guard's protected behavior still holds; `--keep` leaves every file generated for TLC and the proof system, with its command lines, in a folder outside the project |
235
+ | `spex approve <guard>` | Record your approval of a guard's items and files |
236
+
237
+ [Guards](#guards-protect-critical-behavior-on-every-change) describes
238
+ them in full.
239
+
227
240
  ### `spex add`, `remove`, `update` and `list`
228
241
 
229
242
  - `spex add <org>/<pkg>` adds the newest version the registry lists
@@ -313,7 +326,7 @@ them in full.
313
326
  Space, check [Your orgs](https://spex.sublang.ai/account/orgs?scope=registry)
314
327
  in your registry account. A valid, available sign-in name becomes your
315
328
  personal namespace automatically; you can also claim an organization
316
- you own. A Space group grants no publishing namespace.
329
+ you own.
317
330
  - Packages are public by default. **Private packages** restricts a
318
331
  namespace's packages to its personal owner or organization members.
319
332
  - A signed-in dry run and every publication check that the registry
@@ -366,8 +379,7 @@ spex logout --registry https://spex.sublang.ai
366
379
  your registry sign-in. A Space you signed out of stays listed as
367
380
  `signed out`.
368
381
  - Public packages need no sign-in. Private packages and publishing need
369
- a registry sign-in on the computer running the command, a team server
370
- included; a Space sign-in gives none.
382
+ a registry sign-in on the computer running the command.
371
383
  - A `<url>` is just the address, like `https://spex.sublang.ai`: the
372
384
  host, with a port where it is not the default, and no path. `http` is
373
385
  accepted only for a loopback address such as `localhost`.
@@ -378,8 +390,8 @@ spex logout --registry https://spex.sublang.ai
378
390
 
379
391
  ## Exit codes
380
392
 
381
- The package commands exit with these codes. `scaffold` and `lint` keep
382
- their own.
393
+ The package commands exit with these codes. `scaffold`, `lint`,
394
+ `verify` and `approve` keep their own.
383
395
 
384
396
  | Code | Meaning |
385
397
  | --- | --- |
@@ -522,6 +534,399 @@ Review the changes with
522
534
  `git diff -- specs CLAUDE.md AGENTS.md GEMINI.md` and run `spex lint`.
523
535
  The command prints a per-file indicator for every framework and seed path, plus a copy-paste-ready prompt for your AI agent to reconcile citations and local extensions with the refreshed law.
524
536
 
537
+ ## Guards: protect critical behavior on every change
538
+
539
+ A guard protects one behavior you cannot afford to break. A guard is a
540
+ test item that `spex verify` carries out, together with the files under
541
+ `guards/<its ID>/` that say how; other test items are carried out by
542
+ tests you write. Spex has no checking engine of its own for this: the
543
+ judging is done by TLA+ tools people already trust. TLC, the model
544
+ checker, checks a model of the rule at the values the guard declares;
545
+ the TLA+ proof system proves the rule on that model for any values; and
546
+ your code is then tested against the model, through a JavaScript module
547
+ that drives it or through probes that record what it does while your
548
+ own tests run. No agent and no language model takes part in a run and
549
+ nothing is drawn at random, so the same files, code and tool versions
550
+ give the same run wherever your code gives the same records, through
551
+ the module and in your tests, and your tests end the same way, unless a
552
+ tool reaches the time limit. It needs no app and no account.
553
+
554
+ The guard item cites one behavior item, the rule, and lists cases in
555
+ plain words, each marked permitted or forbidden: something the code does
556
+ and the rule allows, or something the code must never do. A permitted
557
+ case may show where the rule stops applying; what the code does there is
558
+ still tested as the case states it.
559
+
560
+ ```markdown
561
+ #### environments-56
562
+
563
+ When `spex verify` checks installs into a project in which several packages provide a spec of one name, it shall find that the code keeps the rule that a standing copy keeps its path [[environments-55](#environments-55)] at every step it tries, reading the rule by these cases:
564
+
565
+ - permitted — a later arrival is blocked: an install selects `zeta/kit` alone and its copy stands, and a second selects `acme/kit` too, both releases providing a `kit` spec; `zeta/kit`'s copy still stands and `acme/kit` alone is reported blocked;
566
+ - forbidden — a later arrival takes the path: the same two installs, ending with `acme/kit`'s copy standing and `zeta/kit` reported blocked;
567
+ - forbidden — the standing package is reported blocked: the same two installs, ending with `zeta/kit`'s copy still standing and both packages reported blocked;
568
+ - forbidden — a package not selected is reported blocked: the same two installs, ending with `zeta/kit`'s copy still standing and `acme/kit` and `mid/kit` reported blocked;
569
+ - permitted — a copy no longer selected leaves: an install selects `zeta/kit` alone and its copy stands, and a second selects `acme/kit` alone, each release providing a `kit` spec; `acme/kit`'s copy stands and no package is reported blocked;
570
+ - permitted — a copy no longer provided leaves: an install selects `zeta/kit` alone and its copy stands, and a second selects `acme/kit` too, when only `acme/kit`'s release still provides a `kit` spec; `acme/kit`'s copy stands and no package is reported blocked.
571
+ ```
572
+
573
+ A guard is named by the ID of its guard item. Its items live in
574
+ `specs/` and its other files beside the code, all committed:
575
+
576
+ | Kept | Where |
577
+ | --- | --- |
578
+ | The rule, a behavior item, and the guard item with its cases | `specs/packages/<pkg>.md` |
579
+ | The guard file: its binding, its time limit and each case again as steps, each an event with its params and an effect | `guards/<guard>/guard.yaml` |
580
+ | The translations: each is the guard's items written in TLA+, one file holding the rule, clause by clause, and the model, which is what the items say each event gives | `guards/<guard>/translations/<name>.tla` |
581
+ | Each translation's proofs, which an agent writes and no person approves | `guards/<guard>/proofs/<name>_proofs.tla` |
582
+ | Each kept fault: a patch to files the binding copies that makes the code do what the rule forbids, which the guard must catch | `guards/<guard>/faults/` |
583
+ | The approval record | `guards/<guard>/approval.json` |
584
+ | A binding: its sets of values, each a mapping of a few declared values with, where the set is ordered, its order; the events it can cause in your code and the effects it can observe; and the JavaScript module that causes them, or the probes that record them, files of your tests in any language, with the command that runs your tests | `guards/bindings/<name>/`; each probe there or among the files the binding copies |
585
+
586
+ Every folder directly under `guards/` other than `bindings` is a guard.
587
+
588
+ ```sh
589
+ spex verify # check every guard under guards/
590
+ spex verify environments-56 # check the guards you name
591
+ spex verify --keep ../kept # also leave every file TLC ran on
592
+ spex approve environments-56 # record your approval
593
+ ```
594
+
595
+ `spex verify` needs Java 11 or later, from `JAVA_HOME` or else the
596
+ `java` on your path; no other command does. It pins one TLC, TLC 2.19,
597
+ the `tla2tools.jar` of TLA+ tools v1.7.4. The first run downloads it
598
+ into the Spex home, `~/.spex` unless `SPEX_HOME` names another, and
599
+ keeps it only if its SHA-256 is the pinned one. Set `SPEX_TLC_JAR` to a
600
+ `tla2tools.jar` to use that file instead, as on a machine that cannot
601
+ reach the download; the report then says whether it is the pinned copy.
602
+ Without Java or the jar a guard is reported as `Cannot be checked`, with
603
+ what to install or set.
604
+
605
+ `spex verify` also needs the TLA+ proof system, TLAPM. Spex does not
606
+ download it: set `SPEX_TLAPM` to a `tlapm` executable, and the report
607
+ names its version and the solvers it runs. Without it the report reads
608
+ `Proofs: not accepted — no proof system: set SPEX_TLAPM to a tlapm executable`,
609
+ the result is `Inconclusive` and the guard does not pass;
610
+ the rest is still checked and your code is still tested.
611
+ Spex pins no release of TLAPM. Its maintainers publish a rolling build,
612
+ [1.6.0-pre](https://github.com/tlaplus/tlapm/releases/tag/1.6.0-pre),
613
+ for Linux on x86-64 (glibc 2.42 or later) and macOS on Apple silicon,
614
+ and the TLA+ community's own checks use it, so that is the one to take.
615
+ A result can change when that build is replaced; it names the version.
616
+
617
+ Both commands read `specs/` and `guards/` at the top level of the Git
618
+ work tree, else in the current folder. `spex verify` writes nothing in
619
+ your project. For each guard it compares the items and files with the
620
+ approval record, and then:
621
+
622
+ Without your code, by TLC:
623
+
624
+ 1. reads each translation alone, and prints every error of form with its
625
+ file and, where it has one, its line and column;
626
+ 2. checks that every translation allows each permitted case and forbids
627
+ each forbidden case;
628
+ 3. checks the translations side by side: at every step any of them
629
+ reaches, they must answer alike on whether the event is legal, what
630
+ it gives, whether the rule applies and which effects the rule
631
+ forbids. A guard needs two translations or more for this: with one
632
+ the run still goes on in full, the report says there is nothing to
633
+ compare the translation with, and the guard does not pass;
634
+ 4. checks the model of the first translation in name order: in every
635
+ state the model reaches, for every legal event, the model's effect is
636
+ one the binding declares and the rule does not forbid it. TLC ends
637
+ only when no state is left, so this check is complete for that model
638
+ and the declared values.
639
+
640
+ For any values, by the proof system:
641
+
642
+ 5. checks each translation's proofs. Spex writes the statements: that
643
+ the translation's model keeps the rule, `KeepsRule`, and, for every
644
+ translation but the first, that it answers as the first does,
645
+ `Agrees`. The proof file proves them as the theorems `RuleProved`
646
+ and `AgreementProved`. It holds only printable ASCII characters,
647
+ definitions of new names and theorems with their proofs, and no
648
+ constant, variable, assumption or axiom of its own, so a proof rests
649
+ only on what the declaration in TLA+ assumes of its sets, such as
650
+ that an order is total. The proofs are accepted only where Spex's own
651
+ reading of each file, TLC's parser and the proof system all agree,
652
+ with every step proved and none left out. Proofs that are not
653
+ accepted do not stop the tests on your code.
654
+
655
+ On a copy of the files the binding names, in a temporary folder, which
656
+ is testing:
657
+
658
+ 6. through the module, where the binding has one, causes each permitted
659
+ case's steps and compares each effect a step states, then causes
660
+ every step of the model once: a fresh start, a shortest sequence to
661
+ its state, then its event;
662
+ 7. through the probes, where it has them, runs your tests with
663
+ `SPEX_RECORDS` naming an empty folder, reads the lines the probes
664
+ wrote there into sequences, finds each whole or not, and finds each
665
+ permitted case at the opening of a sequence;
666
+ 8. has TLC walk every sequence of records, the module's and the
667
+ tests', from the model's start through the model, each no further
668
+ than its first record that is not the model's: an effect the rule
669
+ forbids, another effect, or an event the model does not find legal.
670
+ The records after it are counted as not judged;
671
+ 9. does 6 to 8 again on a copy with each kept fault, which is caught
672
+ only where TLC finds a judged record whose effect the rule forbids.
673
+
674
+ A step is one event with its params and an effect: stated in a case,
675
+ given by the model, judged by the rule, observed on the code. An event
676
+ is legal where the event can happen in this state at all, as a refund
677
+ cannot before a charge. An event that is not legal is not tried on the
678
+ code; it is never a violation. The guard file sets one limit,
679
+ `limits.seconds`, which stops each run of a tool — TLC, TLC's parser or
680
+ the proof system — each of the binding's commands and its test
681
+ command, along with every process they started.
682
+
683
+ A translation is drafted from the items and the binding's declaration
684
+ alone, before its drafter sees your code, and two or more are drafted
685
+ independently. Where translations differ,
686
+ the report prints TLC's shortest sequence to the difference, with the
687
+ one question its last step puts and each translation's answer. That
688
+ sequence is not run on your code: the effects of its earlier steps are
689
+ the model's, on which the translations agree. You answer the one
690
+ question:
691
+
692
+ | Question | Your answer becomes |
693
+ | --- | --- |
694
+ | Is step n legal? | Legal: a permitted case that holds the step. Not legal: no case can show it, so the item is reworded |
695
+ | What must step n give? | You name the effect, and a permitted case states it. Where no item says it, the item is reworded too |
696
+ | Does the rule apply at step n? | It applies: a forbidden case that ends at the step. It does not: no case can show it, so the rule's item is reworded |
697
+ | Is this effect forbidden at step n? | Forbidden: a forbidden case. Permitted, and the model's effect: a permitted case. Permitted, and not the model's effect: no case can show it, so the rule's item is reworded |
698
+
699
+ Where a case can show your answer, the answer becomes a case; where
700
+ none can, the item is reworded to say it. Either way an item has
701
+ changed, and all the translations are then drafted again by fresh
702
+ drafters, from the changed items. No translation is edited to agree. Agreement shows that
703
+ the drafters read the items alike, not that the reading is right; the
704
+ cases and your approval carry that.
705
+
706
+ The following run checked this repository’s approved `environments-56` guard
707
+ with the proof system named by `SPEX_TLAPM`. The revision and tool
708
+ versions identify the run.
709
+
710
+ ```text
711
+ Protect critical behavior on every change
712
+
713
+ environments-56 — checks the rule environments-55:
714
+ While a package's copy stands at `specs/packages/<pkg>.md` [environments-41], with that package
715
+ still selected and its release still providing the spec, when an install runs in a project's
716
+ environment, the package manager shall leave that copy in place as that package's and report
717
+ exactly the other selected packages whose releases provide a `<pkg>` spec as blocked at that path
718
+ (DR-174).
719
+ Approval: approved
720
+ Cases, without the code: each of 3 translations allows the 3 permitted cases and forbids the 3 forbidden cases
721
+ Translations against each other: 3 translations, in agreement at every step TLC reached
722
+ On the model: TLC 2.19 checked every state the model of translation a reaches: 4 states, 256 steps; the rule applied at 48 steps
723
+ TLC's own estimate of the chance it missed a state: 3.6E-15
724
+ Proofs: accepted — the proof system f075721 proved, for any values, that each model keeps the rule and b and c agree with a
725
+ On the code: 256 steps tested, each after a shortest sequence from a fresh start: each gave the model's effect
726
+ the 3 permitted cases went as their steps state
727
+ 454 records in 259 sequences: 454 matched, 0 not judged; the rule applied at 49; they reached 256 of the model's 256 steps
728
+ Result: Model proved, code tested
729
+ assumes: the translations say what the items say: checked by the cases, by their agreement and by a person's approval
730
+ the declaration says what the rule is about, its sets as it states them: checked only by a person's approval
731
+ a proof rests on nothing beyond the declaration's assumptions: checked by Spex's own reading of the proof files
732
+ TLC and the proof system read a file alike: not checked; a translation and a proof file hold only printable ASCII
733
+ the proof system f075721 and its solvers are sound: not checked
734
+ the module reports every event truly and in order: checked in part, by each kept fault
735
+ the tests reach the behavior that matters: not checked; the module tries each step of the model once
736
+ Spex 5.0.0, Node 24.19.0, TLC 2.19 (the pinned copy), the proof system f075721 (SPEX_TLAPM), Java 21.0.12.1
737
+ its solvers: Isabelle (Isabelle2025), zenon (zenon version 0.8.4 [a268] 2017-11-14), Z3 (Z3 version 5.4.1 - 64 bit - build hashcode 145c0c51570a357cc558ce898ce77573ba9d4fbf), LS4 (unknown)
738
+ revision 193b7c1e with changes, copied files sha256 cb6e07a99009
739
+ limits: 300 seconds for each run of a tool and each command
740
+ Kept fault first-by-org: caught at step 2 of the permitted case "a later arrival is blocked"
741
+ 1. install selected={zeta/kit} providing={zeta/kit} -> standing=zeta/kit blocked={}
742
+ 2. install selected={acme/kit, zeta/kit} providing={acme/kit, zeta/kit}
743
+ the model gives standing=zeta/kit blocked={acme/kit}
744
+ the code gave standing=acme/kit blocked={zeta/kit}
745
+ forbidden by the rule
746
+ Passes
747
+
748
+ 1 of 1 guards pass.
749
+ ```
750
+
751
+ Run without `SPEX_TLAPM`, the same guard reads
752
+ `Proofs: not accepted — no proof system: set SPEX_TLAPM to a tlapm executable`,
753
+ its result is `Inconclusive` with that reason under it, the versions
754
+ line names `no proof system` and has no `its solvers:` line under it,
755
+ and the guard's block ends `Does not pass — the result is Inconclusive`.
756
+ The tests on the code and the kept fault go as above.
757
+
758
+ In this repository itself the guard is approved: the owner's approval is
759
+ committed as `guards/environments-56/approval.json`, so the run here
760
+ ends the guard's block `Passes`, counts `1 of 1 guards pass.` and exits
761
+ `0`, or, without a proof system, ends it
762
+ `Does not pass — the result is Inconclusive` and exits `1`. A guard
763
+ with no approval record reads
764
+ `Approval: not approved — no approval record` instead, ends its block
765
+ `Does not pass — not approved`, or
766
+ `Does not pass — not approved; the result is Inconclusive` without a
767
+ proof system, counts `0 of 1 guards pass.` and exits `1`. The checks and
768
+ the result between those lines are as above.
769
+
770
+ A guard gets one result, the highest row found:
771
+
772
+ | Result | What it establishes |
773
+ | --- | --- |
774
+ | `Conflict in the items` | TLC found a sequence after which the items, as translated, require an effect the rule forbids. |
775
+ | `Violated on the code` | The code did what the rule forbids. The sequence that shows it is printed. |
776
+ | `Code differs from the model` | The code gave an effect the model does not give and the rule does not forbid. The rule was not seen broken, and the check cannot go on from there. |
777
+ | `Case failed` | A permitted case did not go on the code as its steps state. |
778
+ | `Inconclusive` | The check could not settle, as when time ran out, a case did not hold without your code, the translations differ, the rule applied at no step, a sequence did not repeat or was not whole, a permitted case was not seen, your tests failed, the binding failed, the translations judge a recorded sequence differently, or the proofs were not accepted. |
779
+ | `Model proved, code tested` | TLC checked every state the model reaches, complete for the declared values, and the model never gives an effect the rule forbids. The proofs were accepted, so the proof system proved, for any values, that each translation's model keeps the rule and that every other translation agrees with the first. On the code, every step of the model was caused once through the module, or every sequence your tests recorded was whole, every record was the model's, and every permitted case went as its steps state. |
780
+
781
+ Spex gives no one-word verdict on your code. `Model proved, code
782
+ tested` is two things. The model is proved: TLC checks it at the
783
+ declared values, and the proof system proves the rule on it for any
784
+ values. The code is tested: through the module every step of the model
785
+ is caused on your code once, nothing drawn at random; through the
786
+ probes your own tests choose what runs, and the report says how many of
787
+ the model's steps they reached. Spex does not explore your code's own
788
+ states, and your code can still break the rule in a run no test made.
789
+ The result rests on the `assumes` lines the report prints under it:
790
+
791
+ - the translations say what the items say, which the cases, the
792
+ agreement of the translations and your approval check;
793
+ - the declaration says what the rule is about, with its sets as it
794
+ states them, which only your approval checks;
795
+ - a proof rests on nothing beyond the declaration's assumptions, which
796
+ Spex's own reading of the proof files checks;
797
+ - TLC and the proof system read a file alike, which is not checked;
798
+ translations and proof files hold only printable ASCII, where the two
799
+ are known to differ otherwise;
800
+ - the proof system and its solvers are sound, which is not checked: the
801
+ report names each with its version;
802
+ - where the binding has probes and a `values` set with an order, values
803
+ outside the declared ones are given to TLC in the declared order, by
804
+ Spex's own sort: TLC checks only that no value stands twice;
805
+ - the module reports every event truly and in order, which each kept
806
+ fault checks in part; for probes, the probes do, which each kept fault
807
+ and each sequence being whole check in part;
808
+ - the tests reach the behavior that matters, which is not checked: the
809
+ module tries each step of the model once, so code that keeps something
810
+ the model does not could behave differently after a longer sequence;
811
+ for probes alone, the result says how much of the model the records
812
+ reached.
813
+
814
+ The translation says what the items mean; the cases you approved are
815
+ what tie it to the items' words. Where the same sequence gives another
816
+ effect when caused a second time through the module, the report says
817
+ so under the result, which is `Inconclusive` unless TLC found a record
818
+ that is not the model's.
819
+
820
+ Spex sees a project file loaded from outside the copy only in the main
821
+ thread of the check's process, not in worker threads, in processes
822
+ your code starts or in your tests. Where the binding fails, the cause names a file of the
823
+ copy by its path in the copy, so two runs print the same report.
824
+
825
+ A guard passes only when all of these hold:
826
+
827
+ - its approval is current;
828
+ - every translation allows each permitted case and forbids each
829
+ forbidden case;
830
+ - it has two translations or more, and they agree;
831
+ - the result is `Model proved, code tested`;
832
+ - it has at least one kept fault, and every one is caught.
833
+
834
+ A guard with an error in its files, with no translation, or whose
835
+ guard item lacks a permitted or a forbidden case, is reported as
836
+ `Cannot be checked` and does not pass. `spex verify` exits `0` when
837
+ every guard it checked passes, `1` otherwise, and `130` when
838
+ interrupted, after it stops its processes and removes its temporary
839
+ folders.
840
+
841
+ `spex verify --keep <folder>` leaves, for each guard, the declaration
842
+ in TLA+ that Spex generates from the binding, the translations, the
843
+ TLA+ file and configuration of each run of TLC, TLC's output, the files
844
+ and output of each run of TLC's parser and the proof system on a proof
845
+ file, the exact command line of each run, and, where the binding has
846
+ probes, each file of lines your tests wrote, byte for byte, with
847
+ `sequences.txt`, which lists each sequence and whether it is whole.
848
+ TLC judges the records in runs of `records`, `records~2` and on, from a
849
+ generated `SpexRecords.tla` that holds each record as a TLA+ value, and
850
+ in `records@b` and on where another translation, `b`, judges them too.
851
+ Anyone can then run each step again
852
+ with the standard TLA+ tools, without Spex. The folder must lie outside
853
+ your project, whether or not Git ignores a folder inside it: a guard
854
+ copies the folders its binding names as they stand, and would test
855
+ kept output as code. If an earlier version left kept output in an
856
+ ignored folder of your project, move or remove it once. For a guard that has no translation
857
+ yet, the run needs no Java and leaves `spex-verify.txt` and the
858
+ declaration in TLA+, `Declaration.tla`, in `<folder>/<guard>/`, for the
859
+ drafters to write over.
860
+
861
+ `spex approve <guard>` prints the guard item's statement, the rule,
862
+ then each case with its steps, then the name of every other file and
863
+ item it records, and what changed since the last record. It then writes
864
+ `approval.json`, or leaves the file as it is where nothing changed. It
865
+ needs no Java. Commit the record, so an approval shows as a change in
866
+ review. After a change to an item, the
867
+ guard file, a translation, a kept fault or the binding, `spex verify`
868
+ names what changed and the guard cannot pass until you approve it again.
869
+ Changes to your code need no approval, nor do changes to your tests; a
870
+ change to a probe does.
871
+
872
+ Draft a guard with the `guard` skill
873
+ (`npx skills add sublang-ai/spex --skill guard`), then ask your agent to
874
+ guard a behavior; an agent also writes the proofs. Where a proof is not
875
+ accepted, declare more values so that TLC searches further, or have the
876
+ proof completed; no statement, assumption or translation is changed to
877
+ make a proof pass.
878
+
879
+ A binding's module is JavaScript, so it reaches only code such a module
880
+ can drive. For other code, and for behavior only your tests reach, a
881
+ binding has probes in place of the module: small files of your tests,
882
+ in your code's own language, that write one JSON line for each event
883
+ the code completes, and nothing where `SPEX_RECORDS` is not set. Every
884
+ file whose code writes a line or works out what one holds is a probe,
885
+ so a helper your tests call to cause an event and record it is one, and
886
+ no kept fault may change a probe. The binding's declaration names them
887
+ and the command that runs your tests:
888
+
889
+ ```yaml
890
+ files: [src, test]
891
+ probes: [test/lock-probe.mjs, test/probed.mjs]
892
+ tests: [node, --test, 'test/*.test.mjs']
893
+ ```
894
+
895
+ A probe writes a start where a test makes the code fresh, a record for
896
+ each event with its params and the effect the code gave, and an end in
897
+ the test's tear-down, each line with its sequence and its place:
898
+
899
+ ```json
900
+ {"spex":"start","seq":"7","n":0,"test":"a second taker waits"}
901
+ {"spex":"record","seq":"7","n":1,"event":"take","params":{"who":"ann"},"effect":{"granted":true,"holder":"ann","waiting":[]}}
902
+ {"spex":"end","seq":"7","n":2}
903
+ ```
904
+
905
+ Each process writes a file of its own, `<pid>.jsonl`, in that folder.
906
+ A permitted case is seen in a sequence of your tests that opens with
907
+ the case's steps. The report then counts what TLC found of the records,
908
+ as in
909
+
910
+ ```text
911
+ On the code: the project's tests ran with the probes on: 3 sequences of records, each whole
912
+ the 2 permitted cases each opened a sequence and went as their steps state
913
+ 9 records in 3 sequences: 9 matched, 0 not judged; the rule applied at 3; they reached 8 of the model's 40 steps
914
+ ```
915
+
916
+ and names a violation or a difference at a record of a named sequence.
917
+ Where the translations judge a recorded sequence differently, the
918
+ report prints that sequence to the record at which they part, with
919
+ each translation's answer there, and marks the line of counts, and
920
+ that of the steps tested, `as translation <t> judges them`: the first
921
+ translation's alone.
922
+ A sequence that is not whole, a line the probe wrote that does not match
923
+ the declaration, a permitted case no sequence opens with, and tests that
924
+ end with another status than `0` each leave the result `Inconclusive`
925
+ unless a higher one was found, with the cause under it. The tests' records are what was tested: the
926
+ result says nothing of a run your tests did not make. The `guard`
927
+ skill's `references/formats.md` gives a probe in ten lines in
928
+ JavaScript and in Python.
929
+
525
930
  ## Upgrading from an earlier release
526
931
 
527
932
  ### From a pre-release source build
@@ -635,8 +1040,10 @@ Then loop back to the next decision or intent.
635
1040
 
636
1041
  ## Requirements
637
1042
 
638
- - Node.js >= 22
1043
+ - Node.js 22.15 or later
639
1044
  - Git (optional, used for repo root detection)
1045
+ - Java 11 or later, for `spex verify` only, which runs TLC; the first run downloads the TLC it pins
1046
+ - The TLA+ proof system, for `spex verify` only: a `tlapm` executable named by `SPEX_TLAPM`, which Spex does not download; without it a guard's result is `Inconclusive`
640
1047
 
641
1048
  ## Contributing
642
1049
 
package/dist/cli.js CHANGED
@@ -24,6 +24,12 @@ const COMMANDS = {
24
24
  };
25
25
  /** The commands keeping their own contracts and exits. */
26
26
  const OWN = { scaffold, lint };
27
+ /** The guard commands (guards-27), which also keep their own exits.
28
+ * Their code loads only when one of them runs. */
29
+ const GUARDS = {
30
+ verify: async (args) => (await import("./guards/commands.js")).verify(args),
31
+ approve: async (args) => (await import("./guards/commands.js")).approve(args),
32
+ };
27
33
  /** Print what was asked on standard output and exit 0 (cli-21). */
28
34
  function say(text) {
29
35
  process.stdout.write(`${text}\n`);
@@ -73,7 +79,8 @@ async function main() {
73
79
  const help = commandHelp(asked);
74
80
  return help === undefined ? unknown(asked) : say(help);
75
81
  }
76
- const named = Object.hasOwn(COMMANDS, command) || Object.hasOwn(OWN, command) ? commandNamed(command) : undefined;
82
+ const known = Object.hasOwn(COMMANDS, command) || Object.hasOwn(OWN, command) || Object.hasOwn(GUARDS, command);
83
+ const named = known ? commandNamed(command) : undefined;
77
84
  if (named === undefined)
78
85
  return unknown(command);
79
86
  if (asksHelp(args.slice(1)))
@@ -89,6 +96,10 @@ async function main() {
89
96
  process.exitCode = code;
90
97
  return;
91
98
  }
99
+ if (Object.hasOwn(GUARDS, command)) {
100
+ process.exitCode = await GUARDS[command](args.slice(1));
101
+ return;
102
+ }
92
103
  OWN[command](args.slice(1));
93
104
  }
94
105
  void main();
@@ -2,7 +2,7 @@ import { type Request } from "../lib/environment/index.js";
2
2
  import { Environment } from "./environment.js";
3
3
  import { type Command } from "./run.js";
4
4
  /** Write one package into the environment's `spex.yaml`
5
- * (environments-15): a file made new explicitly names the public
5
+ * (environments-65): a file made new explicitly names the public
6
6
  * registry (environments-2); comments and key order stay; a file changed
7
7
  * meanwhile is refused. */
8
8
  export declare function writeRequest(env: Environment, name: string, request: Request, made: boolean): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
3
  // `spex add <org>/<pkg>[@<version>]` and `spex add <org>/<pkg> --path
4
- // <folder>` (cli-2, environments-15): write the package into
4
+ // <folder>` (cli-2, environments-65): write the package into
5
5
  // `spex.yaml` — made explicitly naming the public registry where the
6
6
  // root holds none — then resolve, install and export, printing each
7
7
  // package added or updated, where its spec stands in `specs/` with the
@@ -24,7 +24,7 @@ function editRefusal(env, error) {
24
24
  return null;
25
25
  }
26
26
  /** Write one package into the environment's `spex.yaml`
27
- * (environments-15): a file made new explicitly names the public
27
+ * (environments-65): a file made new explicitly names the public
28
28
  * registry (environments-2); comments and key order stay; a file changed
29
29
  * meanwhile is refused. */
30
30
  export async function writeRequest(env, name, request, made) {
@@ -8,8 +8,8 @@ import { Refusal } from "./run.js";
8
8
  * name made long, and the rest as written. */
9
9
  export declare function actualPath(path: string): string;
10
10
  /** Why a folder cannot be an environment's root (cli-1), or null: the
11
- * user's home folder, a folder inside the Spex home other than a seat's
12
- * project below `projects/`, and a folder whose `.spex` holds the home. */
11
+ * user's home folder, a folder inside the Spex home, and a folder whose
12
+ * `.spex` holds the home. */
13
13
  export declare function refusedRoot(dir: string, home: string): string | null;
14
14
  /** The environment root of a command run in `cwd` (cli-1), spelled as
15
15
  * `cwd` is, so a path given from `cwd` compares with it as text. A
@@ -100,7 +100,7 @@ export declare class Environment {
100
100
  * only its registry slot and never the Space's home entry. */
101
101
  private clientAt;
102
102
  /** The built-in spec package as this device's seed holds it
103
- * (environments-7, environments-11): what the app seeded into the
103
+ * (environments-7): what the app seeded into the
104
104
  * shared store, read from `cache/builtins/`; the command line ships
105
105
  * none of its own. */
106
106
  seed(): RegistrySource;
@@ -9,9 +9,7 @@
9
9
  // no folder check; the store and the cache are the ones the app's core
10
10
  // uses under it, so both hosts share one store (environments-7). No
11
11
  // clone, lease, session or record of the home is read or written: a
12
- // root inside the home, other than a seat's project under `projects/`,
13
- // is refused, as is the user's home folder, whose agent folders are the
14
- // user-level ones your own group's export writes (environments-8).
12
+ // root inside the Spex home is refused, as is the user's home folder.
15
13
  import { spawnSync } from "node:child_process";
16
14
  import { realpathSync, statSync } from "node:fs";
17
15
  import { homedir } from "node:os";
@@ -45,14 +43,14 @@ function within(outer, inner) {
45
43
  return path === "" || (path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path));
46
44
  }
47
45
  /** Why a folder cannot be an environment's root (cli-1), or null: the
48
- * user's home folder, a folder inside the Spex home other than a seat's
49
- * project below `projects/`, and a folder whose `.spex` holds the home. */
46
+ * user's home folder, a folder inside the Spex home, and a folder whose
47
+ * `.spex` holds the home. */
50
48
  export function refusedRoot(dir, home) {
51
49
  const at = actualPath(dir);
52
50
  const spexHome = actualPath(home);
53
51
  if (at === actualPath(homedir()))
54
52
  return "is your home folder, where spex manages no packages";
55
- if (within(spexHome, at) && !(within(join(spexHome, "projects"), at) && at !== join(spexHome, "projects"))) {
53
+ if (within(spexHome, at)) {
56
54
  return `lies in the Spex home ${home}, which the app keeps`;
57
55
  }
58
56
  if (within(join(at, ".spex"), spexHome))
@@ -347,7 +345,7 @@ export class Environment {
347
345
  return client;
348
346
  }
349
347
  /** The built-in spec package as this device's seed holds it
350
- * (environments-7, environments-11): what the app seeded into the
348
+ * (environments-7): what the app seeded into the
351
349
  * shared store, read from `cache/builtins/`; the command line ships
352
350
  * none of its own. */
353
351
  seed() {
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
- // `spex export <org>/<pkg>` (cli-23, environments-10, environments-42,
3
+ // `spex export <org>/<pkg>` (cli-23, environments-59, environments-42,
4
4
  // DR-174): a spec package under development built at
5
5
  // `spex-packages/<org>/<pkg>/` under the environment's root, in the
6
6
  // release layout the library reads, by copying the project's own files,
@@ -439,7 +439,7 @@ export const exportPackage = async (args) => {
439
439
  const root = env.root;
440
440
  const registry = env.registryOf(env.readRequests()?.requests ?? null);
441
441
  // The org is a folder, as npm's scopes are, so two orgs' packages of
442
- // one name stand apart (environments-10, DR-165).
442
+ // one name stand apart (environments-59, DR-165).
443
443
  const packages = join(root, "spex-packages");
444
444
  const parent = join(packages, org);
445
445
  const destination = join(parent, name);
@@ -33,9 +33,9 @@ export declare function hostOf(origin: string): string;
33
33
  export declare function nameOf(instance: HomeInstance): string;
34
34
  /** The credential store of one instance under the home (storage-19). */
35
35
  export declare function credentialsOf(dir: string, origin: string, scope?: AuthScope): CredentialStore;
36
- /** The client of one instance, signing in as this device (git-host-3). */
36
+ /** The client of one instance, signing in as this device (git-host-40). */
37
37
  export declare function clientOf(origin: string, credentials: CredentialStore, onSignedOut?: () => void, scope?: AuthScope): GitHostClient;
38
- /** A host's answer in the CLI's words (git-host-11, cli-13): what the
38
+ /** A host's answer in the CLI's words (cli-13): what the
39
39
  * Space or registry said, its own words as the detail, and what to do —
40
40
  * `again`, the command that tries once more — never a secret. An answer
41
41
  * of no known kind, such as a page that is not there, comes from an