@adhdev/daemon-core 0.9.82-rc.275 → 0.9.82-rc.276

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.
@@ -85,6 +85,7 @@ export interface DaemonComponents {
85
85
  meshReconcileLoop?: {
86
86
  stop(): void;
87
87
  };
88
+ statusInstanceId?: string;
88
89
  }
89
90
  export interface DaemonDevSupportOptions {
90
91
  components: DaemonComponents;
package/dist/index.js CHANGED
@@ -275,10 +275,10 @@ function readInjected(value) {
275
275
  }
276
276
  function getDaemonBuildInfo() {
277
277
  if (cached) return cached;
278
- const commit = readInjected(true ? "080b607ef221e44126942d9d52eaf547b4e92550" : void 0) ?? "unknown";
279
- const commitShort = readInjected(true ? "080b607e" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
280
- const version = readInjected(true ? "0.9.82-rc.275" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
281
- const builtAt = readInjected(true ? "2026-06-15T08:24:26.468Z" : void 0);
278
+ const commit = readInjected(true ? "746fc68e4c297b988b76207bb8c63ab6062a38e1" : void 0) ?? "unknown";
279
+ const commitShort = readInjected(true ? "746fc68e" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
280
+ const version = readInjected(true ? "0.9.82-rc.276" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
281
+ const builtAt = readInjected(true ? "2026-06-15T09:29:09.895Z" : void 0);
282
282
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
283
283
  return cached;
284
284
  }
@@ -4279,11 +4279,12 @@ var init_mesh_runtime_store = __esm({
4279
4279
  const onlyEvents = opts?.onlyEvents;
4280
4280
  if (onlyEvents && onlyEvents.size === 0) return [];
4281
4281
  const eventList = onlyEvents ? [...onlyEvents] : [];
4282
+ const daemonIds = (Array.isArray(coordinatorDaemonId) ? coordinatorDaemonId : coordinatorDaemonId ? [coordinatorDaemonId] : []).filter((id) => typeof id === "string" && id.length > 0);
4282
4283
  const clauses = ["mesh_id = ?", "drained = 0"];
4283
4284
  const params = [meshId];
4284
- if (coordinatorDaemonId) {
4285
- clauses.push("(coordinator_daemon_id IS NULL OR coordinator_daemon_id = ?)");
4286
- params.push(coordinatorDaemonId);
4285
+ if (daemonIds.length > 0) {
4286
+ clauses.push(`(coordinator_daemon_id IS NULL OR coordinator_daemon_id IN (${daemonIds.map(() => "?").join(",")}))`);
4287
+ params.push(...daemonIds);
4287
4288
  }
4288
4289
  if (eventList.length > 0) {
4289
4290
  clauses.push(`event IN (${eventList.map(() => "?").join(",")})`);
@@ -4313,8 +4314,9 @@ var init_mesh_runtime_store = __esm({
4313
4314
  }
4314
4315
  /** Non-destructive peek — returns undrained events without marking them drained. */
4315
4316
  peekPendingEvents(meshId, coordinatorDaemonId) {
4316
- const whereClause = coordinatorDaemonId ? `WHERE mesh_id = ? AND drained = 0 AND (coordinator_daemon_id IS NULL OR coordinator_daemon_id = ?)` : `WHERE mesh_id = ? AND drained = 0`;
4317
- const params = coordinatorDaemonId ? [meshId, coordinatorDaemonId] : [meshId];
4317
+ const daemonIds = (Array.isArray(coordinatorDaemonId) ? coordinatorDaemonId : coordinatorDaemonId ? [coordinatorDaemonId] : []).filter((id) => typeof id === "string" && id.length > 0);
4318
+ const whereClause = daemonIds.length > 0 ? `WHERE mesh_id = ? AND drained = 0 AND (coordinator_daemon_id IS NULL OR coordinator_daemon_id IN (${daemonIds.map(() => "?").join(",")}))` : `WHERE mesh_id = ? AND drained = 0`;
4319
+ const params = daemonIds.length > 0 ? [meshId, ...daemonIds] : [meshId];
4318
4320
  const rows = this.db.prepare(
4319
4321
  `SELECT id, event, payload FROM mesh_pending_events ${whereClause} ORDER BY queued_at ASC LIMIT 100`
4320
4322
  ).all(...params);
@@ -6354,6 +6356,19 @@ var init_mesh_events_utils = __esm({
6354
6356
  });
6355
6357
 
6356
6358
  // src/mesh/mesh-events-pending.ts
6359
+ function normalizeCoordinatorDaemonIds(coordinatorDaemonId) {
6360
+ const raw = Array.isArray(coordinatorDaemonId) ? coordinatorDaemonId : coordinatorDaemonId != null ? [coordinatorDaemonId] : [];
6361
+ const seen = /* @__PURE__ */ new Set();
6362
+ const out = [];
6363
+ for (const id of raw) {
6364
+ if (typeof id !== "string") continue;
6365
+ const trimmed = id.trim();
6366
+ if (!trimmed || seen.has(trimmed)) continue;
6367
+ seen.add(trimmed);
6368
+ out.push(trimmed);
6369
+ }
6370
+ return out;
6371
+ }
6357
6372
  function readRefineJobId2(event) {
6358
6373
  const metadata = readRecord3(event.metadataEvent) || event;
6359
6374
  const result = readRecord3(metadata.result);
@@ -6408,7 +6423,9 @@ function getPendingEventsPath(meshId, coordinatorDaemonId) {
6408
6423
  }
6409
6424
  function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
6410
6425
  if (!meshId) return [];
6411
- const paths = coordinatorDaemonId ? [getPendingEventsPath(meshId, coordinatorDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
6426
+ const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
6427
+ const primaryDaemonId = daemonIds[0];
6428
+ const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
6412
6429
  const events = [];
6413
6430
  for (const path39 of paths) {
6414
6431
  if (!(0, import_fs8.existsSync)(path39)) continue;
@@ -6421,7 +6438,7 @@ function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
6421
6438
  return [];
6422
6439
  }
6423
6440
  });
6424
- const filtered = coordinatorDaemonId && path39 === getPendingEventsPath(meshId) ? parsed.filter((e) => !e.targetCoordinatorDaemonId || e.targetCoordinatorDaemonId === coordinatorDaemonId) : parsed;
6441
+ const filtered = primaryDaemonId && path39 === getPendingEventsPath(meshId) ? parsed.filter((e) => !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId)) : parsed;
6425
6442
  events.push(...filtered);
6426
6443
  } catch {
6427
6444
  }
@@ -6599,6 +6616,8 @@ function selectiveDrainFile(path39, predicate) {
6599
6616
  }
6600
6617
  function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId, opts) {
6601
6618
  if (!meshId) return [];
6619
+ const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
6620
+ const primaryDaemonId = daemonIds[0];
6602
6621
  const onlyEvents = opts?.onlyEvents;
6603
6622
  const matchesFilter = (eventName) => !onlyEvents || onlyEvents.has(eventName);
6604
6623
  const merged = [];
@@ -6614,17 +6633,17 @@ function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId, opts) {
6614
6633
  try {
6615
6634
  const store = MeshRuntimeStore.getInstance();
6616
6635
  if (store.pendingEventCount(meshId) > 0) {
6617
- for (const row of store.drainPendingEvents(meshId, coordinatorDaemonId, onlyEvents ? { onlyEvents } : void 0)) {
6636
+ for (const row of store.drainPendingEvents(meshId, daemonIds.length > 0 ? daemonIds : void 0, onlyEvents ? { onlyEvents } : void 0)) {
6618
6637
  const event = row.payload;
6619
6638
  if (event) pushUnique(event);
6620
6639
  }
6621
6640
  }
6622
6641
  } catch {
6623
6642
  }
6624
- const paths = coordinatorDaemonId ? [getPendingEventsPath(meshId, coordinatorDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
6643
+ const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
6625
6644
  for (const path39 of paths) {
6626
- const isSharedFile = coordinatorDaemonId && path39 === getPendingEventsPath(meshId);
6627
- const targets = (e) => !isSharedFile || !e.targetCoordinatorDaemonId || e.targetCoordinatorDaemonId === coordinatorDaemonId;
6645
+ const isSharedFile = !!primaryDaemonId && path39 === getPendingEventsPath(meshId);
6646
+ const targets = (e) => !isSharedFile || !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId);
6628
6647
  if (onlyEvents) {
6629
6648
  for (const event of selectiveDrainFile(path39, (e) => targets(e) && matchesFilter(e.event))) {
6630
6649
  pushUnique(event);
@@ -6648,6 +6667,7 @@ function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId, opts) {
6648
6667
  }
6649
6668
  function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
6650
6669
  if (!meshId) return [];
6670
+ const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
6651
6671
  const merged = [];
6652
6672
  const seenFingerprints = /* @__PURE__ */ new Set();
6653
6673
  const pushUnique = (event) => {
@@ -6661,14 +6681,14 @@ function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
6661
6681
  try {
6662
6682
  const store = MeshRuntimeStore.getInstance();
6663
6683
  if (store.pendingEventCount(meshId) > 0) {
6664
- for (const row of store.peekPendingEvents(meshId, coordinatorDaemonId)) {
6684
+ for (const row of store.peekPendingEvents(meshId, daemonIds.length > 0 ? daemonIds : void 0)) {
6665
6685
  const event = row.payload;
6666
6686
  if (event) pushUnique(event);
6667
6687
  }
6668
6688
  }
6669
6689
  } catch {
6670
6690
  }
6671
- for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId)) {
6691
+ for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId, daemonIds)) {
6672
6692
  pushUnique(event);
6673
6693
  }
6674
6694
  return reconcilePendingMeshCoordinatorEvents(meshId, merged);
@@ -7370,6 +7390,14 @@ var init_mesh_routing = __esm({
7370
7390
  });
7371
7391
 
7372
7392
  // src/mesh/mesh-events-coordinator.ts
7393
+ function resolveCoordinatorDrainDaemonIds(components) {
7394
+ const ids = /* @__PURE__ */ new Set();
7395
+ const statusInstanceId = readNonEmptyString2(components.statusInstanceId);
7396
+ if (statusInstanceId) ids.add(statusInstanceId);
7397
+ const machineId = readNonEmptyString2(loadConfig().machineId);
7398
+ if (machineId) ids.add(machineId);
7399
+ return [...ids];
7400
+ }
7373
7401
  function getCachedMeshByWorkspace(workspace) {
7374
7402
  const now = Date.now();
7375
7403
  const cached2 = meshByWorkspaceCache.get(workspace);
@@ -8494,8 +8522,8 @@ function setupMeshEventForwarding(components) {
8494
8522
  const status = readNonEmptyString2(flushState.status).toLowerCase();
8495
8523
  if (status === "idle") {
8496
8524
  try {
8497
- const localDaemonId = readNonEmptyString2(loadConfig().machineId) || void 0;
8498
- const pendingEvents = drainPendingMeshCoordinatorEvents(coordinatorMeshId, localDaemonId);
8525
+ const drainDaemonIds = resolveCoordinatorDrainDaemonIds(components);
8526
+ const pendingEvents = drainPendingMeshCoordinatorEvents(coordinatorMeshId, drainDaemonIds.length > 0 ? drainDaemonIds : void 0);
8499
8527
  if (pendingEvents.length > 0) {
8500
8528
  LOG.info("MeshEvents", `Auto-flushing ${pendingEvents.length} pending coordinator event(s) for mesh ${coordinatorMeshId} on coordinator idle`);
8501
8529
  for (const pending of pendingEvents) {
@@ -8611,6 +8639,14 @@ function resolveReconcileIntervalMs() {
8611
8639
  }
8612
8640
  return DEFAULT_RECONCILE_INTERVAL_MS;
8613
8641
  }
8642
+ function resolveCoordinatorDaemonIds(components) {
8643
+ const ids = /* @__PURE__ */ new Set();
8644
+ const statusInstanceId = readNonEmptyString2(components.statusInstanceId);
8645
+ if (statusInstanceId) ids.add(statusInstanceId);
8646
+ const machineId = readNonEmptyString2(loadConfig().machineId);
8647
+ if (machineId) ids.add(machineId);
8648
+ return [...ids];
8649
+ }
8614
8650
  function findLiveCoordinators(components) {
8615
8651
  const out = [];
8616
8652
  for (const inst of components.instanceManager.getByCategory("cli")) {
@@ -8643,6 +8679,7 @@ async function runMeshReconcileTick(components) {
8643
8679
  else byMesh.set(c.meshId, [c]);
8644
8680
  }
8645
8681
  const localDaemonId = readNonEmptyString2(loadConfig().machineId) || void 0;
8682
+ const drainDaemonIds = resolveCoordinatorDaemonIds(components);
8646
8683
  const dispatchMeshCommand = components.dispatchMeshCommand;
8647
8684
  const store = (() => {
8648
8685
  try {
@@ -8673,7 +8710,7 @@ async function runMeshReconcileTick(components) {
8673
8710
  try {
8674
8711
  pendingEvents = drainPendingMeshCoordinatorEvents(
8675
8712
  meshId,
8676
- localDaemonId,
8713
+ drainDaemonIds.length > 0 ? drainDaemonIds : localDaemonId,
8677
8714
  forceOnly ? { onlyEvents: MESH_FORCE_INJECT_EVENTS } : void 0
8678
8715
  );
8679
8716
  } catch (e) {
@@ -55782,7 +55819,8 @@ async function initDaemonComponents(config) {
55782
55819
  detectedIdes: detectedIdesRef,
55783
55820
  refreshProviderAvailability,
55784
55821
  dispatchMeshCommand: config.dispatchMeshCommand,
55785
- onMeshCoordinatorEventForwarded: config.onMeshCoordinatorEventForwarded
55822
+ onMeshCoordinatorEventForwarded: config.onMeshCoordinatorEventForwarded,
55823
+ statusInstanceId: config.statusInstanceId
55786
55824
  };
55787
55825
  setupMeshEventForwarding(components);
55788
55826
  components.meshReconcileLoop = setupMeshReconcileLoop(components);