Skip to content

feat(mobile): add hardware keyboard navigation - #20537

Open
isairz wants to merge 6 commits into
stablyai:mainfrom
isairz:mobile-keyboard-nav-core
Open

isairz wants to merge 6 commits into
stablyai:mainfrom
isairz:mobile-keyboard-nav-core

Conversation

@isairz

@isairz isairz commented Sep 14, 2026 •

Copy link
Copy Markdown

ELI5

Adds hardware-keyboard navigation for the mobile worktree/session experience.

What Changed

  • Adds mobile hardware-keyboard command registration and worktree navigation.
  • Keeps navigation ordering, history, palette routing, and stale-response cancellation together.
  • Routes worktree catalog/activation through typed RPC operations.
  • Guards embedded sidebar catalog updates against host-transition races.
  • Terminal/chat input stability remains a separate follow-up PR based on this branch.

Why

This is the focused navigation slice of the original #18195 implementation, so it can be reviewed and landed independently from iOS terminal input stability.

Linked Issue

Visual Proof

N/A — behavior is exercised through hardware-keyboard and navigation tests; physical-device evidence remains in the original implementation context.

Testing

  • ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run mobile/src/hardware-keyboard/use-mobile-worktree-keyboard-navigation.test.ts mobile/src/worktree/worktree-catalog-snapshot-client.test.ts mobile/src/session/mobile-session-route-parity.test.ts
  • ORCA_BACKGROUND_LAUNCH=1 pnpm tc
  • node config/scripts/check-changed-code-quality.mjs e9db1642d1

Review focus

  • Navigation commands and stale route cancellation
  • Host-scoped sidebar catalog updates
  • Typed RPC operation boundaries

Agent skill upstream boundary

No upstream agent-skill changes are included.

Notes

Checklist

  • Focused navigation changes only
  • Bot review fixes applied
  • Tests and typecheck pass
  • Physical-device validation for this split PR

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: f8e79808-de63-4f38-9041-86a61fbb66c8

📥 Commits

Reviewing files that changed from the base of the PR and between b2be4ed and 15b2403.

📒 Files selected for processing (10)
  • mobile/app/h/_layout.tsx
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-actions.ts
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-preferences.ts
  • mobile/src/hardware-keyboard/use-mobile-hardware-keyboard-commands.ts
  • mobile/src/hardware-keyboard/use-mobile-worktree-keyboard-navigation.test.ts
  • mobile/src/hardware-keyboard/use-mobile-worktree-keyboard-navigation.ts
  • mobile/src/host-screen/use-host-screen-controller.ts
  • mobile/src/session/mobile-session-route-parity.test.ts
  • mobile/src/worktree/worktree-catalog-snapshot-client.test.ts
  • mobile/src/worktree/worktree-catalog-snapshot-client.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-preferences.ts
  • mobile/src/hardware-keyboard/use-mobile-worktree-keyboard-navigation.ts
  • mobile/src/hardware-keyboard/use-mobile-hardware-keyboard-commands.ts
  • mobile/src/hardware-keyboard/use-mobile-worktree-keyboard-navigation.test.ts
  • mobile/app/h/_layout.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The mobile app now supports hardware keyboard commands through a local Expo module for Android and iOS. It adds platform-aware bindings, persisted terminal shortcut preferences, tab navigation, worktree navigation, session context tracking, and route integration. A hardware keyboard settings screen and menu entry were added. Worktree catalog requests now use the shared RPC settlement pipeline. Tests cover command translation, preferences, registries, navigation helpers, session context, and deferred worktree requests.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 15b24

Disconnecting a hardware keyboard may leave software-keyboard input unavailable on an active iOS surface. This is a bounded usability risk requiring owner awareness or follow-up.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.53% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 79 functions across 43 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ⚠️ Warning The description references #18195 as the source PR, but the objectives identify #18041 as the issue fixed. The required Fixes #18041`` relationship is missing. Add Fixes #18041`` to the Linked Issue section. Keep #18195 as a related or superseded PR reference.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changes align with the stated objectives for mobile hardware-keyboard navigation, settings, native integrations, scoped command handling, stale-response protection, and related RPC updates.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding hardware keyboard navigation for mobile.
Description check ✅ Passed The description covers the main change, reason, linked issue reference, visual-proof status, testing commands, review focus, scope notes, and checklist. It does not include a separate Review heading, …
  • Fix all pre-merge checks with AI

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.

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: bb33aa44-f1b7-4516-845f-3d50d18a23eb

📥 Commits

Reviewing files that changed from the base of the PR and between e9db164 and 9e668ca.

⛔ Files ignored due to path filters (1)
  • mobile/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (47)
  • mobile/app/_layout.tsx
  • mobile/app/h/_layout.tsx
  • mobile/app/hardware-keyboard-settings.tsx
  • mobile/package.json
  • mobile/packages/expo-hardware-keyboard-navigation/android/build.gradle
  • mobile/packages/expo-hardware-keyboard-navigation/android/src/main/java/expo/modules/hardwarekeyboardnavigation/ExpoHardwareKeyboardNavigationModule.kt
  • mobile/packages/expo-hardware-keyboard-navigation/android/src/main/java/expo/modules/hardwarekeyboardnavigation/HardwareKeyboardActivityLifecycleListener.kt
  • mobile/packages/expo-hardware-keyboard-navigation/android/src/main/java/expo/modules/hardwarekeyboardnavigation/HardwareKeyboardNavigationPackage.kt
  • mobile/packages/expo-hardware-keyboard-navigation/android/src/main/java/expo/modules/hardwarekeyboardnavigation/HardwareKeyboardNavigationRegistry.kt
  • mobile/packages/expo-hardware-keyboard-navigation/android/src/main/java/expo/modules/hardwarekeyboardnavigation/HardwareKeyboardWindowCallback.kt
  • mobile/packages/expo-hardware-keyboard-navigation/expo-module.config.json
  • mobile/packages/expo-hardware-keyboard-navigation/ios/ExpoHardwareKeyboardNavigation.podspec
  • mobile/packages/expo-hardware-keyboard-navigation/ios/ExpoHardwareKeyboardNavigationModule.swift
  • mobile/packages/expo-hardware-keyboard-navigation/package.json
  • mobile/packages/expo-hardware-keyboard-navigation/src/index.ts
  • mobile/src/cache/worktree-cache.ts
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-actions.ts
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-bindings.test.ts
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-bindings.ts
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-preferences.test.ts
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-preferences.ts
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-registry.test.ts
  • mobile/src/hardware-keyboard/mobile-hardware-keyboard-registry.ts
  • mobile/src/hardware-keyboard/mobile-session-hardware-keyboard-context.test.ts
  • mobile/src/hardware-keyboard/mobile-session-hardware-keyboard-context.ts
  • mobile/src/hardware-keyboard/mobile-tab-keyboard-navigation.test.ts
  • mobile/src/hardware-keyboard/mobile-tab-keyboard-navigation.ts
  • mobile/src/hardware-keyboard/mobile-worktree-keyboard-navigation.test.ts
  • mobile/src/hardware-keyboard/mobile-worktree-keyboard-navigation.ts
  • mobile/src/hardware-keyboard/mobile-worktree-keyboard-rpc-operations.ts
  • mobile/src/hardware-keyboard/use-hardware-keyboard-text-input-focus.ts
  • mobile/src/hardware-keyboard/use-mobile-hardware-keyboard-commands.ts
  • mobile/src/hardware-keyboard/use-mobile-hardware-keyboard-preferences.ts
  • mobile/src/hardware-keyboard/use-mobile-session-keyboard-navigation.ts
  • mobile/src/hardware-keyboard/use-mobile-worktree-keyboard-navigation.test.ts
  • mobile/src/hardware-keyboard/use-mobile-worktree-keyboard-navigation.ts
  • mobile/src/hooks/use-active-worktree-scroll.ts
  • mobile/src/host-screen/use-host-screen-controller.ts
  • mobile/src/session/MobileNativeChatComposer.test.ts
  • mobile/src/session/MobileNativeChatComposer.tsx
  • mobile/src/session/MobileSessionCommandDock.tsx
  • mobile/src/session/mobile-session-route-parity.test.ts
  • mobile/src/session/use-mobile-session-controller.ts
  • mobile/src/settings/mobile-settings-menu-items.ts
  • mobile/src/terminal/terminal-live-input-affordance.test.ts
  • mobile/src/transport/unvalidated-rpc-request-port-inventory.ts
  • mobile/src/worktree/worktree-catalog-snapshot-client.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread mobile/app/h/_layout.tsx Resolved
const touchFocusFrameRef = useRef<number | null>(null)

useEffect(() => {
if (!enabled || !isHardwareKeyboardConnected()) {

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

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Description: Look for a hardware-keyboard connection-change subscription API.
fd -t f . mobile/packages/expo-hardware-keyboard-navigation --exec rg -n -C3 'isHardwareKeyboardConnected|addListener|Event|subscribe|onConnect' {}

Repository: stablyai/orca

Length of output: 5230


🏁 Script executed:

#!/bin/bash
set -eu
hook=$(fd -t f 'use-hardware-keyboard-text-input-focus\.ts$' . | head -n 1)
printf '%s\n' "HOOK=$hook"
cat -n "$hook"
printf '\n-- native module files --\n'
fd -t f . mobile/packages/expo-hardware-keyboard-navigation --exec sh -c 'for f do case "$f" in *.ts|*.tsx|*.kt|*.swift) printf "\n### %s\n" "$f"; rg -n -C8 "isHardwareKeyboardConnected|onHardwareKeyboardCommand|addListener|OnStartObserving|Events\\(" "$f" || true;; esac; done' sh {}

Repository: stablyai/orca

Length of output: 7965


Soft-input suppression does not react to a hardware keyboard disconnect.

isHardwareKeyboardConnected() is sampled only when the effect re-runs, and the deps are [enabled, inputRef, surfaceId]. If the user disconnects the keyboard while the same surface stays active, suppressSoftInput stays true and showSoftInputOnFocus stays false.

On Android handleTouchStart clears the state on the next tap. On iOS line 57 returns early, so the input stays focused with no software keyboard until enabled or surfaceId changes.

If the native module exposes a connection-change event, subscribe to it and re-evaluate the suppression state. Otherwise, allow the touch recovery path on iOS as well.

Run the following script to check for a connection-change API on the native module:

#!/bin/bash
# Description: Look for a hardware-keyboard connection-change subscription API.
fd -t f . mobile/packages/expo-hardware-keyboard-navigation --exec rg -n -C3 'isHardwareKeyboardConnected|addListener|Event|subscribe|onConnect' {}

@pullfrog pullfrog 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.

Caution

This PR does not currently pass CI: two mobile test files fail (10 tests) and the changed-code quality gate reports 7 new type-assertion findings. One failure is a genuine behavior regression — WorktreeCatalogSnapshotClient.fetch can now return code: undefined where it previously fell back to 'request_failed'.

Reviewed changes

  • Native Android module — new local Expo module that wraps the Activity Window.Callback and dispatches matched KeyEvents through a process-wide command registry + weak observer set.
  • Native iOS module — installs UIKeyCommands on the key window's root view controller via an added handler method and emits onHardwareKeyboardCommand events.
  • JS command layer — buildMobileHardwareKeyboardCommands maps shared keybinding definitions to native commands (Mod→Ctrl on Android/Linux, Mod→Command on iOS; digit-index actions expand to 1–9), scoped by context and terminal policy with newest-scope-wins dedup.
  • Navigation hooks — worktree/tab cycle helpers, MobileWorktreeNavigationHistory / MobileRecentTabOrder, the session-context registry, and host-layout wiring that publishes the sidebar-rendered worktree order.
  • Soft-keyboard suppression — useHardwareKeyboardTextInputFocus shared by the terminal command dock and native chat composer.
  • Settings — new hardware-keyboard screen and settings-menu entry.
  • Typed worktree catalog RPC — worktree.ps now routes through an RpcOperation; getLastCachedWorktrees added to the cache.

🚨 Existing WorktreeCatalogSnapshotClient tests fail — extra trailing argument

Routing worktree.ps through captureRpcOperationSettlement changed the call shape the test mock observes: rpc-operation.ts's request() always calls client.sendRequest(method, params, options), so a third undefined argument now reaches every mock. Six assertions in mobile/src/worktree/worktree-catalog-snapshot-client.test.ts still expect exactly two arguments, and that test file is not part of this PR's diff.

Technical details
# worktree-catalog-snapshot-client.test.ts assertions vs the RPC operation call shape

## Affected sites
- `mobile/src/worktree/worktree-catalog-snapshot-client.ts:77` — calls `captureRpcOperationSettlement(client, mobileWorktreeCatalog, params)`.
- `mobile/src/transport/rpc-operation.ts:105` — `request()` forwards `options` (undefined here) to `client.sendRequest`, adding a third argument.
- `mobile/src/worktree/worktree-catalog-snapshot-client.test.ts:122,136,154,168,185,209` — `toHaveBeenNthCalledWith(n, 'worktree.ps', {…})` now mismatches on the trailing `undefined`.

## Required outcome
- `cd mobile && pnpm test` is green. Either extend those assertions (trailing `undefined` or `expect.anything()`), or avoid passing an absent `options` through the operation.

## Open questions for the human
- Is the `captureRpcOperationSettlement` signature deliberately always forwarding `options` (so every strict mock must change), or should an omitted `options` stay omitted?

⚠️ Changed-code quality gate fails on new type assertions

node config/scripts/check-changed-code-quality.mjs e9db164 fails with 7 typescript/consistent-type-assertions findings on added lines. The first (code quality) scan, type-aware scan and React Doctor scan are clean; only the casting scan fires. AGENTS.md requires every unavoidable cast to carry a line-specific SAFETY:-annotated disable, and the gate's own SAFETY: check confirms none of these have one.

Technical details
# typescript/consistent-type-assertions findings on added lines

## Affected sites
- `mobile/src/hardware-keyboard/mobile-hardware-keyboard-actions.ts:33` — `MOBILE_HARDWARE_KEYBOARD_ACTIONS as readonly string[]`
- `mobile/src/hardware-keyboard/use-mobile-worktree-keyboard-navigation.ts:157` — `getLastCachedWorktrees(hostId) as Worktree[] | null`
- `mobile/src/hardware-keyboard/use-mobile-worktree-keyboard-navigation.test.ts:11,71,72,73`

## Required outcome
- `pnpm run check:code-quality:changed` is clean. Prefer typed code (`MOBILE_HARDWARE_KEYBOARD_ACTIONS.some((action) => action === actionId)`, a typed cache accessor) where possible; otherwise add `// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: …` on each added line.

ℹ️ Nitpicks

  • useHardwareKeyboardTextInputFocus reads isHardwareKeyboardConnected() once per effect run, so connecting a physical keyboard after mount does not re-evaluate suppression until surfaceId changes.
  • Mobile ignores user keybinding overrides — both the settings list and the command builder call getEffectiveKeybindingsForAction(actionId, platform) with no overrides argument, so desktop remaps do not reach the phone.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

Important

The latest commit is clean, but the CI blockers from the previous review are still present at b200885: 10 mobile tests fail in 2 files and pnpm run check:code-quality:changed still reports 7 findings.

Reviewed changes

Incremental review of b200885 (refactor(mobile): keep terminal focus fixes out of navigation) on top of the prior review of 9e668ca.

  • Soft-keyboard suppression reverted — use-hardware-keyboard-text-input-focus.ts is deleted, and its ref/onTouchStart/showSoftInputOnFocus wiring is removed from MobileNativeChatComposer.tsx and MobileSessionCommandDock.tsx (the live input goes back to bare showSoftInputOnFocus).
  • Associated tests reverted — MobileNativeChatComposer.test.ts and terminal-live-input-affordance.test.ts drop the hardware-keyboard cases; both files pass again (23 tests) and no dangling references to the removed hook remain.

No new issues found in the delta. Current status of the previously reported findings (re-verified at this HEAD, not re-filed): mobile/src/session/mobile-session-route-parity.test.ts (3 tests) and mobile/src/worktree/worktree-catalog-snapshot-client.test.ts (7 tests) still fail, and the casting scan still flags mobile-hardware-keyboard-actions.ts:33, use-mobile-worktree-keyboard-navigation.ts:157, and use-mobile-worktree-keyboard-navigation.test.ts:11,71–73.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Incremental review of 15b2403 (fix(mobile): address navigation bot reviews) on top of the prior Pullfrog review of b200885. This delta resolves all six open threads from the previous review; no new issues found.

  • Stale-route cancellation hardened — useMobileWorktreeKeyboardNavigation's route generation now also keys on worktreeId, so a worktree change within the same host cancels an in-flight catalog response; h/_layout.tsx scopes updateSidebarKeyboardWorktrees to the emitting host (emittedHostId === hostId); and WorktreeCatalogSnapshotClient restores the non-empty-string 'request_failed' code fallback.
  • Quality-gate fixes — isMobileHardwareKeyboardActionId uses a .some() predicate instead of a readonly string[] cast, and the remaining implementation/test casts carry SAFETY:-annotated oxlint-disable-next-line directives.
  • Parity + RPC test expectations regenerated — mobile-session-route-parity.test.ts constants and worktree-catalog-snapshot-client.test.ts assertions (third undefined arg) were updated for the current source; both suites pass.
  • Preferences retry + effect timing — a failed keyboard-preferences load now clears loadPromise so a later mount retries, and the command handler ref updates in useLayoutEffect.

Verified locally at 15b2403: 9 affected files / 33 tests pass, and node config/scripts/check-changed-code-quality.mjs e9db1642d1 reports 0 findings across every scan. The full mobile suite passes 4734 tests; the 14 files that error there fail only on missing *-webview-engine.generated build artifacts, unrelated to this PR.

ℹ️ Physical-device validation remains pending

The PR body still leaves "Physical-device validation for this split PR" unchecked. The navigation layer is unit-tested, but the Android Window.Callback interception and iOS UIKeyCommand installation are only exercised on real hardware. Flagging so the outstanding manual pass is a conscious decision rather than a missed checkbox.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
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