iOS: iMessage-style terminal composer (open by default, inline send, per-terminal drafts)
Lands the iMessage-style terminal composer for iOS. Supersedes https://github.com/manaflow-ai/cmux/pull/5511.
What ships
- Composer open by default per terminal. The composer band presents by default for every terminal, like iMessage shows its input bar in every conversation.
isComposerPresentedis derived per-terminal state over a session-only dismissed set: the chevron hides it (remembered per terminal), and dismissing one terminal leaves every other terminal open. Presented does not imply focused; the band appears with the keyboard down, and focus is a one-shot store handshake (composerFocusRequest+ a pending flag) armed only by an explicit open, the reveal-and-focus path, or a mid-compose terminal switch. - Inline send button. The send button sits inside the textbox container (iMessage's circular up-arrow riding the last line), replacing a detached accessory-bar send.
- One-surface bottom dock. Terminal grid, composer band, always-visible toolbar, and keyboard live in one surface-owned coordinate system; a field grow pushes only the terminal up.
- Per-terminal drafts with a FIFO pipeline. Draft saves, loads, swaps, and wipes apply in exactly the order they were issued, so a stale keystroke save can never overwrite a newer save and nothing written before the sign-out wipe survives it. Keystroke saves coalesce to one latest-value flush per terminal, so a typing burst behind a slow store stays bounded in memory.
- Field-ownership marker. Fixes the draft-erasure bug class on fast terminal switches (A→B→C): the field is persisted on switch only when it actually represents the outgoing terminal's draft, so a transient cleared placeholder can never erase a real stored draft. Red/green pair: failing tests in https://github.com/manaflow-ai/cmux/commit/6c5e5c13d94cf3e0500c5dfc3803ccba482aaa73, fix in https://github.com/manaflow-ai/cmux/commit/8a9ebb32ac56119b496a420824dcf375ab5fc104.
- Post-send hardening. The draft clears on send ack with a re-entrancy-guarded submit (a double tap cannot paste twice), and the deferred-close unmount path cannot unmount a freshly reopened field.
- Mac host:
terminal.pasteRPC. Multi-line composer text lands as one bracketed paste plus a single submit keypress (upgraded to ctrl+enter for Claude Code multi-line), instead ofterminal.inputCR-fragmenting each line into separate commands.
Review hardening (autoreview loop, 8 rounds to clean)
terminal.pastereports partial success (submitted: false+submit_error) when the submit key fails after the text was already delivered, so the client clears the draft and a retry cannot paste a duplicate block.terminal.pasteroutes through theTerminalPanelexplicit-input wrappers, waking a hibernated agent terminal the way local typing does.- Keyboard toggle and HIDE resign whichever responder actually owns the keyboard; with the composer open by default the terminal input proxy can hold first responder while the band is presented, and
endEditingon the composer container alone resigned nothing. - The focus handshake is keyed to its target terminal so the outgoing composer (still mounted during a switch) cannot consume the request meant for the incoming one.
- Hidden chrome (HIDE) reclaims the full grid height including the home-indicator strip, matching the dock frame math.
Tests
swift test: CmuxMobileShell 79 / CMUXMobileCore 74 / CmuxMobileRPC 23, all green, including suites for the dock reducer, default-open, submit/draft reconcile, FIFO ordering + coalescing, draft-swap field ownership, and focus-request keying.- XCUITests added for dock coherence (open/close cycles, draft survival across terminal switches).
- Compile-verified: iOS arm64 simulator (
cmux-ios) and macOS app, tagged derivedDataPaths.
Localization
Composer strings (mobile.composer.placeholder, mobile.composer.send, mobile.composer.close, terminal.input_accessory.composer) are localized in en + ja in ios/cmux/Resources/Localizable.xcstrings; the branch diff was audited for bare English UI strings (none found).
🤖 Generated with Claude Code
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.
[!NOTE]
Medium Risk
Large mobile UI/state-machine change across shell, surface layout, and remote terminal input (terminal.paste); mitigated by extensive tests but still affects core typing/submit flows on iOS.
Overview
Adds an iMessage-style iOS terminal composer that is open by default per terminal (session-only dismiss per terminal), with an inline send control and per-terminal drafts wired through a new TerminalDraftStoring seam and in-memory store plus a FIFO draft pipeline (coalesced saves, sign-out wipe, post-send reconcile).
Bottom dock moves into GhosttySurfaceView: composer band + always-visible toolbar + keyboard in one layout stack (replacing safeAreaInset/toolbar handoff). GhosttySurfaceRepresentable hosts TerminalComposerView in the surface composer band; compose-button behavior uses ComposerDockState (open / reveal-and-focus / close) so hide/reveal cycles do not clear drafts.
Send path uses new terminal.paste RPC from the shell (ack-gated draft clear, re-entrancy guard); mobile RPC client treats paste like terminal input for ticket coverage. Focus uses a terminal-keyed composerFocusRequest handshake plus UIKit assist on reveal.
Adds DEBUG diagnostics (composer events, dock probes) and broad unit tests for dock reducer, default-open, draft ordering/switch ownership, and submit reconcile; minor toolbar UX (sticky-lock border, composer accessory action).
Reviewed by Cursor Bugbot for commit a2d7d0e7eb380eb75a8306fae647c007d91a1911. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Ships an iMessage-style terminal composer on iOS with a default-open band, inline send, and per-terminal drafts in a surface-owned bottom dock. Adds terminal.paste for bracketed multi-line sends and hardens focus/draft handling to prevent draft loss, double submits, and flaky reveal focus.
-
New Features
- Default-open composer per terminal; unfocused by default; chevron hides it per session.
- Inline send; multi-line input submits as one bracketed paste + single submit via
terminal.paste. - One bottom dock (grid, composer, toolbar, keyboard) owned by the terminal surface; field growth only moves the grid; pinned compose toggle.
- Per-terminal drafts behind
TerminalDraftStoringwith FIFO ordering and coalesced keystroke saves; in-memory store for this PR; composer strings localized (en, ja).
-
Bug Fixes
- Compose button resolves to open → reveal-and-focus → close so hidden or unfocused composers aren’t dismissed.
- Field-ownership marker stops draft erasure on fast terminal switches; late loads no longer overwrite edits.
- Post-send clears the submitted terminal’s stored draft on ack (guarded against double taps and mid-flight switches);
terminal.pasteaccepts late acks after reconnect; partial submit failures returnsubmitted: falsewithsubmit_error. - Keyboard toggle and HIDE resign the actual first responder; hidden chrome fully reclaims grid height.
- Focus is keyed to the requesting surface’s terminal ID, plus a deterministic UIKit assist on reveal/HIDE.
- UI tests updated for the always-visible dock (ColorBands threshold) and longer selection waits on slow CI.
Summary by CodeRabbit
-
New Features
- iMessage‑style bottom composer: multi-line input, toggle/hide controls, focus-handshake, measured band height, and preserved drafts across hide/reveal and terminal switches.
- Per‑terminal session draft persistence with async FIFO/coalescing pipeline and ack‑gated clearing on send.
- Remote terminal paste RPC support for multi-line submissions.
- New composer state/intents, diagnostic probes, responder identity tokens, and localized composer labels.
-
Tests
- Extensive unit and UI tests covering open/close, focus/refocus handshake, draft persistence, terminal switching, pipeline ordering/races, and UI regressions.
-
UI
- Accessibility probes for surface/store composer state and a sticky‑locked visual state for accessory buttons.