@adhdev/daemon-core 0.9.82-rc.6 → 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
@@ -23694,26 +23694,127 @@ function buildCachedInlineMeshGitStatus(node) {
23694
23694
  ...submodules ? { submodules } : {}
23695
23695
  };
23696
23696
  }
23697
+ function hasGitWorktreeChanges(git) {
23698
+ if (!git) return false;
23699
+ return Number(git.staged || 0) + Number(git.modified || 0) + Number(git.untracked || 0) + Number(git.deleted || 0) + Number(git.renamed || 0) > 0;
23700
+ }
23701
+ function getGitSubmoduleDriftState(git) {
23702
+ const submodules = Array.isArray(git?.submodules) ? git.submodules : [];
23703
+ let dirty = false;
23704
+ let outOfSync = false;
23705
+ for (const entry of submodules) {
23706
+ const submodule = readObjectRecord(entry);
23707
+ if (readBooleanValue(submodule.dirty) === true) dirty = true;
23708
+ if (readBooleanValue(submodule.outOfSync) === true || !!readStringValue(submodule.error)) outOfSync = true;
23709
+ }
23710
+ return { dirty, outOfSync };
23711
+ }
23712
+ function deriveMeshNodeHealthFromGit(git) {
23713
+ if (!git || readBooleanValue(git.isGitRepo) === false) return "degraded";
23714
+ const branch = readStringValue(git.branch);
23715
+ if (!branch) return "degraded";
23716
+ const submoduleDrift = getGitSubmoduleDriftState(git);
23717
+ if (submoduleDrift.outOfSync) return "degraded";
23718
+ if (submoduleDrift.dirty || hasGitWorktreeChanges(git)) return "dirty";
23719
+ return "online";
23720
+ }
23721
+ function readCachedInlineMeshActiveSessions(node) {
23722
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
23723
+ const activeSession = readObjectRecord(cachedStatus.activeSession);
23724
+ const fallbackSession = Object.keys(activeSession).length ? activeSession : readObjectRecord(node?.activeSession ?? node?.active_session);
23725
+ const sessionId = readStringValue(fallbackSession.id, fallbackSession.sessionId, fallbackSession.session_id, node?.activeSessionId, node?.active_session_id, node?.sessionId, node?.session_id);
23726
+ return sessionId ? [sessionId] : [];
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
+ }
23697
23791
  function applyCachedInlineMeshNodeStatus(status, node) {
23698
23792
  const cachedStatus = readObjectRecord(node?.cachedStatus);
23699
23793
  const git = buildCachedInlineMeshGitStatus(node);
23700
23794
  const error = readStringValue(cachedStatus.error, node?.error);
23701
23795
  const health = readStringValue(cachedStatus.health, node?.health);
23702
23796
  const machineStatus = readStringValue(cachedStatus.machineStatus, node?.machineStatus);
23703
- if (!git && !error && !health) return false;
23704
- if (!machineStatus && !git && !error) return false;
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);
23799
+ const activeSessions = readCachedInlineMeshActiveSessions(node);
23800
+ const activeSessionDetails = readCachedInlineMeshActiveSessionDetails(node);
23801
+ if (!git && !error && !health && !machineStatus && !lastSeenAt && !updatedAt && activeSessions.length === 0) return false;
23705
23802
  if (git) status.git = git;
23706
23803
  if (error) status.error = error;
23804
+ if (machineStatus) status.machineStatus = machineStatus;
23805
+ if (lastSeenAt) status.lastSeenAt = lastSeenAt;
23806
+ if (updatedAt) status.updatedAt = updatedAt;
23807
+ if (activeSessions.length > 0) status.activeSessions = activeSessions;
23808
+ if (activeSessionDetails.length > 0) status.activeSessionDetails = activeSessionDetails;
23707
23809
  if (health) {
23708
23810
  status.health = health;
23709
23811
  return true;
23710
23812
  }
23711
23813
  if (git) {
23712
- const dirty = Number(git.staged || 0) + Number(git.modified || 0) + Number(git.untracked || 0) + Number(git.deleted || 0) + Number(git.renamed || 0) > 0;
23713
- status.health = git.isGitRepo === false ? "degraded" : dirty ? "dirty" : "online";
23814
+ status.health = deriveMeshNodeHealthFromGit(git);
23714
23815
  return true;
23715
23816
  }
23716
- return false;
23817
+ return activeSessions.length > 0 || !!machineStatus || !!lastSeenAt || !!updatedAt;
23717
23818
  }
23718
23819
  async function resolveProviderTypeFromPriority(args) {
23719
23820
  if (!args.providerPriority.length) {
@@ -25953,23 +26054,81 @@ ${block}`);
25953
26054
  const { readLedgerEntries: readLedgerEntries2, getLedgerSummary: getLedgerSummary2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
25954
26055
  const ledgerEntries = readLedgerEntries2(meshId, { tail: 20 });
25955
26056
  const ledgerSummary = getLedgerSummary2(meshId);
26057
+ const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
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();
25956
26062
  const nodeStatuses = [];
25957
- 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);
25958
26072
  const status = {
25959
- nodeId: node.id || node.nodeId,
26073
+ nodeId,
25960
26074
  machineLabel: node.machineLabel || node.id || node.nodeId,
25961
26075
  workspace: node.workspace,
25962
26076
  repoRoot: node.repoRoot,
25963
26077
  isLocalWorktree: node.isLocalWorktree,
25964
26078
  worktreeBranch: node.worktreeBranch,
25965
- daemonId: node.daemonId,
26079
+ daemonId,
25966
26080
  machineId: node.machineId,
26081
+ machineStatus: node.machineStatus,
25967
26082
  health: "unknown",
25968
26083
  providers: node.providers || [],
25969
- activeSessions: []
26084
+ providerPriority,
26085
+ activeSessions: [],
26086
+ activeSessionDetails: [],
26087
+ launchReady: false
25970
26088
  };
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
+ }
26128
+ }
25971
26129
  if (node.workspace && typeof node.workspace === "string") {
25972
26130
  if (!fs10.existsSync(node.workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
26131
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
25973
26132
  nodeStatuses.push(status);
25974
26133
  continue;
25975
26134
  }
@@ -25977,8 +26136,7 @@ ${block}`);
25977
26136
  const gitStatus = await getGitRepoStatus(node.workspace, { timeoutMs: 1e4 });
25978
26137
  status.git = gitStatus;
25979
26138
  if (gitStatus.isGitRepo) {
25980
- const dirty = gitStatus.staged + gitStatus.modified + gitStatus.untracked + gitStatus.deleted + gitStatus.renamed > 0;
25981
- status.health = gitStatus.branch ? dirty ? "dirty" : "online" : "degraded";
26139
+ status.health = deriveMeshNodeHealthFromGit(gitStatus);
25982
26140
  } else {
25983
26141
  status.health = "degraded";
25984
26142
  if (gitStatus.error && !status.error) status.error = gitStatus.error;
@@ -25991,6 +26149,7 @@ ${block}`);
25991
26149
  } else {
25992
26150
  applyCachedInlineMeshNodeStatus(status, node);
25993
26151
  }
26152
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
25994
26153
  nodeStatuses.push(status);
25995
26154
  }
25996
26155
  return {
@@ -25999,6 +26158,7 @@ ${block}`);
25999
26158
  meshName: mesh.name,
26000
26159
  repoIdentity: mesh.repoIdentity,
26001
26160
  defaultBranch: mesh.defaultBranch,
26161
+ refreshedAt: (/* @__PURE__ */ new Date()).toISOString(),
26002
26162
  nodes: nodeStatuses,
26003
26163
  queue: { tasks: queue, summary: queueSummary },
26004
26164
  ledger: { entries: ledgerEntries, summary: ledgerSummary }
@@ -33933,6 +34093,7 @@ async function initDaemonComponents(config) {
33933
34093
  sessionHostControl: config.sessionHostControl,
33934
34094
  statusInstanceId: config.statusInstanceId,
33935
34095
  statusVersion: config.statusVersion,
34096
+ getMeshPeerConnectionStatus: config.getMeshPeerConnectionStatus,
33936
34097
  getCdpLogFn: config.getCdpLogFn || ((ideType) => LOG.forComponent(`CDP:${ideType}`).asLogFn())
33937
34098
  });
33938
34099
  poller = new AgentStreamPoller({