Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ The daemon routes `POST /tool/:name` requests through the registry, applies Zod
| `run_steps` | Executes a batch of tool invocations sequentially. Supports `stopOnError` to halt on first failure, a top-level `observe` level for the single observation collected after the batch (default `diff`; without one, the last executed step's `observe` is used), and `batchTimeoutMs` (1 000–30 000 ms) to set an overall deadline (checked between steps; remaining steps are skipped, partial results are returned). The daemon queue and the CLI wait for the deadline plus the slowest step's own timeout, so a step in progress is never cut off by `MM_QUEUE_TIMEOUT`; without `batchTimeoutMs` the call keeps the daemon queue default (30 s, or 180 s when the host sets it). Accepts tool aliases like `navigate_home` / `navigate-home`. Returns per-step results with timing. |
| **Advanced** | |
| `mock_network` | Adds, clears, lists, and inspects targeted Playwright network mocks on the active browser context. Unmatched same-origin requests are continued unchanged. A rule with `record` and no `response` records the real request and forwards it unchanged. Rules can opt in to record request bodies and headers (redacted). |
| `events` | Bookmarks or clears the session event buffer that `mm logs` and `mm network` read: `mark` returns the current cursor (one cursor for both) and `summary.startedAt`; `clear` empties it without resetting the cursor. The buffer starts with a browser session and keeps the newest 1000 console and 2000 network records. Browser only. |
| `cdp` | Sends a raw Chrome DevTools Protocol command, dispatched through the active platform driver. **Browser:** targets the active page (`target: "page"`, default) or the Extension service worker (`target: "sw"`) on a persistent CDP session shared across calls, so enabled domains and listeners survive; `fresh: true` uses a one-shot session. Full Runtime/DOM/Network/Page surface; destructive methods (`Browser.close`, `Target.closeTarget`, etc.) are blocked. **Mobile (iOS/Android):** targets the app's React Native Hermes JS runtime via Metro's inspector proxy (delegates to `@metamask/device-mcp`, needs a DEBUG build with Metro running); only the JS-engine subset exists (`Runtime`, `Debugger`, `Log`, `HeapProfiler` — no DOM/Page/Network) and `Runtime.terminateExecution` / `Inspector.detached` are blocked. Optional `metroPort` / `appId` are mobile-only (ignored on browser). Categorized as `cdp`: no observation is collected and refs are not refreshed, so run `describe_screen` after a call that changes state. See [Browser vs Mobile CDP](#browser-vs-mobile-hermes-cdp). |
| **Hermes (mobile only)** | |
| `hermes_targets` | Lists and diagnoses the debuggable Hermes targets Metro exposes (iOS and Android), reporting which target would be chosen or why selection is ambiguous. Use to confirm Metro is running and the app is registered. Pass `all` to bypass the appId filter and discover the real appId. Mobile only — there is no browser equivalent. |
Expand Down Expand Up @@ -685,6 +686,8 @@ mm describe-screen
| `mm mock-network clear` | Clears route mocks and recorded requests. |
| `mm mock-network list` | Lists active route mocks. |
| `mm mock-network requests [--limit <n>] [--url <glob-or-text>] [--bodies]` | Shows recorded matched and missed requests. `--url` keeps only matching URLs. `--bodies` adds the recorded (redacted) request bodies and headers. |
| `mm events mark` | Returns the current cursor of the session event buffer and `summary.startedAt`. Take it at the start of a flow and pass it to `mm logs` / `mm network` at the end. Browser only. |
| `mm events clear [--kind console\|network]` | Empties the session event buffer (one kind or all). The cursor keeps counting, so older cursors stay valid. |
| `mm cdp <method> [params-json] [--timeout <ms>] [--target page\|sw\|hermes\|android-webview] [--fresh] [--metro-port <p>] [--app-id <id>]` | Sends a raw Chrome DevTools Protocol command against the active session. Escape hatch for when structured tools are insufficient. Works on both browser and mobile — the target runtime and blocked methods differ by platform (see below). Browser targets are the active page (`page`, default) and the Extension service worker (`sw`); `--fresh` uses a one-shot session. On mobile the session keeps the `--metro-port` given to `mm launch`, so later calls use it; a per-call `--metro-port` is only an override. |

```bash
Expand Down
16 changes: 15 additions & 1 deletion SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The default depends on the tool's category:
| Category | Examples | Default `observe` |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| **Mutating** | click, type, navigate, reload, launch, cleanup, build, clipboard, mock_network, scroll_to_element, device_swipe, long_press, tap_coordinates, dismiss_keyboard, dismiss_alert, open_app, close_app, press_button, device_context, device_clipboard | `diff` |
| **Read-only** | get_state, get_text, inspect, get_context, set_context, get_alert_text, screen_recording, device_logs, generate_locators, hermes_targets | `none` |
| **Read-only** | get_state, get_text, inspect, get_context, set_context, events, get_alert_text, screen_recording, device_logs, generate_locators, hermes_targets | `none` |
| **Discovery** | describe_screen, list_testids, accessibility_snapshot, screenshot (data is already in `result`) | `none` |
| **CDP** | cdp | `none` |
| **Batch** | run_steps | `diff` |
Expand Down Expand Up @@ -747,6 +747,20 @@ mm hermes-targets
mm hermes-targets --all
```

### Session events (browser only)

From `mm launch` on, the daemon records events from every page and the Extension's background service worker into one buffer per session. `mm logs` and `mm network` read it. All kinds share one cursor (`seq`), so one `mark` covers both. Traffic during `mm launch` itself (for example self-onboarding) is not recorded. Mobile sessions return `MM_TOOL_NOT_SUPPORTED_ON_PLATFORM`.

#### `mm events mark`

Returns `{ cursor, summary }`. Take it at the start of a flow.

#### `mm events clear [--kind console|network]`

Empties the buffer (one kind or all). The cursor keeps counting, so older cursors stay valid.

`summary` is `{ startedAt, seq, counts: { console, network }, dropped: { console, network }, captureErrors, lastCaptureError? }`. `startedAt` (epoch ms) changes when the session is relaunched; `seq` then starts at 1 again. The buffer keeps the newest 1000 console and 2000 network records; older ones are dropped and counted. `captureErrors` counts the times the session could not listen to a page or the service worker (for example a target that did not answer within 5 s, or a domain that could not be enabled); `lastCaptureError` is the newest one, redacted. When it grows during a flow, events of that target can be missing. A call that starts the recording waits at most 5 s for a target that does not answer.

### Mobile device actions (iOS/Android only)

These commands require a mobile session (`mm launch --platform ios|android`). On a browser
Expand Down
51 changes: 51 additions & 0 deletions src/cli/mm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ describe('printHelp', () => {
expect(output).toContain('--observe <level>');
expect(output).toContain('--pretty');
expect(output).toContain('MM_PRETTY');
expect(output).toContain('mm events mark');
});
});

Expand Down Expand Up @@ -3119,6 +3120,56 @@ describe('routeCommand', () => {
expectFailure(expect.stringContaining('Usage: mm mock-network add'), 2);
});

it('routes events mark', async () => {
await routeCommand('events', ['mark'], 3000);
expect(globalThis.fetch).toHaveBeenCalledWith(
'http://127.0.0.1:3000/tool/events',
expect.objectContaining({ body: JSON.stringify({ action: 'mark' }) }),
);
});

it('routes events clear with and without --kind', async () => {
await routeCommand('events', ['clear'], 3000);
expect(globalThis.fetch).toHaveBeenLastCalledWith(
'http://127.0.0.1:3000/tool/events',
expect.objectContaining({ body: JSON.stringify({ action: 'clear' }) }),
);
await routeCommand('events', ['clear', '--kind', 'network'], 3000);
expect(globalThis.fetch).toHaveBeenLastCalledWith(
'http://127.0.0.1:3000/tool/events',
expect.objectContaining({
body: JSON.stringify({ action: 'clear', kind: 'network' }),
}),
);
});

it('exits when events clear --kind has no value', async () => {
await expect(
routeCommand('events', ['clear', '--kind'], 3000),
).rejects.toThrowError('process.exit');
expectFailure(expect.stringContaining('Usage: mm events'), 2);
});

it.each<[string, string[]]>([
['mark with a flag', ['mark', '--kind', 'console']],
['mark with a stray value', ['mark', 'extra']],
['clear with a stray value', ['clear', 'extra']],
['clear with an unknown flag', ['clear', '--error']],
['clear with a flag after --kind', ['clear', '--kind', 'console', '--x']],
])('exits when events %s', async (_name, args) => {
await expect(routeCommand('events', args, 3000)).rejects.toThrowError(
'process.exit',
);
expectFailure(expect.stringContaining('Usage: mm events'), 2);
});

it('exits when events has an unknown action', async () => {
await expect(routeCommand('events', [], 3000)).rejects.toThrowError(
'process.exit',
);
expectFailure(expect.stringContaining('Usage: mm events'), 2);
});

it('exits when mock-network has an unknown action', async () => {
await expect(
routeCommand('mock-network', ['unknown'], 3000),
Expand Down
Loading
Loading