shipwright-cli 1.7.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.
- package/LICENSE +21 -0
- package/README.md +926 -0
- package/claude-code/CLAUDE.md.shipwright +125 -0
- package/claude-code/hooks/notify-idle.sh +35 -0
- package/claude-code/hooks/pre-compact-save.sh +57 -0
- package/claude-code/hooks/task-completed.sh +170 -0
- package/claude-code/hooks/teammate-idle.sh +68 -0
- package/claude-code/settings.json.template +184 -0
- package/completions/_shipwright +140 -0
- package/completions/shipwright.bash +89 -0
- package/completions/shipwright.fish +107 -0
- package/docs/KNOWN-ISSUES.md +199 -0
- package/docs/TIPS.md +331 -0
- package/docs/definition-of-done.example.md +16 -0
- package/docs/patterns/README.md +139 -0
- package/docs/patterns/audit-loop.md +149 -0
- package/docs/patterns/bug-hunt.md +183 -0
- package/docs/patterns/feature-implementation.md +159 -0
- package/docs/patterns/refactoring.md +183 -0
- package/docs/patterns/research-exploration.md +144 -0
- package/docs/patterns/test-generation.md +173 -0
- package/package.json +49 -0
- package/scripts/adapters/docker-deploy.sh +50 -0
- package/scripts/adapters/fly-deploy.sh +41 -0
- package/scripts/adapters/iterm2-adapter.sh +122 -0
- package/scripts/adapters/railway-deploy.sh +34 -0
- package/scripts/adapters/tmux-adapter.sh +87 -0
- package/scripts/adapters/vercel-deploy.sh +35 -0
- package/scripts/adapters/wezterm-adapter.sh +103 -0
- package/scripts/cct +242 -0
- package/scripts/cct-cleanup.sh +172 -0
- package/scripts/cct-cost.sh +590 -0
- package/scripts/cct-daemon.sh +3189 -0
- package/scripts/cct-doctor.sh +328 -0
- package/scripts/cct-fix.sh +478 -0
- package/scripts/cct-fleet.sh +904 -0
- package/scripts/cct-init.sh +282 -0
- package/scripts/cct-logs.sh +273 -0
- package/scripts/cct-loop.sh +1332 -0
- package/scripts/cct-memory.sh +1148 -0
- package/scripts/cct-pipeline.sh +3844 -0
- package/scripts/cct-prep.sh +1352 -0
- package/scripts/cct-ps.sh +168 -0
- package/scripts/cct-reaper.sh +390 -0
- package/scripts/cct-session.sh +284 -0
- package/scripts/cct-status.sh +169 -0
- package/scripts/cct-templates.sh +242 -0
- package/scripts/cct-upgrade.sh +422 -0
- package/scripts/cct-worktree.sh +405 -0
- package/scripts/postinstall.mjs +96 -0
- package/templates/pipelines/autonomous.json +71 -0
- package/templates/pipelines/cost-aware.json +95 -0
- package/templates/pipelines/deployed.json +79 -0
- package/templates/pipelines/enterprise.json +114 -0
- package/templates/pipelines/fast.json +63 -0
- package/templates/pipelines/full.json +104 -0
- package/templates/pipelines/hotfix.json +63 -0
- package/templates/pipelines/standard.json +91 -0
- package/tmux/claude-teams-overlay.conf +109 -0
- package/tmux/templates/architecture.json +19 -0
- package/tmux/templates/bug-fix.json +24 -0
- package/tmux/templates/code-review.json +24 -0
- package/tmux/templates/devops.json +19 -0
- package/tmux/templates/documentation.json +19 -0
- package/tmux/templates/exploration.json +19 -0
- package/tmux/templates/feature-dev.json +24 -0
- package/tmux/templates/full-stack.json +24 -0
- package/tmux/templates/migration.json +24 -0
- package/tmux/templates/refactor.json +19 -0
- package/tmux/templates/security-audit.json +24 -0
- package/tmux/templates/testing.json +24 -0
- package/tmux/tmux.conf +167 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Pattern: Bug Hunt
|
|
2
|
+
|
|
3
|
+
Track down complex bugs using parallel hypothesis testing with tmux teams.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
- **Intermittent failures** — the bug doesn't reproduce reliably and you're not sure where to look
|
|
10
|
+
- **Complex root cause** — multiple possible explanations (race condition? state corruption? edge case?)
|
|
11
|
+
- **Large blast radius** — the symptom is far from the cause and you need to search broadly
|
|
12
|
+
- **Time-sensitive** — parallel investigation is faster than sequential hypothesis testing
|
|
13
|
+
|
|
14
|
+
**Don't use** for obvious bugs with clear stack traces, or when you already know the root cause and just need to fix it.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Recommended Team Composition
|
|
19
|
+
|
|
20
|
+
| Role | Agent Name | Focus |
|
|
21
|
+
|------|-----------|-------|
|
|
22
|
+
| **Team Lead** | `lead` | Hypothesis formation, synthesis, fix verification |
|
|
23
|
+
| **Investigator 1** | `investigator-1` | Tests hypothesis A |
|
|
24
|
+
| **Investigator 2** | `investigator-2` | Tests hypothesis B |
|
|
25
|
+
| **Investigator 3** *(optional)* | `investigator-3` | Tests hypothesis C |
|
|
26
|
+
|
|
27
|
+
> **Tip:** Start with 2 investigators. Add a third only if Wave 1 produces 3+ viable hypotheses.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Wave Breakdown
|
|
32
|
+
|
|
33
|
+
### Wave 1: Gather Evidence
|
|
34
|
+
|
|
35
|
+
**Goal:** Collect data from multiple angles simultaneously.
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
┌──────────────────┬──────────────────┬──────────────────┐
|
|
39
|
+
│ Agent: logs │ Agent: code │ Agent: history │
|
|
40
|
+
│ Search error │ Find related │ Check git log │
|
|
41
|
+
│ logs, stack │ code paths, │ for recent │
|
|
42
|
+
│ traces, recent │ identify │ changes to │
|
|
43
|
+
│ failures │ suspects │ affected area │
|
|
44
|
+
└──────────────────┴──────────────────┴──────────────────┘
|
|
45
|
+
↓ Team lead forms hypotheses from evidence
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Agent instructions should be narrow:**
|
|
49
|
+
- Logs agent: "Search for error messages matching [pattern] in logs. Find the 5 most recent occurrences. Extract timestamps, stack traces, and request context."
|
|
50
|
+
- Code agent: "Read the code path for [affected operation]. Identify all places where [symptom] could originate. Check for missing error handling, race conditions, or state mutations."
|
|
51
|
+
- History agent: "Run `git log --since='2 weeks ago'` on [affected files]. Identify changes that could have introduced the bug. Check if the bug timing correlates with any deploy."
|
|
52
|
+
|
|
53
|
+
### Wave 2: Test Hypotheses (Parallel)
|
|
54
|
+
|
|
55
|
+
**Goal:** Each agent tests a different hypothesis simultaneously.
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
┌──────────────────┬──────────────────┬──────────────────┐
|
|
59
|
+
│ Agent: hypo-A │ Agent: hypo-B │ Agent: hypo-C │
|
|
60
|
+
│ Test: race │ Test: state │ Test: edge case │
|
|
61
|
+
│ condition in │ corruption in │ in input │
|
|
62
|
+
│ auth middleware │ session store │ validation │
|
|
63
|
+
└──────────────────┴──────────────────┴──────────────────┘
|
|
64
|
+
↓ Team lead evaluates which hypothesis has evidence
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Each agent should:**
|
|
68
|
+
1. Add targeted logging or assertions to test their hypothesis
|
|
69
|
+
2. Attempt to reproduce the bug under their hypothesis's conditions
|
|
70
|
+
3. Write a clear "confirmed/rejected/inconclusive" verdict with evidence
|
|
71
|
+
|
|
72
|
+
### Wave 3: Fix
|
|
73
|
+
|
|
74
|
+
**Goal:** Implement the fix based on confirmed hypothesis.
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
┌──────────────────┐
|
|
78
|
+
│ Agent: fixer │
|
|
79
|
+
│ Implement fix │
|
|
80
|
+
│ based on │
|
|
81
|
+
│ confirmed │
|
|
82
|
+
│ hypothesis │
|
|
83
|
+
└──────────────────┘
|
|
84
|
+
↓ Team lead reviews fix
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Usually a single agent. The team lead provides the confirmed root cause from Wave 2.
|
|
88
|
+
|
|
89
|
+
### Wave 4: Verify
|
|
90
|
+
|
|
91
|
+
**Goal:** Prove the fix works and prevent regression.
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
┌──────────────────┬──────────────────┐
|
|
95
|
+
│ Agent: regression │ Agent: verify │
|
|
96
|
+
│ Write regression │ Test that the │
|
|
97
|
+
│ test that fails │ original bug │
|
|
98
|
+
│ without fix │ no longer │
|
|
99
|
+
│ passes with it │ reproduces │
|
|
100
|
+
└──────────────────┴──────────────────┘
|
|
101
|
+
↓ Team lead confirms: bug fixed, regression test in place
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## File-Based State Example
|
|
107
|
+
|
|
108
|
+
`.claude/team-state.local.md`:
|
|
109
|
+
|
|
110
|
+
```markdown
|
|
111
|
+
---
|
|
112
|
+
wave: 2
|
|
113
|
+
status: in_progress
|
|
114
|
+
goal: "Find and fix intermittent 401 errors on /api/dashboard after session refresh"
|
|
115
|
+
started_at: 2026-02-07T16:00:00Z
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Bug Description
|
|
119
|
+
Users intermittently get 401 Unauthorized on /api/dashboard. Happens ~5% of the time,
|
|
120
|
+
mostly after browser has been idle for 10+ minutes. Session refresh should be transparent.
|
|
121
|
+
|
|
122
|
+
## Evidence (Wave 1)
|
|
123
|
+
- Error logs show 401s with valid-looking JWT signatures (wave-1-logs.md)
|
|
124
|
+
- Session refresh endpoint returns 200 but sometimes the new token isn't persisted (wave-1-code.md)
|
|
125
|
+
- git log shows refresh token rotation was added 3 weeks ago (wave-1-history.md)
|
|
126
|
+
|
|
127
|
+
## Hypotheses
|
|
128
|
+
- **A: Race condition** — refresh fires twice, second request uses revoked token
|
|
129
|
+
- **B: Cookie timing** — httpOnly cookie isn't set before the next API call fires
|
|
130
|
+
- **C: Clock skew** — JWT "not before" time is in the future on some requests
|
|
131
|
+
|
|
132
|
+
## In Progress (Wave 2)
|
|
133
|
+
- [ ] Testing hypothesis A: Add mutex/dedup to refresh logic
|
|
134
|
+
- [ ] Testing hypothesis B: Add cookie write logging, check timing
|
|
135
|
+
- [ ] Testing hypothesis C: Add clock skew tolerance, check JWT nbf
|
|
136
|
+
|
|
137
|
+
## Agent Outputs
|
|
138
|
+
- wave-1-logs.md
|
|
139
|
+
- wave-1-code.md
|
|
140
|
+
- wave-1-history.md
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Example Commands
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Create a 3-agent bug hunt team
|
|
149
|
+
shipwright session bug-hunt-401
|
|
150
|
+
|
|
151
|
+
# Watch all three investigators work in parallel panes
|
|
152
|
+
# Each pane shows a different hypothesis being tested
|
|
153
|
+
|
|
154
|
+
# Use prefix + G to zoom into the most promising investigator
|
|
155
|
+
# Use prefix + Alt-s to capture pane output for later review
|
|
156
|
+
|
|
157
|
+
# Monitor
|
|
158
|
+
shipwright status
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Tips
|
|
164
|
+
|
|
165
|
+
- **Wave 1 is about breadth, Wave 2 is about depth.** Cast a wide net first, then drill into the most promising leads.
|
|
166
|
+
- **Give each investigator ONE hypothesis.** Don't let agents explore multiple theories — focus produces better results.
|
|
167
|
+
- **Include reproduction steps in agent prompts.** If you know how to trigger the bug (even intermittently), include those exact steps.
|
|
168
|
+
- **The team lead forms hypotheses, not agents.** Agents gather evidence and test hypotheses. The team lead synthesizes evidence into hypotheses and decides which to pursue.
|
|
169
|
+
- **Add logging generously in Wave 2.** Hypothesis testing often requires instrumentation. Let agents add `console.log` or debug assertions freely — you can clean them up after.
|
|
170
|
+
- **Commit the fix AND the regression test together.** A fix without a regression test is a bug waiting to come back.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Anti-Patterns
|
|
175
|
+
|
|
176
|
+
| Don't | Why |
|
|
177
|
+
|-------|-----|
|
|
178
|
+
| Skip evidence gathering (Wave 1) | You'll test the wrong hypotheses |
|
|
179
|
+
| Let agents form their own hypotheses | They lack the full picture — the team lead should synthesize |
|
|
180
|
+
| Test only one hypothesis at a time | That's sequential — the whole point is parallel hypothesis testing |
|
|
181
|
+
| Test more than 3 hypotheses per wave | Agents won't go deep enough on any of them |
|
|
182
|
+
| Implement a fix before confirming the root cause | You'll fix a symptom, not the cause |
|
|
183
|
+
| Skip the regression test (Wave 4) | The bug WILL come back |
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Pattern: Feature Implementation
|
|
2
|
+
|
|
3
|
+
Build multi-component features using iterative parallel waves with tmux teams.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
- Building a feature that spans **2+ layers** (frontend + backend, API + tests, etc.)
|
|
10
|
+
- Work can be **decomposed into independent modules** that different agents can build simultaneously
|
|
11
|
+
- You want **faster delivery** than sequential single-agent work
|
|
12
|
+
|
|
13
|
+
**Don't use** for single-file changes, tightly sequential work, or features small enough for one agent.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Recommended Team Composition
|
|
18
|
+
|
|
19
|
+
| Role | Agent Name | Focus | Example Files |
|
|
20
|
+
|------|-----------|-------|---------------|
|
|
21
|
+
| **Team Lead** | `lead` | Orchestration, synthesis, integration | State file, final wiring |
|
|
22
|
+
| **Backend** | `backend` | Data models, API routes, services | `src/api/`, `src/services/`, `src/models/` |
|
|
23
|
+
| **Frontend** | `frontend` | UI components, state management | `apps/web/src/`, `*.tsx` |
|
|
24
|
+
| **Tests** *(optional)* | `tests` | Unit + integration tests | `src/tests/`, `*.test.ts` |
|
|
25
|
+
|
|
26
|
+
> **Tip:** For smaller features, combine frontend + tests into one agent (2-agent team).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Wave Breakdown
|
|
31
|
+
|
|
32
|
+
### Wave 1: Research & Plan
|
|
33
|
+
|
|
34
|
+
**Goal:** Understand existing patterns before writing code.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
┌──────────────────┬──────────────────┐
|
|
38
|
+
│ Agent: backend │ Agent: frontend │
|
|
39
|
+
│ Scan existing │ Scan existing │
|
|
40
|
+
│ API patterns, │ component │
|
|
41
|
+
│ data models, │ patterns, state │
|
|
42
|
+
│ middleware │ management │
|
|
43
|
+
└──────────────────┴──────────────────┘
|
|
44
|
+
↓ Team lead synthesizes findings
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Each agent writes:** `.claude/team-outputs/wave-1-{name}.md`
|
|
48
|
+
|
|
49
|
+
**Team lead then:** Reads both outputs, identifies the implementation approach, updates the state file with a plan.
|
|
50
|
+
|
|
51
|
+
### Wave 2: Parallel Implementation
|
|
52
|
+
|
|
53
|
+
**Goal:** Build independent components simultaneously.
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
┌──────────────────┬──────────────────┬──────────────────┐
|
|
57
|
+
│ Agent: backend │ Agent: frontend │ Agent: tests │
|
|
58
|
+
│ Build data │ Build UI │ Set up test │
|
|
59
|
+
│ model + API │ components + │ fixtures + │
|
|
60
|
+
│ routes │ state hooks │ unit tests │
|
|
61
|
+
└──────────────────┴──────────────────┴──────────────────┘
|
|
62
|
+
↓ Team lead reviews outputs, checks for errors
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Each agent writes:** `.claude/team-outputs/wave-2-{name}.md`
|
|
66
|
+
|
|
67
|
+
**Team lead then:** Reads outputs, runs a quick build/typecheck, identifies integration points.
|
|
68
|
+
|
|
69
|
+
### Wave 3: Integration & Validation
|
|
70
|
+
|
|
71
|
+
**Goal:** Wire components together, run tests, fix issues.
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
┌──────────────────┬──────────────────┐
|
|
75
|
+
│ Agent: backend │ Agent: tests │
|
|
76
|
+
│ Wire routes to │ Run full test │
|
|
77
|
+
│ frontend calls, │ suite, write │
|
|
78
|
+
│ fix type errors │ integration tests│
|
|
79
|
+
└──────────────────┴──────────────────┘
|
|
80
|
+
↓ Team lead verifies everything passes
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Wave 4: Polish *(if needed)*
|
|
84
|
+
|
|
85
|
+
**Goal:** Fix remaining issues, documentation.
|
|
86
|
+
|
|
87
|
+
Usually a single agent handles the remaining fixes.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## File-Based State Example
|
|
92
|
+
|
|
93
|
+
`.claude/team-state.local.md`:
|
|
94
|
+
|
|
95
|
+
```markdown
|
|
96
|
+
---
|
|
97
|
+
wave: 2
|
|
98
|
+
status: in_progress
|
|
99
|
+
goal: "Build user authentication with JWT — login, signup, password reset"
|
|
100
|
+
started_at: 2026-02-07T10:00:00Z
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Completed
|
|
104
|
+
- [x] Scanned existing Express route patterns (wave-1-backend.md)
|
|
105
|
+
- [x] Scanned existing React component patterns (wave-1-frontend.md)
|
|
106
|
+
- [x] Decided: JWT with httpOnly cookies, Zod validation, React Hook Form
|
|
107
|
+
|
|
108
|
+
## In Progress (Wave 2)
|
|
109
|
+
- [ ] User model + auth routes (backend)
|
|
110
|
+
- [ ] Login/Signup/Reset components (frontend)
|
|
111
|
+
- [ ] Auth test fixtures + unit tests (tests)
|
|
112
|
+
|
|
113
|
+
## Blocked
|
|
114
|
+
- Integration tests blocked on Wave 2 completion
|
|
115
|
+
|
|
116
|
+
## Agent Outputs
|
|
117
|
+
- wave-1-backend.md — Express patterns, middleware chain analysis
|
|
118
|
+
- wave-1-frontend.md — React component patterns, existing form handling
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Example Commands
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Create the team session with 3 panes
|
|
127
|
+
shipwright session auth-feature
|
|
128
|
+
|
|
129
|
+
# In the team lead pane, describe the feature goal and wave plan
|
|
130
|
+
# The team lead spawns workers and tracks state in .claude/team-state.local.md
|
|
131
|
+
|
|
132
|
+
# Monitor progress from any terminal
|
|
133
|
+
shipwright status
|
|
134
|
+
|
|
135
|
+
# Clean up when done
|
|
136
|
+
shipwright cleanup --force
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Tips
|
|
142
|
+
|
|
143
|
+
- **Partition files strictly.** Before Wave 2, explicitly tell each agent which directories they own. File conflicts are the #1 failure mode.
|
|
144
|
+
- **Run typecheck between waves.** The quality gate hooks help here — `teammate-idle.sh` catches type errors before agents go idle.
|
|
145
|
+
- **Don't over-decompose Wave 1.** Two research agents are usually enough. More than 3 researchers creates redundant analysis.
|
|
146
|
+
- **Wave 3 is where things break.** Integration is inherently serial. Be ready to have the team lead handle wiring personally if agents struggle with cross-module connections.
|
|
147
|
+
- **Use `sonnet` for implementation, `haiku` for lookups.** Save the expensive models for the architecture decisions in Wave 1.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Anti-Patterns
|
|
152
|
+
|
|
153
|
+
| Don't | Why |
|
|
154
|
+
|-------|-----|
|
|
155
|
+
| Let two agents edit the same file | One overwrites the other |
|
|
156
|
+
| Skip Wave 1 research | Agents will re-invent existing patterns instead of following them |
|
|
157
|
+
| Give agents the full feature spec | They lose focus. Give each agent only their slice |
|
|
158
|
+
| Run Wave 3 without checking Wave 2 outputs | You'll integrate broken code |
|
|
159
|
+
| Use 4+ agents for a single feature | Coordination cost exceeds the parallel benefit |
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Pattern: Refactoring
|
|
2
|
+
|
|
3
|
+
Perform large-scale code transformations safely using a 2-agent team with strict file ownership and iterative validation.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
- **Pattern migration** — converting callbacks to async/await, class components to hooks, etc.
|
|
10
|
+
- **Architecture changes** — extracting modules, reorganizing directories, splitting monoliths
|
|
11
|
+
- **API redesign** — changing function signatures, renaming across the codebase
|
|
12
|
+
- **Dependency replacement** — swapping one library for another throughout the project
|
|
13
|
+
|
|
14
|
+
**Don't use** for small renames in 1-2 files, or cosmetic changes like formatting.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Recommended Team Composition
|
|
19
|
+
|
|
20
|
+
| Role | Agent Name | Focus | Owns |
|
|
21
|
+
|------|-----------|-------|------|
|
|
22
|
+
| **Team Lead** | `lead` | Orchestration, runs tests between waves | State file |
|
|
23
|
+
| **Refactorer** | `refactor` | Source code transformations | Production source files |
|
|
24
|
+
| **Consumers** | `consumers` | Updates tests, imports, dependents | Test files, config files, docs |
|
|
25
|
+
|
|
26
|
+
> This is intentionally a **2-agent** pattern. Refactoring requires tight coordination — more agents means more conflict risk. The team lead runs tests.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Wave Breakdown
|
|
31
|
+
|
|
32
|
+
### Wave 1: Map
|
|
33
|
+
|
|
34
|
+
**Goal:** Find all instances of the old pattern and understand the dependency graph.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
┌──────────────────┬──────────────────┐
|
|
38
|
+
│ Agent: refactor │ Agent: consumers │
|
|
39
|
+
│ Find all │ Find all tests, │
|
|
40
|
+
│ instances of old │ imports, and │
|
|
41
|
+
│ pattern in source │ dependents of │
|
|
42
|
+
│ code │ affected modules │
|
|
43
|
+
└──────────────────┴──────────────────┘
|
|
44
|
+
↓ Team lead builds the transformation plan
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**This wave is critical.** The team lead uses both outputs to:
|
|
48
|
+
1. Identify the full blast radius of the change
|
|
49
|
+
2. Order the transformation (leaf nodes first)
|
|
50
|
+
3. Assign specific files to each agent
|
|
51
|
+
|
|
52
|
+
### Wave 2: Transform (Leaf Nodes First)
|
|
53
|
+
|
|
54
|
+
**Goal:** Change the code, starting with modules that nothing else depends on.
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
┌──────────────────┬──────────────────┐
|
|
58
|
+
│ Agent: refactor │ Agent: consumers │
|
|
59
|
+
│ Transform leaf │ Update tests for │
|
|
60
|
+
│ modules — files │ leaf modules, │
|
|
61
|
+
│ with zero │ fix imports │
|
|
62
|
+
│ dependents │ │
|
|
63
|
+
└──────────────────┴──────────────────┘
|
|
64
|
+
↓ Team lead runs tests — should still pass
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Why leaf nodes first?** If you change a core module first, everything that depends on it breaks simultaneously. By starting with leaf nodes, you keep the test suite green between waves.
|
|
68
|
+
|
|
69
|
+
### Wave 3: Transform Core
|
|
70
|
+
|
|
71
|
+
**Goal:** Transform the remaining core modules, now that leaf nodes are done.
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
┌──────────────────┬──────────────────┐
|
|
75
|
+
│ Agent: refactor │ Agent: consumers │
|
|
76
|
+
│ Transform core │ Update remaining │
|
|
77
|
+
│ modules │ tests, fix type │
|
|
78
|
+
│ │ errors │
|
|
79
|
+
└──────────────────┴──────────────────┘
|
|
80
|
+
↓ Team lead runs full test suite
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Wave 4+: Fix Breakage
|
|
84
|
+
|
|
85
|
+
**Goal:** Iteratively fix test failures and type errors until green.
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
┌──────────────────┬──────────────────┐
|
|
89
|
+
│ Agent: refactor │ Agent: consumers │
|
|
90
|
+
│ Fix source code │ Fix test │
|
|
91
|
+
│ issues from test │ failures, │
|
|
92
|
+
│ failures │ update snapshots │
|
|
93
|
+
└──────────────────┴──────────────────┘
|
|
94
|
+
↓ Team lead verifies: all tests pass, no type errors
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## File-Based State Example
|
|
100
|
+
|
|
101
|
+
`.claude/team-state.local.md`:
|
|
102
|
+
|
|
103
|
+
```markdown
|
|
104
|
+
---
|
|
105
|
+
wave: 3
|
|
106
|
+
status: in_progress
|
|
107
|
+
goal: "Convert all callback-based code in src/services/ to async/await"
|
|
108
|
+
started_at: 2026-02-07T11:00:00Z
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Transformation Map (from Wave 1)
|
|
112
|
+
Leaf nodes (no dependents):
|
|
113
|
+
- src/services/email.ts (5 callbacks)
|
|
114
|
+
- src/services/logger.ts (2 callbacks)
|
|
115
|
+
|
|
116
|
+
Core modules (have dependents):
|
|
117
|
+
- src/services/db.ts (12 callbacks) → used by 8 other files
|
|
118
|
+
- src/services/auth.ts (7 callbacks) → used by 4 other files
|
|
119
|
+
|
|
120
|
+
## Completed
|
|
121
|
+
- [x] Mapped all 26 callback instances across 4 files (wave-1-refactor.md)
|
|
122
|
+
- [x] Found 14 test files and 6 other dependents (wave-1-consumers.md)
|
|
123
|
+
- [x] Converted email.ts and logger.ts to async/await (wave-2)
|
|
124
|
+
- [x] Updated tests for email.ts and logger.ts (wave-2)
|
|
125
|
+
|
|
126
|
+
## In Progress (Wave 3)
|
|
127
|
+
- [ ] Convert db.ts (12 callbacks → async/await)
|
|
128
|
+
- [ ] Convert auth.ts (7 callbacks → async/await)
|
|
129
|
+
- [ ] Update 14 test files for new signatures
|
|
130
|
+
- [ ] Fix imports in 6 dependent modules
|
|
131
|
+
|
|
132
|
+
## Test Status
|
|
133
|
+
- After Wave 2: 142/142 passing
|
|
134
|
+
- After Wave 3: TBD
|
|
135
|
+
|
|
136
|
+
## Agent Outputs
|
|
137
|
+
- wave-1-refactor.md — Full callback inventory with file:line
|
|
138
|
+
- wave-1-consumers.md — Dependency map of affected modules
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Example Commands
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# Create a 2-agent refactoring team
|
|
147
|
+
shipwright session refactor-async
|
|
148
|
+
|
|
149
|
+
# In the lead pane, describe the refactoring goal
|
|
150
|
+
# Team lead assigns specific files to each agent per wave
|
|
151
|
+
|
|
152
|
+
# Run tests between waves from the lead pane:
|
|
153
|
+
# pnpm test
|
|
154
|
+
|
|
155
|
+
# Monitor agents in their panes
|
|
156
|
+
shipwright status
|
|
157
|
+
|
|
158
|
+
# Clean up
|
|
159
|
+
shipwright cleanup --force
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Tips
|
|
165
|
+
|
|
166
|
+
- **Always map before transforming.** Wave 1 is non-negotiable. Skipping it leads to missed instances and cascading breakage.
|
|
167
|
+
- **Transform leaf nodes first.** This keeps the test suite green through intermediate waves, which gives you confidence that each wave's changes are correct.
|
|
168
|
+
- **The team lead must run tests between every wave.** This is the safety net. If tests break, you know which wave caused it.
|
|
169
|
+
- **Strict file ownership.** The refactorer owns production files. The consumers agent owns test files and config. Never overlap.
|
|
170
|
+
- **Use git commits between waves.** After each successful wave (tests pass), commit. This gives you rollback points if a later wave goes wrong.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Anti-Patterns
|
|
175
|
+
|
|
176
|
+
| Don't | Why |
|
|
177
|
+
|-------|-----|
|
|
178
|
+
| Transform everything at once | If it breaks, you won't know which change caused it |
|
|
179
|
+
| Let both agents edit the same file | Write conflicts |
|
|
180
|
+
| Skip running tests between waves | You lose the ability to isolate which wave broke things |
|
|
181
|
+
| Start with core modules | Everything that depends on them breaks simultaneously |
|
|
182
|
+
| Use 3+ agents for refactoring | The file ownership partition becomes too fragmented |
|
|
183
|
+
| Refactor and add features simultaneously | One change at a time — refactoring should be behavior-preserving |
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Pattern: Research & Exploration
|
|
2
|
+
|
|
3
|
+
Understand a codebase, problem space, or architecture using parallel exploration agents in tmux.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
- **Onboarding** onto an unfamiliar codebase — need to map architecture, patterns, and conventions
|
|
10
|
+
- **Pre-implementation research** — need to understand existing code before building something new
|
|
11
|
+
- **Architecture review** — need a comprehensive understanding of how the system fits together
|
|
12
|
+
- **Dependency audits** — need to survey what's used and where
|
|
13
|
+
|
|
14
|
+
**Don't use** when you already know the codebase well, or for narrow questions where a single `grep` suffices.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Recommended Team Composition
|
|
19
|
+
|
|
20
|
+
| Role | Agent Name | Focus |
|
|
21
|
+
|------|-----------|-------|
|
|
22
|
+
| **Team Lead** | `lead` | Synthesis, asks follow-up questions, produces final report |
|
|
23
|
+
| **Explorer 1** | `structure` | Directory layout, entry points, build system, configuration |
|
|
24
|
+
| **Explorer 2** | `patterns` | Code patterns, abstractions, data flow, key types |
|
|
25
|
+
| **Explorer 3** *(optional)* | `deps` | Dependencies, external integrations, API surface |
|
|
26
|
+
|
|
27
|
+
> **Tip:** For smaller codebases, 2 agents (structure + patterns) is enough.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Wave Breakdown
|
|
32
|
+
|
|
33
|
+
### Wave 1: Broad Scan
|
|
34
|
+
|
|
35
|
+
**Goal:** Map the territory. Each agent scans a different dimension of the codebase.
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
┌──────────────────┬──────────────────┬──────────────────┐
|
|
39
|
+
│ Agent: structure │ Agent: patterns │ Agent: deps │
|
|
40
|
+
│ Map directories │ Find key │ Catalog external │
|
|
41
|
+
│ Find entry │ abstractions, │ dependencies, │
|
|
42
|
+
│ points, configs │ patterns, types │ API boundaries │
|
|
43
|
+
└──────────────────┴──────────────────┴──────────────────┘
|
|
44
|
+
↓ Team lead synthesizes initial map
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Agent prompts should be specific:**
|
|
48
|
+
- Structure agent: "Map the directory tree, identify entry points (main files, index files), find config files (tsconfig, package.json, .env), and document the build pipeline."
|
|
49
|
+
- Patterns agent: "Find recurring code patterns — how are routes defined? How is state managed? What abstraction layers exist? Document with specific file:line references."
|
|
50
|
+
- Deps agent: "Catalog all external dependencies from package.json/go.mod/requirements.txt. Map which modules use which deps. Identify external API calls."
|
|
51
|
+
|
|
52
|
+
### Wave 2: Deep Dives
|
|
53
|
+
|
|
54
|
+
**Goal:** Based on Wave 1 findings, investigate specific areas in depth.
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
┌──────────────────┬──────────────────┐
|
|
58
|
+
│ Agent: deep-1 │ Agent: deep-2 │
|
|
59
|
+
│ Trace the auth │ Trace the data │
|
|
60
|
+
│ flow end-to-end │ layer end-to-end │
|
|
61
|
+
│ (from HTTP to DB)│ (models → API) │
|
|
62
|
+
└──────────────────┴──────────────────┘
|
|
63
|
+
↓ Team lead synthesizes into architecture doc
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The team lead picks the 2-3 most important areas from Wave 1 findings and sends agents to trace them in detail.
|
|
67
|
+
|
|
68
|
+
### Wave 3: Synthesis *(team lead only)*
|
|
69
|
+
|
|
70
|
+
**Goal:** Combine all findings into a coherent report.
|
|
71
|
+
|
|
72
|
+
The team lead reads all agent output files and produces a final architecture document or research summary.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## File-Based State Example
|
|
77
|
+
|
|
78
|
+
`.claude/team-state.local.md`:
|
|
79
|
+
|
|
80
|
+
```markdown
|
|
81
|
+
---
|
|
82
|
+
wave: 2
|
|
83
|
+
status: in_progress
|
|
84
|
+
goal: "Map architecture of the payments service for migration planning"
|
|
85
|
+
started_at: 2026-02-07T09:00:00Z
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Completed
|
|
89
|
+
- [x] Directory structure mapped (wave-1-structure.md)
|
|
90
|
+
- [x] Key patterns identified: repository pattern, event sourcing (wave-1-patterns.md)
|
|
91
|
+
- [x] External deps cataloged: Stripe SDK, Redis, PostgreSQL (wave-1-deps.md)
|
|
92
|
+
|
|
93
|
+
## In Progress (Wave 2)
|
|
94
|
+
- [ ] Deep dive: payment processing flow (Stripe integration → event store → ledger)
|
|
95
|
+
- [ ] Deep dive: subscription lifecycle (create → renew → cancel → webhook handling)
|
|
96
|
+
|
|
97
|
+
## Key Findings So Far
|
|
98
|
+
- Entry point: src/server.ts → src/routes/index.ts
|
|
99
|
+
- All mutations go through event store before updating read models
|
|
100
|
+
- Stripe webhook handler is in src/webhooks/stripe.ts — 800 lines, needs refactoring
|
|
101
|
+
- No test coverage for subscription renewal edge cases
|
|
102
|
+
|
|
103
|
+
## Agent Outputs
|
|
104
|
+
- wave-1-structure.md
|
|
105
|
+
- wave-1-patterns.md
|
|
106
|
+
- wave-1-deps.md
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Example Commands
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# Create a 2-agent exploration team
|
|
115
|
+
shipwright session codebase-explore
|
|
116
|
+
|
|
117
|
+
# Agents run in parallel panes — you can watch both scanning at once
|
|
118
|
+
# Team lead pane synthesizes results between waves
|
|
119
|
+
|
|
120
|
+
# Use tmux zoom (prefix + G) to focus on one agent's output
|
|
121
|
+
# Use synchronized input (prefix + S) to stop all agents at once if needed
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Tips
|
|
127
|
+
|
|
128
|
+
- **Use `haiku` for Wave 1 agents.** Broad scanning is simple work — haiku is fast and cheap for file discovery and pattern matching.
|
|
129
|
+
- **Use `sonnet` or `opus` for Wave 2 deep dives.** Tracing execution paths and understanding architecture requires stronger reasoning.
|
|
130
|
+
- **Give agents specific questions, not vague goals.** Instead of "explore the frontend," ask "How does the React app manage authentication state? Trace from login button click through to authenticated API calls."
|
|
131
|
+
- **Wave 1 should produce file:line references.** Agents should cite specific locations, not just describe patterns abstractly. This makes Wave 2 much more efficient.
|
|
132
|
+
- **The team lead's synthesis is the real deliverable.** Individual agent outputs are raw data. The team lead turns them into actionable understanding.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Anti-Patterns
|
|
137
|
+
|
|
138
|
+
| Don't | Why |
|
|
139
|
+
|-------|-----|
|
|
140
|
+
| Send all agents to explore the same directories | Redundant work, wasted tokens |
|
|
141
|
+
| Skip Wave 1 and go straight to deep dives | You won't know which areas are worth diving into |
|
|
142
|
+
| Have agents write a "report" instead of citing specifics | Abstract summaries are useless — you need file:line references |
|
|
143
|
+
| Use more than 3 exploration agents | Diminishing returns — 3 agents cover most codebases in one wave |
|
|
144
|
+
| Run exploration waves beyond 3 | If you don't understand the codebase after 3 waves, the problem is prompt quality, not wave count |
|