specrails 0.2.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 (74) hide show
  1. package/.claude/skills/openspec-apply-change/SKILL.md +156 -0
  2. package/.claude/skills/openspec-archive-change/SKILL.md +114 -0
  3. package/.claude/skills/openspec-bulk-archive-change/SKILL.md +246 -0
  4. package/.claude/skills/openspec-continue-change/SKILL.md +118 -0
  5. package/.claude/skills/openspec-explore/SKILL.md +290 -0
  6. package/.claude/skills/openspec-ff-change/SKILL.md +101 -0
  7. package/.claude/skills/openspec-new-change/SKILL.md +74 -0
  8. package/.claude/skills/openspec-onboard/SKILL.md +529 -0
  9. package/.claude/skills/openspec-sync-specs/SKILL.md +138 -0
  10. package/.claude/skills/openspec-verify-change/SKILL.md +168 -0
  11. package/README.md +226 -0
  12. package/VERSION +1 -0
  13. package/bin/specrails.js +41 -0
  14. package/commands/setup.md +851 -0
  15. package/install.sh +488 -0
  16. package/package.json +34 -0
  17. package/prompts/analyze-codebase.md +87 -0
  18. package/prompts/generate-personas.md +61 -0
  19. package/prompts/infer-conventions.md +72 -0
  20. package/templates/agents/sr-architect.md +194 -0
  21. package/templates/agents/sr-backend-developer.md +54 -0
  22. package/templates/agents/sr-backend-reviewer.md +139 -0
  23. package/templates/agents/sr-developer.md +146 -0
  24. package/templates/agents/sr-doc-sync.md +167 -0
  25. package/templates/agents/sr-frontend-developer.md +48 -0
  26. package/templates/agents/sr-frontend-reviewer.md +132 -0
  27. package/templates/agents/sr-product-analyst.md +36 -0
  28. package/templates/agents/sr-product-manager.md +148 -0
  29. package/templates/agents/sr-reviewer.md +265 -0
  30. package/templates/agents/sr-security-reviewer.md +178 -0
  31. package/templates/agents/sr-test-writer.md +163 -0
  32. package/templates/claude-md/root.md +50 -0
  33. package/templates/commands/sr/batch-implement.md +282 -0
  34. package/templates/commands/sr/compat-check.md +271 -0
  35. package/templates/commands/sr/health-check.md +396 -0
  36. package/templates/commands/sr/implement.md +972 -0
  37. package/templates/commands/sr/product-backlog.md +195 -0
  38. package/templates/commands/sr/refactor-recommender.md +169 -0
  39. package/templates/commands/sr/update-product-driven-backlog.md +272 -0
  40. package/templates/commands/sr/why.md +96 -0
  41. package/templates/personas/persona.md +43 -0
  42. package/templates/personas/the-maintainer.md +78 -0
  43. package/templates/rules/layer.md +8 -0
  44. package/templates/security/security-exemptions.yaml +20 -0
  45. package/templates/settings/confidence-config.json +17 -0
  46. package/templates/settings/settings.json +15 -0
  47. package/templates/web-manager/README.md +107 -0
  48. package/templates/web-manager/client/index.html +12 -0
  49. package/templates/web-manager/client/package-lock.json +1727 -0
  50. package/templates/web-manager/client/package.json +20 -0
  51. package/templates/web-manager/client/src/App.tsx +83 -0
  52. package/templates/web-manager/client/src/components/AgentActivity.tsx +19 -0
  53. package/templates/web-manager/client/src/components/CommandInput.tsx +81 -0
  54. package/templates/web-manager/client/src/components/LogStream.tsx +57 -0
  55. package/templates/web-manager/client/src/components/PipelineSidebar.tsx +65 -0
  56. package/templates/web-manager/client/src/components/SearchBox.tsx +34 -0
  57. package/templates/web-manager/client/src/hooks/usePipeline.ts +62 -0
  58. package/templates/web-manager/client/src/hooks/useWebSocket.ts +59 -0
  59. package/templates/web-manager/client/src/main.tsx +9 -0
  60. package/templates/web-manager/client/tsconfig.json +21 -0
  61. package/templates/web-manager/client/tsconfig.node.json +11 -0
  62. package/templates/web-manager/client/vite.config.ts +13 -0
  63. package/templates/web-manager/package-lock.json +3327 -0
  64. package/templates/web-manager/package.json +30 -0
  65. package/templates/web-manager/server/hooks.test.ts +196 -0
  66. package/templates/web-manager/server/hooks.ts +71 -0
  67. package/templates/web-manager/server/index.test.ts +186 -0
  68. package/templates/web-manager/server/index.ts +99 -0
  69. package/templates/web-manager/server/spawner.test.ts +319 -0
  70. package/templates/web-manager/server/spawner.ts +89 -0
  71. package/templates/web-manager/server/types.ts +46 -0
  72. package/templates/web-manager/tsconfig.json +14 -0
  73. package/templates/web-manager/vitest.config.ts +8 -0
  74. package/update.sh +877 -0
@@ -0,0 +1,972 @@
1
+ # Implementation Pipeline
2
+
3
+ Full OpenSpec lifecycle with specialized agents: architect designs, developer implements, reviewer validates and archives. Handles 1 to N features — adapts automatically (sequential for 1, parallel with worktrees for N).
4
+
5
+ **MANDATORY: Always follow this pipeline exactly as written. NEVER skip, shortcut, or "optimize away" any phase — even if the task seems simple enough to do directly. The orchestrator MUST launch the architect, developer, and reviewer agents as specified. Do NOT implement changes yourself in the main conversation; delegate to the agents defined in each phase. No exceptions.**
6
+
7
+ **Input:** $ARGUMENTS — accepts three modes:
8
+
9
+ 1. **Issue numbers** (recommended): `#85, #71, #63` — implement these specific GitHub Issues directly. Skips exploration and selection.
10
+ 2. **Text description** (single feature): `"add price history chart"` — implement a single feature from a description. Skips exploration and selection.
11
+ 3. **Area names** (fallback): `Analytics, UI, Testing` — explores areas and picks the best items. Only use if no backlog issues exist.
12
+
13
+ **IMPORTANT:** Before running, ensure Read/Write/Bash/Glob/Grep permissions are set to "allow" — background agents cannot request permissions interactively.
14
+
15
+ ---
16
+
17
+ ## Phase -1: Environment Setup (cloud pre-flight)
18
+
19
+ **This phase runs BEFORE anything else.** Detect if we're in a cloud/remote environment and ensure all required tools are available.
20
+
21
+ ### Detection
22
+
23
+ Check the environment variable `CLAUDE_CODE_ENTRYPOINT`. If it contains `remote_mobile` or `remote_web`, OR if `CLAUDE_CODE_REMOTE` is `true`, we're in a **cloud environment**.
24
+
25
+ ### Checks to run (sequential, fail-fast)
26
+
27
+ #### 1. GitHub CLI authentication
28
+
29
+ ```bash
30
+ gh auth status 2>&1
31
+ ```
32
+
33
+ - Set `GH_AVAILABLE=true/false` for later phases.
34
+
35
+ #### 2. OpenSpec CLI
36
+
37
+ ```bash
38
+ which openspec && openspec --version
39
+ ```
40
+
41
+ - If missing: try `npm install -g @openspec/cli`
42
+ - If install fails: **STOP** — openspec is required.
43
+
44
+ #### 3. Project dependencies
45
+
46
+ {{DEPENDENCY_CHECK_COMMANDS}}
47
+
48
+ #### 4. Test runner
49
+
50
+ {{TEST_RUNNER_CHECK}}
51
+
52
+ ### Summary
53
+
54
+ Print a setup report:
55
+
56
+ ```
57
+ ## Environment Setup
58
+ | Tool | Status | Notes |
59
+ |------|--------|-------|
60
+ | Backlog provider | ok/missing | {{BACKLOG_PROVIDER_NAME}} |
61
+ | OpenSpec | ok | ... |
62
+ | Dependencies | ok | ... |
63
+ | Test runner | ok | ... |
64
+ ```
65
+
66
+ **Pass `TEST_CMD` (or equivalent) and `BACKLOG_AVAILABLE` forward** — all later phases must use these.
67
+
68
+ ---
69
+
70
+ ## Phase 0: Parse input and determine mode
71
+
72
+ ### Flag Detection
73
+
74
+ Before parsing input, scan `$ARGUMENTS` for control flags:
75
+
76
+ - If `--dry-run` or `--preview` is present in `$ARGUMENTS`:
77
+ - Set `DRY_RUN=true`
78
+ - Strip the flag from the arguments before further parsing
79
+ - Print: `[dry-run] Preview mode active — no git, PR, or backlog operations will run.`
80
+ - Set `CACHE_DIR=.claude/.dry-run/<kebab-case-feature-name>` (derive after parsing the remaining input)
81
+ - Note: if a cache already exists at `CACHE_DIR`, print `[dry-run] Overwriting existing cache at CACHE_DIR` before overwriting.
82
+
83
+ - If `--apply <feature-name>` is present in `$ARGUMENTS`:
84
+ - Set `APPLY_MODE=true`
85
+ - Set `APPLY_TARGET=<feature-name>` (the argument immediately following `--apply`)
86
+ - Set `CACHE_DIR=.claude/.dry-run/<feature-name>`
87
+ - Verify `CACHE_DIR` exists. If it does not: print `[apply] Error: no cached dry-run found at CACHE_DIR` and stop.
88
+ - Skip Phases 1–4b. Go directly to Phase 4c (the apply path handles the rest).
89
+ - Strip `--apply` and the feature name before further parsing.
90
+
91
+ - If `--confidence-override "<reason>"` is present in `$ARGUMENTS`:
92
+ - Set `CONFIDENCE_OVERRIDE_REASON=<reason>` (the quoted string immediately following `--confidence-override`)
93
+ - Strip `--confidence-override` and the reason before further parsing.
94
+
95
+ If none of these flags is present: `DRY_RUN=false`, `APPLY_MODE=false`, `CONFIDENCE_OVERRIDE_REASON=""`. Pipeline runs as normal.
96
+
97
+ Note: `CACHE_DIR` for `--dry-run` is finalized after the feature name is derived from the remaining input. All subsequent phases that reference `CACHE_DIR` have access to it.
98
+
99
+ Initialize conflict-tracking variables:
100
+ - `SNAPSHOTS_CAPTURED=false` — set to true in Phase 0 if issue snapshots are successfully written.
101
+ - `CONFLICT_OVERRIDES=[]` — list of conflict records where the user chose to continue; appended by Phase 3a.0 and Phase 4c.0.
102
+
103
+ ---
104
+
105
+ **If the user passed a text description** (e.g. `"add feature X"`):
106
+ - **Single-feature mode**. Derive a kebab-case change name.
107
+ - Set `SINGLE_MODE = true`. No worktrees, no parallelism.
108
+ - **Skip Phase 1 and Phase 2** — go directly to Phase 3a.
109
+
110
+ **If the user passed issue/ticket references** (e.g. `#85, #71` for GitHub or `PROJ-85, PROJ-71` for JIRA):
111
+ - Fetch each issue/ticket:
112
+ ```bash
113
+ {{BACKLOG_VIEW_CMD}}
114
+ ```
115
+ - Extract area, value, effort, and feature details from each issue body.
116
+ - If only 1 issue: set `SINGLE_MODE = true`.
117
+ - **Skip Phase 1 and Phase 2** — go directly to confirmation table.
118
+
119
+ #### Phase 0 snapshot capture
120
+
121
+ After fetching issue refs, capture a baseline snapshot for conflict detection.
122
+
123
+ **If `GH_AVAILABLE=true` and the input mode was issue numbers:**
124
+
125
+ For each resolved issue number, run:
126
+
127
+ ```bash
128
+ gh issue view {number} --json number,title,state,assignees,labels,body,updatedAt
129
+ ```
130
+
131
+ Build a snapshot object for each issue:
132
+ - `number`: integer issue number
133
+ - `title`: issue title string
134
+ - `state`: `"open"` or `"closed"`
135
+ - `assignees`: array of assignee login names, sorted alphabetically
136
+ - `labels`: array of label names, sorted alphabetically
137
+ - `body_sha`: SHA-256 of the raw body string — compute with:
138
+ ```bash
139
+ echo -n "{body}" | sha256sum | cut -d' ' -f1
140
+ ```
141
+ If `sha256sum` is not available, fall back to `openssl dgst -sha256 -r` or `shasum -a 256`.
142
+ - `updated_at`: the `updatedAt` value from the GitHub API response
143
+ - `captured_at`: current local time in ISO 8601 format
144
+
145
+ Write the following JSON to `.claude/backlog-cache.json` (overwrite fully — this establishes a fresh baseline for this run):
146
+
147
+ ```json
148
+ {
149
+ "schema_version": "1",
150
+ "provider": "github",
151
+ "last_updated": "<ISO 8601 timestamp>",
152
+ "written_by": "implement",
153
+ "issues": {
154
+ "<number>": { <snapshot object> },
155
+ ...
156
+ }
157
+ }
158
+ ```
159
+
160
+ If the write succeeds: set `SNAPSHOTS_CAPTURED=true`.
161
+
162
+ If the write fails (e.g., `.claude/` directory does not exist): print `[backlog-cache] Warning: could not write cache. Conflict detection disabled for this run.` and set `SNAPSHOTS_CAPTURED=false`. Do NOT abort the pipeline.
163
+
164
+ **If `GH_AVAILABLE=false` or input was not issue numbers:**
165
+
166
+ Set `SNAPSHOTS_CAPTURED=false`. Print: `[conflict-check] Snapshot skipped — GH unavailable or non-issue input.`
167
+
168
+ #### Gitignore advisory
169
+
170
+ If `SNAPSHOTS_CAPTURED=true`, check whether `.gitignore` already covers the cache file:
171
+
172
+ ```bash
173
+ grep -q "backlog-cache" .gitignore 2>/dev/null || \
174
+ grep -q "\.claude/" .gitignore 2>/dev/null
175
+ ```
176
+
177
+ If neither pattern is found, print:
178
+
179
+ ```
180
+ [backlog-cache] Suggestion: add '.claude/backlog-cache.json' to .gitignore to avoid committing ephemeral cache state.
181
+ ```
182
+
183
+ This advisory is non-blocking and suppressed when `.gitignore` already covers the file.
184
+
185
+ **If the user passed area names**:
186
+ - Check for open backlog issues. If found, filter and pick top 3.
187
+ - If none, proceed to Phase 1.
188
+
189
+ ---
190
+
191
+ ## Phase 1: Explore (parallel)
192
+
193
+ **Only runs if Phase 0 found no backlog issues AND user passed area names.**
194
+
195
+ For each area, launch a **sr-product-manager** agent (`subagent_type: sr-product-manager`, `run_in_background: true`).
196
+
197
+ Wait for all to complete. Read their output.
198
+
199
+ ## Phase 2: Select
200
+
201
+ **Only runs if Phase 1 ran.**
202
+
203
+ Pick the single idea with the best impact/effort ratio from each exploration. Present to user and wait for confirmation.
204
+
205
+ ## Phase 3a.0: Pre-architect conflict check
206
+
207
+ **Guard:** If `SNAPSHOTS_CAPTURED=false` OR `DRY_RUN=true`, print `[conflict-check] Skipped — SNAPSHOTS_CAPTURED=false (or dry-run mode).` and proceed directly to Phase 3a.
208
+
209
+ Otherwise, re-fetch each issue in scope and diff against the Phase 0 snapshot:
210
+
211
+ For each issue number in `ISSUE_REFS`:
212
+
213
+ ```bash
214
+ gh issue view {number} --json number,title,state,assignees,labels,body,updatedAt
215
+ ```
216
+
217
+ If the `gh` command returns non-zero (issue deleted or inaccessible): treat as a CRITICAL conflict — field `"state"`, was `<cached state>`, now `"deleted"`.
218
+
219
+ Otherwise, reconstruct a current snapshot (same shape as Phase 0: sort `assignees` and `labels`, compute `body_sha`).
220
+
221
+ **Short-circuit:** If `current.updatedAt == cached.updated_at`, mark the issue as clean and skip field comparison.
222
+
223
+ **Field comparison** (only when `updatedAt` differs):
224
+
225
+ | Field | Conflict if... | Severity |
226
+ |-------|----------------|----------|
227
+ | `state` | value differs (`open` → `closed`) | CRITICAL |
228
+ | `state` | value differs (`closed` → `open`) | WARNING |
229
+ | `title` | string differs | WARNING |
230
+ | `assignees` | sorted array differs | WARNING |
231
+ | `labels` | sorted array differs | INFO |
232
+ | `body_sha` | SHA differs | WARNING |
233
+
234
+ Collect all conflicts across all issues. If none: print `[conflict-check] All issues clean (Phase 3a.0). Proceeding.` and continue to Phase 3a.
235
+
236
+ **If conflicts exist**, print the following report and await user input:
237
+
238
+ ```
239
+ ## Backlog Conflict Detected
240
+
241
+ The following issues changed since Phase 0 snapshot (captured at <captured_at>):
242
+
243
+ | Issue | Field | Severity | Was | Now |
244
+ |-------|-------|----------|-----|-----|
245
+ | #N | state | CRITICAL | open | closed |
246
+ | #N | body | WARNING | <sha-prefix> | <sha-prefix> |
247
+
248
+ How would you like to proceed?
249
+ [A] Abort — stop the pipeline and exit cleanly
250
+ [C] Continue — proceed despite the conflicts (logged)
251
+
252
+ Enter A or C:
253
+ ```
254
+
255
+ For `body_sha` rows in the table, display only the first 8 characters of each SHA as the "Was" and "Now" values.
256
+
257
+ **Input handling:**
258
+ - Accept `A`, `a` (abort) or `C`, `c` (continue).
259
+ - Re-prompt on any other input, up to 3 times total.
260
+ - After 3 invalid inputs: print `[conflict-abort] Defaulting to abort after 3 invalid inputs.` and abort.
261
+
262
+ **On abort:** Print `[conflict-abort] Pipeline aborted. Re-run /sr:implement after resolving the issues.` and exit. No git state is left behind.
263
+
264
+ **On continue:** Print `[conflict-override] Continuing. N conflict(s) logged.` Append each conflict to `CONFLICT_OVERRIDES` as `{phase: "3a.0", issue: "#N", field: "<field>", severity: "<severity>", was: "<was>", now: "<now>"}`. Proceed to Phase 3a.
265
+
266
+ ## Phase 3a: Architect (parallel, in main repo)
267
+
268
+ For each chosen idea, launch an **sr-architect** agent (`subagent_type: sr-architect`, `run_in_background: true`).
269
+
270
+ Each architect creates OpenSpec artifacts in `openspec/changes/<name>/`.
271
+
272
+ Each agent's prompt should include:
273
+ - Description of the feature
274
+ - Context from exploration (if applicable)
275
+ - Instructions to create: proposal.md, design.md, delta-spec, tasks.md, context-bundle.md
276
+ - Tags for each task: {{LAYER_TAGS}}
277
+
278
+ ### 3a.1 Identify shared file conflicts
279
+
280
+ **Only runs in multi-feature mode** (more than one feature). Skip entirely if `SINGLE_MODE=true`.
281
+
282
+ After all architect agents complete, before launching any developer agent:
283
+
284
+ #### Step 1: Extract file references
285
+
286
+ For each `openspec/changes/<name>/tasks.md`, extract all paths listed under `**Files:**` entries (both `Create:` and `Modify:` lines). Normalize paths: strip leading `./`.
287
+
288
+ #### Step 2: Build the shared-file registry
289
+
290
+ Group file paths across all features. Any path appearing in two or more features' task lists is a **shared file**. Store as `SHARED_FILES` map: `{path: {features: [...], risk: ""}}`.
291
+
292
+ #### Step 3: Classify risk
293
+
294
+ For each shared file, classify risk based on file type and which regions each feature modifies (consult each feature's context-bundle.md "Exact Changes" section):
295
+
296
+ | Risk | Condition |
297
+ |------|-----------|
298
+ | `low` | Both features only append new named sections not present in the other feature's changes |
299
+ | `medium` | Both features modify structurally distinct regions (different `##` sections or different top-level YAML keys) |
300
+ | `high` | Both features modify the same region (same `##` section, same YAML key subtree, or any region in shell scripts) |
301
+
302
+ Shell scripts (`.sh`, `.bash`): always `high`.
303
+ Non-existent files that two features both create: always `high`.
304
+
305
+ #### Step 4: Derive MERGE_ORDER
306
+
307
+ Sort features so that for any pair sharing a `high`-risk file, one appears before the other. Use topological sort; break ties alphabetically. Set `MERGE_ORDER` = sorted feature list.
308
+
309
+ #### Step 5: Print pre-flight report
310
+
311
+ ```
312
+ ## Shared File Analysis
313
+
314
+ | File | Features | Risk |
315
+ |------|----------|------|
316
+ | <path> | <feature-a>, <feature-b> | <risk> |
317
+
318
+ Merge order: <feature-a> → <feature-b> → <feature-c>
319
+
320
+ High-risk files detected. These files will be merged sequentially.
321
+ Developers will still run in parallel — merge order applies at Phase 4a only.
322
+ ```
323
+
324
+ If no shared files: print `No shared files detected. All features modify independent files.`
325
+
326
+ ### 3a.2 Pre-validate architect output
327
+
328
+ Quick-check each architect's artifacts:
329
+ 1. tasks.md exists and has tasks
330
+ 2. context-bundle.md exists
331
+ 3. File references are real (>70% must exist)
332
+ 4. Layer tags present on tasks
333
+
334
+ ## Phase 3b: Implement
335
+
336
+ ### Pre-flight: Verify Bash permission
337
+
338
+ Before launching any developer agent, run a trivial Bash command to confirm Bash is allowed.
339
+
340
+ ### Launch developers
341
+
342
+ **Read reviewer learnings:** Check `.claude/agent-memory/sr-reviewer/common-fixes.md` and include in developer prompts.
343
+
344
+ #### Dry-Run: Redirect developer writes
345
+
346
+ **If `DRY_RUN=true`**, include the following in every developer agent prompt:
347
+
348
+ > IMPORTANT: This is a dry-run. Write all new or modified files under:
349
+ > .claude/.dry-run/\<feature-name\>/
350
+ >
351
+ > Mirror the real destination path within this directory. For example:
352
+ > Real path: src/utils/parser.ts
353
+ > Write to: .claude/.dry-run/\<feature-name\>/src/utils/parser.ts
354
+ >
355
+ > Do NOT write to real file paths. After writing each file, append an entry
356
+ > to .claude/.dry-run/\<feature-name\>/.cache-manifest.json using this JSON format:
357
+ > {"cached_path": "...", "real_path": "...", "operation": "create|modify"}
358
+
359
+ **If `DRY_RUN=false`**: developer agent instructions are unchanged.
360
+
361
+ #### Choosing the right developer agent
362
+
363
+ For each feature, analyze the tasks' layer tags:
364
+
365
+ {{DEVELOPER_ROUTING_RULES}}
366
+
367
+ #### Launch modes
368
+
369
+ **If `SINGLE_MODE`**: Launch in the main repo, foreground.
370
+ **If multiple features**: Launch in isolated worktrees (`isolation: worktree`, `run_in_background: true`).
371
+
372
+ Wait for all developers to complete.
373
+
374
+ ## Phase 3c: Write Tests
375
+
376
+ Launch a **sr-test-writer** agent for each feature immediately after its developer completes.
377
+
378
+ Construct the agent invocation prompt to include:
379
+ - **IMPLEMENTED_FILES_LIST**: the complete list of files the developer created or modified for this feature
380
+ - **TASK_DESCRIPTION**: the original task or feature description that drove the implementation
381
+
382
+ ### Launch modes
383
+
384
+ **If `SINGLE_MODE`**: Launch a single sr-test-writer agent in the foreground (`run_in_background: false`). Wait for it to complete before proceeding to Phase 4.
385
+
386
+ **If multiple features (worktrees)**: Launch one sr-test-writer agent per feature, each in its corresponding worktree (`isolation: worktree`, `run_in_background: true`). Wait for all sr-test-writer agents to complete before proceeding to Phase 4.
387
+
388
+ ### Dry-run behavior
389
+
390
+ **If `DRY_RUN=true`**, include in every test-writer agent prompt:
391
+
392
+ > IMPORTANT: This is a dry-run. Write all new or modified test files under:
393
+ > .claude/.dry-run/\<feature-name\>/
394
+ >
395
+ > Mirror the real destination path within this directory. After writing each file, append an entry
396
+ > to .claude/.dry-run/\<feature-name\>/.cache-manifest.json using:
397
+ > {"cached_path": "...", "real_path": "...", "operation": "create"}
398
+
399
+ ### Failure handling
400
+
401
+ If a test-writer agent fails or times out:
402
+ - Record `Tests: FAILED` for that feature in the Phase 4e report
403
+ - Continue to Phase 4 — the sr-test-writer failure is non-blocking
404
+ - Include in the reviewer agent prompt: "Note: the sr-test-writer failed for this feature. Check for coverage gaps."
405
+
406
+ ## Phase 3d: Doc Sync
407
+
408
+ Launch a **sr-doc-sync** agent for each feature after its tests are written.
409
+
410
+ Construct the agent invocation prompt to include:
411
+ - **IMPLEMENTED_FILES_LIST**: the complete list of files the developer created or modified for this feature
412
+ - **TASK_DESCRIPTION**: the original task or feature description that drove the implementation
413
+
414
+ ### Launch modes
415
+
416
+ **If `SINGLE_MODE`**: Launch a single sr-doc-sync agent in the foreground (`run_in_background: false`). Wait for it to complete before proceeding to Phase 4.
417
+
418
+ **If multiple features (worktrees)**: Launch one sr-doc-sync agent per feature, each in its corresponding worktree (`isolation: worktree`, `run_in_background: true`). Wait for all sr-doc-sync agents to complete before proceeding to Phase 4.
419
+
420
+ ### Dry-run behavior
421
+
422
+ **If `DRY_RUN=true`**, include in every doc-sync agent prompt:
423
+
424
+ > IMPORTANT: This is a dry-run. Write all new or modified doc files under:
425
+ > .claude/.dry-run/\<feature-name\>/
426
+ >
427
+ > Mirror the real destination path within this directory. After writing each file, append an entry
428
+ > to .claude/.dry-run/\<feature-name\>/.cache-manifest.json using:
429
+ > {"cached_path": "...", "real_path": "...", "operation": "create|modify"}
430
+
431
+ ### Failure handling
432
+
433
+ If a doc-sync agent fails or times out:
434
+ - Record `Docs: FAILED` for that feature in the Phase 4e report
435
+ - Continue to Phase 4 — the sr-doc-sync failure is non-blocking
436
+ - Include in the reviewer agent prompt: "Note: the sr-doc-sync agent failed for this feature."
437
+
438
+ ## Phase 4: Merge & Review
439
+
440
+ **This phase is fully autonomous.**
441
+
442
+ ### 4a. Merge worktree changes to main repo
443
+
444
+ - If `SINGLE_MODE`: skip (no worktrees were used). Proceed to Phase 4b.
445
+ - If `DRY_RUN=true`: apply the merge algorithm below, writing all outputs to `CACHE_DIR/<file-path>` instead of the main repo working tree. Do NOT clean up worktrees in dry-run mode.
446
+ - Otherwise: apply the merge algorithm below, writing outputs to the main repo working tree. Clean up worktrees at the end.
447
+
448
+ #### Merge Algorithm
449
+
450
+ Process features in `MERGE_ORDER` sequence. For each feature:
451
+
452
+ **Step 1: Identify changed files**
453
+
454
+ ```bash
455
+ git -C <worktree-path> diff main --name-only
456
+ ```
457
+
458
+ Split into `exclusive_files` (only this feature modifies them) and `shared_files_for_this_feature` (also modified by another feature in MERGE_ORDER).
459
+
460
+ **Step 2: Merge exclusive files**
461
+
462
+ Copy directly from worktree to target:
463
+ ```bash
464
+ cp <worktree-path>/<file> <target>/<file>
465
+ ```
466
+ Log: `Copied (exclusive): <file>`
467
+
468
+ **Step 3: Merge shared files**
469
+
470
+ For each shared file, choose strategy by file type:
471
+
472
+ **Strategy A — Markdown section-aware merge** (`.md` files):
473
+ 1. Read base: current content of `<target>/<file>`.
474
+ 2. Read incoming: `<worktree-path>/<file>`.
475
+ 3. Parse both into sections using `##` heading boundaries (heading line + all content until next `##` or EOF).
476
+ 4. Build section maps: `{heading_text: content}` for base and incoming.
477
+ 5. Merge:
478
+ - Section in base only: keep.
479
+ - Section in incoming only: append to merged output.
480
+ - Section in both, content identical: keep base.
481
+ - Section in both, content differs: insert conflict markers:
482
+ ```
483
+ <<<<<<< <feature-name>
484
+ <incoming section content>
485
+ =======
486
+ <base section content>
487
+ >>>>>>> base
488
+ ```
489
+ Log: `CONFLICT: <file> — section "<heading>" requires manual resolution.`
490
+ 6. Write merged result to `<target>/<file>`.
491
+
492
+ **Strategy B — Unified diff sequential apply** (all other file types):
493
+ 1. Generate incoming diff against original `main`:
494
+ ```bash
495
+ git -C <worktree-path> diff main -- <file>
496
+ ```
497
+ 2. Apply to current target:
498
+ ```bash
499
+ patch --forward --fuzz=3 <target>/<file> < <diff>
500
+ ```
501
+ 3. If `patch` succeeds: log `Merged (diff-apply): <file>`.
502
+ 4. If `patch` fails: insert conflict markers around rejected hunks. Log: `CONFLICT: <file> — N hunks rejected.`
503
+
504
+ If `patch` is not available (detected in Phase -1): use Strategy A for all file types and print: `[warn] patch not available — using section-aware fallback for all shared files.`
505
+
506
+ **Step 4: Record outcomes**
507
+
508
+ Maintain `MERGE_REPORT`:
509
+ - `cleanly_merged`: exclusive files + shared files with no conflicts
510
+ - `auto_resolved`: shared files merged without conflict markers
511
+ - `requires_resolution`: `{file, feature, regions}` for files with conflict markers
512
+
513
+ **Step 5: Emit merge report**
514
+
515
+ After all features are processed:
516
+
517
+ ```
518
+ ## Phase 4a Merge Report
519
+
520
+ ### Cleanly Merged
521
+ - <file> (exclusive to <feature>)
522
+
523
+ ### Auto-Resolved
524
+ - <file> (features: <a>, <b> — distinct sections)
525
+
526
+ ### Requires Manual Resolution
527
+ - <file> (features: <a>, <b> — conflicting section: "<heading>")
528
+ Search for `<<<<<<< <feature-name>` to locate conflict markers.
529
+
530
+ Pipeline will continue. Fix conflicts above before the reviewer runs CI.
531
+ ```
532
+
533
+ **Step 6: Clean up worktrees** (skip if `DRY_RUN=true`)
534
+
535
+ ```bash
536
+ git worktree remove <worktree-path> --force
537
+ ```
538
+
539
+ Pass `MERGE_REPORT` to the Phase 4b reviewer agent prompt, listing any files in `requires_resolution`.
540
+
541
+ ### 4b. Layer Dispatch and Review
542
+
543
+ #### Step 1: Layer Classification
544
+
545
+ Before launching any reviewer, classify `MODIFIED_FILES_LIST` into layer-specific file sets.
546
+
547
+ **Frontend files** — a file is frontend if any of these conditions match:
548
+ - Extension is one of: `.jsx`, `.tsx`, `.vue`, `.svelte`, `.css`, `.scss`, `.sass`, `.less`, `.html`, `.htm`
549
+ - Extension is `.js` or `.ts` AND path contains one of: `components/`, `pages/`, `views/`, `ui/`, `client/`, `frontend/`, `app/`
550
+ - Path starts with: `public/`, `static/`, `assets/`
551
+
552
+ Set `FRONTEND_FILES` = files matching frontend rules.
553
+
554
+ **Backend files** — a file is backend if any of these conditions match:
555
+ - Extension is one of: `.py`, `.go`, `.java`, `.rb`, `.php`, `.rs`, `.cs`, `.sql`
556
+ - Extension is `.js` or `.ts` AND path contains one of: `server/`, `api/`, `routes/`, `controllers/`, `services/`, `models/`, `db/`, `backend/`
557
+ - Path is under: `migrations/`, `alembic/`, `db/migrate/`
558
+
559
+ Set `BACKEND_FILES` = files matching backend rules.
560
+
561
+ **Overlap rule:** a file may appear in both `FRONTEND_FILES` and `BACKEND_FILES` (e.g., a Next.js API route at `pages/api/`). Both reviewers will scan it independently.
562
+
563
+ If `FRONTEND_FILES` is empty: set `FRONTEND_REVIEW_REPORT = "SKIPPED"` and skip frontend-reviewer launch. Note: "No frontend files detected."
564
+ If `BACKEND_FILES` is empty: set `BACKEND_REVIEW_REPORT = "SKIPPED"` and skip backend-reviewer launch. Note: "No backend files detected."
565
+
566
+ #### Step 2: Launch Layer Reviewers in Parallel
567
+
568
+ Launch all applicable layer reviewers in parallel (`run_in_background: true`):
569
+
570
+ **sr-frontend-reviewer** (if `FRONTEND_FILES` is non-empty):
571
+ - Pass `FRONTEND_FILES_LIST`: the list of files in `FRONTEND_FILES`
572
+ - Pass `PIPELINE_CONTEXT`: brief description of what was implemented
573
+
574
+ **sr-backend-reviewer** (if `BACKEND_FILES` is non-empty):
575
+ - Pass `BACKEND_FILES_LIST`: the list of files in `BACKEND_FILES`
576
+ - Pass `PIPELINE_CONTEXT`: brief description of what was implemented
577
+
578
+ **sr-security-reviewer** (always):
579
+ - Pass `MODIFIED_FILES_LIST`: the complete list of all files created or modified during this run
580
+ - Pass `PIPELINE_CONTEXT`: brief description of what was implemented
581
+ - Pass the exemptions config path: `.claude/security-exemptions.yaml`
582
+
583
+ Wait for all launched layer reviewers to complete before proceeding to Step 3.
584
+
585
+ Parse status lines from each completed reviewer:
586
+ - `FRONTEND_REVIEW_STATUS: ISSUES_FOUND` or `CLEAN` → set `FRONTEND_STATUS`
587
+ - `BACKEND_REVIEW_STATUS: ISSUES_FOUND` or `CLEAN` → set `BACKEND_STATUS`
588
+ - `SECURITY_STATUS: BLOCKED | WARNINGS | CLEAN` → set `SECURITY_BLOCKED=true` if `BLOCKED`, otherwise `false`
589
+
590
+ If a layer reviewer fails or times out: set the relevant report variable to `"ERROR: reviewer did not complete"` and continue.
591
+
592
+ #### Step 3: Launch Generalist Reviewer
593
+
594
+ Construct the generalist reviewer's invocation prompt with layer reports injected. Set each variable to the full output of the corresponding reviewer, or to the string `"SKIPPED"` if that reviewer was not launched:
595
+
596
+ - `FRONTEND_REVIEW_REPORT`: full output of frontend-reviewer (or `"SKIPPED"`)
597
+ - `BACKEND_REVIEW_REPORT`: full output of backend-reviewer (or `"SKIPPED"`)
598
+ - `SECURITY_REVIEW_REPORT`: full output of security-reviewer
599
+
600
+ Include in the reviewer prompt:
601
+ - Full CI commands
602
+ - Cross-feature merge issue checks
603
+ - Instruction to record learnings to `common-fixes.md`
604
+ - Instruction to archive completed changes via OpenSpec
605
+ - The three layer report variables substituted into the `[injected]` slots in the reviewer agent template
606
+
607
+ Note: if total layer report length is very large, truncate each layer report to its findings tables only (omit skipped-file logs) to stay within prompt limits.
608
+
609
+ **The security gate (blocking ship on `SECURITY_STATUS: BLOCKED`) is enforced in Phase 4c.** Do not apply it here.
610
+
611
+ Launch the **sr-reviewer** agent (foreground, `run_in_background: false`). Wait for it to complete.
612
+
613
+ **If `DRY_RUN=true`**, add the following to the reviewer agent prompt:
614
+
615
+ > Note: This is a dry-run review. Developer files are under .claude/.dry-run/\<feature-name\>/.
616
+ > Read modified files from there. Write any reviewer fixes back to CACHE_DIR (not real paths).
617
+ > CI commands may be run — they read the real repo, but be aware developer changes are not
618
+ > yet applied to real paths.
619
+
620
+ ### 4b-conf. Confidence Gate
621
+
622
+ After the generalist reviewer agent completes, evaluate the confidence score before proceeding to Phase 4c.
623
+
624
+ **In multi-feature mode (worktrees):** run this gate once per feature immediately after that feature's reviewer completes. Each feature is evaluated independently — a block on one feature does not prevent another feature's gate from running.
625
+
626
+ #### Step 1 — Read score file
627
+
628
+ Path: `openspec/changes/<name>/confidence-score.json`
629
+
630
+ - If the file does not exist:
631
+ - Set `CONFIDENCE_STATUS=MISSING`
632
+ - Print: `[confidence] Warning: confidence-score.json not found. Proceeding without gate.`
633
+ - Continue to Phase 4c.
634
+
635
+ #### Step 2 — Read config
636
+
637
+ Path: `.claude/confidence-config.json`
638
+
639
+ - If the file does not exist:
640
+ - Use built-in defaults (overall: 70; type_correctness: 60; pattern_adherence: 60; test_coverage: 60; security: 75; architectural_alignment: 60).
641
+ - Print:
642
+ ```
643
+ [confidence] No confidence-config.json found. Using built-in defaults.
644
+ [confidence] To customize thresholds, create .claude/confidence-config.json.
645
+ ```
646
+ - If `enabled: false` in the config:
647
+ - Print: `[confidence] Gate disabled. Skipping.`
648
+ - Set `CONFIDENCE_STATUS=DISABLED`
649
+ - Continue to Phase 4c.
650
+
651
+ #### Step 3 — Compare scores
652
+
653
+ - Check `overall` against `thresholds.overall`.
654
+ - Check each of the five aspects against `thresholds.aspects.<aspect>`.
655
+ - Collect all breaches as a list: `{aspect, actual_score, threshold, delta}`.
656
+
657
+ #### Step 4 — Apply on_breach
658
+
659
+ **If no breaches:**
660
+ - Print: `[confidence] All scores meet thresholds. Proceeding.`
661
+ - Set `CONFIDENCE_STATUS=PASS`
662
+ - Continue to Phase 4c.
663
+
664
+ **If breaches exist and `on_breach: "block"`:**
665
+
666
+ 1. Check for `--confidence-override`:
667
+ - If `CONFIDENCE_OVERRIDE_REASON` is non-empty and `override_allowed: true` in the config:
668
+ - Print: `[confidence] Override accepted. Reason: <CONFIDENCE_OVERRIDE_REASON>. Proceeding with gate bypassed.`
669
+ - Set `CONFIDENCE_STATUS=OVERRIDE`
670
+ - Continue to Phase 4c.
671
+ - If `CONFIDENCE_OVERRIDE_REASON` is non-empty but `override_allowed: false` in the config:
672
+ - Print: `[confidence] Override is disabled in confidence-config.json.`
673
+ - (Fall through to block below.)
674
+ - If `CONFIDENCE_OVERRIDE_REASON` is empty or override was rejected:
675
+ - Print the Breach Report (see format below).
676
+ - Set `CONFIDENCE_BLOCKED=true`
677
+ - Set `CONFIDENCE_STATUS=BLOCKED`
678
+ - **Halt: do not proceed to Phase 4c.**
679
+
680
+ **If breaches exist and `on_breach: "warn"`:**
681
+ - Print the Breach Report.
682
+ - Set `CONFIDENCE_STATUS=WARN`
683
+ - Continue to Phase 4c.
684
+
685
+ #### Breach Report Format
686
+
687
+ ```
688
+ ## Confidence Gate: BLOCKED
689
+
690
+ The reviewer's confidence scores do not meet configured thresholds.
691
+
692
+ | Aspect | Score | Threshold | Delta |
693
+ |--------|-------|-----------|-------|
694
+ | <aspect> | <actual> | <threshold> | <delta (negative)> |
695
+
696
+ ### Reviewer Notes on Low-Scoring Aspects
697
+
698
+ **<aspect> (<score>):** <note from confidence-score.json>
699
+
700
+ ### Flags
701
+
702
+ - <flag-1>
703
+ - <flag-2>
704
+ (omit this section if flags array is empty)
705
+
706
+ ### Next Steps
707
+
708
+ 1. Address the concerns above and re-run `/sr:implement`.
709
+ 2. Or, if you have reviewed the concerns and accept the risk, re-run with an override:
710
+ `/sr:implement #N --confidence-override "reason"`
711
+
712
+ Pipeline halted. No git operations have been performed.
713
+ ```
714
+
715
+ #### Dry-Run Behavior
716
+
717
+ When `DRY_RUN=true`, the reviewer still writes `confidence-score.json` (it is an OpenSpec artifact, not a git artifact). Phase 4b-conf still evaluates the score. If `CONFIDENCE_BLOCKED=true`, add to `.cache-manifest.json` under `skipped_operations`:
718
+ ```
719
+ "confidence-gate: blocked — Phase 4c skipped"
720
+ ```
721
+
722
+ ### Phase 4c.0: Pre-ship conflict check
723
+
724
+ **Guard:** If `SNAPSHOTS_CAPTURED=false` OR `DRY_RUN=true`, print `[conflict-check] Skipped — SNAPSHOTS_CAPTURED=false (or dry-run mode).` and proceed directly to Phase 4c.
725
+
726
+ This check is independent of Phase 3a.0. Even if the user chose to continue through a conflict at Phase 3a.0, this gate re-checks all in-scope issues against the Phase 0 snapshot. It is the final gate before any code reaches git.
727
+
728
+ Re-fetch each issue in `ISSUE_REFS` and diff against `.claude/backlog-cache.json` using the same algorithm as Phase 3a.0:
729
+
730
+ ```bash
731
+ gh issue view {number} --json number,title,state,assignees,labels,body,updatedAt
732
+ ```
733
+
734
+ If the cache file is missing or malformed JSON at this point: log `[conflict-check] Warning: cache file missing or unreadable. Skipping diff for this run.` and proceed to Phase 4c (treat as clean).
735
+
736
+ Apply the same short-circuit (`updatedAt` match → clean), field comparison, and severity classification as Phase 3a.0.
737
+
738
+ If all issues are clean: print `[conflict-check] All issues clean (Phase 4c.0). Proceeding.` and continue.
739
+
740
+ If conflicts exist: print the same conflict report format as Phase 3a.0 (with `Phase 4c.0` context) and await `A`/`C` input (same re-prompt and default-abort logic).
741
+
742
+ **On abort:** Print `[conflict-abort] Pipeline aborted. Re-run /sr:implement after resolving the issues.` and exit. No git operations have been performed at this point.
743
+
744
+ **On continue:** Print `[conflict-override] Continuing. N conflict(s) logged.` Append each conflict to `CONFLICT_OVERRIDES` as `{phase: "4c.0", issue: "#N", field: "<field>", severity: "<severity>", was: "<was>", now: "<now>"}`. Proceed to Phase 4c.
745
+
746
+ ### 4c. Ship — Git & backlog updates
747
+
748
+ **Security gate:** If `SECURITY_BLOCKED=true`:
749
+ 1. Print all Critical findings from the security-reviewer output
750
+ 2. Do NOT create a branch, commit, push, or PR
751
+ 3. Print: "Pipeline blocked by security findings. Fix the Critical issues listed above and re-run /sr:implement."
752
+ 4. Skip to Phase 4e.
753
+
754
+ ### Dry-Run Gate
755
+
756
+ **If `DRY_RUN=true`:**
757
+ Print: `[dry-run] Skipping all git and backlog operations.`
758
+ Record skipped operations to `.cache-manifest.json` under `skipped_operations`:
759
+ - `"git: branch creation (feat/<name>)"`
760
+ - `"git: commit"`
761
+ - `"git: push"`
762
+ - `"github: pr creation"` (if `GH_AVAILABLE=true`)
763
+ - `"github: issue comment #N"` for each issue in scope (if `BACKLOG_WRITE=true`)
764
+ - `"github: issue close #N (via PR merge)"` for each fully resolved issue (if `BACKLOG_WRITE=true`)
765
+
766
+ Then skip the rest of Phase 4c and proceed directly to Phase 4e.
767
+
768
+ **If `APPLY_MODE=true`:**
769
+ 1. Read `.cache-manifest.json` from `CACHE_DIR`.
770
+ 2. For each entry in `files`: copy `cached_path` to `real_path`, creating directories as needed.
771
+ 3. Print: `[apply] Copied N files from .claude/.dry-run/<feature-name>/ to real locations.`
772
+ 4. Then proceed with Phase 4c normally (GIT_AUTO logic, backlog updates) using the real files.
773
+ 5. On successful completion of Phase 4c: delete `CACHE_DIR` and print `[apply] Cache cleaned up.`
774
+ If Phase 4c fails: preserve `CACHE_DIR` for re-run.
775
+
776
+ **Otherwise:** proceed as normal.
777
+
778
+ ---
779
+
780
+ This phase respects the `GIT_AUTO` and `BACKLOG_WRITE` settings from configuration.
781
+
782
+ #### If `GIT_AUTO=true` (automatic shipping)
783
+
784
+ 1. Create branch from `main`: `git checkout -b feat/<descriptive-name>`
785
+ 2. One commit per feature with descriptive messages
786
+ 3. If the reviewer modified files, create an additional commit: `fix: resolve CI issues (reviewer)`
787
+ 4. Push with `-u` flag: `git push -u origin <branch-name>`
788
+ 5. Create PR (if GitHub CLI is available):
789
+ ```bash
790
+ {{PR_CREATE_CMD}}
791
+ ```
792
+ If `gh` is not authenticated, print a compare URL for manual PR creation.
793
+
794
+ #### If `GIT_AUTO=false` (manual shipping)
795
+
796
+ Do NOT create branches, commits, or push. Instead display a summary:
797
+
798
+ ```
799
+ ## Changes Ready for Review
800
+
801
+ All implementation is complete and CI checks pass.
802
+
803
+ ### Files Changed
804
+ - [list all modified/created files per feature]
805
+
806
+ ### Suggested Next Steps
807
+ 1. Review the changes: `git diff`
808
+ 2. Create a branch: `git checkout -b feat/<name>`
809
+ 3. Stage and commit: `git add <files> && git commit -m "feat: ..."`
810
+ 4. Push and create PR manually
811
+ ```
812
+
813
+ #### Backlog updates (both modes)
814
+
815
+ **If `BACKLOG_WRITE=true`:**
816
+ - For fully resolved issues/tickets: add a comment noting completion and reference the PR. Do NOT close the issue explicitly — use `Closes #N` in the PR body so GitHub/JIRA closes it automatically when the PR is merged:
817
+ ```bash
818
+ {{BACKLOG_COMMENT_CMD}}
819
+ ```
820
+ - GitHub: `gh issue comment {number} --body "Implemented in PR #XX. All acceptance criteria met."`
821
+ - JIRA: `jira issue comment {key} --message "Implemented in PR #XX. All acceptance criteria met."`
822
+ - Ensure the PR body includes `Closes #N` for each fully resolved issue (GitHub auto-closes on merge)
823
+ - For partially resolved issues/tickets: add a comment noting progress:
824
+ ```bash
825
+ {{BACKLOG_PARTIAL_COMMENT_CMD}}
826
+ ```
827
+
828
+ **If `BACKLOG_WRITE=false`:**
829
+ - Do NOT create, modify, or comment on any issues/tickets.
830
+ - Instead, display what the user should update manually:
831
+ ```
832
+ ## Backlog Updates (manual)
833
+
834
+ The following tickets should be updated:
835
+ | Ticket | Status | Suggested Action |
836
+ |--------|--------|-----------------|
837
+ | #85 / PROJ-85 | Fully implemented | Close / move to Done |
838
+ | #71 / PROJ-71 | Partial progress | Comment: "X completed, Y remaining" |
839
+ ```
840
+
841
+ ### 4d. Monitor CI
842
+
843
+ **Only if `GIT_AUTO=true` and code was pushed.**
844
+
845
+ Check CI status after pushing. Fix failures (up to 2 retries).
846
+
847
+ If `GIT_AUTO=false`: skip — the user will push and monitor CI themselves.
848
+
849
+ ### 4e. Report
850
+
851
+ **If `DRY_RUN=true`**, show this report instead of the standard pipeline table:
852
+
853
+ ---
854
+
855
+ ## Dry-Run Preview Report
856
+
857
+ ### Artifacts Generated
858
+
859
+ | Type | Location |
860
+ |------|----------|
861
+ | OpenSpec proposal | openspec/changes/\<name\>/proposal.md |
862
+ | OpenSpec design | openspec/changes/\<name\>/design.md |
863
+ | OpenSpec tasks | openspec/changes/\<name\>/tasks.md |
864
+ | OpenSpec context-bundle | openspec/changes/\<name\>/context-bundle.md |
865
+ | Developer files | .claude/.dry-run/\<name\>/ (N files) |
866
+
867
+ ### What Would Change
868
+
869
+ [For each file in `.cache-manifest.json` `files` array:]
870
+ - `<real_path>` — [new file / modified] ([approximate line delta if available])
871
+
872
+ ### Confidence
873
+
874
+ | | |
875
+ |-|--|
876
+ | Score file | `openspec/changes/<name>/confidence-score.json` |
877
+ | Gate result | `<CONFIDENCE_STATUS>` (PASS / WARN / BLOCKED / OVERRIDE / MISSING / DISABLED) |
878
+ | Overall score | `<overall score from confidence-score.json, or N/A if MISSING/DISABLED>` |
879
+
880
+ ### Operations Skipped
881
+
882
+ [List items from `.cache-manifest.json` `skipped_operations` array]
883
+
884
+ ### Next Steps
885
+
886
+ To apply these changes and ship:
887
+ ```
888
+ /sr:implement --apply <feature-name>
889
+ ```
890
+
891
+ To discard this dry run:
892
+ ```
893
+ rm -rf .claude/.dry-run/<feature-name>/
894
+ ```
895
+
896
+ ---
897
+
898
+ **Otherwise**, show the standard pipeline table:
899
+
900
+ ```
901
+ | Area | Feature | Change Name | Architect | Developer | Tests | Docs | Reviewer | Frontend | Backend | Confidence | Security | CI | Conflicts | Status |
902
+ |------|---------|-------------|-----------|-----------|-------|------|----------|----------|---------|------------|----------|----|-----------|--------|
903
+ ```
904
+
905
+ Confidence column values:
906
+
907
+ | Value | Meaning |
908
+ |-------|---------|
909
+ | `PASS (82)` | All scores met thresholds; overall score shown in parens |
910
+ | `WARN (62)` | Scores below threshold but `on_breach=warn`; overall score in parens |
911
+ | `BLOCKED (62)` | Gate blocked the pipeline; overall score in parens |
912
+ | `OVERRIDE (62)` | Gate bypassed by `--confidence-override`; overall score in parens |
913
+ | `MISSING` | `confidence-score.json` not found after reviewer completed |
914
+ | `DISABLED` | Gate disabled via `enabled: false` in config |
915
+
916
+ If `CONFIDENCE_OVERRIDE_REASON` is non-empty, append a `### Confidence Override` section below the table:
917
+
918
+ ```
919
+ ### Confidence Override
920
+
921
+ **Reason:** <CONFIDENCE_OVERRIDE_REASON>
922
+ ```
923
+
924
+ Column values:
925
+ - **Frontend**: `CLEAN`, `ISSUES`, or `SKIPPED` (no frontend files in changeset)
926
+ - **Backend**: `CLEAN`, `ISSUES`, or `SKIPPED` (no backend files in changeset)
927
+ - **Security**: `CLEAN`, `WARNINGS`, `BLOCKED`, or `SKIPPED`
928
+
929
+ The `Conflicts` column values:
930
+ - `skipped` — `SNAPSHOTS_CAPTURED=false` (non-issue input or GH unavailable)
931
+ - `clean` — both conflict checks ran and found no changes
932
+ - `overridden (N)` — user chose Continue at one or both gates; N is the total number of conflict records in `CONFLICT_OVERRIDES`
933
+
934
+ If `MERGE_REPORT.requires_resolution` is non-empty, print an additional section:
935
+
936
+ ```
937
+ ### Merge Conflicts Requiring Resolution
938
+
939
+ | File | Features | Conflicting Region |
940
+ |------|----------|-------------------|
941
+ | <file> | <feature-a>, <feature-b> | <section heading or hunk description> |
942
+
943
+ Fix these conflicts (search for `<<<<<<<` in each file), then commit the resolved files.
944
+ ```
945
+
946
+ If `CONFLICT_OVERRIDES` is non-empty, print:
947
+
948
+ ```
949
+ ## Conflict Overrides
950
+
951
+ The following backlog conflicts were detected but overridden by the user:
952
+
953
+ | Phase | Issue | Field | Severity | Was | Now |
954
+ |-------|-------|-------|----------|-----|-----|
955
+ | 3a.0 | #42 | state | CRITICAL | open | closed |
956
+ ```
957
+
958
+ If `CONFLICT_OVERRIDES` is empty or `SNAPSHOTS_CAPTURED=false`: omit the `## Conflict Overrides` section entirely. Do not print an empty table or a "No conflict overrides" line.
959
+
960
+ Include the shipping mode in the report:
961
+ - If automatic: show PR URL, CI status, backlog updates made
962
+ - If manual: show summary of changes, suggested git commands, backlog updates pending
963
+
964
+ ---
965
+
966
+ ## Error Handling
967
+
968
+ - If a sr-product-manager fails: skip that area, continue with others
969
+ - If a sr-architect fails: skip that area, report the failure
970
+ - If a sr-developer fails: report which phase it failed at
971
+ - If the sr-reviewer finds unfixable issues: report them, push what works
972
+ - Never block the entire pipeline on a single agent failure. Always produce a final report.