rocq-live 0.1.0__tar.gz

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.
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.vo
3
+ *.vos
4
+ *.vok
5
+ *.glob
6
+ .*.aux
7
+ _build/
8
+ dist/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kyle Zhang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,367 @@
1
+ Metadata-Version: 2.5
2
+ Name: rocq-live
3
+ Version: 0.1.0
4
+ Summary: Live Rocq proof sessions for coding agents: a CLI and MCP server, with no per-project setup
5
+ Project-URL: Homepage, https://github.com/kylezh/rocq-live
6
+ Project-URL: Repository, https://github.com/kylezh/rocq-live
7
+ Project-URL: Issues, https://github.com/kylezh/rocq-live/issues
8
+ Author: Kyle Zhang
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai-agents,coq,llm,mcp,mcp-server,proof-assistant,rocq,theorem-proving
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
21
+ Classifier: Topic :: Software Development :: Quality Assurance
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+
25
+ # rocq-live
26
+
27
+ Live [Rocq](https://rocq-prover.org) (Coq) proof sessions for coding agents and
28
+ humans, in any project, with no per-project setup.
29
+
30
+ Without a live session, an agent that wants the goal at line 300 recompiles
31
+ lines 1–299 every time it looks. With `rocq-live`, each file gets one
32
+ long-running `coqtop`, so a step costs only that step:
33
+
34
+ ```
35
+ $ rocq-live goto theories/Foo.v:42
36
+ 1 goal
37
+ n : nat
38
+ ============================
39
+ double n = 2 * n
40
+ rocq-live: checked up to theories/Foo.v line 41 (asked for line 42)
41
+
42
+ $ rocq-live run theories/Foo.v 'unfold double. lia.'
43
+ No more goals.
44
+ ```
45
+
46
+ Edit the file and call `goto` again: only the text from the first changed
47
+ character onwards is re-checked.
48
+
49
+ It is one Python file with no dependencies. It works as a **CLI** (for any
50
+ agent with a shell) and as an **MCP server** (Claude Code, Codex, Cursor,
51
+ Gemini CLI, …).
52
+
53
+ ## Install
54
+
55
+ ```sh
56
+ uv tool install rocq-live # or: pipx install rocq-live
57
+ ```
58
+
59
+ Or run it without installing (`uvx rocq-live …`), or take the single file:
60
+
61
+ ```sh
62
+ curl -fsSL -o ~/.local/bin/rocq-live https://raw.githubusercontent.com/kylezh/rocq-live/master/rocq-live
63
+ chmod +x ~/.local/bin/rocq-live # any directory on PATH works
64
+ ```
65
+
66
+ Requirements: Python ≥ 3.9 and `coqtop` (Rocq 9.x; see
67
+ [Compatibility](https://github.com/kylezh/rocq-live#compatibility)). opam and dune are optional. macOS or Linux.
68
+
69
+ ## Connect your agent
70
+
71
+ The server is the same for every client: the command `rocq-live mcp` over stdio.
72
+
73
+ **Claude Code**
74
+
75
+ ```sh
76
+ claude mcp add -s user rocq-live -- rocq-live mcp
77
+ ```
78
+
79
+ **Codex** — `~/.codex/config.toml`:
80
+
81
+ ```toml
82
+ [mcp_servers.rocq-live]
83
+ command = "rocq-live"
84
+ args = ["mcp"]
85
+ tool_timeout_sec = 600 # the first goto may build the file's imports
86
+ ```
87
+
88
+ **Cursor, Gemini CLI, Claude Desktop, other MCP clients** — the usual JSON entry:
89
+
90
+ ```json
91
+ { "mcpServers": { "rocq-live": { "command": "rocq-live", "args": ["mcp"] } } }
92
+ ```
93
+
94
+ **Agents without MCP** — put this in your `AGENTS.md` / `CLAUDE.md`:
95
+
96
+ ```markdown
97
+ To see a proof state, use `rocq-live goto FILE:LINE` (state before LINE);
98
+ try tactics with `rocq-live run FILE 'tac.'`, undo with `rocq-live back FILE`,
99
+ query with `rocq-live query FILE 'Search ...'`. After editing FILE, goto again.
100
+ ```
101
+
102
+ All tools are marked read-only (`readOnlyHint`): they never edit files. A
103
+ `goto` may build the file's imports, as a build would.
104
+
105
+ ## Commands
106
+
107
+ | CLI | MCP tool | does |
108
+ |----------------------------------|-----------------|---------------------------------------------------------|
109
+ | `goto FILE[:LINE] [--full]` | `rocq_goto` | state just before LINE (default: end, checking every proof); starts a session |
110
+ | `run FILE[:LINE] 'tac1. tac2.'` | `rocq_run` | run on the current state (or on the state before LINE); an error changes nothing |
111
+ | `query FILE 'Search …'` | `rocq_query` | run, print, undo (Search, Check, Print, About, …) |
112
+ | `try FILE 'lia' 'auto' …` | `rocq_try` | each tactic alone on the current state: which work, goals left (best first); state unchanged |
113
+ | `audit FILE [NAME…] [--allow AX,…]` | `rocq_audit` | `Admitted`/`admit`/axioms, and `Print Assumptions` of each declaration against the allowed axioms: PASS/FAIL |
114
+ | `back FILE [N]` | `rocq_back` | undo the last N runs |
115
+ | `goals FILE` | `rocq_goals` | current goals |
116
+ | `start FILE[:LINE]` | `rocq_goto` with `fresh` | kill any session for FILE, start a new one |
117
+ | `stop FILE` / `stop --all` | `rocq_stop` | kill the session(s) |
118
+ | `list` | `rocq_sessions` | running sessions: memory, idle time, limits |
119
+ | `gc` | — | apply the limits now (this also happens automatically) |
120
+ | `info FILE` | `rocq_info` | detected root, toolchain and load path |
121
+
122
+ Exit status: 0 on success, 1 on an error (Rocq or setup), 2 on bad usage.
123
+
124
+ **`try`** is for the moment an agent would otherwise guess one tactic per turn:
125
+
126
+ ```
127
+ $ rocq-live try Foo.v 'lia' 'auto' 'intros; split' 'reflexivity'
128
+ rocq-live: 3 of 4 tactics work; state unchanged; best: [1] lia (no goals left)
129
+ [1] lia -> works (no goals left)
130
+ [2] auto -> works (no goals left)
131
+ [3] intros; split -> works (2 goals left)
132
+ ...
133
+ [4] reflexivity -> FAILS: Error: The relation and is not a declared reflexive relation. ...
134
+ ```
135
+
136
+ Each tactic gets `ROCQ_LIVE_TRY_TIMEOUT` seconds (default 30). `query` and
137
+ `try` also accept `FILE:LINE`.
138
+
139
+ **Fast replay.** `goto FILE:LINE` checks the statement of each finished `Qed`
140
+ proof before LINE, but takes the proof itself as `Admitted`, as `coqc -vos`
141
+ does. Everything else in the file (imports, scopes, notations, options,
142
+ `Defined` bodies) is replayed in place, so the goal at LINE is the same; only
143
+ the tactic work in earlier proofs is skipped. The reply says how many proofs
144
+ were taken as Admitted. Proofs are always checked in full when:
145
+ - you edited them since the session last read the file;
146
+ - the proof is `Defined`, `Program`, `Proof term.`, or inside a `Section`
147
+ without `Proof using` (Admitted would generalize it differently);
148
+ - you pass `--full`, or give no LINE at all (the whole file).
149
+
150
+ `audit` always checks in full. Turn fast replay off with `ROCQ_LIVE_FAST=0`.
151
+
152
+ Measured on a file with 12 proofs that each take tactic time, followed by the
153
+ lemma being worked on (Rocq 9.0, M-series Mac):
154
+
155
+ | | time |
156
+ |---|---|
157
+ | fresh session, `goto --full` | 3.36 s |
158
+ | fresh session, `goto` (fast replay) | 0.25 s |
159
+ | one step in a live session | 0.08 s |
160
+ | restoring a stopped session from its recipe | 0.33 s |
161
+ | one call in no-daemon mode | 0.19 s |
162
+
163
+ **`audit`** fails on any `Admitted`, `admit` or `give_up`, on an `Axiom` or
164
+ `Parameter` that is not allowed, and on any declaration whose `Print
165
+ Assumptions` lists an axiom that is not allowed. Admitted lemmas count, since
166
+ Rocq lists them as axioms. Allowed axioms come from `axioms` in `.rocq-live`,
167
+ or from `--allow` / `allow`. With NAMEs, only those declarations are judged.
168
+ The audit checks the whole file, then returns the session to where it was.
169
+
170
+ **Hints.** For an error whose fix isn't in the message, a `rocq-live hint:`
171
+ line follows it. This covers a missing load-path binding, a library that is
172
+ not built, a `.vo` from another Rocq version, a stale `.vo`, a step stopped for
173
+ time or memory, and a proof command given outside a proof.
174
+
175
+ ## Project detection
176
+
177
+ Detection starts at the file and goes upward; the nearest marker wins:
178
+
179
+ | found | load path |
180
+ |------------------------------|--------------------------------------------------------------------|
181
+ | `dune-project` | `dune rocq top` / `dune coq top`; also rebuilds the file's imports |
182
+ | `_CoqProject` | its `-Q`, `-R`, `-I` and `-arg` lines (you keep the `.vo`s built) |
183
+ | neither | no flags (root: the git root) |
184
+
185
+ **Toolchain:** the current opam switch if it has `coqtop`, otherwise `coqtop`
186
+ (or `rocq repl`) on PATH. `rocq-live info FILE` shows what was picked.
187
+
188
+ ### `.rocq-live` (optional)
189
+
190
+ Put this file at the project root to override detection. All keys are optional,
191
+ and relative paths are resolved from the file's directory:
192
+
193
+ ```
194
+ switch rocq-9.0 # opam switch to use (`path`: coqtop on PATH)
195
+ flags -Q theories MyLib # load path, verbatim
196
+ loadpath scripts/loadpath.sh {file} # or: a command that prints the flags
197
+ build make -j8 # command run before each start/goto
198
+ axioms classic functional_extensionality_dep # axioms `audit` accepts
199
+ ```
200
+
201
+ Use `flags` for projects built by a plain `coqc` script, `loadpath` for custom
202
+ build trees (for example one built with `coqc -vos` for speed), and `build`
203
+ when `_CoqProject` `.vo`s should be rebuilt automatically.
204
+
205
+ ### Environment
206
+
207
+ | variable | meaning |
208
+ |---------------------|-----------------------------------------------------------|
209
+ | `ROCQ_LIVE_FLAGS` | load path flags; overrides detection |
210
+ | `ROCQ_LIVE_SWITCH` | opam switch (`path` = coqtop on PATH) |
211
+ | `ROCQ_LIVE_TIMEOUT` | seconds per step (default 600 for goto, 120 otherwise) |
212
+ | `ROCQ_LIVE_TRY_TIMEOUT` | seconds per tactic in `try` (default 30) |
213
+ | `ROCQ_LIVE_FAST` | `0`: `goto` checks every proof (as `--full`) |
214
+ | `ROCQ_LIVE_DAEMON` | `0`: no background process (see [Recipes](https://github.com/kylezh/rocq-live#recipes-and-the-no-daemon-mode)) |
215
+
216
+ The session limits below can also be set in the environment.
217
+
218
+ ## Sessions, memory and GC
219
+
220
+ Each `.v` file being worked on has one session: a background daemon with its
221
+ own `coqtop`, in its own process group, reachable through a Unix socket in
222
+ `/tmp/rocq-live-$UID/`. Within a session, going back (`goto` to an earlier line,
223
+ `back`) drops the later states. A session ends when you `stop` it, when it
224
+ has been idle for `idle` seconds, or when the GC stops it.
225
+
226
+ **Limits** apply to the whole machine. Each is read from the environment, else
227
+ from `~/.config/rocq-live/config` (`key value` lines). They are read again at
228
+ each use, so editing the file changes running sessions too.
229
+
230
+ | key | environment | default | meaning |
231
+ |----------------|--------------------------|--------------------|-----------------------------|
232
+ | `max_mb` | `ROCQ_LIVE_MAX_MB` | half the RAM | all sessions together |
233
+ | `session_mb` | `ROCQ_LIVE_SESSION_MB` | `max_mb` | one session |
234
+ | `max_sessions` | `ROCQ_LIVE_MAX_SESSIONS` | 16 | how many sessions (soft, see below) |
235
+ | `grace` | `ROCQ_LIVE_GRACE` | 600 | seconds a session is spared from the count limit after its last use |
236
+ | `idle` | `ROCQ_LIVE_IDLE` | 1200 | seconds before an idle session exits (its next use restores it from the recipe) |
237
+
238
+ ```
239
+ # ~/.config/rocq-live/config
240
+ max_mb 12000
241
+ session_mb 6000
242
+ max_sessions 12 # about 2 per concurrent agent: its proof file and a scratch file
243
+ grace 600
244
+ ```
245
+
246
+ **GC.** When a session starts, after every request, and every second while a
247
+ step runs, rocq-live compares the sessions with the limits.
248
+ - **Too much memory in total:** the least recently used idle sessions are
249
+ stopped until the total fits. A busy session is never stopped from outside.
250
+ - **Too many sessions:** the same, but sessions used within the last `grace`
251
+ seconds are spared. To rocq-live, an agent thinking between two tool calls
252
+ looks idle, and stopping its session would cost a full re-check on its next
253
+ call. An extra idle `coqtop` costs only memory, and `max_mb` already bounds
254
+ that. So the count is soft: it can be exceeded by sessions in recent use,
255
+ and memory is the hard limit.
256
+ - **A step pushes its session over `session_mb`:** the step is interrupted.
257
+ The same happens when the total is over `max_mb`, the step itself is growing,
258
+ and no idle session is left to stop. Its `coqtop` is then restarted and the
259
+ file replayed, since an OCaml process does not return a big heap to the
260
+ system, and the reply says so. If `coqtop` ignores the interrupt (Rocq 9.3
261
+ does inside `vm_compute`), it is killed after 5 s and the same recovery runs.
262
+ - **A file whose fresh `coqtop` is already above `session_mb`:** that file's
263
+ limit becomes its fresh size plus 25%, with a note, so it isn't restarted on
264
+ every request.
265
+
266
+ `rocq-live list` shows every session's memory and idle time:
267
+
268
+ ```
269
+ $ rocq-live list
270
+ 2.1 GB busy /work/proj/theories/Big.v
271
+ 140 MB 12m idle /work/proj/theories/Small.v
272
+ 2 session(s), 2.2 GB; limits: 16 sessions (sparing those used in the last 10m), 8.0 GB total, 8.0 GB per session, 20m idle
273
+ ```
274
+
275
+ ### Recipes and the no-daemon mode
276
+
277
+ Rocq cannot save a live session's state to a file (`Write State` was removed
278
+ in 2021), so rocq-live saves a **recipe** instead: the session's last `goto`
279
+ line and the runs made on top of it. Recipes live in `~/.cache/rocq-live/recipes/`
280
+ and are kept for 7 days. When a session was stopped by GC, by the idle
281
+ timeout, or by a reboot, its next use restores it: fast replay to the line,
282
+ then the runs. The reply says so, and how long it took. An explicit `stop`
283
+ forgets the recipe.
284
+
285
+ With `ROCQ_LIVE_DAEMON=0`, nothing runs in the background. Each call starts a
286
+ `coqtop`, rebuilds the state from the recipe, answers, saves the recipe and
287
+ exits. Each call is slower, since it replays the file from the start, but the
288
+ commands and output are the same. Use it where background processes are not
289
+ allowed (some CI runners and sandboxes).
290
+
291
+ **Robustness.**
292
+ - **Crash:** if `coqtop` crashes during a step (for example a stack overflow
293
+ in Rocq itself), the session restarts it, replays to where it was, and
294
+ reports that the step was not applied.
295
+ - **Upgrade:** when rocq-live is updated, each session started by the old
296
+ version is restored from its recipe on its next use.
297
+ - **Cleanup:** files left by dead sessions are cleaned up, and their logs are
298
+ kept for a day.
299
+
300
+ ## Caching
301
+
302
+ - **Proof state.** The checked prefix of each file stays in its session. When
303
+ `goto` moves backward it jumps to a saved state (`BackTo`), which is instant.
304
+ When it moves forward or after an edit, it checks only the new text.
305
+ - **Sessions are shared.** A session is a background daemon keyed by the file's
306
+ path, not owned by the agent. The CLI, the MCP server, several agents, and an
307
+ MCP server restarted by its client all use the same warm session.
308
+ - **Imports.** In dune projects, imports are built by dune, so they use dune's
309
+ cache. dune's default (`enabled-except-user-rules`) does not cache Rocq
310
+ rules; to share checked files across worktrees and clones, enable it fully
311
+ with `(cache enabled)` in `dune-workspace` or `DUNE_CACHE=enabled`.
312
+ - **Freshness.** A session watches the `.vo`/`.vos` files of the project modules
313
+ it has loaded. When one is rebuilt, the session restarts `coqtop` and replays
314
+ the file to the last `goto` line and the runs on top of it. It reports this,
315
+ so it never answers from a stale import.
316
+
317
+ ## Compatibility
318
+
319
+ | tested | result |
320
+ |-----------------------------------------------|--------|
321
+ | Rocq 9.0.0 (opam), dune 3.21 with `(using coq …)` | ✓ |
322
+ | Rocq 9.3.0 (Homebrew), dune 3.24 with `(using rocq …)` | ✓ |
323
+ | `_CoqProject` with Rocq 9.0 and 9.3 | ✓ |
324
+ | Python 3.9 and 3.12, macOS | ✓ |
325
+ | MCP: Claude Code, Codex CLI 0.169 | ✓ |
326
+ | memory watchdog / GC on Rocq 9.0 and 9.3 | ✓ |
327
+
328
+ - **Rocq/Coq versions.** rocq-live talks to `coqtop -emacs` using only commands
329
+ that have been stable for years (`Fail Check`, `BackTo`, `Show`, `Print Libraries`).
330
+ It parses both `Rocq <` and `Coq <` prompts, so Coq 8.x should work, but this
331
+ is not tested yet.
332
+ - **dune versions.** It uses `dune rocq top` for `(using rocq …)` projects and
333
+ `dune coq top` for `(using coq …)` projects, and falls back to the other if a
334
+ dune version lacks one. dune ≥ 3.24 has dropped `coq top`.
335
+ - **Linux.** It uses only POSIX features (Unix sockets, process groups) but has
336
+ not been tested there yet. Windows is not supported.
337
+
338
+ ## How it works
339
+
340
+ The file is split into sentences: a `.` followed by white space, outside
341
+ comments and strings, with bullets and braces handled. Each sentence is sent to
342
+ `coqtop -emacs` followed by a marker command; the marker's output shows the
343
+ sentence has finished, and the state id after each sentence is recorded. A step
344
+ that runs too long is interrupted (SIGINT) and undone. Sessions live under
345
+ `/tmp/rocq-live-$UID/`, and a client talks to a session over a Unix socket.
346
+
347
+ ## Tests
348
+
349
+ ```sh
350
+ python3 tests/test_rocq_live.py # default toolchain
351
+ ROCQ_LIVE_SWITCH=path python3 tests/test_rocq_live.py
352
+ ```
353
+
354
+ ## Related
355
+
356
+ [rocq-mcp](https://github.com/LLM4Rocq/rocq-mcp) is a larger MCP server built
357
+ on coq-lsp's `pet`. Its extras include proof-statement verification, a file
358
+ outline, notation lookup, and several errors per compile. rocq-live aims for no
359
+ dependencies beyond `coqtop`, a CLI as well as MCP, sessions shared per file
360
+ across agents, re-checking only what an edit changed, and machine-wide memory
361
+ limits.
362
+
363
+ ## License
364
+
365
+ [MIT](https://github.com/kylezh/rocq-live/blob/master/LICENSE)
366
+
367
+ <!-- mcp-name: io.github.kylezh/rocq-live -->