@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.
- package/README.md +12 -2
- package/dist/mcp/api-paths.js +2 -0
- package/dist/mcp/flags-tools.d.ts +71 -0
- package/dist/mcp/flags-tools.js +158 -0
- package/dist/mcp/index.js +103 -5
- package/dist/mcp/prefs-tools.d.ts +15 -0
- package/dist/mcp/prefs-tools.js +204 -0
- package/dist/mcp/session-enable.d.ts +2 -1
- package/dist/mcp/session-enable.js +29 -2
- package/dist/mcp/snapshot.js +6 -1
- package/dist/mcp/sources-gate.d.ts +23 -0
- package/dist/mcp/sources-gate.js +63 -0
- package/dist/mcp/tools.js +102 -2
- package/dist/shared/android.d.ts +33 -1
- package/dist/shared/android.js +203 -6
- package/dist/shared/constants.d.ts +8 -0
- package/dist/shared/constants.js +13 -1
- package/dist/shared/db.d.ts +21 -3
- package/dist/shared/db.js +89 -23
- package/dist/shared/feature-flags.d.ts +6 -0
- package/dist/shared/feature-flags.js +17 -0
- package/dist/shared/prefs.d.ts +78 -0
- package/dist/shared/prefs.js +416 -0
- package/dist/shared/transport.d.ts +68 -0
- package/dist/web/log-session.d.ts +13 -0
- package/dist/web/log-session.js +16 -0
- package/dist/web/public/index.html +129 -3
- package/dist/web/public/next/app.js +82 -4
- package/dist/web/public/next/feed.js +270 -14
- package/dist/web/public/next/filter.js +200 -0
- package/dist/web/public/next/flags.js +179 -0
- package/dist/web/public/next/prefs.js +399 -0
- package/dist/web/public/next/registry.js +16 -6
- package/dist/web/public/next/store.js +250 -11
- package/dist/web/server.js +267 -7
- package/dist/web/spec.d.ts +7 -7
- package/dist/web/spec.js +15 -9
- package/package.json +1 -1
package/dist/web/server.js
CHANGED
|
@@ -7,7 +7,9 @@ import { fileURLToPath } from "url";
|
|
|
7
7
|
import { AndroidTransport, resolveAdbPath } from "../shared/android.js";
|
|
8
8
|
import { planReconnect } from "../shared/stream.js";
|
|
9
9
|
import { RADAR_HOST, RADAR_PORT, RADAR_VERSION, WEB_PORT_DEFAULT } from "../shared/constants.js";
|
|
10
|
-
import {
|
|
10
|
+
import { friendlyFeatureFlagError } from "../shared/feature-flags.js";
|
|
11
|
+
import { cleanupPulledDatabases, initializeDatabasePath, listDatabases, pullDatabase, pulledSize, queryDatabase, resetDbState, availableUsers, } from "../shared/db.js";
|
|
12
|
+
import { listPrefsFiles, readPrefsFile, parsePrefsXml, searchPrefs, } from "../shared/prefs.js";
|
|
11
13
|
import { LogSession } from "./log-session.js";
|
|
12
14
|
import { BLANK_SPEC, coerceSpec, validateSpec } from "./spec.js";
|
|
13
15
|
import { screenCapabilities, refreshScreenCapabilities, grantScreenConsent, hasScreenConsent, detectDisplay, displayNote, captureScreenshot, startLive, addViewer, removeViewer, reapLiveIfIdle, primeIfNeeded, startRecording, stopRecording, recordingPath, resetScreenState, registerScreenCleanup, resolveFfmpeg, ffmpegInstallHint, SCREEN_BOUNDARY, } from "../shared/screen.js";
|
|
@@ -46,6 +48,14 @@ export function shouldDropLogFrame(replay, writableLength, cap = MAX_SSE_WRITABL
|
|
|
46
48
|
const SPEC_DIR = path.join(os.homedir(), ".slack-radar");
|
|
47
49
|
const SPEC_PATH = path.join(SPEC_DIR, `web-spec-${WEB_PORT}.json`);
|
|
48
50
|
const transport = new AndroidTransport();
|
|
51
|
+
// Reassert the shared adb forward before every HTTP-based device read. Mirrors
|
|
52
|
+
// mcp/index.ts's forwardForRead(): this process's own portForwarded cache cannot see a
|
|
53
|
+
// repoint made by a SEPARATE process (the MCP server) sharing the same host-global
|
|
54
|
+
// forward port -- the split-brain flows both ways. Platforms without a shared
|
|
55
|
+
// host-level forward may omit reassertForward, so this falls back to ensureForward.
|
|
56
|
+
function forwardForRead() {
|
|
57
|
+
return transport.reassertForward?.() ?? transport.ensureForward();
|
|
58
|
+
}
|
|
49
59
|
// One session-long logcat capture shared across every dashboard stream
|
|
50
60
|
// connection. The device cannot replay logcat history to us, so the dashboard
|
|
51
61
|
// keeps its own bounded session ring here and replays it to each newly opened
|
|
@@ -168,8 +178,9 @@ export function createServer() {
|
|
|
168
178
|
handleHealth(res);
|
|
169
179
|
return;
|
|
170
180
|
}
|
|
171
|
-
if (
|
|
172
|
-
|
|
181
|
+
if (urlPath === "/enable" && req.method === "POST") {
|
|
182
|
+
const serial = new URL(url, `http://localhost:${WEB_PORT}`).searchParams.get("device_serial");
|
|
183
|
+
handleEnable(res, serial);
|
|
173
184
|
return;
|
|
174
185
|
}
|
|
175
186
|
if (url === "/stream" && req.method === "GET") {
|
|
@@ -196,6 +207,22 @@ export function createServer() {
|
|
|
196
207
|
handleDbQuery(req, res);
|
|
197
208
|
return;
|
|
198
209
|
}
|
|
210
|
+
if (url.startsWith("/flags") && req.method === "GET") {
|
|
211
|
+
handleFlags(req, res);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (url.split("?")[0] === "/prefs" && req.method === "GET") {
|
|
215
|
+
handlePrefsList(req, res);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (url.startsWith("/prefsread") && req.method === "GET") {
|
|
219
|
+
handlePrefsRead(req, res);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (url.startsWith("/prefssearch") && req.method === "GET") {
|
|
223
|
+
handlePrefsSearch(req, res);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
199
226
|
if (url === "/_control/profiles" && req.method === "GET") {
|
|
200
227
|
listProfiles(res);
|
|
201
228
|
return;
|
|
@@ -206,6 +233,10 @@ export function createServer() {
|
|
|
206
233
|
activateRadar(res, userId);
|
|
207
234
|
return;
|
|
208
235
|
}
|
|
236
|
+
if (url === "/_control/devices" && req.method === "GET") {
|
|
237
|
+
listDevices(res);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
209
240
|
if (url.startsWith("/screen/")) {
|
|
210
241
|
handleScreen(req, res);
|
|
211
242
|
return;
|
|
@@ -365,6 +396,14 @@ async function handleSetSpec(req, res) {
|
|
|
365
396
|
* forward/proxy base as the rest of the server.
|
|
366
397
|
*/
|
|
367
398
|
function handleHealth(res) {
|
|
399
|
+
// Reassert before reading: see forwardForRead's doc comment. Without this, a foreign
|
|
400
|
+
// repoint of the shared port (the MCP process switching devices) makes /health probe
|
|
401
|
+
// the WRONG device while still labeling the reply with THIS process's own (correct)
|
|
402
|
+
// device_serial -- a misleading "connected" status for a device this process is not
|
|
403
|
+
// actually reading. reassertForward's cheap check-first path (adb forward --list) keeps
|
|
404
|
+
// the cost low on the 2s poll cadence; it only pays for a real rebuild when the shared
|
|
405
|
+
// port is actually pointed somewhere else.
|
|
406
|
+
forwardForRead();
|
|
368
407
|
// A probe can fire BOTH an "end" and an "error"/"timeout" (partial response then socket
|
|
369
408
|
// drop), so guard the response to exactly one write. Without this the second sendJson
|
|
370
409
|
// does a second writeHead -> ERR_HTTP_HEADERS_SENT -> uncaught -> the whole server dies.
|
|
@@ -373,15 +412,20 @@ function handleHealth(res) {
|
|
|
373
412
|
// profile owns the socket (the app that bound first), unlike the host-side activate
|
|
374
413
|
// guess in getActiveUserId() which can drift. The dashboard shows this so it never
|
|
375
414
|
// claims a profile you are not actually seeing.
|
|
376
|
-
const reply = (device, boundUserId, boundProfile) => {
|
|
415
|
+
const reply = (device, boundUserId, boundProfile, sources) => {
|
|
377
416
|
if (replied)
|
|
378
417
|
return;
|
|
379
418
|
replied = true;
|
|
419
|
+
const selected = transport.getSelectedDevice?.() ?? null;
|
|
380
420
|
sendJson(res, 200, {
|
|
381
421
|
device,
|
|
382
422
|
screen: screenCapabilities(),
|
|
383
423
|
boundUserId: boundUserId ?? null,
|
|
384
424
|
boundProfile: boundProfile ?? null,
|
|
425
|
+
device_serial: selected?.serial ?? null,
|
|
426
|
+
device_label: selected?.label ?? null,
|
|
427
|
+
// Capture sources the build declares on ping (seam builds only); null on older builds.
|
|
428
|
+
sources: sources ?? null,
|
|
385
429
|
});
|
|
386
430
|
};
|
|
387
431
|
const probe = http.request({
|
|
@@ -406,6 +450,7 @@ function handleHealth(res) {
|
|
|
406
450
|
const ok = up.statusCode === 200;
|
|
407
451
|
let uid = null;
|
|
408
452
|
let profile = null;
|
|
453
|
+
let sources = null;
|
|
409
454
|
// Only trust the body on a 200. A device 5xx-ing with a stale ping body must NOT
|
|
410
455
|
// surface a bound profile while device:false — that would let the dashboard show a
|
|
411
456
|
// confident profile label for an unhealthy device.
|
|
@@ -416,12 +461,14 @@ function handleHealth(res) {
|
|
|
416
461
|
uid = String(p.android_user_id);
|
|
417
462
|
if (typeof p.profile === "string")
|
|
418
463
|
profile = p.profile;
|
|
464
|
+
if (Array.isArray(p.sources))
|
|
465
|
+
sources = p.sources;
|
|
419
466
|
}
|
|
420
467
|
catch {
|
|
421
468
|
// non-JSON / partial body: device is up but we cannot name the profile
|
|
422
469
|
}
|
|
423
470
|
}
|
|
424
|
-
reply(ok, uid, profile);
|
|
471
|
+
reply(ok, uid, profile, sources);
|
|
425
472
|
});
|
|
426
473
|
up.on("error", () => reply(false));
|
|
427
474
|
});
|
|
@@ -438,13 +485,51 @@ function handleHealth(res) {
|
|
|
438
485
|
* user never has to drop to a terminal. Delegates entirely to AndroidTransport;
|
|
439
486
|
* no adb shelling here.
|
|
440
487
|
*/
|
|
441
|
-
function handleEnable(res) {
|
|
488
|
+
function handleEnable(res, deviceSerial) {
|
|
442
489
|
transport.resetState();
|
|
443
490
|
// A reconnect may be a different device / re-armed profile, so drop the cached DB user
|
|
444
491
|
// set + sqlite path; the next /dbs re-detects the profiles fresh.
|
|
445
492
|
resetDbState();
|
|
493
|
+
// Pin the target device BEFORE any adb call, including resetScreenState's pkill below --
|
|
494
|
+
// that call has no serial of its own and would otherwise target whatever `adb` defaults
|
|
495
|
+
// to (or fail ambiguously) on a multi-device host, running one adb call outside the
|
|
496
|
+
// "pin before any adb call" invariant every other call site in this handler honors. An
|
|
497
|
+
// ambiguous choice (multiple devices, no serial) or an unattached explicit serial fails
|
|
498
|
+
// here with the list, before forwarding OR the screen reset.
|
|
499
|
+
const selection = transport.selectDevice?.(deviceSerial ?? null);
|
|
500
|
+
if (selection && !selection.ok) {
|
|
501
|
+
sendJson(res, 409, {
|
|
502
|
+
enabled: false,
|
|
503
|
+
error: selection.error,
|
|
504
|
+
devices: selection.devices,
|
|
505
|
+
});
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
446
508
|
resetScreenState(); // re-detect the active display + clear any stale cast on re-arm
|
|
447
|
-
|
|
509
|
+
// On a switch to a different device, drop this device's pulled DB scratch AND the
|
|
510
|
+
// retained logcat capture -- both are per-device state resetDbState()/resetScreenState()
|
|
511
|
+
// above do not cover. logSession.restart() (not stop()) is deliberate here: stop() alone
|
|
512
|
+
// preserves the ring buffer for a transient same-device drop, but a real switch means
|
|
513
|
+
// every retained line belongs to the WRONG device, and the ring would replay device A's
|
|
514
|
+
// history into a freshly opened /stream on device B (mirrors the MCP side's onDeviceSwitch,
|
|
515
|
+
// which resets its own local buffers/spool/capture on the same switch signal). start() is
|
|
516
|
+
// idempotent, so a still-open Logs tab just keeps polling and picks the new child back up
|
|
517
|
+
// on its next /stream reconnect; nothing here needs to force-restart it eagerly.
|
|
518
|
+
if (selection && selection.ok && selection.switched) {
|
|
519
|
+
cleanupPulledDatabases();
|
|
520
|
+
logSession.restart();
|
|
521
|
+
}
|
|
522
|
+
// Reassert the forward is pointed at the selected device before reading. On a device
|
|
523
|
+
// switch or after a multi-process repoint (e.g., MCP server switched to a different
|
|
524
|
+
// device), the cached forward may be stale even though ensureForward() would not detect
|
|
525
|
+
// it on this process. Mirrors forwardForRead's split-brain handling: two processes
|
|
526
|
+
// sharing the same host-level forward must both reassert before assuming it is still
|
|
527
|
+
// good. Use forwardForRead's own result directly rather than also calling
|
|
528
|
+
// transport.ensureForward() again -- resetState() at the top of this handler already
|
|
529
|
+
// dropped the portForwarded cache, so a second unconditional ensureForward() call would
|
|
530
|
+
// only ever be a genuine repeat rebuild (on the rare reassert-failed path), never a
|
|
531
|
+
// no-op skip; forwardForRead already tried its best.
|
|
532
|
+
const forwarded = forwardForRead();
|
|
448
533
|
if (!forwarded) {
|
|
449
534
|
const reason = transport.getLastForwardError?.() ?? null;
|
|
450
535
|
sendJson(res, 200, {
|
|
@@ -518,6 +603,11 @@ export const DEVICE_SOURCES = {
|
|
|
518
603
|
* `[{type, event}]` frames mirroring the stream shape.
|
|
519
604
|
*/
|
|
520
605
|
function handleBackfill(req, res) {
|
|
606
|
+
// Reassert before reading: see forwardForRead's doc comment. A failed reassert still
|
|
607
|
+
// falls through to the request below rather than erroring out here -- the device-side
|
|
608
|
+
// request will surface its own connection failure, matching the pre-existing behavior
|
|
609
|
+
// when the forward was never set up at all.
|
|
610
|
+
forwardForRead();
|
|
521
611
|
const u = new URL(req.url ?? "", `http://localhost:${WEB_PORT}`);
|
|
522
612
|
const src = u.searchParams.get("source") ?? "network";
|
|
523
613
|
const limit = Math.min(500, Number(u.searchParams.get("limit")) || 200);
|
|
@@ -584,6 +674,8 @@ export function failDetailResponse(res, status) {
|
|
|
584
674
|
* to `/api/<kind>/<id>` so the inspector can fetch a clicked row's payload.
|
|
585
675
|
*/
|
|
586
676
|
function handleDetail(req, res) {
|
|
677
|
+
// Reassert before reading: see forwardForRead's doc comment.
|
|
678
|
+
forwardForRead();
|
|
587
679
|
const u = new URL(req.url ?? "", `http://localhost:${WEB_PORT}`);
|
|
588
680
|
const id = u.searchParams.get("id");
|
|
589
681
|
const kind = u.searchParams.get("kind") ?? "network";
|
|
@@ -613,6 +705,47 @@ function handleDetail(req, res) {
|
|
|
613
705
|
});
|
|
614
706
|
upstream.end();
|
|
615
707
|
}
|
|
708
|
+
// --- Feature flags (source: "flags") ---
|
|
709
|
+
//
|
|
710
|
+
// Proxy the dashboard's /flags to the device's feature-flag RadarPlugin at GET
|
|
711
|
+
// /api/feature_flags, forwarding the ?overridden= filter. The plugin returns the COMPLETE set
|
|
712
|
+
// (no paging), so nothing to inject. Response is buffered so a device error becomes a clean 200
|
|
713
|
+
// {error} the Feature Flags tab renders in-place rather than a half-streamed body.
|
|
714
|
+
//
|
|
715
|
+
// Device list shape: { feature_flags: [{ key, enabled, is_overridden }], total }. `enabled` is
|
|
716
|
+
// the effective value (override if set, else the server value). Live changes arrive separately
|
|
717
|
+
// as `feature_flag` frames on /api/stream (the on-device observer). Builds predating the plugin
|
|
718
|
+
// 404, surfaced as a friendly message client-side.
|
|
719
|
+
function handleFlags(req, res) {
|
|
720
|
+
const u = new URL(req.url ?? "", `http://localhost:${WEB_PORT}`);
|
|
721
|
+
const path = `/api/feature_flags${u.search}`;
|
|
722
|
+
const upstream = http.request({ host: RADAR_HOST, port: RADAR_PORT, path, method: "GET", timeout: 4000 }, (up) => {
|
|
723
|
+
let body = "";
|
|
724
|
+
up.on("data", (c) => (body += c));
|
|
725
|
+
up.on("end", () => {
|
|
726
|
+
try {
|
|
727
|
+
const j = JSON.parse(body);
|
|
728
|
+
if (!Array.isArray(j.feature_flags)) {
|
|
729
|
+
sendJson(res, 200, {
|
|
730
|
+
error: j.error ? friendlyFeatureFlagError(j.error) : "Unexpected response from device.",
|
|
731
|
+
feature_flags: [],
|
|
732
|
+
});
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
sendJson(res, 200, j);
|
|
736
|
+
}
|
|
737
|
+
catch {
|
|
738
|
+
sendJson(res, 200, { error: "Could not parse device response.", feature_flags: [] });
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
upstream.on("error", () => sendJson(res, 200, { error: "Device unreachable. Is Radar armed?", feature_flags: [] }));
|
|
743
|
+
upstream.on("timeout", () => {
|
|
744
|
+
upstream.destroy();
|
|
745
|
+
sendJson(res, 200, { error: "Device request timed out.", feature_flags: [] });
|
|
746
|
+
});
|
|
747
|
+
upstream.end();
|
|
748
|
+
}
|
|
616
749
|
// --- On-device SQLite browser (source: "db") ---
|
|
617
750
|
//
|
|
618
751
|
// These delegate to shared/db.ts (run-as + host sqlite3, read-only). Each computes its
|
|
@@ -692,6 +825,113 @@ async function handleDbQuery(req, res) {
|
|
|
692
825
|
}
|
|
693
826
|
sendJson(res, status, payload);
|
|
694
827
|
}
|
|
828
|
+
// --- On-device SharedPreferences browser (source: "prefs") ---
|
|
829
|
+
//
|
|
830
|
+
// These delegate to shared/prefs.ts (run-as + ADB, read-only; PR1, already tested). Mirrors
|
|
831
|
+
// handleDb* above: compute payload+status BEFORE writing headers, errors surface as 200
|
|
832
|
+
// {error} in-pane rather than a transport error. User resolution reuses dbUser (it only reads
|
|
833
|
+
// req/WEB_PORT/transport, nothing db-specific) rather than duplicating a prefsUser().
|
|
834
|
+
function handlePrefsList(req, res) {
|
|
835
|
+
const adbPath = resolveAdbPath();
|
|
836
|
+
if (!adbPath) {
|
|
837
|
+
sendJson(res, 200, { error: "adb not found. Ensure platform-tools is installed and on PATH.", files: [], available_users: [] });
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
try {
|
|
841
|
+
const user = dbUser(req);
|
|
842
|
+
const result = listPrefsFiles(adbPath, user);
|
|
843
|
+
if (!result) {
|
|
844
|
+
sendJson(res, 200, { error: "unable to list preferences files. Is the debug build installed and is a device connected?", files: [], available_users: availableUsers() });
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
sendJson(res, 200, {
|
|
848
|
+
user: result.user,
|
|
849
|
+
available_users: availableUsers(),
|
|
850
|
+
files: result.files,
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
catch (e) {
|
|
855
|
+
sendJson(res, 200, { error: e.message, files: [], available_users: [] });
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
async function handlePrefsRead(req, res) {
|
|
859
|
+
const u = new URL(req.url ?? "", `http://localhost:${WEB_PORT}`);
|
|
860
|
+
const file = u.searchParams.get("file") ?? "";
|
|
861
|
+
const user = dbUser(req);
|
|
862
|
+
const keysParam = u.searchParams.get("keys") ?? "";
|
|
863
|
+
const keys = keysParam ? keysParam.split(",").filter((k) => k.trim().length > 0) : null;
|
|
864
|
+
const adbPath = resolveAdbPath();
|
|
865
|
+
if (!adbPath) {
|
|
866
|
+
sendJson(res, 200, { error: "adb not found. Ensure platform-tools is installed and on PATH." });
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
let payload;
|
|
870
|
+
try {
|
|
871
|
+
const readResult = await readPrefsFile(adbPath, file, user);
|
|
872
|
+
if ("error" in readResult) {
|
|
873
|
+
payload = { error: readResult.error };
|
|
874
|
+
}
|
|
875
|
+
else {
|
|
876
|
+
const parsed = parsePrefsXml(readResult.xml);
|
|
877
|
+
if ("parseError" in parsed) {
|
|
878
|
+
payload = { error: parsed.parseError };
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
// Web route is human-consumable (renders to a scrolling table), so unlike the MCP
|
|
882
|
+
// get_prefs handler it does NOT byte-cap the response -- only the keys filter (if
|
|
883
|
+
// any) narrows what is returned. device_read_truncated is a real data-completeness
|
|
884
|
+
// signal (the 256KB on-device read cap) and is passed through either way.
|
|
885
|
+
//
|
|
886
|
+
// total_entries is the file's TRUE entry count, before any filtering -- keys narrows
|
|
887
|
+
// what is RETURNED, it does not shrink what the file actually has. Reporting the
|
|
888
|
+
// post-filter count for both fields (the original bug) makes the UI's "X of Y" always
|
|
889
|
+
// read "N of N" the moment keys is used, hiding how much of the file was left out.
|
|
890
|
+
const entries = keys && keys.length
|
|
891
|
+
? parsed.entries.filter((e) => keys.includes(e.key))
|
|
892
|
+
: parsed.entries;
|
|
893
|
+
payload = {
|
|
894
|
+
file,
|
|
895
|
+
user: readResult.user,
|
|
896
|
+
entries,
|
|
897
|
+
...(readResult.truncated ? { device_read_truncated: true } : {}),
|
|
898
|
+
total_entries: parsed.entries.length,
|
|
899
|
+
returned_entries: entries.length,
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
catch (e) {
|
|
905
|
+
payload = { error: String(e.message).split("\n")[0] };
|
|
906
|
+
}
|
|
907
|
+
sendJson(res, 200, payload);
|
|
908
|
+
}
|
|
909
|
+
async function handlePrefsSearch(req, res) {
|
|
910
|
+
const u = new URL(req.url ?? "", `http://localhost:${WEB_PORT}`);
|
|
911
|
+
const query = u.searchParams.get("query") ?? "";
|
|
912
|
+
const user = dbUser(req);
|
|
913
|
+
const adbPath = resolveAdbPath();
|
|
914
|
+
if (!adbPath) {
|
|
915
|
+
sendJson(res, 200, { error: "adb not found. Ensure platform-tools is installed and on PATH." });
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
let payload;
|
|
919
|
+
try {
|
|
920
|
+
const result = await searchPrefs(adbPath, query, user);
|
|
921
|
+
payload = {
|
|
922
|
+
query,
|
|
923
|
+
user: result.user,
|
|
924
|
+
available_users: availableUsers(),
|
|
925
|
+
results: result.results,
|
|
926
|
+
...(result.truncated ? { truncated: true } : {}),
|
|
927
|
+
...(result.skipped && result.skipped.length ? { skipped: result.skipped } : {}),
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
catch (e) {
|
|
931
|
+
payload = { error: String(e.message).split("\n")[0] };
|
|
932
|
+
}
|
|
933
|
+
sendJson(res, 200, payload);
|
|
934
|
+
}
|
|
695
935
|
/**
|
|
696
936
|
* Screen overlay routes. The live screen shows real DMs and message content, so the
|
|
697
937
|
* stream and record routes are gated behind an explicit per-process consent (granted
|
|
@@ -1022,6 +1262,11 @@ function handleStream(req, res) {
|
|
|
1022
1262
|
if (closed)
|
|
1023
1263
|
return;
|
|
1024
1264
|
settled = false;
|
|
1265
|
+
// Reassert before every connect (initial AND each retry): see forwardForRead's doc
|
|
1266
|
+
// comment. planReconnect already forces a hard forward rebuild on every OTHER retry
|
|
1267
|
+
// (tuned for "device end died"), which would only catch a foreign repoint by luck on
|
|
1268
|
+
// half of attempts; this cheap check-first call covers every attempt instead.
|
|
1269
|
+
forwardForRead();
|
|
1025
1270
|
upstream = http.request({
|
|
1026
1271
|
host: RADAR_HOST,
|
|
1027
1272
|
port: RADAR_PORT,
|
|
@@ -1115,6 +1360,21 @@ function listProfiles(res) {
|
|
|
1115
1360
|
const activeUserId = transport.getActiveUserId();
|
|
1116
1361
|
sendJson(res, 200, { profiles, active_user_id: activeUserId });
|
|
1117
1362
|
}
|
|
1363
|
+
// The attached-device list + the currently pinned device, for the dashboard's device picker.
|
|
1364
|
+
// listDevices() returns null when the adb listing itself failed (not "zero attached"); surface
|
|
1365
|
+
// that as adb_error:true with an empty list so the client can say why instead of showing "none".
|
|
1366
|
+
function listDevices(res) {
|
|
1367
|
+
// Distinguish null (adb listing failed) from [] (no devices): null means we cannot tell what
|
|
1368
|
+
// is attached, so tell the client with adb_error instead of a bare "none". A transport with no
|
|
1369
|
+
// listDevices() at all (undefined) is treated as "no devices", not an adb error.
|
|
1370
|
+
const listed = transport.listDevices?.();
|
|
1371
|
+
const adbError = listed === null;
|
|
1372
|
+
sendJson(res, 200, {
|
|
1373
|
+
devices: listed ?? [],
|
|
1374
|
+
selected: transport.getSelectedDevice?.() ?? null,
|
|
1375
|
+
...(adbError ? { adb_error: true } : {}),
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1118
1378
|
function activateRadar(res, userId) {
|
|
1119
1379
|
// Reset cached state so ensureForward() re-runs adb forward. This handles
|
|
1120
1380
|
// stale forwards after device-side idle timeout or profile switching.
|
package/dist/web/spec.d.ts
CHANGED
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
* and the same validate/coerce pass runs on every push so a malformed spec surfaces
|
|
6
6
|
* an error instead of rendering silent zeros.
|
|
7
7
|
*
|
|
8
|
-
* Most sources are live STREAMS (network/rtm/clog/trace/log/all). `db`
|
|
9
|
-
*
|
|
10
|
-
* series / match (
|
|
11
|
-
* validate passes short-circuit for
|
|
8
|
+
* Most sources are live STREAMS (network/rtm/clog/trace/log/all). `db` and `prefs` are the
|
|
9
|
+
* odd ones out: read-only, point-in-time BROWSERS (SQLite databases, SharedPreferences files)
|
|
10
|
+
* with no viz / series / match (each has its own list -> detail view). The coerce and
|
|
11
|
+
* validate passes short-circuit for both accordingly.
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
14
|
* Sources the dashboard can read. The first six are live streams; "all" is their unified
|
|
15
|
-
* timeline. "db"
|
|
16
|
-
*
|
|
15
|
+
* timeline. "db", "prefs", and "flags" are read-only point-in-time browsers (not streams) and
|
|
16
|
+
* are each handled as a distinct view.
|
|
17
17
|
*/
|
|
18
|
-
export declare const SOURCES: readonly ["rtm", "network", "clog", "trace", "log", "all", "db"];
|
|
18
|
+
export declare const SOURCES: readonly ["rtm", "network", "clog", "trace", "log", "all", "db", "prefs", "flags"];
|
|
19
19
|
export type Source = (typeof SOURCES)[number];
|
|
20
20
|
/** Widgets a spec may compose. */
|
|
21
21
|
export declare const VIZ: readonly ["counter", "rate", "sparkline", "feed", "inspector", "graph"];
|
package/dist/web/spec.js
CHANGED
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
* and the same validate/coerce pass runs on every push so a malformed spec surfaces
|
|
6
6
|
* an error instead of rendering silent zeros.
|
|
7
7
|
*
|
|
8
|
-
* Most sources are live STREAMS (network/rtm/clog/trace/log/all). `db`
|
|
9
|
-
*
|
|
10
|
-
* series / match (
|
|
11
|
-
* validate passes short-circuit for
|
|
8
|
+
* Most sources are live STREAMS (network/rtm/clog/trace/log/all). `db` and `prefs` are the
|
|
9
|
+
* odd ones out: read-only, point-in-time BROWSERS (SQLite databases, SharedPreferences files)
|
|
10
|
+
* with no viz / series / match (each has its own list -> detail view). The coerce and
|
|
11
|
+
* validate passes short-circuit for both accordingly.
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
14
|
* Sources the dashboard can read. The first six are live streams; "all" is their unified
|
|
15
|
-
* timeline. "db"
|
|
16
|
-
*
|
|
15
|
+
* timeline. "db", "prefs", and "flags" are read-only point-in-time browsers (not streams) and
|
|
16
|
+
* are each handled as a distinct view.
|
|
17
17
|
*/
|
|
18
|
-
export const SOURCES = ["rtm", "network", "clog", "trace", "log", "all", "db"];
|
|
18
|
+
export const SOURCES = ["rtm", "network", "clog", "trace", "log", "all", "db", "prefs", "flags"];
|
|
19
19
|
/** Widgets a spec may compose. */
|
|
20
20
|
export const VIZ = [
|
|
21
21
|
"counter",
|
|
@@ -50,8 +50,8 @@ export function coerceSpec(input) {
|
|
|
50
50
|
if (!isRecord(input))
|
|
51
51
|
return BLANK_SPEC;
|
|
52
52
|
const s = input;
|
|
53
|
-
// The DB
|
|
54
|
-
if (s.source === "db")
|
|
53
|
+
// The DB, Prefs, and feature-flags browsers have no match/viz/series to repair; leave as-is.
|
|
54
|
+
if (s.source === "db" || s.source === "prefs" || s.source === "flags")
|
|
55
55
|
return s;
|
|
56
56
|
if (typeof s.match === "string") {
|
|
57
57
|
// "all" mixes types whose summary fields differ, so a single field guess
|
|
@@ -110,6 +110,12 @@ export function validateSpec(s) {
|
|
|
110
110
|
}
|
|
111
111
|
return null;
|
|
112
112
|
}
|
|
113
|
+
// The Prefs and feature-flags browsers are likewise distinct, self-contained views: no
|
|
114
|
+
// viz/series/match to validate.
|
|
115
|
+
if (spec.source === "prefs")
|
|
116
|
+
return null;
|
|
117
|
+
if (spec.source === "flags")
|
|
118
|
+
return null;
|
|
113
119
|
if (spec.match !== undefined && !isRecord(spec.match)) {
|
|
114
120
|
return "match must be an object";
|
|
115
121
|
}
|