Skip to content

fix: keep the launch Metro port for mobile cdp; persistent Hermes connection - #91

Merged
cryptotavares merged 9 commits into
cryptotavares/mmcli-p2-01-browser-cdpfrom
cryptotavares/mmcli-p2-03-hermes-session
Nov 18, 2026
Merged

cryptotavares merged 9 commits into
cryptotavares/mmcli-p2-01-browser-cdpfrom
cryptotavares/mmcli-p2-03-hermes-session

Conversation

@cryptotavares

@cryptotavares cryptotavares commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Description

mm launch --platform ios|android --metro-port 8085 stored the port, but mm cdp and mm hermes-targets resolved it again for each call and fell back to HERMES_METRO_PORT or 8081 (baseline B5). On a machine with a second Metro on 8081 they reached the wrong app; without one they failed. Every Hermes call also opened its own WebSocket.

  • MobilePlatformDriver options gain metroPort, deviceId and appId. New optional IPlatformDriver.setHermesDefaults(): the launch tool applies --metro-port / --device-id to the driver after a successful mobile launch, so B5 is fixed with no consumer change.
  • Precedence for each call: per-call --metro-port / --app-id, then the driver (launch) value, then HERMES_METRO_PORT / HERMES_APP_ID, then 8081 / the platform default. CDP failures name the port they tried.
  • When the loaded device-mcp exports HermesClient (feat: HermesClient, a persistent Hermes CDP connection device-mcp#54), cdp keeps one persistent client per session target. A per-call port or app id that differs uses a one-shot call, so the persistent client is never retargeted. The client is closed on dispose(). With device-mcp 0.7.0 (no HermesClient), core keeps the one-shot runHermesCdp path (feature-detected).
  • hermes-targets also reports sessionMetroPort, pinnedDeviceId, connected and deviceId (additive).

Part of the mm CLI v2 effort: ticket P2-03 (Tier 2).
Stacked on #90 (review that first).
Depends on MetaMask/device-mcp#54: the persistent connection needs a device-mcp release with HermesClient, then a dependency bump here. The B5 fix works with the released 0.7.0.

Breaking changes

None. New options and output fields only.

Consumer impact

Consumer Change needed
Mobile tests/llm-workflow/ Optional: pass { metroPort, deviceId, appId } when constructing MobilePlatformDriver (patch ready). Core already applies the launch values itself.

Proof

Yalc build in Mobile (dev client 8.19.0, iOS sim + Android emulator, Metro 8085, launched with --metro-port 8085), mm cdp Runtime.evaluate 1+1 without --metro-port, 10 runs:

Check Before (#79 stack) After
Android, 10 calls 0/10: hermes-targets says metroPort: 8081, metroDown: true 10/10, sessionMetroPort: 8085, p50 15–40 ms
iOS, 10 calls — 10/10, p50 2 ms
hermes-targets after a call — connected: true, pinnedDeviceId set, deviceId = launch device

The before build reached Metro only with an explicit --metro-port 8085 (90 ms per call on Android). The raw client bench is in MetaMask/device-mcp#54 (Android p50 165 → 5 ms).

Unit tests
Test Files  58 passed (58)
     Tests  2178 passed (2178)    (with #89 and #90 merged)
All files  |  97.94 | 95.5 | 97.59 | 98.04 |

Covers the precedence table, launch applies the port, one client for two calls, one-shot on a per-call override, fallback without HermesClient, close on dispose, the pin persisting, and the new hermes-targets fields. CI=1 thresholds not lowered; tsc -p tsconfig.build.json and yarn lint clean.

`mm launch --platform ios|android --metro-port <n>` stored the port on the
session but `mm cdp` and `mm hermes-targets` resolved their target per call
and fell back to `HERMES_METRO_PORT`/8081 (baseline B5), so they could reach
another worktree's Metro.

- `MobilePlatformDriver` options gain `metroPort`, `deviceId` and `appId`;
  `setHermesDefaults` keeps the launch values for later Hermes calls.
- Precedence: per-call flag, then the driver/launch value, then
  `HERMES_METRO_PORT`/`HERMES_APP_ID`, then 8081/platform default.
- `cdp` reuses one persistent device-mcp `HermesClient` per session target
  and is never retargeted: a call with a different port or app id uses a
  one-shot `runHermesCdp`. Releases without `HermesClient` (0.7.0) always
  take the one-shot path.
- `hermes-targets` reports `sessionMetroPort`, `pinnedDeviceId`, `connected`
  and `deviceId`; a CDP failure names the Metro port it tried.
…es/mmcli-p2-03-hermes-session

# Conflicts:
#	CHANGELOG.md
#	README.md
#	SKILL.md
@cryptotavares
cryptotavares added this pull request to stack #92 November 9, 2026 10:12
…es/mmcli-p2-03-hermes-session

# Conflicts:
#	CHANGELOG.md
…r-cdp' into cryptotavares/mmcli-p2-03-hermes-session
The changelog is generated when a release is created.
…r-cdp' into cryptotavares/mmcli-p2-03-hermes-session
…r-cdp' into cryptotavares/mmcli-p2-03-hermes-session

# Conflicts:
#	README.md

@seaona seaona left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once device-mcp ships HermesClient, state-changing Hermes commands persist the same way as in the previous PR #90. On the emulator, Debugger.enable plus Debugger.pause froze the app's JS until Debugger.resume. The tap didn't act for at least 13 s, and any mm command that needs JS would time out. On mobile the risk is higher than on the browser, for two reasons:

  • --fresh is browser-only and silently ignored on mobile. The only way to get a one-shot call is to pass a different port or app ID.
  • SKILL.md:680 describes the persistent connection only as reuse, with no warning.

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.

2 participants