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
7 changes: 6 additions & 1 deletion apps/claude/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ import { downloadedPanelRuntime, panelRuntimeReleaseSchema, usePanelRuntime } fr
// 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))));
if (pinned !== undefined) {
const metadata: unknown = JSON.parse(pinned);
const release = panelRuntimeReleaseSchema.parse(metadata);
const download = downloadedPanelRuntime(release);
usePanelRuntime(download.ensure);
}
await runStdioServer({ panel: createPanel({ inline: false }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: true })] });
10 changes: 10 additions & 0 deletions apps/codex-plugin/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import "@mobile-dev/core/instrument.ts";
import { readFile } from "node:fs/promises";
import { useDownloadedTestingRuntime } from "@mobile-dev/core/e2e-runtime.ts";
import { panelRuntimeReleaseSchema } from "@mobile-dev/core/panel-runtime.ts";
import { runStdioServer } from "@mobile-dev/core/stdio-server.ts";
import { createPanel } from "@mobile-dev/core/panel-tools.ts";
import { agentDeviceTools, readAgentDeviceCatalog } from "@mobile-dev/core/agent-device-tools.ts";
Expand All @@ -9,6 +12,13 @@ import { panelSelection } from "./panel-selection.ts";

// Codex's server: the shared server with Mobile Dev's panel and agent-device's commands, plus
// the updater for Codex plugin installs.
if (!process.env.MOBILE_DEV_E2E_RUNTIME?.trim()) {
const pin = new URL("./testing-runtime.json", import.meta.url);
const source = await readFile(pin, "utf8");
const metadata: unknown = JSON.parse(source);
const release = panelRuntimeReleaseSchema.parse(metadata);
useDownloadedTestingRuntime(release);
}
const inline = panelPlacement("inline") === "inline";
const panelContext = inline ? panelSelection : browserPanel({ always: true });
const features = [agentDeviceTools(readAgentDeviceCatalog()), codexUpdates, panelContext];
Expand Down
10 changes: 9 additions & 1 deletion apps/codex-plugin/tooling/package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { telemetryBuildEnvironment } from "../../../tooling/telemetry-build.mjs"
import { pluginMarketplace } from "./plugin-marketplace.mjs";
import { buildCodexHost } from "./build.mjs";
import { assertRuntime, RELEASE_DOCUMENTS, releaseVersion, stageRuntime } from "../../../tooling/host-runtime.mjs";
import { packPanelRuntime } from "../../../tooling/panel-runtime.mjs";
import { sharedSkills } from "../../../tooling/plugin-hosts.mjs";

const telemetryEnvironment = telemetryBuildEnvironment();
Expand All @@ -20,7 +21,10 @@ await rm(plugin, { recursive: true, force: true });
await mkdir(plugin, { recursive: true });
await copyFile(`${source}/.mcp.json`, `${plugin}/.mcp.json`);
for (const path of RELEASE_DOCUMENTS) await copyFile(path, `${plugin}/${path}`);
await stageRuntime(`${plugin}/dist`);
await stageRuntime(`${plugin}/dist`, { exclude: ["e2e"] });
const runtime = await packPanelRuntime(manifest.version, { release: telemetryEnvironment === "release", testingOnly: true });
const runtimePin = JSON.stringify(runtime.pin, null, 2);
await writeFile(`${plugin}/dist/testing-runtime.json`, runtimePin + "\n");
await buildCodexHost(telemetryEnvironment, `${plugin}/dist`);
for (const path of [".codex-plugin", "assets"]) await cp(`${source}/${path}`, `${plugin}/${path}`, { recursive: true, verbatimSymlinks: true });
for (const skill of sharedSkills) await cp(skill, `${plugin}/skills/${basename(skill)}`, { recursive: true, verbatimSymlinks: true });
Expand All @@ -42,4 +46,8 @@ const files = await readdir(plugin);
if (windows) execFileSync("tar.exe", ["-a", "-cf", archive, ...files], { cwd: plugin });
else execFileSync("zip", ["-qr", archive, ...files], { cwd: plugin });
if ((await stat(archive)).size > 100_000_000) throw new Error("The plugin ZIP exceeds the 100 MB upload limit.");
const tar = windows ? "tar.exe" : "/usr/bin/tar";
const members = execFileSync(tar, ["-tf", archive], { encoding: "utf8", maxBuffer: 16 * 1024 * 1024 });
const entries = members.trimEnd().split("\n").length;
if (entries > 5000) throw new Error(`The plugin ZIP has ${entries} entries. The upload limit is 5000.`);
console.log(`Plugin: ${plugin}\nMarketplace: ${marketplace}\nZIP: ${archive}`);
59 changes: 55 additions & 4 deletions apps/codex-plugin/tooling/smoke-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { access, cp, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { pathToFileURL } from "node:url";
import { setTimeout as delay } from "node:timers/promises";
import { testingRuntimeArchive } from "../../../tooling/panel-runtime.mjs";
import { join, resolve } from "node:path";
import assert from "node:assert/strict";
import { createHash } from "node:crypto";
Expand All @@ -16,6 +19,21 @@ let transport;
let runtimeTransport;
let browserTransport;

async function prepareTestingRuntime(client) {
const deadline = Date.now() + 60_000;
let name = "mobile_testing_prepare_runtime";
for (;;) {
const response = await client.callTool({ name, arguments: {} });
assert.ok(!response.isError, JSON.stringify(response.content));
const progress = response.structuredContent.progress;
assert.notEqual(progress.phase, "failed", progress.message);
if (progress.phase === "ready") return;
assert.ok(Date.now() < deadline, "Testing Studio installation timed out");
name = "mobile_testing_runtime_progress";
await delay(100);
}
}

function uiIdentity(text) {
const user = text.match(/name="mobile-dev-user-id" content="(anon_[a-f0-9]{32})"/);
const session = text.match(/name="mobile-dev-session-id" content="(run_[a-f0-9]{32})"/);
Expand Down Expand Up @@ -94,6 +112,23 @@ try {
const manifestText = await readFile(manifestPath, "utf8");
const manifest = JSON.parse(manifestText);
assert.equal(manifest.name, "mobile-dev");
const runtimeName = testingRuntimeArchive(manifest.version);
const archive = resolve("release", runtimeName);
const pinPath = join(plugin, "dist/testing-runtime.json");
const pin = JSON.parse(await readFile(pinPath, "utf8"));
const bytes = await readFile(archive);
assert.equal(pin.bytes, bytes.length);
assert.equal(pin.sha256, createHash("sha256").update(bytes).digest("hex"));
assert.equal(pin.version, manifest.version);
if (telemetryConfig.environment === "release") {
const repository = process.env.GITHUB_REPOSITORY || "callstackincubator/codex-mobile-dev-plugin";
assert.equal(pin.url, `https://github.com/${repository}/releases/download/v${manifest.version}/${runtimeName}`);
}
// Serve the exact release bytes from a local file before the GitHub release exists.
const localPin = { ...pin, url: pathToFileURL(archive).href };
await writeFile(pinPath, JSON.stringify(localPin));
delete serverEnv.MOBILE_DEV_E2E_RUNTIME;
serverEnv.LOCALAPPDATA = fixtureHome;
transport = new StdioClientTransport({
command: serverConfig.command, args: serverConfig.args, cwd: serverCwd, stderr: "pipe", env: serverEnv,
});
Expand Down Expand Up @@ -127,10 +162,21 @@ try {
for (const name of ["mobile_list_ios_devices", "mobile_list_android_devices", "mobile_boot_android_emulator", "mobile_android_stream_session", "mobile_ios_mirror_session", "mobile_ios_mirror_reset", "mobile_ios_mirror_close"]) assert.ok(tools.tools.some(tool => tool.name === name));
for (const name of ["device_open", "device_snapshot", "device_press", "device_screenshot"]) assert.ok(tools.tools.some(tool => tool.name === name), name);
await access(join(plugin, "dist/agent-device/tools.json"));
await access(join(plugin, "dist/e2e/node_modules/e2e/dist/cli/bin.js"));
await access(join(plugin, "dist/e2e/node_modules/@e2e-dev/mobile/dist/nodes.js"));
await access(join(plugin, "dist/e2e/release.json"));
await access(join(plugin, "dist/e2e/THIRD_PARTY_NOTICES.txt"));
await assert.rejects(access(join(plugin, "dist/e2e")), { code: "ENOENT" });
const testingConfig = () => client.callTool({ name: "mobile_testing_project_config", arguments: { projectPath: temporary } });
const cold = await testingConfig();
assert.equal(cold.isError, undefined, JSON.stringify(cold.content));
assert.equal(cold.structuredContent.needsRuntime, true);
const runtimeRoot = cold.structuredContent.runtime.root;
await assert.rejects(access(runtimeRoot), { code: "ENOENT" });
await prepareTestingRuntime(client);
const warm = await testingConfig();
assert.equal(warm.structuredContent.needsRuntime, false);
for (const path of ["node_modules/e2e/dist/cli/bin.js", "node_modules/@e2e-dev/mobile/dist/nodes.js", "release.json", "THIRD_PARTY_NOTICES.txt"]) {
await access(join(runtimeRoot, path));
}
const runner = join(runtimeRoot, "node_modules/e2e/dist/cli/bin.js");
execFileSync(process.execPath, [runner, "--version"], { encoding: "utf8", timeout: 15_000 });
const physicalMirror = tools.tools.find(tool => tool.name === "mobile_ios_mirror_session");
assert.deepEqual(physicalMirror._meta.ui.visibility, ["app"]);
await access(join(plugin, "dist/serve-emu/src/cli.mjs"));
Expand Down Expand Up @@ -209,9 +255,14 @@ try {
assert.equal(workspace._meta.ui.resourceUri, `ui://mobile-dev/${manifest.version}/workspace.html`);
assert.deepEqual(resource.contents[0]._meta.ui.csp.connectDomains, ["https://o4512180958068736.ingest.de.sentry.io"]);
assert.deepEqual(resource.contents[0]._meta.ui.csp.resourceDomains, []);
// A fresh MCP process must be able to use the cached runner with the release unavailable.
const offlineArchive = join(temporary, "unavailable.tar.gz");
const offlinePin = { ...pin, url: pathToFileURL(offlineArchive).href };
await writeFile(pinPath, JSON.stringify(offlinePin));
runtimeTransport = new StdioClientTransport({ command: serverConfig.command, args: serverConfig.args, cwd: serverCwd, stderr: "pipe", env: serverEnv });
const runtime = new Client({ name: "mobile-dev-package-runtime", version: "1" });
await runtime.connect(runtimeTransport);
await prepareTestingRuntime(runtime);
const runtimeResource = await runtime.readResource({ uri: entrypoint._meta.ui.resourceUri });
if (process.env.MOBILE_DEV_TELEMETRY === "off") {
assert.deepEqual(runtimeResource.contents[0], resource.contents[0]);
Expand Down
8 changes: 5 additions & 3 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ A prerelease version, such as `0.1.172-test.1`, runs the same workflow as a test
deployment. Set that version in the same three places on a branch, commit it as
`chore(release): prepare 0.1.172-test.1`, and push the commit and its
`v0.1.172-test.1` tag. The workflow builds, tests and packages it like a release and
publishes a GitHub prerelease with every package, including Claude's panel runtime
archive, which the Claude plugin of that build downloads. A prerelease is never
publishes a GitHub prerelease with every package, including the runtime archives pinned by the
Codex and Claude packages. A prerelease is never
marked Latest, later release notes skip it, and it stays off `release/latest` and
`release/claude`, so Codex and Claude users do not receive it. Install its Claude
plugin from the prerelease's `claude-plugin` ZIP to test the full download. Delete
Expand Down Expand Up @@ -84,7 +84,9 @@ tags and draft releases do not truncate the list. The first public release lists
the full source history. Later releases also include a link to the full diff.

Download `mobile-dev-<version>-darwin-arm64.zip` directly from the release's
assets for manual store upload. The same ZIP is also retained, with the
assets for manual store upload. The Codex ZIP contains at most 5,000 entries. Testing Studio downloads
`mobile-dev-<version>-testing-runtime-darwin-arm64.tar.gz` from the same release on first use
and caches it after verifying the pinned size and SHA-256. The same ZIP is also retained, with the
Claude packages, as one Actions artifact for 30 days; extract the Actions artifact
wrapper before uploading the plugin ZIP. Publishing a GitHub release does not submit or publish it to the OpenAI
plugin directory. A tag that already has a GitHub release will fail release
Expand Down
9 changes: 6 additions & 3 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ 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 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
- Codex measures its Testing Studio runtime download. Claude measures its combined
device and Testing Studio runtime download. `panel_runtime.ready` records, in milliseconds, how long the runtime took to be
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, including the Testing Studio runtime since 0.1.191. A failure
of each download. Claude includes Testing Studio since 0.1.191. Codex reports its
standalone archive since 0.1.192. Both metrics identify the archive with `runtime`
(`testing` or `panel`). The UI’s installation progress polls are excluded
from MCP traces and product analytics. 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
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.191",
"version": "0.1.192",
"private": true,
"workspaces": [
"packages/shared",
Expand Down
23 changes: 22 additions & 1 deletion packages/core/src/e2e-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ 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";
import { downloadedPanelRuntime, panelRuntimeDirectory, panelRuntimePath, type PanelRuntimeRelease } from "./panel-runtime.ts";
import pinnedRuntime from "../../runtimes/e2e/package.json" with { type: "json" };

export let testingRuntimeDownload: ReturnType<typeof downloadedPanelRuntime> | undefined;

export function useDownloadedTestingRuntime(release: PanelRuntimeRelease) {
const directory = panelRuntimeDirectory(process.env, "testing-runtime");
testingRuntimeDownload = downloadedPanelRuntime(release, directory, true);
}

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

Expand All @@ -24,6 +32,10 @@ export const PROJECT_CLI = "node_modules/.bin/e2e";

/** Resolves the E2E runtime from the source tree or the packaged host's runtime. */
export async function bundledE2eRoot(): Promise<string> {
if (testingRuntimeDownload) {
const directory = await testingRuntimeDownload.ensure();
return join(directory, "e2e");
}
const configured = process.env.MOBILE_DEV_E2E_RUNTIME?.trim();
const root = configured || (modulePath.endsWith(".ts")
? resolve(moduleDirectory, "../../runtimes/e2e")
Expand All @@ -39,6 +51,15 @@ async function version(root: string, name: string): Promise<string> {
}

export async function bundledRuntimeDescriptor(reason?: string): Promise<TestingRuntimeDescriptor> {
// Project discovery also runs behind the device panel. Reading its metadata must stay offline.
if (testingRuntimeDownload) {
const root = join(testingRuntimeDownload.target, "e2e");
return {
mode: "bundled", root, reason,
e2eVersion: pinnedRuntime.dependencies.e2e,
mobileVersion: pinnedRuntime.dependencies["@e2e-dev/mobile"],
};
}
const root = await bundledE2eRoot();
return {
mode: "bundled",
Expand Down
Loading
Loading