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
4 changes: 2 additions & 2 deletions packages/command-surface/src/management/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ export const openCommandFacet = defineCommandFacet({
summary: 'Open an app, deep link or URL, save replays',
searchHint: 'relaunch',
cliDetail:
'Use --platform to bind URL/deep-link opens to the target platform. For local or Limrun iOS simulator initial stdout/stderr, put --launch-console <path> on this open command, for example agent-device open "Agent Device Tester" --platform ios --launch-console artifacts/launch-console.log. Expo Go/dev-client shells accept host + URL, for example agent-device open "Expo Go" exp://127.0.0.1:8081 --platform ios. macOS also supports --surface app|frontmost-app|desktop|menubar. --metro-host/--metro-port/--bundle-url choose the app\'s Metro server and save that address for later metro reload calls in the same session. A fresh open without Metro hints clears an older same-name binding; close also clears it. --launch-url supplies the app\'s launch URL; it does not select the reload server. A later open without these flags applies the hints and launch URL again only when it opens the same app; it opens another app without them. On an iOS simulator without --launch-url, open connects a detected Expo development client through its expo-development-client URL. The app must declare a single exp+<slug> scheme that no other installed app owns. If detection is inconclusive, the app opens normally. Bare React Native apps receive their server settings before launch. On an iOS simulator, when --launch-url raises an "Open in <App>?" prompt that keeps open from seeing the app, open accepts it if the URL scheme belongs to the session app (data.launchConfirmation: "accepted"); if the scheme belongs to another installed app, the prompt stays on screen and open fails with details.reason launch_confirmation_foreign_app; if the scheme owner cannot be resolved because no single installed app owns it or the lookup failed, the prompt stays on screen and open returns with data.launchConfirmation: "unanswered", launchConfirmationReason url-owner-unresolved, and a warning; a prompt that is seen but not recognized is reported the same way with launchConfirmationReason alert-unrecognized and its own warning; for url-owner-unresolved, answer the prompt with alert accept; for alert-unrecognized, read the alert with alert get first, because it can be the app\'s own alert (such as a permission prompt) rather than the launch confirmation, and answer with alert accept only when it is the launch confirmation; when agent-device cannot read whether a prompt is up at all (the alert read, the accept, or the runner itself failed, including after a re-hand of the URL), open stays green, reports no launchConfirmation plus data.launchConfirmationProbeFailure naming the failed step (alert-read, alert-accept, or runner), and appends a warning that says to check with alert get. The prompt is read whenever open cannot see the app afterwards, including on a slow host where the app\'s target discovery fails on its own deadline. When an accept leaves the app provably not running, open hands the same URL over once more and reads again; still not running, it fails with details.reason launch_confirmation_unanswered. When the runner reports its main-thread timeout for the accept and the prompt is still up, open presses Open again, but only when the time the open request has left covers a whole press and the read that checks it. A recognized prompt still visible after a failed accept, or once that time is gone, also fails with this reason, even if the app is running behind it; answer it with alert accept or alert dismiss. A simulator openurl that CoreSimulator never answers fails within 20s with details.reason ios-simulator-openurl-timeout. The prompt is recognized by the OS\'s own wording of its title and buttons in the Simulator\'s preferred languages; when the runner cannot read that wording, the prompt stays on screen as alert-unrecognized. A prompt that appears after open has already seen the app is not answered; use alert accept. A device another session is holding refuses at once; add --wait <ms> to block up to that budget for it and only then fail with DEVICE_IN_USE naming the owning session. On HarmonyOS, open reads the foreground app for up to 5s after dispatch. When the launched app never holds it, open succeeds with a warning that names open-not-foreground with the app that held the foreground, or that no mission is foreground; unlock and run the open again. A budget whose every read fails names open-foreground-probe-unreadable instead and claims nothing; check the connection. With --foreground, it fails with details.reason open-not-foreground or open-foreground-probe-unreadable.',
'Use --platform to bind URL/deep-link opens to the target platform. For local or Limrun iOS simulator initial stdout/stderr, put --launch-console <path> on this open command, for example agent-device open "Agent Device Tester" --platform ios --launch-console artifacts/launch-console.log. Expo Go/dev-client shells accept host + URL, for example agent-device open "Expo Go" exp://127.0.0.1:8081 --platform ios. macOS also supports --surface app|frontmost-app|desktop|menubar. --metro-host/--metro-port/--bundle-url choose the app\'s Metro server and save that address for later metro reload calls in the same session. A fresh open without Metro hints clears an older same-name binding; close also clears it. --launch-url supplies the app\'s launch URL; it does not select the reload server. A later open without these flags applies the hints and launch URL again only when it opens the same app; it opens another app without them. An open that passes hints for another app also removes the earlier hints from the app an earlier open applied them to. On an iOS simulator without --launch-url, open connects a detected Expo development client through its expo-development-client URL. The app must declare a single exp+<slug> scheme that no other installed app owns. If detection is inconclusive, the app opens normally. Bare React Native apps receive their server settings before launch. On an iOS simulator, when --launch-url raises an "Open in <App>?" prompt that keeps open from seeing the app, open accepts it if the URL scheme belongs to the session app (data.launchConfirmation: "accepted"); if the scheme belongs to another installed app, the prompt stays on screen and open fails with details.reason launch_confirmation_foreign_app; if the scheme owner cannot be resolved because no single installed app owns it or the lookup failed, the prompt stays on screen and open returns with data.launchConfirmation: "unanswered", launchConfirmationReason url-owner-unresolved, and a warning; a prompt that is seen but not recognized is reported the same way with launchConfirmationReason alert-unrecognized and its own warning; for url-owner-unresolved, answer the prompt with alert accept; for alert-unrecognized, read the alert with alert get first, because it can be the app\'s own alert (such as a permission prompt) rather than the launch confirmation, and answer with alert accept only when it is the launch confirmation; when agent-device cannot read whether a prompt is up at all (the alert read, the accept, or the runner itself failed, including after a re-hand of the URL), open stays green, reports no launchConfirmation plus data.launchConfirmationProbeFailure naming the failed step (alert-read, alert-accept, or runner), and appends a warning that says to check with alert get. The prompt is read whenever open cannot see the app afterwards, including on a slow host where the app\'s target discovery fails on its own deadline. When an accept leaves the app provably not running, open hands the same URL over once more and reads again; still not running, it fails with details.reason launch_confirmation_unanswered. When the runner reports its main-thread timeout for the accept and the prompt is still up, open presses Open again, but only when the time the open request has left covers a whole press and the read that checks it. A recognized prompt still visible after a failed accept, or once that time is gone, also fails with this reason, even if the app is running behind it; answer it with alert accept or alert dismiss. A simulator openurl that CoreSimulator never answers fails within 20s with details.reason ios-simulator-openurl-timeout. The prompt is recognized by the OS\'s own wording of its title and buttons in the Simulator\'s preferred languages; when the runner cannot read that wording, the prompt stays on screen as alert-unrecognized. A prompt that appears after open has already seen the app is not answered; use alert accept. A device another session is holding refuses at once; add --wait <ms> to block up to that budget for it and only then fail with DEVICE_IN_USE naming the owning session. On HarmonyOS, open reads the foreground app for up to 5s after dispatch. When the launched app never holds it, open succeeds with a warning that names open-not-foreground with the app that held the foreground, or that no mission is foreground; unlock and run the open again. A budget whose every read fails names open-foreground-probe-unreadable instead and claims nothing; check the connection. With --foreground, it fails with details.reason open-not-foreground or open-foreground-probe-unreadable.',
mcpDetail:
"metroHost, metroPort, and bundleUrl choose the app's Metro server and save its address for later reloads. launchUrl selects the app's launch URL and does not select the reload server. A later open without hints applies them again only when it opens the same app; it opens another app without them. A fresh open without Metro hints clears an older same-name binding; close also clears it.",
"metroHost, metroPort, and bundleUrl choose the app's Metro server and save its address for later reloads. launchUrl selects the app's launch URL and does not select the reload server. A later open without hints applies them again only when it opens the same app; it opens another app without them. An open that passes hints for another app also removes the earlier hints from the app an earlier open applied them to. A fresh open without Metro hints clears an older same-name binding; close also clears it.",
},
metadata: openCommandMetadata,
run: (client, input) => client.apps.open(toAppOpenOptions(input)),
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/application-lifecycle-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export type LaunchConfirmationAbsent = Readonly<{
}>;

type OpenApplicationOutcomeBase = Readonly<{
/** The app the open reached. The daemon reads it only when the input carried no `appBundleId`. */
appBundleId?: string;
timing: OpenApplicationTiming;
}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test('address reuse with the same record still starts a different lifetime', ()
assert.throws(() => store.update(old, { appName: 'Stale' }), ended);
assert.equal(store.retire(old), false);
assert.equal(store.get(ADDRESS), session);
assert.equal(store.getRuntimeHints(ADDRESS)?.metroPort, 8082);
assert.equal(store.getRuntimeHints(ADDRESS)?.hints?.metroPort, 8082);
assert.equal(store.retire(successor), true);
assert.equal(store.getRuntimeHints(ADDRESS), undefined);
});
Expand Down
6 changes: 1 addition & 5 deletions packages/daemon/src/core/session-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,7 @@ export class SessionStore {
return Array.from(this.sessions, ([address, entry]) => this.captureRef(address, entry));
}

getRuntimeHints(name: string): SessionRuntimeHints | undefined {
return this.runtimeHints.get(name)?.hints;
}

getStoredRuntimeHints(name: string): StoredRuntimeHints | undefined {
getRuntimeHints(name: string): StoredRuntimeHints | undefined {
return this.runtimeHints.get(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ test.each([false, true])(
values: retired ? {} : { metroHost: 'scoped.example', metroPort: '8082' },
});
expect(sessionStore.resolveCurrent(publicRef)).toBe(publicRef.session);
expect(sessionStore.getRuntimeHints('default')).toEqual({
expect(sessionStore.getRuntimeHints('default')?.hints).toEqual({
metroHost: 'public.example',
metroPort: 8083,
});
if (successor) {
expect(sessionStore.resolveCurrent(successor)).toBe(successor.session);
expect(sessionStore.getRuntimeHints(address)).toEqual({
expect(sessionStore.getRuntimeHints(address)?.hints).toEqual({
metroHost: 'successor.example',
metroPort: 8084,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/src/server/http/daemon-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async function startDaemonRuntimeOnHost(
const session = sessionStore.resolveCurrent(ref) ?? ref.session;
const sessionName = ref.address;
const runtimeHints = runtimeHintsClearInput(
sessionStore.getStoredRuntimeHints(sessionName),
sessionStore.getRuntimeHints(sessionName),
session.appBundleId,
);
await teardownSessionResources({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ test('an idle settle cannot finalize or retire a replacement at its scoped addre
assert.equal(successor.session.scriptPublication.status, 'complete');
}
assert.equal(successor.session.actions.length, 0);
assert.equal(sessionStore.getRuntimeHints(address)?.metroPort, 9090);
assert.equal(sessionStore.getRuntimeHints(address)?.hints?.metroPort, 9090);
assert.equal(sessionStore.readIdleExpiryTombstone(address), undefined);
} finally {
release();
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/src/server/http/server-shutdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export async function teardownDaemonSessionForShutdown(params: {
const current = sessionStore.resolveCurrent(ref);
const session = current ?? ref.session;
const runtimeHints = runtimeHintsClearInput(
current ? sessionStore.getStoredRuntimeHints(ref.address) : undefined,
current ? sessionStore.getRuntimeHints(ref.address) : undefined,
session.appBundleId,
);
const timeoutMs = resolveDaemonSessionTeardownTimeoutMs(session);
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/src/server/request-execution-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ async function teardownExpiredSession(params: {
const session = sessionStore.resolveCurrent(ref) ?? ref.session;
const sessionName = ref.address;
const runtimeHints = runtimeHintsClearInput(
sessionStore.getStoredRuntimeHints(ref.address),
sessionStore.getRuntimeHints(ref.address),
session.appBundleId,
);
let primaryError: unknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ test.each(['rebuild', 'retire'] as const)(
}
} else {
expect(result).toMatchObject({ error: { details: { reason: 'session_lifetime_ended' } } });
expect(store.getRuntimeHints('default')).toEqual({ metroPort: 8083 });
expect(store.getRuntimeHints('default')?.hints).toEqual({ metroPort: 8083 });
}
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ test('runtime clear rejects a false runtime-hints fact before its one implementa
expect(mockInspectDeviceRuntimeFacts).toHaveBeenCalledTimes(1);
expect(mockBindDeviceRuntime).not.toHaveBeenCalled();
expect(mockClearRuntimeHints).not.toHaveBeenCalled();
expect(sessionStore.getRuntimeHints(sessionName)).toEqual({
expect(sessionStore.getRuntimeHints(sessionName)?.hints).toEqual({
platform: 'android',
metroHost: '10.0.0.10',
metroPort: 8081,
Expand Down Expand Up @@ -370,7 +370,7 @@ for (const phase of ['admission', 'effect'] as const) {
code: 'COMMAND_FAILED',
details: { reason: 'session_lifetime_ended' },
});
expect(sessionStore.getRuntimeHints(address)).toBe(successorHints);
expect(sessionStore.getRuntimeHints(address)?.hints).toBe(successorHints);
expect(refFrameState(sessionStore.get(address)!)).toBe('active');
expect(mockClearRuntimeHints).toHaveBeenCalledTimes(phase === 'admission' ? 0 : 1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export function createReplaySession(
const reads = {
get: () => store.get(name),
lookup: () => store.lookup(name),
getRuntimeHints: () => store.getRuntimeHints(name),
getRuntimeHints: () => store.getRuntimeHints(name)?.hints,
ensureSessionDir: () => store.ensureSessionDir(name),
};
let captureCell:
Expand Down
32 changes: 14 additions & 18 deletions packages/daemon/src/sessions/handlers/session-runtime-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { DaemonPlatformServices } from '../../core/platform-services.ts';
import type { DaemonRequest } from '../../core/daemon-request.ts';
import { publicPlatformString } from '@agent-device/kernel/device';
import { clearRuntimeHintsRuntimeUse } from '@agent-device/contracts/application-lifecycle-runtime-plan';
import { SessionStore } from '../../core/session-store.ts';
import type { SessionRef } from '../../core/session-state.ts';
import { SessionStore, type StoredRuntimeHints } from '../../core/session-store.ts';
import type { SessionRef, SessionRuntimeHints } from '../../core/session-state.ts';
import { expireRefFrame } from '../../core/ref-frame.ts';
import { admitRuntimeUse } from '../../core/runtime-admission.ts';
import {
Expand Down Expand Up @@ -76,23 +76,23 @@ export async function handleRuntimeCommand(params: {
}
const ref = sessionStore.lookup(sessionName);
const session = ref?.session;
const current = sessionStore.getRuntimeHints(sessionName);
const stored = sessionStore.getRuntimeHints(sessionName);
if (action === 'clear') {
return await clearRuntimeCommand({
sessionName,
sessionStore,
ref,
current,
stored,
inspectFacts: params.inspectFacts,
platformServices: params.platformServices,
bindDevice: params.bindDevice,
});
}
if (action === 'show') {
return showRuntimeCommand(sessionName, current);
return showRuntimeCommand(sessionName, stored?.hints);
}

return setRuntimeCommand({ req, sessionName, sessionStore, session, current });
return setRuntimeCommand({ req, sessionName, sessionStore, session, stored });
}

async function readGestureViewport(params: {
Expand Down Expand Up @@ -133,15 +133,14 @@ async function clearRuntimeCommand(params: {
sessionName: string;
sessionStore: SessionStore;
ref: SessionRef | undefined;
current: ReturnType<SessionStore['getRuntimeHints']>;
stored: StoredRuntimeHints | undefined;
inspectFacts?: InspectDeviceRuntimeFacts;
platformServices: DaemonPlatformServices;
bindDevice?: BindDeviceRuntime;
}): Promise<DaemonResponse> {
const { sessionName, sessionStore, ref, current, inspectFacts, bindDevice, platformServices } =
const { sessionName, sessionStore, ref, stored, inspectFacts, bindDevice, platformServices } =
params;
const session = ref ? sessionStore.requireCurrent(ref) : undefined;
const stored = sessionStore.getStoredRuntimeHints(sessionName);
if (session && requiresRuntimeHintsClear(runtimeHintsClearInput(stored, session.appBundleId))) {
const admission = await admitClearRuntime({
device: session.device,
Expand All @@ -158,14 +157,14 @@ async function clearRuntimeCommand(params: {
runtimeHintsClearInput(stored, currentSession.appBundleId),
);
}
const cleared = ref ? sessionStore.clearRuntimeHints(ref) : Boolean(current);
const cleared = ref ? sessionStore.clearRuntimeHints(ref) : Boolean(stored);
if (!ref) sessionStore.setRuntimeHints(sessionName, undefined);
return { ok: true, data: { session: sessionName, cleared } };
}

function showRuntimeCommand(
sessionName: string,
current: ReturnType<SessionStore['getRuntimeHints']>,
current: SessionRuntimeHints | undefined,
): DaemonResponse {
return {
ok: true,
Expand All @@ -188,9 +187,10 @@ function setRuntimeCommand(params: {
sessionName: string;
sessionStore: SessionStore;
session: ReturnType<SessionStore['get']>;
current: ReturnType<SessionStore['getRuntimeHints']>;
stored: StoredRuntimeHints | undefined;
}): DaemonResponse {
const { req, sessionName, sessionStore, session, current } = params;
const { req, sessionName, sessionStore, session, stored } = params;
const current = stored?.hints;
// approach (b): resolve the session's PUBLIC leaf platform (ios/macos), never the
// internal `apple`, so the legacy `--platform ios` selector still matches.
const sessionLeaf = sessionLeafPlatform(session);
Expand All @@ -214,11 +214,7 @@ function setRuntimeCommand(params: {
'runtime set requires at least one hint such as --metro-host, --metro-port, --bundle-url, or --launch-url.',
);
}
sessionStore.setRuntimeHints(
sessionName,
nextRuntime,
sessionStore.getStoredRuntimeHints(sessionName)?.appId,
);
sessionStore.setRuntimeHints(sessionName, nextRuntime, stored?.appId);
return {
ok: true,
data: {
Expand Down
Loading
Loading