opencode-swarm-plugin 0.42.9 → 0.43.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.
@@ -122,3 +122,17 @@
122
122
  {"id":"opencode-swarm-plugin--ys7z8-mjmavq7pz17","title":"T2: Semantic Memory Gap Analysis","status":"closed","priority":0,"issue_type":"task","created_at":"2025-12-26T03:16:46.837Z","updated_at":"2025-12-26T03:22:06.745Z","closed_at":"2025-12-26T03:22:06.745Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmavq7f31x","dependencies":[],"labels":[],"comments":[]}
123
123
  {"id":"opencode-swarm-plugin--ys7z8-mjmavq7rt9z","title":"T3: Agent Session Format Survey","status":"closed","priority":0,"issue_type":"task","created_at":"2025-12-26T03:16:46.839Z","updated_at":"2025-12-26T03:22:08.486Z","closed_at":"2025-12-26T03:22:08.486Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmavq7f31x","dependencies":[],"labels":[],"comments":[]}
124
124
  {"id":"opencode-swarm-plugin--ys7z8-mjmavq7va7b","title":"T4: Write ADR-010 with TDD Plan","status":"closed","priority":1,"issue_type":"task","created_at":"2025-12-26T03:16:46.843Z","updated_at":"2025-12-26T03:28:59.753Z","closed_at":"2025-12-26T03:28:59.753Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmavq7f31x","dependencies":[],"labels":[],"comments":[]}
125
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","title":"ADR-010 Implementation: CASS Inhousing - Session Indexing Layer","description":"Implement ADR-010: Bring session indexing in-house by building on semantic-memory infrastructure.\n\n**Vision:** Unified query API for semantic memory + session search, no external CASS binary.\n\n**Acknowledgment:** This work is inspired by CASS (coding_agent_session_search) by Dicklesworthstone - a production-quality Rust implementation that showed us what's possible.\n\n**Scope:**\n- 8 thin adapters on semantic-memory (parser, chunker, watcher, discovery, staleness, viewer, pagination, tools)\n- Full TDD with characterization tests\n- Comprehensive docs (README, AGENTS.md, plugin-wrapper-template.ts)\n- Dual-mode support (binary → hybrid → inhouse migration)\n\n**Out of Scope:**\n- Cloud-only agents (Claude Code, Gemini, Copilot)\n- Multi-machine sync\n- TUI\n\n**Success Criteria:**\n- All tests pass (characterization + unit + integration)\n- cass_* MCP tools work identically to binary CASS\n- Docs updated with session indexing section\n- CASS acknowledged in README","status":"open","priority":1,"issue_type":"epic","created_at":"2025-12-26T03:40:45.275Z","updated_at":"2025-12-26T03:40:45.275Z","dependencies":[],"labels":[],"comments":[]}
126
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk4hney","title":"T0: Characterization Tests - Capture CASS Baseline Behavior","status":"open","priority":0,"issue_type":"task","created_at":"2025-12-26T03:40:45.281Z","updated_at":"2025-12-26T03:40:45.281Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
127
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk4jagt","title":"T1: Session Parser + Metadata Schema Extension","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-26T03:40:45.283Z","updated_at":"2025-12-26T03:40:45.283Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
128
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk4l62w","title":"T2: Chunk Processor - Message-Level Chunking + Embedding","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-26T03:40:45.285Z","updated_at":"2025-12-26T03:40:45.285Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
129
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk4n2t1","title":"T3: Agent Discovery - Path to Agent Type Mapping","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-26T03:40:45.287Z","updated_at":"2025-12-26T03:40:45.287Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
130
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk4ppbb","title":"T4: File Watcher - Debounced Auto-Indexing","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-26T03:40:45.289Z","updated_at":"2025-12-26T03:40:45.289Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
131
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk4rq7j","title":"T5: Staleness Detector - Index Freshness Tracking","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-26T03:40:45.291Z","updated_at":"2025-12-26T03:40:45.291Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
132
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk4ud5r","title":"T6: Session Viewer - JSONL Line Reader with Context","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-26T03:40:45.294Z","updated_at":"2025-12-26T03:40:45.294Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
133
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk4wkik","title":"T7: Pagination API - Field Selection for Compact Output","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-26T03:40:45.296Z","updated_at":"2025-12-26T03:40:45.296Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
134
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk56gp5","title":"T8: Session Indexer Orchestrator - Ties Components Together","status":"open","priority":2,"issue_type":"task","created_at":"2025-12-26T03:40:45.306Z","updated_at":"2025-12-26T03:40:45.306Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
135
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk577u2","title":"T9: MCP Tools - cass_search, cass_view, cass_expand, cass_index, cass_health, cass_stats","status":"open","priority":2,"issue_type":"task","created_at":"2025-12-26T03:40:45.307Z","updated_at":"2025-12-26T03:40:45.307Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
136
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk59ewy","title":"T10: Dual-Mode Support - Binary/Inhouse/Hybrid Switching","status":"open","priority":2,"issue_type":"task","created_at":"2025-12-26T03:40:45.309Z","updated_at":"2025-12-26T03:40:45.309Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
137
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk5batv","title":"T11: Documentation - README, AGENTS.md, Plugin Template, CASS Acknowledgment","status":"open","priority":2,"issue_type":"task","created_at":"2025-12-26T03:40:45.311Z","updated_at":"2025-12-26T03:40:45.311Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
138
+ {"id":"opencode-swarm-plugin--ys7z8-mjmbqk5d7v1","title":"T12: Changeset + Final Validation","status":"open","priority":3,"issue_type":"task","created_at":"2025-12-26T03:40:45.313Z","updated_at":"2025-12-26T03:40:45.313Z","parent_id":"opencode-swarm-plugin--ys7z8-mjmbqk4bd8i","dependencies":[],"labels":[],"comments":[]}
@@ -1,9 +1,9 @@
1
1
  $ bun build ./src/index.ts --outdir ./dist --target node --external @electric-sql/pglite --external swarm-mail --external vitest --external @vitest/ui --external lightningcss && bun build ./src/plugin.ts --outfile ./dist/plugin.js --target node --external @electric-sql/pglite --external swarm-mail --external vitest --external @vitest/ui --external lightningcss && tsc
2
- Bundled 1349 modules in 181ms
2
+ Bundled 1349 modules in 297ms
3
3
 
4
4
  index.js 4.34 MB (entry point)
5
5
 
6
- Bundled 1350 modules in 176ms
6
+ Bundled 1350 modules in 197ms
7
7
 
8
8
  plugin.js 4.31 MB (entry point)
9
9
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,84 @@
1
1
  # opencode-swarm-plugin
2
2
 
3
+ ## 0.43.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`d74f68b`](https://github.com/joelhooks/swarm-tools/commit/d74f68ba491fdd127173c1993400c16b17479c3a) Thanks [@joelhooks](https://github.com/joelhooks)! - ## 🔭 Observability Stack: See What Your Swarm Is Doing
8
+
9
+ ```
10
+ ╭──────────────────────────────────────────────────────────╮
11
+ │ │
12
+ │ "Observability is about instrumenting your system │
13
+ │ in a way that ensures sufficient information about │
14
+ │ a system's runtime is collected and analyzed so │
15
+ │ that when something goes wrong, it can help you │
16
+ │ understand why." │
17
+ │ │
18
+ │ — AI Engineering, Chip Huyen │
19
+ │ │
20
+ ╰──────────────────────────────────────────────────────────╯
21
+ ```
22
+
23
+ Five new modules for understanding multi-agent coordination at runtime:
24
+
25
+ ### Error Enrichment (`error-enrichment.ts`)
26
+
27
+ ```typescript
28
+ throw new SwarmError("File reservation failed", {
29
+ file: "src/auth.ts",
30
+ agent: "DarkHawk",
31
+ epic_id: "mjmas3zxlmg",
32
+ recent_events: [
33
+ /* last 5 events */
34
+ ],
35
+ });
36
+ ```
37
+
38
+ - `SwarmError` class with structured context (file, line, agent, epic, events)
39
+ - `enrichError()` wraps any error with swarm context
40
+ - `debugLog()` respects `DEBUG=swarm:*` patterns
41
+ - `suggestFix()` maps 8+ error patterns to actionable fixes
42
+
43
+ ### SQL Analytics (`swarm query`)
44
+
45
+ ```bash
46
+ swarm query --preset failed_decompositions
47
+ swarm query --sql "SELECT * FROM events WHERE type='worker_spawned'"
48
+ swarm query --preset duration_by_strategy --format csv
49
+ ```
50
+
51
+ 10 preset queries: `failed_decompositions`, `duration_by_strategy`, `file_conflicts`, `worker_success_rate`, `review_rejections`, `blocked_tasks`, `agent_activity`, `event_frequency`, `error_patterns`, `compaction_stats`
52
+
53
+ ### Dashboard Data (`swarm dashboard`)
54
+
55
+ ```bash
56
+ swarm dashboard --epic mjmas3zxlmg --refresh 1000
57
+ ```
58
+
59
+ Real-time data fetching: worker status, subtask progress, file locks, recent messages, epic list.
60
+
61
+ ### Event Replay (`swarm replay`)
62
+
63
+ ```bash
64
+ swarm replay mjmas3zxlmg --speed 2x --type worker_spawned
65
+ swarm replay mjmas3zxlmg --agent DarkHawk --since "2025-12-25T10:00:00"
66
+ ```
67
+
68
+ Replay epic events with timing control. Filter by type, agent, time range. Debug coordination failures by watching the sequence unfold.
69
+
70
+ ### Export Formats (`swarm export`)
71
+
72
+ ```bash
73
+ swarm export --format otlp --epic mjmas3zxlmg # OpenTelemetry traces
74
+ swarm export --format csv --output events.csv # RFC 4180 compliant
75
+ swarm export --format json | jq '.[] | select(.type=="error")'
76
+ ```
77
+
78
+ **Test Coverage:** 225 tests (150 unit + 75 CLI integration)
79
+
80
+ **TDD Enforced:** RED cells first, GREEN cells second. Every function tested before implementation.
81
+
3
82
  ## 0.42.9
4
83
 
5
84
  ### Patch Changes
package/README.md CHANGED
@@ -432,13 +432,18 @@ See **[evals/README.md](./evals/README.md)** for full architecture, scorer detai
432
432
 
433
433
  ---
434
434
 
435
- ## CLI
435
+ ## CLI Reference
436
+
437
+ ### Setup & Configuration
436
438
 
437
439
  ```bash
438
- swarm setup # Install and configure
439
- swarm doctor # Check dependencies (CASS, UBS, Ollama)
440
- swarm init # Initialize hive in project
440
+ swarm setup # Interactive installer for all dependencies
441
+ swarm doctor # Check dependency health (CASS, UBS, Ollama)
442
+ swarm init # Initialize hive in current project
441
443
  swarm config # Show config file paths
444
+ swarm update # Update swarm plugin and bundled skills
445
+ swarm migrate # Migrate from legacy PGLite to libSQL
446
+ swarm version # Show version info
442
447
  ```
443
448
 
444
449
  ### Logging & Observability
@@ -449,9 +454,9 @@ Structured Pino logging with daily rotation:
449
454
  # Enable pretty logging during development
450
455
  SWARM_LOG_PRETTY=1 opencode
451
456
 
452
- # Query logs
457
+ # Query logs (aliases: log/logs)
453
458
  swarm log # Tail recent logs
454
- swarm log compaction # Filter by module
459
+ swarm logs compaction # Filter by module
455
460
  swarm log --level warn # Filter by level (warn+)
456
461
  swarm log --since 1h # Last hour
457
462
  swarm log --json | jq # Pipe to jq for analysis
@@ -462,6 +467,291 @@ swarm log --json | jq # Pipe to jq for analysis
462
467
  - `compaction.1log`, ... (module-specific)
463
468
  - Daily rotation, 14-day retention
464
469
 
470
+ ### Analytics & Debugging
471
+
472
+ Query event store for insights and debugging:
473
+
474
+ ```bash
475
+ # Execute SQL query against event store
476
+ swarm query --sql "SELECT type, COUNT(*) FROM events GROUP BY type"
477
+
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
482
+
483
+ # 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)
487
+
488
+ # Stats and history
489
+ swarm stats # Event store statistics (counts by type, project)
490
+ swarm history # Recent swarm activity summary
491
+ ```
492
+
493
+ ### Real-Time Monitoring
494
+
495
+ ```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
500
+
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
508
+ ```
509
+
510
+ ### Data Export
511
+
512
+ ```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)
519
+ ```
520
+
521
+ ## Observability Architecture
522
+
523
+ Swarm uses **event sourcing** for complete observability. Every coordination action is an event - nothing is lost, everything is queryable.
524
+
525
+ ```
526
+ ┌─────────────────────────────────────────────────────────────────────────┐
527
+ │ OBSERVABILITY FLOW │
528
+ ├─────────────────────────────────────────────────────────────────────────┤
529
+ │ │
530
+ │ ┌────────────┐ │
531
+ │ │ Agent │ swarmmail_init() │
532
+ │ │ (Worker) │ swarmmail_reserve(paths=["src/auth.ts"]) │
533
+ │ │ │ swarm_progress(status="in_progress") │
534
+ │ │ │ swarm_complete(...) │
535
+ │ └─────┬──────┘ │
536
+ │ │ │
537
+ │ ▼ │
538
+ │ ┌────────────────────────────────────────────────────────┐ │
539
+ │ │ libSQL Event Store │ │
540
+ │ │ ┌──────────────────────────────────────────────────┐ │ │
541
+ │ │ │ events table (append-only) │ │ │
542
+ │ │ │ ├─ id, type, timestamp, project_key, data │ │ │
543
+ │ │ │ ├─ agent_registered, message_sent, ... │ │ │
544
+ │ │ │ └─ task_started, task_progress, task_completed │ │ │
545
+ │ │ └──────────────────────────────────────────────────┘ │ │
546
+ │ │ │ │
547
+ │ │ Automatic Projections (materialized views): │ │
548
+ │ │ ├─ agents (who's registered) │ │
549
+ │ │ ├─ messages (agent inbox/outbox) │ │
550
+ │ │ ├─ reservations (file locks) │ │
551
+ │ │ └─ swarm_contexts (checkpoints) │ │
552
+ │ └─────────────────┬───────────────────────────────────────┘ │
553
+ │ │ │
554
+ │ ┌────────────┼────────────┬────────────┐ │
555
+ │ ▼ ▼ ▼ ▼ │
556
+ │ ┌─────────┐ ┌─────────┐ ┌──────────┐ ┌──────────┐ │
557
+ │ │ swarm │ │ swarm │ │ swarm │ │ swarm │ │
558
+ │ │ query │ │ stats │ │ dashboard│ │ replay │ │
559
+ │ │ (SQL) │ │ (counts)│ │ (TUI) │ │ (time) │ │
560
+ │ └─────────┘ └─────────┘ └──────────┘ └──────────┘ │
561
+ │ │
562
+ │ ┌─────────────────────────────────────────────────────────┐ │
563
+ │ │ Analytics Layer (Golden Signals) │ │
564
+ │ │ ├─ Latency: avg task duration, P50/P95/P99 │ │
565
+ │ │ ├─ Traffic: events/sec, message rate │ │
566
+ │ │ ├─ Errors: task failures, violations │ │
567
+ │ │ ├─ Saturation: file conflicts, blocked tasks │ │
568
+ │ │ └─ Conflicts: reservation collisions, deadlocks │ │
569
+ │ └─────────────────────────────────────────────────────────┘ │
570
+ │ │
571
+ └─────────────────────────────────────────────────────────────────────────┘
572
+ ```
573
+
574
+ ### Key Event Types
575
+
576
+ | Event Type | When It Fires | Used For |
577
+ |------------|---------------|----------|
578
+ | `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 |
582
+ | `task_started` | Agent starts cell work | Progress tracking, timeline |
583
+ | `task_progress` | Agent reports milestone | Real-time monitoring, ETA |
584
+ | `task_completed` | Agent calls `swarm_complete()` | Outcome tracking, learning signals |
585
+ | `swarm_checkpointed` | Auto at 25/50/75% or manual | Recovery, context preservation |
586
+
587
+ ### Analytics Queries
588
+
589
+ Pre-built queries based on **Four Golden Signals** observability framework:
590
+
591
+ **Latency** (how fast):
592
+ ```sql
593
+ -- Average task duration by type
594
+ SELECT
595
+ json_extract(data, '$.type') as task_type,
596
+ AVG(duration_ms) as avg_duration,
597
+ MAX(duration_ms) as p99_duration
598
+ FROM events
599
+ WHERE type = 'task_completed'
600
+ GROUP BY task_type;
601
+ ```
602
+
603
+ **Traffic** (how much):
604
+ ```sql
605
+ -- Events per hour
606
+ SELECT
607
+ strftime('%Y-%m-%d %H:00', datetime(timestamp/1000, 'unixepoch')) as hour,
608
+ COUNT(*) as event_count
609
+ FROM events
610
+ GROUP BY hour
611
+ ORDER BY hour DESC
612
+ LIMIT 24;
613
+ ```
614
+
615
+ **Errors** (what's broken):
616
+ ```sql
617
+ -- Failed tasks with reasons
618
+ SELECT
619
+ json_extract(data, '$.bead_id') as task,
620
+ json_extract(data, '$.reason') as failure_reason,
621
+ timestamp
622
+ FROM events
623
+ WHERE type = 'task_completed'
624
+ AND json_extract(data, '$.success') = 0
625
+ ORDER BY timestamp DESC;
626
+ ```
627
+
628
+ **Saturation** (resource contention):
629
+ ```sql
630
+ -- File reservation conflicts
631
+ SELECT
632
+ json_extract(data, '$.paths') as file_paths,
633
+ COUNT(*) as conflict_count,
634
+ GROUP_CONCAT(json_extract(data, '$.agent_name')) as agents
635
+ FROM events
636
+ WHERE type = 'file_reserved'
637
+ GROUP BY file_paths
638
+ HAVING COUNT(*) > 1;
639
+ ```
640
+
641
+ **Conflicts** (deadlocks, collisions):
642
+ ```sql
643
+ -- Reservation wait times (TTL expirations)
644
+ SELECT
645
+ json_extract(data, '$.agent_name') as agent,
646
+ json_extract(data, '$.paths') as paths,
647
+ (expires_at - timestamp) as wait_time_ms
648
+ FROM events
649
+ WHERE type = 'file_reserved'
650
+ AND (expires_at - timestamp) > 10000 -- >10sec wait
651
+ ORDER BY wait_time_ms DESC;
652
+ ```
653
+
654
+ Run these via:
655
+ ```bash
656
+ swarm query --preset golden-signals
657
+ swarm query --preset compaction-health
658
+ swarm query --preset file-conflicts
659
+ ```
660
+
661
+ ### Getting Started with Debugging
662
+
663
+ **Scenario 1: Task is stuck "in_progress" forever**
664
+
665
+ ```bash
666
+ # 1. Find the task in events
667
+ swarm query --sql "SELECT * FROM events WHERE json_extract(data, '$.bead_id') = 'mjmas411jtj' ORDER BY timestamp"
668
+
669
+ # 2. Check for file reservation conflicts
670
+ swarm query --preset file-conflicts
671
+
672
+ # 3. Replay to see execution timeline
673
+ swarm replay mjmas3zxlmg --agent WorkerName
674
+
675
+ # 4. Check if agent is still registered
676
+ swarm stats
677
+ ```
678
+
679
+ **Scenario 2: High failure rate for a specific epic**
680
+
681
+ ```bash
682
+ # 1. Get stats by epic
683
+ swarm query --sql "SELECT type, COUNT(*) FROM events WHERE json_extract(data, '$.epic_id') = 'mjmas3zxlmg' GROUP BY type"
684
+
685
+ # 2. Find failures
686
+ swarm query --sql "SELECT * FROM events WHERE type = 'task_completed' AND json_extract(data, '$.epic_id') = 'mjmas3zxlmg' AND json_extract(data, '$.success') = 0"
687
+
688
+ # 3. Export for analysis
689
+ swarm export --epic mjmas3zxlmg --format csv > failures.csv
690
+ ```
691
+
692
+ **Scenario 3: Performance regression (tasks slower than before)**
693
+
694
+ ```bash
695
+ # 1. Check latency trends
696
+ swarm query --preset golden-signals
697
+
698
+ # 2. Compare with historical baselines
699
+ swarm history
700
+
701
+ # 3. Identify bottlenecks
702
+ swarm dashboard --epic mjmas3zxlmg --refresh 2
703
+ ```
704
+
705
+ ### Event Store Schema
706
+
707
+ ```sql
708
+ CREATE TABLE events (
709
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
710
+ type TEXT NOT NULL, -- Event discriminator
711
+ project_key TEXT NOT NULL, -- Project path (for multi-project filtering)
712
+ timestamp INTEGER NOT NULL, -- Unix ms
713
+ sequence INTEGER GENERATED ALWAYS AS (id) STORED,
714
+ data TEXT NOT NULL, -- JSON payload (event-specific fields)
715
+ created_at TEXT DEFAULT (datetime('now'))
716
+ );
717
+
718
+ -- Indexes for fast queries
719
+ CREATE INDEX idx_events_project_key ON events(project_key);
720
+ CREATE INDEX idx_events_type ON events(type);
721
+ CREATE INDEX idx_events_timestamp ON events(timestamp);
722
+ CREATE INDEX idx_events_project_type ON events(project_key, type);
723
+ ```
724
+
725
+ **Event payload examples:**
726
+
727
+ ```json
728
+ // agent_registered event
729
+ {
730
+ "type": "agent_registered",
731
+ "project_key": "/path/to/project",
732
+ "timestamp": 1703001234567,
733
+ "data": "{\"agent_name\":\"BlueLake\",\"program\":\"opencode\",\"model\":\"claude-sonnet-4\",\"task_description\":\"mjmas411jtj: Update READMEs\"}"
734
+ }
735
+
736
+ // task_completed event
737
+ {
738
+ "type": "task_completed",
739
+ "project_key": "/path/to/project",
740
+ "timestamp": 1703001299999,
741
+ "data": "{\"agent_name\":\"BlueLake\",\"bead_id\":\"mjmas411jtj\",\"summary\":\"Updated both READMEs with CLI reference and event schema\",\"files_touched\":[\"packages/opencode-swarm-plugin/README.md\",\"packages/swarm-mail/README.md\"],\"success\":true}"
742
+ }
743
+ ```
744
+
745
+ ### Database Location
746
+
747
+ ```bash
748
+ # libSQL database path
749
+ ~/.config/swarm-tools/libsql/<project-hash>/swarm.db
750
+
751
+ # Find your project's database
752
+ swarm config # Shows database path for current project
753
+ ```
754
+
465
755
  ---
466
756
 
467
757
  ## Further Reading