@open-code-review/agents 1.0.1 → 1.0.3

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,528 @@
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
+ Read the `config` path from `.ocr/config.yaml` (defaults to `openspec/config.yaml`).
137
+ - For `.yaml` files: extract the `context` field
138
+ - For `.md` files: use entire content (legacy `openspec/project.md`)
139
+
140
+ ```bash
141
+ # Read OpenSpec project context (path from .ocr/config.yaml openspec.config)
142
+ # Default: openspec/config.yaml, legacy: openspec/project.md
143
+ cat openspec/config.yaml 2>/dev/null || cat openspec/project.md 2>/dev/null
144
+
145
+ # Read merged specs for architectural context
146
+ find openspec/specs -name "*.md" -type f 2>/dev/null
147
+
148
+ # Check for active changes that affect the review
149
+ find openspec/changes -name "*.md" -type f 2>/dev/null
150
+ ```
151
+
152
+ **1c. Discover Reference Files**
153
+
154
+ Read files listed in `context_discovery.references`:
155
+
156
+ ```bash
157
+ # Check for AI assistant configuration
158
+ cat AGENTS.md 2>/dev/null
159
+ cat CLAUDE.md 2>/dev/null
160
+ cat .cursorrules 2>/dev/null
161
+ cat .windsurfrules 2>/dev/null
162
+
163
+ # Check for contribution guidelines
164
+ cat CONTRIBUTING.md 2>/dev/null
165
+
166
+ # Check for OpenSpec instructions (legacy projects)
167
+ cat openspec/AGENTS.md 2>/dev/null
168
+ ```
169
+
170
+ **1d. Gather User-Provided Requirements**
171
+
172
+ Recognize requirements from ANY of these forms:
173
+ - **Inline**: "review this against the requirement that..."
174
+ - **Document reference**: "see the spec at path/to/spec.md" → Read the file
175
+ - **Pasted text**: Bug reports, acceptance criteria, notes
176
+ - **Ambiguous reference**: "check the auth spec" → Search for likely files or ask user
177
+
178
+ If requirements provided, save to `requirements.md` in session directory.
179
+
180
+ **1e. Merge Into discovered-standards.md**
181
+
182
+ ```markdown
183
+ # Discovered Project Standards
184
+
185
+ ## OCR Config Context
186
+ [content from .ocr/config.yaml context field]
187
+
188
+ ## OpenSpec Context
189
+ [content from openspec/config.yaml]
190
+
191
+ ## From: AGENTS.md
192
+ [content]
193
+
194
+ ## From: CLAUDE.md
195
+ [content]
196
+
197
+ ## Review Rules
198
+ [rules from .ocr/config.yaml]
199
+ ```
200
+
201
+ See `references/context-discovery.md` for detailed algorithm.
202
+
203
+ ### ✅ Phase 1 Checkpoint
204
+
205
+ **STOP and verify before proceeding:**
206
+ - [ ] `discovered-standards.md` written to session directory
207
+ - [ ] If user provided requirements: `requirements.md` written
208
+
209
+ ---
210
+
211
+ ## Phase 2: Gather Change Context
212
+
213
+ **Goal**: Understand what changed and why.
214
+
215
+ ### Steps
216
+
217
+ 1. Identify the review target:
218
+ - Staged changes: `git diff --cached`
219
+ - Unstaged changes: `git diff`
220
+ - Commit range: `git diff {range}`
221
+ - PR: `gh pr diff {number}`
222
+
223
+ 2. Gather supporting context:
224
+ ```bash
225
+ # Get the diff
226
+ git diff --cached > /tmp/ocr-diff.txt
227
+
228
+ # Get recent commit messages for intent
229
+ git log --oneline -10
230
+
231
+ # Get branch name
232
+ git branch --show-current
233
+
234
+ # List affected files
235
+ git diff --cached --name-only
236
+ ```
237
+
238
+ 3. Create session directory:
239
+ ```bash
240
+ SESSION_ID="$(date +%Y-%m-%d)-$(git branch --show-current | tr '/' '-')"
241
+ mkdir -p .ocr/sessions/$SESSION_ID/reviews
242
+ ```
243
+
244
+ 4. Save context to `context.md`:
245
+ ```markdown
246
+ # Review Context
247
+
248
+ **Session**: {SESSION_ID}
249
+ **Target**: staged changes
250
+ **Branch**: {branch}
251
+ **Files**: {count} files changed
252
+
253
+ ## Change Summary
254
+ [Brief description of what changed]
255
+
256
+ ## Affected Files
257
+ - path/to/file1.ts
258
+ - path/to/file2.ts
259
+ ```
260
+
261
+ ### ✅ Phase 2 Checkpoint
262
+
263
+ **STOP and verify before proceeding:**
264
+ - [ ] Session directory created: `.ocr/sessions/{id}/`
265
+ - [ ] `reviews/` subdirectory created
266
+ - [ ] `context.md` written with change summary
267
+
268
+ ---
269
+
270
+ ## Phase 3: Tech Lead Analysis
271
+
272
+ **Goal**: Summarize changes, analyze against requirements, identify risks, select reviewers.
273
+
274
+ ### Steps
275
+
276
+ 1. Review requirements (if provided):
277
+ - What is the code SUPPOSED to do?
278
+ - What are the acceptance criteria?
279
+ - What edge cases are implied?
280
+
281
+ 2. Analyze the diff to understand:
282
+ - What functionality is being added/changed/removed?
283
+ - Does this align with requirements?
284
+ - What is the likely intent?
285
+ - What are the potential risk areas?
286
+
287
+ 3. Create dynamic guidance for reviewers:
288
+ ```markdown
289
+ ## Tech Lead Guidance
290
+
291
+ ### Requirements Summary (if provided)
292
+ The changes should implement OAuth2 authentication per spec...
293
+ Key acceptance criteria:
294
+ - Users can log in via Google OAuth
295
+ - Session tokens expire after 24 hours
296
+ - Failed logins are rate-limited
297
+
298
+ ### Change Summary
299
+ This PR adds user authentication via OAuth2...
300
+
301
+ ### Requirements Assessment
302
+ - OAuth login: Implemented ✓
303
+ - Token expiry: Not visible in diff - verify implementation
304
+ - Rate limiting: Not found - may be missing
305
+
306
+ ### Clarifying Questions (Tech Lead)
307
+ - The spec says "fast response" - what's the target latency?
308
+ - Should this include account lockout after N failures?
309
+
310
+ ### Risk Areas
311
+ - **Security**: New auth flow needs careful review
312
+ - **Architecture**: New service layer pattern
313
+
314
+ ### Focus Points
315
+ - Validate token handling
316
+ - Check for proper error handling
317
+ - Ensure tests cover edge cases
318
+ - Verify rate limiting is implemented
319
+ ```
320
+
321
+ 4. Select reviewers:
322
+
323
+ **Default team** (always spawned):
324
+ - 2× Principal (holistic architecture review)
325
+ - 2× Quality (code quality review)
326
+
327
+ **Optional reviewers** (added based on change type or user request):
328
+ | Change Type | Additional Reviewers |
329
+ |-------------|---------------------|
330
+ | Auth/Security changes | + 1× Security |
331
+ | API changes | + 1× Security |
332
+ | Logic changes | + 1× Testing |
333
+ | User says "add security" | + 1× Security |
334
+
335
+ ---
336
+
337
+ ## Phase 4: Spawn Reviewers
338
+
339
+ **Goal**: Run each reviewer independently with configured redundancy.
340
+
341
+ ### Steps
342
+
343
+ 1. Load reviewer personas from `references/reviewers/`.
344
+
345
+ 2. Spawn tasks based on default team + detected needs:
346
+ ```
347
+ # Default team (always)
348
+ Spawn Task: principal-1
349
+ Spawn Task: principal-2
350
+ Spawn Task: quality-1
351
+ Spawn Task: quality-2
352
+
353
+ # Optional (if auth/API/data changes OR user requested)
354
+ Spawn Task: security-1
355
+
356
+ # Optional (if logic changes OR user requested)
357
+ Spawn Task: testing-1
358
+ ```
359
+
360
+ 3. Each task receives:
361
+ - Reviewer persona (from `references/reviewers/{name}.md`)
362
+ - Project context (from `discovered-standards.md`)
363
+ - **Requirements context (from `requirements.md` if provided)**
364
+ - Tech Lead guidance (including requirements assessment)
365
+ - The diff to review
366
+ - **Instruction to explore codebase with full agency**
367
+
368
+ 4. Save each review to `.ocr/sessions/{id}/reviews/{reviewer}-{n}.md`.
369
+
370
+ See `references/reviewer-task.md` for the task template.
371
+
372
+ ### ✅ Phase 4 Checkpoint
373
+
374
+ **STOP and verify before proceeding:**
375
+ - [ ] At least 4 review files exist in `reviews/` directory
376
+ - [ ] Each review file contains findings (even if "no issues found")
377
+ - [ ] File naming follows `{reviewer}-{n}.md` pattern
378
+
379
+ ---
380
+
381
+ ## Phase 5: Aggregate Findings
382
+
383
+ **Goal**: Merge redundant reviewer runs and mark confidence.
384
+
385
+ ### Steps
386
+
387
+ 1. For reviewers with redundancy > 1, compare findings:
388
+ - **Confirmed**: Found in all runs → Very High Confidence
389
+ - **Partial**: Found in some runs → Medium Confidence
390
+ - **Single**: Found in one run → Lower Confidence
391
+
392
+ 2. Deduplicate identical findings.
393
+
394
+ 3. Create aggregated findings per reviewer:
395
+ ```markdown
396
+ ## Security Reviewer (2 runs)
397
+
398
+ ### Confirmed Findings (2/2 runs)
399
+ - SQL injection risk in query builder [VERY HIGH]
400
+
401
+ ### Partial Findings (1/2 runs)
402
+ - Potential timing attack in comparison [MEDIUM]
403
+ ```
404
+
405
+ ---
406
+
407
+ ## Phase 6: Discourse
408
+
409
+ **Goal**: Let reviewers challenge and build on each other's findings.
410
+
411
+ > Skip this phase if `--quick` flag is used.
412
+
413
+ ### Steps
414
+
415
+ 1. Present all aggregated findings to each reviewer.
416
+
417
+ 2. Each reviewer responds using these types:
418
+ - **AGREE**: "I concur with Security's SQL injection finding..."
419
+ - **CHALLENGE**: "I disagree because the ORM sanitizes..."
420
+ - **CONNECT**: "This relates to my maintainability concern..."
421
+ - **SURFACE**: "Based on this discussion, I notice..."
422
+
423
+ 3. Save discourse to `.ocr/sessions/{id}/discourse.md`.
424
+
425
+ See `references/discourse.md` for detailed instructions.
426
+
427
+ ### ✅ Phase 6 Checkpoint
428
+
429
+ **STOP and verify before proceeding:**
430
+ - [ ] `discourse.md` written to session directory
431
+ - [ ] Contains AGREE/CHALLENGE/CONNECT/SURFACE responses
432
+ - [ ] (Or if `--quick` flag: skip this phase, proceed to synthesis)
433
+
434
+ ---
435
+
436
+ ## Phase 7: Synthesis
437
+
438
+ **Goal**: Produce final prioritized review.
439
+
440
+ ### Steps
441
+
442
+ 1. Aggregate all findings from Phase 5 and Phase 6.
443
+
444
+ 2. Deduplicate and merge related findings.
445
+
446
+ 3. Weight by confidence:
447
+ - Confirmed by redundancy: +2
448
+ - Agreed in discourse: +1
449
+ - Challenged and defended: +1
450
+ - Challenged and undefended: -1
451
+
452
+ 4. Categorize findings:
453
+ - **Must Fix**: Critical issues, security vulnerabilities
454
+ - **Should Fix**: Important improvements
455
+ - **Consider**: Nice-to-haves, style suggestions
456
+ - **What's Working Well**: Positive feedback
457
+
458
+ 5. **If requirements were provided**, include Requirements Assessment:
459
+ - Which requirements are fully met?
460
+ - Which requirements have gaps?
461
+ - Any deviations from requirements?
462
+ - Confidence level in requirements fulfillment
463
+
464
+ 6. **Collect and surface Clarifying Questions** from Tech Lead and all reviewers:
465
+ - Questions about requirements ambiguity
466
+ - Questions about scope boundaries
467
+ - Questions about edge cases
468
+ - Questions about intentional exclusions
469
+
470
+ These go in a prominent "Clarifying Questions" section for stakeholder response.
471
+
472
+ 7. Save to `.ocr/sessions/{id}/final.md`.
473
+
474
+ See `references/synthesis.md` for template.
475
+
476
+ ### ✅ Phase 7 Checkpoint
477
+
478
+ **STOP and verify before proceeding:**
479
+ - [ ] `final.md` written to session directory
480
+ - [ ] Contains prioritized findings (Must Fix, Should Fix, Consider)
481
+ - [ ] Contains Clarifying Questions section (if any)
482
+ - [ ] If requirements provided: Contains Requirements Assessment
483
+
484
+ ---
485
+
486
+ ## Phase 8: Present
487
+
488
+ **Goal**: Display results and optionally post to GitHub.
489
+
490
+ ### Steps
491
+
492
+ 1. Display the final review in a clear format:
493
+ ```markdown
494
+ # Code Review: {branch}
495
+
496
+ ## Summary
497
+ {X} must-fix, {Y} should-fix, {Z} suggestions
498
+
499
+ ## Must Fix
500
+ ...
501
+
502
+ ## Should Fix
503
+ ...
504
+ ```
505
+
506
+ 2. If `--post` flag or PR target:
507
+ - Check for `gh` CLI: `which gh`
508
+ - Post as PR comment: `gh pr comment {number} --body-file final.md`
509
+
510
+ 3. Confirm session saved:
511
+ ```
512
+ Review saved to: .ocr/sessions/{id}/final.md
513
+ ```
514
+
515
+ ---
516
+
517
+ ## Quick Reference
518
+
519
+ | Phase | Command/Action | Output |
520
+ |-------|---------------|--------|
521
+ | 1 | Search for context files | discovered-standards.md |
522
+ | 2 | git diff, create session | context.md |
523
+ | 3 | Analyze, select reviewers | guidance in context.md |
524
+ | 4 | Spawn reviewer tasks | reviews/*.md |
525
+ | 5 | Compare redundant runs | aggregated findings |
526
+ | 6 | Reviewer discourse | discourse.md |
527
+ | 7 | Synthesize and prioritize | final.md |
528
+ | 8 | Display/post | Terminal output, GitHub |