@slack/radar-mcp 1.25.0 → 1.26.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 +39 -2
- package/dist/mcp/dispatch.d.ts +1 -0
- package/dist/mcp/dispatch.js +4 -2
- package/dist/mcp/flags-tools.d.ts +1 -0
- package/dist/mcp/flags-tools.js +1 -1
- package/dist/mcp/index.js +14 -8
- package/dist/mcp/json-rows.d.ts +6 -0
- package/dist/mcp/json-rows.js +10 -0
- package/dist/mcp/radar-response.d.ts +2 -2
- package/dist/mcp/radar-response.js +2 -2
- package/dist/mcp/redact.d.ts +14 -0
- package/dist/mcp/redact.js +71 -0
- package/dist/mcp/session-enable.d.ts +1 -0
- package/dist/mcp/session-enable.js +8 -6
- package/dist/mcp/snapshot-cli.d.ts +52 -0
- package/dist/mcp/snapshot-cli.js +316 -0
- package/dist/mcp/snapshot-summary.d.ts +1 -0
- package/dist/mcp/snapshot-summary.js +254 -0
- package/dist/mcp/snapshot.d.ts +32 -3
- package/dist/mcp/snapshot.js +347 -102
- package/dist/mcp/tools.js +8 -4
- package/dist/shared/android.d.ts +25 -0
- package/dist/shared/android.js +97 -0
- package/dist/shared/feature-flags.d.ts +14 -5
- package/dist/shared/feature-flags.js +23 -6
- package/dist/shared/radar-token.d.ts +5 -5
- package/dist/shared/radar-token.js +24 -10
- package/dist/shared/switchboard-report.js +3 -0
- package/dist/shared/transport.d.ts +18 -0
- package/dist/web/public/index.html +1 -0
- package/dist/web/public/next/feature-flags.js +23 -6
- package/dist/web/public/next/feed.js +2 -2
- package/dist/web/public/next/flags.js +5 -3
- package/dist/web/public/next/store.js +1 -1
- package/dist/web/public/next/voice-model.js +13 -1
- package/dist/web/public/next/voice.js +8 -3
- package/package.json +1 -1
package/dist/mcp/snapshot.js
CHANGED
|
@@ -4,6 +4,11 @@ import os from "os";
|
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { RADAR_VERSION } from "../shared/constants.js";
|
|
6
6
|
import { getCaptureFilePath, readTailBytes } from "../shared/logcat-capture.js";
|
|
7
|
+
import { switchboardListPath } from "../shared/switchboard.js";
|
|
8
|
+
import { buildApiPath } from "./api-paths.js";
|
|
9
|
+
import { asObj, rowsOf } from "./json-rows.js";
|
|
10
|
+
import { redactDeep, redactText } from "./redact.js";
|
|
11
|
+
import { buildSnapshotSummary } from "./snapshot-summary.js";
|
|
7
12
|
/**
|
|
8
13
|
* `capture_snapshot` composer: bundles everything Radar has seen into a
|
|
9
14
|
* single on-disk artifact so a user can attach it to a Jira, drop it in a
|
|
@@ -11,9 +16,11 @@ import { getCaptureFilePath, readTailBytes } from "../shared/logcat-capture.js";
|
|
|
11
16
|
* tool outputs.
|
|
12
17
|
*
|
|
13
18
|
* Snapshot contents:
|
|
14
|
-
* - `
|
|
19
|
+
* - `summary.md` — the short read-me-first digest of the run
|
|
20
|
+
* - `bundle.json` — device-side buffers (net + RTM + clogs + traces + flags +
|
|
21
|
+
* voice sessions), failed-call details, device and app facts, metadata
|
|
15
22
|
* - `screenshot.png` — current screen (optional)
|
|
16
|
-
* - `logcat.tail.log` — last N lines of the
|
|
23
|
+
* - `logcat.tail.log` — last N lines of the log (optional)
|
|
17
24
|
*
|
|
18
25
|
* Written to `~/.slack-radar/snapshots/snapshot-<ts>/`. No cleanup: snapshots
|
|
19
26
|
* are user-triggered, small, and should persist for post-hoc inspection.
|
|
@@ -24,30 +31,44 @@ const DEFAULT_LOG_TAIL_LINES = 500;
|
|
|
24
31
|
const MAX_LOG_TAIL_LINES = 10_000;
|
|
25
32
|
const DEFAULT_LOG_TAIL_BYTES = 1 * 1024 * 1024; // 1 MB bound on file read
|
|
26
33
|
// Restrictive permissions on the snapshot dir and its files. The bundle
|
|
27
|
-
//
|
|
28
|
-
//
|
|
34
|
+
// can hold request details, message content and user IDs, so it is
|
|
35
|
+
// readable only by the owning user.
|
|
29
36
|
const DIR_MODE = 0o700;
|
|
30
37
|
const FILE_MODE = 0o600;
|
|
31
|
-
|
|
38
|
+
// Failed-call detail pass limits.
|
|
39
|
+
const DETAIL_READ_CAP = 100;
|
|
40
|
+
const DETAIL_KEEP_CAP = 25;
|
|
41
|
+
const DETAIL_BUDGET_MS = 20_000;
|
|
42
|
+
const REQUEST_BODY_CAP = 4 * 1024;
|
|
43
|
+
const RESPONSE_BODY_CAP = 8 * 1024;
|
|
44
|
+
const SWITCHBOARD_KEEP = 20;
|
|
45
|
+
const CONTENTS_LINE = "summaries of network, RTM and clog rows and of trace spans, details (headers and bodies) of failed or requested network calls, feature flags, voice-session summaries, device logs (the app's own log buffer, or logcat from every app on the device), user and org IDs, and device and app facts";
|
|
46
|
+
function privacyNotice(redacted) {
|
|
47
|
+
return redacted
|
|
48
|
+
? `bundle.json holds ${CONTENTS_LINE}. Auth headers, cookies and token-shaped strings are blanked by pattern, best effort, so review before sharing externally. screenshot.png is never redacted.`
|
|
49
|
+
: `Redaction is off. bundle.json holds ${CONTENTS_LINE}, with auth headers, cookies and tokens left as the device sent them. Review before sharing externally.`;
|
|
50
|
+
}
|
|
51
|
+
function bundleReadme(redacted) {
|
|
52
|
+
return `Slack Radar snapshot
|
|
32
53
|
====================
|
|
33
54
|
|
|
34
55
|
This directory is a point-in-time bundle of Radar state.
|
|
35
56
|
|
|
36
57
|
Files:
|
|
37
|
-
-
|
|
58
|
+
- summary.md: short digest of the run. Read this first.
|
|
59
|
+
- bundle.json: device-side network/RTM/clog/trace buffers, feature flags, voice
|
|
60
|
+
sessions, failed-call details, device and app facts, counts, and metadata.
|
|
38
61
|
Its mcp_version field records which @slack/radar-mcp produced this bundle.
|
|
39
|
-
- logcat.tail.log (optional): last N lines of the
|
|
62
|
+
- logcat.tail.log (optional): last N lines of the device log.
|
|
40
63
|
- screenshot.png (optional): current screen.
|
|
41
64
|
|
|
42
|
-
Privacy:
|
|
43
|
-
|
|
44
|
-
performance trace spans. Review before sharing externally. This bundle lives
|
|
45
|
-
on your local disk only; nothing is uploaded anywhere by Radar.
|
|
65
|
+
Privacy: ${privacyNotice(redacted)}
|
|
66
|
+
This bundle lives on your local disk only; nothing is uploaded anywhere by Radar.
|
|
46
67
|
|
|
47
68
|
To inspect: cat bundle.json | jq .
|
|
48
69
|
To share: zip -r snapshot.zip . then attach the zip.
|
|
49
70
|
`;
|
|
50
|
-
|
|
71
|
+
}
|
|
51
72
|
/**
|
|
52
73
|
* Resolve the output directory for a snapshot. Exported for tests.
|
|
53
74
|
*/
|
|
@@ -95,9 +116,162 @@ export function readRecentLogTail(requestedLimit = DEFAULT_LOG_TAIL_LINES) {
|
|
|
95
116
|
const tail = lines.slice(Math.max(0, lines.length - limit));
|
|
96
117
|
return { text: tail.join("\n"), truncated };
|
|
97
118
|
}
|
|
119
|
+
/** A call whose recorded status says it failed: 400 and up, or 0 and below. */
|
|
120
|
+
export function isFailedCall(row) {
|
|
121
|
+
const s = row.status_code;
|
|
122
|
+
return typeof s === "number" && Number.isFinite(s) && (s >= 400 || s <= 0);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The device buffers a snapshot reads, in fetch order. `rows` names the list inside the
|
|
126
|
+
* envelope; `keep` builds the run-window filter (none for flags, which are not timed).
|
|
127
|
+
*/
|
|
128
|
+
const BUFFERS = [
|
|
129
|
+
{ key: "network", path: buildBufferPath("network"), rows: "calls", label: "network buffer", keep: atOrAfter },
|
|
130
|
+
{ key: "rtm", path: buildBufferPath("rtm"), rows: "events", label: "rtm buffer", keep: atOrAfter },
|
|
131
|
+
{ key: "clogs", path: buildBufferPath("clogs"), rows: "clogs", label: "clog buffer", keep: atOrAfter },
|
|
132
|
+
{ key: "traces", path: buildBufferPath("traces"), rows: "traces", label: "trace buffer", keep: atOrAfter },
|
|
133
|
+
{ key: "feature_flags", path: "/api/feature_flags", rows: "feature_flags", label: "feature_flags buffer" },
|
|
134
|
+
{
|
|
135
|
+
key: "switchboard",
|
|
136
|
+
path: switchboardListPath(),
|
|
137
|
+
rows: "sessions",
|
|
138
|
+
label: "switchboard buffer",
|
|
139
|
+
// A session still open has no end yet, so it always overlaps the window.
|
|
140
|
+
keep: (since) => (s) => s.ended_at == null || Number(s.ended_at) >= since,
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
/** Copy of a list envelope with only the rows that pass `keep`; other fields untouched. */
|
|
144
|
+
function filterEnvelope(body, key, keep) {
|
|
145
|
+
const b = asObj(body);
|
|
146
|
+
if (!b || !Array.isArray(b[key]))
|
|
147
|
+
return body;
|
|
148
|
+
return { ...b, [key]: b[key].filter((r) => keep(asObj(r) ?? {})) };
|
|
149
|
+
}
|
|
150
|
+
function atOrAfter(since) {
|
|
151
|
+
// A row with no usable timestamp cannot be judged, so it stays.
|
|
152
|
+
return (row) => typeof row.timestamp !== "number" || row.timestamp >= since;
|
|
153
|
+
}
|
|
154
|
+
function cut(text, cap) {
|
|
155
|
+
return text.length > cap ? { text: text.slice(0, cap), cut: true } : { text, cut: false };
|
|
156
|
+
}
|
|
157
|
+
function bodyError(responseBody) {
|
|
158
|
+
if (typeof responseBody !== "string")
|
|
159
|
+
return { ok: null, error: null };
|
|
160
|
+
try {
|
|
161
|
+
const parsed = asObj(JSON.parse(responseBody));
|
|
162
|
+
if (!parsed)
|
|
163
|
+
return { ok: null, error: null };
|
|
164
|
+
const ok = typeof parsed.ok === "boolean" ? parsed.ok : null;
|
|
165
|
+
const e = parsed.error;
|
|
166
|
+
const error = typeof e === "string" ? e : e == null ? null : JSON.stringify(e).slice(0, 200);
|
|
167
|
+
return { ok, error };
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return { ok: null, error: null };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** Keeps the call in the bucket up to the cap; past it the bucket says it dropped some. */
|
|
174
|
+
function keepCapped(bucket, call) {
|
|
175
|
+
if (bucket.calls.length < DETAIL_KEEP_CAP)
|
|
176
|
+
bucket.calls.push(call);
|
|
177
|
+
else
|
|
178
|
+
bucket.truncated = true;
|
|
179
|
+
}
|
|
180
|
+
/** A body cut to `cap`; redacted first so a cut cannot split a secret value from its key. */
|
|
181
|
+
function cutBody(v, cap, redact) {
|
|
182
|
+
if (typeof v !== "string")
|
|
183
|
+
return { value: v, cut: false };
|
|
184
|
+
const r = cut(redact ? redactText(v) : v, cap);
|
|
185
|
+
return { value: r.text, cut: r.cut };
|
|
186
|
+
}
|
|
98
187
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
188
|
+
* Reads /api/network/<id> for the newest calls and keeps the failed ones (and the ones a
|
|
189
|
+
* caller asked for by URL) with headers and cut bodies. Bodies are redacted BEFORE they are
|
|
190
|
+
* cut, so a cut cannot split a secret value from the key that marks it.
|
|
191
|
+
*/
|
|
192
|
+
async function collectNetworkDetails(calls, fetchJson, detailUrls, redact, budgetMs) {
|
|
193
|
+
const newest = calls.slice().sort((a, b) => Number(b.timestamp ?? 0) - Number(a.timestamp ?? 0));
|
|
194
|
+
const wanted = (c) => typeof c.url === "string" && detailUrls.some((u) => u !== "" && c.url.includes(u));
|
|
195
|
+
const failures = { checked: 0, calls: [], truncated: false, unread: 0 };
|
|
196
|
+
const matches = { checked: 0, calls: [], truncated: false };
|
|
197
|
+
let checked = 0;
|
|
198
|
+
const started = Date.now();
|
|
199
|
+
let budgetSpent = false;
|
|
200
|
+
// A call whose status already says it failed stays listed even when its details could not
|
|
201
|
+
// be read; the row from the list is all there is, and detail_error says why. Only a skipped
|
|
202
|
+
// read counts as unread: a read that threw or came back empty was already counted as checked.
|
|
203
|
+
const keepBare = (call, why, skipped = false) => {
|
|
204
|
+
if (!isFailedCall(call))
|
|
205
|
+
return;
|
|
206
|
+
if (skipped)
|
|
207
|
+
failures.unread = (failures.unread ?? 0) + 1;
|
|
208
|
+
keepCapped(failures, { ...call, detail_error: why });
|
|
209
|
+
};
|
|
210
|
+
for (let i = 0; i < newest.length; i++) {
|
|
211
|
+
const call = newest[i];
|
|
212
|
+
if (i >= DETAIL_READ_CAP) {
|
|
213
|
+
keepBare(call, "details not read: past the first 100 calls", true);
|
|
214
|
+
if (wanted(call))
|
|
215
|
+
matches.truncated = true;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (!budgetSpent && Date.now() - started > budgetMs) {
|
|
219
|
+
budgetSpent = true;
|
|
220
|
+
failures.truncated = true;
|
|
221
|
+
if (detailUrls.length > 0)
|
|
222
|
+
matches.truncated = true;
|
|
223
|
+
}
|
|
224
|
+
if (budgetSpent) {
|
|
225
|
+
keepBare(call, "details not read: time budget spent", true);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const detailPath = buildApiPath("get_network_call_detail", { id: call.id });
|
|
229
|
+
if (!detailPath) {
|
|
230
|
+
keepBare(call, "details not read: no usable call id", true);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
checked++;
|
|
234
|
+
let detail;
|
|
235
|
+
try {
|
|
236
|
+
detail = asObj(await fetchJson(detailPath));
|
|
237
|
+
}
|
|
238
|
+
catch (e) {
|
|
239
|
+
keepBare(call, `details not read: ${e.message}`);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (!detail) {
|
|
243
|
+
keepBare(call, "details not read: empty reply");
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const { ok, error } = bodyError(detail.response_body);
|
|
247
|
+
const isFailed = isFailedCall(call) || ok === false;
|
|
248
|
+
const isWanted = wanted(call);
|
|
249
|
+
if (!isFailed && !isWanted)
|
|
250
|
+
continue;
|
|
251
|
+
const req = cutBody(detail.request_body, REQUEST_BODY_CAP, redact);
|
|
252
|
+
const res = cutBody(detail.response_body, RESPONSE_BODY_CAP, redact);
|
|
253
|
+
const kept = {
|
|
254
|
+
...call,
|
|
255
|
+
request_headers: detail.request_headers ?? null,
|
|
256
|
+
response_headers: detail.response_headers ?? null,
|
|
257
|
+
request_body: req.value ?? null,
|
|
258
|
+
response_body: res.value ?? null,
|
|
259
|
+
...(req.cut ? { request_body_truncated: true } : {}),
|
|
260
|
+
...(res.cut ? { response_body_truncated: true } : {}),
|
|
261
|
+
error,
|
|
262
|
+
};
|
|
263
|
+
if (isFailed)
|
|
264
|
+
keepCapped(failures, kept);
|
|
265
|
+
if (isWanted)
|
|
266
|
+
keepCapped(matches, kept);
|
|
267
|
+
}
|
|
268
|
+
failures.checked = checked;
|
|
269
|
+
matches.checked = checked;
|
|
270
|
+
return { failures, matches: detailUrls.length > 0 ? matches : null };
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Write a snapshot bundle to disk. The caller supplies `fetchJson` (a
|
|
274
|
+
* callback that GETs a device-side Radar path and throws on a device error)
|
|
101
275
|
* so this module does not need to know how `radarRequest` works — easier
|
|
102
276
|
* to test and keeps the device-HTTP plumbing in `index.ts`.
|
|
103
277
|
*
|
|
@@ -105,9 +279,11 @@ export function readRecentLogTail(requestedLimit = DEFAULT_LOG_TAIL_LINES) {
|
|
|
105
279
|
* snapshot still lands on disk with whatever succeeded; failures are
|
|
106
280
|
* collected in `result.errors` so the model can tell the user.
|
|
107
281
|
*/
|
|
108
|
-
export async function createSnapshot(device,
|
|
282
|
+
export async function createSnapshot(device, fetchJson, opts = {}, now = Date.now(), snapshotRoot = SNAPSHOT_DIR) {
|
|
109
283
|
const includeLogs = opts.includeLogs !== false;
|
|
110
284
|
const includeScreenshot = opts.includeScreenshot !== false;
|
|
285
|
+
const redact = opts.redact !== false;
|
|
286
|
+
const since = typeof opts.since === "number" && Number.isFinite(opts.since) ? opts.since : null;
|
|
111
287
|
// Clamp log_tail_lines at the composer boundary. The handler and schema
|
|
112
288
|
// validate too; this is defense-in-depth so no downstream consumer sees
|
|
113
289
|
// a pathological value.
|
|
@@ -120,76 +296,133 @@ export async function createSnapshot(device, fetchBuffer, opts = {}, now = Date.
|
|
|
120
296
|
const dir = buildSnapshotDir(now, snapshotRoot);
|
|
121
297
|
fs.mkdirSync(dir, { recursive: true, mode: DIR_MODE });
|
|
122
298
|
// `mkdirSync({ recursive: true, mode })` only applies the mode to
|
|
123
|
-
// directories it CREATES.
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
299
|
+
// directories it CREATES. Only the default root (and its parent) get
|
|
300
|
+
// tightened: a root the caller picked is theirs, and chmodding it or its
|
|
301
|
+
// parent could lock them out of a shared directory.
|
|
302
|
+
if (snapshotRoot === SNAPSHOT_DIR) {
|
|
303
|
+
for (const p of [snapshotRoot, path.dirname(snapshotRoot)]) {
|
|
304
|
+
try {
|
|
305
|
+
if (fs.existsSync(p))
|
|
306
|
+
fs.chmodSync(p, DIR_MODE);
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
// Best effort; not fatal.
|
|
310
|
+
}
|
|
135
311
|
}
|
|
136
312
|
}
|
|
137
313
|
const files = [];
|
|
138
|
-
const errors = [];
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
314
|
+
const errors = [...(opts.notes ?? [])];
|
|
315
|
+
const buffers = {
|
|
316
|
+
network: null,
|
|
317
|
+
rtm: null,
|
|
318
|
+
clogs: null,
|
|
319
|
+
traces: null,
|
|
320
|
+
feature_flags: null,
|
|
321
|
+
switchboard: null,
|
|
322
|
+
};
|
|
323
|
+
const fetched = {
|
|
324
|
+
network: false,
|
|
325
|
+
rtm: false,
|
|
326
|
+
clogs: false,
|
|
327
|
+
traces: false,
|
|
328
|
+
feature_flags: false,
|
|
329
|
+
switchboard: false,
|
|
330
|
+
};
|
|
331
|
+
// Device-side buffers, one after the other. Failures are individually caught so one failing
|
|
332
|
+
// buffer does not nuke the whole snapshot. `fetched` distinguishes "empty because the buffer
|
|
333
|
+
// was empty" from "null because the fetch failed" — counts alone cannot tell these apart.
|
|
334
|
+
// Traces capture from app start (like clogs); an older debug build without /api/traces fails
|
|
335
|
+
// that one fetch and it lands in errors[] like any other buffer.
|
|
336
|
+
for (const buf of BUFFERS) {
|
|
337
|
+
try {
|
|
338
|
+
buffers[buf.key] = await fetchJson(buf.path);
|
|
339
|
+
fetched[buf.key] = true;
|
|
340
|
+
}
|
|
341
|
+
catch (e) {
|
|
342
|
+
errors.push(`${buf.label}: ${e.message}`);
|
|
343
|
+
}
|
|
158
344
|
}
|
|
159
|
-
|
|
160
|
-
|
|
345
|
+
// Run window. total_captured stays as the device sent it: it says how much the
|
|
346
|
+
// buffer held, which is still true after the cut.
|
|
347
|
+
if (since !== null) {
|
|
348
|
+
for (const buf of BUFFERS) {
|
|
349
|
+
if (buf.keep)
|
|
350
|
+
buffers[buf.key] = filterEnvelope(buffers[buf.key], buf.rows, buf.keep(since));
|
|
351
|
+
}
|
|
161
352
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
353
|
+
// Newest voice sessions first, so the cut keeps the ones a run most likely cares about.
|
|
354
|
+
const sb = asObj(buffers.switchboard);
|
|
355
|
+
if (sb && Array.isArray(sb.sessions)) {
|
|
356
|
+
const sessions = rowsOf(sb, "sessions")
|
|
357
|
+
.sort((x, y) => Number(y.began_at ?? 0) - Number(x.began_at ?? 0))
|
|
358
|
+
.slice(0, SWITCHBOARD_KEEP);
|
|
359
|
+
buffers.switchboard = { ...sb, sessions };
|
|
165
360
|
}
|
|
166
|
-
|
|
167
|
-
|
|
361
|
+
const runWindow = {
|
|
362
|
+
since_ms: since,
|
|
363
|
+
until_ms: typeof opts.untilMs === "number" ? opts.untilMs : null,
|
|
364
|
+
source: since === null ? "none" : (opts.windowSource ?? "since_flag"),
|
|
365
|
+
};
|
|
366
|
+
// Failed calls, plus any the caller asked to keep by URL.
|
|
367
|
+
let networkFailures = null;
|
|
368
|
+
let networkMatches = null;
|
|
369
|
+
if (fetched.network) {
|
|
370
|
+
try {
|
|
371
|
+
const pass = await collectNetworkDetails(rowsOf(buffers.network, "calls"), fetchJson, opts.detailUrls ?? [], redact, opts.detailBudgetMs ?? DETAIL_BUDGET_MS);
|
|
372
|
+
networkFailures = pass.failures;
|
|
373
|
+
networkMatches = pass.matches;
|
|
374
|
+
}
|
|
375
|
+
catch (e) {
|
|
376
|
+
errors.push(`network details: ${e.message}`);
|
|
377
|
+
}
|
|
168
378
|
}
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// the rest of the snapshot still lands.
|
|
379
|
+
// Facts about the device and app.
|
|
380
|
+
let deviceFacts = {};
|
|
381
|
+
let appFacts = {};
|
|
173
382
|
try {
|
|
174
|
-
|
|
175
|
-
|
|
383
|
+
const facts = device.getDeviceFacts?.();
|
|
384
|
+
if (facts) {
|
|
385
|
+
deviceFacts = { ...facts.device };
|
|
386
|
+
appFacts = { ...facts.app };
|
|
387
|
+
}
|
|
176
388
|
}
|
|
177
389
|
catch (e) {
|
|
178
|
-
errors.push(`
|
|
390
|
+
errors.push(`device facts: ${e.message}`);
|
|
179
391
|
}
|
|
180
|
-
|
|
181
|
-
|
|
392
|
+
appFacts.android_user_id = device.getActiveUserId();
|
|
393
|
+
appFacts.signed_in_org_ids = [
|
|
394
|
+
...new Set(rowsOf(buffers.feature_flags, "feature_flags")
|
|
395
|
+
.map((f) => f.org_id)
|
|
396
|
+
.filter((o) => typeof o === "string" && o !== "")),
|
|
397
|
+
];
|
|
398
|
+
// Log tail. The capture file wins when it has lines; otherwise ask the device.
|
|
399
|
+
let logText = "";
|
|
400
|
+
let logTruncated = false;
|
|
401
|
+
let logSourceName = null;
|
|
182
402
|
if (includeLogs) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
403
|
+
if (opts.logSource !== "device") {
|
|
404
|
+
try {
|
|
405
|
+
const tail = readRecentLogTail(logTailLines);
|
|
406
|
+
if (tail.text) {
|
|
407
|
+
logText = tail.text;
|
|
408
|
+
logTruncated = tail.truncated;
|
|
409
|
+
logSourceName = "logcat_capture";
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
catch (e) {
|
|
413
|
+
errors.push(`logcat tail: ${e.message}`);
|
|
189
414
|
}
|
|
190
415
|
}
|
|
191
|
-
|
|
192
|
-
|
|
416
|
+
if (!logText && device.getRecentLogs) {
|
|
417
|
+
try {
|
|
418
|
+
const r = device.getRecentLogs("", logTailLines);
|
|
419
|
+
logText = r.lines.join("\n");
|
|
420
|
+
// A read that worked and came back empty still has a source; the summary shows 0 lines from it.
|
|
421
|
+
logSourceName = r.source;
|
|
422
|
+
}
|
|
423
|
+
catch (e) {
|
|
424
|
+
errors.push(`logcat tail: ${e.message}`);
|
|
425
|
+
}
|
|
193
426
|
}
|
|
194
427
|
}
|
|
195
428
|
// Screenshot. 720px default is plenty for bug reports; full-res is
|
|
@@ -222,12 +455,24 @@ export async function createSnapshot(device, fetchBuffer, opts = {}, now = Date.
|
|
|
222
455
|
errors.push(`screenshot: ${e.message}`);
|
|
223
456
|
}
|
|
224
457
|
}
|
|
458
|
+
const notice = privacyNotice(redact);
|
|
459
|
+
const finalLogText = redact ? redactText(logText) : logText;
|
|
460
|
+
if (finalLogText) {
|
|
461
|
+
try {
|
|
462
|
+
const logFile = path.join(dir, "logcat.tail.log");
|
|
463
|
+
fs.writeFileSync(logFile, finalLogText, { mode: FILE_MODE });
|
|
464
|
+
files.push(logFile);
|
|
465
|
+
}
|
|
466
|
+
catch (e) {
|
|
467
|
+
errors.push(`logcat tail: ${e.message}`);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
225
470
|
// README. One-paragraph explainer so a receiver who opens the dir for
|
|
226
471
|
// the first time knows what each file is and what privacy exposure it
|
|
227
472
|
// carries.
|
|
228
473
|
try {
|
|
229
474
|
const readmeFile = path.join(dir, "README.txt");
|
|
230
|
-
fs.writeFileSync(readmeFile,
|
|
475
|
+
fs.writeFileSync(readmeFile, bundleReadme(redact), { mode: FILE_MODE });
|
|
231
476
|
files.push(readmeFile);
|
|
232
477
|
}
|
|
233
478
|
catch (e) {
|
|
@@ -235,37 +480,50 @@ export async function createSnapshot(device, fetchBuffer, opts = {}, now = Date.
|
|
|
235
480
|
}
|
|
236
481
|
// Bundle JSON. Written last so counts reflect everything captured.
|
|
237
482
|
const counts = {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
traces: countItems(traces),
|
|
242
|
-
log_lines: logTail.text
|
|
243
|
-
? logTail.text.split("\n").filter(Boolean).length
|
|
244
|
-
: 0,
|
|
245
|
-
log_lines_truncated: logTail.truncated,
|
|
483
|
+
...Object.fromEntries(BUFFERS.map((b) => [b.key, rowsOf(buffers[b.key], b.rows).length])),
|
|
484
|
+
log_lines: finalLogText ? finalLogText.split("\n").filter(Boolean).length : 0,
|
|
485
|
+
log_lines_truncated: logTruncated,
|
|
246
486
|
screenshot: screenshotCaptured,
|
|
247
487
|
};
|
|
248
|
-
const
|
|
488
|
+
const rawBundle = {
|
|
249
489
|
// Format version of this bundle's schema — not the Radar version, which
|
|
250
490
|
// is mcp_version below. Named to keep the two unmistakable in a shared file.
|
|
251
|
-
bundle_format_version:
|
|
491
|
+
bundle_format_version: 3,
|
|
252
492
|
mcp_version: RADAR_VERSION,
|
|
253
493
|
timestamp: now,
|
|
254
494
|
platform: device.platform,
|
|
255
495
|
active_user_id: device.getActiveUserId(),
|
|
256
496
|
capture_file: getCaptureFilePath(),
|
|
257
|
-
|
|
497
|
+
run_window: runWindow,
|
|
498
|
+
device: deviceFacts,
|
|
499
|
+
app: appFacts,
|
|
500
|
+
buffers,
|
|
501
|
+
network_failures: networkFailures,
|
|
502
|
+
...(networkMatches ? { network_matches: networkMatches } : {}),
|
|
503
|
+
logs: { source: logSourceName, lines: counts.log_lines, truncated: logTruncated },
|
|
258
504
|
counts,
|
|
259
505
|
fetched,
|
|
260
506
|
errors,
|
|
261
|
-
|
|
507
|
+
redacted: redact,
|
|
508
|
+
privacy_notice: notice,
|
|
262
509
|
};
|
|
510
|
+
const bundle = (redact ? redactDeep(rawBundle) : rawBundle);
|
|
511
|
+
let summaryPath = null;
|
|
512
|
+
try {
|
|
513
|
+
const p = path.join(dir, "summary.md");
|
|
514
|
+
fs.writeFileSync(p, buildSnapshotSummary(bundle, finalLogText), { mode: FILE_MODE });
|
|
515
|
+
summaryPath = p;
|
|
516
|
+
files.unshift(p);
|
|
517
|
+
}
|
|
518
|
+
catch (e) {
|
|
519
|
+
errors.push(`summary: ${e.message}`);
|
|
520
|
+
}
|
|
263
521
|
const bundleFile = path.join(dir, "bundle.json");
|
|
264
522
|
fs.writeFileSync(bundleFile, JSON.stringify(bundle, null, 2), {
|
|
265
523
|
mode: FILE_MODE,
|
|
266
524
|
});
|
|
267
525
|
files.unshift(bundleFile);
|
|
268
|
-
// Auto-zip: collapse the
|
|
526
|
+
// Auto-zip: collapse the directory into a single shareable
|
|
269
527
|
// artifact. Users universally want to attach ONE file to Jira or drop
|
|
270
528
|
// ONE file in Slack, not drag a directory. Best-effort: record the
|
|
271
529
|
// failure and the user can zip manually.
|
|
@@ -274,11 +532,14 @@ export async function createSnapshot(device, fetchBuffer, opts = {}, now = Date.
|
|
|
274
532
|
path: dir,
|
|
275
533
|
files,
|
|
276
534
|
zip_path: zipPath,
|
|
535
|
+
summary_path: summaryPath,
|
|
277
536
|
timestamp: now,
|
|
278
537
|
counts,
|
|
279
538
|
fetched,
|
|
280
539
|
errors,
|
|
281
|
-
privacy_notice:
|
|
540
|
+
privacy_notice: notice,
|
|
541
|
+
redacted: redact,
|
|
542
|
+
run_window: runWindow,
|
|
282
543
|
};
|
|
283
544
|
}
|
|
284
545
|
// `zip` ships with macOS and most Linux distros but not every image (the
|
|
@@ -320,19 +581,3 @@ function zipSnapshotDir(dir, errors) {
|
|
|
320
581
|
: `zip not available: no ${ZIP_TOOLS.map((t) => t.cmd).join(" or ")} on PATH`);
|
|
321
582
|
return null;
|
|
322
583
|
}
|
|
323
|
-
/**
|
|
324
|
-
* Count items inside a buffer response. Handles the `{ calls: [...] }`,
|
|
325
|
-
* `{ events: [...] }`, `{ clogs: [...] }`, `{ traces: [...] }` shapes the
|
|
326
|
-
* radar HTTP server uses. Falls back to 0 on malformed responses.
|
|
327
|
-
*/
|
|
328
|
-
function countItems(body) {
|
|
329
|
-
if (!body || typeof body !== "object")
|
|
330
|
-
return 0;
|
|
331
|
-
const b = body;
|
|
332
|
-
for (const key of ["calls", "events", "clogs", "traces", "items"]) {
|
|
333
|
-
const v = b[key];
|
|
334
|
-
if (Array.isArray(v))
|
|
335
|
-
return v.length;
|
|
336
|
-
}
|
|
337
|
-
return 0;
|
|
338
|
-
}
|
package/dist/mcp/tools.js
CHANGED
|
@@ -88,7 +88,7 @@ export function serverInstructions(platform) {
|
|
|
88
88
|
].join("\n");
|
|
89
89
|
}
|
|
90
90
|
// Shared by the three flag tools so their wording cannot drift apart.
|
|
91
|
-
const SESSION_VALUE_NOTE = "Rows carry session_enabled (the flag's own value the app runs now: the first-read value for a flag already read this session, or the value a read returns now for one not yet read) and restart_note when it differs from `enabled`; a row where session_enabled or enabled is absent or not a boolean is not known, never a match; only when both are booleans does a missing restart_note mean they match.";
|
|
91
|
+
const SESSION_VALUE_NOTE = "Rows carry session_enabled (the flag's own value the app runs now: the first-read value for a flag already read this session, or the value a read returns now for one not yet read) and restart_note when it differs from `enabled`; a toggle row where session_enabled or enabled is absent or not a boolean is not known, never a match; only when both are booleans does a missing restart_note mean they match. Experiment rows carry session_group_name (the group the first read this session returned, or a read returns now for one not yet read; \"\" is no group; read-once code may still use it until restart, for a signed-in team until it signs out) and restart_note when it differs from group_name; absent or not a string means not known, and only when both are strings does a missing restart_note mean they match; code that reads every time already runs group_name.";
|
|
92
92
|
export const TOOL_DEFINITIONS = [
|
|
93
93
|
{
|
|
94
94
|
name: "ping",
|
|
@@ -233,13 +233,13 @@ export const TOOL_DEFINITIONS = [
|
|
|
233
233
|
},
|
|
234
234
|
{
|
|
235
235
|
name: "get_switchboard_sessions",
|
|
236
|
-
description: "List the Slackbot voice (switchboard) sessions the device still holds, at most 8, newest first. A session is one voice conversation attempt, from the controller starting (before any socket opens) to it ending. Each entry carries session_id, team_id, began_at, ended_at (null live), total_captured, frames {incoming, outgoing}, last_state (newest connection/mic/speaking state, absent before the first state record), levels (newest level tick, or null), server_session_id (null until named), turns ({count, last_response_ms, last_clock}, null before the first timed turn) and saved_turn_counts (per outcome), all absent on an older build. last_response_ms can be a gap between reply chunks when last_clock is resumed_from_server_answer. saved_turn_counts counts each outcome, and absent on an older device build means not counted, not zero. A server resend counts again under applied or no_line, so their sum can run above the finals and is not a lost turn. session_id restarts at 1 with the app process; go by began_at. A session already running when radar was enabled lists from its first seen record, team_id null. get_switchboard_session(id) has the records.",
|
|
236
|
+
description: "List the Slackbot voice (switchboard) sessions the device still holds, at most 8, newest first. A session is one voice conversation attempt, from the controller starting (before any socket opens) to it ending. Each entry carries session_id, team_id, began_at, ended_at (null live), total_captured, frames {incoming, outgoing}, last_state (newest connection/mic/speaking/user_speaking state, absent before the first state record), levels (newest level tick, or null), server_session_id (null until named), turns ({count, last_response_ms, last_clock}, null before the first timed turn) and saved_turn_counts (per outcome), all absent on an older build. last_response_ms can be a gap between reply chunks when last_clock is resumed_from_server_answer. saved_turn_counts counts each outcome, and absent on an older device build means not counted, not zero. A server resend counts again under applied or no_line, so their sum can run above the finals and is not a lost turn. session_id restarts at 1 with the app process; go by began_at. A session already running when radar was enabled lists from its first seen record, team_id null. get_switchboard_session(id) has the records.",
|
|
237
237
|
inputSchema: { type: "object", properties: {} },
|
|
238
238
|
annotations: { readOnlyHint: true },
|
|
239
239
|
},
|
|
240
240
|
{
|
|
241
241
|
name: "get_switchboard_session",
|
|
242
|
-
description: "Get one voice session's summary plus the newest `limit` of its records (events), oldest first; events is only the page. Record kinds: state = connection, mic and
|
|
242
|
+
description: "Get one voice session's summary plus the newest `limit` of its records (events), oldest first; events is only the page. Record kinds: state = connection, mic, speaking and user_speaking transitions (state_kind, from, to, cause) with Server:<code> and SwipedAway causes; frame = control frames in and out (direction, frame_type, bytes), audio frames carry frame_type audio and a byte count, never the audio; player = playback events rearm, jitter_trim, hold_refuse, reply_hold, reply_unhold, read_stall, pre_ready_drop with gap_ms, bytes_queued, dropped_chunks; phase = startup phase durations (phase, duration_ms); session = begin, end, ready (server_session_id), config (mic_encoding); levels = one meter-tick batch (started_at, sample_count, offsets_ms, mic/playback rms+peak arrays, 0..1); turn = response_ms (end of speech to first reply audio) and clock (no_card, resumed_from_tap, resumed_from_server_answer); saved_turn = outcome (applied, no_line, missing_field, other_session), has_thread; reconnect_try = trigger (restart, drop, settings), try, outcome (ready, retry, refused, gave_up, where try counts tries made and 0 means the budget was already spent); a Reconnecting state's cause is its trigger; card = card_kind (tool_approval, auth_prompt), event (shown, answered, refused, declined, closed, replaced, expired, cleared, carried), by (tap, server), card_id; a card shown or carried with no later record was still up at the session's last record. Summary server_session_ids lists ready ids. For saved_turn, no_line means no subtitle line still held the item and the turn is still kept; every turn other_session with a null server_session_id usually means session.ready named no session (a ready record with a null id) or never arrived (no ready record). Pass kind to narrow (player for stutter, state for mic and connection, phase for slow start, levels for meter history); the limit applies after the kind filter; total_captured counts every kind. For the whole session use export_switchboard_session or query_session under source switchboard.",
|
|
243
243
|
inputSchema: {
|
|
244
244
|
type: "object",
|
|
245
245
|
properties: {
|
|
@@ -317,7 +317,7 @@ export const TOOL_DEFINITIONS = [
|
|
|
317
317
|
},
|
|
318
318
|
{
|
|
319
319
|
name: "capture_snapshot",
|
|
320
|
-
description: "Bundle the current Radar state into a single on-disk artifact for sharing. Writes
|
|
320
|
+
description: "Bundle the current Radar state into a single on-disk artifact for sharing. Writes to ~/.slack-radar/snapshots/snapshot-<ts>/: summary.md (read this first: failed calls, log errors, clogs, flags), bundle.json (network + RTM + clog + trace buffers, up to 1000 items each, plus feature flags, voice-session summaries, details of failed network calls, and device and app facts), logcat.tail.log (last N log lines), screenshot.png (current screen), and README.txt (receiver-facing explainer). Use when the user says 'save this', 'file this as a bug', 'share this', 'bundle this up', 'attach to a ticket', 'make me a repro', or otherwise wants a shareable reproducible handoff. PRIVACY: auth headers, cookies and token-shaped strings are blanked by pattern by default, best effort, so still review before sharing externally; redact=false keeps them raw. " +
|
|
321
321
|
"When it returns, tell the user: result.zip_path (the single shareable file), else result.path; a one-line summary of the counts; \"Privacy: \" followed by result.privacy_notice word for word, verbatim and never paraphrased, even under time pressure; if result.log_lines_truncated is true, that the 1 MB read cap cut the log lines; if result.errors is non-empty, which parts failed. If they asked to file it as a bug or attach it to a ticket, offer to attach result.zip_path through the Jira or Slack MCP; do not attach without asking.",
|
|
322
322
|
inputSchema: {
|
|
323
323
|
type: "object",
|
|
@@ -336,6 +336,10 @@ export const TOOL_DEFINITIONS = [
|
|
|
336
336
|
minimum: 1,
|
|
337
337
|
maximum: 10000,
|
|
338
338
|
},
|
|
339
|
+
redact: {
|
|
340
|
+
type: "boolean",
|
|
341
|
+
description: "Blank auth headers, cookies and token-shaped strings (default: true). false keeps raw headers and tokens; only for a bundle that stays on this machine.",
|
|
342
|
+
},
|
|
339
343
|
},
|
|
340
344
|
},
|
|
341
345
|
annotations: { readOnlyHint: false },
|