Skip to content

feat(native-chat): per-leaf toggle eligibility + composer UX (paste, draft, scrollbar, focus) - #6783

Merged
Jinwoo-H merged 8 commits into
mainfrom
Jinwoo-H/native-chat-per-leaf-and-composer-ux
Jun 30, 2026
Merged

Jinwoo-H merged 8 commits into
mainfrom
Jinwoo-H/native-chat-per-leaf-and-composer-ux

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #6781 with one resolved review comment plus four composer UX improvements.

1. Per-leaf toggle eligibility (resolves CodeRabbit #3 from #6781)

#6781 gated the native-chat toggle to supported agents but computed eligibility tab-wide, while the toggle acts per-leaf. In a split pane mixing a supported agent (Claude/Codex) in one leaf with an unsupported one (Grok) in another, the toggle could appear on the wrong leaf.

  • The header toggle now gates on the active leaf; the context-menu toggle gates on the leaf the menu was opened over — each keyed by makePaneKey(tabId, leafId).
  • A leaf's own live agent is authoritative; the tab-wide launch/title hints only fill in before hooks arrive (or single-pane), so they can't enable the toggle on a sibling actually running an unsupported agent.
  • The store selector is scoped to this tab's panes (leafId → agentType) and shallow-compared, so an unrelated tab's status tick no longer re-renders this pane.

2. Backspace/Delete focuses the composer

Mirrors the existing printable-typing redirect: pressing Backspace/Delete while the chat pane (not the field) is focused now focuses the composer. Focus-only — the key isn't inserted, the now-focused field handles it.

3. Composer scrollbar

The draft textarea used the heavy native scrollbar once it overflowed max-height. Added scrollbar-sleek (the app's standard treatment; also satisfies the styled-scrollbar lint).

4. Cmd/Ctrl+V image paste (TUI parity)

Pasting an image only worked when the textarea itself was focused; the pane-level Cmd+V path was text-only. Added a pasteFromClipboard handle that tries an image attachment first, falls back to text, and routed the pane-level shortcut, context-menu paste, and app-menu paste through it.

5. Draft survives a TUI→GUI→TUI toggle

The draft was local useState and was lost when the composer unmounted on toggle. Extracted useNativeChatDraft, which backs the draft by a module-level scope cache (same targetPtyId ?? terminalTabId key as image attachments), so an unsent message + its attachments both survive the round-trip.

Testing

  • New unit tests: native-chat-draft-cache (round-trip + clear-drops-entry) and Backspace/Delete focus helper cases. Existing availability tests still pass.
  • pnpm typecheck (web), oxlint, oxlint --config oxlint-react-doctor, and the styled-scrollbar check are clean on the changed files. No new react-doctor warnings (draft/caret reload use the render-time adjustment pattern, not effects).
  • 3 pre-existing native-chat test files fail to import due to an unrelated missing @/lib/onboarding-folder-agent-startup module in repos.ts (reproduces on main); all 229 runnable tests pass.

Note: Best reviewed after #6781 (now merged). The first commit was rebased onto current main, so this PR contains only the changes above.

Made with Orca 🐋

Five native-chat improvements:

- Per-leaf toggle eligibility (CodeRabbit #3 follow-up): a split pane can
  mix a supported agent (Claude/Codex) in one leaf with an unsupported one
  (Grok) in another. The header toggle now gates on the active leaf and the
  context-menu toggle on the menu's target leaf, each keyed by
  makePaneKey(tabId, leafId). A leaf's live agent is authoritative; tab-wide
  launch/title hints only fill in pre-hook so they can't enable the toggle on
  a sibling running an unsupported agent. Scoped + shallow-compared store
  selector avoids re-rendering on unrelated tabs' status ticks.

- Backspace/Delete focuses the composer when the pane (not the field) is
  focused, mirroring the printable-typing redirect — focus only, no insert.

- Composer textarea uses scrollbar-sleek so the overflow gutter stops showing
  the heavy native scrollbar once the draft exceeds max-height.

- Cmd/Ctrl+V pastes a clipboard image as an attachment (TUI parity) even when
  the chat pane — not the textarea — holds focus, via a new
  pasteFromClipboard handle that tries image first then falls back to text.
  Routes the context-menu and app-menu paste through the same path.

- Draft text now survives a TUI->GUI->TUI toggle: extracted useNativeChatDraft
  backs the draft by a module-level scope cache (same key as attachments).

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds scoped native chat draft persistence with cache-backed restoration, routes clipboard paste and Backspace/Delete focus behavior through native chat view and composer methods, changes attachment handling so images remain in the composer until submit, adds Enter-only native chat prompt submission, and updates terminal pane chat toggle eligibility to be leaf-specific.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning It covers summary/testing, but omits required template sections for Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections, include screenshots or a no-visual-change note, complete the testing checklist, and summarize the AI review, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. 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 is concise and accurately highlights the main native-chat composer and per-leaf toggle changes.
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.

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.

@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: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a2920ff4-dae8-4362-b7b4-c276ea04d2d2

📥 Commits

Reviewing files that changed from the base of the PR and between c80dc43 and ea9c7c4.

📒 Files selected for processing (10)
  • src/renderer/src/components/native-chat/NativeChatComposer.tsx
  • src/renderer/src/components/native-chat/NativeChatComposerField.tsx
  • src/renderer/src/components/native-chat/NativeChatView.tsx
  • src/renderer/src/components/native-chat/native-chat-composer-target.ts
  • src/renderer/src/components/native-chat/native-chat-draft-cache.test.ts
  • src/renderer/src/components/native-chat/native-chat-draft-cache.ts
  • src/renderer/src/components/native-chat/native-chat-typing-redirect.test.ts
  • src/renderer/src/components/native-chat/native-chat-typing-redirect.ts
  • src/renderer/src/components/native-chat/use-native-chat-draft.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx

- Per-leaf eligibility (Major): canToggleNativeChat returns true whenever
  isChatViewMode is set, so passing the tab-wide flag re-enabled the toggle on
  an unsupported sibling whenever any leaf in the split was in chat view. Scope
  the 'allow toggling back' rule to the leaf actually showing chat
  (chatLeafId === leafId).

- Backspace/Delete redirect (Minor): also exclude Shift/Alt chords (cut,
  delete-word) so modified-key behavior stays with the focused target. Added
  shiftKey/altKey to the predicate + tests, plus a defaultPrevented test case.

- Clipboard paste staleness (Major): re-read the live disabled state after the
  async clipboard round-trip via a ref, so a canSend flip / pty drop mid-paste
  can't attach or insert into a guarded composer. Extracted the paste concern
  into useNativeChatComposerPaste (also keeps NativeChatComposer under the
  max-lines limit).

Co-authored-by: Orca <[email protected]>

@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: 1

♻️ Duplicate comments (1)
src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts (1)

85-103: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Avoid resuming text paste with a stale draft snapshot.

After the async clipboard reads, Line 102 still calls the insertTypedText closure captured at paste start. In src/renderer/src/components/native-chat/NativeChatComposer.tsx Lines 172-192, that helper rebuilds from the closed-over draft, so characters typed before the clipboard promise resolves can be dropped when the paste lands. Re-read the latest draft/selection at resume time, or make insertion use a functional setDraft update instead.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3f7e5e8b-1a9e-438f-825f-8c5e52b3843e

📥 Commits

Reviewing files that changed from the base of the PR and between ea9c7c4 and 42c5d63.

📒 Files selected for processing (5)
  • src/renderer/src/components/native-chat/NativeChatComposer.tsx
  • src/renderer/src/components/native-chat/native-chat-typing-redirect.test.ts
  • src/renderer/src/components/native-chat/native-chat-typing-redirect.ts
  • src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/components/native-chat/native-chat-typing-redirect.test.ts
  • src/renderer/src/components/native-chat/native-chat-typing-redirect.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx

The composer textarea's React onPaste did not reliably fire for a real
Cmd/Ctrl+V — verified live over CDP: the paste event does not consistently
dispatch to the textarea's React handler (the composer can also mount more
than once), so image paste silently did nothing while the attach button
worked.

Handle paste at the pane root via a capture-phase 'paste' listener that
routes the event into the composer (handlePasteEvent). An image is
intercepted + attached (same immediate bracketed-paste send as the attach
button); text falls through to the native textarea paste. A defaultPrevented
guard dedupes against the textarea's own onPaste so a single paste attaches
once. Replaces the old keydown-based Cmd+V handler that bailed whenever the
textarea was focused.

Verified end-to-end over CDP: focused composer + clipboard screenshot +
Cmd+V attaches exactly one chip; text paste unaffected; empty clipboard is a
no-op.

Co-authored-by: Orca <[email protected]>

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4ea77aed-c655-4bfe-b4ee-b00ee28021ed

📥 Commits

Reviewing files that changed from the base of the PR and between 42c5d63 and 8b72ffb.

📒 Files selected for processing (3)
  • src/renderer/src/components/native-chat/NativeChatComposer.tsx
  • src/renderer/src/components/native-chat/NativeChatView.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/native-chat/use-native-chat-composer-paste.ts
  • src/renderer/src/components/native-chat/NativeChatComposer.tsx

Jinwoo-H and others added 2 commits June 29, 2026 17:07
…ocused

The real cause of paste doing nothing: Cmd/Ctrl+V is claimed by the Edit >
Paste menu accelerator (register-app-menu.ts), which sends an app-menu paste
event instead of producing a DOM paste event on the composer. NativeChatView's
app-menu-paste handler gated on shouldFocusNativeChatPaneFromPointerTarget(
activeElement) being true — which is false for an interactive element — so when
the composer textarea was focused (the normal case) it bailed and nothing
happened. (Earlier CDP tests passed only because synthetic keyboard.press emits
a real DOM paste, bypassing the menu accelerator the real keystroke goes
through.)

Route the app-menu paste into the composer whenever focus is anywhere inside
the chat pane root, including the textarea itself. Verified live over CDP: with
the composer focused, the app-menu paste event now attaches an image chip and
inserts text; no duplication.

Co-authored-by: Orca <[email protected]>
…n sync

Images were pasted into the hosted TUI immediately on attach while text was
held in the GUI draft until submit. That asymmetry meant the X button could
remove a chip from the GUI while the image stayed in the TUI's input buffer,
and image/text ordering didn't match what the user composed.

Hold pasted images as pending chips (like text) and send them — images, then
text body, then Enter — atomically on submit via
sendNativeChatMessageWithImageAttachments. attachLocalPaths no longer writes to
the pty, so removing a chip is a pure GUI operation with nothing to un-paste,
and the GUI composer and TUI input never diverge. Removes the now-dead
sendNativeChatImageAttachments helper.

Co-authored-by: Orca <[email protected]>

@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: Pro

Run ID: 2a2dcd58-1bcf-4bc8-84da-8a60e7654d11

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb4cf8 and 5ec47b5.

📒 Files selected for processing (5)
  • src/renderer/src/components/native-chat/NativeChatComposer.tsx
  • src/renderer/src/components/native-chat/native-chat-runtime-send.test.ts
  • src/renderer/src/components/native-chat/native-chat-runtime-send.ts
  • src/renderer/src/components/native-chat/use-native-chat-composer-attachments.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-attachments.ts

Jinwoo-H and others added 3 commits June 29, 2026 19:13
- CI red: the two new attachment tests read a stale `api` snapshot captured
  before the attach re-render. Track the freshest snapshot via a latest()
  getter so the deferred-chip assertions see post-update state. (Earlier local
  runs masked this by omitting --config config/vitest.config.ts, so the file
  failed to import instead of running — it does run in CI.)

- CodeRabbit (Major): a slash-command draft with pending image chips took the
  image branch and pasted images into the runtime even though the chat turn is
  suppressed. Classify isSlashCommand first and send text-only for it.

- CodeRabbit (Major): the attachments hook only seeded chips from the cache on
  first render, so reusing the composer for another pane kept the previous
  pane's chips live — and with deferred submit they'd be sent to the new
  target. Rescope on attachmentScopeKey change (render-time adjust, matching
  useNativeChatDraft). Added a rescope test.

Co-authored-by: Orca <[email protected]>
…ename

Clipboard-pasted images land in a temp file named orca-paste-<ts>-<uuid>.png;
the composer chip rendered that raw basename. Detect those temp files
(isNativeChatPastedImagePath) and show a translatable 'Pasted image' label
instead, keeping the real basename for picked/dropped files. The full path
stays on the chip's title tooltip. Verified live: the chip reads 'Pasted
image'.

Co-authored-by: Orca <[email protected]>
…] text

A sent image showed up in the transcript as raw '[Image: source: /path]' marker
text. normalizeImageTranscriptMessages only handled the paired
[Image: source]/[Image #1] turns; a lone image turn (image with no caption,
which the deferred-submit flow commonly produces) fell through to markdown text.

- Convert a lone [Image: source: /path] user turn into an image-ref block.
- Also normalize the scrape source (scrollback carries the same markers before
  the transcript loads), not just transcript.
- Show the friendly 'Pasted image' label on transcript image-ref chips for
  orca-paste temp files (matching the composer chip), real basename otherwise.

Added normalizer unit tests. Verified live: sent images render as tidy chips.

Co-authored-by: Orca <[email protected]>
@Jinwoo-H
Jinwoo-H merged commit 34c9c11 into main Jun 30, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/native-chat-per-leaf-and-composer-ux branch June 30, 2026 00:03
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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