opencode-swarm-plugin 0.44.2 → 0.45.1

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 (43) hide show
  1. package/README.md +277 -54
  2. package/bin/swarm.ts +156 -29
  3. package/dist/bin/swarm.js +125212 -0
  4. package/dist/decision-trace-integration.d.ts +204 -0
  5. package/dist/decision-trace-integration.d.ts.map +1 -0
  6. package/dist/hive.d.ts.map +1 -1
  7. package/dist/hive.js +9 -9
  8. package/dist/index.d.ts +32 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +535 -27
  11. package/dist/plugin.js +295 -27
  12. package/dist/query-tools.d.ts +20 -12
  13. package/dist/query-tools.d.ts.map +1 -1
  14. package/dist/swarm-decompose.d.ts +4 -4
  15. package/dist/swarm-decompose.d.ts.map +1 -1
  16. package/dist/swarm-prompts.d.ts.map +1 -1
  17. package/dist/swarm-prompts.js +220 -22
  18. package/dist/swarm-review.d.ts.map +1 -1
  19. package/dist/swarm-signature.d.ts +106 -0
  20. package/dist/swarm-signature.d.ts.map +1 -0
  21. package/dist/swarm-strategies.d.ts +16 -3
  22. package/dist/swarm-strategies.d.ts.map +1 -1
  23. package/dist/swarm.d.ts +4 -2
  24. package/dist/swarm.d.ts.map +1 -1
  25. package/examples/commands/swarm.md +745 -0
  26. package/examples/plugin-wrapper-template.ts +2892 -0
  27. package/examples/skills/hive-workflow/SKILL.md +212 -0
  28. package/examples/skills/skill-creator/SKILL.md +223 -0
  29. package/examples/skills/swarm-coordination/SKILL.md +292 -0
  30. package/global-skills/cli-builder/SKILL.md +344 -0
  31. package/global-skills/cli-builder/references/advanced-patterns.md +244 -0
  32. package/global-skills/learning-systems/SKILL.md +644 -0
  33. package/global-skills/skill-creator/LICENSE.txt +202 -0
  34. package/global-skills/skill-creator/SKILL.md +352 -0
  35. package/global-skills/skill-creator/references/output-patterns.md +82 -0
  36. package/global-skills/skill-creator/references/workflows.md +28 -0
  37. package/global-skills/swarm-coordination/SKILL.md +995 -0
  38. package/global-skills/swarm-coordination/references/coordinator-patterns.md +235 -0
  39. package/global-skills/swarm-coordination/references/strategies.md +138 -0
  40. package/global-skills/system-design/SKILL.md +213 -0
  41. package/global-skills/testing-patterns/SKILL.md +430 -0
  42. package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +586 -0
  43. package/package.json +6 -3
package/README.md CHANGED
@@ -446,78 +446,211 @@ swarm migrate # Migrate from legacy PGLite to libSQL
446
446
  swarm version # Show version info
447
447
  ```
448
448
 
449
- ### Logging & Observability
449
+ ### Observability Commands
450
450
 
451
- Structured Pino logging with daily rotation:
451
+ **swarm query** - SQL analytics with presets
452
452
 
453
453
  ```bash
454
- # Enable pretty logging during development
455
- SWARM_LOG_PRETTY=1 opencode
454
+ # Execute custom SQL query against event store
455
+ swarm query --sql "SELECT * FROM events WHERE type='worker_spawned' LIMIT 10"
456
456
 
457
- # Query logs (aliases: log/logs)
458
- swarm log # Tail recent logs
459
- swarm logs compaction # Filter by module
460
- swarm log --level warn # Filter by level (warn+)
461
- swarm log --since 1h # Last hour
462
- swarm log --json | jq # Pipe to jq for analysis
457
+ # Use preset query (10+ presets available)
458
+ swarm query --preset failed_decompositions
459
+ swarm query --preset duration_by_strategy
460
+ swarm query --preset file_conflicts
461
+ swarm query --preset worker_success_rate
462
+ swarm query --preset review_rejections
463
+ swarm query --preset blocked_tasks
464
+ swarm query --preset agent_activity
465
+ swarm query --preset event_frequency
466
+ swarm query --preset error_patterns
467
+ swarm query --preset compaction_stats
468
+
469
+ # Output formats
470
+ swarm query --preset failed_decompositions --format table # Default
471
+ swarm query --preset duration_by_strategy --format csv
472
+ swarm query --preset file_conflicts --format json
463
473
  ```
464
474
 
465
- **Log files:** `~/.config/swarm-tools/logs/`
466
- - `swarm.1log`, `swarm.2log`, ... (main logs)
467
- - `compaction.1log`, ... (module-specific)
468
- - Daily rotation, 14-day retention
475
+ **swarm dashboard** - Live terminal UI
476
+
477
+ ```bash
478
+ # Launch dashboard (auto-refresh every 1s)
479
+ swarm dashboard
480
+
481
+ # Focus on specific epic
482
+ swarm dashboard --epic mjmas3zxlmg
483
+
484
+ # Custom refresh rate (milliseconds)
485
+ swarm dashboard --refresh 2000
486
+ ```
469
487
 
470
- ### Analytics & Debugging
488
+ **Dashboard shows:**
489
+ - Active workers and their current tasks
490
+ - Progress bars for in-progress work
491
+ - File reservations (who owns what)
492
+ - Recent messages between agents
493
+ - Error alerts
471
494
 
472
- Query event store for insights and debugging:
495
+ **swarm replay** - Event replay with timing
473
496
 
474
497
  ```bash
475
- # Execute SQL query against event store
476
- swarm query --sql "SELECT type, COUNT(*) FROM events GROUP BY type"
498
+ # Replay epic at normal speed
499
+ swarm replay mjmas3zxlmg
500
+
501
+ # Fast playback
502
+ swarm replay mjmas3zxlmg --speed 2x
503
+ swarm replay mjmas3zxlmg --speed instant
504
+
505
+ # Filter by event type
506
+ swarm replay mjmas3zxlmg --type worker_spawned,task_completed
507
+
508
+ # Filter by agent
509
+ swarm replay mjmas3zxlmg --agent DarkHawk
510
+
511
+ # Time range filters
512
+ swarm replay mjmas3zxlmg --since "2025-12-25T10:00:00"
513
+ swarm replay mjmas3zxlmg --until "2025-12-25T12:00:00"
514
+
515
+ # Combine filters
516
+ swarm replay mjmas3zxlmg --speed 2x --type worker_spawned --agent BlueLake
517
+ ```
477
518
 
478
- # Use pre-built analytics queries
479
- swarm query --preset golden-signals # Four Golden Signals (latency, traffic, errors, saturation)
480
- swarm query --preset compaction-health # Compaction performance metrics
481
- swarm query --preset file-conflicts # File reservation conflict analysis
519
+ **swarm export** - Data export for analysis
520
+
521
+ ```bash
522
+ # Export all events as JSON (stdout)
523
+ swarm export
524
+
525
+ # Export specific epic
526
+ swarm export --epic mjmas3zxlmg
482
527
 
483
528
  # Export formats
484
- swarm query --sql "..." --format json # JSON output
485
- swarm query --sql "..." --format csv # CSV output
486
- swarm query --sql "..." --format table # Pretty table (default)
529
+ swarm export --format json --output events.json
530
+ swarm export --format csv --output events.csv
531
+ swarm export --format otlp --output events.otlp # OpenTelemetry Protocol
487
532
 
488
- # Stats and history
489
- swarm stats # Event store statistics (counts by type, project)
490
- swarm history # Recent swarm activity summary
533
+ # Pipe to jq for filtering
534
+ swarm export --format json | jq '.[] | select(.type=="worker_spawned")'
491
535
  ```
492
536
 
493
- ### Real-Time Monitoring
537
+ **swarm stats** - Health metrics
494
538
 
495
539
  ```bash
496
- # Dashboard (TUI) - live swarm status
497
- swarm dashboard # Show all active swarms
498
- swarm dashboard --epic mjmas3zxlmg # Filter by epic ID
499
- swarm dashboard --refresh 5 # Auto-refresh every 5 seconds
540
+ # Last 7 days (default)
541
+ swarm stats
542
+
543
+ # Custom time period
544
+ swarm stats --since 24h
545
+ swarm stats --since 30m
500
546
 
501
- # Event replay - watch swarm execution
502
- swarm replay mjmas3zxlmg # Replay entire epic from events
503
- swarm replay mjmas3zxlmg --speed 2.0 # 2x speed
504
- swarm replay mjmas3zxlmg --type DECISION # Only DECISION events
505
- swarm replay mjmas3zxlmg --agent Worker1 # Single agent's perspective
506
- swarm replay mjmas3zxlmg --since "2h" # Last 2 hours
507
- swarm replay mjmas3zxlmg --until "1h" # Up to 1 hour ago
547
+ # JSON output for scripting
548
+ swarm stats --json
508
549
  ```
509
550
 
510
- ### Data Export
551
+ **swarm history** - Activity timeline
511
552
 
512
553
  ```bash
513
- # Export event data
514
- swarm export # Export all events as JSON
515
- swarm export --format csv # CSV format
516
- swarm export --epic mjmas3zxlmg # Filter by epic ID
517
- swarm export --output swarm-data.json # Save to file
518
- swarm export --format jsonl # JSONL (one event per line)
554
+ # Last 10 swarms (default)
555
+ swarm history
556
+
557
+ # More results
558
+ swarm history --limit 20
559
+
560
+ # Filter by status
561
+ swarm history --status success
562
+ swarm history --status failed
563
+ swarm history --status in_progress
564
+
565
+ # Filter by strategy
566
+ swarm history --strategy file-based
567
+ swarm history --strategy feature-based
568
+
569
+ # Verbose mode (show subtasks)
570
+ swarm history --verbose
519
571
  ```
520
572
 
573
+ **swarm log** - Query/tail logs
574
+
575
+ ```bash
576
+ # Recent logs (last 50 lines)
577
+ swarm log
578
+
579
+ # Filter by module
580
+ swarm log compaction
581
+
582
+ # Filter by level
583
+ swarm log --level error
584
+ swarm log --level warn
585
+
586
+ # Time filters
587
+ swarm log --since 30s
588
+ swarm log --since 5m
589
+ swarm log --since 2h
590
+
591
+ # JSON output
592
+ swarm log --json
593
+
594
+ # Limit output
595
+ swarm log --limit 100
596
+
597
+ # Watch mode (live tail)
598
+ swarm log --watch
599
+ swarm log --watch --interval 500 # Poll every 500ms
600
+ ```
601
+
602
+ **swarm log sessions** - View coordinator sessions
603
+
604
+ ```bash
605
+ # List all sessions
606
+ swarm log sessions
607
+
608
+ # View specific session
609
+ swarm log sessions <session_id>
610
+
611
+ # Most recent session
612
+ swarm log sessions --latest
613
+
614
+ # Filter by event type
615
+ swarm log sessions --type DECISION
616
+ swarm log sessions --type VIOLATION
617
+ swarm log sessions --type OUTCOME
618
+ swarm log sessions --type COMPACTION
619
+
620
+ # JSON output for jq
621
+ swarm log sessions --json
622
+ ```
623
+
624
+ ### Debug Logging
625
+
626
+ Use `DEBUG` env var to enable swarm debug logs:
627
+
628
+ ```bash
629
+ # All swarm logs
630
+ DEBUG=swarm:* swarm dashboard
631
+
632
+ # Coordinator only
633
+ DEBUG=swarm:coordinator swarm replay <epic-id>
634
+
635
+ # Workers only
636
+ DEBUG=swarm:worker swarm export
637
+
638
+ # Swarm mail only
639
+ DEBUG=swarm:mail swarm query --preset agent_activity
640
+
641
+ # Multiple namespaces (comma-separated)
642
+ DEBUG=swarm:coordinator,swarm:worker swarm dashboard
643
+ ```
644
+
645
+ **Namespaces:**
646
+
647
+ | Namespace | What It Logs |
648
+ |-----------|--------------|
649
+ | `swarm:*` | All swarm activity |
650
+ | `swarm:coordinator` | Coordinator decisions (spawn, review, approve/reject) |
651
+ | `swarm:worker` | Worker progress, reservations, completions |
652
+ | `swarm:mail` | Inter-agent messages, inbox/outbox activity |
653
+
521
654
  ## Observability Architecture
522
655
 
523
656
  Swarm uses **event sourcing** for complete observability. Every coordination action is an event - nothing is lost, everything is queryable.
@@ -573,16 +706,65 @@ Swarm uses **event sourcing** for complete observability. Every coordination act
573
706
 
574
707
  ### Key Event Types
575
708
 
709
+ **Agent Lifecycle:**
576
710
  | Event Type | When It Fires | Used For |
577
711
  |------------|---------------|----------|
578
712
  | `agent_registered` | Agent calls `swarmmail_init()` | Agent discovery, project tracking |
579
- | `message_sent` | Agent sends swarm mail | Agent coordination, thread tracking |
580
- | `file_reserved` | Agent reserves files for edit | Conflict detection, lock management |
581
- | `file_released` | Agent releases or completes | Lock cleanup, reservation tracking |
713
+ | `agent_active` | Periodic heartbeat | Last-seen tracking |
714
+
715
+ **Messages:**
716
+ | Event Type | When It Fires | Used For |
717
+ |------------|---------------|----------|
718
+ | `message_sent` | Agent sends swarm mail | Coordination, thread tracking |
719
+ | `message_read` | Agent reads message | Read receipts |
720
+ | `message_acked` | Agent acknowledges | Confirmation tracking |
721
+ | `thread_created` | First message in thread | Thread lifecycle |
722
+ | `thread_activity` | Thread stats update | Unread counts, participants |
723
+
724
+ **File Reservations:**
725
+ | Event Type | When It Fires | Used For |
726
+ |------------|---------------|----------|
727
+ | `file_reserved` | Agent reserves files | Conflict detection, lock management |
728
+ | `file_released` | Agent releases files | Lock cleanup, reservation tracking |
729
+ | `file_conflict` | Reservation collision | Conflict resolution, deadlock detection |
730
+
731
+ **Task Tracking:**
732
+ | Event Type | When It Fires | Used For |
733
+ |------------|---------------|----------|
582
734
  | `task_started` | Agent starts cell work | Progress tracking, timeline |
583
735
  | `task_progress` | Agent reports milestone | Real-time monitoring, ETA |
584
736
  | `task_completed` | Agent calls `swarm_complete()` | Outcome tracking, learning signals |
737
+ | `task_blocked` | Agent hits blocker | Dependency tracking, alerts |
738
+
739
+ **Swarm Coordination:**
740
+ | Event Type | When It Fires | Used For |
741
+ |------------|---------------|----------|
742
+ | `swarm_started` | Coordinator begins epic | Swarm lifecycle tracking |
743
+ | `worker_spawned` | Coordinator spawns worker | Worker tracking, spawn order |
744
+ | `worker_completed` | Worker finishes subtask | Outcome tracking, duration |
745
+ | `review_started` | Coordinator begins review | Review tracking, attempts |
746
+ | `review_completed` | Review finishes | Approval/rejection tracking |
747
+ | `swarm_completed` | All subtasks done | Epic completion, success rate |
748
+ | `decomposition_generated` | Task decomposed | Strategy tracking, subtask planning |
749
+ | `subtask_outcome` | Subtask finishes | Learning signals, scope violations |
750
+
751
+ **Checkpoints & Recovery:**
752
+ | Event Type | When It Fires | Used For |
753
+ |------------|---------------|----------|
585
754
  | `swarm_checkpointed` | Auto at 25/50/75% or manual | Recovery, context preservation |
755
+ | `swarm_recovered` | Resume from checkpoint | Recovery tracking, checkpoint age |
756
+ | `checkpoint_created` | Checkpoint saved | Checkpoint lifecycle |
757
+ | `context_compacted` | Context compaction runs | Context compression tracking |
758
+
759
+ **Validation & Learning:**
760
+ | Event Type | When It Fires | Used For |
761
+ |------------|---------------|----------|
762
+ | `validation_started` | Validation begins | Validation lifecycle |
763
+ | `validation_issue` | Validation finds issue | Issue tracking, debugging |
764
+ | `validation_completed` | Validation finishes | Pass/fail tracking |
765
+ | `human_feedback` | Human accepts/modifies | Human-in-loop learning |
766
+
767
+ **Full Schema:** See [swarm-mail/src/streams/events.ts](../swarm-mail/src/streams/events.ts) for complete Zod schemas (30+ event types)
586
768
 
587
769
  ### Analytics Queries
588
770
 
@@ -667,13 +849,16 @@ swarm query --preset file-conflicts
667
849
  swarm query --sql "SELECT * FROM events WHERE json_extract(data, '$.bead_id') = 'mjmas411jtj' ORDER BY timestamp"
668
850
 
669
851
  # 2. Check for file reservation conflicts
670
- swarm query --preset file-conflicts
852
+ swarm query --preset file_conflicts
671
853
 
672
854
  # 3. Replay to see execution timeline
673
855
  swarm replay mjmas3zxlmg --agent WorkerName
674
856
 
675
857
  # 4. Check if agent is still registered
676
858
  swarm stats
859
+
860
+ # 5. Enable debug logging for live tracking
861
+ DEBUG=swarm:worker swarm dashboard --epic mjmas3zxlmg
677
862
  ```
678
863
 
679
864
  **Scenario 2: High failure rate for a specific epic**
@@ -682,24 +867,62 @@ swarm stats
682
867
  # 1. Get stats by epic
683
868
  swarm query --sql "SELECT type, COUNT(*) FROM events WHERE json_extract(data, '$.epic_id') = 'mjmas3zxlmg' GROUP BY type"
684
869
 
685
- # 2. Find failures
870
+ # 2. Find failures with reasons
686
871
  swarm query --sql "SELECT * FROM events WHERE type = 'task_completed' AND json_extract(data, '$.epic_id') = 'mjmas3zxlmg' AND json_extract(data, '$.success') = 0"
687
872
 
688
873
  # 3. Export for analysis
689
874
  swarm export --epic mjmas3zxlmg --format csv > failures.csv
875
+
876
+ # 4. Check coordinator session for violations
877
+ swarm log sessions --type VIOLATION --json
690
878
  ```
691
879
 
692
880
  **Scenario 3: Performance regression (tasks slower than before)**
693
881
 
694
882
  ```bash
695
883
  # 1. Check latency trends
696
- swarm query --preset golden-signals
884
+ swarm query --preset duration_by_strategy
697
885
 
698
886
  # 2. Compare with historical baselines
699
- swarm history
887
+ swarm history --limit 50
700
888
 
701
889
  # 3. Identify bottlenecks
702
890
  swarm dashboard --epic mjmas3zxlmg --refresh 2
891
+
892
+ # 4. Analyze worker spawn efficiency
893
+ swarm query --preset worker_success_rate
894
+ ```
895
+
896
+ **Scenario 4: File reservation conflicts**
897
+
898
+ ```bash
899
+ # 1. Check active locks
900
+ swarm query --preset file_conflicts
901
+
902
+ # 2. See who's holding what
903
+ swarm dashboard # Shows file locks section
904
+
905
+ # 3. View full conflict history
906
+ swarm query --sql "SELECT * FROM events WHERE type = 'file_conflict' ORDER BY timestamp DESC LIMIT 20"
907
+
908
+ # 4. Replay to see conflict sequence
909
+ swarm replay mjmas3zxlmg --type file_reserved,file_released,file_conflict
910
+ ```
911
+
912
+ **Scenario 5: Coordinator not spawning workers**
913
+
914
+ ```bash
915
+ # 1. Check coordinator session for violations
916
+ swarm log sessions --latest --type DECISION,VIOLATION
917
+
918
+ # 2. Verify decomposition was generated
919
+ swarm query --sql "SELECT * FROM events WHERE type = 'decomposition_generated' ORDER BY timestamp DESC LIMIT 5"
920
+
921
+ # 3. Debug coordinator logic
922
+ DEBUG=swarm:coordinator swarm replay mjmas3zxlmg
923
+
924
+ # 4. Check for blocked tasks
925
+ swarm query --preset blocked_tasks
703
926
  ```
704
927
 
705
928
  ### Event Store Schema