invar-tools 1.0.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.
Files changed (122) hide show
  1. invar_tools-1.0.0/.aider.conf.yml +29 -0
  2. invar_tools-1.0.0/.claude/commands/attack.md +76 -0
  3. invar_tools-1.0.0/.claude/commands/review.md +67 -0
  4. invar_tools-1.0.0/.cursorrules +26 -0
  5. invar_tools-1.0.0/.github/workflows/ci.yml +103 -0
  6. invar_tools-1.0.0/.github/workflows/publish.yml +57 -0
  7. invar_tools-1.0.0/.gitignore +57 -0
  8. invar_tools-1.0.0/.invar/context.md +789 -0
  9. invar_tools-1.0.0/.invar/examples/README.md +21 -0
  10. invar_tools-1.0.0/.invar/examples/contracts.py +111 -0
  11. invar_tools-1.0.0/.invar/examples/core_shell.py +121 -0
  12. invar_tools-1.0.0/.invar/proposals/AGENT-IMPROVEMENTS.md +94 -0
  13. invar_tools-1.0.0/.invar/proposals/DX-12-hypothesis-fallback.md +305 -0
  14. invar_tools-1.0.0/.invar/proposals/DX-13-incremental-prove.md +462 -0
  15. invar_tools-1.0.0/.invar/proposals/DX-14-expanded-prove-usage.md +249 -0
  16. invar_tools-1.0.0/.invar/proposals/DX-16-agent-tool-enforcement.md +166 -0
  17. invar_tools-1.0.0/.invar/proposals/DX-17-workflow-enforcement.md +193 -0
  18. invar_tools-1.0.0/.invar/proposals/TEMPLATE.md +93 -0
  19. invar_tools-1.0.0/.mcp.json +8 -0
  20. invar_tools-1.0.0/.pre-commit-config.yaml +46 -0
  21. invar_tools-1.0.0/.serena/.gitignore +1 -0
  22. invar_tools-1.0.0/.serena/project.yml +84 -0
  23. invar_tools-1.0.0/CLAUDE.md +233 -0
  24. invar_tools-1.0.0/INVAR.md +335 -0
  25. invar_tools-1.0.0/LICENSE +21 -0
  26. invar_tools-1.0.0/PKG-INFO +321 -0
  27. invar_tools-1.0.0/README.md +284 -0
  28. invar_tools-1.0.0/RELEASE_NOTES_v0.1.0.md +102 -0
  29. invar_tools-1.0.0/docs/AGENTS.md +391 -0
  30. invar_tools-1.0.0/docs/DESIGN.md +1034 -0
  31. invar_tools-1.0.0/docs/INVAR-GUIDE.md +190 -0
  32. invar_tools-1.0.0/docs/VISION.md +289 -0
  33. invar_tools-1.0.0/docs/archive/FIRST_PRINCIPLES_REVIEW.md +307 -0
  34. invar_tools-1.0.0/docs/archive/INVAR-DETAILED-v3.16.md +1296 -0
  35. invar_tools-1.0.0/docs/archive/PHASE3_REVIEW.md +347 -0
  36. invar_tools-1.0.0/docs/archive/PROTOCOL_EVOLUTION.md +333 -0
  37. invar_tools-1.0.0/docs/archive/VISION-ORIGINAL.md +190 -0
  38. invar_tools-1.0.0/docs/archive/decisions-2024.md +157 -0
  39. invar_tools-1.0.0/docs/archive/proposals-P15-P23-2025.md +1573 -0
  40. invar_tools-1.0.0/docs/archive/proposals-phase9-reflection-2025.md +523 -0
  41. invar_tools-1.0.0/docs/feedback/INVAR-COMPLIANCE-ANALYSIS.md +501 -0
  42. invar_tools-1.0.0/docs/index.html +1098 -0
  43. invar_tools-1.0.0/docs/proposals/2024-12-21-guard-enhancements.md +589 -0
  44. invar_tools-1.0.0/docs/proposals/2024-12-21-language-inspired-enhancements.md +4445 -0
  45. invar_tools-1.0.0/docs/proposals/2024-12-21-test-first-enhancement.md +842 -0
  46. invar_tools-1.0.0/docs/proposals/2025-12-21-dx-improvements.md +1297 -0
  47. invar_tools-1.0.0/docs/proposals/2025-12-23-dx-20-property-testing-enhancements.md +575 -0
  48. invar_tools-1.0.0/docs/proposals/2025-12-23-dx-21-package-and-init.md +401 -0
  49. invar_tools-1.0.0/docs/proposals/DX-11-documentation-restructure.md +862 -0
  50. invar_tools-1.0.0/docs/research/cruxeval-quick-validation.md +145 -0
  51. invar_tools-1.0.0/pyproject.toml +227 -0
  52. invar_tools-1.0.0/runtime/README.md +87 -0
  53. invar_tools-1.0.0/runtime/pyproject.toml +51 -0
  54. invar_tools-1.0.0/runtime/src/invar_runtime/__init__.py +68 -0
  55. invar_tools-1.0.0/runtime/src/invar_runtime/contracts.py +152 -0
  56. invar_tools-1.0.0/runtime/src/invar_runtime/decorators.py +129 -0
  57. invar_tools-1.0.0/runtime/src/invar_runtime/invariant.py +57 -0
  58. invar_tools-1.0.0/runtime/src/invar_runtime/resource.py +99 -0
  59. invar_tools-1.0.0/scripts/smart-guard.sh +43 -0
  60. invar_tools-1.0.0/src/invar/__init__.py +68 -0
  61. invar_tools-1.0.0/src/invar/contracts.py +152 -0
  62. invar_tools-1.0.0/src/invar/core/__init__.py +8 -0
  63. invar_tools-1.0.0/src/invar/core/contracts.py +375 -0
  64. invar_tools-1.0.0/src/invar/core/extraction.py +172 -0
  65. invar_tools-1.0.0/src/invar/core/formatter.py +281 -0
  66. invar_tools-1.0.0/src/invar/core/hypothesis_strategies.py +454 -0
  67. invar_tools-1.0.0/src/invar/core/inspect.py +154 -0
  68. invar_tools-1.0.0/src/invar/core/lambda_helpers.py +190 -0
  69. invar_tools-1.0.0/src/invar/core/models.py +289 -0
  70. invar_tools-1.0.0/src/invar/core/must_use.py +172 -0
  71. invar_tools-1.0.0/src/invar/core/parser.py +276 -0
  72. invar_tools-1.0.0/src/invar/core/property_gen.py +383 -0
  73. invar_tools-1.0.0/src/invar/core/purity.py +369 -0
  74. invar_tools-1.0.0/src/invar/core/purity_heuristics.py +184 -0
  75. invar_tools-1.0.0/src/invar/core/references.py +180 -0
  76. invar_tools-1.0.0/src/invar/core/rule_meta.py +203 -0
  77. invar_tools-1.0.0/src/invar/core/rules.py +435 -0
  78. invar_tools-1.0.0/src/invar/core/strategies.py +267 -0
  79. invar_tools-1.0.0/src/invar/core/suggestions.py +324 -0
  80. invar_tools-1.0.0/src/invar/core/tautology.py +137 -0
  81. invar_tools-1.0.0/src/invar/core/timeout_inference.py +114 -0
  82. invar_tools-1.0.0/src/invar/core/utils.py +364 -0
  83. invar_tools-1.0.0/src/invar/decorators.py +94 -0
  84. invar_tools-1.0.0/src/invar/invariant.py +57 -0
  85. invar_tools-1.0.0/src/invar/mcp/__init__.py +10 -0
  86. invar_tools-1.0.0/src/invar/mcp/__main__.py +13 -0
  87. invar_tools-1.0.0/src/invar/mcp/server.py +251 -0
  88. invar_tools-1.0.0/src/invar/py.typed +0 -0
  89. invar_tools-1.0.0/src/invar/resource.py +99 -0
  90. invar_tools-1.0.0/src/invar/shell/__init__.py +8 -0
  91. invar_tools-1.0.0/src/invar/shell/cli.py +358 -0
  92. invar_tools-1.0.0/src/invar/shell/config.py +248 -0
  93. invar_tools-1.0.0/src/invar/shell/fs.py +112 -0
  94. invar_tools-1.0.0/src/invar/shell/git.py +85 -0
  95. invar_tools-1.0.0/src/invar/shell/guard_helpers.py +324 -0
  96. invar_tools-1.0.0/src/invar/shell/guard_output.py +235 -0
  97. invar_tools-1.0.0/src/invar/shell/init_cmd.py +289 -0
  98. invar_tools-1.0.0/src/invar/shell/mcp_config.py +171 -0
  99. invar_tools-1.0.0/src/invar/shell/perception.py +125 -0
  100. invar_tools-1.0.0/src/invar/shell/property_tests.py +227 -0
  101. invar_tools-1.0.0/src/invar/shell/prove.py +460 -0
  102. invar_tools-1.0.0/src/invar/shell/prove_cache.py +133 -0
  103. invar_tools-1.0.0/src/invar/shell/prove_fallback.py +183 -0
  104. invar_tools-1.0.0/src/invar/shell/templates.py +443 -0
  105. invar_tools-1.0.0/src/invar/shell/test_cmd.py +117 -0
  106. invar_tools-1.0.0/src/invar/shell/testing.py +297 -0
  107. invar_tools-1.0.0/src/invar/shell/update_cmd.py +191 -0
  108. invar_tools-1.0.0/src/invar/templates/CLAUDE.md.template +58 -0
  109. invar_tools-1.0.0/src/invar/templates/INVAR.md +134 -0
  110. invar_tools-1.0.0/src/invar/templates/__init__.py +1 -0
  111. invar_tools-1.0.0/src/invar/templates/aider.conf.yml.template +29 -0
  112. invar_tools-1.0.0/src/invar/templates/context.md.template +51 -0
  113. invar_tools-1.0.0/src/invar/templates/cursorrules.template +28 -0
  114. invar_tools-1.0.0/src/invar/templates/examples/README.md +21 -0
  115. invar_tools-1.0.0/src/invar/templates/examples/contracts.py +111 -0
  116. invar_tools-1.0.0/src/invar/templates/examples/core_shell.py +121 -0
  117. invar_tools-1.0.0/src/invar/templates/pre-commit-config.yaml.template +44 -0
  118. invar_tools-1.0.0/src/invar/templates/proposal.md.template +93 -0
  119. invar_tools-1.0.0/tests/__init__.py +1 -0
  120. invar_tools-1.0.0/tests/conftest.py +57 -0
  121. invar_tools-1.0.0/tests/integration/__init__.py +0 -0
  122. invar_tools-1.0.0/tests/integration/test_cli_flags.py +171 -0
@@ -0,0 +1,29 @@
1
+ # Invar Project Configuration for Aider
2
+ # This is the Invar project itself
3
+
4
+ # Auto-read protocol files at session start
5
+ read:
6
+ - INVAR.md
7
+ - CLAUDE.md
8
+ - .invar/context.md
9
+
10
+ # System prompt addition
11
+ system-prompt: |
12
+ This is the Invar project itself. Follow INVAR.md and CLAUDE.md.
13
+
14
+ Before writing code, execute:
15
+ 1. invar guard --changed
16
+ 2. invar map --top 10
17
+
18
+ Workflow (ICIDIV):
19
+ - Intent: What? Core or Shell?
20
+ - Contract: @pre/@post + doctests BEFORE code
21
+ - Inspect: invar sig <file>
22
+ - Design: Decompose first
23
+ - Implement: Pass your doctests
24
+ - Verify: invar guard
25
+
26
+ Project-specific:
27
+ - INVAR.md here is the SOURCE, templates are in src/invar/templates/
28
+ - Do NOT run invar update on this project
29
+ - Task complete only when final invar guard passes.
@@ -0,0 +1,76 @@
1
+ # Adversarial Testing (Adversary Role)
2
+
3
+ You are now acting as the **Adversary** - a hostile tester trying to break the code.
4
+
5
+ ## Your Mindset
6
+
7
+ - **Destructive:** Focus on "how to make it crash"
8
+ - **Malicious:** Assume users will intentionally cause harm
9
+ - **Paranoid:** Assume the worst case scenario
10
+
11
+ **Your success = Breaking the code** (or proving it unbreakable).
12
+
13
+ ## Attack Vectors
14
+
15
+ ### 1. Boundary Attacks
16
+ - Empty: `[]`, `""`, `0`, `None`
17
+ - Extreme: `MAX_INT`, `-MAX_INT`, `float('inf')`, `float('nan')`
18
+ - Off-by-one: `list[len(list)]`, negative indices
19
+
20
+ ### 2. Type Attacks
21
+ - Wrong type: string where int expected
22
+ - None where object expected
23
+ - Unicode edge cases: emoji, RTL, zero-width characters
24
+ - Very long strings (1MB+)
25
+
26
+ ### 3. State Attacks
27
+ - Call function twice in a row
28
+ - Call in unexpected order
29
+ - Partially initialized objects
30
+
31
+ ### 4. Resource Attacks
32
+ - Huge inputs (memory exhaustion)
33
+ - Deep nesting (stack overflow)
34
+ - Inputs that cause O(n²) or worse
35
+
36
+ ### 5. Injection Attacks (for Shell code)
37
+ - Path traversal: `../../../etc/passwd`
38
+ - Special characters in filenames
39
+ - Null bytes in strings
40
+
41
+ ## Attack Procedure
42
+
43
+ For each public function:
44
+
45
+ 1. **Identify inputs** - What parameters does it take?
46
+ 2. **Design attacks** - At least 3 malicious inputs per function
47
+ 3. **Predict behavior** - Should it reject? Return error? Crash?
48
+ 4. **Check contracts** - Do @pre/@post catch the attack?
49
+ 5. **Report results**
50
+
51
+ ## Report Format
52
+
53
+ ```
54
+ ## Attack Results: function_name()
55
+
56
+ | Attack | Input | Expected | Actual | Result |
57
+ |--------|-------|----------|--------|--------|
58
+ | Empty list | `[]` | Reject (pre) | Reject | ✅ Contract effective |
59
+ | NaN input | `float('nan')` | Reject | Passed through | ❌ VULNERABILITY |
60
+
61
+ ### Vulnerabilities Found
62
+ 1. NaN not caught by contract - add `not math.isnan(x)` to @pre
63
+ ```
64
+
65
+ ## Instructions
66
+
67
+ 1. Identify target functions
68
+ 2. Design attacks for each
69
+ 3. Run tests or reason about behavior
70
+ 4. Report vulnerabilities and effective defenses
71
+
72
+ **Remember:** Think like an attacker, not a developer. The contracts are your enemy - try to bypass them.
73
+
74
+ ---
75
+
76
+ Now attack the recent changes or the files specified by the user.
@@ -0,0 +1,67 @@
1
+ # Code Review (Reviewer Role)
2
+
3
+ You are now acting as the **Reviewer** - a critical code reviewer.
4
+
5
+ ## Your Mindset
6
+
7
+ - **Critical:** Assume the code has bugs. Your job is to find them.
8
+ - **Skeptical:** Question every design decision.
9
+ - **Uncompromising:** Finding problems is success, not offense.
10
+
11
+ **Your success = Finding problems.** If you find nothing, you probably missed something.
12
+
13
+ ## Review Checklist
14
+
15
+ ### Architecture
16
+ - [ ] Core/Shell separation correct?
17
+ - [ ] Core imports no I/O modules (os, sys, socket, etc.)?
18
+ - [ ] Shell functions return Result[T, E]?
19
+ - [ ] Dependencies flow inward only (Shell → Core)?
20
+
21
+ ### Contracts
22
+ - [ ] All public Core functions have @pre or @post?
23
+ - [ ] Preconditions catch invalid inputs?
24
+ - [ ] Postconditions guarantee valid outputs?
25
+
26
+ ### Edge Cases
27
+ - [ ] Empty collections handled?
28
+ - [ ] Zero values handled?
29
+ - [ ] Negative values handled?
30
+ - [ ] None/null handled?
31
+ - [ ] Very large inputs considered?
32
+
33
+ ### Documentation
34
+ - [ ] Doctest examples present?
35
+ - [ ] Examples cover: normal, zero, boundary cases?
36
+ - [ ] Design decisions explained in comments or docs?
37
+
38
+ ### Code Quality
39
+ - [ ] File < 300 lines?
40
+ - [ ] Function < 50 lines?
41
+ - [ ] No **kwargs or dynamic magic?
42
+ - [ ] Full type annotations?
43
+
44
+ ## Report Format
45
+
46
+ For each issue found:
47
+
48
+ ```
49
+ ### [CRITICAL/WARNING] Issue Title
50
+
51
+ **Location:** file.py:line_number
52
+ **Problem:** What's wrong
53
+ **Suggestion:** How to fix
54
+ ```
55
+
56
+ ## Instructions
57
+
58
+ 1. Read the code carefully
59
+ 2. Check against the checklist above
60
+ 3. Report all issues found
61
+ 4. Be specific with locations and suggestions
62
+
63
+ **Remember:** You are READ-ONLY. Report issues, don't fix them directly.
64
+
65
+ ---
66
+
67
+ Now review the recent changes or the files specified by the user.
@@ -0,0 +1,26 @@
1
+ # Invar Project Development
2
+
3
+ This is the Invar project itself. Follow INVAR.md (the source, not a copy) and CLAUDE.md.
4
+
5
+ ## Entry Verification
6
+
7
+ Before writing any code, execute:
8
+
9
+ ```
10
+ invar_guard (changed=true) # or: invar guard --changed
11
+ invar_map (top=10) # or: invar map --top 10
12
+ ```
13
+
14
+ Use MCP tools if available, otherwise use CLI commands.
15
+
16
+ ## Quick Reference
17
+
18
+ - Core (`src/invar/core/`): @pre/@post contracts, doctests, pure (no I/O)
19
+ - Shell (`src/invar/shell/`): Result[T, E] return type
20
+ - Workflow: Intent -> Contract -> Inspect -> Design -> Implement -> Verify
21
+ - Task complete only when final invar_guard passes.
22
+
23
+ ## Project-Specific
24
+
25
+ - INVAR.md here is the **source**, templates are in `src/invar/templates/`
26
+ - Do NOT run `invar update` on this project
@@ -0,0 +1,103 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [Main, main]
6
+ pull_request:
7
+ branches: [Main, main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.11", "3.12"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+
24
+ - name: Install dependencies
25
+ run: |
26
+ python -m pip install --upgrade pip
27
+ # Install runtime first (local development)
28
+ pip install -e runtime/
29
+ # Install tools with dev dependencies
30
+ pip install -e ".[dev]"
31
+ pip install crosshair-tool # Required for full verification
32
+
33
+ - name: Run runtime tests
34
+ run: |
35
+ pytest --doctest-modules runtime/src/invar_runtime/ -v
36
+
37
+ - name: Run tools tests
38
+ run: |
39
+ pytest --doctest-modules src/invar/ -v
40
+
41
+ # DX-19: Default runs full verification (static + doctests + CrossHair + Hypothesis)
42
+ # continue-on-error because CrossHair finds different edge cases
43
+ # across Python versions. Failures are informational.
44
+ - name: Run Invar Guard
45
+ run: |
46
+ invar guard
47
+ continue-on-error: true
48
+
49
+ - name: Check types with mypy
50
+ run: |
51
+ mypy src/invar/ --ignore-missing-imports
52
+ mypy runtime/src/invar_runtime/ --ignore-missing-imports
53
+ continue-on-error: true
54
+
55
+ lint:
56
+ runs-on: ubuntu-latest
57
+ steps:
58
+ - uses: actions/checkout@v4
59
+
60
+ - name: Set up Python
61
+ uses: actions/setup-python@v5
62
+ with:
63
+ python-version: "3.11"
64
+
65
+ - name: Install ruff
66
+ run: pip install ruff
67
+
68
+ - name: Run ruff on tools
69
+ run: ruff check src/invar/
70
+
71
+ - name: Run ruff on runtime
72
+ run: ruff check runtime/src/invar_runtime/
73
+
74
+ build:
75
+ runs-on: ubuntu-latest
76
+ steps:
77
+ - uses: actions/checkout@v4
78
+
79
+ - name: Set up Python
80
+ uses: actions/setup-python@v5
81
+ with:
82
+ python-version: "3.11"
83
+
84
+ - name: Install build tools
85
+ run: pip install build
86
+
87
+ - name: Build invar-runtime package
88
+ run: python -m build runtime/
89
+
90
+ - name: Build invar-tools package
91
+ run: python -m build
92
+
93
+ - name: Upload runtime artifacts
94
+ uses: actions/upload-artifact@v4
95
+ with:
96
+ name: dist-runtime
97
+ path: runtime/dist/
98
+
99
+ - name: Upload tools artifacts
100
+ uses: actions/upload-artifact@v4
101
+ with:
102
+ name: dist-tools
103
+ path: dist/
@@ -0,0 +1,57 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ publish-runtime:
9
+ name: Publish invar-runtime
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ id-token: write # Required for trusted publishing
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.11"
21
+
22
+ - name: Install build tools
23
+ run: pip install build
24
+
25
+ - name: Build invar-runtime package
26
+ run: python -m build runtime/
27
+
28
+ - name: Publish invar-runtime to PyPI
29
+ uses: pypa/gh-action-pypi-publish@release/v1
30
+ with:
31
+ packages-dir: runtime/dist/
32
+ # Uses trusted publishing - configure at pypi.org/manage/project/invar-runtime/settings/publishing/
33
+
34
+ publish-tools:
35
+ name: Publish invar-tools
36
+ runs-on: ubuntu-latest
37
+ needs: publish-runtime # Tools depend on runtime
38
+ permissions:
39
+ id-token: write # Required for trusted publishing
40
+
41
+ steps:
42
+ - uses: actions/checkout@v4
43
+
44
+ - name: Set up Python
45
+ uses: actions/setup-python@v5
46
+ with:
47
+ python-version: "3.11"
48
+
49
+ - name: Install build tools
50
+ run: pip install build
51
+
52
+ - name: Build invar-tools package
53
+ run: python -m build
54
+
55
+ - name: Publish invar-tools to PyPI
56
+ uses: pypa/gh-action-pypi-publish@release/v1
57
+ # Uses trusted publishing - configure at pypi.org/manage/project/invar-tools/settings/publishing/
@@ -0,0 +1,57 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual environments
24
+ .venv/
25
+ venv/
26
+ ENV/
27
+
28
+ # IDE
29
+ .idea/
30
+ .vscode/
31
+ *.swp
32
+ *.swo
33
+
34
+ # Testing
35
+ .pytest_cache/
36
+ .coverage
37
+ htmlcov/
38
+ .tox/
39
+ .nox/
40
+
41
+ # mypy
42
+ .mypy_cache/
43
+
44
+ # ruff
45
+ .ruff_cache/
46
+
47
+ # Invar cache (DX-13)
48
+ .invar/cache/
49
+
50
+ # OS
51
+ .DS_Store
52
+ Thumbs.db
53
+
54
+ # Claude Code local settings (not committed)
55
+ .claude/settings.local.json
56
+ .hypothesis/
57
+ src/invar/core/.invar/