@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.82-rc.130",
3
+ "version": "0.9.82-rc.131",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -676,6 +676,30 @@ function readCliProviderNativeHistory(agentStr: string, args: {
676
676
  return { ...(sessionHistory as any), lookup: 'session' };
677
677
  }
678
678
 
679
+ function readLiveCodexWorkspaceNativeHistory(agentStr: string, args: {
680
+ canonicalHistory?: ProviderModule['canonicalHistory'];
681
+ workspace?: string;
682
+ offset: number;
683
+ limit: number;
684
+ excludeRecentCount: number;
685
+ historyBehavior?: ProviderModule['historyBehavior'];
686
+ scripts?: ProviderScripts;
687
+ }): (ReturnType<typeof readProviderChatHistory> & { lookup: 'workspace' }) | null {
688
+ if (agentStr !== 'codex-cli') return null;
689
+ const workspace = typeof args.workspace === 'string' ? args.workspace.trim() : '';
690
+ if (!workspace) return null;
691
+ const history = readProviderChatHistory(agentStr, {
692
+ canonicalHistory: args.canonicalHistory,
693
+ workspace,
694
+ offset: args.offset,
695
+ limit: args.limit,
696
+ excludeRecentCount: args.excludeRecentCount,
697
+ historyBehavior: args.historyBehavior,
698
+ scripts: args.scripts as any,
699
+ });
700
+ return { ...(history as any), lookup: 'workspace' };
701
+ }
702
+
679
703
  function isNativeHistoryFreshEnough(args: {
680
704
  sourceMtimeMs?: number;
681
705
  nativeMessages: ChatMessage[];
@@ -1596,87 +1620,168 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
1596
1620
  ptyStatusApprovalOnly: true,
1597
1621
  });
1598
1622
  } else {
1599
- const fallbackReason = buildNativeHistoryFallbackReason({
1600
- providerType,
1601
- provider,
1602
- nativeSource: (nativeHistory as any).source,
1603
- nativeHistoryCoverage,
1604
- unavailableReason,
1605
- nativeMessageCount: nativeMessages.length,
1606
- safeMapping,
1607
- freshEnough,
1623
+ const liveCurrentRuntimePtySafe = isCurrentRuntimePtySafelyAttributed({
1624
+ adapter,
1625
+ helpers: h,
1626
+ readChatArgs: args,
1627
+ sessionWorkspace,
1628
+ intendedWorkspace,
1629
+ ptyMessages: returnedMessages,
1608
1630
  });
1609
- const unsafeNativeFallback = adapter.cliType === 'codex-cli'
1610
- && isUnsafeNativeTranscriptFallback(fallbackReason);
1611
- const safeCurrentRuntimePtyMessages = unsafeNativeFallback
1612
- && isCurrentRuntimePtySafelyAttributed({
1613
- adapter,
1614
- helpers: h,
1615
- readChatArgs: args,
1631
+ const mayProbeLiveCodexWorkspaceNative = adapter.cliType === 'codex-cli'
1632
+ && liveCurrentRuntimePtySafe
1633
+ && !(typeof args?.providerSessionId === 'string' && args.providerSessionId.trim())
1634
+ && !(providerSessionId && providerSessionId.trim())
1635
+ && (!historyProviderSessionId || historyProviderSessionId === nativeHistorySessionId || historyProviderSessionId === historySessionId);
1636
+ const liveWorkspaceNativeHistory = mayProbeLiveCodexWorkspaceNative
1637
+ ? readLiveCodexWorkspaceNativeHistory(agentStr, {
1638
+ canonicalHistory: provider?.canonicalHistory,
1639
+ workspace,
1640
+ offset: 0,
1641
+ limit: nativeHistoryLimit,
1642
+ excludeRecentCount: 0,
1643
+ historyBehavior: provider?.historyBehavior,
1644
+ scripts: provider?.scripts as any,
1645
+ })
1646
+ : null;
1647
+ const liveWorkspaceNativeMessages = Array.isArray((liveWorkspaceNativeHistory as any)?.messages)
1648
+ ? normalizeNativeHistoryMessages(agentStr, (liveWorkspaceNativeHistory as any).messages as ChatMessage[], (liveWorkspaceNativeHistory as any)?.providerSessionId)
1649
+ : [];
1650
+ const liveWorkspaceNativeProviderSessionId = typeof (liveWorkspaceNativeHistory as any)?.providerSessionId === 'string'
1651
+ ? (liveWorkspaceNativeHistory as any).providerSessionId
1652
+ : readHistorySessionIdFromMessages(liveWorkspaceNativeMessages);
1653
+ const liveWorkspaceTranscriptWorkspace = typeof (liveWorkspaceNativeHistory as any)?.workspace === 'string'
1654
+ ? (liveWorkspaceNativeHistory as any).workspace
1655
+ : liveWorkspaceNativeMessages.map((message: any) => typeof message?.workspace === 'string' ? message.workspace.trim() : '').find(Boolean);
1656
+ const liveWorkspaceNativeSafeMapping = liveWorkspaceNativeMessages.length > 0
1657
+ && hasSafeNativeHistoryMapping({
1658
+ workspace,
1659
+ nativeMessages: liveWorkspaceNativeMessages,
1660
+ ptyMessages: returnedMessages,
1661
+ requireWorkspaceContentOverlap: true,
1662
+ });
1663
+ const liveWorkspaceNativeFreshEnough = liveWorkspaceNativeMessages.length > 0
1664
+ && isNativeHistoryFreshEnough({
1665
+ sourceMtimeMs: (liveWorkspaceNativeHistory as any)?.sourceMtimeMs,
1666
+ nativeMessages: liveWorkspaceNativeMessages,
1667
+ ptyMessages: returnedMessages,
1668
+ });
1669
+ const liveWorkspaceNativeUsable = (liveWorkspaceNativeHistory as any)?.source === 'provider-native'
1670
+ && liveWorkspaceNativeMessages.length > 0
1671
+ && (liveWorkspaceNativeHistory as any)?.nativeHistoryCoverage !== 'partial'
1672
+ && (liveWorkspaceNativeHistory as any)?.nativeHistoryCoverage !== 'unavailable'
1673
+ && liveWorkspaceNativeSafeMapping
1674
+ && liveWorkspaceNativeFreshEnough;
1675
+ if (liveWorkspaceNativeUsable) {
1676
+ selectedMessages = finalizeStreamingMessagesWhenIdle(liveWorkspaceNativeMessages, returnedStatus);
1677
+ selectedProviderSessionId = liveWorkspaceNativeProviderSessionId || providerSessionId;
1678
+ selectedTranscriptAuthority = 'provider';
1679
+ selectedCoverage = (liveWorkspaceNativeHistory as any).hasMore ? 'tail' : 'full';
1680
+ messageSource = buildCliMessageSourceProvenance({
1681
+ selected: 'native-history',
1682
+ provider: adapter.cliType,
1683
+ nativeHandle: selectedProviderSessionId || nativeHistorySessionId || historySessionId,
1616
1684
  sessionWorkspace,
1617
1685
  intendedWorkspace,
1686
+ transcriptWorkspace: liveWorkspaceTranscriptWorkspace,
1687
+ nativeSource: (liveWorkspaceNativeHistory as any).source,
1688
+ sourcePath: (liveWorkspaceNativeHistory as any).sourcePath,
1689
+ sourceMtimeMs: (liveWorkspaceNativeHistory as any).sourceMtimeMs,
1690
+ nativeHistoryCoverage: (liveWorkspaceNativeHistory as any).nativeHistoryCoverage,
1691
+ partialReason: (liveWorkspaceNativeHistory as any).partialReason,
1692
+ unavailableReason: (liveWorkspaceNativeHistory as any).unavailableReason,
1693
+ nativeMessages: liveWorkspaceNativeMessages,
1618
1694
  ptyMessages: returnedMessages,
1695
+ returnedMessages: selectedMessages,
1696
+ safeMapping: true,
1697
+ freshEnough: true,
1698
+ ptyStatusApprovalOnly: true,
1619
1699
  });
1620
- const safeRuntimeAckMessages = unsafeNativeFallback
1621
- && !safeCurrentRuntimePtyMessages
1622
- ? selectRuntimeInputAckMessages(returnedMessages)
1623
- : [];
1624
- const exactRuntimeMirrorMessages = unsafeNativeFallback
1625
- && !safeCurrentRuntimePtyMessages
1626
- && safeRuntimeAckMessages.length === 0
1627
- ? readExactRuntimeMirrorMessages({
1700
+ (messageSource as any).selectedDaemonSource = 'live-workspace-native-history';
1701
+ (messageSource as any).runtimeMappingSafe = true;
1702
+ } else {
1703
+ const fallbackReason = buildNativeHistoryFallbackReason({
1628
1704
  providerType,
1629
- targetSessionId: typeof args?.targetSessionId === 'string' ? args.targetSessionId : undefined,
1630
- currentSessionId: typeof (h.currentSession as any)?.sessionId === 'string' ? (h.currentSession as any).sessionId : undefined,
1631
- tailLimit: nativeHistoryLimit,
1632
- historyBehavior: provider?.historyBehavior,
1633
- })
1634
- : [];
1635
- const safeDaemonMessages = safeRuntimeAckMessages.length > 0
1636
- ? safeRuntimeAckMessages
1637
- : exactRuntimeMirrorMessages;
1638
- if (unsafeNativeFallback) {
1705
+ provider,
1706
+ nativeSource: (nativeHistory as any).source,
1707
+ nativeHistoryCoverage,
1708
+ unavailableReason,
1709
+ nativeMessageCount: nativeMessages.length,
1710
+ safeMapping,
1711
+ freshEnough,
1712
+ });
1713
+ const unsafeNativeFallback = adapter.cliType === 'codex-cli'
1714
+ && isUnsafeNativeTranscriptFallback(fallbackReason);
1715
+ const safeCurrentRuntimePtyMessages = unsafeNativeFallback
1716
+ && isCurrentRuntimePtySafelyAttributed({
1717
+ adapter,
1718
+ helpers: h,
1719
+ readChatArgs: args,
1720
+ sessionWorkspace,
1721
+ intendedWorkspace,
1722
+ ptyMessages: returnedMessages,
1723
+ });
1724
+ const safeRuntimeAckMessages = unsafeNativeFallback
1725
+ && !safeCurrentRuntimePtyMessages
1726
+ ? selectRuntimeInputAckMessages(returnedMessages)
1727
+ : [];
1728
+ const exactRuntimeMirrorMessages = unsafeNativeFallback
1729
+ && !safeCurrentRuntimePtyMessages
1730
+ && safeRuntimeAckMessages.length === 0
1731
+ ? readExactRuntimeMirrorMessages({
1732
+ providerType,
1733
+ targetSessionId: typeof args?.targetSessionId === 'string' ? args.targetSessionId : undefined,
1734
+ currentSessionId: typeof (h.currentSession as any)?.sessionId === 'string' ? (h.currentSession as any).sessionId : undefined,
1735
+ tailLimit: nativeHistoryLimit,
1736
+ historyBehavior: provider?.historyBehavior,
1737
+ })
1738
+ : [];
1739
+ const safeDaemonMessages = safeRuntimeAckMessages.length > 0
1740
+ ? safeRuntimeAckMessages
1741
+ : exactRuntimeMirrorMessages;
1742
+ if (unsafeNativeFallback) {
1743
+ if (safeCurrentRuntimePtyMessages) {
1744
+ selectedMessages = returnedMessages;
1745
+ selectedTranscriptAuthority = 'daemon';
1746
+ selectedCoverage = coverage || 'current-turn';
1747
+ selectedStatus = returnedStatus;
1748
+ } else {
1749
+ selectedMessages = safeDaemonMessages;
1750
+ selectedTranscriptAuthority = safeDaemonMessages.length > 0 ? 'daemon' : undefined;
1751
+ selectedCoverage = safeDaemonMessages.length > 0 ? 'tail' : undefined;
1752
+ selectedStatus = coerceUnsafeNativeFallbackStatus(returnedStatus, activeModal);
1753
+ }
1754
+ }
1755
+ messageSource = buildCliMessageSourceProvenance({
1756
+ selected: 'pty-parser',
1757
+ provider: adapter.cliType,
1758
+ nativeHandle: historyProviderSessionId || nativeHistorySessionId || historySessionId,
1759
+ sessionWorkspace,
1760
+ intendedWorkspace,
1761
+ transcriptWorkspace,
1762
+ fallbackReason,
1763
+ nativeSource: (nativeHistory as any).source,
1764
+ sourcePath: (nativeHistory as any).sourcePath,
1765
+ sourceMtimeMs: (nativeHistory as any).sourceMtimeMs,
1766
+ nativeHistoryCoverage,
1767
+ partialReason,
1768
+ unavailableReason,
1769
+ nativeMessages,
1770
+ ptyMessages: returnedMessages,
1771
+ returnedMessages: unsafeNativeFallback && !safeCurrentRuntimePtyMessages ? safeDaemonMessages : returnedMessages,
1772
+ safeMapping,
1773
+ freshEnough,
1774
+ ptyStatusApprovalOnly: unsafeNativeFallback && !safeCurrentRuntimePtyMessages,
1775
+ });
1639
1776
  if (safeCurrentRuntimePtyMessages) {
1640
- selectedMessages = returnedMessages;
1641
- selectedTranscriptAuthority = 'daemon';
1642
- selectedCoverage = coverage || 'current-turn';
1643
- selectedStatus = returnedStatus;
1644
- } else {
1645
- selectedMessages = safeDaemonMessages;
1646
- selectedTranscriptAuthority = safeDaemonMessages.length > 0 ? 'daemon' : undefined;
1647
- selectedCoverage = safeDaemonMessages.length > 0 ? 'tail' : undefined;
1648
- selectedStatus = coerceUnsafeNativeFallbackStatus(returnedStatus, activeModal);
1777
+ (messageSource as any).selectedDaemonSource = 'current-runtime-pty';
1778
+ (messageSource as any).transcriptAuthority = 'daemon';
1779
+ (messageSource as any).runtimeMappingSafe = true;
1780
+ }
1781
+ if (unsafeNativeFallback && exactRuntimeMirrorMessages.length > 0) {
1782
+ (messageSource as any).selectedDaemonSource = 'exact-runtime-mirror';
1783
+ (messageSource as any).transcriptAuthority = 'daemon';
1649
1784
  }
1650
- }
1651
- messageSource = buildCliMessageSourceProvenance({
1652
- selected: 'pty-parser',
1653
- provider: adapter.cliType,
1654
- nativeHandle: historyProviderSessionId || nativeHistorySessionId || historySessionId,
1655
- sessionWorkspace,
1656
- intendedWorkspace,
1657
- transcriptWorkspace,
1658
- fallbackReason,
1659
- nativeSource: (nativeHistory as any).source,
1660
- sourcePath: (nativeHistory as any).sourcePath,
1661
- sourceMtimeMs: (nativeHistory as any).sourceMtimeMs,
1662
- nativeHistoryCoverage,
1663
- partialReason,
1664
- unavailableReason,
1665
- nativeMessages,
1666
- ptyMessages: returnedMessages,
1667
- returnedMessages: unsafeNativeFallback && !safeCurrentRuntimePtyMessages ? safeDaemonMessages : returnedMessages,
1668
- safeMapping,
1669
- freshEnough,
1670
- ptyStatusApprovalOnly: unsafeNativeFallback && !safeCurrentRuntimePtyMessages,
1671
- });
1672
- if (safeCurrentRuntimePtyMessages) {
1673
- (messageSource as any).selectedDaemonSource = 'current-runtime-pty';
1674
- (messageSource as any).transcriptAuthority = 'daemon';
1675
- (messageSource as any).runtimeMappingSafe = true;
1676
- }
1677
- if (unsafeNativeFallback && exactRuntimeMirrorMessages.length > 0) {
1678
- (messageSource as any).selectedDaemonSource = 'exact-runtime-mirror';
1679
- (messageSource as any).transcriptAuthority = 'daemon';
1680
1785
  }
1681
1786
  }
1682
1787
  }