Skip to content

fix: print help for mm <command> --help instead of running the command - #137

Merged
cryptotavares merged 1 commit into
mainfrom
cryptotavares/help-flag-no-run
Dec 2, 2026
Merged

cryptotavares merged 1 commit into
mainfrom
cryptotavares/help-flag-no-run

Conversation

@cryptotavares

Copy link
Copy Markdown
Collaborator

Part of the mm CLI v2 effort.

Summary: mm <command> --help now prints the usage and exits 0. Before, mm ignored the flag and ran the command: mm launch --help started a real session.

Problem

main() treats --help / -h as help only when it is the first argument. In mm launch --help, the first argument is launch, so the command runs. An agent ran mm launch --help to read the flags, and the app launched. The check from #126 ("reject bad CLI input before starting the daemon") does not catch this: parseLaunchArgs only warns about an unknown flag.

Before this PR, against a live daemon (mocked in a unit test, so nothing real ran):

$ mm launch --help
Warning: unknown launch flag '--help'          (stderr)
POST /launch {}                                → a session starts
$ mm stop --help
POST /cleanup {}, SIGTERM to the daemon pid    → "Daemon stopped (was PID … on port …)."
$ mm click --help
POST /tool/click {"testId":"--help"}           → exit 4

Solution

After the unknown-command check, and before any worktree lookup or daemon work, main() asks isHelpRequest(command, args). If it is true, main() calls printHelp() and exits 0.

flowchart TD
    A["mm [global flags] cmd args"] --> B{"cmd missing,<br/>or --help / -h?"}
    B -->|yes| H[printHelp, exit 0]
    B -->|no| C{known command?}
    C -->|no| U["unknown command, exit 2"]
    C -->|yes| D{"isHelpRequest:<br/>lifecycle: --help / -h anywhere<br/>other: --help / -h as the first argument"}
    D -->|yes| H2["printHelp, exit 0.<br/>No worktree lookup, no daemon, no request."]
    D -->|no| E[resolveWorktreeRoot]
    E --> F[lifecycle handling or discoverDaemon, then the request]

    classDef new fill:#fff3cd,stroke:#d39e00
    classDef stop fill:#f8d7da,stroke:#c82333
    class D new
    class H2,U stop
Loading

Yellow boxes are new. Red boxes stop the run.

What changes

Command Before After
mm launch --help Warns, starts the daemon if needed, POST /launch {} Help, exit 0
mm launch --platform ios --help Warns, POST /launch {"platform":"ios"} Help, exit 0
mm serve --help Spawns the daemon in the foreground Help, exit 0
mm stop --help POST /cleanup, then stops the daemon Help, exit 0
mm cleanup --help POST /cleanup: ends the session Help, exit 0
mm click --help Clicks test ID --help, exit 4 Help, exit 0
mm type e5 --help Types the text --help No change
mm --help, mm -h, mm Help, exit 0 No change
mm frobnicate --help unknown command 'frobnicate'. …, exit 2 No change

Decisions for reviewers

Decision Reason
Help flag anywhere for launch, serve, stop, cleanup; only as the first argument for other commands The lifecycle commands take no free text. parseLaunchArgs already rejects a flag value that starts with --. So mm launch --platform ios --help must not launch. The other commands take user text: getPositionalTarget keeps unknown -- tokens as text on purpose.
Print the full printHelp() text The usage lines live in printHelp() only. A per-command copy would be a second source of truth.
Unknown command wins over --help mm frobnicate --help still fails with exit 2, so a typo is not hidden.
The help check runs before resolveWorktreeRoot mm launch --help works outside a git repository, like mm --help.
An unknown launch flag still only warns Out of scope. Making it exit 2 is a possible follow-up.

Review guide

# File What to check
1 src/cli/mm.ts isHelpFlag, isHelpRequest, and the new check in main() after isKnownCommand
2 src/cli/mm.test.ts The main cases: help for each command, type e5 --help, frobnicate --help
Testing
  • yarn build, yarn lint and CI=1 yarn test pass (76 files, 2947 tests). Coverage floors are unchanged; mm.ts is at 98.48% statements, 96.73% branches.

  • The help tests check exit 0 and the usage on stdout. They also check that realpath, readDaemonState, spawn and fetch are never called.

  • With the mm.ts from main, the 8 new help tests fail. The type and frobnicate tests pass.

  • Mutation check. Each change below makes at least one test fail:

    • lifecycle commands check only the first argument
    • every command checks all arguments (type e5 --help fails)
    • resolveWorktreeRoot runs before the help check
  • Live check with the built CLI, in an empty temporary directory (--project <dir>):

    Command Exit Output
    launch --help, launch --platform ios --help, serve --help, stop --help, cleanup --help, click --help 0 mm — MetaMask CLI usage, empty stderr
    type e5 --help 3 no daemon running (the command runs)
    frobnicate --help 2 unknown command 'frobnicate'. …

    The directory stays empty: no .mm-server, no .mm-server.lock, no daemon process. Before the fix, the same launch --help run left a .mm-server.lock file.

@cryptotavares
cryptotavares marked this pull request as ready for review December 2, 2026 12:57
@cryptotavares
cryptotavares requested a review from a team as a code owner December 2, 2026 12:57
@cryptotavares
cryptotavares merged commit ed87968 into main Dec 2, 2026
27 checks passed
@cryptotavares
cryptotavares deleted the cryptotavares/help-flag-no-run branch December 2, 2026 19:18
LabinatorSolutions pushed a commit to LabinatorSolutions/metamask-extension that referenced this pull request Dec 4, 2026
## **Description**

> **Summary:** Bumps the dev-only `@metamask/client-mcp-core` from
0.16.0 to
[0.16.1](https://github.com/MetaMask/client-mcp-core/releases/tag/v0.16.1).
On the Extension, `mm <command> --help` prints help instead of running
the command, and `mm screenshot --selector --timeout` waits for a late
element. Refs stay stamped after a navigation. No app or test code
changes.

Follows
[MetaMask#48425](MetaMask#48425)
(0.16.0). Sibling skill PR:
[MetaMask/skills#328](MetaMask/skills#328).

### What changes

| File | Change |
|---|---|
| `package.json` | `@metamask/client-mcp-core` `0.16.0` → `0.16.1`
(exact pin, `devDependencies`) |
| `yarn.lock` | `client-mcp-core` 0.16.1; its dependency
`@metamask/device-mcp` `^0.9.0` → `^0.10.0` (resolves to 0.10.0). No
other entries change. |
| `test/e2e/playwright/llm-workflow/README.md` | The `--preset` note
drops the version. The daemon-log example names the target (`testid=…`).
|

### What 0.16.1 changes for the Extension (checked live, see Testing)

| Area | 0.16.0 | 0.16.1 |
|---|---|---|
| `mm launch --help`, `mm stop --help`, `mm click --help` | Runs the
command (launches, stops the daemon, clicks test ID `--help`) | Prints
help, exit 0, runs nothing
([MetaMask#137](MetaMask/client-mcp-core#137)) |
| `mm screenshot --selector X --timeout <ms>`, X appears late |
`MM_TARGET_NOT_FOUND` after 2 s | Waits up to `<ms>` and captures
([MetaMask#139](MetaMask/client-mcp-core#139)) |
| Refs and observation after a navigation | Refs could fall back to
`role=`/`text=`; the observation could show the old route | Refs are
stamped; the observation shows the new route
([MetaMask#131](MetaMask/client-mcp-core#131)) |

### Decisions

| Decision | Why |
|---|---|
| No `allow-scripts` / LavaMoat policy change | Both packages are
dev-only. `yarn allow-scripts list` reports no unconfigured packages. |
| No change to `test/e2e/playwright/llm-workflow` code | `yarn lint:tsc`
and the llm-workflow jest suites pass without code changes. |

### Review guide

1. `package.json` and `yarn.lock`: a version bump only (+10/−10 in the
lockfile).
2. `README.md`: two sentences. Both match the live run below.

## **Changelog**

CHANGELOG entry: null

## **Related issues**

Fixes: N/A. Core release:
https://github.com/MetaMask/client-mcp-core/releases/tag/v0.16.1

## **Manual testing steps**

1. `yarn install`, then `yarn webpack:tsc && yarn build:test`.
2. Run `yarn mm launch --help`. Check that it prints help and that no
`.mm-server` file appears.
3. `MM_HEADLESS=true yarn mm launch --context e2e --state default`, then
unlock.
4. Add an element after a few seconds with `yarn mm cdp
Runtime.evaluate` (`setTimeout`). Run `yarn mm screenshot --selector
'<css>' --timeout 10000`. Check that it captures the element.
5. `yarn mm navigate-settings --observe full`. Check that the
observation lists the settings test IDs.
6. `yarn mm cleanup && yarn mm stop`.

<!--
## **Screenshots/Recordings**

### **Before**

### **After**
-->

<details>
<summary>Testing details</summary>

Node v26.13.1 (`.nvmrc`).

| Check | Result |
|---|---|
| `yarn install --immutable` | exit 0 |
| `yarn dedupe --check` | exit 0 |
| `yarn lint:lockfile` | pass |
| `yarn allow-scripts list` | unconfigured packages: none |
| `yarn lint:tsc` | exit 0 |
| `yarn jest test/e2e/playwright/llm-workflow` | 13 suites, 169 tests
pass |
| oxfmt (README), prettier (`package.json`) | pass |

Live run with the 0.16.1 `mm` against a 13.60.0.0 test build (headless,
`--context e2e --state default`). `.mm-server` reports
`"version":"0.16.1"`. The run followed only the sibling skill
([skills#328](MetaMask/skills#328)).

| Command | Result |
|---|---|
| `mm launch --help`, `mm stop --help`, `mm click --help` (no daemon) |
exit 0, usage, no `.mm-server` |
| `mm stop --help`, `mm cleanup --help` (daemon up) | exit 0; `mm
status` shows the same daemon PID |
| `mm frobnicate` | exit 2, `MM_INVALID_INPUT` |
| `screenshot --selector '#late' --timeout 10000`, element added after 4
s | exit 0, 4.26 s |
| `screenshot --selector '#late'`, same injection | exit 4,
`MM_TARGET_NOT_FOUND`, `matched 0 elements after 2000ms`, 2.18 s |
| `navigate-home` → `navigate-settings --observe full` (×5) | 5 of 5
show the settings test IDs and no home test IDs |
| `navigate-home --observe none`, then `describe-screen` (×5) | 16
nodes, 16 elements with `data-mm-ref` each time |
| `mock-network requests --url esplora` |
`https://bitcoin-mainnet.infura.io/v3/[REDACTED]/esplora/blocks?apiKey=[REDACTED]`
|
| `mm launch --state custom --preset withMultipleAccounts` | `Warning:
unknown launch flag '--preset'`, then `MM_LAUNCH_FAILED` |
| `.mm-daemon.log` | `POST /tool/click 200 ok=false
code=MM_TARGET_NOT_FOUND testid=does-not-exist 2078ms` |

</details>

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Dev-only dependency and documentation updates; no production app logic
or security-sensitive paths changed.
> 
> **Overview**
> Bumps the dev-only **`@metamask/client-mcp-core`** pin from `0.16.0`
to **`0.16.1`** in `package.json` and `yarn.lock`, which also resolves
its dependency **`@metamask/device-mcp`** to `0.10.0`. No extension or
test source changes.
> 
> The **`llm-workflow` README** is updated to match 0.16.1 behavior:
daemon log lines now document the **target** (e.g. `testid=…`), and the
custom-launch note drops a stale version reference for `--preset`.
> 
> Downstream, **`mm --help`** on subcommands prints usage instead of
executing the command, **`mm screenshot --selector --timeout`** honors
the wait window for late elements, and **refs/observation** stay correct
after navigation—behavior that lives in the bumped package, not this
repo.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
fe29d1d. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
cryptotavares added a commit to MetaMask/skills that referenced this pull request Dec 4, 2026
…6.1 and @metamask/device-mcp 0.10.0 (#329)

## Description

> **Summary:** Updates `testing/mobile-visual-testing` for
`@metamask/client-mcp-core`
[0.16.1](https://github.com/MetaMask/client-mcp-core/releases/tag/v0.16.1)
and `@metamask/device-mcp` 0.10.0. Five claims in the skill are now
wrong, the most important being that an ambiguous ref can tap another
element. Each fix was checked against the `v0.16.1` code and a live run.

Companion Mobile PR: MetaMask/metamask-mobile#41237. Previous update:
#298 (Mobile #40496).

### Problem

An agent that follows the current skill expects the wrong outcome in
five places:

- An `ambiguous` or label-only ref "can tap another element" ([core
#127](MetaMask/client-mcp-core#127)). A `click`
now taps the listed node at its bounds. The other target commands refuse
such a ref.
- An unknown command with no daemon "exits 3"
([#126](MetaMask/client-mcp-core#126)). It exits
2 before any daemon starts.
- `--timeout abc` "is dropped without an error" (#126). It exits 2 once
a daemon runs, and 3 without one.
- iOS `mm type <field> ""` "exits 4 with `MM_TYPE_FAILED`"
([#134](MetaMask/client-mcp-core#134),
device-mcp 0.10.0). It exits 0.
- The daemon log line "ends with the outcome"
([#133](MetaMask/client-mcp-core#133)). It now
also names the target.

The `cdp` port order also gains the port that the consumer's launch
resolved ([#128](MetaMask/client-mcp-core#128)).

```mermaid
flowchart TD
    S["describe-screen: node ref"] --> Q{"unique testId,<br/>label or text?"}
    Q -->|yes| ANY["every target command"]
    Q -->|"no: unnamed or ambiguous: true"| T{"command?"}
    T -->|click| B["tap at bounds, target ends in (bounds)"]
    B -->|element moved| NF["MM_TARGET_NOT_FOUND, nothing tapped"]
    T -->|"type, wait-for, get-text,<br/>scroll-to-element, long-press"| R["MM_TARGET_NOT_FOUND, exit 4, hint"]

    classDef new fill:#fff3cd,stroke:#d39e00
    classDef stop fill:#f8d7da,stroke:#c82333
    class B new
    class NF,R stop
```

Yellow boxes are new. Red boxes stop the command.

### What changes

| Area | Before | After |
|---|---|---|
| Refs (`repos/metamask-mobile.md`, `cli-reference.md`,
`error-recovery.md`) | Resolved again at tap time; ambiguous or
label-only refs can tap another element; unnamed refs are `Unknown
a11yRef` | Unnamed and `ambiguous` refs work only with `click` (bounds
tap, `(bounds)` target, `MM_TARGET_NOT_FOUND` when moved); other
commands refuse them with a `hint` |
| "The tap opened another screen" row | Cause: an ambiguous ref | Cause:
a substring `--testid` match or a stale ref |
| Expo dev menu close | `tap-coordinates` only; the button "has no
usable ref" | `mm click <ref>` of the unnamed button, or
`tap-coordinates` |
| Bad input | Unknown command exits 3 without a daemon; non-numeric flag
dropped | Unknown command or bad `launch` value: exit 2, no daemon;
`--timeout abc`: exit 2, or 3 without a daemon |
| iOS `type ""` | Exit 4 `MM_TYPE_FAILED`, field cleared | Exit 0,
`textLength: 0` |
| `cdp` port | Launch `--metro-port` or `MM_METRO_PORT` | Launch
`--metro-port`, else the port the launch resolved from `MM_METRO_PORT`,
then `HERMES_METRO_PORT`, then 8081 |
| Daemon log | Outcome only | Outcome and target (`testid=`, `ref=`,
`method=`, …) |

[#137](MetaMask/client-mcp-core#137) (`mm
<command> --help`) needs no change: the skill never told agents to avoid
`--help`. The browser-only changes (#125, #129, #130, #131, #138, #139)
do not apply.

Review: start with "Which refs work where" in
`repos/metamask-mobile.md`.

## Type of Change

- [ ] New skill
- [x] Skill improvement/update
- [ ] Bug fix
- [ ] Documentation update
- [ ] Other (please describe):

## Checklist

- [x] I have read the
[CONTRIBUTING.md](https://github.com/MetaMask/skills/blob/main/CONTRIBUTING.md)
guidelines
- [x] My skill follows the
[SKILL_TEMPLATE.md](https://github.com/MetaMask/skills/blob/main/.github/SKILL_TEMPLATE.md)
format
- [x] I have tested this skill with an AI agent
- [x] My skill does not contain any secrets, private keys, or sensitive
data
- [x] I have added appropriate documentation
- [x] My changes don't break existing skills

## Testing

<details>
<summary>Sources and live run</summary>

- Code: core tag `v0.16.1` (`src/platform/mobile-platform-driver.ts`
bounds refs and `boundsRefError`, `src/cli/mm.ts` `parseIntFlag` and the
help check, `src/tools/launch.ts` `applyHermesDefaults`,
`src/server/request-log.ts`), core `SKILL.md` at the tag, and the
device-mcp 0.10.0 CHANGELOG.
- Live, read only, real-funds wallet, Metro 8085, npm core 0.16.1 and
device-mcp 0.10.0 with MetaMask/metamask-mobile#41237, following only
this skill. iPhone 17 Pro simulator: launch with `MM_METRO_PORT=8085`
and no `--metro-port`, then `hermes-targets` and `cdp`
(`sessionMetroPort: 8085`, `connected: true`); unlock; hamburger menu,
About, back; Explore search, `type` and `type ""` (exit 0, `textLength:
0`), back. Ambiguous and unnamed refs refused by `get-text`, `wait-for`,
`type`, `scroll-to-element`, `long-press` and `run-steps` (exit 4 with a
`hint`); `click` on an unnamed ref returned `target: "a11yRef:e17
(bounds)"`; error paths (exit 2, 3 and 0 for `--help`); daemon log
targets. Android emulator `Medium_Phone_API_36.1`, login screen: the
same `cdp` port, bounds `click`, refusals, `type ""` and `--timeout
abc`.
- Not run live: a bounds `click` after the element moved (code and core
tests only).
- `yarn lint` pass, `yarn test` 106/106 pass, `yarn audit:skills` 0
errors and 134 warnings (same as `main`).

</details>

<details>
<summary>Known gaps (not in this PR)</summary>

- The iOS wallet home tree is 64 levels deep and its full read fails.
device-mcp falls back to a partial tree, and `wait-for --testid
wallet-screen` times out on the right screen. The skill already points
iOS agents to `account-picker`. Fixes: core #141, device-mcp #67 and
#68.
- `explore-safe-area` is not in the iOS tree (the skill names it as the
Android Explore marker only).

</details>

## Additional Context

Merge this after MetaMask/metamask-mobile#41237.
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