Repository navigation
feat(native-chat): per-leaf toggle eligibility + composer UX (paste, draft, scrollbar, focus) - #6783
Conversation
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]>
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe 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)
✅ Passed checks (3 passed)
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: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a2920ff4-dae8-4362-b7b4-c276ea04d2d2
📒 Files selected for processing (10)
src/renderer/src/components/native-chat/NativeChatComposer.tsxsrc/renderer/src/components/native-chat/NativeChatComposerField.tsxsrc/renderer/src/components/native-chat/NativeChatView.tsxsrc/renderer/src/components/native-chat/native-chat-composer-target.tssrc/renderer/src/components/native-chat/native-chat-draft-cache.test.tssrc/renderer/src/components/native-chat/native-chat-draft-cache.tssrc/renderer/src/components/native-chat/native-chat-typing-redirect.test.tssrc/renderer/src/components/native-chat/native-chat-typing-redirect.tssrc/renderer/src/components/native-chat/use-native-chat-draft.tssrc/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]>
There was a problem hiding this comment.
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 winAvoid resuming text paste with a stale draft snapshot.
After the async clipboard reads, Line 102 still calls the
insertTypedTextclosure captured at paste start. Insrc/renderer/src/components/native-chat/NativeChatComposer.tsxLines 172-192, that helper rebuilds from the closed-overdraft, 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 functionalsetDraftupdate instead.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 3f7e5e8b-1a9e-438f-825f-8c5e52b3843e
📒 Files selected for processing (5)
src/renderer/src/components/native-chat/NativeChatComposer.tsxsrc/renderer/src/components/native-chat/native-chat-typing-redirect.test.tssrc/renderer/src/components/native-chat/native-chat-typing-redirect.tssrc/renderer/src/components/native-chat/use-native-chat-composer-paste.tssrc/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]>
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4ea77aed-c655-4bfe-b4ee-b00ee28021ed
📒 Files selected for processing (3)
src/renderer/src/components/native-chat/NativeChatComposer.tsxsrc/renderer/src/components/native-chat/NativeChatView.tsxsrc/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
…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]>
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2a2dcd58-1bcf-4bc8-84da-8a60e7654d11
📒 Files selected for processing (5)
src/renderer/src/components/native-chat/NativeChatComposer.tsxsrc/renderer/src/components/native-chat/native-chat-runtime-send.test.tssrc/renderer/src/components/native-chat/native-chat-runtime-send.tssrc/renderer/src/components/native-chat/use-native-chat-composer-attachments.test.tsxsrc/renderer/src/components/native-chat/use-native-chat-composer-attachments.ts
- 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]>
…draft, scrollbar, focus) (stablyai#6783) Co-authored-by: Orca <[email protected]>
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.
makePaneKey(tabId, leafId).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. Addedscrollbar-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
pasteFromClipboardhandle 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
useStateand was lost when the composer unmounted on toggle. ExtracteduseNativeChatDraft, which backs the draft by a module-level scope cache (sametargetPtyId ?? terminalTabIdkey as image attachments), so an unsent message + its attachments both survive the round-trip.Testing
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 newreact-doctorwarnings (draft/caret reload use the render-time adjustment pattern, not effects).@/lib/onboarding-folder-agent-startupmodule inrepos.ts(reproduces onmain); all 229 runnable tests pass.Made with Orca 🐋