Repository navigation
feat(mobile): redesign the chat composer with file attachments and inline skills - #30359
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
…ing to shared Mobile builds the same skill and command list as desktop.
72a5f2f to
21cd4d2
Compare
The page's font-size census cannot follow a style passed in as a prop.
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments: 1
src/shared/native-chat-picker-items.ts: 1
161-167: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueAvoid 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 aMaponce 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
📒 Files selected for processing: 110
config/scripts/mobile-web-page-routes.mjsmobile/src/components/MobileSegmentedControl.tsxmobile/src/mobile-web-shell/bridge-host-init.test.tsmobile/src/mobile-web-shell/bridge/bridge-media-verbs.tsmobile/src/mobile-web-shell/bridge/bridge-native-verbs.tsmobile/src/mobile-web-shell/bridge/bridge-port-pair-test-harness.tsmobile/src/mobile-web-shell/bridge/use-native-verbs.test.tsxmobile/src/mobile-web-shell/bridge/use-native-verbs.tsmobile/src/mobile-web-shell/media-handle-registry.tsmobile/src/mobile-web-shell/page-route-policy.test.tsmobile/src/platform/media-picker-contract.tsmobile/src/platform/media-picker-test-shell.tsmobile/src/platform/media-picker.test.tsmobile/src/platform/media-picker.tsmobile/src/platform/media-picker.web.test.tsxmobile/src/platform/media-picker.web.tsmobile/src/platform/mobile-picked-file-name.tsmobile/src/platform/native-media.test.tsmobile/src/platform/native-media.tsmobile/src/session/MobileNativeChatComposer.structured.test.tsmobile/src/session/MobileNativeChatComposer.test.tsmobile/src/session/MobileNativeChatComposer.tsxmobile/src/session/MobileNativeChatComposerAttachments.tsxmobile/src/session/MobileNativeChatComposerField.tsxmobile/src/session/MobileNativeChatComposerField.web.tsxmobile/src/session/MobileNativeChatComposerMenu.tsxmobile/src/session/MobileNativeChatComposerSuggestions.tsxmobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/MobileNativeChatQueuedMessages.test.tsxmobile/src/session/MobileNativeChatQueuedMessages.tsxmobile/src/session/MobileNativeChatSessionOptionPickers.test.tsmobile/src/session/MobileNativeChatSessionOptionPickers.tsxmobile/src/session/MobileNativeChatSessionOptionRows.tsxmobile/src/session/MobileNativeChatSessionOptionSegments.tsxmobile/src/session/MobileNativeChatStopButton.tsxmobile/src/session/MobileNativeChatView.prompt-presentation.test.tsmobile/src/session/MobileNativeChatView.tsxmobile/src/session/MobileSessionActiveContent.tsxmobile/src/session/__mocks__/mobile-prompt-controller.tsmobile/src/session/mobile-agent-session-attachment-upload.test.tsmobile/src/session/mobile-agent-session-attachment-upload.tsmobile/src/session/mobile-file-search-owner-cleanup.test.tsxmobile/src/session/mobile-file-source-picker.test.tsmobile/src/session/mobile-file-source-picker.tsmobile/src/session/mobile-image-source-picker.tsmobile/src/session/mobile-native-chat-attach-actions.tsmobile/src/session/mobile-native-chat-autocomplete.test.tsmobile/src/session/mobile-native-chat-autocomplete.tsmobile/src/session/mobile-native-chat-composer-field-skill.tsmobile/src/session/mobile-native-chat-composer-layout.tsmobile/src/session/mobile-native-chat-composer-menu.test.tsmobile/src/session/mobile-native-chat-composer-menu.tsmobile/src/session/mobile-native-chat-composer-styles.tsmobile/src/session/mobile-native-chat-controller-contract.tsmobile/src/session/mobile-native-chat-file-attachment.test.tsmobile/src/session/mobile-native-chat-file-attachment.tsmobile/src/session/mobile-native-chat-image-scope-state.tsmobile/src/session/mobile-native-chat-input-base-styles.tsmobile/src/session/mobile-native-chat-input-styles.tsmobile/src/session/mobile-native-chat-merged-snapshot-parity-hooks.test.tsxmobile/src/session/mobile-native-chat-queued-message-styles.tsmobile/src/session/mobile-structured-agent-session-host-support.test.tsmobile/src/session/mobile-structured-agent-session-host-support.tsmobile/src/session/use-mobile-native-chat-composer-menu.tsmobile/src/session/use-mobile-native-chat-file-attachments.tsmobile/src/session/use-mobile-native-chat-image-attachments.tsmobile/src/session/use-mobile-native-chat-input-lease.tsmobile/src/session/use-mobile-native-chat-structured-composer.tsmobile/src/session/use-mobile-session-attachments.tsmobile/src/session/use-mobile-session-image-attachments.test.tsxmobile/src/session/use-mobile-session-image-attachments.tsmobile/src/session/use-mobile-structured-agent-options.tsmobile/src/session/use-mobile-structured-agent-session-prompt-cancel.test.tsxmobile/src/session/use-mobile-structured-agent-session-queued.test-fixture.tsmobile/src/session/use-mobile-structured-agent-session-send.test.tsxmobile/src/session/use-mobile-structured-native-chat-send-bridge.tsmobile/src/session/use-mobile-structured-send-with-outcome.tsmobile/src/session/use-mobile-structured-session-commands.test.tsxmobile/src/session/use-mobile-structured-session-commands.tsmobile/src/session/use-mobile-structured-turn-indicator.test.tsxmobile/src/theme/mobile-theme.tsmobile/web-entry/web-overrides.jsonsrc/main/runtime/mobile-rpc-allowlist.test.tssrc/main/runtime/rpc/methods/structured-agent-session-attachments.test.tssrc/main/runtime/runtime-rpc/runtime-rpc-mobile-agent-session-methods.tssrc/renderer/src/components/jira-issue-assignee-control.tsxsrc/renderer/src/components/jira-issue-sorter.tssrc/renderer/src/components/native-chat/NativeChatAutocompleteMenus.test.tsxsrc/renderer/src/components/native-chat/NativeChatComposer.tsxsrc/renderer/src/components/native-chat/native-chat-composer-state.test.tssrc/renderer/src/components/native-chat/native-chat-composer-state.tssrc/renderer/src/components/native-chat/use-native-chat-composer-catalog.test.tsxsrc/renderer/src/components/native-chat/use-native-chat-composer-catalog.tssrc/renderer/src/components/native-chat/use-native-chat-composer-submit.test.tsxsrc/renderer/src/components/native-chat/use-native-chat-composer-submit.tssrc/renderer/src/components/native-chat/use-native-chat-picker-state.tssrc/renderer/src/components/skills/skill-delete-copy.tssrc/renderer/src/components/task-page-linear-jira-list-model.tsxsrc/renderer/src/lib/browser-palette-search.tssrc/renderer/src/lib/simulator-palette-search.tssrc/renderer/src/lib/workspace-tab-palette-results.tssrc/renderer/src/web/preload-api/web-agent-session-attachment-upload.tssrc/shared/agent-session-attachments.tssrc/shared/locale-text-collators.test.tssrc/shared/locale-text-collators.tssrc/shared/native-chat-picker-items.tssrc/shared/native-chat-slash-commands.test.tssrc/shared/native-chat-slash-commands.tssrc/shared/protocol-version.tssrc/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.
| // 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) | ||
| } | ||
| }) | ||
| } |
There was a problem hiding this comment.
🩺 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 1Repository: 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.tsRepository: 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/sessionRepository: 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.tsRepository: 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.
| 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) | ||
| } |
There was a problem hiding this comment.
🎯 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 focusand the caret is at 4, sotrigger.endis 4. - If the user picks the skill
/research, thenrestisiew-pr focusand the draft becomes/research iew-pr focus. - If the user picks the command
/compact,applyAutocompletewrites/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.
| 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) | |
| } |
| 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] | ||
| ) |
There was a problem hiding this comment.
🎯 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.
| 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 | |
| }) | |
| }, | |
| [] | |
| ) |
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.
+opens an attach sheet. It has Photos, Files (PDF, text, code…), Workspace file, Skills and Commands, and uses the existingActionSheetModal.agentSessionAttachment.upload*methods. The send then adds it to the message as an@pathreference, the same way desktop does.kind: 'image' | 'file'), not image records with a file flag./(or picking Skills or Commands) opens a grouped menu with each skill's description.agentSession.commands, because phone subscriptions don't carry the command list.src/shared, so both clients list the same entries in the same order.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:
agent-session.attachments.phone.v1. Older hosts advertise attachments but refuse uploads from a phone, so the Files entry is hidden for them.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, namedattachment-<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 sheetSkills menu with descriptions

Picked skill drawn inline

File attached with its real name

The agent reads the attached file

Model sheet: effort, Fast mode, permissions

Testing
Tested on the iOS simulator and the Android emulator, paired to a local dev desktop over the over-the-air page:
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.
Review
MobileNativeChatComposerField.web.tsx). The native field uses a nestedTextinstead.requestSingleFlighthelper.Agent skill upstream boundary
Notes
Known limits:
@pathfor a file.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)