@adhdev/daemon-core 0.9.82-rc.350 → 0.9.82-rc.351

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.mjs CHANGED
@@ -311,10 +311,10 @@ function readInjected(value) {
311
311
  }
312
312
  function getDaemonBuildInfo() {
313
313
  if (cached) return cached;
314
- const commit = readInjected(true ? "f066449c7e758daf63ad40d431a5e97fc8d79a0e" : void 0) ?? "unknown";
315
- const commitShort = readInjected(true ? "f066449c" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
- const version = readInjected(true ? "0.9.82-rc.350" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
- const builtAt = readInjected(true ? "2026-06-21T19:33:17.868Z" : void 0);
314
+ const commit = readInjected(true ? "dad22ef2758130d10a3d55e3c419f0095d5e44b7" : void 0) ?? "unknown";
315
+ const commitShort = readInjected(true ? "dad22ef2" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
+ const version = readInjected(true ? "0.9.82-rc.351" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
+ const builtAt = readInjected(true ? "2026-06-22T04:04:59.936Z" : void 0);
318
318
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
319
319
  return cached;
320
320
  }
@@ -4670,6 +4670,10 @@ var init_mesh_runtime_store = __esm({
4670
4670
  migratedMeshIds = /* @__PURE__ */ new Set();
4671
4671
  fingerprintSweepCounter = 0;
4672
4672
  walWriteCounter = 0;
4673
+ // Independent cadence for the tool-call-log sweep. Must NOT share walWriteCounter:
4674
+ // sharing makes each store's threshold drift by the other's write volume (WAL
4675
+ // checkpoint at 500 vs tool-log sweep at 200 would interfere arbitrarily).
4676
+ toolCallLogCounter = 0;
4673
4677
  static WAL_CHECK_INTERVAL = 500;
4674
4678
  static WAL_MAX_BYTES = 50 * 1024 * 1024;
4675
4679
  // 50 MB
@@ -5563,7 +5567,7 @@ var init_mesh_runtime_store = __esm({
5563
5567
  "SELECT COUNT(*) as cnt FROM mesh_tool_call_log WHERE mesh_id = ? AND tool = ? AND called_at >= ?"
5564
5568
  ).get(meshId, tool, windowStart);
5565
5569
  const callsInWindow = row?.cnt ?? 0;
5566
- if (++this.walWriteCounter % 200 === 0) {
5570
+ if (++this.toolCallLogCounter % 200 === 0) {
5567
5571
  this.db.prepare(
5568
5572
  "DELETE FROM mesh_tool_call_log WHERE called_at < ?"
5569
5573
  ).run(now - Math.max(windowMs * 10, 6e4));
@@ -6018,9 +6022,9 @@ function computeMeshTaskStats(meshId, opts) {
6018
6022
  }
6019
6023
  return targetIds.map((taskId) => {
6020
6024
  const queueEntry = queueById.get(taskId);
6021
- const status = queueEntry?.status ?? "unknown";
6022
6025
  const dispatch = dispatches.get(taskId);
6023
6026
  const terminal = terminals.get(taskId);
6027
+ const status = queueEntry?.status ?? (terminal ? terminal.kind === "task_completed" ? "completed" : "failed" : "unknown");
6024
6028
  const isTerminalStatus = status === "completed" || status === "failed" || status === "cancelled";
6025
6029
  const dispatchTime = parseTime(dispatch?.first ?? queueEntry?.dispatchTimestamp);
6026
6030
  const terminalTime = parseTime(terminal?.at);
@@ -8029,6 +8033,14 @@ function statusFromTerminal(entry) {
8029
8033
  if (entry.kind === "task_completed") return "idle";
8030
8034
  return "failed";
8031
8035
  }
8036
+ function classifyDirectDispatch(params) {
8037
+ const { status, isTerminalRow, hasTerminalStatus, liveStatus, liveStaleReason, dispatchedToIdleSession } = params;
8038
+ const isNoTransition = !hasTerminalStatus && !liveStatus;
8039
+ const isIdleUnacknowledged = status === "idle";
8040
+ const ledgerOnlyStaleReason = !isTerminalRow && (isIdleUnacknowledged || isNoTransition || dispatchedToIdleSession && isIdleUnacknowledged) ? LEDGER_ONLY_STALE_REASON : void 0;
8041
+ const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !liveStaleReason);
8042
+ return { ledgerOnlyStaleReason, isFreshUnacknowledged };
8043
+ }
8032
8044
  function buildMeshActiveWorkSummary(activeWork) {
8033
8045
  const statusCounts = {
8034
8046
  pending: 0,
@@ -8091,10 +8103,14 @@ function buildMeshActiveWork(opts) {
8091
8103
  const dbStatus = dispatch.status;
8092
8104
  const isTerminal = dbStatus === "completed" || dbStatus === "failed" || dbStatus === "stale";
8093
8105
  const status = isTerminal ? dbStatus === "completed" ? "idle" : "failed" : live.status || (dbStatus === "acked" ? "generating" : "assigned");
8094
- const isNoTransition = !isTerminal && !live.status;
8095
- const isIdleUnacknowledged = status === "idle" && !isTerminal;
8096
- const ledgerOnlyStaleReason = !isTerminal && (isIdleUnacknowledged || isNoTransition || dispatch.dispatchedToIdleSession && isIdleUnacknowledged) ? "direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition" : void 0;
8097
- const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !live.staleReason);
8106
+ const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
8107
+ status,
8108
+ isTerminalRow: isTerminal,
8109
+ hasTerminalStatus: isTerminal,
8110
+ liveStatus: live.status,
8111
+ liveStaleReason: live.staleReason,
8112
+ dispatchedToIdleSession: dispatch.dispatchedToIdleSession === true
8113
+ });
8098
8114
  const { title, summary: summary2 } = summarizeMessage(dispatch.message || "");
8099
8115
  const record = {
8100
8116
  taskId: dispatch.taskId,
@@ -8137,13 +8153,16 @@ function buildMeshActiveWork(opts) {
8137
8153
  const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
8138
8154
  const status = terminalStatus || live.status || "assigned";
8139
8155
  const terminalRow = Boolean(terminal && terminal.kind !== "task_approval_needed");
8140
- const dispatchedToIdleSession = dispatch.payload?.dispatchedToIdleSession === true;
8141
- const isNoTransition = !terminalStatus && !live.status;
8142
- const isIdleUnacknowledged = status === "idle";
8143
- const ledgerOnlyStaleReason = !terminalRow && (isIdleUnacknowledged || isNoTransition || dispatchedToIdleSession && isIdleUnacknowledged) ? "direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition" : void 0;
8156
+ const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
8157
+ status,
8158
+ isTerminalRow: terminalRow,
8159
+ hasTerminalStatus: Boolean(terminalStatus),
8160
+ liveStatus: live.status,
8161
+ liveStaleReason: live.staleReason,
8162
+ dispatchedToIdleSession: dispatch.payload?.dispatchedToIdleSession === true
8163
+ });
8144
8164
  const message = readString6(dispatch.payload?.message) || readString6(dispatch.payload?.summary) || "";
8145
8165
  const { title, summary: summary2 } = summarizeMessage(message);
8146
- const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !live.staleReason);
8147
8166
  const record = {
8148
8167
  taskId,
8149
8168
  source: "direct",
@@ -8185,13 +8204,16 @@ function buildMeshActiveWork(opts) {
8185
8204
  const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
8186
8205
  const status = terminalStatus || live.status || "assigned";
8187
8206
  const terminalRow = Boolean(terminal && terminal.kind !== "task_approval_needed");
8188
- const dispatchedToIdleSession = dispatch.payload?.dispatchedToIdleSession === true;
8189
- const isNoTransition = !terminalStatus && !live.status;
8190
- const isIdleUnacknowledged = status === "idle";
8191
- const ledgerOnlyStaleReason = !terminalRow && (isIdleUnacknowledged || isNoTransition || dispatchedToIdleSession && isIdleUnacknowledged) ? "direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition" : void 0;
8207
+ const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
8208
+ status,
8209
+ isTerminalRow: terminalRow,
8210
+ hasTerminalStatus: Boolean(terminalStatus),
8211
+ liveStatus: live.status,
8212
+ liveStaleReason: live.staleReason,
8213
+ dispatchedToIdleSession: dispatch.payload?.dispatchedToIdleSession === true
8214
+ });
8192
8215
  const message = readString6(dispatch.payload?.message) || readString6(dispatch.payload?.summary) || "";
8193
8216
  const { title, summary: summary2 } = summarizeMessage(message);
8194
- const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !live.staleReason);
8195
8217
  const record = {
8196
8218
  taskId,
8197
8219
  source: "direct",
@@ -8342,7 +8364,7 @@ function buildCompactStaleDirectWorkSummary(staleDirectWork, opts = {}) {
8342
8364
  ...opts.note ? { note: opts.note } : {}
8343
8365
  };
8344
8366
  }
8345
- var DIRECT_DISPATCH_VIA, TERMINAL_LEDGER_KINDS, PRUNABLE_ORPHAN_STALE_REASONS;
8367
+ var DIRECT_DISPATCH_VIA, TERMINAL_LEDGER_KINDS, LEDGER_ONLY_STALE_REASON, PRUNABLE_ORPHAN_STALE_REASONS;
8346
8368
  var init_mesh_active_work = __esm({
8347
8369
  "src/mesh/mesh-active-work.ts"() {
8348
8370
  "use strict";
@@ -8351,6 +8373,7 @@ var init_mesh_active_work = __esm({
8351
8373
  init_dist();
8352
8374
  DIRECT_DISPATCH_VIA = /* @__PURE__ */ new Set(["p2p_direct", "local_direct", "mesh_send_task"]);
8353
8375
  TERMINAL_LEDGER_KINDS = /* @__PURE__ */ new Set(["task_completed", "task_failed", "task_stalled"]);
8376
+ LEDGER_ONLY_STALE_REASON = "direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition";
8354
8377
  PRUNABLE_ORPHAN_STALE_REASONS = /* @__PURE__ */ new Set([
8355
8378
  "direct task node is no longer in the live mesh",
8356
8379
  "direct task session is not present in live session records",
@@ -8790,6 +8813,7 @@ function queuePendingMeshCoordinatorEvent(event) {
8790
8813
  return true;
8791
8814
  }
8792
8815
  const fingerprint = buildPendingEventFingerprint(event);
8816
+ let sqliteOk = false;
8793
8817
  try {
8794
8818
  MeshRuntimeStore.getInstance().insertPendingEvent({
8795
8819
  id: randomUUID7(),
@@ -8800,11 +8824,17 @@ function queuePendingMeshCoordinatorEvent(event) {
8800
8824
  fingerprint: fingerprint || null,
8801
8825
  queuedAt: event.queuedAt
8802
8826
  });
8827
+ sqliteOk = true;
8803
8828
  } catch {
8804
8829
  }
8805
- const path42 = getPendingEventsPath(event.meshId, event.targetCoordinatorDaemonId);
8806
- trimPendingEventsIfNeeded(path42);
8807
- appendFileSync2(path42, JSON.stringify(event) + "\n", "utf-8");
8830
+ try {
8831
+ const path42 = getPendingEventsPath(event.meshId, event.targetCoordinatorDaemonId);
8832
+ trimPendingEventsIfNeeded(path42);
8833
+ appendFileSync2(path42, JSON.stringify(event) + "\n", "utf-8");
8834
+ } catch (e) {
8835
+ if (!sqliteOk) throw e;
8836
+ LOG.warn("MeshEvents", `JSONL append failed for mesh ${event.meshId}; SQLite holds the event: ${e?.message || e}`);
8837
+ }
8808
8838
  return true;
8809
8839
  } catch (e) {
8810
8840
  LOG.warn("MeshEvents", `Failed to persist pending coordinator event: ${e?.message || e}`);
@@ -9200,6 +9230,12 @@ function hasUnterminalDirectDispatchLedgerEntry(meshId, sessionId) {
9200
9230
  }
9201
9231
  return false;
9202
9232
  }
9233
+ function isWeakCompletionLedgerPayload(payload) {
9234
+ if (!payload) return false;
9235
+ if (payload.evidenceLevel === "insufficient" || payload.reviewRecommended === true) return true;
9236
+ const diag = readRecord4(payload.completionDiagnostic);
9237
+ return diag?.finalAssistantPresent === false || diag?.blockReason === "missing_final_assistant";
9238
+ }
9203
9239
  function findDirectDispatchLedgerEntry(args) {
9204
9240
  const entries = readLedgerEntries(args.meshId, { tail: 500 });
9205
9241
  for (let i = entries.length - 1; i >= 0; i--) {
@@ -9236,6 +9272,7 @@ function hasTerminalLedgerAfterDispatch(args) {
9236
9272
  if (!afterDispatch) continue;
9237
9273
  }
9238
9274
  if (entry.kind !== "task_completed" && entry.kind !== "task_failed" && entry.kind !== "task_stalled") continue;
9275
+ if (entry.kind === "task_completed" && isWeakCompletionLedgerPayload(entry.payload)) continue;
9239
9276
  const terminalTaskId = readNonEmptyString2(entry.payload?.taskId);
9240
9277
  if (terminalTaskId && terminalTaskId === args.taskId) return true;
9241
9278
  if (terminalTaskId && terminalTaskId !== args.taskId) continue;
@@ -12561,6 +12598,30 @@ function isDuplicateRefineTerminalEvent(meshId, eventName, metadataEvent) {
12561
12598
  recordFingerprintSeen(fingerprint);
12562
12599
  return false;
12563
12600
  }
12601
+ function isFalseIdleCompletion(metadataEvent) {
12602
+ const diag = readRecord4(metadataEvent.completionDiagnostic);
12603
+ if (!diag) return false;
12604
+ return diag.finalAssistantPresent === false || diag.blockReason === "missing_final_assistant";
12605
+ }
12606
+ function isGenuineCompletionEvidence(metadataEvent) {
12607
+ if (isFalseIdleCompletion(metadataEvent)) return false;
12608
+ return !!readWorkerResultMetadata(metadataEvent) || !!readNonEmptyString2(metadataEvent.finalSummary);
12609
+ }
12610
+ function isWeakTerminalLedgerPayload(payload) {
12611
+ if (!payload) return false;
12612
+ if (payload.evidenceLevel === "insufficient" || payload.reviewRecommended === true) return true;
12613
+ const diag = readRecord4(payload.completionDiagnostic);
12614
+ return diag?.finalAssistantPresent === false || diag?.blockReason === "missing_final_assistant";
12615
+ }
12616
+ function resolveActiveDirectDispatchTaskId(meshId, sessionId) {
12617
+ try {
12618
+ const matches = getActiveDirectDispatches(meshId).filter((d) => d.sessionId === sessionId);
12619
+ if (!matches.length) return void 0;
12620
+ return readNonEmptyString2(matches[matches.length - 1].taskId) || void 0;
12621
+ } catch {
12622
+ return void 0;
12623
+ }
12624
+ }
12564
12625
  function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
12565
12626
  const mesh = getMeshWithCache(components, meshId);
12566
12627
  const node = mesh?.nodes.find((n) => readMeshNodeId(n) === nodeId);
@@ -13405,7 +13466,8 @@ function injectMeshSystemMessage(components, args) {
13405
13466
  });
13406
13467
  if (terminal?.kind === "task_completed" && !sessionHasActiveAssignment(args.meshId, eventSessionId)) {
13407
13468
  const newDispatchAfterTerminal = hasDispatchAfterTerminal(args.meshId, eventSessionId, terminal.id);
13408
- if (!newDispatchAfterTerminal) {
13469
+ const supersedesWeakTerminal = isWeakTerminalLedgerPayload(terminal.payload) && isGenuineCompletionEvidence(args.metadataEvent);
13470
+ if (!newDispatchAfterTerminal && !supersedesWeakTerminal) {
13409
13471
  const terminalProviderSessionId = readNonEmptyString2(terminal.payload.providerSessionId);
13410
13472
  const terminalFinalSummary = readNonEmptyString2(terminal.payload.finalSummary);
13411
13473
  const eventProviderSessionId = readNonEmptyString2(args.metadataEvent.providerSessionId);
@@ -13451,24 +13513,30 @@ function injectMeshSystemMessage(components, args) {
13451
13513
  return { success: true, forwarded: 0, suppressed: true, duplicateStopped: true };
13452
13514
  }
13453
13515
  }
13454
- function markSessionTerminal(sessionId, outcome, occurredAtMs) {
13516
+ function markSessionTerminal(sessionId, outcome, occurredAtMs, opts) {
13455
13517
  const eventTaskId = readNonEmptyString2(args.metadataEvent.taskId) || void 0;
13456
13518
  const task = updateSessionTaskStatus(args.meshId, sessionId, outcome, {
13457
13519
  occurredAt: occurredAtMs != null ? new Date(occurredAtMs).toISOString() : void 0,
13458
13520
  taskId: eventTaskId
13459
13521
  });
13460
- updateDirectDispatchStatus(args.meshId, sessionId, outcome);
13522
+ const leaveDirectDispatchActive = !task && opts?.tentativeIfDirect === true;
13523
+ if (!leaveDirectDispatchActive) {
13524
+ updateDirectDispatchStatus(args.meshId, sessionId, outcome);
13525
+ }
13461
13526
  markSessionDeliveriesTerminal(args.meshId, sessionId, outcome);
13462
13527
  setImmediate(() => cleanupTerminalDirectDispatches());
13463
13528
  return task ? { id: task.id } : null;
13464
13529
  }
13465
13530
  let completedTaskForLedger = null;
13531
+ let directDispatchTaskIdForLedger;
13466
13532
  if (args.event === "agent:generating_completed") {
13467
13533
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
13468
13534
  const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
13469
13535
  const providerType = readNonEmptyString2(args.metadataEvent.providerType);
13470
13536
  if (sessionId) {
13471
- completedTaskForLedger = markSessionTerminal(sessionId, "completed", eventTimestamp);
13537
+ directDispatchTaskIdForLedger = resolveActiveDirectDispatchTaskId(args.meshId, sessionId);
13538
+ const isFalseIdle = isFalseIdleCompletion(args.metadataEvent);
13539
+ completedTaskForLedger = markSessionTerminal(sessionId, "completed", eventTimestamp, { tentativeIfDirect: isFalseIdle });
13472
13540
  if (nodeId && providerType) {
13473
13541
  runIdleMaintenanceThenAssignQueue(components, { meshId: args.meshId, nodeId, sessionId, providerType });
13474
13542
  }
@@ -13571,6 +13639,7 @@ function injectMeshSystemMessage(components, args) {
13571
13639
  }
13572
13640
  }
13573
13641
  if (sessionId) {
13642
+ directDispatchTaskIdForLedger = resolveActiveDirectDispatchTaskId(args.meshId, sessionId);
13574
13643
  completedTaskForLedger = markSessionTerminal(sessionId, "failed");
13575
13644
  }
13576
13645
  }
@@ -13600,7 +13669,10 @@ function injectMeshSystemMessage(components, args) {
13600
13669
  payload: {
13601
13670
  event: args.event,
13602
13671
  nodeLabel: args.nodeLabel,
13603
- taskId: completedTaskForLedger?.id || void 0,
13672
+ // Fix B: fall back to the direct-dispatch taskId when no work-queue row
13673
+ // matched, so the terminal entry is attributable in mesh task-stats
13674
+ // (otherwise the direct task shows status='unknown' / terminalKind=null).
13675
+ taskId: completedTaskForLedger?.id || directDispatchTaskIdForLedger || void 0,
13604
13676
  providerSessionId,
13605
13677
  finalSummary,
13606
13678
  workerResult,
@@ -21754,6 +21826,7 @@ init_mesh_active_work();
21754
21826
  init_mesh_refine_status();
21755
21827
  init_mesh_host_ownership();
21756
21828
  init_mesh_events();
21829
+ init_mesh_events_utils();
21757
21830
  init_mesh_delivery_policy();
21758
21831
 
21759
21832
  // src/mesh/p2p-relay-failure.ts
@@ -43315,7 +43388,7 @@ function runGit2(repoRoot, args) {
43315
43388
  return "";
43316
43389
  }
43317
43390
  }
43318
- function readRecord6(repoRoot) {
43391
+ function readRecord5(repoRoot) {
43319
43392
  const path42 = resolve19(repoRoot, PREVIEW_DEPLOY_RECORD);
43320
43393
  if (!existsSync36(path42)) return null;
43321
43394
  try {
@@ -43355,7 +43428,7 @@ function readCurrentMainCommit(repoRoot) {
43355
43428
  }
43356
43429
  function buildPreviewFreshness(repoRoot) {
43357
43430
  const current = readCurrentMainCommit(repoRoot);
43358
- const record = readRecord6(repoRoot);
43431
+ const record = readRecord5(repoRoot);
43359
43432
  const lastPreviewCommit = normalizeCommit(record?.lastPreviewCommit);
43360
43433
  const targets = readTargetFreshness(record, current.currentMainCommit);
43361
43434
  let status = "unknown";
@@ -60283,6 +60356,7 @@ export {
60283
60356
  readLedgerEntries,
60284
60357
  readLedgerSlice,
60285
60358
  readLedgerSliceFromStore,
60359
+ readMeshCompletionSummary,
60286
60360
  reconcileDirectDispatchCompletionFromTranscript,
60287
60361
  recordCompletionConflict,
60288
60362
  recordDebugTrace,
@@ -60308,6 +60382,7 @@ export {
60308
60382
  resolveMeshHostStatus,
60309
60383
  resolveMeshNodeAttribution,
60310
60384
  resolveMeshRefineValidationPlan,
60385
+ resolveMeshSurfacedSessionPreview,
60311
60386
  resolveNodeSchedulingPriority,
60312
60387
  resolveSessionHostAppName,
60313
60388
  resolveSessionHostAppNameResolution,