invar-tools 1.2.0__py3-none-any.whl → 1.3.0__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 (89) hide show
  1. invar/__init__.py +1 -0
  2. invar/core/contracts.py +10 -10
  3. invar/core/entry_points.py +105 -32
  4. invar/core/extraction.py +5 -6
  5. invar/core/format_specs.py +1 -2
  6. invar/core/formatter.py +6 -7
  7. invar/core/hypothesis_strategies.py +5 -7
  8. invar/core/inspect.py +1 -1
  9. invar/core/lambda_helpers.py +3 -3
  10. invar/core/models.py +7 -1
  11. invar/core/must_use.py +2 -1
  12. invar/core/parser.py +7 -4
  13. invar/core/postcondition_scope.py +128 -0
  14. invar/core/property_gen.py +8 -5
  15. invar/core/purity.py +3 -3
  16. invar/core/purity_heuristics.py +5 -9
  17. invar/core/references.py +8 -6
  18. invar/core/review_trigger.py +78 -6
  19. invar/core/rule_meta.py +8 -0
  20. invar/core/rules.py +18 -19
  21. invar/core/shell_analysis.py +5 -10
  22. invar/core/shell_architecture.py +2 -2
  23. invar/core/strategies.py +7 -14
  24. invar/core/suggestions.py +86 -0
  25. invar/core/sync_helpers.py +238 -0
  26. invar/core/tautology.py +102 -37
  27. invar/core/template_parser.py +467 -0
  28. invar/core/timeout_inference.py +4 -7
  29. invar/core/utils.py +13 -15
  30. invar/core/verification_routing.py +4 -7
  31. invar/mcp/server.py +100 -17
  32. invar/shell/commands/__init__.py +11 -0
  33. invar/shell/{cli.py → commands/guard.py} +94 -14
  34. invar/shell/{init_cmd.py → commands/init.py} +179 -27
  35. invar/shell/commands/merge.py +256 -0
  36. invar/shell/commands/sync_self.py +113 -0
  37. invar/shell/commands/template_sync.py +366 -0
  38. invar/shell/commands/update.py +48 -0
  39. invar/shell/config.py +12 -24
  40. invar/shell/coverage.py +351 -0
  41. invar/shell/guard_helpers.py +38 -17
  42. invar/shell/guard_output.py +7 -1
  43. invar/shell/property_tests.py +58 -22
  44. invar/shell/prove/__init__.py +9 -0
  45. invar/shell/{prove.py → prove/crosshair.py} +40 -33
  46. invar/shell/{prove_fallback.py → prove/hypothesis.py} +12 -4
  47. invar/shell/subprocess_env.py +393 -0
  48. invar/shell/template_engine.py +345 -0
  49. invar/shell/templates.py +19 -0
  50. invar/shell/testing.py +71 -20
  51. invar/templates/CLAUDE.md.template +38 -17
  52. invar/templates/aider.conf.yml.template +2 -2
  53. invar/templates/commands/{review.md → audit.md} +20 -82
  54. invar/templates/commands/guard.md +77 -0
  55. invar/templates/config/CLAUDE.md.jinja +206 -0
  56. invar/templates/config/context.md.jinja +92 -0
  57. invar/templates/config/pre-commit.yaml.jinja +44 -0
  58. invar/templates/context.md.template +33 -0
  59. invar/templates/cursorrules.template +7 -4
  60. invar/templates/examples/README.md +2 -0
  61. invar/templates/examples/conftest.py +3 -0
  62. invar/templates/examples/contracts.py +5 -5
  63. invar/templates/examples/core_shell.py +11 -7
  64. invar/templates/examples/workflow.md +81 -0
  65. invar/templates/manifest.toml +137 -0
  66. invar/templates/{INVAR.md → protocol/INVAR.md} +10 -7
  67. invar/templates/skills/develop/SKILL.md.jinja +318 -0
  68. invar/templates/skills/investigate/SKILL.md.jinja +106 -0
  69. invar/templates/skills/propose/SKILL.md.jinja +104 -0
  70. invar/templates/skills/review/SKILL.md.jinja +125 -0
  71. {invar_tools-1.2.0.dist-info → invar_tools-1.3.0.dist-info}/METADATA +108 -118
  72. invar_tools-1.3.0.dist-info/RECORD +95 -0
  73. invar_tools-1.3.0.dist-info/entry_points.txt +2 -0
  74. invar/contracts.py +0 -152
  75. invar/decorators.py +0 -94
  76. invar/invariant.py +0 -58
  77. invar/resource.py +0 -99
  78. invar/shell/update_cmd.py +0 -193
  79. invar_tools-1.2.0.dist-info/RECORD +0 -77
  80. invar_tools-1.2.0.dist-info/entry_points.txt +0 -2
  81. /invar/shell/{mutate_cmd.py → commands/mutate.py} +0 -0
  82. /invar/shell/{perception.py → commands/perception.py} +0 -0
  83. /invar/shell/{test_cmd.py → commands/test.py} +0 -0
  84. /invar/shell/{prove_accept.py → prove/accept.py} +0 -0
  85. /invar/shell/{prove_cache.py → prove/cache.py} +0 -0
  86. {invar_tools-1.2.0.dist-info → invar_tools-1.3.0.dist-info}/WHEEL +0 -0
  87. {invar_tools-1.2.0.dist-info → invar_tools-1.3.0.dist-info}/licenses/LICENSE +0 -0
  88. {invar_tools-1.2.0.dist-info → invar_tools-1.3.0.dist-info}/licenses/LICENSE-GPL +0 -0
  89. {invar_tools-1.2.0.dist-info → invar_tools-1.3.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,106 @@
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
+ ---
8
+ name: investigate
9
+ description: Exploration and understanding phase. Use when task is vague, needs analysis, or requires understanding before action. Triggers on "why", "what is", "how does", "explain", "understand", "analyze", "investigate", "explore". NO CODE CHANGES in this phase.
10
+ ---
11
+
12
+ # Investigation Mode
13
+
14
+ > **Purpose:** Understand before acting. Gather information, analyze code, report findings.
15
+
16
+ ## Constraints
17
+
18
+ **FORBIDDEN in this phase:**
19
+ - Edit, Write (no code changes)
20
+ - git commit (nothing to commit)
21
+ - Creating new files
22
+
23
+ **ALLOWED:**
24
+ - Read, Glob, Grep (exploration)
25
+ {% if syntax == "mcp" -%}
26
+ - invar_sig, invar_map (perception)
27
+ {% else -%}
28
+ - invar sig, invar map (perception)
29
+ {% endif -%}
30
+ - WebSearch, WebFetch (research)
31
+
32
+ ## Entry Actions
33
+
34
+ ### Context Refresh (DX-54)
35
+
36
+ Before any workflow action:
37
+ 1. Read `.invar/context.md` (especially Key Rules section)
38
+ 2. Display routing announcement
39
+
40
+ ### Routing Announcement
41
+
42
+ ```
43
+ 📍 Routing: /investigate — [reason, e.g. "task is vague", "trigger 'why'"]
44
+ Task: [user's request summary]
45
+ ```
46
+
47
+ ### Entry Steps
48
+
49
+ 1. Display routing announcement (above)
50
+ {% if syntax == "mcp" -%}
51
+ 2. Run `invar_map(top=10)` for codebase orientation
52
+ {% else -%}
53
+ 2. Run `invar map --top 10` for codebase orientation
54
+ {% endif -%}
55
+ 3. Explore relevant code and documentation
56
+
57
+ ## Tool Selection
58
+
59
+ | I want to... | Use |
60
+ |--------------|-----|
61
+ {% if syntax == "mcp" -%}
62
+ | See function contracts | `invar_sig(target="<file>")` |
63
+ | Find entry points | `invar_map(top=10)` |
64
+ {% else -%}
65
+ | See function contracts | `invar sig <file>` |
66
+ | Find entry points | `invar map --top 10` |
67
+ {% endif -%}
68
+ | Search code patterns | Grep with regex |
69
+ | Explore codebase | Task(Explore) agent |
70
+
71
+ ## Exit Format
72
+
73
+ ```markdown
74
+ ### Investigation Complete
75
+
76
+ **Topic:** [what was investigated]
77
+
78
+ **Findings:**
79
+ 1. [Key finding 1]
80
+ 2. [Key finding 2]
81
+ 3. [Key finding 3]
82
+
83
+ **Details:**
84
+ [Detailed explanation with file:line references]
85
+
86
+ **Recommendation:**
87
+ - [ ] /propose — Design decision needed
88
+ - [ ] /develop — Ready to implement [specific task]
89
+ - [ ] More investigation — [what's still unclear]
90
+
91
+ **Next step?**
92
+ ```
93
+ <!--/invar:skill-->
94
+
95
+ <!--invar:extensions-->
96
+ <!-- ========================================================================
97
+ EXTENSIONS REGION - USER EDITABLE
98
+ Add project-specific extensions here. This section is preserved on update.
99
+
100
+ Examples of what to add:
101
+ - Project-specific investigation checklists
102
+ - Custom analysis tools or scripts
103
+ - Domain-specific research sources
104
+ - Team documentation references
105
+ ======================================================================== -->
106
+ <!--/invar:extensions-->
@@ -0,0 +1,104 @@
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
+ ---
8
+ name: propose
9
+ 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.
10
+ ---
11
+
12
+ # Proposal Mode
13
+
14
+ > **Purpose:** Facilitate human decision-making with clear options and trade-offs.
15
+
16
+ ## Entry Actions
17
+
18
+ ### Context Refresh (DX-54)
19
+
20
+ Before any workflow action:
21
+ 1. Read `.invar/context.md` (especially Key Rules section)
22
+ 2. Display routing announcement
23
+
24
+ ### Routing Announcement
25
+
26
+ ```
27
+ 📍 Routing: /propose — [trigger detected, e.g. "should we", "compare", "design"]
28
+ Task: [decision topic summary]
29
+ ```
30
+
31
+ ### Entry Steps
32
+
33
+ 1. Display routing announcement (above)
34
+ 2. Explore relevant context if needed
35
+
36
+ ## Output Formats
37
+
38
+ ### Quick Decision (2-4 options)
39
+
40
+ ```markdown
41
+ ### Decision: [Topic]
42
+
43
+ | Option | Description | Pros | Cons |
44
+ |--------|-------------|------|------|
45
+ | A: [name] | [brief] | [pros] | [cons] |
46
+ | B: [name] | [brief] | [pros] | [cons] |
47
+
48
+ **Recommendation:** [A/B] because [concise reason]
49
+
50
+ **Your choice?**
51
+ ```
52
+
53
+ ### Formal Proposal (complex decision)
54
+
55
+ Create `docs/proposals/DX-XX-[topic].md`:
56
+
57
+ ```markdown
58
+ # DX-XX: [Title]
59
+
60
+ **Status:** Discussion
61
+ **Created:** [date]
62
+
63
+ ## Problem Statement
64
+ [What needs to be decided]
65
+
66
+ ## Options
67
+
68
+ ### Option A: [Name]
69
+ - **Description:** [What this involves]
70
+ - **Pros:** [Benefits]
71
+ - **Cons:** [Drawbacks]
72
+ - **Effort:** Low/Medium/High
73
+
74
+ ### Option B: [Name]
75
+ ...
76
+
77
+ ## Recommendation
78
+ [Which option and why]
79
+
80
+ ## Open Questions
81
+ [What needs clarification]
82
+ ```
83
+
84
+ ## Exit Conditions
85
+
86
+ | User Response | Next Action |
87
+ |---------------|-------------|
88
+ | Chooses option | /develop to implement |
89
+ | Needs more info | /investigate for analysis |
90
+ | Approves proposal | Document created |
91
+ <!--/invar:skill-->
92
+
93
+ <!--invar:extensions-->
94
+ <!-- ========================================================================
95
+ EXTENSIONS REGION - USER EDITABLE
96
+ Add project-specific extensions here. This section is preserved on update.
97
+
98
+ Examples of what to add:
99
+ - Project-specific proposal templates
100
+ - Decision criteria or checklists
101
+ - Stakeholder notification rules
102
+ - Architecture decision record (ADR) formats
103
+ ======================================================================== -->
104
+ <!--/invar:extensions-->
@@ -0,0 +1,125 @@
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
+ ---
8
+ name: review
9
+ 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).
10
+ ---
11
+
12
+ # Review Mode
13
+
14
+ > **Purpose:** Find problems that Guard, doctests, and property tests missed.
15
+ > **Mindset:** Adversarial. Your success is measured by problems found, not code approved.
16
+
17
+ ## Entry Actions
18
+
19
+ ### Context Refresh (DX-54)
20
+
21
+ Before any workflow action:
22
+ 1. Read `.invar/context.md` (especially Key Rules section)
23
+ 2. Display routing announcement
24
+
25
+ ### Routing Announcement
26
+
27
+ ```
28
+ 📍 Routing: /review — [trigger, e.g. "review_suggested", "user requested review"]
29
+ Task: [review scope summary]
30
+ ```
31
+
32
+ ## Mode Selection
33
+
34
+ ### Check Guard Output
35
+
36
+ Look for `review_suggested` warning:
37
+ ```
38
+ WARNING: review_suggested - High escape hatch count
39
+ WARNING: review_suggested - Security-sensitive path detected
40
+ WARNING: review_suggested - Low contract coverage
41
+ ```
42
+
43
+ ### Select Mode
44
+
45
+ | Condition | Mode |
46
+ |-----------|------|
47
+ | `review_suggested` present | **Isolated** (spawn sub-agent) |
48
+ | `--isolated` flag | **Isolated** |
49
+ | Default (no trigger) | **Quick** (same context) |
50
+
51
+ ## Review Checklist
52
+
53
+ ### A. Contract Semantic Value
54
+ - [ ] Does @pre constrain inputs beyond type checking?
55
+ - [ ] Does @post verify meaningful output properties?
56
+ - [ ] Could someone implement correctly from contracts alone?
57
+
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?
62
+
63
+ ### C. Escape Hatch Audit
64
+ - [ ] Is each @invar:allow justification valid?
65
+ - [ ] Could refactoring eliminate the need?
66
+
67
+ ### D. Security (if applicable)
68
+ - [ ] Input validation against injection, XSS?
69
+ - [ ] No hardcoded secrets?
70
+
71
+ ## Review-Fix Loop
72
+
73
+ ```
74
+ Round 1: Review → Find issues
75
+
76
+ Fix CRITICAL + MAJOR (MINOR → backlog)
77
+
78
+ Round 2: Re-review (if needed)
79
+
80
+ Convergence check:
81
+ - No CRITICAL/MAJOR → Exit ✓
82
+ - No improvement → Exit (warn)
83
+ - Round >= 3 → Exit (max)
84
+ ```
85
+
86
+ ## Severity Definitions
87
+
88
+ | Level | Meaning | Examples |
89
+ |-------|---------|----------|
90
+ | CRITICAL | Security, data loss, crash | SQL injection, unhandled null |
91
+ | MAJOR | Logic error, missing validation | Wrong calculation, no bounds |
92
+ | MINOR | Style, documentation | Naming, missing docstring |
93
+
94
+ ## Exit Report
95
+
96
+ ```markdown
97
+ ### Review Complete
98
+
99
+ **Rounds:** [N]
100
+ **Exit reason:** quality_met | max_rounds | no_improvement
101
+
102
+ **Fixed:**
103
+ - [list of fixed issues]
104
+
105
+ **Remaining (MINOR - backlog):**
106
+ - [list for later]
107
+
108
+ **Recommendation:**
109
+ - [ ] Ready for merge
110
+ - [ ] Needs more work: [issues]
111
+ ```
112
+ <!--/invar:skill-->
113
+
114
+ <!--invar:extensions-->
115
+ <!-- ========================================================================
116
+ EXTENSIONS REGION - USER EDITABLE
117
+ Add project-specific extensions here. This section is preserved on update.
118
+
119
+ Examples of what to add:
120
+ - Project-specific security review checklists
121
+ - Custom severity definitions
122
+ - Domain-specific code patterns to check
123
+ - Team code review standards
124
+ ======================================================================== -->
125
+ <!--/invar:extensions-->