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
@@ -35,6 +35,7 @@ invar/mcp/__init__.py,sha256=n3S7QwMjSMqOMT8cI2jf9E0yZPjKmBOJyIYhq4WZ8TQ,226
35
35
  invar/mcp/__main__.py,sha256=ZcIT2U6xUyGOWucl4jq422BDE3lRLjqyxb9pFylRBdk,219
36
36
  invar/mcp/server.py,sha256=0a9eAuIZ62UaDGewKhAn8-PhLYvFHta-w_XcygcXCtE,11981
37
37
  invar/shell/__init__.py,sha256=FFw1mNbh_97PeKPcHIqQpQ7mw-JoIvyLM1yOdxLw5uk,204
38
+ invar/shell/claude_hooks.py,sha256=kxkdF2gwTWcGpglccDi6-8IN1zRwelDG6Lg1VPYQgyA,12912
38
39
  invar/shell/config.py,sha256=cixlq47h8HYa9Ku-JOo66KCUyrf59R0NX_Yb7A1fAv4,16134
39
40
  invar/shell/coverage.py,sha256=m01o898IFIdBztEBQLwwL1Vt5PWrpUntO4lv4nWEkls,11344
40
41
  invar/shell/fs.py,sha256=wVD7DPWsCIJXuTyY_pi-5_LS82mXRdn_grJCOLn9zpU,3699
@@ -46,50 +47,56 @@ invar/shell/mutation.py,sha256=Lfyk2b8j8-hxAq-iwAgQeOhr7Ci6c5tRF1TXe3CxQCs,8914
46
47
  invar/shell/property_tests.py,sha256=N9JreyH5PqR89oF5yLcX7ZAV-Koyg5BKo-J05-GUPsA,9109
47
48
  invar/shell/subprocess_env.py,sha256=9oXl3eMEbzLsFEgMHqobEw6oW_wV0qMEP7pklwm58Pw,11453
48
49
  invar/shell/template_engine.py,sha256=IzOiGsKVFo0lDUdtg27wMzIJJKToclv151RDZuDnHHo,11027
49
- invar/shell/templates.py,sha256=l2En95E8jRVlojdQIqdZgRLVB43f_b1d_AJapKkozwA,15908
50
+ invar/shell/templates.py,sha256=FGrHtVCUNF6K6KHrJquI9vyET0zyDkVy5ND1mAeY6NE,15934
50
51
  invar/shell/testing.py,sha256=PTrrCB0nIARuDQa_XREoRzbnqjXxju1l9Eb83pivH6c,10634
51
52
  invar/shell/commands/__init__.py,sha256=MEkKwVyjI9DmkvBpJcuumXo2Pg_FFkfEr-Rr3nrAt7A,284
52
- invar/shell/commands/guard.py,sha256=0v4kfDyxIEl3iZiYjCeTwTgAEUnL-DvCKSvXaDwqRX8,17895
53
- invar/shell/commands/init.py,sha256=K8nz1D3RqWPUr61-gYnMiSg-9cRnnYXPCR-4x37LMQA,17004
53
+ invar/shell/commands/guard.py,sha256=aYqOhxclt_oF93TcSGN1zaB4RUsSQjMUYxfBw2QmqoM,18038
54
+ invar/shell/commands/hooks.py,sha256=W-SOnT4VQyUvXwipozkJwgEYfiOJGz7wksrbcdWegUg,2356
55
+ invar/shell/commands/init.py,sha256=UzHLfAP9ddIY32HrLd32nUveFcHnB0HlbMcIgtfob9Y,18297
54
56
  invar/shell/commands/merge.py,sha256=nuvKo8m32-OL-SCQlS4SLKmOZxQ3qj-1nGCx1Pgzifw,8183
55
57
  invar/shell/commands/mutate.py,sha256=GwemiO6LlbGCBEQsBFnzZuKhF-wIMEl79GAMnKUWc8U,5765
56
58
  invar/shell/commands/perception.py,sha256=TyH_HpqyKkmE3-zcU4YyBG8ghwJaSFeRC-OQMVBDTbQ,3837
57
59
  invar/shell/commands/sync_self.py,sha256=nmqBry7V2_enKwy2zzHg8UoedZNicLe3yKDhjmBeZ68,3880
58
- invar/shell/commands/template_sync.py,sha256=g-IV4X1TGFVIypw9RBToexX7ZCSaCsD9yz-A0Sm-OmM,12155
59
- invar/shell/commands/test.py,sha256=DKnlSbUydKq6skHLLKhZGg42qTAKtiLxrTU3oyFDmAo,4189
60
+ invar/shell/commands/template_sync.py,sha256=wVZ-UvJ1wpN2UBcWMfbei0n46XHYx-zRbMA2oX6FSi4,13723
61
+ invar/shell/commands/test.py,sha256=goMf-ovvzEyWQMheq4YlJ-mwK5-w3lDj0cq0IA_1-_c,4205
60
62
  invar/shell/commands/update.py,sha256=0V5F8vxQ6PHPHPVYDmxdRD7xXeQEFypiJMYpY5ryiek,1349
61
63
  invar/shell/prove/__init__.py,sha256=ZqlbmyMFJf6yAle8634jFuPRv8wNvHps8loMlOJyf8A,240
62
64
  invar/shell/prove/accept.py,sha256=cnY_6jzU1EBnpLF8-zWUWcXiSXtCwxPsXEYXsSVPG38,3717
63
65
  invar/shell/prove/cache.py,sha256=jbNdrvfLjvK7S0iqugErqeabb4YIbQuwIlcSRyCKbcg,4105
64
66
  invar/shell/prove/crosshair.py,sha256=4Z_iIYBlkp-I6FqSYZa89wWB09V4Ouw2PduYhTn6rfw,16525
65
67
  invar/shell/prove/hypothesis.py,sha256=QUclOOUg_VB6wbmHw8O2EPiL5qBOeBRqQeM04AVuLw0,9880
66
- invar/templates/CLAUDE.md.template,sha256=W8o6M-wasCMg-7Ef2-RloDqvSKGS_9KUsy8DVbbUwDo,3719
68
+ invar/templates/CLAUDE.md.template,sha256=p2xFzbZ8NluumH9c03GkAQaqSOvgrG5SqyKU9qXz2HY,4498
67
69
  invar/templates/__init__.py,sha256=cb3ht8KPK5oBn5oG6HsTznujmo9WriJ_P--fVxJwycc,45
68
70
  invar/templates/aider.conf.yml.template,sha256=4xzSs3BXzFJvwdhnWbmzSY0yCbfx5oxqnV8ZjehqHBg,853
69
- invar/templates/context.md.template,sha256=p1-iHl32Z30-FocJa7slcmoA7gtQrUrMO7cE_u5MrSo,2073
71
+ invar/templates/context.md.template,sha256=FKyI1ghpqcf4wftyv9-auIFHor8Nm8lETN45Ja-L8Og,2386
70
72
  invar/templates/cursorrules.template,sha256=N6AiEJRJHGkHm2tswh3PnZ_07ozeyQQI8iEOGK5Aqoc,1023
71
- invar/templates/manifest.toml,sha256=5JxaY9nl9hK5d1qWc2OJEGID6bFSX_Dp39lc5kRoIXk,4252
73
+ invar/templates/manifest.toml,sha256=cEe7yEOOeaLmOF-PrwZXxiPGjHhsSJYkWBKRHDmSbac,4268
72
74
  invar/templates/pre-commit-config.yaml.template,sha256=2qWY3E8iDUqi85jE_X7y0atE88YOlL5IZ93wkjCgQGo,1737
73
75
  invar/templates/proposal.md.template,sha256=UP7SpQ7gk8jVlHGLQCSQ5c-kCj1DBQEz8M-vEStK77I,1573
74
76
  invar/templates/commands/audit.md,sha256=eXBySlQrVyk054vYQWAZYzj-HgT2QXhpzziw6GlIeGM,4112
75
77
  invar/templates/commands/guard.md,sha256=PyeAKfrmlXsgbrTDypQqXmTDKK1JHKhHEQrHqftA7X0,1177
76
- invar/templates/config/CLAUDE.md.jinja,sha256=bowI-vhIHJvTCL20L4dwFtPODvkTWTllH2TRRVUf-cg,6295
77
- invar/templates/config/context.md.jinja,sha256=sEQc-9jBqPpovlbnHSHcH7rwXVChfqDtUbYFTanStJI,2284
78
+ invar/templates/config/CLAUDE.md.jinja,sha256=tdGkWHkx4Xn7d02QQX0J_LN1p13VsvrUNYI_nLYanRE,6766
79
+ invar/templates/config/context.md.jinja,sha256=eyjNwvtSyDCImOw6up4eqfE_ylYWv2HCHMQ1M1qJtGQ,2563
78
80
  invar/templates/config/pre-commit.yaml.jinja,sha256=Qflmii8hngHciSgfa8mIlg3-E3D4b0xflm0-Q-cWcCc,1752
79
81
  invar/templates/examples/README.md,sha256=xMcJZ1KEcfLJi5Ope_4FIbqDWKK3mRleAgllvgeNT6I,572
80
82
  invar/templates/examples/conftest.py,sha256=uKA4NR7nyZWeSzY0URdZtw5zCcJpU32jNcaSKrI1Mxc,152
81
83
  invar/templates/examples/contracts.py,sha256=uqJ6Y1GADo246MjFKoLY-_2E74cfBQsLO4vTqYcR81c,3241
82
84
  invar/templates/examples/core_shell.py,sha256=ckor-7ZoaF7n8gVjnIO0CXlBjKGcVwmOGSDJbaXCSrM,4247
83
85
  invar/templates/examples/workflow.md,sha256=jAopzQH1xE9_leJFdav4oj1AkI46-a2q4L8RQCkDknw,2334
84
- invar/templates/protocol/INVAR.md,sha256=5u4q5PTVHHnJzRVEzfp4rXAfTHajIUNioRB4CQAs4JM,6662
85
- invar/templates/skills/develop/SKILL.md.jinja,sha256=A0Hnx9FlBfPXdk2Mswx0zOnDZbgszI3u5MvLVd2rlM4,9544
86
- invar/templates/skills/investigate/SKILL.md.jinja,sha256=vY6Hri5Nsy9C0JsLWU64NUitrPnBx49NtG0d4cg_FgI,3058
87
- invar/templates/skills/propose/SKILL.md.jinja,sha256=b_cw_EiAneSGSOMTJWu_j9UwIlW7h-xab39uQgFb5wY,2734
88
- invar/templates/skills/review/SKILL.md.jinja,sha256=hkLs5BHlzKNat4BdXNfgB3-3Bvz7C6gFEQJq-0hQHSk,3679
89
- invar_tools-1.3.0.dist-info/METADATA,sha256=Gwg9kdiPndJzHV5168zGSGKXw9O1IXvIEbIgCashDjQ,11656
90
- invar_tools-1.3.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
91
- invar_tools-1.3.0.dist-info/entry_points.txt,sha256=xjkp8_Kipb6KJR6VNfkAEqiOpvrwUnwUG53cegBA6pQ,57
92
- invar_tools-1.3.0.dist-info/licenses/LICENSE,sha256=qeFksp4H4kfTgQxPCIu3OdagXyiZcgBlVfsQ6M5oFyk,10767
93
- invar_tools-1.3.0.dist-info/licenses/LICENSE-GPL,sha256=IvZfC6ZbP7CLjytoHVzvpDZpD-Z3R_qa1GdMdWlWQ6Q,35157
94
- invar_tools-1.3.0.dist-info/licenses/NOTICE,sha256=joEyMyFhFY8Vd8tTJ-a3SirI0m2Sd0WjzqYt3sdcglc,2561
95
- invar_tools-1.3.0.dist-info/RECORD,,
86
+ invar/templates/hooks/PostToolUse.sh.jinja,sha256=H-lzVaEMvlr0uoO2LxrGNpWrBtyUkHmYrhtWmCqdAjI,2967
87
+ invar/templates/hooks/PreToolUse.sh.jinja,sha256=D39PaT1eFSjz_Av16xK1atoBZbhLI8tLp8L12zkG-3k,2334
88
+ invar/templates/hooks/Stop.sh.jinja,sha256=3S6lLeAGIu5aPQVRz4jjFS9AfjCD9DdS_jagmkw-x8Q,960
89
+ invar/templates/hooks/UserPromptSubmit.sh.jinja,sha256=eAQqQ-XdOCyhLpF5_1r1z7C-Ej9GQ5Isqbu_2LAtsno,2302
90
+ invar/templates/hooks/__init__.py,sha256=RnnMoQA-8eqbr8Y_1Vu9B8h5vAz4C-vmo8wgdcGYrz0,43
91
+ invar/templates/protocol/INVAR.md,sha256=Yjwvs0PK9sDUtNExXtS2g7nRV2LcUV22Xa0fY_K-_-0,9940
92
+ invar/templates/skills/develop/SKILL.md.jinja,sha256=AYlvhOnHW-EbuLnt8KwVweoKuV1p4v-6NJxFKrSyl_w,9230
93
+ invar/templates/skills/investigate/SKILL.md.jinja,sha256=bOLdLMH5WUVBYOo4NpsfyvI6xx7I1lCNr_X-8bMe_kg,2744
94
+ invar/templates/skills/propose/SKILL.md.jinja,sha256=_iDLYN6-cfzA8n0_8sv-Dnpm1xq9IIpcDyM10mU2WUA,2420
95
+ invar/templates/skills/review/SKILL.md.jinja,sha256=UDzhdjjzXKeR4olM6S2xHkw_Z-uznaBb9467O2_EOhY,5367
96
+ invar_tools-1.3.2.dist-info/METADATA,sha256=mF3BbovusFAmksInxjWG_s257mh0LkUGcGKxBbtY9KA,16695
97
+ invar_tools-1.3.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
98
+ invar_tools-1.3.2.dist-info/entry_points.txt,sha256=xjkp8_Kipb6KJR6VNfkAEqiOpvrwUnwUG53cegBA6pQ,57
99
+ invar_tools-1.3.2.dist-info/licenses/LICENSE,sha256=qeFksp4H4kfTgQxPCIu3OdagXyiZcgBlVfsQ6M5oFyk,10767
100
+ invar_tools-1.3.2.dist-info/licenses/LICENSE-GPL,sha256=IvZfC6ZbP7CLjytoHVzvpDZpD-Z3R_qa1GdMdWlWQ6Q,35157
101
+ invar_tools-1.3.2.dist-info/licenses/NOTICE,sha256=joEyMyFhFY8Vd8tTJ-a3SirI0m2Sd0WjzqYt3sdcglc,2561
102
+ invar_tools-1.3.2.dist-info/RECORD,,
@@ -1,377 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: invar-tools
3
- Version: 1.3.0
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
- # Invar
43
-
44
- [![PyPI version](https://badge.fury.io/py/invar-tools.svg)](https://badge.fury.io/py/invar-tools)
45
- [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
46
- [![License](https://img.shields.io/badge/License-Apache%202.0%20%2B%20GPL--3.0-blue.svg)](#license)
47
-
48
- > **Don't hope AI code is correct. Know it.**
49
-
50
- Invar is a verification framework for AI-assisted development. It provides contracts, verification, and a structured workflow methodology.
51
-
52
- ```python
53
- from invar_runtime import pre, post
54
-
55
- @pre(lambda items: len(items) > 0)
56
- @post(lambda result: result >= 0)
57
- def average(items: list[float]) -> float:
58
- """
59
- >>> average([1, 2, 3])
60
- 2.0
61
- """
62
- return sum(items) / len(items)
63
- ```
64
-
65
- ---
66
-
67
- ## Experience Tiers
68
-
69
- | Platform | Experience | Features |
70
- |----------|------------|----------|
71
- | **Claude Code** | Full | USBV workflow + skill automation + MCP integration |
72
- | **Cursor/Windsurf** | Basic | INVAR.md protocol + CLI verification |
73
- | **Other editors** | Minimal | CLI verification tools only |
74
-
75
- **Why tiers?** The skill system (`/develop`, `/review`, etc.) requires Claude Code's sub-agent capabilities. Other editors receive the protocol document and CLI tools.
76
-
77
- ---
78
-
79
- ## Installation
80
-
81
- ### Two Packages, Different Purposes
82
-
83
- ```
84
- ┌─────────────────────────────────────────────────────────────────┐
85
- │ Your Project │
86
- │ ├── src/ │
87
- │ │ └── from invar_runtime import pre, post ← Runtime │
88
- │ │ │
89
- │ └── Development (not shipped with your code) │
90
- │ └── uvx invar-tools guard ← Tools │
91
- └─────────────────────────────────────────────────────────────────┘
92
- ```
93
-
94
- | Package | Install | Purpose |
95
- |---------|---------|---------|
96
- | **invar-tools** | `uvx invar-tools <cmd>` | Development: verification, init, MCP server |
97
- | **invar-runtime** | `pip install invar-runtime` | Production: add to your project's dependencies |
98
-
99
- ### Quick Install
100
-
101
- ```bash
102
- # Development tools (recommended: use without installing)
103
- uvx invar-tools guard
104
- uvx invar-tools init --claude
105
-
106
- # Runtime contracts (add to your project)
107
- pip install invar-runtime
108
- ```
109
-
110
- **Why uvx is recommended:**
111
- - Always uses latest version
112
- - Doesn't pollute project dependencies
113
- - Automatically accesses your project's venv dependencies (numpy, pandas, etc.)
114
- - If your project has `invar-tools` installed, uvx will detect and use it
115
-
116
- **When to use pip install instead:**
117
- - CI/CD environments where uvx isn't available
118
- - Projects with C extensions AND Python version mismatch between uvx and project
119
-
120
- ---
121
-
122
- ## Quick Start
123
-
124
- ```bash
125
- # 1. Initialize your project
126
- cd your-project
127
- uvx invar-tools init --claude # Full experience (Claude Code)
128
- uvx invar-tools init # Basic experience (other editors)
129
-
130
- # 2. Write code with AI (AI follows INVAR.md protocol)
131
-
132
- # 3. Verify code quality
133
- uvx invar-tools guard # Runs static analysis + doctests + property tests
134
- ```
135
-
136
- ---
137
-
138
- ## The USBV Workflow
139
-
140
- AI agents follow a four-phase development cycle:
141
-
142
- ```
143
- ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐
144
- │ Understand│ → │ Specify │ → │ Build │ → │ Validate │
145
- │ │ │ │ │ │ │ │
146
- │ Intent │ │ @pre/@post│ │ Implement │ │ invar │
147
- │ Inspect │ │ Doctests │ │ leaves │ │ guard │
148
- │ Constraints │ Design │ │ first │ │ │
149
- └───────────┘ └───────────┘ └───────────┘ └───────────┘
150
- ```
151
-
152
- **Key insight:** Specify contracts BEFORE implementation. The contract becomes the specification.
153
-
154
- See [INVAR.md](./INVAR.md) for complete protocol.
155
-
156
- ---
157
-
158
- ## Session Protocol
159
-
160
- Every AI session follows this format:
161
-
162
- **First message (Check-In):**
163
- ```
164
- ✓ Check-In: [project] | [branch] | [clean/dirty]
165
- ```
166
-
167
- **Last message (Final):**
168
- ```
169
- ✓ Final: guard PASS | 0 errors, 2 warnings
170
- ```
171
-
172
- Check-In shows project context. Guard verification runs during VALIDATE phase and Final, not at Check-In.
173
-
174
- ---
175
-
176
- ## Core/Shell Architecture
177
-
178
- Invar enforces separation between pure logic and I/O:
179
-
180
- | Zone | Requirements | Forbidden |
181
- |------|--------------|-----------|
182
- | **Core** (`**/core/**`) | `@pre`/`@post` contracts, doctests | I/O imports (os, pathlib, requests...) |
183
- | **Shell** (`**/shell/**`) | `Result[T, E]` returns | - |
184
-
185
- ```python
186
- # Core: Pure logic, receives data
187
- def parse_config(content: str) -> Config:
188
- return Config.parse(content)
189
-
190
- # Shell: Handles I/O, returns Result
191
- def load_config(path: Path) -> Result[Config, str]:
192
- content = path.read_text()
193
- return Success(parse_config(content))
194
- ```
195
-
196
- ---
197
-
198
- ## Commands
199
-
200
- ### Guard (Primary)
201
-
202
- ```bash
203
- invar guard # Full verification (static + doctests + property tests)
204
- invar guard --changed # Only git-modified files
205
- invar guard --static # Static analysis only (~0.5s)
206
- invar guard --coverage # Collect branch coverage (doctest + hypothesis)
207
- ```
208
-
209
- **Flags:**
210
-
211
- | Flag | Purpose |
212
- |------|---------|
213
- | `--strict` | Treat warnings as errors |
214
- | `--explain` | Show rule explanations |
215
- | `--agent` | JSON output for AI tools |
216
- | `--coverage` | Branch coverage from doctest + hypothesis phases |
217
-
218
- ### Other Commands
219
-
220
- ```bash
221
- invar sig <file> # Show signatures + contracts
222
- invar map --top 10 # Most-referenced symbols
223
- invar rules # List all rules
224
- invar update # Update managed files
225
- ```
226
-
227
- ---
228
-
229
- ## Workflow Skills (Claude Code)
230
-
231
- `invar init --claude` creates workflow skills in `.claude/skills/`:
232
-
233
- | Skill | Trigger | Purpose |
234
- |-------|---------|---------|
235
- | `/investigate` | "why", "explain", vague tasks | Exploration, no code changes |
236
- | `/propose` | "should we", "compare" | Decision facilitation with options |
237
- | `/develop` | "add", "fix", "implement" | USBV implementation workflow |
238
- | `/review` | After develop, `review_suggested` | Adversarial review with fix loop |
239
-
240
- **Note:** Skills are Claude Code exclusive. Other editors use INVAR.md protocol directly.
241
-
242
- ---
243
-
244
- ## Configuration
245
-
246
- ### pyproject.toml
247
-
248
- ```toml
249
- [tool.invar.guard]
250
- # Directory classification
251
- core_paths = ["src/myapp/core"]
252
- shell_paths = ["src/myapp/shell"]
253
-
254
- # Or use patterns for existing projects
255
- core_patterns = ["**/domain/**", "**/models/**"]
256
- shell_patterns = ["**/api/**", "**/cli/**"]
257
-
258
- # Size limits
259
- max_file_lines = 500
260
- max_function_lines = 50
261
-
262
- # Contract requirements
263
- require_contracts = true
264
- require_doctests = true
265
-
266
- # Doctest-heavy code
267
- exclude_doctest_lines = true
268
-
269
- # Rule exclusions
270
- [[tool.invar.guard.rule_exclusions]]
271
- pattern = "**/generated/**"
272
- rules = ["*"]
273
- ```
274
-
275
- ---
276
-
277
- ## Rules Reference
278
-
279
- | Rule | Severity | What It Checks |
280
- |------|----------|----------------|
281
- | `file_size` | ERROR | File > max lines |
282
- | `function_size` | WARN | Function > max lines |
283
- | `missing_contract` | ERROR | Core function lacks @pre/@post |
284
- | `missing_doctest` | WARN | Contracted function lacks doctest |
285
- | `forbidden_import` | ERROR | I/O import in Core |
286
- | `shell_result` | WARN | Shell function not returning Result |
287
- | `empty_contract` | ERROR | Contract is `lambda: True` |
288
-
289
- Full list: `invar rules --explain`
290
-
291
- ---
292
-
293
- ## MCP Integration (Claude Code)
294
-
295
- `invar init --claude` automatically configures MCP:
296
-
297
- ```json
298
- {
299
- "mcpServers": {
300
- "invar": {
301
- "command": "uvx",
302
- "args": ["invar-tools", "mcp"]
303
- }
304
- }
305
- }
306
- ```
307
-
308
- **MCP Tools:**
309
-
310
- | Tool | Replaces | Purpose |
311
- |------|----------|---------|
312
- | `invar_guard` | `pytest`, `crosshair` | Smart verification |
313
- | `invar_sig` | Reading entire files | Show contracts and signatures |
314
- | `invar_map` | `grep` for functions | Symbol map with reference counts |
315
-
316
- ---
317
-
318
- ## Platform Support
319
-
320
- | Feature | Claude Code | Cursor/Windsurf | Others |
321
- |---------|-------------|-----------------|--------|
322
- | Smart Guard CLI | ✅ | ✅ | ✅ |
323
- | INVAR.md protocol | ✅ | ✅ | ✅ |
324
- | MCP integration | ✅ | ❌ | ❌ |
325
- | Workflow skills | ✅ | ❌ | ❌ |
326
- | Sub-agent review | ✅ | ❌ | ❌ |
327
-
328
- **Claude Code** provides the full experience with automated workflow and independent review.
329
-
330
- **Other editors** receive the protocol and CLI tools. Workflow adherence is manual.
331
-
332
- ---
333
-
334
- ## File Ownership
335
-
336
- | File | Owner | Edit? |
337
- |------|-------|-------|
338
- | `INVAR.md` | Invar | No (`invar update` manages) |
339
- | `CLAUDE.md` | You | Yes (project config) |
340
- | `.claude/skills/` | You | Yes (customize workflows) |
341
-
342
- ---
343
-
344
- ## Runtime Behavior
345
-
346
- Contracts are checked at runtime via [deal](https://github.com/life4/deal).
347
-
348
- ```bash
349
- # Disable in production for performance
350
- DEAL_DISABLE=1 python app.py
351
- ```
352
-
353
- ---
354
-
355
- ## Learn More
356
-
357
- **In your project** (created by `invar init`):
358
- - `INVAR.md` — Protocol v5.0 for AI agents
359
- - `CLAUDE.md` — Project configuration
360
- - `.invar/examples/` — Reference patterns
361
-
362
- **Documentation:**
363
- - [docs/vision.md](./docs/vision.md) — Design philosophy
364
- - [docs/design.md](./docs/design.md) — Technical architecture
365
- - [GitHub Pages](https://tefx.github.io/Invar/) — Visual overview
366
-
367
- ---
368
-
369
- ## License
370
-
371
- | Component | License | Purpose |
372
- |-----------|---------|---------|
373
- | **invar-runtime** | [Apache-2.0](LICENSE) | Runtime contracts - use freely |
374
- | **invar-tools** | [GPL-3.0](LICENSE-GPL) | CLI tools - improvements shared |
375
- | **Documentation** | [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/) | Share with attribution |
376
-
377
- See [NOTICE](NOTICE) for third-party licenses.