opencode-swarm-plugin 0.14.0 → 0.15.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,900 @@
1
+ # Subagent Coordination Patterns Analysis
2
+
3
+ **Source:** obra/superpowers repository
4
+ **Files Analyzed:**
5
+
6
+ - skills/subagent-driven-development/SKILL.md
7
+ - skills/dispatching-parallel-agents/SKILL.md
8
+ - skills/requesting-code-review/SKILL.md
9
+ - skills/requesting-code-review/code-reviewer.md
10
+
11
+ ---
12
+
13
+ ## 1. Core Principles
14
+
15
+ 1. **Fresh Subagent Per Task** - No context pollution. Each agent starts clean, reads requirements, executes, reports back.
16
+
17
+ 2. **Review Between Tasks** - Code review after EACH task catches issues before they compound. Cheaper than debugging later.
18
+
19
+ 3. **Focused Agent Prompts** - One clear problem domain per agent. Self-contained context. Specific about expected output.
20
+
21
+ 4. **Parallelize Independent Work** - 3+ independent failures/tasks = dispatch concurrent agents. No shared state = parallel safe.
22
+
23
+ 5. **Same Session Execution** - Subagent-driven development stays in current session (vs executing-plans which spawns parallel session).
24
+
25
+ 6. **Quality Gates Over Speed** - More subagent invocations cost tokens, but catching issues early is cheaper than debugging cascading failures.
26
+
27
+ 7. **Never Skip Review** - Even "simple" tasks get reviewed. Critical issues block progress. Important issues fixed before next task.
28
+
29
+ 8. **Explicit Severity Tiers** - Critical (must fix), Important (should fix), Minor (nice to have). Not everything is critical.
30
+
31
+ ---
32
+
33
+ ## 2. When to Use Each Pattern
34
+
35
+ ### Subagent-Driven Development
36
+
37
+ **Use when:**
38
+
39
+ - Staying in current session (no context switch)
40
+ - Tasks are mostly independent
41
+ - Want continuous progress with quality gates
42
+ - Have a plan ready to execute
43
+
44
+ **Don't use when:**
45
+
46
+ - Need to review plan first → use `executing-plans`
47
+ - Tasks are tightly coupled → manual execution better
48
+ - Plan needs revision → brainstorm first
49
+
50
+ **Decision tree:**
51
+
52
+ ```
53
+ Have implementation plan?
54
+ ├─ Yes → Tasks independent?
55
+ │ ├─ Yes → Stay in session?
56
+ │ │ ├─ Yes → Subagent-Driven Development ✓
57
+ │ │ └─ No → Executing Plans (parallel session)
58
+ │ └─ No → Manual execution (tight coupling)
59
+ └─ No → Write plan first
60
+ ```
61
+
62
+ ---
63
+
64
+ ### Dispatching Parallel Agents
65
+
66
+ **Use when:**
67
+
68
+ - 3+ test files failing with different root causes
69
+ - Multiple subsystems broken independently
70
+ - Each problem can be understood without context from others
71
+ - No shared state between investigations
72
+
73
+ **Don't use when:**
74
+
75
+ - Failures are related (fix one might fix others)
76
+ - Need to understand full system state
77
+ - Agents would interfere with each other (shared state, editing same files)
78
+ - Exploratory debugging (don't know what's broken yet)
79
+
80
+ **Decision tree:**
81
+
82
+ ```
83
+ Multiple failures?
84
+ ├─ Yes → Are they independent?
85
+ │ ├─ Yes → Can work in parallel?
86
+ │ │ ├─ Yes → 3+ failures?
87
+ │ │ │ ├─ Yes → Parallel Dispatch ✓
88
+ │ │ │ └─ No → Sequential agents
89
+ │ │ └─ No (shared state) → Sequential agents
90
+ │ └─ No (related) → Single agent investigates all
91
+ └─ No → Single investigation
92
+ ```
93
+
94
+ **Heuristics:**
95
+
96
+ - Different test files = likely independent
97
+ - Different subsystems = likely independent
98
+ - Same error across files = likely related
99
+ - Cascading failures = investigate root cause first
100
+
101
+ ---
102
+
103
+ ### Requesting Code Review
104
+
105
+ **Mandatory:**
106
+
107
+ - After each task in subagent-driven development
108
+ - After completing major feature
109
+ - Before merge to main
110
+
111
+ **Optional but valuable:**
112
+
113
+ - When stuck (fresh perspective)
114
+ - Before refactoring (baseline check)
115
+ - After fixing complex bug
116
+
117
+ **Never skip because:**
118
+
119
+ - "It's simple" (simple tasks can have subtle issues)
120
+ - "I'm confident" (review finds blind spots)
121
+ - "Time pressure" (unfixed bugs cost more time later)
122
+
123
+ ---
124
+
125
+ ## 3. Agent Prompt Best Practices
126
+
127
+ ### Anatomy of a Good Prompt
128
+
129
+ **1. Focused** - One clear problem domain
130
+
131
+ ```markdown
132
+ ❌ "Fix all the tests"
133
+ ✓ "Fix agent-tool-abort.test.ts"
134
+ ```
135
+
136
+ **2. Self-contained** - All context needed
137
+
138
+ ```markdown
139
+ ❌ "Fix the race condition"
140
+ ✓ "Fix the 3 failing tests in src/agents/agent-tool-abort.test.ts:
141
+
142
+ 1. 'should abort tool with partial output capture' - expects 'interrupted at' in message
143
+ 2. 'should handle mixed completed and aborted tools' - fast tool aborted instead of completed
144
+ 3. 'should properly track pendingToolCount' - expects 3 results but gets 0"
145
+ ```
146
+
147
+ **3. Specific about output** - What should agent return?
148
+
149
+ ```markdown
150
+ ❌ "Fix it"
151
+ ✓ "Return: Summary of root cause and what you fixed"
152
+ ```
153
+
154
+ **4. Constraints** - Prevent scope creep
155
+
156
+ ```markdown
157
+ ✓ "Do NOT just increase timeouts - find the real issue"
158
+ ✓ "Do NOT change production code - fix tests only"
159
+ ✓ "Don't refactor - minimal changes to make tests pass"
160
+ ```
161
+
162
+ ---
163
+
164
+ ### Implementation Subagent Template
165
+
166
+ ```markdown
167
+ You are implementing Task N from [plan-file].
168
+
169
+ Read that task carefully. Your job is to:
170
+
171
+ 1. Implement exactly what the task specifies
172
+ 2. Write tests (following TDD if task says to)
173
+ 3. Verify implementation works
174
+ 4. Commit your work
175
+ 5. Report back
176
+
177
+ Work from: [directory]
178
+
179
+ Report: What you implemented, what you tested, test results, files changed, any issues
180
+ ```
181
+
182
+ **Key elements:**
183
+
184
+ - References plan file for context
185
+ - Explicit steps to follow
186
+ - Specific output format
187
+ - Working directory specified
188
+
189
+ ---
190
+
191
+ ### Parallel Investigation Template
192
+
193
+ ```markdown
194
+ Fix the 3 failing tests in src/agents/agent-tool-abort.test.ts:
195
+
196
+ 1. "should abort tool with partial output capture" - expects 'interrupted at' in message
197
+ 2. "should handle mixed completed and aborted tools" - fast tool aborted instead of completed
198
+ 3. "should properly track pendingToolCount" - expects 3 results but gets 0
199
+
200
+ These are timing/race condition issues. Your task:
201
+
202
+ 1. Read the test file and understand what each test verifies
203
+ 2. Identify root cause - timing issues or actual bugs?
204
+ 3. Fix by:
205
+ - Replacing arbitrary timeouts with event-based waiting
206
+ - Fixing bugs in abort implementation if found
207
+ - Adjusting test expectations if testing changed behavior
208
+
209
+ Do NOT just increase timeouts - find the real issue.
210
+
211
+ Return: Summary of what you found and what you fixed.
212
+ ```
213
+
214
+ **Key elements:**
215
+
216
+ - Paste error messages and test names (full context)
217
+ - Hypothesis about root cause
218
+ - Clear fixing strategy
219
+ - Anti-pattern constraint ("Do NOT just increase timeouts")
220
+ - Expected return format
221
+
222
+ ---
223
+
224
+ ### Fix Subagent Template
225
+
226
+ ```markdown
227
+ Fix issues from code review: [list issues]
228
+
229
+ Context: [what was just implemented]
230
+
231
+ Issues to fix:
232
+
233
+ 1. [Issue from reviewer with file:line reference]
234
+ 2. [Issue from reviewer with file:line reference]
235
+
236
+ Fix these issues and commit. Report what you changed.
237
+ ```
238
+
239
+ **Key elements:**
240
+
241
+ - Specific issues from code review
242
+ - Context of original implementation
243
+ - Clear success criteria
244
+
245
+ ---
246
+
247
+ ## 4. Code Review Template Structure
248
+
249
+ ### Dispatcher Side (Requesting Review)
250
+
251
+ **1. Get git SHAs:**
252
+
253
+ ```bash
254
+ BASE_SHA=$(git rev-parse HEAD~1) # or origin/main
255
+ HEAD_SHA=$(git rev-parse HEAD)
256
+ ```
257
+
258
+ **2. Fill template placeholders:**
259
+
260
+ - `{WHAT_WAS_IMPLEMENTED}` - What you just built
261
+ - `{PLAN_OR_REQUIREMENTS}` - What it should do (reference plan file/section)
262
+ - `{BASE_SHA}` - Starting commit
263
+ - `{HEAD_SHA}` - Ending commit
264
+ - `{DESCRIPTION}` - Brief summary
265
+
266
+ **3. Dispatch superpowers:code-reviewer subagent** with filled template
267
+
268
+ ---
269
+
270
+ ### Code Reviewer Side (Template Output)
271
+
272
+ #### Strengths
273
+
274
+ [What's well done? Be specific with file:line references]
275
+
276
+ Example:
277
+
278
+ ```
279
+ - Clean database schema with proper migrations (db.ts:15-42)
280
+ - Comprehensive test coverage (18 tests, all edge cases)
281
+ - Good error handling with fallbacks (summarizer.ts:85-92)
282
+ ```
283
+
284
+ ---
285
+
286
+ #### Issues
287
+
288
+ ##### Critical (Must Fix)
289
+
290
+ [Bugs, security issues, data loss risks, broken functionality]
291
+
292
+ ##### Important (Should Fix)
293
+
294
+ [Architecture problems, missing features, poor error handling, test gaps]
295
+
296
+ ##### Minor (Nice to Have)
297
+
298
+ [Code style, optimization opportunities, documentation improvements]
299
+
300
+ **For each issue:**
301
+
302
+ - File:line reference
303
+ - What's wrong
304
+ - Why it matters
305
+ - How to fix (if not obvious)
306
+
307
+ Example:
308
+
309
+ ```
310
+ #### Important
311
+ 1. **Missing help text in CLI wrapper**
312
+ - File: index-conversations:1-31
313
+ - Issue: No --help flag, users won't discover --concurrency
314
+ - Fix: Add --help case with usage examples
315
+
316
+ 2. **Date validation missing**
317
+ - File: search.ts:25-27
318
+ - Issue: Invalid dates silently return no results
319
+ - Fix: Validate ISO format, throw error with example
320
+ ```
321
+
322
+ ---
323
+
324
+ #### Recommendations
325
+
326
+ [Improvements for code quality, architecture, or process]
327
+
328
+ ---
329
+
330
+ #### Assessment
331
+
332
+ **Ready to merge?** [Yes/No/With fixes]
333
+
334
+ **Reasoning:** [Technical assessment in 1-2 sentences]
335
+
336
+ Example:
337
+
338
+ ```
339
+ **Ready to merge: With fixes**
340
+
341
+ **Reasoning:** Core implementation is solid with good architecture and tests.
342
+ Important issues (help text, date validation) are easily fixed and don't affect
343
+ core functionality.
344
+ ```
345
+
346
+ ---
347
+
348
+ ### Review Checklist (Reviewer Uses This)
349
+
350
+ **Code Quality:**
351
+
352
+ - Clean separation of concerns?
353
+ - Proper error handling?
354
+ - Type safety (if applicable)?
355
+ - DRY principle followed?
356
+ - Edge cases handled?
357
+
358
+ **Architecture:**
359
+
360
+ - Sound design decisions?
361
+ - Scalability considerations?
362
+ - Performance implications?
363
+ - Security concerns?
364
+
365
+ **Testing:**
366
+
367
+ - Tests actually test logic (not mocks)?
368
+ - Edge cases covered?
369
+ - Integration tests where needed?
370
+ - All tests passing?
371
+
372
+ **Requirements:**
373
+
374
+ - All plan requirements met?
375
+ - Implementation matches spec?
376
+ - No scope creep?
377
+ - Breaking changes documented?
378
+
379
+ **Production Readiness:**
380
+
381
+ - Migration strategy (if schema changes)?
382
+ - Backward compatibility considered?
383
+ - Documentation complete?
384
+ - No obvious bugs?
385
+
386
+ ---
387
+
388
+ ## 5. Anti-Patterns and Red Flags
389
+
390
+ ### Subagent-Driven Development
391
+
392
+ **Never:**
393
+
394
+ - ❌ Skip code review between tasks
395
+ - ❌ Proceed with unfixed Critical issues
396
+ - ❌ Dispatch multiple implementation subagents in parallel (conflicts)
397
+ - ❌ Implement without reading plan task
398
+ - ❌ Try to fix subagent failures manually (context pollution)
399
+
400
+ **If subagent fails task:**
401
+
402
+ - ✓ Dispatch fix subagent with specific instructions
403
+ - ✓ Don't try to fix manually (context pollution)
404
+
405
+ ---
406
+
407
+ ### Dispatching Parallel Agents
408
+
409
+ **Common mistakes:**
410
+
411
+ ❌ **Too broad:** "Fix all the tests"
412
+ ✓ **Specific:** "Fix agent-tool-abort.test.ts"
413
+
414
+ ❌ **No context:** "Fix the race condition"
415
+ ✓ **Context:** Paste error messages and test names
416
+
417
+ ❌ **No constraints:** Agent might refactor everything
418
+ ✓ **Constraints:** "Do NOT change production code" or "Fix tests only"
419
+
420
+ ❌ **Vague output:** "Fix it"
421
+ ✓ **Specific:** "Return summary of root cause and changes"
422
+
423
+ **When NOT to parallelize:**
424
+
425
+ - Related failures (fix one might fix others)
426
+ - Need full context (understanding requires seeing entire system)
427
+ - Exploratory debugging (don't know what's broken yet)
428
+ - Shared state (agents would interfere)
429
+
430
+ ---
431
+
432
+ ### Requesting Code Review
433
+
434
+ **Never:**
435
+
436
+ - ❌ Skip review because "it's simple"
437
+ - ❌ Ignore Critical issues
438
+ - ❌ Proceed with unfixed Important issues
439
+ - ❌ Argue with valid technical feedback
440
+
441
+ **If reviewer wrong:**
442
+
443
+ - ✓ Push back with technical reasoning
444
+ - ✓ Show code/tests that prove it works
445
+ - ✓ Request clarification
446
+
447
+ ---
448
+
449
+ ### Code Reviewer Anti-Patterns
450
+
451
+ **DO:**
452
+
453
+ - ✓ Categorize by actual severity (not everything is Critical)
454
+ - ✓ Be specific (file:line, not vague)
455
+ - ✓ Explain WHY issues matter
456
+ - ✓ Acknowledge strengths
457
+ - ✓ Give clear verdict
458
+
459
+ **DON'T:**
460
+
461
+ - ❌ Say "looks good" without checking
462
+ - ❌ Mark nitpicks as Critical
463
+ - ❌ Give feedback on code you didn't review
464
+ - ❌ Be vague ("improve error handling")
465
+ - ❌ Avoid giving a clear verdict
466
+
467
+ ---
468
+
469
+ ## 6. Integration Between Patterns
470
+
471
+ ### Subagent-Driven Development Workflow
472
+
473
+ ```
474
+ 1. Load Plan
475
+ └─ Read plan file, create TodoWrite with all tasks
476
+
477
+ 2. For Each Task:
478
+ ├─ Dispatch implementation subagent
479
+ │ └─ Fresh context, follows TDD, commits work
480
+
481
+ ├─ Get git SHAs (before task, after task)
482
+
483
+ ├─ Dispatch code-reviewer subagent
484
+ │ └─ Reviews against plan requirements
485
+
486
+ ├─ Act on review feedback
487
+ │ ├─ Critical issues → Fix immediately
488
+ │ ├─ Important issues → Dispatch fix subagent
489
+ │ └─ Minor issues → Note for later
490
+
491
+ └─ Mark task complete in TodoWrite
492
+
493
+ 3. After All Tasks:
494
+ ├─ Dispatch final code-reviewer
495
+ │ └─ Reviews entire implementation
496
+
497
+ └─ Use finishing-a-development-branch skill
498
+ └─ Verify tests, present options, execute choice
499
+ ```
500
+
501
+ ---
502
+
503
+ ### Parallel Investigation Workflow
504
+
505
+ ```
506
+ 1. Multiple Failures Detected
507
+ └─ Identify independent problem domains
508
+
509
+ 2. Group by Domain
510
+ ├─ File A tests: Tool approval flow
511
+ ├─ File B tests: Batch completion behavior
512
+ └─ File C tests: Abort functionality
513
+
514
+ 3. Dispatch Parallel Agents
515
+ ├─ Agent 1: Fix File A (focused scope, specific errors)
516
+ ├─ Agent 2: Fix File B (focused scope, specific errors)
517
+ └─ Agent 3: Fix File C (focused scope, specific errors)
518
+
519
+ 4. Review and Integrate
520
+ ├─ Read each summary
521
+ ├─ Verify fixes don't conflict
522
+ ├─ Run full test suite
523
+ └─ Integrate all changes
524
+ ```
525
+
526
+ ---
527
+
528
+ ### Acting on Code Review Feedback
529
+
530
+ **Severity Tiers:**
531
+
532
+ **Critical (Must Fix):**
533
+
534
+ - Bugs, security issues, data loss risks, broken functionality
535
+ - **Action:** Fix immediately, re-review, don't proceed without fixing
536
+
537
+ **Important (Should Fix):**
538
+
539
+ - Architecture problems, missing features, poor error handling, test gaps
540
+ - **Action:** Dispatch fix subagent before next task
541
+
542
+ **Minor (Nice to Have):**
543
+
544
+ - Code style, optimization opportunities, documentation improvements
545
+ - **Action:** Note for later, don't block on these
546
+
547
+ **Example flow:**
548
+
549
+ ```
550
+ Reviewer returns:
551
+ Critical: None
552
+ Important: Missing progress indicators, Date validation missing
553
+ Minor: Magic number (100) for reporting interval
554
+
555
+ Action:
556
+ 1. Dispatch fix subagent: "Fix Important issues from review: [list]"
557
+ 2. Fix subagent commits changes
558
+ 3. (Optional) Quick re-review if fixes were complex
559
+ 4. Mark task complete, proceed to next task
560
+ 5. Note Minor issues for future cleanup
561
+ ```
562
+
563
+ ---
564
+
565
+ ## 7. Required Workflow Skills
566
+
567
+ ### Subagent-Driven Development Dependencies
568
+
569
+ **REQUIRED:**
570
+
571
+ - `writing-plans` - Creates the plan that this skill executes
572
+ - `requesting-code-review` - Review after each task
573
+ - `finishing-a-development-branch` - Complete development after all tasks
574
+
575
+ **Subagents must use:**
576
+
577
+ - `test-driven-development` - Subagents follow TDD for each task
578
+
579
+ **Alternative workflow:**
580
+
581
+ - `executing-plans` - Use for parallel session instead of same-session execution
582
+
583
+ ---
584
+
585
+ ## 8. Real-World Examples
586
+
587
+ ### Parallel Investigation (from Session 2025-10-03)
588
+
589
+ **Scenario:** 6 test failures across 3 files after major refactoring
590
+
591
+ **Failures:**
592
+
593
+ - agent-tool-abort.test.ts: 3 failures (timing issues)
594
+ - batch-completion-behavior.test.ts: 2 failures (tools not executing)
595
+ - tool-approval-race-conditions.test.ts: 1 failure (execution count = 0)
596
+
597
+ **Decision:** Independent domains - abort logic separate from batch completion separate from race conditions
598
+
599
+ **Dispatch:**
600
+
601
+ ```
602
+ Agent 1 → Fix agent-tool-abort.test.ts
603
+ Agent 2 → Fix batch-completion-behavior.test.ts
604
+ Agent 3 → Fix tool-approval-race-conditions.test.ts
605
+ ```
606
+
607
+ **Results:**
608
+
609
+ - Agent 1: Replaced timeouts with event-based waiting
610
+ - Agent 2: Fixed event structure bug (threadId in wrong place)
611
+ - Agent 3: Added wait for async tool execution to complete
612
+
613
+ **Integration:** All fixes independent, no conflicts, full suite green
614
+
615
+ **Time saved:** 3 problems solved in parallel vs sequentially
616
+
617
+ ---
618
+
619
+ ### Subagent-Driven Development Example
620
+
621
+ ```
622
+ Coordinator: I'm using Subagent-Driven Development to execute this plan.
623
+
624
+ [Load plan, create TodoWrite]
625
+
626
+ Task 1: Hook installation script
627
+
628
+ [Dispatch implementation subagent]
629
+ Subagent: Implemented install-hook with tests, 5/5 passing
630
+
631
+ [Get git SHAs, dispatch code-reviewer]
632
+ Reviewer: Strengths: Good test coverage. Issues: None. Ready.
633
+
634
+ [Mark Task 1 complete]
635
+
636
+ Task 2: Recovery modes
637
+
638
+ [Dispatch implementation subagent]
639
+ Subagent: Added verify/repair, 8/8 tests passing
640
+
641
+ [Dispatch code-reviewer]
642
+ Reviewer: Strengths: Solid. Issues (Important): Missing progress reporting
643
+
644
+ [Dispatch fix subagent]
645
+ Fix subagent: Added progress every 100 conversations
646
+
647
+ [Verify fix, mark Task 2 complete]
648
+
649
+ ...
650
+
651
+ [After all tasks]
652
+ [Dispatch final code-reviewer]
653
+ Final reviewer: All requirements met, ready to merge
654
+
655
+ Done!
656
+ ```
657
+
658
+ ---
659
+
660
+ ## 9. Key Quotes Worth Preserving
661
+
662
+ > **"Fresh subagent per task + review between tasks = high quality, fast iteration"**
663
+ > — subagent-driven-development/SKILL.md
664
+
665
+ > **"Dispatch one agent per independent problem domain. Let them work concurrently."**
666
+ > — dispatching-parallel-agents/SKILL.md
667
+
668
+ > **"Review early, review often."**
669
+ > — requesting-code-review/SKILL.md
670
+
671
+ > **"More subagent invocations cost tokens, but catching issues early is cheaper than debugging later."**
672
+ > — subagent-driven-development/SKILL.md (paraphrased from "Cost" section)
673
+
674
+ > **"Do NOT just increase timeouts - find the real issue."**
675
+ > — dispatching-parallel-agents/SKILL.md (example prompt constraint)
676
+
677
+ > **"Categorize by actual severity (not everything is Critical)"**
678
+ > — code-reviewer.md
679
+
680
+ > **"Be specific (file:line, not vague)"**
681
+ > — code-reviewer.md
682
+
683
+ > **"If subagent fails task: Dispatch fix subagent with specific instructions. Don't try to fix manually (context pollution)."**
684
+ > — subagent-driven-development/SKILL.md
685
+
686
+ ---
687
+
688
+ ## 10. Advantages Summary
689
+
690
+ ### Subagent-Driven Development
691
+
692
+ **vs. Manual execution:**
693
+
694
+ - Subagents follow TDD naturally
695
+ - Fresh context per task (no confusion)
696
+ - Parallel-safe (subagents don't interfere)
697
+
698
+ **vs. Executing Plans:**
699
+
700
+ - Same session (no handoff)
701
+ - Continuous progress (no waiting)
702
+ - Review checkpoints automatic
703
+
704
+ **Cost tradeoff:**
705
+
706
+ - More subagent invocations
707
+ - But catches issues early (cheaper than debugging later)
708
+
709
+ ---
710
+
711
+ ### Dispatching Parallel Agents
712
+
713
+ **Benefits:**
714
+
715
+ 1. **Parallelization** - Multiple investigations happen simultaneously
716
+ 2. **Focus** - Each agent has narrow scope, less context to track
717
+ 3. **Independence** - Agents don't interfere with each other
718
+ 4. **Speed** - 3 problems solved in time of 1
719
+
720
+ **Verification after agents return:**
721
+
722
+ 1. Review each summary - Understand what changed
723
+ 2. Check for conflicts - Did agents edit same code?
724
+ 3. Run full suite - Verify all fixes work together
725
+ 4. Spot check - Agents can make systematic errors
726
+
727
+ ---
728
+
729
+ ### Requesting Code Review
730
+
731
+ **Benefits:**
732
+
733
+ - Catches issues before they compound
734
+ - Fresh perspective on implementation
735
+ - Validates against requirements
736
+ - Explicit severity tiers guide priority
737
+ - Clear verdict (Yes/No/With fixes)
738
+
739
+ **Integration:**
740
+
741
+ - Subagent-Driven Development: Review after EACH task
742
+ - Executing Plans: Review after each batch (3 tasks)
743
+ - Ad-Hoc Development: Review before merge, when stuck
744
+
745
+ ---
746
+
747
+ ## 11. Decision Tree: Which Pattern to Use?
748
+
749
+ ```
750
+ What are you doing?
751
+ ├─ Executing implementation plan?
752
+ │ ├─ Yes → Subagent-Driven Development
753
+ │ │ ├─ Fresh subagent per task
754
+ │ │ ├─ Code review after each task
755
+ │ │ └─ Same session, continuous progress
756
+ │ │
757
+ │ └─ No → Continue...
758
+
759
+ ├─ Multiple independent failures?
760
+ │ ├─ Yes (3+) → Dispatching Parallel Agents
761
+ │ │ ├─ One agent per problem domain
762
+ │ │ ├─ Focused prompts with constraints
763
+ │ │ └─ Review and integrate results
764
+ │ │
765
+ │ └─ No → Continue...
766
+
767
+ └─ Completed task/feature?
768
+ └─ Yes → Requesting Code Review
769
+ ├─ Get git SHAs
770
+ ├─ Dispatch code-reviewer subagent
771
+ ├─ Fix Critical/Important issues
772
+ └─ Proceed or merge
773
+ ```
774
+
775
+ ---
776
+
777
+ ## 12. Prompt Templates Quick Reference
778
+
779
+ ### Implementation Subagent
780
+
781
+ ```
782
+ You are implementing Task N from [plan-file].
783
+ Read that task carefully. Your job is to:
784
+ 1. Implement exactly what the task specifies
785
+ 2. Write tests (following TDD if task says to)
786
+ 3. Verify implementation works
787
+ 4. Commit your work
788
+ 5. Report back
789
+
790
+ Work from: [directory]
791
+ Report: What you implemented, what you tested, test results, files changed, any issues
792
+ ```
793
+
794
+ ### Parallel Investigation Subagent
795
+
796
+ ```
797
+ Fix the 3 failing tests in [test-file]:
798
+ [Paste test names and error messages]
799
+
800
+ Your task:
801
+ 1. Read the test file and understand what each test verifies
802
+ 2. Identify root cause
803
+ 3. Fix by: [strategy]
804
+
805
+ Do NOT [anti-pattern constraint]
806
+ Return: Summary of what you found and what you fixed.
807
+ ```
808
+
809
+ ### Fix Subagent
810
+
811
+ ```
812
+ Fix issues from code review: [list issues]
813
+ Context: [what was just implemented]
814
+ Issues to fix:
815
+ 1. [Issue with file:line]
816
+ 2. [Issue with file:line]
817
+
818
+ Fix these issues and commit. Report what you changed.
819
+ ```
820
+
821
+ ### Code Reviewer Subagent
822
+
823
+ ```
824
+ Review {WHAT_WAS_IMPLEMENTED}
825
+ Compare against {PLAN_OR_REQUIREMENTS}
826
+ Git range: {BASE_SHA}..{HEAD_SHA}
827
+
828
+ Output:
829
+ - Strengths (specific, with file:line)
830
+ - Issues (Critical/Important/Minor with file:line, why, how to fix)
831
+ - Recommendations
832
+ - Assessment (Ready to merge? Yes/No/With fixes + reasoning)
833
+ ```
834
+
835
+ ---
836
+
837
+ ## 13. Context Pollution Prevention
838
+
839
+ **Problem:** Coordinator tries to fix subagent failures manually, polluting context with failed attempts.
840
+
841
+ **Solution:** Always dispatch fix subagent instead.
842
+
843
+ **Pattern:**
844
+
845
+ ```
846
+ Subagent fails task → Review failure report → Dispatch fix subagent with:
847
+ - What failed
848
+ - Why it failed (from report)
849
+ - Specific fix instructions
850
+ - Constraints to prevent same failure
851
+ ```
852
+
853
+ **Why it works:**
854
+
855
+ - Fix subagent has fresh context
856
+ - Coordinator maintains high-level coordination role
857
+ - No accumulated debugging cruft in coordinator context
858
+ - Parallel-safe (fix subagent doesn't interfere with other work)
859
+
860
+ ---
861
+
862
+ ## 14. File Reservation (Not in Source Docs)
863
+
864
+ **Note:** The analyzed skills don't mention file reservation, but this is a common coordination primitive for multi-agent systems.
865
+
866
+ **When it would apply:**
867
+
868
+ - Parallel agents editing potentially overlapping files
869
+ - Prevention of merge conflicts
870
+ - Coordination of shared state mutations
871
+
872
+ **Integration point:**
873
+
874
+ - Would fit in "Dispatching Parallel Agents" when agents might touch overlapping code
875
+ - Verification step: "Check for conflicts - Did agents edit same code?"
876
+
877
+ **For opencode-swarm-plugin:** Agent Mail has file reservation (`agentmail_reserve`, `agentmail_release`). This pattern could enhance parallel dispatch safety.
878
+
879
+ ---
880
+
881
+ ## END ANALYSIS
882
+
883
+ **Key takeaways for opencode-swarm-plugin:**
884
+
885
+ 1. **Adopt fresh subagent per task** - Prevents context pollution, enables TDD naturally
886
+ 2. **Mandatory code review between tasks** - Catches issues early, explicit severity tiers
887
+ 3. **Parallelize at 3+ independent failures** - Clear heuristic for when to dispatch concurrent agents
888
+ 4. **Focused agent prompts** - Self-contained, specific output, constraints prevent scope creep
889
+ 5. **Never skip review because "it's simple"** - Simple tasks can have subtle issues
890
+ 6. **Fix subagents instead of manual fixes** - Preserves coordinator context clarity
891
+ 7. **Explicit severity tiers guide priority** - Critical blocks, Important before next task, Minor noted
892
+ 8. **Same session vs parallel session** - Subagent-driven stays in session, executing-plans spawns parallel
893
+
894
+ **Patterns to integrate:**
895
+
896
+ - ✓ Fresh subagent per task (already in swarm worker pattern)
897
+ - ✓ Code review after each task (add to swarm_complete?)
898
+ - ✓ Parallel dispatch at 3+ failures (add to debug-plus command)
899
+ - ✓ Severity-based issue triage (integrate with UBS scan results)
900
+ - ✓ Fix subagent pattern (add to swarm toolkit)