@adhdev/daemon-standalone 0.9.82-rc.305 → 0.9.82-rc.308

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
@@ -30004,10 +30004,10 @@ var require_dist3 = __commonJS({
30004
30004
  }
30005
30005
  function getDaemonBuildInfo() {
30006
30006
  if (cached2) return cached2;
30007
- const commit = readInjected(true ? "6103da081f92baaf891d3410e3d7ebc36d9e300d" : void 0) ?? "unknown";
30008
- const commitShort = readInjected(true ? "6103da08" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30009
- const version2 = readInjected(true ? "0.9.82-rc.305" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30010
- const builtAt = readInjected(true ? "2026-06-17T06:08:38.971Z" : void 0);
30007
+ const commit = readInjected(true ? "b435468bd803949fd743c1479ae440680a73e372" : void 0) ?? "unknown";
30008
+ const commitShort = readInjected(true ? "b435468b" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30009
+ const version2 = readInjected(true ? "0.9.82-rc.308" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30010
+ const builtAt = readInjected(true ? "2026-06-17T08:19:25.919Z" : void 0);
30011
30011
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30012
30012
  return cached2;
30013
30013
  }
@@ -34279,6 +34279,108 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
34279
34279
  };
34280
34280
  }
34281
34281
  });
34282
+ function readPayloadTaskId(entry) {
34283
+ const value = entry.payload?.taskId;
34284
+ return typeof value === "string" && value.trim() ? value.trim() : "";
34285
+ }
34286
+ function parseTime(value) {
34287
+ if (!value) return null;
34288
+ const parsed = new Date(value).getTime();
34289
+ return Number.isFinite(parsed) ? parsed : null;
34290
+ }
34291
+ function computeMeshTaskStats(meshId, opts) {
34292
+ const queue = getQueue(meshId);
34293
+ const queueById = new Map(queue.map((task) => [task.id, task]));
34294
+ let targetIds;
34295
+ if (opts?.taskIds?.length) {
34296
+ targetIds = [...new Set(opts.taskIds)];
34297
+ } else if (opts?.missionId) {
34298
+ targetIds = queue.filter((task) => task.missionId === opts.missionId).map((task) => task.id);
34299
+ } else {
34300
+ targetIds = queue.map((task) => task.id);
34301
+ }
34302
+ if (targetIds.length === 0) return [];
34303
+ const targetSet = new Set(targetIds);
34304
+ const entries = readLedgerEntries(meshId, { tail: opts?.tail ?? 1e3 });
34305
+ const dispatches = /* @__PURE__ */ new Map();
34306
+ const terminals = /* @__PURE__ */ new Map();
34307
+ for (const entry of entries) {
34308
+ const taskId = readPayloadTaskId(entry);
34309
+ if (!taskId || !targetSet.has(taskId)) continue;
34310
+ if (entry.kind === "task_dispatched") {
34311
+ const existing = dispatches.get(taskId);
34312
+ if (existing) existing.count += 1;
34313
+ else dispatches.set(taskId, { first: entry.timestamp, count: 1 });
34314
+ } else if (entry.kind === "task_completed" || entry.kind === "task_failed") {
34315
+ terminals.set(taskId, { at: entry.timestamp, kind: entry.kind });
34316
+ }
34317
+ }
34318
+ return targetIds.map((taskId) => {
34319
+ const queueEntry = queueById.get(taskId);
34320
+ const status = queueEntry?.status ?? "unknown";
34321
+ const dispatch = dispatches.get(taskId);
34322
+ const terminal = terminals.get(taskId);
34323
+ const isTerminalStatus = status === "completed" || status === "failed" || status === "cancelled";
34324
+ const dispatchTime = parseTime(dispatch?.first ?? queueEntry?.dispatchTimestamp);
34325
+ const terminalTime = parseTime(terminal?.at);
34326
+ const stats = {
34327
+ taskId,
34328
+ status,
34329
+ dispatchedAt: dispatch?.first ?? queueEntry?.dispatchTimestamp ?? null,
34330
+ terminalAt: terminal?.at ?? null,
34331
+ terminalKind: terminal?.kind ?? null,
34332
+ durationMs: null,
34333
+ dispatchCount: dispatch?.count ?? 0,
34334
+ requeueCount: queueEntry?.requeueCount ?? 0
34335
+ };
34336
+ if (dispatchTime !== null && terminalTime !== null && terminalTime >= dispatchTime) {
34337
+ stats.durationMs = terminalTime - dispatchTime;
34338
+ } else if (isTerminalStatus) {
34339
+ stats.incompleteEvidence = true;
34340
+ }
34341
+ return stats;
34342
+ });
34343
+ }
34344
+ function computeMeshMissionStats(meshId, missionId) {
34345
+ const tasks = computeMeshTaskStats(meshId, { missionId });
34346
+ const stats = {
34347
+ missionId,
34348
+ taskCount: tasks.length,
34349
+ completed: 0,
34350
+ failed: 0,
34351
+ totalDurationMs: 0,
34352
+ wallClockMs: null,
34353
+ retries: 0,
34354
+ incompleteTaskIds: []
34355
+ };
34356
+ let firstDispatch = null;
34357
+ let lastTerminal = null;
34358
+ for (const task of tasks) {
34359
+ if (task.status === "completed") stats.completed += 1;
34360
+ else if (task.status === "failed") stats.failed += 1;
34361
+ stats.retries += task.requeueCount;
34362
+ if (task.incompleteEvidence) {
34363
+ stats.incompleteTaskIds.push(task.taskId);
34364
+ continue;
34365
+ }
34366
+ if (task.durationMs !== null) stats.totalDurationMs += task.durationMs;
34367
+ const dispatchTime = parseTime(task.dispatchedAt);
34368
+ const terminalTime = parseTime(task.terminalAt);
34369
+ if (dispatchTime !== null && (firstDispatch === null || dispatchTime < firstDispatch)) firstDispatch = dispatchTime;
34370
+ if (terminalTime !== null && (lastTerminal === null || terminalTime > lastTerminal)) lastTerminal = terminalTime;
34371
+ }
34372
+ if (firstDispatch !== null && lastTerminal !== null && lastTerminal >= firstDispatch) {
34373
+ stats.wallClockMs = lastTerminal - firstDispatch;
34374
+ }
34375
+ return stats;
34376
+ }
34377
+ var init_mesh_task_stats = __esm2({
34378
+ "src/mesh/mesh-task-stats.ts"() {
34379
+ "use strict";
34380
+ init_mesh_ledger();
34381
+ init_mesh_work_queue();
34382
+ }
34383
+ });
34282
34384
  var mesh_missions_exports = {};
34283
34385
  __export2(mesh_missions_exports, {
34284
34386
  GOAL_PREVIEW_MAX: () => GOAL_PREVIEW_MAX,
@@ -34369,7 +34471,10 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
34369
34471
  const all = getMeshMissions(meshId);
34370
34472
  const live = all.filter((m) => m.status === "active" || m.status === "paused");
34371
34473
  const history = all.filter((m) => m.status === "completed" || m.status === "abandoned").sort((a, b) => (b.updatedAt || "").localeCompare(a.updatedAt || "")).slice(0, historyLimit);
34372
- const full = [...live, ...history].map((mission) => summarizeMeshMission(meshId, mission));
34474
+ let full = [...live, ...history].map((mission) => summarizeMeshMission(meshId, mission));
34475
+ if (options?.withStats) {
34476
+ full = full.map((summary) => ({ ...summary, stats: computeMeshMissionStats(meshId, summary.id) }));
34477
+ }
34373
34478
  return options?.verbose ? full : full.map(slimMissionSummary);
34374
34479
  }
34375
34480
  function listMeshMissionSummaries(meshId, options) {
@@ -34405,6 +34510,7 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
34405
34510
  import_crypto6 = require("crypto");
34406
34511
  init_mesh_runtime_store();
34407
34512
  init_mesh_work_queue();
34513
+ init_mesh_task_stats();
34408
34514
  MESH_MISSION_STATUSES = ["active", "paused", "completed", "abandoned"];
34409
34515
  GOAL_PREVIEW_MAX = 120;
34410
34516
  }
@@ -47087,103 +47193,7 @@ ${lastSnapshot}`;
47087
47193
  init_mesh_config();
47088
47194
  init_coordinator_prompt();
47089
47195
  init_mesh_missions();
47090
- init_mesh_ledger();
47091
- init_mesh_work_queue();
47092
- function readPayloadTaskId(entry) {
47093
- const value = entry.payload?.taskId;
47094
- return typeof value === "string" && value.trim() ? value.trim() : "";
47095
- }
47096
- function parseTime(value) {
47097
- if (!value) return null;
47098
- const parsed = new Date(value).getTime();
47099
- return Number.isFinite(parsed) ? parsed : null;
47100
- }
47101
- function computeMeshTaskStats(meshId, opts) {
47102
- const queue = getQueue(meshId);
47103
- const queueById = new Map(queue.map((task) => [task.id, task]));
47104
- let targetIds;
47105
- if (opts?.taskIds?.length) {
47106
- targetIds = [...new Set(opts.taskIds)];
47107
- } else if (opts?.missionId) {
47108
- targetIds = queue.filter((task) => task.missionId === opts.missionId).map((task) => task.id);
47109
- } else {
47110
- targetIds = queue.map((task) => task.id);
47111
- }
47112
- if (targetIds.length === 0) return [];
47113
- const targetSet = new Set(targetIds);
47114
- const entries = readLedgerEntries(meshId, { tail: opts?.tail ?? 1e3 });
47115
- const dispatches = /* @__PURE__ */ new Map();
47116
- const terminals = /* @__PURE__ */ new Map();
47117
- for (const entry of entries) {
47118
- const taskId = readPayloadTaskId(entry);
47119
- if (!taskId || !targetSet.has(taskId)) continue;
47120
- if (entry.kind === "task_dispatched") {
47121
- const existing = dispatches.get(taskId);
47122
- if (existing) existing.count += 1;
47123
- else dispatches.set(taskId, { first: entry.timestamp, count: 1 });
47124
- } else if (entry.kind === "task_completed" || entry.kind === "task_failed") {
47125
- terminals.set(taskId, { at: entry.timestamp, kind: entry.kind });
47126
- }
47127
- }
47128
- return targetIds.map((taskId) => {
47129
- const queueEntry = queueById.get(taskId);
47130
- const status = queueEntry?.status ?? "unknown";
47131
- const dispatch = dispatches.get(taskId);
47132
- const terminal = terminals.get(taskId);
47133
- const isTerminalStatus = status === "completed" || status === "failed" || status === "cancelled";
47134
- const dispatchTime = parseTime(dispatch?.first ?? queueEntry?.dispatchTimestamp);
47135
- const terminalTime = parseTime(terminal?.at);
47136
- const stats = {
47137
- taskId,
47138
- status,
47139
- dispatchedAt: dispatch?.first ?? queueEntry?.dispatchTimestamp ?? null,
47140
- terminalAt: terminal?.at ?? null,
47141
- terminalKind: terminal?.kind ?? null,
47142
- durationMs: null,
47143
- dispatchCount: dispatch?.count ?? 0,
47144
- requeueCount: queueEntry?.requeueCount ?? 0
47145
- };
47146
- if (dispatchTime !== null && terminalTime !== null && terminalTime >= dispatchTime) {
47147
- stats.durationMs = terminalTime - dispatchTime;
47148
- } else if (isTerminalStatus) {
47149
- stats.incompleteEvidence = true;
47150
- }
47151
- return stats;
47152
- });
47153
- }
47154
- function computeMeshMissionStats(meshId, missionId) {
47155
- const tasks = computeMeshTaskStats(meshId, { missionId });
47156
- const stats = {
47157
- missionId,
47158
- taskCount: tasks.length,
47159
- completed: 0,
47160
- failed: 0,
47161
- totalDurationMs: 0,
47162
- wallClockMs: null,
47163
- retries: 0,
47164
- incompleteTaskIds: []
47165
- };
47166
- let firstDispatch = null;
47167
- let lastTerminal = null;
47168
- for (const task of tasks) {
47169
- if (task.status === "completed") stats.completed += 1;
47170
- else if (task.status === "failed") stats.failed += 1;
47171
- stats.retries += task.requeueCount;
47172
- if (task.incompleteEvidence) {
47173
- stats.incompleteTaskIds.push(task.taskId);
47174
- continue;
47175
- }
47176
- if (task.durationMs !== null) stats.totalDurationMs += task.durationMs;
47177
- const dispatchTime = parseTime(task.dispatchedAt);
47178
- const terminalTime = parseTime(task.terminalAt);
47179
- if (dispatchTime !== null && (firstDispatch === null || dispatchTime < firstDispatch)) firstDispatch = dispatchTime;
47180
- if (terminalTime !== null && (lastTerminal === null || terminalTime > lastTerminal)) lastTerminal = terminalTime;
47181
- }
47182
- if (firstDispatch !== null && lastTerminal !== null && lastTerminal >= firstDispatch) {
47183
- stats.wallClockMs = lastTerminal - firstDispatch;
47184
- }
47185
- return stats;
47186
- }
47196
+ init_mesh_task_stats();
47187
47197
  init_mesh_review_inbox();
47188
47198
  var import_path5 = require("path");
47189
47199
  var import_fs5 = require("fs");
@@ -71881,6 +71891,31 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
71881
71891
  const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
71882
71892
  return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
71883
71893
  }
71894
+ var MESH_DIRECT_PROBE_MAX_RETRIES = 2;
71895
+ function readMeshConnectionState(connection) {
71896
+ return readStringValue(connection?.state);
71897
+ }
71898
+ async function probeRemoteMeshGitStatusWithRetry(args) {
71899
+ for (let attempt = 0; attempt <= MESH_DIRECT_PROBE_MAX_RETRIES; attempt += 1) {
71900
+ if (attempt > 0) {
71901
+ const connection = args.getConnection?.(args.daemonId);
71902
+ if (args.getConnection && readMeshConnectionState(connection) !== "connected") break;
71903
+ if (connection) args.onConnection?.(connection);
71904
+ await new Promise((resolve24) => setTimeout(resolve24, 250 * 2 ** (attempt - 1)));
71905
+ }
71906
+ try {
71907
+ const remoteGit = await probeRemoteMeshGitStatus({
71908
+ dispatchMeshCommand: args.dispatchMeshCommand,
71909
+ daemonId: args.daemonId,
71910
+ workspace: args.workspace,
71911
+ timeoutMs: attempt === 0 ? args.timeoutMs : args.retryTimeoutMs ?? args.timeoutMs
71912
+ });
71913
+ if (remoteGit) return remoteGit;
71914
+ } catch {
71915
+ }
71916
+ }
71917
+ return null;
71918
+ }
71884
71919
  async function hydrateInlineMeshDirectTruth(args) {
71885
71920
  const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
71886
71921
  if (!nodes.length) {
@@ -71940,19 +71975,18 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
71940
71975
  continue;
71941
71976
  }
71942
71977
  peerAttemptedCount += 1;
71943
- try {
71944
- const remoteGit = await probeRemoteMeshGitStatus({
71945
- dispatchMeshCommand: args.dispatchMeshCommand,
71946
- daemonId,
71947
- workspace,
71948
- timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS
71949
- });
71950
- if (remoteGit) {
71951
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
71952
- peerConfirmedCount += 1;
71953
- continue;
71954
- }
71955
- } catch {
71978
+ const remoteGit = await probeRemoteMeshGitStatusWithRetry({
71979
+ dispatchMeshCommand: args.dispatchMeshCommand,
71980
+ daemonId,
71981
+ workspace,
71982
+ timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS,
71983
+ retryTimeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS,
71984
+ getConnection: args.getMeshPeerConnectionStatus
71985
+ });
71986
+ if (remoteGit) {
71987
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
71988
+ peerConfirmedCount += 1;
71989
+ continue;
71956
71990
  }
71957
71991
  unavailableNodeIds.push(nodeId);
71958
71992
  }
@@ -76170,6 +76204,7 @@ ${hintLines.join("\n")}` : "",
76170
76204
  mesh: meshRecord.mesh,
76171
76205
  meshSource: meshRecord.source,
76172
76206
  dispatchMeshCommand: this.deps.dispatchMeshCommand,
76207
+ getMeshPeerConnectionStatus: this.deps.getMeshPeerConnectionStatus,
76173
76208
  statusInstanceId: this.deps.statusInstanceId,
76174
76209
  localMachineId: loadConfig2().machineId || "",
76175
76210
  probeRemotePeers
@@ -77752,6 +77787,7 @@ ${ptyResult.output.slice(-2e3)}`);
77752
77787
  mesh,
77753
77788
  meshSource: meshRecord.source,
77754
77789
  dispatchMeshCommand: this.deps.dispatchMeshCommand,
77790
+ getMeshPeerConnectionStatus: this.deps.getMeshPeerConnectionStatus,
77755
77791
  statusInstanceId: this.deps.statusInstanceId,
77756
77792
  localMachineId,
77757
77793
  // Standing-state model: only an explicit refresh fans
@@ -77918,52 +77954,28 @@ ${ptyResult.output.slice(-2e3)}`);
77918
77954
  }
77919
77955
  remoteProbeApplied = true;
77920
77956
  } else if (refreshRequested && !isSelfNode && daemonId && this.deps.dispatchMeshCommand && !directTruthUnavailableNodeIds.has(nodeId)) {
77921
- try {
77922
- const remoteGit = await probeRemoteMeshGitStatus({
77923
- dispatchMeshCommand: this.deps.dispatchMeshCommand,
77924
- daemonId,
77925
- workspace,
77926
- timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS
77927
- });
77928
- if (remoteGit) {
77929
- status.git = remoteGit;
77930
- status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
77931
- const connection = readObjectRecord(status.connection);
77932
- const connectionState = readStringValue(connection.state);
77933
- const connectionReported = readBooleanValue(connection.reported) ?? false;
77934
- if (!connectionReported || connectionState === "unknown") {
77935
- status.connection = buildLivePeerGitConnection(connection, refreshedAt);
77936
- }
77937
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
77938
- remoteProbeApplied = true;
77957
+ const remoteGit = await probeRemoteMeshGitStatusWithRetry({
77958
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
77959
+ daemonId,
77960
+ workspace,
77961
+ timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS,
77962
+ retryTimeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS,
77963
+ getConnection: this.deps.getMeshPeerConnectionStatus,
77964
+ onConnection: (connection) => {
77965
+ status.connection = connection;
77939
77966
  }
77940
- } catch {
77941
- const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
77942
- const refreshedConnectionState = readStringValue(refreshedConnection?.state);
77943
- if (refreshedConnection && refreshedConnectionState === "connected") {
77944
- status.connection = refreshedConnection;
77945
- try {
77946
- const remoteGit = await probeRemoteMeshGitStatus({
77947
- dispatchMeshCommand: this.deps.dispatchMeshCommand,
77948
- daemonId,
77949
- workspace,
77950
- timeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS
77951
- });
77952
- if (remoteGit) {
77953
- status.git = remoteGit;
77954
- status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
77955
- const connection = readObjectRecord(status.connection);
77956
- const connectionState = readStringValue(connection.state);
77957
- const connectionReported = readBooleanValue(connection.reported) ?? false;
77958
- if (!connectionReported || connectionState === "unknown") {
77959
- status.connection = buildLivePeerGitConnection(connection, refreshedAt);
77960
- }
77961
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
77962
- remoteProbeApplied = true;
77963
- }
77964
- } catch {
77965
- }
77967
+ });
77968
+ if (remoteGit) {
77969
+ status.git = remoteGit;
77970
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
77971
+ const connection = readObjectRecord(status.connection);
77972
+ const connectionState = readStringValue(connection.state);
77973
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
77974
+ if (!connectionReported || connectionState === "unknown") {
77975
+ status.connection = buildLivePeerGitConnection(connection, refreshedAt);
77966
77976
  }
77977
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
77978
+ remoteProbeApplied = true;
77967
77979
  }
77968
77980
  }
77969
77981
  if (!remoteProbeApplied) {
@@ -78032,7 +78044,7 @@ ${ptyResult.output.slice(-2e3)}`);
78032
78044
  liveSessionRecords: liveMeshSessions
78033
78045
  });
78034
78046
  const { getMeshStatusMissionSummaries: getMeshStatusMissionSummaries2 } = await Promise.resolve().then(() => (init_mesh_missions(), mesh_missions_exports));
78035
- const missions = getMeshStatusMissionSummaries2(meshId, { verbose: verboseMissions });
78047
+ const missions = getMeshStatusMissionSummaries2(meshId, { verbose: verboseMissions, withStats: true });
78036
78048
  const statusResult = {
78037
78049
  success: true,
78038
78050
  meshId: mesh.id,