specrails-core 4.12.1 → 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 (97) hide show
  1. package/README.md +103 -339
  2. package/bin/specrails-core.mjs +20 -98
  3. package/bin/tui-installer.mjs +22 -105
  4. package/commands/doctor.md +1 -1
  5. package/dist/installer/cli.js +16 -2
  6. package/dist/installer/cli.js.map +1 -1
  7. package/dist/installer/commands/doctor.js +3 -5
  8. package/dist/installer/commands/doctor.js.map +1 -1
  9. package/dist/installer/commands/framework.js +64 -49
  10. package/dist/installer/commands/framework.js.map +1 -1
  11. package/dist/installer/commands/init.js +122 -82
  12. package/dist/installer/commands/init.js.map +1 -1
  13. package/dist/installer/commands/update.js +90 -83
  14. package/dist/installer/commands/update.js.map +1 -1
  15. package/dist/installer/commands/v5-migration.js +133 -0
  16. package/dist/installer/commands/v5-migration.js.map +1 -0
  17. package/dist/installer/phases/framework-lifecycle.js +2 -0
  18. package/dist/installer/phases/framework-lifecycle.js.map +1 -1
  19. package/dist/installer/phases/install-config.js +3 -6
  20. package/dist/installer/phases/install-config.js.map +1 -1
  21. package/dist/installer/phases/manifest.js +2 -6
  22. package/dist/installer/phases/manifest.js.map +1 -1
  23. package/dist/installer/phases/prereqs.js +0 -1
  24. package/dist/installer/phases/prereqs.js.map +1 -1
  25. package/dist/installer/phases/scaffold.js +228 -405
  26. package/dist/installer/phases/scaffold.js.map +1 -1
  27. package/dist/installer/runtime/pipeline-state.js +801 -0
  28. package/dist/installer/runtime/pipeline-state.js.map +1 -0
  29. package/dist/installer/util/install-transaction.js +246 -0
  30. package/dist/installer/util/install-transaction.js.map +1 -0
  31. package/dist/installer/util/registry.js +20 -0
  32. package/dist/installer/util/registry.js.map +1 -1
  33. package/docs/ci-cd.md +57 -0
  34. package/docs/user-docs/codex-vs-claude-code.md +23 -151
  35. package/docs/user-docs/core-updates.md +70 -0
  36. package/docs/user-docs/provider-pipelines.md +53 -0
  37. package/integration-contract.json +179 -66
  38. package/package.json +5 -2
  39. package/schemas/profile.v1.json +1 -1
  40. package/templates/agents/sr-architect.md +30 -0
  41. package/templates/agents/sr-developer.md +30 -19
  42. package/templates/agents/sr-reviewer.md +70 -64
  43. package/templates/codex-skills/batch-implement/SKILL.md +58 -267
  44. package/templates/codex-skills/implement/SKILL.md +136 -420
  45. package/templates/codex-skills/rails/sr-architect/SKILL.md +45 -20
  46. package/templates/codex-skills/rails/sr-developer/SKILL.md +42 -10
  47. package/templates/codex-skills/rails/sr-reviewer/SKILL.md +60 -15
  48. package/templates/codex-skills/retry/SKILL.md +37 -117
  49. package/templates/commands/specrails/batch-implement.md +16 -288
  50. package/templates/commands/specrails/doctor.md +1 -1
  51. package/templates/commands/specrails/implement.md +94 -1260
  52. package/templates/commands/specrails/memory-inspect.md +6 -4
  53. package/templates/commands/specrails/propose-spec.md +1 -1
  54. package/templates/commands/specrails/refactor-recommender.md +8 -51
  55. package/templates/commands/specrails/retry.md +22 -350
  56. package/templates/commands/specrails/telemetry.md +1 -1
  57. package/templates/gemini-commands/batch-implement.toml +28 -40
  58. package/templates/gemini-commands/implement.toml +55 -105
  59. package/templates/gemini-commands/retry.toml +21 -0
  60. package/templates/kimi/specrails/run-skill.mjs +51 -2
  61. package/templates/profiles/default.json +5 -18
  62. package/templates/runtime/provider-pipeline.md +55 -0
  63. package/commands/enrich.md +0 -1456
  64. package/templates/agents/sr-backend-developer.md +0 -91
  65. package/templates/agents/sr-backend-reviewer.md +0 -152
  66. package/templates/agents/sr-doc-sync.md +0 -247
  67. package/templates/agents/sr-frontend-developer.md +0 -85
  68. package/templates/agents/sr-frontend-reviewer.md +0 -145
  69. package/templates/agents/sr-merge-resolver.md +0 -195
  70. package/templates/agents/sr-performance-reviewer.md +0 -186
  71. package/templates/agents/sr-product-analyst.md +0 -36
  72. package/templates/agents/sr-product-manager.md +0 -148
  73. package/templates/agents/sr-security-reviewer.md +0 -191
  74. package/templates/agents/sr-test-writer.md +0 -176
  75. package/templates/codex-skills/enrich/SKILL.md +0 -191
  76. package/templates/codex-skills/merge-resolve/SKILL.md +0 -88
  77. package/templates/codex-skills/rails/sr-backend-developer/SKILL.md +0 -93
  78. package/templates/codex-skills/rails/sr-backend-reviewer/SKILL.md +0 -120
  79. package/templates/codex-skills/rails/sr-doc-sync/SKILL.md +0 -124
  80. package/templates/codex-skills/rails/sr-frontend-developer/SKILL.md +0 -106
  81. package/templates/codex-skills/rails/sr-frontend-reviewer/SKILL.md +0 -111
  82. package/templates/codex-skills/rails/sr-merge-resolver/SKILL.md +0 -156
  83. package/templates/codex-skills/rails/sr-performance-reviewer/SKILL.md +0 -109
  84. package/templates/codex-skills/rails/sr-product-analyst/SKILL.md +0 -85
  85. package/templates/codex-skills/rails/sr-product-manager/SKILL.md +0 -131
  86. package/templates/codex-skills/rails/sr-security-reviewer/SKILL.md +0 -121
  87. package/templates/codex-skills/rails/sr-test-writer/SKILL.md +0 -115
  88. package/templates/commands/specrails/auto-propose-backlog-specs.md +0 -312
  89. package/templates/commands/specrails/enrich.md +0 -1456
  90. package/templates/commands/specrails/get-backlog-specs.md +0 -226
  91. package/templates/commands/specrails/merge-resolve.md +0 -172
  92. package/templates/commands/specrails/reconfig.md +0 -80
  93. package/templates/commands/specrails/vpc-drift.md +0 -405
  94. package/templates/commands/test.md +0 -58
  95. package/templates/personas/persona.md +0 -43
  96. package/templates/personas/the-maintainer.md +0 -98
  97. package/templates/settings/perf-thresholds.yml +0 -25
@@ -1,425 +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), one or more developers code in TDD order, one or more reviewers validate in parallel. Routing is dynamic — the orchestrator inspects which rail skills are installed in .codex/skills/rails/ and spawns the specialists that apply to the change's scope. 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 5. 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
- │ + a "Scope" tag in design.md
75
- │
76
- ├─► PHASE 2: developer(s) — routing depends on scope
77
- │ scope=frontend → $sr-frontend-developer (if installed)
78
- │ scope=backend → $sr-backend-developer (if installed)
79
- │ scope=both → spawn BOTH in parallel (tasks.md must be
80
- │ partitioned), OR fall back to $sr-developer
81
- │ else → $sr-developer
82
- │
83
- ├─► PHASE 3: reviewer(s) — parallel where installed
84
- │ always: $sr-reviewer (baseline)
85
- │ frontend changes: $sr-frontend-reviewer (if installed)
86
- │ backend changes: $sr-backend-reviewer (if installed)
87
- │ security-sensitive: $sr-security-reviewer (if installed)
88
- │ perf-sensitive: $sr-performance-reviewer (if installed)
89
- │
90
- ├─► PHASE 4 (optional): post-review augmentation
91
- │ coverage dropped + $sr-test-writer installed → spawn
92
- │ public surface changed + $sr-doc-sync installed → spawn
93
- │
94
- └─► PHASE 5: close ticket + report
95
- ```
96
-
97
- All spawns are **full-history forks**. NEVER pass `agent_type`,
98
- `model`, or `reasoning_effort` to `spawn_agent` — codex rejects
99
- the combo and you'll burn a turn on the retry.
100
-
101
- ## Steps (in order)
102
-
103
- ### 0. Bootstrap + agent discovery
104
-
105
- 1. Confirm the repo root with `git -C "${SPECRAILS_REPO_DIR:-.}" rev-parse --show-toplevel`
106
- (the source repo is `${SPECRAILS_REPO_DIR:-.}`; unset ⇒ `.`).
107
- 2. Load the ticket (skip for free-form invocations) — the ticket store is
108
- run-state, relative to the working directory:
109
- `jq '.tickets["<ID>"]' .specrails/local-tickets.json`
110
- 3. **List the installed rail skills**:
111
- `ls .codex/skills/rails/`
112
- The output drives routing in phases 2-4. Skills that aren't
113
- listed are not installed — never spawn them. The three core
114
- rails (`sr-architect`, `sr-developer`, `sr-reviewer`) are
115
- always present. `sr-merge-resolver` and every layer specialist
116
- are optional — spawn them only when listed.
117
- 4. State (≤4 lines) the ticket goal, the stack you detected from
118
- a quick `ls`/`find`, and the optional rails that are
119
- available. Do NOT plan files-to-touch — that's the
120
- architect's job.
121
-
122
- ### 1. Phase 1 — Architect
123
-
124
- - `spawn_agent` (full-history, no agent_type / model /
125
- reasoning_effort).
126
- - `send_message` body (substitute `<TICKET_ID>` and
127
- `<TICKET_TITLE>`):
128
-
129
- > `$sr-architect`
130
- >
131
- > Ticket id: `<TICKET_ID>`
132
- > Ticket title: `<TICKET_TITLE>`
133
- >
134
- > Read `jq '.tickets["<TICKET_ID>"]' .specrails/local-tickets.json`
135
- > for the full ticket. Follow the `$sr-architect` skill
136
- > instructions exactly.
137
- >
138
- > In `design.md`'s `## Context` section, include a
139
- > `Scope: <labels>` line. Labels are a comma-separated set
140
- > drawn from: `frontend`, `backend`, `both`, `security-sensitive`,
141
- > `performance-sensitive`. Pick the labels that honestly apply
142
- > to this change. The orchestrator uses these to route
143
- > subsequent phases.
144
- >
145
- > Reply with the one-line summary the skill specifies.
146
-
147
- - `wait_agent`. Read the reply. Extract the plan path.
148
- - `close_agent`. Open the plan file + design.md.
149
- - **Parse the Scope line** from design.md's Context section.
150
- Store the set of labels for use in phases 2-3. If the line is
151
- missing, default to scope = `both`.
152
-
153
- If the architect replied with `BLOCKED: …`, stop the pipeline,
154
- write that reason into the final report, and exit without
155
- updating the ticket.
156
-
157
- ### 2. Phase 2 — Developer(s)
158
-
159
- Routing matrix (`available_rails` is the set from step 0.3,
160
- `scope` is the parsed set from step 1):
161
-
162
- | scope contains | available_rails has | spawn |
163
- |---|---|---|
164
- | `frontend` only | `sr-frontend-developer` | $sr-frontend-developer |
165
- | `backend` only | `sr-backend-developer` | $sr-backend-developer |
166
- | `frontend` only | (no fe specialist) | $sr-developer (general) |
167
- | `backend` only | (no be specialist) | $sr-developer (general) |
168
- | `both` | both specialists installed | TWO devs in parallel (see below) |
169
- | `both` | only one or neither specialist | $sr-developer (general) |
170
- | neither/unknown | — | $sr-developer (general) |
171
-
172
- **Parallel developer case** (`scope = both` AND both specialists
173
- installed AND `tasks.md` has tasks tagged `[frontend]` /
174
- `[backend]`):
175
-
176
- - spawn TWO `spawn_agent`s, anonymously named e.g.
177
- `developer-fe-#<TICKET_ID>` and `developer-be-#<TICKET_ID>`.
178
- - `send_message` to the frontend agent: `$sr-frontend-developer
179
- ... only run task blocks tagged [frontend] in tasks.md`.
180
- Symmetric message to the backend agent.
181
- - `wait_agent` on BOTH. Aggregate the changed-files list.
182
- - `close_agent` on both.
183
-
184
- If the architect's `tasks.md` doesn't tag task blocks, fall back
185
- to a single `$sr-developer` invocation — the parallel split
186
- needs ordered, non-overlapping cycles.
187
-
188
- **Sequential developer case** (default):
189
-
190
- - `spawn_agent` (full-history).
191
- - `send_message`:
192
-
193
- > `$<developer-skill>`
194
- >
195
- > Ticket id: `<TICKET_ID>`
196
- > Plan: `<PLAN_PATH>`
197
- > Scope: `<comma-separated labels>`
198
- >
199
- > Follow the `$<developer-skill>` skill instructions exactly.
200
-
201
- - `wait_agent`. Capture file list. `close_agent`.
202
-
203
- If the developer returned `BLOCKED: …`, surface it to the user
204
- in the final report (no review phase, no ticket update).
205
-
206
- ### 3. Phase 3 — Reviewer(s) in parallel
207
-
208
- Always spawn `$sr-reviewer`. In addition, spawn each of the
209
- following if the rail is installed AND the scope flag applies:
210
-
211
- | scope flag | rail to add (if installed) |
212
- |---|---|
213
- | `frontend` | `$sr-frontend-reviewer` |
214
- | `backend` | `$sr-backend-reviewer` |
215
- | `security-sensitive` | `$sr-security-reviewer` |
216
- | `performance-sensitive` | `$sr-performance-reviewer` |
217
-
218
- For each reviewer:
219
-
220
- - `spawn_agent` (full-history).
221
- - `send_message`:
222
-
223
- > `$<reviewer-skill>`
224
- >
225
- > Ticket id: `<TICKET_ID>`
226
- > Plan: `<PLAN_PATH>`
227
- > Changed files:
228
- > <one per line>
229
- >
230
- > Follow the `$<reviewer-skill>` skill instructions exactly.
231
-
232
- **Spawn all reviewers BEFORE waiting** so they run in parallel.
233
- Then `wait_agent` on each in turn. `close_agent` each as it
234
- returns.
235
-
236
- **Aggregate verdicts**:
237
-
238
- - Per reviewer: parse `Score: N/100` and `Verdict: …` from the
239
- reply.
240
- - Overall score = minimum of the reviewer scores (the harshest
241
- reviewer is the bound).
242
- - Overall verdict:
243
- - `clean` — every reviewer scored ≥ 70 AND nobody said
244
- fix/blocked
245
- - `fix needed` — any reviewer said `fix needed: …`, OR any
246
- score < 70 with no `blocked: …` verdict, OR any reviewer
247
- said `blocked: …` AND the overall score is **in the
248
- recoverable range 30-69**. The recoverable-blocked case is
249
- the common one where the reviewer used "blocked" because
250
- the issue is significant, not because the design itself is
251
- wrong — a single developer fix pass can usually clear it
252
- (e.g. API surface mismatch, missing JSX component shape,
253
- forgotten persistence hook).
254
- - `blocked` — any reviewer said `blocked: …` AND overall
255
- score is **< 30**, OR every reviewer said `blocked: …`.
256
- This is the design-level case where another developer
257
- pass won't help — the architect needs to re-engage.
258
-
259
- ### 4. Phase 4 — Optional augmentation
260
-
261
- Run AFTER review is `clean` (or after the single fix-loop pass).
262
- Skip when the overall verdict is `fix needed` or `blocked` — no
263
- point sugar-coating an unsound change.
264
-
265
- - If `sr-test-writer` is installed AND the reviewer's confidence
266
- artefact reports a coverage gap (`tdd_evidence.all_tasks_have_tests`
267
- is `false`, or `tdd_evidence.tests_are_non_trivial` is `false`),
268
- spawn it with the changed files list. It writes more tests, runs
269
- them, reports. (These are the fields the `$sr-reviewer` skill
270
- actually writes — do not key on a non-existent "coverage" field.)
271
- - If `sr-doc-sync` is installed AND the change touches a
272
- publicly-documented surface (README mentions a renamed
273
- function, AGENTS.md references a removed file, openspec specs
274
- drifted), spawn it.
275
-
276
- These augment, never block. If they return findings, surface in
277
- the final report under "Follow-up" rather than reopening the
278
- ticket.
279
-
280
- ### 5. Optional fix loop (single pass only)
281
-
282
- If phase 3's overall verdict is `fix needed`:
283
-
284
- - Spawn ONE follow-up developer (same routing rules as phase 2)
285
- with a message that includes every reviewer's `issues[]`
286
- array from their confidence artefacts.
287
- - `wait_agent`. `close_agent`.
288
- - Re-run phase 3 (same reviewer set). If still `fix needed` or
289
- `blocked`, **do not loop again** — surface in the final
290
- report.
291
-
292
- ### 6. Phase 5 — Archive FIRST, then close + report
293
-
294
- > **INVARIANT.** A ticket may be marked `done` ONLY if its change is
295
- > archived (`openspec/changes/archive/<slug>/` exists). A `clean`
296
- > verdict with an unarchived change is `todo` + `fix needed`, never
297
- > `done`. Archiving the change and closing the ticket are a single
298
- > atomic obligation — you cannot satisfy one and skip the other.
299
-
300
- **Step A — Archive the OpenSpec change through `$sr-reviewer`
301
- (mandatory when the verdict is `clean`). Run this BEFORE touching the
302
- ticket or writing the report.** A change is not done until it is
303
- archived — this is the codex equivalent of `opsx:archive`, and it MUST
304
- run. When the overall verdict is `clean`, delegate the final OpenSpec
305
- close to the reviewer rail so the same agent that validated the change
306
- performs the lifecycle close:
307
-
308
- 1. Spawn `$sr-reviewer` one final time (full-history fork).
309
- 2. Send this exact close prompt:
310
-
311
- > `$sr-reviewer`
312
- >
313
- > ARCHIVE_ONLY=true
314
- > ARCHIVE_AUTHORIZED=true
315
- > Ticket id: `<TICKET_ID>`
316
- > Plan: `<PLAN_PATH>`
317
- > Change slug: `<slug>`
318
- >
319
- > The aggregated reviewer verdict is clean. Follow the
320
- > `$sr-reviewer` archive-only instructions exactly: validate the
321
- > OpenSpec change, confirm every task is checked, perform the
322
- > OpenSpec archive command, and verify the archive landed.
323
-
324
- 3. `wait_agent`, parse the two-line `Score:` / `Verdict:` reply, and
325
- `close_agent`.
326
- 4. Treat any non-clean archive reply as archive failure.
327
-
328
- The reviewer rail's archive-only mode must run these checks:
329
-
330
- 1. Re-confirm every task box in `${SPECRAILS_REPO_DIR:-.}/openspec/changes/<slug>/tasks.md`
331
- is ticked (`- [x]`) and the change validates:
332
- `(cd "${SPECRAILS_REPO_DIR:-.}" && openspec validate "<slug>" --strict)`.
333
- 2. Archive it: `(cd "${SPECRAILS_REPO_DIR:-.}" && openspec archive "<slug>" -y)` — this updates the
334
- main specs and moves the change to `${SPECRAILS_REPO_DIR:-.}/openspec/changes/archive/`.
335
- 3. **Verify the archive landed — do NOT assume success.** Confirm
336
- `${SPECRAILS_REPO_DIR:-.}/openspec/changes/archive/` now contains the slug
337
- (`ls -d "${SPECRAILS_REPO_DIR:-.}"/openspec/changes/archive/*<slug>* 2>/dev/null`) AND that
338
- `${SPECRAILS_REPO_DIR:-.}/openspec/changes/<slug>/` is gone. If the archive directory is
339
- absent, archiving FAILED.
340
- 4. If `openspec validate`, `openspec archive`, or the step-3
341
- verification fails: do NOT mark the ticket `done`. Treat the run
342
- as `fix needed`, surface the error in the final report, set the
343
- report's `Archive:` line to `FAILED`, and leave the ticket
344
- `todo`.
345
-
346
- Skip archiving only when the verdict is `fix needed` or `blocked` —
347
- an unsound change must never be archived. In that case set the
348
- report's `Archive:` line to `skipped (<verdict>)`.
349
-
350
- **Step B — Close the ticket + report.** If a ticket id is in play:
351
-
352
- - Update `.specrails/local-tickets.json`. Modify only:
353
- - `tickets["<ID>"].status` → `"done"` (clean) or `"todo"`
354
- (fix needed / blocked)
355
- - `tickets["<ID>"].updated_at` → `date -Iseconds`
356
- - top-level `revision` → `revision + 1`
357
- - PRESERVE every other field.
358
-
359
- Print the final summary (≤18 lines):
360
-
361
- ```
362
- #<N> → done|todo
363
- Pipeline: architect → <developer skill(s)> → <reviewer skill(s)>
364
- Plan: <path>
365
- Confidence: <best path> (overall <score>/100)
366
- Archive: archived → openspec/changes/archive/<slug> | skipped (<verdict>) | FAILED
367
- Files: <one path per line, capped at 12; truncate beyond>
368
- Tests: <ran command, pass/fail>
369
- Build: <ran command, ok/fail/n/a>
370
- Follow-up: <one bullet per item>
371
- ```
372
-
373
- ## While a sub-agent is running: WAIT, do nothing else
374
-
375
- After `spawn_agent` + `send_message`, the only tool you should
376
- call is `wait_agent`. Do **not**:
377
-
378
- - Read files (`sed`, `cat`, `head`, `tail`) for "context to
379
- prepare the next phase"
380
- - Run `find`, `git status`, `git diff`, `npm test`, `ls`, or
381
- any other inspection during the wait
382
- - Spawn additional sub-agents speculatively
383
- - Try to "save time" by overlapping work
384
-
385
- Why:
386
-
387
- - The sub-agent is editing files; concurrent reads race with
388
- its writes and can return half-written content that
389
- poisons your next decision.
390
- - Each `sed`/`find`/`grep` you run costs tokens. A
391
- 10-minute developer phase with you reading the codebase
392
- every 30s adds up to a real cost increase for no benefit.
393
- - The next phase's brief is **deterministic** — it only
394
- needs the sub-agent's reply. You don't need to pre-scout.
395
-
396
- If `wait_agent` returns before the sub-agent is done (e.g.
397
- timeout on your side), wait again. Do not start
398
- inspecting.
399
-
400
- The only acceptable activity during the wait is your own
401
- narration — a single short line explaining what you're
402
- waiting for is fine for the user, but do not chain more
403
- than one such line per wait.
404
-
405
- ## What you must NOT do
406
-
407
- - **Do NOT handle multi-ticket invocations.** Route them to
408
- `$batch-implement` (see "Single-ticket only" above).
409
- - **Do NOT pass `agent_type`, `model`, or `reasoning_effort`** to
410
- `spawn_agent` on full-history forks.
411
- - **Do NOT inline role instructions** in your messages — each
412
- rail skill is the source of truth for what its role does.
413
- Your message points the sub-agent at the right skill and
414
- passes parameters; the skill body teaches the role.
415
- - **Do NOT spawn rails that aren't installed** in
416
- `.codex/skills/rails/`. The user's wizard selection determines
417
- what's available; respect it.
418
- - **Do NOT skip phases**. Even on trivial tickets, run
419
- architect → developer → at-least-one reviewer. A trivial run
420
- is still trazabilidad.
421
- - **Do NOT loop the fix-review more than once**.
422
- - **Do NOT touch `.claude/agent-memory/`** — codex projects use
423
- `.specrails/agent-memory/`.
424
- - **Do NOT update `.specrails/local-tickets.json`** from inside
425
- 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.