Skip to content

feat(mobile): redesign the chat composer with file attachments and inline skills - #30359

Merged
AmoabaKelvin merged 3 commits into
mainfrom
redesign-and-improve-mobile-composer
Oct 18, 2026
Merged

AmoabaKelvin merged 3 commits into
mainfrom
redesign-and-improve-mobile-composer

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1028 $\color{#cf222e}{\Huge{\mathbf{−}}}$​127 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​901
Prod 78 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2084 $\color{#cf222e}{\Huge{\mathbf{−}}}$​728 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1356

ELI5

The phone chat box now looks and works like the desktop one. You can attach files as well as photos, pick a skill and see it highlighted inline, and change model, effort and permissions from one sheet.

What Changed

This covers structured chats only. Terminal-backed chats keep the old composer.

  • One rounded composer. The box keeps the same shape whether it's idle, typing or working. Queued messages tuck in under it, so you can see what's waiting.
  • + opens an attach sheet. It has Photos, Files (PDF, text, code…), Workspace file, Skills and Commands, and uses the existing ActionSheetModal.
  • Files go to the agent.
    • A picked file uploads to the host's attachment store through the existing agentSessionAttachment.upload* methods. The send then adds it to the message as an @path reference, the same way desktop does.
    • The send path takes a discriminated attachment type (kind: 'image' | 'file'), not image records with a file flag.
  • Skills are listed and drawn inline.
    • Typing / (or picking Skills or Commands) opens a grouped menu with each skill's description.
    • It reads agentSession.commands, because phone subscriptions don't carry the command list.
    • A picked skill shows inline as a highlighted token, like the Claude app. Deleting into the token removes the whole token.
    • The menu uses the desktop picker builder, now moved to src/shared, so both clients list the same entries in the same order.
  • Model, effort and permissions share one sheet. A single model pill opens it:
    • model choices;
    • effort as a segmented control;
    • toggles such as Fast mode;
    • a Permissions row, shown in amber when the agent has full access.

Why

The old composer looked out of place next to desktop. It could only attach images, gave no view of the queue, and had no way to find skills.

Version compatibility. The host and the app update separately, so each new piece is gated:

  • Phone uploads need the new host capability agent-session.attachments.phone.v1. Older hosts advertise attachments but refuse uploads from a phone, so the Files entry is hidden for them.
  • The real file name comes from a new optional shell verb, native.media.name. The app's existing media verbs reject unknown fields in both directions, so a new verb was the only safe route. An older app still attaches the file, named attachment-<n>.<ext>.

Visual Proof

iPhone on the left, Android on the right. Both are running the real over-the-air page against a dev desktop.

+ attach sheet
plus sheet

Skills menu with descriptions
skills menu

Picked skill drawn inline
skill inline

File attached with its real name
file attached

The agent reads the attached file
file read

Model sheet: effort, Fast mode, permissions
model sheet

Testing

Tested on the iOS simulator and the Android emulator, paired to a local dev desktop over the over-the-air page:

  • the skills menu and an inline skill send that runs the skill;
  • a file attach, upload and read by Claude;
  • photo attach, the model sheet and the queue.

Unit tests were added for the menu, inline skill editing, the commands refresh (including a refresh during a pending read), file upload and the mixed image/file send.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

  • The web text field draws the skill token on an overlay copy, because a textarea can't style part of its text (MobileNativeChatComposerField.web.tsx). The native field uses a nested Text instead.
  • Commands are refreshed whenever the slash menu opens, through the existing requestSingleFlight helper.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Known limits:

  • There is no recent-photos strip or camera button yet. Both need a new native module.
  • Until the first turn, Claude reports skills as plain commands, so the Skills filter shows the whole list.
  • The sent message shows the raw @path for a file.
  • Phone uploads are capped at 18 MB.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 18, 2026 18:41
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The pull request adds mobile file selection, staged media-name lookup, and host-side attachment uploads for structured chats. It updates the mobile composer with file attachments, menu and field components, and revised session-option controls. Shared picker APIs now retain session-reported skill descriptions, and renderer autocomplete uses the updated skill records.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to c1245

Resolve the attachment, composer, and permission-setting concerns before merging.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Description check Warning The description thoroughly covers the user impact, implementation, compatibility, testing, visual proof, and known limits. However, the required Linked Issue section is incomplete because it contains … Add a valid issue reference after Fixes #. If the contributor is external, include the required linked issue. If the contributor is an internal maintainer, document the applicable pre-existing issue or maintainer exception.
Docstring Coverage Inconclusive Docstring coverage is 55.93% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 59 functions across 50 files. (56 skipped… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely summarizes the primary change: a mobile chat composer redesign with file attachments and inline skills.
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 thoroughly covers the user impact, implementation, compatibility, testing, visual proof, and known limits. However, the required Linked Issue section is incomplete because it contains only Fixes # without an issue reference.

Resolution

Add a valid issue reference after Fixes #. If the contributor is external, include the required linked issue. If the contributor is an internal maintainer, document the applicable pre-existing issue or maintainer exception.

Full details: Docstring Coverage

Explanation

Docstring coverage is 55.93% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 59 functions across 50 files. (56 skipped: 1 unsupported, 55 over the file limit.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

The page's font-size census cannot follow a style passed in as a prop.

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

🧹 Nitpick comments: 1
src/shared/native-chat-picker-items.ts: 1

161-167: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Avoid the O(n²) description lookup in mergeNativeChatSkills.

For every merged name, sessionSkills?.find(...) scans the whole reported list. The renderer calls this builder on each keystroke, and the PR notes show about 76 skills. The cost is small at that size. Duplicate reported names also resolve to the first entry. Build a Map once to remove the repeated scan and make the duplicate rule explicit.

♻️ Proposed refactor
+  const reportedDescriptions = new Map<string, string | undefined>()
+  for (const entry of sessionSkills ?? []) {
+    if (!reportedDescriptions.has(entry.name)) {
+      reportedDescriptions.set(entry.name, entry.description)
+    }
+  }
   return [...new Set(names)]
     .map((name) => {
       const skill = discovered.get(name) ?? pickerSkill(name, [], skillSigil)
-      const reported = sessionSkills?.find((entry) => entry.name === name)?.description
+      const reported = reportedDescriptions.get(name)

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9c792d5a-f068-4f33-8afb-fa814868e426
📥 Commits

Reviewing files that changed from the base of the PR and between 72a5f2f and c1245d0.

📒 Files selected for processing: 110
  • config/scripts/mobile-web-page-routes.mjs
  • mobile/src/components/MobileSegmentedControl.tsx
  • mobile/src/mobile-web-shell/bridge-host-init.test.ts
  • mobile/src/mobile-web-shell/bridge/bridge-media-verbs.ts
  • mobile/src/mobile-web-shell/bridge/bridge-native-verbs.ts
  • mobile/src/mobile-web-shell/bridge/bridge-port-pair-test-harness.ts
  • mobile/src/mobile-web-shell/bridge/use-native-verbs.test.tsx
  • mobile/src/mobile-web-shell/bridge/use-native-verbs.ts
  • mobile/src/mobile-web-shell/media-handle-registry.ts
  • mobile/src/mobile-web-shell/page-route-policy.test.ts
  • mobile/src/platform/media-picker-contract.ts
  • mobile/src/platform/media-picker-test-shell.ts
  • mobile/src/platform/media-picker.test.ts
  • mobile/src/platform/media-picker.ts
  • mobile/src/platform/media-picker.web.test.tsx
  • mobile/src/platform/media-picker.web.ts
  • mobile/src/platform/mobile-picked-file-name.ts
  • mobile/src/platform/native-media.test.ts
  • mobile/src/platform/native-media.ts
  • mobile/src/session/MobileNativeChatComposer.structured.test.ts
  • mobile/src/session/MobileNativeChatComposer.test.ts
  • mobile/src/session/MobileNativeChatComposer.tsx
  • mobile/src/session/MobileNativeChatComposerAttachments.tsx
  • mobile/src/session/MobileNativeChatComposerField.tsx
  • mobile/src/session/MobileNativeChatComposerField.web.tsx
  • mobile/src/session/MobileNativeChatComposerMenu.tsx
  • mobile/src/session/MobileNativeChatComposerSuggestions.tsx
  • mobile/src/session/MobileNativeChatOverlay.tsx
  • mobile/src/session/MobileNativeChatQueuedMessages.test.tsx
  • mobile/src/session/MobileNativeChatQueuedMessages.tsx
  • mobile/src/session/MobileNativeChatSessionOptionPickers.test.ts
  • mobile/src/session/MobileNativeChatSessionOptionPickers.tsx
  • mobile/src/session/MobileNativeChatSessionOptionRows.tsx
  • mobile/src/session/MobileNativeChatSessionOptionSegments.tsx
  • mobile/src/session/MobileNativeChatStopButton.tsx
  • mobile/src/session/MobileNativeChatView.prompt-presentation.test.ts
  • mobile/src/session/MobileNativeChatView.tsx
  • mobile/src/session/MobileSessionActiveContent.tsx
  • mobile/src/session/__mocks__/mobile-prompt-controller.ts
  • mobile/src/session/mobile-agent-session-attachment-upload.test.ts
  • mobile/src/session/mobile-agent-session-attachment-upload.ts
  • mobile/src/session/mobile-file-search-owner-cleanup.test.tsx
  • mobile/src/session/mobile-file-source-picker.test.ts
  • mobile/src/session/mobile-file-source-picker.ts
  • mobile/src/session/mobile-image-source-picker.ts
  • mobile/src/session/mobile-native-chat-attach-actions.ts
  • mobile/src/session/mobile-native-chat-autocomplete.test.ts
  • mobile/src/session/mobile-native-chat-autocomplete.ts
  • mobile/src/session/mobile-native-chat-composer-field-skill.ts
  • mobile/src/session/mobile-native-chat-composer-layout.ts
  • mobile/src/session/mobile-native-chat-composer-menu.test.ts
  • mobile/src/session/mobile-native-chat-composer-menu.ts
  • mobile/src/session/mobile-native-chat-composer-styles.ts
  • mobile/src/session/mobile-native-chat-controller-contract.ts
  • mobile/src/session/mobile-native-chat-file-attachment.test.ts
  • mobile/src/session/mobile-native-chat-file-attachment.ts
  • mobile/src/session/mobile-native-chat-image-scope-state.ts
  • mobile/src/session/mobile-native-chat-input-base-styles.ts
  • mobile/src/session/mobile-native-chat-input-styles.ts
  • mobile/src/session/mobile-native-chat-merged-snapshot-parity-hooks.test.tsx
  • mobile/src/session/mobile-native-chat-queued-message-styles.ts
  • mobile/src/session/mobile-structured-agent-session-host-support.test.ts
  • mobile/src/session/mobile-structured-agent-session-host-support.ts
  • mobile/src/session/use-mobile-native-chat-composer-menu.ts
  • mobile/src/session/use-mobile-native-chat-file-attachments.ts
  • mobile/src/session/use-mobile-native-chat-image-attachments.ts
  • mobile/src/session/use-mobile-native-chat-input-lease.ts
  • mobile/src/session/use-mobile-native-chat-structured-composer.ts
  • mobile/src/session/use-mobile-session-attachments.ts
  • mobile/src/session/use-mobile-session-image-attachments.test.tsx
  • mobile/src/session/use-mobile-session-image-attachments.ts
  • mobile/src/session/use-mobile-structured-agent-options.ts
  • mobile/src/session/use-mobile-structured-agent-session-prompt-cancel.test.tsx
  • mobile/src/session/use-mobile-structured-agent-session-queued.test-fixture.ts
  • mobile/src/session/use-mobile-structured-agent-session-send.test.tsx
  • mobile/src/session/use-mobile-structured-native-chat-send-bridge.ts
  • mobile/src/session/use-mobile-structured-send-with-outcome.ts
  • mobile/src/session/use-mobile-structured-session-commands.test.tsx
  • mobile/src/session/use-mobile-structured-session-commands.ts
  • mobile/src/session/use-mobile-structured-turn-indicator.test.tsx
  • mobile/src/theme/mobile-theme.ts
  • mobile/web-entry/web-overrides.json
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session-attachments.test.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-agent-session-methods.ts
  • src/renderer/src/components/jira-issue-assignee-control.tsx
  • src/renderer/src/components/jira-issue-sorter.ts
  • src/renderer/src/components/native-chat/NativeChatAutocompleteMenus.test.tsx
  • src/renderer/src/components/native-chat/NativeChatComposer.tsx
  • src/renderer/src/components/native-chat/native-chat-composer-state.test.ts
  • src/renderer/src/components/native-chat/native-chat-composer-state.ts
  • src/renderer/src/components/native-chat/use-native-chat-composer-catalog.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-catalog.ts
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-composer-submit.ts
  • src/renderer/src/components/native-chat/use-native-chat-picker-state.ts
  • src/renderer/src/components/skills/skill-delete-copy.ts
  • src/renderer/src/components/task-page-linear-jira-list-model.tsx
  • src/renderer/src/lib/browser-palette-search.ts
  • src/renderer/src/lib/simulator-palette-search.ts
  • src/renderer/src/lib/workspace-tab-palette-results.ts
  • src/renderer/src/web/preload-api/web-agent-session-attachment-upload.ts
  • src/shared/agent-session-attachments.ts
  • src/shared/locale-text-collators.test.ts
  • src/shared/locale-text-collators.ts
  • src/shared/native-chat-picker-items.ts
  • src/shared/native-chat-slash-commands.test.ts
  • src/shared/native-chat-slash-commands.ts
  • src/shared/protocol-version.ts
  • src/shared/runtime-capability-constants.ts
💤 Files with no reviewable changes: 4
  • mobile/src/session/MobileNativeChatComposerSuggestions.tsx
  • mobile/src/session/mobile-native-chat-composer-layout.ts
  • src/shared/locale-text-collators.test.ts
  • src/shared/locale-text-collators.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • mobile/src/theme/mobile-theme.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment on lines 109 to 119
// A permission pick shows at once; its write may wait behind a starting agent.
if (descriptor === permission) {
closePicker()
onNavigate(descriptor === home ? null : home.id)
}
void controller.setOption(descriptor.id, value).then((applied) => {
if (applied) {
closePicker()
// The sheet stays on its home page so the next setting is one tap away; a sub page returns.
if (applied && descriptor !== home && descriptor !== permission) {
onNavigate(home.id)
}
})
}

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- target references and imports ---'
rg -n -F --glob 'MobileNativeChatSessionOptionPickers.tsx' -e 'controller' -e 'setOption' -e 'permission' mobile/src/session || test "$?" -eq 1
sed -n '1,190p' mobile/src/session/MobileNativeChatSessionOptionPickers.tsx
printf '%s\n' '--- setOption declarations and usages ---'
rg -n -F --glob '*.{ts,tsx}' -e 'setOption' mobile/src
printf '%s\n' '--- controller construction/type references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'MobileNativeChatSessionOptionPickers' -e 'NativeChatSessionController' -e 'controller:' mobile/src/session mobile/src || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 41558


🏁 Script executed:

set -eu
printf '%s\n' '--- native options controller interface/implementation ---'
sed -n '1,360p' mobile/src/session/use-mobile-native-chat-session-options.ts
printf '%s\n' '--- controller adapter ---'
sed -n '1,150p' mobile/src/session/use-mobile-native-chat-session-option-controller.ts
printf '%s\n' '--- structured options implementation ---'
sed -n '1,290p' mobile/src/session/use-mobile-structured-agent-options.ts

Repository: stablyai/orca

Length of output: 29597


🏁 Script executed:

set -eu
printf '%s\n' '--- picker permission tests ---'
sed -n '280,370p' mobile/src/session/MobileNativeChatSessionOptionPickers.test.ts
printf '%s\n' '--- native send outcome definitions/usages ---'
rg -n -F --glob '*.{ts,tsx}' -e 'type MobileNativeChatSendOutcome' -e 'MobileNativeChatSendOutcome' -e "outcome === 'rejected'" -e "outcome: 'rejected'" mobile/src/session
printf '%s\n' '--- structured mutation definitions/usages ---'
rg -n -F --glob '*.{ts,tsx}' -e 'type StructuredAgentSessionMutate' -e 'StructuredAgentSessionMutate' -e 'status ===' -e 'status: .rejected' mobile/src/session

Repository: stablyai/orca

Length of output: 22492


🏁 Script executed:

set -eu
printf '%s\n' '--- native message send rejection handling ---'
sed -n '1,240p' mobile/src/session/use-mobile-native-chat-message-send.ts
printf '%s\n' '--- structured send dispatch and delivery ---'
sed -n '1,130p' mobile/src/session/mobile-structured-agent-session-send.ts
sed -n '1,120p' mobile/src/session/mobile-structured-send-delivery.ts
printf '%s\n' '--- structured RPC mutation contract ---'
sed -n '1,110p' mobile/src/session/mobile-structured-agent-session-rpc.ts

Repository: stablyai/orca

Length of output: 19187


🏁 Script executed:

set -eu
printf '%s\n' '--- numbered decisive excerpts ---'
nl -ba mobile/src/session/MobileNativeChatSessionOptionPickers.tsx | sed -n '100,120p'
nl -ba mobile/src/session/use-mobile-structured-agent-options.ts | sed -n '205,275p'
nl -ba mobile/src/session/use-mobile-native-chat-message-send.ts | sed -n '240,315p'
nl -ba mobile/src/session/use-mobile-structured-agent-session.ts | sed -n '180,240p'
printf '%s\n' '--- structured permission rejection test ---'
nl -ba mobile/src/session/use-mobile-structured-agent-options.permission-mode.test.ts | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 17923


🏁 Script executed:

set -eu
nl -ba mobile/src/session/use-mobile-structured-agent-options.permission-mode.test.ts | sed -n '175,290p'
nl -ba mobile/src/session/use-mobile-native-chat-message-send.ts | sed -n '200,225p'

Repository: stablyai/orca

Length of output: 5111


Surface rejected structured permission writes.

The picker navigates before setOption resolves and ignores false for permission selections. In structured chats, a failed write is read back and can silently restore the previous mode. Show a user-visible error for the rejected result. Native catalog writes already report Message not sent, so scope this change to the structured controller path.

Comment on lines +107 to +123
const pick = (row: ComposerMenuRow): void => {
if (!trigger) {
return
}
setMenuKind(null)
// On the page a tapped row takes focus from the field; typing goes on where the pick left off.
input.focusField()
if (row.kind === 'skill') {
const rest = value.slice(trigger.end).trimStart()
onChangeText(`${row.token} ${rest}`)
placeCaret(row.token.length + 1)
return
}
const next = applyAutocomplete(value, trigger, composerMenuInsertText(row))
setDraft(next.text)
placeCaret(next.cursor)
}

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

Replace the whole leading / token when a row is picked, not only the part before the caret.

detectAutocompleteTrigger sets trigger.end to the caret position, not to the end of the token. A user can put the caret inside a leading token, for example inside a picked skill. In that case pick keeps the rest of the token in the draft:

  • The draft is /review-pr focus and the caret is at 4, so trigger.end is 4.
  • If the user picks the skill /research, then rest is iew-pr focus and the draft becomes /research iew-pr focus.
  • If the user picks the command /compact, applyAutocomplete writes /compact iew-pr focus.

The field draws the skill as one unit, so a tap inside the token is a realistic action. The result is a corrupted draft that the user must repair by hand. For a slash trigger, extend the end of the replaced span to the next whitespace.

🐛 Proposed fix
--- "a/mobile/src/session/use-mobile-native-chat-composer-menu.ts"
+++ "b/mobile/src/session/use-mobile-native-chat-composer-menu.ts"
@@ -104,23 +104,32 @@
     setPendingSelection({ start: at, end: at })
   }
 
   const pick = (row: ComposerMenuRow): void => {
     if (!trigger) {
       return
     }
     setMenuKind(null)
     // On the page a tapped row takes focus from the field; typing goes on where the pick left off.
     input.focusField()
+    // A slash token is replaced whole, also when the caret sits inside it.
+    const tokenEnd =
+      trigger.kind === 'slash'
+        ? (() => {
+            const space = value.slice(trigger.start).search(/\s/)
+            return space === -1 ? value.length : trigger.start + space
+          })()
+        : trigger.end
+    const span = { ...trigger, end: tokenEnd }
     if (row.kind === 'skill') {
-      const rest = value.slice(trigger.end).trimStart()
+      const rest = value.slice(span.end).trimStart()
       onChangeText(`${row.token} ${rest}`)
       placeCaret(row.token.length + 1)
       return
     }
-    const next = applyAutocomplete(value, trigger, composerMenuInsertText(row))
+    const next = applyAutocomplete(value, span, composerMenuInsertText(row))
     setDraft(next.text)
     placeCaret(next.cursor)
   }
 
   /** The + sheet's Skills and Commands rows: a leading `/` opens the menu, narrowed. */
   const openSlashMenu = (kind: MenuKind): void => {
📝 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
const pick = (row: ComposerMenuRow): void => {
if (!trigger) {
return
}
setMenuKind(null)
// On the page a tapped row takes focus from the field; typing goes on where the pick left off.
input.focusField()
if (row.kind === 'skill') {
const rest = value.slice(trigger.end).trimStart()
onChangeText(`${row.token} ${rest}`)
placeCaret(row.token.length + 1)
return
}
const next = applyAutocomplete(value, trigger, composerMenuInsertText(row))
setDraft(next.text)
placeCaret(next.cursor)
}
const pick = (row: ComposerMenuRow): void => {
if (!trigger) {
return
}
setMenuKind(null)
// On the page a tapped row takes focus from the field; typing goes on where the pick left off.
input.focusField()
// A slash token is replaced whole, also when the caret sits inside it.
const tokenEnd =
trigger.kind === 'slash'
? (() => {
const space = value.slice(trigger.start).search(/\s/)
return space === -1 ? value.length : trigger.start + space
})()
: trigger.end
const span = { ...trigger, end: tokenEnd }
if (row.kind === 'skill') {
const rest = value.slice(span.end).trimStart()
onChangeText(`${row.token} ${rest}`)
placeCaret(row.token.length + 1)
return
}
const next = applyAutocomplete(value, span, composerMenuInsertText(row))
setDraft(next.text)
placeCaret(next.cursor)
}

Comment on lines +78 to +86
const removeFiles = useCallback(
(ids: readonly string[]) => {
if (scopeKey) {
const removed = new Set(ids)
updateScope(scopeKey, (current) => current.filter((file) => !removed.has(file.id)))
}
},
[scopeKey, updateScope]
)

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

Remove sent files from the scope that sent them, not the current scope.

removeFiles reads scopeKey when the call runs. sendNativeChat in use-mobile-native-chat-image-attachments.ts (Line 215) calls onFilesSent only after await baseSend(...) finishes. If the user switches tabs during that await, scopeKey points to the new tab. The filter then runs on the new tab's list, where the sent ids do not exist. The sent file chips stay in the original tab. The next send from that tab references the same stored paths again. The image path in the same function avoids this because it captures scope before the await.

File ids come from one idCounter, so they are unique across scopes. Remove the ids from every scope. Then the result does not depend on which tab is active.

🐛 Proposed fix
--- "a/mobile/src/session/use-mobile-native-chat-file-attachments.ts"
+++ "b/mobile/src/session/use-mobile-native-chat-file-attachments.ts"
@@ -75,15 +75,29 @@
     })
   }, [client, enabled, picker, scopeKey, sessionId, showToast, updateScope])
 
   const removeFiles = useCallback(
     (ids: readonly string[]) => {
-      if (scopeKey) {
-        const removed = new Set(ids)
-        updateScope(scopeKey, (current) => current.filter((file) => !removed.has(file.id)))
-      }
+      if (ids.length === 0) {
+        return
+      }
+      const removed = new Set(ids)
+      // Ids are unique across scopes; a send that finished after a tab switch still drops its own.
+      setFilesByScope((prev) => {
+        let next = prev
+        for (const [scope, list] of Object.entries(prev)) {
+          if (list.some((file) => removed.has(file.id))) {
+            next = withScopeAttachments(
+              next,
+              scope,
+              list.filter((file) => !removed.has(file.id))
+            )
+          }
+        }
+        return next
+      })
     },
-    [scopeKey, updateScope]
+    []
   )
 
   return { files, attachFiles, removeFiles }
 }
📝 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
const removeFiles = useCallback(
(ids: readonly string[]) => {
if (scopeKey) {
const removed = new Set(ids)
updateScope(scopeKey, (current) => current.filter((file) => !removed.has(file.id)))
}
},
[scopeKey, updateScope]
)
const removeFiles = useCallback(
(ids: readonly string[]) => {
if (ids.length === 0) {
return
}
const removed = new Set(ids)
// Ids are unique across scopes; a send that finished after a tab switch still drops its own.
setFilesByScope((prev) => {
let next = prev
for (const [scope, list] of Object.entries(prev)) {
if (list.some((file) => removed.has(file.id))) {
next = withScopeAttachments(
next,
scope,
list.filter((file) => !removed.has(file.id))
)
}
}
return next
})
},
[]
)

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