specrails 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/.claude/skills/openspec-apply-change/SKILL.md +156 -0
  2. package/.claude/skills/openspec-archive-change/SKILL.md +114 -0
  3. package/.claude/skills/openspec-bulk-archive-change/SKILL.md +246 -0
  4. package/.claude/skills/openspec-continue-change/SKILL.md +118 -0
  5. package/.claude/skills/openspec-explore/SKILL.md +290 -0
  6. package/.claude/skills/openspec-ff-change/SKILL.md +101 -0
  7. package/.claude/skills/openspec-new-change/SKILL.md +74 -0
  8. package/.claude/skills/openspec-onboard/SKILL.md +529 -0
  9. package/.claude/skills/openspec-sync-specs/SKILL.md +138 -0
  10. package/.claude/skills/openspec-verify-change/SKILL.md +168 -0
  11. package/README.md +226 -0
  12. package/VERSION +1 -0
  13. package/bin/specrails.js +41 -0
  14. package/commands/setup.md +851 -0
  15. package/install.sh +488 -0
  16. package/package.json +34 -0
  17. package/prompts/analyze-codebase.md +87 -0
  18. package/prompts/generate-personas.md +61 -0
  19. package/prompts/infer-conventions.md +72 -0
  20. package/templates/agents/sr-architect.md +194 -0
  21. package/templates/agents/sr-backend-developer.md +54 -0
  22. package/templates/agents/sr-backend-reviewer.md +139 -0
  23. package/templates/agents/sr-developer.md +146 -0
  24. package/templates/agents/sr-doc-sync.md +167 -0
  25. package/templates/agents/sr-frontend-developer.md +48 -0
  26. package/templates/agents/sr-frontend-reviewer.md +132 -0
  27. package/templates/agents/sr-product-analyst.md +36 -0
  28. package/templates/agents/sr-product-manager.md +148 -0
  29. package/templates/agents/sr-reviewer.md +265 -0
  30. package/templates/agents/sr-security-reviewer.md +178 -0
  31. package/templates/agents/sr-test-writer.md +163 -0
  32. package/templates/claude-md/root.md +50 -0
  33. package/templates/commands/sr/batch-implement.md +282 -0
  34. package/templates/commands/sr/compat-check.md +271 -0
  35. package/templates/commands/sr/health-check.md +396 -0
  36. package/templates/commands/sr/implement.md +972 -0
  37. package/templates/commands/sr/product-backlog.md +195 -0
  38. package/templates/commands/sr/refactor-recommender.md +169 -0
  39. package/templates/commands/sr/update-product-driven-backlog.md +272 -0
  40. package/templates/commands/sr/why.md +96 -0
  41. package/templates/personas/persona.md +43 -0
  42. package/templates/personas/the-maintainer.md +78 -0
  43. package/templates/rules/layer.md +8 -0
  44. package/templates/security/security-exemptions.yaml +20 -0
  45. package/templates/settings/confidence-config.json +17 -0
  46. package/templates/settings/settings.json +15 -0
  47. package/templates/web-manager/README.md +107 -0
  48. package/templates/web-manager/client/index.html +12 -0
  49. package/templates/web-manager/client/package-lock.json +1727 -0
  50. package/templates/web-manager/client/package.json +20 -0
  51. package/templates/web-manager/client/src/App.tsx +83 -0
  52. package/templates/web-manager/client/src/components/AgentActivity.tsx +19 -0
  53. package/templates/web-manager/client/src/components/CommandInput.tsx +81 -0
  54. package/templates/web-manager/client/src/components/LogStream.tsx +57 -0
  55. package/templates/web-manager/client/src/components/PipelineSidebar.tsx +65 -0
  56. package/templates/web-manager/client/src/components/SearchBox.tsx +34 -0
  57. package/templates/web-manager/client/src/hooks/usePipeline.ts +62 -0
  58. package/templates/web-manager/client/src/hooks/useWebSocket.ts +59 -0
  59. package/templates/web-manager/client/src/main.tsx +9 -0
  60. package/templates/web-manager/client/tsconfig.json +21 -0
  61. package/templates/web-manager/client/tsconfig.node.json +11 -0
  62. package/templates/web-manager/client/vite.config.ts +13 -0
  63. package/templates/web-manager/package-lock.json +3327 -0
  64. package/templates/web-manager/package.json +30 -0
  65. package/templates/web-manager/server/hooks.test.ts +196 -0
  66. package/templates/web-manager/server/hooks.ts +71 -0
  67. package/templates/web-manager/server/index.test.ts +186 -0
  68. package/templates/web-manager/server/index.ts +99 -0
  69. package/templates/web-manager/server/spawner.test.ts +319 -0
  70. package/templates/web-manager/server/spawner.ts +89 -0
  71. package/templates/web-manager/server/types.ts +46 -0
  72. package/templates/web-manager/tsconfig.json +14 -0
  73. package/templates/web-manager/vitest.config.ts +8 -0
  74. package/update.sh +877 -0
@@ -0,0 +1,851 @@
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 if `$ARGUMENTS` contains `--update`:
12
+ - If yes → execute **Update Mode** (below), then stop. Do NOT continue to the full setup wizard.
13
+ - If no → skip to **Phase 1** and execute the full setup wizard.
14
+
15
+ ---
16
+
17
+ ## Update Mode
18
+
19
+ 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.
20
+
21
+ ### Phase U1: Read Update Context
22
+
23
+ Read the following files to understand the current installation state:
24
+
25
+ 1. Read `.specrails-manifest.json` — contains agent template checksums from the last install/update. Structure:
26
+ ```json
27
+ {
28
+ "version": "0.2.0",
29
+ "installed_at": "2025-01-15T10:00:00Z",
30
+ "artifacts": {
31
+ "templates/agents/architect.md": "sha256:<checksum>",
32
+ "templates/agents/developer.md": "sha256:<checksum>",
33
+ "templates/agents/reviewer.md": "sha256:<checksum>"
34
+ }
35
+ }
36
+ ```
37
+ If this file does not exist, inform the user:
38
+ > "No `.specrails-manifest.json` found. This looks like a pre-versioning installation. Run `update.sh` first to initialize the manifest, then re-run `/setup --update`."
39
+ Then stop.
40
+
41
+ 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)`.
42
+
43
+ 3. List all template files in `.claude/setup-templates/agents/` — these are the NEW templates from the update:
44
+ ```bash
45
+ ls .claude/setup-templates/agents/
46
+ ```
47
+ Template files are named with `sr-` prefix (e.g., `sr-architect.md`, `sr-developer.md`).
48
+
49
+ ### Phase U2: Quick Codebase Re-Analysis
50
+
51
+ 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.
52
+
53
+ Detect:
54
+ - **Languages**: Check for `*.py`, `*.ts`, `*.tsx`, `*.go`, `*.rs`, `*.java`, `*.kt`, `*.rb`, `*.cs`
55
+ - **Frameworks**: Search for imports (`fastapi`, `express`, `react`, `vue`, `angular`, `django`, `spring`, `gin`, `actix`, `rails`)
56
+ - **Directory structure**: Identify backend/frontend/core/test directories
57
+ - **Database**: Check for SQL files, ORM configs, migration directories
58
+ - **CI/CD**: Parse `.github/workflows/*.yml` for lint/test/build commands
59
+ - **Naming conventions**: Read 2-3 source files per detected layer
60
+
61
+ Read:
62
+ - `README.md` (if exists)
63
+ - `package.json` / `pyproject.toml` / `Cargo.toml` / `go.mod` / `pom.xml` (detect stack)
64
+ - `.github/workflows/*.yml` (detect CI commands)
65
+
66
+ Store all results for use in Phases U4 and U5.
67
+
68
+ ### Phase U3: Identify What Needs Regeneration
69
+
70
+ 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/`:
71
+
72
+ ```bash
73
+ sha256sum .claude/setup-templates/agents/sr-<name>.md
74
+ ```
75
+
76
+ Build three lists:
77
+
78
+ 1. **Changed agents**: agent name exists in manifest AND the current template checksum differs from the manifest checksum → mark for regeneration
79
+ 2. **New agents**: template file exists in `.claude/setup-templates/agents/` but the agent name is NOT in the manifest → mark for evaluation
80
+ 3. **Unchanged agents**: agent name exists in manifest AND checksum matches → skip
81
+
82
+ Display the analysis to the user:
83
+
84
+ ```
85
+ ## Agent Update Analysis
86
+
87
+ ### Changed Templates (will be regenerated)
88
+ - sr-architect.md (template modified)
89
+ - sr-developer.md (template modified)
90
+
91
+ ### New Templates Available
92
+ - sr-frontend-developer.md
93
+ - sr-backend-developer.md
94
+
95
+ ### Unchanged (keeping current)
96
+ - sr-reviewer.md
97
+ - sr-product-manager.md
98
+ ```
99
+
100
+ If there are no changed agents and no new agents, display:
101
+ ```
102
+ All agents are already up to date. Nothing to regenerate.
103
+ ```
104
+ Then jump to Phase U7.
105
+
106
+ ### Phase U4: Regenerate Changed Agents
107
+
108
+ For each agent in the "changed" list:
109
+
110
+ 1. Read the NEW template from `.claude/setup-templates/agents/sr-<name>.md`
111
+ 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:
112
+ - `{{PROJECT_NAME}}` → project name (from README.md or directory name)
113
+ - `{{ARCHITECTURE_DIAGRAM}}` → detected architecture layers
114
+ - `{{LAYER_TAGS}}` → detected layer tags (e.g., `[backend]`, `[frontend]`, `[api]`)
115
+ - `{{CI_COMMANDS_BACKEND}}` → backend CI commands
116
+ - `{{CI_COMMANDS_FRONTEND}}` → frontend CI commands
117
+ - `{{LAYER_CONVENTIONS}}` → detected conventions per layer
118
+ - `{{PERSONA_NAMES}}` → read existing persona names from `.claude/agents/personas/` filenames
119
+ - `{{PERSONA_FILES}}` → paths to existing persona files in `.claude/agents/personas/`
120
+ - `{{DOMAIN_EXPERTISE}}` → infer from detected stack and README
121
+ - `{{KEY_FILE_PATHS}}` → important file paths detected in Phase U2
122
+ - `{{WARNINGS}}` → read from existing `CLAUDE.md` if present
123
+ - `{{MEMORY_PATH}}` → `.claude/agent-memory/sr-<agent-name>/`
124
+ 3. Write the adapted agent to `.claude/agents/sr-<name>.md`
125
+ 4. Show: `✓ Regenerated sr-<name>`
126
+
127
+ After regenerating all changed agents, verify no unresolved placeholders remain:
128
+ ```bash
129
+ grep -r '{{[A-Z_]*}}' .claude/agents/sr-*.md 2>/dev/null || echo "OK: no broken placeholders"
130
+ ```
131
+
132
+ ### Phase U5: Evaluate New Agents
133
+
134
+ For each agent in the "new" list:
135
+
136
+ 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)
137
+ 2. Match against the codebase detected in Phase U2:
138
+ - If the template targets a layer/stack that IS present (e.g., `sr-frontend-developer` and React was detected), prompt:
139
+ > "New agent available: `sr-<name>` — your project uses [detected tech]. Add it? [Y/n]"
140
+ - If the template targets a layer/stack that is NOT present (e.g., `sr-backend-developer` and no backend was detected), prompt:
141
+ > "New agent available: `sr-<name>` — no [layer] detected in your project. Skip? [Y/n]"
142
+ 3. If the user accepts (or presses Enter on a pre-selected default):
143
+ - Generate the agent using the same template adaptation as Phase U4
144
+ - Create memory directory if it does not exist: `.claude/agent-memory/sr-<name>/`
145
+ - Show: `✓ Added sr-<name>`
146
+ 4. If the user declines:
147
+ - Show: `→ Skipped sr-<name>`
148
+
149
+ ### Phase U6: Update Workflow Commands
150
+
151
+ If any new agents were added in Phase U5:
152
+
153
+ 1. Read `.claude/commands/sr/implement.md`
154
+ 2. Check if the file references agent names in its orchestration steps (look for `sr-architect`, `sr-developer`, `sr-reviewer` etc.)
155
+ 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
156
+ 4. Write the updated `.claude/commands/sr/implement.md` if any changes were made
157
+ 5. Show which commands were updated, or "No command updates needed" if nothing changed
158
+
159
+ This is a lightweight check — only update commands where the sr- agent clearly belongs. Do not restructure the entire command.
160
+
161
+ ### Phase U7: Summary
162
+
163
+ Display the final summary and stop. Do not continue to Phase 1 of the full setup wizard.
164
+
165
+ ```
166
+ ## Update Complete
167
+
168
+ specrails updated from v<previous> to v<new>.
169
+
170
+ | Action | Count |
171
+ |--------------------|-------|
172
+ | Agents regenerated | N |
173
+ | Agents added | N |
174
+ | Agents skipped | N |
175
+ | Commands updated | N |
176
+
177
+ All agents are now up to date.
178
+
179
+ ### Regenerated
180
+ [list agent names, or "(none)"]
181
+
182
+ ### Added
183
+ [list agent names, or "(none)"]
184
+
185
+ ### Skipped
186
+ [list agent names, or "(none)"]
187
+ ```
188
+
189
+ Update `.specrails-manifest.json` to reflect the new checksums for all regenerated and added agents:
190
+ - For each regenerated agent: update its checksum entry to the new template's checksum
191
+ - For each added agent: add a new entry with its checksum
192
+ - Update the `version` field to the version read from `.specrails-version`
193
+
194
+ ---
195
+
196
+ ## Phase 1: Codebase Analysis
197
+
198
+ Analyze the repository to understand its architecture, stack, and conventions.
199
+
200
+ ### 1.1 Read project structure
201
+
202
+ ```bash
203
+ # Get the repo root and basic info
204
+ git rev-parse --show-toplevel
205
+ ls -la
206
+ ```
207
+
208
+ Read the following to understand the project:
209
+ - `README.md` (if exists)
210
+ - `CLAUDE.md` (if exists — don't overwrite, merge later)
211
+ - `package.json` or `pyproject.toml` or `Cargo.toml` or `go.mod` or `pom.xml` (detect stack)
212
+ - `.github/workflows/*.yml` (detect CI commands)
213
+ - `docker-compose.yml` or `Dockerfile` (detect infra)
214
+
215
+ ### 1.2 Detect architecture layers
216
+
217
+ Use Glob and Grep to identify:
218
+
219
+ 1. **Languages**: Check for `*.py`, `*.ts`, `*.tsx`, `*.go`, `*.rs`, `*.java`, `*.kt`, `*.rb`, `*.cs`
220
+ 2. **Frameworks**: Search for imports (`fastapi`, `express`, `react`, `vue`, `angular`, `django`, `spring`, `gin`, `actix`, `rails`)
221
+ 3. **Directory structure**: Identify backend/frontend/core/test directories
222
+ 4. **Database**: Check for SQL files, ORM configs, migration directories
223
+ 5. **CI/CD**: Parse workflow files for lint/test/build commands
224
+
225
+ ### 1.3 Infer conventions
226
+
227
+ Read 3-5 representative source files from each detected layer to understand:
228
+ - Naming conventions (camelCase, snake_case, PascalCase)
229
+ - Import patterns
230
+ - Error handling patterns
231
+ - Testing patterns (framework, structure, mocking approach)
232
+ - API patterns (REST, GraphQL, tRPC)
233
+
234
+ ### 1.4 Present findings
235
+
236
+ Display the detected architecture to the user:
237
+
238
+ ```
239
+ ## Codebase Analysis
240
+
241
+ | Layer | Tech | Path |
242
+ |-------------|---------------------|---------------|
243
+ | Backend | FastAPI (Python) | backend/ |
244
+ | Frontend | React + TypeScript | frontend/ |
245
+ | Core | Python package | src/ |
246
+ | Tests | pytest | tests/ |
247
+ | Database | PostgreSQL | migrations/ |
248
+
249
+ ### CI Commands Detected
250
+ - Lint: `ruff check .`
251
+ - Format: `ruff format --check .`
252
+ - Test: `pytest tests/ -q`
253
+ - Frontend lint: `npm run lint`
254
+ - Frontend build: `npx tsc --noEmit`
255
+
256
+ ### Conventions Detected
257
+ - Python: snake_case, type hints, Pydantic models
258
+ - TypeScript: strict mode, functional components
259
+ - Testing: pytest fixtures with scope="function"
260
+
261
+ ### OSS Project Detection
262
+
263
+ Read `.claude/setup-templates/.oss-detection.json` if it exists.
264
+
265
+ | Signal | Status |
266
+ |--------|--------|
267
+ | Public repository | [Yes / No / Unknown] |
268
+ | CI workflows (.github/workflows/) | [Yes / No] |
269
+ | CONTRIBUTING.md | [Yes / No] |
270
+ | **Result** | **OSS detected / Not detected / Could not check** |
271
+
272
+ If `is_oss: false` but at least one signal is `true`:
273
+ > "Some OSS signals were found but not all three. Is this an open-source project? (yes/no)"
274
+
275
+ If `.oss-detection.json` does not exist:
276
+ > "Is this an open-source project? (yes/no)"
277
+
278
+ When `IS_OSS=false` and no signals are present, skip OSS output entirely to avoid cluttering the display for non-OSS projects.
279
+
280
+ Store the final OSS determination as `IS_OSS` for use throughout the rest of setup.
281
+
282
+ [Confirm] [Modify] [Rescan]
283
+ ```
284
+
285
+ Wait for user confirmation. If they want to modify, ask what to change.
286
+
287
+ ---
288
+
289
+ ## Phase 2: User Personas & Product Discovery
290
+
291
+ ### 2.1 Ask about target users
292
+
293
+ Ask the user:
294
+
295
+ > If IS_OSS=true, prepend:
296
+ > "This is an OSS project. The **Maintainer** persona (Kai) is automatically included —
297
+ > you do not need to add 'open-source maintainers' to your list.
298
+ > Describe your other target user types below."
299
+
300
+ > **Who are the target users of your software?**
301
+ >
302
+ > Describe them in natural language. Examples:
303
+ > - "Developers who manage Kubernetes clusters"
304
+ > - "Small business owners tracking inventory and sales"
305
+ > - "Gamers who collect and trade digital items"
306
+ >
307
+ > I'll research the competitive landscape and create detailed personas
308
+ > with Value Proposition Canvas profiles for each user type.
309
+ >
310
+ > **How many distinct user types do you have?** (typically 2-3)
311
+
312
+ Wait for the user's response.
313
+
314
+ ### 2.2 Research competitive landscape
315
+
316
+ For each user type described, use WebSearch to research:
317
+
318
+ 1. **Existing tools** they use today (competitors)
319
+ 2. **Common pain points** reported in forums, Reddit, product reviews
320
+ 3. **Feature gaps** in current tools
321
+ 4. **Unmet needs** and workflow frustrations
322
+
323
+ Search queries to use (adapt to the domain):
324
+ - `"[domain] [user type] best tools 2025"`
325
+ - `"[domain] [user type] pain points frustrations"`
326
+ - `"[competitor name] missing features complaints"`
327
+ - `"[domain] management app feature comparison"`
328
+ - `site:reddit.com "[domain] [user type] what tool do you use"`
329
+
330
+ ### 2.3 Generate VPC personas
331
+
332
+ For each user type, generate a full Value Proposition Canvas persona file following the template at `.claude/setup-templates/personas/persona.md`.
333
+
334
+ Each persona must include:
335
+ - **Profile**: Demographics, behaviors, tools used, spending patterns
336
+ - **Customer Jobs**: Functional, social, emotional (6-8 jobs)
337
+ - **Pains**: Graded by severity (Critical > High > Medium > Low) with 6-8 entries
338
+ - **Gains**: Graded by impact (High > Medium > Low) with 6-8 entries
339
+ - **Key Insight**: The #1 unmet need that this project can address
340
+ - **Sources**: Links to competitive analysis, forums, reviews used in research
341
+
342
+ ### 2.4 Present personas
343
+
344
+ Display each generated persona to the user:
345
+
346
+ ```
347
+ ## Generated Personas
348
+
349
+ ### Persona 1: "[Nickname]" — The [Role]
350
+ - Age: X-Y
351
+ - Key pain: [Critical pain]
352
+ - Key insight: [Main unmet need]
353
+
354
+ ### Persona 2: "[Nickname]" — The [Role]
355
+ - Age: X-Y
356
+ - Key pain: [Critical pain]
357
+ - Key insight: [Main unmet need]
358
+
359
+ [Accept] [Edit] [Regenerate]
360
+ ```
361
+
362
+ Wait for confirmation. If the user wants edits, apply them.
363
+
364
+ ---
365
+
366
+ ## Phase 3: Configuration
367
+
368
+ ### 3.1 Agents to install
369
+
370
+ Present the available agents and let the user choose:
371
+
372
+ ```
373
+ ## Agent Selection
374
+
375
+ Which agents do you want to install?
376
+
377
+ | Agent | Purpose | Model | Required |
378
+ |-------|---------|-------|----------|
379
+ | sr-architect | Design features, create implementation plans | Sonnet | Yes |
380
+ | sr-developer (full-stack) | Implement features across all layers | Sonnet | Yes |
381
+ | sr-reviewer | CI/CD quality gate, fix issues | Sonnet | Yes |
382
+ | sr-product-manager | Product discovery, ideation, VPC evaluation | Opus | Recommended |
383
+ | sr-product-analyst | Read-only backlog analysis | Haiku | Recommended |
384
+ | sr-backend-developer | Specialized backend implementation | Sonnet | If backend layer exists |
385
+ | sr-frontend-developer | Specialized frontend implementation | Sonnet | If frontend layer exists |
386
+
387
+ [All] [Required only] [Custom selection]
388
+ ```
389
+
390
+ ### 3.2 Backlog provider
391
+
392
+ Ask the user where they manage their product backlog:
393
+
394
+ ```
395
+ ## Backlog Provider
396
+
397
+ Where do you track your product backlog?
398
+
399
+ 1. **GitHub Issues** — uses `gh` CLI to read/create issues with labels and VPC scores
400
+ 2. **JIRA** — uses JIRA CLI or REST API to read/create tickets in a JIRA project
401
+ 3. **None** — skip backlog commands (you can still use /implement with text descriptions)
402
+ ```
403
+
404
+ Wait for the user's choice. Set `BACKLOG_PROVIDER` to `github`, `jira`, or `none`.
405
+
406
+ #### If GitHub Issues
407
+
408
+ - Verify `gh auth status` works. If not, warn and offer to skip.
409
+ - Ask about **access mode**:
410
+
411
+ ```
412
+ ## GitHub Issues — Access Mode
413
+
414
+ How should we interact with GitHub Issues?
415
+
416
+ 1. **Read & Write** (default) — read backlog, create new issues from product discovery,
417
+ close resolved issues, add comments on partial progress
418
+ 2. **Read only** — read backlog for prioritization, but don't create or modify issues.
419
+ Product discovery will propose ideas as output but won't sync them to GitHub.
420
+ ```
421
+
422
+ Set `BACKLOG_WRITE=true/false`.
423
+
424
+ - If write mode, ask if they want to create labels:
425
+ - `product-driven-backlog` (purple) — product feature ideas
426
+ - `area:*` labels for each detected layer/area
427
+ - `enhancement`, `bug`, `tech-debt`
428
+
429
+ #### If JIRA
430
+
431
+ First, check if JIRA CLI is installed:
432
+
433
+ ```bash
434
+ command -v jira &> /dev/null
435
+ ```
436
+
437
+ If not installed, offer to install it:
438
+
439
+ > JIRA CLI is not installed. There are several options:
440
+ >
441
+ > 1. **go-jira** (recommended) — lightweight CLI
442
+ > - macOS: `brew install go-jira`
443
+ > - Linux/other: `go install github.com/go-jira/jira/cmd/jira@latest`
444
+ > 2. **Atlassian CLI** — official but heavier
445
+ > - `npm install -g @atlassian/cli`
446
+ > 3. **Skip CLI, use REST API** — no CLI needed, uses `curl` with API token
447
+ >
448
+ > Which option? (1/2/3)
449
+
450
+ If the user chooses option 1 or 2, run the install command. If option 3, proceed with REST API mode.
451
+
452
+ Then ask for JIRA configuration:
453
+
454
+ > To connect to JIRA, I need:
455
+ >
456
+ > 1. **JIRA base URL** (e.g., `https://your-company.atlassian.net`)
457
+ > 2. **Project key** (e.g., `PROJ`, `DECK`, `MYAPP`)
458
+ > 3. **Authentication method**:
459
+ > - **JIRA CLI** (`jira` command) — if already configured
460
+ > - **API token** — stored in `.env` as `JIRA_API_TOKEN` and `JIRA_USER_EMAIL`
461
+ >
462
+ > Optional:
463
+ > - **Custom issue type** for backlog items (default: "Story")
464
+ > - **Custom fields** for VPC scores (or use labels/description)
465
+
466
+ Then ask about **access mode**:
467
+
468
+ ```
469
+ ## JIRA — Access Mode
470
+
471
+ How should we interact with JIRA?
472
+
473
+ 1. **Read & Write** — read tickets for implementation context, create new tickets
474
+ from product discovery, add a comment to tickets when implementation is complete
475
+ 2. **Read only** — read tickets for implementation context, but never create or
476
+ modify tickets. Product discovery will propose ideas as output only. After
477
+ implementation, the pipeline will show what to update manually but won't
478
+ touch JIRA.
479
+ ```
480
+
481
+ Set `BACKLOG_WRITE=true/false`.
482
+
483
+ <!-- no separate template — this file IS the source (install.sh copies commands/setup.md directly) -->
484
+
485
+ #### Project Label
486
+
487
+ After the access mode selection, ask:
488
+
489
+ > **Project Label (optional but recommended)**
490
+ >
491
+ > JIRA teams often tag all tickets for a product with a project label
492
+ > (e.g., `PROJECT-specrails`, `PLATFORM`, `MOBILE`). This label is applied
493
+ > to every ticket the backlog pipeline creates — making it easy to filter all
494
+ > AI-generated backlog items across JIRA.
495
+ >
496
+ > Enter a project label, or press Enter to skip:
497
+
498
+ If the user enters a label: set `PROJECT_LABEL=<value>`.
499
+ If the user skips: set `PROJECT_LABEL=""`.
500
+
501
+ #### Epic Link Field
502
+
503
+ Ask:
504
+
505
+ > **Epic Link Field (optional — advanced)**
506
+ >
507
+ > JIRA Next-Gen (team-managed) projects link stories to epics using the `parent`
508
+ > field. JIRA Classic (company-managed) projects use `Epic Link` (customfield_10014).
509
+ >
510
+ > Which does your project use?
511
+ > 1. `parent` — Next-Gen / team-managed **(default)**
512
+ > 2. `customfield_10014` — Classic / company-managed
513
+
514
+ Set `EPIC_LINK_FIELD` to `parent` or `customfield_10014`. Default: `parent`.
515
+
516
+ Store the full configuration in `.claude/backlog-config.json`:
517
+ ```json
518
+ {
519
+ "provider": "jira",
520
+ "write_access": true,
521
+ "jira_base_url": "https://your-company.atlassian.net",
522
+ "jira_project_key": "PROJ",
523
+ "issue_type": "Story",
524
+ "auth_method": "api_token",
525
+ "cli_installed": true,
526
+ "project_label": "<PROJECT_LABEL or empty string>",
527
+ "epic_link_field": "parent",
528
+ "epic_mapping": {}
529
+ }
530
+ ```
531
+
532
+ #### If None
533
+
534
+ - Skip `/sr:product-backlog` and `/sr:update-product-driven-backlog` commands.
535
+ - The `/sr:implement` command will still work with text descriptions.
536
+
537
+ ### 3.3 Git & shipping workflow
538
+
539
+ Ask how the user wants to handle git operations after implementation:
540
+
541
+ ```
542
+ ## Git & Shipping
543
+
544
+ After implementation is complete, how should we handle shipping?
545
+
546
+ 1. **Automatic** (default) — create branch, commit changes, push, and open a PR
547
+ (requires GitHub CLI for PRs, otherwise prints a compare URL)
548
+ 2. **Manual** — stop after implementation and review. You handle branching,
549
+ committing, and PR creation yourself. The pipeline will show a summary
550
+ of all changes but won't touch git.
551
+ ```
552
+
553
+ Set `GIT_AUTO=true/false`.
554
+
555
+ 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.
556
+
557
+ ### 3.4 Commands to install
558
+
559
+ ```
560
+ ## Command Selection
561
+
562
+ | Command | Purpose | Requires |
563
+ |---------|---------|----------|
564
+ | /sr:implement | Full pipeline: sr-architect → sr-developer → sr-reviewer → ship | sr-architect + sr-developer + sr-reviewer |
565
+ | /sr:product-backlog | View prioritized backlog with VPC scores | sr-product-analyst + Backlog provider |
566
+ | /sr:update-product-driven-backlog | Generate new feature ideas via product discovery | sr-product-manager + Backlog provider |
567
+
568
+ [All] [Custom selection]
569
+ ```
570
+
571
+ Note: If `BACKLOG_PROVIDER=none`, the backlog commands are not offered.
572
+
573
+ ### 3.5 Confirm configuration
574
+
575
+ Display the full configuration summary including access modes:
576
+
577
+ ```
578
+ ## Configuration Summary
579
+
580
+ | Setting | Value |
581
+ |---------|-------|
582
+ | Backlog provider | GitHub Issues / JIRA / None |
583
+ | Backlog access | Read & Write / Read only |
584
+ | Project label (JIRA) | PROJECT-specrails / (none) |
585
+ | Epic link field (JIRA) | parent / customfield_10014 |
586
+ | Git workflow | Automatic / Manual |
587
+ | Agents | [list] |
588
+ | Commands | [list] |
589
+ | Personas | [count] personas |
590
+
591
+ Note: The `Project label (JIRA)` and `Epic link field (JIRA)` rows are only shown when `BACKLOG_PROVIDER=jira`.
592
+
593
+ [Confirm] [Modify]
594
+ ```
595
+
596
+ Wait for final confirmation.
597
+
598
+ ---
599
+
600
+ ## Phase 4: Generate Files
601
+
602
+ 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.
603
+
604
+ ### 4.1 Generate agents
605
+
606
+ For each selected agent, read the template and generate the adapted version:
607
+
608
+ **Template → Output mapping:**
609
+ - `setup-templates/agents/sr-architect.md` → `.claude/agents/sr-architect.md`
610
+ - `setup-templates/agents/sr-developer.md` → `.claude/agents/sr-developer.md`
611
+ - `setup-templates/agents/sr-reviewer.md` → `.claude/agents/sr-reviewer.md`
612
+ - `setup-templates/agents/sr-product-manager.md` → `.claude/agents/sr-product-manager.md`
613
+ - `setup-templates/agents/sr-product-analyst.md` → `.claude/agents/sr-product-analyst.md`
614
+ - `setup-templates/agents/sr-backend-developer.md` → `.claude/agents/sr-backend-developer.md` (if backend layer)
615
+ - `setup-templates/agents/sr-frontend-developer.md` → `.claude/agents/sr-frontend-developer.md` (if frontend layer)
616
+
617
+ When generating each agent:
618
+ 1. Read the template
619
+ 2. Replace all `{{PLACEHOLDER}}` values with project-specific content:
620
+ - `{{PROJECT_NAME}}` → project name
621
+ - `{{ARCHITECTURE_DIAGRAM}}` → detected architecture
622
+ - `{{LAYER_TAGS}}` → detected layer tags (e.g., `[backend]`, `[frontend]`, `[api]`, `[mobile]`)
623
+ - `{{CI_COMMANDS_BACKEND}}` → backend CI commands from Phase 1
624
+ - `{{CI_COMMANDS_FRONTEND}}` → frontend CI commands from Phase 1
625
+ - `{{LAYER_CONVENTIONS}}` → detected conventions per layer
626
+ - `{{PERSONA_NAMES}}` → names from generated personas
627
+ - `{{PERSONA_FILES}}` → paths to persona files
628
+ - `{{DOMAIN_EXPERTISE}}` → domain knowledge from Phase 2 research
629
+ - `{{COMPETITIVE_LANDSCAPE}}` → competitors discovered in Phase 2
630
+ - `{{KEY_FILE_PATHS}}` → important file paths detected in Phase 1
631
+ - `{{WARNINGS}}` → project-specific warnings (from existing CLAUDE.md or detected)
632
+ - `{{MEMORY_PATH}}` → agent memory directory path (e.g., `.claude/agent-memory/sr-<agent-name>/`)
633
+ 3. Write the final file
634
+
635
+ ### 4.2 Generate personas
636
+
637
+ If IS_OSS=true:
638
+ 1. Copy `setup-templates/personas/the-maintainer.md` to `.claude/agents/personas/the-maintainer.md`
639
+ 2. Log: "Maintainer persona included"
640
+ 3. Set MAINTAINER_INCLUDED=true for use in template substitution
641
+ 4. Set `{{MAINTAINER_PERSONA_LINE}}` = `- \`.claude/agents/personas/the-maintainer.md\` — "Kai" the Maintainer (open-source maintainer)`
642
+ 5. Increment `{{PERSONA_COUNT}}` by 1 to account for the Maintainer
643
+
644
+ If IS_OSS=false:
645
+ - Set `{{MAINTAINER_PERSONA_LINE}}` = *(empty string)*
646
+
647
+ Then for each user-defined VPC persona from Phase 2.3:
648
+
649
+ Write each persona to `.claude/agents/personas/`:
650
+ - Use the VPC personas generated in Phase 2
651
+ - File naming: kebab-case of persona nickname (e.g., `the-developer.md`, `the-admin.md`)
652
+
653
+ ### 4.3 Generate commands
654
+
655
+ For each selected command, read the template and adapt:
656
+ - `setup-templates/commands/sr/implement.md` → `.claude/commands/sr/implement.md`
657
+ - `setup-templates/commands/sr/product-backlog.md` → `.claude/commands/sr/product-backlog.md` (if `BACKLOG_PROVIDER != none`)
658
+ - `setup-templates/commands/sr/update-product-driven-backlog.md` → `.claude/commands/sr/update-product-driven-backlog.md` (if `BACKLOG_PROVIDER != none`)
659
+
660
+ Adapt:
661
+ - CI commands to match detected stack
662
+ - Persona references to match generated personas
663
+ - File paths to match project structure
664
+ - Layer tags to match detected layers
665
+ - **Backlog provider commands** based on `BACKLOG_PROVIDER`:
666
+
667
+ #### GitHub Issues (`BACKLOG_PROVIDER=github`)
668
+ - Issue fetch: `gh issue list --label "product-driven-backlog" --state open --limit 100 --json number,title,labels,body`
669
+ - Issue create: `gh issue create --title "..." --label "..." --body "..."`
670
+ - Issue view: `gh issue view {number} --json number,title,labels,body`
671
+ - Issue label names to match project areas
672
+ - Pre-flight check: `gh auth status`
673
+
674
+ #### JIRA (`BACKLOG_PROVIDER=jira`)
675
+ - 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:
676
+ ```bash
677
+ curl -s -u "$JIRA_USER_EMAIL:$JIRA_API_TOKEN" \
678
+ "{{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"
679
+ ```
680
+ - Issue create: `jira issue create --project {{JIRA_PROJECT_KEY}} --type Story --summary "..." --label product-backlog --description "..."` or equivalent REST API call
681
+ - Issue view: `jira issue view {key}` or REST API
682
+ - VPC scores stored in the issue description body (same markdown format, parsed from description)
683
+ - Pre-flight check: `jira me` or test API connectivity
684
+ - Store JIRA config in `.claude/backlog-config.json`:
685
+ ```json
686
+ {
687
+ "provider": "jira",
688
+ "jira_base_url": "https://your-company.atlassian.net",
689
+ "jira_project_key": "PROJ",
690
+ "issue_type": "Story",
691
+ "auth_method": "api_token"
692
+ }
693
+ ```
694
+
695
+ The command templates use `{{BACKLOG_FETCH_CMD}}`, `{{BACKLOG_CREATE_CMD}}`, `{{BACKLOG_VIEW_CMD}}`, and `{{BACKLOG_PREFLIGHT}}` placeholders that get filled with the provider-specific commands.
696
+
697
+ ### 4.4 Generate rules
698
+
699
+ For each detected layer, read the layer rule template and generate a layer-specific rules file:
700
+ - `setup-templates/rules/layer.md` → `.claude/rules/{layer-name}.md`
701
+
702
+ Each rule file must:
703
+ - Have the correct `paths:` frontmatter matching the layer's directory
704
+ - Contain conventions specific to that layer (from Phase 1 analysis)
705
+ - Reference actual file paths and patterns from the codebase
706
+
707
+ ### 4.5 Generate root CLAUDE.md
708
+
709
+ If no CLAUDE.md exists, generate one from the template. If one already exists, **merge** — add the agent workflow sections without removing existing content.
710
+
711
+ ### 4.6 Generate settings
712
+
713
+ Create or merge `.claude/settings.json` with permissions for:
714
+ - All detected CI commands
715
+ - Git operations
716
+ - OpenSpec CLI (if installed)
717
+ - GitHub CLI (if available)
718
+ - Language-specific tools (python, npm, cargo, go, etc.)
719
+
720
+ ### 4.7 Initialize agent memory
721
+
722
+ Create memory directories for each installed agent:
723
+
724
+ ```bash
725
+ mkdir -p .claude/agent-memory/sr-{agent-name}/
726
+ ```
727
+
728
+ Each gets an empty `MEMORY.md` that will be populated during usage.
729
+
730
+ ---
731
+
732
+ ## Phase 5: Cleanup & Summary
733
+
734
+ ### 5.1 Remove all scaffolding artifacts
735
+
736
+ The setup process installed temporary files that are only needed during installation. Remove them all now that the final files have been generated.
737
+
738
+ ```bash
739
+ # 1. Remove setup templates (used as structural references during generation)
740
+ rm -rf .claude/setup-templates/
741
+
742
+ # 2. Remove the /setup command itself — it's a one-time installer, not a permanent command
743
+ rm -f .claude/commands/setup.md
744
+
745
+ # 3. Remove the specrails/ directory from the repo if it exists at the root
746
+ # (it was only needed for install.sh and templates — everything is now in .claude/)
747
+ # NOTE: Only remove if it's inside this repo. Ask the user if unsure.
748
+ ```
749
+
750
+ **What gets removed:**
751
+ | Artifact | Why |
752
+ |----------|-----|
753
+ | `.claude/setup-templates/` | Temporary — templates already rendered into final files |
754
+ | `.claude/commands/setup.md` | One-time installer — running it again would overwrite customized agents |
755
+
756
+ **What to do with `specrails/`:**
757
+
758
+ 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`:
759
+
760
+ ```bash
761
+ # Add specrails/ to .gitignore if not already there
762
+ if ! grep -q '^specrails/' .gitignore 2>/dev/null; then
763
+ echo '' >> .gitignore
764
+ echo '# specrails installer (one-time setup tool, not part of the project)' >> .gitignore
765
+ echo 'specrails/' >> .gitignore
766
+ fi
767
+ ```
768
+
769
+ Then ask the user:
770
+
771
+ > `specrails/` has been added to `.gitignore`. Do you also want to delete it?
772
+ >
773
+ > 1. **Keep it** (default) — stays locally in case you want to re-run setup or install in other repos
774
+ > 2. **Delete it** — everything is installed, you don't need it anymore
775
+
776
+ Apply the user's choice.
777
+
778
+ ### 5.2 Verify clean state
779
+
780
+ After cleanup, verify that only the intended files remain:
781
+
782
+ ```bash
783
+ # These should exist (the actual system):
784
+ ls .claude/agents/sr-*.md
785
+ ls .claude/agents/personas/*.md
786
+ ls .claude/commands/sr/*.md
787
+ ls .claude/rules/*.md
788
+ ls .claude/agent-memory/
789
+
790
+ # These should NOT exist (scaffolding):
791
+ # .claude/setup-templates/ — GONE
792
+ # .claude/commands/setup.md — GONE
793
+ ```
794
+
795
+ If any scaffolding artifact remains, remove it.
796
+
797
+ ### 5.3 Summary
798
+
799
+ Display the complete installation summary:
800
+
801
+ ```
802
+ ## Setup Complete
803
+
804
+ ### Agents Installed
805
+ | Agent | File | Model |
806
+ |-------|------|-------|
807
+ | sr-architect | .claude/agents/sr-architect.md | Sonnet |
808
+ | sr-developer | .claude/agents/sr-developer.md | Sonnet |
809
+ | sr-reviewer | .claude/agents/sr-reviewer.md | Sonnet |
810
+ | sr-product-manager | .claude/agents/sr-product-manager.md | Opus |
811
+
812
+ ### Personas Created
813
+ | Persona | File | Source |
814
+ |---------|------|--------|
815
+ [If IS_OSS=true:]
816
+ | "Kai" — The Maintainer | .claude/agents/personas/sr-the-maintainer.md | Auto-included (OSS) |
817
+ [For each user-generated persona:]
818
+ | "[Name]" — The [Role] | .claude/agents/personas/[name].md | Generated |
819
+
820
+ ### Commands Installed
821
+ | Command | File |
822
+ |---------|------|
823
+ | /sr:implement | .claude/commands/sr/implement.md |
824
+ | /sr:product-backlog | .claude/commands/sr/product-backlog.md |
825
+ | /sr:update-product-driven-backlog | .claude/commands/sr/update-product-driven-backlog.md |
826
+
827
+ ### Rules Created
828
+ | Layer | File |
829
+ |-------|------|
830
+ | Backend | .claude/rules/backend.md |
831
+ | Frontend | .claude/rules/frontend.md |
832
+
833
+ ### Scaffolding Removed
834
+ | Artifact | Status |
835
+ |----------|--------|
836
+ | .claude/setup-templates/ | Deleted |
837
+ | .claude/commands/setup.md | Deleted |
838
+ | specrails/ | [User's choice] |
839
+
840
+ ### Next Steps
841
+ 1. Review the generated files in .claude/
842
+ 2. Run `/sr:product-backlog` to see your backlog (if GitHub Issues exist)
843
+ 3. Run `/sr:update-product-driven-backlog` to generate feature ideas
844
+ 4. Run `/sr:implement #issue-number` to implement a feature
845
+ 5. Commit the .claude/ directory to version control
846
+
847
+ ### Quick Start
848
+ - `/sr:implement "describe a feature"` — implement something right now
849
+ - `/sr:product-backlog` — see prioritized feature ideas
850
+ - `/sr:update-product-driven-backlog` — discover new features using VPC
851
+ ```