pi-simmesh
by wundervrc
README.md
# pi-simmesh
Discover and control iOS simulators and Android emulators across machines over Tailscale. pi-simmesh ships as a Pi extension, a standalone MCP server and a small CLI.
## Why
- Keep simulators on the machine that can run them. Drive them from Pi anywhere on your tailnet.
- Pair once with a short-lived 6-digit code. Later calls use a bearer token.
- Tailscale-only by default. LAN and external access stay closed until you opt in.
- Lazy MCP tools keep the model context small. The `simmesh` gateway advertises one tool and discovers the rest on demand.
## Requirements
- Node.js 22 or newer.
- Tailscale on each host for mesh discovery and stable addresses.
- macOS with Xcode command line tools for iOS simulators.
- Android SDK with `adb` and `emulator` on `PATH` or `ANDROID_HOME` set for Android emulators.
## Install
```bash
pi install npm:pi-simmesh
```
Install straight from GitHub to track the latest commit:
```bash
pi install git:github.com/wundervrc/pi-simmesh
```
The package registers the `simmesh` tool, the `/simmesh-*` commands and the `simmesh` skill. The daemon starts with Pi by default.
To use the CLI and standalone MCP server without Pi:
```bash
npm install -g pi-simmesh
pi-simmesh status
```
## Quick start
On the host with simulators:
```text
/simmesh-code
```
This starts the daemon if needed and shows a 6-digit code, the Tailscale address and the expiry.
On the host that runs Pi:
```text
/simmesh-pair
```
Choose a discovered Tailscale peer or enter an address by hand. Enter the code when the peer asks for a PIN. The paired peer and its simulators are saved in `~/.simmesh/config.json`.
Then ask the agent to use the `simmesh` tool or run:
```text
/simmesh-devices
/simmesh-status
```
## Pi commands
| Command | Purpose |
| --- | --- |
| `/simmesh` | Dispatch `status`, `pair`, `code`, `devices`, `settings`, `unpair` or `daemon` |
| `/simmesh-pair` | Probe Tailscale peers, enter an address and pair |
| `/simmesh-code` | Create a 6-digit pairing code for this host |
| `/simmesh-status` | Show daemon, peer, pairing and device counts |
| `/simmesh-devices [peer]` | List simulators and emulators |
| `/simmesh-settings` | Toggle security options, change the port, manage the background service or restart the daemon |
| `/simmesh-service [install\|uninstall\|status]` | Install, uninstall or inspect the always-on background service |
| `/simmesh-unpair [name]` | Remove a paired peer |
| `/simmesh-doctor` (or `/simmesh doctor`) | One-shot health check with short, actionable fixes |
## Pi tool
The extension registers one compact tool named `simmesh`. It supports these actions:
- `peers` lists the local host and paired peers with online state.
- `devices` lists devices across hosts. Pass `peer` to limit the result.
- `tools` returns the command catalog for lazy discovery.
- `run` runs a command on `local` or a named peer. A screenshot comes back as an image block.
- `pair_status` reports pairing and security state.
```json
{ "action": "run", "peer": "sim-host", "command": "screenshot", "device": "<device-id>" }
```
pi-simmesh never calls `pi.registerMcpServer`, so it works alongside `pi-mcp-adapter`.
## Security
Defaults:
- Tailscale-only mode is on. LAN and external clients receive HTTP 403.
- A pairing PIN is required for Tailscale, LAN and external clients.
- Every data route (`/api/v1/devices`, `/api/v1/exec`, `/api/v1/upload`) requires a bearer token, or the local secret from loopback. `authorizeProtected` accepts `X-Simmesh-Local-Secret` only when the socket address is loopback, and the client sends that secret only to the daemon's own port.
- Admin routes (`/api/v1/settings`, `/api/v1/code/generate`, `/api/v1/tokens/revoke`, `/api/v1/shutdown`) and loopback pairing require the per-process `X-Simmesh-Local-Secret` value written to `daemon.json`. A paired bearer token is deliberately rejected there, and the secret is only sent to the local daemon's own port, never to arbitrary loopback ports such as SSH tunnels.
- Any request carrying an `Origin` header is rejected with HTTP 403, from loopback or remote, which closes DNS rebinding even when pairing PINs are turned off.
- Loopback requests carrying `X-Forwarded-For`, `Forwarded`, `X-Real-IP` or any `Tailscale-User-*` header are rejected with HTTP 403 to block CSRF and proxy bypass.
- Anonymous access is opt-in and limited to `/api/v1/pair` and `/mcp` for the source class whose PIN requirement is off. Everything else needs a bearer token.
- JSON POST routes require `Content-Type: application/json` and return HTTP 415 otherwise. Uploads also accept `application/octet-stream` with `X-Simmesh-Filename`.
- Inbound tokens are stored as SHA-256 hashes and compared in constant time. Revoke them with `pi-simmesh revoke <peer>` or `POST /api/v1/tokens/revoke`.
- `config.json` and `daemon.json` are private to the current user on POSIX systems.
Open `/simmesh-settings` to change these options:
- Tailscale-only mode. Turn it off to listen on all interfaces for LAN or external access.
- Require a pairing PIN on Tailscale.
- Require a pairing PIN on non-Tailscale sources.
- Auto-start the daemon with Pi.
- Background service. Install the daemon as a user service that keeps running when Pi is closed.
- The daemon port. The default is `47110`.
- Restart the daemon to apply binding changes.
Keep both PIN options on when you enable LAN or external access. Pairing codes expire after five minutes and lock after five wrong attempts.
## Standalone MCP
Run the MCP server over stdio:
```bash
pi-simmesh mcp
```
Point any MCP client at that command. The server exposes `simmesh_peers`, `simmesh_devices`, `simmesh_tools` and `simmesh_run`.
The daemon also serves Streamable HTTP MCP at `/mcp` on the configured port. A paired peer sends `Authorization: Bearer <token>`. When the PIN requirement for the source class is off, an allowed source may call `/mcp` without a token. That endpoint is pinned to `local`: it lists only this host, ignores any `peer` argument and applies the same remote exec policy as `/api/v1/exec`.
```bash
pi-simmesh daemon --port 47110
```
## Background service
Pi starts the daemon when it runs. On an always-on host that should keep the daemon and the HTTP MCP server running when Pi is closed, install the background service:
```bash
pi-simmesh service install
pi-simmesh service status
pi-simmesh service uninstall
```
The same actions are available from `/simmesh-service`, from `/simmesh service` and from the `Background service` entry in `/simmesh-settings`.
Linux writes a systemd user unit to `~/.config/systemd/user/pi-simmesh.service` and enables it. macOS writes a LaunchAgent to `~/Library/LaunchAgents/io.wundervrc.pi-simmesh.plist` and loads it for the current user. Windows creates a per-user logon Scheduled Task named `pi-simmesh`. The service runs the current Node binary with `dist/cli.js daemon`. Linux and macOS restart it on failure.
Admin routes for code generation, settings, token revocation and shutdown only accept loopback clients and need `X-Simmesh-Local-Secret`. `/api/v1/peers` stays loopback-only and accepts the local secret or a paired bearer token. `/api/v1/devices`, `/api/v1/exec` and `/api/v1/upload` need a bearer token from remote sources and a bearer token, or the local secret from loopback.
Remote `/api/v1/exec` callers are limited to the `simmesh` command catalog plus `boot` and `install`. `platform` must be a known platform, `device` and `session` may not start with `-`, `args` may not start with `-` except `-i`, `--settle` and `--raw`, `appPath` is rejected, and filesystem paths in `args` plus `artifactPath` must point at uploaded artifacts inside the private uploads directory. A bare artifact name such as `Foo.app` is treated as a path on `install` and rejected unless it names an upload. The same policy is enforced by the daemon HTTP `/mcp` endpoint, which always forces `peer: "local"`, so a remote MCP caller cannot pivot through this host to another peer or install a local path.
Uploads are streamed to disk. A `.apk` or `.ipa` is sent as `Content-Type: application/octet-stream` with a percent-encoded `X-Simmesh-Filename`, so a large artifact never sits in memory and a non-ASCII name survives the header. The JSON `{ filename, dataBase64 }` form still works. A sweep removes stale uploads every 15 minutes.
## CLI
```bash
pi-simmesh daemon [--port <p>]
pi-simmesh daemon-stop
pi-simmesh mcp
pi-simmesh doctor
pi-simmesh service [install|uninstall|status]
pi-simmesh status
pi-simmesh devices [--peer <name>]
pi-simmesh code
pi-simmesh pair <address> [--port <p>] [--code <code>]
pi-simmesh unpair <name>
pi-simmesh revoke <name>
pi-simmesh settings [--tailscale-only on|off] [--pin-tailscale on|off] [--pin-other on|off]
```
`daemon` runs in the foreground. The extension starts a detached daemon when `/simmesh-code` runs or when Pi starts with auto-start enabled.
`pi-simmesh doctor` checks Node 22+, the Tailscale CLI and IP, daemon reachability, Xcode/`simctl` on macOS, the Android SDK (`adb`, `emulator`, AVDs), agent-device resolution and the background service, then prints a one-line fix for anything that fails.
## Files
- `~/.simmesh/config.json` stores node identity, settings, peers and hashed inbound tokens.
- `~/.simmesh/daemon.json` stores the running daemon PID, port and loopback local secret.
- `~/.simmesh/daemon.log` receives daemon stderr when Pi auto-starts it.
- Uploads for `install` go to `~/.simmesh/uploads` (mode `0700`). Files older than one hour are swept on startup and removed after a remote install.
Set `SIMMESH_HOME` to use a different config directory.
## Cross-platform notes
- macOS supports iOS and tvOS simulators through `xcrun simctl` and Android emulators through `adb`.
- Linux supports Android emulators and devices. iOS simulators need macOS.
- Windows supports Android emulators and devices. Use Tailscale for Windows if you pair from a Windows host.
- Screenshots are PNG on every platform. On macOS, PNGs above 400 KB are resized to 1280px with `sips` when available; pass `--raw` in `args` to keep the original. Uploads are capped at 250 MB.
- The background service uses systemd on Linux, launchd on macOS and a per-user Scheduled Task on Windows.
## Development
```bash
npm install
npm run typecheck
npm run build
npm test
```
`npm run build` emits `dist/cli.js` and `dist/extension.js`. Tests run TypeScript directly with `tsx` and do not write to `dist`.
## License
MIT (c) wundervrc
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues