@adhdev/daemon-standalone 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.js CHANGED
@@ -30036,10 +30036,10 @@ var require_dist3 = __commonJS({
30036
30036
  }
30037
30037
  function getDaemonBuildInfo() {
30038
30038
  if (cached2) return cached2;
30039
- const commit = readInjected(true ? "f066449c7e758daf63ad40d431a5e97fc8d79a0e" : void 0) ?? "unknown";
30040
- const commitShort = readInjected(true ? "f066449c" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30041
- const version2 = readInjected(true ? "0.9.82-rc.350" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30042
- const builtAt = readInjected(true ? "2026-06-21T19:33:42.557Z" : void 0);
30039
+ const commit = readInjected(true ? "dad22ef2758130d10a3d55e3c419f0095d5e44b7" : void 0) ?? "unknown";
30040
+ const commitShort = readInjected(true ? "dad22ef2" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30041
+ const version2 = readInjected(true ? "0.9.82-rc.351" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30042
+ const builtAt = readInjected(true ? "2026-06-22T04:05:27.792Z" : void 0);
30043
30043
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30044
30044
  return cached2;
30045
30045
  }
@@ -34454,6 +34454,10 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
34454
34454
  migratedMeshIds = /* @__PURE__ */ new Set();
34455
34455
  fingerprintSweepCounter = 0;
34456
34456
  walWriteCounter = 0;
34457
+ // Independent cadence for the tool-call-log sweep. Must NOT share walWriteCounter:
34458
+ // sharing makes each store's threshold drift by the other's write volume (WAL
34459
+ // checkpoint at 500 vs tool-log sweep at 200 would interfere arbitrarily).
34460
+ toolCallLogCounter = 0;
34457
34461
  static WAL_CHECK_INTERVAL = 500;
34458
34462
  static WAL_MAX_BYTES = 50 * 1024 * 1024;
34459
34463
  // 50 MB
@@ -35347,7 +35351,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
35347
35351
  "SELECT COUNT(*) as cnt FROM mesh_tool_call_log WHERE mesh_id = ? AND tool = ? AND called_at >= ?"
35348
35352
  ).get(meshId, tool, windowStart);
35349
35353
  const callsInWindow = row?.cnt ?? 0;
35350
- if (++this.walWriteCounter % 200 === 0) {
35354
+ if (++this.toolCallLogCounter % 200 === 0) {
35351
35355
  this.db.prepare(
35352
35356
  "DELETE FROM mesh_tool_call_log WHERE called_at < ?"
35353
35357
  ).run(now - Math.max(windowMs * 10, 6e4));
@@ -35800,9 +35804,9 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
35800
35804
  }
35801
35805
  return targetIds.map((taskId) => {
35802
35806
  const queueEntry = queueById.get(taskId);
35803
- const status = queueEntry?.status ?? "unknown";
35804
35807
  const dispatch = dispatches.get(taskId);
35805
35808
  const terminal = terminals.get(taskId);
35809
+ const status = queueEntry?.status ?? (terminal ? terminal.kind === "task_completed" ? "completed" : "failed" : "unknown");
35806
35810
  const isTerminalStatus = status === "completed" || status === "failed" || status === "cancelled";
35807
35811
  const dispatchTime = parseTime(dispatch?.first ?? queueEntry?.dispatchTimestamp);
35808
35812
  const terminalTime = parseTime(terminal?.at);
@@ -37812,6 +37816,14 @@ ${rendered}`, "utf-8");
37812
37816
  if (entry.kind === "task_completed") return "idle";
37813
37817
  return "failed";
37814
37818
  }
37819
+ function classifyDirectDispatch(params) {
37820
+ const { status, isTerminalRow, hasTerminalStatus, liveStatus, liveStaleReason, dispatchedToIdleSession } = params;
37821
+ const isNoTransition = !hasTerminalStatus && !liveStatus;
37822
+ const isIdleUnacknowledged = status === "idle";
37823
+ const ledgerOnlyStaleReason = !isTerminalRow && (isIdleUnacknowledged || isNoTransition || dispatchedToIdleSession && isIdleUnacknowledged) ? LEDGER_ONLY_STALE_REASON : void 0;
37824
+ const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !liveStaleReason);
37825
+ return { ledgerOnlyStaleReason, isFreshUnacknowledged };
37826
+ }
37815
37827
  function buildMeshActiveWorkSummary(activeWork) {
37816
37828
  const statusCounts = {
37817
37829
  pending: 0,
@@ -37874,10 +37886,14 @@ ${rendered}`, "utf-8");
37874
37886
  const dbStatus = dispatch.status;
37875
37887
  const isTerminal = dbStatus === "completed" || dbStatus === "failed" || dbStatus === "stale";
37876
37888
  const status = isTerminal ? dbStatus === "completed" ? "idle" : "failed" : live.status || (dbStatus === "acked" ? "generating" : "assigned");
37877
- const isNoTransition = !isTerminal && !live.status;
37878
- const isIdleUnacknowledged = status === "idle" && !isTerminal;
37879
- const ledgerOnlyStaleReason = !isTerminal && (isIdleUnacknowledged || isNoTransition || dispatch.dispatchedToIdleSession && isIdleUnacknowledged) ? "direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition" : void 0;
37880
- const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !live.staleReason);
37889
+ const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
37890
+ status,
37891
+ isTerminalRow: isTerminal,
37892
+ hasTerminalStatus: isTerminal,
37893
+ liveStatus: live.status,
37894
+ liveStaleReason: live.staleReason,
37895
+ dispatchedToIdleSession: dispatch.dispatchedToIdleSession === true
37896
+ });
37881
37897
  const { title, summary: summary2 } = summarizeMessage(dispatch.message || "");
37882
37898
  const record2 = {
37883
37899
  taskId: dispatch.taskId,
@@ -37920,13 +37936,16 @@ ${rendered}`, "utf-8");
37920
37936
  const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
37921
37937
  const status = terminalStatus || live.status || "assigned";
37922
37938
  const terminalRow = Boolean(terminal && terminal.kind !== "task_approval_needed");
37923
- const dispatchedToIdleSession = dispatch.payload?.dispatchedToIdleSession === true;
37924
- const isNoTransition = !terminalStatus && !live.status;
37925
- const isIdleUnacknowledged = status === "idle";
37926
- const ledgerOnlyStaleReason = !terminalRow && (isIdleUnacknowledged || isNoTransition || dispatchedToIdleSession && isIdleUnacknowledged) ? "direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition" : void 0;
37939
+ const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
37940
+ status,
37941
+ isTerminalRow: terminalRow,
37942
+ hasTerminalStatus: Boolean(terminalStatus),
37943
+ liveStatus: live.status,
37944
+ liveStaleReason: live.staleReason,
37945
+ dispatchedToIdleSession: dispatch.payload?.dispatchedToIdleSession === true
37946
+ });
37927
37947
  const message = readString6(dispatch.payload?.message) || readString6(dispatch.payload?.summary) || "";
37928
37948
  const { title, summary: summary2 } = summarizeMessage(message);
37929
- const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !live.staleReason);
37930
37949
  const record2 = {
37931
37950
  taskId,
37932
37951
  source: "direct",
@@ -37968,13 +37987,16 @@ ${rendered}`, "utf-8");
37968
37987
  const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
37969
37988
  const status = terminalStatus || live.status || "assigned";
37970
37989
  const terminalRow = Boolean(terminal && terminal.kind !== "task_approval_needed");
37971
- const dispatchedToIdleSession = dispatch.payload?.dispatchedToIdleSession === true;
37972
- const isNoTransition = !terminalStatus && !live.status;
37973
- const isIdleUnacknowledged = status === "idle";
37974
- const ledgerOnlyStaleReason = !terminalRow && (isIdleUnacknowledged || isNoTransition || dispatchedToIdleSession && isIdleUnacknowledged) ? "direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition" : void 0;
37990
+ const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
37991
+ status,
37992
+ isTerminalRow: terminalRow,
37993
+ hasTerminalStatus: Boolean(terminalStatus),
37994
+ liveStatus: live.status,
37995
+ liveStaleReason: live.staleReason,
37996
+ dispatchedToIdleSession: dispatch.payload?.dispatchedToIdleSession === true
37997
+ });
37975
37998
  const message = readString6(dispatch.payload?.message) || readString6(dispatch.payload?.summary) || "";
37976
37999
  const { title, summary: summary2 } = summarizeMessage(message);
37977
- const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !live.staleReason);
37978
38000
  const record2 = {
37979
38001
  taskId,
37980
38002
  source: "direct",
@@ -38127,6 +38149,7 @@ ${rendered}`, "utf-8");
38127
38149
  }
38128
38150
  var DIRECT_DISPATCH_VIA;
38129
38151
  var TERMINAL_LEDGER_KINDS;
38152
+ var LEDGER_ONLY_STALE_REASON;
38130
38153
  var PRUNABLE_ORPHAN_STALE_REASONS;
38131
38154
  var init_mesh_active_work = __esm2({
38132
38155
  "src/mesh/mesh-active-work.ts"() {
@@ -38136,6 +38159,7 @@ ${rendered}`, "utf-8");
38136
38159
  init_dist();
38137
38160
  DIRECT_DISPATCH_VIA = /* @__PURE__ */ new Set(["p2p_direct", "local_direct", "mesh_send_task"]);
38138
38161
  TERMINAL_LEDGER_KINDS = /* @__PURE__ */ new Set(["task_completed", "task_failed", "task_stalled"]);
38162
+ LEDGER_ONLY_STALE_REASON = "direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition";
38139
38163
  PRUNABLE_ORPHAN_STALE_REASONS = /* @__PURE__ */ new Set([
38140
38164
  "direct task node is no longer in the live mesh",
38141
38165
  "direct task session is not present in live session records",
@@ -38569,6 +38593,7 @@ Next step: ${nextStep}`;
38569
38593
  return true;
38570
38594
  }
38571
38595
  const fingerprint = buildPendingEventFingerprint(event);
38596
+ let sqliteOk = false;
38572
38597
  try {
38573
38598
  MeshRuntimeStore.getInstance().insertPendingEvent({
38574
38599
  id: (0, import_crypto7.randomUUID)(),
@@ -38579,11 +38604,17 @@ Next step: ${nextStep}`;
38579
38604
  fingerprint: fingerprint || null,
38580
38605
  queuedAt: event.queuedAt
38581
38606
  });
38607
+ sqliteOk = true;
38582
38608
  } catch {
38583
38609
  }
38584
- const path422 = getPendingEventsPath(event.meshId, event.targetCoordinatorDaemonId);
38585
- trimPendingEventsIfNeeded(path422);
38586
- (0, import_fs10.appendFileSync)(path422, JSON.stringify(event) + "\n", "utf-8");
38610
+ try {
38611
+ const path422 = getPendingEventsPath(event.meshId, event.targetCoordinatorDaemonId);
38612
+ trimPendingEventsIfNeeded(path422);
38613
+ (0, import_fs10.appendFileSync)(path422, JSON.stringify(event) + "\n", "utf-8");
38614
+ } catch (e) {
38615
+ if (!sqliteOk) throw e;
38616
+ LOG2.warn("MeshEvents", `JSONL append failed for mesh ${event.meshId}; SQLite holds the event: ${e?.message || e}`);
38617
+ }
38587
38618
  return true;
38588
38619
  } catch (e) {
38589
38620
  LOG2.warn("MeshEvents", `Failed to persist pending coordinator event: ${e?.message || e}`);
@@ -38986,6 +39017,12 @@ Next step: ${nextStep}`;
38986
39017
  }
38987
39018
  return false;
38988
39019
  }
39020
+ function isWeakCompletionLedgerPayload(payload) {
39021
+ if (!payload) return false;
39022
+ if (payload.evidenceLevel === "insufficient" || payload.reviewRecommended === true) return true;
39023
+ const diag = readRecord4(payload.completionDiagnostic);
39024
+ return diag?.finalAssistantPresent === false || diag?.blockReason === "missing_final_assistant";
39025
+ }
38989
39026
  function findDirectDispatchLedgerEntry(args) {
38990
39027
  const entries = readLedgerEntries(args.meshId, { tail: 500 });
38991
39028
  for (let i = entries.length - 1; i >= 0; i--) {
@@ -39022,6 +39059,7 @@ Next step: ${nextStep}`;
39022
39059
  if (!afterDispatch) continue;
39023
39060
  }
39024
39061
  if (entry.kind !== "task_completed" && entry.kind !== "task_failed" && entry.kind !== "task_stalled") continue;
39062
+ if (entry.kind === "task_completed" && isWeakCompletionLedgerPayload(entry.payload)) continue;
39025
39063
  const terminalTaskId = readNonEmptyString2(entry.payload?.taskId);
39026
39064
  if (terminalTaskId && terminalTaskId === args.taskId) return true;
39027
39065
  if (terminalTaskId && terminalTaskId !== args.taskId) continue;
@@ -42351,6 +42389,30 @@ ${cleanBody}`;
42351
42389
  recordFingerprintSeen(fingerprint);
42352
42390
  return false;
42353
42391
  }
42392
+ function isFalseIdleCompletion(metadataEvent) {
42393
+ const diag = readRecord4(metadataEvent.completionDiagnostic);
42394
+ if (!diag) return false;
42395
+ return diag.finalAssistantPresent === false || diag.blockReason === "missing_final_assistant";
42396
+ }
42397
+ function isGenuineCompletionEvidence(metadataEvent) {
42398
+ if (isFalseIdleCompletion(metadataEvent)) return false;
42399
+ return !!readWorkerResultMetadata(metadataEvent) || !!readNonEmptyString2(metadataEvent.finalSummary);
42400
+ }
42401
+ function isWeakTerminalLedgerPayload(payload) {
42402
+ if (!payload) return false;
42403
+ if (payload.evidenceLevel === "insufficient" || payload.reviewRecommended === true) return true;
42404
+ const diag = readRecord4(payload.completionDiagnostic);
42405
+ return diag?.finalAssistantPresent === false || diag?.blockReason === "missing_final_assistant";
42406
+ }
42407
+ function resolveActiveDirectDispatchTaskId(meshId, sessionId) {
42408
+ try {
42409
+ const matches = getActiveDirectDispatches(meshId).filter((d) => d.sessionId === sessionId);
42410
+ if (!matches.length) return void 0;
42411
+ return readNonEmptyString2(matches[matches.length - 1].taskId) || void 0;
42412
+ } catch {
42413
+ return void 0;
42414
+ }
42415
+ }
42354
42416
  function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
42355
42417
  const mesh = getMeshWithCache(components, meshId);
42356
42418
  const node = mesh?.nodes.find((n) => readMeshNodeId(n) === nodeId);
@@ -43195,7 +43257,8 @@ ${cleanBody}`;
43195
43257
  });
43196
43258
  if (terminal?.kind === "task_completed" && !sessionHasActiveAssignment(args.meshId, eventSessionId)) {
43197
43259
  const newDispatchAfterTerminal = hasDispatchAfterTerminal(args.meshId, eventSessionId, terminal.id);
43198
- if (!newDispatchAfterTerminal) {
43260
+ const supersedesWeakTerminal = isWeakTerminalLedgerPayload(terminal.payload) && isGenuineCompletionEvidence(args.metadataEvent);
43261
+ if (!newDispatchAfterTerminal && !supersedesWeakTerminal) {
43199
43262
  const terminalProviderSessionId = readNonEmptyString2(terminal.payload.providerSessionId);
43200
43263
  const terminalFinalSummary = readNonEmptyString2(terminal.payload.finalSummary);
43201
43264
  const eventProviderSessionId = readNonEmptyString2(args.metadataEvent.providerSessionId);
@@ -43241,24 +43304,30 @@ ${cleanBody}`;
43241
43304
  return { success: true, forwarded: 0, suppressed: true, duplicateStopped: true };
43242
43305
  }
43243
43306
  }
43244
- function markSessionTerminal(sessionId, outcome, occurredAtMs) {
43307
+ function markSessionTerminal(sessionId, outcome, occurredAtMs, opts) {
43245
43308
  const eventTaskId = readNonEmptyString2(args.metadataEvent.taskId) || void 0;
43246
43309
  const task = updateSessionTaskStatus(args.meshId, sessionId, outcome, {
43247
43310
  occurredAt: occurredAtMs != null ? new Date(occurredAtMs).toISOString() : void 0,
43248
43311
  taskId: eventTaskId
43249
43312
  });
43250
- updateDirectDispatchStatus(args.meshId, sessionId, outcome);
43313
+ const leaveDirectDispatchActive = !task && opts?.tentativeIfDirect === true;
43314
+ if (!leaveDirectDispatchActive) {
43315
+ updateDirectDispatchStatus(args.meshId, sessionId, outcome);
43316
+ }
43251
43317
  markSessionDeliveriesTerminal(args.meshId, sessionId, outcome);
43252
43318
  setImmediate(() => cleanupTerminalDirectDispatches());
43253
43319
  return task ? { id: task.id } : null;
43254
43320
  }
43255
43321
  let completedTaskForLedger = null;
43322
+ let directDispatchTaskIdForLedger;
43256
43323
  if (args.event === "agent:generating_completed") {
43257
43324
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
43258
43325
  const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
43259
43326
  const providerType = readNonEmptyString2(args.metadataEvent.providerType);
43260
43327
  if (sessionId) {
43261
- completedTaskForLedger = markSessionTerminal(sessionId, "completed", eventTimestamp);
43328
+ directDispatchTaskIdForLedger = resolveActiveDirectDispatchTaskId(args.meshId, sessionId);
43329
+ const isFalseIdle = isFalseIdleCompletion(args.metadataEvent);
43330
+ completedTaskForLedger = markSessionTerminal(sessionId, "completed", eventTimestamp, { tentativeIfDirect: isFalseIdle });
43262
43331
  if (nodeId && providerType) {
43263
43332
  runIdleMaintenanceThenAssignQueue(components, { meshId: args.meshId, nodeId, sessionId, providerType });
43264
43333
  }
@@ -43361,6 +43430,7 @@ ${cleanBody}`;
43361
43430
  }
43362
43431
  }
43363
43432
  if (sessionId) {
43433
+ directDispatchTaskIdForLedger = resolveActiveDirectDispatchTaskId(args.meshId, sessionId);
43364
43434
  completedTaskForLedger = markSessionTerminal(sessionId, "failed");
43365
43435
  }
43366
43436
  }
@@ -43390,7 +43460,10 @@ ${cleanBody}`;
43390
43460
  payload: {
43391
43461
  event: args.event,
43392
43462
  nodeLabel: args.nodeLabel,
43393
- taskId: completedTaskForLedger?.id || void 0,
43463
+ // Fix B: fall back to the direct-dispatch taskId when no work-queue row
43464
+ // matched, so the terminal entry is attributable in mesh task-stats
43465
+ // (otherwise the direct task shows status='unknown' / terminalKind=null).
43466
+ taskId: completedTaskForLedger?.id || directDispatchTaskIdForLedger || void 0,
43394
43467
  providerSessionId,
43395
43468
  finalSummary,
43396
43469
  workerResult,
@@ -49980,6 +50053,7 @@ ${lastSnapshot}`;
49980
50053
  readLedgerEntries: () => readLedgerEntries,
49981
50054
  readLedgerSlice: () => readLedgerSlice,
49982
50055
  readLedgerSliceFromStore: () => readLedgerSliceFromStore,
50056
+ readMeshCompletionSummary: () => readMeshCompletionSummary,
49983
50057
  reconcileDirectDispatchCompletionFromTranscript: () => reconcileDirectDispatchCompletionFromTranscript,
49984
50058
  recordCompletionConflict: () => recordCompletionConflict,
49985
50059
  recordDebugTrace: () => recordDebugTrace,
@@ -50005,6 +50079,7 @@ ${lastSnapshot}`;
50005
50079
  resolveMeshHostStatus: () => resolveMeshHostStatus,
50006
50080
  resolveMeshNodeAttribution: () => resolveMeshNodeAttribution,
50007
50081
  resolveMeshRefineValidationPlan: () => resolveMeshRefineValidationPlan,
50082
+ resolveMeshSurfacedSessionPreview: () => resolveMeshSurfacedSessionPreview,
50008
50083
  resolveNodeSchedulingPriority: () => resolveNodeSchedulingPriority,
50009
50084
  resolveSessionHostAppName: () => resolveSessionHostAppName,
50010
50085
  resolveSessionHostAppNameResolution: () => resolveSessionHostAppNameResolution2,
@@ -51889,6 +51964,7 @@ ${lastSnapshot}`;
51889
51964
  init_mesh_refine_status();
51890
51965
  init_mesh_host_ownership();
51891
51966
  init_mesh_events();
51967
+ init_mesh_events_utils();
51892
51968
  init_mesh_delivery_policy();
51893
51969
  var NO_FALLBACK_REASON = "Repo Mesh command/data-plane is P2P-only; WS/REST command fallback is intentionally disabled to preserve the transport boundary.";
51894
51970
  var P2P_NEXT_ACTION = "Check daemon/P2P health, wait briefly for connection establishment, then do one bounded retry or requeue the mesh task after clearing stale target session metadata.";
@@ -73275,7 +73351,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
73275
73351
  return "";
73276
73352
  }
73277
73353
  }
73278
- function readRecord6(repoRoot) {
73354
+ function readRecord5(repoRoot) {
73279
73355
  const path422 = (0, import_node_path2.resolve)(repoRoot, PREVIEW_DEPLOY_RECORD);
73280
73356
  if (!(0, import_node_fs4.existsSync)(path422)) return null;
73281
73357
  try {
@@ -73315,7 +73391,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
73315
73391
  }
73316
73392
  function buildPreviewFreshness(repoRoot) {
73317
73393
  const current = readCurrentMainCommit(repoRoot);
73318
- const record2 = readRecord6(repoRoot);
73394
+ const record2 = readRecord5(repoRoot);
73319
73395
  const lastPreviewCommit = normalizeCommit(record2?.lastPreviewCommit);
73320
73396
  const targets = readTargetFreshness(record2, current.currentMainCommit);
73321
73397
  let status = "unknown";