invar-tools 1.7.1__py3-none-any.whl → 1.10.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 (113) hide show
  1. invar/__init__.py +8 -0
  2. invar/core/language.py +88 -0
  3. invar/core/models.py +106 -0
  4. invar/core/patterns/detector.py +6 -1
  5. invar/core/patterns/p0_exhaustive.py +15 -3
  6. invar/core/patterns/p0_literal.py +15 -3
  7. invar/core/patterns/p0_newtype.py +15 -3
  8. invar/core/patterns/p0_nonempty.py +15 -3
  9. invar/core/patterns/p0_validation.py +15 -3
  10. invar/core/patterns/registry.py +5 -1
  11. invar/core/patterns/types.py +5 -1
  12. invar/core/property_gen.py +4 -0
  13. invar/core/rules.py +84 -18
  14. invar/core/sync_helpers.py +27 -1
  15. invar/core/template_helpers.py +32 -0
  16. invar/core/ts_parsers.py +286 -0
  17. invar/core/ts_sig_parser.py +307 -0
  18. invar/node_tools/MANIFEST +7 -0
  19. invar/node_tools/__init__.py +51 -0
  20. invar/node_tools/fc-runner/cli.js +77 -0
  21. invar/node_tools/quick-check/cli.js +28 -0
  22. invar/node_tools/ts-analyzer/cli.js +480 -0
  23. invar/shell/claude_hooks.py +35 -12
  24. invar/shell/commands/guard.py +36 -1
  25. invar/shell/commands/init.py +133 -7
  26. invar/shell/commands/perception.py +157 -33
  27. invar/shell/commands/skill.py +187 -0
  28. invar/shell/commands/template_sync.py +65 -13
  29. invar/shell/commands/uninstall.py +77 -12
  30. invar/shell/commands/update.py +6 -14
  31. invar/shell/contract_coverage.py +1 -0
  32. invar/shell/fs.py +66 -13
  33. invar/shell/pi_hooks.py +213 -0
  34. invar/shell/prove/guard_ts.py +899 -0
  35. invar/shell/skill_manager.py +353 -0
  36. invar/shell/template_engine.py +28 -4
  37. invar/shell/templates.py +4 -4
  38. invar/templates/claude-md/python/critical-rules.md +33 -0
  39. invar/templates/claude-md/python/quick-reference.md +24 -0
  40. invar/templates/claude-md/typescript/critical-rules.md +40 -0
  41. invar/templates/claude-md/typescript/quick-reference.md +24 -0
  42. invar/templates/claude-md/universal/check-in.md +25 -0
  43. invar/templates/claude-md/universal/skills.md +73 -0
  44. invar/templates/claude-md/universal/workflow.md +55 -0
  45. invar/templates/commands/{audit.md → audit.md.jinja} +18 -1
  46. invar/templates/config/AGENT.md.jinja +256 -0
  47. invar/templates/config/CLAUDE.md.jinja +16 -209
  48. invar/templates/config/context.md.jinja +19 -0
  49. invar/templates/examples/{README.md → python/README.md} +2 -0
  50. invar/templates/examples/{conftest.py → python/conftest.py} +1 -1
  51. invar/templates/examples/{contracts.py → python/contracts.py} +81 -4
  52. invar/templates/examples/python/core_shell.py +227 -0
  53. invar/templates/examples/python/functional.py +613 -0
  54. invar/templates/examples/typescript/README.md +31 -0
  55. invar/templates/examples/typescript/contracts.ts +163 -0
  56. invar/templates/examples/typescript/core_shell.ts +374 -0
  57. invar/templates/examples/typescript/functional.ts +601 -0
  58. invar/templates/examples/typescript/workflow.md +95 -0
  59. invar/templates/hooks/PostToolUse.sh.jinja +10 -1
  60. invar/templates/hooks/PreToolUse.sh.jinja +38 -0
  61. invar/templates/hooks/Stop.sh.jinja +1 -1
  62. invar/templates/hooks/UserPromptSubmit.sh.jinja +7 -0
  63. invar/templates/hooks/pi/invar.ts.jinja +82 -0
  64. invar/templates/manifest.toml +8 -6
  65. invar/templates/onboard/assessment.md.jinja +214 -0
  66. invar/templates/onboard/patterns/python.md +347 -0
  67. invar/templates/onboard/patterns/typescript.md +452 -0
  68. invar/templates/onboard/roadmap.md.jinja +168 -0
  69. invar/templates/protocol/INVAR.md.jinja +51 -0
  70. invar/templates/protocol/python/architecture-examples.md +41 -0
  71. invar/templates/protocol/python/contracts-syntax.md +56 -0
  72. invar/templates/protocol/python/markers.md +44 -0
  73. invar/templates/protocol/python/tools.md +24 -0
  74. invar/templates/protocol/python/troubleshooting.md +38 -0
  75. invar/templates/protocol/typescript/architecture-examples.md +52 -0
  76. invar/templates/protocol/typescript/contracts-syntax.md +73 -0
  77. invar/templates/protocol/typescript/markers.md +48 -0
  78. invar/templates/protocol/typescript/tools.md +65 -0
  79. invar/templates/protocol/typescript/troubleshooting.md +104 -0
  80. invar/templates/protocol/universal/architecture.md +36 -0
  81. invar/templates/protocol/universal/completion.md +14 -0
  82. invar/templates/protocol/universal/contracts-concept.md +37 -0
  83. invar/templates/protocol/universal/header.md +17 -0
  84. invar/templates/protocol/universal/session.md +17 -0
  85. invar/templates/protocol/universal/six-laws.md +10 -0
  86. invar/templates/protocol/universal/usbv.md +14 -0
  87. invar/templates/protocol/universal/visible-workflow.md +25 -0
  88. invar/templates/skills/develop/SKILL.md.jinja +98 -3
  89. invar/templates/skills/extensions/_registry.yaml +93 -0
  90. invar/templates/skills/extensions/acceptance/SKILL.md +383 -0
  91. invar/templates/skills/extensions/invar-onboard/SKILL.md +448 -0
  92. invar/templates/skills/extensions/invar-onboard/patterns/python.md +347 -0
  93. invar/templates/skills/extensions/invar-onboard/patterns/typescript.md +452 -0
  94. invar/templates/skills/extensions/invar-onboard/templates/assessment.md.jinja +214 -0
  95. invar/templates/skills/extensions/invar-onboard/templates/roadmap.md.jinja +168 -0
  96. invar/templates/skills/extensions/security/SKILL.md +382 -0
  97. invar/templates/skills/extensions/security/patterns/_common.yaml +126 -0
  98. invar/templates/skills/extensions/security/patterns/python.yaml +155 -0
  99. invar/templates/skills/extensions/security/patterns/typescript.yaml +194 -0
  100. invar/templates/skills/investigate/SKILL.md.jinja +15 -0
  101. invar/templates/skills/propose/SKILL.md.jinja +33 -0
  102. invar/templates/skills/review/SKILL.md.jinja +346 -71
  103. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/METADATA +326 -19
  104. invar_tools-1.10.0.dist-info/RECORD +173 -0
  105. invar/templates/examples/core_shell.py +0 -127
  106. invar/templates/protocol/INVAR.md +0 -310
  107. invar_tools-1.7.1.dist-info/RECORD +0 -112
  108. /invar/templates/examples/{workflow.md → python/workflow.md} +0 -0
  109. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/WHEEL +0 -0
  110. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/entry_points.txt +0 -0
  111. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/licenses/LICENSE +0 -0
  112. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/licenses/LICENSE-GPL +0 -0
  113. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/licenses/NOTICE +0 -0
@@ -1,8 +1,8 @@
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 ReviewerFixer→Reviewer until quality_met or max_rounds. No human confirmation needed between roles.
3
+ description: Fault-finding code review with REJECTION-FIRST mindset. Code is GUILTY until proven INNOCENT. Two-step loop (ReviewFix) with full-scope review each round. Use after development, when Guard reports review_suggested, or user explicitly requests review.
4
4
  _invar:
5
- version: "{{ version }}"
5
+ version: "5.3"
6
6
  managed: skill
7
7
  ---
8
8
  <!--invar:skill-->
@@ -12,15 +12,124 @@ _invar:
12
12
  > **Purpose:** Find problems that Guard, doctests, and property tests missed.
13
13
  > **Mindset:** REJECTION-FIRST. Code is GUILTY until proven INNOCENT.
14
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).
15
+ > **Workflow:** Two-step loop: Review Fix Review → Fix → ... (full scope each round, no separate "verify" step).
16
+
17
+ ## Depth Levels (DX-70)
18
+
19
+ | Level | Context | Use Case |
20
+ |-------|---------|----------|
21
+ | (default) | Same context | Reviewing **others' code** only |
22
+ | `--deep` | **Isolated agent** | Self-review, before merge, maximum objectivity |
23
+
24
+ **Default:** Same context — **only appropriate for code you did NOT write**.
25
+
26
+ **`--deep` mode:** Spawns isolated agent with no conversation history. **Required when:**
27
+ - You wrote or modified the code being reviewed (self-review)
28
+ - Before merge/PR
29
+ - Maximum objectivity needed
30
+
31
+ ### ⚠️ Same-Context Review Limitations (CRITICAL)
32
+
33
+ **Same-context review CANNOT be objective for self-written code because:**
34
+
35
+ | Cognitive Bias | Effect |
36
+ |----------------|--------|
37
+ | **Intent over code** | You "know" what it's supposed to do, so you don't see what it actually does |
38
+ | **Context memory** | You "remember" reading code, so you skip re-reading carefully |
39
+ | **Confirmation bias** | You look for "code works" evidence, not "code fails" evidence |
40
+ | **Completion pressure** | Subconscious goal becomes "finish review" not "find bugs" |
41
+
42
+ **Evidence:** In DX-71 review, same-context missed 2 CRITICAL + 4 MAJOR issues that
43
+ isolated agent found immediately. "Fresh eyes" claims don't work in same context.
44
+
45
+ ### Mandatory Self-Review Detection (DX-72)
46
+
47
+ **Before starting review, you MUST check:**
48
+
49
+ ```
50
+ If ANY file in review scope was edited by agent this session:
51
+ ┌──────────────────────────────────────────────────────────────┐
52
+ │ 🚨 SELF-REVIEW DETECTED — Isolation Required │
53
+ │ │
54
+ │ You modified files in the review scope this session. │
55
+ │ Same-context review has proven cognitive blind spots. │
56
+ │ │
57
+ │ Options: │
58
+ │ [1] Use --deep (RECOMMENDED) — Spawn isolated agent │
59
+ │ [2] Acknowledge risk — User explicitly accepts limitations │
60
+ │ │
61
+ │ If user says "continue" or "quick review": │
62
+ │ → Proceed but add WARNING to final report │
63
+ │ → Report MUST state: "Self-review without isolation" │
64
+ └──────────────────────────────────────────────────────────────┘
65
+ ```
66
+
67
+ **Default action:** If user doesn't specify, use `--deep` for self-review.
68
+
69
+ ### --deep Mode Execution
70
+
71
+ When `--deep` is selected:
72
+
73
+ 1. Collect minimal inputs:
74
+ - Files to review
75
+ - Contracts (if available)
76
+ - Test files (if available)
77
+
78
+ 2. Spawn Task agent with:
79
+ - **Adversarial Code Reviewer persona** (see Appendix)
80
+ - NO conversation history
81
+ - Only the collected inputs
82
+
83
+ 3. Isolated agent returns structured review report
84
+
85
+ 4. Main agent fixes issues (if any)
86
+
87
+ 5. **CRITICAL: Spawn NEW isolated agent for Round 2+ Review**
88
+
89
+ ### --deep Mode Loop (MANDATORY)
90
+
91
+ ```
92
+ while not quality_met:
93
+ report = spawn_NEW_isolated_reviewer(files) # 每轮新 agent
94
+ if report.has_critical_or_major:
95
+ main_agent.fix(report.issues) # 主 agent 修复
96
+ else:
97
+ quality_met = True
98
+ ```
99
+
100
+ **Why new agent each round?**
101
+ - Main agent has context contamination from fixing
102
+ - "Fresh eyes" cannot be achieved in same context
103
+ - Round 2 in same context drifts to "verify my fixes" not "find problems"
104
+
105
+ ---
106
+
107
+ ## Scope Boundaries
108
+
109
+ **This skill IS for:**
110
+ - Finding bugs and logic errors in existing code
111
+ - Verifying contract semantic value
112
+ - Auditing escape hatches
113
+ - Security review
114
+
115
+ **This skill is NOT for:**
116
+ - Implementing new features → switch to `/develop`
117
+ - Understanding how code works → switch to `/investigate`
118
+ - Deciding on architecture → switch to `/propose`
119
+
120
+ **Drift detection:** If you're writing significant new code (not fixes) → STOP, you're in wrong skill.
16
121
 
17
122
  ## Auto-Loop Configuration
18
123
 
19
124
  ```
20
125
  MAX_ROUNDS = 5 # Maximum review-fix cycles
21
126
  AUTO_TRANSITION = true # No human confirmation between roles
127
+ ASK_USER = never # NEVER ask user, just do it
22
128
  ```
23
129
 
130
+ **CRITICAL: After finding issues, IMMEDIATELY switch to FIXER role and fix them.**
131
+ **DO NOT ask "Proceed with fixes?" or similar — just fix and continue.**
132
+
24
133
  ## Prime Directive: Reject Until Proven Correct
25
134
 
26
135
  **You are the PROSECUTOR, not the defense attorney.**
@@ -39,25 +148,23 @@ AUTO_TRANSITION = true # No human confirmation between roles
39
148
 
40
149
  | Role | Allowed Actions | Forbidden |
41
150
  |------|-----------------|-----------|
42
- | **REVIEWER** | Find issues, judge fixes, declare quality_met | Write code, rationalize issues |
151
+ | **REVIEWER** | Find issues (full scope), declare quality_met | Write code, rationalize issues |
43
152
  | **FIXER** | Implement fixes only | Declare quality_met, dismiss issues |
44
153
 
45
154
  **Role Transition Markers (REQUIRED):**
46
155
 
47
156
  ```
48
157
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
49
- 🔍 REVIEWER [Round N] — Finding issues
158
+ 🔍 REVIEWER [Round N] — Full scope review
50
159
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
51
160
 
52
161
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
53
162
  🔧 FIXER [Round N] — Implementing fixes
54
163
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
55
-
56
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
57
- ✅ REVIEWER [Round N] — Verifying fixes
58
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
59
164
  ```
60
165
 
166
+ **NO separate "Verify" step.** After Fix, go directly to next round's Review.
167
+
61
168
  ## Quality Gate Authority
62
169
 
63
170
  **ONLY the Reviewer role can declare `quality_met`.**
@@ -85,7 +192,87 @@ You ARE here to:
85
192
  - Find bugs, logic errors, edge cases
86
193
  - Challenge whether contracts have semantic value
87
194
  - Check if code matches contracts (not if code "seems right")
88
- - **RE-VERIFY fixes, not trust them**
195
+
196
+ ## Fresh Eyes Mandate (Round 2+) — ENFORCED
197
+
198
+ **For rounds after the first, you MUST adopt "fresh eyes" mindset:**
199
+
200
+ > "I am a different reviewer who has never seen this code or the previous fixes."
201
+
202
+ | Trap | Correction |
203
+ |------|------------|
204
+ | "I just fixed this" | Irrelevant. Review it like new code. |
205
+ | "This was fine last round" | Maybe you missed something. Check again. |
206
+ | "The fix looks correct" | That's FIXER thinking. Find what's WRONG. |
207
+
208
+ ### Why This Exists
209
+
210
+ Round 2+ in the same context naturally drifts toward "verify my fixes" instead of
211
+ "find all problems". This cognitive bias causes issues to slip through:
212
+ - Attention focuses on recently-fixed areas
213
+ - Brain skips content it "remembers" reading
214
+ - Subconscious goal becomes "complete task" not "find bugs"
215
+
216
+ ### Mandatory Actions (Round 2+)
217
+
218
+ **Before declaring quality_met, you MUST:**
219
+
220
+ 1. **RE-READ all files using Read tool**
221
+ ```
222
+ ❌ WRONG: Rely on context memory ("I already read this")
223
+ ✅ RIGHT: Call Read() for each file in scope, every round
224
+ ```
225
+
226
+ 2. **Systematic audit per code block** (for documentation/examples)
227
+ ```
228
+ For each code block:
229
+ - List all symbols USED (types, functions, classes)
230
+ - List all IMPORTS shown
231
+ - Verify: every used symbol has corresponding import
232
+ ```
233
+
234
+ 3. **Section-by-section explicit check**
235
+ ```
236
+ □ Section 1 checked
237
+ □ Section 2 checked
238
+ □ Section 3 checked
239
+ ... (every section, not "looks fine overall")
240
+ ```
241
+
242
+ 4. **Verbalize findings before exit**
243
+ ```
244
+ ❌ WRONG: "Verified fixes, looks good"
245
+ ✅ RIGHT: "Re-read 5 files, checked 23 sections, found 0 new issues"
246
+ ```
247
+
248
+ ### Round 2+ Workflow Diagram
249
+
250
+ ```
251
+ FIXER [Round N] completes
252
+
253
+ ┌─────────────────────────────────────────┐
254
+ │ REVIEWER [Round N+1] — MANDATORY STEPS │
255
+ │ │
256
+ │ 1. Call Read() for EVERY file in scope │
257
+ │ (Do NOT skip, do NOT rely on memory)│
258
+ │ │
259
+ │ 2. For each file: │
260
+ │ □ Check section by section │
261
+ │ □ Audit imports vs usage │
262
+ │ □ Look for issues MISSED before │
263
+ │ │
264
+ │ 3. Verbalize: "Read X files, checked │
265
+ │ Y sections, found Z issues" │
266
+ │ │
267
+ │ 4. Only THEN: EXIT CHECK │
268
+ └─────────────────────────────────────────┘
269
+ ```
270
+
271
+ **Full scope means:**
272
+ 1. Re-run the ENTIRE checklist (A through G)
273
+ 2. Review ALL files in scope, not just recent fixes
274
+ 3. Check if fixes introduced NEW issues
275
+ 4. Look for issues you missed in previous rounds
89
276
 
90
277
  ## Entry Actions
91
278
 
@@ -104,7 +291,27 @@ Before any workflow action:
104
291
 
105
292
  ## Mode Selection
106
293
 
107
- ### Check Guard Output
294
+ ### Step 1: Check Self-Review (MANDATORY)
295
+
296
+ ```python
297
+ # Pseudo-code for self-review detection
298
+ files_in_scope = get_review_scope()
299
+ files_edited_this_session = get_agent_edits()
300
+
301
+ if files_in_scope & files_edited_this_session:
302
+ # SELF-REVIEW DETECTED
303
+ if user_said("--deep") or user_said("deep review"):
304
+ mode = ISOLATED
305
+ elif user_said("quick") or user_said("continue"):
306
+ mode = SAME_CONTEXT
307
+ add_warning_to_report = True # "Self-review without isolation"
308
+ else:
309
+ # Default: recommend --deep, wait for user choice
310
+ show_self_review_warning()
311
+ mode = ISOLATED # Default to safe option
312
+ ```
313
+
314
+ ### Step 2: Check Guard Output
108
315
 
109
316
  Look for `review_suggested` warning:
110
317
  ```
@@ -113,25 +320,28 @@ WARNING: review_suggested - Security-sensitive path detected
113
320
  WARNING: review_suggested - Low contract coverage
114
321
  ```
115
322
 
116
- ### Select Mode
323
+ ### Select Mode (Final Decision)
117
324
 
118
- | Condition | Mode |
119
- |-----------|------|
120
- | `review_suggested` present | **Isolated** (spawn sub-agent) |
121
- | `--isolated` flag | **Isolated** |
122
- | Default (no trigger) | **Quick** (same context) |
325
+ | Condition | Mode | Notes |
326
+ |-----------|------|-------|
327
+ | Self-review detected | **Isolated** (default) | Unless user explicitly accepts risk |
328
+ | `review_suggested` present | **Isolated** | Guard recommends isolation |
329
+ | `--deep` flag | **Isolated** | User requested |
330
+ | Others' code, no triggers | **Quick** (same context) | Only valid for non-self code |
123
331
 
124
332
  ## Review Checklist
125
333
 
126
334
  > **Principle:** Only items requiring semantic judgment. Mechanical checks are handled by Guard.
127
335
 
128
336
  ### A. Contract Semantic Value
337
+
129
338
  - [ ] Does @pre constrain inputs beyond type checking?
130
339
  - Bad: `@pre(lambda x: isinstance(x, int))`
131
340
  - Good: `@pre(lambda x: x > 0 and x < MAX_VALUE)`
132
341
  - [ ] Does @post verify meaningful output properties?
133
342
  - Bad: `@post(lambda result: result is not None)`
134
343
  - Good: `@post(lambda result: len(result) == len(input))`
344
+
135
345
  - [ ] Could someone implement correctly from contracts alone?
136
346
  - [ ] Are boundary conditions explicit in contracts?
137
347
 
@@ -179,21 +389,37 @@ These are checked by Guard or linters - don't duplicate:
179
389
  - Entry point thickness → Guard (entry_point_too_thick)
180
390
  - Escape hatch count → Guard (review_suggested)
181
391
 
182
- ## Auto-Loop Workflow (NO HUMAN CONFIRMATION)
392
+ ## Auto-Loop Workflow (FULLY AUTOMATIC)
393
+
394
+ **The loop runs AUTOMATICALLY until exit condition is met. NO user interaction.**
395
+
396
+ **Two-step cycle: Review → Fix → Review → Fix → ...**
183
397
 
184
- **The loop runs AUTOMATICALLY until exit condition is met.**
398
+ ⚠️ **NEVER ask user:**
399
+ - "Proceed with fixes?"
400
+ - "Should I fix these?"
401
+ - "Do you want me to continue?"
402
+
403
+ **Just do it.** Find issues → Fix them → Review again → Repeat until done.
185
404
 
186
405
  ```
187
406
  ┌─────────────────────────────────────────────────────────────────┐
188
407
  │ START: round = 1, issues = [] │
189
408
  │ │
190
409
  │ ┌─────────────────────────────────────────────────────────┐ │
191
- │ │ 🔍 REVIEWER [Round N] │ │
192
- │ │ 1. Find ALL issues (don't stop at first) │ │
193
- │ │ 2. Classify: CRITICAL / MAJOR / MINOR │ │
194
- │ │ 3. Add to issues table │ │
195
- │ │ 4. IF no CRITICAL/MAJOR quality_met, EXIT │ │
196
- │ │ 5. ELSE AUTO-TRANSITION to FIXER │ │
410
+ │ │ 🔍 REVIEWER [Round N] — Full Scope Review │ │
411
+ │ │ 1. Apply FULL checklist (A-G) to ENTIRE scope │ │
412
+ │ │ 2. Find ALL issues (don't stop at first) │ │
413
+ │ │ 3. Classify: CRITICAL / MAJOR / MINOR │ │
414
+ │ │ 4. Check previous fixes: CODE or just COMMENT? │ │
415
+ │ │ 5. Check if fixes introduced NEW issues │ │
416
+ │ │ 6. Update issues table │ │
417
+ │ │ │ │
418
+ │ │ EXIT CHECK: │ │
419
+ │ │ - IF no CRITICAL/MAJOR found → quality_met, EXIT │ │
420
+ │ │ - IF round >= MAX_ROUNDS → max_rounds, EXIT │ │
421
+ │ │ - IF no progress (same issues 2 rounds) → EXIT │ │
422
+ │ │ - ELSE → AUTO-TRANSITION to FIXER │ │
197
423
  │ └─────────────────────────────────────────────────────────┘ │
198
424
  │ ↓ (automatic) │
199
425
  │ ┌─────────────────────────────────────────────────────────┐ │
@@ -201,26 +427,20 @@ These are checked by Guard or linters - don't duplicate:
201
427
  │ │ 1. Fix EACH CRITICAL/MAJOR issue with CODE │ │
202
428
  │ │ 2. Run invar_guard() after fixes │ │
203
429
  │ │ 3. NO declaring quality_met (forbidden) │ │
204
- │ │ 4. AUTO-TRANSITION back to REVIEWER │ │
205
- └─────────────────────────────────────────────────────────┘
206
- │ ↓ (automatic) │
207
- │ ┌─────────────────────────────────────────────────────────┐ │
208
- │ │ ✅ REVIEWER [Round N] — Verification │ │
209
- │ │ 1. Re-verify EACH fix: │ │
210
- │ │ - Is fix CODE or just COMMENT? │ │
211
- │ │ - Does fix actually address issue? │ │
212
- │ │ - Did fix introduce new issues? │ │
213
- │ │ 2. Update verification table │ │
214
- │ │ 3. IF all CRITICAL/MAJOR fixed → quality_met, EXIT │ │
215
- │ │ 4. IF round >= MAX_ROUNDS → max_rounds, EXIT │ │
216
- │ │ 5. IF no progress → no_improvement, EXIT │ │
217
- │ │ 6. ELSE → round++, LOOP to REVIEWER [Round N+1] │ │
430
+ │ │ 4. round++ │ │
431
+ 5. AUTO-TRANSITION to REVIEWER [Round N+1]
218
432
  │ └─────────────────────────────────────────────────────────┘ │
433
+ │ ↓ (automatic, fresh eyes) │
434
+ │ [LOOP BACK TO REVIEWER] │
219
435
  │ │
220
436
  │ EXIT: Generate final report │
221
437
  └─────────────────────────────────────────────────────────────────┘
222
438
  ```
223
439
 
440
+ **Key change from v5.1:** No separate "Verify" step. Each round's Review is a
441
+ full-scope audit with the same rigor as Round 1. This prevents the "verification
442
+ mindset" trap where standards unconsciously lower after fixing.
443
+
224
444
  ## Loop State Tracking
225
445
 
226
446
  **Maintain this state throughout the loop:**
@@ -234,20 +454,25 @@ These are checked by Guard or linters - don't duplicate:
234
454
  - **Guard Status:** PASS | FAIL
235
455
  ```
236
456
 
237
- ## Verification Table (Updated Each Round)
457
+ ## Issues Table (Updated Each Round)
238
458
 
239
- | Issue ID | Severity | Round Found | Status | Evidence |
240
- |----------|----------|-------------|--------|----------|
241
- | MAJOR-1 | MAJOR | 1 | ✅ Fixed (R2) | Code change at line X |
242
- | MAJOR-2 | MAJOR | 1 | ❌ Unfixed | Fix attempted but failed |
243
- | MAJOR-3 | MAJOR | 2 | 🔄 New | Found during re-verification |
244
- | ... | ... | ... | ... | ... |
459
+ | Issue ID | Severity | Round Found | Round Fixed | Status | Evidence |
460
+ |----------|----------|-------------|-------------|--------|----------|
461
+ | MAJOR-1 | MAJOR | 1 | 1 | ✅ Fixed | Code change at file.py:123 |
462
+ | MAJOR-2 | MAJOR | 1 | - | ❌ Unfixed | Fix was comment, not code |
463
+ | MAJOR-3 | MAJOR | 2 | - | 🆕 New | Found in Round 2 review |
464
+ | MINOR-1 | MINOR | 1 | - | ⏭️ Backlog | Deferred (non-blocking) |
245
465
 
246
466
  **Status Legend:**
247
- - ✅ Fixed (RN) — Actually fixed with code in round N
248
- - ❌ Unfixed — Fix failed or was just a comment
249
- - 🔄 New — Found during re-verification (new issue)
250
- - ⏭️ Backlog — MINOR, deferred to later
467
+ - ✅ Fixed — Actually fixed with CODE (not comments)
468
+ - ❌ Unfixed — Fix failed, was just a comment, or not addressed
469
+ - 🆕 New — Found in a later round (fix may have introduced it, or missed earlier)
470
+ - ⏭️ Backlog — MINOR, deferred to later (non-blocking)
471
+
472
+ **Round 2+ Review MUST check:**
473
+ 1. Are previous ✅ Fixed items ACTUALLY fixed? (Re-verify with fresh eyes)
474
+ 2. Did fixes introduce NEW issues?
475
+ 3. Did we miss anything in earlier rounds?
251
476
 
252
477
  If ANY ❌ exists for CRITICAL/MAJOR after MAX_ROUNDS → quality_not_met
253
478
 
@@ -261,26 +486,28 @@ If ANY ❌ exists for CRITICAL/MAJOR after MAX_ROUNDS → quality_not_met
261
486
 
262
487
  ## Exit Conditions (Auto-Loop)
263
488
 
264
- **Exit triggers (checked automatically after each REVIEWER phase):**
489
+ **Exit is checked at the START of each REVIEWER phase (before finding issues):**
265
490
 
266
491
  | Condition | Exit Reason | Result |
267
492
  |-----------|-------------|--------|
268
- | All CRITICAL/MAJOR fixed | `quality_met` | ✅ Ready for merge |
493
+ | Round N Review finds 0 CRITICAL/MAJOR | `quality_met` | ✅ Ready for merge |
269
494
  | Round >= MAX_ROUNDS | `max_rounds` | ⚠️ Manual review needed |
270
495
  | No progress (same issues 2 rounds) | `no_improvement` | ❌ Architectural issue |
271
- | Guard fails after fix | Continue loop | 🔄 More fixes needed |
272
496
 
273
497
  **quality_met requires ALL of:**
274
- 1. Zero CRITICAL issues remaining
275
- 2. Zero MAJOR issues remaining (not "assessed", actually FIXED)
276
- 3. Verification table completed with evidence for each fix
277
- 4. Guard passes after all fixes
498
+ 1. Current round's FULL SCOPE review found zero CRITICAL/MAJOR
499
+ 2. All previous issues verified as fixed (with code, not comments)
500
+ 3. Guard passes
501
+ 4. Issues table complete with evidence
278
502
 
279
503
  **Automatic quality_not_met:**
280
504
  - Any MAJOR "fixed" with comment instead of code
281
505
  - Any issue marked "assessed" or "acceptable"
282
506
  - Fixer role declared quality_met (role violation)
283
- - Infinite loop detected (no progress)
507
+ - Same CRITICAL/MAJOR persists for 2+ rounds
508
+
509
+ **Important:** quality_met is declared when a Review round finds NO new issues,
510
+ not when fixes are applied. This ensures the final state is actually reviewed.
284
511
 
285
512
  ## Exit Report (Generated Automatically)
286
513
 
@@ -291,29 +518,45 @@ If ANY ❌ exists for CRITICAL/MAJOR after MAX_ROUNDS → quality_not_met
291
518
 
292
519
  **Exit Reason:** quality_met | max_rounds | no_improvement
293
520
  **Total Rounds:** N / MAX_ROUNDS
521
+ **Final Round Result:** 0 CRITICAL/MAJOR found (quality_met) | X issues remain
294
522
  **Guard Status:** PASS | FAIL
523
+ **Review Mode:** Isolated | Same-context (self-review⚠️)
295
524
 
296
- ## Verification Table
525
+ ## Issues Table
297
526
 
298
- | Issue | Severity | Round | Status | Evidence |
299
- |-------|----------|-------|--------|----------|
300
- | MAJOR-1 | MAJOR | 1→2 | ✅ Fixed | Code at file.py:123 |
301
- | ... | ... | ... | ... | ... |
527
+ | Issue | Severity | Found | Fixed | Status | Evidence |
528
+ |-------|----------|-------|-------|--------|----------|
529
+ | MAJOR-1 | MAJOR | R1 | R1 | ✅ Fixed | Code at file.py:123 |
530
+ | MAJOR-2 | MAJOR | R2 | R2 | Fixed | Added validation |
531
+ | ... | ... | ... | ... | ... | ... |
302
532
 
303
- ## Statistics
533
+ ## Round Summary
304
534
 
305
- - Issues Found: X
306
- - Issues Fixed: Y
307
- - Fix Rate: Y/X (Z%)
308
- - New Issues from Fixes: N
535
+ | Round | Issues Found | Issues Fixed | New from Fixes |
536
+ |-------|--------------|--------------|----------------|
537
+ | 1 | 3 | 3 | 0 |
538
+ | 2 | 1 | 1 | 0 |
539
+ | 3 | 0 | - | - | ← quality_met
309
540
 
310
- ## Self-Check (Reviewer Final)
541
+ ## Self-Check (Final Review Round)
311
542
 
543
+ - [x] Applied FULL checklist (A-G) with fresh eyes
312
544
  - [x] All fixes are CODE, not comments
313
545
  - [x] No "assessed as acceptable" rationalizations
314
546
  - [x] Guard passes after all changes
315
547
  - [x] Role separation maintained throughout
316
548
 
549
+ ## Self-Review Warning (if applicable)
550
+
551
+ ⚠️ **This was a same-context self-review.** Cognitive biases may have caused
552
+ issues to be missed. For higher confidence, run `--deep` review before merge.
553
+
554
+ Known blind spots in self-review:
555
+ - Exception handlers that silently lose data
556
+ - Path traversal / security issues in user input
557
+ - Edge cases in validation logic
558
+ - Documentation-implementation mismatches
559
+
317
560
  ## Recommendation
318
561
 
319
562
  - [x] Ready for merge (quality_met)
@@ -323,8 +566,40 @@ If ANY ❌ exists for CRITICAL/MAJOR after MAX_ROUNDS → quality_not_met
323
566
  **MINOR (Backlog):**
324
567
  - [list deferred items]
325
568
  ```
326
- <!--/invar:skill-->
327
- <!--invar:extensions-->
569
+ ## Appendix: Adversarial Code Reviewer Persona
570
+
571
+ Used in `--deep` mode (isolated agent):
572
+
573
+ ```
574
+ You are an independent Adversarial Code Reviewer.
575
+
576
+ CRITICAL RULES:
577
+ 1. Code is GUILTY until proven INNOCENT
578
+ 2. You did NOT write this code — no emotional attachment
579
+ 3. Find reasons to REJECT, not accept
580
+ 4. Be specific and actionable (file:line, concrete fix)
581
+ 5. Your job is to find bugs, not approve code
582
+
583
+ INPUT YOU WILL RECEIVE:
584
+ - Code files to review
585
+ - Contracts (if available)
586
+ - Test files (if available)
587
+
588
+ INPUT YOU WILL NOT RECEIVE:
589
+ - Development conversation history
590
+ - Developer's explanations
591
+ - Prior context about design decisions
592
+
593
+ OUTPUT FORMAT:
594
+ Produce structured Review Report with:
595
+ 1. Verdict: APPROVED / NEEDS WORK / REJECTED
596
+ 2. Critical issues (must fix)
597
+ 3. Major issues (should fix)
598
+ 4. Minor issues (nice to fix)
599
+ 5. Positive observations (what's done well)
600
+ ```
601
+
602
+ <!--/invar:skill--><!--invar:extensions-->
328
603
  <!-- ========================================================================
329
604
  EXTENSIONS REGION - USER EDITABLE
330
605
  Add project-specific extensions here. This section is preserved on update.