@limrun/api 0.71.1 → 0.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ios-client.ts CHANGED
@@ -162,6 +162,8 @@ export type ElementTreeNode = {
162
162
  AXUniqueId?: string | null;
163
163
  AXValue?: string | null;
164
164
  children?: ElementTreeNode[];
165
+ /** True when visibleOnly omitted offscreen descendants of this container. */
166
+ has_offscreen_children?: boolean;
165
167
  content_required: boolean;
166
168
  custom_actions: string[];
167
169
  enabled: boolean;
@@ -178,6 +180,11 @@ export type ElementTreeNode = {
178
180
 
179
181
  export type ElementTree = ElementTreeNode[];
180
182
 
183
+ export type ElementTreeOptions = {
184
+ /** Skip branches whose nonempty frames fall outside the display. Full-tree reads only. Defaults to false. */
185
+ visibleOnly?: boolean;
186
+ };
187
+
181
188
  export type ElementTreeResultMessage = {
182
189
  type: 'elementTreeResult';
183
190
  id: string;
@@ -320,6 +327,12 @@ export type DeviceInfo = {
320
327
  screenHeight: number;
321
328
  /** Device model name */
322
329
  model: string;
330
+ /** Current interface orientation, when the simulator can report it. */
331
+ orientation?: 'portrait' | 'portraitUpsideDown' | 'landscapeLeft' | 'landscapeRight';
332
+ /** Current display width in points, accounting for orientation. */
333
+ displayWidth?: number;
334
+ /** Current display height in points, accounting for orientation. */
335
+ displayHeight?: number;
323
336
  /** Simulator OS version, e.g. "26.4" */
324
337
  osVersion?: string;
325
338
  };
@@ -754,14 +767,14 @@ export type InstanceClient = {
754
767
  * @param point Optional point to get the element at that specific location
755
768
  * @returns A promise that resolves to the parsed accessibility tree
756
769
  */
757
- elementTree: (point?: AccessibilityPoint) => Promise<ElementTree>;
770
+ elementTree: (point?: AccessibilityPoint, options?: ElementTreeOptions) => Promise<ElementTree>;
758
771
 
759
772
  /**
760
773
  * Get the raw element tree string returned by the server.
761
774
  * @param point Optional point to get the element at that specific location
762
775
  * @returns A promise that resolves to the raw accessibility tree payload
763
776
  */
764
- elementTreeRaw: (point?: AccessibilityPoint) => Promise<string>;
777
+ elementTreeRaw: (point?: AccessibilityPoint, options?: ElementTreeOptions) => Promise<string>;
765
778
 
766
779
  /**
767
780
  * Tap at the specified coordinates on the active screen (uses native screen dimensions)
@@ -1322,6 +1335,26 @@ export type InstanceClient = {
1322
1335
  */
1323
1336
  simctl: (args: string[], opts?: SimctlOptions) => SimctlExecution;
1324
1337
 
1338
+ /**
1339
+ * Run Xcode's LLDB inside the simulator, attached to an app when `bundleId` or `pid` is given.
1340
+ * LLDB can debug the simulator's apps built with the `get-task-allow` entitlement, which
1341
+ * Xcode adds to debug builds.
1342
+ *
1343
+ * @param args Arguments passed to `lldb`, such as `['--batch', '-o', 'bt']`
1344
+ * @param opts Which process to attach to and how standard input is fed
1345
+ * @returns An LldbExecution handle for output and, with `keepStdinOpen`, live input
1346
+ *
1347
+ * @example
1348
+ * ```typescript
1349
+ * // One-shot: print a backtrace and detach
1350
+ * const result = await client
1351
+ * .lldb(['--batch', '-o', 'bt', '-o', 'detach'], { bundleId: 'com.example.app' })
1352
+ * .wait();
1353
+ * console.log(result.stdout);
1354
+ * ```
1355
+ */
1356
+ lldb: (args: string[], opts?: LldbOptions) => LldbExecution;
1357
+
1325
1358
  /**
1326
1359
  * Push a local file to the simulator. Returns the path of the file on the simulator host
1327
1360
  * that can be used in simctl commands.
@@ -1463,10 +1496,12 @@ export type InstanceClient = {
1463
1496
  lsof: () => Promise<LsofEntry[]>;
1464
1497
 
1465
1498
  /**
1466
- * Device information fetched during client initialization.
1499
+ * Device information fetched during client initialization and refreshed by getDeviceInfo().
1467
1500
  * Contains id, udid, screen dimensions, and model.
1468
1501
  */
1469
1502
  deviceInfo: DeviceInfo;
1503
+ /** Fetch current device info without reading the accessibility tree; refreshes deviceInfo. */
1504
+ getDeviceInfo: () => Promise<DeviceInfo>;
1470
1505
  };
1471
1506
 
1472
1507
  /**
@@ -1552,6 +1587,36 @@ type SimctlRequest = {
1552
1587
  stdin?: string;
1553
1588
  };
1554
1589
 
1590
+ /**
1591
+ * Options for an LLDB session
1592
+ */
1593
+ export type LldbOptions = {
1594
+ /** Attach to the running app with this bundle ID. */
1595
+ bundleId?: string;
1596
+ /** Attach to this process of the simulator. */
1597
+ pid?: number;
1598
+ /** Commands written to LLDB's standard input before anything sent with `write`. */
1599
+ stdin?: string | Buffer;
1600
+ /**
1601
+ * Keep standard input open for `write` and `end`. Without it LLDB runs its arguments and
1602
+ * `stdin`, then exits.
1603
+ */
1604
+ keepStdinOpen?: boolean;
1605
+ /** Disconnect from the instance when LLDB exits */
1606
+ disconnectOnExit?: boolean;
1607
+ };
1608
+
1609
+ type LldbRequest = {
1610
+ type: 'lldb';
1611
+ id: string;
1612
+ args: string[];
1613
+ bundleId?: string;
1614
+ pid?: number;
1615
+ /** Base64 of LLDB's initial standard input */
1616
+ stdin?: string;
1617
+ keepStdinOpen?: boolean;
1618
+ };
1619
+
1555
1620
  /**
1556
1621
  * Generic server response with optional error
1557
1622
  */
@@ -1598,6 +1663,9 @@ type ServerResponse = {
1598
1663
  screenHeight?: number;
1599
1664
  model?: string;
1600
1665
  osVersion?: string;
1666
+ orientation?: DeviceInfo['orientation'];
1667
+ displayWidth?: number;
1668
+ displayHeight?: number;
1601
1669
  // Simctl streaming fields
1602
1670
  stdout?: string;
1603
1671
  stderr?: string;
@@ -1793,6 +1861,65 @@ export class SimctlExecution extends EventEmitter {
1793
1861
  }
1794
1862
  }
1795
1863
 
1864
+ /**
1865
+ * Handle for a running LLDB session. It streams output like a simctl execution, and takes
1866
+ * commands on standard input when the session was started with `keepStdinOpen`.
1867
+ *
1868
+ * @example
1869
+ * ```typescript
1870
+ * const session = client.lldb([], { bundleId: 'com.example.app', keepStdinOpen: true });
1871
+ * session.on('stdout', (data) => process.stdout.write(data));
1872
+ * session.write('bt\n');
1873
+ * session.end(); // LLDB detaches and exits once it has read everything
1874
+ * await session.wait();
1875
+ * ```
1876
+ */
1877
+ export class LldbExecution extends SimctlExecution {
1878
+ private sendInput: (data: Buffer | undefined, close: boolean, sequence: number) => void;
1879
+ private started = false;
1880
+ private held: Array<[Buffer | undefined, boolean, number]> = [];
1881
+ private sequence = 0;
1882
+
1883
+ constructor(
1884
+ stopCallback: () => void,
1885
+ sendInput: (data: Buffer | undefined, close: boolean, sequence: number) => void,
1886
+ ) {
1887
+ super(stopCallback);
1888
+ this.sendInput = sendInput;
1889
+ }
1890
+
1891
+ /** Write to LLDB's standard input. End each command with a newline. */
1892
+ write(data: string | Buffer): void {
1893
+ this.input(Buffer.from(data), false);
1894
+ }
1895
+
1896
+ /** Close LLDB's standard input. LLDB detaches from the process and exits. */
1897
+ end(): void {
1898
+ this.input(undefined, true);
1899
+ }
1900
+
1901
+ // The instance drops input for a session it has not started yet, so input waits for the
1902
+ // session's first frame. Each write is numbered: the instance handles the messages of a
1903
+ // connection concurrently and uses the number to apply them in order.
1904
+ private input(data: Buffer | undefined, close: boolean): void {
1905
+ const sequence = this.sequence++;
1906
+ if (this.started) {
1907
+ this.sendInput(data, close, sequence);
1908
+ } else {
1909
+ this.held.push([data, close, sequence]);
1910
+ }
1911
+ }
1912
+
1913
+ /** @internal - The instance sent the session's first frame, so LLDB is reading its input */
1914
+ _handleStarted(): void {
1915
+ if (this.started) return;
1916
+ this.started = true;
1917
+ for (const [data, close, sequence] of this.held.splice(0)) {
1918
+ this.sendInput(data, close, sequence);
1919
+ }
1920
+ }
1921
+ }
1922
+
1796
1923
  export type PerformanceStreamOptions = {
1797
1924
  /** The instance's status.apiUrl. */
1798
1925
  apiUrl: string;
@@ -2181,6 +2308,9 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
2181
2308
  screenHeight: msg.screenHeight!,
2182
2309
  model: msg.model!,
2183
2310
  osVersion: msg.osVersion,
2311
+ orientation: msg.orientation,
2312
+ displayWidth: msg.displayWidth,
2313
+ displayHeight: msg.displayHeight,
2184
2314
  }),
2185
2315
  openUrlResult: () => undefined,
2186
2316
  appInstallationResult: (msg) => ({
@@ -2253,6 +2383,9 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
2253
2383
  logger.debug(`Received simctl stream for unknown execution: ${message.id}`);
2254
2384
  return;
2255
2385
  }
2386
+ if (execution instanceof LldbExecution) {
2387
+ execution._handleStarted();
2388
+ }
2256
2389
 
2257
2390
  if (message.stdout) {
2258
2391
  try {
@@ -2436,6 +2569,7 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
2436
2569
  getConnectionState,
2437
2570
  onConnectionStateChange,
2438
2571
  simctl,
2572
+ lldb,
2439
2573
  xcrun,
2440
2574
  startXcrunShim,
2441
2575
  xcodebuild,
@@ -2447,6 +2581,7 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
2447
2581
  clearCameraVideo,
2448
2582
  lsof,
2449
2583
  deviceInfo: cachedDeviceInfo,
2584
+ getDeviceInfo,
2450
2585
  });
2451
2586
  }
2452
2587
  });
@@ -2460,12 +2595,18 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
2460
2595
  return sendRequest<ScreenshotData>('screenshot', options);
2461
2596
  };
2462
2597
 
2463
- const elementTree = (point?: AccessibilityPoint): Promise<ElementTree> => {
2464
- return sendRequest<ElementTree>('elementTree', { point });
2598
+ const elementTree = (
2599
+ point?: AccessibilityPoint,
2600
+ options: ElementTreeOptions = {},
2601
+ ): Promise<ElementTree> => {
2602
+ return sendRequest<ElementTree>('elementTree', { point, ...options });
2465
2603
  };
2466
2604
 
2467
- const elementTreeRaw = (point?: AccessibilityPoint): Promise<string> => {
2468
- return sendRequest<string>('elementTree', { point }, (msg) => msg.json ?? '');
2605
+ const elementTreeRaw = (
2606
+ point?: AccessibilityPoint,
2607
+ options: ElementTreeOptions = {},
2608
+ ): Promise<string> => {
2609
+ return sendRequest<string>('elementTree', { point, ...options }, (msg) => msg.json ?? '');
2469
2610
  };
2470
2611
 
2471
2612
  const tap = (x: number, y: number): Promise<void> => {
@@ -3136,33 +3277,30 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
3136
3277
  return sendRequest<DeviceInfo>('deviceInfo');
3137
3278
  };
3138
3279
 
3280
+ const getDeviceInfo = async (): Promise<DeviceInfo> => {
3281
+ return Object.assign(cachedDeviceInfo, await fetchDeviceInfo());
3282
+ };
3283
+
3139
3284
  // Cached device info, populated during connection
3140
3285
  let cachedDeviceInfo: DeviceInfo;
3141
3286
 
3142
- const simctl = (args: string[], opts: SimctlOptions = {}): SimctlExecution => {
3143
- const id = generateId();
3144
-
3145
- const cancelCallback = () => {
3146
- // Clean up execution tracking
3147
- simctlExecutions.delete(id);
3148
- if (opts.disconnectOnExit) {
3149
- logger.debug(`Simctl execution ${id} cancelled, disconnecting due to disconnectOnExit`);
3150
- disconnect();
3151
- }
3152
- logger.debug(`Simctl execution ${id} cancelled`);
3153
- };
3154
-
3155
- const execution = new SimctlExecution(cancelCallback);
3287
+ /** Tracks a streamed command, sends its request, and returns the handle. */
3288
+ const startExecution = <E extends SimctlExecution>(
3289
+ id: string,
3290
+ execution: E,
3291
+ request: SimctlRequest | LldbRequest,
3292
+ disconnectOnExit: boolean | undefined,
3293
+ ): E => {
3156
3294
  simctlExecutions.set(id, execution);
3157
3295
 
3158
3296
  // If disconnectOnExit is enabled, register listeners before any async operations
3159
- if (opts.disconnectOnExit) {
3297
+ if (disconnectOnExit) {
3160
3298
  execution.once('exit', () => {
3161
- logger.debug(`Simctl execution ${id} finished, disconnecting due to disconnectOnExit`);
3299
+ logger.debug(`Execution ${id} finished, disconnecting due to disconnectOnExit`);
3162
3300
  disconnect();
3163
3301
  });
3164
3302
  execution.once('error', () => {
3165
- logger.debug(`Simctl execution ${id} errored, disconnecting due to disconnectOnExit`);
3303
+ logger.debug(`Execution ${id} errored, disconnecting due to disconnectOnExit`);
3166
3304
  disconnect();
3167
3305
  });
3168
3306
  }
@@ -3177,25 +3315,82 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
3177
3315
  return execution;
3178
3316
  }
3179
3317
 
3180
- const simctlRequest: SimctlRequest = {
3318
+ // stdin can carry secrets such as one-time codes, so it stays out of the log.
3319
+ logger.debug(`Sending ${request.type} request:`, { ...request, stdin: undefined });
3320
+ ws.send(JSON.stringify(request), (err?: Error) => {
3321
+ if (err) {
3322
+ logger.error(`Failed to send ${request.type} request:`, err);
3323
+ execution._handleError(err);
3324
+ simctlExecutions.delete(id);
3325
+ }
3326
+ });
3327
+
3328
+ return execution;
3329
+ };
3330
+
3331
+ /** Forgets a stopped command, and disconnects when its caller asked for that. */
3332
+ const stopExecution = (id: string, disconnectOnExit: boolean | undefined) => () => {
3333
+ simctlExecutions.delete(id);
3334
+ if (disconnectOnExit) {
3335
+ logger.debug(`Execution ${id} cancelled, disconnecting due to disconnectOnExit`);
3336
+ disconnect();
3337
+ }
3338
+ logger.debug(`Execution ${id} cancelled`);
3339
+ };
3340
+
3341
+ const simctl = (args: string[], opts: SimctlOptions = {}): SimctlExecution => {
3342
+ const id = generateId();
3343
+ const request: SimctlRequest = {
3181
3344
  type: 'simctl',
3182
3345
  ...(opts.envFromSecret && { envFromSecret: opts.envFromSecret }),
3183
3346
  id,
3184
3347
  args,
3185
3348
  ...(opts.stdin !== undefined && { stdin: Buffer.from(opts.stdin).toString('base64') }),
3186
3349
  };
3350
+ return startExecution(
3351
+ id,
3352
+ new SimctlExecution(stopExecution(id, opts.disconnectOnExit)),
3353
+ request,
3354
+ opts.disconnectOnExit,
3355
+ );
3356
+ };
3187
3357
 
3188
- // stdin can carry secrets such as one-time codes, so it stays out of the log.
3189
- logger.debug('Sending simctl request:', { ...simctlRequest, stdin: undefined });
3190
- ws.send(JSON.stringify(simctlRequest), (err?: Error) => {
3191
- if (err) {
3192
- logger.error('Failed to send simctl request:', err);
3193
- execution._handleError(err);
3358
+ const lldb = (args: string[], opts: LldbOptions = {}): LldbExecution => {
3359
+ const id = generateId();
3360
+ const sendInput = (data: Buffer | undefined, close: boolean, sequence: number) => {
3361
+ if (!ws || ws.readyState !== WebSocket.OPEN) return;
3362
+ ws.send(
3363
+ JSON.stringify({
3364
+ type: 'lldbInput',
3365
+ id,
3366
+ sequence,
3367
+ ...(data && { data: data.toString('base64') }),
3368
+ ...(close && { close }),
3369
+ }),
3370
+ );
3371
+ };
3372
+ const execution: LldbExecution = new LldbExecution(() => {
3373
+ // The session stays tracked: the instance answers with the exit of LLDB, which is what
3374
+ // ends `wait()`. A session dropped without `end` would otherwise keep the app stopped.
3375
+ if (!execution.isRunning) return;
3376
+ if (ws && ws.readyState === WebSocket.OPEN) {
3377
+ ws.send(JSON.stringify({ type: 'simctlTerminate', id }));
3378
+ } else {
3379
+ // Without a connection the instance has already ended the session and cannot say so.
3194
3380
  simctlExecutions.delete(id);
3381
+ execution._handleExit(143);
3195
3382
  }
3196
- });
3197
-
3198
- return execution;
3383
+ }, sendInput);
3384
+ const request: LldbRequest = {
3385
+ type: 'lldb',
3386
+ id,
3387
+ args,
3388
+ ...(opts.bundleId !== undefined && { bundleId: opts.bundleId }),
3389
+ ...(opts.pid !== undefined && { pid: opts.pid }),
3390
+ ...(opts.stdin !== undefined && { stdin: Buffer.from(opts.stdin).toString('base64') }),
3391
+ ...(opts.keepStdinOpen && { keepStdinOpen: true }),
3392
+ };
3393
+ return startExecution(id, execution, request, opts.disconnectOnExit);
3199
3394
  };
3200
3395
 
3201
3396
  const buildFilesUrl = (name: string, opts?: ContainerTargetOptions): string => {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.71.1'; // x-release-please-version
1
+ export const VERSION = '0.73.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.71.1";
1
+ export declare const VERSION = "0.73.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.71.1";
1
+ export declare const VERSION = "0.73.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.71.1'; // x-release-please-version
4
+ exports.VERSION = '0.73.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.71.1'; // x-release-please-version
1
+ export const VERSION = '0.73.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map