Repository navigation
feat(mobile): show attached images as removable thumbnails in native chat - #9981
brennanb2025 wants to merge 13 commits into
Conversation
…chat Attaching a picture in mobile native chat gave no visible feedback: the image uploaded to the host and its path was pasted into the hidden PTY, so nothing on screen ever showed it was attached. Defer the TUI paste to send time and hold picked images in composer state, rendered as a thumbnail tray above the input (spinner while uploading, X to remove, image-only sends allowed). On send, each ready image's path is pasted bracketed into the agent TUI right before the message text, matching the desktop composer-attachment model. The terminal live-input surface keeps the immediate paste, where the TUI's own input line is the feedback.
|
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:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughNative chat now supports queued image attachments. Picked images retain local URIs, remain visible while uploading, and transition to ready entries with removable and consumable state. A new sender pastes ready images into the active terminal before sending text or submitting image-only messages, with checks for upload readiness, disconnection, and terminal changes. The composer renders attachment thumbnails and upload status, while the session overlay wires the new hooks and callbacks. Tests cover picker output, lifecycle races, rendering behavior, and send sequencing. 🚥 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
mobile/app/h/[hostId]/session/[worktreeId].tsx (1)
3629-3672: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winWrong
isAttachingsource wired into the native-chat composer.
onAttachImageonMobileNativeChatOverlaynow calls the newattachPendingChatImage(chat-scoped upload), but theisAttachingprop passed alongside it is stillisAttachingfromuseMobileImageAttachment— the terminal live-input attach flow, which is unrelated and (since the terminal command dock is unmounted while chat is shown) effectively alwaysfalsehere. The chat composer's "Attach image" button therefore never shows its upload spinner/disabled state for a chat-image upload, and the!isAttachingclause inMobileNativeChatComposer'scanSendis inert for this surface.🛡️ Proposed fix
+ const isChatImageUploading = pendingChatImages.some((image) => image.status === 'uploading') + <MobileNativeChatOverlay controller={nativeChatController} onAttachImage={() => void attachPendingChatImage('library')} - isAttaching={isAttaching} + isAttaching={isChatImageUploading} onSend={sendNativeChatWithImages} pendingImages={pendingChatImages} onRemovePendingImage={removePendingChatImage}Also applies to: 4721-4727
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 17d88c7d-e751-4911-a09e-189767557f5d
📒 Files selected for processing (12)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/session/MobileNativeChatComposer.test.tsmobile/src/session/MobileNativeChatComposer.tsxmobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/MobileNativeChatView.tsxmobile/src/session/mobile-image-source-picker.test.tsmobile/src/session/mobile-image-source-picker.tsmobile/src/session/use-mobile-image-attachment.tsmobile/src/session/use-mobile-native-chat-image-send.test.tsmobile/src/session/use-mobile-native-chat-image-send.tsmobile/src/session/use-mobile-native-chat-pending-images.test.tsmobile/src/session/use-mobile-native-chat-pending-images.ts
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: 90ac42ba-a3d2-4f45-b347-25b3e16d212d
📒 Files selected for processing (4)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/use-mobile-native-chat-controller.tsmobile/src/session/use-mobile-native-chat-image-attachments.ts
…dd-picture-attachment
…dd-picture-attachment
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/src/session/use-mobile-native-chat-pending-images.ts (1)
66-87: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate upload-abort cleanup across two effects.
Both effects abort and clear
uploadControllersRefon cleanup. The[client, attachmentScopeKey]-effect's cleanup already runs on unmount (in addition to dependency changes), so the abort loop inside the empty-deps effect's cleanup (lines 70-73) is fully subsumed by the second effect. Keeping two copies of this loop risks drift if one is edited without the other.♻️ Extract a shared helper to avoid duplicating the abort loop
+ const abortAllUploads = useCallback(() => { + for (const controller of uploadControllersRef.current.values()) { + controller.abort() + } + uploadControllersRef.current.clear() + }, []) + useEffect(() => { mountedRef.current = true return () => { mountedRef.current = false - for (const controller of uploadControllersRef.current.values()) { - controller.abort() - } - uploadControllersRef.current.clear() + abortAllUploads() // Why: release thumbnail data captured by in-flight uploads instead of retaining it until RPC timeout. entriesRef.current = [] } - }, []) + }, [abortAllUploads]) useEffect( - () => () => { - for (const controller of uploadControllersRef.current.values()) { - controller.abort() - } - uploadControllersRef.current.clear() - }, - [client, attachmentScopeKey] + () => abortAllUploads, + [client, attachmentScopeKey, abortAllUploads] )
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 3aaad746-c4e8-4c50-acd0-e13e60349df7
📒 Files selected for processing (13)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/session/MobileNativeChatComposer.test.tsmobile/src/session/MobileNativeChatComposer.tsxmobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/mobile-clipboard-image.test.tsmobile/src/session/mobile-clipboard-image.tsmobile/src/session/use-mobile-native-chat-controller.tsmobile/src/session/use-mobile-native-chat-image-attachments.tsmobile/src/session/use-mobile-native-chat-image-send.test.tsmobile/src/session/use-mobile-native-chat-image-send.tsmobile/src/session/use-mobile-native-chat-pending-images.test.tsmobile/src/session/use-mobile-native-chat-pending-images.tsmobile/src/theme/mobile-theme.ts
💤 Files with no reviewable changes (1)
- mobile/app/h/[hostId]/session/[worktreeId].tsx
🚧 Files skipped from review as they are similar to previous changes (6)
- mobile/src/session/MobileNativeChatComposer.test.ts
- mobile/src/session/use-mobile-native-chat-image-attachments.ts
- mobile/src/session/use-mobile-native-chat-pending-images.test.ts
- mobile/src/session/MobileNativeChatComposer.tsx
- mobile/src/session/use-mobile-native-chat-controller.ts
- mobile/src/session/MobileNativeChatOverlay.tsx
…dd-picture-attachment # Conflicts: # resources/skills/release-mapping.json
…dd-picture-attachment # Conflicts: # mobile/src/session/mobile-image-source-picker.test.ts # mobile/src/session/mobile-image-source-picker.ts
Problem
Attaching a picture in mobile native chat gave no visible feedback. The image uploaded to the host and its file path was pasted straight into the hidden PTY (
mobile-image-attachment.ts), so beyond a brief spinner on the attach button, nothing on screen ever indicated an image was attached — it looked like the button did nothing.Change
Native chat now defers the TUI paste to send time and shows picked images as a thumbnail tray above the input, matching the desktop composer-attachment model (chips held in composer state, images "ride along" on submit):
use-mobile-native-chat-pending-images.ts— pending-image state. Picking still uploads to the host eagerly (same chunked upload RPC); the entry renders as an 88px thumbnail with a spinner overlay while uploading and a circular ✕ once ready. Thumbnails use the picker's local file URI so no second base64 copy is held in JS memory. Pending images are scoped to the chat target and RPC client, and target switches/removal/unmount cancel remaining upload chunks.use-mobile-native-chat-image-send.ts— send wrapper. Pastes each ready image's host path bracketed (enter:false, the same payload as a desktop image paste) right before the message text. Accepted path writes remain as non-removablepastedentries until the caption/Enter is accepted, so rejected and delivery-unknown retries never paste the same path twice. Image-only sends submit with a bare Enter and can retry only that Enter after rejection. Newly pasted paths use the same 300 ms image-settle and 500 ms submit cadence as desktop so caption or Enter bytes cannot overtake TUI image-chip processing.MobileNativeChatComposer.tsx— attachment tray UI; send is allowed with images and no text, blocked while an upload is in flight, and uses the native-chat upload state rather than the unrelated terminal-mode spinner.PickedMobileImagenow carries the picker's fileuri; the attach-failure toast copy is extracted tomobileImageAttachToastMessageand shared by both flows.Deferring the paste is what makes ✕ possible: removing a ready thumbnail needs no TUI un-paste. Once a path has reached the hidden TUI, its retained non-removable thumbnail keeps composer state aligned with that input until submission settles.
The terminal live-input surface intentionally keeps the immediate paste — there the agent TUI's own input line is the visible feedback.
Follow-up review also closes asynchronous target-lifetime races: picker/upload completion is ignored after a terminal/client switch, removal, or unmount; multi-image delivery stops if the active terminal/client/lease changes; and a caption can no longer be sent to a different terminal than the one that received the image paths. The native-chat controller owns this coordination, keeping the already-dense session route below its max-lines ratchet without a lint bypass.
Out of scope (follow-ups)
use-mobile-attachment-input-lease-gate.ts) still read as picker-cancel.Testing
tsc --noEmit, full oxlint, oxfmt, the repository max-lines ratchet, and reliability-manifest validation passed.Reliability contract
mobile-relay.terminal-input-delivery): an attachment remains bound to its originating chat target; retry never duplicates a path already accepted or possibly delivered byterminal.send; a rejected final submit remains retryable; caption and image-only submit writes preserve the desktop-proven TUI settle cadence.terminal.sendcalls across accepted, rejected, target-switch, and delivery-unknown outcomes; cancellation assertsstart → first chunk → abortwith no later chunk or commit.config/reliability-gates.jsonc; the focused mobile tests are the deterministic gate for this PR.pastedand avoids duplication; the user must inspect the terminal before retrying, as the toast states.Manual validation
Validated on an iPhone 17 Pro simulator (iOS 26.5) paired to an isolated desktop runtime: selecting a photo shows a ready thumbnail, ✕ removes it without touching the TUI input, and an image-only send delivers the image then clears the tray.