buildwithjpegg 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 (64) hide show
  1. package/.claude-plugin/marketplace.json +18 -0
  2. package/.claude-plugin/plugin.json +12 -0
  3. package/.codex/INSTALL.md +67 -0
  4. package/.opencode/INSTALL.md +118 -0
  5. package/.opencode/plugins/buildwithjpegg.js +95 -0
  6. package/LICENSE +24 -0
  7. package/README.md +134 -0
  8. package/RELEASE-NOTES.md +7 -0
  9. package/agents/code-reviewer.md +48 -0
  10. package/commands/evaluate.md +6 -0
  11. package/commands/run-build.md +6 -0
  12. package/commands/write-blueprint.md +6 -0
  13. package/hooks/hooks.json +16 -0
  14. package/hooks/run-hook.cmd +43 -0
  15. package/hooks/session-start.sh +46 -0
  16. package/lib/skills-core.js +208 -0
  17. package/package.json +39 -0
  18. package/rules/conventions.md +22 -0
  19. package/rules/git.md +18 -0
  20. package/rules/mcp-servers.md +28 -0
  21. package/rules/platform.md +10 -0
  22. package/rules/stack.md +29 -0
  23. package/rules/testing.md +18 -0
  24. package/rules/ui-ux.md +151 -0
  25. package/rules/workflow.md +48 -0
  26. package/skills/auto-release/SKILL.md +176 -0
  27. package/skills/blueprint/SKILL.md +116 -0
  28. package/skills/build/SKILL.md +84 -0
  29. package/skills/ci-loop/SKILL.md +98 -0
  30. package/skills/craft-skill/SKILL.md +655 -0
  31. package/skills/craft-skill/anthropic-best-practices.md +1150 -0
  32. package/skills/craft-skill/examples/CLAUDE_MD_TESTING.md +189 -0
  33. package/skills/craft-skill/graphviz-conventions.dot +172 -0
  34. package/skills/craft-skill/persuasion-principles.md +187 -0
  35. package/skills/craft-skill/render-graphs.js +168 -0
  36. package/skills/craft-skill/testing-skills-with-subagents.md +384 -0
  37. package/skills/delegate/SKILL.md +242 -0
  38. package/skills/delegate/code-quality-reviewer-prompt.md +20 -0
  39. package/skills/delegate/implementer-prompt.md +78 -0
  40. package/skills/delegate/spec-reviewer-prompt.md +61 -0
  41. package/skills/draft-prs/SKILL.md +132 -0
  42. package/skills/evaluate/SKILL.md +96 -0
  43. package/skills/fan-out/SKILL.md +180 -0
  44. package/skills/handle-review/SKILL.md +213 -0
  45. package/skills/onboard/SKILL.md +95 -0
  46. package/skills/pr-stack/SKILL.md +112 -0
  47. package/skills/pre-ship/SKILL.md +139 -0
  48. package/skills/root-cause/CREATION-LOG.md +119 -0
  49. package/skills/root-cause/SKILL.md +296 -0
  50. package/skills/root-cause/condition-based-waiting-example.ts +158 -0
  51. package/skills/root-cause/condition-based-waiting.md +115 -0
  52. package/skills/root-cause/defense-in-depth.md +122 -0
  53. package/skills/root-cause/find-polluter.sh +63 -0
  54. package/skills/root-cause/root-cause-tracing.md +169 -0
  55. package/skills/root-cause/test-academic.md +14 -0
  56. package/skills/root-cause/test-pressure-1.md +58 -0
  57. package/skills/root-cause/test-pressure-2.md +68 -0
  58. package/skills/root-cause/test-pressure-3.md +69 -0
  59. package/skills/seek-review/SKILL.md +105 -0
  60. package/skills/seek-review/code-reviewer.md +146 -0
  61. package/skills/test-first/SKILL.md +371 -0
  62. package/skills/test-first/testing-anti-patterns.md +299 -0
  63. package/skills/worktree/SKILL.md +218 -0
  64. package/skills/wrap-up/SKILL.md +200 -0
@@ -0,0 +1,180 @@
1
+ ---
2
+ name: fan-out
3
+ description: Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies
4
+ ---
5
+
6
+ # Dispatching Parallel Agents
7
+
8
+ ## Overview
9
+
10
+ When you have multiple unrelated failures (different test files, different subsystems, different bugs), investigating them sequentially wastes time. Each investigation is independent and can happen in parallel.
11
+
12
+ **Core principle:** Dispatch one agent per independent problem domain. Let them work concurrently.
13
+
14
+ ## When to Use
15
+
16
+ ```dot
17
+ digraph when_to_use {
18
+ "Multiple failures?" [shape=diamond];
19
+ "Are they independent?" [shape=diamond];
20
+ "Single agent investigates all" [shape=box];
21
+ "One agent per problem domain" [shape=box];
22
+ "Can they work in parallel?" [shape=diamond];
23
+ "Sequential agents" [shape=box];
24
+ "Parallel dispatch" [shape=box];
25
+
26
+ "Multiple failures?" -> "Are they independent?" [label="yes"];
27
+ "Are they independent?" -> "Single agent investigates all" [label="no - related"];
28
+ "Are they independent?" -> "Can they work in parallel?" [label="yes"];
29
+ "Can they work in parallel?" -> "Parallel dispatch" [label="yes"];
30
+ "Can they work in parallel?" -> "Sequential agents" [label="no - shared state"];
31
+ }
32
+ ```
33
+
34
+ **Use when:**
35
+ - 3+ test files failing with different root causes
36
+ - Multiple subsystems broken independently
37
+ - Each problem can be understood without context from others
38
+ - No shared state between investigations
39
+
40
+ **Don't use when:**
41
+ - Failures are related (fix one might fix others)
42
+ - Need to understand full system state
43
+ - Agents would interfere with each other
44
+
45
+ ## The Pattern
46
+
47
+ ### 1. Identify Independent Domains
48
+
49
+ Group failures by what's broken:
50
+ - File A tests: Tool approval flow
51
+ - File B tests: Batch completion behavior
52
+ - File C tests: Abort functionality
53
+
54
+ Each domain is independent - fixing tool approval doesn't affect abort tests.
55
+
56
+ ### 2. Create Focused Agent Tasks
57
+
58
+ Each agent gets:
59
+ - **Specific scope:** One test file or subsystem
60
+ - **Clear goal:** Make these tests pass
61
+ - **Constraints:** Don't change other code
62
+ - **Expected output:** Summary of what you found and fixed
63
+
64
+ ### 3. Dispatch in Parallel
65
+
66
+ ```typescript
67
+ // In Claude Code / AI environment
68
+ Task("Fix agent-tool-abort.test.ts failures")
69
+ Task("Fix batch-completion-behavior.test.ts failures")
70
+ Task("Fix tool-approval-race-conditions.test.ts failures")
71
+ // All three run concurrently
72
+ ```
73
+
74
+ ### 4. Review and Integrate
75
+
76
+ When agents return:
77
+ - Read each summary
78
+ - Verify fixes don't conflict
79
+ - Run full test suite
80
+ - Integrate all changes
81
+
82
+ ## Agent Prompt Structure
83
+
84
+ Good agent prompts are:
85
+ 1. **Focused** - One clear problem domain
86
+ 2. **Self-contained** - All context needed to understand the problem
87
+ 3. **Specific about output** - What should the agent return?
88
+
89
+ ```markdown
90
+ Fix the 3 failing tests in src/agents/agent-tool-abort.test.ts:
91
+
92
+ 1. "should abort tool with partial output capture" - expects 'interrupted at' in message
93
+ 2. "should handle mixed completed and aborted tools" - fast tool aborted instead of completed
94
+ 3. "should properly track pendingToolCount" - expects 3 results but gets 0
95
+
96
+ These are timing/race condition issues. Your task:
97
+
98
+ 1. Read the test file and understand what each test verifies
99
+ 2. Identify root cause - timing issues or actual bugs?
100
+ 3. Fix by:
101
+ - Replacing arbitrary timeouts with event-based waiting
102
+ - Fixing bugs in abort implementation if found
103
+ - Adjusting test expectations if testing changed behavior
104
+
105
+ Do NOT just increase timeouts - find the real issue.
106
+
107
+ Return: Summary of what you found and what you fixed.
108
+ ```
109
+
110
+ ## Common Mistakes
111
+
112
+ **❌ Too broad:** "Fix all the tests" - agent gets lost
113
+ **✅ Specific:** "Fix agent-tool-abort.test.ts" - focused scope
114
+
115
+ **❌ No context:** "Fix the race condition" - agent doesn't know where
116
+ **✅ Context:** Paste the error messages and test names
117
+
118
+ **❌ No constraints:** Agent might refactor everything
119
+ **✅ Constraints:** "Do NOT change production code" or "Fix tests only"
120
+
121
+ **❌ Vague output:** "Fix it" - you don't know what changed
122
+ **✅ Specific:** "Return summary of root cause and changes"
123
+
124
+ ## When NOT to Use
125
+
126
+ **Related failures:** Fixing one might fix others - investigate together first
127
+ **Need full context:** Understanding requires seeing entire system
128
+ **Exploratory debugging:** You don't know what's broken yet
129
+ **Shared state:** Agents would interfere (editing same files, using same resources)
130
+
131
+ ## Real Example from Session
132
+
133
+ **Scenario:** 6 test failures across 3 files after major refactoring
134
+
135
+ **Failures:**
136
+ - agent-tool-abort.test.ts: 3 failures (timing issues)
137
+ - batch-completion-behavior.test.ts: 2 failures (tools not executing)
138
+ - tool-approval-race-conditions.test.ts: 1 failure (execution count = 0)
139
+
140
+ **Decision:** Independent domains - abort logic separate from batch completion separate from race conditions
141
+
142
+ **Dispatch:**
143
+ ```
144
+ Agent 1 → Fix agent-tool-abort.test.ts
145
+ Agent 2 → Fix batch-completion-behavior.test.ts
146
+ Agent 3 → Fix tool-approval-race-conditions.test.ts
147
+ ```
148
+
149
+ **Results:**
150
+ - Agent 1: Replaced timeouts with event-based waiting
151
+ - Agent 2: Fixed event structure bug (threadId in wrong place)
152
+ - Agent 3: Added wait for async tool execution to complete
153
+
154
+ **Integration:** All fixes independent, no conflicts, full suite green
155
+
156
+ **Time saved:** 3 problems solved in parallel vs sequentially
157
+
158
+ ## Key Benefits
159
+
160
+ 1. **Parallelization** - Multiple investigations happen simultaneously
161
+ 2. **Focus** - Each agent has narrow scope, less context to track
162
+ 3. **Independence** - Agents don't interfere with each other
163
+ 4. **Speed** - 3 problems solved in time of 1
164
+
165
+ ## Verification
166
+
167
+ After agents return:
168
+ 1. **Review each summary** - Understand what changed
169
+ 2. **Check for conflicts** - Did agents edit same code?
170
+ 3. **Run full suite** - Verify all fixes work together
171
+ 4. **Spot check** - Agents can make systematic errors
172
+
173
+ ## Real-World Impact
174
+
175
+ From debugging session (2025-10-03):
176
+ - 6 failures across 3 files
177
+ - 3 agents dispatched in parallel
178
+ - All investigations completed concurrently
179
+ - All fixes integrated successfully
180
+ - Zero conflicts between agent changes
@@ -0,0 +1,213 @@
1
+ ---
2
+ name: handle-review
3
+ description: Use when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation
4
+ ---
5
+
6
+ # Code Review Reception
7
+
8
+ ## Overview
9
+
10
+ Code review requires technical evaluation, not emotional performance.
11
+
12
+ **Core principle:** Verify before implementing. Ask before assuming. Technical correctness over social comfort.
13
+
14
+ ## The Response Pattern
15
+
16
+ ```
17
+ WHEN receiving code review feedback:
18
+
19
+ 1. READ: Complete feedback without reacting
20
+ 2. UNDERSTAND: Restate requirement in own words (or ask)
21
+ 3. VERIFY: Check against codebase reality
22
+ 4. EVALUATE: Technically sound for THIS codebase?
23
+ 5. RESPOND: Technical acknowledgment or reasoned pushback
24
+ 6. IMPLEMENT: One item at a time, test each
25
+ ```
26
+
27
+ ## Forbidden Responses
28
+
29
+ **NEVER:**
30
+ - "You're absolutely right!" (explicit CLAUDE.md violation)
31
+ - "Great point!" / "Excellent feedback!" (performative)
32
+ - "Let me implement that now" (before verification)
33
+
34
+ **INSTEAD:**
35
+ - Restate the technical requirement
36
+ - Ask clarifying questions
37
+ - Push back with technical reasoning if wrong
38
+ - Just start working (actions > words)
39
+
40
+ ## Handling Unclear Feedback
41
+
42
+ ```
43
+ IF any item is unclear:
44
+ STOP - do not implement anything yet
45
+ ASK for clarification on unclear items
46
+
47
+ WHY: Items may be related. Partial understanding = wrong implementation.
48
+ ```
49
+
50
+ **Example:**
51
+ ```
52
+ your human partner: "Fix 1-6"
53
+ You understand 1,2,3,6. Unclear on 4,5.
54
+
55
+ ❌ WRONG: Implement 1,2,3,6 now, ask about 4,5 later
56
+ ✅ RIGHT: "I understand items 1,2,3,6. Need clarification on 4 and 5 before proceeding."
57
+ ```
58
+
59
+ ## Source-Specific Handling
60
+
61
+ ### From your human partner
62
+ - **Trusted** - implement after understanding
63
+ - **Still ask** if scope unclear
64
+ - **No performative agreement**
65
+ - **Skip to action** or technical acknowledgment
66
+
67
+ ### From External Reviewers
68
+ ```
69
+ BEFORE implementing:
70
+ 1. Check: Technically correct for THIS codebase?
71
+ 2. Check: Breaks existing functionality?
72
+ 3. Check: Reason for current implementation?
73
+ 4. Check: Works on all platforms/versions?
74
+ 5. Check: Does reviewer understand full context?
75
+
76
+ IF suggestion seems wrong:
77
+ Push back with technical reasoning
78
+
79
+ IF can't easily verify:
80
+ Say so: "I can't verify this without [X]. Should I [investigate/ask/proceed]?"
81
+
82
+ IF conflicts with your human partner's prior decisions:
83
+ Stop and discuss with your human partner first
84
+ ```
85
+
86
+ **your human partner's rule:** "External feedback - be skeptical, but check carefully"
87
+
88
+ ## YAGNI Check for "Professional" Features
89
+
90
+ ```
91
+ IF reviewer suggests "implementing properly":
92
+ grep codebase for actual usage
93
+
94
+ IF unused: "This endpoint isn't called. Remove it (YAGNI)?"
95
+ IF used: Then implement properly
96
+ ```
97
+
98
+ **your human partner's rule:** "You and reviewer both report to me. If we don't need this feature, don't add it."
99
+
100
+ ## Implementation Order
101
+
102
+ ```
103
+ FOR multi-item feedback:
104
+ 1. Clarify anything unclear FIRST
105
+ 2. Then implement in this order:
106
+ - Blocking issues (breaks, security)
107
+ - Simple fixes (typos, imports)
108
+ - Complex fixes (refactoring, logic)
109
+ 3. Test each fix individually
110
+ 4. Verify no regressions
111
+ ```
112
+
113
+ ## When To Push Back
114
+
115
+ Push back when:
116
+ - Suggestion breaks existing functionality
117
+ - Reviewer lacks full context
118
+ - Violates YAGNI (unused feature)
119
+ - Technically incorrect for this stack
120
+ - Legacy/compatibility reasons exist
121
+ - Conflicts with your human partner's architectural decisions
122
+
123
+ **How to push back:**
124
+ - Use technical reasoning, not defensiveness
125
+ - Ask specific questions
126
+ - Reference working tests/code
127
+ - Involve your human partner if architectural
128
+
129
+ **Signal if uncomfortable pushing back out loud:** "Strange things are afoot at the Circle K"
130
+
131
+ ## Acknowledging Correct Feedback
132
+
133
+ When feedback IS correct:
134
+ ```
135
+ ✅ "Fixed. [Brief description of what changed]"
136
+ ✅ "Good catch - [specific issue]. Fixed in [location]."
137
+ ✅ [Just fix it and show in the code]
138
+
139
+ ❌ "You're absolutely right!"
140
+ ❌ "Great point!"
141
+ ❌ "Thanks for catching that!"
142
+ ❌ "Thanks for [anything]"
143
+ ❌ ANY gratitude expression
144
+ ```
145
+
146
+ **Why no thanks:** Actions speak. Just fix it. The code itself shows you heard the feedback.
147
+
148
+ **If you catch yourself about to write "Thanks":** DELETE IT. State the fix instead.
149
+
150
+ ## Gracefully Correcting Your Pushback
151
+
152
+ If you pushed back and were wrong:
153
+ ```
154
+ ✅ "You were right - I checked [X] and it does [Y]. Implementing now."
155
+ ✅ "Verified this and you're correct. My initial understanding was wrong because [reason]. Fixing."
156
+
157
+ ❌ Long apology
158
+ ❌ Defending why you pushed back
159
+ ❌ Over-explaining
160
+ ```
161
+
162
+ State the correction factually and move on.
163
+
164
+ ## Common Mistakes
165
+
166
+ | Mistake | Fix |
167
+ |---------|-----|
168
+ | Performative agreement | State requirement or just act |
169
+ | Blind implementation | Verify against codebase first |
170
+ | Batch without testing | One at a time, test each |
171
+ | Assuming reviewer is right | Check if breaks things |
172
+ | Avoiding pushback | Technical correctness > comfort |
173
+ | Partial implementation | Clarify all items first |
174
+ | Can't verify, proceed anyway | State limitation, ask for direction |
175
+
176
+ ## Real Examples
177
+
178
+ **Performative Agreement (Bad):**
179
+ ```
180
+ Reviewer: "Remove legacy code"
181
+ ❌ "You're absolutely right! Let me remove that..."
182
+ ```
183
+
184
+ **Technical Verification (Good):**
185
+ ```
186
+ Reviewer: "Remove legacy code"
187
+ ✅ "Checking... build target is 10.15+, this API needs 13+. Need legacy for backward compat. Current impl has wrong bundle ID - fix it or drop pre-13 support?"
188
+ ```
189
+
190
+ **YAGNI (Good):**
191
+ ```
192
+ Reviewer: "Implement proper metrics tracking with database, date filters, CSV export"
193
+ ✅ "Grepped codebase - nothing calls this endpoint. Remove it (YAGNI)? Or is there usage I'm missing?"
194
+ ```
195
+
196
+ **Unclear Item (Good):**
197
+ ```
198
+ your human partner: "Fix items 1-6"
199
+ You understand 1,2,3,6. Unclear on 4,5.
200
+ ✅ "Understand 1,2,3,6. Need clarification on 4 and 5 before implementing."
201
+ ```
202
+
203
+ ## GitHub Thread Replies
204
+
205
+ When replying to inline review comments on GitHub, reply in the comment thread (`gh api repos/{owner}/{repo}/pulls/{pr}/comments/{id}/replies`), not as a top-level PR comment.
206
+
207
+ ## The Bottom Line
208
+
209
+ **External feedback = suggestions to evaluate, not orders to follow.**
210
+
211
+ Verify. Question. Then implement.
212
+
213
+ No performative agreement. Technical rigor always.
@@ -0,0 +1,95 @@
1
+ ---
2
+ name: onboard
3
+ description: Use when starting any conversation - establishes how to find and use skills, requiring Skill tool invocation before ANY response including clarifying questions
4
+ ---
5
+
6
+ <EXTREMELY-IMPORTANT>
7
+ If you think there is even a 1% chance a skill might apply to what you are doing, you ABSOLUTELY MUST invoke the skill.
8
+
9
+ IF A SKILL APPLIES TO YOUR TASK, YOU DO NOT HAVE A CHOICE. YOU MUST USE IT.
10
+
11
+ This is not negotiable. This is not optional. You cannot rationalize your way out of this.
12
+ </EXTREMELY-IMPORTANT>
13
+
14
+ ## How to Access Skills
15
+
16
+ **In Claude Code:** Use the `Skill` tool. When you invoke a skill, its content is loaded and presented to you--follow it directly. Never use the Read tool on skill files.
17
+
18
+ **In other environments:** Check your platform's documentation for how skills are loaded.
19
+
20
+ # Using Skills
21
+
22
+ ## The Rule
23
+
24
+ **Invoke relevant or requested skills BEFORE any response or action.** Even a 1% chance a skill might apply means that you should invoke the skill to check. If an invoked skill turns out to be wrong for the situation, you don't need to use it.
25
+
26
+ ```dot
27
+ digraph skill_flow {
28
+ "User message received" [shape=doublecircle];
29
+ "About to EnterPlanMode?" [shape=doublecircle];
30
+ "Already brainstormed?" [shape=diamond];
31
+ "Invoke evaluate skill" [shape=box];
32
+ "Might any skill apply?" [shape=diamond];
33
+ "Invoke Skill tool" [shape=box];
34
+ "Announce: 'Using [skill] to [purpose]'" [shape=box];
35
+ "Has checklist?" [shape=diamond];
36
+ "Create TodoWrite todo per item" [shape=box];
37
+ "Follow skill exactly" [shape=box];
38
+ "Respond (including clarifications)" [shape=doublecircle];
39
+
40
+ "About to EnterPlanMode?" -> "Already brainstormed?";
41
+ "Already brainstormed?" -> "Invoke evaluate skill" [label="no"];
42
+ "Already brainstormed?" -> "Might any skill apply?" [label="yes"];
43
+ "Invoke evaluate skill" -> "Might any skill apply?";
44
+
45
+ "User message received" -> "Might any skill apply?";
46
+ "Might any skill apply?" -> "Invoke Skill tool" [label="yes, even 1%"];
47
+ "Might any skill apply?" -> "Respond (including clarifications)" [label="definitely not"];
48
+ "Invoke Skill tool" -> "Announce: 'Using [skill] to [purpose]'";
49
+ "Announce: 'Using [skill] to [purpose]'" -> "Has checklist?";
50
+ "Has checklist?" -> "Create TodoWrite todo per item" [label="yes"];
51
+ "Has checklist?" -> "Follow skill exactly" [label="no"];
52
+ "Create TodoWrite todo per item" -> "Follow skill exactly";
53
+ }
54
+ ```
55
+
56
+ ## Red Flags
57
+
58
+ These thoughts mean STOP--you're rationalizing:
59
+
60
+ | Thought | Reality |
61
+ |-|-|
62
+ | "This is just a simple question" | Questions are tasks. Check for skills. |
63
+ | "I need more context first" | Skill check comes BEFORE clarifying questions. |
64
+ | "Let me explore the codebase first" | Skills tell you HOW to explore. Check first. |
65
+ | "I can check git/files quickly" | Files lack conversation context. Check for skills. |
66
+ | "Let me gather information first" | Skills tell you HOW to gather information. |
67
+ | "This doesn't need a formal skill" | If a skill exists, use it. |
68
+ | "I remember this skill" | Skills evolve. Read current version. |
69
+ | "This doesn't count as a task" | Action = task. Check for skills. |
70
+ | "The skill is overkill" | Simple things become complex. Use it. |
71
+ | "I'll just do this one thing first" | Check BEFORE doing anything. |
72
+ | "This feels productive" | Undisciplined action wastes time. Skills prevent this. |
73
+ | "I know what that means" | Knowing the concept != using the skill. Invoke it. |
74
+
75
+ ## Skill Priority
76
+
77
+ When multiple skills could apply, use this order:
78
+
79
+ 1. **Process skills first** (evaluate, root-cause) - these determine HOW to approach the task
80
+ 2. **Implementation skills second** (frontend-design, mcp-builder) - these guide execution
81
+
82
+ "Let's build X" -> evaluate first, then implementation skills.
83
+ "Fix this bug" -> root-cause first, then domain-specific skills.
84
+
85
+ ## Skill Types
86
+
87
+ **Rigid** (TDD, debugging): Follow exactly. Don't adapt away discipline.
88
+
89
+ **Flexible** (patterns): Adapt principles to context.
90
+
91
+ The skill itself tells you which.
92
+
93
+ ## User Instructions
94
+
95
+ Instructions say WHAT, not HOW. "Add X" or "Fix Y" doesn't mean skip workflows.
@@ -0,0 +1,112 @@
1
+ ---
2
+ name: pr-stack
3
+ description: Maintains .claude/stack.json tracking stacked PR state across sessions. Read at session start when working on a stacked feature. Update after every PR creation, merge, or rebase.
4
+ ---
5
+
6
+ # Stack State
7
+
8
+ Manages `.claude/stack.json` -- the persistent record of stacked PR state across sessions.
9
+
10
+ ## Current State
11
+ - Stack file: !`cat .claude/stack.json 2>/dev/null || echo "No stack file found"`
12
+ - Open PRs: !`gh pr list --json number,title,headRefName,baseRefName,isDraft,state 2>/dev/null`
13
+ - Current branch: !`git branch --show-current`
14
+
15
+ ## Stack File Schema
16
+
17
+ ```json
18
+ {
19
+ "plan": "path/to/plan-document.md",
20
+ "stack": [
21
+ {
22
+ "branch": "feat/flow-creation",
23
+ "pr": 12,
24
+ "base": "main",
25
+ "status": "merged",
26
+ "description": "Flow creation entry point and edit mode"
27
+ },
28
+ {
29
+ "branch": "feat/flow-node-editor",
30
+ "pr": 13,
31
+ "base": "feat/flow-creation",
32
+ "status": "open",
33
+ "description": "Node canvas, 4 node types, drag/arrange/delete"
34
+ },
35
+ {
36
+ "branch": "feat/flow-connections",
37
+ "pr": 14,
38
+ "base": "feat/flow-node-editor",
39
+ "status": "draft",
40
+ "description": "Output/input circles, bezier edge connections"
41
+ }
42
+ ]
43
+ }
44
+ ```
45
+
46
+ **Status values:** `open` | `draft` | `merged` | `closed`
47
+
48
+ ## Operations
49
+
50
+ ### Read at session start
51
+
52
+ If `.claude/stack.json` exists:
53
+ 1. Read the file
54
+ 2. Show the current stack state as a summary table
55
+ 3. Identify which PR is current (first non-merged entry)
56
+ 4. Check that PR's actual status on GitHub matches the file
57
+
58
+ Report discrepancies and correct the file if needed.
59
+
60
+ ### After creating a PR
61
+
62
+ Add an entry to the stack array:
63
+
64
+ ```json
65
+ {
66
+ "branch": "<branch name>",
67
+ "pr": <PR number from gh pr create output>,
68
+ "base": "<base branch>",
69
+ "status": "open", // or "draft" if created with --draft
70
+ "description": "<one line summary>"
71
+ }
72
+ ```
73
+
74
+ Write the updated file.
75
+
76
+ ### After a PR is merged
77
+
78
+ 1. Set that entry's `status` to `"merged"`
79
+ 2. Find the next entry in the stack
80
+ 3. Update its `base` to `"main"` (it will be rebased onto main)
81
+ 4. Write the updated file
82
+ 5. Trigger the post-merge rebase sequence (see `rules/workflow.md`)
83
+
84
+ ### After rebasing a downstream branch
85
+
86
+ Update the entry's `base` field if it changed.
87
+
88
+ ### Checking stack health
89
+
90
+ Compare each open/draft PR's base branch on GitHub against the stack file. Flag mismatches.
91
+
92
+ ```bash
93
+ gh pr view <number> --json baseRefName -q '.baseRefName'
94
+ ```
95
+
96
+ ## Starting a fresh stack
97
+
98
+ When beginning a new stacked feature:
99
+
100
+ 1. Create `.claude/stack.json` with `"stack": []`
101
+ 2. Set `"plan"` to the path of the approved plan document
102
+ 3. Add entries as PRs are created
103
+
104
+ If no `.claude` directory exists:
105
+
106
+ ```bash
107
+ mkdir -p .claude
108
+ ```
109
+
110
+ ## Stack file location
111
+
112
+ Always `.claude/stack.json` relative to the repo root. Never in a subdirectory.