opencode-swarm-plugin 0.23.6 → 0.24.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,470 @@
1
+ # Context Recovery Manual Test Scenario
2
+
3
+ ## Overview
4
+
5
+ This test scenario verifies that the swarm coordination system can survive context death and recover from checkpoints. It proves that work-in-progress state is preserved across session boundaries, enabling agents to resume work after catastrophic context loss.
6
+
7
+ **What this tests:**
8
+ - Automatic checkpoint creation at progress milestones (25%, 50%, 75%)
9
+ - State persistence to swarm-mail event store
10
+ - Recovery mechanism that restores agent state
11
+ - Continuity of work across session boundaries
12
+
13
+ **Success criteria:**
14
+ - Agent can resume work from exact state before context loss
15
+ - All file modifications are tracked
16
+ - Progress percentage is preserved
17
+ - Coordinator context and directives are restored
18
+
19
+ ---
20
+
21
+ ## Prerequisites
22
+
23
+ ### Required Setup
24
+ 1. **Project with swarm-mail initialized**
25
+ ```bash
26
+ cd /path/to/your/project
27
+ # Ensure swarm-mail database exists
28
+ ```
29
+
30
+ 2. **OpenCode Swarm Plugin installed**
31
+ ```bash
32
+ npm install opencode-swarm-plugin
33
+ # or
34
+ bun add opencode-swarm-plugin
35
+ ```
36
+
37
+ 3. **Test bead structure**
38
+ - Epic bead with at least one subtask
39
+ - Example:
40
+ ```bash
41
+ beads_create_epic(
42
+ epic_title: "Test Context Recovery",
43
+ subtasks: [
44
+ { title: "Modify test files", files: ["test/file1.ts", "test/file2.ts"] }
45
+ ]
46
+ )
47
+ ```
48
+
49
+ 4. **Two terminal windows/sessions**
50
+ - Session A: For initial work (will be killed)
51
+ - Session B: For recovery
52
+
53
+ ---
54
+
55
+ ## Test Procedure
56
+
57
+ ### Phase 1: Start Initial Work Session
58
+
59
+ **Session A - Terminal 1**
60
+
61
+ 1. **Initialize swarm mail**
62
+ ```typescript
63
+ swarmmail_init(
64
+ project_path: "/absolute/path/to/project",
65
+ task_description: "bd-123.1: Test context recovery feature"
66
+ )
67
+ ```
68
+
69
+ **Expected result:**
70
+ ```json
71
+ {
72
+ "success": true,
73
+ "data": {
74
+ "agent_name": "BlueLake", // Random agent name
75
+ "project_key": "/absolute/path/to/project"
76
+ }
77
+ }
78
+ ```
79
+
80
+ **Verify:**
81
+ - ✅ Agent name assigned (e.g., "BlueLake")
82
+ - ✅ Project key matches your path
83
+
84
+ 2. **Reserve files for work**
85
+ ```typescript
86
+ swarmmail_reserve(
87
+ paths: ["test/file1.ts", "test/file2.ts"],
88
+ reason: "bd-123.1: Context recovery test",
89
+ ttl_seconds: 3600
90
+ )
91
+ ```
92
+
93
+ **Expected result:**
94
+ ```json
95
+ {
96
+ "success": true,
97
+ "data": {
98
+ "reservation_ids": [1, 2],
99
+ "agent_name": "BlueLake",
100
+ "expires_at": 1234567890
101
+ }
102
+ }
103
+ ```
104
+
105
+ **Verify:**
106
+ - ✅ Reservation IDs returned
107
+ - ✅ Files locked to this agent
108
+
109
+ 3. **Make some file modifications**
110
+ ```bash
111
+ # Modify test/file1.ts
112
+ echo "// First change" >> test/file1.ts
113
+ ```
114
+
115
+ **Expected result:**
116
+ - File modified on disk
117
+
118
+ **Verify:**
119
+ - ✅ File contains new content
120
+
121
+ 4. **Report 50% progress (triggers auto-checkpoint)**
122
+ ```typescript
123
+ swarm_progress(
124
+ project_key: "/absolute/path/to/project",
125
+ agent_name: "BlueLake",
126
+ bead_id: "bd-123.1",
127
+ status: "in_progress",
128
+ progress_percent: 50,
129
+ message: "Completed first file modification",
130
+ files_touched: ["test/file1.ts"]
131
+ )
132
+ ```
133
+
134
+ **Expected result:**
135
+ ```json
136
+ {
137
+ "success": true,
138
+ "data": {
139
+ "checkpoint_created": true,
140
+ "message": "Progress reported and checkpoint saved"
141
+ }
142
+ }
143
+ ```
144
+
145
+ **Verify:**
146
+ - ✅ Checkpoint creation confirmed
147
+ - ✅ Progress percentage is 50
148
+ - ✅ Files touched recorded
149
+
150
+ 5. **Verify checkpoint was created in swarm-mail**
151
+ ```typescript
152
+ // Query the event store directly (if you have access)
153
+ // Or check via beads metadata
154
+ beads_query(status: "in_progress")
155
+ ```
156
+
157
+ **Expected result:**
158
+ - Bead shows 50% progress
159
+ - Checkpoint event exists in event store
160
+
161
+ **Verify:**
162
+ - ✅ Checkpoint event type: "swarm_checkpoint_created"
163
+ - ✅ Recovery data includes: epic_id, bead_id, files, progress_percent, files_modified
164
+
165
+ ---
166
+
167
+ ### Phase 2: Simulate Context Death
168
+
169
+ **Session A - Terminal 1**
170
+
171
+ 6. **Kill the session abruptly**
172
+ ```bash
173
+ # Press Ctrl+C or kill the terminal
174
+ # DO NOT gracefully close - simulate crash
175
+ ```
176
+
177
+ **Expected result:**
178
+ - Session terminates immediately
179
+ - No cleanup runs
180
+
181
+ **Verify:**
182
+ - ✅ Session ended ungracefully
183
+ - ✅ Agent did NOT release reservations
184
+ - ✅ Work state is "frozen" in event store
185
+
186
+ ---
187
+
188
+ ### Phase 3: Recover State in New Session
189
+
190
+ **Session B - Terminal 2**
191
+
192
+ 7. **Start fresh session (simulate new agent)**
193
+ ```typescript
194
+ swarmmail_init(
195
+ project_path: "/absolute/path/to/project",
196
+ task_description: "Recovering from context death"
197
+ )
198
+ ```
199
+
200
+ **Expected result:**
201
+ ```json
202
+ {
203
+ "success": true,
204
+ "data": {
205
+ "agent_name": "CrimsonPeak", // DIFFERENT agent name
206
+ "project_key": "/absolute/path/to/project"
207
+ }
208
+ }
209
+ ```
210
+
211
+ **Verify:**
212
+ - ✅ New agent name (different from Session A)
213
+ - ✅ Fresh session started
214
+
215
+ 8. **Attempt recovery**
216
+ ```typescript
217
+ swarm_recover(
218
+ project_key: "/absolute/path/to/project",
219
+ bead_id: "bd-123.1"
220
+ )
221
+ ```
222
+
223
+ **Expected result:**
224
+ ```json
225
+ {
226
+ "success": true,
227
+ "data": {
228
+ "recovered": true,
229
+ "checkpoint": {
230
+ "epic_id": "bd-123",
231
+ "bead_id": "bd-123.1",
232
+ "strategy": "file-based",
233
+ "files": ["test/file1.ts", "test/file2.ts"],
234
+ "recovery": {
235
+ "last_checkpoint": 1234567890,
236
+ "files_modified": ["test/file1.ts"],
237
+ "progress_percent": 50,
238
+ "last_message": "Completed first file modification"
239
+ },
240
+ "directives": {
241
+ "shared_context": "Test context recovery feature",
242
+ "coordinator_notes": "Resume from 50% completion"
243
+ }
244
+ },
245
+ "message": "State recovered from checkpoint at 50%"
246
+ }
247
+ }
248
+ ```
249
+
250
+ **Verify:**
251
+ - ✅ Recovery successful
252
+ - ✅ Progress is 50% (matches last checkpoint)
253
+ - ✅ Files modified list is correct
254
+ - ✅ Last message preserved
255
+ - ✅ Strategy and directives restored
256
+
257
+ 9. **Verify file reservations were transferred**
258
+ ```typescript
259
+ // Check inbox for reservation status
260
+ swarmmail_inbox(limit: 5)
261
+ ```
262
+
263
+ **Expected result:**
264
+ - Reservations still exist (orphaned from BlueLake)
265
+ - OR recovery automatically transferred ownership to CrimsonPeak
266
+
267
+ **Verify:**
268
+ - ✅ Files are either still reserved or available for new reservation
269
+ - ✅ No reservation conflicts
270
+
271
+ 10. **Resume work with recovered state**
272
+ ```bash
273
+ # Modify test/file2.ts (continue where Session A left off)
274
+ echo "// Second change" >> test/file2.ts
275
+ ```
276
+
277
+ **Expected result:**
278
+ - File modified successfully
279
+
280
+ **Verify:**
281
+ - ✅ Agent can continue work
282
+ - ✅ File modifications build on previous state
283
+
284
+ 11. **Report completion**
285
+ ```typescript
286
+ swarm_complete(
287
+ project_key: "/absolute/path/to/project",
288
+ agent_name: "CrimsonPeak",
289
+ bead_id: "bd-123.1",
290
+ summary: "Completed context recovery test - survived session death",
291
+ files_touched: ["test/file1.ts", "test/file2.ts"]
292
+ )
293
+ ```
294
+
295
+ **Expected result:**
296
+ ```json
297
+ {
298
+ "success": true,
299
+ "data": {
300
+ "bead_closed": true,
301
+ "reservations_released": true,
302
+ "ubs_scan_passed": true
303
+ }
304
+ }
305
+ ```
306
+
307
+ **Verify:**
308
+ - ✅ Bead marked complete
309
+ - ✅ Reservations released
310
+ - ✅ All files touched recorded (both sessions combined)
311
+
312
+ ---
313
+
314
+ ## Verification Checklist
315
+
316
+ ### Checkpoint Creation
317
+ - [ ] Auto-checkpoint triggered at 50% progress
318
+ - [ ] Checkpoint includes epic_id, bead_id, strategy
319
+ - [ ] Files list preserved
320
+ - [ ] Progress percentage stored
321
+ - [ ] Files modified list accurate
322
+ - [ ] Last message captured
323
+
324
+ ### Recovery Mechanism
325
+ - [ ] New session can query checkpoint by bead_id
326
+ - [ ] All checkpoint data restored correctly
327
+ - [ ] Directives and context preserved
328
+ - [ ] Recovery returns actionable state object
329
+
330
+ ### State Continuity
331
+ - [ ] Work can resume from exact checkpoint state
332
+ - [ ] File modifications from Session A are visible
333
+ - [ ] Progress percentage matches last checkpoint (50%)
334
+ - [ ] Completion acknowledges full file list (both sessions)
335
+
336
+ ### Edge Cases
337
+ - [ ] Recovery fails gracefully if no checkpoint exists
338
+ - [ ] Recovery handles multiple checkpoints (returns latest)
339
+ - [ ] Orphaned reservations don't block recovery
340
+ - [ ] Recovery works across different agent names
341
+
342
+ ---
343
+
344
+ ## Expected Failure Modes (Negative Testing)
345
+
346
+ ### Test 1: Recovery with No Checkpoint
347
+ ```typescript
348
+ swarm_recover(
349
+ project_key: "/path/to/project",
350
+ bead_id: "bd-999.1" // Non-existent bead
351
+ )
352
+ ```
353
+
354
+ **Expected result:**
355
+ ```json
356
+ {
357
+ "success": false,
358
+ "error": "No checkpoint found for bead bd-999.1"
359
+ }
360
+ ```
361
+
362
+ ### Test 2: Recovery Before Any Progress
363
+ ```typescript
364
+ // Create bead but never report progress
365
+ swarm_recover(
366
+ project_key: "/path/to/project",
367
+ bead_id: "bd-123.2"
368
+ )
369
+ ```
370
+
371
+ **Expected result:**
372
+ ```json
373
+ {
374
+ "success": false,
375
+ "error": "No checkpoint found - agent never reported progress"
376
+ }
377
+ ```
378
+
379
+ ### Test 3: Manual Checkpoint Creation
380
+ ```typescript
381
+ // Agent can force checkpoint at any time
382
+ swarm_checkpoint(
383
+ project_key: "/path/to/project",
384
+ bead_id: "bd-123.1",
385
+ checkpoint_data: {
386
+ progress_percent: 33,
387
+ files_modified: ["test/file1.ts"],
388
+ message: "Manual checkpoint before risky operation"
389
+ }
390
+ )
391
+ ```
392
+
393
+ **Expected result:**
394
+ ```json
395
+ {
396
+ "success": true,
397
+ "data": {
398
+ "checkpoint_id": 42,
399
+ "message": "Manual checkpoint created"
400
+ }
401
+ }
402
+ ```
403
+
404
+ ---
405
+
406
+ ## Troubleshooting
407
+
408
+ ### Issue: Recovery returns empty checkpoint
409
+ **Cause:** Checkpoint event not committed to event store
410
+ **Fix:** Verify `swarm_progress` was called with `progress_percent >= 25`
411
+
412
+ ### Issue: Files modified in Session A not visible in Session B
413
+ **Cause:** File changes not committed to git or filesystem
414
+ **Fix:** Ensure file writes are flushed before killing session
415
+
416
+ ### Issue: Reservation conflicts after recovery
417
+ **Cause:** Orphaned reservations from dead agent
418
+ **Fix:** Implement TTL-based reservation expiry or manual release by project_key
419
+
420
+ ### Issue: Multiple checkpoints confuse recovery
421
+ **Cause:** Recovery not selecting latest checkpoint
422
+ **Fix:** Verify recovery queries `ORDER BY timestamp DESC LIMIT 1`
423
+
424
+ ---
425
+
426
+ ## Advanced Scenarios
427
+
428
+ ### Scenario A: Coordinator Death
429
+ 1. Coordinator spawns 5 worker agents
430
+ 2. Coordinator dies at 60% overall completion
431
+ 3. New coordinator recovers state for all workers
432
+ 4. Workers continue reporting to new coordinator
433
+
434
+ ### Scenario B: Cascading Recovery
435
+ 1. Worker A checkpoints at 50%
436
+ 2. Worker A dies
437
+ 3. Worker B recovers Worker A's state
438
+ 4. Worker B checkpoints at 75%
439
+ 5. Worker B dies
440
+ 6. Worker C recovers Worker B's state (which includes Worker A's progress)
441
+
442
+ ### Scenario C: Partial File Reservation
443
+ 1. Agent reserves 10 files
444
+ 2. Modifies 3 files
445
+ 3. Dies at 30%
446
+ 4. Recovery agent only needs to work on remaining 7 files
447
+
448
+ ---
449
+
450
+ ## Success Metrics
451
+
452
+ | Metric | Target | Actual |
453
+ |--------|--------|--------|
454
+ | Recovery accuracy | 100% state match | _____ |
455
+ | Time to recover | < 5 seconds | _____ |
456
+ | Data loss | 0 bytes | _____ |
457
+ | Checkpoint overhead | < 100ms per checkpoint | _____ |
458
+ | Storage per checkpoint | < 10KB | _____ |
459
+
460
+ ---
461
+
462
+ ## Conclusion
463
+
464
+ This manual test proves that:
465
+ 1. ✅ Agents can survive catastrophic context loss
466
+ 2. ✅ Work state is preserved in event-sourced storage
467
+ 3. ✅ Recovery is deterministic and accurate
468
+ 4. ✅ Multi-session workflows are possible
469
+
470
+ **Sign-off:** If all verification checkboxes are marked and success metrics met, the context recovery feature is production-ready.
@@ -10,10 +10,29 @@ $ARGUMENTS
10
10
 
11
11
  ## Flags (parse from task above)
12
12
 
13
+ ### Planning Modes
14
+
15
+ - `--fast` - Skip brainstorming, go straight to decomposition
16
+ - `--auto` - Use best recommendations, minimal questions
17
+ - `--confirm-only` - Show decomposition, single yes/no, then execute
18
+ - (default) - Full Socratic planning with questions and alternatives
19
+
20
+ ### Workflow Options
21
+
13
22
  - `--to-main` - Push directly to main, skip PR
14
23
  - `--no-sync` - Skip mid-task context sharing
15
24
 
16
- **Default: Feature branch + PR with context sync.**
25
+ **Defaults: Socratic planning, feature branch + PR, context sync enabled.**
26
+
27
+ ### Example Usage
28
+
29
+ ```bash
30
+ /swarm "task description" # Full Socratic (default)
31
+ /swarm --fast "task description" # Skip brainstorming
32
+ /swarm --auto "task description" # Auto-select, minimal Q&A
33
+ /swarm --confirm-only "task" # Show plan, yes/no only
34
+ /swarm --fast --to-main "quick fix" # Fast mode + push to main
35
+ ```
17
36
 
18
37
  ## MANDATORY: Swarm Mail
19
38
 
@@ -126,11 +145,61 @@ git checkout -b swarm/<short-task-name>
126
145
  git push -u origin HEAD
127
146
  ```
128
147
 
129
- ### 4. Decompose Task (DELEGATE TO SUBAGENT)
148
+ ### 4. Interactive Planning (MANDATORY)
149
+
150
+ **Parse planning mode from flags:**
151
+
152
+ - `--fast` → mode="fast"
153
+ - `--auto` → mode="auto"
154
+ - `--confirm-only` → mode="confirm-only"
155
+ - No flag → mode="socratic" (default)
156
+
157
+ **Use swarm_plan_interactive for ALL planning:**
158
+
159
+ ```bash
160
+ # Start interactive planning session
161
+ swarm_plan_interactive(
162
+ task="<task description>",
163
+ mode="socratic", # or "fast", "auto", "confirm-only"
164
+ context="<synthesized knowledge from step 2>",
165
+ max_subtasks=5
166
+ )
167
+ ```
168
+
169
+ **Multi-turn conversation flow:**
170
+
171
+ The tool returns:
172
+
173
+ ```json
174
+ {
175
+ "ready_to_decompose": false, // or true when planning complete
176
+ "follow_up": "What approach do you prefer: A) file-based or B) feature-based?",
177
+ "options": ["A) File-based...", "B) Feature-based..."],
178
+ "recommendation": "I recommend A because..."
179
+ }
180
+ ```
181
+
182
+ **Continue conversation until ready_to_decompose=true:**
183
+
184
+ ```bash
185
+ # User responds to follow-up question
186
+ # You call swarm_plan_interactive again with:
187
+ swarm_plan_interactive(
188
+ task="<same task>",
189
+ mode="socratic",
190
+ context="<synthesized knowledge>",
191
+ user_response="A - file-based approach"
192
+ )
193
+
194
+ # Repeat until ready_to_decompose=true
195
+ # Then tool returns final decomposition prompt
196
+ ```
197
+
198
+ **When ready_to_decompose=true:**
130
199
 
131
200
  > **⚠️ CRITICAL: Context Preservation**
132
201
  >
133
- > **DO NOT decompose inline in the coordinator thread.** This consumes massive context with file reading, CASS queries, and reasoning. You will hit context limits on long swarms.
202
+ > **DO NOT decompose inline in the coordinator thread.** This consumes massive context with file reading, CASS queries, and reasoning.
134
203
  >
135
204
  > **ALWAYS delegate to a `swarm/planner` subagent** that returns only the validated BeadTree JSON.
136
205
 
@@ -138,11 +207,8 @@ git push -u origin HEAD
138
207
 
139
208
  ```bash
140
209
  # This pollutes your main thread context
141
- swarm_select_strategy(task="<the task>")
142
- swarm_plan_prompt(task="<the task>", ...)
143
210
  # ... you reason about decomposition inline ...
144
211
  # ... context fills with file contents, analysis ...
145
- swarm_validate_decomposition(response="...")
146
212
  ```
147
213
 
148
214
  **✅ Do this (delegate to subagent):**
@@ -151,36 +217,42 @@ swarm_validate_decomposition(response="...")
151
217
  # 1. Create planning bead
152
218
  beads_create(title="Plan: <task>", type="task", description="Decompose into subtasks")
153
219
 
154
- # 2. Delegate to swarm/planner subagent
220
+ # 2. Get final prompt from swarm_plan_interactive (when ready_to_decompose=true)
221
+ # final_prompt = <from last swarm_plan_interactive call>
222
+
223
+ # 3. Delegate to swarm/planner subagent
155
224
  Task(
156
225
  subagent_type="swarm/planner",
157
226
  description="Decompose task: <task>",
158
227
  prompt="
159
228
  You are a swarm planner. Generate a BeadTree for this task.
160
229
 
161
- ## Task
162
- <task description>
163
-
164
- ## Synthesized Context
165
- <from knowledge gathering step 2>
230
+ <final_prompt from swarm_plan_interactive>
166
231
 
167
232
  ## Instructions
168
- 1. Use swarm_select_strategy(task=\"...\")
169
- 2. Use swarm_plan_prompt(task=\"...\", max_subtasks=5, query_cass=true)
170
- 3. Reason about decomposition strategy
171
- 4. Generate BeadTree JSON
172
- 5. Validate with swarm_validate_decomposition
173
- 6. Return ONLY the validated BeadTree JSON (no analysis)
233
+ 1. Reason about decomposition strategy
234
+ 2. Generate BeadTree JSON
235
+ 3. Validate with swarm_validate_decomposition
236
+ 4. Return ONLY the validated BeadTree JSON (no analysis)
174
237
 
175
238
  Output: Valid BeadTree JSON only.
176
239
  "
177
240
  )
178
241
 
179
- # 3. Subagent returns validated JSON, parse it
242
+ # 4. Subagent returns validated JSON, parse it
180
243
  # beadTree = <result from subagent>
181
244
  ```
182
245
 
183
- **Why?**
246
+ **Planning Mode Behavior:**
247
+
248
+ | Mode | Questions | User Input | Confirmation |
249
+ | --------------- | --------- | ---------- | ------------ |
250
+ | `socratic` | Multiple | Yes | Yes |
251
+ | `fast` | None | No | Yes |
252
+ | `auto` | Minimal | Rare | No |
253
+ | `confirm-only` | None | Yes (1x) | Yes (1x) |
254
+
255
+ **Why delegate?**
184
256
 
185
257
  - Main thread stays clean (only receives final JSON)
186
258
  - Subagent context is disposable (garbage collected after planning)