specrails-core 3.4.0 → 3.4.2

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.
@@ -0,0 +1,1461 @@
1
+ # Setup: Agent Workflow System
2
+
3
+ Interactive wizard to configure the full agent workflow system for this repository. Analyzes the codebase, discovers target users, generates VPC personas, and creates all agents, commands, rules, and configuration adapted to this project.
4
+
5
+ **Prerequisites:** Run `specrails/install.sh` first to install templates.
6
+
7
+ ---
8
+
9
+ ## Mode Detection
10
+
11
+ Check `$ARGUMENTS` in this order:
12
+
13
+ 1. If `--update` is present → execute **Update Mode** (below), then stop. Do NOT continue to Phase 1 or Lite Mode.
14
+ 2. If `--lite` is present → execute **Lite Mode** (below), then stop. Do NOT execute Phase 1.
15
+ 3. Otherwise (no flags) → skip directly to **Phase 1** and execute the full 5-phase wizard.
16
+
17
+ **Default is the full wizard.** Lite Mode only runs when `--lite` is explicitly passed.
18
+
19
+ ---
20
+
21
+ ## Update Mode
22
+
23
+ When `--update` is passed, execute this streamlined flow instead of the full wizard. Do not run any phases from the full wizard. When Phase U7 is complete, stop.
24
+
25
+ ### Phase U1: Read Update Context
26
+
27
+ Read the following files to understand the current installation state:
28
+
29
+ 1. Read `.specrails-manifest.json` — contains agent template checksums from the last install/update. Structure:
30
+ ```json
31
+ {
32
+ "version": "0.2.0",
33
+ "installed_at": "2025-01-15T10:00:00Z",
34
+ "artifacts": {
35
+ "templates/agents/architect.md": "sha256:<checksum>",
36
+ "templates/agents/developer.md": "sha256:<checksum>",
37
+ "templates/agents/reviewer.md": "sha256:<checksum>"
38
+ }
39
+ }
40
+ ```
41
+ If this file does not exist, inform the user:
42
+ > "No `.specrails-manifest.json` found. This looks like a pre-versioning installation. Run `update.sh` first to initialize the manifest, then re-run `/specrails:setup --update`."
43
+ Then stop.
44
+
45
+ 2. Read `.specrails-version` — contains the current version string (e.g., `0.2.0`). If it does not exist, treat version as `0.1.0 (legacy)`.
46
+
47
+ 3. Determine `$SPECRAILS_DIR` by reading `$SPECRAILS_DIR/setup-templates/.provider-detection.json` — try `.claude/setup-templates/.provider-detection.json` first, then `.codex/setup-templates/.provider-detection.json`. Extract `cli_provider` and `specrails_dir`. If not found, default to `cli_provider = "claude"`, `specrails_dir = ".claude"`.
48
+
49
+ 4. List all template files in `$SPECRAILS_DIR/setup-templates/agents/` — these are the NEW agent templates from the update:
50
+ ```bash
51
+ ls $SPECRAILS_DIR/setup-templates/agents/
52
+ ```
53
+ Template files are named with `sr-` prefix (e.g., `sr-architect.md`, `sr-developer.md`).
54
+
55
+ 5. List all template files in `$SPECRAILS_DIR/setup-templates/commands/specrails/` — these are the NEW command templates from the update:
56
+ ```bash
57
+ ls $SPECRAILS_DIR/setup-templates/commands/specrails/
58
+ ```
59
+ Command template files include `implement.md`, `batch-implement.md`, `compat-check.md`, `refactor-recommender.md`, `why.md`, `product-backlog.md`, `update-product-driven-backlog.md`.
60
+ If this directory does not exist, skip command template checking for this update.
61
+
62
+ 6. Read `$SPECRAILS_DIR/backlog-config.json` if it exists — contains stored provider configuration needed for command placeholder substitution.
63
+
64
+ ### Phase U2: Quick Codebase Re-Analysis
65
+
66
+ Perform the same analysis as Phase 1 of the full setup wizard, but silently — do not prompt the user and do not show the findings table. Just execute and store results internally.
67
+
68
+ Detect:
69
+ - **Languages**: Check for `*.py`, `*.ts`, `*.tsx`, `*.go`, `*.rs`, `*.java`, `*.kt`, `*.rb`, `*.cs`
70
+ - **Frameworks**: Search for imports (`fastapi`, `express`, `react`, `vue`, `angular`, `django`, `spring`, `gin`, `actix`, `rails`)
71
+ - **Directory structure**: Identify backend/frontend/core/test directories
72
+ - **Database**: Check for SQL files, ORM configs, migration directories
73
+ - **CI/CD**: Parse `.github/workflows/*.yml` for lint/test/build commands
74
+ - **Naming conventions**: Read 2-3 source files per detected layer
75
+
76
+ Read:
77
+ - `README.md` (if exists)
78
+ - `package.json` / `pyproject.toml` / `Cargo.toml` / `go.mod` / `pom.xml` (detect stack)
79
+ - `.github/workflows/*.yml` (detect CI commands)
80
+
81
+ Store all results for use in Phases U4 and U5.
82
+
83
+ ### Phase U3: Identify What Needs Regeneration
84
+
85
+ **Agent templates:** For each agent template, find its entry in the manifest's `artifacts` map (keyed as `templates/agents/sr-<name>.md`). Compute the SHA-256 checksum of the corresponding file in `.claude/setup-templates/agents/`:
86
+
87
+ ```bash
88
+ sha256sum .claude/setup-templates/agents/sr-<name>.md
89
+ ```
90
+
91
+ Build three lists for agents:
92
+
93
+ 1. **Changed agents**: agent name exists in manifest AND the current template checksum differs from the manifest checksum → mark for regeneration
94
+ 2. **New agents**: template file exists in `.claude/setup-templates/agents/` but the agent name is NOT in the manifest → mark for evaluation
95
+ 3. **Unchanged agents**: agent name exists in manifest AND checksum matches → skip
96
+
97
+ **Command templates:** If `.claude/setup-templates/commands/specrails/` exists, for each command template file, find its entry in the manifest's `artifacts` map (keyed as `templates/commands/specrails/<name>.md`). Compute the SHA-256 checksum of the corresponding file in `.claude/setup-templates/commands/specrails/`:
98
+
99
+ ```bash
100
+ sha256sum .claude/setup-templates/commands/specrails/<name>.md
101
+ ```
102
+
103
+ Build three lists for commands:
104
+
105
+ 1. **Changed commands**: command name exists in manifest AND the current template checksum differs from the manifest checksum → mark for update
106
+ 2. **New commands**: template file exists in `.claude/setup-templates/commands/specrails/` but the command name is NOT in the manifest → mark for evaluation
107
+ 3. **Unchanged commands**: command name exists in manifest AND checksum matches → skip
108
+
109
+ Display the combined analysis to the user:
110
+
111
+ ```
112
+ ## Update Analysis
113
+
114
+ ### Agents — Changed Templates (will be regenerated)
115
+ - sr-architect.md (template modified)
116
+ - sr-developer.md (template modified)
117
+
118
+ ### Agents — New Templates Available
119
+ - sr-frontend-developer.md
120
+ - sr-backend-developer.md
121
+
122
+ ### Agents — Unchanged (keeping current)
123
+ - sr-reviewer.md
124
+ - sr-product-manager.md
125
+
126
+ ### Commands — Changed Templates (will be updated)
127
+ - implement.md (template modified)
128
+
129
+ ### Commands — New Templates Available
130
+ - refactor-recommender.md
131
+
132
+ ### Commands — Unchanged (keeping current)
133
+ - compat-check.md
134
+ - why.md
135
+ ```
136
+
137
+ If there are no changed agents, no new agents, no changed commands, and no new commands, display:
138
+ ```
139
+ All agents and commands are already up to date. Nothing to regenerate.
140
+ ```
141
+ Then jump to Phase U7.
142
+
143
+ ### Phase U4: Regenerate Changed Agents
144
+
145
+ For each agent in the "changed" list:
146
+
147
+ 1. Read the NEW template from `$SPECRAILS_DIR/setup-templates/agents/sr-<name>.md`
148
+ 2. Use the codebase analysis from Phase U2 to fill in all `{{PLACEHOLDER}}` values, using the same substitution rules as Phase 4.1 of the full setup:
149
+ - `{{PROJECT_NAME}}` → project name (from README.md or directory name)
150
+ - `{{ARCHITECTURE_DIAGRAM}}` → detected architecture layers
151
+ - `{{LAYER_TAGS}}` → detected layer tags (e.g., `[backend]`, `[frontend]`, `[api]`)
152
+ - `{{CI_COMMANDS_BACKEND}}` → backend CI commands
153
+ - `{{CI_COMMANDS_FRONTEND}}` → frontend CI commands
154
+ - `{{LAYER_CONVENTIONS}}` → detected conventions per layer
155
+ - `{{PERSONA_NAMES}}` → read existing persona names from `$SPECRAILS_DIR/agents/personas/` filenames
156
+ - `{{PERSONA_FILES}}` → paths to existing persona files in `$SPECRAILS_DIR/agents/personas/`
157
+ - `{{DOMAIN_EXPERTISE}}` → infer from detected stack and README
158
+ - `{{KEY_FILE_PATHS}}` → important file paths detected in Phase U2
159
+ - `{{WARNINGS}}` → read from existing `CLAUDE.md` if present
160
+ - `{{MEMORY_PATH}}` → `$SPECRAILS_DIR/agent-memory/sr-<agent-name>/`
161
+ 3. Write the adapted agent using the format for the active provider (same dual-format rules as Phase 4.1):
162
+ - `cli_provider == "claude"`: write to `$SPECRAILS_DIR/agents/sr-<name>.md` (Markdown with YAML frontmatter)
163
+ - `cli_provider == "codex"`: write to `$SPECRAILS_DIR/agents/sr-<name>.toml` (TOML format with `name`, `description`, `model`, `prompt` fields)
164
+ 4. Show: `✓ Regenerated sr-<name>`
165
+
166
+ After regenerating all changed agents, verify no unresolved placeholders remain:
167
+ ```bash
168
+ # Claude Code
169
+ grep -r '{{[A-Z_]*}}' .claude/agents/sr-*.md 2>/dev/null || echo "OK: no broken placeholders"
170
+ # Codex
171
+ grep -r '{{[A-Z_]*}}' .codex/agents/sr-*.toml 2>/dev/null || echo "OK: no broken placeholders"
172
+ ```
173
+
174
+ ### Phase U4b: Update Changed Commands
175
+
176
+ For each command in the "changed commands" list from Phase U3:
177
+
178
+ 1. Read the NEW template:
179
+ - If `cli_provider == "claude"`: from `$SPECRAILS_DIR/setup-templates/commands/specrails/<name>.md`
180
+ - If `cli_provider == "codex"`: from `$SPECRAILS_DIR/setup-templates/skills/sr-<name>/SKILL.md`
181
+ 2. Read stored backlog configuration from `$SPECRAILS_DIR/backlog-config.json` (if it exists) to resolve provider-specific placeholders:
182
+ - `BACKLOG_PROVIDER` → `provider` field (`github`, `jira`, or `none`)
183
+ - `BACKLOG_WRITE` → `write_access` field
184
+ - `JIRA_BASE_URL` → `jira_base_url` field
185
+ - `JIRA_PROJECT_KEY` → `jira_project_key` field
186
+ 3. Substitute all `{{PLACEHOLDER}}` values using the same rules as Phase 4.3 of the full setup:
187
+ - `{{CI_COMMANDS_BACKEND}}` → backend CI commands detected in Phase U2
188
+ - `{{CI_COMMANDS_FRONTEND}}` → frontend CI commands detected in Phase U2
189
+ - `{{DEPENDENCY_CHECK_COMMANDS}}` → stack-specific dependency check commands from Phase U2
190
+ - `{{TEST_RUNNER_CHECK}}` → test runner commands from Phase U2
191
+ - `{{BACKLOG_FETCH_CMD}}` → provider-specific fetch command from backlog config
192
+ - `{{BACKLOG_CREATE_CMD}}` → provider-specific create command from backlog config
193
+ - `{{BACKLOG_VIEW_CMD}}` → provider-specific view command from backlog config
194
+ - `{{BACKLOG_PREFLIGHT}}` → provider-specific preflight check from backlog config
195
+ - Any other `{{PLACEHOLDER}}` values → use Phase U2 analysis data
196
+ 4. Write the updated file:
197
+ - If `cli_provider == "claude"`: to `.claude/commands/specrails/<name>.md`
198
+ - If `cli_provider == "codex"`: to `.agents/skills/sr-<name>/SKILL.md`
199
+ 5. Show:
200
+ - If `cli_provider == "claude"`: `✓ Updated /specrails:<name>`
201
+ - If `cli_provider == "codex"`: `✓ Updated $sr-<name>`
202
+
203
+ After updating all changed commands/skills, verify no unresolved placeholders remain:
204
+ ```bash
205
+ # If cli_provider == "claude":
206
+ grep -l '{{[A-Z_]*}}' .claude/commands/specrails/*.md 2>/dev/null || echo "OK: no broken placeholders"
207
+ # If cli_provider == "codex":
208
+ grep -rl '{{[A-Z_]*}}' .agents/skills/sr-*/SKILL.md 2>/dev/null || echo "OK: no broken placeholders"
209
+ ```
210
+ If any placeholders remain unresolved, warn the user:
211
+ > "⚠ Some placeholders in `<filename>` could not be resolved automatically. Please review the file and fill them in manually."
212
+
213
+ ### Phase U5: Evaluate New Agents
214
+
215
+ For each agent in the "new" list:
216
+
217
+ 1. Read the template from `.claude/setup-templates/agents/sr-<name>.md` to understand what stack or layer it targets (read its description and any layer-specific comments)
218
+ 2. Match against the codebase detected in Phase U2:
219
+ - If the template targets a layer/stack that IS present (e.g., `sr-frontend-developer` and React was detected), prompt:
220
+ > "New agent available: `sr-<name>` — your project uses [detected tech]. Add it? [Y/n]"
221
+ - If the template targets a layer/stack that is NOT present (e.g., `sr-backend-developer` and no backend was detected), prompt:
222
+ > "New agent available: `sr-<name>` — no [layer] detected in your project. Skip? [Y/n]"
223
+ 3. If the user accepts (or presses Enter on a pre-selected default):
224
+ - Generate the agent using the same template adaptation as Phase U4
225
+ - Create memory directory if it does not exist: `$SPECRAILS_DIR/agent-memory/sr-<name>/`
226
+ - Show: `✓ Added sr-<name>`
227
+ 4. If the user declines:
228
+ - Show: `→ Skipped sr-<name>`
229
+
230
+ For each command in the "new commands" list from Phase U3:
231
+
232
+ 1. Read the template:
233
+ - If `cli_provider == "claude"`: from `$SPECRAILS_DIR/setup-templates/commands/specrails/<name>.md`
234
+ - If `cli_provider == "codex"`: from `$SPECRAILS_DIR/setup-templates/skills/sr-<name>/SKILL.md`
235
+ 2. Prompt the user:
236
+ - If `cli_provider == "claude"`: `"New command available: /specrails:<name> — [one-line description]. Install it? [Y/n]"`
237
+ - If `cli_provider == "codex"`: `"New skill available: $sr-<name> — [one-line description]. Install it? [Y/n]"`
238
+ 3. If the user accepts (or presses Enter):
239
+ - Apply placeholder substitution using the same rules as Phase U4b (backlog config + codebase analysis)
240
+ - If `cli_provider == "claude"`: write to `.claude/commands/specrails/<name>.md` — show `✓ Added /specrails:<name>`
241
+ - If `cli_provider == "codex"`: write to `.agents/skills/sr-<name>/SKILL.md` — show `✓ Added $sr-<name>`
242
+ 4. If the user declines:
243
+ - If `cli_provider == "claude"`: show `→ Skipped /specrails:<name>`
244
+ - If `cli_provider == "codex"`: show `→ Skipped $sr-<name>`
245
+
246
+ ### Phase U6: Update Workflow Commands
247
+
248
+ If any new agents were added in Phase U5:
249
+
250
+ 1. Read the implement command/skill:
251
+ - If `cli_provider == "claude"`: `.claude/commands/specrails/implement.md`
252
+ - If `cli_provider == "codex"`: `.agents/skills/sr-implement/SKILL.md`
253
+ 2. Check if the file references agent names in its orchestration steps (look for `sr-architect`, `sr-developer`, `sr-reviewer` etc.)
254
+ 3. If newly added agents belong in the implementation pipeline (i.e., they are layer-specific developers such as `sr-frontend-developer` or `sr-backend-developer`), add them to the appropriate step in the implement command — specifically where parallel developer agents are launched
255
+ 4. Write the updated file if any changes were made:
256
+ - If `cli_provider == "claude"`: `.claude/commands/specrails/implement.md`
257
+ - If `cli_provider == "codex"`: `.agents/skills/sr-implement/SKILL.md`
258
+ 5. Show which commands were updated, or "No command updates needed" if nothing changed
259
+
260
+ This is a lightweight check — only update commands where the sr- agent clearly belongs. Do not restructure the entire command.
261
+
262
+ ### Phase U7: Summary
263
+
264
+ Display the final summary and stop. Do not continue to Phase 1 of the full setup wizard.
265
+
266
+ ```
267
+ ## Update Complete
268
+
269
+ specrails updated from v<previous> to v<new>.
270
+
271
+ | Action | Count |
272
+ |---------------------|-------|
273
+ | Agents regenerated | N |
274
+ | Agents added | N |
275
+ | Agents skipped | N |
276
+ | Commands updated | N |
277
+ | Commands added | N |
278
+ | Commands skipped | N |
279
+
280
+ All agents and commands are now up to date.
281
+
282
+ ### Agents Regenerated
283
+ [list agent names, or "(none)"]
284
+
285
+ ### Agents Added
286
+ [list agent names, or "(none)"]
287
+
288
+ ### Agents Skipped
289
+ [list agent names, or "(none)"]
290
+
291
+ ### Commands Updated
292
+ [list command names, or "(none)"]
293
+
294
+ ### Commands Added
295
+ [list command names, or "(none)"]
296
+
297
+ ### Commands Skipped
298
+ [list command names, or "(none)"]
299
+ ```
300
+
301
+ Update `.specrails-manifest.json` to reflect the new checksums for all regenerated/updated and added agents and commands:
302
+ - For each regenerated agent: update its checksum entry to the new template's checksum (keyed as `templates/agents/sr-<name>.md`)
303
+ - For each added agent: add a new entry with its checksum
304
+ - For each updated command: update its checksum entry to the new template's checksum (keyed as `templates/commands/specrails/<name>.md`)
305
+ - For each added command: add a new entry with its checksum
306
+ - Update the `version` field to the version read from `.specrails-version`
307
+
308
+ ---
309
+
310
+ ## Lite Mode
311
+
312
+ When `--lite` is passed, run this streamlined 3-question setup. Do NOT run Phase 1–5. When QS4 is complete, stop.
313
+
314
+ ### QS1: Ask the 3 questions
315
+
316
+ Display the following prompt EXACTLY ONCE and then wait for the user's responses. Do NOT repeat the questions — output them a single time only.
317
+
318
+ Welcome to specrails! Let's get your AI agent team set up in 3 quick questions.
319
+
320
+ 1. What is this project? (one sentence)
321
+ 2. Who are the target users?
322
+ 3. Git access for agents — read-only or read-write?
323
+ (read-only = agents can read and suggest; read-write = agents can commit)
324
+
325
+ Store the answers as:
326
+ - `QS_PROJECT_DESCRIPTION` — answer to question 1
327
+ - `QS_TARGET_USERS` — answer to question 2
328
+ - `QS_GIT_ACCESS` — "read-only" or "read-write" (normalize if user types "ro", "rw", "readonly", etc.)
329
+
330
+ ### QS2: Apply opinionated defaults
331
+
332
+ Use these defaults for all configuration not asked in QS1:
333
+
334
+ | Setting | Lite Mode Default |
335
+ |---------|------------------|
336
+ | Agents enabled | sr-architect, sr-developer, sr-reviewer, sr-product-manager |
337
+ | Git mode | Derived from QS_GIT_ACCESS |
338
+ | CLAUDE.md template | `templates/CLAUDE-quickstart.md` |
339
+ | OpenSpec enabled | Yes if `openspec` CLI is detected in PATH, No otherwise |
340
+ | Telemetry | Not configured (deferred to PRD-002) |
341
+ | Backlog provider | local (lightweight JSON-based, no external tools needed) |
342
+
343
+ Detect whether this is an existing codebase or new project:
344
+ - **Existing codebase**: `package.json`, `Gemfile`, `pyproject.toml`, `go.mod`, or `pom.xml` found in the repo root
345
+ - **New project**: none of the above found
346
+
347
+ Store as `QS_IS_EXISTING_CODEBASE=true/false`.
348
+
349
+ ### QS2.5: Re-run Detection
350
+
351
+ Before generating files, check if this is a re-run:
352
+
353
+ 1. Check if commands/skills already exist:
354
+ - If `cli_provider == "claude"`: check if `.claude/commands/specrails/` directory exists with any `.md` files:
355
+ ```bash
356
+ ls .claude/commands/specrails/*.md 2>/dev/null
357
+ ```
358
+ - If `cli_provider == "codex"`: check if `.agents/skills/sr-*/SKILL.md` files exist:
359
+ ```bash
360
+ ls .agents/skills/sr-*/SKILL.md 2>/dev/null
361
+ ```
362
+ 2. If files are found → this is a **re-run**. Store `QS_IS_RERUN=true`.
363
+ 3. If the directory does not exist or is empty → this is a **fresh install**. Store `QS_IS_RERUN=false`.
364
+
365
+ In re-run mode, QS3 executes in **gap-fill mode** for command/skill files:
366
+ - For each command in the list, check if it already exists:
367
+ - If `cli_provider == "claude"`: at `.claude/commands/specrails/<name>.md`
368
+ - If `cli_provider == "codex"`: at `.agents/skills/sr-<name>/SKILL.md`
369
+ - If it exists: skip it and show:
370
+ - Claude: `✓ Already installed: /specrails:<name>`
371
+ - Codex: `✓ Already installed: $sr-<name>`
372
+ - If it does NOT exist: install it and show:
373
+ - Claude: `✓ Added /specrails:<name> (was missing)`
374
+ - Codex: `✓ Added $sr-<name> (was missing)`
375
+ - Do NOT prompt the user for confirmation on missing files — install them automatically
376
+
377
+ For CLAUDE.md/AGENTS.md and agent files, the existing per-file prompts already handle re-runs (user is asked before overwriting). No change needed there.
378
+
379
+ ### QS3: Generate files
380
+
381
+ Generate files using the Lite Mode defaults.
382
+
383
+ **1. CLAUDE.md**
384
+
385
+ Read `setup-templates/claude-md/CLAUDE-quickstart.md` (or fall back to `setup-templates/claude-md/default.md` if quickstart template is not found).
386
+
387
+ Replace placeholders:
388
+ - `{{PROJECT_NAME}}` → derive from directory name or README.md first heading
389
+ - `{{PROJECT_DESCRIPTION}}` → `QS_PROJECT_DESCRIPTION`
390
+ - `{{TARGET_USERS}}` → `QS_TARGET_USERS`
391
+ - `{{GIT_ACCESS}}` → `QS_GIT_ACCESS`
392
+
393
+ Write to `CLAUDE.md` in the repo root. If `CLAUDE.md` already exists, ask:
394
+ > "CLAUDE.md already exists. Overwrite? [Y/n]"
395
+ Skip if user says no.
396
+
397
+ **2. Agent files**
398
+
399
+ For each default agent (sr-architect, sr-developer, sr-reviewer, sr-product-manager), read the template from `$SPECRAILS_DIR/setup-templates/agents/<name>.md` and generate the adapted agent file using the dual-format rules from Phase 4.1:
400
+ - `cli_provider == "claude"`: write to `.claude/agents/<name>.md` (Markdown with frontmatter)
401
+ - `cli_provider == "codex"`: write to `.codex/agents/<name>.toml` (TOML format)
402
+
403
+ Fill placeholders with best-effort values from the limited context available:
404
+ - `{{PROJECT_NAME}}` → directory name or README first heading
405
+ - `{{PROJECT_DESCRIPTION}}` → `QS_PROJECT_DESCRIPTION`
406
+ - `{{TARGET_USERS}}` → `QS_TARGET_USERS`
407
+ - `{{GIT_ACCESS}}` → `QS_GIT_ACCESS`
408
+ - `{{ARCHITECTURE_DIAGRAM}}` → "(Lite Mode — run `/specrails:setup` for full architecture analysis)"
409
+ - `{{TECH_EXPERTISE}}` → "(Lite Mode — run `/specrails:setup` for codebase-specific expertise)"
410
+ - `{{LAYER_TAGS}}` → detect from package.json / Gemfile / go.mod if present; otherwise leave empty
411
+ - All other placeholders → "(not configured — run `/specrails:setup`)"
412
+
413
+ Create memory directories: `$SPECRAILS_DIR/agent-memory/sr-<name>/`
414
+
415
+ **3. Command files**
416
+
417
+ Core commands (always install if missing):
418
+ - `implement.md`
419
+ - `batch-implement.md`
420
+ - `propose-spec.md`
421
+ - `compat-check.md`
422
+ - `why.md`
423
+ - `product-backlog.md`
424
+ - `update-product-driven-backlog.md`
425
+
426
+ **Initialize local ticket storage** (backlog provider defaults to `local`):
427
+ 1. Copy `templates/local-tickets-schema.json` to `$SPECRAILS_DIR/local-tickets.json` and set `last_updated` to the current ISO-8601 timestamp. Skip if the file already exists.
428
+ 2. Write `$SPECRAILS_DIR/backlog-config.json` (skip if already exists):
429
+ ```json
430
+ {
431
+ "provider": "local",
432
+ "write_access": true,
433
+ "git_auto": true
434
+ }
435
+ ```
436
+
437
+ **If `cli_provider == "claude"`:**
438
+
439
+ If `QS_IS_RERUN=false` (fresh install): for each core command, read the template from `$SPECRAILS_DIR/setup-templates/commands/specrails/<name>.md`, substitute the backlog placeholders with local values (using the same table as Phase 4.3 "Local Tickets"), stub all persona placeholders with `(Lite Mode — run /specrails:setup to configure personas)`, then write to `.claude/commands/specrails/<name>.md`.
440
+
441
+ If `QS_IS_RERUN=true` (gap-fill mode): for each command in the list above, check if `.claude/commands/specrails/<name>.md` already exists:
442
+ - If it exists: skip it — show `✓ Already installed: /specrails:<name>`
443
+ - If it does NOT exist: read template, substitute placeholders as above, write to `.claude/commands/specrails/<name>.md` — show `✓ Added /specrails:<name> (was missing)`
444
+
445
+ **If `cli_provider == "codex"`:**
446
+
447
+ If `QS_IS_RERUN=false` (fresh install): for each core command, read the corresponding skill template from `$SPECRAILS_DIR/setup-templates/skills/sr-<name>/SKILL.md`, substitute the backlog placeholders with local values and stub persona placeholders with `(Lite Mode — run /specrails:setup to configure personas)`, then write to `.agents/skills/sr-<name>/SKILL.md` (create the directory first).
448
+
449
+ If `QS_IS_RERUN=true` (gap-fill mode): for each command in the list above, check if `.agents/skills/sr-<name>/SKILL.md` already exists:
450
+ - If it exists: skip it — show `✓ Already installed: $sr-<name>`
451
+ - If it does NOT exist: read template, substitute placeholders as above, write to `.agents/skills/sr-<name>/SKILL.md` — show `✓ Added $sr-<name> (was missing)`
452
+
453
+ **4. Cleanup**
454
+
455
+ Remove `setup-templates/` from `.claude/` (same as full wizard cleanup in Phase 5).
456
+
457
+ Remove `commands/setup.md` from `.claude/commands/` if it was copied there by the installer.
458
+
459
+ ### QS4: First Task Prompt
460
+
461
+ After generating all files, display the setup complete message.
462
+
463
+ Then, based on `QS_IS_EXISTING_CODEBASE`:
464
+ - **Existing codebase** (`true`): recommend `/specrails:refactor-recommender`
465
+ - **New project** (`false`): recommend `/specrails:product-backlog`
466
+
467
+ If `QS_IS_RERUN=false`, display:
468
+ ```
469
+ ✅ Setup complete.
470
+
471
+ Try your first command:
472
+ > /specrails:product-backlog
473
+ ```
474
+ (Replace `/specrails:product-backlog` with `/specrails:refactor-recommender` for existing codebases.)
475
+
476
+ If `QS_IS_RERUN=true`, display the gap-fill summary and stop:
477
+ ```
478
+ ✅ Re-run complete.
479
+
480
+ Commands status:
481
+ ✓ Already installed: /specrails:<name>
482
+ ✓ Added /specrails:<name> (was missing)
483
+ [... one line per command ...]
484
+
485
+ All commands are up to date.
486
+ ```
487
+ If all commands were already present, display:
488
+ ```
489
+ ✅ Re-run complete. All commands already installed — nothing to add.
490
+ ```
491
+
492
+ Then stop. Do not execute Phase 1.
493
+
494
+ ---
495
+
496
+ ## Phase 1: Codebase Analysis
497
+
498
+ Analyze the repository to understand its architecture, stack, and conventions.
499
+
500
+ ### 1.1 Read project structure
501
+
502
+ ```bash
503
+ # Get the repo root and basic info
504
+ git rev-parse --show-toplevel
505
+ ls -la
506
+ ```
507
+
508
+ Read the following to understand the project:
509
+ - `README.md` (if exists)
510
+ - `CLAUDE.md` (if exists — don't overwrite, merge later)
511
+ - `package.json` or `pyproject.toml` or `Cargo.toml` or `go.mod` or `pom.xml` (detect stack)
512
+ - `.github/workflows/*.yml` (detect CI commands)
513
+ - `docker-compose.yml` or `Dockerfile` (detect infra)
514
+
515
+ ### 1.2 Detect architecture layers
516
+
517
+ Use Glob and Grep to identify:
518
+
519
+ 1. **Languages**: Check for `*.py`, `*.ts`, `*.tsx`, `*.go`, `*.rs`, `*.java`, `*.kt`, `*.rb`, `*.cs`
520
+ 2. **Frameworks**: Search for imports (`fastapi`, `express`, `react`, `vue`, `angular`, `django`, `spring`, `gin`, `actix`, `rails`)
521
+ 3. **Directory structure**: Identify backend/frontend/core/test directories
522
+ 4. **Database**: Check for SQL files, ORM configs, migration directories
523
+ 5. **CI/CD**: Parse workflow files for lint/test/build commands
524
+
525
+ ### 1.3 Infer conventions
526
+
527
+ Read 3-5 representative source files from each detected layer to understand:
528
+ - Naming conventions (camelCase, snake_case, PascalCase)
529
+ - Import patterns
530
+ - Error handling patterns
531
+ - Testing patterns (framework, structure, mocking approach)
532
+ - API patterns (REST, GraphQL, tRPC)
533
+
534
+ ### 1.4 Present findings
535
+
536
+ Display the detected architecture to the user:
537
+
538
+ ```
539
+ ## Codebase Analysis
540
+
541
+ | Layer | Tech | Path |
542
+ |-------------|---------------------|---------------|
543
+ | Backend | FastAPI (Python) | backend/ |
544
+ | Frontend | React + TypeScript | frontend/ |
545
+ | Core | Python package | src/ |
546
+ | Tests | pytest | tests/ |
547
+ | Database | PostgreSQL | migrations/ |
548
+
549
+ ### CI Commands Detected
550
+ - Lint: `ruff check .`
551
+ - Format: `ruff format --check .`
552
+ - Test: `pytest tests/ -q`
553
+ - Frontend lint: `npm run lint`
554
+ - Frontend build: `npx tsc --noEmit`
555
+
556
+ ### Conventions Detected
557
+ - Python: snake_case, type hints, Pydantic models
558
+ - TypeScript: strict mode, functional components
559
+ - Testing: pytest fixtures with scope="function"
560
+
561
+ ### OSS Project Detection
562
+
563
+ Read `.claude/setup-templates/.oss-detection.json` if it exists.
564
+
565
+ | Signal | Status |
566
+ |--------|--------|
567
+ | Public repository | [Yes / No / Unknown] |
568
+ | CI workflows (.github/workflows/) | [Yes / No] |
569
+ | CONTRIBUTING.md | [Yes / No] |
570
+ | **Result** | **OSS detected / Not detected / Could not check** |
571
+
572
+ If `is_oss: false` but at least one signal is `true`:
573
+ > "Some OSS signals were found but not all three. Is this an open-source project? (yes/no)"
574
+
575
+ If `.oss-detection.json` does not exist:
576
+ > "Is this an open-source project? (yes/no)"
577
+
578
+ When `IS_OSS=false` and no signals are present, skip OSS output entirely to avoid cluttering the display for non-OSS projects.
579
+
580
+ Store the final OSS determination as `IS_OSS` for use throughout the rest of setup.
581
+
582
+ [Confirm] [Modify] [Rescan]
583
+ ```
584
+
585
+ Wait for user confirmation. If they want to modify, ask what to change.
586
+
587
+ ---
588
+
589
+ ## Phase 2: User Personas & Product Discovery
590
+
591
+ ### 2.1 Ask about target users
592
+
593
+ Ask the user:
594
+
595
+ > If IS_OSS=true, prepend:
596
+ > "This is an OSS project. The **Maintainer** persona (Kai) is automatically included —
597
+ > you do not need to add 'open-source maintainers' to your list.
598
+ > Describe your other target user types below."
599
+
600
+ > **Who are the target users of your software?**
601
+ >
602
+ > Describe them in natural language. Examples:
603
+ > - "Developers who manage Kubernetes clusters"
604
+ > - "Small business owners tracking inventory and sales"
605
+ > - "Gamers who collect and trade digital items"
606
+ >
607
+ > I'll research the competitive landscape and create detailed personas
608
+ > with Value Proposition Canvas profiles for each user type.
609
+ >
610
+ > **How many distinct user types do you have?** (typically 2-3)
611
+
612
+ Wait for the user's response.
613
+
614
+ ### 2.2 Research competitive landscape
615
+
616
+ For each user type described, use WebSearch to research:
617
+
618
+ 1. **Existing tools** they use today (competitors)
619
+ 2. **Common pain points** reported in forums, Reddit, product reviews
620
+ 3. **Feature gaps** in current tools
621
+ 4. **Unmet needs** and workflow frustrations
622
+
623
+ Search queries to use (adapt to the domain):
624
+ - `"[domain] [user type] best tools 2025"`
625
+ - `"[domain] [user type] pain points frustrations"`
626
+ - `"[competitor name] missing features complaints"`
627
+ - `"[domain] management app feature comparison"`
628
+ - `site:reddit.com "[domain] [user type] what tool do you use"`
629
+
630
+ ### 2.3 Generate VPC personas
631
+
632
+ For each user type, generate a full Value Proposition Canvas persona file following the template at `.claude/setup-templates/personas/persona.md`.
633
+
634
+ Each persona must include:
635
+ - **Profile**: Demographics, behaviors, tools used, spending patterns
636
+ - **Customer Jobs**: Functional, social, emotional (6-8 jobs)
637
+ - **Pains**: Graded by severity (Critical > High > Medium > Low) with 6-8 entries
638
+ - **Gains**: Graded by impact (High > Medium > Low) with 6-8 entries
639
+ - **Key Insight**: The #1 unmet need that this project can address
640
+ - **Sources**: Links to competitive analysis, forums, reviews used in research
641
+
642
+ ### 2.4 Present personas
643
+
644
+ Display each generated persona to the user:
645
+
646
+ ```
647
+ ## Generated Personas
648
+
649
+ ### Persona 1: "[Nickname]" — The [Role]
650
+ - Age: X-Y
651
+ - Key pain: [Critical pain]
652
+ - Key insight: [Main unmet need]
653
+
654
+ ### Persona 2: "[Nickname]" — The [Role]
655
+ - Age: X-Y
656
+ - Key pain: [Critical pain]
657
+ - Key insight: [Main unmet need]
658
+
659
+ [Accept] [Edit] [Regenerate]
660
+ ```
661
+
662
+ Wait for confirmation. If the user wants edits, apply them.
663
+
664
+ ---
665
+
666
+ ## Phase 3: Configuration
667
+
668
+ ### 3.1 Agents to install
669
+
670
+ Present the available agents and let the user choose:
671
+
672
+ ```
673
+ ## Agent Selection
674
+
675
+ Which agents do you want to install?
676
+
677
+ | Agent | Purpose | Model | Required |
678
+ |-------|---------|-------|----------|
679
+ | sr-architect | Design features, create implementation plans | Sonnet | Yes |
680
+ | sr-developer (full-stack) | Implement features across all layers | Sonnet | Yes |
681
+ | sr-reviewer | CI/CD quality gate, fix issues | Sonnet | Yes |
682
+ | sr-test-writer | Generate unit, integration, and edge-case tests after implementation | Sonnet | Yes |
683
+ | sr-security-reviewer | Scan for secrets, OWASP vulnerabilities, hardcoded credentials | Sonnet | Yes |
684
+ | sr-product-manager | Product discovery, ideation, VPC evaluation | Opus | Recommended |
685
+ | sr-product-analyst | Read-only backlog analysis | Haiku | Recommended |
686
+ | sr-backend-developer | Specialized backend implementation | Sonnet | If backend layer exists |
687
+ | sr-frontend-developer | Specialized frontend implementation | Sonnet | If frontend layer exists |
688
+
689
+ [All] [Required only] [Custom selection]
690
+ ```
691
+
692
+ ### 3.2 Backlog provider
693
+
694
+ Ask the user how they want to manage their product backlog. Default is local — no external tools or accounts required:
695
+
696
+ ```
697
+ ## Backlog Provider
698
+
699
+ Use local ticket management or connect an external provider?
700
+
701
+ 1. **Local tickets** (default, recommended) — lightweight JSON-based ticket management built into the project.
702
+ No external tools or accounts required. Tickets stored in `.claude/local-tickets.json`, version-controlled and diffable.
703
+ 2. **External provider** — connect GitHub Issues, JIRA, or disable backlog commands
704
+ ```
705
+
706
+ If the user selects **1** or presses Enter without typing anything: set `BACKLOG_PROVIDER=local` and proceed directly to **If Local Tickets** below. Do NOT ask about GitHub CLI, JIRA credentials, or any external provider configuration.
707
+
708
+ If the user selects **2**: display the secondary menu:
709
+
710
+ ```
711
+ ## External Backlog Provider
712
+
713
+ Which external provider?
714
+
715
+ 1. **Local tickets** (recommended) — lightweight JSON-based ticket management built into the project.
716
+ No external tools required. Tickets stored in `.claude/local-tickets.json`, version-controlled and diffable.
717
+ 2. **GitHub Issues** — uses `gh` CLI to read/create issues with labels and VPC scores
718
+ 3. **JIRA** — uses JIRA CLI or REST API to read/create tickets in a JIRA project
719
+ 4. **None** — skip backlog commands (you can still use /implement with text descriptions)
720
+ ```
721
+
722
+ Wait for the user's choice. Set `BACKLOG_PROVIDER` to `local`, `github`, `jira`, or `none`.
723
+
724
+ #### If Local Tickets
725
+
726
+ No external tools or credentials required. Initialize the storage file:
727
+
728
+ 1. Copy `templates/local-tickets-schema.json` to `$SPECRAILS_DIR/local-tickets.json`
729
+ 2. Set `last_updated` to the current ISO-8601 timestamp
730
+
731
+ Store configuration in `$SPECRAILS_DIR/backlog-config.json`:
732
+ ```json
733
+ {
734
+ "provider": "local",
735
+ "write_access": true,
736
+ "git_auto": true
737
+ }
738
+ ```
739
+
740
+ Local tickets are always read-write — there is no "read only" mode since the file is local.
741
+
742
+ **Ticket schema** — each entry in the `tickets` map has these fields:
743
+
744
+ ```json
745
+ {
746
+ "id": 1,
747
+ "title": "Feature title",
748
+ "description": "Markdown description",
749
+ "status": "todo",
750
+ "priority": "medium",
751
+ "labels": ["area:frontend", "effort:medium"],
752
+ "assignee": null,
753
+ "prerequisites": [],
754
+ "metadata": {
755
+ "vpc_scores": {},
756
+ "effort_level": "Medium",
757
+ "user_story": "",
758
+ "area": ""
759
+ },
760
+ "comments": [],
761
+ "created_at": "<ISO-8601>",
762
+ "updated_at": "<ISO-8601>",
763
+ "created_by": "user",
764
+ "source": "manual"
765
+ }
766
+ ```
767
+
768
+ **Status values:** `todo`, `in_progress`, `done`, `cancelled`
769
+ **Priority values:** `critical`, `high`, `medium`, `low`
770
+ **Labels:** Freeform strings following the `area:*` and `effort:*` convention
771
+ **Source values:** `manual`, `product-backlog`, `propose-spec`
772
+
773
+ **Advisory file locking protocol** (CLI agents and hub server must both follow this):
774
+
775
+ The `revision` counter in the JSON root enables optimistic concurrency — increment it on **every** write. The lock file prevents concurrent corruption:
776
+
777
+ 1. **Acquire lock:** Check for `$SPECRAILS_DIR/local-tickets.json.lock`
778
+ - If the file exists and its `timestamp` is less than 30 seconds old: wait 500ms and retry (max 5 attempts before aborting with an error)
779
+ - If the file exists and its `timestamp` is 30+ seconds old (stale): delete it and proceed
780
+ - If no lock file exists: proceed immediately
781
+ 2. **Create lock file:** Write `{"agent": "<agent-name-or-process>", "timestamp": "<ISO-8601>"}` to `$SPECRAILS_DIR/local-tickets.json.lock`
782
+ 3. **Minimal lock window:** Read the JSON → modify in memory → write back → release
783
+ 4. **Release lock:** Delete `$SPECRAILS_DIR/local-tickets.json.lock`
784
+ 5. **Always increment `revision`** by 1 and update `last_updated` on every successful write
785
+
786
+ The hub server uses `proper-lockfile` (or equivalent) to honor the same protocol via the `.lock` file path.
787
+
788
+ #### If GitHub Issues
789
+
790
+ - Verify `gh auth status` works. If not, warn and offer to skip.
791
+ - Ask about **access mode**:
792
+
793
+ ```
794
+ ## GitHub Issues — Access Mode
795
+
796
+ How should we interact with GitHub Issues?
797
+
798
+ 1. **Read & Write** (default) — read backlog, create new issues from product discovery,
799
+ close resolved issues, add comments on partial progress
800
+ 2. **Read only** — read backlog for prioritization, but don't create or modify issues.
801
+ Product discovery will propose ideas as output but won't sync them to GitHub.
802
+ ```
803
+
804
+ Set `BACKLOG_WRITE=true/false`.
805
+
806
+ - If write mode, ask if they want to create labels:
807
+ - `product-driven-backlog` (purple) — product feature ideas
808
+ - `area:*` labels for each detected layer/area
809
+ - `enhancement`, `bug`, `tech-debt`
810
+
811
+ #### If JIRA
812
+
813
+ First, check if JIRA CLI is installed:
814
+
815
+ ```bash
816
+ command -v jira &> /dev/null
817
+ ```
818
+
819
+ If not installed, offer to install it:
820
+
821
+ > JIRA CLI is not installed. There are several options:
822
+ >
823
+ > 1. **go-jira** (recommended) — lightweight CLI
824
+ > - macOS: `brew install go-jira`
825
+ > - Linux/other: `go install github.com/go-jira/jira/cmd/jira@latest`
826
+ > 2. **Atlassian CLI** — official but heavier
827
+ > - `npm install -g @atlassian/cli`
828
+ > 3. **Skip CLI, use REST API** — no CLI needed, uses `curl` with API token
829
+ >
830
+ > Which option? (1/2/3)
831
+
832
+ If the user chooses option 1 or 2, run the install command. If option 3, proceed with REST API mode.
833
+
834
+ Then ask for JIRA configuration:
835
+
836
+ > To connect to JIRA, I need:
837
+ >
838
+ > 1. **JIRA base URL** (e.g., `https://your-company.atlassian.net`)
839
+ > 2. **Project key** (e.g., `PROJ`, `DECK`, `MYAPP`)
840
+ > 3. **Authentication method**:
841
+ > - **JIRA CLI** (`jira` command) — if already configured
842
+ > - **API token** — stored in `.env` as `JIRA_API_TOKEN` and `JIRA_USER_EMAIL`
843
+ >
844
+ > Optional:
845
+ > - **Custom issue type** for backlog items (default: "Story")
846
+ > - **Custom fields** for VPC scores (or use labels/description)
847
+
848
+ Then ask about **access mode**:
849
+
850
+ ```
851
+ ## JIRA — Access Mode
852
+
853
+ How should we interact with JIRA?
854
+
855
+ 1. **Read & Write** — read tickets for implementation context, create new tickets
856
+ from product discovery, add a comment to tickets when implementation is complete
857
+ 2. **Read only** — read tickets for implementation context, but never create or
858
+ modify tickets. Product discovery will propose ideas as output only. After
859
+ implementation, the pipeline will show what to update manually but won't
860
+ touch JIRA.
861
+ ```
862
+
863
+ Set `BACKLOG_WRITE=true/false`.
864
+
865
+ <!-- no separate template — this file IS the source (install.sh copies commands/setup.md directly) -->
866
+
867
+ #### Project Label
868
+
869
+ After the access mode selection, ask:
870
+
871
+ > **Project Label (optional but recommended)**
872
+ >
873
+ > JIRA teams often tag all tickets for a product with a project label
874
+ > (e.g., `PROJECT-specrails`, `PLATFORM`, `MOBILE`). This label is applied
875
+ > to every ticket the backlog pipeline creates — making it easy to filter all
876
+ > AI-generated backlog items across JIRA.
877
+ >
878
+ > Enter a project label, or press Enter to skip:
879
+
880
+ If the user enters a label: set `PROJECT_LABEL=<value>`.
881
+ If the user skips: set `PROJECT_LABEL=""`.
882
+
883
+ #### Epic Link Field
884
+
885
+ Ask:
886
+
887
+ > **Epic Link Field (optional — advanced)**
888
+ >
889
+ > JIRA Next-Gen (team-managed) projects link stories to epics using the `parent`
890
+ > field. JIRA Classic (company-managed) projects use `Epic Link` (customfield_10014).
891
+ >
892
+ > Which does your project use?
893
+ > 1. `parent` — Next-Gen / team-managed **(default)**
894
+ > 2. `customfield_10014` — Classic / company-managed
895
+
896
+ Set `EPIC_LINK_FIELD` to `parent` or `customfield_10014`. Default: `parent`.
897
+
898
+ Store the full configuration in `.claude/backlog-config.json`:
899
+ ```json
900
+ {
901
+ "provider": "jira",
902
+ "write_access": true,
903
+ "jira_base_url": "https://your-company.atlassian.net",
904
+ "jira_project_key": "PROJ",
905
+ "issue_type": "Story",
906
+ "auth_method": "api_token",
907
+ "cli_installed": true,
908
+ "project_label": "<PROJECT_LABEL or empty string>",
909
+ "epic_link_field": "parent",
910
+ "epic_mapping": {}
911
+ }
912
+ ```
913
+
914
+ #### If None
915
+
916
+ - Skip `/specrails:product-backlog` and `/specrails:update-product-driven-backlog` commands.
917
+ - The `/specrails:implement` command will still work with text descriptions.
918
+
919
+ ### 3.3 Git & shipping workflow
920
+
921
+ Ask how the user wants to handle git operations after implementation:
922
+
923
+ ```
924
+ ## Git & Shipping
925
+
926
+ After implementation is complete, how should we handle shipping?
927
+
928
+ 1. **Automatic** (default) — create branch, commit changes, push, and open a PR
929
+ (requires GitHub CLI for PRs, otherwise prints a compare URL)
930
+ 2. **Manual** — stop after implementation and review. You handle branching,
931
+ committing, and PR creation yourself. The pipeline will show a summary
932
+ of all changes but won't touch git.
933
+ ```
934
+
935
+ Set `GIT_AUTO=true/false`.
936
+
937
+ If automatic, also check if `gh` is authenticated (for PR creation). If not, warn that PRs will be skipped but commits and push will still work.
938
+
939
+ ### 3.4 Commands to install
940
+
941
+ ```
942
+ ## Command Selection
943
+
944
+ | Command | Purpose | Requires |
945
+ |---------|---------|----------|
946
+ | /specrails:implement | Full pipeline: sr-architect → sr-developer → sr-reviewer → ship | sr-architect + sr-developer + sr-reviewer |
947
+ | /specrails:batch-implement | Orchestrate multiple features in dependency-aware waves | sr-architect + sr-developer + sr-reviewer |
948
+ | /specrails:propose-spec | Interactively propose and refine a feature spec, then create a GitHub issue | GitHub CLI |
949
+ | /specrails:product-backlog | View prioritized backlog with VPC scores | sr-product-analyst + Backlog provider |
950
+ | /specrails:update-product-driven-backlog | Generate new feature ideas via product discovery | sr-product-manager + Backlog provider |
951
+ | /specrails:compat-check | Snapshot API surface and detect breaking changes | None |
952
+ | /specrails:refactor-recommender | Scan for refactoring opportunities ranked by impact/effort | None |
953
+ | /specrails:why | Search past architectural decisions from agent memory | None |
954
+
955
+ [All] [Custom selection]
956
+ ```
957
+
958
+ Note: If `BACKLOG_PROVIDER=none`, the backlog commands are not offered.
959
+
960
+ ### 3.5 Confirm configuration
961
+
962
+ Display the full configuration summary including access modes:
963
+
964
+ ```
965
+ ## Configuration Summary
966
+
967
+ | Setting | Value |
968
+ |---------|-------|
969
+ | Backlog provider | GitHub Issues / JIRA / None |
970
+ | Backlog access | Read & Write / Read only |
971
+ | Project label (JIRA) | PROJECT-specrails / (none) |
972
+ | Epic link field (JIRA) | parent / customfield_10014 |
973
+ | Git workflow | Automatic / Manual |
974
+ | Agents | [list] |
975
+ | Commands | [list] |
976
+ | Personas | [count] personas |
977
+
978
+ Note: The `Project label (JIRA)` and `Epic link field (JIRA)` rows are only shown when `BACKLOG_PROVIDER=jira`.
979
+
980
+ [Confirm] [Modify]
981
+ ```
982
+
983
+ Wait for final confirmation.
984
+
985
+ ---
986
+
987
+ ## Phase 4: Generate Files
988
+
989
+ Read each template from `.claude/setup-templates/` and generate the final files adapted to this project. Use the codebase analysis from Phase 1, personas from Phase 2, and configuration from Phase 3.
990
+
991
+ **Provider detection (required before any file generation):** Read `$SPECRAILS_DIR/setup-templates/.provider-detection.json` to determine `cli_provider` (`"claude"` or `"codex"`) and `specrails_dir` (`.claude` or `.codex`). All output paths in Phase 4 use `$SPECRAILS_DIR` as the base directory. If the file is missing, fall back to `cli_provider = "claude"` and `specrails_dir = ".claude"`.
992
+
993
+ ### 4.1 Generate agents
994
+
995
+ For each selected agent, read the template and generate the adapted version.
996
+
997
+ **Template → Output mapping:**
998
+
999
+ **If `cli_provider == "claude"` (default):**
1000
+ - `setup-templates/agents/sr-architect.md` → `.claude/agents/sr-architect.md`
1001
+ - `setup-templates/agents/sr-developer.md` → `.claude/agents/sr-developer.md`
1002
+ - `setup-templates/agents/sr-reviewer.md` → `.claude/agents/sr-reviewer.md`
1003
+ - `setup-templates/agents/sr-test-writer.md` → `.claude/agents/sr-test-writer.md`
1004
+ - `setup-templates/agents/sr-security-reviewer.md` → `.claude/agents/sr-security-reviewer.md`
1005
+ - `setup-templates/agents/sr-product-manager.md` → `.claude/agents/sr-product-manager.md`
1006
+ - `setup-templates/agents/sr-product-analyst.md` → `.claude/agents/sr-product-analyst.md`
1007
+ - `setup-templates/agents/sr-backend-developer.md` → `.claude/agents/sr-backend-developer.md` (if backend layer)
1008
+ - `setup-templates/agents/sr-frontend-developer.md` → `.claude/agents/sr-frontend-developer.md` (if frontend layer)
1009
+
1010
+ **If `cli_provider == "codex"`:**
1011
+ - `setup-templates/agents/sr-architect.md` → `.codex/agents/sr-architect.toml`
1012
+ - `setup-templates/agents/sr-developer.md` → `.codex/agents/sr-developer.toml`
1013
+ - `setup-templates/agents/sr-reviewer.md` → `.codex/agents/sr-reviewer.toml`
1014
+ - `setup-templates/agents/sr-test-writer.md` → `.codex/agents/sr-test-writer.toml`
1015
+ - `setup-templates/agents/sr-security-reviewer.md` → `.codex/agents/sr-security-reviewer.toml`
1016
+ - `setup-templates/agents/sr-product-manager.md` → `.codex/agents/sr-product-manager.toml`
1017
+ - `setup-templates/agents/sr-product-analyst.md` → `.codex/agents/sr-product-analyst.toml`
1018
+ - `setup-templates/agents/sr-backend-developer.md` → `.codex/agents/sr-backend-developer.toml` (if backend layer)
1019
+ - `setup-templates/agents/sr-frontend-developer.md` → `.codex/agents/sr-frontend-developer.toml` (if frontend layer)
1020
+
1021
+ When generating each agent:
1022
+ 1. Read the template
1023
+ 2. Replace all `{{PLACEHOLDER}}` values with project-specific content:
1024
+ - `{{PROJECT_NAME}}` → project name
1025
+ - `{{ARCHITECTURE_DIAGRAM}}` → detected architecture
1026
+ - `{{LAYER_TAGS}}` → detected layer tags (e.g., `[backend]`, `[frontend]`, `[api]`, `[mobile]`)
1027
+ - `{{CI_COMMANDS_BACKEND}}` → backend CI commands from Phase 1
1028
+ - `{{CI_COMMANDS_FRONTEND}}` → frontend CI commands from Phase 1
1029
+ - `{{LAYER_CONVENTIONS}}` → detected conventions per layer
1030
+ - `{{PERSONA_NAMES}}` → names from generated personas
1031
+ - `{{PERSONA_FILES}}` → paths to persona files
1032
+ - `{{DOMAIN_EXPERTISE}}` → domain knowledge from Phase 2 research
1033
+ - `{{COMPETITIVE_LANDSCAPE}}` → competitors discovered in Phase 2
1034
+ - `{{KEY_FILE_PATHS}}` → important file paths detected in Phase 1
1035
+ - `{{WARNINGS}}` → project-specific warnings (from existing CLAUDE.md or detected)
1036
+ - `{{MEMORY_PATH}}` → agent memory directory path (e.g., `$SPECRAILS_DIR/agent-memory/sr-<agent-name>/`)
1037
+ - `{{TECH_EXPERTISE}}` → detected languages, frameworks, and test frameworks from Phase 1
1038
+ - `{{LAYER_CLAUDE_MD_PATHS}}` → comma-separated paths to per-layer rules files (e.g., `$SPECRAILS_DIR/rules/backend.md`, `$SPECRAILS_DIR/rules/frontend.md`)
1039
+ - `{{SECURITY_EXEMPTIONS_PATH}}` → `$SPECRAILS_DIR/security-exemptions.yaml`
1040
+ 3. Write the final file in the format for the active provider:
1041
+
1042
+ **If `cli_provider == "claude"`:** Write as Markdown with YAML frontmatter — the template file as-is (frontmatter preserved).
1043
+
1044
+ **If `cli_provider == "codex"`:** Convert to TOML format:
1045
+ - Extract YAML frontmatter fields: `name`, `description`, `model`
1046
+ - Extract the body content (everything after the closing `---` of the frontmatter)
1047
+ - Map the `model` field: `sonnet` → `codex-mini-latest`, `opus` → `o3`, `haiku` → `codex-mini-latest`
1048
+ - Write a `.toml` file with this structure:
1049
+ ```toml
1050
+ name = "<name from frontmatter>"
1051
+ description = "<description from frontmatter, escaped for TOML>"
1052
+ model = "codex-mini-latest"
1053
+ prompt = """
1054
+ <body content after placeholder substitution>
1055
+ """
1056
+ ```
1057
+
1058
+ ### 4.2 Generate personas
1059
+
1060
+ If IS_OSS=true:
1061
+ 1. Copy `setup-templates/personas/the-maintainer.md` to `$SPECRAILS_DIR/agents/personas/the-maintainer.md`
1062
+ 2. Log: "Maintainer persona included"
1063
+ 3. Set MAINTAINER_INCLUDED=true for use in template substitution
1064
+ 4. Set `{{MAINTAINER_PERSONA_LINE}}` = `- \`$SPECRAILS_DIR/agents/personas/the-maintainer.md\` — "Kai" the Maintainer (open-source maintainer)`
1065
+ 5. Increment `{{PERSONA_COUNT}}` by 1 to account for the Maintainer
1066
+
1067
+ If IS_OSS=false:
1068
+ - Set `{{MAINTAINER_PERSONA_LINE}}` = *(empty string)*
1069
+
1070
+ Then for each user-defined VPC persona from Phase 2.3:
1071
+
1072
+ Write each persona to `$SPECRAILS_DIR/agents/personas/`:
1073
+ - Use the VPC personas generated in Phase 2
1074
+ - File naming: kebab-case of persona nickname (e.g., `the-developer.md`, `the-admin.md`)
1075
+
1076
+ ### 4.3 Generate commands / skills
1077
+
1078
+ For each selected command, read the template and adapt.
1079
+
1080
+ **If `cli_provider == "claude"` (default):**
1081
+ - `setup-templates/commands/specrails/implement.md` → `.claude/commands/specrails/implement.md`
1082
+ - `setup-templates/commands/specrails/batch-implement.md` → `.claude/commands/specrails/batch-implement.md`
1083
+ - `setup-templates/commands/specrails/propose-spec.md` → `.claude/commands/specrails/propose-spec.md`
1084
+ - `setup-templates/commands/specrails/product-backlog.md` → `.claude/commands/specrails/product-backlog.md` (if `BACKLOG_PROVIDER != none`)
1085
+ - `setup-templates/commands/specrails/update-product-driven-backlog.md` → `.claude/commands/specrails/update-product-driven-backlog.md` (if `BACKLOG_PROVIDER != none`)
1086
+ - `setup-templates/commands/specrails/compat-check.md` → `.claude/commands/specrails/compat-check.md`
1087
+ - `setup-templates/commands/specrails/refactor-recommender.md` → `.claude/commands/specrails/refactor-recommender.md`
1088
+ - `setup-templates/commands/specrails/why.md` → `.claude/commands/specrails/why.md`
1089
+
1090
+ **If `cli_provider == "codex"`:**
1091
+ - `setup-templates/skills/sr-implement/SKILL.md` → `.agents/skills/sr-implement/SKILL.md`
1092
+ - `setup-templates/skills/sr-batch-implement/SKILL.md` → `.agents/skills/sr-batch-implement/SKILL.md`
1093
+ - `setup-templates/commands/specrails/propose-spec.md` → `.agents/skills/sr-propose-spec/SKILL.md` (wrap with YAML frontmatter if no skill template exists)
1094
+ - `setup-templates/commands/specrails/product-backlog.md` → `.agents/skills/sr-product-backlog/SKILL.md` (if `BACKLOG_PROVIDER != none`; wrap with frontmatter)
1095
+ - `setup-templates/commands/specrails/update-product-driven-backlog.md` → `.agents/skills/sr-update-product-driven-backlog/SKILL.md` (if `BACKLOG_PROVIDER != none`; wrap with frontmatter)
1096
+ - `setup-templates/skills/sr-compat-check/SKILL.md` → `.agents/skills/sr-compat-check/SKILL.md`
1097
+ - `setup-templates/skills/sr-refactor-recommender/SKILL.md` → `.agents/skills/sr-refactor-recommender/SKILL.md`
1098
+ - `setup-templates/skills/sr-why/SKILL.md` → `.agents/skills/sr-why/SKILL.md`
1099
+
1100
+ **Codex skill frontmatter wrapping:** When a dedicated skill template does not exist in `setup-templates/skills/` for a command, generate the `SKILL.md` by prepending YAML frontmatter to the command content:
1101
+ ```yaml
1102
+ ---
1103
+ name: sr-<name>
1104
+ description: "<one-line description from the command's first heading>"
1105
+ license: MIT
1106
+ compatibility: "Requires git."
1107
+ metadata:
1108
+ author: specrails
1109
+ version: "1.0"
1110
+ ---
1111
+ ```
1112
+
1113
+ For both providers, create the output directory before writing (`mkdir -p` for `.claude/commands/specrails/` or `.agents/skills/sr-<name>/`).
1114
+
1115
+ Adapt:
1116
+ - CI commands to match detected stack
1117
+ - **Persona references** to match generated personas (see substitution rules below)
1118
+ - File paths to match project structure
1119
+ - Layer tags to match detected layers
1120
+ - **Backlog provider commands** based on `BACKLOG_PROVIDER`:
1121
+
1122
+ #### Backlog command persona placeholder substitution
1123
+
1124
+ When adapting `update-product-driven-backlog.md` and `product-backlog.md`, substitute the persona placeholders based on the full persona set (user-generated personas + Maintainer if `IS_OSS=true`):
1125
+
1126
+ | Placeholder | Substitution rule |
1127
+ |-------------|------------------|
1128
+ | `{{PERSONA_FILE_READ_LIST}}` | One bullet per persona file: `- Read \`$SPECRAILS_DIR/agents/personas/{name}.md\`` |
1129
+ | `{{PERSONA_SCORE_HEADERS}}` | Column headers for each persona nickname: e.g., `Alex \| Sara \| Kai` |
1130
+ | `{{PERSONA_SCORE_SEPARATORS}}` | One `------` separator per persona column |
1131
+ | `{{PERSONA_FIT_FORMAT}}` | Inline score display: e.g., `Alex: X/5, Sara: X/5, Kai: X/5` |
1132
+ | `{{PERSONA_VPC_SECTIONS}}` | One VPC section block per persona (see format below) |
1133
+ | `{{MAX_SCORE}}` | Total max score = 5 × number of personas (e.g., `15` for 3 personas) |
1134
+ | `{{PERSONA_NAMES_WITH_ROLES}}` | Comma-separated: e.g., `Alex (Lead Dev), Sara (Product Founder), Kai (OSS Maintainer)` |
1135
+
1136
+ **`{{PERSONA_VPC_SECTIONS}}` format** — repeat for each persona in order:
1137
+ ```
1138
+ ### "{Nickname}" — The {Role} (X/5)
1139
+ - **Jobs addressed**: {list}
1140
+ - **Pains relieved**: {list with severity}
1141
+ - **Gains created**: {list with impact}
1142
+ ```
1143
+
1144
+ **Kai inclusion rule**: When `IS_OSS=true`, Kai (`sr-the-maintainer.md`) is always the last entry in persona lists and the rightmost column in scoring tables. Kai uses the evaluation criteria defined in `.claude/agents/personas/sr-the-maintainer.md` — features score high (4-5/5) for Kai when they reduce async review burden, enforce project-specific conventions, or automate release/dependency coordination; features score low (0-1/5) when they add configuration complexity or require paid tiers.
1145
+
1146
+ **When `IS_OSS=false`**: All Kai-related persona references are omitted. `{{MAX_SCORE}}` reduces by 5. Tables and inline scores contain only user-generated personas.
1147
+
1148
+ #### Local Tickets (`BACKLOG_PROVIDER=local`)
1149
+
1150
+ For the local provider, backlog placeholders resolve to **inline file-operation instructions** embedded in the generated command markdown — not shell commands. Agents execute these by reading/writing `$SPECRAILS_DIR/local-tickets.json` directly using their file tools.
1151
+
1152
+ All write operations must follow the **advisory file locking protocol** defined in Phase 3.2. Always increment `revision` and update `last_updated` on every write.
1153
+
1154
+ | Placeholder | Substituted value |
1155
+ |-------------|-------------------|
1156
+ | `{{BACKLOG_PROVIDER_NAME}}` | `Local Tickets` |
1157
+ | `{{BACKLOG_PREFLIGHT}}` | `[[ -f "$SPECRAILS_DIR/local-tickets.json" ]] && echo "Local tickets storage: OK" \|\| echo "WARNING: $SPECRAILS_DIR/local-tickets.json not found — run /specrails:setup to initialize"` |
1158
+ | `{{BACKLOG_FETCH_CMD}}` | Read `$SPECRAILS_DIR/local-tickets.json`. Parse the `tickets` map and return all entries where `status` is `"todo"` or `"in_progress"`. |
1159
+ | `{{BACKLOG_FETCH_ALL_CMD}}` | Read `$SPECRAILS_DIR/local-tickets.json`. Parse the `tickets` map and return all entries regardless of status. |
1160
+ | `{{BACKLOG_FETCH_CLOSED_CMD}}` | Read `$SPECRAILS_DIR/local-tickets.json`. Parse the `tickets` map and return all entries where `status` is `"done"` or `"cancelled"`. |
1161
+ | `{{BACKLOG_VIEW_CMD}}` | Read `$SPECRAILS_DIR/local-tickets.json`. Parse JSON and return the full ticket object at `tickets["{id}"]`, or an error if not found. |
1162
+ | `{{BACKLOG_CREATE_CMD}}` | Write to `$SPECRAILS_DIR/local-tickets.json` using the advisory locking protocol: acquire lock → read file → set `id = next_id`, increment `next_id`, set all ticket fields, set `created_at` and `updated_at` to now, bump `revision`, update `last_updated` → write → release lock. |
1163
+ | `{{BACKLOG_UPDATE_CMD}}` | Write to `$SPECRAILS_DIR/local-tickets.json` using the advisory locking protocol: acquire lock → read file → update fields in `tickets["{id}"]`, set `updated_at` to now, bump `revision`, update `last_updated` → write → release lock. |
1164
+ | `{{BACKLOG_DELETE_CMD}}` | Write to `$SPECRAILS_DIR/local-tickets.json` using the advisory locking protocol: acquire lock → read file → delete `tickets["{id}"]`, bump `revision`, update `last_updated` → write → release lock. |
1165
+ | `{{BACKLOG_COMMENT_CMD}}` | Write to `$SPECRAILS_DIR/local-tickets.json` using the advisory locking protocol: acquire lock → read file → append `{"author": "<agent-name>", "body": "<comment>", "created_at": "<ISO-8601>"}` to `tickets["{id}"].comments` (create the array if absent), set `updated_at` to now, bump `revision`, update `last_updated` → write → release lock. |
1166
+ | `{{BACKLOG_PARTIAL_COMMENT_CMD}}` | Same as `{{BACKLOG_COMMENT_CMD}}` but append `{"author": "<agent-name>", "body": "<comment>", "type": "progress", "created_at": "<ISO-8601>"}`. |
1167
+ | `{{BACKLOG_INIT_LABELS_CMD}}` | No label initialization required. Local tickets use freeform label strings. Standard label conventions: `area:frontend`, `area:backend`, `area:api`, `effort:low`, `effort:medium`, `effort:high`. |
1168
+
1169
+ #### GitHub Issues (`BACKLOG_PROVIDER=github`)
1170
+ - Issue fetch: `gh issue list --label "product-driven-backlog" --state open --limit 100 --json number,title,labels,body`
1171
+ - Issue create: `gh issue create --title "..." --label "..." --body "..."`
1172
+ - Issue view: `gh issue view {number} --json number,title,labels,body`
1173
+ - Issue label names to match project areas
1174
+ - Pre-flight check: `gh auth status`
1175
+
1176
+ #### JIRA (`BACKLOG_PROVIDER=jira`)
1177
+ - Issue fetch: `jira issue list --project {{JIRA_PROJECT_KEY}} --type Story --label product-backlog --status "To Do" --plain` or equivalent JIRA REST API call via curl:
1178
+ ```bash
1179
+ curl -s -u "$JIRA_USER_EMAIL:$JIRA_API_TOKEN" \
1180
+ "{{JIRA_BASE_URL}}/rest/api/3/search?jql=project={{JIRA_PROJECT_KEY}} AND labels=product-backlog AND status='To Do'&fields=summary,description,labels,priority"
1181
+ ```
1182
+ - Issue create: `jira issue create --project {{JIRA_PROJECT_KEY}} --type Story --summary "..." --label product-backlog --description "..."` or equivalent REST API call
1183
+ - Issue view: `jira issue view {key}` or REST API
1184
+ - VPC scores stored in the issue description body (same markdown format, parsed from description)
1185
+ - Pre-flight check: `jira me` or test API connectivity
1186
+ - Store JIRA config in `$SPECRAILS_DIR/backlog-config.json`:
1187
+ ```json
1188
+ {
1189
+ "provider": "jira",
1190
+ "jira_base_url": "https://your-company.atlassian.net",
1191
+ "jira_project_key": "PROJ",
1192
+ "issue_type": "Story",
1193
+ "auth_method": "api_token"
1194
+ }
1195
+ ```
1196
+
1197
+ The command templates use `{{BACKLOG_FETCH_CMD}}`, `{{BACKLOG_CREATE_CMD}}`, `{{BACKLOG_VIEW_CMD}}`, `{{BACKLOG_PREFLIGHT}}`, and related placeholders that get filled with the provider-specific commands (for `local`) or instructions (for `github`, `jira`). The `{{BACKLOG_PROVIDER_NAME}}` placeholder is substituted with a human-readable provider label in all three cases.
1198
+
1199
+ ### 4.4 Generate rules
1200
+
1201
+ For each detected layer, read the layer rule template and generate a layer-specific rules file:
1202
+ - `setup-templates/rules/layer.md` → `$SPECRAILS_DIR/rules/{layer-name}.md`
1203
+
1204
+ Each rule file must:
1205
+ - Have the correct `paths:` frontmatter matching the layer's directory
1206
+ - Contain conventions specific to that layer (from Phase 1 analysis)
1207
+ - Reference actual file paths and patterns from the codebase
1208
+
1209
+ ### 4.5 Generate root instructions file
1210
+
1211
+ **If `cli_provider == "claude"`:** If no `CLAUDE.md` exists, generate one from the template. If one already exists, **merge** — add the agent workflow sections without removing existing content.
1212
+
1213
+ **If `cli_provider == "codex"`:** If no `AGENTS.md` exists, generate one from the template. If one already exists, **merge** — add the agent workflow sections without removing existing content.
1214
+
1215
+ ### 4.6 Generate settings
1216
+
1217
+ Read `.claude/setup-templates/.provider-detection.json` (written by `install.sh`) to determine `cli_provider` (`"claude"` or `"codex"`).
1218
+
1219
+ **If `cli_provider == "claude"` (default):**
1220
+
1221
+ Create or merge `.claude/settings.json` with permissions for:
1222
+ - All detected CI commands
1223
+ - Git operations
1224
+ - OpenSpec CLI (if installed)
1225
+ - GitHub CLI (if available)
1226
+ - Language-specific tools (python, npm, cargo, go, etc.)
1227
+
1228
+ **If `cli_provider == "codex"`:**
1229
+
1230
+ 1. Read `setup-templates/settings/codex-config.toml`. Write it to `.codex/config.toml` as-is (no substitutions needed — the TOML is static).
1231
+
1232
+ 2. Read `setup-templates/settings/codex-rules.star`. Replace `{{CODEX_SHELL_RULES}}` with Starlark `prefix_rule(...)` lines for each detected tool allowance:
1233
+
1234
+ | Detected tool/command | Starlark rule |
1235
+ |----------------------|---------------|
1236
+ | OpenSpec CLI (`openspec`) | `prefix_rule(pattern=["openspec"], decision="allow")` |
1237
+ | Python (`python`, `pip`) | `prefix_rule(pattern=["python"], decision="allow")`<br>`prefix_rule(pattern=["pip"], decision="allow")` |
1238
+ | npm (`npm`) | `prefix_rule(pattern=["npm"], decision="allow")` |
1239
+ | Cargo (`cargo`) | `prefix_rule(pattern=["cargo"], decision="allow")` |
1240
+ | Go (`go`) | `prefix_rule(pattern=["go"], decision="allow")` |
1241
+ | Any detected CI command | `prefix_rule(pattern=["<cmd>"], decision="allow")` |
1242
+
1243
+ Write the rendered file to `.codex/rules/default.rules`.
1244
+
1245
+ ```bash
1246
+ mkdir -p .codex/rules
1247
+ ```
1248
+
1249
+ If `cli_provider` cannot be determined (file missing), fall back to `"claude"` behavior.
1250
+
1251
+ ### 4.7 Initialize agent memory
1252
+
1253
+ Create memory directories for each installed agent using the provider-aware base directory:
1254
+
1255
+ ```bash
1256
+ mkdir -p $SPECRAILS_DIR/agent-memory/sr-{agent-name}/
1257
+ ```
1258
+
1259
+ Each gets an empty `MEMORY.md` that will be populated during usage.
1260
+
1261
+ ---
1262
+
1263
+ ## Phase 5: Cleanup & Summary
1264
+
1265
+ ### 5.1 Remove all scaffolding artifacts
1266
+
1267
+ The setup process installed temporary files that are only needed during installation. Remove them all now that the final files have been generated.
1268
+
1269
+ ```bash
1270
+ # 1. Remove setup templates (used as structural references during generation)
1271
+ rm -rf .claude/setup-templates/
1272
+
1273
+ # 2. Remove the /specrails:setup command itself — it's a one-time installer, not a permanent command
1274
+ rm -f .claude/commands/setup.md
1275
+
1276
+ # 3. Remove the specrails/ directory from the repo if it exists at the root
1277
+ # (it was only needed for install.sh and templates — everything is now in .claude/)
1278
+ # NOTE: Only remove if it's inside this repo. Ask the user if unsure.
1279
+ ```
1280
+
1281
+ **What gets removed:**
1282
+ | Artifact | Why |
1283
+ |----------|-----|
1284
+ | `.claude/setup-templates/` | Temporary — templates already rendered into final files |
1285
+ | `.claude/commands/setup.md` | One-time installer — running it again would overwrite customized agents |
1286
+
1287
+ **What to do with `specrails/`:**
1288
+
1289
+ The `specrails/` directory should NOT be committed to the target repo — it's an installer tool, not part of the project. Always add it to `.gitignore`:
1290
+
1291
+ ```bash
1292
+ # Add specrails/ to .gitignore if not already there
1293
+ if ! grep -q '^specrails/' .gitignore 2>/dev/null; then
1294
+ echo '' >> .gitignore
1295
+ echo '# specrails installer (one-time setup tool, not part of the project)' >> .gitignore
1296
+ echo 'specrails/' >> .gitignore
1297
+ fi
1298
+ ```
1299
+
1300
+ Then ask the user:
1301
+
1302
+ > `specrails/` has been added to `.gitignore`. Do you also want to delete it?
1303
+ >
1304
+ > 1. **Keep it** (default) — stays locally in case you want to re-run setup or install in other repos
1305
+ > 2. **Delete it** — everything is installed, you don't need it anymore
1306
+
1307
+ Apply the user's choice.
1308
+
1309
+ ### 5.2 Verify clean state
1310
+
1311
+ After cleanup, verify that only the intended files remain:
1312
+
1313
+ ```bash
1314
+ # These should exist (the actual system) — use $SPECRAILS_DIR from .provider-detection.json:
1315
+ # If cli_provider == "claude":
1316
+ ls .claude/agents/sr-*.md
1317
+ ls .claude/agents/personas/*.md
1318
+ ls .claude/commands/specrails/*.md
1319
+ ls .claude/rules/*.md
1320
+ ls .claude/agent-memory/
1321
+
1322
+ # If cli_provider == "codex":
1323
+ ls .codex/agents/sr-*.toml
1324
+ ls .codex/agents/personas/*.md
1325
+ ls .agents/skills/sr-*/SKILL.md
1326
+ ls .codex/rules/*.md
1327
+ ls .codex/agent-memory/
1328
+
1329
+ # These should NOT exist (scaffolding):
1330
+ # $SPECRAILS_DIR/setup-templates/ — GONE
1331
+ # If cli_provider == "claude": $SPECRAILS_DIR/commands/setup.md — GONE
1332
+ # If cli_provider == "codex": .agents/skills/setup/ — GONE (installer scaffold, not a generated sr-skill)
1333
+ ```
1334
+
1335
+ If any scaffolding artifact remains, remove it.
1336
+
1337
+ ### 5.3 Summary
1338
+
1339
+ Display the complete installation summary:
1340
+
1341
+ ```
1342
+ ## Setup Complete
1343
+
1344
+ ### Agents Installed
1345
+ | Agent | File | Model |
1346
+ |-------|------|-------|
1347
+ [If cli_provider == "claude":]
1348
+ | sr-architect | .claude/agents/sr-architect.md | Sonnet |
1349
+ | sr-developer | .claude/agents/sr-developer.md | Sonnet |
1350
+ | sr-reviewer | .claude/agents/sr-reviewer.md | Sonnet |
1351
+ | sr-test-writer | .claude/agents/sr-test-writer.md | Sonnet |
1352
+ | sr-security-reviewer | .claude/agents/sr-security-reviewer.md | Sonnet |
1353
+ | sr-product-manager | .claude/agents/sr-product-manager.md | Opus |
1354
+ [If cli_provider == "codex":]
1355
+ | sr-architect | .codex/agents/sr-architect.toml | codex-mini-latest |
1356
+ | sr-developer | .codex/agents/sr-developer.toml | codex-mini-latest |
1357
+ | sr-reviewer | .codex/agents/sr-reviewer.toml | codex-mini-latest |
1358
+ | sr-test-writer | .codex/agents/sr-test-writer.toml | codex-mini-latest |
1359
+ | sr-security-reviewer | .codex/agents/sr-security-reviewer.toml | codex-mini-latest |
1360
+ | sr-product-manager | .codex/agents/sr-product-manager.toml | o3 |
1361
+
1362
+ ### Personas Created
1363
+ | Persona | File | Source |
1364
+ |---------|------|--------|
1365
+ [If IS_OSS=true:]
1366
+ | "Kai" — The Maintainer | $SPECRAILS_DIR/agents/personas/sr-the-maintainer.md | Auto-included (OSS) |
1367
+ [For each user-generated persona:]
1368
+ | "[Name]" — The [Role] | $SPECRAILS_DIR/agents/personas/[name].md | Generated |
1369
+
1370
+ ### Commands / Skills Installed
1371
+ [If cli_provider == "claude":]
1372
+ | Command | File |
1373
+ |---------|------|
1374
+ | /specrails:implement | .claude/commands/specrails/implement.md |
1375
+ | /specrails:batch-implement | .claude/commands/specrails/batch-implement.md |
1376
+ | /specrails:propose-spec | .claude/commands/specrails/propose-spec.md |
1377
+ | /specrails:product-backlog | .claude/commands/specrails/product-backlog.md |
1378
+ | /specrails:update-product-driven-backlog | .claude/commands/specrails/update-product-driven-backlog.md |
1379
+ | /specrails:compat-check | .claude/commands/specrails/compat-check.md |
1380
+ | /specrails:refactor-recommender | .claude/commands/specrails/refactor-recommender.md |
1381
+ | /specrails:why | .claude/commands/specrails/why.md |
1382
+ [If cli_provider == "codex":]
1383
+ | Skill | File |
1384
+ |-------|------|
1385
+ | $sr-implement | .agents/skills/sr-implement/SKILL.md |
1386
+ | $sr-batch-implement | .agents/skills/sr-batch-implement/SKILL.md |
1387
+ | $sr-propose-spec | .agents/skills/sr-propose-spec/SKILL.md |
1388
+ | $sr-product-backlog | .agents/skills/sr-product-backlog/SKILL.md |
1389
+ | $sr-update-product-driven-backlog | .agents/skills/sr-update-product-driven-backlog/SKILL.md |
1390
+ | $sr-compat-check | .agents/skills/sr-compat-check/SKILL.md |
1391
+ | $sr-refactor-recommender | .agents/skills/sr-refactor-recommender/SKILL.md |
1392
+ | $sr-why | .agents/skills/sr-why/SKILL.md |
1393
+
1394
+ Note: Only commands/skills selected during setup are shown. Backlog commands are excluded if no backlog provider was configured.
1395
+
1396
+ ### Rules Created
1397
+ | Layer | File |
1398
+ |-------|------|
1399
+ | Backend | $SPECRAILS_DIR/rules/backend.md |
1400
+ | Frontend | $SPECRAILS_DIR/rules/frontend.md |
1401
+
1402
+ ### Scaffolding Removed
1403
+ | Artifact | Status |
1404
+ |----------|--------|
1405
+ | $SPECRAILS_DIR/setup-templates/ | Deleted |
1406
+ [If cli_provider == "claude":] | .claude/commands/setup.md | Deleted |
1407
+ [If cli_provider == "codex":] | .agents/skills/setup/ | Deleted |
1408
+ | specrails/ | [User's choice] |
1409
+
1410
+ ### Next Steps
1411
+ [If cli_provider == "claude":]
1412
+ 1. Review the generated files in .claude/
1413
+ 2. Run `/specrails:product-backlog` to see your backlog (if GitHub Issues exist)
1414
+ 3. Run `/specrails:update-product-driven-backlog` to generate feature ideas
1415
+ 4. Run `/specrails:implement #issue-number` to implement a feature
1416
+ 5. Commit the .claude/ directory to version control
1417
+ [If cli_provider == "codex":]
1418
+ 1. Review the generated files in .codex/ and .agents/skills/
1419
+ 2. Run `$sr-product-backlog` to see your backlog (if GitHub Issues exist)
1420
+ 3. Run `$sr-update-product-driven-backlog` to generate feature ideas
1421
+ 4. Run `$sr-implement #issue-number` to implement a feature
1422
+ 5. Commit the .codex/ and .agents/ directories to version control
1423
+
1424
+ ### Quick Start
1425
+ [If cli_provider == "claude":]
1426
+ - `/specrails:implement "describe a feature"` — implement something right now
1427
+ - `/specrails:product-backlog` — see prioritized feature ideas
1428
+ - `/specrails:update-product-driven-backlog` — discover new features using VPC
1429
+ [If cli_provider == "codex":]
1430
+ - `$sr-implement "describe a feature"` — implement something right now
1431
+ - `$sr-product-backlog` — see prioritized feature ideas
1432
+ - `$sr-update-product-driven-backlog` — discover new features using VPC
1433
+ ```
1434
+
1435
+ ## First Task Prompt (Full Wizard)
1436
+
1437
+ After displaying the setup complete summary above, detect the project type and output:
1438
+
1439
+ **New project** (no `package.json`, `Gemfile`, `pyproject.toml`, `go.mod`, or `pom.xml` in root):
1440
+ ```
1441
+ ✅ Setup complete.
1442
+
1443
+ Try your first spec:
1444
+ [If cli_provider == "claude":]
1445
+ > /specrails:product-backlog
1446
+ [If cli_provider == "codex":]
1447
+ > $sr-product-backlog
1448
+ ```
1449
+
1450
+ **Existing codebase** (one or more of the above files found in root):
1451
+ ```
1452
+ ✅ Setup complete.
1453
+
1454
+ Try your first spec:
1455
+ [If cli_provider == "claude":]
1456
+ > /specrails:refactor-recommender
1457
+ [If cli_provider == "codex":]
1458
+ > $sr-refactor-recommender
1459
+ ```
1460
+
1461
+ Then stop.