agent-formal-verify 0.4.12 → 0.4.13

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 (38) hide show
  1. package/CHANGES.md +136 -0
  2. package/README.md +5 -3
  3. package/package.json +2 -1
  4. package/skills/formal-verify/SKILL.md +11 -13
  5. package/skills/formal-verify/examples/kani-template/src/lib.rs +5 -6
  6. package/skills/formal-verify/examples/lean-template/Model/BoundedQueue.statements +10 -45
  7. package/skills/formal-verify/examples/tla-template/BoundedQueue.matrix +16 -13
  8. package/skills/formal-verify/examples/tla-template/BoundedQueue.mutations +92 -14
  9. package/skills/formal-verify/examples/tla-template/BoundedQueue.tla +169 -28
  10. package/skills/formal-verify/references/evidence.md +1 -1
  11. package/skills/formal-verify/references/helpers.md +4 -3
  12. package/skills/formal-verify/references/lean-brief.md +2 -2
  13. package/skills/formal-verify/references/rust-brief.md +58 -6
  14. package/skills/formal-verify/references/setup.md +23 -7
  15. package/skills/formal-verify/references/tla-brief.md +2 -2
  16. package/skills/formal-verify/scripts/baseline.py +564 -66
  17. package/skills/formal-verify/scripts/kani-check.sh +3 -1
  18. package/skills/formal-verify/scripts/kani.py +127 -59
  19. package/skills/formal-verify/scripts/lean-analysis.lean +387 -0
  20. package/skills/formal-verify/scripts/lean-check.sh +6 -243
  21. package/skills/formal-verify/scripts/lean.py +484 -0
  22. package/skills/formal-verify/scripts/lean_mutations.py +195 -0
  23. package/skills/formal-verify/scripts/lean_records.py +25 -0
  24. package/skills/formal-verify/scripts/mutate.py +81 -195
  25. package/skills/formal-verify/scripts/processes.py +266 -0
  26. package/skills/formal-verify/scripts/python-tools.sh +15 -0
  27. package/skills/formal-verify/scripts/runner.py +56 -0
  28. package/skills/formal-verify/scripts/setup.sh +18 -19
  29. package/skills/formal-verify/scripts/storage.py +207 -0
  30. package/skills/formal-verify/scripts/sync.py +401 -0
  31. package/skills/formal-verify/scripts/tlc-matrix.sh +3 -1
  32. package/skills/formal-verify/scripts/tlc.py +423 -116
  33. package/skills/formal-verify/scripts/{tlc-trace.py → tlc_trace.py} +16 -10
  34. package/skills/setup/SKILL.md +1 -1
  35. package/skills/formal-verify/scripts/lean-mutations.lean +0 -95
  36. package/skills/formal-verify/scripts/lean-statements.py +0 -161
  37. package/skills/formal-verify/scripts/lean-tools.sh +0 -24
  38. package/skills/formal-verify/scripts/tlc-tools.sh +0 -47
@@ -10,9 +10,21 @@ The helpers are in the `scripts/` directory of the installed `formal-verify` ski
10
10
 
11
11
  Stay in the target repository and run each helper with `bash` and its absolute path. Pass absolute paths to model projects and matrices. Keep the installed skill files read-only, and create models and build outputs in the target repository. Shared tool caches can serve several repositories; each repository determines its own tool requirements and Lean pins.
12
12
 
13
+ Every runner writes its temporary state into `TMPDIR` (failing cleanly with `FAIL` if an explicitly set `TMPDIR` cannot be created or written) and removes its working directories between matrix runs and on `SIGINT`, `SIGTERM` or `SIGHUP`. `setup.sh tla`, `setup.sh rust` and `setup.sh lean` stop their readiness check on these signals too, including one sent to the `setup.sh` process alone, and end by the signal. Lean builds write into the model project's `.lake` directory, while `lean-check.sh` places its module lists for the audit and the kernel replay in `TMPDIR`. `setup.sh` (`tla`, `rust`, `lean`, and `storage`) reports `TEMP_DIR` free space, and `SYSTEM_DISK` free space when the temporary directory is on another device. It warns when the active temporary volume, or the system disk while it holds the temporary directory, has less than `FORMAL_MIN_FREE_GIB` free (default `64` GiB). It also lists larger writable `EXTERNAL_VOLUME` mounts so heavy runs can redirect `TMPDIR` onto an external disk. `bash <skill-dir>/scripts/setup.sh storage` runs this storage check alone. Checkers also warn once on `stderr` before starting when active temporary space drops below `10` GiB (or `FORMAL_MIN_FREE_GIB` when set).
14
+
15
+ To stop a checker, a runner suspends the checker and every process it started, then sends them `SIGTERM` and resumes them, so none can start another process meanwhile. This takes a few `ps` calls, a few tens of milliseconds on an idle machine and longer under load. A runner ended in that time by a signal it does not handle, such as `SIGKILL` or `SIGQUIT`, cannot resume them. The checker and the processes suspended so far then stay suspended until something ends them, and the processes it started that were not yet suspended keep running. `SIGINT`, `SIGTERM` and `SIGHUP` do not cause this, because the runner holds them back until the stop finishes and then ends by the signal.
16
+
17
+ The left-behind processes share the process group of the runner that ended. To find them, list the suspended processes, whose state starts with `T`, with their process group:
18
+
19
+ ```shell
20
+ ps -A -o stat,pid,ppid,pgid,command | grep '^T'
21
+ ```
22
+
23
+ A left-behind checker has lost its runner, so its parent is process 1 or a service manager such as `systemd --user`, and it runs a command such as TLC's `java`, `cargo-kani`, `cbmc`, `cargo`, `elan`, `lake` or `lean`. A job that you suspended yourself, such as an editor stopped with Ctrl-Z, has your shell as its parent; leave it alone. To list every process in a left-behind checker's group, including those still running, run `ps -A -o stat,pid,ppid,pgid,command` and keep the rows whose group matches the checker's. End each one with `kill -KILL <pid>`, or with `kill -TERM <pid>` followed by `kill -CONT <pid>` to let it clean up first. Do not signal the whole group, which can also hold the shell or job that started the runner.
24
+
13
25
  ## TLA+ and TLC
14
26
 
15
- The setup helper needs a JDK, Python 3, and `sha256sum` or `shasum` to verify the TLC JAR. If `java` on PATH has no runtime, as with the macOS stub, set `JAVA` to a working JDK's `java` binary. Copy the [TLA+ template](../examples/tla-template/BoundedQueue.tla) with its `BoundedQueue.matrix` and `BoundedQueue.mutations` into the project to start a spec.
27
+ The setup helper needs a JDK and Python 3.9 or later as `python3`. If `java` on PATH has no runtime, as with the macOS stub, set `JAVA` to a working JDK's `java` binary. Copy the [TLA+ template](../examples/tla-template/BoundedQueue.tla) with its `BoundedQueue.matrix` and `BoundedQueue.mutations` into the project to start a spec.
16
28
 
17
29
  ```shell
18
30
  bash <skill-dir>/scripts/setup.sh tla
@@ -20,9 +32,9 @@ bash <skill-dir>/scripts/tlc-matrix.sh /path/to/models/Name.matrix
20
32
  python3 <skill-dir>/scripts/mutate.py /path/to/models/Name.mutations
21
33
  ```
22
34
 
23
- The plugin does not download TLC. Save `tla2tools.jar` from the [TLA+ release](https://github.com/tlaplus/tlaplus/releases/tag/v1.7.4) pinned in `scripts/tlc-tools.sh` as `~/.cache/tla/tla2tools-v1.7.4.jar`; the setup helper verifies its pinned SHA256 and names that path and release when the file is missing or does not match. Set `TLC_CACHE` to choose another cache directory. Set `TLC_JAR` to use an existing JAR; an explicitly supplied JAR is trusted and must already exist.
35
+ The plugin does not download TLC. Save `tla2tools.jar` from the [TLA+ release](https://github.com/tlaplus/tlaplus/releases/tag/v1.7.4) pinned in `scripts/tlc.py` as `~/.cache/tla/tla2tools-v1.7.4.jar`; the setup helper verifies its pinned SHA256 and names that path and release when the file is missing or does not match. Set `TLC_CACHE` to choose another cache directory. Set `TLC_JAR` to use an existing JAR; an explicitly supplied JAR is trusted and must already exist.
24
36
 
25
- The matrix runner requires the JAR and a working Java runtime. It checks Python 3 before running, so a failing model can always print its reduced trace. It does not download tools. Each run checks the formula its spec names `Spec` and sees only the modules beside that spec. `TLC_WORKERS` controls the TLC worker count.
37
+ The matrix runner requires the JAR and a working Java runtime. It checks for Python 3.9 or later before running, so a failing model can always print its reduced trace. It does not download tools. Each run checks the formula its spec names `Spec` and sees only the modules beside that spec. `TLC_WORKERS` controls the TLC worker count. Each run stops after sixty minutes by default; set `TLC_TIMEOUT` to change the limit using a whole number from 1 to 4294967295 with an optional unit `s`, `m` or `h`, such as `90s` or `1h`. For any other value, `setup.sh tla`, the matrix runner and the mutation runner print `UNAVAILABLE` and exit 3 without running TLC. A run that reaches the limit fails with a message naming the limit and `TLC_TIMEOUT`, and a mutation run that reaches it reaches no verdict. During long runs, the runner forwards periodic elapsed-time and `Progress(...)` updates from `tlc.log` to `stderr`. Each run gives the JVM its own `java.io.tmpdir` inside the run directory, so TLC runs started at the same time do not delete each other's copy of the standard modules. A `-Djava.io.tmpdir` in `_JAVA_OPTIONS` overrides it, because the JVM reads that variable after the command line; set the temporary directory with `TMPDIR` instead.
26
38
 
27
39
  The mutation runner reads `Name.mutations` beside `Name.tla` and `Name.matrix`. For each mutation it copies the spec, replaces the listed text, and runs the matrix runner with the one property the mutation names, so it needs the same tools and settings.
28
40
 
@@ -58,19 +70,19 @@ bash <skill-dir>/scripts/lean-check.sh /path/to/lean-project Model/Name.lean
58
70
  python3 <skill-dir>/scripts/mutate.py /path/to/lean-project/Model/Name.mutations
59
71
  ```
60
72
 
61
- The setup helper checks the version in the project's current `lean-toolchain` and installs it only when it is not ready; it leaves the global default unchanged. The Lean checker uses `elan run` without its install flag, so a missing toolchain is UNAVAILABLE instead of downloading inside the checker. Lake builds may fetch dependencies declared by the model project. The supplied template has no external Lean packages.
73
+ The setup helper and the Lean checker need Python 3.9 or later as `python3`. The Lean pin lookup and readiness check live in [`scripts/lean.py`](../scripts/lean.py), with the checker's steps. The setup helper runs `lean.py ready`, which checks the version in the project's current `lean-toolchain` and installs it only when it is not ready; it leaves the global default unchanged. `elan run` installs a toolchain that is not installed, even without its install flag, so the Lean checker and the mutation runner first look for the pin in `elan toolchain list` and report a missing toolchain as UNAVAILABLE instead of downloading it. A `lean-toolchain` names a release, such as `leanprover/lean4:v4.35.0`, a toolchain that `elan toolchain link` added, or an absolute path to a toolchain directory. A channel, `stable`, `beta` or `nightly`, or a repository's `lean-toolchain` release name, fails, because elan resolves it to a release online. Lake builds may fetch dependencies declared by the model project. The supplied template has no external Lean packages.
62
74
 
63
- The Lean checker builds every `.lean` file in the project by its path, so a file that no Lake library owns fails the build instead of going unchecked. It then compiles a short audit against the modules Lake reports for those files. The checker needs a pin of Lean 4.20.0 or later, the first whose Lake builds a module by its source path, and says so when an older pin fails. The audit lists every declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, so a model needs no `#print axioms` lines. The audit imports the project's modules together, so each model declares its names in a namespace of its own. A file name after the project limits the build and the audit to that file.
75
+ The Lean checker builds every `.lean` file in the project by its path, so a file that no Lake library owns fails the build instead of going unchecked. It then runs the audit in [`scripts/lean-analysis.lean`](../scripts/lean-analysis.lean) against the modules Lake reports for those files. The checker needs a pin of Lean 4.20.0 or later, the first whose Lake builds a module by its source path, and says so when an older pin fails. The audit lists every declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, so a model needs no `#print axioms` lines. The audit imports the project's modules together, so each model declares its names in a namespace of its own. A file name after the project limits the build and the audit to that file.
64
76
 
65
77
  The mutation runner reads `Name.mutations` beside `Name.lean`. It elaborates each mutated copy with the project's toolchain and built modules, outside the project, and does not install a toolchain.
66
78
 
67
- Helpers print `UNAVAILABLE` and exit 3 when a required tool is missing, unusable or unverified. Report the target as "not checked" and give the printed remedy. A model or input error prints `FAIL` and exits 1; a usage error exits 2. An unavailable run prints no PASS or SUMMARY line.
79
+ Helpers print `UNAVAILABLE` and exit 3 when a required tool is missing, unusable or unverified. Report the target as "not checked" and give the printed remedy. A model or input error prints `FAIL` and exits 1; a usage error exits 2. An unavailable run prints no PASS or SUMMARY line. One line reuses the token for an optional part of a check that passed: `lean-check.sh` prints `UNAVAILABLE kernel replay` when the pin ships no `leanchecker`, then its `PASS` line, and exits 0.
68
80
 
69
81
  ## CI
70
82
 
71
83
  The helpers live in this plugin, not in the target repository. In CI, check out `michael-denyer/agent-formal-verify` at a pinned commit into a separate directory and run the helpers from its `skills/formal-verify/scripts/`. Update that pin deliberately, as for any other tool. A repository that vendors the scripts instead must keep their GPL-3.0-only license headers.
72
84
 
73
- Install the chosen runtime and the pinned TLC JAR in the CI environment, run the setup helper, then run the matrix runner, Lean checker or mutation runner as a separate step. Cache elan's toolchain directory if useful, and keep the version pins with the models. Use the same `TLC_JAR` and `JAVA` settings in setup and verification.
85
+ Install the chosen runtime and the pinned TLC JAR, and for Rust the pinned Kani, in the CI environment, run the setup helper, then run the matrix runner, Lean checker, Rust checker or mutation runner as a separate step. Cache elan's toolchain directory if useful, and keep the version pins with the models. Use the same `TLC_JAR` and `JAVA` settings in setup and verification.
74
86
 
75
87
  ```yaml
76
88
  - uses: actions/checkout@<commit>
@@ -84,4 +96,8 @@ Install the chosen runtime and the pinned TLC JAR in the CI environment, run the
84
96
  - run: bash .formal-verify/skills/formal-verify/scripts/setup.sh lean "$GITHUB_WORKSPACE/lean"
85
97
  - run: bash .formal-verify/skills/formal-verify/scripts/lean-check.sh "$GITHUB_WORKSPACE/lean"
86
98
  - run: python3 .formal-verify/skills/formal-verify/scripts/mutate.py "$GITHUB_WORKSPACE/lean/Model/Name.mutations"
99
+ - run: cargo install --locked kani-verifier --version 0.68.0 && cargo kani setup
100
+ - run: bash .formal-verify/skills/formal-verify/scripts/setup.sh rust
101
+ - run: bash .formal-verify/skills/formal-verify/scripts/kani-check.sh "$GITHUB_WORKSPACE/verify"
102
+ - run: python3 .formal-verify/skills/formal-verify/scripts/mutate.py "$GITHUB_WORKSPACE/verify/src/lib.mutations"
87
103
  ```
@@ -51,9 +51,9 @@ python3 <skill-dir>/scripts/mutate.py <absolute-path>/tla/<Name>.mutations
51
51
 
52
52
  The matrix runner prints PASS or FAIL per run and a SUMMARY line. A failing run prints its error trace, reduced to the variables each step changed.
53
53
 
54
- Each reach check prints its own PASS with the shortest witness length in states and transitions, or FAIL when the model never reaches the state. Reach searches use one worker and ignore deadlock so they can finish exploring a stopped model. The SUMMARY counts reach checks separately; its state total covers ordinary runs only. Use `detects reach:<Operator>` for a mutation that removes a required state. Reach checks do not count as properties for mutation coverage.
54
+ Each reach check prints its own PASS with the shortest witness length in states and transitions, or FAIL when the model never reaches the state. Witness searches use one worker and ignore deadlock so they can finish exploring a stopped model; `reach:` mutations run with `TLC_WORKERS` because confirming `UNREACHED` explores the full state graph without a witness trace. Attach each `reach` check—especially those paired with `detects reach:<Operator>`—to the smallest boundary `run` that exercises the predicate rather than large fault-injection configurations. The SUMMARY counts reach checks separately; its state total covers ordinary runs only. Use `detects reach:<Operator>` for a mutation that removes a required state. Reach checks do not count as properties for mutation coverage.
55
55
 
56
- Before reporting a pass, list mutations that represent plausible code bugs in the mutations file. Try replacing `while` with `if`, removing a broadcast, replacing FIFO order with stack order, leaving a flag set, or taking an item without removing it. Each mutation names the one property that must fail on it. For each fix commit in your row, add a mutation that restores the behaviour the code had before the fix, with the commit's short hash in its label. The mutation runner applies each to a copy of the spec, using only matrix runs where its named check is in scope. Temporal mutations disable TLC's separate deadlock check so that the temporal property itself must fail; a deadlock alone earns no detection. Revise a property it reports as UNCOVERED, and the property or the mutation behind each MISSED line.
56
+ Before reporting a pass, list mutations that represent plausible code bugs in the mutations file. Try replacing `while` with `if`, removing a broadcast, replacing FIFO order with stack order, leaving a flag set, or taking an item without removing it. Each mutation names the one property that must fail on it. For each fix commit in your row, add a mutation that restores the behaviour the code had before the fix, with the commit's short hash in its label. The mutation runner applies each to a copy of the spec, using only matrix runs where its named check is in scope. The same detector must pass on the original spec at those settings before a mutant can earn credit. Temporal mutations disable TLC's separate deadlock check so that the temporal property itself must fail; a deadlock alone earns no detection. Revise a property it reports as UNCOVERED, and the property or the mutation behind each MISSED line.
57
57
 
58
58
  ## Report
59
59