@slack/radar-mcp 1.25.0 → 1.27.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 (63) hide show
  1. package/README.md +47 -3
  2. package/dist/mcp/api-paths.d.ts +25 -1
  3. package/dist/mcp/api-paths.js +85 -9
  4. package/dist/mcp/dispatch.d.ts +1 -0
  5. package/dist/mcp/dispatch.js +4 -2
  6. package/dist/mcp/flags-tools.d.ts +1 -0
  7. package/dist/mcp/flags-tools.js +1 -1
  8. package/dist/mcp/index.js +36 -11
  9. package/dist/mcp/json-rows.d.ts +6 -0
  10. package/dist/mcp/json-rows.js +10 -0
  11. package/dist/mcp/radar-response.d.ts +2 -2
  12. package/dist/mcp/radar-response.js +2 -2
  13. package/dist/mcp/redact.d.ts +14 -0
  14. package/dist/mcp/redact.js +71 -0
  15. package/dist/mcp/session-enable.d.ts +1 -0
  16. package/dist/mcp/session-enable.js +8 -6
  17. package/dist/mcp/snapshot-cli.d.ts +52 -0
  18. package/dist/mcp/snapshot-cli.js +331 -0
  19. package/dist/mcp/snapshot-summary.d.ts +1 -0
  20. package/dist/mcp/snapshot-summary.js +254 -0
  21. package/dist/mcp/snapshot.d.ts +32 -3
  22. package/dist/mcp/snapshot.js +392 -125
  23. package/dist/mcp/test-runs-tools.d.ts +2 -0
  24. package/dist/mcp/test-runs-tools.js +58 -5
  25. package/dist/mcp/tools.js +32 -6
  26. package/dist/shared/android.d.ts +40 -4
  27. package/dist/shared/android.js +199 -12
  28. package/dist/shared/constants.d.ts +6 -5
  29. package/dist/shared/constants.js +6 -5
  30. package/dist/shared/feature-flags.d.ts +14 -5
  31. package/dist/shared/feature-flags.js +23 -6
  32. package/dist/shared/radar-token.d.ts +5 -5
  33. package/dist/shared/radar-token.js +24 -10
  34. package/dist/shared/switchboard-note.js +2 -1
  35. package/dist/shared/switchboard-report.js +4 -1
  36. package/dist/shared/test-case-capture.d.ts +15 -0
  37. package/dist/shared/test-case-capture.js +235 -0
  38. package/dist/shared/test-case-store.d.ts +54 -0
  39. package/dist/shared/test-case-store.js +208 -0
  40. package/dist/shared/transport.d.ts +27 -1
  41. package/dist/web/install-app.js +1 -1
  42. package/dist/web/public/index.html +2 -0
  43. package/dist/web/public/next/app.js +12 -1
  44. package/dist/web/public/next/feature-flags.js +23 -6
  45. package/dist/web/public/next/feed.js +19 -4
  46. package/dist/web/public/next/filters.js +5 -5
  47. package/dist/web/public/next/flags.js +5 -3
  48. package/dist/web/public/next/registry.js +3 -2
  49. package/dist/web/public/next/save-case.js +92 -0
  50. package/dist/web/public/next/store.js +4 -2
  51. package/dist/web/public/next/switchboard-note.js +2 -1
  52. package/dist/web/public/next/test-cases.js +328 -0
  53. package/dist/web/public/next/voice-model.js +13 -1
  54. package/dist/web/public/next/voice.js +9 -4
  55. package/dist/web/server.d.ts +1 -0
  56. package/dist/web/server.js +214 -2
  57. package/dist/web/spec.d.ts +3 -2
  58. package/dist/web/spec.js +10 -9
  59. package/package.json +1 -1
  60. package/dist/mcp/test-cases.d.ts +0 -14
  61. package/dist/mcp/test-cases.js +0 -77
  62. /package/dist/web/public/icons/{radar-1024.png → icon-1024.png} +0 -0
  63. /package/dist/web/public/icons/{radar.svg → icon.svg} +0 -0
@@ -176,7 +176,7 @@ export async function runSessionEnable(timeoutMinutes, deviceSerial, deps) {
176
176
  return outcome;
177
177
  }
178
178
  async function enableSession(timeoutMinutes, deviceSerial, deps) {
179
- const { device, destroyStream, connectStream, isStreamConnected, wasStreamRejected, resetDbState, startSpool, runBackfill, ping, sleep, onDeviceSwitch, } = deps;
179
+ const { device, destroyStream, connectStream, isStreamConnected, wasStreamRejected, resetDbState, startSpool, runBackfill, ping, sleep, onDeviceSwitch, surface = "mcp", } = deps;
180
180
  // Tear down the old stream (and its reconnect loop) FIRST, then drop all cached
181
181
  // transport state so this enable starts clean. Without the reset, a stale adb
182
182
  // forward (device end dead after an idle timeout or a replug) makes ensureForward()
@@ -200,7 +200,9 @@ async function enableSession(timeoutMinutes, deviceSerial, deps) {
200
200
  enabled: false,
201
201
  body: {
202
202
  // The transport error is a neutral core; the MCP body appends agent-facing retry guidance.
203
- error: `${selection.error} Retry _radar_session_enable with device_serial set to one of them. If you cannot tell which device the user wants, ask them before retrying.`,
203
+ error: surface === "cli"
204
+ ? selection.error
205
+ : `${selection.error} Retry _radar_session_enable with device_serial set to one of them. If you cannot tell which device the user wants, ask them before retrying.`,
204
206
  devices: selection.devices,
205
207
  enabled: false,
206
208
  platform: device.platform,
@@ -267,7 +269,7 @@ async function enableSession(timeoutMinutes, deviceSerial, deps) {
267
269
  if (tokenFileError) {
268
270
  return {
269
271
  enabled: false,
270
- body: { error: tokenFileMessage(tokenFileError, "mcp"), enabled: false, platform: device.platform },
272
+ body: { error: tokenFileMessage(tokenFileError, surface), enabled: false, platform: device.platform },
271
273
  };
272
274
  }
273
275
  const activateError = device.getLastActivateError?.() ?? null;
@@ -309,7 +311,7 @@ async function enableSession(timeoutMinutes, deviceSerial, deps) {
309
311
  enabled: false,
310
312
  body: {
311
313
  error: device.getLastActivateBareError?.() ? activateError : error instanceof PingRefused
312
- ? `Radar activation broadcast failed: ${activateError}. ${unauthorizedMessageFor(device)}`
314
+ ? `Radar activation broadcast failed: ${activateError}. ${unauthorizedMessageFor(device, surface)}`
313
315
  : device.radarListenerHint
314
316
  ? `Radar activation failed: ${activateError}. ${device.radarListenerHint}`
315
317
  : `Radar activation broadcast failed: ${activateError}. Is the device connected? Check adb devices.`,
@@ -383,7 +385,7 @@ async function enableSession(timeoutMinutes, deviceSerial, deps) {
383
385
  return {
384
386
  enabled: false,
385
387
  body: {
386
- error: unauthorizedMessageFor(device),
388
+ error: unauthorizedMessageFor(device, surface),
387
389
  enabled: false,
388
390
  platform: device.platform,
389
391
  ...tokenViaArgvField(device),
@@ -417,7 +419,7 @@ async function enableSession(timeoutMinutes, deviceSerial, deps) {
417
419
  else if (!isStreamConnected())
418
420
  connectStream();
419
421
  // A tokened enable that stays open did not take, so name its broadcast failure.
420
- const openModeWarning = openModeWarningAfterEnable(status.token_required, activateError);
422
+ const openModeWarning = openModeWarningAfterEnable(status.token_required, activateError, surface);
421
423
  return {
422
424
  enabled: true,
423
425
  body: {
@@ -0,0 +1,52 @@
1
+ import type { DeviceTransport } from "../shared/transport.js";
2
+ import { type RadarResponse } from "./radar-response.js";
3
+ import { type EnableOutcome } from "./session-enable.js";
4
+ import { type SnapshotOptions, type SnapshotResult } from "./snapshot.js";
5
+ export declare const SNAPSHOT_USAGE = "Usage: radar-mcp snapshot [options]\n\nSave a Radar snapshot without an MCP client. Run it with --start when a test run\nbegins and without --start when it ends.\n\nAndroid only: it needs adb and a debug build on a device or emulator. Other platforms are\nnot supported.\n\nOptions:\n --serial <id> Device to use (default: the only attached device)\n --out <dir> Directory to write the snapshot under (default: ~/.slack-radar/snapshots)\n --start Only record the start of a run; no snapshot is written\n --since <epoch-ms> Keep events from this time on. Device clock, the same clock as the\n since_ms that --start prints. Beats the start marker\n --detail-url <text> Also keep the details of calls whose URL contains this text\n (repeatable); failed calls are always kept\n --timeout-minutes <n> How long Radar stays on with no calls, 1-1440 (default 60)\n --no-redact Keep tokens and auth headers as the device sent them\n --help Show this text\n\nEach run forwards its own free host port; set SLACK_RADAR_DEVICE_PORT to pin a fixed one.\n\nPrints one JSON line on stdout. Exit codes: 0 done, 1 failed, 2 bad usage.\n";
6
+ export interface SnapshotCliArgs {
7
+ serial: string | null;
8
+ out: string | null;
9
+ start: boolean;
10
+ since: number | null;
11
+ detailUrls: string[];
12
+ timeoutMinutes: number;
13
+ redact: boolean;
14
+ }
15
+ export type ParsedSnapshotArgs = {
16
+ kind: "run";
17
+ args: SnapshotCliArgs;
18
+ } | {
19
+ kind: "help";
20
+ } | {
21
+ kind: "usage";
22
+ message: string;
23
+ };
24
+ export declare function parseSnapshotArgs(argv: string[]): ParsedSnapshotArgs;
25
+ /** Serial reduced to characters that are safe in a file name. */
26
+ export declare function markerFileName(serial: string | null): string;
27
+ export declare function markerPath(homeDir: string, serial: string | null): string;
28
+ export declare function writeStartMarker(homeDir: string, serial: string | null, sinceMs: number): string;
29
+ export declare function readStartMarker(homeDir: string, serial: string | null): {
30
+ since_ms: number;
31
+ ageMs: number;
32
+ file: string;
33
+ } | null;
34
+ export interface SnapshotCliDeps {
35
+ device: DeviceTransport;
36
+ enable: (timeoutMinutes: number, serial: string | null) => Promise<EnableOutcome>;
37
+ fetchJson: (path: string) => Promise<unknown>;
38
+ snapshot: (device: DeviceTransport, fetchJson: (path: string) => Promise<unknown>, opts: SnapshotOptions, now: number, root?: string) => Promise<SnapshotResult>;
39
+ now: () => number;
40
+ homeDir: string;
41
+ stdout: (text: string) => void;
42
+ stderr: (text: string) => void;
43
+ }
44
+ /**
45
+ * GET helper for the snapshot reads. The forwarded port is host-wide and a dashboard or another
46
+ * run can repoint it, so it is pointed at this device again before every read.
47
+ */
48
+ export declare function cliFetchJson(device: DeviceTransport, send: (apiPath: string) => Promise<RadarResponse>): (apiPath: string) => Promise<unknown>;
49
+ /** Runs the command and returns the exit code. Prints exactly one JSON line for exit 0 and 1. */
50
+ export declare function runSnapshotCli(argv: string[], deps?: SnapshotCliDeps): Promise<number>;
51
+ /** Entry for index.ts: run, then exit so no adb child keeps the process alive. */
52
+ export declare function snapshotCliMain(argv: string[]): Promise<never>;
@@ -0,0 +1,331 @@
1
+ /**
2
+ * `radar-mcp snapshot`: a headless front door for a test run. It arms Radar, then calls the
3
+ * same composer `capture_snapshot` uses and prints one JSON line. Runs before the MCP server
4
+ * starts, so there is no stdio session and no mcp-seen marker.
5
+ *
6
+ * Two uses:
7
+ * radar-mcp snapshot --start at the start of a run: remember the device clock
8
+ * radar-mcp snapshot [--out <dir>] at the end: bundle only what happened since
9
+ */
10
+ import fs from "fs";
11
+ import os from "os";
12
+ import path from "path";
13
+ import { AndroidTransport } from "../shared/android.js";
14
+ import { RADAR_HOST, RADAR_PORT } from "../shared/constants.js";
15
+ import { radarHttpRequest } from "./radar-http.js";
16
+ import { unauthorizedResponse } from "./radar-response.js";
17
+ import { runSessionEnable } from "./session-enable.js";
18
+ import { createSnapshot } from "./snapshot.js";
19
+ const DEFAULT_TIMEOUT_MINUTES = 60;
20
+ const SNAPSHOT_LOG_LINES = 5000;
21
+ const RESTART_SLACK_MS = 2000;
22
+ const STALE_MARKER_MS = 24 * 60 * 60 * 1000;
23
+ export const SNAPSHOT_USAGE = `Usage: radar-mcp snapshot [options]
24
+
25
+ Save a Radar snapshot without an MCP client. Run it with --start when a test run
26
+ begins and without --start when it ends.
27
+
28
+ Android only: it needs adb and a debug build on a device or emulator. Other platforms are
29
+ not supported.
30
+
31
+ Options:
32
+ --serial <id> Device to use (default: the only attached device)
33
+ --out <dir> Directory to write the snapshot under (default: ~/.slack-radar/snapshots)
34
+ --start Only record the start of a run; no snapshot is written
35
+ --since <epoch-ms> Keep events from this time on. Device clock, the same clock as the
36
+ since_ms that --start prints. Beats the start marker
37
+ --detail-url <text> Also keep the details of calls whose URL contains this text
38
+ (repeatable); failed calls are always kept
39
+ --timeout-minutes <n> How long Radar stays on with no calls, 1-1440 (default ${DEFAULT_TIMEOUT_MINUTES})
40
+ --no-redact Keep tokens and auth headers as the device sent them
41
+ --help Show this text
42
+
43
+ Each run forwards its own free host port; set SLACK_RADAR_DEVICE_PORT to pin a fixed one.
44
+
45
+ Prints one JSON line on stdout. Exit codes: 0 done, 1 failed, 2 bad usage.
46
+ `;
47
+ export function parseSnapshotArgs(argv) {
48
+ const args = {
49
+ serial: null,
50
+ out: null,
51
+ start: false,
52
+ since: null,
53
+ detailUrls: [],
54
+ timeoutMinutes: DEFAULT_TIMEOUT_MINUTES,
55
+ redact: true,
56
+ };
57
+ const usage = (message) => ({ kind: "usage", message });
58
+ for (let i = 0; i < argv.length; i++) {
59
+ const flag = argv[i];
60
+ const value = () => {
61
+ const v = argv[i + 1];
62
+ if (v === undefined || v.startsWith("--"))
63
+ return null;
64
+ i++;
65
+ return v;
66
+ };
67
+ // The value of a flag that must have one, or the usage error to return.
68
+ const need = () => value() || usage(`${flag} needs a value`);
69
+ switch (flag) {
70
+ case "--help":
71
+ case "-h":
72
+ return { kind: "help" };
73
+ case "--start":
74
+ args.start = true;
75
+ break;
76
+ case "--no-redact":
77
+ args.redact = false;
78
+ break;
79
+ case "--serial": {
80
+ const v = need();
81
+ if (typeof v !== "string")
82
+ return v;
83
+ args.serial = v;
84
+ break;
85
+ }
86
+ case "--out": {
87
+ const v = need();
88
+ if (typeof v !== "string")
89
+ return v;
90
+ args.out = v;
91
+ break;
92
+ }
93
+ case "--detail-url": {
94
+ const v = need();
95
+ if (typeof v !== "string")
96
+ return v;
97
+ args.detailUrls.push(v);
98
+ break;
99
+ }
100
+ case "--since": {
101
+ const v = value();
102
+ if (v === null || !/^\d+$/.test(v))
103
+ return usage("--since needs a device epoch in milliseconds");
104
+ args.since = Number(v);
105
+ break;
106
+ }
107
+ case "--timeout-minutes": {
108
+ const v = value();
109
+ const n = v !== null && /^\d+$/.test(v) ? Number(v) : NaN;
110
+ if (!(n >= 1 && n <= 1440))
111
+ return usage("--timeout-minutes needs a whole number from 1 to 1440");
112
+ args.timeoutMinutes = n;
113
+ break;
114
+ }
115
+ default:
116
+ return usage(`unknown option ${flag}`);
117
+ }
118
+ }
119
+ if (args.start && (args.since !== null || args.out !== null || args.detailUrls.length > 0)) {
120
+ return usage("--start cannot be combined with --since, --out or --detail-url");
121
+ }
122
+ return { kind: "run", args };
123
+ }
124
+ // --- start marker ---
125
+ /** Serial reduced to characters that are safe in a file name. */
126
+ export function markerFileName(serial) {
127
+ const safe = (serial ?? "").replace(/[^A-Za-z0-9._:-]/g, "_");
128
+ return `${safe === "" ? "default" : safe}.json`;
129
+ }
130
+ export function markerPath(homeDir, serial) {
131
+ return path.join(homeDir, ".slack-radar", "snapshot-starts", markerFileName(serial));
132
+ }
133
+ export function writeStartMarker(homeDir, serial, sinceMs) {
134
+ const file = markerPath(homeDir, serial);
135
+ const dir = path.dirname(file);
136
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
137
+ // mkdir only sets the mode on directories it creates.
138
+ fs.chmodSync(dir, 0o700);
139
+ fs.writeFileSync(file, JSON.stringify({ since_ms: sinceMs, serial }), { mode: 0o600 });
140
+ fs.chmodSync(file, 0o600);
141
+ return file;
142
+ }
143
+ export function readStartMarker(homeDir, serial) {
144
+ const file = markerPath(homeDir, serial);
145
+ try {
146
+ const parsed = JSON.parse(fs.readFileSync(file, "utf-8"));
147
+ if (typeof parsed.since_ms !== "number" || !Number.isFinite(parsed.since_ms))
148
+ return null;
149
+ return { since_ms: parsed.since_ms, ageMs: Date.now() - fs.statSync(file).mtimeMs, file };
150
+ }
151
+ catch {
152
+ return null;
153
+ }
154
+ }
155
+ /**
156
+ * GET helper for the snapshot reads. The forwarded port is host-wide and a dashboard or another
157
+ * run can repoint it, so it is pointed at this device again before every read.
158
+ */
159
+ export function cliFetchJson(device, send) {
160
+ return async (apiPath) => {
161
+ const forwarded = device.reassertForward?.() ?? device.ensureForward();
162
+ if (!forwarded) {
163
+ throw new Error(`port forward to ${device.getSelectedDevice?.()?.serial ?? "the device"} failed`);
164
+ }
165
+ const checked = unauthorizedResponse(await send(apiPath), device, "cli");
166
+ if (checked.error)
167
+ throw new Error(checked.error);
168
+ return checked;
169
+ };
170
+ }
171
+ function defaultDeps() {
172
+ const device = new AndroidTransport({ ownForwardPort: true });
173
+ const ping = () => radarHttpRequest({
174
+ host: RADAR_HOST,
175
+ port: RADAR_PORT,
176
+ path: "/api/ping",
177
+ timeoutMs: 2000,
178
+ deadlineMs: Date.now() + 2000,
179
+ transport: device,
180
+ });
181
+ const enableDeps = {
182
+ device,
183
+ // No MCP session here, so nothing streams, spools or backfills.
184
+ destroyStream: () => { },
185
+ connectStream: () => { },
186
+ isStreamConnected: () => false,
187
+ wasStreamRejected: () => false,
188
+ resetDbState: () => { },
189
+ startSpool: () => { },
190
+ runBackfill: async () => { },
191
+ onDeviceSwitch: () => { },
192
+ ping,
193
+ surface: "cli",
194
+ sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
195
+ };
196
+ return {
197
+ device,
198
+ enable: (timeout, serial) => runSessionEnable(timeout, serial, enableDeps),
199
+ fetchJson: cliFetchJson(device, (apiPath) => radarHttpRequest({ host: RADAR_HOST, port: RADAR_PORT, path: apiPath, transport: device })),
200
+ snapshot: createSnapshot,
201
+ now: () => Date.now(),
202
+ homeDir: os.homedir(),
203
+ stdout: (t) => process.stdout.write(t),
204
+ stderr: (t) => process.stderr.write(t),
205
+ };
206
+ }
207
+ function iso(ms) {
208
+ return new Date(ms).toISOString();
209
+ }
210
+ /** Runs the command and returns the exit code. Prints exactly one JSON line for exit 0 and 1. */
211
+ export async function runSnapshotCli(argv, deps = defaultDeps()) {
212
+ const parsed = parseSnapshotArgs(argv);
213
+ if (parsed.kind === "help") {
214
+ deps.stdout(SNAPSHOT_USAGE);
215
+ return 0;
216
+ }
217
+ if (parsed.kind === "usage") {
218
+ deps.stderr(`${parsed.message}\n\n${SNAPSHOT_USAGE}`);
219
+ return 2;
220
+ }
221
+ const { args } = parsed;
222
+ const { device } = deps;
223
+ const warnings = [];
224
+ const fail = (message) => {
225
+ deps.stderr(`${message}\n`);
226
+ deps.stdout(`${JSON.stringify({ error: message, warnings })}\n`);
227
+ return 1;
228
+ };
229
+ // The log capture's own signal handlers call process.exit, which skips the finally below.
230
+ // Our handlers exit with the same codes, so the exit hook always gets to drop the forward.
231
+ const onExit = () => device.releaseForward?.();
232
+ const onSigint = () => process.exit(130);
233
+ const onSigterm = () => process.exit(143);
234
+ process.once("exit", onExit);
235
+ process.on("SIGINT", onSigint);
236
+ process.on("SIGTERM", onSigterm);
237
+ try {
238
+ const outcome = await deps.enable(args.timeoutMinutes, args.serial);
239
+ if (!outcome.enabled) {
240
+ return fail(typeof outcome.body.error === "string" ? outcome.body.error : "Radar did not start on the device");
241
+ }
242
+ // The enable picked the device; key the start marker by it so --start and the end agree.
243
+ const serial = device.getSelectedDevice?.()?.serial ?? args.serial;
244
+ const warning = outcome.body.warning;
245
+ if (typeof warning === "string")
246
+ warnings.push(warning);
247
+ const viaArgv = outcome.body.token_via_argv;
248
+ if (typeof viaArgv === "string") {
249
+ warnings.push(`the Radar token was sent on the adb command line because ${viaArgv}`);
250
+ }
251
+ for (const w of warnings)
252
+ deps.stderr(`warning: ${w}\n`);
253
+ // The enable starts a log capture that has seconds of lines at most. Stop it so the
254
+ // composer reads the device log instead.
255
+ device.stopLogCapture?.();
256
+ device.reassertForward?.();
257
+ if (args.start) {
258
+ const sinceMs = device.deviceClockMs?.() ?? null;
259
+ if (sinceMs === null)
260
+ return fail("could not read the device clock over adb");
261
+ const file = writeStartMarker(deps.homeDir, serial, sinceMs);
262
+ deps.stdout(`${JSON.stringify({ started: true, since_ms: sinceMs, serial, marker_path: file, warnings })}\n`);
263
+ return 0;
264
+ }
265
+ const marker = args.since === null ? readStartMarker(deps.homeDir, serial) : null;
266
+ const since = args.since ?? marker?.since_ms ?? null;
267
+ const untilMs = device.deviceClockMs?.() ?? null;
268
+ const notes = [];
269
+ const uptime = outcome.body.uptime_ms;
270
+ if (since !== null && untilMs !== null && typeof uptime === "number") {
271
+ const radarStart = untilMs - uptime;
272
+ // since comes from whole device seconds, so allow a little rounding before calling it a restart.
273
+ if (radarStart > since + RESTART_SLACK_MS) {
274
+ notes.push(`Radar restarted during the run: network, RTM and voice sessions before ${iso(radarStart)} are gone`);
275
+ }
276
+ }
277
+ if (marker && marker.ageMs > STALE_MARKER_MS) {
278
+ notes.push("The start marker is more than 24 hours old; it may be left from an earlier run");
279
+ }
280
+ const result = await deps.snapshot(device, deps.fetchJson, {
281
+ since,
282
+ windowSource: args.since !== null ? "since_flag" : "start_marker",
283
+ untilMs,
284
+ redact: args.redact,
285
+ logSource: "device",
286
+ // A crash can be older than the default 500 lines; this stays under the 10000 maximum.
287
+ logTailLines: SNAPSHOT_LOG_LINES,
288
+ notes,
289
+ detailUrls: args.detailUrls,
290
+ }, deps.now(), args.out ?? undefined);
291
+ // The marker goes only once the summary is written. A failed delete is a warning, not a failure.
292
+ if (marker && result.summary_path) {
293
+ try {
294
+ fs.rmSync(marker.file, { force: true });
295
+ }
296
+ catch (e) {
297
+ const w = `could not delete the start marker ${marker.file}: ${e.message}`;
298
+ warnings.push(w);
299
+ deps.stderr(`warning: ${w}\n`);
300
+ }
301
+ }
302
+ deps.stdout(`${JSON.stringify({
303
+ path: result.path,
304
+ zip_path: result.zip_path,
305
+ summary_path: result.summary_path,
306
+ counts: result.counts,
307
+ run_window: result.run_window,
308
+ redacted: result.redacted,
309
+ warnings,
310
+ errors: result.errors,
311
+ privacy_notice: result.privacy_notice,
312
+ })}\n`);
313
+ return result.summary_path ? 0 : 1;
314
+ }
315
+ catch (e) {
316
+ return fail(`snapshot failed: ${e.message}`);
317
+ }
318
+ finally {
319
+ // Release first, so a throwing stopLogCapture cannot skip it.
320
+ device.releaseForward?.();
321
+ process.off("exit", onExit);
322
+ process.off("SIGINT", onSigint);
323
+ process.off("SIGTERM", onSigterm);
324
+ device.stopLogCapture?.();
325
+ }
326
+ }
327
+ /** Entry for index.ts: run, then exit so no adb child keeps the process alive. */
328
+ export async function snapshotCliMain(argv) {
329
+ const code = await runSnapshotCli(argv);
330
+ process.exit(code);
331
+ }
@@ -0,0 +1 @@
1
+ export declare function buildSnapshotSummary(bundle: unknown, logText: string): string;