@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
package/README.md
CHANGED
|
@@ -108,6 +108,7 @@ All optional. Set them on the process that runs the MCP server or the dashboard.
|
|
|
108
108
|
|---|---|
|
|
109
109
|
| `SLACK_RADAR_WEB_PORT` | Port the dashboard listens on. Default `8100`. The dock app bakes it in at install time, so set it when you run `install-app`. |
|
|
110
110
|
| `SLACK_RADAR_DEVICE_PORT` | Host port forwarded to the device-side server. Default `8099`. |
|
|
111
|
+
| `SLACK_RADAR_DEBUG_PACKAGE` | The Slack debug package to arm, like `com.Slack.intune.debug`. Set it when two Slack debug builds run on one profile; it must be a Slack debug app id, like `com.Slack.intune.debug` or `com.Slack.debug`. Auto-detect knows the four shipped ids (`com.Slack.internal.debug`, `com.Slack.intune.debug`, `com.Slack.prototype.debug`, `com.Slack.debug`); any other debug app id needs this variable. Unset, Radar uses the one shipped debug build running, else `com.Slack.internal.debug`. The build is decided when the session enables or switches profile and held through re-arms; if it has gone by a re-arm, the re-arm sends nothing to another build, and when nothing else answers the session asks you to enable again. |
|
|
111
112
|
| `SLACK_RADAR_NO_AUTO_CLOSE=1` | Keep the dashboard running forever instead of closing it once every tab is gone. |
|
|
112
113
|
| `SLACK_RADAR_ALLOWED_HOSTS` | Extra `Host` values the dashboard will answer, comma-separated (`radar.local,myhost:8100`). Only needed when you reach it by a name other than localhost. See Security. |
|
|
113
114
|
| `SLACK_RADAR_NO_ARM=1` | Never arm the device without a press: skips the arm at launch and turns off a tab's automatic re-enable. A Reconnect press still arms. |
|
|
@@ -144,7 +145,7 @@ Radar starts **disabled** each session. All tools except `ping` return an error
|
|
|
144
145
|
| `get_recent_traces` | Performance trace/span summaries: trace name, span name, duration. Filterable by name substring. |
|
|
145
146
|
| `get_trace_detail` | Full trace/span detail for a specific trace, including tags. |
|
|
146
147
|
| `get_switchboard_sessions` | Slackbot voice (switchboard) sessions the device still holds, newest first: `session_id`, `team_id`, `began_at`, `ended_at`, record and frame counts, the newest state and audio levels, `server_session_id` (the server's own name for the session, null until it names one; absent on an older build), `turns` (turn count, the newest response time and its clock, null before the first turn; absent on an older build), and `saved_turn_counts` (saved turns per outcome; absent on an older build means not counted, not zero). Ids restart with the app process. |
|
|
147
|
-
| `get_switchboard_session` | One voice session's summary plus its records, oldest first: `state` transitions, control frames (`frame`) in and out, `player` stutter events, `phase` startup timings, `session` begin/end/ready (`ready` carries `server_session_id`), `levels` (batched mic/playback meter ticks), `turn` (one timed voice turn: `response_ms` and `clock`), and `saved_turn` (whether a spoken turn got saved to the DM: `outcome` (`applied`, `no_line`, `missing_field`, `other_session`) and `has_thread`; the summary's `saved_turn_counts` counts each outcome, and absent on an older device build means not counted, not zero). Narrow with `kind`; `limit` is how many of the newest records come back (default 50, max 2000 per request; the device may hold more, paged with before_id), filtered by kind first, so a kind page is the newest `limit` records of that kind. |
|
|
148
|
+
| `get_switchboard_session` | One voice session's summary plus its records, oldest first: `state` transitions, control frames (`frame`) in and out, `player` stutter events, `phase` startup timings, `session` begin/end/ready (`ready` carries `server_session_id`), `levels` (batched mic/playback meter ticks), `turn` (one timed voice turn: `response_ms` and `clock`), and `saved_turn` (whether a spoken turn got saved to the DM: `outcome` (`applied`, `no_line`, `missing_field`, `other_session`) and `has_thread`; the summary's `saved_turn_counts` counts each outcome, and absent on an older device build means not counted, not zero). Narrow with `kind`; `limit` is how many of the newest records come back (default 50, max 2000 per request; the device may hold more, paged with before_id), filtered by kind first, so a kind page is the newest `limit` records of that kind. `reconnect_try` (one voice reconnect try: `trigger` (`restart`, `drop`, `settings`), `try` and `outcome` (`ready`, `retry`, `refused`, `gave_up`)); a Reconnecting state's cause is its trigger, and the summary's `server_session_ids` lists every ready id. `card` (one move of a voice card the server is waiting on: `card_kind`, `event`, `by`, `card_id`; a card shown or carried with no later record was still up at the session's last record). |
|
|
148
149
|
| `export_switchboard_session` | Write one voice session's summary and its records to a plain-text report under `~/.slack-radar/exports/`, permissions 0700/0600 like `capture_snapshot`. Pages the device, then merges in the live stream copy; the export can stop early (for example an old build, the 32 MB size cap, the page limit, or the device stopping answering), and the report notes say why anything is missing. An unknown id (404, unreachable, or too large to read) errors unless this process streamed the call live, then the report comes from the live stream copy alone, whichever process ran the export, since this MCP server and the web dashboard each keep their own. Defaults to newest when `id` is omitted; returns the file path and a summary. |
|
|
149
150
|
| `wait_for_events` | Block until matching events arrive via SSE stream. Idle-timeout based, not polling. |
|
|
150
151
|
| `search` | Full-text search across network, RTM, clog, and trace buffers. |
|
|
@@ -161,7 +162,7 @@ Radar starts **disabled** each session. All tools except `ping` return an error
|
|
|
161
162
|
| `list_prefs` | List the app's on-device SharedPreferences files. Read-only. |
|
|
162
163
|
| `get_prefs` | Read a preferences file's keys and values, optionally filtered to specific keys. |
|
|
163
164
|
| `search_prefs` | Search preference keys and values across every file by a substring. |
|
|
164
|
-
| `list_feature_flags` | List every feature flag with its
|
|
165
|
+
| `list_feature_flags` | List every feature flag with its latest effective value and override status; toggle rows also carry `session_enabled`, the flag's own value the app runs now: the first-read value for a flag already read this session, or the value a read returns now for one not yet read. Optionally filtered to just the overridden ones. Boolean toggles carry `enabled`; multi-variant experiments carry `type: "experiment"` and a `group_name` string (the effective variant, e.g. `"treatment_a"`) instead. |
|
|
165
166
|
| `search_feature_flags` | Case-insensitive substring search on feature flag names, against the same live list as `list_feature_flags`. Rows carry the same `type`/`group_name` fields for experiments. |
|
|
166
167
|
| `get_feature_flag` | Look up one feature flag by its exact key. Returns one row per scope (authenticated/unauthenticated) and per signed-in org, since each workspace resolves its own value; pass `org_id` to narrow to one workspace. An experiment row carries `type: "experiment"` and its `group_name` variant rather than a boolean `enabled`. |
|
|
167
168
|
| `run_test_case` | Replay a built-in or hand-written case. Pass `case`, optional `repeat` and `rate_per_second` (null for burst). Requires a debug build serving `test_runs`. |
|
|
@@ -236,10 +237,16 @@ All device-specific logic lives behind the `DeviceTransport` interface (`src/sha
|
|
|
236
237
|
## Security
|
|
237
238
|
|
|
238
239
|
* **No TCP port on device.** Uses platform-specific local sockets, only reachable via port forwarding. Requires physical USB or explicit debug pairing.
|
|
239
|
-
* **Per-user device token.** The first Radar process that needs the token (MCP or dashboard) mints it at `~/.slack-radar/radar-token`, mode 0600, one per OS user
|
|
240
|
+
* **Per-user device token.** The first Radar process that needs the token (MCP or dashboard) mints it at `~/.slack-radar/radar-token`, mode 0600, one per OS user. Every request carries it as `X-Radar-Token`; a device build with the token check answers 401 to anything else. How an enable hands it to the device:
|
|
241
|
+
* First Radar checks `ps` for a debug build running as the target Android user. Nothing running there: nothing is written or sent, and the enable fails with "no debug build of the Slack app is running in Android user N; open it there and retry" (just "...is running; open it and retry" when ps saw no build and no user was asked for), from `/radar-enable`, `activate_for_user` and the dashboard alike. Open Slack in that profile first; `activate_for_user` only picks the profile, it cannot start the app.
|
|
242
|
+
* File path (the default): the token goes over stdin with `run-as` into the app's private `files/slack-radar/enable-token` (mode 0600), then `slack.debug.ENABLE_RADAR_TOKEN_FILE` is sent with no token extra; the app reads and deletes the file inside the broadcast. This path keeps the token off every command line.
|
|
243
|
+
* Argv fallback, the old `ENABLE_RADAR --es radar_token` enable, visible in `ps` and adbd's log while it runs, when a debug build is running (or `ps` could not tell) and one of these holds:
|
|
244
|
+
* the `run-as` write failed, timed out or printed no `written` verdict (the build is not debuggable in that profile, or this adb cannot run `run-as --user`); Radar removes anything that landed first. The device's ping says nothing about this case: `token_file: true` only means the build has the action;
|
|
245
|
+
* the file was still there after the broadcast: the build predates the action, or the app failed to delete it; Radar removes it, checks `ps` once more, and sends nothing if the app has stopped meanwhile. The enable result (`_radar_session_enable`, `activate_for_user`) carries `token_via_argv` with the reason when the token rode argv; the key is absent when it did not.
|
|
246
|
+
* One argv enable exposes the long-lived token. `token_via_argv` covers only the enable that returned it; a background re-arm (any Radar tool call, the dashboard boot arm) or a dashboard enable can fall back too, and an argv broadcast that fails after `am` ran can still have exposed the token. To check from outside, watch `adb shell ps -A | grep radar_token` during the enable.
|
|
240
247
|
* What it stops: a browser page that reaches the forwarded port (DNS rebinding, or any page you visit), and another app on the device connecting to the abstract socket. Neither can read your `~/.slack-radar`.
|
|
241
|
-
* What it does not stop: anything with adb access. The adb server on `127.0.0.1:5037` has no auth, so any local process can send a tokenless
|
|
242
|
-
* Open mode is deliberate: an
|
|
248
|
+
* What it does not stop: anything with adb access. The adb server on `127.0.0.1:5037` has no auth, so any local process can send a tokenless `ENABLE_RADAR` and put the device back in open mode, read the private token file with `run-as` in the moment before the app consumes it, or see the token in host or device `ps` during an argv fallback. Processes running as you can read the host file. The token keeps honest sessions apart; it does not lock out adb.
|
|
249
|
+
* Open mode is deliberate: an `ENABLE_RADAR` broadcast with no `radar_token` extra (an older Radar MCP or dashboard, or a hand-typed `am broadcast`) turns the check off so older builds keep working. `ENABLE_RADAR_TOKEN_FILE` never opens a tokenless session: a refused file is logged and the session kept as it was, and a build that predates the action drops the broadcast. The MCP warns on every enable result and every `ping` that finds the device in open mode. The dashboard does not warn.
|
|
243
250
|
* The token is never logged and never appears in an error. A failed broadcast reports adb's exit code and the first line of its stderr, with any token-shaped text redacted.
|
|
244
251
|
* The file is never replaced on a 401. Delete it only when a message says the file itself is unusable; then re-enable every other Radar session so they pick up the new one.
|
|
245
252
|
* Known limit: the dashboard forwards every device route (`/api`, `/flags`, `/backfill`, `/detail`) to the device with the token attached. Reads need only a local Host header; writes need an `X-Radar-Dashboard: 1` header or a JSON Content-Type. Any local process can send all of these, so while a dashboard runs, any local process reaches the device through it, writes included. Stop the dashboard when you are not using it.
|
|
@@ -263,7 +270,7 @@ What gets captured depends on the in-app server implementation. The MCP server i
|
|
|
263
270
|
* **Test runs**: Made-up RTM replay frames sent to the app's handler. The device keeps the last ten run summaries, with settled counts and per-type timings.
|
|
264
271
|
* **SQLite database** (Database tab, web dashboard only): when you open a database, a read-only **plaintext** copy of that on-device store (message text, request/response bodies, user/channel/team IDs) is pulled to a temp directory **on your own machine** (`os.tmpdir()/slack-radar-db-<port>`, files mode 0600). Auto-deleted when the dashboard process stops.
|
|
265
272
|
* **SharedPreferences** (`list_prefs`/`get_prefs`/`search_prefs`, and the Preferences tab): read directly off the device over `adb`, no local copy written. Files can contain feature flag overrides, cached team/org/channel IDs, and other app state.
|
|
266
|
-
* **Feature flags** (`list_feature_flags`/`search_feature_flags`/`get_feature_flag`): read directly off the device over `adb`, no local copy written. Shows every flag's
|
|
273
|
+
* **Feature flags** (`list_feature_flags`/`search_feature_flags`/`get_feature_flag`): read directly off the device over `adb`, no local copy written. Shows every flag's latest effective value, the flag's own value the app runs now (the first-read value once a flag has been read this session) where the build reports it, and whether it is locally overridden.
|
|
267
274
|
|
|
268
275
|
The network, RTM, clog, and trace captures are in-memory ring buffers. The Database tab is the exception: it writes a plaintext copy of the selected on-device database to a temp file on your host for the duration of the session. Review before sharing anything from it.
|
|
269
276
|
|
|
@@ -355,7 +362,7 @@ An older Radar MCP or dashboard, or a manual `am broadcast`, enabled the device
|
|
|
355
362
|
Another Radar session enabled the device after you did: another machine or OS user, a session using a token file you deleted, or Radar enabled in a different profile. Stop that session, or run `/radar-enable` in it so it picks up the new file, or make sure the Slack debug build runs in the profile you want (`list_profiles` shows which do), then run `/radar-enable` here (on the dashboard, press Reconnect). Deleting `~/.slack-radar/radar-token` never fixes this.
|
|
356
363
|
|
|
357
364
|
**Devices with more than one user (e.g. a work profile)**
|
|
358
|
-
The MCP server auto-detects the Android user ID via `ps` and targets the broadcast accordingly. No manual `--user` flag needed. In the dashboard's Logs tab, the package filter narrows logcat to the Slack app; clear the chip or pick another package to widen it.
|
|
365
|
+
The MCP server auto-detects the Android user ID via `ps` and targets the broadcast accordingly. No manual `--user` flag needed while `ps` finds the app running in that profile; open it there first, and use `activate_for_user` when `ps` cannot tell. When Slack debug builds run in several profiles, `SLACK_RADAR_DEBUG_PACKAGE` wins in every one. Unset, an enable arms the build the last enable chose (`com.Slack.internal.debug` on the first enable) wherever it runs, a non-zero profile first, and takes another shipped debug build only when that preferred one runs in no profile. Re-arms stay on the build the enable armed, and `activate_for_user` arms another profile. In the dashboard's Logs tab, the package filter narrows logcat to the Slack app; clear the chip or pick another package to widen it.
|
|
359
366
|
|
|
360
367
|
**Tools not appearing after setup**
|
|
361
368
|
Restart your Claude Code session. MCP servers are registered at session start.
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
export interface DashboardHealthIdentity {
|
|
2
2
|
platform?: string;
|
|
3
3
|
device_serial?: string | null;
|
|
4
|
+
log_package?: string;
|
|
5
|
+
device?: boolean;
|
|
4
6
|
}
|
|
5
7
|
/** Whether an existing dashboard process belongs to this MCP transport and selected device. */
|
|
6
8
|
export declare function dashboardMatchesDevice(platform: string, selectedSerial: string | null | undefined, health: DashboardHealthIdentity): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Error text when a running dashboard reads a different Slack debug build than this armed MCP,
|
|
11
|
+
* else null. Unarmed, the MCP has no fresher answer than the dashboard (a human-launched one may
|
|
12
|
+
* have detected its own build), and a dashboard that does not report log_package is older. A dashboard
|
|
13
|
+
* that could not see the socket has no build to be wrong about, and its next poll adopts the owner,
|
|
14
|
+
* but only a shipped id: an override build is never adopted, so that case is refused as before.
|
|
15
|
+
*/
|
|
16
|
+
export declare function dashboardDebugPackageError(armed: boolean, ourPackage: string, health: DashboardHealthIdentity): string | null;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEBUG_PACKAGE_ENV, SHIPPED_DEBUG_PACKAGES } from "../shared/constants.js";
|
|
1
2
|
/** Whether an existing dashboard process belongs to this MCP transport and selected device. */
|
|
2
3
|
export function dashboardMatchesDevice(platform, selectedSerial, health) {
|
|
3
4
|
// A dashboard started before /health carried `platform` (1.21.0 and earlier) is Android-only,
|
|
@@ -9,3 +10,22 @@ export function dashboardMatchesDevice(platform, selectedSerial, health) {
|
|
|
9
10
|
}
|
|
10
11
|
return true;
|
|
11
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Error text when a running dashboard reads a different Slack debug build than this armed MCP,
|
|
15
|
+
* else null. Unarmed, the MCP has no fresher answer than the dashboard (a human-launched one may
|
|
16
|
+
* have detected its own build), and a dashboard that does not report log_package is older. A dashboard
|
|
17
|
+
* that could not see the socket has no build to be wrong about, and its next poll adopts the owner,
|
|
18
|
+
* but only a shipped id: an override build is never adopted, so that case is refused as before.
|
|
19
|
+
*/
|
|
20
|
+
export function dashboardDebugPackageError(armed, ourPackage, health) {
|
|
21
|
+
if (!armed || !health.log_package || health.log_package === ourPackage)
|
|
22
|
+
return null;
|
|
23
|
+
if (health.device !== true && SHIPPED_DEBUG_PACKAGES.includes(ourPackage))
|
|
24
|
+
return null;
|
|
25
|
+
// A restart adopts the armed build at boot, but only for a shipped id; any other id came from
|
|
26
|
+
// an override, so the restarted dashboard needs it in its own environment.
|
|
27
|
+
const restart = SHIPPED_DEBUG_PACKAGES.includes(ourPackage)
|
|
28
|
+
? "Restart the dashboard or use a separate SLACK_RADAR_WEB_PORT."
|
|
29
|
+
: `Restart the dashboard with ${DEBUG_PACKAGE_ENV}=${ourPackage} in its environment, or use a separate SLACK_RADAR_WEB_PORT.`;
|
|
30
|
+
return `The dashboard reads ${health.log_package} but this session armed ${ourPackage}. ${restart}`;
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Session data (ring buffers, the event spool, cached flags) belongs to one Slack debug build.
|
|
2
|
+
// A re-enable or profile switch on the same device can land on another build, whose event ids restart from zero
|
|
3
|
+
// and would collide with the old ones in the spool's have-set. Kept out of index.ts (which
|
|
4
|
+
// connects stdio at load) so it is testable; the effects are injected. Only the enable and the
|
|
5
|
+
// profile switch check; a re-arm targets the held build and never lands here.
|
|
6
|
+
export function createDebugPackageReset(currentPackage, reset, startSpool) {
|
|
7
|
+
let held = null;
|
|
8
|
+
// Reads the package at call time, never captured, since an arm can change it.
|
|
9
|
+
const check = () => {
|
|
10
|
+
const pkg = currentPackage();
|
|
11
|
+
if (held !== null && held !== pkg)
|
|
12
|
+
reset();
|
|
13
|
+
held = pkg;
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
check,
|
|
17
|
+
// The enable's spool start: reset first, so the spool opens on a fresh file and the backfill
|
|
18
|
+
// that follows builds its have-set from it.
|
|
19
|
+
startSpool() {
|
|
20
|
+
check();
|
|
21
|
+
startSpool();
|
|
22
|
+
},
|
|
23
|
+
// A device switch already resets everything, so the next arm must not reset twice.
|
|
24
|
+
forget() {
|
|
25
|
+
held = null;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
package/dist/mcp/flags-tools.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// Flags dashboard tab filters client-side after one full fetch. A device-side fix is the real
|
|
9
9
|
// fix (tracked separately); this stays the correct behavior either way once that ships, since
|
|
10
10
|
// filtering an already-correct list is a no-op.
|
|
11
|
-
import { friendlyFeatureFlagError } from "../shared/feature-flags.js";
|
|
11
|
+
import { flagRestartNote, friendlyFeatureFlagError } from "../shared/feature-flags.js";
|
|
12
12
|
/**
|
|
13
13
|
* Shares one in-flight fetch of the flag list across the three tools (a model doing "list,
|
|
14
14
|
* then search, then get" in one turn would otherwise pay a device round-trip per call).
|
|
@@ -54,7 +54,15 @@ function wellFormedRows(response) {
|
|
|
54
54
|
return [];
|
|
55
55
|
return raw
|
|
56
56
|
.filter((f) => typeof f === "object" && f !== null && typeof f.key === "string")
|
|
57
|
-
.map(dropEmptyOrg)
|
|
57
|
+
.map(dropEmptyOrg)
|
|
58
|
+
.map(withRestartNote);
|
|
59
|
+
}
|
|
60
|
+
function withRestartNote(f) {
|
|
61
|
+
// Dropped first so a device that sent its own note cannot pass it through: only this function
|
|
62
|
+
// writes it, and only for a real mismatch.
|
|
63
|
+
const { restart_note: _dropped, ...row } = f;
|
|
64
|
+
const note = flagRestartNote(f);
|
|
65
|
+
return note === undefined ? row : { ...row, restart_note: note };
|
|
58
66
|
}
|
|
59
67
|
// An empty org id means the same thing as no org id, so it is dropped rather than treated as a
|
|
60
68
|
// distinct org a caller could match or that an error message would render as a blank name. Same
|
package/dist/mcp/index.js
CHANGED
|
@@ -9,10 +9,11 @@ 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, setRadarPort, } from "../shared/constants.js";
|
|
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";
|
|
@@ -27,6 +28,7 @@ import { resolveDetailById } from "./session-detail.js";
|
|
|
27
28
|
import { decorateToolResult } from "./network-detail.js";
|
|
28
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,9 +36,9 @@ 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
44
|
import { unauthorizedResponse } from "./radar-response.js";
|
|
@@ -48,18 +50,6 @@ import { buildOpenDashboardResult, readDashboardFingerprint } from "./stale-dash
|
|
|
48
50
|
// pulled out to a pure function so the bin-name/subcommand rules are unit-testable.
|
|
49
51
|
const sub = process.argv[2];
|
|
50
52
|
const { wantsInstallApp, wantsWeb } = computeDispatch(process.argv[1], sub);
|
|
51
|
-
// The background check RadarApp.swift spawns on every dock launch (see install-app.ts's
|
|
52
|
-
// runSelfHealCheck). A sibling of install-app, not a third dispatch branch: same subcommand,
|
|
53
|
-
// different entry point once inside.
|
|
54
|
-
const wantsSelfHealCheck = wantsInstallApp && process.argv.includes("--self-heal-check");
|
|
55
|
-
// What RadarApp.swift ACTUALLY spawns now (see install-app.ts's runSelfHealPrecheck): a safe
|
|
56
|
-
// registry-version precheck that only falls through to --self-heal-check once a real upgrade is
|
|
57
|
-
// confirmed. Checked before wantsSelfHealCheck below so the two flags stay mutually exclusive.
|
|
58
|
-
const wantsSelfHealPrecheck = wantsInstallApp && process.argv.includes("--self-heal-precheck");
|
|
59
|
-
// The two interactive halves of the app's Check for Updates... item: ask whether a newer build is
|
|
60
|
-
// published, then install it. Each prints a single JSON line for the app to read.
|
|
61
|
-
const wantsCheckUpdate = wantsInstallApp && process.argv.includes("--check-update");
|
|
62
|
-
const wantsUpdateNow = wantsInstallApp && process.argv.includes("--update-now");
|
|
63
53
|
// --- Web dashboard bridge (open_radar_dashboard) ---
|
|
64
54
|
//
|
|
65
55
|
// The MCP server and the web dashboard are separate processes. open_radar_dashboard
|
|
@@ -169,7 +159,7 @@ function getSpecTitle() {
|
|
|
169
159
|
req.end();
|
|
170
160
|
});
|
|
171
161
|
}
|
|
172
|
-
async function openDashboardSpec(device, spec) {
|
|
162
|
+
async function openDashboardSpec(device, spec, armed) {
|
|
173
163
|
const cold = !(await webAlive());
|
|
174
164
|
if (cold) {
|
|
175
165
|
// Seed the spec into the spawned server so it is the startup writer and the browser's
|
|
@@ -190,6 +180,11 @@ async function openDashboardSpec(device, spec) {
|
|
|
190
180
|
if (!dashboardMatchesDevice(device.platform, selected, health)) {
|
|
191
181
|
throw new Error("The dashboard port belongs to a different platform or device. Use a separate SLACK_RADAR_WEB_PORT.");
|
|
192
182
|
}
|
|
183
|
+
const packageError = device.platform === "android"
|
|
184
|
+
? dashboardDebugPackageError(armed, slackDebugPackage(), health)
|
|
185
|
+
: null;
|
|
186
|
+
if (packageError)
|
|
187
|
+
throw new Error(packageError);
|
|
193
188
|
// A dashboard keeps the version it started with, so read its version on both the cold and warm paths.
|
|
194
189
|
const fingerprint = await readDashboardFingerprint(WEB_BASE);
|
|
195
190
|
const r = await postSpec(spec);
|
|
@@ -210,26 +205,8 @@ async function openDashboardSpec(device, spec) {
|
|
|
210
205
|
return { ...r.json, fingerprint };
|
|
211
206
|
}
|
|
212
207
|
if (wantsInstallApp) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
console.log(JSON.stringify(await checkForUpdate(process.env.RADAR_APP_VERSION)));
|
|
216
|
-
}
|
|
217
|
-
else if (wantsUpdateNow) {
|
|
218
|
-
const { runUpdateNow } = await import("../web/install-app.js");
|
|
219
|
-
await runUpdateNow();
|
|
220
|
-
}
|
|
221
|
-
else if (wantsSelfHealPrecheck) {
|
|
222
|
-
const { runSelfHealPrecheck } = await import("../web/install-app.js");
|
|
223
|
-
runSelfHealPrecheck();
|
|
224
|
-
}
|
|
225
|
-
else if (wantsSelfHealCheck) {
|
|
226
|
-
const { runSelfHealCheck } = await import("../web/install-app.js");
|
|
227
|
-
runSelfHealCheck();
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
const { runInstallApp } = await import("../web/install-app.js");
|
|
231
|
-
runInstallApp();
|
|
232
|
-
}
|
|
208
|
+
const { runInstallAppCli } = await import("../web/install-app-cli.js");
|
|
209
|
+
await runInstallAppCli(process.argv);
|
|
233
210
|
}
|
|
234
211
|
else if (wantsWeb) {
|
|
235
212
|
const { startWebServer } = await import("../web/bin.js");
|
|
@@ -417,6 +394,8 @@ async function runMcpServer() {
|
|
|
417
394
|
return device.reassertForward?.() ?? device.ensureForward();
|
|
418
395
|
}
|
|
419
396
|
const REARM_BUDGET_MS = 30_000;
|
|
397
|
+
// Counts recovery re-arms so requests that fail together (a backfill fans out five) share one.
|
|
398
|
+
let recoveryRearms = 0;
|
|
420
399
|
async function callRadar(requestPath, init = {}) {
|
|
421
400
|
if (!device.supportsRadarHttpTools) {
|
|
422
401
|
return {
|
|
@@ -448,6 +427,7 @@ async function runMcpServer() {
|
|
|
448
427
|
};
|
|
449
428
|
const mismatch = (response) => unauthorizedResponse(response, device);
|
|
450
429
|
device.activate(device.getTimeoutMinutes());
|
|
430
|
+
const rearmsAtSend = recoveryRearms;
|
|
451
431
|
try {
|
|
452
432
|
return mismatch(await requestFromVerifiedPeer());
|
|
453
433
|
}
|
|
@@ -459,17 +439,28 @@ async function runMcpServer() {
|
|
|
459
439
|
device.resetState();
|
|
460
440
|
return { error: `${REQUEST_LOST_PREFIX}${error.message}. Call again.`, request_lost: true };
|
|
461
441
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
442
|
+
// A sibling request already re-armed since this one went out; a second broadcast would only restart it.
|
|
443
|
+
if (recoveryRearms === rearmsAtSend) {
|
|
444
|
+
device.resetState();
|
|
445
|
+
destroyStream();
|
|
446
|
+
if (!device.ensureForward()) {
|
|
447
|
+
sessionEnabled = false;
|
|
448
|
+
return {
|
|
449
|
+
error: "Device not connected or radar not running. Session disabled. Use /radar-enable to reconnect.",
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
// The re-arm is a fresh claim on the device, so a refusal from before it is stale.
|
|
453
|
+
clearStreamRejected();
|
|
454
|
+
recoveryRearms++;
|
|
469
455
|
}
|
|
456
|
+
// Also for a skipper: a no-op on an armed device, its own try if the sibling's arm failed.
|
|
457
|
+
// When that try is the one that lands, it is the re-arm, so the refusal it leaves behind is stale too.
|
|
458
|
+
const armFailedBefore = Boolean(device.getLastActivateError?.());
|
|
470
459
|
device.activate(device.getTimeoutMinutes());
|
|
471
|
-
|
|
472
|
-
|
|
460
|
+
if (armFailedBefore && !device.getLastActivateError?.()) {
|
|
461
|
+
destroyStream();
|
|
462
|
+
clearStreamRejected();
|
|
463
|
+
}
|
|
473
464
|
try {
|
|
474
465
|
return mismatch(await requestFromVerifiedPeer());
|
|
475
466
|
}
|
|
@@ -478,9 +469,7 @@ async function runMcpServer() {
|
|
|
478
469
|
if (init.reportLost && e2.message === REQUEST_TIMED_OUT)
|
|
479
470
|
return { error: `${REQUEST_LOST_PREFIX}${e2.message}. Call again.`, request_lost: true };
|
|
480
471
|
sessionEnabled = false;
|
|
481
|
-
return {
|
|
482
|
-
error: `Radar not responding: ${e2.message}. Session disabled. Use /radar-enable to reconnect.`,
|
|
483
|
-
};
|
|
472
|
+
return { error: sessionDisabledLine(device, `Radar not responding: ${e2.message}.`) };
|
|
484
473
|
}
|
|
485
474
|
}
|
|
486
475
|
}
|
|
@@ -530,6 +519,16 @@ async function runMcpServer() {
|
|
|
530
519
|
};
|
|
531
520
|
}
|
|
532
521
|
// --- Tool handlers ---
|
|
522
|
+
// Not stopCapture (logcat is device-wide) and not cleanupPulledDatabases (pulled file names
|
|
523
|
+
// already carry the package).
|
|
524
|
+
const debugPackageReset = createDebugPackageReset(() => slackDebugPackage(), () => {
|
|
525
|
+
// Both callers run with a session that is, or is about to be, enabled, so the spool reopens.
|
|
526
|
+
stopSpool();
|
|
527
|
+
startSpool();
|
|
528
|
+
clearLocalBuffers();
|
|
529
|
+
clearSources();
|
|
530
|
+
featureFlagsCache.clear();
|
|
531
|
+
}, startSpool);
|
|
533
532
|
async function handleSessionEnable(args) {
|
|
534
533
|
const deviceSerial = args?.device_serial || null;
|
|
535
534
|
// The enabler owns the choice, counters and flag updates without starting stdio.
|
|
@@ -542,7 +541,9 @@ async function runMcpServer() {
|
|
|
542
541
|
isStreamConnected,
|
|
543
542
|
wasStreamRejected,
|
|
544
543
|
resetDbState,
|
|
545
|
-
|
|
544
|
+
// After the arm and before the backfill: the spool reopens fresh and the backfill's have-set
|
|
545
|
+
// is built from the new file.
|
|
546
|
+
startSpool: () => debugPackageReset.startSpool(),
|
|
546
547
|
runBackfill: runBackfillSerialized,
|
|
547
548
|
// A health ping does not need the default 10s: a half-alive server
|
|
548
549
|
// (accepts TCP, never answers) would otherwise stretch the verify loop
|
|
@@ -551,9 +552,16 @@ async function runMcpServer() {
|
|
|
551
552
|
// under that ceiling.
|
|
552
553
|
ping: () => peerPing(),
|
|
553
554
|
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
555
|
+
onForeignOwnerAfterBackfill: () => {
|
|
556
|
+
debugPackageReset.forget();
|
|
557
|
+
// The backfill filled the rings from the foreign build too.
|
|
558
|
+
clearLocalBuffers();
|
|
559
|
+
stopSpool();
|
|
560
|
+
},
|
|
554
561
|
// Only fires on a switch to a different device: the prior device's buffers,
|
|
555
562
|
// spool, capture, and pulled DBs are stale for the new hardware.
|
|
556
563
|
onDeviceSwitch: () => {
|
|
564
|
+
debugPackageReset.forget();
|
|
557
565
|
clearLocalBuffers();
|
|
558
566
|
// Closing the spool is also what keeps the old device's switchboard records out of
|
|
559
567
|
// export_switchboard_session's device-free fallback.
|
|
@@ -563,6 +571,8 @@ async function runMcpServer() {
|
|
|
563
571
|
// The old device's declared sources and cached flags do not describe the new one.
|
|
564
572
|
clearSources();
|
|
565
573
|
featureFlagsCache.clear();
|
|
574
|
+
// The new device may run a different Slack debug build; the next arm re-detects it.
|
|
575
|
+
resetSlackDebugPackage();
|
|
566
576
|
},
|
|
567
577
|
};
|
|
568
578
|
const outcome = await enabler.enable(args?.timeout_minutes, deviceSerial, deps);
|
|
@@ -671,6 +681,8 @@ async function runMcpServer() {
|
|
|
671
681
|
const timeout = args?.timeout_minutes || device.getTimeoutMinutes() || 5;
|
|
672
682
|
clearRadarTokenCache();
|
|
673
683
|
enabler.switchProfile(() => activateForUser.call(device, args.user_id, timeout));
|
|
684
|
+
// The switch can land on another build; reset before its frames reach the old buffers.
|
|
685
|
+
debugPackageReset.check();
|
|
674
686
|
// Restart the SSE stream so network/RTM/clog events from the newly
|
|
675
687
|
// activated profile start flowing again.
|
|
676
688
|
destroyStream();
|
|
@@ -684,12 +696,13 @@ async function runMcpServer() {
|
|
|
684
696
|
return textResult({
|
|
685
697
|
user_id: args.user_id,
|
|
686
698
|
timeout_minutes: timeout,
|
|
699
|
+
...tokenViaArgvField(device),
|
|
687
700
|
capture_file: device.getCaptureFilePath?.() ?? null,
|
|
688
701
|
note: "Profile activated. Log capture restarted on a new file; old capture preserved for 7 days.",
|
|
689
702
|
});
|
|
690
703
|
}
|
|
691
704
|
catch (e) {
|
|
692
|
-
return textResult({ error: e instanceof TokenFileError ? tokenFileMessage(e, "profile") : `Profile activation failed: ${e.message}. Is the device connected? Check adb devices.` }, true);
|
|
705
|
+
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);
|
|
693
706
|
}
|
|
694
707
|
}
|
|
695
708
|
async function handleCaptureSnapshot(args) {
|
|
@@ -812,18 +825,25 @@ async function runMcpServer() {
|
|
|
812
825
|
const result = await callRadar("/api/clear");
|
|
813
826
|
return textResult(result, !!result.error);
|
|
814
827
|
}
|
|
828
|
+
function dashboardUrlField() {
|
|
829
|
+
return dashboardPlatformError(device) ? {} : { dashboard_url: WEB_BASE };
|
|
830
|
+
}
|
|
815
831
|
async function handlePing(args) {
|
|
816
832
|
if (args?.timeout_minutes) {
|
|
817
833
|
device.activate(args.timeout_minutes);
|
|
818
834
|
const tokenFileError = device.getLastActivateTokenFileError?.();
|
|
819
|
-
if (tokenFileError)
|
|
820
|
-
return textResult({ error: tokenFileError.message, mcp_version: RADAR_VERSION }, true);
|
|
835
|
+
if (tokenFileError) {
|
|
836
|
+
return textResult({ error: tokenFileError.message, mcp_version: RADAR_VERSION, ...dashboardUrlField() }, true);
|
|
837
|
+
}
|
|
821
838
|
}
|
|
822
839
|
const result = await callRadar("/api/ping");
|
|
823
840
|
// Version is a property of this process, not the device, so it is reported
|
|
824
841
|
// even when the device probe fails — the error path is exactly when a
|
|
825
842
|
// reviewer needs to correlate a report against a known-bad release.
|
|
826
843
|
result.mcp_version = RADAR_VERSION;
|
|
844
|
+
// Same reasoning: the dashboard address comes from this process's port setting, so it is
|
|
845
|
+
// reported even when the device is down. It says where the dashboard lives, not whether it runs.
|
|
846
|
+
Object.assign(result, dashboardUrlField());
|
|
827
847
|
if (!result.error) {
|
|
828
848
|
result.stream_connected = isStreamConnected();
|
|
829
849
|
result.local_network_buffer = localNetworkBuffer.length;
|
|
@@ -850,7 +870,7 @@ async function runMcpServer() {
|
|
|
850
870
|
// The web server runs its own coerce+validate on /setspec, so a thin pass of
|
|
851
871
|
// the authored args is enough; a bad spec comes back as an HTTP 400 with its
|
|
852
872
|
// reason, which we surface verbatim rather than rendering silent zeros.
|
|
853
|
-
const out = await openDashboardSpec(device, args);
|
|
873
|
+
const out = await openDashboardSpec(device, args, sessionEnabled);
|
|
854
874
|
return textResult(buildOpenDashboardResult({ ...out, title: out.title ?? args.title }, out.fingerprint, RADAR_VERSION, WEB_BASE));
|
|
855
875
|
}
|
|
856
876
|
catch (e) {
|
|
@@ -861,7 +881,7 @@ async function runMcpServer() {
|
|
|
861
881
|
}
|
|
862
882
|
}
|
|
863
883
|
// --- MCP Server ---
|
|
864
|
-
const server = new Server({ name: "slack-radar", version: "1.
|
|
884
|
+
const server = new Server({ name: "slack-radar", version: "1.25.0" }, { capabilities: { tools: {} }, instructions: serverInstructions(device.platform) });
|
|
865
885
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
866
886
|
tools: TOOL_DEFINITIONS,
|
|
867
887
|
}));
|
package/dist/mcp/radar-http.js
CHANGED
|
@@ -23,8 +23,10 @@ export function radarHttpRequest({ host, port, path, method = "GET", body, timeo
|
|
|
23
23
|
clearTimeout(overallTimer);
|
|
24
24
|
reject(error);
|
|
25
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.
|
|
26
28
|
const req = http.request({
|
|
27
|
-
host, port, path, method, timeout: timeoutMs,
|
|
29
|
+
host, port, path, method, timeout: timeoutMs, agent: false,
|
|
28
30
|
headers: {
|
|
29
31
|
...radarTokenHeaderFor(transport),
|
|
30
32
|
...(body === undefined ? {} : {
|
|
@@ -12,6 +12,7 @@ export interface EnableDeps {
|
|
|
12
12
|
ping: () => Promise<Record<string, unknown>>;
|
|
13
13
|
sleep: (ms: number) => Promise<void>;
|
|
14
14
|
onDeviceSwitch: () => void;
|
|
15
|
+
onForeignOwnerAfterBackfill?: () => void;
|
|
15
16
|
}
|
|
16
17
|
export interface EnableOutcome {
|
|
17
18
|
body: Record<string, unknown>;
|