@slack/radar-mcp 1.18.0 → 1.19.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 +9 -4
- package/dist/mcp/index.js +18 -1
- package/dist/mcp/web-child-env.js +10 -7
- package/dist/shared/android.d.ts +10 -21
- package/dist/shared/android.js +40 -10
- package/dist/shared/dashboard-screen.d.ts +2 -2
- package/dist/shared/ios.d.ts +5 -10
- package/dist/shared/ios.js +23 -5
- package/dist/shared/screen-artifacts.d.ts +18 -1
- package/dist/shared/screen-artifacts.js +18 -2
- package/dist/shared/screen.d.ts +8 -14
- package/dist/shared/screen.js +26 -45
- package/dist/shared/transport.d.ts +31 -19
- package/dist/shared/wire.d.ts +24 -0
- package/dist/shared/wire.js +6 -0
- package/dist/web/bin.js +13 -9
- package/dist/web/macapp/RadarApp.swift +24 -4
- package/dist/web/public/index.html +39 -4
- package/dist/web/public/next/app.js +186 -18
- package/dist/web/public/next/feed.js +60 -11
- package/dist/web/public/next/filter.js +24 -11
- package/dist/web/public/next/screen.js +154 -73
- package/dist/web/public/next/store.js +639 -28
- package/dist/web/server.d.ts +29 -8
- package/dist/web/server.js +634 -65
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ import { html } from "./html.js";
|
|
|
8
8
|
import { render } from "preact";
|
|
9
9
|
import { useState, useEffect, useCallback, useRef } from "preact/hooks";
|
|
10
10
|
import { useStoreValue } from "./hooks.js";
|
|
11
|
-
import { store, MODES, modeServed, describeConstraints } from "./store.js";
|
|
11
|
+
import { store, MODES, modeServed, describeConstraints, AUTO_REARM_MAX_FAILS } from "./store.js";
|
|
12
12
|
import { SOURCES } from "./registry.js";
|
|
13
13
|
import { Feed } from "./feed.js";
|
|
14
14
|
import { Cards } from "./widgets.js";
|
|
@@ -18,6 +18,17 @@ import { DbBrowser } from "./db.js";
|
|
|
18
18
|
import { FlagsBrowser } from "./flags.js";
|
|
19
19
|
import { PrefsBrowser } from "./prefs.js";
|
|
20
20
|
import { ScreenOverlay } from "./screen.js";
|
|
21
|
+
// Dismissal is per-browser on purpose: the marker file is per-machine, so without a local flag
|
|
22
|
+
// the hint would come back on every load for a user who already chose to ignore it.
|
|
23
|
+
const SETUP_HINT_DISMISS_KEY = "radar-setup-hint-dismissed";
|
|
24
|
+
function readSetupHintDismissed() {
|
|
25
|
+
try {
|
|
26
|
+
return localStorage.getItem(SETUP_HINT_DISMISS_KEY) === "1";
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
21
32
|
function readTheme() {
|
|
22
33
|
try {
|
|
23
34
|
return document.documentElement.classList.contains("light") ? "light" : "dark";
|
|
@@ -37,11 +48,9 @@ function DeviceChip() {
|
|
|
37
48
|
// Unpinned with exactly one ready device: bare adb targets that device anyway, so name it
|
|
38
49
|
// instead of claiming "none". "none" is reserved for genuinely nothing attached.
|
|
39
50
|
const label = selected?.label ?? (ready.length === 1 ? ready[0].label : "none");
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
// header row explain the same outage twice, and the reconnect reason is the later answer.
|
|
44
|
-
const deviceError = store.visibleEnableError ? null : store.deviceError;
|
|
51
|
+
// The chip carries only the picker. Its pick error renders in the Header AFTER the controls
|
|
52
|
+
// (see pickError there): inside the chip, the error's mount/unmount changed the chip's width and
|
|
53
|
+
// moved the Reconnect button beside it at exactly the attempt boundaries a user reaches for it.
|
|
45
54
|
if (store.devicesError) {
|
|
46
55
|
return html `<span class="profilewrap" title="adb devices failed; check adb">device: <b>adb error</b></span>`;
|
|
47
56
|
}
|
|
@@ -51,19 +60,63 @@ function DeviceChip() {
|
|
|
51
60
|
${!selected ? html `<option value="" selected disabled>pick a device…</option>` : null}
|
|
52
61
|
${ready.map((d) => html `<option value=${d.serial} selected=${d.serial === selected?.serial}>${d.label} (${d.serial})</option>`)}
|
|
53
62
|
</select>`;
|
|
54
|
-
return html `<span class="profilewrap" title="the device Radar is bound to; pick another to switch">device: ${picker}
|
|
63
|
+
return html `<span class="profilewrap" title="the device Radar is bound to; pick another to switch">device: ${picker}</span>`;
|
|
55
64
|
}
|
|
56
65
|
export function Header({ screenOpen, onScreenToggle }) {
|
|
57
66
|
const conn = useStoreValue(store, "conn", () => store.conn);
|
|
58
67
|
// Why the last Reconnect press failed, shown next to the button that produced it. The store's
|
|
59
|
-
// getter owns
|
|
60
|
-
// earlier one
|
|
68
|
+
// getter owns all three conditions (disconnected, the reason belongs to THIS outage rather
|
|
69
|
+
// than an earlier one, and no fresh flight is in progress — a new attempt supersedes the old
|
|
70
|
+
// answer), so there is no gating to get wrong here.
|
|
61
71
|
const enableError = useStoreValue(store, "enable-error", () => store.visibleEnableError);
|
|
72
|
+
const enableInstructs = useStoreValue(store, "enable-error", () => store.visibleEnableInstructs);
|
|
62
73
|
const profile = useStoreValue(store, "profile", () => store.profileLabel);
|
|
63
74
|
const version = useStoreValue(store, "version", () => store.serverVersion);
|
|
64
75
|
const selfHeal = useStoreValue(store, "self-heal", () => store.selfHeal);
|
|
76
|
+
const setupHint = useStoreValue(store, "setup-hint", () => store.setupHint);
|
|
65
77
|
const stopped = useStoreValue(store, "stopped", () => store.stopped);
|
|
66
|
-
|
|
78
|
+
// The recovery state, all store-owned: `enabling` is the single-flight latch reconnect()
|
|
79
|
+
// itself holds (manual press and auto-re-arm alike), so the button disables and relabels
|
|
80
|
+
// off the same fact that refuses a concurrent /enable. `sessionEnded` drives the conn span
|
|
81
|
+
// (the fixed diagnosis) and, with `exhausted`/`terminal`, the recovery tail rendered after
|
|
82
|
+
// the button: the diagnosed message must come from the latch, not conn.msg, because
|
|
83
|
+
// pollHealth's generic "device offline, retrying…" overwrites conn.msg within one 2s tick —
|
|
84
|
+
// and is factually wrong for this outage mode.
|
|
85
|
+
const enabling = useStoreValue(store, "enabling", () => store.enabling);
|
|
86
|
+
const autoRearming = useStoreValue(store, "auto-rearm", () => store.autoRearming);
|
|
87
|
+
const sessionEnded = useStoreValue(store, "session-ended", () => store.sessionEnded);
|
|
88
|
+
const exhausted = useStoreValue(store, "auto-rearm", () => store.autoRearmExhausted);
|
|
89
|
+
const terminal = useStoreValue(store, "auto-rearm", () => store.autoRearmTerminal);
|
|
90
|
+
const flapped = useStoreValue(store, "auto-rearm", () => store.autoRearmFlapped);
|
|
91
|
+
const suppressed = useStoreValue(store, "auto-rearm", () => store.autoRearmSuppressed);
|
|
92
|
+
const needsPick = useStoreValue(store, "devices", () => store.needsDevicePick);
|
|
93
|
+
// Whether this dashboard process may arm the device on its own (an agent spawned it, or
|
|
94
|
+
// SLACK_RADAR_NO_ARM is set). Such a tab NEVER arms unattended, so it must not promise a
|
|
95
|
+
// retry or offer to stop one — it says what is true for it: press the button. Tri-state:
|
|
96
|
+
// null means no /health reply has answered yet, and the store refuses to arm until one does,
|
|
97
|
+
// so an unanswered tab hides the automation controls like a blocked one (mayAutoRearm false)
|
|
98
|
+
// but renders its own "checking…" tail rather than an instruction the reply may withdraw.
|
|
99
|
+
const selfArmBlocked = useStoreValue(store, "self-arm-blocked", () => store.selfArmBlocked);
|
|
100
|
+
const mayAutoRearm = selfArmBlocked === false;
|
|
101
|
+
// A device-select failure (e.g. an ambiguous /enable 409). Only a later pick that works clears
|
|
102
|
+
// it; a bound-device change does not (a failed pick the server did pin moves the baseline
|
|
103
|
+
// after the error is written, so the error is about the device just pinned — see
|
|
104
|
+
// checkSerialEdge). Suppressed while a reconnect reason is on screen (two differently worded
|
|
105
|
+
// spans explaining one outage) and during an /enable flight (a new attempt supersedes the old
|
|
106
|
+
// answer, and visibleEnableError is null for the same reason).
|
|
107
|
+
const pickError = useStoreValue(store, "device-error", () => store.deviceError);
|
|
108
|
+
const pickInstructs = useStoreValue(store, "device-error", () => store.deviceErrorInstructs);
|
|
109
|
+
const visiblePickError = enableError || enabling ? null : pickError;
|
|
110
|
+
const [hintDismissed, setHintDismissed] = useState(readSetupHintDismissed);
|
|
111
|
+
const dismissHint = useCallback(() => {
|
|
112
|
+
try {
|
|
113
|
+
localStorage.setItem(SETUP_HINT_DISMISS_KEY, "1");
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
/* private mode: the hint returns next load */
|
|
117
|
+
}
|
|
118
|
+
setHintDismissed(true);
|
|
119
|
+
}, []);
|
|
67
120
|
const [killing, setKilling] = useState(false);
|
|
68
121
|
// Arm/confirm for the destructive kill button: the FIRST click only arms a "sure?" state
|
|
69
122
|
// (auto-disarms after a few seconds so a stray click never leaves a live trap); the SECOND
|
|
@@ -75,10 +128,11 @@ export function Header({ screenOpen, onScreenToggle }) {
|
|
|
75
128
|
useEffect(() => () => { if (killArmTimer.current)
|
|
76
129
|
clearTimeout(killArmTimer.current); }, []);
|
|
77
130
|
const [theme, setTheme] = useState(readTheme);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
131
|
+
// Press state lives in the store's `enabling` latch (reconnect() refuses overlap itself),
|
|
132
|
+
// not in component state: the same flight must disable the button whether a press or the
|
|
133
|
+
// auto-re-arm started it.
|
|
134
|
+
const reconnect = useCallback(() => {
|
|
135
|
+
void store.reconnect();
|
|
82
136
|
}, []);
|
|
83
137
|
const kill = useCallback(async () => {
|
|
84
138
|
if (!killArmed) {
|
|
@@ -118,20 +172,134 @@ export function Header({ screenOpen, onScreenToggle }) {
|
|
|
118
172
|
return html `<h1>SLACK RADAR DASHBOARD <span class="conn waiting">● dashboard stopped</span></h1>`;
|
|
119
173
|
}
|
|
120
174
|
const connected = conn.state === "connected";
|
|
175
|
+
// The no-radar-session wording is split in two so the controls between them hold still: the
|
|
176
|
+
// conn span keeps the fixed diagnosis ("● no radar session on the device") for the whole
|
|
177
|
+
// outage, and the part that changes with what the automation is doing renders in its own
|
|
178
|
+
// span AFTER the Reconnect button and the automation chip. A relabel of that tail at an
|
|
179
|
+
// attempt boundary therefore cannot move the button or the chip under a cursor reaching for
|
|
180
|
+
// them. The head does change at the outage's two ENDS (the diagnosis replacing the generic
|
|
181
|
+
// waiting message; the armed reply's interim message replacing the diagnosis), and the
|
|
182
|
+
// profile label can change during one; accepted, since neither is an attempt boundary.
|
|
183
|
+
//
|
|
184
|
+
// The tail is a short sentence of its own (capitalised, and closed with a period when a
|
|
185
|
+
// reason follows it): at 1280px and below with a typical profile label it already wraps to
|
|
186
|
+
// its own line, where a lowercase fragment read as an unrelated second status. The tail and
|
|
187
|
+
// the reason spans share one status row, rendered LAST in the header so it takes the line
|
|
188
|
+
// below whatever the controls occupy and can never push them down (they may still wrap for
|
|
189
|
+
// width reasons of their own), one text line tall (the reason is ellipsized, full text on
|
|
190
|
+
// hover) and present whenever the Reconnect button is — so a reason mounting or unmounting at an
|
|
191
|
+
// attempt boundary, or at a manual press in an undiagnosed outage, changes what the row says,
|
|
192
|
+
// not how tall the header is (a height change reflows everything below it).
|
|
193
|
+
//
|
|
194
|
+
// The tail's precedence, each rung earning its rank: an unresolved device PICK outranks
|
|
195
|
+
// everything (the policy refuses to act until the human picks, so promising a retry would be
|
|
196
|
+
// false); a flight IN PROGRESS outranks the give-up wording (a manual press after give-up
|
|
197
|
+
// must not render "press Reconnect" beside its own disabled, already-pressed button; the
|
|
198
|
+
// manual flight renders no tail at all, since the button already reads "enabling…"); a
|
|
199
|
+
// BLOCKED process says the press is the human's; the human's own persisted STOP outranks an
|
|
200
|
+
// unanswered consent question (the store refuses on suppression whatever the answer); an
|
|
201
|
+
// UNANSWERED question says so rather than issuing an instruction the reply may withdraw.
|
|
202
|
+
// An imperative yields only to a reason span that itself instructs (see reasonInstructs): a
|
|
203
|
+
// reason that merely explains the failure leaves the tail's ", press Reconnect" in place, so
|
|
204
|
+
// the row always carries exactly one instruction.
|
|
205
|
+
const inOutage = !connected && sessionEnded;
|
|
206
|
+
const connLabel = connected
|
|
207
|
+
? "● live"
|
|
208
|
+
: sessionEnded
|
|
209
|
+
? needsPick
|
|
210
|
+
? "● multiple devices attached, pick one"
|
|
211
|
+
: "● no radar session on the device"
|
|
212
|
+
: "● " + (conn.msg || "reconnecting…");
|
|
213
|
+
// Whether the reason about to render beside the tail tells the user to do something. Read off
|
|
214
|
+
// the reply's own flag (set where each wording is written) rather than judged from the prose:
|
|
215
|
+
// some reasons carry adb's stderr verbatim, which no verb list classifies, and a reworded
|
|
216
|
+
// message would silently drift a regex. The pick error stands in for the reason when no
|
|
217
|
+
// reconnect reason is on screen.
|
|
218
|
+
const reasonInstructs = enableError ? enableInstructs : visiblePickError ? pickInstructs : false;
|
|
219
|
+
const press = reasonInstructs ? "" : ", press Reconnect";
|
|
220
|
+
// "gave up after N tries" names real attempts only: a refusal the server will repeat for every
|
|
221
|
+
// unattended retry ends the outage's automation at the attempt that receives it (usually the
|
|
222
|
+
// first), and that reads "gave up" with no count, since the number of attempts is not what
|
|
223
|
+
// ended it; the reason span beside it says why.
|
|
224
|
+
// A count reached through drops (the session kept dying right after coming back) names what
|
|
225
|
+
// happened instead of "tries" the tab did not all make.
|
|
226
|
+
const gaveUp = terminal
|
|
227
|
+
? "Auto re-enable gave up"
|
|
228
|
+
: flapped
|
|
229
|
+
? "Auto re-enable gave up, the session keeps dying soon after coming back"
|
|
230
|
+
: "Auto re-enable gave up after " + AUTO_REARM_MAX_FAILS + " tries";
|
|
231
|
+
const tailText = !inOutage || needsPick
|
|
232
|
+
? null
|
|
233
|
+
: enabling || autoRearming
|
|
234
|
+
? autoRearming
|
|
235
|
+
? "Re-enabling automatically…"
|
|
236
|
+
: null
|
|
237
|
+
: selfArmBlocked === true
|
|
238
|
+
? reasonInstructs ? "Auto re-enable is unavailable on this tab" : "Press Reconnect"
|
|
239
|
+
: suppressed
|
|
240
|
+
? "Auto re-enable is off" + press
|
|
241
|
+
: selfArmBlocked === null
|
|
242
|
+
? "Checking whether this tab may re-enable…"
|
|
243
|
+
: exhausted
|
|
244
|
+
? gaveUp + press
|
|
245
|
+
: "Will retry automatically";
|
|
246
|
+
const followedByReason = !!(enableError || visiblePickError);
|
|
247
|
+
const recoveryTail = tailText && followedByReason && !/[.…]$/.test(tailText) ? tailText + "." : tailText;
|
|
248
|
+
// Why this tab does not recover on its own. Only where that is KNOWN: the server folds both
|
|
249
|
+
// reasons into one boolean, so a blocked tab names the pair; an unanswered tab says what it is
|
|
250
|
+
// waiting for, since the reason is not yet known and for a human launch would be false.
|
|
251
|
+
const tailTitle = !inOutage || enabling || autoRearming
|
|
252
|
+
? undefined
|
|
253
|
+
: selfArmBlocked === true
|
|
254
|
+
? "This dashboard process does not arm the device on its own (it was started by an agent, or SLACK_RADAR_NO_ARM is set). Reconnect works as usual."
|
|
255
|
+
: suppressed
|
|
256
|
+
? mayAutoRearm
|
|
257
|
+
? undefined
|
|
258
|
+
: "Turned off for dashboards at this address. The resume control appears once a /health reply says this tab may re-enable on its own (this dashboard version may not report it)."
|
|
259
|
+
: selfArmBlocked === null
|
|
260
|
+
? "No /health reply has said yet whether this tab may re-enable on its own (this dashboard version may not report it). Reconnect works as usual."
|
|
261
|
+
: exhausted
|
|
262
|
+
? AUTO_REARM_MAX_FAILS + " failed attempts, or a session that died within a minute of each re-enable. Press Reconnect; automatic re-enable starts again once the session stays up for a minute."
|
|
263
|
+
: "Once right away (or on the minute, if the session just came back and died again), then about once a minute, up to " + AUTO_REARM_MAX_FAILS + " tries. A session that dies again within a minute of coming back counts as a failed try.";
|
|
264
|
+
// One status row: the tail, then the reason and pick-error spans. Present whenever the Reconnect
|
|
265
|
+
// button is (any disconnected state, diagnosed or not), plus whenever a pick error shows, so its
|
|
266
|
+
// members can come and go — including across a manual press — without changing the header's
|
|
267
|
+
// height.
|
|
268
|
+
const statusRow = !connected || !!visiblePickError;
|
|
121
269
|
return html `
|
|
122
270
|
<h1>
|
|
123
271
|
SLACK RADAR DASHBOARD
|
|
124
|
-
<span class=${"conn " + conn.state}>${
|
|
272
|
+
<span class=${"conn " + conn.state}>${connLabel}</span>
|
|
125
273
|
<span class="profilewrap" title="the device profile Radar is connected to (first app to launch wins the socket)">profile: <b>${profile}</b></span>
|
|
126
274
|
<${DeviceChip} />
|
|
127
|
-
${!connected ? html `<button class="reconnect" disabled=${
|
|
128
|
-
${
|
|
275
|
+
${!connected ? html `<button class="reconnect" disabled=${enabling} onClick=${reconnect}>${enabling ? "⟳ enabling…" : "⟳ Reconnect Radar"}</button>` : null}
|
|
276
|
+
${suppressed
|
|
277
|
+
// The choice PERSISTS across reloads, so its way back must not depend on being
|
|
278
|
+
// mid-outage: a user who opted out yesterday sees the state and can undo it any time.
|
|
279
|
+
// Hidden where the process cannot self-arm anyway (agent-spawned, NO_ARM set, or not
|
|
280
|
+
// yet answered).
|
|
281
|
+
? mayAutoRearm
|
|
282
|
+
? html `<button class="themebtn" onClick=${() => store.setAutoRearmSuppressed(false)} title="Automatic re-enable is off for dashboards at this address, and remembered until you turn it back on. Click to allow it again.">↻ resume auto re-enable</button>`
|
|
283
|
+
: null
|
|
284
|
+
// Offered while the automation is armed for this outage — including after its budget is
|
|
285
|
+
// spent (it refills on the next recovery, so there is still something to switch off) and
|
|
286
|
+
// including MID-FLIGHT: pressing cannot cancel an /enable already sent, but it stops
|
|
287
|
+
// every future attempt, and for a user whose re-arms always SUCCEED the flight is the
|
|
288
|
+
// only window this control ever renders in (a successful attempt retires the outage
|
|
289
|
+
// before an idle frame exists). Action-voiced like the theme button in the same row
|
|
290
|
+
// (the label names what a click does), which is why the give-up tail says "gave up"
|
|
291
|
+
// and never "stopped": "stopped" beside "stop" read as a contradiction.
|
|
292
|
+
: inOutage && !needsPick && mayAutoRearm
|
|
293
|
+
? html `<button class="themebtn" onClick=${() => store.setAutoRearmSuppressed(true)} title="Stop dashboards at this address from re-enabling Radar automatically, in this outage and later ones. It cannot cancel an attempt already in flight. Remembered until you turn it back on, and other tabs open on this address pick it up. It does not turn Radar off, and an MCP session can still arm the device.">✋ stop auto re-enable</button>`
|
|
294
|
+
: null}
|
|
129
295
|
<button class="themebtn" onClick=${toggleTheme} title="Toggle light / dark theme">${theme === "light" ? "🌙 Dark" : "☀ Light"}</button>
|
|
130
296
|
<button class=${"screenbtn" + (screenOpen ? " on" : "")} onClick=${onScreenToggle} title="Mirror the live device screen">▣ Screen</button>
|
|
131
297
|
<button class=${"themebtn killbtn" + (killArmed ? " armed" : "")} disabled=${killing} onClick=${kill} title=${killArmed ? "Click again to confirm" : "Stop the dashboard server"}>${killing ? "⏻ stopping…" : killArmed ? "⏻ Confirm stop?" : "⏻ Stop dashboard"}</button>
|
|
132
298
|
${version ? html `<span class="version" title="Version of the dashboard process. It can differ from your Claude Code MCP session if a dashboard from an earlier launch still holds the port; restart the dashboard to match.">v${version}</span>` : null}
|
|
133
299
|
${selfHeal?.outcome === "updated" ? html `<span class="version" title="Radar self-healed to a newer version on this launch">↑ updated to v${selfHeal.toVersion}</span>` : null}
|
|
134
300
|
${selfHeal?.outcome === "error" ? html `<span class="conn waiting" title=${"The dock launcher's self-heal check failed: " + (selfHeal.error || "unknown error") + ". Log: ~/Library/Logs/slack-radar-dashboard.log"}>⚠ self-heal check failed</span>` : null}
|
|
301
|
+
${setupHint && !setupHint.mcpSeen && !hintDismissed ? html `<span class="setuphint" title="Radar has not seen an agent client start its MCP server on this machine. The dashboard works without one.">No agent client has connected yet. <a href="https://slack-github.com/slack/slack-radar-mcp#installation" target="_blank" rel="noreferrer">Set up agent tools</a>.<button class="hintdismiss" onClick=${dismissHint} aria-label="Hide the agent tools hint permanently for dashboards at this address" title="Hide this hint permanently for dashboards at this address">✕</button></span>` : null}
|
|
302
|
+
${statusRow ? html `<span class="statusrow">${recoveryTail ? html `<span class=${"conn " + conn.state} title=${tailTitle}>${recoveryTail}</span>` : null}${enableError ? html `<span class="conn waiting reason" title=${enableError}>${enableError}</span>` : null}${visiblePickError ? html `<span class="conn waiting reason" title=${visiblePickError}>${visiblePickError}</span>` : null}</span>` : null}
|
|
135
303
|
</h1>
|
|
136
304
|
`;
|
|
137
305
|
}
|
|
@@ -327,7 +495,7 @@ function App() {
|
|
|
327
495
|
<${Header} screenOpen=${screenOpen} onScreenToggle=${() => setScreenOpen((o) => !o)} />
|
|
328
496
|
<${ModeBar} />
|
|
329
497
|
${view}
|
|
330
|
-
<${ScreenOverlay} open=${screenOpen} onClose=${() => setScreenOpen(false)} />
|
|
498
|
+
<${ScreenOverlay} open=${screenOpen} onClose=${() => setScreenOpen(false)} capsSource=${store} />
|
|
331
499
|
`;
|
|
332
500
|
}
|
|
333
501
|
// Both the poll loops and the render are gated on the mount point existing. The render already was;
|
|
@@ -7,7 +7,7 @@ import { html } from "./html.js";
|
|
|
7
7
|
import { useState, useEffect, useRef, useCallback, useMemo } from "preact/hooks";
|
|
8
8
|
import { store, shortUrl, shortPkg, MODES, modeServed, fmtNum } from "./store.js";
|
|
9
9
|
import { STREAM_KINDS } from "./registry.js";
|
|
10
|
-
import { parseFilter, tokenize, isCompleteTerm } from "./filter.js";
|
|
10
|
+
import { parseFilter, tokenize, isCompleteTerm, isQuote } from "./filter.js";
|
|
11
11
|
const ROW_H = 24;
|
|
12
12
|
const OVERSCAN = 10;
|
|
13
13
|
// Feed UI prefs PERSIST across tab switches (the Feed unmounts/remounts per source). The text
|
|
@@ -59,7 +59,7 @@ function pillClasses(raw, invalidSet, sourceIsAll) {
|
|
|
59
59
|
classes.push("fpill-neg");
|
|
60
60
|
if (body.startsWith("/"))
|
|
61
61
|
classes.push("fpill-re");
|
|
62
|
-
else if (body
|
|
62
|
+
else if (isQuote(body[0]))
|
|
63
63
|
classes.push("fpill-quote");
|
|
64
64
|
else if (sourceIsAll && KIND_TOKENS.has(body.toLowerCase()))
|
|
65
65
|
classes.push("fpill-kind", "fpill-kind-" + body.toLowerCase());
|
|
@@ -67,11 +67,16 @@ function pillClasses(raw, invalidSet, sourceIsAll) {
|
|
|
67
67
|
}
|
|
68
68
|
// The label shown on a pill. Negation renders as a leading "−" glyph outside the body so the
|
|
69
69
|
// body reads the same as it does in the filter string. Regex pills keep their slashes (that is
|
|
70
|
-
// how they were typed)
|
|
70
|
+
// how they were typed). A quoted phrase drops its straight quotes from the body and gets curly
|
|
71
|
+
// marks rendered OUTSIDE the ellipsizing body instead: a long pasted line used to truncate its
|
|
72
|
+
// closing quote away and read as an unbalanced `"Fetched 0 AI app profiles for tea…`. The raw
|
|
73
|
+
// term (quotes included) still rides the title and pops back for editing unchanged.
|
|
71
74
|
function pillLabel(raw) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
const neg = raw.startsWith("-");
|
|
76
|
+
const body = neg ? raw.slice(1) : raw;
|
|
77
|
+
if (body.length >= 2 && isQuote(body[0]) && isQuote(body[body.length - 1]))
|
|
78
|
+
return { neg, body: body.slice(1, -1), quoted: true };
|
|
79
|
+
return { neg, body, quoted: false };
|
|
75
80
|
}
|
|
76
81
|
// Platform-aware jump-pill labels. macOS has no Home/End, so show the chord that works there.
|
|
77
82
|
const IS_MAC = typeof navigator !== "undefined" && /Mac|iP(hone|ad|od)/.test(navigator.platform || navigator.userAgent || "");
|
|
@@ -715,6 +720,20 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
715
720
|
// state: it changes nothing visually until the next commit. Cleared when the draft is
|
|
716
721
|
// erased (erasing the popped text means "remove that term", so a new term goes to the tail).
|
|
717
722
|
const editSlotRef = useRef(null);
|
|
723
|
+
// Stable identity on purpose: an inline arrow would be a new ref every render, and Preact detaches
|
|
724
|
+
// and reattaches a changed ref, replaying the three setAttribute calls per frame while tailing.
|
|
725
|
+
// Set as ATTRIBUTES, not props: spellcheck and (in WebKit) autocorrect are boolean IDL
|
|
726
|
+
// properties, and Preact assigns a prop that exists on the element as a property, so
|
|
727
|
+
// spellcheck="false" would coerce to true. The text substitution these turn off is what rewrote
|
|
728
|
+
// a typed quote into a curly one in the dock app's web view.
|
|
729
|
+
const attachFilterInput = useCallback((el) => {
|
|
730
|
+
filterRef.current = el;
|
|
731
|
+
if (el) {
|
|
732
|
+
el.setAttribute("spellcheck", "false");
|
|
733
|
+
el.setAttribute("autocorrect", "off");
|
|
734
|
+
el.setAttribute("autocapitalize", "off");
|
|
735
|
+
}
|
|
736
|
+
}, []);
|
|
718
737
|
const commitDraft = (rawDraft) => {
|
|
719
738
|
// Only commit a complete non-empty term; a bare "-" or an open /… / "… span stays as draft.
|
|
720
739
|
if (!isCompleteTerm(rawDraft))
|
|
@@ -766,7 +785,7 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
766
785
|
inp.focus();
|
|
767
786
|
}}>
|
|
768
787
|
${pills.map((raw, idx) => {
|
|
769
|
-
const { neg, body } = pillLabel(raw);
|
|
788
|
+
const { neg, body, quoted } = pillLabel(raw);
|
|
770
789
|
const cls = pillClasses(raw, invalidSet, sourceIsAll);
|
|
771
790
|
// The title always carries the raw term: long pills ellipsize at max-width, and
|
|
772
791
|
// hover is the only way to audit a truncated term without mutating the query.
|
|
@@ -802,7 +821,7 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
802
821
|
e.preventDefault();
|
|
803
822
|
popPillForEdit(idx);
|
|
804
823
|
}}>
|
|
805
|
-
${neg ? html `<span class="fpill-sign">−</span>` : null}<span class="fpill-body">${body}</span
|
|
824
|
+
${neg ? html `<span class="fpill-sign">−</span>` : null}${quoted ? html `<span class="fpill-q">“</span>` : null}<span class="fpill-body">${body}</span>${quoted ? html `<span class="fpill-q">”</span>` : null}<span class="fpill-x"
|
|
806
825
|
title="remove this term"
|
|
807
826
|
onMouseDown=${(e) => {
|
|
808
827
|
e.preventDefault();
|
|
@@ -812,15 +831,45 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
812
831
|
</span>
|
|
813
832
|
`;
|
|
814
833
|
})}
|
|
815
|
-
<input class=${"ffilter" + (draftInvalid ? " finvalid" : "")}
|
|
816
|
-
placeholder=${pills.length ? "" : "filter rows… -exclude /regex/
|
|
834
|
+
<input class=${"ffilter" + (draftInvalid ? " finvalid" : "")}
|
|
835
|
+
placeholder=${pills.length ? "\"phrase\" -exclude /regex/" : "filter rows… \"phrase\" -exclude /regex/"} autocomplete="off" value=${draft}
|
|
836
|
+
aria-label="filter rows"
|
|
817
837
|
title=${draftInvalid
|
|
818
838
|
? "invalid regex ignored: " + draft
|
|
819
839
|
: draftHint
|
|
820
840
|
? draftHint
|
|
821
|
-
: '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)'}
|
|
841
|
+
: 'space-separated terms AND together · -term excludes · /pattern/ is regex with optional short flags (i/m/s/g, 1-2 letters, so /api/im reads as flags) · unterminated /…/ or flag typos like /error/x become literal regex · "quote" to match any /…/ literally, curly quotes count too · pasting text with spaces into an empty box quotes it as one phrase · on Live, a kind name (log, clog, trace, rtm, network) matches by type or substring, and its -kind form excludes by type only (quote it, -"log", to exclude by text instead)'}
|
|
842
|
+
ref=${attachFilterInput}
|
|
822
843
|
onFocus=${() => { if (sel.size)
|
|
823
844
|
clearSel(); }}
|
|
845
|
+
onPaste=${(e) => {
|
|
846
|
+
// A pasted line with spaces is one thing the user is looking for, not a list of
|
|
847
|
+
// terms: without this, the next space chopped a pasted log message into a pill per
|
|
848
|
+
// word, and common words like "0" or "app" matched half the feed. So a multi-word
|
|
849
|
+
// paste that REPLACES the draft (empty, or fully selected) commits as one quoted
|
|
850
|
+
// phrase. Pastes that fall through and land as typed: a single word; anything that
|
|
851
|
+
// spans lines (a single-line input cannot hold or round-trip the newline, and no row
|
|
852
|
+
// text has one); text carrying its own double quote, straight or curly (it would end
|
|
853
|
+
// the span early); and anything that STARTS in the box's own syntax (a quote, a
|
|
854
|
+
// regex, or an exclude). Only the first token is judged: log lines routinely carry
|
|
855
|
+
// "-1" or "/data/..." mid-line, and judging every token turned those back into a
|
|
856
|
+
// pill per word, which is the exact failure this handler exists to stop. A copied
|
|
857
|
+
// filter expression that starts with a bare word is quoted; the pill pops back for
|
|
858
|
+
// editing.
|
|
859
|
+
const el = e.currentTarget;
|
|
860
|
+
const text = (e.clipboardData?.getData("text") ?? "").trim();
|
|
861
|
+
const replacing = el.value === "" || (el.selectionStart === 0 && el.selectionEnd === el.value.length);
|
|
862
|
+
const tokens = text.split(/\s+/);
|
|
863
|
+
// A leading quote is already covered by the any-quote check below (one alphabet,
|
|
864
|
+
// QUOTE_CHARS, via isQuote); a leading regex or exclude is what this reads.
|
|
865
|
+
const syntax = /^\//.test(tokens[0]) || /^-\S/.test(tokens[0]);
|
|
866
|
+
if (!replacing || tokens.length < 2 || /[\r\n]/.test(text) || [...text].some(isQuote) || syntax)
|
|
867
|
+
return;
|
|
868
|
+
// Same shape as the space path: only a commit that happened consumes the keystroke,
|
|
869
|
+
// so a refused commit can never eat the clipboard.
|
|
870
|
+
if (commitDraft('"' + text + '"'))
|
|
871
|
+
e.preventDefault();
|
|
872
|
+
}}
|
|
824
873
|
onKeyDown=${(e) => {
|
|
825
874
|
const el = e.currentTarget;
|
|
826
875
|
if (e.key === " ") {
|
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
// on an ambiguous /…/tail is reported in `hints` so the reading is visible,
|
|
20
20
|
// never silent.
|
|
21
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 /.
|
|
22
|
+
// Quoting is also the escape hatch for a literal leading - or /. Curly quotes
|
|
23
|
+
// (“ ”) count as quotes too: macOS smart-quote substitution rewrites a typed "
|
|
24
|
+
// inside the dock app's WKWebView, and a phrase that then split into tokens was
|
|
25
|
+
// reported as "quoting does not work".
|
|
23
26
|
//
|
|
24
27
|
// An invalid or incomplete regex (e.g. "/foo(" mid-typing) never throws and never filters:
|
|
25
28
|
// that term goes INERT (matches everything) and parse() reports it in `invalid` so the box can
|
|
@@ -33,6 +36,10 @@ const MATCH_ALL = Object.freeze({
|
|
|
33
36
|
hints: Object.freeze([]),
|
|
34
37
|
empty: true,
|
|
35
38
|
});
|
|
39
|
+
// Every character that opens or closes a quoted span. Straight and curly are interchangeable
|
|
40
|
+
// on both ends, so a span typed as “a b" (one side rewritten by the OS) still closes.
|
|
41
|
+
export const QUOTE_CHARS = new Set(['"', "\u201c", "\u201d"]);
|
|
42
|
+
export const isQuote = (c) => c !== undefined && QUOTE_CHARS.has(c);
|
|
36
43
|
// Split the query into raw term tokens: whitespace-separated, but /…/ and "…" spans (with an
|
|
37
44
|
// optional leading -) stay one token even when they contain spaces. An unterminated span runs
|
|
38
45
|
// to the end of the query.
|
|
@@ -49,9 +56,10 @@ export function tokenize(query) {
|
|
|
49
56
|
if (query[i] === "-")
|
|
50
57
|
i++;
|
|
51
58
|
const open = query[i];
|
|
52
|
-
if (open === "/" || open
|
|
59
|
+
if (open === "/" || isQuote(open)) {
|
|
53
60
|
i++;
|
|
54
|
-
|
|
61
|
+
const closes = (c) => (open === "/" ? c === "/" : isQuote(c));
|
|
62
|
+
while (i < n && !closes(query[i]))
|
|
55
63
|
i++;
|
|
56
64
|
if (i < n)
|
|
57
65
|
i++; // consume the closer
|
|
@@ -68,9 +76,10 @@ export function tokenize(query) {
|
|
|
68
76
|
return tokens;
|
|
69
77
|
}
|
|
70
78
|
// 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:
|
|
72
|
-
// the first / or
|
|
73
|
-
// opener are always complete (a bare word, or /foo/tail once the
|
|
79
|
+
// span is CLOSED around at least one character. Reuses the tokenizer's span logic (same rules:
|
|
80
|
+
// an optional leading -, then the first / or quote opens a span that a closer of its own kind
|
|
81
|
+
// ends). Terms with no span opener are always complete (a bare word, or /foo/tail once the
|
|
82
|
+
// closer is past).
|
|
74
83
|
export function isCompleteTerm(raw) {
|
|
75
84
|
if (!raw)
|
|
76
85
|
return false;
|
|
@@ -80,12 +89,16 @@ export function isCompleteTerm(raw) {
|
|
|
80
89
|
if (i === raw.length)
|
|
81
90
|
return false; // a bare "-" while typing is not committable
|
|
82
91
|
const open = raw[i];
|
|
83
|
-
if (open !== "/" && open
|
|
92
|
+
if (open !== "/" && !isQuote(open))
|
|
84
93
|
return true; // no span, so complete
|
|
85
94
|
i++;
|
|
86
|
-
|
|
95
|
+
const closes = (c) => (open === "/" ? c === "/" : isQuote(c));
|
|
96
|
+
const contentStart = i;
|
|
97
|
+
while (i < raw.length && !closes(raw[i]))
|
|
87
98
|
i++;
|
|
88
|
-
|
|
99
|
+
// true only when the closer was found AND the span holds something: "" or “” would commit as a
|
|
100
|
+
// pill that filters nothing and never turns amber, so it stays in the draft instead.
|
|
101
|
+
return i < raw.length && i > contentStart;
|
|
89
102
|
}
|
|
90
103
|
// A tail reads as regex flags only when it is the short flag string fingers actually type:
|
|
91
104
|
// 1-2 letters from i/m/s/g with no repeats. Longer or letter-repeating tails (img, ims, sms)
|
|
@@ -146,8 +159,8 @@ function compileTerm(raw, invalid, hints, kinds) {
|
|
|
146
159
|
return null; // invalid regex: inert, reported
|
|
147
160
|
}
|
|
148
161
|
}
|
|
149
|
-
if (body[0]
|
|
150
|
-
const closed = body.length >= 2 && body[body.length - 1]
|
|
162
|
+
if (isQuote(body[0])) {
|
|
163
|
+
const closed = body.length >= 2 && isQuote(body[body.length - 1]);
|
|
151
164
|
const phrase = (closed ? body.slice(1, -1) : body.slice(1)).toLowerCase();
|
|
152
165
|
if (!phrase)
|
|
153
166
|
return null;
|