specrails-core 3.0.0 → 3.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.
package/commands/setup.md CHANGED
@@ -314,21 +314,14 @@ When no flags are passed (the default), run this streamlined 3-question setup. D
314
314
 
315
315
  ### QS1: Ask the 3 questions
316
316
 
317
- Ask exactly these questions in sequence. Do not ask any other questions.
317
+ 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.
318
318
 
319
- ```
320
319
  Welcome to specrails! Let's get your AI agent team set up in 3 quick questions.
321
320
 
322
321
  1. What is this project? (one sentence)
323
- > _
324
-
325
322
  2. Who are the target users?
326
- > _
327
-
328
323
  3. Git access for agents — read-only or read-write?
329
324
  (read-only = agents can read and suggest; read-write = agents can commit)
330
- > _
331
- ```
332
325
 
333
326
  Store the answers as:
334
327
  - `QS_PROJECT_DESCRIPTION` — answer to question 1
@@ -696,12 +689,78 @@ Ask the user where they manage their product backlog:
696
689
 
697
690
  Where do you track your product backlog?
698
691
 
699
- 1. **GitHub Issues** — uses `gh` CLI to read/create issues with labels and VPC scores
700
- 2. **JIRA** uses JIRA CLI or REST API to read/create tickets in a JIRA project
701
- 3. **None** — skip backlog commands (you can still use /implement with text descriptions)
692
+ 1. **Local tickets** (recommended) lightweight JSON-based ticket management built into the project.
693
+ No external tools required. Tickets stored in `.claude/local-tickets.json`, version-controlled and diffable.
694
+ 2. **GitHub Issues** — uses `gh` CLI to read/create issues with labels and VPC scores
695
+ 3. **JIRA** — uses JIRA CLI or REST API to read/create tickets in a JIRA project
696
+ 4. **None** — skip backlog commands (you can still use /implement with text descriptions)
702
697
  ```
703
698
 
704
- Wait for the user's choice. Set `BACKLOG_PROVIDER` to `github`, `jira`, or `none`.
699
+ Wait for the user's choice. Set `BACKLOG_PROVIDER` to `local`, `github`, `jira`, or `none`.
700
+
701
+ #### If Local Tickets
702
+
703
+ No external tools or credentials required. Initialize the storage file:
704
+
705
+ 1. Copy `templates/local-tickets-schema.json` to `$SPECRAILS_DIR/local-tickets.json`
706
+ 2. Set `last_updated` to the current ISO-8601 timestamp
707
+
708
+ Store configuration in `$SPECRAILS_DIR/backlog-config.json`:
709
+ ```json
710
+ {
711
+ "provider": "local",
712
+ "write_access": true,
713
+ "git_auto": true
714
+ }
715
+ ```
716
+
717
+ Local tickets are always read-write — there is no "read only" mode since the file is local.
718
+
719
+ **Ticket schema** — each entry in the `tickets` map has these fields:
720
+
721
+ ```json
722
+ {
723
+ "id": 1,
724
+ "title": "Feature title",
725
+ "description": "Markdown description",
726
+ "status": "todo",
727
+ "priority": "medium",
728
+ "labels": ["area:frontend", "effort:medium"],
729
+ "assignee": null,
730
+ "prerequisites": [],
731
+ "metadata": {
732
+ "vpc_scores": {},
733
+ "effort_level": "Medium",
734
+ "user_story": "",
735
+ "area": ""
736
+ },
737
+ "comments": [],
738
+ "created_at": "<ISO-8601>",
739
+ "updated_at": "<ISO-8601>",
740
+ "created_by": "user",
741
+ "source": "manual"
742
+ }
743
+ ```
744
+
745
+ **Status values:** `todo`, `in_progress`, `done`, `cancelled`
746
+ **Priority values:** `critical`, `high`, `medium`, `low`
747
+ **Labels:** Freeform strings following the `area:*` and `effort:*` convention
748
+ **Source values:** `manual`, `product-backlog`, `propose-spec`
749
+
750
+ **Advisory file locking protocol** (CLI agents and hub server must both follow this):
751
+
752
+ The `revision` counter in the JSON root enables optimistic concurrency — increment it on **every** write. The lock file prevents concurrent corruption:
753
+
754
+ 1. **Acquire lock:** Check for `$SPECRAILS_DIR/local-tickets.json.lock`
755
+ - 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)
756
+ - If the file exists and its `timestamp` is 30+ seconds old (stale): delete it and proceed
757
+ - If no lock file exists: proceed immediately
758
+ 2. **Create lock file:** Write `{"agent": "<agent-name-or-process>", "timestamp": "<ISO-8601>"}` to `$SPECRAILS_DIR/local-tickets.json.lock`
759
+ 3. **Minimal lock window:** Read the JSON → modify in memory → write back → release
760
+ 4. **Release lock:** Delete `$SPECRAILS_DIR/local-tickets.json.lock`
761
+ 5. **Always increment `revision`** by 1 and update `last_updated` on every successful write
762
+
763
+ The hub server uses `proper-lockfile` (or equivalent) to honor the same protocol via the `.lock` file path.
705
764
 
706
765
  #### If GitHub Issues
707
766
 
@@ -1066,6 +1125,27 @@ When adapting `update-product-driven-backlog.md` and `product-backlog.md`, subst
1066
1125
 
1067
1126
  **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.
1068
1127
 
1128
+ #### Local Tickets (`BACKLOG_PROVIDER=local`)
1129
+
1130
+ 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.
1131
+
1132
+ 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.
1133
+
1134
+ | Placeholder | Substituted value |
1135
+ |-------------|-------------------|
1136
+ | `{{BACKLOG_PROVIDER_NAME}}` | `Local Tickets` |
1137
+ | `{{BACKLOG_PREFLIGHT}}` | `[[ -f "$SPECRAILS_DIR/local-tickets.json" ]] && echo "Local tickets storage: OK" \|\| echo "WARNING: $SPECRAILS_DIR/local-tickets.json not found — run /setup to initialize"` |
1138
+ | `{{BACKLOG_FETCH_CMD}}` | Read `$SPECRAILS_DIR/local-tickets.json`. Parse the `tickets` map and return all entries where `status` is `"todo"` or `"in_progress"`. |
1139
+ | `{{BACKLOG_FETCH_ALL_CMD}}` | Read `$SPECRAILS_DIR/local-tickets.json`. Parse the `tickets` map and return all entries regardless of status. |
1140
+ | `{{BACKLOG_FETCH_CLOSED_CMD}}` | Read `$SPECRAILS_DIR/local-tickets.json`. Parse the `tickets` map and return all entries where `status` is `"done"` or `"cancelled"`. |
1141
+ | `{{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. |
1142
+ | `{{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. |
1143
+ | `{{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. |
1144
+ | `{{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. |
1145
+ | `{{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. |
1146
+ | `{{BACKLOG_PARTIAL_COMMENT_CMD}}` | Same as `{{BACKLOG_COMMENT_CMD}}` but append `{"author": "<agent-name>", "body": "<comment>", "type": "progress", "created_at": "<ISO-8601>"}`. |
1147
+ | `{{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`. |
1148
+
1069
1149
  #### GitHub Issues (`BACKLOG_PROVIDER=github`)
1070
1150
  - Issue fetch: `gh issue list --label "product-driven-backlog" --state open --limit 100 --json number,title,labels,body`
1071
1151
  - Issue create: `gh issue create --title "..." --label "..." --body "..."`
@@ -1094,7 +1174,7 @@ When adapting `update-product-driven-backlog.md` and `product-backlog.md`, subst
1094
1174
  }
1095
1175
  ```
1096
1176
 
1097
- 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.
1177
+ 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.
1098
1178
 
1099
1179
  ### 4.4 Generate rules
1100
1180
 
package/install.sh CHANGED
@@ -44,6 +44,7 @@ SPECRAILS_DIR=""
44
44
  INSTRUCTIONS_FILE=""
45
45
  HAS_CLAUDE=false
46
46
  HAS_CODEX=false
47
+ AGENT_TEAMS=false
47
48
 
48
49
  while [[ $# -gt 0 ]]; do
49
50
  case "$1" in
@@ -98,7 +99,7 @@ if [[ -z "$CUSTOM_ROOT_DIR" && -f "$SCRIPT_DIR/install.sh" && -d "$SCRIPT_DIR/te
98
99
  echo -e "${YELLOW}⚠${NC} You're running the installer from inside the specrails source repo."
99
100
  echo -e " specrails installs into a ${BOLD}target${NC} repository, not into itself."
100
101
  echo ""
101
- read -p " Enter the path to the target repo (or 'q' to quit): " TARGET_PATH
102
+ read -p " Enter the path to the target repo (or 'q' to quit): " TARGET_PATH || TARGET_PATH="q"
102
103
  if [[ "$TARGET_PATH" == "q" || -z "$TARGET_PATH" ]]; then
103
104
  echo " Aborted. No changes made."
104
105
  exit 0
@@ -229,7 +230,7 @@ elif [ "$HAS_CLAUDE" = true ] && [ "$HAS_CODEX" = true ]; then
229
230
  echo " 1) Claude Code (claude) → output to .claude/"
230
231
  echo " 2) Codex (codex) → output to .codex/"
231
232
  echo ""
232
- read -p " Select provider (1 or 2, default: 1): " PROVIDER_CHOICE
233
+ read -p " Select provider (1 or 2, default: 1): " PROVIDER_CHOICE || PROVIDER_CHOICE="1"
233
234
  PROVIDER_CHOICE="${PROVIDER_CHOICE:-1}"
234
235
  if [[ "$PROVIDER_CHOICE" == "2" ]]; then
235
236
  CLI_PROVIDER="codex"
@@ -266,6 +267,35 @@ else
266
267
  INSTRUCTIONS_FILE="CLAUDE.md"
267
268
  fi
268
269
 
270
+ # 1.2b Agent Teams opt-in (Claude Code only)
271
+ if [[ "$CLI_PROVIDER" == "claude" ]]; then
272
+ echo ""
273
+ if [ "$AUTO_YES" = true ]; then
274
+ # --yes flag: default to NOT installing (opt-in, not opt-out)
275
+ AGENT_TEAMS=false
276
+ info "Agent Teams commands: skipped (opt-in, use interactive mode to enable)"
277
+ else
278
+ echo -e " ${BOLD}Agent Teams commands are available (experimental):${NC}"
279
+ echo " /sr:team-review — Multi-perspective code review with AI reviewers"
280
+ echo " /sr:team-debug — Collaborative debugging with competing hypotheses"
281
+ echo ""
282
+ echo " These require Claude Code Agent Teams (experimental feature)."
283
+ read -p " Install Agent Teams commands? (y/n, default: n): " INSTALL_AGENT_TEAMS || INSTALL_AGENT_TEAMS="n"
284
+ if [[ "$INSTALL_AGENT_TEAMS" == "y" || "$INSTALL_AGENT_TEAMS" == "Y" ]]; then
285
+ AGENT_TEAMS=true
286
+ ok "Agent Teams commands will be installed"
287
+ echo ""
288
+ info "Remember to set the feature flag before using these commands:"
289
+ echo ""
290
+ echo " export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1"
291
+ echo ""
292
+ else
293
+ AGENT_TEAMS=false
294
+ info "Agent Teams commands: skipped"
295
+ fi
296
+ fi
297
+ fi
298
+
269
299
  # 1.3 API key / authentication (provider-specific)
270
300
  if [[ "$CLI_PROVIDER" == "claude" ]]; then
271
301
  CLAUDE_AUTHED=false
@@ -334,7 +364,7 @@ elif [ -f "$REPO_ROOT/node_modules/.bin/openspec" ]; then
334
364
  else
335
365
  warn "OpenSpec CLI not found."
336
366
  if [ "$HAS_NPM" = true ]; then
337
- if [ "$AUTO_YES" = true ]; then INSTALL_OPENSPEC="y"; else read -p " Install OpenSpec CLI globally? (y/n): " INSTALL_OPENSPEC; fi
367
+ if [ "$AUTO_YES" = true ]; then INSTALL_OPENSPEC="y"; else read -p " Install OpenSpec CLI globally? (y/n): " INSTALL_OPENSPEC || INSTALL_OPENSPEC="n"; fi
338
368
  if [ "$INSTALL_OPENSPEC" = "y" ] || [ "$INSTALL_OPENSPEC" = "Y" ]; then
339
369
  info "Installing OpenSpec CLI..."
340
370
  npm install -g @openspec/cli 2>/dev/null && {
@@ -439,7 +469,7 @@ fi
439
469
  if [ "$EXISTING_SETUP" = true ]; then
440
470
  echo ""
441
471
  warn "This repo already has some agent/command/openspec artifacts."
442
- if [ "$AUTO_YES" = true ]; then CONTINUE="y"; else read -p " Continue and merge with existing setup? (y/n): " CONTINUE; fi
472
+ if [ "$AUTO_YES" = true ]; then CONTINUE="y"; else read -p " Continue and merge with existing setup? (y/n): " CONTINUE || CONTINUE="n"; fi
443
473
  if [ "$CONTINUE" != "y" ] && [ "$CONTINUE" != "Y" ]; then
444
474
  info "Aborted. No changes made."
445
475
  exit 0
@@ -521,7 +551,9 @@ chmod +x "$REPO_ROOT/.specrails/bin/doctor.sh"
521
551
  ok "Installed specrails doctor (bin/doctor.sh)"
522
552
 
523
553
  # Copy templates (includes commands, skills, agents, rules, personas, settings)
524
- cp -r "$SCRIPT_DIR/templates/"* "$REPO_ROOT/$SPECRAILS_DIR/setup-templates/"
554
+ # Use tar to exclude node_modules and package-lock.json for performance
555
+ tar -C "$SCRIPT_DIR/templates" --exclude='node_modules' --exclude='package-lock.json' -cf - . \
556
+ | tar -C "$REPO_ROOT/$SPECRAILS_DIR/setup-templates/" -xf -
525
557
  ok "Installed setup templates (commands + skills)"
526
558
 
527
559
  # Write OSS detection results for /setup
@@ -542,7 +574,8 @@ cat > "$REPO_ROOT/$SPECRAILS_DIR/setup-templates/.provider-detection.json" << EO
542
574
  {
543
575
  "cli_provider": "$CLI_PROVIDER",
544
576
  "specrails_dir": "$SPECRAILS_DIR",
545
- "instructions_file": "$INSTRUCTIONS_FILE"
577
+ "instructions_file": "$INSTRUCTIONS_FILE",
578
+ "agent_teams": $AGENT_TEAMS
546
579
  }
547
580
  EOF
548
581
  ok "Provider detection results written ($CLI_PROVIDER → $SPECRAILS_DIR/)"
@@ -589,6 +622,10 @@ echo ""
589
622
  echo -e "${BOLD}${GREEN}Installation summary:${NC}"
590
623
  echo ""
591
624
  echo " Provider: $CLI_PROVIDER → output to $SPECRAILS_DIR/"
625
+ if [[ "$AGENT_TEAMS" == "true" ]]; then
626
+ echo " Agent Teams: installed (/sr:team-review, /sr:team-debug)"
627
+ echo " Feature flag: CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 (required)"
628
+ fi
592
629
  echo ""
593
630
  echo " Files installed:"
594
631
  if [[ "$CLI_PROVIDER" == "codex" ]]; then
@@ -35,5 +35,11 @@
35
35
  "refactor-recommender",
36
36
  "health-check",
37
37
  "compat-check"
38
- ]
38
+ ],
39
+ "ticketProvider": {
40
+ "type": "local",
41
+ "storageFile": "local-tickets.json",
42
+ "lockFile": "local-tickets.json.lock",
43
+ "capabilities": ["crud", "labels", "status", "priorities", "dependencies", "comments"]
44
+ }
39
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "specrails-core",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "AI agent workflow system for Claude Code — installs 12 specialized agents, orchestration commands, and persona-driven product discovery into any repository",
5
5
  "bin": {
6
6
  "specrails-core": "bin/specrails-core.js"
@@ -50,6 +50,10 @@
50
50
  "bugs": {
51
51
  "url": "https://github.com/fjpulidop/specrails-core/issues"
52
52
  },
53
+ "scripts": {
54
+ "test": "bash tests/run-all.sh",
55
+ "test:coverage": "bash tests/run-coverage.sh"
56
+ },
53
57
  "license": "MIT",
54
58
  "author": "fjpulidop"
55
59
  }
@@ -24,12 +24,22 @@ Check the environment variable `CLAUDE_CODE_ENTRYPOINT`. If it contains `remote_
24
24
 
25
25
  ### Checks to run (sequential, fail-fast)
26
26
 
27
- #### 1. GitHub CLI authentication
27
+ #### 1. Backlog provider availability
28
28
 
29
+ Read `.claude/backlog-config.json` and extract `BACKLOG_PROVIDER`.
30
+
31
+ **If `BACKLOG_PROVIDER=local`:**
29
32
  ```bash
30
- gh auth status 2>&1
33
+ [[ -f "$SPECRAILS_DIR/local-tickets.json" ]] && echo "Local tickets storage: OK" || echo "WARNING: local-tickets.json not found"
31
34
  ```
35
+ - Set `LOCAL_TICKETS_AVAILABLE=true/false` based on file existence.
36
+ - Set `GH_AVAILABLE=false` (GitHub CLI not needed for local provider).
37
+ - Set `BACKLOG_AVAILABLE=true` if local-tickets.json exists.
32
38
 
39
+ **Otherwise:**
40
+ ```bash
41
+ gh auth status 2>&1
42
+ ```
33
43
  - Set `GH_AVAILABLE=true/false` for later phases.
34
44
 
35
45
  #### 2. OpenSpec CLI
@@ -107,7 +117,7 @@ Initialize conflict-tracking variables:
107
117
  - Set `SINGLE_MODE = true`. No worktrees, no parallelism.
108
118
  - **Skip Phase 1 and Phase 2** — go directly to Phase 3a.
109
119
 
110
- **If the user passed issue/ticket references** (e.g. `#85, #71` for GitHub or `PROJ-85, PROJ-71` for JIRA):
120
+ **If the user passed issue/ticket references** (e.g. `#85, #71` for GitHub, `#1, #2` for local tickets, or `PROJ-85, PROJ-71` for JIRA):
111
121
  - Fetch each issue/ticket:
112
122
  ```bash
113
123
  {{BACKLOG_VIEW_CMD}}
@@ -120,7 +130,44 @@ Initialize conflict-tracking variables:
120
130
 
121
131
  After fetching issue refs, capture a baseline snapshot for conflict detection.
122
132
 
123
- **If `GH_AVAILABLE=true` and the input mode was issue numbers:**
133
+ ##### If `BACKLOG_PROVIDER=local` and input mode was issue numbers:
134
+
135
+ For each resolved ticket ID, read `$SPECRAILS_DIR/local-tickets.json` and extract the ticket object at `tickets["{id}"]`.
136
+
137
+ Build a snapshot object for each ticket:
138
+ - `number`: ticket `id` (integer)
139
+ - `title`: ticket `title` string
140
+ - `state`: map ticket `status` — `"done"` or `"cancelled"` → `"closed"`, otherwise → `"open"`
141
+ - `assignees`: `[ticket.assignee]` if non-null, else `[]`
142
+ - `labels`: ticket `labels` array, sorted alphabetically
143
+ - `body_sha`: SHA-256 of the ticket `description` string — compute with:
144
+ ```bash
145
+ echo -n "{description}" | sha256sum | cut -d' ' -f1
146
+ ```
147
+ If `sha256sum` is not available, fall back to `openssl dgst -sha256 -r` or `shasum -a 256`.
148
+ - `updated_at`: ticket `updated_at` value
149
+ - `captured_at`: current local time in ISO 8601 format
150
+
151
+ Write the following JSON to `.claude/backlog-cache.json` (overwrite fully — this establishes a fresh baseline for this run):
152
+
153
+ ```json
154
+ {
155
+ "schema_version": "1",
156
+ "provider": "local",
157
+ "last_updated": "<ISO 8601 timestamp>",
158
+ "written_by": "implement",
159
+ "issues": {
160
+ "<id>": { <snapshot object> },
161
+ ...
162
+ }
163
+ }
164
+ ```
165
+
166
+ If the write succeeds: set `SNAPSHOTS_CAPTURED=true`.
167
+
168
+ If the write fails: print `[backlog-cache] Warning: could not write cache. Conflict detection disabled for this run.` and set `SNAPSHOTS_CAPTURED=false`. Do NOT abort the pipeline.
169
+
170
+ ##### If `GH_AVAILABLE=true` and input mode was issue numbers (GitHub/JIRA):
124
171
 
125
172
  For each resolved issue number, run:
126
173
 
@@ -161,9 +208,9 @@ If the write succeeds: set `SNAPSHOTS_CAPTURED=true`.
161
208
 
162
209
  If the write fails (e.g., `.claude/` directory does not exist): print `[backlog-cache] Warning: could not write cache. Conflict detection disabled for this run.` and set `SNAPSHOTS_CAPTURED=false`. Do NOT abort the pipeline.
163
210
 
164
- **If `GH_AVAILABLE=false` or input was not issue numbers:**
211
+ ##### Otherwise (no backlog available or non-issue input):
165
212
 
166
- Set `SNAPSHOTS_CAPTURED=false`. Print: `[conflict-check] Snapshot skipped — GH unavailable or non-issue input.`
213
+ Set `SNAPSHOTS_CAPTURED=false`. Print: `[conflict-check] Snapshot skipped — backlog unavailable or non-issue input.`
167
214
 
168
215
  #### Gitignore advisory
169
216
 
@@ -267,7 +314,9 @@ Pick the single idea with the best impact/effort ratio from each exploration. Pr
267
314
 
268
315
  Otherwise, re-fetch each issue in scope and diff against the Phase 0 snapshot:
269
316
 
270
- For each issue number in `ISSUE_REFS`:
317
+ **If `BACKLOG_PROVIDER=local`:** For each ticket ID in `ISSUE_REFS`, read `$SPECRAILS_DIR/local-tickets.json` and extract the ticket at `tickets["{id}"]`. If the ticket does not exist (deleted): treat as a CRITICAL conflict — field `"state"`, was `<cached state>`, now `"deleted"`. Otherwise, reconstruct a current snapshot using the same mapping as the Phase 0 local snapshot.
318
+
319
+ **If `BACKLOG_PROVIDER=github`:** For each issue number in `ISSUE_REFS`:
271
320
 
272
321
  ```bash
273
322
  gh issue view {number} --json number,title,state,assignees,labels,body,updatedAt
@@ -275,7 +324,7 @@ gh issue view {number} --json number,title,state,assignees,labels,body,updatedAt
275
324
 
276
325
  If the `gh` command returns non-zero (issue deleted or inaccessible): treat as a CRITICAL conflict — field `"state"`, was `<cached state>`, now `"deleted"`.
277
326
 
278
- Otherwise, reconstruct a current snapshot (same shape as Phase 0: sort `assignees` and `labels`, compute `body_sha`).
327
+ In both cases, reconstruct a current snapshot (same shape as Phase 0: sort `assignees` and `labels`, compute `body_sha`).
279
328
 
280
329
  **Short-circuit:** If `current.updatedAt == cached.updated_at`, mark the issue as clean and skip field comparison.
281
330
 
@@ -848,6 +897,9 @@ This check is independent of Phase 3a.0. Even if the user chose to continue thro
848
897
 
849
898
  Re-fetch each issue in `ISSUE_REFS` and diff against `.claude/backlog-cache.json` using the same algorithm as Phase 3a.0:
850
899
 
900
+ **If `BACKLOG_PROVIDER=local`:** Read `$SPECRAILS_DIR/local-tickets.json` and extract each ticket by ID.
901
+
902
+ **If `BACKLOG_PROVIDER=github`:**
851
903
  ```bash
852
904
  gh issue view {number} --json number,title,state,assignees,labels,body,updatedAt
853
905
  ```
@@ -881,8 +933,12 @@ Record skipped operations to `.cache-manifest.json` under `skipped_operations`:
881
933
  - `"git: commit"`
882
934
  - `"git: push"`
883
935
  - `"github: pr creation"` (if `GH_AVAILABLE=true`)
884
- - `"github: issue comment #N"` for each issue in scope (if `BACKLOG_WRITE=true`)
885
- - `"github: issue close #N (via PR merge)"` for each fully resolved issue (if `BACKLOG_WRITE=true`)
936
+ - If `BACKLOG_PROVIDER=local` and `BACKLOG_WRITE=true`:
937
+ - `"local: ticket comment #{id}"` for each ticket in scope
938
+ - `"local: ticket status update #{id}"` for each fully resolved ticket
939
+ - If `BACKLOG_PROVIDER=github` and `BACKLOG_WRITE=true`:
940
+ - `"github: issue comment #N"` for each issue in scope
941
+ - `"github: issue close #N (via PR merge)"` for each fully resolved issue
886
942
 
887
943
  Then skip the rest of Phase 4c and proceed directly to Phase 4e.
888
944
 
@@ -934,17 +990,19 @@ All implementation is complete and CI checks pass.
934
990
  #### Backlog updates (both modes)
935
991
 
936
992
  **If `BACKLOG_WRITE=true`:**
937
- - For fully resolved issues/tickets: add a comment noting completion and reference the PR. Do NOT close the issue explicitly — use `Closes #N` in the PR body so GitHub/JIRA closes it automatically when the PR is merged:
993
+ - For fully resolved issues/tickets: add a comment noting completion and reference the PR:
938
994
  ```bash
939
995
  {{BACKLOG_COMMENT_CMD}}
940
996
  ```
941
- - GitHub: `gh issue comment {number} --body "Implemented in PR #XX. All acceptance criteria met."`
942
- - JIRA: `jira issue comment {key} --message "Implemented in PR #XX. All acceptance criteria met."`
943
- - Ensure the PR body includes `Closes #N` for each fully resolved issue (GitHub auto-closes on merge)
997
+ - **Local:** Update the ticket status to `"done"` using `{{BACKLOG_UPDATE_CMD}}` and add a comment: `"Implemented in PR #XX. All acceptance criteria met."` via `{{BACKLOG_COMMENT_CMD}}`. Local tickets are closed directly — there is no auto-close-on-merge mechanism.
998
+ - **GitHub:** `gh issue comment {number} --body "Implemented in PR #XX. All acceptance criteria met."` — do NOT close the issue explicitly. Use `Closes #N` in the PR body so GitHub auto-closes on merge.
999
+ - **JIRA:** `jira issue comment {key} --message "Implemented in PR #XX. All acceptance criteria met."`
1000
+ - For GitHub/JIRA: ensure the PR body includes `Closes #N` for each fully resolved issue (auto-closes on merge)
944
1001
  - For partially resolved issues/tickets: add a comment noting progress:
945
1002
  ```bash
946
1003
  {{BACKLOG_PARTIAL_COMMENT_CMD}}
947
1004
  ```
1005
+ - **Local:** Additionally update the ticket status to `"in_progress"` via `{{BACKLOG_UPDATE_CMD}}` if it is still `"todo"`.
948
1006
 
949
1007
  **If `BACKLOG_WRITE=false`:**
950
1008
  - Do NOT create, modify, or comment on any issues/tickets.
@@ -161,6 +161,33 @@ The product-analyst receives this prompt:
161
161
 
162
162
  7. **[Orchestrator]** After the product-analyst completes, write issue snapshots to `.claude/backlog-cache.json`.
163
163
 
164
+ #### If provider=local — Cache from Local Tickets
165
+
166
+ Read `$SPECRAILS_DIR/local-tickets.json` and parse the `tickets` map. For each ticket with `"product-driven-backlog"` in its `labels` array and `status` not `"cancelled"`, build a snapshot object:
167
+ - `number`: ticket `id` (integer)
168
+ - `title`: ticket `title` string
169
+ - `state`: map ticket `status` — `"done"` or `"cancelled"` → `"closed"`, otherwise → `"open"`
170
+ - `assignees`: `[ticket.assignee]` if non-null, else `[]`
171
+ - `labels`: ticket `labels` array, sorted alphabetically
172
+ - `body_sha`: SHA-256 of the ticket `description` string — compute with:
173
+ ```bash
174
+ echo -n "{description}" | sha256sum | cut -d' ' -f1
175
+ ```
176
+ If `sha256sum` is not available, fall back to `openssl dgst -sha256 -r` or `shasum -a 256`.
177
+ - `updated_at`: ticket `updated_at` value
178
+ - `captured_at`: current local time in ISO 8601 format
179
+
180
+ Write to `.claude/backlog-cache.json` with:
181
+ - `schema_version`: `"1"`
182
+ - `provider`: `"local"`
183
+ - `last_updated`: current ISO 8601 timestamp
184
+ - `written_by`: `"product-backlog"`
185
+ - `issues`: the map keyed by string ticket ID
186
+
187
+ If the write fails: print `[backlog-cache] Warning: could not write cache. Continuing.` Do not abort.
188
+
189
+ #### If provider=github — Cache from GitHub Issues
190
+
164
191
  **Guard:** If `GH_AVAILABLE=false` (from Phase 0 pre-flight), print `[backlog-cache] Skipped — GH unavailable.` and return. Do not attempt the write.
165
192
 
166
193
  **Fetch all open backlog issues in one call:**
@@ -193,3 +220,7 @@ The product-analyst receives this prompt:
193
220
  - `issues`: the merged map keyed by string issue number
194
221
 
195
222
  If the write fails (e.g., `.claude/` directory does not exist): print `[backlog-cache] Warning: could not write cache. Continuing.` Do not abort.
223
+
224
+ #### If provider=jira or provider=none
225
+
226
+ Print `[backlog-cache] Skipped — provider does not support cache.` Do not attempt the write.
@@ -42,3 +42,59 @@ Output ONLY the following structured markdown. Do not add any preamble or explan
42
42
  ## Estimated Complexity
43
43
  [One of: Low (< 1 day) / Medium (1-3 days) / High (3-7 days) / Very High (> 1 week)]
44
44
  [One sentence justifying the estimate]
45
+
46
+ ---
47
+
48
+ ## Backlog Sync
49
+
50
+ After generating the proposal, read `.claude/backlog-config.json` to determine `BACKLOG_PROVIDER` and `BACKLOG_WRITE`.
51
+
52
+ ### If provider=local — Create Local Ticket
53
+
54
+ Create a local ticket from the proposal output:
55
+
56
+ ```
57
+ {{BACKLOG_CREATE_CMD}}
58
+ ```
59
+
60
+ Set the following fields:
61
+ - `title`: The Spec Title from the proposal
62
+ - `description`: The full structured proposal markdown (all sections from Problem Statement through Estimated Complexity)
63
+ - `status`: `"todo"`
64
+ - `priority`: Map Estimated Complexity — Low → `"low"`, Medium → `"medium"`, High/Very High → `"high"`
65
+ - `labels`: `["spec-proposal"]`
66
+ - `source`: `"propose-spec"`
67
+ - `created_by`: `"sr-product-engineer"`
68
+
69
+ Print: `Created local ticket #{id}: {title}`
70
+
71
+ ### If provider=github and BACKLOG_WRITE=true — Create GitHub Issue
72
+
73
+ ```bash
74
+ {{BACKLOG_CREATE_CMD}}
75
+ ```
76
+
77
+ Create a GitHub Issue with:
78
+ - Title: The Spec Title
79
+ - Body: Full structured proposal markdown
80
+ - Labels: `spec-proposal`
81
+
82
+ Print: `Created GitHub Issue #{number}: {title}`
83
+
84
+ ### If provider=jira and BACKLOG_WRITE=true — Create JIRA Story
85
+
86
+ Create a JIRA Story using the same authentication and API pattern as `/sr:update-product-driven-backlog`:
87
+ - Summary: The Spec Title
88
+ - Description: Full structured proposal in Atlassian Document Format
89
+ - Labels: `spec-proposal`
90
+
91
+ Print: `Created JIRA ticket {key}: {title}`
92
+
93
+ ### If BACKLOG_WRITE=false or provider=none
94
+
95
+ Do NOT create any tickets. Print:
96
+ ```
97
+ Spec proposal ready. Create a ticket manually if desired:
98
+ Title: {Spec Title}
99
+ Complexity: {Estimated Complexity}
100
+ ```
@@ -0,0 +1,286 @@
1
+ ---
2
+ name: "Team Debug"
3
+ description: "Collaborative debugging using Claude Code Agent Teams. Multiple investigators pursue competing hypotheses independently, challenge each other's findings, and produce a root cause analysis ranked by confidence."
4
+ category: Workflow
5
+ tags: [workflow, debugging, agent-teams, investigation]
6
+ ---
7
+
8
+ Collaborative debugging for **{{PROJECT_NAME}}** using Claude Code Agent Teams. Multiple investigators pursue competing hypotheses about a bug, challenge each other's findings, and produce a confidence-ranked root cause analysis.
9
+
10
+ **Input:** $ARGUMENTS — required: a bug description in one of these forms:
11
+ - `"Login fails silently when email has uppercase letters"` — free text bug description
12
+ - `tests/auth.test.ts` — a failing test file path
13
+ - `"TypeError: Cannot read property 'id' of undefined"` — an error message or stack trace
14
+ - `#42` — a GitHub issue number
15
+
16
+ Optional flags:
17
+ - `--scope <paths>` — comma-separated file/directory paths to constrain investigation (default: entire repo)
18
+ - `--depth <level>` — investigation depth: `shallow`, `normal` (default), `deep`
19
+
20
+ ---
21
+
22
+ ## Phase 0: Feature Flag Guard
23
+
24
+ **This check is mandatory and runs before anything else.**
25
+
26
+ Check whether Agent Teams is enabled:
27
+
28
+ ```bash
29
+ echo "${CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS:-}"
30
+ ```
31
+
32
+ If the variable is unset or not equal to `1`, print this message and **stop immediately**:
33
+
34
+ ```
35
+ Error: Agent Teams is an experimental feature that requires opt-in.
36
+
37
+ To enable it, set the environment variable before starting Claude Code:
38
+
39
+ export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
40
+
41
+ Agent Teams requires Claude Code v2.1.32 or later.
42
+ ```
43
+
44
+ Do NOT proceed past this point if the guard fails.
45
+
46
+ ---
47
+
48
+ ## Phase 1: Bug Context Gathering
49
+
50
+ Parse `$ARGUMENTS` to determine the bug context and flags.
51
+
52
+ **Variables to set:**
53
+
54
+ - `BUG_DESCRIPTION` — the user's description of the bug
55
+ - `INPUT_TYPE` — `"text"`, `"test"`, `"error"`, or `"issue"`
56
+ - `SCOPE_PATHS` — from `--scope` flag or `["."]` (entire repo)
57
+ - `INVESTIGATION_DEPTH` — from `--depth` flag or `"normal"`
58
+
59
+ **Detection rules:**
60
+
61
+ 1. If input starts with `#` or is a bare integer -> `INPUT_TYPE="issue"`, fetch issue body via `gh issue view <number> --json title,body`
62
+ 2. If input is a file path that exists and contains `test` or `spec` -> `INPUT_TYPE="test"`, run the test to capture failure output
63
+ 3. If input contains common error patterns (stack trace, `Error:`, `Exception`, `FATAL`) -> `INPUT_TYPE="error"`
64
+ 4. Otherwise -> `INPUT_TYPE="text"`
65
+
66
+ If `$ARGUMENTS` is empty, print usage and stop:
67
+ ```
68
+ Usage: /sr:team-debug <bug-description> [--scope <paths>] [--depth <level>]
69
+
70
+ Examples:
71
+ /sr:team-debug "Login fails silently when email has uppercase letters"
72
+ /sr:team-debug tests/auth.test.ts --depth deep
73
+ /sr:team-debug "TypeError: Cannot read property 'id' of undefined" --scope src/api
74
+ /sr:team-debug #42
75
+ ```
76
+
77
+ ---
78
+
79
+ ## Phase 2: Hypothesis Generation
80
+
81
+ Analyze the bug context and generate competing hypotheses:
82
+
83
+ 1. **Analyze symptoms**: Read relevant source files within `SCOPE_PATHS`, examine recent git changes (`git log --oneline -20` for the relevant paths), check related tests
84
+ 2. **Generate hypotheses**: Produce 2-3 distinct, testable hypotheses about the root cause. Each must target a different subsystem, mechanism, or failure mode.
85
+ 3. **Rank hypotheses**: Order by initial likelihood based on available evidence
86
+
87
+ Each hypothesis MUST include:
88
+ - **Title**: One-line description of the proposed cause
89
+ - **Rationale**: Why this is plausible given the symptoms
90
+ - **Investigation plan**: Specific files to examine, commands to run, patterns to search for
91
+ - **Expected evidence**: What would confirm or refute this hypothesis
92
+
93
+ Decide whether to launch 2 or 3 investigators:
94
+ - Default: 2 investigators (Hypothesis A and B)
95
+ - Launch 3 when: `--depth deep` is set, OR the bug description is ambiguous enough to warrant three genuinely distinct hypotheses
96
+
97
+ Print the hypothesis summary:
98
+ ```
99
+ ## Bug Analysis
100
+
101
+ **Input type:** <text / test / error / issue>
102
+ **Scope:** <SCOPE_PATHS>
103
+ **Depth:** <INVESTIGATION_DEPTH>
104
+
105
+ ### Hypotheses
106
+
107
+ 1. **<Hypothesis A title>** (initial confidence: X%)
108
+ <one-line rationale>
109
+
110
+ 2. **<Hypothesis B title>** (initial confidence: Y%)
111
+ <one-line rationale>
112
+
113
+ 3. **<Hypothesis C title>** (initial confidence: Z%) [if applicable]
114
+ <one-line rationale>
115
+
116
+ Launching <N> investigators...
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Phase 3: Launch Investigation Team
122
+
123
+ Create 2-3 investigator teammates using Agent Teams. Each teammate receives the bug context and their assigned hypothesis.
124
+
125
+ **IMPORTANT:** Use the Agent Teams teammate mechanism — NOT the Agent tool's `subagent_type`. Teammates share a task list and can message each other via mailbox.
126
+
127
+ ### Investigator A: Primary Hypothesis
128
+
129
+ **Prompt:**
130
+ ```
131
+ You are Investigator A on a debugging team. Your job is to prove or disprove your assigned hypothesis through systematic investigation.
132
+
133
+ ## Bug Context
134
+ <BUG_DESCRIPTION>
135
+ <additional context gathered in Phase 1: test output, error details, issue body>
136
+
137
+ ## Your Hypothesis
138
+ **<Hypothesis A title>**
139
+ <Hypothesis A rationale>
140
+
141
+ ## Investigation Plan
142
+ <Hypothesis A investigation plan>
143
+
144
+ ## Scope
145
+ Limit your investigation to: <SCOPE_PATHS>
146
+
147
+ ## Instructions
148
+ 1. Follow your investigation plan systematically
149
+ 2. Read source files, search for patterns, examine git history within scope
150
+ 3. Collect concrete evidence — file paths, line numbers, code snippets, command output
151
+ 4. Determine a confidence level (0-100%) that your hypothesis is the root cause
152
+ 5. After completing your investigation, read the other investigators' findings from the task list
153
+ 6. If you find evidence that supports or contradicts another investigator's hypothesis, send a mailbox message challenging or endorsing their findings
154
+ 7. Do NOT modify any files — this is a read-only investigation
155
+
156
+ ## Report Format
157
+ Post your findings as a task list update:
158
+
159
+ ### Investigator A: <Hypothesis Title>
160
+
161
+ #### Evidence Found
162
+ | # | Type | Location | Finding |
163
+ |---|------|----------|---------|
164
+ | 1 | code/git/test/config | file:line | What was found |
165
+
166
+ #### Evidence Against
167
+ <any evidence that contradicts this hypothesis>
168
+
169
+ #### Confidence: X%
170
+ <explanation of confidence level>
171
+
172
+ #### Verdict
173
+ <CONFIRMED / REFUTED / INCONCLUSIVE>
174
+ <brief explanation>
175
+ ```
176
+
177
+ ### Investigator B: Alternative Hypothesis
178
+
179
+ Same structure as Investigator A, with Hypothesis B title, rationale, investigation plan, and expected evidence.
180
+
181
+ ### Investigator C: Contrarian Hypothesis (when applicable)
182
+
183
+ Same structure as Investigator A, with Hypothesis C title, rationale, investigation plan, and expected evidence. Only launched when 3 hypotheses are generated.
184
+
185
+ ### Team Coordination
186
+
187
+ After launching all investigators:
188
+
189
+ 1. Wait for all investigators to complete their independent investigations (posted to the shared task list)
190
+ 2. Allow one round of cross-investigation challenge via mailbox — each investigator may respond to findings from the others
191
+ 3. Collect all findings and challenge outcomes
192
+
193
+ If any teammate fails to respond, proceed with available findings and note the gap in the final report.
194
+
195
+ ---
196
+
197
+ ## Phase 4: Root Cause Synthesis
198
+
199
+ After all investigations and challenges are complete, the team lead produces the root cause analysis.
200
+
201
+ ### Step 1: Evidence Aggregation
202
+
203
+ 1. Read all investigator reports from the task list
204
+ 2. Identify converging evidence (multiple investigators pointing to the same cause)
205
+ 3. Identify conflicting evidence and note unresolved disagreements
206
+ 4. Read any mailbox challenge messages for cross-investigator insights
207
+
208
+ ### Step 2: Confidence Recalibration
209
+
210
+ Adjust hypothesis confidence levels based on cross-investigation challenges:
211
+ - A hypothesis endorsed by evidence from another investigator: confidence boost (+10-20%)
212
+ - A hypothesis contradicted by another investigator's evidence: confidence reduction (-10-30%)
213
+ - A hypothesis with no cross-investigation interaction: confidence unchanged
214
+ - Converging evidence from multiple investigators: strongest signal for root cause
215
+
216
+ ### Step 3: Render Report
217
+
218
+ ```markdown
219
+ ## Root Cause Analysis
220
+
221
+ **Bug:** <one-line bug description>
222
+ **Scope:** <SCOPE_PATHS>
223
+ **Depth:** <INVESTIGATION_DEPTH>
224
+ **Investigators:** <N>
225
+
226
+ ---
227
+
228
+ ### Most Likely Root Cause
229
+
230
+ **<Winning hypothesis title>** — Confidence: X%
231
+
232
+ <2-3 sentence explanation of the root cause with specific file and line references>
233
+
234
+ #### Key Evidence
235
+ | # | Location | Finding |
236
+ |---|----------|---------|
237
+ | 1 | file:line | Evidence supporting this conclusion |
238
+
239
+ #### Suggested Fix
240
+ <specific, actionable fix recommendation with file and line references>
241
+
242
+ ---
243
+
244
+ ### Alternative Hypotheses
245
+
246
+ | # | Hypothesis | Initial | Final | Verdict | Key Evidence |
247
+ |---|-----------|---------|-------|---------|-------------|
248
+ | 1 | <title> | X% | Y% | CONFIRMED/REFUTED/INCONCLUSIVE | <one-line> |
249
+ | 2 | <title> | X% | Y% | CONFIRMED/REFUTED/INCONCLUSIVE | <one-line> |
250
+
251
+ ### Investigation Trail
252
+
253
+ <for each investigator, a 2-3 line summary of what they investigated and what they found>
254
+
255
+ ### Cross-Investigation Notes
256
+
257
+ <any points of challenge or agreement between investigators, with resolution>
258
+
259
+ ---
260
+
261
+ ### Recommended Next Steps
262
+
263
+ 1. <most important action — typically the fix>
264
+ 2. <verification step — test to confirm the fix>
265
+ 3. <preventive step — how to avoid this class of bug>
266
+ ```
267
+
268
+ ### Step 4: Cost Notice
269
+
270
+ Print a brief cost notice after the report:
271
+
272
+ ```
273
+ Note: Team debug used ~<N>x the tokens of a single-agent investigation (<N> parallel investigators + challenge round).
274
+ ```
275
+
276
+ ---
277
+
278
+ ## Rules
279
+
280
+ - This command is **read-only** — it MUST NOT create, modify, or delete any files
281
+ - All investigators run as Agent Teams teammates, not as Agent tool subagents
282
+ - If Agent Teams is unavailable at runtime (API error, version mismatch), fall back to running 2-3 sequential Agent tool subagents and skip the challenge phase. Print a warning about the fallback.
283
+ - The challenge phase is limited to one round per investigator to control token costs
284
+ - Findings MUST include file paths and line numbers — vague findings are not acceptable
285
+ - Investigation MUST stay within `SCOPE_PATHS` if specified
286
+ - This command is Claude Code only — it is NOT installed when the provider is `codex`
@@ -0,0 +1,341 @@
1
+ ---
2
+ name: "Team Review"
3
+ description: "Multi-perspective code review using Claude Code Agent Teams. Three specialized reviewers (security, performance, correctness) independently review changes, debate findings, and produce a consolidated report."
4
+ category: Workflow
5
+ tags: [workflow, review, agent-teams, security, performance]
6
+ ---
7
+
8
+ Multi-perspective code review for **{{PROJECT_NAME}}** using Claude Code Agent Teams. Three specialized reviewers analyze changes independently, debate cross-cutting findings, and produce a consolidated report.
9
+
10
+ **Input:** $ARGUMENTS — required: a review target in one of these forms:
11
+ - `#123` — review a pull request by number
12
+ - `feat/my-feature` — review a branch diff against base
13
+ - `abc1234..def5678` — review a commit range
14
+
15
+ Optional flags:
16
+ - `--base <branch>` — override base branch for comparison (default: repository default branch)
17
+ - `--focus <areas>` — comma-separated focus areas to weight: `security`, `performance`, `correctness`, `tests`, `types`
18
+
19
+ ---
20
+
21
+ ## Phase 0: Feature Flag Guard
22
+
23
+ **This check is mandatory and runs before anything else.**
24
+
25
+ Check whether Agent Teams is enabled:
26
+
27
+ ```bash
28
+ echo "${CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS:-}"
29
+ ```
30
+
31
+ If the variable is unset or not equal to `1`, print this message and **stop immediately**:
32
+
33
+ ```
34
+ Error: Agent Teams is an experimental feature that requires opt-in.
35
+
36
+ To enable it, set the environment variable before starting Claude Code:
37
+
38
+ export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
39
+
40
+ Agent Teams requires Claude Code v2.1.32 or later.
41
+ ```
42
+
43
+ Do NOT proceed past this point if the guard fails.
44
+
45
+ ---
46
+
47
+ ## Phase 1: Input Parsing
48
+
49
+ Parse `$ARGUMENTS` to determine the review target and flags.
50
+
51
+ **Variables to set:**
52
+
53
+ - `REVIEW_TARGET` — the PR number, branch name, or commit range
54
+ - `REVIEW_TYPE` — `"pr"`, `"branch"`, or `"range"`
55
+ - `BASE_BRANCH` — from `--base` flag or detect via `gh repo view --json defaultBranchRef -q '.defaultBranchRef.name'` or fall back to `main`
56
+ - `FOCUS_AREAS` — array from `--focus` flag or `["all"]`
57
+
58
+ **Detection rules:**
59
+
60
+ 1. If input starts with `#` or is a bare integer → `REVIEW_TYPE="pr"`, strip `#` prefix
61
+ 2. If input contains `..` → `REVIEW_TYPE="range"`
62
+ 3. Otherwise → `REVIEW_TYPE="branch"`
63
+
64
+ If `$ARGUMENTS` is empty, print usage and stop:
65
+ ```
66
+ Usage: /sr:team-review <target> [--base <branch>] [--focus <areas>]
67
+
68
+ Examples:
69
+ /sr:team-review #42
70
+ /sr:team-review feat/new-auth --focus security
71
+ /sr:team-review abc123..def456
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Phase 2: Gather Diff
77
+
78
+ Collect the code changes based on `REVIEW_TYPE`:
79
+
80
+ - **PR**: Run `gh pr diff <REVIEW_TARGET>` and `gh pr diff <REVIEW_TARGET> --name-only`
81
+ - **Branch**: Run `git diff ${BASE_BRANCH}...${REVIEW_TARGET}` and `git diff --name-only ${BASE_BRANCH}...${REVIEW_TARGET}`
82
+ - **Range**: Run `git diff ${REVIEW_TARGET}` and `git diff --name-only ${REVIEW_TARGET}`
83
+
84
+ Also collect file-level stats: `git diff --stat <appropriate-range>`
85
+
86
+ **Store these variables for Phase 3:**
87
+ - `DIFF_CONTENT` — full unified diff
88
+ - `CHANGED_FILES` — list of changed file paths
89
+ - `DIFF_STATS` — file-level line count changes
90
+
91
+ If the diff is empty, print `No changes found for the given review target.` and stop.
92
+
93
+ Print a summary:
94
+ ```
95
+ ## Review Target
96
+ Type: <PR / Branch / Range>
97
+ Target: <REVIEW_TARGET>
98
+ Base: <BASE_BRANCH>
99
+ Changed files: <N>
100
+ Focus: <FOCUS_AREAS or "all areas">
101
+
102
+ <DIFF_STATS output>
103
+ ```
104
+
105
+ ---
106
+
107
+ ## Phase 3: Launch Team Review
108
+
109
+ Create three reviewer teammates using Agent Teams. Each teammate receives the full diff and file list.
110
+
111
+ **IMPORTANT:** Use the Agent Teams teammate mechanism — NOT the Agent tool's `subagent_type`. Teammates share a task list and can message each other via mailbox.
112
+
113
+ ### Teammate 1: Security Reviewer
114
+
115
+ **Persona:** sr-security-reviewer (or sr-reviewer with security focus if persona not available)
116
+
117
+ **Prompt:**
118
+ ```
119
+ You are the Security Reviewer on a team code review.
120
+
121
+ ## Your Focus Areas
122
+ - Authentication and authorization flaws
123
+ - Input validation and injection vulnerabilities (SQL, XSS, command injection)
124
+ - Secrets or credentials in code
125
+ - OWASP Top 10 vulnerabilities
126
+ - Insecure dependencies or configurations
127
+ - Missing rate limiting or access controls
128
+
129
+ ## Changed Files
130
+ <CHANGED_FILES>
131
+
132
+ ## Diff
133
+ <DIFF_CONTENT>
134
+
135
+ ## Instructions
136
+ 1. Review every changed file through a security lens
137
+ 2. Report findings using the format below — be specific about file, line, and fix
138
+ 3. After completing your review, read the other reviewers' findings from the task list
139
+ 4. If you have security-relevant context on their findings, send a mailbox message
140
+
141
+ ## Report Format
142
+ Post your findings as a task list update:
143
+
144
+ ### Security Review Findings
145
+
146
+ #### Summary
147
+ <1-2 sentences>
148
+
149
+ #### Findings
150
+ | # | Severity | File | Line(s) | Finding | Recommendation |
151
+ |---|----------|------|---------|---------|----------------|
152
+
153
+ #### Verdict
154
+ <APPROVE / REQUEST_CHANGES / COMMENT>
155
+ ```
156
+
157
+ ### Teammate 2: Performance Reviewer
158
+
159
+ **Persona:** sr-performance-reviewer (or sr-reviewer with performance focus if persona not available)
160
+
161
+ **Prompt:**
162
+ ```
163
+ You are the Performance Reviewer on a team code review.
164
+
165
+ ## Your Focus Areas
166
+ - Database query complexity and N+1 queries
167
+ - Missing or broken caching
168
+ - Memory leaks and excessive allocations
169
+ - Algorithmic complexity (O(n^2) or worse in hot paths)
170
+ - Bundle size and lazy loading concerns (frontend)
171
+ - Missing pagination or unbounded data fetching
172
+
173
+ ## Changed Files
174
+ <CHANGED_FILES>
175
+
176
+ ## Diff
177
+ <DIFF_CONTENT>
178
+
179
+ ## Instructions
180
+ 1. Review every changed file through a performance lens
181
+ 2. Report findings using the format below — be specific about file, line, and fix
182
+ 3. After completing your review, read the other reviewers' findings from the task list
183
+ 4. If you have performance-relevant context on their findings, send a mailbox message
184
+
185
+ ## Report Format
186
+ Post your findings as a task list update:
187
+
188
+ ### Performance Review Findings
189
+
190
+ #### Summary
191
+ <1-2 sentences>
192
+
193
+ #### Findings
194
+ | # | Severity | File | Line(s) | Finding | Recommendation |
195
+ |---|----------|------|---------|---------|----------------|
196
+
197
+ #### Verdict
198
+ <APPROVE / REQUEST_CHANGES / COMMENT>
199
+ ```
200
+
201
+ ### Teammate 3: Correctness Reviewer
202
+
203
+ **Persona:** sr-reviewer
204
+
205
+ **Prompt:**
206
+ ```
207
+ You are the Correctness Reviewer on a team code review.
208
+
209
+ ## Your Focus Areas
210
+ - Logic errors and edge cases
211
+ - Missing or inadequate test coverage
212
+ - Type safety violations
213
+ - Error handling gaps (uncaught exceptions, missing error paths)
214
+ - API contract mismatches
215
+ - Race conditions and concurrency issues
216
+
217
+ ## Changed Files
218
+ <CHANGED_FILES>
219
+
220
+ ## Diff
221
+ <DIFF_CONTENT>
222
+
223
+ ## Instructions
224
+ 1. Review every changed file through a correctness and test coverage lens
225
+ 2. Report findings using the format below — be specific about file, line, and fix
226
+ 3. After completing your review, read the other reviewers' findings from the task list
227
+ 4. If you have correctness-relevant context on their findings, send a mailbox message
228
+
229
+ ## Report Format
230
+ Post your findings as a task list update:
231
+
232
+ ### Correctness Review Findings
233
+
234
+ #### Summary
235
+ <1-2 sentences>
236
+
237
+ #### Findings
238
+ | # | Severity | File | Line(s) | Finding | Recommendation |
239
+ |---|----------|------|---------|---------|----------------|
240
+
241
+ #### Verdict
242
+ <APPROVE / REQUEST_CHANGES / COMMENT>
243
+ ```
244
+
245
+ ### Team Coordination
246
+
247
+ After launching all three teammates:
248
+
249
+ 1. Wait for all three to complete their independent reviews (posted to the shared task list)
250
+ 2. Allow one round of cross-review debate via mailbox — each reviewer may respond to findings from the other two
251
+ 3. Collect all findings and debate outcomes
252
+
253
+ If any teammate fails to respond, proceed with available reviews and note the gap in the final report.
254
+
255
+ ---
256
+
257
+ ## Phase 4: Synthesize Consolidated Report
258
+
259
+ After all reviews and debate are complete, the team lead produces the final report.
260
+
261
+ ### Step 1: Collect and Deduplicate
262
+
263
+ 1. Read all three reviewer reports from the task list
264
+ 2. Identify duplicate findings (same file + overlapping lines + similar issue)
265
+ 3. For duplicates: keep the highest-severity version, note which reviewers flagged it
266
+
267
+ ### Step 2: Apply Focus Weighting
268
+
269
+ If `FOCUS_AREAS` is not `["all"]`:
270
+ - Findings in focus areas get their severity preserved
271
+ - Findings outside focus areas: Critical stays Critical, but High→Medium, Medium→Low for display purposes
272
+ - Note the weighting in the report header
273
+
274
+ ### Step 3: Render Report
275
+
276
+ ```markdown
277
+ ## Team Review Report
278
+
279
+ **Target:** <PR #N / branch-name / commit-range>
280
+ **Base:** <BASE_BRANCH>
281
+ **Reviewers:** Security, Performance, Correctness
282
+ **Changed files:** N files (+X/-Y lines)
283
+ **Focus:** <FOCUS_AREAS or "all areas equally weighted">
284
+
285
+ ---
286
+
287
+ ### Critical Findings (action required before merge)
288
+
289
+ | # | Severity | Domain | File | Line(s) | Finding | Recommendation | Flagged By |
290
+ |---|----------|--------|------|---------|---------|----------------|------------|
291
+
292
+ ### High-Priority Findings
293
+
294
+ | # | Severity | Domain | File | Line(s) | Finding | Recommendation | Flagged By |
295
+ |---|----------|--------|------|---------|---------|----------------|------------|
296
+
297
+ ### Medium & Low Findings
298
+
299
+ | # | Severity | Domain | File | Line(s) | Finding | Recommendation |
300
+ |---|----------|--------|------|---------|---------|----------------|
301
+
302
+ ### Praise (things done well)
303
+ <positive observations from reviewers>
304
+
305
+ ---
306
+
307
+ ### Cross-Review Notes
308
+ <any points of debate or disagreement between reviewers, with resolution>
309
+
310
+ ---
311
+
312
+ ### Reviewer Verdicts
313
+
314
+ | Reviewer | Verdict | Critical | High | Medium | Low | Info |
315
+ |----------|---------|----------|------|--------|-----|------|
316
+ | Security | APPROVE/REQUEST_CHANGES | N | N | N | N | N |
317
+ | Performance | APPROVE/REQUEST_CHANGES | N | N | N | N | N |
318
+ | Correctness | APPROVE/REQUEST_CHANGES | N | N | N | N | N |
319
+
320
+ ### Overall Verdict: <APPROVE / REQUEST_CHANGES>
321
+
322
+ <one-paragraph summary: key risks, recommended actions, and overall assessment>
323
+ ```
324
+
325
+ ### Step 4: Cost Notice
326
+
327
+ Print a brief cost notice after the report:
328
+
329
+ ```
330
+ Note: Team review used ~3x the tokens of a single-reviewer run (3 parallel reviewers + debate round).
331
+ ```
332
+
333
+ ---
334
+
335
+ ## Rules
336
+
337
+ - This command is **read-only** — it MUST NOT create, modify, or delete any files
338
+ - All three reviewers run as Agent Teams teammates, not as Agent tool subagents
339
+ - If Agent Teams is unavailable at runtime (API error, version mismatch), fall back to running three sequential Agent tool subagents with `subagent_type: sr-reviewer` and skip the debate phase. Print a warning about the fallback.
340
+ - The debate phase is limited to one round per reviewer to control token costs
341
+ - Findings MUST include file paths and line numbers — vague findings are not acceptable
@@ -68,7 +68,7 @@ After the Explore agent completes:
68
68
  1. **Display** results to the user.
69
69
 
70
70
  2. Read `.claude/backlog-config.json` and extract:
71
- - `BACKLOG_PROVIDER` (`github`, `jira`, or `none`)
71
+ - `BACKLOG_PROVIDER` (`local`, `github`, `jira`, or `none`)
72
72
  - `BACKLOG_WRITE` (from `write_access`)
73
73
 
74
74
  ### If `BACKLOG_WRITE=false` — Display only (no sync)
@@ -98,6 +98,46 @@ After the Explore agent completes:
98
98
 
99
99
  4. **Do NOT** create, modify, or comment on any issues/tickets.
100
100
 
101
+ ### If provider=local — Sync to Local Tickets
102
+
103
+ Local tickets are always read-write. Sync directly to `$SPECRAILS_DIR/local-tickets.json`.
104
+
105
+ 3. **Fetch existing local tickets** to avoid duplicates:
106
+ ```
107
+ {{BACKLOG_FETCH_ALL_CMD}}
108
+ ```
109
+ Collect all ticket titles into a duplicate-check set.
110
+
111
+ 4. **Initialize labels** (idempotent):
112
+ ```
113
+ {{BACKLOG_INIT_LABELS_CMD}}
114
+ ```
115
+
116
+ 5. **For each proposed feature, create a local ticket** (skip if title matches an existing ticket):
117
+ ```
118
+ {{BACKLOG_CREATE_CMD}}
119
+ ```
120
+ Set the following fields on each new ticket:
121
+ - `title`: Feature name
122
+ - `description`: Full VPC body markdown (same format as the GitHub/JIRA issue body above)
123
+ - `status`: `"todo"`
124
+ - `priority`: Map effort to priority — Low effort → `"high"` priority, Medium → `"medium"`, High → `"low"`
125
+ - `labels`: `["product-driven-backlog", "area:{area}"]`
126
+ - `metadata.vpc_scores`: Object with per-persona scores from the VPC evaluation
127
+ - `metadata.effort_level`: `"High"`, `"Medium"`, or `"Low"`
128
+ - `metadata.user_story`: The user story text
129
+ - `metadata.area`: The area name (without `area:` prefix)
130
+ - `prerequisites`: Array of ticket IDs for any features this depends on (empty if none)
131
+ - `source`: `"product-backlog"`
132
+ - `created_by`: `"sr-product-manager"`
133
+
134
+ 6. **Report** sync results:
135
+ ```
136
+ Product discovery complete:
137
+ - Created: {N} new feature ideas as local tickets
138
+ - Skipped: {N} duplicates (already exist)
139
+ ```
140
+
101
141
  ### If provider=github and BACKLOG_WRITE=true — Sync to GitHub Issues
102
142
 
103
143
  3. **Fetch existing product-driven backlog items** to avoid duplicates:
@@ -0,0 +1,7 @@
1
+ {
2
+ "schema_version": "1.0",
3
+ "revision": 0,
4
+ "last_updated": null,
5
+ "next_id": 1,
6
+ "tickets": {}
7
+ }
package/update.sh CHANGED
@@ -94,7 +94,7 @@ if [[ -z "$CUSTOM_ROOT_DIR" && -f "$SCRIPT_DIR/install.sh" && -d "$SCRIPT_DIR/te
94
94
  echo -e "${YELLOW}⚠${NC} You're running the updater from inside the specrails source repo."
95
95
  echo -e " specrails updates a ${BOLD}target${NC} repository, not itself."
96
96
  echo ""
97
- read -p " Enter the path to the target repo (or 'q' to quit): " TARGET_PATH
97
+ read -p " Enter the path to the target repo (or 'q' to quit): " TARGET_PATH || TARGET_PATH="q"
98
98
  if [[ "$TARGET_PATH" == "q" || -z "$TARGET_PATH" ]]; then
99
99
  echo " Aborted. No changes made."
100
100
  exit 0
@@ -107,7 +107,7 @@ if [[ -z "$CUSTOM_ROOT_DIR" && -f "$SCRIPT_DIR/install.sh" && -d "$SCRIPT_DIR/te
107
107
  }
108
108
  if [[ ! -d "$REPO_ROOT/.git" ]]; then
109
109
  echo -e "${YELLOW}⚠${NC} Warning: $REPO_ROOT does not appear to be a git repository."
110
- read -p " Continue anyway? (y/n): " CONTINUE_NOGIT
110
+ read -p " Continue anyway? (y/n): " CONTINUE_NOGIT || CONTINUE_NOGIT="n"
111
111
  if [[ "$CONTINUE_NOGIT" != "y" && "$CONTINUE_NOGIT" != "Y" ]]; then
112
112
  echo " Aborted. No changes made."
113
113
  exit 0
@@ -658,7 +658,7 @@ except Exception:
658
658
  fi
659
659
 
660
660
  local answer
661
- read -p " Regenerate agents? (y/N): " answer
661
+ read -p " Regenerate agents? (y/N): " answer || answer="n"
662
662
  if [[ "$answer" == "y" ]] || [[ "$answer" == "Y" ]]; then
663
663
  NEEDS_SETUP_UPDATE=true
664
664
  ok "Will regenerate agents via /setup --update"