ultra-builder-pro-cli 0.8.1 → 0.10.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +79 -1
  2. package/README.md +45 -26
  3. package/adapters/_shared/codex-assets.cjs +38 -0
  4. package/adapters/_shared/handbook.cjs +10 -1
  5. package/adapters/_shared/path-rewrite.cjs +3 -0
  6. package/adapters/_shared/runtime-assets.cjs +3 -1
  7. package/adapters/_shared/tests/handbook.test.cjs +9 -1
  8. package/adapters/_shared/tests/path-rewrite.test.cjs +3 -1
  9. package/adapters/_shared/tests/runtime-assets.test.cjs +5 -1
  10. package/adapters/kimi.js +642 -0
  11. package/adapters/opencode.js +46 -17
  12. package/adapters/tests/claude.test.cjs +4 -1
  13. package/adapters/tests/codex.test.cjs +4 -3
  14. package/adapters/tests/kimi-hook.test.cjs +122 -0
  15. package/adapters/tests/kimi.test.cjs +259 -0
  16. package/adapters/tests/opencode.test.cjs +46 -3
  17. package/bin/handbook.js +2 -2
  18. package/bin/install.js +9 -4
  19. package/bin/orchestrator.js +1 -1
  20. package/docs/AGENT-CONTEXT.md +39 -15
  21. package/docs/ARCHITECTURE.md +35 -9
  22. package/docs/PLAN.zh-CN.md +5 -4
  23. package/docs/ROADMAP.md +8 -7
  24. package/docs/RUNTIME-COMPAT-MATRIX.md +110 -64
  25. package/docs/USER-HANDBOOK-CONTRACT.md +13 -3
  26. package/hooks/README.md +6 -4
  27. package/hooks/active_task_context.py +14 -0
  28. package/hooks/adapters/kimi.py +162 -0
  29. package/hooks/context_spine.py +218 -0
  30. package/hooks/health_check.py +1 -1
  31. package/hooks/workflow_context.py +16 -123
  32. package/hooks/workflow_resume.py +21 -0
  33. package/mcp-server/lib/change-workflow.cjs +89 -11
  34. package/mcp-server/lib/change-workflow.test.cjs +202 -7
  35. package/mcp-server/lib/context-spine.cjs +331 -0
  36. package/mcp-server/lib/context-spine.test.cjs +73 -0
  37. package/mcp-server/lib/spec-learning.cjs +191 -0
  38. package/mcp-server/lib/spec-learning.test.cjs +62 -0
  39. package/mcp-server/lib/state-db.cjs +149 -4
  40. package/mcp-server/lib/state-db.test.cjs +61 -0
  41. package/mcp-server/server.cjs +31 -1
  42. package/mcp-server/tests/db-ops.test.cjs +3 -3
  43. package/mcp-server/tests/init-project.test.cjs +2 -2
  44. package/mcp-server/tests/server-contract.test.cjs +74 -0
  45. package/mcp-server/tests/state-db.test.cjs +20 -3
  46. package/package.json +4 -2
  47. package/skills/learn/SKILL.md +1 -0
  48. package/skills/ultra-change/SKILL.md +91 -118
  49. package/skills/ultra-deliver/SKILL.md +93 -221
  50. package/skills/ultra-dev/SKILL.md +81 -310
  51. package/skills/ultra-doctor/SKILL.md +1 -0
  52. package/skills/ultra-init/SKILL.md +1 -0
  53. package/skills/ultra-plan/SKILL.md +72 -292
  54. package/skills/ultra-review/SKILL.md +79 -407
  55. package/skills/ultra-status/SKILL.md +55 -168
  56. package/skills/ultra-test/SKILL.md +64 -183
  57. package/skills/ultra-think/SKILL.md +1 -0
  58. package/spec/cli-protocol.md +3 -0
  59. package/spec/mcp-tools.yaml +136 -7
  60. package/spec/schemas/skill-manifest.schema.json +2 -2
  61. package/spec/schemas/state-db.sql +35 -2
@@ -1,453 +1,125 @@
1
1
  ---
2
2
  name: ultra-review
3
- description: "Parallel code review orchestration with 6 specialized agents + coordinator. Zero context pollution - all output via JSON files."
3
+ description: "Run two independent review axes over one current diff, using bounded specialist workers and file-based evidence without context pollution."
4
4
  user-invocable: true
5
5
  runtime: all
6
6
  mcp_tools_required:
7
7
  - change.list
8
+ - change.get
9
+ - change.context
10
+ - change.breadcrumb
8
11
  - task.list
9
12
  ---
10
13
 
11
14
  # /ultra-review - Ultra Review System
12
15
 
13
- Orchestrates parallel code review using specialized agents. All findings written to JSON files to prevent context window pollution.
16
+ Review one explicit diff at the current HEAD. The top-level gates are independent:
14
17
 
15
- ## Workflow Tracking (MANDATORY)
18
+ 1. `spec_fidelity`: does the implementation satisfy intent, acceptance, delta,
19
+ documentation impact, and public seam?
20
+ 2. `engineering_standards`: is the implementation correct, safe, maintainable,
21
+ tested, observable, and recoverable?
16
22
 
17
- **On command start**, create tasks for each major step using `TaskCreate`:
18
-
19
- | Step | Subject | activeForm |
20
- |------|---------|------------|
21
- | 1 | Setup & Scope Detection | Detecting diff scope... |
22
- | 2 | Agent Selection | Selecting review agents... |
23
- | 3 | Background Execution | Running review agents... |
24
- | 4 | Wait & Coordinate | Waiting for agent results... |
25
- | 5 | Report to User | Generating review report... |
26
-
27
- **Before each step**: `TaskUpdate` → `status: "in_progress"`
28
- **After each step**: `TaskUpdate` → `status: "completed"`
29
- **On context recovery**: `TaskList` → resume from last incomplete step
23
+ One axis cannot compensate for the other. The coordinator may deduplicate the same
24
+ root cause but must preserve each source finding's severity, confidence, file/line,
25
+ and axis; it may not silently downgrade or rerank findings.
30
26
 
31
27
  ## Usage
32
28
 
29
+ ```text
30
+ /ultra-review # applicable specialists
31
+ /ultra-review all # all five specialists; delivery gate
32
+ /ultra-review quick # review-code only
33
+ /ultra-review security # review-code + review-errors
34
+ /ultra-review tests # review-tests only
35
+ /ultra-review recheck # unresolved P0/P1 scope
36
+ /ultra-review delta # files changed since last review
37
+ /ultra-review --range <range> | --pr <number>
33
38
  ```
34
- /ultra-review # Full review (smart skip based on diff content)
35
- /ultra-review all # Force ALL 6 agents, no auto-skip (pre-merge gate)
36
- /ultra-review quick # Quick review (review-code only)
37
- /ultra-review security # Security focus (review-code + review-errors)
38
- /ultra-review tests # Test quality focus (review-tests only)
39
- /ultra-review recheck # Re-check only P0/P1 files from last session
40
- /ultra-review delta # Review only changes since last review session
41
- /ultra-review <agents...> # Custom: e.g., /ultra-review tests errors types
42
- ```
43
-
44
- ### Scope Options (combinable with any mode)
45
-
46
- ```
47
- /ultra-review --pr 123 # Review PR #123 diff (base...head)
48
- /ultra-review --range main..HEAD # Review specific commit range
49
- /ultra-review --range abc123 # Review single commit
50
- /ultra-review security --pr 42 # Security review scoped to PR #42
51
- ```
52
-
53
- ## Orchestration Flow
54
-
55
- ### Phase 1: Setup & Scope Detection
56
-
57
- ```python
58
- # 1. Determine session context
59
- BRANCH = git branch --show-current # e.g., "feat/task-3-auth"
60
- ITER = count existing sessions matching this branch + 1 # iteration number
61
- CHANGE_ID = active change whose linked tasks/diff match this scope, else null
62
-
63
- # 2. Create session directory with full context
64
- SESSION_ID = "<YYYYMMDD-HHmmss>-<branch>-iter<N>"
65
- # e.g., "20260214-103000-feat-task-3-auth-iter2"
66
- SESSION_PATH = ".ultra/reviews/{SESSION_ID}/"
67
- mkdir -p SESSION_PATH
68
39
 
69
- # 3. Update session index (placeholder — verdict filled in Phase 5)
70
- # Append entry to .ultra/reviews/index.json with verdict="pending"
71
- # See Session Index below for full schema
40
+ ## Phase 1: Scope and Context
72
41
 
73
- # 4. Cleanup (see Lifecycle Management below)
42
+ 1. Resolve one diff range and `DIFF_FILES`. Include staged and unstaged changes for
43
+ default working-tree review.
44
+ 2. Bind to the single matching change through `change.list`/`task.list`; require an
45
+ explicit id if ambiguous.
46
+ 3. Compile `change.context` with `role=review`, `gate=review`, spec/delta/test refs,
47
+ current diff paths, and the public-seam execution contract.
48
+ 4. Stop on stale HEAD, blocked readiness, empty scope, or missing acceptance evidence.
49
+ 5. Create `.ultra/reviews/<session-id>/` and an index entry with reviewed HEAD,
50
+ change id, mode, range, and `verdict=pending`.
74
51
 
75
- # 5. Detect diff scope (priority order)
76
- ```
52
+ The spec-fidelity axis reads only the bounded intent/delta/baseline/acceptance packet;
53
+ the engineering axis reads the bounded diff and test evidence. Do not load unrelated
54
+ project history or external provider payloads.
77
55
 
78
- **Scope resolution priority:**
56
+ ## Phase 2: Specialist Selection
79
57
 
80
- | Flag | Diff Command | DIFF_RANGE |
81
- |------|-------------|------------|
82
- | `--pr NUMBER` | `gh pr diff NUMBER --name-only` | PR base...head |
83
- | `--range RANGE` | `git diff RANGE --name-only` | Specified range |
84
- | _(default)_ | `git diff --name-only HEAD` + `git diff --cached --name-only` | HEAD (unstaged + staged) |
58
+ Five engineering specialists feed the two-axis result:
85
59
 
86
- **PR scope details** (`--pr NUMBER`):
87
- ```bash
88
- # Get PR metadata for session naming
89
- gh pr view NUMBER --json headRefName,baseRefName,title
90
- # Get changed files
91
- gh pr diff NUMBER --name-only
92
- # Set DIFF_RANGE to base...head for agents
93
- DIFF_RANGE="$(gh pr view NUMBER --json baseRefName -q .baseRefName)..HEAD"
94
- ```
60
+ | Worker | Scope |
61
+ |---|---|
62
+ | `review-code` | correctness, security, live-path reachability |
63
+ | `review-tests` | meaningful coverage, mocks, red/green evidence |
64
+ | `review-errors` | swallowed failures, recovery, observability |
65
+ | `review-design` | types, boundaries, complexity, coupling |
66
+ | `review-comments` | stale or misleading comments/docs |
95
67
 
96
- **Range scope details** (`--range RANGE`):
97
- ```bash
98
- git diff RANGE --name-only
99
- DIFF_RANGE="RANGE"
100
- ```
68
+ `all` always runs all five. Other modes may skip a worker only when its scope is
69
+ provably absent, and the skip reason is written to the session. Spec fidelity is never
70
+ skipped for a change-linked review.
101
71
 
102
- **Continuous-change linkage**:
72
+ ## Phase 3: Background Execution (Zero Context Pollution)
103
73
 
104
- Call `change.list` and `task.list`, then bind the review to the single active or
105
- blocked change whose linked task files intersect `DIFF_FILES`. If multiple
106
- changes match, require an explicit scope instead of guessing. Write
107
- `change_id` and reviewed HEAD into `SUMMARY.json` and the session index so
108
- `/ultra-deliver` can use this artifact as review evidence. Initial-baseline
109
- reviews may use `change_id: null`.
74
+ Launch selected workers in background mode using multiple Task tool calls in a single
75
+ message when the current host supports it. Each bounded worker must:
110
76
 
111
- ### Phase 2: Agent Selection
77
+ 1. read its installed worker instructions;
78
+ 2. inspect only `DIFF_FILES`, `DIFF_RANGE`, and supplied role context;
79
+ 3. write `{SESSION_PATH}/{worker}.json` following
80
+ `$CLAUDE_PLUGIN_ROOT/skills/ultra-review/references/unified-schema.md`;
81
+ 4. return at most 12 findings with confidence >= 75, ordered by its own severity;
82
+ 5. output only a one-line file acknowledgement after the artifact exists.
112
83
 
113
- Based on the mode argument and file classification:
84
+ Do not copy worker transcripts into the parent context. Findings flow through files.
114
85
 
115
- **Mode: `full` (default)**
116
- Select all applicable agents based on diff content:
86
+ ## Phase 4: Wait & Coordinate (File-Based)
117
87
 
118
- | Agent | Skip Condition | Warning |
119
- |-------|---------------|---------|
120
- | review-code | Never skip | - |
121
- | review-tests | No test files in diff AND no source files without tests | WARN: "Code changed without test updates" |
122
- | review-errors | No error handling code detected | - |
123
- | review-design | No type definitions AND no function-level changes in diff | - |
124
- | review-comments | No comment changes in diff | - |
125
-
126
- **Auto-skip detection commands:**
127
- ```bash
128
- # Has type definitions?
129
- grep -l "interface \|type \|class \|enum " <diff_files>
130
-
131
- # Has comment changes?
132
- git diff HEAD -- <diff_files> | grep "^[+-].*//\|^[+-].*\*\|^[+-].*#"
133
-
134
- # Has test files?
135
- echo "<diff_files>" | grep -E "\.(test|spec)\.(ts|tsx|js|jsx)$|test_.*\.py$|.*_test\.go$"
136
-
137
- # Has error handling?
138
- grep -l "try\|catch\|\.catch\|throw\|Error(" <diff_files>
139
- ```
140
-
141
- **Mode: `all`** → Force ALL 6 agents, no auto-skip. Use for pre-merge gates (`/ultra-dev`).
142
- **Mode: `quick`** → review-code only
143
- **Mode: `security`** → review-code + review-errors
144
- **Mode: `tests`** → review-tests only
145
- **Mode: `recheck`** → See Recheck Logic below
146
- **Mode: `delta`** → See Delta Logic below
147
- **Mode: custom** → Parse agent names from arguments
148
-
149
- ### Phase 3: Background Execution (Zero Context Pollution)
150
-
151
- Launch ALL selected agents in **background mode** (`run_in_background: true`) using multiple Task tool calls in a single message. This prevents agent output from polluting the main conversation context.
152
-
153
- Each agent receives this prompt template:
154
-
155
- ```
156
- You are running as part of /ultra-review pipeline.
157
-
158
- SESSION_PATH: {SESSION_PATH}
159
- OUTPUT_FILE: {agent-name}.json
160
- DIFF_FILES: {comma-separated file list}
161
- DIFF_RANGE: {resolved DIFF_RANGE from Phase 1}
162
-
163
- Review the changed files and write your findings as JSON to:
164
- {SESSION_PATH}/{agent-name}.json
165
-
166
- Follow the ultra-review-findings-v1 schema exactly. Read the schema from:
167
- $CLAUDE_PLUGIN_ROOT/skills/ultra-review/references/unified-schema.md
168
-
169
- Only report findings with confidence >= 75.
170
-
171
- After writing the JSON file, output one line: "Wrote N findings (P0:X P1:X P2:X P3:X) to <filepath>"
172
- ```
173
-
174
- **Important**: Use `subagent_type` matching the agent name (e.g., `review-code`, `review-tests`, etc.).
175
-
176
- **Important**: Set `run_in_background: true` on every Task call. Do NOT read TaskOutput — this avoids injecting agent results into main context.
177
-
178
- Maximum 12 findings per agent. If you find more, report only the top 12 by severity (P0 first),
179
- then confidence. Note total count in your output line: "Wrote 12/23 findings..."
180
-
181
- **CRITICAL PROHIBITION**: After launching background agents, you MUST:
182
- 1. Call `review_wait.py` IMMEDIATELY — do NOT process idle notifications
183
- 2. NEVER call TaskOutput for any review agent — their output goes to JSON files only
184
- 3. Ignore all agent idle/completion messages between launch and wait script return
185
- 4. The ONLY information path from agents is: wait script → Read SUMMARY.json
186
-
187
- Violation of these rules causes context overflow. The review agents write to files; you read from files.
188
-
189
- ### Phase 4: Wait & Coordinate (File-Based)
190
-
191
- **Step 4a: Wait for agents** — Use Bash to block until all agents finish writing:
88
+ Validate worker files:
192
89
 
193
90
  ```bash
194
91
  python3 "$CLAUDE_PLUGIN_ROOT/skills/ultra-review/scripts/review_wait.py" {SESSION_PATH} agents {AGENT_COUNT}
195
92
  ```
196
93
 
197
- This polls for `review-*.json` files every 2 seconds. Timeout: 5 minutes.
198
- Output is structured JSON on stdout:
199
- - `status: "complete"` → all agents done, proceed normally
200
- - `status: "partial"` → timeout, log missing agents, pass only `agents_done` to coordinator, note partial review in SUMMARY
201
- - Exit code 1 (0 agents) → skip review, warn user, allow ultra-dev to continue
202
-
203
- **Step 4b: Launch coordinator in background:**
204
-
205
- Launch review-coordinator with `run_in_background: true`:
206
-
207
- ```
208
- You are the review coordinator.
209
-
210
- SESSION_PATH: {SESSION_PATH}
211
- AGENTS_RUN: {list of agents from wait output}
212
-
213
- Read all review-*.json files in the session directory, deduplicate findings,
214
- compute verdict, and generate SUMMARY.md + SUMMARY.json.
215
- ```
216
-
217
- **Step 4c: Wait for coordinator:**
94
+ Then run the installed `review-coordinator` over valid artifacts plus the independent
95
+ spec-fidelity assessment. It writes `SUMMARY.json` and `SUMMARY.md`. Validate:
218
96
 
219
97
  ```bash
220
98
  python3 "$CLAUDE_PLUGIN_ROOT/skills/ultra-review/scripts/review_wait.py" {SESSION_PATH} summary
221
99
  ```
222
100
 
223
- Output is a single verdict line (~15 tokens).
224
-
225
- ### Phase 5: Report to User
226
-
227
- After `review_wait.py summary` returns:
228
-
229
- 1. **Read SUMMARY.json** (one Read call, ~500 tokens) to get verdict and counts
230
- 2. **Update index.json** — fill in the placeholder entry with actual verdict, p0, p1, total from SUMMARY.json
231
- 3. Present a concise summary:
232
-
233
- ```markdown
234
- ## Review Complete
235
-
236
- **Verdict**: {APPROVE | COMMENT | REQUEST_CHANGES}
237
- **Findings**: X total (P0: A, P1: B, P2: C, P3: D)
238
- **Agents**: N ran, M succeeded
239
-
240
- ### Top Findings
241
- 1. [P0] {title} - {file}:{line}
242
- 2. [P1] {title} - {file}:{line}
243
- 3. ...
244
- (show up to 5 most critical findings)
245
-
246
- Full report: {SESSION_PATH}/SUMMARY.md
247
- ```
248
-
249
- Then ask the user:
250
- 1. **Fix all** - Fix all P0 and P1 issues
251
- 2. **Fix P0 only** - Fix only critical issues
252
- 3. **View full report** - Read SUMMARY.md
253
- 4. **Skip** - No fixes needed
254
-
255
- ## Recheck Logic
256
-
257
- When mode is `recheck`:
258
- 1. Find the most recent session **for the current branch** in `index.json`
259
- 2. Read its `SUMMARY.json`
260
- 3. Extract files with P0 or P1 findings
261
- 4. Run review-code only on those specific files
262
- 5. Compare with previous findings to show delta (resolved / new / unchanged)
101
+ Partial worker completion is explicit. Zero valid worker files blocks the engineering
102
+ axis. A coordinator may merge duplicate root causes but must retain source ids and the
103
+ highest original severity/confidence without reinterpreting priorities.
263
104
 
264
- ## Delta Logic
105
+ ## Phase 5: Report to User
265
106
 
266
- When mode is `delta`:
267
- 1. Find the most recent session **for the current branch** in `index.json`
268
- 2. Read its `SUMMARY.json` to get the scope of last review
269
- 3. Identify files changed since the last review:
270
- ```bash
271
- # If last session was commit-based, diff from that commit
272
- git diff --name-only <last-reviewed-commit>..HEAD
273
- # If last session was working-tree-based, diff current unstaged + staged
274
- git diff --name-only HEAD
275
- ```
276
- 4. **Exclude** files that have NOT changed since last review (already reviewed)
277
- 5. Run full agent set only on the newly changed files
278
- 6. In coordinator, merge with previous session findings (carry forward unresolved P0/P1)
107
+ `SUMMARY.json` must contain:
279
108
 
280
- **Use case**: Iterative development — fix issues, add code, only review what's new.
281
-
282
- ## Session Index
283
-
284
- A lightweight index file tracks all sessions for cross-referencing:
285
-
286
- **File**: `.ultra/reviews/index.json`
287
-
288
- ```json
289
- {
290
- "sessions": [
291
- {
292
- "id": "20260214-103000-feat-task-3-auth-iter1",
293
- "branch": "feat/task-3-auth",
294
- "change_id": "auth-change",
295
- "iteration": 1,
296
- "mode": "full",
297
- "timestamp": "2026-02-14T10:30:00Z",
298
- "verdict": "REQUEST_CHANGES",
299
- "p0": 2,
300
- "p1": 3,
301
- "total": 12,
302
- "parent": null
303
- },
304
- {
305
- "id": "20260214-113000-feat-task-3-auth-iter2",
306
- "branch": "feat/task-3-auth",
307
- "iteration": 2,
308
- "mode": "recheck",
309
- "timestamp": "2026-02-14T11:30:00Z",
310
- "verdict": "COMMENT",
311
- "p0": 0,
312
- "p1": 1,
313
- "total": 4,
314
- "parent": "20260214-103000-feat-task-3-auth-iter1"
315
- }
316
- ]
317
- }
318
- ```
109
+ - session/change id, reviewed HEAD/range, workers run/skipped;
110
+ - `axes.spec_fidelity` and `axes.engineering_standards`, each with its own verdict and
111
+ evidence refs;
112
+ - unchanged source findings with axis/source provenance;
113
+ - overall verdict: `REQUEST_CHANGES` when either axis has P0/P1 or fails;
114
+ - incomplete/partial status and exact rerun command.
319
115
 
320
- **Fields**:
116
+ Report the two axis verdicts first, then P0/P1 findings and the report path. Fixes are a
117
+ separate implementation action; review itself is read-only except for review artifacts.
118
+ After fixes, use `recheck` or `delta` rather than rerunning unrelated scope.
321
119
 
322
- | Field | Description |
323
- |-------|-------------|
324
- | `id` | Session directory name |
325
- | `branch` | Git branch at review time |
326
- | `change_id` | Continuous change reviewed, or null for initial baseline |
327
- | `iteration` | Nth review for this branch (auto-incremented) |
328
- | `mode` | Review mode used (full/quick/security/recheck/delta) |
329
- | `timestamp` | ISO 8601 |
330
- | `verdict` | APPROVE / COMMENT / REQUEST_CHANGES |
331
- | `p0`, `p1`, `total` | Finding counts from SUMMARY.json |
332
- | `parent` | Previous session ID for this branch (forms iteration chain) |
120
+ ## Convergence handoff
333
121
 
334
- **Branch-scoped queries**:
335
- - `recheck` / `delta`: filter `index.json` by `branch == current branch`, take latest
336
- - Avoids cross-task pollution when multiple branches are active
337
-
338
- ## Lifecycle Management
339
-
340
- **Cleanup strategy** (runs at Phase 1 of every `/ultra-review`):
341
-
342
- | Rule | Action |
343
- |------|--------|
344
- | Session > 7 days AND verdict = APPROVE | Delete directory + remove from index |
345
- | Session > 7 days AND verdict = COMMENT | Delete directory + remove from index |
346
- | Session > 7 days AND verdict = REQUEST_CHANGES | **Keep** (unresolved P0s should not be silently deleted) |
347
- | Session > 30 days (any verdict) | Delete directory + remove from index |
348
- | Per-branch limit: > 5 sessions | Delete oldest APPROVE/COMMENT sessions for that branch |
349
-
350
- **Implementation**:
351
- ```python
352
- # In Phase 1, after creating session directory:
353
- index = read index.json (or create if missing)
354
-
355
- # 1. Remove stale sessions
356
- now = current_time()
357
- for session in index.sessions:
358
- age_days = (now - session.timestamp).days
359
- if age_days > 30:
360
- delete(session)
361
- elif age_days > 7 and session.verdict != 'REQUEST_CHANGES':
362
- delete(session)
363
-
364
- # 2. Per-branch cap (keep latest 5)
365
- branch_sessions = [s for s in index.sessions if s.branch == current_branch]
366
- if len(branch_sessions) > 5:
367
- # Sort by timestamp, keep latest 5, delete rest (except REQUEST_CHANGES)
368
- to_remove = sorted(branch_sessions, key=timestamp)[:-5]
369
- for s in to_remove:
370
- if s.verdict != 'REQUEST_CHANGES':
371
- delete(s)
372
-
373
- # 3. Write updated index
374
- write index.json
375
- ```
376
-
377
- ## Fix Flow
378
-
379
- When user selects "Fix all" or "Fix P0 only" after review:
380
-
381
- **Step 0: Context Reset** (if verdict is REQUEST_CHANGES):
382
- - Run `/compact` to clear TDD cycle history from context
383
- - After compact, read `.ultra/workflow-state.json` to restore task context
384
- - Read `SUMMARY.json` fresh to get actionable findings
385
- - Then proceed with fixes below
386
-
387
- 1. **Read SUMMARY.json** — extract actionable P0/P1 items, sort by severity (P0 first)
388
- 2. **Group by file** — organize findings per file
389
- 3. **For each file with findings** (with circuit breaker tracking):
390
- a. Read the file once
391
- b. Apply ALL P0/P1 fixes for that file (batch within same file)
392
- c. Run the RELEVANT test file only:
393
- - Detect: `foo.ts` → `foo.test.ts` / `foo.spec.ts`
394
- - Run: `npx jest <test-file> --bail` or `pytest <test-file> -x`
395
- d. If test passes → mark findings as addressed, move to next file
396
- e. If test fails from THIS fix → increment per-file failure counter, revert, try alternative approach
397
- f. If test fails from pre-existing issue → note it, continue
398
- g. **Circuit Breaker**: If same file has 3 consecutive fix failures (test fails after each attempt):
399
- - Display: "Circuit breaker: {filename} — 3 consecutive fix failures. Likely architectural issue, not isolated bug."
400
- - Use AskUserQuestion:
401
- - A) "Skip this file, continue with others"
402
- - B) "Manually inspect this file" (exit auto-fix, user takes over)
403
- - C) "Abandon this fix round" (end fix flow, write UNRESOLVED.md)
404
- h. **Global Circuit Breaker**: If 3+ files trigger per-file circuit breaker:
405
- - Display: "Multiple files failing repeatedly — suggests systematic issue, not isolated bugs."
406
- - Recommend ending fix flow, write all unresolved findings to UNRESOLVED.md with tag `ARCHITECTURAL_CONCERN`
407
- 4. **After all files fixed**: run FULL test suite once as validation
408
- 5. **Update verdict** — after all P0 fixes applied and tests pass:
409
- ```bash
410
- python3 "$CLAUDE_PLUGIN_ROOT/skills/ultra-review/scripts/review_verdict_update.py" {SESSION_PATH}
411
- ```
412
- This recalculates the verdict from current P0/P1 counts and updates both SUMMARY.json and index.json.
413
- Without this step, pre_stop_check will block on stale REQUEST_CHANGES verdict.
414
- 6. **Optionally**: `/ultra-review recheck` (counts as iteration, respects max 2 cap)
415
-
416
- **Important**: The main agent (not review agents) performs fixes. Review agents are read-only by design.
417
-
418
- ## Integration with ultra-dev
419
-
420
- This skill integrates with the TDD workflow:
421
- - After `tdd-runner` confirms tests pass
422
- - Before `commit` or PR creation
423
- - Quick mode for iterative development
424
- - Full mode for pre-merge gate
425
- - Recheck mode after fixing review findings
426
- - Delta mode for incremental review during long development sessions
427
-
428
- ## Error Handling
429
-
430
- - If no diff detected: inform user, suggest using `--range` or `--pr` to specify scope
431
- - If `--pr` fails (no gh CLI or no PR): fall back to default diff and warn user
432
- - If an agent fails to write JSON: note in coordinator input, skip that agent's findings
433
- - If coordinator fails: fall back to reading individual JSON files and presenting raw findings
434
- - If no agents selected (all skipped): inform user with skip reasons
435
-
436
- ## Directory Structure
437
-
438
- ```
439
- .ultra/reviews/
440
- ├── index.json # Session index (all sessions metadata)
441
- ├── 20260214-103000-feat-task-3-auth-iter1/ # First review
442
- │ ├── review-code.json
443
- │ ├── review-tests.json
444
- │ ├── review-errors.json
445
- │ ├── review-design.json
446
- │ ├── review-comments.json
447
- │ ├── SUMMARY.json
448
- │ └── SUMMARY.md
449
- └── 20260214-113000-feat-task-3-auth-iter2/ # Recheck after fixes
450
- ├── review-code.json
451
- ├── SUMMARY.json
452
- └── SUMMARY.md
453
- ```
122
+ At the final HEAD, recompile `change.context` with `role=review` and a next action of
123
+ `Converge and deliver the verified change`. The delivery workflow must submit two
124
+ separate `review` evidence rows: one with `axis=spec_fidelity`, one with
125
+ `axis=engineering_standards`. A single aggregate “review passed” row is invalid.