Skip to content

[eas-cli] Detect argent MCP config and improve argent session instructions#3766

Draft
szdziedzic wants to merge 1 commit into
mainfrom
05-20-_eas-cli_detect_argent_mcp_config_and_improve_argent_session_instructions
Draft

[eas-cli] Detect argent MCP config and improve argent session instructions#3766
szdziedzic wants to merge 1 commit into
mainfrom
05-20-_eas-cli_detect_argent_mcp_config_and_improve_argent_session_instructions

Conversation

@szdziedzic
Copy link
Copy Markdown
Contributor

@szdziedzic szdziedzic commented May 20, 2026

Why

After eas simulator:start --type argent returns a tunnel URL, the CLI used to print one line:

🔑 Open the following URL to access the Argent tools for this session:

https://<tunnel>.trycloudflare.com

— and leave the user to figure out that the URL goes into ARGENT_TOOLS_URL in their editor's MCP config, which of nine possible config files / formats theirs lives in, and that the editor has to be restarted to pick it up.

This PR replaces that flow with detection + interactive auto-edit. The CLI now scans the same set of MCP config locations argent init itself writes to, prompts the user with a multi-select of detected configs (pre-checked, opt-out per row, with a per-row diff), applies the ARGENT_TOOLS_URL edit to whichever stayed checked, and reverts every edit when the session ends. Non-interactive runs (--non-interactive) still print instructions and touch nothing.

How

All changes in packages/eas-cli/src/simulator/. Two new deps: jsonc-parser@3.3.1, smol-toml@1.6.1.

Editor coverage

Mirrors argent's installer adapter set in packages/argent-installer/src/mcp-configs.ts. All nine adapters, project + global where applicable:

Editor Format Project Global Key path Env key
Cursor JSON .cursor/mcp.json ~/.cursor/mcp.json mcpServers.argent env
Claude Code JSON .mcp.json ~/.claude.json mcpServers.argent env
VS Code JSON .vscode/mcp.json servers.argent env
Windsurf JSON ~/.codeium/windsurf/mcp_config.json mcpServers.argent env
Zed JSONC .zed/settings.json ~/.config/zed/settings.json context_servers.argent env
Gemini JSON .gemini/settings.json ~/.gemini/settings.json mcpServers.argent env
Codex TOML .codex/config.toml ~/.codex/config.toml mcp_servers.argent env
Hermes YAML ~/.hermes/config.yaml mcp_servers.argent env
opencode JSONC opencode.{jsonc,json} ~/.config/opencode/{opencode.jsonc,opencode.json,config.json} mcp.argent environment

opencode's odd environment key (not env) is modeled by an envKeyName field on each candidate. Multiple opencode filename candidates per scope are deduped by (editor, scope).

Per-format read/write

Four FormatDrivers each implementing hasKeyPath / readString / writeString / removeKey. Capture / apply / revert dispatch by format.

Driver Library Round-trip behavior
JSON built-in Preserves indent (auto-detected: 2 / 4 / tab) and trailing newline. JSON has no comments.
JSONC jsonc-parser (modify + applyEdits) Surgical text edits — preserves comments, trailing commas, surrounding whitespace untouched.
YAML yaml package (Document API) Preserves comments, anchors, formatting.
TOML smol-toml (parse + stringify) Lossy — comments dropped, keys may reorder. Matches argent's installer behavior.

Interactive flow

When remoteConfig.__typename === 'ArgentRunSessionRemoteConfig' and we're interactive:

  1. captureWritableArgentEdits() reads every candidate config that actually parses + contains an argent entry, capturing the current ARGENT_TOOLS_URL value (or null) on each.
  2. Print a preview per row: + ARGENT_TOOLS_URL = "<new>" for adds, both - <old> and + <new> for overwrites.
  3. prompts multi-select with instructions: false, every row pre-selected: true. User can opt rows out.
  4. applyArgentEdits(selected, toolsUrl) writes through the right driver per file. Mid-batch failures roll back the edits already applied in that batch and rethrow.
  5. After the session ends (clean exit or first Ctrl-C), the finally block in runAsync calls revertArgentEdits with an onError callback that logs Log.warn and continues so one bad file doesn't block reverting the others.

The applied-edits summary tells the user to restart the editor and mentions npx -y @swmansion/argent init as a manual escape hatch for cases the auto-revert can't recover (process hard-killed, kill -9, etc.).

Non-interactive flow

Unchanged: formatRemoteSessionInstructions is the single entry point. It now lists all nine editors (with both project + global paths) in the fallback "didn't detect a config" branch, and surfaces detected configs by editor + scope when it finds them. No file mutation in non-interactive mode.

Files

  • packages/eas-cli/src/simulator/utils.ts — candidate list, format drivers, capture/apply/revert, instruction formatting.
  • packages/eas-cli/src/commands/simulator/start.tspromptAndApplyArgentEditsAsync, printArgentEditSummary, try/finally around the post-poll flow, revert hook.
  • packages/eas-cli/src/simulator/__tests__/utils-test.ts — 22 cases.

Test Plan

  • yarn typecheck clean
  • yarn lint on touched files — no new warnings
  • yarn fmt:check clean
  • yarn test on the new suite — 22/22 pass
  • yarn test on the full eas-cli suite — 1616/1620 (4 pre-existing skips)
  • Manual: from a project with an existing .mcp.json containing argent, eas simulator:start --platform ios --type argent → prompt offers the file pre-checked → confirm → file is edited with the new ARGENT_TOOLS_URL → cancel session → file restored to original state.
  • Manual: opt-out flow (uncheck all in prompt) → falls back to printed instructions, no file touched.
  • Manual: same in non-interactive mode (--non-interactive) → only prints instructions.
  • Manual: detection across formats — verify Zed JSONC, Codex TOML, Hermes YAML, opencode (uses environment) all detected and editable.

The 22 unit tests already cover all four format drivers (including JSONC comment preservation and YAML comment preservation), partial-failure rollback, revert when previous value was null vs string, and the opencode environment quirk.

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@szdziedzic szdziedzic force-pushed the 05-20-_eas-cli_detect_argent_mcp_config_and_improve_argent_session_instructions branch from 45d1244 to 98e5c77 Compare May 20, 2026 18:26
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 58.17490% with 110 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.83%. Comparing base (fa6c877) to head (d41b0b3).

Files with missing lines Patch % Lines
packages/eas-cli/src/commands/simulator/start.ts 1.67% 55 Missing and 4 partials ⚠️
packages/eas-cli/src/simulator/utils.ts 74.88% 49 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3766      +/-   ##
==========================================
+ Coverage   56.80%   56.83%   +0.03%     
==========================================
  Files         904      904              
  Lines       39112    39363     +251     
  Branches     8173     8213      +40     
==========================================
+ Hits        22214    22367     +153     
- Misses      15428    15522      +94     
- Partials     1470     1474       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@szdziedzic szdziedzic force-pushed the 05-20-_eas-cli_detect_argent_mcp_config_and_improve_argent_session_instructions branch 7 times, most recently from d502f6c to 6df6386 Compare May 21, 2026 11:31
@szdziedzic szdziedzic added the no changelog PR that doesn't require a changelog entry label May 21, 2026
@szdziedzic szdziedzic force-pushed the 05-20-_eas-cli_detect_argent_mcp_config_and_improve_argent_session_instructions branch from 6df6386 to d41b0b3 Compare May 21, 2026 11:44
@github-actions
Copy link
Copy Markdown

⏩ The changelog entry check has been skipped since the "no changelog" label is present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog PR that doesn't require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant