iOS mobile terminal: SPM repackage + render-grid faithful replay

Merged
LA
6mo ago
+50119-560

Summary

The SPM-repackaged iOS mobile terminal line, pushed as its own PR (parallel to https://github.com/manaflow-ai/cmux/pull/4055). It splits the iOS mobile code into Packages/ SPM modules under Swift 6 strict concurrency, and adds render-grid faithful cold-attach replay plus the root-cause iOS rendering fixes.

What's in it

  • SPM repackage. iOS mobile split into Packages/ modules (CMUXMobileCore, CmuxMobileAuth, CmuxMobileTerminal, CMUXAuthCore, …); ios/cmuxPackage/cmuxFeature consumes them as dependencies. Swift 6 strict concurrency.
  • Render-grid faithful replay. The ghostty producer exports the active screen (primary/alternate), DEC/ANSI modes, dynamic fg/bg/cursor colors, and scrollback history alongside the visible viewport, so a mobile mirror restores terminal state faithfully on cold attach.
  • iOS rendering fixes (ghostty feat-pty-tee-cb @ 90bbff12a): glyph DPI on iOS (72 like macOS, not the FreeType 96 that inflated glyphs ~1.33x), and two pinch-zoom render-freeze root causes (coretext CF-release mailbox and renderer-health mailbox both switched from .forever to .instant pushes so a zoom storm can't wedge the serial render queue).
  • Terminal UX. Configurable terminal shortcuts, viewport self-heal after resize, accessory-bar tweaks, arrow-key (CSI/SS3) and option-backspace mapping over mobile input.
  • Security. mobile.attach_ticket.create now requires auth (routes through the Stack Auth account token), removing unauthenticated attach-ticket minting.

Relationship to #4055

Both branches descend from a shared 2026-05-29 ancestor and are parallel rewrites of the same iOS mobile subsystems (RPC, terminal input, auth). https://github.com/manaflow-ai/cmux/pull/4055 is the stabilization line (auth/input/overflow hardening). This branch is the SPM-repackaged feature line. They do not cleanly merge (a naive merge fails to compile and reverts hardening), so integration of the two is a deliberate follow-up decision, not done here.

Status / known gaps

  • Behind main (~182 commits); the main merge is deferred, so this PR may show conflicts with main until merged.
  • ghostty points at manaflow-ai/ghostty feat-pty-tee-cb @ 90bbff12a. No prebuilt xcframework exists for this SHA, so CI builds GhosttyKit from source.
  • CI validation via test-ios.yml.

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag @codesmith with what you need. Autofix is disabled.


[!NOTE]
Medium Risk
Auth launch and session-restore behavior changed (users may see sign-in/restore longer until tokens validate); new shared wire formats and CI paths need cross-platform compatibility checks.

Overview
This PR adds shared mobile/auth packages and CI, and tightens launch-time auth gating so cached credentials no longer look signed-in before validation finishes.

CMUXMobileCore introduces wire types for mobile sync and terminal mirroring: attach tickets/routes with validation, pairing QR payloads (secret fields rejected), length-prefixed framing, and cmux.render-grid.v1 frames with a MobileTerminalRenderGridReplay VT synthesizer for full cold-attach vs delta row updates (scrollback, alternate screen, DEC/ANSI modes, styled spans).

CmuxAuthRuntime extracts an injected AuthCoordinator (Stack client, config resolver, error mapping, push registration) with tests around session restore: transient failures stay retryable when a refresh token remains; definitive token loss clears state and routes to sign-in.

CMUXAuthState.primed now sets isAuthenticated = false and isRestoringSession = true when tokens or auto-login credentials exist, until live validation completes (tests updated).

CI/docs: macOS jobs drop shared DerivedData caching in favor of per-run isolated CMUX_DERIVED_DATA_PATH; new test-ios.yml runs package-convention lint, CMUXMobileCore swift test, and iPhone/iPad simulator matrices with GhosttyKit provisioning and flaky-launch retries. CLAUDE.md bans free functions except sanctioned C trampolines; .gitignore adds local iOS plist and experiment build dirs.

Reviewed by Cursor Bugbot for commit c35ea51a0a350317101eb99db82a65d8fdb2fb21. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Repackages the iOS terminal into Swift 6 SPM modules, adds a shared auth runtime, and delivers faithful render‑grid cold‑attach replay with instant server‑push updates. Renames the app target to cmux, adds QR pairing and a Settings menu, and stabilizes CI.

  • New Features

    • Persistent multiplexed transport with serialized writes; subscribe to events.v1 and replace the 750 ms poll with terminal.updated/workspace.updated pushes (runtime‑flag fallback for older hosts).
    • Render‑grid replay from Ghostty active‑area VT export (write_active_file) for ANSI styles and row alignment; pinch‑to‑zoom with a reset button while zoomed.
    • SPM split into shared Swift 6 packages: CmuxAuthRuntime, CMUXMobileCore, CmuxMobileRPC, CmuxMobileShell/CmuxMobileShellModel, CmuxMobileCamera, CmuxMobilePairedMac, CmuxMobileDiagnostics; ios/cmuxPackage exposes cmuxFeature.
    • Auth: new CmuxAuthRuntime with injected AuthCoordinator; primed state keeps isAuthenticated false and isRestoringSession true until live token validation; push registration via PushRegistrationService.
    • Pairing/persistence: QR scan stream and URL decode, SQLite‑backed paired‑Mac store scoped to the signed‑in user; show the auth account in pairing; Settings adds Rescan QR + Sign Out.
    • App/CI: rename cmuxMobile to cmux; add test-ios.yml simulator matrix, isolated DerivedData, GhosttyKit provisioning, and iPad stabilization.
  • Bug Fixes

    • Keystroke echo latency: honor normal TTL and bypass cache during pending echo (~200 ms) to cut echo from ~1 s to ~120 ms.
    • Transport/events: dedicated writer queue, subscribe‑ack validation, capability advertisement, and dropped cancelled writes.
    • Snapshot fidelity: fix cursor row drift, VT row splitting, preserve ANSI styling across input, and bound the cursor source to the active area.
    • Auth/attach: enforce terminal‑scoped attach tickets; stricter route trust (Stack auth only over encrypted or loopback); manual pairing auth fallback; preserve cached user on transient failures.
    • Input/viewport: chunk input with a back‑pressured buffer; clear viewport limits on disconnect; keep reports across RPC closes; reliable real‑time workspace list updates.

Summary by CodeRabbit

  • New Features

    • Launch a SwiftUI iOS/macOS mobile experience: sign-in, device pairing, attach-ticket pairing, route selection, server-push events, terminal replay/export, viewport/zoom controls, and in-app mobile UI flows.
  • Bug Fixes

    • Session priming now avoids treating auto-login credentials as fully authenticated before session restore completes.
  • Testing

    • Added iOS simulator CI workflow and broad unit/UI test coverage for mobile auth, host RPC, transport, and viewport.
  • Infrastructure

    • New mobile packages, iOS project/configs, assets, and CI improvements.
  • Documentation

    • Added iOS Swift mobile plan and README.