@open-code-review/agents 1.0.0 → 1.0.2

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.
@@ -0,0 +1,520 @@
1
+ # OCR Review Workflow
2
+
3
+ Complete 8-phase process for multi-agent code review.
4
+
5
+ > ⚠️ **CRITICAL**: You MUST update `state.json` at each phase transition. The `ocr progress` CLI reads this file for accurate tracking.
6
+
7
+ ---
8
+
9
+ ## Phase 0: Session State Verification (ALWAYS DO FIRST)
10
+
11
+ Before starting ANY work, verify the current session state to avoid duplicating work or losing progress.
12
+
13
+ ### Step 1: Check for existing session
14
+
15
+ ```bash
16
+ # Get current branch
17
+ BRANCH=$(git branch --show-current)
18
+ DATE=$(date +%Y-%m-%d)
19
+ SESSION_DIR=".ocr/sessions/${DATE}-${BRANCH}"
20
+
21
+ # Check if session exists
22
+ ls -la "$SESSION_DIR" 2>/dev/null
23
+ ```
24
+
25
+ ### Step 2: If `--fresh` flag provided
26
+
27
+ Delete the existing session and start from scratch:
28
+ ```bash
29
+ rm -rf "$SESSION_DIR"
30
+ mkdir -p "$SESSION_DIR/reviews"
31
+ ```
32
+ Then proceed to Phase 1.
33
+
34
+ ### Step 3: If session exists, verify state matches files
35
+
36
+ Read `state.json` and verify actual files exist:
37
+
38
+ | Phase Complete? | state.json check | File check |
39
+ |-----------------|------------------|------------|
40
+ | context | `"context"` in `completed_phases` | `context.md` exists |
41
+ | requirements | `"requirements"` in `completed_phases` | `discovered-standards.md` exists |
42
+ | reviews | `"reviews"` in `completed_phases` | ≥2 files in `reviews/` |
43
+ | discourse | `"discourse"` in `completed_phases` | `discourse.md` exists |
44
+ | synthesis | `"synthesis"` in `completed_phases` | `final.md` exists |
45
+
46
+ ### Step 4: Determine resume point
47
+
48
+ - **state.json missing, files exist**: Recreate `state.json` based on file existence
49
+ - **state.json exists, files match**: Resume from `current_phase`
50
+ - **state.json and files mismatch**: Ask user which to trust
51
+ - **No session exists**: Create session directory and start Phase 1
52
+
53
+ ### Step 5: Report to user
54
+
55
+ Before proceeding, tell the user:
56
+ ```
57
+ 📍 Session: {session_id}
58
+ 📊 Current phase: {current_phase} (Phase {phase_number}/8)
59
+ ✅ Completed: {completed_phases}
60
+ 🔄 Action: [Starting fresh | Resuming from Phase X]
61
+ ```
62
+
63
+ ---
64
+
65
+ ## State Tracking
66
+
67
+ At **every phase transition**, update `.ocr/sessions/{id}/state.json`:
68
+
69
+ ```json
70
+ {
71
+ "session_id": "{id}",
72
+ "current_phase": "reviews",
73
+ "phase_number": 4,
74
+ "completed_phases": ["context", "requirements", "analysis"],
75
+ "started_at": "2026-01-26T17:00:00Z",
76
+ "updated_at": "2026-01-26T17:05:00Z"
77
+ }
78
+ ```
79
+
80
+ **Phase values**: `context`, `requirements`, `analysis`, `reviews`, `aggregation`, `discourse`, `synthesis`, `complete`
81
+
82
+ ## Artifact Checklist
83
+
84
+ Before proceeding to each phase, verify the required artifacts exist:
85
+
86
+ | Phase | Required Before Starting | Artifact to Create |
87
+ |-------|-------------------------|-------------------|
88
+ | 1 | Session directory created | `discovered-standards.md`, `state.json` |
89
+ | 2 | — | `context.md`, update `state.json` |
90
+ | 3 | `context.md` exists | Tech Lead guidance (inline), update `state.json` |
91
+ | 4 | `context.md` exists | `reviews/{reviewer}-{n}.md`, update `state.json` |
92
+ | 5 | ≥2 files in `reviews/` | Aggregated findings (inline), update `state.json` |
93
+ | 6 | Reviews complete | `discourse.md`, update `state.json` |
94
+ | 7 | `discourse.md` exists | `final.md`, update `state.json` |
95
+ | 8 | `final.md` exists | Present to user, set phase to `complete` |
96
+
97
+ **NEVER skip directly to `final.md`** — this breaks progress tracking.
98
+
99
+ ## Session Storage
100
+
101
+ **IMPORTANT**: Always store sessions in the project's `.ocr/sessions/` directory:
102
+
103
+ ```bash
104
+ mkdir -p .ocr/sessions/{YYYY-MM-DD}-{branch}
105
+ ```
106
+
107
+ This location is consistent regardless of how OCR is installed (CLI or plugin), enabling:
108
+ - `npx @open-code-review/cli progress` to track reviews in real-time
109
+ - `ocr history` and `ocr show` to access past sessions
110
+ - Cross-tool compatibility (same session visible from any AI tool)
111
+
112
+ ## Phase 1: Context Discovery (Including Requirements)
113
+
114
+ **Goal**: Build review context from config + discovered files + user requirements.
115
+
116
+ ### Steps
117
+
118
+ **1a. Load OCR Configuration**
119
+
120
+ Read `.ocr/config.yaml` for project-specific context and discovery settings:
121
+
122
+ ```bash
123
+ cat .ocr/config.yaml
124
+ ```
125
+
126
+ Extract:
127
+ - `context:` — Direct project context (injected into all reviews)
128
+ - `context_discovery.openspec` — OpenSpec integration settings
129
+ - `context_discovery.references` — Files to discover
130
+ - `rules:` — Per-severity review rules
131
+
132
+ **1b. Pull OpenSpec Context (if enabled)**
133
+
134
+ If `context_discovery.openspec.enabled: true`:
135
+
136
+ ```bash
137
+ # Read OpenSpec project context
138
+ cat openspec/config.yaml 2>/dev/null
139
+
140
+ # Read merged specs for architectural context
141
+ find openspec/specs -name "*.md" -type f 2>/dev/null
142
+
143
+ # Check for active changes that affect the review
144
+ find openspec/changes -name "*.md" -type f 2>/dev/null
145
+ ```
146
+
147
+ **1c. Discover Reference Files**
148
+
149
+ Read files listed in `context_discovery.references`:
150
+
151
+ ```bash
152
+ # Check for AI assistant configuration
153
+ cat AGENTS.md 2>/dev/null
154
+ cat CLAUDE.md 2>/dev/null
155
+ cat .cursorrules 2>/dev/null
156
+ cat .windsurfrules 2>/dev/null
157
+
158
+ # Check for contribution guidelines
159
+ cat CONTRIBUTING.md 2>/dev/null
160
+ ```
161
+
162
+ **1d. Gather User-Provided Requirements**
163
+
164
+ Recognize requirements from ANY of these forms:
165
+ - **Inline**: "review this against the requirement that..."
166
+ - **Document reference**: "see the spec at path/to/spec.md" → Read the file
167
+ - **Pasted text**: Bug reports, acceptance criteria, notes
168
+ - **Ambiguous reference**: "check the auth spec" → Search for likely files or ask user
169
+
170
+ If requirements provided, save to `requirements.md` in session directory.
171
+
172
+ **1e. Merge Into discovered-standards.md**
173
+
174
+ ```markdown
175
+ # Discovered Project Standards
176
+
177
+ ## OCR Config Context
178
+ [content from .ocr/config.yaml context field]
179
+
180
+ ## OpenSpec Context
181
+ [content from openspec/config.yaml]
182
+
183
+ ## From: AGENTS.md
184
+ [content]
185
+
186
+ ## From: CLAUDE.md
187
+ [content]
188
+
189
+ ## Review Rules
190
+ [rules from .ocr/config.yaml]
191
+ ```
192
+
193
+ See `references/context-discovery.md` for detailed algorithm.
194
+
195
+ ### ✅ Phase 1 Checkpoint
196
+
197
+ **STOP and verify before proceeding:**
198
+ - [ ] `discovered-standards.md` written to session directory
199
+ - [ ] If user provided requirements: `requirements.md` written
200
+
201
+ ---
202
+
203
+ ## Phase 2: Gather Change Context
204
+
205
+ **Goal**: Understand what changed and why.
206
+
207
+ ### Steps
208
+
209
+ 1. Identify the review target:
210
+ - Staged changes: `git diff --cached`
211
+ - Unstaged changes: `git diff`
212
+ - Commit range: `git diff {range}`
213
+ - PR: `gh pr diff {number}`
214
+
215
+ 2. Gather supporting context:
216
+ ```bash
217
+ # Get the diff
218
+ git diff --cached > /tmp/ocr-diff.txt
219
+
220
+ # Get recent commit messages for intent
221
+ git log --oneline -10
222
+
223
+ # Get branch name
224
+ git branch --show-current
225
+
226
+ # List affected files
227
+ git diff --cached --name-only
228
+ ```
229
+
230
+ 3. Create session directory:
231
+ ```bash
232
+ SESSION_ID="$(date +%Y-%m-%d)-$(git branch --show-current | tr '/' '-')"
233
+ mkdir -p .ocr/sessions/$SESSION_ID/reviews
234
+ ```
235
+
236
+ 4. Save context to `context.md`:
237
+ ```markdown
238
+ # Review Context
239
+
240
+ **Session**: {SESSION_ID}
241
+ **Target**: staged changes
242
+ **Branch**: {branch}
243
+ **Files**: {count} files changed
244
+
245
+ ## Change Summary
246
+ [Brief description of what changed]
247
+
248
+ ## Affected Files
249
+ - path/to/file1.ts
250
+ - path/to/file2.ts
251
+ ```
252
+
253
+ ### ✅ Phase 2 Checkpoint
254
+
255
+ **STOP and verify before proceeding:**
256
+ - [ ] Session directory created: `.ocr/sessions/{id}/`
257
+ - [ ] `reviews/` subdirectory created
258
+ - [ ] `context.md` written with change summary
259
+
260
+ ---
261
+
262
+ ## Phase 3: Tech Lead Analysis
263
+
264
+ **Goal**: Summarize changes, analyze against requirements, identify risks, select reviewers.
265
+
266
+ ### Steps
267
+
268
+ 1. Review requirements (if provided):
269
+ - What is the code SUPPOSED to do?
270
+ - What are the acceptance criteria?
271
+ - What edge cases are implied?
272
+
273
+ 2. Analyze the diff to understand:
274
+ - What functionality is being added/changed/removed?
275
+ - Does this align with requirements?
276
+ - What is the likely intent?
277
+ - What are the potential risk areas?
278
+
279
+ 3. Create dynamic guidance for reviewers:
280
+ ```markdown
281
+ ## Tech Lead Guidance
282
+
283
+ ### Requirements Summary (if provided)
284
+ The changes should implement OAuth2 authentication per spec...
285
+ Key acceptance criteria:
286
+ - Users can log in via Google OAuth
287
+ - Session tokens expire after 24 hours
288
+ - Failed logins are rate-limited
289
+
290
+ ### Change Summary
291
+ This PR adds user authentication via OAuth2...
292
+
293
+ ### Requirements Assessment
294
+ - OAuth login: Implemented ✓
295
+ - Token expiry: Not visible in diff - verify implementation
296
+ - Rate limiting: Not found - may be missing
297
+
298
+ ### Clarifying Questions (Tech Lead)
299
+ - The spec says "fast response" - what's the target latency?
300
+ - Should this include account lockout after N failures?
301
+
302
+ ### Risk Areas
303
+ - **Security**: New auth flow needs careful review
304
+ - **Architecture**: New service layer pattern
305
+
306
+ ### Focus Points
307
+ - Validate token handling
308
+ - Check for proper error handling
309
+ - Ensure tests cover edge cases
310
+ - Verify rate limiting is implemented
311
+ ```
312
+
313
+ 4. Select reviewers:
314
+
315
+ **Default team** (always spawned):
316
+ - 2× Principal (holistic architecture review)
317
+ - 2× Quality (code quality review)
318
+
319
+ **Optional reviewers** (added based on change type or user request):
320
+ | Change Type | Additional Reviewers |
321
+ |-------------|---------------------|
322
+ | Auth/Security changes | + 1× Security |
323
+ | API changes | + 1× Security |
324
+ | Logic changes | + 1× Testing |
325
+ | User says "add security" | + 1× Security |
326
+
327
+ ---
328
+
329
+ ## Phase 4: Spawn Reviewers
330
+
331
+ **Goal**: Run each reviewer independently with configured redundancy.
332
+
333
+ ### Steps
334
+
335
+ 1. Load reviewer personas from `references/reviewers/`.
336
+
337
+ 2. Spawn tasks based on default team + detected needs:
338
+ ```
339
+ # Default team (always)
340
+ Spawn Task: principal-1
341
+ Spawn Task: principal-2
342
+ Spawn Task: quality-1
343
+ Spawn Task: quality-2
344
+
345
+ # Optional (if auth/API/data changes OR user requested)
346
+ Spawn Task: security-1
347
+
348
+ # Optional (if logic changes OR user requested)
349
+ Spawn Task: testing-1
350
+ ```
351
+
352
+ 3. Each task receives:
353
+ - Reviewer persona (from `references/reviewers/{name}.md`)
354
+ - Project context (from `discovered-standards.md`)
355
+ - **Requirements context (from `requirements.md` if provided)**
356
+ - Tech Lead guidance (including requirements assessment)
357
+ - The diff to review
358
+ - **Instruction to explore codebase with full agency**
359
+
360
+ 4. Save each review to `.ocr/sessions/{id}/reviews/{reviewer}-{n}.md`.
361
+
362
+ See `references/reviewer-task.md` for the task template.
363
+
364
+ ### ✅ Phase 4 Checkpoint
365
+
366
+ **STOP and verify before proceeding:**
367
+ - [ ] At least 4 review files exist in `reviews/` directory
368
+ - [ ] Each review file contains findings (even if "no issues found")
369
+ - [ ] File naming follows `{reviewer}-{n}.md` pattern
370
+
371
+ ---
372
+
373
+ ## Phase 5: Aggregate Findings
374
+
375
+ **Goal**: Merge redundant reviewer runs and mark confidence.
376
+
377
+ ### Steps
378
+
379
+ 1. For reviewers with redundancy > 1, compare findings:
380
+ - **Confirmed**: Found in all runs → Very High Confidence
381
+ - **Partial**: Found in some runs → Medium Confidence
382
+ - **Single**: Found in one run → Lower Confidence
383
+
384
+ 2. Deduplicate identical findings.
385
+
386
+ 3. Create aggregated findings per reviewer:
387
+ ```markdown
388
+ ## Security Reviewer (2 runs)
389
+
390
+ ### Confirmed Findings (2/2 runs)
391
+ - SQL injection risk in query builder [VERY HIGH]
392
+
393
+ ### Partial Findings (1/2 runs)
394
+ - Potential timing attack in comparison [MEDIUM]
395
+ ```
396
+
397
+ ---
398
+
399
+ ## Phase 6: Discourse
400
+
401
+ **Goal**: Let reviewers challenge and build on each other's findings.
402
+
403
+ > Skip this phase if `--quick` flag is used.
404
+
405
+ ### Steps
406
+
407
+ 1. Present all aggregated findings to each reviewer.
408
+
409
+ 2. Each reviewer responds using these types:
410
+ - **AGREE**: "I concur with Security's SQL injection finding..."
411
+ - **CHALLENGE**: "I disagree because the ORM sanitizes..."
412
+ - **CONNECT**: "This relates to my maintainability concern..."
413
+ - **SURFACE**: "Based on this discussion, I notice..."
414
+
415
+ 3. Save discourse to `.ocr/sessions/{id}/discourse.md`.
416
+
417
+ See `references/discourse.md` for detailed instructions.
418
+
419
+ ### ✅ Phase 6 Checkpoint
420
+
421
+ **STOP and verify before proceeding:**
422
+ - [ ] `discourse.md` written to session directory
423
+ - [ ] Contains AGREE/CHALLENGE/CONNECT/SURFACE responses
424
+ - [ ] (Or if `--quick` flag: skip this phase, proceed to synthesis)
425
+
426
+ ---
427
+
428
+ ## Phase 7: Synthesis
429
+
430
+ **Goal**: Produce final prioritized review.
431
+
432
+ ### Steps
433
+
434
+ 1. Aggregate all findings from Phase 5 and Phase 6.
435
+
436
+ 2. Deduplicate and merge related findings.
437
+
438
+ 3. Weight by confidence:
439
+ - Confirmed by redundancy: +2
440
+ - Agreed in discourse: +1
441
+ - Challenged and defended: +1
442
+ - Challenged and undefended: -1
443
+
444
+ 4. Categorize findings:
445
+ - **Must Fix**: Critical issues, security vulnerabilities
446
+ - **Should Fix**: Important improvements
447
+ - **Consider**: Nice-to-haves, style suggestions
448
+ - **What's Working Well**: Positive feedback
449
+
450
+ 5. **If requirements were provided**, include Requirements Assessment:
451
+ - Which requirements are fully met?
452
+ - Which requirements have gaps?
453
+ - Any deviations from requirements?
454
+ - Confidence level in requirements fulfillment
455
+
456
+ 6. **Collect and surface Clarifying Questions** from Tech Lead and all reviewers:
457
+ - Questions about requirements ambiguity
458
+ - Questions about scope boundaries
459
+ - Questions about edge cases
460
+ - Questions about intentional exclusions
461
+
462
+ These go in a prominent "Clarifying Questions" section for stakeholder response.
463
+
464
+ 7. Save to `.ocr/sessions/{id}/final.md`.
465
+
466
+ See `references/synthesis.md` for template.
467
+
468
+ ### ✅ Phase 7 Checkpoint
469
+
470
+ **STOP and verify before proceeding:**
471
+ - [ ] `final.md` written to session directory
472
+ - [ ] Contains prioritized findings (Must Fix, Should Fix, Consider)
473
+ - [ ] Contains Clarifying Questions section (if any)
474
+ - [ ] If requirements provided: Contains Requirements Assessment
475
+
476
+ ---
477
+
478
+ ## Phase 8: Present
479
+
480
+ **Goal**: Display results and optionally post to GitHub.
481
+
482
+ ### Steps
483
+
484
+ 1. Display the final review in a clear format:
485
+ ```markdown
486
+ # Code Review: {branch}
487
+
488
+ ## Summary
489
+ {X} must-fix, {Y} should-fix, {Z} suggestions
490
+
491
+ ## Must Fix
492
+ ...
493
+
494
+ ## Should Fix
495
+ ...
496
+ ```
497
+
498
+ 2. If `--post` flag or PR target:
499
+ - Check for `gh` CLI: `which gh`
500
+ - Post as PR comment: `gh pr comment {number} --body-file final.md`
501
+
502
+ 3. Confirm session saved:
503
+ ```
504
+ Review saved to: .ocr/sessions/{id}/final.md
505
+ ```
506
+
507
+ ---
508
+
509
+ ## Quick Reference
510
+
511
+ | Phase | Command/Action | Output |
512
+ |-------|---------------|--------|
513
+ | 1 | Search for context files | discovered-standards.md |
514
+ | 2 | git diff, create session | context.md |
515
+ | 3 | Analyze, select reviewers | guidance in context.md |
516
+ | 4 | Spawn reviewer tasks | reviews/*.md |
517
+ | 5 | Compare redundant runs | aggregated findings |
518
+ | 6 | Reviewer discourse | discourse.md |
519
+ | 7 | Synthesize and prioritize | final.md |
520
+ | 8 | Display/post | Terminal output, GitHub |