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

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.129",
3
+ "version": "0.9.82-rc.130",
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",
@@ -494,6 +494,62 @@ function readExactRuntimeMirrorMessages(args: {
494
494
  });
495
495
  }
496
496
 
497
+ function normalizeComparableWorkspace(value: unknown): string {
498
+ const text = typeof value === 'string' ? value.trim() : '';
499
+ if (!text) return '';
500
+ return path.resolve(text);
501
+ }
502
+
503
+ function isCurrentRuntimePtySafelyAttributed(args: {
504
+ adapter: CliAdapter;
505
+ helpers: CommandHelpers;
506
+ readChatArgs: any;
507
+ sessionWorkspace?: string;
508
+ intendedWorkspace?: string;
509
+ ptyMessages: ChatMessage[];
510
+ }): boolean {
511
+ if (args.adapter.cliType !== 'codex-cli') return false;
512
+ if (!Array.isArray(args.ptyMessages) || args.ptyMessages.length === 0) return false;
513
+ const targetSessionId = typeof args.readChatArgs?.targetSessionId === 'string'
514
+ ? args.readChatArgs.targetSessionId.trim()
515
+ : '';
516
+ const currentSession = args.helpers.currentSession as any;
517
+ const currentSessionId = typeof currentSession?.sessionId === 'string'
518
+ ? currentSession.sessionId.trim()
519
+ : '';
520
+ if (!targetSessionId || !currentSessionId || targetSessionId !== currentSessionId) return false;
521
+
522
+ const runtimeMeta = typeof (args.adapter as any).getRuntimeMetadata === 'function'
523
+ ? (args.adapter as any).getRuntimeMetadata()
524
+ : null;
525
+ const runtimeId = typeof runtimeMeta?.runtimeId === 'string' ? runtimeMeta.runtimeId.trim() : '';
526
+ if (!runtimeId || runtimeId !== targetSessionId) return false;
527
+ const surfaceKind = typeof runtimeMeta?.surfaceKind === 'string' ? runtimeMeta.surfaceKind : '';
528
+ if (surfaceKind === 'inactive_record' || surfaceKind === 'recovery_snapshot') return false;
529
+
530
+ const sessionWorkspace = normalizeComparableWorkspace(args.sessionWorkspace);
531
+ const adapterWorkspace = normalizeComparableWorkspace(args.adapter.workingDir);
532
+ if (!sessionWorkspace || !adapterWorkspace || sessionWorkspace !== adapterWorkspace) return false;
533
+ const intendedWorkspace = normalizeComparableWorkspace(args.intendedWorkspace);
534
+ if (intendedWorkspace && intendedWorkspace !== sessionWorkspace) return false;
535
+
536
+ const registryEntry = args.helpers.ctx?.sessionRegistry?.get?.(targetSessionId) as any;
537
+ const registryInstanceKey = typeof registryEntry?.adapterKey === 'string' && registryEntry.adapterKey.trim()
538
+ ? registryEntry.adapterKey.trim()
539
+ : typeof registryEntry?.instanceKey === 'string' && registryEntry.instanceKey.trim()
540
+ ? registryEntry.instanceKey.trim()
541
+ : '';
542
+ if (registryInstanceKey) {
543
+ const targetInstance = args.helpers.ctx?.instanceManager?.getInstance?.(registryInstanceKey);
544
+ if (targetInstance) {
545
+ const instanceType = typeof (targetInstance as any).type === 'string' ? (targetInstance as any).type : '';
546
+ if (instanceType && instanceType !== args.adapter.cliType) return false;
547
+ }
548
+ }
549
+
550
+ return true;
551
+ }
552
+
497
553
  function supportsCliNativeTranscript(providerType: string, provider?: ProviderModule): boolean {
498
554
  if (CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType)) return true;
499
555
  return provider?.category === 'cli' && isNativeSourceCanonicalHistory(provider?.canonicalHistory);
@@ -1552,10 +1608,21 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
1552
1608
  });
1553
1609
  const unsafeNativeFallback = adapter.cliType === 'codex-cli'
1554
1610
  && isUnsafeNativeTranscriptFallback(fallbackReason);
1611
+ const safeCurrentRuntimePtyMessages = unsafeNativeFallback
1612
+ && isCurrentRuntimePtySafelyAttributed({
1613
+ adapter,
1614
+ helpers: h,
1615
+ readChatArgs: args,
1616
+ sessionWorkspace,
1617
+ intendedWorkspace,
1618
+ ptyMessages: returnedMessages,
1619
+ });
1555
1620
  const safeRuntimeAckMessages = unsafeNativeFallback
1621
+ && !safeCurrentRuntimePtyMessages
1556
1622
  ? selectRuntimeInputAckMessages(returnedMessages)
1557
1623
  : [];
1558
1624
  const exactRuntimeMirrorMessages = unsafeNativeFallback
1625
+ && !safeCurrentRuntimePtyMessages
1559
1626
  && safeRuntimeAckMessages.length === 0
1560
1627
  ? readExactRuntimeMirrorMessages({
1561
1628
  providerType,
@@ -1569,10 +1636,17 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
1569
1636
  ? safeRuntimeAckMessages
1570
1637
  : exactRuntimeMirrorMessages;
1571
1638
  if (unsafeNativeFallback) {
1572
- selectedMessages = safeDaemonMessages;
1573
- selectedTranscriptAuthority = safeDaemonMessages.length > 0 ? 'daemon' : undefined;
1574
- selectedCoverage = safeDaemonMessages.length > 0 ? 'tail' : undefined;
1575
- selectedStatus = coerceUnsafeNativeFallbackStatus(returnedStatus, activeModal);
1639
+ 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);
1649
+ }
1576
1650
  }
1577
1651
  messageSource = buildCliMessageSourceProvenance({
1578
1652
  selected: 'pty-parser',
@@ -1590,11 +1664,16 @@ export async function handleReadChat(h: CommandHelpers, args: any): Promise<Comm
1590
1664
  unavailableReason,
1591
1665
  nativeMessages,
1592
1666
  ptyMessages: returnedMessages,
1593
- returnedMessages: unsafeNativeFallback ? safeDaemonMessages : returnedMessages,
1667
+ returnedMessages: unsafeNativeFallback && !safeCurrentRuntimePtyMessages ? safeDaemonMessages : returnedMessages,
1594
1668
  safeMapping,
1595
1669
  freshEnough,
1596
- ptyStatusApprovalOnly: unsafeNativeFallback,
1670
+ ptyStatusApprovalOnly: unsafeNativeFallback && !safeCurrentRuntimePtyMessages,
1597
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
+ }
1598
1677
  if (unsafeNativeFallback && exactRuntimeMirrorMessages.length > 0) {
1599
1678
  (messageSource as any).selectedDaemonSource = 'exact-runtime-mirror';
1600
1679
  (messageSource as any).transcriptAuthority = 'daemon';