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
2 changes: 1 addition & 1 deletion src/core/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppError } from '../utils/errors.ts';
import type { BatchStep, CommandFlags } from './dispatch.ts';

export const DEFAULT_BATCH_MAX_STEPS = 100;
export const BATCH_BLOCKED_COMMANDS = new Set(['batch', 'replay']);
const BATCH_BLOCKED_COMMANDS = new Set(['batch', 'replay']);

export type NormalizedBatchStep = {
command: string;
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/is-predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { SnapshotState } from '../utils/snapshot.ts';
import { extractNodeText } from './snapshot-processing.ts';
import { isNodeEditable, isNodeVisible } from './selectors.ts';

export type IsPredicate = 'visible' | 'hidden' | 'exists' | 'editable' | 'selected' | 'text';
type IsPredicate = 'visible' | 'hidden' | 'exists' | 'editable' | 'selected' | 'text';

export function isSupportedPredicate(input: string): input is IsPredicate {
return ['visible', 'hidden', 'exists', 'editable', 'selected', 'text'].includes(input);
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/scroll-planner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { centerOfRect, type RawSnapshotNode, type Rect } from '../utils/snapshot.ts';

export type ScrollIntoViewPlan = {
type ScrollIntoViewPlan = {
x: number;
startY: number;
endY: number;
Expand Down
8 changes: 4 additions & 4 deletions src/daemon/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type SelectorTerm = {
value: string | boolean;
};

export type Selector = {
type Selector = {
raw: string;
terms: SelectorTerm[];
};
Expand All @@ -31,12 +31,12 @@ export type SelectorChain = {
selectors: Selector[];
};

export type SelectorDiagnostics = {
type SelectorDiagnostics = {
selector: string;
matches: number;
};

export type SelectorResolution = {
type SelectorResolution = {
node: SnapshotNode;
selector: Selector;
selectorIndex: number;
Expand Down Expand Up @@ -233,7 +233,7 @@ export function isNodeEditable(node: SnapshotNode, platform: 'ios' | 'android'):

export function buildSelectorChainForNode(
node: SnapshotNode,
platform: 'ios' | 'android',
_platform: 'ios' | 'android',
options: { action?: 'click' | 'fill' | 'get' } = {},
): string[] {
const chain: string[] = [];
Expand Down
10 changes: 5 additions & 5 deletions src/daemon/snapshot-diff.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { SnapshotNode } from '../utils/snapshot.ts';
import { buildSnapshotDisplayLines, displayLabel, formatRole, formatSnapshotLine } from '../utils/snapshot-lines.ts';

export type SnapshotDiffLine = {
type SnapshotDiffLine = {
kind: 'added' | 'removed' | 'unchanged';
text: string;
};

export type SnapshotDiffSummary = {
type SnapshotDiffSummary = {
additions: number;
removals: number;
unchanged: number;
};

export type SnapshotDiffResult = {
type SnapshotDiffResult = {
summary: SnapshotDiffSummary;
lines: SnapshotDiffLine[];
};

export type SnapshotDiffOptions = {
type SnapshotDiffOptions = {
flatten?: boolean;
};

Expand All @@ -26,7 +26,7 @@ type SnapshotComparableLine = {
comparable: string;
};

export function snapshotNodeToComparableLine(node: SnapshotNode, depthOverride?: number): string {
function snapshotNodeToComparableLine(node: SnapshotNode, depthOverride?: number): string {
const role = formatRole(node.type ?? 'Element');
const textPart = displayLabel(node, role);
const enabledPart = node.enabled === false ? 'disabled' : 'enabled';
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/android/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function listAndroidDevices(): Promise<DeviceInfo[]> {
return devices;
}

export async function isAndroidBooted(serial: string): Promise<boolean> {
async function isAndroidBooted(serial: string): Promise<boolean> {
try {
const result = await readAndroidBootProp(serial);
return result.stdout.trim() === '1';
Expand Down
6 changes: 3 additions & 3 deletions src/platforms/android/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function adbArgs(device: DeviceInfo, args: string[]): string[] {
return ['-s', device.id, ...args];
}

export async function resolveAndroidApp(
async function resolveAndroidApp(
device: DeviceInfo,
app: string,
): Promise<{ type: 'intent' | 'package'; value: string }> {
Expand Down Expand Up @@ -320,7 +320,7 @@ export async function closeAndroidApp(device: DeviceInfo, app: string): Promise<
await runCmd('adb', adbArgs(device, ['shell', 'am', 'force-stop', resolved.value]));
}

export async function uninstallAndroidApp(
async function uninstallAndroidApp(
device: DeviceInfo,
app: string,
): Promise<{ package: string }> {
Expand All @@ -342,7 +342,7 @@ export async function uninstallAndroidApp(
return { package: resolved.value };
}

export async function installAndroidApp(device: DeviceInfo, appPath: string): Promise<void> {
async function installAndroidApp(device: DeviceInfo, appPath: string): Promise<void> {
await runCmd('adb', adbArgs(device, ['install', appPath]));
}

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/boot-diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { asAppError } from '../utils/errors.ts';

export type BootFailureReason =
type BootFailureReason =
| 'IOS_BOOT_TIMEOUT'
| 'IOS_RUNNER_CONNECT_TIMEOUT'
| 'IOS_TOOL_MISSING'
Expand Down
4 changes: 1 addition & 3 deletions src/platforms/ios/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEnvTruthy, TIMEOUT_PROFILES } from '../../utils/retry.ts';
import { TIMEOUT_PROFILES } from '../../utils/retry.ts';
import { resolveTimeoutMs } from '../../utils/timeouts.ts';

export const IOS_BOOT_TIMEOUT_MS = resolveTimeoutMs(
Expand All @@ -24,5 +24,3 @@ export const IOS_DEVICECTL_TIMEOUT_MS = resolveTimeoutMs(
20_000,
1_000,
);

export const RETRY_LOGS_ENABLED = isEnvTruthy(process.env.AGENT_DEVICE_RETRY_LOGS);
16 changes: 2 additions & 14 deletions src/platforms/ios/runner-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { bootFailureHint, classifyBootFailure } from '../boot-diagnostics.ts';
import { resolveTimeoutMs, resolveTimeoutSeconds } from '../../utils/timeouts.ts';
import { isRequestCanceled } from '../../daemon/request-cancel.ts';

export type RunnerCommand = {
type RunnerCommand = {
command:
| 'tap'
| 'tapSeries'
Expand Down Expand Up @@ -58,7 +58,7 @@ export type RunnerCommand = {
clearFirst?: boolean;
};

export type RunnerSession = {
type RunnerSession = {
device: DeviceInfo;
deviceId: string;
port: number;
Expand Down Expand Up @@ -116,18 +116,6 @@ const RUNNER_STOP_WAIT_TIMEOUT_MS = 10_000;
const RUNNER_SHUTDOWN_TIMEOUT_MS = 15_000;
const RUNNER_DERIVED_ROOT = path.join(os.homedir(), '.agent-device', 'ios-runner');

export type RunnerSnapshotNode = {
index: number;
type?: string;
label?: string;
value?: string;
identifier?: string;
rect?: { x: number; y: number; width: number; height: number };
enabled?: boolean;
hittable?: boolean;
depth?: number;
};

export async function runIosRunnerCommand(
device: DeviceInfo,
command: RunnerCommand,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type FlagKey,
} from './command-schema.ts';

export type ParsedArgs = {
type ParsedArgs = {
command: string | null;
positionals: string[];
flags: CliFlags;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/command-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type CliFlags = {
};

export type FlagKey = keyof CliFlags;
export type FlagType = 'boolean' | 'int' | 'enum' | 'string' | 'booleanOrString';
type FlagType = 'boolean' | 'int' | 'enum' | 'string' | 'booleanOrString';

export type FlagDefinition = {
key: FlagKey;
Expand All @@ -54,7 +54,7 @@ export type FlagDefinition = {
usageDescription?: string;
};

export type CommandSchema = {
type CommandSchema = {
description: string;
positionalArgs: readonly string[];
allowsExtraPositionals?: boolean;
Expand All @@ -80,7 +80,7 @@ const SELECTOR_SNAPSHOT_FLAGS = [

const FIND_SNAPSHOT_FLAGS = ['snapshotDepth', 'snapshotRaw'] as const satisfies readonly FlagKey[];

export const FLAG_DEFINITIONS: readonly FlagDefinition[] = [
const FLAG_DEFINITIONS: readonly FlagDefinition[] = [
{
key: 'platform',
names: ['--platform'],
Expand Down Expand Up @@ -354,7 +354,7 @@ export const GLOBAL_FLAG_KEYS = new Set<FlagKey>([
'noRecord',
]);

export const COMMAND_SCHEMAS: Record<string, CommandSchema> = {
const COMMAND_SCHEMAS: Record<string, CommandSchema> = {
boot: {
description: 'Ensure target device/simulator is booted and ready',
positionalArgs: [],
Expand Down
6 changes: 3 additions & 3 deletions src/utils/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { AppError } from './errors.ts';
import { isInteractive } from './interactive.ts';
import { isCancel, select } from '@clack/prompts';

export type Platform = 'ios' | 'android';
export type DeviceKind = 'simulator' | 'emulator' | 'device';
type Platform = 'ios' | 'android';
type DeviceKind = 'simulator' | 'emulator' | 'device';

export type DeviceInfo = {
platform: Platform;
Expand All @@ -13,7 +13,7 @@ export type DeviceInfo = {
booted?: boolean;
};

export type DeviceSelector = {
type DeviceSelector = {
platform?: Platform;
deviceName?: string;
udid?: string;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';

export type DiagnosticLevel = 'info' | 'warn' | 'error' | 'debug';
type DiagnosticLevel = 'info' | 'warn' | 'error' | 'debug';

export type DiagnosticEvent = {
type DiagnosticEvent = {
ts: string;
level: DiagnosticLevel;
phase: string;
Expand All @@ -17,7 +17,7 @@ export type DiagnosticEvent = {
data?: Record<string, unknown>;
};

export type DiagnosticsScopeOptions = {
type DiagnosticsScopeOptions = {
session?: string;
requestId?: string;
command?: string;
Expand All @@ -40,7 +40,7 @@ export function createRequestId(): string {
return crypto.randomBytes(8).toString('hex');
}

export function createDiagnosticId(): string {
function createDiagnosticId(): string {
return `${Date.now().toString(36)}-${crypto.randomBytes(4).toString('hex')}`;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { redactDiagnosticData } from './diagnostics.ts';

export type ErrorCode =
type ErrorCode =
| 'INVALID_ARGS'
| 'DEVICE_NOT_FOUND'
| 'TOOL_MISSING'
Expand All @@ -12,7 +12,7 @@ export type ErrorCode =
| 'UNAUTHORIZED'
| 'UNKNOWN';

export type AppErrorDetails = Record<string, unknown> & {
type AppErrorDetails = Record<string, unknown> & {
hint?: string;
diagnosticId?: string;
logPath?: string;
Expand Down
14 changes: 2 additions & 12 deletions src/utils/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type ExecResult = {
stdoutBuffer?: Buffer;
};

export type ExecOptions = {
type ExecOptions = {
cwd?: string;
env?: NodeJS.ProcessEnv;
allowFailure?: boolean;
Expand All @@ -18,7 +18,7 @@ export type ExecOptions = {
detached?: boolean;
};

export type ExecStreamOptions = ExecOptions & {
type ExecStreamOptions = ExecOptions & {
onStdoutChunk?: (chunk: string) => void;
onStderrChunk?: (chunk: string) => void;
onSpawn?: (child: ReturnType<typeof spawn>) => void;
Expand Down Expand Up @@ -320,16 +320,6 @@ export function runCmdBackground(
return { child, wait };
}

export function whichCmdSync(cmd: string): boolean {
try {
const { shell, args } = resolveWhichArgs(cmd);
const result = runCmdSync(shell, args, { allowFailure: true });
return result.exitCode === 0 && result.stdout.trim().length > 0;
} catch {
return false;
}
}

function resolveWhichArgs(cmd: string): { shell: string; args: string[] } {
if (process.platform === 'win32') {
return { shell: 'cmd.exe', args: ['/c', 'where', cmd] };
Expand Down
4 changes: 2 additions & 2 deletions src/utils/finders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type { SnapshotNode } from './snapshot.ts';

export type FindLocator = 'any' | 'text' | 'label' | 'value' | 'role' | 'id';

export type FindMatchOptions = {
type FindMatchOptions = {
requireRect?: boolean;
};

export type FindBestMatches = {
type FindBestMatches = {
matches: SnapshotNode[];
score: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/interactors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type RunnerContext = {
traceLogPath?: string;
};

export type Interactor = {
type Interactor = {
open(app: string, options?: { activity?: string; appBundleId?: string; url?: string }): Promise<void>;
openDevice(): Promise<void>;
close(app: string): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppError, normalizeError, type NormalizedError } from './errors.ts';
import { buildSnapshotDisplayLines, formatSnapshotLine } from './snapshot-lines.ts';
import type { SnapshotNode } from './snapshot.ts';

export type JsonResult =
type JsonResult =
| { success: true; data?: Record<string, unknown> }
| {
success: false;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ type RetryOptions = {
shouldRetry?: (error: unknown, attempt: number) => boolean;
};

export type RetryPolicy = {
type RetryPolicy = {
maxAttempts: number;
baseDelayMs: number;
maxDelayMs: number;
jitter: number;
shouldRetry?: (error: unknown, attempt: number) => boolean;
};

export type RetryAttemptContext = {
type RetryAttemptContext = {
attempt: number;
maxAttempts: number;
deadline?: Deadline;
};

export type TimeoutProfile = {
type TimeoutProfile = {
startupMs: number;
operationMs: number;
totalMs: number;
};

export type RetryTelemetryEvent = {
type RetryTelemetryEvent = {
phase?: string;
event: 'attempt_failed' | 'retry_scheduled' | 'succeeded' | 'exhausted';
attempt: number;
Expand Down
Loading
Loading