@slack/radar-mcp 1.20.0 → 1.22.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 +75 -17
- package/dist/mcp/api-paths.d.ts +11 -0
- package/dist/mcp/api-paths.js +56 -20
- package/dist/mcp/dashboard-identity.d.ts +6 -0
- package/dist/mcp/dashboard-identity.js +11 -0
- package/dist/mcp/index.js +138 -36
- package/dist/mcp/logs-result.d.ts +1 -0
- package/dist/mcp/logs-result.js +1 -0
- package/dist/mcp/network-detail.d.ts +5 -0
- package/dist/mcp/network-detail.js +86 -0
- package/dist/mcp/radar-export-get.d.ts +30 -0
- package/dist/mcp/radar-export-get.js +49 -0
- package/dist/mcp/radar-response.d.ts +11 -1
- package/dist/mcp/radar-response.js +23 -3
- package/dist/mcp/session-backfill.d.ts +9 -3
- package/dist/mcp/session-backfill.js +76 -17
- package/dist/mcp/session-detail.js +54 -2
- package/dist/mcp/session-enable.d.ts +1 -0
- package/dist/mcp/session-enable.js +146 -15
- package/dist/mcp/session-query.js +53 -11
- package/dist/mcp/snapshot.js +42 -26
- package/dist/mcp/sources-gate.js +5 -0
- package/dist/mcp/stale-dashboard.d.ts +23 -0
- package/dist/mcp/stale-dashboard.js +122 -0
- package/dist/mcp/switchboard-spool.d.ts +12 -0
- package/dist/mcp/switchboard-spool.js +107 -0
- package/dist/mcp/switchboard-tools.d.ts +18 -0
- package/dist/mcp/switchboard-tools.js +178 -0
- package/dist/mcp/tools.d.ts +4 -1
- package/dist/mcp/tools.js +114 -23
- package/dist/mcp/web-child-env.d.ts +4 -1
- package/dist/mcp/web-child-env.js +4 -1
- package/dist/shared/android.d.ts +43 -0
- package/dist/shared/android.js +227 -19
- package/dist/shared/constants.d.ts +19 -4
- package/dist/shared/constants.js +19 -4
- package/dist/shared/event-spool.js +3 -2
- package/dist/shared/feature-flags.d.ts +1 -0
- package/dist/shared/feature-flags.js +1 -0
- package/dist/shared/form-body.d.ts +18 -0
- package/dist/shared/form-body.js +251 -0
- package/dist/shared/ios-logs.d.ts +10 -0
- package/dist/shared/ios-logs.js +91 -0
- package/dist/shared/ios.d.ts +25 -2
- package/dist/shared/ios.js +157 -3
- package/dist/{web → shared}/log-session.d.ts +45 -31
- package/dist/shared/log-session.js +300 -0
- package/dist/shared/radar-request-raw.d.ts +7 -0
- package/dist/shared/radar-request-raw.js +89 -0
- package/dist/shared/radar-token.d.ts +25 -0
- package/dist/shared/radar-token.js +164 -0
- package/dist/shared/stream.d.ts +4 -1
- package/dist/shared/stream.js +107 -15
- package/dist/shared/switchboard-host-store.d.ts +21 -0
- package/dist/shared/switchboard-host-store.js +166 -0
- package/dist/shared/switchboard-note.d.ts +15 -0
- package/dist/shared/switchboard-note.js +92 -0
- package/dist/shared/switchboard-report-file.d.ts +5 -0
- package/dist/shared/switchboard-report-file.js +26 -0
- package/dist/shared/switchboard-report.d.ts +20 -0
- package/dist/shared/switchboard-report.js +406 -0
- package/dist/shared/switchboard.d.ts +118 -0
- package/dist/shared/switchboard.js +487 -0
- package/dist/shared/transport.d.ts +43 -3
- package/dist/shared/version.d.ts +2 -0
- package/dist/shared/version.js +18 -0
- package/dist/shared/wire.d.ts +46 -1
- package/dist/web/install-app.d.ts +57 -8
- package/dist/web/install-app.js +270 -60
- package/dist/web/macapp/RadarApp.swift +340 -22
- package/dist/web/public/index.html +216 -12
- package/dist/web/public/next/app.js +43 -22
- package/dist/web/public/next/db.js +4 -1
- package/dist/web/public/next/feed.js +604 -59
- package/dist/web/public/next/filters.js +158 -40
- package/dist/web/public/next/flags.js +3 -0
- package/dist/web/public/next/form-body.js +252 -0
- package/dist/web/public/next/inspector.js +171 -14
- package/dist/web/public/next/prefs.js +5 -2
- package/dist/web/public/next/registry.js +35 -3
- package/dist/web/public/next/store.js +947 -69
- package/dist/web/public/next/switchboard-note.js +93 -0
- package/dist/web/public/next/toast.js +9 -5
- package/dist/web/public/next/voice-model.js +712 -0
- package/dist/web/public/next/voice.js +552 -0
- package/dist/web/server.d.ts +20 -9
- package/dist/web/server.js +834 -174
- package/dist/web/spec.d.ts +11 -6
- package/dist/web/spec.js +62 -6
- package/package.json +4 -4
- package/dist/web/log-session.js +0 -166
package/dist/shared/android.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { execFile, execSync, execFileSync } from "child_process";
|
|
1
|
+
import { execFile, execSync, execFileSync, spawn, } from "child_process";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import os from "os";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { promisify } from "util";
|
|
6
6
|
import { readDebugLogBuffer } from "./debug-log.js";
|
|
7
7
|
import { filterLogLines, getCaptureFilePath, isCapturing, readRecentLogs, registerCleanup, rotateCaptureIfNeeded, startCapture, stopCapture, } from "./logcat-capture.js";
|
|
8
|
-
import { RADAR_PORT, RADAR_VERSION } from "./constants.js";
|
|
8
|
+
import { RADAR_PORT, RADAR_VERSION, SLACK_DEBUG_PKG } from "./constants.js";
|
|
9
|
+
import { getOrCreateRadarToken } from "./radar-token.js";
|
|
10
|
+
import { LogSession } from "./log-session.js";
|
|
9
11
|
const SOCKET_NAME = "slack-radar";
|
|
10
12
|
const ENABLE_ACTION = "slack.debug.ENABLE_RADAR";
|
|
11
13
|
/**
|
|
@@ -23,6 +25,35 @@ const PS_PROBE_TIMEOUT_MS = 5000;
|
|
|
23
25
|
const LIST_DEVICES_TIMEOUT_MS = Number(process.env.SLACK_RADAR_ADB_LIST_TIMEOUT_MS) > 0
|
|
24
26
|
? Number(process.env.SLACK_RADAR_ADB_LIST_TIMEOUT_MS)
|
|
25
27
|
: 5000;
|
|
28
|
+
// The enable broadcast waits for ordered delivery, and a cold debug build has been observed to
|
|
29
|
+
// hold completion past 5 seconds, so it gets a taller ceiling than the quick adb queries.
|
|
30
|
+
const ENABLE_BROADCAST_TIMEOUT_MS = 15_000;
|
|
31
|
+
function stderrText(raw) {
|
|
32
|
+
// Redact before the cut so a token crossing it cannot survive.
|
|
33
|
+
const text = (typeof raw === "string" ? raw : Buffer.isBuffer(raw) ? raw.toString("utf8") : "")
|
|
34
|
+
.replace(/[0-9a-f]{64,}/g, "<redacted>");
|
|
35
|
+
const lines = text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
36
|
+
const firstLine = lines[0] ?? "";
|
|
37
|
+
const reason = firstLine.endsWith(":") && lines[1] ? `${firstLine} ${lines[1]}` : firstLine;
|
|
38
|
+
// ADB tags and trailing punctuation would repeat the caller wording.
|
|
39
|
+
return reason.slice(0, 200)
|
|
40
|
+
.replace(/^(?:adb: |error: )+/, "")
|
|
41
|
+
.replace(/[.!]+$/, "");
|
|
42
|
+
}
|
|
43
|
+
// Return a bare reason because every caller adds its own failure wording.
|
|
44
|
+
export function describeBroadcastFailure(error) {
|
|
45
|
+
const failure = error;
|
|
46
|
+
// execFile (async) marks a timeout kill with killed; execFileSync reports code ETIMEDOUT.
|
|
47
|
+
if (failure.killed || failure.code === "ETIMEDOUT") {
|
|
48
|
+
return `timed out after ${ENABLE_BROADCAST_TIMEOUT_MS / 1000}s ` +
|
|
49
|
+
"(the device or the debug build did not finish delivering the broadcast)";
|
|
50
|
+
}
|
|
51
|
+
const reason = stderrText(failure.stderr);
|
|
52
|
+
const exitCode = typeof failure.status === "number" ? failure.status : typeof failure.code === "number" ? failure.code : null;
|
|
53
|
+
const errno = typeof failure.code === "string" ? failure.code : null;
|
|
54
|
+
const head = exitCode !== null ? `adb exited ${exitCode}` : errno ? `adb failed (${errno})` : "adb failed";
|
|
55
|
+
return reason ? `${head}: ${reason}` : head;
|
|
56
|
+
}
|
|
26
57
|
/**
|
|
27
58
|
* Resolve the adb binary. MCP servers spawned from GUI launchers (Spotlight,
|
|
28
59
|
* Raycast, Dock) do not inherit the user's shell PATH, so a bare `adb` call
|
|
@@ -76,6 +107,109 @@ export function resolveAdbPath() {
|
|
|
76
107
|
// Module-level resolution, done once at import time. The MCP process lifetime
|
|
77
108
|
// is short enough (session-scoped) that we do not need to re-resolve.
|
|
78
109
|
const ADB = resolveAdbPath();
|
|
110
|
+
// Logcat line parsing for the dashboard's transport-owned host log session. Format:
|
|
111
|
+
// "MM-DD HH:MM:SS.mmm PID TID L Tag: message"
|
|
112
|
+
const LOG_LINE_RE = /^(\d\d-\d\d \d\d:\d\d:\d\d\.\d+)\s+(\d+)\s+(\d+)\s+([VDIWEF])\s+([^:]*?):\s?(.*)$/;
|
|
113
|
+
const LOG_LEVELS = {
|
|
114
|
+
V: "VERBOSE",
|
|
115
|
+
D: "DEBUG",
|
|
116
|
+
I: "INFO",
|
|
117
|
+
W: "WARN",
|
|
118
|
+
E: "ERROR",
|
|
119
|
+
F: "FATAL",
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* A device-scoped PID -> package snapshot for dashboard log rows.
|
|
123
|
+
*
|
|
124
|
+
* Android reuses PIDs, and a dashboard can switch between devices without restarting its
|
|
125
|
+
* process. Replacing the whole snapshot on refresh, rather than appending to a module-global
|
|
126
|
+
* map, prevents a PID on the new process/device from inheriting the old package label.
|
|
127
|
+
*/
|
|
128
|
+
export class AndroidPidPackageMap {
|
|
129
|
+
spawnProcessList;
|
|
130
|
+
packages = new Map();
|
|
131
|
+
refreshVersion = 0;
|
|
132
|
+
activeRefresh = 0;
|
|
133
|
+
lastRefresh = 0;
|
|
134
|
+
constructor(spawnProcessList = () => {
|
|
135
|
+
const adb = resolveAdbPath();
|
|
136
|
+
return adb ? spawn(adb, ["shell", "ps", "-A", "-o", "PID,NAME"]) : null;
|
|
137
|
+
}) {
|
|
138
|
+
this.spawnProcessList = spawnProcessList;
|
|
139
|
+
}
|
|
140
|
+
resolve(pid) {
|
|
141
|
+
const hit = this.packages.get(pid);
|
|
142
|
+
if (hit !== undefined)
|
|
143
|
+
return hit;
|
|
144
|
+
// Unknown PID: a rate-limited refresh so a later line resolves. A hit never refreshes,
|
|
145
|
+
// so steady logs from known processes do not keep `adb shell ps` running.
|
|
146
|
+
if (Date.now() - this.lastRefresh > 3000)
|
|
147
|
+
this.refresh();
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
refresh() {
|
|
151
|
+
if (this.activeRefresh !== 0)
|
|
152
|
+
return;
|
|
153
|
+
const ps = this.spawnProcessList();
|
|
154
|
+
if (!ps)
|
|
155
|
+
return;
|
|
156
|
+
const version = ++this.refreshVersion;
|
|
157
|
+
this.activeRefresh = version;
|
|
158
|
+
this.lastRefresh = Date.now();
|
|
159
|
+
let out = "";
|
|
160
|
+
let failed = false;
|
|
161
|
+
ps.stdout?.on("data", (chunk) => (out += chunk.toString()));
|
|
162
|
+
ps.on("error", () => {
|
|
163
|
+
failed = true;
|
|
164
|
+
if (this.activeRefresh === version)
|
|
165
|
+
this.activeRefresh = 0;
|
|
166
|
+
});
|
|
167
|
+
ps.on("close", (code) => {
|
|
168
|
+
if (this.activeRefresh === version)
|
|
169
|
+
this.activeRefresh = 0;
|
|
170
|
+
if (failed || code !== 0 || this.refreshVersion !== version)
|
|
171
|
+
return;
|
|
172
|
+
const next = new Map();
|
|
173
|
+
for (const line of out.split("\n")) {
|
|
174
|
+
const match = line.trim().match(/^(\d+)\s+(\S+)$/);
|
|
175
|
+
if (match)
|
|
176
|
+
next.set(Number(match[1]), match[2]);
|
|
177
|
+
}
|
|
178
|
+
// A listing that parsed to nothing (a device mid-reboot, a truncated shell) says nothing
|
|
179
|
+
// about which PIDs exist, so it must not wipe the labels lines are still resolving against.
|
|
180
|
+
if (next.size > 0)
|
|
181
|
+
this.packages = next;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
reset() {
|
|
185
|
+
// Invalidate an in-flight `ps` result. It may still emit close later, but its
|
|
186
|
+
// version can no longer replace the new device's package snapshot.
|
|
187
|
+
this.refreshVersion++;
|
|
188
|
+
this.activeRefresh = 0;
|
|
189
|
+
this.packages.clear();
|
|
190
|
+
this.lastRefresh = 0;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
let dashboardLogIdSequence = 0;
|
|
194
|
+
/** Parse one adb logcat threadtime line into the dashboard's normalized log frame. */
|
|
195
|
+
export function parseAndroidLogcat(line, resolvePackage = () => undefined) {
|
|
196
|
+
const match = line.match(LOG_LINE_RE);
|
|
197
|
+
if (!match)
|
|
198
|
+
return null;
|
|
199
|
+
const [, logTimestamp, pid, tid, level, tag, message] = match;
|
|
200
|
+
const numericPid = Number(pid);
|
|
201
|
+
return {
|
|
202
|
+
id: ++dashboardLogIdSequence,
|
|
203
|
+
timestamp: Date.now(),
|
|
204
|
+
log_ts: logTimestamp,
|
|
205
|
+
pid: numericPid,
|
|
206
|
+
tid: Number(tid),
|
|
207
|
+
level: LOG_LEVELS[level] ?? level,
|
|
208
|
+
tag: tag.trim(),
|
|
209
|
+
message,
|
|
210
|
+
package: resolvePackage(numericPid),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
79
213
|
// Promisified execFile for the *Async transport methods below. argv form (no shell), so an
|
|
80
214
|
// interpolated value can never break out of a command string, and stdout/stderr are captured
|
|
81
215
|
// rather than inherited, matching the stdio discipline execsync-stdio.test.mjs pins.
|
|
@@ -87,8 +221,8 @@ const ADB_NOT_FOUND_FORWARD_ERROR = "adb binary not found. Set ANDROID_HOME or i
|
|
|
87
221
|
// comment for why the `|| exit 9` and the trailing `|| true` are each load-bearing.
|
|
88
222
|
const PS_DEBUG_BUILD_SCRIPT = 'out=$(ps -A -o USER,NAME) || exit 9; echo "$out" | grep Slack | grep debug || true';
|
|
89
223
|
// The enable broadcast, in argv form so the sync and async activate paths send the exact
|
|
90
|
-
// same command.
|
|
91
|
-
function enableBroadcastArgs(userId, timeoutMinutes) {
|
|
224
|
+
// same command. The package target keeps other receivers from reading the token.
|
|
225
|
+
function enableBroadcastArgs(userId, timeoutMinutes, token) {
|
|
92
226
|
return [
|
|
93
227
|
"shell",
|
|
94
228
|
"am",
|
|
@@ -97,12 +231,17 @@ function enableBroadcastArgs(userId, timeoutMinutes) {
|
|
|
97
231
|
userId,
|
|
98
232
|
"-a",
|
|
99
233
|
ENABLE_ACTION,
|
|
234
|
+
"-p",
|
|
235
|
+
SLACK_DEBUG_PKG,
|
|
100
236
|
"--ei",
|
|
101
237
|
"timeout_minutes",
|
|
102
238
|
String(timeoutMinutes),
|
|
103
239
|
"--es",
|
|
104
240
|
"mcp_version",
|
|
105
241
|
RADAR_VERSION,
|
|
242
|
+
"--es",
|
|
243
|
+
"radar_token",
|
|
244
|
+
token,
|
|
106
245
|
];
|
|
107
246
|
}
|
|
108
247
|
/**
|
|
@@ -167,10 +306,22 @@ export function parseAdbDevicesOutput(raw) {
|
|
|
167
306
|
}
|
|
168
307
|
return devices;
|
|
169
308
|
}
|
|
309
|
+
function spawnAndroidLogcat() {
|
|
310
|
+
const adb = resolveAdbPath();
|
|
311
|
+
if (!adb)
|
|
312
|
+
throw new Error(ADB_NOT_FOUND_FORWARD_ERROR);
|
|
313
|
+
return spawn(adb, ["logcat", "-v", "threadtime", "-T", "1"], {
|
|
314
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
315
|
+
});
|
|
316
|
+
}
|
|
170
317
|
export class AndroidTransport {
|
|
171
318
|
platform = "android";
|
|
319
|
+
logPackage = SLACK_DEBUG_PKG;
|
|
320
|
+
supportsHostLogs = true;
|
|
321
|
+
logSession;
|
|
172
322
|
// The Android debug build serves Radar's HTTP API through the adb-forwarded local socket.
|
|
173
323
|
supportsRadarHttpTools = true;
|
|
324
|
+
sendsRadarToken = true;
|
|
174
325
|
// adb reaches the app's databases and shared prefs through run-as, so the DB and prefs tools
|
|
175
326
|
// (which shell to adb themselves) are cleared to run.
|
|
176
327
|
supportsLocalFileAccess = true;
|
|
@@ -182,9 +333,21 @@ export class AndroidTransport {
|
|
|
182
333
|
radarEnabled = false;
|
|
183
334
|
lastForwardError = null;
|
|
184
335
|
lastActivateError = null;
|
|
336
|
+
lastActivateTokenFileError = null;
|
|
185
337
|
// The device pinned by selectDevice, surfaced via getSelectedDevice for the enable
|
|
186
338
|
// body and web /health. Not cleared by resetState: the env pin is sticky by design.
|
|
187
339
|
selectedDevice = null;
|
|
340
|
+
dashboardPidPackages;
|
|
341
|
+
constructor(dependencies = {}) {
|
|
342
|
+
this.dashboardPidPackages = new AndroidPidPackageMap(dependencies.spawnProcessList);
|
|
343
|
+
const spawnLogcat = dependencies.spawnLogcat ?? spawnAndroidLogcat;
|
|
344
|
+
this.logSession = new LogSession(() => {
|
|
345
|
+
const child = spawnLogcat();
|
|
346
|
+
// Warm the PID labels only once the capture exists, so a failed spawn costs no `ps`.
|
|
347
|
+
this.dashboardPidPackages.refresh();
|
|
348
|
+
return child;
|
|
349
|
+
}, (line) => parseAndroidLogcat(line, (pid) => this.dashboardPidPackages.resolve(pid)));
|
|
350
|
+
}
|
|
188
351
|
ensureForward() {
|
|
189
352
|
if (this.portForwarded)
|
|
190
353
|
return true;
|
|
@@ -324,12 +487,15 @@ export class AndroidTransport {
|
|
|
324
487
|
const timeout = timeoutMinutes || this.currentTimeoutMinutes;
|
|
325
488
|
if (this.radarEnabled && timeout === this.currentTimeoutMinutes)
|
|
326
489
|
return;
|
|
490
|
+
const token = this.readArmToken();
|
|
491
|
+
if (token === null)
|
|
492
|
+
return;
|
|
327
493
|
try {
|
|
328
494
|
const userId = this.detectDebugBuildUser();
|
|
329
495
|
// Same taller ceiling as the async twin: the broadcast waits for ordered delivery and a
|
|
330
496
|
// cold debug build can hold completion past 5 seconds.
|
|
331
|
-
execFileSync(ADB, enableBroadcastArgs(userId, timeout), {
|
|
332
|
-
timeout:
|
|
497
|
+
execFileSync(ADB, enableBroadcastArgs(userId, timeout, token), {
|
|
498
|
+
timeout: ENABLE_BROADCAST_TIMEOUT_MS,
|
|
333
499
|
stdio: ["ignore", "ignore", "pipe"],
|
|
334
500
|
});
|
|
335
501
|
this.recordActivateSuccess(timeout);
|
|
@@ -352,12 +518,15 @@ export class AndroidTransport {
|
|
|
352
518
|
const timeout = timeoutMinutes || this.currentTimeoutMinutes;
|
|
353
519
|
if (this.radarEnabled && timeout === this.currentTimeoutMinutes)
|
|
354
520
|
return;
|
|
521
|
+
const token = this.readArmToken();
|
|
522
|
+
if (token === null)
|
|
523
|
+
return;
|
|
355
524
|
try {
|
|
356
525
|
const userId = await this.detectDebugBuildUserAsync();
|
|
357
526
|
// The broadcast waits for ordered delivery, and a cold debug build has been observed to
|
|
358
527
|
// hold completion past 5 seconds; a killed broadcast reads as a failed arm, so this one
|
|
359
528
|
// call gets a taller ceiling than the quick adb queries.
|
|
360
|
-
await execFileAsync(ADB, enableBroadcastArgs(userId, timeout), { timeout:
|
|
529
|
+
await execFileAsync(ADB, enableBroadcastArgs(userId, timeout, token), { timeout: ENABLE_BROADCAST_TIMEOUT_MS });
|
|
361
530
|
this.recordActivateSuccess(timeout);
|
|
362
531
|
}
|
|
363
532
|
catch (e) {
|
|
@@ -394,6 +563,7 @@ export class AndroidTransport {
|
|
|
394
563
|
this.currentTimeoutMinutes = timeout;
|
|
395
564
|
this.radarEnabled = true;
|
|
396
565
|
this.lastActivateError = null;
|
|
566
|
+
this.lastActivateTokenFileError = null;
|
|
397
567
|
registerCleanup();
|
|
398
568
|
if (ADB)
|
|
399
569
|
startCapture(ADB);
|
|
@@ -404,17 +574,33 @@ export class AndroidTransport {
|
|
|
404
574
|
// later activate() early-return and never re-send the broadcast.
|
|
405
575
|
recordActivateFailure(e) {
|
|
406
576
|
this.radarEnabled = false;
|
|
407
|
-
this.lastActivateError = e
|
|
577
|
+
this.lastActivateError = describeBroadcastFailure(e);
|
|
578
|
+
}
|
|
579
|
+
readArmToken() {
|
|
580
|
+
this.lastActivateTokenFileError = null;
|
|
581
|
+
try {
|
|
582
|
+
return getOrCreateRadarToken();
|
|
583
|
+
}
|
|
584
|
+
catch (error) {
|
|
585
|
+
this.radarEnabled = false;
|
|
586
|
+
this.lastActivateTokenFileError = error;
|
|
587
|
+
this.lastActivateError = error.message;
|
|
588
|
+
return null;
|
|
589
|
+
}
|
|
408
590
|
}
|
|
409
591
|
getLastActivateError() {
|
|
410
592
|
return this.lastActivateError;
|
|
411
593
|
}
|
|
594
|
+
getLastActivateTokenFileError() {
|
|
595
|
+
return this.lastActivateTokenFileError;
|
|
596
|
+
}
|
|
412
597
|
resetState() {
|
|
413
598
|
this.portForwarded = false;
|
|
414
599
|
this.detectedUserId = null;
|
|
415
600
|
this.radarEnabled = false;
|
|
416
601
|
this.lastForwardError = null;
|
|
417
602
|
this.lastActivateError = null;
|
|
603
|
+
this.lastActivateTokenFileError = null;
|
|
418
604
|
// Capture has its own idle timer; not stopped on activation reset (see logcat-capture.ts).
|
|
419
605
|
}
|
|
420
606
|
dropForward() {
|
|
@@ -523,16 +709,22 @@ export class AndroidTransport {
|
|
|
523
709
|
source: "logcat_ring",
|
|
524
710
|
};
|
|
525
711
|
}
|
|
712
|
+
stopLogCapture() {
|
|
713
|
+
stopCapture();
|
|
714
|
+
this.logSession.stop();
|
|
715
|
+
}
|
|
526
716
|
// Shares psDebugBuildProbe's `ps` call rather than repeating the pipeline: two copies
|
|
527
717
|
// of the same command drifted independently once already.
|
|
528
718
|
listProfiles() {
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
719
|
+
const probe = this.psDebugBuildProbe();
|
|
720
|
+
if (probe.state !== "running") {
|
|
721
|
+
throw new Error(probe.state === "stopped"
|
|
722
|
+
? "The Slack debug build is not running. Start it, then call list_profiles again."
|
|
723
|
+
: "Could not check for the Slack debug build. Connect exactly one device and make sure adb is installed, then call list_profiles again.");
|
|
724
|
+
}
|
|
533
725
|
const seen = new Set();
|
|
534
726
|
const profiles = [];
|
|
535
|
-
for (const line of
|
|
727
|
+
for (const line of probe.lines.split("\n")) {
|
|
536
728
|
const match = line.match(/u(\d+)_/);
|
|
537
729
|
if (match && !seen.has(match[1])) {
|
|
538
730
|
seen.add(match[1]);
|
|
@@ -543,7 +735,7 @@ export class AndroidTransport {
|
|
|
543
735
|
});
|
|
544
736
|
}
|
|
545
737
|
}
|
|
546
|
-
return profiles.length > 0 ? profiles :
|
|
738
|
+
return profiles.length > 0 ? profiles : [{ userId: "0", label: "Personal (user 0)" }];
|
|
547
739
|
}
|
|
548
740
|
activateForUser(userId, timeoutMinutes) {
|
|
549
741
|
if (!ADB)
|
|
@@ -553,12 +745,19 @@ export class AndroidTransport {
|
|
|
553
745
|
// scoped to a profile we could not detect, and appending this profile's
|
|
554
746
|
// run to it would mix profiles in one file. Rotating is the safe default.
|
|
555
747
|
const profileChanged = this.detectedUserId !== userId;
|
|
748
|
+
this.lastActivateTokenFileError = null;
|
|
749
|
+
const token = getOrCreateRadarToken();
|
|
556
750
|
// The same argv and the same tall ceiling as activate's twins: the broadcast waits for
|
|
557
751
|
// ordered delivery and a cold debug build can hold completion past 5 seconds.
|
|
558
|
-
|
|
559
|
-
timeout
|
|
560
|
-
|
|
561
|
-
|
|
752
|
+
try {
|
|
753
|
+
execFileSync(ADB, enableBroadcastArgs(userId, timeout, token), {
|
|
754
|
+
timeout: ENABLE_BROADCAST_TIMEOUT_MS,
|
|
755
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
catch (error) {
|
|
759
|
+
throw new Error(describeBroadcastFailure(error));
|
|
760
|
+
}
|
|
562
761
|
this.detectedUserId = userId;
|
|
563
762
|
this.currentTimeoutMinutes = timeout;
|
|
564
763
|
this.radarEnabled = true;
|
|
@@ -627,8 +826,10 @@ export class AndroidTransport {
|
|
|
627
826
|
if (!this.selectedDevice)
|
|
628
827
|
return;
|
|
629
828
|
const stillAttached = devices.some((d) => d.serial === this.selectedDevice.serial && d.state === "device");
|
|
630
|
-
if (!stillAttached)
|
|
829
|
+
if (!stillAttached) {
|
|
631
830
|
this.selectedDevice = null;
|
|
831
|
+
this.dashboardPidPackages.reset();
|
|
832
|
+
}
|
|
632
833
|
}
|
|
633
834
|
selectDevice(serial) {
|
|
634
835
|
return this.pickFromListing(this.listDevices(), serial, true);
|
|
@@ -737,6 +938,13 @@ export class AndroidTransport {
|
|
|
737
938
|
// ~30 of them) targets this device without per-call plumbing, and record it for
|
|
738
939
|
// getSelectedDevice. adb devices ignores ANDROID_SERIAL, so listing stays global.
|
|
739
940
|
pin(serial, label) {
|
|
941
|
+
const prior = this.selectedDevice?.serial ?? (process.env.ANDROID_SERIAL || null);
|
|
942
|
+
if (prior !== null && prior !== serial) {
|
|
943
|
+
// Both belong to the old device: its PID labels, and a logcat child that inherited the old
|
|
944
|
+
// ANDROID_SERIAL and would keep reading that device. restart() also drops the old ring.
|
|
945
|
+
this.dashboardPidPackages.reset();
|
|
946
|
+
this.logSession.restart();
|
|
947
|
+
}
|
|
740
948
|
process.env.ANDROID_SERIAL = serial;
|
|
741
949
|
this.selectedDevice = { serial, label };
|
|
742
950
|
}
|
|
@@ -36,6 +36,8 @@ export declare function setRadarPort(port: number): void;
|
|
|
36
36
|
export declare const RADAR_HOST = "127.0.0.1";
|
|
37
37
|
/** Max events to retain in each local SSE buffer. */
|
|
38
38
|
export declare const MAX_LOCAL_BUFFER = 500;
|
|
39
|
+
/** Waits between device pings after an enable broadcast. */
|
|
40
|
+
export declare const ENABLE_PING_WAITS_MS: readonly number[];
|
|
39
41
|
/**
|
|
40
42
|
* Max parsed logcat frames the web dashboard retains for the whole server
|
|
41
43
|
* session. The device does not buffer logcat host-side, so the dashboard keeps
|
|
@@ -44,12 +46,15 @@ export declare const MAX_LOCAL_BUFFER = 500;
|
|
|
44
46
|
* instead of only the lines that arrive after the reconnect. Bounded so a long,
|
|
45
47
|
* chatty session cannot grow without limit. logcat is captured for ALL apps (the
|
|
46
48
|
* dashboard filters by package client-side), so the depth is sized for an all-app
|
|
47
|
-
* stream
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* the oldest lines age out once the cap is reached, not kept forever.
|
|
49
|
+
* stream. A separate estimated-byte ceiling handles stack-trace-heavy sessions.
|
|
50
|
+
* Like Android Studio's logcat, retention is a bounded ring — the oldest lines
|
|
51
|
+
* age out once either cap is reached, not kept forever.
|
|
51
52
|
*/
|
|
52
53
|
export declare const MAX_LOG_SESSION_BUFFER = 20000;
|
|
54
|
+
/** Maximum estimated serialized size of one host-captured log frame. */
|
|
55
|
+
export declare const MAX_LOG_FRAME_BYTES: number;
|
|
56
|
+
/** Maximum estimated serialized size retained by one host log session. */
|
|
57
|
+
export declare const MAX_LOG_SESSION_BYTES: number;
|
|
53
58
|
/**
|
|
54
59
|
* Default port for the web dashboard. Shared so the MCP `open_radar_dashboard`
|
|
55
60
|
* tool POSTs its spec to the same port the web server listens on; both honor the
|
|
@@ -87,3 +92,13 @@ export declare const MAX_RADAR_RESPONSE_BYTES: number;
|
|
|
87
92
|
* any future second caller of this cap shares it rather than risking drift.
|
|
88
93
|
*/
|
|
89
94
|
export declare const MAX_PREFS_RESPONSE_BYTES: number;
|
|
95
|
+
/**
|
|
96
|
+
* Past this many UTF-8 bytes get_network_call_detail (and a query_session id read) skip the decoded
|
|
97
|
+
* copy of a form-encoded request body and say so in request_body_decoded_omitted; the raw bytes
|
|
98
|
+
* still ride in request_body. The decoded pretty print runs about three times the raw, so the copy
|
|
99
|
+
* would otherwise pile onto an already large payload in the model context. Both the raw body and
|
|
100
|
+
* the decoded pretty print are measured against this one number. The label is the prose form
|
|
101
|
+
* every note and tool description in the server uses, so the number is spelled once there.
|
|
102
|
+
*/
|
|
103
|
+
export declare const MAX_FORM_DECODE_BYTES: number;
|
|
104
|
+
export declare const FORM_DECODE_LIMIT_LABEL = "64 KB";
|
package/dist/shared/constants.js
CHANGED
|
@@ -51,6 +51,8 @@ export function setRadarPort(port) {
|
|
|
51
51
|
export const RADAR_HOST = "127.0.0.1";
|
|
52
52
|
/** Max events to retain in each local SSE buffer. */
|
|
53
53
|
export const MAX_LOCAL_BUFFER = 500;
|
|
54
|
+
/** Waits between device pings after an enable broadcast. */
|
|
55
|
+
export const ENABLE_PING_WAITS_MS = [500, 1000, 1000];
|
|
54
56
|
/**
|
|
55
57
|
* Max parsed logcat frames the web dashboard retains for the whole server
|
|
56
58
|
* session. The device does not buffer logcat host-side, so the dashboard keeps
|
|
@@ -59,12 +61,15 @@ export const MAX_LOCAL_BUFFER = 500;
|
|
|
59
61
|
* instead of only the lines that arrive after the reconnect. Bounded so a long,
|
|
60
62
|
* chatty session cannot grow without limit. logcat is captured for ALL apps (the
|
|
61
63
|
* dashboard filters by package client-side), so the depth is sized for an all-app
|
|
62
|
-
* stream
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* the oldest lines age out once the cap is reached, not kept forever.
|
|
64
|
+
* stream. A separate estimated-byte ceiling handles stack-trace-heavy sessions.
|
|
65
|
+
* Like Android Studio's logcat, retention is a bounded ring — the oldest lines
|
|
66
|
+
* age out once either cap is reached, not kept forever.
|
|
66
67
|
*/
|
|
67
68
|
export const MAX_LOG_SESSION_BUFFER = 20000;
|
|
69
|
+
/** Maximum estimated serialized size of one host-captured log frame. */
|
|
70
|
+
export const MAX_LOG_FRAME_BYTES = 1024 * 1024;
|
|
71
|
+
/** Maximum estimated serialized size retained by one host log session. */
|
|
72
|
+
export const MAX_LOG_SESSION_BYTES = 10 * 1024 * 1024;
|
|
68
73
|
/**
|
|
69
74
|
* Default port for the web dashboard. Shared so the MCP `open_radar_dashboard`
|
|
70
75
|
* tool POSTs its spec to the same port the web server listens on; both honor the
|
|
@@ -102,3 +107,13 @@ export const MAX_RADAR_RESPONSE_BYTES = 1024 * 1024;
|
|
|
102
107
|
* any future second caller of this cap shares it rather than risking drift.
|
|
103
108
|
*/
|
|
104
109
|
export const MAX_PREFS_RESPONSE_BYTES = 64 * 1024;
|
|
110
|
+
/**
|
|
111
|
+
* Past this many UTF-8 bytes get_network_call_detail (and a query_session id read) skip the decoded
|
|
112
|
+
* copy of a form-encoded request body and say so in request_body_decoded_omitted; the raw bytes
|
|
113
|
+
* still ride in request_body. The decoded pretty print runs about three times the raw, so the copy
|
|
114
|
+
* would otherwise pile onto an already large payload in the model context. Both the raw body and
|
|
115
|
+
* the decoded pretty print are measured against this one number. The label is the prose form
|
|
116
|
+
* every note and tool description in the server uses, so the number is spelled once there.
|
|
117
|
+
*/
|
|
118
|
+
export const MAX_FORM_DECODE_BYTES = 64 * 1024;
|
|
119
|
+
export const FORM_DECODE_LIMIT_LABEL = `${MAX_FORM_DECODE_BYTES / 1024} KB`;
|
|
@@ -2,8 +2,9 @@ import fs from "fs";
|
|
|
2
2
|
import os from "os";
|
|
3
3
|
import path from "path";
|
|
4
4
|
/**
|
|
5
|
-
* Appends every streamed SSE frame (network, rtm, clog,
|
|
6
|
-
*
|
|
5
|
+
* Appends every streamed SSE frame (network, rtm, clog, trace, switchboard; log
|
|
6
|
+
* lines are a host-side dashboard merge and never reach it) to a per-session
|
|
7
|
+
* file so the full session record survives buffer eviction. The
|
|
7
8
|
* device rings and the host push ring both drop the oldest entry once full, so
|
|
8
9
|
* a long session loses its early events; the spool keeps the whole session. It
|
|
9
10
|
* does not replace the rings. The device ring stays the source of truth: it
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
* Rewrite the device's raw "Not Found" into an actionable message. The route 404s as valid
|
|
3
3
|
* JSON ({"error":"Not Found"}) on builds that predate the feature-flag Radar plugin, which is
|
|
4
4
|
* correct but useless to a caller with no way to know this route is plugin-gated.
|
|
5
|
+
* A 401 is not read here; both callers decide it from the HTTP status before this runs.
|
|
5
6
|
*/
|
|
6
7
|
export declare function friendlyFeatureFlagError(error: unknown): string;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Rewrite the device's raw "Not Found" into an actionable message. The route 404s as valid
|
|
7
7
|
* JSON ({"error":"Not Found"}) on builds that predate the feature-flag Radar plugin, which is
|
|
8
8
|
* correct but useless to a caller with no way to know this route is plugin-gated.
|
|
9
|
+
* A 401 is not read here; both callers decide it from the HTTP status before this runs.
|
|
9
10
|
*/
|
|
10
11
|
export function friendlyFeatureFlagError(error) {
|
|
11
12
|
if (typeof error !== "string")
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface FormField {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string;
|
|
4
|
+
json?: unknown;
|
|
5
|
+
unparsedReason?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FormBody {
|
|
8
|
+
fields: FormField[];
|
|
9
|
+
truncated: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function formContentType(contentType: unknown): boolean | undefined;
|
|
12
|
+
export declare function isFormBody(text: string, contentType?: unknown): boolean;
|
|
13
|
+
export declare function looksLikeFormBody(text: string): boolean;
|
|
14
|
+
export declare function decodeFormBody(text: string, contentType?: unknown): FormBody | null;
|
|
15
|
+
export declare function formBodyLooksTruncated(body: FormBody): boolean;
|
|
16
|
+
export declare function formTextLooksTruncated(text: string): boolean;
|
|
17
|
+
export declare function jsonTextLooksCut(text: string, contentType?: unknown): boolean;
|
|
18
|
+
export declare function formBodyToObject(body: FormBody): Record<string, unknown>;
|