@slack/radar-mcp 1.17.1 → 1.18.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/README.md +24 -7
- package/dist/mcp/flags-tools.d.ts +14 -9
- package/dist/mcp/flags-tools.js +70 -20
- package/dist/mcp/index.js +15 -4
- package/dist/mcp/platform-detect.d.ts +2 -0
- package/dist/mcp/platform-detect.js +2 -0
- package/dist/mcp/tools.js +4 -3
- package/dist/shared/android-dashboard-screen.d.ts +15 -0
- package/dist/shared/android-dashboard-screen.js +48 -0
- package/dist/shared/android.d.ts +1 -0
- package/dist/shared/android.js +2 -0
- package/dist/shared/dashboard-screen.d.ts +35 -0
- package/dist/shared/dashboard-screen.js +12 -0
- package/dist/shared/ios-dashboard-screen.d.ts +32 -0
- package/dist/shared/ios-dashboard-screen.js +266 -0
- package/dist/shared/ios.d.ts +72 -0
- package/dist/shared/ios.js +313 -0
- package/dist/shared/platform.d.ts +3 -0
- package/dist/shared/platform.js +16 -0
- package/dist/shared/screen-artifacts.d.ts +10 -0
- package/dist/shared/screen-artifacts.js +57 -0
- package/dist/shared/screen.d.ts +20 -5
- package/dist/shared/screen.js +35 -39
- package/dist/shared/transport.d.ts +38 -0
- package/dist/shared/webapp.d.ts +1 -0
- package/dist/shared/webapp.js +2 -0
- package/dist/web/public/index.html +51 -11
- package/dist/web/public/next/db.js +292 -39
- package/dist/web/public/next/flags.js +306 -48
- package/dist/web/public/next/screen.js +76 -11
- package/dist/web/public/next/store.js +1 -1
- package/dist/web/server.d.ts +2 -3
- package/dist/web/server.js +169 -74
- package/package.json +3 -2
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { cleanupRecordings, createRecordingPath, recordingPath, removeRecording, secureRecording, } from "./screen-artifacts.js";
|
|
5
|
+
const RECORDING_START_TIMEOUT_MS = 5_000;
|
|
6
|
+
const RECORDING_STOP_TIMEOUT_MS = 8_000;
|
|
7
|
+
function processRunning(child) {
|
|
8
|
+
return child.exitCode === null && child.signalCode === null;
|
|
9
|
+
}
|
|
10
|
+
/** Start simctl's open-ended recorder and expose its readiness/finalization lifecycle. */
|
|
11
|
+
export function startIosSimulatorRecording(simulatorUdid, outputPath) {
|
|
12
|
+
const child = spawn("xcrun", ["simctl", "io", simulatorUdid, "recordVideo", "--codec=h264", "--force", outputPath], { stdio: ["ignore", "ignore", "pipe"] });
|
|
13
|
+
let stderr = "";
|
|
14
|
+
const started = new Promise((resolve, reject) => {
|
|
15
|
+
let settled = false;
|
|
16
|
+
const finish = (error) => {
|
|
17
|
+
if (settled)
|
|
18
|
+
return;
|
|
19
|
+
settled = true;
|
|
20
|
+
clearTimeout(timeout);
|
|
21
|
+
child.off("error", onError);
|
|
22
|
+
child.off("exit", onExit);
|
|
23
|
+
child.stderr?.off("data", onData);
|
|
24
|
+
error ? reject(error) : resolve();
|
|
25
|
+
};
|
|
26
|
+
const onData = (chunk) => {
|
|
27
|
+
stderr += chunk.toString();
|
|
28
|
+
if (stderr.includes("Recording started"))
|
|
29
|
+
finish();
|
|
30
|
+
};
|
|
31
|
+
const onError = (error) => finish(error);
|
|
32
|
+
const onExit = (code, signal) => {
|
|
33
|
+
finish(new Error(stderr.trim() || `simctl recordVideo exited before capture started (${code ?? signal ?? "unknown"})`));
|
|
34
|
+
};
|
|
35
|
+
const timeout = setTimeout(() => finish(new Error("Timed out waiting for iOS Simulator screen recording to start")), RECORDING_START_TIMEOUT_MS);
|
|
36
|
+
child.stderr?.on("data", onData);
|
|
37
|
+
child.once("error", onError);
|
|
38
|
+
child.once("exit", onExit);
|
|
39
|
+
});
|
|
40
|
+
child.on("error", () => { });
|
|
41
|
+
return {
|
|
42
|
+
started,
|
|
43
|
+
isRunning: () => processRunning(child),
|
|
44
|
+
kill: () => { try {
|
|
45
|
+
child.kill("SIGKILL");
|
|
46
|
+
}
|
|
47
|
+
catch { /* already exited */ } },
|
|
48
|
+
stop: () => new Promise((resolve, reject) => {
|
|
49
|
+
if (!processRunning(child)) {
|
|
50
|
+
resolve();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let settled = false;
|
|
54
|
+
const finish = (error) => {
|
|
55
|
+
if (settled)
|
|
56
|
+
return;
|
|
57
|
+
settled = true;
|
|
58
|
+
clearTimeout(timeout);
|
|
59
|
+
child.off("error", onError);
|
|
60
|
+
child.off("exit", onExit);
|
|
61
|
+
error ? reject(error) : resolve();
|
|
62
|
+
};
|
|
63
|
+
const onError = (error) => finish(error);
|
|
64
|
+
const onExit = (code, signal) => {
|
|
65
|
+
if (code === 0 || signal === "SIGINT")
|
|
66
|
+
finish();
|
|
67
|
+
else
|
|
68
|
+
finish(new Error(stderr.trim() || `simctl recordVideo failed (${code ?? signal ?? "unknown"})`));
|
|
69
|
+
};
|
|
70
|
+
const timeout = setTimeout(() => {
|
|
71
|
+
try {
|
|
72
|
+
child.kill("SIGKILL");
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// already exited
|
|
76
|
+
}
|
|
77
|
+
finish(new Error("Timed out finalizing iOS Simulator screen recording"));
|
|
78
|
+
}, RECORDING_STOP_TIMEOUT_MS);
|
|
79
|
+
child.once("error", onError);
|
|
80
|
+
child.once("exit", onExit);
|
|
81
|
+
try {
|
|
82
|
+
child.kill("SIGINT");
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
finish(error instanceof Error ? error : new Error(String(error)));
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function probeSimctl() {
|
|
91
|
+
try {
|
|
92
|
+
const r = spawnSync("xcrun", ["simctl", "list", "devices", "-j"], {
|
|
93
|
+
timeout: 5_000,
|
|
94
|
+
encoding: "utf8",
|
|
95
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
96
|
+
});
|
|
97
|
+
if (r.status !== 0 || !r.stdout)
|
|
98
|
+
return { available: false, hasBootedSim: false };
|
|
99
|
+
const json = JSON.parse(r.stdout);
|
|
100
|
+
const devices = json.devices ?? {};
|
|
101
|
+
const booted = Object.values(devices).flat().some((d) => d.state === "Booted");
|
|
102
|
+
return { available: true, hasBootedSim: booted };
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return { available: false, hasBootedSim: false };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** iOS Simulator's dashboard capture implementation, isolated around simctl. */
|
|
109
|
+
export class IosDashboardScreenController {
|
|
110
|
+
transport;
|
|
111
|
+
startSimulatorRecording;
|
|
112
|
+
recording = null;
|
|
113
|
+
cleanupRegistered = false;
|
|
114
|
+
caps = null;
|
|
115
|
+
constructor(transport, startSimulatorRecording = startIosSimulatorRecording) {
|
|
116
|
+
this.transport = transport;
|
|
117
|
+
this.startSimulatorRecording = startSimulatorRecording;
|
|
118
|
+
// Capabilities are probed lazily on first access to avoid blocking the listen
|
|
119
|
+
// with a cold CoreSimulatorService (probeSimctl can take up to 5s).
|
|
120
|
+
}
|
|
121
|
+
capabilities() {
|
|
122
|
+
if (!this.caps)
|
|
123
|
+
this.caps = this.buildCaps(probeSimctl());
|
|
124
|
+
return this.caps;
|
|
125
|
+
}
|
|
126
|
+
async refreshCapabilities() {
|
|
127
|
+
this.caps = this.buildCaps(probeSimctl());
|
|
128
|
+
}
|
|
129
|
+
buildCaps(probe) {
|
|
130
|
+
return {
|
|
131
|
+
screenshot: probe.available && probe.hasBootedSim,
|
|
132
|
+
liveCast: false,
|
|
133
|
+
snapshotCast: probe.available && probe.hasBootedSim,
|
|
134
|
+
recording: probe.available && probe.hasBootedSim,
|
|
135
|
+
ffmpeg: false,
|
|
136
|
+
scrcpy: false,
|
|
137
|
+
installHint: probe.available ? null : "Install Xcode to enable iOS Simulator screen capture.",
|
|
138
|
+
platform: "ios",
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async captureScreenshot() {
|
|
142
|
+
let screenshot = null;
|
|
143
|
+
try {
|
|
144
|
+
screenshot = this.transport.screenshot?.(true) ?? null;
|
|
145
|
+
if (!screenshot)
|
|
146
|
+
return null;
|
|
147
|
+
return fs.readFileSync(screenshot);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
if (screenshot) {
|
|
154
|
+
try {
|
|
155
|
+
fs.rmSync(path.dirname(screenshot), { recursive: true, force: true });
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
// OS temp cleanup remains the fallback.
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async startRecording() {
|
|
164
|
+
if (this.recording?.handle.isRunning())
|
|
165
|
+
return this.recording.path;
|
|
166
|
+
if (!this.transport.ensureForward()) {
|
|
167
|
+
throw new Error(this.transport.getLastForwardError?.() ??
|
|
168
|
+
"No booted iOS Simulator found. Open one in Xcode and retry.");
|
|
169
|
+
}
|
|
170
|
+
const serial = this.transport.getSelectedDevice?.()?.serial;
|
|
171
|
+
if (!serial) {
|
|
172
|
+
throw new Error("No booted iOS Simulator found. Open one in Xcode and retry.");
|
|
173
|
+
}
|
|
174
|
+
const output = createRecordingPath();
|
|
175
|
+
const handle = this.startSimulatorRecording(serial, output);
|
|
176
|
+
this.recording = { handle, path: output };
|
|
177
|
+
try {
|
|
178
|
+
await handle.started;
|
|
179
|
+
return output;
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
this.recording = null;
|
|
183
|
+
try {
|
|
184
|
+
await handle.stop();
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// Preserve the startup error; stopping a failed process is best-effort.
|
|
188
|
+
}
|
|
189
|
+
removeRecording(output);
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async stopRecording() {
|
|
194
|
+
const recording = this.recording;
|
|
195
|
+
if (!recording)
|
|
196
|
+
return null;
|
|
197
|
+
this.recording = null;
|
|
198
|
+
await recording.handle.stop();
|
|
199
|
+
let size = 0;
|
|
200
|
+
try {
|
|
201
|
+
size = fs.statSync(recording.path).size;
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// Report the same failure for an absent and an empty output.
|
|
205
|
+
}
|
|
206
|
+
if (size === 0) {
|
|
207
|
+
removeRecording(recording.path);
|
|
208
|
+
throw new Error("simctl produced an empty screen recording");
|
|
209
|
+
}
|
|
210
|
+
secureRecording(recording.path);
|
|
211
|
+
return recording.path;
|
|
212
|
+
}
|
|
213
|
+
isRecording() {
|
|
214
|
+
return this.recording?.handle.isRunning() ?? false;
|
|
215
|
+
}
|
|
216
|
+
redetect() {
|
|
217
|
+
this.transport.resetState?.();
|
|
218
|
+
if (!this.transport.ensureForward()) {
|
|
219
|
+
return Promise.reject(new Error(this.transport.getLastForwardError?.() ??
|
|
220
|
+
"No booted iOS Simulator found. Open one in Xcode and retry."));
|
|
221
|
+
}
|
|
222
|
+
return Promise.resolve(this.transport.getSelectedDevice?.()?.label ?? "iOS Simulator");
|
|
223
|
+
}
|
|
224
|
+
reset() {
|
|
225
|
+
const recording = this.recording;
|
|
226
|
+
this.recording = null;
|
|
227
|
+
if (recording) {
|
|
228
|
+
recording.handle.stop().then(() => { removeRecording(recording.path); cleanupRecordings(); }, () => { removeRecording(recording.path); cleanupRecordings(); });
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
cleanupRecordings();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
resetDetection() {
|
|
235
|
+
// Drop the cached probe so the next capabilities() read re-checks simctl; recordings and
|
|
236
|
+
// saved artifacts are untouched, which is the point of the light path.
|
|
237
|
+
this.caps = null;
|
|
238
|
+
}
|
|
239
|
+
resolveRecording(file) {
|
|
240
|
+
return recordingPath(file);
|
|
241
|
+
}
|
|
242
|
+
registerCleanup() {
|
|
243
|
+
if (this.cleanupRegistered)
|
|
244
|
+
return;
|
|
245
|
+
this.cleanupRegistered = true;
|
|
246
|
+
const teardown = () => {
|
|
247
|
+
const rec = this.recording;
|
|
248
|
+
this.recording = null;
|
|
249
|
+
if (rec) {
|
|
250
|
+
try {
|
|
251
|
+
rec.handle.kill();
|
|
252
|
+
}
|
|
253
|
+
catch { /* best-effort */ }
|
|
254
|
+
try {
|
|
255
|
+
removeRecording(rec.path);
|
|
256
|
+
}
|
|
257
|
+
catch { /* best-effort */ }
|
|
258
|
+
}
|
|
259
|
+
cleanupRecordings();
|
|
260
|
+
};
|
|
261
|
+
const signalHandler = () => { teardown(); process.exit(128); };
|
|
262
|
+
process.on("SIGINT", signalHandler);
|
|
263
|
+
process.on("SIGTERM", signalHandler);
|
|
264
|
+
process.on("exit", teardown);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { DeviceInfo, DeviceTransport } from "./transport.js";
|
|
2
|
+
export type IosScreenshotCapturer = (simulatorUdid: string, outputPath: string) => void;
|
|
3
|
+
export type IosScreenRecorder = (simulatorUdid: string, outputPath: string, durationSeconds: number) => void;
|
|
4
|
+
export interface IosSimulatorTransportDependencies {
|
|
5
|
+
readBootedSimulators?: () => string;
|
|
6
|
+
captureScreenshot?: IosScreenshotCapturer;
|
|
7
|
+
recordScreen?: IosScreenRecorder;
|
|
8
|
+
}
|
|
9
|
+
/** Convert a CoreSimulator runtime identifier into the label users see in Xcode. */
|
|
10
|
+
export declare function simulatorRuntimeLabel(identifier: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Parse `xcrun simctl list devices booted --json` into Radar's normalized device shape.
|
|
13
|
+
* simctl groups devices by runtime and calls a usable simulator "Booted"; Radar's existing
|
|
14
|
+
* picker treats the normalized state "device" as selectable, matching Android's adb state.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseBootedIosSimulators(raw: string): DeviceInfo[];
|
|
17
|
+
/** Capture a full-resolution PNG from a specific booted Simulator. */
|
|
18
|
+
export declare function captureIosSimulatorScreenshot(simulatorUdid: string, outputPath: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Record a fixed-duration H.264 mp4 from a specific booted Simulator.
|
|
21
|
+
*
|
|
22
|
+
* simctl recordVideo takes no duration argument; the timeout ends the recording. SIGINT
|
|
23
|
+
* is sent first so simctl can finalize the movie container (SIGKILL prevents finalization
|
|
24
|
+
* and produces an unplayable file). A second timeout with SIGKILL backstops a hung simctl.
|
|
25
|
+
*
|
|
26
|
+
* spawnSync cannot do a two-phase signal escalation, so we use SIGINT as the kill signal
|
|
27
|
+
* with a generous total timeout that covers both the recording and the finalization window.
|
|
28
|
+
* Measured: simctl exits within 1-2s of SIGINT.
|
|
29
|
+
*/
|
|
30
|
+
export declare function recordIosSimulatorScreen(simulatorUdid: string, outputPath: string, durationSeconds: number): void;
|
|
31
|
+
/** Host-side transport for iOS Simulators. */
|
|
32
|
+
export declare class IosSimulatorTransport implements DeviceTransport {
|
|
33
|
+
readonly platform = "ios";
|
|
34
|
+
readonly supportsRadarHttpTools = false;
|
|
35
|
+
private forwarded;
|
|
36
|
+
private timeoutMinutes;
|
|
37
|
+
private selectedDevice;
|
|
38
|
+
private lastForwardError;
|
|
39
|
+
private readonly readBootedSimulators;
|
|
40
|
+
private readonly captureSimulatorScreenshot;
|
|
41
|
+
private readonly recordSimulatorScreen;
|
|
42
|
+
constructor(dependencies?: IosSimulatorTransportDependencies);
|
|
43
|
+
listDevices(): DeviceInfo[] | null;
|
|
44
|
+
selectDevice(serial: string | null): {
|
|
45
|
+
ok: true;
|
|
46
|
+
serial: string | null;
|
|
47
|
+
switched?: boolean;
|
|
48
|
+
} | {
|
|
49
|
+
ok: false;
|
|
50
|
+
error: string;
|
|
51
|
+
devices: DeviceInfo[];
|
|
52
|
+
};
|
|
53
|
+
getSelectedDevice(): {
|
|
54
|
+
serial: string;
|
|
55
|
+
label: string;
|
|
56
|
+
} | null;
|
|
57
|
+
ensureForward(): boolean;
|
|
58
|
+
reassertForward(): boolean;
|
|
59
|
+
isForwarded(): boolean;
|
|
60
|
+
resetState(): void;
|
|
61
|
+
dropForward(): void;
|
|
62
|
+
getLastForwardError(): string | null;
|
|
63
|
+
activate(timeoutMinutes: number): void;
|
|
64
|
+
getTimeoutMinutes(): number;
|
|
65
|
+
getActiveUserId(): string | null;
|
|
66
|
+
resolveActiveUser(): string;
|
|
67
|
+
screenshot(fullRes: boolean): string;
|
|
68
|
+
recordScreen(durationS: number): string;
|
|
69
|
+
private reconcileSelectedDevice;
|
|
70
|
+
private clearSelectedDevice;
|
|
71
|
+
private describeDevices;
|
|
72
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { execFileSync, spawnSync } from "child_process";
|
|
2
|
+
import { chmodSync, mkdtempSync, rmSync, statSync, } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
const IOS_SIMULATOR_UDID_ENV = "SLACK_RADAR_IOS_SIMULATOR_UDID";
|
|
6
|
+
/** Convert a CoreSimulator runtime identifier into the label users see in Xcode. */
|
|
7
|
+
export function simulatorRuntimeLabel(identifier) {
|
|
8
|
+
const runtime = identifier.split("SimRuntime.").pop() ?? identifier;
|
|
9
|
+
const match = runtime.match(/^iOS-(\d+)-(\d+)(?:-(\d+))?$/);
|
|
10
|
+
if (!match)
|
|
11
|
+
return runtime.replaceAll("-", " ");
|
|
12
|
+
return `iOS ${match[1]}.${match[2]}${match[3] ? `.${match[3]}` : ""}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parse `xcrun simctl list devices booted --json` into Radar's normalized device shape.
|
|
16
|
+
* simctl groups devices by runtime and calls a usable simulator "Booted"; Radar's existing
|
|
17
|
+
* picker treats the normalized state "device" as selectable, matching Android's adb state.
|
|
18
|
+
*/
|
|
19
|
+
export function parseBootedIosSimulators(raw) {
|
|
20
|
+
let parsed;
|
|
21
|
+
try {
|
|
22
|
+
parsed = JSON.parse(raw);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
if (!parsed.devices || typeof parsed.devices !== "object" || Array.isArray(parsed.devices)) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const simulators = [];
|
|
31
|
+
for (const [runtimeIdentifier, value] of Object.entries(parsed.devices)) {
|
|
32
|
+
// Radar's iOS transport deliberately excludes watchOS/tvOS/visionOS simulators.
|
|
33
|
+
if (!runtimeIdentifier.includes("SimRuntime.iOS-") || !Array.isArray(value))
|
|
34
|
+
continue;
|
|
35
|
+
const runtime = simulatorRuntimeLabel(runtimeIdentifier);
|
|
36
|
+
for (const item of value) {
|
|
37
|
+
if (!item || typeof item !== "object")
|
|
38
|
+
continue;
|
|
39
|
+
if (item.state !== "Booted" || item.isAvailable === false)
|
|
40
|
+
continue;
|
|
41
|
+
if (typeof item.udid !== "string" || item.udid.length === 0)
|
|
42
|
+
continue;
|
|
43
|
+
const name = typeof item.name === "string" && item.name.length > 0
|
|
44
|
+
? item.name
|
|
45
|
+
: item.udid;
|
|
46
|
+
simulators.push({
|
|
47
|
+
serial: item.udid,
|
|
48
|
+
label: `${name} (${runtime} Simulator)`,
|
|
49
|
+
state: "device",
|
|
50
|
+
platform: "ios",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return simulators.sort((a, b) => a.label.localeCompare(b.label) || a.serial.localeCompare(b.serial));
|
|
55
|
+
}
|
|
56
|
+
/** Capture a full-resolution PNG from a specific booted Simulator. */
|
|
57
|
+
export function captureIosSimulatorScreenshot(simulatorUdid, outputPath) {
|
|
58
|
+
execFileSync("xcrun", ["simctl", "io", simulatorUdid, "screenshot", "--type=png", outputPath], {
|
|
59
|
+
timeout: 10_000,
|
|
60
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Record a fixed-duration H.264 mp4 from a specific booted Simulator.
|
|
65
|
+
*
|
|
66
|
+
* simctl recordVideo takes no duration argument; the timeout ends the recording. SIGINT
|
|
67
|
+
* is sent first so simctl can finalize the movie container (SIGKILL prevents finalization
|
|
68
|
+
* and produces an unplayable file). A second timeout with SIGKILL backstops a hung simctl.
|
|
69
|
+
*
|
|
70
|
+
* spawnSync cannot do a two-phase signal escalation, so we use SIGINT as the kill signal
|
|
71
|
+
* with a generous total timeout that covers both the recording and the finalization window.
|
|
72
|
+
* Measured: simctl exits within 1-2s of SIGINT.
|
|
73
|
+
*/
|
|
74
|
+
export function recordIosSimulatorScreen(simulatorUdid, outputPath, durationSeconds) {
|
|
75
|
+
const FINALIZE_TIMEOUT_MS = 10_000;
|
|
76
|
+
const result = spawnSync("xcrun", ["simctl", "io", simulatorUdid, "recordVideo", "--codec=h264", "--force", outputPath], {
|
|
77
|
+
timeout: durationSeconds * 1_000 + FINALIZE_TIMEOUT_MS,
|
|
78
|
+
killSignal: "SIGINT",
|
|
79
|
+
encoding: "utf8",
|
|
80
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
81
|
+
});
|
|
82
|
+
const errorCode = result.error?.code;
|
|
83
|
+
// ETIMEDOUT with SIGINT means the recording ended on schedule and simctl finalized.
|
|
84
|
+
if (result.error && errorCode !== "ETIMEDOUT")
|
|
85
|
+
throw result.error;
|
|
86
|
+
// A signal death (SIGINT) sets status=null and signal="SIGINT" — normal completion.
|
|
87
|
+
if (result.signal === "SIGINT")
|
|
88
|
+
return;
|
|
89
|
+
if (result.status !== null && result.status !== 0) {
|
|
90
|
+
throw new Error(result.stderr?.trim() || `simctl recordVideo failed with status ${result.status}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Host-side transport for iOS Simulators. */
|
|
94
|
+
export class IosSimulatorTransport {
|
|
95
|
+
platform = "ios";
|
|
96
|
+
// Simulator capture works through simctl, but no iOS Radar HTTP server exists yet.
|
|
97
|
+
supportsRadarHttpTools = false;
|
|
98
|
+
forwarded = false;
|
|
99
|
+
timeoutMinutes = 5;
|
|
100
|
+
selectedDevice = null;
|
|
101
|
+
lastForwardError = null;
|
|
102
|
+
readBootedSimulators;
|
|
103
|
+
captureSimulatorScreenshot;
|
|
104
|
+
recordSimulatorScreen;
|
|
105
|
+
constructor(dependencies = {}) {
|
|
106
|
+
this.readBootedSimulators = dependencies.readBootedSimulators ?? (() => execFileSync("xcrun", ["simctl", "list", "devices", "booted", "--json"], {
|
|
107
|
+
timeout: 10_000,
|
|
108
|
+
encoding: "utf-8",
|
|
109
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
110
|
+
}));
|
|
111
|
+
this.captureSimulatorScreenshot = dependencies.captureScreenshot ??
|
|
112
|
+
captureIosSimulatorScreenshot;
|
|
113
|
+
this.recordSimulatorScreen = dependencies.recordScreen ?? recordIosSimulatorScreen;
|
|
114
|
+
}
|
|
115
|
+
listDevices() {
|
|
116
|
+
try {
|
|
117
|
+
const raw = this.readBootedSimulators();
|
|
118
|
+
const devices = parseBootedIosSimulators(raw);
|
|
119
|
+
this.reconcileSelectedDevice(devices);
|
|
120
|
+
return devices;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// A simctl/CoreSimulatorService failure means the list is unknown, not empty.
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
selectDevice(serial) {
|
|
128
|
+
const devices = this.listDevices();
|
|
129
|
+
if (devices === null) {
|
|
130
|
+
return {
|
|
131
|
+
ok: false,
|
|
132
|
+
error: "Could not list iOS simulators (xcrun simctl failed). Check Xcode and retry.",
|
|
133
|
+
devices: [],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const prior = this.selectedDevice?.serial ?? null;
|
|
137
|
+
const pin = (device) => {
|
|
138
|
+
if (this.selectedDevice && this.selectedDevice.serial !== device.serial) {
|
|
139
|
+
this.forwarded = false;
|
|
140
|
+
}
|
|
141
|
+
this.selectedDevice = { serial: device.serial, label: device.label };
|
|
142
|
+
return {
|
|
143
|
+
ok: true,
|
|
144
|
+
serial: device.serial,
|
|
145
|
+
switched: prior !== null && prior !== device.serial,
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
if (serial) {
|
|
149
|
+
const match = devices.find((device) => device.serial === serial);
|
|
150
|
+
if (match)
|
|
151
|
+
return pin(match);
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
error: `iOS Simulator ${serial} is not booted. Booted: ${this.describeDevices(devices)}`,
|
|
155
|
+
devices,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// Honour an explicit env pin, but refuse rather than silently discarding it.
|
|
159
|
+
const envUdid = process.env[IOS_SIMULATOR_UDID_ENV];
|
|
160
|
+
if (envUdid) {
|
|
161
|
+
const match = devices.find((device) => device.serial === envUdid);
|
|
162
|
+
if (match)
|
|
163
|
+
return pin(match);
|
|
164
|
+
return {
|
|
165
|
+
ok: false,
|
|
166
|
+
error: `SLACK_RADAR_IOS_SIMULATOR_UDID=${envUdid} is not booted. Booted: ${this.describeDevices(devices)}`,
|
|
167
|
+
devices,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// Sticky re-pin: keep the previous selection if it's still booted.
|
|
171
|
+
if (this.selectedDevice) {
|
|
172
|
+
const match = devices.find((device) => device.serial === this.selectedDevice.serial);
|
|
173
|
+
if (match)
|
|
174
|
+
return pin(match);
|
|
175
|
+
this.clearSelectedDevice();
|
|
176
|
+
}
|
|
177
|
+
if (devices.length === 1)
|
|
178
|
+
return pin(devices[0]);
|
|
179
|
+
if (devices.length === 0) {
|
|
180
|
+
this.clearSelectedDevice();
|
|
181
|
+
return { ok: true, serial: null };
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
ok: false,
|
|
185
|
+
error: `Multiple iOS simulators are booted; specify which one. Booted: ${this.describeDevices(devices)}.`,
|
|
186
|
+
devices,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
getSelectedDevice() {
|
|
190
|
+
return this.selectedDevice;
|
|
191
|
+
}
|
|
192
|
+
ensureForward() {
|
|
193
|
+
if (this.forwarded)
|
|
194
|
+
return true;
|
|
195
|
+
const selected = this.selectDevice(null);
|
|
196
|
+
if (!selected.ok) {
|
|
197
|
+
this.lastForwardError = selected.error;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
if (selected.serial === null) {
|
|
201
|
+
this.lastForwardError = "No booted iOS Simulator found. Open one in Xcode and retry.";
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
this.forwarded = true;
|
|
205
|
+
this.lastForwardError = null;
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
reassertForward() {
|
|
209
|
+
// Unconditional: re-verify the simulator is still booted even if cached as forwarded.
|
|
210
|
+
this.forwarded = false;
|
|
211
|
+
return this.ensureForward();
|
|
212
|
+
}
|
|
213
|
+
isForwarded() {
|
|
214
|
+
return this.forwarded;
|
|
215
|
+
}
|
|
216
|
+
resetState() {
|
|
217
|
+
this.forwarded = false;
|
|
218
|
+
this.lastForwardError = null;
|
|
219
|
+
}
|
|
220
|
+
dropForward() {
|
|
221
|
+
this.forwarded = false;
|
|
222
|
+
this.lastForwardError = null;
|
|
223
|
+
}
|
|
224
|
+
getLastForwardError() {
|
|
225
|
+
return this.lastForwardError;
|
|
226
|
+
}
|
|
227
|
+
activate(timeoutMinutes) {
|
|
228
|
+
this.timeoutMinutes = timeoutMinutes || this.timeoutMinutes;
|
|
229
|
+
}
|
|
230
|
+
getTimeoutMinutes() {
|
|
231
|
+
return this.timeoutMinutes;
|
|
232
|
+
}
|
|
233
|
+
getActiveUserId() {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
resolveActiveUser() {
|
|
237
|
+
return "";
|
|
238
|
+
}
|
|
239
|
+
screenshot(fullRes) {
|
|
240
|
+
const selection = this.selectDevice(null);
|
|
241
|
+
if (!selection.ok)
|
|
242
|
+
throw new Error(selection.error);
|
|
243
|
+
if (!selection.serial) {
|
|
244
|
+
throw new Error("No booted iOS Simulator found. Open one in Xcode and retry.");
|
|
245
|
+
}
|
|
246
|
+
const captureDirectory = mkdtempSync(path.join(tmpdir(), "slack-radar-ios-screenshot-"));
|
|
247
|
+
const outputPath = path.join(captureDirectory, "screenshot.png");
|
|
248
|
+
try {
|
|
249
|
+
chmodSync(captureDirectory, 0o700);
|
|
250
|
+
this.captureSimulatorScreenshot(selection.serial, outputPath);
|
|
251
|
+
if (statSync(outputPath).size === 0) {
|
|
252
|
+
throw new Error("simctl produced an empty screenshot");
|
|
253
|
+
}
|
|
254
|
+
chmodSync(outputPath, 0o600);
|
|
255
|
+
if (!fullRes) {
|
|
256
|
+
try {
|
|
257
|
+
execFileSync("sips", ["-Z", "720", outputPath], {
|
|
258
|
+
timeout: 5_000,
|
|
259
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
// Resizing is best-effort. The full-resolution PNG is still valid.
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return outputPath;
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
rmSync(captureDirectory, { recursive: true, force: true });
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
recordScreen(durationS) {
|
|
274
|
+
const selection = this.selectDevice(null);
|
|
275
|
+
if (!selection.ok)
|
|
276
|
+
throw new Error(selection.error);
|
|
277
|
+
if (!selection.serial) {
|
|
278
|
+
throw new Error("No booted iOS Simulator found. Open one in Xcode and retry.");
|
|
279
|
+
}
|
|
280
|
+
const duration = Math.min(Math.max(Math.round(durationS), 1), 30);
|
|
281
|
+
const captureDirectory = mkdtempSync(path.join(tmpdir(), "slack-radar-ios-recording-"));
|
|
282
|
+
const outputPath = path.join(captureDirectory, "recording.mp4");
|
|
283
|
+
try {
|
|
284
|
+
chmodSync(captureDirectory, 0o700);
|
|
285
|
+
this.recordSimulatorScreen(selection.serial, outputPath, duration);
|
|
286
|
+
if (statSync(outputPath).size === 0) {
|
|
287
|
+
throw new Error("simctl produced an empty screen recording");
|
|
288
|
+
}
|
|
289
|
+
chmodSync(outputPath, 0o600);
|
|
290
|
+
return outputPath;
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
rmSync(captureDirectory, { recursive: true, force: true });
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
reconcileSelectedDevice(devices) {
|
|
298
|
+
if (!this.selectedDevice)
|
|
299
|
+
return;
|
|
300
|
+
if (!devices.some((device) => device.serial === this.selectedDevice.serial)) {
|
|
301
|
+
this.clearSelectedDevice();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
clearSelectedDevice() {
|
|
305
|
+
this.forwarded = false;
|
|
306
|
+
this.selectedDevice = null;
|
|
307
|
+
}
|
|
308
|
+
describeDevices(devices) {
|
|
309
|
+
return devices.length > 0
|
|
310
|
+
? devices.map((device) => `${device.serial} (${device.label})`).join(", ")
|
|
311
|
+
: "none";
|
|
312
|
+
}
|
|
313
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AndroidTransport } from "./android.js";
|
|
2
|
+
import { IosSimulatorTransport } from "./ios.js";
|
|
3
|
+
/** Resolve the requested host transport without coupling the MCP or web entrypoint to a platform. */
|
|
4
|
+
export function createTransport(args = process.argv, env = process.env) {
|
|
5
|
+
const platformArg = args.find((arg) => arg.startsWith("--platform="));
|
|
6
|
+
const platform = platformArg?.slice("--platform=".length) || env.SLACK_RADAR_PLATFORM || "android";
|
|
7
|
+
switch (platform.toLowerCase()) {
|
|
8
|
+
case "android":
|
|
9
|
+
return new AndroidTransport();
|
|
10
|
+
case "ios":
|
|
11
|
+
case "ios-simulator":
|
|
12
|
+
return new IosSimulatorTransport();
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Unsupported platform: ${platform}. Supported: android, ios`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Allocate an owner-only path for a recording containing sensitive screen content. */
|
|
2
|
+
export declare function createRecordingPath(): string;
|
|
3
|
+
/** Restrict a completed recording to its owner. */
|
|
4
|
+
export declare function secureRecording(recording: string): void;
|
|
5
|
+
/** Remove a failed or cancelled recording without surfacing cleanup errors. */
|
|
6
|
+
export declare function removeRecording(recording: string): void;
|
|
7
|
+
/** Remove every Radar-owned screen recording at a session boundary. */
|
|
8
|
+
export declare function cleanupRecordings(): void;
|
|
9
|
+
/** Resolve a safe recording download without allowing traversal or unrelated files. */
|
|
10
|
+
export declare function recordingPath(file: string): string | null;
|