feat(tool-server): add start-metro tool#370
Open
hubgan wants to merge 2 commits into
Open
Conversation
latekvo
reviewed
Jun 18, 2026
…vent server crash
latekvo
approved these changes
Jun 18, 2026
filip131311
requested changes
Jun 19, 2026
filip131311
left a comment
Collaborator
There was a problem hiding this comment.
expo will not work after this PR
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.
Add
start-metrotool for React Native Metro bundler startupSummary
Adds a
start-metrotool that starts a Metro bundler for a React Native project, or reuses an instance already running on the target port — complementing the existingstop-metro. Until now agents had to instruct users to run Metro manually (npx react-native start), which made fully automated RN app startup impossible. With this tool the start→run→debug loop can run end-to-end without a human in the loop.What it does
start-metroreturns{ port, pid, status }wherestatusis"started"or"reused":/statusendpoint for thepackager-status:runningmarker; if Metro is already up, returnsstatus: "reused"without spawning a second server.reuseExisting: false— forces a fresh instance; errors instead of reusing a running Metro.stop-metro, rather than spawning a Metro that would just fail to bind.npx react-native start --port <port>detached by default; passcommand/args(e.g."npm"+["run", "start:local"]) to run a project's own start script verbatim (no flag injection — the caller owns its flags). Supports cache-reset via custom args.projectRoot— sets the working directory (and--projectRootfor the default command) for monorepos where the tool-server cwd isn't the app root./statusuntil Metro is ready (60s timeout) before returning, folding boot-timeerror/exitlisteners into the readiness race so a later natural exit can't crash the tool-server.Implementation notes
unref'd child outlives the tool-server (same pattern as simulator-server);stop-metroterminates it by port later.findListeningPidsuseslsof -ti tcp:<port> -sTCP:LISTEN. The-sTCP:LISTENfilter is essential — a bare query also matches established client sockets (including the tool-server's own keep-alive to Metro), which would return the wrong PID. For wrapper commands (npx/npm run) the reported PID is the descendant that actually bound the port, not the wrapper.spawn/execFileSyncwith no shell, soportand other inputs can never be shell-interpreted.Files
packages/tool-server/src/tools/simulator/start-metro.ts— the toolpackages/tool-server/src/utils/setup-registry.ts— registrationpackages/tool-server/test/start-metro.test.ts— unit tests covering reuse, fresh start, custom command verbatim, LISTEN-only PID lookup, non-Metro port conflict, andreuseExisting: falseargent.mdrule,argent-react-native-app-workflowSKILL,argent-metro-debuggerfailure-scenarios) to route agents tostart-metroinstead of shelling out tonpx react-native startScope note
The optional
--public-base-urlflag for remote-agent workflows from the original scope is not included in this change. The reuse/fresh-start parameter is implemented as a booleanreuseExisting(defaulttrue) rather than a--no-reuse-existingflag.