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

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;
@@ -23865,8 +23955,21 @@ function summarizeMeshSessionRecord(record) {
23865
23955
  isCached: false
23866
23956
  };
23867
23957
  }
23958
+ function liveSessionRecordMatchesMeshNode(record, meshId, nodeId) {
23959
+ const recordNodeId = readStringValue(record?.meta?.meshNodeId);
23960
+ if (!recordNodeId || recordNodeId !== nodeId) return false;
23961
+ const recordMeshId = readStringValue(record?.meta?.meshNodeFor);
23962
+ return !recordMeshId || recordMeshId === meshId;
23963
+ }
23964
+ function liveSessionRecordMatchesMeshWorkspace(record, meshId, workspace) {
23965
+ const recordWorkspace = readStringValue(record?.workspace);
23966
+ if (!recordWorkspace || !workspace || recordWorkspace !== workspace) return false;
23967
+ const recordMeshId = readStringValue(record?.meta?.meshNodeFor);
23968
+ if (recordMeshId) return recordMeshId === meshId;
23969
+ return record?.meta?.launchedByCoordinator === true || !!readStringValue(record?.meta?.meshNodeId);
23970
+ }
23868
23971
  function readLiveMeshNodeWorkspace(args) {
23869
- const directNodeWorkspace = args.liveSessionRecords.find((record) => readStringValue(record?.meta?.meshNodeId) === args.nodeId && readStringValue(record?.workspace));
23972
+ const directNodeWorkspace = args.liveSessionRecords.find((record) => liveSessionRecordMatchesMeshNode(record, args.meshId, args.nodeId) && readStringValue(record?.workspace));
23870
23973
  if (directNodeWorkspace) {
23871
23974
  return readStringValue(directNodeWorkspace.workspace) || "";
23872
23975
  }
@@ -23880,10 +23983,9 @@ function readLiveMeshNodeWorkspace(args) {
23880
23983
  }
23881
23984
  function collectLiveMeshSessionRecords(args) {
23882
23985
  const matches = args.liveSessionRecords.filter((record) => {
23883
- if (readStringValue(record?.meta?.meshNodeId) === args.nodeId) return true;
23884
- const recordWorkspace = readStringValue(record?.workspace);
23885
23986
  const nodeWorkspace = readStringValue(args.node?.workspace);
23886
- return !!recordWorkspace && !!nodeWorkspace && recordWorkspace === nodeWorkspace;
23987
+ if (liveSessionRecordMatchesMeshNode(record, args.meshId, args.nodeId)) return true;
23988
+ return !!nodeWorkspace && liveSessionRecordMatchesMeshWorkspace(record, args.meshId, nodeWorkspace);
23887
23989
  });
23888
23990
  if (args.allowCoordinatorSession) {
23889
23991
  for (const record of args.liveSessionRecords) {
@@ -24325,10 +24427,15 @@ var DaemonCommandRouter = class {
24325
24427
  }
24326
24428
  warmInlineMeshCache(meshId, inlineMesh) {
24327
24429
  if (!inlineMesh || typeof inlineMesh !== "object") return void 0;
24430
+ const sanitizedInlineMesh = sanitizeInlineMesh(inlineMesh);
24328
24431
  const cached = this.inlineMeshCache.get(meshId);
24329
- if (cached) return cached;
24330
- this.inlineMeshCache.set(meshId, inlineMesh);
24331
- return inlineMesh;
24432
+ if (cached) {
24433
+ const merged = reconcileInlineMeshCache(cached, sanitizedInlineMesh);
24434
+ this.inlineMeshCache.set(meshId, merged);
24435
+ return merged;
24436
+ }
24437
+ this.inlineMeshCache.set(meshId, sanitizedInlineMesh);
24438
+ return sanitizedInlineMesh;
24332
24439
  }
24333
24440
  async getMeshForCommand(meshId, inlineMesh, options) {
24334
24441
  const preferInline = options?.preferInline === true;
@@ -26271,10 +26378,17 @@ ${block}`);
26271
26378
  }
26272
26379
  }
26273
26380
  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;
26381
+ if (!fs10.existsSync(workspace)) {
26382
+ if (applyCachedInlineMeshNodeStatus(status, node)) {
26383
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26384
+ nodeStatuses.push(status);
26385
+ continue;
26386
+ }
26387
+ if (meshRecord?.source === "inline_cache" && !isSelfNode) {
26388
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26389
+ nodeStatuses.push(status);
26390
+ continue;
26391
+ }
26278
26392
  }
26279
26393
  try {
26280
26394
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });