@slack/radar-mcp 1.10.0 → 1.12.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.
@@ -11,6 +11,74 @@ export const localRtmBuffer = [];
11
11
  let streamConnection = null;
12
12
  let streamConnected = false;
13
13
  const eventWaiters = [];
14
+ // Reconnect cadence. A plain retry reuses the existing adb forward; every other
15
+ // attempt rebuilds it, because a forward whose device end died is not revived by
16
+ // waiting (the stream would retry into a dead socket forever). Mirrors the web
17
+ // stream proxy's cadence (src/web/server.ts).
18
+ const RETRY_DELAY_MS = 2000;
19
+ const REBUILD_RETRY_DELAY_MS = 1500;
20
+ // Failures since the last successful connect; drives the every-other-attempt
21
+ // rebuild. The pending reconnect timer is held module-level so destroyStream()
22
+ // can cancel it: an intentional teardown (disable, enable-restart) must stop
23
+ // the loop, or it resurrects the stream the user just closed.
24
+ let reconnectAttempts = 0;
25
+ let reconnectTimer = null;
26
+ /**
27
+ * Decide whether this reconnect attempt rebuilds the adb forward, perform the
28
+ * rebuild if so, and return the delay before the next connect. Does not call
29
+ * setTimeout itself so the decision is unit-testable without a live socket.
30
+ *
31
+ * Prefers dropForward() (drops only the cached forward flag) over resetState()
32
+ * so a rebuild does not wipe the detected user id mid-session: a full reset
33
+ * followed by a re-detect while the app process is down would rebind the
34
+ * session to user 0, losing a work-profile binding.
35
+ *
36
+ * @param t transport whose forward may be stale
37
+ * @param attempt 1-based failure count since the last successful connect
38
+ */
39
+ export function planReconnect(t, attempt) {
40
+ if (attempt % 2 === 0) {
41
+ if (t.dropForward) {
42
+ t.dropForward();
43
+ }
44
+ else {
45
+ t.resetState();
46
+ }
47
+ t.ensureForward();
48
+ return REBUILD_RETRY_DELAY_MS;
49
+ }
50
+ return RETRY_DELAY_MS;
51
+ }
52
+ // Schedule the next reconnect attempt. Stale-callback dedup happens at the
53
+ // call sites (the failure handlers no-op unless their request still owns
54
+ // streamConnection), so by the time this runs the disconnect is real. The
55
+ // timer callback keeps the loop alive when a rebuild attempt could not
56
+ // restore the forward (device unplugged): connectStream would early-return
57
+ // on !isForwarded() and the loop would otherwise die permanently, leaving
58
+ // the stream down even after the device comes back.
59
+ function scheduleReconnect() {
60
+ // Never leave a previous timer untracked: if a second chain schedules while
61
+ // one is pending, overwriting the ref would orphan the first timer beyond
62
+ // destroyStream()'s reach, and it would resurrect the stream after a
63
+ // deliberate teardown. The connectStream guard makes this near-unreachable;
64
+ // this is the backstop.
65
+ if (reconnectTimer)
66
+ clearTimeout(reconnectTimer);
67
+ streamConnection = null;
68
+ streamConnected = false;
69
+ reconnectAttempts++;
70
+ const delay = transport
71
+ ? planReconnect(transport, reconnectAttempts)
72
+ : RETRY_DELAY_MS;
73
+ reconnectTimer = setTimeout(() => {
74
+ reconnectTimer = null;
75
+ if (transport && !transport.isForwarded()) {
76
+ scheduleReconnect();
77
+ return;
78
+ }
79
+ connectStream();
80
+ }, delay);
81
+ }
14
82
  // Fires once after a RECONNECT (not the first connect), so the owner can backfill the device ring
15
83
  // rows the ~2s gap dropped. index.ts sets it to the backfill; unset it is a no-op, so the web
16
84
  // server (which shares this module) and tests are unaffected. hasConnectedOnce gates it to a true
@@ -52,7 +120,21 @@ export function clearLocalBuffers() {
52
120
  export function getStreamConnection() {
53
121
  return streamConnection;
54
122
  }
123
+ /**
124
+ * Deliberate teardown: destroy the live stream AND stop the reconnect loop.
125
+ * Cancelling the pending timer matters as much as the destroy — without it a
126
+ * disable (or an enable-restart) leaves a timer that resurrects the stream
127
+ * seconds later, refilling buffers the caller just cleared and churning adb
128
+ * forward rebuilds against a session the user turned off. The destroyed
129
+ * request's own async failure events are ignored by the ownership check in
130
+ * connectStream's handlers (they no longer own streamConnection).
131
+ */
55
132
  export function destroyStream() {
133
+ if (reconnectTimer) {
134
+ clearTimeout(reconnectTimer);
135
+ reconnectTimer = null;
136
+ }
137
+ reconnectAttempts = 0;
56
138
  if (streamConnection) {
57
139
  streamConnection.destroy();
58
140
  streamConnection = null;
@@ -132,10 +214,33 @@ export function waitForEvents({ event_type, channel, source, timeout_ms = 30000,
132
214
  });
133
215
  }
134
216
  export function connectStream() {
135
- if (streamConnection || !transport?.isForwarded())
217
+ // The reconnectTimer check keeps an external caller (a tool call landing in
218
+ // the gap between a drop and the scheduled retry) from opening a competing
219
+ // request: scheduleReconnect nulls streamConnection, so without this the
220
+ // call would slip past the first check, and its failure would schedule a
221
+ // second timer chain. The loop itself is unaffected: the timer callback
222
+ // nulls reconnectTimer before calling here.
223
+ if (streamConnection || reconnectTimer || !transport?.isForwarded())
136
224
  return;
225
+ // Ownership guard shared by all three failure callbacks of this request. A
226
+ // destroyed request emits its failure events asynchronously (verified: res
227
+ // "error"/"aborted" fire a tick after destroy()), so by the time a stale
228
+ // callback runs, a NEWER healthy stream may own streamConnection. Without
229
+ // this check the stale callback would null the live stream (orphaning it,
230
+ // still buffering, no longer reachable by destroyStream) and schedule a
231
+ // duplicate connect: two live streams double-delivering every event. The
232
+ // guard also dedups the three callbacks of one failed attempt: the first to
233
+ // run hands ownership to scheduleReconnect, the rest see a mismatch.
234
+ const fail = () => {
235
+ if (streamConnection !== req)
236
+ return;
237
+ scheduleReconnect();
238
+ };
137
239
  const req = http.get({ host: RADAR_HOST, port: RADAR_PORT, path: "/api/stream", timeout: 0 }, (res) => {
138
240
  streamConnected = true;
241
+ // Connected cleanly, so the next disconnect starts its rebuild cadence
242
+ // from attempt 1 rather than inheriting a counter grown across the session.
243
+ reconnectAttempts = 0;
139
244
  // Fire the reconnect hook on a true reconnect (not the first connect). Kept in its own fn so
140
245
  // the logic is unit-testable without a live socket.
141
246
  noteStreamConnected();
@@ -156,21 +261,9 @@ export function connectStream() {
156
261
  }
157
262
  }
158
263
  });
159
- res.on("end", () => {
160
- streamConnection = null;
161
- streamConnected = false;
162
- setTimeout(connectStream, 2000);
163
- });
164
- res.on("error", () => {
165
- streamConnection = null;
166
- streamConnected = false;
167
- setTimeout(connectStream, 2000);
168
- });
169
- });
170
- req.on("error", () => {
171
- streamConnection = null;
172
- streamConnected = false;
173
- setTimeout(connectStream, 2000);
264
+ res.on("end", fail);
265
+ res.on("error", fail);
174
266
  });
267
+ req.on("error", fail);
175
268
  streamConnection = req;
176
269
  }
@@ -13,6 +13,18 @@ export interface LogResult {
13
13
  lines: string[];
14
14
  source: LogSource;
15
15
  }
16
+ /**
17
+ * One attached device as reported by the platform's device listing. serial is the
18
+ * stable id used to target a specific device (Android: `adb -s <serial>`); label is a
19
+ * human-readable name (device model) falling back to the serial; state is the raw
20
+ * connection state ("device", "offline", "unauthorized"). Only state "device" entries
21
+ * are selectable.
22
+ */
23
+ export interface DeviceInfo {
24
+ serial: string;
25
+ label: string;
26
+ state: string;
27
+ }
16
28
  export interface DeviceTransport {
17
29
  /** Human-readable platform name (e.g. "android", "ios"). */
18
30
  readonly platform: string;
@@ -30,6 +42,31 @@ export interface DeviceTransport {
30
42
  activate(timeoutMinutes: number): void;
31
43
  /** Reset all connection state (forwarding, activation, caches). */
32
44
  resetState(): void;
45
+ /**
46
+ * Drop only the cached forwarding state so the next ensureForward() rebuilds
47
+ * the mapping, keeping activation state and the detected user id intact.
48
+ * Reconnect paths use this instead of resetState(): a full reset mid-session
49
+ * would force a user re-detect that can rebind a work-profile session to
50
+ * user 0 while the app process is briefly down. Optional; callers fall back
51
+ * to resetState() when absent.
52
+ */
53
+ dropForward?(): void;
54
+ /**
55
+ * Re-issue the adb forward for this process's pinned device, UNCONDITIONALLY --
56
+ * unlike ensureForward(), a cached "already forwarded" is not trusted. The forward
57
+ * this MCP process set up is host-global (keyed by local port only), and a SEPARATE
58
+ * process on the same host (the web dashboard) can repoint that same port to a
59
+ * different device at any time via its own selectDevice call. That process's repoint
60
+ * does not touch this process's `portForwarded` cache, so a plain ensureForward()
61
+ * would skip re-forwarding and this session would silently start reading the other
62
+ * process's device over its HTTP-based tools while its direct-adb tools (which honor
63
+ * process.env.ANDROID_SERIAL per-call, not the shared port) keep reading the correct
64
+ * one -- a split-brain within one MCP session. Call this immediately before every
65
+ * device HTTP read so the shared port is always pointed at OUR pinned serial first.
66
+ * Optional; platforms without a shared host-level forward may omit it, and callers
67
+ * fall back to ensureForward() when absent.
68
+ */
69
+ reassertForward?(): boolean;
33
70
  /** Whether forwarding has been established. */
34
71
  isForwarded(): boolean;
35
72
  /** Current auto-shutdown timeout in minutes. */
@@ -89,6 +126,15 @@ export interface DeviceTransport {
89
126
  * "device not connected" message. Optional; implementations may omit it.
90
127
  */
91
128
  getLastForwardError?(): string | null;
129
+ /**
130
+ * Returns the error message from the last `activate()` attempt, or null if the
131
+ * last attempt succeeded or none has happened. activate() itself never throws
132
+ * (a failed broadcast is expected when no device is attached), so this is the
133
+ * only way callers can tell "activated" from "broadcast never landed" and
134
+ * report a real error instead of a silently dead session. Optional;
135
+ * implementations may omit it.
136
+ */
137
+ getLastActivateError?(): string | null;
92
138
  /**
93
139
  * Returns the path of the session-scoped log capture file, or null if no
94
140
  * capture is running. Surfaced in tool responses so the model can reason
@@ -115,4 +161,44 @@ export interface DeviceTransport {
115
161
  * @param timeoutMinutes Auto-shutdown timeout in minutes
116
162
  */
117
163
  activateForUser?(userId: string, timeoutMinutes: number): void;
164
+ /**
165
+ * List the devices currently attached to the host. Android runs `adb devices -l`;
166
+ * iOS and test fakes may omit it (single-device or no listing support). Selection
167
+ * treats an absent listing as "cannot tell", not "no devices", so existing flows
168
+ * that fake adb without `devices -l` support stay a no-op.
169
+ */
170
+ listDevices?(): DeviceInfo[] | null;
171
+ /**
172
+ * Pick which attached device every later adb call targets, for the whole session.
173
+ * Selection is transport-owned (not the enable body's job) because only the transport
174
+ * knows how targeting works on its platform: on Android this pins process.env.ANDROID_SERIAL
175
+ * once, and every adb call site inherits it, so no per-call-site plumbing is needed.
176
+ *
177
+ * @param serial An explicit device serial to target, or null to auto-select (keep a
178
+ * sticky prior pin if still attached, else the sole attached device).
179
+ * @returns ok:true with the pinned serial (null when nothing could be selected and the
180
+ * downstream forward path reports no-device on its own), or ok:false with a
181
+ * human-readable error plus the device list when the choice is ambiguous or the
182
+ * requested serial is not attached. switched is true when this pin differs from the
183
+ * session's prior device: a switch invalidates device-scoped session state, and the
184
+ * orchestrator owns the reset.
185
+ */
186
+ selectDevice?(serial: string | null): {
187
+ ok: true;
188
+ serial: string | null;
189
+ switched?: boolean;
190
+ } | {
191
+ ok: false;
192
+ error: string;
193
+ devices: DeviceInfo[];
194
+ };
195
+ /**
196
+ * The device pinned by the last successful selectDevice, or null when none is pinned.
197
+ * The enable body and the web /health response surface this so a user can see which
198
+ * hardware the session is bound to. Optional; single-device platforms may omit it.
199
+ */
200
+ getSelectedDevice?(): {
201
+ serial: string;
202
+ label: string;
203
+ } | null;
118
204
  }
@@ -67,6 +67,19 @@ export declare class LogSession {
67
67
  start(): boolean;
68
68
  /** Stop the capture and drop the child. The ring buffer is preserved. */
69
69
  stop(): void;
70
+ /**
71
+ * Stop the capture AND drop the retained ring, for when the underlying device
72
+ * actually changed (PR #94 multi-device switch), not just dropped transiently.
73
+ * stop() alone preserves the ring by design (a transient adb-server hiccup or
74
+ * device unplug/replug is the SAME device coming back, so its history is still
75
+ * valid and should survive) -- but a switch to DIFFERENT hardware means every
76
+ * retained frame belongs to the wrong device, and replaying them into a freshly
77
+ * opened /stream on the new device would show device A's logs mislabeled as
78
+ * device B's. The caller (handleEnable's switched branch) is responsible for
79
+ * calling armLogcat() / start() again afterward if a log tab is active; this
80
+ * method only tears down, matching stop()'s existing division of labor.
81
+ */
82
+ restart(): void;
70
83
  /**
71
84
  * Install process-exit handlers (once) so the persistent `adb logcat` child is
72
85
  * killed when the server process exits. Without this, the capture orphans when
@@ -75,6 +75,22 @@ export class LogSession {
75
75
  }
76
76
  }
77
77
  }
78
+ /**
79
+ * Stop the capture AND drop the retained ring, for when the underlying device
80
+ * actually changed (PR #94 multi-device switch), not just dropped transiently.
81
+ * stop() alone preserves the ring by design (a transient adb-server hiccup or
82
+ * device unplug/replug is the SAME device coming back, so its history is still
83
+ * valid and should survive) -- but a switch to DIFFERENT hardware means every
84
+ * retained frame belongs to the wrong device, and replaying them into a freshly
85
+ * opened /stream on the new device would show device A's logs mislabeled as
86
+ * device B's. The caller (handleEnable's switched branch) is responsible for
87
+ * calling armLogcat() / start() again afterward if a log tab is active; this
88
+ * method only tears down, matching stop()'s existing division of labor.
89
+ */
90
+ restart() {
91
+ this.stop();
92
+ this.ring.length = 0;
93
+ }
78
94
  /**
79
95
  * Install process-exit handlers (once) so the persistent `adb logcat` child is
80
96
  * killed when the server process exits. Without this, the capture orphans when
@@ -56,13 +56,16 @@
56
56
  .reconnect { background:var(--surface); border:1px solid var(--warn); color:var(--warn); border-radius:8px; padding:4px 12px; font:inherit; font-size:12px; font-weight:600; cursor:pointer; }
57
57
  .reconnect:hover { border-color:var(--warn-2); } .reconnect:disabled { opacity:.6; cursor:default; }
58
58
  .profilewrap { font-size:12px; color:var(--blue-2); } .profilewrap b { color:var(--text); }
59
+ .profilewrap select { background:var(--surface); border:1px solid var(--border-2); border-radius:6px; color:var(--text); padding:3px 6px; font:inherit; font-size:11px; margin-left:4px; cursor:pointer; }
60
+ h1 .version { margin-left:auto; font-size:11px; font-weight:400; color:var(--muted-2); letter-spacing:0; }
59
61
  .themebtn, .screenbtn { background:var(--surface); border:1px solid var(--border-2); color:var(--muted-2); border-radius:8px; padding:5px 12px; font:inherit; font-size:12.5px; cursor:pointer; }
60
62
  .themebtn:hover, .screenbtn:hover { border-color:var(--accent); color:var(--text); } .screenbtn.on { background:var(--accent-bg); border-color:var(--accent); color:var(--accent-text); }
61
- .modebar { display:flex; gap:6px; margin:0 0 6px; flex-wrap:wrap; flex:0 0 auto; }
63
+ .modebar { display:flex; gap:6px; margin:0 0 6px; flex-wrap:wrap; flex:0 0 auto; align-items:center; }
62
64
  .modebtn { background:var(--surface); border:1px solid var(--border-2); color:var(--muted-2); border-radius:8px; padding:6px 14px; font:inherit; font-size:12.5px; cursor:pointer; }
63
65
  .modebtn:hover { border-color:var(--accent); color:var(--text); }
64
66
  .modebtn.active { background:var(--accent-bg); border-color:var(--accent); color:var(--accent-text); font-weight:600; }
65
67
  .modebtn.custom { margin-left:10px; border-style:dashed; color:var(--purple); } .modebtn.custom.active { background:var(--accent-bg); border-color:var(--purple); color:var(--purple); }
68
+ .modedivider { width:1px; height:20px; background:var(--border-2); margin:0 4px; }
66
69
  .sub { margin:0 0 6px; flex:0 0 auto; } .sub .summary { display:block; color:var(--text-2); font-size:12px; font-weight:600; } .sub .tech { display:none; }
67
70
  /* filters — slim when collapsed */
68
71
  .filters { max-width:1100px; margin-bottom:6px; flex:0 0 auto; }
@@ -121,11 +124,59 @@
121
124
  .stage.split .feedwrap-next { flex:2 1 380px; min-width:0; } .stage.split .inspector { flex:1 1 300px; }
122
125
  .feedwrap-next { flex:1; min-width:0; display:flex; flex-direction:column; min-height:0; }
123
126
  .feedbar { display:flex; gap:8px; align-items:center; margin-bottom:8px; flex-wrap:wrap; flex:0 0 auto; }
124
- .ffilterwrap { position:relative; flex:1; display:flex; min-width:140px; } .ffilterwrap .ffilter { flex:1; padding-right:26px; }
127
+ /* Filter box: pills + draft input wrap together in one field-shaped container (Android
128
+ Studio Logcat style). The wrap owns the border + padding + focus ring; the input inside
129
+ is chromeless so pills + draft read as one control. Pills flex-wrap onto more lines when
130
+ the query is long. */
131
+ .ffilterwrap { position:relative; flex:1; display:flex; flex-wrap:wrap; align-items:center; gap:5px; min-width:140px; background:var(--surface-2); border:1px solid var(--border-2); border-radius:8px; padding:4px 26px 4px 6px; cursor:text; }
132
+ .ffilterwrap:focus-within { border-color:var(--accent); }
133
+ .ffilterwrap .ffilter { flex:1; min-width:80px; background:transparent; border:none; padding:3px 4px; font:inherit; font-size:12.5px; color:var(--text); }
134
+ .ffilterwrap .ffilter:focus { outline:none; }
125
135
  .feedbar input { background:var(--surface-2); border:1px solid var(--border-2); border-radius:8px; color:var(--text); padding:7px 10px; font:inherit; font-size:12.5px; }
126
136
  .feedbar input:focus { outline:none; border-color:var(--accent); }
127
- .ffilterclear { position:absolute; right:8px; top:50%; transform:translateY(-50%); cursor:pointer; color:var(--muted-2); background:var(--surface); border-radius:50%; width:16px; height:16px; line-height:14px; text-align:center; font-size:10px; }
137
+ .ffilterclear { position:absolute; right:8px; top:9px; cursor:pointer; color:var(--muted-2); background:var(--surface); border-radius:50%; width:16px; height:16px; line-height:14px; text-align:center; font-size:10px; }
128
138
  .ffilterclear:hover { color:#fff; background:var(--error-2); }
139
+ /* The draft input turns amber when its own text is an invalid regex mid-typing. Committed
140
+ terms use the per-pill amber (.fpill-bad) instead. */
141
+ .ffilterwrap:has(.ffilter.finvalid) { border-color:var(--warn); }
142
+ /* Fallback for browsers without :has(): the wrap keeps its normal border and the draft
143
+ amber shows on the input itself via a bottom border. */
144
+ .feedbar input.ffilter.finvalid { box-shadow:inset 0 -2px 0 var(--warn); }
145
+ /* Pills. Compact rounded chip inside the wrap; regex pills stay monospace so slashes read
146
+ as syntax. Every pill uses the same base padding + font-size as the input so the row
147
+ lines up visually. */
148
+ .fpill { display:inline-flex; align-items:center; gap:4px; background:var(--surface); border:1px solid var(--border-3); color:var(--text); border-radius:6px; padding:1px 4px 1px 7px; font-size:12.5px; line-height:1.4; max-width:340px; cursor:pointer; }
149
+ .fpill:hover { border-color:var(--accent); }
150
+ .fpill:focus-visible { outline:2px solid var(--accent); outline-offset:1px; }
151
+ .fpill-body { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
152
+ .fpill-sign { color:var(--muted-2); font-weight:700; margin-right:1px; }
153
+ .fpill-x { cursor:pointer; color:var(--muted-2); background:var(--surface-3); border-radius:50%; width:14px; height:14px; line-height:13px; text-align:center; font-size:9.5px; margin-left:2px; }
154
+ .fpill-x:hover { color:#fff; background:var(--error-2); }
155
+ .fpill-neg { background:var(--lvl-err-bg); border-color:var(--error-2); color:var(--error-2); }
156
+ .fpill-neg .fpill-sign { color:var(--error-2); }
157
+ .fpill-re, .fpill-quote { font-family:ui-monospace,Menlo,Consolas,monospace; }
158
+ .fpill-bad { background:var(--lvl-warn-bg); border-color:var(--warn); color:var(--warn-2); }
159
+ /* Kind-name pills on the Live view. Match the row's type chip color so "clog" reads the
160
+ same whether you see it in the pill or in the row's tchip. */
161
+ .fpill-kind-network { background:var(--chip-net-bg); border-color:var(--blue); color:var(--blue); }
162
+ .fpill-kind-rtm { background:var(--chip-rtm-bg); border-color:var(--purple); color:var(--purple); }
163
+ .fpill-kind-clog { background:var(--chip-clog-bg); border-color:var(--accent); color:var(--accent); }
164
+ .fpill-kind-trace { background:var(--chip-trace-bg); border-color:var(--warn); color:var(--warn); }
165
+ .fpill-kind-log { background:var(--chip-log-bg); border-color:var(--chip-log-fg); color:var(--chip-log-fg); }
166
+ /* A negated kind pill (e.g. -log) carries BOTH .fpill-neg and .fpill-kind-* at once; equal
167
+ specificity means whichever rule is defined later in the stylesheet wins, which happened
168
+ to be the kind color, burying the negation-red the "-" glyph is there to signal. The
169
+ compound selector below outranks the plain .fpill-kind-* rules so negated-red always wins
170
+ the background, regardless of source order. */
171
+ .fpill-neg.fpill-kind-network,
172
+ .fpill-neg.fpill-kind-rtm,
173
+ .fpill-neg.fpill-kind-clog,
174
+ .fpill-neg.fpill-kind-trace,
175
+ .fpill-neg.fpill-kind-log {
176
+ background: var(--lvl-err-bg);
177
+ border-color: var(--error-2);
178
+ color: var(--error-2);
179
+ }
129
180
  .fbtn { background:var(--surface); border:1px solid var(--border-3); border-radius:8px; color:var(--text); padding:6px 10px; font:inherit; font-size:12px; cursor:pointer; white-space:nowrap; }
130
181
  .fbtn:hover { border-color:var(--accent); } .fbtn:disabled { opacity:.4; cursor:default; } .fbtn.paused { color:var(--warn); border-color:var(--warn); }
131
182
  .fcount { color:var(--muted); font-size:11.5px; white-space:nowrap; }
@@ -230,6 +281,60 @@
230
281
  .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; }
231
282
  .dbout td { padding:6px 10px; border-bottom:1px solid var(--rowline); max-width:380px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
232
283
  .dbout tr:hover td { background:var(--hover); }
284
+ /* Prefs browser: mirrors db.ts CSS, same visual language */
285
+ .prefsview { display:flex; gap:16px; max-width:1180px; margin-top:8px; height:72vh; }
286
+ .prefsside { flex:0 0 260px; overflow:auto; border:1px solid var(--border); border-radius:10px; padding:12px; }
287
+ .prefssec { color:var(--muted); font-size:10.5px; text-transform:uppercase; letter-spacing:.06em; margin:6px 0 6px; } .prefssec:not(:first-child){ margin-top:14px; }
288
+ .prefsitem { padding:6px 9px; border-radius:7px; cursor:pointer; font-size:12.5px; display:flex; align-items:center; gap:6px; }
289
+ /* The filename is the ONLY element that shrinks/truncates -- min-width:0 is load-bearing in a
290
+ flex row (without it a child never shrinks below its content size, so overflow:hidden does
291
+ nothing and the row just clips everything past the sidebar edge, size span included). The
292
+ size/badge stay flex-shrink:0 so they are always visible regardless of filename length. */
293
+ .prefsitem .prefsitemname { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
294
+ .prefsitem:hover { background:var(--hover-soft); } .prefsitem.sel { background:var(--sel-soft); color:var(--accent); } .prefsitem .size { color:var(--muted); font-size:11px; flex-shrink:0; } .prefsitem .ffbadge { color:var(--accent); font-size:10px; font-weight:600; flex-shrink:0; }
295
+ .prefsitem.kbd { outline:2px solid var(--accent); outline-offset:-2px; }
296
+ /* Near-empty files (a handful of scalar entries at most) fade back so attention goes to the
297
+ files actually worth opening; still fully visible and clickable, just de-emphasized. */
298
+ .prefsitem.tiny { color:var(--muted); } .prefsitem.tiny .size { opacity:.7; }
299
+ .prefsmain { flex:1; min-width:0; display:flex; flex-direction:column; }
300
+ /* The search bar gets its own bordered/tinted container, set apart from the results below it
301
+ (.prefsout), so it reads as "search every file" rather than looking like a header row glued
302
+ to whichever file happens to be selected. */
303
+ .prefssearchbar { background:var(--surface-2); border:1px solid var(--border); border-radius:10px; padding:9px 11px; margin-bottom:10px; }
304
+ .prefssearchlabel { color:var(--muted); font-size:10px; text-transform:uppercase; letter-spacing:.06em; margin-bottom:6px; }
305
+ .prefssearch { display:flex; gap:8px; }
306
+ .prefssearch input { flex:1; background:var(--surface); border:1px solid var(--border-2); border-radius:8px; color:var(--text); padding:8px 11px; font:inherit; font-size:12.5px; } .prefssearch input:focus { outline:none; border-color:var(--accent); }
307
+ .prefssearch button { background:var(--accent-bg); border:1px solid var(--accent); color:var(--accent-text); border-radius:8px; padding:0 16px; font:inherit; font-size:12.5px; font-weight:600; cursor:pointer; display:flex; align-items:center; gap:6px; }
308
+ .prefssearch button:disabled { opacity:.7; cursor:default; }
309
+ .spinner { display:inline-block; width:11px; height:11px; border:2px solid currentColor; border-right-color:transparent; border-radius:50%; animation:prefsspin .7s linear infinite; }
310
+ @keyframes prefsspin { to { transform:rotate(360deg); } }
311
+ .prefsmeta { color:var(--muted); font-size:11.5px; margin-bottom:8px; }
312
+ .prefsprivacy { background:var(--lvl-warn-bg); border:1px solid var(--warn); color:var(--warn-2); border-radius:8px; padding:8px 11px; font-size:11.5px; line-height:1.5; margin-bottom:10px; }
313
+ .prefsprofile { color:var(--blue-2); font-size:11.5px; margin-bottom:8px; } .prefsprofile b { color:var(--text); }
314
+ .prefsprofcap { color:var(--muted); text-transform:uppercase; letter-spacing:.06em; font-size:10px; }
315
+ .prefsprofile select { background:var(--surface); border:1px solid var(--border-2); border-radius:6px; color:var(--text); padding:3px 6px; font:inherit; font-size:11px; margin-left:4px; }
316
+ .prefsrefresh { background:var(--surface); border:1px solid var(--border-3); border-radius:6px; color:var(--muted-2); padding:2px 8px; font:inherit; font-size:11px; cursor:pointer; margin-left:8px; } .prefsrefresh:hover { border-color:var(--accent); color:var(--accent); }
317
+ .prefsout { flex:1; overflow:auto; border:1px solid var(--border); border-radius:10px; }
318
+ .prefsout table { border-collapse:collapse; width:100%; font-size:12px; }
319
+ .prefsout 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; }
320
+ .prefsout td { padding:6px 10px; border-bottom:1px solid var(--rowline); max-width:380px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; } .prefsout td.val { font-family:monospace; font-size:11.5px; cursor:pointer; }
321
+ .prefsout tr:hover td { background:var(--hover); }
322
+ .prefsout td.val:hover { color:var(--accent); }
323
+ .prefsout td.val.open { color:var(--accent); font-weight:600; }
324
+ /* Expanded value row: a full pretty-printed value below the clicked row, for values the
325
+ column truncates (JSON blobs like navigation_history/experiment_data routinely run past
326
+ 380px with no other way to read or select the rest). */
327
+ .valexpand td { background:var(--surface-2); padding:10px; border-bottom:1px solid var(--rowline); white-space:normal; max-width:none; }
328
+ .valexpandbar { display:flex; gap:8px; margin-bottom:8px; }
329
+ .valexpandbar button { background:var(--surface); border:1px solid var(--border-3); border-radius:6px; color:var(--muted-2); padding:3px 10px; font:inherit; font-size:11px; cursor:pointer; } .valexpandbar button:hover { border-color:var(--accent); color:var(--accent); }
330
+ .valpretty { margin:0; white-space:pre-wrap; word-break:break-word; font-size:11.5px; line-height:1.45; color:var(--text-2); max-height:300px; overflow:auto; }
331
+ .truncwarn { background:var(--lvl-info-bg); border:1px solid var(--blue); color:var(--blue); border-radius:8px; padding:8px 11px; font-size:11.5px; margin-bottom:10px; }
332
+ /* Stronger treatment for the "no matches" case where files were skipped -- a search that
333
+ could not read anything is a different severity than one that read everything and found
334
+ nothing, so it must not share the same quiet blue "fyi" styling as a partial skip. */
335
+ .truncwarn.err { background:var(--lvl-warn-bg); border-color:var(--warn); color:var(--warn-2); }
336
+ .searchgroup { margin-bottom:16px; }
337
+ .searchfile { color:var(--muted-2); font-size:11px; font-weight:600; padding:6px 10px; background:var(--surface); border-radius:6px; margin-bottom:8px; }
233
338
  .msg { color:var(--muted); font-size:12px; padding:10px; } .msg.err { color:var(--error); }
234
339
  /* screen overlay */
235
340
  #screenpanel { position:fixed; top:0; right:0; bottom:0; width:340px; background:var(--surface-2); border-left:1px solid var(--border); z-index:40; display:flex; flex-direction:column; padding:12px; box-shadow:-4px 0 16px var(--shadow); overflow:auto; }
@@ -9,11 +9,13 @@ import { render } from "preact";
9
9
  import { useState, useEffect, useCallback } from "preact/hooks";
10
10
  import { useStoreValue } from "./hooks.js";
11
11
  import { store, MODES, describeConstraints } from "./store.js";
12
+ import { SOURCES } from "./registry.js";
12
13
  import { Feed } from "./feed.js";
13
14
  import { Cards } from "./widgets.js";
14
15
  import { Inspector } from "./inspector.js";
15
16
  import { Filters } from "./filters.js";
16
17
  import { DbBrowser } from "./db.js";
18
+ import { PrefsBrowser } from "./prefs.js";
17
19
  import { ScreenOverlay } from "./screen.js";
18
20
  function readTheme() {
19
21
  try {
@@ -23,9 +25,35 @@ function readTheme() {
23
25
  return "dark";
24
26
  }
25
27
  }
28
+ // Header device picker. With 2+ attached devices it is a dropdown of the ready ones (state
29
+ // "device"), current one selected; picking one pins it via store.selectDevice. With 0 or 1
30
+ // device it is a plain chip (the bound label, or "none"). Mirrors the DB browser's profile
31
+ // chip/select pattern (.dbprofile) rather than reinventing markup.
32
+ function DeviceChip() {
33
+ const devices = useStoreValue(store, "devices", () => store.devices);
34
+ const ready = devices.filter((d) => d.state === "device");
35
+ const selected = store.selectedDevice;
36
+ // Unpinned with exactly one ready device: bare adb targets that device anyway, so name it
37
+ // instead of claiming "none". "none" is reserved for genuinely nothing attached.
38
+ const label = selected?.label ?? (ready.length === 1 ? ready[0].label : "none");
39
+ // A device-select failure (e.g. an ambiguous /enable 409). Shown in warn styling next to the
40
+ // picker, which stays usable so the user can pick a valid device (a successful pick clears it).
41
+ const deviceError = store.deviceError;
42
+ if (store.devicesError) {
43
+ return html `<span class="profilewrap" title="adb devices failed; check adb">device: <b>adb error</b></span>`;
44
+ }
45
+ const picker = ready.length < 2
46
+ ? html `<b>${label}</b>`
47
+ : html `<select onChange=${(e) => store.selectDevice(e.currentTarget.value)}>
48
+ ${!selected ? html `<option value="" selected disabled>pick a device…</option>` : null}
49
+ ${ready.map((d) => html `<option value=${d.serial} selected=${d.serial === selected?.serial}>${d.label} (${d.serial})</option>`)}
50
+ </select>`;
51
+ return html `<span class="profilewrap" title="the device Radar is bound to; pick another to switch">device: ${picker}${deviceError ? html `<span class="conn waiting" style="margin-left:6px">${deviceError}</span>` : null}</span>`;
52
+ }
26
53
  function Header({ screenOpen, onScreenToggle }) {
27
54
  const conn = useStoreValue(store, "conn", () => store.conn);
28
55
  const profile = useStoreValue(store, "profile", () => store.profileLabel);
56
+ const version = useStoreValue(store, "version", () => store.serverVersion);
29
57
  const [busy, setBusy] = useState(false);
30
58
  const [theme, setTheme] = useState(readTheme);
31
59
  const reconnect = useCallback(async () => {
@@ -50,9 +78,11 @@ function Header({ screenOpen, onScreenToggle }) {
50
78
  SLACK RADAR DASHBOARD
51
79
  <span class=${"conn " + conn.state}>${connected ? "● live" : "● " + (conn.msg || "reconnecting…")}</span>
52
80
  <span class="profilewrap" title="the device profile Radar is connected to (first app to launch wins the socket)">profile: <b>${profile}</b></span>
81
+ <${DeviceChip} />
53
82
  ${!connected ? html `<button class="reconnect" disabled=${busy} onClick=${reconnect}>${busy ? "⟳ enabling…" : "⟳ Reconnect Radar"}</button>` : null}
54
83
  <button class="themebtn" onClick=${toggleTheme} title="Toggle light / dark theme">${theme === "light" ? "🌙 Dark" : "☀ Light"}</button>
55
84
  <button class=${"screenbtn" + (screenOpen ? " on" : "")} onClick=${onScreenToggle} title="Mirror the live device screen">▣ Screen</button>
85
+ ${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}
56
86
  </h1>
57
87
  `;
58
88
  }
@@ -61,9 +91,14 @@ function ModeBar() {
61
91
  useEffect(() => store.on("spec", () => force((n) => n + 1)), []);
62
92
  const activeKey = store.activeModeKey();
63
93
  const pick = (specToPush) => store.setSpec(specToPush);
94
+ // Group modes by source kind for visual separation
95
+ const streamModes = MODES.filter((m) => SOURCES[m.spec.source]?.kind === "stream");
96
+ const stateModes = MODES.filter((m) => SOURCES[m.spec.source]?.kind === "state");
64
97
  return html `
65
98
  <div class="modebar">
66
- ${MODES.map((m) => html `<button class=${"modebtn" + (activeKey === m.key ? " active" : "")} onClick=${() => pick(m.spec)}>${m.label}</button>`)}
99
+ ${streamModes.map((m) => html `<button class=${"modebtn" + (activeKey === m.key ? " active" : "")} onClick=${() => pick(m.spec)}>${m.label}</button>`)}
100
+ ${stateModes.length > 0 ? html `<span class="modedivider"></span>` : null}
101
+ ${stateModes.map((m) => html `<button class=${"modebtn" + (activeKey === m.key ? " active" : "")} onClick=${() => pick(m.spec)}>${m.label}</button>`)}
67
102
  ${store.lastCustomSpec ? html `<button class=${"modebtn custom" + (activeKey === "__custom__" ? " active" : "")} title="pushed from a terminal Claude Code session; persists until refresh" onClick=${() => pick(store.lastCustomSpec)}>✎ ${store.lastCustomSpec.title || "Custom"}</button>` : null}
68
103
  </div>
69
104
  `;
@@ -142,6 +177,13 @@ function Blank() {
142
177
  function App() {
143
178
  const spec = useStoreValue(store, "spec", () => store.spec);
144
179
  const [screenOpen, setScreenOpen] = useState(false);
180
+ // The DB and Prefs tabs cannot import the store (neither needs the SSE engine/timers a
181
+ // point-in-time browser has no use for), so neither can self-reset on a device change. The
182
+ // store emits "db-resync" on any bound-device change (first pin included, PR #94
183
+ // multi-device); folding that counter into each tab's key remounts it on a switch, which
184
+ // drops its picked-file/table/results state and re-fetches from the newly bound device. Name
185
+ // is a historical artifact (the DB tab needed this first); Prefs folds in the same counter.
186
+ const dbResync = useStoreValue(store, "db-resync", () => store.dbSerialVersion);
145
187
  // The screen overlay is a fixed right-docked panel; widen the page padding while it is open so
146
188
  // it never covers the feed/widgets.
147
189
  useEffect(() => {
@@ -190,7 +232,21 @@ function App() {
190
232
  <span class="summary">${spec.summary || "Device database browser"}</span>
191
233
  <span class="tech">source=db (on-device SQLite snapshot, read-only)</span>
192
234
  </div>
193
- <${DbBrowser} spec=${spec} key="db" />
235
+ <${DbBrowser} spec=${spec} key=${"db-" + dbResync} />
236
+ `;
237
+ }
238
+ else if (spec.source === "prefs") {
239
+ // The Prefs browser is a self-contained, point-in-time container: it does NOT import the store
240
+ // (no SSE engine / timers on a tab that has no live feed). key folds in dbResync (PR #94
241
+ // multi-device: the same store event the DB tab remounts on) so a device switch also
242
+ // remounts Prefs -- without it Prefs kept the OLD device's files/entries on screen after
243
+ // switching, since its own useEffect only fetches once on initial mount.
244
+ view = html `
245
+ <div class="sub">
246
+ <span class="summary">${spec.summary || "Device preferences browser"}</span>
247
+ <span class="tech">source=prefs (on-device SharedPreferences snapshot, read-only)</span>
248
+ </div>
249
+ <${PrefsBrowser} spec=${spec} key=${"prefs-" + dbResync} />
194
250
  `;
195
251
  }
196
252
  else {