@adhdev/daemon-standalone 0.9.82-rc.370 → 0.9.82-rc.373

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 ? "84d52e533859a9dd3c3bc8bc11a2541911f7bd0c" : void 0) ?? "unknown";
30040
- const commitShort = readInjected(true ? "84d52e53" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30041
- const version2 = readInjected(true ? "0.9.82-rc.370" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30042
- const builtAt = readInjected(true ? "2026-06-24T10:08:19.248Z" : void 0);
30039
+ const commit = readInjected(true ? "f16b5e6cdf653b4258f8f44cb11fb6ad8c13329f" : void 0) ?? "unknown";
30040
+ const commitShort = readInjected(true ? "f16b5e6c" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30041
+ const version2 = readInjected(true ? "0.9.82-rc.373" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30042
+ const builtAt = readInjected(true ? "2026-06-24T16:29:42.060Z" : void 0);
30043
30043
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30044
30044
  return cached2;
30045
30045
  }
@@ -35318,7 +35318,14 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
35318
35318
  if (candidate.taskMode === "live_debug_readonly") return true;
35319
35319
  return !nodeBusy;
35320
35320
  };
35321
- const entry = candidates.find((candidate) => nodeSatisfiesRequiredTags(candidate.requiredTags, capabilityTags) && dependenciesSatisfied(candidate) && nodeConflictAllows(candidate));
35321
+ const nodeIsWorktree = opts?.nodeIsWorktree === true;
35322
+ const convergenceAllows = (candidate) => candidate.taskMode !== "convergence" || !nodeIsWorktree;
35323
+ const targetMatches = (candidate) => {
35324
+ if (candidate.targetSessionId && candidate.targetSessionId !== sessionId) return false;
35325
+ if (candidate.targetNodeId && candidate.targetNodeId !== nodeId) return false;
35326
+ return true;
35327
+ };
35328
+ const entry = candidates.find((candidate) => nodeSatisfiesRequiredTags(candidate.requiredTags, capabilityTags) && dependenciesSatisfied(candidate) && convergenceAllows(candidate) && targetMatches(candidate) && nodeConflictAllows(candidate));
35322
35329
  if (!entry) return null;
35323
35330
  const now = (/* @__PURE__ */ new Date()).toISOString();
35324
35331
  entry.status = "assigned";
@@ -42530,6 +42537,31 @@ ${cleanBody}`;
42530
42537
  }
42531
42538
  return "";
42532
42539
  }
42540
+ function resolveForwardEventMeshId(components, payload) {
42541
+ const direct = readNonEmptyString2(payload.meshId);
42542
+ if (direct) return direct;
42543
+ const workspace = readNonEmptyString2(payload.workspace);
42544
+ const byWorkspace = workspace ? readNonEmptyString2(getCachedMeshByWorkspace(workspace)?.id) : "";
42545
+ if (byWorkspace) return byWorkspace;
42546
+ const byNode = recoverMeshIdByNodeId(readNonEmptyString2(payload.nodeId));
42547
+ if (byNode) return byNode;
42548
+ const sessionId = readNonEmptyString2(payload.targetSessionId) || readNonEmptyString2(payload.sessionId) || readNonEmptyString2(payload.instanceId);
42549
+ if (sessionId) {
42550
+ try {
42551
+ const state = components.instanceManager?.getInstance?.(sessionId)?.getState?.();
42552
+ const settings = state?.settings || {};
42553
+ const meshNodeFor = readNonEmptyString2(settings.meshNodeFor);
42554
+ if (meshNodeFor) return meshNodeFor;
42555
+ const byStamp = recoverMeshIdByNodeId(readNonEmptyString2(settings.meshNodeId));
42556
+ if (byStamp) return byStamp;
42557
+ const sessionWorkspace = readNonEmptyString2(state?.workspace);
42558
+ const bySessionWorkspace = sessionWorkspace ? readNonEmptyString2(getCachedMeshByWorkspace(sessionWorkspace)?.id) : "";
42559
+ if (bySessionWorkspace) return bySessionWorkspace;
42560
+ } catch {
42561
+ }
42562
+ }
42563
+ return "";
42564
+ }
42533
42565
  function __resetIdleAutoFastForwardForTests() {
42534
42566
  idleAutoFastForwardLastAttempt.clear();
42535
42567
  }
@@ -42776,9 +42808,11 @@ ${cleanBody}`;
42776
42808
  }
42777
42809
  const capabilityTags = buildMeshNodeCapabilityTags(node, providerType);
42778
42810
  const providerMaxParallel = resolveProviderMaxParallel(node?.policy, providerType);
42811
+ const nodeIsWorktree = node?.isLocalWorktree === true;
42779
42812
  const task = claimNextTask(meshId, nodeId, sessionId, capabilityTags, {
42780
42813
  providerType,
42781
- ...providerMaxParallel !== void 0 ? { providerMaxParallel } : {}
42814
+ ...providerMaxParallel !== void 0 ? { providerMaxParallel } : {},
42815
+ nodeIsWorktree
42782
42816
  });
42783
42817
  if (!task) {
42784
42818
  return false;
@@ -43122,6 +43156,7 @@ ${cleanBody}`;
43122
43156
  }
43123
43157
  const candidateNodes = Array.isArray(mesh?.nodes) ? mesh.nodes.filter((node) => {
43124
43158
  if (task.targetNodeId && !meshNodeIdMatches(node, task.targetNodeId)) return false;
43159
+ if (task.taskMode === "convergence" && node?.isLocalWorktree === true) return false;
43125
43160
  if (task.requiredTags?.length) {
43126
43161
  const priorities = normalizeProviderPriority(node?.policy);
43127
43162
  const providerCandidates = priorities.length ? priorities : [void 0];
@@ -44105,6 +44140,8 @@ ${cleanBody}`;
44105
44140
  nodeId: readNonEmptyString2(routing.nodeId) || readNonEmptyString2(event.meshNodeId) || void 0,
44106
44141
  workspace: readNonEmptyString2(routing.workspace) || readNonEmptyString2(event.workspace) || void 0
44107
44142
  };
44143
+ const resolvedMeshId = resolveForwardEventMeshId(components, payload);
44144
+ if (resolvedMeshId) payload.meshId = resolvedMeshId;
44108
44145
  const selfDaemonIds = resolveCoordinatorDrainDaemonIds(components);
44109
44146
  if (selfDaemonIds.some((self) => daemonIdsEquivalent(self, coordinatorDaemonId))) {
44110
44147
  try {
@@ -44645,7 +44682,10 @@ ${cleanBody}`;
44645
44682
  if (!dispatchMeshCommand) return;
44646
44683
  expireStaleUnresolvedDelegateForwards();
44647
44684
  const entries = peekUnresolvedDelegateForwards();
44648
- if (entries.length === 0) return;
44685
+ if (entries.length === 0) {
44686
+ if (unresolvedForwardRejectionCounts.size > 0) unresolvedForwardRejectionCounts.clear();
44687
+ return;
44688
+ }
44649
44689
  const selfIds = resolveCoordinatorDaemonIds(components);
44650
44690
  const isSelfCoordinatorId = (id) => selfIds.some((self) => daemonIdsEquivalent(self, id));
44651
44691
  for (const entry of entries) {
@@ -44664,6 +44704,7 @@ ${cleanBody}`;
44664
44704
  LOG2.warn("MeshReconcile", `Local route of self-addressed forward to ${entry.coordinatorDaemonId} threw: ${e?.message || e} \u2014 draining anyway to break the retry loop`);
44665
44705
  }
44666
44706
  ackUnresolvedDelegateForward(entry.id);
44707
+ unresolvedForwardRejectionCounts.delete(entry.id);
44667
44708
  if (localResult && localResult.success === false) {
44668
44709
  LOG2.warn("MeshReconcile", `Self-addressed unresolved-delegate ${readNonEmptyString2(entry.payload.event)} rejected by local router (${readNonEmptyString2(localResult.error) || "no reason"}) \u2014 drained to break the self-forward retry loop`);
44669
44710
  traceMeshEventDrop("self_forward_local_rejected", entryTraceCtx, readNonEmptyString2(localResult.error) || "no reason");
@@ -44672,21 +44713,40 @@ ${cleanBody}`;
44672
44713
  }
44673
44714
  continue;
44674
44715
  }
44716
+ let pushPayload = entry.payload;
44717
+ if (!readNonEmptyString2(pushPayload.meshId)) {
44718
+ const recoveredMeshId = resolveForwardEventMeshId(components, pushPayload);
44719
+ if (recoveredMeshId) {
44720
+ pushPayload = { ...pushPayload, meshId: recoveredMeshId };
44721
+ traceMeshEventStage("forward_meshid_recovered", entryTraceCtx, `meshId=${recoveredMeshId}`);
44722
+ }
44723
+ }
44675
44724
  let result;
44676
44725
  try {
44677
44726
  traceMeshEventStage("forward_send", entryTraceCtx, `retry \u2192 ${entry.coordinatorDaemonId}`);
44678
- result = await dispatchMeshCommand(entry.coordinatorDaemonId, "mesh_forward_event", entry.payload);
44727
+ result = await dispatchMeshCommand(entry.coordinatorDaemonId, "mesh_forward_event", pushPayload);
44679
44728
  } catch (e) {
44680
44729
  LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} failed: ${e?.message || e} \u2014 left queued`);
44681
44730
  traceMeshEventDrop("retry_forward_failed", entryTraceCtx, e?.message || String(e));
44682
44731
  continue;
44683
44732
  }
44684
44733
  if (result && result.success === false) {
44685
- LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected (${readNonEmptyString2(result.error) || "no reason"}) \u2014 left queued`);
44686
- traceMeshEventDrop("retry_forward_rejected", entryTraceCtx, readNonEmptyString2(result.error) || "no reason");
44734
+ const rejections = (unresolvedForwardRejectionCounts.get(entry.id) || 0) + 1;
44735
+ unresolvedForwardRejectionCounts.set(entry.id, rejections);
44736
+ const reason = readNonEmptyString2(result.error) || "no reason";
44737
+ if (rejections >= MAX_FORWARD_REJECTIONS) {
44738
+ ackUnresolvedDelegateForward(entry.id);
44739
+ unresolvedForwardRejectionCounts.delete(entry.id);
44740
+ LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected ${rejections}x (${reason}) \u2014 dropping unresolved-delegate ${readNonEmptyString2(entry.payload.event)} (sess=${readNonEmptyString2(entry.payload.targetSessionId) || readNonEmptyString2(entry.payload.sessionId) || "-"}) to stop the retry loop`);
44741
+ traceMeshEventDrop("retry_forward_exhausted", entryTraceCtx, `${reason} (${rejections} rejections)`);
44742
+ } else {
44743
+ LOG2.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected (${reason}) \u2014 left queued (attempt ${rejections}/${MAX_FORWARD_REJECTIONS})`);
44744
+ traceMeshEventDrop("retry_forward_rejected", entryTraceCtx, reason);
44745
+ }
44687
44746
  continue;
44688
44747
  }
44689
44748
  ackUnresolvedDelegateForward(entry.id);
44749
+ unresolvedForwardRejectionCounts.delete(entry.id);
44690
44750
  LOG2.info("MeshReconcile", `Retried+delivered unresolved-delegate ${readNonEmptyString2(entry.payload.event)} to coordinator ${entry.coordinatorDaemonId}`);
44691
44751
  }
44692
44752
  }
@@ -44917,6 +44977,8 @@ ${cleanBody}`;
44917
44977
  var heldEventLedgerRecorded;
44918
44978
  var ASSIGNED_STRANDED_DEADLINE_MS;
44919
44979
  var STRICT_SESSION_MATCH_TTL_MS;
44980
+ var unresolvedForwardRejectionCounts;
44981
+ var MAX_FORWARD_REJECTIONS;
44920
44982
  var init_mesh_reconcile_loop = __esm2({
44921
44983
  "src/mesh/mesh-reconcile-loop.ts"() {
44922
44984
  "use strict";
@@ -44941,6 +45003,8 @@ ${cleanBody}`;
44941
45003
  heldEventLedgerRecorded = /* @__PURE__ */ new Set();
44942
45004
  ASSIGNED_STRANDED_DEADLINE_MS = 5 * 6e4;
44943
45005
  STRICT_SESSION_MATCH_TTL_MS = 6e4;
45006
+ unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
45007
+ MAX_FORWARD_REJECTIONS = 5;
44944
45008
  }
44945
45009
  });
44946
45010
  var mesh_events_exports = {};
@@ -50518,6 +50582,7 @@ ${lastSnapshot}`;
50518
50582
  MESH_CONVERGE_FAST_FORWARD_TAG: () => MESH_CONVERGE_FAST_FORWARD_TAG,
50519
50583
  MESH_CONVERGE_REFINE_TAG: () => MESH_CONVERGE_REFINE_TAG,
50520
50584
  MESH_MISSION_STATUSES: () => MESH_MISSION_STATUSES,
50585
+ MESH_NODE_LIVE_TRUTH_MARKER: () => MESH_NODE_LIVE_TRUTH_MARKER,
50521
50586
  MESH_REFINE_CONFIG_LOCATIONS: () => MESH_REFINE_CONFIG_LOCATIONS,
50522
50587
  MESH_REFINE_CONFIG_SCHEMA: () => MESH_REFINE_CONFIG_SCHEMA,
50523
50588
  MESH_SCHEDULING_STRATEGIES: () => MESH_SCHEDULING_STRATEGIES,
@@ -50564,6 +50629,8 @@ ${lastSnapshot}`;
50564
50629
  buildMeshLedgerReconciliationEvidence: () => buildMeshLedgerReconciliationEvidence,
50565
50630
  buildMeshLedgerReplicaEvidence: () => buildMeshLedgerReplicaEvidence,
50566
50631
  buildMeshNodeCapabilityTags: () => buildMeshNodeCapabilityTags,
50632
+ buildMeshNodeDataFreshness: () => buildMeshNodeDataFreshness,
50633
+ buildMeshNodeProbeFreshness: () => buildMeshNodeProbeFreshness,
50567
50634
  buildMissionPromptSection: () => buildMissionPromptSection,
50568
50635
  buildP2pRelayFailurePayload: () => buildP2pRelayFailurePayload,
50569
50636
  buildPinnedGlobalInstallCommand: () => buildPinnedGlobalInstallCommand,
@@ -64416,6 +64483,27 @@ ${body}
64416
64483
  fs13.closeSync(fd);
64417
64484
  }
64418
64485
  }
64486
+ function splitLogLines(text) {
64487
+ const lines = text.split("\n");
64488
+ if (lines.length && lines[lines.length - 1] === "") lines.pop();
64489
+ return lines;
64490
+ }
64491
+ function takeLastLinesWithinBytes(lines, limitBytes) {
64492
+ if (lines.length === 0) return { kept: [], truncated: false, bytesReturned: 0 };
64493
+ let total = 0;
64494
+ let firstKept = lines.length;
64495
+ for (let i = lines.length - 1; i >= 0; i--) {
64496
+ const lineBytes = Buffer.byteLength(lines[i], "utf-8") + 1;
64497
+ if (firstKept !== lines.length && total + lineBytes > limitBytes) break;
64498
+ total += lineBytes;
64499
+ firstKept = i;
64500
+ }
64501
+ return {
64502
+ kept: lines.slice(firstKept),
64503
+ truncated: firstKept > 0,
64504
+ bytesReturned: total
64505
+ };
64506
+ }
64419
64507
  function parseLineEpochMs(line, fileDate) {
64420
64508
  const m = line.match(/^\[(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?\]/);
64421
64509
  if (!m) {
@@ -64430,47 +64518,97 @@ ${body}
64430
64518
  d.setHours(Number(m[1]), Number(m[2]), Number(m[3]), m[4] ? Number(m[4].padEnd(3, "0")) : 0);
64431
64519
  return d.getTime();
64432
64520
  }
64521
+ function buildGrepPredicate(grepSource) {
64522
+ let re = null;
64523
+ try {
64524
+ re = new RegExp(grepSource, "i");
64525
+ } catch {
64526
+ re = null;
64527
+ }
64528
+ if (re) {
64529
+ const compiled = re;
64530
+ return (line) => compiled.test(line);
64531
+ }
64532
+ const needle = grepSource.toLowerCase();
64533
+ return (line) => line.toLowerCase().includes(needle);
64534
+ }
64535
+ function fileDateFor(date5) {
64536
+ if (date5 instanceof Date) return date5;
64537
+ if (typeof date5 === "string" && date5.trim()) return /* @__PURE__ */ new Date(`${date5.trim()}T00:00:00.000Z`);
64538
+ return /* @__PURE__ */ new Date();
64539
+ }
64540
+ function errorResult(error48, logPath, platform10) {
64541
+ return {
64542
+ success: false,
64543
+ error: error48,
64544
+ lines: [],
64545
+ truncated: false,
64546
+ logPath,
64547
+ platform: platform10,
64548
+ bytesReturned: 0,
64549
+ filtered: false,
64550
+ fullScan: false,
64551
+ scannedBytes: 0,
64552
+ matchedLineCount: 0,
64553
+ excludedByFilter: 0
64554
+ };
64555
+ }
64433
64556
  function readDaemonLogTail(args = {}) {
64434
64557
  const platform10 = process.platform;
64435
64558
  const limitBytes = clampTailBytes(args.tailBytes);
64436
- let logPath = resolveLogPath(args.date);
64437
- if (!fs13.existsSync(logPath)) {
64438
- const backup = logPath.replace(/\.log$/, ".1.log");
64439
- if (fs13.existsSync(backup)) {
64440
- logPath = backup;
64441
- } else {
64442
- return {
64443
- success: false,
64444
- error: `No daemon log file at ${logPath} (dir: ${getDaemonLogDir()})`,
64445
- lines: [],
64446
- truncated: false,
64447
- logPath,
64448
- platform: platform10,
64449
- bytesReturned: 0,
64450
- filtered: false
64451
- };
64452
- }
64559
+ const primaryPath = resolveLogPath(args.date);
64560
+ const backupPath = primaryPath.replace(/\.log$/, ".1.log");
64561
+ const primaryExists = fs13.existsSync(primaryPath);
64562
+ const backupExists = fs13.existsSync(backupPath);
64563
+ if (!primaryExists && !backupExists) {
64564
+ return errorResult(
64565
+ `No daemon log file at ${primaryPath} (dir: ${getDaemonLogDir()})`,
64566
+ primaryPath,
64567
+ platform10
64568
+ );
64453
64569
  }
64454
- let raw;
64455
- try {
64456
- raw = readByteBoundedTail(logPath, limitBytes);
64457
- } catch (e) {
64570
+ const logPath = primaryExists ? primaryPath : backupPath;
64571
+ const hasGrep = typeof args.grep === "string" && args.grep.trim().length > 0;
64572
+ const hasSince = Number.isFinite(args.sinceMs);
64573
+ const filterMode = hasGrep || hasSince;
64574
+ if (!filterMode) {
64575
+ let raw;
64576
+ try {
64577
+ raw = readByteBoundedTail(logPath, limitBytes);
64578
+ } catch (e) {
64579
+ return errorResult(`Failed to read ${logPath}: ${e?.message ?? String(e)}`, logPath, platform10);
64580
+ }
64581
+ const lines2 = splitLogLines(raw.text);
64458
64582
  return {
64459
- success: false,
64460
- error: `Failed to read ${logPath}: ${e?.message ?? String(e)}`,
64461
- lines: [],
64462
- truncated: false,
64583
+ success: true,
64584
+ lines: lines2,
64585
+ truncated: raw.truncated,
64463
64586
  logPath,
64464
64587
  platform: platform10,
64465
- bytesReturned: 0,
64466
- filtered: false
64588
+ bytesReturned: raw.bytesReturned,
64589
+ filtered: false,
64590
+ fullScan: false,
64591
+ scannedBytes: raw.bytesReturned,
64592
+ matchedLineCount: lines2.length,
64593
+ excludedByFilter: 0
64467
64594
  };
64468
64595
  }
64469
- let lines = raw.text.split("\n");
64470
- if (lines.length && lines[lines.length - 1] === "") lines.pop();
64471
- const rawCount = lines.length;
64472
- if (Number.isFinite(args.sinceMs)) {
64473
- const fileDate = args.date instanceof Date ? args.date : typeof args.date === "string" && args.date.trim() ? /* @__PURE__ */ new Date(`${args.date.trim()}T00:00:00.000Z`) : /* @__PURE__ */ new Date();
64596
+ let scannedBytes = 0;
64597
+ let allLines = [];
64598
+ try {
64599
+ for (const p of [backupExists ? backupPath : null, primaryExists ? primaryPath : null]) {
64600
+ if (!p) continue;
64601
+ const buf = fs13.readFileSync(p);
64602
+ scannedBytes += buf.length;
64603
+ allLines = allLines.concat(splitLogLines(buf.toString("utf-8")));
64604
+ }
64605
+ } catch (e) {
64606
+ return errorResult(`Failed to read ${logPath}: ${e?.message ?? String(e)}`, logPath, platform10);
64607
+ }
64608
+ const scannedLineCount = allLines.length;
64609
+ let lines = allLines;
64610
+ if (hasSince) {
64611
+ const fileDate = fileDateFor(args.date);
64474
64612
  const floor = args.sinceMs;
64475
64613
  lines = lines.filter((line) => {
64476
64614
  const ts2 = parseLineEpochMs(line, fileDate);
@@ -64478,30 +64616,26 @@ ${body}
64478
64616
  });
64479
64617
  }
64480
64618
  let appliedGrep;
64481
- if (typeof args.grep === "string" && args.grep.trim()) {
64619
+ if (hasGrep) {
64482
64620
  appliedGrep = args.grep.trim();
64483
- let re = null;
64484
- try {
64485
- re = new RegExp(appliedGrep, "i");
64486
- } catch {
64487
- re = null;
64488
- }
64489
- if (re) {
64490
- const compiled = re;
64491
- lines = lines.filter((line) => compiled.test(line));
64492
- } else {
64493
- const needle = appliedGrep.toLowerCase();
64494
- lines = lines.filter((line) => line.toLowerCase().includes(needle));
64495
- }
64621
+ const matches = buildGrepPredicate(appliedGrep);
64622
+ lines = lines.filter(matches);
64496
64623
  }
64624
+ const matchedLineCount = lines.length;
64625
+ const excludedByFilter = scannedLineCount - matchedLineCount;
64626
+ const capped = takeLastLinesWithinBytes(lines, limitBytes);
64497
64627
  return {
64498
64628
  success: true,
64499
- lines,
64500
- truncated: raw.truncated,
64629
+ lines: capped.kept,
64630
+ truncated: capped.truncated,
64501
64631
  logPath,
64502
64632
  platform: platform10,
64503
- bytesReturned: raw.bytesReturned,
64504
- filtered: lines.length !== rawCount,
64633
+ bytesReturned: capped.bytesReturned,
64634
+ filtered: excludedByFilter > 0,
64635
+ fullScan: true,
64636
+ scannedBytes,
64637
+ matchedLineCount,
64638
+ excludedByFilter,
64505
64639
  ...appliedGrep ? { grep: appliedGrep } : {}
64506
64640
  };
64507
64641
  }
@@ -64614,6 +64748,12 @@ ${body}
64614
64748
  truncated: tail.truncated,
64615
64749
  filtered: tail.filtered,
64616
64750
  bytesReturned: tail.bytesReturned,
64751
+ // Transparency meta — lets the coordinator see that a full-file grep
64752
+ // ran past the recent tail window, and how much was scanned/excluded.
64753
+ fullScan: tail.fullScan,
64754
+ scannedBytes: tail.scannedBytes,
64755
+ matchedLineCount: tail.matchedLineCount,
64756
+ excludedByFilter: tail.excludedByFilter,
64617
64757
  ...tail.grep ? { grep: tail.grep } : {}
64618
64758
  };
64619
64759
  }
@@ -71695,7 +71835,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
71695
71835
  const adapter = this.adapters.get(ik);
71696
71836
  if (adapter) return { adapter, key: ik };
71697
71837
  }
71698
- if (opts?.dir) {
71838
+ if (opts?.dir && !opts?.instanceKey) {
71699
71839
  for (const [k, a] of this.adapters) {
71700
71840
  if (a.cliType === agentType && a.workingDir === opts.dir) {
71701
71841
  return { adapter: a, key: k };
@@ -77259,6 +77399,50 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
77259
77399
  return ctx.startMeshRefineBatchJob(meshId, requestedNodeIds, args);
77260
77400
  }
77261
77401
  };
77402
+ init_dist();
77403
+ var RESTART_BLOCKING_STATES = /* @__PURE__ */ new Set(["generating", "waiting_approval", "starting"]);
77404
+ function hasBlockingSessions(ctx) {
77405
+ const states = ctx.deps.instanceManager.collectAllStates();
77406
+ for (const state of states) {
77407
+ if (RESTART_BLOCKING_STATES.has(String(state.status || ""))) return true;
77408
+ const childStates = "extensions" in state && Array.isArray(state.extensions) ? state.extensions : [];
77409
+ for (const child of childStates) {
77410
+ if (RESTART_BLOCKING_STATES.has(String(child?.status || ""))) return true;
77411
+ }
77412
+ }
77413
+ return false;
77414
+ }
77415
+ var meshRestartHandlers = {
77416
+ restart_daemon_node: async (ctx, args) => {
77417
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
77418
+ const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
77419
+ let nodeDaemonId;
77420
+ if (meshId && nodeId) {
77421
+ const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
77422
+ const node = meshRecord?.mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
77423
+ nodeDaemonId = typeof node?.daemonId === "string" ? node.daemonId.trim() : void 0;
77424
+ }
77425
+ const selfDaemonId = ctx.deps.statusInstanceId;
77426
+ const isRemote = nodeDaemonId && selfDaemonId && !daemonIdsEquivalent(nodeDaemonId, selfDaemonId);
77427
+ if (isRemote && ctx.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
77428
+ const forwarded = await ctx.deps.dispatchMeshCommand(nodeDaemonId, "restart_daemon_node", {
77429
+ ...typeof args === "object" && args !== null ? args : {},
77430
+ _meshDirectDispatch: true
77431
+ });
77432
+ return forwarded ?? { success: false, error: "no response from remote node" };
77433
+ }
77434
+ if (hasBlockingSessions(ctx)) {
77435
+ return {
77436
+ success: false,
77437
+ restarted: false,
77438
+ code: "blocking_sessions",
77439
+ reason: "Daemon has an active session (generating / waiting_approval / starting); restart refused to avoid interrupting in-flight work. Retry when the node is idle."
77440
+ };
77441
+ }
77442
+ const result = await daemonLifecycleHandlers.daemon_upgrade({ deps: ctx.deps }, args);
77443
+ return { ...result, restarted: result?.restarting === true };
77444
+ }
77445
+ };
77262
77446
  var medFamilyRegistry = new Map(
77263
77447
  Object.entries({
77264
77448
  ...cliAgentHandlers,
@@ -77266,7 +77450,8 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
77266
77450
  ...meshCrudHandlers,
77267
77451
  ...meshHostPairingHandlers,
77268
77452
  ...meshQueueHandlers,
77269
- ...fastForwardHandlers
77453
+ ...fastForwardHandlers,
77454
+ ...meshRestartHandlers
77270
77455
  })
77271
77456
  );
77272
77457
  init_mesh_events();
@@ -77593,7 +77778,7 @@ ${ptyResult.output.slice(-2e3)}`);
77593
77778
  workspace
77594
77779
  };
77595
77780
  }
77596
- const { existsSync: existsSync49, readFileSync: readFileSync39, writeFileSync: writeFileSync24, copyFileSync: copyFileSync4, mkdirSync: mkdirSync21 } = await import("fs");
77781
+ const { existsSync: existsSync49, readFileSync: readFileSync40, writeFileSync: writeFileSync24, copyFileSync: copyFileSync4, mkdirSync: mkdirSync21 } = await import("fs");
77597
77782
  const { dirname: dirname17 } = await import("path");
77598
77783
  const mcpConfigPath = coordinatorSetup.configPath;
77599
77784
  const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
@@ -77643,7 +77828,7 @@ ${ptyResult.output.slice(-2e3)}`);
77643
77828
  }
77644
77829
  if (hadExistingMcpConfig) {
77645
77830
  try {
77646
- const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(readFileSync39(mcpConfigPath, "utf-8"), configFormat);
77831
+ const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(readFileSync40(mcpConfigPath, "utf-8"), configFormat);
77647
77832
  const existingCoordinatorConfig = hermesManualFallback ? stripHermesCoordinatorTempModelProviderOverrides(parsedExistingMcpConfig) : parsedExistingMcpConfig;
77648
77833
  existingMcpConfig = { ...existingMcpConfig, ...existingCoordinatorConfig };
77649
77834
  copyFileSync4(mcpConfigPath, mcpConfigPath + ".backup");
@@ -79345,6 +79530,23 @@ ${ptyResult.output.slice(-2e3)}`);
79345
79530
  staleness
79346
79531
  };
79347
79532
  }
79533
+ function buildMeshNodeProbeFreshness(args) {
79534
+ const { git, liveTruthProbed, isSelfNode, daemonId, node, now } = args;
79535
+ const status = {
79536
+ git,
79537
+ connection: { state: liveTruthProbed ? "connected" : "disconnected" }
79538
+ };
79539
+ if (liveTruthProbed) status[MESH_NODE_LIVE_TRUTH_MARKER] = true;
79540
+ return buildMeshNodeDataFreshness({
79541
+ status,
79542
+ node,
79543
+ isSelfNode,
79544
+ daemonId,
79545
+ liveTruthProbed,
79546
+ directTruthUnavailable: !liveTruthProbed && !!daemonId,
79547
+ now
79548
+ });
79549
+ }
79348
79550
  function finalizeMeshNodeStatus(args) {
79349
79551
  const { status, node, daemonId, isSelfNode, directTruthUnavailable } = args;
79350
79552
  if (!readStringValue(status.machineStatus)) {