Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ Claude plugin folder `release/claude-plugin/mobile-dev` with its ZIP, and a loca
Claude's server (`apps/claude/server`), with the panel and agent-device's commands as
`device_*` tools, the skill in `apps/claude/skills` and the shared agent-device skill.
Packaging fails if a file exceeds the Claude plugin directory's 5 MiB limit, so the
packages leave out the panel's native parts (`PANEL_PARTS` in
`tooling/host-runtime.mjs`: Baguette, serve-emu, the iOS mirror addon and its
service), as `"panelRuntime": "download"` in `apps/claude/plugin-host.json` asks.
packages use `"panelRuntime": "download"` in `apps/claude/plugin-host.json`. The archive
includes the native panel parts and the Testing Studio runner
(`DOWNLOADED_RUNTIME_PARTS` in `tooling/host-runtime.mjs`).
Packaging packs those parts from `dist/` into
`release/mobile-dev-<version>-panel-runtime-darwin-arm64.tar.gz` and pins it in
`dist/panel-runtime.json` with its size and SHA-256. A local build pins the archive by
its `file:` URL; `--release` pins it on the GitHub release `v<version>`, which the
release workflow creates with every `release/mobile-dev-<version>-*` file, this archive
included. On the first panel open, the server downloads the archive, checks its size
included. On first use of a component in the archive, the server downloads it, checks its size
and checksum, refuses entries outside the parts and links, and extracts it into
`${CLAUDE_PLUGIN_DATA}/panel-runtime/<version>-<checksum>` (or
`~/Library/Caches/mobile-dev/panel-runtime` without it). The folder appears only once
Expand Down
2 changes: 1 addition & 1 deletion PRIVACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ not a reason to put secrets into your test data.

### Product analytics

Starting with version 0.1.190, release builds send basic product analytics to Anal
Starting with version 0.1.191, release builds send basic product analytics to Anal
at `anal.margelo.com` so we can see how many installations use Mobile Dev and which
tools they use most. Events record that a host session started or that a tool
was called, with the tool's name, whether it succeeded, the host (Codex, Claude,
Expand Down
6 changes: 3 additions & 3 deletions apps/claude/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ The plugin bundles most of its runtimes and native helpers, so no `npm install`,
account, or hosted service is needed. Your project's own tools build the app. Besides
its Node.js server, it runs:

- **The device panel's runtime, downloaded once.** The first time you open the panel,
- **The device and Testing Studio runtime, downloaded once.** On first use,
Mobile Dev downloads one archive from this project's GitHub release for the
installed version (`mobile-dev-<version>-panel-runtime-darwin-arm64.tar.gz`, from
`github.com/callstackincubator/codex-mobile-dev-plugin/releases`). The plugin pins
the archive's size and SHA-256 checksum and refuses any other file. It holds
[Baguette](https://github.com/tddworks/baguette), which streams and controls iOS
simulators, serve-emu with scrcpy for Android streaming, and the physical iPhone
mirroring addon and its service, built from the source and versions this
repository pins. It is unpacked into Claude Code's data folder for the plugin
mirroring addon and its service, plus the Testing Studio runner. The repository
pins their versions. The archive is unpacked into Claude Code's plugin data folder
(`~/.claude/plugins/data/`), or `~/Library/Caches/mobile-dev` elsewhere, and kept
across sessions; an update downloads its own version and removes older ones.
Nothing is downloaded until you open the panel, and the other tools work without it.
Expand Down
5 changes: 2 additions & 3 deletions apps/claude/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import { downloadedPanelRuntime, panelRuntimeReleaseSchema, usePanelRuntime } fr
// which Claude Code shows in a browser beside the chat. The panel never renders inline,
// even in the desktop app's Code tab, which renders MCP Apps: every host gets the
// browser link, so the device stays beside the chat. The plugin directory's file limit
// leaves the panel's native parts out of the package; it pins their release archive in
// panel-runtime.json, which the server downloads on first use. Without that file, as in
// host tests, the parts sit beside the server.
// applies to the panel's native parts and the Testing Studio runner. The package pins
// their release archive in panel-runtime.json, which the server downloads on first use.
const pinned = await readFile(new URL("./panel-runtime.json", import.meta.url), "utf8").catch(() => undefined);
if (pinned !== undefined) usePanelRuntime(downloadedPanelRuntime(panelRuntimeReleaseSchema.parse(JSON.parse(pinned))));
await runStdioServer({ panel: createPanel({ inline: false }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: true })] });
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A host adds to the shared pieces without changing them:
- **Runtime:** a host's `plugin-host.json` can leave out the panel's parts of `dist/`
(`"panel": false`, see `PANEL_PARTS` in `tooling/host-runtime.mjs`), download them
instead (`"panelRuntime": "download"`), and name a server build of its own. Claude
downloads Baguette, serve-emu and the iOS mirror from a release archive its package
downloads the native helpers and Testing Studio runner from a release archive its package
pins (`packages/core/src/panel-runtime.ts`), and its server loads after telemetry as
a separate module, so esbuild splits it into chunks beside `server.mjs`, keeping
every file under the Claude plugin directory's 5 MiB limit.
Expand Down
9 changes: 5 additions & 4 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ Behavior never depends on this value; it only attributes measurements and errors
model context updates by `outcome` (`stored`, `invalid` or `too_large`), and
`browser_panel.context_bytes` records the size of stored updates in bytes; the
context's text and images are never sent.
- Packages that download the panel's native parts, such as Claude's, measure that
- Packages that download the device and Testing Studio runtime, such as Claude's, measure that
step. `panel_runtime.ready` records, in milliseconds, how long the runtime took to be
ready on a panel's first backend start in a server, by `outcome`: `cached` when a
ready on its first use in a server, by `outcome`: `cached` when a
complete folder was already there, `downloaded` for a download, checksum check and
extraction, or `failed` with a bounded `reason` (`network`, `http`, `checksum`,
`archive` or `filesystem`). `panel_runtime.download_bytes` records the archive size
of each download. A failure surfaces as the expected `download_failed` outcome;
of each download, including the Testing Studio runtime since 0.1.191. A failure
surfaces as the expected `download_failed` outcome;
checksum, archive and filesystem failures are also captured as
`panel_runtime.prepare` errors with a `panel_runtime_failure` tag, while offline
machines and unreachable releases are not. URLs, paths and versions are never
Expand All @@ -60,7 +61,7 @@ shell has no native Sentry SDK.

## Product analytics

Starting with 0.1.190, release MCP servers send basic product analytics to the
Starting with 0.1.191, release MCP servers send basic product analytics to the
Mobile Dev project in Anal to count installations and feature use. Earlier
releases from 0.1.177 send to Mixpanel's EU endpoint. `instrumentProductAnalytics`
(`packages/core/src/analytics.ts`) wraps the `tools/call` handler and reports
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobile-dev",
"version": "0.1.190",
"version": "0.1.191",
"private": true,
"workspaces": [
"packages/shared",
Expand Down
21 changes: 12 additions & 9 deletions packages/core/src/e2e-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { readFile } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { ExpectedOperationError } from "@mobile-dev/shared/error-reporting.ts";
import { panelRuntimePath } from "./panel-runtime.ts";

export type TestingRuntimeMode = "project" | "bundled";

Expand All @@ -15,18 +16,20 @@ export interface TestingRuntimeDescriptor {
reason?: string;
}

const sourceRuntime = resolve("packages/runtimes/e2e");
const modulePath = fileURLToPath(import.meta.url);
const moduleDirectory = dirname(modulePath);

/** The runner a project run executes (`runnerBin`); its presence is what makes a project's own setup usable. */
export const PROJECT_CLI = "node_modules/.bin/e2e";

/** The shipped runtime beside server.mjs, with the source tree fallback used by unit tests. */
export function bundledE2eRoot(): string {
/** Resolves the E2E runtime from the source tree or the packaged host's runtime. */
export async function bundledE2eRoot(): Promise<string> {
const configured = process.env.MOBILE_DEV_E2E_RUNTIME?.trim();
const besideServer = join(dirname(fileURLToPath(import.meta.url)), "e2e");
for (const candidate of [configured, besideServer, sourceRuntime]) {
if (candidate && existsSync(join(candidate, "node_modules/e2e/package.json"))) return candidate;
}
const root = configured || (modulePath.endsWith(".ts")
? resolve(moduleDirectory, "../../runtimes/e2e")
: await panelRuntimePath("e2e"));
const manifest = join(root, "node_modules/e2e/package.json");
if (existsSync(manifest)) return root;
throw new ExpectedOperationError("app_unavailable", "The bundled e2e runtime is missing. Reinstall Mobile Dev.");
}

Expand All @@ -36,7 +39,7 @@ async function version(root: string, name: string): Promise<string> {
}

export async function bundledRuntimeDescriptor(reason?: string): Promise<TestingRuntimeDescriptor> {
const root = bundledE2eRoot();
const root = await bundledE2eRoot();
return {
mode: "bundled",
root,
Expand Down Expand Up @@ -65,7 +68,7 @@ export async function projectRuntimeDescriptor(projectPath: string): Promise<Tes
}

export async function verifyBundledE2eRuntime(): Promise<void> {
const root = bundledE2eRoot();
const root = await bundledE2eRoot();
const lock = await readFile(join(root, "package-lock.json"), "utf8");
const release = JSON.parse(await readFile(join(root, "release.json"), "utf8"));
const actual = createHash("sha256").update(lock).digest("hex");
Expand Down
15 changes: 11 additions & 4 deletions packages/core/src/panel-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { z } from "zod";
import { ExpectedOperationError } from "@mobile-dev/shared/error-reporting.ts";
import { captureServerError, recordPanelRuntime } from "./telemetry.ts";

/** The panel's native parts, as the runtime archive and dist/ lay them out (tooling's PANEL_PARTS). */
export const PANEL_RUNTIME_PARTS = ["baguette", "serve-emu", "ios-mirror", "ios-mirror-service.mjs", "resource-saving"] as const;
export type PanelRuntimeFile = "baguette/Baguette" | "serve-emu/src/cli.mjs" | "ios-mirror-service.mjs" | "resource-saving/simslim" | "resource-saving/avdslim";
/** The parts in the downloadable runtime, as laid out in dist/. */
export const PANEL_RUNTIME_PARTS = ["baguette", "serve-emu", "ios-mirror", "ios-mirror-service.mjs", "resource-saving", "e2e"] as const;
export type PanelRuntimeFile = "baguette/Baguette" | "serve-emu/src/cli.mjs" | "ios-mirror-service.mjs" | "resource-saving/simslim" | "resource-saving/avdslim" | "e2e";
const E2E_CLI = "e2e/node_modules/e2e/dist/cli/bin.js";

// Bundled, this module is server.mjs or a chunk in dist/, beside the parts.
let locate: () => Promise<string> = async () => fileURLToPath(new URL("./", import.meta.url));
Expand All @@ -40,7 +41,7 @@ export type PanelRuntimeRelease = z.infer<typeof panelRuntimeReleaseSchema>;

export class PanelRuntimeUnavailableError extends ExpectedOperationError {
constructor(detail: string) {
super("download_failed", `Mobile Dev could not download its device runtime: ${detail} Check the internet connection, then open Mobile Dev again.`);
super("download_failed", `Mobile Dev could not download its device and testing runtime: ${detail} Check the internet connection, then try again.`);
}
}

Expand Down Expand Up @@ -123,6 +124,8 @@ async function complete(target: string, release: PanelRuntimeRelease) {
const marker: unknown = JSON.parse(await readFile(join(target, "panel-runtime.json"), "utf8"));
if (typeof marker !== "object" || marker === null || ("sha256" in marker && marker.sha256 === release.sha256) === false) return false;
await access(join(target, "baguette/Baguette"), constants.X_OK);
const e2eCli = join(target, E2E_CLI);
await access(e2eCli);
for (const name of ["simslim", "avdslim"]) {
const executable = join(target, "resource-saving", name);
await access(executable, constants.X_OK);
Expand Down Expand Up @@ -182,6 +185,10 @@ async function extract(archive: string, staging: string) {
await access(join(staging, "baguette/Baguette"), constants.X_OK).catch(() => {
throw new RuntimeFailure("archive", "the simulator backend in the archive is not executable.");
});
const e2eCli = join(staging, E2E_CLI);
await access(e2eCli).catch(() => {
throw new RuntimeFailure("archive", "the archive is missing the Testing Studio runner.");
});
for (const name of ["simslim", "avdslim"]) {
const executable = join(staging, "resource-saving", name);
await access(executable, constants.X_OK).catch(() => { throw new RuntimeFailure("archive", "a resource optimizer in the archive is not executable."); });
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/testing-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async function loadProjectionWithFallback(runtimeRoot: string): Promise<EnginePr
return await loadProjection(runtimeRoot);
} catch (error) {
let bundled: string;
try { bundled = bundledE2eRoot(); } catch { throw error; }
try { bundled = await bundledE2eRoot(); } catch { throw error; }
if (bundled === runtimeRoot) throw error;
return await loadProjection(bundled).catch(() => { throw error; });
}
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/testing-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ const SUBSCRIPTION_IDS = ["openai", "github-copilot", "opencode-console", "space
export async function readTestingLoginStatus(): Promise<TestingLoginStatus> {
const status = Object.fromEntries(SUBSCRIPTION_IDS.map(id => [id, false])) as TestingLoginStatus;
try {
const module = await import(pathToFileURL(join(bundledE2eRoot(), "node_modules/e2e/dist/oauth/store.js")).href) as {
const root = await bundledE2eRoot();
const store = join(root, "node_modules/e2e/dist/oauth/store.js");
const url = pathToFileURL(store);
const module = await import(url.href) as {
defaultCredentialStore(): { list(): Promise<string[]> };
};
const stored = new Set(await module.defaultCredentialStore().list());
Expand Down Expand Up @@ -200,7 +203,8 @@ function packageManager(root: string, manifest: Record<string, unknown>): SetupP
}

async function skillFiles(): Promise<{ relative: string; content: string }[]> {
const root = join(bundledE2eRoot(), "node_modules/e2e/skills/e2e");
const runtime = await bundledE2eRoot();
const root = join(runtime, "node_modules/e2e/skills/e2e");
const files: { relative: string; content: string }[] = [];
const walk = async (directory: string) => {
for (const entry of await readdir(directory, { withFileTypes: true })) {
Expand Down Expand Up @@ -372,7 +376,10 @@ type OAuthProvider = "openai" | "github-copilot" | "opencode-console" | "spacexa
type LoginCallbacks = { signal: AbortSignal; onAuth(auth: { url: string; instructions: string; userCode?: string }): void; onProgress(message: string): void; onPrompt(prompt: { message: string; placeholder?: string }): Promise<string> };
type LoginRunner = (provider: OAuthProvider, callbacks: LoginCallbacks) => Promise<unknown>;
async function e2eLogin(providerId: OAuthProvider, callbacks: LoginCallbacks) {
const module = await import(pathToFileURL(join(bundledE2eRoot(), "node_modules/e2e/dist/oauth/login.js")).href) as { login(provider: string, input: Record<string, unknown>): Promise<unknown> };
const root = await bundledE2eRoot();
const login = join(root, "node_modules/e2e/dist/oauth/login.js");
const url = pathToFileURL(login);
const module = await import(url.href) as { login(provider: string, input: Record<string, unknown>): Promise<unknown> };
return module.login(providerId, { callbacks });
}
export function startTestingLogin(id: OAuthProvider, runLogin: LoginRunner = e2eLogin): SetupOperation {
Expand Down
9 changes: 7 additions & 2 deletions packages/core/test/panel-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { join } from "node:path";
import { pathToFileURL } from "node:url";
import { ExpectedOperationError } from "@mobile-dev/shared/error-reporting.ts";
import { downloadedPanelRuntime, PANEL_RUNTIME_PARTS, panelRuntimeDirectory, panelRuntimeReleaseSchema, panelRuntimePath, PanelRuntimeUnavailableError, usePanelRuntime, type PanelRuntimeRelease } from "../src/panel-runtime.ts";
import { PANEL_PARTS } from "../../../tooling/host-runtime.mjs";
import { DOWNLOADED_RUNTIME_PARTS } from "../../../tooling/host-runtime.mjs";

/** A runtime archive laid out like dist/, with extra entries a tampered archive might hold. */
async function archive(t: test.TestContext, extra?: (root: string) => Promise<string[]>) {
Expand All @@ -32,6 +32,9 @@ async function archive(t: test.TestContext, extra?: (root: string) => Promise<st
await writeFile(executable, "#!/bin/sh\n");
await chmod(executable, 0o755);
}
const cliDirectory = join(root, "e2e/node_modules/e2e/dist/cli");
await mkdir(cliDirectory, { recursive: true });
await writeFile(join(cliDirectory, "bin.js"), 'console.log("e2e");');
const members = [...PANEL_RUNTIME_PARTS, ...await extra?.(root) ?? []];
const file = join(directory, "runtime.tar.gz");
execFileSync("tar", ["-czf", file, "-C", root, ...members], { env: { ...process.env, COPYFILE_DISABLE: "1" } });
Expand All @@ -56,7 +59,7 @@ async function serve(t: test.TestContext, respond: () => { status: number; body?
}

test("the runtime parts match the parts packaging leaves out", () => {
assert.deepEqual([...PANEL_RUNTIME_PARTS], PANEL_PARTS);
assert.deepEqual([...PANEL_RUNTIME_PARTS], DOWNLOADED_RUNTIME_PARTS);
});

test("the runtime downloads once, verifies, and is shared by later servers", async t => {
Expand All @@ -76,6 +79,8 @@ test("the runtime downloads once, verifies, and is shared by later servers", asy
assert.deepEqual(await readdir(data), [`1.2.3-${release.sha256.slice(0, 12)}`]);
usePanelRuntime(first);
assert.equal(await panelRuntimePath("serve-emu/src/cli.mjs"), join(root, "serve-emu/src/cli.mjs"));
const e2e = await panelRuntimePath("e2e");
assert.equal(e2e, join(root, "e2e"));
});

test("an archive that does not match its pin is refused and leaves nothing behind", async t => {
Expand Down
Loading
Loading