@slack/radar-mcp 1.23.0 → 1.25.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 +14 -7
- 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 +10 -2
- package/dist/mcp/index.js +74 -54
- package/dist/mcp/radar-http.js +3 -1
- package/dist/mcp/session-enable.d.ts +1 -0
- package/dist/mcp/session-enable.js +52 -8
- package/dist/mcp/switchboard-tools.d.ts +5 -2
- package/dist/mcp/switchboard-tools.js +18 -12
- package/dist/mcp/tools.js +69 -169
- package/dist/mcp/web-child-env.js +2 -1
- package/dist/shared/android.d.ts +74 -10
- package/dist/shared/android.js +344 -103
- 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/feature-flags.d.ts +11 -0
- package/dist/shared/feature-flags.js +18 -4
- package/dist/shared/log-session.d.ts +2 -1
- package/dist/shared/prefs.js +4 -5
- package/dist/shared/radar-request-raw.js +3 -1
- package/dist/shared/switchboard-note.d.ts +19 -0
- package/dist/shared/switchboard-note.js +76 -0
- package/dist/shared/switchboard-report.js +40 -4
- package/dist/shared/switchboard.d.ts +2 -1
- package/dist/shared/switchboard.js +17 -3
- package/dist/shared/transport.d.ts +24 -0
- package/dist/shared/wire.d.ts +2 -0
- package/dist/web/install-app-cli.d.ts +2 -0
- package/dist/web/install-app-cli.js +60 -0
- package/dist/web/install-app.d.ts +16 -7
- package/dist/web/install-app.js +92 -39
- package/dist/web/macapp/RadarApp.swift +12 -11
- package/dist/web/public/index.html +4 -2
- package/dist/web/public/next/feature-flags.js +33 -0
- package/dist/web/public/next/feed.js +13 -2
- package/dist/web/public/next/flags.js +15 -3
- package/dist/web/public/next/registry.js +4 -4
- package/dist/web/public/next/store.js +89 -3
- package/dist/web/public/next/switchboard-note.js +76 -0
- package/dist/web/public/next/voice-model.js +196 -14
- package/dist/web/public/next/voice.js +68 -10
- package/dist/web/server.d.ts +17 -0
- package/dist/web/server.js +180 -35
- package/dist/web/spec.d.ts +1 -1
- package/dist/web/spec.js +1 -1
- package/package.json +1 -1
|
@@ -69,13 +69,25 @@ export declare const WEB_PORT_DEFAULT = 8100;
|
|
|
69
69
|
* commits to redirecting RADAR_PORT at it.
|
|
70
70
|
*/
|
|
71
71
|
export declare const WEBAPP_DEFAULT_PORT = 1989;
|
|
72
|
+
/** Env var that pins the Slack debug package, for a profile running two debug builds at once. */
|
|
73
|
+
export declare const DEBUG_PACKAGE_ENV = "SLACK_RADAR_DEBUG_PACKAGE";
|
|
74
|
+
export declare const DEFAULT_DEBUG_PKG = "com.Slack.internal.debug";
|
|
72
75
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* on a debuggable build. Defined once here so the two readers cannot drift.
|
|
76
|
+
* The debug app ids the Slack app ships: applicationId com.Slack, flavors internal, intune and
|
|
77
|
+
* prototype (or none), debug build type. Auto-detect from ps adopts only these; anything else
|
|
78
|
+
* needs SLACK_RADAR_DEBUG_PACKAGE, so a lookalike process never gets the token.
|
|
77
79
|
*/
|
|
78
|
-
export declare const
|
|
80
|
+
export declare const SHIPPED_DEBUG_PACKAGES: readonly string[];
|
|
81
|
+
/** A ps NAME may carry a `:process` suffix; the package is what comes before it. */
|
|
82
|
+
export declare function debugPackageFromPsName(name: string): string | null;
|
|
83
|
+
/** The env override, or null when unset. An invalid value still comes back so the caller can fail loudly. */
|
|
84
|
+
export declare function debugPackageOverride(): string | null;
|
|
85
|
+
/** Error text for an env value that breaks the rule, or null when the env is unset or fine. */
|
|
86
|
+
export declare function debugPackageOverrideError(): string | null;
|
|
87
|
+
export declare function slackDebugPackage(): string;
|
|
88
|
+
export declare function setSlackDebugPackage(pkg: string): void;
|
|
89
|
+
/** Back to env-or-default, for a device switch. A lost request keeps the armed package. */
|
|
90
|
+
export declare function resetSlackDebugPackage(): void;
|
|
79
91
|
/**
|
|
80
92
|
* Host-side ceiling on a single response we forward into the model context. A
|
|
81
93
|
* proxied device response (large trace/clog payloads) or a session-spool query
|
package/dist/shared/constants.js
CHANGED
|
@@ -84,13 +84,67 @@ export const WEB_PORT_DEFAULT = 8100;
|
|
|
84
84
|
* commits to redirecting RADAR_PORT at it.
|
|
85
85
|
*/
|
|
86
86
|
export const WEBAPP_DEFAULT_PORT = 1989;
|
|
87
|
+
/** Env var that pins the Slack debug package, for a profile running two debug builds at once. */
|
|
88
|
+
export const DEBUG_PACKAGE_ENV = "SLACK_RADAR_DEBUG_PACKAGE";
|
|
89
|
+
export const DEFAULT_DEBUG_PKG = "com.Slack.internal.debug";
|
|
90
|
+
// One rule for the env value and for names read off ps. It keeps every name shell-safe (it goes
|
|
91
|
+
// into `adb shell` strings) and inside what the ps grep can see, so an override can never read
|
|
92
|
+
// as a false "stopped".
|
|
93
|
+
const DEBUG_PACKAGE_RULE = /^com\.Slack(\.[A-Za-z0-9_]+)*\.debug$/;
|
|
87
94
|
/**
|
|
88
|
-
* The
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* on a debuggable build. Defined once here so the two readers cannot drift.
|
|
95
|
+
* The debug app ids the Slack app ships: applicationId com.Slack, flavors internal, intune and
|
|
96
|
+
* prototype (or none), debug build type. Auto-detect from ps adopts only these; anything else
|
|
97
|
+
* needs SLACK_RADAR_DEBUG_PACKAGE, so a lookalike process never gets the token.
|
|
92
98
|
*/
|
|
93
|
-
export const
|
|
99
|
+
export const SHIPPED_DEBUG_PACKAGES = [
|
|
100
|
+
"com.Slack.internal.debug",
|
|
101
|
+
"com.Slack.intune.debug",
|
|
102
|
+
"com.Slack.prototype.debug",
|
|
103
|
+
"com.Slack.debug",
|
|
104
|
+
];
|
|
105
|
+
/** A ps NAME may carry a `:process` suffix; the package is what comes before it. */
|
|
106
|
+
export function debugPackageFromPsName(name) {
|
|
107
|
+
const pkg = name.split(":")[0];
|
|
108
|
+
return DEBUG_PACKAGE_RULE.test(pkg) ? pkg : null;
|
|
109
|
+
}
|
|
110
|
+
/** The env override, or null when unset. An invalid value still comes back so the caller can fail loudly. */
|
|
111
|
+
export function debugPackageOverride() {
|
|
112
|
+
const value = process.env[DEBUG_PACKAGE_ENV];
|
|
113
|
+
return value ? value : null;
|
|
114
|
+
}
|
|
115
|
+
/** Error text for an env value that breaks the rule, or null when the env is unset or fine. */
|
|
116
|
+
export function debugPackageOverrideError() {
|
|
117
|
+
const value = debugPackageOverride();
|
|
118
|
+
if (value === null || DEBUG_PACKAGE_RULE.test(value))
|
|
119
|
+
return null;
|
|
120
|
+
return `${DEBUG_PACKAGE_ENV} must be a Slack debug app id, like com.Slack.intune.debug or com.Slack.debug (letters, digits and underscores between the dots), got "${value}"`;
|
|
121
|
+
}
|
|
122
|
+
function validPackageFrom(value) {
|
|
123
|
+
return value && DEBUG_PACKAGE_RULE.test(value) ? value : null;
|
|
124
|
+
}
|
|
125
|
+
function envOrDefaultPackage() {
|
|
126
|
+
return validPackageFrom(debugPackageOverride()) ?? DEFAULT_DEBUG_PKG;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The Slack debug build whose sandbox the host can `run-as` into: the enable broadcast, the token
|
|
130
|
+
* file, the SQLite browser (db.ts), prefs and the app log-buffer reader all target it, so they
|
|
131
|
+
* cannot drift. The arm sets it to what ps shows, so read it through slackDebugPackage().
|
|
132
|
+
*
|
|
133
|
+
* Precedence: SLACK_RADAR_DEBUG_PACKAGE env > the one debug package ps shows for the bound user
|
|
134
|
+
* (with several, the current one if it is among them) > com.Slack.internal.debug. After an
|
|
135
|
+
* enable, re-arms keep the build it armed; when ps cannot answer, the current build is kept.
|
|
136
|
+
*/
|
|
137
|
+
let debugPackage = envOrDefaultPackage();
|
|
138
|
+
export function slackDebugPackage() {
|
|
139
|
+
return debugPackage;
|
|
140
|
+
}
|
|
141
|
+
export function setSlackDebugPackage(pkg) {
|
|
142
|
+
debugPackage = pkg;
|
|
143
|
+
}
|
|
144
|
+
/** Back to env-or-default, for a device switch. A lost request keeps the armed package. */
|
|
145
|
+
export function resetSlackDebugPackage() {
|
|
146
|
+
debugPackage = envOrDefaultPackage();
|
|
147
|
+
}
|
|
94
148
|
/**
|
|
95
149
|
* Host-side ceiling on a single response we forward into the model context. A
|
|
96
150
|
* proxied device response (large trace/clog payloads) or a session-spool query
|
package/dist/shared/db.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare function resetDbState(): void;
|
|
|
38
38
|
* every switch rather than being structurally impossible. process.env.ANDROID_SERIAL is
|
|
39
39
|
* the same pin every adb call site in this file already targets (see pin() in android.ts);
|
|
40
40
|
* "single" covers a single-device host with no pin set, matching the existing "single"
|
|
41
|
-
* fallback for an unset user.
|
|
41
|
+
* fallback for an unset user. The package is in the name for the same reason as the serial.
|
|
42
42
|
*/
|
|
43
43
|
export declare function localPath(name: string, user: string): string;
|
|
44
44
|
/**
|
package/dist/shared/db.js
CHANGED
|
@@ -19,9 +19,7 @@ import fs from "fs";
|
|
|
19
19
|
import os from "os";
|
|
20
20
|
import path from "path";
|
|
21
21
|
import { resolveAdbPath } from "./android.js";
|
|
22
|
-
import {
|
|
23
|
-
/** The debug build whose sandbox we can `run-as` into. */
|
|
24
|
-
const DB_PKG = SLACK_DEBUG_PKG;
|
|
22
|
+
import { DEFAULT_DEBUG_PKG, slackDebugPackage } from "./constants.js";
|
|
25
23
|
/** Dedicated tmp dir for pulled DB copies. Cleaned on start/stop; files written 0600. Scoped by a per-process key so concurrent readers do not collide. */
|
|
26
24
|
let DB_TMP = path.join(os.tmpdir(), "slack-radar-db");
|
|
27
25
|
/**
|
|
@@ -144,7 +142,7 @@ function userHasBuild(user) {
|
|
|
144
142
|
try {
|
|
145
143
|
runAdb([
|
|
146
144
|
"shell",
|
|
147
|
-
`run-as ${
|
|
145
|
+
`run-as ${slackDebugPackage()} ${user ? "--user " + user : ""} ls databases >/dev/null 2>&1 && echo ok`,
|
|
148
146
|
]);
|
|
149
147
|
return true;
|
|
150
148
|
}
|
|
@@ -163,15 +161,21 @@ function userHasBuild(user) {
|
|
|
163
161
|
* it once and reuse; resetDbState() clears it for a device/profile change.
|
|
164
162
|
*/
|
|
165
163
|
let cachedUsers = null;
|
|
164
|
+
// The list belongs to one package: another debug build has its own set of profiles.
|
|
165
|
+
let cachedUsersPkg = null;
|
|
166
166
|
export function availableUsers() {
|
|
167
|
-
if (cachedUsers)
|
|
167
|
+
if (cachedUsers && cachedUsersPkg === slackDebugPackage())
|
|
168
168
|
return cachedUsers;
|
|
169
|
+
cachedUsers = null;
|
|
169
170
|
const ids = deviceUserIds();
|
|
170
171
|
const found = ids.filter(userHasBuild);
|
|
171
172
|
// Fallback for an older adb / odd `pm` output: try the no-flag form.
|
|
172
173
|
const resolved = found.length ? found : userHasBuild("") ? [""] : [];
|
|
173
|
-
if (resolved.length)
|
|
174
|
-
|
|
174
|
+
if (resolved.length) {
|
|
175
|
+
// only cache a successful probe
|
|
176
|
+
cachedUsers = resolved;
|
|
177
|
+
cachedUsersPkg = slackDebugPackage();
|
|
178
|
+
}
|
|
175
179
|
return resolved;
|
|
176
180
|
}
|
|
177
181
|
/** `--user N` flag for a resolved user, or "" for the single-user case. */
|
|
@@ -205,7 +209,7 @@ function assertSafeName(name) {
|
|
|
205
209
|
* every switch rather than being structurally impossible. process.env.ANDROID_SERIAL is
|
|
206
210
|
* the same pin every adb call site in this file already targets (see pin() in android.ts);
|
|
207
211
|
* "single" covers a single-device host with no pin set, matching the existing "single"
|
|
208
|
-
* fallback for an unset user.
|
|
212
|
+
* fallback for an unset user. The package is in the name for the same reason as the serial.
|
|
209
213
|
*/
|
|
210
214
|
// Exported for testability only (mirrors assertReadOnlyQuery/isExplainQuery below);
|
|
211
215
|
// callers within this file use it directly.
|
|
@@ -213,7 +217,10 @@ export function localPath(name, user) {
|
|
|
213
217
|
const safeName = name.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
214
218
|
const safeUser = (user || "single").replace(/[^A-Za-z0-9._-]/g, "_");
|
|
215
219
|
const safeSerial = (process.env.ANDROID_SERIAL || "single").replace(/[^A-Za-z0-9._-]/g, "_");
|
|
216
|
-
|
|
220
|
+
// Two debug builds hold different stores under the same user and name. The default build
|
|
221
|
+
// keeps the plain name so copies named before the package could change stay valid.
|
|
222
|
+
const pkgPart = slackDebugPackage() === DEFAULT_DEBUG_PKG ? "" : `-p${slackDebugPackage().replace(/[^A-Za-z0-9._]/g, "_")}`;
|
|
223
|
+
return path.join(DB_TMP, `d${safeSerial}-u${safeUser}${pkgPart}-${safeName}.sqlite`);
|
|
217
224
|
}
|
|
218
225
|
/**
|
|
219
226
|
* Resolve the Android user to target. The dashboard passes the profile it is bound to
|
|
@@ -223,7 +230,7 @@ export function localPath(name, user) {
|
|
|
223
230
|
function resolveUser(user) {
|
|
224
231
|
const available = availableUsers();
|
|
225
232
|
if (!available.length) {
|
|
226
|
-
throw new Error(`cannot run-as ${
|
|
233
|
+
throw new Error(`cannot run-as ${slackDebugPackage()}. Is the debug build installed and is a device connected?`);
|
|
227
234
|
}
|
|
228
235
|
if (user != null && available.includes(user))
|
|
229
236
|
return user;
|
|
@@ -241,12 +248,12 @@ export function listDatabases(user) {
|
|
|
241
248
|
// profile change clears it via resetDbState() (wired to /enable / reconnect).
|
|
242
249
|
const available = availableUsers();
|
|
243
250
|
if (!available.length) {
|
|
244
|
-
throw new Error(`cannot run-as ${
|
|
251
|
+
throw new Error(`cannot run-as ${slackDebugPackage()}. Is the debug build installed and is a device connected?`);
|
|
245
252
|
}
|
|
246
253
|
const u = user != null && available.includes(user) ? user : available[0];
|
|
247
254
|
const out = runAdb([
|
|
248
255
|
"shell",
|
|
249
|
-
`run-as ${
|
|
256
|
+
`run-as ${slackDebugPackage()} ${userFlag(u)} ls -1 databases`,
|
|
250
257
|
]).toString();
|
|
251
258
|
const names = out
|
|
252
259
|
.split("\n")
|
|
@@ -340,7 +347,7 @@ export async function pullDatabase(name, user, force = false) {
|
|
|
340
347
|
// every other tab, the stream, and /health for the duration of the pull).
|
|
341
348
|
bytes = await runAdbAsync([
|
|
342
349
|
"exec-out",
|
|
343
|
-
`run-as ${
|
|
350
|
+
`run-as ${slackDebugPackage()} ${userFlag(u)} cat databases/${name}`,
|
|
344
351
|
]);
|
|
345
352
|
}
|
|
346
353
|
catch {
|
|
@@ -370,7 +377,7 @@ export async function pullDatabase(name, user, force = false) {
|
|
|
370
377
|
fs.rmSync(sidecar, { force: true });
|
|
371
378
|
const sb = await runAdbAsync([
|
|
372
379
|
"exec-out",
|
|
373
|
-
`run-as ${
|
|
380
|
+
`run-as ${slackDebugPackage()} ${userFlag(u)} cat databases/${name}${ext}`,
|
|
374
381
|
]);
|
|
375
382
|
if (sb && sb.length > 0)
|
|
376
383
|
fs.writeFileSync(sidecar, sb, { mode: 0o600 });
|
package/dist/shared/debug-log.js
CHANGED
|
@@ -19,9 +19,7 @@
|
|
|
19
19
|
* applied before return.
|
|
20
20
|
*/
|
|
21
21
|
import { execFileSync } from "child_process";
|
|
22
|
-
import {
|
|
23
|
-
/** The debug build whose sandbox we can `run-as` into. */
|
|
24
|
-
const LOG_PKG = SLACK_DEBUG_PKG;
|
|
22
|
+
import { slackDebugPackage } from "./constants.js";
|
|
25
23
|
/** Number of rolling log files DebugLogger maintains (debug.log0..debug.log5). */
|
|
26
24
|
const LOG_FILE_COUNT = 6;
|
|
27
25
|
const ADB_MAX_BUFFER = 16 * 1024 * 1024; // total buffer is ~1.5MB; headroom for safety.
|
|
@@ -75,7 +73,7 @@ export function readDebugLogBuffer(adbPath, user) {
|
|
|
75
73
|
// which exits 0 with the helper error in stdout).
|
|
76
74
|
const runAs = (userFlag) => {
|
|
77
75
|
try {
|
|
78
|
-
return execFileSync(adbPath, ["exec-out", `run-as ${
|
|
76
|
+
return execFileSync(adbPath, ["exec-out", `run-as ${slackDebugPackage()} ${userFlag}sh -c 'cat ${catList} 2>/dev/null'`], {
|
|
79
77
|
timeout: 10000,
|
|
80
78
|
maxBuffer: ADB_MAX_BUFFER,
|
|
81
79
|
encoding: "utf-8",
|
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
import type { ProcessState } from "./transport.js";
|
|
1
|
+
import type { ArgvReason, ProcessState } from "./transport.js";
|
|
2
|
+
/** What pinned a package the pick only checks: the env override, or the build this session armed. */
|
|
3
|
+
export type PinReason = "override" | "held";
|
|
4
|
+
export declare function noDebugBuildRunningMessage(userId: string | null, pkg?: string, reason?: PinReason): string;
|
|
5
|
+
export declare function foreignRadarOwnerMessage(armedPackage: string, owner: string): string;
|
|
6
|
+
export declare class BareEnableError extends Error {
|
|
7
|
+
}
|
|
8
|
+
export declare class NoDebugBuildRunningError extends BareEnableError {
|
|
9
|
+
constructor(userId: string | null, pkg?: string, reason?: PinReason);
|
|
10
|
+
}
|
|
11
|
+
export declare class AmbiguousDebugPackageError extends BareEnableError {
|
|
12
|
+
constructor(userId: string, packages: readonly string[]);
|
|
13
|
+
}
|
|
14
|
+
export declare class UnknownDebugBuildError extends BareEnableError {
|
|
15
|
+
constructor(userId: string, packages: readonly string[]);
|
|
16
|
+
}
|
|
17
|
+
export declare class DebugPackageOverrideError extends BareEnableError {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
export declare function tokenViaArgvField(device: {
|
|
21
|
+
getLastTokenViaArgv?(): ArgvReason | null;
|
|
22
|
+
}): {
|
|
23
|
+
token_via_argv?: ArgvReason;
|
|
24
|
+
};
|
|
25
|
+
export declare class AndroidUserIdError extends BareEnableError {
|
|
26
|
+
constructor();
|
|
27
|
+
}
|
|
2
28
|
/**
|
|
3
29
|
* What to tell the user when activation was broadcast but the device server never
|
|
4
30
|
* answered a ping.
|
|
@@ -1,3 +1,76 @@
|
|
|
1
|
+
// The one place the "broadcast landed, server stayed silent" message is worded. Both
|
|
2
|
+
// entry points reach this state -- the MCP _radar_session_enable flow and the dashboard's
|
|
3
|
+
// /enable route -- and a user who retries in the other surface must not be told a
|
|
4
|
+
// different story about the same device.
|
|
5
|
+
import { DEBUG_PACKAGE_ENV, debugPackageFromPsName } from "./constants.js";
|
|
6
|
+
// A null user means ps saw no debug build anywhere, so naming the fallback user 0 would be a guess.
|
|
7
|
+
// A pinned package is the one thing known, so the message names it and what pinned it: the
|
|
8
|
+
// variable, or the build this session armed (the way back is to enable again).
|
|
9
|
+
export function noDebugBuildRunningMessage(userId, pkg, reason = "override") {
|
|
10
|
+
if (pkg) {
|
|
11
|
+
const where = userId === null ? "" : ` in Android user ${userId}`;
|
|
12
|
+
if (reason === "held")
|
|
13
|
+
return `${pkg}, the build this session armed, is not running${where}; enable again`;
|
|
14
|
+
return `${pkg} (set by ${DEBUG_PACKAGE_ENV}) is not running${where}; open it, pick its profile with list_profiles, or unset the variable`;
|
|
15
|
+
}
|
|
16
|
+
return userId === null
|
|
17
|
+
? "no debug build of the Slack app is running; open it and retry"
|
|
18
|
+
: `no debug build of the Slack app is running in Android user ${userId}; open it there and retry`;
|
|
19
|
+
}
|
|
20
|
+
// The ping body can be large and lands in a tool result, so the owner's name is printed only
|
|
21
|
+
// when it looks like a Slack debug package; anything else is "another app".
|
|
22
|
+
export function foreignRadarOwnerMessage(armedPackage, owner) {
|
|
23
|
+
if (debugPackageFromPsName(owner) !== owner) {
|
|
24
|
+
return `Radar on this device is served by another app, not the ${armedPackage} this session armed. ` +
|
|
25
|
+
`Force-stop that app, or disable Radar in the session that armed it, then enable again.`;
|
|
26
|
+
}
|
|
27
|
+
return `Radar on this device is served by ${owner}, not the ${armedPackage} this session armed. ` +
|
|
28
|
+
`Force-stop ${owner}, or disable Radar in the session that armed it, then enable again; ` +
|
|
29
|
+
`or set ${DEBUG_PACKAGE_ENV}=${owner} to read that build instead.`;
|
|
30
|
+
}
|
|
31
|
+
// Errors whose message already tells the user what to do, so every surface shows them bare.
|
|
32
|
+
export class BareEnableError extends Error {
|
|
33
|
+
}
|
|
34
|
+
// Callers branch on the type, never on the sentence.
|
|
35
|
+
export class NoDebugBuildRunningError extends BareEnableError {
|
|
36
|
+
constructor(userId, pkg, reason) {
|
|
37
|
+
super(noDebugBuildRunningMessage(userId, pkg, reason));
|
|
38
|
+
this.name = "NoDebugBuildRunningError";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Says what ps saw. It never claims a build is missing, because several are running.
|
|
42
|
+
export class AmbiguousDebugPackageError extends BareEnableError {
|
|
43
|
+
constructor(userId, packages) {
|
|
44
|
+
super(`Slack debug builds are running for user ${userId}: ${packages.join(", ")}. ` +
|
|
45
|
+
`Set ${DEBUG_PACKAGE_ENV} to the one to arm, in the slack-radar MCP server config, and restart the MCP.`);
|
|
46
|
+
this.name = "AmbiguousDebugPackageError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// A Slack debug process is on screen, so "no debug build is running" would be false.
|
|
50
|
+
export class UnknownDebugBuildError extends BareEnableError {
|
|
51
|
+
constructor(userId, packages) {
|
|
52
|
+
super(`a Slack debug build ${packages.join(", ")} is running in Android user ${userId} but is not a known flavour; ` +
|
|
53
|
+
`set ${DEBUG_PACKAGE_ENV} to target it`);
|
|
54
|
+
this.name = "UnknownDebugBuildError";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export class DebugPackageOverrideError extends BareEnableError {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = "DebugPackageOverrideError";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Absent unless the token went over the command line, so a clean enable stays quiet.
|
|
64
|
+
export function tokenViaArgvField(device) {
|
|
65
|
+
const reason = device.getLastTokenViaArgv?.();
|
|
66
|
+
return reason ? { token_via_argv: reason } : {};
|
|
67
|
+
}
|
|
68
|
+
export class AndroidUserIdError extends BareEnableError {
|
|
69
|
+
constructor() {
|
|
70
|
+
super("user_id must be a decimal Android user id (list_profiles shows them)");
|
|
71
|
+
this.name = "AndroidUserIdError";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
1
74
|
/**
|
|
2
75
|
* What to tell the user when activation was broadcast but the device server never
|
|
3
76
|
* answered a ping.
|
|
@@ -5,3 +5,14 @@
|
|
|
5
5
|
* A 401 is not read here; both callers decide it from the HTTP status before this runs.
|
|
6
6
|
*/
|
|
7
7
|
export declare function friendlyFeatureFlagError(error: unknown): string;
|
|
8
|
+
/**
|
|
9
|
+
* The one sentence for a flag whose latest value differs from what the app runs. A flag the app
|
|
10
|
+
* read once keeps that value until restart, so `enabled` (latest or override) can differ from
|
|
11
|
+
* `session_enabled`. Only two real booleans that differ earn a note: an absent or non-boolean
|
|
12
|
+
* session_enabled is "not known", and saying nothing there is the honest answer.
|
|
13
|
+
*/
|
|
14
|
+
export declare function flagRestartNote(row: {
|
|
15
|
+
enabled?: unknown;
|
|
16
|
+
session_enabled?: unknown;
|
|
17
|
+
is_overridden?: unknown;
|
|
18
|
+
}): string | undefined;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// Shared feature-flag response handling for the
|
|
2
|
-
// /api/feature_flags route: the MCP tools (flags-tools.ts)
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Shared feature-flag response handling for the callers that read the device's
|
|
2
|
+
// /api/feature_flags route: the MCP tools (flags-tools.ts), the web server (web/server.ts) and the
|
|
3
|
+
// dashboard's Flags tab, which gets a mirrored copy of this file (scripts/mirror-shared.mjs). So it
|
|
4
|
+
// must stay import-free. The "Not Found" rewrite and the restart sentence live here once instead
|
|
5
|
+
// of drifting between copies.
|
|
5
6
|
/**
|
|
6
7
|
* Rewrite the device's raw "Not Found" into an actionable message. The route 404s as valid
|
|
7
8
|
* JSON ({"error":"Not Found"}) on builds that predate the feature-flag Radar plugin, which is
|
|
@@ -16,3 +17,16 @@ export function friendlyFeatureFlagError(error) {
|
|
|
16
17
|
}
|
|
17
18
|
return error;
|
|
18
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* The one sentence for a flag whose latest value differs from what the app runs. A flag the app
|
|
22
|
+
* read once keeps that value until restart, so `enabled` (latest or override) can differ from
|
|
23
|
+
* `session_enabled`. Only two real booleans that differ earn a note: an absent or non-boolean
|
|
24
|
+
* session_enabled is "not known", and saying nothing there is the honest answer.
|
|
25
|
+
*/
|
|
26
|
+
export function flagRestartNote(row) {
|
|
27
|
+
const { enabled, session_enabled: session } = row;
|
|
28
|
+
if (typeof enabled !== "boolean" || typeof session !== "boolean" || enabled === session)
|
|
29
|
+
return undefined;
|
|
30
|
+
const source = row.is_overridden === true ? "override" : "fetched";
|
|
31
|
+
return `app uses ${session} until restart, ${source} ${enabled}`;
|
|
32
|
+
}
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* no stream was attached — the user sees their log count shrink on a tab switch.
|
|
11
11
|
*
|
|
12
12
|
* This module fixes that the way Android Studio does: ONE capture process per
|
|
13
|
-
* device for the whole server session, feeding a bounded session ring buffer.
|
|
13
|
+
* device for the whole server session, feeding a bounded session ring buffer. A stop keeps
|
|
14
|
+
* the ring, and a later start resumes into it.
|
|
14
15
|
* Each `/stream` connection subscribes as a listener and is first replayed the
|
|
15
16
|
* entire retained buffer, then receives live lines. Switching tabs only
|
|
16
17
|
* adds/removes a listener; the underlying capture and its history are untouched.
|
package/dist/shared/prefs.js
CHANGED
|
@@ -13,10 +13,9 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { execFileSync, execFile } from "child_process";
|
|
15
15
|
import { promisify } from "util";
|
|
16
|
-
import {
|
|
16
|
+
import { slackDebugPackage } from "./constants.js";
|
|
17
17
|
import { detectRunAsError } from "./debug-log.js";
|
|
18
18
|
import { availableUsers } from "./db.js";
|
|
19
|
-
const PREFS_PKG = SLACK_DEBUG_PKG;
|
|
20
19
|
const ADB_MAX_BUFFER = 2 * 1024 * 1024; // prefs can be large; user 10 observed 1.2MB total
|
|
21
20
|
// ASYNC, not execFileSync: Node is single-threaded, so a blocking adb call freezes the whole
|
|
22
21
|
// event loop -- every other in-flight HTTP request (a file click, /health) queues behind it.
|
|
@@ -74,7 +73,7 @@ export function listPrefsFiles(adbPath, user) {
|
|
|
74
73
|
try {
|
|
75
74
|
const resolvedUser = resolveUser(user);
|
|
76
75
|
const userFlag = `--user ${resolvedUser} `;
|
|
77
|
-
const out = execFileSync(adbPath, ["shell", `run-as ${
|
|
76
|
+
const out = execFileSync(adbPath, ["shell", `run-as ${slackDebugPackage()} ${userFlag}ls -la shared_prefs/`], { timeout: 10000, maxBuffer: ADB_MAX_BUFFER, encoding: "utf-8", stdio: LIST_STDIO });
|
|
78
77
|
const runAsErr = detectRunAsError(out);
|
|
79
78
|
if (runAsErr) {
|
|
80
79
|
// Try without user flag as fallback (see debug-log.ts for rationale). Which user this
|
|
@@ -82,7 +81,7 @@ export function listPrefsFiles(adbPath, user) {
|
|
|
82
81
|
// profile it just failed to reach) — report "" (db.ts's convention for "ambiguous/
|
|
83
82
|
// implicit user") rather than mislabeling the result with the requested id.
|
|
84
83
|
try {
|
|
85
|
-
const retry = execFileSync(adbPath, ["shell", `run-as ${
|
|
84
|
+
const retry = execFileSync(adbPath, ["shell", `run-as ${slackDebugPackage()} ls -la shared_prefs/`], { timeout: 10000, maxBuffer: ADB_MAX_BUFFER, encoding: "utf-8", stdio: LIST_STDIO });
|
|
86
85
|
if (!detectRunAsError(retry)) {
|
|
87
86
|
return parseListOutput(retry, "");
|
|
88
87
|
}
|
|
@@ -171,7 +170,7 @@ export async function readPrefsFile(adbPath, name, user) {
|
|
|
171
170
|
// intended behavior of reading it fully and truncating the string afterward.
|
|
172
171
|
const out = await runAdbAsync(adbPath, [
|
|
173
172
|
"exec-out",
|
|
174
|
-
`run-as ${
|
|
173
|
+
`run-as ${slackDebugPackage()} ${userFlag}cat shared_prefs/${name}`,
|
|
175
174
|
]);
|
|
176
175
|
return { out, denied: !!detectRunAsError(out) };
|
|
177
176
|
}
|
|
@@ -38,7 +38,9 @@ transport, surface = "mcp") {
|
|
|
38
38
|
}, idleMs);
|
|
39
39
|
};
|
|
40
40
|
try {
|
|
41
|
-
|
|
41
|
+
// agent: false so no request rides a pooled socket the device already closed; that reads
|
|
42
|
+
// as a dead device (ECONNRESET) and costs a re-arm.
|
|
43
|
+
req = http.get({ host, port, path: requestPath, agent: false, headers: radarTokenHeaderFor(transport, surface) }, (res) => {
|
|
42
44
|
// Decode once at the end: a multi-byte UTF-8 character can split across chunks.
|
|
43
45
|
const chunks = [];
|
|
44
46
|
let bytes = 0;
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
export declare function capitalizeSwitchboardNote(note: string): string;
|
|
2
2
|
export declare const CLIP_PEAK = 0.99;
|
|
3
|
+
export declare function micEncodingNote(label: string): string | null;
|
|
3
4
|
export declare function switchboardClockLabel(clock: string): string;
|
|
5
|
+
export declare const SERVER_SESSION_ID_CAP = 8;
|
|
6
|
+
export declare function reconnectTriggerWord(trigger: string): string;
|
|
7
|
+
export declare function reconnectOutcomeWord(outcome: string): string;
|
|
8
|
+
export declare function reconnectTryLabel(trigger: string, outcome: string, n: number | null | undefined): string;
|
|
4
9
|
export declare const SAVED_TURN_DROP_OUTCOMES: readonly string[];
|
|
5
10
|
export declare const SAVED_TURN_KEPT_OUTCOMES: readonly string[];
|
|
6
11
|
export declare const SAVED_TURN_OUTCOMES: readonly string[];
|
|
12
|
+
export declare function cardKindWord(kind: unknown): string;
|
|
13
|
+
export declare function cardLabel(kind: unknown, event: unknown, by: unknown): string;
|
|
14
|
+
export interface OpenCard {
|
|
15
|
+
kind: string;
|
|
16
|
+
id: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function openCards(records: ReadonlyArray<Record<string, unknown>>): OpenCard[];
|
|
7
19
|
export declare const SWITCHBOARD_CONTROL_CHARS: RegExp;
|
|
8
20
|
export declare function stripSwitchboardControlChars(s: string): string;
|
|
9
21
|
export declare function switchboardDeviceToken(name: string): string;
|
|
@@ -13,3 +25,10 @@ export declare function savedTurnCountEntries(counts: unknown): {
|
|
|
13
25
|
outcome: string;
|
|
14
26
|
count: number | null;
|
|
15
27
|
}[];
|
|
28
|
+
export declare function serverEndedNormally(cause: unknown): boolean;
|
|
29
|
+
export declare function connectionEndedNormally(r: {
|
|
30
|
+
kind?: unknown;
|
|
31
|
+
state_kind?: unknown;
|
|
32
|
+
to?: unknown;
|
|
33
|
+
cause?: unknown;
|
|
34
|
+
}): boolean;
|
|
@@ -7,6 +7,16 @@ export function capitalizeSwitchboardNote(note) {
|
|
|
7
7
|
// A peak at or above this is clipping. Shared here so the report and the dashboard sparkline use
|
|
8
8
|
// the same threshold.
|
|
9
9
|
export const CLIP_PEAK = 0.99;
|
|
10
|
+
// What the mic codec costs on the uplink, for the strip and the report header. The sizes are
|
|
11
|
+
// 24 kHz x 2 bytes x 0.2 s for pcm16, and the provider's own note for adts. An unknown label is
|
|
12
|
+
// the device's to add, so it has no note and prints as sent.
|
|
13
|
+
const MIC_ENCODING_NOTES = {
|
|
14
|
+
pcm16: "raw 24 kHz PCM, about 9.6 KB per 200 ms uplink audio frame",
|
|
15
|
+
adts: "AAC in ADTS frames, uplink audio frames about a tenth of pcm16",
|
|
16
|
+
};
|
|
17
|
+
export function micEncodingNote(label) {
|
|
18
|
+
return Object.hasOwn(MIC_ENCODING_NOTES, label) ? MIC_ENCODING_NOTES[label] : null;
|
|
19
|
+
}
|
|
10
20
|
// A turn record's `clock` in words. Shared here so the feed row and the report read the same.
|
|
11
21
|
// An unknown value is the device's to add, so it shows as sent rather than throwing.
|
|
12
22
|
const TURN_CLOCK_LABELS = {
|
|
@@ -17,6 +27,27 @@ const TURN_CLOCK_LABELS = {
|
|
|
17
27
|
export function switchboardClockLabel(clock) {
|
|
18
28
|
return Object.hasOwn(TURN_CLOCK_LABELS, clock) ? TURN_CLOCK_LABELS[clock] : clock;
|
|
19
29
|
}
|
|
30
|
+
// The most server session ids the device lists in a summary (server_session_ids). The host trims
|
|
31
|
+
// its own lists to the same count, so a summary built here matches one the device sent.
|
|
32
|
+
export const SERVER_SESSION_ID_CAP = 8;
|
|
33
|
+
// The panel's words for a reconnect's trigger and outcome. An unknown token is the device's to add,
|
|
34
|
+
// so it shows as sent rather than throwing; hasOwn keeps a name like "constructor" from finding an
|
|
35
|
+
// Object.prototype member.
|
|
36
|
+
const RECONNECT_TRIGGER_WORDS = { restart: "server restart", drop: "dropped connection", settings: "settings change" };
|
|
37
|
+
const RECONNECT_OUTCOME_WORDS = { ready: "back", retry: "failed, trying again", refused: "refused, call ended" };
|
|
38
|
+
export function reconnectTriggerWord(trigger) {
|
|
39
|
+
return Object.hasOwn(RECONNECT_TRIGGER_WORDS, trigger) ? RECONNECT_TRIGGER_WORDS[trigger] : trigger;
|
|
40
|
+
}
|
|
41
|
+
export function reconnectOutcomeWord(outcome) {
|
|
42
|
+
return Object.hasOwn(RECONNECT_OUTCOME_WORDS, outcome) ? RECONNECT_OUTCOME_WORDS[outcome] : outcome;
|
|
43
|
+
}
|
|
44
|
+
// A reconnect_try record in the export line's words ("drop try 2 ready", "drop gave_up after 2
|
|
45
|
+
// tries"), shared by the feed row and the report. A missing try number reads "?".
|
|
46
|
+
export function reconnectTryLabel(trigger, outcome, n) {
|
|
47
|
+
if (outcome === "gave_up")
|
|
48
|
+
return `${trigger} gave_up after ${n ?? "?"} ${n === 1 ? "try" : "tries"}`;
|
|
49
|
+
return `${trigger} try ${n ?? "?"} ${outcome}`;
|
|
50
|
+
}
|
|
20
51
|
// The saved_turn outcomes, the one list the feed row, the panel and the report read. `applied`
|
|
21
52
|
// (a subtitle line still held the frame's item) and `no_line` (no line held it any more, a normal
|
|
22
53
|
// late save, still kept) keep the turn; the drop reasons lose it. The words are the row's and the
|
|
@@ -33,6 +64,40 @@ export const SAVED_TURN_DROP_OUTCOMES = Object.keys(SAVED_TURN_DROPS);
|
|
|
33
64
|
export const SAVED_TURN_KEPT_OUTCOMES = Object.keys(SAVED_TURN_KEPT);
|
|
34
65
|
// The four a revision 3 build always counts, in the order the panel and the report list them.
|
|
35
66
|
export const SAVED_TURN_OUTCOMES = [...Object.keys(SAVED_TURN_KEPT), ...SAVED_TURN_DROP_OUTCOMES];
|
|
67
|
+
// A card record in words, shared by the feed row, the voice panel and the report. A kind or event
|
|
68
|
+
// the device adds later shows as sent, and a missing field reads "?", so nothing throws.
|
|
69
|
+
const CARD_KIND_WORDS = { tool_approval: "tool approval", auth_prompt: "connect prompt" };
|
|
70
|
+
// An event in this set takes the card down; "shown" and "carried" put it up.
|
|
71
|
+
const CARD_CLOSING_EVENTS = ["answered", "refused", "declined", "closed", "replaced", "expired", "cleared"];
|
|
72
|
+
const CARD_OPENING_EVENTS = ["shown", "carried"];
|
|
73
|
+
export function cardKindWord(kind) {
|
|
74
|
+
if (typeof kind !== "string" || !kind)
|
|
75
|
+
return "?";
|
|
76
|
+
return Object.hasOwn(CARD_KIND_WORDS, kind) ? CARD_KIND_WORDS[kind] : kind;
|
|
77
|
+
}
|
|
78
|
+
export function cardLabel(kind, event, by) {
|
|
79
|
+
const eventWord = typeof event === "string" && event ? event : "?";
|
|
80
|
+
return `${cardKindWord(kind)} ${eventWord}${typeof by === "string" && by ? ` by ${by}` : ""}`;
|
|
81
|
+
}
|
|
82
|
+
// The cards still up after these records, in the order they came up. Shown or carried puts a card
|
|
83
|
+
// up (a re-sent one keeps its place), the closing events take it down, and an event it does not
|
|
84
|
+
// know changes nothing, so a newer device build cannot make a card look gone.
|
|
85
|
+
export function openCards(records) {
|
|
86
|
+
const open = new Map();
|
|
87
|
+
for (const r of records) {
|
|
88
|
+
if (r.kind !== "card" || typeof r.card_kind !== "string" || typeof r.card_id !== "string" || typeof r.event !== "string")
|
|
89
|
+
continue;
|
|
90
|
+
const key = `${r.card_kind}\u0000${r.card_id}`;
|
|
91
|
+
if (CARD_OPENING_EVENTS.includes(r.event)) {
|
|
92
|
+
if (!open.has(key))
|
|
93
|
+
open.set(key, { kind: r.card_kind, id: r.card_id });
|
|
94
|
+
}
|
|
95
|
+
else if (CARD_CLOSING_EVENTS.includes(r.event)) {
|
|
96
|
+
open.delete(key);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return [...open.values()];
|
|
100
|
+
}
|
|
36
101
|
// Code points a free-form device string could use to fake a line break, a report boundary, or a
|
|
37
102
|
// hidden direction override: controls, bidi marks, zero-width characters, U+2028/2029 (a newline
|
|
38
103
|
// to a browser), and the BOM. Here rather than in the report so the panel strips the same set.
|
|
@@ -90,3 +155,14 @@ export function savedTurnCountEntries(counts) {
|
|
|
90
155
|
out.push({ outcome: k, count: read(k) });
|
|
91
156
|
return out;
|
|
92
157
|
}
|
|
158
|
+
// The server endings that are a normal end, not a fault. Matches the device's `endsNormally`. An
|
|
159
|
+
// older device build sends plain "Server" for these too, and that stays an error since nothing
|
|
160
|
+
// says which ending it was.
|
|
161
|
+
const NORMAL_SERVER_ENDINGS = ["Server:live_session_limit", "Server:session_limit", "Server:live_idle_timeout", "Server:live_call_ended"];
|
|
162
|
+
export function serverEndedNormally(cause) {
|
|
163
|
+
return typeof cause === "string" && NORMAL_SERVER_ENDINGS.includes(cause);
|
|
164
|
+
}
|
|
165
|
+
// A connection state record that moved to Failed on a normal server ending.
|
|
166
|
+
export function connectionEndedNormally(r) {
|
|
167
|
+
return r.kind === "state" && r.state_kind === "connection" && r.to === "Failed" && serverEndedNormally(r.cause);
|
|
168
|
+
}
|