Skip to content

feat: add a session event buffer with one cursor and mm events mark - #109

Open
cryptotavares wants to merge 1 commit into
cryptotavares/mmcli-p2-28-cdp-target-eventsfrom
cryptotavares/mmcli-p2-15-events
Open

cryptotavares wants to merge 1 commit into
cryptotavares/mmcli-p2-28-cdp-target-eventsfrom
cryptotavares/mmcli-p2-15-events

Conversation

@cryptotavares

@cryptotavares cryptotavares commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Important

Stacked on #107 (P2-28, ready to review on main; review it first). This PR targets #107's branch and contains one commit. #110 (P2-16) and #111 (P2-17) stack on it.

mm logs (P2-16) and mm network (P2-17) are streams. An agent needs "everything since the start of this flow" in one cheap, paged, redacted read. It must also know when records were lost (buffer overflow, relaunch). Today there is no session-level event store: CdpManager.subscribe (#107) delivers events, but nothing keeps them.

This PR adds that store and its bookmark command. The buffer has no sources yet: P2-16 and P2-17 fill it.

  • One buffer per browser session (src/events/event-buffer.ts), with one monotonic seq shared by all record kinds (starts at 1 per session). Two kinds, each with its own capacity and drop count: console (1000) and network (2000). A full kind drops its oldest record.
  • Read API read({ kind, cursor?, since?, limit, filter? }) → { records, cursor, hasMore, gap, summary }, oldest first. The returned cursor continues the read with no duplicates or holes. gap: true when a record after the cursor (or at/after since) was dropped. A cursor above the newest seq (from an earlier session) is stale: the read starts from the oldest record and reports gap: true, so a client that compares cursors notices. With both cursor and since, gap is approximate (a record dropped after the cursor but before since is not distinguished). limit is clamped to at least 1. A record updated in place later (a network request that finishes) keeps its seq, so it is never returned twice.
  • summary { startedAt, seq, counts, dropped }. startedAt (epoch ms) is new for each session, so a reader can detect a relaunch.
  • mm events mark → { cursor, summary }. mm events clear [--kind console|network] empties the buffer without resetting seq (old cursors stay valid). Unknown arguments (mark --kind x, clear extra, a missing --kind value) are usage errors (exit 2).
  • Redaction helpers (src/events/redact.ts, from feat: add mm network-log, a passive request and console log with service-worker traffic #106's redactUrl): credentials (user:pass@ → [REDACTED]@); host labels and path segments of 24+ letters/digits (32-hex Infura keys); sensitive query and fragment values (feat: record request bodies in mock-network #93's body-field list + key, token, sig, jwt, session, projectId, signature, credential, code, …), matched by exact name and by suffix/prefix after normalization (infuraProjectId, api_token, access_key, x-api-key, authToken, X-Amz-Credential); ^auth does not match author/authors/authority and ^sig only matches sig/sign/signature, and a JWT or bare key used as a value is redacted even under a harmless name. A JWT path segment is always redacted, and an opaque segment after v1–v4 (≥ 28 chars) is treated as an API key, so a digitless Alchemy key is caught. 0x addresses, 64-hex/base58 IDs after account(s)/address(es)/tx/transaction(s), and UUIDs under a real path are kept; a UUID that is the only path segment is redacted (Blast-style gateway). The same rules apply to URLs inside text; trailing .,;:!?, } and * stay outside the redacted URL, a URL in [...] is matched without its bracket, and a URL with nothing to redact is left byte-for-byte as it appeared. A scheme://user:pass@ URL of a scheme the pattern does not know (ftp:, postgres:, redis:, mongodb+srv:) is redacted by parsing the match, so a path with : and @ is not mistaken for a credential. Text (not only URLs) also loses JWTs (eyJ…) and Bearer values (the value needs 8+ token characters, so prose such as the bearer of good news stays). passwd, pwd, pass, bearer, seed, pk and mnemonic… names are redacted; publicKey, pubKey, sortKey, cacheKey, primaryKey and sourceToken…nativeToken are allowlisted (not secrets). Trailing punctuation is stripped in a backward loop, so a long run is linear (0.3 ms on 100 000 dots; the old regex took 4803.9 ms).
  • Auto-start: launch starts the session's event sources on browser sessions. It waits at most 5 s and never fails the launch. The first events/logs/network call starts them again if the CDP manager was replaced.
  • events is a read-only, browser-only tool (zod schema, registry, CLI help, README, SKILL.md). Mobile returns MM_TOOL_NOT_SUPPORTED_ON_PLATFORM.

Part of the mm CLI v2 effort: ticket P2-15 (Phase 2). Next: P2-16 mm logs (stacked on this PR), P2-17 mm network.

Shared #93 helper: redact.ts uses mock-network's isSensitiveBodyField (now exported) and REDACTED_VALUE, so the body field list has one source. It adds only the query parameter names (key, token, sig, …) and the URL segment rule.

Breaking changes

None.

Consumer impact

Consumer Change needed Done on branch
Extension test/e2e/playwright/llm-workflow/ none n/a
Mobile tests/llm-workflow/ none (browser only) n/a

Proof

Ticket platform: unit. The live run also uses the real daemon + built CLI on an MV3 test extension. The buffer is empty in this PR (no sources).

Check Result
Overflow drops the oldest of that kind, counted; cursor before the oldest kept → gap: true ✅ unit
Cursor / since paging with limit: hasMore, no duplicates or holes; an in-place update is not returned again ✅ unit
startedAt changes on a new session; clear keeps seq ✅ unit + live (startedAt 1795010983961 → 1795010991417 across cleanup + launch)
Redaction table: Infura key in host and path, apiKey=, credentials (HTTP and non-HTTP schemes), fragment pairs, JWT path and JWT/Bearer in text, suffix/prefix names, digitless key, UUID only as the sole path segment, 0x address / 64-hex / base58 kept, URL inside text kept when clean and byte-identical ✅ 51 cases, plus a checked 76-URL / 32-text / 10-byte-identity table in the P2-15 proof; trailing punctuation 4803.9 ms → 0.3 ms on 100 000 dots
Stale cursor (cursor > seq) reads from the oldest record and reports gap: true ✅ unit
Bad flag (mm events clear --kind) ✅ MM_INVALID_INPUT, exit 2
Transcript
$ mm events mark
{"action":"mark","cursor":0,"summary":{"startedAt":1795010983961,"seq":0,"counts":{"console":0,"network":0},"dropped":{"console":0,"network":0}},...}
$ mm cleanup && mm launch && mm events mark
{"action":"mark","cursor":0,"summary":{"startedAt":1795010991417,"seq":0,...}}
$ mm events clear --kind
{"ok":false,"error":{"code":"MM_INVALID_INPUT","message":"Usage: mm events <mark | clear [--kind console|network]>","retryable":false}}
Unit tests
 Test Files  68 passed (68)
      Tests  2559 passed (2559)
Type Errors  no errors
All files          |   98.26 |    95.98 |   97.78 |   98.38 |
  event-buffer.ts  |     100 |      100 |     100 |     100 |
  redact.ts        |   98.78 |      100 |     100 |   98.76 |
yarn lint: exit 0
yarn build: exit 0

@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-15-events branch from 5c2279c to 72c8e8b Compare November 18, 2026 15:45
@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-28-cdp-target-events branch from 8fab0d4 to 233b290 Compare November 18, 2026 15:45
@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-28-cdp-target-events branch from 233b290 to c0dfe35 Compare November 18, 2026 16:59
@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-15-events branch from 72c8e8b to 54fe280 Compare November 18, 2026 17:05
@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-28-cdp-target-events branch from c0dfe35 to 7d46869 Compare November 18, 2026 17:56
@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-15-events branch from 54fe280 to 65ef5ed Compare November 18, 2026 17:59
@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-28-cdp-target-events branch from 7d46869 to 73122e8 Compare November 18, 2026 18:39
@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-15-events branch from 65ef5ed to 00ddbcc Compare November 18, 2026 18:43
Adds one buffer per browser session for console and network records
(filled by mm logs and mm network sources in follow-ups). Records share
one monotonic seq, so a single 'mm events mark' bookmarks both kinds.
Reads are paged with cursor/since/limit and report hasMore, gap
(records after the cursor were dropped) and a summary whose startedAt
changes on relaunch. Adds URL/text redaction helpers applied before a
record enters the buffer. The buffer starts with the session at launch;
'mm events' is browser only and read-only.
@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-15-events branch from 00ddbcc to d75e3ac Compare November 18, 2026 18:45
@cryptotavares
cryptotavares marked this pull request as ready for review November 18, 2026 18:58
@cryptotavares
cryptotavares requested a review from a team as a code owner November 18, 2026 18:58

This branch has not been deployed

No deployments
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