@slack/radar-mcp 1.11.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +12 -2
  2. package/dist/mcp/api-paths.js +2 -0
  3. package/dist/mcp/flags-tools.d.ts +71 -0
  4. package/dist/mcp/flags-tools.js +158 -0
  5. package/dist/mcp/index.js +103 -5
  6. package/dist/mcp/prefs-tools.d.ts +15 -0
  7. package/dist/mcp/prefs-tools.js +204 -0
  8. package/dist/mcp/session-enable.d.ts +2 -1
  9. package/dist/mcp/session-enable.js +29 -2
  10. package/dist/mcp/snapshot.js +6 -1
  11. package/dist/mcp/sources-gate.d.ts +23 -0
  12. package/dist/mcp/sources-gate.js +63 -0
  13. package/dist/mcp/tools.js +102 -2
  14. package/dist/shared/android.d.ts +33 -1
  15. package/dist/shared/android.js +203 -6
  16. package/dist/shared/constants.d.ts +8 -0
  17. package/dist/shared/constants.js +13 -1
  18. package/dist/shared/db.d.ts +21 -3
  19. package/dist/shared/db.js +89 -23
  20. package/dist/shared/feature-flags.d.ts +6 -0
  21. package/dist/shared/feature-flags.js +17 -0
  22. package/dist/shared/prefs.d.ts +78 -0
  23. package/dist/shared/prefs.js +416 -0
  24. package/dist/shared/transport.d.ts +68 -0
  25. package/dist/web/log-session.d.ts +13 -0
  26. package/dist/web/log-session.js +16 -0
  27. package/dist/web/public/index.html +129 -3
  28. package/dist/web/public/next/app.js +82 -4
  29. package/dist/web/public/next/feed.js +270 -14
  30. package/dist/web/public/next/filter.js +200 -0
  31. package/dist/web/public/next/flags.js +179 -0
  32. package/dist/web/public/next/prefs.js +399 -0
  33. package/dist/web/public/next/registry.js +16 -6
  34. package/dist/web/public/next/store.js +250 -11
  35. package/dist/web/server.js +267 -7
  36. package/dist/web/spec.d.ts +7 -7
  37. package/dist/web/spec.js +15 -9
  38. package/package.json +1 -1
@@ -0,0 +1,179 @@
1
+ // Feature Flags browser (source:"flags") -- a live view of the running Slack app's feature
2
+ // flags. Loads a point-in-time snapshot, then subscribes to the device's on-device observer so
3
+ // rows update in place as overrides/server values change. Like the DB browser it must NOT import
4
+ // the streaming store (that would start the store's own SSE engine + timers on this tab); it
5
+ // opens its OWN short-lived EventSource on /stream and closes it on unmount.
6
+ //
7
+ // Server contract (server.ts proxies to the device feature-flag RadarPlugin):
8
+ // GET /flags -> { feature_flags: FlagRow[], total } | { error, feature_flags: [] }
9
+ //
10
+ // Each FlagRow (device list = summary, kept light):
11
+ // key flag name, e.g. "android_some_flag"
12
+ // enabled the EFFECTIVE value the app uses right now (local override if set, else the
13
+ // server value). Boolean today; a string (variant group name) is rendered too,
14
+ // defensively, in case the device plugin regains multi-variant support.
15
+ // is_overridden true when a local debug override is active
16
+ //
17
+ // Live updates: the device observer pushes `feature_flag` frames on /api/stream (proxied to
18
+ // /stream) whenever a flag's effective value changes: {type:"feature_flag", event:{key, enabled,
19
+ // is_overridden}}. We upsert those into the row set by key and briefly flash the changed row.
20
+ //
21
+ // Columns: flag | value | origin. `value` = enabled (ON/OFF, or a variant group pill). `origin`
22
+ // = Override (local) when is_overridden, else Server. (The device no longer sends a separate
23
+ // server value or scope in the list, so those columns are gone.)
24
+ import { html } from "./html.js";
25
+ import { useState, useEffect, useCallback, useRef } from "preact/hooks";
26
+ // Render a flag value. Booleans (toggles) show ON/OFF; a variant group-name string shows as a
27
+ // text pill ("" / "control" read as the off/baseline arm). `dim` mutes a secondary column.
28
+ function valuePill(v, dim) {
29
+ if (v === undefined || v === null)
30
+ return html `<span class="flagval dim">—</span>`;
31
+ if (typeof v === "boolean") {
32
+ return html `<span class=${"flagval " + (v ? "on" : "off") + (dim ? " dim" : "")}>${v ? "ON" : "OFF"}</span>`;
33
+ }
34
+ const off = v === "" || v.toLowerCase() === "control";
35
+ return html `<span class=${"flagval variant " + (off ? "off" : "on") + (dim ? " dim" : "")}>${v || "—"}</span>`;
36
+ }
37
+ // Why a flag has its effective value. No SERVER/LOCAL state field anymore, so origin is derived
38
+ // purely from whether a local override is active.
39
+ function origin(f) {
40
+ return f.is_overridden === true
41
+ ? { label: "Override (local)", cls: "or-override" }
42
+ : { label: "Server", cls: "or-server" };
43
+ }
44
+ const FLASH_MS = 1200;
45
+ export function FlagsBrowser() {
46
+ // rows: the current flag set keyed by name (upserted by both the snapshot and live events).
47
+ const [rows, setRows] = useState(null); // null = loading
48
+ const [err, setErr] = useState(null);
49
+ const [filter, setFilter] = useState("");
50
+ // keys that changed recently (drives the row flash); value is a token cleared on a timer.
51
+ const [flashed, setFlashed] = useState({});
52
+ const flashTimers = useRef({});
53
+ const flash = useCallback((key) => {
54
+ setFlashed((f) => ({ ...f, [key]: (f[key] || 0) + 1 }));
55
+ const timers = flashTimers.current;
56
+ if (timers[key])
57
+ clearTimeout(timers[key]);
58
+ timers[key] = setTimeout(() => {
59
+ setFlashed((f) => {
60
+ const next = { ...f };
61
+ delete next[key];
62
+ return next;
63
+ });
64
+ delete timers[key];
65
+ }, FLASH_MS);
66
+ }, []);
67
+ const load = useCallback(async () => {
68
+ setRows(null);
69
+ setErr(null);
70
+ try {
71
+ const r = await (await fetch("/flags")).json();
72
+ if (r.error) {
73
+ setErr(r.error);
74
+ setRows({});
75
+ return;
76
+ }
77
+ const byKey = {};
78
+ for (const fl of r.feature_flags || [])
79
+ byKey[fl.key] = fl;
80
+ setRows(byKey);
81
+ }
82
+ catch {
83
+ setErr("network error loading feature flags");
84
+ setRows({});
85
+ }
86
+ }, []);
87
+ // initial snapshot
88
+ useEffect(() => {
89
+ load();
90
+ }, []);
91
+ // Live observer: our OWN EventSource (not the store's). Patch rows on `feature_flag` frames.
92
+ useEffect(() => {
93
+ const es = new EventSource("/stream");
94
+ es.onmessage = (m) => {
95
+ let f;
96
+ try {
97
+ f = JSON.parse(m.data);
98
+ }
99
+ catch {
100
+ return;
101
+ }
102
+ if (f.type !== "feature_flag" || !f.event || !f.event.key)
103
+ return;
104
+ const ev = f.event;
105
+ setRows((prev) => ({ ...(prev || {}), [ev.key]: { ...(prev && prev[ev.key]), ...ev } }));
106
+ flash(ev.key);
107
+ };
108
+ // The tab works without live updates; a stream error just means no live patching.
109
+ es.onerror = () => { };
110
+ return () => es.close();
111
+ }, [flash]);
112
+ // clear any pending flash timers on unmount
113
+ useEffect(() => () => {
114
+ for (const t of Object.values(flashTimers.current))
115
+ clearTimeout(t);
116
+ }, []);
117
+ const all = rows ? Object.values(rows).sort((a, b) => a.key.localeCompare(b.key)) : [];
118
+ const f = filter.trim().toLowerCase();
119
+ const shown = f ? all.filter((x) => (x.key || "").toLowerCase().includes(f)) : all;
120
+ const meta = rows == null ? "" : f ? shown.length + " / " + all.length + " shown" : all.length + " flags";
121
+ return html `
122
+ <div class="flagsview">
123
+ <div class="flagsbar">
124
+ <span class="ffilterwrap">
125
+ <input
126
+ class="ffilter"
127
+ value=${filter}
128
+ placeholder="filter flags by name…"
129
+ autocomplete="off"
130
+ onInput=${(e) => setFilter(e.currentTarget.value)}
131
+ onKeyDown=${(e) => {
132
+ if (e.key === "Escape")
133
+ setFilter("");
134
+ }}
135
+ />
136
+ ${filter ? html `<span class="ffilterclear" title="clear filter" onClick=${() => setFilter("")}>✕</span>` : null}
137
+ </span>
138
+ <span class="flagsmeta">${meta}</span>
139
+ <button class="flagsrefresh" title="re-fetch the snapshot" onClick=${() => load()}>↻ refresh</button>
140
+ </div>
141
+ <div class="dbout flagsout">
142
+ ${rows == null
143
+ ? html `<div class="msg">loading…</div>`
144
+ : err
145
+ ? html `<div class="msg err">${err}</div>`
146
+ : !all.length
147
+ ? html `<div class="msg">no feature flags (device unreachable, or this build predates the feature-flag plugin)</div>`
148
+ : !shown.length
149
+ ? html `<div class="msg">no flags match “${filter}”</div>`
150
+ : html `<${Table} rows=${shown} flashed=${flashed} />`}
151
+ </div>
152
+ </div>
153
+ `;
154
+ }
155
+ function Table({ rows, flashed }) {
156
+ return html `
157
+ <table>
158
+ <thead>
159
+ <tr>
160
+ <th>flag</th>
161
+ <th class="val">value</th>
162
+ <th class="origin">origin</th>
163
+ </tr>
164
+ </thead>
165
+ <tbody>
166
+ ${rows.map((x) => {
167
+ const o = origin(x);
168
+ const ov = x.is_overridden === true;
169
+ const cls = (ov ? "overridden" : "") + (flashed[x.key] ? " flash" : "");
170
+ return html `<tr class=${cls}>
171
+ <td class="key" title=${x.key}>${x.key}</td>
172
+ <td class="val">${valuePill(x.enabled)}</td>
173
+ <td class="origin"><span class=${"orbadge " + o.cls}>${o.label}</span></td>
174
+ </tr>`;
175
+ })}
176
+ </tbody>
177
+ </table>
178
+ `;
179
+ }
@@ -0,0 +1,399 @@
1
+ // Prefs browser (source:"prefs") -- read-only on-device SharedPreferences browser: file list ->
2
+ // entries, with a profile picker on dual-profile devices. Mirrors db.ts exactly: file list on
3
+ // the left, entries in the main pane, dual-profile picker, privacy banner. Server contract:
4
+ // /prefs?user= -> { user, available_users: string[], files: {name,size}[] } | { error, files:[], available_users:[] }
5
+ // /prefsread?file=&user=&keys= -> { file, user, entries: {key,type,value}[], device_read_truncated?, total_entries, returned_entries } | { error }
6
+ // /prefssearch?query=&user= -> { query, user, available_users, results, truncated?, skipped?: string[] }
7
+ //
8
+ // IMPORTANT (plan requirement): this module must NOT import the streaming store. The Prefs tab is
9
+ // point-in-time, not a live feed; pulling the store would start the SSE engine + timers on a
10
+ // tab that has no use for them. It carries its own keyboard nav since there is no Feed here.
11
+ import { html } from "./html.js";
12
+ import { useState, useEffect, useCallback, useRef } from "preact/hooks";
13
+ import { useLatestRef, useGlobalKeydown } from "./hooks.js";
14
+ import { highlightJson } from "./inspector.js";
15
+ function profileLabel(u) {
16
+ return u === "" || u == null ? "device" : u === "0" ? "personal (user 0)" : "secondary (user " + u + ")";
17
+ }
18
+ // Badge for feature-flag prefs files
19
+ function isFfFile(name) {
20
+ return name.startsWith("debug_features_") || name.startsWith("easy_features_") || name.startsWith("feature_flags_");
21
+ }
22
+ // `(size/1024)|0` truncates every file under 1024 bytes to a flat, indistinguishable "0 KB" --
23
+ // on a real device a third-plus of the files are that small (locale_prefs, security prefs,
24
+ // small per-team overrides), so the list read as broken/unsorted rather than correctly sorted
25
+ // with tiny files at the bottom. Show exact bytes below 1KB, one decimal of KB below 10KB
26
+ // (rounds small-but-real files like "1.8 KB" instead of collapsing to "1 KB"), whole KB above.
27
+ function formatSize(bytes) {
28
+ if (bytes < 1024)
29
+ return bytes + " B";
30
+ if (bytes < 10240)
31
+ return (bytes / 1024).toFixed(1) + " KB";
32
+ return Math.round(bytes / 1024) + " KB";
33
+ }
34
+ // Below this, a file is functionally empty (a handful of scalar entries at most) -- muted in
35
+ // the list so attention goes to the files worth opening, without hiding them entirely.
36
+ const TINY_FILE_BYTES = 200;
37
+ export function PrefsBrowser({ spec }) {
38
+ const [user, setUser] = useState(null);
39
+ const [files, setFiles] = useState(null); // null = loading
40
+ const [selectedFile, setSelectedFile] = useState(null);
41
+ const [entries, setEntries] = useState(null); // null = loading
42
+ const [searchQuery, setSearchQuery] = useState("");
43
+ const [searchResults, setSearchResults] = useState(null);
44
+ const [searching, setSearching] = useState(false);
45
+ const [meta, setMeta] = useState("");
46
+ // Keyboard nav covers the FILE LIST only (j/k + Enter to open). The entries pane is
47
+ // mouse-driven: it had a keyboard highlight once, but a green outline landing on an
48
+ // arbitrary row read as a rendering glitch, so entries keyboard nav was removed.
49
+ const [fileIdx, setFileIdx] = useState(0);
50
+ // Which row (by flat index across all visible PrefsGrid instances) is expanded to show its
51
+ // full value. Owned here so ONE index can address a row inside whichever of the (possibly
52
+ // several, one per matching search file) PrefsGrid instances renders it.
53
+ const [expandedIdx, setExpandedIdx] = useState(null);
54
+ // Bumped on every pickFile/search call so a slower, now-stale fetch cannot land after a newer
55
+ // one already resolved or after the user clicked away -- e.g. clicking a file while a search
56
+ // is still in flight must not let the search response overwrite the file's entries once it
57
+ // finally arrives (the pane/searching state would otherwise say "not searching" while a search
58
+ // result still shows up a moment later).
59
+ const requestIdRef = useRef(0);
60
+ const userQS = useCallback((u) => (u != null ? "&user=" + encodeURIComponent(u) : ""), []);
61
+ const loadFiles = useCallback(async (u) => {
62
+ setFiles(null);
63
+ try {
64
+ const r = await (await fetch("/prefs?" + (u != null ? "user=" + encodeURIComponent(u) : ""))).json();
65
+ setFiles(r);
66
+ if (!r.error)
67
+ setUser(r.user ?? null);
68
+ }
69
+ catch (e) {
70
+ setFiles({ error: "network error loading preferences files" });
71
+ }
72
+ }, []);
73
+ // initial load
74
+ useEffect(() => {
75
+ loadFiles(null);
76
+ }, []);
77
+ // keep the keyboard highlight in range when the file list changes
78
+ useEffect(() => {
79
+ const count = (files && files.files) ? files.files.length : 0;
80
+ setFileIdx((i) => Math.max(0, Math.min(count - 1, i)));
81
+ }, [files]);
82
+ const pickFile = useCallback(async (name) => {
83
+ // Picking a file always wins over an in-flight search: bump the request token so that
84
+ // search's eventual response (if any) is discarded on arrival, and drop the "searching"
85
+ // spinner immediately rather than leaving it spinning for a search the user just abandoned.
86
+ const myRequestId = ++requestIdRef.current;
87
+ setSelectedFile(name);
88
+ setSearchQuery("");
89
+ setSearchResults(null);
90
+ setSearching(false);
91
+ setEntries(null);
92
+ try {
93
+ const r = await (await fetch("/prefsread?file=" + encodeURIComponent(name) + userQS(user))).json();
94
+ if (requestIdRef.current !== myRequestId)
95
+ return; // superseded by a newer click
96
+ setEntries(r);
97
+ if (!r.error) {
98
+ const note = r.device_read_truncated ? " (device 256KB cap)" : "";
99
+ setMeta(name + " — " + (r.returned_entries ?? 0) + " of " + (r.total_entries ?? 0) + " entries" + note + " · " + profileLabel(user));
100
+ }
101
+ }
102
+ catch (e) {
103
+ if (requestIdRef.current !== myRequestId)
104
+ return;
105
+ setEntries({ error: "network error loading preferences" });
106
+ }
107
+ }, [user, userQS]);
108
+ const search = useCallback(async (q) => {
109
+ const myRequestId = ++requestIdRef.current;
110
+ if (!q) {
111
+ setSearchQuery("");
112
+ setSearchResults(null);
113
+ setSearching(false);
114
+ return;
115
+ }
116
+ setSearchQuery(q);
117
+ setSearching(true);
118
+ try {
119
+ const r = await (await fetch("/prefssearch?query=" + encodeURIComponent(q) + userQS(user))).json();
120
+ // A file click (or a newer search) superseded this request while it was in flight --
121
+ // discard the result instead of overwriting whatever the user has since selected.
122
+ if (requestIdRef.current !== myRequestId)
123
+ return;
124
+ setSearchResults(r);
125
+ setSearching(false);
126
+ if (!r.error) {
127
+ const note = r.skipped && r.skipped.length ? " (" + r.skipped.length + " files could not be read)" : "";
128
+ setMeta("search: " + q + " — " + (r.results?.length ?? 0) + " files" + note + " · " + profileLabel(user));
129
+ }
130
+ }
131
+ catch (e) {
132
+ if (requestIdRef.current !== myRequestId)
133
+ return;
134
+ setSearchResults({ error: "network error searching preferences" });
135
+ setSearching(false);
136
+ }
137
+ }, [user, userQS]);
138
+ const sideRef = useRef(null);
139
+ useEffect(() => {
140
+ const host = sideRef.current;
141
+ const el = host && host.querySelector(".kbd");
142
+ if (el && el.scrollIntoView)
143
+ el.scrollIntoView({ block: "nearest" });
144
+ }, [fileIdx]);
145
+ // Keyboard navigation, file list only: j/k move, Enter opens, Escape closes a click-expanded
146
+ // value. There is no "pane" concept anymore -- the file list is the only keyboard-focusable
147
+ // list, and expanding/collapsing a value is a click-only action.
148
+ const fileNames = (files && files.files) || [];
149
+ const expandedIdxRef = useLatestRef(expandedIdx);
150
+ const st = useLatestRef({ fileNames, fileIdx, pickFile, expandedIdxRef });
151
+ useGlobalKeydown((e) => {
152
+ // never hijack search or profile dropdown
153
+ const t = e.target;
154
+ if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.tagName === "SELECT" || t.isContentEditable))
155
+ return;
156
+ if (e.metaKey || e.ctrlKey || e.altKey)
157
+ return;
158
+ const s = st.current;
159
+ switch (e.key) {
160
+ case "ArrowDown":
161
+ case "j":
162
+ if (!s.fileNames.length)
163
+ return;
164
+ setExpandedIdx(null); // moving the highlight closes whatever was expanded
165
+ setFileIdx((i) => Math.min(s.fileNames.length - 1, i + 1));
166
+ break;
167
+ case "ArrowUp":
168
+ case "k":
169
+ if (!s.fileNames.length)
170
+ return;
171
+ setExpandedIdx(null);
172
+ setFileIdx((i) => Math.max(0, i - 1));
173
+ break;
174
+ case "Enter": {
175
+ const file = s.fileNames[s.fileIdx];
176
+ if (file)
177
+ s.pickFile(file.name);
178
+ break;
179
+ }
180
+ case "Escape":
181
+ if (s.expandedIdxRef.current !== null)
182
+ setExpandedIdx(null);
183
+ else
184
+ return;
185
+ break;
186
+ default:
187
+ return;
188
+ }
189
+ e.preventDefault();
190
+ });
191
+ const RENDER_LIMIT = 10000;
192
+ // Sort files by size descending (biggest/most-interesting first)
193
+ const sortedFiles = files && files.files ? [...files.files].sort((a, b) => b.size - a.size) : [];
194
+ return html `
195
+ <div class="prefsview">
196
+ <div class="prefsside" ref=${sideRef}>
197
+ <div class="prefssec">files</div>
198
+ ${files == null
199
+ ? html `<div class="msg">loading…</div>`
200
+ : files.error
201
+ ? html `<div class="msg err">${files.error}</div>`
202
+ : !files.files || !files.files.length
203
+ ? html `<div class="msg">no preference files (device unreachable, or debug build not installed)</div>`
204
+ : html `
205
+ ${(files.available_users || []).length > 1
206
+ ? html `<div class="prefsprofile">
207
+ <span class="prefsprofcap">profile</span>
208
+ <select
209
+ onChange=${(e) => {
210
+ const v = e.currentTarget.value;
211
+ requestIdRef.current++; // discard any in-flight search/read from the old profile
212
+ setUser(v);
213
+ setSelectedFile(null);
214
+ setEntries(null);
215
+ setSearchResults(null);
216
+ setSearchQuery("");
217
+ setSearching(false);
218
+ setMeta("");
219
+ loadFiles(v);
220
+ }}
221
+ >
222
+ ${files.available_users.map((u) => html `<option value=${u} selected=${u === files.user}>${profileLabel(u)}</option>`)}
223
+ </select>
224
+ </div>`
225
+ : html `<div class="prefsprofile">profile: <b>${profileLabel(files.user)}</b></div>`}
226
+ ${sortedFiles.map((f, i) => html `<div
227
+ class=${"prefsitem" + (f.name === selectedFile ? " sel" : "") + (i === fileIdx ? " kbd" : "") + (f.size < TINY_FILE_BYTES ? " tiny" : "")}
228
+ onClick=${() => {
229
+ setFileIdx(i);
230
+ pickFile(f.name);
231
+ }}
232
+ >
233
+ <span class="prefsitemname" title=${f.name}>${f.name}</span>${isFfFile(f.name) ? html `<span class="ffbadge">[FF]</span>` : null}<span class="size">${formatSize(f.size)}</span>
234
+ </div>`)}
235
+ `}
236
+ </div>
237
+ <div class="prefsmain">
238
+ <div class="prefsprivacy">
239
+ Preference values can include user, team, and org identifiers. Review before sharing.
240
+ </div>
241
+ <div class="prefssearchbar">
242
+ <div class="prefssearchlabel">Search ACROSS ALL FILES</div>
243
+ <div class="prefssearch">
244
+ <input
245
+ value=${searchQuery}
246
+ placeholder="e.g. slackbot, count, feature name…"
247
+ autocomplete="off"
248
+ onInput=${(e) => {
249
+ const v = e.currentTarget.value;
250
+ setSearchQuery(v);
251
+ }}
252
+ onKeyDown=${(e) => {
253
+ if (e.key === "Enter")
254
+ search(searchQuery);
255
+ }}
256
+ />
257
+ <button disabled=${searching} onClick=${() => search(searchQuery)}>${searching ? html `<span class="spinner"></span> Searching…` : "Search"}</button>
258
+ ${selectedFile && !searchQuery ? html `<button class="prefsrefresh" onClick=${() => pickFile(selectedFile)}>↻ refresh</button>` : null}
259
+ </div>
260
+ </div>
261
+ <div class="prefsmeta">${searching ? "searching…" : meta}</div>
262
+ <div class="prefsout">
263
+ ${searching
264
+ ? html `<div class="msg">searching all files…</div>`
265
+ : searchResults
266
+ ? searchResults.error
267
+ ? html `<div class="msg err">${searchResults.error}</div>`
268
+ : !searchResults.results || !searchResults.results.length
269
+ ? // "no matches" must never stand alone when files were skipped -- skipped:[]
270
+ // means "searched everything, found nothing" (a real answer); a non-empty
271
+ // skipped array means some files were never actually searched (a run-as
272
+ // denial, mid-write, or unreadable file), which reads as a false negative
273
+ // if the UI shows the same "no matches" text either way. `results` only
274
+ // lists files WITH a match, so there is no total-files-searched count to
275
+ // quote here -- name what is known (skipped count) without inventing one.
276
+ html `
277
+ ${searchResults.skipped && searchResults.skipped.length
278
+ ? html `<div class="truncwarn err">${searchResults.skipped.length} file${searchResults.skipped.length === 1 ? "" : "s"} could not be read. "No matches" only reflects the files that were searched.</div>`
279
+ : null}
280
+ <div class="msg">no matches</div>
281
+ `
282
+ : html `
283
+ ${searchResults.skipped && searchResults.skipped.length
284
+ ? html `<div class="truncwarn">${searchResults.skipped.length} files could not be read.</div>`
285
+ : null}
286
+ ${(() => {
287
+ let rowOffset = 0;
288
+ return searchResults.results.slice(0, RENDER_LIMIT).map((group) => {
289
+ const result = html `<div class="searchgroup">
290
+ <div class="searchfile">${group.file}</div>
291
+ <${PrefsGrid}
292
+ rows=${group.matches}
293
+ rowOffset=${rowOffset}
294
+ expandedIdx=${expandedIdx}
295
+ onToggleExpanded=${(idx) => setExpandedIdx(idx === expandedIdx ? null : idx)}
296
+ />
297
+ </div>`;
298
+ rowOffset += group.matches.length;
299
+ return result;
300
+ });
301
+ })()}
302
+ ${searchResults.results.length > RENDER_LIMIT
303
+ ? html `<div class="msg">(showing first ${RENDER_LIMIT} of ${searchResults.results.length} files)</div>`
304
+ : null}
305
+ `
306
+ : selectedFile == null
307
+ ? html `<div class="msg">pick a preferences file, or search above</div>`
308
+ : entries == null
309
+ ? html `<div class="msg">loading…</div>`
310
+ : entries.error
311
+ ? html `<div class="msg err">${entries.error}</div>`
312
+ : html `
313
+ ${entries.device_read_truncated ? html `<div class="truncwarn">This read stopped partway through the file on the device (256KB cap).</div>` : null}
314
+ ${!entries.entries || !entries.entries.length
315
+ ? html `<div class="msg">0 entries</div>`
316
+ : html `<${PrefsGrid}
317
+ rows=${entries.entries}
318
+ rowOffset=${0}
319
+ expandedIdx=${expandedIdx}
320
+ onToggleExpanded=${(idx) => setExpandedIdx(idx === expandedIdx ? null : idx)}
321
+ />`}
322
+ `}
323
+ </div>
324
+ </div>
325
+ </div>
326
+ `;
327
+ }
328
+ function copyText(e, value) {
329
+ navigator.clipboard?.writeText(value);
330
+ const btn = e.currentTarget;
331
+ const original = btn.textContent;
332
+ btn.textContent = "copied ✓";
333
+ setTimeout(() => {
334
+ btn.textContent = original;
335
+ }, 900);
336
+ }
337
+ // Parse a value string as JSON when possible, so a navigation_history/experiment blob renders
338
+ // pretty-printed (via inspector.ts's highlightJson) instead of a flat unreadable line. Falls
339
+ // back to the raw string for plain values (booleans, ints, short strings).
340
+ function tryParseJson(v) {
341
+ if (!v || (v[0] !== "{" && v[0] !== "["))
342
+ return null;
343
+ try {
344
+ return JSON.parse(v);
345
+ }
346
+ catch {
347
+ return null;
348
+ }
349
+ }
350
+ // Click a truncated value cell to expand it in place: the CSS ellipsis clips long values (a
351
+ // navigation_history or experiment_data blob easily runs to hundreds of chars, past the column
352
+ // width, with no way to read or select the rest). Expanding shows the full value, pretty-printed
353
+ // when it parses as JSON, plus a copy button -- same spirit as inspector.ts's detail view, scoped
354
+ // to one table row instead of a whole event.
355
+ function PrefsGrid({ rows, rowOffset = 0, expandedIdx = null, onToggleExpanded, }) {
356
+ return html `
357
+ <table>
358
+ <thead>
359
+ <tr>
360
+ <th>key</th>
361
+ <th>type</th>
362
+ <th>value</th>
363
+ </tr>
364
+ </thead>
365
+ <tbody>
366
+ ${rows.map((row, localIdx) => {
367
+ const globalIdx = rowOffset + localIdx;
368
+ const valueStr = String(row.value ?? "");
369
+ const isOpen = expandedIdx === globalIdx;
370
+ const parsed = isOpen ? tryParseJson(valueStr) : null;
371
+ return html `<tr>
372
+ <td title=${String(row.key ?? "")}>${String(row.key ?? "")}</td>
373
+ <td title=${String(row.type ?? "")}>${String(row.type ?? "")}</td>
374
+ <td
375
+ title="click to view full value"
376
+ class=${"val" + (isOpen ? " open" : "")}
377
+ onClick=${() => onToggleExpanded?.(globalIdx)}
378
+ >
379
+ ${valueStr}
380
+ </td>
381
+ </tr>
382
+ ${isOpen
383
+ ? html `<tr class="valexpand">
384
+ <td colspan="3">
385
+ <div class="valexpandbar">
386
+ <button onClick=${(e) => copyText(e, valueStr)}>Copy</button>
387
+ <button onClick=${() => onToggleExpanded?.(globalIdx)}>Close</button>
388
+ </div>
389
+ ${parsed !== null
390
+ ? html `<pre class="valpretty" dangerouslySetInnerHTML=${{ __html: highlightJson(parsed) }}></pre>`
391
+ : html `<pre class="valpretty">${valueStr}</pre>`}
392
+ </td>
393
+ </tr>`
394
+ : null}`;
395
+ })}
396
+ </tbody>
397
+ </table>
398
+ `;
399
+ }
@@ -32,7 +32,7 @@ export const FIELD_VALUES = {
32
32
  method: ["GET", "POST", "PUT", "DELETE", "PATCH"],
33
33
  };
34
34
  // SOURCE registry: one row per source. `kind` routes the view (streaming feed vs the
35
- // point-in-time DB browser) without a hardcoded source check.
35
+ // point-in-time state browser) without a hardcoded source check.
36
36
  export const SOURCES = {
37
37
  network: { label: "Network", kind: "stream", hasDetailEndpoint: true, eagerCapture: true, ringSize: 400, detailNoun: "the full request/response body" },
38
38
  rtm: { label: "RTM", kind: "stream", hasDetailEndpoint: true, eagerCapture: true, ringSize: 2000, detailNoun: "the full payload" },
@@ -40,7 +40,10 @@ export const SOURCES = {
40
40
  trace: { label: "Traces", kind: "stream", hasDetailEndpoint: true, ringSize: 2000, detailNoun: "the span timing and tag detail" },
41
41
  log: { label: "Logs", kind: "stream", hasDetailEndpoint: false },
42
42
  all: { label: "Live", kind: "stream" },
43
- db: { label: "Database", kind: "db" },
43
+ db: { label: "Database", kind: "state" },
44
+ prefs: { label: "Preferences", kind: "state" },
45
+ // Feature flags: a point-in-time snapshot like db/prefs (own container, no SSE feed).
46
+ flags: { label: "Feature Flags", kind: "state" },
44
47
  };
45
48
  // The set of streaming source kinds the store admits off the SSE stream (derived from SOURCES,
46
49
  // excluding the non-stream db + the unified "all" alias).
@@ -57,6 +60,13 @@ export const DETAILABLE_KINDS = Object.entries(SOURCES)
57
60
  export const EAGER_CAPTURE_KINDS = Object.entries(SOURCES)
58
61
  .filter(([, v]) => v.hasDetailEndpoint && v.eagerCapture)
59
62
  .map(([k]) => k);
63
+ // A "state" source is a point-in-time browser (db, prefs, flags), NOT a live stream. The store
64
+ // fully quiets its SSE engine + tick for these (they run their own fetch/stream), so this is the
65
+ // single check the store branches on — derived from the registry so a new state source cannot
66
+ // drift out of sync with the store's quieting logic.
67
+ export function isStateSource(source) {
68
+ return !!source && SOURCES[source]?.kind === "state";
69
+ }
60
70
  export function hasDetailEndpoint(kind) {
61
71
  return !!SOURCES[kind]?.hasDetailEndpoint;
62
72
  }
@@ -65,8 +75,8 @@ export function hasDetailEndpoint(kind) {
65
75
  // see widgets.ts). A new widget = one key here + one component.
66
76
  export const WIDGETS = ["counter", "rate", "sparkline", "graph"];
67
77
  // Source order for the modebar / global tab-switch (matches the MODES preset order).
68
- export const SOURCE_ORDER = ["all", "network", "rtm", "clog", "trace", "log", "db"];
69
- // The source options the Filters panel offers: every streaming source (db is its own container,
70
- // not a feed filter). Derived from SOURCES so adding a streaming source surfaces it in Filters
71
- // with no edit there. Ordered by SOURCE_ORDER (the modebar order) for a stable, familiar list.
78
+ export const SOURCE_ORDER = ["all", "network", "rtm", "clog", "trace", "log", "db", "prefs", "flags"];
79
+ // The source options the Filters panel offers: every streaming source (state sources like db/prefs
80
+ // are their own containers, not feed filters). Derived from SOURCES so adding a streaming source
81
+ // surfaces it in Filters with no edit there. Ordered by SOURCE_ORDER (the modebar order) for a stable, familiar list.
72
82
  export const FILTER_SOURCES = SOURCE_ORDER.filter((s) => SOURCES[s]?.kind === "stream");