@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
@@ -18,15 +18,32 @@ export function friendlyFeatureFlagError(error) {
18
18
  return error;
19
19
  }
20
20
  /**
21
- * The one sentence for a flag whose latest value differs from what the app runs. A flag the app
22
- * read once keeps that value until restart, so `enabled` (latest or override) can differ from
23
- * `session_enabled`. Only two real booleans that differ earn a note: an absent or non-boolean
24
- * session_enabled is "not known", and saying nothing there is the honest answer.
21
+ * The sentence (`note`) and the short tab text (`label`) for a flag whose latest value differs from
22
+ * what the app runs. An experiment's label names the group itself, since a group has no ON/OFF to
23
+ * flip. A flag the app read once keeps that value until restart, so the latest value (`enabled` on a toggle,
24
+ * `group_name` on an experiment; fetched or override) can differ from the session value
25
+ * (`session_enabled`, `session_group_name`). Only two real values of
26
+ * the right type that differ earn a note: an absent or mistyped session value is "not known", and
27
+ * saying nothing there is the honest answer. An experiment's "" is a read that found no group, and
28
+ * its note is hedged because read-once code may still use the session group, not that it must.
25
29
  */
26
30
  export function flagRestartNote(row) {
31
+ const source = row.is_overridden === true ? "override" : "fetched";
32
+ const { group_name: group, session_group_name: sessionGroup } = row;
33
+ if (typeof group === "string" && typeof sessionGroup === "string") {
34
+ if (group === sessionGroup)
35
+ return undefined;
36
+ const used = sessionGroup || "no group";
37
+ return {
38
+ note: `read-once code may still use ${used} until restart, ${source} ${group || "no group"}`,
39
+ label: `read-once may use ${used}`,
40
+ };
41
+ }
27
42
  const { enabled, session_enabled: session } = row;
28
43
  if (typeof enabled !== "boolean" || typeof session !== "boolean" || enabled === session)
29
44
  return undefined;
30
- const source = row.is_overridden === true ? "override" : "fetched";
31
- return `app uses ${session} until restart, ${source} ${enabled}`;
45
+ return {
46
+ note: `app uses ${session} until restart, ${source} ${enabled}`,
47
+ label: `runs ${session ? "ON" : "OFF"} until restart`,
48
+ };
32
49
  }
@@ -1,6 +1,6 @@
1
1
  import type { DeviceTransport } from "./transport.js";
2
2
  export declare const RADAR_TOKEN_HEADER = "X-Radar-Token";
3
- export type TokenSurface = "mcp" | "dashboard";
3
+ export type TokenSurface = "mcp" | "dashboard" | "cli";
4
4
  export type TokenFileSurface = TokenSurface | "profile";
5
5
  export declare class TokenFileError extends Error {
6
6
  readonly problem: string;
@@ -12,14 +12,14 @@ export declare function getOrCreateRadarToken(): string;
12
12
  export declare function clearRadarTokenCache(): void;
13
13
  export declare function radarTokenHeader(): Record<string, string>;
14
14
  export type RadarTokenSender = Pick<DeviceTransport, "sendsRadarToken"> | null | undefined;
15
- export declare const TOKEN_MISMATCH_MESSAGE = "The device holds a different token than this session's. Check these, then run /radar-enable here. Another machine or OS user enabled Radar on this device: stop that session. Radar was enabled in a different profile: make sure the Slack debug build runs in the profile you want (list_profiles shows which profiles have it). Another Radar session on this machine still uses a token file you deleted: run /radar-enable there too.";
15
+ export declare const TOKEN_MISMATCH_MESSAGE: string;
16
16
  export declare const TOKEN_MISMATCH_DASHBOARD_MESSAGE = "This device answered to a different Radar token. Stop any other Radar session using it, or run /radar-enable there if you deleted the token file, then press Reconnect.";
17
17
  export declare const DEVICE_401_MESSAGE = "The device refused the request (HTTP 401). Run /radar-enable to try again.";
18
18
  export declare const DEVICE_401_DASHBOARD_MESSAGE = "The device refused the request (HTTP 401). Press Reconnect to try again.";
19
19
  export declare function lastHeaderBuildFailure(): TokenFileError | null;
20
20
  export declare function unauthorizedMessageFor(sender: RadarTokenSender, surface?: TokenSurface): string;
21
21
  export declare function radarTokenHeaderFor(transport: RadarTokenSender, surface?: TokenSurface): Record<string, string>;
22
- export declare const OPEN_MODE_WARNING = "The device is in open mode, so anything that reaches the forwarded port can read and change its Radar data. An older Radar MCP or dashboard, or a manual enable broadcast, turned the token check off. If an older Radar MCP or dashboard is still running, stop it, then run /radar-enable.";
22
+ export declare const OPEN_MODE_WARNING: string;
23
23
  export declare const OPEN_MODE_PROFILE_WARNING = "The device is in open mode even though this enable sent the token, so the broadcast did not reach the server that answered: it likely runs in a different profile and was enabled without a token. Anything that reaches the forwarded port can read and change its Radar data. Run list_profiles, then activate_for_user for the profile you want, or stop the older Radar MCP or dashboard that enabled it.";
24
- export declare function openModeWarning(tokenRequired: unknown): string | undefined;
25
- export declare function openModeWarningAfterEnable(tokenRequired: unknown, activateError: string | null): string | undefined;
24
+ export declare function openModeWarning(tokenRequired: unknown, surface?: TokenSurface): string | undefined;
25
+ export declare function openModeWarningAfterEnable(tokenRequired: unknown, activateError: string | null, surface?: TokenSurface): string | undefined;
@@ -24,9 +24,17 @@ export class TokenFileError extends Error {
24
24
  }
25
25
  }
26
26
  export function tokenFileMessage(error, surface = "mcp") {
27
- const act = surface === "dashboard" ? "press Reconnect" : surface === "profile" ? "run activate_for_user again" : "run /radar-enable";
27
+ const act = surface === "dashboard"
28
+ ? "press Reconnect"
29
+ : surface === "profile"
30
+ ? "run activate_for_user again"
31
+ : `run ${enableCommand(surface)}`;
28
32
  return `${error.problem}. ${error.fix}, then ${act}.`;
29
33
  }
34
+ /** What the user types to arm Radar again on a surface. */
35
+ function enableCommand(surface) {
36
+ return surface === "cli" ? "radar-mcp snapshot" : "/radar-enable";
37
+ }
30
38
  let cachedToken = null;
31
39
  function code(error) {
32
40
  return error?.code;
@@ -108,11 +116,12 @@ export function radarTokenHeader() {
108
116
  return { [RADAR_TOKEN_HEADER]: getOrCreateRadarToken() };
109
117
  }
110
118
  const PROFILE_FIX = "make sure the Slack debug build runs in the profile you want (list_profiles shows which profiles have it)";
111
- const MISMATCH_TAIL = `Check these, then run /radar-enable here. Another machine or OS user enabled Radar on this device: stop that session. Radar was enabled in a different profile: ${PROFILE_FIX}. Another Radar session on this machine still uses a token file you deleted: run /radar-enable there too.`;
119
+ const mismatchTail = (cmd) => `Check these, then run ${cmd} here. Another machine or OS user enabled Radar on this device: stop that session. Radar was enabled in a different profile: ${PROFILE_FIX}. Another Radar session on this machine still uses a token file you deleted: run ${cmd} there too.`;
112
120
  const DASHBOARD_TAIL = "Stop any other Radar session using it, or run /radar-enable there if you deleted the token file, then press Reconnect.";
113
- export const TOKEN_MISMATCH_MESSAGE = `The device holds a different token than this session's. ${MISMATCH_TAIL}`;
121
+ export const TOKEN_MISMATCH_MESSAGE = `The device holds a different token than this session's. ${mismatchTail("/radar-enable")}`;
114
122
  export const TOKEN_MISMATCH_DASHBOARD_MESSAGE = `This device answered to a different Radar token. ${DASHBOARD_TAIL}`;
115
123
  export const DEVICE_401_MESSAGE = "The device refused the request (HTTP 401). Run /radar-enable to try again.";
124
+ const DEVICE_401_CLI_MESSAGE = "The device refused the request (HTTP 401). Run radar-mcp snapshot to try again.";
116
125
  export const DEVICE_401_DASHBOARD_MESSAGE = "The device refused the request (HTTP 401). Press Reconnect to try again.";
117
126
  export function lastHeaderBuildFailure() {
118
127
  return lastHeaderFailure;
@@ -121,9 +130,13 @@ export function unauthorizedMessageFor(sender, surface = "mcp") {
121
130
  if (sender?.sendsRadarToken) {
122
131
  if (lastHeaderFailure)
123
132
  return tokenFileMessage(lastHeaderFailure, surface);
124
- return surface === "dashboard" ? TOKEN_MISMATCH_DASHBOARD_MESSAGE : TOKEN_MISMATCH_MESSAGE;
133
+ if (surface === "dashboard")
134
+ return TOKEN_MISMATCH_DASHBOARD_MESSAGE;
135
+ return surface === "cli"
136
+ ? `The device holds a different token than this session's. ${mismatchTail(enableCommand(surface))}`
137
+ : TOKEN_MISMATCH_MESSAGE;
125
138
  }
126
- return surface === "dashboard" ? DEVICE_401_DASHBOARD_MESSAGE : DEVICE_401_MESSAGE;
139
+ return surface === "dashboard" ? DEVICE_401_DASHBOARD_MESSAGE : surface === "cli" ? DEVICE_401_CLI_MESSAGE : DEVICE_401_MESSAGE;
127
140
  }
128
141
  // Never throws: an empty header lets the request go out so an open-mode device can answer.
129
142
  export function radarTokenHeaderFor(transport, surface = "mcp") {
@@ -150,15 +163,16 @@ export function radarTokenHeaderFor(transport, surface = "mcp") {
150
163
  return {};
151
164
  }
152
165
  }
153
- export const OPEN_MODE_WARNING = "The device is in open mode, so anything that reaches the forwarded port can read and change its Radar data. An older Radar MCP or dashboard, or a manual enable broadcast, turned the token check off. If an older Radar MCP or dashboard is still running, stop it, then run /radar-enable.";
166
+ const openModeText = (cmd) => `The device is in open mode, so anything that reaches the forwarded port can read and change its Radar data. An older Radar MCP or dashboard, or a manual enable broadcast, turned the token check off. If an older Radar MCP or dashboard is still running, stop it, then run ${cmd}.`;
167
+ export const OPEN_MODE_WARNING = openModeText("/radar-enable");
154
168
  export const OPEN_MODE_PROFILE_WARNING = "The device is in open mode even though this enable sent the token, so the broadcast did not reach the server that answered: it likely runs in a different profile and was enabled without a token. Anything that reaches the forwarded port can read and change its Radar data. Run list_profiles, then activate_for_user for the profile you want, or stop the older Radar MCP or dashboard that enabled it.";
155
- export function openModeWarning(tokenRequired) {
156
- return tokenRequired === false ? OPEN_MODE_WARNING : undefined;
169
+ export function openModeWarning(tokenRequired, surface = "mcp") {
170
+ return tokenRequired === false ? openModeText(enableCommand(surface)) : undefined;
157
171
  }
158
- export function openModeWarningAfterEnable(tokenRequired, activateError) {
172
+ export function openModeWarningAfterEnable(tokenRequired, activateError, surface = "mcp") {
159
173
  if (tokenRequired !== false)
160
174
  return undefined;
161
175
  return activateError
162
- ? `The device is in open mode: this enable's broadcast failed (${activateError}) and a server enabled without a token answered instead. Anything that reaches the forwarded port can read and change its Radar data. Check the device connection, then run /radar-enable.`
176
+ ? `The device is in open mode: this enable's broadcast failed (${activateError}) and a server enabled without a token answered instead. Anything that reaches the forwarded port can read and change its Radar data. Check the device connection, then run ${enableCommand(surface)}.`
163
177
  : OPEN_MODE_PROFILE_WARNING;
164
178
  }
@@ -67,7 +67,8 @@ export const SAVED_TURN_OUTCOMES = [...Object.keys(SAVED_TURN_KEPT), ...SAVED_TU
67
67
  // A card record in words, shared by the feed row, the voice panel and the report. A kind or event
68
68
  // the device adds later shows as sent, and a missing field reads "?", so nothing throws.
69
69
  const CARD_KIND_WORDS = { tool_approval: "tool approval", auth_prompt: "connect prompt" };
70
- // An event in this set takes the card down; "shown" and "carried" put it up.
70
+ // An event in this set takes the card down; "shown" and "carried" put it up. "answer_failed" is in
71
+ // neither: the card stays as it was.
71
72
  const CARD_CLOSING_EVENTS = ["answered", "refused", "declined", "closed", "replaced", "expired", "cleared"];
72
73
  const CARD_OPENING_EVENTS = ["shown", "carried"];
73
74
  export function cardKindWord(kind) {
@@ -121,6 +121,9 @@ function recordLine(r) {
121
121
  parts.push(`gap ${gap} ms`);
122
122
  if (queued !== null)
123
123
  parts.push(`${queued} B queued`);
124
+ const dropped = num(r.dropped_chunks);
125
+ if (dropped !== null)
126
+ parts.push(`dropped ${dropped} mic chunk${dropped === 1 ? "" : "s"}`);
124
127
  return `${head} ${parts.join(", ")}`;
125
128
  }
126
129
  case "levels": {
@@ -264,7 +267,7 @@ export function buildSwitchboardReport(assembly, now = Date.now()) {
264
267
  const up = openCards(events).map((c) => `${stripSwitchboardControlChars(c.kind)} ${stripSwitchboardControlChars(c.id)}`);
265
268
  // A card shown in a record this report lacks looks closed or never up, so say so.
266
269
  const partial = !holdsEveryRecord;
267
- const note = partial ? "shown or carried with no later record, among the records this report holds" : "shown or carried with no later record";
270
+ const note = partial ? "shown or carried and not taken down since, among the records this report holds" : "shown or carried and not taken down since";
268
271
  lines.push(`cards_open: ${up.length ? `${up.join(", ")} (${note})` : partial ? "none seen (the report does not hold every record)" : "none"}`);
269
272
  }
270
273
  lines.push(`team_id: ${teamId ?? "(none)"}`);
@@ -0,0 +1,15 @@
1
+ export interface CapturedRecord {
2
+ id: number;
3
+ direction?: unknown;
4
+ data?: unknown;
5
+ is_base64?: unknown;
6
+ }
7
+ export interface Capture {
8
+ events: Record<string, unknown>[];
9
+ kept: Record<string, number>;
10
+ dropped: Record<string, number>;
11
+ seeded: boolean;
12
+ targets: number;
13
+ removed: Record<string, number>;
14
+ }
15
+ export declare function captureCase(records: CapturedRecord[]): Capture;
@@ -0,0 +1,235 @@
1
+ import { BUILTIN_SEED, pairLabel } from "./test-case-store.js";
2
+ const TEST_USER = "UZRDR0000001";
3
+ const CHANNEL = "{{test_channel}}";
4
+ const SEQ_TS = "{{seq_ts}}";
5
+ const FRAME_TS = "{{frame_ts}}";
6
+ const SEQ_UUID = "{{seq_uuid}}";
7
+ const PAIRS = new Set(["message", "message.message_changed", "message.message_replied"]);
8
+ const SAFE_WORD = /^[a-z_]+$/;
9
+ const SAFE_MIME = /^[\w.+/-]*$/;
10
+ const MESSAGE_KEYS = ["type", "subtype", "channel", "ts", "thread_ts", "user", "client_msg_id", "text", "blocks", "files", "reply_count", "replies", "hidden"];
11
+ const isObj = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
12
+ const bump = (counts, key) => { counts[key] = (counts[key] ?? 0) + 1; };
13
+ // Plain ASCII of the same byte length, so sizes survive and no real text does.
14
+ function filler(original) {
15
+ const bytes = Buffer.byteLength(original);
16
+ return "made up replay text ".repeat(Math.ceil(bytes / 20)).slice(0, bytes);
17
+ }
18
+ // Only fields that shape how a block renders survive; anything else (urls aside, ids, counts)
19
+ // could be real, so an unknown key is removed rather than scrubbed. Fields the app needs to parse
20
+ // a block or chunk stay with made-up values: image sizes as 1, mention ids as test ids, and a
21
+ // fixed date and color.
22
+ const BLOCK_KEYS = new Set(["type", "block_id", "elements", "text", "style", "indent", "border", "offset", "user_id", "channel_id", "name", "url", "image_url", "alt_text", "image_height", "image_width", "image_bytes", "range", "usergroup_id", "team_id", "timestamp", "format", "fallback", "value", "fields", "accessory", "action_id", "bold", "italic", "strike", "code"]);
23
+ const BLOCK_NUMBERS = new Set(["indent", "border", "offset"]);
24
+ // the app needs these on an image block, but a real size says something about the image
25
+ const BLOCK_SIZES = new Set(["image_height", "image_width", "image_bytes"]);
26
+ // rich text chunks the app needs whole: each value is fixed, a filler, or one of a few known words
27
+ const BROADCAST_RANGES = new Set(["here", "channel", "everyone"]);
28
+ const FIXED_STRINGS = { usergroup_id: "SZRDR0000001", team_id: "TZRDR0000001", format: "{date_short}", value: "#000000" };
29
+ const BLOCK_FLAGS = new Set(["bold", "italic", "strike", "code"]);
30
+ // removed counts the keys left out, by name, so the caller can say what a saved case lacks
31
+ function walk(value, key, removed) {
32
+ if (Array.isArray(value))
33
+ return value.map((item) => walk(item, key, removed)).filter((item) => item !== undefined);
34
+ if (key === "action_id" && typeof value !== "string")
35
+ return undefined;
36
+ if (isObj(value)) {
37
+ const out = {};
38
+ for (const [name, item] of Object.entries(value)) {
39
+ if (item === undefined || item === null)
40
+ continue;
41
+ const kept = BLOCK_KEYS.has(name) ? walk(item, name, removed) : undefined;
42
+ if (kept === undefined)
43
+ bump(removed, name);
44
+ else
45
+ out[name] = kept;
46
+ }
47
+ return out;
48
+ }
49
+ if (typeof value === "number")
50
+ return key === "timestamp" ? 4000000000 : BLOCK_SIZES.has(key) ? 1 : BLOCK_NUMBERS.has(key) ? value : undefined;
51
+ if (typeof value === "boolean")
52
+ return BLOCK_FLAGS.has(key) ? value : undefined;
53
+ if (typeof value !== "string" || BLOCK_FLAGS.has(key) || BLOCK_SIZES.has(key) || key === "timestamp")
54
+ return undefined;
55
+ if (key === "range")
56
+ return BROADCAST_RANGES.has(value) ? value : undefined;
57
+ if (key in FIXED_STRINGS)
58
+ return FIXED_STRINGS[key];
59
+ if (key === "type" || key === "style")
60
+ return SAFE_WORD.test(value) ? value : filler(value);
61
+ if (key === "user_id")
62
+ return TEST_USER;
63
+ if (key === "channel_id")
64
+ return CHANNEL;
65
+ return filler(value);
66
+ }
67
+ function buildFile(file, pass) {
68
+ // the app needs SlackFile.id
69
+ if (!isObj(file) || typeof file.id !== "string")
70
+ return undefined;
71
+ const out = {};
72
+ if (!pass.fileIds.has(file.id))
73
+ pass.fileIds.set(file.id, `CZRDRF${pass.fileIds.size + 1}`);
74
+ out.id = pass.fileIds.get(file.id);
75
+ for (const key of ["name", "title"])
76
+ if (typeof file[key] === "string")
77
+ out[key] = filler(file[key]);
78
+ for (const key of ["mimetype", "filetype", "mode"])
79
+ if (typeof file[key] === "string" && SAFE_MIME.test(file[key]))
80
+ out[key] = file[key];
81
+ if (typeof file.size === "number")
82
+ out.size = file.size;
83
+ if (typeof file.user === "string")
84
+ out.user = TEST_USER;
85
+ return out;
86
+ }
87
+ // tsValue is what this level's ts becomes; undefined means the level has no ts
88
+ function buildLevel(src, top, tsValue, pass) {
89
+ const out = {};
90
+ for (const key of MESSAGE_KEYS) {
91
+ const value = src[key];
92
+ if (value === undefined)
93
+ continue;
94
+ switch (key) {
95
+ case "type":
96
+ if (top)
97
+ out.type = "message";
98
+ else if (value === "message")
99
+ out.type = value;
100
+ break;
101
+ case "subtype":
102
+ if (top && typeof value === "string")
103
+ out.subtype = value;
104
+ break;
105
+ case "channel":
106
+ if (typeof value === "string")
107
+ out.channel = CHANNEL;
108
+ break;
109
+ case "ts":
110
+ if (tsValue !== undefined)
111
+ out.ts = tsValue;
112
+ break;
113
+ case "thread_ts":
114
+ if (tsValue !== undefined)
115
+ out.thread_ts = tsValue;
116
+ break;
117
+ case "user":
118
+ if (typeof value === "string")
119
+ out.user = TEST_USER;
120
+ break;
121
+ case "client_msg_id":
122
+ if (typeof value === "string" && tsValue === SEQ_TS)
123
+ out.client_msg_id = SEQ_UUID;
124
+ break;
125
+ case "text":
126
+ if (typeof value === "string")
127
+ out.text = filler(value);
128
+ break;
129
+ case "blocks":
130
+ if (Array.isArray(value))
131
+ out.blocks = walk(value, key, pass.removed);
132
+ break;
133
+ case "files":
134
+ if (Array.isArray(value))
135
+ out.files = value.map((file) => buildFile(file, pass)).filter((file) => file !== undefined);
136
+ break;
137
+ case "reply_count":
138
+ if (Number.isInteger(value))
139
+ out.reply_count = value;
140
+ break;
141
+ case "replies":
142
+ if (Array.isArray(value))
143
+ out.replies = value.map(() => ({ user: TEST_USER, ts: FRAME_TS }));
144
+ break;
145
+ case "hidden":
146
+ if (typeof value === "boolean")
147
+ out.hidden = value;
148
+ break;
149
+ }
150
+ }
151
+ return out;
152
+ }
153
+ function classify(record) {
154
+ if (String(record.direction).toUpperCase() !== "INCOMING")
155
+ return "sent by the app";
156
+ let frame;
157
+ if (record.is_base64 !== true && typeof record.data === "string") {
158
+ try {
159
+ frame = JSON.parse(record.data);
160
+ }
161
+ catch { }
162
+ }
163
+ if (!isObj(frame))
164
+ return "not a JSON object";
165
+ const label = pairLabel(frame);
166
+ if (!PAIRS.has(label))
167
+ return label;
168
+ const message = frame.message;
169
+ const previous = frame.previous_message;
170
+ if ((isObj(message) && message.subtype !== undefined) || (isObj(previous) && previous.subtype !== undefined))
171
+ return "nested subtype";
172
+ const update = label !== "message";
173
+ if (!update && typeof frame.ts !== "string")
174
+ return "no ts";
175
+ if (update && !(isObj(message) && typeof message.ts === "string"))
176
+ return "no message.ts";
177
+ const levels = update ? [message, previous] : [frame];
178
+ for (const level of levels) {
179
+ if (isObj(level) && level.thread_ts !== undefined && level.thread_ts !== level.ts)
180
+ return "reply";
181
+ }
182
+ return { label, frame, update };
183
+ }
184
+ export function captureCase(records) {
185
+ const byId = new Map();
186
+ for (const record of records)
187
+ if (!byId.has(record.id))
188
+ byId.set(record.id, record);
189
+ const ordered = [...byId.values()].sort((a, b) => a.id - b.id);
190
+ const kept = {};
191
+ const dropped = {};
192
+ const candidates = [];
193
+ const targets = new Set();
194
+ for (const record of ordered) {
195
+ const result = classify(record);
196
+ if (typeof result === "string") {
197
+ bump(dropped, result);
198
+ continue;
199
+ }
200
+ bump(kept, result.label);
201
+ candidates.push(result);
202
+ if (result.update)
203
+ targets.add(result.frame.message.ts);
204
+ }
205
+ const pass = { fileIds: new Map(), removed: {} };
206
+ const events = [];
207
+ // {{seq_ts}} is the ts of the iteration's first frame, so a {{frame_ts}} message at index 0
208
+ // would share it and get overwritten by the seed. A seq message must come first.
209
+ const first = candidates[0];
210
+ const firstIsTarget = first && !first.update && typeof first.frame.ts === "string" && targets.has(first.frame.ts);
211
+ const seeded = targets.size > 0 && !firstIsTarget;
212
+ if (seeded)
213
+ events.push(structuredClone(BUILTIN_SEED));
214
+ for (const { frame, update } of candidates) {
215
+ let event;
216
+ if (update) {
217
+ event = buildLevel(frame, true, undefined, pass);
218
+ for (const key of ["message", "previous_message"]) {
219
+ const level = frame[key];
220
+ if (isObj(level))
221
+ event[key] = buildLevel(level, false, typeof level.ts === "string" ? SEQ_TS : undefined, pass);
222
+ }
223
+ }
224
+ else {
225
+ const isTarget = typeof frame.ts === "string" && targets.has(frame.ts);
226
+ event = buildLevel(frame, true, isTarget ? SEQ_TS : FRAME_TS, pass);
227
+ event.user = TEST_USER;
228
+ if (isTarget)
229
+ event.client_msg_id = SEQ_UUID;
230
+ }
231
+ event.channel = CHANNEL;
232
+ events.push(event);
233
+ }
234
+ return { events, kept, dropped, seeded, targets: targets.size, removed: pass.removed };
235
+ }
@@ -0,0 +1,54 @@
1
+ export declare const CASE_NAME: RegExp;
2
+ export declare const MAX_CASE_FILE_BYTES: number;
3
+ export declare const testCaseDir: () => string;
4
+ export interface TestCase {
5
+ repeat?: number;
6
+ rate_per_second: number | null;
7
+ events: Record<string, unknown>[];
8
+ }
9
+ export declare const BUILTIN_SEED: {
10
+ type: string;
11
+ channel: string;
12
+ ts: string;
13
+ client_msg_id: string;
14
+ text: string;
15
+ user: string;
16
+ };
17
+ export declare const BUILTIN_CASES: Map<string, TestCase>;
18
+ export declare function caseStem(name: string): string;
19
+ export declare function loadCase(name: string, dir?: string): TestCase | {
20
+ error: string;
21
+ };
22
+ export declare function buildRunBody(caseDef: TestCase, overrides: Partial<Pick<TestCase, "repeat" | "rate_per_second">>, runId: string): string;
23
+ export declare function pairLabel(event: Record<string, unknown>): string;
24
+ export declare function checkCaseName(name: string, overwrite: boolean, dir?: string): {
25
+ error: string;
26
+ reason: string;
27
+ } | null;
28
+ export declare function saveCase(name: string, caseDef: TestCase, overwrite: boolean, dir?: string): {
29
+ path: string;
30
+ } | {
31
+ error: string;
32
+ reason?: string;
33
+ };
34
+ /** Removes a saved case file. lstat counts a dangling link as present, and unlink never follows a link, so deleting one leaves its target. */
35
+ export declare function deleteCase(name: string, dir?: string): {
36
+ deleted: string;
37
+ } | {
38
+ error: string;
39
+ };
40
+ export interface CaseSummary {
41
+ name: string;
42
+ built_in?: boolean;
43
+ path?: string;
44
+ replaces_built_in?: boolean;
45
+ repeat?: number;
46
+ rate_per_second?: number | null;
47
+ events?: number;
48
+ types?: Record<string, number>;
49
+ error?: string;
50
+ }
51
+ export declare function listCases(dir?: string): {
52
+ dir: string;
53
+ cases: CaseSummary[];
54
+ };