@slack/radar-mcp 1.14.0 → 1.17.1

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 (49) 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 +105 -37
  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/mcp/web-child-env.d.ts +1 -0
  16. package/dist/mcp/web-child-env.js +32 -0
  17. package/dist/shared/android.d.ts +89 -1
  18. package/dist/shared/android.js +352 -78
  19. package/dist/shared/constants.d.ts +25 -1
  20. package/dist/shared/constants.js +27 -1
  21. package/dist/shared/db.js +11 -2
  22. package/dist/shared/debug-log.js +6 -1
  23. package/dist/shared/enable-diagnosis.d.ts +28 -0
  24. package/dist/shared/enable-diagnosis.js +41 -0
  25. package/dist/shared/prefs.d.ts +0 -5
  26. package/dist/shared/prefs.js +6 -2
  27. package/dist/shared/screen.d.ts +46 -9
  28. package/dist/shared/screen.js +74 -11
  29. package/dist/shared/transport.d.ts +62 -5
  30. package/dist/shared/webapp.d.ts +50 -0
  31. package/dist/shared/webapp.js +65 -0
  32. package/dist/web/bin.js +5 -1
  33. package/dist/web/install-app.d.ts +87 -0
  34. package/dist/web/install-app.js +703 -0
  35. package/dist/web/macapp/RadarApp.swift +466 -0
  36. package/dist/web/public/icons/radar-1024.png +0 -0
  37. package/dist/web/public/icons/radar.svg +40 -0
  38. package/dist/web/public/index.html +41 -1
  39. package/dist/web/public/next/app.js +19 -4
  40. package/dist/web/public/next/db.js +145 -5
  41. package/dist/web/public/next/feed.js +18 -0
  42. package/dist/web/public/next/hooks.js +10 -1
  43. package/dist/web/public/next/registry.js +18 -10
  44. package/dist/web/public/next/screen.js +147 -43
  45. package/dist/web/public/next/store.js +393 -51
  46. package/dist/web/public/next/toast.js +134 -0
  47. package/dist/web/server.d.ts +26 -1
  48. package/dist/web/server.js +341 -113
  49. package/package.json +2 -2
@@ -0,0 +1,134 @@
1
+ // A small floating confirmation, shown for anything the user needs a moment to notice and then
2
+ // forget (a save, e.g.). Deliberately plain DOM, not a Preact component: the whole point is that
3
+ // it survives regardless of what any particular panel is doing, including a panel that unmounts
4
+ // itself right after triggering the action (the screen overlay returns null when closed, so a
5
+ // confirmation living inside it can never render at the one moment auto-save needs it most).
6
+ const finishListeners = new Set();
7
+ /**
8
+ * Called from the packaged dock app's native side (RadarApp.swift) once a WKDownload actually
9
+ * finishes, with the REAL on-disk path. The filename Radar guesses client-side before the
10
+ * download even starts is not necessarily final -- the app uniquifies a colliding name -- so
11
+ * "where did it save" can only be answered after the fact, from the native side that chose the
12
+ * destination. Never invoked in a plain browser tab: there is no bridge there, so this global is
13
+ * simply never called, and every listener below just never fires, which is correct -- a web page
14
+ * cannot reveal a file in Finder no matter what UI it draws.
15
+ *
16
+ * Uses globalThis, not the bare `window` identifier: this line runs at module load, and Node's
17
+ * test harness for this file installs a stand-in `window` by CALLING a setup function after
18
+ * imports resolve, not before -- referencing `window` directly here would throw before that
19
+ * setup ever runs. globalThis always exists in both Node and a real browser, and in a real
20
+ * browser globalThis IS window, so Swift's `window.__radarDownloadFinished(...)` call still
21
+ * finds this unchanged.
22
+ */
23
+ globalThis.__radarDownloadFinished = (path) => {
24
+ finishListeners.forEach((cb) => cb(path));
25
+ };
26
+ /** Subscribe to native download-finished notifications. Returns an unsubscribe function. */
27
+ export function onDownloadFinished(cb) {
28
+ finishListeners.add(cb);
29
+ return () => finishListeners.delete(cb);
30
+ }
31
+ export function revealInFinder(path) {
32
+ const w = globalThis;
33
+ w.webkit?.messageHandlers?.radarReveal?.postMessage(path);
34
+ }
35
+ /**
36
+ * Does `downloadedPath` hold the capture the server named as `expectedFile`?
37
+ *
38
+ * The two names are usually equal -- /screen/download sends the capture's own basename as its
39
+ * Content-Disposition filename, and that is what the native side receives as the suggested name.
40
+ * They differ when ~/Downloads already holds that name: decideDestinationUsing in RadarApp.swift
41
+ * uniquifies as "<stem>-N.<ext>" rather than overwriting. So exact equality alone would drop the
42
+ * reveal offer on exactly the re-download it was added for, and a bare "any path will do" accepts
43
+ * an earlier save's file. Accepting the name plus its uniquified forms is the narrow middle.
44
+ *
45
+ * Capture names are `radar_screen_<ISO timestamp>.<ext>` with a fixed-width timestamp, so no
46
+ * capture's stem can be another's stem followed by "-N": the suffix cannot collide with a real
47
+ * name.
48
+ */
49
+ export function isCaptureDownloadMatch(downloadedPath, expectedFile) {
50
+ const base = downloadedPath.split("/").pop() ?? "";
51
+ if (!base || !expectedFile)
52
+ return false;
53
+ if (base === expectedFile)
54
+ return true;
55
+ const dot = expectedFile.lastIndexOf(".");
56
+ if (dot <= 0)
57
+ return false;
58
+ const stem = expectedFile.slice(0, dot);
59
+ const ext = expectedFile.slice(dot);
60
+ if (!base.startsWith(stem) || !base.endsWith(ext))
61
+ return false;
62
+ const middle = base.slice(stem.length, base.length - ext.length);
63
+ return /^-\d+$/.test(middle);
64
+ }
65
+ let toastTimer = null;
66
+ // The capture the toast on screen is waiting on, or null when it is not waiting on one. Holding
67
+ // the FILE rather than a boolean is what lets the listener below tell "this save's download
68
+ // landed" from "some earlier save's download landed while this toast happens to be up".
69
+ let awaitedFile = null;
70
+ /**
71
+ * Show a confirmation with no file behind it: a failure, or any plain status line. Leaves the
72
+ * toast unclickable and shuts the reveal gate, so a late download-finished path from an earlier
73
+ * save cannot attach itself to this message.
74
+ */
75
+ export function showToast(message) {
76
+ paint(message);
77
+ awaitedFile = null;
78
+ }
79
+ /**
80
+ * Show a save confirmation and accept a reveal offer for `file` specifically -- the name the
81
+ * server reported for THIS save.
82
+ */
83
+ export function showSaveToast(message, file) {
84
+ paint(message);
85
+ awaitedFile = file;
86
+ }
87
+ function paint(message) {
88
+ let el = document.getElementById("radartoast");
89
+ if (!el) {
90
+ el = document.createElement("div");
91
+ el.id = "radartoast";
92
+ document.body.appendChild(el);
93
+ }
94
+ el.textContent = message;
95
+ // "clickable" is dropped along with the reveal wiring: this toast has no file yet, and the
96
+ // class is what lets it take clicks at all (the base rule is pointer-events:none so a toast
97
+ // never swallows a click meant for a row underneath it).
98
+ el.className = "on";
99
+ // Clear any reveal wiring from a PREVIOUS save so this toast cannot end up pointing at the
100
+ // wrong file if this save's own confirmation is still in flight.
101
+ el.onclick = null;
102
+ el.title = "";
103
+ if (toastTimer)
104
+ clearTimeout(toastTimer);
105
+ const target = el;
106
+ toastTimer = setTimeout(() => {
107
+ target.className = "";
108
+ // A toast that has faded is no longer waiting on anything, so a path arriving after it must
109
+ // not re-arm a toast a later message has since taken over.
110
+ awaitedFile = null;
111
+ }, 4000);
112
+ }
113
+ // Single persistent listener: the toast on screen becomes clickable once the download IT is
114
+ // waiting on actually finishes. Registered once at module load rather than per paint() call, since
115
+ // a toast's own lifetime (4s) can easily be shorter than the round trip to the native side and
116
+ // back for a real recording.
117
+ //
118
+ // Both guards are load-bearing. Without the awaitedFile check this wired reveal onto whichever
119
+ // toast merely had class "on", so a failure toast could offer to reveal an earlier capture; the
120
+ // base rule's pointer-events:none hid that until the clickable state made the handler reachable.
121
+ // Matching the path as well as checking for one keeps a slow first download from attaching itself
122
+ // to the second save's confirmation.
123
+ onDownloadFinished((path) => {
124
+ const el = document.getElementById("radartoast");
125
+ if (!el || !el.classList.contains("on"))
126
+ return;
127
+ if (!awaitedFile || !isCaptureDownloadMatch(path, awaitedFile))
128
+ return;
129
+ // Adding the class is what makes the handler reachable. Setting onclick alone did nothing:
130
+ // the base rule's pointer-events:none meant the element never received the click.
131
+ el.classList.add("clickable");
132
+ el.title = "Click to show in Finder";
133
+ el.onclick = () => revealInFinder(path);
134
+ });
@@ -1,4 +1,5 @@
1
1
  import http from "http";
2
+ import type { ProcessState } from "../shared/transport.js";
2
3
  import { type LogFrame } from "./log-session.js";
3
4
  import { stopRecording, getLive } from "../shared/screen.js";
4
5
  declare const WEB_PORT: number;
@@ -113,6 +114,30 @@ interface ShutdownDeps {
113
114
  export declare function shutdownDashboard(server: {
114
115
  close(cb?: () => void): void;
115
116
  }, deps?: ShutdownDeps): Promise<void>;
117
+ /**
118
+ * Arm Radar once, at dashboard boot, so a launch against a freshly restarted app does not land on
119
+ * "waiting for device" until the human finds the Reconnect button. Called by bin.ts from the listen
120
+ * callback, for the same reason startAutoCloseSweep is: only the process that actually WON the port
121
+ * may touch the device, so a second launcher that adopts a running dashboard never re-arms someone
122
+ * else's session.
123
+ *
124
+ * The work itself runs OFF the event loop entirely (see armDevice), because an
125
+ * attached-but-unauthorised or locked device can hold a single adb call at its 5 second ceiling,
126
+ * and a chain of them can run 15 seconds or more. A server that cannot answer meanwhile breaks
127
+ * the adopt path this file otherwise protects carefully: a second launcher hits EADDRINUSE,
128
+ * probes the loopback /spec with a 2 second timeout to recognise this dashboard, and declares
129
+ * the port foreign and exits if that probe does not answer.
130
+ *
131
+ * NOT routed through handleEnable, which is written around an HTTP response. Two of the steps it
132
+ * additionally performs really are no-ops in a fresh process (resetState and resetDbState only clear
133
+ * in-process fields that are already at their defaults), but two are NOT, and this is deliberately
134
+ * left as a known gap rather than claimed away: resetScreenState() kills orphaned device-side
135
+ * screenrecord processes left by a crashed prior dashboard, and the switched-device branch
136
+ * (cleanupPulledDatabases + logSession.restart) is gated on a serial inherited from the environment,
137
+ * so a boot carrying a stale ANDROID_SERIAL can legitimately be a switch. Pressing Reconnect still
138
+ * performs both. If a third step is ever needed here, extract the shared core instead of copying it.
139
+ */
140
+ export declare function armOnBoot(): void;
116
141
  /**
117
142
  * Start the periodic auto-close sweep. Called once by bin.ts AFTER a successful listen bind, not
118
143
  * from createServer, so importing this module (or spinning a throwaway server in a test) never
@@ -175,7 +200,7 @@ export declare function isOpenToAnyCaller(urlPath: string, method: string | unde
175
200
  * would just get a 403 with nothing to do about it.
176
201
  */
177
202
  export declare function isLocalHostHeader(host: string | string[] | undefined, allowedHosts?: string | undefined): boolean;
178
- export declare function enableResultBody(enabled: boolean, onEnabled?: () => void): {
203
+ export declare function enableResultBody(enabled: boolean, onEnabled?: () => void, processState?: ProcessState): {
179
204
  enabled: boolean;
180
205
  error?: string;
181
206
  };