@slack/radar-mcp 1.19.0 → 1.20.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.
@@ -144,7 +144,7 @@
144
144
  Studio Logcat style). The wrap owns the border + padding + focus ring; the input inside
145
145
  is chromeless so pills + draft read as one control. Pills flex-wrap onto more lines when
146
146
  the query is long. */
147
- .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; }
147
+ .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 48px 4px 6px; cursor:text; }
148
148
  .ffilterwrap:focus-within { border-color:var(--accent); }
149
149
  .ffilterwrap .ffilter { flex:1; min-width:80px; background:transparent; border:none; padding:3px 4px; font:inherit; font-size:12.5px; color:var(--text); }
150
150
  .ffilterwrap .ffilter:focus { outline:none; }
@@ -157,8 +157,21 @@
157
157
  .ffilterwrap:has(.fpill) .ffilter { min-width:28ch; }
158
158
  .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; }
159
159
  .feedbar input:focus { outline:none; border-color:var(--accent); }
160
- .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; }
160
+ .ffilterclear { position:absolute; right:32px; 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; }
161
161
  .ffilterclear:hover { color:#fff; background:var(--error-2); }
162
+ /* The ? is the standing way in to the syntax; the placeholder only hints at it and vanishes
163
+ the moment somebody types. The legend opens under the box so it reads next to the input. */
164
+ .fhelp { position:absolute; right:8px; top:8px; cursor:pointer; color:var(--muted-2); border:1px solid var(--border-3); border-radius:50%; width:16px; height:16px; line-height:14px; text-align:center; font-size:10px; font-weight:600; user-select:none; }
165
+ .fhelp:hover, .fhelp.open { color:var(--text); border-color:var(--accent); }
166
+ /* Focus is the pill's ring, so it reads as focus and not as "open". */
167
+ .fhelp:focus-visible { outline:2px solid var(--accent); outline-offset:1px; }
168
+ /* Anchored to the box's left edge: the box is the wide element on the bar, so the legend has
169
+ room to its right and never runs off the viewport on a narrow window. */
170
+ .fhelppop { position:absolute; left:0; top:calc(100% + 4px); z-index:5; display:grid; grid-template-columns:auto 1fr; gap:4px 12px; max-width:min(460px, 90vw); background:var(--surface); border:1px solid var(--border-3); border-radius:8px; padding:8px 10px; font-size:12px; color:var(--text); box-shadow:0 4px 16px var(--shadow); cursor:default; }
171
+ /* --accent-text, not --accent: the accent lands near 3.4:1 on the light surface, and the same
172
+ call is made for the other small accent text in this file. */
173
+ .fhelppop code { color:var(--accent-text); font-size:11.5px; white-space:nowrap; }
174
+ .fhelppop .fhelpnote { grid-column:1 / -1; color:var(--muted-2); padding-top:2px; }
162
175
  /* The draft input turns amber when its own text is an invalid regex mid-typing. Committed
163
176
  terms use the per-pill amber (.fpill-bad) instead. */
164
177
  .ffilterwrap:has(.ffilter.finvalid) { border-color:var(--warn); }
@@ -317,6 +330,36 @@
317
330
  .dbout tr:hover td { background:var(--hover); }
318
331
  .dbout tr { cursor:pointer; }
319
332
  .dbout tr.rowsel td { background:var(--sel-soft); }
333
+ /* Sortable column headers in the results grid. .dbsortable only lands on headers the DB grid
334
+ renders, so the flags table (which reuses .dbout but builds its own header row) picks up none of
335
+ this. Every header owns a direction slot at all times, a dim ↕ when unsorted, which is what
336
+ holds the column boundaries still across a click: measured, 0.00px of movement on every column.
337
+ The slot's fixed width is insurance on top of that, for a fallback font whose glyph advances
338
+ differ; this stack is monospace, so they do not.
339
+ Three colour decisions, each measured against the surface the element actually sits on:
340
+ - the sorted column is --accent-text, not --accent. On light, #0e9f6e is 3.39:1 against the
341
+ header's --surface, under WCAG AA's 4.5:1 for text this size; #0a7d56 is 5.15:1. Dark is
342
+ 9.62:1 either way. Same reasoning as --warn-text above.
343
+ - the slot's three states are a colour progression, not an alpha one. At opacity .3 the
344
+ resting ↕ measured 1.61:1, under the 3:1 floor for a state indicator, and it is the only
345
+ at-rest sign that a header is clickable. As --muted it is 4.55:1 light and 3.52:1 dark.
346
+ - hover is a BACKGROUND change so the SORTED column gets feedback too. The colour rules have
347
+ to exclude .sorted, because hover is the more specific selector and would otherwise
348
+ overwrite the sorted colour and de-highlight the very column being pointed at, which left
349
+ the clearing click with no hover response at all. Brightening instead is not available:
350
+ --accent on light is dimmer than --accent-text. The cost is that hovering the sorted column
351
+ is the tightest state in the feature, 4.52:1 on light, 0.02 over the floor. */
352
+ .dbout th.dbsortable:hover { background:var(--hover-soft); }
353
+ .dbout th.dbsortable:not(.sorted):hover { color:var(--text); }
354
+ .dbout th.sorted { color:var(--accent-text); }
355
+ .dbout th .dbsortdir { display:inline-block; width:9px; margin-left:5px; font-size:10px; vertical-align:1px; text-align:center; color:var(--muted); }
356
+ .dbout th.dbsortable:not(.sorted):hover .dbsortdir { color:var(--text); }
357
+ .dbout th.sorted .dbsortdir { color:var(--accent-text); }
358
+ /* Brighter than the --muted meta text it sits inside: this is the only place the grid says what a
359
+ sort covered, and --muted against the page's --bg measures 3.84:1 on dark. --muted-2 is 7.11:1
360
+ there and 6.89:1 on light. Its separating space is in the TEXT rather than a margin here, so the
361
+ line also reads correctly when it is copied or read aloud. */
362
+ .dbsortnote { color:var(--muted-2); }
320
363
  /* DB dock -- docked right of the grid, shared by the row detail and the query history via
321
364
  tabs; the split shrinks the grid to make room. Mirrors the feed's .stage.split layout. */
322
365
  .dbsplit { flex:1; min-height:0; display:flex; gap:14px; align-items:stretch; }
@@ -8,7 +8,7 @@ import { html } from "./html.js";
8
8
  import { render } from "preact";
9
9
  import { useState, useEffect, useCallback, useRef } from "preact/hooks";
10
10
  import { useStoreValue } from "./hooks.js";
11
- import { store, MODES, modeServed, describeConstraints, AUTO_REARM_MAX_FAILS } from "./store.js";
11
+ import { store, MODES, modeServed, describeConstraints, AUTO_REARM_MAX_FAILS, specForTab } from "./store.js";
12
12
  import { SOURCES } from "./registry.js";
13
13
  import { Feed } from "./feed.js";
14
14
  import { Cards } from "./widgets.js";
@@ -303,18 +303,21 @@ export function Header({ screenOpen, onScreenToggle }) {
303
303
  </h1>
304
304
  `;
305
305
  }
306
- function ModeBar() {
306
+ export function ModeBar() {
307
307
  const [, force] = useState(0);
308
308
  useEffect(() => store.on("spec", () => force((n) => n + 1)), []);
309
309
  const deviceSources = useStoreValue(store, "sources", () => store.deviceSources);
310
310
  const activeKey = store.activeModeKey();
311
- const pick = (specToPush) => store.setSpec(specToPush);
311
+ const pick = (specToPush) => store.setSpec(specForTab(specToPush, store.spec, store.lastLogLevel));
312
312
  const serves = (m) => modeServed(m.key, deviceSources);
313
313
  // A device switch can hide the active tab (leaner build). Reset to the first tab so the
314
- // user is never stranded on an invisible mode rendering a dead feed.
314
+ // user is never stranded on an invisible mode rendering a dead feed. Through specForTab like
315
+ // every other preset push, so the level floor rides along: Live carries log rows, so a bare
316
+ // MODES[0].spec would not just skip the floor for this one push, applySpec would also forget
317
+ // it (lastLogLevel back to ""), and the next Logs click would start at VERBOSE.
315
318
  useEffect(() => {
316
319
  if (activeKey && activeKey !== "__custom__" && !modeServed(activeKey, deviceSources)) {
317
- store.setSpec(MODES[0].spec);
320
+ store.setSpec(specForTab(MODES[0].spec, store.spec, store.lastLogLevel));
318
321
  }
319
322
  }, [deviceSources, activeKey]);
320
323
  // Group modes by source kind for visual separation
@@ -325,7 +328,7 @@ function ModeBar() {
325
328
  ${streamModes.map((m) => html `<button class=${"modebtn" + (activeKey === m.key ? " active" : "")} onClick=${() => pick(m.spec)}>${m.label}</button>`)}
326
329
  ${stateModes.length > 0 ? html `<span class="modedivider"></span>` : null}
327
330
  ${stateModes.map((m) => html `<button class=${"modebtn" + (activeKey === m.key ? " active" : "")} onClick=${() => pick(m.spec)}>${m.label}</button>`)}
328
- ${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}
331
+ ${store.lastCustomSpec ? html `<button class=${"modebtn custom" + (activeKey === "__custom__" ? " active" : "")} title="pushed from a terminal Claude Code session; persists until refresh" onClick=${() => store.setSpec(store.lastCustomSpec)}>✎ ${store.lastCustomSpec.title || "Custom"}</button>` : null}
329
332
  </div>
330
333
  `;
331
334
  }
@@ -438,7 +441,8 @@ function App() {
438
441
  if (next === cur)
439
442
  return;
440
443
  const nextKey = keys[next];
441
- const nextSpec = nextKey === "__custom__" ? store.lastCustomSpec : MODES.find((m) => m.key === nextKey)?.spec;
444
+ const preset = MODES.find((m) => m.key === nextKey)?.spec;
445
+ const nextSpec = nextKey === "__custom__" ? store.lastCustomSpec : preset && specForTab(preset, store.spec, store.lastLogLevel);
442
446
  if (nextSpec)
443
447
  store.setSpec(nextSpec);
444
448
  e.preventDefault();
@@ -9,7 +9,7 @@
9
9
  // point-in-time, not a live feed; pulling the store would start the SSE engine + timers on a
10
10
  // tab that has no use for them. It carries its own keyboard nav since there is no Feed here.
11
11
  import { html } from "./html.js";
12
- import { useState, useEffect, useCallback, useRef } from "preact/hooks";
12
+ import { useState, useEffect, useCallback, useMemo, useRef } from "preact/hooks";
13
13
  import { useLatestRef, useGlobalKeydown } from "./hooks.js";
14
14
  // --- query history ---
15
15
  // The queries you ran by hand in this tab, newest-first, per database AND per profile (the same
@@ -144,6 +144,88 @@ function copyText(text, e) {
144
144
  btn.textContent = "copied ✓";
145
145
  setTimeout(() => (btn.textContent = prev), 1200);
146
146
  }
147
+ // The words SQLite refuses as a bare table name in a FROM clause. Deliberately NOT its full
148
+ // keyword list: most SQLite keywords are still legal identifiers, and measuring the difference
149
+ // matters here because every unnecessary quote brings back the swallowing described below. Each
150
+ // of the 147 documented keywords was created as a table and selected from bare; these 58 failed
151
+ // and the other 89 (`key`, `row`, `end`, `filter`, `view`, `match` and the rest) parsed fine.
152
+ // If a later SQLite reserves another word, that name gets a syntax error the moment it is
153
+ // clicked, which is visible and immediate rather than a wrong answer.
154
+ const SQLITE_RESERVED = new Set(("ADD ALL ALTER AND AS AUTOINCREMENT BETWEEN CASE CHECK COLLATE COMMIT CONSTRAINT CREATE " +
155
+ "DEFAULT DEFERRABLE DELETE DISTINCT DROP ELSE ESCAPE EXCEPT EXISTS FOREIGN FROM GROUP " +
156
+ "HAVING IN INDEX INSERT INTERSECT INTO IS ISNULL JOIN LIMIT NOT NOTHING NOTNULL NULL ON " +
157
+ "OR ORDER PRIMARY REFERENCES RETURNING SELECT SET TABLE THEN TO TRANSACTION UNION UNIQUE " +
158
+ "UPDATE USING VALUES WHEN WHERE").split(" "));
159
+ // A bare table name: the identifier shape SQLite accepts without quotes. Any byte at or above 0x80
160
+ // counts as a name character, so a non-ASCII table name needs no quotes either. `$` counts too, but
161
+ // only after the first character: measured, `a$b` and `a$` select bare while `$b` is a syntax error.
162
+ const BARE_NAME = /^[A-Za-z_\u0080-\uFFFF][A-Za-z0-9_$\u0080-\uFFFF]*$/;
163
+ // How a table name is written into the generated SELECT. A plain word goes in bare, because
164
+ // quotes around it swallow whatever is typed beside them: `SELECT * FROM "items" LIMIT 100`
165
+ // edited into `... FROM "items WHERE id='1'" LIMIT 100` asks for a table named
166
+ // `items WHERE id='1'`, and sqlite answers "no such table", which reads as though the table
167
+ // vanished rather than as a clause in the wrong place. A name that cannot stand bare keeps its
168
+ // quotes, with any embedded quote doubled, which is SQL's own escape. Quotes are the fallback
169
+ // because a quoted identifier is always legal, and the set above is kept tight so the fallback
170
+ // stays rare.
171
+ export function tableRef(name) {
172
+ return BARE_NAME.test(name) && !SQLITE_RESERVED.has(name.toUpperCase())
173
+ ? name
174
+ : '"' + name.replace(/"/g, '""') + '"';
175
+ }
176
+ // A cell with nothing in it. SQLite columns are dynamically typed, so one column holds numbers,
177
+ // text and NULL at once. `undefined` is here for a caller passing rows that do not all carry the
178
+ // same columns; /dbquery cannot produce that, because sqlite3 -json emits every key on every row.
179
+ //
180
+ // Whitespace-only text counts as blank, for two reasons. The grid renders cells into `<td>`, where
181
+ // HTML collapses whitespace, so such a cell IS an empty cell to the reader the sort is for. And it
182
+ // keeps whitespace away from `numericValue`, where `Number("")` is 0, which would rank a
183
+ // blank-looking cell as zero ahead of every real number ascending.
184
+ function isBlank(v) {
185
+ return v === null || v === undefined || (typeof v === "string" && v.trim() === "");
186
+ }
187
+ // One collator for the whole module. Building one per comparison costs 222ms to sort a 10000-row
188
+ // text column against 15ms for a cached one, measured, and a sort runs on the UI thread.
189
+ const COLLATOR = new Intl.Collator(undefined, { numeric: true });
190
+ // A cell's numeric value, when it has one. Not just typeof number: SQLite columns are dynamically
191
+ // typed and a column of numbers stored as TEXT is ordinary, so `"1.09"` has to rank as 1.09. Text
192
+ // collation gets those wrong even with numeric:true, because it reads digit runs rather than values:
193
+ // measured, it puts `1.09` after `1.5` and `-3` before `-5`. A value only counts as numeric when the
194
+ // WHOLE string is a finite number, so `item9` still takes the text path and stays ahead of `item10`.
195
+ function numericValue(v) {
196
+ if (typeof v === "number")
197
+ return Number.isFinite(v) ? v : null;
198
+ if (typeof v !== "string")
199
+ return null;
200
+ const n = Number(v.trim());
201
+ return Number.isFinite(n) ? n : null;
202
+ }
203
+ // A copy of `rows` ordered by `col`.
204
+ //
205
+ // Three bands, in this order: values that are numbers, then everything else, then blanks. The
206
+ // direction reorders values WITHIN a band and never reshuffles the bands, so blanks stay at the
207
+ // bottom and numbers stay ahead of text whichever way the column points. Blanks sink because "no
208
+ // value" is not a value to rank, and because a descending sort whose first screen is empty cells
209
+ // hides the rows the sort was for. Text compares with numeric collation, which keeps `item9` ahead of
210
+ // `item10`. Array.prototype.sort is stable, so rows that tie keep the order the query returned them
211
+ // in, which is what the third click goes back to.
212
+ export function sortRows(rows, col, dir) {
213
+ return rows.slice().sort((x, y) => {
214
+ const xv = x[col];
215
+ const yv = y[col];
216
+ const xb = isBlank(xv);
217
+ const yb = isBlank(yv);
218
+ if (xb || yb)
219
+ return xb && yb ? 0 : xb ? 1 : -1;
220
+ const xn = numericValue(xv);
221
+ const yn = numericValue(yv);
222
+ if (xn !== null && yn !== null)
223
+ return dir * (xn < yn ? -1 : xn > yn ? 1 : 0);
224
+ if ((xn === null) !== (yn === null))
225
+ return xn !== null ? -1 : 1;
226
+ return dir * COLLATOR.compare(String(xv), String(yv));
227
+ });
228
+ }
147
229
  export function DbBrowser({ spec }) {
148
230
  const [user, setUser] = useState(null);
149
231
  const [dbs, setDbs] = useState(null); // null = loading
@@ -152,9 +234,13 @@ export function DbBrowser({ spec }) {
152
234
  const [sql, setSql] = useState("");
153
235
  const [out, setOut] = useState({ msg: "pick a database, then a table" });
154
236
  const [meta, setMeta] = useState("");
155
- // The result row whose full detail is open in the dock. Cleared whenever a new query runs,
156
- // since a stale row index would point into the old result set.
237
+ // The result row whose full detail is open in the dock. Held as the row itself rather than its
238
+ // position, because sorting moves the position while the open row stays the same row. Cleared
239
+ // whenever a new query runs, since a row from the old result set has nothing to point at.
157
240
  const [selectedRow, setSelectedRow] = useState(null);
241
+ // How the grid is ordered. Cleared when a new result ARRIVES rather than when a query is sent, so
242
+ // an earlier answer landing late cannot inherit an ordering chosen for a different result.
243
+ const [sort, setSort] = useState(null);
158
244
  // What the right-hand dock is showing, if anything. Row detail and query history share one
159
245
  // dock (tabbed) so the results grid never has to give up width to two panels at once.
160
246
  const [dock, setDock] = useState(() => (readDockPref() ? "history" : null));
@@ -251,6 +337,7 @@ export function DbBrowser({ spec }) {
251
337
  setOut({ error: r.error });
252
338
  return; // a rejected query is not worth remembering
253
339
  }
340
+ setSort(null); // see the state declaration for why this is here and not before the request
254
341
  // Recorded on any answer the server accepted, 0 rows included -- an empty result is a
255
342
  // legitimate query you may well want to run again.
256
343
  if (record)
@@ -271,8 +358,39 @@ export function DbBrowser({ spec }) {
271
358
  setOut({ error: "network error running query" });
272
359
  }
273
360
  }, [db, sql, user, userQS]);
361
+ // Clicking a column header walks it: ascending, then descending, then back to the order the query
362
+ // returned. Clicking a different header starts that column ascending. Nothing here touches the
363
+ // query or the device: it is grid state over the rows already on screen, which is why it is instant
364
+ // and why the grid says what it covered.
365
+ const cycleSort = useCallback((col) => {
366
+ setSort((s) => (!s || s.col !== col ? { col, dir: 1 } : s.dir === 1 ? { col, dir: -1 } : null));
367
+ }, []);
368
+ // The rows as the grid shows them. Memoized on the rows and the sort so scrolling, opening a row,
369
+ // or typing in the SQL box does not re-sort a big result on every render.
370
+ const shown = useMemo(() => (out.rows && out.rows.length && sort ? sortRows(out.rows, sort.col, sort.dir) : out.rows), [out.rows, sort]);
371
+ // Column set comes from the rows AS THEY ARRIVED, never from the sorted copy, so which row landed
372
+ // first cannot change which columns the grid has. /dbquery cannot actually send rows with
373
+ // different keys, since sqlite3 -json emits every key on every row, but Grid takes the rows it is
374
+ // given and this makes the header set independent of their order either way.
375
+ const cols = useMemo(() => (out.rows && out.rows.length ? Object.keys(out.rows[0]) : []), [out.rows]);
376
+ // The scope, said in rendered text beside the row count rather than in a tooltip, because a sorted
377
+ // column normally implies the whole result and this one covers the rows on screen. Said every time
378
+ // a sort is in effect rather than only when something looks unusual.
379
+ //
380
+ // It states coverage and stops there. Naming what was left out would be a claim about the query,
381
+ // and nothing here can tell whether anything WAS left out: `LIMIT 100` that hands back 14 rows
382
+ // truncated nothing, so "not the whole result" is false exactly as often as it is useful. The
383
+ // reason a reader needs, that `LIMIT` with no ORDER BY returns a storage-order prefix and so the
384
+ // top row after sorting by time can be the newest of an OLD hundred, is in the header tooltip,
385
+ // where it is advice about the next click rather than an assertion about this result.
386
+ //
387
+ // Only rendered when there are rows, so it cannot sit beside a stale count while a query is in
388
+ // flight or after one has failed.
389
+ const sortScope = sort && out.rows && out.rows.length
390
+ ? html `<span class="dbsortnote"> · sorted these ${out.rows.length} rows</span>`
391
+ : null;
274
392
  const pickTable = useCallback((t) => {
275
- const q = 'SELECT * FROM "' + t + '" LIMIT 100';
393
+ const q = "SELECT * FROM " + tableRef(t) + " LIMIT 100";
276
394
  setSql(q);
277
395
  run(q, false); // generated, not typed: keep it out of the history
278
396
  }, [run]);
@@ -325,6 +443,17 @@ export function DbBrowser({ spec }) {
325
443
  if (el && el.scrollIntoView)
326
444
  el.scrollIntoView({ block: "nearest" });
327
445
  }, [pane, dbIdx, tblIdx, histIdx]);
446
+ // The results pane scrolls and its header is sticky, so a sort is one click away however deep you
447
+ // are. Reordering under a scrolled viewport leaves you in the middle of the new order looking at an
448
+ // arbitrary slice, with the rows the sort was for off-screen above. Go back to the top, which is
449
+ // where the answer now is. Keyed on the rows as well as the sort, because a new result is the other
450
+ // way the content under the viewport changes completely, and it should not matter which of the two
451
+ // put different rows there.
452
+ const outRef = useRef(null);
453
+ useEffect(() => {
454
+ if (outRef.current)
455
+ outRef.current.scrollTop = 0;
456
+ }, [sort, out.rows]);
328
457
  // Keyboard navigation. The latest lists/indices/handlers live in a ref so the single window
329
458
  // listener (attached once by useGlobalKeydown) never goes stale. Mirrors the PoC's
330
459
  // stale-closure-ref pattern, now via the shared Foundation hooks.
@@ -496,23 +625,28 @@ export function DbBrowser({ spec }) {
496
625
  </button>`
497
626
  : null}
498
627
  </div>
499
- <div class="dbmeta">${meta}</div>
628
+ <div class="dbmeta">${meta}${sortScope}</div>
500
629
  <div class=${"dbsplit" + (dock ? " open" : "")}>
501
- <div class="dbout">
630
+ <div class="dbout" ref=${outRef}>
502
631
  ${out.msg
503
632
  ? html `<div class="msg">${out.msg}</div>`
504
633
  : out.error
505
634
  ? html `<div class="msg err">${out.error}</div>`
506
- : !out.rows || !out.rows.length
635
+ : !shown || !shown.length
507
636
  ? html `<div class="msg">0 rows</div>`
508
637
  : html `<${Grid}
509
- rows=${out.rows}
510
- selectedIndex=${dock === "row" && selectedRow ? selectedRow.index : -1}
511
- onSelect=${(row, index) => {
638
+ rows=${shown}
639
+ cols=${cols}
640
+ sort=${sort}
641
+ onSort=${cycleSort}
642
+ selectedRow=${dock === "row" ? selectedRow : null}
643
+ onSelect=${(row) => {
512
644
  // Clicking the open row again closes it; the dock then falls back to
513
- // history if that is where you had it.
514
- const same = dock === "row" && selectedRow && selectedRow.index === index;
515
- setSelectedRow(same ? null : { row, index });
645
+ // history if that is where you had it. Compared by row, not by position,
646
+ // so a sort between the two clicks cannot make them look like different
647
+ // rows (or make two different rows look like the same one).
648
+ const same = dock === "row" && selectedRow === row;
649
+ setSelectedRow(same ? null : row);
516
650
  setDock(same ? (readDockPref() ? "history" : null) : "row");
517
651
  }}
518
652
  />`}
@@ -534,7 +668,7 @@ export function DbBrowser({ spec }) {
534
668
  <span class="x" title="close" onClick=${closeDock}>✕</span>
535
669
  </div>
536
670
  ${dock === "row" && selectedRow
537
- ? html `<${RowInspector} row=${selectedRow.row} />`
671
+ ? html `<${RowInspector} row=${selectedRow} />`
538
672
  : html `<${HistoryPanel}
539
673
  entries=${history}
540
674
  focusIdx=${pane === "hist" ? histIdx : -1}
@@ -552,17 +686,42 @@ export function DbBrowser({ spec }) {
552
686
  </div>
553
687
  `;
554
688
  }
555
- function Grid({ rows, selectedIndex, onSelect, }) {
556
- const cols = Object.keys(rows[0]);
689
+ function Grid({ rows, cols, selectedRow, onSelect, sort, onSort, }) {
690
+ // What the next click does, and what it will cover, at the control rather than only on the meta
691
+ // line. The remedy is here too: nothing else tells a reader that the wider question is theirs to
692
+ // ask, and it is knowable without inspecting anything.
693
+ //
694
+ // No aria-describedby pointing at the scope note. It was tried and measured worse: a description
695
+ // SUPERSEDES the title in the accessible name computation, so the action copy disappeared from the
696
+ // accessibility tree exactly where it stops being guessable, and pointing every header at one
697
+ // result-wide note described eleven unsorted columns as sorted. The note is rendered text either
698
+ // way, so a reader meets it; it is just not wired to the control.
699
+ const hint = (dir) => dir === null
700
+ ? "sort ascending, these rows only. Add ORDER BY to the query to sort everything"
701
+ : dir === 1
702
+ ? "sort descending, these rows only. Add ORDER BY to the query to sort everything"
703
+ : "clear the sort";
557
704
  return html `
558
705
  <table>
559
706
  <thead>
560
707
  <tr>
561
- ${cols.map((c) => html `<th>${c}</th>`)}
708
+ ${cols.map((c) => {
709
+ // One read of the sort per header, which every other attribute derives from: null means
710
+ // this column is not the sorted one.
711
+ const dir = sort !== null && sort.col === c ? sort.dir : null;
712
+ return html `<th
713
+ class=${"dbsortable" + (dir === null ? "" : " sorted")}
714
+ title=${hint(dir)}
715
+ aria-sort=${dir === null ? "none" : dir === 1 ? "ascending" : "descending"}
716
+ onClick=${() => onSort(c)}
717
+ >
718
+ ${c}<span class="dbsortdir" aria-hidden="true">${dir === null ? "↕" : dir === 1 ? "▲" : "▼"}</span>
719
+ </th>`;
720
+ })}
562
721
  </tr>
563
722
  </thead>
564
723
  <tbody>
565
- ${rows.map((row, i) => html `<tr class=${i === selectedIndex ? "rowsel" : ""} onClick=${() => onSelect(row, i)}>
724
+ ${rows.map((row) => html `<tr class=${row === selectedRow ? "rowsel" : ""} onClick=${() => onSelect(row)}>
566
725
  ${cols.map((c) => html `<td title=${String(row[c] ?? "")}>${String(row[c] ?? "")}</td>`)}
567
726
  </tr>`)}
568
727
  </tbody>
@@ -5,8 +5,8 @@
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, specForTab } from "./store.js";
9
+ import { STREAM_KINDS, LOG_LEVEL_ORDER, levelRank } from "./registry.js";
10
10
  import { parseFilter, tokenize, isCompleteTerm, isQuote } from "./filter.js";
11
11
  const ROW_H = 24;
12
12
  const OVERSCAN = 10;
@@ -94,7 +94,7 @@ function sortOptionsFor(source) {
94
94
  opts.push({ key: "status", label: "status code (high→low)", get: (e) => Number(e.status_code), dir: "desc" });
95
95
  }
96
96
  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" });
97
+ opts.push({ key: "severity", label: "severity (errors first)", get: (e) => levelRank(e.level), dir: "desc" });
98
98
  if (source === "rtm")
99
99
  opts.push({ key: "evtype", label: "event type (A→Z)", get: (e) => e.event_type || "", dir: "asc" });
100
100
  if (source === "clog")
@@ -192,6 +192,22 @@ export function Feed({ spec, onInspect, selectedId }) {
192
192
  const [filter, setFilterState] = useState(() => FEED_PREFS.filter);
193
193
  const [sort, setSortState] = useState(() => FEED_PREFS.sortBySource[source || ""] || "newest");
194
194
  const [paused, setPaused] = useState(false);
195
+ const [helpOpen, setHelpOpen] = useState(false);
196
+ // The legend closes on a press anywhere outside it, the way the combobox lists do, so it never
197
+ // has to be hunted down again once read. Presses inside it are left alone so its examples can
198
+ // be selected and copied.
199
+ useEffect(() => {
200
+ if (!helpOpen || typeof document === "undefined" || !document.addEventListener)
201
+ return;
202
+ const onDown = (e) => {
203
+ const t = e.target;
204
+ if (t && typeof t.closest === "function" && t.closest(".fhelp, .fhelppop"))
205
+ return;
206
+ setHelpOpen(false);
207
+ };
208
+ document.addEventListener("mousedown", onDown);
209
+ return () => document.removeEventListener("mousedown", onDown);
210
+ }, [helpOpen]);
195
211
  const setFilter = useCallback((v) => {
196
212
  FEED_PREFS.filter = v;
197
213
  setFilterState(v);
@@ -326,10 +342,12 @@ export function Feed({ spec, onInspect, selectedId }) {
326
342
  });
327
343
  return off;
328
344
  }, [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 || "");
345
+ // Rebuild when the SERVER-SIDE filter (match/bodyContains/minLevel) changes -- that changes
346
+ // what store.matches() admits, so the whole snapshot must refresh. Keyed so it only fires on a
347
+ // real filter change, not every spec poll. minLevel is part of the key because the level
348
+ // selector's first live test left 289 rows of INFO and DEBUG on screen under "level ≥ ERROR":
349
+ // new frames were filtered, the rows already rendered were not.
350
+ const matchKey = JSON.stringify(spec.match || {}) + "|" + (spec.bodyContains || "") + "|" + (spec.minLevel || "");
333
351
  useEffect(() => {
334
352
  forceSnap();
335
353
  }, [matchKey]);
@@ -676,6 +694,19 @@ export function Feed({ spec, onInspect, selectedId }) {
676
694
  delete next.match;
677
695
  store.setSpec(next, { local: true });
678
696
  }, [spec]);
697
+ // The level selector writes the spec, the way the app selector does, so the choice survives a
698
+ // reload, shows as a chip, and an agent-authored spec can set the same field. VERBOSE is the
699
+ // floor of the order, so it is stored as no field at all rather than as a value that filters
700
+ // nothing.
701
+ const curLevel = (typeof spec.minLevel === "string" && spec.minLevel) || LOG_LEVEL_ORDER[0];
702
+ const changeLevel = useCallback((v) => {
703
+ const next = JSON.parse(JSON.stringify(spec));
704
+ if (v === LOG_LEVEL_ORDER[0])
705
+ delete next.minLevel;
706
+ else
707
+ next.minLevel = v;
708
+ store.setSpec(next, { local: true });
709
+ }, [spec]);
679
710
  // build only the visible slice
680
711
  const slice = [];
681
712
  for (let i = first; i < last; i++) {
@@ -778,7 +809,9 @@ export function Feed({ spec, onInspect, selectedId }) {
778
809
  // Click anywhere in the wrap that is NOT a pill focuses the draft input (matches
779
810
  // browser input behavior: the whole wrap reads as one field).
780
811
  const target = e.target;
781
- if (target && typeof target.closest === "function" && target.closest(".fpill"))
812
+ // The legend and its button are left alone too: focusing the input on the click that ends
813
+ // a drag-select would drop the selection somebody just made in the legend.
814
+ if (target && typeof target.closest === "function" && target.closest(".fpill, .fhelp, .fhelppop"))
782
815
  return;
783
816
  const inp = filterRef.current;
784
817
  if (inp && typeof inp.focus === "function")
@@ -900,14 +933,16 @@ export function Feed({ spec, onInspect, selectedId }) {
900
933
  setPillsAndDraft(pills.slice(0, -1), last);
901
934
  }
902
935
  else if (e.key === "Escape") {
936
+ setHelpOpen(false);
903
937
  el.blur();
904
938
  }
905
939
  else if ((e.key === "ArrowLeft" || e.key === "ArrowRight") && el.value === "") {
906
940
  e.preventDefault();
907
941
  el.blur();
908
942
  const ns = neighborTabSpec(e.key === "ArrowRight" ? 1 : -1);
943
+ // Presets carry the level floor the way a tab click does; the Custom spec is pushed as is.
909
944
  if (ns)
910
- store.setSpec(ns);
945
+ store.setSpec(ns === store.lastCustomSpec ? ns : specForTab(ns, store.spec, store.lastLogLevel));
911
946
  }
912
947
  }}
913
948
  onInput=${(e) => {
@@ -919,7 +954,32 @@ export function Feed({ spec, onInspect, selectedId }) {
919
954
  setPillsAndDraft(pills, v);
920
955
  }} />
921
956
  ${filter ? html `<span class="ffilterclear" title="clear all" onClick=${() => setFilter("")}>✕</span>` : null}
957
+ <span class=${"fhelp" + (helpOpen ? " open" : "")} title="filter syntax help" role="button" tabindex="0"
958
+ aria-label="filter syntax help" aria-expanded=${helpOpen} aria-controls=${helpOpen ? "fhelppop" : undefined}
959
+ onMouseDown=${(e) => e.preventDefault()}
960
+ onClick=${() => setHelpOpen((o) => !o)}
961
+ onKeyDown=${(e) => {
962
+ // A span does not synthesize a click from Enter or Space the way a button does, so the
963
+ // keys are handled here; assistive tech sends a real click, handled above.
964
+ if (e.key === "Enter" || e.key === " ") {
965
+ e.preventDefault();
966
+ setHelpOpen((o) => !o);
967
+ }
968
+ else if (e.key === "Escape")
969
+ setHelpOpen(false);
970
+ }}>?</span>
971
+ ${helpOpen ? html `<div class="fhelppop" id="fhelppop" role="note">
972
+ <code>error</code><span>rows containing it (case does not matter)</span>
973
+ <code>error timeout</code><span>rows containing both, in any order</span>
974
+ <code>"not found"</code><span>rows containing that phrase</span>
975
+ <code>-heartbeat</code><span>hide rows containing it</span>
976
+ <code>"-1"</code><span>a literal - or / goes in quotes</span>
977
+ <code>/^Fetch/</code><span>a regular expression</span>
978
+ ${source === "all" ? html `<code>-log</code><span>hide every row of a kind (log, clog, trace, rtm, network)</span>` : null}
979
+ ${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}
980
+ </div>` : null}
922
981
  </span>
982
+ ${isLogish ? html `<label class="fsortlbl" title=${source === "all" ? "show log lines at this level or above. Rows of other kinds 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}
923
983
  ${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
984
  <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>
925
985
  <button class=${"fbtn" + (paused ? " paused" : "")} title="pause / resume the live feed" onClick=${() => setPaused((p) => !p)}>${paused ? "▶ resume" : "⏸ pause"}</button>
@@ -10,12 +10,16 @@ function Chips({ spec }) {
10
10
  const items = Object.entries(m).map(([k, v]) => ({ k, v, kind: "match" }));
11
11
  if (spec.bodyContains)
12
12
  items.push({ k: "body contains", v: spec.bodyContains, kind: "body" });
13
+ if (typeof spec.minLevel === "string" && spec.minLevel)
14
+ items.push({ k: "level", v: "≥ " + spec.minLevel, kind: "level" });
13
15
  if (!items.length)
14
16
  return null;
15
17
  const clear = (it) => {
16
18
  const next = JSON.parse(JSON.stringify(spec));
17
19
  if (it.kind === "body")
18
20
  delete next.bodyContains;
21
+ else if (it.kind === "level")
22
+ delete next.minLevel;
19
23
  else {
20
24
  if (next.match)
21
25
  delete next.match[it.k];
@@ -74,6 +78,10 @@ export function Filters({ spec }) {
74
78
  const apply = async () => {
75
79
  const next = JSON.parse(JSON.stringify(spec));
76
80
  next.source = source;
81
+ // The level only means something where log rows are; the server rejects it elsewhere, and a
82
+ // rejection from this panel is the last thing it needs.
83
+ if (source !== "log" && source !== "all")
84
+ delete next.minLevel;
77
85
  const match = {};
78
86
  for (const r of rows)
79
87
  if (r.field && r.value.trim())
@@ -9,7 +9,10 @@ export const MATCH_FIELDS = {
9
9
  rtm: ["event_type", "direction", "channel"],
10
10
  clog: ["event_name"],
11
11
  trace: ["trace_name", "span_name"],
12
- log: ["tag", "level", "message", "pid", "package"],
12
+ // No `level` here: a substring on the level name next to the toolbar's "level ≥" floor was two
13
+ // controls with one word and different meanings. A spec that already carries match.level still
14
+ // works and still shows as a row (the row select keeps an unknown field), it is just not offered.
15
+ log: ["tag", "message", "pid", "package"],
13
16
  };
14
17
  // `all` = the union of every streaming source's fields (deduped, order-stable). Derived, not
15
18
  // hand-maintained, so adding a source's fields above surfaces them in the unified Live tab too.
@@ -31,6 +34,14 @@ export const FIELD_VALUES = {
31
34
  level: ["VERBOSE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"],
32
35
  method: ["GET", "POST", "PUT", "DELETE", "PATCH"],
33
36
  };
37
+ // Logcat priorities, lowest first: the order `minLevel` ("this priority or above") is read in.
38
+ export const LOG_LEVEL_ORDER = FIELD_VALUES.level;
39
+ // -1 for a priority the order does not know (absent, or a shape the logcat parser never
40
+ // produces), so such a row never clears a minimum. Hiding it is the visible consequence of the
41
+ // selector the person set; letting it through would show a row as if it had a priority it lacks.
42
+ export function levelRank(level) {
43
+ return LOG_LEVEL_ORDER.indexOf(String(level ?? "").toUpperCase());
44
+ }
34
45
  // SOURCE registry: one row per source. `kind` routes the view (streaming feed vs the
35
46
  // point-in-time state browser) without a hardcoded source check.
36
47
  export const SOURCES = {