@slack/radar-mcp 1.20.0 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +75 -17
  2. package/dist/mcp/api-paths.d.ts +11 -0
  3. package/dist/mcp/api-paths.js +56 -20
  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 +138 -36
  7. package/dist/mcp/logs-result.d.ts +1 -0
  8. package/dist/mcp/logs-result.js +1 -0
  9. package/dist/mcp/network-detail.d.ts +5 -0
  10. package/dist/mcp/network-detail.js +86 -0
  11. package/dist/mcp/radar-export-get.d.ts +30 -0
  12. package/dist/mcp/radar-export-get.js +49 -0
  13. package/dist/mcp/radar-response.d.ts +11 -1
  14. package/dist/mcp/radar-response.js +23 -3
  15. package/dist/mcp/session-backfill.d.ts +9 -3
  16. package/dist/mcp/session-backfill.js +76 -17
  17. package/dist/mcp/session-detail.js +54 -2
  18. package/dist/mcp/session-enable.d.ts +1 -0
  19. package/dist/mcp/session-enable.js +146 -15
  20. package/dist/mcp/session-query.js +53 -11
  21. package/dist/mcp/snapshot.js +42 -26
  22. package/dist/mcp/sources-gate.js +5 -0
  23. package/dist/mcp/stale-dashboard.d.ts +23 -0
  24. package/dist/mcp/stale-dashboard.js +122 -0
  25. package/dist/mcp/switchboard-spool.d.ts +12 -0
  26. package/dist/mcp/switchboard-spool.js +107 -0
  27. package/dist/mcp/switchboard-tools.d.ts +18 -0
  28. package/dist/mcp/switchboard-tools.js +178 -0
  29. package/dist/mcp/tools.d.ts +4 -1
  30. package/dist/mcp/tools.js +114 -23
  31. package/dist/mcp/web-child-env.d.ts +4 -1
  32. package/dist/mcp/web-child-env.js +4 -1
  33. package/dist/shared/android.d.ts +43 -0
  34. package/dist/shared/android.js +227 -19
  35. package/dist/shared/constants.d.ts +19 -4
  36. package/dist/shared/constants.js +19 -4
  37. package/dist/shared/event-spool.js +3 -2
  38. package/dist/shared/feature-flags.d.ts +1 -0
  39. package/dist/shared/feature-flags.js +1 -0
  40. package/dist/shared/form-body.d.ts +18 -0
  41. package/dist/shared/form-body.js +251 -0
  42. package/dist/shared/ios-logs.d.ts +10 -0
  43. package/dist/shared/ios-logs.js +91 -0
  44. package/dist/shared/ios.d.ts +25 -2
  45. package/dist/shared/ios.js +157 -3
  46. package/dist/{web → shared}/log-session.d.ts +45 -31
  47. package/dist/shared/log-session.js +300 -0
  48. package/dist/shared/radar-request-raw.d.ts +7 -0
  49. package/dist/shared/radar-request-raw.js +89 -0
  50. package/dist/shared/radar-token.d.ts +25 -0
  51. package/dist/shared/radar-token.js +164 -0
  52. package/dist/shared/stream.d.ts +4 -1
  53. package/dist/shared/stream.js +107 -15
  54. package/dist/shared/switchboard-host-store.d.ts +21 -0
  55. package/dist/shared/switchboard-host-store.js +166 -0
  56. package/dist/shared/switchboard-note.d.ts +15 -0
  57. package/dist/shared/switchboard-note.js +92 -0
  58. package/dist/shared/switchboard-report-file.d.ts +5 -0
  59. package/dist/shared/switchboard-report-file.js +26 -0
  60. package/dist/shared/switchboard-report.d.ts +20 -0
  61. package/dist/shared/switchboard-report.js +406 -0
  62. package/dist/shared/switchboard.d.ts +118 -0
  63. package/dist/shared/switchboard.js +487 -0
  64. package/dist/shared/transport.d.ts +43 -3
  65. package/dist/shared/version.d.ts +2 -0
  66. package/dist/shared/version.js +18 -0
  67. package/dist/shared/wire.d.ts +46 -1
  68. package/dist/web/install-app.d.ts +57 -8
  69. package/dist/web/install-app.js +270 -60
  70. package/dist/web/macapp/RadarApp.swift +340 -22
  71. package/dist/web/public/index.html +216 -12
  72. package/dist/web/public/next/app.js +43 -22
  73. package/dist/web/public/next/db.js +4 -1
  74. package/dist/web/public/next/feed.js +604 -59
  75. package/dist/web/public/next/filters.js +158 -40
  76. package/dist/web/public/next/flags.js +3 -0
  77. package/dist/web/public/next/form-body.js +252 -0
  78. package/dist/web/public/next/inspector.js +171 -14
  79. package/dist/web/public/next/prefs.js +5 -2
  80. package/dist/web/public/next/registry.js +35 -3
  81. package/dist/web/public/next/store.js +947 -69
  82. package/dist/web/public/next/switchboard-note.js +93 -0
  83. package/dist/web/public/next/toast.js +9 -5
  84. package/dist/web/public/next/voice-model.js +712 -0
  85. package/dist/web/public/next/voice.js +552 -0
  86. package/dist/web/server.d.ts +20 -9
  87. package/dist/web/server.js +834 -174
  88. package/dist/web/spec.d.ts +11 -6
  89. package/dist/web/spec.js +62 -6
  90. package/package.json +4 -4
  91. package/dist/web/log-session.js +0 -166
@@ -5,20 +5,22 @@
5
5
  * and the same validate/coerce pass runs on every push so a malformed spec surfaces
6
6
  * an error instead of rendering silent zeros.
7
7
  *
8
- * Most sources are live STREAMS (network/rtm/clog/trace/log/all). `db` and `prefs` are the
8
+ * Most sources are live STREAMS (network/rtm/clog/trace/log/switchboard/all). `db` and `prefs` are the
9
9
  * odd ones out: read-only, point-in-time BROWSERS (SQLite databases, SharedPreferences files)
10
10
  * with no viz / series / match (each has its own list -> detail view). The coerce and
11
11
  * validate passes short-circuit for both accordingly.
12
12
  */
13
13
  /**
14
- * Sources the dashboard can read. The first six are live streams; "all" is their unified
15
- * timeline. "db", "prefs", and "flags" are read-only point-in-time browsers (not streams) and
16
- * are each handled as a distinct view.
14
+ * Sources the dashboard can read. The first five plus "switchboard" are live streams; "all" is
15
+ * their unified timeline. "db", "prefs", and "flags" are read-only point-in-time browsers (not
16
+ * streams) and are each handled as a distinct view. "switchboard" is the Slackbot voice transport's
17
+ * own event stream (session / state / frame / phase / player / levels / turn / saved_turn records),
18
+ * device-produced like rtm.
17
19
  */
18
- export declare const SOURCES: readonly ["rtm", "network", "clog", "trace", "log", "all", "db", "prefs", "flags"];
20
+ export declare const SOURCES: readonly ["rtm", "network", "clog", "trace", "log", "switchboard", "all", "db", "prefs", "flags"];
19
21
  export type Source = (typeof SOURCES)[number];
20
22
  /** Widgets a spec may compose. */
21
- export declare const VIZ: readonly ["counter", "rate", "sparkline", "feed", "inspector", "graph"];
23
+ export declare const VIZ: readonly ["counter", "rate", "sparkline", "feed", "inspector", "graph", "voice"];
22
24
  export type Viz = (typeof VIZ)[number];
23
25
  /** Metrics a graph series can plot. */
24
26
  export declare const SERIES_METRICS: readonly ["ratePerSec", "count", "avg", "errorRate"];
@@ -26,6 +28,8 @@ export type SeriesMetric = (typeof SERIES_METRICS)[number];
26
28
  declare const HIGHLIGHT_OPS: readonly [">", ">=", "<", "<=", "=="];
27
29
  export declare const LOG_LEVELS: readonly ["VERBOSE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"];
28
30
  export type LogLevel = (typeof LOG_LEVELS)[number];
31
+ export declare const EXCLUDE_MAX_TERMS = 20;
32
+ export declare const EXCLUDE_MAX_TERM_LENGTH = 200;
29
33
  export type HighlightOp = (typeof HIGHLIGHT_OPS)[number];
30
34
  export interface GraphSeries {
31
35
  label?: string;
@@ -64,6 +68,7 @@ export interface Spec {
64
68
  match?: Record<string, string>;
65
69
  bodyContains?: string;
66
70
  minLevel?: LogLevel;
71
+ exclude?: string[];
67
72
  viz?: Viz[];
68
73
  rateWindowSec?: number;
69
74
  series?: GraphSeries[];
package/dist/web/spec.js CHANGED
@@ -5,17 +5,19 @@
5
5
  * and the same validate/coerce pass runs on every push so a malformed spec surfaces
6
6
  * an error instead of rendering silent zeros.
7
7
  *
8
- * Most sources are live STREAMS (network/rtm/clog/trace/log/all). `db` and `prefs` are the
8
+ * Most sources are live STREAMS (network/rtm/clog/trace/log/switchboard/all). `db` and `prefs` are the
9
9
  * odd ones out: read-only, point-in-time BROWSERS (SQLite databases, SharedPreferences files)
10
10
  * with no viz / series / match (each has its own list -> detail view). The coerce and
11
11
  * validate passes short-circuit for both accordingly.
12
12
  */
13
13
  /**
14
- * Sources the dashboard can read. The first six are live streams; "all" is their unified
15
- * timeline. "db", "prefs", and "flags" are read-only point-in-time browsers (not streams) and
16
- * are each handled as a distinct view.
14
+ * Sources the dashboard can read. The first five plus "switchboard" are live streams; "all" is
15
+ * their unified timeline. "db", "prefs", and "flags" are read-only point-in-time browsers (not
16
+ * streams) and are each handled as a distinct view. "switchboard" is the Slackbot voice transport's
17
+ * own event stream (session / state / frame / phase / player / levels / turn / saved_turn records),
18
+ * device-produced like rtm.
17
19
  */
18
- export const SOURCES = ["rtm", "network", "clog", "trace", "log", "all", "db", "prefs", "flags"];
20
+ export const SOURCES = ["rtm", "network", "clog", "trace", "log", "switchboard", "all", "db", "prefs", "flags"];
19
21
  /** Widgets a spec may compose. */
20
22
  export const VIZ = [
21
23
  "counter",
@@ -24,6 +26,8 @@ export const VIZ = [
24
26
  "feed",
25
27
  "inspector",
26
28
  "graph",
29
+ // The Switchboard tab's voice panel (session strip, tracks, stat cards). Only that source draws it.
30
+ "voice",
27
31
  ];
28
32
  /** Metrics a graph series can plot. */
29
33
  export const SERIES_METRICS = [
@@ -36,6 +40,11 @@ const HIGHLIGHT_OPS = [">", ">=", "<", "<=", "=="];
36
40
  // Logcat priorities, lowest first. `minLevel` on a log-carrying spec keeps rows at that priority
37
41
  // or above, and this order is what "or above" means.
38
42
  export const LOG_LEVELS = ["VERBOSE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"];
43
+ // Caps on `exclude`: enough for a preset's noise list, small enough that a runaway agent cannot
44
+ // push a spec that costs a substring scan per term per row. The browser build cannot import this
45
+ // file, so src/web/public/next/registry.ts carries a mirror; the two are pinned equal in a test.
46
+ export const EXCLUDE_MAX_TERMS = 20;
47
+ export const EXCLUDE_MAX_TERM_LENGTH = 200;
39
48
  /** The empty dashboard. Rendered until a spec is pushed. */
40
49
  export const BLANK_SPEC = { title: "", blank: true, viz: [] };
41
50
  function isRecord(v) {
@@ -66,6 +75,21 @@ export function coerceSpec(input) {
66
75
  else
67
76
  s.minLevel = up;
68
77
  }
78
+ // Whitespace is not a term. Trim each, drop the empties, and drop the field once nothing is
79
+ // left, so "no exclusions" has one spelling on the wire (no field), the way VERBOSE does above.
80
+ // Matching is case-insensitive, so "Meter" and "meter" are one term: keep the first spelling.
81
+ // Only well-formed arrays of strings are repaired; anything else is left for the validator.
82
+ if (Array.isArray(s.exclude) && s.exclude.every((t) => typeof t === "string")) {
83
+ const seen = new Set();
84
+ s.exclude = s.exclude.map((t) => t.trim()).filter((t) => {
85
+ if (t.length === 0 || seen.has(t.toLowerCase()))
86
+ return false;
87
+ seen.add(t.toLowerCase());
88
+ return true;
89
+ });
90
+ if (s.exclude.length === 0)
91
+ delete s.exclude;
92
+ }
69
93
  // The DB, Prefs, and feature-flags browsers have no match/viz/series to repair; leave as-is.
70
94
  if (s.source === "db" || s.source === "prefs" || s.source === "flags")
71
95
  return s;
@@ -83,10 +107,21 @@ export function coerceSpec(input) {
83
107
  ? "event_name"
84
108
  : s.source === "trace"
85
109
  ? "trace_name"
86
- : "url";
110
+ : s.source === "switchboard"
111
+ ? "kind"
112
+ : "url";
87
113
  s.match = { [field]: s.match };
88
114
  }
89
115
  }
116
+ // The voice panel only draws for the switchboard source: a voice key riding in on any other
117
+ // source's viz array can never draw anything, so drop it rather than store a spec that looks
118
+ // like it asked for a panel it will never get. Falling back when that was the only key left
119
+ // matches the validator's non-empty-viz rule, rather than storing a spec doomed to fail it.
120
+ if (Array.isArray(s.viz) && s.viz.includes("voice") && s.source !== "switchboard") {
121
+ s.viz = s.viz.filter((v) => v !== "voice");
122
+ if (s.viz.length === 0)
123
+ s.viz = ["feed", "inspector"];
124
+ }
90
125
  // graph series repair: fill if missing/empty, trim to the validator's 1-2 cap,
91
126
  // and drop entries with an unusable metric so the dashboard never hard-rejects.
92
127
  if (Array.isArray(s.viz) && s.viz.includes("graph")) {
@@ -128,6 +163,27 @@ export function validateSpec(s) {
128
163
  return "minLevel applies to the log and all sources only";
129
164
  }
130
165
  }
166
+ // Likewise ahead of the per-source returns: the browsers have no rows with searchable text, so
167
+ // an exclusion there would be stored and never act.
168
+ if (spec.exclude !== undefined) {
169
+ if (!Array.isArray(spec.exclude))
170
+ return "exclude must be an array of strings";
171
+ if (spec.source === "db" || spec.source === "prefs" || spec.source === "flags") {
172
+ return "exclude applies to stream sources only (log, all, network, rtm, clog, trace, switchboard)";
173
+ }
174
+ if (spec.exclude.length > EXCLUDE_MAX_TERMS)
175
+ return `exclude takes at most ${EXCLUDE_MAX_TERMS} terms`;
176
+ for (const t of spec.exclude) {
177
+ if (typeof t !== "string" || t.trim().length === 0)
178
+ return "exclude terms must be non-empty strings";
179
+ if (t.length > EXCLUDE_MAX_TERM_LENGTH)
180
+ return `exclude terms must be at most ${EXCLUDE_MAX_TERM_LENGTH} characters`;
181
+ // The Filters panel splits its input on commas and line breaks, so a term holding one would
182
+ // come back as two on the first edit there; refused here so no entry point can store it.
183
+ if (/[,\n]/.test(t))
184
+ return "exclude terms must not contain a comma or a line break";
185
+ }
186
+ }
131
187
  // The DB browser is a distinct view: no viz/series/match. Only its optional deep-link
132
188
  // fields are constrained (each must be a string when present).
133
189
  if (spec.source === "db") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slack/radar-mcp",
3
- "version": "1.20.0",
3
+ "version": "1.22.0",
4
4
  "description": "MCP server and web dashboard for debugging Slack on Android and iOS Simulator",
5
5
  "type": "module",
6
6
  "main": "dist/mcp/index.js",
@@ -15,15 +15,15 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "clean": "rm -rf dist",
18
- "prebuild": "npm run clean",
18
+ "prebuild": "npm run clean && node scripts/mirror-shared.mjs",
19
19
  "copy-vendor": "node scripts/copy-vendor.mjs",
20
- "build:web": "tsc -p tsconfig.web.json",
20
+ "build:web": "node scripts/mirror-shared.mjs && tsc -p tsconfig.web.json",
21
21
  "build": "tsc && npm run build:web && node scripts/copy-public.mjs && npm run copy-vendor && chmod +x dist/mcp/index.js dist/web/bin.js",
22
22
  "start": "node dist/mcp/index.js",
23
23
  "start:web": "node dist/web/bin.js",
24
24
  "watch": "tsc --watch",
25
25
  "test": "npm run build && node tests/run.mjs",
26
- "test:tap": "npm run build && node --test tests/*.test.mjs",
26
+ "test:tap": "npm run build && node --import ./tests/temp-home.mjs --test tests/*.test.mjs",
27
27
  "test:smoke": "npm run build && bash tests/smoke.sh",
28
28
  "test:all": "npm run test && npm run test:smoke",
29
29
  "prepare": "npm run build"
@@ -1,166 +0,0 @@
1
- import { MAX_LOG_SESSION_BUFFER } from "../shared/constants.js";
2
- /**
3
- * A single session-long logcat capture with a bounded ring buffer and listener
4
- * fan-out. One instance is shared across every dashboard stream connection.
5
- */
6
- export class LogSession {
7
- spawnLogcat;
8
- parseLine;
9
- cap;
10
- child = null;
11
- lineBuf = "";
12
- ring = [];
13
- listeners = new Set();
14
- cleanupRegistered = false;
15
- constructor(spawnLogcat, parseLine, cap = MAX_LOG_SESSION_BUFFER) {
16
- this.spawnLogcat = spawnLogcat;
17
- this.parseLine = parseLine;
18
- this.cap = cap > 0 ? cap : MAX_LOG_SESSION_BUFFER;
19
- }
20
- /** True while a logcat child is running. */
21
- isRunning() {
22
- return this.child !== null;
23
- }
24
- /** Number of frames currently retained (for tests / diagnostics). */
25
- bufferSize() {
26
- return this.ring.length;
27
- }
28
- /** Number of attached stream listeners (for tests / diagnostics). */
29
- listenerCount() {
30
- return this.listeners.size;
31
- }
32
- /**
33
- * Start the capture if it is not already running. Idempotent: a second call
34
- * while a child is alive is a no-op, so concurrent tab opens cannot fan out
35
- * duplicate logcat processes. Returns true if a capture is running after the
36
- * call (already-running counts as success), false if the spawn failed.
37
- */
38
- start() {
39
- if (this.child)
40
- return true;
41
- let child;
42
- try {
43
- child = this.spawnLogcat();
44
- }
45
- catch {
46
- return false;
47
- }
48
- this.child = child;
49
- this.lineBuf = "";
50
- // A background diagnostic child must not keep the host process alive on its
51
- // own. The listening dashboard socket is what holds the event loop open in
52
- // production; when that closes (a test, or a clean shutdown) node should be
53
- // free to exit even if a logcat capture is still running. registerCleanup
54
- // still kills the child on exit, so unref only removes the loop-blocking ref.
55
- child.unref?.();
56
- child.stdout?.on("data", (c) => this.onData(c));
57
- // A crashed/killed logcat (device unplugged, adb server restart) clears the
58
- // child so the next connect() can restart it. The retained ring survives so
59
- // history is not lost across a transient device drop.
60
- child.on("error", () => this.onChildGone(child));
61
- child.on("exit", () => this.onChildGone(child));
62
- return true;
63
- }
64
- /** Stop the capture and drop the child. The ring buffer is preserved. */
65
- stop() {
66
- const child = this.child;
67
- this.child = null;
68
- this.lineBuf = "";
69
- if (child) {
70
- try {
71
- child.kill();
72
- }
73
- catch {
74
- // already dead
75
- }
76
- }
77
- }
78
- /**
79
- * Stop the capture AND drop the retained ring, for when the underlying device
80
- * actually changed (PR #94 multi-device switch), not just dropped transiently.
81
- * stop() alone preserves the ring by design (a transient adb-server hiccup or
82
- * device unplug/replug is the SAME device coming back, so its history is still
83
- * valid and should survive) -- but a switch to DIFFERENT hardware means every
84
- * retained frame belongs to the wrong device, and replaying them into a freshly
85
- * opened /stream on the new device would show device A's logs mislabeled as
86
- * device B's. The caller (handleEnable's switched branch) is responsible for
87
- * calling armLogcat() / start() again afterward if a log tab is active; this
88
- * method only tears down, matching stop()'s existing division of labor.
89
- */
90
- restart() {
91
- this.stop();
92
- this.ring.length = 0;
93
- }
94
- /**
95
- * Install process-exit handlers (once) so the persistent `adb logcat` child is
96
- * killed when the server process exits. Without this, the capture orphans when
97
- * the server is terminated by signal — notably when `open_radar_dashboard`
98
- * spawns the dashboard as a child and later kills it by PID — and orphaned adb
99
- * logcat readers accumulate across dashboard open/close cycles, holding the
100
- * device's logcat stream. Mirrors logcat-capture.ts's registerCleanup().
101
- */
102
- registerCleanup() {
103
- if (this.cleanupRegistered)
104
- return;
105
- this.cleanupRegistered = true;
106
- process.on("exit", () => this.stop());
107
- process.on("SIGINT", () => {
108
- this.stop();
109
- process.exit(130);
110
- });
111
- process.on("SIGTERM", () => {
112
- this.stop();
113
- process.exit(143);
114
- });
115
- }
116
- /**
117
- * Subscribe a stream to the session. The listener is FIRST replayed the entire
118
- * retained ring (replay=true) so a freshly opened tab shows full history, then
119
- * receives every subsequent live frame (replay=false). Returns an unsubscribe
120
- * function; call it when the stream closes (this does NOT stop the capture).
121
- */
122
- subscribe(listener) {
123
- // Replay a snapshot of the current ring. Snapshot first so a frame arriving
124
- // mid-replay is not delivered twice (once via replay, once live).
125
- const snapshot = this.ring.slice();
126
- for (const frame of snapshot)
127
- listener(frame, true);
128
- this.listeners.add(listener);
129
- return () => {
130
- this.listeners.delete(listener);
131
- };
132
- }
133
- onChildGone(child) {
134
- // Guard against a late event from an already-replaced child.
135
- if (this.child === child) {
136
- this.child = null;
137
- this.lineBuf = "";
138
- }
139
- }
140
- onData(chunk) {
141
- this.lineBuf += chunk.toString();
142
- let nl;
143
- while ((nl = this.lineBuf.indexOf("\n")) >= 0) {
144
- const line = this.lineBuf.slice(0, nl);
145
- this.lineBuf = this.lineBuf.slice(nl + 1);
146
- const frame = this.parseLine(line);
147
- if (frame)
148
- this.push(frame);
149
- }
150
- }
151
- push(frame) {
152
- this.ring.push(frame);
153
- if (this.ring.length > this.cap)
154
- this.ring.shift();
155
- for (const listener of this.listeners) {
156
- // A throwing listener (e.g. a closed response) must not kill the capture
157
- // or starve the other listeners.
158
- try {
159
- listener(frame, false);
160
- }
161
- catch {
162
- // best-effort fan-out
163
- }
164
- }
165
- }
166
- }