Skip to content

feat: pass arguments and environment variables to apps launch - #531

Open
mobile-kevin wants to merge 2 commits into
mainfrom
feat/launch-args-env
Open

mobile-kevin wants to merge 2 commits into
mainfrom
feat/launch-args-env

Conversation

@mobile-kevin

@mobile-kevin mobile-kevin commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Adds launch arguments and environment variables to apps launch, for the "App launch options" roadmap item (mobile-next/mobile-mcp#370).

# iOS
mobilecli apps launch com.example.app --device <id> --arg -FeatureX --arg YES --env API_URL=https://staging.example.com
# Android
mobilecli apps launch com.example.app --device <id> --arg featureX=true --arg apiUrl=https://staging.example.com
  • --arg can be repeated. --env KEY=VALUE can also be repeated. Values may contain = or be empty.
  • On a real iOS device, both are passed through instruments ProcessControl (LaunchAppWithArgs).
  • On the iOS Simulator, arguments go after the bundle id in simctl launch, and env vars are passed as SIMCTL_CHILD_<KEY>.
  • On Android, each --arg must be key=value and becomes a string intent extra, am start --es key value. The app reads it from its launch intent (getIntent().getStringExtra("key")). An argument without = is an error. --env is an error because Android apps have no environment.
  • The device.apps.launch JSON-RPC method accepts args (string[]) and env (object). RemoteDevice forwards both.

Testing

  • Unit tests for simctlLaunchArgs, simctlLaunchEnv, launchExtras, launchArgs with extras, parseLaunchEnv, and the Android rejections.
  • iOS 26 simulator: ps eww on the launched Settings process shows -AppleLanguages (he) as arguments and FOO=bar in its environment.
  • Physical Android device: launching Settings with --arg "mcpFlag=hello world; echo pwned" succeeds, and dumpsys activity shows the intent (has extras). The value stays one shell-quoted word. --arg -FeatureX is rejected.
  • Not yet tested on a real iOS device.

Summary by CodeRabbit

  • New Features
    • App launch commands now accept repeated arguments and environment variables.
    • On iOS, arguments are passed to the app process and environment variables are available at launch. On Android, arguments can be supplied as key=value intent extras.
    • Simulator launches now pass configured environment variables to the app.
  • Limitations
    • Android launches return an error if environment variables are provided or arguments are not in key=value format.
    • Environment entries must include a nonempty key and an = sign.

apps launch takes repeatable --arg and --env KEY=VALUE flags. On a real
iOS device they go through ProcessControl, on a simulator as simctl launch
arguments and SIMCTL_CHILD_ variables. Android has no app arguments or
environment, so both are rejected there. The device.apps.launch JSON-RPC
method accepts the same as args and env.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: mobile-next/mobilecli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7775f0e6-fec8-4563-b417-bd37e875f095
📥 Commits

Reviewing files that changed from the base of the PR and between 974879c and 3ae1c94.

⛔ Files ignored due to path filters: 2
  • README.md is excluded by !**/*.md
  • skills/mobilecli/reference.md is excluded by !**/*.md
📒 Files selected for processing: 5
  • cli/apps.go
  • devices/android.go
  • devices/android_launch_test.go
  • devices/common.go
  • devices/simulator_launch_test.go
🚧 Files skipped from review as they are similar to previous changes: 1
  • cli/apps.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

📝 Walkthrough

App launch requests now accept arguments and environment variables. The CLI and server forward these options to device launch implementations. iOS and simulator launches apply them, remote launches include them in RPC parameters, and Android rejects non-empty environment options and invalid arguments.

Changes: App Launch Options

Layer / File(s) Summary
Launch request inputs and forwarding
commands/apps.go, server/server.go, cli/flags.go, cli/apps.go, cli/apps_test.go, devices/common.go
Launch request types and CLI flags carry arguments and environment variables. The CLI parses KEY=VALUE entries, and the command validates environment keys before mapping the options into LaunchOptions. The server forwards the parsed options.
Platform launch handling
devices/ios.go, devices/simulator.go, devices/remote.go, devices/android.go, devices/android_launch_test.go, devices/simulator_launch_test.go
iOS forwards configured arguments and environment entries. The simulator appends arguments and passes sorted SIMCTL_CHILD_ environment entries. Remote launch requests include non-empty options. Android converts valid key=value arguments to string intent extras and rejects environment options. Tests cover parsing, formatting, ordering, and platform rejection.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant AppsLaunchParams
  participant handleAppsLaunch
  participant LaunchAppCommand
  participant Device
  CLI->>AppsLaunchParams: Send args and env
  AppsLaunchParams->>handleAppsLaunch: Provide parsed args and env
  handleAppsLaunch->>LaunchAppCommand: Forward AppRequest
  LaunchAppCommand->>Device: Pass Arguments and Env in LaunchOptions
Loading

Suggested reviewers: gmegidish

Merge Risk: ⚪ Minimal · up to 3ae1c

No actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely summarizes the main change: adding argument and environment-variable support to app launches.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

Each --arg on Android must be key=value and becomes am start --es key
value, which the app reads from its launch intent. An argument without
'=' is an error. --env stays iOS-only.
@mobile-kevin mobile-kevin changed the title feat: pass arguments and environment variables to apps launch on iOS feat: pass arguments and environment variables to apps launch Oct 18, 2026
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