@adhdev/daemon-standalone 0.9.82-rc.274 → 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.
package/dist/index.js CHANGED
@@ -29983,10 +29983,10 @@ var require_dist3 = __commonJS({
29983
29983
  }
29984
29984
  function getDaemonBuildInfo() {
29985
29985
  if (cached2) return cached2;
29986
- const commit = readInjected(true ? "89d1ac61612c1dfe7fac53be61ec5dbfa67d00b2" : void 0) ?? "unknown";
29987
- const commitShort = readInjected(true ? "89d1ac61" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
29988
- const version2 = readInjected(true ? "0.9.82-rc.274" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
29989
- const builtAt = readInjected(true ? "2026-06-15T07:05:20.920Z" : void 0);
29986
+ const commit = readInjected(true ? "746fc68e4c297b988b76207bb8c63ab6062a38e1" : void 0) ?? "unknown";
29987
+ const commitShort = readInjected(true ? "746fc68e" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
29988
+ const version2 = readInjected(true ? "0.9.82-rc.276" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
29989
+ const builtAt = readInjected(true ? "2026-06-15T09:29:38.830Z" : void 0);
29990
29990
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
29991
29991
  return cached2;
29992
29992
  }
@@ -34007,12 +34007,34 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
34007
34007
  this.maybeCheckpointWal();
34008
34008
  return result.changes > 0;
34009
34009
  }
34010
- drainPendingEvents(meshId, coordinatorDaemonId) {
34010
+ /**
34011
+ * Drain undrained pending events for a mesh, atomically marking them drained.
34012
+ * When `opts.onlyEvents` is supplied, ONLY rows whose `event` is in that set are
34013
+ * drained — the rest stay queued (drained=0) for a later drain. This is how the
34014
+ * reconcile loop force-drains terminal/force-inject events into a *generating*
34015
+ * coordinator while leaving non-force progress events for the coordinator's next
34016
+ * idle transition. Filtering happens inside the same transaction as the
34017
+ * drained=1 marking, so force-drain + a concurrent full drain can never both
34018
+ * consume the same row.
34019
+ */
34020
+ drainPendingEvents(meshId, coordinatorDaemonId, opts) {
34011
34021
  return this.transaction(() => {
34012
- 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`;
34013
- const params = coordinatorDaemonId ? [meshId, coordinatorDaemonId] : [meshId];
34022
+ const onlyEvents = opts?.onlyEvents;
34023
+ if (onlyEvents && onlyEvents.size === 0) return [];
34024
+ const eventList = onlyEvents ? [...onlyEvents] : [];
34025
+ const daemonIds = (Array.isArray(coordinatorDaemonId) ? coordinatorDaemonId : coordinatorDaemonId ? [coordinatorDaemonId] : []).filter((id) => typeof id === "string" && id.length > 0);
34026
+ const clauses = ["mesh_id = ?", "drained = 0"];
34027
+ const params = [meshId];
34028
+ if (daemonIds.length > 0) {
34029
+ clauses.push(`(coordinator_daemon_id IS NULL OR coordinator_daemon_id IN (${daemonIds.map(() => "?").join(",")}))`);
34030
+ params.push(...daemonIds);
34031
+ }
34032
+ if (eventList.length > 0) {
34033
+ clauses.push(`event IN (${eventList.map(() => "?").join(",")})`);
34034
+ params.push(...eventList);
34035
+ }
34014
34036
  const rows = this.db.prepare(
34015
- `SELECT id, event, payload FROM mesh_pending_events ${whereClause} ORDER BY queued_at ASC LIMIT 100`
34037
+ `SELECT id, event, payload FROM mesh_pending_events WHERE ${clauses.join(" AND ")} ORDER BY queued_at ASC LIMIT 100`
34016
34038
  ).all(...params);
34017
34039
  if (rows.length === 0) return [];
34018
34040
  const ids = rows.map((r) => r.id);
@@ -34035,8 +34057,9 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
34035
34057
  }
34036
34058
  /** Non-destructive peek — returns undrained events without marking them drained. */
34037
34059
  peekPendingEvents(meshId, coordinatorDaemonId) {
34038
- 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`;
34039
- const params = coordinatorDaemonId ? [meshId, coordinatorDaemonId] : [meshId];
34060
+ const daemonIds = (Array.isArray(coordinatorDaemonId) ? coordinatorDaemonId : coordinatorDaemonId ? [coordinatorDaemonId] : []).filter((id) => typeof id === "string" && id.length > 0);
34061
+ 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`;
34062
+ const params = daemonIds.length > 0 ? [meshId, ...daemonIds] : [meshId];
34040
34063
  const rows = this.db.prepare(
34041
34064
  `SELECT id, event, payload FROM mesh_pending_events ${whereClause} ORDER BY queued_at ASC LIMIT 100`
34042
34065
  ).all(...params);
@@ -36090,6 +36113,19 @@ Next step: ${nextStep}`;
36090
36113
  "use strict";
36091
36114
  }
36092
36115
  });
36116
+ function normalizeCoordinatorDaemonIds(coordinatorDaemonId) {
36117
+ const raw = Array.isArray(coordinatorDaemonId) ? coordinatorDaemonId : coordinatorDaemonId != null ? [coordinatorDaemonId] : [];
36118
+ const seen = /* @__PURE__ */ new Set();
36119
+ const out = [];
36120
+ for (const id of raw) {
36121
+ if (typeof id !== "string") continue;
36122
+ const trimmed = id.trim();
36123
+ if (!trimmed || seen.has(trimmed)) continue;
36124
+ seen.add(trimmed);
36125
+ out.push(trimmed);
36126
+ }
36127
+ return out;
36128
+ }
36093
36129
  function readRefineJobId2(event) {
36094
36130
  const metadata = readRecord3(event.metadataEvent) || event;
36095
36131
  const result = readRecord3(metadata.result);
@@ -36144,7 +36180,9 @@ Next step: ${nextStep}`;
36144
36180
  }
36145
36181
  function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
36146
36182
  if (!meshId) return [];
36147
- const paths = coordinatorDaemonId ? [getPendingEventsPath(meshId, coordinatorDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
36183
+ const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
36184
+ const primaryDaemonId = daemonIds[0];
36185
+ const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
36148
36186
  const events = [];
36149
36187
  for (const path39 of paths) {
36150
36188
  if (!(0, import_fs8.existsSync)(path39)) continue;
@@ -36157,7 +36195,7 @@ Next step: ${nextStep}`;
36157
36195
  return [];
36158
36196
  }
36159
36197
  });
36160
- const filtered = coordinatorDaemonId && path39 === getPendingEventsPath(meshId) ? parsed.filter((e) => !e.targetCoordinatorDaemonId || e.targetCoordinatorDaemonId === coordinatorDaemonId) : parsed;
36198
+ const filtered = primaryDaemonId && path39 === getPendingEventsPath(meshId) ? parsed.filter((e) => !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId)) : parsed;
36161
36199
  events.push(...filtered);
36162
36200
  } catch {
36163
36201
  }
@@ -36286,8 +36324,59 @@ Next step: ${nextStep}`;
36286
36324
  return null;
36287
36325
  }
36288
36326
  }
36289
- function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
36327
+ function selectiveDrainFile(path39, predicate) {
36328
+ const tmpPath = `${path39}.draining`;
36329
+ try {
36330
+ (0, import_fs8.renameSync)(path39, tmpPath);
36331
+ } catch {
36332
+ return [];
36333
+ }
36334
+ let content;
36335
+ try {
36336
+ content = (0, import_fs8.readFileSync)(tmpPath, "utf-8");
36337
+ } catch {
36338
+ try {
36339
+ (0, import_fs8.unlinkSync)(tmpPath);
36340
+ } catch {
36341
+ }
36342
+ return [];
36343
+ }
36344
+ const consumed = [];
36345
+ const keptLines = [];
36346
+ for (const line of content.split("\n")) {
36347
+ if (!line) continue;
36348
+ let parsed;
36349
+ try {
36350
+ parsed = JSON.parse(line);
36351
+ } catch {
36352
+ parsed = void 0;
36353
+ }
36354
+ if (parsed && predicate(parsed)) {
36355
+ consumed.push(parsed);
36356
+ } else {
36357
+ keptLines.push(line);
36358
+ }
36359
+ }
36360
+ try {
36361
+ if (keptLines.length > 0) {
36362
+ (0, import_fs8.writeFileSync)(path39, keptLines.join("\n") + "\n", "utf-8");
36363
+ }
36364
+ (0, import_fs8.unlinkSync)(tmpPath);
36365
+ } catch {
36366
+ try {
36367
+ if ((0, import_fs8.existsSync)(tmpPath) && !(0, import_fs8.existsSync)(path39)) (0, import_fs8.renameSync)(tmpPath, path39);
36368
+ } catch {
36369
+ }
36370
+ return [];
36371
+ }
36372
+ return consumed;
36373
+ }
36374
+ function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId, opts) {
36290
36375
  if (!meshId) return [];
36376
+ const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
36377
+ const primaryDaemonId = daemonIds[0];
36378
+ const onlyEvents = opts?.onlyEvents;
36379
+ const matchesFilter = (eventName) => !onlyEvents || onlyEvents.has(eventName);
36291
36380
  const merged = [];
36292
36381
  const seenFingerprints = /* @__PURE__ */ new Set();
36293
36382
  const pushUnique = (event) => {
@@ -36301,15 +36390,23 @@ Next step: ${nextStep}`;
36301
36390
  try {
36302
36391
  const store = MeshRuntimeStore.getInstance();
36303
36392
  if (store.pendingEventCount(meshId) > 0) {
36304
- for (const row of store.drainPendingEvents(meshId, coordinatorDaemonId)) {
36393
+ for (const row of store.drainPendingEvents(meshId, daemonIds.length > 0 ? daemonIds : void 0, onlyEvents ? { onlyEvents } : void 0)) {
36305
36394
  const event = row.payload;
36306
36395
  if (event) pushUnique(event);
36307
36396
  }
36308
36397
  }
36309
36398
  } catch {
36310
36399
  }
36311
- const paths = coordinatorDaemonId ? [getPendingEventsPath(meshId, coordinatorDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
36400
+ const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
36312
36401
  for (const path39 of paths) {
36402
+ const isSharedFile = !!primaryDaemonId && path39 === getPendingEventsPath(meshId);
36403
+ const targets = (e) => !isSharedFile || !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId);
36404
+ if (onlyEvents) {
36405
+ for (const event of selectiveDrainFile(path39, (e) => targets(e) && matchesFilter(e.event))) {
36406
+ pushUnique(event);
36407
+ }
36408
+ continue;
36409
+ }
36313
36410
  const content = atomicDrainFile(path39);
36314
36411
  if (!content) continue;
36315
36412
  const parsed = content.split("\n").filter(Boolean).flatMap((line) => {
@@ -36319,7 +36416,7 @@ Next step: ${nextStep}`;
36319
36416
  return [];
36320
36417
  }
36321
36418
  });
36322
- const filtered = coordinatorDaemonId && path39 === getPendingEventsPath(meshId) ? parsed.filter((e) => !e.targetCoordinatorDaemonId || e.targetCoordinatorDaemonId === coordinatorDaemonId) : parsed;
36419
+ const filtered = isSharedFile ? parsed.filter(targets) : parsed;
36323
36420
  for (const event of filtered) pushUnique(event);
36324
36421
  }
36325
36422
  if (merged.length === 0) return [];
@@ -36327,6 +36424,7 @@ Next step: ${nextStep}`;
36327
36424
  }
36328
36425
  function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
36329
36426
  if (!meshId) return [];
36427
+ const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
36330
36428
  const merged = [];
36331
36429
  const seenFingerprints = /* @__PURE__ */ new Set();
36332
36430
  const pushUnique = (event) => {
@@ -36340,14 +36438,14 @@ Next step: ${nextStep}`;
36340
36438
  try {
36341
36439
  const store = MeshRuntimeStore.getInstance();
36342
36440
  if (store.pendingEventCount(meshId) > 0) {
36343
- for (const row of store.peekPendingEvents(meshId, coordinatorDaemonId)) {
36441
+ for (const row of store.peekPendingEvents(meshId, daemonIds.length > 0 ? daemonIds : void 0)) {
36344
36442
  const event = row.payload;
36345
36443
  if (event) pushUnique(event);
36346
36444
  }
36347
36445
  }
36348
36446
  } catch {
36349
36447
  }
36350
- for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId)) {
36448
+ for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId, daemonIds)) {
36351
36449
  pushUnique(event);
36352
36450
  }
36353
36451
  return reconcilePendingMeshCoordinatorEvents(meshId, merged);
@@ -37052,6 +37150,14 @@ Next step: ${nextStep}`;
37052
37150
  recentUnroutableDiagnostics = /* @__PURE__ */ new Map();
37053
37151
  }
37054
37152
  });
37153
+ function resolveCoordinatorDrainDaemonIds(components) {
37154
+ const ids = /* @__PURE__ */ new Set();
37155
+ const statusInstanceId = readNonEmptyString2(components.statusInstanceId);
37156
+ if (statusInstanceId) ids.add(statusInstanceId);
37157
+ const machineId = readNonEmptyString2(loadConfig2().machineId);
37158
+ if (machineId) ids.add(machineId);
37159
+ return [...ids];
37160
+ }
37055
37161
  function getCachedMeshByWorkspace(workspace) {
37056
37162
  const now = Date.now();
37057
37163
  const cached22 = meshByWorkspaceCache.get(workspace);
@@ -38176,8 +38282,8 @@ Next step: ${nextStep}`;
38176
38282
  const status = readNonEmptyString2(flushState.status).toLowerCase();
38177
38283
  if (status === "idle") {
38178
38284
  try {
38179
- const localDaemonId = readNonEmptyString2(loadConfig2().machineId) || void 0;
38180
- const pendingEvents = drainPendingMeshCoordinatorEvents(coordinatorMeshId, localDaemonId);
38285
+ const drainDaemonIds = resolveCoordinatorDrainDaemonIds(components);
38286
+ const pendingEvents = drainPendingMeshCoordinatorEvents(coordinatorMeshId, drainDaemonIds.length > 0 ? drainDaemonIds : void 0);
38181
38287
  if (pendingEvents.length > 0) {
38182
38288
  LOG2.info("MeshEvents", `Auto-flushing ${pendingEvents.length} pending coordinator event(s) for mesh ${coordinatorMeshId} on coordinator idle`);
38183
38289
  for (const pending of pendingEvents) {
@@ -38304,6 +38410,14 @@ Next step: ${nextStep}`;
38304
38410
  }
38305
38411
  return DEFAULT_RECONCILE_INTERVAL_MS;
38306
38412
  }
38413
+ function resolveCoordinatorDaemonIds(components) {
38414
+ const ids = /* @__PURE__ */ new Set();
38415
+ const statusInstanceId = readNonEmptyString2(components.statusInstanceId);
38416
+ if (statusInstanceId) ids.add(statusInstanceId);
38417
+ const machineId = readNonEmptyString2(loadConfig2().machineId);
38418
+ if (machineId) ids.add(machineId);
38419
+ return [...ids];
38420
+ }
38307
38421
  function findLiveCoordinators(components) {
38308
38422
  const out = [];
38309
38423
  for (const inst of components.instanceManager.getByCategory("cli")) {
@@ -38336,6 +38450,7 @@ Next step: ${nextStep}`;
38336
38450
  else byMesh.set(c.meshId, [c]);
38337
38451
  }
38338
38452
  const localDaemonId = readNonEmptyString2(loadConfig2().machineId) || void 0;
38453
+ const drainDaemonIds = resolveCoordinatorDaemonIds(components);
38339
38454
  const dispatchMeshCommand = components.dispatchMeshCommand;
38340
38455
  const store = (() => {
38341
38456
  try {
@@ -38353,7 +38468,9 @@ Next step: ${nextStep}`;
38353
38468
  }
38354
38469
  }
38355
38470
  const idleCoordinators = meshCoordinators.filter((c) => c.idle);
38356
- if (idleCoordinators.length === 0) continue;
38471
+ const generatingCoordinators = meshCoordinators.filter((c) => !c.idle);
38472
+ const targetCoordinators = idleCoordinators.length > 0 ? idleCoordinators : generatingCoordinators;
38473
+ const forceOnly = idleCoordinators.length === 0;
38357
38474
  if (store) {
38358
38475
  try {
38359
38476
  if (store.pendingEventCount(meshId) === 0) continue;
@@ -38362,15 +38479,20 @@ Next step: ${nextStep}`;
38362
38479
  }
38363
38480
  let pendingEvents = [];
38364
38481
  try {
38365
- pendingEvents = drainPendingMeshCoordinatorEvents(meshId, localDaemonId);
38482
+ pendingEvents = drainPendingMeshCoordinatorEvents(
38483
+ meshId,
38484
+ drainDaemonIds.length > 0 ? drainDaemonIds : localDaemonId,
38485
+ forceOnly ? { onlyEvents: MESH_FORCE_INJECT_EVENTS } : void 0
38486
+ );
38366
38487
  } catch (e) {
38367
38488
  LOG2.warn("MeshReconcile", `Drain failed for mesh ${meshId}: ${e?.message || e}`);
38368
38489
  continue;
38369
38490
  }
38370
38491
  if (pendingEvents.length === 0) continue;
38371
- LOG2.info("MeshReconcile", `Reconcile inject: ${pendingEvents.length} pending event(s) \u2192 ${idleCoordinators.length} idle coordinator(s) for mesh ${meshId}`);
38492
+ const mode = forceOnly ? "force-drain \u2192 generating" : "inject \u2192 idle";
38493
+ LOG2.info("MeshReconcile", `Reconcile ${mode}: ${pendingEvents.length} pending event(s) \u2192 ${targetCoordinators.length} coordinator(s) for mesh ${meshId}`);
38372
38494
  for (const pending of pendingEvents) {
38373
- for (const c of idleCoordinators) {
38495
+ for (const c of targetCoordinators) {
38374
38496
  injectPendingIntoCoordinator(c.instance, pending);
38375
38497
  }
38376
38498
  }
@@ -85175,7 +85297,8 @@ data: ${JSON.stringify(msg.data)}
85175
85297
  detectedIdes: detectedIdesRef,
85176
85298
  refreshProviderAvailability,
85177
85299
  dispatchMeshCommand: config2.dispatchMeshCommand,
85178
- onMeshCoordinatorEventForwarded: config2.onMeshCoordinatorEventForwarded
85300
+ onMeshCoordinatorEventForwarded: config2.onMeshCoordinatorEventForwarded,
85301
+ statusInstanceId: config2.statusInstanceId
85179
85302
  };
85180
85303
  setupMeshEventForwarding(components);
85181
85304
  components.meshReconcileLoop = setupMeshReconcileLoop(components);