invar-tools 1.3.0__py3-none-any.whl → 1.3.2__py3-none-any.whl

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 (30) hide show
  1. invar/shell/claude_hooks.py +387 -0
  2. invar/shell/commands/guard.py +2 -0
  3. invar/shell/commands/hooks.py +74 -0
  4. invar/shell/commands/init.py +30 -0
  5. invar/shell/commands/template_sync.py +42 -11
  6. invar/shell/commands/test.py +1 -1
  7. invar/shell/templates.py +2 -2
  8. invar/templates/CLAUDE.md.template +25 -5
  9. invar/templates/config/CLAUDE.md.jinja +16 -0
  10. invar/templates/config/context.md.jinja +11 -6
  11. invar/templates/context.md.template +35 -18
  12. invar/templates/hooks/PostToolUse.sh.jinja +102 -0
  13. invar/templates/hooks/PreToolUse.sh.jinja +74 -0
  14. invar/templates/hooks/Stop.sh.jinja +23 -0
  15. invar/templates/hooks/UserPromptSubmit.sh.jinja +77 -0
  16. invar/templates/hooks/__init__.py +1 -0
  17. invar/templates/manifest.toml +2 -2
  18. invar/templates/protocol/INVAR.md +105 -6
  19. invar/templates/skills/develop/SKILL.md.jinja +4 -7
  20. invar/templates/skills/investigate/SKILL.md.jinja +4 -7
  21. invar/templates/skills/propose/SKILL.md.jinja +4 -7
  22. invar/templates/skills/review/SKILL.md.jinja +63 -15
  23. invar_tools-1.3.2.dist-info/METADATA +505 -0
  24. {invar_tools-1.3.0.dist-info → invar_tools-1.3.2.dist-info}/RECORD +29 -22
  25. invar_tools-1.3.0.dist-info/METADATA +0 -377
  26. {invar_tools-1.3.0.dist-info → invar_tools-1.3.2.dist-info}/WHEEL +0 -0
  27. {invar_tools-1.3.0.dist-info → invar_tools-1.3.2.dist-info}/entry_points.txt +0 -0
  28. {invar_tools-1.3.0.dist-info → invar_tools-1.3.2.dist-info}/licenses/LICENSE +0 -0
  29. {invar_tools-1.3.0.dist-info → invar_tools-1.3.2.dist-info}/licenses/LICENSE-GPL +0 -0
  30. {invar_tools-1.3.0.dist-info → invar_tools-1.3.2.dist-info}/licenses/NOTICE +0 -0
@@ -1,13 +1,11 @@
1
- <!--invar:skill version="{{ version }}"-->
2
- <!-- ========================================================================
3
- SKILL REGION - DO NOT EDIT
4
- This section is managed by Invar and will be overwritten on update.
5
- To add project-specific extensions, use the "extensions" region below.
6
- ======================================================================== -->
7
1
  ---
8
2
  name: propose
9
3
  description: Decision facilitation phase. Use when design decision is needed, multiple approaches are valid, or user asks "should we", "how should", "which", "compare", "design", "architect". Presents options with trade-offs for human choice.
4
+ _invar:
5
+ version: "{{ version }}"
6
+ managed: skill
10
7
  ---
8
+ <!--invar:skill-->
11
9
 
12
10
  # Proposal Mode
13
11
 
@@ -89,7 +87,6 @@ Create `docs/proposals/DX-XX-[topic].md`:
89
87
  | Needs more info | /investigate for analysis |
90
88
  | Approves proposal | Document created |
91
89
  <!--/invar:skill-->
92
-
93
90
  <!--invar:extensions-->
94
91
  <!-- ========================================================================
95
92
  EXTENSIONS REGION - USER EDITABLE
@@ -1,19 +1,30 @@
1
- <!--invar:skill version="{{ version }}"-->
2
- <!-- ========================================================================
3
- SKILL REGION - DO NOT EDIT
4
- This section is managed by Invar and will be overwritten on update.
5
- To add project-specific extensions, use the "extensions" region below.
6
- ======================================================================== -->
7
1
  ---
8
2
  name: review
9
3
  description: Adversarial code review with fix loop. Use after development, when Guard reports review_suggested, or user explicitly requests review. Finds issues that automated verification misses. Supports isolated mode (sub-agent) and quick mode (same context).
4
+ _invar:
5
+ version: "{{ version }}"
6
+ managed: skill
10
7
  ---
8
+ <!--invar:skill-->
11
9
 
12
10
  # Review Mode
13
11
 
14
12
  > **Purpose:** Find problems that Guard, doctests, and property tests missed.
15
13
  > **Mindset:** Adversarial. Your success is measured by problems found, not code approved.
16
14
 
15
+ ## Adversarial Reviewer Persona
16
+
17
+ Assume:
18
+ - The code has bugs until proven otherwise
19
+ - The contracts may be meaningless ceremony
20
+ - The implementer may have rationalized poor decisions
21
+ - Escape hatches may be abused
22
+
23
+ You ARE here to:
24
+ - Find bugs, logic errors, edge cases
25
+ - Challenge whether contracts have semantic value
26
+ - Check if code matches contracts (not if code "seems right")
27
+
17
28
  ## Entry Actions
18
29
 
19
30
  ### Context Refresh (DX-54)
@@ -50,23 +61,61 @@ WARNING: review_suggested - Low contract coverage
50
61
 
51
62
  ## Review Checklist
52
63
 
64
+ > **Principle:** Only items requiring semantic judgment. Mechanical checks are handled by Guard.
65
+
53
66
  ### A. Contract Semantic Value
54
67
  - [ ] Does @pre constrain inputs beyond type checking?
68
+ - Bad: `@pre(lambda x: isinstance(x, int))`
69
+ - Good: `@pre(lambda x: x > 0 and x < MAX_VALUE)`
55
70
  - [ ] Does @post verify meaningful output properties?
71
+ - Bad: `@post(lambda result: result is not None)`
72
+ - Good: `@post(lambda result: len(result) == len(input))`
56
73
  - [ ] Could someone implement correctly from contracts alone?
74
+ - [ ] Are boundary conditions explicit in contracts?
57
75
 
58
- ### B. Logic Verification
59
- - [ ] Do contracts correctly capture intended behavior?
60
- - [ ] Are there paths bypassing contract checks?
61
- - [ ] Is there dead code or unreachable branches?
76
+ ### B. Doctest Coverage
77
+ - [ ] Do doctests cover normal cases?
78
+ - [ ] Do doctests cover boundary cases?
79
+ - [ ] Do doctests cover error cases?
80
+ - [ ] Are doctests testing behavior, not just syntax?
62
81
 
63
- ### C. Escape Hatch Audit
82
+ ### C. Code Quality
83
+ - [ ] Is duplicated code worth extracting?
84
+ - [ ] Is naming consistent and clear?
85
+ - [ ] Is complexity justified?
86
+
87
+ ### D. Escape Hatch Audit
64
88
  - [ ] Is each @invar:allow justification valid?
65
89
  - [ ] Could refactoring eliminate the need?
90
+ - [ ] Is there a pattern suggesting systematic issues?
91
+
92
+ ### E. Logic Verification
93
+ - [ ] Do contracts correctly capture intended behavior?
94
+ - [ ] Are there paths that bypass contract checks?
95
+ - [ ] Are there implicit assumptions not in contracts?
96
+ - [ ] Is there dead code or unreachable branches?
66
97
 
67
- ### D. Security (if applicable)
68
- - [ ] Input validation against injection, XSS?
69
- - [ ] No hardcoded secrets?
98
+ ### F. Security
99
+ - [ ] Are inputs validated against security threats (injection, XSS)?
100
+ - [ ] No hardcoded secrets (API keys, passwords, tokens)?
101
+ - [ ] Are authentication/authorization checks correct?
102
+ - [ ] Is sensitive data properly protected?
103
+
104
+ ### G. Error Handling & Observability
105
+ - [ ] Are exceptions caught at appropriate level?
106
+ - [ ] Are error messages clear without leaking sensitive info?
107
+ - [ ] Are critical operations logged for debugging?
108
+ - [ ] Is there graceful degradation on failure?
109
+
110
+ ## Excluded (Covered by Guard)
111
+
112
+ These are checked by Guard or linters - don't duplicate:
113
+ - Core/Shell separation → Guard (forbidden_import, impure_call)
114
+ - Shell returns Result[T,E] → Guard (shell_result)
115
+ - Missing contracts → Guard (missing_contract)
116
+ - File/function size limits → Guard (file_size, function_size)
117
+ - Entry point thickness → Guard (entry_point_too_thick)
118
+ - Escape hatch count → Guard (review_suggested)
70
119
 
71
120
  ## Review-Fix Loop
72
121
 
@@ -110,7 +159,6 @@ Convergence check:
110
159
  - [ ] Needs more work: [issues]
111
160
  ```
112
161
  <!--/invar:skill-->
113
-
114
162
  <!--invar:extensions-->
115
163
  <!-- ========================================================================
116
164
  EXTENSIONS REGION - USER EDITABLE
@@ -0,0 +1,505 @@
1
+ Metadata-Version: 2.4
2
+ Name: invar-tools
3
+ Version: 1.3.2
4
+ Summary: AI-native software engineering tools with design-by-contract verification
5
+ Project-URL: Homepage, https://github.com/tefx/invar
6
+ Project-URL: Documentation, https://github.com/tefx/invar#readme
7
+ Project-URL: Repository, https://github.com/tefx/invar
8
+ Project-URL: Issues, https://github.com/tefx/invar/issues
9
+ Author: Invar Team
10
+ License-Expression: GPL-3.0-or-later
11
+ License-File: LICENSE
12
+ License-File: LICENSE-GPL
13
+ License-File: NOTICE
14
+ Keywords: ai,code-quality,contracts,design-by-contract,static-analysis
15
+ Classifier: Development Status :: 3 - Alpha
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Quality Assurance
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: crosshair-tool>=0.0.60
25
+ Requires-Dist: hypothesis>=6.0
26
+ Requires-Dist: invar-runtime>=1.0
27
+ Requires-Dist: jinja2>=3.0
28
+ Requires-Dist: mcp>=1.0
29
+ Requires-Dist: pre-commit>=3.0
30
+ Requires-Dist: pydantic>=2.0
31
+ Requires-Dist: returns>=0.20
32
+ Requires-Dist: rich>=13.0
33
+ Requires-Dist: typer>=0.9
34
+ Provides-Extra: dev
35
+ Requires-Dist: coverage[toml]>=7.0; extra == 'dev'
36
+ Requires-Dist: mypy>=1.0; extra == 'dev'
37
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
38
+ Requires-Dist: pytest>=7.0; extra == 'dev'
39
+ Requires-Dist: ruff>=0.1; extra == 'dev'
40
+ Description-Content-Type: text/markdown
41
+
42
+ <p align="center">
43
+ <img src="docs/logo.svg" alt="Invar Logo" width="128" height="128">
44
+ </p>
45
+
46
+ <h1 align="center">Invar</h1>
47
+
48
+ <p align="center">
49
+ <strong>From AI-generated to AI-engineered code.</strong>
50
+ </p>
51
+
52
+ <p align="center">
53
+ Invar brings decades of software engineering best practices to AI-assisted development.<br>
54
+ Through automated verification, structured workflows, and proven design patterns,<br>
55
+ agents write code that's correct by construction—not by accident.
56
+ </p>
57
+
58
+ <p align="center">
59
+ <a href="https://badge.fury.io/py/invar-tools"><img src="https://badge.fury.io/py/invar-tools.svg" alt="PyPI version"></a>
60
+ <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.11+-blue.svg" alt="Python 3.11+"></a>
61
+ <a href="#license"><img src="https://img.shields.io/badge/License-Apache%202.0%20%2B%20GPL--3.0-blue.svg" alt="License"></a>
62
+ </p>
63
+
64
+ ### What It Looks Like
65
+
66
+ An AI agent, guided by Invar, writes code with formal contracts and built-in tests:
67
+
68
+ ```python
69
+ from invar_runtime import pre, post
70
+
71
+ @pre(lambda items: len(items) > 0)
72
+ @post(lambda result: result >= 0)
73
+ def average(items: list[float]) -> float:
74
+ """
75
+ Calculate the average of a non-empty list.
76
+
77
+ >>> average([1.0, 2.0, 3.0])
78
+ 2.0
79
+ >>> average([10.0])
80
+ 10.0
81
+ """
82
+ return sum(items) / len(items)
83
+ ```
84
+
85
+ Invar's Guard automatically verifies the code—the agent sees results and fixes issues without human intervention:
86
+
87
+ ```
88
+ $ invar guard
89
+ Invar Guard Report
90
+ ========================================
91
+ No violations found.
92
+ ----------------------------------------
93
+ Files checked: 1 | Errors: 0 | Warnings: 0
94
+ Contract coverage: 100% (1/1 functions)
95
+
96
+ Code Health: 100% ████████████████████ (Excellent)
97
+ ✓ Doctests passed
98
+ ✓ CrossHair: no counterexamples found
99
+ ✓ Hypothesis: property tests passed
100
+ ----------------------------------------
101
+ Guard passed.
102
+ ```
103
+
104
+ ---
105
+
106
+ ## 🚀 Quick Start
107
+
108
+ ### 📦 Two Packages, Different Purposes
109
+
110
+ ```
111
+ ┌───────────────────────────────────────────────────────────────────┐
112
+ │ Your Project │
113
+ │ ├── pyproject.toml │
114
+ │ │ └── dependencies = ["invar-runtime"] ← Ships with code │
115
+ │ │ │
116
+ │ └── Development (never enters production) │
117
+ │ └── uvx --from invar-tools invar guard ← Guides agents │
118
+ └───────────────────────────────────────────────────────────────────┘
119
+ ```
120
+
121
+ | Package | Purpose | Install |
122
+ |---------|---------|---------|
123
+ | **invar-runtime** | Runtime contracts. Add to your project dependencies. | `pip install invar-runtime` |
124
+ | **invar-tools** | Development tools. Guides agents during development. | `uvx --from invar-tools invar <cmd>` |
125
+
126
+ **Why uvx?** Always uses latest version, doesn't pollute project dependencies, auto-detects your project's venv.
127
+
128
+ ### 🆕 New Project
129
+
130
+ ```bash
131
+ # 1. Initialize with Claude Code (full experience)
132
+ uvx --from invar-tools invar init --claude
133
+
134
+ # 2. Add runtime contracts to your project
135
+ pip install invar-runtime
136
+ # Or add to pyproject.toml: dependencies = ["invar-runtime"]
137
+
138
+ # 3. Start coding with AI
139
+ ```
140
+
141
+ ### 📁 Existing Project
142
+
143
+ ```bash
144
+ # Update managed files, preserve your customizations
145
+ uvx --from invar-tools invar init --claude
146
+
147
+ # Or without Claude Code integration
148
+ uvx --from invar-tools invar init
149
+ ```
150
+
151
+ Invar's init is idempotent—safe to run multiple times. It detects existing configuration and updates only managed regions.
152
+
153
+ ### 💬 Example Interaction
154
+
155
+ **You say:**
156
+ > "Add a function that calculates compound interest with validation"
157
+
158
+ **Agent responds (automatically guided by Invar):**
159
+
160
+ ```
161
+ ✓ Check-In: my-project | main | clean
162
+
163
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
164
+ 📍 /develop → SPECIFY (2/4)
165
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
166
+
167
+ First, I'll define the contract:
168
+
169
+ @pre(lambda principal, rate, years: principal > 0 and rate >= 0 and years > 0)
170
+ @post(lambda result: result >= principal)
171
+ def compound_interest(principal: float, rate: float, years: int) -> float:
172
+ ...
173
+
174
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
175
+ 📍 /develop → VALIDATE (4/4)
176
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
177
+
178
+ $ invar guard --changed
179
+ WARN: missing doctest example (compound_interest)
180
+
181
+ [Agent adds doctest, re-runs guard]
182
+
183
+ $ invar guard --changed
184
+ Guard passed. (1 file, 0 errors)
185
+
186
+ ✓ Final: guard PASS | 0 errors, 0 warnings
187
+ ```
188
+
189
+ **Key insight:** The agent verifies and fixes automatically. You review the result, not the process.
190
+
191
+ ---
192
+
193
+ ## Why Invar?
194
+
195
+ ### ⚠️ The Problem: Unconstrained AI = Unpredictable Quality
196
+
197
+ Without guardrails, AI-generated code has systematic risks:
198
+ - **No specification** → Agent guesses intent, misses edge cases
199
+ - **No feedback loop** → Errors accumulate undetected
200
+ - **No workflow** → Jumps to implementation, skips validation
201
+ - **No separation** → I/O mixed with logic, code becomes untestable
202
+
203
+ Invar addresses each from the ground up.
204
+
205
+ ### ✅ Solution 1: Contracts as Specification
206
+
207
+ Contracts (`@pre`/`@post`) turn vague intent into verifiable specifications:
208
+
209
+ ```python
210
+ # Without contracts: "calculate average" is ambiguous
211
+ def average(items):
212
+ return sum(items) / len(items) # What if empty? What's the return type?
213
+
214
+ # With contracts: specification is explicit and verifiable
215
+ @pre(lambda items: len(items) > 0) # Precondition: non-empty input
216
+ @post(lambda result: result >= 0) # Postcondition: non-negative output
217
+ def average(items: list[float]) -> float:
218
+ """
219
+ >>> average([1.0, 2.0, 3.0])
220
+ 2.0
221
+ """
222
+ return sum(items) / len(items)
223
+ ```
224
+
225
+ **Benefits:**
226
+ - Agent knows exactly what to implement
227
+ - Edge cases are explicit in the contract
228
+ - Verification is automatic, not manual review
229
+
230
+ ### ✅ Solution 2: Multi-Layer Verification
231
+
232
+ Guard provides fast feedback. Agent sees errors, fixes immediately:
233
+
234
+ | Layer | Tool | Speed | What It Catches |
235
+ |-------|------|-------|-----------------|
236
+ | **Static** | Guard rules | ~0.5s | Architecture violations, missing contracts |
237
+ | **Doctest** | pytest | ~2s | Example correctness |
238
+ | **Property** | Hypothesis | ~10s | Edge cases via random inputs |
239
+ | **Symbolic** | CrossHair | ~30s | Mathematical proof of contracts |
240
+
241
+ ```
242
+ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
243
+ │ ⚡ Static │ → │ 🧪 Doctest│ → │ 🎲 Property│ → │ 🔬 Symbolic│
244
+ │ ~0.5s │ │ ~2s │ │ ~10s │ │ ~30s │
245
+ └──────────┘ └──────────┘ └──────────┘ └──────────┘
246
+ ```
247
+
248
+ ```
249
+ Agent writes code
250
+
251
+ invar guard ←──────┐
252
+ ↓ │
253
+ Error found? │
254
+ ↓ Yes │
255
+ Agent fixes ────────┘
256
+ ↓ No
257
+ Done ✓
258
+ ```
259
+
260
+ ### ✅ Solution 3: Workflow Discipline
261
+
262
+ The USBV workflow forces "specify before implement":
263
+
264
+ ```
265
+ 🔍 Understand → 📝 Specify → 🔨 Build → ✓ Validate
266
+ │ │ │ │
267
+ Context Contracts Code Guard
268
+ ```
269
+
270
+ Skill routing ensures agents enter through the correct workflow:
271
+
272
+ | User Intent | Skill Invoked | Behavior |
273
+ |-------------|---------------|----------|
274
+ | "why does X fail?" | `/investigate` | Research only, no code changes |
275
+ | "should we use A or B?" | `/propose` | Present options with trade-offs |
276
+ | "add feature X" | `/develop` | Full USBV workflow |
277
+ | (after develop) | `/review` | Adversarial review with fix loop |
278
+
279
+ ### ✅ Solution 4: Architecture Constraints
280
+
281
+ | Pattern | Enforcement | Benefit |
282
+ |---------|-------------|---------|
283
+ | **Core/Shell** | Guard blocks I/O imports in Core | 100% testable business logic |
284
+ | **Result[T, E]** | Guard warns if Shell returns bare values | Explicit error handling |
285
+
286
+ ### 🔮 Future: Quality Guidance (DX-61)
287
+
288
+ Beyond "correct or not"—Invar will suggest improvements:
289
+
290
+ ```
291
+ SUGGEST: 3 string parameters in 'find_symbol'
292
+ → Consider NewType for semantic clarity
293
+ ```
294
+
295
+ From gatekeeper to mentor.
296
+
297
+ ---
298
+
299
+ ## 🏗️ Core Concepts
300
+
301
+ ### Core/Shell Architecture
302
+
303
+ Separate pure logic from I/O for maximum testability:
304
+
305
+ | Zone | Location | Requirements |
306
+ |------|----------|--------------|
307
+ | **Core** | `**/core/**` | `@pre`/`@post` contracts, doctests, no I/O imports |
308
+ | **Shell** | `**/shell/**` | `Result[T, E]` return types |
309
+
310
+ ```
311
+ ┌─────────────────────────────────────────────┐
312
+ │ 🐚 Shell (I/O Layer) │
313
+ │ load_config, save_result, fetch_data │
314
+ └──────────────────┬──────────────────────────┘
315
+
316
+
317
+ ┌─────────────────────────────────────────────┐
318
+ │ 💎 Core (Pure Logic) │
319
+ │ parse_config, validate, calculate │
320
+ └──────────────────┬──────────────────────────┘
321
+
322
+ ▼ Result[T, E]
323
+ ```
324
+
325
+ ```python
326
+ # Core: Pure, testable, provable
327
+ def parse_config(content: str) -> Config:
328
+ return Config.parse(content)
329
+
330
+ # Shell: Handles I/O, returns Result
331
+ def load_config(path: Path) -> Result[Config, str]:
332
+ try:
333
+ return Success(parse_config(path.read_text()))
334
+ except FileNotFoundError:
335
+ return Failure(f"Not found: {path}")
336
+ ```
337
+
338
+ ### Session Protocol
339
+
340
+ Clear boundaries for every AI session:
341
+
342
+ | Phase | Format | Purpose |
343
+ |-------|--------|---------|
344
+ | **Start** | `✓ Check-In: project \| branch \| status` | Context visibility |
345
+ | **End** | `✓ Final: guard PASS \| 0 errors` | Verification proof |
346
+
347
+ ### Intellectual Heritage
348
+
349
+ **Foundational Theory:**
350
+ Design-by-Contract (Meyer, 1986) ·
351
+ Functional Core/Imperative Shell (Bernhardt) ·
352
+ Property-Based Testing (QuickCheck, 2000) ·
353
+ Symbolic Execution (King, 1976)
354
+
355
+ **Inspired By:**
356
+ Eiffel · Dafny · Idris · Haskell
357
+
358
+ **AI Programming Research:**
359
+ AlphaCodium · Parsel · Reflexion · Clover
360
+
361
+ **Dependencies:**
362
+ [deal](https://github.com/life4/deal) ·
363
+ [returns](https://github.com/dry-python/returns) ·
364
+ [CrossHair](https://github.com/pschanely/CrossHair) ·
365
+ [Hypothesis](https://hypothesis.readthedocs.io/)
366
+
367
+ ---
368
+
369
+ ## 🖥️ Platform Experience
370
+
371
+ | Feature | Claude Code | Other Editors |
372
+ |---------|-------------|---------------|
373
+ | CLI verification (`invar guard`) | ✅ | ✅ |
374
+ | Protocol document (INVAR.md) | ✅ | ✅ |
375
+ | MCP tool integration | ✅ Auto-configured | Manual setup possible |
376
+ | Workflow skills | ✅ Auto-configured | Include in system prompt |
377
+ | Pre-commit hooks | ✅ | ✅ |
378
+ | Sub-agent review | ✅ | — |
379
+
380
+ **Claude Code** provides the full experience—MCP tools, skill routing, and hooks are auto-configured by `invar init --claude`.
381
+
382
+ **Other editors** can achieve similar results by:
383
+ 1. Adding INVAR.md content to system prompts
384
+ 2. Manually configuring MCP servers (if supported)
385
+ 3. Using CLI commands for verification
386
+
387
+ ---
388
+
389
+ ## 📂 What Gets Installed
390
+
391
+ `invar init --claude` creates:
392
+
393
+ | File/Directory | Purpose | Editable? |
394
+ |----------------|---------|-----------|
395
+ | `INVAR.md` | Protocol for AI agents | No (managed) |
396
+ | `CLAUDE.md` | Project configuration | Yes |
397
+ | `.claude/skills/` | Workflow skills | Yes |
398
+ | `.claude/hooks/` | Tool call interception | Yes |
399
+ | `.invar/examples/` | Reference patterns | No (managed) |
400
+ | `.invar/context.md` | Project state, lessons | Yes |
401
+ | `pyproject.toml` | `[tool.invar]` section | Yes |
402
+
403
+ **Recommended structure:**
404
+
405
+ ```
406
+ src/{project}/
407
+ ├── core/ # Pure logic (@pre/@post, doctests, no I/O)
408
+ └── shell/ # I/O operations (Result[T, E] returns)
409
+ ```
410
+
411
+ ---
412
+
413
+ ## ⚙️ Configuration
414
+
415
+ ```toml
416
+ # pyproject.toml
417
+
418
+ [tool.invar.guard]
419
+ # Option 1: Explicit paths
420
+ core_paths = ["src/myapp/core"]
421
+ shell_paths = ["src/myapp/shell"]
422
+
423
+ # Option 2: Pattern matching (for existing projects)
424
+ core_patterns = ["**/domain/**", "**/models/**"]
425
+ shell_patterns = ["**/api/**", "**/cli/**"]
426
+
427
+ # Option 3: Auto-detection (when no paths/patterns specified)
428
+ # - Default paths: src/core, core, src/shell, shell
429
+ # - Content analysis: @pre/@post → Core, Result → Shell
430
+
431
+ # Size limits
432
+ max_file_lines = 500
433
+ max_function_lines = 50
434
+
435
+ # Requirements
436
+ require_contracts = true
437
+ require_doctests = true
438
+ ```
439
+
440
+ ### 🚪 Escape Hatches
441
+
442
+ For code that intentionally breaks rules:
443
+
444
+ ```toml
445
+ # Exclude entire directories
446
+ [[tool.invar.guard.rule_exclusions]]
447
+ pattern = "**/generated/**"
448
+ rules = ["*"]
449
+
450
+ # Exclude specific rules for specific files
451
+ [[tool.invar.guard.rule_exclusions]]
452
+ pattern = "**/legacy_api.py"
453
+ rules = ["missing_contract", "shell_result"]
454
+ ```
455
+
456
+ ---
457
+
458
+ ## 🔧 Tool Reference
459
+
460
+ ### CLI Commands
461
+
462
+ | Command | Purpose |
463
+ |---------|---------|
464
+ | `invar guard` | Full verification (static + doctest + property + symbolic) |
465
+ | `invar guard --changed` | Only git-modified files |
466
+ | `invar guard --static` | Static analysis only (~0.5s) |
467
+ | `invar init` | Initialize or update project |
468
+ | `invar sig <file>` | Show signatures and contracts |
469
+ | `invar map` | Symbol map with reference counts |
470
+ | `invar rules` | List all rules |
471
+ | `invar test` | Property-based tests (Hypothesis) |
472
+ | `invar verify` | Symbolic verification (CrossHair) |
473
+ | `invar hooks` | Manage Claude Code hooks |
474
+
475
+ ### MCP Tools
476
+
477
+ | Tool | Purpose |
478
+ |------|---------|
479
+ | `invar_guard` | Smart multi-layer verification |
480
+ | `invar_sig` | Extract signatures and contracts |
481
+ | `invar_map` | Symbol map with reference counts |
482
+
483
+ ---
484
+
485
+ ## 📚 Learn More
486
+
487
+ **Created by `invar init`:**
488
+ - `INVAR.md` — Protocol v5.0
489
+ - `.invar/examples/` — Reference patterns
490
+
491
+ **Documentation:**
492
+ - [Vision & Philosophy](./docs/vision.md)
493
+ - [Technical Design](./docs/design.md)
494
+
495
+ ---
496
+
497
+ ## 📄 License
498
+
499
+ | Component | License | Notes |
500
+ |-----------|---------|-------|
501
+ | **invar-runtime** | [Apache-2.0](LICENSE) | Use freely in any project |
502
+ | **invar-tools** | [GPL-3.0](LICENSE-GPL) | Improvements must be shared |
503
+ | **Documentation** | [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/) | Share with attribution |
504
+
505
+ See [NOTICE](NOTICE) for third-party licenses.