Repository navigation
fix(native-chat): gate view toggle to supported agents (Claude/Codex) - #6781
Conversation
The native chat toggle was shown for every agent terminal, not just the Claude/Codex sessions native chat can actually render. canToggleNativeChat only checked *whether* an agent was present (booleans hasDetectedAgent/ hasResolvedAgent + an unused launchAgent), so Grok, Gemini, and others incorrectly surfaced the 'Switch to chat view' control. Make the gate agent-aware: add a NATIVE_CHAT_SUPPORTED_AGENTS allowlist (claude, openclaude, codex) and require a supported agent on each signal path. Thread the real agent identity through all three call sites — the tab context menu (TabBar), the pane header/context menu (TerminalPane), and the keyboard shortcut — instead of collapsing it to a boolean. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThe native chat availability logic now uses explicit agent identity fields instead of boolean detection flags. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/components/terminal-pane/TerminalPane.tsx (1)
565-589: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftScope detected-agent eligibility to the leaf being toggled.
This selector returns the first agent status for the tab, but the header/context-menu actions toggle a specific leaf. In mixed split panes, a supported sibling can enable native chat for an unsupported active pane, or an unsupported first entry can hide it for a supported pane. Compute eligibility from
makePaneKey(tabId, leafId)for the active/header leaf and the context-menu leaf separately.Also applies to: 2420-2428, 2901-2903
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d063f717-4003-427d-9ca1-bcdd577510ad
📒 Files selected for processing (5)
src/renderer/src/components/native-chat/native-chat-availability.test.tssrc/renderer/src/components/native-chat/native-chat-availability.tssrc/renderer/src/components/native-chat/use-native-chat-toggle-shortcut.tssrc/renderer/src/components/tab-bar/TabBar.tsxsrc/renderer/src/components/terminal-pane/TerminalPane.tsx
Address CodeRabbit: agent-status pane keys are `${terminalTabId}:${leafId}`,
but the tab toggle (TabBar) and keyboard shortcut keyed the lookup by the
unified tab id, which can differ. That left the native-chat toggle inert for
manually-started supported agents unless another signal happened to resolve.
Use the backing terminal tab id (terminalTab.id / tab.entityId), matching the
working NativeChatView resolution path.
Co-authored-by: Orca <[email protected]>
|
Re: the "Scope detected-agent eligibility to the leaf being toggled" comment on This is a real edge case but it's a pre-existing limitation, not introduced by this PR. The original Properly fixing it is the "Heavy lift" the comment notes: Leaving it out of scope here to keep the fix focused; happy to follow up in a dedicated PR for split-pane per-leaf eligibility. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/tab-bar/TabBar.tsx (1)
453-455: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUpdate the stale pane-key explanation.
This still says live pane keys use
${unifiedTabId}:…, but the fixed lookup below correctly uses the backing terminal tab id. Keeping both explanations risks reintroducing the mismatch.Proposed comment update
- // Why: gate the tab long-press view-mode toggle to agent terminals. A tab is - // eligible when it launched an agent or has a live agent-status entry on any of - // its panes (paneKey = `${unifiedTabId}:…`), mirroring the toggle button's gate. + // Why: gate the tab long-press view-mode toggle to supported agent terminals. + // Live status uses pane keys minted from `${terminalTab.id}:${leafId}`, not + // unified tab ids, matching the per-tab view-mode gate below.Based on learnings, live agent-status entries in this path must be keyed by the backing terminal tab id. As per coding guidelines, non-obvious TS/TSX behavior should have short comments explaining why the code behaves that way.
Sources: Coding guidelines, Learnings
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 408b2ddf-1955-4041-a608-44278d83768f
📒 Files selected for processing (2)
src/renderer/src/components/native-chat/use-native-chat-toggle-shortcut.tssrc/renderer/src/components/tab-bar/TabBar.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/components/native-chat/use-native-chat-toggle-shortcut.ts
Problem
The experimental Native Chat view is only meant to work for Claude and Codex (its transcript/streaming parser is provider-specific). But the "Switch to chat view" toggle was showing for every agent terminal — Grok, Gemini, and the rest — even though native chat can't render those.
Root cause
canToggleNativeChatonly checked whether a terminal was running an agent, never which one. The agent's identity was discarded at every call site before the gate could see it:launchAgentwas passed but never inspectedhasDetectedAgent/hasResolvedAgent)So any truthy agent signal — regardless of provider — satisfied the gate.
Fix
Make the gate agent-aware:
NATIVE_CHAT_SUPPORTED_AGENTSallowlist (claude,openclaude,codex) and anisNativeChatSupportedAgent()helper innative-chat-availability.ts.detectedAgent,resolvedAgent) and require a supported agent on every signal path.TabBar.tsx— tab context menu (resolves the liveagentTypeviafindTabAgentEntry; removed the now-deadtabIdsWithLiveAgentmemo)TerminalPane.tsx— pane header + context menuuse-native-chat-toggle-shortcut.ts— keyboard chord (stays inert on unsupported agents)All three mattered: fixing only the menu would still let Grok enter native chat via the header or the shortcut.
Testing
native-chat-availability.test.ts(Grok/Gemini rejected via launch hint, live detection, and title resolution) — 13/13 pass.pnpm typecheck(web project) andoxlinton the changed files are clean.Made with Orca 🐋