@adhdev/daemon-standalone 0.9.82-rc.273 → 0.9.82-rc.274

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 ? "e4a64afbd050fa5167c383b1fc6f9df5f8e48ba2" : void 0) ?? "unknown";
29987
- const commitShort = readInjected(true ? "e4a64afb" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
29988
- const version2 = readInjected(true ? "0.9.82-rc.273" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
29989
- const builtAt = readInjected(true ? "2026-06-15T05:37:35.385Z" : void 0);
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);
29990
29990
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
29991
29991
  return cached2;
29992
29992
  }
@@ -35927,16 +35927,6 @@ ${rendered}`, "utf-8");
35927
35927
  function readRecord3(value) {
35928
35928
  return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
35929
35929
  }
35930
- function canonicalDaemonId(value) {
35931
- const id = readNonEmptyString2(value);
35932
- if (!id) return "";
35933
- return id.replace(/^(?:daemon|standalone)_/, "");
35934
- }
35935
- function sameDaemonId(a, b) {
35936
- const ca = canonicalDaemonId(a);
35937
- const cb = canonicalDaemonId(b);
35938
- return ca !== "" && ca === cb;
35939
- }
35940
35930
  function buildMeshWorkerRelayStamp(currentSettings, meshContext) {
35941
35931
  if (!meshContext) return void 0;
35942
35932
  const settings = currentSettings && typeof currentSettings === "object" ? currentSettings : {};
@@ -36135,29 +36125,6 @@ Next step: ${nextStep}`;
36135
36125
  timestamp || ""
36136
36126
  ].join("::");
36137
36127
  }
36138
- function markMeshCoordinatorEventDirectDelivered(coordinatorDaemonId, event) {
36139
- const canonical = canonicalDaemonId(coordinatorDaemonId);
36140
- if (!canonical) return;
36141
- const fingerprint = buildPendingEventFingerprint(event);
36142
- if (!fingerprint.trim()) return;
36143
- try {
36144
- const store = MeshRuntimeStore.getInstance();
36145
- store.recordDirectDelivered(canonical, fingerprint, DIRECT_DELIVERED_TTL_MS);
36146
- store.sweepExpiredDirectDelivered();
36147
- } catch {
36148
- }
36149
- }
36150
- function wasDirectDeliveredToCoordinator(coordinatorDaemonId, event) {
36151
- const canonical = canonicalDaemonId(coordinatorDaemonId);
36152
- if (!canonical) return false;
36153
- const fingerprint = buildPendingEventFingerprint(event);
36154
- if (!fingerprint.trim()) return false;
36155
- try {
36156
- return MeshRuntimeStore.getInstance().wasDirectDelivered(canonical, fingerprint);
36157
- } catch {
36158
- return false;
36159
- }
36160
- }
36161
36128
  function hasPendingCoordinatorEventDuplicate(event) {
36162
36129
  const fingerprint = buildPendingEventFingerprint(event);
36163
36130
  if (!fingerprint.trim()) return false;
@@ -36356,9 +36323,7 @@ Next step: ${nextStep}`;
36356
36323
  for (const event of filtered) pushUnique(event);
36357
36324
  }
36358
36325
  if (merged.length === 0) return [];
36359
- const deliverable = coordinatorDaemonId ? merged.filter((event) => !wasDirectDeliveredToCoordinator(coordinatorDaemonId, event)) : merged;
36360
- if (deliverable.length === 0) return [];
36361
- return reconcilePendingMeshCoordinatorEvents(meshId, deliverable);
36326
+ return reconcilePendingMeshCoordinatorEvents(meshId, merged);
36362
36327
  }
36363
36328
  function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
36364
36329
  if (!meshId) return [];
@@ -36385,8 +36350,7 @@ Next step: ${nextStep}`;
36385
36350
  for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId)) {
36386
36351
  pushUnique(event);
36387
36352
  }
36388
- const deliverable = coordinatorDaemonId ? merged.filter((event) => !wasDirectDeliveredToCoordinator(coordinatorDaemonId, event)) : merged;
36389
- return reconcilePendingMeshCoordinatorEvents(meshId, deliverable);
36353
+ return reconcilePendingMeshCoordinatorEvents(meshId, merged);
36390
36354
  }
36391
36355
  function clearPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
36392
36356
  if (!meshId) return;
@@ -36406,7 +36370,6 @@ Next step: ${nextStep}`;
36406
36370
  var import_path8;
36407
36371
  var import_crypto7;
36408
36372
  var REFINE_TERMINAL_EVENTS;
36409
- var DIRECT_DELIVERED_TTL_MS;
36410
36373
  var MAX_PENDING_EVENTS_BYTES;
36411
36374
  var MAX_PENDING_EVENTS_KEEP;
36412
36375
  var init_mesh_events_pending = __esm2({
@@ -36420,7 +36383,6 @@ Next step: ${nextStep}`;
36420
36383
  init_mesh_runtime_store();
36421
36384
  init_mesh_events_utils();
36422
36385
  REFINE_TERMINAL_EVENTS = /* @__PURE__ */ new Set(["refine:completed", "refine:failed"]);
36423
- DIRECT_DELIVERED_TTL_MS = 10 * 60 * 1e3;
36424
36386
  MAX_PENDING_EVENTS_BYTES = 100 * 1024;
36425
36387
  MAX_PENDING_EVENTS_KEEP = 50;
36426
36388
  }
@@ -37780,7 +37742,6 @@ Next step: ${nextStep}`;
37780
37742
  const workerCoordinatorDaemonId = readNonEmptyString2(
37781
37743
  sourceSession?.getState()?.settings?.meshCoordinatorDaemonId
37782
37744
  );
37783
- const localDaemonId = readNonEmptyString2(loadConfig2().machineId);
37784
37745
  if (components.onMeshCoordinatorEventForwarded) {
37785
37746
  try {
37786
37747
  components.onMeshCoordinatorEventForwarded({
@@ -38135,60 +38096,6 @@ Next step: ${nextStep}`;
38135
38096
  recoveryContext
38136
38097
  });
38137
38098
  if (!messageText) return { success: false, error: "unsupported mesh event" };
38138
- const coordinatorInstances = components.instanceManager.getByCategory("cli").filter((inst) => {
38139
- const instState = inst.getState();
38140
- if (instState.settings?.meshCoordinatorFor !== args.meshId) return false;
38141
- if (args.sourceInstanceId && instState.instanceId === args.sourceInstanceId) return false;
38142
- if (workerCoordinatorDaemonId && localDaemonId && !sameDaemonId(workerCoordinatorDaemonId, localDaemonId)) return false;
38143
- return true;
38144
- });
38145
- if (coordinatorInstances.length === 0) {
38146
- const remoteCoordinatorDaemonId = workerCoordinatorDaemonId && localDaemonId && !sameDaemonId(workerCoordinatorDaemonId, localDaemonId) ? workerCoordinatorDaemonId : "";
38147
- if (remoteCoordinatorDaemonId && components.dispatchMeshCommand) {
38148
- const forwardPayload = {
38149
- event: args.event,
38150
- meshId: args.meshId,
38151
- nodeId: args.nodeId || void 0,
38152
- workspace: readNonEmptyString2(args.metadataEvent.workspace),
38153
- ...args.metadataEvent,
38154
- ...recoveryContext ? { recoveryContext } : {}
38155
- };
38156
- components.dispatchMeshCommand(remoteCoordinatorDaemonId, "mesh_forward_event", forwardPayload).then(() => {
38157
- LOG2.info("MeshEvents", `Forwarded ${args.event} for mesh ${args.meshId} to remote coordinator daemon ${remoteCoordinatorDaemonId.slice(0, 12)}\u2026`);
38158
- }).catch((error48) => {
38159
- LOG2.warn("MeshEvents", `Remote forward of ${args.event} failed (${error48?.message || error48}); queuing for backfill`);
38160
- queuePendingMeshCoordinatorEvent({
38161
- event: args.event,
38162
- meshId: args.meshId,
38163
- nodeLabel: args.nodeLabel,
38164
- nodeId: args.nodeId || void 0,
38165
- workspace: readNonEmptyString2(args.metadataEvent.workspace),
38166
- metadataEvent: { ...args.metadataEvent, ...recoveryContext ? { recoveryContext } : {} },
38167
- coordinatorMessage: messageText,
38168
- queuedAt: Date.now(),
38169
- targetCoordinatorDaemonId: remoteCoordinatorDaemonId
38170
- });
38171
- });
38172
- return { success: true, forwarded: 0, remoteForwarded: true };
38173
- }
38174
- if (queuePendingMeshCoordinatorEvent({
38175
- event: args.event,
38176
- meshId: args.meshId,
38177
- nodeLabel: args.nodeLabel,
38178
- nodeId: args.nodeId || void 0,
38179
- workspace: readNonEmptyString2(args.metadataEvent.workspace),
38180
- metadataEvent: {
38181
- ...args.metadataEvent,
38182
- ...recoveryContext ? { recoveryContext } : {}
38183
- },
38184
- coordinatorMessage: messageText,
38185
- queuedAt: Date.now(),
38186
- ...workerCoordinatorDaemonId ? { targetCoordinatorDaemonId: workerCoordinatorDaemonId } : {}
38187
- })) {
38188
- LOG2.info("MeshEvents", `Queued ${args.event} for MCP coordinator (mesh ${args.meshId}${workerCoordinatorDaemonId ? `, coordinator daemon ${workerCoordinatorDaemonId}` : ""})`);
38189
- }
38190
- return { success: true, forwarded: 0 };
38191
- }
38192
38099
  const pendingEvent = {
38193
38100
  event: args.event,
38194
38101
  meshId: args.meshId,
@@ -38204,21 +38111,9 @@ Next step: ${nextStep}`;
38204
38111
  ...workerCoordinatorDaemonId ? { targetCoordinatorDaemonId: workerCoordinatorDaemonId } : {}
38205
38112
  };
38206
38113
  if (queuePendingMeshCoordinatorEvent(pendingEvent)) {
38207
- LOG2.info("MeshEvents", `Queued ${args.event} for MCP coordinator (mesh ${args.meshId})`);
38208
- }
38209
- if (localDaemonId) {
38210
- markMeshCoordinatorEventDirectDelivered(localDaemonId, pendingEvent);
38211
- }
38212
- const forceInject = shouldForceInjectMeshEvent(args.event);
38213
- for (const coord of coordinatorInstances) {
38214
- const coordState = coord.getState();
38215
- LOG2.info("MeshEvents", `Forwarding mesh event to coordinator ${coordState.instanceId}${forceInject ? " (force)" : ""}`);
38216
- coord.onEvent("send_message", {
38217
- input: { text: messageText, textFallback: messageText },
38218
- ...forceInject ? { force: true } : {}
38219
- });
38114
+ LOG2.info("MeshEvents", `Queued ${args.event} for coordinator (mesh ${args.meshId}${workerCoordinatorDaemonId ? `, coordinator daemon ${workerCoordinatorDaemonId}` : ""})`);
38220
38115
  }
38221
- return { success: true, forwarded: coordinatorInstances.length };
38116
+ return { success: true, forwarded: 0 };
38222
38117
  }
38223
38118
  function handleMeshForwardEvent(components, payload) {
38224
38119
  const eventName = readNonEmptyString2(payload.event);
@@ -38401,6 +38296,167 @@ Next step: ${nextStep}`;
38401
38296
  ]);
38402
38297
  }
38403
38298
  });
38299
+ function resolveReconcileIntervalMs() {
38300
+ const raw = readNonEmptyString2(process.env.MESH_RECONCILE_INTERVAL_MS);
38301
+ if (raw) {
38302
+ const parsed = Number.parseInt(raw, 10);
38303
+ if (Number.isFinite(parsed) && parsed >= 1e3 && parsed <= 6e4) return parsed;
38304
+ }
38305
+ return DEFAULT_RECONCILE_INTERVAL_MS;
38306
+ }
38307
+ function findLiveCoordinators(components) {
38308
+ const out = [];
38309
+ for (const inst of components.instanceManager.getByCategory("cli")) {
38310
+ const state = inst.getState();
38311
+ const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
38312
+ const meshId = readNonEmptyString2(settings.meshCoordinatorFor);
38313
+ if (!meshId) continue;
38314
+ const status = readNonEmptyString2(state.status).toLowerCase();
38315
+ out.push({ meshId, instance: inst, idle: status === "idle" });
38316
+ }
38317
+ return out;
38318
+ }
38319
+ function injectPendingIntoCoordinator(coordinator, pending) {
38320
+ if (!coordinator || !pending.coordinatorMessage) return;
38321
+ const force = shouldForceInjectMeshEvent(pending.event);
38322
+ coordinator.onEvent("send_message", {
38323
+ input: { text: pending.coordinatorMessage, textFallback: pending.coordinatorMessage },
38324
+ ...force ? { force: true } : {}
38325
+ });
38326
+ }
38327
+ async function runMeshReconcileTick(components) {
38328
+ const coordinators = findLiveCoordinators(components);
38329
+ if (coordinators.length === 0) {
38330
+ return;
38331
+ }
38332
+ const byMesh = /* @__PURE__ */ new Map();
38333
+ for (const c of coordinators) {
38334
+ const list = byMesh.get(c.meshId);
38335
+ if (list) list.push(c);
38336
+ else byMesh.set(c.meshId, [c]);
38337
+ }
38338
+ const localDaemonId = readNonEmptyString2(loadConfig2().machineId) || void 0;
38339
+ const dispatchMeshCommand = components.dispatchMeshCommand;
38340
+ const store = (() => {
38341
+ try {
38342
+ return MeshRuntimeStore.getInstance();
38343
+ } catch {
38344
+ return void 0;
38345
+ }
38346
+ })();
38347
+ for (const [meshId, meshCoordinators] of byMesh) {
38348
+ if (dispatchMeshCommand) {
38349
+ try {
38350
+ await pullRemoteNodeQueues(components, meshId, localDaemonId);
38351
+ } catch (e) {
38352
+ LOG2.warn("MeshReconcile", `Remote node pull failed for mesh ${meshId}: ${e?.message || e}`);
38353
+ }
38354
+ }
38355
+ const idleCoordinators = meshCoordinators.filter((c) => c.idle);
38356
+ if (idleCoordinators.length === 0) continue;
38357
+ if (store) {
38358
+ try {
38359
+ if (store.pendingEventCount(meshId) === 0) continue;
38360
+ } catch {
38361
+ }
38362
+ }
38363
+ let pendingEvents = [];
38364
+ try {
38365
+ pendingEvents = drainPendingMeshCoordinatorEvents(meshId, localDaemonId);
38366
+ } catch (e) {
38367
+ LOG2.warn("MeshReconcile", `Drain failed for mesh ${meshId}: ${e?.message || e}`);
38368
+ continue;
38369
+ }
38370
+ 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}`);
38372
+ for (const pending of pendingEvents) {
38373
+ for (const c of idleCoordinators) {
38374
+ injectPendingIntoCoordinator(c.instance, pending);
38375
+ }
38376
+ }
38377
+ }
38378
+ }
38379
+ async function pullRemoteNodeQueues(components, meshId, localDaemonId) {
38380
+ const dispatchMeshCommand = components.dispatchMeshCommand;
38381
+ if (!dispatchMeshCommand) return;
38382
+ const mesh = listMeshes().find((m) => m.id === meshId);
38383
+ if (!mesh) return;
38384
+ const pendingEventArgs = {
38385
+ meshId,
38386
+ ...localDaemonId ? { coordinatorDaemonId: localDaemonId } : {}
38387
+ };
38388
+ for (const node of mesh.nodes) {
38389
+ const nodeDaemonId = readNonEmptyString2(node.daemonId);
38390
+ if (!nodeDaemonId) continue;
38391
+ if (localDaemonId && nodeDaemonId === localDaemonId) continue;
38392
+ let events;
38393
+ try {
38394
+ events = await dispatchMeshCommand(nodeDaemonId, "get_pending_mesh_events", pendingEventArgs);
38395
+ } catch {
38396
+ continue;
38397
+ }
38398
+ const list = extractPendingEvents(events).filter((e) => readNonEmptyString2(e?.meshId) === meshId);
38399
+ for (const event of list) {
38400
+ const payload = buildForwardPayloadFromPending(event);
38401
+ if (!payload.event || !payload.meshId) continue;
38402
+ try {
38403
+ handleMeshForwardEvent(components, payload);
38404
+ } catch {
38405
+ }
38406
+ }
38407
+ }
38408
+ }
38409
+ function extractPendingEvents(raw) {
38410
+ if (Array.isArray(raw)) return raw;
38411
+ if (raw && typeof raw === "object") {
38412
+ const events = raw.events;
38413
+ if (Array.isArray(events)) return events;
38414
+ }
38415
+ return [];
38416
+ }
38417
+ function buildForwardPayloadFromPending(event) {
38418
+ const metadata = event?.metadataEvent && typeof event.metadataEvent === "object" ? event.metadataEvent : {};
38419
+ return {
38420
+ event: readNonEmptyString2(event?.event),
38421
+ meshId: readNonEmptyString2(event?.meshId),
38422
+ nodeId: readNonEmptyString2(event?.nodeId) || readNonEmptyString2(metadata.meshNodeId),
38423
+ workspace: readNonEmptyString2(event?.workspace) || readNonEmptyString2(metadata.workspace),
38424
+ ...metadata
38425
+ };
38426
+ }
38427
+ function setupMeshReconcileLoop(components) {
38428
+ const intervalMs = resolveReconcileIntervalMs();
38429
+ let running = false;
38430
+ const timer = setInterval(() => {
38431
+ if (running) return;
38432
+ running = true;
38433
+ void runMeshReconcileTick(components).catch((e) => LOG2.warn("MeshReconcile", `Reconcile tick error: ${e?.message || e}`)).finally(() => {
38434
+ running = false;
38435
+ });
38436
+ }, intervalMs);
38437
+ if (typeof timer.unref === "function") timer.unref();
38438
+ LOG2.info("MeshReconcile", `Mesh reconcile loop started (interval ${intervalMs}ms)`);
38439
+ return {
38440
+ stop() {
38441
+ clearInterval(timer);
38442
+ LOG2.info("MeshReconcile", "Mesh reconcile loop stopped");
38443
+ }
38444
+ };
38445
+ }
38446
+ var DEFAULT_RECONCILE_INTERVAL_MS;
38447
+ var init_mesh_reconcile_loop = __esm2({
38448
+ "src/mesh/mesh-reconcile-loop.ts"() {
38449
+ "use strict";
38450
+ init_config();
38451
+ init_mesh_config();
38452
+ init_logger();
38453
+ init_mesh_events_pending();
38454
+ init_mesh_runtime_store();
38455
+ init_mesh_events_coordinator();
38456
+ init_mesh_events_utils();
38457
+ DEFAULT_RECONCILE_INTERVAL_MS = 4e3;
38458
+ }
38459
+ });
38404
38460
  var mesh_events_exports = {};
38405
38461
  __export2(mesh_events_exports, {
38406
38462
  __resetIdleAutoFastForwardForTests: () => __resetIdleAutoFastForwardForTests,
@@ -38410,10 +38466,11 @@ Next step: ${nextStep}`;
38410
38466
  getPendingMeshCoordinatorEvents: () => getPendingMeshCoordinatorEvents,
38411
38467
  handleMeshForwardEvent: () => handleMeshForwardEvent,
38412
38468
  isMeshCoordinatorEvent: () => isMeshCoordinatorEvent,
38413
- markMeshCoordinatorEventDirectDelivered: () => markMeshCoordinatorEventDirectDelivered,
38414
38469
  queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
38415
38470
  reconcileDirectDispatchCompletionFromTranscript: () => reconcileDirectDispatchCompletionFromTranscript,
38471
+ runMeshReconcileTick: () => runMeshReconcileTick,
38416
38472
  setupMeshEventForwarding: () => setupMeshEventForwarding,
38473
+ setupMeshReconcileLoop: () => setupMeshReconcileLoop,
38417
38474
  triggerMeshQueue: () => triggerMeshQueue,
38418
38475
  tryAssignQueueTask: () => tryAssignQueueTask
38419
38476
  });
@@ -38422,6 +38479,7 @@ Next step: ${nextStep}`;
38422
38479
  "use strict";
38423
38480
  init_mesh_events_pending();
38424
38481
  init_mesh_events_stale();
38482
+ init_mesh_reconcile_loop();
38425
38483
  init_mesh_events_coordinator();
38426
38484
  }
38427
38485
  });
@@ -84922,6 +84980,7 @@ data: ${JSON.stringify(msg.data)}
84922
84980
  init_logger();
84923
84981
  init_config();
84924
84982
  init_mesh_events();
84983
+ init_mesh_reconcile_loop();
84925
84984
  var _hardened = false;
84926
84985
  var HARDENED_PROTOS = [
84927
84986
  { name: "Object", proto: Object.prototype },
@@ -85119,6 +85178,7 @@ data: ${JSON.stringify(msg.data)}
85119
85178
  onMeshCoordinatorEventForwarded: config2.onMeshCoordinatorEventForwarded
85120
85179
  };
85121
85180
  setupMeshEventForwarding(components);
85181
+ components.meshReconcileLoop = setupMeshReconcileLoop(components);
85122
85182
  setImmediate(() => void router.resumePendingRefineJobsOnStartup());
85123
85183
  return components;
85124
85184
  }
@@ -85144,10 +85204,15 @@ data: ${JSON.stringify(msg.data)}
85144
85204
  agentStreamManager,
85145
85205
  cliManager,
85146
85206
  instanceManager,
85147
- cdpManagers
85207
+ cdpManagers,
85208
+ meshReconcileLoop
85148
85209
  } = components;
85149
85210
  poller.stop();
85150
85211
  cdpInitializer.stop();
85212
+ try {
85213
+ meshReconcileLoop?.stop();
85214
+ } catch {
85215
+ }
85151
85216
  try {
85152
85217
  if (agentStreamManager) {
85153
85218
  await agentStreamManager.dispose(cdpManagers);