@adhdev/daemon-core 0.9.82-rc.117 → 0.9.82-rc.118

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
@@ -16654,6 +16654,7 @@ function buildCliMessageSourceProvenance(args) {
16654
16654
  }
16655
16655
  function buildNativeHistoryFallbackReason(args) {
16656
16656
  if (!supportsCliNativeTranscript(args.providerType, args.provider)) return "provider_native_transcript_not_supported";
16657
+ if (args.unavailableReason) return `native_history_unavailable:${args.unavailableReason}`;
16657
16658
  if (args.nativeSource === "native-unavailable") return "native_history_unavailable";
16658
16659
  if (args.nativeHistoryCoverage === "partial") return "native_history_partial";
16659
16660
  if (args.nativeHistoryCoverage === "unavailable") return "native_history_unavailable";
@@ -16728,6 +16729,15 @@ function hasSafeNativeHistoryMapping(args) {
16728
16729
  return hasOverlappingVisibleConversationText(args.nativeMessages, args.ptyMessages || []);
16729
16730
  }
16730
16731
  function readCliProviderNativeHistory(agentStr, args) {
16732
+ if (!args.historySessionId) {
16733
+ return {
16734
+ messages: [],
16735
+ hasMore: false,
16736
+ source: "native-unavailable",
16737
+ unavailableReason: "native_history_workspace_only_lookup_unsafe",
16738
+ lookup: "session"
16739
+ };
16740
+ }
16731
16741
  const sessionHistory = readProviderChatHistory(agentStr, {
16732
16742
  canonicalHistory: args.canonicalHistory,
16733
16743
  historySessionId: args.historySessionId,
@@ -16738,20 +16748,7 @@ function readCliProviderNativeHistory(agentStr, args) {
16738
16748
  historyBehavior: args.historyBehavior,
16739
16749
  scripts: args.scripts
16740
16750
  });
16741
- if (sessionHistory.source !== "native-unavailable" || args.exactSessionScoped || !args.historySessionId || !args.workspace) {
16742
- return { ...sessionHistory, lookup: args.historySessionId ? "session" : "workspace" };
16743
- }
16744
- const workspaceHistory = readProviderChatHistory(agentStr, {
16745
- canonicalHistory: args.canonicalHistory,
16746
- historySessionId: void 0,
16747
- workspace: args.workspace,
16748
- offset: args.offset,
16749
- limit: args.limit,
16750
- excludeRecentCount: args.excludeRecentCount,
16751
- historyBehavior: args.historyBehavior,
16752
- scripts: args.scripts
16753
- });
16754
- return { ...workspaceHistory, lookup: "workspace" };
16751
+ return { ...sessionHistory, lookup: "session" };
16755
16752
  }
16756
16753
  function isNativeHistoryFreshEnough(args) {
16757
16754
  const nativeNewest = getMessageNewestReceivedAt(args.nativeMessages);
@@ -17494,6 +17491,7 @@ async function handleReadChat(h, args) {
17494
17491
  provider,
17495
17492
  nativeSource: nativeHistory.source,
17496
17493
  nativeHistoryCoverage,
17494
+ unavailableReason,
17497
17495
  nativeMessageCount: nativeMessages.length,
17498
17496
  safeMapping,
17499
17497
  freshEnough
@@ -17593,6 +17591,7 @@ async function handleReadChat(h, args) {
17593
17591
  provider,
17594
17592
  nativeSource: history.source,
17595
17593
  nativeHistoryCoverage,
17594
+ unavailableReason,
17596
17595
  nativeMessageCount: historyMessages.length,
17597
17596
  safeMapping,
17598
17597
  freshEnough: true
@@ -27714,9 +27713,12 @@ function summarizeMeshSessionRecord(record) {
27714
27713
  isCached: false
27715
27714
  };
27716
27715
  }
27717
- function liveSessionRecordMatchesMeshNode(record, meshId, nodeId) {
27716
+ function liveSessionRecordMatchesMeshNode(record, meshId, nodeId, nodeWorkspace = "", nodeIsMissingLocalWorktree = false) {
27718
27717
  const recordNodeId = readStringValue(record?.meta?.meshNodeId);
27719
27718
  if (!recordNodeId || recordNodeId !== nodeId) return false;
27719
+ if (nodeIsMissingLocalWorktree) return false;
27720
+ const recordWorkspace = readStringValue(record?.workspace);
27721
+ if (nodeWorkspace && recordWorkspace && recordWorkspace !== nodeWorkspace) return false;
27720
27722
  const recordMeshId = readStringValue(record?.meta?.meshNodeFor);
27721
27723
  return !recordMeshId || recordMeshId === meshId;
27722
27724
  }
@@ -27741,9 +27743,13 @@ function readLiveMeshNodeWorkspace(args) {
27741
27743
  return "";
27742
27744
  }
27743
27745
  function collectLiveMeshSessionRecords(args) {
27746
+ const nodeWorkspace = readStringValue(args.node?.workspace);
27747
+ const nodeIsMissingLocalWorktree = args.node?.isLocalWorktree === true && !!nodeWorkspace && !fs11.existsSync(nodeWorkspace);
27744
27748
  const matches = args.liveSessionRecords.filter((record) => {
27745
- const nodeWorkspace = readStringValue(args.node?.workspace);
27746
- if (liveSessionRecordMatchesMeshNode(record, args.meshId, args.nodeId)) return true;
27749
+ const recordNodeId = readStringValue(record?.meta?.meshNodeId);
27750
+ if (recordNodeId && recordNodeId !== args.nodeId) return false;
27751
+ if (liveSessionRecordMatchesMeshNode(record, args.meshId, args.nodeId, nodeWorkspace || "", nodeIsMissingLocalWorktree)) return true;
27752
+ if (nodeIsMissingLocalWorktree) return false;
27747
27753
  return !!nodeWorkspace && liveSessionRecordMatchesMeshWorkspace(record, args.meshId, nodeWorkspace);
27748
27754
  });
27749
27755
  if (args.allowCoordinatorSession) {
@@ -27759,11 +27765,15 @@ function collectLiveMeshSessionRecords(args) {
27759
27765
  function buildHistoricalMeshSessions(args) {
27760
27766
  const liveNodeIds = /* @__PURE__ */ new Set();
27761
27767
  const liveWorkspaces = /* @__PURE__ */ new Set();
27768
+ const missingLocalWorktreeNodeIds = /* @__PURE__ */ new Set();
27762
27769
  for (const node of args.nodes || []) {
27763
27770
  const nodeId = readStringValue(node?.id, node?.nodeId);
27764
27771
  const workspace = readStringValue(node?.workspace);
27765
27772
  if (nodeId) liveNodeIds.add(nodeId);
27766
27773
  if (workspace) liveWorkspaces.add(workspace);
27774
+ if (nodeId && node?.isLocalWorktree === true && workspace && !fs11.existsSync(workspace)) {
27775
+ missingLocalWorktreeNodeIds.add(nodeId);
27776
+ }
27767
27777
  }
27768
27778
  const sessions = [];
27769
27779
  for (const record of args.liveSessionRecords || []) {
@@ -27772,7 +27782,7 @@ function buildHistoricalMeshSessions(args) {
27772
27782
  if (recordMeshId !== args.meshId) continue;
27773
27783
  const recordNodeId = readStringValue(meta.meshNodeId);
27774
27784
  const workspace = readStringValue(record?.workspace);
27775
- const removedNode = !!recordNodeId && !liveNodeIds.has(recordNodeId);
27785
+ const removedNode = !!recordNodeId && (!liveNodeIds.has(recordNodeId) || missingLocalWorktreeNodeIds.has(recordNodeId));
27776
27786
  const orphanedWorkspace = !!workspace && !liveWorkspaces.has(workspace) && meta.meshCoordinatorFor !== args.meshId;
27777
27787
  if (!removedNode && !orphanedWorkspace) continue;
27778
27788
  sessions.push({
@@ -31526,12 +31536,18 @@ ${block2}`);
31526
31536
  for (const [nodeIndex, node] of (mesh.nodes || []).entries()) {
31527
31537
  const nodeId = String(node.id || node.nodeId || "");
31528
31538
  const daemonId = readStringValue(node.daemonId);
31539
+ const nodeMachineId = readMeshNodeMachineId(node);
31540
+ const nodeHostname = readMeshNodeHostname(node);
31529
31541
  const providerPriority = readProviderPriorityFromPolicy(node.policy);
31542
+ const configuredCoordinatorNode = Boolean(
31543
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
31544
+ );
31545
+ const sparseConfiguredCoordinatorNode = configuredCoordinatorNode && !daemonId && !nodeMachineId && !nodeHostname;
31530
31546
  const isSelfNode = Boolean(
31531
31547
  nodeId && inlineCoordinatorNodeId && nodeId === inlineCoordinatorNodeId
31532
31548
  ) || Boolean(
31533
31549
  daemonId && (daemonId === localMachineId || daemonId === this.deps.statusInstanceId)
31534
- ) || Boolean(meshRecord?.inline && nodeIndex === 0);
31550
+ ) || Boolean(meshRecord?.inline && nodeIndex === 0) || sparseConfiguredCoordinatorNode;
31535
31551
  const machineIdentity = buildMeshNodeMachineIdentity(node, {
31536
31552
  localMachineId,
31537
31553
  localDaemonId: this.deps.statusInstanceId,
@@ -31548,7 +31564,7 @@ ${block2}`);
31548
31564
  worktreeBranch: node.worktreeBranch,
31549
31565
  role: normalizeMeshDaemonRole(node.role) || (meshHost.hostNodeId && nodeId === meshHost.hostNodeId ? "host" : void 0),
31550
31566
  daemonId,
31551
- machineId: readMeshNodeMachineId(node) || node.machineId,
31567
+ machineId: nodeMachineId || node.machineId,
31552
31568
  machine: machineIdentity,
31553
31569
  machineStatus: node.machineStatus,
31554
31570
  health: "unknown",