@slack/radar-mcp 1.24.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.
Files changed (51) hide show
  1. package/README.md +41 -4
  2. package/dist/mcp/dispatch.d.ts +1 -0
  3. package/dist/mcp/dispatch.js +4 -2
  4. package/dist/mcp/flags-tools.d.ts +1 -0
  5. package/dist/mcp/flags-tools.js +3 -9
  6. package/dist/mcp/index.js +16 -40
  7. package/dist/mcp/json-rows.d.ts +6 -0
  8. package/dist/mcp/json-rows.js +10 -0
  9. package/dist/mcp/radar-response.d.ts +2 -2
  10. package/dist/mcp/radar-response.js +2 -2
  11. package/dist/mcp/redact.d.ts +14 -0
  12. package/dist/mcp/redact.js +71 -0
  13. package/dist/mcp/session-enable.d.ts +1 -0
  14. package/dist/mcp/session-enable.js +8 -6
  15. package/dist/mcp/snapshot-cli.d.ts +52 -0
  16. package/dist/mcp/snapshot-cli.js +316 -0
  17. package/dist/mcp/snapshot-summary.d.ts +1 -0
  18. package/dist/mcp/snapshot-summary.js +254 -0
  19. package/dist/mcp/snapshot.d.ts +32 -3
  20. package/dist/mcp/snapshot.js +347 -102
  21. package/dist/mcp/tools.js +11 -7
  22. package/dist/shared/android.d.ts +25 -0
  23. package/dist/shared/android.js +97 -0
  24. package/dist/shared/feature-flags.d.ts +20 -0
  25. package/dist/shared/feature-flags.js +35 -4
  26. package/dist/shared/radar-token.d.ts +5 -5
  27. package/dist/shared/radar-token.js +24 -10
  28. package/dist/shared/switchboard-note.d.ts +19 -0
  29. package/dist/shared/switchboard-note.js +76 -0
  30. package/dist/shared/switchboard-report.js +43 -4
  31. package/dist/shared/switchboard.d.ts +1 -1
  32. package/dist/shared/switchboard.js +14 -2
  33. package/dist/shared/transport.d.ts +18 -0
  34. package/dist/shared/wire.d.ts +2 -0
  35. package/dist/web/install-app-cli.d.ts +2 -0
  36. package/dist/web/install-app-cli.js +60 -0
  37. package/dist/web/install-app.d.ts +16 -7
  38. package/dist/web/install-app.js +92 -39
  39. package/dist/web/macapp/RadarApp.swift +12 -11
  40. package/dist/web/public/index.html +5 -2
  41. package/dist/web/public/next/feature-flags.js +50 -0
  42. package/dist/web/public/next/feed.js +15 -4
  43. package/dist/web/public/next/flags.js +17 -3
  44. package/dist/web/public/next/registry.js +4 -4
  45. package/dist/web/public/next/store.js +90 -4
  46. package/dist/web/public/next/switchboard-note.js +76 -0
  47. package/dist/web/public/next/voice-model.js +209 -15
  48. package/dist/web/public/next/voice.js +73 -10
  49. package/dist/web/spec.d.ts +1 -1
  50. package/dist/web/spec.js +1 -1
  51. package/package.json +1 -1
@@ -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
- * - `bundle.json` — device-side buffers (net + RTM + clogs + traces) plus metadata
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 active capture file (optional)
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
- // contains network request/response bodies (including auth headers),
28
- // message content, and user IDs — readable only by the owning user.
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
- const BUNDLE_README = `Slack Radar snapshot
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
- - bundle.json: device-side network/RTM/clog/trace buffers, counts, and metadata.
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 on-device logcat capture.
62
+ - logcat.tail.log (optional): last N lines of the device log.
40
63
  - screenshot.png (optional): current screen.
41
64
 
42
- Privacy: bundle.json contains raw API request/response bodies (auth headers,
43
- tokens), RTM message content, user IDs, channel IDs, clog payloads, and
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
- const PRIVACY_NOTICE = "bundle.json contains raw API request/response bodies (including auth headers), RTM message content, user IDs, clog payloads, and performance trace spans. Review before sharing externally.";
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
- * Write a snapshot bundle to disk. The caller supplies `fetchBuffer` (a
100
- * callback that hits the device's HTTP endpoint for a given buffer name)
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, fetchBuffer, opts = {}, now = Date.now(), snapshotRoot = SNAPSHOT_DIR) {
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. If `~/.slack-radar/` or `.../snapshots/`
124
- // already existed (e.g. created by a pre-R1 build or by the logcat
125
- // capture module with default umask → 0o755), they keep old perms.
126
- // Tighten them to 0o700 on every snapshot so the parent tree cannot
127
- // leak directory-listing on a shared host.
128
- for (const p of [snapshotRoot, path.dirname(snapshotRoot)]) {
129
- try {
130
- if (fs.existsSync(p))
131
- fs.chmodSync(p, DIR_MODE);
132
- }
133
- catch {
134
- // Best effort; not fatal.
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
- let network = null;
140
- let rtm = null;
141
- let clogs = null;
142
- let traces = null;
143
- const fetched = { network: false, rtm: false, clogs: false, traces: false };
144
- // Device-side buffers. Failures are individually caught so one failing
145
- // buffer does not nuke the whole snapshot. `fetched` distinguishes
146
- // "empty because the buffer was empty" from "null because the fetch
147
- // failed" — counts alone cannot tell these apart.
148
- try {
149
- network = await fetchBuffer("network");
150
- fetched.network = true;
151
- }
152
- catch (e) {
153
- errors.push(`network buffer: ${e.message}`);
154
- }
155
- try {
156
- rtm = await fetchBuffer("rtm");
157
- fetched.rtm = true;
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
- catch (e) {
160
- errors.push(`rtm buffer: ${e.message}`);
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
- try {
163
- clogs = await fetchBuffer("clogs");
164
- fetched.clogs = true;
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
- catch (e) {
167
- errors.push(`clog buffer: ${e.message}`);
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
- // Traces capture from app start (like clogs), so they are worth
170
- // bundling. An older debug build without the /api/traces route fails
171
- // this one fetch and it is recorded in errors[] like any other buffer;
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
- traces = await fetchBuffer("traces");
175
- fetched.traces = true;
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(`trace buffer: ${e.message}`);
390
+ errors.push(`device facts: ${e.message}`);
179
391
  }
180
- // Logcat tail.
181
- let logTail = { text: "", truncated: false };
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
- try {
184
- logTail = readRecentLogTail(logTailLines);
185
- if (logTail.text) {
186
- const logFile = path.join(dir, "logcat.tail.log");
187
- fs.writeFileSync(logFile, logTail.text, { mode: FILE_MODE });
188
- files.push(logFile);
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
- catch (e) {
192
- errors.push(`logcat tail: ${e.message}`);
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, BUNDLE_README, { mode: FILE_MODE });
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
- network: countItems(network),
239
- rtm: countItems(rtm),
240
- clogs: countItems(clogs),
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 bundle = {
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: 2,
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
- buffers: { network, rtm, clogs, traces },
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
- privacy_notice: PRIVACY_NOTICE,
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 4-file directory into a single shareable
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: 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
- }