@slack/radar-mcp 1.19.0 → 1.21.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 (44) hide show
  1. package/README.md +48 -8
  2. package/dist/mcp/api-paths.d.ts +11 -0
  3. package/dist/mcp/api-paths.js +67 -16
  4. package/dist/mcp/index.js +24 -7
  5. package/dist/mcp/network-detail.d.ts +5 -0
  6. package/dist/mcp/network-detail.js +86 -0
  7. package/dist/mcp/radar-response.d.ts +7 -0
  8. package/dist/mcp/radar-response.js +15 -0
  9. package/dist/mcp/session-backfill.d.ts +9 -3
  10. package/dist/mcp/session-backfill.js +77 -17
  11. package/dist/mcp/session-detail.js +54 -2
  12. package/dist/mcp/session-query.js +53 -11
  13. package/dist/mcp/sources-gate.js +4 -0
  14. package/dist/mcp/switchboard-tools.d.ts +9 -0
  15. package/dist/mcp/switchboard-tools.js +40 -0
  16. package/dist/mcp/tools.js +69 -18
  17. package/dist/shared/constants.d.ts +14 -3
  18. package/dist/shared/constants.js +14 -3
  19. package/dist/shared/event-spool.js +3 -2
  20. package/dist/shared/form-body.d.ts +18 -0
  21. package/dist/shared/form-body.js +251 -0
  22. package/dist/shared/stream.d.ts +1 -1
  23. package/dist/shared/switchboard.d.ts +9 -0
  24. package/dist/shared/switchboard.js +54 -0
  25. package/dist/shared/wire.d.ts +32 -0
  26. package/dist/web/install-app.d.ts +64 -1
  27. package/dist/web/install-app.js +174 -24
  28. package/dist/web/macapp/RadarApp.swift +1287 -71
  29. package/dist/web/public/index.html +216 -11
  30. package/dist/web/public/next/app.js +22 -12
  31. package/dist/web/public/next/db.js +180 -18
  32. package/dist/web/public/next/feed.js +571 -53
  33. package/dist/web/public/next/filters.js +160 -34
  34. package/dist/web/public/next/form-body.js +252 -0
  35. package/dist/web/public/next/inspector.js +103 -12
  36. package/dist/web/public/next/registry.js +33 -3
  37. package/dist/web/public/next/store.js +577 -53
  38. package/dist/web/public/next/voice-model.js +532 -0
  39. package/dist/web/public/next/voice.js +397 -0
  40. package/dist/web/server.d.ts +110 -6
  41. package/dist/web/server.js +436 -40
  42. package/dist/web/spec.d.ts +13 -6
  43. package/dist/web/spec.js +89 -6
  44. package/package.json +3 -3
@@ -5,11 +5,16 @@
5
5
  // and the RENDER side (windowed rows + keyboard model).
6
6
  import { html } from "./html.js";
7
7
  import { useState, useEffect, useRef, useCallback, useMemo } from "preact/hooks";
8
- import { store, shortUrl, shortPkg, MODES, modeServed, fmtNum } from "./store.js";
9
- import { STREAM_KINDS } from "./registry.js";
8
+ import { store, shortUrl, shortPkg, MODES, modeServed, fmtNum, specMatchesMode, searchText, parseExcludeTerm, isGappedFieldTerm } from "./store.js";
9
+ import { gappedFieldHint } from "./filters.js";
10
+ import { STREAM_KINDS, LOG_LEVEL_ORDER, levelRank, EXCLUDE_MAX_TERMS, EXCLUDE_MAX_TERM_LENGTH, SWITCHBOARD_KINDS } from "./registry.js";
10
11
  import { parseFilter, tokenize, isCompleteTerm, isQuote } from "./filter.js";
11
12
  const ROW_H = 24;
12
13
  const OVERSCAN = 10;
14
+ // How long the empty line's counts may stay behind the cache after an eviction before the next
15
+ // bump pays a full walk for them. At the cap every push evicts, so without this an empty view
16
+ // holding hidden rows walked the whole cache on every bump. See the recount below.
17
+ const RECOUNT_MS = 250;
13
18
  // Feed UI prefs PERSIST across tab switches (the Feed unmounts/remounts per source). The text
14
19
  // filter is global; sort is per-source (a Network "slowest" is meaningless on RTM).
15
20
  const FEED_PREFS = { filter: "", sortBySource: {} };
@@ -88,17 +93,19 @@ function sortOptionsFor(source) {
88
93
  { key: "oldest", label: "oldest first", get: (e) => e.timestamp || 0, dir: "asc" },
89
94
  ];
90
95
  if (source === "all")
91
- opts.push({ key: "type", label: "group by type", get: (e) => ({ network: 0, rtm: 1, clog: 2, trace: 3, log: 4 }[e._type || ""] ?? 9), dir: "asc" });
96
+ opts.push({ key: "type", label: "group by type", get: (e) => ({ network: 0, rtm: 1, clog: 2, trace: 3, log: 4, switchboard: 5 }[e._type || ""] ?? 9), dir: "asc" });
92
97
  if (source === "network") {
93
98
  opts.push({ key: "slow", label: "slowest (response time)", get: (e) => Number(e.duration_ms), dir: "desc" });
94
99
  opts.push({ key: "status", label: "status code (high→low)", get: (e) => Number(e.status_code), dir: "desc" });
95
100
  }
96
101
  if (source === "log")
97
- opts.push({ key: "severity", label: "severity (errors first)", get: (e) => ({ FATAL: 5, ERROR: 4, WARN: 3, INFO: 2, DEBUG: 1, VERBOSE: 0 }[(e.level || "").toUpperCase()] ?? -1), dir: "desc" });
102
+ opts.push({ key: "severity", label: "severity (errors first)", get: (e) => levelRank(e.level), dir: "desc" });
98
103
  if (source === "rtm")
99
104
  opts.push({ key: "evtype", label: "event type (A→Z)", get: (e) => e.event_type || "", dir: "asc" });
100
105
  if (source === "clog")
101
106
  opts.push({ key: "name", label: "clog name (A→Z)", get: (e) => e.event_name || "", dir: "asc" });
107
+ if (source === "switchboard")
108
+ opts.push({ key: "kind", label: "kind (A→Z)", get: (e) => e.kind || "", dir: "asc" });
102
109
  if (source === "trace") {
103
110
  opts.push({ key: "slow", label: "slowest (duration)", get: (e) => Number(e.duration_ms), dir: "desc" });
104
111
  opts.push({ key: "name", label: "trace name (A→Z)", get: (e) => e.trace_name || "", dir: "asc" });
@@ -119,16 +126,8 @@ function neighborTabSpec(dir) {
119
126
  const k = keys[next];
120
127
  return k === "__custom__" ? store.lastCustomSpec || undefined : MODES.find((m) => m.key === k)?.spec;
121
128
  }
122
- // One searchable string per frame for the text filter. The row KIND is deliberately NOT
123
- // part of this string: a kind token would make "-log" silently exclude clogs (log ⊂ clog).
124
- // Kind matching happens by EQUALITY via the predicate's second argument instead (see filterKind).
125
- function searchText(ev) {
126
- if ((ev._type || "") === "log")
127
- return [ev.level, ev.package, ev.tag, ev.message].filter(Boolean).join(" ").toLowerCase();
128
- if ((ev._type || "") === "trace")
129
- return [ev.trace_name, ev.span_name].filter(Boolean).join(" ").toLowerCase();
130
- return [ev.direction, ev.method, ev.event_type, ev.event_name, shortUrl(ev.url), ev.channel].filter(Boolean).join(" ").toLowerCase();
131
- }
129
+ // searchText (the one searchable string per frame) lives in store.ts, shared with the spec's
130
+ // `exclude` gate so both read the same haystack.
132
131
  // The kind handed to the filter predicate. Only the unified view exposes it: that is where the
133
132
  // type chip is visible, so "trace" / "-log" reading as kind filters matches what the user
134
133
  // sees. On a single-source tab every row is the same kind, so kind matching would only turn
@@ -145,8 +144,56 @@ function rawLine(ev) {
145
144
  return `${t} ${ev.method || "GET"} ${shortUrl(ev.url)} ${ev.status_code ?? ""} ${ev.duration_ms ?? ""}ms`;
146
145
  if (ev._type === "trace")
147
146
  return `${t} ${ev.trace_name || ""} ${ev.span_name || ""} ${ev.duration_ms ?? ""}ms`;
147
+ if (ev._type === "switchboard")
148
+ return `${t} ${String(ev.session_id ?? "")} ${ev.kind || ""} ${ev.kind === "frame" ? switchboardArrow(ev.direction) + " " : ""}${switchboardSummary(ev)}`.trimEnd();
148
149
  return `${t} ${ev._type} ${ev.event_type || ev.event_name || ""} ${ev.channel || ""}`.trimEnd();
149
150
  }
151
+ // ---- switchboard rows: the record's kind, then that kind's fields read as one phrase. ----
152
+ // The tail of the session id: the device mints one per voice session, and the tail is what tells
153
+ // two sessions apart on screen. The full id is on the row's title, on the raw copy line and in the
154
+ // inspector.
155
+ export function shortSession(id) {
156
+ const s = String(id ?? "");
157
+ return s.length > 6 ? s.slice(-6) : s;
158
+ }
159
+ // Frame direction as an arrow, read from the device's point of view: incoming frames arrive from
160
+ // the server (←), outgoing frames leave the device (→).
161
+ export function switchboardArrow(direction) {
162
+ return direction === "incoming" ? "←" : direction === "outgoing" ? "→" : "";
163
+ }
164
+ // A state change whose destination reads as a failure. Cosmetic only (the kind badge turns red):
165
+ // switchboard rows carry no logcat level, so this is where a failed transition stands out.
166
+ export function switchboardFailed(ev) {
167
+ return ev.kind === "state" && /fail|error/i.test(String(ev.to ?? ""));
168
+ }
169
+ // The per-kind summary after the badge: the kind's own fields by name (switchboardFields, the
170
+ // search haystack, lists the same ones), minus the kind (already the badge) and, for frames, minus
171
+ // the direction (already the arrow), with units for the numbers.
172
+ export function switchboardSummary(ev) {
173
+ const num = (v) => (typeof v === "number" ? v : undefined);
174
+ const text = (v) => (v == null ? "" : String(v));
175
+ switch (ev.kind) {
176
+ case "session": return text(ev.event);
177
+ // The state kind and the transition are set apart so a word both carry ("speaking speaking →
178
+ // quiet") does not read as a stutter.
179
+ case "state": return `${text(ev.state_kind)} · ${text(ev.from)} → ${text(ev.to)}${ev.cause ? ` (${text(ev.cause)})` : ""}`.trim();
180
+ // The plugin writes "unknown" for a frame it could not classify; the row says so in words (the
181
+ // search haystack keeps the raw token, so typing unknown still finds it).
182
+ case "frame": {
183
+ const b = num(ev.bytes);
184
+ return `${ev.frame_type === "unknown" ? "unknown type" : text(ev.frame_type)}${b != null ? ` ${fmtNum(b)} B` : ""}`;
185
+ }
186
+ case "phase": {
187
+ const d = num(ev.duration_ms);
188
+ return `${text(ev.phase)}${d != null ? ` ${fmtNum(d)} ms` : ""}`;
189
+ }
190
+ case "player": {
191
+ const g = num(ev.gap_ms), q = num(ev.bytes_queued);
192
+ return `${text(ev.event)}${g != null ? ` gap ${fmtNum(g)} ms` : ""}${q != null ? ` queued ${fmtNum(q)} B` : ""}`;
193
+ }
194
+ default: return "";
195
+ }
196
+ }
150
197
  function statusBand(c) {
151
198
  if (!c)
152
199
  return "";
@@ -179,6 +226,12 @@ function RowBody({ ev, source, highlight }) {
179
226
  const breach = highlight && store.breaches(ev);
180
227
  return html `<span class="t">${t}</span>${typeChip}${ev.duration_ms != null ? html `<span class="durchip">${fmtNum(Number(ev.duration_ms))} ms</span>` : null}<span class="tracename">${ev.trace_name || ""}</span><span class="spanname">${ev.span_name || ""}</span>${breach && highlight ? html `<span class="breachbadge">${breachBadge(ev, highlight)}</span>` : null}`;
181
228
  }
229
+ if ((ev._type || source) === "switchboard") {
230
+ const kind = ev.kind || "";
231
+ const arrow = kind === "frame" ? switchboardArrow(ev.direction) : "";
232
+ // One neutral kind pill on the tab and on Live; only a failed transition changes its colour.
233
+ return html `<span class="t">${t}</span>${typeChip}<span class="sbsess" title=${String(ev.session_id ?? "")}>${shortSession(ev.session_id)}</span><span class=${"sbkind" + (switchboardFailed(ev) ? " sbkind-bad" : "")}>${kind}</span>${arrow ? html `<span class=${"sbdir dir-" + ev.direction} title=${String(ev.direction)}>${arrow}</span>` : null}<span class="sbsum">${switchboardSummary(ev)}</span>`;
234
+ }
182
235
  const breach = highlight && store.breaches(ev);
183
236
  const isNet = (ev._type || source) === "network" || ev.url != null;
184
237
  const code = Number(ev.status_code);
@@ -192,6 +245,22 @@ export function Feed({ spec, onInspect, selectedId }) {
192
245
  const [filter, setFilterState] = useState(() => FEED_PREFS.filter);
193
246
  const [sort, setSortState] = useState(() => FEED_PREFS.sortBySource[source || ""] || "newest");
194
247
  const [paused, setPaused] = useState(false);
248
+ const [helpOpen, setHelpOpen] = useState(false);
249
+ // The legend closes on a press anywhere outside it, the way the combobox lists do, so it never
250
+ // has to be hunted down again once read. Presses inside it are left alone so its examples can
251
+ // be selected and copied.
252
+ useEffect(() => {
253
+ if (!helpOpen || typeof document === "undefined" || !document.addEventListener)
254
+ return;
255
+ const onDown = (e) => {
256
+ const t = e.target;
257
+ if (t && typeof t.closest === "function" && t.closest(".fhelp, .fhelppop"))
258
+ return;
259
+ setHelpOpen(false);
260
+ };
261
+ document.addEventListener("mousedown", onDown);
262
+ return () => document.removeEventListener("mousedown", onDown);
263
+ }, [helpOpen]);
195
264
  const setFilter = useCallback((v) => {
196
265
  FEED_PREFS.filter = v;
197
266
  setFilterState(v);
@@ -279,57 +348,131 @@ export function Feed({ spec, onInspect, selectedId }) {
279
348
  // scroll, new events only bump newCount). While following with "newest" sort we prepend only
280
349
  // the new tail (O(new), not a full O(N) rebuild over 100k) -- the 100k-buffer enabler. Full
281
350
  // recompute() runs only on control change / resume; a non-newest sort rebuilds while tailing.
351
+ //
352
+ // The cache only ever loses entries from the front (TTL, the cap) or in a clear, so "what is new
353
+ // since the last bump" is the run after a cursor, and the length alone cannot place the cursor:
354
+ // at the cap a shift plus a push leaves it flat. The entry that sat at the cursor is the proof.
355
+ // When it is still there the run starts after it; when it moved, the run starts after wherever
356
+ // it went; when it is gone, everything held is new.
282
357
  const seenLenRef = useRef(0);
358
+ const seenTailRef = useRef(undefined);
359
+ const runStart = (len, tail, cacheLen) => {
360
+ if (len === 0)
361
+ return 0;
362
+ if (store.cache[len - 1] === tail)
363
+ return len;
364
+ let j = Math.min(len, cacheLen) - 1;
365
+ while (j >= 0 && store.cache[j] !== tail)
366
+ j--;
367
+ return j + 1;
368
+ };
369
+ const markSeen = (cacheLen) => {
370
+ seenLenRef.current = cacheLen;
371
+ seenTailRef.current = store.cache[cacheLen - 1];
372
+ };
373
+ // The empty line's running counts (see the render below for the recount). `len`/`tail` is the
374
+ // counts' own cursor, `parsed`/`key` the controls they were counted under.
375
+ const countsRef = useRef({ held: 0, belowLevel: 0, excluded: 0, excludedByKind: 0, offBox: 0, waiting: 0, len: 0, tail: undefined, dirty: true, stale: false, at: 0, parsed: null, key: "" });
283
376
  useEffect(() => {
284
377
  snapRef.current = recompute();
285
378
  bumpSnap((n) => n + 1);
286
- seenLenRef.current = store.cache.length;
379
+ markSeen(store.cache.length);
287
380
  const off = store.on("feed", () => {
288
381
  const cacheLen = store.cache.length;
382
+ const startLen = runStart(seenLenRef.current, seenTailRef.current, cacheLen);
383
+ // The empty line's counts are kept running, so the rows that landed are sorted into them
384
+ // here, before the follow check: a paused tab counts too. One judgement per fresh row serves
385
+ // both the counts and the follow's fresh list, so a row costs one pass whether it shows or
386
+ // not. Rows of another source cost nothing; a row of this source that is not for this view (a
387
+ // log line from another tag on a tag-narrowed view) costs one passesMatch and nothing else.
388
+ const cnt = countsRef.current;
389
+ const countStart = runStart(cnt.len, cnt.tail, cacheLen);
390
+ // The front moved, so counted rows may be gone. Only counts that hold something can go
391
+ // stale that way: eviction never adds a row, so all-zero counts stay right, and an empty
392
+ // tab at the cap pays nothing per batch. Stale, not dirty: an eviction is the one cause
393
+ // that repeats on every bump at the cap, and the line can wait for it (see the recount).
394
+ // A clear that emptied the cache is dirty: a walk over nothing is free, and the line must
395
+ // not keep naming hidden rows over an empty cache until the next bump.
396
+ if (countStart < cnt.len && cnt.held > 0) {
397
+ if (cacheLen === 0)
398
+ cnt.dirty = true;
399
+ else
400
+ cnt.stale = true;
401
+ }
402
+ let countChanged = false;
403
+ const src = store.spec.source;
404
+ const fresh = [];
405
+ for (let i = Math.min(startLen, countStart); i < cacheLen; i++) {
406
+ const c = store.cache[i];
407
+ if (!c)
408
+ continue;
409
+ if (src !== "all" && c.type !== src)
410
+ continue;
411
+ const ev = c.ev;
412
+ ev._type = c.type;
413
+ if (!store.passesMatch(ev))
414
+ continue;
415
+ // The level is judged first (it is what the server applies), so a row both hide counts
416
+ // against the level; an exclusion is only blamed for rows the level let through, and the
417
+ // box only for rows neither of those hid, so an excluded row is never charged to the box
418
+ // and never waits. A kind chip's term is its own bucket where the chips exist (the Switchboard
419
+ // tab), so the line can name the control; anywhere else a kind: term is just an exclusion.
420
+ // One excludeReason per row: it is the hidden-or-not answer and the reason in one walk.
421
+ let bucket = "waiting";
422
+ if (!store.passesLevel(ev))
423
+ bucket = "belowLevel";
424
+ else {
425
+ const why = store.excludeReason(ev);
426
+ if (why)
427
+ bucket = why === "kind" && src === "switchboard" ? "excludedByKind" : "excluded";
428
+ else if (!matchParsed.empty && !matchParsed.test(searchText(ev), filterKind(ev, src)))
429
+ bucket = "offBox";
430
+ }
431
+ if (i >= countStart) {
432
+ cnt[bucket]++;
433
+ cnt.held++;
434
+ countChanged = true;
435
+ }
436
+ if (i >= startLen && bucket === "waiting")
437
+ fresh.push(ev);
438
+ }
439
+ cnt.len = cacheLen;
440
+ cnt.tail = store.cache[cacheLen - 1];
441
+ markSeen(cacheLen);
289
442
  if (!followRef.current) {
290
443
  setNewCount((c) => c + 1);
291
- seenLenRef.current = cacheLen; // keep the cursor current so resume is incremental
292
444
  return;
293
445
  }
294
- const src = store.spec.source;
295
446
  if (sort === "newest") {
296
- const startLen = Math.min(seenLenRef.current, cacheLen); // guard against eviction shrink
297
- const fresh = [];
298
- for (let i = startLen; i < cacheLen; i++) {
299
- const c = store.cache[i];
300
- if (!c)
301
- continue;
302
- if (src !== "all" && c.type !== src)
303
- continue;
304
- const ev = c.ev;
305
- ev._type = c.type;
306
- if (!store.matches(ev))
307
- continue;
308
- if (!matchParsed.empty && !matchParsed.test(searchText(ev), filterKind(ev, src)))
309
- continue;
310
- fresh.push(ev);
311
- }
312
447
  if (fresh.length) {
313
448
  fresh.reverse();
314
449
  snapRef.current = fresh.concat(snapRef.current);
315
450
  bumpSnap((n) => n + 1);
316
451
  }
452
+ else if (snapRef.current.length === 0 && (countChanged || cnt.dirty || cnt.stale)) {
453
+ // Nothing to show, but the empty line reads the counts on a render, so it gets one when
454
+ // they moved. A bump that carried no row for this view asks for nothing.
455
+ bumpSnap((n) => n + 1);
456
+ }
317
457
  }
318
458
  else {
319
459
  snapRef.current = recompute();
320
460
  bumpSnap((n) => n + 1);
321
461
  }
322
- seenLenRef.current = cacheLen;
323
462
  const el = vpRef.current;
324
463
  if (el)
325
464
  el.scrollTop = 0; // glue to newest (top)
326
465
  });
327
466
  return off;
328
467
  }, [recompute, matchParsed, sort, sortOpts]);
329
- // Rebuild when the SERVER-SIDE filter (match/bodyContains) changes -- that changes what
330
- // store.matches() admits, so the whole snapshot must refresh. Keyed so it only fires on a
331
- // real filter change, not every spec poll.
332
- const matchKey = JSON.stringify(spec.match || {}) + "|" + (spec.bodyContains || "");
468
+ // Rebuild when the SERVER-SIDE filter (match/bodyContains/minLevel) changes -- that changes
469
+ // what store.matches() admits, so the whole snapshot must refresh. Keyed so it only fires on a
470
+ // real filter change, not every spec poll. minLevel is part of the key because the level
471
+ // selector's first live test left 289 rows of INFO and DEBUG on screen under "level ≥ ERROR":
472
+ // new frames were filtered, the rows already rendered were not.
473
+ // exclude is in the key for the same reason minLevel is: a chip removed or a term added must
474
+ // re-filter the rows already on screen, not only the frames that arrive afterwards.
475
+ const matchKey = JSON.stringify(spec.match || {}) + "|" + (spec.bodyContains || "") + "|" + (spec.minLevel || "") + "|" + JSON.stringify(spec.exclude || []);
333
476
  useEffect(() => {
334
477
  forceSnap();
335
478
  }, [matchKey]);
@@ -356,6 +499,96 @@ export function Feed({ spec, onInspect, selectedId }) {
356
499
  const frames = snapRef.current;
357
500
  const total = frames.length;
358
501
  const totalH = total * ROW_H;
502
+ // Zero rows on screen has three causes that want different lines: the store holds nothing for
503
+ // this view yet (say so), it holds rows the level, the exclusions or the filter box are hiding,
504
+ // or it holds rows that would show and are waiting behind a pause or a lock. "For this view"
505
+ // means the source plus the spec's `match`: on a view narrowed to one tag, log lines from other
506
+ // tags are not rows being hidden, they are simply not rows of this view.
507
+ //
508
+ // The counts run: the feed handler sorts each fresh row in as it lands, so a render reads them
509
+ // and walks nothing. The one full walk is the recount below, taken only when the view is empty
510
+ // and the counts are dirty: the controls changed (level, match, exclusions, box, source; matchKey
511
+ // carries the exclude terms, so a chip added or removed by the toolbar, the Filters panel or an
512
+ // agent lands here through the key) or the cache lost
513
+ // rows from the front (TTL, the cap, a clear), which the handler detects by the cursor entry
514
+ // moving, not by the length. The counts keep their own cursor so their bookkeeping stays
515
+ // independent of the follow's: a recount here moves only the counts' cursor and leaves the
516
+ // snapshot's alone. The two causes are told apart: a control change (a chip added, a level
517
+ // moved) must land at once, so it is `dirty` and walks now; an eviction only makes the counts
518
+ // `stale`, and a stale walk runs at most once per RECOUNT_MS, because at the cap every push
519
+ // evicts and a view holding hidden rows would otherwise walk the whole cache on every bump. In
520
+ // between the line may name up to RECOUNT_MS of evicted rows; it is informational, so that is
521
+ // fine. An empty view with nothing held never goes stale (see the handler), and under the cap a
522
+ // bump costs only the rows it carried.
523
+ const countKey = matchKey + "|" + source;
524
+ const cnt = countsRef.current;
525
+ if (cnt.parsed !== matchParsed || cnt.key !== countKey) {
526
+ cnt.parsed = matchParsed;
527
+ cnt.key = countKey;
528
+ cnt.dirty = true;
529
+ }
530
+ if (total === 0 && (cnt.dirty || (cnt.stale && Date.now() - cnt.at > RECOUNT_MS))) {
531
+ cnt.at = Date.now();
532
+ cnt.held = 0;
533
+ cnt.belowLevel = 0;
534
+ cnt.excluded = 0;
535
+ cnt.excludedByKind = 0;
536
+ cnt.offBox = 0;
537
+ cnt.waiting = 0;
538
+ for (const c of store.cache) {
539
+ if (!c || (source !== "all" && c.type !== source))
540
+ continue;
541
+ const ev = c.ev;
542
+ ev._type = c.type;
543
+ if (!store.passesMatch(ev))
544
+ continue;
545
+ cnt.held++;
546
+ // Same order as the handler: level, then exclusion, then the box.
547
+ if (!store.passesLevel(ev))
548
+ cnt.belowLevel++;
549
+ else {
550
+ const why = store.excludeReason(ev);
551
+ if (why) {
552
+ if (why === "kind" && source === "switchboard")
553
+ cnt.excludedByKind++;
554
+ else
555
+ cnt.excluded++;
556
+ }
557
+ else if (!matchParsed.empty && !matchParsed.test(searchText(ev), filterKind(ev, source)))
558
+ cnt.offBox++;
559
+ else
560
+ cnt.waiting++;
561
+ }
562
+ }
563
+ cnt.len = store.cache.length;
564
+ cnt.tail = store.cache[cnt.len - 1];
565
+ cnt.dirty = false;
566
+ cnt.stale = false;
567
+ }
568
+ let emptyLine = null;
569
+ if (total === 0) {
570
+ const { held, belowLevel, excluded, excludedByKind, offBox, waiting } = cnt;
571
+ const n = (k) => (k === 1 ? "1 row" : k + " rows");
572
+ if (held === 0)
573
+ emptyLine = source === "switchboard" ? "Nothing yet. Start a Slackbot voice session on the device; the first records arrive when it connects. A build without the Switchboard plugin leaves this tab empty." : "Nothing yet.";
574
+ // A row the level, the exclusions and the box all let through is waiting, not hidden, and the
575
+ // status pill already tells pause from lock (a selection, a scroll, or jump-to-oldest), so the
576
+ // line does too.
577
+ else if (waiting > 0 && !following)
578
+ emptyLine = n(waiting) + (paused ? " arrived while paused." : " arrived while the feed is locked.");
579
+ else {
580
+ const parts = [];
581
+ if (belowLevel > 0)
582
+ parts.push(n(belowLevel) + (belowLevel === 1 ? " is" : " are") + " below the level ≥ selector.");
583
+ if (excludedByKind > 0)
584
+ parts.push(n(excludedByKind) + (excludedByKind === 1 ? " is" : " are") + " hidden by a kind chip.");
585
+ if (excluded > 0)
586
+ parts.push(n(excluded) + (excluded === 1 ? " is" : " are") + " hidden by an exclusion.");
587
+ if (offBox > 0)
588
+ parts.push(n(offBox) + (offBox === 1 ? " does" : " do") + " not match the filter box.");
589
+ emptyLine = parts.join(" ") || null;
590
+ }
591
+ }
359
592
  const first = Math.max(0, Math.floor(scrollTop / ROW_H) - OVERSCAN);
360
593
  const visCount = Math.ceil(vpH / ROW_H) + OVERSCAN * 2;
361
594
  const last = Math.min(total, first + visCount);
@@ -494,6 +727,9 @@ export function Feed({ spec, onInspect, selectedId }) {
494
727
  highlightRef.current = null;
495
728
  setNewCount(0);
496
729
  onInspect && onInspect(null);
730
+ // The clear must recount now, not on the eviction throttle: other tabs' rows can keep the
731
+ // cache non-empty, so the handler above only marked the counts stale.
732
+ countsRef.current.dirty = true;
497
733
  forceSnap();
498
734
  }, [forceSnap, onInspect]);
499
735
  const scrollIntoView = useCallback((idx) => {
@@ -582,6 +818,13 @@ export function Feed({ spec, onInspect, selectedId }) {
582
818
  return; // native copy proceeds
583
819
  }
584
820
  const t = e.target;
821
+ // A focused button (exclude…, pause, Clear, a filter pill) owns its Enter and Space: the
822
+ // browser turns them into a click, and swallowing them here left the keyboard unable to
823
+ // press. Only those two: the row keys (j/k, arrows, Home/End, g/G, Cmd-C) keep working
824
+ // with a button focused, as they do after a mouse click on pause or a mode tab.
825
+ const onButton = !!t && (t.tagName === "BUTTON" || (typeof t.getAttribute === "function" && t.getAttribute("role") === "button"));
826
+ if (onButton && (e.key === "Enter" || e.key === " "))
827
+ return;
585
828
  if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.tagName === "SELECT" || t.isContentEditable)) {
586
829
  if ((e.metaKey || e.ctrlKey) && e.key === "c" && sel.size) {
587
830
  e.preventDefault();
@@ -665,17 +908,204 @@ export function Feed({ spec, onInspect, selectedId }) {
665
908
  return observed;
666
909
  }, [spec, store.feedVersion, frames.length]);
667
910
  const curPkg = (spec.match && spec.match.package) || "__all__";
911
+ // Both selectors are links in the store's write chain (updateSpec), built from the spec the store
912
+ // holds when their turn comes: a change made while a typed term's push is in flight keeps the
913
+ // term, where a body built from the prop at click time posted the list without it.
668
914
  const changePkg = useCallback((v) => {
669
- const next = JSON.parse(JSON.stringify(spec));
670
- next.match = next.match || {};
671
- if (v === "__all__")
672
- delete next.match.package;
673
- else
674
- next.match.package = v;
675
- if (!Object.keys(next.match).length)
676
- delete next.match;
677
- store.setSpec(next, { local: true });
915
+ void store.updateSpec((base) => {
916
+ // The selectors sit on the log-carrying views (Logs and Live); a change still queued when the
917
+ // view moved to another source has nothing to write.
918
+ if (base.source !== "log" && base.source !== "all")
919
+ return null;
920
+ const next = JSON.parse(JSON.stringify(base));
921
+ next.match = next.match || {};
922
+ if (v === "__all__")
923
+ delete next.match.package;
924
+ else
925
+ next.match.package = v;
926
+ if (!Object.keys(next.match).length)
927
+ delete next.match;
928
+ return next;
929
+ }, { local: true });
930
+ }, []);
931
+ // The level selector writes the spec, the way the app selector does, so the choice survives a
932
+ // reload, shows as a chip, and an agent-authored spec can set the same field. VERBOSE is the
933
+ // floor of the order, so it is stored as no field at all rather than as a value that filters
934
+ // nothing.
935
+ const curLevel = (typeof spec.minLevel === "string" && spec.minLevel) || LOG_LEVEL_ORDER[0];
936
+ const changeLevel = useCallback((v) => {
937
+ void store.updateSpec((base) => {
938
+ if (base.source !== "log" && base.source !== "all")
939
+ return null;
940
+ const next = JSON.parse(JSON.stringify(base));
941
+ if (v === LOG_LEVEL_ORDER[0])
942
+ delete next.minLevel;
943
+ else
944
+ next.minLevel = v;
945
+ return next;
946
+ }, { local: true });
947
+ }, []);
948
+ // The exclude… control writes spec.exclude the same way, so a term added here is a chip, is
949
+ // kept with the tab, and is the same field an agent or the Filters panel sets. The box stays
950
+ // open after Enter for the next term; Escape, or leaving it empty, closes it. The cap and the
951
+ // case-insensitive dedupe mirror the server's rules, so a refused term never reaches it. A
952
+ // refusal is said next to the box and keeps the draft: a term that vanishes with no chip
953
+ // reads as a bug, not as a rule. A comma is refused too: the Filters panel splits its input
954
+ // on commas, so a term holding one would come back as two on the first edit there.
955
+ const isStream = source !== "db" && source !== "prefs" && source !== "flags";
956
+ const [exclOpen, setExclOpen] = useState(false);
957
+ const [exclDraft, setExclDraft] = useState("");
958
+ // The note under the box: a refusal keeps the draft and marks the input invalid; a hint (a term
959
+ // that was added but is probably not what was meant) shows the same way without either.
960
+ const [exclNote, setExclNote] = useState(null);
961
+ // One add at a time: a second Enter while the first push is in flight is ignored. The
962
+ // generation guards a late resolve after the box was closed or reopened, so an old refusal
963
+ // never lands next to a new draft.
964
+ const exclPendingRef = useRef(false);
965
+ const exclGenRef = useRef(0);
966
+ const exclRef = useRef(null);
967
+ const exclBtnRef = useRef(null);
968
+ useEffect(() => {
969
+ if (exclOpen && exclRef.current && typeof exclRef.current.focus === "function")
970
+ exclRef.current.focus();
971
+ }, [exclOpen]);
972
+ // `ok` says whether the term was added (a blank adds nothing and is ok). `note` is the reason
973
+ // it was refused, or a hint on a term that was added anyway. The server has the last word, so
974
+ // its refusal is surfaced the same way as the local ones. The write is a link in the store's
975
+ // chain (updateSpec), so the list is read once the writes before it have settled: a term typed
976
+ // while a chip's push is in flight builds on the acked list. The tab is the one the term was
977
+ // typed on: a write still queued when the tab changed has nothing to add to the new tab's list,
978
+ // and says nothing.
979
+ const addExclude = useCallback((raw) => {
980
+ const term = raw.trim();
981
+ if (!term)
982
+ return Promise.resolve({ ok: true, note: null });
983
+ if (term.includes(","))
984
+ return Promise.resolve({ ok: false, note: "one term at a time, no commas" });
985
+ const at = store.spec ?? spec;
986
+ const mySource = (at.source ?? "all");
987
+ const myTab = specMatchesMode(at);
988
+ const out = { refusal: null, stale: false };
989
+ return store.updateSpec((base) => {
990
+ if (base.source !== at.source || specMatchesMode(base) !== myTab) {
991
+ out.stale = true;
992
+ return null;
993
+ }
994
+ const cur = Array.isArray(base.exclude) ? base.exclude.map(String) : [];
995
+ const lower = term.toLowerCase();
996
+ if (cur.some((t) => t.toLowerCase() === lower)) {
997
+ out.refusal = "already excluded";
998
+ return null;
999
+ }
1000
+ if (cur.length >= EXCLUDE_MAX_TERMS) {
1001
+ out.refusal = "up to " + EXCLUDE_MAX_TERMS + " terms";
1002
+ return null;
1003
+ }
1004
+ if (term.length > EXCLUDE_MAX_TERM_LENGTH) {
1005
+ out.refusal = "up to " + EXCLUDE_MAX_TERM_LENGTH + " characters";
1006
+ return null;
1007
+ }
1008
+ const next = JSON.parse(JSON.stringify(base));
1009
+ next.exclude = [...cur, term];
1010
+ return next;
1011
+ }, { local: true }).then((r) => {
1012
+ if (out.stale)
1013
+ return { ok: false, note: null };
1014
+ if (out.refusal)
1015
+ return { ok: false, note: out.refusal };
1016
+ if (!r.ok)
1017
+ return { ok: false, note: r.error || "rejected" };
1018
+ return { ok: true, note: isGappedFieldTerm(term, (f) => store.fieldSeen(mySource, f)) ? gappedFieldHint(term) : null };
1019
+ });
678
1020
  }, [spec]);
1021
+ // The Switchboard tab's kind chips: one exclude term, kind:<name>, per kind, written the way
1022
+ // addExclude writes a typed term. A chip reads its state off the same list toggleKind writes
1023
+ // (the store's spec, which the prop can lag by one render), so the chip above the feed, the
1024
+ // Filters row, the tab memory and an agent's spec all move it; nothing is stored twice. A full
1025
+ // list, or a push the server refuses, is said with the exclude box's note, next to the chips.
1026
+ // A term is read through parseExcludeTerm, as the store reads it, so " kind:frame " and
1027
+ // KIND:FRAME are the same chip.
1028
+ const [kindNote, setKindNote] = useState(null);
1029
+ const kindNoteSpecRef = useRef(null);
1030
+ const isKindTerm = (t, name) => {
1031
+ const p = parseExcludeTerm(String(t));
1032
+ return "field" in p && p.field === "kind" && p.value === name;
1033
+ };
1034
+ const kindHidden = useCallback((name) => {
1035
+ const base = store.spec ?? spec;
1036
+ const ex = Array.isArray(base.exclude) ? base.exclude : [];
1037
+ return ex.some((t) => isKindTerm(t, name));
1038
+ }, [spec]);
1039
+ // A press is a link in the store's write chain, so a second press on a chip mid-flight is the
1040
+ // next toggle, not a lost one, and a press still queued when the tab changed writes nothing. A
1041
+ // refusal is said only while the list it answered is still the store's: an accepted write, a tab
1042
+ // switch or another control each replace store.spec, and a refusal of a list that is gone is
1043
+ // not said. The check is on identity right after the ack. In a burst (press 1 accepted, press 2
1044
+ // refused) the second's list is the first's acked spec, so it passes; the ref below is what
1045
+ // keeps the clearing effect the first's ack scheduled from wiping it a moment later.
1046
+ const toggleKind = useCallback(async (name) => {
1047
+ setKindNote(null);
1048
+ const seen = { base: null, full: false };
1049
+ const r = await store.updateSpec((base) => {
1050
+ seen.base = base;
1051
+ // The chips are Switchboard's; a press still queued when the tab changed has nothing to write.
1052
+ if (base.source !== "switchboard")
1053
+ return null;
1054
+ const cur = Array.isArray(base.exclude) ? base.exclude.map(String) : [];
1055
+ const rest = cur.filter((t) => !isKindTerm(t, name));
1056
+ const next = JSON.parse(JSON.stringify(base));
1057
+ if (rest.length !== cur.length) {
1058
+ if (rest.length)
1059
+ next.exclude = rest;
1060
+ else
1061
+ delete next.exclude;
1062
+ }
1063
+ else {
1064
+ if (cur.length >= EXCLUDE_MAX_TERMS) {
1065
+ seen.full = true;
1066
+ return null;
1067
+ }
1068
+ next.exclude = [...cur, "kind:" + name];
1069
+ }
1070
+ return next;
1071
+ }, { local: true });
1072
+ if (store.spec !== seen.base)
1073
+ return;
1074
+ const note = seen.full ? "up to " + EXCLUDE_MAX_TERMS + " terms" : r.ok ? null : r.error || "rejected";
1075
+ if (note === null)
1076
+ return;
1077
+ kindNoteSpecRef.current = store.spec;
1078
+ setKindNote(note);
1079
+ }, []);
1080
+ // The note answers one press; the next change to the list (a chip removed, a tab switch, a term
1081
+ // typed) ends it. The effect runs after its render, on the next frame or at the start of the
1082
+ // render after it, so it can land after a note set for a later press: press 1's ack changes the
1083
+ // list, press 2's refusal sets the note a few ms on, then the effect the ack scheduled fires. The
1084
+ // ref names the spec the note was said against; the note goes only once the store has moved past it.
1085
+ // The spec itself is the dep, not its exclude list: an Apply that changes only the match leaves
1086
+ // an empty list as undefined on both sides, and the note would otherwise outlive the spec it
1087
+ // answered.
1088
+ useEffect(() => {
1089
+ if (store.spec === kindNoteSpecRef.current)
1090
+ return;
1091
+ kindNoteSpecRef.current = null;
1092
+ setKindNote(null);
1093
+ }, [spec, source]);
1094
+ // Escape from the input hands focus back to the button, so the keyboard does not land on the
1095
+ // page body; a blur is focus already on its way elsewhere and is left alone.
1096
+ const closeExclude = useCallback((returnFocus = false) => {
1097
+ exclGenRef.current++;
1098
+ // A push still in flight belongs to the box that closed; the next box starts free.
1099
+ exclPendingRef.current = false;
1100
+ setExclOpen(false);
1101
+ setExclDraft("");
1102
+ setExclNote(null);
1103
+ if (returnFocus && exclBtnRef.current && typeof exclBtnRef.current.focus === "function")
1104
+ exclBtnRef.current.focus();
1105
+ }, []);
1106
+ // Memory is a preset tab's: a Custom view has no key to come back to, so its copy must not
1107
+ // promise one.
1108
+ const excludeRemembered = specMatchesMode(spec) !== null;
679
1109
  // build only the visible slice
680
1110
  const slice = [];
681
1111
  for (let i = first; i < last; i++) {
@@ -778,7 +1208,9 @@ export function Feed({ spec, onInspect, selectedId }) {
778
1208
  // Click anywhere in the wrap that is NOT a pill focuses the draft input (matches
779
1209
  // browser input behavior: the whole wrap reads as one field).
780
1210
  const target = e.target;
781
- if (target && typeof target.closest === "function" && target.closest(".fpill"))
1211
+ // The legend and its button are left alone too: focusing the input on the click that ends
1212
+ // a drag-select would drop the selection somebody just made in the legend.
1213
+ if (target && typeof target.closest === "function" && target.closest(".fpill, .fhelp, .fhelppop"))
782
1214
  return;
783
1215
  const inp = filterRef.current;
784
1216
  if (inp && typeof inp.focus === "function")
@@ -838,7 +1270,7 @@ export function Feed({ spec, onInspect, selectedId }) {
838
1270
  ? "invalid regex ignored: " + draft
839
1271
  : draftHint
840
1272
  ? draftHint
841
- : 'space-separated terms AND together · -term excludes · /pattern/ is regex with optional short flags (i/m/s/g, 1-2 letters, so /api/im reads as flags) · unterminated /…/ or flag typos like /error/x become literal regex · "quote" to match any /…/ literally, curly quotes count too · pasting text with spaces into an empty box quotes it as one phrase · on Live, a kind name (log, clog, trace, rtm, network) matches by type or substring, and its -kind form excludes by type only (quote it, -"log", to exclude by text instead)'}
1273
+ : 'space-separated terms AND together · -term excludes · /pattern/ is regex with optional short flags (i/m/s/g, 1-2 letters, so /api/im reads as flags) · unterminated /…/ or flag typos like /error/x become literal regex · "quote" to match any /…/ literally, curly quotes count too · pasting text with spaces into an empty box quotes it as one phrase · on Live, a kind name (log, clog, trace, rtm, network, switchboard) matches by type or substring, and its -kind form excludes by type only (quote it, -"log", to exclude by text instead)'}
842
1274
  ref=${attachFilterInput}
843
1275
  onFocus=${() => { if (sel.size)
844
1276
  clearSel(); }}
@@ -900,14 +1332,20 @@ export function Feed({ spec, onInspect, selectedId }) {
900
1332
  setPillsAndDraft(pills.slice(0, -1), last);
901
1333
  }
902
1334
  else if (e.key === "Escape") {
1335
+ setHelpOpen(false);
903
1336
  el.blur();
904
1337
  }
905
1338
  else if ((e.key === "ArrowLeft" || e.key === "ArrowRight") && el.value === "") {
906
1339
  e.preventDefault();
907
1340
  el.blur();
908
1341
  const ns = neighborTabSpec(e.key === "ArrowRight" ? 1 : -1);
909
- if (ns)
910
- store.setSpec(ns);
1342
+ // Presets carry the level floor the way a tab click does; the Custom spec is pushed as is.
1343
+ if (ns) {
1344
+ if (ns === store.lastCustomSpec)
1345
+ store.setSpec(ns);
1346
+ else
1347
+ store.pushPreset(ns);
1348
+ }
911
1349
  }
912
1350
  }}
913
1351
  onInput=${(e) => {
@@ -919,9 +1357,88 @@ export function Feed({ spec, onInspect, selectedId }) {
919
1357
  setPillsAndDraft(pills, v);
920
1358
  }} />
921
1359
  ${filter ? html `<span class="ffilterclear" title="clear all" onClick=${() => setFilter("")}>✕</span>` : null}
1360
+ <span class=${"fhelp" + (helpOpen ? " open" : "")} title="filter syntax help" role="button" tabindex="0"
1361
+ aria-label="filter syntax help" aria-expanded=${helpOpen} aria-controls=${helpOpen ? "fhelppop" : undefined}
1362
+ onMouseDown=${(e) => e.preventDefault()}
1363
+ onClick=${() => setHelpOpen((o) => !o)}
1364
+ onKeyDown=${(e) => {
1365
+ // A span does not synthesize a click from Enter or Space the way a button does, so the
1366
+ // keys are handled here; assistive tech sends a real click, handled above.
1367
+ if (e.key === "Enter" || e.key === " ") {
1368
+ e.preventDefault();
1369
+ setHelpOpen((o) => !o);
1370
+ }
1371
+ else if (e.key === "Escape")
1372
+ setHelpOpen(false);
1373
+ }}>?</span>
1374
+ ${helpOpen ? html `<div class="fhelppop" id="fhelppop" role="note">
1375
+ <code>error</code><span>rows containing it (case does not matter)</span>
1376
+ <code>error timeout</code><span>rows containing both, in any order</span>
1377
+ <code>"not found"</code><span>rows containing that phrase</span>
1378
+ <code>-heartbeat</code><span>hide rows containing it</span>
1379
+ <code>"-1"</code><span>a literal - or / goes in quotes</span>
1380
+ <code>/^Fetch/</code><span>a regular expression</span>
1381
+ ${source === "all" ? html `<code>-log</code><span>hide every row of one type (log, clog, trace, rtm, network, switchboard)</span>` : null}
1382
+ ${source === "switchboard" ? html `<code>-audio</code><span>hide audio frames (most rows in a live session; the audio_claim phase goes too)</span><span class="fhelpnote">Each kind chip on the toolbar turns one kind of record off; it writes the exclude term <code>kind:${"<name>"}</code> (say <code>kind:frame</code>, no space after the colon), which you can also type in <b>exclude…</b>. For one kind only: <b>Filters</b> › <b>+ add match field</b> › <b>kind</b>.</span>` : null}
1383
+ ${isLogish ? html `<span class="fhelpnote">Typing <code>WARN</code> matches rows that contain it. For WARN and above, use the <b>level ≥</b> selector on this bar.</span>` : null}
1384
+ <span class="fhelpnote"><code>-term</code> is page-wide and forgets on reload. To keep an exclusion on this tab, use <b>exclude…</b> on the toolbar; it shows as a chip, saved with this ${excludeRemembered ? "tab and remembered when you come back" : "view"}.</span>
1385
+ </div>` : null}
922
1386
  </span>
1387
+ ${isLogish ? html `<label class="fsortlbl" title=${source === "all" ? "show log lines at this level or above. Rows of other types are not affected." : "show log lines at this level or above"}>level ≥ <select class="flevel" value=${curLevel} onChange=${(e) => changeLevel(e.currentTarget.value)}>${LOG_LEVEL_ORDER.map((l) => html `<option value=${l}>${l === LOG_LEVEL_ORDER[0] ? l + " (all)" : l}</option>`)}</select></label>` : null}
1388
+ ${isStream ? html `<span class="fexcludewrap">
1389
+ <button class="fexclude" type="button" ref=${exclBtnRef}
1390
+ title=${"hide rows whose text contains a term; a field:value term (no space after the colon) hides rows whose field equals the value, case-insensitive; shown as a chip above the feed; saved with this " + (excludeRemembered ? "tab and remembered when you come back" : "view")}
1391
+ aria-expanded=${exclOpen} aria-controls=${exclOpen ? "fexclude-input" : undefined}
1392
+ onClick=${() => (exclOpen ? closeExclude() : (exclGenRef.current++, setExclOpen(true)))}>exclude…</button>
1393
+ ${exclOpen ? html `<input class="fexclude-input" id="fexclude-input" ref=${exclRef} placeholder="term, then Enter" autocomplete="off" value=${exclDraft}
1394
+ aria-label="exclude term" aria-invalid=${exclNote?.refused ? "true" : undefined} aria-describedby=${exclNote ? "fexclude-note" : undefined}
1395
+ onInput=${(e) => { setExclDraft(e.currentTarget.value); setExclNote(null); }}
1396
+ onKeyDown=${(e) => {
1397
+ const el = e.currentTarget;
1398
+ if (e.key === "Enter") {
1399
+ e.preventDefault();
1400
+ if (exclPendingRef.current)
1401
+ return;
1402
+ exclPendingRef.current = true;
1403
+ const gen = exclGenRef.current;
1404
+ void addExclude(el.value).then(({ ok, note }) => {
1405
+ // A push from a box that has since closed does not free the box that is open now.
1406
+ if (gen !== exclGenRef.current)
1407
+ return;
1408
+ exclPendingRef.current = false;
1409
+ if (ok)
1410
+ setExclDraft("");
1411
+ setExclNote(note ? { text: note, refused: !ok } : null);
1412
+ }).catch((e) => {
1413
+ // A write that threw (not a refusal) frees the box and is said like one.
1414
+ if (gen !== exclGenRef.current)
1415
+ return;
1416
+ exclPendingRef.current = false;
1417
+ setExclNote({ text: e instanceof Error && e.message ? e.message : "request failed", refused: true });
1418
+ });
1419
+ }
1420
+ else if (e.key === "Escape") {
1421
+ e.preventDefault();
1422
+ closeExclude(true);
1423
+ }
1424
+ }}
1425
+ onBlur=${(e) => { if (!e.currentTarget.value.trim())
1426
+ closeExclude(); }} />` : null}
1427
+ ${exclOpen && exclNote ? html `<span class=${"fexclude-note" + (exclNote.refused ? "" : " fexclude-note-plain")} id="fexclude-note" role="status">${exclNote.text}</span>` : null}
1428
+ </span>` : null}
1429
+ ${source === "switchboard" ? html `<span class="fsortlbl"><span id="fkinds-label">kinds</span> <span class="fkinds" role="group" aria-labelledby="fkinds-label">
1430
+ ${SWITCHBOARD_KINDS.map((k) => {
1431
+ const on = !kindHidden(k);
1432
+ // The accessible name is the kind; aria-checked carries the state. The title is the
1433
+ // mouse hint and names the action, which read inverted as a screen reader's name.
1434
+ return html `<button class=${"fkind" + (on ? "" : " fkind-off")} type="button" role="switch" aria-checked=${on ? "true" : "false"}
1435
+ title=${(on ? "hide " : "show ") + k + " records"} aria-label=${k + " records"} aria-describedby=${kindNote ? "fkinds-note" : undefined}
1436
+ onClick=${() => { void toggleKind(k).catch((e) => setKindNote(e instanceof Error && e.message ? e.message : "request failed")); }}>${k}</button>`;
1437
+ })}
1438
+ ${kindNote ? html `<span class="fexclude-note" id="fkinds-note" role="status">${kindNote}</span>` : null}
1439
+ </span></span>` : null}
923
1440
  ${isLogish ? html `<label class="fsortlbl">app <select onChange=${(e) => changePkg(e.currentTarget.value)}><option value="__all__" selected=${curPkg === "__all__"}>all apps</option>${pkgOptions.map((p) => html `<option value=${p} selected=${p === curPkg}>${shortPkg(p)}</option>`)}</select></label>` : null}
924
- <label class="fsortlbl">sort <select value=${sort} onChange=${(e) => setSort(e.currentTarget.value)}>${sortOpts.map((o) => html `<option value=${o.key}>${o.label}</option>`)}</select></label>
1441
+ <label class="fsortlbl">sort <select class="fsort" value=${sort} onChange=${(e) => setSort(e.currentTarget.value)}>${sortOpts.map((o) => html `<option value=${o.key}>${o.label}</option>`)}</select></label>
925
1442
  <button class=${"fbtn" + (paused ? " paused" : "")} title="pause / resume the live feed" onClick=${() => setPaused((p) => !p)}>${paused ? "▶ resume" : "⏸ pause"}</button>
926
1443
  <button class="fbtn" disabled=${!total} onClick=${clearView}
927
1444
  title="empty this dashboard's view. The device keeps its own buffers, so reconnecting or switching source backfills recent records again. To wipe the device too, ask Claude Code for clear_buffers.">Clear</button>
@@ -932,6 +1449,7 @@ export function Feed({ spec, onInspect, selectedId }) {
932
1449
  </div>
933
1450
  <div class="vpbox">
934
1451
  <div class="vp" ref=${vpRef} onScroll=${onScroll}>
1452
+ ${emptyLine ? html `<div class="empty-row">${emptyLine}</div>` : null}
935
1453
  <div class="spacer" style=${{ height: totalH + "px" }}>${slice}</div>
936
1454
  </div>
937
1455
  ${!following && (newCount > 0 || scrollTop > ROW_H) ? html `<div class="pill" onClick=${jumpNewest}>↑ newest${newCount ? ` (${newCount} new)` : ""} <span class="pillkey">${KEY_NEWEST}</span></div>` : null}
@@ -940,4 +1458,4 @@ export function Feed({ spec, onInspect, selectedId }) {
940
1458
  </div>
941
1459
  `;
942
1460
  }
943
- export { ROW_H, sortOptionsFor, searchText, filterKind, rawLine, statusBand };
1461
+ export { ROW_H, sortOptionsFor, searchText, filterKind, rawLine, statusBand, RowBody };