fv-skills-baif 1.2.0 → 1.3.1

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 (46) hide show
  1. package/CHANGELOG.md +32 -3
  2. package/README.md +27 -8
  3. package/agents/fvs-executor.md +3 -3
  4. package/agents/fvs-lean-prover.md +9 -9
  5. package/agents/{fvs-lean-simplifier.md → fvs-lean-refactorer.md} +22 -22
  6. package/agents/fvs-lean-spec-generator.md +6 -6
  7. package/agents/fvs-researcher.md +50 -9
  8. package/bin/install.js +93 -12
  9. package/commands/fvs/help.md +67 -17
  10. package/commands/fvs/kb-setup.md +321 -0
  11. package/commands/fvs/lean-formalise.md +335 -0
  12. package/commands/fvs/lean-proof-port.md +3 -3
  13. package/commands/fvs/{lean-simplify.md → lean-refactor.md} +43 -43
  14. package/commands/fvs/lean-spec-port.md +6 -6
  15. package/commands/fvs/lean-specify.md +7 -7
  16. package/commands/fvs/lean-verify.md +3 -3
  17. package/commands/fvs/sync-aeneas.md +277 -0
  18. package/fv-skills/references/aeneas-patterns.md +412 -3
  19. package/fv-skills/references/{lean-simplification.md → lean-refactoring.md} +334 -44
  20. package/fv-skills/references/lean-spec-conventions.md +14 -14
  21. package/fv-skills/references/model-profiles.md +4 -4
  22. package/fv-skills/references/proof-strategies.md +338 -38
  23. package/fv-skills/references/tactic-usage.md +369 -62
  24. package/fv-skills/templates/config.json +2 -1
  25. package/fv-skills/templates/spec-file.lean +4 -4
  26. package/fv-skills/upstream/aeneas/_sync-meta.json +102 -0
  27. package/fv-skills/upstream/aeneas/aeneas-lean-core.instructions.md +1904 -0
  28. package/fv-skills/upstream/aeneas/aeneas-tactics-quickref.instructions.md +600 -0
  29. package/fv-skills/upstream/aeneas/agent-fleet-management.instructions.md +400 -0
  30. package/fv-skills/upstream/aeneas/launching-proof-agents.instructions.md +1296 -0
  31. package/fv-skills/upstream/aeneas/lean-lsp-mcp.instructions.md +321 -0
  32. package/fv-skills/upstream/aeneas/proof-patterns.instructions.md +151 -0
  33. package/fv-skills/upstream/aeneas/proof-strategies.md +455 -0
  34. package/fv-skills/upstream/aeneas/tactics-reference.md +256 -0
  35. package/fv-skills/upstream/aeneas/tips-and-tricks.md +416 -0
  36. package/fv-skills/workflows/lean-formalise.md +264 -0
  37. package/fv-skills/workflows/lean-proof-port.md +19 -18
  38. package/fv-skills/workflows/{lean-simplify.md → lean-refactor.md} +41 -41
  39. package/fv-skills/workflows/lean-spec-port.md +4 -4
  40. package/fv-skills/workflows/lean-specify.md +3 -3
  41. package/fv-skills/workflows/lean-verify.md +2 -2
  42. package/fv-skills/workflows/sync-aeneas.md +219 -0
  43. package/hooks/dist/fvs-check-update.js +73 -5
  44. package/hooks/dist/fvs-statusline.js +30 -11
  45. package/package.json +1 -1
  46. package/scripts/fvs-kb-query.py +208 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,35 @@ All notable changes to FVS (Formal Verification Skills) will be documented in th
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/).
6
6
 
7
+ ## [1.3.1] - 2026-04-07
8
+
9
+ ### Fixed
10
+ - Statusline not showing FVS state in GSD delegation mode -- now detects `.formalising/` as FVS project indicator
11
+ - Update/staleness indicators never shown when GSD statusline active -- `readFvsCache()` shared across both modes
12
+ - Local install skipping FVS statusline when GSD globally present -- now wraps GSD locally via project-level settings
13
+
14
+ ## [1.3.0] - 2026-04-05
15
+
16
+ ### Added
17
+ - `/fvs:lean-formalise` command -- paper track for formalising mathematical papers into Lean 4 specs, 4 interactive prompts, two-phase researcher→executor dispatch, KB integration
18
+ - `/fvs:kb-setup` command -- interactive NotebookLM knowledge base setup (venv, auth, KB registration)
19
+ - `fvs-kb-query.py` composable CLI tool -- ask/list/health subcommands for querying NotebookLM KBs with structured JSON output
20
+ - `fvs-researcher` formalise mode (6th mode) -- reads resources (PDF, images, LaTeX, text), queries KB with domain gating, extracts mathematical structure, proposes Lean file layout
21
+ - `/fvs:sync-aeneas` command and workflow for continuous Aeneas upstream integration
22
+ - Aeneas upstream documentation snapshot (`fv-skills/upstream/aeneas/`) with sync mapping (`_sync-meta.json`)
23
+ - Aeneas staleness detection in session start hook -- queries GitHub API, shows warning in statusline
24
+ - Protocol verification domain pattern (Spec_pro/Spec_sec/Spec_pro|=Spec_sec) in lean-formalise
25
+ - `knowledge_bases` array in config template for domain-gated KB entries
26
+ - Installer copies `scripts/` directory to target with manifest tracking and uninstall cleanup
27
+ - Acknowledgements section in README
28
+
29
+ ### Changed
30
+ - `/fvs:lean-simplify` renamed to `/fvs:lean-refactor` with expanded refactoring corpus
31
+ - `fvs-lean-simplifier` agent renamed to `fvs-lean-refactorer`
32
+ - All tactic names migrated to current Aeneas conventions: `progress`→`step`, `@[progress]`→`@[step]`, `omega` BANNED, `agrind` as default
33
+ - References enriched from upstream: aeneas-patterns (+400 lines), tactic-usage (+260 lines), proof-strategies (+300 lines), lean-refactoring (+400 lines)
34
+ - Test suite expanded from 154 to 167 tests (scripts, new commands, updated counts)
35
+
7
36
  ## [1.2.0] - 2026-03-16
8
37
 
9
38
  ### Added
@@ -44,9 +73,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
44
73
  ## [1.1.0] - 2026-03-09
45
74
 
46
75
  ### Added
47
- - `/fvs:lean-simplify` command for post-verification proof cleanup (#17) -- three modes (safe/balanced/aggressive), tiered heuristics, one change per invocation with build verification
48
- - `fvs-lean-simplifier` agent for iterative proof simplification
49
- - `lean-simplification.md` reference with proof-fuel rule, simplification ordering, layering strategy, target selection heuristics, and repo-specific lessons
76
+ - `/fvs:lean-refactor` command for post-verification proof cleanup (#17) -- three modes (safe/balanced/aggressive), tiered heuristics, one change per invocation with build verification
77
+ - `fvs-lean-refactorer` agent for iterative proof refactoring
78
+ - `lean-refactoring.md` reference with proof-fuel rule, refactoring ordering, layering strategy, target selection heuristics, and repo-specific lessons
50
79
  - Codex runtime support in installer (#18) -- `npx fv-skills-baif --codex`
51
80
  - `/fvs:pause-work` command for session context handoff (#10)
52
81
  - `/fvs:resume-work` command for session context restoration (#10)
package/README.md CHANGED
@@ -110,14 +110,15 @@ Use `--claude`, `--codex`, `--opencode`, `--gemini`, or `--all` to skip the runt
110
110
  | `/fvs:help` | Show available FVS commands and usage guide |
111
111
  | `/fvs:update` | Self-update to latest version via npx |
112
112
  | `/fvs:reapply-patches` | Reapply local modifications after an FVS update |
113
+ | `/fvs:sync-aeneas` | Sync Aeneas upstream documentation and update FVS references |
113
114
 
114
115
  ### Lean 4 (via Aeneas)
115
116
 
116
117
  | Command | Description |
117
118
  |---------|-------------|
118
- | `/fvs:lean-specify` | Generate Lean spec skeleton with `@[progress]` theorem pattern |
119
- | `/fvs:lean-verify` | Attempt proof using domain tactics (progress, simp, ring, omega) |
120
- | `/fvs:lean-simplify` | Simplify and golf verified proofs (dead code removal, simp sharpening, tactic golf) |
119
+ | `/fvs:lean-specify` | Generate Lean spec skeleton with `@[step]` theorem pattern |
120
+ | `/fvs:lean-verify` | Attempt proof using domain tactics (step, simp, ring, agrind, scalar_tac) |
121
+ | `/fvs:lean-refactor` | Refactor, simplify, and decompose verified proofs (dead code removal, simp sharpening, tactic golf) |
121
122
 
122
123
  ### Cross-language Porting
123
124
 
@@ -126,6 +127,13 @@ Use `--claude`, `--codex`, `--opencode`, `--gemini`, or `--all` to skip the runt
126
127
  | `/fvs:lean-spec-port` | Port specs from other FV languages (Verus, F*, Coq, Dafny) to Lean |
127
128
  | `/fvs:lean-proof-port` | Port proofs from other FV languages to Lean |
128
129
 
130
+ ### Formalisation (Paper Track)
131
+
132
+ | Command | Description |
133
+ |---------|-------------|
134
+ | `/fvs:lean-formalise` | Formalise paper/math content into Lean 4 specs and definitions |
135
+ | `/fvs:kb-setup` | Set up NotebookLM knowledge base integration (venv, auth, config) |
136
+
129
137
  ---
130
138
 
131
139
  ## How It Works
@@ -142,15 +150,15 @@ FVS follows a five-stage workflow. Each stage builds on the previous.
142
150
 
143
151
  ### 3. Specify
144
152
 
145
- `/fvs:lean-specify <function>` — Generate a specification skeleton for the target function. For Lean 4: uses the `@[progress] theorem fn_spec` pattern with preconditions from Rust source analysis and postconditions matching function behavior.
153
+ `/fvs:lean-specify <function>` — Generate a specification skeleton for the target function. For Lean 4: uses the `@[step] theorem fn_spec` pattern with preconditions from Rust source analysis and postconditions matching function behavior.
146
154
 
147
155
  ### 4. Verify
148
156
 
149
- `/fvs:lean-verify <function>` — Attempt to prove the specification. For Lean 4: uses domain-specific tactics (`progress`, `simp`, `ring`, `field_simp`, `omega`). Reports proof status and remaining goals if incomplete.
157
+ `/fvs:lean-verify <function>` — Attempt to prove the specification. For Lean 4: uses domain-specific tactics (`step`, `simp`, `ring`, `field_simp`, `omega`). Reports proof status and remaining goals if incomplete.
150
158
 
151
159
  ### 5. Simplify
152
160
 
153
- `/fvs:lean-simplify <spec_path>` — Simplify and golf verified proofs. Applies tiered heuristics (dead code removal, simp sharpening, tactic golf, smart automation) while verifying compilation after every change. Three modes: safe, balanced (default), and aggressive.
161
+ `/fvs:lean-refactor <spec_path>` — Refactor, simplify, and decompose verified proofs. Applies tiered heuristics (dead code removal, simp sharpening, tactic golf, smart automation) while verifying compilation after every change. Three modes: safe, balanced (default), and aggressive.
154
162
 
155
163
  ---
156
164
 
@@ -169,9 +177,20 @@ Removes all FVS commands, agents, hooks, and settings entries. Does not affect o
169
177
 
170
178
  ---
171
179
 
172
- ## Acknowledgments
180
+ ## Acknowledgements
181
+
182
+ FVS builds on the work of several open-source projects:
183
+
184
+ - **[Aeneas](https://github.com/AeneasVerif/aeneas)** -- FVS incorporates and adapts
185
+ documentation and proof skills from the Aeneas verification framework (Apache 2.0).
186
+ The upstream Aeneas documentation is stored in `fv-skills/upstream/aeneas/` and can
187
+ be synced with `/fvs:sync-aeneas`.
188
+
189
+ - **[GSD (Get Shit Done)](https://github.com/gsd-build/get-shit-done)** -- FVS follows
190
+ the GSD plugin architecture for Claude Code skill distribution (MIT).
173
191
 
174
- The architecture and plugin infrastructure of this project is heavily inspired by — and in parts directly adapted from — [Get Shit Done (GSD)](https://github.com/glittercowboy/get-shit-done). Thanks to the GSD maintainers for building such a solid foundation.
192
+ - **[lean-lsp-mcp](https://github.com/oOo0oOo/lean-lsp-mcp)** -- MCP server for Lean
193
+ LSP integration, referenced in proof workflows (MIT).
175
194
 
176
195
  ---
177
196
 
@@ -82,16 +82,16 @@ Your parent command provides `<execution_mode>` and `<research_findings>` tags.
82
82
  **Input:** Current proof state, available lemmas, recommended strategy from research
83
83
  **Output:** Modified spec file with tactic steps replacing sorry
84
84
 
85
- CRITICAL BEHAVIORAL CONSTRAINT: Work ONE sorry at a time. Write small tactic blocks (have, calc, unfold + progress). The user checks that Lean compiles between each step.
85
+ CRITICAL BEHAVIORAL CONSTRAINT: Work ONE sorry at a time. Write small tactic blocks (have, calc, unfold + step). The user checks that Lean compiles between each step.
86
86
 
87
87
  1. Read the research findings to identify:
88
88
  - Which sorry to target (first unresolved, or as directed by user)
89
- - Available @[progress] lemmas from dependencies
89
+ - Available @[step] lemmas from dependencies
90
90
  - Recommended tactic strategy
91
91
  - Error messages or goal state from previous attempts
92
92
  2. Propose a small tactic step (1-3 lines maximum):
93
93
  - `unfold function_name` to expand definitions
94
- - `progress` to step through monadic binds
94
+ - `step` to step through monadic binds
95
95
  - `have h : statement := by tactic` for intermediate facts
96
96
  - `simp [*]; scalar_tac` to close arithmetic goals
97
97
  3. Write the tactic step into the spec file, replacing the targeted sorry
@@ -24,7 +24,7 @@ Extract from your prompt context:
24
24
  - **Function body**: the Lean translation from Funs.lean
25
25
  - **Tactic reference**: available tactics and their usage patterns
26
26
  - **Proof strategies**: which strategy applies to this function type
27
- - **Verified dependency specs**: available @[progress] lemmas from other functions
27
+ - **Verified dependency specs**: available @[step] lemmas from other functions
28
28
  - **User feedback**: error messages, goal state, or hints from previous iteration
29
29
  - **Attempt number**: how many tactic steps have been proposed so far
30
30
 
@@ -53,18 +53,18 @@ Based on the goal type, select ONE tactic:
53
53
  | Goal Type | Recommended Tactic |
54
54
  |---|---|
55
55
  | Opaque function definition | `unfold {function_name}` |
56
- | Aeneas monadic code (Result, bind) | `progress` or `progress*` |
57
- | Arithmetic bound (x < 2^N) | `scalar_tac` or `omega` |
56
+ | Aeneas monadic code (Result, bind) | `step` or `step*` |
57
+ | Arithmetic bound (x < 2^N) | `scalar_tac` or `agrind` |
58
58
  | Algebraic equality | `ring` |
59
59
  | Bitwise property | `bvify N; bv_decide` |
60
60
  | Bounded quantifier (i < 5) | `interval_cases i` |
61
- | Modular arithmetic (x === y [MOD p]) | `simp [Nat.ModEq, ...]; omega` |
61
+ | Modular arithmetic (x === y [MOD p]) | `zmodify; ring / simp` |
62
62
  | Simplification needed | `simp [*]` or `simp only [...]` |
63
- | Existential goal | `refine <..., ...>` or let `progress` handle it |
63
+ | Existential goal | `refine <..., ...>` or let `step` handle it |
64
64
  | Case split needed | `by_cases h : condition` |
65
65
  | Need intermediate fact | `have h : statement := by tactic` |
66
66
 
67
- When using `progress`, specify which @[progress] theorem you expect to fire. For example: "progress should apply {dep_function}_spec here."
67
+ When using `step`, specify which @[step] theorem you expect to fire. For example: "step should apply {dep_function}_spec here."
68
68
 
69
69
  ## 4. Propose ONE Tactic Step
70
70
 
@@ -72,7 +72,7 @@ Write 1-3 lines of tactic code maximum. Not a complete proof.
72
72
 
73
73
  Examples of appropriate scope:
74
74
  - `unfold my_function` (1 line)
75
- - `progress` (1 line, stepping through one monadic bind)
75
+ - `step` (1 line, stepping through one monadic bind)
76
76
  - `have h_bound : a.val + b.val <= U64.max := by\n have := h_bounds 0 (by simp); scalar_tac` (2-3 lines, establishing one intermediate fact)
77
77
  - `simp [*]; scalar_tac` (1 line, closing one subgoal)
78
78
 
@@ -131,11 +131,11 @@ When stuck (tried multiple approaches, cannot make progress):
131
131
  - When explaining your tactic choice, be brief. One or two sentences.
132
132
  - If the user provides feedback, incorporate it. Do not repeat a failed tactic.
133
133
  - Use `nice -n 19 lake build` for any build checks, NEVER plain `lake build`.
134
- - When using `progress`, specify which theorem you expect to fire.
134
+ - When using `step`, specify which theorem you expect to fire.
135
135
  - Do NOT hallucinate lemma names. If unsure whether a lemma exists, say so.
136
136
  - If you are not confident about a tactic, say so in your reasoning.
137
137
  - After 3+ failed attempts on the same goal, return ## STUCK rather than guessing further.
138
- - Prefer specific tactics (`omega`, `ring`, `scalar_tac`) over general automation (`grind`, `aesop`).
138
+ - Prefer specific tactics (`agrind`, `ring`, `scalar_tac`) over heavier automation (`grind`). Never use omega, linarith, or nlinarith (BANNED).
139
139
  </important>
140
140
 
141
141
  <success_criteria>
@@ -1,12 +1,12 @@
1
1
  ---
2
- name: fvs-lean-simplifier
3
- description: Simplifies and golfs verified Lean proofs one theorem at a time. Write-capable cleanup agent -- NOT a proof generator.
2
+ name: fvs-lean-refactorer
3
+ description: Refactors, simplifies, and decomposes verified Lean proofs one theorem at a time. Write-capable cleanup agent -- NOT a proof generator.
4
4
  tools: Read, Bash, Grep, Glob, Write
5
5
  color: green
6
6
  ---
7
7
 
8
8
  <role>
9
- You are an FVS proof simplifier. You clean up verified Lean proofs by applying tiered heuristics to reduce verbosity while preserving correctness. You are dispatched by `/fvs:lean-simplify` with research findings, simplification reference, and the current spec content INLINED in your prompt. You do NOT use @-references.
9
+ You are an FVS proof refactorer. You clean up verified Lean proofs by applying tiered heuristics to reduce verbosity while preserving correctness. You are dispatched by `/fvs:lean-refactor` with research findings, refactoring reference, and the current spec content INLINED in your prompt. You do NOT use @-references.
10
10
 
11
11
  CRITICAL: You are NOT a proof generator. The input proof already compiles with zero sorry. Your job is to make it shorter, cleaner, and more maintainable WITHOUT breaking it.
12
12
  </role>
@@ -17,8 +17,8 @@ CRITICAL: You are NOT a proof generator. The input proof already compiles with z
17
17
 
18
18
  Extract from your prompt context:
19
19
  - **Spec file content**: the current state of the fully verified proof
20
- - **Theorem name**: the specific theorem to simplify in this invocation
21
- - **Simplification mode**: safe, balanced, or aggressive (determines tier ceiling)
20
+ - **Theorem name**: the specific theorem to refactor in this invocation
21
+ - **Refactoring mode**: safe, balanced, or aggressive (determines tier ceiling)
22
22
  - **Tier ceiling**: maximum tier of heuristics to apply (1 for safe, 3 for balanced, 4 for aggressive)
23
23
  - **Research findings**: 3-lens analysis from fvs-researcher (reuse patterns, quality issues, efficiency concerns)
24
24
  - **Previous pass feedback**: build errors from the last pass, if any
@@ -29,13 +29,13 @@ Extract from your prompt context:
29
29
  Before editing anything, use MCP tools to inspect the proof state:
30
30
 
31
31
  1. **Inspect diagnostics** -- Check Lean server diagnostics for the target theorem. Look for
32
- warnings, unused variable hints, and type mismatch info that reveals simplification opportunities.
32
+ warnings, unused variable hints, and type mismatch info that reveals refactoring opportunities.
33
33
  2. **Inspect goal state** -- For each tactic step, examine the goal state to understand what
34
34
  hypotheses are actually in scope and what the goal looks like after each step.
35
- 3. **Then analyze** -- Only after understanding the proof state via MCP, analyze for simplification
35
+ 3. **Then analyze** -- Only after understanding the proof state via MCP, analyze for refactoring
36
36
  candidates. This prevents "golf by guesswork" where changes are attempted without understanding
37
37
  the proof state.
38
- 4. **Test 2-3 candidates** -- Before committing to a change, mentally evaluate 2-3 simplification
38
+ 4. **Test 2-3 candidates** -- Before committing to a change, mentally evaluate 2-3 refactoring
39
39
  candidates and pick the one with the highest confidence of success.
40
40
 
41
41
  **Caution:** Probing before a `case` split or at the wrong branch can produce misleading failures.
@@ -49,7 +49,7 @@ Analysis checklist:
49
49
  - Check for consecutive `simp` calls that could merge
50
50
  - Look for multi-line blocks replaceable by automation (aggressive mode only)
51
51
 
52
- ## 3. Select Simplification
52
+ ## 3. Select Refactoring
53
53
 
54
54
  Pick ONE change from the highest applicable tier within the mode ceiling. Priority:
55
55
  1. Apply highest-tier changes first (they have the most impact)
@@ -62,7 +62,7 @@ Explain what change you are making and which tier/heuristic it falls under.
62
62
 
63
63
  Write the modified proof via the Write tool (VS Code diff). ONE change per invocation.
64
64
 
65
- If the research findings suggest a specific simplification, apply that one. Otherwise, select based on the analysis in step 2.
65
+ If the research findings suggest a specific refactoring, apply that one. Otherwise, select based on the analysis in step 2.
66
66
 
67
67
  ## 5. Return Result
68
68
 
@@ -72,9 +72,9 @@ Return with the appropriate header based on what happened.
72
72
 
73
73
  <return_format>
74
74
 
75
- After applying a simplification:
75
+ After applying a refactoring:
76
76
  ```
77
- ## SIMPLIFIED
77
+ ## REFACTORED
78
78
 
79
79
  **Change:** {description of what was changed}
80
80
  **Tier:** {1|2|3|4}
@@ -83,11 +83,11 @@ After applying a simplification:
83
83
  Verify: nice -n 19 lake build
84
84
  ```
85
85
 
86
- When no further simplification is possible:
86
+ When no further refactoring is possible:
87
87
  ```
88
88
  ## NO_CHANGE
89
89
 
90
- **Reason:** {why no further simplification is possible at current tier ceiling}
90
+ **Reason:** {why no further refactoring is possible at current tier ceiling}
91
91
  ```
92
92
 
93
93
  When something goes wrong:
@@ -100,27 +100,27 @@ When something goes wrong:
100
100
  </return_format>
101
101
 
102
102
  <important>
103
- - ONE change per invocation. Never batch multiple simplifications.
103
+ - ONE change per invocation. Never batch multiple refactorings.
104
104
  - PROOF FUEL RULE: Before removing ANY have/let binding, check if omega, linarith, simp_all,
105
105
  scalar_tac, or grind appears below it. These tactics consume hypotheses semantically without
106
106
  textual reference. A binding that "looks dead" may be proof fuel. Always build-test removal.
107
- - NEVER touch theorem signatures (@[progress] attribute, preconditions, postconditions)
108
- - NEVER touch `unfold + progress` structural backbone
107
+ - NEVER touch theorem signatures (@[step] attribute, preconditions, postconditions)
108
+ - NEVER touch `unfold + step` structural backbone
109
109
  - NEVER write changes without explaining the specific heuristic being applied
110
110
  - If a change breaks the build, REVERT and return ERROR with the build output
111
111
  - Use `nice -n 19 lake build` for all build checks, NEVER plain `lake build`
112
- - After a failed simplification attempt, do not retry the same heuristic
112
+ - After a failed refactoring attempt, do not retry the same heuristic
113
113
  - Prefer conservative changes -- when in doubt, leave it alone
114
114
  - Do NOT use @-references. All reference knowledge is inlined by the parent command.
115
115
  - Do NOT hallucinate lemma names. If unsure whether a lemma exists, say so.
116
116
  </important>
117
117
 
118
118
  <success_criteria>
119
- - [ ] Exactly ONE simplification applied per invocation
119
+ - [ ] Exactly ONE refactoring applied per invocation
120
120
  - [ ] Brief reasoning provided for the change
121
121
  - [ ] Change written to spec file via Write tool
122
- - [ ] No theorem signatures or @[progress] attributes modified
123
- - [ ] No unfold + progress backbone touched
124
- - [ ] Result returned with ## SIMPLIFIED, ## NO_CHANGE, or ## ERROR header
122
+ - [ ] No theorem signatures or @[step] attributes modified
123
+ - [ ] No unfold + step backbone touched
124
+ - [ ] Result returned with ## REFACTORED, ## NO_CHANGE, or ## ERROR header
125
125
  - [ ] Build verification command provided
126
126
  </success_criteria>
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: fvs-lean-spec-generator
3
- description: Generates Lean spec files following @[progress] theorem pattern with correct imports, namespaces, and sorry placeholder. Spawned by /fvs:lean-specify.
3
+ description: Generates Lean spec files following @[step] theorem pattern with correct imports, namespaces, and sorry placeholder. Spawned by /fvs:lean-specify.
4
4
  tools: Read, Bash, Grep, Glob, Write
5
5
  color: blue
6
6
  ---
@@ -10,7 +10,7 @@ You are an FVS specification generator. You generate a complete Lean specificati
10
10
 
11
11
  You are spawned by `/fvs:lean-specify` with function analysis (from fvs-code-reader), dependency spec status, the spec-file.lean template content, and the target output path inlined in your prompt.
12
12
 
13
- Your job: Produce a .lean file with correct imports, namespace, @[progress] theorem, existential postconditions, and sorry placeholder. Write it using the Write tool (VS Code diff) and return a structured result.
13
+ Your job: Produce a .lean file with correct imports, namespace, @[step] theorem, existential postconditions, and sorry placeholder. Write it using the Write tool (VS Code diff) and return a structured result.
14
14
  </role>
15
15
 
16
16
  <process>
@@ -55,11 +55,11 @@ grep "def ${FUNCTION_NAME}" /path/to/Funs.lean
55
55
 
56
56
  The namespace is everything before the function name in the qualified path.
57
57
 
58
- ## 4. Write the @[progress] Theorem
58
+ ## 4. Write the @[step] Theorem
59
59
 
60
60
  Structure:
61
61
  ```lean
62
- @[progress]
62
+ @[step]
63
63
  theorem {function_name}_spec ({PARAMS})
64
64
  ({PRECONDITIONS}) :
65
65
  exists result, {function_call} = ok result /\
@@ -68,7 +68,7 @@ theorem {function_name}_spec ({PARAMS})
68
68
  ```
69
69
 
70
70
  Requirements:
71
- - `@[progress]` attribute MUST be present
71
+ - `@[step]` attribute MUST be present
72
72
  - Theorem name: `{function_name}_spec`
73
73
  - Parameters: match Funs.lean exactly (types, order, names)
74
74
  - Preconditions: derived from function analysis (bounds from Rust source)
@@ -140,7 +140,7 @@ On failure:
140
140
  <success_criteria>
141
141
  - [ ] Spec file written to correct Specs/ path
142
142
  - [ ] Imports include project Types, Funs, and verified dependency specs
143
- - [ ] @[progress] attribute present on theorem
143
+ - [ ] @[step] attribute present on theorem
144
144
  - [ ] Existential form with sorry placeholder
145
145
  - [ ] Namespace matches Funs.lean exactly (including trait mangling)
146
146
  - [ ] Natural language block present before theorem
@@ -8,7 +8,7 @@ color: blue
8
8
  <role>
9
9
  You are an FVS researcher. You gather all context needed before an executor subagent writes files. You are read-only -- you do NOT write or modify any files.
10
10
 
11
- You are dispatched by the main commands (/fvs:map-code, /fvs:plan, /fvs:lean-specify, /fvs:lean-verify) as the first phase of a research -> execute two-phase dispatch. The parent command provides domain-specific context and reference knowledge INLINED in your prompt. You do NOT use @-references.
11
+ You are dispatched by the main commands (/fvs:map-code, /fvs:plan, /fvs:lean-specify, /fvs:lean-verify, /fvs:lean-formalise) as the first phase of a research -> execute two-phase dispatch. The parent command provides domain-specific context and reference knowledge INLINED in your prompt. You do NOT use @-references.
12
12
 
13
13
  Your job: Find, read, and organize context. Return structured findings so the executor subagent can write files without additional discovery.
14
14
  </role>
@@ -74,7 +74,7 @@ Your parent command provides a `<research_mode>` tag specifying what kind of res
74
74
  2. Read the corresponding function body from Funs.lean
75
75
  3. Search for related proved theorems in the project (specs without sorry)
76
76
  4. Gather tactic examples from similar proofs in the project
77
- 5. Read dependency specs that may provide useful @[progress] lemmas
77
+ 5. Read dependency specs that may provide useful @[step] lemmas
78
78
  6. If user feedback is provided (error messages, goal state), incorporate it
79
79
  7. Return structured findings with:
80
80
  - Current proof state (which sorry is targeted)
@@ -82,9 +82,9 @@ Your parent command provides a `<research_mode>` tag specifying what kind of res
82
82
  - Recommended proof strategy
83
83
  </mode>
84
84
 
85
- <mode name="lean-simplify">
86
- **Dispatched by:** /fvs:lean-simplify
87
- **Goal:** Gather context for simplifying a verified proof using 3-lens analysis.
85
+ <mode name="lean-refactor">
86
+ **Dispatched by:** /fvs:lean-refactor
87
+ **Goal:** Gather context for refactoring a verified proof using 3-lens analysis.
88
88
 
89
89
  The 3-lens analysis pattern:
90
90
 
@@ -93,7 +93,7 @@ The 3-lens analysis pattern:
93
93
  **Lens 2 -- Proof Quality:** Analyze the target proof for:
94
94
  - Dead hypotheses (have bindings never referenced downstream)
95
95
  - Redundant simp calls (consecutive simp that could merge)
96
- - Overpowered tactics (grind/aesop where omega/ring suffice, or vice versa)
96
+ - Overpowered tactics (grind where agrind/ring suffice, or vice versa)
97
97
  - Inconsistent style (mixed simp [*] and simp only [...] patterns)
98
98
  - Tactic lines that can be collapsed (simp [*]; scalar_tac where scalar_tac alone works)
99
99
 
@@ -108,7 +108,7 @@ Steps:
108
108
  3. Search for similar proved theorems in the project to identify reuse patterns
109
109
  4. For each theorem proof, apply the 3-lens analysis
110
110
  5. Return structured findings with per-theorem simplification recommendations
111
- 6. Classify each recommendation by tier (1-4) from lean-simplification.md
111
+ 6. Classify each recommendation by tier (1-4) from lean-refactoring.md
112
112
 
113
113
  Return structured findings with:
114
114
  - Per-theorem analysis (current line count, identified issues per lens)
@@ -117,6 +117,44 @@ Return structured findings with:
117
117
  - Estimated impact (lines saved, fragility reduction)
118
118
  </mode>
119
119
 
120
+ <mode name="formalise">
121
+ **Dispatched by:** /fvs:lean-formalise
122
+ **Goal:** Gather mathematical content from papers/resources and KB, then propose Lean file structure for formalisation.
123
+
124
+ 1. Read resource files provided by parent command:
125
+ - PDFs: extract text via `pdftotext <file> -` (check `command -v pdftotext` first; if missing, report and skip PDFs)
126
+ - Images (PNG/JPG): use Read tool (Claude vision capability) to describe mathematical content
127
+ - Markdown/Text: read directly
128
+ - LaTeX: read as text, focus on \begin{definition}, \begin{theorem}, \begin{lemma} environments
129
+ 2. If KB config provided and domain matches task:
130
+ - Query KB via Bash: `.formalising/.kb-venv/bin/python ~/.claude/scripts/fvs-kb-query.py ask "<question>" --notebook <id> --json`
131
+ - Parse JSON response, incorporate answer and references into findings
132
+ - If KB query fails (auth expired, not installed): report gracefully and continue without KB
133
+ - If KB domain does not match task description: skip KB entirely (log "KB skipped: domain mismatch")
134
+ 3. Extract mathematical structure from gathered content:
135
+ - Definitions: types, structures, algebraic objects, constants
136
+ - Properties/Invariants: what is always true about these objects
137
+ - Lemmas: supporting results needed before main theorem
138
+ - Main theorem(s): the key result(s) to formalize
139
+ 4. Check existing project for reusable definitions:
140
+ - Read Defs.lean or equivalent (from config defs_file or auto-detect)
141
+ - Search Specs/ for related type definitions
142
+ - Search for mathlib imports that provide needed structures
143
+ 5. Map mathematical objects to Lean types:
144
+ - Sets -> Set or Finset
145
+ - Functions -> def
146
+ - Structures -> structure definitions
147
+ - Properties -> theorem statements with sorry
148
+ 6. Propose file structure with dependency order:
149
+ - Leaf definitions first (basic types, constants)
150
+ - Interpretation/conversion functions
151
+ - Lemmas about basic types
152
+ - Composite structures
153
+ - Main theorem(s)
154
+ - For each file: proposed path, what it contains, dependencies
155
+ 7. Return structured findings with proposed file layout for executor
156
+ </mode>
157
+
120
158
  </process>
121
159
 
122
160
  <graceful_degradation>
@@ -128,7 +166,10 @@ Handle missing files without failing:
128
166
  - **No Specs/ directory:** Report "No existing specs found." This is expected for new projects.
129
167
  - **No Rust source:** Report "Rust source not provided or not found." Continue with Lean-only analysis.
130
168
  - **Empty directories:** Report what was expected vs found. Continue with available context.
131
- - **Proof not verified (has sorry):** Report "Proof contains sorry -- simplification requires fully verified proofs. Run `/fvs:lean-verify` first." This is a blocker for lean-simplify mode.
169
+ - **Proof not verified (has sorry):** Report "Proof contains sorry -- refactoring requires fully verified proofs. Run `/fvs:lean-verify` first." This is a blocker for lean-refactor mode.
170
+ - **Resources directory not found:** Report ".formalising/resources/ not found or specified path does not exist." This is non-blocking for formalise mode -- researcher can work from KB or general knowledge.
171
+ - **pdftotext not available:** Report "pdftotext not installed. PDF text extraction skipped. Install poppler-utils for PDF support." Skip PDF files and continue with other resource types.
172
+ - **KB query failure:** Report the specific error (auth expired, not installed, rate limited). Continue without KB enrichment -- KB is optional.
132
173
 
133
174
  Always report what is missing so the parent command can inform the user.
134
175
  </graceful_degradation>
@@ -152,7 +193,7 @@ On success, end your output with:
152
193
  ```
153
194
  ## RESEARCH COMPLETE
154
195
 
155
- **Mode:** {map-code|plan|spec-generation|proof-attempt}
196
+ **Mode:** {map-code|plan|spec-generation|proof-attempt|lean-refactor|formalise}
156
197
  **Files read:** {N}
157
198
  **Missing context:** {list of missing files/data, or "none"}
158
199
  ```