Repository navigation
feat(native-chat): restore the terminal/chat switcher for bridge chat only - #18532
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe change restores terminal-to-native-chat view switching through tab menus, terminal context menus, the pane header, the native-chat context menu, and a keyboard shortcut. Structured sessions cannot use the switcher. Toggle state flows through chat state, pane projection, and tab rendering. Native-chat agent evidence uses unified-tab and terminal metadata. Tab rename behavior moves into a dedicated hook. Tests update related hook-order, subscription-budget, availability, context-menu, and agent-evidence expectations. Merge Risk: ⚪ Minimal · up to This update aligns the agent-identity inventory with the relocated native-chat evidence helper. No current merge-blocking behavior or user-impacting issue remains. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description gives a detailed, relevant summary, rationale, implementation scope, testing results, and visual proof. However, it omits the required Linked Issue entry and several template sections or checklist confirmations, including ELI5, AI Disclosure, Review, Notes, Agent skill upstream boundary, and Checklist. Resolution Add the required linked issue after
✨ Finishing Touches 💡 1📝 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 |
Electron CDP visual proofValidated on a dedicated Bridge Claude: pane-header Show terminal is present; click switches to the live TUI and back. Tab context menu includes Switch to terminal view. Structured Codex Chat: no pane-header switcher, and the tab context menu has no Switch to terminal/chat item. Not exercised: pane context-menu item and keyboard chord. Dark theme only. |
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions inline.
Reviewed changes
Restores the terminal ⇄ native-chat view switcher for bridge (terminal-backed) chat while keeping it absent for structured sessions, gated by the new canSwitchNativeChatView rule. Rewires four surfaces (pane header button, pane context menu, tab context menu, keyboard chord) to live toggleTabViewMode/per-leaf chat actions, and extracts SortableTab's inline rename state into use-sortable-tab-rename.ts to stay under the 400-line cap.
- Native-chat gate —
canSwitchNativeChatViewrefuses the switch when astructuredSessionIdis present, layered over the existingcanToggleNativeChateligibility. - Per-leaf toggling —
use-terminal-pane-chat-state.tsaddscanToggleChatForLeaf/toggleNativeChatForLeaf/handleToggleNativeChat, scoping "always allow toggling back" to the leaf currently showing chat. - Surface rewiring —
TerminalPaneHeaderOverlay,TerminalContextMenu,SortableTabContextMenurender the switcher per leaf;TerminalPaneOverlayLayerre-wires the previously-dead keyboard hook. - SortableTab rename extraction — pure move to
use-sortable-tab-rename.ts, no behavior change. - Ratchet updates — hook-order parity 204→208 (still 8
useMemo) and store-subscription pre-fold constant 48→49 (per-pane budget stays 17).
ℹ️ Nitpicks
TerminalContextMenu.test.tsxgains the three new props as defaults (canToggleNativeChat: false, …) but only asserts the negative case (the item stays hidden); there's no positive case that the "Switch to chat/terminal view" item renders and firesonToggleNativeChatwhencanToggleNativeChatis true.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| // contentType gates out standalone structured (agent-session) tabs; | ||
| // structuredSessionId gates out a terminal tab that adopted one, which | ||
| // renders the structured surface with no TUI to switch back to. | ||
| if (!tab || tab.contentType !== 'terminal' || tab.structuredSessionId) { |
There was a problem hiding this comment.
The keyboard hook reimplements the structured-session gate inline (tab.structuredSessionId) instead of calling canSwitchNativeChatView like the tab bar does, which slightly undercuts the 'one rule, one place' intent. The canToggleNativeChat call below already passes every other field, so swapping it for canSwitchNativeChatView({ ..., structuredSessionId: tab.structuredSessionId ?? null }) would subsume this check and keep the three surfaces on the same rule.
… only #16729 removed every user-facing terminal<->chat switching affordance as a side effect of the structured Codex restructure ("renderer switching affordances and their dead leftovers"). That was right for structured Codex sessions, which render their own transcript with no live TUI underneath, but it also took the switcher away from bridge native chat, which still reads the terminal and has one to return to. Restore all four surfaces, each gated so structured sessions keep the removal: - pane header chat/terminal button (TerminalPaneHeaderOverlay) - pane context-menu "Switch to chat/terminal view" (TerminalContextMenu) - tab context-menu equivalent (SortableTabContextMenu) - the keyboard chord, whose hook had survived uncalled since #16729 Gating is one rule in one place: `canSwitchNativeChatView` refuses whenever a `structuredSessionId` is present, over the existing `canToggleNativeChat` eligibility. Standalone structured tabs are already excluded by the `contentType === 'terminal'` check; the new guard covers a terminal tab that adopted a structured session. The shortcut hook applies the same rule. The state plumbing (`viewMode`, `setTabViewMode`, `toggleTabViewMode`, host mirroring, `native_chat_toggled` telemetry) was never removed, so this rewires live actions rather than reintroducing logic. SortableTab.tsx sat exactly at its 400-line cap, so its inline-rename state and the window rename-request listener move to `use-sortable-tab-rename.ts` to make room. No behavior change; its rename tests pass unmodified. Two ratchets move for real, explained in place: - store-subscription budget: per-pane listeners stay pinned at 17 (the folded action bundle is still one listener); only the counterfactual pre-fold constant grows 48 -> 49 for the added `toggleTabViewMode` key. - hook-order parity: 204 -> 208 hooks for the four added `useCallback`s, useMemo count unchanged at 8.
aabd3c7 to
42c6c49
Compare
|
Review status for
Recommendation: ready to merge once the required GitHub checks finish green. |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: c52c6206-f92a-465e-a63f-011215e5f31e
📥 Commits
Reviewing files that changed from the base of the PR and between aabd3c71a33de6fbfc64b236dedee2516cfb908b and 42c6c49.
📒 Files selected for processing (8)
src/renderer/src/components/native-chat/NativeChatResolvedView.tsxsrc/renderer/src/components/native-chat/native-chat-availability.test.tssrc/renderer/src/components/native-chat/use-native-chat-context-menu.test.tsxsrc/renderer/src/components/native-chat/use-native-chat-context-menu.tsxsrc/renderer/src/components/native-chat/use-native-chat-toggle-shortcut.tssrc/renderer/src/components/tab-bar/native-chat-tab-agent-evidence.test.tssrc/renderer/src/components/tab-bar/native-chat-tab-agent-evidence.tssrc/renderer/src/components/tab-bar/tab-bar-item-surface.tsx
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| renderToStaticMarkup(<Harness />) | ||
|
|
||
| expect( | ||
| items.list.some((candidate) => childrenText(candidate.children) === 'Switch to terminal view') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Detect the switch command with the full rendered text.
Line 107 compares the complete menu-item text to only the label. DropdownMenuShortcut adds the shortcut text, so this assertion passes even when the switch command is present. Use the same startsWith predicate as the positive test.
Proposed fix
- items.list.some((candidate) => childrenText(candidate.children) === 'Switch to terminal view')
+ items.list.some((candidate) =>
+ childrenText(candidate.children).startsWith('Switch to terminal view')
+ )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| items.list.some((candidate) => childrenText(candidate.children) === 'Switch to terminal view') | |
| items.list.some((candidate) => | |
| childrenText(candidate.children).startsWith('Switch to terminal view') | |
| ) |
| const titleFallbackAgent = | ||
| tabWideFallbackSafe && terminalTab | ||
| ? resolveNativeChatTabAgentEvidence(terminalTab, tab) | ||
| : null |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Require the backing terminal tab before processing the shortcut.
Line 82 only disables title fallback when terminalTab is absent. It does not stop the shortcut flow. A retained agentStatusByPaneKey entry can still provide detectedAgent, pass the availability check, and call toggleTabViewMode without a terminal to return to. Add if (!terminalTab) return before agent evaluation.
There was a problem hiding this comment.
ℹ️ No critical issues — the bridge escape hatch and agent-evidence refactor look correct; one minor test assertion could be tightened.
Reviewed changes
- Restored the native-chat context-menu escape hatch —
useNativeChatContextMenurenders a "Switch to terminal view" item (with the ⌘⇧J chord label) when a bridge callback is supplied. - Wired
onSwitchToTerminalthroughNativeChatResolvedViewfor bridge chat; structured mode never passes it, so organized sessions get no item. - Added
canSwitchNativeChatViewcoverage — three new cases close the previous test gap. - Extracted
resolveNativeChatTabAgentEvidenceto unify agent resolution across the tab bar and the keyboard hook, adding a retained AI-Vault-title fallback (precedence: unified label → terminal title → AI-Vault agent).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| renderToStaticMarkup(<Harness />) | ||
|
|
||
| expect( | ||
| items.list.some((candidate) => childrenText(candidate.children) === 'Switch to terminal view') |
There was a problem hiding this comment.
The negative assertion compares childrenText(...) === 'Switch to terminal view', but the mocked DropdownMenuShortcut appends the chord label, so a rendered item's text is Switch to terminal view⌘⇧J and never equals the bare label. That makes this check pass even if the item were rendered without a bridge callback — the test can't catch that regression. Use startsWith, matching the positive test.
| items.list.some((candidate) => childrenText(candidate.children) === 'Switch to terminal view') | |
| items.list.some((candidate) => | |
| childrenText(candidate.children).startsWith('Switch to terminal view') | |
| ) |
|
CI follow-up: the red
|
|
CI rerun update for head |
… only (stablyai#18532) * feat(native-chat): restore the terminal/chat switcher for bridge chat only stablyai#16729 removed every user-facing terminal<->chat switching affordance as a side effect of the structured Codex restructure ("renderer switching affordances and their dead leftovers"). That was right for structured Codex sessions, which render their own transcript with no live TUI underneath, but it also took the switcher away from bridge native chat, which still reads the terminal and has one to return to. Restore all four surfaces, each gated so structured sessions keep the removal: - pane header chat/terminal button (TerminalPaneHeaderOverlay) - pane context-menu "Switch to chat/terminal view" (TerminalContextMenu) - tab context-menu equivalent (SortableTabContextMenu) - the keyboard chord, whose hook had survived uncalled since stablyai#16729 Gating is one rule in one place: `canSwitchNativeChatView` refuses whenever a `structuredSessionId` is present, over the existing `canToggleNativeChat` eligibility. Standalone structured tabs are already excluded by the `contentType === 'terminal'` check; the new guard covers a terminal tab that adopted a structured session. The shortcut hook applies the same rule. The state plumbing (`viewMode`, `setTabViewMode`, `toggleTabViewMode`, host mirroring, `native_chat_toggled` telemetry) was never removed, so this rewires live actions rather than reintroducing logic. SortableTab.tsx sat exactly at its 400-line cap, so its inline-rename state and the window rename-request listener move to `use-sortable-tab-rename.ts` to make room. No behavior change; its rename tests pass unmodified. Two ratchets move for real, explained in place: - store-subscription budget: per-pane listeners stay pinned at 17 (the folded action bundle is still one listener); only the counterfactual pre-fold constant grows 48 -> 49 for the added `toggleTabViewMode` key. - hook-order parity: 204 -> 208 hooks for the four added `useCallback`s, useMemo count unchanged at 8. * fix(native-chat): restore bridge chat escape hatch * test: update pane agent identity inventory --------- Co-authored-by: Merge Sim <sim@local>






What
Brings back the terminal ⇄ chat UI switcher for everything that still reads the terminal, while keeping it removed for Codex restructured (structured) native chat.
Why
The switcher wasn't removed on purpose as its own change — it was collateral in #16729 (Codex structured native chat restructure), whose commit message lists "renderer switching affordances and their dead leftovers" under Deliberately not ported.
That call was correct for structured Codex sessions: a structured session is the conversation and owns its whole surface, with no live TUI underneath to switch back to — which is exactly why making the switcher work there is awkward. But the same removal also stripped it from bridge native chat, which still reads the terminal and does have one to return to. Since #16729 there has been no way for a user to flip a bridge chat pane back to the TUI at all; the only remaining escape hatch was programmatic (
onSwitchToTerminal, fired when a session-option command needs the agent's own picker).The gate
One rule, one place —
canSwitchNativeChatViewinnative-chat-availability.tsrefuses whenever astructuredSessionIdis present, layered over the existingcanToggleNativeChateligibility:contentType: 'agent-session') were already excluded by the existingcontentType === 'terminal'check.tab.structuredSessionId.Surfaces restored
TerminalPaneHeaderOverlay.tsxTerminalContextMenu.tsxSortableTabContextMenu.tsxTerminalPaneOverlayLayer.tsxThe chord's hook (
use-native-chat-toggle-shortcut.ts) survived #16729 uncalled — its single call site was deleted, leaving it dead along with three stalevi.mocks that mocked a module the component no longer loaded. It is wired up again rather than rewritten.No state plumbing was reintroduced:
viewMode,setTabViewMode,toggleTabViewMode, host mirroring and thenative_chat_toggledtelemetry all survived the removal. This change rewires the surfaces to live actions.Collateral, called out explicitly
SortableTab.tsxwas sitting exactly at its 400-line cap, so any addition overflowed it. Rather than suppressmax-lines(forbidden byAGENTS.md), its inline-rename state and the window rename-request listener move intouse-sortable-tab-rename.ts. Pure extraction, no behavior change —SortableTab.rename-shortcut.test.tsxpasses unmodified.Two ratchets move for real, each with the reason recorded in the file:
toggleTabViewModekey costs nothing at runtime. Only the counterfactual pre-fold constant grows 48 → 49.useCallbacks (three in chat-state, one in projection).useMemocount unchanged at 8.Testing
pnpm tc(web project) clean;oxlintclean on all touched directories.native-chatsuite: 96 files passed.terminal-panesuite: 4179/4182, with the 3 remaining failures being rotatingremote-runtime-pty-transport-*timeouts that pass in isolation and touch none of these files.a35451f5b9: the sametab-bargroup fails 8 tests there without any of these changes (BrowserTab ×5, TabBar.context-menu ×3), versus fewer on this branch.Visual proof (Electron CDP)
Validated in a dedicated dev instance of this worktree (
Orca: brennanb2025/restore-tui-chat-switcher, identityrestore-switcher-review @ brennanb2025/restore-tui-chat-switcher). Experimental Chat UI + structured native chat were enabled. No product code was changed.Bridge (Claude Code,
contentType: terminal,viewMode: chat): the pane-header switcher is present. Hovering it shows Show terminal; clicking it reveals the live Claude TUI and the button becomes Show chat view; clicking again returns to chat. The tab context menu includes Switch to terminal view.Structured (Codex Chat,
contentType: agent-session): no pane-header switcher, and the tab context menu has no Switch to terminal/chat item.Not exercised in this pass: the pane context-menu item and the keyboard chord. Dark theme only.