@adhdev/daemon-core 0.9.82-rc.21 → 0.9.82-rc.22

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
@@ -24004,6 +24004,96 @@ function buildCachedInlineMeshGitStatus(node) {
24004
24004
  ...submodules ? { submodules } : {}
24005
24005
  };
24006
24006
  }
24007
+ function shouldDiscardCachedInlineMeshStatus(node) {
24008
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
24009
+ if (!Object.keys(cachedStatus).length) return false;
24010
+ const cachedGit = readObjectRecord(cachedStatus.git);
24011
+ const workspaceError = readStringValue(cachedStatus.error, node?.error);
24012
+ if (workspaceError && /workspace must be an existing directory/i.test(workspaceError)) return true;
24013
+ const isGitRepo = readBooleanValue(cachedGit.isGitRepo);
24014
+ const branch = readStringValue(cachedGit.branch);
24015
+ const headCommit = readStringValue(cachedGit.headCommit);
24016
+ return isGitRepo === false && !branch && !headCommit;
24017
+ }
24018
+ function stripInlineMeshTransientNodeState(node) {
24019
+ if (!node || typeof node !== "object" || Array.isArray(node)) return node;
24020
+ const {
24021
+ cachedStatus,
24022
+ lastGit: _lastGit,
24023
+ last_git: _lastGitLegacy,
24024
+ lastProbe: _lastProbe,
24025
+ last_probe: _lastProbeLegacy,
24026
+ error: _error,
24027
+ health: _health,
24028
+ machineStatus: _machineStatus,
24029
+ lastSeenAt: _lastSeenAt,
24030
+ last_seen_at: _lastSeenAtLegacy,
24031
+ updatedAt: _updatedAt,
24032
+ updated_at: _updatedAtLegacy,
24033
+ activeSession: _activeSession,
24034
+ active_session: _activeSessionLegacy,
24035
+ activeSessionId: _activeSessionId,
24036
+ active_session_id: _activeSessionIdLegacy,
24037
+ sessionId: _sessionId,
24038
+ session_id: _sessionIdLegacy,
24039
+ providerType: _providerType,
24040
+ provider_type: _providerTypeLegacy,
24041
+ providers: _providers,
24042
+ ...rest
24043
+ } = node;
24044
+ if (cachedStatus && !shouldDiscardCachedInlineMeshStatus(node)) {
24045
+ return { ...rest, cachedStatus };
24046
+ }
24047
+ return rest;
24048
+ }
24049
+ function hasInlineMeshTransientNodeState(node) {
24050
+ if (!node || typeof node !== "object" || Array.isArray(node)) return false;
24051
+ return "cachedStatus" in node || "lastGit" in node || "last_git" in node || "lastProbe" in node || "last_probe" in node || "error" in node || "health" in node || "machineStatus" in node || "lastSeenAt" in node || "last_seen_at" in node || "updatedAt" in node || "updated_at" in node || "activeSession" in node || "active_session" in node || "activeSessionId" in node || "active_session_id" in node || "sessionId" in node || "session_id" in node || "providerType" in node || "provider_type" in node || "providers" in node;
24052
+ }
24053
+ function readInlineMeshNodeId(node) {
24054
+ return readStringValue(node?.id, node?.nodeId) || "";
24055
+ }
24056
+ function sanitizeInlineMesh(inlineMesh) {
24057
+ if (!inlineMesh || typeof inlineMesh !== "object" || Array.isArray(inlineMesh)) return inlineMesh;
24058
+ if (!Array.isArray(inlineMesh.nodes)) return inlineMesh;
24059
+ let changed = false;
24060
+ const nodes = inlineMesh.nodes.map((node) => {
24061
+ if (!hasInlineMeshTransientNodeState(node)) return node;
24062
+ changed = true;
24063
+ return stripInlineMeshTransientNodeState(node);
24064
+ });
24065
+ if (!changed) return inlineMesh;
24066
+ return {
24067
+ ...inlineMesh,
24068
+ nodes
24069
+ };
24070
+ }
24071
+ function reconcileInlineMeshCache(cached, incoming) {
24072
+ if (!cached || typeof cached !== "object" || Array.isArray(cached)) return incoming;
24073
+ if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) return cached;
24074
+ const cachedNodes = Array.isArray(cached.nodes) ? cached.nodes : [];
24075
+ const incomingNodes = Array.isArray(incoming.nodes) ? incoming.nodes : [];
24076
+ if (!cachedNodes.length || !incomingNodes.length) return { ...cached, ...incoming };
24077
+ const incomingById = /* @__PURE__ */ new Map();
24078
+ for (const node of incomingNodes) {
24079
+ const nodeId = readInlineMeshNodeId(node);
24080
+ if (nodeId) incomingById.set(nodeId, node);
24081
+ }
24082
+ const nodes = cachedNodes.map((cachedNode) => {
24083
+ const nodeId = readInlineMeshNodeId(cachedNode);
24084
+ const incomingNode = nodeId ? incomingById.get(nodeId) : void 0;
24085
+ if (!incomingNode) return cachedNode;
24086
+ if (hasInlineMeshTransientNodeState(incomingNode)) {
24087
+ return { ...cachedNode, ...incomingNode };
24088
+ }
24089
+ return { ...stripInlineMeshTransientNodeState(cachedNode), ...incomingNode };
24090
+ });
24091
+ return {
24092
+ ...cached,
24093
+ ...incoming,
24094
+ nodes
24095
+ };
24096
+ }
24007
24097
  function hasGitWorktreeChanges(git) {
24008
24098
  if (!git) return false;
24009
24099
  return Number(git.staged || 0) + Number(git.modified || 0) + Number(git.untracked || 0) + Number(git.deleted || 0) + Number(git.renamed || 0) > 0;
@@ -24558,10 +24648,15 @@ var DaemonCommandRouter = class {
24558
24648
  }
24559
24649
  warmInlineMeshCache(meshId, inlineMesh) {
24560
24650
  if (!inlineMesh || typeof inlineMesh !== "object") return void 0;
24651
+ const sanitizedInlineMesh = sanitizeInlineMesh(inlineMesh);
24561
24652
  const cached = this.inlineMeshCache.get(meshId);
24562
- if (cached) return cached;
24563
- this.inlineMeshCache.set(meshId, inlineMesh);
24564
- return inlineMesh;
24653
+ if (cached) {
24654
+ const merged = reconcileInlineMeshCache(cached, sanitizedInlineMesh);
24655
+ this.inlineMeshCache.set(meshId, merged);
24656
+ return merged;
24657
+ }
24658
+ this.inlineMeshCache.set(meshId, sanitizedInlineMesh);
24659
+ return sanitizedInlineMesh;
24565
24660
  }
24566
24661
  async getMeshForCommand(meshId, inlineMesh, options) {
24567
24662
  const preferInline = options?.preferInline === true;
@@ -26504,10 +26599,17 @@ ${block}`);
26504
26599
  }
26505
26600
  }
26506
26601
  if (workspace) {
26507
- if (!fs10.existsSync(workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
26508
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26509
- nodeStatuses.push(status);
26510
- continue;
26602
+ if (!fs10.existsSync(workspace)) {
26603
+ if (applyCachedInlineMeshNodeStatus(status, node)) {
26604
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26605
+ nodeStatuses.push(status);
26606
+ continue;
26607
+ }
26608
+ if (meshRecord?.source === "inline_cache" && !isSelfNode) {
26609
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26610
+ nodeStatuses.push(status);
26611
+ continue;
26612
+ }
26511
26613
  }
26512
26614
  try {
26513
26615
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });