opencode-swarm-plugin 0.38.0 → 0.40.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.
Files changed (91) hide show
  1. package/.env +2 -0
  2. package/.hive/eval-results.json +26 -0
  3. package/.hive/issues.jsonl +27 -0
  4. package/.hive/memories.jsonl +23 -1
  5. package/.opencode/eval-history.jsonl +12 -0
  6. package/CHANGELOG.md +182 -0
  7. package/README.md +29 -12
  8. package/bin/swarm.test.ts +881 -0
  9. package/bin/swarm.ts +686 -0
  10. package/dist/compaction-hook.d.ts +8 -1
  11. package/dist/compaction-hook.d.ts.map +1 -1
  12. package/dist/compaction-observability.d.ts +173 -0
  13. package/dist/compaction-observability.d.ts.map +1 -0
  14. package/dist/compaction-prompt-scoring.d.ts +124 -0
  15. package/dist/compaction-prompt-scoring.d.ts.map +1 -0
  16. package/dist/eval-capture.d.ts +174 -1
  17. package/dist/eval-capture.d.ts.map +1 -1
  18. package/dist/eval-gates.d.ts +84 -0
  19. package/dist/eval-gates.d.ts.map +1 -0
  20. package/dist/eval-history.d.ts +117 -0
  21. package/dist/eval-history.d.ts.map +1 -0
  22. package/dist/eval-learning.d.ts +216 -0
  23. package/dist/eval-learning.d.ts.map +1 -0
  24. package/dist/hive.d.ts.map +1 -1
  25. package/dist/index.d.ts +80 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +16098 -651
  28. package/dist/plugin.js +16012 -756
  29. package/dist/post-compaction-tracker.d.ts +133 -0
  30. package/dist/post-compaction-tracker.d.ts.map +1 -0
  31. package/dist/schemas/task.d.ts +3 -3
  32. package/dist/swarm-orchestrate.d.ts +23 -0
  33. package/dist/swarm-orchestrate.d.ts.map +1 -1
  34. package/dist/swarm-prompts.d.ts +25 -1
  35. package/dist/swarm-prompts.d.ts.map +1 -1
  36. package/dist/swarm.d.ts +4 -0
  37. package/dist/swarm.d.ts.map +1 -1
  38. package/evals/README.md +702 -105
  39. package/evals/compaction-prompt.eval.ts +149 -0
  40. package/evals/coordinator-behavior.eval.ts +8 -8
  41. package/evals/fixtures/compaction-prompt-cases.ts +305 -0
  42. package/evals/lib/compaction-loader.test.ts +248 -0
  43. package/evals/lib/compaction-loader.ts +320 -0
  44. package/evals/lib/data-loader.test.ts +345 -0
  45. package/evals/lib/data-loader.ts +107 -6
  46. package/evals/scorers/compaction-prompt-scorers.ts +145 -0
  47. package/evals/scorers/compaction-scorers.ts +13 -13
  48. package/evals/scorers/coordinator-discipline.evalite-test.ts +166 -2
  49. package/evals/scorers/coordinator-discipline.ts +348 -15
  50. package/evals/scorers/index.test.ts +146 -0
  51. package/evals/scorers/index.ts +104 -0
  52. package/evals/swarm-decomposition.eval.ts +9 -2
  53. package/examples/commands/swarm.md +291 -21
  54. package/examples/plugin-wrapper-template.ts +117 -0
  55. package/package.json +7 -5
  56. package/scripts/migrate-unknown-sessions.ts +349 -0
  57. package/src/compaction-capture.integration.test.ts +257 -0
  58. package/src/compaction-hook.test.ts +42 -0
  59. package/src/compaction-hook.ts +315 -86
  60. package/src/compaction-observability.integration.test.ts +139 -0
  61. package/src/compaction-observability.test.ts +187 -0
  62. package/src/compaction-observability.ts +324 -0
  63. package/src/compaction-prompt-scorers.test.ts +299 -0
  64. package/src/compaction-prompt-scoring.ts +298 -0
  65. package/src/eval-capture.test.ts +626 -1
  66. package/src/eval-capture.ts +286 -2
  67. package/src/eval-gates.test.ts +306 -0
  68. package/src/eval-gates.ts +218 -0
  69. package/src/eval-history.test.ts +508 -0
  70. package/src/eval-history.ts +214 -0
  71. package/src/eval-learning.test.ts +378 -0
  72. package/src/eval-learning.ts +360 -0
  73. package/src/eval-runner.test.ts +96 -0
  74. package/src/eval-runner.ts +356 -0
  75. package/src/hive.ts +34 -0
  76. package/src/index.ts +115 -2
  77. package/src/memory.test.ts +110 -0
  78. package/src/memory.ts +34 -0
  79. package/src/post-compaction-tracker.test.ts +251 -0
  80. package/src/post-compaction-tracker.ts +237 -0
  81. package/src/swarm-decompose.ts +2 -2
  82. package/src/swarm-orchestrate.ts +2 -2
  83. package/src/swarm-prompts.ts +2 -2
  84. package/src/swarm-review.ts +3 -3
  85. package/dist/beads.d.ts +0 -386
  86. package/dist/beads.d.ts.map +0 -1
  87. package/dist/schemas/bead-events.d.ts +0 -698
  88. package/dist/schemas/bead-events.d.ts.map +0 -1
  89. package/dist/schemas/bead.d.ts +0 -255
  90. package/dist/schemas/bead.d.ts.map +0 -1
  91. /package/evals/{evalite.config.ts → evalite.config.ts.bak} +0 -0
package/evals/README.md CHANGED
@@ -1,6 +1,18 @@
1
- # Evalite - Swarm Decomposition Evals
1
+ # Eval-Driven Development with Progressive Gates
2
2
 
3
- TypeScript-native evaluation framework for testing swarm task decomposition quality.
3
+ ```
4
+ ┌──────────────────────────────────────────────────────────────┐
5
+ │ EVAL PIPELINE │
6
+ │ │
7
+ │ CAPTURE → SCORE → STORE → GATE → LEARN → IMPROVE │
8
+ │ │
9
+ │ Real execution data feeds back into prompt generation │
10
+ └──────────────────────────────────────────────────────────────┘
11
+ ```
12
+
13
+ TypeScript-native evaluation framework for testing swarm task decomposition quality and coordinator discipline. Built on [Evalite](https://evalite.dev), powered by captured real-world execution data.
14
+
15
+ ---
4
16
 
5
17
  ## Quick Start
6
18
 
@@ -9,163 +21,748 @@ TypeScript-native evaluation framework for testing swarm task decomposition qual
9
21
  bun run eval:run
10
22
 
11
23
  # Run specific eval suite
12
- bun run eval:decomposition
13
- bun run eval:coordinator
24
+ bun run eval:decomposition # Task decomposition quality
25
+ bun run eval:coordinator # Coordinator protocol compliance
26
+ bun run eval:compaction # Compaction prompt quality
27
+
28
+ # Check eval status (progressive gates)
29
+ swarm eval status
30
+
31
+ # View eval history with trends
32
+ swarm eval history
14
33
  ```
15
34
 
16
- ## Structure
35
+ ---
36
+
37
+ ## Architecture
38
+
39
+ ### The Pipeline
17
40
 
18
41
  ```
19
- evals/
20
- ├── evalite.config.ts # Evalite configuration
21
- ├── scorers/
22
- └── index.ts # Custom scorers (independence, balance, coverage, clarity)
23
- ├── fixtures/
24
- └── decomposition-cases.ts # Test cases with expected outcomes
25
- └── *.eval.ts # Eval files (auto-discovered)
42
+ ┌─────────────────────────────────────────────────────────────────┐
43
+ │ │
44
+ │ 1. CAPTURE (Real Execution) │
45
+ ├─ Decomposition: task, strategy, subtasks │
46
+ │ ├─ Outcomes: duration, errors, retries, success │
47
+ ├─ Coordinator Events: decisions, violations, compaction │
48
+ │ └─ Store to: .opencode/eval-data.jsonl, sessions/*.jsonl │
49
+ │ │
50
+ │ 2. SCORE (Quality Metrics) │
51
+ │ ├─ Subtask Independence (file conflicts) │
52
+ │ ├─ Complexity Balance (fair work distribution) │
53
+ │ ├─ Coverage Completeness (files + scope) │
54
+ │ ├─ Instruction Clarity (actionable descriptions) │
55
+ │ └─ Coordinator Discipline (protocol adherence) │
56
+ │ │
57
+ │ 3. STORE (History Tracking) │
58
+ │ ├─ Record to: .opencode/eval-history.jsonl │
59
+ │ ├─ Track: score, timestamp, run_count │
60
+ │ └─ Calculate: phase, variance, baseline │
61
+ │ │
62
+ │ 4. GATE (Progressive Quality Control) │
63
+ │ ├─ Bootstrap (<10 runs): Always pass, collect data │
64
+ │ ├─ Stabilization (10-50 runs): Warn on >10% regression │
65
+ │ └─ Production (>50 runs, variance <0.1): Fail on >5% drop │
66
+ │ │
67
+ │ 5. LEARN (Failure Feedback) │
68
+ │ ├─ Detect: Significant score drops (>15% from baseline) │
69
+ │ ├─ Store to: Semantic memory with tags │
70
+ │ └─ Query: Before generating future prompts │
71
+ │ │
72
+ │ 6. IMPROVE (Continuous Refinement) │
73
+ │ └─ Future prompts query past failures for context │
74
+ │ │
75
+ └─────────────────────────────────────────────────────────────────┘
76
+ ```
77
+
78
+ ### Progressive Gates (Phase-Based Quality Control)
79
+
80
+ The eval system uses **progressive gates** that adapt based on data maturity:
81
+
82
+ ```
83
+ Phase Runs Variance Gate Behavior
84
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
85
+ Bootstrap <10 N/A ✅ Always pass (collect data)
86
+ Stabilization 10-50 N/A ⚠️ Warn on >10% regression (pass)
87
+ Production >50 <0.1 ❌ Fail on >5% regression
88
+ (High Variance) >50 ≥0.1 ⚠️ Stay in stabilization
89
+ ```
90
+
91
+ **Why progressive?**
92
+
93
+ - **Bootstrap**: No baseline yet, focus on data collection
94
+ - **Stabilization**: Baseline forming, tolerate noise while learning
95
+ - **Production**: Stable baseline, strict quality enforcement
96
+
97
+ **Variance threshold (0.1)**: Measures score consistency. High variance = unstable eval, stays in stabilization until it settles.
98
+
99
+ **Regression calculation**:
100
+ ```
101
+ baseline = mean(historical_scores)
102
+ regression = (baseline - current_score) / baseline
103
+ ```
104
+
105
+ ---
106
+
107
+ ## Eval Suites
108
+
109
+ ### Swarm Decomposition (`swarm-decomposition.eval.ts`)
110
+
111
+ **What it measures:** Quality of task decomposition into parallel subtasks
112
+
113
+ **Data sources:**
114
+ - Fixtures: `fixtures/decomposition-cases.ts`
115
+ - Real captures: `.opencode/eval-data.jsonl`
116
+
117
+ **Scorers:**
118
+
119
+ | Scorer | Weight | What It Checks | Perfect Score |
120
+ | ------------------------ | ------ | ------------------------------------------------------- | ---------------------------------- |
121
+ | **Subtask Independence** | 0.25 | No file overlaps between subtasks (prevents conflicts) | 0 files in multiple subtasks |
122
+ | **Complexity Balance** | 0.25 | Work distributed evenly (coefficient of variation <0.3) | CV <0.3 (max/min complexity ratio) |
123
+ | **Coverage** | 0.25 | Required files covered, subtask count in range | All required files + 3-6 subtasks |
124
+ | **Instruction Clarity** | 0.25 | Descriptions actionable, files specified, titles clear | >20 chars, files listed, specific |
125
+
126
+ **Example output:**
127
+ ```
128
+ swarm-decomposition
129
+ ├─ subtaskIndependence: 1.0 (no conflicts)
130
+ ├─ complexityBalance: 0.85 (CV: 0.22)
131
+ ├─ coverageCompleteness: 1.0 (all files covered)
132
+ └─ instructionClarity: 0.90 (clear, actionable)
133
+ → Overall: 0.94 ✅ PASS (stabilization phase)
134
+ ```
135
+
136
+ ### Coordinator Session (`coordinator-session.eval.ts`)
137
+
138
+ **What it measures:** Coordinator protocol adherence during swarm runs
139
+
140
+ **Data sources:**
141
+ - Real sessions: `~/.config/swarm-tools/sessions/*.jsonl`
142
+ - Fixtures: `fixtures/coordinator-sessions.ts`
143
+
144
+ **Scorers:**
145
+
146
+ | Scorer | Weight | What It Checks | Perfect Score |
147
+ | ---------------------------- | ------ | -------------------------------------------------- | -------------------- |
148
+ | **Violation Count** | 0.30 | Protocol violations (edit files, run tests, etc.) | 0 violations |
149
+ | **Spawn Efficiency** | 0.25 | Workers spawned / subtasks planned | 100% (all delegated) |
150
+ | **Review Thoroughness** | 0.25 | Reviews completed / workers finished | 100% (all reviewed) |
151
+ | **Time to First Spawn** | 0.20 | Speed from decomposition to first worker spawn | <60 seconds |
152
+ | **Overall Discipline** (composite) | 1.00 | Weighted composite of above | 1.0 (perfect) |
153
+
154
+ **Violations tracked:**
155
+ - `coordinator_edited_file` - Coordinator should NEVER edit directly
156
+ - `coordinator_ran_tests` - Workers run tests, not coordinator
157
+ - `coordinator_reserved_files` - Only workers reserve files
158
+ - `no_worker_spawned` - Coordinator must delegate, not do work itself
159
+
160
+ **Example output:**
161
+ ```
162
+ coordinator-behavior
163
+ ├─ violationCount: 1.0 (0 violations)
164
+ ├─ spawnEfficiency: 1.0 (3/3 workers spawned)
165
+ ├─ reviewThoroughness: 0.67 (2/3 reviewed)
166
+ └─ timeToFirstSpawn: 0.90 (45 seconds)
167
+ → overallDiscipline: 0.89 ✅ PASS (bootstrap phase, collecting data)
168
+ ```
169
+
170
+ #### Coordinator Session Capture (Deep Dive)
171
+
172
+ **How it works:** Session capture is fully automatic when coordinator tools are used. No manual instrumentation needed.
173
+
174
+ **Capture flow:**
175
+
176
+ ```
177
+ ┌─────────────────────────────────────────────────────────────┐
178
+ │ SESSION CAPTURE FLOW │
179
+ │ │
180
+ │ 1. Coordinator tool call detected │
181
+ │ ├─ swarm_decompose, hive_create_epic, etc. │
182
+ │ └─ Tool name + args inspected in real-time │
183
+ │ │
184
+ │ 2. Violation detection (planning-guardrails.ts) │
185
+ │ ├─ detectCoordinatorViolation() checks patterns │
186
+ │ ├─ Edit/Write tools → coordinator_edited_file │
187
+ │ ├─ bash with test patterns → coordinator_ran_tests │
188
+ │ └─ swarmmail_reserve → coordinator_reserved_files │
189
+ │ │
190
+ │ 3. Event emission (eval-capture.ts) │
191
+ │ ├─ captureCoordinatorEvent() validates via Zod │
192
+ │ ├─ Appends JSONL line to session file │
193
+ │ └─ ~/.config/swarm-tools/sessions/{session_id}.jsonl │
194
+ │ │
195
+ │ 4. Eval consumption (coordinator-session.eval.ts) │
196
+ │ ├─ loadCapturedSessions() reads all *.jsonl files │
197
+ │ ├─ Parses events, reconstructs sessions │
198
+ │ └─ Scorers analyze event sequences │
199
+ │ │
200
+ └─────────────────────────────────────────────────────────────┘
201
+ ```
202
+
203
+ **Event types:**
204
+
205
+ | Event Type | Subtypes | When Captured |
206
+ | -------------- | --------------------------------------------------------------------- | ------------------------------------ |
207
+ | `DECISION` | strategy_selected, worker_spawned, review_completed, decomposition_complete | Coordinator makes decision |
208
+ | `VIOLATION` | coordinator_edited_file, coordinator_ran_tests, coordinator_reserved_files, no_worker_spawned | Protocol violation detected |
209
+ | `OUTCOME` | subtask_success, subtask_retry, subtask_failed, epic_complete | Worker completes or epic finishes |
210
+ | `COMPACTION` | detection_complete, prompt_generated, context_injected, resumption_started, tool_call_tracked | Compaction lifecycle events |
211
+
212
+ **Violation detection patterns** (from `planning-guardrails.ts`):
213
+
214
+ ```typescript
215
+ // File modification detection
216
+ VIOLATION_PATTERNS.FILE_MODIFICATION_TOOLS = ["edit", "write"];
217
+
218
+ // Test execution detection (regex patterns in bash commands)
219
+ VIOLATION_PATTERNS.TEST_EXECUTION_PATTERNS = [
220
+ /\bbun\s+test\b/i,
221
+ /\bnpm\s+(run\s+)?test/i,
222
+ /\bjest\b/i,
223
+ /\bvitest\b/i,
224
+ // ... and 6 more patterns
225
+ ];
226
+
227
+ // File reservation detection
228
+ VIOLATION_PATTERNS.RESERVATION_TOOLS = ["swarmmail_reserve", "agentmail_reserve"];
229
+ ```
230
+
231
+ **Example session file** (`~/.config/swarm-tools/sessions/session-abc123.jsonl`):
232
+
233
+ ```jsonl
234
+ {"session_id":"session-abc123","epic_id":"mjkw81rkq4c","timestamp":"2025-01-01T12:00:00Z","event_type":"DECISION","decision_type":"strategy_selected","payload":{"strategy":"feature-based"}}
235
+ {"session_id":"session-abc123","epic_id":"mjkw81rkq4c","timestamp":"2025-01-01T12:01:00Z","event_type":"DECISION","decision_type":"decomposition_complete","payload":{"subtask_count":3}}
236
+ {"session_id":"session-abc123","epic_id":"mjkw81rkq4c","timestamp":"2025-01-01T12:02:00Z","event_type":"DECISION","decision_type":"worker_spawned","payload":{"worker_id":"SwiftFire","bead_id":"mjkw81rkq4c.1"}}
237
+ {"session_id":"session-abc123","epic_id":"mjkw81rkq4c","timestamp":"2025-01-01T12:05:00Z","event_type":"VIOLATION","violation_type":"coordinator_edited_file","payload":{"tool":"edit","file":"src/auth.ts"}}
238
+ {"session_id":"session-abc123","epic_id":"mjkw81rkq4c","timestamp":"2025-01-01T12:10:00Z","event_type":"OUTCOME","outcome_type":"subtask_success","payload":{"bead_id":"mjkw81rkq4c.1","duration_ms":480000}}
239
+ ```
240
+
241
+ **Viewing sessions:**
242
+
243
+ ```bash
244
+ # List all captured sessions (coming soon)
245
+ swarm log sessions
246
+
247
+ # View specific session events
248
+ cat ~/.config/swarm-tools/sessions/session-abc123.jsonl | jq .
249
+
250
+ # Filter to violations only
251
+ cat ~/.config/swarm-tools/sessions/*.jsonl | jq 'select(.event_type == "VIOLATION")'
252
+
253
+ # Count violations by type
254
+ cat ~/.config/swarm-tools/sessions/*.jsonl | jq -r 'select(.event_type == "VIOLATION") | .violation_type' | sort | uniq -c
255
+ ```
256
+
257
+ **Why JSONL format?**
258
+
259
+ - **Append-only**: No file locking, safe for concurrent writes
260
+ - **Streamable**: Process events one-by-one without loading full file
261
+ - **Line-oriented**: Easy to `grep`, `jq`, `tail -f` for live monitoring
262
+ - **Fault-tolerant**: Corrupted line doesn't break entire file
263
+
264
+ **Integration points:**
265
+
266
+ | Where | What Gets Captured | File |
267
+ | -------------------------- | ----------------------------------------- | ----------------------- |
268
+ | `swarm_decompose` | DECISION: strategy_selected, decomposition_complete | sessions/*.jsonl |
269
+ | `swarm_spawn_subtask` | DECISION: worker_spawned | sessions/*.jsonl |
270
+ | `swarm_review` | DECISION: review_completed | sessions/*.jsonl |
271
+ | `swarm_complete` | OUTCOME: subtask_success/failed | sessions/*.jsonl |
272
+ | Tool call inspection | VIOLATION: (real-time pattern matching) | sessions/*.jsonl |
273
+ | Compaction hook | COMPACTION: (all lifecycle stages) | sessions/*.jsonl |
274
+
275
+ **Source files:**
276
+
277
+ - **Schema**: `src/eval-capture.ts` - CoordinatorEventSchema (Zod discriminated union)
278
+ - **Violation detection**: `src/planning-guardrails.ts` - detectCoordinatorViolation()
279
+ - **Capture**: `src/eval-capture.ts` - captureCoordinatorEvent()
280
+ - **Scorers**: `evals/scorers/coordinator-discipline.ts` - violationCount, spawnEfficiency, etc.
281
+ - **Eval**: `evals/coordinator-session.eval.ts` - Real sessions + fixtures
282
+
283
+ ### Compaction Prompt (`compaction-prompt.eval.ts`)
284
+
285
+ **What it measures:** Quality of continuation prompts after context compaction
286
+
287
+ **Data sources:**
288
+ - Captured compaction events from session files
289
+ - Test fixtures with known-good/bad prompts
290
+
291
+ **Scorers:**
292
+
293
+ | Scorer | Weight | What It Checks | Perfect Score |
294
+ | -------------------------------- | ------ | --------------------------------------------------------- | -------------------------------- |
295
+ | **Epic ID Specificity** | 0.20 | Real IDs (mjkw...) not placeholders (<epic-id>, bd-xxx) | Real epic ID present |
296
+ | **Actionability** | 0.20 | Tool calls with real values (swarm_status with epic ID) | Actionable tool with real values |
297
+ | **Coordinator Identity** | 0.25 | ASCII header + strong mandates (NEVER/ALWAYS) | ASCII box + strong language |
298
+ | **Forbidden Tools Listed** | 0.15 | Lists Edit, Write, swarmmail_reserve, git commit by name | 4/4 forbidden tools listed |
299
+ | **Post-Compaction Discipline** | 0.20 | First suggested tool is swarm_status or inbox (not Edit) | First tool correct |
300
+
301
+ **Why these metrics?**
302
+
303
+ Post-compaction coordinators often "wake up" confused:
304
+ - Forget they're coordinators → start editing files
305
+ - Use placeholders → can't check actual status
306
+ - Weak language → ignore mandates
307
+ - Wrong first tool → dive into code instead of checking workers
308
+
309
+ **Example output:**
310
+ ```
311
+ compaction-prompt
312
+ ├─ epicIdSpecificity: 1.0 (real ID: mjkw81rkq4c)
313
+ ├─ actionability: 1.0 (swarm_status with real epic ID)
314
+ ├─ coordinatorIdentity: 1.0 (ASCII header + NEVER/ALWAYS)
315
+ ├─ forbiddenToolsPresent: 1.0 (4/4 tools listed)
316
+ └─ postCompactionDiscipline: 1.0 (first tool: swarm_status)
317
+ → Overall: 1.0 ✅ PASS (production phase)
318
+ ```
319
+
320
+ ---
321
+
322
+ ## Data Capture
323
+
324
+ ### What Gets Captured
325
+
326
+ **Decomposition Events** (`.opencode/eval-data.jsonl`):
327
+ ```jsonl
328
+ {
329
+ "id": "mjkw81rkq4c",
330
+ "timestamp": "2025-01-01T12:00:00Z",
331
+ "task": "Add OAuth authentication",
332
+ "strategy": "feature-based",
333
+ "epic_title": "OAuth Implementation",
334
+ "subtasks": [...],
335
+ "outcomes": [...]
336
+ }
26
337
  ```
27
338
 
28
- ## Custom Scorers
339
+ **Coordinator Sessions** (`~/.config/swarm-tools/sessions/<session-id>.jsonl`):
340
+ ```jsonl
341
+ {"event_type": "DECISION", "decision_type": "strategy_selected", ...}
342
+ {"event_type": "DECISION", "decision_type": "worker_spawned", ...}
343
+ {"event_type": "VIOLATION", "violation_type": "coordinator_edited_file", ...}
344
+ {"event_type": "COMPACTION", "compaction_type": "prompt_generated", ...}
345
+ ```
346
+
347
+ **Eval History** (`.opencode/eval-history.jsonl`):
348
+ ```jsonl
349
+ {"timestamp": "...", "eval_name": "swarm-decomposition", "score": 0.92, "run_count": 15}
350
+ ```
351
+
352
+ ### Capture Points (Automatic)
353
+
354
+ | Integration Point | What Gets Captured | File |
355
+ | -------------------------- | ------------------------------------- | ----------------------- |
356
+ | `swarm_decompose` | Task, strategy, subtasks | eval-data.jsonl |
357
+ | `swarm_complete` | Outcome signals (duration, errors) | eval-data.jsonl |
358
+ | `swarm_record_outcome` | Learning signals | swarm-mail database |
359
+ | Coordinator spawn | Worker spawn event | sessions/*.jsonl |
360
+ | Coordinator review | Review decision | sessions/*.jsonl |
361
+ | Compaction hook | Prompt content, detection results | sessions/*.jsonl |
362
+ | Evalite runner | Score, baseline, phase | eval-history.jsonl |
363
+
364
+ ---
29
365
 
30
- ### Subtask Independence (0-1)
366
+ ## CLI Commands
31
367
 
32
- Checks no files appear in multiple subtasks. File conflicts cause merge conflicts and coordination overhead.
368
+ ### `swarm eval status [eval-name]`
33
369
 
34
- ### Complexity Balance (0-1)
370
+ Shows current phase, gate thresholds, and recent scores with sparklines.
35
371
 
36
- Measures coefficient of variation (CV) of estimated_complexity across subtasks. CV < 0.3 scores 1.0, decreases linearly to 0 at CV = 1.0.
372
+ ```bash
373
+ $ swarm eval status swarm-decomposition
374
+
375
+ ┌─────────────────────────────────────────────────────────────┐
376
+ │ Eval: swarm-decomposition │
377
+ │ Phase: 🚀 Production (53 runs, variance: 0.08) │
378
+ │ │
379
+ │ Gate Thresholds: │
380
+ │ ├─ Stabilization: >10% regression (warn) │
381
+ │ └─ Production: >5% regression (fail) │
382
+ │ │
383
+ │ Recent Scores (last 10 runs): │
384
+ │ 0.92 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2025-01-01 12:00 │
385
+ │ 0.89 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2025-01-01 11:30 │
386
+ │ 0.94 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2025-01-01 11:00 │
387
+ │ Baseline: 0.91 | Variance: 0.08 | Trend: ↗ │
388
+ └─────────────────────────────────────────────────────────────┘
389
+ ```
390
+
391
+ **Phase indicators:**
392
+ - 🌱 Bootstrap - Collecting data
393
+ - ⚙️ Stabilization - Learning baseline
394
+ - 🚀 Production - Enforcing quality
37
395
 
38
- ### Coverage Completeness (0-1)
396
+ ### `swarm eval history`
39
397
 
40
- If expected.requiredFiles specified: ratio of covered files.
41
- Otherwise: checks subtask count is within min/max range.
398
+ Shows eval run history grouped by eval name with trends and color-coded scores.
42
399
 
43
- ### Instruction Clarity (0-1)
400
+ ```bash
401
+ $ swarm eval history
402
+
403
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
404
+ swarm-decomposition (53 runs)
405
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
406
+ Run #53 0.92 2025-01-01 12:00:00 ✅ PASS
407
+ Run #52 0.89 2025-01-01 11:30:00 ✅ PASS
408
+ Run #51 0.94 2025-01-01 11:00:00 ✅ PASS
409
+ ...
410
+ Sparkline: ▁▂▃▄▅▆▇█▇▆▅▄▃▂▁▂▃▄▅▆▇█
411
+ Trend: ↗ (improving)
412
+
413
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
414
+ coordinator-behavior (8 runs)
415
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
416
+ Run #8 0.85 2025-01-01 10:00:00 ⚠️ WARN
417
+ Run #7 0.91 2025-01-01 09:30:00 ✅ PASS
418
+ ...
419
+ ```
44
420
 
45
- Average quality score per subtask based on:
421
+ **Color coding:**
422
+ - 🟢 Green: ≥0.8 (pass/high score)
423
+ - 🟡 Yellow: 0.6-0.8 (warning/medium score)
424
+ - 🔴 Red: <0.6 (fail/low score)
425
+
426
+ ### `swarm eval run` (Stub)
427
+
428
+ Placeholder for future direct eval execution from CLI.
429
+
430
+ ---
431
+
432
+ ## CI Integration
433
+
434
+ ### GitHub Actions Workflow
435
+
436
+ Progressive gates integrate with CI for PR checks:
437
+
438
+ ```yaml
439
+ # .github/workflows/eval-check.yml
440
+ name: Eval Quality Gate
441
+
442
+ on:
443
+ pull_request:
444
+ branches: [main]
445
+
446
+ jobs:
447
+ eval-gate:
448
+ runs-on: ubuntu-latest
449
+ steps:
450
+ - uses: actions/checkout@v4
451
+
452
+ - name: Setup Bun
453
+ uses: oven-sh/setup-bun@v1
454
+
455
+ - name: Install deps
456
+ run: bun install
457
+
458
+ - name: Run evals
459
+ run: bun run eval:run
460
+
461
+ - name: Check gates
462
+ run: |
463
+ # Check if any eval failed production gate
464
+ swarm eval status | grep "FAIL" && exit 1 || exit 0
465
+
466
+ - name: Post PR comment
467
+ if: failure()
468
+ uses: actions/github-script@v7
469
+ with:
470
+ script: |
471
+ // Post detailed gate failure to PR
472
+ const status = await exec.getExecOutput('swarm eval status');
473
+ github.rest.issues.createComment({
474
+ issue_number: context.issue.number,
475
+ body: `## ❌ Eval Gate Failed\n\n\`\`\`\n${status.stdout}\n\`\`\``
476
+ });
477
+ ```
46
478
 
47
- - Description length > 20 chars (+0.2)
48
- - Files specified (+0.2)
49
- - Non-generic title (+0.1)
479
+ **Gate behavior in CI:**
480
+ - Bootstrap: Always pass (collecting data)
481
+ - Stabilization: Pass but warn on >10% regression
482
+ - Production: **FAIL PR** on >5% regression
50
483
 
51
- ## Writing Evals
484
+ ---
485
+
486
+ ## Writing New Evals
487
+
488
+ ### 1. Create Eval File
52
489
 
53
490
  ```typescript
491
+ // evals/my-feature.eval.ts
54
492
  import { evalite } from "evalite";
55
- import { subtaskIndependence, coverageCompleteness } from "./scorers/index.js";
493
+ import { createScorer } from "evalite";
494
+
495
+ // Define your scorer
496
+ const myScorer = createScorer({
497
+ name: "My Quality Metric",
498
+ description: "Checks if feature meets quality bar",
499
+ scorer: async ({ output, expected, input }) => {
500
+ // Implement scoring logic
501
+ const score = /* calculate 0-1 score */;
502
+ return {
503
+ score,
504
+ message: "Details about score"
505
+ };
506
+ },
507
+ });
56
508
 
57
- evalite("My decomposition test", {
509
+ // Define the eval
510
+ evalite("My Feature Quality", {
58
511
  data: async () => {
512
+ // Load test cases
59
513
  return [
60
514
  {
61
- input: "Add OAuth authentication",
62
- expected: {
63
- minSubtasks: 3,
64
- maxSubtasks: 6,
65
- requiredFiles: ["src/auth/oauth.ts", "src/middleware/auth.ts"],
66
- },
515
+ input: "test input",
516
+ expected: { /* expected structure */ },
67
517
  },
68
518
  ];
69
519
  },
70
520
  task: async (input) => {
71
- // Call your decomposition logic here
72
- // Should return CellTree JSON as string
521
+ // Call your system under test
522
+ const output = await myFeature(input);
523
+ return output;
73
524
  },
74
- scorers: [subtaskIndependence, coverageCompleteness],
525
+ scorers: [myScorer],
75
526
  });
76
527
  ```
77
528
 
78
- ## CellTree Format
529
+ ### 2. Add to Package Scripts
79
530
 
80
- Scorers expect output as JSON string matching:
531
+ ```json
532
+ {
533
+ "scripts": {
534
+ "eval:my-feature": "bunx evalite run evals/my-feature.eval.ts"
535
+ }
536
+ }
537
+ ```
538
+
539
+ ### 3. Add Capture Points
540
+
541
+ Wire your feature to capture real execution data:
81
542
 
82
543
  ```typescript
83
- {
84
- epic: {
85
- title: string;
86
- description: string;
544
+ import { captureMyFeatureEvent } from "./eval-capture.js";
545
+
546
+ async function myFeature(input) {
547
+ const startTime = Date.now();
548
+
549
+ try {
550
+ const result = await doWork(input);
551
+
552
+ // Capture success
553
+ captureMyFeatureEvent({
554
+ input,
555
+ output: result,
556
+ duration_ms: Date.now() - startTime,
557
+ success: true,
558
+ });
559
+
560
+ return result;
561
+ } catch (error) {
562
+ // Capture failure
563
+ captureMyFeatureEvent({
564
+ input,
565
+ error: error.message,
566
+ duration_ms: Date.now() - startTime,
567
+ success: false,
568
+ });
569
+ throw error;
87
570
  }
88
- subtasks: Array<{
89
- title: string;
90
- description?: string;
91
- files?: string[];
92
- estimated_complexity?: number; // 1-3
93
- }>;
94
571
  }
95
572
  ```
96
573
 
97
- ## Fixtures
574
+ ### 4. Test Locally
98
575
 
99
- See `fixtures/decomposition-cases.ts` for example test cases covering:
576
+ ```bash
577
+ # Run your eval
578
+ bun run eval:my-feature
100
579
 
101
- - OAuth implementation
102
- - Rate limiting
103
- - TypeScript migration
104
- - Admin dashboard
105
- - Memory leak debugging
106
- - Feature flag system
580
+ # Check status
581
+ swarm eval status my-feature
107
582
 
108
- ## Coordinator Session Eval
583
+ # View history
584
+ swarm eval history
585
+ ```
109
586
 
110
- ### coordinator-session.eval.ts
587
+ ---
111
588
 
112
- Scores coordinator discipline during swarm sessions.
589
+ ## Scorer Reference
113
590
 
114
- **Data Sources:**
115
- - Real captured sessions from `~/.config/swarm-tools/sessions/*.jsonl`
116
- - Synthetic fixtures from `fixtures/coordinator-sessions.ts`
591
+ ### Scorer Pattern (Evalite v1.0)
117
592
 
118
- **Scorers:**
119
- - `violationCount` - Protocol violations (edit files, run tests, reserve files)
120
- - `spawnEfficiency` - Workers spawned / subtasks planned
121
- - `reviewThoroughness` - Reviews completed / workers finished
122
- - `timeToFirstSpawn` - Speed from decomposition to first worker spawn
123
- - `overallDiscipline` - Weighted composite score
124
-
125
- **Fixtures:**
126
- - `perfectCoordinator` - 0 violations, 100% spawn, 100% review, 30s to spawn
127
- - `badCoordinator` - 5 violations, 33% spawn, 0% review, 10min to spawn
128
- - `decentCoordinator` - 1 violation, 100% spawn, 50% review, 45s to spawn
129
-
130
- **Run:**
593
+ **IMPORTANT**: Evalite scorers are **async functions**, not objects with `.scorer` property.
594
+
595
+ ```typescript
596
+ import { createScorer } from "evalite";
597
+
598
+ // CORRECT
599
+ const myScorer = createScorer({
600
+ name: "My Scorer",
601
+ description: "What it measures",
602
+ scorer: async ({ output, expected, input }) => {
603
+ return { score: 0.8, message: "Details" };
604
+ },
605
+ });
606
+
607
+ // Use in eval
608
+ evalite("test", {
609
+ scorers: [myScorer], // Pass the scorer directly
610
+ });
611
+
612
+ // In composite scorers
613
+ const result = await childScorer({ output, expected, input });
614
+ const score = result.score ?? 0;
615
+ ```
616
+
617
+ **WRONG ❌**:
618
+ ```typescript
619
+ // Don't do this - .scorer property doesn't exist
620
+ const result = childScorer.scorer({ output, expected }); // ❌
621
+ ```
622
+
623
+ ### Custom Scorer Template
624
+
625
+ ```typescript
626
+ export const myCustomScorer = createScorer({
627
+ name: "My Custom Metric",
628
+ description: "Detailed description of what this measures and why it matters",
629
+ scorer: async ({ output, expected, input }) => {
630
+ // 1. Parse output
631
+ let data;
632
+ try {
633
+ data = typeof output === "string" ? JSON.parse(output) : output;
634
+ } catch {
635
+ return { score: 0, message: "Invalid output format" };
636
+ }
637
+
638
+ // 2. Calculate score (0-1 range)
639
+ const score = calculateYourMetric(data, expected);
640
+
641
+ // 3. Return with detailed message
642
+ return {
643
+ score,
644
+ message: `Score: ${score.toFixed(2)} - ${getExplanation(score)}`,
645
+ };
646
+ },
647
+ });
648
+ ```
649
+
650
+ ---
651
+
652
+ ## Troubleshooting
653
+
654
+ ### "No eval history found"
655
+
656
+ **Cause:** Haven't run any evals yet or `.opencode/eval-history.jsonl` missing.
657
+
658
+ **Fix:**
131
659
  ```bash
132
- bunx evalite run evals/coordinator-session.eval.ts
660
+ # Run an eval to create history
661
+ bun run eval:decomposition
662
+ swarm eval status # Should show bootstrap phase
133
663
  ```
134
664
 
135
- ## Data Capture
665
+ ### "Phase stuck in stabilization despite >50 runs"
136
666
 
137
- ### What Gets Captured
667
+ **Cause:** High variance (≥0.1). Scores not consistent enough for production phase.
668
+
669
+ **Fix:** Investigate why scores fluctuate:
670
+ ```bash
671
+ # Check variance
672
+ swarm eval status my-eval # Shows variance value
673
+
674
+ # View score history to spot outliers
675
+ swarm eval history
676
+
677
+ # Common causes:
678
+ # - Eval depends on external state (network, filesystem)
679
+ # - Non-deterministic scoring logic
680
+ # - Input data changing between runs
681
+ ```
682
+
683
+ ### "Gate failing on minor changes"
684
+
685
+ **Cause:** Production phase threshold (5%) too strict for your use case.
686
+
687
+ **Fix:** Adjust threshold in eval code:
688
+ ```typescript
689
+ import { checkGate } from "../src/eval-gates.js";
690
+
691
+ const result = checkGate(projectPath, evalName, score, {
692
+ productionThreshold: 0.10, // 10% instead of 5%
693
+ });
694
+ ```
695
+
696
+ ### "Evalite not finding my eval file"
138
697
 
139
- **Decomposition Eval Data:**
140
- - Task input (user's original request)
141
- - Generated CellTree JSON (epic + subtasks)
142
- - Timestamp and context
143
- - Stored in: `.opencode/eval-data.jsonl`
698
+ **Cause:** File not matching `*.eval.ts` pattern or not in `evals/` directory.
144
699
 
145
- **Coordinator Session Data:**
146
- - Real swarm sessions captured during `/swarm` runs
147
- - Includes: decomposition, spawn events, reviews, violations
148
- - Stored in: `~/.config/swarm-tools/sessions/*.jsonl`
700
+ **Fix:**
701
+ ```bash
702
+ # Ensure file is named correctly
703
+ mv evals/my-test.ts evals/my-test.eval.ts
149
704
 
150
- **Subtask Outcome Data:**
151
- - Duration, success/failure, error count, retry count
152
- - Files touched, strategy used
153
- - Used for learning and pattern maturity
154
- - Stored in: swarm-mail database (libSQL)
705
+ # Verify discovery
706
+ bunx evalite run evals/ # Should list your eval
707
+ ```
708
+
709
+ ### "Scorers returning undefined"
710
+
711
+ **Cause:** Forgot to `await` async scorers or accessing `.scorer` property (doesn't exist).
712
+
713
+ **Fix:**
714
+ ```typescript
715
+ // CORRECT ✅
716
+ const result = await myScorer({ output, expected, input });
717
+ const score = result.score ?? 0;
718
+
719
+ // WRONG ❌
720
+ const result = myScorer.scorer({ output, expected }); // .scorer doesn't exist
721
+ ```
722
+
723
+ ---
724
+
725
+ ## File Structure
726
+
727
+ ```
728
+ evals/
729
+ ├── README.md # This file
730
+ ├── evalite.config.ts # Evalite configuration
731
+
732
+ ├── fixtures/
733
+ │ ├── decomposition-cases.ts # Test cases for decomposition
734
+ │ ├── coordinator-sessions.ts # Known good/bad coordinator sessions
735
+ │ └── compaction-prompts.ts # Sample compaction prompts
736
+
737
+ ├── lib/
738
+ │ ├── data-loader.ts # Load eval data from JSONL files
739
+ │ └── test-helpers.ts # Shared test utilities
740
+
741
+ ├── scorers/
742
+ │ ├── decomposition-scorers.ts # Subtask quality scorers
743
+ │ ├── coordinator-scorers.ts # Protocol adherence scorers
744
+ │ └── compaction-prompt-scorers.ts # Prompt quality scorers
745
+
746
+ ├── swarm-decomposition.eval.ts # Decomposition quality eval
747
+ ├── coordinator-session.eval.ts # Coordinator discipline eval
748
+ ├── compaction-prompt.eval.ts # Compaction prompt quality eval
749
+ └── example.eval.ts # Sanity check / template
750
+ ```
155
751
 
156
- ### Data Loaders
752
+ **Data locations:**
753
+ - `.opencode/eval-data.jsonl` - Decomposition captures
754
+ - `.opencode/eval-history.jsonl` - Score history
755
+ - `~/.config/swarm-tools/sessions/*.jsonl` - Coordinator sessions
157
756
 
158
- **lib/data-loader.ts** provides utilities to load eval data:
757
+ ---
159
758
 
160
- - `loadEvalCases()` - Load eval records from swarm-mail database
161
- - `loadCapturedSessions()` - Real coordinator sessions from `~/.config/swarm-tools/sessions/`
162
- - `hasRealEvalData()` - Check if enough real data exists
163
- - `getEvalDataSummary()` - Stats about available eval data
759
+ ## Further Reading
164
760
 
165
- ## Notes
761
+ - **[Evalite Docs](https://evalite.dev)** - Evaluation framework
762
+ - **[Progressive Gates Implementation](../src/eval-gates.ts)** - Phase-based quality control
763
+ - **[Learning Feedback Loop](../src/eval-learning.ts)** - Auto-store failures to memory
764
+ - **[Data Capture](../src/eval-capture.ts)** - Real execution tracking
765
+ - **[Compaction Scorers](../src/compaction-prompt-scoring.ts)** - Pure scoring functions
166
766
 
167
- - Evalite v1.0.0-beta.15 installed
168
- - Built on Vitest
169
- - Runs locally, no API keys required
170
- - Results cached in `node_modules/.evalite/`
171
- - Clear cache if needed: `rm -rf node_modules/.evalite`
767
+ > _"Measure outcomes, not outputs. The system that learns from failure beats the system that avoids it."_
768
+ > Inspired by Site Reliability Engineering principles