@slack/radar-mcp 1.10.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/mcp/index.js +75 -50
- package/dist/mcp/prefs-tools.d.ts +15 -0
- package/dist/mcp/prefs-tools.js +204 -0
- package/dist/mcp/session-enable.d.ts +18 -0
- package/dist/mcp/session-enable.js +131 -0
- package/dist/mcp/snapshot.js +6 -1
- package/dist/mcp/tools.js +65 -2
- package/dist/shared/android.d.ts +36 -1
- package/dist/shared/android.js +247 -13
- package/dist/shared/constants.d.ts +17 -2
- package/dist/shared/constants.js +22 -3
- package/dist/shared/db.d.ts +14 -0
- package/dist/shared/db.js +16 -5
- package/dist/shared/prefs.d.ts +78 -0
- package/dist/shared/prefs.js +416 -0
- package/dist/shared/stream.d.ts +23 -0
- package/dist/shared/stream.js +109 -16
- package/dist/shared/transport.d.ts +86 -0
- package/dist/web/log-session.d.ts +13 -0
- package/dist/web/log-session.js +16 -0
- package/dist/web/public/index.html +108 -3
- package/dist/web/public/next/app.js +58 -2
- package/dist/web/public/next/feed.js +261 -12
- package/dist/web/public/next/filter.js +200 -0
- package/dist/web/public/next/prefs.js +399 -0
- package/dist/web/public/next/registry.js +7 -6
- package/dist/web/public/next/store.js +201 -10
- package/dist/web/server.js +236 -21
- package/dist/web/spec.d.ts +7 -7
- package/dist/web/spec.js +12 -9
- package/package.json +1 -1
|
@@ -6,11 +6,73 @@
|
|
|
6
6
|
import { html } from "./html.js";
|
|
7
7
|
import { useState, useEffect, useRef, useCallback, useMemo } from "preact/hooks";
|
|
8
8
|
import { store, shortUrl, shortPkg, MODES, fmtNum } from "./store.js";
|
|
9
|
+
import { STREAM_KINDS } from "./registry.js";
|
|
10
|
+
import { parseFilter, tokenize, isCompleteTerm } from "./filter.js";
|
|
9
11
|
const ROW_H = 24;
|
|
10
12
|
const OVERSCAN = 10;
|
|
11
13
|
// Feed UI prefs PERSIST across tab switches (the Feed unmounts/remounts per source). The text
|
|
12
14
|
// filter is global; sort is per-source (a Network "slowest" is meaningless on RTM).
|
|
13
15
|
const FEED_PREFS = { filter: "", sortBySource: {} };
|
|
16
|
+
// The set of kind names that render as colored kind-pills on the unified Live view (bare token
|
|
17
|
+
// equal to one of these). On a single-source tab the kind chip is invisible in the row (every
|
|
18
|
+
// row is the same kind), so a matching pill would just look like a bare-word pill; the coloring
|
|
19
|
+
// only kicks in when source === "all".
|
|
20
|
+
const KIND_TOKENS = new Set(STREAM_KINDS);
|
|
21
|
+
// Split the persisted filter string into committed pill tokens + a trailing draft. Uses the
|
|
22
|
+
// tokenizer that the parser uses, so pill-vs-string equivalence holds by construction: the
|
|
23
|
+
// pill list is exactly the tokens the parser would consume, minus the one still being typed.
|
|
24
|
+
// The draft is the LAST token when it is incomplete (mid /…/ or "…" span, or a bare "-"), or
|
|
25
|
+
// when the raw string has no trailing whitespace (still-being-typed complete token); otherwise
|
|
26
|
+
// the draft is "" and every token is a committed pill.
|
|
27
|
+
function splitPillsAndDraft(raw) {
|
|
28
|
+
const tokens = tokenize(raw);
|
|
29
|
+
if (!tokens.length)
|
|
30
|
+
return { pills: [], draft: "" };
|
|
31
|
+
const last = tokens[tokens.length - 1];
|
|
32
|
+
const endsWithSpace = raw.length > 0 && /\s$/.test(raw);
|
|
33
|
+
const lastIsDraft = !endsWithSpace || !isCompleteTerm(last);
|
|
34
|
+
if (lastIsDraft)
|
|
35
|
+
return { pills: tokens.slice(0, -1), draft: last };
|
|
36
|
+
return { pills: tokens, draft: "" };
|
|
37
|
+
}
|
|
38
|
+
// Join pill tokens + a draft back into the filter string. A trailing space after the pills
|
|
39
|
+
// keeps the draft as its own token (never glued to the previous pill), which is what the
|
|
40
|
+
// tokenizer would consume; when the draft is empty the string is just the pills separated by
|
|
41
|
+
// single spaces plus a trailing space (so appending more text starts a fresh token).
|
|
42
|
+
function joinPillsAndDraft(pills, draft) {
|
|
43
|
+
if (!pills.length && !draft)
|
|
44
|
+
return "";
|
|
45
|
+
if (!pills.length)
|
|
46
|
+
return draft;
|
|
47
|
+
const base = pills.join(" ");
|
|
48
|
+
return draft ? base + " " + draft : base + " ";
|
|
49
|
+
}
|
|
50
|
+
// The visual class for a pill token: bad (invalid regex), negated (leading "-"), regex ("/"),
|
|
51
|
+
// kind (bare token equal to a source kind, on the Live view only). A term can be both negated
|
|
52
|
+
// and regex/quoted; the negation class stacks on top of the shape class.
|
|
53
|
+
function pillClasses(raw, invalidSet, sourceIsAll) {
|
|
54
|
+
const classes = ["fpill"];
|
|
55
|
+
const body = raw.startsWith("-") ? raw.slice(1) : raw;
|
|
56
|
+
if (invalidSet.has(raw))
|
|
57
|
+
classes.push("fpill-bad");
|
|
58
|
+
if (raw.startsWith("-"))
|
|
59
|
+
classes.push("fpill-neg");
|
|
60
|
+
if (body.startsWith("/"))
|
|
61
|
+
classes.push("fpill-re");
|
|
62
|
+
else if (body.startsWith('"'))
|
|
63
|
+
classes.push("fpill-quote");
|
|
64
|
+
else if (sourceIsAll && KIND_TOKENS.has(body.toLowerCase()))
|
|
65
|
+
classes.push("fpill-kind", "fpill-kind-" + body.toLowerCase());
|
|
66
|
+
return classes.join(" ");
|
|
67
|
+
}
|
|
68
|
+
// The label shown on a pill. Negation renders as a leading "−" glyph outside the body so the
|
|
69
|
+
// body reads the same as it does in the filter string. Regex pills keep their slashes (that is
|
|
70
|
+
// how they were typed); quoted phrases keep their quotes.
|
|
71
|
+
function pillLabel(raw) {
|
|
72
|
+
if (raw.startsWith("-"))
|
|
73
|
+
return { neg: true, body: raw.slice(1) };
|
|
74
|
+
return { neg: false, body: raw };
|
|
75
|
+
}
|
|
14
76
|
// Platform-aware jump-pill labels. macOS has no Home/End, so show the chord that works there.
|
|
15
77
|
const IS_MAC = typeof navigator !== "undefined" && /Mac|iP(hone|ad|od)/.test(navigator.platform || navigator.userAgent || "");
|
|
16
78
|
const KEY_NEWEST = IS_MAC ? "⌘↑" : "Ctrl↑";
|
|
@@ -51,7 +113,9 @@ function neighborTabSpec(dir) {
|
|
|
51
113
|
const k = keys[next];
|
|
52
114
|
return k === "__custom__" ? store.lastCustomSpec || undefined : MODES.find((m) => m.key === k)?.spec;
|
|
53
115
|
}
|
|
54
|
-
// One searchable string per frame for the text filter
|
|
116
|
+
// One searchable string per frame for the text filter. The row KIND is deliberately NOT
|
|
117
|
+
// part of this string: a kind token would make "-log" silently exclude clogs (log ⊂ clog).
|
|
118
|
+
// Kind matching happens by EQUALITY via the predicate's second argument instead (see filterKind).
|
|
55
119
|
function searchText(ev) {
|
|
56
120
|
if ((ev._type || "") === "log")
|
|
57
121
|
return [ev.level, ev.package, ev.tag, ev.message].filter(Boolean).join(" ").toLowerCase();
|
|
@@ -59,6 +123,13 @@ function searchText(ev) {
|
|
|
59
123
|
return [ev.trace_name, ev.span_name].filter(Boolean).join(" ").toLowerCase();
|
|
60
124
|
return [ev.direction, ev.method, ev.event_type, ev.event_name, shortUrl(ev.url), ev.channel].filter(Boolean).join(" ").toLowerCase();
|
|
61
125
|
}
|
|
126
|
+
// The kind handed to the filter predicate. Only the unified view exposes it: that is where the
|
|
127
|
+
// type chip is visible, so "trace" / "-log" reading as kind filters matches what the user
|
|
128
|
+
// sees. On a single-source tab every row is the same kind, so kind matching would only turn
|
|
129
|
+
// the tab's own name into an invisible match-all ("network" matching every Network row).
|
|
130
|
+
function filterKind(ev, source) {
|
|
131
|
+
return source === "all" ? ev._type : undefined;
|
|
132
|
+
}
|
|
62
133
|
// One raw copy line per frame (Logcat-style), pulled from the ring on copy.
|
|
63
134
|
function rawLine(ev) {
|
|
64
135
|
const t = new Date(ev.timestamp || Date.now()).toLocaleTimeString();
|
|
@@ -135,6 +206,32 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
135
206
|
const [, bumpSnap] = useState(0);
|
|
136
207
|
const sortOpts = useMemo(() => sortOptionsFor(source), [source]);
|
|
137
208
|
const isLogish = source === "log" || source === "all";
|
|
209
|
+
// Compile the filter query ONCE per change (FEED_PREFS keeps the raw string across remounts;
|
|
210
|
+
// the parsed form rebuilds from it here). `parsed` drives the INSTANT feedback near the input
|
|
211
|
+
// (invalid-regex highlighting, the hint tooltip) -- those must never lag a keystroke, or a
|
|
212
|
+
// typo looks unrecognized for a beat. It must stay off the live `filter`, not a debounced copy.
|
|
213
|
+
const parsed = useMemo(() => parseFilter(filter, STREAM_KINDS), [filter]);
|
|
214
|
+
// debouncedFilter feeds ONLY the row-matching predicate below (matchParsed), which is what
|
|
215
|
+
// orderFrames/recompute actually run over the ring (up to 100k entries, on every keystroke
|
|
216
|
+
// without this). Debouncing the FEED WORK rather than the whole `parsed` value is deliberate:
|
|
217
|
+
// parsed itself stays synchronous so typing feedback (above) is never delayed by this.
|
|
218
|
+
const [debouncedFilter, setDebouncedFilter] = useState(filter);
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
const t = setTimeout(() => setDebouncedFilter(filter), 180);
|
|
221
|
+
return () => clearTimeout(t);
|
|
222
|
+
}, [filter]);
|
|
223
|
+
const matchParsed = useMemo(() => parseFilter(debouncedFilter, STREAM_KINDS), [debouncedFilter]);
|
|
224
|
+
// The filter STRING stays the single source of truth (FEED_PREFS.filter); pills are a VIEW
|
|
225
|
+
// over it. tokenize splits the string as the parser would; the trailing token becomes the
|
|
226
|
+
// draft input (if it is incomplete, or if the string has no trailing space) so the user can
|
|
227
|
+
// keep typing where they left off. Every commit / pop / remove writes a new filter string,
|
|
228
|
+
// never touches the pill array directly, which keeps the pill list and the compiled predicate
|
|
229
|
+
// impossible to drift apart. On a page reload the persisted string re-tokenizes back into
|
|
230
|
+
// pills + draft with no state hand-off.
|
|
231
|
+
const { pills, draft } = useMemo(() => splitPillsAndDraft(filter), [filter]);
|
|
232
|
+
const setPillsAndDraft = useCallback((nextPills, nextDraft) => {
|
|
233
|
+
setFilter(joinPillsAndDraft(nextPills, nextDraft));
|
|
234
|
+
}, [setFilter]);
|
|
138
235
|
// On source change: keep the persisted filter, re-derive the per-source sort, reset transient
|
|
139
236
|
// view state (selection, pause, follow). Filter + sort persist; selection does not.
|
|
140
237
|
useEffect(() => {
|
|
@@ -149,9 +246,10 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
149
246
|
setNewCount(0);
|
|
150
247
|
}, [source]);
|
|
151
248
|
// Build the display order from a chronological list of matched frames (text filter + sort +
|
|
152
|
-
// inversion). The full-buffer pass; used on control changes.
|
|
249
|
+
// inversion). The full-buffer pass; used on control changes. Runs against matchParsed (the
|
|
250
|
+
// debounced predicate), not parsed, since this is the O(N) work the debounce exists to spare.
|
|
153
251
|
const orderFrames = useCallback((chrono) => {
|
|
154
|
-
const frames =
|
|
252
|
+
const frames = matchParsed.empty ? chrono : chrono.filter((ev) => matchParsed.test(searchText(ev), filterKind(ev, source)));
|
|
155
253
|
if (sort === "newest")
|
|
156
254
|
return frames.slice().reverse();
|
|
157
255
|
if (sort === "oldest")
|
|
@@ -165,7 +263,7 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
165
263
|
return opt.dir === "asc" ? 1 : -1;
|
|
166
264
|
return 0;
|
|
167
265
|
});
|
|
168
|
-
}, [
|
|
266
|
+
}, [matchParsed, sort, sortOpts, source]);
|
|
169
267
|
const recompute = useCallback(() => orderFrames(store.viewFrames()), [orderFrames]);
|
|
170
268
|
const forceSnap = useCallback(() => {
|
|
171
269
|
snapRef.current = recompute();
|
|
@@ -201,7 +299,7 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
201
299
|
ev._type = c.type;
|
|
202
300
|
if (!store.matches(ev))
|
|
203
301
|
continue;
|
|
204
|
-
if (
|
|
302
|
+
if (!matchParsed.empty && !matchParsed.test(searchText(ev), filterKind(ev, src)))
|
|
205
303
|
continue;
|
|
206
304
|
fresh.push(ev);
|
|
207
305
|
}
|
|
@@ -221,7 +319,7 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
221
319
|
el.scrollTop = 0; // glue to newest (top)
|
|
222
320
|
});
|
|
223
321
|
return off;
|
|
224
|
-
}, [recompute,
|
|
322
|
+
}, [recompute, matchParsed, sort, sortOpts]);
|
|
225
323
|
// Rebuild when the SERVER-SIDE filter (match/bodyContains) changes -- that changes what
|
|
226
324
|
// store.matches() admits, so the whole snapshot must refresh. Keyed so it only fires on a
|
|
227
325
|
// real filter change, not every spec poll.
|
|
@@ -571,20 +669,164 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
571
669
|
</div>
|
|
572
670
|
`);
|
|
573
671
|
}
|
|
672
|
+
// Per-pill amber replaces the whole-input amber border for COMMITTED terms; the draft input
|
|
673
|
+
// still turns amber when its own text is an invalid regex mid-typing (feedback while typing).
|
|
674
|
+
const invalidSet = new Set(parsed.invalid);
|
|
675
|
+
const draftInvalid = draft.length > 0 && invalidSet.has(draft);
|
|
676
|
+
// Per-pill hint tooltip: parseFilter.hints entries lead with the raw token followed by a
|
|
677
|
+
// space ("<raw> read as …"), so match on raw + " ". A bare prefix match would let /api/im
|
|
678
|
+
// pick up /api/imx's hint (they share a prefix) and show the wrong reading.
|
|
679
|
+
const hintFor = (raw) => parsed.hints.find((h) => h.startsWith(raw + " "));
|
|
680
|
+
// The draft input only surfaces a hint about ITS OWN text; hints for committed terms live on
|
|
681
|
+
// their pills. Without this gate the input tooltip showed stale copy about other terms.
|
|
682
|
+
const draftHint = draft ? parsed.hints.find((h) => h.startsWith(draft + " ")) : undefined;
|
|
683
|
+
const sourceIsAll = source === "all";
|
|
684
|
+
const focusDraftInput = () => {
|
|
685
|
+
const inp = filterRef.current;
|
|
686
|
+
if (inp && typeof inp.focus === "function")
|
|
687
|
+
inp.focus();
|
|
688
|
+
};
|
|
689
|
+
// Where the next committed draft is inserted. Normally the tail; set to the source index
|
|
690
|
+
// when a pill is popped for re-edit so the term returns to ITS spot instead of jumping to
|
|
691
|
+
// the end (AND is commutative so the predicate never cares, but the eye does). A ref, not
|
|
692
|
+
// state: it changes nothing visually until the next commit. Cleared when the draft is
|
|
693
|
+
// erased (erasing the popped text means "remove that term", so a new term goes to the tail).
|
|
694
|
+
const editSlotRef = useRef(null);
|
|
695
|
+
const commitDraft = (rawDraft) => {
|
|
696
|
+
// Only commit a complete non-empty term; a bare "-" or an open /… / "… span stays as draft.
|
|
697
|
+
if (!isCompleteTerm(rawDraft))
|
|
698
|
+
return false;
|
|
699
|
+
const slot = editSlotRef.current;
|
|
700
|
+
editSlotRef.current = null;
|
|
701
|
+
const nextPills = [...pills];
|
|
702
|
+
const at = slot == null ? nextPills.length : Math.max(0, Math.min(slot, nextPills.length));
|
|
703
|
+
nextPills.splice(at, 0, rawDraft);
|
|
704
|
+
setPillsAndDraft(nextPills, "");
|
|
705
|
+
return true;
|
|
706
|
+
};
|
|
707
|
+
// Pop the pill at idx into the draft for re-edit. A complete draft commits first (to its own
|
|
708
|
+
// slot rules); an incomplete draft blocks the pop so its text is never silently lost.
|
|
709
|
+
const popPillForEdit = (idx) => {
|
|
710
|
+
const raw = pills[idx];
|
|
711
|
+
if (draft && !isCompleteTerm(draft)) {
|
|
712
|
+
focusDraftInput();
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
const nextPills = [...pills];
|
|
716
|
+
nextPills.splice(idx, 1);
|
|
717
|
+
editSlotRef.current = idx;
|
|
718
|
+
setPillsAndDraft(draft ? [...nextPills, draft] : nextPills, raw);
|
|
719
|
+
focusDraftInput();
|
|
720
|
+
};
|
|
721
|
+
const removePill = (idx) => {
|
|
722
|
+
// Removing a pill above the remembered re-edit slot shifts every later index down one;
|
|
723
|
+
// move the slot with it so a popped term still recommits to its visual spot.
|
|
724
|
+
const slot = editSlotRef.current;
|
|
725
|
+
if (slot != null && idx < slot)
|
|
726
|
+
editSlotRef.current = slot - 1;
|
|
727
|
+
const nextPills = [...pills];
|
|
728
|
+
nextPills.splice(idx, 1);
|
|
729
|
+
setPillsAndDraft(nextPills, draft);
|
|
730
|
+
};
|
|
574
731
|
return html `
|
|
575
732
|
<div class="feedwrap-next">
|
|
576
733
|
<div class="feedbar">
|
|
577
|
-
<span class="ffilterwrap"
|
|
578
|
-
|
|
734
|
+
<span class="ffilterwrap"
|
|
735
|
+
onClick=${(e) => {
|
|
736
|
+
// Click anywhere in the wrap that is NOT a pill focuses the draft input (matches
|
|
737
|
+
// browser input behavior: the whole wrap reads as one field).
|
|
738
|
+
const target = e.target;
|
|
739
|
+
if (target && typeof target.closest === "function" && target.closest(".fpill"))
|
|
740
|
+
return;
|
|
741
|
+
const inp = filterRef.current;
|
|
742
|
+
if (inp && typeof inp.focus === "function")
|
|
743
|
+
inp.focus();
|
|
744
|
+
}}>
|
|
745
|
+
${pills.map((raw, idx) => {
|
|
746
|
+
const { neg, body } = pillLabel(raw);
|
|
747
|
+
const cls = pillClasses(raw, invalidSet, sourceIsAll);
|
|
748
|
+
// The title always carries the raw term: long pills ellipsize at max-width, and
|
|
749
|
+
// hover is the only way to audit a truncated term without mutating the query.
|
|
750
|
+
const title = invalidSet.has(raw)
|
|
751
|
+
? raw + " · invalid regex, this whole term is ignored and filters nothing"
|
|
752
|
+
: hintFor(raw) || raw + " · click or Enter to edit · ✕ or Backspace to remove";
|
|
753
|
+
return html `
|
|
754
|
+
<span class=${cls} title=${title} key=${idx + ":" + raw}
|
|
755
|
+
role="button" tabindex="0" aria-label=${"filter term " + raw}
|
|
756
|
+
onKeyDown=${(e) => {
|
|
757
|
+
// Keyboard path mirrors the mouse path so interior pills stay reachable
|
|
758
|
+
// without a mouse: Tab focuses a pill, Enter pops it for edit, Backspace or
|
|
759
|
+
// Delete removes it.
|
|
760
|
+
if (e.key === "Enter") {
|
|
761
|
+
e.preventDefault();
|
|
762
|
+
popPillForEdit(idx);
|
|
763
|
+
}
|
|
764
|
+
else if (e.key === "Backspace" || e.key === "Delete") {
|
|
765
|
+
e.preventDefault();
|
|
766
|
+
removePill(idx);
|
|
767
|
+
focusDraftInput();
|
|
768
|
+
}
|
|
769
|
+
}}
|
|
770
|
+
onMouseDown=${(e) => {
|
|
771
|
+
// MouseDown so the click never blurs the input into a state where the pop
|
|
772
|
+
// races the setFilter (mousedown on a pill fires before the input's blur).
|
|
773
|
+
// The ✕ handler stops propagation, but a mousedown that lands directly on it
|
|
774
|
+
// still bubbles here first; skip in that case so the ✕ path owns removal.
|
|
775
|
+
const t = e.target;
|
|
776
|
+
const tCls = t && (t.className || t.attributes?.class || "");
|
|
777
|
+
if (typeof tCls === "string" && tCls.split(/\s+/).includes("fpill-x"))
|
|
778
|
+
return;
|
|
779
|
+
e.preventDefault();
|
|
780
|
+
popPillForEdit(idx);
|
|
781
|
+
}}>
|
|
782
|
+
${neg ? html `<span class="fpill-sign">−</span>` : null}<span class="fpill-body">${body}</span><span class="fpill-x"
|
|
783
|
+
title="remove this term"
|
|
784
|
+
onMouseDown=${(e) => {
|
|
785
|
+
e.preventDefault();
|
|
786
|
+
e.stopPropagation();
|
|
787
|
+
removePill(idx);
|
|
788
|
+
}}>✕</span>
|
|
789
|
+
</span>
|
|
790
|
+
`;
|
|
791
|
+
})}
|
|
792
|
+
<input class=${"ffilter" + (draftInvalid ? " finvalid" : "")} ref=${filterRef}
|
|
793
|
+
placeholder=${pills.length ? "" : "filter rows… -exclude /regex/ \"phrase\""} autocomplete="off" value=${draft}
|
|
794
|
+
title=${draftInvalid
|
|
795
|
+
? "invalid regex ignored: " + draft
|
|
796
|
+
: draftHint
|
|
797
|
+
? draftHint
|
|
798
|
+
: '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 · 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)'}
|
|
579
799
|
onFocus=${() => { if (sel.size)
|
|
580
800
|
clearSel(); }}
|
|
581
801
|
onKeyDown=${(e) => {
|
|
582
802
|
const el = e.currentTarget;
|
|
583
|
-
if (e.key === "
|
|
803
|
+
if (e.key === " ") {
|
|
804
|
+
// Space commits a COMPLETE draft term as a pill. commitDraft is the single
|
|
805
|
+
// completeness gate: when the draft is an open /…/ or "…" span it refuses,
|
|
806
|
+
// no preventDefault fires, and the space lands as literal text inside the
|
|
807
|
+
// span. One chokepoint, so a broken gate fails visibly instead of being
|
|
808
|
+
// masked by a redundant check here.
|
|
809
|
+
if (commitDraft(el.value))
|
|
810
|
+
e.preventDefault();
|
|
811
|
+
}
|
|
812
|
+
else if (e.key === "Enter") {
|
|
584
813
|
e.preventDefault();
|
|
814
|
+
commitDraft(el.value);
|
|
585
815
|
el.blur();
|
|
586
816
|
moveSel(1);
|
|
587
817
|
}
|
|
818
|
+
else if (e.key === "ArrowDown") {
|
|
819
|
+
e.preventDefault();
|
|
820
|
+
el.blur();
|
|
821
|
+
moveSel(1);
|
|
822
|
+
}
|
|
823
|
+
else if (e.key === "Backspace" && el.value === "" && pills.length) {
|
|
824
|
+
// Empty-input backspace pops the last pill back into the draft. Native browser
|
|
825
|
+
// behavior for chip inputs, and gives fast keyboard-only re-edits.
|
|
826
|
+
e.preventDefault();
|
|
827
|
+
const last = pills[pills.length - 1];
|
|
828
|
+
setPillsAndDraft(pills.slice(0, -1), last);
|
|
829
|
+
}
|
|
588
830
|
else if (e.key === "Escape") {
|
|
589
831
|
el.blur();
|
|
590
832
|
}
|
|
@@ -596,8 +838,15 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
596
838
|
store.setSpec(ns);
|
|
597
839
|
}
|
|
598
840
|
}}
|
|
599
|
-
onInput=${(e) =>
|
|
600
|
-
|
|
841
|
+
onInput=${(e) => {
|
|
842
|
+
const v = e.currentTarget.value;
|
|
843
|
+
// Erasing a popped pill's text to nothing means "remove that term": the term is
|
|
844
|
+
// gone from the string, so the remembered slot must not capture the NEXT term.
|
|
845
|
+
if (!v)
|
|
846
|
+
editSlotRef.current = null;
|
|
847
|
+
setPillsAndDraft(pills, v);
|
|
848
|
+
}} />
|
|
849
|
+
${filter ? html `<span class="ffilterclear" title="clear all" onClick=${() => setFilter("")}>✕</span>` : null}
|
|
601
850
|
</span>
|
|
602
851
|
${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}
|
|
603
852
|
<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>
|
|
@@ -617,4 +866,4 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
617
866
|
</div>
|
|
618
867
|
`;
|
|
619
868
|
}
|
|
620
|
-
export { ROW_H, sortOptionsFor, searchText, rawLine, statusBand };
|
|
869
|
+
export { ROW_H, sortOptionsFor, searchText, filterKind, rawLine, statusBand };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Smart text filter for the feed. Parses the filter-box query ONCE into a predicate that the
|
|
2
|
+
// feed runs over searchText(ev) per row. Compiling here keeps regexes out of the hot path: the
|
|
3
|
+
// predicate runs over up to 100k ring entries on a rebuild and per-frame (~400/s) while
|
|
4
|
+
// tailing, so per-row work must be a few .includes()/.test() calls, never a re-parse.
|
|
5
|
+
//
|
|
6
|
+
// Syntax (space-separated terms AND together):
|
|
7
|
+
// term case-insensitive substring (the old behavior; muscle memory keeps working).
|
|
8
|
+
// A bare term also matches when it EQUALS the row kind passed to test(),
|
|
9
|
+
// see the kind parameter below.
|
|
10
|
+
// -term exclude rows matching term
|
|
11
|
+
// /pattern/ regex term (case-insensitive); -/pattern/ excludes by regex
|
|
12
|
+
// /pat/flags trailing flags are honored for the short flag strings people actually type
|
|
13
|
+
// (1-2 letters from i/m/s/g, no repeats; g is stripped because a stateful
|
|
14
|
+
// lastIndex across .test() calls would make matches flicker). Any other tail
|
|
15
|
+
// (junk, a path segment like users/id, three or more letters) becomes part
|
|
16
|
+
// of the pattern as best-effort regex, so pasted paths like /api/users and
|
|
17
|
+
// flag-typos like /error/x keep matching literally. The ambiguity is inherent
|
|
18
|
+
// (/api/im reads as both regex + flags and regex + path). Every judgment call
|
|
19
|
+
// on an ambiguous /…/tail is reported in `hints` so the reading is visible,
|
|
20
|
+
// never silent.
|
|
21
|
+
// "a b" quoted phrase, matches the space literally; -"a b" excludes the phrase.
|
|
22
|
+
// Quoting is also the escape hatch for a literal leading - or /.
|
|
23
|
+
//
|
|
24
|
+
// An invalid or incomplete regex (e.g. "/foo(" mid-typing) never throws and never filters:
|
|
25
|
+
// that term goes INERT (matches everything) and parse() reports it in `invalid` so the box can
|
|
26
|
+
// show a soft warning state. Degrading to inert, not substring, is deliberate: treating "/fo("
|
|
27
|
+
// as a literal substring would blank the feed while typing, which reads as data loss.
|
|
28
|
+
// Frozen (object and all nested arrays) so the shared match-all result handed out for every
|
|
29
|
+
// empty query cannot be mutated by a consumer.
|
|
30
|
+
const MATCH_ALL = Object.freeze({
|
|
31
|
+
test: () => true,
|
|
32
|
+
invalid: Object.freeze([]),
|
|
33
|
+
hints: Object.freeze([]),
|
|
34
|
+
empty: true,
|
|
35
|
+
});
|
|
36
|
+
// Split the query into raw term tokens: whitespace-separated, but /…/ and "…" spans (with an
|
|
37
|
+
// optional leading -) stay one token even when they contain spaces. An unterminated span runs
|
|
38
|
+
// to the end of the query.
|
|
39
|
+
export function tokenize(query) {
|
|
40
|
+
const tokens = [];
|
|
41
|
+
let i = 0;
|
|
42
|
+
const n = query.length;
|
|
43
|
+
while (i < n) {
|
|
44
|
+
while (i < n && /\s/.test(query[i]))
|
|
45
|
+
i++;
|
|
46
|
+
if (i >= n)
|
|
47
|
+
break;
|
|
48
|
+
const start = i;
|
|
49
|
+
if (query[i] === "-")
|
|
50
|
+
i++;
|
|
51
|
+
const open = query[i];
|
|
52
|
+
if (open === "/" || open === '"') {
|
|
53
|
+
i++;
|
|
54
|
+
while (i < n && query[i] !== open)
|
|
55
|
+
i++;
|
|
56
|
+
if (i < n)
|
|
57
|
+
i++; // consume the closer
|
|
58
|
+
// trailing non-space glue (flags, or the rest of a pasted path) stays part of the token
|
|
59
|
+
while (i < n && !/\s/.test(query[i]))
|
|
60
|
+
i++;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
while (i < n && !/\s/.test(query[i]))
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
tokens.push(query.slice(start, i));
|
|
67
|
+
}
|
|
68
|
+
return tokens;
|
|
69
|
+
}
|
|
70
|
+
// A term is committable as a pill when non-empty, not a bare "-", and any opened /…/ or "…"
|
|
71
|
+
// span is CLOSED. Reuses the tokenizer's span logic (same rules: an optional leading -, then
|
|
72
|
+
// the first / or " opens a span that must be closed by the same character). Terms with no span
|
|
73
|
+
// opener are always complete (a bare word, or /foo/tail once the closer is past).
|
|
74
|
+
export function isCompleteTerm(raw) {
|
|
75
|
+
if (!raw)
|
|
76
|
+
return false;
|
|
77
|
+
let i = 0;
|
|
78
|
+
if (raw[i] === "-")
|
|
79
|
+
i++;
|
|
80
|
+
if (i === raw.length)
|
|
81
|
+
return false; // a bare "-" while typing is not committable
|
|
82
|
+
const open = raw[i];
|
|
83
|
+
if (open !== "/" && open !== '"')
|
|
84
|
+
return true; // no span, so complete
|
|
85
|
+
i++;
|
|
86
|
+
while (i < raw.length && raw[i] !== open)
|
|
87
|
+
i++;
|
|
88
|
+
return i < raw.length; // true only when the closer was found
|
|
89
|
+
}
|
|
90
|
+
// A tail reads as regex flags only when it is the short flag string fingers actually type:
|
|
91
|
+
// 1-2 letters from i/m/s/g with no repeats. Longer or letter-repeating tails (img, ims, sms)
|
|
92
|
+
// and anything outside the set (id, dm, us, svg, junk) read as part of a pasted path instead.
|
|
93
|
+
function asFlagTail(tail) {
|
|
94
|
+
if (!/^[gims]{1,2}$/.test(tail))
|
|
95
|
+
return null;
|
|
96
|
+
if (tail.length === 2 && tail[0] === tail[1])
|
|
97
|
+
return null;
|
|
98
|
+
return tail;
|
|
99
|
+
}
|
|
100
|
+
function compileTerm(raw, invalid, hints, kinds) {
|
|
101
|
+
let negate = false;
|
|
102
|
+
let body = raw;
|
|
103
|
+
if (body.startsWith("-")) {
|
|
104
|
+
negate = true;
|
|
105
|
+
body = body.slice(1);
|
|
106
|
+
}
|
|
107
|
+
if (!body)
|
|
108
|
+
return null; // a bare "-" while typing: inert
|
|
109
|
+
if (body[0] === "/") {
|
|
110
|
+
// Three shapes: /pat/ (closed), /pat/flags (short flag tail), or best-effort (everything
|
|
111
|
+
// after the leading slash is ONE pattern: mid-typing, or a pasted path like /api/users).
|
|
112
|
+
// The flags-vs-path ambiguity is inherent (/api/im is both), so whichever way an ambiguous
|
|
113
|
+
// tail is read, the reading lands in `hints` and quoting is the documented escape hatch.
|
|
114
|
+
let src;
|
|
115
|
+
let rawFlags = "";
|
|
116
|
+
if (body.length >= 2 && body.endsWith("/")) {
|
|
117
|
+
src = body.slice(1, -1);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const lastSlash = body.lastIndexOf("/");
|
|
121
|
+
const tail = lastSlash > 0 ? body.slice(lastSlash + 1) : "";
|
|
122
|
+
const flags = tail ? asFlagTail(tail) : null;
|
|
123
|
+
if (flags) {
|
|
124
|
+
src = body.slice(1, lastSlash);
|
|
125
|
+
rawFlags = flags;
|
|
126
|
+
hints.push(`${raw} read as regex "${src}" with flags "${flags}". Quote it to match the text literally`);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
src = body.slice(1);
|
|
130
|
+
if (lastSlash > 0) {
|
|
131
|
+
hints.push(`${raw} read as one regex "${src}". Quote it to match the text literally`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!src)
|
|
136
|
+
return null; // "/" or "//" while typing: inert
|
|
137
|
+
let flags = rawFlags.replace(/g/g, "");
|
|
138
|
+
if (!flags.includes("i"))
|
|
139
|
+
flags += "i";
|
|
140
|
+
try {
|
|
141
|
+
const re = new RegExp(src, flags);
|
|
142
|
+
return { negate, test: (t) => re.test(t) };
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
invalid.push(raw);
|
|
146
|
+
return null; // invalid regex: inert, reported
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (body[0] === '"') {
|
|
150
|
+
const closed = body.length >= 2 && body[body.length - 1] === '"';
|
|
151
|
+
const phrase = (closed ? body.slice(1, -1) : body.slice(1)).toLowerCase();
|
|
152
|
+
if (!phrase)
|
|
153
|
+
return null;
|
|
154
|
+
return { negate, test: (t) => t.includes(phrase) };
|
|
155
|
+
}
|
|
156
|
+
const needle = body.toLowerCase();
|
|
157
|
+
if (negate && kinds.has(needle)) {
|
|
158
|
+
// A negated KIND NAME excludes by row type ONLY when kind matching is active (the Live
|
|
159
|
+
// view passes kind). Substring must not participate: "-log" would otherwise also hide
|
|
160
|
+
// any clog whose text contains "log" (logout_success, app_login), which is exactly the
|
|
161
|
+
// silent data loss kind matching exists to prevent. On single-source tabs (kind
|
|
162
|
+
// undefined) it falls back to plain substring exclusion, same as any other term.
|
|
163
|
+
return { negate, test: (t, kind) => (kind !== undefined ? kind === needle : t.includes(needle)) };
|
|
164
|
+
}
|
|
165
|
+
return { negate, test: (t, kind) => t.includes(needle) || kind === needle };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Parse a filter-box query into a compiled predicate. Call on filter CHANGE only (the result
|
|
169
|
+
* is stable for a given query); run `parsed.test(searchText(ev), kind?)` per row.
|
|
170
|
+
* `kindNames` is the vocabulary of row-type names ("log", "clog", …) that get kind semantics;
|
|
171
|
+
* the caller owns it (registry's STREAM_KINDS) so this module stays pure and dependency-free.
|
|
172
|
+
*/
|
|
173
|
+
export function parseFilter(query, kindNames) {
|
|
174
|
+
const q = (query || "").trim();
|
|
175
|
+
if (!q)
|
|
176
|
+
return MATCH_ALL;
|
|
177
|
+
const kinds = new Set(kindNames || []);
|
|
178
|
+
const invalid = [];
|
|
179
|
+
const hints = [];
|
|
180
|
+
const terms = [];
|
|
181
|
+
for (const raw of tokenize(q)) {
|
|
182
|
+
const t = compileTerm(raw, invalid, hints, kinds);
|
|
183
|
+
if (t)
|
|
184
|
+
terms.push(t);
|
|
185
|
+
}
|
|
186
|
+
if (!terms.length)
|
|
187
|
+
return { test: () => true, invalid, hints, empty: true };
|
|
188
|
+
return {
|
|
189
|
+
test: (text, kind) => {
|
|
190
|
+
for (const t of terms) {
|
|
191
|
+
if (t.test(text, kind) === t.negate)
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
},
|
|
196
|
+
invalid,
|
|
197
|
+
hints,
|
|
198
|
+
empty: false,
|
|
199
|
+
};
|
|
200
|
+
}
|