@slack/radar-mcp 1.22.0 → 1.23.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.
@@ -571,6 +571,13 @@ function buildIcns(resourcesDir) {
571
571
  fs.rmSync(iconset, { recursive: true, force: true });
572
572
  }
573
573
  }
574
+ // buildSwiftApp()'s compile is the one step in here that can be slow for a structural reason, and it
575
+ // is bounded at 60s by its own execFileSync timeout, which leaves about 60s of slack against this
576
+ // threshold. The rest is unbounded but local and sub-second in practice (sips, iconutil, lsregister).
577
+ // A lock older than this can only be a crash leftover, the process that made it died before reaching
578
+ // the finally below. Without this, one crashed install would wedge every self-heal check forever,
579
+ // since nothing else ever removes the lock file.
580
+ const STALE_LOCK_MS = 2 * 60 * 1000;
574
581
  /**
575
582
  * Create (or replace) the launcher app. Returns its path.
576
583
  *
@@ -596,13 +603,6 @@ export function installMacApp() {
596
603
  // staging path -- for the self-heal caller that just means trying again next launch.
597
604
  fs.mkdirSync(dir, { recursive: true });
598
605
  const lockPath = path.join(dir, ".install.lock");
599
- // buildSwiftApp()'s compile is the one step in here that can be slow for a structural reason, and it
600
- // is bounded at 60s by its own execFileSync timeout, which leaves about 60s of slack against this
601
- // threshold. The rest is unbounded but local and sub-second in practice (sips, iconutil, lsregister).
602
- // A lock older than this can only be a crash leftover, the process that made it died before reaching
603
- // the finally below. Without this, one crashed install would wedge every self-heal check forever,
604
- // since nothing else ever removes the lock file.
605
- const STALE_LOCK_MS = 2 * 60 * 1000;
606
606
  let lockFd;
607
607
  try {
608
608
  lockFd = fs.openSync(lockPath, "wx");
@@ -1061,3 +1061,56 @@ export async function runSelfHealPrecheckAsync() {
1061
1061
  writeSelfHealState({ checkedAt, outcome: "error", toVersion: RADAR_VERSION, error: e.message });
1062
1062
  }
1063
1063
  }
1064
+ /** Whether the registry has a newer Radar than the installed app, or the installed app is already
1065
+ * ahead of `runningVersion` and just needs a restart. Never throws; failures land in `error`. */
1066
+ export async function checkForUpdate(runningVersion = "unknown") {
1067
+ const read = readInstalledVersion();
1068
+ if (!read.found) {
1069
+ return { installed: null, latest: null, updateAvailable: false, error: "Slack Radar.app is not installed" };
1070
+ }
1071
+ if ((compareVersions(read.plain, runningVersion.split(/[-+]/, 1)[0]) ?? 0) > 0) {
1072
+ return { installed: read.version, latest: null, updateAvailable: false, restartAvailable: true };
1073
+ }
1074
+ const latest = await checkLatestPublishedVersion();
1075
+ if (latest === null) {
1076
+ return { installed: read.version, latest: null, updateAvailable: false, error: "could not reach the npm registry" };
1077
+ }
1078
+ const comparison = compareVersions(latest, read.plain);
1079
+ return { installed: read.version, latest, updateAvailable: comparison !== null && comparison > 0 };
1080
+ }
1081
+ /** Entry point for `install-app --update-now`. Reuses the self-heal rebuild, so an explicit update
1082
+ * stays subject to the same npm config as the background one. */
1083
+ export async function runUpdateNow() {
1084
+ const startedAt = new Date().toISOString();
1085
+ const before = readInstalledVersion();
1086
+ const running = (process.env.RADAR_APP_VERSION ?? "").split(/[-+]/, 1)[0];
1087
+ // Updated means newer than the running app, or than the copy before the install when no version was baked in.
1088
+ const base = parseVersion(running) ? running : before.found ? before.plain : null;
1089
+ const isUpdated = (r) => r.found && base !== null && (compareVersions(r.plain, base) ?? 0) > 0;
1090
+ await runSelfHealPrecheckAsync();
1091
+ let after = readInstalledVersion();
1092
+ // A fresh lock means the launch self-heal beat our rebuild to it, so wait for it to finish.
1093
+ const lock = path.join(appDir(), ".install.lock");
1094
+ while (!isUpdated(after) && Date.now() - (fs.statSync(lock, { throwIfNoEntry: false })?.mtimeMs ?? 0) < STALE_LOCK_MS) {
1095
+ await new Promise((resolve) => setTimeout(resolve, 250));
1096
+ after = readInstalledVersion();
1097
+ }
1098
+ const result = { updated: isUpdated(after) };
1099
+ if (!result.updated) {
1100
+ const state = readSelfHealState();
1101
+ const recorded = state && state.checkedAt >= startedAt && state.outcome === "error" ? state.error : undefined;
1102
+ if (recorded !== undefined) {
1103
+ result.error = recorded;
1104
+ }
1105
+ else {
1106
+ // No recorded error: the rebuild resolved a version equal to what's already installed, the
1107
+ // signature of an npm min-release-age hold. Confirm against the registry before naming it.
1108
+ const latest = after.found ? await checkLatestPublishedVersion() : null;
1109
+ result.error =
1110
+ after.found && latest !== null && (compareVersions(latest, after.plain) ?? 0) > 0
1111
+ ? `Your npm config may be holding Radar back on ${after.version}. The published version is ${latest}.`
1112
+ : "The app was not updated. See ~/Library/Logs/slack-radar-dashboard.log for the log.";
1113
+ }
1114
+ }
1115
+ console.log(JSON.stringify(result));
1116
+ }
@@ -1436,11 +1436,47 @@ func triggerSelfHealCheck() {
1436
1436
  }
1437
1437
  }
1438
1438
 
1439
+ /// Runs `install-app <flag>` from the installed Radar and returns the JSON object it printed as its
1440
+ /// last line, or nil on failure. Blocks (drains the pipe before waiting), so call it off the main thread.
1441
+ func runInstalledRadar(_ flag: String) -> [String: Any]? {
1442
+ guard let node = resolveNodePath(RADAR_NODE) else {
1443
+ appendLaunchLog("update: node was not at the baked path \(RADAR_NODE), cannot run \(flag).")
1444
+ return nil
1445
+ }
1446
+ let task = Process()
1447
+ task.executableURL = URL(fileURLWithPath: node)
1448
+ task.arguments = [RADAR_MCP_BIN, "install-app", flag]
1449
+ var env = ProcessInfo.processInfo.environment
1450
+ env["SLACK_RADAR_WEB_PORT"] = String(radarPort)
1451
+ env["RADAR_APP_VERSION"] = RADAR_APP_VERSION
1452
+ task.environment = env
1453
+ let output = Pipe()
1454
+ task.standardOutput = output
1455
+ task.standardError = radarLogHandle() ?? FileHandle.nullDevice
1456
+ do {
1457
+ try task.run()
1458
+ } catch {
1459
+ appendLaunchLog("update: could not start \(flag): \(error)")
1460
+ return nil
1461
+ }
1462
+ let data = output.fileHandleForReading.readDataToEndOfFile()
1463
+ task.waitUntilExit()
1464
+ radarLogHandle()?.write(data)
1465
+ guard let text = String(data: data, encoding: .utf8),
1466
+ let line = text.split(separator: "\n").last(where: { $0.hasPrefix("{") }),
1467
+ let object = try? JSONSerialization.jsonObject(with: Data(line.utf8)) as? [String: Any]
1468
+ else {
1469
+ appendLaunchLog("update: \(flag) printed no JSON result.")
1470
+ return nil
1471
+ }
1472
+ return object
1473
+ }
1474
+
1439
1475
  /// The launch attempt that runs before the window exists (see the bottom of this file), whose load is
1440
1476
  /// the window's first.
1441
1477
  let firstLaunch = LaunchTicket()
1442
1478
 
1443
- class AppDelegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKDownloadDelegate, WKScriptMessageHandler {
1479
+ class AppDelegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKDownloadDelegate, WKScriptMessageHandler, NSMenuItemValidation {
1444
1480
  var window: NSWindow!
1445
1481
  var webView: WKWebView!
1446
1482
  // The load that ended a launch attempt, and which attempt that was: the only navigation that
@@ -1535,6 +1571,114 @@ class AppDelegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKDown
1535
1571
  NSApp.activate(ignoringOtherApps: true)
1536
1572
  }
1537
1573
 
1574
+ // Main thread only. Keeps a second click from starting a second check or install while one is running.
1575
+ private var updateInProgress = false
1576
+
1577
+ func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
1578
+ if menuItem.action == #selector(checkForUpdates(_:)) { return !updateInProgress }
1579
+ return true
1580
+ }
1581
+
1582
+ @objc func checkForUpdates(_ sender: Any?) {
1583
+ updateInProgress = true
1584
+ DispatchQueue.global().async {
1585
+ let check = runInstalledRadar("--check-update")
1586
+ DispatchQueue.main.async { self.presentUpdateCheck(check) }
1587
+ }
1588
+ }
1589
+
1590
+ /// Ends an update attempt (including a successful "up to date" check) with a one-button alert.
1591
+ /// Capitalizes detail's first letter once here, so a lowercase error reads right either way.
1592
+ private func endUpdate(_ message: String, _ detail: String) {
1593
+ updateInProgress = false
1594
+ let alert = NSAlert()
1595
+ alert.messageText = message
1596
+ alert.informativeText = detail.prefix(1).uppercased() + detail.dropFirst()
1597
+ alert.addButton(withTitle: "OK")
1598
+ alert.runModal()
1599
+ }
1600
+
1601
+ /// A two-button yes/no alert, shared by the restart and the install confirmations below.
1602
+ private func confirm(_ title: String, _ detail: String, _ button: String) -> Bool {
1603
+ let alert = NSAlert()
1604
+ alert.messageText = title
1605
+ alert.informativeText = detail
1606
+ alert.addButton(withTitle: button)
1607
+ alert.addButton(withTitle: "Not Now")
1608
+ return alert.runModal() == .alertFirstButtonReturn
1609
+ }
1610
+
1611
+ private func presentUpdateCheck(_ check: [String: Any]?) {
1612
+ guard let check = check else {
1613
+ endUpdate("Could not check for updates", "Radar could not run its update check. See ~/Library/Logs/slack-radar-dashboard.log for the log.")
1614
+ return
1615
+ }
1616
+ if let error = check["error"] as? String {
1617
+ endUpdate("Could not check for updates", error)
1618
+ return
1619
+ }
1620
+ let installed = check["installed"] as? String ?? "unknown"
1621
+ // The launch-time self-heal already rebuilt the installed bundle while this window kept running
1622
+ // the older build it launched with: no install needed, just a restart to pick it up.
1623
+ if check["restartAvailable"] as? Bool == true {
1624
+ guard confirm("Slack Radar \(installed) is already installed", "A background update already finished. Restart to use it now?", "Restart Now") else {
1625
+ updateInProgress = false
1626
+ return
1627
+ }
1628
+ relaunch()
1629
+ return
1630
+ }
1631
+ guard check["updateAvailable"] as? Bool == true, let latest = check["latest"] as? String else {
1632
+ endUpdate("Slack Radar is up to date", "You have the latest version (\(installed)).")
1633
+ return
1634
+ }
1635
+ let detail = "You have \(installed). Install the update now? Radar will restart when it finishes."
1636
+ guard confirm("Slack Radar \(latest) is available", detail, "Install and Restart") else {
1637
+ updateInProgress = false
1638
+ return
1639
+ }
1640
+ installUpdate()
1641
+ }
1642
+
1643
+ /// A minimal sheet so Install shows something for the up-to-a-minute rebuild instead of going
1644
+ /// quiet until it relaunches or fails. No real buttons: the hidden one just lets NSAlert show.
1645
+ private func installUpdate() {
1646
+ let progress = NSAlert()
1647
+ progress.messageText = "Installing Slack Radar"
1648
+ progress.informativeText = "This can take a minute."
1649
+ progress.addButton(withTitle: "OK")
1650
+ progress.buttons[0].isHidden = true
1651
+ progress.beginSheetModal(for: window, completionHandler: nil)
1652
+ DispatchQueue.global().async {
1653
+ let result = runInstalledRadar("--update-now")
1654
+ DispatchQueue.main.async {
1655
+ self.window.endSheet(progress.window)
1656
+ if result?["updated"] as? Bool == true {
1657
+ self.relaunch()
1658
+ return
1659
+ }
1660
+ self.endUpdate("Update failed", result?["error"] as? String ?? "Radar could not run the installer.")
1661
+ }
1662
+ }
1663
+ }
1664
+
1665
+ /// Starts a fresh copy once this one has exited, waiting on our pid so the quit finishes first.
1666
+ private func relaunch() {
1667
+ let helper = Process()
1668
+ helper.executableURL = URL(fileURLWithPath: "/bin/sh")
1669
+ helper.arguments = [
1670
+ "-c", "while kill -0 \"$1\" 2>/dev/null; do sleep 0.2; done; /usr/bin/open \"$2\"",
1671
+ "sh", String(ProcessInfo.processInfo.processIdentifier), Bundle.main.bundlePath,
1672
+ ]
1673
+ do {
1674
+ try helper.run()
1675
+ } catch {
1676
+ endUpdate("Updated but could not restart", "Quit Slack Radar and open it again to use the new version.")
1677
+ return
1678
+ }
1679
+ NSApp.terminate(nil)
1680
+ }
1681
+
1538
1682
  /// Quit when the window is closed. A dock app with no window and no menu bar presence would
1539
1683
  /// otherwise sit running invisibly, and the next dock click would do nothing at all.
1540
1684
  func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
@@ -1997,6 +2141,8 @@ let mainMenu = NSMenu()
1997
2141
  let appMenuItem = NSMenuItem()
1998
2142
  mainMenu.addItem(appMenuItem)
1999
2143
  let appMenu = NSMenu()
2144
+ appMenu.addItem(NSMenuItem(title: "Check for Updates…", action: #selector(AppDelegate.checkForUpdates(_:)), keyEquivalent: ""))
2145
+ appMenu.addItem(NSMenuItem.separator())
2000
2146
  appMenu.addItem(NSMenuItem(title: "Quit Slack Radar", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
2001
2147
  appMenuItem.submenu = appMenu
2002
2148
  let editMenuItem = NSMenuItem()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slack/radar-mcp",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "description": "MCP server and web dashboard for debugging Slack on Android and iOS Simulator",
5
5
  "type": "module",
6
6
  "main": "dist/mcp/index.js",