@slack/radar-mcp 1.20.0 → 1.22.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.
- package/README.md +75 -17
- package/dist/mcp/api-paths.d.ts +11 -0
- package/dist/mcp/api-paths.js +56 -20
- package/dist/mcp/dashboard-identity.d.ts +6 -0
- package/dist/mcp/dashboard-identity.js +11 -0
- package/dist/mcp/index.js +138 -36
- package/dist/mcp/logs-result.d.ts +1 -0
- package/dist/mcp/logs-result.js +1 -0
- package/dist/mcp/network-detail.d.ts +5 -0
- package/dist/mcp/network-detail.js +86 -0
- package/dist/mcp/radar-export-get.d.ts +30 -0
- package/dist/mcp/radar-export-get.js +49 -0
- package/dist/mcp/radar-response.d.ts +11 -1
- package/dist/mcp/radar-response.js +23 -3
- package/dist/mcp/session-backfill.d.ts +9 -3
- package/dist/mcp/session-backfill.js +76 -17
- package/dist/mcp/session-detail.js +54 -2
- package/dist/mcp/session-enable.d.ts +1 -0
- package/dist/mcp/session-enable.js +146 -15
- package/dist/mcp/session-query.js +53 -11
- package/dist/mcp/snapshot.js +42 -26
- package/dist/mcp/sources-gate.js +5 -0
- package/dist/mcp/stale-dashboard.d.ts +23 -0
- package/dist/mcp/stale-dashboard.js +122 -0
- package/dist/mcp/switchboard-spool.d.ts +12 -0
- package/dist/mcp/switchboard-spool.js +107 -0
- package/dist/mcp/switchboard-tools.d.ts +18 -0
- package/dist/mcp/switchboard-tools.js +178 -0
- package/dist/mcp/tools.d.ts +4 -1
- package/dist/mcp/tools.js +114 -23
- package/dist/mcp/web-child-env.d.ts +4 -1
- package/dist/mcp/web-child-env.js +4 -1
- package/dist/shared/android.d.ts +43 -0
- package/dist/shared/android.js +227 -19
- package/dist/shared/constants.d.ts +19 -4
- package/dist/shared/constants.js +19 -4
- package/dist/shared/event-spool.js +3 -2
- package/dist/shared/feature-flags.d.ts +1 -0
- package/dist/shared/feature-flags.js +1 -0
- package/dist/shared/form-body.d.ts +18 -0
- package/dist/shared/form-body.js +251 -0
- package/dist/shared/ios-logs.d.ts +10 -0
- package/dist/shared/ios-logs.js +91 -0
- package/dist/shared/ios.d.ts +25 -2
- package/dist/shared/ios.js +157 -3
- package/dist/{web → shared}/log-session.d.ts +45 -31
- package/dist/shared/log-session.js +300 -0
- package/dist/shared/radar-request-raw.d.ts +7 -0
- package/dist/shared/radar-request-raw.js +89 -0
- package/dist/shared/radar-token.d.ts +25 -0
- package/dist/shared/radar-token.js +164 -0
- package/dist/shared/stream.d.ts +4 -1
- package/dist/shared/stream.js +107 -15
- package/dist/shared/switchboard-host-store.d.ts +21 -0
- package/dist/shared/switchboard-host-store.js +166 -0
- package/dist/shared/switchboard-note.d.ts +15 -0
- package/dist/shared/switchboard-note.js +92 -0
- package/dist/shared/switchboard-report-file.d.ts +5 -0
- package/dist/shared/switchboard-report-file.js +26 -0
- package/dist/shared/switchboard-report.d.ts +20 -0
- package/dist/shared/switchboard-report.js +406 -0
- package/dist/shared/switchboard.d.ts +118 -0
- package/dist/shared/switchboard.js +487 -0
- package/dist/shared/transport.d.ts +43 -3
- package/dist/shared/version.d.ts +2 -0
- package/dist/shared/version.js +18 -0
- package/dist/shared/wire.d.ts +46 -1
- package/dist/web/install-app.d.ts +57 -8
- package/dist/web/install-app.js +270 -60
- package/dist/web/macapp/RadarApp.swift +340 -22
- package/dist/web/public/index.html +216 -12
- package/dist/web/public/next/app.js +43 -22
- package/dist/web/public/next/db.js +4 -1
- package/dist/web/public/next/feed.js +604 -59
- package/dist/web/public/next/filters.js +158 -40
- package/dist/web/public/next/flags.js +3 -0
- package/dist/web/public/next/form-body.js +252 -0
- package/dist/web/public/next/inspector.js +171 -14
- package/dist/web/public/next/prefs.js +5 -2
- package/dist/web/public/next/registry.js +35 -3
- package/dist/web/public/next/store.js +947 -69
- package/dist/web/public/next/switchboard-note.js +93 -0
- package/dist/web/public/next/toast.js +9 -5
- package/dist/web/public/next/voice-model.js +712 -0
- package/dist/web/public/next/voice.js +552 -0
- package/dist/web/server.d.ts +20 -9
- package/dist/web/server.js +834 -174
- package/dist/web/spec.d.ts +11 -6
- package/dist/web/spec.js +62 -6
- package/package.json +4 -4
- package/dist/web/log-session.js +0 -166
|
@@ -5,11 +5,18 @@
|
|
|
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,
|
|
9
|
-
import {
|
|
8
|
+
import { store, shortUrl, shortPkg, MODES, modeServed, fmtNum, 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";
|
|
12
|
+
import { inSessionCut, sameSessionCut } from "./voice-model.js";
|
|
13
|
+
import { savedTurnLabel, switchboardClockLabel } from "./switchboard-note.js";
|
|
11
14
|
const ROW_H = 24;
|
|
12
15
|
const OVERSCAN = 10;
|
|
16
|
+
// How long the empty line's counts may stay behind the cache after an eviction before the next
|
|
17
|
+
// bump pays a full walk for them. At the cap every push evicts, so without this an empty view
|
|
18
|
+
// holding hidden rows walked the whole cache on every bump. See the recount below.
|
|
19
|
+
const RECOUNT_MS = 250;
|
|
13
20
|
// Feed UI prefs PERSIST across tab switches (the Feed unmounts/remounts per source). The text
|
|
14
21
|
// filter is global; sort is per-source (a Network "slowest" is meaningless on RTM).
|
|
15
22
|
const FEED_PREFS = { filter: "", sortBySource: {} };
|
|
@@ -88,7 +95,7 @@ function sortOptionsFor(source) {
|
|
|
88
95
|
{ key: "oldest", label: "oldest first", get: (e) => e.timestamp || 0, dir: "asc" },
|
|
89
96
|
];
|
|
90
97
|
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" });
|
|
98
|
+
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
99
|
if (source === "network") {
|
|
93
100
|
opts.push({ key: "slow", label: "slowest (response time)", get: (e) => Number(e.duration_ms), dir: "desc" });
|
|
94
101
|
opts.push({ key: "status", label: "status code (high→low)", get: (e) => Number(e.status_code), dir: "desc" });
|
|
@@ -99,6 +106,8 @@ function sortOptionsFor(source) {
|
|
|
99
106
|
opts.push({ key: "evtype", label: "event type (A→Z)", get: (e) => e.event_type || "", dir: "asc" });
|
|
100
107
|
if (source === "clog")
|
|
101
108
|
opts.push({ key: "name", label: "clog name (A→Z)", get: (e) => e.event_name || "", dir: "asc" });
|
|
109
|
+
if (source === "switchboard")
|
|
110
|
+
opts.push({ key: "kind", label: "kind (A→Z)", get: (e) => e.kind || "", dir: "asc" });
|
|
102
111
|
if (source === "trace") {
|
|
103
112
|
opts.push({ key: "slow", label: "slowest (duration)", get: (e) => Number(e.duration_ms), dir: "desc" });
|
|
104
113
|
opts.push({ key: "name", label: "trace name (A→Z)", get: (e) => e.trace_name || "", dir: "asc" });
|
|
@@ -119,16 +128,8 @@ function neighborTabSpec(dir) {
|
|
|
119
128
|
const k = keys[next];
|
|
120
129
|
return k === "__custom__" ? store.lastCustomSpec || undefined : MODES.find((m) => m.key === k)?.spec;
|
|
121
130
|
}
|
|
122
|
-
//
|
|
123
|
-
//
|
|
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
|
-
}
|
|
131
|
+
// searchText (the one searchable string per frame) lives in store.ts, shared with the spec's
|
|
132
|
+
// `exclude` gate so both read the same haystack.
|
|
132
133
|
// The kind handed to the filter predicate. Only the unified view exposes it: that is where the
|
|
133
134
|
// type chip is visible, so "trace" / "-log" reading as kind filters matches what the user
|
|
134
135
|
// sees. On a single-source tab every row is the same kind, so kind matching would only turn
|
|
@@ -145,8 +146,102 @@ function rawLine(ev) {
|
|
|
145
146
|
return `${t} ${ev.method || "GET"} ${shortUrl(ev.url)} ${ev.status_code ?? ""} ${ev.duration_ms ?? ""}ms`;
|
|
146
147
|
if (ev._type === "trace")
|
|
147
148
|
return `${t} ${ev.trace_name || ""} ${ev.span_name || ""} ${ev.duration_ms ?? ""}ms`;
|
|
149
|
+
if (ev._type === "switchboard")
|
|
150
|
+
return `${t} ${String(ev.session_id ?? "")} ${ev.kind || ""} ${ev.kind === "frame" ? switchboardArrow(ev.direction) + " " : ""}${switchboardSummary(ev)}`.trimEnd();
|
|
148
151
|
return `${t} ${ev._type} ${ev.event_type || ev.event_name || ""} ${ev.channel || ""}`.trimEnd();
|
|
149
152
|
}
|
|
153
|
+
// ---- switchboard rows: the record's kind, then that kind's fields read as one phrase. ----
|
|
154
|
+
// The tail of the session id: the device mints one per voice session, and the tail is what tells
|
|
155
|
+
// two sessions apart on screen. The full id is on the row's title, on the raw copy line and in the
|
|
156
|
+
// inspector.
|
|
157
|
+
export function shortSession(id) {
|
|
158
|
+
const s = String(id ?? "");
|
|
159
|
+
return s.length > 6 ? s.slice(-6) : s;
|
|
160
|
+
}
|
|
161
|
+
// Frame direction as an arrow, read from the device's point of view: incoming frames arrive from
|
|
162
|
+
// the server (←), outgoing frames leave the device (→).
|
|
163
|
+
export function switchboardArrow(direction) {
|
|
164
|
+
return direction === "incoming" ? "←" : direction === "outgoing" ? "→" : "";
|
|
165
|
+
}
|
|
166
|
+
// A state change whose destination reads as a failure. Cosmetic only (the kind badge turns red):
|
|
167
|
+
// switchboard rows carry no logcat level, so this is where a failed transition stands out.
|
|
168
|
+
export function switchboardFailed(ev) {
|
|
169
|
+
return ev.kind === "state" && /fail|error/i.test(String(ev.to ?? ""));
|
|
170
|
+
}
|
|
171
|
+
// dBFS reads better than a raw 0..1 peak: 0.05 and 0.5 both look "quiet" on a linear scale, but
|
|
172
|
+
// -26 dBFS and -6 dBFS say which one is actually louder. Floored at -60 to match the sparkline's
|
|
173
|
+
// own floor, same reason a near-zero peak doesn't round to an unreadable -80.
|
|
174
|
+
const FEED_DBFS_FLOOR = -60;
|
|
175
|
+
function fmtDbfsPeak(linear) {
|
|
176
|
+
if (linear == null)
|
|
177
|
+
return "?";
|
|
178
|
+
const v = Math.max(0, Math.min(1, linear));
|
|
179
|
+
if (v <= 0)
|
|
180
|
+
return "silent";
|
|
181
|
+
return `${Math.round(Math.max(FEED_DBFS_FLOOR, 20 * Math.log10(v)))} dBFS`;
|
|
182
|
+
}
|
|
183
|
+
// The per-kind summary after the badge: the kind's own fields by name (switchboardFields, the
|
|
184
|
+
// search haystack, lists the same ones), minus the kind (already the badge) and, for frames, minus
|
|
185
|
+
// the direction (already the arrow), with units for the numbers.
|
|
186
|
+
export function switchboardSummary(ev) {
|
|
187
|
+
const num = (v) => (typeof v === "number" ? v : undefined);
|
|
188
|
+
const text = (v) => (v == null ? "" : String(v));
|
|
189
|
+
switch (ev.kind) {
|
|
190
|
+
case "session": return text(ev.event);
|
|
191
|
+
// The state kind and the transition are set apart so a word both carry ("speaking speaking →
|
|
192
|
+
// quiet") does not read as a stutter.
|
|
193
|
+
case "state": return `${text(ev.state_kind)} · ${text(ev.from)} → ${text(ev.to)}${ev.cause ? ` (${text(ev.cause)})` : ""}`.trim();
|
|
194
|
+
// The plugin writes "unknown" for a frame it could not classify; the row says so in words (the
|
|
195
|
+
// search haystack keeps the raw token, so typing unknown still finds it).
|
|
196
|
+
case "frame": {
|
|
197
|
+
const b = num(ev.bytes);
|
|
198
|
+
return `${ev.frame_type === "unknown" ? "unknown type" : text(ev.frame_type)}${b != null ? ` ${fmtNum(b)} B` : ""}`;
|
|
199
|
+
}
|
|
200
|
+
case "phase": {
|
|
201
|
+
const d = num(ev.duration_ms);
|
|
202
|
+
return `${text(ev.phase)}${d != null ? ` ${fmtNum(d)} ms` : ""}`;
|
|
203
|
+
}
|
|
204
|
+
case "player": {
|
|
205
|
+
const g = num(ev.gap_ms), q = num(ev.bytes_queued);
|
|
206
|
+
return `${text(ev.event)}${g != null ? ` gap ${fmtNum(g)} ms` : ""}${q != null ? ` queued ${fmtNum(q)} B` : ""}`;
|
|
207
|
+
}
|
|
208
|
+
// Shows size, reach, and peak loudness, not averaged rms, since averaging would wash out
|
|
209
|
+
// the one loud spike a debugger is usually looking for.
|
|
210
|
+
case "levels": {
|
|
211
|
+
const sampleCount = num(ev.sample_count);
|
|
212
|
+
const offsets = Array.isArray(ev.offsets_ms) ? ev.offsets_ms : [];
|
|
213
|
+
const lastOffset = offsets.length ? num(offsets[offsets.length - 1]) : null;
|
|
214
|
+
// A plain loop, not Math.max(...nums): spreading a levels batch with tens of thousands of
|
|
215
|
+
// samples into function arguments blows the engine's own call-stack argument limit.
|
|
216
|
+
const maxOf = (arr) => {
|
|
217
|
+
if (!Array.isArray(arr))
|
|
218
|
+
return null;
|
|
219
|
+
let max = -Infinity;
|
|
220
|
+
let found = false;
|
|
221
|
+
for (const v of arr) {
|
|
222
|
+
if (typeof v === "number" && Number.isFinite(v)) {
|
|
223
|
+
found = true;
|
|
224
|
+
if (v > max)
|
|
225
|
+
max = v;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return found ? max : null;
|
|
229
|
+
};
|
|
230
|
+
const micPeak = maxOf(ev.mic_peak);
|
|
231
|
+
const playbackPeak = maxOf(ev.playback_peak);
|
|
232
|
+
return `${sampleCount ?? "?"} sample${sampleCount === 1 ? "" : "s"}${lastOffset != null ? ` over ${fmtNum(lastOffset)} ms` : ""}, peak mic ${fmtDbfsPeak(micPeak)} / playback ${fmtDbfsPeak(playbackPeak)}`;
|
|
233
|
+
}
|
|
234
|
+
// An unknown clock shows as sent (switchboardClockLabel passes it through).
|
|
235
|
+
case "turn": {
|
|
236
|
+
const r = num(ev.response_ms);
|
|
237
|
+
const c = typeof ev.clock === "string" ? switchboardClockLabel(ev.clock) : "";
|
|
238
|
+
return [r != null ? `${fmtNum(r)} ms` : "", c].filter(Boolean).join(", ");
|
|
239
|
+
}
|
|
240
|
+
// An unknown outcome shows as its device token, quoted unless plain (see savedTurnLabel).
|
|
241
|
+
case "saved_turn": return savedTurnLabel(ev.outcome, ev.has_thread);
|
|
242
|
+
default: return "";
|
|
243
|
+
}
|
|
244
|
+
}
|
|
150
245
|
function statusBand(c) {
|
|
151
246
|
if (!c)
|
|
152
247
|
return "";
|
|
@@ -179,6 +274,12 @@ function RowBody({ ev, source, highlight }) {
|
|
|
179
274
|
const breach = highlight && store.breaches(ev);
|
|
180
275
|
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
276
|
}
|
|
277
|
+
if ((ev._type || source) === "switchboard") {
|
|
278
|
+
const kind = ev.kind || "";
|
|
279
|
+
const arrow = kind === "frame" ? switchboardArrow(ev.direction) : "";
|
|
280
|
+
// One neutral kind pill on the tab and on Live; only a failed transition changes its colour.
|
|
281
|
+
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>`;
|
|
282
|
+
}
|
|
182
283
|
const breach = highlight && store.breaches(ev);
|
|
183
284
|
const isNet = (ev._type || source) === "network" || ev.url != null;
|
|
184
285
|
const code = Number(ev.status_code);
|
|
@@ -295,59 +396,169 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
295
396
|
// scroll, new events only bump newCount). While following with "newest" sort we prepend only
|
|
296
397
|
// the new tail (O(new), not a full O(N) rebuild over 100k) -- the 100k-buffer enabler. Full
|
|
297
398
|
// recompute() runs only on control change / resume; a non-newest sort rebuilds while tailing.
|
|
399
|
+
//
|
|
400
|
+
// The cache only ever loses entries from the front (TTL, the cap) or when the clear button or a
|
|
401
|
+
// device switch wipes it, so "what is new since the last bump" is the run after a cursor, and
|
|
402
|
+
// the length alone cannot place the cursor: at the cap a shift plus a push leaves it flat. The
|
|
403
|
+
// entry that sat at the cursor is the proof.
|
|
404
|
+
// When it is still there the run starts after it; when it moved, the run starts after wherever
|
|
405
|
+
// it went; when it is gone, everything held is new.
|
|
298
406
|
const seenLenRef = useRef(0);
|
|
407
|
+
const seenTailRef = useRef(undefined);
|
|
408
|
+
const runStart = (len, tail, cacheLen) => {
|
|
409
|
+
if (len === 0)
|
|
410
|
+
return 0;
|
|
411
|
+
if (store.cache[len - 1] === tail)
|
|
412
|
+
return len;
|
|
413
|
+
let j = Math.min(len, cacheLen) - 1;
|
|
414
|
+
while (j >= 0 && store.cache[j] !== tail)
|
|
415
|
+
j--;
|
|
416
|
+
return j + 1;
|
|
417
|
+
};
|
|
418
|
+
const markSeen = (cacheLen) => {
|
|
419
|
+
seenLenRef.current = cacheLen;
|
|
420
|
+
seenTailRef.current = store.cache[cacheLen - 1];
|
|
421
|
+
};
|
|
422
|
+
// The Switchboard tab shows only the newest session's current run (store.switchboardNewestCut(),
|
|
423
|
+
// the same rule the panel draws with); the other tabs and search see every row. The cut is
|
|
424
|
+
// tracked here because a change to it (a newer begin, a reused id's new run, the newest begin
|
|
425
|
+
// evicted) changes which rows belong in the view without touching the cache's front, the one
|
|
426
|
+
// thing the incremental cursor below can see.
|
|
427
|
+
const sbCutRef = useRef(source === "switchboard" ? store.switchboardNewestCut() : null);
|
|
428
|
+
// The empty line's running counts (see the render below for the recount). `len`/`tail` is the
|
|
429
|
+
// counts' own cursor, `parsed`/`key` the controls they were counted under.
|
|
430
|
+
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: "" });
|
|
431
|
+
// Zero the counts and mark them for a recount, for a change to which rows the view admits: the
|
|
432
|
+
// old counts were sorted under the old rule, and an empty view must not name them.
|
|
433
|
+
const resetCounts = () => {
|
|
434
|
+
const cnt = countsRef.current;
|
|
435
|
+
cnt.held = 0;
|
|
436
|
+
cnt.belowLevel = 0;
|
|
437
|
+
cnt.excluded = 0;
|
|
438
|
+
cnt.excludedByKind = 0;
|
|
439
|
+
cnt.offBox = 0;
|
|
440
|
+
cnt.waiting = 0;
|
|
441
|
+
cnt.len = store.cache.length;
|
|
442
|
+
cnt.tail = store.cache[store.cache.length - 1];
|
|
443
|
+
cnt.dirty = true;
|
|
444
|
+
cnt.stale = false;
|
|
445
|
+
};
|
|
299
446
|
useEffect(() => {
|
|
300
447
|
snapRef.current = recompute();
|
|
301
448
|
bumpSnap((n) => n + 1);
|
|
302
|
-
|
|
449
|
+
markSeen(store.cache.length);
|
|
450
|
+
sbCutRef.current = source === "switchboard" ? store.switchboardNewestCut() : null;
|
|
303
451
|
const off = store.on("feed", () => {
|
|
452
|
+
if (source === "switchboard") {
|
|
453
|
+
const cut = store.switchboardNewestCut();
|
|
454
|
+
if (!sameSessionCut(cut, sbCutRef.current)) {
|
|
455
|
+
sbCutRef.current = cut;
|
|
456
|
+
forceSnap();
|
|
457
|
+
resetCounts();
|
|
458
|
+
markSeen(store.cache.length);
|
|
459
|
+
setNewCount(0);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
304
463
|
const cacheLen = store.cache.length;
|
|
464
|
+
const startLen = runStart(seenLenRef.current, seenTailRef.current, cacheLen);
|
|
465
|
+
// The empty line's counts are kept running, so the rows that landed are sorted into them
|
|
466
|
+
// here, before the follow check: a paused tab counts too. One judgement per fresh row serves
|
|
467
|
+
// both the counts and the follow's fresh list, so a row costs one pass whether it shows or
|
|
468
|
+
// not. Rows of another source cost nothing; a row of this source that is not for this view (a
|
|
469
|
+
// log line from another tag on a tag-narrowed view) costs one passesMatch and nothing else.
|
|
470
|
+
const cnt = countsRef.current;
|
|
471
|
+
const countStart = runStart(cnt.len, cnt.tail, cacheLen);
|
|
472
|
+
// The front moved, so counted rows may be gone. Only counts that hold something can go
|
|
473
|
+
// stale that way: eviction never adds a row, so all-zero counts stay right, and an empty
|
|
474
|
+
// tab at the cap pays nothing per batch. Stale, not dirty: an eviction is the one cause
|
|
475
|
+
// that repeats on every bump at the cap, and the line can wait for it (see the recount).
|
|
476
|
+
// A clear that emptied the cache is dirty: a walk over nothing is free, and the line must
|
|
477
|
+
// not keep naming hidden rows over an empty cache until the next bump.
|
|
478
|
+
if (countStart < cnt.len && cnt.held > 0) {
|
|
479
|
+
if (cacheLen === 0)
|
|
480
|
+
cnt.dirty = true;
|
|
481
|
+
else
|
|
482
|
+
cnt.stale = true;
|
|
483
|
+
}
|
|
484
|
+
let countChanged = false;
|
|
485
|
+
const src = store.spec.source;
|
|
486
|
+
const fresh = [];
|
|
487
|
+
for (let i = Math.min(startLen, countStart); i < cacheLen; i++) {
|
|
488
|
+
const c = store.cache[i];
|
|
489
|
+
if (!c)
|
|
490
|
+
continue;
|
|
491
|
+
if (src !== "all" && c.type !== src)
|
|
492
|
+
continue;
|
|
493
|
+
if (src === "switchboard" && sbCutRef.current !== null && !inSessionCut(c.ev, sbCutRef.current))
|
|
494
|
+
continue;
|
|
495
|
+
const ev = c.ev;
|
|
496
|
+
ev._type = c.type;
|
|
497
|
+
if (!store.passesMatch(ev))
|
|
498
|
+
continue;
|
|
499
|
+
// The level is judged first (it is what the server applies), so a row both hide counts
|
|
500
|
+
// against the level; an exclusion is only blamed for rows the level let through, and the
|
|
501
|
+
// box only for rows neither of those hid, so an excluded row is never charged to the box
|
|
502
|
+
// and never waits. A kind chip's term is its own bucket where the chips exist (the Switchboard
|
|
503
|
+
// tab), so the line can name the control; anywhere else a kind: term is just an exclusion.
|
|
504
|
+
// One excludeReason per row: it is the hidden-or-not answer and the reason in one walk.
|
|
505
|
+
let bucket = "waiting";
|
|
506
|
+
if (!store.passesLevel(ev))
|
|
507
|
+
bucket = "belowLevel";
|
|
508
|
+
else {
|
|
509
|
+
const why = store.excludeReason(ev);
|
|
510
|
+
if (why)
|
|
511
|
+
bucket = why === "kind" && src === "switchboard" ? "excludedByKind" : "excluded";
|
|
512
|
+
else if (!matchParsed.empty && !matchParsed.test(searchText(ev), filterKind(ev, src)))
|
|
513
|
+
bucket = "offBox";
|
|
514
|
+
}
|
|
515
|
+
if (i >= countStart) {
|
|
516
|
+
cnt[bucket]++;
|
|
517
|
+
cnt.held++;
|
|
518
|
+
countChanged = true;
|
|
519
|
+
}
|
|
520
|
+
if (i >= startLen && bucket === "waiting")
|
|
521
|
+
fresh.push(ev);
|
|
522
|
+
}
|
|
523
|
+
cnt.len = cacheLen;
|
|
524
|
+
cnt.tail = store.cache[cacheLen - 1];
|
|
525
|
+
markSeen(cacheLen);
|
|
305
526
|
if (!followRef.current) {
|
|
306
527
|
setNewCount((c) => c + 1);
|
|
307
|
-
seenLenRef.current = cacheLen; // keep the cursor current so resume is incremental
|
|
308
528
|
return;
|
|
309
529
|
}
|
|
310
|
-
const src = store.spec.source;
|
|
311
530
|
if (sort === "newest") {
|
|
312
|
-
const startLen = Math.min(seenLenRef.current, cacheLen); // guard against eviction shrink
|
|
313
|
-
const fresh = [];
|
|
314
|
-
for (let i = startLen; i < cacheLen; i++) {
|
|
315
|
-
const c = store.cache[i];
|
|
316
|
-
if (!c)
|
|
317
|
-
continue;
|
|
318
|
-
if (src !== "all" && c.type !== src)
|
|
319
|
-
continue;
|
|
320
|
-
const ev = c.ev;
|
|
321
|
-
ev._type = c.type;
|
|
322
|
-
if (!store.matches(ev))
|
|
323
|
-
continue;
|
|
324
|
-
if (!matchParsed.empty && !matchParsed.test(searchText(ev), filterKind(ev, src)))
|
|
325
|
-
continue;
|
|
326
|
-
fresh.push(ev);
|
|
327
|
-
}
|
|
328
531
|
if (fresh.length) {
|
|
329
532
|
fresh.reverse();
|
|
330
533
|
snapRef.current = fresh.concat(snapRef.current);
|
|
331
534
|
bumpSnap((n) => n + 1);
|
|
332
535
|
}
|
|
536
|
+
else if (snapRef.current.length === 0 && (countChanged || cnt.dirty || cnt.stale)) {
|
|
537
|
+
// Nothing to show, but the empty line reads the counts on a render, so it gets one when
|
|
538
|
+
// they moved. A bump that carried no row for this view asks for nothing.
|
|
539
|
+
bumpSnap((n) => n + 1);
|
|
540
|
+
}
|
|
333
541
|
}
|
|
334
542
|
else {
|
|
335
543
|
snapRef.current = recompute();
|
|
336
544
|
bumpSnap((n) => n + 1);
|
|
337
545
|
}
|
|
338
|
-
seenLenRef.current = cacheLen;
|
|
339
546
|
const el = vpRef.current;
|
|
340
547
|
if (el)
|
|
341
548
|
el.scrollTop = 0; // glue to newest (top)
|
|
342
549
|
});
|
|
343
|
-
return
|
|
344
|
-
|
|
550
|
+
return () => {
|
|
551
|
+
off();
|
|
552
|
+
};
|
|
553
|
+
}, [forceSnap, recompute, matchParsed, sort, sortOpts]);
|
|
345
554
|
// Rebuild when the SERVER-SIDE filter (match/bodyContains/minLevel) changes -- that changes
|
|
346
555
|
// what store.matches() admits, so the whole snapshot must refresh. Keyed so it only fires on a
|
|
347
556
|
// real filter change, not every spec poll. minLevel is part of the key because the level
|
|
348
557
|
// selector's first live test left 289 rows of INFO and DEBUG on screen under "level ≥ ERROR":
|
|
349
558
|
// new frames were filtered, the rows already rendered were not.
|
|
350
|
-
|
|
559
|
+
// exclude is in the key for the same reason minLevel is: a chip removed or a term added must
|
|
560
|
+
// re-filter the rows already on screen, not only the frames that arrive afterwards.
|
|
561
|
+
const matchKey = JSON.stringify(spec.match || {}) + "|" + (spec.bodyContains || "") + "|" + (spec.minLevel || "") + "|" + JSON.stringify(spec.exclude || []);
|
|
351
562
|
useEffect(() => {
|
|
352
563
|
forceSnap();
|
|
353
564
|
}, [matchKey]);
|
|
@@ -374,6 +585,99 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
374
585
|
const frames = snapRef.current;
|
|
375
586
|
const total = frames.length;
|
|
376
587
|
const totalH = total * ROW_H;
|
|
588
|
+
// Zero rows on screen has three causes that want different lines: the store holds nothing for
|
|
589
|
+
// this view yet (say so), it holds rows the level, the exclusions or the filter box are hiding,
|
|
590
|
+
// or it holds rows that would show and are waiting behind a pause or a lock. "For this view"
|
|
591
|
+
// means the source plus the spec's `match`: on a view narrowed to one tag, log lines from other
|
|
592
|
+
// tags are not rows being hidden, they are simply not rows of this view.
|
|
593
|
+
//
|
|
594
|
+
// The counts run: the feed handler sorts each fresh row in as it lands, so a render reads them
|
|
595
|
+
// and walks nothing. The one full walk is the recount below, taken only when the view is empty
|
|
596
|
+
// and the counts are dirty: the controls changed (level, match, exclusions, box, source; matchKey
|
|
597
|
+
// carries the exclude terms, so a chip added or removed by the toolbar, the Filters panel or an
|
|
598
|
+
// agent lands here through the key) or the cache lost
|
|
599
|
+
// rows from the front (TTL, the cap, a clear), which the handler detects by the cursor entry
|
|
600
|
+
// moving, not by the length. The counts keep their own cursor so their bookkeeping stays
|
|
601
|
+
// independent of the follow's: a recount here moves only the counts' cursor and leaves the
|
|
602
|
+
// snapshot's alone. The two causes are told apart: a control change (a chip added, a level
|
|
603
|
+
// moved) must land at once, so it is `dirty` and walks now; an eviction only makes the counts
|
|
604
|
+
// `stale`, and a stale walk runs at most once per RECOUNT_MS, because at the cap every push
|
|
605
|
+
// evicts and a view holding hidden rows would otherwise walk the whole cache on every bump. In
|
|
606
|
+
// between the line may name up to RECOUNT_MS of evicted rows; it is informational, so that is
|
|
607
|
+
// fine. An empty view with nothing held never goes stale (see the handler), and under the cap a
|
|
608
|
+
// bump costs only the rows it carried.
|
|
609
|
+
const countKey = matchKey + "|" + source;
|
|
610
|
+
const cnt = countsRef.current;
|
|
611
|
+
if (cnt.parsed !== matchParsed || cnt.key !== countKey) {
|
|
612
|
+
cnt.parsed = matchParsed;
|
|
613
|
+
cnt.key = countKey;
|
|
614
|
+
cnt.dirty = true;
|
|
615
|
+
}
|
|
616
|
+
if (total === 0 && (cnt.dirty || (cnt.stale && Date.now() - cnt.at > RECOUNT_MS))) {
|
|
617
|
+
cnt.at = Date.now();
|
|
618
|
+
cnt.held = 0;
|
|
619
|
+
cnt.belowLevel = 0;
|
|
620
|
+
cnt.excluded = 0;
|
|
621
|
+
cnt.excludedByKind = 0;
|
|
622
|
+
cnt.offBox = 0;
|
|
623
|
+
cnt.waiting = 0;
|
|
624
|
+
const cut = source === "switchboard" ? store.switchboardNewestCut() : null;
|
|
625
|
+
for (const c of store.cache) {
|
|
626
|
+
if (!c || (source !== "all" && c.type !== source))
|
|
627
|
+
continue;
|
|
628
|
+
if (cut !== null && !inSessionCut(c.ev, cut))
|
|
629
|
+
continue;
|
|
630
|
+
const ev = c.ev;
|
|
631
|
+
ev._type = c.type;
|
|
632
|
+
if (!store.passesMatch(ev))
|
|
633
|
+
continue;
|
|
634
|
+
cnt.held++;
|
|
635
|
+
// Same order as the handler: level, then exclusion, then the box.
|
|
636
|
+
if (!store.passesLevel(ev))
|
|
637
|
+
cnt.belowLevel++;
|
|
638
|
+
else {
|
|
639
|
+
const why = store.excludeReason(ev);
|
|
640
|
+
if (why) {
|
|
641
|
+
if (why === "kind" && source === "switchboard")
|
|
642
|
+
cnt.excludedByKind++;
|
|
643
|
+
else
|
|
644
|
+
cnt.excluded++;
|
|
645
|
+
}
|
|
646
|
+
else if (!matchParsed.empty && !matchParsed.test(searchText(ev), filterKind(ev, source)))
|
|
647
|
+
cnt.offBox++;
|
|
648
|
+
else
|
|
649
|
+
cnt.waiting++;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
cnt.len = store.cache.length;
|
|
653
|
+
cnt.tail = store.cache[cnt.len - 1];
|
|
654
|
+
cnt.dirty = false;
|
|
655
|
+
cnt.stale = false;
|
|
656
|
+
}
|
|
657
|
+
let emptyLine = null;
|
|
658
|
+
if (total === 0) {
|
|
659
|
+
const { held, belowLevel, excluded, excludedByKind, offBox, waiting } = cnt;
|
|
660
|
+
const n = (k) => (k === 1 ? "1 row" : k + " rows");
|
|
661
|
+
if (held === 0)
|
|
662
|
+
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.";
|
|
663
|
+
// A row the level, the exclusions and the box all let through is waiting, not hidden, and the
|
|
664
|
+
// status pill already tells pause from lock (a selection, a scroll, or jump-to-oldest), so the
|
|
665
|
+
// line does too.
|
|
666
|
+
else if (waiting > 0 && !following)
|
|
667
|
+
emptyLine = n(waiting) + (paused ? " arrived while paused." : " arrived while the feed is locked.");
|
|
668
|
+
else {
|
|
669
|
+
const parts = [];
|
|
670
|
+
if (belowLevel > 0)
|
|
671
|
+
parts.push(n(belowLevel) + (belowLevel === 1 ? " is" : " are") + " below the level ≥ selector.");
|
|
672
|
+
if (excludedByKind > 0)
|
|
673
|
+
parts.push(n(excludedByKind) + (excludedByKind === 1 ? " is" : " are") + " hidden by a kind chip.");
|
|
674
|
+
if (excluded > 0)
|
|
675
|
+
parts.push(n(excluded) + (excluded === 1 ? " is" : " are") + " hidden by an exclusion.");
|
|
676
|
+
if (offBox > 0)
|
|
677
|
+
parts.push(n(offBox) + (offBox === 1 ? " does" : " do") + " not match the filter box.");
|
|
678
|
+
emptyLine = parts.join(" ") || null;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
377
681
|
const first = Math.max(0, Math.floor(scrollTop / ROW_H) - OVERSCAN);
|
|
378
682
|
const visCount = Math.ceil(vpH / ROW_H) + OVERSCAN * 2;
|
|
379
683
|
const last = Math.min(total, first + visCount);
|
|
@@ -512,6 +816,9 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
512
816
|
highlightRef.current = null;
|
|
513
817
|
setNewCount(0);
|
|
514
818
|
onInspect && onInspect(null);
|
|
819
|
+
// The clear must recount now, not on the eviction throttle: other tabs' rows can keep the
|
|
820
|
+
// cache non-empty, so the handler above only marked the counts stale.
|
|
821
|
+
countsRef.current.dirty = true;
|
|
515
822
|
forceSnap();
|
|
516
823
|
}, [forceSnap, onInspect]);
|
|
517
824
|
const scrollIntoView = useCallback((idx) => {
|
|
@@ -600,6 +907,13 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
600
907
|
return; // native copy proceeds
|
|
601
908
|
}
|
|
602
909
|
const t = e.target;
|
|
910
|
+
// A focused button (exclude…, pause, Clear, a filter pill) owns its Enter and Space: the
|
|
911
|
+
// browser turns them into a click, and swallowing them here left the keyboard unable to
|
|
912
|
+
// press. Only those two: the row keys (j/k, arrows, Home/End, g/G, Cmd-C) keep working
|
|
913
|
+
// with a button focused, as they do after a mouse click on pause or a mode tab.
|
|
914
|
+
const onButton = !!t && (t.tagName === "BUTTON" || (typeof t.getAttribute === "function" && t.getAttribute("role") === "button"));
|
|
915
|
+
if (onButton && (e.key === "Enter" || e.key === " "))
|
|
916
|
+
return;
|
|
603
917
|
if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.tagName === "SELECT" || t.isContentEditable)) {
|
|
604
918
|
if ((e.metaKey || e.ctrlKey) && e.key === "c" && sel.size) {
|
|
605
919
|
e.preventDefault();
|
|
@@ -683,30 +997,204 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
683
997
|
return observed;
|
|
684
998
|
}, [spec, store.feedVersion, frames.length]);
|
|
685
999
|
const curPkg = (spec.match && spec.match.package) || "__all__";
|
|
1000
|
+
// Both selectors are links in the store's write chain (updateSpec), built from the spec the store
|
|
1001
|
+
// holds when their turn comes: a change made while a typed term's push is in flight keeps the
|
|
1002
|
+
// term, where a body built from the prop at click time posted the list without it.
|
|
686
1003
|
const changePkg = useCallback((v) => {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
next
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
1004
|
+
void store.updateSpec((base) => {
|
|
1005
|
+
// The selectors sit on the log-carrying views (Logs and Live); a change still queued when the
|
|
1006
|
+
// view moved to another source has nothing to write.
|
|
1007
|
+
if (base.source !== "log" && base.source !== "all")
|
|
1008
|
+
return null;
|
|
1009
|
+
const next = JSON.parse(JSON.stringify(base));
|
|
1010
|
+
next.match = next.match || {};
|
|
1011
|
+
if (v === "__all__")
|
|
1012
|
+
delete next.match.package;
|
|
1013
|
+
else
|
|
1014
|
+
next.match.package = v;
|
|
1015
|
+
if (!Object.keys(next.match).length)
|
|
1016
|
+
delete next.match;
|
|
1017
|
+
return next;
|
|
1018
|
+
}, { local: true });
|
|
1019
|
+
}, []);
|
|
697
1020
|
// The level selector writes the spec, the way the app selector does, so the choice survives a
|
|
698
1021
|
// reload, shows as a chip, and an agent-authored spec can set the same field. VERBOSE is the
|
|
699
1022
|
// floor of the order, so it is stored as no field at all rather than as a value that filters
|
|
700
1023
|
// nothing.
|
|
701
1024
|
const curLevel = (typeof spec.minLevel === "string" && spec.minLevel) || LOG_LEVEL_ORDER[0];
|
|
702
1025
|
const changeLevel = useCallback((v) => {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
1026
|
+
void store.updateSpec((base) => {
|
|
1027
|
+
if (base.source !== "log" && base.source !== "all")
|
|
1028
|
+
return null;
|
|
1029
|
+
const next = JSON.parse(JSON.stringify(base));
|
|
1030
|
+
if (v === LOG_LEVEL_ORDER[0])
|
|
1031
|
+
delete next.minLevel;
|
|
1032
|
+
else
|
|
1033
|
+
next.minLevel = v;
|
|
1034
|
+
return next;
|
|
1035
|
+
}, { local: true });
|
|
1036
|
+
}, []);
|
|
1037
|
+
// The exclude… control writes spec.exclude the same way, so a term added here is a chip, is
|
|
1038
|
+
// kept with the tab, and is the same field an agent or the Filters panel sets. The box stays
|
|
1039
|
+
// open after Enter for the next term; Escape, or leaving it empty, closes it. The cap and the
|
|
1040
|
+
// case-insensitive dedupe mirror the server's rules, so a refused term never reaches it. A
|
|
1041
|
+
// refusal is said next to the box and keeps the draft: a term that vanishes with no chip
|
|
1042
|
+
// reads as a bug, not as a rule. A comma is refused too: the Filters panel splits its input
|
|
1043
|
+
// on commas, so a term holding one would come back as two on the first edit there.
|
|
1044
|
+
const isStream = source !== "db" && source !== "prefs" && source !== "flags";
|
|
1045
|
+
const [exclOpen, setExclOpen] = useState(false);
|
|
1046
|
+
const [exclDraft, setExclDraft] = useState("");
|
|
1047
|
+
// The note under the box: a refusal keeps the draft and marks the input invalid; a hint (a term
|
|
1048
|
+
// that was added but is probably not what was meant) shows the same way without either.
|
|
1049
|
+
const [exclNote, setExclNote] = useState(null);
|
|
1050
|
+
// One add at a time: a second Enter while the first push is in flight is ignored. The
|
|
1051
|
+
// generation guards a late resolve after the box was closed or reopened, so an old refusal
|
|
1052
|
+
// never lands next to a new draft.
|
|
1053
|
+
const exclPendingRef = useRef(false);
|
|
1054
|
+
const exclGenRef = useRef(0);
|
|
1055
|
+
const exclRef = useRef(null);
|
|
1056
|
+
const exclBtnRef = useRef(null);
|
|
1057
|
+
useEffect(() => {
|
|
1058
|
+
if (exclOpen && exclRef.current && typeof exclRef.current.focus === "function")
|
|
1059
|
+
exclRef.current.focus();
|
|
1060
|
+
}, [exclOpen]);
|
|
1061
|
+
// `ok` says whether the term was added (a blank adds nothing and is ok). `note` is the reason
|
|
1062
|
+
// it was refused, or a hint on a term that was added anyway. The server has the last word, so
|
|
1063
|
+
// its refusal is surfaced the same way as the local ones. The write is a link in the store's
|
|
1064
|
+
// chain (updateSpec), so the list is read once the writes before it have settled: a term typed
|
|
1065
|
+
// while a chip's push is in flight builds on the acked list. The tab is the one the term was
|
|
1066
|
+
// typed on: a write still queued when the tab changed has nothing to add to the new tab's list,
|
|
1067
|
+
// and says nothing.
|
|
1068
|
+
const addExclude = useCallback((raw) => {
|
|
1069
|
+
const term = raw.trim();
|
|
1070
|
+
if (!term)
|
|
1071
|
+
return Promise.resolve({ ok: true, note: null });
|
|
1072
|
+
if (term.includes(","))
|
|
1073
|
+
return Promise.resolve({ ok: false, note: "one term at a time, no commas" });
|
|
1074
|
+
const at = store.spec ?? spec;
|
|
1075
|
+
const mySource = (at.source ?? "all");
|
|
1076
|
+
const myTab = store.matchesMode(at);
|
|
1077
|
+
const out = { refusal: null, stale: false };
|
|
1078
|
+
return store.updateSpec((base) => {
|
|
1079
|
+
if (base.source !== at.source || store.matchesMode(base) !== myTab) {
|
|
1080
|
+
out.stale = true;
|
|
1081
|
+
return null;
|
|
1082
|
+
}
|
|
1083
|
+
const cur = Array.isArray(base.exclude) ? base.exclude.map(String) : [];
|
|
1084
|
+
const lower = term.toLowerCase();
|
|
1085
|
+
if (cur.some((t) => t.toLowerCase() === lower)) {
|
|
1086
|
+
out.refusal = "already excluded";
|
|
1087
|
+
return null;
|
|
1088
|
+
}
|
|
1089
|
+
if (cur.length >= EXCLUDE_MAX_TERMS) {
|
|
1090
|
+
out.refusal = "up to " + EXCLUDE_MAX_TERMS + " terms";
|
|
1091
|
+
return null;
|
|
1092
|
+
}
|
|
1093
|
+
if (term.length > EXCLUDE_MAX_TERM_LENGTH) {
|
|
1094
|
+
out.refusal = "up to " + EXCLUDE_MAX_TERM_LENGTH + " characters";
|
|
1095
|
+
return null;
|
|
1096
|
+
}
|
|
1097
|
+
const next = JSON.parse(JSON.stringify(base));
|
|
1098
|
+
next.exclude = [...cur, term];
|
|
1099
|
+
return next;
|
|
1100
|
+
}, { local: true }).then((r) => {
|
|
1101
|
+
if (out.stale)
|
|
1102
|
+
return { ok: false, note: null };
|
|
1103
|
+
if (out.refusal)
|
|
1104
|
+
return { ok: false, note: out.refusal };
|
|
1105
|
+
if (!r.ok)
|
|
1106
|
+
return { ok: false, note: r.error || "rejected" };
|
|
1107
|
+
return { ok: true, note: isGappedFieldTerm(term, (f) => store.fieldSeen(mySource, f)) ? gappedFieldHint(term) : null };
|
|
1108
|
+
});
|
|
1109
|
+
}, [spec]);
|
|
1110
|
+
// The Switchboard tab's kind chips: one exclude term, kind:<name>, per kind, written the way
|
|
1111
|
+
// addExclude writes a typed term. A chip reads its state off the same list toggleKind writes
|
|
1112
|
+
// (the store's spec, which the prop can lag by one render), so the chip above the feed, the
|
|
1113
|
+
// Filters row, the tab memory and an agent's spec all move it; nothing is stored twice. A full
|
|
1114
|
+
// list, or a push the server refuses, is said with the exclude box's note, next to the chips.
|
|
1115
|
+
// A term is read through parseExcludeTerm, as the store reads it, so " kind:frame " and
|
|
1116
|
+
// KIND:FRAME are the same chip.
|
|
1117
|
+
const [kindNote, setKindNote] = useState(null);
|
|
1118
|
+
const kindNoteSpecRef = useRef(null);
|
|
1119
|
+
const isKindTerm = (t, name) => {
|
|
1120
|
+
const p = parseExcludeTerm(String(t));
|
|
1121
|
+
return "field" in p && p.field === "kind" && p.value === name;
|
|
1122
|
+
};
|
|
1123
|
+
const kindHidden = useCallback((name) => {
|
|
1124
|
+
const base = store.spec ?? spec;
|
|
1125
|
+
const ex = Array.isArray(base.exclude) ? base.exclude : [];
|
|
1126
|
+
return ex.some((t) => isKindTerm(t, name));
|
|
709
1127
|
}, [spec]);
|
|
1128
|
+
// A press is a link in the store's write chain, so a second press on a chip mid-flight is the
|
|
1129
|
+
// next toggle, not a lost one, and a press still queued when the tab changed writes nothing. A
|
|
1130
|
+
// refusal is said only while the list it answered is still the store's: an accepted write, a tab
|
|
1131
|
+
// switch or another control each replace store.spec, and a refusal of a list that is gone is
|
|
1132
|
+
// not said. The check is on identity right after the ack. In a burst (press 1 accepted, press 2
|
|
1133
|
+
// refused) the second's list is the first's acked spec, so it passes; the ref below is what
|
|
1134
|
+
// keeps the clearing effect the first's ack scheduled from wiping it a moment later.
|
|
1135
|
+
const toggleKind = useCallback(async (name) => {
|
|
1136
|
+
setKindNote(null);
|
|
1137
|
+
const seen = { base: null, full: false };
|
|
1138
|
+
const r = await store.updateSpec((base) => {
|
|
1139
|
+
seen.base = base;
|
|
1140
|
+
// The chips are Switchboard's; a press still queued when the tab changed has nothing to write.
|
|
1141
|
+
if (base.source !== "switchboard")
|
|
1142
|
+
return null;
|
|
1143
|
+
const cur = Array.isArray(base.exclude) ? base.exclude.map(String) : [];
|
|
1144
|
+
const rest = cur.filter((t) => !isKindTerm(t, name));
|
|
1145
|
+
const next = JSON.parse(JSON.stringify(base));
|
|
1146
|
+
if (rest.length !== cur.length) {
|
|
1147
|
+
if (rest.length)
|
|
1148
|
+
next.exclude = rest;
|
|
1149
|
+
else
|
|
1150
|
+
delete next.exclude;
|
|
1151
|
+
}
|
|
1152
|
+
else {
|
|
1153
|
+
if (cur.length >= EXCLUDE_MAX_TERMS) {
|
|
1154
|
+
seen.full = true;
|
|
1155
|
+
return null;
|
|
1156
|
+
}
|
|
1157
|
+
next.exclude = [...cur, "kind:" + name];
|
|
1158
|
+
}
|
|
1159
|
+
return next;
|
|
1160
|
+
}, { local: true });
|
|
1161
|
+
if (store.spec !== seen.base)
|
|
1162
|
+
return;
|
|
1163
|
+
const note = seen.full ? "up to " + EXCLUDE_MAX_TERMS + " terms" : r.ok ? null : r.error || "rejected";
|
|
1164
|
+
if (note === null)
|
|
1165
|
+
return;
|
|
1166
|
+
kindNoteSpecRef.current = store.spec;
|
|
1167
|
+
setKindNote(note);
|
|
1168
|
+
}, []);
|
|
1169
|
+
// The note answers one press; the next change to the list (a chip removed, a tab switch, a term
|
|
1170
|
+
// typed) ends it. The effect runs after its render, on the next frame or at the start of the
|
|
1171
|
+
// render after it, so it can land after a note set for a later press: press 1's ack changes the
|
|
1172
|
+
// list, press 2's refusal sets the note a few ms on, then the effect the ack scheduled fires. The
|
|
1173
|
+
// ref names the spec the note was said against; the note goes only once the store has moved past it.
|
|
1174
|
+
// The spec itself is the dep, not its exclude list: an Apply that changes only the match leaves
|
|
1175
|
+
// an empty list as undefined on both sides, and the note would otherwise outlive the spec it
|
|
1176
|
+
// answered.
|
|
1177
|
+
useEffect(() => {
|
|
1178
|
+
if (store.spec === kindNoteSpecRef.current)
|
|
1179
|
+
return;
|
|
1180
|
+
kindNoteSpecRef.current = null;
|
|
1181
|
+
setKindNote(null);
|
|
1182
|
+
}, [spec, source]);
|
|
1183
|
+
// Escape from the input hands focus back to the button, so the keyboard does not land on the
|
|
1184
|
+
// page body; a blur is focus already on its way elsewhere and is left alone.
|
|
1185
|
+
const closeExclude = useCallback((returnFocus = false) => {
|
|
1186
|
+
exclGenRef.current++;
|
|
1187
|
+
// A push still in flight belongs to the box that closed; the next box starts free.
|
|
1188
|
+
exclPendingRef.current = false;
|
|
1189
|
+
setExclOpen(false);
|
|
1190
|
+
setExclDraft("");
|
|
1191
|
+
setExclNote(null);
|
|
1192
|
+
if (returnFocus && exclBtnRef.current && typeof exclBtnRef.current.focus === "function")
|
|
1193
|
+
exclBtnRef.current.focus();
|
|
1194
|
+
}, []);
|
|
1195
|
+
// Memory is a preset tab's: a Custom view has no key to come back to, so its copy must not
|
|
1196
|
+
// promise one.
|
|
1197
|
+
const excludeRemembered = store.matchesMode(spec) !== null;
|
|
710
1198
|
// build only the visible slice
|
|
711
1199
|
const slice = [];
|
|
712
1200
|
for (let i = first; i < last; i++) {
|
|
@@ -871,7 +1359,7 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
871
1359
|
? "invalid regex ignored: " + draft
|
|
872
1360
|
: draftHint
|
|
873
1361
|
? draftHint
|
|
874
|
-
: '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)'}
|
|
1362
|
+
: '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)'}
|
|
875
1363
|
ref=${attachFilterInput}
|
|
876
1364
|
onFocus=${() => { if (sel.size)
|
|
877
1365
|
clearSel(); }}
|
|
@@ -941,8 +1429,10 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
941
1429
|
el.blur();
|
|
942
1430
|
const ns = neighborTabSpec(e.key === "ArrowRight" ? 1 : -1);
|
|
943
1431
|
// Presets carry the level floor the way a tab click does; the Custom spec is pushed as is.
|
|
944
|
-
if (ns)
|
|
945
|
-
store.setSpec(ns
|
|
1432
|
+
if (ns === store.lastCustomSpec)
|
|
1433
|
+
store.setSpec(ns);
|
|
1434
|
+
else if (ns)
|
|
1435
|
+
store.pushPreset(ns);
|
|
946
1436
|
}
|
|
947
1437
|
}}
|
|
948
1438
|
onInput=${(e) => {
|
|
@@ -975,13 +1465,67 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
975
1465
|
<code>-heartbeat</code><span>hide rows containing it</span>
|
|
976
1466
|
<code>"-1"</code><span>a literal - or / goes in quotes</span>
|
|
977
1467
|
<code>/^Fetch/</code><span>a regular expression</span>
|
|
978
|
-
${source === "all" ? html `<code>-log</code><span>hide every row of
|
|
1468
|
+
${source === "all" ? html `<code>-log</code><span>hide every row of one type (log, clog, trace, rtm, network, switchboard)</span>` : null}
|
|
1469
|
+
${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}
|
|
979
1470
|
${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}
|
|
1471
|
+
<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>
|
|
980
1472
|
</div>` : null}
|
|
981
1473
|
</span>
|
|
982
|
-
${isLogish ? html `<label class="fsortlbl" title=${source === "all" ? "show log lines at this level or above. Rows of other
|
|
1474
|
+
${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}
|
|
1475
|
+
${isStream ? html `<span class="fexcludewrap">
|
|
1476
|
+
<button class="fexclude" type="button" ref=${exclBtnRef}
|
|
1477
|
+
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")}
|
|
1478
|
+
aria-expanded=${exclOpen} aria-controls=${exclOpen ? "fexclude-input" : undefined}
|
|
1479
|
+
onClick=${() => (exclOpen ? closeExclude() : (exclGenRef.current++, setExclOpen(true)))}>exclude…</button>
|
|
1480
|
+
${exclOpen ? html `<input class="fexclude-input" id="fexclude-input" ref=${exclRef} placeholder="term, then Enter" autocomplete="off" value=${exclDraft}
|
|
1481
|
+
aria-label="exclude term" aria-invalid=${exclNote?.refused ? "true" : undefined} aria-describedby=${exclNote ? "fexclude-note" : undefined}
|
|
1482
|
+
onInput=${(e) => { setExclDraft(e.currentTarget.value); setExclNote(null); }}
|
|
1483
|
+
onKeyDown=${(e) => {
|
|
1484
|
+
const el = e.currentTarget;
|
|
1485
|
+
if (e.key === "Enter") {
|
|
1486
|
+
e.preventDefault();
|
|
1487
|
+
if (exclPendingRef.current)
|
|
1488
|
+
return;
|
|
1489
|
+
exclPendingRef.current = true;
|
|
1490
|
+
const gen = exclGenRef.current;
|
|
1491
|
+
void addExclude(el.value).then(({ ok, note }) => {
|
|
1492
|
+
// A push from a box that has since closed does not free the box that is open now.
|
|
1493
|
+
if (gen !== exclGenRef.current)
|
|
1494
|
+
return;
|
|
1495
|
+
exclPendingRef.current = false;
|
|
1496
|
+
if (ok)
|
|
1497
|
+
setExclDraft("");
|
|
1498
|
+
setExclNote(note ? { text: note, refused: !ok } : null);
|
|
1499
|
+
}).catch((e) => {
|
|
1500
|
+
// A write that threw (not a refusal) frees the box and is said like one.
|
|
1501
|
+
if (gen !== exclGenRef.current)
|
|
1502
|
+
return;
|
|
1503
|
+
exclPendingRef.current = false;
|
|
1504
|
+
setExclNote({ text: e instanceof Error && e.message ? e.message : "request failed", refused: true });
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
else if (e.key === "Escape") {
|
|
1508
|
+
e.preventDefault();
|
|
1509
|
+
closeExclude(true);
|
|
1510
|
+
}
|
|
1511
|
+
}}
|
|
1512
|
+
onBlur=${(e) => { if (!e.currentTarget.value.trim())
|
|
1513
|
+
closeExclude(); }} />` : null}
|
|
1514
|
+
${exclOpen && exclNote ? html `<span class=${"fexclude-note" + (exclNote.refused ? "" : " fexclude-note-plain")} id="fexclude-note" role="status">${exclNote.text}</span>` : null}
|
|
1515
|
+
</span>` : null}
|
|
1516
|
+
${source === "switchboard" ? html `<span class="fsortlbl"><span id="fkinds-label">kinds</span> <span class="fkinds" role="group" aria-labelledby="fkinds-label">
|
|
1517
|
+
${SWITCHBOARD_KINDS.map((k) => {
|
|
1518
|
+
const on = !kindHidden(k);
|
|
1519
|
+
// The accessible name is the kind; aria-checked carries the state. The title is the
|
|
1520
|
+
// mouse hint and names the action, which read inverted as a screen reader's name.
|
|
1521
|
+
return html `<button class=${"fkind" + (on ? "" : " fkind-off")} type="button" role="switch" aria-checked=${on ? "true" : "false"}
|
|
1522
|
+
title=${(on ? "hide " : "show ") + k + " records"} aria-label=${k + " records"} aria-describedby=${kindNote ? "fkinds-note" : undefined}
|
|
1523
|
+
onClick=${() => { void toggleKind(k).catch((e) => setKindNote(e instanceof Error && e.message ? e.message : "request failed")); }}>${k}</button>`;
|
|
1524
|
+
})}
|
|
1525
|
+
${kindNote ? html `<span class="fexclude-note" id="fkinds-note" role="status">${kindNote}</span>` : null}
|
|
1526
|
+
</span></span>` : null}
|
|
983
1527
|
${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}
|
|
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>
|
|
1528
|
+
<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>
|
|
985
1529
|
<button class=${"fbtn" + (paused ? " paused" : "")} title="pause / resume the live feed" onClick=${() => setPaused((p) => !p)}>${paused ? "▶ resume" : "⏸ pause"}</button>
|
|
986
1530
|
<button class="fbtn" disabled=${!total} onClick=${clearView}
|
|
987
1531
|
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>
|
|
@@ -992,6 +1536,7 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
992
1536
|
</div>
|
|
993
1537
|
<div class="vpbox">
|
|
994
1538
|
<div class="vp" ref=${vpRef} onScroll=${onScroll}>
|
|
1539
|
+
${emptyLine ? html `<div class="empty-row">${emptyLine}</div>` : null}
|
|
995
1540
|
<div class="spacer" style=${{ height: totalH + "px" }}>${slice}</div>
|
|
996
1541
|
</div>
|
|
997
1542
|
${!following && (newCount > 0 || scrollTop > ROW_H) ? html `<div class="pill" onClick=${jumpNewest}>↑ newest${newCount ? ` (${newCount} new)` : ""} <span class="pillkey">${KEY_NEWEST}</span></div>` : null}
|
|
@@ -1000,4 +1545,4 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
1000
1545
|
</div>
|
|
1001
1546
|
`;
|
|
1002
1547
|
}
|
|
1003
|
-
export { ROW_H, sortOptionsFor, searchText, filterKind, rawLine, statusBand };
|
|
1548
|
+
export { ROW_H, sortOptionsFor, searchText, filterKind, rawLine, statusBand, RowBody };
|