fix(mobile): preserve terminal input mode on reentry
Summary
Fixes #6972.
Preserve the mobile terminal input mode across Android terminal re-entry and session/tab refreshes.
Before this change, switching a terminal from live input to buffered input could be lost after leaving and re-entering the terminal because that preference lived only in transient mobile session state.
This change:
- Persists per-worktree live-input opt-outs.
- Restores the preference before terminal handles are defaulted again.
- Isolates the behavior in a focused hook.
Screenshots
- No visual change.
Checklist
- [x]
pnpm lint - [x]
pnpm typecheck - [x]
pnpm test - [x]
pnpm build - [x] Added or updated high-quality tests that would catch regressions, or explained why tests were not needed.
Focused checks run
- [x]
pnpm --dir mobile exec vitest run src/storage/preferences.test.ts src/terminal/terminal-live-input.test.ts - [x]
pnpm exec oxlint mobile/src/storage/preferences.ts mobile/src/storage/preferences.test.ts mobile/src/terminal/terminal-live-input.ts mobile/src/terminal/terminal-live-input.test.ts mobile/src/session/use-terminal-live-input-mode-preference.ts mobile/app/h/[hostId]/session/[worktreeId].tsx
AI Review Report
Reviewed for:
- Cross-platform compatibility
- SSH, remote, and local behavior
- Git-provider neutrality
- Performance risk
- Regression risk around terminal/session re-entry
Main finding
The input-mode preference was stored only in transient mobile session state, so re-entering the terminal could treat an existing terminal handle as newly defaulted to live input.
The fix:
- Persists the opt-out preference.
- Restores it before defaulting terminal handles.
- Adds regression test coverage.
No desktop shortcuts, Electron menus, path separator behavior, or platform-label behavior changed in this PR.
Security Audit
Reviewed:
- Local preference persistence
- Input handling
- Path/key construction
- Command execution
- IPC surface
- Authentication
- Secrets
- Dependency risk
No new command execution, authentication, secret handling, or IPC surface was introduced. The new behavior only persists phone-local preference state in AsyncStorage, scoped by host and worktree.
📝 Walkthrough
Walkthrough
This change adds host/worktree-scoped persistence for disabled terminal live-input handles, helper functions for reconciling enabled and defaulted handle sets, and a new useTerminalLiveInputModePreference hook that centralizes live-input hydration, toggling, pruning, and clearing. SessionScreen now consumes that hook instead of maintaining local live-input mode state and helper logic, and its toggle and cleanup paths were updated accordingly. Tests were added for the new storage helpers, terminal-live-input helpers, and hook behavior.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title is concise and accurately summarizes the main change: preserving mobile terminal input mode on reentry. |
| Description check | ✅ Passed | The description covers summary, screenshots, testing, review, and security; only the exact Notes section and some template specifics are missing. |
| Linked Issues check | ✅ Passed | The changes persist and restore the terminal input-mode preference before defaulting handles, matching #6972's Android reentry requirement. |
| Out of Scope Changes check | ✅ Passed | The changes stay focused on terminal input-mode persistence, related storage, hook logic, and regression tests, with no clear unrelated additions. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
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 @coderabbitai help to get the list of available commands.