@adhdev/daemon-core 0.9.82-rc.7 → 0.9.82-rc.8

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
@@ -23725,17 +23725,87 @@ function readCachedInlineMeshActiveSessions(node) {
23725
23725
  const sessionId = readStringValue(fallbackSession.id, fallbackSession.sessionId, fallbackSession.session_id, node?.activeSessionId, node?.active_session_id, node?.sessionId, node?.session_id);
23726
23726
  return sessionId ? [sessionId] : [];
23727
23727
  }
23728
+ function readCachedInlineMeshActiveSessionDetails(node) {
23729
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
23730
+ const activeSession = readObjectRecord(cachedStatus.activeSession);
23731
+ const fallbackSession = Object.keys(activeSession).length ? activeSession : readObjectRecord(node?.activeSession ?? node?.active_session);
23732
+ const sessionId = readStringValue(
23733
+ fallbackSession.id,
23734
+ fallbackSession.sessionId,
23735
+ fallbackSession.session_id,
23736
+ node?.activeSessionId,
23737
+ node?.active_session_id,
23738
+ node?.sessionId,
23739
+ node?.session_id
23740
+ );
23741
+ if (!sessionId) return [];
23742
+ return [{
23743
+ sessionId,
23744
+ providerType: readStringValue(
23745
+ fallbackSession.providerType,
23746
+ fallbackSession.provider_type,
23747
+ fallbackSession.cliType,
23748
+ fallbackSession.cli_type,
23749
+ fallbackSession.provider,
23750
+ node?.providerType,
23751
+ node?.provider_type
23752
+ ),
23753
+ state: readStringValue(fallbackSession.status, fallbackSession.state, fallbackSession.lifecycle),
23754
+ lifecycle: readStringValue(fallbackSession.lifecycle),
23755
+ title: readStringValue(fallbackSession.title, fallbackSession.displayName, fallbackSession.display_name) ?? null,
23756
+ workspace: readStringValue(fallbackSession.workspace, node?.workspace) ?? null,
23757
+ lastActivityAt: readStringValue(fallbackSession.lastActivityAt, fallbackSession.last_activity_at) ?? null,
23758
+ recoveryState: readStringValue(fallbackSession.recoveryState, fallbackSession.recovery_state) ?? null,
23759
+ isCached: true
23760
+ }];
23761
+ }
23762
+ function readLiveMeshSessionState(record) {
23763
+ return readStringValue(
23764
+ record?.meta?.sessionStatus,
23765
+ record?.meta?.status,
23766
+ record?.meta?.providerStatus,
23767
+ record?.status,
23768
+ record?.state,
23769
+ record?.lifecycle
23770
+ );
23771
+ }
23772
+ function toIsoTimestamp(value) {
23773
+ if (typeof value === "number" && Number.isFinite(value)) return new Date(value).toISOString();
23774
+ const stringValue = readStringValue(value);
23775
+ return stringValue || null;
23776
+ }
23777
+ function summarizeMeshSessionRecord(record) {
23778
+ return {
23779
+ sessionId: readStringValue(record?.sessionId) || "unknown",
23780
+ providerType: readStringValue(record?.providerType),
23781
+ state: readLiveMeshSessionState(record),
23782
+ lifecycle: readStringValue(record?.lifecycle),
23783
+ surfaceKind: getSessionHostSurfaceKind(record),
23784
+ recoveryState: readStringValue(record?.meta?.runtimeRecoveryState) ?? null,
23785
+ workspace: readStringValue(record?.workspace) ?? null,
23786
+ title: readStringValue(record?.displayName, record?.workspaceLabel) ?? null,
23787
+ lastActivityAt: toIsoTimestamp(record?.updatedAt ?? record?.lastActivityAt ?? record?.last_activity_at),
23788
+ isCached: false
23789
+ };
23790
+ }
23728
23791
  function applyCachedInlineMeshNodeStatus(status, node) {
23729
23792
  const cachedStatus = readObjectRecord(node?.cachedStatus);
23730
23793
  const git = buildCachedInlineMeshGitStatus(node);
23731
23794
  const error = readStringValue(cachedStatus.error, node?.error);
23732
23795
  const health = readStringValue(cachedStatus.health, node?.health);
23733
23796
  const machineStatus = readStringValue(cachedStatus.machineStatus, node?.machineStatus);
23797
+ const lastSeenAt = toIsoTimestamp(cachedStatus.lastSeenAt ?? cachedStatus.last_seen_at ?? node?.lastSeenAt ?? node?.last_seen_at);
23798
+ const updatedAt = toIsoTimestamp(cachedStatus.updatedAt ?? cachedStatus.updated_at ?? node?.updatedAt ?? node?.updated_at);
23734
23799
  const activeSessions = readCachedInlineMeshActiveSessions(node);
23735
- if (!git && !error && !health && !machineStatus && activeSessions.length === 0) return false;
23800
+ const activeSessionDetails = readCachedInlineMeshActiveSessionDetails(node);
23801
+ if (!git && !error && !health && !machineStatus && !lastSeenAt && !updatedAt && activeSessions.length === 0) return false;
23736
23802
  if (git) status.git = git;
23737
23803
  if (error) status.error = error;
23804
+ if (machineStatus) status.machineStatus = machineStatus;
23805
+ if (lastSeenAt) status.lastSeenAt = lastSeenAt;
23806
+ if (updatedAt) status.updatedAt = updatedAt;
23738
23807
  if (activeSessions.length > 0) status.activeSessions = activeSessions;
23808
+ if (activeSessionDetails.length > 0) status.activeSessionDetails = activeSessionDetails;
23739
23809
  if (health) {
23740
23810
  status.health = health;
23741
23811
  return true;
@@ -23744,7 +23814,7 @@ function applyCachedInlineMeshNodeStatus(status, node) {
23744
23814
  status.health = deriveMeshNodeHealthFromGit(git);
23745
23815
  return true;
23746
23816
  }
23747
- return activeSessions.length > 0 || !!machineStatus;
23817
+ return activeSessions.length > 0 || !!machineStatus || !!lastSeenAt || !!updatedAt;
23748
23818
  }
23749
23819
  async function resolveProviderTypeFromPriority(args) {
23750
23820
  if (!args.providerPriority.length) {
@@ -25986,28 +26056,79 @@ ${block}`);
25986
26056
  const ledgerSummary = getLedgerSummary2(meshId);
25987
26057
  const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
25988
26058
  const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
26059
+ const localMachineId = loadConfig().machineId || "";
26060
+ const inlineCoordinatorNodeId = meshRecord?.inline && Array.isArray(mesh.nodes) ? readStringValue(mesh.nodes[0]?.id, mesh.nodes[0]?.nodeId) : void 0;
26061
+ const refreshedAt = (/* @__PURE__ */ new Date()).toISOString();
25989
26062
  const nodeStatuses = [];
25990
- for (const node of mesh.nodes || []) {
26063
+ for (const [nodeIndex, node] of (mesh.nodes || []).entries()) {
26064
+ const nodeId = String(node.id || node.nodeId || "");
26065
+ const daemonId = readStringValue(node.daemonId);
26066
+ const providerPriority = readProviderPriorityFromPolicy(node.policy);
26067
+ const isSelfNode = Boolean(
26068
+ nodeId && inlineCoordinatorNodeId && nodeId === inlineCoordinatorNodeId
26069
+ ) || Boolean(
26070
+ daemonId && (daemonId === localMachineId || daemonId === this.deps.statusInstanceId)
26071
+ ) || Boolean(meshRecord?.inline && nodeIndex === 0);
25991
26072
  const status = {
25992
- nodeId: node.id || node.nodeId,
26073
+ nodeId,
25993
26074
  machineLabel: node.machineLabel || node.id || node.nodeId,
25994
26075
  workspace: node.workspace,
25995
26076
  repoRoot: node.repoRoot,
25996
26077
  isLocalWorktree: node.isLocalWorktree,
25997
26078
  worktreeBranch: node.worktreeBranch,
25998
- daemonId: node.daemonId,
26079
+ daemonId,
25999
26080
  machineId: node.machineId,
26081
+ machineStatus: node.machineStatus,
26000
26082
  health: "unknown",
26001
26083
  providers: node.providers || [],
26002
- activeSessions: []
26084
+ providerPriority,
26085
+ activeSessions: [],
26086
+ activeSessionDetails: [],
26087
+ launchReady: false
26003
26088
  };
26004
- const nodeId = String(node.id || node.nodeId || "");
26005
- const matchedLiveSessions = liveMeshSessions.filter((record) => this.sessionMatchesMeshNode(record, node, nodeId)).map((record) => typeof record?.sessionId === "string" ? record.sessionId : "").filter(Boolean);
26006
- if (matchedLiveSessions.length > 0) {
26007
- status.activeSessions = matchedLiveSessions;
26089
+ if (isSelfNode) {
26090
+ status.connection = {
26091
+ perspective: "selected_coordinator",
26092
+ source: "mesh_peer_status",
26093
+ state: "self",
26094
+ transport: "local",
26095
+ reported: true,
26096
+ reason: "Selected coordinator daemon",
26097
+ lastStateChangeAt: refreshedAt
26098
+ };
26099
+ } else if (daemonId) {
26100
+ const connection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
26101
+ status.connection = connection ?? {
26102
+ perspective: "selected_coordinator",
26103
+ source: "not_reported",
26104
+ state: "unknown",
26105
+ transport: "unknown",
26106
+ reported: false,
26107
+ reason: "No live mesh peer telemetry reported by the selected coordinator yet."
26108
+ };
26109
+ } else {
26110
+ status.connection = {
26111
+ perspective: "selected_coordinator",
26112
+ source: "not_reported",
26113
+ state: "unknown",
26114
+ transport: "unknown",
26115
+ reported: false,
26116
+ reason: "Node has no daemon id, so mesh transport cannot be reported from the selected coordinator."
26117
+ };
26118
+ }
26119
+ const matchedLiveSessionRecords = liveMeshSessions.filter((record) => this.sessionMatchesMeshNode(record, node, nodeId));
26120
+ if (matchedLiveSessionRecords.length > 0) {
26121
+ const sessionIds = matchedLiveSessionRecords.map((record) => typeof record?.sessionId === "string" ? record.sessionId : "").filter(Boolean);
26122
+ const providerTypes = matchedLiveSessionRecords.map((record) => readStringValue(record?.providerType)).filter(Boolean);
26123
+ status.activeSessions = sessionIds;
26124
+ status.activeSessionDetails = matchedLiveSessionRecords.map(summarizeMeshSessionRecord);
26125
+ if (providerTypes.length > 0) {
26126
+ status.providers = Array.from(/* @__PURE__ */ new Set([...Array.isArray(status.providers) ? status.providers : [], ...providerTypes]));
26127
+ }
26008
26128
  }
26009
26129
  if (node.workspace && typeof node.workspace === "string") {
26010
26130
  if (!fs10.existsSync(node.workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
26131
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26011
26132
  nodeStatuses.push(status);
26012
26133
  continue;
26013
26134
  }
@@ -26028,6 +26149,7 @@ ${block}`);
26028
26149
  } else {
26029
26150
  applyCachedInlineMeshNodeStatus(status, node);
26030
26151
  }
26152
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26031
26153
  nodeStatuses.push(status);
26032
26154
  }
26033
26155
  return {
@@ -26036,6 +26158,7 @@ ${block}`);
26036
26158
  meshName: mesh.name,
26037
26159
  repoIdentity: mesh.repoIdentity,
26038
26160
  defaultBranch: mesh.defaultBranch,
26161
+ refreshedAt: (/* @__PURE__ */ new Date()).toISOString(),
26039
26162
  nodes: nodeStatuses,
26040
26163
  queue: { tasks: queue, summary: queueSummary },
26041
26164
  ledger: { entries: ledgerEntries, summary: ledgerSummary }
@@ -33970,6 +34093,7 @@ async function initDaemonComponents(config) {
33970
34093
  sessionHostControl: config.sessionHostControl,
33971
34094
  statusInstanceId: config.statusInstanceId,
33972
34095
  statusVersion: config.statusVersion,
34096
+ getMeshPeerConnectionStatus: config.getMeshPeerConnectionStatus,
33973
34097
  getCdpLogFn: config.getCdpLogFn || ((ideType) => LOG.forComponent(`CDP:${ideType}`).asLogFn())
33974
34098
  });
33975
34099
  poller = new AgentStreamPoller({