@adhdev/daemon-core 0.9.82-rc.305 → 0.9.82-rc.306

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
@@ -290,10 +290,10 @@ function readInjected(value) {
290
290
  }
291
291
  function getDaemonBuildInfo() {
292
292
  if (cached) return cached;
293
- const commit = readInjected(true ? "6103da081f92baaf891d3410e3d7ebc36d9e300d" : void 0) ?? "unknown";
294
- const commitShort = readInjected(true ? "6103da08" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
295
- const version = readInjected(true ? "0.9.82-rc.305" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
296
- const builtAt = readInjected(true ? "2026-06-17T06:08:13.151Z" : void 0);
293
+ const commit = readInjected(true ? "6ded896662908225a48ad662b6eec83267dbe9ba" : void 0) ?? "unknown";
294
+ const commitShort = readInjected(true ? "6ded8966" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
295
+ const version = readInjected(true ? "0.9.82-rc.306" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
296
+ const builtAt = readInjected(true ? "2026-06-17T07:21:37.675Z" : void 0);
297
297
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
298
298
  return cached;
299
299
  }
@@ -4529,6 +4529,110 @@ var init_mesh_runtime_store = __esm({
4529
4529
  }
4530
4530
  });
4531
4531
 
4532
+ // src/mesh/mesh-task-stats.ts
4533
+ function readPayloadTaskId(entry) {
4534
+ const value = entry.payload?.taskId;
4535
+ return typeof value === "string" && value.trim() ? value.trim() : "";
4536
+ }
4537
+ function parseTime(value) {
4538
+ if (!value) return null;
4539
+ const parsed = new Date(value).getTime();
4540
+ return Number.isFinite(parsed) ? parsed : null;
4541
+ }
4542
+ function computeMeshTaskStats(meshId, opts) {
4543
+ const queue = getQueue(meshId);
4544
+ const queueById = new Map(queue.map((task) => [task.id, task]));
4545
+ let targetIds;
4546
+ if (opts?.taskIds?.length) {
4547
+ targetIds = [...new Set(opts.taskIds)];
4548
+ } else if (opts?.missionId) {
4549
+ targetIds = queue.filter((task) => task.missionId === opts.missionId).map((task) => task.id);
4550
+ } else {
4551
+ targetIds = queue.map((task) => task.id);
4552
+ }
4553
+ if (targetIds.length === 0) return [];
4554
+ const targetSet = new Set(targetIds);
4555
+ const entries = readLedgerEntries(meshId, { tail: opts?.tail ?? 1e3 });
4556
+ const dispatches = /* @__PURE__ */ new Map();
4557
+ const terminals = /* @__PURE__ */ new Map();
4558
+ for (const entry of entries) {
4559
+ const taskId = readPayloadTaskId(entry);
4560
+ if (!taskId || !targetSet.has(taskId)) continue;
4561
+ if (entry.kind === "task_dispatched") {
4562
+ const existing = dispatches.get(taskId);
4563
+ if (existing) existing.count += 1;
4564
+ else dispatches.set(taskId, { first: entry.timestamp, count: 1 });
4565
+ } else if (entry.kind === "task_completed" || entry.kind === "task_failed") {
4566
+ terminals.set(taskId, { at: entry.timestamp, kind: entry.kind });
4567
+ }
4568
+ }
4569
+ return targetIds.map((taskId) => {
4570
+ const queueEntry = queueById.get(taskId);
4571
+ const status = queueEntry?.status ?? "unknown";
4572
+ const dispatch = dispatches.get(taskId);
4573
+ const terminal = terminals.get(taskId);
4574
+ const isTerminalStatus = status === "completed" || status === "failed" || status === "cancelled";
4575
+ const dispatchTime = parseTime(dispatch?.first ?? queueEntry?.dispatchTimestamp);
4576
+ const terminalTime = parseTime(terminal?.at);
4577
+ const stats = {
4578
+ taskId,
4579
+ status,
4580
+ dispatchedAt: dispatch?.first ?? queueEntry?.dispatchTimestamp ?? null,
4581
+ terminalAt: terminal?.at ?? null,
4582
+ terminalKind: terminal?.kind ?? null,
4583
+ durationMs: null,
4584
+ dispatchCount: dispatch?.count ?? 0,
4585
+ requeueCount: queueEntry?.requeueCount ?? 0
4586
+ };
4587
+ if (dispatchTime !== null && terminalTime !== null && terminalTime >= dispatchTime) {
4588
+ stats.durationMs = terminalTime - dispatchTime;
4589
+ } else if (isTerminalStatus) {
4590
+ stats.incompleteEvidence = true;
4591
+ }
4592
+ return stats;
4593
+ });
4594
+ }
4595
+ function computeMeshMissionStats(meshId, missionId) {
4596
+ const tasks = computeMeshTaskStats(meshId, { missionId });
4597
+ const stats = {
4598
+ missionId,
4599
+ taskCount: tasks.length,
4600
+ completed: 0,
4601
+ failed: 0,
4602
+ totalDurationMs: 0,
4603
+ wallClockMs: null,
4604
+ retries: 0,
4605
+ incompleteTaskIds: []
4606
+ };
4607
+ let firstDispatch = null;
4608
+ let lastTerminal = null;
4609
+ for (const task of tasks) {
4610
+ if (task.status === "completed") stats.completed += 1;
4611
+ else if (task.status === "failed") stats.failed += 1;
4612
+ stats.retries += task.requeueCount;
4613
+ if (task.incompleteEvidence) {
4614
+ stats.incompleteTaskIds.push(task.taskId);
4615
+ continue;
4616
+ }
4617
+ if (task.durationMs !== null) stats.totalDurationMs += task.durationMs;
4618
+ const dispatchTime = parseTime(task.dispatchedAt);
4619
+ const terminalTime = parseTime(task.terminalAt);
4620
+ if (dispatchTime !== null && (firstDispatch === null || dispatchTime < firstDispatch)) firstDispatch = dispatchTime;
4621
+ if (terminalTime !== null && (lastTerminal === null || terminalTime > lastTerminal)) lastTerminal = terminalTime;
4622
+ }
4623
+ if (firstDispatch !== null && lastTerminal !== null && lastTerminal >= firstDispatch) {
4624
+ stats.wallClockMs = lastTerminal - firstDispatch;
4625
+ }
4626
+ return stats;
4627
+ }
4628
+ var init_mesh_task_stats = __esm({
4629
+ "src/mesh/mesh-task-stats.ts"() {
4630
+ "use strict";
4631
+ init_mesh_ledger();
4632
+ init_mesh_work_queue();
4633
+ }
4634
+ });
4635
+
4532
4636
  // src/mesh/mesh-missions.ts
4533
4637
  var mesh_missions_exports = {};
4534
4638
  __export(mesh_missions_exports, {
@@ -4621,7 +4725,10 @@ function getMeshStatusMissionSummaries(meshId, options) {
4621
4725
  const all = getMeshMissions(meshId);
4622
4726
  const live = all.filter((m) => m.status === "active" || m.status === "paused");
4623
4727
  const history = all.filter((m) => m.status === "completed" || m.status === "abandoned").sort((a, b) => (b.updatedAt || "").localeCompare(a.updatedAt || "")).slice(0, historyLimit);
4624
- const full = [...live, ...history].map((mission) => summarizeMeshMission(meshId, mission));
4728
+ let full = [...live, ...history].map((mission) => summarizeMeshMission(meshId, mission));
4729
+ if (options?.withStats) {
4730
+ full = full.map((summary) => ({ ...summary, stats: computeMeshMissionStats(meshId, summary.id) }));
4731
+ }
4625
4732
  return options?.verbose ? full : full.map(slimMissionSummary);
4626
4733
  }
4627
4734
  function listMeshMissionSummaries(meshId, options) {
@@ -4654,6 +4761,7 @@ var init_mesh_missions = __esm({
4654
4761
  "use strict";
4655
4762
  init_mesh_runtime_store();
4656
4763
  init_mesh_work_queue();
4764
+ init_mesh_task_stats();
4657
4765
  MESH_MISSION_STATUSES = ["active", "paused", "completed", "abandoned"];
4658
4766
  GOAL_PREVIEW_MAX = 120;
4659
4767
  }
@@ -17003,107 +17111,7 @@ function getSavedProviderSessions(state, filters) {
17003
17111
  init_mesh_config();
17004
17112
  init_coordinator_prompt();
17005
17113
  init_mesh_missions();
17006
-
17007
- // src/mesh/mesh-task-stats.ts
17008
- init_mesh_ledger();
17009
- init_mesh_work_queue();
17010
- function readPayloadTaskId(entry) {
17011
- const value = entry.payload?.taskId;
17012
- return typeof value === "string" && value.trim() ? value.trim() : "";
17013
- }
17014
- function parseTime(value) {
17015
- if (!value) return null;
17016
- const parsed = new Date(value).getTime();
17017
- return Number.isFinite(parsed) ? parsed : null;
17018
- }
17019
- function computeMeshTaskStats(meshId, opts) {
17020
- const queue = getQueue(meshId);
17021
- const queueById = new Map(queue.map((task) => [task.id, task]));
17022
- let targetIds;
17023
- if (opts?.taskIds?.length) {
17024
- targetIds = [...new Set(opts.taskIds)];
17025
- } else if (opts?.missionId) {
17026
- targetIds = queue.filter((task) => task.missionId === opts.missionId).map((task) => task.id);
17027
- } else {
17028
- targetIds = queue.map((task) => task.id);
17029
- }
17030
- if (targetIds.length === 0) return [];
17031
- const targetSet = new Set(targetIds);
17032
- const entries = readLedgerEntries(meshId, { tail: opts?.tail ?? 1e3 });
17033
- const dispatches = /* @__PURE__ */ new Map();
17034
- const terminals = /* @__PURE__ */ new Map();
17035
- for (const entry of entries) {
17036
- const taskId = readPayloadTaskId(entry);
17037
- if (!taskId || !targetSet.has(taskId)) continue;
17038
- if (entry.kind === "task_dispatched") {
17039
- const existing = dispatches.get(taskId);
17040
- if (existing) existing.count += 1;
17041
- else dispatches.set(taskId, { first: entry.timestamp, count: 1 });
17042
- } else if (entry.kind === "task_completed" || entry.kind === "task_failed") {
17043
- terminals.set(taskId, { at: entry.timestamp, kind: entry.kind });
17044
- }
17045
- }
17046
- return targetIds.map((taskId) => {
17047
- const queueEntry = queueById.get(taskId);
17048
- const status = queueEntry?.status ?? "unknown";
17049
- const dispatch = dispatches.get(taskId);
17050
- const terminal = terminals.get(taskId);
17051
- const isTerminalStatus = status === "completed" || status === "failed" || status === "cancelled";
17052
- const dispatchTime = parseTime(dispatch?.first ?? queueEntry?.dispatchTimestamp);
17053
- const terminalTime = parseTime(terminal?.at);
17054
- const stats = {
17055
- taskId,
17056
- status,
17057
- dispatchedAt: dispatch?.first ?? queueEntry?.dispatchTimestamp ?? null,
17058
- terminalAt: terminal?.at ?? null,
17059
- terminalKind: terminal?.kind ?? null,
17060
- durationMs: null,
17061
- dispatchCount: dispatch?.count ?? 0,
17062
- requeueCount: queueEntry?.requeueCount ?? 0
17063
- };
17064
- if (dispatchTime !== null && terminalTime !== null && terminalTime >= dispatchTime) {
17065
- stats.durationMs = terminalTime - dispatchTime;
17066
- } else if (isTerminalStatus) {
17067
- stats.incompleteEvidence = true;
17068
- }
17069
- return stats;
17070
- });
17071
- }
17072
- function computeMeshMissionStats(meshId, missionId) {
17073
- const tasks = computeMeshTaskStats(meshId, { missionId });
17074
- const stats = {
17075
- missionId,
17076
- taskCount: tasks.length,
17077
- completed: 0,
17078
- failed: 0,
17079
- totalDurationMs: 0,
17080
- wallClockMs: null,
17081
- retries: 0,
17082
- incompleteTaskIds: []
17083
- };
17084
- let firstDispatch = null;
17085
- let lastTerminal = null;
17086
- for (const task of tasks) {
17087
- if (task.status === "completed") stats.completed += 1;
17088
- else if (task.status === "failed") stats.failed += 1;
17089
- stats.retries += task.requeueCount;
17090
- if (task.incompleteEvidence) {
17091
- stats.incompleteTaskIds.push(task.taskId);
17092
- continue;
17093
- }
17094
- if (task.durationMs !== null) stats.totalDurationMs += task.durationMs;
17095
- const dispatchTime = parseTime(task.dispatchedAt);
17096
- const terminalTime = parseTime(task.terminalAt);
17097
- if (dispatchTime !== null && (firstDispatch === null || dispatchTime < firstDispatch)) firstDispatch = dispatchTime;
17098
- if (terminalTime !== null && (lastTerminal === null || terminalTime > lastTerminal)) lastTerminal = terminalTime;
17099
- }
17100
- if (firstDispatch !== null && lastTerminal !== null && lastTerminal >= firstDispatch) {
17101
- stats.wallClockMs = lastTerminal - firstDispatch;
17102
- }
17103
- return stats;
17104
- }
17105
-
17106
- // src/index.ts
17114
+ init_mesh_task_stats();
17107
17115
  init_mesh_review_inbox();
17108
17116
 
17109
17117
  // src/mesh/coordinator-registry.ts
@@ -42004,6 +42012,31 @@ async function probeRemoteMeshGitStatus(args) {
42004
42012
  const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
42005
42013
  return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
42006
42014
  }
42015
+ var MESH_DIRECT_PROBE_MAX_RETRIES = 2;
42016
+ function readMeshConnectionState(connection) {
42017
+ return readStringValue(connection?.state);
42018
+ }
42019
+ async function probeRemoteMeshGitStatusWithRetry(args) {
42020
+ for (let attempt = 0; attempt <= MESH_DIRECT_PROBE_MAX_RETRIES; attempt += 1) {
42021
+ if (attempt > 0) {
42022
+ const connection = args.getConnection?.(args.daemonId);
42023
+ if (args.getConnection && readMeshConnectionState(connection) !== "connected") break;
42024
+ if (connection) args.onConnection?.(connection);
42025
+ await new Promise((resolve24) => setTimeout(resolve24, 250 * 2 ** (attempt - 1)));
42026
+ }
42027
+ try {
42028
+ const remoteGit = await probeRemoteMeshGitStatus({
42029
+ dispatchMeshCommand: args.dispatchMeshCommand,
42030
+ daemonId: args.daemonId,
42031
+ workspace: args.workspace,
42032
+ timeoutMs: attempt === 0 ? args.timeoutMs : args.retryTimeoutMs ?? args.timeoutMs
42033
+ });
42034
+ if (remoteGit) return remoteGit;
42035
+ } catch {
42036
+ }
42037
+ }
42038
+ return null;
42039
+ }
42007
42040
  async function hydrateInlineMeshDirectTruth(args) {
42008
42041
  const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
42009
42042
  if (!nodes.length) {
@@ -42063,19 +42096,18 @@ async function hydrateInlineMeshDirectTruth(args) {
42063
42096
  continue;
42064
42097
  }
42065
42098
  peerAttemptedCount += 1;
42066
- try {
42067
- const remoteGit = await probeRemoteMeshGitStatus({
42068
- dispatchMeshCommand: args.dispatchMeshCommand,
42069
- daemonId,
42070
- workspace,
42071
- timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS
42072
- });
42073
- if (remoteGit) {
42074
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
42075
- peerConfirmedCount += 1;
42076
- continue;
42077
- }
42078
- } catch {
42099
+ const remoteGit = await probeRemoteMeshGitStatusWithRetry({
42100
+ dispatchMeshCommand: args.dispatchMeshCommand,
42101
+ daemonId,
42102
+ workspace,
42103
+ timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS,
42104
+ retryTimeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS,
42105
+ getConnection: args.getMeshPeerConnectionStatus
42106
+ });
42107
+ if (remoteGit) {
42108
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
42109
+ peerConfirmedCount += 1;
42110
+ continue;
42079
42111
  }
42080
42112
  unavailableNodeIds.push(nodeId);
42081
42113
  }
@@ -46293,6 +46325,7 @@ ${hintLines.join("\n")}` : "",
46293
46325
  mesh: meshRecord.mesh,
46294
46326
  meshSource: meshRecord.source,
46295
46327
  dispatchMeshCommand: this.deps.dispatchMeshCommand,
46328
+ getMeshPeerConnectionStatus: this.deps.getMeshPeerConnectionStatus,
46296
46329
  statusInstanceId: this.deps.statusInstanceId,
46297
46330
  localMachineId: loadConfig().machineId || "",
46298
46331
  probeRemotePeers
@@ -47875,6 +47908,7 @@ ${ptyResult.output.slice(-2e3)}`);
47875
47908
  mesh,
47876
47909
  meshSource: meshRecord.source,
47877
47910
  dispatchMeshCommand: this.deps.dispatchMeshCommand,
47911
+ getMeshPeerConnectionStatus: this.deps.getMeshPeerConnectionStatus,
47878
47912
  statusInstanceId: this.deps.statusInstanceId,
47879
47913
  localMachineId,
47880
47914
  // Standing-state model: only an explicit refresh fans
@@ -48041,52 +48075,28 @@ ${ptyResult.output.slice(-2e3)}`);
48041
48075
  }
48042
48076
  remoteProbeApplied = true;
48043
48077
  } else if (refreshRequested && !isSelfNode && daemonId && this.deps.dispatchMeshCommand && !directTruthUnavailableNodeIds.has(nodeId)) {
48044
- try {
48045
- const remoteGit = await probeRemoteMeshGitStatus({
48046
- dispatchMeshCommand: this.deps.dispatchMeshCommand,
48047
- daemonId,
48048
- workspace,
48049
- timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS
48050
- });
48051
- if (remoteGit) {
48052
- status.git = remoteGit;
48053
- status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48054
- const connection = readObjectRecord(status.connection);
48055
- const connectionState = readStringValue(connection.state);
48056
- const connectionReported = readBooleanValue(connection.reported) ?? false;
48057
- if (!connectionReported || connectionState === "unknown") {
48058
- status.connection = buildLivePeerGitConnection(connection, refreshedAt);
48059
- }
48060
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48061
- remoteProbeApplied = true;
48078
+ const remoteGit = await probeRemoteMeshGitStatusWithRetry({
48079
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48080
+ daemonId,
48081
+ workspace,
48082
+ timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS,
48083
+ retryTimeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS,
48084
+ getConnection: this.deps.getMeshPeerConnectionStatus,
48085
+ onConnection: (connection) => {
48086
+ status.connection = connection;
48062
48087
  }
48063
- } catch {
48064
- const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
48065
- const refreshedConnectionState = readStringValue(refreshedConnection?.state);
48066
- if (refreshedConnection && refreshedConnectionState === "connected") {
48067
- status.connection = refreshedConnection;
48068
- try {
48069
- const remoteGit = await probeRemoteMeshGitStatus({
48070
- dispatchMeshCommand: this.deps.dispatchMeshCommand,
48071
- daemonId,
48072
- workspace,
48073
- timeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS
48074
- });
48075
- if (remoteGit) {
48076
- status.git = remoteGit;
48077
- status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48078
- const connection = readObjectRecord(status.connection);
48079
- const connectionState = readStringValue(connection.state);
48080
- const connectionReported = readBooleanValue(connection.reported) ?? false;
48081
- if (!connectionReported || connectionState === "unknown") {
48082
- status.connection = buildLivePeerGitConnection(connection, refreshedAt);
48083
- }
48084
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48085
- remoteProbeApplied = true;
48086
- }
48087
- } catch {
48088
- }
48088
+ });
48089
+ if (remoteGit) {
48090
+ status.git = remoteGit;
48091
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48092
+ const connection = readObjectRecord(status.connection);
48093
+ const connectionState = readStringValue(connection.state);
48094
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
48095
+ if (!connectionReported || connectionState === "unknown") {
48096
+ status.connection = buildLivePeerGitConnection(connection, refreshedAt);
48089
48097
  }
48098
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48099
+ remoteProbeApplied = true;
48090
48100
  }
48091
48101
  }
48092
48102
  if (!remoteProbeApplied) {
@@ -48155,7 +48165,7 @@ ${ptyResult.output.slice(-2e3)}`);
48155
48165
  liveSessionRecords: liveMeshSessions
48156
48166
  });
48157
48167
  const { getMeshStatusMissionSummaries: getMeshStatusMissionSummaries2 } = await Promise.resolve().then(() => (init_mesh_missions(), mesh_missions_exports));
48158
- const missions = getMeshStatusMissionSummaries2(meshId, { verbose: verboseMissions });
48168
+ const missions = getMeshStatusMissionSummaries2(meshId, { verbose: verboseMissions, withStats: true });
48159
48169
  const statusResult = {
48160
48170
  success: true,
48161
48171
  meshId: mesh.id,