@slack/radar-mcp 1.22.0 → 1.24.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 +62 -12
- package/dist/mcp/dashboard-identity.d.ts +10 -0
- package/dist/mcp/dashboard-identity.js +20 -0
- package/dist/mcp/debug-package-reset.d.ts +5 -0
- package/dist/mcp/debug-package-reset.js +28 -0
- package/dist/mcp/flags-tools.d.ts +2 -0
- package/dist/mcp/flags-tools.js +15 -1
- package/dist/mcp/index.js +172 -142
- package/dist/mcp/radar-http.d.ts +22 -0
- package/dist/mcp/radar-http.js +63 -0
- package/dist/mcp/radar-response.d.ts +1 -0
- package/dist/mcp/session-enable.d.ts +15 -0
- package/dist/mcp/session-enable.js +195 -33
- package/dist/mcp/sources-gate.js +5 -0
- package/dist/mcp/switchboard-tools.d.ts +5 -2
- package/dist/mcp/switchboard-tools.js +18 -12
- package/dist/mcp/test-cases.d.ts +14 -0
- package/dist/mcp/test-cases.js +77 -0
- package/dist/mcp/test-runs-tools.d.ts +8 -0
- package/dist/mcp/test-runs-tools.js +95 -0
- package/dist/mcp/tools.js +106 -171
- package/dist/mcp/web-child-env.js +2 -1
- package/dist/shared/android.d.ts +75 -10
- package/dist/shared/android.js +352 -109
- package/dist/shared/constants.d.ts +17 -5
- package/dist/shared/constants.js +59 -5
- package/dist/shared/db.d.ts +1 -1
- package/dist/shared/db.js +21 -14
- package/dist/shared/debug-log.js +2 -4
- package/dist/shared/enable-diagnosis.d.ts +27 -1
- package/dist/shared/enable-diagnosis.js +73 -0
- package/dist/shared/log-session.d.ts +2 -1
- package/dist/shared/logcat-capture.js +17 -1
- package/dist/shared/prefs.js +4 -5
- package/dist/shared/radar-request-raw.js +3 -1
- package/dist/shared/switchboard.d.ts +1 -0
- package/dist/shared/switchboard.js +3 -1
- package/dist/shared/transport.d.ts +30 -0
- package/dist/web/install-app.d.ts +18 -0
- package/dist/web/install-app.js +60 -7
- package/dist/web/macapp/RadarApp.swift +147 -1
- package/dist/web/server.d.ts +17 -0
- package/dist/web/server.js +180 -35
- package/package.json +1 -1
package/dist/mcp/index.js
CHANGED
|
@@ -9,24 +9,26 @@ import os from "os";
|
|
|
9
9
|
import path from "path";
|
|
10
10
|
import { fileURLToPath } from "url";
|
|
11
11
|
import { AndroidTransport } from "../shared/android.js";
|
|
12
|
+
import { BareEnableError, tokenViaArgvField } from "../shared/enable-diagnosis.js";
|
|
12
13
|
import { IosSimulatorTransport } from "../shared/ios.js";
|
|
13
14
|
import { WebappTransport } from "../shared/webapp.js";
|
|
14
15
|
import { webChildEnv } from "./web-child-env.js";
|
|
15
|
-
import { RADAR_HOST, RADAR_PORT, RADAR_VERSION, WEB_PORT_DEFAULT, WEBAPP_DEFAULT_PORT,
|
|
16
|
+
import { RADAR_HOST, RADAR_PORT, RADAR_VERSION, WEB_PORT_DEFAULT, WEBAPP_DEFAULT_PORT, slackDebugPackage, resetSlackDebugPackage, setRadarPort, } from "../shared/constants.js";
|
|
16
17
|
import { dashboardPlatformError, decidePlatform, pingLooksLikeWebappRadar, quickAndroidDeviceState, unsupportedCapabilityError, } from "./platform-detect.js";
|
|
17
18
|
import { stopCapture } from "../shared/logcat-capture.js";
|
|
18
19
|
import { getSpoolFilePath, epochFromSpoolPath, initializeSpoolDir, readSpool, startSpool, stopSpool, writeFrame, registerCleanup as registerSpoolCleanup, } from "../shared/event-spool.js";
|
|
19
20
|
import { connectStream, destroyStream, waitForEvents, clearLocalBuffers, isStreamConnected, wasStreamRejected, clearStreamRejected, localNetworkBuffer, localRtmBuffer, setTransport, setOnReconnect, } from "../shared/stream.js";
|
|
20
21
|
import { makeCallRadarForExport } from "./radar-export-get.js";
|
|
21
22
|
import { radarRequestRaw } from "../shared/radar-request-raw.js";
|
|
22
|
-
import { TokenFileError, clearRadarTokenCache, openModeWarning,
|
|
23
|
+
import { TokenFileError, clearRadarTokenCache, openModeWarning, tokenFileMessage, unauthorizedMessageFor } from "../shared/radar-token.js";
|
|
23
24
|
import { buildBufferPath, createSnapshot } from "./snapshot.js";
|
|
24
25
|
import { clampLogLimit, shapeLogsResult } from "./logs-result.js";
|
|
25
26
|
import { querySession, clampByteCap, toNum } from "./session-query.js";
|
|
26
27
|
import { resolveDetailById } from "./session-detail.js";
|
|
27
28
|
import { decorateToolResult } from "./network-detail.js";
|
|
28
|
-
import {
|
|
29
|
+
import { createEnabler } from "./session-enable.js";
|
|
29
30
|
import { applyEnableOutcome, clearSources, sourceGate } from "./sources-gate.js";
|
|
31
|
+
import { createDebugPackageReset } from "./debug-package-reset.js";
|
|
30
32
|
import { computeDispatch } from "./dispatch.js";
|
|
31
33
|
import { backfillSpool, BACKFILL_SOURCES, makeSerializedRunner, } from "./session-backfill.js";
|
|
32
34
|
import { handleListDatabases, handleListTables, handleQueryDatabase, } from "./db-tools.js";
|
|
@@ -34,12 +36,14 @@ import { handleListPrefs, handleGetPrefs, handleSearchPrefs, } from "./prefs-too
|
|
|
34
36
|
import { listFeatureFlags, searchFeatureFlags, getFeatureFlag, normalizeOverriddenArg, createFeatureFlagsCache, } from "./flags-tools.js";
|
|
35
37
|
import { cleanupPulledDatabases, initializeDatabasePath, resetDbState, } from "../shared/db.js";
|
|
36
38
|
import { TOOL_DEFINITIONS, serverInstructions, sessionGate } from "./tools.js";
|
|
37
|
-
import { dashboardMatchesDevice } from "./dashboard-identity.js";
|
|
39
|
+
import { dashboardDebugPackageError, dashboardMatchesDevice } from "./dashboard-identity.js";
|
|
38
40
|
import { buildApiPath } from "./api-paths.js";
|
|
39
|
-
import { dispatchExportSwitchboardSession, handleGetSwitchboardSession, handleGetSwitchboardSessions, shouldExportSwitchboardOffline, } from "./switchboard-tools.js";
|
|
41
|
+
import { dispatchExportSwitchboardSession, handleGetSwitchboardSession, handleGetSwitchboardSessions, sessionDisabledLine, shouldExportSwitchboardOffline, } from "./switchboard-tools.js";
|
|
40
42
|
import { getSpoolSwitchboardRecords, markSwitchboardSpoolCleared, newestSpoolSwitchboardSessionId } from "./switchboard-spool.js";
|
|
41
43
|
import { nonNegativeIntArg, SWITCHBOARD_EXPORT_SAFETY_CAP_BYTES, SWITCHBOARD_EXPORT_IDLE_MS, SWITCHBOARD_EXPORT_OVERALL_MS } from "../shared/switchboard.js";
|
|
42
|
-
import {
|
|
44
|
+
import { unauthorizedResponse } from "./radar-response.js";
|
|
45
|
+
import { DEFAULT_TIMEOUT_MS, radarHttpRequest, REQUEST_LOST_PREFIX, REQUEST_TIMED_OUT } from "./radar-http.js";
|
|
46
|
+
import { handleRunTestCase, handleGetTestRun, handleStopTestRun } from "./test-runs-tools.js";
|
|
43
47
|
import { buildOpenDashboardResult, readDashboardFingerprint } from "./stale-dashboard.js";
|
|
44
48
|
// --- Subcommand + bin-name dispatch ---
|
|
45
49
|
// See computeDispatch's own comment (dispatch.ts) for the full front-door table and rationale;
|
|
@@ -54,6 +58,10 @@ const wantsSelfHealCheck = wantsInstallApp && process.argv.includes("--self-heal
|
|
|
54
58
|
// registry-version precheck that only falls through to --self-heal-check once a real upgrade is
|
|
55
59
|
// confirmed. Checked before wantsSelfHealCheck below so the two flags stay mutually exclusive.
|
|
56
60
|
const wantsSelfHealPrecheck = wantsInstallApp && process.argv.includes("--self-heal-precheck");
|
|
61
|
+
// The two interactive halves of the app's Check for Updates... item: ask whether a newer build is
|
|
62
|
+
// published, then install it. Each prints a single JSON line for the app to read.
|
|
63
|
+
const wantsCheckUpdate = wantsInstallApp && process.argv.includes("--check-update");
|
|
64
|
+
const wantsUpdateNow = wantsInstallApp && process.argv.includes("--update-now");
|
|
57
65
|
// --- Web dashboard bridge (open_radar_dashboard) ---
|
|
58
66
|
//
|
|
59
67
|
// The MCP server and the web dashboard are separate processes. open_radar_dashboard
|
|
@@ -163,7 +171,7 @@ function getSpecTitle() {
|
|
|
163
171
|
req.end();
|
|
164
172
|
});
|
|
165
173
|
}
|
|
166
|
-
async function openDashboardSpec(device, spec) {
|
|
174
|
+
async function openDashboardSpec(device, spec, armed) {
|
|
167
175
|
const cold = !(await webAlive());
|
|
168
176
|
if (cold) {
|
|
169
177
|
// Seed the spec into the spawned server so it is the startup writer and the browser's
|
|
@@ -184,6 +192,11 @@ async function openDashboardSpec(device, spec) {
|
|
|
184
192
|
if (!dashboardMatchesDevice(device.platform, selected, health)) {
|
|
185
193
|
throw new Error("The dashboard port belongs to a different platform or device. Use a separate SLACK_RADAR_WEB_PORT.");
|
|
186
194
|
}
|
|
195
|
+
const packageError = device.platform === "android"
|
|
196
|
+
? dashboardDebugPackageError(armed, slackDebugPackage(), health)
|
|
197
|
+
: null;
|
|
198
|
+
if (packageError)
|
|
199
|
+
throw new Error(packageError);
|
|
187
200
|
// A dashboard keeps the version it started with, so read its version on both the cold and warm paths.
|
|
188
201
|
const fingerprint = await readDashboardFingerprint(WEB_BASE);
|
|
189
202
|
const r = await postSpec(spec);
|
|
@@ -204,7 +217,15 @@ async function openDashboardSpec(device, spec) {
|
|
|
204
217
|
return { ...r.json, fingerprint };
|
|
205
218
|
}
|
|
206
219
|
if (wantsInstallApp) {
|
|
207
|
-
if (
|
|
220
|
+
if (wantsCheckUpdate) {
|
|
221
|
+
const { checkForUpdate } = await import("../web/install-app.js");
|
|
222
|
+
console.log(JSON.stringify(await checkForUpdate(process.env.RADAR_APP_VERSION)));
|
|
223
|
+
}
|
|
224
|
+
else if (wantsUpdateNow) {
|
|
225
|
+
const { runUpdateNow } = await import("../web/install-app.js");
|
|
226
|
+
await runUpdateNow();
|
|
227
|
+
}
|
|
228
|
+
else if (wantsSelfHealPrecheck) {
|
|
208
229
|
const { runSelfHealPrecheck } = await import("../web/install-app.js");
|
|
209
230
|
runSelfHealPrecheck();
|
|
210
231
|
}
|
|
@@ -310,6 +331,14 @@ async function runMcpServer() {
|
|
|
310
331
|
// just-ended session stays readable.
|
|
311
332
|
registerSpoolCleanup();
|
|
312
333
|
let sessionEnabled = false;
|
|
334
|
+
const enabler = createEnabler({
|
|
335
|
+
isEnabled: () => sessionEnabled,
|
|
336
|
+
setEnabled: (on) => { sessionEnabled = on; },
|
|
337
|
+
applyEnableOutcome,
|
|
338
|
+
clearSources,
|
|
339
|
+
clearStreamRejected,
|
|
340
|
+
log: (line) => console.error(line),
|
|
341
|
+
});
|
|
313
342
|
// The envelope key each device list route wraps its rows in: /api/network -> {calls}, /api/rtm ->
|
|
314
343
|
// {events}, /api/clogs -> {clogs}, /api/traces -> {traces}. Read once against the same list routes
|
|
315
344
|
// buildApiPath pins. Defined here (the impure layer) since it is the device-response shape, not
|
|
@@ -380,56 +409,11 @@ async function runMcpServer() {
|
|
|
380
409
|
// a truncation marker rather than a partial JSON blob the parser would choke on. Bulk exports go
|
|
381
410
|
// through capture_snapshot, not this path. The ceiling now lives in constants so the device path
|
|
382
411
|
// and the session-query byte cap share one value.
|
|
383
|
-
function radarRequest(requestPath,
|
|
384
|
-
return
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
let settled = false;
|
|
389
|
-
const done = (r) => {
|
|
390
|
-
if (settled)
|
|
391
|
-
return;
|
|
392
|
-
settled = true;
|
|
393
|
-
resolve(r);
|
|
394
|
-
};
|
|
395
|
-
const fail = (e) => {
|
|
396
|
-
if (settled)
|
|
397
|
-
return;
|
|
398
|
-
settled = true;
|
|
399
|
-
reject(e);
|
|
400
|
-
};
|
|
401
|
-
const req = http.get({
|
|
402
|
-
host: RADAR_HOST,
|
|
403
|
-
port: RADAR_PORT,
|
|
404
|
-
headers: radarTokenHeaderFor(device),
|
|
405
|
-
path: requestPath,
|
|
406
|
-
timeout: timeoutMs,
|
|
407
|
-
}, (res) => {
|
|
408
|
-
let data = "";
|
|
409
|
-
let bytes = 0;
|
|
410
|
-
res.on("data", (chunk) => {
|
|
411
|
-
if (settled)
|
|
412
|
-
return;
|
|
413
|
-
bytes += chunk.length; // byte length, not String.length (UTF-8 over the wire)
|
|
414
|
-
if (bytes > MAX_RADAR_RESPONSE_BYTES) {
|
|
415
|
-
// Resolve the truncation NOW (not on "end" — req.destroy() aborts the response so
|
|
416
|
-
// "end" never fires; it surfaces as an "error" the settled-guard then swallows).
|
|
417
|
-
done(responseBudgetError());
|
|
418
|
-
req.destroy();
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
data += chunk;
|
|
422
|
-
});
|
|
423
|
-
res.on("end", () => {
|
|
424
|
-
done(interpretRadarResponse(res.statusCode ?? 0, data));
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
req.on("error", fail);
|
|
428
|
-
req.on("timeout", () => {
|
|
429
|
-
req.destroy();
|
|
430
|
-
fail(new Error("Request timed out"));
|
|
431
|
-
});
|
|
432
|
-
});
|
|
412
|
+
function radarRequest(requestPath, init = {}) {
|
|
413
|
+
return radarHttpRequest({ ...init, host: RADAR_HOST, port: RADAR_PORT, path: requestPath, transport: device });
|
|
414
|
+
}
|
|
415
|
+
function peerPing(deadlineMs) {
|
|
416
|
+
return radarRequest("/api/ping", { timeoutMs: 2000, deadlineMs: deadlineMs ?? Date.now() + 2000 });
|
|
433
417
|
}
|
|
434
418
|
// Reassert the shared adb forward before every HTTP-based device read. Prefer
|
|
435
419
|
// reassertForward() (repoints the shared port at OUR pinned device even if a separate
|
|
@@ -439,7 +423,10 @@ async function runMcpServer() {
|
|
|
439
423
|
function forwardForRead() {
|
|
440
424
|
return device.reassertForward?.() ?? device.ensureForward();
|
|
441
425
|
}
|
|
442
|
-
|
|
426
|
+
const REARM_BUDGET_MS = 30_000;
|
|
427
|
+
// Counts recovery re-arms so requests that fail together (a backfill fans out five) share one.
|
|
428
|
+
let recoveryRearms = 0;
|
|
429
|
+
async function callRadar(requestPath, init = {}) {
|
|
443
430
|
if (!device.supportsRadarHttpTools) {
|
|
444
431
|
return {
|
|
445
432
|
error: unsupportedCapabilityError(device.platform, "Radar HTTP tools"),
|
|
@@ -451,8 +438,11 @@ async function runMcpServer() {
|
|
|
451
438
|
};
|
|
452
439
|
}
|
|
453
440
|
const requestFromVerifiedPeer = async () => {
|
|
441
|
+
if (init.deadlineMs !== undefined && init.deadlineMs - Date.now() <= 0) {
|
|
442
|
+
return { error: "Radar did not answer in time. Call again." };
|
|
443
|
+
}
|
|
454
444
|
if (device.acceptsRadarPeer) {
|
|
455
|
-
const peer = await
|
|
445
|
+
const peer = await peerPing(init.deadlineMs);
|
|
456
446
|
if (!device.acceptsRadarPeer(peer)) {
|
|
457
447
|
return {
|
|
458
448
|
error: `The Radar listener on the shared host port does not belong to the selected ${device.platform} app.`,
|
|
@@ -463,33 +453,53 @@ async function runMcpServer() {
|
|
|
463
453
|
}
|
|
464
454
|
if (!wasStreamRejected())
|
|
465
455
|
connectStream();
|
|
466
|
-
return radarRequest(requestPath);
|
|
456
|
+
return radarRequest(requestPath, init);
|
|
467
457
|
};
|
|
468
458
|
const mismatch = (response) => unauthorizedResponse(response, device);
|
|
469
459
|
device.activate(device.getTimeoutMinutes());
|
|
460
|
+
const rearmsAtSend = recoveryRearms;
|
|
470
461
|
try {
|
|
471
462
|
return mismatch(await requestFromVerifiedPeer());
|
|
472
463
|
}
|
|
473
|
-
catch {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
464
|
+
catch (error) {
|
|
465
|
+
const timedOut = error.message === REQUEST_TIMED_OUT;
|
|
466
|
+
if (init.reportLost && init.deadlineMs !== undefined && init.deadlineMs - Date.now() < (init.timeoutMs ?? DEFAULT_TIMEOUT_MS) + REARM_BUDGET_MS) {
|
|
467
|
+
// the stream's own loop reconnects it. A teardown here leaves no timer, so capture stays off until the next device call
|
|
468
|
+
if (!timedOut)
|
|
469
|
+
device.resetState();
|
|
470
|
+
return { error: `${REQUEST_LOST_PREFIX}${error.message}. Call again.`, request_lost: true };
|
|
471
|
+
}
|
|
472
|
+
// A sibling request already re-armed since this one went out; a second broadcast would only restart it.
|
|
473
|
+
if (recoveryRearms === rearmsAtSend) {
|
|
474
|
+
device.resetState();
|
|
475
|
+
destroyStream();
|
|
476
|
+
if (!device.ensureForward()) {
|
|
477
|
+
sessionEnabled = false;
|
|
478
|
+
return {
|
|
479
|
+
error: "Device not connected or radar not running. Session disabled. Use /radar-enable to reconnect.",
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
// The re-arm is a fresh claim on the device, so a refusal from before it is stale.
|
|
483
|
+
clearStreamRejected();
|
|
484
|
+
recoveryRearms++;
|
|
481
485
|
}
|
|
486
|
+
// Also for a skipper: a no-op on an armed device, its own try if the sibling's arm failed.
|
|
487
|
+
// When that try is the one that lands, it is the re-arm, so the refusal it leaves behind is stale too.
|
|
488
|
+
const armFailedBefore = Boolean(device.getLastActivateError?.());
|
|
482
489
|
device.activate(device.getTimeoutMinutes());
|
|
483
|
-
|
|
484
|
-
|
|
490
|
+
if (armFailedBefore && !device.getLastActivateError?.()) {
|
|
491
|
+
destroyStream();
|
|
492
|
+
clearStreamRejected();
|
|
493
|
+
}
|
|
485
494
|
try {
|
|
486
495
|
return mismatch(await requestFromVerifiedPeer());
|
|
487
496
|
}
|
|
488
497
|
catch (e2) {
|
|
498
|
+
// a retry that times out may have reached the handler, so the read-back decides; any other retry error means the device is gone right after a re-broadcast
|
|
499
|
+
if (init.reportLost && e2.message === REQUEST_TIMED_OUT)
|
|
500
|
+
return { error: `${REQUEST_LOST_PREFIX}${e2.message}. Call again.`, request_lost: true };
|
|
489
501
|
sessionEnabled = false;
|
|
490
|
-
return {
|
|
491
|
-
error: `Radar not responding: ${e2.message}. Session disabled. Use /radar-enable to reconnect.`,
|
|
492
|
-
};
|
|
502
|
+
return { error: sessionDisabledLine(device, `Radar not responding: ${e2.message}.`) };
|
|
493
503
|
}
|
|
494
504
|
}
|
|
495
505
|
}
|
|
@@ -539,66 +549,64 @@ async function runMcpServer() {
|
|
|
539
549
|
};
|
|
540
550
|
}
|
|
541
551
|
// --- Tool handlers ---
|
|
552
|
+
// Not stopCapture (logcat is device-wide) and not cleanupPulledDatabases (pulled file names
|
|
553
|
+
// already carry the package).
|
|
554
|
+
const debugPackageReset = createDebugPackageReset(() => slackDebugPackage(), () => {
|
|
555
|
+
// Both callers run with a session that is, or is about to be, enabled, so the spool reopens.
|
|
556
|
+
stopSpool();
|
|
557
|
+
startSpool();
|
|
558
|
+
clearLocalBuffers();
|
|
559
|
+
clearSources();
|
|
560
|
+
featureFlagsCache.clear();
|
|
561
|
+
}, startSpool);
|
|
542
562
|
async function handleSessionEnable(args) {
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
//
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
//
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
//
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return textResult(outcome.body, !outcome.enabled);
|
|
591
|
-
}
|
|
592
|
-
catch (e) {
|
|
593
|
-
sessionEnabled = false;
|
|
594
|
-
clearSources();
|
|
595
|
-
destroyStream();
|
|
596
|
-
return textResult({
|
|
597
|
-
error: `Enable failed unexpectedly: ${e.message}`,
|
|
598
|
-
enabled: false,
|
|
599
|
-
platform: device.platform,
|
|
600
|
-
}, true);
|
|
601
|
-
}
|
|
563
|
+
const deviceSerial = args?.device_serial || null;
|
|
564
|
+
// The enabler owns the choice, counters and flag updates without starting stdio.
|
|
565
|
+
// This handler lends it the session flag and wires the real effects.
|
|
566
|
+
const deps = {
|
|
567
|
+
device,
|
|
568
|
+
forwardForRead,
|
|
569
|
+
destroyStream,
|
|
570
|
+
connectStream,
|
|
571
|
+
isStreamConnected,
|
|
572
|
+
wasStreamRejected,
|
|
573
|
+
resetDbState,
|
|
574
|
+
// After the arm and before the backfill: the spool reopens fresh and the backfill's have-set
|
|
575
|
+
// is built from the new file.
|
|
576
|
+
startSpool: () => debugPackageReset.startSpool(),
|
|
577
|
+
runBackfill: runBackfillSerialized,
|
|
578
|
+
// A health ping does not need the default 10s: a half-alive server
|
|
579
|
+
// (accepts TCP, never answers) would otherwise stretch the verify loop
|
|
580
|
+
// past the MCP client's 60s tool-call timeout, and the crafted error
|
|
581
|
+
// would never reach the user. 2s keeps worst-case enable wall time far
|
|
582
|
+
// under that ceiling.
|
|
583
|
+
ping: () => peerPing(),
|
|
584
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
585
|
+
onForeignOwnerAfterBackfill: () => {
|
|
586
|
+
debugPackageReset.forget();
|
|
587
|
+
// The backfill filled the rings from the foreign build too.
|
|
588
|
+
clearLocalBuffers();
|
|
589
|
+
stopSpool();
|
|
590
|
+
},
|
|
591
|
+
// Only fires on a switch to a different device: the prior device's buffers,
|
|
592
|
+
// spool, capture, and pulled DBs are stale for the new hardware.
|
|
593
|
+
onDeviceSwitch: () => {
|
|
594
|
+
debugPackageReset.forget();
|
|
595
|
+
clearLocalBuffers();
|
|
596
|
+
// Closing the spool is also what keeps the old device's switchboard records out of
|
|
597
|
+
// export_switchboard_session's device-free fallback.
|
|
598
|
+
stopSpool();
|
|
599
|
+
stopCapture();
|
|
600
|
+
cleanupPulledDatabases();
|
|
601
|
+
// The old device's declared sources and cached flags do not describe the new one.
|
|
602
|
+
clearSources();
|
|
603
|
+
featureFlagsCache.clear();
|
|
604
|
+
// The new device may run a different Slack debug build; the next arm re-detects it.
|
|
605
|
+
resetSlackDebugPackage();
|
|
606
|
+
},
|
|
607
|
+
};
|
|
608
|
+
const outcome = await enabler.enable(args?.timeout_minutes, deviceSerial, deps);
|
|
609
|
+
return textResult(outcome.body, !outcome.enabled);
|
|
602
610
|
}
|
|
603
611
|
function handleSessionDisable() {
|
|
604
612
|
device.stopLogCapture?.();
|
|
@@ -637,7 +645,7 @@ async function runMcpServer() {
|
|
|
637
645
|
if (device.acceptsRadarPeer) {
|
|
638
646
|
// connectStream() checks the peer too, but only by declining to connect; without this
|
|
639
647
|
// the tool would wait out its timeout and report "no events" from a foreign listener.
|
|
640
|
-
const peer = await
|
|
648
|
+
const peer = await peerPing().catch(() => null);
|
|
641
649
|
if (peer && !device.acceptsRadarPeer(peer)) {
|
|
642
650
|
return textResult({
|
|
643
651
|
error: `The Radar listener on the shared host port does not belong to the selected ${device.platform} app.`,
|
|
@@ -695,14 +703,16 @@ async function runMcpServer() {
|
|
|
695
703
|
}
|
|
696
704
|
}
|
|
697
705
|
async function handleActivateForUser(args) {
|
|
698
|
-
const
|
|
699
|
-
if (typeof
|
|
706
|
+
const { activateForUser } = device;
|
|
707
|
+
if (typeof activateForUser !== "function") {
|
|
700
708
|
return textResult({ error: `Profile switching not supported on platform ${device.platform}` }, true);
|
|
701
709
|
}
|
|
702
710
|
try {
|
|
703
711
|
const timeout = args?.timeout_minutes || device.getTimeoutMinutes() || 5;
|
|
704
712
|
clearRadarTokenCache();
|
|
705
|
-
|
|
713
|
+
enabler.switchProfile(() => activateForUser.call(device, args.user_id, timeout));
|
|
714
|
+
// The switch can land on another build; reset before its frames reach the old buffers.
|
|
715
|
+
debugPackageReset.check();
|
|
706
716
|
// Restart the SSE stream so network/RTM/clog events from the newly
|
|
707
717
|
// activated profile start flowing again.
|
|
708
718
|
destroyStream();
|
|
@@ -716,12 +726,13 @@ async function runMcpServer() {
|
|
|
716
726
|
return textResult({
|
|
717
727
|
user_id: args.user_id,
|
|
718
728
|
timeout_minutes: timeout,
|
|
729
|
+
...tokenViaArgvField(device),
|
|
719
730
|
capture_file: device.getCaptureFilePath?.() ?? null,
|
|
720
731
|
note: "Profile activated. Log capture restarted on a new file; old capture preserved for 7 days.",
|
|
721
732
|
});
|
|
722
733
|
}
|
|
723
734
|
catch (e) {
|
|
724
|
-
return textResult({ error: e instanceof TokenFileError ? tokenFileMessage(e, "profile") : `Profile activation failed: ${e.message}. Is the device connected? Check adb devices.` }, true);
|
|
735
|
+
return textResult({ error: e instanceof TokenFileError ? tokenFileMessage(e, "profile") : e instanceof BareEnableError ? e.message : `Profile activation failed: ${e.message}. Is the device connected? Check adb devices.` }, true);
|
|
725
736
|
}
|
|
726
737
|
}
|
|
727
738
|
async function handleCaptureSnapshot(args) {
|
|
@@ -844,18 +855,25 @@ async function runMcpServer() {
|
|
|
844
855
|
const result = await callRadar("/api/clear");
|
|
845
856
|
return textResult(result, !!result.error);
|
|
846
857
|
}
|
|
858
|
+
function dashboardUrlField() {
|
|
859
|
+
return dashboardPlatformError(device) ? {} : { dashboard_url: WEB_BASE };
|
|
860
|
+
}
|
|
847
861
|
async function handlePing(args) {
|
|
848
862
|
if (args?.timeout_minutes) {
|
|
849
863
|
device.activate(args.timeout_minutes);
|
|
850
864
|
const tokenFileError = device.getLastActivateTokenFileError?.();
|
|
851
|
-
if (tokenFileError)
|
|
852
|
-
return textResult({ error: tokenFileError.message, mcp_version: RADAR_VERSION }, true);
|
|
865
|
+
if (tokenFileError) {
|
|
866
|
+
return textResult({ error: tokenFileError.message, mcp_version: RADAR_VERSION, ...dashboardUrlField() }, true);
|
|
867
|
+
}
|
|
853
868
|
}
|
|
854
869
|
const result = await callRadar("/api/ping");
|
|
855
870
|
// Version is a property of this process, not the device, so it is reported
|
|
856
871
|
// even when the device probe fails — the error path is exactly when a
|
|
857
872
|
// reviewer needs to correlate a report against a known-bad release.
|
|
858
873
|
result.mcp_version = RADAR_VERSION;
|
|
874
|
+
// Same reasoning: the dashboard address comes from this process's port setting, so it is
|
|
875
|
+
// reported even when the device is down. It says where the dashboard lives, not whether it runs.
|
|
876
|
+
Object.assign(result, dashboardUrlField());
|
|
859
877
|
if (!result.error) {
|
|
860
878
|
result.stream_connected = isStreamConnected();
|
|
861
879
|
result.local_network_buffer = localNetworkBuffer.length;
|
|
@@ -882,7 +900,7 @@ async function runMcpServer() {
|
|
|
882
900
|
// The web server runs its own coerce+validate on /setspec, so a thin pass of
|
|
883
901
|
// the authored args is enough; a bad spec comes back as an HTTP 400 with its
|
|
884
902
|
// reason, which we surface verbatim rather than rendering silent zeros.
|
|
885
|
-
const out = await openDashboardSpec(device, args);
|
|
903
|
+
const out = await openDashboardSpec(device, args, sessionEnabled);
|
|
886
904
|
return textResult(buildOpenDashboardResult({ ...out, title: out.title ?? args.title }, out.fingerprint, RADAR_VERSION, WEB_BASE));
|
|
887
905
|
}
|
|
888
906
|
catch (e) {
|
|
@@ -893,7 +911,7 @@ async function runMcpServer() {
|
|
|
893
911
|
}
|
|
894
912
|
}
|
|
895
913
|
// --- MCP Server ---
|
|
896
|
-
const server = new Server({ name: "slack-radar", version: "1.
|
|
914
|
+
const server = new Server({ name: "slack-radar", version: "1.24.0" }, { capabilities: { tools: {} }, instructions: serverInstructions(device.platform) });
|
|
897
915
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
898
916
|
tools: TOOL_DEFINITIONS,
|
|
899
917
|
}));
|
|
@@ -1017,6 +1035,18 @@ async function runMcpServer() {
|
|
|
1017
1035
|
}
|
|
1018
1036
|
// The switchboard tools validate host-side and answer a bad id with a reason, where the generic
|
|
1019
1037
|
// buildApiPath fallthrough below would only say "unknown tool" for a null path.
|
|
1038
|
+
if (name === "run_test_case") {
|
|
1039
|
+
const { data, isError } = await handleRunTestCase(toolArgs, callRadar);
|
|
1040
|
+
return textResult(data, isError);
|
|
1041
|
+
}
|
|
1042
|
+
if (name === "get_test_run") {
|
|
1043
|
+
const { data, isError } = await handleGetTestRun(toolArgs, callRadar);
|
|
1044
|
+
return textResult(data, isError);
|
|
1045
|
+
}
|
|
1046
|
+
if (name === "stop_test_run") {
|
|
1047
|
+
const { data, isError } = await handleStopTestRun(toolArgs, callRadar);
|
|
1048
|
+
return textResult(data, isError);
|
|
1049
|
+
}
|
|
1020
1050
|
if (name === "get_switchboard_sessions") {
|
|
1021
1051
|
const { data, isError } = await handleGetSwitchboardSessions(callRadar);
|
|
1022
1052
|
return textResult(data, isError);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type RadarTokenSender } from "../shared/radar-token.js";
|
|
2
|
+
import { type RadarResponse } from "./radar-response.js";
|
|
3
|
+
export declare const REQUEST_LOST_PREFIX = "Radar did not answer in time: ";
|
|
4
|
+
export declare const REQUEST_TIMED_OUT = "Request timed out";
|
|
5
|
+
export declare const DEFAULT_TIMEOUT_MS = 10000;
|
|
6
|
+
export interface RadarRequestInit {
|
|
7
|
+
method?: "POST" | "DELETE";
|
|
8
|
+
body?: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
deadlineMs?: number;
|
|
11
|
+
reportLost?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function radarHttpRequest({ host, port, path, method, body, timeoutMs, deadlineMs, transport }: {
|
|
14
|
+
host: string;
|
|
15
|
+
port: number;
|
|
16
|
+
path: string;
|
|
17
|
+
method?: string;
|
|
18
|
+
body?: string;
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
deadlineMs?: number;
|
|
21
|
+
transport: RadarTokenSender;
|
|
22
|
+
}): Promise<RadarResponse>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import http from "http";
|
|
2
|
+
import { MAX_RADAR_RESPONSE_BYTES } from "../shared/constants.js";
|
|
3
|
+
import { radarTokenHeaderFor } from "../shared/radar-token.js";
|
|
4
|
+
import { interpretRadarResponse, responseBudgetError } from "./radar-response.js";
|
|
5
|
+
export const REQUEST_LOST_PREFIX = "Radar did not answer in time: ";
|
|
6
|
+
export const REQUEST_TIMED_OUT = "Request timed out";
|
|
7
|
+
export const DEFAULT_TIMEOUT_MS = 10_000;
|
|
8
|
+
export function radarHttpRequest({ host, port, path, method = "GET", body, timeoutMs = DEFAULT_TIMEOUT_MS, deadlineMs, transport }) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
let settled = false;
|
|
11
|
+
let overallTimer;
|
|
12
|
+
const done = (response) => {
|
|
13
|
+
if (settled)
|
|
14
|
+
return;
|
|
15
|
+
settled = true;
|
|
16
|
+
clearTimeout(overallTimer);
|
|
17
|
+
resolve(response);
|
|
18
|
+
};
|
|
19
|
+
const fail = (error) => {
|
|
20
|
+
if (settled)
|
|
21
|
+
return;
|
|
22
|
+
settled = true;
|
|
23
|
+
clearTimeout(overallTimer);
|
|
24
|
+
reject(error);
|
|
25
|
+
};
|
|
26
|
+
// agent: false so no request rides a pooled socket the device already closed; that reads as
|
|
27
|
+
// a dead device (ECONNRESET) and costs a re-arm.
|
|
28
|
+
const req = http.request({
|
|
29
|
+
host, port, path, method, timeout: timeoutMs, agent: false,
|
|
30
|
+
headers: {
|
|
31
|
+
...radarTokenHeaderFor(transport),
|
|
32
|
+
...(body === undefined ? {} : {
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
"Content-Length": Buffer.byteLength(body),
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
}, (res) => {
|
|
38
|
+
let data = "";
|
|
39
|
+
let bytes = 0;
|
|
40
|
+
res.on("data", (chunk) => {
|
|
41
|
+
if (settled)
|
|
42
|
+
return;
|
|
43
|
+
bytes += chunk.length;
|
|
44
|
+
if (bytes > MAX_RADAR_RESPONSE_BYTES) {
|
|
45
|
+
done(responseBudgetError());
|
|
46
|
+
req.destroy();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
data += chunk;
|
|
50
|
+
});
|
|
51
|
+
res.on("end", () => done(interpretRadarResponse(res.statusCode ?? 0, data)));
|
|
52
|
+
});
|
|
53
|
+
req.on("error", fail);
|
|
54
|
+
const timedOut = () => {
|
|
55
|
+
req.destroy();
|
|
56
|
+
fail(new Error(REQUEST_TIMED_OUT));
|
|
57
|
+
};
|
|
58
|
+
req.on("timeout", timedOut);
|
|
59
|
+
if (deadlineMs !== undefined)
|
|
60
|
+
overallTimer = setTimeout(timedOut, Math.max(0, Math.min(timeoutMs, deadlineMs - Date.now())));
|
|
61
|
+
req.end(body);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DeviceTransport } from "../shared/transport.js";
|
|
2
2
|
export interface EnableDeps {
|
|
3
3
|
device: DeviceTransport;
|
|
4
|
+
forwardForRead?: () => boolean;
|
|
4
5
|
destroyStream: () => void;
|
|
5
6
|
connectStream: () => void;
|
|
6
7
|
isStreamConnected: () => boolean;
|
|
@@ -11,9 +12,23 @@ export interface EnableDeps {
|
|
|
11
12
|
ping: () => Promise<Record<string, unknown>>;
|
|
12
13
|
sleep: (ms: number) => Promise<void>;
|
|
13
14
|
onDeviceSwitch: () => void;
|
|
15
|
+
onForeignOwnerAfterBackfill?: () => void;
|
|
14
16
|
}
|
|
15
17
|
export interface EnableOutcome {
|
|
16
18
|
body: Record<string, unknown>;
|
|
17
19
|
enabled: boolean;
|
|
18
20
|
}
|
|
21
|
+
export interface EnablerHooks {
|
|
22
|
+
isEnabled: () => boolean;
|
|
23
|
+
setEnabled: (enabled: boolean) => void;
|
|
24
|
+
applyEnableOutcome: (outcome: EnableOutcome) => void;
|
|
25
|
+
clearSources: () => void;
|
|
26
|
+
clearStreamRejected: () => void;
|
|
27
|
+
log: (line: string) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare function createEnabler(hooks: EnablerHooks): {
|
|
30
|
+
switchProfile(broadcast: () => void): void;
|
|
31
|
+
enable(timeoutMinutes: number | null | undefined, deviceSerial: string | null, deps: EnableDeps): Promise<EnableOutcome>;
|
|
32
|
+
};
|
|
33
|
+
export declare function refreshEnabledSession(timeoutMinutes: number | null, deviceSerial: string | null, deps: EnableDeps): Promise<EnableOutcome | null>;
|
|
19
34
|
export declare function runSessionEnable(timeoutMinutes: number, deviceSerial: string | null, deps: EnableDeps): Promise<EnableOutcome>;
|