xcobra 0.0.2 → 0.0.4

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.
Files changed (3) hide show
  1. package/README.md +80 -329
  2. package/dist/index.js +353 -125
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,19 +1,18 @@
1
1
  # $ bunx xcobra
2
2
 
3
- A full toolkit for **headless iOS agent development** and automation. Build apps, interact with simulators, capture screens, and control UI—all from the command line.
3
+ A toolkit for **iOS simulator automation** and development. Build apps, capture screens, record video, and debug via LLDB—all from the command line.
4
4
 
5
5
  <img width="1530" height="738" alt="xcobra" src="https://github.com/user-attachments/assets/802373aa-2e5e-4c68-8c61-3b751c9b44b2" />
6
6
 
7
7
  ## Features
8
8
 
9
- - 🤖 **Headless Agent Toolkit**: Complete set of commands for building AI agents that interact with iOS simulators
10
- - **Pretty Build Output**: Clean, colored formatting for xcodebuild operations
11
- - 📱 **Simulator Control**: Tap, swipe, type, press buttons, and more
12
- - 📸 **Screen Capture**: Screenshots and video recording
13
- - 🌳 **Accessibility Tree**: Query UI elements as XML for element targeting
14
- - 📝 **Log Streaming**: Real-time simulator logs with app filtering
15
- - 💥 **Crash Reports**: Parse and display iOS crash reports with symbolicated backtraces
16
- - 🚀 **Zero Config**: Works as a drop-in replacement for xcodebuild
9
+ - **Pretty Build Output**: Clean, colored formatting for xcodebuild operations
10
+ - **Screen Capture**: Screenshots and video recording via simctl
11
+ - **View Hierarchy**: Get UIKit view hierarchy via LLDB debugging
12
+ - **Heap Analysis**: Chrome DevTools-like heap snapshots
13
+ - **Log Streaming**: Real-time simulator logs with app filtering
14
+ - **Crash Reports**: Parse and display iOS crash reports with symbolicated backtraces
15
+ - **Zero Config**: Works as a drop-in replacement for xcodebuild
17
16
 
18
17
  ## Prerequisites
19
18
 
@@ -23,17 +22,6 @@ A full toolkit for **headless iOS agent development** and automation. Build apps
23
22
  xcode-select --install
24
23
  ```
25
24
 
26
- ### AXe (Apple Accessibility CLI)
27
-
28
- This toolkit requires [AXe](https://github.com/cameroncooke/AXe) for simulator interaction commands. Install via Homebrew:
29
-
30
- ```sh
31
- brew tap cameroncooke/axe
32
- brew install axe
33
- ```
34
-
35
- AXe provides low-level access to iOS Simulator accessibility APIs, enabling touch simulation, keyboard input, hardware button presses, and screen capture.
36
-
37
25
  ## Installation
38
26
 
39
27
  ```sh
@@ -44,58 +32,20 @@ npx xcobra <args>
44
32
  npm install -g xcobra
45
33
  ```
46
34
 
47
- ## Quick Start for Agent Development
35
+ ## Quick Start
48
36
 
49
37
  ```sh
50
- # 1. Build your app
51
- npx xcobra -project MyApp.xcodeproj -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 16' build
52
-
53
- # 2. Get the accessibility tree (for element targeting)
54
- npx xcobra sim xml
55
-
56
- # 3. Tap on an element by label
57
- npx xcobra sim tap --label "Sign In"
58
-
59
- # 4. Type text
60
- npx xcobra sim type "hello@example.com"
38
+ # Build your app
39
+ npx xcobra build -project MyApp.xcodeproj -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 16'
61
40
 
62
- # 5. Take a screenshot
41
+ # Take a screenshot
63
42
  npx xcobra sim screenshot --output ./screenshot.png
64
- ```
65
-
66
- ### Example: Finding and Tapping a Button
67
-
68
- First, get the accessibility tree to discover elements:
69
-
70
- ```sh
71
- npx xcobra sim xml
72
- ```
73
-
74
- This outputs XML like:
75
-
76
- ```xml
77
- <AXApplication label="MyApp" enabled="true">
78
- <AXWindow>
79
- <AXScrollView>
80
- <AXButton label="Sign In" enabled="true" x="147" y="680" width="120" height="44" />
81
- <AXTextField label="Email" value="" x="40" y="320" width="334" height="44" />
82
- <AXSecureTextField label="Password" value="" x="40" y="380" width="334" height="44" />
83
- </AXScrollView>
84
- </AXWindow>
85
- </AXApplication>
86
- ```
87
43
 
88
- Then tap the button using any of these methods:
44
+ # Record video
45
+ npx xcobra sim record-video --output ./recording.mp4
89
46
 
90
- ```sh
91
- # By label (recommended for readability)
92
- npx xcobra sim tap --label "Sign In"
93
-
94
- # By coordinates (from x/y attributes)
95
- npx xcobra sim tap --x 207 --y 702
96
-
97
- # By accessibility identifier (if set in code)
98
- npx xcobra sim tap --id "signInButton"
47
+ # Get view hierarchy (auto-detects running app)
48
+ npx xcobra sim hierarchy
99
49
  ```
100
50
 
101
51
  ---
@@ -104,16 +54,7 @@ npx xcobra sim tap --id "signInButton"
104
54
 
105
55
  All simulator commands automatically detect the booted simulator. Use `--udid <UDID>` to target a specific device.
106
56
 
107
- ### Accessibility & UI Inspection
108
-
109
- #### `sim xml` — Get Accessibility Tree
110
-
111
- Output the full accessibility tree as XML for UI element discovery and targeting:
112
-
113
- ```sh
114
- npx xcobra sim xml
115
- npx xcobra sim xml --udid <SIMULATOR_UDID>
116
- ```
57
+ ### Device Listing
117
58
 
118
59
  #### `sim list` — List Simulators
119
60
 
@@ -121,154 +62,100 @@ Display all available iOS simulators:
121
62
 
122
63
  ```sh
123
64
  npx xcobra sim list
65
+ npx xcobra sim list --json
124
66
  ```
125
67
 
126
- ### Touch & Gestures
68
+ ### Screenshots & Video
127
69
 
128
- #### `sim tap` — Tap on Screen
70
+ #### `sim screenshot` — Capture Screenshot
129
71
 
130
- Tap at coordinates or on accessibility elements:
72
+ Capture the simulator display as PNG:
131
73
 
132
74
  ```sh
133
- # Tap at coordinates
134
- npx xcobra sim tap --x 100 --y 200
135
-
136
- # Tap element by accessibility identifier
137
- npx xcobra sim tap --id "loginButton"
138
-
139
- # Tap element by label
140
- npx xcobra sim tap --label "Sign In"
75
+ # Auto-generated filename
76
+ npx xcobra sim screenshot
141
77
 
142
- # With delays (seconds)
143
- npx xcobra sim tap --x 100 --y 200 --pre-delay 1.0 --post-delay 0.5
78
+ # Custom output path
79
+ npx xcobra sim screenshot --output ~/Desktop/screenshot.png
144
80
  ```
145
81
 
146
- #### `sim swipe` — Swipe Gesture
82
+ #### `sim record-video` — Record Video
147
83
 
148
- Execute swipe gestures with configurable start/end points:
84
+ Record simulator video:
149
85
 
150
86
  ```sh
151
- # Basic swipe
152
- npx xcobra sim swipe --start-x 100 --start-y 500 --end-x 100 --end-y 200
87
+ # Basic recording (press Ctrl+C to stop)
88
+ npx xcobra sim record-video --output recording.mp4
153
89
 
154
- # Slow swipe with custom duration
155
- npx xcobra sim swipe --start-x 50 --start-y 500 --end-x 350 --end-y 500 --duration 2.0
90
+ # With codec option
91
+ npx xcobra sim record-video --output recording.mp4 --codec hevc
156
92
  ```
157
93
 
158
- #### `sim touch` — Low-level Touch Control
159
-
160
- Fine-grained touch down/up events for complex gestures:
161
-
162
- ```sh
163
- # Touch down
164
- npx xcobra sim touch --x 150 --y 250 --down
165
-
166
- # Touch up
167
- npx xcobra sim touch --x 150 --y 250 --up
168
-
169
- # Touch down, wait, then up
170
- npx xcobra sim touch --x 150 --y 250 --down --up --delay 1.0
171
- ```
94
+ ### View Hierarchy (LLDB)
172
95
 
173
- #### `sim gesture` — Preset Gestures
96
+ #### `sim hierarchy` — Get UIKit View Hierarchy
174
97
 
175
- Common gesture patterns:
98
+ Get the full UIKit view hierarchy via LLDB, similar to Xcode's view debugger:
176
99
 
177
100
  ```sh
178
- npx xcobra sim gesture scroll-up
179
- npx xcobra sim gesture scroll-down
180
- npx xcobra sim gesture scroll-left
181
- npx xcobra sim gesture scroll-right
182
- npx xcobra sim gesture swipe-from-left-edge
183
- npx xcobra sim gesture swipe-from-right-edge
184
- npx xcobra sim gesture swipe-from-top-edge
185
- npx xcobra sim gesture swipe-from-bottom-edge
186
-
187
- # With delays
188
- npx xcobra sim gesture scroll-down --pre-delay 1.0 --post-delay 0.5
189
- ```
190
-
191
- ### Text Input
192
-
193
- #### `sim type` — Type Text
194
-
195
- Input text with automatic keyboard handling:
101
+ # Get view hierarchy (auto-detects running app)
102
+ npx xcobra sim hierarchy
196
103
 
197
- ```sh
198
- # Direct text input
199
- npx xcobra sim type "Hello World!"
104
+ # Get view controller hierarchy
105
+ npx xcobra sim hierarchy --controllers
200
106
 
201
- # From stdin
202
- echo "Complex text" | npx xcobra sim type --stdin
107
+ # Get Auto Layout constraint trace
108
+ npx xcobra sim hierarchy --constraints
203
109
 
204
- # From file
205
- npx xcobra sim type --file input.txt
110
+ # Or target a specific app
111
+ npx xcobra sim hierarchy --bundle-id com.example.myapp
206
112
  ```
207
113
 
208
- ### Hardware Buttons
114
+ **Note**: The hierarchy command attaches LLDB to the running app, which briefly pauses execution. Only works with debuggable apps (not system apps).
209
115
 
210
- #### `sim button` — Press Hardware Buttons
116
+ ### Heap Memory Analysis
211
117
 
212
- Simulate hardware button presses:
118
+ #### `sim heap` — Chrome DevTools-like Heap Snapshots
213
119
 
214
- ```sh
215
- npx xcobra sim button home
216
- npx xcobra sim button lock
217
- npx xcobra sim button side-button
218
- npx xcobra sim button siri
219
- npx xcobra sim button apple-pay
220
-
221
- # Long press
222
- npx xcobra sim button lock --duration 2.0
223
- ```
120
+ Analyze heap memory using LLDB:
224
121
 
225
- ### Keyboard Control
122
+ ```sh
123
+ # Get heap summary (auto-detects running app)
124
+ npx xcobra sim heap summary
226
125
 
227
- #### `sim key` Press Individual Key
126
+ # Take a full heap snapshot
127
+ npx xcobra sim heap snapshot --output snapshot.json
228
128
 
229
- Press keys by HID keycode:
129
+ # Inspect a specific object by address
130
+ npx xcobra sim heap inspect 0x7f8b12345678
230
131
 
231
- ```sh
232
- npx xcobra sim key 40 # Enter key
233
- npx xcobra sim key 42 --duration 1.0 # Long press
132
+ # Or target a specific app
133
+ npx xcobra sim heap summary --bundle-id com.example.myapp
234
134
  ```
235
135
 
236
- #### `sim key-sequence` — Press Key Sequence
136
+ ### Keyboard
237
137
 
238
- Execute multiple keycodes in sequence:
138
+ #### `sim keyboard` Toggle Software Keyboard
239
139
 
240
140
  ```sh
241
- npx xcobra sim key-sequence --keycodes 11,8,15,15,18 # Types "hello"
141
+ npx xcobra sim keyboard
242
142
  ```
243
143
 
244
- ### Screenshots & Video
144
+ ### Logging
245
145
 
246
- #### `sim screenshot` — Capture Screenshot
146
+ #### `sim log` — Stream Logs
247
147
 
248
- Capture the simulator display as PNG:
148
+ Stream logs from the simulator:
249
149
 
250
150
  ```sh
251
- # Auto-generated filename
252
- npx xcobra sim screenshot
253
-
254
- # Custom output path
255
- npx xcobra sim screenshot --output ~/Desktop/screenshot.png
256
-
257
- # Output to directory (auto-generates filename)
258
- npx xcobra sim screenshot --output ~/Desktop/
259
- ```
260
-
261
- #### `sim record-video` — Record Video
262
-
263
- Record simulator video to MP4:
151
+ # All logs from booted simulator
152
+ npx xcobra sim log
264
153
 
265
- ```sh
266
- # Basic recording (press Ctrl+C to stop)
267
- npx xcobra sim record-video --output recording.mp4
154
+ # Filter by app bundle identifier
155
+ npx xcobra sim log --app-id com.example.myapp
268
156
 
269
- # With options
270
- npx xcobra sim record-video --output recording.mp4 --fps 30
271
- npx xcobra sim record-video --output low-bandwidth.mp4 --fps 10 --quality 60 --scale 0.5
157
+ # Specific simulator
158
+ npx xcobra sim log --udid <SIMULATOR_UDID>
272
159
  ```
273
160
 
274
161
  ### Appearance
@@ -283,26 +170,6 @@ xcrun simctl ui booted appearance dark
283
170
 
284
171
  # Set to light mode
285
172
  xcrun simctl ui booted appearance light
286
-
287
- # Target specific simulator
288
- xcrun simctl ui <UDID> appearance dark
289
- ```
290
-
291
- ### Logging
292
-
293
- #### `sim log` — Stream Logs
294
-
295
- Stream logs from the simulator:
296
-
297
- ```sh
298
- # All logs from booted simulator
299
- npx xcobra sim log
300
-
301
- # Filter by app bundle identifier
302
- npx xcobra sim log --app-id com.example.myapp
303
-
304
- # Specific simulator
305
- npx xcobra sim log --udid <SIMULATOR_UDID>
306
173
  ```
307
174
 
308
175
  ---
@@ -329,22 +196,6 @@ npx xcobra crash list
329
196
  npx xcobra crash list --json
330
197
  ```
331
198
 
332
- Example output:
333
-
334
- ```
335
- Found 5 crash report(s):
336
-
337
- RouterE2E
338
- Bundle ID: com.expo.routere2e
339
- Date: 12/31/2025, 12:14:36 PM
340
- Path: /Users/.../RouterE2E-2025-12-31-121436.ips
341
-
342
- MyApp
343
- Bundle ID: com.example.myapp
344
- Date: 12/30/2025, 3:45:22 PM
345
- Path: /Users/.../MyApp-2025-12-30-154522.ips
346
- ```
347
-
348
199
  ### `crash <path>` — View Specific Crash
349
200
 
350
201
  Display a specific crash report file:
@@ -367,98 +218,6 @@ The formatted output includes:
367
218
  - **Other Threads**: Condensed backtraces showing top 5 frames
368
219
  - **Binary Images**: App-related dylibs with UUIDs for symbolication
369
220
 
370
- Example output:
371
-
372
- ```
373
- ────────────────────────────────────────────────────────────────────────────────
374
- CRASH REPORT: RouterE2E
375
- ────────────────────────────────────────────────────────────────────────────────
376
-
377
- Process Information:
378
- Process: RouterE2E
379
- Bundle ID: com.expo.routere2e
380
- Version: 0.0.0 (1)
381
-
382
- Exception Information:
383
- Type: EXC_BAD_ACCESS (SIGSEGV)
384
- Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
385
-
386
- ────────────────────────────────────────────────────────────────────────────────
387
- CRASHED THREAD 0 (com.apple.main-thread)
388
- ────────────────────────────────────────────────────────────────────────────────
389
- 0 RouterE2E.debug.dylib 0x0000000104c90b94 +[SentrySDKInternal crash] + 20 (SentrySDKInternal.m:701)
390
- 1 RouterE2E.debug.dylib 0x0000000104d67f6c static SentrySDK.crash() + 44 (SentrySDK.swift:339)
391
- 2 RouterE2E.debug.dylib 0x0000000104b45b7c +[SentrySDKWrapper crash] + 36 (SentrySDKWrapper.m:15)
392
- 3 RouterE2E.debug.dylib 0x0000000104b33104 -[RNSentry crash] + 36 (RNSentry.mm:713)
393
- ...
394
- ```
395
-
396
- ---
397
-
398
- ## Agent Debugging Workflow
399
-
400
- When building AI agents that interact with iOS apps, crashes are inevitable. Here's how to use the crash commands to debug issues:
401
-
402
- ### 1. Detect a Crash
403
-
404
- When your agent's action causes an unexpected app termination:
405
-
406
- ```sh
407
- # Check if there's a recent crash
408
- npx xcobra crash list
409
- ```
410
-
411
- ### 2. Analyze the Crash
412
-
413
- View the crash details to understand what went wrong:
414
-
415
- ```sh
416
- # View the latest crash
417
- npx xcobra crash
418
-
419
- # Or get JSON for programmatic analysis
420
- npx xcobra crash --json
421
- ```
422
-
423
- ### 3. Identify the Root Cause
424
-
425
- The crash report shows:
426
-
427
- - **Exception type**: `EXC_BAD_ACCESS` = memory issue, `EXC_CRASH` = uncaught exception
428
- - **Crashed thread backtrace**: Shows exactly where the crash occurred with source file:line
429
- - **Binary images**: Which frameworks/libraries were involved
430
-
431
- ### 4. Example: Agent Workflow with Crash Detection
432
-
433
- ```sh
434
- # Agent attempts an action
435
- npx xcobra sim tap --label "Submit"
436
-
437
- # Check if app is still responsive by getting UI tree
438
- npx xcobra sim xml
439
-
440
- # If the above fails or returns empty, check for crash
441
- npx xcobra crash --json | jq '.header.app_name, .body.exception.type'
442
- ```
443
-
444
- ### 5. Automated Crash Monitoring
445
-
446
- For continuous agent operation, monitor crashes programmatically:
447
-
448
- ```sh
449
- # Get crash data as JSON for parsing
450
- CRASH_DATA=$(npx xcobra crash --json)
451
-
452
- # Extract key information
453
- echo "$CRASH_DATA" | jq '{
454
- app: .header.app_name,
455
- time: .body.captureTime,
456
- exception: .body.exception.type,
457
- signal: .body.exception.signal,
458
- reason: .body.termination.indicator
459
- }'
460
- ```
461
-
462
221
  ---
463
222
 
464
223
  ## Build Commands
@@ -467,11 +226,11 @@ Standard xcodebuild commands with pretty-formatted output:
467
226
 
468
227
  ```sh
469
228
  # Build a project
470
- npx xcobra -project MyApp.xcodeproj -scheme MyApp -configuration Debug build
229
+ npx xcobra build -project MyApp.xcodeproj -scheme MyApp -configuration Debug
471
230
 
472
231
  # Build for simulator
473
- npx xcobra -project MyApp.xcodeproj -scheme MyApp \
474
- -destination 'platform=iOS Simulator,name=iPhone 16' build
232
+ npx xcobra build -project MyApp.xcodeproj -scheme MyApp \
233
+ -destination 'platform=iOS Simulator,name=iPhone 16'
475
234
 
476
235
  # Show version (raw output)
477
236
  npx xcobra -version
@@ -491,22 +250,15 @@ Build logs are automatically saved to `.xcodebuild/xcodebuild.log`.
491
250
 
492
251
  ### Simulator Commands
493
252
 
494
- | Command | Description |
495
- | ------------------ | ------------------------------------- |
496
- | `sim xml` | Get accessibility tree as XML |
497
- | `sim list` | List all simulators |
498
- | `sim tap` | Tap at coordinates or on element |
499
- | `sim swipe` | Swipe gesture |
500
- | `sim touch` | Low-level touch down/up |
501
- | `sim gesture` | Preset gestures (scroll, edge swipes) |
502
- | `sim type` | Type text |
503
- | `sim button` | Press hardware buttons |
504
- | `sim key` | Press individual key by keycode |
505
- | `sim key-sequence` | Press sequence of keys |
506
- | `sim screenshot` | Capture screenshot |
507
- | `sim record-video` | Record video |
508
- | `sim log` | Stream simulator logs |
509
- | `xcrun simctl ui` | Toggle appearance (dark/light mode) |
253
+ | Command | Description |
254
+ | ---------------- | ------------------------------------- |
255
+ | `sim list` | List all simulators |
256
+ | `sim screenshot` | Capture screenshot |
257
+ | `sim record-video` | Record video |
258
+ | `sim hierarchy` | Get UIKit view hierarchy via LLDB |
259
+ | `sim heap` | Heap memory analysis |
260
+ | `sim keyboard` | Toggle software keyboard |
261
+ | `sim log` | Stream simulator logs |
510
262
 
511
263
  ### Crash Report Commands
512
264
 
@@ -517,7 +269,6 @@ Build logs are automatically saved to `.xcodebuild/xcodebuild.log`.
517
269
  | `crash list` | List recent crash reports |
518
270
  | `crash <path>` | Display specific crash report |
519
271
  | `crash --json` | Output crash data as JSON |
520
- | `crash list --json` | Output crash list as JSON |
521
272
 
522
273
  ---
523
274
 
@@ -531,7 +282,7 @@ bun install
531
282
  bun run build
532
283
 
533
284
  # Test locally
534
- ./dist/index.js sim xml
285
+ ./dist/index.js sim list
535
286
  ```
536
287
 
537
288
  Claude Code + xcode, brah