Repository navigation
perf: start the CLI faster; load device-mcp on first mobile use - #73
Draft
cryptotavares wants to merge 3 commits into
Draft
cryptotavares wants to merge 3 commits into
cryptotavares wants to merge 3 commits into
Conversation
- Find the project root by walking up to the nearest `.git` entry instead of running `git rev-parse` (about 90 ms per call). Fall back to git when no `.git` entry is found or GIT_DIR / GIT_WORK_TREE is set. - Do not load zod in the CLI: the `--observe` levels move to a zod-free module that `schemas.ts` also uses (CLI modules 95 -> 15). - `MobilePlatformDriver` loads `@metamask/device-mcp` on first use, so a browser-only daemon never loads it. The CJS build uses `require` to share the consumer's copy; the ESM build uses `import()`. - README: recommend `node_modules/.bin/mm` over `yarn mm` / `npx mm` for agents.
… test" This reverts commit 0b9408b.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack context: mm CLI v2, Phase 1, P1-25 (first Tier 1 ticket after the stack merge). Base:
main.Problem
Measured on
main227674a, daemon running, p50 of 10:node -e 0node_modules/.bin/mm statusyarn mm statusresolveWorktreeRoot(src/cli/mm.ts:270) runsgit rev-parse --show-toplevelon every call: about 90 ms.observeLevelSchemafromvalidation/schemas.tsonly to read three strings. That loads zod: 79 of the CLI's 95 modules, about 25 ms.MobilePlatformDriverimports device-mcp at module load, andsrc/index.tsre-exports it, so every browser daemon loads 54 device-mcp modules at start.yarn mm. On a 400-call release run,yarnalone is about 2.5-3 minutes.Solution
.gitentry (directory or file). Fall back togit rev-parsewhen there is none, or whenGIT_DIR/GIT_WORK_TREEis setfindGitWorktreeRootinsrc/cli/mm.tsschemas.tsbuilds its enum from itsrc/validation/observe-level.tsrequirein the CJS build (shares the consumer's copy),import()in the ESM build. The Hermes session is created on first usesrc/platform/device-mcp-runtime.ts,mobile-platform-driver.tsnode_modules/.bin/mmfor agents, with the measured costREADME.mdOutcome
Before =
main, after = this branch, same host, back to back. No device is touched by the bench.node_modules/.bin/mm statusnode_modules/.bin/mm statusyarn mm statusyarn mm statusmm --helpDecisions
requirein CJS,import()in ESMimport()in the CJS build loads device-mcp's ESM build as a second copy next to the consumer's CJS copy. Module state (for examplegetHermesSession()) would splitimport()everywhere;createRequire(works, but adds a shim for no gain)git rev-parsefallbackGIT_DIR/GIT_WORK_TREEsetups and unusual layouts at no cost to the normal path.gitfile counts as a root.gitfile;git rev-parse --show-toplevelreturns that directory tooReview guide
src/platform/device-mcp-runtime.tsand its test: the test fails onmain("expected true to be false") and passes here.src/platform/mobile-platform-driver.ts: the four call sites that now load device-mcp (#hermesCdp,hermesTargets,generateLocators,#getHermesSession). Types stayimport type.findGitWorktreeRootinsrc/cli/mm.tsand its tests../device-mcp-runtime.js, becausevi.mock('@metamask/device-mcp')does not intercept a CJSrequire.Breaking changes
None.
MobilePlatformDriver's public API is unchanged.Consumer impact
test/e2e/playwright/llm-workflow/tests/llm-workflow/node_modules/.bin/mmcryptotavares/mm-cli-v2-mobile66a504511f0Testing details
Yalc build of this branch (
0.12.0+e92d761d):wallet-screen), describe-screen,cdp Runtime.evaluate 1+1= 2, screenshot. All exit 0.cdpgoes through the lazily loaded device-mcp.require('dist/index.cjs')loads 0 device-mcp modules. The firstgenerateLocators()loads 54, the same copy as the consumer'srequire('@metamask/device-mcp').import('dist/index.mjs')works throughimport().yarn lintpasses.attw --packis green for node10, node16 CJS, node16 ESM and bundler. Coverage thresholds are unchanged.