Skip to content

feat(native-chat): restore the terminal/chat switcher for bridge chat only - #18532

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/restore-tui-chat-switcher
Sep 3, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/restore-tui-chat-switcher

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​196 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​188
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​441 $\color{#cf222e}{\Huge{\mathbf{−}}}$​85 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​356

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 — canSwitchNativeChatView in native-chat-availability.ts refuses whenever a structuredSessionId is present, layered over the existing canToggleNativeChat eligibility:

  • Standalone structured tabs (contentType: 'agent-session') were already excluded by the existing contentType === 'terminal' check.
  • The new guard covers the remaining case: a terminal tab that adopted a structured session.
  • The keyboard hook applies the same rule against tab.structuredSessionId.

Surfaces restored

Surface File
Pane header chat/terminal button TerminalPaneHeaderOverlay.tsx
Pane context menu item TerminalContextMenu.tsx
Tab context menu item SortableTabContextMenu.tsx
Keyboard chord TerminalPaneOverlayLayer.tsx

The chord's hook (use-native-chat-toggle-shortcut.ts) survived #16729 uncalled — its single call site was deleted, leaving it dead along with three stale vi.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 the native_chat_toggled telemetry all survived the removal. This change rewires the surfaces to live actions.

Collateral, called out explicitly

SortableTab.tsx was sitting exactly at its 400-line cap, so any addition overflowed it. Rather than suppress max-lines (forbidden by AGENTS.md), its inline-rename state and the window rename-request listener move into use-sortable-tab-rename.ts. Pure extraction, no behavior change — SortableTab.rename-shortcut.test.tsx passes unmodified.

Two ratchets move for real, each with the reason recorded in the file:

  • Store subscription budget — per-pane listeners stay pinned at 17; the folded action bundle is still a single listener, so the new toggleTabViewMode key costs nothing at runtime. Only the counterfactual pre-fold constant grows 48 → 49.
  • Hook-order parity — 204 → 208 hooks for four added useCallbacks (three in chat-state, one in projection). useMemo count unchanged at 8.

Testing

  • pnpm tc (web project) clean; oxlint clean on all touched directories.
  • Full native-chat suite: 96 files passed.
  • Full terminal-pane suite: 4179/4182, with the 3 remaining failures being rotating remote-runtime-pty-transport-* timeouts that pass in isolation and touch none of these files.
  • Pre-existing flakes confirmed against the base commit a35451f5b9: the same tab-bar group 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, identity restore-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.

Claude bridge chat with Show terminal tooltip

Claude TUI after switching from chat

Claude chat after round-trip switch

Claude tab context menu: 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.

Structured Codex chat with no switcher

Structured Codex tab context menu without switcher

Not exercised in this pass: the pane context-menu item and the keyboard chord. Dark theme only.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 2f2af63b-3eef-45b7-8829-03fa15b4c7de

📥 Commits

Reviewing files that changed from the base of the PR and between 42c6c49 and 24a39c0.

📒 Files selected for processing (1)
  • src/shared/pane-agent-identity-inventory.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The 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 24a39

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 … Add the required linked issue after Fixes #. Add or explicitly mark the remaining template sections as applicable, complete the checklist confirmations, and state any non-applicable items such as AI Disclosure or the Agent skill upstream …
Docstring Coverage ⚠️ Warning Docstring coverage is 36.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 23 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes restoring the terminal/chat switcher for bridge native chat while excluding structured sessions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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 Fixes #. Add or explicitly mark the remaining template sections as applicable, complete the checklist confirmations, and state any non-applicable items such as AI Disclosure or the Agent skill upstream boundary.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron CDP visual proof

Validated on a dedicated restore-switcher-review @ brennanb2025/restore-tui-chat-switcher dev instance (identity + Dock tile matched this worktree). Experimental Chat UI + structured native chat enabled. No product code changed.

Bridge Claude: pane-header Show terminal is present; click switches to the live TUI and back. Tab context menu includes Switch to terminal view.

Claude bridge chat with Show terminal tooltip

Claude TUI after switching from chat

Claude tab context menu: Switch to terminal view

Structured Codex Chat: no pane-header switcher, and the tab context menu has no Switch to terminal/chat item.

Structured Codex chat with no switcher

Structured Codex tab context menu without switcher

Not exercised: pane context-menu item and keyboard chord. Dark theme only.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 — canSwitchNativeChatView refuses the switch when a structuredSessionId is present, layered over the existing canToggleNativeChat eligibility.
  • Per-leaf toggling — use-terminal-pane-chat-state.ts adds canToggleChatForLeaf/toggleNativeChatForLeaf/handleToggleNativeChat, scoping "always allow toggling back" to the leaf currently showing chat.
  • Surface rewiring — TerminalPaneHeaderOverlay, TerminalContextMenu, SortableTabContextMenu render the switcher per leaf; TerminalPaneOverlayLayer re-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.tsx gains 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 fires onToggleNativeChat when canToggleNativeChat is true.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Merge Sim added 2 commits September 3, 2026 15:43
… 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.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/restore-tui-chat-switcher branch from aabd3c7 to 42c6c49 Compare September 3, 2026 22:43
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status for brennanb2025/restore-tui-chat-switcher (head 42c6c497d3):

  • Rebased onto the latest origin/main and force-with-lease pushed to this same PR branch.
  • Same-model review loop is clean after two focused fixes: restored the bridge native-chat context-menu return-to-terminal action, and restored retained aiVaultTitle.agent evidence for tab-menu/keyboard eligibility. Structured/Codex native chat remains switcher-free.
  • Verification: 586 renderer test files / 5,619 tests passed across native-chat, tab-bar, and terminal-pane; focused post-commit checks 54/54 passed; pnpm tc:web passed; changed-code quality and React Doctor report 0 new findings; git diff --check clean.
  • Electron CDP proof is attached in the PR body: bridge header round-trip and tab context-menu switcher, plus structured Codex header/tab menus with no switcher.
  • Remaining QA note: pane context-menu activation and keyboard-chord activation were not separately clicked in Electron; both are covered by focused tests, and the visual surfaces are present in the attached proof.

Recommendation: ready to merge once the required GitHub checks finish green.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.tsx
  • src/renderer/src/components/native-chat/native-chat-availability.test.ts
  • src/renderer/src/components/native-chat/use-native-chat-context-menu.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-context-menu.tsx
  • src/renderer/src/components/native-chat/use-native-chat-toggle-shortcut.ts
  • src/renderer/src/components/tab-bar/native-chat-tab-agent-evidence.test.ts
  • src/renderer/src/components/tab-bar/native-chat-tab-agent-evidence.ts
  • src/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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
items.list.some((candidate) => childrenText(candidate.children) === 'Switch to terminal view')
items.list.some((candidate) =>
childrenText(candidate.children).startsWith('Switch to terminal view')
)

Comment on lines +81 to +84
const titleFallbackAgent =
tabWideFallbackSafe && terminalTab
? resolveNativeChatTabAgentEvidence(terminalTab, tab)
: null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 — useNativeChatContextMenu renders a "Switch to terminal view" item (with the ⌘⇧J chord label) when a bridge callback is supplied.
  • Wired onSwitchToTerminal through NativeChatResolvedView for bridge chat; structured mode never passes it, so organized sessions get no item.
  • Added canSwitchNativeChatView coverage — three new cases close the previous test gap.
  • Extracted resolveNativeChatTabAgentEvidence to 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).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

renderToStaticMarkup(<Harness />)

expect(
items.list.some((candidate) => childrenText(candidate.children) === 'Switch to terminal view')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
items.list.some((candidate) => childrenText(candidate.children) === 'Switch to terminal view')
items.list.some((candidate) =>
childrenText(candidate.children).startsWith('Switch to terminal view')
)

@brennanb2025

Copy link
Copy Markdown
Contributor Author

CI follow-up: the red test / tests node 24 3/8 was a real PR-side ratchet mismatch caused by moving the agent-evidence helper; I updated src/shared/pane-agent-identity-inventory.test.ts and pushed 24a39c0e3c. The replacement shard is running now.

static analysis is still red at the pre-existing runtime-required localization catalog check for four onboarding capability keys (browseIssues, managePullRequests, reviewStatus, startWorkspaceFromIssue). The PR has no localization-file changes; those keys were added on origin/main by c79e1c097b without regenerating en-runtime-required.json. verify is red only because it aggregates static-analysis + test results. I am leaving that unrelated catalog repair out of this focused PR.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

CI rerun update for head 24a39c0e3c: all 8 Node 24 test shards now pass, including the previously failing shard 3/8; typecheck, packaging (Linux/Windows), guards, and change detection also pass. The only remaining red check is static analysis at the same pre-existing runtime-required localization catalog drift (the four onboarding capability keys from c79e1c097b, absent from en-runtime-required.json). verify will consequently remain blocked by that static-analysis result; no PR localization files were changed.

@brennanb2025
brennanb2025 merged commit e85ebb0 into main Sep 3, 2026
26 of 28 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant