Repository navigation
Conversation
|
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:
📝 WalkthroughWalkthroughAdds a native Expo hardware keyboard capture package for Android and iOS with JavaScript fallbacks. Introduces terminal hardware-key mapping and commit handling for navigation, shortcuts, editing, and pending text. Adds focus coordination for soft-keyboard requests, modal state, and capture gating. Refactors the live-input bar into a reusable component and integrates hardware-key events and deferred focus behavior into the session route. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
🧹 Nitpick comments (1)
mobile/src/terminal/use-terminal-live-input-commit.ts (1)
209-212: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDerive local-edit bytes from the accessory-key definitions.
mobile/src/terminal/use-terminal-live-input-commit.ts:209-212restates'backspace'/'delete'bytes ('\x7f'and'\x1b[3~') that already live inmobile/src/terminal/terminal-accessory-keys.ts. Reuse a small helper/constant keyed by local-edit value so later byte changes do not diverge from the accessory key mapping.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d0478e6a-fb90-4cdf-83c3-c68226a8a9d0
⛔ Files ignored due to path filters (1)
mobile/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (28)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/package.jsonmobile/packages/expo-hardware-keyboard/android/build.gradlemobile/packages/expo-hardware-keyboard/android/src/main/AndroidManifest.xmlmobile/packages/expo-hardware-keyboard/android/src/main/java/expo/modules/hardwarekeyboard/ExpoHardwareKeyboardModule.ktmobile/packages/expo-hardware-keyboard/android/src/main/java/expo/modules/hardwarekeyboard/HardwareKeyboardCaptureView.ktmobile/packages/expo-hardware-keyboard/expo-module.config.jsonmobile/packages/expo-hardware-keyboard/ios/ExpoHardwareKeyboard.podspecmobile/packages/expo-hardware-keyboard/ios/ExpoHardwareKeyboardModule.swiftmobile/packages/expo-hardware-keyboard/ios/HardwareKeyboardCaptureView.swiftmobile/packages/expo-hardware-keyboard/package.jsonmobile/packages/expo-hardware-keyboard/src/ExpoHardwareKeyboard.types.tsmobile/packages/expo-hardware-keyboard/src/ExpoHardwareKeyboardModule.tsmobile/packages/expo-hardware-keyboard/src/ExpoHardwareKeyboardModule.web.tsmobile/packages/expo-hardware-keyboard/src/HardwareKeyboardCaptureView.tsxmobile/packages/expo-hardware-keyboard/src/index.tsmobile/packages/expo-hardware-keyboard/tsconfig.jsonmobile/src/session/MobileTerminalLiveInputBar.tsxmobile/src/terminal/terminal-live-hardware-key-mapping.test.tsmobile/src/terminal/terminal-live-hardware-key-mapping.tsmobile/src/terminal/terminal-live-hardware-key-native-contract.test.tsmobile/src/terminal/terminal-live-hardware-keyboard-focus.test.tsmobile/src/terminal/terminal-live-hardware-keyboard-focus.tsmobile/src/terminal/terminal-live-input-affordance.test.tsmobile/src/terminal/use-terminal-live-hardware-keyboard.test.tsmobile/src/terminal/use-terminal-live-hardware-keyboard.tsmobile/src/terminal/use-terminal-live-input-commit.test.tsmobile/src/terminal/use-terminal-live-input-commit.ts
1cf9247 to
3aba36b
Compare
|
Thanks @bbingz for the original implementation and native groundwork. With maintainer approval, I rebased it onto current main and added the reviewed Android modifier/AltGr, iOS command-cache/forward-Delete, modal-focus, and test-oracle fixes in two follow-up commits; the updated description records the verification evidence and remaining device/build gaps. |
Greptile SummaryThis PR adds a new
Confidence Score: 5/5Safe to merge with awareness of the two unverified device gaps noted by the author: physical iPad keyboard behavior under the Focus Engine, and real-device Android compilation after the AltGr fix. The implementation is thorough: review fixes addressed the known Android AltGr modifier bug, iOS forward-Delete conflation with Backspace, static UIKeyCommand allocation, and modal focus leakage. The 76-test focused suite covers the critical mapper paths, focus-latch states, modal blur, and native contract invariants with a source-revert anti-vacuity probe confirming the tests are non-trivial. The two findings are style-level: a redundant Files Needing Attention: The unverified device scenarios called out in the PR description — physical iPad keyboard behavior and real Android compilation after the AltGr modifier fix — should be confirmed before shipping to users who rely on those platforms.
|
| Filename | Overview |
|---|---|
| mobile/packages/expo-hardware-keyboard/ios/HardwareKeyboardCaptureView.swift | New iOS native capture view; correctly caches UIKeyCommands as a static let, maps Backspace/Delete distinctly, and guards Meta/Ctrl+Space. The #available(iOS 15.0, *) check inside buildTerminalKeyCommands is always-true given the podspec iOS 15.1 floor. |
| mobile/packages/expo-hardware-keyboard/android/src/main/java/expo/modules/hardwarekeyboard/HardwareKeyboardCaptureView.kt | New Android capture view; AltGr heuristic correctly compares alternate and base characters under the same Shift/Caps state, Ctrl+Space/Meta/Enter are correctly passed through, and isCtrlPrintable excludes space (0x20 not in '!'..'~'). |
| mobile/src/terminal/terminal-live-hardware-key-mapping.ts | New TS key mapper; correctly ignores Meta/Enter/Ctrl+Space/plain-printable/alt-printable, routes special keys through getTerminalLiveSpecialKeyDecision, and routes Ctrl+printable/modifier+special through buildTerminalShortcutKey. |
| mobile/src/terminal/use-terminal-live-hardware-keyboard.ts | New focus-latch hook; the setState-during-render pattern for modal open is React 18-endorsed. A stale pendingSoftFocusSeq can cause a deferred focus to fire when showSoftInputOnFocus toggles back to true after a canSend/liveInputEnabled cycle, potentially surfacing the software keyboard unexpectedly. |
| mobile/src/terminal/use-terminal-live-input-commit.ts | Adds handleLiveInputHardwareKey alongside existing handlers; correctly reads heldText/sentText from stable refs, clears stale pending state on terminal-handle mismatch, and routes local-edit/send-bytes/flush-field-then-send correctly. |
| mobile/src/session/MobileTerminalLiveInputBar.tsx | Clean extraction of the live-input bar into its own component; wraps TextInput in HardwareKeyboardCaptureView and correctly threads showSoftInputOnFocus and hardwareCaptureEnabled props. |
| mobile/app/h/[hostId]/session/[worktreeId].tsx | Replaces inline live-input bar with MobileTerminalLiveInputBar, adds useTerminalLiveHardwareKeyboard hook, and wires hardwareKeyboardModalOpen from 15 modal-state signals with clearSoftKeyboardRequest threaded through keyboard-hide, tab action sheet, and dismiss paths. |
| mobile/src/terminal/terminal-live-hardware-keyboard-focus.ts | Pure focus-decision functions; correctly returns silent-focus vs soft-focus vs idle, and planExplicitSoftKeyboardFocus handles all four focused×alreadyWantsSoftKeyboard combinations. |
| mobile/src/terminal/terminal-live-hardware-key-native-contract.test.ts | Source-text contract tests anchored to specific guard bodies rather than whole-file substring matches; covers Meta, Enter, Ctrl+Space, AltGr, iOS Backspace/Delete distinction, and static command caching. |
| mobile/src/terminal/use-terminal-live-hardware-keyboard.test.ts | Hook integration tests covering soft-focus latch deferral, modal open/close latch drop, stale-event rejection, and terminal-switch silent focus; uses react-test-renderer correctly with fake timers. |
| mobile/packages/expo-hardware-keyboard/src/HardwareKeyboardCaptureView.tsx | Falls back to a plain View when native module is absent; correctly uses the try/catch loader in ExpoHardwareKeyboardModule.ts for web/test safety. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Physical Key Event] --> B{Platform}
B --> |iOS| C[UIKeyCommand registered?]
B --> |Android| D[dispatchKeyEvent ACTION_DOWN]
C --> |No| E[TextInput/IME handles it]
C --> |Yes| F{handleKeyCommand}
F --> |Meta/Cmd| E
F --> |Ctrl+Space| E
F --> G[canonicalKey → key name]
D --> |Meta| E
D --> |Enter| E
D --> |Ctrl+Space| E
D --> H{isSpecial OR isCtrlPrintable?}
H --> |No| E
H --> |Yes| I[canonicalKey → key name]
G --> J[onHardwareKey event dispatched]
I --> J
J --> K[useTerminalLiveHardwareKeyboard.onHardwareKey]
K --> |liveInputEnabled=false OR canSend=false OR modalOpen=true| L[Dropped in JS]
K --> M[handleLiveInputHardwareKey]
M --> N[mapTerminalLiveHardwareKeyEvent]
N --> |meta| O[ignore]
N --> |Enter| O
N --> |Ctrl+Space| O
N --> |plain/shift/alt printable| O
N --> |Backspace/Delete + field text| P[local-edit]
N --> |special key no modifier| Q{getTerminalLiveSpecialKeyDecision}
N --> |special+modifier or ctrl+printable| R[buildTerminalShortcutKey]
Q --> |heldText present| S[flush-field-then-send]
Q --> |empty field| T[send-bytes]
R --> S
R --> T
P --> U[handleLiveInputAccessoryBytes]
S --> V[flushPendingLiveInputText then sendLiveTerminalInput]
T --> W[sendTerminalLiveControlAfterPendingFlush]
Reviews (4): Last reviewed commit: "fix(mobile): tighten hardware keyboard c..." | Re-trigger Greptile
The changed-code quality gate flags clearing wantSoftKeyboard from the modal-open effect (react-doctor/no-adjust-state-on-prop-change). Adjust it during render per React's prop-change pattern so the latch never renders a frame stale; the effect keeps only its imperative timer/blur work.
The React Doctor changed-lines gate blocks on two counts: the modalOpen ref was written during render, and every effect listed the caller-supplied ref containers as dependencies, so it traced them as freshly built each render. Move the ref write into an effect declared before the silent-focus effect that reads it, and drop the ref containers from the dependency arrays -- refs are stable, so listing them never triggered a re-run anyway.
589a4e5 to
005622e
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (6)
mobile/src/terminal/use-terminal-live-input-commit.ts (1)
199-248: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate guard/dispatch logic vs.
handleLiveInputKeyPress.
handleLiveInputHardwareKeyre-implements the same activeHandle/ownership guard andsendTerminalLiveControlAfterPendingFlushdispatch pattern already present inhandleLiveInputKeyPress(Lines 141-182). Consider extracting the shared guard clause (and possibly the send-dispatch) into a small helper so future changes to pending-state ownership handling don't need to be applied in two places.mobile/packages/expo-hardware-keyboard/src/HardwareKeyboardCaptureView.tsx (1)
10-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReduce this docblock to one non-obvious rationale.
It restates the implementation and fallback behavior visible below. For example:
Proposed change
-/** - * Wraps the live-terminal TextInput so physical keys enter the native - * responder/view chain. Falls back to a plain View on web/tests. - */ +/** Keeps terminal navigation and control keys in the native responder chain. */As per coding guidelines, comments must be “concise, limited to non-obvious information, and preferably one line.”
Source: Coding guidelines
mobile/packages/expo-hardware-keyboard/android/src/main/java/expo/modules/hardwarekeyboard/HardwareKeyboardCaptureView.kt (1)
131-136: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueTighten the function-key test to the mapped set.
key.startsWith("F")is a prefix heuristic that happens to be safe only becausecanonicalKeylowercases fallback labels. A future canonical name starting withF(e.g."Find") would silently be treated as a terminal special key.♻️ Match F1–F12 explicitly
- key == "Home" || key == "End" || key == "PageUp" || key == "PageDown" || - key.startsWith("F") + key == "Home" || key == "End" || key == "PageUp" || key == "PageDown" || + FUNCTION_KEYS.contains(key) } + + private companion object { + val FUNCTION_KEYS = (1..12).map { "F$it" }.toSet() + }mobile/src/terminal/terminal-live-hardware-keyboard-focus.test.ts (1)
9-27: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd an
idledecision case.
getTerminalLiveHardwareKeyboardFocusDecisionhas three outcomes but onlysilent-focusandsoft-focusare asserted; the!liveInputEnabled || !canSendgate (which prevents focus/capture on a non-sendable terminal) is untested.💚 Suggested test
+ it('Given live input disabled When decided Then idle', () => { + expect( + getTerminalLiveHardwareKeyboardFocusDecision({ + wantSoftKeyboard: true, + liveInputEnabled: false, + canSend: true + }) + ).toEqual({ kind: 'idle' }) + })mobile/app/h/[hostId]/session/[worktreeId].tsx (1)
1085-1100: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the modal aggregation into a named, testable helper.
This 15-term chain is the single gate for hardware capture, soft-latch release, and blur-on-open. Any modal state added later must be remembered here or physical keys keep reaching the terminal while a sheet is open. Moving it next to the other session-route helpers (e.g.
mobile-session-route-helpers.ts) makes it unit-testable and keeps the render body readable.♻️ Sketch
- const hardwareKeyboardModalOpen = - showHeaderMoreActions || - showQuickCommands || - ... - deleteKeyTarget != null + const hardwareKeyboardModalOpen = isMobileSessionModalOpen({ + showHeaderMoreActions, + showQuickCommands, + showCreateTabDrawer, + showCreateBrowserModal, + showCustomKeyModal, + showDictationSetup, + pendingDiffNotesDelivery, + actionTarget, + markdownActionTarget, + fileActionTarget, + browserActionTarget, + leaveDrafts, + discardMarkdownTarget, + renameTarget, + deleteKeyTarget + })mobile/src/terminal/use-terminal-live-hardware-keyboard.test.ts (1)
8-18: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReplace the
react-test-rendererdeprecation suppression.
@testing-library/react-nativeis already in the mobile test stack, andrenderHook/RNTL event APIs can replace the React Test Renderer harness here so this test no longer depends on keeping the deprecated renderer warning hidden.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6dcd3746-519c-424f-baef-365c8020ed99
⛔ Files ignored due to path filters (1)
mobile/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (28)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/package.jsonmobile/packages/expo-hardware-keyboard/android/build.gradlemobile/packages/expo-hardware-keyboard/android/src/main/AndroidManifest.xmlmobile/packages/expo-hardware-keyboard/android/src/main/java/expo/modules/hardwarekeyboard/ExpoHardwareKeyboardModule.ktmobile/packages/expo-hardware-keyboard/android/src/main/java/expo/modules/hardwarekeyboard/HardwareKeyboardCaptureView.ktmobile/packages/expo-hardware-keyboard/expo-module.config.jsonmobile/packages/expo-hardware-keyboard/ios/ExpoHardwareKeyboard.podspecmobile/packages/expo-hardware-keyboard/ios/ExpoHardwareKeyboardModule.swiftmobile/packages/expo-hardware-keyboard/ios/HardwareKeyboardCaptureView.swiftmobile/packages/expo-hardware-keyboard/package.jsonmobile/packages/expo-hardware-keyboard/src/ExpoHardwareKeyboard.types.tsmobile/packages/expo-hardware-keyboard/src/ExpoHardwareKeyboardModule.tsmobile/packages/expo-hardware-keyboard/src/ExpoHardwareKeyboardModule.web.tsmobile/packages/expo-hardware-keyboard/src/HardwareKeyboardCaptureView.tsxmobile/packages/expo-hardware-keyboard/src/index.tsmobile/packages/expo-hardware-keyboard/tsconfig.jsonmobile/src/session/MobileTerminalLiveInputBar.tsxmobile/src/terminal/terminal-live-hardware-key-mapping.test.tsmobile/src/terminal/terminal-live-hardware-key-mapping.tsmobile/src/terminal/terminal-live-hardware-key-native-contract.test.tsmobile/src/terminal/terminal-live-hardware-keyboard-focus.test.tsmobile/src/terminal/terminal-live-hardware-keyboard-focus.tsmobile/src/terminal/terminal-live-input-affordance.test.tsmobile/src/terminal/use-terminal-live-hardware-keyboard.test.tsmobile/src/terminal/use-terminal-live-hardware-keyboard.tsmobile/src/terminal/use-terminal-live-input-commit.test.tsmobile/src/terminal/use-terminal-live-input-commit.ts
|
+1 to this, I am using iPad OS to work remotely on daily basis, would like to see this implemented, any help needed? |
|
@littleq0903 yes — physical-iPad verification is the one gap this PR can't close from here. It's listed under "Device/build gaps before merge" in the description: simulator testing can't settle #10447's report that the iPadOS Focus Engine may consume Tab / Up / Down, and held-key repeat is device-unverified. The implementation relies on If you can run a dev build on your iPad with a hardware keyboard, these five checks would unblock it:
For any failure, note the key and whether the app swallowed it or the system did — that distinction picks the fix. @brennanb2025 owns the current head, so results should land here and he can sequence them. |
|
I can help on that, I am using an iPad OS as my major command center to a heavy agentic workflow. |
|
@littleq0903 thank you — that is exactly the gap. A short physical-iPad checklist if you have a few minutes while driving a real agent workflow: Setup
Must-pass
Must-not-break
Please report back
No need for a formal write-up — a short bullet list in this thread is enough. I will fold failures into the PR before asking for merge. |
Physical iPad hardware-keyboard verification checklistI’m taking the real-device verification requested above. I’ll test the current PR head and update this checklist with the results. Test environment
PTY key delivery
Focus and input ownership
Composition and system shortcuts
Failure reporting
|
|
@littleq0903 thank you — perfect. Holding this head for your run so results stay unambiguous:
Whenever you post the checklist results (or any early failure notes), I will fold them into the PR description. |
|
I am building it currently, I did have only iOS resources previously so i am setting up everything, almost done setting up and begin the testing. |
|
I've been traveling with iPadOS for a few months now. Most of my work involves codex and claude sessions (maintaining more than 15 online production services), and as long as I have a terminal and remote access, everything runs pretty smoothly. However, Orca has shown me that I might be able to access these resources with much lower latency and bandwidth, so I'm really looking forward to it. Hopefully this helps. |
|
I am testing now, arrow keys worked now, but I had to click the Live input button at the bottom to be able to input anything. |
|
@littleq0903 great signal — arrows reaching the PTY means the native capture path is live on real iPad hardware. On needing the Live input control first: that first claim is expected. Hardware keys only route once the hidden live-input field owns focus; the bar/button is the explicit entry. After that first claim, the intended model is silent hold (keys keep working without re-tapping, and without forcing the software keyboard up). Worth checking next:
Please keep going through the rest of your checklist (Ctrl-C/D/Z, Tab/Shift-Tab, held-key repeat, IME, Cmd-Tab/Cmd-Space). No code changes from me mid-run so the oracle stays on |
|
Magic Keyboard doesn't have
shift tab doesn't work while tab is working I don't have any bluetooth keyboard unfortunately. |
|
@bbingz the result posted. |
|
@littleq0903 thank you — this is exactly the oracle we needed. Folded your results into the PR description. Summary I recorded
No rebase from me this cycle (still dirty vs |
|
Closing as part of fork PR backlog cleanup. This branch is long-conflicted (DIRTY) against current |
Summary
Review fixes
The review found and fixed these material issues:
UIKeyCommandobjects during key resolution. The commands are now cached once per process.UIKeyCommand.inputDeleteis U+0008 (Backspace), so the prior canonicalization made forward Delete unreachable. Backspace and U+007F forward Delete are now distinct.TextInputfocused, allowing printable input or Enter to leak beneath some modals. Modal open now blurs the field.Issue scope
This PR intentionally does not close either issue:
+path can hang the app, is untouched.Verification
origin/main: 351 test files / 2,590 passed / 2 skippedpnpm lint(oxlint)pnpm format:check(oxfmt; no Prettier)pnpm typecheck(tsc --noEmit)node config/scripts/check-max-lines-ratchet.mjsgit diff --check origin/main...HEADExpoHardwareKeyboardXcode iOS Simulator build: BUILD SUCCEEDED, compiling the edited SwiftThe full suites ran at two workers because the host was saturated. No silent or stalled lane was treated as success.
Review
The requested same-model adversarial review loop checked the full implementation for correctness, regression risk, and performance. It produced the Android AltGr, iOS forward Delete, and modal-focus fixes above; the final pass returned clean after focused tests and static gates.
No polling, provider scans, IPC fanout, or subprocess work was added. Android key classification remains bounded O(1), while iOS changes per-resolution command construction from 226 allocations to one process-lifetime static command array.
Desktop macOS/Linux/Windows input paths are untouched. Mobile local, daemon, relay, folder-workspace, git-worktree, and SSH terminals continue through the existing PTY send path; the native capture layer does not assume a local git worktree.
Device/build gaps before merge
Physical iPad verification (2026-08-07) — @littleq0903
005622e5a67bb3e64c94e9125895188a935a337acom.littleq0903.orca.mobile.devwithExpoHardwareKeyboard, Metro over LANStill open
ELI5
Physical keyboards on mobile terminals only partly worked. Native capture now maps terminal keys without breaking IME or system shortcuts, and review fixes cover modifier edge cases, forward Delete, modal ownership, and a hot-path iOS allocation problem.