@open-code-review/agents 1.3.1 → 1.5.0

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.
@@ -8,10 +8,18 @@ Every OCR session creates files in `.ocr/sessions/{session-id}/`:
8
8
 
9
9
  ```
10
10
  .ocr/sessions/{YYYY-MM-DD}-{branch}/
11
- ├── state.json # Session state (REQUIRED)
12
11
  ├── discovered-standards.md # Merged project context (shared across rounds)
13
12
  ├── requirements.md # User-provided requirements (if any, shared)
14
13
  ├── context.md # Phase 2+3: Change summary + Tech Lead guidance (shared)
14
+ ├── map/ # Code Review Map artifacts (optional)
15
+ │ └── runs/
16
+ │ ├── run-1/ # First map generation
17
+ │ │ ├── topology.md # File categorization and sections
18
+ │ │ ├── flow-analysis.md # Dependency tracing results
19
+ │ │ ├── requirements-mapping.md # Coverage matrix (if requirements)
20
+ │ │ └── map.md # Final map output
21
+ │ └── run-2/ # Subsequent runs (created on re-map)
22
+ │ └── ... # Same structure as run-1
15
23
  └── rounds/ # All round-specific artifacts
16
24
  ├── round-1/ # First review round
17
25
  │ ├── reviews/ # Individual reviewer outputs
@@ -40,28 +48,51 @@ OCR uses a **round-first architecture** where all round-specific artifacts live
40
48
  - Subsequent `/ocr-review` on same day/branch creates `rounds/round-{n+1}/`
41
49
  - Previous rounds are preserved (never overwritten)
42
50
  - Each round has its own `discourse.md` and `final.md`
43
- - `state.json` tracks `current_round`; round metadata derived from filesystem
51
+ - SQLite tracks `current_round` via `ocr state show`; round metadata derived from filesystem
44
52
 
45
- **Shared vs per-round artifacts**:
46
- | Shared (session root) | Per-round (`rounds/round-{n}/`) |
47
- |----------------------|--------------------------------|
48
- | `state.json` | `reviews/*.md` |
49
- | `discovered-standards.md` | `discourse.md` |
50
- | `requirements.md` | `final.md` |
51
- | `context.md` | |
53
+ **Shared vs per-round/run artifacts**:
54
+ | Shared (session root) | Per-round (`rounds/round-{n}/`) | Per-run (`map/runs/run-{n}/`) |
55
+ |----------------------|--------------------------------|-------------------------------|
56
+ | `discovered-standards.md` | `reviews/*.md` | `topology.md` |
57
+ | `requirements.md` | `discourse.md` | `flow-analysis.md` |
58
+ | `context.md` | `final.md` | `requirements-mapping.md` |
59
+ | | | `map.md` |
52
60
 
53
61
  **When to use multiple rounds**:
54
62
  - Author addresses feedback and requests re-review
55
63
  - Scope changes mid-review
56
64
  - Different reviewer team composition needed
57
65
 
66
+ ## Map Runs
67
+
68
+ OCR uses a **run-based architecture** for maps, parallel to review rounds.
69
+
70
+ **Run behavior**:
71
+ - First `/ocr-map` creates `map/runs/run-1/` with map artifacts
72
+ - Subsequent `/ocr-map` on same day/branch creates `map/runs/run-{n+1}/`
73
+ - Previous runs are preserved (never overwritten)
74
+ - Each run produces a complete `map.md`
75
+ - SQLite tracks `current_map_run` via `ocr state show`; run metadata derived from filesystem
76
+
77
+ **Map artifacts per run**:
78
+ | File | Phase | Description |
79
+ |------|-------|-------------|
80
+ | `topology.md` | 2 | File categorization and section groupings |
81
+ | `flow-analysis.md` | 3 | Upstream/downstream dependency tracing |
82
+ | `requirements-mapping.md` | 4 | Requirements coverage matrix (if requirements provided) |
83
+ | `map.md` | 5 | Final synthesized Code Review Map |
84
+
85
+ **When to use multiple runs**:
86
+ - Changeset has evolved since last map
87
+ - Different requirements context needed
88
+ - Fresh analysis desired after code updates
89
+
58
90
  ## File Specifications
59
91
 
60
92
  ### Required Files
61
93
 
62
94
  | File | Phase | Description | Used By |
63
95
  |------|-------|-------------|---------|
64
- | `state.json` | 1 | Session state for progress tracking | CLI, resume logic |
65
96
  | `discovered-standards.md` | 1 | Merged project context from config + references | All reviewers |
66
97
  | `context.md` | 2 | Change summary, diff analysis, Tech Lead guidance | All reviewers |
67
98
  | `rounds/round-{n}/reviews/{type}-{n}.md` | 4 | Individual reviewer outputs | Discourse, Synthesis |
@@ -102,18 +133,18 @@ rounds/round-1/reviews/performance-1.md # Custom reviewer
102
133
 
103
134
  | Phase | Phase Name | Files to Create/Update |
104
135
  |-------|------------|------------------------|
105
- | 1 | Context Discovery | `state.json`, `discovered-standards.md`, `requirements.md` (if provided) |
106
- | 2 | Change Analysis | `context.md`, update `state.json` |
107
- | 3 | Tech Lead Analysis | Update `context.md` with guidance, update `state.json` |
108
- | 4 | Parallel Reviews | `rounds/round-{n}/reviews/{type}-{n}.md` for each reviewer, update `state.json` |
109
- | 5 | Aggregation | (Inline analysis), update `state.json` |
110
- | 6 | Discourse | `rounds/round-{n}/discourse.md`, update `state.json` |
111
- | 7 | Synthesis | `rounds/round-{n}/final.md`, update `state.json` |
112
- | 8 | Presentation | Set `state.json` status to `"closed"` |
136
+ | 1 | Context Discovery | `discovered-standards.md`, `requirements.md` (if provided) |
137
+ | 2 | Change Analysis | `context.md`, call `ocr state transition` |
138
+ | 3 | Tech Lead Analysis | Update `context.md` with guidance, call `ocr state transition` |
139
+ | 4 | Parallel Reviews | `rounds/round-{n}/reviews/{type}-{n}.md` for each reviewer, call `ocr state transition` |
140
+ | 5 | Aggregation | (Inline analysis), call `ocr state transition` |
141
+ | 6 | Discourse | `rounds/round-{n}/discourse.md`, call `ocr state transition` |
142
+ | 7 | Synthesis | `rounds/round-{n}/final.md`, call `ocr state transition` |
143
+ | 8 | Presentation | Call `ocr state close` |
113
144
 
114
145
  ## State Transitions and File Validation
115
146
 
116
- When updating `state.json`, verify the corresponding file exists:
147
+ When calling `ocr state transition`, verify the corresponding file exists:
117
148
 
118
149
  | Phase | Verify file exists |
119
150
  |---------------------------|-------------------|
@@ -147,30 +178,9 @@ SESSION_ID="$(date +%Y-%m-%d)-$(git branch --show-current | tr '/' '-')"
147
178
 
148
179
  ## File Content Requirements
149
180
 
150
- ### state.json (Minimal Schema)
151
-
152
- ```json
153
- {
154
- "session_id": "{session-id}",
155
- "status": "active",
156
- "current_phase": "{phase-name}",
157
- "phase_number": 4,
158
- "current_round": 1,
159
- "started_at": "{ISO-8601-timestamp}",
160
- "round_started_at": "{ISO-8601-timestamp}",
161
- "updated_at": "{ISO-8601-timestamp}"
162
- }
163
- ```
164
-
165
- > **Note**: `round_started_at` is set when starting a new round (> 1) for accurate per-round timing display.
166
-
167
- **Derived from filesystem** (not stored in state.json):
168
- - Round count: enumerate `rounds/round-*/` directories
169
- - Round completion: check for `final.md` in round directory
170
- - Reviewers in round: list files in `rounds/round-{n}/reviews/`
171
- - Discourse complete: check for `discourse.md` in round directory
181
+ ### Session State
172
182
 
173
- See `references/session-state.md` for complete state management details.
183
+ Session state is stored in SQLite at `.ocr/data/ocr.db`. Use `ocr state show` to inspect current state. See `session-state.md` for the full data model.
174
184
 
175
185
  ### Reviewer Files
176
186
 
@@ -200,14 +210,14 @@ The `ocr progress` CLI depends on these exact file names:
200
210
 
201
211
  | CLI Feature | Files Read |
202
212
  |-------------|-----------|
203
- | Session detection | `state.json` |
204
- | Phase tracking | `state.json` → `current_phase` |
205
- | Current round | `state.json` → `current_round` (reconciled with filesystem) |
213
+ | Session detection | `ocr state show` / SQLite |
214
+ | Phase tracking | SQLite → `current_phase` |
215
+ | Current round | SQLite → `current_round` (reconciled with filesystem) |
206
216
  | Reviewer progress | `rounds/round-{n}/reviews/*.md` file existence |
207
217
  | Round completion | `rounds/round-{n}/final.md` existence |
208
- | Elapsed time | `state.json` → `started_at` |
218
+ | Elapsed time | SQLite → `started_at` |
209
219
 
210
- **Filesystem as truth**: The CLI derives round metadata from the filesystem, using `state.json` as a hint. If state.json is missing or inconsistent, the CLI reconstructs state by:
220
+ **Filesystem as truth**: The CLI derives round metadata from the filesystem, using SQLite as the primary state store. Round-level details are always reconciled against the filesystem by:
211
221
  1. Enumerating `rounds/round-*/` to count rounds
212
222
  2. Checking `final.md` presence to determine completion
213
223
  3. Listing `reviews/*.md` to identify reviewers
@@ -2,42 +2,50 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- OCR uses a **state file** approach for reliable progress tracking. The orchestrating agent writes to `.ocr/sessions/{id}/state.json` at each phase transition.
5
+ OCR uses **SQLite** as the primary state store for reliable progress tracking. The database is located at `.ocr/data/ocr.db` and is managed through the `ocr state` CLI commands. Agents use these CLI commands at each phase transition instead of writing state files directly.
6
6
 
7
7
  ## Cross-Mode Compatibility
8
8
 
9
- Sessions are **always** stored in the project's `.ocr/sessions/` directory, regardless of installation mode:
9
+ Sessions are **always** stored in the project's `.ocr/data/ocr.db` database and mirrored to `.ocr/sessions/`, regardless of installation mode:
10
10
 
11
- | Mode | Skills Location | Sessions Location |
12
- |------|-----------------|-------------------|
13
- | **CLI** | `.ocr/skills/` | `.ocr/sessions/` |
14
- | **Plugin** | Plugin cache | `.ocr/sessions/` |
11
+ | Mode | Skills Location | State Store | Sessions Mirror |
12
+ |------|-----------------|-------------|-----------------|
13
+ | **CLI** | `.ocr/skills/` | `.ocr/data/ocr.db` | `.ocr/sessions/` |
14
+ | **Plugin** | Plugin cache | `.ocr/data/ocr.db` | `.ocr/sessions/` |
15
15
 
16
16
  This means:
17
17
  - The `ocr progress` CLI works identically in both modes
18
18
  - Running `npx @open-code-review/cli progress` from any project picks up the session state
19
- - No configuration needed — the CLI always looks in `.ocr/sessions/`
19
+ - No configuration needed — the CLI always reads from `.ocr/data/ocr.db`
20
20
 
21
- ## State File Format (Minimal Schema)
21
+ ## State Data Model
22
+
23
+ The following fields are tracked per session in SQLite:
22
24
 
23
25
  ```json
24
26
  {
25
27
  "session_id": "{session-id}",
28
+ "workflow_type": "review",
26
29
  "status": "active",
27
30
  "current_phase": "reviews",
28
31
  "phase_number": 4,
29
32
  "current_round": 1,
33
+ "current_map_run": 1,
30
34
  "started_at": "{ISO-8601-TIMESTAMP}",
31
35
  "round_started_at": "{ISO-8601-TIMESTAMP}",
36
+ "map_started_at": "{ISO-8601-TIMESTAMP}",
32
37
  "updated_at": "{ISO-8601-TIMESTAMP}"
33
38
  }
34
39
  ```
35
40
 
36
- **Minimal by design**: Round metadata is derived from the filesystem, not stored in state.json.
41
+ **Minimal by design**: Round and map run metadata is derived from the filesystem, not stored in the database.
37
42
 
38
43
  **Field descriptions**:
39
- - `started_at`: When the session was created (first `/ocr-review`)
40
- - `round_started_at`: When the current round began (updated when starting round > 1)
44
+ - `workflow_type`: Current workflow type (`"review"` or `"map"`) — enables `ocr progress` to track correct workflow
45
+ - `started_at`: When the session was created (first `/ocr-review` or `/ocr-map`)
46
+ - `round_started_at`: When the current review round began (set when starting round ≥ 1)
47
+ - `map_started_at`: When the current map run began (set when starting a map run)
48
+ - `current_map_run`: Current map run number (only present during map workflow)
41
49
  - `updated_at`: Last modification time (updated at every phase transition)
42
50
 
43
51
  **Derived from filesystem** (not stored):
@@ -45,8 +53,17 @@ This means:
45
53
  - Round completion: check for `final.md` in round directory
46
54
  - Reviewers in round: list files in `rounds/round-{n}/reviews/`
47
55
  - Discourse complete: check for `discourse.md` in round directory
56
+ - Map run count: enumerate `map/runs/run-*/` directories
57
+ - Map run completion: check for `map.md` in run directory
58
+
59
+ ## Orchestration Events Table
60
+
61
+ In addition to the session state, SQLite tracks an **orchestration events timeline** in the `orchestration_events` table. Each `ocr state transition` call automatically logs an event, providing a complete history of phase transitions with timestamps. This enables:
62
+ - Post-session analytics (time spent per phase)
63
+ - Debugging stalled reviews
64
+ - Progress timeline reconstruction
48
65
 
49
- **IMPORTANT**: Timestamps MUST be generated dynamically using the current time in ISO 8601 format (e.g., `new Date().toISOString()` → `"2026-01-27T09:45:00.000Z"`). Do NOT copy example timestamps.
66
+ Events are stored with the session ID, phase name, phase number, and timestamp.
50
67
 
51
68
  ## Session Status
52
69
 
@@ -58,105 +75,158 @@ The `status` field controls session visibility:
58
75
  | `closed` | Complete and dismissed | Skipped | Cannot resume |
59
76
 
60
77
  **Lifecycle:**
61
- 1. Session created → `status: "active"`
62
- 2. Review in progress → `status: "active"`, `current_phase` updates
63
- 3. Phase 8 complete → `status: "closed"`, `current_phase: "complete"`
78
+ 1. Session created via `ocr state init` → `status: "active"`
79
+ 2. Review in progress → `status: "active"`, `current_phase` updates via `ocr state transition`
80
+ 3. Phase 8 complete → `ocr state close` sets `status: "closed"`, `current_phase: "complete"`
64
81
 
65
82
  The `ocr progress` command only auto-detects sessions with `status: "active"`. Closed sessions are accessible via `/ocr-history` and `/ocr-show`.
66
83
 
84
+ ## CLI Commands for State Management
85
+
86
+ Agents MUST use these CLI commands to manage session state. **Do NOT write state files directly.**
87
+
88
+ > **Note**: These commands require the OCR CLI. Install globally with `npm install -g @open-code-review/cli` or prefix with `npx @open-code-review/cli`.
89
+
90
+ ### `ocr state init` — Create a new session
91
+
92
+ ```bash
93
+ ocr state init \
94
+ --session-id "{session-id}" \
95
+ --branch "{branch}" \
96
+ --workflow-type review \
97
+ --session-dir ".ocr/sessions/{session-id}"
98
+ ```
99
+
100
+ Creates the session record in SQLite.
101
+
102
+ ### `ocr state transition` — Update phase at each boundary
103
+
104
+ ```bash
105
+ ocr state transition \
106
+ --phase "{phase-name}" \
107
+ --phase-number {N}
108
+ ```
109
+
110
+ For review workflows with multiple rounds:
111
+ ```bash
112
+ ocr state transition \
113
+ --phase "{phase-name}" \
114
+ --phase-number {N} \
115
+ --current-round {round-number}
116
+ ```
117
+
118
+ For map workflows:
119
+ ```bash
120
+ ocr state transition \
121
+ --phase "{phase-name}" \
122
+ --phase-number {N} \
123
+ --current-map-run {run-number}
124
+ ```
125
+
126
+ Updates the session in SQLite and logs an orchestration event.
127
+
128
+ ### `ocr state close` — Close the session
129
+
130
+ ```bash
131
+ ocr state close
132
+ ```
133
+
134
+ Sets `status: "closed"` and `current_phase: "complete"` in SQLite.
135
+
136
+ ### `ocr state show` — Read current session state
137
+
138
+ ```bash
139
+ ocr state show
140
+ ```
141
+
142
+ Outputs the current session state from SQLite. Use this to inspect current session state.
143
+
144
+ ### `ocr state sync` — Rebuild from filesystem
145
+
146
+ ```bash
147
+ ocr state sync
148
+ ```
149
+
150
+ Scans filesystem session directories and backfills any missing sessions into SQLite.
151
+
67
152
  ## Phase Transitions
68
153
 
69
154
  > **See `references/session-files.md` for the authoritative file manifest.**
70
155
 
71
- The Tech Lead MUST update `state.json` at each phase boundary:
156
+ The Tech Lead MUST call `ocr state transition` at each phase boundary:
72
157
 
73
- | Phase | When to Update | File Created |
74
- |-------|---------------|--------------|
158
+ ### Review Phases
159
+
160
+ | Phase | When to Transition | File Created |
161
+ |-------|-------------------|--------------|
75
162
  | context | After writing project standards | `discovered-standards.md` |
76
163
  | change-context | After writing change summary | `context.md`, `requirements.md` (if provided) |
77
164
  | analysis | After adding Tech Lead guidance | Update `context.md` |
78
165
  | reviews | After each reviewer completes | `rounds/round-{n}/reviews/{type}-{n}.md` |
79
166
  | discourse | After cross-reviewer discussion | `rounds/round-{n}/discourse.md` |
80
167
  | synthesis | After final review | `rounds/round-{n}/final.md` |
81
- | complete | After presenting to user | Set `status: "closed"` |
168
+ | complete | After presenting to user | Call `ocr state close` |
82
169
 
83
- ## Writing State
170
+ ### Map Phases
84
171
 
85
- **CRITICAL**: Always generate timestamps dynamically using the current UTC time in ISO 8601 format.
172
+ | Phase | When to Transition | File Created |
173
+ |-------|-------------------|--------------|
174
+ | map-context | After writing project standards | `discovered-standards.md` (shared) |
175
+ | topology | After topology analysis | `map/runs/run-{n}/topology.md` |
176
+ | flow-analysis | After flow analysis | `map/runs/run-{n}/flow-analysis.md` |
177
+ | requirements-mapping | After requirements mapping | `map/runs/run-{n}/requirements-mapping.md` |
178
+ | synthesis | After map generation | `map/runs/run-{n}/map.md` |
179
+ | complete | After presenting map | Keep `status: "active"` (session continues) |
86
180
 
87
- ### Generating Timestamps
181
+ ## State Transition Examples
88
182
 
89
- ```bash
90
- # macOS/Linux
91
- date -u +"%Y-%m-%dT%H:%M:%SZ"
92
- # Output: 2026-01-27T09:45:00Z
93
-
94
- # Windows (PowerShell)
95
- Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ" -AsUTC
183
+ When creating a new session (Phase 1 start):
96
184
 
97
- # Node.js / JavaScript
98
- new Date().toISOString()
185
+ ```bash
186
+ ocr state init \
187
+ --session-id "{session-id}" \
188
+ --branch "{branch}" \
189
+ --workflow-type review \
190
+ --session-dir ".ocr/sessions/{session-id}"
99
191
  ```
100
192
 
101
- When creating a new session (Phase 1 start):
193
+ When transitioning phases:
102
194
 
103
- ```json
104
- {
105
- "session_id": "{session-id}",
106
- "status": "active",
107
- "current_phase": "context",
108
- "phase_number": 1,
109
- "current_round": 1,
110
- "started_at": "{CURRENT_ISO_TIMESTAMP}",
111
- "updated_at": "{CURRENT_ISO_TIMESTAMP}"
112
- }
195
+ ```bash
196
+ ocr state transition --phase "reviews" --phase-number 4 --current-round 1
113
197
  ```
114
198
 
115
- When transitioning phases (preserve `started_at`, update `updated_at`):
199
+ When starting a map workflow:
116
200
 
117
- ```json
118
- {
119
- "session_id": "{session-id}",
120
- "status": "active",
121
- "current_phase": "reviews",
122
- "phase_number": 4,
123
- "current_round": 1,
124
- "started_at": "{PRESERVE_ORIGINAL}",
125
- "updated_at": "{CURRENT_ISO_TIMESTAMP}"
126
- }
201
+ ```bash
202
+ ocr state init \
203
+ --session-id "{session-id}" \
204
+ --branch "{branch}" \
205
+ --workflow-type map \
206
+ --session-dir ".ocr/sessions/{session-id}"
207
+
208
+ ocr state transition --phase "map-context" --phase-number 1 --current-map-run 1
127
209
  ```
128
210
 
129
211
  When closing a session (Phase 8 complete):
130
212
 
131
- ```json
132
- {
133
- "session_id": "{session-id}",
134
- "status": "closed",
135
- "current_phase": "complete",
136
- "phase_number": 8,
137
- "current_round": 1,
138
- "started_at": "{PRESERVE_ORIGINAL}",
139
- "updated_at": "{CURRENT_ISO_TIMESTAMP}"
140
- }
213
+ ```bash
214
+ ocr state close
141
215
  ```
142
216
 
143
217
  ## Benefits
144
218
 
145
219
  1. **Explicit state** — No inference required
146
- 2. **Atomic updates** — Single file write
147
- 3. **Rich metadata** — Reviewer assignments, timestamps
148
- 4. **Debuggable** — Human-readable JSON
149
- 5. **CLI-friendly** — Easy to parse programmatically
220
+ 2. **Atomic updates** — SQLite transactions ensure consistency
221
+ 3. **Rich metadata** — Reviewer assignments, timestamps, orchestration events
222
+ 4. **Debuggable** — `ocr state show` for human-readable output
223
+ 5. **CLI-friendly** — All state operations via `ocr state` commands
224
+ 6. **Timeline tracking** — Orchestration events table records full phase history
150
225
 
151
226
  ## Important
152
227
 
153
- The `state.json` file is the **primary** source for workflow progress. However, with the round-first architecture:
228
+ SQLite (`.ocr/data/ocr.db`) is the **sole** source for workflow progress. With the round-first architecture:
154
229
 
230
+ - **SQLite is truth for workflow state**: `current_phase`, `phase_number`, `status`, timestamps
155
231
  - **Filesystem is truth for round data**: Round count, completion, and reviewers are derived from `rounds/` directory structure
156
- - **state.json is truth for workflow state**: `current_phase`, `phase_number`, `status`, timestamps
157
- - **Reconciliation**: If state.json and filesystem disagree, the CLI reconciles by trusting the filesystem for round data
158
-
159
- If `state.json` is missing entirely, the CLI will show "Waiting for session..." until the orchestrating agent creates `state.json`. Future versions may implement filesystem reconstruction to derive:
160
- 1. Round count from `rounds/round-*/` directories
161
- 2. Round completion from `final.md` presence
162
- 3. Approximate phase from file existence
232
+ - **Reconciliation**: If SQLite and filesystem disagree, the CLI reconciles by trusting the filesystem for round data
@@ -128,6 +128,26 @@ mkdir -p .ocr/sessions
128
128
 
129
129
  This is safe to do automatically since it's just an empty directory for storing review sessions.
130
130
 
131
+ ### 5. Verify CLI is Reachable (CLI Mode Only)
132
+
133
+ The review and map workflows require `ocr state` commands at every phase transition. Verify the CLI is available:
134
+
135
+ ```bash
136
+ ocr --version 2>/dev/null || npx @open-code-review/cli --version 2>/dev/null
137
+ ```
138
+
139
+ **If neither works:**
140
+ ```
141
+ ⚠ OCR CLI not found in PATH.
142
+
143
+ The review workflow requires the CLI for state management (ocr state).
144
+ Install it globally or use npx:
145
+
146
+ npm install -g @open-code-review/cli
147
+ # or prefix commands with: npx @open-code-review/cli
148
+ ```
149
+ **Then WARN** (do not stop — the user may have the CLI installed elsewhere).
150
+
131
151
  ## Success Response
132
152
 
133
153
  If all checks pass, respond briefly and proceed: