Skip to content

Commit d9abfdd

Browse files
feat(mobile): mobile:install --session installs into an agent-device session
For devices opened elsewhere (a device pool, cloud, or remote host), install the cached dev client for this checkout's fingerprint through the caller's agent-device session, from the caller's workspace (agent-device scopes session ownership to it). It never builds; without a shared build it names the next step. --abi picks the Android build, --metro opens it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7a95549 commit d9abfdd

3 files changed

Lines changed: 127 additions & 2 deletions

File tree

‎.agents/skills/test-t3-mobile/SKILL.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ names). The device id may be omitted when exactly one device is booted. It
4141
prints one JSON line; on failure it names the next command. Authorized mobile
4242
verification includes that step unless the user prohibits it.
4343

44+
For a device you opened in an agent-device session elsewhere (a device pool,
45+
cloud, or remote host), run `vp run mobile:install <ios|android> --session <s>`
46+
from the directory you opened the session in. It installs the cached build into
47+
that session (`--abi arm64-v8a` for an ARM Android device; `--metro <url>` also
48+
opens it against Metro) and never builds.
49+
4450
Start `vp run dev:client` from `apps/mobile`, or reuse a healthy Metro belonging
4551
to this checkout. Open its printed development-client URL with AgentDevice
4652
`open com.t3tools.t3code.dev <url>` and all returned target arguments.

‎apps/mobile/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ log file it prints (`T3_NATIVE_CLIENT_VERBOSE=1` streams it instead). Builds are
4141
your task-cache login (`bash infra/task-cache/install.sh`) can write. `T3_NATIVE_CLIENT_CACHE=read`
4242
skips the upload and `off` skips the shared cache. Physical iPhones still use `vp run ios:dev`.
4343

44+
`--session <name>` installs into an agent-device session opened elsewhere, such as a device pool
45+
or a cloud simulator, instead of a local device: `vp run mobile:install android --session pool-1
46+
--metro http://<this-machine>:8081`. It uses only the cached build (x86_64 by default; `--abi`
47+
for ARM) and fails with the next step when no machine has built this fingerprint yet.
48+
4449
For a read-only decision, run `node ../../scripts/mobile-native-client.ts check <ios|android>
4550
[device]`: exit 0 means compatible, 2 means an install is needed, and 1 means an operational error.
4651
An externally installed client is unverified until the helper installs it once.

‎scripts/mobile-native-client.ts‎

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as Path from "effect/Path";
1414
import * as Random from "effect/Random";
1515
import * as Schema from "effect/Schema";
1616
import * as Stream from "effect/Stream";
17-
import { Argument, Command } from "effect/cli";
17+
import { Argument, Command, Flag } from "effect/cli";
1818
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
1919
import { ChildProcess, ChildProcessSpawner } from "effect/process";
2020

@@ -710,6 +710,7 @@ export const resolveArtifact = Effect.fn("nativeClient.resolveArtifact")(functio
710710
platform: NativePlatform,
711711
abi: string | null,
712712
fingerprint: string,
713+
allowBuild = true,
713714
) {
714715
const fs = yield* FileSystem.FileSystem;
715716
const path = yield* Path.Path;
@@ -738,6 +739,10 @@ export const resolveArtifact = Effect.fn("nativeClient.resolveArtifact")(functio
738739
return { ...artifact, source: "remote" as const, buildMs: yield* readBuildMs(directory) };
739740
}
740741
}
742+
if (!allowBuild)
743+
return yield* new NativeClientError({
744+
message: `No shared build of ${key} yet. Run \`vp run mobile:install ${platform}\` once on a machine with a local ${platform === "ios" ? "simulator" : "emulator"} of this checkout; it builds the client and shares it.`,
745+
});
741746
const log = yield* BuildLog;
742747
yield* Console.error(
743748
`No cached client for ${key}. Building it once for every machine (5-15 min)${log ? `. Log: ${log}` : ""}`,
@@ -830,15 +835,124 @@ const reportTelemetry = Effect.fn("nativeClient.reportTelemetry")(
830835
(effect) => effect.pipe(Effect.timeout("5 seconds"), Effect.ignore),
831836
);
832837

838+
/**
839+
* Install into an agent-device session the caller already opened (a device pool, a cloud
840+
* provider, or a local device), using the shared cache only; such hosts cannot build.
841+
*/
842+
const installIntoSession = Effect.fn("nativeClient.installIntoSession")(function* (
843+
home: string,
844+
platform: NativePlatform,
845+
session: string,
846+
abi: string,
847+
metro: string | undefined,
848+
) {
849+
const started = yield* Clock.currentTimeMillis;
850+
const path = yield* Path.Path;
851+
const node = yield* HostProcess.ExecutablePath;
852+
const agentDevice = path.join(
853+
(yield* roots).repo,
854+
"scripts/node_modules/agent-device/bin/agent-device.mjs",
855+
);
856+
// agent-device scopes session ownership to the workspace (working directory) it runs in.
857+
const workspace = yield* HostProcess.WorkingDirectory;
858+
const deviceAbi = platform === "android" ? abi : null;
859+
const task = deviceAbi ? `native-client:android-${deviceAbi}` : `native-client:${platform}`;
860+
const current = yield* fingerprint(platform);
861+
const artifact = yield* resolveArtifact(home, platform, deviceAbi, current, false).pipe(
862+
Effect.tapError(() => reportTelemetry(home, task, "failed", 0)),
863+
);
864+
yield* Console.error(`Installing into agent-device session ${session}...`);
865+
yield* command(
866+
node,
867+
[agentDevice, "install", bundleId, artifact.file, "--session", session],
868+
true,
869+
workspace,
870+
);
871+
if (metro) {
872+
const url = encodeURIComponent(metro);
873+
yield* command(
874+
node,
875+
[
876+
agentDevice,
877+
"open",
878+
bundleId,
879+
`t3code-dev://expo-development-client/?url=${url}&disableOnboarding=1&disableFab=1&disableAutoLaunch=1`,
880+
"--session",
881+
session,
882+
],
883+
true,
884+
workspace,
885+
);
886+
}
887+
yield* reportTelemetry(
888+
home,
889+
task,
890+
artifact.source === "build" ? "executed" : artifact.source,
891+
artifact.buildMs,
892+
);
893+
const seconds = Math.round(((yield* Clock.currentTimeMillis) - started) / 1000);
894+
yield* Console.error(
895+
`Installed into session ${session} in ${seconds}s (${artifact.source}).${metro ? "" : " Open it with Metro: --metro http://<this-machine>:8081."}`,
896+
);
897+
yield* Console.log(
898+
yield* encodeOutput({
899+
status: "installed",
900+
source: artifact.source,
901+
fingerprint: current,
902+
session,
903+
seconds,
904+
}),
905+
);
906+
});
907+
833908
const main = Command.make(
834909
"mobile-native-client",
835910
{
836911
mode: Argument.Literals("mode", ["check", "ensure"]),
837912
platform: Argument.Literals("platform", ["ios", "android"]),
838913
device: Argument.String("device").pipe(Argument.optional),
914+
session: Flag.String("session").pipe(
915+
Flag.withDescription(
916+
"Install into this already-open agent-device session (a device pool, cloud, or remote host) instead of a local device.",
917+
),
918+
Flag.optional,
919+
),
920+
abi: Flag.Literals("abi", ["x86_64", "arm64-v8a"]).pipe(
921+
Flag.withDescription("Android ABI of the session's device (default x86_64)."),
922+
Flag.withDefault("x86_64" as const),
923+
),
924+
metro: Flag.String("metro").pipe(
925+
Flag.withDescription("With --session, open the dev client against this Metro URL."),
926+
Flag.optional,
927+
),
839928
},
840-
Effect.fn("nativeClient.main")(function* ({ mode, platform, device: requested }) {
929+
Effect.fn("nativeClient.main")(function* ({
930+
mode,
931+
platform,
932+
device: requested,
933+
session,
934+
abi: sessionAbi,
935+
metro,
936+
}) {
841937
const started = yield* Clock.currentTimeMillis;
938+
if (Option.isSome(session)) {
939+
if (mode !== "ensure" || Option.isSome(requested))
940+
return yield* new NativeClientError({
941+
message:
942+
"--session installs into an agent-device session; use it with ensure and no device id.",
943+
});
944+
const environment = yield* HostProcess.Environment;
945+
const home = environment.HOME ?? environment.USERPROFILE;
946+
if (!home)
947+
return yield* new NativeClientError({ message: "HOME or USERPROFILE must be set." });
948+
return yield* installIntoSession(
949+
home,
950+
platform,
951+
session.value,
952+
sessionAbi,
953+
Option.getOrUndefined(metro),
954+
);
955+
}
842956
const target = yield* resolveDevice(platform, Option.getOrUndefined(requested));
843957
const device = target.id;
844958
yield* Console.error(`Device: ${target.label} (${device})`);

0 commit comments

Comments
 (0)