@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,166 @@
1
+ // The host's bounded copy of every switchboard record it streamed live, so an export can still
2
+ // reach a call's true start after the small device ring evicts it.
3
+ //
4
+ // Sizes are each record's JSON length, not heap/RSS, so real memory runs higher than the caps.
5
+ // Cleared on an explicit disable, a device switch, a deliberate clear, and process exit, never on
6
+ // a transient device blip.
7
+ import { SWITCHBOARD_EXPORT_SAFETY_CAP_BYTES } from "./switchboard.js";
8
+ // Well above the device ring (up to 10000), so the host copy outlives a device-side eviction.
9
+ export const SWITCHBOARD_HOST_STORE_MAX_RECORDS = 50000;
10
+ // Session ids restart with the app process, so without a cap stale entries would pile up.
11
+ export const SWITCHBOARD_HOST_STORE_MAX_SESSIONS = 8;
12
+ // The per-session byte cap alone still allows MAX_SESSIONS * SAFETY_CAP_BYTES resident; this is
13
+ // the real ceiling, enforced by evicting whole sessions.
14
+ export const SWITCHBOARD_HOST_STORE_MAX_TOTAL_BYTES = 64 * 1024 * 1024;
15
+ let nextSeq = 0;
16
+ // Evicted in Map insertion order. A reset session is deleted and re-inserted, moving it to the
17
+ // back, which is right since it is starting a new call.
18
+ const sessions = new Map();
19
+ let totalBytes = 0;
20
+ function evictOldestSession() {
21
+ const oldestSessionId = sessions.keys().next().value;
22
+ if (oldestSessionId === undefined)
23
+ return;
24
+ const oldest = sessions.get(oldestSessionId);
25
+ if (oldest)
26
+ totalBytes -= oldest.bytes;
27
+ sessions.delete(oldestSessionId);
28
+ }
29
+ function estimateBytes(e) {
30
+ try {
31
+ return Buffer.byteLength(JSON.stringify(e), "utf8");
32
+ }
33
+ catch {
34
+ // Never throw into the stream path.
35
+ return 0;
36
+ }
37
+ }
38
+ /**
39
+ * Record one live switchboard event. A session_id restarts with the app process, so the same id
40
+ * can name two calls; the entry resets on a second session/begin, or on an id at or below the
41
+ * newest held one with a later timestamp (ids climb within a call). Otherwise the previous call's
42
+ * tail would export as bogus host-recovered records on the new call. A lower id without a later
43
+ * timestamp is a late arrival and is inserted in id order.
44
+ *
45
+ * Duplicates are checked first, so a redelivered begin (even with no timestamp on either copy)
46
+ * does not wipe the entry.
47
+ */
48
+ export function recordSwitchboardStreamed(event) {
49
+ const id = event.id;
50
+ const sessionId = event.session_id;
51
+ if (typeof id !== "number" || !Number.isFinite(id))
52
+ return;
53
+ if (typeof sessionId !== "number" || !Number.isFinite(sessionId))
54
+ return;
55
+ let entry = sessions.get(sessionId);
56
+ let lateArrival = false;
57
+ if (entry) {
58
+ const held = entry.records.get(id);
59
+ // undefined === undefined counts as a match on purpose (the begin-redelivery case above).
60
+ if (held && held.timestamp === event.timestamp)
61
+ return; // true duplicate, not a restart signal
62
+ const newestHeldId = entry.order.length ? entry.order[entry.order.length - 1] : null;
63
+ const newestHeldRecord = newestHeldId !== null ? entry.records.get(newestHeldId) : undefined;
64
+ const isBegin = event.kind === "session" && event.event === "begin" && entry.order.length > 0;
65
+ const idAtOrBelowNewest = newestHeldId !== null && id <= newestHeldId;
66
+ const isLaterThanNewest = typeof event.timestamp === "number" && typeof newestHeldRecord?.timestamp === "number" && event.timestamp > newestHeldRecord.timestamp;
67
+ const isRegression = idAtOrBelowNewest && isLaterThanNewest;
68
+ if (isBegin || isRegression) {
69
+ totalBytes -= entry.bytes;
70
+ sessions.delete(sessionId);
71
+ entry = undefined;
72
+ }
73
+ else if (idAtOrBelowNewest) {
74
+ lateArrival = true;
75
+ }
76
+ }
77
+ if (!entry) {
78
+ entry = { records: new Map(), order: [], sizes: new Map(), bytes: 0, seq: nextSeq++ };
79
+ sessions.set(sessionId, entry);
80
+ while (sessions.size > SWITCHBOARD_HOST_STORE_MAX_SESSIONS)
81
+ evictOldestSession();
82
+ }
83
+ if (entry.records.has(id))
84
+ return;
85
+ // At the cap, an id older than everything held would be evicted straight back off.
86
+ if (entry.order.length >= SWITCHBOARD_HOST_STORE_MAX_RECORDS && id < entry.order[0])
87
+ return;
88
+ const size = estimateBytes(event);
89
+ entry.records.set(id, event);
90
+ entry.sizes.set(id, size);
91
+ if (lateArrival) {
92
+ // Binary search, since a device streaming ids out of order would make a linear scan per insert.
93
+ let lo = 0;
94
+ let hi = entry.order.length;
95
+ while (lo < hi) {
96
+ const mid = (lo + hi) >> 1;
97
+ if (entry.order[mid] > id)
98
+ hi = mid;
99
+ else
100
+ lo = mid + 1;
101
+ }
102
+ entry.order.splice(lo, 0, id);
103
+ }
104
+ else {
105
+ entry.order.push(id);
106
+ }
107
+ entry.bytes += size;
108
+ totalBytes += size;
109
+ while (entry.order.length > 0 && (entry.order.length > SWITCHBOARD_HOST_STORE_MAX_RECORDS || entry.bytes > SWITCHBOARD_EXPORT_SAFETY_CAP_BYTES)) {
110
+ const evictId = entry.order.shift();
111
+ const evictSize = entry.sizes.get(evictId) ?? 0;
112
+ entry.bytes -= evictSize;
113
+ totalBytes -= evictSize;
114
+ entry.sizes.delete(evictId);
115
+ entry.records.delete(evictId);
116
+ }
117
+ // Can evict the session just written to, if it is the oldest-inserted.
118
+ while (totalBytes > SWITCHBOARD_HOST_STORE_MAX_TOTAL_BYTES && sessions.size > 0)
119
+ evictOldestSession();
120
+ }
121
+ /** One session's held records in id order; [] for a session never seen live or already cleared. */
122
+ export function getHostSwitchboardRecords(sessionId) {
123
+ const entry = sessions.get(sessionId);
124
+ if (!entry)
125
+ return [];
126
+ const out = [];
127
+ for (const id of entry.order) {
128
+ const record = entry.records.get(id);
129
+ if (record)
130
+ out.push(record);
131
+ }
132
+ return out;
133
+ }
134
+ /** Ranked by newest record timestamp, not id: ids restart with the app process, timestamps do not. */
135
+ export function newestHostSwitchboardSessionId() {
136
+ let bestId = null;
137
+ let bestTimestamp = -Infinity;
138
+ let bestRecordId = -Infinity;
139
+ let bestSeq = -1;
140
+ for (const [id, entry] of sessions) {
141
+ const highestHeldId = entry.order.length > 0 ? entry.order[entry.order.length - 1] : -Infinity;
142
+ const highestHeldRecord = entry.order.length > 0 ? entry.records.get(entry.order[entry.order.length - 1]) : undefined;
143
+ const timestamp = typeof highestHeldRecord?.timestamp === "number" && Number.isFinite(highestHeldRecord.timestamp) ? highestHeldRecord.timestamp : -Infinity;
144
+ const better = bestId === null ||
145
+ timestamp > bestTimestamp ||
146
+ (timestamp === bestTimestamp && highestHeldId > bestRecordId) ||
147
+ (timestamp === bestTimestamp && highestHeldId === bestRecordId && entry.seq > bestSeq);
148
+ if (better) {
149
+ bestId = id;
150
+ bestTimestamp = timestamp;
151
+ bestRecordId = highestHeldId;
152
+ bestSeq = entry.seq;
153
+ }
154
+ }
155
+ return bestId;
156
+ }
157
+ export function clearSwitchboardHostStore() {
158
+ sessions.clear();
159
+ totalBytes = 0;
160
+ }
161
+ export function _hostStoreSessionCountForTest() {
162
+ return sessions.size;
163
+ }
164
+ export function _hostStoreTotalBytesForTest() {
165
+ return totalBytes;
166
+ }
@@ -0,0 +1,15 @@
1
+ export declare function capitalizeSwitchboardNote(note: string): string;
2
+ export declare const CLIP_PEAK = 0.99;
3
+ export declare function switchboardClockLabel(clock: string): string;
4
+ export declare const SAVED_TURN_DROP_OUTCOMES: readonly string[];
5
+ export declare const SAVED_TURN_KEPT_OUTCOMES: readonly string[];
6
+ export declare const SAVED_TURN_OUTCOMES: readonly string[];
7
+ export declare const SWITCHBOARD_CONTROL_CHARS: RegExp;
8
+ export declare function stripSwitchboardControlChars(s: string): string;
9
+ export declare function switchboardDeviceToken(name: string): string;
10
+ export declare function savedTurnCountWord(outcome: string): string;
11
+ export declare function savedTurnLabel(outcome: unknown, hasThread: unknown): string;
12
+ export declare function savedTurnCountEntries(counts: unknown): {
13
+ outcome: string;
14
+ count: number | null;
15
+ }[];
@@ -0,0 +1,92 @@
1
+ // Kept free of imports: scripts/mirror-shared.mjs mirrors it into the browser bundle, which could
2
+ // not resolve switchboard-report.ts's Node-side import chain.
3
+ // NOTE lines are lowercase inline in the report; a caller opening a sentence with one needs this.
4
+ export function capitalizeSwitchboardNote(note) {
5
+ return note ? note.charAt(0).toUpperCase() + note.slice(1) : note;
6
+ }
7
+ // A peak at or above this is clipping. Shared here so the report and the dashboard sparkline use
8
+ // the same threshold.
9
+ export const CLIP_PEAK = 0.99;
10
+ // A turn record's `clock` in words. Shared here so the feed row and the report read the same.
11
+ // An unknown value is the device's to add, so it shows as sent rather than throwing.
12
+ const TURN_CLOCK_LABELS = {
13
+ no_card: "no card",
14
+ resumed_from_tap: "after tap",
15
+ resumed_from_server_answer: "after server answer",
16
+ };
17
+ export function switchboardClockLabel(clock) {
18
+ return Object.hasOwn(TURN_CLOCK_LABELS, clock) ? TURN_CLOCK_LABELS[clock] : clock;
19
+ }
20
+ // The saved_turn outcomes, the one list the feed row, the panel and the report read. `applied`
21
+ // (a subtitle line still held the frame's item) and `no_line` (no line held it any more, a normal
22
+ // late save, still kept) keep the turn; the drop reasons lose it. The words are the row's and the
23
+ // panel's. A server resend counts again under `applied` while its line still holds the slot, then
24
+ // under `no_line` once the line has moved on; no counting code needs the resend as its own name.
25
+ const SAVED_TURN_KEPT = { applied: "saved", no_line: "saved (line moved on)" };
26
+ const SAVED_TURN_DROPS = { missing_field: "missing field", other_session: "other session" };
27
+ const DROP_PREFIX = "dropped";
28
+ const THREAD_FLAG = "thread";
29
+ const NO_THREAD_FLAG = "no thread";
30
+ export const SAVED_TURN_DROP_OUTCOMES = Object.keys(SAVED_TURN_DROPS);
31
+ // Only these keep the turn. The panel warns on anything else, so a drop reason the device adds
32
+ // later fails closed instead of reading as a clean session.
33
+ export const SAVED_TURN_KEPT_OUTCOMES = Object.keys(SAVED_TURN_KEPT);
34
+ // The four a revision 3 build always counts, in the order the panel and the report list them.
35
+ export const SAVED_TURN_OUTCOMES = [...Object.keys(SAVED_TURN_KEPT), ...SAVED_TURN_DROP_OUTCOMES];
36
+ // Code points a free-form device string could use to fake a line break, a report boundary, or a
37
+ // hidden direction override: controls, bidi marks, zero-width characters, U+2028/2029 (a newline
38
+ // to a browser), and the BOM. Here rather than in the report so the panel strips the same set.
39
+ export const SWITCHBOARD_CONTROL_CHARS = new RegExp("[\\u0000-\\u001f\\u007f-\\u009f\\u061c\\u200b-\\u200f\\u2028\\u2029\\u202a-\\u202e\\u2066-\\u2069\\ufeff]", "g");
40
+ export function stripSwitchboardControlChars(s) {
41
+ return s.replace(SWITCHBOARD_CONTROL_CHARS, "");
42
+ }
43
+ // The words a device name could be misread by: the kept marker "saved", the retired "replaced",
44
+ // the drop prefix, the thread flag, and the known outcome names. A name is matched on its letters
45
+ // alone, lowercased, so Saved, saved_again, savedAgain, saved2 and noLine all hit, while a name
46
+ // that only shares a filler word with a label (session_closed, line_busy) stays bare.
47
+ const letters = (s) => s.toLowerCase().replace(/[^a-z]/g, "");
48
+ const SAVED_TURN_MARKERS = [...SAVED_TURN_OUTCOMES, "saved", "replaced", DROP_PREFIX, THREAD_FLAG].map(letters);
49
+ // A device-added name (an outcome, a counts key) as the panel, the feed row and the report print
50
+ // it: bare only when it is a plain token with none of the marker words in it, quoted otherwise, so
51
+ // it cannot pass for a built-in word or a count of its own. The quoted form escapes the raw name,
52
+ // anything outside printable ASCII as \uXXXX, rather than stripping it first: the escape already
53
+ // makes a control or invisible character harmless, and stripping would print two names that differ
54
+ // only by one the same.
55
+ export function switchboardDeviceToken(name) {
56
+ if (/^[A-Za-z0-9_.-]+$/.test(name) && !SAVED_TURN_MARKERS.some((m) => letters(name).includes(m)))
57
+ return name;
58
+ return JSON.stringify(name).replace(/[^\x20-\x7e]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
59
+ }
60
+ // An outcome in words: "saved", "saved (line moved on)", "dropped: missing field", decided on the
61
+ // raw outcome. An unknown outcome is the device's to add and prints as a device token (above).
62
+ export function savedTurnCountWord(outcome) {
63
+ if (Object.hasOwn(SAVED_TURN_KEPT, outcome))
64
+ return SAVED_TURN_KEPT[outcome];
65
+ return Object.hasOwn(SAVED_TURN_DROPS, outcome) ? `${DROP_PREFIX}: ${SAVED_TURN_DROPS[outcome]}` : switchboardDeviceToken(outcome);
66
+ }
67
+ // A saved_turn record in words, shared by the feed row and the report like the clock above. A kept
68
+ // turn reads with its thread flag; a drop reads its reason alone; an unknown outcome reads as its
69
+ // token and never gets a thread flag, so it cannot read as a kept turn. A non-string outcome reads "".
70
+ export function savedTurnLabel(outcome, hasThread) {
71
+ if (typeof outcome !== "string")
72
+ return "";
73
+ const word = savedTurnCountWord(outcome);
74
+ return Object.hasOwn(SAVED_TURN_KEPT, outcome) ? `${word}, ${hasThread === true ? THREAD_FLAG : NO_THREAD_FLAG}` : word;
75
+ }
76
+ // A summary's `saved_turn_counts` as ordered entries: the four known outcomes first, then any key
77
+ // the device added, as sent. A count reads null when nothing counted it: absent (a revision 2 build
78
+ // counts nothing, which is not zero), a known key missing from a present object (revision 3 always
79
+ // sends all four), or a value that is not a non-negative safe integer. The caller prints "?" rather
80
+ // than a count nobody sent.
81
+ export function savedTurnCountEntries(counts) {
82
+ const obj = counts !== null && typeof counts === "object" && !Array.isArray(counts) ? counts : {};
83
+ const read = (k) => {
84
+ const v = obj[k];
85
+ return typeof v === "number" && Number.isSafeInteger(v) && v >= 0 ? v : null;
86
+ };
87
+ const out = SAVED_TURN_OUTCOMES.map((k) => ({ outcome: k, count: read(k) }));
88
+ for (const k of Object.keys(obj))
89
+ if (!SAVED_TURN_OUTCOMES.includes(k))
90
+ out.push({ outcome: k, count: read(k) });
91
+ return out;
92
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Write `content` under `dir` and return the path. The random suffix keeps two same-millisecond
3
+ * writes apart, since writeFileSync follows symlinks and overwrites. Throws on I/O failure.
4
+ */
5
+ export declare function writeSwitchboardReportFile(dir: string, prefix: string, content: string, now?: number): string;
@@ -0,0 +1,26 @@
1
+ // Shared by the MCP export tool and the web export route.
2
+ import crypto from "crypto";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ const DIR_MODE = 0o700;
6
+ const FILE_MODE = 0o600;
7
+ /**
8
+ * Write `content` under `dir` and return the path. The random suffix keeps two same-millisecond
9
+ * writes apart, since writeFileSync follows symlinks and overwrites. Throws on I/O failure.
10
+ */
11
+ export function writeSwitchboardReportFile(dir, prefix, content, now = Date.now()) {
12
+ fs.mkdirSync(dir, { recursive: true, mode: DIR_MODE });
13
+ // mkdirSync's mode only applies to directories it creates, so tighten existing ones too.
14
+ for (const p of [dir, path.dirname(dir)]) {
15
+ try {
16
+ if (fs.existsSync(p))
17
+ fs.chmodSync(p, DIR_MODE);
18
+ }
19
+ catch {
20
+ // Best effort; not fatal.
21
+ }
22
+ }
23
+ const file = path.join(dir, `${prefix}-${now}-${crypto.randomBytes(8).toString("hex")}.txt`);
24
+ fs.writeFileSync(file, content, { mode: FILE_MODE });
25
+ return file;
26
+ }
@@ -0,0 +1,20 @@
1
+ import { type SwitchboardReportAssembly } from "./switchboard.js";
2
+ export { SWITCHBOARD_CONTROL_CHARS, stripSwitchboardControlChars } from "./switchboard-note.js";
3
+ export declare const DBFS_FLOOR = -60;
4
+ export declare function toDbfs(linear: number): number;
5
+ export declare function fmtDbfs(v: unknown): string;
6
+ export declare function fmtDbfsRange(s: {
7
+ min: number;
8
+ max: number;
9
+ } | null): string;
10
+ /**
11
+ * Build the report for one assembled export. Records sort by their own timestamp then id, never
12
+ * the device's arrival order, since a late-landing batch can carry a higher id than an earlier
13
+ * neighbor. now is a parameter so the report stays pure and testable.
14
+ *
15
+ * A hostOnlyCause overrides every other NOTE: the eviction and ring-cap reasoning needs device
16
+ * detail that a host-only report does not have.
17
+ */
18
+ export declare function buildSwitchboardReport(assembly: SwitchboardReportAssembly, now?: number): string;
19
+ export declare function switchboardReportNotes(report: string): string[];
20
+ export { capitalizeSwitchboardNote } from "./switchboard-note.js";