invar-tools 1.8.0__py3-none-any.whl → 1.11.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 (117) hide show
  1. invar/__init__.py +8 -0
  2. invar/core/doc_edit.py +187 -0
  3. invar/core/doc_parser.py +563 -0
  4. invar/core/language.py +88 -0
  5. invar/core/models.py +106 -0
  6. invar/core/patterns/detector.py +6 -1
  7. invar/core/patterns/p0_exhaustive.py +15 -3
  8. invar/core/patterns/p0_literal.py +15 -3
  9. invar/core/patterns/p0_newtype.py +15 -3
  10. invar/core/patterns/p0_nonempty.py +15 -3
  11. invar/core/patterns/p0_validation.py +15 -3
  12. invar/core/patterns/registry.py +5 -1
  13. invar/core/patterns/types.py +5 -1
  14. invar/core/property_gen.py +4 -0
  15. invar/core/rules.py +84 -18
  16. invar/core/sync_helpers.py +27 -1
  17. invar/core/ts_parsers.py +286 -0
  18. invar/core/ts_sig_parser.py +310 -0
  19. invar/mcp/handlers.py +408 -0
  20. invar/mcp/server.py +288 -143
  21. invar/node_tools/MANIFEST +7 -0
  22. invar/node_tools/__init__.py +51 -0
  23. invar/node_tools/fc-runner/cli.js +77 -0
  24. invar/node_tools/quick-check/cli.js +28 -0
  25. invar/node_tools/ts-analyzer/cli.js +480 -0
  26. invar/shell/claude_hooks.py +35 -12
  27. invar/shell/commands/doc.py +409 -0
  28. invar/shell/commands/guard.py +41 -1
  29. invar/shell/commands/init.py +154 -16
  30. invar/shell/commands/perception.py +157 -33
  31. invar/shell/commands/skill.py +187 -0
  32. invar/shell/commands/template_sync.py +65 -13
  33. invar/shell/commands/uninstall.py +60 -12
  34. invar/shell/commands/update.py +6 -14
  35. invar/shell/contract_coverage.py +1 -0
  36. invar/shell/doc_tools.py +459 -0
  37. invar/shell/fs.py +67 -13
  38. invar/shell/pi_hooks.py +6 -0
  39. invar/shell/prove/crosshair.py +3 -0
  40. invar/shell/prove/guard_ts.py +902 -0
  41. invar/shell/skill_manager.py +355 -0
  42. invar/shell/template_engine.py +28 -4
  43. invar/shell/templates.py +4 -4
  44. invar/templates/claude-md/python/critical-rules.md +33 -0
  45. invar/templates/claude-md/python/quick-reference.md +24 -0
  46. invar/templates/claude-md/typescript/critical-rules.md +40 -0
  47. invar/templates/claude-md/typescript/quick-reference.md +24 -0
  48. invar/templates/claude-md/universal/check-in.md +25 -0
  49. invar/templates/claude-md/universal/skills.md +73 -0
  50. invar/templates/claude-md/universal/workflow.md +55 -0
  51. invar/templates/commands/{audit.md → audit.md.jinja} +18 -1
  52. invar/templates/config/AGENT.md.jinja +58 -0
  53. invar/templates/config/CLAUDE.md.jinja +16 -209
  54. invar/templates/config/context.md.jinja +19 -0
  55. invar/templates/examples/{README.md → python/README.md} +2 -0
  56. invar/templates/examples/{conftest.py → python/conftest.py} +1 -1
  57. invar/templates/examples/{contracts.py → python/contracts.py} +81 -4
  58. invar/templates/examples/python/core_shell.py +227 -0
  59. invar/templates/examples/python/functional.py +613 -0
  60. invar/templates/examples/typescript/README.md +31 -0
  61. invar/templates/examples/typescript/contracts.ts +163 -0
  62. invar/templates/examples/typescript/core_shell.ts +374 -0
  63. invar/templates/examples/typescript/functional.ts +601 -0
  64. invar/templates/examples/typescript/workflow.md +95 -0
  65. invar/templates/hooks/PostToolUse.sh.jinja +10 -1
  66. invar/templates/hooks/PreToolUse.sh.jinja +38 -0
  67. invar/templates/hooks/Stop.sh.jinja +1 -1
  68. invar/templates/hooks/UserPromptSubmit.sh.jinja +7 -0
  69. invar/templates/hooks/pi/invar.ts.jinja +9 -0
  70. invar/templates/manifest.toml +7 -6
  71. invar/templates/onboard/assessment.md.jinja +214 -0
  72. invar/templates/onboard/patterns/python.md +347 -0
  73. invar/templates/onboard/patterns/typescript.md +452 -0
  74. invar/templates/onboard/roadmap.md.jinja +168 -0
  75. invar/templates/protocol/INVAR.md.jinja +51 -0
  76. invar/templates/protocol/python/architecture-examples.md +41 -0
  77. invar/templates/protocol/python/contracts-syntax.md +56 -0
  78. invar/templates/protocol/python/markers.md +44 -0
  79. invar/templates/protocol/python/tools.md +24 -0
  80. invar/templates/protocol/python/troubleshooting.md +38 -0
  81. invar/templates/protocol/typescript/architecture-examples.md +52 -0
  82. invar/templates/protocol/typescript/contracts-syntax.md +73 -0
  83. invar/templates/protocol/typescript/markers.md +48 -0
  84. invar/templates/protocol/typescript/tools.md +65 -0
  85. invar/templates/protocol/typescript/troubleshooting.md +104 -0
  86. invar/templates/protocol/universal/architecture.md +36 -0
  87. invar/templates/protocol/universal/completion.md +14 -0
  88. invar/templates/protocol/universal/contracts-concept.md +37 -0
  89. invar/templates/protocol/universal/header.md +17 -0
  90. invar/templates/protocol/universal/session.md +17 -0
  91. invar/templates/protocol/universal/six-laws.md +10 -0
  92. invar/templates/protocol/universal/usbv.md +14 -0
  93. invar/templates/protocol/universal/visible-workflow.md +25 -0
  94. invar/templates/skills/develop/SKILL.md.jinja +85 -3
  95. invar/templates/skills/extensions/_registry.yaml +93 -0
  96. invar/templates/skills/extensions/acceptance/SKILL.md +383 -0
  97. invar/templates/skills/extensions/invar-onboard/SKILL.md +448 -0
  98. invar/templates/skills/extensions/invar-onboard/patterns/python.md +347 -0
  99. invar/templates/skills/extensions/invar-onboard/patterns/typescript.md +452 -0
  100. invar/templates/skills/extensions/invar-onboard/templates/assessment.md.jinja +214 -0
  101. invar/templates/skills/extensions/invar-onboard/templates/roadmap.md.jinja +168 -0
  102. invar/templates/skills/extensions/security/SKILL.md +382 -0
  103. invar/templates/skills/extensions/security/patterns/_common.yaml +126 -0
  104. invar/templates/skills/extensions/security/patterns/python.yaml +155 -0
  105. invar/templates/skills/extensions/security/patterns/typescript.yaml +194 -0
  106. invar/templates/skills/review/SKILL.md.jinja +220 -248
  107. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/METADATA +336 -12
  108. invar_tools-1.11.0.dist-info/RECORD +178 -0
  109. invar/templates/examples/core_shell.py +0 -127
  110. invar/templates/protocol/INVAR.md +0 -310
  111. invar_tools-1.8.0.dist-info/RECORD +0 -116
  112. /invar/templates/examples/{workflow.md → python/workflow.md} +0 -0
  113. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/WHEEL +0 -0
  114. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/entry_points.txt +0 -0
  115. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/licenses/LICENSE +0 -0
  116. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/licenses/LICENSE-GPL +0 -0
  117. {invar_tools-1.8.0.dist-info → invar_tools-1.11.0.dist-info}/licenses/NOTICE +0 -0
@@ -1,146 +1,161 @@
1
1
  ---
2
2
  name: review
3
- description: Fault-finding code review with REJECTION-FIRST mindset and AUTO-LOOP. Code is GUILTY until proven INNOCENT. Automatically cycles Reviewer→Fixer→Reviewer until quality_met or max_rounds. No human confirmation needed between roles.
3
+ description: Adversarial code review. Code is GUILTY until proven INNOCENT. Every round spawns isolated subagent reviewing FULL scope.
4
4
  _invar:
5
- version: "{{ version }}"
5
+ version: "7.0"
6
6
  managed: skill
7
7
  ---
8
8
  <!--invar:skill-->
9
9
 
10
- # Review Mode (Fault-Finding with Auto-Loop)
10
+ # Review Skill (Adversarial)
11
11
 
12
- > **Purpose:** Find problems that Guard, doctests, and property tests missed.
13
- > **Mindset:** REJECTION-FIRST. Code is GUILTY until proven INNOCENT.
14
- > **Success Metric:** Issues FOUND, not code approved. Zero issues = you failed to look hard enough.
15
- > **Workflow:** AUTOMATIC Reviewer↔Fixer loop until quality_met or max_rounds (no human confirmation).
12
+ ## Mandatory Rules (MUST follow, NO exceptions)
16
13
 
17
- ## Scope Boundaries
18
-
19
- **This skill IS for:**
20
- - Finding bugs and logic errors in existing code
21
- - Verifying contract semantic value
22
- - Auditing escape hatches
23
- - Security review
24
-
25
- **This skill is NOT for:**
26
- - Implementing new features → switch to `/develop`
27
- - Understanding how code works → switch to `/investigate`
28
- - Deciding on architecture → switch to `/propose`
29
-
30
- **Drift detection:** If you're writing significant new code (not fixes) → STOP, you're in wrong skill.
14
+ 1. **EVERY round MUST spawn isolated subagent** (Task tool with model=opus)
15
+ 2. **EVERY round reviews FULL scope** (all files, not just changes)
16
+ 3. **Code is GUILTY until proven INNOCENT**
17
+ 4. **NO user confirmation between rounds** just do it
18
+ 5. **MAX_ROUNDS = 5**
31
19
 
32
- ## Auto-Loop Configuration
33
-
34
- ```
35
- MAX_ROUNDS = 5 # Maximum review-fix cycles
36
- AUTO_TRANSITION = true # No human confirmation between roles
37
- ```
20
+ **Violation = Review Invalid.** If you skip subagent or review only changes, the review is worthless.
38
21
 
39
- ## Prime Directive: Reject Until Proven Correct
22
+ ---
40
23
 
41
- **You are the PROSECUTOR, not the defense attorney.**
24
+ ## Scope Classification (DX-75)
42
25
 
43
- | Trap | Reality Check |
44
- |------|---------------|
45
- | "Seems fine" | You failed to find the bug |
46
- | "Makes sense" | You're rationalizing, not reviewing |
47
- | "Edge case is unlikely" | Edge cases ARE bugs |
48
- | "Comment explains it" | Comments don't fix code |
49
- | "Assessed as acceptable" | "Assessed" ≠ "Fixed" |
26
+ **Before starting, classify the scope:**
50
27
 
51
- ## Role Separation (CRITICAL)
28
+ | Classification | Criteria | Strategy |
29
+ |----------------|----------|----------|
30
+ | **SMALL** | <5 files AND <1500 lines | THOROUGH (no enumeration) |
31
+ | **MEDIUM** | 5-10 files OR 1500-5000 lines | HYBRID (enum + open) |
32
+ | **LARGE** | >10 files OR >5000 lines | CHUNKED (parallel subagents) |
52
33
 
53
- **You play TWO distinct roles that cycle AUTOMATICALLY:**
34
+ **Why different strategies?**
35
+ - SMALL: Pre-enumeration causes "checklist mentality" — you only verify listed items, miss variants
36
+ - LARGE: Without enumeration, attention drifts — later files get less scrutiny
54
37
 
55
- | Role | Allowed Actions | Forbidden |
56
- |------|-----------------|-----------|
57
- | **REVIEWER** | Find issues, judge fixes, declare quality_met | Write code, rationalize issues |
58
- | **FIXER** | Implement fixes only | Declare quality_met, dismiss issues |
38
+ ---
59
39
 
60
- **Role Transition Markers (REQUIRED):**
40
+ ## Strategy: THOROUGH (SMALL scope)
61
41
 
62
42
  ```
63
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
64
- 🔍 REVIEWER [Round N] — Finding issues
65
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
66
-
67
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
68
- 🔧 FIXER [Round N] Implementing fixes
69
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
70
-
71
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
72
- REVIEWER [Round N] Verifying fixes
73
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
43
+ ┌─────────────────────────────────────────────────────────────┐
44
+ │ THOROUGH STRATEGY (for SMALL scope) │
45
+ │ ───────────────────────────────────────────────────────────│
46
+ │ │
47
+ │ ⚠️ DO NOT pre-enumerate issues or patterns │
48
+ │ ⚠️ DO NOT use grep/sig to "find issues first" │
49
+ │ │
50
+ │ Instead: │
51
+ │ 1. Read each file COMPLETELY, line by line │
52
+ │ 2. Apply checklist A-G as you read │
53
+ │ 3. Trust your judgment to find issues │
54
+ │ 4. Look for VARIANTS and EDGE CASES │
55
+ │ │
56
+ │ Why: Pre-enumeration narrows focus to known patterns. │
57
+ │ Small scope = you CAN read everything thoroughly. │
58
+ │ This finds issues that pattern matching misses. │
59
+ └─────────────────────────────────────────────────────────────┘
74
60
  ```
75
61
 
76
- ## Quality Gate Authority
77
-
78
- **ONLY the Reviewer role can declare `quality_met`.**
79
-
80
- Before declaring exit:
81
- 1. Re-read EVERY issue found
82
- 2. For each issue, verify: "Is this ACTUALLY fixed, or did I rationalize it?"
83
- 3. Ask: "Would I accept this excuse from someone else's code?"
84
-
85
- **Self-Check Questions:**
86
- - Did I write code AND declare quality_met? → Role confusion detected
87
- - Did I say "assessed" instead of "fixed"? → Rationalization detected
88
- - Did any MAJOR become a comment instead of code? → Fix failed
89
-
90
- ## Fault-Finding Persona
62
+ ## Strategy: HYBRID (MEDIUM scope)
91
63
 
92
- Assume:
93
- - The code has bugs until proven otherwise
94
- - The contracts may be meaningless ceremony
95
- - The implementer may have rationalized poor decisions
96
- - Escape hatches may be abused
97
- - **Your own fixes may introduce new bugs**
98
-
99
- You ARE here to:
100
- - Find bugs, logic errors, edge cases
101
- - Challenge whether contracts have semantic value
102
- - Check if code matches contracts (not if code "seems right")
103
- - **RE-VERIFY fixes, not trust them**
104
-
105
- ## Entry Actions
106
-
107
- ### Context Refresh (DX-54)
108
-
109
- Before any workflow action:
110
- 1. Read `.invar/context.md` (especially Key Rules section)
111
- 2. Display routing announcement
64
+ ```
65
+ ┌─────────────────────────────────────────────────────────────┐
66
+ │ HYBRID STRATEGY (for MEDIUM scope) │
67
+ │ ───────────────────────────────────────────────────────────│
68
+ │ │
69
+ │ Phase 0: ENUMERATE (Main Agent) │
70
+ │ ┌─────────────────────────────────────────────────────┐ │
71
+ │ │ Use grep/invar_sig to find: │ │
72
+ │ │ - All @pre/@post contracts │ │
73
+ │ │ - All @invar:allow escape hatches │ │
74
+ │ │ - Hardcoded strings (secrets?) │ │
75
+ │ │ - subprocess/exec/eval calls │ │
76
+ │ │ - bare except clauses │ │
77
+ │ │ Create issue_map with file:line for each │ │
78
+ │ └─────────────────────────────────────────────────────┘ │
79
+ │ │
80
+ │ Phase 1: GUIDED REVIEW (Isolated Subagent) │
81
+ │ ┌─────────────────────────────────────────────────────┐ │
82
+ │ │ Pass issue_map to subagent │ │
83
+ │ │ Subagent verifies each item │ │
84
+ │ │ Reports: "Checked N/M items from issue_map" │ │
85
+ │ └─────────────────────────────────────────────────────┘ │
86
+ │ │
87
+ │ Phase 2: OPEN DISCOVERY (Same Subagent) │
88
+ │ ┌─────────────────────────────────────────────────────┐ │
89
+ │ │ "Now forget the issue_map. │ │
90
+ │ │ Look for issues NOT in the map: │ │
91
+ │ │ - Variants of listed patterns │ │
92
+ │ │ - Logic errors │ │
93
+ │ │ - Edge cases" │ │
94
+ │ │ Reports: "Found N additional issues" │ │
95
+ │ └─────────────────────────────────────────────────────┘ │
96
+ └─────────────────────────────────────────────────────────────┘
97
+ ```
112
98
 
113
- ### Routing Announcement
99
+ ## Strategy: CHUNKED (LARGE scope)
114
100
 
115
101
  ```
116
- 📍 Routing: /review — [trigger, e.g. "review_suggested", "user requested review"]
117
- Task: [review scope summary]
102
+ ┌─────────────────────────────────────────────────────────────┐
103
+ │ CHUNKED STRATEGY (for LARGE scope) │
104
+ │ ───────────────────────────────────────────────────────────│
105
+ │ │
106
+ │ 1. Split files into chunks of ~3-5 files each │
107
+ │ │
108
+ │ 2. For each chunk (can be parallel): │
109
+ │ - Spawn isolated subagent │
110
+ │ - Use HYBRID strategy within chunk │
111
+ │ │
112
+ │ 3. Cross-chunk analysis: │
113
+ │ - Check cross-file dependencies │
114
+ │ - Check API consistency │
115
+ │ │
116
+ │ 4. Merge all findings, deduplicate │
117
+ │ │
118
+ │ Why: Prevents "attention fatigue" on file 8+ of 15. │
119
+ │ Each chunk gets fresh attention. │
120
+ └─────────────────────────────────────────────────────────────┘
118
121
  ```
119
122
 
120
- ## Mode Selection
123
+ ---
121
124
 
122
- ### Check Guard Output
125
+ ## 2-Step Loop (MANDATORY workflow)
123
126
 
124
- Look for `review_suggested` warning:
125
127
  ```
126
- WARNING: review_suggested - High escape hatch count
127
- WARNING: review_suggested - Security-sensitive path detected
128
- WARNING: review_suggested - Low contract coverage
128
+ ┌─────────────────────────────────────────────────────────────┐
129
+ │ Round N:
130
+ │ │
131
+ │ 1. REVIEWER [Subagent] ─────────────────────────────────── │
132
+ │ • Spawn NEW isolated agent (Task tool) │
133
+ │ • Use strategy based on scope classification │
134
+ │ • Review ALL files in scope (full checklist A-G) │
135
+ │ • Return: issues[] or APPROVED │
136
+ │ │
137
+ │ 2. FIXER [Main Agent] ──────────────────────────────────── │
138
+ │ • Fix CRITICAL/MAJOR issues with CODE │
139
+ │ • Run invar_guard() │
140
+ │ • Cannot declare quality_met │
141
+ │ │
142
+ │ → Loop until: APPROVED OR max_rounds OR no_progress │
143
+ └─────────────────────────────────────────────────────────────┘
129
144
  ```
130
145
 
131
- ### Select Mode
146
+ **Why new subagent each round?**
147
+ - Main agent has context contamination from fixing
148
+ - "Fresh eyes" impossible in same context
149
+ - Round 2+ drifts to "verify my fixes" not "find problems"
132
150
 
133
- | Condition | Mode |
134
- |-----------|------|
135
- | `review_suggested` present | **Isolated** (spawn sub-agent) |
136
- | `--isolated` flag | **Isolated** |
137
- | Default (no trigger) | **Quick** (same context) |
151
+ ---
138
152
 
139
- ## Review Checklist
153
+ ## Review Checklist (apply to ALL files)
140
154
 
141
- > **Principle:** Only items requiring semantic judgment. Mechanical checks are handled by Guard.
155
+ > **Principle:** Only items requiring semantic judgment. Mechanical checks handled by Guard.
142
156
 
143
157
  ### A. Contract Semantic Value
158
+
144
159
  - [ ] Does @pre constrain inputs beyond type checking?
145
160
  - Bad: `@pre(lambda x: isinstance(x, int))`
146
161
  - Good: `@pre(lambda x: x > 0 and x < MAX_VALUE)`
@@ -151,203 +166,160 @@ WARNING: review_suggested - Low contract coverage
151
166
  - [ ] Are boundary conditions explicit in contracts?
152
167
 
153
168
  ### B. Doctest Coverage
154
- - [ ] Do doctests cover normal cases?
155
- - [ ] Do doctests cover boundary cases?
156
- - [ ] Do doctests cover error cases?
169
+
170
+ - [ ] Do doctests cover normal, boundary, and error cases?
157
171
  - [ ] Are doctests testing behavior, not just syntax?
158
172
 
159
173
  ### C. Code Quality
174
+
160
175
  - [ ] Is duplicated code worth extracting?
161
176
  - [ ] Is naming consistent and clear?
162
177
  - [ ] Is complexity justified?
163
178
 
164
179
  ### D. Escape Hatch Audit
180
+
165
181
  - [ ] Is each @invar:allow justification valid?
166
182
  - [ ] Could refactoring eliminate the need?
167
- - [ ] Is there a pattern suggesting systematic issues?
168
183
 
169
184
  ### E. Logic Verification
185
+
170
186
  - [ ] Do contracts correctly capture intended behavior?
171
187
  - [ ] Are there paths that bypass contract checks?
172
188
  - [ ] Are there implicit assumptions not in contracts?
173
- - [ ] Is there dead code or unreachable branches?
174
189
 
175
190
  ### F. Security
191
+
176
192
  - [ ] Are inputs validated against security threats (injection, XSS)?
177
193
  - [ ] No hardcoded secrets (API keys, passwords, tokens)?
178
194
  - [ ] Are authentication/authorization checks correct?
179
- - [ ] Is sensitive data properly protected?
180
195
 
181
- ### G. Error Handling & Observability
196
+ ### G. Error Handling
197
+
182
198
  - [ ] Are exceptions caught at appropriate level?
183
199
  - [ ] Are error messages clear without leaking sensitive info?
184
- - [ ] Are critical operations logged for debugging?
185
200
  - [ ] Is there graceful degradation on failure?
186
201
 
187
- ## Excluded (Covered by Guard)
188
-
189
- These are checked by Guard or linters - don't duplicate:
190
- - Core/Shell separation → Guard (forbidden_import, impure_call)
191
- - Shell returns Result[T,E] → Guard (shell_result)
192
- - Missing contracts → Guard (missing_contract)
193
- - File/function size limits → Guard (file_size, function_size)
194
- - Entry point thickness → Guard (entry_point_too_thick)
195
- - Escape hatch count → Guard (review_suggested)
202
+ ---
196
203
 
197
- ## Auto-Loop Workflow (NO HUMAN CONFIRMATION)
204
+ ## Subagent Prompt Templates
198
205
 
199
- **The loop runs AUTOMATICALLY until exit condition is met.**
206
+ ### THOROUGH (SMALL scope)
200
207
 
201
208
  ```
202
- ┌─────────────────────────────────────────────────────────────────┐
203
- │ START: round = 1, issues = [] │
204
- │ │
205
- │ ┌─────────────────────────────────────────────────────────┐ │
206
- │ │ 🔍 REVIEWER [Round N] │ │
207
- │ │ 1. Find ALL issues (don't stop at first) │ │
208
- │ │ 2. Classify: CRITICAL / MAJOR / MINOR │ │
209
- │ │ 3. Add to issues table │ │
210
- │ │ 4. IF no CRITICAL/MAJOR → quality_met, EXIT │ │
211
- │ │ 5. ELSE AUTO-TRANSITION to FIXER │ │
212
- │ └─────────────────────────────────────────────────────────┘ │
213
- │ ↓ (automatic) │
214
- │ ┌─────────────────────────────────────────────────────────┐ │
215
- │ │ 🔧 FIXER [Round N] │ │
216
- │ │ 1. Fix EACH CRITICAL/MAJOR issue with CODE │ │
217
- │ │ 2. Run invar_guard() after fixes │ │
218
- │ │ 3. NO declaring quality_met (forbidden) │ │
219
- │ │ 4. AUTO-TRANSITION back to REVIEWER │ │
220
- │ └─────────────────────────────────────────────────────────┘ │
221
- │ ↓ (automatic) │
222
- │ ┌─────────────────────────────────────────────────────────┐ │
223
- │ │ ✅ REVIEWER [Round N] Verification │ │
224
- │ │ 1. Re-verify EACH fix: │ │
225
- │ │ - Is fix CODE or just COMMENT? │ │
226
- │ │ - Does fix actually address issue? │ │
227
- │ │ - Did fix introduce new issues? │ │
228
- │ │ 2. Update verification table │ │
229
- │ │ 3. IF all CRITICAL/MAJOR fixed → quality_met, EXIT │ │
230
- │ │ 4. IF round >= MAX_ROUNDS → max_rounds, EXIT │ │
231
- │ │ 5. IF no progress → no_improvement, EXIT │ │
232
- │ │ 6. ELSE → round++, LOOP to REVIEWER [Round N+1] │ │
233
- │ └─────────────────────────────────────────────────────────┘ │
234
- │ │
235
- │ EXIT: Generate final report │
236
- └─────────────────────────────────────────────────────────────────┘
209
+ You are an independent Adversarial Code Reviewer.
210
+
211
+ RULES:
212
+ 1. Code is GUILTY until proven INNOCENT
213
+ 2. You did NOT write this code — no emotional attachment
214
+ 3. Find reasons to REJECT, not accept
215
+ 4. Be specific: file:line + concrete fix
216
+
217
+ STRATEGY: THOROUGH READING
218
+ - Read each file COMPLETELY, line by line
219
+ - DO NOT pre-scan for patterns — just READ
220
+ - Look for VARIANTS and EDGE CASES
221
+ - Trust your judgment
222
+
223
+ SCOPE: [list all files]
224
+
225
+ Apply checklist A-G to each file.
226
+
227
+ OUTPUT FORMAT:
228
+ ## Verdict: APPROVED | NEEDS WORK | REJECTED
229
+ ## Critical Issues (must fix)
230
+ | ID | File:Line | Issue | Fix |
231
+ ## Major Issues (should fix)
232
+ | ID | File:Line | Issue | Fix |
233
+ ## Minor Issues (backlog)
234
+ | ID | File:Line | Issue | Fix |
237
235
  ```
238
236
 
239
- ## Loop State Tracking
237
+ ### HYBRID (MEDIUM scope)
240
238
 
241
- **Maintain this state throughout the loop:**
242
-
243
- ```markdown
244
- ## Review State
245
- - **Round:** N / MAX_ROUNDS
246
- - **Role:** REVIEWER | FIXER
247
- - **Issues Found:** [count]
248
- - **Issues Fixed:** [count]
249
- - **Guard Status:** PASS | FAIL
250
239
  ```
240
+ You are an independent Adversarial Code Reviewer.
241
+
242
+ RULES:
243
+ 1. Code is GUILTY until proven INNOCENT
244
+ 2. You did NOT write this code — no emotional attachment
245
+ 3. Find reasons to REJECT, not accept
246
+ 4. Be specific: file:line + concrete fix
247
+
248
+ STRATEGY: HYBRID (two passes)
251
249
 
252
- ## Verification Table (Updated Each Round)
250
+ PASS 1 - GUIDED:
251
+ Using this issue_map, verify each potential issue:
252
+ [issue_map from Phase 0]
253
253
 
254
- | Issue ID | Severity | Round Found | Status | Evidence |
255
- |----------|----------|-------------|--------|----------|
256
- | MAJOR-1 | MAJOR | 1 | ✅ Fixed (R2) | Code change at line X |
257
- | MAJOR-2 | MAJOR | 1 | ❌ Unfixed | Fix attempted but failed |
258
- | MAJOR-3 | MAJOR | 2 | 🔄 New | Found during re-verification |
259
- | ... | ... | ... | ... | ... |
254
+ Report: "Verified X/Y items from issue_map"
260
255
 
261
- **Status Legend:**
262
- - Fixed (RN) Actually fixed with code in round N
263
- - Unfixed Fix failed or was just a comment
264
- - 🔄 New Found during re-verification (new issue)
265
- - ⏭️ Backlog — MINOR, deferred to later
256
+ PASS 2 - OPEN DISCOVERY:
257
+ Now FORGET the issue_map. Read the code fresh.
258
+ Look for issues NOT in the map:
259
+ - Variants of listed patterns
260
+ - Logic errors
261
+ - Edge cases
266
262
 
267
- If ANY exists for CRITICAL/MAJOR after MAX_ROUNDS → quality_not_met
263
+ Report: "Found N additional issues not in issue_map"
268
264
 
269
- ## Severity Definitions
265
+ SCOPE: [list all files]
270
266
 
271
- | Level | Meaning | Examples | Exit Blocker? |
272
- |-------|---------|----------|---------------|
273
- | CRITICAL | Security, data loss, crash | SQL injection, unhandled null | **YES** |
274
- | MAJOR | Logic error, missing validation | Wrong calculation, no bounds | **YES** |
275
- | MINOR | Style, documentation | Naming, missing docstring | No (backlog) |
267
+ OUTPUT FORMAT:
268
+ ## Verdict: APPROVED | NEEDS WORK | REJECTED
269
+ ## From Issue Map (Pass 1)
270
+ | ID | File:Line | Issue | Fix |
271
+ ## Additional Findings (Pass 2)
272
+ | ID | File:Line | Issue | Fix |
273
+ ```
276
274
 
277
- ## Exit Conditions (Auto-Loop)
275
+ ---
278
276
 
279
- **Exit triggers (checked automatically after each REVIEWER phase):**
277
+ ## Exit Conditions
280
278
 
281
279
  | Condition | Exit Reason | Result |
282
280
  |-----------|-------------|--------|
283
- | All CRITICAL/MAJOR fixed | `quality_met` | Ready for merge |
284
- | Round >= MAX_ROUNDS | `max_rounds` | ⚠️ Manual review needed |
285
- | No progress (same issues 2 rounds) | `no_improvement` | Architectural issue |
286
- | Guard fails after fix | Continue loop | 🔄 More fixes needed |
287
-
288
- **quality_met requires ALL of:**
289
- 1. Zero CRITICAL issues remaining
290
- 2. Zero MAJOR issues remaining (not "assessed", actually FIXED)
291
- 3. Verification table completed with evidence for each fix
292
- 4. Guard passes after all fixes
293
-
294
- **Automatic quality_not_met:**
295
- - Any MAJOR "fixed" with comment instead of code
296
- - Any issue marked "assessed" or "acceptable"
297
- - Fixer role declared quality_met (role violation)
298
- - Infinite loop detected (no progress)
299
-
300
- ## Exit Report (Generated Automatically)
301
-
302
- ```markdown
281
+ | Subagent returns APPROVED | `quality_met` | Ready for merge |
282
+ | round >= 5 | `max_rounds` | Manual review needed |
283
+ | Same issues 2 rounds | `no_improvement` | Architectural issue |
284
+
285
+ ---
286
+
287
+ ## Exit Report
288
+
289
+ ```
303
290
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
304
291
  📋 REVIEW COMPLETE
305
292
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
306
293
 
307
- **Exit Reason:** quality_met | max_rounds | no_improvement
308
- **Total Rounds:** N / MAX_ROUNDS
309
- **Guard Status:** PASS | FAIL
310
-
311
- ## Verification Table
294
+ **Scope:** SMALL | MEDIUM | LARGE
295
+ **Strategy:** THOROUGH | HYBRID | CHUNKED
296
+ **Exit:** quality_met | max_rounds | no_improvement
297
+ **Rounds:** N / 5
298
+ **Guard:** PASS | FAIL
312
299
 
300
+ ## Issues Table
313
301
  | Issue | Severity | Round | Status | Evidence |
314
- |-------|----------|-------|--------|----------|
315
- | MAJOR-1 | MAJOR | 1→2 | ✅ Fixed | Code at file.py:123 |
316
- | ... | ... | ... | ... | ... |
317
302
 
318
- ## Statistics
303
+ ## Round Summary
304
+ | Round | Found | Fixed |
319
305
 
320
- - Issues Found: X
321
- - Issues Fixed: Y
322
- - Fix Rate: Y/X (Z%)
323
- - New Issues from Fixes: N
306
+ Final: guard PASS | X errors, Y warnings
307
+ ```
324
308
 
325
- ## Self-Check (Reviewer Final)
309
+ ---
326
310
 
327
- - [x] All fixes are CODE, not comments
328
- - [x] No "assessed as acceptable" rationalizations
329
- - [x] Guard passes after all changes
330
- - [x] Role separation maintained throughout
311
+ ## Scope Boundaries
331
312
 
332
- ## Recommendation
313
+ **IS for:** Finding bugs, verifying contracts, security review
314
+ **NOT for:** New features → /develop | Understanding → /investigate
333
315
 
334
- - [x] Ready for merge (quality_met)
335
- - [ ] Needs manual review (max_rounds)
336
- - [ ] Architectural refactor needed (no_improvement)
316
+ ## Excluded (Covered by Guard)
337
317
 
338
- **MINOR (Backlog):**
339
- - [list deferred items]
340
- ```
341
- <!--/invar:skill-->
342
- <!--invar:extensions-->
343
- <!-- ========================================================================
344
- EXTENSIONS REGION - USER EDITABLE
345
- Add project-specific extensions here. This section is preserved on update.
346
-
347
- Examples of what to add:
348
- - Project-specific security review checklists
349
- - Custom severity definitions
350
- - Domain-specific code patterns to check
351
- - Team code review standards
352
- ======================================================================== -->
318
+ Don't duplicate mechanical checks:
319
+ - Core/Shell separation → Guard
320
+ - Missing contracts → Guard
321
+ - File/function size → Guard
322
+
323
+ <!--/invar:skill--><!--invar:extensions-->
324
+ <!-- User extensions preserved on update -->
353
325
  <!--/invar:extensions-->