Skip to content

Replace the native mobile UI with a WebView shell around the PWA - #2515

Merged
SawyerHood merged 5 commits into
mainfrom
bb/phase-0-spikes-pwa-webview-shell-ios-thr_ehcf4b9d2m
Aug 27, 2026
Merged

SawyerHood merged 5 commits into
mainfrom
bb/phase-0-spikes-pwa-webview-shell-ios-thr_ehcf4b9d2m

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

apps/mobile carried about 112,000 lines of native UI duplicating what
apps/app already renders, so every product feature needed two
implementations. The plan (Docs plans/mobile-webview-shell.md) replaces the
native screens with one WebView over the page, keeping native only what a web
page cannot do on a phone.

What changed

Five commits, in order:

  1. @bb/mobile-bridge — one versioned contract both sides import: the
    handshake the shell installs, page-to-shell messages, shell-to-page events,
    and the injected script itself, so the window.bb.native global cannot
    drift. compareBridgeVersions(remoteVersion, localVersion) is symmetric;
    capabilities are declared in the handshake rather than inferred from the
    version, so a shell can withdraw one without a bump.
  2. The shell — ProfileWebViewScreen, pure logic in src/lib/shell tested
    under node, native error states (re-pair / retry / content-process reload),
    and deep links that resolve to one shell route carrying a web path. The
    session is not re-implemented: the existing connector already mints and
    renews the connect cookie.
  3. The page side — src/lib/native-shell with shellHaptic,
    shellSetBadge, shellOpenExternal, shellShare, shellOpenNative, each
    falling back to web behaviour. The app surface header is now mobile inside
    the shell. Two fixes come from the Phase 0 measurements: the bottom
    safe-area inset collapses while the keyboard is open, and voice input names
    the real reason it is unavailable on a plain-HTTP origin.
  4. End-to-end coverage — the mobile e2e harness serves a built apps/app
    when BB_MOBILE_E2E_SERVE_APP=1, because the shell has no page otherwise.
  5. The delete — 620 files, 95,754 deletions. apps/mobile falls to about
    24,000 lines. 24 dependencies, three Expo config plugins, the committed
    terminal page and its builder go with it.

A native /settings/device screen holds what the phone owns and is the shell's
escape hatch. Three entry points reach it — a row in the page's Settings over
the bridge, the shell's load-failure screen, and a Home Screen quick action —
and only the first needs a live page. That matters: after the delete there is
no native UI to fall back to.

No wire change: HOST_DAEMON_PROTOCOL_VERSION is untouched. mobile was
already in REQUEST_APP_SURFACE_VALUES.

How you verified

Automated: 0 lint errors, typecheck clean, and 23 + 286 + 3,437 tests across
@bb/mobile-bridge, @bb/mobile, and @bb/app after rebasing onto main.

On an iPhone 17 Pro simulator (iOS 26.3), the four CI flows pass against the
e2e harness on a build made after the dependency prune: shell-launch,
shell-deep-link, shell-send (send a message, assert the provider's echo),
and shell-unreachable-server.

On a physical iPhone 15 Pro (iOS 26.6), a Release build installs and runs, and
the Home Screen quick action reaches device settings — the one entry point
simulator automation could not exercise.

Phase 0 measured the risky parts on device before any of this was built; the
numbers and verdicts are in section 11 of the plan. The keyboard fix moved the
composer-to-keyboard gap from 60 CSS px to 26, against about 15 for the old
native composer.

Three bugs the tests caught before they shipped: z.string().url() accepts
javascript: and data:, and open-external reaches the system link opener;
first run behind the shell spun forever with no server paired; and the shell
preference survived a state wipe because it cached its value.

EAP codename scan over origin/main..HEAD: clean (working tree, tracked at
HEAD, added lines, commit messages all 0).

Known gaps

  • navigator.serviceWorker does not exist in WKWebView on any origin bb
    needs. It requires app-bound domains, which would both break Direct mode and
    disable JavaScript injection for any web view that does not opt in — killing
    the bridge. The service worker is therefore dropped from the plan, not
    deferred. Measured cold start is 142 ms (LAN) to 2.1 s (a shaped 3G link),
    which is acceptable without it.
  • Camera capture is unverified. The WKWebView file chooser offers it and
    the photo-library path is proven end to end, but the simulator has no camera
    and I did not exercise it on the device.
  • shell-unreachable-server covers the add-server probe refusing a dead URL,
    not the shell's own load-failure screen. That path is hand-verified;
    automating it needs a harness that can stop answering mid-flow.
  • About 5,800 lines of src/lib/query, src/lib/realtime, and the connection
    layer survive. They are reachable only through the session-cookie path the
    WebView needs, so removing them is a refactor of the connector rather than a
    delete, and it would cost the native chrome its server palette.

AGENT GENERATED

SawyerHood and others added 5 commits August 26, 2026 18:14
## What was wrong

The mobile WebView shell (Docs plans/mobile-webview-shell.md, Phase 1) needs
the app shell and the page it renders to agree on a message contract. The two
ship on different schedules — the shell through the App Store, the page with
whatever server it points at — so they can never assume matching versions.

## What changed

- New workspace package with the whole contract: the handshake the shell
  installs, page-to-shell messages, shell-to-page events, and the injected
  script itself, so the `window.bb.native` global cannot drift between sides.
- `compareBridgeVersions(remoteVersion, localVersion)` is symmetric: both
  sides call it with the version they were handed, an older or newer peer
  stays usable, and only a nonsense version reads as "no bridge".
- Capabilities are declared in the handshake, never inferred from the version,
  so a shell can withdraw one without a version bump.
- Both sides parse at the boundary and drop what they do not recognise. A
  newer page must never crash an older shell.

Bridge version 2 ships here: `open-native` lets the page ask for a native
screen by name, from a closed list rather than a route string, so no script on
the origin can drive the shell's navigator.

## How this was verified

23 tests, including the injected script run against a stub window so the tests
cover the real string the shell ships. One of them caught a live hole:
`z.string().url()` accepts `javascript:` and `data:`, and `open-external` goes
straight to the system link opener, so both it and the share payload now take
an explicit http/https check.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
## What was wrong

Every product feature needs two implementations today: `apps/mobile` is about
112,000 lines of native UI duplicating what `apps/app` already does. The plan
(Docs plans/mobile-webview-shell.md, Phase 2) replaces the native screens with
one WebView over the page, keeping native only what a web page cannot do on a
phone.

## What changed

- `ProfileWebViewScreen` at `/webview`, behind a client-local switch. Both UIs
  ship in the same binary, so a bad page is one toggle away from the native
  screens rather than a reinstall.
- Pure logic in `src/lib/shell` with tests under node: URL building for servers
  behind a path prefix, the screen-state rules, deep-link resolution, and the
  preference store.
- The session is not re-implemented. The existing connector already mints the
  connect cookie and renews it on resume; the screen waits for that and reloads
  when a fresh cookie replaces the one the page loaded with.
- Native error states: re-pair on a rejected credential, retry on a failed load
  or an error status, and a reload when the WebView content process dies.
- Deep links resolve to one shell route carrying a *web* path. Connect
  enrolment, the server list, machines, and device settings stay native.
- A `/settings/device` screen holds what the phone owns, and is the shell's
  escape hatch: it can turn the shell off and clear a wedged page. Three ways
  reach it — a row in the page's Settings over the bridge, the shell's
  load-failure screen, and a Home Screen quick action — and only the first
  needs a working page.

Two WebView props carry Phase 0 measurements (plan section 11):
`mediaCapturePermissionGrantType="grant"`, or WKWebView re-asks for the
microphone on every recording; and `hideKeyboardAccessoryView`, which returns
68 CSS px to the composer. `WKAppBoundDomains` is deliberately absent: it would
disable JavaScript injection for any web view that does not opt in, which
would break the bridge, and it cannot cover Direct-mode hosts anyway.

Also lands the Phase 0 spike harness (`dev/webview-spike`) that produced those
measurements, so the numbers in the plan can be reproduced.

## How this was verified

933 unit tests, and an end-to-end Maestro run on an iPhone 17 Pro simulator:
pair a server, turn the shell on, open a thread from the page, send a message
and get the provider's reply, then turn it off and land back on the native
list. Two bugs it caught: first run behind the switch spun forever with no
server paired, and the preference survived a state wipe because it cached its
value.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
## What was wrong

The page renders inside the mobile WebView shell but had no idea it was there
(Docs plans/mobile-webview-shell.md, Phase 3). Its traffic looked like a
browser, its links tried to open windows a WebView blocks, and the composer sat
in a dead band above the soft keyboard.

## What changed

- `src/lib/native-shell` reads the bridge once at boot and exposes
  `shellHaptic`, `shellSetBadge`, `shellOpenExternal`, `shellShare`, and
  `shellOpenNative`. Each falls back to the web behaviour and reports whether
  the shell took the call, because the same build runs in a plain browser.
- The app surface header is now `mobile` inside the shell, so phone traffic
  stops landing in the `web` bucket.
- `openUrlInExternalBrowser` routes through the shell, mirroring the branch the
  desktop app already had.
- The settings navigation gains a "This device" row when the shell declares
  `open-native`, which is how a user reaches the switch that turns the shell
  off.
- `?initialPrompt=` seeds the root compose view and is stripped from the URL,
  so a share from outside the app does not seed twice on reload.

Two fixes come straight from Phase 0 (plan section 11):

- `useMobileVisualViewportHeight` collapses the bottom safe-area inset while
  the keyboard is open. iOS keeps that inset at full value even though the
  keyboard covers the home indicator. Keyed on a focused editor plus a real
  viewport shrink, so a URL-bar collapse does not trigger it. Measured on
  device: the gap between the composer and the keys fell from 60 CSS px to 26,
  against about 15 for the native app.
- Voice input names the real reason it is unavailable. `getUserMedia` is
  secure-context only, so a plain-HTTP LAN server has no microphone at all;
  "not supported in this browser" was wrong and left nothing to act on.

## How this was verified

3,445 tests. The native-shell tests install the real script the shell ships
rather than a stand-in, which caught the handshake parse failing on the strict
schema because the global carries its functions alongside its fields.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
## What was wrong

The shell renders the page the server serves, so nothing about it can be
proven without a server that actually serves that page. The mobile e2e harness
answered API routes only, and no flow exercised the shell.

## What changed

- The harness serves a built `apps/app` when `BB_MOBILE_E2E_SERVE_APP=1`, the
  way a real bb server does. Every other flow drives native screens and is
  unaffected.
- `phase2-webview-shell.yaml` is the plan's Phase 2 acceptance test: pair the
  harness server, turn the shell on, load the page, open a thread from the
  page, send a message and get the provider's echo, reach the native device
  screen through the page over the bridge, then turn the shell off and land
  back on the native list.
- CI builds the web app before starting the backend, and runs the new flow.

Two things the flow taught us, recorded as comments so the Phase 5 replacement
flows do not repeat them:

- Maestro reads WKWebView content through the accessibility tree, so page
  assertions match text, not test ids. Its iOS driver also crashed once
  snapshotting a full page's hierarchy; treat deep page assertions as the
  flaky part.
- The flow first passed for the wrong reason. It asserted the sent text was
  visible, and that held while the text was still sitting in the composer:
  `inputText` ends with the keyboard's return, which submits only in some
  composer modes. It now taps the submit button and asserts on the provider's
  echo, which is the only thing that proves the message left the phone.

## How this was verified

The flow passes end to end on an iPhone 17 Pro simulator, iOS 26.3.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
## What was wrong

`apps/mobile` carried about 112,000 lines of native screens duplicating what
`apps/app` already renders, so every product feature needed two
implementations. The WebView shell proved out, so the duplicate goes (Docs
plans/mobile-webview-shell.md, Phase 5).

## What changed

Deleted: the thread list, timeline, composer, panel, terminal, files, diffs,
plugins, skills, machines, projects, pickers, and every settings screen the
server owns, plus the data layer, markdown/diff/ansi renderers, and the
showcase screens that existed to demo them. `apps/mobile` falls from ~115,000
lines to ~24,000.

Kept, because a web page cannot do these on a phone: server profiles, bb
connect enrolment and the Keychain credential, the session-cookie mint, deep
links, the share sheet, haptics, the badge, the load-failure screen, and the
WebView itself.

**The shell is now unconditional.** The "use the web interface" switch existed
so a bad page was one toggle away from the native screens; with those gone it
had nothing to switch to. `/settings/device` keeps the recovery actions that
replaced it — reload the page, clear website data — and the three entry points
that reach it still hold, one of which never needs a live page.

Also dropped: 24 dependencies (flash-list, the remark stack, the xterm dev
dependencies, expo-audio/image-picker/web-browser/document-picker/keep-awake,
react-native-svg, parse-git-diff, sugar-high), three Expo config plugins, the
committed terminal page and its builder, and `terminal:build`.

## How this was verified

The 26 Maestro flows became five that drive the shell — launch and pair, deep
links, send a message, an unreachable server, and connect enrolment. Four run
in CI; all four pass on an iPhone 17 Pro simulator against the e2e harness,
against a Release-shaped build made after the dependency prune.

286 unit tests, 0 lint errors, typecheck clean.

Two things the flows caught, both now recorded in the flows themselves:

- An `http://127.0.0.1` link cannot be a universal link, so iOS hands it to
  Safari. Only `*.getbb.app` is an associated domain, so the web-link branch of
  the resolver is covered by unit tests rather than a flow.
- The icon map deliberately mirrors the web vocabulary, so "every allowlisted
  brand mark is rendered somewhere" stopped being a valid invariant once the
  screens that rendered Discord and GitHub went away.

## What this does not do

`src/lib/query`, `src/lib/realtime`, and the connection layer survive at about
5,800 lines. They are reachable only through the session-cookie path the
WebView genuinely needs, so removing them is a refactor of the connector, not a
delete — and it would cost the native chrome its server palette. Left for a
follow-up.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@SawyerHood
SawyerHood merged commit 15e87df into main Aug 27, 2026
15 checks passed
@SawyerHood
SawyerHood deleted the bb/phase-0-spikes-pwa-webview-shell-ios-thr_ehcf4b9d2m branch August 27, 2026 01:21
ymichael added a commit that referenced this pull request Aug 31, 2026
The native mobile UI was replaced upstream by a WebView shell around the
PWA (#2515), deleting apps/mobile/src/screens. The dedicated mobile hold
commit had no surviving consumers and was dropped in the rebase, so the
"As shipped" mobile bullet now records that mobile is served by the
responsive app UI instead of separate native views.

Co-Authored-By: Claude Fable 5 <[email protected]>
ymichael added a commit that referenced this pull request Aug 31, 2026
The native mobile UI was replaced upstream by a WebView shell around the
PWA (#2515), deleting apps/mobile/src/screens. The dedicated mobile hold
commit had no surviving consumers and was dropped in the rebase, so the
"As shipped" mobile bullet now records that mobile is served by the
responsive app UI instead of separate native views.

Co-Authored-By: Claude Fable 5 <[email protected]>
ymichael added a commit that referenced this pull request Sep 1, 2026
The native mobile UI was replaced upstream by a WebView shell around the
PWA (#2515), deleting apps/mobile/src/screens. The dedicated mobile hold
commit had no surviving consumers and was dropped in the rebase, so the
"As shipped" mobile bullet now records that mobile is served by the
responsive app UI instead of separate native views.

Co-Authored-By: Claude Fable 5 <[email protected]>
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