@slack/radar-mcp 1.13.0 → 1.17.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 +31 -3
- package/dist/mcp/db-tools.js +23 -0
- package/dist/mcp/dispatch.d.ts +4 -0
- package/dist/mcp/dispatch.js +26 -0
- package/dist/mcp/index.js +112 -33
- package/dist/mcp/platform-detect.d.ts +110 -0
- package/dist/mcp/platform-detect.js +246 -0
- package/dist/mcp/prefs-tools.d.ts +4 -3
- package/dist/mcp/prefs-tools.js +26 -3
- package/dist/mcp/session-enable.js +19 -1
- package/dist/mcp/snapshot.js +4 -1
- package/dist/mcp/sources-gate.js +6 -3
- package/dist/mcp/tools.d.ts +11 -0
- package/dist/mcp/tools.js +38 -0
- package/dist/shared/android.d.ts +40 -1
- package/dist/shared/android.js +114 -51
- package/dist/shared/constants.d.ts +25 -1
- package/dist/shared/constants.js +27 -1
- package/dist/shared/db.js +11 -2
- package/dist/shared/debug-log.js +6 -1
- package/dist/shared/enable-diagnosis.d.ts +28 -0
- package/dist/shared/enable-diagnosis.js +41 -0
- package/dist/shared/prefs.d.ts +0 -5
- package/dist/shared/prefs.js +6 -2
- package/dist/shared/screen.d.ts +46 -9
- package/dist/shared/screen.js +74 -11
- package/dist/shared/transport.d.ts +62 -5
- package/dist/shared/webapp.d.ts +50 -0
- package/dist/shared/webapp.js +65 -0
- package/dist/web/bin.js +16 -6
- package/dist/web/install-app.d.ts +87 -0
- package/dist/web/install-app.js +703 -0
- package/dist/web/macapp/RadarApp.swift +466 -0
- package/dist/web/public/icons/radar-1024.png +0 -0
- package/dist/web/public/icons/radar.svg +40 -0
- package/dist/web/public/index.html +42 -1
- package/dist/web/public/next/app.js +42 -1
- package/dist/web/public/next/db.js +153 -7
- package/dist/web/public/next/feed.js +18 -0
- package/dist/web/public/next/hooks.js +10 -1
- package/dist/web/public/next/screen.js +156 -46
- package/dist/web/public/next/store.js +164 -21
- package/dist/web/public/next/toast.js +134 -0
- package/dist/web/server.d.ts +151 -1
- package/dist/web/server.js +579 -22
- package/package.json +2 -2
package/dist/shared/android.js
CHANGED
|
@@ -7,6 +7,12 @@ import { filterLogLines, getCaptureFilePath, isCapturing, readRecentLogs, regist
|
|
|
7
7
|
import { RADAR_PORT, RADAR_VERSION } from "./constants.js";
|
|
8
8
|
const SOCKET_NAME = "slack-radar";
|
|
9
9
|
const ENABLE_ACTION = "slack.debug.ENABLE_RADAR";
|
|
10
|
+
/**
|
|
11
|
+
* Default ceiling for the `ps` process probe. Patient by design: on the MCP enable path
|
|
12
|
+
* several seconds of ping retries have already elapsed, so a slow adb is worth waiting out
|
|
13
|
+
* to get a real answer rather than an "unknown".
|
|
14
|
+
*/
|
|
15
|
+
const PS_PROBE_TIMEOUT_MS = 5000;
|
|
10
16
|
/**
|
|
11
17
|
* Resolve the adb binary. MCP servers spawned from GUI launchers (Spotlight,
|
|
12
18
|
* Raycast, Dock) do not inherit the user's shell PATH, so a bare `adb` call
|
|
@@ -24,6 +30,7 @@ export function resolveAdbPath() {
|
|
|
24
30
|
timeout: 2000,
|
|
25
31
|
encoding: "utf-8",
|
|
26
32
|
shell: "/bin/sh",
|
|
33
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
27
34
|
}).trim();
|
|
28
35
|
if (which && fs.existsSync(which))
|
|
29
36
|
return "adb";
|
|
@@ -123,6 +130,11 @@ export function parseAdbDevicesOutput(raw) {
|
|
|
123
130
|
}
|
|
124
131
|
export class AndroidTransport {
|
|
125
132
|
platform = "android";
|
|
133
|
+
// adb reaches the app's databases and shared prefs through run-as, so the DB and prefs tools
|
|
134
|
+
// (which shell to adb themselves) are cleared to run.
|
|
135
|
+
supportsLocalFileAccess = true;
|
|
136
|
+
// The dashboard's device arming and Reconnect flow is built around an adb-attached device.
|
|
137
|
+
supportsDeviceDashboard = true;
|
|
126
138
|
portForwarded = false;
|
|
127
139
|
detectedUserId = null;
|
|
128
140
|
currentTimeoutMinutes = 5;
|
|
@@ -153,7 +165,10 @@ export class AndroidTransport {
|
|
|
153
165
|
// remove fails harmlessly when no mapping exists. process.env.ANDROID_SERIAL (set by
|
|
154
166
|
// pin()) targets both calls at OUR device, not whichever adb would pick by default.
|
|
155
167
|
try {
|
|
156
|
-
execSync(`${ADB} forward --remove tcp:${RADAR_PORT}`, {
|
|
168
|
+
execSync(`${ADB} forward --remove tcp:${RADAR_PORT}`, {
|
|
169
|
+
timeout: 5000,
|
|
170
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
171
|
+
});
|
|
157
172
|
}
|
|
158
173
|
catch {
|
|
159
174
|
// No existing mapping, or adb hiccup; the add below surfaces real failures.
|
|
@@ -161,6 +176,7 @@ export class AndroidTransport {
|
|
|
161
176
|
try {
|
|
162
177
|
execSync(`${ADB} forward tcp:${RADAR_PORT} localabstract:${SOCKET_NAME}`, {
|
|
163
178
|
timeout: 5000,
|
|
179
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
164
180
|
});
|
|
165
181
|
this.portForwarded = true;
|
|
166
182
|
this.lastForwardError = null;
|
|
@@ -185,6 +201,7 @@ export class AndroidTransport {
|
|
|
185
201
|
const list = execSync(`${ADB} forward --list`, {
|
|
186
202
|
timeout: 5000,
|
|
187
203
|
encoding: "utf-8",
|
|
204
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
188
205
|
});
|
|
189
206
|
const wanted = `${serial} tcp:${RADAR_PORT} localabstract:${SOCKET_NAME}`;
|
|
190
207
|
if (list.split("\n").some((line) => line.trim() === wanted)) {
|
|
@@ -213,7 +230,7 @@ export class AndroidTransport {
|
|
|
213
230
|
return;
|
|
214
231
|
try {
|
|
215
232
|
const userId = this.detectDebugBuildUser();
|
|
216
|
-
execSync(`${ADB} shell am broadcast --user ${userId} -a ${ENABLE_ACTION} --ei timeout_minutes ${timeout} --es mcp_version ${RADAR_VERSION}`, { timeout: 5000 });
|
|
233
|
+
execSync(`${ADB} shell am broadcast --user ${userId} -a ${ENABLE_ACTION} --ei timeout_minutes ${timeout} --es mcp_version ${RADAR_VERSION}`, { timeout: 5000, stdio: ["ignore", "ignore", "pipe"] });
|
|
217
234
|
this.currentTimeoutMinutes = timeout;
|
|
218
235
|
this.radarEnabled = true;
|
|
219
236
|
this.lastActivateError = null;
|
|
@@ -274,12 +291,13 @@ export class AndroidTransport {
|
|
|
274
291
|
throw new Error("adb not found on PATH or common SDK locations");
|
|
275
292
|
const tmpFile = path.join(os.tmpdir(), `slack-radar-screenshot-${Date.now()}.png`);
|
|
276
293
|
const devicePath = "/data/local/tmp/slack-radar-screenshot.png";
|
|
277
|
-
|
|
278
|
-
execSync(`${ADB}
|
|
279
|
-
execSync(`${ADB}
|
|
294
|
+
const stdio = ["ignore", "ignore", "pipe"];
|
|
295
|
+
execSync(`${ADB} shell screencap -p ${devicePath}`, { timeout: 10000, stdio });
|
|
296
|
+
execSync(`${ADB} pull ${devicePath} "${tmpFile}"`, { timeout: 10000, stdio });
|
|
297
|
+
execSync(`${ADB} shell rm ${devicePath}`, { timeout: 5000, stdio });
|
|
280
298
|
if (!fullRes) {
|
|
281
299
|
try {
|
|
282
|
-
execSync(`sips -Z 720 "${tmpFile}" 2>/dev/null`, { timeout: 5000 });
|
|
300
|
+
execSync(`sips -Z 720 "${tmpFile}" 2>/dev/null`, { timeout: 5000, stdio });
|
|
283
301
|
}
|
|
284
302
|
catch {
|
|
285
303
|
// Resize failed; keep full res
|
|
@@ -293,15 +311,16 @@ export class AndroidTransport {
|
|
|
293
311
|
const duration = Math.min(Math.max(durationS, 1), 30);
|
|
294
312
|
const tmpFile = path.join(os.tmpdir(), `slack-radar-recording-${Date.now()}.mp4`);
|
|
295
313
|
const devicePath = "/data/local/tmp/slack-radar-recording.mp4";
|
|
296
|
-
|
|
297
|
-
execSync(`${ADB}
|
|
298
|
-
execSync(`${ADB}
|
|
314
|
+
const recordStdio = ["ignore", "ignore", "pipe"];
|
|
315
|
+
execSync(`${ADB} shell screenrecord --time-limit ${duration} --size 720x1280 ${devicePath}`, { timeout: (duration + 5) * 1000, stdio: recordStdio });
|
|
316
|
+
execSync(`${ADB} pull ${devicePath} "${tmpFile}"`, { timeout: 10000, stdio: recordStdio });
|
|
317
|
+
execSync(`${ADB} shell rm ${devicePath}`, { timeout: 5000, stdio: recordStdio });
|
|
299
318
|
return tmpFile;
|
|
300
319
|
}
|
|
301
320
|
getAppState() {
|
|
302
321
|
if (!ADB)
|
|
303
322
|
throw new Error("adb not found on PATH or common SDK locations");
|
|
304
|
-
return execSync(`${ADB} shell "dumpsys activity activities | grep -A 5 'com.Slack.internal'"`, { timeout: 10000, encoding: "utf-8" }).trim();
|
|
323
|
+
return execSync(`${ADB} shell "dumpsys activity activities | grep -A 5 'com.Slack.internal'"`, { timeout: 10000, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
305
324
|
}
|
|
306
325
|
getRecentLogs(tag, limit, grep) {
|
|
307
326
|
if (!ADB)
|
|
@@ -339,6 +358,7 @@ export class AndroidTransport {
|
|
|
339
358
|
timeout: 10000,
|
|
340
359
|
encoding: "utf-8",
|
|
341
360
|
maxBuffer: 64 * 1024 * 1024,
|
|
361
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
342
362
|
});
|
|
343
363
|
const lines = output.split("\n").filter(Boolean);
|
|
344
364
|
return {
|
|
@@ -346,33 +366,27 @@ export class AndroidTransport {
|
|
|
346
366
|
source: "logcat_ring",
|
|
347
367
|
};
|
|
348
368
|
}
|
|
369
|
+
// Shares psDebugBuildProbe's `ps` call rather than repeating the pipeline: two copies
|
|
370
|
+
// of the same command drifted independently once already.
|
|
349
371
|
listProfiles() {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
label: id === "0" ? "Personal (user 0)" : `Secondary (user ${id}, e.g. a work profile)`,
|
|
366
|
-
});
|
|
367
|
-
}
|
|
372
|
+
const fallback = [{ userId: "0", label: "Personal (user 0)" }];
|
|
373
|
+
const ps = this.psDebugBuildLine();
|
|
374
|
+
if (!ps)
|
|
375
|
+
return fallback;
|
|
376
|
+
const seen = new Set();
|
|
377
|
+
const profiles = [];
|
|
378
|
+
for (const line of ps.split("\n")) {
|
|
379
|
+
const match = line.match(/u(\d+)_/);
|
|
380
|
+
if (match && !seen.has(match[1])) {
|
|
381
|
+
seen.add(match[1]);
|
|
382
|
+
const id = match[1];
|
|
383
|
+
profiles.push({
|
|
384
|
+
userId: id,
|
|
385
|
+
label: id === "0" ? "Personal (user 0)" : `Secondary (user ${id}, e.g. a work profile)`,
|
|
386
|
+
});
|
|
368
387
|
}
|
|
369
|
-
return profiles.length > 0
|
|
370
|
-
? profiles
|
|
371
|
-
: [{ userId: "0", label: "Personal (user 0)" }];
|
|
372
|
-
}
|
|
373
|
-
catch {
|
|
374
|
-
return [{ userId: "0", label: "Personal (user 0)" }];
|
|
375
388
|
}
|
|
389
|
+
return profiles.length > 0 ? profiles : fallback;
|
|
376
390
|
}
|
|
377
391
|
activateForUser(userId, timeoutMinutes) {
|
|
378
392
|
if (!ADB)
|
|
@@ -382,7 +396,7 @@ export class AndroidTransport {
|
|
|
382
396
|
// scoped to a profile we could not detect, and appending this profile's
|
|
383
397
|
// run to it would mix profiles in one file. Rotating is the safe default.
|
|
384
398
|
const profileChanged = this.detectedUserId !== userId;
|
|
385
|
-
execSync(`${ADB} shell am broadcast --user ${userId} -a ${ENABLE_ACTION} --ei timeout_minutes ${timeout} --es mcp_version ${RADAR_VERSION}`, { timeout: 5000 });
|
|
399
|
+
execSync(`${ADB} shell am broadcast --user ${userId} -a ${ENABLE_ACTION} --ei timeout_minutes ${timeout} --es mcp_version ${RADAR_VERSION}`, { timeout: 5000, stdio: ["ignore", "ignore", "pipe"] });
|
|
386
400
|
this.detectedUserId = userId;
|
|
387
401
|
this.currentTimeoutMinutes = timeout;
|
|
388
402
|
this.radarEnabled = true;
|
|
@@ -408,6 +422,7 @@ export class AndroidTransport {
|
|
|
408
422
|
const raw = execSync(`${ADB} devices -l`, {
|
|
409
423
|
timeout: 5000,
|
|
410
424
|
encoding: "utf-8",
|
|
425
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
411
426
|
});
|
|
412
427
|
// Empty output parses to [] — a valid "no devices attached" success, distinct
|
|
413
428
|
// from the null below which means the listing itself failed.
|
|
@@ -513,26 +528,74 @@ export class AndroidTransport {
|
|
|
513
528
|
process.env.ANDROID_SERIAL = serial;
|
|
514
529
|
this.selectedDevice = { serial, label };
|
|
515
530
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
531
|
+
/**
|
|
532
|
+
* Fresh `ps` probe for debug-build Slack processes. Reports what it could establish,
|
|
533
|
+
* not a yes/no: "stopped" only when the device answered and matched nothing, "unknown"
|
|
534
|
+
* when it could not answer at all.
|
|
535
|
+
*
|
|
536
|
+
* Two details carry that distinction, and both are load-bearing.
|
|
537
|
+
*
|
|
538
|
+
* The trailing `|| true` keeps a grep no-match from looking like a failure. Without it,
|
|
539
|
+
* grep's exit 1 arrives as an execSync throw, identical to a detached device, an
|
|
540
|
+
* unauthorized device, a missing adb and a timeout, so every one of them would read as
|
|
541
|
+
* "not running".
|
|
542
|
+
*
|
|
543
|
+
* Running `ps` through a command substitution and exiting 9 when it fails keeps the
|
|
544
|
+
* opposite mistake from happening. Piping `ps` straight into grep discards ps's own exit
|
|
545
|
+
* status, so a device whose `ps` rejects `-o USER,NAME` produced empty output and exit 0
|
|
546
|
+
* and read as a CONFIRMED stop, which is precisely the failure class this return type
|
|
547
|
+
* exists to rule out. Exit 9 throws instead, landing on "unknown".
|
|
548
|
+
*
|
|
549
|
+
* @param timeoutMs Ceiling for the adb round trip. Callers diagnosing an already-known
|
|
550
|
+
* failure should pass something short; see DIAGNOSTIC_PS_TIMEOUT_MS in web/server.ts.
|
|
551
|
+
*/
|
|
552
|
+
psDebugBuildProbe(timeoutMs = PS_PROBE_TIMEOUT_MS) {
|
|
519
553
|
if (!ADB)
|
|
520
|
-
return "
|
|
554
|
+
return { state: "unknown", lines: "" };
|
|
521
555
|
try {
|
|
522
|
-
const ps = execSync(`${ADB} shell
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
// never receive the enable broadcast.
|
|
527
|
-
const match = ps.match(/u(\d+)_/);
|
|
528
|
-
if (!match)
|
|
529
|
-
return "0";
|
|
530
|
-
this.detectedUserId = parseUserFromPsOutput(ps);
|
|
531
|
-
return this.detectedUserId;
|
|
556
|
+
const ps = execSync(`${ADB} shell 'out=$(ps -A -o USER,NAME) || exit 9; echo "$out" | grep Slack | grep debug || true'`, { timeout: timeoutMs, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
557
|
+
return ps.length > 0
|
|
558
|
+
? { state: "running", lines: ps }
|
|
559
|
+
: { state: "stopped", lines: "" };
|
|
532
560
|
}
|
|
533
561
|
catch {
|
|
534
|
-
|
|
535
|
-
return "0";
|
|
562
|
+
return { state: "unknown", lines: "" };
|
|
536
563
|
}
|
|
537
564
|
}
|
|
565
|
+
/** Raw `ps` lines for running debug-build Slack processes, or null if there are none. */
|
|
566
|
+
psDebugBuildLine() {
|
|
567
|
+
const probe = this.psDebugBuildProbe();
|
|
568
|
+
return probe.state === "running" ? probe.lines : null;
|
|
569
|
+
}
|
|
570
|
+
detectDebugBuildUser() {
|
|
571
|
+
if (this.detectedUserId !== null)
|
|
572
|
+
return this.detectedUserId;
|
|
573
|
+
const ps = this.psDebugBuildLine();
|
|
574
|
+
if (!ps)
|
|
575
|
+
return "0";
|
|
576
|
+
// Cache only when a debug-build process was actually seen. Caching the "0"
|
|
577
|
+
// fallback would pin every later enable to user 0 for the process lifetime,
|
|
578
|
+
// so a work-profile build (user 10) launched after a failed detect would
|
|
579
|
+
// never receive the enable broadcast.
|
|
580
|
+
const match = ps.match(/u(\d+)_/);
|
|
581
|
+
if (!match)
|
|
582
|
+
return "0";
|
|
583
|
+
this.detectedUserId = parseUserFromPsOutput(ps);
|
|
584
|
+
return this.detectedUserId;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* State of the debug-build Slack process, checked fresh via `ps` (independent of
|
|
588
|
+
* detectDebugBuildUser's cache, so a process that died after the cache was set still
|
|
589
|
+
* reads as stopped). Lets the enable flow tell a confirmed stop apart from a probe
|
|
590
|
+
* that could not reach the device, which is the difference between naming the fix and
|
|
591
|
+
* guessing at it.
|
|
592
|
+
*
|
|
593
|
+
* @param timeoutMs Optional ceiling for the adb round trip, defaulting to
|
|
594
|
+
* PS_PROBE_TIMEOUT_MS. A caller that is only explaining a failure it has already
|
|
595
|
+
* detected should pass something shorter, so the explanation cannot cost more than
|
|
596
|
+
* the operation it explains.
|
|
597
|
+
*/
|
|
598
|
+
processState(timeoutMs) {
|
|
599
|
+
return this.psDebugBuildProbe(timeoutMs).state;
|
|
600
|
+
}
|
|
538
601
|
}
|
|
@@ -13,8 +13,24 @@ export declare const RADAR_VERSION: string;
|
|
|
13
13
|
* exists for tests only: stream lifecycle tests stand up a local server on an
|
|
14
14
|
* ephemeral port so they cannot collide with a real forwarded device on 8099.
|
|
15
15
|
* Set before module load, like SLACK_RADAR_WEB_PORT.
|
|
16
|
+
*
|
|
17
|
+
* `let`, not `const`: the webapp auto-detect path (mcp/platform-detect.ts, wired from
|
|
18
|
+
* createTransport()) needs to repoint every existing RADAR_HOST:RADAR_PORT caller
|
|
19
|
+
* (radarRequest, android.ts's adb forward target) at the webapp dev server's port
|
|
20
|
+
* AFTER this module has already loaded and android callers have already captured the
|
|
21
|
+
* initial value via import. setRadarPort() is the only sanctioned way to change it; the
|
|
22
|
+
* initial-value expression below must stay exactly as it is today so android's
|
|
23
|
+
* zero-config default (8099) never changes.
|
|
16
24
|
*/
|
|
17
|
-
export declare
|
|
25
|
+
export declare let RADAR_PORT: number;
|
|
26
|
+
/**
|
|
27
|
+
* Override RADAR_PORT after module load. Called exactly once, only by the webapp
|
|
28
|
+
* auto-detect/explicit-platform path in mcp/index.ts's createTransport() -- never on the
|
|
29
|
+
* android path, so android's RADAR_PORT resolution stays byte-for-byte identical to
|
|
30
|
+
* today. ES module `let` exports are live bindings, so every existing importer (stream.ts,
|
|
31
|
+
* android.ts, index.ts's radarRequest) sees the new value immediately, with no re-import.
|
|
32
|
+
*/
|
|
33
|
+
export declare function setRadarPort(port: number): void;
|
|
18
34
|
/** Host address for the forwarded connection. */
|
|
19
35
|
export declare const RADAR_HOST = "127.0.0.1";
|
|
20
36
|
/** Max events to retain in each local SSE buffer. */
|
|
@@ -39,6 +55,14 @@ export declare const MAX_LOG_SESSION_BUFFER = 20000;
|
|
|
39
55
|
* `SLACK_RADAR_WEB_PORT` env override.
|
|
40
56
|
*/
|
|
41
57
|
export declare const WEB_PORT_DEFAULT = 8100;
|
|
58
|
+
/**
|
|
59
|
+
* Default port the webapp Radar debug server listens on, matching
|
|
60
|
+
* webpack/util/default-dev-port.ts in the webapp repo. Hardcoded rather than imported: this
|
|
61
|
+
* package does not depend on the webapp repo. Separate constant from RADAR_PORT/WEB_PORT_DEFAULT
|
|
62
|
+
* -- it names the webapp target's OWN default, which platform-detect.ts probes before anything
|
|
63
|
+
* commits to redirecting RADAR_PORT at it.
|
|
64
|
+
*/
|
|
65
|
+
export declare const WEBAPP_DEFAULT_PORT = 1989;
|
|
42
66
|
/**
|
|
43
67
|
* The Slack debug build whose sandbox the host can `run-as` into. Both the
|
|
44
68
|
* on-device SQLite browser (db.ts) and the app log-buffer reader (debug-log.ts)
|
package/dist/shared/constants.js
CHANGED
|
@@ -26,8 +26,26 @@ export const RADAR_VERSION = (() => {
|
|
|
26
26
|
* exists for tests only: stream lifecycle tests stand up a local server on an
|
|
27
27
|
* ephemeral port so they cannot collide with a real forwarded device on 8099.
|
|
28
28
|
* Set before module load, like SLACK_RADAR_WEB_PORT.
|
|
29
|
+
*
|
|
30
|
+
* `let`, not `const`: the webapp auto-detect path (mcp/platform-detect.ts, wired from
|
|
31
|
+
* createTransport()) needs to repoint every existing RADAR_HOST:RADAR_PORT caller
|
|
32
|
+
* (radarRequest, android.ts's adb forward target) at the webapp dev server's port
|
|
33
|
+
* AFTER this module has already loaded and android callers have already captured the
|
|
34
|
+
* initial value via import. setRadarPort() is the only sanctioned way to change it; the
|
|
35
|
+
* initial-value expression below must stay exactly as it is today so android's
|
|
36
|
+
* zero-config default (8099) never changes.
|
|
29
37
|
*/
|
|
30
|
-
export
|
|
38
|
+
export let RADAR_PORT = Number(process.env.SLACK_RADAR_DEVICE_PORT) || 8099;
|
|
39
|
+
/**
|
|
40
|
+
* Override RADAR_PORT after module load. Called exactly once, only by the webapp
|
|
41
|
+
* auto-detect/explicit-platform path in mcp/index.ts's createTransport() -- never on the
|
|
42
|
+
* android path, so android's RADAR_PORT resolution stays byte-for-byte identical to
|
|
43
|
+
* today. ES module `let` exports are live bindings, so every existing importer (stream.ts,
|
|
44
|
+
* android.ts, index.ts's radarRequest) sees the new value immediately, with no re-import.
|
|
45
|
+
*/
|
|
46
|
+
export function setRadarPort(port) {
|
|
47
|
+
RADAR_PORT = port;
|
|
48
|
+
}
|
|
31
49
|
/** Host address for the forwarded connection. */
|
|
32
50
|
export const RADAR_HOST = "127.0.0.1";
|
|
33
51
|
/** Max events to retain in each local SSE buffer. */
|
|
@@ -52,6 +70,14 @@ export const MAX_LOG_SESSION_BUFFER = 20000;
|
|
|
52
70
|
* `SLACK_RADAR_WEB_PORT` env override.
|
|
53
71
|
*/
|
|
54
72
|
export const WEB_PORT_DEFAULT = 8100;
|
|
73
|
+
/**
|
|
74
|
+
* Default port the webapp Radar debug server listens on, matching
|
|
75
|
+
* webpack/util/default-dev-port.ts in the webapp repo. Hardcoded rather than imported: this
|
|
76
|
+
* package does not depend on the webapp repo. Separate constant from RADAR_PORT/WEB_PORT_DEFAULT
|
|
77
|
+
* -- it names the webapp target's OWN default, which platform-detect.ts probes before anything
|
|
78
|
+
* commits to redirecting RADAR_PORT at it.
|
|
79
|
+
*/
|
|
80
|
+
export const WEBAPP_DEFAULT_PORT = 1989;
|
|
55
81
|
/**
|
|
56
82
|
* The Slack debug build whose sandbox the host can `run-as` into. Both the
|
|
57
83
|
* on-device SQLite browser (db.ts) and the app log-buffer reader (debug-log.ts)
|
package/dist/shared/db.js
CHANGED
|
@@ -47,9 +47,13 @@ function adbBin() {
|
|
|
47
47
|
return p;
|
|
48
48
|
}
|
|
49
49
|
function runAdb(args, opts = {}) {
|
|
50
|
+
// Every caller reads the return value (toString() or the Buffer itself), so stdout
|
|
51
|
+
// stays "pipe"; stderr is "ignore" since no caller reads .stderr off a thrown error
|
|
52
|
+
// here, only catches and falls back — piping it would just leave it uncollected.
|
|
50
53
|
return execFileSync(adbBin(), args, {
|
|
51
54
|
timeout: 15000,
|
|
52
55
|
maxBuffer: ADB_MAX_BUFFER,
|
|
56
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
53
57
|
...opts,
|
|
54
58
|
});
|
|
55
59
|
}
|
|
@@ -74,9 +78,11 @@ function runAdbAsync(args) {
|
|
|
74
78
|
* binary, and only fall back to a working-but-fts5-less one if none has it (non-FTS DBs still
|
|
75
79
|
* work there). Cached after first success.
|
|
76
80
|
*/
|
|
81
|
+
// Neither probe reads stdout or stderr; both only check whether the call throws.
|
|
82
|
+
const PROBE_STDIO = ["ignore", "ignore", "ignore"];
|
|
77
83
|
function hasSqlite(bin) {
|
|
78
84
|
try {
|
|
79
|
-
execFileSync(bin, ["--version"], { timeout: 3000 });
|
|
85
|
+
execFileSync(bin, ["--version"], { timeout: 3000, stdio: PROBE_STDIO });
|
|
80
86
|
return true;
|
|
81
87
|
}
|
|
82
88
|
catch {
|
|
@@ -86,7 +92,10 @@ function hasSqlite(bin) {
|
|
|
86
92
|
function hasFts5(bin) {
|
|
87
93
|
try {
|
|
88
94
|
// throws "no such module: fts5" on a binary built without it
|
|
89
|
-
execFileSync(bin, [":memory:", "CREATE VIRTUAL TABLE t USING fts5(x);"], {
|
|
95
|
+
execFileSync(bin, [":memory:", "CREATE VIRTUAL TABLE t USING fts5(x);"], {
|
|
96
|
+
timeout: 3000,
|
|
97
|
+
stdio: PROBE_STDIO,
|
|
98
|
+
});
|
|
90
99
|
return true;
|
|
91
100
|
}
|
|
92
101
|
catch {
|
package/dist/shared/debug-log.js
CHANGED
|
@@ -75,7 +75,12 @@ export function readDebugLogBuffer(adbPath, user) {
|
|
|
75
75
|
// which exits 0 with the helper error in stdout).
|
|
76
76
|
const runAs = (userFlag) => {
|
|
77
77
|
try {
|
|
78
|
-
return execFileSync(adbPath, ["exec-out", `run-as ${LOG_PKG} ${userFlag}sh -c 'cat ${catList} 2>/dev/null'`], {
|
|
78
|
+
return execFileSync(adbPath, ["exec-out", `run-as ${LOG_PKG} ${userFlag}sh -c 'cat ${catList} 2>/dev/null'`], {
|
|
79
|
+
timeout: 10000,
|
|
80
|
+
maxBuffer: ADB_MAX_BUFFER,
|
|
81
|
+
encoding: "utf-8",
|
|
82
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
83
|
+
});
|
|
79
84
|
}
|
|
80
85
|
catch (err) {
|
|
81
86
|
return err instanceof Error ? err : new Error(String(err));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ProcessState } from "./transport.js";
|
|
2
|
+
/**
|
|
3
|
+
* What to tell the user when activation was broadcast but the device server never
|
|
4
|
+
* answered a ping.
|
|
5
|
+
*
|
|
6
|
+
* Only a confirmed "stopped" earns the sharper text. "unknown" means the probe could not
|
|
7
|
+
* reach the device (unplugged after the broadcast landed, unauthorized, adb dead) and the
|
|
8
|
+
* app may well be running fine, so it keeps the generic wording rather than asserting a
|
|
9
|
+
* launch is missing.
|
|
10
|
+
*
|
|
11
|
+
* The wording tracks what the probe actually looks for: a Slack process whose name
|
|
12
|
+
* contains "debug", which covers every debug flavour and deliberately no release or
|
|
13
|
+
* plain-internal build. Saying "no debug build" is therefore true, where "the Slack app is
|
|
14
|
+
* not running" is false for anyone whose com.Slack.internal dogfood build is on screen --
|
|
15
|
+
* and that reader is exactly who needs the debug-build hint.
|
|
16
|
+
*/
|
|
17
|
+
export declare function deviceServerSilentError(processState: ProcessState): string;
|
|
18
|
+
/**
|
|
19
|
+
* Read a transport's process probe without letting it break the caller's own failure
|
|
20
|
+
* report. An absent method and a throwing one are both "unknown": a diagnostic that
|
|
21
|
+
* cannot answer must not turn into a claim about the app.
|
|
22
|
+
*
|
|
23
|
+
* @param timeoutMs Optional ceiling handed to the transport. Pass a short one when the
|
|
24
|
+
* failure is already known and this call only explains it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readProcessState(device: {
|
|
27
|
+
processState?(timeoutMs?: number): ProcessState;
|
|
28
|
+
}, timeoutMs?: number): ProcessState;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to tell the user when activation was broadcast but the device server never
|
|
3
|
+
* answered a ping.
|
|
4
|
+
*
|
|
5
|
+
* Only a confirmed "stopped" earns the sharper text. "unknown" means the probe could not
|
|
6
|
+
* reach the device (unplugged after the broadcast landed, unauthorized, adb dead) and the
|
|
7
|
+
* app may well be running fine, so it keeps the generic wording rather than asserting a
|
|
8
|
+
* launch is missing.
|
|
9
|
+
*
|
|
10
|
+
* The wording tracks what the probe actually looks for: a Slack process whose name
|
|
11
|
+
* contains "debug", which covers every debug flavour and deliberately no release or
|
|
12
|
+
* plain-internal build. Saying "no debug build" is therefore true, where "the Slack app is
|
|
13
|
+
* not running" is false for anyone whose com.Slack.internal dogfood build is on screen --
|
|
14
|
+
* and that reader is exactly who needs the debug-build hint.
|
|
15
|
+
*/
|
|
16
|
+
export function deviceServerSilentError(processState) {
|
|
17
|
+
if (processState === "stopped") {
|
|
18
|
+
return ("Radar broadcast sent but the device server did not respond, and no debug build of " +
|
|
19
|
+
"the Slack app is running on the device. Radar only exists in debug builds, so launch " +
|
|
20
|
+
"one and retry. If it keeps stopping right after launch, that points at Radar's own " +
|
|
21
|
+
"activation code, not a missing launch.");
|
|
22
|
+
}
|
|
23
|
+
return ("Radar broadcast sent but the device server did not respond. Is a debug build with " +
|
|
24
|
+
"the slack-radar modules installed and running on the active profile?");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Read a transport's process probe without letting it break the caller's own failure
|
|
28
|
+
* report. An absent method and a throwing one are both "unknown": a diagnostic that
|
|
29
|
+
* cannot answer must not turn into a claim about the app.
|
|
30
|
+
*
|
|
31
|
+
* @param timeoutMs Optional ceiling handed to the transport. Pass a short one when the
|
|
32
|
+
* failure is already known and this call only explains it.
|
|
33
|
+
*/
|
|
34
|
+
export function readProcessState(device, timeoutMs) {
|
|
35
|
+
try {
|
|
36
|
+
return device.processState?.(timeoutMs) ?? "unknown";
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return "unknown";
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/shared/prefs.d.ts
CHANGED
|
@@ -11,11 +11,6 @@
|
|
|
11
11
|
* state. This reader only returns files/keys/values to the caller (no host-side file
|
|
12
12
|
* written), with a privacy note reminding the caller to review before sharing.
|
|
13
13
|
*/
|
|
14
|
-
/**
|
|
15
|
-
* List SharedPreferences files for a user, with their sizes.
|
|
16
|
-
* Via `run-as ... ls -la shared_prefs/` and parse name+size.
|
|
17
|
-
* Returns null on run-as failure.
|
|
18
|
-
*/
|
|
19
14
|
export declare function listPrefsFiles(adbPath: string, user?: string): {
|
|
20
15
|
user: string;
|
|
21
16
|
files: {
|
package/dist/shared/prefs.js
CHANGED
|
@@ -64,13 +64,17 @@ function assertSafeUser(user) {
|
|
|
64
64
|
* Via `run-as ... ls -la shared_prefs/` and parse name+size.
|
|
65
65
|
* Returns null on run-as failure.
|
|
66
66
|
*/
|
|
67
|
+
// Both listPrefsFiles calls read the return value via detectRunAsError/parseListOutput, so
|
|
68
|
+
// stdout stays "pipe"; stderr is "ignore", matching this file's own catch-and-return-null
|
|
69
|
+
// handling (no caller here reads .stderr off a thrown error).
|
|
70
|
+
const LIST_STDIO = ["ignore", "pipe", "ignore"];
|
|
67
71
|
export function listPrefsFiles(adbPath, user) {
|
|
68
72
|
if (user)
|
|
69
73
|
assertSafeUser(user);
|
|
70
74
|
try {
|
|
71
75
|
const resolvedUser = resolveUser(user);
|
|
72
76
|
const userFlag = `--user ${resolvedUser} `;
|
|
73
|
-
const out = execFileSync(adbPath, ["shell", `run-as ${PREFS_PKG} ${userFlag}ls -la shared_prefs/`], { timeout: 10000, maxBuffer: ADB_MAX_BUFFER, encoding: "utf-8" });
|
|
77
|
+
const out = execFileSync(adbPath, ["shell", `run-as ${PREFS_PKG} ${userFlag}ls -la shared_prefs/`], { timeout: 10000, maxBuffer: ADB_MAX_BUFFER, encoding: "utf-8", stdio: LIST_STDIO });
|
|
74
78
|
const runAsErr = detectRunAsError(out);
|
|
75
79
|
if (runAsErr) {
|
|
76
80
|
// Try without user flag as fallback (see debug-log.ts for rationale). Which user this
|
|
@@ -78,7 +82,7 @@ export function listPrefsFiles(adbPath, user) {
|
|
|
78
82
|
// profile it just failed to reach) — report "" (db.ts's convention for "ambiguous/
|
|
79
83
|
// implicit user") rather than mislabeling the result with the requested id.
|
|
80
84
|
try {
|
|
81
|
-
const retry = execFileSync(adbPath, ["shell", `run-as ${PREFS_PKG} ls -la shared_prefs/`], { timeout: 10000, maxBuffer: ADB_MAX_BUFFER, encoding: "utf-8" });
|
|
85
|
+
const retry = execFileSync(adbPath, ["shell", `run-as ${PREFS_PKG} ls -la shared_prefs/`], { timeout: 10000, maxBuffer: ADB_MAX_BUFFER, encoding: "utf-8", stdio: LIST_STDIO });
|
|
82
86
|
if (!detectRunAsError(retry)) {
|
|
83
87
|
return parseListOutput(retry, "");
|
|
84
88
|
}
|
package/dist/shared/screen.d.ts
CHANGED
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
*/
|
|
39
39
|
import { type ChildProcess } from "child_process";
|
|
40
40
|
/**
|
|
41
|
-
* Remove all
|
|
42
|
-
* live screen content and must not linger across sessions on disk. Called on
|
|
41
|
+
* Remove all captures from the screen tmp dir. Recordings and screenshots both hold
|
|
42
|
+
* sensitive live screen content and must not linger across sessions on disk. Called on
|
|
43
43
|
* resetScreenState() (device re-enable) and on process exit — the same posture the
|
|
44
|
-
* DB-browser uses for its pulled copies. Scoped to the
|
|
45
|
-
*
|
|
44
|
+
* DB-browser uses for its pulled copies. Scoped to the names this module writes so it
|
|
45
|
+
* never deletes an unrelated file that landed in the dir.
|
|
46
46
|
*/
|
|
47
47
|
export declare function cleanupRecordings(): void;
|
|
48
48
|
/** Resolve an ffmpeg binary, or null if none is installed. Cached. */
|
|
@@ -195,12 +195,49 @@ export declare const SCREEN_BOUNDARY = "radarframe";
|
|
|
195
195
|
export declare function startRecording(): string | null;
|
|
196
196
|
export declare function stopRecording(L?: LiveCast): Promise<string | null>;
|
|
197
197
|
/**
|
|
198
|
-
* Resolve a recording for download. Restricted to the screen tmp
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
198
|
+
* Resolve a capture (recording or screenshot) for download. Restricted to the screen tmp
|
|
199
|
+
* dir AND to the names this module writes: path.basename strips any directory (no
|
|
200
|
+
* traversal), and the prefix/extension check means a download request can only ever name
|
|
201
|
+
* a radar capture, never an arbitrary file that happened to land in the dir.
|
|
202
202
|
*/
|
|
203
|
-
export declare function
|
|
203
|
+
export declare function capturePath(file: string): string | null;
|
|
204
|
+
/**
|
|
205
|
+
* Why this reports which half failed instead of returning null for both: the caller turns a
|
|
206
|
+
* failure into user-facing text, and the two halves need different text. "is the device awake and
|
|
207
|
+
* connected?" is the right question when screencap came back empty and actively misleading when
|
|
208
|
+
* the phone answered fine and the HOST could not write the file (a full disk, a bad mode on the
|
|
209
|
+
* dir). Answering a disk problem with a question about the phone is the same dishonesty this
|
|
210
|
+
* two-phase route exists to remove.
|
|
211
|
+
*/
|
|
212
|
+
export type ScreenshotSaveResult = {
|
|
213
|
+
ok: true;
|
|
214
|
+
path: string;
|
|
215
|
+
} | {
|
|
216
|
+
ok: false;
|
|
217
|
+
reason: "capture-failed";
|
|
218
|
+
} | {
|
|
219
|
+
ok: false;
|
|
220
|
+
reason: "write-failed";
|
|
221
|
+
detail: string;
|
|
222
|
+
};
|
|
223
|
+
/** The user-facing wording for each way a screenshot save can fail. */
|
|
224
|
+
export declare function screenshotSaveErrorMessage(result: Extract<ScreenshotSaveResult, {
|
|
225
|
+
ok: false;
|
|
226
|
+
}>): string;
|
|
227
|
+
/**
|
|
228
|
+
* Capture a screenshot and write it to the screen tmp dir.
|
|
229
|
+
*
|
|
230
|
+
* Writing to disk is what makes the outcome reportable. Streaming the PNG straight back as
|
|
231
|
+
* a Content-Disposition attachment gave the browser no way to distinguish a saved file from
|
|
232
|
+
* a 403 or a 502: the response never reaches page JavaScript, and a download navigation
|
|
233
|
+
* fires neither load nor error on the frame that requested it. Landing the bytes first
|
|
234
|
+
* turns "did this work" into an ordinary JSON answer, which is the same two-phase shape
|
|
235
|
+
* /screen/record/stop already uses.
|
|
236
|
+
*
|
|
237
|
+
* Same on-disk posture as a recording, and for the same reason: a screenshot is a full
|
|
238
|
+
* frame of whatever is on the phone, so the dir is owner-only and the file owner-read/write.
|
|
239
|
+
*/
|
|
240
|
+
export declare function saveScreenshot(): Promise<ScreenshotSaveResult>;
|
|
204
241
|
/** Reset detection + tear down any live cast. Called on device re-enable and shutdown. */
|
|
205
242
|
export declare function resetScreenState(): void;
|
|
206
243
|
/**
|