@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.mjs CHANGED
@@ -23771,6 +23771,96 @@ function buildCachedInlineMeshGitStatus(node) {
23771
23771
  ...submodules ? { submodules } : {}
23772
23772
  };
23773
23773
  }
23774
+ function shouldDiscardCachedInlineMeshStatus(node) {
23775
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
23776
+ if (!Object.keys(cachedStatus).length) return false;
23777
+ const cachedGit = readObjectRecord(cachedStatus.git);
23778
+ const workspaceError = readStringValue(cachedStatus.error, node?.error);
23779
+ if (workspaceError && /workspace must be an existing directory/i.test(workspaceError)) return true;
23780
+ const isGitRepo = readBooleanValue(cachedGit.isGitRepo);
23781
+ const branch = readStringValue(cachedGit.branch);
23782
+ const headCommit = readStringValue(cachedGit.headCommit);
23783
+ return isGitRepo === false && !branch && !headCommit;
23784
+ }
23785
+ function stripInlineMeshTransientNodeState(node) {
23786
+ if (!node || typeof node !== "object" || Array.isArray(node)) return node;
23787
+ const {
23788
+ cachedStatus,
23789
+ lastGit: _lastGit,
23790
+ last_git: _lastGitLegacy,
23791
+ lastProbe: _lastProbe,
23792
+ last_probe: _lastProbeLegacy,
23793
+ error: _error,
23794
+ health: _health,
23795
+ machineStatus: _machineStatus,
23796
+ lastSeenAt: _lastSeenAt,
23797
+ last_seen_at: _lastSeenAtLegacy,
23798
+ updatedAt: _updatedAt,
23799
+ updated_at: _updatedAtLegacy,
23800
+ activeSession: _activeSession,
23801
+ active_session: _activeSessionLegacy,
23802
+ activeSessionId: _activeSessionId,
23803
+ active_session_id: _activeSessionIdLegacy,
23804
+ sessionId: _sessionId,
23805
+ session_id: _sessionIdLegacy,
23806
+ providerType: _providerType,
23807
+ provider_type: _providerTypeLegacy,
23808
+ providers: _providers,
23809
+ ...rest
23810
+ } = node;
23811
+ if (cachedStatus && !shouldDiscardCachedInlineMeshStatus(node)) {
23812
+ return { ...rest, cachedStatus };
23813
+ }
23814
+ return rest;
23815
+ }
23816
+ function hasInlineMeshTransientNodeState(node) {
23817
+ if (!node || typeof node !== "object" || Array.isArray(node)) return false;
23818
+ 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;
23819
+ }
23820
+ function readInlineMeshNodeId(node) {
23821
+ return readStringValue(node?.id, node?.nodeId) || "";
23822
+ }
23823
+ function sanitizeInlineMesh(inlineMesh) {
23824
+ if (!inlineMesh || typeof inlineMesh !== "object" || Array.isArray(inlineMesh)) return inlineMesh;
23825
+ if (!Array.isArray(inlineMesh.nodes)) return inlineMesh;
23826
+ let changed = false;
23827
+ const nodes = inlineMesh.nodes.map((node) => {
23828
+ if (!hasInlineMeshTransientNodeState(node)) return node;
23829
+ changed = true;
23830
+ return stripInlineMeshTransientNodeState(node);
23831
+ });
23832
+ if (!changed) return inlineMesh;
23833
+ return {
23834
+ ...inlineMesh,
23835
+ nodes
23836
+ };
23837
+ }
23838
+ function reconcileInlineMeshCache(cached, incoming) {
23839
+ if (!cached || typeof cached !== "object" || Array.isArray(cached)) return incoming;
23840
+ if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) return cached;
23841
+ const cachedNodes = Array.isArray(cached.nodes) ? cached.nodes : [];
23842
+ const incomingNodes = Array.isArray(incoming.nodes) ? incoming.nodes : [];
23843
+ if (!cachedNodes.length || !incomingNodes.length) return { ...cached, ...incoming };
23844
+ const incomingById = /* @__PURE__ */ new Map();
23845
+ for (const node of incomingNodes) {
23846
+ const nodeId = readInlineMeshNodeId(node);
23847
+ if (nodeId) incomingById.set(nodeId, node);
23848
+ }
23849
+ const nodes = cachedNodes.map((cachedNode) => {
23850
+ const nodeId = readInlineMeshNodeId(cachedNode);
23851
+ const incomingNode = nodeId ? incomingById.get(nodeId) : void 0;
23852
+ if (!incomingNode) return cachedNode;
23853
+ if (hasInlineMeshTransientNodeState(incomingNode)) {
23854
+ return { ...cachedNode, ...incomingNode };
23855
+ }
23856
+ return { ...stripInlineMeshTransientNodeState(cachedNode), ...incomingNode };
23857
+ });
23858
+ return {
23859
+ ...cached,
23860
+ ...incoming,
23861
+ nodes
23862
+ };
23863
+ }
23774
23864
  function hasGitWorktreeChanges(git) {
23775
23865
  if (!git) return false;
23776
23866
  return Number(git.staged || 0) + Number(git.modified || 0) + Number(git.untracked || 0) + Number(git.deleted || 0) + Number(git.renamed || 0) > 0;
@@ -24325,10 +24415,15 @@ var DaemonCommandRouter = class {
24325
24415
  }
24326
24416
  warmInlineMeshCache(meshId, inlineMesh) {
24327
24417
  if (!inlineMesh || typeof inlineMesh !== "object") return void 0;
24418
+ const sanitizedInlineMesh = sanitizeInlineMesh(inlineMesh);
24328
24419
  const cached = this.inlineMeshCache.get(meshId);
24329
- if (cached) return cached;
24330
- this.inlineMeshCache.set(meshId, inlineMesh);
24331
- return inlineMesh;
24420
+ if (cached) {
24421
+ const merged = reconcileInlineMeshCache(cached, sanitizedInlineMesh);
24422
+ this.inlineMeshCache.set(meshId, merged);
24423
+ return merged;
24424
+ }
24425
+ this.inlineMeshCache.set(meshId, sanitizedInlineMesh);
24426
+ return sanitizedInlineMesh;
24332
24427
  }
24333
24428
  async getMeshForCommand(meshId, inlineMesh, options) {
24334
24429
  const preferInline = options?.preferInline === true;
@@ -26271,10 +26366,17 @@ ${block}`);
26271
26366
  }
26272
26367
  }
26273
26368
  if (workspace) {
26274
- if (!fs10.existsSync(workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
26275
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26276
- nodeStatuses.push(status);
26277
- continue;
26369
+ if (!fs10.existsSync(workspace)) {
26370
+ if (applyCachedInlineMeshNodeStatus(status, node)) {
26371
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26372
+ nodeStatuses.push(status);
26373
+ continue;
26374
+ }
26375
+ if (meshRecord?.source === "inline_cache" && !isSelfNode) {
26376
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26377
+ nodeStatuses.push(status);
26378
+ continue;
26379
+ }
26278
26380
  }
26279
26381
  try {
26280
26382
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });