@slack/radar-mcp 1.24.0 → 1.26.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 (51) hide show
  1. package/README.md +41 -4
  2. package/dist/mcp/dispatch.d.ts +1 -0
  3. package/dist/mcp/dispatch.js +4 -2
  4. package/dist/mcp/flags-tools.d.ts +1 -0
  5. package/dist/mcp/flags-tools.js +3 -9
  6. package/dist/mcp/index.js +16 -40
  7. package/dist/mcp/json-rows.d.ts +6 -0
  8. package/dist/mcp/json-rows.js +10 -0
  9. package/dist/mcp/radar-response.d.ts +2 -2
  10. package/dist/mcp/radar-response.js +2 -2
  11. package/dist/mcp/redact.d.ts +14 -0
  12. package/dist/mcp/redact.js +71 -0
  13. package/dist/mcp/session-enable.d.ts +1 -0
  14. package/dist/mcp/session-enable.js +8 -6
  15. package/dist/mcp/snapshot-cli.d.ts +52 -0
  16. package/dist/mcp/snapshot-cli.js +316 -0
  17. package/dist/mcp/snapshot-summary.d.ts +1 -0
  18. package/dist/mcp/snapshot-summary.js +254 -0
  19. package/dist/mcp/snapshot.d.ts +32 -3
  20. package/dist/mcp/snapshot.js +347 -102
  21. package/dist/mcp/tools.js +11 -7
  22. package/dist/shared/android.d.ts +25 -0
  23. package/dist/shared/android.js +97 -0
  24. package/dist/shared/feature-flags.d.ts +20 -0
  25. package/dist/shared/feature-flags.js +35 -4
  26. package/dist/shared/radar-token.d.ts +5 -5
  27. package/dist/shared/radar-token.js +24 -10
  28. package/dist/shared/switchboard-note.d.ts +19 -0
  29. package/dist/shared/switchboard-note.js +76 -0
  30. package/dist/shared/switchboard-report.js +43 -4
  31. package/dist/shared/switchboard.d.ts +1 -1
  32. package/dist/shared/switchboard.js +14 -2
  33. package/dist/shared/transport.d.ts +18 -0
  34. package/dist/shared/wire.d.ts +2 -0
  35. package/dist/web/install-app-cli.d.ts +2 -0
  36. package/dist/web/install-app-cli.js +60 -0
  37. package/dist/web/install-app.d.ts +16 -7
  38. package/dist/web/install-app.js +92 -39
  39. package/dist/web/macapp/RadarApp.swift +12 -11
  40. package/dist/web/public/index.html +5 -2
  41. package/dist/web/public/next/feature-flags.js +50 -0
  42. package/dist/web/public/next/feed.js +15 -4
  43. package/dist/web/public/next/flags.js +17 -3
  44. package/dist/web/public/next/registry.js +4 -4
  45. package/dist/web/public/next/store.js +90 -4
  46. package/dist/web/public/next/switchboard-note.js +76 -0
  47. package/dist/web/public/next/voice-model.js +209 -15
  48. package/dist/web/public/next/voice.js +73 -10
  49. package/dist/web/spec.d.ts +1 -1
  50. package/dist/web/spec.js +1 -1
  51. package/package.json +1 -1
package/dist/mcp/tools.js CHANGED
@@ -88,7 +88,7 @@ export function serverInstructions(platform) {
88
88
  ].join("\n");
89
89
  }
90
90
  // Shared by the three flag tools so their wording cannot drift apart.
91
- const SESSION_VALUE_NOTE = "Rows carry session_enabled (the flag's own value fixed for this session) and restart_note when it differs from `enabled`; a row where session_enabled or enabled is absent or not a boolean is not known, never a match; only when both are booleans does a missing restart_note mean they match.";
91
+ const SESSION_VALUE_NOTE = "Rows 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) and restart_note when it differs from `enabled`; a toggle row where session_enabled or enabled is absent or not a boolean is not known, never a match; only when both are booleans does a missing restart_note mean they match. Experiment rows carry session_group_name (the group the first read this session returned, or a read returns now for one not yet read; \"\" is no group; read-once code may still use it until restart, for a signed-in team until it signs out) and restart_note when it differs from group_name; absent or not a string means not known, and only when both are strings does a missing restart_note mean they match; code that reads every time already runs group_name.";
92
92
  export const TOOL_DEFINITIONS = [
93
93
  {
94
94
  name: "ping",
@@ -233,20 +233,20 @@ export const TOOL_DEFINITIONS = [
233
233
  },
234
234
  {
235
235
  name: "get_switchboard_sessions",
236
- 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. saved_turn_counts counts each outcome, and 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. 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.",
236
+ 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/user_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. saved_turn_counts counts each outcome, and 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. 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.",
237
237
  inputSchema: { type: "object", properties: {} },
238
238
  annotations: { readOnlyHint: true },
239
239
  },
240
240
  {
241
241
  name: "get_switchboard_session",
242
- 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. For saved_turn, no_line means no subtitle line still held the item and the turn is still kept; 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). Pass kind to narrow (player for stutter, state for mic and connection, phase for slow start, 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.",
242
+ 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, speaking and user_speaking transitions (state_kind, from, to, cause) with Server:<code> and SwipedAway causes; 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, hold_refuse, reply_hold, reply_unhold, read_stall, pre_ready_drop with gap_ms, bytes_queued, dropped_chunks; phase = startup phase durations (phase, duration_ms); session = begin, end, ready (server_session_id), config (mic_encoding); 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; reconnect_try = trigger (restart, drop, settings), try, outcome (ready, retry, refused, gave_up, where try counts tries made and 0 means the budget was already spent); a Reconnecting state's cause is its trigger; card = card_kind (tool_approval, auth_prompt), event (shown, answered, refused, declined, closed, replaced, expired, cleared, carried), by (tap, server), card_id; a card shown or carried with no later record was still up at the session's last record. Summary server_session_ids lists ready ids. For saved_turn, no_line means no subtitle line still held the item and the turn is still kept; 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). Pass kind to narrow (player for stutter, state for mic and connection, phase for slow start, levels for meter history); the limit applies after the kind filter; total_captured counts every kind. For the whole session use export_switchboard_session or query_session under source switchboard.",
243
243
  inputSchema: {
244
244
  type: "object",
245
245
  properties: {
246
246
  id: { type: "number", description: "The session_id from get_switchboard_sessions" },
247
247
  kind: {
248
248
  type: "string",
249
- enum: ["session", "state", "frame", "phase", "player", "levels", "turn", "saved_turn"],
249
+ enum: ["session", "state", "frame", "phase", "player", "levels", "turn", "saved_turn", "card", "reconnect_try"],
250
250
  description: "Only records of this kind (default: every kind)",
251
251
  },
252
252
  limit: {
@@ -317,7 +317,7 @@ export const TOOL_DEFINITIONS = [
317
317
  },
318
318
  {
319
319
  name: "capture_snapshot",
320
- description: "Bundle the current Radar state into a single on-disk artifact for sharing. Writes four files to ~/.slack-radar/snapshots/snapshot-<ts>/: bundle.json (network + RTM + clog + trace buffers, up to 1000 items each — a bulk export, much larger than point queries like get_network_call_detail), logcat.tail.log (last N lines of the active capture), screenshot.png (current screen), and README.txt (receiver-facing explainer). Switchboard voice sessions are not bundled; keep them with get_switchboard_session or query_session(source=switchboard). Use when the user says 'save this', 'file this as a bug', 'share this', 'bundle this up', 'attach to a ticket', 'make me a repro', or otherwise wants a shareable reproducible handoff. PRIVACY: bundle.json contains raw API request/response bodies including auth headers, RTM message content, user/team/channel IDs, clog payloads, and performance trace spans — review before sharing externally. " +
320
+ description: "Bundle the current Radar state into a single on-disk artifact for sharing. Writes to ~/.slack-radar/snapshots/snapshot-<ts>/: summary.md (read this first: failed calls, log errors, clogs, flags), bundle.json (network + RTM + clog + trace buffers, up to 1000 items each, plus feature flags, voice-session summaries, details of failed network calls, and device and app facts), logcat.tail.log (last N log lines), screenshot.png (current screen), and README.txt (receiver-facing explainer). Use when the user says 'save this', 'file this as a bug', 'share this', 'bundle this up', 'attach to a ticket', 'make me a repro', or otherwise wants a shareable reproducible handoff. PRIVACY: auth headers, cookies and token-shaped strings are blanked by pattern by default, best effort, so still review before sharing externally; redact=false keeps them raw. " +
321
321
  "When it returns, tell the user: result.zip_path (the single shareable file), else result.path; a one-line summary of the counts; \"Privacy: \" followed by result.privacy_notice word for word, verbatim and never paraphrased, even under time pressure; if result.log_lines_truncated is true, that the 1 MB read cap cut the log lines; if result.errors is non-empty, which parts failed. If they asked to file it as a bug or attach it to a ticket, offer to attach result.zip_path through the Jira or Slack MCP; do not attach without asking.",
322
322
  inputSchema: {
323
323
  type: "object",
@@ -336,6 +336,10 @@ export const TOOL_DEFINITIONS = [
336
336
  minimum: 1,
337
337
  maximum: 10000,
338
338
  },
339
+ redact: {
340
+ type: "boolean",
341
+ description: "Blank auth headers, cookies and token-shaped strings (default: true). false keeps raw headers and tokens; only for a bundle that stays on this machine.",
342
+ },
339
343
  },
340
344
  },
341
345
  annotations: { readOnlyHint: false },
@@ -415,13 +419,13 @@ export const TOOL_DEFINITIONS = [
415
419
  source: {
416
420
  type: "string",
417
421
  enum: [...SOURCES],
418
- 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).",
422
+ 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|card|reconnect_try).",
419
423
  },
420
424
  match: {
421
425
  type: "object",
422
426
  description: "Case-insensitive substring filter on SUMMARY fields, keyed by source. network: url/method/status_code; " +
423
427
  "rtm: event_type/direction/channel; clog: event_name; trace: trace_name/span_name; " +
424
- "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 " +
428
+ "log: tag/level/message/pid/package (iOS also: subsystem/process); switchboard: kind/session_id/direction/frame_type/state_kind/phase/event/clock/outcome/trigger/card_kind/card_id. NEVER invent a field " +
425
429
  "(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.",
426
430
  },
427
431
  bodyContains: {
@@ -118,6 +118,26 @@ export interface AndroidTransportDependencies {
118
118
  /** Start the `ps` listing that labels log rows with their package. */
119
119
  spawnProcessList?: SpawnAndroidProcessList;
120
120
  }
121
+ /** First `versionName` / `versionCode` in a `dumpsys package` dump (one block per user repeats them). */
122
+ export declare function parsePackageVersion(dump: string): {
123
+ version_name: string | null;
124
+ version_code: string | null;
125
+ };
126
+ /**
127
+ * The foreground component from a `dumpsys activity activities` dump. Newer builds print
128
+ * `topResumedActivity`, older ones `mResumedActivity`; the new form wins when both show.
129
+ */
130
+ export declare function parseResumedActivity(dump: string): string | null;
131
+ /** `adb shell date +%s` output as epoch ms, or null when it is not whole seconds. */
132
+ export declare function parseDeviceClockMs(out: string): number | null;
133
+ /**
134
+ * Reads the device and app facts through `run`, which takes adb argv and returns stdout or
135
+ * throws. Split out so a test can feed canned output without a device.
136
+ */
137
+ export declare function readDeviceFacts(run: (args: string[]) => string, pkg: string, serial: string | null): {
138
+ device: Record<string, string | boolean | null>;
139
+ app: Record<string, string | null>;
140
+ };
121
141
  export declare class AndroidTransport implements DeviceTransport {
122
142
  readonly platform = "android";
123
143
  get logPackage(): string;
@@ -202,6 +222,11 @@ export declare class AndroidTransport implements DeviceTransport {
202
222
  recordScreen(durationS: number): string;
203
223
  getAppState(): string;
204
224
  getRecentLogs(tag: string, limit: number, grep?: string): LogResult;
225
+ getDeviceFacts(): {
226
+ device: Record<string, string | boolean | null>;
227
+ app: Record<string, string | null>;
228
+ };
229
+ deviceClockMs(): number | null;
205
230
  stopLogCapture(): void;
206
231
  listProfiles(): {
207
232
  userId: string;
@@ -470,6 +470,75 @@ function spawnAndroidLogcat() {
470
470
  stdio: ["ignore", "pipe", "ignore"],
471
471
  });
472
472
  }
473
+ /** First `versionName` / `versionCode` in a `dumpsys package` dump (one block per user repeats them). */
474
+ export function parsePackageVersion(dump) {
475
+ const name = /versionName=(\S+)/.exec(dump)?.[1] ?? null;
476
+ const code = /versionCode=(\d+)/.exec(dump)?.[1] ?? null;
477
+ return { version_name: name, version_code: code };
478
+ }
479
+ /**
480
+ * The foreground component from a `dumpsys activity activities` dump. Newer builds print
481
+ * `topResumedActivity`, older ones `mResumedActivity`; the new form wins when both show.
482
+ */
483
+ export function parseResumedActivity(dump) {
484
+ for (const key of ["topResumedActivity", "mResumedActivity"]) {
485
+ const line = dump.split("\n").find((l) => l.includes(key));
486
+ const m = line ? /([A-Za-z0-9_.$]+\/[A-Za-z0-9_.$]+)/.exec(line) : null;
487
+ if (m)
488
+ return m[1];
489
+ }
490
+ return null;
491
+ }
492
+ /** `adb shell date +%s` output as epoch ms, or null when it is not whole seconds. */
493
+ export function parseDeviceClockMs(out) {
494
+ const t = out.trim();
495
+ return /^\d{1,12}$/.test(t) ? Number(t) * 1000 : null;
496
+ }
497
+ /**
498
+ * Reads the device and app facts through `run`, which takes adb argv and returns stdout or
499
+ * throws. Split out so a test can feed canned output without a device.
500
+ */
501
+ export function readDeviceFacts(run, pkg, serial) {
502
+ const attempt = (fn) => {
503
+ try {
504
+ return fn();
505
+ }
506
+ catch {
507
+ return null;
508
+ }
509
+ };
510
+ // One shell round trip for the six props; getprop prints an empty line for an unset one, so
511
+ // the lines stay in step with the names.
512
+ const propNames = ["ro.product.model", "ro.product.manufacturer", "ro.build.version.release", "ro.build.version.sdk", "ro.kernel.qemu", "ro.boot.qemu"];
513
+ const propOut = attempt(() => run(["shell", `for p in ${propNames.join(" ")}; do getprop $p; done`]));
514
+ const props = propOut === null ? [] : propOut.split("\n");
515
+ const prop = (name) => props[propNames.indexOf(name)]?.trim() || null;
516
+ // Older images set ro.kernel.qemu, newer ones only ro.boot.qemu.
517
+ const isEmulator = propOut === null ? null : prop("ro.kernel.qemu") === "1" || prop("ro.boot.qemu") === "1";
518
+ // `adb shell` re-parses its args on the device, so a package name with shell characters
519
+ // is never sent; it only ever comes from config, and a dot-separated name is all it needs.
520
+ // Both dumps are large, so grep keeps only the lines the parsers read on the device side.
521
+ const pkgDump = /^[A-Za-z0-9_.]+$/.test(pkg)
522
+ ? attempt(() => run(["shell", `dumpsys package ${pkg} | grep -E 'versionName|versionCode'`]))
523
+ : null;
524
+ const actDump = attempt(() => run(["shell", "dumpsys activity activities | grep -E 'topResumedActivity|mResumedActivity'"]));
525
+ const version = pkgDump ? parsePackageVersion(pkgDump) : { version_name: null, version_code: null };
526
+ return {
527
+ device: {
528
+ model: prop("ro.product.model"),
529
+ manufacturer: prop("ro.product.manufacturer"),
530
+ android_release: prop("ro.build.version.release"),
531
+ sdk: prop("ro.build.version.sdk"),
532
+ emulator: isEmulator,
533
+ serial,
534
+ },
535
+ app: {
536
+ package: pkg,
537
+ ...version,
538
+ resumed_activity: actDump ? parseResumedActivity(actDump) : null,
539
+ },
540
+ };
541
+ }
473
542
  export class AndroidTransport {
474
543
  platform = "android";
475
544
  get logPackage() { return slackDebugPackage(); }
@@ -951,6 +1020,34 @@ export class AndroidTransport {
951
1020
  source: "logcat_ring",
952
1021
  };
953
1022
  }
1023
+ getDeviceFacts() {
1024
+ const run = (args) => {
1025
+ if (!ADB)
1026
+ throw new Error("adb not found");
1027
+ return execFileSync(ADB, args, {
1028
+ timeout: 5000,
1029
+ encoding: "utf-8",
1030
+ maxBuffer: 32 * 1024 * 1024,
1031
+ stdio: ["ignore", "pipe", "ignore"],
1032
+ });
1033
+ };
1034
+ return readDeviceFacts(run, slackDebugPackage(), this.getSelectedDevice()?.serial ?? null);
1035
+ }
1036
+ deviceClockMs() {
1037
+ if (!ADB)
1038
+ return null;
1039
+ try {
1040
+ const out = execFileSync(ADB, ["shell", "date", "+%s"], {
1041
+ timeout: 5000,
1042
+ encoding: "utf-8",
1043
+ stdio: ["ignore", "pipe", "ignore"],
1044
+ });
1045
+ return parseDeviceClockMs(out);
1046
+ }
1047
+ catch {
1048
+ return null;
1049
+ }
1050
+ }
954
1051
  stopLogCapture() {
955
1052
  stopCapture();
956
1053
  this.logSession.stop();
@@ -5,3 +5,23 @@
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 sentence (`note`) and the short tab text (`label`) for a flag whose latest value differs from
10
+ * what the app runs. An experiment's label names the group itself, since a group has no ON/OFF to
11
+ * flip. A flag the app read once keeps that value until restart, so the latest value (`enabled` on a toggle,
12
+ * `group_name` on an experiment; fetched or override) can differ from the session value
13
+ * (`session_enabled`, `session_group_name`). Only two real values of
14
+ * the right type that differ earn a note: an absent or mistyped session value is "not known", and
15
+ * saying nothing there is the honest answer. An experiment's "" is a read that found no group, and
16
+ * its note is hedged because read-once code may still use the session group, not that it must.
17
+ */
18
+ export declare function flagRestartNote(row: {
19
+ enabled?: unknown;
20
+ session_enabled?: unknown;
21
+ group_name?: unknown;
22
+ session_group_name?: unknown;
23
+ is_overridden?: unknown;
24
+ }): {
25
+ note: string;
26
+ label: string;
27
+ } | undefined;
@@ -1,7 +1,8 @@
1
- // Shared feature-flag response handling for the two callers that read the device's
2
- // /api/feature_flags route: the MCP tools (flags-tools.ts) and the web dashboard's Flags tab
3
- // (web/server.ts). Both need the same "Not Found" rewrite for builds that predate the
4
- // feature-flag Radar plugin, so it lives here once instead of drifting between two copies.
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,33 @@ export function friendlyFeatureFlagError(error) {
16
17
  }
17
18
  return error;
18
19
  }
20
+ /**
21
+ * The sentence (`note`) and the short tab text (`label`) for a flag whose latest value differs from
22
+ * what the app runs. An experiment's label names the group itself, since a group has no ON/OFF to
23
+ * flip. A flag the app read once keeps that value until restart, so the latest value (`enabled` on a toggle,
24
+ * `group_name` on an experiment; fetched or override) can differ from the session value
25
+ * (`session_enabled`, `session_group_name`). Only two real values of
26
+ * the right type that differ earn a note: an absent or mistyped session value is "not known", and
27
+ * saying nothing there is the honest answer. An experiment's "" is a read that found no group, and
28
+ * its note is hedged because read-once code may still use the session group, not that it must.
29
+ */
30
+ export function flagRestartNote(row) {
31
+ const source = row.is_overridden === true ? "override" : "fetched";
32
+ const { group_name: group, session_group_name: sessionGroup } = row;
33
+ if (typeof group === "string" && typeof sessionGroup === "string") {
34
+ if (group === sessionGroup)
35
+ return undefined;
36
+ const used = sessionGroup || "no group";
37
+ return {
38
+ note: `read-once code may still use ${used} until restart, ${source} ${group || "no group"}`,
39
+ label: `read-once may use ${used}`,
40
+ };
41
+ }
42
+ const { enabled, session_enabled: session } = row;
43
+ if (typeof enabled !== "boolean" || typeof session !== "boolean" || enabled === session)
44
+ return undefined;
45
+ return {
46
+ note: `app uses ${session} until restart, ${source} ${enabled}`,
47
+ label: `runs ${session ? "ON" : "OFF"} until restart`,
48
+ };
49
+ }
@@ -1,6 +1,6 @@
1
1
  import type { DeviceTransport } from "./transport.js";
2
2
  export declare const RADAR_TOKEN_HEADER = "X-Radar-Token";
3
- export type TokenSurface = "mcp" | "dashboard";
3
+ export type TokenSurface = "mcp" | "dashboard" | "cli";
4
4
  export type TokenFileSurface = TokenSurface | "profile";
5
5
  export declare class TokenFileError extends Error {
6
6
  readonly problem: string;
@@ -12,14 +12,14 @@ export declare function getOrCreateRadarToken(): string;
12
12
  export declare function clearRadarTokenCache(): void;
13
13
  export declare function radarTokenHeader(): Record<string, string>;
14
14
  export type RadarTokenSender = Pick<DeviceTransport, "sendsRadarToken"> | null | undefined;
15
- export declare const TOKEN_MISMATCH_MESSAGE = "The device holds a different token than this session's. Check these, then run /radar-enable here. Another machine or OS user enabled Radar on this device: stop that session. Radar was enabled in a different profile: make sure the Slack debug build runs in the profile you want (list_profiles shows which profiles have it). Another Radar session on this machine still uses a token file you deleted: run /radar-enable there too.";
15
+ export declare const TOKEN_MISMATCH_MESSAGE: string;
16
16
  export declare const TOKEN_MISMATCH_DASHBOARD_MESSAGE = "This device answered to a different Radar token. Stop any other Radar session using it, or run /radar-enable there if you deleted the token file, then press Reconnect.";
17
17
  export declare const DEVICE_401_MESSAGE = "The device refused the request (HTTP 401). Run /radar-enable to try again.";
18
18
  export declare const DEVICE_401_DASHBOARD_MESSAGE = "The device refused the request (HTTP 401). Press Reconnect to try again.";
19
19
  export declare function lastHeaderBuildFailure(): TokenFileError | null;
20
20
  export declare function unauthorizedMessageFor(sender: RadarTokenSender, surface?: TokenSurface): string;
21
21
  export declare function radarTokenHeaderFor(transport: RadarTokenSender, surface?: TokenSurface): Record<string, string>;
22
- export declare const OPEN_MODE_WARNING = "The device is in open mode, so anything that reaches the forwarded port can read and change its Radar data. An older Radar MCP or dashboard, or a manual enable broadcast, turned the token check off. If an older Radar MCP or dashboard is still running, stop it, then run /radar-enable.";
22
+ export declare const OPEN_MODE_WARNING: string;
23
23
  export declare const OPEN_MODE_PROFILE_WARNING = "The device is in open mode even though this enable sent the token, so the broadcast did not reach the server that answered: it likely runs in a different profile and was enabled without a token. Anything that reaches the forwarded port can read and change its Radar data. Run list_profiles, then activate_for_user for the profile you want, or stop the older Radar MCP or dashboard that enabled it.";
24
- export declare function openModeWarning(tokenRequired: unknown): string | undefined;
25
- export declare function openModeWarningAfterEnable(tokenRequired: unknown, activateError: string | null): string | undefined;
24
+ export declare function openModeWarning(tokenRequired: unknown, surface?: TokenSurface): string | undefined;
25
+ export declare function openModeWarningAfterEnable(tokenRequired: unknown, activateError: string | null, surface?: TokenSurface): string | undefined;
@@ -24,9 +24,17 @@ export class TokenFileError extends Error {
24
24
  }
25
25
  }
26
26
  export function tokenFileMessage(error, surface = "mcp") {
27
- const act = surface === "dashboard" ? "press Reconnect" : surface === "profile" ? "run activate_for_user again" : "run /radar-enable";
27
+ const act = surface === "dashboard"
28
+ ? "press Reconnect"
29
+ : surface === "profile"
30
+ ? "run activate_for_user again"
31
+ : `run ${enableCommand(surface)}`;
28
32
  return `${error.problem}. ${error.fix}, then ${act}.`;
29
33
  }
34
+ /** What the user types to arm Radar again on a surface. */
35
+ function enableCommand(surface) {
36
+ return surface === "cli" ? "radar-mcp snapshot" : "/radar-enable";
37
+ }
30
38
  let cachedToken = null;
31
39
  function code(error) {
32
40
  return error?.code;
@@ -108,11 +116,12 @@ export function radarTokenHeader() {
108
116
  return { [RADAR_TOKEN_HEADER]: getOrCreateRadarToken() };
109
117
  }
110
118
  const PROFILE_FIX = "make sure the Slack debug build runs in the profile you want (list_profiles shows which profiles have it)";
111
- const MISMATCH_TAIL = `Check these, then run /radar-enable here. Another machine or OS user enabled Radar on this device: stop that session. Radar was enabled in a different profile: ${PROFILE_FIX}. Another Radar session on this machine still uses a token file you deleted: run /radar-enable there too.`;
119
+ const mismatchTail = (cmd) => `Check these, then run ${cmd} here. Another machine or OS user enabled Radar on this device: stop that session. Radar was enabled in a different profile: ${PROFILE_FIX}. Another Radar session on this machine still uses a token file you deleted: run ${cmd} there too.`;
112
120
  const DASHBOARD_TAIL = "Stop any other Radar session using it, or run /radar-enable there if you deleted the token file, then press Reconnect.";
113
- export const TOKEN_MISMATCH_MESSAGE = `The device holds a different token than this session's. ${MISMATCH_TAIL}`;
121
+ export const TOKEN_MISMATCH_MESSAGE = `The device holds a different token than this session's. ${mismatchTail("/radar-enable")}`;
114
122
  export const TOKEN_MISMATCH_DASHBOARD_MESSAGE = `This device answered to a different Radar token. ${DASHBOARD_TAIL}`;
115
123
  export const DEVICE_401_MESSAGE = "The device refused the request (HTTP 401). Run /radar-enable to try again.";
124
+ const DEVICE_401_CLI_MESSAGE = "The device refused the request (HTTP 401). Run radar-mcp snapshot to try again.";
116
125
  export const DEVICE_401_DASHBOARD_MESSAGE = "The device refused the request (HTTP 401). Press Reconnect to try again.";
117
126
  export function lastHeaderBuildFailure() {
118
127
  return lastHeaderFailure;
@@ -121,9 +130,13 @@ export function unauthorizedMessageFor(sender, surface = "mcp") {
121
130
  if (sender?.sendsRadarToken) {
122
131
  if (lastHeaderFailure)
123
132
  return tokenFileMessage(lastHeaderFailure, surface);
124
- return surface === "dashboard" ? TOKEN_MISMATCH_DASHBOARD_MESSAGE : TOKEN_MISMATCH_MESSAGE;
133
+ if (surface === "dashboard")
134
+ return TOKEN_MISMATCH_DASHBOARD_MESSAGE;
135
+ return surface === "cli"
136
+ ? `The device holds a different token than this session's. ${mismatchTail(enableCommand(surface))}`
137
+ : TOKEN_MISMATCH_MESSAGE;
125
138
  }
126
- return surface === "dashboard" ? DEVICE_401_DASHBOARD_MESSAGE : DEVICE_401_MESSAGE;
139
+ return surface === "dashboard" ? DEVICE_401_DASHBOARD_MESSAGE : surface === "cli" ? DEVICE_401_CLI_MESSAGE : DEVICE_401_MESSAGE;
127
140
  }
128
141
  // Never throws: an empty header lets the request go out so an open-mode device can answer.
129
142
  export function radarTokenHeaderFor(transport, surface = "mcp") {
@@ -150,15 +163,16 @@ export function radarTokenHeaderFor(transport, surface = "mcp") {
150
163
  return {};
151
164
  }
152
165
  }
153
- export const OPEN_MODE_WARNING = "The device is in open mode, so anything that reaches the forwarded port can read and change its Radar data. An older Radar MCP or dashboard, or a manual enable broadcast, turned the token check off. If an older Radar MCP or dashboard is still running, stop it, then run /radar-enable.";
166
+ const openModeText = (cmd) => `The device is in open mode, so anything that reaches the forwarded port can read and change its Radar data. An older Radar MCP or dashboard, or a manual enable broadcast, turned the token check off. If an older Radar MCP or dashboard is still running, stop it, then run ${cmd}.`;
167
+ export const OPEN_MODE_WARNING = openModeText("/radar-enable");
154
168
  export const OPEN_MODE_PROFILE_WARNING = "The device is in open mode even though this enable sent the token, so the broadcast did not reach the server that answered: it likely runs in a different profile and was enabled without a token. Anything that reaches the forwarded port can read and change its Radar data. Run list_profiles, then activate_for_user for the profile you want, or stop the older Radar MCP or dashboard that enabled it.";
155
- export function openModeWarning(tokenRequired) {
156
- return tokenRequired === false ? OPEN_MODE_WARNING : undefined;
169
+ export function openModeWarning(tokenRequired, surface = "mcp") {
170
+ return tokenRequired === false ? openModeText(enableCommand(surface)) : undefined;
157
171
  }
158
- export function openModeWarningAfterEnable(tokenRequired, activateError) {
172
+ export function openModeWarningAfterEnable(tokenRequired, activateError, surface = "mcp") {
159
173
  if (tokenRequired !== false)
160
174
  return undefined;
161
175
  return activateError
162
- ? `The device is in open mode: this enable's broadcast failed (${activateError}) and a server enabled without a token answered instead. Anything that reaches the forwarded port can read and change its Radar data. Check the device connection, then run /radar-enable.`
176
+ ? `The device is in open mode: this enable's broadcast failed (${activateError}) and a server enabled without a token answered instead. Anything that reaches the forwarded port can read and change its Radar data. Check the device connection, then run ${enableCommand(surface)}.`
163
177
  : OPEN_MODE_PROFILE_WARNING;
164
178
  }
@@ -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
+ }