specrails-core 5.0.0 → 5.1.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 (48) hide show
  1. package/README.md +103 -310
  2. package/bin/specrails-core.mjs +3 -1
  3. package/dist/installer/cli.js +4 -0
  4. package/dist/installer/cli.js.map +1 -1
  5. package/dist/installer/commands/framework.js +64 -49
  6. package/dist/installer/commands/framework.js.map +1 -1
  7. package/dist/installer/commands/init.js +102 -66
  8. package/dist/installer/commands/init.js.map +1 -1
  9. package/dist/installer/commands/update.js +80 -74
  10. package/dist/installer/commands/update.js.map +1 -1
  11. package/dist/installer/commands/v5-migration.js +14 -0
  12. package/dist/installer/commands/v5-migration.js.map +1 -1
  13. package/dist/installer/phases/framework-lifecycle.js +2 -0
  14. package/dist/installer/phases/framework-lifecycle.js.map +1 -1
  15. package/dist/installer/phases/scaffold.js +191 -258
  16. package/dist/installer/phases/scaffold.js.map +1 -1
  17. package/dist/installer/runtime/pipeline-state.js +801 -0
  18. package/dist/installer/runtime/pipeline-state.js.map +1 -0
  19. package/dist/installer/util/exec.js +6 -1
  20. package/dist/installer/util/exec.js.map +1 -1
  21. package/dist/installer/util/fs.js +11 -2
  22. package/dist/installer/util/fs.js.map +1 -1
  23. package/dist/installer/util/install-transaction.js +246 -0
  24. package/dist/installer/util/install-transaction.js.map +1 -0
  25. package/dist/installer/util/registry.js +20 -0
  26. package/dist/installer/util/registry.js.map +1 -1
  27. package/docs/ci-cd.md +57 -0
  28. package/docs/user-docs/codex-vs-claude-code.md +23 -151
  29. package/docs/user-docs/core-updates.md +70 -0
  30. package/docs/user-docs/provider-pipelines.md +53 -0
  31. package/integration-contract.json +179 -66
  32. package/package.json +5 -2
  33. package/templates/agents/sr-developer.md +9 -11
  34. package/templates/agents/sr-reviewer.md +26 -33
  35. package/templates/codex-skills/batch-implement/SKILL.md +58 -244
  36. package/templates/codex-skills/implement/SKILL.md +136 -338
  37. package/templates/codex-skills/rails/sr-architect/SKILL.md +7 -0
  38. package/templates/codex-skills/rails/sr-developer/SKILL.md +13 -0
  39. package/templates/codex-skills/rails/sr-reviewer/SKILL.md +39 -5
  40. package/templates/codex-skills/retry/SKILL.md +37 -117
  41. package/templates/commands/specrails/batch-implement.md +16 -288
  42. package/templates/commands/specrails/implement.md +62 -1057
  43. package/templates/commands/specrails/retry.md +22 -314
  44. package/templates/gemini-commands/batch-implement.toml +28 -40
  45. package/templates/gemini-commands/implement.toml +55 -114
  46. package/templates/gemini-commands/retry.toml +21 -0
  47. package/templates/kimi/specrails/run-skill.mjs +51 -2
  48. package/templates/runtime/provider-pipeline.md +55 -0
@@ -1,343 +1,141 @@
1
1
  ---
2
2
  name: implement
3
- description: "Implement a single backlog ticket through a multi-phase pipeline: architect plans (OpenSpec proposal+design+tasks+specs), sr-developer codes in TDD order, sr-reviewer validates (correctness, tests, security, performance). A profile may add custom-* rails. Reads .specrails/local-tickets.json, closes the ticket in place, reports concisely. Use when the user invokes `$implement #N` or `$implement <free-form>`."
3
+ description: "Implement one frozen spec or route multiple specs to an aggregate pipeline, with resumable design, implementation, verification, review, archive and ownership-aware delivery."
4
4
  license: MIT
5
- compatibility: "Codex-native. Uses spawn_agent / send_message / wait_agent (full-history forks, no agent_type / model / reasoning_effort). Per-role instructions live in the rail skills; this orchestrator only routes."
5
+ compatibility: "Codex-native role delegation with explicit handoffs and the installed SpecRails pipeline runtime. Use only capabilities exposed by the host."
6
6
  ---
7
7
 
8
- You are the **implement orchestrator**. The user invoked you as a
9
- multi-agent pipeline. Your job is to load the ticket, delegate to
10
- the rail skills available in this project, aggregate their
11
- verdicts, and close the ticket. The role instructions live in
12
- their own skills — your message to each spawn invokes the right
13
- role via `$skill_name`.
14
-
15
- **Repository location.** Your working directory may NOT be the source repo.
16
- `openspec/**`, `.git`, and the source live under `${SPECRAILS_REPO_DIR:-.}`
17
- (unset ⇒ `.` ⇒ classic in-repo run). Run every `openspec`/`git` CLI command
18
- from the repo — `(cd "${SPECRAILS_REPO_DIR:-.}" && …)` — and read change
19
- artefacts under `${SPECRAILS_REPO_DIR:-.}/openspec/...`. The ticket store
20
- `.specrails/local-tickets.json` is run-state and stays relative to the working
21
- directory.
22
-
23
- **This is explicit permission to use `spawn_agent`.** The user
24
- wants the multi-agent split. Do not collapse the work into a
25
- single turn.
26
-
27
- **Each phase MUST be a real `spawn_agent` call.** You are
28
- *forbidden* from "doing the developer phase inline to save
29
- time" or "running the architect work directly because the
30
- ticket looks small". Every phase below is a hard requirement
31
- to spawn the named role skill via `spawn_agent` +
32
- `send_message`. If your final report says "local
33
- implementation" or "did this myself" anywhere, you violated
34
- this contract.
35
-
36
- The only reason a phase can be skipped is the BLOCKED reply
37
- path documented per phase (architect / developer can return
38
- `BLOCKED: …` and you stop). Otherwise: spawn, wait, close,
39
- move on.
40
-
41
- **A `clean` run is NOT finished until the change is archived.**
42
- Archiving (`openspec archive`) is a hard obligation, not an
43
- optional epilogue — see Phase 4. If you mark a ticket `done`
44
- without an archived change under `openspec/changes/archive/`,
45
- you violated this contract.
46
-
47
- ## How the user invokes you
48
-
49
- - `$implement #N` — implement ticket `N` from
50
- `.specrails/local-tickets.json`.
51
- - `$implement #N --yes` — non-interactive (skip confirmations).
52
- - `$implement <free-form>` — implement a free-form description
53
- (no ticket id; skip the ticket-update step at the end).
54
-
55
- ### Single-ticket only
56
-
57
- You handle **exactly one** ticket per invocation. If the user
58
- passes more than one `#N` (e.g. `$implement #5 #6 --yes`), do
59
- NOT improvise a multi-ticket flow — reply with:
60
-
61
- `"$implement runs one ticket at a time. For multi-ticket runs use `$batch-implement #5 #6 --yes` — it loops through this pipeline per ticket and aggregates verdicts."`
62
-
63
- and end. Routing multi-ticket invocations through
64
- `$batch-implement` keeps file-mutation conflicts impossible
65
- and gives you a single aggregated report.
66
-
67
- ## Pipeline (logical phases)
68
-
69
- ```
70
- YOU (orchestrator)
71
- │
72
- ├─► PHASE 1: $sr-architect
73
- │ produces openspec/changes/<slug>/{proposal,design,tasks,specs}
74
- │
75
- ├─► PHASE 2: $sr-developer
76
- │ implements every task (tests + docs included per task)
77
- │
78
- ├─► PHASE 3: $sr-reviewer
79
- │ single reviewer — correctness, TDD/spec, security, performance
80
- │
81
- └─► PHASE 4: close ticket + report
82
- ```
83
-
84
- All spawns are **full-history forks**. NEVER pass `agent_type`,
85
- `model`, or `reasoning_effort` to `spawn_agent` — codex rejects
86
- the combo and you'll burn a turn on the retry.
87
-
88
- ## Steps (in order)
89
-
90
- ### 0. Bootstrap + agent discovery
91
-
92
- 1. Confirm the repo root with `git -C "${SPECRAILS_REPO_DIR:-.}" rev-parse --show-toplevel`
93
- (the source repo is `${SPECRAILS_REPO_DIR:-.}`; unset ⇒ `.`).
94
- 2. Load the ticket (skip for free-form invocations) — the ticket store is
95
- run-state, relative to the working directory:
96
- `jq '.tickets["<ID>"]' .specrails/local-tickets.json`
97
- 3. **List the installed rail skills**:
98
- `ls .codex/skills/rails/`
99
- The three core rails (`sr-architect`, `sr-developer`,
100
- `sr-reviewer`) are always present and are the only first-party
101
- rails. A profile may add user-owned `custom-*` rails; spawn a
102
- `custom-*` rail only when it is listed.
103
- 4. State (≤4 lines) the ticket goal and the stack you detected from
104
- a quick `ls`/`find`. Do NOT plan files-to-touch — that's the
105
- architect's job.
106
-
107
- ### 1. Phase 1 — Architect
108
-
109
- - `spawn_agent` (full-history, no agent_type / model /
110
- reasoning_effort).
111
- - `send_message` body (substitute `<TICKET_ID>` and
112
- `<TICKET_TITLE>`):
113
-
114
- > `$sr-architect`
115
- >
116
- > Ticket id: `<TICKET_ID>`
117
- > Ticket title: `<TICKET_TITLE>`
118
- >
119
- > Read `jq '.tickets["<TICKET_ID>"]' .specrails/local-tickets.json`
120
- > for the full ticket. Follow the `$sr-architect` skill
121
- > instructions exactly.
122
- >
123
- > Reply with the one-line summary the skill specifies.
124
-
125
- - `wait_agent`. Read the reply. Extract the plan path.
126
- - `close_agent`. Open the plan file + design.md.
127
-
128
- If the architect replied with `BLOCKED: …`, stop the pipeline,
129
- write that reason into the final report, and exit without
130
- updating the ticket.
131
-
132
- **Design confidence gate.** Read
133
- `${SPECRAILS_REPO_DIR:-.}/openspec/changes/<slug>/design-confidence.json`
134
- (the architect writes it as part of its skill). File missing →
135
- warn and proceed (backward compatible). `high`/`medium` →
136
- proceed. `low` → **STOP before Phase 2** — implementation is the
137
- expensive phase and must not run on an unconfident design.
138
- Report:
139
-
140
- > `BLOCKED: design confidence low — <blocking_question>`
141
- >
142
- > Answer the question (edit the ticket description), then re-run
143
- > `$implement #N`. The OpenSpec artifacts are left in place as a
144
- > resumable starting point.
145
-
146
- Do NOT update the ticket, do NOT spawn the developer.
147
-
148
- ### 2. Phase 2 — Developer
149
-
150
- There is one developer rail. Unless an active profile routes the
151
- ticket to a `custom-*` developer that is listed in step 0.3, spawn
152
- `$sr-developer`.
153
-
154
- - `spawn_agent` (full-history).
155
- - `send_message`:
156
-
157
- > `$sr-developer`
158
- >
159
- > Ticket id: `<TICKET_ID>`
160
- > Plan: `<PLAN_PATH>`
161
- >
162
- > Follow the `$sr-developer` skill instructions exactly.
163
-
164
- - `wait_agent`. Capture file list. `close_agent`.
165
-
166
- If the developer returned `BLOCKED: …`, surface it to the user
167
- in the final report (no review phase, no ticket update).
168
-
169
- ### 3. Phase 3 — Reviewer
170
-
171
- Spawn the single `$sr-reviewer`. It owns every review dimension —
172
- correctness, TDD/spec completeness, code quality, security, and
173
- performance — scaled to what the change touches.
174
-
175
- - `spawn_agent` (full-history).
176
- - `send_message`:
177
-
178
- > `$sr-reviewer`
179
- >
180
- > Ticket id: `<TICKET_ID>`
181
- > Plan: `<PLAN_PATH>`
182
- > Changed files:
183
- > <one per line>
184
- >
185
- > Follow the `$sr-reviewer` skill instructions exactly.
186
-
187
- - `wait_agent`. `close_agent`.
188
-
189
- **Verdict** — parse `Score: N/100` and `Verdict: …` from the reply:
190
-
191
- - `clean` — score ≥ 70 AND not fix/blocked.
192
- - `fix needed` — verdict `fix needed: …`, OR score < 70 with no
193
- `blocked: …`, OR `blocked: …` with score **in the recoverable
194
- range 30-69** (a single developer fix pass can usually clear it).
195
- - `blocked` — `blocked: …` with score **< 30**. Design-level; a
196
- developer pass won't help — the architect needs to re-engage.
197
-
198
- ### 4. Optional fix loop (single pass only)
199
-
200
- If phase 3's verdict is `fix needed`:
201
-
202
- - Spawn ONE follow-up developer (`$sr-developer`, or the same
203
- `custom-*` developer used in phase 2) with a message that
204
- includes the reviewer's `issues[]` array from its confidence
205
- artefact.
206
- - `wait_agent`. `close_agent`.
207
- - Re-run phase 3. If still `fix needed` or `blocked`, **do not loop
208
- again** — surface in the final report.
209
-
210
- ### 5. Phase 4 — Archive FIRST, then close + report
211
-
212
- > **INVARIANT.** A ticket may be marked `done` ONLY if its change is
213
- > archived (`openspec/changes/archive/<slug>/` exists). A `clean`
214
- > verdict with an unarchived change is `todo` + `fix needed`, never
215
- > `done`. Archiving the change and closing the ticket are a single
216
- > atomic obligation — you cannot satisfy one and skip the other.
217
-
218
- **Step A — Archive the OpenSpec change through `$sr-reviewer`
219
- (mandatory when the verdict is `clean`). Run this BEFORE touching the
220
- ticket or writing the report.** A change is not done until it is
221
- archived — this is the codex equivalent of `opsx:archive`, and it MUST
222
- run. When the overall verdict is `clean`, delegate the final OpenSpec
223
- close to the reviewer rail so the same agent that validated the change
224
- performs the lifecycle close:
225
-
226
- 1. Spawn `$sr-reviewer` one final time (full-history fork).
227
- 2. Send this exact close prompt:
228
-
229
- > `$sr-reviewer`
230
- >
231
- > ARCHIVE_ONLY=true
232
- > ARCHIVE_AUTHORIZED=true
233
- > Ticket id: `<TICKET_ID>`
234
- > Plan: `<PLAN_PATH>`
235
- > Change slug: `<slug>`
236
- >
237
- > The aggregated reviewer verdict is clean. Follow the
238
- > `$sr-reviewer` archive-only instructions exactly: validate the
239
- > OpenSpec change, confirm every task is checked, perform the
240
- > OpenSpec archive command, and verify the archive landed.
241
-
242
- 3. `wait_agent`, parse the two-line `Score:` / `Verdict:` reply, and
243
- `close_agent`.
244
- 4. Treat any non-clean archive reply as archive failure.
245
-
246
- The reviewer rail's archive-only mode must run these checks:
247
-
248
- 1. Re-confirm every task box in `${SPECRAILS_REPO_DIR:-.}/openspec/changes/<slug>/tasks.md`
249
- is ticked (`- [x]`) and the change validates:
250
- `(cd "${SPECRAILS_REPO_DIR:-.}" && openspec validate "<slug>" --strict)`.
251
- 2. Archive it: `(cd "${SPECRAILS_REPO_DIR:-.}" && openspec archive "<slug>" -y)` — this updates the
252
- main specs and moves the change to `${SPECRAILS_REPO_DIR:-.}/openspec/changes/archive/`.
253
- 3. **Verify the archive landed — do NOT assume success.** Confirm
254
- `${SPECRAILS_REPO_DIR:-.}/openspec/changes/archive/` now contains the slug
255
- (`ls -d "${SPECRAILS_REPO_DIR:-.}"/openspec/changes/archive/*<slug>* 2>/dev/null`) AND that
256
- `${SPECRAILS_REPO_DIR:-.}/openspec/changes/<slug>/` is gone. If the archive directory is
257
- absent, archiving FAILED.
258
- 4. If `openspec validate`, `openspec archive`, or the step-3
259
- verification fails: do NOT mark the ticket `done`. Treat the run
260
- as `fix needed`, surface the error in the final report, set the
261
- report's `Archive:` line to `FAILED`, and leave the ticket
262
- `todo`.
263
-
264
- Skip archiving only when the verdict is `fix needed` or `blocked` —
265
- an unsound change must never be archived. In that case set the
266
- report's `Archive:` line to `skipped (<verdict>)`.
267
-
268
- **Step B — Close the ticket + report.** If a ticket id is in play:
269
-
270
- - Update `.specrails/local-tickets.json`. Modify only:
271
- - `tickets["<ID>"].status` → `"done"` (clean) or `"todo"`
272
- (fix needed / blocked)
273
- - `tickets["<ID>"].updated_at` → `date -Iseconds`
274
- - top-level `revision` → `revision + 1`
275
- - PRESERVE every other field.
276
-
277
- Print the final summary (≤18 lines):
278
-
279
- ```
280
- #<N> → done|todo
281
- Pipeline: architect → <developer skill(s)> → <reviewer skill(s)>
282
- Plan: <path>
283
- Confidence: <best path> (overall <score>/100)
284
- Archive: archived → openspec/changes/archive/<slug> | skipped (<verdict>) | FAILED
285
- Files: <one path per line, capped at 12; truncate beyond>
286
- Tests: <ran command, pass/fail>
287
- Build: <ran command, ok/fail/n/a>
288
- Follow-up: <one bullet per item>
289
- ```
290
-
291
- ## While a sub-agent is running: WAIT, do nothing else
292
-
293
- After `spawn_agent` + `send_message`, the only tool you should
294
- call is `wait_agent`. Do **not**:
295
-
296
- - Read files (`sed`, `cat`, `head`, `tail`) for "context to
297
- prepare the next phase"
298
- - Run `find`, `git status`, `git diff`, `npm test`, `ls`, or
299
- any other inspection during the wait
300
- - Spawn additional sub-agents speculatively
301
- - Try to "save time" by overlapping work
302
-
303
- Why:
304
-
305
- - The sub-agent is editing files; concurrent reads race with
306
- its writes and can return half-written content that
307
- poisons your next decision.
308
- - Each `sed`/`find`/`grep` you run costs tokens. A
309
- 10-minute developer phase with you reading the codebase
310
- every 30s adds up to a real cost increase for no benefit.
311
- - The next phase's brief is **deterministic** — it only
312
- needs the sub-agent's reply. You don't need to pre-scout.
313
-
314
- If `wait_agent` returns before the sub-agent is done (e.g.
315
- timeout on your side), wait again. Do not start
316
- inspecting.
317
-
318
- The only acceptable activity during the wait is your own
319
- narration — a single short line explaining what you're
320
- waiting for is fine for the user, but do not chain more
321
- than one such line per wait.
322
-
323
- ## What you must NOT do
324
-
325
- - **Do NOT handle multi-ticket invocations.** Route them to
326
- `$batch-implement` (see "Single-ticket only" above).
327
- - **Do NOT pass `agent_type`, `model`, or `reasoning_effort`** to
328
- `spawn_agent` on full-history forks.
329
- - **Do NOT inline role instructions** in your messages — each
330
- rail skill is the source of truth for what its role does.
331
- Your message points the sub-agent at the right skill and
332
- passes parameters; the skill body teaches the role.
333
- - **Do NOT spawn rails that aren't installed** in
334
- `.codex/skills/rails/`. The user's wizard selection determines
335
- what's available; respect it.
336
- - **Do NOT skip phases**. Even on trivial tickets, run
337
- architect → developer → at-least-one reviewer. A trivial run
338
- is still trazabilidad.
339
- - **Do NOT loop the fix-review more than once**.
340
- - **Do NOT touch `.claude/agent-memory/`** — codex projects use
341
- `.specrails/agent-memory/`.
342
- - **Do NOT update `.specrails/local-tickets.json`** from inside
343
- a sub-agent. Only you (the orchestrator) write that file.
8
+ You coordinate the implementation. Role skills supply design, coding and review
9
+ instructions; the installed runtime supplies immutable scope, phase status and
10
+ actual verification evidence. A completed valid phase needs no new model call.
11
+
12
+ **Input:** `$implement #N`, `$implement #N --yes`, a free-form description, or
13
+ multiple `#N` references. More than one ID routes directly to
14
+ `.codex/skills/batch-implement/SKILL.md` with the original arguments and complete
15
+ frozen context. Do not ask the user to resend or spawn a nested implement.
16
+
17
+ ## Admission and capabilities
18
+
19
+ Follow the executable pipeline contract above. Initialize the one stable change
20
+ with supplied context, explicit ticket IDs, or a free-form scope request; then
21
+ read `status`. Do not initialize another run on retry or replace frozen requirements
22
+ with live ticket text. OpenSpec lives under `context.artifactRoot`; the compatibility
23
+ path `${SPECRAILS_REPO_DIR:-.}/openspec/changes/<slug>/` applies only after resolving
24
+ that variable to artifactRoot. Source/tests use the selected repository ID/path;
25
+ backlog uses `context.backlogPath`, independent of cwd.
26
+
27
+ Discover `.codex/skills/rails/` and require sr-architect, sr-developer and
28
+ sr-reviewer. Validate any explicit profile (`SPECRAILS_PROFILE_PATH`, otherwise the
29
+ project's configured default): schemaVersion 1, baseline trio, routing/default and
30
+ referenced installed roles. Only installed custom-* roles may supplement or fulfill
31
+ a routed task group; they do not bypass the canonical phase gates.
32
+
33
+ Use the host's actual `spawn_agent`, `send_message` and `wait_agent` signatures.
34
+ Invoke required architect/developer/reviewer roles as real workers and collect their
35
+ terminal outcomes. Full-history forks inherit the current model; do not pass model
36
+ or reasoning overrides unsupported by that fork mode. Report unsupported profile
37
+ model overrides honestly. Use `close_agent` only when that capability exists and
38
+ only after the worker finished; never invent a cleanup tool or interrupt running
39
+ work to simulate completion. Avoid parallel writers in shared candidate roots.
40
+
41
+ Every worker receives its `$sr-*` skill and the explicit bounded handoff: runId,
42
+ phase, absolute runtime/context paths, all frozen criteria, repository ownership,
43
+ change/plan/tasks paths, prior outcome and next action. Do not rely on inherited
44
+ conversation memory. A task start, turn limit or process exit alone is not success.
45
+ Continue from durable progress; two continuations without progress become blocked.
46
+
47
+ ## Durable phases
48
+
49
+ `architect → developer → reviewer → archive → ship → ci`
50
+
51
+ Follow `status.resumePhase`. Start required work with the helper's
52
+ `phase --phase <phase> --status running`. Record done only after validating actual
53
+ outcomes and runtime gates. Record blocked/failed with a concrete reason; dependent
54
+ phases remain incomplete. Reopening a phase invalidates dependent completion.
55
+ If every phase is valid, report existing completion without new worker calls.
56
+
57
+ ### Architect
58
+
59
+ Invoke `$sr-architect` with the exact slug and aggregate frozen scope. Use the
60
+ installed official OpenSpec fast-forward workflow. Require proposal, design, specs,
61
+ tasks and medium/high design-confidence.json. Missing/malformed/low confidence
62
+ blocks development; record the unresolved issue and retain artifacts for retry.
63
+ Do not edit a ticket and silently substitute the new description into this run.
64
+ Changed requirements need a newly admitted scope.
65
+
66
+ ### Developer
67
+
68
+ Invoke `$sr-developer` or the validated profile role for each task group. Keep
69
+ source writes in its selected repositories, serialize dependencies/shared files,
70
+ and persist real task progress. A BLOCKED outcome stops downstream phases.
71
+ Scoped checks support development; once all groups are implemented, execute one
72
+ full CI-equivalent check request through the installed helper. Derive actual checks
73
+ from each selected repository and include required cross-repository integration.
74
+ All tasks and current full evidence must pass before recording developer done.
75
+
76
+ ### Reviewer and bounded repair
77
+
78
+ Invoke `$sr-reviewer` with complete criteria, candidate inventory and current
79
+ verification receipt. Ordinary review does not archive. Require explicit semantic
80
+ acceptance, safe behavior and required regression coverage; green baseline tests
81
+ with missing implementation are incomplete. Reuse unchanged full verification;
82
+ review edits require one fresh final full request on the resulting candidate.
83
+
84
+ Read canonical `<context.artifactRoot>/openspec/changes/<slug>/confidence-score.json`.
85
+ Require overall ≥70, security ≥75 and every other aspect ≥60 (or stricter configured
86
+ thresholds), all tasks complete and no unresolved explicit blocker. Missing or
87
+ ambiguous verdicts/scores fail closed. A numeric score never converts a blocked
88
+ security or design finding into clean acceptance.
89
+
90
+ For concrete recoverable findings, reopen developer and invoke it once with those
91
+ exact findings, then re-review and refresh evidence. An architectural blocker
92
+ returns to architect; do not infer its category from a score range. If the one
93
+ repair round does not resolve acceptance, preserve work and record blocked.
94
+ Only then may the runtime record reviewer done.
95
+
96
+ ### Archive
97
+
98
+ Run `archive-check` immediately before archiving. Nonzero means stop. After success,
99
+ invoke `$sr-reviewer` with ARCHIVE_ONLY=true and ARCHIVE_AUTHORIZED=true and the
100
+ same explicit handoff, or run the installed official archive workflow directly
101
+ as coordinator. Preserve approved confidence bytes; no rescoring or code changes.
102
+ Confirm the exact active change is gone, its archive exists under
103
+ `<context.artifactRoot>/openspec/changes/archive/<date>-<slug>/` and canonical specs
104
+ synced before `phase --phase archive --status done`. Do not emulate an official
105
+ archive with file moves or accept incomplete-task prompts. A failed archive remains
106
+ resumable; it never closes specs or restarts valid development automatically.
107
+
108
+ ### Delivery and CI
109
+
110
+ For `context.ownership.git === "host"`, record ship and ci skipped with the ownership
111
+ reason and return evidence to the host. Do not stage, commit, push or open PRs.
112
+ For Core-owned git, perform only the delivery already authorized by user/settings,
113
+ in each selected repository. `GIT_AUTO=false` and preview disable shipping even if
114
+ Core owns git. Preserve unrelated changes; stage only the reviewed candidate.
115
+ Record actual per-repository commits/PRs and required CI results before phase done.
116
+ Partial delivery stays incomplete. CI retry checks existing delivery, without
117
+ creating duplicate commits or PRs. No authorized delivery means a concrete blocker,
118
+ not a fabricated successful ship phase.
119
+
120
+ ### Backlog and report
121
+
122
+ Host-owned backlog remains untouched. Core-owned backlog may close only after all
123
+ required delivery succeeds, current evidence remains valid, and live participating
124
+ ticket requirements still match frozen IDs/descriptions/criteria/repository scope.
125
+ A mismatch leaves that ticket open and reports the conflict. Read/write only
126
+ `context.backlogPath` (fallback context.backlogRoot/.specrails/local-tickets.json),
127
+ preserve unrelated tickets/fields, and apply the store's revision protocol. Workers
128
+ never close tickets. A free-form scope without a real ticket has no ticket mutation.
129
+
130
+ Report run/change, frozen tickets/roots, reused and newly completed phases,
131
+ verification commands, confidence, archive and each repository's actual delivery.
132
+ Distinguish ready-for-host-delivery from delivered. Include concrete remaining
133
+ blockers; no complete/done claim while a required gate or repository is incomplete.
134
+
135
+ ## Preview and apply
136
+
137
+ `--dry-run`/`--preview` uses the runtime preview contract and reports UNVERIFIED
138
+ PREVIEW. Tests on untouched source are baseline evidence only. `--apply` resumes the
139
+ exact existing preview journal, verifies unchanged base/cache and runs checks on
140
+ actual applied source through `apply-preview`; continue the ordinary review,
141
+ confidence and archive gates. Preview never grants shipping/backlog ownership.
@@ -5,6 +5,13 @@ license: MIT
5
5
  compatibility: "Codex-native. Designed to run as a full-history sub-agent fork of the implement orchestrator."
6
6
  ---
7
7
 
8
+ **Execution scope.** The orchestrator's explicit frozen handoff or execution-context
9
+ file is authoritative. Use all selected repository IDs/paths for source work and
10
+ `context.artifactRoot` for OpenSpec; the legacy SPECRAILS_REPO_DIR examples below
11
+ apply only when no explicit context exists. Preserve the aggregate change slug for
12
+ a batch. Do not reload mutable tickets to replace frozen descriptions. Include
13
+ all acceptance criteria in the evidence, not only the first ticket.
14
+
8
15
  **Deterministic repo map.** If `SPECRAILS_REPO_MAP_PATH` is set
9
16
  and readable, read that file FIRST — a zero-AI map of the repo
10
17
  (packages, ecosystems, sizes) generated by the spawner. Use it to
@@ -5,6 +5,13 @@ license: MIT
5
5
  compatibility: "Codex-native. Designed to run as a full-history sub-agent fork of the implement orchestrator."
6
6
  ---
7
7
 
8
+ **Execution scope.** The orchestrator's explicit frozen handoff or execution-context
9
+ file is authoritative. Use all selected repository IDs/paths for source work and
10
+ `context.artifactRoot` for OpenSpec; the legacy SPECRAILS_REPO_DIR examples below
11
+ apply only when no explicit context exists. Preserve the aggregate change slug for
12
+ a batch. Do not reload mutable tickets to replace frozen descriptions. Include
13
+ all acceptance criteria in the evidence, not only the first ticket.
14
+
8
15
  **Repository location.** Your working directory may NOT be the source
9
16
  repo. `openspec/**` and the source files named in `tasks.md` (repo-relative
10
17
  paths like `src/foo.ts`) live under `${SPECRAILS_REPO_DIR:-.}` — unset ⇒ `.`
@@ -123,6 +130,12 @@ note it in your reply — do not block on the architect.
123
130
 
124
131
  ## Validation gate
125
132
 
133
+ Run the gate through the installed pipeline helper `verify --request <json>` so
134
+ its actual command exits and repository fingerprints become a reusable receipt.
135
+ The request lists all required commands with repositoryId, executable, argv and
136
+ cwd; use the frozen handoff repositories. Never invent a receipt or reuse one
137
+ whose status is invalid. Save the receipt path with the developer outcome.
138
+
126
139
  The final task block in `tasks.md` is always the validation gate
127
140
  (`## N. Validation gate`). Run it:
128
141
 
@@ -5,6 +5,13 @@ license: MIT
5
5
  compatibility: "Codex-native. Designed to run as a full-history sub-agent fork of the implement orchestrator."
6
6
  ---
7
7
 
8
+ **Execution scope.** The orchestrator's explicit frozen handoff or execution-context
9
+ file is authoritative. Use all selected repository IDs/paths for source work and
10
+ `context.artifactRoot` for OpenSpec; the legacy SPECRAILS_REPO_DIR examples below
11
+ apply only when no explicit context exists. Preserve the aggregate change slug for
12
+ a batch. Do not reload mutable tickets to replace frozen descriptions. Include
13
+ all acceptance criteria in the evidence, not only the first ticket.
14
+
8
15
  You are the **reviewer** in the specrails implement pipeline. The
9
16
  architect produced an OpenSpec change package, and the developer
10
17
  implemented it. Your job is to validate the **whole** implementation
@@ -101,8 +108,8 @@ For each `## N.` task block in `tasks.md`:
101
108
 
102
109
  ### 4. Walk the ticket's acceptance criteria
103
110
 
104
- Load `.specrails/local-tickets.json`, read
105
- `tickets["<ID>"].description`. Map each acceptance criterion
111
+ Read every frozen ticket description/acceptance criterion from the handoff or
112
+ execution context; only legacy runs consult the explicitly resolved ticket store. Map each acceptance criterion
106
113
  to evidence in the changed files. Every criterion must have
107
114
  at least one of: a passing test, an observable code path, or
108
115
  a screenshot/manual-check note in the design's
@@ -136,13 +143,32 @@ re-buys information the pipeline already has. So:
136
143
 
137
144
  Path:
138
145
 
139
- `.specrails/agent-memory/explanations/YYYY-MM-DD-reviewer-ticket-{TICKET_ID}.confidence-score.json`
146
+ `<context.artifactRoot>/openspec/changes/<slug>/confidence-score.json`
147
+
148
+ This canonical report is required by the pipeline gate. An optional copy may be
149
+ kept in `.specrails/agent-memory/explanations/` for human history. Score the five
150
+ aspects independently from actual findings; never fill them mechanically from
151
+ the overall score. Keep `overall_score` as a legacy summary alias of `overall`.
140
152
 
141
153
  (today's date; create parent dir if missing). Shape:
142
154
 
143
155
  ```json
144
156
  {
157
+ "schema_version": "1",
158
+ "change": "<slug>",
159
+ "agent": "reviewer",
160
+ "scored_at": "<ISO timestamp>",
161
+ "overall": 0-100,
145
162
  "overall_score": 0-100,
163
+ "aspects": {
164
+ "type_correctness": 0-100,
165
+ "pattern_adherence": 0-100,
166
+ "test_coverage": 0-100,
167
+ "security": 0-100,
168
+ "architectural_alignment": 0-100
169
+ },
170
+ "notes": { "<aspect>": "<concrete evidence and concerns>" },
171
+ "flags": [],
146
172
  "summary": "<one paragraph>",
147
173
  "openspec_artefacts": {
148
174
  "proposal_ok": true,
@@ -195,11 +221,18 @@ Scoring guide:
195
221
 
196
222
  ### 7. Archive the OpenSpec change when authorized
197
223
 
224
+ Authorization requires a successful shared pipeline `archive-check` after the
225
+ orchestrator recorded semantic reviewer done. Ordinary review records findings
226
+ and confidence only; it never archives before that combined gate.
227
+
198
228
  Archiving is mandatory for a clean close, but only safe after the
199
229
  orchestrator has aggregated all reviewer verdicts. Therefore:
200
230
 
201
231
  - If the orchestrator prompt includes both `ARCHIVE_ONLY=true` and
202
- `ARCHIVE_AUTHORIZED=true`, skip Steps 2-5 of the code review. You are
232
+ `ARCHIVE_AUTHORIZED=true`, skip Steps 2-6 of the code review. Preserve the
233
+ canonical confidence report byte-for-byte: the gate authorizes its exact hash.
234
+ Do not rescore or rewrite archive_status; report archive outcomes through the
235
+ journal and final reply only. You are
203
236
  being invoked only to perform the final OpenSpec close. You must still
204
237
  run Step 1, confirm all tasks are checked, run `openspec archive`, and
205
238
  verify the archive landed.
@@ -234,7 +267,8 @@ OpenSpec archive failed`.
234
267
  ## What you must NOT do
235
268
 
236
269
  - **Do not** edit any source or test file.
237
- - **Do not** edit OpenSpec files by hand. The only allowed OpenSpec
270
+ - **Do not** edit OpenSpec design/tasks/specs by hand. Writing the required
271
+ canonical confidence report during ordinary review is allowed. Lifecycle
238
272
  mutation is `openspec archive "<slug>" -y` during Step 7 when
239
273
  `ARCHIVE_AUTHORIZED=true` and the verdict is clean.
240
274
  - **Do not** update `.specrails/local-tickets.json`. The