invar-tools 1.0.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.
- invar/__init__.py +1 -0
- invar/core/contracts.py +80 -10
- invar/core/entry_points.py +367 -0
- invar/core/extraction.py +5 -6
- invar/core/format_specs.py +195 -0
- invar/core/format_strategies.py +197 -0
- invar/core/formatter.py +32 -10
- invar/core/hypothesis_strategies.py +50 -10
- invar/core/inspect.py +1 -1
- invar/core/lambda_helpers.py +3 -2
- invar/core/models.py +30 -18
- invar/core/must_use.py +2 -1
- invar/core/parser.py +13 -6
- invar/core/postcondition_scope.py +128 -0
- invar/core/property_gen.py +86 -42
- invar/core/purity.py +13 -7
- invar/core/purity_heuristics.py +5 -9
- invar/core/references.py +8 -6
- invar/core/review_trigger.py +370 -0
- invar/core/rule_meta.py +69 -2
- invar/core/rules.py +91 -28
- invar/core/shell_analysis.py +247 -0
- invar/core/shell_architecture.py +171 -0
- invar/core/strategies.py +7 -14
- invar/core/suggestions.py +92 -0
- invar/core/sync_helpers.py +238 -0
- invar/core/tautology.py +103 -37
- invar/core/template_parser.py +467 -0
- invar/core/timeout_inference.py +4 -7
- invar/core/utils.py +63 -18
- invar/core/verification_routing.py +155 -0
- invar/mcp/server.py +113 -13
- invar/shell/commands/__init__.py +11 -0
- invar/shell/{cli.py → commands/guard.py} +152 -44
- invar/shell/{init_cmd.py → commands/init.py} +200 -28
- invar/shell/commands/merge.py +256 -0
- invar/shell/commands/mutate.py +184 -0
- invar/shell/{perception.py → commands/perception.py} +2 -0
- invar/shell/commands/sync_self.py +113 -0
- invar/shell/commands/template_sync.py +366 -0
- invar/shell/{test_cmd.py → commands/test.py} +3 -1
- invar/shell/commands/update.py +48 -0
- invar/shell/config.py +247 -10
- invar/shell/coverage.py +351 -0
- invar/shell/fs.py +5 -2
- invar/shell/git.py +2 -0
- invar/shell/guard_helpers.py +116 -20
- invar/shell/guard_output.py +106 -24
- invar/shell/mcp_config.py +3 -0
- invar/shell/mutation.py +314 -0
- invar/shell/property_tests.py +75 -24
- invar/shell/prove/__init__.py +9 -0
- invar/shell/prove/accept.py +113 -0
- invar/shell/{prove.py → prove/crosshair.py} +69 -30
- invar/shell/prove/hypothesis.py +293 -0
- invar/shell/subprocess_env.py +393 -0
- invar/shell/template_engine.py +345 -0
- invar/shell/templates.py +53 -0
- invar/shell/testing.py +77 -37
- invar/templates/CLAUDE.md.template +86 -9
- invar/templates/aider.conf.yml.template +16 -14
- invar/templates/commands/audit.md +138 -0
- invar/templates/commands/guard.md +77 -0
- invar/templates/config/CLAUDE.md.jinja +206 -0
- invar/templates/config/context.md.jinja +92 -0
- invar/templates/config/pre-commit.yaml.jinja +44 -0
- invar/templates/context.md.template +33 -0
- invar/templates/cursorrules.template +25 -13
- invar/templates/examples/README.md +2 -0
- invar/templates/examples/conftest.py +3 -0
- invar/templates/examples/contracts.py +4 -2
- invar/templates/examples/core_shell.py +10 -4
- invar/templates/examples/workflow.md +81 -0
- invar/templates/manifest.toml +137 -0
- invar/templates/protocol/INVAR.md +210 -0
- invar/templates/skills/develop/SKILL.md.jinja +318 -0
- invar/templates/skills/investigate/SKILL.md.jinja +106 -0
- invar/templates/skills/propose/SKILL.md.jinja +104 -0
- invar/templates/skills/review/SKILL.md.jinja +125 -0
- invar_tools-1.3.0.dist-info/METADATA +377 -0
- invar_tools-1.3.0.dist-info/RECORD +95 -0
- invar_tools-1.3.0.dist-info/entry_points.txt +2 -0
- invar_tools-1.3.0.dist-info/licenses/LICENSE +190 -0
- invar_tools-1.3.0.dist-info/licenses/LICENSE-GPL +674 -0
- invar_tools-1.3.0.dist-info/licenses/NOTICE +63 -0
- invar/contracts.py +0 -152
- invar/decorators.py +0 -94
- invar/invariant.py +0 -57
- invar/resource.py +0 -99
- invar/shell/prove_fallback.py +0 -183
- invar/shell/update_cmd.py +0 -191
- invar/templates/INVAR.md +0 -134
- invar_tools-1.0.0.dist-info/METADATA +0 -321
- invar_tools-1.0.0.dist-info/RECORD +0 -64
- invar_tools-1.0.0.dist-info/entry_points.txt +0 -2
- invar_tools-1.0.0.dist-info/licenses/LICENSE +0 -21
- /invar/shell/{prove_cache.py → prove/cache.py} +0 -0
- {invar_tools-1.0.0.dist-info → invar_tools-1.3.0.dist-info}/WHEEL +0 -0
|
@@ -1,21 +1,43 @@
|
|
|
1
1
|
# Project Development Guide
|
|
2
2
|
|
|
3
|
-
> **Protocol:** Follow [INVAR.md](./INVAR.md) — includes
|
|
3
|
+
> **Protocol:** Follow [INVAR.md](./INVAR.md) — includes Check-In, USBV workflow, and Task Completion requirements.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Check-In
|
|
6
6
|
|
|
7
|
-
Your
|
|
7
|
+
Your first message MUST display:
|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
|
|
11
|
-
invar_map(top=10) # or: invar map --top 10
|
|
10
|
+
✓ Check-In: [project] | [branch] | [clean/dirty]
|
|
12
11
|
```
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
Actions:
|
|
14
|
+
1. Read `.invar/context.md` (Key Rules + Current State + Lessons Learned)
|
|
15
|
+
2. Show one-line status
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
Example:
|
|
18
|
+
```
|
|
19
|
+
✓ Check-In: MyProject | main | clean
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Do NOT execute guard or map at Check-In.**
|
|
23
|
+
Guard is for VALIDATE phase and Final only.
|
|
24
|
+
|
|
25
|
+
This is your sign-in. The user sees it immediately.
|
|
26
|
+
No visible check-in = Session not started.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Final
|
|
31
|
+
|
|
32
|
+
Your last message for an implementation task MUST display:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
✓ Final: guard PASS | 0 errors, 2 warnings
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Execute `invar_guard()` and show this one-line summary.
|
|
17
39
|
|
|
18
|
-
This
|
|
40
|
+
This is your sign-out. Completes the Check-In/Final pair.
|
|
19
41
|
|
|
20
42
|
---
|
|
21
43
|
|
|
@@ -43,7 +65,62 @@ src/{project}/
|
|
|
43
65
|
| INVAR.md | Invar | No | Protocol (`invar update` to sync) |
|
|
44
66
|
| CLAUDE.md | User | Yes | Project customization (this file) |
|
|
45
67
|
| .invar/context.md | User | Yes | Project state, lessons learned |
|
|
46
|
-
| .invar/examples/ | Invar | No | **Must read:** Core/Shell patterns |
|
|
68
|
+
| .invar/examples/ | Invar | No | **Must read:** Core/Shell patterns, workflow |
|
|
69
|
+
|
|
70
|
+
## Visible Workflow (DX-30)
|
|
71
|
+
|
|
72
|
+
For complex tasks (3+ functions), show 3 checkpoints in TodoList:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
□ [UNDERSTAND] Task description, codebase context, constraints
|
|
76
|
+
□ [SPECIFY] Contracts (@pre/@post) and design decomposition
|
|
77
|
+
□ [VALIDATE] Guard results, Review Gate status, integration status
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**BUILD is internal work** — not shown in TodoList.
|
|
81
|
+
|
|
82
|
+
**Show contracts before code.** See `.invar/examples/workflow.md` for full example.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Commands (User-Invokable)
|
|
87
|
+
|
|
88
|
+
| Command | Purpose |
|
|
89
|
+
|---------|---------|
|
|
90
|
+
| `/audit` | Read-only code review (reports issues, no fixes) |
|
|
91
|
+
| `/guard` | Run Invar verification (reports results) |
|
|
92
|
+
|
|
93
|
+
## Skills (Agent-Invoked)
|
|
94
|
+
|
|
95
|
+
| Skill | Triggers | Purpose |
|
|
96
|
+
|-------|----------|---------|
|
|
97
|
+
| `/investigate` | "why", "explain", vague tasks | Research mode, no code changes |
|
|
98
|
+
| `/propose` | "should we", "compare" | Decision facilitation |
|
|
99
|
+
| `/develop` | "add", "fix", "implement" | USBV implementation workflow |
|
|
100
|
+
| `/review` | After /develop, `review_suggested` | Adversarial review with fix loop |
|
|
101
|
+
|
|
102
|
+
**Note:** Skills are invoked by agent based on context. Use `/audit` for user-initiated review.
|
|
103
|
+
|
|
104
|
+
Guard triggers `review_suggested` for: security-sensitive files, escape hatches >= 3, contract coverage < 50%.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Workflow Routing (MANDATORY)
|
|
109
|
+
|
|
110
|
+
When user message contains these triggers, you MUST invoke the corresponding skill:
|
|
111
|
+
|
|
112
|
+
| Trigger Words | Skill | Notes |
|
|
113
|
+
|---------------|-------|-------|
|
|
114
|
+
| "review", "review and fix" | `/review` | Adversarial review with fix loop |
|
|
115
|
+
| "implement", "add", "fix", "update" | `/develop` | Unless in review context |
|
|
116
|
+
| "why", "explain", "investigate" | `/investigate` | Research mode, no code changes |
|
|
117
|
+
| "compare", "should we", "design" | `/propose` | Decision facilitation |
|
|
118
|
+
|
|
119
|
+
**Violation check (before writing ANY code):**
|
|
120
|
+
- "Am I in a workflow?"
|
|
121
|
+
- "Did I invoke the correct skill?"
|
|
122
|
+
|
|
123
|
+
---
|
|
47
124
|
|
|
48
125
|
## Project-Specific Rules
|
|
49
126
|
|
|
@@ -4,26 +4,28 @@
|
|
|
4
4
|
# Auto-read protocol files at session start
|
|
5
5
|
read:
|
|
6
6
|
- INVAR.md
|
|
7
|
-
- .invar/examples/
|
|
8
|
-
- .invar/examples/
|
|
7
|
+
- .invar/examples/contracts.py
|
|
8
|
+
- .invar/examples/core_shell.py
|
|
9
9
|
- .invar/context.md
|
|
10
10
|
|
|
11
11
|
# System prompt addition
|
|
12
12
|
system-prompt: |
|
|
13
13
|
Follow the Invar Protocol in INVAR.md.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
## Check-In
|
|
16
|
+
Your first message MUST display:
|
|
17
|
+
✓ Check-In: [project] | [branch] | [clean/dirty]
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Read .invar/context.md first. Do NOT run guard/map at Check-In.
|
|
20
|
+
This is your sign-in. No visible check-in = Session not started.
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- Inspect: invar_sig (or: invar sig <file>)
|
|
25
|
-
- Design: Decompose first
|
|
26
|
-
- Implement: Pass your doctests
|
|
27
|
-
- Verify: invar_guard (or: invar guard)
|
|
22
|
+
## Final
|
|
23
|
+
Your last message MUST display:
|
|
24
|
+
✓ Final: guard PASS | 0 errors, 2 warnings
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
Execute: invar guard
|
|
27
|
+
This is your sign-out. Completes the Check-In/Final pair.
|
|
28
|
+
|
|
29
|
+
## Workflow (USBV)
|
|
30
|
+
Understand → Specify → Build → Validate
|
|
31
|
+
Inspect before Contract. Depth varies naturally.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Audit
|
|
2
|
+
|
|
3
|
+
Read-only code review. Reports issues without fixing them.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Behavior
|
|
8
|
+
|
|
9
|
+
1. Analyze code for issues (style, bugs, security, architecture)
|
|
10
|
+
2. Report findings with file:line references
|
|
11
|
+
3. **Do NOT make any changes** - report only
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Adversarial Reviewer Persona
|
|
16
|
+
|
|
17
|
+
You are an **adversarial code reviewer**. Your job is to FIND PROBLEMS.
|
|
18
|
+
|
|
19
|
+
### Your Mindset
|
|
20
|
+
|
|
21
|
+
Assume:
|
|
22
|
+
- The code has bugs until proven otherwise
|
|
23
|
+
- The contracts may be meaningless ceremony
|
|
24
|
+
- The implementer may have rationalized poor decisions
|
|
25
|
+
- Escape hatches may be abused
|
|
26
|
+
|
|
27
|
+
You are NOT here to:
|
|
28
|
+
- Validate that code works
|
|
29
|
+
- Confirm the implementer did a good job
|
|
30
|
+
- Be nice or diplomatic
|
|
31
|
+
|
|
32
|
+
You ARE here to:
|
|
33
|
+
- Find bugs, logic errors, edge cases
|
|
34
|
+
- Challenge whether contracts have semantic value
|
|
35
|
+
- Identify code smells and duplication
|
|
36
|
+
- Question every escape hatch
|
|
37
|
+
- Check if code matches contracts (not if code "seems right")
|
|
38
|
+
|
|
39
|
+
**Your success is measured by problems found, not code approved.**
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Review Checklist
|
|
44
|
+
|
|
45
|
+
> **Principle:** Only items requiring semantic judgment. Mechanical checks are excluded (see bottom).
|
|
46
|
+
|
|
47
|
+
### A. Contract Semantic Value
|
|
48
|
+
- [ ] Does @pre constrain inputs beyond type checking?
|
|
49
|
+
- Bad: `@pre(lambda x: isinstance(x, int))`
|
|
50
|
+
- Good: `@pre(lambda x: x > 0 and x < MAX_VALUE)`
|
|
51
|
+
- [ ] Does @post verify meaningful output properties?
|
|
52
|
+
- Bad: `@post(lambda result: result is not None)`
|
|
53
|
+
- Good: `@post(lambda result: len(result) == len(input))`
|
|
54
|
+
- [ ] Could someone implement correctly from contracts alone?
|
|
55
|
+
- [ ] Are boundary conditions explicit in contracts?
|
|
56
|
+
|
|
57
|
+
### B. Doctest Coverage
|
|
58
|
+
- [ ] Do doctests cover normal cases?
|
|
59
|
+
- [ ] Do doctests cover boundary cases?
|
|
60
|
+
- [ ] Do doctests cover error cases?
|
|
61
|
+
- [ ] Are doctests testing behavior, not just syntax?
|
|
62
|
+
|
|
63
|
+
### C. Code Quality
|
|
64
|
+
- [ ] Is duplicated code worth extracting?
|
|
65
|
+
- [ ] Is naming consistent and clear?
|
|
66
|
+
- [ ] Is complexity justified?
|
|
67
|
+
|
|
68
|
+
### D. Escape Hatch Audit
|
|
69
|
+
- [ ] Is each @invar:allow justification valid?
|
|
70
|
+
- [ ] Could refactoring eliminate the need?
|
|
71
|
+
- [ ] Is there a pattern suggesting systematic issues?
|
|
72
|
+
|
|
73
|
+
### E. Logic Verification
|
|
74
|
+
- [ ] Do contracts correctly capture intended behavior?
|
|
75
|
+
- [ ] Are there paths that bypass contract checks?
|
|
76
|
+
- [ ] Are there implicit assumptions not in contracts?
|
|
77
|
+
- [ ] What happens with unexpected inputs?
|
|
78
|
+
|
|
79
|
+
### F. Security
|
|
80
|
+
- [ ] Are inputs validated against security threats (injection, XSS)?
|
|
81
|
+
- [ ] No hardcoded secrets (API keys, passwords, tokens)?
|
|
82
|
+
- [ ] Are authentication/authorization checks correct?
|
|
83
|
+
- [ ] Is sensitive data properly protected?
|
|
84
|
+
|
|
85
|
+
### G. Error Handling & Observability
|
|
86
|
+
- [ ] Are exceptions caught at appropriate level?
|
|
87
|
+
- [ ] Are error messages clear without leaking sensitive info?
|
|
88
|
+
- [ ] Are critical operations logged for debugging?
|
|
89
|
+
- [ ] Is there graceful degradation on failure?
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Excluded (Covered by Guard)
|
|
94
|
+
|
|
95
|
+
These are checked by Guard or linters - don't duplicate:
|
|
96
|
+
- Core/Shell separation → Guard (forbidden_import, impure_call)
|
|
97
|
+
- Shell returns Result[T,E] → Guard (shell_result)
|
|
98
|
+
- Missing contracts → Guard (missing_contract)
|
|
99
|
+
- File/function size limits → Guard (file_size, function_size)
|
|
100
|
+
- Entry point thickness → Guard (entry_point_too_thick)
|
|
101
|
+
- Escape hatch count → Guard (review_suggested)
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Report Format
|
|
106
|
+
|
|
107
|
+
For each issue found, use severity levels:
|
|
108
|
+
|
|
109
|
+
| Severity | Meaning |
|
|
110
|
+
|----------|---------|
|
|
111
|
+
| **CRITICAL** | Must fix before completion |
|
|
112
|
+
| **MAJOR** | Fix or provide written justification |
|
|
113
|
+
| **MINOR** | Optional, can defer |
|
|
114
|
+
|
|
115
|
+
```markdown
|
|
116
|
+
### [CRITICAL/MAJOR/MINOR] Issue Title
|
|
117
|
+
|
|
118
|
+
**Location:** file.py:line_number
|
|
119
|
+
**Category:** contract_quality | logic_error | security | escape_hatch | code_smell
|
|
120
|
+
**Problem:** What's wrong
|
|
121
|
+
**Suggestion:** How to fix (but don't implement)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Instructions
|
|
127
|
+
|
|
128
|
+
1. Run `invar guard --changed` to see current state
|
|
129
|
+
2. Go through each checklist category
|
|
130
|
+
3. For each issue, determine severity (CRITICAL/MAJOR/MINOR)
|
|
131
|
+
4. Report with structured format above
|
|
132
|
+
5. Be thorough and adversarial
|
|
133
|
+
|
|
134
|
+
**Remember:** You are READ-ONLY. Report issues, don't fix them.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
Now review the recent changes or the files specified by the user.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Guard
|
|
2
|
+
|
|
3
|
+
Run Invar verification on the project and report results.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Behavior
|
|
8
|
+
|
|
9
|
+
Execute `invar_guard()` and report:
|
|
10
|
+
- Pass/fail status
|
|
11
|
+
- Error count with details
|
|
12
|
+
- Warning count with details
|
|
13
|
+
|
|
14
|
+
**Do NOT fix issues** - just report verification results.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## When to Use
|
|
19
|
+
|
|
20
|
+
- Quick verification check
|
|
21
|
+
- Before committing changes
|
|
22
|
+
- After pulling changes
|
|
23
|
+
- To see current project health
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Execution
|
|
28
|
+
|
|
29
|
+
Run verification:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
invar_guard(changed=true)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or for full project verification:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
invar_guard()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Report Format
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
## Guard Results
|
|
47
|
+
|
|
48
|
+
**Status:** PASS / FAIL
|
|
49
|
+
**Errors:** N
|
|
50
|
+
**Warnings:** N
|
|
51
|
+
|
|
52
|
+
### Errors (if any)
|
|
53
|
+
|
|
54
|
+
| Rule | File | Line | Message |
|
|
55
|
+
|------|------|------|---------|
|
|
56
|
+
| missing_contract | src/foo.py | 42 | Function 'bar' has no @pre/@post |
|
|
57
|
+
|
|
58
|
+
### Warnings (if any)
|
|
59
|
+
|
|
60
|
+
| Rule | File | Line | Message |
|
|
61
|
+
|------|------|------|---------|
|
|
62
|
+
| function_size | src/baz.py | 15 | Function exceeds 50 lines |
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Next Steps
|
|
68
|
+
|
|
69
|
+
After reporting results:
|
|
70
|
+
- If PASS: No action needed
|
|
71
|
+
- If FAIL: User decides whether to fix issues
|
|
72
|
+
|
|
73
|
+
**Remember:** You are READ-ONLY. Report results, don't fix them.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
Now run verification on the current project.
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
<!--invar:managed version="{{ version }}"-->
|
|
2
|
+
# Project Development Guide
|
|
3
|
+
|
|
4
|
+
> **Protocol:** Follow [INVAR.md](./INVAR.md) — includes Check-In, USBV workflow, and Task Completion requirements.
|
|
5
|
+
|
|
6
|
+
## Check-In (DX-54)
|
|
7
|
+
|
|
8
|
+
Your first message MUST display:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
✓ Check-In: [project] | [branch] | [clean/dirty]
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Actions:
|
|
15
|
+
1. Read `.invar/context.md` (Key Rules + Current State + Lessons Learned)
|
|
16
|
+
2. Show one-line status
|
|
17
|
+
|
|
18
|
+
Example:
|
|
19
|
+
```
|
|
20
|
+
✓ Check-In: MyProject | main | clean
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Do NOT execute guard or map at Check-In.**
|
|
24
|
+
Guard is for VALIDATE phase and Final only.
|
|
25
|
+
|
|
26
|
+
This is your sign-in. The user sees it immediately.
|
|
27
|
+
No visible check-in = Session not started.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Final
|
|
32
|
+
|
|
33
|
+
Your last message for an implementation task MUST display:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
✓ Final: guard PASS | 0 errors, 2 warnings
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
{% if syntax == "mcp" -%}
|
|
40
|
+
Execute `invar_guard()` and show this one-line summary.
|
|
41
|
+
{% else -%}
|
|
42
|
+
Execute `invar guard` and show this one-line summary.
|
|
43
|
+
{% endif %}
|
|
44
|
+
|
|
45
|
+
This is your sign-out. Completes the Check-In/Final pair.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Project Structure
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
src/{project}/
|
|
53
|
+
├── core/ # Pure logic (@pre/@post, doctests, no I/O)
|
|
54
|
+
└── shell/ # I/O operations (Result[T, E] return type)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Key insight:** Core receives data (strings), Shell handles I/O (paths, files).
|
|
58
|
+
|
|
59
|
+
## Quick Reference
|
|
60
|
+
|
|
61
|
+
| Zone | Requirements |
|
|
62
|
+
|------|-------------|
|
|
63
|
+
| Core | `@pre`/`@post` + doctests, pure (no I/O) |
|
|
64
|
+
| Shell | Returns `Result[T, E]` from `returns` library |
|
|
65
|
+
|
|
66
|
+
## Documentation Structure
|
|
67
|
+
|
|
68
|
+
| File | Owner | Edit? | Purpose |
|
|
69
|
+
|------|-------|-------|---------|
|
|
70
|
+
| INVAR.md | Invar | No | Protocol (`invar update` to sync) |
|
|
71
|
+
| CLAUDE.md | User | Yes | Project customization (this file) |
|
|
72
|
+
| .invar/context.md | User | Yes | Project state, lessons learned |
|
|
73
|
+
| .invar/examples/ | Invar | No | **Must read:** Core/Shell patterns, workflow |
|
|
74
|
+
|
|
75
|
+
## Visible Workflow (DX-30)
|
|
76
|
+
|
|
77
|
+
For complex tasks (3+ functions), show 3 checkpoints in TodoList:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
□ [UNDERSTAND] Task description, codebase context, constraints
|
|
81
|
+
□ [SPECIFY] Contracts (@pre/@post) and design decomposition
|
|
82
|
+
□ [VALIDATE] Guard results, Review Gate status, integration status
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**BUILD is internal work** — not shown in TodoList.
|
|
86
|
+
|
|
87
|
+
**Show contracts before code.** See `.invar/examples/workflow.md` for full example.
|
|
88
|
+
|
|
89
|
+
## Phase Visibility (DX-51)
|
|
90
|
+
|
|
91
|
+
Each USBV phase transition requires a visible header:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
95
|
+
📍 /develop → SPECIFY (2/4)
|
|
96
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Three-layer visibility:**
|
|
100
|
+
- **Skill** (`/develop`) — Routing announcement
|
|
101
|
+
- **Phase** (`SPECIFY 2/4`) — Phase header (this section)
|
|
102
|
+
- **Tasks** — TodoWrite items
|
|
103
|
+
|
|
104
|
+
Phase headers are SEPARATE from TodoWrite. Phase = where you are; TodoWrite = what to do.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Context Management (DX-54)
|
|
109
|
+
|
|
110
|
+
Re-read `.invar/context.md` when:
|
|
111
|
+
1. Entering any workflow (/develop, /review, etc.)
|
|
112
|
+
2. Completing a TodoWrite task (before moving to next)
|
|
113
|
+
3. Conversation exceeds ~15-20 exchanges
|
|
114
|
+
4. Unsure about project rules or patterns
|
|
115
|
+
|
|
116
|
+
**Refresh is transparent** — do not announce "I'm refreshing context."
|
|
117
|
+
Only show routing announcements when entering workflows.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Commands (User-Invokable)
|
|
122
|
+
|
|
123
|
+
| Command | Purpose |
|
|
124
|
+
|---------|---------|
|
|
125
|
+
| `/audit` | Read-only code review (reports issues, no fixes) |
|
|
126
|
+
| `/guard` | Run Invar verification (reports results) |
|
|
127
|
+
|
|
128
|
+
## Skills (Agent-Invoked)
|
|
129
|
+
|
|
130
|
+
| Skill | Triggers | Purpose |
|
|
131
|
+
|-------|----------|---------|
|
|
132
|
+
| `/investigate` | "why", "explain", vague tasks | Research mode, no code changes |
|
|
133
|
+
| `/propose` | "should we", "compare" | Decision facilitation |
|
|
134
|
+
| `/develop` | "add", "fix", "implement" | USBV implementation workflow |
|
|
135
|
+
| `/review` | After /develop, `review_suggested` | Adversarial review with fix loop |
|
|
136
|
+
|
|
137
|
+
**Note:** Skills are invoked by agent based on context. Use `/audit` for user-initiated review.
|
|
138
|
+
|
|
139
|
+
Guard triggers `review_suggested` for: security-sensitive files, escape hatches >= 3, contract coverage < 50%.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Workflow Routing (MANDATORY)
|
|
144
|
+
|
|
145
|
+
When user message contains these triggers, you MUST invoke the corresponding skill:
|
|
146
|
+
|
|
147
|
+
| Trigger Words | Skill | Notes |
|
|
148
|
+
|---------------|-------|-------|
|
|
149
|
+
| "review", "review and fix" | `/review` | Adversarial review with fix loop |
|
|
150
|
+
| "implement", "add", "fix", "update" | `/develop` | Unless in review context |
|
|
151
|
+
| "why", "explain", "investigate" | `/investigate` | Research mode, no code changes |
|
|
152
|
+
| "compare", "should we", "design" | `/propose` | Decision facilitation |
|
|
153
|
+
|
|
154
|
+
**Violation check (before writing ANY code):**
|
|
155
|
+
- "Am I in a workflow?"
|
|
156
|
+
- "Did I invoke the correct skill?"
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Routing Control (DX-42)
|
|
161
|
+
|
|
162
|
+
Agent announces routing decision before entering any workflow:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
📍 Routing: /[skill] — [trigger or reason]
|
|
166
|
+
Task: [summary]
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**User can redirect with natural language:**
|
|
170
|
+
- "wait" / "stop" — pause and ask for direction
|
|
171
|
+
- "just do it" — proceed with /develop
|
|
172
|
+
- "let's discuss" — switch to /propose
|
|
173
|
+
- "explain first" — switch to /investigate
|
|
174
|
+
|
|
175
|
+
**Simple task optimization:** For simple tasks (single file, clear target, <50 lines), agent may offer:
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
📊 Simple task. Auto-orchestrate? [Y/N]
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- Y → Full cycle without intermediate confirmations
|
|
182
|
+
- N → Normal step-by-step workflow
|
|
183
|
+
|
|
184
|
+
**Auto-review (DX-41):** When Guard outputs `review_suggested`, agent automatically
|
|
185
|
+
enters /review. Say "skip" to bypass.
|
|
186
|
+
<!--/invar:managed-->
|
|
187
|
+
|
|
188
|
+
<!--invar:project-->
|
|
189
|
+
<!-- ========================================================================
|
|
190
|
+
PROJECT REGION - INVAR PROJECT ONLY
|
|
191
|
+
This section is populated by .invar/project-additions.md via sync-self.
|
|
192
|
+
For other projects, this region remains empty.
|
|
193
|
+
======================================================================== -->
|
|
194
|
+
<!--/invar:project-->
|
|
195
|
+
|
|
196
|
+
<!--invar:user-->
|
|
197
|
+
<!-- ========================================================================
|
|
198
|
+
USER REGION - EDITABLE
|
|
199
|
+
Add your team conventions and project-specific rules below.
|
|
200
|
+
This section is preserved across invar update and sync-self.
|
|
201
|
+
======================================================================== -->
|
|
202
|
+
<!--/invar:user-->
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
*Generated by `invar init` v{{ version }}. Customize the user section freely.*
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Project Context
|
|
2
|
+
|
|
3
|
+
*Last updated: [DATE]*
|
|
4
|
+
|
|
5
|
+
## Current State
|
|
6
|
+
|
|
7
|
+
- Phase: [current development phase]
|
|
8
|
+
- Working on: [current task or feature]
|
|
9
|
+
- Blockers: None
|
|
10
|
+
|
|
11
|
+
## Key Rules (Quick Reference)
|
|
12
|
+
|
|
13
|
+
<!-- DX-54: Rules summary for long conversation resilience -->
|
|
14
|
+
|
|
15
|
+
### Core/Shell Separation
|
|
16
|
+
- **Core** (`**/core/**`): @pre/@post + doctests, NO I/O imports
|
|
17
|
+
- **Shell** (`**/shell/**`): Result[T, E] return type
|
|
18
|
+
|
|
19
|
+
### USBV Workflow
|
|
20
|
+
1. Understand → 2. Specify (contracts first) → 3. Build → 4. Validate
|
|
21
|
+
|
|
22
|
+
### Verification
|
|
23
|
+
{% if syntax == "mcp" -%}
|
|
24
|
+
- `invar_guard()` = static + doctests + CrossHair + Hypothesis
|
|
25
|
+
{% else -%}
|
|
26
|
+
- `invar guard` = static + doctests + CrossHair + Hypothesis
|
|
27
|
+
{% endif -%}
|
|
28
|
+
- Final must show: `✓ Final: guard PASS | ...`
|
|
29
|
+
|
|
30
|
+
## Self-Reminder
|
|
31
|
+
|
|
32
|
+
<!-- DX-54: AI should re-read this file periodically -->
|
|
33
|
+
|
|
34
|
+
**When to re-read this file:**
|
|
35
|
+
- Starting a new task
|
|
36
|
+
- Completing a task (before moving to next)
|
|
37
|
+
- Conversation has been going on for a while (~15-20 exchanges)
|
|
38
|
+
- Unsure about project rules or patterns
|
|
39
|
+
|
|
40
|
+
**Quick rule check:**
|
|
41
|
+
- Am I in Core or Shell?
|
|
42
|
+
- Do I have @pre/@post contracts?
|
|
43
|
+
- Am I following USBV workflow?
|
|
44
|
+
- Did I run guard before claiming "done"?
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Recent Decisions
|
|
49
|
+
|
|
50
|
+
1. [Decision summary] - [Brief rationale]
|
|
51
|
+
|
|
52
|
+
## Lessons Learned
|
|
53
|
+
|
|
54
|
+
1. [Pitfall or issue] → [Solution or workaround]
|
|
55
|
+
|
|
56
|
+
## Documentation Structure
|
|
57
|
+
|
|
58
|
+
| File | Owner | Edit? |
|
|
59
|
+
|------|-------|-------|
|
|
60
|
+
| INVAR.md | Invar | No — use `invar update` |
|
|
61
|
+
| CLAUDE.md | User | Yes |
|
|
62
|
+
| .invar/context.md | User | Yes (this file) |
|
|
63
|
+
| .invar/examples/ | Invar | No |
|
|
64
|
+
|
|
65
|
+
**Decision rule:** Is this Invar protocol or project-specific?
|
|
66
|
+
- Protocol content → Already in INVAR.md, don't duplicate
|
|
67
|
+
- Project-specific → Add to CLAUDE.md or here
|
|
68
|
+
|
|
69
|
+
## Technical Debt
|
|
70
|
+
|
|
71
|
+
{% if syntax == "mcp" -%}
|
|
72
|
+
*Run `invar_guard()` to check current status.*
|
|
73
|
+
{% else -%}
|
|
74
|
+
*Run `invar guard` to check current status.*
|
|
75
|
+
{% endif %}
|
|
76
|
+
|
|
77
|
+
| File | Warning | Priority |
|
|
78
|
+
|------|---------|----------|
|
|
79
|
+
| (none) | — | — |
|
|
80
|
+
|
|
81
|
+
## Key Files
|
|
82
|
+
|
|
83
|
+
| File | Purpose |
|
|
84
|
+
|------|---------|
|
|
85
|
+
| INVAR.md | Protocol reference (Invar-managed) |
|
|
86
|
+
| CLAUDE.md | Project guide (customize freely) |
|
|
87
|
+
| src/core/ | Pure business logic |
|
|
88
|
+
| src/shell/ | I/O adapters |
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
*Update this file when: completing major tasks, making design decisions, discovering pitfalls.*
|