@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.js CHANGED
@@ -295,10 +295,10 @@ function readInjected(value) {
295
295
  }
296
296
  function getDaemonBuildInfo() {
297
297
  if (cached) return cached;
298
- const commit = readInjected(true ? "6103da081f92baaf891d3410e3d7ebc36d9e300d" : void 0) ?? "unknown";
299
- const commitShort = readInjected(true ? "6103da08" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
300
- const version = readInjected(true ? "0.9.82-rc.305" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
301
- const builtAt = readInjected(true ? "2026-06-17T06:08:13.151Z" : void 0);
298
+ const commit = readInjected(true ? "6ded896662908225a48ad662b6eec83267dbe9ba" : void 0) ?? "unknown";
299
+ const commitShort = readInjected(true ? "6ded8966" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
300
+ const version = readInjected(true ? "0.9.82-rc.306" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
301
+ const builtAt = readInjected(true ? "2026-06-17T07:21:37.675Z" : void 0);
302
302
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
303
303
  return cached;
304
304
  }
@@ -4535,6 +4535,110 @@ var init_mesh_runtime_store = __esm({
4535
4535
  }
4536
4536
  });
4537
4537
 
4538
+ // src/mesh/mesh-task-stats.ts
4539
+ function readPayloadTaskId(entry) {
4540
+ const value = entry.payload?.taskId;
4541
+ return typeof value === "string" && value.trim() ? value.trim() : "";
4542
+ }
4543
+ function parseTime(value) {
4544
+ if (!value) return null;
4545
+ const parsed = new Date(value).getTime();
4546
+ return Number.isFinite(parsed) ? parsed : null;
4547
+ }
4548
+ function computeMeshTaskStats(meshId, opts) {
4549
+ const queue = getQueue(meshId);
4550
+ const queueById = new Map(queue.map((task) => [task.id, task]));
4551
+ let targetIds;
4552
+ if (opts?.taskIds?.length) {
4553
+ targetIds = [...new Set(opts.taskIds)];
4554
+ } else if (opts?.missionId) {
4555
+ targetIds = queue.filter((task) => task.missionId === opts.missionId).map((task) => task.id);
4556
+ } else {
4557
+ targetIds = queue.map((task) => task.id);
4558
+ }
4559
+ if (targetIds.length === 0) return [];
4560
+ const targetSet = new Set(targetIds);
4561
+ const entries = readLedgerEntries(meshId, { tail: opts?.tail ?? 1e3 });
4562
+ const dispatches = /* @__PURE__ */ new Map();
4563
+ const terminals = /* @__PURE__ */ new Map();
4564
+ for (const entry of entries) {
4565
+ const taskId = readPayloadTaskId(entry);
4566
+ if (!taskId || !targetSet.has(taskId)) continue;
4567
+ if (entry.kind === "task_dispatched") {
4568
+ const existing = dispatches.get(taskId);
4569
+ if (existing) existing.count += 1;
4570
+ else dispatches.set(taskId, { first: entry.timestamp, count: 1 });
4571
+ } else if (entry.kind === "task_completed" || entry.kind === "task_failed") {
4572
+ terminals.set(taskId, { at: entry.timestamp, kind: entry.kind });
4573
+ }
4574
+ }
4575
+ return targetIds.map((taskId) => {
4576
+ const queueEntry = queueById.get(taskId);
4577
+ const status = queueEntry?.status ?? "unknown";
4578
+ const dispatch = dispatches.get(taskId);
4579
+ const terminal = terminals.get(taskId);
4580
+ const isTerminalStatus = status === "completed" || status === "failed" || status === "cancelled";
4581
+ const dispatchTime = parseTime(dispatch?.first ?? queueEntry?.dispatchTimestamp);
4582
+ const terminalTime = parseTime(terminal?.at);
4583
+ const stats = {
4584
+ taskId,
4585
+ status,
4586
+ dispatchedAt: dispatch?.first ?? queueEntry?.dispatchTimestamp ?? null,
4587
+ terminalAt: terminal?.at ?? null,
4588
+ terminalKind: terminal?.kind ?? null,
4589
+ durationMs: null,
4590
+ dispatchCount: dispatch?.count ?? 0,
4591
+ requeueCount: queueEntry?.requeueCount ?? 0
4592
+ };
4593
+ if (dispatchTime !== null && terminalTime !== null && terminalTime >= dispatchTime) {
4594
+ stats.durationMs = terminalTime - dispatchTime;
4595
+ } else if (isTerminalStatus) {
4596
+ stats.incompleteEvidence = true;
4597
+ }
4598
+ return stats;
4599
+ });
4600
+ }
4601
+ function computeMeshMissionStats(meshId, missionId) {
4602
+ const tasks = computeMeshTaskStats(meshId, { missionId });
4603
+ const stats = {
4604
+ missionId,
4605
+ taskCount: tasks.length,
4606
+ completed: 0,
4607
+ failed: 0,
4608
+ totalDurationMs: 0,
4609
+ wallClockMs: null,
4610
+ retries: 0,
4611
+ incompleteTaskIds: []
4612
+ };
4613
+ let firstDispatch = null;
4614
+ let lastTerminal = null;
4615
+ for (const task of tasks) {
4616
+ if (task.status === "completed") stats.completed += 1;
4617
+ else if (task.status === "failed") stats.failed += 1;
4618
+ stats.retries += task.requeueCount;
4619
+ if (task.incompleteEvidence) {
4620
+ stats.incompleteTaskIds.push(task.taskId);
4621
+ continue;
4622
+ }
4623
+ if (task.durationMs !== null) stats.totalDurationMs += task.durationMs;
4624
+ const dispatchTime = parseTime(task.dispatchedAt);
4625
+ const terminalTime = parseTime(task.terminalAt);
4626
+ if (dispatchTime !== null && (firstDispatch === null || dispatchTime < firstDispatch)) firstDispatch = dispatchTime;
4627
+ if (terminalTime !== null && (lastTerminal === null || terminalTime > lastTerminal)) lastTerminal = terminalTime;
4628
+ }
4629
+ if (firstDispatch !== null && lastTerminal !== null && lastTerminal >= firstDispatch) {
4630
+ stats.wallClockMs = lastTerminal - firstDispatch;
4631
+ }
4632
+ return stats;
4633
+ }
4634
+ var init_mesh_task_stats = __esm({
4635
+ "src/mesh/mesh-task-stats.ts"() {
4636
+ "use strict";
4637
+ init_mesh_ledger();
4638
+ init_mesh_work_queue();
4639
+ }
4640
+ });
4641
+
4538
4642
  // src/mesh/mesh-missions.ts
4539
4643
  var mesh_missions_exports = {};
4540
4644
  __export(mesh_missions_exports, {
@@ -4626,7 +4730,10 @@ function getMeshStatusMissionSummaries(meshId, options) {
4626
4730
  const all = getMeshMissions(meshId);
4627
4731
  const live = all.filter((m) => m.status === "active" || m.status === "paused");
4628
4732
  const history = all.filter((m) => m.status === "completed" || m.status === "abandoned").sort((a, b) => (b.updatedAt || "").localeCompare(a.updatedAt || "")).slice(0, historyLimit);
4629
- const full = [...live, ...history].map((mission) => summarizeMeshMission(meshId, mission));
4733
+ let full = [...live, ...history].map((mission) => summarizeMeshMission(meshId, mission));
4734
+ if (options?.withStats) {
4735
+ full = full.map((summary) => ({ ...summary, stats: computeMeshMissionStats(meshId, summary.id) }));
4736
+ }
4630
4737
  return options?.verbose ? full : full.map(slimMissionSummary);
4631
4738
  }
4632
4739
  function listMeshMissionSummaries(meshId, options) {
@@ -4660,6 +4767,7 @@ var init_mesh_missions = __esm({
4660
4767
  import_crypto6 = require("crypto");
4661
4768
  init_mesh_runtime_store();
4662
4769
  init_mesh_work_queue();
4770
+ init_mesh_task_stats();
4663
4771
  MESH_MISSION_STATUSES = ["active", "paused", "completed", "abandoned"];
4664
4772
  GOAL_PREVIEW_MAX = 120;
4665
4773
  }
@@ -17347,107 +17455,7 @@ function getSavedProviderSessions(state, filters) {
17347
17455
  init_mesh_config();
17348
17456
  init_coordinator_prompt();
17349
17457
  init_mesh_missions();
17350
-
17351
- // src/mesh/mesh-task-stats.ts
17352
- init_mesh_ledger();
17353
- init_mesh_work_queue();
17354
- function readPayloadTaskId(entry) {
17355
- const value = entry.payload?.taskId;
17356
- return typeof value === "string" && value.trim() ? value.trim() : "";
17357
- }
17358
- function parseTime(value) {
17359
- if (!value) return null;
17360
- const parsed = new Date(value).getTime();
17361
- return Number.isFinite(parsed) ? parsed : null;
17362
- }
17363
- function computeMeshTaskStats(meshId, opts) {
17364
- const queue = getQueue(meshId);
17365
- const queueById = new Map(queue.map((task) => [task.id, task]));
17366
- let targetIds;
17367
- if (opts?.taskIds?.length) {
17368
- targetIds = [...new Set(opts.taskIds)];
17369
- } else if (opts?.missionId) {
17370
- targetIds = queue.filter((task) => task.missionId === opts.missionId).map((task) => task.id);
17371
- } else {
17372
- targetIds = queue.map((task) => task.id);
17373
- }
17374
- if (targetIds.length === 0) return [];
17375
- const targetSet = new Set(targetIds);
17376
- const entries = readLedgerEntries(meshId, { tail: opts?.tail ?? 1e3 });
17377
- const dispatches = /* @__PURE__ */ new Map();
17378
- const terminals = /* @__PURE__ */ new Map();
17379
- for (const entry of entries) {
17380
- const taskId = readPayloadTaskId(entry);
17381
- if (!taskId || !targetSet.has(taskId)) continue;
17382
- if (entry.kind === "task_dispatched") {
17383
- const existing = dispatches.get(taskId);
17384
- if (existing) existing.count += 1;
17385
- else dispatches.set(taskId, { first: entry.timestamp, count: 1 });
17386
- } else if (entry.kind === "task_completed" || entry.kind === "task_failed") {
17387
- terminals.set(taskId, { at: entry.timestamp, kind: entry.kind });
17388
- }
17389
- }
17390
- return targetIds.map((taskId) => {
17391
- const queueEntry = queueById.get(taskId);
17392
- const status = queueEntry?.status ?? "unknown";
17393
- const dispatch = dispatches.get(taskId);
17394
- const terminal = terminals.get(taskId);
17395
- const isTerminalStatus = status === "completed" || status === "failed" || status === "cancelled";
17396
- const dispatchTime = parseTime(dispatch?.first ?? queueEntry?.dispatchTimestamp);
17397
- const terminalTime = parseTime(terminal?.at);
17398
- const stats = {
17399
- taskId,
17400
- status,
17401
- dispatchedAt: dispatch?.first ?? queueEntry?.dispatchTimestamp ?? null,
17402
- terminalAt: terminal?.at ?? null,
17403
- terminalKind: terminal?.kind ?? null,
17404
- durationMs: null,
17405
- dispatchCount: dispatch?.count ?? 0,
17406
- requeueCount: queueEntry?.requeueCount ?? 0
17407
- };
17408
- if (dispatchTime !== null && terminalTime !== null && terminalTime >= dispatchTime) {
17409
- stats.durationMs = terminalTime - dispatchTime;
17410
- } else if (isTerminalStatus) {
17411
- stats.incompleteEvidence = true;
17412
- }
17413
- return stats;
17414
- });
17415
- }
17416
- function computeMeshMissionStats(meshId, missionId) {
17417
- const tasks = computeMeshTaskStats(meshId, { missionId });
17418
- const stats = {
17419
- missionId,
17420
- taskCount: tasks.length,
17421
- completed: 0,
17422
- failed: 0,
17423
- totalDurationMs: 0,
17424
- wallClockMs: null,
17425
- retries: 0,
17426
- incompleteTaskIds: []
17427
- };
17428
- let firstDispatch = null;
17429
- let lastTerminal = null;
17430
- for (const task of tasks) {
17431
- if (task.status === "completed") stats.completed += 1;
17432
- else if (task.status === "failed") stats.failed += 1;
17433
- stats.retries += task.requeueCount;
17434
- if (task.incompleteEvidence) {
17435
- stats.incompleteTaskIds.push(task.taskId);
17436
- continue;
17437
- }
17438
- if (task.durationMs !== null) stats.totalDurationMs += task.durationMs;
17439
- const dispatchTime = parseTime(task.dispatchedAt);
17440
- const terminalTime = parseTime(task.terminalAt);
17441
- if (dispatchTime !== null && (firstDispatch === null || dispatchTime < firstDispatch)) firstDispatch = dispatchTime;
17442
- if (terminalTime !== null && (lastTerminal === null || terminalTime > lastTerminal)) lastTerminal = terminalTime;
17443
- }
17444
- if (firstDispatch !== null && lastTerminal !== null && lastTerminal >= firstDispatch) {
17445
- stats.wallClockMs = lastTerminal - firstDispatch;
17446
- }
17447
- return stats;
17448
- }
17449
-
17450
- // src/index.ts
17458
+ init_mesh_task_stats();
17451
17459
  init_mesh_review_inbox();
17452
17460
 
17453
17461
  // src/mesh/coordinator-registry.ts
@@ -42343,6 +42351,31 @@ async function probeRemoteMeshGitStatus(args) {
42343
42351
  const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
42344
42352
  return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
42345
42353
  }
42354
+ var MESH_DIRECT_PROBE_MAX_RETRIES = 2;
42355
+ function readMeshConnectionState(connection) {
42356
+ return readStringValue(connection?.state);
42357
+ }
42358
+ async function probeRemoteMeshGitStatusWithRetry(args) {
42359
+ for (let attempt = 0; attempt <= MESH_DIRECT_PROBE_MAX_RETRIES; attempt += 1) {
42360
+ if (attempt > 0) {
42361
+ const connection = args.getConnection?.(args.daemonId);
42362
+ if (args.getConnection && readMeshConnectionState(connection) !== "connected") break;
42363
+ if (connection) args.onConnection?.(connection);
42364
+ await new Promise((resolve24) => setTimeout(resolve24, 250 * 2 ** (attempt - 1)));
42365
+ }
42366
+ try {
42367
+ const remoteGit = await probeRemoteMeshGitStatus({
42368
+ dispatchMeshCommand: args.dispatchMeshCommand,
42369
+ daemonId: args.daemonId,
42370
+ workspace: args.workspace,
42371
+ timeoutMs: attempt === 0 ? args.timeoutMs : args.retryTimeoutMs ?? args.timeoutMs
42372
+ });
42373
+ if (remoteGit) return remoteGit;
42374
+ } catch {
42375
+ }
42376
+ }
42377
+ return null;
42378
+ }
42346
42379
  async function hydrateInlineMeshDirectTruth(args) {
42347
42380
  const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
42348
42381
  if (!nodes.length) {
@@ -42402,19 +42435,18 @@ async function hydrateInlineMeshDirectTruth(args) {
42402
42435
  continue;
42403
42436
  }
42404
42437
  peerAttemptedCount += 1;
42405
- try {
42406
- const remoteGit = await probeRemoteMeshGitStatus({
42407
- dispatchMeshCommand: args.dispatchMeshCommand,
42408
- daemonId,
42409
- workspace,
42410
- timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS
42411
- });
42412
- if (remoteGit) {
42413
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
42414
- peerConfirmedCount += 1;
42415
- continue;
42416
- }
42417
- } catch {
42438
+ const remoteGit = await probeRemoteMeshGitStatusWithRetry({
42439
+ dispatchMeshCommand: args.dispatchMeshCommand,
42440
+ daemonId,
42441
+ workspace,
42442
+ timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS,
42443
+ retryTimeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS,
42444
+ getConnection: args.getMeshPeerConnectionStatus
42445
+ });
42446
+ if (remoteGit) {
42447
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
42448
+ peerConfirmedCount += 1;
42449
+ continue;
42418
42450
  }
42419
42451
  unavailableNodeIds.push(nodeId);
42420
42452
  }
@@ -46632,6 +46664,7 @@ ${hintLines.join("\n")}` : "",
46632
46664
  mesh: meshRecord.mesh,
46633
46665
  meshSource: meshRecord.source,
46634
46666
  dispatchMeshCommand: this.deps.dispatchMeshCommand,
46667
+ getMeshPeerConnectionStatus: this.deps.getMeshPeerConnectionStatus,
46635
46668
  statusInstanceId: this.deps.statusInstanceId,
46636
46669
  localMachineId: loadConfig().machineId || "",
46637
46670
  probeRemotePeers
@@ -48214,6 +48247,7 @@ ${ptyResult.output.slice(-2e3)}`);
48214
48247
  mesh,
48215
48248
  meshSource: meshRecord.source,
48216
48249
  dispatchMeshCommand: this.deps.dispatchMeshCommand,
48250
+ getMeshPeerConnectionStatus: this.deps.getMeshPeerConnectionStatus,
48217
48251
  statusInstanceId: this.deps.statusInstanceId,
48218
48252
  localMachineId,
48219
48253
  // Standing-state model: only an explicit refresh fans
@@ -48380,52 +48414,28 @@ ${ptyResult.output.slice(-2e3)}`);
48380
48414
  }
48381
48415
  remoteProbeApplied = true;
48382
48416
  } else if (refreshRequested && !isSelfNode && daemonId && this.deps.dispatchMeshCommand && !directTruthUnavailableNodeIds.has(nodeId)) {
48383
- try {
48384
- const remoteGit = await probeRemoteMeshGitStatus({
48385
- dispatchMeshCommand: this.deps.dispatchMeshCommand,
48386
- daemonId,
48387
- workspace,
48388
- timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS
48389
- });
48390
- if (remoteGit) {
48391
- status.git = remoteGit;
48392
- status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48393
- const connection = readObjectRecord(status.connection);
48394
- const connectionState = readStringValue(connection.state);
48395
- const connectionReported = readBooleanValue(connection.reported) ?? false;
48396
- if (!connectionReported || connectionState === "unknown") {
48397
- status.connection = buildLivePeerGitConnection(connection, refreshedAt);
48398
- }
48399
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48400
- remoteProbeApplied = true;
48417
+ const remoteGit = await probeRemoteMeshGitStatusWithRetry({
48418
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48419
+ daemonId,
48420
+ workspace,
48421
+ timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS,
48422
+ retryTimeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS,
48423
+ getConnection: this.deps.getMeshPeerConnectionStatus,
48424
+ onConnection: (connection) => {
48425
+ status.connection = connection;
48401
48426
  }
48402
- } catch {
48403
- const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
48404
- const refreshedConnectionState = readStringValue(refreshedConnection?.state);
48405
- if (refreshedConnection && refreshedConnectionState === "connected") {
48406
- status.connection = refreshedConnection;
48407
- try {
48408
- const remoteGit = await probeRemoteMeshGitStatus({
48409
- dispatchMeshCommand: this.deps.dispatchMeshCommand,
48410
- daemonId,
48411
- workspace,
48412
- timeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS
48413
- });
48414
- if (remoteGit) {
48415
- status.git = remoteGit;
48416
- status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48417
- const connection = readObjectRecord(status.connection);
48418
- const connectionState = readStringValue(connection.state);
48419
- const connectionReported = readBooleanValue(connection.reported) ?? false;
48420
- if (!connectionReported || connectionState === "unknown") {
48421
- status.connection = buildLivePeerGitConnection(connection, refreshedAt);
48422
- }
48423
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48424
- remoteProbeApplied = true;
48425
- }
48426
- } catch {
48427
- }
48427
+ });
48428
+ if (remoteGit) {
48429
+ status.git = remoteGit;
48430
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48431
+ const connection = readObjectRecord(status.connection);
48432
+ const connectionState = readStringValue(connection.state);
48433
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
48434
+ if (!connectionReported || connectionState === "unknown") {
48435
+ status.connection = buildLivePeerGitConnection(connection, refreshedAt);
48428
48436
  }
48437
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48438
+ remoteProbeApplied = true;
48429
48439
  }
48430
48440
  }
48431
48441
  if (!remoteProbeApplied) {
@@ -48494,7 +48504,7 @@ ${ptyResult.output.slice(-2e3)}`);
48494
48504
  liveSessionRecords: liveMeshSessions
48495
48505
  });
48496
48506
  const { getMeshStatusMissionSummaries: getMeshStatusMissionSummaries2 } = await Promise.resolve().then(() => (init_mesh_missions(), mesh_missions_exports));
48497
- const missions = getMeshStatusMissionSummaries2(meshId, { verbose: verboseMissions });
48507
+ const missions = getMeshStatusMissionSummaries2(meshId, { verbose: verboseMissions, withStats: true });
48498
48508
  const statusResult = {
48499
48509
  success: true,
48500
48510
  meshId: mesh.id,