@houseofwolvesllc/claude-scrum-skill 1.2.4 → 1.4.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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "claude-scrum-skill",
3
3
  "description": "Complete scrum pipeline — PRD to production release with Claude as scrum master. Includes project scaffolding, sprint planning, status tracking, sprint releases, and full-project emulation testing.",
4
- "version": "1.2.4",
4
+ "version": "1.3.0",
5
5
  "author": {
6
6
  "name": "House of Wolves LLC"
7
7
  },
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Claude Scrum Skill
2
2
 
3
- An open-source npm package of Claude Code skills that give you a complete scrum pipeline — from PRD to production release — with Claude as your scrum master. Includes project scaffolding, sprint planning, status tracking, sprint releases, and full-project emulation testing. One PR per sprint. You stay in the executive seat.
3
+ An open-source npm package of Claude Code skills that give you a complete scrum pipeline — from PRD to production release — with Claude as your scrum master. Includes project scaffolding, sprint planning, status tracking, sprint releases, full-project emulation testing, and autonomous orchestration. One PR per sprint, or let Claude drive the entire lifecycle hands-free.
4
4
 
5
5
  ```
6
+ Manual mode — you invoke each skill:
7
+
6
8
  PRD → /project-scaffold → GitHub Project with sprints, stories, branches
7
9
 
8
10
  /sprint-plan → populate the next sprint
@@ -16,6 +18,26 @@ PRD → /project-scaffold → GitHub Project with sprints, stories, branches
16
18
  You review one PR → merge to development
17
19
 
18
20
  /sprint-plan → next cycle
21
+
22
+ Autonomous mode — one command drives the full lifecycle:
23
+
24
+ PRD (optional) → /project-orchestrate (scaffolds PRD if given, else uses existing board)
25
+
26
+ ┌──────── Epic Completion Loop ────────┐
27
+ │ /sprint-plan → execute stories │
28
+ │ → /sprint-release → merge to dev │
29
+ │ → branch cleanup → next sprint │
30
+ │ (repeat until all epics done) │
31
+ └──────────────┬───────────────────────┘
32
+
33
+ ┌──── Emulation Hardening Loop ────────┐
34
+ │ /project-emulate → parse findings │
35
+ │ → generate PRD → /project-scaffold │
36
+ │ → fix sprints → re-emulate │
37
+ │ (repeat until clean) │
38
+ └──────────────┬───────────────────────┘
39
+
40
+ Production-ready codebase
19
41
  ```
20
42
 
21
43
  ## Installation
@@ -29,7 +51,7 @@ Add the marketplace and install the plugin directly from GitHub:
29
51
  /plugin install claude-scrum-skill@houseofwolvesllc
30
52
  ```
31
53
 
32
- This installs all five skills as a native Claude Code plugin with automatic updates. To update later:
54
+ This installs all six skills as a native Claude Code plugin with automatic updates. To update later:
33
55
 
34
56
  ```
35
57
  /plugin marketplace update
@@ -38,10 +60,14 @@ This installs all five skills as a native Claude Code plugin with automatic upda
38
60
  ### npm
39
61
 
40
62
  ```bash
63
+ # Global — installs to ~/.claude/skills/ (all projects)
41
64
  npm install -g @houseofwolvesllc/claude-scrum-skill
65
+
66
+ # Local — installs to <project>/.claude/skills/ (this project only)
67
+ npm install @houseofwolvesllc/claude-scrum-skill
42
68
  ```
43
69
 
44
- This copies all skills into `~/.claude/skills/`. All five skills are installed as siblings so relative paths to shared conventions resolve correctly.
70
+ Global install copies skills to `~/.claude/skills/` so they're available everywhere. Local install copies them to your project's `.claude/skills/` directory useful for dev containers and CI where the home directory is ephemeral.
45
71
 
46
72
  ### Manual
47
73
 
@@ -177,13 +203,30 @@ Claude reads the entire codebase and runs a multi-phase validation:
177
203
  5. **Full lifecycle walkthrough** — emulates each role executing each action from deployment through teardown
178
204
  6. **Coverage report** — permission matrix, categorized issues, and missing coverage
179
205
 
180
- ### 10. Repeat
206
+ ### 10. Orchestrate (Optional — Full Autonomy)
207
+
208
+ ```
209
+ # Scaffold a PRD and orchestrate only its epics/stories
210
+ /project-orchestrate path/to/prd.md
211
+
212
+ # Orchestrate all open epics/stories on an existing project
213
+ /project-orchestrate owner/repo
214
+
215
+ # Both — scaffold PRD into a specific repo, then orchestrate
216
+ /project-orchestrate path/to/prd.md owner/repo
217
+ ```
218
+
219
+ Instead of manually invoking each skill at every step, let Claude drive the entire lifecycle autonomously. Pass a PRD to scaffold and execute just that work, or pass a repo to execute everything on the board. The orchestrator loops through sprint planning, story execution (parallel subagents for `executor:claude` stories), sprint release, merge to development, and branch cleanup — repeating until all in-scope epics are complete. Then it runs emulation hardening loops against the **entire codebase** (not just the new work): emulate, generate a findings PRD, scaffold a hardening epic, fix everything, and re-emulate until the codebase is clean.
220
+
221
+ Human/cowork stories are skipped (they roll over). Merges to `development` happen automatically. Merges to `main` still require your review. State is persisted to `.claude/orchestration-state.md` so progress survives session restarts.
222
+
223
+ ### 11. Repeat (Manual Mode)
181
224
 
182
225
  ```
183
226
  /sprint-plan owner/repo
184
227
  ```
185
228
 
186
- Start the next sprint. The cycle continues until the project is complete.
229
+ If you prefer manual control, start the next sprint. The cycle continues until the project is complete.
187
230
 
188
231
  ## How It Works
189
232
 
@@ -239,6 +282,7 @@ Located at: `project-scaffold/references/CONVENTIONS.md`
239
282
  | `sprint-status` | `/sprint-status [owner/repo]` | Progress report and burndown |
240
283
  | `sprint-release` | `/sprint-release [owner/repo]` | Close sprint, open release PR to development |
241
284
  | `project-emulate` | `/project-emulate` | Integration seams, layer contracts, cross-service payloads, and full lifecycle walkthrough |
285
+ | `project-orchestrate` | `/project-orchestrate [prd-path] [owner/repo]` | Autonomous lifecycle driver — sprint loop + emulation hardening until done |
242
286
 
243
287
  ## Customization
244
288
 
@@ -257,6 +301,40 @@ Edit `CONVENTIONS.md` → "Executor Assignment Guidelines" to tune what gets ass
257
301
  ### Adding Epics
258
302
  Epics map to your PRD structure. To add new epics later, run `/project-scaffold` with the new PRD — it detects the existing project and lets you add stories to existing epics or create new ones.
259
303
 
304
+ ## Autonomous Orchestration
305
+
306
+ The `/project-orchestrate` skill is a meta-orchestrator that chains all other skills into a fully autonomous pipeline. After scaffolding your project, run it once and Claude handles everything else.
307
+
308
+ ### What It Does
309
+
310
+ **Phase 1 — Epic Completion Loop:**
311
+ 1. Detects open epics and presents an overview
312
+ 2. Plans sprints via `/sprint-plan`
313
+ 3. Executes `executor:claude` stories in parallel via subagents (skips human/cowork — they roll over)
314
+ 4. Releases via `/sprint-release`
315
+ 5. Merges the release PR to `development` (pre-authorized, no confirmation needed)
316
+ 6. Cleans up merged branches
317
+ 7. Repeats until all epics are complete
318
+
319
+ **Phase 2 — Emulation Hardening Loop:**
320
+ 1. Runs `/project-emulate` to discover issues
321
+ 2. Generates a hardening PRD from critical/warning findings
322
+ 3. Scaffolds a "Hardening (Run N)" epic via `/project-scaffold`
323
+ 4. Executes the hardening sprint (same loop as Phase 1)
324
+ 5. Re-emulates — if new issues found, repeats; if clean, done
325
+
326
+ ### State Persistence
327
+
328
+ Orchestration state is saved to `.claude/orchestration-state.md` (human-readable markdown). If Claude hits a usage cap or the session restarts, it picks up exactly where it left off. The state file tracks the current phase, epic, sprint, story status, and a running log.
329
+
330
+ ### Safety Boundaries
331
+
332
+ - Merges to `development` are pre-authorized (standing auth)
333
+ - Merges to `main` are **never** automatic — always requires your review
334
+ - Failed stories are retried once, then marked blocked — they don't halt the pipeline
335
+ - Merge conflicts pause orchestration and escalate to you
336
+ - After 3 hardening runs without a clean emulation, Claude pauses and asks for guidance
337
+
260
338
  ## Tips
261
339
 
262
340
  - **Chunk large epics** into multiple sprints for natural review gates. If an epic has 30 stories, split it into 2-3 sprints rather than one massive batch.
package/bin/install.js CHANGED
@@ -4,15 +4,35 @@ const fs = require('fs');
4
4
  const path = require('path');
5
5
 
6
6
  const HOME = process.env.HOME || process.env.USERPROFILE;
7
- const SKILLS_DIR = path.join(HOME, '.claude', 'skills');
8
7
  const SOURCE_DIR = path.join(__dirname, '..', 'skills');
8
+ const IS_GLOBAL = process.env.npm_config_global === 'true';
9
+
10
+ // Global install → ~/.claude/skills/
11
+ // Local install → <project>/.claude/skills/
12
+ let skillsDir;
13
+ if (IS_GLOBAL) {
14
+ skillsDir = path.join(HOME, '.claude', 'skills');
15
+ } else {
16
+ // Walk up from node_modules to find the project root
17
+ let projectRoot = path.resolve(__dirname, '..');
18
+ while (projectRoot !== path.dirname(projectRoot)) {
19
+ if (path.basename(projectRoot) === 'node_modules') {
20
+ projectRoot = path.dirname(projectRoot);
21
+ break;
22
+ }
23
+ projectRoot = path.dirname(projectRoot);
24
+ }
25
+ skillsDir = path.join(projectRoot, '.claude', 'skills');
26
+ }
9
27
 
10
28
  const skills = [
11
29
  'project-scaffold',
12
30
  'sprint-plan',
13
31
  'sprint-status',
14
32
  'sprint-release',
15
- 'project-emulate'
33
+ 'project-emulate',
34
+ 'project-orchestrate',
35
+ 'project-cleanup'
16
36
  ];
17
37
 
18
38
  function copyRecursive(src, dest) {
@@ -28,15 +48,15 @@ function copyRecursive(src, dest) {
28
48
  }
29
49
  }
30
50
 
31
- console.log('\n📋 Installing claude-scrum-skill...\n');
51
+ const location = IS_GLOBAL ? 'global (~/.claude/skills/)' : `project (${skillsDir})`;
52
+ console.log(`\n📋 Installing claude-scrum-skill (${location})...\n`);
32
53
 
33
- // Ensure ~/.claude/skills exists
34
- fs.mkdirSync(SKILLS_DIR, { recursive: true });
54
+ fs.mkdirSync(skillsDir, { recursive: true });
35
55
 
36
56
  let installed = 0;
37
57
  for (const skill of skills) {
38
58
  const src = path.join(SOURCE_DIR, skill);
39
- const dest = path.join(SKILLS_DIR, skill);
59
+ const dest = path.join(skillsDir, skill);
40
60
 
41
61
  if (fs.existsSync(src)) {
42
62
  copyRecursive(src, dest);
@@ -47,6 +67,6 @@ for (const skill of skills) {
47
67
  }
48
68
  }
49
69
 
50
- console.log(`\n✨ Installed ${installed} skills to ${SKILLS_DIR}`);
51
- console.log(' Skills are available in Claude Code immediately.\n');
70
+ console.log(`\n✨ Installed ${installed} skills to ${skillsDir}`);
71
+ console.log(' Restart Claude Code for the skills to become available.\n');
52
72
  console.log(' Run /project-scaffold <prd-path> to get started.\n');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@houseofwolvesllc/claude-scrum-skill",
3
- "version": "1.2.4",
4
- "description": "Claude Code skills for scrum project management — PRD to production release pipeline with project scaffolding, sprint planning, status tracking, sprint releases, and full-project emulation testing.",
3
+ "version": "1.4.0",
4
+ "description": "Claude Code skills for scrum project management — PRD to production release pipeline with project scaffolding, sprint planning, status tracking, sprint releases, full-project emulation testing, autonomous orchestration, and project cleanup.",
5
5
  "bin": {},
6
6
  "scripts": {
7
7
  "postinstall": "node bin/install.js"
@@ -0,0 +1,426 @@
1
+ ---
2
+ name: project-cleanup
3
+ description: Systematically verify and enforce codebase hygiene — zero build errors, zero lint warnings, HATEOAS compliance, no dead or duplicated code, all tests passing with at least 50% coverage. Reads the project's CLAUDE.md for overrides and treats best practices as defaults that yield to project-specific rules.
4
+ ---
5
+
6
+ # Project Cleanup
7
+
8
+ Ensure the codebase is production-clean: builds without errors or warnings, passes lint with zero issues, adheres to HATEOAS and project conventions, contains no dead or duplicated code, and has comprehensive test coverage.
9
+
10
+ ---
11
+
12
+ ## Before You Start
13
+
14
+ 1. Read the project's `CLAUDE.md` (if it exists) for project-specific rules. **CLAUDE.md overrides are authoritative** — if a project rule conflicts with a best practice listed here, the project rule wins. Record any overrides you find so you can reference them when making decisions.
15
+ 2. Read `../project-scaffold/references/CONVENTIONS.md` for project management standards (if applicable).
16
+ 3. **Terminology:** Always refer to milestones as **"epics"** in all user-facing text, summaries, and conversational output. The word "milestone" should only appear in GitHub API commands and code — never in communication with the user.
17
+ 4. Identify the project's language(s), framework(s), build system, linter, test runner, and coverage tool by reading `package.json`, `tsconfig.json`, `pyproject.toml`, `Cargo.toml`, `go.mod`, `Makefile`, or equivalent config files.
18
+ 5. Confirm all required tooling is installed and runnable (`npm`, `npx`, `tsc`, `eslint`, `jest`/`vitest`/`pytest`/`go test`, etc.).
19
+
20
+ ---
21
+
22
+ ## Input
23
+
24
+ `$ARGUMENTS` can be:
25
+
26
+ 1. **Nothing** — clean up the entire project in the current working directory.
27
+ 2. **A path** (e.g., `src/` or `packages/api/`) — scope cleanup to a specific directory or package.
28
+ 3. **A flag** `--fix` — automatically fix all issues found. Without this flag, the skill reports issues but does not modify code.
29
+ 4. **A flag** `--report-only` — produce the report without any fixes, even if `--fix` is also present.
30
+
31
+ Flags can be combined: `/project-cleanup src/ --fix`
32
+
33
+ ---
34
+
35
+ ## Phase 1: Build Verification
36
+
37
+ Verify the project compiles and builds with zero errors and zero warnings.
38
+
39
+ ### Step 1: Identify Build Commands
40
+
41
+ Detect the build toolchain from project config files:
42
+
43
+ - **Node.js/TypeScript:** `tsc --noEmit` for type checking, `npm run build` or equivalent for full build
44
+ - **Go:** `go build ./...`
45
+ - **Rust:** `cargo build 2>&1`
46
+ - **Python:** `python -m py_compile` or `mypy` for type checking
47
+ - **Multi-package (monorepo):** Run build for each workspace/package
48
+
49
+ If the project has a `build` script in `package.json`, use it. Otherwise infer from the toolchain.
50
+
51
+ ### Step 2: Run Build
52
+
53
+ Execute the build command and capture all output. Parse output into:
54
+
55
+ - **Errors** — compilation failures, type errors, missing imports
56
+ - **Warnings** — unused variables, implicit any, deprecation notices
57
+
58
+ **Target: zero errors, zero warnings.**
59
+
60
+ ### Step 3: Catalog Build Issues
61
+
62
+ For each issue found, record:
63
+
64
+ | File | Line | Severity | Code | Message |
65
+ |------|------|----------|------|---------|
66
+ | `src/api/handler.ts` | 42 | error | TS2345 | Argument of type 'string' is not assignable... |
67
+
68
+ If `--fix` is active, fix each issue in order of severity (errors first, then warnings). After fixing, re-run the build to confirm the fix didn't introduce new issues.
69
+
70
+ ---
71
+
72
+ ## Phase 2: Lint Verification
73
+
74
+ Verify the project passes lint with zero errors and zero warnings.
75
+
76
+ ### Step 1: Identify Lint Configuration
77
+
78
+ Detect the linter(s) from project config:
79
+
80
+ - **ESLint:** `.eslintrc.*`, `eslint.config.*`, `eslint` field in `package.json`
81
+ - **Prettier:** `.prettierrc.*`, `prettier` field in `package.json`
82
+ - **Biome:** `biome.json`
83
+ - **golangci-lint:** `.golangci.yml`
84
+ - **Ruff/flake8:** `pyproject.toml [tool.ruff]`, `.flake8`
85
+ - **clippy:** `cargo clippy`
86
+
87
+ ### Step 2: Run Linter
88
+
89
+ Execute the linter with all warnings enabled:
90
+
91
+ ```bash
92
+ # Example for ESLint
93
+ npx eslint . --max-warnings 0 --format json
94
+ ```
95
+
96
+ Use `--max-warnings 0` (or equivalent) to treat warnings as failures.
97
+
98
+ ### Step 3: Catalog Lint Issues
99
+
100
+ For each issue found, record:
101
+
102
+ | File | Line | Rule | Severity | Message | Fixable |
103
+ |------|------|------|----------|---------|---------|
104
+ | `src/utils.ts` | 15 | `no-unused-vars` | warning | 'helper' is defined but never used | no |
105
+
106
+ ### Step 4: Apply Fixes (if `--fix` active)
107
+
108
+ 1. Run the linter's auto-fix first: `npx eslint . --fix`
109
+ 2. Re-run the linter to identify remaining issues that need manual fixes
110
+ 3. Fix remaining issues manually, following these rules:
111
+ - **Unused imports/variables:** Remove them
112
+ - **Formatting issues:** Apply the project's formatter (Prettier, Biome, etc.)
113
+ - **Rule violations:** Fix the code to comply with the rule; do NOT add `eslint-disable` comments unless `CLAUDE.md` explicitly allows it
114
+ - **Deprecation warnings:** Update to the recommended replacement
115
+ 4. Re-run the linter to confirm zero remaining issues
116
+
117
+ ---
118
+
119
+ ## Phase 3: HATEOAS and Project Principles Compliance
120
+
121
+ Verify the codebase adheres to HATEOAS (Hypermedia as the Engine of Application State) principles and any project-specific architectural standards.
122
+
123
+ **Important:** Only apply HATEOAS checks to projects that expose REST APIs. Skip this phase entirely for CLI tools, libraries, static sites, or other non-API projects.
124
+
125
+ ### Step 1: Identify API Layer
126
+
127
+ Scan for API route definitions, controllers, and response construction:
128
+
129
+ - Express/Fastify/Koa route handlers
130
+ - NestJS/Spring/Django/Rails controllers
131
+ - Serverless function handlers (Lambda, Cloud Functions)
132
+ - GraphQL resolvers (HATEOAS doesn't apply to GraphQL — skip these)
133
+
134
+ ### Step 2: HATEOAS Link Audit
135
+
136
+ For each API endpoint that returns resource representations, verify:
137
+
138
+ **Self links** — Every resource response MUST include a `self` link:
139
+ ```json
140
+ {
141
+ "id": "123",
142
+ "name": "Example",
143
+ "_links": {
144
+ "self": { "href": "/resources/123" }
145
+ }
146
+ }
147
+ ```
148
+
149
+ **Relational links** — Resources with relationships SHOULD include navigational links:
150
+ - Parent resource link (e.g., `collection` → `/resources`)
151
+ - Related resource links (e.g., `author` → `/users/456`)
152
+ - Action links where applicable (e.g., `approve` → `/resources/123/approve`)
153
+
154
+ **Collection links** — Collection endpoints SHOULD include:
155
+ - `self` link with current query parameters
156
+ - Pagination links (`next`, `prev`, `first`, `last`) when paginated
157
+ - Item links or embedded items with their own `self` links
158
+
159
+ **Consistency checks:**
160
+ - All link `href` values MUST correspond to actual routes that exist in the codebase
161
+ - Link relations MUST be consistent across all endpoints (don't use `_links` in some responses and `links` in others)
162
+ - Media type SHOULD be consistent (if using HAL, use HAL everywhere; if using JSON:API, use JSON:API everywhere)
163
+
164
+ ### Step 3: Project-Specific Principles
165
+
166
+ Read `CLAUDE.md` and any architecture documentation (ADRs, `docs/architecture.md`, etc.) for project-specific principles. Common things to check:
167
+
168
+ - **Layered architecture compliance** — are controllers calling repositories directly instead of going through services?
169
+ - **Dependency direction** — do inner layers depend on outer layers?
170
+ - **Naming conventions** — do file names, function names, and variable names follow the project's conventions?
171
+ - **Error handling patterns** — does the project use a specific error handling strategy consistently?
172
+ - **Response envelope** — does the project wrap responses in a specific envelope format?
173
+
174
+ ### Step 4: Catalog HATEOAS/Architecture Issues
175
+
176
+ For each violation found, record:
177
+
178
+ | File | Line | Category | Issue | Recommendation |
179
+ |------|------|----------|-------|----------------|
180
+ | `src/controllers/users.ts` | 78 | HATEOAS | Response missing `_links.self` | Add self link to user response |
181
+ | `src/routes/orders.ts` | 45 | Architecture | Controller directly queries DB | Route through OrderService |
182
+
183
+ If `--fix` is active:
184
+ - Add missing `_links` to response objects
185
+ - Add missing pagination links to collection responses
186
+ - Refactor architectural violations (move logic to correct layer)
187
+ - Verify fixes don't break existing tests
188
+
189
+ ---
190
+
191
+ ## Phase 4: Dead and Duplicated Code Detection
192
+
193
+ Find and remove code that is unused, unreachable, or unnecessarily duplicated.
194
+
195
+ ### Step 1: Dead Code Detection
196
+
197
+ **Unused exports** — Identify exports that are never imported anywhere:
198
+ ```bash
199
+ # Use the project's tooling if available (e.g., ts-prune, knip, unimported)
200
+ # Otherwise, for each exported symbol, grep for its import across the codebase
201
+ ```
202
+
203
+ Tools to check for (use if present in devDependencies):
204
+ - `knip` — comprehensive unused file/export/dependency detector
205
+ - `ts-prune` — TypeScript-specific unused export finder
206
+ - `unimported` — unused file detector
207
+ - `depcheck` — unused dependency detector
208
+
209
+ If no specialized tool is available, perform manual analysis:
210
+
211
+ 1. **Unused files** — files that are never imported or referenced
212
+ 2. **Unused exports** — exported functions, classes, types, or constants that are never imported
213
+ 3. **Unused dependencies** — packages in `dependencies`/`devDependencies` that are never imported
214
+ 4. **Dead branches** — code paths that can never execute (e.g., `if (false)`, unreachable code after `return`)
215
+ 5. **Commented-out code** — blocks of commented code (not documentation comments)
216
+ 6. **Vestigial patterns** — unused interfaces/types kept "for backwards compatibility" with no consumers, re-exports that point to nothing, empty files, placeholder implementations
217
+
218
+ **Exclusions — do NOT flag as dead code:**
219
+ - Entry points referenced in `package.json` (`main`, `bin`, `exports`)
220
+ - Files referenced in build config (`webpack.config`, `vite.config`, etc.)
221
+ - Test files and test utilities
222
+ - Type declaration files (`.d.ts`) that are part of the public API
223
+ - Anything that `CLAUDE.md` explicitly says to keep
224
+
225
+ ### Step 2: Duplicated Code Detection
226
+
227
+ Identify substantially duplicated code blocks:
228
+
229
+ 1. **Exact duplicates** — identical code blocks (3+ lines) appearing in multiple locations
230
+ 2. **Near duplicates** — code blocks that differ only in variable names, literal values, or minor structural variations
231
+ 3. **Pattern duplication** — repeated patterns that should be abstracted (e.g., the same error handling try/catch block copied across 5 handlers)
232
+
233
+ **Judgment calls (follow CLAUDE.md if it has guidance):**
234
+ - Two similar 3-line blocks are fine — don't create a premature abstraction
235
+ - The same 10+ line pattern in 4+ places should be extracted
236
+ - If extracting would require complex parameterization, the duplication may be preferable — note it but don't force an abstraction
237
+
238
+ ### Step 3: Catalog Dead/Duplicated Code
239
+
240
+ | File | Line(s) | Category | Description |
241
+ |------|---------|----------|-------------|
242
+ | `src/old-handler.ts` | 1-120 | Dead file | Never imported anywhere |
243
+ | `src/utils.ts` | 45-67 | Dead export | `formatDate` exported but never imported |
244
+ | `src/controllers/` | various | Duplication | Error handling block repeated in 6 controllers |
245
+
246
+ If `--fix` is active:
247
+ - **Dead code:** Remove it. Delete unused files, remove unused exports, remove unused dependencies from `package.json`.
248
+ - **Duplicated code:** Extract shared logic into utility functions or base classes. Follow the project's existing abstraction patterns.
249
+ - After each batch of removals, re-run the build and linter to confirm nothing broke.
250
+
251
+ ---
252
+
253
+ ## Phase 5: Test Verification and Coverage
254
+
255
+ Verify all tests pass and coverage meets the 50% minimum threshold.
256
+
257
+ ### Step 1: Identify Test Framework
258
+
259
+ Detect from project config:
260
+
261
+ - **Jest:** `jest.config.*`, `jest` field in `package.json`
262
+ - **Vitest:** `vitest.config.*`, `vite.config.*` with test config
263
+ - **Mocha/Chai:** `.mocharc.*`, `mocha` field in `package.json`
264
+ - **pytest:** `pyproject.toml [tool.pytest]`, `pytest.ini`, `conftest.py`
265
+ - **Go:** Built-in `go test`
266
+ - **Rust:** Built-in `cargo test`
267
+
268
+ ### Step 2: Run Tests
269
+
270
+ Execute the full test suite:
271
+
272
+ ```bash
273
+ # Example for Jest/Vitest
274
+ npx jest --ci --coverage --coverageReporters=json-summary --coverageReporters=text
275
+ ```
276
+
277
+ Capture:
278
+ - Pass/fail status for every test
279
+ - Coverage summary (statements, branches, functions, lines)
280
+
281
+ ### Step 3: Analyze Test Results
282
+
283
+ **Failing tests** — For each failure, record:
284
+
285
+ | Test File | Test Name | Error | Category |
286
+ |-----------|-----------|-------|----------|
287
+ | `src/__tests__/auth.test.ts` | `should reject expired token` | `TypeError: jwt.verify is not a function` | Broken import |
288
+
289
+ Categorize failures:
290
+ - **Environment issues** — missing env vars, database not available, network dependency
291
+ - **Broken imports** — module not found, wrong path
292
+ - **Logic errors** — assertion failures indicating actual bugs
293
+ - **Stale tests** — tests for code that was refactored but tests weren't updated
294
+
295
+ **Coverage analysis:**
296
+
297
+ | Metric | Current | Target | Status |
298
+ |--------|---------|--------|--------|
299
+ | Statements | 62% | 50% | PASS |
300
+ | Branches | 38% | 50% | FAIL |
301
+ | Functions | 71% | 50% | PASS |
302
+ | Lines | 60% | 50% | PASS |
303
+
304
+ **Target: all four metrics at or above 50%.**
305
+
306
+ ### Step 4: Identify Coverage Gaps
307
+
308
+ If any metric is below 50%, identify the files and functions most responsible for the gap:
309
+
310
+ 1. List uncovered files (0% coverage) that contain substantive logic (not config, not types)
311
+ 2. List partially covered files where key functions lack tests
312
+ 3. Prioritize by impact — covering a 200-line untested service file moves the needle more than adding edge case tests to an already-covered utility
313
+
314
+ ### Step 5: Fix Tests and Improve Coverage (if `--fix` active)
315
+
316
+ **Fix failing tests first** (in this order):
317
+ 1. Broken imports — update paths, fix module resolution
318
+ 2. Stale tests — update tests to match refactored code
319
+ 3. Logic errors — determine if the test or the code is wrong; fix the one that's wrong
320
+ 4. Environment issues — add proper mocking or skip with a clear annotation
321
+
322
+ **Then improve coverage** (if below 50%):
323
+ 1. Write tests for completely uncovered files with substantive logic
324
+ 2. Add tests for uncovered branches in partially covered files
325
+ 3. Focus on testing public API / exported functions
326
+ 4. Follow existing test patterns and conventions in the project
327
+ 5. Do NOT write trivial tests just to hit the number (e.g., testing that a constant equals itself)
328
+
329
+ After writing new tests, re-run the full suite to confirm all tests pass and coverage meets the target.
330
+
331
+ ---
332
+
333
+ ## Phase 6: Final Validation
334
+
335
+ After all fixes (or after cataloging all issues in report-only mode), run a final validation pass.
336
+
337
+ ### Step 1: Full Verification Run
338
+
339
+ Run all checks in sequence and confirm clean results:
340
+
341
+ 1. **Build:** `tsc --noEmit` / `npm run build` — zero errors, zero warnings
342
+ 2. **Lint:** `npx eslint . --max-warnings 0` — zero issues
343
+ 3. **Tests:** `npx jest --ci --coverage` — all pass, coverage >= 50%
344
+
345
+ ### Step 2: Regression Check
346
+
347
+ If `--fix` was active, verify that fixes didn't introduce new problems:
348
+
349
+ - Run a `git diff --stat` to summarize all changes
350
+ - Verify no test that previously passed is now failing
351
+ - Verify coverage didn't decrease in any file that wasn't touched
352
+ - Verify no new lint or build warnings were introduced
353
+
354
+ ---
355
+
356
+ ## Output
357
+
358
+ Save the cleanup report to `.claude/reports/cleanup-report/`. Create the directory if it doesn't exist.
359
+
360
+ ### Report Structure
361
+
362
+ ```
363
+ cleanup-report/
364
+ ├── SUMMARY.md # High-level findings, pass/fail status for each phase
365
+ ├── BUILD.md # Build errors and warnings
366
+ ├── LINT.md # Lint violations by rule and file
367
+ ├── HATEOAS.md # HATEOAS and architecture compliance findings
368
+ ├── DEAD-CODE.md # Dead and duplicated code inventory
369
+ ├── TESTS.md # Test results and coverage analysis
370
+ └── FIXES.md # (if --fix was used) Summary of all changes made
371
+ ```
372
+
373
+ ### SUMMARY.md Format
374
+
375
+ ```markdown
376
+ # Project Cleanup Report
377
+
378
+ **Date:** <ISO date>
379
+ **Scope:** <full project | scoped to path>
380
+ **Mode:** <report-only | fix>
381
+ **CLAUDE.md Overrides:** <list any project rules that overrode default behavior>
382
+
383
+ ## Results
384
+
385
+ | Phase | Status | Issues Found | Issues Fixed |
386
+ |-------|--------|--------------|--------------|
387
+ | Build | PASS/FAIL | <count> errors, <count> warnings | <count> (if --fix) |
388
+ | Lint | PASS/FAIL | <count> errors, <count> warnings | <count> (if --fix) |
389
+ | HATEOAS/Architecture | PASS/FAIL/SKIP | <count> violations | <count> (if --fix) |
390
+ | Dead/Duplicated Code | PASS/FAIL | <count> dead, <count> duplicated | <count> (if --fix) |
391
+ | Tests | PASS/FAIL | <count> failing, coverage: <pct>% | <count> (if --fix) |
392
+ | **Overall** | **PASS/FAIL** | **<total>** | **<total>** |
393
+
394
+ ## Coverage Summary
395
+
396
+ | Metric | Before | After | Target | Status |
397
+ |--------|--------|-------|--------|--------|
398
+ | Statements | <pct>% | <pct>% | 50% | PASS/FAIL |
399
+ | Branches | <pct>% | <pct>% | 50% | PASS/FAIL |
400
+ | Functions | <pct>% | <pct>% | 50% | PASS/FAIL |
401
+ | Lines | <pct>% | <pct>% | 50% | PASS/FAIL |
402
+
403
+ ## Critical Issues
404
+
405
+ <List any issues that block production readiness>
406
+
407
+ ## Recommendations
408
+
409
+ <Prioritized list of remaining work if not all issues were fixed>
410
+ ```
411
+
412
+ ---
413
+
414
+ ## Execution Notes
415
+
416
+ **CLAUDE.md is king.** If the project says "we use `eslint-disable` for generated files" or "skip HATEOAS for internal microservice endpoints" or "we intentionally keep the old API types for backwards compat" — follow those rules. Best practices are defaults, not mandates.
417
+
418
+ **Fix in dependency order.** Build errors can cause false-positive lint failures. Dead code removal can cause build errors. Fix in this order: dead code removal, build errors, lint issues, HATEOAS compliance, test fixes, coverage improvement.
419
+
420
+ **Don't over-abstract.** When removing duplicated code, only extract when it genuinely simplifies the codebase. Three similar 5-line blocks are not necessarily worth a shared utility with 3 parameters.
421
+
422
+ **Don't write bad tests.** When improving coverage, write meaningful tests that verify actual behavior. A test that just calls a function without asserting anything useful doesn't count. Focus on public API surface, error paths, and boundary conditions.
423
+
424
+ **Report, don't surprise.** In `--fix` mode, the FIXES.md file should clearly document every change made and why. The user should be able to review all changes before committing.
425
+
426
+ **Preserve project style.** When writing new tests or refactoring code, match the existing patterns in the codebase. Don't introduce a new testing pattern, assertion library, or file structure convention.
@@ -0,0 +1,518 @@
1
+ ---
2
+ name: project-orchestrate
3
+ description: Autonomous project lifecycle driver that ties together all skills into a continuous loop — plan sprints, execute stories in parallel, release, merge, clean up, and repeat until all epics are done, then run emulation hardening loops until the codebase is clean. Use when you want Claude to drive the entire project from backlog to production-ready without manual skill invocation at each step.
4
+ ---
5
+
6
+ # Project Orchestrate
7
+
8
+ Fully autonomous project lifecycle driver. Plans sprints, executes stories via parallel subagents, releases, merges to development, cleans up branches, and repeats until every epic is complete — then hardens the codebase through emulation-driven fix cycles until no issues remain.
9
+
10
+ ---
11
+
12
+ ## Before You Start
13
+
14
+ 1. Read `../project-scaffold/references/CONVENTIONS.md` for all project management standards. Follow these conventions exactly.
15
+ 2. Read the project's `CLAUDE.md` (if it exists) for project-specific rules. **All subagents you spawn must also read and follow `CLAUDE.md`** — include this instruction explicitly in every subagent prompt.
16
+ 3. **Terminology:** Always refer to milestones as **"epics"** in all user-facing text, summaries, and conversational output. The word "milestone" should only appear in GitHub API commands and code — never in communication with the user.
17
+ 4. Confirm the `gh` CLI is authenticated by running `gh auth status`.
18
+ 5. Identify the target repository. If the user doesn't specify, detect from the current git remote or ask.
19
+
20
+ ### Standing Authorizations
21
+
22
+ The following actions are pre-authorized and do NOT require user confirmation during orchestration:
23
+
24
+ - **Merge release PRs to `development`** — after the release PR is created and CI passes
25
+ - **Delete merged story and release branches** — standard cleanup after merge
26
+ - **Create and switch between feature/release branches** — normal git workflow
27
+
28
+ The following actions are NEVER authorized:
29
+
30
+ - **Merge anything to `main`** — always requires explicit human review
31
+ - **Force push or destructive git operations** — never permitted
32
+ - **Close or delete issues without completing them** — incomplete work rolls over
33
+
34
+ ---
35
+
36
+ ## Input
37
+
38
+ `$ARGUMENTS` can be:
39
+
40
+ 1. **A PRD file path** (e.g., `path/to/prd.md`) — scaffold the PRD first via `/project-scaffold`, then orchestrate **only the epics and stories created from that PRD**. The repo is detected from the current git remote (or ask the user).
41
+ 2. **A repo identifier** (e.g., `owner/repo`) — orchestrate **all open epics and stories** already on the project board. No scaffolding step.
42
+ 3. **A PRD file path + repo identifier** (e.g., `path/to/prd.md owner/repo`) — scaffold the PRD into the specified repo, then orchestrate only those epics/stories.
43
+ 4. **Nothing** — detect the repo from the current git remote and orchestrate all open epics/stories.
44
+
45
+ **How to distinguish:** If an argument is a path to an existing file, treat it as a PRD. Otherwise treat it as a repo identifier.
46
+
47
+ ### Scope Rules
48
+
49
+ - **Phase 1 (Epic Completion Loop):** When a PRD is provided, only execute epics/stories that were created from that PRD. Record the milestone numbers and issue numbers created during scaffolding and limit the sprint loop to those. When no PRD is provided, execute all open epics/stories on the project board.
50
+ - **Phase 2 (Emulation Hardening Loop):** Always applies to the **entire codebase** regardless of whether a PRD was provided. Emulation validates the whole project, not just the new work.
51
+
52
+ ---
53
+
54
+ ## State Management
55
+
56
+ Orchestration state is persisted to `.claude/orchestration-state.md` so progress survives context compaction, usage caps, and session restarts. This file is human-readable markdown.
57
+
58
+ ### State File Structure
59
+
60
+ ```markdown
61
+ # Orchestration State
62
+
63
+ ## Meta
64
+ - **Repo:** owner/repo
65
+ - **Project:** #<number>
66
+ - **Phase:** epic-completion | emulation-hardening
67
+ - **Status:** running | paused | completed
68
+ - **Scope:** prd | all
69
+ - **PRD Source:** path/to/prd.md (if scope=prd, otherwise "—")
70
+ - **Scoped Milestones:** #1, #3 (if scope=prd — only these epics are orchestrated in Phase 1)
71
+ - **Scoped Issues:** #10, #11, #12, ... (if scope=prd — only these stories are orchestrated in Phase 1)
72
+ - **Started:** <ISO timestamp>
73
+ - **Last Updated:** <ISO timestamp>
74
+
75
+ ## Current Position
76
+ - **Current Epic:** <epic name> (milestone #<number>)
77
+ - **Current Sprint:** <N>
78
+ - **Hardening Run:** <N> (Phase 2 only)
79
+
80
+ ## Epic Progress
81
+ | Epic | Status | Open | Closed | Total |
82
+ |------|--------|------|--------|-------|
83
+ | Core API | in-progress | 4 | 12 | 16 |
84
+ | Dashboard | pending | 8 | 0 | 8 |
85
+
86
+ ## Current Sprint Stories
87
+ | # | Title | Executor | Status | Subagent |
88
+ |---|-------|----------|--------|----------|
89
+ | 12 | Auth endpoint | claude | done | — |
90
+ | 13 | Login UI | claude | in-progress | agent-3 |
91
+ | 14 | API keys | human | skipped | — |
92
+
93
+ ## Dependency Map
94
+ - #15 blocked-by #12 → unblocked (completed)
95
+ - #18 blocked-by #15 → waiting
96
+
97
+ ## Log
98
+ - [<timestamp>] Phase 1 started — 3 open epics detected
99
+ - [<timestamp>] Sprint 1 planned — 8 stories, 19 points
100
+ - [<timestamp>] Story #12 completed by subagent
101
+ - [<timestamp>] Sprint 1 released — PR #25
102
+ ```
103
+
104
+ ### State Operations
105
+
106
+ **On startup**, check for an existing `.claude/orchestration-state.md`:
107
+ - If found and `Status: running` → resume from the recorded position
108
+ - If found and `Status: paused` → ask the user whether to resume or restart
109
+ - If found and `Status: completed` → ask the user whether to start a fresh run
110
+ - If not found → initialize a new state file
111
+
112
+ **During execution**, update the state file:
113
+ - After every sprint plan, story completion, release, and phase transition
114
+ - On any error that pauses execution
115
+ - Keep the log section as an append-only journal (trim entries older than the current phase to prevent unbounded growth)
116
+
117
+ **On completion**, set `Status: completed` and write a final summary to the log.
118
+
119
+ ---
120
+
121
+ ## Phase 1 — Epic Completion Loop
122
+
123
+ Drive all open epics to completion through iterative sprint cycles.
124
+
125
+ ### Step 1: Initialize
126
+
127
+ **If a PRD was provided** — scaffold it first, then scope the run:
128
+
129
+ ```
130
+ /project-scaffold <prd-path>
131
+ ```
132
+
133
+ After scaffolding completes, capture the milestone numbers and issue numbers that were created. These define the **orchestration scope** — Phase 1 will only plan and execute sprints for these specific epics and stories. Record them in the state file under `Scoped Milestones` and `Scoped Issues`.
134
+
135
+ **If no PRD was provided** — detect and assess the existing project state:
136
+
137
+ ```bash
138
+ # Get open epics (milestones)
139
+ gh api repos/<owner/repo>/milestones --jq '.[] | select(.state=="open") | {number, title, open_issues, closed_issues}'
140
+
141
+ # Get backlog overview
142
+ gh issue list --repo <owner/repo> --state open --label "type:story" --json number,title,labels,milestone
143
+
144
+ # Get current sprint iteration info via GraphQL
145
+ # Check for any in-progress work
146
+ ```
147
+
148
+ All open epics and stories are in scope for Phase 1.
149
+
150
+ **In both cases**, present a brief overview to the user:
151
+
152
+ ```
153
+ ## Orchestration Overview
154
+
155
+ **Repo:** owner/repo
156
+ **Scope:** PRD-scoped (path/to/prd.md) | All open epics
157
+ **Epics in scope:** 3
158
+ - Core API: 16 stories (4 remaining)
159
+ - Dashboard: 8 stories (all pending)
160
+ - Notifications: 5 stories (all pending)
161
+
162
+ **Total stories remaining:** 17
163
+ **Estimated sprints:** 2-3 (at 20 pts/sprint)
164
+
165
+ Starting Phase 1 — Epic Completion Loop.
166
+ ```
167
+
168
+ Initialize the state file and proceed.
169
+
170
+ ### Step 2: Sprint Planning
171
+
172
+ Invoke the `/sprint-plan` skill for the current epic:
173
+
174
+ ```
175
+ /sprint-plan <owner/repo>
176
+ ```
177
+
178
+ **If PRD-scoped:** Ensure the sprint plan only pulls from the scoped issues (recorded in the state file). If `/sprint-plan` proposes stories outside the scope, exclude them — they belong to other work and should not be mixed into this orchestration run.
179
+
180
+ Since this is autonomous mode, accept the default sprint plan without waiting for user confirmation — the skill's proposed sprint based on priority ordering and velocity target is the plan.
181
+
182
+ After planning completes, update the state file with the sprint stories and their dependency map.
183
+
184
+ ### Step 3: Story Execution
185
+
186
+ Execute all `executor:claude` stories in the current sprint. Skip `executor:human` and `executor:cowork` stories — they will roll over to the next sprint automatically.
187
+
188
+ **Parallel execution via Task subagents:**
189
+
190
+ For stories with no unresolved dependencies, spawn parallel Task subagents (using the `Task` tool with `subagent_type: "Bash"` or `subagent_type: "general-purpose"` as appropriate). Each subagent receives:
191
+
192
+ ```
193
+ You are executing story #<number> for repo <owner/repo>.
194
+
195
+ **IMPORTANT:** First read the project's CLAUDE.md file if it exists, and follow all instructions in it.
196
+
197
+ **Story:** <title>
198
+ **Acceptance criteria:** <from issue body>
199
+ **Branch strategy:** Create branch `story/<number>-<slug>` from `release/<epic-slug>`, implement, commit, push, and open a PR targeting `release/<epic-slug>`.
200
+
201
+ After implementation:
202
+ 1. Open a PR with a clear description of changes
203
+ 2. Ensure CI passes
204
+ 3. The PR should target the release branch, NOT development or main
205
+
206
+ Do NOT merge the PR — just open it and report back.
207
+ ```
208
+
209
+ **Execution rules:**
210
+
211
+ 1. **Independence check:** Before spawning subagents, analyze story dependencies. Only spawn stories whose blockers are all resolved.
212
+ 2. **Concurrency limit:** Run up to 3 subagents in parallel to avoid rate limiting.
213
+ 3. **Progress tracking:** As each subagent completes, update the state file and check if any blocked stories are now unblocked. Spawn newly unblocked stories immediately.
214
+ 4. **Failure handling:** If a subagent fails, retry once with additional context about the failure. If it fails again, mark the story as blocked with a note and continue with remaining stories.
215
+ 5. **PR merging:** After a story PR is opened and CI passes, merge it to the release branch:
216
+ ```bash
217
+ gh pr merge <pr-number> --repo <owner/repo> --squash --auto
218
+ ```
219
+ 6. **Skip human/cowork stories:** Log them as skipped in the state file. They roll over naturally during sprint release.
220
+
221
+ **Progress updates** — Print a concise progress line every 2-3 story completions:
222
+
223
+ ```
224
+ Sprint 2: 5/8 stories done (13/19 pts) — #21 auth middleware ✓, #22 rate limiting ✓
225
+ ```
226
+
227
+ ### Step 4: Sprint Release
228
+
229
+ Once all `executor:claude` stories in the sprint are complete (or retried and marked blocked), invoke the sprint release skill:
230
+
231
+ ```
232
+ /sprint-release <owner/repo>
233
+ ```
234
+
235
+ This closes the sprint, handles rolled-over stories, and opens the release PR to `development`.
236
+
237
+ ### Step 5: Merge Release PR to Development
238
+
239
+ After `/sprint-release` creates the release PR, merge it to `development` (standing authorization — no user confirmation needed):
240
+
241
+ ```bash
242
+ # Wait for CI to pass on the release PR
243
+ gh pr checks <pr-number> --repo <owner/repo> --watch
244
+
245
+ # Merge the release PR to development
246
+ gh pr merge <pr-number> --repo <owner/repo> --squash
247
+ ```
248
+
249
+ If merge conflicts exist:
250
+ 1. Attempt automatic resolution by rebasing the release branch onto `development`
251
+ 2. If auto-resolution fails, **pause orchestration** and escalate to the user:
252
+ ```
253
+ ⚠️ Merge conflict on release/<epic-slug> → development
254
+ Conflicting files: <list>
255
+
256
+ Orchestration paused. Please resolve conflicts and resume.
257
+ ```
258
+ 3. Update the state file with `Status: paused` and the conflict details.
259
+
260
+ ### Step 6: Branch Cleanup
261
+
262
+ After successful merge, clean up merged branches (standing authorization):
263
+
264
+ ```bash
265
+ # Delete merged story branches
266
+ git fetch origin
267
+ git branch -r --merged origin/development | grep -E 'origin/story/' | sed 's|origin/||' | while read branch; do
268
+ git push origin --delete "$branch"
269
+ done
270
+
271
+ # If the release branch is fully merged and the epic is complete, delete it too
272
+ git push origin --delete release/<epic-slug>
273
+
274
+ # Prune local references
275
+ git remote prune origin
276
+ ```
277
+
278
+ Never delete `main` or `development`.
279
+
280
+ ### Step 7: Epic Completion Check
281
+
282
+ After each sprint cycle, check if the current epic is complete:
283
+
284
+ ```bash
285
+ # Check remaining open issues for this epic
286
+ gh api repos/<owner/repo>/milestones/<milestone-number> --jq '{open_issues, closed_issues}'
287
+ ```
288
+
289
+ **If open issues remain** (excluding `executor:human`/`executor:cowork` stories that were skipped):
290
+ - Check if remaining stories are all human/cowork → if yes, the epic's claude-executable work is done, move to next epic
291
+ - Otherwise → loop back to Step 2 for another sprint
292
+
293
+ **If all issues are closed:**
294
+ ```bash
295
+ # Close the epic
296
+ gh api repos/<owner/repo>/milestones/<milestone-number> -X PATCH -f state="closed"
297
+ ```
298
+
299
+ **If more in-scope epics remain** → move to the next epic (by priority) and loop back to Step 2. When PRD-scoped, only consider epics listed in `Scoped Milestones`.
300
+
301
+ **If all in-scope epics are complete** → transition to Phase 2.
302
+
303
+ Print a phase transition summary:
304
+
305
+ ```
306
+ ## Phase 1 Complete — All Epics Done
307
+
308
+ **Sprints completed:** 4
309
+ **Stories delivered:** 32
310
+ **Stories skipped (human/cowork):** 6
311
+ **Total points delivered:** 89
312
+
313
+ Transitioning to Phase 2 — Emulation Hardening.
314
+ ```
315
+
316
+ ---
317
+
318
+ ## Phase 2 — Emulation Hardening Loop
319
+
320
+ Validate the **entire codebase** through emulation, fix discovered issues, and repeat until clean. This phase always covers the full project regardless of whether Phase 1 was PRD-scoped — new code must integrate cleanly with the existing codebase.
321
+
322
+ ### Step 8: Run Emulation
323
+
324
+ Invoke the project emulation skill:
325
+
326
+ ```
327
+ /project-emulate
328
+ ```
329
+
330
+ This produces the full emulation report in `.claude/reports/emulation-report/`, including `ISSUES.md` with categorized findings.
331
+
332
+ ### Step 9: Parse Findings
333
+
334
+ Read and parse `.claude/reports/emulation-report/ISSUES.md`. Extract findings by severity:
335
+
336
+ - **Critical** — must fix (blocks production readiness)
337
+ - **Warning** — should fix (degrades quality or reliability)
338
+ - **Info** — may fix (cleanup, minor improvements)
339
+
340
+ If no critical or warning findings exist → orchestration is complete, skip to Step 14.
341
+
342
+ Count and categorize:
343
+
344
+ ```
345
+ ## Emulation Results (Run <N>)
346
+
347
+ **Critical:** 3 findings
348
+ **Warning:** 7 findings
349
+ **Info:** 4 findings
350
+
351
+ Generating hardening PRD for 10 actionable findings.
352
+ ```
353
+
354
+ ### Step 10: Generate Hardening PRD
355
+
356
+ Create a PRD document at `.claude/hardening-prd-run-<N>.md` from the emulation findings. This PRD becomes the input for scaffolding a hardening epic.
357
+
358
+ Structure the PRD as:
359
+
360
+ ```markdown
361
+ # Hardening PRD — Run <N>
362
+
363
+ ## Overview
364
+ Automated hardening pass based on emulation findings from run <N>.
365
+ Addresses <count> critical and <count> warning issues discovered during
366
+ full-project emulation.
367
+
368
+ ## Epic: Hardening (Run <N>)
369
+
370
+ ### Stories
371
+
372
+ #### Fix: <Issue title from ISSUES.md>
373
+ **Priority:** <P0 for critical, P1 for warning>
374
+ **Executor:** claude
375
+ **Story Points:** <estimate based on scope>
376
+ **Acceptance Criteria:**
377
+ - <derived from the issue description>
378
+ - Verify fix by re-checking the specific integration seam / layer contract / workflow
379
+
380
+ #### Fix: <next issue>
381
+ ...
382
+ ```
383
+
384
+ Only include critical and warning findings. Info-level findings are logged but not scaffolded.
385
+
386
+ ### Step 11: Scaffold Hardening Epic
387
+
388
+ Invoke project scaffold with the hardening PRD to create a single "Hardening (Run N)" epic:
389
+
390
+ ```
391
+ /project-scaffold .claude/hardening-prd-run-<N>.md
392
+ ```
393
+
394
+ This creates the milestone, issues, labels, and branches for the hardening work.
395
+
396
+ ### Step 12: Execute Hardening Sprints
397
+
398
+ Run the same sprint loop as Phase 1 (Steps 2-7) for the hardening epic. Since hardening stories are typically all `executor:claude`, this should proceed fully autonomously.
399
+
400
+ ### Step 13: Re-validate
401
+
402
+ After the hardening epic is complete, run emulation again:
403
+
404
+ ```
405
+ /project-emulate
406
+ ```
407
+
408
+ Parse the new findings:
409
+
410
+ - **If new critical or warning findings exist** → increment the run counter and loop back to Step 10
411
+ - **If clean (no critical or warning findings)** → proceed to Step 14
412
+
413
+ Safety valve: If this is the 3rd consecutive hardening run, pause and escalate to the user:
414
+
415
+ ```
416
+ ⚠️ Hardening loop has run 3 times without reaching a clean state.
417
+ Remaining findings may require human judgment.
418
+
419
+ <summary of remaining findings>
420
+
421
+ Options:
422
+ 1. Continue for another hardening run
423
+ 2. Accept current state and finish
424
+ 3. Review findings manually
425
+ ```
426
+
427
+ ### Step 14: Completion Summary
428
+
429
+ Print a comprehensive summary of the entire orchestration run:
430
+
431
+ ```
432
+ ## Orchestration Complete
433
+
434
+ ### Phase 1 — Epic Completion
435
+ - **Epics completed:** <N>
436
+ - **Sprints executed:** <N>
437
+ - **Stories delivered:** <N> (<points> story points)
438
+ - **Stories skipped (human/cowork):** <N>
439
+ - **Average velocity:** <points>/sprint
440
+
441
+ ### Phase 2 — Emulation Hardening
442
+ - **Hardening runs:** <N>
443
+ - **Issues fixed:** <N> critical, <N> warning
444
+ - **Final emulation status:** ✅ Clean / ⚠️ Accepted with <N> remaining
445
+
446
+ ### Timeline
447
+ - Started: <timestamp>
448
+ - Phase 1 completed: <timestamp>
449
+ - Phase 2 completed: <timestamp>
450
+
451
+ ### Remaining Work
452
+ - <N> human/cowork stories still open across <N> epics
453
+ - <list any deferred or unresolved items>
454
+ ```
455
+
456
+ Update the state file with `Status: completed`.
457
+
458
+ ---
459
+
460
+ ## Communication Pattern
461
+
462
+ Keep the user informed without being noisy:
463
+
464
+ | Event | Output |
465
+ |-------|--------|
466
+ | Orchestration start | Full overview (Step 1) |
467
+ | Sprint planned | Sprint number, story count, point total — 2 lines |
468
+ | Every 2-3 stories | Progress line with counts and latest completions |
469
+ | Story failure | Immediate single-line alert with story number and error |
470
+ | Sprint released | Sprint scorecard — 3-4 lines |
471
+ | Merge to development | Single confirmation line |
472
+ | Epic completed | Epic summary — 3-4 lines |
473
+ | Phase transition | Full phase summary |
474
+ | Hardening run start | Run number and finding counts |
475
+ | Orchestration complete | Full completion summary (Step 14) |
476
+ | Error/pause | Immediate alert with context and options |
477
+
478
+ ---
479
+
480
+ ## Error Handling
481
+
482
+ ### Subagent Failures
483
+ - Retry once with additional context about the failure
484
+ - If second attempt fails, mark story as blocked, log the error, and continue
485
+ - Do not let a single story failure halt the entire sprint
486
+
487
+ ### Merge Conflicts
488
+ - Attempt automatic rebase resolution first
489
+ - If auto-resolution fails, pause orchestration and escalate to the user
490
+ - Update state file with conflict details for resume
491
+
492
+ ### State File Corruption
493
+ - If `.claude/orchestration-state.md` is unreadable or malformed, reconstruct state from GitHub:
494
+ ```bash
495
+ # Get sprint and story status from the project board
496
+ # Get branch state from git
497
+ # Get PR state from gh
498
+ ```
499
+ - Log the reconstruction and continue
500
+
501
+ ### Rate Limiting
502
+ - If GitHub API returns 429 or secondary rate limit errors, back off exponentially:
503
+ - First: wait 30 seconds
504
+ - Second: wait 60 seconds
505
+ - Third: wait 2 minutes
506
+ - Fourth: pause orchestration and notify the user
507
+
508
+ ### CI Failures on Release Branch
509
+ - If CI fails on the release PR, do not merge
510
+ - Report the failure with links to the failing checks
511
+ - Attempt to identify the failing test or build step
512
+ - If the fix is straightforward, create a fix commit on the release branch and retry
513
+ - If not, pause and escalate
514
+
515
+ ### Usage Cap / Context Compaction
516
+ - The state file ensures progress is not lost
517
+ - On resume, read the state file and continue from the last recorded position
518
+ - The log section provides context about what happened before compaction
@@ -96,6 +96,16 @@ main (human-only — gh token has NO write access)
96
96
  - Release PR to development includes a sprint summary (auto-generated by sprint-release skill).
97
97
  - Production PRs from development → main are opened manually when ready to ship.
98
98
 
99
+ ### Branch Lifecycle & Cleanup
100
+
101
+ The skill that creates branches is NOT necessarily the skill that cleans them up. `project-scaffold` and `sprint-plan` create release and story branches. `sprint-release` is responsible for cleaning up any that are fully merged into `development` by the time it runs. This prevents branch sprawl regardless of which execution pattern was used during the sprint.
102
+
103
+ **Cleanup rules:**
104
+ - Never delete `main` or `development`
105
+ - Only delete branches fully merged into `development`
106
+ - Do not delete unmerged release branches (they have pending work)
107
+ - Report all deletions in the release summary
108
+
99
109
  ### Approval Layers
100
110
 
101
111
  | Merge | Reviewer | Trigger |
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: sprint-release
3
- description: Wrap up a sprint by generating a release summary, opening the release PR to main for human review, handling incomplete stories, and preparing for the next sprint. Use when a sprint is complete or at the sprint boundary deadline.
3
+ description: Wrap up a sprint by generating a release summary, opening release PRs for human review, handling incomplete stories, cleaning up merged branches, and preparing for the next sprint. Use when a sprint is complete or at the sprint boundary deadline.
4
4
  ---
5
5
 
6
6
  # Sprint Release
@@ -114,19 +114,38 @@ for the reviewer to be aware of.>
114
114
  - [ ] Reviewed release summary above
115
115
  ```
116
116
 
117
- ### Step 4: Open the Release PR
117
+ ### Step 4: Detect Branch State
118
118
 
119
- The release PR targets `development`, NOT `main`. The development → main promotion is a separate, human-initiated production release.
119
+ Before creating any PR, determine the current branch state:
120
120
 
121
121
  ```bash
122
- # Ensure release branch is up to date
123
- git checkout release/<epic-slug> && git pull
122
+ git fetch origin
123
+
124
+ # Find all release and story branches
125
+ RELEASE_BRANCHES=$(git branch -r | grep 'origin/release/' | sed 's|origin/||' | xargs)
126
+ STORY_BRANCHES=$(git branch -r | grep 'origin/story/' | sed 's|origin/||' | xargs)
127
+
128
+ # Check which release branches have unmerged commits relative to development
129
+ UNMERGED=""
130
+ for branch in $RELEASE_BRANCHES; do
131
+ AHEAD=$(git rev-list --count origin/development..origin/$branch 2>/dev/null || echo "0")
132
+ if [ "$AHEAD" -gt 0 ]; then
133
+ UNMERGED="$UNMERGED $branch"
134
+ fi
135
+ done
136
+ ```
137
+
138
+ Based on the result, follow the matching scenario:
139
+
140
+ **Scenario A — Unmerged release branches exist:**
141
+
142
+ Release branches have commits not yet in `development`. This is the "accumulate and release" pattern.
124
143
 
125
- # Check for conflicts with development
126
- git fetch origin development
127
- git merge-tree $(git merge-base HEAD origin/development) HEAD origin/development
144
+ 1. Create one PR per unmerged release branch targeting `development`
145
+ 2. Do NOT create a `development` → `main` PR (that's a separate human-initiated production release)
146
+ 3. Clean up only the story branches that are fully merged into their release branch
128
147
 
129
- # Open the PR targeting development
148
+ ```bash
130
149
  gh pr create \
131
150
  --repo <owner/repo> \
132
151
  --base development \
@@ -142,9 +161,68 @@ If there are merge conflicts with development:
142
161
  - Offer to resolve them or flag for manual resolution
143
162
  - Do NOT open the PR until conflicts are resolved
144
163
 
145
- ### Step 5: Close the Epic (if all stories are complete)
164
+ **Scenario B All release branches already merged to development:**
165
+
166
+ All epic work was merged into `development` during sprint execution. Nothing to PR into `development`.
146
167
 
147
- If all stories in the epic (milestone) are complete (no open issues remaining):
168
+ 1. Check for an existing `development` `main` PR
169
+ - If one exists, update its body with the release notes
170
+ - If none exists, create it
171
+ 2. Clean up all merged story and release branches (both local and remote)
172
+
173
+ ```bash
174
+ # Check for existing development → main PR
175
+ gh pr list --repo <owner/repo> --base main --head development --json number,state
176
+
177
+ # If no PR exists, create the production release PR
178
+ gh pr create \
179
+ --repo <owner/repo> \
180
+ --base main \
181
+ --head development \
182
+ --title "Release: Sprint <N> — <summary>" \
183
+ --body "<release PR body from Step 3>" \
184
+ --reviewer <owner> \
185
+ --label "type:release"
186
+
187
+ # If a PR already exists, update its body with the release notes
188
+ gh api repos/<owner/repo>/pulls/<pr-number> -X PATCH -f body="<release PR body>"
189
+ ```
190
+
191
+ **Scenario C — Mixed (some merged, some not):**
192
+
193
+ Some release branches were merged during sprint execution, others are still pending.
194
+
195
+ 1. Create PRs for unmerged release branches → `development` (Scenario A behavior)
196
+ 2. Do NOT create the `development` → `main` PR yet (pending work still needs to land)
197
+ 3. Clean up only fully-merged branches
198
+
199
+ ### Step 5: Clean Up Merged Branches
200
+
201
+ After handling the release PR(s), clean up branches that are fully merged into `development`. The skill that creates branches is NOT necessarily the skill that cleans them up — `project-scaffold` and `sprint-plan` create release/story branches, but `sprint-release` is responsible for cleaning up any that are fully merged by the time it runs.
202
+
203
+ ```bash
204
+ # Identify merged branches (excluding main and development)
205
+ git branch -r --merged origin/development | grep -E 'origin/(story|release)/' | sed 's|origin/||'
206
+
207
+ # Delete remote branches
208
+ for branch in <merged-branches>; do
209
+ git push origin --delete "$branch"
210
+ done
211
+
212
+ # Delete local tracking branches and prune
213
+ git branch -d <local-merged-branches>
214
+ git remote prune origin
215
+ ```
216
+
217
+ **Cleanup rules:**
218
+ - Never delete `main` or `development`
219
+ - Only delete branches fully merged into `development`
220
+ - In Scenario A/C, only delete story branches merged into their release branch — do not delete unmerged release branches
221
+ - Report all deletions in the release summary
222
+
223
+ ### Step 6: Close Epics (if all stories are complete)
224
+
225
+ If all stories in an epic (milestone) are complete (no open issues remaining):
148
226
 
149
227
  ```bash
150
228
  gh api repos/<owner/repo>/milestones/<milestone-number> -f state="closed"
@@ -152,13 +230,13 @@ gh api repos/<owner/repo>/milestones/<milestone-number> -f state="closed"
152
230
 
153
231
  If stories remain, keep the epic open for the next sprint.
154
232
 
155
- ### Step 6: Generate Release Report
233
+ ### Step 7: Generate Release Report
156
234
 
157
235
  ```
158
236
  ## Sprint <N> Release Complete
159
237
 
160
238
  **Release PR:** #<pr-number> — awaiting your review
161
- **Branch:** release/<slug> → development
239
+ **Branch:** <branch flow description, e.g. "development → main" or "release/<slug> → development">
162
240
 
163
241
  ### Sprint Scorecard
164
242
  - **Velocity:** <points_completed> points (target was <planned_points>)
@@ -170,12 +248,20 @@ If stories remain, keep the epic open for the next sprint.
170
248
  - **<Epic Name>:** <closed_issues>/<total_issues> stories complete (<percentage>%)
171
249
  - **Epic status:** <open/closed>
172
250
 
251
+ ### Cleanup
252
+ - **Branches deleted:** <list of deleted branches, or "none">
253
+ - **Remaining branches:** main, development
254
+
173
255
  ### Next Steps
256
+ <If Scenario A (release → development):>
174
257
  1. **Review the release PR:** <link to PR>
175
258
  2. **Merge to development** when satisfied
176
259
  3. Run `/sprint-plan` to plan Sprint <N+1>
177
- <If epic complete:>
178
- 4. Epic "<Epic Name>" is complete! Consider promoting development → main for a production release.
260
+
261
+ <If Scenario B (development → main):>
262
+ 1. **Review the production release PR:** <link to PR>
263
+ 2. **Merge to main** when satisfied
264
+ 3. Run `/sprint-plan` to plan the next phase
179
265
  ```
180
266
 
181
267
  ## Error Handling