@codacy/verity-cli 0.33.3-experimental.52f1656 → 0.33.3-experimental.80b064d

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.
@@ -1,174 +1,135 @@
1
1
  ---
2
2
  description: >-
3
- Formally verify a small, risky piece of code with a Lean 4 model: pick candidates from git
4
- history, CONFIRM with the user which code to model, write the model, run it locally with
5
- `verity prove check`, and replay any counterexample on the real code before calling it a bug.
6
- Use when the user asks to verify, prove, or model-check code, or asks "can this race / double
7
- run / fail open?". Anything typed after /verity-prove is the user's hint: the file, function,
8
- or worry to check.
3
+ Formally verify a small, risky piece of code with a Lean 4 model written by the
4
+ Verity service: rank candidates from git history and the user's hint, CONFIRM with
5
+ the user which code to model, have the service generate the model, check it locally
6
+ with `verity prove check`, and replay any counterexample on the real code before
7
+ calling it a bug. Use when the user asks to verify, prove, or model-check code, or
8
+ asks "can this race / double run / fail open?". Anything typed after /verity-prove
9
+ is the user's hint: the file, function, or worry to check.
9
10
  ---
10
11
  # /verity-prove — Formal verification of small pieces of code
11
12
 
12
13
  **The words after `/verity-prove` are the hint.** `/verity-prove` alone means "find me
13
14
  something worth checking"; `/verity-prove can the Stripe webhook double-charge on a
14
- redelivered event?` means that is the target and, if it is a worry, the property.
15
- Carry it through every step below as `$ARGUMENTS`.
15
+ redelivered event?` names the target and the worry. Carry it through every step as
16
+ `$ARGUMENTS`.
16
17
 
17
- Verity keeps **Lean 4 models of the riskiest code**, not of the codebase. A model is
18
- another tool for finding bugs: a few dozen lines that abstract ONE function and check
19
- a few properties by exhaustive bounded search. When a property fails you get the
20
- **shortest sequence of actions** that breaks it — a hypothesis to replay on the real
21
- code. When it holds you know exactly how far it was checked.
18
+ Verity keeps **Lean 4 models of the riskiest code**, not of the codebase: a few dozen
19
+ lines that abstract ONE function and check a few properties by exhaustive bounded
20
+ search. When a property fails you get the **shortest sequence of actions** that breaks
21
+ it — a hypothesis to replay on the real code.
22
22
 
23
- This skill is the **explicit, user-driven** entry; nothing in it blocks a commit or a
24
- push. (The push-time phase — `verity config formal push` — is a separate, opt-in path
25
- that uses the same tools.) Lean runs on this machine because the user asked for it.
23
+ **The service does the work; you orchestrate and present.** Ranking, writing the model
24
+ and replaying its counterexample all run on the Verity service through the CLI. You
25
+ do not search the codebase by hand, read the Lean library, or write Lean yourself
26
+ unless a step below says so. Each step is one command; read its output, decide, move on.
27
+ Lean runs on this machine only because the user asked for it; nothing here blocks a
28
+ commit or a push.
26
29
 
27
30
  ## The flow
28
31
 
29
- ### 1. Find what deserves a model
32
+ ### 1. Candidates — one command
30
33
 
31
34
  ```bash
32
- verity prove candidates --limit 8 # git history + risk signals
33
- verity prove candidates --rank luna --json # + a cheap model re-ranks and names a symbol
34
- verity prove candidates src/payments # scoped to a path
35
+ verity prove candidates --hint "$ARGUMENTS" --json # hint given
36
+ verity prove candidates --limit 8 --json # no hint
35
37
  ```
36
38
 
37
- Each candidate says why: fix commits over commits, check-then-act, retries, caches,
38
- locks/leases, status transitions, money.
39
+ The hint **widens the pool** (files it names by path or content come first) and the
40
+ service ranks it, naming a symbol and the properties worth checking per file. Do not
41
+ search for the code yourself: if the ranker's list does not contain what the user
42
+ meant, say so and ask them for the file or function. A named file or function in the
43
+ hint skips ranking: go straight to step 2 with it.
39
44
 
40
- **With a hint** (`$ARGUMENTS` non-empty) — a file, a function, or a worry in the user's
41
- own words ("can the webhook double-charge?", "does the retry ever lose the feedback?"):
45
+ ### 2. Confirm with the user — always
42
46
 
43
- ```bash
44
- verity prove candidates --hint "$ARGUMENTS"
45
- ```
47
+ **Do not generate a model until the user has said which code.** Present at most three
48
+ candidates in one short message: file, the symbol the ranker named, the first property
49
+ it suggested, the reason. Ask. Their answer is the scope; do not widen it. If the hint
50
+ is a worry in the user's words, it becomes an `intent` property — that needs no further
51
+ confirmation, they just gave it.
46
52
 
47
- A named file or function skips the ranking entirely: go to step 2 with it. A *worry*
48
- becomes an `intent` property in step 4, with `source := "user, <date>: <their words>"`;
49
- it needs no further confirmation, they just gave it. The candidates list is still shown,
50
- so the user sees what else the history says — but the hint decides.
53
+ A hint that names the code, or a candidate the user saw in an earlier session, is
54
+ **not** a confirmation of the exact symbol and property. Still ask, in one line:
55
+ "I'll model `<file>#<symbol>` for `<property>` — go ahead?" It costs the user one word.
51
56
 
52
- ### 2. Confirm with the user — always
57
+ ### 3. Set up once per repo
53
58
 
54
- **Do not write a model until the user has said which code.** Present at most three
55
- candidates in one short message, each as: file, the function you would model, the
56
- property you would check first, and the reason from the signals. Then ask. The user may
57
- pick one, name something else, or narrow the property. Their answer is the scope; do not
58
- widen it.
59
+ ```bash
60
+ verity prove init
61
+ ```
59
62
 
60
- A model is a claim about what the code *means*. Only the person who owns the code can
61
- say whether that claim is worth checking.
63
+ If Lean is missing, say what will be installed and where before running
64
+ `verity lean install` (official release, ≈800 MB download, 2.7 GB on disk, into
65
+ `~/.verity/lean`). Everything else needs only `verity login`.
62
66
 
63
- ### 3. Set up the project (once per repo)
67
+ ### 4. Generate the model — one command
64
68
 
65
69
  ```bash
66
- verity prove init
70
+ verity prove generate src/pay.ts#charge --hint "$ARGUMENTS"
71
+ verity prove generate src/handler.ts --lines 120-180 --hint "$ARGUMENTS" # a region
67
72
  ```
68
73
 
69
- Creates `.verity/proofs/` — a Lake project with Verity's library (`Verity.System`,
70
- `Verity.check`, a bounded explorer). Re-running refreshes the library and never touches
71
- `Models/`. If Lean is missing, install it only after telling the user what will be
72
- installed and where: `verity lean install` (official release, ≈800 MB download, 2.7 GB
73
- on disk, into `~/.verity/lean`). Ranking (`--hint`, `--rank luna`) and `verity prove
74
- replay` run on the Verity service with the user's login (`verity login`); without a
75
- login, ranking is deterministic and replay is by hand (step 6.2).
76
-
77
- ### 4. Write the model — `Models/<Name>.lean`
78
-
79
- Rules that keep models small and honest:
80
-
81
- - **One symbol.** The header names it: `Verity.model { name, abstracts := [{ file, symbol, sha256 }] }`.
82
- Get the hash with `verity prove hash <file>`. `verity prove check` reports drift when the file changes.
83
- When the code is a *region* rather than a named function (a branch inside a large
84
- handler), add `lines := "a-b"` (1-based, inclusive) — `verity prove replay` needs it
85
- to know which real lines must run.
86
- - **State = only what the property reads.** Actions = the operations that can interleave
87
- (a retry, a second call, a concurrent writer). Steps = what the code does, not what it should.
88
- - **Properties are tagged.** `kind := .structural` for the catalogue (idempotence, no lost
89
- update, status only moves forward, retries terminate, never fails open, bounded size,
90
- check-then-act is atomic, no double effect). `kind := .intent` **only** when a human
91
- wrote the expectation down — a doc comment, an ADR, a ticket, a Standard rule — and
92
- `source :=` cites it. Never invent intent.
93
- - **End with the checks.** `#eval Verity.model …` then one `#eval Verity.check …` per
94
- property (bounded exploration), `Verity.checkData` for input properties, `Verity.proved`
95
- only beside a real theorem. `sorry` fails the run.
96
- - Keep it under ~120 lines. If it wants more, the scope is wrong — go back to step 2.
97
-
98
- `Models/README.md` has the skeleton; `cli/tests/fixtures/proofs/SeedRunner.lean` in
99
- Verity's own repo is a worked example (the VRT-243 seed-duplication bug).
100
-
101
- ### 5. Check it
74
+ The service writes the model, the linter fences it, this machine elaborates it, with
75
+ up to **3** rounds on compiler errors — all inside the command. It prints the check:
76
+ per property `✓ holds to bound k`, `✗ COUNTEREXAMPLE` with the trace, or `? inconclusive`.
77
+ Only if it ends with "no model elaborated" do you write one by hand from
78
+ `.verity/proofs/Models/README.md` (one symbol, ≤ ~120 lines, `#eval Verity.model …`
79
+ header, one `#eval Verity.check …` per property, tagged `.structural` or `.intent` with
80
+ `source :=`); check it with `verity prove check <Name>`.
81
+
82
+ ### 5. Replay before you call it a bug — one command
102
83
 
103
84
  ```bash
104
- verity prove check <Name> # one model
105
- verity prove check # every model
106
- verity prove check <Name> --json # for scripts
85
+ verity prove replay <Name> # every counterexample
86
+ verity prove replay <Name> --property P2 # one
107
87
  ```
108
88
 
109
- Per property: `✓ holds to bound k`, `✓ proved`, `✗ COUNTEREXAMPLE` with the trace and
110
- the state after each step, or `? inconclusive` (state cap).
111
-
112
- **Hard caps — never loop:**
113
- - elaboration errors: at most **3** fix rounds, then stop and say the model could not be
114
- built;
115
- - a counterexample that **diverges** on replay (the model was wrong about the code): at
116
- most **2** model revisions, each naming what the replay showed was different; after
117
- that, stop and report "no faithful model found for `<symbol>`" — that is a valid result;
118
- - never weaken or delete a property to make it pass; never add a property to make
119
- something fail.
120
-
121
- A wrong model is expected some of the time. It costs a replay and is discarded; it never
122
- costs a false bug, because only a *reproduced* counterexample is reported (step 6).
123
-
124
- ### 6. Replay before you call it a bug
125
-
126
- A counterexample is a fact about the **model**. Before reporting a bug:
127
-
128
- 1. Run the replay in OpenAI's disposable container (network off, deleted afterwards):
129
-
130
- ```bash
131
- verity prove replay <Name> # every counterexample
132
- verity prove replay <Name> --property P2 # one
133
- ```
134
-
135
- It hands a model the trace, the Lean file and the real source — the abstracted
136
- file's content leaves the machine for the Verity service and OpenAI's container;
137
- only git-tracked files are ever read — and requires three things before accepting
138
- its answer: code actually ran (a shell call with output), the real function's lines
139
- appear verbatim in what it wrote, and the harness itself printed
140
- `REPLAY_RESULT=reproduced`. `REPRODUCED` → the
141
- real code does this. `DIVERGED` → the model is wrong about the code. `UNVERIFIED` →
142
- not evidence either way. `UNREPLAYABLE` → it could not run the function faithfully.
143
- Read its reason: the stubs it chose are where a false reproduction hides.
144
- 2. When the replay is unverified or unreplayable — or the code needs a runtime the
145
- container lacks (Deno edge functions, a real database) — replay by hand: read the
146
- real function again, map every trace action to a real call, and reproduce it with a
147
- throwaway harness in a scratch directory that loads the real module and stubs only
148
- I/O boundaries. **Never edit the user's source files to do this.**
149
- 3. Reproduced → report it as a bug, with the trace and the reproduction. Not reproduced
150
- → the model is wrong (`model-divergence`): say so, fix the model, do not report a bug.
151
-
152
- This is the rule Verity applies everywhere (memory: *replay formal counterexamples
153
- against changed code before blocking*). A model that finds a bug in itself is noise.
154
-
155
- ### 7. Report, in a few lines
156
-
157
- State what was modelled, what was checked to what bound, what was refuted and whether
158
- it replayed, and what remains `intent` awaiting the user's confirmation. **Never offer
159
- to commit the model** — `.verity/proofs/` is machine-local and ignores itself; models
160
- would only confuse reviewers. What reaches the team is the bug report and, when asked,
161
- the fix. Then record the outcome:
89
+ The service replays the trace on the real code in a network-less container and accepts
90
+ an answer only when code ran, the real function's lines appear verbatim in the harness,
91
+ and the harness itself printed `REPLAY_RESULT=reproduced`. A model's counterexamples
92
+ replay in parallel, so the command takes about as long as one replay (~30 s). **Run it
93
+ in the foreground and wait for it**: do not background it, do other work, or report
94
+ before every verdict is in. Read the verdict:
95
+
96
+ - **REPRODUCED** — the real code does this. **This is final: do not replay by hand
97
+ as well.** Report it as a bug (step 6).
98
+ - **DIVERGED** — the model is wrong about the code. Revise it **at most twice**, each
99
+ time saying what the replay showed:
100
+ `verity prove generate <target> --revise <Name> --note "<what the replay showed>"`,
101
+ then replay again. After two divergences, report "no faithful model found for
102
+ `<symbol>`" — that is a valid result, not a bug.
103
+ - **UNVERIFIED / UNREPLAYABLE** — not evidence either way. Only now replay by hand:
104
+ a throwaway harness in a scratch directory that loads the real module and stubs only
105
+ I/O boundaries **in memory**. Never edit the user's source files, and never read from
106
+ or write to the user's databases, services or local stacks to do this — ask first if
107
+ a stub cannot be faithful.
108
+
109
+ Never weaken or delete a property to get green; never add one to make something fail.
110
+
111
+ ### 6. Report, in a few lines
112
+
113
+ What was modelled, what was checked to what bound, what was refuted and whether it
114
+ replayed, and what remains `intent` awaiting the user's confirmation. **Never offer to
115
+ commit the model** — `.verity/proofs/` is machine-local and ignores itself. What reaches
116
+ the team is the bug report and, when asked, the fix. Then record the outcome:
162
117
 
163
118
  ```bash
164
119
  verity reflect --user-input "Modelled runSeed (cli/src/lib/seed-runner.ts): P1 at-most-once refuted in 2 steps, replayed — guard checks a path the server never writes." --kind gotcha
165
120
  ```
166
121
 
122
+ The abstracted file's content leaves the machine for the Verity service and its
123
+ replay container; only git-tracked files are ever read.
124
+
167
125
  ## Do not
168
126
 
127
+ - Search the codebase yourself before the ranker has answered, or instead of asking the user.
169
128
  - Model code the user did not confirm.
170
- - Present a model-only counterexample as a bug.
171
- - Put `sorry` in a model, or weaken a property to get green.
172
- - Touch source files, run Lean from a hook, or install anything silently.
129
+ - Write Lean by hand while `verity prove generate` can still try.
130
+ - Replay by hand after a REPRODUCED verdict, or present a model-only counterexample as a bug.
131
+ - Background `verity prove replay`, or report before its verdicts are in.
132
+ - Write to the user's databases or local services, even throwaway rows.
133
+ - Put `sorry` in a model, weaken a property to get green, or touch source files.
134
+ - Run Lean from a hook, or install anything silently.
173
135
  - Commit, stage, or un-ignore anything under `.verity/proofs/`.
174
- - Model a whole module. If the state has more than ~6 fields, narrow it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/verity-cli",
3
- "version": "0.33.3-experimental.52f1656",
3
+ "version": "0.33.3-experimental.80b064d",
4
4
  "description": "CLI for Verity quality gate service",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://verity.md",
@@ -13,6 +13,7 @@
13
13
  "files": [
14
14
  "bin/verity.js",
15
15
  "data/skills/",
16
+ "data/grammars/",
16
17
  "package.json",
17
18
  "README.md",
18
19
  "LICENSE",
@@ -31,8 +32,14 @@
31
32
  "devDependencies": {
32
33
  "@types/node": "^20",
33
34
  "esbuild": "^0.25.12",
35
+ "tree-sitter-go": "0.25.0",
36
+ "tree-sitter-java": "0.23.5",
37
+ "tree-sitter-javascript": "0.25.0",
38
+ "tree-sitter-python": "0.25.0",
39
+ "tree-sitter-typescript": "0.23.2",
34
40
  "tsx": "^4.21.0",
35
- "typescript": "^5.4"
41
+ "typescript": "^5.4",
42
+ "web-tree-sitter": "0.27.0"
36
43
  },
37
44
  "dependencies": {
38
45
  "commander": "^12",