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 packages/capture-kit/src/app-log-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ const APP_LOG_RESOURCE_KIND = 'app-log' as const;
export function createAppLogStartResult(
handle: AppLogLiveHandle,
envelope: DurableResourceEnvelope<typeof APP_LOG_RESOURCE_KIND>,
options: Readonly<{ relaunched?: boolean }> = {},
): AppLogStartResult {
return Object.freeze({ pendingHandle: new PendingTransferGuard(handle), envelope });
return Object.freeze({
pendingHandle: new PendingTransferGuard(handle),
envelope,
...(options.relaunched ? { relaunched: true as const } : {}),
});
}

type AppLogRecoveryContext = Readonly<{
Expand Down
2 changes: 2 additions & 0 deletions packages/command-output/src/observability/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type LogsActionFields = {
marked?: true;
cleared?: true;
restarted?: true;
relaunched?: true;
removedRotatedFiles?: number;
};

Expand Down Expand Up @@ -48,6 +49,7 @@ const LOG_ACTION_FIELD_KEYS = [
'marked',
'cleared',
'restarted',
'relaunched',
'removedRotatedFiles',
] as const satisfies readonly (keyof LogsActionFields)[];

Expand Down
2 changes: 1 addition & 1 deletion packages/command-surface/src/observability/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const AUDIO_ACTION_VALUES = ['probe'] as const;
const AUDIO_PROBE_ACTION_VALUES = ['start', 'status', 'stop'] as const;

const logsCommandDescription =
'Session app log info, start/stop streaming, diagnostics, and markers';
'Session app log info, start/stop streaming, diagnostics, and markers. On iOS physical devices, starting the stream relaunches the session app and reports relaunched: true, and stopping the stream ends the app.';
const eventsCommandDescription =
'Read the daemon-owned session event timeline as paged JSON-friendly entries';
const networkCommandDescription = 'Dump recent HTTP(s) traffic parsed from the session app log';
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/app-log-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export type AppLogStartInput = Readonly<{
export type AppLogStartResult = Readonly<{
pendingHandle: PendingTransferGuard<AppLogLiveHandle>;
envelope: DurableResourceEnvelope<typeof APP_LOG_RESOURCE_KIND>;
/** Set when the capture relaunched the session app to attach to it; stopping it ends the app. */
relaunched?: true;
}>;

type AppLogReattachInput = Readonly<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ test('logs clear --restart finishes generation one before adopting generation tw
});
});

test.each([
{ relaunched: true, expected: { relaunched: true } },
{ relaunched: false, expected: {} },
])(
'logs start reports relaunched only when the start relaunched the app ($relaunched)',
async ({ relaunched, expected }) => {
runtime = createRuntimeHarness({ relaunched });
const { sessionStore, sessionName } = openSession();
const started = await runLogs(sessionStore, sessionName, ['start'], {}, runtime.bindDevice);
expect(started).toEqual({
ok: true,
data: { path: expect.any(String), started: true, ...expected },
});
},
);

test('cancellation after native start persists recovery truth and cleans the pending handle', async () => {
const { sessionStore, sessionName } = openSession();
const response = await runLogs(
Expand Down Expand Up @@ -355,6 +371,7 @@ function createRuntimeHarness(
options: {
inspectAvailable?: boolean;
inspectFact?: RuntimeOperationFact;
relaunched?: boolean;
} = {},
) {
const owner = localRuntimeOwner('apple');
Expand Down Expand Up @@ -394,7 +411,7 @@ function createRuntimeHarness(
lifecycle: 'open',
descriptor: { version: 1, body: { outputPath: input.outputPath } },
});
return createAppLogStartResult(handle, envelope);
return createAppLogStartResult(handle, envelope, { relaunched: options.relaunched });
});
const operations: DeviceBinding<PlatformRuntimeOperations>['operations'] = {
appLogInspect: inspect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ async function startSessionAppLog(
envelope: result.envelope,
throwIfCanceled: params.throwIfCanceled ?? (() => {}),
});
return { ok: true, data: { path: outputPath, started: true } };
return {
ok: true,
data: { path: outputPath, started: true, ...(result.relaunched ? { relaunched: true } : {}) },
};
} catch (error) {
const normalized = recordSessionAppLogFailure({
ref: params.ref,
Expand Down
41 changes: 41 additions & 0 deletions packages/platform-apple/src/logs/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,47 @@ test('simulator start cancelled before the stream launches terminates the proces
expect(fixture.outputDisposed()).toBe(true);
});

test.each([
{
name: 'a CoreDevice physical iOS device',
device: appleDevice({ kind: 'device', iosPhysicalDeviceBackend: 'coredevice' }),
relaunched: true,
},
{ name: 'a host macOS target', device: appleDevice({ appleOs: 'macos', kind: 'device' }) },
])('start on $name reports relaunched only for devicectl console capture', async (scenario) => {
const fixture = hostFixture({
appleToolRun: async () => ({
stdout: 'USAGE: devicectl device process launch --console --terminate-existing',
stderr: '',
exitCode: 0,
}),
});

const started = await startAppleAppLogs(
fixture.host,
scenario.device,
startInput(),
localRuntimeOwner('apple'),
);

expect(started.relaunched).toBe(scenario.relaunched);
if (scenario.relaunched) expect(fixture.backgroundCommands[0]).toContain('--terminate-existing');
});

test('simulator start does not report relaunched', async () => {
const stream = launchingStream({ exited: true });
const fixture = hostFixture({ startProcess: stream.start, sleep: sleepUntilAborted });

const started = await startAppleAppLogs(
fixture.host,
appleDevice(),
startInput(),
localRuntimeOwner('apple'),
);

expect(started.relaunched).toBeUndefined();
});

function startInput() {
return {
sessionId: 'session',
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-apple/src/logs/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export async function startAppleAppLogs(
fence: input.fence,
descriptor,
}),
// devicectl --console --terminate-existing relaunches the app, and devicectl forwards the
// stop signal to the app, which ends it.
{ relaunched: backend === 'ios-device' },
);
adopted = true;
return result;
Expand Down
10 changes: 10 additions & 0 deletions src/__tests__/cli-help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ test('appstate --help prints command help and skips daemon dispatch', async () =
assert.doesNotMatch(result.stdout, /Global Flags:/);
});

test('help logs discloses the physical iOS device relaunch on start and app end on stop', async () => {
const result = await runCliCapture(['help', 'logs']);
assert.equal(result.code, 0);
assert.equal(result.calls.length, 0);
assert.match(
result.stdout,
/On iOS physical devices, starting the stream relaunches the session app and reports relaunched: true, and stopping the stream ends the app\./,
);
});

test('prepare help documents iOS runner CI setup', async () => {
const result = await runCliCapture(['help', 'prepare']);
assert.equal(result.code, 0);
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/cli-logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ test('logs clear prints action metadata and forwards --restart flag', async () =
assert.match(result.stderr, /restarted=true/);
assert.match(result.stderr, /removedRotatedFiles=2/);
});

test('logs start prints the physical-device relaunch disclosure', async () => {
const result = await runCliCapture(['logs', 'start'], async () => ({
ok: true,
data: { path: '/tmp/app.log', started: true, relaunched: true },
}));

assert.equal(result.code, null);
assert.match(result.stderr, /started=true/);
assert.match(result.stderr, /relaunched=true/);
});
6 changes: 5 additions & 1 deletion src/commands/schema/cli-help-workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ test('usageForCommand resolves debugging help topic', async () => {
if (help === null) throw new Error('Expected debugging help text');
assert.match(help, /^agent-device \S+ — debugging/);
assert.match(help, /Use logs when you need the lead-up timeline/);
assert.match(help, /relaunches the session app through devicectl process launch --console/);
assert.match(
help,
/logs start and logs clear --restart relaunch the session app through devicectl process launch --console/,
);
assert.match(help, /logs stop ends the app/);
assert.match(help, /Use debug symbols when you have crash\.ips\/crash\.log/);
assert.match(help, /Use Xcode\/LLDB when you need live state/);
assert.match(help, /debug symbols --artifact crash\.ips --search-path \.\/build/);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/schema/cli-help-workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Logs:
Do not cat a full stale log into agent context. Open or grep only the relevant window when needed.
logs clear --restart is the compact command to clear old logs and start a fresh capture; do not split it into logs stop, logs clear, logs start.
On iOS simulators, logs scope by bundle id and resolved app executable, so use this instead of raw simctl log stream predicates.
On iOS physical devices, logs clear --restart relaunches the session app through devicectl process launch --console so stdout/stderr can be captured.
On iOS physical devices, logs start and logs clear --restart relaunch the session app through devicectl process launch --console so stdout/stderr can be captured; logs start reports relaunched: true. logs stop ends the app.
For iOS simulator launch-time stdout/stderr, use --launch-console on the direct app launch:
agent-device open MyApp --platform ios --relaunch --launch-console ./artifacts/app.console.log
--launch-console is only for local or Limrun iOS simulator app launches, not URL opens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async function assertMetrics(context: LiveContext): Promise<void> {
async function assertLogs(context: LiveContext): Promise<void> {
const started = await runStep(context, 'start Android fixture logcat stream', ['logs', 'start']);
assert.equal(started.json?.data?.started, true, JSON.stringify(started.json));
assert.equal(started.json?.data?.relaunched, undefined, JSON.stringify(started.json));
assert.ok(fs.existsSync(String(started.json?.data?.path)), JSON.stringify(started.json));
const inspected = await runStep(context, 'inspect Android fixture logcat stream', [
'logs',
Expand Down
1 change: 1 addition & 0 deletions test/integration/ios-simulator-e2e/live-full-scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export async function assertObservabilityAndArtifacts(context: LiveContext): Pro

const logsStart = await runStep(context, 'start fixture log stream', ['logs', 'start']);
assert.equal(logsStart.json?.data?.started, true, JSON.stringify(logsStart.json));
assert.equal(logsStart.json?.data?.relaunched, undefined, JSON.stringify(logsStart.json));
assert.ok(fs.existsSync(String(logsStart.json?.data?.path)), JSON.stringify(logsStart.json));
const logsPath = await runStep(context, 'inspect fixture log stream', ['logs', 'path']);
assert.equal(logsPath.json?.data?.active, true, JSON.stringify(logsPath.json));
Expand Down
1 change: 1 addition & 0 deletions website/docs/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ agent-device network dump 25 --include headers --platform web # Browser requests
```

- `logs` works on iOS simulators, iOS physical devices, Android, and macOS (app-scoped Unified Logging). On iOS, capture relies on Unified Logging (`os_log`); plain stdout/stderr may be limited.
- On iOS physical devices, `logs start` relaunches the session app through `devicectl device process launch --console --terminate-existing` and reports `relaunched: true`; `logs stop` ends the app. Run `open <app>` again after `logs stop` to keep using it. Other targets do not report `relaunched`.
- `logs start` appends to `app.log` and rotates at 5 MB. Override with `AGENT_DEVICE_APP_LOG_MAX_BYTES` and `AGENT_DEVICE_APP_LOG_MAX_FILES`; set `AGENT_DEVICE_APP_LOG_REDACT_PATTERNS` to a comma-separated regex list for write-time redaction. Commas inside a `{m,n}` quantifier, `[...]`, or `(...)` stay in their pattern; write `\,` for any other literal comma. If a pattern does not compile, `logs start` fails with `INVALID_ARGS`, `details.reason: "app_log_redact_pattern_invalid"`, and the zero-based `details.patternIndex` of that comma-separated field (empty fields count); the pattern text is not echoed. On Apple simulators, `logs start` returns once the simulator log stream is running, so lines that the app logs after that are captured. If the stream does not start within 10 s, `logs start` fails with `details.reason: "simulator-log-stream-launch-timeout"`.
- `open` prints `Session state: <path>`; see [Sessions](/docs/sessions#find-a-sessions-logs-and-artifacts) for the files it contains.
- `events` reads the session timeline, which leaves out user-entered content; `--no-record` suppresses `action.recorded` entries. `events.ndjson` rotates before an entry would exceed 5 MiB (`AGENT_DEVICE_EVENT_LOG_MAX_BYTES`) and keeps one generation. Cursors stay valid across rotation; a cursor older than the retained window fails with `details.reason: "EVENT_LOG_CURSOR_EXPIRED"` and `details.earliestCursor`. If the retained files were edited or deleted, `events` fails with `details.reason: "EVENT_LOG_WINDOW_UNVERIFIED"`.
Expand Down
Loading