bigpowers 2.2.0 → 2.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.
Files changed (147) hide show
  1. package/.pi/package.json +16 -0
  2. package/.pi/prompts/assess-impact.md +76 -0
  3. package/.pi/prompts/audit-code.md +156 -0
  4. package/.pi/prompts/build-epic.md +44 -0
  5. package/.pi/prompts/change-request.md +105 -0
  6. package/.pi/prompts/commit-message.md +135 -0
  7. package/.pi/prompts/compose-workflow.md +40 -0
  8. package/.pi/prompts/craft-skill.md +150 -0
  9. package/.pi/prompts/deepen-architecture.md +235 -0
  10. package/.pi/prompts/define-language.md +79 -0
  11. package/.pi/prompts/define-success.md +62 -0
  12. package/.pi/prompts/delegate-task.md +76 -0
  13. package/.pi/prompts/design-interface.md +96 -0
  14. package/.pi/prompts/develop-tdd.md +375 -0
  15. package/.pi/prompts/diagnose-root.md +23 -0
  16. package/.pi/prompts/dispatch-agents.md +83 -0
  17. package/.pi/prompts/edit-document.md +22 -0
  18. package/.pi/prompts/elaborate-spec.md +81 -0
  19. package/.pi/prompts/enforce-first.md +77 -0
  20. package/.pi/prompts/evolve-skill.md +38 -0
  21. package/.pi/prompts/execute-plan.md +54 -0
  22. package/.pi/prompts/fix-bug.md +36 -0
  23. package/.pi/prompts/grill-me.md +95 -0
  24. package/.pi/prompts/grill-with-docs.md +37 -0
  25. package/.pi/prompts/guard-git.md +212 -0
  26. package/.pi/prompts/hook-commits.md +93 -0
  27. package/.pi/prompts/inspect-quality.md +105 -0
  28. package/.pi/prompts/investigate-bug.md +117 -0
  29. package/.pi/prompts/kickoff-branch.md +99 -0
  30. package/.pi/prompts/map-codebase.md +70 -0
  31. package/.pi/prompts/migrate-spec.md +482 -0
  32. package/.pi/prompts/model-domain.md +227 -0
  33. package/.pi/prompts/orchestrate-project.md +161 -0
  34. package/.pi/prompts/organize-workspace.md +159 -0
  35. package/.pi/prompts/plan-refactor.md +77 -0
  36. package/.pi/prompts/plan-release.md +145 -0
  37. package/.pi/prompts/plan-work.md +161 -0
  38. package/.pi/prompts/release-branch.md +158 -0
  39. package/.pi/prompts/request-review.md +70 -0
  40. package/.pi/prompts/research-first.md +62 -0
  41. package/.pi/prompts/reset-baseline.md +20 -0
  42. package/.pi/prompts/respond-review.md +70 -0
  43. package/.pi/prompts/run-evals.md +56 -0
  44. package/.pi/prompts/run-planning.md +26 -0
  45. package/.pi/prompts/scope-work.md +23 -0
  46. package/.pi/prompts/search-skills.md +21 -0
  47. package/.pi/prompts/seed-conventions.md +132 -0
  48. package/.pi/prompts/session-state.md +146 -0
  49. package/.pi/prompts/setup-environment.md +23 -0
  50. package/.pi/prompts/simulate-agents.md +25 -0
  51. package/.pi/prompts/slice-tasks.md +23 -0
  52. package/.pi/prompts/spike-prototype.md +94 -0
  53. package/.pi/prompts/stocktake-skills.md +40 -0
  54. package/.pi/prompts/survey-context.md +129 -0
  55. package/.pi/prompts/terse-mode.md +37 -0
  56. package/.pi/prompts/trace-requirement.md +68 -0
  57. package/.pi/prompts/using-bigpowers.md +105 -0
  58. package/.pi/prompts/validate-fix.md +98 -0
  59. package/.pi/prompts/verify-work.md +125 -0
  60. package/.pi/prompts/visual-dashboard.md +51 -0
  61. package/.pi/prompts/wire-observability.md +92 -0
  62. package/.pi/prompts/write-document.md +244 -0
  63. package/.pi/skills/assess-impact/SKILL.md +77 -0
  64. package/.pi/skills/audit-code/SKILL.md +157 -0
  65. package/.pi/skills/build-epic/SKILL.md +45 -0
  66. package/.pi/skills/change-request/SKILL.md +106 -0
  67. package/.pi/skills/commit-message/SKILL.md +136 -0
  68. package/.pi/skills/compose-workflow/SKILL.md +41 -0
  69. package/.pi/skills/craft-skill/SKILL.md +151 -0
  70. package/.pi/skills/deepen-architecture/SKILL.md +236 -0
  71. package/.pi/skills/define-language/SKILL.md +80 -0
  72. package/.pi/skills/define-success/SKILL.md +63 -0
  73. package/.pi/skills/delegate-task/SKILL.md +77 -0
  74. package/.pi/skills/design-interface/SKILL.md +97 -0
  75. package/.pi/skills/develop-tdd/SKILL.md +376 -0
  76. package/.pi/skills/diagnose-root/SKILL.md +24 -0
  77. package/.pi/skills/dispatch-agents/SKILL.md +84 -0
  78. package/.pi/skills/edit-document/SKILL.md +23 -0
  79. package/.pi/skills/elaborate-spec/SKILL.md +82 -0
  80. package/.pi/skills/enforce-first/SKILL.md +78 -0
  81. package/.pi/skills/evolve-skill/SKILL.md +39 -0
  82. package/.pi/skills/execute-plan/SKILL.md +55 -0
  83. package/.pi/skills/fix-bug/SKILL.md +37 -0
  84. package/.pi/skills/grill-me/SKILL.md +96 -0
  85. package/.pi/skills/grill-with-docs/SKILL.md +38 -0
  86. package/.pi/skills/guard-git/SKILL.md +213 -0
  87. package/.pi/skills/hook-commits/SKILL.md +94 -0
  88. package/.pi/skills/inspect-quality/SKILL.md +106 -0
  89. package/.pi/skills/investigate-bug/SKILL.md +118 -0
  90. package/.pi/skills/kickoff-branch/SKILL.md +100 -0
  91. package/.pi/skills/map-codebase/SKILL.md +71 -0
  92. package/.pi/skills/migrate-spec/SKILL.md +483 -0
  93. package/.pi/skills/model-domain/SKILL.md +228 -0
  94. package/.pi/skills/orchestrate-project/SKILL.md +162 -0
  95. package/.pi/skills/organize-workspace/SKILL.md +160 -0
  96. package/.pi/skills/plan-refactor/SKILL.md +78 -0
  97. package/.pi/skills/plan-release/SKILL.md +146 -0
  98. package/.pi/skills/plan-work/SKILL.md +162 -0
  99. package/.pi/skills/release-branch/SKILL.md +159 -0
  100. package/.pi/skills/request-review/SKILL.md +71 -0
  101. package/.pi/skills/research-first/SKILL.md +63 -0
  102. package/.pi/skills/reset-baseline/SKILL.md +21 -0
  103. package/.pi/skills/respond-review/SKILL.md +71 -0
  104. package/.pi/skills/run-evals/SKILL.md +57 -0
  105. package/.pi/skills/run-planning/SKILL.md +27 -0
  106. package/.pi/skills/scope-work/SKILL.md +24 -0
  107. package/.pi/skills/search-skills/SKILL.md +22 -0
  108. package/.pi/skills/seed-conventions/SKILL.md +133 -0
  109. package/.pi/skills/session-state/SKILL.md +147 -0
  110. package/.pi/skills/setup-environment/SKILL.md +24 -0
  111. package/.pi/skills/simulate-agents/SKILL.md +26 -0
  112. package/.pi/skills/slice-tasks/SKILL.md +24 -0
  113. package/.pi/skills/spike-prototype/SKILL.md +95 -0
  114. package/.pi/skills/stocktake-skills/SKILL.md +41 -0
  115. package/.pi/skills/survey-context/SKILL.md +130 -0
  116. package/.pi/skills/terse-mode/SKILL.md +38 -0
  117. package/.pi/skills/trace-requirement/SKILL.md +69 -0
  118. package/.pi/skills/using-bigpowers/SKILL.md +106 -0
  119. package/.pi/skills/validate-fix/SKILL.md +99 -0
  120. package/.pi/skills/verify-work/SKILL.md +126 -0
  121. package/.pi/skills/visual-dashboard/SKILL.md +52 -0
  122. package/.pi/skills/wire-observability/SKILL.md +93 -0
  123. package/.pi/skills/write-document/SKILL.md +245 -0
  124. package/CHANGELOG.md +14 -0
  125. package/README.md +27 -1
  126. package/deepen-architecture/SKILL.md +2 -0
  127. package/define-language/SKILL.md +2 -0
  128. package/diagnose-root/SKILL.md +2 -0
  129. package/edit-document/SKILL.md +2 -0
  130. package/fix-bug/SKILL.md +3 -1
  131. package/grill-me/SKILL.md +3 -1
  132. package/grill-with-docs/SKILL.md +3 -1
  133. package/investigate-bug/SKILL.md +5 -11
  134. package/map-codebase/SKILL.md +3 -1
  135. package/model-domain/SKILL.md +2 -0
  136. package/package.json +11 -2
  137. package/plan-release/SKILL.md +1 -1
  138. package/plan-work/SKILL.md +3 -1
  139. package/release-branch/SKILL.md +4 -2
  140. package/run-planning/SKILL.md +3 -2
  141. package/scope-work/SKILL.md +3 -1
  142. package/scripts/sync-skills.sh +48 -3
  143. package/scripts/validate-doctrine.sh +24 -9
  144. package/seed-conventions/SKILL.md +2 -0
  145. package/slice-tasks/SKILL.md +3 -1
  146. package/survey-context/SKILL.md +3 -1
  147. package/write-document/SKILL.md +2 -0
@@ -0,0 +1,80 @@
1
+ ---
2
+ name: define-language
3
+ description: "Extract a DDD-style ubiquitous language glossary from the current conversation, flagging ambiguities and proposing canonical terms. Saves to specs/UBIQUITOUS_LANGUAGE.md. Use when user wants to define domain terms, build a glossary, harden terminology, create a ubiquitous language, or mentions "domain model" or "DDD"."
4
+ ---
5
+
6
+
7
+ # Define Language
8
+
9
+ Extract and formalize domain terminology from the current conversation into a consistent glossary, saved to `specs/UBIQUITOUS_LANGUAGE.md`.
10
+
11
+ **Distinct from `model-domain` and `deepen-architecture`:** Use this skill to produce a canonical glossary of terms (words and definitions). Use `model-domain` to stress-test a plan through an interview that resolves domain model decisions. Use `deepen-architecture` to find module-level refactoring opportunities in the codebase.
12
+
13
+ > **HARD GATE** — Ubiquitous language is NOT optional. Every term in the domain that could be misunderstood must be glossed. Ambiguity = rework.
14
+
15
+ ## Process
16
+
17
+ 1. **Scan the conversation** for domain-relevant nouns, verbs, and concepts
18
+ 2. **Identify problems**:
19
+ - Same word used for different concepts (ambiguity)
20
+ - Different words used for the same concept (synonyms)
21
+ - Vague or overloaded terms
22
+ 3. **Propose a canonical glossary** with opinionated term choices
23
+ 4. **Write to `specs/UBIQUITOUS_LANGUAGE.md`** in the working directory using the format below
24
+ 5. **Output a summary** inline in the conversation
25
+
26
+ ## Output Format
27
+
28
+ Write a `specs/UBIQUITOUS_LANGUAGE.md` file with this structure:
29
+
30
+ ```md
31
+ # Ubiquitous Language
32
+
33
+ ## Order lifecycle
34
+
35
+ | Term | Definition | Aliases to avoid |
36
+ | ----------- | ------------------------------------------------------- | --------------------- |
37
+ | **Order** | A customer's request to purchase one or more items | Purchase, transaction |
38
+ | **Invoice** | A request for payment sent to a customer after delivery | Bill, payment request |
39
+
40
+ ## People
41
+
42
+ | Term | Definition | Aliases to avoid |
43
+ | ------------ | ------------------------------------------- | ---------------------- |
44
+ | **Customer** | A person or organization that places orders | Client, buyer, account |
45
+ | **User** | An authentication identity in the system | Login, account |
46
+
47
+ ## Relationships
48
+
49
+ - An **Invoice** belongs to exactly one **Customer**
50
+ - An **Order** produces one or more **Invoices**
51
+
52
+ ## Example dialogue
53
+
54
+ > **Dev:** "When a **Customer** places an **Order**, do we create the **Invoice** immediately?"
55
+ > **Domain expert:** "No — an **Invoice** is only generated once a **Fulfillment** is confirmed."
56
+
57
+ ## Flagged ambiguities
58
+
59
+ - "account" was used to mean both **Customer** and **User** — these are distinct concepts.
60
+ ```
61
+
62
+ ## Rules
63
+
64
+ - **Be opinionated.** When multiple words exist for the same concept, pick the best one and list the others as aliases to avoid.
65
+ - **Flag conflicts explicitly.** If a term is used ambiguously, call it out in "Flagged ambiguities" with a clear recommendation.
66
+ - **Only include terms relevant for domain experts.** Skip names of modules or classes unless they have domain meaning.
67
+ - **Keep definitions tight.** One sentence max. Define what it IS, not what it does.
68
+ - **Show relationships.** Use bold term names and express cardinality where obvious.
69
+ - **Group terms into multiple tables** when natural clusters emerge. One table is fine if terms are cohesive.
70
+ - **Write an example dialogue.** 3–5 exchanges between a dev and domain expert showing terms used precisely.
71
+
72
+ ## Re-running
73
+
74
+ When invoked again in the same conversation:
75
+
76
+ 1. Read the existing `specs/UBIQUITOUS_LANGUAGE.md`
77
+ 2. Incorporate any new terms from subsequent discussion
78
+ 3. Update definitions if understanding has evolved
79
+ 4. Re-flag any new ambiguities
80
+ 5. Rewrite the example dialogue to incorporate new terms
@@ -0,0 +1,63 @@
1
+ ---
2
+ name: define-success
3
+ description: "Convert an imperative task statement into explicit "step → verify: <cmd>" pairs before implementation begins. Use before plan-work when success criteria are unclear, when a task lacks verifiable checkpoints, or when user says "how will we know this is done?"."
4
+ ---
5
+
6
+
7
+ # Define Success
8
+
9
+ Transform "do X" into "step → verify: <cmd>" pairs. This is the pre-flight check before `plan-work` or `develop-tdd` — it makes success observable and removes ambiguity about when you're done.
10
+
11
+ > **HARD GATE** — Success criteria must be testable and user-observable. "Code should be fast" is not testable. "Pageload latency < 2s" is testable.
12
+
13
+ ## Why this matters
14
+
15
+ "Implement user authentication" is not a plan. It has no checkpoints, no evidence requirement, and no way to know if you're done. The Karpathy principle: every step must be independently verifiable with a runnable command. If you can't verify it, you can't prove it works.
16
+
17
+ ## Process
18
+
19
+ ### 1. Read the task statement
20
+
21
+ Take the task as stated (from conversation, or from `specs/epics/ (see slice-tasks)`, or from `specs/product/SCOPE_LATEST.yaml`).
22
+
23
+ ### 2. Break into observable outcomes
24
+
25
+ For each thing the task requires, identify:
26
+ - The smallest unit of observable behavior that proves something works
27
+ - The command that proves it
28
+
29
+ Work at the level of behaviors (what the system does) not implementation steps (how you'll write the code).
30
+
31
+ ### 3. Write the pairs
32
+
33
+ Format each pair as:
34
+ ```
35
+ N. [What must be true] → verify: <runnable command>
36
+ ```
37
+
38
+ Examples:
39
+
40
+ ```
41
+ Task: "Add user registration to the API"
42
+
43
+ 1. POST /users accepts {email, name} and returns {id, email, name} → verify: curl -s -X POST http://localhost:3000/users -H 'Content-Type: application/json' -d '{"email":"test@test.com","name":"Test"}' | jq .id
44
+ 2. Duplicate email is rejected with 409 → verify: npm test -- user-registration.test.ts
45
+ 3. Missing email is rejected with 400 and descriptive error → verify: npm test -- user-validation.test.ts
46
+ 4. Password is hashed (never stored in plaintext) → verify: npm test -- user-security.test.ts
47
+ 5. All existing tests still pass → verify: npm test
48
+ ```
49
+
50
+ ### 4. Challenge completeness
51
+
52
+ Ask yourself:
53
+ - Is there any behavior the task requires that isn't covered by a verify step?
54
+ - Is every verify step runnable right now without additional setup?
55
+ - Does the final step verify the whole thing end-to-end?
56
+
57
+ Add any missing pairs.
58
+
59
+ ### 5. Output
60
+
61
+ Present the pairs to the user and ask: "Does this capture everything the task requires? Anything missing?"
62
+
63
+ Once confirmed, these pairs become the skeleton for `plan-work`'s steps. Pass them along when calling `plan-work`.
@@ -0,0 +1,77 @@
1
+ ---
2
+ name: delegate-task
3
+ description: "Delegate one complex task to a single subagent, review its work in two stages before merging back. Sequential — one agent at a time, with oversight. Use when a task is complex and requires careful review before the result is accepted. Distinct from dispatch-agents (no parallelism here; reviewer sees full diff before proceeding)."
4
+ ---
5
+
6
+
7
+ # Delegate Task
8
+ > **HARD GATE** — **HARD GATE** — Delegated work must have clear success criteria and verification commands. The delegate must be able to verify completion independently.
9
+
10
+
11
+ Delegate a single complex task to a subagent with a two-stage review gate before accepting the result. Use when oversight of a single task matters more than speed.
12
+
13
+ **Distinct from `dispatch-agents`:** This skill runs one subagent sequentially with a mandatory review. `dispatch-agents` runs multiple subagents in parallel without inter-task review gates.
14
+
15
+ ## Process
16
+
17
+ ### 1. Define the task
18
+
19
+ Before spawning the agent, read `specs/state.yaml` if it exists. Then write a minimal self-contained brief using this template (brief size directly controls token cost and hallucination risk — do not pad):
20
+
21
+ ```
22
+ Goal: [one sentence — specific, measurable outcome]
23
+ In scope: [explicit file or module list]
24
+ Out of bounds: [what NOT to do]
25
+ Constraints: [relevant CONVENTIONS.md rules, existing patterns, test requirements]
26
+ Verify: [runnable command]
27
+ Prior decisions: [relevant entries from specs/state.yaml — omit section if none apply]
28
+ ```
29
+
30
+ Do not include full file contents, full conversation history, or decisions unrelated to this task.
31
+
32
+ ### 2. Spawn the subagent (iterative retrieval, max 3 cycles)
33
+
34
+ Use the Agent tool with a **fresh context** per spawn. Pass prior decisions only via `specs/state.yaml`.
35
+
36
+ **Cycle:** dispatch → evaluate output vs goal → refine brief → re-spawn if needed (max 3 cycles).
37
+
38
+ Include in each brief:
39
+ - All context the agent needs (it starts cold — no shared state)
40
+ - Reference to CONVENTIONS.md constraints
41
+ - The verify command it must run before reporting done
42
+
43
+ ### 3. Stage 1 review — output inspection
44
+
45
+ When the subagent returns, review its report before looking at the diff:
46
+ - Did it run the verify command? Did it pass?
47
+ - Does it explain what it changed and why?
48
+ - Are there any concerns raised by the agent?
49
+
50
+ If the report raises red flags, ask the subagent for clarification or re-run with adjusted instructions.
51
+
52
+ ### 4. Stage 2 review — diff inspection
53
+
54
+ Inspect the actual diff:
55
+ ```bash
56
+ git diff main...HEAD
57
+ ```
58
+
59
+ Check:
60
+ - [ ] Changes are scoped to what was asked — nothing extra
61
+ - [ ] No `any`, no `@ts-ignore`, no disabled lint rules
62
+ - [ ] Tests added for new behavior
63
+ - [ ] CONVENTIONS.md compliance (naming, structure, no gh issue creation)
64
+ - [ ] Boy Scout Rule: touched areas are cleaner than before
65
+
66
+ ### 5. Decision
67
+
68
+ - **Accept**: merge the result into the main working branch
69
+ - **Revise**: send back to the subagent with specific feedback
70
+ - **Reject**: discard and re-approach differently
71
+
72
+ **After accepting**, append to `specs/state.yaml` under `## Active Decisions`:
73
+ ```
74
+ **[task short name]**: [what approach the agent chose and why — one sentence]
75
+ ```
76
+
77
+ Report the decision and rationale to the user.
@@ -0,0 +1,97 @@
1
+ ---
2
+ name: design-interface
3
+ description: "Generate multiple radically different interface designs for a module using parallel sub-agents, then compare trade-offs. Based on "Design It Twice" from A Philosophy of Software Design. Use when user wants to design an API, explore interface options, compare module shapes, or mentions "design it twice"."
4
+ ---
5
+
6
+
7
+ # Design Interface
8
+
9
+ Based on "Design It Twice" from "A Philosophy of Software Design": your first idea is unlikely to be the best. Generate multiple radically different designs, then compare.
10
+
11
+ > **HARD GATE** — Multiple design options must be explored. Do NOT settle on first idea. Compare trade-offs (UX, complexity, extensibility, performance) before committing.
12
+
13
+ ## Workflow
14
+
15
+ ### 1. Gather Requirements
16
+
17
+ Before designing, understand:
18
+
19
+ - [ ] What problem does this module solve?
20
+ - [ ] Who are the callers? (other modules, external users, tests)
21
+ - [ ] What are the key operations?
22
+ - [ ] Any constraints? (performance, compatibility, existing patterns)
23
+ - [ ] What should be hidden inside vs exposed?
24
+
25
+ Ask: "What does this module need to do? Who will use it?"
26
+
27
+ ### 2. Generate Designs (Parallel Sub-Agents)
28
+
29
+ Spawn 3+ sub-agents simultaneously using Task tool. Each must produce a **radically different** approach.
30
+
31
+ ```
32
+ Prompt template for each sub-agent:
33
+
34
+ Design an interface for: [module description]
35
+
36
+ Requirements: [gathered requirements]
37
+
38
+ Constraints for this design: [assign a different constraint to each agent]
39
+ - Agent 1: "Minimize method count - aim for 1-3 methods max"
40
+ - Agent 2: "Maximize flexibility - support many use cases"
41
+ - Agent 3: "Optimize for the most common case"
42
+ - Agent 4: "Take inspiration from [specific paradigm/library]"
43
+
44
+ Output format:
45
+ 1. Interface signature (types/methods)
46
+ 2. Usage example (how caller uses it)
47
+ 3. What this design hides internally
48
+ 4. Trade-offs of this approach
49
+ ```
50
+
51
+ ### 3. Present Designs
52
+
53
+ Show each design with:
54
+
55
+ 1. **Interface signature** — types, methods, params
56
+ 2. **Usage examples** — how callers actually use it in practice
57
+ 3. **What it hides** — complexity kept internal
58
+
59
+ Present designs sequentially so user can absorb each approach before comparison.
60
+
61
+ ### 4. Compare Designs
62
+
63
+ After showing all designs, compare them on:
64
+
65
+ - **Interface simplicity**: fewer methods, simpler params
66
+ - **General-purpose vs specialized**: flexibility vs focus
67
+ - **Implementation efficiency**: does shape allow efficient internals?
68
+ - **Depth**: small interface hiding significant complexity (good) vs large interface with thin implementation (bad)
69
+ - **Ease of correct use** vs **ease of misuse**
70
+
71
+ Discuss trade-offs in prose, not tables. Highlight where designs diverge most.
72
+
73
+ ### 5. Synthesize
74
+
75
+ Often the best design combines insights from multiple options. Ask:
76
+
77
+ - "Which design best fits your primary use case?"
78
+ - "Any elements from other designs worth incorporating?"
79
+
80
+ ## Evaluation Criteria
81
+
82
+ From "A Philosophy of Software Design":
83
+
84
+ **Interface simplicity**: Fewer methods, simpler params = easier to learn and use correctly.
85
+
86
+ **General-purpose**: Can handle future use cases without changes. But beware over-generalization.
87
+
88
+ **Implementation efficiency**: Does interface shape allow efficient implementation? Or force awkward internals?
89
+
90
+ **Depth**: Small interface hiding significant complexity = deep module (good). Large interface with thin implementation = shallow module (avoid).
91
+
92
+ ## Anti-Patterns
93
+
94
+ - Don't let sub-agents produce similar designs — enforce radical difference
95
+ - Don't skip comparison — the value is in contrast
96
+ - Don't implement — this is purely about interface shape
97
+ - Don't evaluate based on implementation effort
@@ -0,0 +1,376 @@
1
+ ---
2
+ name: develop-tdd
3
+ description: "Test-driven development with red-green-refactor loop using vertical slices. Use for features (epic tasks) or bugs (specs/bugs/BUG-*.md)."
4
+ ---
5
+
6
+
7
+ # Develop TDD
8
+
9
+ > **HARD GATE** — Do NOT proceed if on `main` or `master`. Run `kickoff-branch` first to create a feature branch or worktree.
10
+ >
11
+ > **HARD GATE** — Do NOT write code before you have a plan. New feature: `plan-work` → epic capsule tasks. Bug: `investigate-bug` → `specs/bugs/BUG-*.md` (or use `fix-bug` orchestrator).
12
+ >
13
+ > **RECURSIVE DISCIPLINE** — This lifecycle applies to EVERY task, including updating these skills. Never skip planning because a task is "meta" or "just documentation."
14
+
15
+ ## Philosophy
16
+
17
+ Tests verify behavior through public interfaces, not implementation details. A good test reads like a specification. See [REFERENCE.md](REFERENCE.md) for the horizontal-slice anti-pattern and TDD phase detail.
18
+
19
+ ## Red Flags
20
+
21
+ If you catch yourself thinking these, stop and reconsider — you are likely deviating from production-grade craft.
22
+
23
+ | Red Flag | Reality |
24
+ | :--- | :--- |
25
+ | "This is too simple to need tests." | Simple code is where bugs hide. If it's simple, the test is cheap. |
26
+ | "I'll refactor this later." | "Later" is when technical debt becomes bankruptcy. Refactor while Green. |
27
+ | "The tests are already comprehensive." | If you're adding behavior, you need a new test. Coverage ≠ Correctness. |
28
+ | "I'm just fixing a small bug." | Small bugs often indicate deep interface flaws. Investigate root cause. |
29
+ | "I need to mock this internal class." | Mocking internals couples tests to implementation. Mock only I/O. |
30
+ | "This refactor is out of scope." | Leave the code cleaner than you found it (Boy Scout Rule). |
31
+
32
+ ## Workflow
33
+
34
+ ### 1. Planning
35
+
36
+ - [ ] Read active `specs/epics/*/epic.yaml` story tasks or `specs/bugs/BUG-*.md` — understand verify steps
37
+ - [ ] Confirm interface changes and behaviors to test (prioritize)
38
+ - [ ] Design interfaces for testability — identify [deep modules](deep-modules.md) opportunities
39
+ - [ ] Get user approval on the plan
40
+
41
+ Apply the **enforce-first** F.I.R.S.T rubric: Fast, Independent, Repeatable, Self-Validating, Timely.
42
+
43
+ ### 2. Tracer Bullet
44
+
45
+ Write ONE test that confirms ONE thing about the system:
46
+
47
+ ```
48
+ RED: Write test for first behavior → test fails → commit: test(<scope>): ...
49
+ GREEN: Write minimal code to pass → test passes → commit: feat(<scope>): ...
50
+ REFACTOR (optional): clean up → commit: refactor(<scope>): ...
51
+ ```
52
+
53
+ ### 3. Incremental Loop
54
+
55
+ > **STREAM CONTINUITY** — When writing file content, output in continuous chunks of ~200 lines. Do not pause. Emit a placeholder comment rather than going silent.
56
+
57
+ For each remaining behavior: RED → GREEN → REFACTOR (optional). One test at a time. Commit after every GREEN phase.
58
+
59
+ ### 4. Visual Slices (UI alternate workflow)
60
+
61
+ For UI components where behavioral unit testing is brittle: extract logic into a Controller/ViewModel/Hook (pure TDD), then use Visual Slices for the View layer. See [REFERENCE.md](REFERENCE.md) for the full Visual Slices procedure.
62
+
63
+ ### 5. Refactor
64
+
65
+ After all tests pass: extract duplication, deepen modules, apply SOLID principles. **Never refactor while RED.**
66
+
67
+ ### 6. Verify
68
+
69
+ After every behavior cycle, run the verify command from the active epic task. Show evidence before declaring the step done.
70
+
71
+ ### 7. Manual Verification Handover
72
+
73
+ Once all tests pass: locate the Verification Script in the active epic capsule, present it to the user step-by-step, and wait for confirmation of behavioral correctness.
74
+
75
+ ## Checklist Per Cycle
76
+
77
+ ```
78
+ [ ] Test describes behavior, not implementation
79
+ [ ] No test is ignored without an explicit ambiguity note (T4)
80
+ [ ] Boundary conditions tested: empty, max, min, off-by-one (T5)
81
+ [ ] Tests verify behavior through public interface only — no private methods (T8)
82
+ [ ] Test would survive internal refactor
83
+ [ ] Code is minimal for this test
84
+ [ ] No speculative features added
85
+ [ ] Every new abstraction has an explicit "Reason for Depth" justification
86
+ [ ] Progress committed (Conventional Commits)
87
+ [ ] verify: command passes
88
+ ```
89
+
90
+ ## Handoff
91
+
92
+ Gate: READY -> next: verify-work
93
+ Writes: state.yaml handoff.next_skill = verify-work
94
+
95
+ ---
96
+
97
+ # Develop TDD — Reference
98
+
99
+ ## Anti-Pattern: Horizontal Slices
100
+
101
+ **DO NOT write all tests first, then all implementation.** This is "horizontal slicing" — treating RED as "write all tests" and GREEN as "write all code."
102
+
103
+ This produces **crap tests**:
104
+ - Tests written in bulk test _imagined_ behavior, not _actual_ behavior
105
+ - You end up testing the _shape_ of things rather than user-facing behavior
106
+ - Tests become insensitive to real changes
107
+
108
+ **Correct approach**: Vertical slices via tracer bullets. One test → one implementation → repeat.
109
+
110
+ ```
111
+ WRONG (horizontal):
112
+ RED: test1, test2, test3, test4, test5
113
+ GREEN: impl1, impl2, impl3, impl4, impl5
114
+
115
+ RIGHT (vertical):
116
+ RED→GREEN: test1→impl1
117
+ RED→GREEN: test2→impl2
118
+ RED→GREEN: test3→impl3
119
+ ...
120
+ ```
121
+
122
+ > The Red Flags table lives in [SKILL.md](SKILL.md#red-flags) — it is core behavioral guidance, not reference detail.
123
+
124
+ ## TDD Phases (Detail)
125
+
126
+ ### Red Phase
127
+
128
+ Write a failing test first:
129
+ - Test describes the desired observable behavior through the public interface
130
+ - Run the test to confirm it fails for the right reason (not a syntax error, not a typo)
131
+ - Commit: `git commit -m "test(<scope>): <description>"`
132
+
133
+ ### Green Phase
134
+
135
+ Write the minimum code to make the test pass:
136
+ - No extra logic, no anticipated future cases, no premature optimization
137
+ - Focus only on making the current test pass
138
+ - Commit: `git commit -m "feat(<scope>): <description>"` or `"fix(<scope>): <description>"`
139
+
140
+ ### Refactor Phase
141
+
142
+ Improve structure without changing behavior:
143
+ - Extract duplication, apply SOLID principles where natural, deepen modules
144
+ - Run tests after each refactor step to ensure behavior is preserved
145
+ - Commit: `git commit -m "refactor(<scope>): <description>"`
146
+ - Apply the Boy Scout Rule: leave the code cleaner than you found it
147
+
148
+ ## Visual Slices (UI Alternate Workflow)
149
+
150
+ For UI components (SwiftUI, React, Flutter) where behavioral unit testing is brittle or low-signal:
151
+
152
+ 1. **Test-First Logic**: Extract logic (state transitions, formatting, validation) into a Controller, ViewModel, or Hook. This logic MUST follow pure TDD.
153
+ 2. **Visual Verification**: For the View/Component itself:
154
+ - **RED**: Write the component signature and a basic preview/snapshot that fails (or displays placeholder).
155
+ - **GREEN**: Implement the UI and verify visually via manual run, preview, or snapshot test.
156
+ - **REFINE**: Adjust styling and layout until it matches the design.
157
+ 3. **COMMIT**: `git commit -m "feat(ui): <component name> visual slice verified"`
158
+
159
+ ---
160
+
161
+ # Deep Modules
162
+
163
+ From "A Philosophy of Software Design":
164
+
165
+ **Deep module** = small interface + lots of implementation
166
+
167
+ ```
168
+ ┌─────────────────────┐
169
+ │ Small Interface │ ← Few methods, simple params
170
+ ├─────────────────────┤
171
+ │ │
172
+ │ │
173
+ │ Deep Implementation│ ← Complex logic hidden
174
+ │ │
175
+ │ │
176
+ └─────────────────────┘
177
+ ```
178
+
179
+ **Shallow module** = large interface + little implementation (avoid)
180
+
181
+ ```
182
+ ┌─────────────────────────────────┐
183
+ │ Large Interface │ ← Many methods, complex params
184
+ ├─────────────────────────────────┤
185
+ │ Thin Implementation │ ← Just passes through
186
+ └─────────────────────────────────┘
187
+ ```
188
+
189
+ When designing interfaces, ask:
190
+
191
+ - Can I reduce the number of methods?
192
+ - Can I simplify the parameters?
193
+ - Can I hide more complexity inside?
194
+
195
+ ---
196
+
197
+ # Interface Design for Testability
198
+
199
+ Good interfaces make testing natural:
200
+
201
+ 1. **Accept dependencies, don't create them**
202
+
203
+ ```typescript
204
+ // Testable
205
+ function processOrder(order, paymentGateway) {}
206
+
207
+ // Hard to test
208
+ function processOrder(order) {
209
+ const gateway = new StripeGateway();
210
+ }
211
+ ```
212
+
213
+ 2. **Return results, don't produce side effects**
214
+
215
+ ```typescript
216
+ // Testable
217
+ function calculateDiscount(cart): Discount {}
218
+
219
+ // Hard to test
220
+ function applyDiscount(cart): void {
221
+ cart.total -= discount;
222
+ }
223
+ ```
224
+
225
+ 3. **Small surface area**
226
+ - Fewer methods = fewer tests needed
227
+ - Fewer params = simpler test setup
228
+
229
+ ---
230
+
231
+ # When to Mock
232
+
233
+ Mock at **system boundaries** only:
234
+
235
+ - External APIs (payment, email, etc.)
236
+ - Databases (sometimes - prefer test DB)
237
+ - Time/randomness
238
+ - File system (sometimes)
239
+
240
+ Don't mock:
241
+
242
+ - Your own classes/modules
243
+ - Internal collaborators
244
+ - Anything you control
245
+
246
+ ## Designing for Mockability
247
+
248
+ At system boundaries, design interfaces that are easy to mock:
249
+
250
+ **1. Use dependency injection**
251
+
252
+ Pass external dependencies in rather than creating them internally:
253
+
254
+ ```typescript
255
+ // Easy to mock
256
+ function processPayment(order, paymentClient) {
257
+ return paymentClient.charge(order.total);
258
+ }
259
+
260
+ // Hard to mock
261
+ function processPayment(order) {
262
+ const client = new StripeClient(process.env.STRIPE_KEY);
263
+ return client.charge(order.total);
264
+ }
265
+ ```
266
+
267
+ **2. Prefer SDK-style interfaces over generic fetchers**
268
+
269
+ Create specific functions for each external operation instead of one generic function with conditional logic:
270
+
271
+ ```typescript
272
+ // GOOD: Each function is independently mockable
273
+ const api = {
274
+ getUser: (id) => fetch(`/users/${id}`),
275
+ getOrders: (userId) => fetch(`/users/${userId}/orders`),
276
+ createOrder: (data) => fetch('/orders', { method: 'POST', body: data }),
277
+ };
278
+
279
+ // BAD: Mocking requires conditional logic inside the mock
280
+ const api = {
281
+ fetch: (endpoint, options) => fetch(endpoint, options),
282
+ };
283
+ ```
284
+
285
+ The SDK approach means:
286
+ - Each mock returns one specific shape
287
+ - No conditional logic in test setup
288
+ - Easier to see which endpoints a test exercises
289
+ - Type safety per endpoint
290
+
291
+ ---
292
+
293
+ # Refactor Candidates
294
+
295
+ After TDD cycle, look for:
296
+
297
+ - **Duplication** → Extract function/class
298
+ - **Long methods** → Break into private helpers (keep tests on public interface)
299
+ - **Shallow modules** → Combine or deepen
300
+ - **Feature envy** → Move logic to where data lives
301
+ - **Primitive obsession** → Introduce value objects
302
+ - **Existing code** the new code reveals as problematic
303
+
304
+ ---
305
+
306
+ # Good and Bad Tests
307
+
308
+ ## Good Tests
309
+
310
+ **Integration-style**: Test through real interfaces, not mocks of internal parts.
311
+
312
+ ```typescript
313
+ // GOOD: Tests observable behavior
314
+ test("user can checkout with valid cart", async () => {
315
+ const cart = createCart();
316
+ cart.add(product);
317
+ const result = await checkout(cart, paymentMethod);
318
+ expect(result.status).toBe("confirmed");
319
+ });
320
+ ```
321
+
322
+ Characteristics:
323
+
324
+ - Tests behavior users/callers care about
325
+ - Uses public API only
326
+ - Survives internal refactors
327
+ - Describes WHAT, not HOW
328
+ - One logical assertion per test
329
+
330
+ ## Bad Tests
331
+
332
+ **Implementation-detail tests**: Coupled to internal structure.
333
+
334
+ ```typescript
335
+ // BAD: Tests implementation details
336
+ test("checkout calls paymentService.process", async () => {
337
+ const mockPayment = jest.mock(paymentService);
338
+ await checkout(cart, payment);
339
+ expect(mockPayment.process).toHaveBeenCalledWith(cart.total);
340
+ });
341
+ ```
342
+
343
+ Red flags:
344
+
345
+ - Mocking internal collaborators
346
+ - Testing private methods
347
+ - Asserting on call counts/order
348
+ - Test breaks when refactoring without behavior change
349
+ - Test name describes HOW not WHAT
350
+ - Verifying through external means instead of interface
351
+
352
+ ```typescript
353
+ // BAD: Bypasses interface to verify
354
+ test("createUser saves to database", async () => {
355
+ await createUser({ name: "Alice" });
356
+ const row = await db.query("SELECT * FROM users WHERE name = ?", ["Alice"]);
357
+ expect(row).toBeDefined();
358
+ });
359
+
360
+ // GOOD: Verifies through interface
361
+ test("createUser makes user retrievable", async () => {
362
+ const user = await createUser({ name: "Alice" });
363
+ const retrieved = await getUser(user.id);
364
+ expect(retrieved.name).toBe("Alice");
365
+ });
366
+ ```
367
+
368
+ ## Clean Test Heuristics (Uncle Bob, Ch 17)
369
+
370
+ Apply these specific heuristics to maintain a high-quality suite:
371
+
372
+ - **T1: Insufficient Tests**: A test suite should test everything that could possibly break. Don't stop at "it seems to work."
373
+ - **T4: Ignored Tests**: Never ignore a test without documenting the ambiguity. An ignored test is a silent warning of a gap in understanding.
374
+ - **T5: Test Boundary Conditions**: Most bugs happen at the edges. Test the exact boundaries (e.g., empty strings, max integers, off-by-one indices).
375
+ - **T6: Exhaustively Test Near Bugs**: Bugs congregate. If you find one, there are likely others nearby; test that area thoroughly.
376
+ - **T9: Tests Should Be Fast**: Slow tests don't get run. Keep them fast so they remain part of the core developer loop.