agentlane 0.0.0 → 0.4.0-rc.2

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 (146) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/LICENSE +27 -0
  3. package/README.md +167 -2
  4. package/dist/agents/claude-plugin.js +79 -0
  5. package/dist/agents/cli.js +258 -0
  6. package/dist/agents/detect.js +88 -0
  7. package/dist/agents/init.js +251 -0
  8. package/dist/agents/launcher.js +32 -0
  9. package/dist/agents/package.js +119 -0
  10. package/dist/agents/skills.js +59 -0
  11. package/dist/agents/toml.js +325 -0
  12. package/dist/agents/wiring-check.js +117 -0
  13. package/dist/agents/wiring.js +374 -0
  14. package/dist/bench/host.js +104 -0
  15. package/dist/bench/live.js +511 -0
  16. package/dist/bench/mcp-client.js +91 -0
  17. package/dist/bench/model.js +15 -0
  18. package/dist/bench/report.js +162 -0
  19. package/dist/bench/run.js +121 -0
  20. package/dist/bench/schedule.js +140 -0
  21. package/dist/bench/stats.js +59 -0
  22. package/dist/bench-cli.js +167 -0
  23. package/dist/browser/aria.js +184 -0
  24. package/dist/browser/control.js +203 -0
  25. package/dist/browser/env.js +118 -0
  26. package/dist/browser/evidence.js +44 -0
  27. package/dist/browser/install.js +361 -0
  28. package/dist/browser/kinds.js +10 -0
  29. package/dist/browser/lane-browser.js +224 -0
  30. package/dist/browser/libraries.js +56 -0
  31. package/dist/browser/paths.js +29 -0
  32. package/dist/browser/release.js +121 -0
  33. package/dist/browser/screen.js +19 -0
  34. package/dist/browser/signin.js +154 -0
  35. package/dist/browser/stop.js +163 -0
  36. package/dist/browser/tools.js +25 -0
  37. package/dist/cache/build.js +154 -0
  38. package/dist/cache/config.js +186 -0
  39. package/dist/cache/index.js +4 -0
  40. package/dist/cache/key.js +196 -0
  41. package/dist/cache/store.js +303 -0
  42. package/dist/cli.js +178 -0
  43. package/dist/clock.js +4 -0
  44. package/dist/devices/adb.js +160 -0
  45. package/dist/devices/android.js +214 -0
  46. package/dist/devices/backend.js +7 -0
  47. package/dist/devices/bundler.js +46 -0
  48. package/dist/devices/common.js +51 -0
  49. package/dist/devices/controls.js +65 -0
  50. package/dist/devices/dial.js +56 -0
  51. package/dist/devices/emulator.js +396 -0
  52. package/dist/devices/hygiene.js +202 -0
  53. package/dist/devices/index.js +5 -0
  54. package/dist/devices/launch.js +76 -0
  55. package/dist/devices/simctl.js +119 -0
  56. package/dist/devices/tools.js +1 -0
  57. package/dist/devices/variant.js +99 -0
  58. package/dist/devices/xcrun.js +265 -0
  59. package/dist/driver/absence.js +54 -0
  60. package/dist/driver/caller.js +51 -0
  61. package/dist/driver/client.js +312 -0
  62. package/dist/driver/diff.js +180 -0
  63. package/dist/driver/elements.js +70 -0
  64. package/dist/driver/engine-main.js +13 -0
  65. package/dist/driver/engine.js +499 -0
  66. package/dist/driver/errors.js +11 -0
  67. package/dist/driver/exec.js +66 -0
  68. package/dist/driver/failure.js +156 -0
  69. package/dist/driver/flow.js +94 -0
  70. package/dist/driver/idle.js +100 -0
  71. package/dist/driver/images.js +68 -0
  72. package/dist/driver/install.js +272 -0
  73. package/dist/driver/lock.js +101 -0
  74. package/dist/driver/look.js +223 -0
  75. package/dist/driver/maestro-child.js +194 -0
  76. package/dist/driver/maestro-runs.js +46 -0
  77. package/dist/driver/paths.js +105 -0
  78. package/dist/driver/pixels.js +144 -0
  79. package/dist/driver/plan.js +108 -0
  80. package/dist/driver/release.js +7 -0
  81. package/dist/driver/runner.js +42 -0
  82. package/dist/driver/selector.js +91 -0
  83. package/dist/driver/session.js +474 -0
  84. package/dist/driver/suggest.js +86 -0
  85. package/dist/driver/supervisor.js +251 -0
  86. package/dist/driver/tree.js +426 -0
  87. package/dist/driver-cli.js +865 -0
  88. package/dist/evidence/device.js +177 -0
  89. package/dist/evidence/evidence.js +304 -0
  90. package/dist/evidence/files.js +92 -0
  91. package/dist/hooks/env.js +81 -0
  92. package/dist/hooks/run.js +101 -0
  93. package/dist/mcp/server.js +69 -0
  94. package/dist/mcp/tools.js +246 -0
  95. package/dist/name.js +22 -0
  96. package/dist/plugin/aims.js +465 -0
  97. package/dist/plugin/conventions.js +73 -0
  98. package/dist/plugin/guard.js +163 -0
  99. package/dist/plugin/hook-cli.js +216 -0
  100. package/dist/plugin/session-name.js +28 -0
  101. package/dist/plugin/shell.js +254 -0
  102. package/dist/processes.js +77 -0
  103. package/dist/project/config.js +316 -0
  104. package/dist/project/schema.js +335 -0
  105. package/dist/project/validate.js +224 -0
  106. package/dist/registry/config.js +142 -0
  107. package/dist/registry/format.js +22 -0
  108. package/dist/registry/owner.js +265 -0
  109. package/dist/registry/paths.js +50 -0
  110. package/dist/registry/ports.js +26 -0
  111. package/dist/registry/prune.js +160 -0
  112. package/dist/registry/refusal.js +53 -0
  113. package/dist/registry/registry.js +1027 -0
  114. package/dist/registry/resources.js +117 -0
  115. package/dist/registry/rows.js +115 -0
  116. package/dist/registry/status.js +85 -0
  117. package/dist/registry/store.js +274 -0
  118. package/dist/registry/types.js +1 -0
  119. package/dist/registry-cli.js +544 -0
  120. package/dist/services/services.js +268 -0
  121. package/dist/services/system.js +189 -0
  122. package/dist/up/deps.js +1 -0
  123. package/dist/up/doctor.js +424 -0
  124. package/dist/up/exec.js +133 -0
  125. package/dist/up/lane-files.js +75 -0
  126. package/dist/up/lane-services.js +38 -0
  127. package/dist/up/maestro-env.js +172 -0
  128. package/dist/up/preflight.js +232 -0
  129. package/dist/up/release.js +148 -0
  130. package/dist/up/resources.js +178 -0
  131. package/dist/up/restart.js +87 -0
  132. package/dist/up/setup.js +28 -0
  133. package/dist/up/up.js +610 -0
  134. package/dist/up-cli.js +258 -0
  135. package/dist/usage.js +16 -0
  136. package/package.json +58 -3
  137. package/schema/agentlane.schema.json +675 -0
  138. package/skills/create-verification-skill/LICENSE +21 -0
  139. package/skills/create-verification-skill/SKILL.md +88 -0
  140. package/skills/dev-loop/LICENSE +21 -0
  141. package/skills/dev-loop/SKILL.md +61 -0
  142. package/skills/device/SKILL.md +8 -0
  143. package/skills/drive/SKILL.md +64 -0
  144. package/skills/maintain-verification-skill/LICENSE +21 -0
  145. package/skills/maintain-verification-skill/SKILL.md +42 -0
  146. package/skills/setup/SKILL.md +80 -0
@@ -0,0 +1,202 @@
1
+ import { DeviceStateError, requireBooted } from "./common.js";
2
+ import { formatCoordinate } from "./xcrun.js";
3
+ export const DEFAULT_FIXTURE_LOCATION = { latitude: 37.3349, longitude: -122.009 };
4
+ export const DEFAULT_APPEARANCE = 'light';
5
+ export const STATUS_BAR_PIN_FLAGS = [
6
+ '--time',
7
+ '09:41',
8
+ '--dataNetwork',
9
+ 'wifi',
10
+ '--wifiMode',
11
+ 'active',
12
+ '--wifiBars',
13
+ '3',
14
+ '--cellularMode',
15
+ 'active',
16
+ '--cellularBars',
17
+ '4',
18
+ '--batteryState',
19
+ 'charged',
20
+ '--batteryLevel',
21
+ '100',
22
+ ];
23
+ export const STATUS_BAR_PIN_FIELDS = {
24
+ Time: '09:41',
25
+ DataNetworkType: '11',
26
+ 'WiFi Mode': '3',
27
+ 'WiFi Bars': '3',
28
+ 'Cell Mode': '3',
29
+ 'Cell Bars': '4',
30
+ 'Battery State': '2',
31
+ 'Battery Level': '100',
32
+ };
33
+ const LOCATION_FRESH_MS = 3000;
34
+ const LOCATION_HEARD_MS = 300_000;
35
+ const COORDINATE_TOLERANCE = 5e-8;
36
+ export class HygieneError extends DeviceStateError {
37
+ name = 'HygieneError';
38
+ report;
39
+ constructor(report) {
40
+ const failed = report.steps.filter(step => !step.ok);
41
+ super(`capture hygiene did not take on ${report.udid}: ${failed
42
+ .map(step => `${step.step} reads back ${step.after}, not ${step.wanted}${step.tries ? ` ${step.tries}` : ''}${step.error ? ` (${step.error})` : ''}`)
43
+ .join('; ')}`);
44
+ this.report = report;
45
+ }
46
+ }
47
+ export function sameCoordinate(a, b) {
48
+ return (a !== undefined &&
49
+ Math.abs(a.latitude - b.latitude) <= COORDINATE_TOLERANCE &&
50
+ Math.abs(a.longitude - b.longitude) <= COORDINATE_TOLERANCE);
51
+ }
52
+ /** simctl reads the pinned time back as `09:41` on some Macs and `9:41` on others. */
53
+ function sameField(key, got, wanted) {
54
+ if (key !== 'Time')
55
+ return got === wanted;
56
+ return got?.replace(/^0(?=\d:)/, '') === wanted.replace(/^0(?=\d:)/, '');
57
+ }
58
+ export function statusBarPinned(fields) {
59
+ return (fields !== undefined && Object.entries(STATUS_BAR_PIN_FIELDS).every(([key, value]) => sameField(key, fields[key], value)));
60
+ }
61
+ function formatStatusBar(fields) {
62
+ const entries = Object.entries(fields ?? {});
63
+ return entries.length === 0 ? 'no overrides' : entries.map(([key, value]) => `${key} ${value}`).join(', ');
64
+ }
65
+ function message(error) {
66
+ return error instanceof Error ? error.message : String(error);
67
+ }
68
+ export async function readLocation(tools, udid, lookbackMs = LOCATION_FRESH_MS) {
69
+ return tools.readLocation(udid, new Date(tools.now().getTime() - lookbackMs));
70
+ }
71
+ function steps(tools, udid, options) {
72
+ const location = options.location ?? DEFAULT_FIXTURE_LOCATION;
73
+ const appearance = options.appearance ?? DEFAULT_APPEARANCE;
74
+ const attempts = options.locationReadAttempts ?? 8;
75
+ const pollMs = options.locationPollMs ?? 1000;
76
+ const setAttempts = options.locationSetAttempts ?? 3;
77
+ let locationSetAt = tools.now();
78
+ let sets = 0;
79
+ const locationStep = {
80
+ name: 'location',
81
+ wanted: formatCoordinate(location),
82
+ read: () => readLocation(tools, udid, options.locationLookbackMs),
83
+ matches: value => sameCoordinate(value, location),
84
+ format: value => (value ? formatCoordinate(value) : 'nothing'),
85
+ async apply() {
86
+ locationSetAt = tools.now();
87
+ sets = 1;
88
+ await tools.setLocation(udid, location);
89
+ },
90
+ async readBack() {
91
+ let got;
92
+ for (;;) {
93
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
94
+ await tools.sleep(pollMs);
95
+ got = await tools.readLocation(udid, locationSetAt);
96
+ if (sameCoordinate(got, location))
97
+ return got;
98
+ }
99
+ if (sets >= setAttempts)
100
+ return got;
101
+ sets += 1;
102
+ await tools.setLocation(udid, location);
103
+ }
104
+ },
105
+ tries: () => `after setting it ${String(sets)} time${sets === 1 ? '' : 's'} over ${String(Math.round((tools.now().getTime() - locationSetAt.getTime()) / 1000))} s`,
106
+ };
107
+ const keyboardStep = {
108
+ name: 'keyboard',
109
+ wanted: 'hardware keyboard disconnected',
110
+ read: () => tools.readHardwareKeyboard(udid),
111
+ matches: value => value === false,
112
+ format: value => value === undefined
113
+ ? 'no per-device setting (inherits the host)'
114
+ : `hardware keyboard ${value ? 'connected' : 'disconnected'}`,
115
+ apply: () => tools.writeHardwareKeyboard(udid, false),
116
+ readBack: () => tools.readHardwareKeyboard(udid),
117
+ };
118
+ const keyboardIntroStep = {
119
+ name: 'keyboard-intro',
120
+ wanted: 'slide-to-type intro marked shown',
121
+ read: () => tools.readKeyboardIntroShown(udid),
122
+ matches: value => value === true,
123
+ format: value => `slide-to-type intro ${value ? 'marked shown' : 'not shown yet'}`,
124
+ apply: () => tools.writeKeyboardIntroShown(udid, true),
125
+ readBack: () => tools.readKeyboardIntroShown(udid),
126
+ };
127
+ const statusBarStep = {
128
+ name: 'status-bar',
129
+ wanted: formatStatusBar(STATUS_BAR_PIN_FIELDS),
130
+ read: () => tools.readStatusBar(udid),
131
+ matches: statusBarPinned,
132
+ format: formatStatusBar,
133
+ apply: () => tools.overrideStatusBar(udid, STATUS_BAR_PIN_FLAGS),
134
+ readBack: () => tools.readStatusBar(udid),
135
+ };
136
+ const appearanceStep = {
137
+ name: 'appearance',
138
+ wanted: appearance,
139
+ read: () => tools.readAppearance(udid),
140
+ matches: value => value === appearance,
141
+ format: value => value ?? 'nothing',
142
+ apply: () => tools.setAppearance(udid, appearance),
143
+ readBack: () => tools.readAppearance(udid),
144
+ };
145
+ return [locationStep, keyboardStep, keyboardIntroStep, statusBarStep, appearanceStep];
146
+ }
147
+ export async function checkHygiene(tools, udid, options = {}) {
148
+ await requireBooted(tools, udid);
149
+ const checks = [];
150
+ for (const step of steps(tools, udid, { locationLookbackMs: LOCATION_HEARD_MS, ...options })) {
151
+ try {
152
+ const got = await step.read();
153
+ checks.push({ step: step.name, wanted: step.wanted, got: step.format(got), ok: step.matches(got) });
154
+ }
155
+ catch (error) {
156
+ checks.push({ step: step.name, wanted: step.wanted, got: `unreadable (${message(error)})`, ok: false });
157
+ }
158
+ }
159
+ return { udid, ok: checks.every(check => check.ok), steps: checks };
160
+ }
161
+ export async function applyHygiene(tools, udid, options = {}) {
162
+ await requireBooted(tools, udid);
163
+ const reports = [];
164
+ for (const step of steps(tools, udid, options)) {
165
+ let before = 'unread';
166
+ try {
167
+ const current = await step.read();
168
+ before = step.format(current);
169
+ if (step.matches(current)) {
170
+ reports.push({ step: step.name, wanted: step.wanted, before, after: before, changed: false, ok: true });
171
+ continue;
172
+ }
173
+ await step.apply();
174
+ const after = await step.readBack();
175
+ const ok = step.matches(after);
176
+ reports.push({
177
+ step: step.name,
178
+ wanted: step.wanted,
179
+ before,
180
+ after: step.format(after),
181
+ changed: true,
182
+ ok,
183
+ ...(!ok && step.tries ? { tries: step.tries() } : {}),
184
+ });
185
+ }
186
+ catch (error) {
187
+ reports.push({
188
+ step: step.name,
189
+ wanted: step.wanted,
190
+ before,
191
+ after: 'unread',
192
+ changed: false,
193
+ ok: false,
194
+ error: message(error),
195
+ });
196
+ }
197
+ }
198
+ const report = { udid, changed: reports.some(step => step.changed), steps: reports };
199
+ if (reports.some(step => !step.ok))
200
+ throw new HygieneError(report);
201
+ return report;
202
+ }
@@ -0,0 +1,5 @@
1
+ export { assertBundleId, assertHost, assertPort, assertScheme, assertUdid, DeviceStateError, requireBooted, requireDevice, requireInstalled, } from "./common.js";
2
+ export { BUNDLER_PIN_KEY, BundlerPinError, bundlerLocation, clearBundlerPin, pinBundler, REACT_NATIVE_DEFAULT_PORT, readBundlerPin, } from "./bundler.js";
3
+ export { devClientLink, DevClientError, ensureSchemeApproval, launchApp, launchDevClient, metroUrl, readSchemeApproval, rebootDevice, SCHEME_APPROVAL_PLIST, SCHEME_APPROVAL_PREFIX, schemeApprovalFile, schemeApprovalKey, } from "./launch.js";
4
+ export { applyHygiene, checkHygiene, DEFAULT_APPEARANCE, DEFAULT_FIXTURE_LOCATION, HygieneError, readLocation, sameCoordinate, STATUS_BAR_PIN_FIELDS, STATUS_BAR_PIN_FLAGS, statusBarPinned, } from "./hygiene.js";
5
+ export { createXcrunTools, DeviceCommandError, execCommand, formatCoordinate, LOCATION_LOG_PREDICATE, parseAppPid, parseDevices, parseLocationLog, parseLogTimestamp, parsePlistBoolean, parseStatusBar, } from "./xcrun.js";
@@ -0,0 +1,76 @@
1
+ import path from 'node:path';
2
+ import { assertBundleId, assertHost, assertPort, assertScheme, DeviceStateError, requireBooted, requireDevice, requireInstalled, } from "./common.js";
3
+ export const SCHEME_APPROVAL_PLIST = 'com.apple.launchservices.schemeapproval.plist';
4
+ export const SCHEME_APPROVAL_PREFIX = 'com.apple.CoreSimulator.CoreSimulatorBridge-->';
5
+ export class DevClientError extends DeviceStateError {
6
+ name = 'DevClientError';
7
+ }
8
+ export function metroUrl(port, host = 'localhost') {
9
+ assertPort(port);
10
+ assertHost(host);
11
+ return `http://${host}:${String(port)}`;
12
+ }
13
+ export function devClientLink({ scheme, port, host }) {
14
+ assertScheme(scheme);
15
+ return `${scheme}://expo-development-client/?url=${encodeURIComponent(metroUrl(port, host))}`;
16
+ }
17
+ export function schemeApprovalFile(dataPath) {
18
+ return path.join(dataPath, 'Library', 'Preferences', SCHEME_APPROVAL_PLIST);
19
+ }
20
+ export function schemeApprovalKey(scheme) {
21
+ assertScheme(scheme);
22
+ return `${SCHEME_APPROVAL_PREFIX}${scheme}`;
23
+ }
24
+ export async function readSchemeApproval(tools, udid, scheme) {
25
+ const device = await requireDevice(tools, udid);
26
+ return tools.readPlistString(schemeApprovalFile(device.dataPath), schemeApprovalKey(scheme));
27
+ }
28
+ export async function ensureSchemeApproval(tools, options) {
29
+ const { udid, scheme, bundleId } = options;
30
+ assertBundleId(bundleId);
31
+ const device = await requireDevice(tools, udid);
32
+ const file = schemeApprovalFile(device.dataPath);
33
+ const key = schemeApprovalKey(scheme);
34
+ const before = await tools.readPlistString(file, key);
35
+ if (before === bundleId)
36
+ return { file, key, before, readBack: before, changed: false, needsReboot: false };
37
+ await tools.writePlistString(file, key, bundleId);
38
+ const readBack = await tools.readPlistString(file, key);
39
+ if (readBack !== bundleId) {
40
+ throw new DevClientError(`the '${scheme}' scheme approval in ${file} reads back '${readBack ?? 'nothing'}', not ${bundleId}`);
41
+ }
42
+ return { file, key, before, readBack, changed: true, needsReboot: device.state !== 'Shutdown' };
43
+ }
44
+ export async function rebootDevice(tools, udid, settleMs = 3000) {
45
+ await tools.shutdown(udid);
46
+ await tools.boot(udid);
47
+ await tools.sleep(settleMs);
48
+ await requireBooted(tools, udid);
49
+ }
50
+ async function waitRunning(tools, options, what, fix) {
51
+ const attempts = options.launchAttempts ?? 20;
52
+ const pollMs = options.launchPollMs ?? 500;
53
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
54
+ if (await tools.appRunning(options.udid, options.bundleId))
55
+ return;
56
+ await tools.sleep(pollMs);
57
+ }
58
+ throw new DevClientError(`${options.bundleId} is not running on ${options.udid} after ${what}`, fix);
59
+ }
60
+ async function relaunch(tools, options, args) {
61
+ await tools.terminate(options.udid, options.bundleId);
62
+ await tools.launch(options.udid, options.bundleId, args);
63
+ await waitRunning(tools, options, `launching it with [${args.join(' ')}]`);
64
+ }
65
+ export async function launchApp(tools, options) {
66
+ await requireBooted(tools, options.udid);
67
+ await requireInstalled(tools, options.udid, options.bundleId);
68
+ const args = [...(options.launchArgs ?? [])];
69
+ await relaunch(tools, options, args);
70
+ return { bundleId: options.bundleId, args, running: true };
71
+ }
72
+ export async function launchDevClient(tools, options) {
73
+ const initialUrl = metroUrl(options.port, options.host);
74
+ const report = await launchApp(tools, { ...options, launchArgs: ['--initialUrl', initialUrl, ...(options.launchArgs ?? [])] });
75
+ return { ...report, initialUrl };
76
+ }
@@ -0,0 +1,119 @@
1
+ import { execFile, execFileSync } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { UsageError } from "../registry/refusal.js";
4
+ import { DeviceBackendError } from "./backend.js";
5
+ const UDID = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/;
6
+ const execFileAsync = promisify(execFile);
7
+ function simctl(args, timeoutMs = 60_000) {
8
+ try {
9
+ return execFileSync('xcrun', ['simctl', ...args], {
10
+ encoding: 'utf8',
11
+ timeout: timeoutMs,
12
+ stdio: ['ignore', 'pipe', 'pipe'],
13
+ });
14
+ }
15
+ catch (error) {
16
+ const e = error;
17
+ if (e.code === 'ENOENT') {
18
+ throw new UsageError('xcrun is not on PATH, so iOS simulators are unavailable', 'install Xcode, or claim without a device (--no-device)');
19
+ }
20
+ throw new DeviceBackendError(`xcrun simctl ${args.join(' ')} failed: ${(e.stderr ?? e.message).trim()}`);
21
+ }
22
+ }
23
+ function compareVersions(a, b) {
24
+ const pa = a.split('.').map(Number);
25
+ const pb = b.split('.').map(Number);
26
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
27
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
28
+ if (d !== 0)
29
+ return d;
30
+ }
31
+ return 0;
32
+ }
33
+ export function newestIphone(types) {
34
+ const iphones = types.filter(t => t.productFamily === 'iPhone' || t.name.startsWith('iPhone'));
35
+ const generation = (t) => Number(/^iPhone (\d+)/.exec(t.name)?.[1] ?? -1);
36
+ const newest = Math.max(...iphones.map(generation));
37
+ const candidates = iphones.filter(t => generation(t) === newest);
38
+ return candidates.find(t => t.name === `iPhone ${String(newest)}`) ?? candidates[0];
39
+ }
40
+ function matches(wanted, ...names) {
41
+ const w = wanted.trim().toLowerCase();
42
+ return names.some(n => n.toLowerCase() === w);
43
+ }
44
+ export function resolveSimSpec(runtimes, request) {
45
+ const ios = runtimes.filter(r => r.isAvailable && (r.platform === 'iOS' || r.identifier.includes('SimRuntime.iOS-')));
46
+ if (ios.length === 0) {
47
+ throw new UsageError('no iOS simulator runtime is installed', 'install one with: xcodebuild -downloadPlatform iOS');
48
+ }
49
+ const runtime = request.runtime
50
+ ? ios.find(r => matches(request.runtime ?? '', r.identifier, r.name, r.version))
51
+ : [...ios].sort((a, b) => compareVersions(b.version, a.version))[0];
52
+ if (!runtime) {
53
+ throw new UsageError(`no installed iOS runtime matches '${request.runtime ?? ''}'`, `pass --runtime with one of: ${ios.map(r => r.name).join(', ')}`);
54
+ }
55
+ const types = runtime.supportedDeviceTypes ?? [];
56
+ const deviceType = request.deviceType
57
+ ? types.find(t => matches(request.deviceType ?? '', t.identifier, t.name))
58
+ : newestIphone(types);
59
+ if (!deviceType) {
60
+ const iphones = types.filter(t => t.productFamily === 'iPhone').map(t => t.name);
61
+ throw new UsageError(`${runtime.name} has no device type '${request.deviceType ?? 'iPhone'}'`, `pass --device-type with one of: ${iphones.join(', ') || '(none listed)'}`);
62
+ }
63
+ return {
64
+ deviceType: deviceType.identifier,
65
+ deviceTypeName: deviceType.name,
66
+ runtime: runtime.identifier,
67
+ runtimeName: runtime.name,
68
+ };
69
+ }
70
+ export function parseDeviceList(json) {
71
+ const parsed = JSON.parse(json);
72
+ const devices = [];
73
+ for (const [runtime, list] of Object.entries(parsed.devices ?? {})) {
74
+ if (!runtime.includes('SimRuntime.iOS-'))
75
+ continue;
76
+ for (const d of list) {
77
+ devices.push({ id: d.udid, name: d.name, deviceType: d.deviceTypeIdentifier ?? '', runtime, booted: d.state === 'Booted' });
78
+ }
79
+ }
80
+ return devices;
81
+ }
82
+ export const simctlBackend = {
83
+ platform: 'ios',
84
+ resolveSpec(request) {
85
+ const parsed = JSON.parse(simctl(['list', '-j', 'runtimes']));
86
+ return resolveSimSpec(parsed.runtimes ?? [], request);
87
+ },
88
+ list() {
89
+ return parseDeviceList(simctl(['list', '-j', 'devices']));
90
+ },
91
+ create(name, spec) {
92
+ const udid = simctl(['create', name, spec.deviceType, spec.runtime], 120_000).trim();
93
+ if (!UDID.test(udid))
94
+ throw new DeviceBackendError(`xcrun simctl create printed '${udid}', not a UDID`);
95
+ return udid;
96
+ },
97
+ delete(id) {
98
+ simctl(['delete', id], 120_000);
99
+ },
100
+ shutdown(id) {
101
+ try {
102
+ simctl(['shutdown', id], 120_000);
103
+ }
104
+ catch (error) {
105
+ if (error instanceof DeviceBackendError && error.message.includes('current state: Shutdown'))
106
+ return;
107
+ throw error;
108
+ }
109
+ },
110
+ async boot(id) {
111
+ try {
112
+ await execFileAsync('xcrun', ['simctl', 'bootstatus', id, '-b'], { timeout: 300_000 });
113
+ }
114
+ catch (error) {
115
+ const e = error;
116
+ throw new DeviceBackendError(`xcrun simctl bootstatus ${id} -b failed: ${(e.stderr ?? e.message).trim()}`);
117
+ }
118
+ },
119
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,99 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ function plistExecutable(plist) {
6
+ let text;
7
+ try {
8
+ text = fs.readFileSync(plist, 'latin1');
9
+ }
10
+ catch {
11
+ return undefined;
12
+ }
13
+ if (!text.startsWith('bplist'))
14
+ return /<key>CFBundleExecutable<\/key>\s*<string>([^<]+)<\/string>/.exec(text)?.[1];
15
+ const result = spawnSync('plutil', ['-extract', 'CFBundleExecutable', 'raw', '-o', '-', plist], { encoding: 'utf8' });
16
+ return result.status === 0 ? result.stdout.trim() || undefined : undefined;
17
+ }
18
+ /** One hash over the files that exist among `files`, in order; undefined when the first is missing. */
19
+ function sha256Of(files) {
20
+ const hash = createHash('sha256');
21
+ const chunk = Buffer.alloc(1 << 20);
22
+ for (const [index, file] of files.entries()) {
23
+ let fd;
24
+ try {
25
+ fd = fs.openSync(file, 'r');
26
+ }
27
+ catch {
28
+ if (index === 0)
29
+ return undefined;
30
+ continue;
31
+ }
32
+ try {
33
+ hash.update(`${path.basename(file)}\0`);
34
+ for (let read = fs.readSync(fd, chunk); read > 0; read = fs.readSync(fd, chunk))
35
+ hash.update(chunk.subarray(0, read));
36
+ }
37
+ finally {
38
+ fs.closeSync(fd);
39
+ }
40
+ }
41
+ return hash.digest('hex');
42
+ }
43
+ export function readIosBundle(app) {
44
+ const executable = plistExecutable(path.join(app, 'Info.plist')) ?? path.basename(app, '.app');
45
+ return {
46
+ executable,
47
+ sha256: sha256Of([path.join(app, executable), path.join(app, `${executable}.debug.dylib`)]),
48
+ debugDylib: fs.existsSync(path.join(app, `${executable}.debug.dylib`)),
49
+ jsBundle: fs.existsSync(path.join(app, 'main.jsbundle')),
50
+ };
51
+ }
52
+ /**
53
+ * Debug or Release as an iOS bundle's files show it. Xcode 16 and later link a Debug build's code into
54
+ * `<executable>.debug.dylib` (ENABLE_DEBUG_DYLIB), and React Native embeds `main.jsbundle` only in a Release build.
55
+ */
56
+ function bundleVariant(facts) {
57
+ if (facts.debugDylib)
58
+ return { variant: 'Debug', why: `it has ${facts.executable}.debug.dylib` };
59
+ if (facts.jsBundle)
60
+ return { variant: 'Release', why: `it embeds main.jsbundle and has no ${facts.executable}.debug.dylib` };
61
+ return { variant: undefined, why: `it has neither ${facts.executable}.debug.dylib nor main.jsbundle` };
62
+ }
63
+ const KNOWN = new Set(['Debug', 'Release']);
64
+ export function judgeIosVariant(facts, expected, installed) {
65
+ const shown = bundleVariant(facts);
66
+ const reads = shown.variant === undefined
67
+ ? `its files don't show the variant (${shown.why})`
68
+ : `it reads as ${shown.variant} (${shown.why})`;
69
+ if (installed && facts.sha256 !== undefined) {
70
+ if (installed.sha256 === facts.sha256) {
71
+ return {
72
+ ok: true,
73
+ detail: `${installed.variant}: the build up installed (${facts.executable} sha256 ${facts.sha256.slice(0, 12)})`,
74
+ };
75
+ }
76
+ return {
77
+ ok: false,
78
+ detail: `not the ${installed.variant} build up installed: ${facts.executable} has sha256 ${facts.sha256.slice(0, 12)}, not ${installed.sha256.slice(0, 12)}, and ${reads}`,
79
+ };
80
+ }
81
+ if (shown.variant !== undefined && KNOWN.has(expected) && shown.variant !== expected) {
82
+ return { ok: false, detail: `${shown.variant}, not the ${expected} build up makes: ${shown.why}` };
83
+ }
84
+ return { ok: true, detail: shown.variant === undefined ? `unknown: ${reads}` : `${shown.variant}: ${shown.why}` };
85
+ }
86
+ /** Android marks a debug build's package DEBUGGABLE, which `dumpsys package` lists in its flags. */
87
+ export function parseDebuggable(dumpsys) {
88
+ const flags = /\bflags=\[([^\]]*)\]/.exec(dumpsys)?.[1];
89
+ return flags === undefined ? undefined : flags.split(/\s+/).includes('DEBUGGABLE');
90
+ }
91
+ export function judgeAndroidVariant(pkg, debuggable, expected) {
92
+ if (debuggable === undefined)
93
+ return { ok: true, detail: `unknown: dumpsys package ${pkg} lists no flags` };
94
+ const shown = debuggable ? 'Debug' : 'Release';
95
+ const why = `${pkg} is ${debuggable ? '' : 'not '}debuggable`;
96
+ if (KNOWN.has(expected) && shown !== expected)
97
+ return { ok: false, detail: `${shown}, not the ${expected} build up makes: ${why}` };
98
+ return { ok: true, detail: `${shown}: ${why}` };
99
+ }