claude-code-scanner 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/DOCUMENTATION.md +1210 -0
  2. package/LICENSE +21 -0
  3. package/README.md +306 -0
  4. package/bin/cli.js +305 -0
  5. package/package.json +43 -0
  6. package/template/.claude/agents/api-builder.md +64 -0
  7. package/template/.claude/agents/architect.md +92 -0
  8. package/template/.claude/agents/debugger.md +69 -0
  9. package/template/.claude/agents/explorer.md +71 -0
  10. package/template/.claude/agents/frontend.md +61 -0
  11. package/template/.claude/agents/infra.md +66 -0
  12. package/template/.claude/agents/product-owner.md +73 -0
  13. package/template/.claude/agents/qa-lead.md +102 -0
  14. package/template/.claude/agents/reviewer.md +77 -0
  15. package/template/.claude/agents/security.md +81 -0
  16. package/template/.claude/agents/team-lead.md +128 -0
  17. package/template/.claude/agents/tester.md +72 -0
  18. package/template/.claude/docs/agent-error-protocol.md +89 -0
  19. package/template/.claude/docs/best-practices.md +93 -0
  20. package/template/.claude/docs/commands-template.md +73 -0
  21. package/template/.claude/docs/conflict-resolution-protocol.md +82 -0
  22. package/template/.claude/docs/context-budget.md +54 -0
  23. package/template/.claude/docs/execution-metrics-protocol.md +105 -0
  24. package/template/.claude/docs/flow-engine.md +475 -0
  25. package/template/.claude/docs/smithery-setup.md +51 -0
  26. package/template/.claude/docs/task-record-schema.md +196 -0
  27. package/template/.claude/hooks/drift-detector.js +143 -0
  28. package/template/.claude/hooks/execution-report.js +114 -0
  29. package/template/.claude/hooks/notify-approval.js +30 -0
  30. package/template/.claude/hooks/post-compact-recovery.js +68 -0
  31. package/template/.claude/hooks/post-edit-format.js +43 -0
  32. package/template/.claude/hooks/pre-compact-save.js +94 -0
  33. package/template/.claude/hooks/protect-files.js +39 -0
  34. package/template/.claude/hooks/session-start.js +76 -0
  35. package/template/.claude/hooks/stop-failure-handler.js +77 -0
  36. package/template/.claude/hooks/tool-failure-tracker.js +54 -0
  37. package/template/.claude/hooks/track-file-changes.js +34 -0
  38. package/template/.claude/hooks/validate-bash.js +34 -0
  39. package/template/.claude/manifest.json +22 -0
  40. package/template/.claude/profiles/backend.md +34 -0
  41. package/template/.claude/profiles/devops.md +36 -0
  42. package/template/.claude/profiles/frontend.md +34 -0
  43. package/template/.claude/rules/context-budget.md +34 -0
  44. package/template/.claude/scripts/verify-setup.js +210 -0
  45. package/template/.claude/settings.json +154 -0
  46. package/template/.claude/skills/context-check/SKILL.md +112 -0
  47. package/template/.claude/skills/execution-report/SKILL.md +229 -0
  48. package/template/.claude/skills/generate-environment/SKILL.md +128 -0
  49. package/template/.claude/skills/generate-environment/additional-skills.md +276 -0
  50. package/template/.claude/skills/generate-environment/artifact-templates.md +386 -0
  51. package/template/.claude/skills/generate-environment/domain-agents.md +202 -0
  52. package/template/.claude/skills/impact-analysis/SKILL.md +17 -0
  53. package/template/.claude/skills/metrics/SKILL.md +19 -0
  54. package/template/.claude/skills/progress-report/SKILL.md +27 -0
  55. package/template/.claude/skills/rollback/SKILL.md +75 -0
  56. package/template/.claude/skills/scan-codebase/SKILL.md +59 -0
  57. package/template/.claude/skills/scan-codebase/deep-scan-instructions.md +101 -0
  58. package/template/.claude/skills/scan-codebase/tech-markers.md +87 -0
  59. package/template/.claude/skills/setup-smithery/SKILL.md +38 -0
  60. package/template/.claude/skills/sync/SKILL.md +239 -0
  61. package/template/.claude/skills/task-tracker/SKILL.md +40 -0
  62. package/template/.claude/skills/validate-setup/SKILL.md +30 -0
  63. package/template/.claude/skills/workflow/SKILL.md +333 -0
  64. package/template/.claude/templates/README.md +42 -0
  65. package/template/CLAUDE.md +67 -0
@@ -0,0 +1,333 @@
1
+ ---
2
+ name: workflow
3
+ description: Full SDLC workflow orchestrator. Coordinates agents from task intake through production deployment. Use when starting new work, checking task status, or managing the development lifecycle.
4
+ user-invocable: true
5
+ disable-model-invocation: true
6
+ context: fork
7
+ allowed-tools: Read, Edit, Write, Bash, Grep, Glob, Agent
8
+ argument-hint: "new|status|plan|dev|review|qa|deploy|resume [description|TASK-id] [--hotfix] [--spike]"
9
+ effort: high
10
+ ---
11
+
12
+ # Workflow: $ARGUMENTS
13
+
14
+ Orchestrate the full development lifecycle. No phase advances until exit criteria are met.
15
+
16
+ ## Commands
17
+ - `/workflow new "description"` — Full flow from Phase 1
18
+ - `/workflow new --hotfix "issue"` — Skip design/biz, fast-track to deploy
19
+ - `/workflow new --spike "question"` — Research only, no code (ends at CLOSED)
20
+ - `/workflow status` — All active tasks
21
+ - `/workflow resume TASK-id` — Resume ON_HOLD or interrupted task
22
+ - `/workflow cancel TASK-id` — Cancel task with cleanup
23
+ - `/workflow plan|dev|review|qa|deploy TASK-id` — Jump to phase
24
+
25
+ ## Concurrency Rule
26
+ **ONE active workflow at a time.** Before starting `/workflow new`, check `.claude/tasks/` for any task in an active state (DEVELOPING, DEV_TESTING, REVIEWING, etc.). If found:
27
+ - Prompt user: "TASK-{id} is active. Options: (1) pause it to ON_HOLD, (2) cancel it, (3) abort new workflow"
28
+ - Do NOT start a second concurrent workflow
29
+
30
+ ## Orchestration Model
31
+ **IMPORTANT:** Subagents cannot spawn other subagents. All agent-to-agent coordination flows through THIS workflow skill. When Phase N requires multiple agents, invoke them sequentially or in parallel from here — never expect one agent to call another.
32
+
33
+ **ALL handoffs route through this orchestrator.** When flow-engine describes "@debugger fixes, handoff to @tester", the actual path is: @debugger -> HANDOFF to orchestrator -> orchestrator invokes @tester.
34
+
35
+ ## Agent Team
36
+ | Role | Agent | Responsibility |
37
+ |------|-------|---------------|
38
+ | Coordination | @team-lead | Assigns work, resolves blockers, tech sign-off |
39
+ | Architecture | @architect | Design review, system design |
40
+ | Business | @product-owner | Acceptance criteria, business sign-off |
41
+ | QA Strategy | @qa-lead | QA planning, QA sign-off |
42
+ | Backend Dev | @api-builder | API endpoints, services |
43
+ | Frontend Dev | @frontend | UI components, pages |
44
+ | Testing | @tester | Write and run automated tests |
45
+ | Debugging | @debugger | Root cause analysis, bug fixes |
46
+ | Code Review | @reviewer | Quality, conventions |
47
+ | Security | @security | Vulnerability review |
48
+ | Investigation | @explorer | Codebase exploration, impact mapping |
49
+ | Infrastructure | @infra | Docker, CI/CD, deployment |
50
+
51
+ ## Handoff Protocol
52
+ Every agent transition MUST include a structured handoff:
53
+ ```
54
+ HANDOFF:
55
+ from: @agent-name
56
+ to: @next-agent
57
+ reason: why this handoff is happening
58
+ artifacts:
59
+ - list of files/docs produced
60
+ context: |
61
+ Summary of what was done and key decisions
62
+ iteration: N/max (if in a loop)
63
+ ```
64
+
65
+ ## Context Budget Protocol
66
+ **Note:** This workflow runs in `context: fork`. The `/context-check` skill measures the fork's own context, not the parent. Between heavy phases, compact the fork's context:
67
+ 1. Update task record with current phase status (persisted to disk)
68
+ 2. If responses feel slow or truncated: `/compact "focus on TASK-{id} Phase {N}"`
69
+ 3. After compaction: re-read task file to restore loop state
70
+
71
+ ---
72
+
73
+ ## Prerequisite Validation
74
+ Before advancing ANY phase, check:
75
+ 1. **Dependencies:** If task has `depends-on: TASK-X`, verify TASK-X has reached at least Phase 8 (CI_PENDING). If not, BLOCK with reason.
76
+ 2. **Task record exists:** `.claude/tasks/TASK-{id}.md` must exist and be readable.
77
+ 3. **Previous phase exit criteria met:** Read task record, confirm previous phase output sections are populated.
78
+
79
+ ---
80
+
81
+ ## VARIANT: Hotfix Fast-Track
82
+
83
+ When `--hotfix` flag is present:
84
+ ```
85
+ Phase 1 (Intake: type=hotfix) -> Phase 2 (Impact, abbreviated)
86
+ -> SKIP Phase 3 (Architecture) and Phase 4 (Business)
87
+ -> Phase 5 (Dev: @debugger as primary, not @api-builder)
88
+ -> Phase 6 (Dev-Test: max 3 iterations, not 5)
89
+ -> Phase 7 (Review: @reviewer + @security, max 2 iterations)
90
+ -> Phase 8 (PR + CI: max 2 attempts)
91
+ -> Phase 9 (QA: verify-only — @qa-lead confirms fix, no full test plan)
92
+ -> Phase 10 (Tech sign-off ONLY — skip QA formal + business sign-off)
93
+ -> Phase 11 (Deploy: max 1 attempt, rollback immediately on failure)
94
+ -> Phase 12 (Post-Deploy: monitor 15min, not 30)
95
+ ```
96
+
97
+ **Hotfix circuit breakers (tighter):**
98
+ - Dev-test: max 3 (not 5)
99
+ - Review: max 2 (not 3)
100
+ - CI: max 2 (not 3)
101
+ - Deploy: max 1 (immediate rollback on failure)
102
+ - If any breaker trips: rollback + escalate immediately
103
+
104
+ ---
105
+
106
+ ## VARIANT: Spike (Research Only)
107
+
108
+ When `--spike` flag is present:
109
+ ```
110
+ Phase 1 (Intake: type=spike) -> create task record, NO branch
111
+ -> Phase 2 (Impact Analysis: @explorer only, no @security)
112
+ -> Phase 3 (Architecture: @architect + @explorer investigate the question)
113
+ -> SKIP Phase 4-12 (no code, no tests, no deploy)
114
+ -> Output: Research Report saved to task record
115
+ - Question investigated
116
+ - Findings with file:line refs
117
+ - Recommendation: proceed as feature / not viable / needs more research
118
+ - Estimated complexity if proceeding
119
+ -> Task status: CLOSED (type: spike)
120
+ -> If recommendation is "proceed as feature": prompt user to run
121
+ `/workflow new "description based on spike findings"`
122
+ ```
123
+
124
+ **Spike has NO loops, NO circuit breakers, NO sign-offs.**
125
+
126
+ ---
127
+
128
+ ## Phase 1: Task Intake
129
+ **Drift check (automatic):** Run `/sync --check` silently. If drift detected:
130
+ - Minor drift (1-3 items): log warning in task record, continue
131
+ - Major drift (4+ items or tech stack change): prompt user "Environment may be stale. Run `/sync --fix` before continuing? (y/N)"
132
+ - If user says yes: run `/sync --fix`, then continue intake
133
+ - If user says no: continue with warning logged
134
+
135
+ Classify type (feature/bugfix/refactor/hotfix/spike), scope (frontend/backend/fullstack/infra), complexity (small/medium/large). Create branch (except spike). Log to `.claude/tasks/TASK-{id}.md`.
136
+
137
+ **State: INTAKE**
138
+
139
+ ## Phase 2: Impact Analysis
140
+ Run @explorer + @security in PARALLEL (spike: @explorer only).
141
+ - Files affected, blast radius, test coverage, security flags
142
+ - Risk: LOW/MEDIUM/HIGH/CRITICAL
143
+ - Exit: impact report generated
144
+
145
+ **State: ANALYZING**
146
+
147
+ ## Phase 3: Architecture Review
148
+ **Skip condition (automatic):** Skip if ALL of: complexity == small AND risk == LOW AND type != refactor.
149
+ If skipped, log in task record: "Phase 3 skipped: small + LOW risk."
150
+ If NOT skipped: @architect designs solution. User approves before proceeding.
151
+
152
+ **State: DESIGNING -> APPROVED (on user approval)**
153
+
154
+ ## Phase 4: Business Analysis
155
+ @product-owner generates acceptance criteria (GIVEN/WHEN/THEN). User confirms.
156
+ **Skip condition:** Skip if type == hotfix OR type == refactor OR type == tech-debt.
157
+
158
+ **State: APPROVED (after user confirms criteria)**
159
+
160
+ ## Phase 5: Development
161
+ @team-lead assigns by scope. **Sub-steps are conditional:**
162
+
163
+ | Sub-step | Runs When | Agent |
164
+ |----------|-----------|-------|
165
+ | 5a: DB migrations | scope includes backend AND database changes detected | @api-builder |
166
+ | 5b: Backend code | scope includes backend | @api-builder |
167
+ | 5c: Frontend code | scope includes frontend | @frontend |
168
+ | 5d: Tests | always (even infra tasks get smoke tests) | @tester |
169
+
170
+ **Fullstack parallel execution:**
171
+ 1. 5a runs FIRST (DB must be ready before code)
172
+ 2. 5b + 5c run in PARALLEL (using isolation: worktree)
173
+ 3. @api-builder's worktree merges FIRST (backend defines API contract)
174
+ 4. @team-lead resolves any type/interface conflicts
175
+ 5. @frontend's worktree merges SECOND (adapts to final backend)
176
+ 6. 5d runs AFTER merge (tests against merged code)
177
+
178
+ **If one parallel agent finishes early:** It waits. The orchestrator does NOT advance that agent to Phase 6 independently — both must complete Phase 5 before either enters Phase 6.
179
+
180
+ **State: DEVELOPING**
181
+
182
+ ## Phase 6: Dev Self-Testing
183
+ @tester runs FIRST. Measure coverage baseline at Phase 5 end.
184
+ **Loop (max 5 iterations):**
185
+ 1. Orchestrator invokes @tester -> full test suite
186
+ 2. ALL PASS + coverage >= baseline -> EXIT to Phase 7
187
+ 3. FAILURES -> route to fix agent by issue type
188
+ 4. Fix agent applies fix -> HANDOFF back
189
+ 5. Re-invoke @tester (increment iteration)
190
+ 6. **Agent timeout:** If fix agent hits maxTurns, count as 1 loop iteration, re-invoke with narrowed scope
191
+ 7. Iteration 5 -> CIRCUIT BREAKER
192
+
193
+ Track: `dev-test-loop: N/5`, `coverage-baseline`, `coverage-current`, `fix-agent`, `last-failure`
194
+
195
+ **State: DEV_TESTING**
196
+
197
+ ## Phase 7: Code Review
198
+ @reviewer + @security in PARALLEL. Stricter verdict wins if split.
199
+ **Loop (max 3 iterations):**
200
+ 1. BOTH APPROVE -> EXIT to Phase 8
201
+ 2. SPLIT DECISION -> only re-review with rejecting agent
202
+ 3. REQUEST_CHANGES -> route fixes by category to appropriate dev agent
203
+ 4. Partial re-review (only the agent(s) that requested changes)
204
+ 5. **Agent timeout:** Reviewer timeout = count as iteration, re-invoke
205
+ 6. Iteration 3 -> CIRCUIT BREAKER
206
+
207
+ Track: `review-loop: N/3`, `reviewer-status`, `security-status`, `open-comments`
208
+
209
+ **State: REVIEWING**
210
+
211
+ ## Phase 8: PR + CI
212
+ Create PR, wait for CI.
213
+ **Loop (max 3 iterations):**
214
+ 1. CI fails -> classify failure -> route to fix agent
215
+ 2. Fix -> push -> CI re-runs
216
+ 3. Substantive fix (logic change): flag for Phase 7 re-review
217
+ 4. **Agent timeout:** CI fix agent timeout = count as iteration
218
+ 5. Iteration 3 -> CIRCUIT BREAKER
219
+
220
+ Track: `ci-fix-loop: N/3`, `last-ci-failure`, `fix-agent`
221
+
222
+ **State: CI_PENDING**
223
+
224
+ ## Phase 9: QA Testing
225
+ 1. @qa-lead creates QA test plan
226
+ 2. @tester executes automated scenarios (this is how @qa-lead gets test execution — @qa-lead plans, @tester executes)
227
+ 3. @qa-lead reviews results, files bug reports
228
+
229
+ **Bug loop (max 3 per bug, 15 total):**
230
+ - Priority order: P0 -> P1 -> P2. P3/P4 logged as known issues.
231
+ - Per bug: @debugger fixes -> @tester regression suite -> @qa-lead re-verifies
232
+ - P2: @qa-lead decides — must-fix or CONDITIONAL with workaround doc
233
+ - Per-bug iteration 3 -> escalate THAT bug to @team-lead
234
+ - Total > 15 -> escalate entire Phase 9
235
+
236
+ Track: `qa-bug-loop` per bug, `total-bugs`, `regression-check-after-each-fix: true`
237
+
238
+ **State: QA_TESTING**
239
+
240
+ ## Phase 10: Sign-offs (max 2 full rejection cycles)
241
+ Sequential gates:
242
+ 1. **QA sign-off** -> @qa-lead
243
+ 2. **Business sign-off** -> @product-owner (skip if hotfix/refactor/tech-debt)
244
+ 3. **Tech sign-off** -> @team-lead
245
+
246
+ **Sign-off preservation on rejection:**
247
+ | Rejection | QA Approval | Biz Approval | Route To |
248
+ |-----------|-------------|-------------|----------|
249
+ | @qa-lead (bugs) | INVALIDATED | INVALIDATED | Phase 5 -> Phase 6 -> 7 -> 8 -> 9 -> 10 |
250
+ | @product-owner (reqs) | PRESERVED | INVALIDATED | Phase 4 -> Phase 5 -> ... -> 10 |
251
+ | @product-owner (UI) | PRESERVED | INVALIDATED | Phase 5c -> 6 -> 7 -> 8 -> 9 -> 10 |
252
+ | @team-lead (architecture) | INVALIDATED | INVALIDATED | Phase 3 -> full re-flow |
253
+ | @team-lead (perf/tests) | PRESERVED | PRESERVED | Phase 5 -> 6 -> 7 -> 8 -> 9 -> 10 |
254
+
255
+ **On re-entry:** ALL inner loop counters reset to 0. Signoff-rejection-cycle increments.
256
+ **Cycle 2 -> CIRCUIT BREAKER:** escalate to user (continue, re-scope, split, cancel)
257
+
258
+ Track: `signoff-rejection-cycle: N/2`, per-gate status
259
+
260
+ **States: QA_SIGNOFF -> BIZ_SIGNOFF -> TECH_SIGNOFF**
261
+
262
+ ## Phase 11: Deployment (max 2 attempts)
263
+ @infra: pre-checks -> merge PR -> deploy -> health check -> smoke test.
264
+ **On failure — triage first:**
265
+ - Config/env -> @infra fixes -> retry directly
266
+ - Code bug -> @debugger hotfix -> fast-track Phase 6->7->8->11
267
+ - Infra issue -> @infra resolves -> retry
268
+ - Unknown -> `/rollback`, escalate to user
269
+ Attempt 2 fails -> rollback + escalate.
270
+
271
+ Track: `deploy-loop: N/2`, `last-deploy-failure`, `rollback-executed`
272
+
273
+ **State: DEPLOYING**
274
+
275
+ ## Phase 12: Post-Deploy
276
+ Monitor 30min (hotfix: 15min). Close issues. Notify stakeholders.
277
+ Production bugs: P0/P1 -> new hotfix workflow, P2/P3 -> new task.
278
+
279
+ **State: MONITORING -> CLOSED**
280
+
281
+ ## Phase 13: Execution Report
282
+ Generated by the orchestrator (NOT the Stop hook — Stop hook handles session-level reports, Phase 13 handles workflow-level reports):
283
+ - **Per-phase reports:** Generated after each phase completes, saved to `.claude/reports/executions/TASK-{id}_phase-{N}_{timestamp}.md`
284
+ - **Final cumulative report:** Generated once after Phase 12, saved to `.claude/reports/executions/TASK-{id}_final.md`
285
+ - **Stop hook:** Generates session-level snapshot only — does NOT duplicate Phase 13
286
+
287
+ ---
288
+
289
+ ## ON_HOLD Management
290
+ - **Enter:** Any sign-off gate defers, or user explicitly pauses
291
+ - **State preserved:** Task stays at its current phase, all loop counters preserved
292
+ - **Resume:** `/workflow resume TASK-id` — re-enters at the saved phase
293
+ - **Auto-reminder:** If ON_HOLD > 7 days, session-start hook warns user
294
+ - **Cancel threshold:** If ON_HOLD > 30 days, prompt user to cancel or resume
295
+
296
+ ## CANCELLED Cleanup
297
+ When `/workflow cancel TASK-id`:
298
+ 1. Set status to CANCELLED in task record
299
+ 2. Close any open PR: `gh pr close {pr_number}`
300
+ 3. Delete feature branch: `git branch -D {branch}` (local only — prompt for remote)
301
+ 4. Clean up worktrees: `git worktree remove` if any exist
302
+ 5. Log cancellation in task timeline with reason
303
+ 6. Task record stays in `.claude/tasks/` for historical reference
304
+
305
+ ## Task State Machine
306
+ ```
307
+ BACKLOG -> INTAKE -> ANALYZING -> DESIGNING -> APPROVED -> DEVELOPING
308
+ -> DEV_TESTING -> REVIEWING -> CI_PENDING -> QA_TESTING
309
+ -> QA_SIGNOFF -> BIZ_SIGNOFF -> TECH_SIGNOFF
310
+ -> DEPLOYING -> MONITORING -> CLOSED
311
+
312
+ Special states (from ANY active state):
313
+ -> BLOCKED (requires depends-on resolution or manual unblock)
314
+ -> ON_HOLD (user/product-owner deferred, resume with /workflow resume)
315
+ -> CANCELLED (cleanup executed, terminal state)
316
+
317
+ Reverse transitions (rejection routing):
318
+ QA_SIGNOFF -> DEVELOPING (QA rejects)
319
+ BIZ_SIGNOFF -> APPROVED (reqs wrong) or DEVELOPING (UI wrong)
320
+ TECH_SIGNOFF -> DESIGNING (architecture) or DEVELOPING (perf/tests)
321
+ ```
322
+
323
+ ## Circuit Breaker Summary
324
+ | Loop | Max | Scope | Hotfix Max |
325
+ |------|-----|-------|------------|
326
+ | Dev-Test (P6) | 5 | Global | 3 |
327
+ | Review (P7) | 3 | Global | 2 |
328
+ | CI Fix (P8) | 3 | Global | 2 |
329
+ | QA Bug (P9) | 3/bug, 15 total | Per-bug | 2/bug, 6 total |
330
+ | Sign-off (P10) | 2 cycles | Global | 1 cycle |
331
+ | Deploy (P11) | 2 | Global | 1 |
332
+
333
+ Any breaker tripped -> STOP -> escalate to user: continue, re-plan, reduce scope, cancel, assign to human.
@@ -0,0 +1,42 @@
1
+ # Code Templates
2
+
3
+ This directory contains code scaffolding templates extracted from the REAL codebase during `/generate-environment`. Templates are NOT invented — they are skeletons derived from actual existing files.
4
+
5
+ ## How Templates Are Extracted
6
+ 1. Read 3-5 existing files of each type
7
+ 2. Identify the common skeleton (imports, structure, patterns, exports)
8
+ 3. Replace specific values with `{placeholder}` markers
9
+ 4. Save as a markdown file with the template in a code block
10
+
11
+ ## Expected Templates (generated per project)
12
+ - `component.md` — UI component skeleton (if frontend exists)
13
+ - `api-endpoint.md` — API route/handler/service skeleton (if backend API exists)
14
+ - `service.md` — Business logic service skeleton
15
+ - `model.md` — Data model/entity skeleton (if ORM exists)
16
+ - `test.md` — Test file skeleton matching project patterns
17
+ - `hook.md` — React hook / lifecycle hook skeleton (if applicable)
18
+ - `migration.md` — Database migration skeleton (if migrations exist)
19
+ - `middleware.md` — Middleware skeleton (if middleware pattern detected)
20
+
21
+ ## Template Format
22
+ ```markdown
23
+ # Template: {type}
24
+ Source: extracted from {list of source files}
25
+ Pattern: {pattern name}
26
+
27
+ \`\`\`{language}
28
+ {template code with {placeholders}}
29
+ \`\`\`
30
+
31
+ ## Usage
32
+ {when to use this template}
33
+
34
+ ## Customization Points
35
+ - {placeholder1}: {what to replace with}
36
+ - {placeholder2}: {what to replace with}
37
+ ```
38
+
39
+ ## Important
40
+ - Templates are EMPTY until `/generate-environment` runs
41
+ - Never invent patterns — only extract from existing code
42
+ - Update templates when codebase patterns change significantly
@@ -0,0 +1,67 @@
1
+ # Codebase Scanner & Claude Code Environment Generator
2
+
3
+ You are a **Codebase Archaeology & Claude Code Setup Specialist**. Scan any existing codebase and generate a production-ready Claude Code environment.
4
+
5
+ ## What You Generate
6
+ - `CLAUDE.md` (root + nested per module)
7
+ - `.claude/rules/` — path-specific rules
8
+ - `.claude/agents/` — role-based agent team (12 agents)
9
+ - `.claude/skills/` — workflow skills
10
+ - `.claude/settings.json` — permissions, hooks
11
+ - `.claude/hooks/` — automation scripts
12
+ - `.claude/templates/` — code scaffolding templates
13
+ - `.claude/profiles/` — developer role profiles
14
+ - `.claude/scripts/` — setup + verification scripts
15
+ - `.claude/docs/commands.md` — master command reference
16
+
17
+ ## Execution Order
18
+
19
+ ### Phase 1: Scan (parallel subagents)
20
+ Use `/scan-codebase` skill — spawns 6 agents to fingerprint the tech stack, directory structure, backend, frontend, architecture, domain knowledge, and tooling. Outputs a `TECH_MANIFEST`.
21
+
22
+ ### Phase 2: Generate
23
+ Use `/generate-environment` skill — takes TECH_MANIFEST and produces all artifacts. Every `{placeholder}` replaced with real values from Phase 1.
24
+
25
+ ### Phase 3: Validate
26
+ Use `/validate-setup` skill — checks line counts, JSON validity, hook permissions, context budget.
27
+
28
+ ### Phase 4: Setup Smithery
29
+ Use `/setup-smithery` skill — installs matching Smithery skills and MCP servers based on tech stack.
30
+
31
+ ## Context Budget Rules
32
+ - Root CLAUDE.md: recommended 150 lines (hard limit 200)
33
+ - Rules: max 50 lines each, with `paths:` frontmatter
34
+ - Skills: `context: fork` for heavy work
35
+ - MCP servers: max 5, scoped to agents via `mcpServers:` field
36
+ - Startup context: under 20%
37
+ - Working context: under 60%
38
+ - Run `/context` to verify
39
+
40
+ ## Agent Team (Role-Based)
41
+ | Role | Agent | Access |
42
+ |------|-------|--------|
43
+ | Tech Lead | `@team-lead` | Read/Write — orchestrates, assigns, signs off |
44
+ | Architect | `@architect` | Read-only — designs, reviews architecture |
45
+ | Product Owner | `@product-owner` | Read-only — acceptance criteria, biz sign-off |
46
+ | QA Lead | `@qa-lead` | Read-only — QA plans, QA sign-off |
47
+ | Explorer | `@explorer` | Read-only — investigation, impact analysis |
48
+ | Reviewer | `@reviewer` | Read-only — code review |
49
+ | Security | `@security` | Read-only — vulnerability review |
50
+ | API Dev | `@api-builder` | Read/Write — backend endpoints, services |
51
+ | Frontend Dev | `@frontend` | Read/Write — UI components, pages |
52
+ | Tester | `@tester` | Read/Write — automated tests |
53
+ | Debugger | `@debugger` | Read/Write — bug fixes |
54
+ | Infra | `@infra` | Read/Write — Docker, CI/CD, deployment |
55
+
56
+ ## Keeping In Sync
57
+ - `/sync --check` — detect drift between environment and codebase (weekly recommended)
58
+ - `/sync --fix` — auto-repair stale agents, skills, CLAUDE.md, rules, hooks
59
+ - `/sync --full-rescan` — re-scan and regenerate everything
60
+ - Drift detector runs automatically on every session start
61
+
62
+ ## Workflow After Setup
63
+ - `/workflow new "task"` — full SDLC (intake -> impact -> design -> dev -> test -> review -> QA -> signoff -> deploy)
64
+ - `/task-tracker status` — dashboard
65
+ - See `.claude/docs/commands.md` for complete reference
66
+
67
+ @.claude/rules/context-budget.md