opencode-swarm-plugin 0.45.1 → 0.45.3

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.
package/dist/bin/swarm.js CHANGED
@@ -27034,6 +27034,34 @@ import {
27034
27034
  sep as sep3
27035
27035
  } from "path";
27036
27036
  import { fileURLToPath as fileURLToPath2 } from "url";
27037
+ import { getSwarmMailLibSQL as getSwarmMailLibSQL8, createEvent as createEvent7 } from "swarm-mail";
27038
+ async function emitSkillLoadedEvent2(data) {
27039
+ try {
27040
+ const projectPath = skillsProjectDirectory2;
27041
+ const swarmMail = await getSwarmMailLibSQL8(projectPath);
27042
+ const event = createEvent7("skill_loaded", {
27043
+ project_key: projectPath,
27044
+ skill_name: data.skill_name,
27045
+ skill_source: data.skill_source,
27046
+ context_provided: data.context_provided,
27047
+ content_length: data.content_length
27048
+ });
27049
+ await swarmMail.appendEvent(event);
27050
+ } catch {}
27051
+ }
27052
+ async function emitSkillCreatedEvent2(data) {
27053
+ try {
27054
+ const projectPath = skillsProjectDirectory2;
27055
+ const swarmMail = await getSwarmMailLibSQL8(projectPath);
27056
+ const event = createEvent7("skill_created", {
27057
+ project_key: projectPath,
27058
+ skill_name: data.skill_name,
27059
+ skill_scope: data.skill_scope,
27060
+ description: data.description
27061
+ });
27062
+ await swarmMail.appendEvent(event);
27063
+ } catch {}
27064
+ }
27037
27065
  function setSkillsProjectDirectory2(dir) {
27038
27066
  skillsProjectDirectory2 = dir;
27039
27067
  skillsCache2 = null;
@@ -27469,6 +27497,18 @@ If the skill has scripts, you can run them with skills_execute.`,
27469
27497
  const names = available.map((s) => s.name).join(", ");
27470
27498
  return `Skill '${args2.name}' not found. Available skills: ${names || "none"}`;
27471
27499
  }
27500
+ let skillSource = "project";
27501
+ if (skill.path.includes(".config/opencode/skills") || skill.path.includes(".claude/skills")) {
27502
+ skillSource = "global";
27503
+ } else if (skill.path.includes("global-skills")) {
27504
+ skillSource = "bundled";
27505
+ }
27506
+ await emitSkillLoadedEvent2({
27507
+ skill_name: skill.metadata.name,
27508
+ skill_source: skillSource,
27509
+ context_provided: true,
27510
+ content_length: skill.body.length
27511
+ });
27472
27512
  const includeScripts = args2.include_scripts !== false;
27473
27513
  let output = `# Skill: ${skill.metadata.name}
27474
27514
 
@@ -27637,6 +27677,12 @@ Good skills have:
27637
27677
  const content = generateSkillContent2(args2.name, args2.description, args2.body, { tags: args2.tags, tools: args2.tools });
27638
27678
  await writeFile2(skillPath, content, "utf-8");
27639
27679
  invalidateSkillsCache2();
27680
+ const skillScope = args2.directory === "global" || args2.directory === "global-claude" ? "global" : "project";
27681
+ await emitSkillCreatedEvent2({
27682
+ skill_name: args2.name,
27683
+ skill_scope: skillScope,
27684
+ description: args2.description
27685
+ });
27640
27686
  const response = {
27641
27687
  success: true,
27642
27688
  skill: args2.name,
@@ -27872,6 +27918,12 @@ echo "Project directory: $1"
27872
27918
  createdFiles.push("references/guide.md");
27873
27919
  }
27874
27920
  invalidateSkillsCache2();
27921
+ const skillScope = args2.directory === "global" ? "global" : "project";
27922
+ await emitSkillCreatedEvent2({
27923
+ skill_name: args2.name,
27924
+ skill_scope: skillScope,
27925
+ description: args2.description || "[TODO: Complete description]"
27926
+ });
27875
27927
  return JSON.stringify({
27876
27928
  success: true,
27877
27929
  skill: args2.name,
@@ -36159,7 +36211,7 @@ var require_atomic_sleep = __commonJS((exports2, module2) => {
36159
36211
 
36160
36212
  // ../../node_modules/.bun/sonic-boom@4.2.0/node_modules/sonic-boom/index.js
36161
36213
  var require_sonic_boom = __commonJS((exports2, module2) => {
36162
- var fs8 = __require("fs");
36214
+ var fs7 = __require("fs");
36163
36215
  var EventEmitter = __require("events");
36164
36216
  var inherits = __require("util").inherits;
36165
36217
  var path4 = __require("path");
@@ -36217,21 +36269,21 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36217
36269
  if (sonic.sync) {
36218
36270
  try {
36219
36271
  if (sonic.mkdir)
36220
- fs8.mkdirSync(path4.dirname(file4), { recursive: true });
36221
- const fd = fs8.openSync(file4, flags, mode);
36272
+ fs7.mkdirSync(path4.dirname(file4), { recursive: true });
36273
+ const fd = fs7.openSync(file4, flags, mode);
36222
36274
  fileOpened(null, fd);
36223
36275
  } catch (err) {
36224
36276
  fileOpened(err);
36225
36277
  throw err;
36226
36278
  }
36227
36279
  } else if (sonic.mkdir) {
36228
- fs8.mkdir(path4.dirname(file4), { recursive: true }, (err) => {
36280
+ fs7.mkdir(path4.dirname(file4), { recursive: true }, (err) => {
36229
36281
  if (err)
36230
36282
  return fileOpened(err);
36231
- fs8.open(file4, flags, mode, fileOpened);
36283
+ fs7.open(file4, flags, mode, fileOpened);
36232
36284
  });
36233
36285
  } else {
36234
- fs8.open(file4, flags, mode, fileOpened);
36286
+ fs7.open(file4, flags, mode, fileOpened);
36235
36287
  }
36236
36288
  }
36237
36289
  function SonicBoom(opts) {
@@ -36272,16 +36324,16 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36272
36324
  this.flush = flushBuffer;
36273
36325
  this.flushSync = flushBufferSync;
36274
36326
  this._actualWrite = actualWriteBuffer;
36275
- fsWriteSync = () => fs8.writeSync(this.fd, this._writingBuf);
36276
- fsWrite = () => fs8.write(this.fd, this._writingBuf, this.release);
36327
+ fsWriteSync = () => fs7.writeSync(this.fd, this._writingBuf);
36328
+ fsWrite = () => fs7.write(this.fd, this._writingBuf, this.release);
36277
36329
  } else if (contentMode === undefined || contentMode === kContentModeUtf8) {
36278
36330
  this._writingBuf = "";
36279
36331
  this.write = write;
36280
36332
  this.flush = flush;
36281
36333
  this.flushSync = flushSync;
36282
36334
  this._actualWrite = actualWrite;
36283
- fsWriteSync = () => fs8.writeSync(this.fd, this._writingBuf, "utf8");
36284
- fsWrite = () => fs8.write(this.fd, this._writingBuf, "utf8", this.release);
36335
+ fsWriteSync = () => fs7.writeSync(this.fd, this._writingBuf, "utf8");
36336
+ fsWrite = () => fs7.write(this.fd, this._writingBuf, "utf8", this.release);
36285
36337
  } else {
36286
36338
  throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
36287
36339
  }
@@ -36337,7 +36389,7 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36337
36389
  }
36338
36390
  }
36339
36391
  if (this._fsync) {
36340
- fs8.fsyncSync(this.fd);
36392
+ fs7.fsyncSync(this.fd);
36341
36393
  }
36342
36394
  const len = this._len;
36343
36395
  if (this._reopening) {
@@ -36450,7 +36502,7 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36450
36502
  const onDrain = () => {
36451
36503
  if (!this._fsync) {
36452
36504
  try {
36453
- fs8.fsync(this.fd, (err) => {
36505
+ fs7.fsync(this.fd, (err) => {
36454
36506
  this._flushPending = false;
36455
36507
  cb(err);
36456
36508
  });
@@ -36552,7 +36604,7 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36552
36604
  const fd = this.fd;
36553
36605
  this.once("ready", () => {
36554
36606
  if (fd !== this.fd) {
36555
- fs8.close(fd, (err) => {
36607
+ fs7.close(fd, (err) => {
36556
36608
  if (err) {
36557
36609
  return this.emit("error", err);
36558
36610
  }
@@ -36601,7 +36653,7 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36601
36653
  buf = this._bufs[0];
36602
36654
  }
36603
36655
  try {
36604
- const n = fs8.writeSync(this.fd, buf, "utf8");
36656
+ const n = fs7.writeSync(this.fd, buf, "utf8");
36605
36657
  const releasedBufObj = releaseWritingBuf(buf, this._len, n);
36606
36658
  buf = releasedBufObj.writingBuf;
36607
36659
  this._len = releasedBufObj.len;
@@ -36617,7 +36669,7 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36617
36669
  }
36618
36670
  }
36619
36671
  try {
36620
- fs8.fsyncSync(this.fd);
36672
+ fs7.fsyncSync(this.fd);
36621
36673
  } catch {}
36622
36674
  }
36623
36675
  function flushBufferSync() {
@@ -36637,7 +36689,7 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36637
36689
  buf = mergeBuf(this._bufs[0], this._lens[0]);
36638
36690
  }
36639
36691
  try {
36640
- const n = fs8.writeSync(this.fd, buf);
36692
+ const n = fs7.writeSync(this.fd, buf);
36641
36693
  buf = buf.subarray(n);
36642
36694
  this._len = Math.max(this._len - n, 0);
36643
36695
  if (buf.length <= 0) {
@@ -36665,13 +36717,13 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36665
36717
  this._writingBuf = this._writingBuf || this._bufs.shift() || "";
36666
36718
  if (this.sync) {
36667
36719
  try {
36668
- const written = fs8.writeSync(this.fd, this._writingBuf, "utf8");
36720
+ const written = fs7.writeSync(this.fd, this._writingBuf, "utf8");
36669
36721
  release(null, written);
36670
36722
  } catch (err) {
36671
36723
  release(err);
36672
36724
  }
36673
36725
  } else {
36674
- fs8.write(this.fd, this._writingBuf, "utf8", release);
36726
+ fs7.write(this.fd, this._writingBuf, "utf8", release);
36675
36727
  }
36676
36728
  }
36677
36729
  function actualWriteBuffer() {
@@ -36680,7 +36732,7 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36680
36732
  this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
36681
36733
  if (this.sync) {
36682
36734
  try {
36683
- const written = fs8.writeSync(this.fd, this._writingBuf);
36735
+ const written = fs7.writeSync(this.fd, this._writingBuf);
36684
36736
  release(null, written);
36685
36737
  } catch (err) {
36686
36738
  release(err);
@@ -36689,7 +36741,7 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36689
36741
  if (kCopyBuffer) {
36690
36742
  this._writingBuf = Buffer.from(this._writingBuf);
36691
36743
  }
36692
- fs8.write(this.fd, this._writingBuf, release);
36744
+ fs7.write(this.fd, this._writingBuf, release);
36693
36745
  }
36694
36746
  }
36695
36747
  function actualClose(sonic) {
@@ -36705,11 +36757,11 @@ var require_sonic_boom = __commonJS((exports2, module2) => {
36705
36757
  sonic._lens = [];
36706
36758
  assert4(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
36707
36759
  try {
36708
- fs8.fsync(sonic.fd, closeWrapped);
36760
+ fs7.fsync(sonic.fd, closeWrapped);
36709
36761
  } catch {}
36710
36762
  function closeWrapped() {
36711
36763
  if (sonic.fd !== 1 && sonic.fd !== 2) {
36712
- fs8.close(sonic.fd, done8);
36764
+ fs7.close(sonic.fd, done8);
36713
36765
  } else {
36714
36766
  done8();
36715
36767
  }
@@ -54156,6 +54208,20 @@ var hive_create = tool({
54156
54208
  parent_id: validated.parent_id
54157
54209
  });
54158
54210
  await adapter.markDirty(projectKey, cell.id);
54211
+ try {
54212
+ const event = createEvent("cell_created", {
54213
+ project_key: projectKey,
54214
+ cell_id: cell.id,
54215
+ title: validated.title,
54216
+ description: validated.description,
54217
+ issue_type: validated.type || "task",
54218
+ priority: validated.priority ?? 2,
54219
+ parent_id: validated.parent_id
54220
+ });
54221
+ await appendEvent(event, projectKey);
54222
+ } catch (error45) {
54223
+ console.warn("[hive_create] Failed to emit cell_created event:", error45);
54224
+ }
54159
54225
  const formatted = formatCellForOutput(cell);
54160
54226
  return JSON.stringify(formatted, null, 2);
54161
54227
  } catch (error45) {
@@ -54215,6 +54281,19 @@ var hive_create_epic = tool({
54215
54281
  subtasks: created.slice(1).map((c) => formatCellForOutput(c))
54216
54282
  };
54217
54283
  const effectiveProjectKey = args.project_key || projectKey;
54284
+ try {
54285
+ const epicCreatedEvent = createEvent("epic_created", {
54286
+ project_key: effectiveProjectKey,
54287
+ epic_id: epic.id,
54288
+ title: validated.epic_title,
54289
+ description: validated.epic_description,
54290
+ subtask_count: validated.subtasks.length,
54291
+ subtask_ids: created.slice(1).map((c) => c.id)
54292
+ });
54293
+ await appendEvent(epicCreatedEvent, effectiveProjectKey);
54294
+ } catch (error45) {
54295
+ console.warn("[hive_create_epic] Failed to emit epic_created event:", error45);
54296
+ }
54218
54297
  try {
54219
54298
  const event = createEvent("decomposition_generated", {
54220
54299
  project_key: effectiveProjectKey,
@@ -54379,6 +54458,23 @@ var hive_update = tool({
54379
54458
  cell = existingCell;
54380
54459
  }
54381
54460
  await adapter.markDirty(projectKey, cellId);
54461
+ try {
54462
+ const fieldsChanged = [];
54463
+ if (validated.status)
54464
+ fieldsChanged.push("status");
54465
+ if (validated.description !== undefined)
54466
+ fieldsChanged.push("description");
54467
+ if (validated.priority !== undefined)
54468
+ fieldsChanged.push("priority");
54469
+ const event = createEvent("cell_updated", {
54470
+ project_key: projectKey,
54471
+ cell_id: cellId,
54472
+ fields_changed: fieldsChanged
54473
+ });
54474
+ await appendEvent(event, projectKey);
54475
+ } catch (error45) {
54476
+ console.warn("[hive_update] Failed to emit cell_updated event:", error45);
54477
+ }
54382
54478
  const formatted = formatCellForOutput(cell);
54383
54479
  return JSON.stringify(formatted, null, 2);
54384
54480
  } catch (error45) {
@@ -54495,6 +54591,16 @@ var hive_close = tool({
54495
54591
  console.warn("[hive_close] Failed to emit SwarmCompletedEvent:", error45);
54496
54592
  }
54497
54593
  }
54594
+ try {
54595
+ const event = createEvent("cell_closed", {
54596
+ project_key: projectKey,
54597
+ cell_id: cellId,
54598
+ reason: validated.reason
54599
+ });
54600
+ await appendEvent(event, projectKey);
54601
+ } catch (error45) {
54602
+ console.warn("[hive_close] Failed to emit cell_closed event:", error45);
54603
+ }
54498
54604
  return `Closed ${cell.id}: ${validated.reason}`;
54499
54605
  } catch (error45) {
54500
54606
  const message = error45 instanceof Error ? error45.message : String(error45);
@@ -54520,6 +54626,17 @@ var hive_start = tool({
54520
54626
  const cellId = await resolvePartialId(adapter, projectKey, args.id) || args.id;
54521
54627
  const cell = await adapter.changeCellStatus(projectKey, cellId, "in_progress");
54522
54628
  await adapter.markDirty(projectKey, cellId);
54629
+ try {
54630
+ const event = createEvent("cell_status_changed", {
54631
+ project_key: projectKey,
54632
+ cell_id: cellId,
54633
+ old_status: "open",
54634
+ new_status: "in_progress"
54635
+ });
54636
+ await appendEvent(event, projectKey);
54637
+ } catch (error45) {
54638
+ console.warn("[hive_start] Failed to emit cell_status_changed event:", error45);
54639
+ }
54523
54640
  return `Started: ${cell.id}`;
54524
54641
  } catch (error45) {
54525
54642
  const message = error45 instanceof Error ? error45.message : String(error45);
@@ -54708,11 +54825,25 @@ var hive_sync = tool({
54708
54825
  }
54709
54826
  const remoteCheckResult = await runGitCommand(["remote"]);
54710
54827
  const hasRemote = remoteCheckResult.stdout.trim() !== "";
54828
+ let pushSuccess = false;
54711
54829
  if (hasRemote) {
54712
54830
  const pushResult = await withTimeout(runGitCommand(["push"]), TIMEOUT_MS, "git push");
54713
54831
  if (pushResult.exitCode !== 0) {
54714
54832
  throw new HiveError(`Failed to push: ${pushResult.stderr}`, "git push", pushResult.exitCode);
54715
54833
  }
54834
+ pushSuccess = true;
54835
+ }
54836
+ try {
54837
+ const event = createEvent("hive_synced", {
54838
+ project_key: projectKey,
54839
+ cells_synced: flushResult.cellsExported,
54840
+ push_success: pushSuccess
54841
+ });
54842
+ await appendEvent(event, projectKey);
54843
+ } catch (error45) {
54844
+ console.warn("[hive_sync] Failed to emit hive_synced event:", error45);
54845
+ }
54846
+ if (hasRemote) {
54716
54847
  return "Hive synced and pushed successfully";
54717
54848
  } else {
54718
54849
  return "Hive synced successfully (no remote configured)";
@@ -54840,14 +54971,15 @@ import {
54840
54971
  sep as sep2
54841
54972
  } from "path";
54842
54973
  import { fileURLToPath } from "url";
54974
+ import { getSwarmMailLibSQL as getSwarmMailLibSQL2, createEvent as createEvent2 } from "swarm-mail";
54843
54975
  import {
54844
54976
  getSwarmInbox,
54845
54977
  releaseSwarmFiles,
54846
54978
  sendSwarmMessage as sendSwarmMessage2,
54847
54979
  getAgent,
54848
- createEvent as createEvent2,
54980
+ createEvent as createEvent3,
54849
54981
  appendEvent as appendEvent2,
54850
- getSwarmMailLibSQL as getSwarmMailLibSQL2
54982
+ getSwarmMailLibSQL as getSwarmMailLibSQL3
54851
54983
  } from "swarm-mail";
54852
54984
  import { checkSwarmHealth } from "swarm-mail";
54853
54985
  import {
@@ -54855,13 +54987,13 @@ import {
54855
54987
  FlushManager as FlushManager2,
54856
54988
  importFromJSONL as importFromJSONL2,
54857
54989
  syncMemories as syncMemories2,
54858
- getSwarmMailLibSQL as getSwarmMailLibSQL3,
54990
+ getSwarmMailLibSQL as getSwarmMailLibSQL4,
54859
54991
  resolvePartialId as resolvePartialId2,
54860
54992
  findCellsByPartialId as findCellsByPartialId2
54861
54993
  } from "swarm-mail";
54862
54994
  import { existsSync as existsSync22, readFileSync as readFileSync22 } from "node:fs";
54863
54995
  import { join as join22 } from "node:path";
54864
- import { createEvent as createEvent3, appendEvent as appendEvent3 } from "swarm-mail";
54996
+ import { createEvent as createEvent4, appendEvent as appendEvent3 } from "swarm-mail";
54865
54997
  import { join as join4 } from "node:path";
54866
54998
  import { existsSync as existsSync32 } from "node:fs";
54867
54999
  import { sendSwarmMessage } from "swarm-mail";
@@ -54871,7 +55003,7 @@ import {
54871
55003
  } from "swarm-mail";
54872
55004
  import { createLibSQLAdapter } from "swarm-mail";
54873
55005
  import { getDatabasePath } from "swarm-mail";
54874
- import { getSwarmMailLibSQL as getSwarmMailLibSQL32 } from "swarm-mail";
55006
+ import { getSwarmMailLibSQL as getSwarmMailLibSQL42, createEvent as createEvent42, appendEvent as appendEvent32 } from "swarm-mail";
54875
55007
  import {
54876
55008
  createMemoryStore,
54877
55009
  getDefaultConfig,
@@ -72167,6 +72299,33 @@ __export3(exports_skills, {
72167
72299
  findRelevantSkills: () => findRelevantSkills,
72168
72300
  discoverSkills: () => discoverSkills
72169
72301
  });
72302
+ async function emitSkillLoadedEvent(data) {
72303
+ try {
72304
+ const projectPath = skillsProjectDirectory;
72305
+ const swarmMail = await getSwarmMailLibSQL2(projectPath);
72306
+ const event = createEvent2("skill_loaded", {
72307
+ project_key: projectPath,
72308
+ skill_name: data.skill_name,
72309
+ skill_source: data.skill_source,
72310
+ context_provided: data.context_provided,
72311
+ content_length: data.content_length
72312
+ });
72313
+ await swarmMail.appendEvent(event);
72314
+ } catch {}
72315
+ }
72316
+ async function emitSkillCreatedEvent(data) {
72317
+ try {
72318
+ const projectPath = skillsProjectDirectory;
72319
+ const swarmMail = await getSwarmMailLibSQL2(projectPath);
72320
+ const event = createEvent2("skill_created", {
72321
+ project_key: projectPath,
72322
+ skill_name: data.skill_name,
72323
+ skill_scope: data.skill_scope,
72324
+ description: data.description
72325
+ });
72326
+ await swarmMail.appendEvent(event);
72327
+ } catch {}
72328
+ }
72170
72329
  function setSkillsProjectDirectory(dir) {
72171
72330
  skillsProjectDirectory = dir;
72172
72331
  skillsCache = null;
@@ -72616,6 +72775,18 @@ If the skill has scripts, you can run them with skills_execute.`,
72616
72775
  const names = available.map((s) => s.name).join(", ");
72617
72776
  return `Skill '${args.name}' not found. Available skills: ${names || "none"}`;
72618
72777
  }
72778
+ let skillSource = "project";
72779
+ if (skill.path.includes(".config/opencode/skills") || skill.path.includes(".claude/skills")) {
72780
+ skillSource = "global";
72781
+ } else if (skill.path.includes("global-skills")) {
72782
+ skillSource = "bundled";
72783
+ }
72784
+ await emitSkillLoadedEvent({
72785
+ skill_name: skill.metadata.name,
72786
+ skill_source: skillSource,
72787
+ context_provided: true,
72788
+ content_length: skill.body.length
72789
+ });
72619
72790
  const includeScripts = args.include_scripts !== false;
72620
72791
  let output = `# Skill: ${skill.metadata.name}
72621
72792
 
@@ -72784,6 +72955,12 @@ Good skills have:
72784
72955
  const content = generateSkillContent(args.name, args.description, args.body, { tags: args.tags, tools: args.tools });
72785
72956
  await writeFile(skillPath, content, "utf-8");
72786
72957
  invalidateSkillsCache();
72958
+ const skillScope = args.directory === "global" || args.directory === "global-claude" ? "global" : "project";
72959
+ await emitSkillCreatedEvent({
72960
+ skill_name: args.name,
72961
+ skill_scope: skillScope,
72962
+ description: args.description
72963
+ });
72787
72964
  const response = {
72788
72965
  success: true,
72789
72966
  skill: args.name,
@@ -73019,6 +73196,12 @@ echo "Project directory: $1"
73019
73196
  createdFiles.push("references/guide.md");
73020
73197
  }
73021
73198
  invalidateSkillsCache();
73199
+ const skillScope = args.directory === "global" ? "global" : "project";
73200
+ await emitSkillCreatedEvent({
73201
+ skill_name: args.name,
73202
+ skill_scope: skillScope,
73203
+ description: args.description || "[TODO: Complete description]"
73204
+ });
73022
73205
  return JSON.stringify({
73023
73206
  success: true,
73024
73207
  skill: args.name,
@@ -75906,7 +76089,7 @@ async function getHiveAdapter2(projectKey) {
75906
76089
  if (adapterCache2.has(projectKey)) {
75907
76090
  return adapterCache2.get(projectKey);
75908
76091
  }
75909
- const swarmMail = await getSwarmMailLibSQL3(projectKey);
76092
+ const swarmMail = await getSwarmMailLibSQL4(projectKey);
75910
76093
  const db = await swarmMail.getDatabase();
75911
76094
  const adapter = createHiveAdapter2(db, projectKey);
75912
76095
  await adapter.runMigrations();
@@ -75976,6 +76159,20 @@ var hive_create2 = tool2({
75976
76159
  parent_id: validated.parent_id
75977
76160
  });
75978
76161
  await adapter.markDirty(projectKey, cell.id);
76162
+ try {
76163
+ const event = createEvent4("cell_created", {
76164
+ project_key: projectKey,
76165
+ cell_id: cell.id,
76166
+ title: validated.title,
76167
+ description: validated.description,
76168
+ issue_type: validated.type || "task",
76169
+ priority: validated.priority ?? 2,
76170
+ parent_id: validated.parent_id
76171
+ });
76172
+ await appendEvent3(event, projectKey);
76173
+ } catch (error452) {
76174
+ console.warn("[hive_create] Failed to emit cell_created event:", error452);
76175
+ }
75979
76176
  const formatted = formatCellForOutput2(cell);
75980
76177
  return JSON.stringify(formatted, null, 2);
75981
76178
  } catch (error452) {
@@ -76036,7 +76233,20 @@ var hive_create_epic2 = tool2({
76036
76233
  };
76037
76234
  const effectiveProjectKey = args.project_key || projectKey;
76038
76235
  try {
76039
- const event = createEvent3("decomposition_generated", {
76236
+ const epicCreatedEvent = createEvent4("epic_created", {
76237
+ project_key: effectiveProjectKey,
76238
+ epic_id: epic.id,
76239
+ title: validated.epic_title,
76240
+ description: validated.epic_description,
76241
+ subtask_count: validated.subtasks.length,
76242
+ subtask_ids: created.slice(1).map((c) => c.id)
76243
+ });
76244
+ await appendEvent3(epicCreatedEvent, effectiveProjectKey);
76245
+ } catch (error452) {
76246
+ console.warn("[hive_create_epic] Failed to emit epic_created event:", error452);
76247
+ }
76248
+ try {
76249
+ const event = createEvent4("decomposition_generated", {
76040
76250
  project_key: effectiveProjectKey,
76041
76251
  epic_id: epic.id,
76042
76252
  task: args.task || validated.epic_title,
@@ -76056,7 +76266,7 @@ var hive_create_epic2 = tool2({
76056
76266
  }
76057
76267
  try {
76058
76268
  const totalFiles = validated.subtasks.reduce((count, st) => count + (st.files?.length || 0), 0);
76059
- const swarmStartedEvent = createEvent3("swarm_started", {
76269
+ const swarmStartedEvent = createEvent4("swarm_started", {
76060
76270
  project_key: effectiveProjectKey,
76061
76271
  epic_id: epic.id,
76062
76272
  epic_title: validated.epic_title,
@@ -76199,6 +76409,23 @@ var hive_update2 = tool2({
76199
76409
  cell = existingCell;
76200
76410
  }
76201
76411
  await adapter.markDirty(projectKey, cellId);
76412
+ try {
76413
+ const fieldsChanged = [];
76414
+ if (validated.status)
76415
+ fieldsChanged.push("status");
76416
+ if (validated.description !== undefined)
76417
+ fieldsChanged.push("description");
76418
+ if (validated.priority !== undefined)
76419
+ fieldsChanged.push("priority");
76420
+ const event = createEvent4("cell_updated", {
76421
+ project_key: projectKey,
76422
+ cell_id: cellId,
76423
+ fields_changed: fieldsChanged
76424
+ });
76425
+ await appendEvent3(event, projectKey);
76426
+ } catch (error452) {
76427
+ console.warn("[hive_update] Failed to emit cell_updated event:", error452);
76428
+ }
76202
76429
  const formatted = formatCellForOutput2(cell);
76203
76430
  return JSON.stringify(formatted, null, 2);
76204
76431
  } catch (error452) {
@@ -76315,6 +76542,16 @@ var hive_close2 = tool2({
76315
76542
  console.warn("[hive_close] Failed to emit SwarmCompletedEvent:", error452);
76316
76543
  }
76317
76544
  }
76545
+ try {
76546
+ const event = createEvent4("cell_closed", {
76547
+ project_key: projectKey,
76548
+ cell_id: cellId,
76549
+ reason: validated.reason
76550
+ });
76551
+ await appendEvent3(event, projectKey);
76552
+ } catch (error452) {
76553
+ console.warn("[hive_close] Failed to emit cell_closed event:", error452);
76554
+ }
76318
76555
  return `Closed ${cell.id}: ${validated.reason}`;
76319
76556
  } catch (error452) {
76320
76557
  const message = error452 instanceof Error ? error452.message : String(error452);
@@ -76340,6 +76577,17 @@ var hive_start2 = tool2({
76340
76577
  const cellId = await resolvePartialId2(adapter, projectKey, args.id) || args.id;
76341
76578
  const cell = await adapter.changeCellStatus(projectKey, cellId, "in_progress");
76342
76579
  await adapter.markDirty(projectKey, cellId);
76580
+ try {
76581
+ const event = createEvent4("cell_status_changed", {
76582
+ project_key: projectKey,
76583
+ cell_id: cellId,
76584
+ old_status: "open",
76585
+ new_status: "in_progress"
76586
+ });
76587
+ await appendEvent3(event, projectKey);
76588
+ } catch (error452) {
76589
+ console.warn("[hive_start] Failed to emit cell_status_changed event:", error452);
76590
+ }
76343
76591
  return `Started: ${cell.id}`;
76344
76592
  } catch (error452) {
76345
76593
  const message = error452 instanceof Error ? error452.message : String(error452);
@@ -76469,7 +76717,7 @@ var hive_sync2 = tool2({
76469
76717
  outputPath: `${projectKey}/.hive/issues.jsonl`
76470
76718
  });
76471
76719
  const flushResult = await withTimeout(flushManager.flush(), TIMEOUT_MS, "flush hive");
76472
- const swarmMail = await getSwarmMailLibSQL3(projectKey);
76720
+ const swarmMail = await getSwarmMailLibSQL4(projectKey);
76473
76721
  const db = await swarmMail.getDatabase();
76474
76722
  const hivePath = join22(projectKey, ".hive");
76475
76723
  let memoriesSynced = 0;
@@ -76528,11 +76776,25 @@ var hive_sync2 = tool2({
76528
76776
  }
76529
76777
  const remoteCheckResult = await runGitCommand2(["remote"]);
76530
76778
  const hasRemote = remoteCheckResult.stdout.trim() !== "";
76779
+ let pushSuccess = false;
76531
76780
  if (hasRemote) {
76532
76781
  const pushResult = await withTimeout(runGitCommand2(["push"]), TIMEOUT_MS, "git push");
76533
76782
  if (pushResult.exitCode !== 0) {
76534
76783
  throw new HiveError2(`Failed to push: ${pushResult.stderr}`, "git push", pushResult.exitCode);
76535
76784
  }
76785
+ pushSuccess = true;
76786
+ }
76787
+ try {
76788
+ const event = createEvent4("hive_synced", {
76789
+ project_key: projectKey,
76790
+ cells_synced: flushResult.cellsExported,
76791
+ push_success: pushSuccess
76792
+ });
76793
+ await appendEvent3(event, projectKey);
76794
+ } catch (error452) {
76795
+ console.warn("[hive_sync] Failed to emit hive_synced event:", error452);
76796
+ }
76797
+ if (hasRemote) {
76536
76798
  return "Hive synced and pushed successfully";
76537
76799
  } else {
76538
76800
  return "Hive synced successfully (no remote configured)";
@@ -77205,9 +77467,9 @@ var swarm_review = tool2({
77205
77467
  downstream_tasks: downstreamTasks.length > 0 ? downstreamTasks : undefined
77206
77468
  });
77207
77469
  try {
77208
- const { createEvent: createEvent22, appendEvent: appendEvent22 } = await import("swarm-mail");
77470
+ const { createEvent: createEvent32, appendEvent: appendEvent22 } = await import("swarm-mail");
77209
77471
  const attempt = getReviewStatus(args.task_id).attempt_count || 1;
77210
- const reviewStartedEvent = createEvent22("review_started", {
77472
+ const reviewStartedEvent = createEvent32("review_started", {
77211
77473
  project_key: args.project_key,
77212
77474
  epic_id: args.epic_id,
77213
77475
  bead_id: args.task_id,
@@ -77296,9 +77558,9 @@ var swarm_review_feedback = tool2({
77296
77558
  console.warn("[swarm_review_feedback] Failed to trace review_decision:", error452);
77297
77559
  }
77298
77560
  try {
77299
- const { createEvent: createEvent22, appendEvent: appendEvent22 } = await import("swarm-mail");
77561
+ const { createEvent: createEvent32, appendEvent: appendEvent22 } = await import("swarm-mail");
77300
77562
  const attempt = getReviewStatus(args.task_id).attempt_count || 1;
77301
- const reviewCompletedEvent = createEvent22("review_completed", {
77563
+ const reviewCompletedEvent = createEvent32("review_completed", {
77302
77564
  project_key: args.project_key,
77303
77565
  epic_id: epicId,
77304
77566
  bead_id: args.task_id,
@@ -77367,9 +77629,9 @@ You may now complete the task with \`swarm_complete\`.`,
77367
77629
  console.warn("[swarm_review_feedback] Failed to trace review_decision:", error452);
77368
77630
  }
77369
77631
  try {
77370
- const { createEvent: createEvent22, appendEvent: appendEvent22 } = await import("swarm-mail");
77632
+ const { createEvent: createEvent32, appendEvent: appendEvent22 } = await import("swarm-mail");
77371
77633
  const status = remaining <= 0 ? "blocked" : "needs_changes";
77372
- const reviewCompletedEvent = createEvent22("review_completed", {
77634
+ const reviewCompletedEvent = createEvent32("review_completed", {
77373
77635
  project_key: args.project_key,
77374
77636
  epic_id: epicId,
77375
77637
  bead_id: args.task_id,
@@ -77919,7 +78181,7 @@ var swarm_progress = tool2({
77919
78181
  }
77920
78182
  };
77921
78183
  const checkpointData = JSON.stringify(checkpoint);
77922
- const checkpointEvent = createEvent2("swarm_checkpointed", {
78184
+ const checkpointEvent = createEvent3("swarm_checkpointed", {
77923
78185
  project_key: args.project_key,
77924
78186
  ...checkpoint,
77925
78187
  checkpoint_size_bytes: Buffer.byteLength(checkpointData, "utf8"),
@@ -77927,7 +78189,7 @@ var swarm_progress = tool2({
77927
78189
  });
77928
78190
  await appendEvent2(checkpointEvent, args.project_key);
77929
78191
  const checkpointId = `ckpt-${Date.now()}-${args.bead_id}`;
77930
- const createdEvent = createEvent2("checkpoint_created", {
78192
+ const createdEvent = createEvent3("checkpoint_created", {
77931
78193
  project_key: args.project_key,
77932
78194
  epic_id: epicId,
77933
78195
  bead_id: args.bead_id,
@@ -78180,7 +78442,7 @@ This will be recorded as a negative learning signal.`;
78180
78442
  let deferredResolved = false;
78181
78443
  let deferredError;
78182
78444
  try {
78183
- const swarmMail = await getSwarmMailLibSQL2(args.project_key);
78445
+ const swarmMail = await getSwarmMailLibSQL3(args.project_key);
78184
78446
  const db = await swarmMail.getDatabase();
78185
78447
  const deferredUrl = `deferred:${args.bead_id}`;
78186
78448
  const checkResult = await db.query(`SELECT url, resolved FROM deferred WHERE url = ? AND resolved = 0`, [deferredUrl]);
@@ -78209,16 +78471,16 @@ This will be recorded as a negative learning signal.`;
78209
78471
  syncError = error452 instanceof Error ? error452.message : String(error452);
78210
78472
  console.warn(`[swarm_complete] Auto-sync failed (non-fatal): ${syncError}`);
78211
78473
  }
78474
+ const completionDurationMs = args.start_time ? Date.now() - args.start_time : 0;
78475
+ const eventEpicId = cell.parent_id || (args.bead_id.includes(".") ? args.bead_id.split(".")[0] : args.bead_id);
78212
78476
  try {
78213
- const durationMs2 = args.start_time ? Date.now() - args.start_time : 0;
78214
- const eventEpicId = cell.parent_id || (args.bead_id.includes(".") ? args.bead_id.split(".")[0] : args.bead_id);
78215
- const event = createEvent2("subtask_outcome", {
78477
+ const event = createEvent3("subtask_outcome", {
78216
78478
  project_key: args.project_key,
78217
78479
  epic_id: eventEpicId,
78218
78480
  bead_id: args.bead_id,
78219
78481
  planned_files: args.planned_files || [],
78220
78482
  actual_files: args.files_touched || [],
78221
- duration_ms: durationMs2,
78483
+ duration_ms: completionDurationMs,
78222
78484
  error_count: args.error_count || 0,
78223
78485
  retry_count: args.retry_count || 0,
78224
78486
  success: true,
@@ -78229,8 +78491,21 @@ This will be recorded as a negative learning signal.`;
78229
78491
  } catch (error452) {
78230
78492
  console.warn("[swarm_complete] Failed to emit SubtaskOutcomeEvent:", error452);
78231
78493
  }
78494
+ try {
78495
+ const workerCompletedEvent = createEvent3("worker_completed", {
78496
+ project_key: args.project_key,
78497
+ epic_id: eventEpicId,
78498
+ bead_id: args.bead_id,
78499
+ worker_agent: args.agent_name,
78500
+ success: true,
78501
+ duration_ms: completionDurationMs,
78502
+ files_touched: args.files_touched || []
78503
+ });
78504
+ await appendEvent2(workerCompletedEvent, args.project_key);
78505
+ } catch (error452) {
78506
+ console.warn("[swarm_complete] Failed to emit worker_completed event:", error452);
78507
+ }
78232
78508
  let capturedStrategy;
78233
- const durationMs = args.start_time ? Date.now() - args.start_time : 0;
78234
78509
  const memoryInfo = formatMemoryStoreOnSuccess(args.bead_id, args.summary, args.files_touched || [], capturedStrategy);
78235
78510
  let memoryStored = false;
78236
78511
  let memoryError;
@@ -78347,7 +78622,7 @@ Files touched: ${args.files_touched?.join(", ") || "none recorded"}`,
78347
78622
  };
78348
78623
  try {
78349
78624
  const { captureSubtaskOutcome: captureSubtaskOutcome22 } = await Promise.resolve().then(() => (init_eval_capture2(), exports_eval_capture2));
78350
- const durationMs2 = args.start_time ? Date.now() - args.start_time : 0;
78625
+ const durationMs = args.start_time ? Date.now() - args.start_time : 0;
78351
78626
  const evalEpicId = cell.parent_id || epicId2;
78352
78627
  captureSubtaskOutcome22({
78353
78628
  epicId: evalEpicId,
@@ -78356,7 +78631,7 @@ Files touched: ${args.files_touched?.join(", ") || "none recorded"}`,
78356
78631
  title: cell.title,
78357
78632
  plannedFiles: args.planned_files || [],
78358
78633
  actualFiles: args.files_touched || [],
78359
- durationMs: durationMs2,
78634
+ durationMs,
78360
78635
  errorCount: args.error_count || 0,
78361
78636
  retryCount: args.retry_count || 0,
78362
78637
  success: true
@@ -78365,7 +78640,7 @@ Files touched: ${args.files_touched?.join(", ") || "none recorded"}`,
78365
78640
  console.warn("[swarm_complete] Failed to capture subtask outcome:", error452);
78366
78641
  }
78367
78642
  try {
78368
- const durationMs2 = args.start_time ? Date.now() - args.start_time : 0;
78643
+ const durationMs = args.start_time ? Date.now() - args.start_time : 0;
78369
78644
  captureCoordinatorEvent2({
78370
78645
  session_id: _ctx.sessionID || "unknown",
78371
78646
  epic_id: epicId2,
@@ -78374,7 +78649,7 @@ Files touched: ${args.files_touched?.join(", ") || "none recorded"}`,
78374
78649
  outcome_type: "subtask_success",
78375
78650
  payload: {
78376
78651
  bead_id: args.bead_id,
78377
- duration_ms: durationMs2,
78652
+ duration_ms: durationMs,
78378
78653
  files_touched: args.files_touched || [],
78379
78654
  verification_passed: verificationResult?.passed ?? false,
78380
78655
  verification_skipped: args.skip_verification ?? false
@@ -78848,7 +79123,7 @@ var swarm_checkpoint = tool2({
78848
79123
  }
78849
79124
  };
78850
79125
  const checkpointData = JSON.stringify(checkpoint);
78851
- const event = createEvent2("swarm_checkpointed", {
79126
+ const event = createEvent3("swarm_checkpointed", {
78852
79127
  project_key: args.project_key,
78853
79128
  epic_id: args.epic_id,
78854
79129
  bead_id: args.bead_id,
@@ -78890,8 +79165,8 @@ var swarm_recover = tool2({
78890
79165
  },
78891
79166
  async execute(args) {
78892
79167
  try {
78893
- const { getSwarmMailLibSQL: getSwarmMailLibSQL33 } = await import("swarm-mail");
78894
- const swarmMail = await getSwarmMailLibSQL33(args.project_key);
79168
+ const { getSwarmMailLibSQL: getSwarmMailLibSQL43 } = await import("swarm-mail");
79169
+ const swarmMail = await getSwarmMailLibSQL43(args.project_key);
78895
79170
  const db = await swarmMail.getDatabase();
78896
79171
  const result = await db.query(`SELECT * FROM swarm_contexts
78897
79172
  WHERE epic_id = $1
@@ -78918,7 +79193,7 @@ var swarm_recover = tool2({
78918
79193
  created_at: row.created_at,
78919
79194
  updated_at: row.updated_at
78920
79195
  };
78921
- const event = createEvent2("swarm_recovered", {
79196
+ const event = createEvent3("swarm_recovered", {
78922
79197
  project_key: args.project_key,
78923
79198
  epic_id: args.epic_id,
78924
79199
  bead_id: context.bead_id,
@@ -92421,7 +92696,7 @@ async function getMemoryAdapter(projectPath) {
92421
92696
  if (cachedAdapter && cachedProjectPath === path32) {
92422
92697
  return cachedAdapter;
92423
92698
  }
92424
- const swarmMail = await getSwarmMailLibSQL32(path32);
92699
+ const swarmMail = await getSwarmMailLibSQL42(path32);
92425
92700
  const dbAdapter = await swarmMail.getDatabase();
92426
92701
  cachedAdapter = await createMemoryAdapter(dbAdapter);
92427
92702
  cachedProjectPath = path32;
@@ -92442,6 +92717,21 @@ var semantic_memory_store = tool2({
92442
92717
  async execute(args2, ctx) {
92443
92718
  const adapter = await getMemoryAdapter();
92444
92719
  const result = await adapter.store(args2);
92720
+ try {
92721
+ const projectKey = cachedProjectPath || process.cwd();
92722
+ const tags = args2.tags ? args2.tags.split(",").map((t) => t.trim()) : [];
92723
+ const event = createEvent42("memory_stored", {
92724
+ project_key: projectKey,
92725
+ memory_id: result.id,
92726
+ content_preview: args2.information.slice(0, 100),
92727
+ tags,
92728
+ auto_tagged: args2.autoTag,
92729
+ collection: args2.collection
92730
+ });
92731
+ await appendEvent32(event, projectKey);
92732
+ } catch (error452) {
92733
+ console.warn("[semantic_memory_store] Failed to emit memory_stored event:", error452);
92734
+ }
92445
92735
  return JSON.stringify(result, null, 2);
92446
92736
  }
92447
92737
  });
@@ -92455,8 +92745,25 @@ var semantic_memory_find = tool2({
92455
92745
  fts: tool2.schema.boolean().optional().describe("Use full-text search instead of vector search (default: false)")
92456
92746
  },
92457
92747
  async execute(args2, ctx) {
92748
+ const startTime = Date.now();
92458
92749
  const adapter = await getMemoryAdapter();
92459
92750
  const result = await adapter.find(args2);
92751
+ const duration32 = Date.now() - startTime;
92752
+ try {
92753
+ const projectKey = cachedProjectPath || process.cwd();
92754
+ const topScore = result.results.length > 0 ? result.results[0].score : undefined;
92755
+ const event = createEvent42("memory_found", {
92756
+ project_key: projectKey,
92757
+ query: args2.query,
92758
+ result_count: result.results.length,
92759
+ top_score: topScore,
92760
+ search_duration_ms: duration32,
92761
+ used_fts: args2.fts
92762
+ });
92763
+ await appendEvent32(event, projectKey);
92764
+ } catch (error452) {
92765
+ console.warn("[semantic_memory_find] Failed to emit memory_found event:", error452);
92766
+ }
92460
92767
  return JSON.stringify(result, null, 2);
92461
92768
  }
92462
92769
  });
@@ -92479,6 +92786,18 @@ var semantic_memory_remove = tool2({
92479
92786
  async execute(args2, ctx) {
92480
92787
  const adapter = await getMemoryAdapter();
92481
92788
  const result = await adapter.remove(args2);
92789
+ if (result.success) {
92790
+ try {
92791
+ const projectKey = cachedProjectPath || process.cwd();
92792
+ const event = createEvent42("memory_deleted", {
92793
+ project_key: projectKey,
92794
+ memory_id: args2.id
92795
+ });
92796
+ await appendEvent32(event, projectKey);
92797
+ } catch (error452) {
92798
+ console.warn("[semantic_memory_remove] Failed to emit memory_deleted event:", error452);
92799
+ }
92800
+ }
92482
92801
  return JSON.stringify(result, null, 2);
92483
92802
  }
92484
92803
  });
@@ -92490,6 +92809,19 @@ var semantic_memory_validate = tool2({
92490
92809
  async execute(args2, ctx) {
92491
92810
  const adapter = await getMemoryAdapter();
92492
92811
  const result = await adapter.validate(args2);
92812
+ if (result.success) {
92813
+ try {
92814
+ const projectKey = cachedProjectPath || process.cwd();
92815
+ const event = createEvent42("memory_validated", {
92816
+ project_key: projectKey,
92817
+ memory_id: args2.id,
92818
+ decay_reset: true
92819
+ });
92820
+ await appendEvent32(event, projectKey);
92821
+ } catch (error452) {
92822
+ console.warn("[semantic_memory_validate] Failed to emit memory_validated event:", error452);
92823
+ }
92824
+ }
92493
92825
  return JSON.stringify(result, null, 2);
92494
92826
  }
92495
92827
  });
@@ -92537,6 +92869,18 @@ var semantic_memory_upsert = tool2({
92537
92869
  async execute(args2, ctx) {
92538
92870
  const adapter = await getMemoryAdapter();
92539
92871
  const result = await adapter.upsert(args2);
92872
+ try {
92873
+ const projectKey = cachedProjectPath || process.cwd();
92874
+ const event = createEvent42("memory_updated", {
92875
+ project_key: projectKey,
92876
+ memory_id: result.memoryId || "unknown",
92877
+ operation: result.operation,
92878
+ reason: result.reason
92879
+ });
92880
+ await appendEvent32(event, projectKey);
92881
+ } catch (error452) {
92882
+ console.warn("[semantic_memory_upsert] Failed to emit memory_updated event:", error452);
92883
+ }
92540
92884
  return JSON.stringify(result, null, 2);
92541
92885
  }
92542
92886
  });
@@ -93869,9 +94213,9 @@ var swarm_spawn_subtask = tool2({
93869
94213
  }
93870
94214
  if (args2.project_path) {
93871
94215
  try {
93872
- const { createEvent: createEvent32, appendEvent: appendEvent32 } = await import("swarm-mail");
94216
+ const { createEvent: createEvent5, appendEvent: appendEvent4 } = await import("swarm-mail");
93873
94217
  const spawnOrder = 0;
93874
- const workerSpawnedEvent = createEvent32("worker_spawned", {
94218
+ const workerSpawnedEvent = createEvent5("worker_spawned", {
93875
94219
  project_key: args2.project_path,
93876
94220
  epic_id: args2.epic_id,
93877
94221
  bead_id: args2.bead_id,
@@ -93881,7 +94225,7 @@ var swarm_spawn_subtask = tool2({
93881
94225
  spawn_order: spawnOrder,
93882
94226
  is_parallel: false
93883
94227
  });
93884
- await appendEvent32(workerSpawnedEvent, args2.project_path);
94228
+ await appendEvent4(workerSpawnedEvent, args2.project_path);
93885
94229
  } catch (error452) {
93886
94230
  console.warn("[swarm_spawn_subtask] Failed to emit WorkerSpawnedEvent:", error452);
93887
94231
  }
@@ -94175,13 +94519,13 @@ import {
94175
94519
  getLibSQLProjectTempDirName,
94176
94520
  getLibSQLDatabasePath,
94177
94521
  hashLibSQLProjectPath,
94178
- getSwarmMailLibSQL as getSwarmMailLibSQL10,
94522
+ getSwarmMailLibSQL as getSwarmMailLibSQL13,
94179
94523
  createHiveAdapter as createHiveAdapter4,
94180
94524
  resolvePartialId as resolvePartialId4,
94181
94525
  createDurableStreamAdapter,
94182
94526
  createDurableStreamServer
94183
94527
  } from "swarm-mail";
94184
- import { execSync } from "child_process";
94528
+ import { execSync as execSync2 } from "child_process";
94185
94529
  import { tmpdir as tmpdir3 } from "os";
94186
94530
 
94187
94531
  // src/query-tools.ts
@@ -94890,7 +95234,7 @@ import {
94890
95234
  agentActivity,
94891
95235
  checkpointFrequency,
94892
95236
  failedDecompositions,
94893
- getSwarmMailLibSQL as getSwarmMailLibSQL5,
95237
+ getSwarmMailLibSQL as getSwarmMailLibSQL6,
94894
95238
  humanFeedback,
94895
95239
  lockContention,
94896
95240
  messageLatency,
@@ -94955,7 +95299,7 @@ var swarm_analytics = tool3({
94955
95299
  async execute(args2) {
94956
95300
  try {
94957
95301
  const projectPath = process.cwd();
94958
- const db = await getSwarmMailLibSQL5(projectPath);
95302
+ const db = await getSwarmMailLibSQL6(projectPath);
94959
95303
  const filters = {
94960
95304
  project_key: projectPath
94961
95305
  };
@@ -95025,7 +95369,7 @@ var swarm_query = tool3({
95025
95369
  async execute(args2) {
95026
95370
  try {
95027
95371
  const projectPath = process.cwd();
95028
- const swarmMail = await getSwarmMailLibSQL5(projectPath);
95372
+ const swarmMail = await getSwarmMailLibSQL6(projectPath);
95029
95373
  const db = await swarmMail.getDatabase();
95030
95374
  if (!args2.sql.trim().toLowerCase().startsWith("select")) {
95031
95375
  return JSON.stringify({
@@ -95075,7 +95419,7 @@ var swarm_diagnose = tool3({
95075
95419
  async execute(args2) {
95076
95420
  try {
95077
95421
  const projectPath = process.cwd();
95078
- const swarmMail = await getSwarmMailLibSQL5(projectPath);
95422
+ const swarmMail = await getSwarmMailLibSQL6(projectPath);
95079
95423
  const db = await swarmMail.getDatabase();
95080
95424
  const diagnosis = [];
95081
95425
  const include = args2.include || [
@@ -95186,7 +95530,7 @@ var swarm_insights = tool3({
95186
95530
  });
95187
95531
  }
95188
95532
  const projectPath = process.cwd();
95189
- const swarmMail = await getSwarmMailLibSQL5(projectPath);
95533
+ const swarmMail = await getSwarmMailLibSQL6(projectPath);
95190
95534
  const db = await swarmMail.getDatabase();
95191
95535
  const insights = [];
95192
95536
  if (args2.metrics.includes("success_rate")) {
@@ -95314,7 +95658,7 @@ function aggregateByStrategy(outcomes) {
95314
95658
  }));
95315
95659
  }
95316
95660
  async function querySwarmHistory(projectPath, options2) {
95317
- const swarmMail = await getSwarmMailLibSQL5(projectPath);
95661
+ const swarmMail = await getSwarmMailLibSQL6(projectPath);
95318
95662
  const db = await swarmMail.getDatabase();
95319
95663
  const conditions = [];
95320
95664
  const params = [];
@@ -95483,20 +95827,6 @@ var STABILIZATION_THRESHOLD2 = 50;
95483
95827
  function getEvalHistoryPath2(projectPath) {
95484
95828
  return path6.join(projectPath, DEFAULT_EVAL_HISTORY_PATH2);
95485
95829
  }
95486
- function ensureEvalHistoryDir2(projectPath) {
95487
- const historyPath = getEvalHistoryPath2(projectPath);
95488
- const dir = path6.dirname(historyPath);
95489
- if (!fs4.existsSync(dir)) {
95490
- fs4.mkdirSync(dir, { recursive: true });
95491
- }
95492
- }
95493
- function recordEvalRun2(projectPath, run) {
95494
- ensureEvalHistoryDir2(projectPath);
95495
- const historyPath = getEvalHistoryPath2(projectPath);
95496
- const line = `${JSON.stringify(run)}
95497
- `;
95498
- fs4.appendFileSync(historyPath, line, "utf-8");
95499
- }
95500
95830
  function readAllRecords2(projectPath) {
95501
95831
  const historyPath = getEvalHistoryPath2(projectPath);
95502
95832
  if (!fs4.existsSync(historyPath)) {
@@ -95780,7 +96110,7 @@ import {
95780
96110
  FlushManager as FlushManager3,
95781
96111
  importFromJSONL as importFromJSONL3,
95782
96112
  syncMemories as syncMemories3,
95783
- getSwarmMailLibSQL as getSwarmMailLibSQL6,
96113
+ getSwarmMailLibSQL as getSwarmMailLibSQL7,
95784
96114
  resolvePartialId as resolvePartialId3,
95785
96115
  findCellsByPartialId as findCellsByPartialId3
95786
96116
  } from "swarm-mail";
@@ -96347,7 +96677,7 @@ var CellEventSchema3 = exports_external3.discriminatedUnion("type", [
96347
96677
  CellCompactedEventSchema3
96348
96678
  ]);
96349
96679
  // src/hive.ts
96350
- import { createEvent as createEvent5, appendEvent as appendEvent5 } from "swarm-mail";
96680
+ import { createEvent as createEvent6, appendEvent as appendEvent5 } from "swarm-mail";
96351
96681
  var hiveWorkingDirectory3 = null;
96352
96682
  function setHiveWorkingDirectory2(directory) {
96353
96683
  hiveWorkingDirectory3 = directory;
@@ -96431,7 +96761,7 @@ async function getHiveAdapter3(projectKey) {
96431
96761
  if (adapterCache3.has(projectKey)) {
96432
96762
  return adapterCache3.get(projectKey);
96433
96763
  }
96434
- const swarmMail = await getSwarmMailLibSQL6(projectKey);
96764
+ const swarmMail = await getSwarmMailLibSQL7(projectKey);
96435
96765
  const db = await swarmMail.getDatabase();
96436
96766
  const adapter = createHiveAdapter3(db, projectKey);
96437
96767
  await adapter.runMigrations();
@@ -96501,6 +96831,20 @@ var hive_create3 = tool3({
96501
96831
  parent_id: validated.parent_id
96502
96832
  });
96503
96833
  await adapter.markDirty(projectKey, cell.id);
96834
+ try {
96835
+ const event = createEvent6("cell_created", {
96836
+ project_key: projectKey,
96837
+ cell_id: cell.id,
96838
+ title: validated.title,
96839
+ description: validated.description,
96840
+ issue_type: validated.type || "task",
96841
+ priority: validated.priority ?? 2,
96842
+ parent_id: validated.parent_id
96843
+ });
96844
+ await appendEvent5(event, projectKey);
96845
+ } catch (error54) {
96846
+ console.warn("[hive_create] Failed to emit cell_created event:", error54);
96847
+ }
96504
96848
  const formatted = formatCellForOutput3(cell);
96505
96849
  return JSON.stringify(formatted, null, 2);
96506
96850
  } catch (error54) {
@@ -96561,7 +96905,20 @@ var hive_create_epic3 = tool3({
96561
96905
  };
96562
96906
  const effectiveProjectKey = args2.project_key || projectKey;
96563
96907
  try {
96564
- const event = createEvent5("decomposition_generated", {
96908
+ const epicCreatedEvent = createEvent6("epic_created", {
96909
+ project_key: effectiveProjectKey,
96910
+ epic_id: epic.id,
96911
+ title: validated.epic_title,
96912
+ description: validated.epic_description,
96913
+ subtask_count: validated.subtasks.length,
96914
+ subtask_ids: created.slice(1).map((c) => c.id)
96915
+ });
96916
+ await appendEvent5(epicCreatedEvent, effectiveProjectKey);
96917
+ } catch (error54) {
96918
+ console.warn("[hive_create_epic] Failed to emit epic_created event:", error54);
96919
+ }
96920
+ try {
96921
+ const event = createEvent6("decomposition_generated", {
96565
96922
  project_key: effectiveProjectKey,
96566
96923
  epic_id: epic.id,
96567
96924
  task: args2.task || validated.epic_title,
@@ -96581,7 +96938,7 @@ var hive_create_epic3 = tool3({
96581
96938
  }
96582
96939
  try {
96583
96940
  const totalFiles = validated.subtasks.reduce((count, st) => count + (st.files?.length || 0), 0);
96584
- const swarmStartedEvent = createEvent5("swarm_started", {
96941
+ const swarmStartedEvent = createEvent6("swarm_started", {
96585
96942
  project_key: effectiveProjectKey,
96586
96943
  epic_id: epic.id,
96587
96944
  epic_title: validated.epic_title,
@@ -96724,6 +97081,23 @@ var hive_update3 = tool3({
96724
97081
  cell = existingCell;
96725
97082
  }
96726
97083
  await adapter.markDirty(projectKey, cellId);
97084
+ try {
97085
+ const fieldsChanged = [];
97086
+ if (validated.status)
97087
+ fieldsChanged.push("status");
97088
+ if (validated.description !== undefined)
97089
+ fieldsChanged.push("description");
97090
+ if (validated.priority !== undefined)
97091
+ fieldsChanged.push("priority");
97092
+ const event = createEvent6("cell_updated", {
97093
+ project_key: projectKey,
97094
+ cell_id: cellId,
97095
+ fields_changed: fieldsChanged
97096
+ });
97097
+ await appendEvent5(event, projectKey);
97098
+ } catch (error54) {
97099
+ console.warn("[hive_update] Failed to emit cell_updated event:", error54);
97100
+ }
96727
97101
  const formatted = formatCellForOutput3(cell);
96728
97102
  return JSON.stringify(formatted, null, 2);
96729
97103
  } catch (error54) {
@@ -96756,7 +97130,7 @@ var hive_close3 = tool3({
96756
97130
  await adapter.markDirty(projectKey, cellId);
96757
97131
  if (isEpic && cellBeforeClose) {
96758
97132
  try {
96759
- const { createEvent: createEvent4, appendEvent: appendEvent4 } = await import("swarm-mail");
97133
+ const { createEvent: createEvent5, appendEvent: appendEvent4 } = await import("swarm-mail");
96760
97134
  const subtasks = await adapter.queryCells(projectKey, { parent_id: cellId });
96761
97135
  const completedSubtasks = subtasks.filter((st) => st.status === "closed");
96762
97136
  const failedSubtasks = subtasks.filter((st) => st.status === "blocked");
@@ -96794,7 +97168,7 @@ var hive_close3 = tool3({
96794
97168
  } catch (error54) {
96795
97169
  console.warn("[hive_close] Failed to calculate duration:", error54);
96796
97170
  }
96797
- const swarmCompletedEvent = createEvent4("swarm_completed", {
97171
+ const swarmCompletedEvent = createEvent5("swarm_completed", {
96798
97172
  project_key: projectKey,
96799
97173
  epic_id: cellId,
96800
97174
  epic_title: cellBeforeClose.title,
@@ -96840,6 +97214,16 @@ var hive_close3 = tool3({
96840
97214
  console.warn("[hive_close] Failed to emit SwarmCompletedEvent:", error54);
96841
97215
  }
96842
97216
  }
97217
+ try {
97218
+ const event = createEvent6("cell_closed", {
97219
+ project_key: projectKey,
97220
+ cell_id: cellId,
97221
+ reason: validated.reason
97222
+ });
97223
+ await appendEvent5(event, projectKey);
97224
+ } catch (error54) {
97225
+ console.warn("[hive_close] Failed to emit cell_closed event:", error54);
97226
+ }
96843
97227
  return `Closed ${cell.id}: ${validated.reason}`;
96844
97228
  } catch (error54) {
96845
97229
  const message = error54 instanceof Error ? error54.message : String(error54);
@@ -96865,6 +97249,17 @@ var hive_start3 = tool3({
96865
97249
  const cellId = await resolvePartialId3(adapter, projectKey, args2.id) || args2.id;
96866
97250
  const cell = await adapter.changeCellStatus(projectKey, cellId, "in_progress");
96867
97251
  await adapter.markDirty(projectKey, cellId);
97252
+ try {
97253
+ const event = createEvent6("cell_status_changed", {
97254
+ project_key: projectKey,
97255
+ cell_id: cellId,
97256
+ old_status: "open",
97257
+ new_status: "in_progress"
97258
+ });
97259
+ await appendEvent5(event, projectKey);
97260
+ } catch (error54) {
97261
+ console.warn("[hive_start] Failed to emit cell_status_changed event:", error54);
97262
+ }
96868
97263
  return `Started: ${cell.id}`;
96869
97264
  } catch (error54) {
96870
97265
  const message = error54 instanceof Error ? error54.message : String(error54);
@@ -96994,7 +97389,7 @@ var hive_sync3 = tool3({
96994
97389
  outputPath: `${projectKey}/.hive/issues.jsonl`
96995
97390
  });
96996
97391
  const flushResult = await withTimeout(flushManager.flush(), TIMEOUT_MS, "flush hive");
96997
- const swarmMail = await getSwarmMailLibSQL6(projectKey);
97392
+ const swarmMail = await getSwarmMailLibSQL7(projectKey);
96998
97393
  const db = await swarmMail.getDatabase();
96999
97394
  const hivePath = join13(projectKey, ".hive");
97000
97395
  let memoriesSynced = 0;
@@ -97053,11 +97448,25 @@ var hive_sync3 = tool3({
97053
97448
  }
97054
97449
  const remoteCheckResult = await runGitCommand3(["remote"]);
97055
97450
  const hasRemote = remoteCheckResult.stdout.trim() !== "";
97451
+ let pushSuccess = false;
97056
97452
  if (hasRemote) {
97057
97453
  const pushResult = await withTimeout(runGitCommand3(["push"]), TIMEOUT_MS, "git push");
97058
97454
  if (pushResult.exitCode !== 0) {
97059
97455
  throw new HiveError3(`Failed to push: ${pushResult.stderr}`, "git push", pushResult.exitCode);
97060
97456
  }
97457
+ pushSuccess = true;
97458
+ }
97459
+ try {
97460
+ const event = createEvent6("hive_synced", {
97461
+ project_key: projectKey,
97462
+ cells_synced: flushResult.cellsExported,
97463
+ push_success: pushSuccess
97464
+ });
97465
+ await appendEvent5(event, projectKey);
97466
+ } catch (error54) {
97467
+ console.warn("[hive_sync] Failed to emit hive_synced event:", error54);
97468
+ }
97469
+ if (hasRemote) {
97061
97470
  return "Hive synced and pushed successfully";
97062
97471
  } else {
97063
97472
  return "Hive synced successfully (no remote configured)";
@@ -101637,9 +102046,9 @@ import {
101637
102046
  releaseSwarmFiles as releaseSwarmFiles3,
101638
102047
  sendSwarmMessage as sendSwarmMessage6,
101639
102048
  getAgent as getAgent2,
101640
- createEvent as createEvent6,
102049
+ createEvent as createEvent8,
101641
102050
  appendEvent as appendEvent6,
101642
- getSwarmMailLibSQL as getSwarmMailLibSQL7
102051
+ getSwarmMailLibSQL as getSwarmMailLibSQL9
101643
102052
  } from "swarm-mail";
101644
102053
  init_skills2();
101645
102054
 
@@ -102142,9 +102551,9 @@ var swarm_review2 = tool3({
102142
102551
  downstream_tasks: downstreamTasks.length > 0 ? downstreamTasks : undefined
102143
102552
  });
102144
102553
  try {
102145
- const { createEvent: createEvent4, appendEvent: appendEvent4 } = await import("swarm-mail");
102554
+ const { createEvent: createEvent5, appendEvent: appendEvent4 } = await import("swarm-mail");
102146
102555
  const attempt = getReviewStatus2(args2.task_id).attempt_count || 1;
102147
- const reviewStartedEvent = createEvent4("review_started", {
102556
+ const reviewStartedEvent = createEvent5("review_started", {
102148
102557
  project_key: args2.project_key,
102149
102558
  epic_id: args2.epic_id,
102150
102559
  bead_id: args2.task_id,
@@ -102233,9 +102642,9 @@ var swarm_review_feedback2 = tool3({
102233
102642
  console.warn("[swarm_review_feedback] Failed to trace review_decision:", error54);
102234
102643
  }
102235
102644
  try {
102236
- const { createEvent: createEvent4, appendEvent: appendEvent4 } = await import("swarm-mail");
102645
+ const { createEvent: createEvent5, appendEvent: appendEvent4 } = await import("swarm-mail");
102237
102646
  const attempt = getReviewStatus2(args2.task_id).attempt_count || 1;
102238
- const reviewCompletedEvent = createEvent4("review_completed", {
102647
+ const reviewCompletedEvent = createEvent5("review_completed", {
102239
102648
  project_key: args2.project_key,
102240
102649
  epic_id: epicId,
102241
102650
  bead_id: args2.task_id,
@@ -102304,9 +102713,9 @@ You may now complete the task with \`swarm_complete\`.`,
102304
102713
  console.warn("[swarm_review_feedback] Failed to trace review_decision:", error54);
102305
102714
  }
102306
102715
  try {
102307
- const { createEvent: createEvent4, appendEvent: appendEvent4 } = await import("swarm-mail");
102716
+ const { createEvent: createEvent5, appendEvent: appendEvent4 } = await import("swarm-mail");
102308
102717
  const status = remaining <= 0 ? "blocked" : "needs_changes";
102309
- const reviewCompletedEvent = createEvent4("review_completed", {
102718
+ const reviewCompletedEvent = createEvent5("review_completed", {
102310
102719
  project_key: args2.project_key,
102311
102720
  epic_id: epicId,
102312
102721
  bead_id: args2.task_id,
@@ -102862,7 +103271,7 @@ var swarm_progress2 = tool3({
102862
103271
  }
102863
103272
  };
102864
103273
  const checkpointData = JSON.stringify(checkpoint);
102865
- const checkpointEvent = createEvent6("swarm_checkpointed", {
103274
+ const checkpointEvent = createEvent8("swarm_checkpointed", {
102866
103275
  project_key: args2.project_key,
102867
103276
  ...checkpoint,
102868
103277
  checkpoint_size_bytes: Buffer.byteLength(checkpointData, "utf8"),
@@ -102870,7 +103279,7 @@ var swarm_progress2 = tool3({
102870
103279
  });
102871
103280
  await appendEvent6(checkpointEvent, args2.project_key);
102872
103281
  const checkpointId = `ckpt-${Date.now()}-${args2.bead_id}`;
102873
- const createdEvent = createEvent6("checkpoint_created", {
103282
+ const createdEvent = createEvent8("checkpoint_created", {
102874
103283
  project_key: args2.project_key,
102875
103284
  epic_id: epicId,
102876
103285
  bead_id: args2.bead_id,
@@ -103123,7 +103532,7 @@ This will be recorded as a negative learning signal.`;
103123
103532
  let deferredResolved = false;
103124
103533
  let deferredError;
103125
103534
  try {
103126
- const swarmMail = await getSwarmMailLibSQL7(args2.project_key);
103535
+ const swarmMail = await getSwarmMailLibSQL9(args2.project_key);
103127
103536
  const db = await swarmMail.getDatabase();
103128
103537
  const deferredUrl = `deferred:${args2.bead_id}`;
103129
103538
  const checkResult = await db.query(`SELECT url, resolved FROM deferred WHERE url = ? AND resolved = 0`, [deferredUrl]);
@@ -103152,16 +103561,16 @@ This will be recorded as a negative learning signal.`;
103152
103561
  syncError = error54 instanceof Error ? error54.message : String(error54);
103153
103562
  console.warn(`[swarm_complete] Auto-sync failed (non-fatal): ${syncError}`);
103154
103563
  }
103564
+ const completionDurationMs = args2.start_time ? Date.now() - args2.start_time : 0;
103565
+ const eventEpicId = cell.parent_id || (args2.bead_id.includes(".") ? args2.bead_id.split(".")[0] : args2.bead_id);
103155
103566
  try {
103156
- const durationMs2 = args2.start_time ? Date.now() - args2.start_time : 0;
103157
- const eventEpicId = cell.parent_id || (args2.bead_id.includes(".") ? args2.bead_id.split(".")[0] : args2.bead_id);
103158
- const event = createEvent6("subtask_outcome", {
103567
+ const event = createEvent8("subtask_outcome", {
103159
103568
  project_key: args2.project_key,
103160
103569
  epic_id: eventEpicId,
103161
103570
  bead_id: args2.bead_id,
103162
103571
  planned_files: args2.planned_files || [],
103163
103572
  actual_files: args2.files_touched || [],
103164
- duration_ms: durationMs2,
103573
+ duration_ms: completionDurationMs,
103165
103574
  error_count: args2.error_count || 0,
103166
103575
  retry_count: args2.retry_count || 0,
103167
103576
  success: true,
@@ -103172,8 +103581,21 @@ This will be recorded as a negative learning signal.`;
103172
103581
  } catch (error54) {
103173
103582
  console.warn("[swarm_complete] Failed to emit SubtaskOutcomeEvent:", error54);
103174
103583
  }
103584
+ try {
103585
+ const workerCompletedEvent = createEvent8("worker_completed", {
103586
+ project_key: args2.project_key,
103587
+ epic_id: eventEpicId,
103588
+ bead_id: args2.bead_id,
103589
+ worker_agent: args2.agent_name,
103590
+ success: true,
103591
+ duration_ms: completionDurationMs,
103592
+ files_touched: args2.files_touched || []
103593
+ });
103594
+ await appendEvent6(workerCompletedEvent, args2.project_key);
103595
+ } catch (error54) {
103596
+ console.warn("[swarm_complete] Failed to emit worker_completed event:", error54);
103597
+ }
103175
103598
  let capturedStrategy;
103176
- const durationMs = args2.start_time ? Date.now() - args2.start_time : 0;
103177
103599
  const memoryInfo = formatMemoryStoreOnSuccess2(args2.bead_id, args2.summary, args2.files_touched || [], capturedStrategy);
103178
103600
  let memoryStored = false;
103179
103601
  let memoryError;
@@ -103290,7 +103712,7 @@ Files touched: ${args2.files_touched?.join(", ") || "none recorded"}`,
103290
103712
  };
103291
103713
  try {
103292
103714
  const { captureSubtaskOutcome: captureSubtaskOutcome4 } = await Promise.resolve().then(() => (init_eval_capture3(), exports_eval_capture3));
103293
- const durationMs2 = args2.start_time ? Date.now() - args2.start_time : 0;
103715
+ const durationMs = args2.start_time ? Date.now() - args2.start_time : 0;
103294
103716
  const evalEpicId = cell.parent_id || epicId2;
103295
103717
  captureSubtaskOutcome4({
103296
103718
  epicId: evalEpicId,
@@ -103299,7 +103721,7 @@ Files touched: ${args2.files_touched?.join(", ") || "none recorded"}`,
103299
103721
  title: cell.title,
103300
103722
  plannedFiles: args2.planned_files || [],
103301
103723
  actualFiles: args2.files_touched || [],
103302
- durationMs: durationMs2,
103724
+ durationMs,
103303
103725
  errorCount: args2.error_count || 0,
103304
103726
  retryCount: args2.retry_count || 0,
103305
103727
  success: true
@@ -103308,7 +103730,7 @@ Files touched: ${args2.files_touched?.join(", ") || "none recorded"}`,
103308
103730
  console.warn("[swarm_complete] Failed to capture subtask outcome:", error54);
103309
103731
  }
103310
103732
  try {
103311
- const durationMs2 = args2.start_time ? Date.now() - args2.start_time : 0;
103733
+ const durationMs = args2.start_time ? Date.now() - args2.start_time : 0;
103312
103734
  captureCoordinatorEvent4({
103313
103735
  session_id: _ctx.sessionID || "unknown",
103314
103736
  epic_id: epicId2,
@@ -103317,7 +103739,7 @@ Files touched: ${args2.files_touched?.join(", ") || "none recorded"}`,
103317
103739
  outcome_type: "subtask_success",
103318
103740
  payload: {
103319
103741
  bead_id: args2.bead_id,
103320
- duration_ms: durationMs2,
103742
+ duration_ms: durationMs,
103321
103743
  files_touched: args2.files_touched || [],
103322
103744
  verification_passed: verificationResult?.passed ?? false,
103323
103745
  verification_skipped: args2.skip_verification ?? false
@@ -103791,7 +104213,7 @@ var swarm_checkpoint2 = tool3({
103791
104213
  }
103792
104214
  };
103793
104215
  const checkpointData = JSON.stringify(checkpoint);
103794
- const event = createEvent6("swarm_checkpointed", {
104216
+ const event = createEvent8("swarm_checkpointed", {
103795
104217
  project_key: args2.project_key,
103796
104218
  epic_id: args2.epic_id,
103797
104219
  bead_id: args2.bead_id,
@@ -103833,8 +104255,8 @@ var swarm_recover2 = tool3({
103833
104255
  },
103834
104256
  async execute(args2) {
103835
104257
  try {
103836
- const { getSwarmMailLibSQL: getSwarmMailLibSQL4 } = await import("swarm-mail");
103837
- const swarmMail = await getSwarmMailLibSQL4(args2.project_key);
104258
+ const { getSwarmMailLibSQL: getSwarmMailLibSQL5 } = await import("swarm-mail");
104259
+ const swarmMail = await getSwarmMailLibSQL5(args2.project_key);
103838
104260
  const db = await swarmMail.getDatabase();
103839
104261
  const result = await db.query(`SELECT * FROM swarm_contexts
103840
104262
  WHERE epic_id = $1
@@ -103861,7 +104283,7 @@ var swarm_recover2 = tool3({
103861
104283
  created_at: row.created_at,
103862
104284
  updated_at: row.updated_at
103863
104285
  };
103864
- const event = createEvent6("swarm_recovered", {
104286
+ const event = createEvent8("swarm_recovered", {
103865
104287
  project_key: args2.project_key,
103866
104288
  epic_id: args2.epic_id,
103867
104289
  bead_id: context4.bead_id,
@@ -104036,7 +104458,7 @@ init_eval_capture3();
104036
104458
 
104037
104459
  // src/memory-tools.ts
104038
104460
  init_dist2();
104039
- import { getSwarmMailLibSQL as getSwarmMailLibSQL8 } from "swarm-mail";
104461
+ import { getSwarmMailLibSQL as getSwarmMailLibSQL10, createEvent as createEvent9, appendEvent as appendEvent7 } from "swarm-mail";
104040
104462
 
104041
104463
  // ../../node_modules/.bun/effect@3.19.12/node_modules/effect/dist/esm/Function.js
104042
104464
  var isFunction3 = (input) => typeof input === "function";
@@ -117653,7 +118075,7 @@ async function getMemoryAdapter2(projectPath) {
117653
118075
  if (cachedAdapter2 && cachedProjectPath2 === path4) {
117654
118076
  return cachedAdapter2;
117655
118077
  }
117656
- const swarmMail = await getSwarmMailLibSQL8(path4);
118078
+ const swarmMail = await getSwarmMailLibSQL10(path4);
117657
118079
  const dbAdapter = await swarmMail.getDatabase();
117658
118080
  cachedAdapter2 = await createMemoryAdapter2(dbAdapter);
117659
118081
  cachedProjectPath2 = path4;
@@ -117674,6 +118096,21 @@ var semantic_memory_store2 = tool3({
117674
118096
  async execute(args3, ctx) {
117675
118097
  const adapter = await getMemoryAdapter2();
117676
118098
  const result = await adapter.store(args3);
118099
+ try {
118100
+ const projectKey = cachedProjectPath2 || process.cwd();
118101
+ const tags = args3.tags ? args3.tags.split(",").map((t) => t.trim()) : [];
118102
+ const event = createEvent9("memory_stored", {
118103
+ project_key: projectKey,
118104
+ memory_id: result.id,
118105
+ content_preview: args3.information.slice(0, 100),
118106
+ tags,
118107
+ auto_tagged: args3.autoTag,
118108
+ collection: args3.collection
118109
+ });
118110
+ await appendEvent7(event, projectKey);
118111
+ } catch (error54) {
118112
+ console.warn("[semantic_memory_store] Failed to emit memory_stored event:", error54);
118113
+ }
117677
118114
  return JSON.stringify(result, null, 2);
117678
118115
  }
117679
118116
  });
@@ -117687,8 +118124,25 @@ var semantic_memory_find2 = tool3({
117687
118124
  fts: tool3.schema.boolean().optional().describe("Use full-text search instead of vector search (default: false)")
117688
118125
  },
117689
118126
  async execute(args3, ctx) {
118127
+ const startTime = Date.now();
117690
118128
  const adapter = await getMemoryAdapter2();
117691
118129
  const result = await adapter.find(args3);
118130
+ const duration4 = Date.now() - startTime;
118131
+ try {
118132
+ const projectKey = cachedProjectPath2 || process.cwd();
118133
+ const topScore = result.results.length > 0 ? result.results[0].score : undefined;
118134
+ const event = createEvent9("memory_found", {
118135
+ project_key: projectKey,
118136
+ query: args3.query,
118137
+ result_count: result.results.length,
118138
+ top_score: topScore,
118139
+ search_duration_ms: duration4,
118140
+ used_fts: args3.fts
118141
+ });
118142
+ await appendEvent7(event, projectKey);
118143
+ } catch (error54) {
118144
+ console.warn("[semantic_memory_find] Failed to emit memory_found event:", error54);
118145
+ }
117692
118146
  return JSON.stringify(result, null, 2);
117693
118147
  }
117694
118148
  });
@@ -117711,6 +118165,18 @@ var semantic_memory_remove2 = tool3({
117711
118165
  async execute(args3, ctx) {
117712
118166
  const adapter = await getMemoryAdapter2();
117713
118167
  const result = await adapter.remove(args3);
118168
+ if (result.success) {
118169
+ try {
118170
+ const projectKey = cachedProjectPath2 || process.cwd();
118171
+ const event = createEvent9("memory_deleted", {
118172
+ project_key: projectKey,
118173
+ memory_id: args3.id
118174
+ });
118175
+ await appendEvent7(event, projectKey);
118176
+ } catch (error54) {
118177
+ console.warn("[semantic_memory_remove] Failed to emit memory_deleted event:", error54);
118178
+ }
118179
+ }
117714
118180
  return JSON.stringify(result, null, 2);
117715
118181
  }
117716
118182
  });
@@ -117722,6 +118188,19 @@ var semantic_memory_validate2 = tool3({
117722
118188
  async execute(args3, ctx) {
117723
118189
  const adapter = await getMemoryAdapter2();
117724
118190
  const result = await adapter.validate(args3);
118191
+ if (result.success) {
118192
+ try {
118193
+ const projectKey = cachedProjectPath2 || process.cwd();
118194
+ const event = createEvent9("memory_validated", {
118195
+ project_key: projectKey,
118196
+ memory_id: args3.id,
118197
+ decay_reset: true
118198
+ });
118199
+ await appendEvent7(event, projectKey);
118200
+ } catch (error54) {
118201
+ console.warn("[semantic_memory_validate] Failed to emit memory_validated event:", error54);
118202
+ }
118203
+ }
117725
118204
  return JSON.stringify(result, null, 2);
117726
118205
  }
117727
118206
  });
@@ -117769,6 +118248,18 @@ var semantic_memory_upsert2 = tool3({
117769
118248
  async execute(args3, ctx) {
117770
118249
  const adapter = await getMemoryAdapter2();
117771
118250
  const result = await adapter.upsert(args3);
118251
+ try {
118252
+ const projectKey = cachedProjectPath2 || process.cwd();
118253
+ const event = createEvent9("memory_updated", {
118254
+ project_key: projectKey,
118255
+ memory_id: result.memoryId || "unknown",
118256
+ operation: result.operation,
118257
+ reason: result.reason
118258
+ });
118259
+ await appendEvent7(event, projectKey);
118260
+ } catch (error54) {
118261
+ console.warn("[semantic_memory_upsert] Failed to emit memory_updated event:", error54);
118262
+ }
117772
118263
  return JSON.stringify(result, null, 2);
117773
118264
  }
117774
118265
  });
@@ -118754,9 +119245,9 @@ var swarm_spawn_subtask2 = tool3({
118754
119245
  }
118755
119246
  if (args3.project_path) {
118756
119247
  try {
118757
- const { createEvent: createEvent4, appendEvent: appendEvent4 } = await import("swarm-mail");
119248
+ const { createEvent: createEvent5, appendEvent: appendEvent4 } = await import("swarm-mail");
118758
119249
  const spawnOrder = 0;
118759
- const workerSpawnedEvent = createEvent4("worker_spawned", {
119250
+ const workerSpawnedEvent = createEvent5("worker_spawned", {
118760
119251
  project_key: args3.project_path,
118761
119252
  epic_id: args3.epic_id,
118762
119253
  bead_id: args3.bead_id,
@@ -120398,7 +120889,7 @@ import {
120398
120889
  agentActivity as agentActivity2,
120399
120890
  checkpointFrequency as checkpointFrequency2,
120400
120891
  failedDecompositions as failedDecompositions2,
120401
- getSwarmMailLibSQL as getSwarmMailLibSQL9,
120892
+ getSwarmMailLibSQL as getSwarmMailLibSQL11,
120402
120893
  humanFeedback as humanFeedback2,
120403
120894
  lockContention as lockContention2,
120404
120895
  messageLatency as messageLatency2,
@@ -120463,7 +120954,7 @@ var swarm_analytics2 = tool3({
120463
120954
  async execute(args3) {
120464
120955
  try {
120465
120956
  const projectPath = process.cwd();
120466
- const db = await getSwarmMailLibSQL9(projectPath);
120957
+ const db = await getSwarmMailLibSQL11(projectPath);
120467
120958
  const filters = {
120468
120959
  project_key: projectPath
120469
120960
  };
@@ -120533,7 +121024,7 @@ var swarm_query2 = tool3({
120533
121024
  async execute(args3) {
120534
121025
  try {
120535
121026
  const projectPath = process.cwd();
120536
- const swarmMail = await getSwarmMailLibSQL9(projectPath);
121027
+ const swarmMail = await getSwarmMailLibSQL11(projectPath);
120537
121028
  const db = await swarmMail.getDatabase();
120538
121029
  if (!args3.sql.trim().toLowerCase().startsWith("select")) {
120539
121030
  return JSON.stringify({
@@ -120583,7 +121074,7 @@ var swarm_diagnose2 = tool3({
120583
121074
  async execute(args3) {
120584
121075
  try {
120585
121076
  const projectPath = process.cwd();
120586
- const swarmMail = await getSwarmMailLibSQL9(projectPath);
121077
+ const swarmMail = await getSwarmMailLibSQL11(projectPath);
120587
121078
  const db = await swarmMail.getDatabase();
120588
121079
  const diagnosis = [];
120589
121080
  const include = args3.include || [
@@ -120694,7 +121185,7 @@ var swarm_insights2 = tool3({
120694
121185
  });
120695
121186
  }
120696
121187
  const projectPath = process.cwd();
120697
- const swarmMail = await getSwarmMailLibSQL9(projectPath);
121188
+ const swarmMail = await getSwarmMailLibSQL11(projectPath);
120698
121189
  const db = await swarmMail.getDatabase();
120699
121190
  const insights = [];
120700
121191
  if (args3.metrics.includes("success_rate")) {
@@ -120754,344 +121245,6 @@ var observabilityTools = {
120754
121245
  swarm_insights: swarm_insights2
120755
121246
  };
120756
121247
 
120757
- // src/eval-runner.ts
120758
- init_dist2();
120759
- import { runEvalite } from "evalite/runner";
120760
- import { createInMemoryStorage } from "evalite/in-memory-storage";
120761
- import fs7 from "node:fs/promises";
120762
- import path10 from "node:path";
120763
-
120764
- // src/eval-gates.ts
120765
- var DEFAULT_THRESHOLDS2 = {
120766
- stabilization: 0.1,
120767
- production: 0.05
120768
- };
120769
- function calculateBaseline2(history, currentScore) {
120770
- if (history.length === 0) {
120771
- return currentScore;
120772
- }
120773
- return history.reduce((sum2, run) => sum2 + run.score, 0) / history.length;
120774
- }
120775
- function calculateRegression2(baseline, currentScore) {
120776
- if (baseline === 0) {
120777
- return 0;
120778
- }
120779
- return (baseline - currentScore) / baseline;
120780
- }
120781
- function formatRegressionMessage2(regressionPercent, baseline, currentScore) {
120782
- return `${(regressionPercent * 100).toFixed(1)}% regression (baseline: ${baseline.toFixed(2)}, current: ${currentScore.toFixed(2)})`;
120783
- }
120784
- function checkGate2(projectPath, evalName, currentScore, config4) {
120785
- const thresholds = {
120786
- stabilization: config4?.stabilizationThreshold ?? DEFAULT_THRESHOLDS2.stabilization,
120787
- production: config4?.productionThreshold ?? DEFAULT_THRESHOLDS2.production
120788
- };
120789
- const phase = getPhase2(projectPath, evalName);
120790
- const history = getScoreHistory2(projectPath, evalName);
120791
- if (phase === "bootstrap") {
120792
- return {
120793
- passed: true,
120794
- phase: "bootstrap",
120795
- message: `Bootstrap phase (${history.length}/10 runs) - collecting data`,
120796
- currentScore
120797
- };
120798
- }
120799
- const baseline = calculateBaseline2(history, currentScore);
120800
- const regressionPercent = calculateRegression2(baseline, currentScore);
120801
- const regressionMsg = formatRegressionMessage2(regressionPercent, baseline, currentScore);
120802
- if (phase === "stabilization") {
120803
- if (regressionPercent > thresholds.stabilization) {
120804
- return {
120805
- passed: true,
120806
- phase: "stabilization",
120807
- message: `Stabilization phase: ${regressionMsg} - exceeds ${(thresholds.stabilization * 100).toFixed(0)}% threshold but still passing`,
120808
- baseline,
120809
- currentScore,
120810
- regressionPercent
120811
- };
120812
- }
120813
- if (history.length > 50) {
120814
- const scores = history.map((run) => run.score);
120815
- const variance6 = calculateVariance2(scores);
120816
- return {
120817
- passed: true,
120818
- phase: "stabilization",
120819
- message: `Stabilization phase: ${regressionMsg} - acceptable. High variance (${variance6.toFixed(3)}) prevents production phase.`,
120820
- baseline,
120821
- currentScore,
120822
- regressionPercent
120823
- };
120824
- }
120825
- return {
120826
- passed: true,
120827
- phase: "stabilization",
120828
- message: `Stabilization phase: ${regressionMsg} - acceptable`,
120829
- baseline,
120830
- currentScore,
120831
- regressionPercent
120832
- };
120833
- }
120834
- if (regressionPercent > thresholds.production) {
120835
- return {
120836
- passed: false,
120837
- phase: "production",
120838
- message: `Production phase FAIL: ${regressionMsg} - exceeds ${(thresholds.production * 100).toFixed(0)}% threshold`,
120839
- baseline,
120840
- currentScore,
120841
- regressionPercent
120842
- };
120843
- }
120844
- return {
120845
- passed: true,
120846
- phase: "production",
120847
- message: `Production phase: ${regressionMsg} - acceptable`,
120848
- baseline,
120849
- currentScore,
120850
- regressionPercent
120851
- };
120852
- }
120853
-
120854
- // src/eval-learning.ts
120855
- var DEFAULT_EVAL_LEARNING_CONFIG = {
120856
- dropThreshold: 0.15,
120857
- windowSize: 5
120858
- };
120859
- function calculateRollingAverage(history, windowSize = 5) {
120860
- if (history.length === 0) {
120861
- return 0;
120862
- }
120863
- const recentRuns = history.slice(-windowSize);
120864
- const sum2 = recentRuns.reduce((acc, run) => acc + run.score, 0);
120865
- return sum2 / recentRuns.length;
120866
- }
120867
- function isSignificantDrop(currentScore, baseline, threshold = 0.15) {
120868
- if (baseline === 0) {
120869
- return false;
120870
- }
120871
- const drop4 = (baseline - currentScore) / baseline;
120872
- return drop4 >= threshold;
120873
- }
120874
- function formatFailureContext(evalName, currentScore, baseline, scorerContext) {
120875
- const dropPercentage = baseline > 0 ? (baseline - currentScore) / baseline * 100 : 0;
120876
- const lines = [
120877
- `Eval "${evalName}" regression detected:`,
120878
- `- Current score: ${currentScore.toFixed(2)}`,
120879
- `- Baseline (rolling avg): ${baseline.toFixed(2)}`,
120880
- `- Drop: ${dropPercentage.toFixed(1)}%`
120881
- ];
120882
- if (scorerContext) {
120883
- lines.push("", "Scorer context:", scorerContext);
120884
- }
120885
- lines.push("", "Action: Review recent changes that may have caused regression.", "Query this memory when generating future prompts for this eval.");
120886
- return lines.join(`
120887
- `);
120888
- }
120889
- async function learnFromEvalFailure(evalName, currentScore, history, memoryAdapter, options2) {
120890
- const config4 = options2?.config ?? DEFAULT_EVAL_LEARNING_CONFIG;
120891
- const baseline = calculateRollingAverage(history, config4.windowSize);
120892
- const dropPercentage = baseline > 0 ? (baseline - currentScore) / baseline : 0;
120893
- const significant = isSignificantDrop(currentScore, baseline, config4.dropThreshold);
120894
- const result = {
120895
- triggered: significant,
120896
- baseline,
120897
- current: currentScore,
120898
- drop_percentage: dropPercentage
120899
- };
120900
- if (significant) {
120901
- const information = formatFailureContext(evalName, currentScore, baseline, options2?.scorerContext);
120902
- const tags = ["eval-failure", evalName, "regression"].join(",");
120903
- const metadata = JSON.stringify({
120904
- eval_name: evalName,
120905
- baseline_score: baseline,
120906
- current_score: currentScore,
120907
- drop_percentage: dropPercentage,
120908
- timestamp: new Date().toISOString()
120909
- });
120910
- const storeResult = await memoryAdapter.store({
120911
- information,
120912
- tags,
120913
- metadata
120914
- });
120915
- if (storeResult.id) {
120916
- result.memory_id = storeResult.id;
120917
- }
120918
- }
120919
- return result;
120920
- }
120921
-
120922
- // src/eval-runner.ts
120923
- async function runEvals(options2 = {}) {
120924
- const {
120925
- cwd = process.cwd(),
120926
- suiteFilter,
120927
- scoreThreshold,
120928
- outputPath: userOutputPath
120929
- } = options2;
120930
- try {
120931
- const projectRoot = cwd.endsWith("src") ? path10.dirname(cwd) : cwd;
120932
- const evalsDir = path10.join(projectRoot, "evals");
120933
- let evalPath;
120934
- if (suiteFilter) {
120935
- try {
120936
- const files = await fs7.readdir(evalsDir);
120937
- const matchingFiles = files.filter((f) => f.toLowerCase().includes(suiteFilter.toLowerCase()));
120938
- if (matchingFiles.length === 0) {
120939
- return {
120940
- success: true,
120941
- totalSuites: 0,
120942
- totalEvals: 0,
120943
- averageScore: 0,
120944
- suites: []
120945
- };
120946
- }
120947
- evalPath = path10.join(evalsDir, matchingFiles[0]);
120948
- } catch (err) {
120949
- return {
120950
- success: false,
120951
- totalSuites: 0,
120952
- totalEvals: 0,
120953
- averageScore: 0,
120954
- suites: [],
120955
- error: `Failed to read evals directory: ${err instanceof Error ? err.message : String(err)}`
120956
- };
120957
- }
120958
- } else {
120959
- evalPath = evalsDir;
120960
- }
120961
- const outputPath = userOutputPath || path10.join(projectRoot, `.evalite-results-${Date.now()}.json`);
120962
- const isTemporaryOutput = !userOutputPath;
120963
- const storage = createInMemoryStorage();
120964
- await runEvalite({
120965
- path: evalPath,
120966
- cwd: projectRoot,
120967
- mode: "run-once-and-exit",
120968
- scoreThreshold,
120969
- outputPath,
120970
- hideTable: true,
120971
- storage,
120972
- disableServer: true
120973
- });
120974
- let outputJson;
120975
- try {
120976
- outputJson = await fs7.readFile(outputPath, "utf-8");
120977
- } catch (err) {
120978
- return {
120979
- success: false,
120980
- totalSuites: 0,
120981
- totalEvals: 0,
120982
- averageScore: 0,
120983
- suites: [],
120984
- error: `No results file generated: ${err instanceof Error ? err.message : String(err)}`
120985
- };
120986
- }
120987
- const output = JSON.parse(outputJson);
120988
- if (isTemporaryOutput) {
120989
- await fs7.unlink(outputPath).catch(() => {});
120990
- }
120991
- const suites = output.evals.map((evalItem) => ({
120992
- name: evalItem.name,
120993
- filepath: evalItem.filepath,
120994
- status: evalItem.status,
120995
- duration: evalItem.duration,
120996
- averageScore: evalItem.averageScore,
120997
- evalCount: evalItem.results.length,
120998
- evals: evalItem.results.map((r2) => ({
120999
- input: r2.input,
121000
- output: r2.output,
121001
- expected: r2.expected,
121002
- scores: r2.scores.map((s) => ({
121003
- name: s.name,
121004
- score: s.score,
121005
- description: s.description
121006
- }))
121007
- }))
121008
- }));
121009
- for (const suite of suites) {
121010
- const history = getScoreHistory2(projectRoot, suite.name);
121011
- recordEvalRun2(projectRoot, {
121012
- timestamp: new Date().toISOString(),
121013
- eval_name: suite.name,
121014
- score: suite.averageScore,
121015
- run_count: history.length + 1
121016
- });
121017
- }
121018
- const gateResults = [];
121019
- for (const suite of suites) {
121020
- const history = getScoreHistory2(projectRoot, suite.name);
121021
- const gate = checkGate2(projectRoot, suite.name, suite.averageScore);
121022
- gateResults.push({ suite: suite.name, ...gate });
121023
- if (!gate.passed) {
121024
- try {
121025
- const memoryAdapter = await getMemoryAdapter2();
121026
- await learnFromEvalFailure(suite.name, suite.averageScore, history, memoryAdapter);
121027
- } catch (e2) {
121028
- console.warn(`Failed to store learning for ${suite.name}:`, e2);
121029
- }
121030
- }
121031
- }
121032
- const totalEvals = suites.reduce((sum2, s) => sum2 + s.evalCount, 0);
121033
- const averageScore = suites.length > 0 ? suites.reduce((sum2, s) => sum2 + s.averageScore, 0) / suites.length : 0;
121034
- const thresholdPassed = scoreThreshold === undefined || averageScore * 100 >= scoreThreshold;
121035
- return {
121036
- success: thresholdPassed,
121037
- totalSuites: suites.length,
121038
- totalEvals,
121039
- averageScore,
121040
- suites,
121041
- gateResults
121042
- };
121043
- } catch (error54) {
121044
- return {
121045
- success: false,
121046
- totalSuites: 0,
121047
- totalEvals: 0,
121048
- averageScore: 0,
121049
- suites: [],
121050
- error: error54 instanceof Error ? error54.message : String(error54)
121051
- };
121052
- }
121053
- }
121054
- var eval_run = tool3({
121055
- description: `Run evalite evals programmatically and get structured results with scores.
121056
-
121057
- Use this to:
121058
- - Run all evals in evals/ directory
121059
- - Filter by specific eval suite (e.g., "coordinator", "compaction")
121060
- - Enforce score thresholds for quality gates
121061
- - Get per-suite and per-eval scores
121062
-
121063
- Returns structured JSON with:
121064
- - success: boolean (true if all tests passed threshold)
121065
- - totalSuites: number of eval suites run
121066
- - totalEvals: number of individual test cases
121067
- - averageScore: 0-1 score across all suites
121068
- - suites: array of suite results with scores
121069
-
121070
- Example usage:
121071
- - Run all evals: eval_run()
121072
- - Run coordinator evals: eval_run({ suiteFilter: "coordinator" })
121073
- - Enforce 80% threshold: eval_run({ scoreThreshold: 80 })`,
121074
- args: {
121075
- suiteFilter: tool3.schema.string().optional().describe('Optional filter to run specific eval suite (e.g., "coordinator", "compaction"). Matches against eval file paths using substring matching.'),
121076
- scoreThreshold: tool3.schema.number().optional().describe("Optional minimum average score threshold (0-100). If average score falls below this, result.success will be false. Useful for CI quality gates."),
121077
- includeDetailedResults: tool3.schema.boolean().optional().describe("Include individual eval results with input/output/scores in response. Set to false (default) for summary only to save token usage.")
121078
- },
121079
- execute: async (args3) => {
121080
- const result = await runEvals({
121081
- cwd: process.cwd(),
121082
- suiteFilter: args3.suiteFilter,
121083
- scoreThreshold: args3.scoreThreshold
121084
- });
121085
- const includeDetails = args3.includeDetailedResults === true;
121086
- if (!includeDetails) {
121087
- for (const suite of result.suites) {
121088
- delete suite.evals;
121089
- }
121090
- }
121091
- return JSON.stringify(result, null, 2);
121092
- }
121093
- });
121094
-
121095
121248
  // src/contributor-tools.ts
121096
121249
  init_dist2();
121097
121250
  init_zod3();
@@ -121183,6 +121336,268 @@ var contributorTools = {
121183
121336
  contributor_lookup
121184
121337
  };
121185
121338
 
121339
+ // src/cass-tools.ts
121340
+ init_dist2();
121341
+ import { execSync, spawn } from "child_process";
121342
+ import { getSwarmMailLibSQL as getSwarmMailLibSQL12, createEvent as createEvent10 } from "swarm-mail";
121343
+ function isCassAvailable() {
121344
+ try {
121345
+ execSync("which cass", { stdio: "ignore" });
121346
+ return true;
121347
+ } catch {
121348
+ return false;
121349
+ }
121350
+ }
121351
+ async function execCass(args3) {
121352
+ return new Promise((resolve3, reject) => {
121353
+ const proc = spawn("cass", args3, {
121354
+ stdio: ["ignore", "pipe", "pipe"]
121355
+ });
121356
+ let stdout = "";
121357
+ let stderr = "";
121358
+ proc.stdout.on("data", (data) => {
121359
+ stdout += data;
121360
+ });
121361
+ proc.stderr.on("data", (data) => {
121362
+ stderr += data;
121363
+ });
121364
+ proc.on("close", (code) => {
121365
+ if (code === 0) {
121366
+ resolve3(stdout);
121367
+ } else {
121368
+ reject(new Error(stderr || `cass exited with code ${code}`));
121369
+ }
121370
+ });
121371
+ proc.on("error", (err) => {
121372
+ if (err.code === "ENOENT") {
121373
+ reject(new Error("cass CLI not found. Install from: https://github.com/Dicklesworthstone/coding_agent_session_search"));
121374
+ } else {
121375
+ reject(err);
121376
+ }
121377
+ });
121378
+ });
121379
+ }
121380
+ async function emitEvent(eventType, data) {
121381
+ try {
121382
+ const projectPath = process.cwd();
121383
+ const swarmMail = await getSwarmMailLibSQL12(projectPath);
121384
+ const event = createEvent10(eventType, {
121385
+ project_key: projectPath,
121386
+ ...data
121387
+ });
121388
+ await swarmMail.appendEvent(event);
121389
+ } catch {}
121390
+ }
121391
+ var cass_search = tool3({
121392
+ description: "Search across all AI coding agent histories (Claude, Codex, Cursor, Gemini, Aider, ChatGPT, Cline, OpenCode). Query BEFORE solving problems from scratch - another agent may have already solved it.",
121393
+ args: {
121394
+ query: tool3.schema.string().describe("Search query (e.g., 'authentication error Next.js')"),
121395
+ agent: tool3.schema.string().optional().describe("Filter by agent name (e.g., 'claude', 'cursor')"),
121396
+ days: tool3.schema.number().optional().describe("Only search sessions from last N days"),
121397
+ limit: tool3.schema.number().optional().describe("Max results to return (default: 5)"),
121398
+ fields: tool3.schema.string().optional().describe("Field selection: 'minimal' for compact output (path, line, agent only)")
121399
+ },
121400
+ async execute(args3) {
121401
+ const startTime = Date.now();
121402
+ if (!isCassAvailable()) {
121403
+ return JSON.stringify({
121404
+ error: "cass CLI not found. Install from: https://github.com/Dicklesworthstone/coding_agent_session_search"
121405
+ });
121406
+ }
121407
+ try {
121408
+ const cliArgs = ["search", args3.query];
121409
+ if (args3.agent) {
121410
+ cliArgs.push("--agent", args3.agent);
121411
+ }
121412
+ if (args3.days) {
121413
+ cliArgs.push("--days", String(args3.days));
121414
+ }
121415
+ if (args3.limit) {
121416
+ cliArgs.push("--limit", String(args3.limit));
121417
+ }
121418
+ if (args3.fields === "minimal") {
121419
+ cliArgs.push("--minimal");
121420
+ }
121421
+ const output = await execCass(cliArgs);
121422
+ const lines = output.trim().split(`
121423
+ `).filter((l2) => l2.trim());
121424
+ const resultCount = lines.length;
121425
+ await emitEvent("cass_searched", {
121426
+ query: args3.query,
121427
+ agent_filter: args3.agent,
121428
+ days_filter: args3.days,
121429
+ result_count: resultCount,
121430
+ search_duration_ms: Date.now() - startTime
121431
+ });
121432
+ return output;
121433
+ } catch (error54) {
121434
+ return JSON.stringify({
121435
+ error: error54 instanceof Error ? error54.message : String(error54)
121436
+ });
121437
+ }
121438
+ }
121439
+ });
121440
+ var cass_view = tool3({
121441
+ description: "View a specific conversation/session from search results. Use source_path from cass_search output.",
121442
+ args: {
121443
+ path: tool3.schema.string().describe("Path to session file (from cass_search results)"),
121444
+ line: tool3.schema.number().optional().describe("Jump to specific line number")
121445
+ },
121446
+ async execute(args3) {
121447
+ if (!isCassAvailable()) {
121448
+ return JSON.stringify({
121449
+ error: "cass CLI not found. Install from: https://github.com/Dicklesworthstone/coding_agent_session_search"
121450
+ });
121451
+ }
121452
+ try {
121453
+ const cliArgs = ["view", args3.path];
121454
+ if (args3.line) {
121455
+ cliArgs.push("--line", String(args3.line));
121456
+ }
121457
+ const output = await execCass(cliArgs);
121458
+ let agentType;
121459
+ if (args3.path.includes("claude"))
121460
+ agentType = "claude";
121461
+ else if (args3.path.includes("cursor"))
121462
+ agentType = "cursor";
121463
+ else if (args3.path.includes("opencode"))
121464
+ agentType = "opencode";
121465
+ else if (args3.path.includes("codex"))
121466
+ agentType = "codex";
121467
+ await emitEvent("cass_viewed", {
121468
+ session_path: args3.path,
121469
+ line_number: args3.line,
121470
+ agent_type: agentType
121471
+ });
121472
+ return output;
121473
+ } catch (error54) {
121474
+ return JSON.stringify({
121475
+ error: error54 instanceof Error ? error54.message : String(error54)
121476
+ });
121477
+ }
121478
+ }
121479
+ });
121480
+ var cass_expand = tool3({
121481
+ description: "Expand context around a specific line in a session. Shows messages before/after.",
121482
+ args: {
121483
+ path: tool3.schema.string().describe("Path to session file"),
121484
+ line: tool3.schema.number().describe("Line number to expand around"),
121485
+ context: tool3.schema.number().optional().describe("Number of lines before/after to show (default: 5)")
121486
+ },
121487
+ async execute(args3) {
121488
+ if (!isCassAvailable()) {
121489
+ return JSON.stringify({
121490
+ error: "cass CLI not found. Install from: https://github.com/Dicklesworthstone/coding_agent_session_search"
121491
+ });
121492
+ }
121493
+ try {
121494
+ const cliArgs = ["expand", args3.path, "--line", String(args3.line)];
121495
+ if (args3.context) {
121496
+ cliArgs.push("--context", String(args3.context));
121497
+ }
121498
+ const output = await execCass(cliArgs);
121499
+ await emitEvent("cass_viewed", {
121500
+ session_path: args3.path,
121501
+ line_number: args3.line
121502
+ });
121503
+ return output;
121504
+ } catch (error54) {
121505
+ return JSON.stringify({
121506
+ error: error54 instanceof Error ? error54.message : String(error54)
121507
+ });
121508
+ }
121509
+ }
121510
+ });
121511
+ var cass_health = tool3({
121512
+ description: "Check if cass index is healthy. Exit 0 = ready, Exit 1 = needs indexing. Run this before searching.",
121513
+ args: {},
121514
+ async execute() {
121515
+ if (!isCassAvailable()) {
121516
+ return JSON.stringify({
121517
+ healthy: false,
121518
+ error: "cass CLI not found. Install from: https://github.com/Dicklesworthstone/coding_agent_session_search"
121519
+ });
121520
+ }
121521
+ try {
121522
+ await execCass(["health"]);
121523
+ return JSON.stringify({ healthy: true, message: "Index is ready" });
121524
+ } catch (error54) {
121525
+ return JSON.stringify({
121526
+ healthy: false,
121527
+ message: "Index needs rebuilding. Run cass_index()",
121528
+ error: error54 instanceof Error ? error54.message : String(error54)
121529
+ });
121530
+ }
121531
+ }
121532
+ });
121533
+ var cass_index = tool3({
121534
+ description: "Build or rebuild the search index. Run this if health check fails or to pick up new sessions.",
121535
+ args: {
121536
+ full: tool3.schema.boolean().optional().describe("Force full rebuild (default: incremental)")
121537
+ },
121538
+ async execute(args3) {
121539
+ const startTime = Date.now();
121540
+ if (!isCassAvailable()) {
121541
+ return JSON.stringify({
121542
+ error: "cass CLI not found. Install from: https://github.com/Dicklesworthstone/coding_agent_session_search"
121543
+ });
121544
+ }
121545
+ try {
121546
+ const cliArgs = ["index"];
121547
+ if (args3.full) {
121548
+ cliArgs.push("--full");
121549
+ }
121550
+ const output = await execCass(cliArgs);
121551
+ let sessionsIndexed = 0;
121552
+ let messagesIndexed = 0;
121553
+ const sessionsMatch = output.match(/(\d+)\s*sessions?/i);
121554
+ const messagesMatch = output.match(/(\d+)\s*messages?/i);
121555
+ if (sessionsMatch)
121556
+ sessionsIndexed = parseInt(sessionsMatch[1], 10);
121557
+ if (messagesMatch)
121558
+ messagesIndexed = parseInt(messagesMatch[1], 10);
121559
+ await emitEvent("cass_indexed", {
121560
+ sessions_indexed: sessionsIndexed,
121561
+ messages_indexed: messagesIndexed,
121562
+ duration_ms: Date.now() - startTime,
121563
+ full_rebuild: args3.full ?? false
121564
+ });
121565
+ return output;
121566
+ } catch (error54) {
121567
+ return JSON.stringify({
121568
+ error: error54 instanceof Error ? error54.message : String(error54)
121569
+ });
121570
+ }
121571
+ }
121572
+ });
121573
+ var cass_stats = tool3({
121574
+ description: "Show index statistics - how many sessions, messages, agents indexed.",
121575
+ args: {},
121576
+ async execute() {
121577
+ if (!isCassAvailable()) {
121578
+ return JSON.stringify({
121579
+ error: "cass CLI not found. Install from: https://github.com/Dicklesworthstone/coding_agent_session_search"
121580
+ });
121581
+ }
121582
+ try {
121583
+ const output = await execCass(["stats"]);
121584
+ return output;
121585
+ } catch (error54) {
121586
+ return JSON.stringify({
121587
+ error: error54 instanceof Error ? error54.message : String(error54)
121588
+ });
121589
+ }
121590
+ }
121591
+ });
121592
+ var cassTools = {
121593
+ cass_search,
121594
+ cass_view,
121595
+ cass_expand,
121596
+ cass_health,
121597
+ cass_index,
121598
+ cass_stats
121599
+ };
121600
+
121186
121601
  // src/planning-guardrails.ts
121187
121602
  init_eval_capture3();
121188
121603
 
@@ -121386,7 +121801,8 @@ var allTools = {
121386
121801
  ...mandateTools,
121387
121802
  ...memoryTools,
121388
121803
  ...observabilityTools,
121389
- ...contributorTools
121804
+ ...contributorTools,
121805
+ ...cassTools
121390
121806
  };
121391
121807
 
121392
121808
  // bin/swarm.ts
@@ -124277,7 +124693,7 @@ async function cells() {
124277
124693
  }
124278
124694
  const projectPath = process.cwd();
124279
124695
  try {
124280
- const swarmMail = await getSwarmMailLibSQL10(projectPath);
124696
+ const swarmMail = await getSwarmMailLibSQL13(projectPath);
124281
124697
  const db = await swarmMail.getDatabase();
124282
124698
  const adapter = createHiveAdapter4(db, projectPath);
124283
124699
  await adapter.runMigrations();
@@ -124533,7 +124949,7 @@ async function db() {
124533
124949
  const sizeKB = Math.round(stats.size / 1024);
124534
124950
  console.log(` ${green("\u2713")} Database exists (${sizeKB} KB)`);
124535
124951
  try {
124536
- const schema = execSync(`sqlite3 "${dbFile}" "SELECT sql FROM sqlite_master WHERE type='table' AND name='beads'"`, { encoding: "utf-8" }).trim();
124952
+ const schema = execSync2(`sqlite3 "${dbFile}" "SELECT sql FROM sqlite_master WHERE type='table' AND name='beads'"`, { encoding: "utf-8" }).trim();
124537
124953
  if (schema) {
124538
124954
  const hasProjectKey = schema.includes("project_key");
124539
124955
  if (hasProjectKey) {
@@ -124548,7 +124964,7 @@ async function db() {
124548
124964
  console.log(` ${dim("\u25CB")} No beads table yet (will be created on first use)`);
124549
124965
  }
124550
124966
  try {
124551
- const version5 = execSync(`sqlite3 "${dbFile}" "SELECT MAX(version) FROM schema_version"`, { encoding: "utf-8" }).trim();
124967
+ const version5 = execSync2(`sqlite3 "${dbFile}" "SELECT MAX(version) FROM schema_version"`, { encoding: "utf-8" }).trim();
124552
124968
  if (version5 && version5 !== "") {
124553
124969
  console.log(` ${dim("\u25CB")} Schema version: ${version5}`);
124554
124970
  }
@@ -124556,11 +124972,11 @@ async function db() {
124556
124972
  console.log(` ${dim("\u25CB")} No schema_version table`);
124557
124973
  }
124558
124974
  try {
124559
- const beadCount = execSync(`sqlite3 "${dbFile}" "SELECT COUNT(*) FROM beads"`, { encoding: "utf-8" }).trim();
124975
+ const beadCount = execSync2(`sqlite3 "${dbFile}" "SELECT COUNT(*) FROM beads"`, { encoding: "utf-8" }).trim();
124560
124976
  console.log(` ${dim("\u25CB")} Cells: ${beadCount}`);
124561
124977
  } catch {}
124562
124978
  try {
124563
- const memoryCount = execSync(`sqlite3 "${dbFile}" "SELECT COUNT(*) FROM memories"`, { encoding: "utf-8" }).trim();
124979
+ const memoryCount = execSync2(`sqlite3 "${dbFile}" "SELECT COUNT(*) FROM memories"`, { encoding: "utf-8" }).trim();
124564
124980
  console.log(` ${dim("\u25CB")} Memories: ${memoryCount}`);
124565
124981
  } catch {}
124566
124982
  } catch (error54) {
@@ -124691,7 +125107,7 @@ async function stats() {
124691
125107
  }
124692
125108
  try {
124693
125109
  const projectPath = process.cwd();
124694
- const swarmMail = await getSwarmMailLibSQL10(projectPath);
125110
+ const swarmMail = await getSwarmMailLibSQL13(projectPath);
124695
125111
  const db2 = await swarmMail.getDatabase();
124696
125112
  const since = parseTimePeriod(period);
124697
125113
  const periodMatch = period.match(/^(\d+)([dhm])$/);
@@ -124997,7 +125413,7 @@ async function serve() {
124997
125413
  M2.message(dim(` Project: ${projectPath}`));
124998
125414
  M2.message(dim(` Port: ${port} (HIVE on phone keypad)`));
124999
125415
  try {
125000
- const swarmMail = await getSwarmMailLibSQL10(projectPath);
125416
+ const swarmMail = await getSwarmMailLibSQL13(projectPath);
125001
125417
  const streamAdapter = createDurableStreamAdapter(swarmMail, projectPath);
125002
125418
  const db2 = await swarmMail.getDatabase(projectPath);
125003
125419
  const hiveAdapter = createHiveAdapter4(db2, projectPath);
@@ -125032,7 +125448,7 @@ async function viz() {
125032
125448
  M2.message(dim(` Project: ${projectPath}`));
125033
125449
  M2.message(dim(` Port: ${port}`));
125034
125450
  try {
125035
- const swarmMail = await getSwarmMailLibSQL10(projectPath);
125451
+ const swarmMail = await getSwarmMailLibSQL13(projectPath);
125036
125452
  const streamAdapter = createDurableStreamAdapter(swarmMail, projectPath);
125037
125453
  const db2 = await swarmMail.getDatabase(projectPath);
125038
125454
  const hiveAdapter = createHiveAdapter4(db2, projectPath);