opencode-swarm-plugin 0.44.0 → 0.44.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 (205) hide show
  1. package/bin/swarm.serve.test.ts +6 -4
  2. package/bin/swarm.ts +16 -10
  3. package/dist/compaction-prompt-scoring.js +139 -0
  4. package/dist/eval-capture.js +12811 -0
  5. package/dist/hive.d.ts.map +1 -1
  6. package/dist/index.js +7644 -62599
  7. package/dist/plugin.js +23766 -78721
  8. package/dist/swarm-orchestrate.d.ts.map +1 -1
  9. package/dist/swarm-prompts.d.ts.map +1 -1
  10. package/dist/swarm-review.d.ts.map +1 -1
  11. package/package.json +17 -5
  12. package/.changeset/swarm-insights-data-layer.md +0 -63
  13. package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
  14. package/.hive/analysis/session-data-quality-audit.md +0 -320
  15. package/.hive/eval-results.json +0 -483
  16. package/.hive/issues.jsonl +0 -138
  17. package/.hive/memories.jsonl +0 -729
  18. package/.opencode/eval-history.jsonl +0 -327
  19. package/.turbo/turbo-build.log +0 -9
  20. package/CHANGELOG.md +0 -2286
  21. package/SCORER-ANALYSIS.md +0 -598
  22. package/docs/analysis/subagent-coordination-patterns.md +0 -902
  23. package/docs/analysis-socratic-planner-pattern.md +0 -504
  24. package/docs/planning/ADR-001-monorepo-structure.md +0 -171
  25. package/docs/planning/ADR-002-package-extraction.md +0 -393
  26. package/docs/planning/ADR-003-performance-improvements.md +0 -451
  27. package/docs/planning/ADR-004-message-queue-features.md +0 -187
  28. package/docs/planning/ADR-005-devtools-observability.md +0 -202
  29. package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
  30. package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
  31. package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
  32. package/docs/planning/ADR-010-cass-inhousing.md +0 -1215
  33. package/docs/planning/ROADMAP.md +0 -368
  34. package/docs/semantic-memory-cli-syntax.md +0 -123
  35. package/docs/swarm-mail-architecture.md +0 -1147
  36. package/docs/testing/context-recovery-test.md +0 -470
  37. package/evals/ARCHITECTURE.md +0 -1189
  38. package/evals/README.md +0 -768
  39. package/evals/compaction-prompt.eval.ts +0 -149
  40. package/evals/compaction-resumption.eval.ts +0 -289
  41. package/evals/coordinator-behavior.eval.ts +0 -307
  42. package/evals/coordinator-session.eval.ts +0 -154
  43. package/evals/evalite.config.ts.bak +0 -15
  44. package/evals/example.eval.ts +0 -31
  45. package/evals/fixtures/cass-baseline.ts +0 -217
  46. package/evals/fixtures/compaction-cases.ts +0 -350
  47. package/evals/fixtures/compaction-prompt-cases.ts +0 -311
  48. package/evals/fixtures/coordinator-sessions.ts +0 -328
  49. package/evals/fixtures/decomposition-cases.ts +0 -105
  50. package/evals/lib/compaction-loader.test.ts +0 -248
  51. package/evals/lib/compaction-loader.ts +0 -320
  52. package/evals/lib/data-loader.evalite-test.ts +0 -289
  53. package/evals/lib/data-loader.test.ts +0 -345
  54. package/evals/lib/data-loader.ts +0 -281
  55. package/evals/lib/llm.ts +0 -115
  56. package/evals/scorers/compaction-prompt-scorers.ts +0 -145
  57. package/evals/scorers/compaction-scorers.ts +0 -305
  58. package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
  59. package/evals/scorers/coordinator-discipline.ts +0 -325
  60. package/evals/scorers/index.test.ts +0 -146
  61. package/evals/scorers/index.ts +0 -328
  62. package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
  63. package/evals/scorers/outcome-scorers.ts +0 -349
  64. package/evals/swarm-decomposition.eval.ts +0 -121
  65. package/examples/commands/swarm.md +0 -745
  66. package/examples/plugin-wrapper-template.ts +0 -2515
  67. package/examples/skills/hive-workflow/SKILL.md +0 -212
  68. package/examples/skills/skill-creator/SKILL.md +0 -223
  69. package/examples/skills/swarm-coordination/SKILL.md +0 -292
  70. package/global-skills/cli-builder/SKILL.md +0 -344
  71. package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
  72. package/global-skills/learning-systems/SKILL.md +0 -644
  73. package/global-skills/skill-creator/LICENSE.txt +0 -202
  74. package/global-skills/skill-creator/SKILL.md +0 -352
  75. package/global-skills/skill-creator/references/output-patterns.md +0 -82
  76. package/global-skills/skill-creator/references/workflows.md +0 -28
  77. package/global-skills/swarm-coordination/SKILL.md +0 -995
  78. package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
  79. package/global-skills/swarm-coordination/references/strategies.md +0 -138
  80. package/global-skills/system-design/SKILL.md +0 -213
  81. package/global-skills/testing-patterns/SKILL.md +0 -430
  82. package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
  83. package/opencode-swarm-plugin-0.30.7.tgz +0 -0
  84. package/opencode-swarm-plugin-0.31.0.tgz +0 -0
  85. package/scripts/cleanup-test-memories.ts +0 -346
  86. package/scripts/init-skill.ts +0 -222
  87. package/scripts/migrate-unknown-sessions.ts +0 -349
  88. package/scripts/validate-skill.ts +0 -204
  89. package/src/agent-mail.ts +0 -1724
  90. package/src/anti-patterns.test.ts +0 -1167
  91. package/src/anti-patterns.ts +0 -448
  92. package/src/compaction-capture.integration.test.ts +0 -257
  93. package/src/compaction-hook.test.ts +0 -838
  94. package/src/compaction-hook.ts +0 -1204
  95. package/src/compaction-observability.integration.test.ts +0 -139
  96. package/src/compaction-observability.test.ts +0 -187
  97. package/src/compaction-observability.ts +0 -324
  98. package/src/compaction-prompt-scorers.test.ts +0 -475
  99. package/src/compaction-prompt-scoring.ts +0 -300
  100. package/src/contributor-tools.test.ts +0 -133
  101. package/src/contributor-tools.ts +0 -201
  102. package/src/dashboard.test.ts +0 -611
  103. package/src/dashboard.ts +0 -462
  104. package/src/error-enrichment.test.ts +0 -403
  105. package/src/error-enrichment.ts +0 -219
  106. package/src/eval-capture.test.ts +0 -1015
  107. package/src/eval-capture.ts +0 -929
  108. package/src/eval-gates.test.ts +0 -306
  109. package/src/eval-gates.ts +0 -218
  110. package/src/eval-history.test.ts +0 -508
  111. package/src/eval-history.ts +0 -214
  112. package/src/eval-learning.test.ts +0 -378
  113. package/src/eval-learning.ts +0 -360
  114. package/src/eval-runner.test.ts +0 -223
  115. package/src/eval-runner.ts +0 -402
  116. package/src/export-tools.test.ts +0 -476
  117. package/src/export-tools.ts +0 -257
  118. package/src/hive.integration.test.ts +0 -2241
  119. package/src/hive.ts +0 -1628
  120. package/src/index.ts +0 -940
  121. package/src/learning.integration.test.ts +0 -1815
  122. package/src/learning.ts +0 -1079
  123. package/src/logger.test.ts +0 -189
  124. package/src/logger.ts +0 -135
  125. package/src/mandate-promotion.test.ts +0 -473
  126. package/src/mandate-promotion.ts +0 -239
  127. package/src/mandate-storage.integration.test.ts +0 -601
  128. package/src/mandate-storage.test.ts +0 -578
  129. package/src/mandate-storage.ts +0 -794
  130. package/src/mandates.ts +0 -540
  131. package/src/memory-tools.test.ts +0 -195
  132. package/src/memory-tools.ts +0 -344
  133. package/src/memory.integration.test.ts +0 -334
  134. package/src/memory.test.ts +0 -158
  135. package/src/memory.ts +0 -527
  136. package/src/model-selection.test.ts +0 -188
  137. package/src/model-selection.ts +0 -68
  138. package/src/observability-tools.test.ts +0 -359
  139. package/src/observability-tools.ts +0 -871
  140. package/src/output-guardrails.test.ts +0 -438
  141. package/src/output-guardrails.ts +0 -381
  142. package/src/pattern-maturity.test.ts +0 -1160
  143. package/src/pattern-maturity.ts +0 -525
  144. package/src/planning-guardrails.test.ts +0 -491
  145. package/src/planning-guardrails.ts +0 -438
  146. package/src/plugin.ts +0 -23
  147. package/src/post-compaction-tracker.test.ts +0 -251
  148. package/src/post-compaction-tracker.ts +0 -237
  149. package/src/query-tools.test.ts +0 -636
  150. package/src/query-tools.ts +0 -324
  151. package/src/rate-limiter.integration.test.ts +0 -466
  152. package/src/rate-limiter.ts +0 -774
  153. package/src/replay-tools.test.ts +0 -496
  154. package/src/replay-tools.ts +0 -240
  155. package/src/repo-crawl.integration.test.ts +0 -441
  156. package/src/repo-crawl.ts +0 -610
  157. package/src/schemas/cell-events.test.ts +0 -347
  158. package/src/schemas/cell-events.ts +0 -807
  159. package/src/schemas/cell.ts +0 -257
  160. package/src/schemas/evaluation.ts +0 -166
  161. package/src/schemas/index.test.ts +0 -199
  162. package/src/schemas/index.ts +0 -286
  163. package/src/schemas/mandate.ts +0 -232
  164. package/src/schemas/swarm-context.ts +0 -115
  165. package/src/schemas/task.ts +0 -161
  166. package/src/schemas/worker-handoff.test.ts +0 -302
  167. package/src/schemas/worker-handoff.ts +0 -131
  168. package/src/sessions/agent-discovery.test.ts +0 -137
  169. package/src/sessions/agent-discovery.ts +0 -112
  170. package/src/sessions/index.ts +0 -15
  171. package/src/skills.integration.test.ts +0 -1192
  172. package/src/skills.test.ts +0 -643
  173. package/src/skills.ts +0 -1549
  174. package/src/storage.integration.test.ts +0 -341
  175. package/src/storage.ts +0 -884
  176. package/src/structured.integration.test.ts +0 -817
  177. package/src/structured.test.ts +0 -1046
  178. package/src/structured.ts +0 -762
  179. package/src/swarm-decompose.test.ts +0 -188
  180. package/src/swarm-decompose.ts +0 -1302
  181. package/src/swarm-deferred.integration.test.ts +0 -157
  182. package/src/swarm-deferred.test.ts +0 -38
  183. package/src/swarm-insights.test.ts +0 -214
  184. package/src/swarm-insights.ts +0 -459
  185. package/src/swarm-mail.integration.test.ts +0 -970
  186. package/src/swarm-mail.ts +0 -739
  187. package/src/swarm-orchestrate.integration.test.ts +0 -282
  188. package/src/swarm-orchestrate.test.ts +0 -548
  189. package/src/swarm-orchestrate.ts +0 -3084
  190. package/src/swarm-prompts.test.ts +0 -1270
  191. package/src/swarm-prompts.ts +0 -2077
  192. package/src/swarm-research.integration.test.ts +0 -701
  193. package/src/swarm-research.test.ts +0 -698
  194. package/src/swarm-research.ts +0 -472
  195. package/src/swarm-review.integration.test.ts +0 -285
  196. package/src/swarm-review.test.ts +0 -879
  197. package/src/swarm-review.ts +0 -709
  198. package/src/swarm-strategies.ts +0 -407
  199. package/src/swarm-worktree.test.ts +0 -501
  200. package/src/swarm-worktree.ts +0 -575
  201. package/src/swarm.integration.test.ts +0 -2377
  202. package/src/swarm.ts +0 -38
  203. package/src/tool-adapter.integration.test.ts +0 -1221
  204. package/src/tool-availability.ts +0 -461
  205. package/tsconfig.json +0 -28
@@ -1,807 +0,0 @@
1
- /**
2
- * Event Types for Cells Event Sourcing
3
- *
4
- * These events form an audit trail for all cell operations.
5
- * Events are NOT replayed for state reconstruction (cells uses hybrid CRUD + audit trail).
6
- * Events enable:
7
- * - Full audit history
8
- * - Debugging distributed swarm operations
9
- * - Learning from cell lifecycle patterns
10
- * - Integration with swarm-mail coordination
11
- *
12
- * Design notes:
13
- * - 75% reusable infrastructure from swarm-mail
14
- * - Events stay local (PGLite/SQLite), not written to JSONL
15
- * - JSONL export happens from projection snapshots (proven git merge driver)
16
- * - Follows same BaseEventSchema pattern as swarm-mail
17
- */
18
- import { z } from "zod";
19
- import {
20
- CellDependencySchema,
21
- CellStatusSchema,
22
- CellTypeSchema,
23
- } from "./cell.js";
24
-
25
- // ============================================================================
26
- // Base Event Schema (mirrors swarm-mail pattern)
27
- // ============================================================================
28
-
29
- /**
30
- * Base fields present on all cell events
31
- */
32
- export const BaseCellEventSchema = z.object({
33
- /** Auto-generated event ID */
34
- id: z.number().optional(),
35
- /** Event type discriminator */
36
- type: z.string(),
37
- /** Project key (usually absolute path) */
38
- project_key: z.string(),
39
- /** Timestamp when event occurred */
40
- timestamp: z.number(), // Unix ms
41
- /** Sequence number for ordering */
42
- sequence: z.number().optional(),
43
- });
44
-
45
- // ============================================================================
46
- // Issue Lifecycle Events
47
- // ============================================================================
48
-
49
- /**
50
- * Cell created
51
- *
52
- * Emitted when:
53
- * - User calls `hive create`
54
- * - Swarm epic decomposition creates subtasks
55
- * - Agent spawns new cells during work
56
- */
57
- export const CellCreatedEventSchema = BaseCellEventSchema.extend({
58
- type: z.literal("cell_created"),
59
- cell_id: z.string(),
60
- title: z.string(),
61
- description: z.string().optional(),
62
- issue_type: CellTypeSchema,
63
- priority: z.number().int().min(0).max(3),
64
- parent_id: z.string().optional(),
65
- /** Agent/user who created the cell */
66
- created_by: z.string().optional(),
67
- /** Metadata for tracking (e.g., epic context, swarm strategy) */
68
- metadata: z.record(z.string(), z.unknown()).optional(),
69
- });
70
-
71
- /**
72
- * Cell updated (generic field changes)
73
- *
74
- * Emitted for non-status field updates: title, description, priority
75
- */
76
- export const CellUpdatedEventSchema = BaseCellEventSchema.extend({
77
- type: z.literal("cell_updated"),
78
- cell_id: z.string(),
79
- /** Agent/user who made the update */
80
- updated_by: z.string().optional(),
81
- /** Changed fields with old and new values */
82
- changes: z.object({
83
- title: z
84
- .object({
85
- old: z.string(),
86
- new: z.string(),
87
- })
88
- .optional(),
89
- description: z
90
- .object({
91
- old: z.string(),
92
- new: z.string(),
93
- })
94
- .optional(),
95
- priority: z
96
- .object({
97
- old: z.number(),
98
- new: z.number(),
99
- })
100
- .optional(),
101
- }),
102
- });
103
-
104
- /**
105
- * Cell status changed
106
- *
107
- * Separate event for status transitions to enable workflow analysis.
108
- * Tracks state machine: open → in_progress → (blocked | closed)
109
- */
110
- export const CellStatusChangedEventSchema = BaseCellEventSchema.extend({
111
- type: z.literal("cell_status_changed"),
112
- cell_id: z.string(),
113
- from_status: CellStatusSchema,
114
- to_status: CellStatusSchema,
115
- /** Agent/user who changed status */
116
- changed_by: z.string().optional(),
117
- /** Optional reason (required for closed status) */
118
- reason: z.string().optional(),
119
- });
120
-
121
- /**
122
- * Cell closed
123
- *
124
- * Explicit close event (subset of status_changed for convenience).
125
- * Includes closure reason for audit trail.
126
- */
127
- export const CellClosedEventSchema = BaseCellEventSchema.extend({
128
- type: z.literal("cell_closed"),
129
- cell_id: z.string(),
130
- reason: z.string(),
131
- /** Agent/user who closed */
132
- closed_by: z.string().optional(),
133
- /** Files touched during work (from swarm completion) */
134
- files_touched: z.array(z.string()).optional(),
135
- /** Duration in ms (if tracked by agent) */
136
- duration_ms: z.number().optional(),
137
- });
138
-
139
- /**
140
- * Cell reopened
141
- *
142
- * Emitted when closed cell is reopened.
143
- */
144
- export const CellReopenedEventSchema = BaseCellEventSchema.extend({
145
- type: z.literal("cell_reopened"),
146
- cell_id: z.string(),
147
- reason: z.string().optional(),
148
- /** Agent/user who reopened */
149
- reopened_by: z.string().optional(),
150
- });
151
-
152
- /**
153
- * Cell deleted
154
- *
155
- * Hard delete event (rare - cells are usually closed, not deleted).
156
- * Useful for cleaning up spurious/duplicate cells.
157
- */
158
- export const CellDeletedEventSchema = BaseCellEventSchema.extend({
159
- type: z.literal("cell_deleted"),
160
- cell_id: z.string(),
161
- reason: z.string().optional(),
162
- /** Agent/user who deleted */
163
- deleted_by: z.string().optional(),
164
- });
165
-
166
- // ============================================================================
167
- // Dependency Events
168
- // ============================================================================
169
-
170
- /**
171
- * Dependency added between cells
172
- *
173
- * Supports 4 relationship types:
174
- * - blocks: This cell blocks the target
175
- * - blocked-by: This cell is blocked by the target
176
- * - related: Informational link
177
- * - discovered-from: Cell spawned from investigation of target
178
- */
179
- export const CellDependencyAddedEventSchema = BaseCellEventSchema.extend({
180
- type: z.literal("cell_dependency_added"),
181
- cell_id: z.string(),
182
- /** Dependency relationship */
183
- dependency: CellDependencySchema,
184
- /** Agent/user who added dependency */
185
- added_by: z.string().optional(),
186
- /** Optional reason (e.g., "needs auth service before OAuth implementation") */
187
- reason: z.string().optional(),
188
- });
189
-
190
- /**
191
- * Dependency removed
192
- *
193
- * Emitted when dependency is no longer relevant or was added in error.
194
- */
195
- export const CellDependencyRemovedEventSchema = BaseCellEventSchema.extend({
196
- type: z.literal("cell_dependency_removed"),
197
- cell_id: z.string(),
198
- /** Dependency being removed */
199
- dependency: CellDependencySchema,
200
- /** Agent/user who removed */
201
- removed_by: z.string().optional(),
202
- reason: z.string().optional(),
203
- });
204
-
205
- // ============================================================================
206
- // Label Events
207
- // ============================================================================
208
-
209
- /**
210
- * Label added to cell
211
- *
212
- * Labels are string tags for categorization/filtering.
213
- * Common labels: "p0", "needs-review", "blocked-external", "tech-debt"
214
- */
215
- export const CellLabelAddedEventSchema = BaseCellEventSchema.extend({
216
- type: z.literal("cell_label_added"),
217
- cell_id: z.string(),
218
- label: z.string(),
219
- /** Agent/user who added label */
220
- added_by: z.string().optional(),
221
- });
222
-
223
- /**
224
- * Label removed from cell
225
- */
226
- export const CellLabelRemovedEventSchema = BaseCellEventSchema.extend({
227
- type: z.literal("cell_label_removed"),
228
- cell_id: z.string(),
229
- label: z.string(),
230
- /** Agent/user who removed label */
231
- removed_by: z.string().optional(),
232
- });
233
-
234
- // ============================================================================
235
- // Comment Events
236
- // ============================================================================
237
-
238
- /**
239
- * Comment added to cell
240
- *
241
- * Supports agent-to-agent communication, human notes, and progress updates.
242
- */
243
- export const CellCommentAddedEventSchema = BaseCellEventSchema.extend({
244
- type: z.literal("cell_comment_added"),
245
- cell_id: z.string(),
246
- /** Auto-generated comment ID */
247
- comment_id: z.number().optional(),
248
- author: z.string(),
249
- body: z.string(),
250
- /** Optional parent comment ID for threading */
251
- parent_comment_id: z.number().optional(),
252
- /** Comment metadata (e.g., attachments, mentions) */
253
- metadata: z.record(z.string(), z.unknown()).optional(),
254
- });
255
-
256
- /**
257
- * Comment updated (edit)
258
- */
259
- export const CellCommentUpdatedEventSchema = BaseCellEventSchema.extend({
260
- type: z.literal("cell_comment_updated"),
261
- cell_id: z.string(),
262
- comment_id: z.number(),
263
- old_body: z.string(),
264
- new_body: z.string(),
265
- updated_by: z.string(),
266
- });
267
-
268
- /**
269
- * Comment deleted
270
- */
271
- export const CellCommentDeletedEventSchema = BaseCellEventSchema.extend({
272
- type: z.literal("cell_comment_deleted"),
273
- cell_id: z.string(),
274
- comment_id: z.number(),
275
- deleted_by: z.string(),
276
- reason: z.string().optional(),
277
- });
278
-
279
- // ============================================================================
280
- // Epic Events
281
- // ============================================================================
282
-
283
- /**
284
- * Child cell added to epic
285
- *
286
- * Emitted when:
287
- * - Epic created with subtasks (batch event for each child)
288
- * - User manually adds child via `hive add-child`
289
- * - Agent spawns additional subtask during work
290
- */
291
- export const CellEpicChildAddedEventSchema = BaseCellEventSchema.extend({
292
- type: z.literal("cell_epic_child_added"),
293
- /** Epic ID */
294
- cell_id: z.string(),
295
- /** Child cell ID */
296
- child_id: z.string(),
297
- /** Optional index for ordering */
298
- child_index: z.number().optional(),
299
- added_by: z.string().optional(),
300
- });
301
-
302
- /**
303
- * Child cell removed from epic
304
- *
305
- * Rare - usually happens when subtask is merged/consolidated.
306
- */
307
- export const CellEpicChildRemovedEventSchema = BaseCellEventSchema.extend({
308
- type: z.literal("cell_epic_child_removed"),
309
- /** Epic ID */
310
- cell_id: z.string(),
311
- /** Child cell ID */
312
- child_id: z.string(),
313
- removed_by: z.string().optional(),
314
- reason: z.string().optional(),
315
- });
316
-
317
- /**
318
- * Epic eligible for closure
319
- *
320
- * Emitted when all child cells are closed.
321
- * Triggers coordinator review for epic closure.
322
- */
323
- export const CellEpicClosureEligibleEventSchema = BaseCellEventSchema.extend({
324
- type: z.literal("cell_epic_closure_eligible"),
325
- cell_id: z.string(),
326
- /** Child cell IDs (all closed) */
327
- child_ids: z.array(z.string()),
328
- /** Total duration across all children */
329
- total_duration_ms: z.number().optional(),
330
- /** Aggregate file changes */
331
- all_files_touched: z.array(z.string()).optional(),
332
- });
333
-
334
- // ============================================================================
335
- // Swarm Integration Events (bridge to swarm-mail)
336
- // ============================================================================
337
-
338
- /**
339
- * Cell assigned to agent
340
- *
341
- * Links cells to swarm-mail's agent tracking.
342
- * Emitted when agent calls `cells_start` or swarm spawns worker.
343
- */
344
- export const CellAssignedEventSchema = BaseCellEventSchema.extend({
345
- type: z.literal("cell_assigned"),
346
- cell_id: z.string(),
347
- agent_name: z.string(),
348
- /** Agent's task description for context */
349
- task_description: z.string().optional(),
350
- });
351
-
352
- /**
353
- * Cell work started
354
- *
355
- * Separate from status change to track actual work start time.
356
- * Useful for duration/velocity metrics.
357
- */
358
- export const CellWorkStartedEventSchema = BaseCellEventSchema.extend({
359
- type: z.literal("cell_work_started"),
360
- cell_id: z.string(),
361
- agent_name: z.string(),
362
- /** Files reserved for this work */
363
- reserved_files: z.array(z.string()).optional(),
364
- });
365
-
366
- /**
367
- * Cell compacted
368
- *
369
- * Emitted when cell's event history is compressed (rare).
370
- * Follows steveyegge/beads pattern - old events archived, projection preserved.
371
- */
372
- export const CellCompactedEventSchema = BaseCellEventSchema.extend({
373
- type: z.literal("cell_compacted"),
374
- cell_id: z.string(),
375
- /** Number of events archived */
376
- events_archived: z.number(),
377
- /** New event store start sequence */
378
- new_start_sequence: z.number(),
379
- });
380
-
381
- // ============================================================================
382
- // Union Type
383
- // ============================================================================
384
-
385
- export const CellEventSchema = z.discriminatedUnion("type", [
386
- // Lifecycle
387
- CellCreatedEventSchema,
388
- CellUpdatedEventSchema,
389
- CellStatusChangedEventSchema,
390
- CellClosedEventSchema,
391
- CellReopenedEventSchema,
392
- CellDeletedEventSchema,
393
-
394
- // Dependencies
395
- CellDependencyAddedEventSchema,
396
- CellDependencyRemovedEventSchema,
397
-
398
- // Labels
399
- CellLabelAddedEventSchema,
400
- CellLabelRemovedEventSchema,
401
-
402
- // Comments
403
- CellCommentAddedEventSchema,
404
- CellCommentUpdatedEventSchema,
405
- CellCommentDeletedEventSchema,
406
-
407
- // Epic
408
- CellEpicChildAddedEventSchema,
409
- CellEpicChildRemovedEventSchema,
410
- CellEpicClosureEligibleEventSchema,
411
-
412
- // Swarm Integration
413
- CellAssignedEventSchema,
414
- CellWorkStartedEventSchema,
415
-
416
- // Maintenance
417
- CellCompactedEventSchema,
418
- ]);
419
-
420
- export type CellEvent = z.infer<typeof CellEventSchema>;
421
-
422
- // ============================================================================
423
- // Individual event types for convenience
424
- // ============================================================================
425
-
426
- export type CellCreatedEvent = z.infer<typeof CellCreatedEventSchema>;
427
- export type CellUpdatedEvent = z.infer<typeof CellUpdatedEventSchema>;
428
- export type CellStatusChangedEvent = z.infer<
429
- typeof CellStatusChangedEventSchema
430
- >;
431
- export type CellClosedEvent = z.infer<typeof CellClosedEventSchema>;
432
- export type CellReopenedEvent = z.infer<typeof CellReopenedEventSchema>;
433
- export type CellDeletedEvent = z.infer<typeof CellDeletedEventSchema>;
434
- export type CellDependencyAddedEvent = z.infer<
435
- typeof CellDependencyAddedEventSchema
436
- >;
437
- export type CellDependencyRemovedEvent = z.infer<
438
- typeof CellDependencyRemovedEventSchema
439
- >;
440
- export type CellLabelAddedEvent = z.infer<typeof CellLabelAddedEventSchema>;
441
- export type CellLabelRemovedEvent = z.infer<typeof CellLabelRemovedEventSchema>;
442
- export type CellCommentAddedEvent = z.infer<typeof CellCommentAddedEventSchema>;
443
- export type CellCommentUpdatedEvent = z.infer<
444
- typeof CellCommentUpdatedEventSchema
445
- >;
446
- export type CellCommentDeletedEvent = z.infer<
447
- typeof CellCommentDeletedEventSchema
448
- >;
449
- export type CellEpicChildAddedEvent = z.infer<
450
- typeof CellEpicChildAddedEventSchema
451
- >;
452
- export type CellEpicChildRemovedEvent = z.infer<
453
- typeof CellEpicChildRemovedEventSchema
454
- >;
455
- export type CellEpicClosureEligibleEvent = z.infer<
456
- typeof CellEpicClosureEligibleEventSchema
457
- >;
458
- export type CellAssignedEvent = z.infer<typeof CellAssignedEventSchema>;
459
- export type CellWorkStartedEvent = z.infer<typeof CellWorkStartedEventSchema>;
460
- export type CellCompactedEvent = z.infer<typeof CellCompactedEventSchema>;
461
-
462
- // ============================================================================
463
- // Event Helpers
464
- // ============================================================================
465
-
466
- /**
467
- * Create a cell event with timestamp and validate
468
- *
469
- * Usage:
470
- * ```typescript
471
- * const event = createCellEvent("cell_created", {
472
- * project_key: "/path/to/repo",
473
- * cell_id: "bd-123",
474
- * title: "Add auth",
475
- * issue_type: "feature",
476
- * priority: 2
477
- * });
478
- * ```
479
- */
480
- export function createCellEvent<T extends CellEvent["type"]>(
481
- type: T,
482
- data: Omit<
483
- Extract<CellEvent, { type: T }>,
484
- "type" | "timestamp" | "id" | "sequence"
485
- >,
486
- ): Extract<CellEvent, { type: T }> {
487
- const event = {
488
- type,
489
- timestamp: Date.now(),
490
- ...data,
491
- } as Extract<CellEvent, { type: T }>;
492
-
493
- // Validate
494
- const result = CellEventSchema.safeParse(event);
495
- if (!result.success) {
496
- throw new Error(`Invalid cell event: ${result.error.message}`);
497
- }
498
-
499
- return result.data as Extract<CellEvent, { type: T }>;
500
- }
501
-
502
- /**
503
- * Type guard for specific cell event types
504
- *
505
- * Usage:
506
- * ```typescript
507
- * if (isCellEventType(event, "cell_closed")) {
508
- * console.log(event.reason); // TypeScript knows this is CellClosedEvent
509
- * }
510
- * ```
511
- */
512
- export function isCellEventType<T extends CellEvent["type"]>(
513
- event: CellEvent,
514
- type: T,
515
- ): event is Extract<CellEvent, { type: T }> {
516
- return event.type === type;
517
- }
518
-
519
- /**
520
- * Extract cell ID from event (convenience helper)
521
- *
522
- * All cell events have cell_id field (or it's the epic's cell_id for epic events).
523
- */
524
- export function getCellIdFromEvent(event: CellEvent): string {
525
- return event.cell_id;
526
- }
527
-
528
- /**
529
- * Check if event represents a state transition
530
- */
531
- export function isStateTransitionEvent(
532
- event: CellEvent,
533
- ): event is CellStatusChangedEvent | CellClosedEvent | CellReopenedEvent {
534
- return (
535
- event.type === "cell_status_changed" ||
536
- event.type === "cell_closed" ||
537
- event.type === "cell_reopened"
538
- );
539
- }
540
-
541
- /**
542
- * Check if event represents an epic operation
543
- */
544
- export function isEpicEvent(
545
- event: CellEvent,
546
- ): event is
547
- | CellEpicChildAddedEvent
548
- | CellEpicChildRemovedEvent
549
- | CellEpicClosureEligibleEvent {
550
- return (
551
- event.type === "cell_epic_child_added" ||
552
- event.type === "cell_epic_child_removed" ||
553
- event.type === "cell_epic_closure_eligible"
554
- );
555
- }
556
-
557
- /**
558
- * Check if event was triggered by an agent (vs human user)
559
- */
560
- export function isAgentEvent(event: CellEvent): boolean {
561
- // Agent events have agent_name field or *_by field containing agent signature
562
- if ("agent_name" in event) return true;
563
-
564
- const actorFields = [
565
- "created_by",
566
- "updated_by",
567
- "changed_by",
568
- "closed_by",
569
- "deleted_by",
570
- "added_by",
571
- "removed_by",
572
- "reopened_by",
573
- ] as const;
574
-
575
- return actorFields.some((field) => {
576
- if (field in event) {
577
- const value = (event as Record<string, unknown>)[field];
578
- // Agent names are typically lowercase or have specific patterns
579
- return typeof value === "string" && /^[a-z]+$/i.test(value);
580
- }
581
- return false;
582
- });
583
- }
584
-
585
- // ============================================================================
586
- // Backward Compatibility Aliases
587
- // ============================================================================
588
-
589
- /**
590
- * @deprecated Use BaseCellEventSchema instead
591
- */
592
- export const BaseBeadEventSchema = BaseCellEventSchema;
593
-
594
- /**
595
- * @deprecated Use CellCreatedEventSchema instead
596
- */
597
- export const BeadCreatedEventSchema = CellCreatedEventSchema;
598
-
599
- /**
600
- * @deprecated Use CellUpdatedEventSchema instead
601
- */
602
- export const BeadUpdatedEventSchema = CellUpdatedEventSchema;
603
-
604
- /**
605
- * @deprecated Use CellStatusChangedEventSchema instead
606
- */
607
- export const BeadStatusChangedEventSchema = CellStatusChangedEventSchema;
608
-
609
- /**
610
- * @deprecated Use CellClosedEventSchema instead
611
- */
612
- export const BeadClosedEventSchema = CellClosedEventSchema;
613
-
614
- /**
615
- * @deprecated Use CellReopenedEventSchema instead
616
- */
617
- export const BeadReopenedEventSchema = CellReopenedEventSchema;
618
-
619
- /**
620
- * @deprecated Use CellDeletedEventSchema instead
621
- */
622
- export const BeadDeletedEventSchema = CellDeletedEventSchema;
623
-
624
- /**
625
- * @deprecated Use CellDependencyAddedEventSchema instead
626
- */
627
- export const BeadDependencyAddedEventSchema = CellDependencyAddedEventSchema;
628
-
629
- /**
630
- * @deprecated Use CellDependencyRemovedEventSchema instead
631
- */
632
- export const BeadDependencyRemovedEventSchema = CellDependencyRemovedEventSchema;
633
-
634
- /**
635
- * @deprecated Use CellLabelAddedEventSchema instead
636
- */
637
- export const BeadLabelAddedEventSchema = CellLabelAddedEventSchema;
638
-
639
- /**
640
- * @deprecated Use CellLabelRemovedEventSchema instead
641
- */
642
- export const BeadLabelRemovedEventSchema = CellLabelRemovedEventSchema;
643
-
644
- /**
645
- * @deprecated Use CellCommentAddedEventSchema instead
646
- */
647
- export const BeadCommentAddedEventSchema = CellCommentAddedEventSchema;
648
-
649
- /**
650
- * @deprecated Use CellCommentUpdatedEventSchema instead
651
- */
652
- export const BeadCommentUpdatedEventSchema = CellCommentUpdatedEventSchema;
653
-
654
- /**
655
- * @deprecated Use CellCommentDeletedEventSchema instead
656
- */
657
- export const BeadCommentDeletedEventSchema = CellCommentDeletedEventSchema;
658
-
659
- /**
660
- * @deprecated Use CellEpicChildAddedEventSchema instead
661
- */
662
- export const BeadEpicChildAddedEventSchema = CellEpicChildAddedEventSchema;
663
-
664
- /**
665
- * @deprecated Use CellEpicChildRemovedEventSchema instead
666
- */
667
- export const BeadEpicChildRemovedEventSchema = CellEpicChildRemovedEventSchema;
668
-
669
- /**
670
- * @deprecated Use CellEpicClosureEligibleEventSchema instead
671
- */
672
- export const BeadEpicClosureEligibleEventSchema = CellEpicClosureEligibleEventSchema;
673
-
674
- /**
675
- * @deprecated Use CellAssignedEventSchema instead
676
- */
677
- export const BeadAssignedEventSchema = CellAssignedEventSchema;
678
-
679
- /**
680
- * @deprecated Use CellWorkStartedEventSchema instead
681
- */
682
- export const BeadWorkStartedEventSchema = CellWorkStartedEventSchema;
683
-
684
- /**
685
- * @deprecated Use CellCompactedEventSchema instead
686
- */
687
- export const BeadCompactedEventSchema = CellCompactedEventSchema;
688
-
689
- /**
690
- * @deprecated Use CellEventSchema instead
691
- */
692
- export const BeadEventSchema = CellEventSchema;
693
-
694
- /**
695
- * @deprecated Use CellEvent instead
696
- */
697
- export type BeadEvent = CellEvent;
698
-
699
- /**
700
- * @deprecated Use CellCreatedEvent instead
701
- */
702
- export type BeadCreatedEvent = CellCreatedEvent;
703
-
704
- /**
705
- * @deprecated Use CellUpdatedEvent instead
706
- */
707
- export type BeadUpdatedEvent = CellUpdatedEvent;
708
-
709
- /**
710
- * @deprecated Use CellStatusChangedEvent instead
711
- */
712
- export type BeadStatusChangedEvent = CellStatusChangedEvent;
713
-
714
- /**
715
- * @deprecated Use CellClosedEvent instead
716
- */
717
- export type BeadClosedEvent = CellClosedEvent;
718
-
719
- /**
720
- * @deprecated Use CellReopenedEvent instead
721
- */
722
- export type BeadReopenedEvent = CellReopenedEvent;
723
-
724
- /**
725
- * @deprecated Use CellDeletedEvent instead
726
- */
727
- export type BeadDeletedEvent = CellDeletedEvent;
728
-
729
- /**
730
- * @deprecated Use CellDependencyAddedEvent instead
731
- */
732
- export type BeadDependencyAddedEvent = CellDependencyAddedEvent;
733
-
734
- /**
735
- * @deprecated Use CellDependencyRemovedEvent instead
736
- */
737
- export type BeadDependencyRemovedEvent = CellDependencyRemovedEvent;
738
-
739
- /**
740
- * @deprecated Use CellLabelAddedEvent instead
741
- */
742
- export type BeadLabelAddedEvent = CellLabelAddedEvent;
743
-
744
- /**
745
- * @deprecated Use CellLabelRemovedEvent instead
746
- */
747
- export type BeadLabelRemovedEvent = CellLabelRemovedEvent;
748
-
749
- /**
750
- * @deprecated Use CellCommentAddedEvent instead
751
- */
752
- export type BeadCommentAddedEvent = CellCommentAddedEvent;
753
-
754
- /**
755
- * @deprecated Use CellCommentUpdatedEvent instead
756
- */
757
- export type BeadCommentUpdatedEvent = CellCommentUpdatedEvent;
758
-
759
- /**
760
- * @deprecated Use CellCommentDeletedEvent instead
761
- */
762
- export type BeadCommentDeletedEvent = CellCommentDeletedEvent;
763
-
764
- /**
765
- * @deprecated Use CellEpicChildAddedEvent instead
766
- */
767
- export type BeadEpicChildAddedEvent = CellEpicChildAddedEvent;
768
-
769
- /**
770
- * @deprecated Use CellEpicChildRemovedEvent instead
771
- */
772
- export type BeadEpicChildRemovedEvent = CellEpicChildRemovedEvent;
773
-
774
- /**
775
- * @deprecated Use CellEpicClosureEligibleEvent instead
776
- */
777
- export type BeadEpicClosureEligibleEvent = CellEpicClosureEligibleEvent;
778
-
779
- /**
780
- * @deprecated Use CellAssignedEvent instead
781
- */
782
- export type BeadAssignedEvent = CellAssignedEvent;
783
-
784
- /**
785
- * @deprecated Use CellWorkStartedEvent instead
786
- */
787
- export type BeadWorkStartedEvent = CellWorkStartedEvent;
788
-
789
- /**
790
- * @deprecated Use CellCompactedEvent instead
791
- */
792
- export type BeadCompactedEvent = CellCompactedEvent;
793
-
794
- /**
795
- * @deprecated Use createCellEvent instead
796
- */
797
- export const createBeadEvent = createCellEvent;
798
-
799
- /**
800
- * @deprecated Use isCellEventType instead
801
- */
802
- export const isBeadEventType = isCellEventType;
803
-
804
- /**
805
- * @deprecated Use getCellIdFromEvent instead
806
- */
807
- export const getBeadIdFromEvent = getCellIdFromEvent;