@slack/radar-mcp 1.21.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.
Files changed (80) hide show
  1. package/README.md +68 -15
  2. package/dist/mcp/api-paths.d.ts +2 -2
  3. package/dist/mcp/api-paths.js +4 -19
  4. package/dist/mcp/dashboard-identity.d.ts +6 -0
  5. package/dist/mcp/dashboard-identity.js +11 -0
  6. package/dist/mcp/index.js +117 -32
  7. package/dist/mcp/logs-result.d.ts +1 -0
  8. package/dist/mcp/logs-result.js +1 -0
  9. package/dist/mcp/radar-export-get.d.ts +30 -0
  10. package/dist/mcp/radar-export-get.js +49 -0
  11. package/dist/mcp/radar-response.d.ts +4 -1
  12. package/dist/mcp/radar-response.js +8 -3
  13. package/dist/mcp/session-backfill.js +3 -4
  14. package/dist/mcp/session-enable.d.ts +1 -0
  15. package/dist/mcp/session-enable.js +146 -15
  16. package/dist/mcp/snapshot.js +42 -26
  17. package/dist/mcp/sources-gate.js +1 -0
  18. package/dist/mcp/stale-dashboard.d.ts +23 -0
  19. package/dist/mcp/stale-dashboard.js +122 -0
  20. package/dist/mcp/switchboard-spool.d.ts +12 -0
  21. package/dist/mcp/switchboard-spool.js +107 -0
  22. package/dist/mcp/switchboard-tools.d.ts +9 -0
  23. package/dist/mcp/switchboard-tools.js +144 -6
  24. package/dist/mcp/tools.d.ts +4 -1
  25. package/dist/mcp/tools.js +60 -15
  26. package/dist/mcp/web-child-env.d.ts +4 -1
  27. package/dist/mcp/web-child-env.js +4 -1
  28. package/dist/shared/android.d.ts +43 -0
  29. package/dist/shared/android.js +227 -19
  30. package/dist/shared/constants.d.ts +9 -4
  31. package/dist/shared/constants.js +9 -4
  32. package/dist/shared/feature-flags.d.ts +1 -0
  33. package/dist/shared/feature-flags.js +1 -0
  34. package/dist/shared/ios-logs.d.ts +10 -0
  35. package/dist/shared/ios-logs.js +91 -0
  36. package/dist/shared/ios.d.ts +25 -2
  37. package/dist/shared/ios.js +157 -3
  38. package/dist/{web → shared}/log-session.d.ts +45 -31
  39. package/dist/shared/log-session.js +300 -0
  40. package/dist/shared/radar-request-raw.d.ts +7 -0
  41. package/dist/shared/radar-request-raw.js +89 -0
  42. package/dist/shared/radar-token.d.ts +25 -0
  43. package/dist/shared/radar-token.js +164 -0
  44. package/dist/shared/stream.d.ts +3 -0
  45. package/dist/shared/stream.js +107 -15
  46. package/dist/shared/switchboard-host-store.d.ts +21 -0
  47. package/dist/shared/switchboard-host-store.js +166 -0
  48. package/dist/shared/switchboard-note.d.ts +15 -0
  49. package/dist/shared/switchboard-note.js +92 -0
  50. package/dist/shared/switchboard-report-file.d.ts +5 -0
  51. package/dist/shared/switchboard-report-file.js +26 -0
  52. package/dist/shared/switchboard-report.d.ts +20 -0
  53. package/dist/shared/switchboard-report.js +406 -0
  54. package/dist/shared/switchboard.d.ts +111 -2
  55. package/dist/shared/switchboard.js +436 -3
  56. package/dist/shared/transport.d.ts +43 -3
  57. package/dist/shared/version.d.ts +2 -0
  58. package/dist/shared/version.js +18 -0
  59. package/dist/shared/wire.d.ts +14 -1
  60. package/dist/web/install-app.d.ts +57 -8
  61. package/dist/web/install-app.js +270 -60
  62. package/dist/web/macapp/RadarApp.swift +340 -22
  63. package/dist/web/public/index.html +51 -9
  64. package/dist/web/public/next/app.js +33 -18
  65. package/dist/web/public/next/feed.js +102 -15
  66. package/dist/web/public/next/flags.js +3 -0
  67. package/dist/web/public/next/inspector.js +69 -3
  68. package/dist/web/public/next/prefs.js +5 -2
  69. package/dist/web/public/next/registry.js +18 -5
  70. package/dist/web/public/next/store.js +455 -29
  71. package/dist/web/public/next/switchboard-note.js +93 -0
  72. package/dist/web/public/next/toast.js +9 -5
  73. package/dist/web/public/next/voice-model.js +215 -35
  74. package/dist/web/public/next/voice.js +173 -18
  75. package/dist/web/server.d.ts +15 -11
  76. package/dist/web/server.js +690 -168
  77. package/dist/web/spec.d.ts +2 -1
  78. package/dist/web/spec.js +2 -1
  79. package/package.json +2 -2
  80. package/dist/web/log-session.js +0 -166
@@ -0,0 +1,107 @@
1
+ // The MCP export tool's host copy of switchboard records, read out of the session event spool,
2
+ // which already holds every switchboard frame this process received.
3
+ //
4
+ // A session_id restarts with the app process, so the spool can hold several calls under one id,
5
+ // and the enable backfill can append device rows after live ones or duplicate them.
6
+ // getSpoolSwitchboardRecords reduces that to the current call, each record once, because
7
+ // mergeSwitchboardRecords keys on the bare id and must never see an older call's id 1 next to
8
+ // this call's id 1.
9
+ //
10
+ // An auto-disable leaves the spool open, so these keep working after one; an explicit disable or
11
+ // a device switch closes it, which empties the fallback. clear_buffers keeps the spool open for
12
+ // other readers, so it records a mark and both functions read only past it.
13
+ import fs from "node:fs";
14
+ import { getSpoolFilePath, readSpool } from "../shared/event-spool.js";
15
+ import { SWITCHBOARD_KIND } from "../shared/switchboard.js";
16
+ // A mark only counts for the file it was taken on: a rotation or a re-enable opens a new file,
17
+ // which holds nothing from before the clear.
18
+ let clearMark = null;
19
+ // The spool can reach 100MB and one export reads it up to four times (the disabled gate, then the
20
+ // newest id and the records), so the switchboard frames are kept until the file changes.
21
+ let parsed = null;
22
+ function switchboardFrames() {
23
+ const file = getSpoolFilePath();
24
+ if (file === null)
25
+ return [];
26
+ let stat;
27
+ try {
28
+ stat = fs.statSync(file);
29
+ }
30
+ catch {
31
+ return [];
32
+ }
33
+ if (parsed !== null && parsed.file === file && parsed.size === stat.size && parsed.mtimeMs === stat.mtimeMs)
34
+ return parsed.frames;
35
+ const frames = readSpool().filter((f) => f.type === SWITCHBOARD_KIND);
36
+ parsed = { file, size: stat.size, mtimeMs: stat.mtimeMs, frames };
37
+ return frames;
38
+ }
39
+ /** Hide every switchboard record spooled so far from the export's host copy (clear_buffers). */
40
+ export function markSwitchboardSpoolCleared() {
41
+ const file = getSpoolFilePath();
42
+ clearMark = file === null ? null : { file, frames: switchboardFrames().length };
43
+ }
44
+ function framesSinceClear() {
45
+ const frames = switchboardFrames();
46
+ return clearMark !== null && clearMark.file === getSpoolFilePath() ? frames.slice(clearMark.frames) : frames;
47
+ }
48
+ function switchboardEventOf(frame) {
49
+ if (frame.type !== SWITCHBOARD_KIND)
50
+ return null;
51
+ return frame.event !== null && typeof frame.event === "object" ? frame.event : null;
52
+ }
53
+ const finiteOr = (v, fallback) => (typeof v === "number" && Number.isFinite(v) ? v : fallback);
54
+ /**
55
+ * The spooled records of `sessionId`'s newest call, each once, in id order. [] when the spool is
56
+ * closed (disabled) or this process never spooled the id.
57
+ *
58
+ * Walked in time order, a call starts at a session/begin, or at an id at or below one already
59
+ * seen (ids climb within a call, so this catches a restart whose begin was never spooled).
60
+ */
61
+ export function getSpoolSwitchboardRecords(sessionId) {
62
+ const byKey = new Map();
63
+ for (const frame of framesSinceClear()) {
64
+ const event = switchboardEventOf(frame);
65
+ if (event === null || event.session_id !== sessionId)
66
+ continue;
67
+ if (typeof event.id !== "number" || !Number.isFinite(event.id))
68
+ continue;
69
+ const key = `${event.id}\u0000${String(event.timestamp)}`;
70
+ if (!byKey.has(key))
71
+ byKey.set(key, event);
72
+ }
73
+ const records = [...byKey.values()].sort((a, b) => finiteOr(a.timestamp, -Infinity) - finiteOr(b.timestamp, -Infinity) || a.id - b.id);
74
+ let start = 0;
75
+ let maxId = -Infinity;
76
+ for (let i = 0; i < records.length; i++) {
77
+ const r = records[i];
78
+ const id = r.id;
79
+ if ((r.kind === "session" && r.event === "begin") || id <= maxId) {
80
+ start = i;
81
+ maxId = -Infinity;
82
+ }
83
+ maxId = Math.max(maxId, id);
84
+ }
85
+ return records.slice(start).sort((a, b) => a.id - b.id);
86
+ }
87
+ /** Ranked by timestamp, not id: ids restart with the app process, timestamps keep climbing. */
88
+ export function newestSpoolSwitchboardSessionId() {
89
+ let bestId = null;
90
+ let bestTimestamp = -Infinity;
91
+ for (const frame of framesSinceClear()) {
92
+ const event = switchboardEventOf(frame);
93
+ if (event === null)
94
+ continue;
95
+ const sessionId = event.session_id;
96
+ const timestamp = event.timestamp;
97
+ if (typeof sessionId !== "number" || !Number.isFinite(sessionId))
98
+ continue;
99
+ if (typeof timestamp !== "number" || !Number.isFinite(timestamp))
100
+ continue;
101
+ if (timestamp > bestTimestamp) {
102
+ bestTimestamp = timestamp;
103
+ bestId = sessionId;
104
+ }
105
+ }
106
+ return bestId;
107
+ }
@@ -1,3 +1,5 @@
1
+ import type { RadarTokenSender } from "../shared/radar-token.js";
2
+ import { type SwitchboardExportGet } from "../shared/switchboard.js";
1
3
  import { type RadarResponse } from "./radar-response.js";
2
4
  export interface HandlerResult {
3
5
  data: unknown;
@@ -7,3 +9,10 @@ export type RadarFetch = (apiPath: string) => Promise<RadarResponse>;
7
9
  export declare const SWITCHBOARD_BUDGET_HINT = "Pass kind or lower limit; for the whole session use query_session with source switchboard, which pages with a cursor.";
8
10
  export declare function handleGetSwitchboardSessions(fetch: RadarFetch): Promise<HandlerResult>;
9
11
  export declare function handleGetSwitchboardSession(args: Record<string, unknown>, fetch: RadarFetch): Promise<HandlerResult>;
12
+ export declare const SESSION_DISABLED_SUFFIX_LINE = "Session disabled. Use /radar-enable to reconnect.";
13
+ export declare const RECONNECT_ONLY_SUFFIX_LINE = "Use /radar-enable to reconnect.";
14
+ export declare function appendSessionDisabledSuffix(message: string, sessionJustDisabled: boolean): string;
15
+ export declare function handleExportSwitchboardSession(args: Record<string, unknown>, get: SwitchboardExportGet, sender: RadarTokenSender, now?: number, exportRoot?: string): Promise<HandlerResult>;
16
+ export declare function shouldExportSwitchboardOffline(requestedId: number | null, getHostRecords: (sessionId: number) => Record<string, unknown>[], getNewestHostSessionId: () => number | null): boolean;
17
+ export declare function handleExportSwitchboardSessionOffline(args: Record<string, unknown>, now?: number, exportRoot?: string): HandlerResult;
18
+ export declare function dispatchExportSwitchboardSession(args: Record<string, unknown>, isSessionEnabled: () => boolean, get: SwitchboardExportGet, sender: RadarTokenSender, now?: number, exportRoot?: string): Promise<HandlerResult>;
@@ -1,11 +1,14 @@
1
- // The two switchboard tools' handlers, pure so a test can drive them with a fake callRadar.
2
- // get_switchboard_sessions proxies the device's session list; get_switchboard_session validates
3
- // its args host-side (a bad id never reaches the device) and proxies one session's page. Both
4
- // keep the device's own error body (a 404 for an unknown id) as the tool error. An answer over the
5
- // response budget, whether radarRequest cut it on the wire or the parsed body would blow it once
6
- // serialized, comes back as the shared over-budget note with a hint of their own, since
1
+ // The switchboard tools' handlers. The two get_ tools are pure so a test can drive them with a
2
+ // fake callRadar; they validate args host-side (a bad id never reaches the device) and keep the
3
+ // device's own error body as the tool error. An over-budget answer gets its own hint, since
7
4
  // capture_snapshot does not bundle switchboard.
5
+ import os from "os";
6
+ import path from "path";
8
7
  import { MAX_RADAR_RESPONSE_BYTES } from "../shared/constants.js";
8
+ import { buildSwitchboardReport, capitalizeSwitchboardNote, stripSwitchboardControlChars, switchboardReportNotes } from "../shared/switchboard-report.js";
9
+ import { writeSwitchboardReportFile } from "../shared/switchboard-report-file.js";
10
+ import { getSpoolSwitchboardRecords, newestSpoolSwitchboardSessionId } from "./switchboard-spool.js";
11
+ import { assembleSwitchboardExport, hostOnlyGapCount, hostOnlySwitchboardDetail, nonNegativeIntArg, } from "../shared/switchboard.js";
9
12
  import { buildApiPath, switchboardSessionQuery } from "./api-paths.js";
10
13
  import { responseBudgetError } from "./radar-response.js";
11
14
  export const SWITCHBOARD_BUDGET_HINT = "Pass kind or lower limit; for the whole session use query_session with source switchboard, which pages with a cursor.";
@@ -38,3 +41,138 @@ export async function handleGetSwitchboardSession(args, fetch) {
38
41
  return { data: { error: q.error }, isError: true };
39
42
  return passThrough(await fetch(q.path));
40
43
  }
44
+ // Restrictive permissions like snapshot.ts, since a session record can carry a team_id.
45
+ const SWITCHBOARD_EXPORT_DIR = path.join(os.homedir(), ".slack-radar", "exports");
46
+ function parseSwitchboardExportId(args) {
47
+ if (args?.id === undefined || args.id === null)
48
+ return { ok: true, id: null };
49
+ const parsed = nonNegativeIntArg(args.id);
50
+ if (parsed === null) {
51
+ return { ok: false, error: `id must be a non-negative integer session_id from get_switchboard_sessions; got ${JSON.stringify(args.id)}.` };
52
+ }
53
+ return { ok: true, id: parsed };
54
+ }
55
+ export const SESSION_DISABLED_SUFFIX_LINE = "Session disabled. Use /radar-enable to reconnect.";
56
+ // For a session already off before the call: the report notes already say the session is off.
57
+ export const RECONNECT_ONLY_SUFFIX_LINE = "Use /radar-enable to reconnect.";
58
+ // switchboard.ts's messages are shared with the web export route, which has no session concept,
59
+ // so the MCP appends this itself when the export call is what disabled the session.
60
+ export function appendSessionDisabledSuffix(message, sessionJustDisabled) {
61
+ return sessionJustDisabled ? `${message} ${SESSION_DISABLED_SUFFIX_LINE}` : message;
62
+ }
63
+ export async function handleExportSwitchboardSession(args, get, sender, now = Date.now(), exportRoot = SWITCHBOARD_EXPORT_DIR) {
64
+ const parsedId = parseSwitchboardExportId(args);
65
+ if (!parsedId.ok)
66
+ return { data: { error: parsedId.error }, isError: true };
67
+ const assembled = await assembleSwitchboardExport(parsedId.id, get, getSpoolSwitchboardRecords, newestSpoolSwitchboardSessionId, sender, "mcp");
68
+ if (!assembled.ok) {
69
+ return { data: { error: assembled.message }, isError: true };
70
+ }
71
+ return writeSwitchboardReport(assembled, now, exportRoot);
72
+ }
73
+ // Lets the export through a disabled gate only when the spool holds records for the id it would
74
+ // resolve to; otherwise the ordinary gate error stands.
75
+ export function shouldExportSwitchboardOffline(requestedId, getHostRecords, getNewestHostSessionId) {
76
+ const sessionId = requestedId ?? getNewestHostSessionId();
77
+ return sessionId !== null && getHostRecords(sessionId).length > 0;
78
+ }
79
+ // Makes no device calls at all, which is what makes it safe to run through a disabled gate.
80
+ export function handleExportSwitchboardSessionOffline(args, now = Date.now(), exportRoot = SWITCHBOARD_EXPORT_DIR) {
81
+ const parsedId = parseSwitchboardExportId(args);
82
+ if (!parsedId.ok)
83
+ return { data: { error: parsedId.error }, isError: true };
84
+ const sessionId = parsedId.id ?? newestSpoolSwitchboardSessionId();
85
+ const hostRecords = sessionId !== null ? getSpoolSwitchboardRecords(sessionId) : [];
86
+ if (sessionId === null || hostRecords.length === 0) {
87
+ // Unreachable through the gate, which already requires spooled records.
88
+ return {
89
+ data: { error: "Radar is not active. Use /radar-enable to connect, or ask about the device to auto-enable." },
90
+ isError: true,
91
+ };
92
+ }
93
+ const detail = hostOnlySwitchboardDetail(sessionId, hostRecords);
94
+ const heldEvents = Array.isArray(detail.events) ? detail.events : [];
95
+ const assembly = {
96
+ ok: true,
97
+ sessionId,
98
+ detail,
99
+ hostStreamCount: heldEvents.length,
100
+ deviceEventCount: null,
101
+ deviceOldestTimestamp: null,
102
+ hostOnlyCause: "disabled",
103
+ walkStopReason: null,
104
+ gapCount: hostOnlyGapCount(heldEvents),
105
+ };
106
+ return writeSwitchboardReport(assembly, now, exportRoot, RECONNECT_ONLY_SUFFIX_LINE);
107
+ }
108
+ // isSessionEnabled is a getter so it can be read again after the device call, which may have
109
+ // disabled the session.
110
+ export async function dispatchExportSwitchboardSession(args, isSessionEnabled, get, sender, now = Date.now(), exportRoot = SWITCHBOARD_EXPORT_DIR) {
111
+ if (!isSessionEnabled()) {
112
+ return handleExportSwitchboardSessionOffline(args, now, exportRoot);
113
+ }
114
+ const result = await handleExportSwitchboardSession(args, get, sender, now, exportRoot);
115
+ return isSessionEnabled() ? result : withSessionDisabledSuffix(result);
116
+ }
117
+ // Touches only the returned data, never the file already on disk.
118
+ function withSessionDisabledSuffix(result) {
119
+ const data = result.data;
120
+ if (data === null || typeof data !== "object" || Array.isArray(data))
121
+ return result;
122
+ const d = { ...data };
123
+ if (typeof d.error === "string") {
124
+ d.error = appendSessionDisabledSuffix(d.error, true);
125
+ }
126
+ else {
127
+ if (Array.isArray(d.notes))
128
+ d.notes = [...d.notes, SESSION_DISABLED_SUFFIX_LINE];
129
+ if (typeof d.summary === "string")
130
+ d.summary = appendSessionDisabledSuffix(d.summary, true);
131
+ }
132
+ return { data: d, isError: result.isError };
133
+ }
134
+ // Build and write the report; a build or disk failure is a clean tool error, never a throw.
135
+ function writeSwitchboardReport(assembly, now, exportRoot,
136
+ // Describes the tool call, not the session, so it goes last in notes and summary and never
137
+ // into the file.
138
+ sessionDisabledSuffix = null) {
139
+ const { sessionId, detail, hostOnlyCause = null } = assembly;
140
+ let report;
141
+ try {
142
+ report = buildSwitchboardReport(assembly, now);
143
+ }
144
+ catch (e) {
145
+ return { data: { error: `Failed to build the report: ${e.message}` }, isError: true };
146
+ }
147
+ const reportNotes = switchboardReportNotes(report);
148
+ const notes = sessionDisabledSuffix ? [...reportNotes, sessionDisabledSuffix] : reportNotes;
149
+ // Stripped here too: the JSON result repeats server_session_id outside the stripped report.
150
+ const serverSessionId = typeof detail.server_session_id === "string" ? stripSwitchboardControlChars(detail.server_session_id) : null;
151
+ const recordCount = Array.isArray(detail.events) ? detail.events.length : 0;
152
+ const totalCaptured = typeof detail.total_captured === "number" ? detail.total_captured : null;
153
+ let file;
154
+ try {
155
+ file = writeSwitchboardReportFile(exportRoot, `switchboard-session-${sessionId}`, report, now);
156
+ }
157
+ catch (e) {
158
+ return { data: { error: `Failed to write the report to disk: ${e.message}` }, isError: true };
159
+ }
160
+ return {
161
+ data: {
162
+ path: file,
163
+ session_id: sessionId,
164
+ server_session_id: serverSessionId,
165
+ record_count: recordCount,
166
+ total_captured: totalCaptured,
167
+ notes,
168
+ host_recovered: assembly.hostStreamCount ?? 0,
169
+ device_gone: hostOnlyCause === "not-found",
170
+ device_unreachable: hostOnlyCause === "unreachable",
171
+ host_only_cause: hostOnlyCause,
172
+ summary: `Voice session ${sessionId}${serverSessionId ? ` (server ${serverSessionId})` : ""}: ${recordCount} record${recordCount === 1 ? "" : "s"} exported to ${file}.` +
173
+ (reportNotes.length > 0 ? ` ${capitalizeSwitchboardNote(reportNotes[0])}` : "") +
174
+ (sessionDisabledSuffix ? ` ${sessionDisabledSuffix}` : ""),
175
+ },
176
+ isError: false,
177
+ };
178
+ }
@@ -28,8 +28,11 @@ export declare const TOOL_DEFINITIONS: ToolDefinition[];
28
28
  /**
29
29
  * Check whether a tool call should be blocked by the session gate.
30
30
  * Returns an error response object if blocked, or null if allowed.
31
+ *
32
+ * `allowSwitchboardExportOffline` lets export_switchboard_session through while disabled; the
33
+ * caller sets it only when a host-only report can be built without touching the device.
31
34
  */
32
- export declare function sessionGate(toolName: string, sessionEnabled: boolean): {
35
+ export declare function sessionGate(toolName: string, sessionEnabled: boolean, allowSwitchboardExportOffline?: boolean): {
33
36
  content: Array<{
34
37
  type: string;
35
38
  text: string;
package/dist/mcp/tools.js CHANGED
@@ -4,7 +4,9 @@ export const SERVER_INSTRUCTIONS = [
4
4
  "Slack Radar provides on-device debugging tools for the Slack Android app via ADB.",
5
5
  "",
6
6
  "SESSION STATE:",
7
- "Radar starts DISABLED each session. All tools except ping return an error until enabled.",
7
+ "Radar starts DISABLED each session. ping, list_profiles, and open_radar_dashboard work before enabling; other tools return an error until enabled.",
8
+ "export_switchboard_session also works after an auto-disable if this process streamed the call",
9
+ "live. It builds the report from the live stream copy, no device call needed.",
8
10
  "Use /radar-enable to activate, /radar-disable to deactivate.",
9
11
  "",
10
12
  "AUTO-ENABLE: When the user asks an obvious device question, invoke the Skill tool with",
@@ -26,6 +28,8 @@ export const SERVER_INSTRUCTIONS = [
26
28
  '- "did I get X" / "did X happen" -> search(query="X") across ALL buffers, not just one',
27
29
  '- "everything since I enabled" / "the whole session" / "what did I miss" -> query_session',
28
30
  '- "what happened in the voice session" / "why did playback stutter" / "did the mic open" -> get_switchboard_sessions then get_switchboard_session(id, kind=...): player for stutter, state for mic and connection, phase for slow start',
31
+ '- "did the turns get saved" / "why is a turn missing from the DM" -> get_switchboard_session(id, kind=saved_turn): outcome is applied, no_line (no subtitle line still held the item, still kept), or why a turn was dropped; the summary\'s saved_turn_counts counts each outcome (absent on an older device build means not counted, not zero). A server resend counts again under applied or no_line, so their sum can run above the finals and is not a lost turn. Every turn other_session with a null server_session_id usually means session.ready named no session (a ready record with a null id) or never arrived (no ready record).',
32
+ '- "export this voice session" / "save the switchboard session" / "hand this voice session to someone else" -> export_switchboard_session(id=...)',
29
33
  '- "check the debug logs" -> get_recent_logs (tag is OPTIONAL: pass tag="SlackRadar" to filter, or omit it for all recent lines)',
30
34
  '- "is flag X on?" / "what is the effective value of X" / "what feature flags does the app have" -> get_feature_flag(key="X") / search_feature_flags(query="X") / list_feature_flags. This is the LIVE effective state (override if set, else server value), requires a debug build with the feature-flag Radar plugin.',
31
35
  '- "what feature-flag overrides are set?" / "check debug_features" -> search_prefs(query="X") or get_prefs(file="debug_features_...xml"). This shows MANUAL OVERRIDES only, not effective flag state: debug_features_*.xml holds only flags the debug menu overrode, and an override is deleted once it matches the server value. A flag missing from this file can still be ON server-side -- absence means "no override," never "disabled." Prefer get_feature_flag/list_feature_flags/search_feature_flags for the actual live value; use this route only when the manual-override history itself is what is being asked about.',
@@ -54,9 +58,10 @@ export const SERVER_INSTRUCTIONS = [
54
58
  "- Setup: /slack-radar-setup",
55
59
  "- Manual enable (no skill): adb shell am broadcast -a slack.debug.ENABLE_RADAR --ei timeout_minutes 5 -p com.Slack.internal.debug",
56
60
  " Then: adb forward tcp:8099 localabstract:slack-radar (prefix adb -s <serial> when multiple devices are attached)",
61
+ " This starts Radar in open mode (no radar_token extra, so the device accepts any caller). Use it only when /radar-enable cannot run; /radar-enable sends the token.",
57
62
  "",
58
63
  "WEB DASHBOARD (/radar-ui):",
59
- "A browser-based dashboard (http://localhost:8100) shows the same live device data as",
64
+ "A browser-based dashboard (http://localhost:8100, or the port set in SLACK_RADAR_WEB_PORT) shows the same live device data as",
60
65
  "tabs: Live (everything), Network, RTM, Clogs, Traces, Logs, and Switchboard, each with a",
61
66
  "filterable feed and a payload inspector, a live rate on most, a graph on Network and Traces,",
62
67
  "plus the Database/Preferences/Feature Flags browsers.",
@@ -109,8 +114,8 @@ export const SERVER_INSTRUCTIONS = [
109
114
  "- source is one of network/rtm/clog/trace/log/switchboard/all ('all' = one unified timeline).",
110
115
  "- match filters on SUMMARY fields only, by source: network=url/method/status_code,",
111
116
  " rtm=event_type/direction/channel, clog=event_name, trace=trace_name/span_name,",
112
- " log=tag/level/message/pid/package,",
113
- " switchboard=kind/session_id/direction/frame_type/state_kind/phase/event.",
117
+ " log=tag/level/message/pid/package (iOS also: subsystem/process),",
118
+ " switchboard=kind/session_id/direction/frame_type/state_kind/phase/event/clock/outcome.",
114
119
  " NEVER invent a field; a match on a field the stream does not carry silently matches",
115
120
  " nothing. To filter on body text use bodyContains (network/all only), which fetches detail.",
116
121
  "- viz composes counter/rate/sparkline/feed/inspector/graph/voice. graph needs a series array",
@@ -151,6 +156,24 @@ export const SERVER_INSTRUCTIONS = [
151
156
  export function serverInstructions(platform) {
152
157
  if (platform === "android")
153
158
  return SERVER_INSTRUCTIONS;
159
+ if (platform === "ios") {
160
+ return [
161
+ "PLATFORM: iOS Simulator (NOT Android over adb).",
162
+ "This overrides anything below that assumes Android:",
163
+ "- Radar selects a booted iOS Simulator and enables its app listener directly; ignore adb",
164
+ " broadcasts, Android profiles, package names, and work-profile switching advice.",
165
+ "- Available: ping, network calls, RTM events, clogs, traces, search, query_session,",
166
+ " wait_for_events, clear_buffers, feature flags, capture_snapshot, get_recent_logs,",
167
+ " screenshot, record_screen, and open_radar_dashboard.",
168
+ "- Not available: get_app_state, database tools, preferences tools, list_profiles, and",
169
+ " activate_for_user. Treat their supported-platform error as a capability gap.",
170
+ "- Unified-log capture begins when the Radar session is enabled; it cannot backfill logs",
171
+ " emitted before that point. Leave tag unset for all Slack-authored categories.",
172
+ "- Physical iOS devices are not supported yet.",
173
+ "",
174
+ SERVER_INSTRUCTIONS,
175
+ ].join("\n");
176
+ }
154
177
  if (platform === "webapp") {
155
178
  return [
156
179
  "PLATFORM: webapp (a local Slack webapp dev server, NOT an Android device over adb).",
@@ -179,7 +202,7 @@ export function serverInstructions(platform) {
179
202
  export const TOOL_DEFINITIONS = [
180
203
  {
181
204
  name: "ping",
182
- description: "Check if Slack Radar is running. Returns uptime, buffer sizes, remaining session time, stream status, the Radar MCP tool version (mcp_version), and which app/profile is bound: android_user_id (0 = personal, non-zero = a secondary user such as a work profile), profile ('personal'/'secondary'), and package.",
205
+ description: "Check if Slack Radar is running. Returns uptime, buffer sizes, remaining session time, stream status, the Radar MCP tool version (mcp_version), and which app/profile is bound: android_user_id (0 = personal, non-zero = a secondary user such as a work profile), profile ('personal'/'secondary'), and package. If the result has a warning field, show it to the user verbatim.",
183
206
  inputSchema: {
184
207
  type: "object",
185
208
  properties: {
@@ -320,25 +343,25 @@ export const TOOL_DEFINITIONS = [
320
343
  },
321
344
  {
322
345
  name: "get_switchboard_sessions",
323
- description: "List the Slackbot voice (switchboard) sessions the device still holds, at most 8, newest first. A session is one voice conversation attempt, from the controller starting (before any socket opens) to it ending. Each entry carries session_id, team_id, began_at, ended_at (null while live), total_captured (records held), frames {incoming, outgoing} counts, last_state (the newest connection/mic/speaking state, absent before the first state record) and levels (the newest audio level tick, or null). session_id restarts at 1 with the app process, so a small id can be the newest session; go by began_at. A session already running when radar was enabled lists from its first seen record, with team_id null. Follow with get_switchboard_session(id) for the records.",
346
+ description: "List the Slackbot voice (switchboard) sessions the device still holds, at most 8, newest first. A session is one voice conversation attempt, from the controller starting (before any socket opens) to it ending. Each entry carries session_id, team_id, began_at, ended_at (null live), total_captured, frames {incoming, outgoing}, last_state (newest connection/mic/speaking state, absent before the first state record), levels (newest level tick, or null), server_session_id (null until named), turns ({count, last_response_ms, last_clock}, null before the first timed turn) and saved_turn_counts (per outcome), all absent on an older build. last_response_ms can be a gap between reply chunks when last_clock is resumed_from_server_answer. session_id restarts at 1 with the app process; go by began_at. A session already running when radar was enabled lists from its first seen record, team_id null. get_switchboard_session(id) has the records.",
324
347
  inputSchema: { type: "object", properties: {} },
325
348
  annotations: { readOnlyHint: true },
326
349
  },
327
350
  {
328
351
  name: "get_switchboard_session",
329
- description: "Get one voice session's summary plus the newest `limit` of its records (events), oldest first; events is only the page. Record kinds: state = connection, mic and speaking transitions (state_kind, from, to, cause); frame = control frames in and out (direction, frame_type, bytes), audio frames carry frame_type audio and a byte count, never the audio; player = playback events rearm, jitter_trim, read_stall and pre_ready_drop with gap_ms and bytes_queued; phase = startup phase durations (phase, duration_ms); session = begin and end. Pass kind to narrow (player for stutter); the device filters by kind before taking the limit, so the page is the newest limit of that kind, while total_captured still counts every kind. No older page, raise limit instead. An unknown id is a device 404. The same records are in query_session under source switchboard.",
352
+ description: "Get one voice session's summary plus the newest `limit` of its records (events), oldest first; events is only the page. Record kinds: state = connection, mic and speaking transitions (state_kind, from, to, cause); frame = control frames in and out (direction, frame_type, bytes), audio frames carry frame_type audio and a byte count, never the audio; player = playback events rearm, jitter_trim, read_stall and pre_ready_drop with gap_ms and bytes_queued; phase = startup phase durations (phase, duration_ms); session = begin and end, plus ready (server_session_id); levels = one meter-tick batch (started_at, sample_count, offsets_ms, mic/playback rms+peak arrays, 0..1); turn = response_ms (end of speech to first reply audio) and clock (no_card, resumed_from_tap, resumed_from_server_answer); saved_turn = outcome (applied, no_line, missing_field, other_session), has_thread. Pass kind to narrow (player for stutter, levels for meter history); the device filters by kind before taking the limit, so the page is the newest limit of that kind, while total_captured still counts every kind. This is a single page, not the whole session; for that use export_switchboard_session or query_session under source switchboard. An unknown id is a device 404.",
330
353
  inputSchema: {
331
354
  type: "object",
332
355
  properties: {
333
356
  id: { type: "number", description: "The session_id from get_switchboard_sessions" },
334
357
  kind: {
335
358
  type: "string",
336
- enum: ["session", "state", "frame", "phase", "player"],
359
+ enum: ["session", "state", "frame", "phase", "player", "levels", "turn", "saved_turn"],
337
360
  description: "Only records of this kind (default: every kind)",
338
361
  },
339
362
  limit: {
340
363
  type: "number",
341
- description: "How many of the newest records to return (default: 50, max: 2000, the device's per-session ring)",
364
+ description: "How many of the newest records to return (default: 50, max: 2000 per request; the device may hold more than this single request returns; for the whole session use export_switchboard_session or query_session)",
342
365
  minimum: 1,
343
366
  maximum: 2000,
344
367
  },
@@ -347,6 +370,17 @@ export const TOOL_DEFINITIONS = [
347
370
  },
348
371
  annotations: { readOnlyHint: true },
349
372
  },
373
+ {
374
+ name: "export_switchboard_session",
375
+ description: "Write one Slackbot voice (switchboard) session's summary and its records to a plain-text file. Pages the device (up to 2000 per request, paged with before_id), then merges in this process's own live stream copy (read from its session event spool), so a call the device ring has since evicted can still show up if this MCP was connected while it happened. The export can stop early (for example an old device build that does not page, the 32 MB size cap, the page limit, or the device stopping answering), and the report notes say why anything is missing; the spool itself rotates at 100 MB across every event kind it captures, not just switchboard, so an unusually long or chatty session could in principle rotate away a call's own early records before the device ring would have evicted them. Writes it as a readable report (server_session_id, summary, then one line per record, oldest first) under ~/.slack-radar/exports/<file>, permissions 0700/0600 like capture_snapshot. Defaults to the newest session when id is omitted. Returns the file path, a short summary, and notes. An unknown id (404, unreachable, or a reply 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. Still works right after Radar auto-disables, from the live stream copy alone with no device call; an explicit /radar-disable or clear_buffers wipes that copy.",
376
+ inputSchema: {
377
+ type: "object",
378
+ properties: {
379
+ id: { type: "number", description: "The session_id from get_switchboard_sessions. Omit to export the newest session." },
380
+ },
381
+ },
382
+ annotations: { readOnlyHint: false },
383
+ },
350
384
  {
351
385
  name: "get_app_state",
352
386
  description: "Get the current app state from the device.",
@@ -355,11 +389,11 @@ export const TOOL_DEFINITIONS = [
355
389
  },
356
390
  {
357
391
  name: "get_recent_logs",
358
- description: "Get recent device logs for the Slack debug build. Reads the app's own log buffer first (the DEBUG-and-above Timber lines the in-app Log Viewer shows, this app only), and falls back to an adb logcat snapshot when that buffer cannot be read. The result includes a `source` field (app_buffer / logcat_capture / logcat_ring) so you can tell a real empty result from a fallback. Leave `tag` out to get all recent lines. For native crashes, VERBOSE lines, or non-Slack processes, use adb logcat directly.",
392
+ description: "Get recent device logs for the Slack debug build. Android reads the app's Timber buffer first and falls back to logcat. iOS returns only Slack-authored unified logs captured since the Radar session was enabled; it cannot backfill earlier lines, and if the capture died it returns what it retained with a `capture_error`. The result's `source` is one of `app_buffer`, `logcat_capture`, `logcat_ring`, or `ios_unified_capture`. Leave `tag` out to get all recent lines. On Android, for native crashes, VERBOSE lines, or non-Slack processes, use adb logcat directly.",
359
393
  inputSchema: {
360
394
  type: "object",
361
395
  properties: {
362
- tag: { type: "string", description: "Optional substring to filter log lines by (matched anywhere in the line, not an exact tag-column match). Omit to return all recent lines." },
396
+ tag: { type: "string", description: "Optional substring filter: Android matches anywhere in the line; iOS matches the category/tag field. Use grep to search message text. Omit to return all recent lines." },
363
397
  limit: { type: "number", description: "Max number of lines to return (default: 50, capped at 1000)" },
364
398
  grep: { type: "string", description: "Optional text to grep within the filtered output" },
365
399
  },
@@ -445,7 +479,7 @@ export const TOOL_DEFINITIONS = [
445
479
  },
446
480
  {
447
481
  name: "_radar_session_enable",
448
- description: "Enable Slack Radar for this session. Sets up ADB forwarding, activates the device-side server, and connects the SSE stream. Called by /radar-enable skill.",
482
+ description: "Enable Slack Radar for this session. Sets up ADB forwarding, activates the device-side server, and connects the SSE stream. Called by /radar-enable skill. If the result has a warning field, show it to the user verbatim.",
449
483
  inputSchema: {
450
484
  type: "object",
451
485
  properties: {
@@ -484,12 +518,13 @@ export const TOOL_DEFINITIONS = [
484
518
  source: {
485
519
  type: "string",
486
520
  enum: [...SOURCES],
487
- description: "Which device stream to read. 'all' is a unified timeline mixing network, RTM, clog, trace, log, and switchboard. 'switchboard' is the Slackbot voice transport's own records (kind: session|state|frame|phase|player).",
521
+ description: "Which device stream to read. 'all' is a unified timeline mixing network, RTM, clog, trace, log, and switchboard. 'switchboard' is the Slackbot voice transport's own records (kind: session|state|frame|phase|player|levels|turn|saved_turn).",
488
522
  },
489
523
  match: {
490
524
  type: "object",
491
525
  description: "Case-insensitive substring filter on SUMMARY fields, keyed by source. network: url/method/status_code; " +
492
- "rtm: event_type/direction/channel; clog: event_name; trace: trace_name/span_name; log: tag/level/package; switchboard: kind/session_id/direction/frame_type/state_kind/phase/event. NEVER invent a field " +
526
+ "rtm: event_type/direction/channel; clog: event_name; trace: trace_name/span_name; " +
527
+ "log: tag/level/message/pid/package (iOS also: subsystem/process); switchboard: kind/session_id/direction/frame_type/state_kind/phase/event/clock/outcome. NEVER invent a field " +
493
528
  "(a match on an absent field silently matches nothing). For body text use bodyContains instead; for a log level floor use minLevel, not match.level.",
494
529
  },
495
530
  bodyContains: {
@@ -698,8 +733,11 @@ export const TOOL_DEFINITIONS = [
698
733
  /**
699
734
  * Check whether a tool call should be blocked by the session gate.
700
735
  * Returns an error response object if blocked, or null if allowed.
736
+ *
737
+ * `allowSwitchboardExportOffline` lets export_switchboard_session through while disabled; the
738
+ * caller sets it only when a host-only report can be built without touching the device.
701
739
  */
702
- export function sessionGate(toolName, sessionEnabled) {
740
+ export function sessionGate(toolName, sessionEnabled, allowSwitchboardExportOffline = false) {
703
741
  // Session enable/disable are always allowed
704
742
  if (toolName === "_radar_session_enable" || toolName === "_radar_session_disable") {
705
743
  return null;
@@ -708,11 +746,18 @@ export function sessionGate(toolName, sessionEnabled) {
708
746
  if (toolName === "ping") {
709
747
  return null;
710
748
  }
749
+ // Profile discovery is adb-only and is the recovery path named by a refused enable.
750
+ if (toolName === "list_profiles") {
751
+ return null;
752
+ }
711
753
  // open_radar_dashboard launches an independent local web process with its own
712
754
  // device-enable (Reconnect) button, so it does not require the MCP session enabled.
713
755
  if (toolName === "open_radar_dashboard") {
714
756
  return null;
715
757
  }
758
+ if (toolName === "export_switchboard_session" && allowSwitchboardExportOffline) {
759
+ return null;
760
+ }
716
761
  if (!sessionEnabled) {
717
762
  return {
718
763
  content: [
@@ -1 +1,4 @@
1
- export declare function webChildEnv(initialSpec?: Record<string, unknown>): NodeJS.ProcessEnv;
1
+ export declare function webChildEnv(initialSpec?: Record<string, unknown>, target?: {
2
+ platform: string;
3
+ serial?: string | null;
4
+ }): NodeJS.ProcessEnv;
@@ -6,9 +6,12 @@
6
6
  // transport at import time, so a test importing it would hang rather than exit. Keeping the builder
7
7
  // here makes the boundary assertable without importing a server.
8
8
  import { RADAR_PORT } from "../shared/constants.js";
9
- export function webChildEnv(initialSpec) {
9
+ export function webChildEnv(initialSpec, target) {
10
10
  return {
11
11
  ...process.env,
12
+ ...(target ? { SLACK_RADAR_PLATFORM: target.platform } : {}),
13
+ ...(target?.platform === "ios" && target.serial
14
+ ? { SLACK_RADAR_IOS_SIMULATOR_UDID: target.serial } : {}),
12
15
  // A bridge-spawned dashboard must not pop a window unbidden: the Claude Code session returns the
13
16
  // URL instead, which is what the /radar-ui server instructions promise.
14
17
  SLACK_RADAR_NO_OPEN: "1",
@@ -1,4 +1,8 @@
1
+ import { type ChildProcess } from "child_process";
2
+ import { TokenFileError } from "./radar-token.js";
3
+ import { LogSession, type LogFrame } from "./log-session.js";
1
4
  import type { DeviceInfo, DeviceTransport, LogResult, ProcessState, DevicePick } from "./transport.js";
5
+ export declare function describeBroadcastFailure(error: Error): string;
2
6
  /**
3
7
  * Resolve the adb binary. MCP servers spawned from GUI launchers (Spotlight,
4
8
  * Raycast, Dock) do not inherit the user's shell PATH, so a bare `adb` call
@@ -10,6 +14,27 @@ import type { DeviceInfo, DeviceTransport, LogResult, ProcessState, DevicePick }
10
14
  * surface a clear error instead of a misleading "device not connected".
11
15
  */
12
16
  export declare function resolveAdbPath(): string | null;
17
+ type SpawnAndroidProcessList = () => ChildProcess | null;
18
+ /**
19
+ * A device-scoped PID -> package snapshot for dashboard log rows.
20
+ *
21
+ * Android reuses PIDs, and a dashboard can switch between devices without restarting its
22
+ * process. Replacing the whole snapshot on refresh, rather than appending to a module-global
23
+ * map, prevents a PID on the new process/device from inheriting the old package label.
24
+ */
25
+ export declare class AndroidPidPackageMap {
26
+ private readonly spawnProcessList;
27
+ private packages;
28
+ private refreshVersion;
29
+ private activeRefresh;
30
+ private lastRefresh;
31
+ constructor(spawnProcessList?: SpawnAndroidProcessList);
32
+ resolve(pid: number): string | undefined;
33
+ refresh(): void;
34
+ reset(): void;
35
+ }
36
+ /** Parse one adb logcat threadtime line into the dashboard's normalized log frame. */
37
+ export declare function parseAndroidLogcat(line: string, resolvePackage?: (pid: number) => string | undefined): LogFrame | null;
13
38
  /**
14
39
  * Parse the output of `ps -A -o USER,NAME` to extract the Android user ID
15
40
  * for the debug build process. When multiple profiles are running, prefers
@@ -31,9 +56,20 @@ export declare function parseAdbDevicesOutput(raw: string): {
31
56
  label: string;
32
57
  state: string;
33
58
  }[];
59
+ /** Seams for AndroidTransport's host log capture, shaped like IosSimulatorTransportDependencies. */
60
+ export interface AndroidTransportDependencies {
61
+ /** Start the dashboard's `adb logcat` child. Defaults to the resolved adb binary. */
62
+ spawnLogcat?: () => ChildProcess;
63
+ /** Start the `ps` listing that labels log rows with their package. */
64
+ spawnProcessList?: SpawnAndroidProcessList;
65
+ }
34
66
  export declare class AndroidTransport implements DeviceTransport {
35
67
  readonly platform = "android";
68
+ readonly logPackage = "com.Slack.internal.debug";
69
+ readonly supportsHostLogs = true;
70
+ readonly logSession: LogSession;
36
71
  readonly supportsRadarHttpTools = true;
72
+ readonly sendsRadarToken = true;
37
73
  readonly supportsLocalFileAccess = true;
38
74
  readonly supportsDeviceDashboard = true;
39
75
  private portForwarded;
@@ -42,7 +78,10 @@ export declare class AndroidTransport implements DeviceTransport {
42
78
  private radarEnabled;
43
79
  private lastForwardError;
44
80
  private lastActivateError;
81
+ private lastActivateTokenFileError;
45
82
  private selectedDevice;
83
+ private readonly dashboardPidPackages;
84
+ constructor(dependencies?: AndroidTransportDependencies);
46
85
  ensureForward(): boolean;
47
86
  private rebuildForward;
48
87
  reassertForward(): boolean;
@@ -76,7 +115,9 @@ export declare class AndroidTransport implements DeviceTransport {
76
115
  radarSocketPresentAsync(): Promise<"present" | "absent" | "unknown">;
77
116
  private recordActivateSuccess;
78
117
  private recordActivateFailure;
118
+ private readArmToken;
79
119
  getLastActivateError(): string | null;
120
+ getLastActivateTokenFileError(): TokenFileError | null;
80
121
  resetState(): void;
81
122
  dropForward(): void;
82
123
  isForwarded(): boolean;
@@ -95,6 +136,7 @@ export declare class AndroidTransport implements DeviceTransport {
95
136
  recordScreen(durationS: number): string;
96
137
  getAppState(): string;
97
138
  getRecentLogs(tag: string, limit: number, grep?: string): LogResult;
139
+ stopLogCapture(): void;
98
140
  listProfiles(): {
99
141
  userId: string;
100
142
  label: string;
@@ -165,3 +207,4 @@ export declare class AndroidTransport implements DeviceTransport {
165
207
  */
166
208
  processState(timeoutMs?: number): ProcessState;
167
209
  }
210
+ export {};