@open-code-review/agents 1.4.0 → 1.5.1

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.
@@ -2,23 +2,25 @@
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
  {
@@ -36,7 +38,7 @@ This means:
36
38
  }
37
39
  ```
38
40
 
39
- **Minimal by design**: Round and map run 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.
40
42
 
41
43
  **Field descriptions**:
42
44
  - `workflow_type`: Current workflow type (`"review"` or `"map"`) — enables `ocr progress` to track correct workflow
@@ -46,8 +48,6 @@ This means:
46
48
  - `current_map_run`: Current map run number (only present during map workflow)
47
49
  - `updated_at`: Last modification time (updated at every phase transition)
48
50
 
49
- **CRITICAL for timing**: When starting a NEW workflow type in an existing session (e.g., starting `/ocr-map` after `/ocr-review`), you MUST set the workflow-specific start time (`map_started_at` or `round_started_at`) to the current timestamp. This ensures `ocr progress` shows accurate elapsed time for each workflow.
50
-
51
51
  **Derived from filesystem** (not stored):
52
52
  - Round count: enumerate `rounds/round-*/` directories
53
53
  - Round completion: check for `final.md` in round directory
@@ -56,7 +56,14 @@ This means:
56
56
  - Map run count: enumerate `map/runs/run-*/` directories
57
57
  - Map run completion: check for `map.md` in run directory
58
58
 
59
- **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.
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
65
+
66
+ Events are stored with the session ID, phase name, phase number, and timestamp.
60
67
 
61
68
  ## Session Status
62
69
 
@@ -68,34 +75,102 @@ The `status` field controls session visibility:
68
75
  | `closed` | Complete and dismissed | Skipped | Cannot resume |
69
76
 
70
77
  **Lifecycle:**
71
- 1. Session created → `status: "active"`
72
- 2. Review in progress → `status: "active"`, `current_phase` updates
73
- 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"`
74
81
 
75
82
  The `ocr progress` command only auto-detects sessions with `status: "active"`. Closed sessions are accessible via `/ocr-history` and `/ocr-show`.
76
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
+
77
152
  ## Phase Transitions
78
153
 
79
154
  > **See `references/session-files.md` for the authoritative file manifest.**
80
155
 
81
- The Tech Lead MUST update `state.json` at each phase boundary:
156
+ The Tech Lead MUST call `ocr state transition` at each phase boundary:
82
157
 
83
158
  ### Review Phases
84
159
 
85
- | Phase | When to Update | File Created |
86
- |-------|---------------|--------------|
160
+ | Phase | When to Transition | File Created |
161
+ |-------|-------------------|--------------|
87
162
  | context | After writing project standards | `discovered-standards.md` |
88
163
  | change-context | After writing change summary | `context.md`, `requirements.md` (if provided) |
89
164
  | analysis | After adding Tech Lead guidance | Update `context.md` |
90
165
  | reviews | After each reviewer completes | `rounds/round-{n}/reviews/{type}-{n}.md` |
91
166
  | discourse | After cross-reviewer discussion | `rounds/round-{n}/discourse.md` |
92
167
  | synthesis | After final review | `rounds/round-{n}/final.md` |
93
- | complete | After presenting to user | Set `status: "closed"` |
168
+ | complete | After presenting to user | Call `ocr state close` |
94
169
 
95
170
  ### Map Phases
96
171
 
97
- | Phase | When to Update | File Created |
98
- |-------|---------------|--------------|
172
+ | Phase | When to Transition | File Created |
173
+ |-------|-------------------|--------------|
99
174
  | map-context | After writing project standards | `discovered-standards.md` (shared) |
100
175
  | topology | After topology analysis | `map/runs/run-{n}/topology.md` |
101
176
  | flow-analysis | After flow analysis | `map/runs/run-{n}/flow-analysis.md` |
@@ -103,110 +178,55 @@ The Tech Lead MUST update `state.json` at each phase boundary:
103
178
  | synthesis | After map generation | `map/runs/run-{n}/map.md` |
104
179
  | complete | After presenting map | Keep `status: "active"` (session continues) |
105
180
 
106
- ## Writing State
107
-
108
- **CRITICAL**: Always generate timestamps using a **tool call** — never construct them manually.
109
-
110
- ### Generating Timestamps
111
-
112
- > ⚠️ **NEVER** write timestamps manually (e.g., `"2026-01-29T22:00:00Z"`). Always use a tool call to get the current time. Manual timestamps risk timezone errors, typos, and incorrect elapsed time display.
181
+ ## State Transition Examples
113
182
 
114
- **Required approach**: Use `run_command` tool to execute:
183
+ When creating a new session (Phase 1 start):
115
184
 
116
185
  ```bash
117
- # macOS/Linux USE THIS
118
- date -u +"%Y-%m-%dT%H:%M:%SZ"
119
- # Output: 2026-01-27T09:45:00Z
120
- ```
121
-
122
- **Example tool call** (do this before writing state.json):
186
+ ocr state init \
187
+ --session-id "{session-id}" \
188
+ --branch "{branch}" \
189
+ --workflow-type review \
190
+ --session-dir ".ocr/sessions/{session-id}"
123
191
  ```
124
- run_command: date -u +"%Y-%m-%dT%H:%M:%SZ"
125
- ```
126
-
127
- Then use the **exact output** as the timestamp value in state.json.
128
192
 
129
- **Why this matters**: The `ocr progress` command calculates elapsed time from these timestamps. If a timestamp is incorrect (wrong timezone, future time, etc.), the progress display will show wrong/counting-down times.
193
+ When transitioning phases:
130
194
 
131
- When creating a new session (Phase 1 start):
132
-
133
- ```json
134
- {
135
- "session_id": "{session-id}",
136
- "status": "active",
137
- "current_phase": "context",
138
- "phase_number": 1,
139
- "current_round": 1,
140
- "started_at": "{CURRENT_ISO_TIMESTAMP}",
141
- "updated_at": "{CURRENT_ISO_TIMESTAMP}"
142
- }
195
+ ```bash
196
+ ocr state transition --phase "reviews" --phase-number 4 --current-round 1
143
197
  ```
144
198
 
145
- When transitioning phases (preserve `started_at`, update `updated_at`):
146
-
147
- ```json
148
- {
149
- "session_id": "{session-id}",
150
- "workflow_type": "review",
151
- "status": "active",
152
- "current_phase": "reviews",
153
- "phase_number": 4,
154
- "current_round": 1,
155
- "started_at": "{PRESERVE_ORIGINAL}",
156
- "round_started_at": "{PRESERVE_ORIGINAL}",
157
- "updated_at": "{CURRENT_ISO_TIMESTAMP}"
158
- }
159
- ```
199
+ When starting a map workflow:
160
200
 
161
- When starting a map workflow (new map run or first map in session):
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}"
162
207
 
163
- ```json
164
- {
165
- "session_id": "{session-id}",
166
- "workflow_type": "map",
167
- "status": "active",
168
- "current_phase": "map-context",
169
- "phase_number": 1,
170
- "current_map_run": 1,
171
- "started_at": "{PRESERVE_ORIGINAL_OR_SET_IF_NEW}",
172
- "map_started_at": "{CURRENT_ISO_TIMESTAMP}",
173
- "updated_at": "{CURRENT_ISO_TIMESTAMP}"
174
- }
208
+ ocr state transition --phase "map-context" --phase-number 1 --current-map-run 1
175
209
  ```
176
210
 
177
- **CRITICAL**: Always set `map_started_at` to `{CURRENT_ISO_TIMESTAMP}` when starting a new map run. This ensures accurate elapsed time tracking even if the session had a prior review workflow.
178
-
179
211
  When closing a session (Phase 8 complete):
180
212
 
181
- ```json
182
- {
183
- "session_id": "{session-id}",
184
- "status": "closed",
185
- "current_phase": "complete",
186
- "phase_number": 8,
187
- "current_round": 1,
188
- "started_at": "{PRESERVE_ORIGINAL}",
189
- "updated_at": "{CURRENT_ISO_TIMESTAMP}"
190
- }
213
+ ```bash
214
+ ocr state close
191
215
  ```
192
216
 
193
217
  ## Benefits
194
218
 
195
219
  1. **Explicit state** — No inference required
196
- 2. **Atomic updates** — Single file write
197
- 3. **Rich metadata** — Reviewer assignments, timestamps
198
- 4. **Debuggable** — Human-readable JSON
199
- 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
200
225
 
201
226
  ## Important
202
227
 
203
- 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:
204
229
 
230
+ - **SQLite is truth for workflow state**: `current_phase`, `phase_number`, `status`, timestamps
205
231
  - **Filesystem is truth for round data**: Round count, completion, and reviewers are derived from `rounds/` directory structure
206
- - **state.json is truth for workflow state**: `current_phase`, `phase_number`, `status`, timestamps
207
- - **Reconciliation**: If state.json and filesystem disagree, the CLI reconciles by trusting the filesystem for round data
208
-
209
- 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:
210
- 1. Round count from `rounds/round-*/` directories
211
- 2. Round completion from `final.md` presence
212
- 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: