@slack/radar-mcp 1.23.0 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +14 -7
  2. package/dist/mcp/dashboard-identity.d.ts +10 -0
  3. package/dist/mcp/dashboard-identity.js +20 -0
  4. package/dist/mcp/debug-package-reset.d.ts +5 -0
  5. package/dist/mcp/debug-package-reset.js +28 -0
  6. package/dist/mcp/flags-tools.d.ts +2 -0
  7. package/dist/mcp/flags-tools.js +10 -2
  8. package/dist/mcp/index.js +74 -54
  9. package/dist/mcp/radar-http.js +3 -1
  10. package/dist/mcp/session-enable.d.ts +1 -0
  11. package/dist/mcp/session-enable.js +52 -8
  12. package/dist/mcp/switchboard-tools.d.ts +5 -2
  13. package/dist/mcp/switchboard-tools.js +18 -12
  14. package/dist/mcp/tools.js +69 -169
  15. package/dist/mcp/web-child-env.js +2 -1
  16. package/dist/shared/android.d.ts +74 -10
  17. package/dist/shared/android.js +344 -103
  18. package/dist/shared/constants.d.ts +17 -5
  19. package/dist/shared/constants.js +59 -5
  20. package/dist/shared/db.d.ts +1 -1
  21. package/dist/shared/db.js +21 -14
  22. package/dist/shared/debug-log.js +2 -4
  23. package/dist/shared/enable-diagnosis.d.ts +27 -1
  24. package/dist/shared/enable-diagnosis.js +73 -0
  25. package/dist/shared/feature-flags.d.ts +11 -0
  26. package/dist/shared/feature-flags.js +18 -4
  27. package/dist/shared/log-session.d.ts +2 -1
  28. package/dist/shared/prefs.js +4 -5
  29. package/dist/shared/radar-request-raw.js +3 -1
  30. package/dist/shared/switchboard-note.d.ts +19 -0
  31. package/dist/shared/switchboard-note.js +76 -0
  32. package/dist/shared/switchboard-report.js +40 -4
  33. package/dist/shared/switchboard.d.ts +2 -1
  34. package/dist/shared/switchboard.js +17 -3
  35. package/dist/shared/transport.d.ts +24 -0
  36. package/dist/shared/wire.d.ts +2 -0
  37. package/dist/web/install-app-cli.d.ts +2 -0
  38. package/dist/web/install-app-cli.js +60 -0
  39. package/dist/web/install-app.d.ts +16 -7
  40. package/dist/web/install-app.js +92 -39
  41. package/dist/web/macapp/RadarApp.swift +12 -11
  42. package/dist/web/public/index.html +4 -2
  43. package/dist/web/public/next/feature-flags.js +33 -0
  44. package/dist/web/public/next/feed.js +13 -2
  45. package/dist/web/public/next/flags.js +15 -3
  46. package/dist/web/public/next/registry.js +4 -4
  47. package/dist/web/public/next/store.js +89 -3
  48. package/dist/web/public/next/switchboard-note.js +76 -0
  49. package/dist/web/public/next/voice-model.js +196 -14
  50. package/dist/web/public/next/voice.js +68 -10
  51. package/dist/web/server.d.ts +17 -0
  52. package/dist/web/server.js +180 -35
  53. package/dist/web/spec.d.ts +1 -1
  54. package/dist/web/spec.js +1 -1
  55. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  // Pure text builder for one switchboard (Slackbot voice) session report. Input is read
2
2
  // defensively: it crossed the device wire, and one odd or older-build field must never throw.
3
3
  import { SWITCHBOARD_DEVICE_RING_CAP, SWITCHBOARD_EXPORT_SAFETY_CAP_BYTES, SWITCHBOARD_EXPORT_WALK_DEADLINE_MS, switchboardWalkStopNote, } from "./switchboard.js";
4
- import { CLIP_PEAK, SAVED_TURN_OUTCOMES, savedTurnCountEntries, savedTurnLabel, stripSwitchboardControlChars, switchboardClockLabel, switchboardDeviceToken, } from "./switchboard-note.js";
4
+ import { CLIP_PEAK, micEncodingNote, openCards, SAVED_TURN_OUTCOMES, reconnectTryLabel, savedTurnCountEntries, savedTurnLabel, serverEndedNormally, stripSwitchboardControlChars, switchboardClockLabel, switchboardDeviceToken, } from "./switchboard-note.js";
5
5
  const refusedPhrase = (sendsToken) => sendsToken ? "the device refused this Radar session's token" : "the device refused the request (HTTP 401)";
6
6
  const againPhrase = (surface) => surface === "dashboard" ? "press Reconnect and export again for the device copy" : "run /radar-enable and export again for the device copy";
7
7
  // Re-exported so the existing callers keep their import; the set itself lives in the note.
@@ -90,14 +90,17 @@ function recordLine(r) {
90
90
  case "session": {
91
91
  const event = str(r.event) ?? "?";
92
92
  const serverId = str(r.server_session_id);
93
- return `${head} ${event}${serverId ? ` server_session_id=${serverId}` : ""}`;
93
+ const micEncoding = str(r.mic_encoding);
94
+ return `${head} ${event}${serverId ? ` server_session_id=${serverId}` : ""}${micEncoding ? ` mic_encoding=${micEncoding}` : ""}`;
94
95
  }
95
96
  case "state": {
96
97
  const stateKind = str(r.state_kind) ?? "?";
97
98
  const from = str(r.from) ?? "?";
98
99
  const to = str(r.to) ?? "?";
99
100
  const cause = str(r.cause);
100
- return `${head} ${stateKind} ${from} -> ${to}${cause ? ` (${cause})` : ""}`;
101
+ // A goodbye or a limit still reads Failed on the wire; say it was a normal end.
102
+ const normal = stateKind === "connection" && to === "Failed" && serverEndedNormally(cause) ? ", a normal end" : "";
103
+ return `${head} ${stateKind} ${from} -> ${to}${cause ? ` (${cause}${normal})` : ""}`;
101
104
  }
102
105
  case "frame": {
103
106
  const direction = str(r.direction) ?? "?";
@@ -144,6 +147,16 @@ function recordLine(r) {
144
147
  const clock = str(r.clock);
145
148
  return `${head} ${fmtMs(r.response_ms)}, ${clock ? reportClockLabel(clock) : "?"}`;
146
149
  }
150
+ case "reconnect_try": {
151
+ const trigger = str(r.trigger) ?? "?";
152
+ const outcome = str(r.outcome) ?? "?";
153
+ return `${head} ${reconnectTryLabel(trigger, outcome, num(r.try))}`;
154
+ }
155
+ case "card": {
156
+ // The wire labels, not the panel's words, so a reader can grep the export for them.
157
+ const by = str(r.by);
158
+ return `${head} ${str(r.card_kind) ?? "?"} ${str(r.event) ?? "?"}${by ? ` by ${by}` : ""} card_id=${str(r.card_id) ?? "?"}`;
159
+ }
147
160
  case "saved_turn": {
148
161
  // Raw, not stripped: known or unknown is decided on what the device sent, so "applied" plus a
149
162
  // hidden character is an unknown outcome, quoted, and never "saved, thread".
@@ -220,6 +233,9 @@ export function buildSwitchboardReport(assembly, now = Date.now()) {
220
233
  const deviceOnlyCount = deviceEventCount !== null ? deviceEventCount : events.length - hostStreamCount;
221
234
  const streamedDuringExport = deviceEventCount !== null ? Math.max(0, events.length - hostStreamCount - deviceEventCount) : 0;
222
235
  const fetchIncomplete = deviceOnlyCount > 0 && totalCaptured !== null && deviceOnlyCount < totalCaptured;
236
+ // One completeness rule for the cards_open line and the stream-copy note. A short fetch the live
237
+ // stream copy filled is not missing records, and the stream-copy note says so.
238
+ const holdsEveryRecord = !startMissing && gapCount === 0 && (!fetchIncomplete || hostStreamCount > 0);
223
239
  // Suggestive, not proof, that the ring lost the start, so it only earns the soft phrasing. The
224
240
  // oldest-timestamp signal counts only when the walk reached the end of the device's range.
225
241
  const oldestTimestampIsRingEvidence = walkStopReason === null || walkStopReason === "done";
@@ -231,6 +247,26 @@ export function buildSwitchboardReport(assembly, now = Date.now()) {
231
247
  // live device connection to promise one.
232
248
  const serverSessionIdText = serverSessionId ?? (!deviceGone && live && hasServerSessionIdKey ? "pending" : "(not reported)");
233
249
  lines.push(`server_session_id: ${serverSessionIdText}`);
250
+ // A reconnect can bring a new server id; older builds send no list, so they print as before.
251
+ const allServerIds = Array.isArray(d.server_session_ids) ? d.server_session_ids.map(str).filter((x) => x !== null) : [];
252
+ if (allServerIds.length >= 2)
253
+ lines.push(`server_session_ids: ${allServerIds.join(", ")}`);
254
+ // The summary's label outlives the config record's eviction, and a host-only report already
255
+ // gets it from hostOnlySwitchboardDetail. A build that sends no label prints no line.
256
+ const micEncoding = str(d.mic_encoding);
257
+ if (micEncoding !== null) {
258
+ const micNote = micEncodingNote(micEncoding);
259
+ lines.push(`mic_encoding: ${micEncoding}${micNote ? ` (${micNote})` : ""}`);
260
+ }
261
+ // Only rows with a card record get the line; none printed means no card record in these rows, not
262
+ // that no card is up.
263
+ if (events.some((e) => e.kind === "card")) {
264
+ const up = openCards(events).map((c) => `${stripSwitchboardControlChars(c.kind)} ${stripSwitchboardControlChars(c.id)}`);
265
+ // A card shown in a record this report lacks looks closed or never up, so say so.
266
+ const partial = !holdsEveryRecord;
267
+ const note = partial ? "shown or carried with no later record, among the records this report holds" : "shown or carried with no later record";
268
+ lines.push(`cards_open: ${up.length ? `${up.join(", ")} (${note})` : partial ? "none seen (the report does not hold every record)" : "none"}`);
269
+ }
234
270
  lines.push(`team_id: ${teamId ?? "(none)"}`);
235
271
  lines.push(`began_at: ${isoOrRaw(beganAt)}`);
236
272
  // A host-only report with no end record is not evidence the call is still live.
@@ -285,7 +321,7 @@ export function buildSwitchboardReport(assembly, now = Date.now()) {
285
321
  }
286
322
  lines.push(`exported_at: ${isoOrRaw(now)}`);
287
323
  // A host copy with a mid-call gap did not really supply the older records.
288
- const hostFilledStart = !startMissing && hostStreamCount > 0 && gapCount === 0;
324
+ const hostFilledStart = holdsEveryRecord && hostStreamCount > 0;
289
325
  const hostWalkNote = hostFilledWalkNoteText(walkStopReason, hostFilledStart, refused, again);
290
326
  // "up to": ids come from one counter shared across sessions, so gapCount is an upper bound.
291
327
  const gapNote = (cause) => `the report reaches the call's start, but up to ${gapCount} record${gapCount === 1 ? "" : "s"} in the middle may be missing: ${cause}`;
@@ -3,12 +3,13 @@ export declare const SWITCHBOARD_KIND = "switchboard";
3
3
  export declare const SWITCHBOARD_BACKFILL_SESSIONS = 3;
4
4
  export declare const SWITCHBOARD_BACKFILL_DEADLINE_MS: number;
5
5
  export declare function switchboardListPath(): string;
6
- export declare const SWITCHBOARD_KINDS: readonly ["session", "state", "frame", "phase", "player", "levels", "turn", "saved_turn"];
6
+ export declare const SWITCHBOARD_KINDS: readonly ["session", "state", "frame", "phase", "player", "levels", "turn", "saved_turn", "card", "reconnect_try"];
7
7
  export type SwitchboardKind = (typeof SWITCHBOARD_KINDS)[number];
8
8
  export declare function switchboardSessionPath(sessionId: number, limit: number, kind?: SwitchboardKind, beforeId?: number): string;
9
9
  export declare function newestSwitchboardSessionIds(list: unknown): number[];
10
10
  export declare function switchboardPageEvents(session: unknown): Record<string, unknown>[];
11
11
  export declare function nonNegativeIntArg(v: unknown): number | null;
12
+ export declare const SWITCHBOARD_DEVICE_UNREACHABLE_ERROR = "Device unreachable. Is Radar armed?";
12
13
  export declare const SWITCHBOARD_EXPORT_MAX_LIMIT = 2000;
13
14
  export declare const SWITCHBOARD_DEVICE_RING_CAP = 10000;
14
15
  export declare const SWITCHBOARD_EXPORT_MAX_PAGES = 25;
@@ -7,6 +7,7 @@
7
7
  // is absent, so the limit is forwarded per session or a talkative session replays as its last few
8
8
  // seconds).
9
9
  import { lastHeaderBuildFailure, unauthorizedMessageFor, } from "./radar-token.js";
10
+ import { SERVER_SESSION_ID_CAP } from "./switchboard-note.js";
10
11
  export const SWITCHBOARD_KIND = "switchboard";
11
12
  // Sessions replayed per backfill. Bounds the round trips (one list plus one fetch per session).
12
13
  export const SWITCHBOARD_BACKFILL_SESSIONS = 3;
@@ -20,7 +21,7 @@ export function switchboardListPath() {
20
21
  }
21
22
  // The record kinds the plugin emits, the closed set a `kind` query may name. Shared so the path
22
23
  // builder below takes the type and never sees raw input.
23
- export const SWITCHBOARD_KINDS = ["session", "state", "frame", "phase", "player", "levels", "turn", "saved_turn"];
24
+ export const SWITCHBOARD_KINDS = ["session", "state", "frame", "phase", "player", "levels", "turn", "saved_turn", "card", "reconnect_try"];
24
25
  // beforeId asks for records with id < beforeId. An older device ignores it and repeats the newest
25
26
  // page; walkSwitchboardExportPages detects that.
26
27
  export function switchboardSessionPath(sessionId, limit, kind, beforeId) {
@@ -70,6 +71,8 @@ export function nonNegativeIntArg(v) {
70
71
  }
71
72
  return Number.isSafeInteger(n) && n >= 0 ? n : null;
72
73
  }
74
+ // The export error for a device that never answered; the MCP swaps it for the enable error when it has one.
75
+ export const SWITCHBOARD_DEVICE_UNREACHABLE_ERROR = "Device unreachable. Is Radar armed?";
73
76
  // The device's per-request cap on a session detail limit.
74
77
  export const SWITCHBOARD_EXPORT_MAX_LIMIT = 2000;
75
78
  // The device's per-session ring cap (docs/wire-contract.md). Eviction checks compare against
@@ -380,12 +383,19 @@ export function hostOnlySwitchboardDetail(sessionId, hostRecords) {
380
383
  : null;
381
384
  let teamId = null;
382
385
  let serverSessionId = null;
386
+ const serverSessionIds = [];
383
387
  let endedAt = null;
388
+ let micEncoding = null;
384
389
  for (const e of records) {
385
390
  if (teamId === null && typeof e.team_id === "string")
386
391
  teamId = e.team_id;
387
- if (serverSessionId === null && e.kind === "session" && e.event === "ready" && typeof e.server_session_id === "string")
392
+ if (e.kind === "session" && e.event === "ready" && typeof e.server_session_id === "string") {
388
393
  serverSessionId = e.server_session_id;
394
+ if (!serverSessionIds.includes(e.server_session_id))
395
+ serverSessionIds.push(e.server_session_id);
396
+ }
397
+ if (e.kind === "session" && e.event === "config" && typeof e.mic_encoding === "string")
398
+ micEncoding = e.mic_encoding;
389
399
  if (endedAt === null && e.kind === "session" && e.event === "end" && typeof e.timestamp === "number" && Number.isFinite(e.timestamp))
390
400
  endedAt = e.timestamp;
391
401
  }
@@ -400,6 +410,10 @@ export function hostOnlySwitchboardDetail(sessionId, hostRecords) {
400
410
  };
401
411
  if (serverSessionId !== null)
402
412
  detail.server_session_id = serverSessionId;
413
+ if (serverSessionIds.length > 0)
414
+ detail.server_session_ids = serverSessionIds.slice(-SERVER_SESSION_ID_CAP);
415
+ if (micEncoding !== null)
416
+ detail.mic_encoding = micEncoding;
403
417
  return detail;
404
418
  }
405
419
  export function oldestSwitchboardTimestamp(events) {
@@ -462,7 +476,7 @@ getNewestHostSessionId, sender, surface = "mcp") {
462
476
  : outcome.reason === "not-found"
463
477
  ? `No switchboard session ${outcome.sessionId} on the device (unknown id, or the device already dropped it).`
464
478
  : outcome.reason === "unreachable"
465
- ? "Device unreachable. Is Radar armed?"
479
+ ? SWITCHBOARD_DEVICE_UNREACHABLE_ERROR
466
480
  : outcome.reason === "bad-response" && outcome.sessionId !== undefined
467
481
  ? `The device reply was too large to read (over the ${SWITCHBOARD_EXPORT_SAFETY_CAP_BYTES / (1024 * 1024)} MB size cap), and this process holds no live stream copy of the call.`
468
482
  : "The device answered, but not with anything this export could use.";
@@ -7,7 +7,10 @@
7
7
  * interact only through this interface.
8
8
  */
9
9
  import type { LogSession } from "./log-session.js";
10
+ import type { BareEnableError } from "./enable-diagnosis.js";
10
11
  import type { TokenFileError } from "./radar-token.js";
12
+ /** Why an enable sent the token on the command line instead of the token file. */
13
+ export type ArgvReason = "the token file write failed" | "this build has no token file reader; update it";
11
14
  /** Which underlying source served a getRecentLogs result. */
12
15
  export type LogSource = "app_buffer" | "logcat_capture" | "logcat_ring" | "ios_unified_capture";
13
16
  /**
@@ -117,6 +120,23 @@ export interface DeviceTransport {
117
120
  * Android adb forward can otherwise be mistaken for the selected Simulator app.
118
121
  */
119
122
  acceptsRadarPeer?(ping: Record<string, unknown>): boolean;
123
+ /**
124
+ * The package of a different build that owns the Radar listener, or null when the ping does
125
+ * not show one. Android has one device-side socket, so a second debug build cannot bind it
126
+ * and the ping then answers for the build that did. Kept apart from acceptsRadarPeer: that
127
+ * method makes the enable and the web arm treat a mismatch as "no listener", which would
128
+ * refuse a cold Android enable and change which sources are offered.
129
+ */
130
+ foreignRadarOwner?(ping: Record<string, unknown>): string | null;
131
+ /**
132
+ * Take the package that owns the Radar listener as this transport's own build, when that is
133
+ * safe. A dashboard started by hand on a device another session already armed has no
134
+ * way to learn which build it is reading, and the ping names it. No-op when the transport
135
+ * cannot adopt.
136
+ */
137
+ adoptRadarOwner?(ping: Record<string, unknown>): void;
138
+ /** Forget the build a past arm decided, at the start of a fresh enable or profile switch. */
139
+ releaseDebugBuild?(): void;
120
140
  /**
121
141
  * What the user should do when the app's Radar listener does not answer, for transports
122
142
  * whose default advice ("check adb devices") does not apply. Absent keeps that default.
@@ -256,6 +276,10 @@ export interface DeviceTransport {
256
276
  ensureLogCapture?(): void;
257
277
  /** No broadcast went out, so callers report the file problem without probing the device. */
258
278
  getLastActivateTokenFileError?(): TokenFileError | null;
279
+ /** The last enable error whose message already says what to do (no debug build, two builds, a bad package override), shown plain. */
280
+ getLastActivateBareError?(): BareEnableError | null;
281
+ /** Why the last enable sent the token over the command line, or null when it went through the file. */
282
+ getLastTokenViaArgv?(): ArgvReason | null;
259
283
  /**
260
284
  * State of the target app process on the device, checked fresh (not cached). Lets the
261
285
  * enable flow tell a confirmed "stopped" apart from "the probe could not tell" when the
@@ -57,12 +57,14 @@ export interface SwitchboardSessionSummary {
57
57
  total_captured: number;
58
58
  levels: SwitchboardLevels | null;
59
59
  server_session_id?: string | null;
60
+ server_session_ids?: string[];
60
61
  turns?: {
61
62
  count: number;
62
63
  last_response_ms: number;
63
64
  last_clock: string;
64
65
  } | null;
65
66
  saved_turn_counts?: Record<string, number>;
67
+ mic_encoding?: string | null;
66
68
  }
67
69
  export interface SwitchboardSessionDetail extends SwitchboardSessionSummary {
68
70
  events: Record<string, unknown>[];
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function runInstallAppCli(argv: string[]): Promise<void>;
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ // The install-app flag dispatch, pulled out of mcp/index.ts so the app can spawn it without the
3
+ // MCP SDK. Imports only node builtins and ./install-app.js (which imports only from ../shared),
4
+ // so a copy of dist/ plus package.json is enough to run it.
5
+ //
6
+ // The argv shape is what RadarApp.swift spawns: `<bin> install-app [flag]`.
7
+ import { realpathSync } from "fs";
8
+ import { fileURLToPath } from "url";
9
+ export async function runInstallAppCli(argv) {
10
+ // The background rebuild RadarApp.swift runs once the precheck confirms a newer version (see
11
+ // install-app.ts's runSelfHealCheck).
12
+ const wantsSelfHealCheck = argv.includes("--self-heal-check");
13
+ // What RadarApp.swift ACTUALLY spawns now (see install-app.ts's runSelfHealPrecheck): a safe
14
+ // registry-version precheck that only falls through to --self-heal-check once a real upgrade is
15
+ // confirmed. Checked before wantsSelfHealCheck below so the two flags stay mutually exclusive.
16
+ const wantsSelfHealPrecheck = argv.includes("--self-heal-precheck");
17
+ // The two interactive halves of the app's Check for Updates... item: ask whether a newer build is
18
+ // published, then install it. Each prints a single JSON line for the app to read.
19
+ const wantsCheckUpdate = argv.includes("--check-update");
20
+ const wantsUpdateNow = argv.includes("--update-now");
21
+ if (wantsCheckUpdate) {
22
+ const { checkForUpdate } = await import("./install-app.js");
23
+ console.log(JSON.stringify(await checkForUpdate(process.env.RADAR_APP_VERSION)));
24
+ }
25
+ else if (wantsUpdateNow) {
26
+ const { runUpdateNow } = await import("./install-app.js");
27
+ await runUpdateNow();
28
+ }
29
+ else if (wantsSelfHealPrecheck) {
30
+ const { runSelfHealPrecheck } = await import("./install-app.js");
31
+ runSelfHealPrecheck();
32
+ }
33
+ else if (wantsSelfHealCheck) {
34
+ const { runSelfHealCheck } = await import("./install-app.js");
35
+ runSelfHealCheck();
36
+ }
37
+ else {
38
+ const { runInstallApp } = await import("./install-app.js");
39
+ runInstallApp();
40
+ }
41
+ }
42
+ // Same bin-vs-import test as bin.ts: realpathSync resolves an npm bin symlink to the real path.
43
+ function invokedDirectly() {
44
+ const arg = process.argv[1];
45
+ if (!arg)
46
+ return false;
47
+ try {
48
+ return fileURLToPath(import.meta.url) === realpathSync(arg);
49
+ }
50
+ catch {
51
+ return false;
52
+ }
53
+ }
54
+ if (invokedDirectly()) {
55
+ if (process.argv[2] !== "install-app") {
56
+ console.error("usage: install-app-cli install-app [--check-update|--update-now|--self-heal-precheck|--self-heal-check]");
57
+ process.exit(1);
58
+ }
59
+ await runInstallAppCli(process.argv);
60
+ }
@@ -1,4 +1,12 @@
1
1
  import { spawn } from "child_process";
2
+ /** Refuses anything that is not a version, so a value like ".." can never aim the swap at ~/.slack-radar itself. */
3
+ export declare function runtimeCopyDirFor(version: string): string;
4
+ /**
5
+ * Copies the package.json and dist the app needs into destRoot. No node_modules: the dashboard
6
+ * and install-app-cli.js import node builtins only. Throws on failure so the install stops before
7
+ * it bakes a path to a file that is not there.
8
+ */
9
+ export declare function copyRuntime(sourceRoot: string, destRoot: string): void;
2
10
  /**
3
11
  * Where a stable, version-free name for a node interpreter could live. Homebrew keeps one at
4
12
  * `<prefix>/bin/node` (`/opt/homebrew` on Apple silicon, `/usr/local` on Intel) pointing into the
@@ -153,11 +161,12 @@ export declare function installAppMessage(result: {
153
161
  }): string;
154
162
  /**
155
163
  * Entry point for `install-app --self-heal-check`, spawned in the background by RadarApp.swift
156
- * on every dock launch. install-app bakes the .app's paths and version in ONCE, so a Radar
157
- * upgrade via `npx @slack/radar-mcp@latest` (the documented setup) can leave the installed app
158
- * pointed at a stale, orphaned npx cache path with no signal to the user. This rebuilds it in
159
- * place when this process's own version (itself just resolved via the same `@latest` npx call)
160
- * differs from what is installed, so the fix lands invisibly and takes effect on the NEXT
164
+ * on every dock launch. install-app bakes the .app's paths and version in ONCE, and the app runs
165
+ * from its own copy of the package under ~/.slack-radar/app/<version>, so a Radar upgrade via
166
+ * `npx @slack/radar-mcp@latest` (the documented setup) leaves the installed app on the older
167
+ * version with no signal to the user. This rebuilds it in place, copying this process's own
168
+ * version (itself just resolved via the same `@latest` npx call) and pointing the app at that copy
169
+ * when it differs from what is installed, so the fix lands invisibly and takes effect on the NEXT
161
170
  * launch. Never throws out of this function, except when the final state write itself fails: a
162
171
  * launcher-triggered background process failing loudly would look like a crash, which is exactly
163
172
  * what staying invisible rules out. That one throw exits non-zero, which the precheck counts as a failure.
@@ -178,8 +187,8 @@ export declare function checkLatestPublishedVersion(): Promise<string | null>;
178
187
  export declare function _setSelfHealSpawnForTest(fn: typeof spawn): void;
179
188
  export declare function _setSelfHealRebuildTimeoutForTest(ms: number): void;
180
189
  /**
181
- * Entry point for `install-app --self-heal-precheck`. RadarApp.swift now spawns THIS (the
182
- * already-installed, guaranteed self-heal-aware mcp/index.js) instead of going straight to `npx
190
+ * Entry point for `install-app --self-heal-precheck`. RadarApp.swift now spawns THIS (install-app-cli.js
191
+ * in the app's own copy of the package, guaranteed self-heal-aware) instead of going straight to `npx
183
192
  * -y @slack/radar-mcp@latest install-app --self-heal-check`. The direct-to-npx version had a real
184
193
  * bug: nothing guaranteed `@latest` resolved to code that understood `--self-heal-check`, and the
185
194
  * already-published old dispatch ignores unknown flags and runs the full INTERACTIVE install
@@ -17,7 +17,10 @@
17
17
  // everyone. The shell launcher stays as the fallback for a machine with no Swift toolchain.
18
18
  //
19
19
  // Either way the app holds NO dashboard logic -- it starts the server and renders localhost -- so it
20
- // does not go stale when Radar upgrades (the SAME app keeps working against a newer dist).
20
+ // does not go stale when Radar upgrades (the SAME app keeps working against a newer dist). It runs
21
+ // from its own copy of the package under ~/.slack-radar/app/<version>, so the npx cache can change
22
+ // under it without changing what it serves. A self-heal rebuild copies the newer version and points
23
+ // the app at it. A checkout install needs install-app re-run to pick up dist edits.
21
24
  import { execFileSync, spawn } from "child_process";
22
25
  import fs from "fs";
23
26
  import http from "http";
@@ -49,15 +52,39 @@ function bashQuote(value) {
49
52
  function appDir() {
50
53
  return path.join(os.homedir(), "Applications");
51
54
  }
52
- /** The dashboard entrypoint this install will launch. Absolute, so a minimal PATH cannot break it. */
55
+ /** The package root this install runs from: two dirs above install-app.js (dist/web). */
56
+ function sourceRootPath() {
57
+ return path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
58
+ }
59
+ /** The dashboard entrypoint in the package being installed. Only used to check the install can
60
+ * proceed; the app bakes the copy's path instead (see runtimeCopyDir). */
53
61
  function webBinPath() {
54
- return path.join(path.dirname(fileURLToPath(import.meta.url)), "bin.js");
62
+ return path.join(sourceRootPath(), "dist", "web", "bin.js");
63
+ }
64
+ /** Where the app's own copies of the package live, one dir per version. */
65
+ function runtimeRoot() {
66
+ return path.join(os.homedir(), ".slack-radar", "app");
67
+ }
68
+ /** The copy this version's app runs from. Derived from RADAR_VERSION so a test can compute it. */
69
+ function runtimeCopyDir() {
70
+ return runtimeCopyDirFor(RADAR_VERSION);
71
+ }
72
+ /** Refuses anything that is not a version, so a value like ".." can never aim the swap at ~/.slack-radar itself. */
73
+ export function runtimeCopyDirFor(version) {
74
+ if (!/^[0-9][0-9A-Za-z.+-]*$/.test(version)) {
75
+ throw new Error(`refusing to copy the runtime for "${version}", which is not a version`);
76
+ }
77
+ return path.join(runtimeRoot(), version);
55
78
  }
56
- /** The ALREADY-INSTALLED mcp/index.js -- baked in at install time, so it is guaranteed to be
57
- * from THIS build (and therefore self-heal-precheck-aware), the same certainty webBinPath()
58
- * already gives the dashboard entrypoint. */
59
- function mcpBinPath() {
60
- return path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "mcp", "index.js");
79
+ /**
80
+ * Copies the package.json and dist the app needs into destRoot. No node_modules: the dashboard
81
+ * and install-app-cli.js import node builtins only. Throws on failure so the install stops before
82
+ * it bakes a path to a file that is not there.
83
+ */
84
+ export function copyRuntime(sourceRoot, destRoot) {
85
+ fs.mkdirSync(destRoot, { recursive: true });
86
+ fs.cpSync(path.join(sourceRoot, "package.json"), path.join(destRoot, "package.json"));
87
+ fs.cpSync(path.join(sourceRoot, "dist"), path.join(destRoot, "dist"), { recursive: true });
61
88
  }
62
89
  /**
63
90
  * A keg-only formula (`brew install node@22`) is not linked into `<prefix>/bin`, so it has no entry
@@ -414,10 +441,12 @@ export function installPort(env = process.env, installed) {
414
441
  * bakes execPath. With them, a synthetic Homebrew layout proves the wiring anywhere.
415
442
  */
416
443
  export function installConfigValues(execPath, candidates) {
444
+ const copy = runtimeCopyDir();
417
445
  return {
418
446
  node: stableNodePath(execPath ?? process.execPath, candidates ?? stableNodeCandidates()),
419
- webBin: webBinPath(),
420
- mcpBin: mcpBinPath(),
447
+ webBin: path.join(copy, "dist", "web", "bin.js"),
448
+ // install-app-cli.js, not mcp/index.js: it needs no node_modules, so the copy stays small.
449
+ mcpBin: path.join(copy, "dist", "web", "install-app-cli.js"),
421
450
  port: installPort(),
422
451
  };
423
452
  }
@@ -578,6 +607,46 @@ function buildIcns(resourcesDir) {
578
607
  // the finally below. Without this, one crashed install would wedge every self-heal check forever,
579
608
  // since nothing else ever removes the lock file.
580
609
  const STALE_LOCK_MS = 2 * 60 * 1000;
610
+ /**
611
+ * Puts the package copy at destDir: staged at `.new`, then renamed into place, with any existing
612
+ * same-version dir moved to `.old` first and removed after, the same shape as the bundle swap.
613
+ * When the install is already running from destDir (the app's own copy rebuilding the same
614
+ * version) the copy is skipped, since swapping a dir out from under the code reading it would
615
+ * delete the source.
616
+ */
617
+ function installRuntimeCopy(sourceRoot, destDir) {
618
+ try {
619
+ if (fs.realpathSync(sourceRoot) === fs.realpathSync(destDir))
620
+ return;
621
+ }
622
+ catch {
623
+ // destDir is not there yet, so the two cannot be the same dir.
624
+ }
625
+ const staging = `${destDir}.new`;
626
+ fs.mkdirSync(path.dirname(destDir), { recursive: true });
627
+ fs.rmSync(staging, { recursive: true, force: true });
628
+ copyRuntime(sourceRoot, staging);
629
+ swapIntoPlace(staging, destDir);
630
+ }
631
+ /**
632
+ * Renames a fully written staging dir over dest, keeping the old one at `.old` until the new one
633
+ * is in place. Clears a stale `.old` first (a crashed run's leftover) so the first rename cannot
634
+ * fail with ENOTEMPTY. Each rename is atomic, but the pair is not: a crash between them leaves dest
635
+ * at `.old` until a later run or a person moves it back. Node has no rename-exchange to close that.
636
+ */
637
+ function swapIntoPlace(staging, dest) {
638
+ const backup = `${dest}.old`;
639
+ fs.rmSync(backup, { recursive: true, force: true });
640
+ if (fs.existsSync(dest))
641
+ fs.renameSync(dest, backup);
642
+ fs.renameSync(staging, dest);
643
+ try {
644
+ fs.rmSync(backup, { recursive: true, force: true });
645
+ }
646
+ catch {
647
+ // A leftover .old must not fail an otherwise-good install.
648
+ }
649
+ }
581
650
  /**
582
651
  * Create (or replace) the launcher app. Returns its path.
583
652
  *
@@ -591,12 +660,12 @@ export function installMacApp() {
591
660
  const dir = appDir();
592
661
  const app = path.join(dir, `${APP_NAME}.app`);
593
662
  const staging = `${app}.new`;
594
- const backup = `${app}.old`;
595
663
  // Resolved once, since both build paths below need the same answer.
596
664
  const values = installConfigValues();
597
665
  const webBin = values.webBin;
598
- if (!fs.existsSync(webBin)) {
599
- throw new Error(`cannot find the dashboard entrypoint at ${webBin}`);
666
+ const sourceBin = webBinPath();
667
+ if (!fs.existsSync(sourceBin)) {
668
+ throw new Error(`cannot find the dashboard entrypoint at ${sourceBin}`);
600
669
  }
601
670
  // "wx" is atomic create-if-absent, so there is no check-then-create race on the lock itself.
602
671
  // A second caller finding it already there fails immediately rather than racing the same
@@ -629,6 +698,7 @@ export function installMacApp() {
629
698
  }
630
699
  }
631
700
  try {
701
+ installRuntimeCopy(sourceRootPath(), runtimeCopyDir());
632
702
  const macos = path.join(staging, "Contents", "MacOS");
633
703
  const resources = path.join(staging, "Contents", "Resources");
634
704
  fs.rmSync(staging, { recursive: true, force: true });
@@ -647,25 +717,7 @@ export function installMacApp() {
647
717
  }
648
718
  fs.writeFileSync(path.join(staging, "Contents", "Info.plist"), infoPlist(native ? "SlackRadar" : "radar-launcher", values.port));
649
719
  const icon = buildIcns(resources);
650
- // Each rename is one atomic filesystem op, so `app` is never half-old-half-new WITHIN either
651
- // step. The pair is not one atomic transaction though: a crash between the two renames leaves
652
- // no `app` at all (it is sitting at `backup`) until the process resumes and completes the
653
- // second rename or a person restores it by hand -- Node's fs has no rename-exchange primitive
654
- // to close that particular gap, so this is close to the best achievable on POSIX, not a full
655
- // guarantee. Clear any stale `.old` first (a previous run's crash leftover) so the first
656
- // rename cannot fail with ENOTEMPTY.
657
- fs.rmSync(backup, { recursive: true, force: true });
658
- if (fs.existsSync(app)) {
659
- fs.renameSync(app, backup);
660
- }
661
- fs.renameSync(staging, app);
662
- // Best-effort cleanup on success; a leftover .old must not fail an otherwise-good install.
663
- try {
664
- fs.rmSync(backup, { recursive: true, force: true });
665
- }
666
- catch {
667
- // harmless
668
- }
720
+ swapIntoPlace(staging, app);
669
721
  // Nudge Launch Services to notice the new bundle so it appears in Spotlight immediately
670
722
  // instead of whenever the system next rescans. Best effort; the app works regardless.
671
723
  try {
@@ -774,11 +826,12 @@ function logNoInstalledVersion(checkedAt, reason) {
774
826
  }
775
827
  /**
776
828
  * Entry point for `install-app --self-heal-check`, spawned in the background by RadarApp.swift
777
- * on every dock launch. install-app bakes the .app's paths and version in ONCE, so a Radar
778
- * upgrade via `npx @slack/radar-mcp@latest` (the documented setup) can leave the installed app
779
- * pointed at a stale, orphaned npx cache path with no signal to the user. This rebuilds it in
780
- * place when this process's own version (itself just resolved via the same `@latest` npx call)
781
- * differs from what is installed, so the fix lands invisibly and takes effect on the NEXT
829
+ * on every dock launch. install-app bakes the .app's paths and version in ONCE, and the app runs
830
+ * from its own copy of the package under ~/.slack-radar/app/<version>, so a Radar upgrade via
831
+ * `npx @slack/radar-mcp@latest` (the documented setup) leaves the installed app on the older
832
+ * version with no signal to the user. This rebuilds it in place, copying this process's own
833
+ * version (itself just resolved via the same `@latest` npx call) and pointing the app at that copy
834
+ * when it differs from what is installed, so the fix lands invisibly and takes effect on the NEXT
782
835
  * launch. Never throws out of this function, except when the final state write itself fails: a
783
836
  * launcher-triggered background process failing loudly would look like a crash, which is exactly
784
837
  * what staying invisible rules out. That one throw exits non-zero, which the precheck counts as a failure.
@@ -898,8 +951,8 @@ export function _setSelfHealRebuildTimeoutForTest(ms) {
898
951
  selfHealRebuildTimeoutMs = ms;
899
952
  }
900
953
  /**
901
- * Entry point for `install-app --self-heal-precheck`. RadarApp.swift now spawns THIS (the
902
- * already-installed, guaranteed self-heal-aware mcp/index.js) instead of going straight to `npx
954
+ * Entry point for `install-app --self-heal-precheck`. RadarApp.swift now spawns THIS (install-app-cli.js
955
+ * in the app's own copy of the package, guaranteed self-heal-aware) instead of going straight to `npx
903
956
  * -y @slack/radar-mcp@latest install-app --self-heal-check`. The direct-to-npx version had a real
904
957
  * bug: nothing guaranteed `@latest` resolved to code that understood `--self-heal-check`, and the
905
958
  * already-published old dispatch ignores unknown flags and runs the full INTERACTIVE install
@@ -770,11 +770,11 @@ enum QuitStopOutcome {
770
770
  /// window is what is left after this app's own window is excluded by id.
771
771
  case leftForWindow
772
772
  /// This app spawned it, and the server said somebody is using it without saying who, so it was left
773
- /// running. On the quit side that answer can only come from a server newer than this binary (a
774
- /// server this app spawned runs RADAR_WEB_BIN, which self-heal moves ahead of the compiled app), and
775
- /// the wire contract says a new kind is to be expected. Stopping a server whose newer answer said
776
- /// somebody was on it would be the implicit path costing somebody a page, which is the trade the launch
777
- /// arm reserves for an explicit request. The cost is one orphaned server, which the launch path reclaims.
773
+ /// running. On the quit side that answer should not come from a server this app spawned, since it
774
+ /// runs RADAR_WEB_BIN, which is this app's own version. If it ever does, it is a kind this binary
775
+ /// has not heard of, and the wire contract says a new kind is to be expected. Stopping a server whose
776
+ /// newer answer said somebody was on it would be the implicit path costing somebody a page, which is
777
+ /// the trade the launch arm reserves for an explicit request. The cost is one orphaned server, which the launch path reclaims.
778
778
  case leftUnattributed
779
779
  }
780
780
 
@@ -853,8 +853,8 @@ final class SpawnedDashboard {
853
853
  // used to kill the server that tab was reading.
854
854
  //
855
855
  // someoneUnnamed keeps the server too, and the route in matters. A server THIS app spawned runs
856
- // RADAR_WEB_BIN, which is this app's version or a NEWER one (self-heal updates the package under the
857
- // app, see triggerSelfHealCheck), so it understands the exclusion and never produces the OLD-server
856
+ // RADAR_WEB_BIN, which is this app's own version (a self-heal rebuild installs the newer version and
857
+ // points the app at it, see triggerSelfHealCheck), so it understands the exclusion and never produces the OLD-server
858
858
  // route into someoneUnnamed. The route it can produce is a kind this binary has not heard of, which
859
859
  // is exactly what the wire contract says to expect when the server is ahead, and that answer says
860
860
  // somebody is there. A quit is nobody asking, so it may not cost that somebody a page; the launch
@@ -1396,14 +1396,15 @@ func ensureDashboardRunning(respectInUse: Bool = true, ticket: LaunchTicket? = n
1396
1396
  }
1397
1397
 
1398
1398
  /// Fire-and-forget check that a newer Radar is available, so a dock app that install-app baked
1399
- /// paths and a version into ONCE self-heals on the NEXT launch instead of staying pinned to a
1400
- /// stale npx cache path after an `npx @slack/radar-mcp@latest` upgrade. Never blocks: this must
1399
+ /// paths and a version into ONCE self-heals on the NEXT launch instead of staying on its own copy
1400
+ /// of the older version after an `npx @slack/radar-mcp@latest` upgrade. Never blocks: this must
1401
1401
  /// add no delay before the window appears, so there is no waitUntilExit and no exit-status check.
1402
1402
  ///
1403
- /// Spawns the ALREADY-INSTALLED mcp/index.js, not `npx @latest` directly: nothing guarantees
1403
+ /// Spawns the ALREADY-INSTALLED install-app-cli.js (RADAR_MCP_BIN, in the app's own copy of the
1404
+ /// package), not `npx @latest` directly: nothing guarantees
1404
1405
  /// `@latest` resolves to code that understands `--self-heal-check`, and the already-published old
1405
1406
  /// dispatch ignores that unknown flag and runs the full INTERACTIVE install unconditionally. The
1406
- /// installed mcp/index.js is guaranteed to be from THIS build, so it knows to check the registry
1407
+ /// installed copy is guaranteed to be from THIS build, so it knows to check the registry
1407
1408
  /// itself before ever touching npx -- see install-app.ts's runSelfHealPrecheck().
1408
1409
  func triggerSelfHealCheck() {
1409
1410
  // Existence-checked, like the dashboard start. It used to be spawned under the baked path whatever
@@ -395,14 +395,15 @@
395
395
  :root.light .voice-guide { opacity:.6; }
396
396
  .voice-legend { display:flex; gap:8px 14px; font-size:11px; color:var(--muted-2); margin-top:8px; flex-wrap:wrap; }
397
397
  .voice-legend span::before { content:""; display:inline-block; width:10px; height:10px; border-radius:2px; margin-right:6px; vertical-align:-1px; background:var(--muted); }
398
- .voice-legend .m::before { background:var(--blue); } .voice-legend .y::before { background:var(--accent); } .voice-legend .r::before { background:var(--warn); } .voice-legend .s::before { background:var(--purple); } .voice-legend .f::before { background:var(--muted-2); }
398
+ .voice-legend .m::before { background:var(--blue); } .voice-legend .y::before { background:var(--accent); } .voice-legend .r::before { background:var(--warn); } .voice-legend .s::before { background:var(--purple); } .voice-legend .f::before { background:var(--muted-2); } .voice-legend .en::before { background:var(--muted); } .voice-legend .cd::before { background:var(--blue-2); }
399
399
  /* Plain swatch, matching the clipped peak rect in voice.ts's levelBars. */
400
+ .voice-legend .hd::before { background:var(--muted-2); opacity:.45; }
400
401
  .voice-legend .clip::before { background:var(--error); }
401
402
  /* Legend swatches teach the tracks' own shapes, not just their colours: a thin vertical bar
402
403
  for the line-tick markers (half height for the focus tick, half width for the stop tick,
403
404
  matching their own glyphs), a two-band gradient standing in for the stall's dashed cap, and a
404
405
  head-plus-stem shape for the error dot and the mixed glyph's own square-capped shape line. */
405
- .voice-legend .r::before, .voice-legend .s::before, .voice-legend .st::before, .voice-legend .e::before, .voice-legend .f::before { width:3px; height:11px; border-radius:1.5px; }
406
+ .voice-legend .r::before, .voice-legend .s::before, .voice-legend .st::before, .voice-legend .e::before, .voice-legend .en::before, .voice-legend .f::before, .voice-legend .cd::before { width:3px; height:11px; border-radius:1.5px; }
406
407
  .voice-legend .f::before { height:6px; }
407
408
  .voice-legend .s::before { width:2px; }
408
409
  .voice-legend .st::before { width:3px; height:11px; border:0; border-radius:0; background:repeating-linear-gradient(to bottom, var(--warn-2) 0 4px, transparent 4px 7px); }
@@ -691,6 +692,7 @@
691
692
  carry the disagreement signal and the raw accent/muted tokens sat under 4.5:1 in light. */
692
693
  .flagval.on { color:var(--accent-text); } .flagval.off { color:var(--text-2); } .flagval.dim { color:var(--muted-2); font-weight:400; }
693
694
  .flagval.variant { font-variant-numeric:normal; font-family:ui-monospace,Menlo,Consolas,monospace; font-size:11.5px; }
695
+ .flagrestart { margin-left:6px; font-size:10.5px; white-space:nowrap; color:var(--text-2); }
694
696
  .flagsview .dbout tr.overridden td { background:var(--hover); }
695
697
  /* live observer patch: briefly highlight a row whose value just changed */
696
698
  .flagsview .dbout tr.flash td { animation:flagflash 1.2s ease-out; }