codingbuddy-rules 1.0.1 → 1.1.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.
@@ -0,0 +1,240 @@
1
+ ---
2
+ name: subagent-driven-development
3
+ description: Use when executing implementation plans with independent tasks in the current session
4
+ ---
5
+
6
+ # Subagent-Driven Development
7
+
8
+ Execute plan by dispatching fresh subagent per task, with two-stage review after each: spec compliance review first, then code quality review.
9
+
10
+ **Core principle:** Fresh subagent per task + two-stage review (spec then quality) = high quality, fast iteration
11
+
12
+ ## When to Use
13
+
14
+ ```dot
15
+ digraph when_to_use {
16
+ "Have implementation plan?" [shape=diamond];
17
+ "Tasks mostly independent?" [shape=diamond];
18
+ "Stay in this session?" [shape=diamond];
19
+ "subagent-driven-development" [shape=box];
20
+ "executing-plans" [shape=box];
21
+ "Manual execution or brainstorm first" [shape=box];
22
+
23
+ "Have implementation plan?" -> "Tasks mostly independent?" [label="yes"];
24
+ "Have implementation plan?" -> "Manual execution or brainstorm first" [label="no"];
25
+ "Tasks mostly independent?" -> "Stay in this session?" [label="yes"];
26
+ "Tasks mostly independent?" -> "Manual execution or brainstorm first" [label="no - tightly coupled"];
27
+ "Stay in this session?" -> "subagent-driven-development" [label="yes"];
28
+ "Stay in this session?" -> "executing-plans" [label="no - parallel session"];
29
+ }
30
+ ```
31
+
32
+ **vs. Executing Plans (parallel session):**
33
+ - Same session (no context switch)
34
+ - Fresh subagent per task (no context pollution)
35
+ - Two-stage review after each task: spec compliance first, then code quality
36
+ - Faster iteration (no human-in-loop between tasks)
37
+
38
+ ## The Process
39
+
40
+ ```dot
41
+ digraph process {
42
+ rankdir=TB;
43
+
44
+ subgraph cluster_per_task {
45
+ label="Per Task";
46
+ "Dispatch implementer subagent (./implementer-prompt.md)" [shape=box];
47
+ "Implementer subagent asks questions?" [shape=diamond];
48
+ "Answer questions, provide context" [shape=box];
49
+ "Implementer subagent implements, tests, commits, self-reviews" [shape=box];
50
+ "Dispatch spec reviewer subagent (./spec-reviewer-prompt.md)" [shape=box];
51
+ "Spec reviewer subagent confirms code matches spec?" [shape=diamond];
52
+ "Implementer subagent fixes spec gaps" [shape=box];
53
+ "Dispatch code quality reviewer subagent (./code-quality-reviewer-prompt.md)" [shape=box];
54
+ "Code quality reviewer subagent approves?" [shape=diamond];
55
+ "Implementer subagent fixes quality issues" [shape=box];
56
+ "Mark task complete in TodoWrite" [shape=box];
57
+ }
58
+
59
+ "Read plan, extract all tasks with full text, note context, create TodoWrite" [shape=box];
60
+ "More tasks remain?" [shape=diamond];
61
+ "Dispatch final code reviewer subagent for entire implementation" [shape=box];
62
+ "Use superpowers:finishing-a-development-branch" [shape=box style=filled fillcolor=lightgreen];
63
+
64
+ "Read plan, extract all tasks with full text, note context, create TodoWrite" -> "Dispatch implementer subagent (./implementer-prompt.md)";
65
+ "Dispatch implementer subagent (./implementer-prompt.md)" -> "Implementer subagent asks questions?";
66
+ "Implementer subagent asks questions?" -> "Answer questions, provide context" [label="yes"];
67
+ "Answer questions, provide context" -> "Dispatch implementer subagent (./implementer-prompt.md)";
68
+ "Implementer subagent asks questions?" -> "Implementer subagent implements, tests, commits, self-reviews" [label="no"];
69
+ "Implementer subagent implements, tests, commits, self-reviews" -> "Dispatch spec reviewer subagent (./spec-reviewer-prompt.md)";
70
+ "Dispatch spec reviewer subagent (./spec-reviewer-prompt.md)" -> "Spec reviewer subagent confirms code matches spec?";
71
+ "Spec reviewer subagent confirms code matches spec?" -> "Implementer subagent fixes spec gaps" [label="no"];
72
+ "Implementer subagent fixes spec gaps" -> "Dispatch spec reviewer subagent (./spec-reviewer-prompt.md)" [label="re-review"];
73
+ "Spec reviewer subagent confirms code matches spec?" -> "Dispatch code quality reviewer subagent (./code-quality-reviewer-prompt.md)" [label="yes"];
74
+ "Dispatch code quality reviewer subagent (./code-quality-reviewer-prompt.md)" -> "Code quality reviewer subagent approves?";
75
+ "Code quality reviewer subagent approves?" -> "Implementer subagent fixes quality issues" [label="no"];
76
+ "Implementer subagent fixes quality issues" -> "Dispatch code quality reviewer subagent (./code-quality-reviewer-prompt.md)" [label="re-review"];
77
+ "Code quality reviewer subagent approves?" -> "Mark task complete in TodoWrite" [label="yes"];
78
+ "Mark task complete in TodoWrite" -> "More tasks remain?";
79
+ "More tasks remain?" -> "Dispatch implementer subagent (./implementer-prompt.md)" [label="yes"];
80
+ "More tasks remain?" -> "Dispatch final code reviewer subagent for entire implementation" [label="no"];
81
+ "Dispatch final code reviewer subagent for entire implementation" -> "Use superpowers:finishing-a-development-branch";
82
+ }
83
+ ```
84
+
85
+ ## Prompt Templates
86
+
87
+ - `./implementer-prompt.md` - Dispatch implementer subagent
88
+ - `./spec-reviewer-prompt.md` - Dispatch spec compliance reviewer subagent
89
+ - `./code-quality-reviewer-prompt.md` - Dispatch code quality reviewer subagent
90
+
91
+ ## Example Workflow
92
+
93
+ ```
94
+ You: I'm using Subagent-Driven Development to execute this plan.
95
+
96
+ [Read plan file once: docs/plans/feature-plan.md]
97
+ [Extract all 5 tasks with full text and context]
98
+ [Create TodoWrite with all tasks]
99
+
100
+ Task 1: Hook installation script
101
+
102
+ [Get Task 1 text and context (already extracted)]
103
+ [Dispatch implementation subagent with full task text + context]
104
+
105
+ Implementer: "Before I begin - should the hook be installed at user or system level?"
106
+
107
+ You: "User level (~/.config/superpowers/hooks/)"
108
+
109
+ Implementer: "Got it. Implementing now..."
110
+ [Later] Implementer:
111
+ - Implemented install-hook command
112
+ - Added tests, 5/5 passing
113
+ - Self-review: Found I missed --force flag, added it
114
+ - Committed
115
+
116
+ [Dispatch spec compliance reviewer]
117
+ Spec reviewer: ✅ Spec compliant - all requirements met, nothing extra
118
+
119
+ [Get git SHAs, dispatch code quality reviewer]
120
+ Code reviewer: Strengths: Good test coverage, clean. Issues: None. Approved.
121
+
122
+ [Mark Task 1 complete]
123
+
124
+ Task 2: Recovery modes
125
+
126
+ [Get Task 2 text and context (already extracted)]
127
+ [Dispatch implementation subagent with full task text + context]
128
+
129
+ Implementer: [No questions, proceeds]
130
+ Implementer:
131
+ - Added verify/repair modes
132
+ - 8/8 tests passing
133
+ - Self-review: All good
134
+ - Committed
135
+
136
+ [Dispatch spec compliance reviewer]
137
+ Spec reviewer: ❌ Issues:
138
+ - Missing: Progress reporting (spec says "report every 100 items")
139
+ - Extra: Added --json flag (not requested)
140
+
141
+ [Implementer fixes issues]
142
+ Implementer: Removed --json flag, added progress reporting
143
+
144
+ [Spec reviewer reviews again]
145
+ Spec reviewer: ✅ Spec compliant now
146
+
147
+ [Dispatch code quality reviewer]
148
+ Code reviewer: Strengths: Solid. Issues (Important): Magic number (100)
149
+
150
+ [Implementer fixes]
151
+ Implementer: Extracted PROGRESS_INTERVAL constant
152
+
153
+ [Code reviewer reviews again]
154
+ Code reviewer: ✅ Approved
155
+
156
+ [Mark Task 2 complete]
157
+
158
+ ...
159
+
160
+ [After all tasks]
161
+ [Dispatch final code-reviewer]
162
+ Final reviewer: All requirements met, ready to merge
163
+
164
+ Done!
165
+ ```
166
+
167
+ ## Advantages
168
+
169
+ **vs. Manual execution:**
170
+ - Subagents follow TDD naturally
171
+ - Fresh context per task (no confusion)
172
+ - Parallel-safe (subagents don't interfere)
173
+ - Subagent can ask questions (before AND during work)
174
+
175
+ **vs. Executing Plans:**
176
+ - Same session (no handoff)
177
+ - Continuous progress (no waiting)
178
+ - Review checkpoints automatic
179
+
180
+ **Efficiency gains:**
181
+ - No file reading overhead (controller provides full text)
182
+ - Controller curates exactly what context is needed
183
+ - Subagent gets complete information upfront
184
+ - Questions surfaced before work begins (not after)
185
+
186
+ **Quality gates:**
187
+ - Self-review catches issues before handoff
188
+ - Two-stage review: spec compliance, then code quality
189
+ - Review loops ensure fixes actually work
190
+ - Spec compliance prevents over/under-building
191
+ - Code quality ensures implementation is well-built
192
+
193
+ **Cost:**
194
+ - More subagent invocations (implementer + 2 reviewers per task)
195
+ - Controller does more prep work (extracting all tasks upfront)
196
+ - Review loops add iterations
197
+ - But catches issues early (cheaper than debugging later)
198
+
199
+ ## Red Flags
200
+
201
+ **Never:**
202
+ - Skip reviews (spec compliance OR code quality)
203
+ - Proceed with unfixed issues
204
+ - Dispatch multiple implementation subagents in parallel (conflicts)
205
+ - Make subagent read plan file (provide full text instead)
206
+ - Skip scene-setting context (subagent needs to understand where task fits)
207
+ - Ignore subagent questions (answer before letting them proceed)
208
+ - Accept "close enough" on spec compliance (spec reviewer found issues = not done)
209
+ - Skip review loops (reviewer found issues = implementer fixes = review again)
210
+ - Let implementer self-review replace actual review (both are needed)
211
+ - **Start code quality review before spec compliance is ✅** (wrong order)
212
+ - Move to next task while either review has open issues
213
+
214
+ **If subagent asks questions:**
215
+ - Answer clearly and completely
216
+ - Provide additional context if needed
217
+ - Don't rush them into implementation
218
+
219
+ **If reviewer finds issues:**
220
+ - Implementer (same subagent) fixes them
221
+ - Reviewer reviews again
222
+ - Repeat until approved
223
+ - Don't skip the re-review
224
+
225
+ **If subagent fails task:**
226
+ - Dispatch fix subagent with specific instructions
227
+ - Don't try to fix manually (context pollution)
228
+
229
+ ## Integration
230
+
231
+ **Required workflow skills:**
232
+ - **superpowers:writing-plans** - Creates the plan this skill executes
233
+ - **superpowers:requesting-code-review** - Code review template for reviewer subagents
234
+ - **superpowers:finishing-a-development-branch** - Complete development after all tasks
235
+
236
+ **Subagents should use:**
237
+ - **superpowers:test-driven-development** - Subagents follow TDD for each task
238
+
239
+ **Alternative workflow:**
240
+ - **superpowers:executing-plans** - Use for parallel session instead of same-session execution
@@ -0,0 +1,296 @@
1
+ ---
2
+ name: systematic-debugging
3
+ description: Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
4
+ ---
5
+
6
+ # Systematic Debugging
7
+
8
+ ## Overview
9
+
10
+ Random fixes waste time and create new bugs. Quick patches mask underlying issues.
11
+
12
+ **Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
13
+
14
+ **Violating the letter of this process is violating the spirit of debugging.**
15
+
16
+ ## The Iron Law
17
+
18
+ ```
19
+ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
20
+ ```
21
+
22
+ If you haven't completed Phase 1, you cannot propose fixes.
23
+
24
+ ## When to Use
25
+
26
+ Use for ANY technical issue:
27
+ - Test failures
28
+ - Bugs in production
29
+ - Unexpected behavior
30
+ - Performance problems
31
+ - Build failures
32
+ - Integration issues
33
+
34
+ **Use this ESPECIALLY when:**
35
+ - Under time pressure (emergencies make guessing tempting)
36
+ - "Just one quick fix" seems obvious
37
+ - You've already tried multiple fixes
38
+ - Previous fix didn't work
39
+ - You don't fully understand the issue
40
+
41
+ **Don't skip when:**
42
+ - Issue seems simple (simple bugs have root causes too)
43
+ - You're in a hurry (rushing guarantees rework)
44
+ - Manager wants it fixed NOW (systematic is faster than thrashing)
45
+
46
+ ## The Four Phases
47
+
48
+ You MUST complete each phase before proceeding to the next.
49
+
50
+ ### Phase 1: Root Cause Investigation
51
+
52
+ **BEFORE attempting ANY fix:**
53
+
54
+ 1. **Read Error Messages Carefully**
55
+ - Don't skip past errors or warnings
56
+ - They often contain the exact solution
57
+ - Read stack traces completely
58
+ - Note line numbers, file paths, error codes
59
+
60
+ 2. **Reproduce Consistently**
61
+ - Can you trigger it reliably?
62
+ - What are the exact steps?
63
+ - Does it happen every time?
64
+ - If not reproducible → gather more data, don't guess
65
+
66
+ 3. **Check Recent Changes**
67
+ - What changed that could cause this?
68
+ - Git diff, recent commits
69
+ - New dependencies, config changes
70
+ - Environmental differences
71
+
72
+ 4. **Gather Evidence in Multi-Component Systems**
73
+
74
+ **WHEN system has multiple components (CI → build → signing, API → service → database):**
75
+
76
+ **BEFORE proposing fixes, add diagnostic instrumentation:**
77
+ ```
78
+ For EACH component boundary:
79
+ - Log what data enters component
80
+ - Log what data exits component
81
+ - Verify environment/config propagation
82
+ - Check state at each layer
83
+
84
+ Run once to gather evidence showing WHERE it breaks
85
+ THEN analyze evidence to identify failing component
86
+ THEN investigate that specific component
87
+ ```
88
+
89
+ **Example (multi-layer system):**
90
+ ```bash
91
+ # Layer 1: Workflow
92
+ echo "=== Secrets available in workflow: ==="
93
+ echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
94
+
95
+ # Layer 2: Build script
96
+ echo "=== Env vars in build script: ==="
97
+ env | grep IDENTITY || echo "IDENTITY not in environment"
98
+
99
+ # Layer 3: Signing script
100
+ echo "=== Keychain state: ==="
101
+ security list-keychains
102
+ security find-identity -v
103
+
104
+ # Layer 4: Actual signing
105
+ codesign --sign "$IDENTITY" --verbose=4 "$APP"
106
+ ```
107
+
108
+ **This reveals:** Which layer fails (secrets → workflow ✓, workflow → build ✗)
109
+
110
+ 5. **Trace Data Flow**
111
+
112
+ **WHEN error is deep in call stack:**
113
+
114
+ See `root-cause-tracing.md` in this directory for the complete backward tracing technique.
115
+
116
+ **Quick version:**
117
+ - Where does bad value originate?
118
+ - What called this with bad value?
119
+ - Keep tracing up until you find the source
120
+ - Fix at source, not at symptom
121
+
122
+ ### Phase 2: Pattern Analysis
123
+
124
+ **Find the pattern before fixing:**
125
+
126
+ 1. **Find Working Examples**
127
+ - Locate similar working code in same codebase
128
+ - What works that's similar to what's broken?
129
+
130
+ 2. **Compare Against References**
131
+ - If implementing pattern, read reference implementation COMPLETELY
132
+ - Don't skim - read every line
133
+ - Understand the pattern fully before applying
134
+
135
+ 3. **Identify Differences**
136
+ - What's different between working and broken?
137
+ - List every difference, however small
138
+ - Don't assume "that can't matter"
139
+
140
+ 4. **Understand Dependencies**
141
+ - What other components does this need?
142
+ - What settings, config, environment?
143
+ - What assumptions does it make?
144
+
145
+ ### Phase 3: Hypothesis and Testing
146
+
147
+ **Scientific method:**
148
+
149
+ 1. **Form Single Hypothesis**
150
+ - State clearly: "I think X is the root cause because Y"
151
+ - Write it down
152
+ - Be specific, not vague
153
+
154
+ 2. **Test Minimally**
155
+ - Make the SMALLEST possible change to test hypothesis
156
+ - One variable at a time
157
+ - Don't fix multiple things at once
158
+
159
+ 3. **Verify Before Continuing**
160
+ - Did it work? Yes → Phase 4
161
+ - Didn't work? Form NEW hypothesis
162
+ - DON'T add more fixes on top
163
+
164
+ 4. **When You Don't Know**
165
+ - Say "I don't understand X"
166
+ - Don't pretend to know
167
+ - Ask for help
168
+ - Research more
169
+
170
+ ### Phase 4: Implementation
171
+
172
+ **Fix the root cause, not the symptom:**
173
+
174
+ 1. **Create Failing Test Case**
175
+ - Simplest possible reproduction
176
+ - Automated test if possible
177
+ - One-off test script if no framework
178
+ - MUST have before fixing
179
+ - Use the `superpowers:test-driven-development` skill for writing proper failing tests
180
+
181
+ 2. **Implement Single Fix**
182
+ - Address the root cause identified
183
+ - ONE change at a time
184
+ - No "while I'm here" improvements
185
+ - No bundled refactoring
186
+
187
+ 3. **Verify Fix**
188
+ - Test passes now?
189
+ - No other tests broken?
190
+ - Issue actually resolved?
191
+
192
+ 4. **If Fix Doesn't Work**
193
+ - STOP
194
+ - Count: How many fixes have you tried?
195
+ - If < 3: Return to Phase 1, re-analyze with new information
196
+ - **If ≥ 3: STOP and question the architecture (step 5 below)**
197
+ - DON'T attempt Fix #4 without architectural discussion
198
+
199
+ 5. **If 3+ Fixes Failed: Question Architecture**
200
+
201
+ **Pattern indicating architectural problem:**
202
+ - Each fix reveals new shared state/coupling/problem in different place
203
+ - Fixes require "massive refactoring" to implement
204
+ - Each fix creates new symptoms elsewhere
205
+
206
+ **STOP and question fundamentals:**
207
+ - Is this pattern fundamentally sound?
208
+ - Are we "sticking with it through sheer inertia"?
209
+ - Should we refactor architecture vs. continue fixing symptoms?
210
+
211
+ **Discuss with your human partner before attempting more fixes**
212
+
213
+ This is NOT a failed hypothesis - this is a wrong architecture.
214
+
215
+ ## Red Flags - STOP and Follow Process
216
+
217
+ If you catch yourself thinking:
218
+ - "Quick fix for now, investigate later"
219
+ - "Just try changing X and see if it works"
220
+ - "Add multiple changes, run tests"
221
+ - "Skip the test, I'll manually verify"
222
+ - "It's probably X, let me fix that"
223
+ - "I don't fully understand but this might work"
224
+ - "Pattern says X but I'll adapt it differently"
225
+ - "Here are the main problems: [lists fixes without investigation]"
226
+ - Proposing solutions before tracing data flow
227
+ - **"One more fix attempt" (when already tried 2+)**
228
+ - **Each fix reveals new problem in different place**
229
+
230
+ **ALL of these mean: STOP. Return to Phase 1.**
231
+
232
+ **If 3+ fixes failed:** Question the architecture (see Phase 4.5)
233
+
234
+ ## your human partner's Signals You're Doing It Wrong
235
+
236
+ **Watch for these redirections:**
237
+ - "Is that not happening?" - You assumed without verifying
238
+ - "Will it show us...?" - You should have added evidence gathering
239
+ - "Stop guessing" - You're proposing fixes without understanding
240
+ - "Ultrathink this" - Question fundamentals, not just symptoms
241
+ - "We're stuck?" (frustrated) - Your approach isn't working
242
+
243
+ **When you see these:** STOP. Return to Phase 1.
244
+
245
+ ## Common Rationalizations
246
+
247
+ | Excuse | Reality |
248
+ |--------|---------|
249
+ | "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |
250
+ | "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |
251
+ | "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |
252
+ | "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |
253
+ | "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |
254
+ | "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. |
255
+ | "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. |
256
+ | "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |
257
+
258
+ ## Quick Reference
259
+
260
+ | Phase | Key Activities | Success Criteria |
261
+ |-------|---------------|------------------|
262
+ | **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |
263
+ | **2. Pattern** | Find working examples, compare | Identify differences |
264
+ | **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |
265
+ | **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |
266
+
267
+ ## When Process Reveals "No Root Cause"
268
+
269
+ If systematic investigation reveals issue is truly environmental, timing-dependent, or external:
270
+
271
+ 1. You've completed the process
272
+ 2. Document what you investigated
273
+ 3. Implement appropriate handling (retry, timeout, error message)
274
+ 4. Add monitoring/logging for future investigation
275
+
276
+ **But:** 95% of "no root cause" cases are incomplete investigation.
277
+
278
+ ## Supporting Techniques
279
+
280
+ These techniques are part of systematic debugging and available in this directory:
281
+
282
+ - **`root-cause-tracing.md`** - Trace bugs backward through call stack to find original trigger
283
+ - **`defense-in-depth.md`** - Add validation at multiple layers after finding root cause
284
+ - **`condition-based-waiting.md`** - Replace arbitrary timeouts with condition polling
285
+
286
+ **Related skills:**
287
+ - **superpowers:test-driven-development** - For creating failing test case (Phase 4, Step 1)
288
+ - **superpowers:verification-before-completion** - Verify fix worked before claiming success
289
+
290
+ ## Real-World Impact
291
+
292
+ From debugging sessions:
293
+ - Systematic approach: 15-30 minutes to fix
294
+ - Random fixes approach: 2-3 hours of thrashing
295
+ - First-time fix rate: 95% vs 40%
296
+ - New bugs introduced: Near zero vs common