@adhdev/daemon-core 0.9.82-rc.130 → 0.9.82-rc.131

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
@@ -17013,6 +17013,21 @@ function readCliProviderNativeHistory(agentStr, args) {
17013
17013
  });
17014
17014
  return { ...sessionHistory, lookup: "session" };
17015
17015
  }
17016
+ function readLiveCodexWorkspaceNativeHistory(agentStr, args) {
17017
+ if (agentStr !== "codex-cli") return null;
17018
+ const workspace = typeof args.workspace === "string" ? args.workspace.trim() : "";
17019
+ if (!workspace) return null;
17020
+ const history = readProviderChatHistory(agentStr, {
17021
+ canonicalHistory: args.canonicalHistory,
17022
+ workspace,
17023
+ offset: args.offset,
17024
+ limit: args.limit,
17025
+ excludeRecentCount: args.excludeRecentCount,
17026
+ historyBehavior: args.historyBehavior,
17027
+ scripts: args.scripts
17028
+ });
17029
+ return { ...history, lookup: "workspace" };
17030
+ }
17016
17031
  function isNativeHistoryFreshEnough(args) {
17017
17032
  const nativeNewest = getMessageNewestReceivedAt(args.nativeMessages);
17018
17033
  const ptyNewest = getMessageNewestReceivedAt(args.ptyMessages);
@@ -17765,18 +17780,7 @@ async function handleReadChat(h, args) {
17765
17780
  ptyStatusApprovalOnly: true
17766
17781
  });
17767
17782
  } else {
17768
- const fallbackReason = buildNativeHistoryFallbackReason({
17769
- providerType,
17770
- provider,
17771
- nativeSource: nativeHistory.source,
17772
- nativeHistoryCoverage,
17773
- unavailableReason,
17774
- nativeMessageCount: nativeMessages.length,
17775
- safeMapping,
17776
- freshEnough
17777
- });
17778
- const unsafeNativeFallback = adapter.cliType === "codex-cli" && isUnsafeNativeTranscriptFallback(fallbackReason);
17779
- const safeCurrentRuntimePtyMessages = unsafeNativeFallback && isCurrentRuntimePtySafelyAttributed({
17783
+ const liveCurrentRuntimePtySafe = isCurrentRuntimePtySafelyAttributed({
17780
17784
  adapter,
17781
17785
  helpers: h,
17782
17786
  readChatArgs: args,
@@ -17784,57 +17788,130 @@ async function handleReadChat(h, args) {
17784
17788
  intendedWorkspace,
17785
17789
  ptyMessages: returnedMessages
17786
17790
  });
17787
- const safeRuntimeAckMessages = unsafeNativeFallback && !safeCurrentRuntimePtyMessages ? selectRuntimeInputAckMessages(returnedMessages) : [];
17788
- const exactRuntimeMirrorMessages = unsafeNativeFallback && !safeCurrentRuntimePtyMessages && safeRuntimeAckMessages.length === 0 ? readExactRuntimeMirrorMessages({
17789
- providerType,
17790
- targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
17791
- currentSessionId: typeof h.currentSession?.sessionId === "string" ? h.currentSession.sessionId : void 0,
17792
- tailLimit: nativeHistoryLimit,
17793
- historyBehavior: provider?.historyBehavior
17794
- }) : [];
17795
- const safeDaemonMessages = safeRuntimeAckMessages.length > 0 ? safeRuntimeAckMessages : exactRuntimeMirrorMessages;
17796
- if (unsafeNativeFallback) {
17797
- if (safeCurrentRuntimePtyMessages) {
17798
- selectedMessages = returnedMessages;
17799
- selectedTranscriptAuthority = "daemon";
17800
- selectedCoverage = coverage || "current-turn";
17801
- selectedStatus = returnedStatus;
17802
- } else {
17803
- selectedMessages = safeDaemonMessages;
17804
- selectedTranscriptAuthority = safeDaemonMessages.length > 0 ? "daemon" : void 0;
17805
- selectedCoverage = safeDaemonMessages.length > 0 ? "tail" : void 0;
17806
- selectedStatus = coerceUnsafeNativeFallbackStatus(returnedStatus, activeModal);
17807
- }
17808
- }
17809
- messageSource = buildCliMessageSourceProvenance({
17810
- selected: "pty-parser",
17811
- provider: adapter.cliType,
17812
- nativeHandle: historyProviderSessionId || nativeHistorySessionId || historySessionId,
17813
- sessionWorkspace,
17814
- intendedWorkspace,
17815
- transcriptWorkspace,
17816
- fallbackReason,
17817
- nativeSource: nativeHistory.source,
17818
- sourcePath: nativeHistory.sourcePath,
17819
- sourceMtimeMs: nativeHistory.sourceMtimeMs,
17820
- nativeHistoryCoverage,
17821
- partialReason,
17822
- unavailableReason,
17823
- nativeMessages,
17791
+ const mayProbeLiveCodexWorkspaceNative = adapter.cliType === "codex-cli" && liveCurrentRuntimePtySafe && !(typeof args?.providerSessionId === "string" && args.providerSessionId.trim()) && !(providerSessionId && providerSessionId.trim()) && (!historyProviderSessionId || historyProviderSessionId === nativeHistorySessionId || historyProviderSessionId === historySessionId);
17792
+ const liveWorkspaceNativeHistory = mayProbeLiveCodexWorkspaceNative ? readLiveCodexWorkspaceNativeHistory(agentStr, {
17793
+ canonicalHistory: provider?.canonicalHistory,
17794
+ workspace,
17795
+ offset: 0,
17796
+ limit: nativeHistoryLimit,
17797
+ excludeRecentCount: 0,
17798
+ historyBehavior: provider?.historyBehavior,
17799
+ scripts: provider?.scripts
17800
+ }) : null;
17801
+ const liveWorkspaceNativeMessages = Array.isArray(liveWorkspaceNativeHistory?.messages) ? normalizeNativeHistoryMessages(agentStr, liveWorkspaceNativeHistory.messages, liveWorkspaceNativeHistory?.providerSessionId) : [];
17802
+ const liveWorkspaceNativeProviderSessionId = typeof liveWorkspaceNativeHistory?.providerSessionId === "string" ? liveWorkspaceNativeHistory.providerSessionId : readHistorySessionIdFromMessages(liveWorkspaceNativeMessages);
17803
+ const liveWorkspaceTranscriptWorkspace = typeof liveWorkspaceNativeHistory?.workspace === "string" ? liveWorkspaceNativeHistory.workspace : liveWorkspaceNativeMessages.map((message) => typeof message?.workspace === "string" ? message.workspace.trim() : "").find(Boolean);
17804
+ const liveWorkspaceNativeSafeMapping = liveWorkspaceNativeMessages.length > 0 && hasSafeNativeHistoryMapping({
17805
+ workspace,
17806
+ nativeMessages: liveWorkspaceNativeMessages,
17824
17807
  ptyMessages: returnedMessages,
17825
- returnedMessages: unsafeNativeFallback && !safeCurrentRuntimePtyMessages ? safeDaemonMessages : returnedMessages,
17826
- safeMapping,
17827
- freshEnough,
17828
- ptyStatusApprovalOnly: unsafeNativeFallback && !safeCurrentRuntimePtyMessages
17808
+ requireWorkspaceContentOverlap: true
17809
+ });
17810
+ const liveWorkspaceNativeFreshEnough = liveWorkspaceNativeMessages.length > 0 && isNativeHistoryFreshEnough({
17811
+ sourceMtimeMs: liveWorkspaceNativeHistory?.sourceMtimeMs,
17812
+ nativeMessages: liveWorkspaceNativeMessages,
17813
+ ptyMessages: returnedMessages
17829
17814
  });
17830
- if (safeCurrentRuntimePtyMessages) {
17831
- messageSource.selectedDaemonSource = "current-runtime-pty";
17832
- messageSource.transcriptAuthority = "daemon";
17815
+ const liveWorkspaceNativeUsable = liveWorkspaceNativeHistory?.source === "provider-native" && liveWorkspaceNativeMessages.length > 0 && liveWorkspaceNativeHistory?.nativeHistoryCoverage !== "partial" && liveWorkspaceNativeHistory?.nativeHistoryCoverage !== "unavailable" && liveWorkspaceNativeSafeMapping && liveWorkspaceNativeFreshEnough;
17816
+ if (liveWorkspaceNativeUsable) {
17817
+ selectedMessages = finalizeStreamingMessagesWhenIdle(liveWorkspaceNativeMessages, returnedStatus);
17818
+ selectedProviderSessionId = liveWorkspaceNativeProviderSessionId || providerSessionId;
17819
+ selectedTranscriptAuthority = "provider";
17820
+ selectedCoverage = liveWorkspaceNativeHistory.hasMore ? "tail" : "full";
17821
+ messageSource = buildCliMessageSourceProvenance({
17822
+ selected: "native-history",
17823
+ provider: adapter.cliType,
17824
+ nativeHandle: selectedProviderSessionId || nativeHistorySessionId || historySessionId,
17825
+ sessionWorkspace,
17826
+ intendedWorkspace,
17827
+ transcriptWorkspace: liveWorkspaceTranscriptWorkspace,
17828
+ nativeSource: liveWorkspaceNativeHistory.source,
17829
+ sourcePath: liveWorkspaceNativeHistory.sourcePath,
17830
+ sourceMtimeMs: liveWorkspaceNativeHistory.sourceMtimeMs,
17831
+ nativeHistoryCoverage: liveWorkspaceNativeHistory.nativeHistoryCoverage,
17832
+ partialReason: liveWorkspaceNativeHistory.partialReason,
17833
+ unavailableReason: liveWorkspaceNativeHistory.unavailableReason,
17834
+ nativeMessages: liveWorkspaceNativeMessages,
17835
+ ptyMessages: returnedMessages,
17836
+ returnedMessages: selectedMessages,
17837
+ safeMapping: true,
17838
+ freshEnough: true,
17839
+ ptyStatusApprovalOnly: true
17840
+ });
17841
+ messageSource.selectedDaemonSource = "live-workspace-native-history";
17833
17842
  messageSource.runtimeMappingSafe = true;
17834
- }
17835
- if (unsafeNativeFallback && exactRuntimeMirrorMessages.length > 0) {
17836
- messageSource.selectedDaemonSource = "exact-runtime-mirror";
17837
- messageSource.transcriptAuthority = "daemon";
17843
+ } else {
17844
+ const fallbackReason = buildNativeHistoryFallbackReason({
17845
+ providerType,
17846
+ provider,
17847
+ nativeSource: nativeHistory.source,
17848
+ nativeHistoryCoverage,
17849
+ unavailableReason,
17850
+ nativeMessageCount: nativeMessages.length,
17851
+ safeMapping,
17852
+ freshEnough
17853
+ });
17854
+ const unsafeNativeFallback = adapter.cliType === "codex-cli" && isUnsafeNativeTranscriptFallback(fallbackReason);
17855
+ const safeCurrentRuntimePtyMessages = unsafeNativeFallback && isCurrentRuntimePtySafelyAttributed({
17856
+ adapter,
17857
+ helpers: h,
17858
+ readChatArgs: args,
17859
+ sessionWorkspace,
17860
+ intendedWorkspace,
17861
+ ptyMessages: returnedMessages
17862
+ });
17863
+ const safeRuntimeAckMessages = unsafeNativeFallback && !safeCurrentRuntimePtyMessages ? selectRuntimeInputAckMessages(returnedMessages) : [];
17864
+ const exactRuntimeMirrorMessages = unsafeNativeFallback && !safeCurrentRuntimePtyMessages && safeRuntimeAckMessages.length === 0 ? readExactRuntimeMirrorMessages({
17865
+ providerType,
17866
+ targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
17867
+ currentSessionId: typeof h.currentSession?.sessionId === "string" ? h.currentSession.sessionId : void 0,
17868
+ tailLimit: nativeHistoryLimit,
17869
+ historyBehavior: provider?.historyBehavior
17870
+ }) : [];
17871
+ const safeDaemonMessages = safeRuntimeAckMessages.length > 0 ? safeRuntimeAckMessages : exactRuntimeMirrorMessages;
17872
+ if (unsafeNativeFallback) {
17873
+ if (safeCurrentRuntimePtyMessages) {
17874
+ selectedMessages = returnedMessages;
17875
+ selectedTranscriptAuthority = "daemon";
17876
+ selectedCoverage = coverage || "current-turn";
17877
+ selectedStatus = returnedStatus;
17878
+ } else {
17879
+ selectedMessages = safeDaemonMessages;
17880
+ selectedTranscriptAuthority = safeDaemonMessages.length > 0 ? "daemon" : void 0;
17881
+ selectedCoverage = safeDaemonMessages.length > 0 ? "tail" : void 0;
17882
+ selectedStatus = coerceUnsafeNativeFallbackStatus(returnedStatus, activeModal);
17883
+ }
17884
+ }
17885
+ messageSource = buildCliMessageSourceProvenance({
17886
+ selected: "pty-parser",
17887
+ provider: adapter.cliType,
17888
+ nativeHandle: historyProviderSessionId || nativeHistorySessionId || historySessionId,
17889
+ sessionWorkspace,
17890
+ intendedWorkspace,
17891
+ transcriptWorkspace,
17892
+ fallbackReason,
17893
+ nativeSource: nativeHistory.source,
17894
+ sourcePath: nativeHistory.sourcePath,
17895
+ sourceMtimeMs: nativeHistory.sourceMtimeMs,
17896
+ nativeHistoryCoverage,
17897
+ partialReason,
17898
+ unavailableReason,
17899
+ nativeMessages,
17900
+ ptyMessages: returnedMessages,
17901
+ returnedMessages: unsafeNativeFallback && !safeCurrentRuntimePtyMessages ? safeDaemonMessages : returnedMessages,
17902
+ safeMapping,
17903
+ freshEnough,
17904
+ ptyStatusApprovalOnly: unsafeNativeFallback && !safeCurrentRuntimePtyMessages
17905
+ });
17906
+ if (safeCurrentRuntimePtyMessages) {
17907
+ messageSource.selectedDaemonSource = "current-runtime-pty";
17908
+ messageSource.transcriptAuthority = "daemon";
17909
+ messageSource.runtimeMappingSafe = true;
17910
+ }
17911
+ if (unsafeNativeFallback && exactRuntimeMirrorMessages.length > 0) {
17912
+ messageSource.selectedDaemonSource = "exact-runtime-mirror";
17913
+ messageSource.transcriptAuthority = "daemon";
17914
+ }
17838
17915
  }
17839
17916
  }
17840
17917
  }