@solidnative-dev/cli 0.0.0-stage → 0.1.0-beta.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.
Files changed (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +841 -2
  3. package/dist/android-apk-signing.d.ts +36 -0
  4. package/dist/android-apk-signing.d.ts.map +1 -0
  5. package/dist/android-apk-signing.js +292 -0
  6. package/dist/android-apk-signing.js.map +1 -0
  7. package/dist/android-bundle-signing.d.ts +34 -0
  8. package/dist/android-bundle-signing.d.ts.map +1 -0
  9. package/dist/android-bundle-signing.js +167 -0
  10. package/dist/android-bundle-signing.js.map +1 -0
  11. package/dist/android-causal-debug.d.ts +38 -0
  12. package/dist/android-causal-debug.d.ts.map +1 -0
  13. package/dist/android-causal-debug.js +239 -0
  14. package/dist/android-causal-debug.js.map +1 -0
  15. package/dist/android-device-proof.d.ts +58 -0
  16. package/dist/android-device-proof.d.ts.map +1 -0
  17. package/dist/android-device-proof.js +554 -0
  18. package/dist/android-device-proof.js.map +1 -0
  19. package/dist/android-logs.d.ts +50 -0
  20. package/dist/android-logs.d.ts.map +1 -0
  21. package/dist/android-logs.js +253 -0
  22. package/dist/android-logs.js.map +1 -0
  23. package/dist/android-release-signing.d.ts +12 -0
  24. package/dist/android-release-signing.d.ts.map +1 -0
  25. package/dist/android-release-signing.js +165 -0
  26. package/dist/android-release-signing.js.map +1 -0
  27. package/dist/android-run-lease.d.ts +15 -0
  28. package/dist/android-run-lease.d.ts.map +1 -0
  29. package/dist/android-run-lease.js +333 -0
  30. package/dist/android-run-lease.js.map +1 -0
  31. package/dist/android-run-preflight.d.ts +45 -0
  32. package/dist/android-run-preflight.d.ts.map +1 -0
  33. package/dist/android-run-preflight.js +183 -0
  34. package/dist/android-run-preflight.js.map +1 -0
  35. package/dist/android-signing-shared.d.ts +38 -0
  36. package/dist/android-signing-shared.d.ts.map +1 -0
  37. package/dist/android-signing-shared.js +210 -0
  38. package/dist/android-signing-shared.js.map +1 -0
  39. package/dist/bin.d.ts +3 -0
  40. package/dist/bin.d.ts.map +1 -0
  41. package/dist/bin.js +4530 -0
  42. package/dist/bin.js.map +1 -0
  43. package/dist/bundle-artifacts.d.ts +48 -0
  44. package/dist/bundle-artifacts.d.ts.map +1 -0
  45. package/dist/bundle-artifacts.js +427 -0
  46. package/dist/bundle-artifacts.js.map +1 -0
  47. package/dist/causal-debug-compare.d.ts +81 -0
  48. package/dist/causal-debug-compare.d.ts.map +1 -0
  49. package/dist/causal-debug-compare.js +238 -0
  50. package/dist/causal-debug-compare.js.map +1 -0
  51. package/dist/causal-debug-report.d.ts +33 -0
  52. package/dist/causal-debug-report.d.ts.map +1 -0
  53. package/dist/causal-debug-report.js +979 -0
  54. package/dist/causal-debug-report.js.map +1 -0
  55. package/dist/causal-debug-watch.d.ts +33 -0
  56. package/dist/causal-debug-watch.d.ts.map +1 -0
  57. package/dist/causal-debug-watch.js +92 -0
  58. package/dist/causal-debug-watch.js.map +1 -0
  59. package/dist/causal-debug.d.ts +131 -0
  60. package/dist/causal-debug.d.ts.map +1 -0
  61. package/dist/causal-debug.js +503 -0
  62. package/dist/causal-debug.js.map +1 -0
  63. package/dist/compatibility-catalog.d.ts +88 -0
  64. package/dist/compatibility-catalog.d.ts.map +1 -0
  65. package/dist/compatibility-catalog.js +344 -0
  66. package/dist/compatibility-catalog.js.map +1 -0
  67. package/dist/deep-link.d.ts +90 -0
  68. package/dist/deep-link.d.ts.map +1 -0
  69. package/dist/deep-link.js +346 -0
  70. package/dist/deep-link.js.map +1 -0
  71. package/dist/device-proof-signatures.d.ts +307 -0
  72. package/dist/device-proof-signatures.d.ts.map +1 -0
  73. package/dist/device-proof-signatures.js +1024 -0
  74. package/dist/device-proof-signatures.js.map +1 -0
  75. package/dist/fingerprint.d.ts +35 -0
  76. package/dist/fingerprint.d.ts.map +1 -0
  77. package/dist/fingerprint.js +454 -0
  78. package/dist/fingerprint.js.map +1 -0
  79. package/dist/index.d.ts +388 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +2996 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/ios-causal-debug.d.ts +39 -0
  84. package/dist/ios-causal-debug.d.ts.map +1 -0
  85. package/dist/ios-causal-debug.js +318 -0
  86. package/dist/ios-causal-debug.js.map +1 -0
  87. package/dist/ios-logs.d.ts +58 -0
  88. package/dist/ios-logs.d.ts.map +1 -0
  89. package/dist/ios-logs.js +269 -0
  90. package/dist/ios-logs.js.map +1 -0
  91. package/dist/ios-process.d.ts +69 -0
  92. package/dist/ios-process.d.ts.map +1 -0
  93. package/dist/ios-process.js +389 -0
  94. package/dist/ios-process.js.map +1 -0
  95. package/dist/ios-run-preflight.d.ts +35 -0
  96. package/dist/ios-run-preflight.d.ts.map +1 -0
  97. package/dist/ios-run-preflight.js +172 -0
  98. package/dist/ios-run-preflight.js.map +1 -0
  99. package/dist/live-causal-debug-report.d.ts +49 -0
  100. package/dist/live-causal-debug-report.d.ts.map +1 -0
  101. package/dist/live-causal-debug-report.js +123 -0
  102. package/dist/live-causal-debug-report.js.map +1 -0
  103. package/dist/local-symbolication.d.ts +35 -0
  104. package/dist/local-symbolication.d.ts.map +1 -0
  105. package/dist/local-symbolication.js +89 -0
  106. package/dist/local-symbolication.js.map +1 -0
  107. package/dist/native-archive.d.ts +15 -0
  108. package/dist/native-archive.d.ts.map +1 -0
  109. package/dist/native-archive.js +441 -0
  110. package/dist/native-archive.js.map +1 -0
  111. package/dist/native-test.d.ts +43 -0
  112. package/dist/native-test.d.ts.map +1 -0
  113. package/dist/native-test.js +209 -0
  114. package/dist/native-test.js.map +1 -0
  115. package/dist/package-add.d.ts +56 -0
  116. package/dist/package-add.d.ts.map +1 -0
  117. package/dist/package-add.js +764 -0
  118. package/dist/package-add.js.map +1 -0
  119. package/dist/react-native-upgrade.d.ts +96 -0
  120. package/dist/react-native-upgrade.d.ts.map +1 -0
  121. package/dist/react-native-upgrade.js +882 -0
  122. package/dist/react-native-upgrade.js.map +1 -0
  123. package/dist/release-device-correlation.d.ts +40 -0
  124. package/dist/release-device-correlation.d.ts.map +1 -0
  125. package/dist/release-device-correlation.js +113 -0
  126. package/dist/release-device-correlation.js.map +1 -0
  127. package/dist/release-signatures.d.ts +168 -0
  128. package/dist/release-signatures.d.ts.map +1 -0
  129. package/dist/release-signatures.js +677 -0
  130. package/dist/release-signatures.js.map +1 -0
  131. package/dist/release.d.ts +88 -0
  132. package/dist/release.d.ts.map +1 -0
  133. package/dist/release.js +771 -0
  134. package/dist/release.js.map +1 -0
  135. package/dist/signature-utilities.d.ts +16 -0
  136. package/dist/signature-utilities.d.ts.map +1 -0
  137. package/dist/signature-utilities.js +114 -0
  138. package/dist/signature-utilities.js.map +1 -0
  139. package/dist/solid-diagnostics-correlation.d.ts +11 -0
  140. package/dist/solid-diagnostics-correlation.d.ts.map +1 -0
  141. package/dist/solid-diagnostics-correlation.js +78 -0
  142. package/dist/solid-diagnostics-correlation.js.map +1 -0
  143. package/dist/solid-diagnostics-debug.d.ts +15 -0
  144. package/dist/solid-diagnostics-debug.d.ts.map +1 -0
  145. package/dist/solid-diagnostics-debug.js +93 -0
  146. package/dist/solid-diagnostics-debug.js.map +1 -0
  147. package/dist/solid-diagnostics-inspection.d.ts +41 -0
  148. package/dist/solid-diagnostics-inspection.d.ts.map +1 -0
  149. package/dist/solid-diagnostics-inspection.js +196 -0
  150. package/dist/solid-diagnostics-inspection.js.map +1 -0
  151. package/dist/source-map.d.ts +36 -0
  152. package/dist/source-map.d.ts.map +1 -0
  153. package/dist/source-map.js +488 -0
  154. package/dist/source-map.js.map +1 -0
  155. package/dist/stack-symbolication.d.ts +56 -0
  156. package/dist/stack-symbolication.d.ts.map +1 -0
  157. package/dist/stack-symbolication.js +310 -0
  158. package/dist/stack-symbolication.js.map +1 -0
  159. package/dist/symbolication.d.ts +27 -0
  160. package/dist/symbolication.d.ts.map +1 -0
  161. package/dist/symbolication.js +75 -0
  162. package/dist/symbolication.js.map +1 -0
  163. package/dist/tree-debug.d.ts +53 -0
  164. package/dist/tree-debug.d.ts.map +1 -0
  165. package/dist/tree-debug.js +283 -0
  166. package/dist/tree-debug.js.map +1 -0
  167. package/dist/versions.d.ts +13 -0
  168. package/dist/versions.d.ts.map +1 -0
  169. package/dist/versions.js +14 -0
  170. package/dist/versions.js.map +1 -0
  171. package/package.json +46 -3
  172. package/templates/react-native-0.88/README.md +328 -0
  173. package/templates/react-native-0.88/android/CMakeLists.txt +27 -0
  174. package/templates/react-native-0.88/android/MainActivity.kt +123 -0
  175. package/templates/react-native-0.88/android/MainApplication.kt +43 -0
  176. package/templates/react-native-0.88/android/OnLoad.cpp +60 -0
  177. package/templates/react-native-0.88/index.js +1 -0
  178. package/templates/react-native-0.88/ios/AppDelegate.swift +190 -0
  179. package/templates/react-native-0.88/metro.config.js +16 -0
  180. package/templates/react-native-0.88/specs/NativeSolidNativeDebug.ts +16 -0
  181. package/templates/react-native-0.88/specs/NativeSolidNativePlatformAndroid.ts +14 -0
  182. package/templates/react-native-0.88/src/App.tsx +161 -0
  183. package/templates/react-native-0.88/src/main.tsx +88 -0
  184. package/templates/react-native-0.88/test/App.test.tsx +152 -0
@@ -0,0 +1,318 @@
1
+ import { execFile } from "node:child_process";
2
+ import { randomBytes } from "node:crypto";
3
+ import { mkdtemp, readFile, rm, stat } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import path from "node:path";
6
+ import { TextDecoder } from "node:util";
7
+ import { SOLID_DIAGNOSTICS_DEBUG_MAX_SERIALIZED_BYTES, TREE_DEBUG_SNAPSHOT_MAX_SERIALIZED_BYTES, } from "@solidnative-dev/observability";
8
+ import { NATIVE_CAUSAL_DEBUG_MAX_INPUT_BYTES, parseNativeCausalDebugSnapshotBytes, } from "./causal-debug.js";
9
+ import { parseNativeSolidDiagnosticsControlBytes, parseNativeSolidDiagnosticsDebugBytes, } from "./solid-diagnostics-debug.js";
10
+ import { parseNativeTreeDebugDeviceResponseBytes } from "./tree-debug.js";
11
+ export const NATIVE_IOS_CAUSAL_DEBUG_DEFAULT_TIMEOUT_MS = 10_000;
12
+ export const NATIVE_IOS_CAUSAL_DEBUG_MIN_TIMEOUT_MS = 5_000;
13
+ export const NATIVE_IOS_CAUSAL_DEBUG_MAX_TIMEOUT_MS = 30_000;
14
+ export const NATIVE_IOS_CAUSAL_DEBUG_URL_SCHEME = "solid-native-debug";
15
+ export const NATIVE_IOS_SOLID_DIAGNOSTICS_DEFAULT_DURATION_MS = 1_000;
16
+ export const NATIVE_IOS_SOLID_DIAGNOSTICS_MAX_DURATION_MS = 30_000;
17
+ const OPERATION_CAUSAL_SNAPSHOT = "causal-snapshot";
18
+ const OPERATION_SOLID_DIAGNOSTICS_BEGIN = "solid-diagnostics-begin";
19
+ const OPERATION_SOLID_DIAGNOSTICS_END = "solid-diagnostics-end";
20
+ const OPERATION_TREE_SNAPSHOT = "tree-snapshot";
21
+ const BUNDLE_IDENTIFIER_PATTERN = /^[A-Za-z0-9][A-Za-z0-9-]*(?:\.[A-Za-z0-9][A-Za-z0-9-]*)+$/u;
22
+ const REQUEST_ID_PATTERN = /^[a-f0-9]{32}$/u;
23
+ const POLL_INTERVAL_MS = 100;
24
+ const COMMAND_TIMEOUT_MS = 5_000;
25
+ const CORE_DEVICE_RESULT_MAX_BYTES = 1_048_576;
26
+ function boundedIdentifier(value, label, maximumLength) {
27
+ if (typeof value !== "string" ||
28
+ value.length === 0 ||
29
+ value.length > maximumLength ||
30
+ /\p{Cc}/u.test(value)) {
31
+ throw new TypeError(`${label} must be a bounded printable string.`);
32
+ }
33
+ return value;
34
+ }
35
+ function timeoutMilliseconds(value) {
36
+ if (!Number.isSafeInteger(value) ||
37
+ value < NATIVE_IOS_CAUSAL_DEBUG_MIN_TIMEOUT_MS ||
38
+ value > NATIVE_IOS_CAUSAL_DEBUG_MAX_TIMEOUT_MS) {
39
+ throw new TypeError(`iOS causal-debug timeout must be a safe integer from ${NATIVE_IOS_CAUSAL_DEBUG_MIN_TIMEOUT_MS} through ${NATIVE_IOS_CAUSAL_DEBUG_MAX_TIMEOUT_MS} milliseconds.`);
40
+ }
41
+ return value;
42
+ }
43
+ function durationMilliseconds(value) {
44
+ if (!Number.isSafeInteger(value) ||
45
+ value < 1 ||
46
+ value > NATIVE_IOS_SOLID_DIAGNOSTICS_MAX_DURATION_MS) {
47
+ throw new TypeError(`iOS Solid diagnostics duration must be a safe integer from 1 through ${NATIVE_IOS_SOLID_DIAGNOSTICS_MAX_DURATION_MS} milliseconds.`);
48
+ }
49
+ return value;
50
+ }
51
+ function defaultRunCommand(command, args, options) {
52
+ return new Promise((resolve) => {
53
+ execFile(command, [...args], {
54
+ encoding: "buffer",
55
+ maxBuffer: 1_048_576,
56
+ timeout: options.timeoutMs,
57
+ }, (error, stdout, stderr) => {
58
+ const commandError = error;
59
+ resolve({
60
+ exitCode: commandError === null
61
+ ? 0
62
+ : typeof commandError.code === "number"
63
+ ? commandError.code
64
+ : null,
65
+ stdout: new Uint8Array(stdout),
66
+ stderr: new Uint8Array(stderr),
67
+ timedOut: commandError?.killed === true,
68
+ ...(typeof commandError?.code === "string"
69
+ ? { errorCode: commandError.code }
70
+ : {}),
71
+ });
72
+ });
73
+ });
74
+ }
75
+ function dependencies(overrides) {
76
+ return {
77
+ createRequestId: overrides?.createRequestId ?? (() => randomBytes(16).toString("hex")),
78
+ now: overrides?.now ?? (() => Date.now()),
79
+ runCommand: overrides?.runCommand ?? defaultRunCommand,
80
+ wait: overrides?.wait ??
81
+ ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))),
82
+ };
83
+ }
84
+ function decode(bytes, label) {
85
+ try {
86
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
87
+ }
88
+ catch {
89
+ throw new TypeError(`${label} must be valid UTF-8.`);
90
+ }
91
+ }
92
+ function commandFailure(label, result) {
93
+ const detail = decode(result.stderr.byteLength === 0 ? result.stdout : result.stderr, `${label} diagnostic output`).trim();
94
+ return new TypeError(`${label} failed${detail === "" ? "." : `: ${detail}`}`);
95
+ }
96
+ function parseCoreDeviceSuccess(bytes, label) {
97
+ if (bytes.byteLength > CORE_DEVICE_RESULT_MAX_BYTES) {
98
+ throw new RangeError(`${label} CoreDevice result exceeds ${CORE_DEVICE_RESULT_MAX_BYTES} bytes.`);
99
+ }
100
+ let document;
101
+ try {
102
+ document = JSON.parse(decode(bytes, `${label} CoreDevice result`));
103
+ }
104
+ catch (error) {
105
+ if (error instanceof TypeError)
106
+ throw error;
107
+ throw new TypeError(`${label} returned invalid CoreDevice JSON.`);
108
+ }
109
+ if (typeof document !== "object" ||
110
+ document === null ||
111
+ !("info" in document) ||
112
+ typeof document.info !== "object" ||
113
+ document.info === null ||
114
+ !("outcome" in document.info) ||
115
+ document.info.outcome !== "success" ||
116
+ "error" in document) {
117
+ throw new TypeError(`${label} did not return a successful CoreDevice result.`);
118
+ }
119
+ }
120
+ function captureRequestUrl(requestId, operation, sessionId) {
121
+ return `${NATIVE_IOS_CAUSAL_DEBUG_URL_SCHEME}://capture?requestId=${requestId}&operation=${operation}${sessionId === undefined ? "" : `&sessionId=${sessionId}`}`;
122
+ }
123
+ function acknowledgementUrl(requestId) {
124
+ return `${NATIVE_IOS_CAUSAL_DEBUG_URL_SCHEME}://ack?requestId=${requestId}`;
125
+ }
126
+ async function captureNativeIosDebugResponse(options, parse) {
127
+ if (typeof options !== "object" || options === null) {
128
+ throw new TypeError("iOS causal-debug capture options are required.");
129
+ }
130
+ const bundleIdentifier = boundedIdentifier(options.bundleIdentifier, "iOS bundle identifier", 255);
131
+ if (!BUNDLE_IDENTIFIER_PATTERN.test(bundleIdentifier)) {
132
+ throw new TypeError("iOS bundle identifier is invalid.");
133
+ }
134
+ const device = boundedIdentifier(options.device, "iOS device identifier", 256);
135
+ const timeoutMs = timeoutMilliseconds(options.timeoutMs ?? NATIVE_IOS_CAUSAL_DEBUG_DEFAULT_TIMEOUT_MS);
136
+ const dependency = dependencies(options.dependencies);
137
+ const requestId = options.requestId ?? dependency.createRequestId();
138
+ if (!REQUEST_ID_PATTERN.test(requestId)) {
139
+ throw new TypeError("iOS causal-debug request IDs must contain exactly 32 lowercase hexadecimal characters.");
140
+ }
141
+ const sessionId = options.sessionId;
142
+ if (options.operation === OPERATION_SOLID_DIAGNOSTICS_END
143
+ ? typeof sessionId !== "string" || !REQUEST_ID_PATTERN.test(sessionId)
144
+ : sessionId !== undefined) {
145
+ throw new TypeError("iOS native-debug session IDs must bind diagnostics end to one begin request.");
146
+ }
147
+ const startedAt = dependency.now();
148
+ if (!Number.isFinite(startedAt) || startedAt < 0) {
149
+ throw new TypeError("iOS causal-debug clock returned an invalid time.");
150
+ }
151
+ const temporaryDirectory = await mkdtemp(path.join(tmpdir(), "solid-native-ios-debug-"));
152
+ const responsePath = path.join(temporaryDirectory, `${requestId}.json`);
153
+ let commandIndex = 0;
154
+ let requested = false;
155
+ let captured = false;
156
+ const runDevicectl = async (args, commandTimeoutMs, trailingArguments = []) => {
157
+ const resultPath = path.join(temporaryDirectory, `devicectl-${String(commandIndex)}.json`);
158
+ commandIndex += 1;
159
+ const result = await dependency.runCommand("xcrun", [
160
+ "devicectl",
161
+ ...args,
162
+ "--quiet",
163
+ "--timeout",
164
+ String(Math.max(NATIVE_IOS_CAUSAL_DEBUG_MIN_TIMEOUT_MS / 1_000, Math.ceil(commandTimeoutMs / 1_000))),
165
+ "--json-output",
166
+ resultPath,
167
+ ...trailingArguments,
168
+ ], {
169
+ timeoutMs: Math.max(NATIVE_IOS_CAUSAL_DEBUG_MIN_TIMEOUT_MS, commandTimeoutMs) +
170
+ 1_000,
171
+ });
172
+ if (result.exitCode === 0 && !result.timedOut) {
173
+ parseCoreDeviceSuccess(new Uint8Array(await readFile(resultPath)), "iOS causal-debug command");
174
+ }
175
+ return result;
176
+ };
177
+ const launch = (url, commandTimeoutMs = COMMAND_TIMEOUT_MS) => runDevicectl(["device", "process", "launch", "--device", device, "--payload-url", url], commandTimeoutMs, [bundleIdentifier]);
178
+ try {
179
+ const request = await launch(captureRequestUrl(requestId, options.operation, sessionId), Math.min(COMMAND_TIMEOUT_MS, timeoutMs));
180
+ if (request.exitCode !== 0 || request.timedOut) {
181
+ throw commandFailure("iOS causal-debug snapshot request", request);
182
+ }
183
+ requested = true;
184
+ while (true) {
185
+ await rm(responsePath, { force: true });
186
+ const now = dependency.now();
187
+ if (!Number.isFinite(now) || now < startedAt) {
188
+ throw new TypeError("iOS causal-debug clock returned an invalid time.");
189
+ }
190
+ const remaining = timeoutMs - (now - startedAt);
191
+ if (remaining <= 0) {
192
+ throw new TypeError(`The debuggable iOS application did not publish causal-debug request ${requestId} within ${timeoutMs} milliseconds.`);
193
+ }
194
+ const response = await runDevicectl([
195
+ "device",
196
+ "copy",
197
+ "from",
198
+ "--device",
199
+ device,
200
+ "--source",
201
+ `Library/Caches/solid-native-debug/${requestId}.json`,
202
+ "--destination",
203
+ responsePath,
204
+ "--domain-type",
205
+ "appDataContainer",
206
+ "--domain-identifier",
207
+ bundleIdentifier,
208
+ ], Math.min(COMMAND_TIMEOUT_MS, remaining));
209
+ if (response.exitCode === 0 && !response.timedOut) {
210
+ const file = await stat(responsePath);
211
+ if (!file.isFile()) {
212
+ throw new TypeError("The iOS causal-debug response is not a regular file.");
213
+ }
214
+ const maximumResponseBytes = options.operation === OPERATION_CAUSAL_SNAPSHOT
215
+ ? NATIVE_CAUSAL_DEBUG_MAX_INPUT_BYTES
216
+ : options.operation === OPERATION_TREE_SNAPSHOT
217
+ ? TREE_DEBUG_SNAPSHOT_MAX_SERIALIZED_BYTES
218
+ : SOLID_DIAGNOSTICS_DEBUG_MAX_SERIALIZED_BYTES;
219
+ if (file.size === 0 || file.size > maximumResponseBytes) {
220
+ throw new RangeError(`The iOS native debug response must contain 1-${String(maximumResponseBytes)} bytes.`);
221
+ }
222
+ const snapshot = parse(new Uint8Array(await readFile(responsePath)));
223
+ captured = true;
224
+ return snapshot;
225
+ }
226
+ const afterCopy = dependency.now();
227
+ if (!Number.isFinite(afterCopy) || afterCopy < startedAt) {
228
+ throw new TypeError("iOS causal-debug clock returned an invalid time.");
229
+ }
230
+ if (afterCopy - startedAt >= timeoutMs) {
231
+ throw new TypeError(`The debuggable iOS application did not publish causal-debug request ${requestId} within ${timeoutMs} milliseconds.`);
232
+ }
233
+ await dependency.wait(Math.min(POLL_INTERVAL_MS, timeoutMs - (afterCopy - startedAt)));
234
+ }
235
+ }
236
+ finally {
237
+ let acknowledgementError;
238
+ if (requested) {
239
+ try {
240
+ const acknowledgement = await launch(acknowledgementUrl(requestId));
241
+ if (acknowledgement.exitCode !== 0 || acknowledgement.timedOut) {
242
+ throw commandFailure("iOS causal-debug snapshot acknowledgement", acknowledgement);
243
+ }
244
+ }
245
+ catch (error) {
246
+ acknowledgementError = error;
247
+ }
248
+ }
249
+ await rm(temporaryDirectory, { force: true, recursive: true });
250
+ if (captured && acknowledgementError !== undefined) {
251
+ throw acknowledgementError;
252
+ }
253
+ }
254
+ }
255
+ /** Requests, validates, acknowledges, and consumes one iOS app-private snapshot. */
256
+ export async function captureNativeIosCausalDebugSnapshot(options) {
257
+ return captureNativeIosDebugResponse({ ...options, operation: OPERATION_CAUSAL_SNAPSHOT }, parseNativeCausalDebugSnapshotBytes);
258
+ }
259
+ /** Requests, validates, acknowledges, and consumes one value-free UI tree snapshot on iOS. */
260
+ export async function captureNativeIosTreeDebugSnapshot(options) {
261
+ return captureNativeIosDebugResponse({ ...options, operation: OPERATION_TREE_SNAPSHOT }, (bytes) => parseNativeTreeDebugDeviceResponseBytes(bytes, "iOS"));
262
+ }
263
+ /** Captures one bounded, value-free Solid attribution window on iOS. */
264
+ export async function captureNativeIosSolidDiagnostics(options) {
265
+ if (typeof options !== "object" || options === null) {
266
+ throw new TypeError("iOS Solid diagnostics capture options are required.");
267
+ }
268
+ const durationMs = durationMilliseconds(options.durationMs ?? NATIVE_IOS_SOLID_DIAGNOSTICS_DEFAULT_DURATION_MS);
269
+ const dependency = dependencies(options.dependencies);
270
+ const sharedOptions = {
271
+ bundleIdentifier: options.bundleIdentifier,
272
+ device: options.device,
273
+ ...(options.timeoutMs === undefined
274
+ ? {}
275
+ : { timeoutMs: options.timeoutMs }),
276
+ dependencies: dependency,
277
+ };
278
+ const sessionId = dependency.createRequestId();
279
+ let mayOwnSession = true;
280
+ let ended = false;
281
+ try {
282
+ const begin = await captureNativeIosDebugResponse({
283
+ ...sharedOptions,
284
+ operation: OPERATION_SOLID_DIAGNOSTICS_BEGIN,
285
+ requestId: sessionId,
286
+ }, (bytes) => parseNativeSolidDiagnosticsControlBytes(bytes, OPERATION_SOLID_DIAGNOSTICS_BEGIN));
287
+ if (!begin.ok) {
288
+ mayOwnSession = false;
289
+ throw new TypeError(`The iOS application rejected Solid diagnostics capture (${begin.error ?? "unknown"}).`);
290
+ }
291
+ if (!begin.active) {
292
+ throw new TypeError("The iOS application acknowledged Solid diagnostics without activating capture.");
293
+ }
294
+ await dependency.wait(durationMs);
295
+ const envelope = await captureNativeIosDebugResponse({
296
+ ...sharedOptions,
297
+ operation: OPERATION_SOLID_DIAGNOSTICS_END,
298
+ sessionId,
299
+ }, parseNativeSolidDiagnosticsDebugBytes);
300
+ ended = true;
301
+ return envelope;
302
+ }
303
+ finally {
304
+ if (mayOwnSession && !ended) {
305
+ try {
306
+ await captureNativeIosDebugResponse({
307
+ ...sharedOptions,
308
+ operation: OPERATION_SOLID_DIAGNOSTICS_END,
309
+ sessionId,
310
+ }, (bytes) => bytes);
311
+ }
312
+ catch {
313
+ // Preserve the primary capture failure after a bounded best-effort stop.
314
+ }
315
+ }
316
+ }
317
+ }
318
+ //# sourceMappingURL=ios-causal-debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ios-causal-debug.js","sourceRoot":"","sources":["../src/ios-causal-debug.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,QA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,yEAAyE;YAC3E,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,58 @@
1
+ export interface NativeIosLogCommandResult {
2
+ readonly exitCode: number | null;
3
+ readonly stdout: string;
4
+ readonly stderr: string;
5
+ readonly timedOut: boolean;
6
+ readonly errorCode?: string;
7
+ }
8
+ export type NativeIosLogCommandRunner = (command: string, args: readonly string[], context: {
9
+ readonly cwd: string;
10
+ readonly env: NodeJS.ProcessEnv;
11
+ readonly timeoutMs: number;
12
+ }) => Promise<NativeIosLogCommandResult>;
13
+ export interface NativeIosLogsDependencies {
14
+ readonly hostPlatform: NodeJS.Platform;
15
+ readonly runCommand: NativeIosLogCommandRunner;
16
+ }
17
+ export interface NativeIosLogsOptions {
18
+ readonly bundleIdentifier: string;
19
+ readonly device: string;
20
+ /** Required acknowledgement that CoreDevice replaces the application process. */
21
+ readonly restart: true;
22
+ readonly cwd?: string;
23
+ readonly env?: NodeJS.ProcessEnv;
24
+ readonly dependencies?: Partial<NativeIosLogsDependencies>;
25
+ }
26
+ export interface NativeIosInstalledApplication {
27
+ readonly bundleIdentifier: string;
28
+ readonly name: string;
29
+ readonly version: string;
30
+ readonly builtByDeveloper: true;
31
+ }
32
+ export interface NativeIosLogsPlan {
33
+ readonly schemaVersion: 0;
34
+ readonly operation: "logs";
35
+ readonly platform: "ios";
36
+ readonly bundleIdentifier: string;
37
+ readonly device: string;
38
+ readonly application: NativeIosInstalledApplication;
39
+ readonly restartsApplication: true;
40
+ readonly includesHistoricalLogs: false;
41
+ readonly cwd: string;
42
+ readonly command: "xcrun";
43
+ readonly args: readonly string[];
44
+ }
45
+ export type NativeIosLogsExecutor = (plan: NativeIosLogsPlan, context: {
46
+ readonly env: NodeJS.ProcessEnv;
47
+ }) => Promise<number>;
48
+ export declare const defaultNativeIosLogCommandRunner: NativeIosLogCommandRunner;
49
+ export declare function parseNativeIosInstalledApplication(source: string, bundleIdentifier: string): NativeIosInstalledApplication;
50
+ /** Performs read-only CoreDevice discovery and creates an explicit restart plan. */
51
+ export declare function createNativeIosLogsPlan(options: NativeIosLogsOptions): Promise<NativeIosLogsPlan>;
52
+ export declare const defaultNativeIosLogsExecutor: NativeIosLogsExecutor;
53
+ export declare function executeNativeIosLogsPlan(plan: NativeIosLogsPlan, options?: {
54
+ readonly env?: NodeJS.ProcessEnv;
55
+ readonly executor?: NativeIosLogsExecutor;
56
+ }): Promise<number>;
57
+ export declare function formatNativeIosLogsPlan(plan: NativeIosLogsPlan): string;
58
+ //# sourceMappingURL=ios-logs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ios-logs.d.ts","sourceRoot":"","sources":["../src/ios-logs.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,yBAAyB,GAAG,CACtC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,EAAE;IACP,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,KACE,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAExC,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC;IACvC,QAAQ,CAAC,UAAU,EAAE,yBAAyB,CAAC;CAChD;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,MAAM,E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wBL,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,6BAA6B,CA4C/B;AA2CD,oFAAoF;AACpF,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,iBAAiB,CAAC,CAkF5B;AA6BD,eAAO,MAAM,4BAA4B,EAAE,qBAuCvC,CAAC;AAEL,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,iBAAiB,EACvB,OAAO,GAAE;IACP,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CACtC,GACL,OAAO,CAAC,MAAM,CAAC,CAIjB;AAQD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAEvE"}
@@ -0,0 +1,269 @@
1
+ import { spawn } from "node:child_process";
2
+ import { readFile, mkdtemp, rm } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ const COMMAND_TIMEOUT_MS = 12_000;
6
+ const CORE_DEVICE_TIMEOUT_SECONDS = 10;
7
+ const MAX_COMMAND_OUTPUT = 64 * 1024;
8
+ const MAX_CORE_DEVICE_RESULT_BYTES = 1024 * 1024;
9
+ const IOS_BUNDLE_IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9-]*(?:\.[A-Za-z0-9][A-Za-z0-9-]*)+$/u;
10
+ function boundedCommandOutput(current, chunk) {
11
+ return `${current}${chunk.toString("utf8")}`.slice(-MAX_COMMAND_OUTPUT);
12
+ }
13
+ export const defaultNativeIosLogCommandRunner = (command, args, context) => new Promise((resolve) => {
14
+ let stdout = "";
15
+ let stderr = "";
16
+ let settled = false;
17
+ let timedOut = false;
18
+ const child = spawn(command, [...args], {
19
+ cwd: context.cwd,
20
+ env: context.env,
21
+ stdio: ["ignore", "pipe", "pipe"],
22
+ });
23
+ child.stdout.on("data", (chunk) => {
24
+ stdout = boundedCommandOutput(stdout, chunk);
25
+ });
26
+ child.stderr.on("data", (chunk) => {
27
+ stderr = boundedCommandOutput(stderr, chunk);
28
+ });
29
+ const finish = (result) => {
30
+ if (settled)
31
+ return;
32
+ settled = true;
33
+ clearTimeout(timer);
34
+ resolve(result);
35
+ };
36
+ const timer = setTimeout(() => {
37
+ timedOut = true;
38
+ child.kill("SIGTERM");
39
+ }, context.timeoutMs);
40
+ child.on("error", (error) => {
41
+ finish({
42
+ exitCode: null,
43
+ stdout,
44
+ stderr: `${stderr}${error.message}`,
45
+ timedOut: false,
46
+ ...(error.code === undefined ? {} : { errorCode: error.code }),
47
+ });
48
+ });
49
+ child.on("close", (exitCode) => {
50
+ finish({ exitCode, stdout, stderr, timedOut });
51
+ });
52
+ });
53
+ function isRecord(value) {
54
+ return value !== null && typeof value === "object" && !Array.isArray(value);
55
+ }
56
+ function boundedString(value, label, maximumLength) {
57
+ if (typeof value !== "string" ||
58
+ value.length === 0 ||
59
+ value.length > maximumLength ||
60
+ /[\0\r\n]/u.test(value)) {
61
+ throw new TypeError(`${label} must be 1-${String(maximumLength)} characters without control line breaks.`);
62
+ }
63
+ return value;
64
+ }
65
+ export function parseNativeIosInstalledApplication(source, bundleIdentifier) {
66
+ if (Buffer.byteLength(source, "utf8") > MAX_CORE_DEVICE_RESULT_BYTES) {
67
+ throw new RangeError(`CoreDevice application result exceeds ${String(MAX_CORE_DEVICE_RESULT_BYTES)} bytes.`);
68
+ }
69
+ let document;
70
+ try {
71
+ document = JSON.parse(source);
72
+ }
73
+ catch {
74
+ throw new TypeError("CoreDevice returned invalid application JSON.");
75
+ }
76
+ if (!isRecord(document) ||
77
+ !isRecord(document.info) ||
78
+ document.info.outcome !== "success" ||
79
+ "error" in document ||
80
+ !isRecord(document.result) ||
81
+ !Array.isArray(document.result.apps)) {
82
+ throw new TypeError("CoreDevice did not return a successful installed-application result.");
83
+ }
84
+ const matches = document.result.apps.filter((entry) => isRecord(entry) && entry.bundleIdentifier === bundleIdentifier);
85
+ if (matches.length !== 1 || !isRecord(matches[0])) {
86
+ throw new TypeError(`iOS application ${bundleIdentifier} is not installed exactly once on the selected device.`);
87
+ }
88
+ const application = matches[0];
89
+ if (application.builtByDeveloper !== true) {
90
+ throw new TypeError(`iOS application ${bundleIdentifier} is not a developer-installed application.`);
91
+ }
92
+ return {
93
+ bundleIdentifier,
94
+ name: boundedString(application.name, "iOS application name", 256),
95
+ version: boundedString(application.version, "iOS application version", 128),
96
+ builtByDeveloper: true,
97
+ };
98
+ }
99
+ function assertBundleIdentifier(bundleIdentifier) {
100
+ if (bundleIdentifier.length > 255 ||
101
+ !IOS_BUNDLE_IDENTIFIER.test(bundleIdentifier)) {
102
+ throw new TypeError(`iOS logs require a valid dotted bundle identifier, received ${JSON.stringify(bundleIdentifier)}.`);
103
+ }
104
+ }
105
+ function assertDevice(device) {
106
+ if (device.length === 0 || device.length > 256 || /[\s\0]/u.test(device)) {
107
+ throw new TypeError("iOS device identifiers must be 1-256 non-whitespace characters.");
108
+ }
109
+ }
110
+ function commandFailure(result) {
111
+ if (result.timedOut) {
112
+ return new TypeError(`CoreDevice application lookup did not finish within ${String(COMMAND_TIMEOUT_MS / 1_000)} seconds. Confirm the iPhone is wired, unlocked, and trusted.`);
113
+ }
114
+ if (result.errorCode === "ENOENT") {
115
+ return new TypeError("Could not start xcrun. Install Xcode and select its developer directory before streaming iOS logs.");
116
+ }
117
+ const detail = `${result.stderr}\n${result.stdout}`
118
+ .split(/\r?\n/u)
119
+ .map((line) => line.trim())
120
+ .find((line) => line.length > 0);
121
+ return new TypeError(detail === undefined
122
+ ? "CoreDevice application lookup failed without diagnostic output."
123
+ : `CoreDevice application lookup failed: ${detail}`);
124
+ }
125
+ /** Performs read-only CoreDevice discovery and creates an explicit restart plan. */
126
+ export async function createNativeIosLogsPlan(options) {
127
+ assertBundleIdentifier(options.bundleIdentifier);
128
+ assertDevice(options.device);
129
+ if (options.restart !== true) {
130
+ throw new TypeError("iOS console streaming requires restart: true because CoreDevice can connect standard streams only while launching the application.");
131
+ }
132
+ const hostPlatform = options.dependencies?.hostPlatform ?? process.platform;
133
+ if (hostPlatform !== "darwin") {
134
+ throw new TypeError(`iOS console streaming requires macOS and Xcode; received ${hostPlatform}.`);
135
+ }
136
+ const cwd = path.resolve(options.cwd ?? process.cwd());
137
+ const env = options.env ?? process.env;
138
+ const runner = options.dependencies?.runCommand ?? defaultNativeIosLogCommandRunner;
139
+ const temporaryDirectory = await mkdtemp(path.join(tmpdir(), "solid-native-ios-logs-"));
140
+ const resultPath = path.join(temporaryDirectory, "applications.json");
141
+ try {
142
+ const result = await runner("xcrun", [
143
+ "devicectl",
144
+ "device",
145
+ "info",
146
+ "apps",
147
+ "--device",
148
+ options.device,
149
+ "--bundle-id",
150
+ options.bundleIdentifier,
151
+ "--quiet",
152
+ "--timeout",
153
+ String(CORE_DEVICE_TIMEOUT_SECONDS),
154
+ "--json-output",
155
+ resultPath,
156
+ ], { cwd, env, timeoutMs: COMMAND_TIMEOUT_MS });
157
+ if (result.exitCode !== 0 || result.timedOut)
158
+ throw commandFailure(result);
159
+ let source;
160
+ try {
161
+ source = await readFile(resultPath, "utf8");
162
+ }
163
+ catch {
164
+ throw new TypeError("CoreDevice application lookup succeeded without writing its required JSON result.");
165
+ }
166
+ const application = parseNativeIosInstalledApplication(source, options.bundleIdentifier);
167
+ return {
168
+ schemaVersion: 0,
169
+ operation: "logs",
170
+ platform: "ios",
171
+ bundleIdentifier: options.bundleIdentifier,
172
+ device: options.device,
173
+ application,
174
+ restartsApplication: true,
175
+ includesHistoricalLogs: false,
176
+ cwd,
177
+ command: "xcrun",
178
+ args: [
179
+ "devicectl",
180
+ "device",
181
+ "process",
182
+ "launch",
183
+ "--device",
184
+ options.device,
185
+ "--terminate-existing",
186
+ "--console",
187
+ "--quiet",
188
+ options.bundleIdentifier,
189
+ ],
190
+ };
191
+ }
192
+ finally {
193
+ await rm(temporaryDirectory, { recursive: true });
194
+ }
195
+ }
196
+ const FORWARDED_SIGNALS = ["SIGHUP", "SIGINT", "SIGTERM"];
197
+ function signalExitCode(signal) {
198
+ switch (signal) {
199
+ case "SIGHUP":
200
+ return 129;
201
+ case "SIGINT":
202
+ return 130;
203
+ case "SIGTERM":
204
+ return 143;
205
+ default:
206
+ return 1;
207
+ }
208
+ }
209
+ function forwardSignal(child, signal) {
210
+ if (process.platform !== "win32" && child.pid !== undefined) {
211
+ try {
212
+ process.kill(-child.pid, signal);
213
+ return;
214
+ }
215
+ catch {
216
+ // Fall through after a concurrent CoreDevice exit.
217
+ }
218
+ }
219
+ if (!child.killed)
220
+ child.kill(signal);
221
+ }
222
+ export const defaultNativeIosLogsExecutor = (plan, context) => new Promise((resolve, reject) => {
223
+ const child = spawn(plan.command, [...plan.args], {
224
+ cwd: plan.cwd,
225
+ detached: process.platform !== "win32",
226
+ env: context.env,
227
+ stdio: "inherit",
228
+ });
229
+ let forwardedSignal;
230
+ const handlers = new Map();
231
+ const removeHandlers = () => {
232
+ for (const [signal, handler] of handlers) {
233
+ process.removeListener(signal, handler);
234
+ }
235
+ handlers.clear();
236
+ };
237
+ for (const signal of FORWARDED_SIGNALS) {
238
+ const handler = () => {
239
+ forwardedSignal ??= signal;
240
+ forwardSignal(child, signal);
241
+ };
242
+ handlers.set(signal, handler);
243
+ process.on(signal, handler);
244
+ }
245
+ child.once("error", (error) => {
246
+ removeHandlers();
247
+ reject(error);
248
+ });
249
+ child.once("close", (exitCode, signal) => {
250
+ removeHandlers();
251
+ resolve(forwardedSignal === undefined
252
+ ? (exitCode ?? signalExitCode(signal))
253
+ : signalExitCode(forwardedSignal));
254
+ });
255
+ });
256
+ export function executeNativeIosLogsPlan(plan, options = {}) {
257
+ return (options.executor ?? defaultNativeIosLogsExecutor)(plan, {
258
+ env: options.env ?? process.env,
259
+ });
260
+ }
261
+ function quoteArgument(argument) {
262
+ return /^[A-Za-z0-9_./:@%+=,-]+$/u.test(argument)
263
+ ? argument
264
+ : `'${argument.replaceAll("'", `'\\''`)}'`;
265
+ }
266
+ export function formatNativeIosLogsPlan(plan) {
267
+ return [plan.command, ...plan.args].map(quoteArgument).join(" ");
268
+ }
269
+ //# sourceMappingURL=ios-logs.js.map