@slack/radar-mcp 1.14.0 → 1.17.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 (45) hide show
  1. package/README.md +15 -3
  2. package/dist/mcp/db-tools.js +23 -0
  3. package/dist/mcp/dispatch.d.ts +4 -0
  4. package/dist/mcp/dispatch.js +26 -0
  5. package/dist/mcp/index.js +104 -32
  6. package/dist/mcp/platform-detect.d.ts +110 -0
  7. package/dist/mcp/platform-detect.js +246 -0
  8. package/dist/mcp/prefs-tools.d.ts +4 -3
  9. package/dist/mcp/prefs-tools.js +26 -3
  10. package/dist/mcp/session-enable.js +19 -1
  11. package/dist/mcp/snapshot.js +4 -1
  12. package/dist/mcp/sources-gate.js +6 -3
  13. package/dist/mcp/tools.d.ts +11 -0
  14. package/dist/mcp/tools.js +38 -0
  15. package/dist/shared/android.d.ts +40 -1
  16. package/dist/shared/android.js +114 -51
  17. package/dist/shared/constants.d.ts +25 -1
  18. package/dist/shared/constants.js +27 -1
  19. package/dist/shared/db.js +11 -2
  20. package/dist/shared/debug-log.js +6 -1
  21. package/dist/shared/enable-diagnosis.d.ts +28 -0
  22. package/dist/shared/enable-diagnosis.js +41 -0
  23. package/dist/shared/prefs.d.ts +0 -5
  24. package/dist/shared/prefs.js +6 -2
  25. package/dist/shared/screen.d.ts +46 -9
  26. package/dist/shared/screen.js +74 -11
  27. package/dist/shared/transport.d.ts +62 -5
  28. package/dist/shared/webapp.d.ts +50 -0
  29. package/dist/shared/webapp.js +65 -0
  30. package/dist/web/install-app.d.ts +87 -0
  31. package/dist/web/install-app.js +703 -0
  32. package/dist/web/macapp/RadarApp.swift +466 -0
  33. package/dist/web/public/icons/radar-1024.png +0 -0
  34. package/dist/web/public/icons/radar.svg +40 -0
  35. package/dist/web/public/index.html +41 -1
  36. package/dist/web/public/next/app.js +3 -0
  37. package/dist/web/public/next/db.js +145 -5
  38. package/dist/web/public/next/feed.js +18 -0
  39. package/dist/web/public/next/hooks.js +10 -1
  40. package/dist/web/public/next/screen.js +147 -43
  41. package/dist/web/public/next/store.js +114 -16
  42. package/dist/web/public/next/toast.js +134 -0
  43. package/dist/web/server.d.ts +2 -1
  44. package/dist/web/server.js +117 -12
  45. package/package.json +2 -2
@@ -0,0 +1,466 @@
1
+ // The macOS dock app's window. Compiled at install time by `slack-radar install-app`.
2
+ //
3
+ // WHY A NATIVE WINDOW AND NOT A BROWSER. The first version of this launcher just opened a URL, and
4
+ // a URL always resolves to a TAB in whatever browser is already running -- so a dock click landed
5
+ // Radar in the middle of a Safari window full of unrelated tabs. That is not an app. Chromium's
6
+ // --app flag produces a real standalone window, but only for Chromium users, and picking Chrome for
7
+ // a Safari user means launching a browser they do not use. A WKWebView owns its window outright, so
8
+ // every user gets the same thing: one window, one dock icon, no tab bar, no address bar, no browser.
9
+ //
10
+ // This holds NO dashboard logic. It starts the server if needed and renders localhost, so it does
11
+ // not go stale when Radar upgrades.
12
+ import AppKit
13
+ import WebKit
14
+
15
+ // --- BEGIN INSTALL CONFIG ---
16
+ // install-app.ts REPLACES this whole block (between the markers) with the real values before
17
+ // compiling. They are declared here as working defaults rather than bare placeholder tokens so this
18
+ // file stays valid, compilable Swift on its own -- an editor can typecheck it and `swiftc` builds it
19
+ // straight from the repo, which a token like RADAR_URL would break.
20
+ //
21
+ // Absolute paths, not bare names: a Finder-launched app gets a minimal PATH without the shell
22
+ // config that puts node on it, so `node` would not resolve.
23
+ let RADAR_URL = "http://localhost:8100"
24
+ let RADAR_NODE = "/usr/bin/env"
25
+ let RADAR_WEB_BIN = "node"
26
+ let RADAR_NPX = "/usr/bin/env"
27
+ let RADAR_MCP_BIN = "node"
28
+ // --- END INSTALL CONFIG ---
29
+
30
+ let radarURL = URL(string: RADAR_URL)!
31
+
32
+ /// Best-effort check that the dashboard is listening. /spec is instant (no device round-trip) and
33
+ /// unique to Radar, the same fingerprint the shell launcher and bin.ts's adopt path use.
34
+ func dashboardAlive() -> Bool {
35
+ var request = URLRequest(url: radarURL.appendingPathComponent("spec"))
36
+ request.timeoutInterval = 1.5
37
+ // A synchronous probe on a background queue: this runs before the window exists, so there is no
38
+ // UI to block, and the sequential start-then-wait reads far clearer than nested callbacks.
39
+ let semaphore = DispatchSemaphore(value: 0)
40
+ var ok = false
41
+ URLSession.shared.dataTask(with: request) { _, response, _ in
42
+ ok = (response as? HTTPURLResponse)?.statusCode == 200
43
+ semaphore.signal()
44
+ }.resume()
45
+ _ = semaphore.wait(timeout: .now() + 2)
46
+ return ok
47
+ }
48
+
49
+ /// Start the dashboard server if it is not already up, then wait for it to answer.
50
+ ///
51
+ /// The server auto-closes 5 minutes after its last tab closes, so on a cold Mac this is the normal
52
+ /// path, not an edge case. Waiting (rather than sleeping a fixed guess) matters because a cold node
53
+ /// start ranges from ~300ms to several seconds on a loaded machine, and loading the view too early
54
+ /// renders a WebKit error page the user has to manually reload past.
55
+ func ensureDashboardRunning() {
56
+ if dashboardAlive() { return }
57
+
58
+ let task = Process()
59
+ task.executableURL = URL(fileURLWithPath: RADAR_NODE)
60
+ task.arguments = [RADAR_WEB_BIN]
61
+ // SLACK_RADAR_NO_OPEN stops the server from opening a browser tab of its own, which would put a
62
+ // second copy of the dashboard on screen next to this window.
63
+ var env = ProcessInfo.processInfo.environment
64
+ env["SLACK_RADAR_NO_OPEN"] = "1"
65
+ task.environment = env
66
+ // Detach stdio to a log rather than inheriting: an inherited pipe nobody drains fills its buffer
67
+ // and blocks the server once it has logged enough.
68
+ let logPath = ("~/Library/Logs/slack-radar-dashboard.log" as NSString).expandingTildeInPath
69
+ FileManager.default.createFile(atPath: logPath, contents: nil)
70
+ if let handle = FileHandle(forWritingAtPath: logPath) {
71
+ handle.seekToEndOfFile()
72
+ task.standardOutput = handle
73
+ task.standardError = handle
74
+ }
75
+ do {
76
+ try task.run()
77
+ } catch {
78
+ // Nothing to do but continue: the window will show a connection error, which is the honest
79
+ // signal. A modal dialog here would be worse, since the usual cause is a port already taken
80
+ // by a healthy dashboard this probe merely failed to reach.
81
+ NSLog("radar: could not start the dashboard server: \(error)")
82
+ return
83
+ }
84
+
85
+ // ~10s ceiling, then load anyway so a merely-slow server still gets a window.
86
+ for _ in 0..<50 {
87
+ if dashboardAlive() { return }
88
+ Thread.sleep(forTimeInterval: 0.2)
89
+ }
90
+ }
91
+
92
+ /// Fire-and-forget check that a newer Radar is available, so a dock app that install-app baked
93
+ /// paths and a version into ONCE self-heals on the NEXT launch instead of staying pinned to a
94
+ /// stale npx cache path after an `npx @slack/radar-mcp@latest` upgrade. Never blocks: this must
95
+ /// add no delay before the window appears, so there is no waitUntilExit and no exit-status check.
96
+ ///
97
+ /// Spawns the ALREADY-INSTALLED mcp/index.js, not `npx @latest` directly: nothing guarantees
98
+ /// `@latest` resolves to code that understands `--self-heal-check`, and the already-published old
99
+ /// dispatch ignores that unknown flag and runs the full INTERACTIVE install unconditionally. The
100
+ /// installed mcp/index.js is guaranteed to be from THIS build, so it knows to check the registry
101
+ /// itself before ever touching npx -- see install-app.ts's runSelfHealPrecheck().
102
+ func triggerSelfHealCheck() {
103
+ let task = Process()
104
+ task.executableURL = URL(fileURLWithPath: RADAR_NODE)
105
+ task.arguments = [RADAR_MCP_BIN, "install-app", "--self-heal-precheck"]
106
+ // Same log file ensureDashboardRunning() writes to, so the outcome shows up next to the
107
+ // dashboard's own launch log. Not inherited stdio: an unread pipe can block the child.
108
+ let logPath = ("~/Library/Logs/slack-radar-dashboard.log" as NSString).expandingTildeInPath
109
+ FileManager.default.createFile(atPath: logPath, contents: nil)
110
+ if let handle = FileHandle(forWritingAtPath: logPath) {
111
+ handle.seekToEndOfFile()
112
+ task.standardOutput = handle
113
+ task.standardError = handle
114
+ }
115
+ do {
116
+ try task.run()
117
+ } catch {
118
+ // Same reasoning as ensureDashboardRunning(): log and move on, never crash the launcher.
119
+ NSLog("radar: could not start the self-heal check: \(error)")
120
+ }
121
+ }
122
+
123
+ extension FileManager {
124
+ /// Create the file only if it does not exist, so an existing log is appended to, not truncated.
125
+ func createFile(atPath path: String, contents: Data?) {
126
+ if !fileExists(atPath: path) {
127
+ createFile(atPath: path, contents: contents, attributes: nil)
128
+ }
129
+ }
130
+ }
131
+
132
+ class AppDelegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKDownloadDelegate, WKScriptMessageHandler {
133
+ var window: NSWindow!
134
+ var webView: WKWebView!
135
+ // Diverting a main-frame navigation response to a download cancels the frame load underneath
136
+ // it, and WebKit reports that cancellation to didFail/didFailProvisionalNavigation exactly like
137
+ // a real connection failure ("Frame load interrupted"). A token recorded just before that
138
+ // choice lets those delegates tell "we did this on purpose, the download is fine" apart from an
139
+ // actual dead server, instead of showing the error page after a save. Tokens are fungible there
140
+ // (neither delegate can tell which diversion it belongs to), so consuming any pending one is
141
+ // correct; each diversion's own expiry timer removes only the token IT created, so overlapping
142
+ // diversions cannot steal each other's credit.
143
+ private var pendingDownloadInterruptions: Set<UUID> = []
144
+ // The destination decideDestinationUsing picked for each download currently in flight, keyed by
145
+ // the WKDownload's own identity rather than a single slot. Two downloads can genuinely overlap:
146
+ // the dashboard blocks a second REQUEST while one is open, but a download keeps writing after
147
+ // that, so the next request's download can start before the previous one finishes. A single
148
+ // optional slot would let the second one's destination overwrite the first's before
149
+ // downloadDidFinish reads it, reporting the wrong file back to the page. downloadDidFinish
150
+ // reads its own entry and removes it; a failed download removes its entry too, so this never
151
+ // grows unbounded across a long session.
152
+ private var downloadDestinations: [ObjectIdentifier: URL] = [:]
153
+ // Paths this app has actually told the page about via downloadDidFinish below, most recent
154
+ // last. The reveal bridge only ever acts on a path in this list, never on an arbitrary string
155
+ // the page sends -- downloadDestinations itself is not usable for that check, since a finished
156
+ // download's entry is removed from it the moment it finishes, exactly the moment a reveal click
157
+ // becomes valid. Bounded (oldest dropped past maxRevealablePaths): a long-running dock app
158
+ // session doing nothing but taking screenshots should not grow this without limit, and nothing
159
+ // needs to reveal a save from dozens of screenshots ago.
160
+ private var revealablePaths: [String] = []
161
+ private let maxRevealablePaths = 20
162
+
163
+ func applicationDidFinishLaunching(_ notification: Notification) {
164
+ let config = WKWebViewConfiguration()
165
+ // The dashboard streams: /stream is Server-Sent Events and /screen/stream is a live MJPEG
166
+ // cast. Both are plain same-origin HTTP that WKWebView handles natively, so no extra config --
167
+ // this comment exists so a future change here is weighed against them.
168
+ config.websiteDataStore = .default() // persist localStorage so the theme choice survives a quit
169
+ // Lets the page ask us to reveal a saved file in Finder -- something no web page can do on
170
+ // its own. window.webkit.messageHandlers.radarReveal.postMessage(path) on the JS side.
171
+ config.userContentController.add(self, name: "radarReveal")
172
+ // Lets the failure page's Retry button call back into Swift without a custom URL scheme.
173
+ config.userContentController.add(self, name: "radarRetry")
174
+
175
+ webView = WKWebView(frame: .zero, configuration: config)
176
+ webView.navigationDelegate = self
177
+
178
+ let frame = NSRect(x: 0, y: 0, width: 1400, height: 900)
179
+ window = NSWindow(
180
+ contentRect: frame,
181
+ // A normal titled window with the standard traffic lights, which is what makes it read as an
182
+ // app rather than a browser. fullSizeContentView would look sleeker but would put the
183
+ // dashboard's own header behind the traffic lights.
184
+ styleMask: [.titled, .closable, .miniaturizable, .resizable],
185
+ backing: .buffered,
186
+ defer: false
187
+ )
188
+ window.title = "Slack Radar"
189
+ window.contentView = webView
190
+ window.center()
191
+ // Remember size and position across launches, the way a real app does.
192
+ window.setFrameAutosaveName("SlackRadarMainWindow")
193
+ // Match the dashboard's dark --bg so a resize does not flash white behind the content.
194
+ window.backgroundColor = NSColor(red: 0.043, green: 0.059, blue: 0.078, alpha: 1)
195
+ window.makeKeyAndOrderFront(nil)
196
+
197
+ // Minimum that keeps the feed's virtualized columns usable rather than clipped.
198
+ window.minSize = NSSize(width: 900, height: 600)
199
+
200
+ webView.load(URLRequest(url: radarURL))
201
+ NSApp.activate(ignoringOtherApps: true)
202
+ }
203
+
204
+ /// Quit when the window is closed. A dock app with no window and no menu bar presence would
205
+ /// otherwise sit running invisibly, and the next dock click would do nothing at all.
206
+ func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
207
+ return true
208
+ }
209
+
210
+ /// Route anything that is not our own localhost dashboard to the real browser. A Slack or docs
211
+ /// link opened inside this window would strand the user in an app with no back button, no tabs,
212
+ /// and no address bar.
213
+ func webView(
214
+ _ webView: WKWebView,
215
+ decidePolicyFor navigationAction: WKNavigationAction,
216
+ decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
217
+ ) {
218
+ guard let url = navigationAction.request.url else {
219
+ decisionHandler(.allow)
220
+ return
221
+ }
222
+ let isOurs = url.host == radarURL.host && url.port == radarURL.port
223
+ if isOurs || url.scheme == "about" || url.scheme == "data" || url.scheme == "blob" {
224
+ decisionHandler(.allow)
225
+ } else {
226
+ NSWorkspace.shared.open(url)
227
+ decisionHandler(.cancel)
228
+ }
229
+ }
230
+
231
+ /// The screen panel offers a screenshot or a finished recording as a download. WKWebView only
232
+ /// converts a navigation into a WKDownload when SOMETHING tells it to: by default it just loads
233
+ /// the response as the main frame, replacing the whole dashboard with a raw PNG or MP4 and
234
+ /// leaving the user stranded in a window with no back button, no tabs, and no address bar. A
235
+ /// `Content-Disposition: attachment` header is exactly that signal, so check for it here and
236
+ /// hand the response to the download path instead of letting it load as a page.
237
+ func webView(
238
+ _ webView: WKWebView,
239
+ decidePolicyFor navigationResponse: WKNavigationResponse,
240
+ decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void
241
+ ) {
242
+ if let http = navigationResponse.response as? HTTPURLResponse,
243
+ let disposition = http.value(forHTTPHeaderField: "Content-Disposition"),
244
+ disposition.lowercased().hasPrefix("attachment") {
245
+ // Arm a token ONLY for a main-frame diversion. didFail/didFailProvisionalNavigation are
246
+ // top-level-navigation callbacks, so a subframe diversion can never produce the failure a
247
+ // token exists to excuse -- but the token would still sit there for 3s and get consumed by
248
+ // an unrelated main-frame failure that happened to land in that window, swallowing a real
249
+ // dead-server report and leaving the user with no failure page and no Retry. Every download
250
+ // today goes through screen.ts's hidden iframe, so in practice this arms nothing at all and
251
+ // a genuine main-frame failure always reaches the error page.
252
+ //
253
+ // Still a Set rather than a Bool: the per-diversion timer removing only its OWN token is
254
+ // what keeps two overlapping diversions from stealing each other's credit, and that
255
+ // guarantee should not depend on main-frame downloads staying as rare as they are today.
256
+ if navigationResponse.isForMainFrame {
257
+ let token = UUID()
258
+ pendingDownloadInterruptions.insert(token)
259
+ // Primary cleanup, not a rare fallback: even for a main frame, the conversion to a
260
+ // download does not reliably report the underlying cancellation. 3s is far longer than a
261
+ // local download conversion takes to report it on the paths that do.
262
+ DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [weak self] in
263
+ self?.pendingDownloadInterruptions.remove(token)
264
+ }
265
+ }
266
+ decisionHandler(.download)
267
+ } else {
268
+ decisionHandler(.allow)
269
+ }
270
+ }
271
+
272
+ /// Reached once the response above is diverted to a download. Without this delegate WKWebView
273
+ /// silently drops the navigation, so the Save button would do nothing.
274
+ func webView(
275
+ _ webView: WKWebView,
276
+ navigationAction: WKNavigationAction,
277
+ didBecome download: WKDownload
278
+ ) {
279
+ download.delegate = self
280
+ }
281
+
282
+ /// Same conversion, reached when the download starts from a navigation RESPONSE rather than a
283
+ /// user-initiated action (the case above). Both paths can fire depending on how the navigation
284
+ /// began, so both need the delegate wired the same way.
285
+ func webView(
286
+ _ webView: WKWebView,
287
+ navigationResponse: WKNavigationResponse,
288
+ didBecome download: WKDownload
289
+ ) {
290
+ download.delegate = self
291
+ }
292
+
293
+ func download(
294
+ _ download: WKDownload,
295
+ decideDestinationUsing response: URLResponse,
296
+ suggestedFilename: String,
297
+ completionHandler: @escaping (URL?) -> Void
298
+ ) {
299
+ // Straight to ~/Downloads under the server's suggested name, uniquified rather than
300
+ // overwriting: successive screen recordings share a name pattern.
301
+ let dir = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0]
302
+ var dest = dir.appendingPathComponent(suggestedFilename)
303
+ var n = 1
304
+ let ext = dest.pathExtension
305
+ let base = dest.deletingPathExtension().lastPathComponent
306
+ while FileManager.default.fileExists(atPath: dest.path) {
307
+ dest = dir.appendingPathComponent(ext.isEmpty ? "\(base)-\(n)" : "\(base)-\(n).\(ext)")
308
+ n += 1
309
+ }
310
+ downloadDestinations[ObjectIdentifier(download)] = dest
311
+ completionHandler(dest)
312
+ }
313
+
314
+ /// The file is actually on disk now (decideDestinationUsing only picked where it WOULD go).
315
+ /// Tell the page, so it can offer "show in Finder" -- something no plain web page could ever
316
+ /// do on its own, which is why this is a message back into JS rather than page-side logic.
317
+ func downloadDidFinish(_ download: WKDownload) {
318
+ let key = ObjectIdentifier(download)
319
+ guard let dest = downloadDestinations.removeValue(forKey: key) else { return }
320
+ revealablePaths.append(dest.path)
321
+ if revealablePaths.count > maxRevealablePaths {
322
+ revealablePaths.removeFirst(revealablePaths.count - maxRevealablePaths)
323
+ }
324
+ guard let arg = try? JSONSerialization.data(withJSONObject: [dest.path]) else { return }
325
+ let js = "window.__radarDownloadFinished && window.__radarDownloadFinished(\(String(data: arg, encoding: .utf8) ?? "[]")[0])"
326
+ webView.evaluateJavaScript(js)
327
+ }
328
+
329
+ /// A download that fails never finishes, so its entry would otherwise sit in
330
+ /// downloadDestinations forever across a long session. resumeData is ignored on purpose: this
331
+ /// is a debug convenience, not a file manager, and re-requesting a screenshot is instant.
332
+ func download(_ download: WKDownload, didFailWithError error: Error, resumeData: Data?) {
333
+ downloadDestinations.removeValue(forKey: ObjectIdentifier(download))
334
+ }
335
+
336
+ /// Handles the page asking to reveal a saved file. Only ever act on a path THIS app actually
337
+ /// chose as a real download destination, never trust the string the message carries on its
338
+ /// own -- today's page content is same-origin and not attacker-controlled, but Finder access
339
+ /// is exactly the kind of native capability that should not take an unvalidated round trip
340
+ /// through the page at face value when the source of truth already lives right here.
341
+ private func handleRevealMessage(_ message: WKScriptMessage) {
342
+ guard let path = message.body as? String else { return }
343
+ guard revealablePaths.contains(path) else { return }
344
+ NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: path)])
345
+ }
346
+
347
+ /// A failed load is nearly always "the server is not up yet". Show the reason plus the URL rather
348
+ /// than WebKit's bare error page, which does not say what was being reached or how to fix it.
349
+ /// Exception: the cancellation from diverting a response to a download also lands here, and
350
+ /// that one is not a failure at all -- see pendingDownloadInterruptions above.
351
+ func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
352
+ // Any pending token proves SOME diversion is in flight; this callback has no way to tell
353
+ // which one it belongs to (see pendingDownloadInterruptions above), so popping any one token
354
+ // is correct -- they are fungible signals, not identity-correlated to a specific navigation.
355
+ if pendingDownloadInterruptions.popFirst() != nil {
356
+ return
357
+ }
358
+ showLoadFailure(error)
359
+ }
360
+
361
+ func webView(
362
+ _ webView: WKWebView,
363
+ didFailProvisionalNavigation navigation: WKNavigation!,
364
+ withError error: Error
365
+ ) {
366
+ if pendingDownloadInterruptions.popFirst() != nil {
367
+ return
368
+ }
369
+ showLoadFailure(error)
370
+ }
371
+
372
+ private func showLoadFailure(_ error: Error) {
373
+ let html = """
374
+ <html><body style="background:#0b0f14;color:#e8f0f8;font:14px -apple-system,sans-serif;\
375
+ display:flex;align-items:center;justify-content:center;height:100vh;margin:0">
376
+ <div style="max-width:34em;text-align:center">
377
+ <div style="font-size:15px;margin-bottom:.6em">Could not reach the Radar dashboard</div>
378
+ <div style="color:#8aa0b4;line-height:1.6">\(RADAR_URL) did not respond.<br>
379
+ \(error.localizedDescription)<br><br>
380
+ Press the button below, or press &#8984;R once it starts.</div>
381
+ <button onclick="window.webkit.messageHandlers.radarRetry.postMessage('retry')"
382
+ style="margin-top:1em;padding:.5em 1.2em;font:14px -apple-system,sans-serif;\
383
+ background:#39d98a;color:#0b0f14;border:none;border-radius:6px;cursor:pointer">
384
+ Retry</button>
385
+ </div></body></html>
386
+ """
387
+ webView.loadHTMLString(html, baseURL: nil)
388
+ }
389
+
390
+ /// Handles the failure page's Retry button. Runs ensureDashboardRunning() on a background
391
+ /// queue, NOT the main thread: its polling loop sleeps up to ~10s, and calling it here (after
392
+ /// the window already exists) would freeze the whole app, including the button just clicked.
393
+ private func handleRetryMessage() {
394
+ DispatchQueue.global().async {
395
+ ensureDashboardRunning()
396
+ DispatchQueue.main.async {
397
+ self.webView.load(URLRequest(url: radarURL))
398
+ }
399
+ }
400
+ }
401
+
402
+ /// Dispatches to whichever bridge the page called: radarReveal (show a saved file in Finder) or
403
+ /// radarRetry (the failure page's Retry button). Merged into one method because
404
+ /// WKScriptMessageHandler only allows a single conforming method per class -- two separate
405
+ /// declarations here would not compile.
406
+ func userContentController(
407
+ _ userContentController: WKUserContentController,
408
+ didReceive message: WKScriptMessage
409
+ ) {
410
+ switch message.name {
411
+ case "radarReveal": handleRevealMessage(message)
412
+ case "radarRetry": handleRetryMessage()
413
+ default: break
414
+ }
415
+ }
416
+ }
417
+
418
+ // Cmd+R goes home, not just reload. WKWebView has no menu bar here, so the shortcut needs wiring
419
+ // by hand. See the comment inside sendEvent below for why this is the ONLY shortcut here, and why
420
+ // it loads radarURL directly rather than calling webView.reload().
421
+ class ReloadingApplication: NSApplication {
422
+ override func sendEvent(_ event: NSEvent) {
423
+ // Load radarURL directly rather than webView.reload(): reload() repeats whatever is CURRENTLY
424
+ // loaded, which is exactly the page a stranded window needs to get away from, not back to. A
425
+ // second shortcut (originally Cmd+Left) for this used to exist here too, but Cmd+Left is the
426
+ // standard macOS binding for "move cursor to start of line" -- hijacking it at this level,
427
+ // before any focused search or filter field ever sees the key, broke normal text editing
428
+ // anywhere in the dashboard. Cmd+R already covers the "get me back to the dashboard" need
429
+ // without colliding with anything: it has no default text-editing meaning.
430
+ if event.type == .keyDown,
431
+ event.modifierFlags.contains(.command),
432
+ event.charactersIgnoringModifiers?.lowercased() == "r",
433
+ let delegate = self.delegate as? AppDelegate {
434
+ delegate.webView.load(URLRequest(url: radarURL))
435
+ return
436
+ }
437
+ super.sendEvent(event)
438
+ }
439
+ }
440
+
441
+ // Start the server BEFORE the window exists so the first load lands on a live port instead of an
442
+ // error page the user has to reload past.
443
+ ensureDashboardRunning()
444
+ // Spawned and forgotten: fixes today's staleness for the NEXT launch, never this one.
445
+ triggerSelfHealCheck()
446
+
447
+ let app = ReloadingApplication.shared
448
+ // .regular is what puts the app in the dock and lets it own a real window. The default for a
449
+ // bare binary is .prohibited, which would show no dock icon at all.
450
+ app.setActivationPolicy(.regular)
451
+
452
+ // A bare binary like this one has no storyboard, so nothing builds the app menu that a normal
453
+ // app gets for free. Without it, Cmd+Q has no "Quit" menu item to route to and silently does
454
+ // nothing; the only way to close was the window's own red button. One item is enough here, this
455
+ // app has no other menu-worthy actions.
456
+ let mainMenu = NSMenu()
457
+ let appMenuItem = NSMenuItem()
458
+ mainMenu.addItem(appMenuItem)
459
+ let appMenu = NSMenu()
460
+ appMenu.addItem(NSMenuItem(title: "Quit Slack Radar", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
461
+ appMenuItem.submenu = appMenu
462
+ app.mainMenu = mainMenu
463
+
464
+ let delegate = AppDelegate()
465
+ app.delegate = delegate
466
+ app.run()
@@ -0,0 +1,40 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" role="img" aria-label="Slack Radar">
2
+ <!-- Source of truth for every raster icon; scripts/make-icons.mjs rasterizes this.
3
+ Colors are the dashboard's own dark-theme tokens (bg #0b0f14, accent #39d98a, blue
4
+ #6cb6ff) so the dock icon matches the window it opens. Hard-coded rather than var()
5
+ because an icon renders outside the page and cannot inherit the stylesheet.
6
+
7
+ NO gradients, on purpose. ImageMagick's built-in SVG reader ignores radialGradient and
8
+ filled the sweep solid black; flat layered wedges fake the angular falloff and render
9
+ the same in every renderer. -->
10
+
11
+ <rect width="512" height="512" rx="112" fill="#0b0f14"/>
12
+ <circle cx="256" cy="256" r="176" fill="#101a24"/>
13
+
14
+ <!-- Range rings. Stroke widths grow outward so the dish reads as depth, not flat rings. -->
15
+ <g fill="none" stroke="#39d98a" stroke-opacity=".30">
16
+ <circle cx="256" cy="256" r="56" stroke-width="6"/>
17
+ <circle cx="256" cy="256" r="112" stroke-width="7"/>
18
+ <circle cx="256" cy="256" r="168" stroke-width="8"/>
19
+ </g>
20
+
21
+ <!-- Crosshairs, dimmer than the rings so they sit behind the sweep. -->
22
+ <g stroke="#39d98a" stroke-opacity=".16" stroke-width="6">
23
+ <line x1="256" y1="80" x2="256" y2="432"/>
24
+ <line x1="80" y1="256" x2="432" y2="256"/>
25
+ </g>
26
+
27
+ <!-- The sweep, leading edge at ~2 o'clock trailing back to 12. Three nested wedges share the
28
+ leading edge and narrow toward it, so their overlap brightens where the beam just passed
29
+ and thins out behind it. -->
30
+ <g fill="#39d98a">
31
+ <path d="M256 256 L256 88 A168 168 0 0 1 401.5 172 Z" fill-opacity=".10"/>
32
+ <path d="M256 256 L340 110.5 A168 168 0 0 1 401.5 172 Z" fill-opacity=".14"/>
33
+ <path d="M256 256 L374.8 137.2 A168 168 0 0 1 401.5 172 Z" fill-opacity=".20"/>
34
+ </g>
35
+ <path d="M256 256 L401.5 172" stroke="#39d98a" stroke-width="10" stroke-linecap="round"/>
36
+
37
+ <!-- Blips: a bright contact the beam is passing now, a cooler one already behind it. -->
38
+ <circle cx="348" cy="179" r="19" fill="#39d98a"/>
39
+ <circle cx="186" cy="322" r="13" fill="#6cb6ff" fill-opacity=".85"/>
40
+ </svg>
@@ -282,6 +282,34 @@
282
282
  .dbout th { position:sticky; top:0; background:var(--surface); color:var(--muted-2); text-align:left; padding:7px 10px; border-bottom:1px solid var(--border); white-space:nowrap; }
283
283
  .dbout td { padding:6px 10px; border-bottom:1px solid var(--rowline); max-width:380px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
284
284
  .dbout tr:hover td { background:var(--hover); }
285
+ .dbout tr { cursor:pointer; }
286
+ .dbout tr.rowsel td { background:var(--sel-soft); }
287
+ /* DB row detail panel -- docked right of the grid; the split shrinks the grid to make room.
288
+ Mirrors the feed's .stage.split + .inspector layout. */
289
+ .dbsplit { flex:1; min-height:0; display:flex; gap:14px; align-items:stretch; }
290
+ .dbsplit .dbout { flex:1; min-width:0; }
291
+ .dbsplit.open .dbout { flex:2 1 0; }
292
+ .rowinspector { flex:1 1 360px; min-width:300px; max-width:520px; overflow:auto; background:var(--surface-2); border:1px solid var(--border); border-radius:10px; padding:12px 14px; }
293
+ .rowinspector .inspector-hd { display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:8px; }
294
+ .rowinspector .inspector-hd .ttl { color:var(--text); font-size:13px; font-weight:600; word-break:break-word; }
295
+ .rowinspector .inspector-hd .x { cursor:pointer; color:var(--muted-2); border:1px solid var(--border-3); border-radius:6px; padding:1px 8px; flex:0 0 auto; }
296
+ .rowinspector .inspector-hd .x:hover { color:var(--error); border-color:var(--error); }
297
+ .rowfield { border:1px solid var(--border); border-radius:8px; margin-bottom:8px; overflow:hidden; }
298
+ .rowfield-hd { display:flex; align-items:center; gap:8px; padding:6px 10px; background:var(--surface-2); border-bottom:1px solid var(--border); }
299
+ .rowfield-k { font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:var(--muted-2); font-weight:600; word-break:break-all; }
300
+ .rowfield-v { padding:8px 10px; font-size:12px; line-height:1.45; color:var(--text-2); white-space:pre-wrap; word-break:break-word; }
301
+ /* collapsible JSON tree */
302
+ .jtree { padding:6px 4px 8px; font-family:ui-monospace,Menlo,Consolas,monospace; font-size:12px; line-height:1.5; }
303
+ .jrow { display:flex; align-items:flex-start; gap:4px; white-space:pre-wrap; word-break:break-word; }
304
+ .jnode > .jrow { cursor:pointer; border-radius:4px; }
305
+ .jnode > .jrow:hover { background:var(--hover); }
306
+ .jcaret { color:var(--muted); width:11px; flex:0 0 auto; }
307
+ .jleaf { padding-left:0; } .jclose { color:var(--muted-2); }
308
+ .jsummary { color:var(--muted-2); }
309
+ .j-punc { color:var(--muted-2); }
310
+ .jtree-copy { margin-left:auto; color:var(--muted); font-family:inherit; font-size:10.5px; text-transform:uppercase; letter-spacing:.05em; cursor:pointer; opacity:0; flex:0 0 auto; padding-left:8px; }
311
+ .jrow:hover .jtree-copy, .rowfield-hd:hover .jtree-copy { opacity:1; }
312
+ .jtree-copy:hover { color:var(--accent); }
285
313
  /* Prefs browser: mirrors db.ts CSS, same visual language */
286
314
  .prefsview { display:flex; gap:16px; max-width:1180px; margin-top:8px; height:72vh; }
287
315
  .prefsside { flex:0 0 260px; overflow:auto; border:1px solid var(--border); border-radius:10px; padding:12px; }
@@ -364,7 +392,19 @@
364
392
  #screenpanel .sctitle { font-size:12.5px; color:var(--text); font-weight:600; flex:1; }
365
393
  #screenpanel .scbtn { background:var(--surface); border:1px solid var(--border-2); color:var(--muted-2); border-radius:6px; padding:3px 9px; font:inherit; font-size:11.5px; cursor:pointer; } #screenpanel .scbtn:hover { border-color:var(--accent); color:var(--text); } #screenpanel .scbtn.rec { color:var(--error); border-color:var(--error); }
366
394
  #screenimg { width:100%; border:1px solid var(--border); border-radius:8px; background:#000; min-height:120px; }
367
- #schint { font-size:11.5px; color:var(--muted); margin-top:8px; line-height:1.5; }
395
+ #schint { font-size:11.5px; color:var(--muted); margin-bottom:8px; line-height:1.5; }
396
+ /* Floating save confirmation. Lives outside the docked side panel on purpose: the panel is
397
+ only 340px wide and clipped to the right edge, and closing it (which auto-saves a running
398
+ recording) unmounts it entirely, so anything panel-local can be invisible exactly when it
399
+ matters most. Bottom-center and transient. Ignores clicks unless it has a saved file to
400
+ reveal, which is the one case the rule below opts into. */
401
+ #radartoast { position:fixed; left:50%; bottom:28px; transform:translateX(-50%) translateY(8px); background:var(--surface); border:1px solid var(--accent); color:var(--text); border-radius:8px; padding:8px 16px; font-size:12.5px; box-shadow:0 4px 16px var(--shadow); z-index:70; opacity:0; pointer-events:none; transition:opacity .15s ease, transform .15s ease; }
402
+ #radartoast.on { opacity:1; transform:translateX(-50%) translateY(0); }
403
+ /* Only a save confirmation that actually has a file to reveal takes clicks. The default
404
+ stays pointer-events:none above, because a toast floats over rows the user is clicking
405
+ and must not swallow those clicks -- and every toast except this one has nothing to
406
+ click anyway, so an always-on hit area would only ever eat input. */
407
+ #radartoast.on.clickable { pointer-events:auto; cursor:pointer; }
368
408
  .scconsent { background:var(--surface); border:1px solid var(--border-3); border-radius:8px; padding:12px; font-size:12px; color:var(--text-2); line-height:1.55; } .scconsent b { color:var(--warn-2); }
369
409
  .scconsent .scaccept { background:var(--accent-bg); border:1px solid var(--accent); color:var(--accent-text); border-radius:6px; padding:6px 14px; font:inherit; font-size:12px; cursor:pointer; margin-top:10px; display:block; } .scconsent .scaccept:hover { filter:brightness(1.1); }
370
410
  .scinstall { background:var(--surface-2); border:1px solid var(--border); border-radius:6px; padding:8px 10px; margin-top:8px; font-size:11.5px; color:var(--text-2); } .scinstall code { color:var(--copybtn-fg); }
@@ -55,6 +55,7 @@ function Header({ screenOpen, onScreenToggle }) {
55
55
  const conn = useStoreValue(store, "conn", () => store.conn);
56
56
  const profile = useStoreValue(store, "profile", () => store.profileLabel);
57
57
  const version = useStoreValue(store, "version", () => store.serverVersion);
58
+ const selfHeal = useStoreValue(store, "self-heal", () => store.selfHeal);
58
59
  const stopped = useStoreValue(store, "stopped", () => store.stopped);
59
60
  const [busy, setBusy] = useState(false);
60
61
  const [killing, setKilling] = useState(false);
@@ -122,6 +123,8 @@ function Header({ screenOpen, onScreenToggle }) {
122
123
  <button class=${"screenbtn" + (screenOpen ? " on" : "")} onClick=${onScreenToggle} title="Mirror the live device screen">▣ Screen</button>
123
124
  <button class=${"themebtn killbtn" + (killArmed ? " armed" : "")} disabled=${killing} onClick=${kill} title=${killArmed ? "Click again to confirm" : "Stop the dashboard server"}>${killing ? "⏻ stopping…" : killArmed ? "⏻ Confirm stop?" : "⏻ Stop dashboard"}</button>
124
125
  ${version ? html `<span class="version" title="Version of the dashboard process. It can differ from your Claude Code MCP session if a dashboard from an earlier launch still holds the port; restart the dashboard to match.">v${version}</span>` : null}
126
+ ${selfHeal?.outcome === "updated" ? html `<span class="version" title="Radar self-healed to a newer version on this launch">↑ updated to v${selfHeal.toVersion}</span>` : null}
127
+ ${selfHeal?.outcome === "error" ? html `<span class="conn waiting" title=${"The dock launcher's self-heal check failed: " + (selfHeal.error || "unknown error") + ". Log: ~/Library/Logs/slack-radar-dashboard.log"}>⚠ self-heal check failed</span>` : null}
125
128
  </h1>
126
129
  `;
127
130
  }