@tmhs/screencast-mcp 0.49.1 → 0.51.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 (134) hide show
  1. package/README.md +15 -9
  2. package/dist/index.js +551 -106
  3. package/dist/wgcRecorder.js +15 -139
  4. package/package.json +9 -5
  5. package/assets/.gitkeep +0 -0
  6. package/assets/icon.png +0 -0
  7. package/dist/cli.js +0 -516
  8. package/dist/context.js +0 -50
  9. package/dist/prompts.js +0 -95
  10. package/dist/resources.js +0 -93
  11. package/dist/server.js +0 -174
  12. package/dist/setup.js +0 -438
  13. package/dist/tools/addMarker.js +0 -93
  14. package/dist/tools/assembleHighlights.js +0 -69
  15. package/dist/tools/backdrop.js +0 -79
  16. package/dist/tools/bugReport.js +0 -243
  17. package/dist/tools/burnSubtitles.js +0 -56
  18. package/dist/tools/callout.js +0 -62
  19. package/dist/tools/chapters.js +0 -156
  20. package/dist/tools/clip.js +0 -52
  21. package/dist/tools/compress.js +0 -51
  22. package/dist/tools/concat.js +0 -67
  23. package/dist/tools/contactSheet.js +0 -113
  24. package/dist/tools/convert.js +0 -46
  25. package/dist/tools/crop.js +0 -43
  26. package/dist/tools/cursor.js +0 -67
  27. package/dist/tools/cutByTranscript.js +0 -86
  28. package/dist/tools/cutIdle.js +0 -84
  29. package/dist/tools/deleteRecording.js +0 -119
  30. package/dist/tools/denoise.js +0 -60
  31. package/dist/tools/doctor.js +0 -146
  32. package/dist/tools/exportGif.js +0 -57
  33. package/dist/tools/exportPreset.js +0 -48
  34. package/dist/tools/extractAudio.js +0 -65
  35. package/dist/tools/findText.js +0 -194
  36. package/dist/tools/getMediaInfo.js +0 -36
  37. package/dist/tools/getSession.js +0 -40
  38. package/dist/tools/indexRecording.js +0 -195
  39. package/dist/tools/keystrokeOverlay.js +0 -90
  40. package/dist/tools/listAudioDevices.js +0 -35
  41. package/dist/tools/listSessions.js +0 -28
  42. package/dist/tools/listTargets.js +0 -76
  43. package/dist/tools/listVideoDevices.js +0 -26
  44. package/dist/tools/musicBed.js +0 -55
  45. package/dist/tools/narrate.js +0 -86
  46. package/dist/tools/normalizeAudio.js +0 -59
  47. package/dist/tools/overlay.js +0 -62
  48. package/dist/tools/pauseRecording.js +0 -44
  49. package/dist/tools/pipeline.js +0 -397
  50. package/dist/tools/readEvents.js +0 -98
  51. package/dist/tools/redactRegion.js +0 -62
  52. package/dist/tools/reframe.js +0 -46
  53. package/dist/tools/resumeRecording.js +0 -46
  54. package/dist/tools/reviewRecording.js +0 -163
  55. package/dist/tools/sampleFrames.js +0 -200
  56. package/dist/tools/saveReplay.js +0 -90
  57. package/dist/tools/scale.js +0 -44
  58. package/dist/tools/screenDiff.js +0 -86
  59. package/dist/tools/screenshot.js +0 -76
  60. package/dist/tools/searchRecording.js +0 -79
  61. package/dist/tools/speed.js +0 -46
  62. package/dist/tools/startRecording.js +0 -398
  63. package/dist/tools/stepGuide.js +0 -249
  64. package/dist/tools/stopRecording.js +0 -132
  65. package/dist/tools/titleCard.js +0 -67
  66. package/dist/tools/transcribe.js +0 -66
  67. package/dist/tools/trim.js +0 -57
  68. package/dist/tools/waitForChange.js +0 -142
  69. package/dist/tools/xfadeTransition.js +0 -58
  70. package/dist/tools/zoom.js +0 -134
  71. package/dist/utils/anim.js +0 -54
  72. package/dist/utils/animExport.js +0 -56
  73. package/dist/utils/argPaths.js +0 -39
  74. package/dist/utils/audio.js +0 -117
  75. package/dist/utils/audioDevices.js +0 -107
  76. package/dist/utils/backdrop.js +0 -162
  77. package/dist/utils/bugReport.js +0 -195
  78. package/dist/utils/callout.js +0 -132
  79. package/dist/utils/calloutAssets.js +0 -42
  80. package/dist/utils/capabilities.js +0 -96
  81. package/dist/utils/captions.js +0 -104
  82. package/dist/utils/chapters.js +0 -227
  83. package/dist/utils/consent.js +0 -29
  84. package/dist/utils/cursor.js +0 -338
  85. package/dist/utils/diff.js +0 -186
  86. package/dist/utils/errors.js +0 -29
  87. package/dist/utils/events.js +0 -403
  88. package/dist/utils/expr.js +0 -11
  89. package/dist/utils/ffmpeg.js +0 -285
  90. package/dist/utils/fontCoverage.js +0 -177
  91. package/dist/utils/fonts.js +0 -154
  92. package/dist/utils/frameQueue.js +0 -50
  93. package/dist/utils/gpu.js +0 -219
  94. package/dist/utils/idle.js +0 -91
  95. package/dist/utils/images.js +0 -38
  96. package/dist/utils/jobs.js +0 -129
  97. package/dist/utils/keystrokes.js +0 -198
  98. package/dist/utils/lifecycle.js +0 -233
  99. package/dist/utils/logging.js +0 -75
  100. package/dist/utils/media.js +0 -584
  101. package/dist/utils/monitors.js +0 -124
  102. package/dist/utils/narrate.js +0 -233
  103. package/dist/utils/ocr.js +0 -222
  104. package/dist/utils/ocrScan.js +0 -93
  105. package/dist/utils/paths.js +0 -155
  106. package/dist/utils/pause.js +0 -190
  107. package/dist/utils/pipeline.js +0 -361
  108. package/dist/utils/player.js +0 -85
  109. package/dist/utils/pool.js +0 -29
  110. package/dist/utils/produce.js +0 -300
  111. package/dist/utils/recipes.js +0 -71
  112. package/dist/utils/recorder.js +0 -173
  113. package/dist/utils/recordingFiles.js +0 -32
  114. package/dist/utils/recordingIndex.js +0 -312
  115. package/dist/utils/replay.js +0 -283
  116. package/dist/utils/resolveTarget.js +0 -25
  117. package/dist/utils/retention.js +0 -48
  118. package/dist/utils/roots.js +0 -43
  119. package/dist/utils/sessions.js +0 -499
  120. package/dist/utils/sheet.js +0 -82
  121. package/dist/utils/stepGuide.js +0 -231
  122. package/dist/utils/steps.js +0 -88
  123. package/dist/utils/still.js +0 -38
  124. package/dist/utils/targetList.js +0 -64
  125. package/dist/utils/targets.js +0 -265
  126. package/dist/utils/timeline.js +0 -85
  127. package/dist/utils/toolSpec.js +0 -31
  128. package/dist/utils/toolsets.js +0 -134
  129. package/dist/utils/transcriptCut.js +0 -149
  130. package/dist/utils/validate.js +0 -23
  131. package/dist/utils/waitLoop.js +0 -50
  132. package/dist/utils/wgc.js +0 -84
  133. package/dist/utils/windows.js +0 -192
  134. package/dist/utils/zoom.js +0 -252
package/dist/cli.js DELETED
@@ -1,516 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { createRequire } from "node:module";
3
- import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
- import { join, resolve } from "node:path";
5
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
6
- import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
7
- import { createServer } from "./server.js";
8
- import { MAX_RECORDING_CAP_SEC } from "./utils/targets.js";
9
- import { DEFAULT_ERROR_PATTERN, DEFAULT_SECRET_PATTERN, MAX_ERROR_LINES, maskSecrets } from "./utils/bugReport.js";
10
- import { defaultSetupDeps, parseSetupArgs, runSetup, SETUP_USAGE } from "./setup.js";
11
- import { errorMessage } from "./utils/errors.js";
12
- const VERSION = createRequire(import.meta.url)("../package.json").version;
13
- export class CliUsageError extends Error {
14
- }
15
- const SUBCOMMANDS = new Set(["record", "call", "setup", "help", "--help", "-h", "--version", "-v"]);
16
- export function isCliInvocation(argv) {
17
- return argv.length > 0 && SUBCOMMANDS.has(argv[0] ?? "");
18
- }
19
- export const USAGE = `screencast-mcp: an MCP server for Windows screen recording.
20
-
21
- Usage:
22
- screencast-mcp run the MCP server over stdio (default)
23
- screencast-mcp record [options] -- <command...>
24
- record the screen while <command> runs
25
- screencast-mcp record [options] --command-env <NAME>
26
- the same, running the command in env var NAME
27
- screencast-mcp call <tool> [json|@file] call one tool and print its result
28
- screencast-mcp setup [options] check this machine and wire up MCP clients
29
- screencast-mcp --version | --help
30
-
31
- record options:
32
- --target <target> full | monitor:<i> | window:<title> | region:x,y,w,h (default full)
33
- --fps <n> capture frame rate, 1-120 (default 15)
34
- --out <dir> output folder (default screencast-evidence)
35
- --artifacts <when> make the GIF and contact sheet on: failure | always | never (default failure)
36
- --last <sec> the GIF covers the last <sec> seconds; 0 = all (default 30)
37
- --no-gif skip the GIF
38
- --no-contact-sheet skip the contact sheet
39
- --discard-on-success delete the recording when the command exits 0
40
- --ocr-errors on failure, OCR the last <sec> seconds for error lines (Windows OCR)
41
- --max-duration <sec> stop recording after <sec> seconds, an integer 0-${MAX_RECORDING_CAP_SEC}
42
- (0 = no cap; default SCREENCAST_MAX_RECORDING_SEC, else 3600)
43
- --command-env <NAME> run the command line in environment variable NAME instead of
44
- the arguments after --, so quotes and & survive any shell
45
-
46
- record exits with the command's exit code and writes <out>/evidence.json.
47
-
48
- ${SETUP_USAGE}`;
49
- function takeValue(argv, i, flag) {
50
- const value = argv[i + 1];
51
- if (value === undefined || value === "--")
52
- throw new CliUsageError(`${flag} needs a value.`);
53
- return value;
54
- }
55
- function number(value, flag, min, max = Infinity, integer = false) {
56
- const n = Number(value);
57
- if (value.trim() === "" || !Number.isFinite(n) || n < min || n > max || (integer && !Number.isInteger(n))) {
58
- const range = max === Infinity ? `>= ${min}` : `${min}-${max}`;
59
- throw new CliUsageError(`${flag} must be ${integer ? "an integer" : "a number"} ${range}, got "${value}".`);
60
- }
61
- return n;
62
- }
63
- function parseRecord(argv, env) {
64
- const dash = argv.indexOf("--");
65
- const options = {
66
- target: "full",
67
- fps: 15,
68
- outDir: "screencast-evidence",
69
- artifacts: "failure",
70
- lastSec: 30,
71
- gif: true,
72
- contactSheet: true,
73
- discardOnSuccess: false,
74
- ocrErrors: false,
75
- command: dash === -1 ? [] : argv.slice(dash + 1),
76
- };
77
- let commandEnv;
78
- const flags = dash === -1 ? argv : argv.slice(0, dash);
79
- for (let i = 0; i < flags.length; i++) {
80
- const raw = flags[i] ?? "";
81
- const eq = raw.startsWith("--") ? raw.indexOf("=") : -1;
82
- const flag = eq === -1 ? raw : raw.slice(0, eq);
83
- const inline = eq === -1 ? undefined : raw.slice(eq + 1);
84
- const value = () => {
85
- if (inline !== undefined)
86
- return inline;
87
- const v = takeValue(flags, i, flag);
88
- i++;
89
- return v;
90
- };
91
- switch (flag) {
92
- case "--target":
93
- options.target = value();
94
- break;
95
- case "--fps":
96
- options.fps = number(value(), flag, 1, 120, true);
97
- break;
98
- case "--out":
99
- options.outDir = value();
100
- break;
101
- case "--artifacts": {
102
- const v = value();
103
- if (v !== "failure" && v !== "always" && v !== "never") {
104
- throw new CliUsageError(`--artifacts must be failure, always, or never, got "${v}".`);
105
- }
106
- options.artifacts = v;
107
- break;
108
- }
109
- case "--last":
110
- options.lastSec = number(value(), flag, 0);
111
- break;
112
- case "--max-duration":
113
- options.maxDurationSec = number(value(), flag, 0, MAX_RECORDING_CAP_SEC, true);
114
- break;
115
- case "--command-env":
116
- commandEnv = value();
117
- break;
118
- case "--no-gif":
119
- options.gif = false;
120
- break;
121
- case "--no-contact-sheet":
122
- options.contactSheet = false;
123
- break;
124
- case "--discard-on-success":
125
- options.discardOnSuccess = true;
126
- break;
127
- case "--ocr-errors":
128
- options.ocrErrors = true;
129
- break;
130
- default:
131
- throw new CliUsageError(`Unknown record option "${raw}". Run screencast-mcp --help.`);
132
- }
133
- }
134
- if (commandEnv !== undefined) {
135
- if (options.command.length > 0) {
136
- throw new CliUsageError("Give the command either after -- or with --command-env, not both.");
137
- }
138
- const line = env[commandEnv];
139
- if (line === undefined || line.trim() === "") {
140
- throw new CliUsageError(`--command-env ${commandEnv}: the environment variable is unset or empty.`);
141
- }
142
- options.command = [line];
143
- }
144
- else if (options.command.length === 0) {
145
- throw new CliUsageError("record needs a command after -- (or --command-env NAME), e.g. screencast-mcp record -- npm test");
146
- }
147
- return options;
148
- }
149
- export function parseCliArgs(argv, env = process.env) {
150
- const [sub, ...rest] = argv;
151
- switch (sub) {
152
- case "help":
153
- case "--help":
154
- case "-h":
155
- return { kind: "help" };
156
- case "--version":
157
- case "-v":
158
- return { kind: "version" };
159
- case "record":
160
- if (rest[0] === "--help" || rest[0] === "-h")
161
- return { kind: "help" };
162
- return { kind: "record", options: parseRecord(rest, env) };
163
- case "call": {
164
- const [tool, args, extra] = rest;
165
- if (!tool || tool.startsWith("-"))
166
- throw new CliUsageError("call needs a tool name, e.g. screencast-mcp call doctor");
167
- if (extra !== undefined)
168
- throw new CliUsageError("call takes one JSON argument; quote it as a single string.");
169
- return { kind: "call", tool, args };
170
- }
171
- case "setup": {
172
- if (rest[0] === "--help" || rest[0] === "-h")
173
- return { kind: "help" };
174
- try {
175
- return { kind: "setup", options: parseSetupArgs(rest) };
176
- }
177
- catch (err) {
178
- throw new CliUsageError(errorMessage(err));
179
- }
180
- }
181
- default:
182
- throw new CliUsageError(`Unknown command "${sub ?? ""}". Run screencast-mcp --help.`);
183
- }
184
- }
185
- const CMD_META = /([()\][%!^"`<>&|;, *?])/g;
186
- const BATCH_SHIM = /(\.(cmd|bat)$)|^(npm|npx|pnpm|yarn|corepack)$/i;
187
- function msvcQuote(arg) {
188
- const escaped = arg.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\+)$/, "$1$1");
189
- return `"${escaped}"`;
190
- }
191
- const NEEDS_QUOTES = /[\s"&|<>^()!;'`$*?%,[\]]/;
192
- export function commandLine(command, platform = process.platform) {
193
- if (command.length === 1)
194
- return command[0] ?? "";
195
- if (platform !== "win32") {
196
- return command.map((a) => (/^[\w@%+=:,./-]+$/.test(a) ? a : `'${a.replace(/'/g, `'\\''`)}'`)).join(" ");
197
- }
198
- const batch = BATCH_SHIM.test(command[0] ?? "");
199
- return command
200
- .map((a, i) => {
201
- if (i === 0 || (!NEEDS_QUOTES.test(a) && a !== ""))
202
- return a;
203
- let q = msvcQuote(a).replace(CMD_META, "^$1");
204
- if (batch)
205
- q = q.replace(CMD_META, "^$1");
206
- return q;
207
- })
208
- .join(" ");
209
- }
210
- export function displayCommand(command) {
211
- if (command.length === 1)
212
- return command[0] ?? "";
213
- return command.map((a) => (NEEDS_QUOTES.test(a) || a === "" ? `"${a.replace(/"/g, '\\"')}"` : a)).join(" ");
214
- }
215
- export function tailWindow(durationSec, lastSec) {
216
- if (!lastSec || durationSec === null || durationSec <= lastSec)
217
- return {};
218
- return { start: Math.round((durationSec - lastSec) * 1000) / 1000, duration: lastSec };
219
- }
220
- export function errorLines(matches) {
221
- const sorted = [...matches].sort((a, b) => (Number(b.t) || 0) - (Number(a.t) || 0));
222
- const seen = new Set();
223
- const lines = [];
224
- for (const m of sorted) {
225
- const line = String(m.line ?? m.text ?? "").trim();
226
- const key = line.toLowerCase().replace(/\s+/g, " ");
227
- if (!line || seen.has(key))
228
- continue;
229
- seen.add(key);
230
- lines.push(line);
231
- if (lines.length >= MAX_ERROR_LINES)
232
- break;
233
- }
234
- return maskSecrets(lines, DEFAULT_SECRET_PATTERN);
235
- }
236
- export function parseToolArgs(raw, readFile = (p) => readFileSync(p, "utf8")) {
237
- if (raw === undefined || raw.trim() === "")
238
- return {};
239
- const text = raw.startsWith("@") ? readFile(raw.slice(1)) : raw;
240
- let value;
241
- try {
242
- value = JSON.parse(text);
243
- }
244
- catch (err) {
245
- throw new CliUsageError(`Tool arguments are not valid JSON: ${errorMessage(err)}`);
246
- }
247
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
248
- throw new CliUsageError("Tool arguments must be a JSON object.");
249
- }
250
- return value;
251
- }
252
- export async function connect() {
253
- const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
254
- await createServer({ toolsets: "all" }).connect(serverSide);
255
- const client = new Client({ name: "screencast-mcp-cli", version: VERSION });
256
- await client.connect(clientSide);
257
- return {
258
- async call(name, args) {
259
- const res = await client.callTool({ name, arguments: args });
260
- const text = res.content
261
- .map((c) => (c.type === "text" ? (c.text ?? "") : `[${c.type} omitted]`))
262
- .join("\n");
263
- return {
264
- isError: res.isError === true,
265
- text,
266
- structured: res.structuredContent,
267
- };
268
- },
269
- close: () => client.close(),
270
- };
271
- }
272
- export async function mustCall(client, name, args) {
273
- const res = await client.call(name, args);
274
- if (res.isError)
275
- throw new Error(`${name}: ${res.text}`);
276
- return res.structured ?? {};
277
- }
278
- const defaultIo = {
279
- out: (s) => process.stdout.write(s),
280
- err: (s) => process.stderr.write(s),
281
- };
282
- function runCommand(command) {
283
- return new Promise((resolveExit) => {
284
- const child = spawn(commandLine(command), { shell: true, stdio: "inherit" });
285
- const forward = (sig) => () => child.kill(sig);
286
- const onInt = forward("SIGINT");
287
- const onTerm = forward("SIGTERM");
288
- process.on("SIGINT", onInt);
289
- process.on("SIGTERM", onTerm);
290
- const done = (code) => {
291
- process.off("SIGINT", onInt);
292
- process.off("SIGTERM", onTerm);
293
- resolveExit(code);
294
- };
295
- child.on("error", (err) => {
296
- process.stderr.write(`screencast-mcp: could not run the command: ${err.message}\n`);
297
- done(127);
298
- });
299
- child.on("exit", (code, signal) => done(code ?? (signal ? 1 : 0)));
300
- });
301
- }
302
- export function earlyEndWarning(status, endReason, durationSec) {
303
- if (status === null)
304
- return null;
305
- const at = durationSec === null ? "" : ` at ${durationSec} s`;
306
- const tail = "so the GIF and contact sheet show the end of the recording, not the end of the run.";
307
- if (endReason === "max_duration") {
308
- return `the recording hit its max-duration cap${at} before the command finished, ${tail} Raise --max-duration (0 = no cap).`;
309
- }
310
- if (status === "failed" || endReason === "crashed") {
311
- return `the recording failed${at} before the command finished (endReason ${endReason ?? "unknown"}), ${tail}`;
312
- }
313
- if (endReason === "window_closed") {
314
- return `the recorded window closed${at} before the command finished, ${tail}`;
315
- }
316
- if (endReason !== null && endReason !== "stopped") {
317
- return `the recording ended early${at} (endReason ${endReason}), ${tail}`;
318
- }
319
- return null;
320
- }
321
- const defaultRecordDeps = { connect, run: runCommand, now: () => Date.now() };
322
- export async function runRecord(opts, io = defaultIo, deps = defaultRecordDeps) {
323
- const outDir = resolve(opts.outDir);
324
- mkdirSync(outDir, { recursive: true });
325
- const evidence = {
326
- command: displayCommand(opts.command),
327
- exitCode: 0,
328
- target: opts.target,
329
- recording: null,
330
- durationSec: null,
331
- commandSec: 0,
332
- status: null,
333
- endReason: null,
334
- gif: null,
335
- contactSheet: null,
336
- errors: null,
337
- warnings: [],
338
- };
339
- const warn = (msg) => {
340
- evidence.warnings.push(msg);
341
- io.err(`screencast-mcp: ${msg}\n`);
342
- };
343
- const client = await deps.connect();
344
- try {
345
- let sessionId = null;
346
- try {
347
- const started = await mustCall(client, "start_recording", {
348
- target: opts.target,
349
- fps: opts.fps,
350
- output: join(outDir, "recording.mp4"),
351
- overwrite: true,
352
- ...(opts.maxDurationSec !== undefined ? { maxDurationSec: opts.maxDurationSec } : {}),
353
- });
354
- sessionId = String(started.sessionId);
355
- io.err(`screencast-mcp: recording ${opts.target} to ${String(started.outputPath)}\n`);
356
- }
357
- catch (err) {
358
- warn(`recording did not start, running the command without it: ${errorMessage(err)}`);
359
- }
360
- const began = deps.now();
361
- evidence.exitCode = await deps.run(opts.command);
362
- evidence.commandSec = Math.round(deps.now() - began) / 1000;
363
- if (sessionId) {
364
- try {
365
- const stopped = await mustCall(client, "stop_recording", { sessionId });
366
- evidence.recording = String(stopped.outputPath);
367
- evidence.durationSec = typeof stopped.durationSec === "number" ? stopped.durationSec : null;
368
- evidence.status = typeof stopped.status === "string" ? stopped.status : null;
369
- evidence.endReason =
370
- typeof stopped.endReason === "string" ? stopped.endReason : evidence.status === "stopped" ? "stopped" : null;
371
- const early = earlyEndWarning(evidence.status, evidence.endReason, evidence.durationSec);
372
- if (early)
373
- warn(early);
374
- }
375
- catch (err) {
376
- warn(`stop_recording failed: ${errorMessage(err)}`);
377
- }
378
- }
379
- const failed = evidence.exitCode !== 0;
380
- const wanted = opts.artifacts === "always" || (opts.artifacts === "failure" && failed);
381
- if (evidence.recording && wanted) {
382
- const input = evidence.recording;
383
- if (opts.gif) {
384
- try {
385
- const gif = await mustCall(client, "export_gif", {
386
- input,
387
- ...tailWindow(evidence.durationSec, opts.lastSec),
388
- output: join(outDir, "evidence.gif"),
389
- overwrite: true,
390
- });
391
- evidence.gif = String(gif.outputPath);
392
- }
393
- catch (err) {
394
- warn(`export_gif failed: ${errorMessage(err)}`);
395
- }
396
- }
397
- if (opts.contactSheet) {
398
- try {
399
- const sheet = await mustCall(client, "contact_sheet", {
400
- input,
401
- output: join(outDir, "contact-sheet.png"),
402
- overwrite: true,
403
- returnImage: false,
404
- });
405
- evidence.contactSheet = String(sheet.outputPath);
406
- }
407
- catch (err) {
408
- warn(`contact_sheet failed: ${errorMessage(err)}`);
409
- }
410
- }
411
- }
412
- if (evidence.recording && failed && opts.ocrErrors) {
413
- evidence.errors = await ocrErrors(client, evidence.recording, evidence.durationSec, opts.lastSec, outDir, warn);
414
- }
415
- if (!failed && opts.discardOnSuccess && evidence.recording) {
416
- rmSync(evidence.recording, { force: true });
417
- evidence.recording = null;
418
- }
419
- }
420
- finally {
421
- await client.close();
422
- }
423
- writeFileSync(join(outDir, "evidence.json"), JSON.stringify(evidence, null, 2) + "\n");
424
- io.err(`screencast-mcp: command exited ${evidence.exitCode}; evidence in ${outDir}` +
425
- (evidence.gif ? ` (gif: ${evidence.gif})` : "") +
426
- "\n");
427
- return evidence.exitCode;
428
- }
429
- async function ocrErrors(client, recording, durationSec, lastSec, outDir, warn) {
430
- const window = tailWindow(durationSec, lastSec);
431
- let input = recording;
432
- let tail = null;
433
- try {
434
- if (window.start !== undefined) {
435
- const cut = await mustCall(client, "trim", {
436
- input: recording,
437
- start: window.start,
438
- duration: window.duration,
439
- output: join(outDir, ".ocr-tail.mp4"),
440
- overwrite: true,
441
- });
442
- tail = String(cut.outputPath);
443
- input = tail;
444
- }
445
- const found = await mustCall(client, "find_text", {
446
- input,
447
- scanEverySec: 1,
448
- maxFrames: 30,
449
- query: DEFAULT_ERROR_PATTERN,
450
- regex: true,
451
- returnImage: false,
452
- });
453
- const matches = Array.isArray(found.matches) ? found.matches : [];
454
- return errorLines(matches);
455
- }
456
- catch (err) {
457
- warn(`OCR of error lines failed: ${errorMessage(err)}`);
458
- return null;
459
- }
460
- finally {
461
- if (tail)
462
- rmSync(tail, { force: true });
463
- }
464
- }
465
- async function call(tool, rawArgs, io) {
466
- const args = parseToolArgs(rawArgs);
467
- const client = await connect();
468
- try {
469
- const res = await client.call(tool, args);
470
- if (res.isError) {
471
- io.err(`${res.text}\n`);
472
- return 1;
473
- }
474
- io.out((res.structured ? JSON.stringify(res.structured, null, 2) : res.text) + "\n");
475
- return 0;
476
- }
477
- finally {
478
- await client.close();
479
- }
480
- }
481
- export async function runCli(argv, io = defaultIo) {
482
- let command;
483
- try {
484
- command = parseCliArgs(argv);
485
- }
486
- catch (err) {
487
- if (err instanceof CliUsageError) {
488
- io.err(`screencast-mcp: ${err.message}\n`);
489
- return 2;
490
- }
491
- throw err;
492
- }
493
- switch (command.kind) {
494
- case "help":
495
- io.out(USAGE);
496
- return 0;
497
- case "version":
498
- io.out(`${VERSION}\n`);
499
- return 0;
500
- case "record":
501
- return runRecord(command.options, io);
502
- case "setup":
503
- return runSetup(command.options, defaultSetupDeps({ connect, io }));
504
- case "call":
505
- try {
506
- return await call(command.tool, command.args, io);
507
- }
508
- catch (err) {
509
- if (err instanceof CliUsageError) {
510
- io.err(`screencast-mcp: ${err.message}\n`);
511
- return 2;
512
- }
513
- throw err;
514
- }
515
- }
516
- }
package/dist/context.js DELETED
@@ -1,50 +0,0 @@
1
- import { SessionStore } from "./utils/sessions.js";
2
- import { registryPath } from "./utils/paths.js";
3
- import { ScreencastError } from "./utils/errors.js";
4
- let store = null;
5
- export function getStore() {
6
- if (!store) {
7
- store = new SessionStore(registryPath());
8
- store.load();
9
- }
10
- return store;
11
- }
12
- let shuttingDown = false;
13
- export function markShuttingDown() {
14
- shuttingDown = true;
15
- }
16
- export function isShuttingDown() {
17
- return shuttingDown;
18
- }
19
- let startsInFlight = 0;
20
- let onStartsIdle = [];
21
- export function beginStart() {
22
- if (shuttingDown)
23
- throw new ScreencastError("The server is shutting down; the recording was not started.");
24
- startsInFlight++;
25
- let released = false;
26
- return () => {
27
- if (released)
28
- return;
29
- released = true;
30
- startsInFlight--;
31
- if (startsInFlight === 0) {
32
- const waiters = onStartsIdle;
33
- onStartsIdle = [];
34
- for (const w of waiters)
35
- w();
36
- }
37
- };
38
- }
39
- export function startsSettled(timeoutMs) {
40
- if (startsInFlight === 0)
41
- return Promise.resolve(true);
42
- return new Promise((resolve) => {
43
- const timer = setTimeout(() => resolve(false), timeoutMs);
44
- timer.unref?.();
45
- onStartsIdle.push(() => {
46
- clearTimeout(timer);
47
- resolve(true);
48
- });
49
- });
50
- }
package/dist/prompts.js DELETED
@@ -1,95 +0,0 @@
1
- import { z } from "zod";
2
- const message = (text) => ({ messages: [{ role: "user", content: { type: "text", text } }] });
3
- export const PROMPT_TEXT = {
4
- bugReproClip: (target, notes) => `Record a short bug-reproduction clip of ${target}.${notes ? ` The bug: ${notes}.` : ""}
5
-
6
- 1. start_recording { target: "${target}", quality: "standard" }, then tell me to reproduce the bug (or reproduce it yourself if you can drive the app), and stop_recording when done.
7
- 2. sample_frames { input: <recording>, mode: "scenes" } to see what happened, and describe the moment the bug appears.
8
- 3. find_text { input: <recording>, scanEverySec: 1, query: "sk-|ghp_|api.?key|token|password", regex: true, redact: true } to check the whole clip, not one frame. If anything sensitive shows up, redact_region its redactRegions (each has its own start/end) with style "box" before sharing. OCR can miss text, so also look at the frames yourself.
9
- 4. trim (or clip) to the few seconds around the bug, and callout to box or point at it.
10
- 5. export_gif { input: <clip>, maxBytes: 10000000 } so it can be pasted into an issue or PR.
11
- Report the final file path, what the clip shows, and anything you redacted. (To file it as an issue, bug_report does steps 3-5 in one call and writes report.md.)`,
12
- fileBugReport: (target, notes, expected) => `File a bug report for ${target}, with a redacted repro package.${notes ? ` The bug: ${notes}.` : ""}${expected ? ` Expected: ${expected}.` : ""}
13
-
14
- 1. start_recording { target: "${target}", events: true } so clicks and shortcuts are logged as repro steps, then reproduce the bug (or ask me to), and stop_recording right after it shows.
15
- 2. contact_sheet { input: <recording> } and find the moment it goes wrong; note its time.
16
- 3. bug_report { sessionId: <session id>, title: <one-line summary>, actual: <what happened>, expected: <what should happen>, clipSec: 30 } (or start/end around that moment). It scans the clip for secrets with OCR and boxes them out before writing the clip, GIF, contact sheet, steps, error text, and report.md.
17
- 4. Read report.md and look at the contact sheet it returns: check the steps make sense and that nothing sensitive is left (OCR can miss text; add regions and rerun with overwrite: true if so).
18
- 5. Only if I confirm, run gh issue create --title <title> --body-file <reportPath>, then attach the GIF to the issue.
19
- Report the folder path, the steps, the error text found, and what was redacted.`,
20
- demoGif: (target, maxMB) => `Make a demo GIF of ${target} for a README or PR, under ${maxMB} MB.
21
-
22
- 1. start_recording { target: "${target}", events: true }, walk through the feature (or ask me to), then stop_recording.
23
- 2. contact_sheet { input: <recording>, mode: "scenes" } to see the whole run at a glance and pick the best stretch.
24
- 3. pipeline { input: <recording>, recipe: "pr_demo", steps: [{ op: "trim", ... that stretch }, { op: "export_gif", maxBytes: ${Math.round(Number(maxMB) * 1_000_000) || 10_000_000} }] }: one pass that cuts idle time, zooms toward the clicks, and writes the GIF (dryRun first to see the steps). If it does not fit, try format: "webp" or a shorter stretch.
25
- Report the file path, its size, and the settings export_gif chose.`,
26
- verifyUiChange: (target, expectation) => `Verify a UI change in ${target}. Expected: ${expectation || "(describe what should change)"}.
27
-
28
- 1. screenshot { target: "${target}" } as the "before" image.
29
- 2. Make the change (run the action, reload, or ask me to).
30
- 3. wait_for_change { target: "${target}", mode: "settle" } so you check after the screen has finished updating, not mid-render.
31
- 4. screen_diff { a: <before>, b: <after> } and look at where it changed.
32
- 5. If the expectation mentions text, find_text { target: "${target}", query: <that text> } to confirm it is really on screen.
33
- Say whether the change happened, whether anything changed that should not have, and show the evidence.`,
34
- reviewRecording: (path) => `Review the recording at ${path} and tell me what happens in it.
35
-
36
- 1. get_media_info { input: "${path}" } for length and resolution.
37
- 2. contact_sheet { input: "${path}" } for an overview of the whole recording in one image.
38
- 3. sample_frames { input: "${path}", mode: "scenes" } to look closely at each change.
39
- 4. If there is on-screen text worth quoting, find_text on the relevant frame.
40
- Give a timestamped summary of the main steps and anything that looks wrong.`,
41
- documentSteps: (target, task) => `Document ${task ? `how to ${task}` : "what I do next"} as a step-by-step guide.
42
-
43
- 1. start_recording { target: "${target}", events: true } so every click and shortcut is logged, then do the task (or ask me to). Between phases, add_marker { sessionId: <id>, label: <phase name> } so the guide gets section headings. Then stop_recording.
44
- 2. step_guide { sessionId: <session id>, title: <what the guide teaches> }. It writes guide.md (with an images folder) and a self-contained guide.html: one screenshot per step, the click ringed, captioned from the text under it, secrets boxed out. Typed text is never logged; say what to type in the captions yourself.
45
- 3. Read the returned steps and rewrite any vague caption ("Click the marked spot") in guide.md, using the screenshot to name the control.
46
- Report the guide paths, the steps, and anything you would check before sharing it.`,
47
- };
48
- export function registerPrompts(server) {
49
- server.registerPrompt("bug-repro-clip", {
50
- title: "Record a bug reproduction",
51
- description: "Record a target, find the bug moment, redact secrets, trim, annotate, and export a GIF for an issue.",
52
- argsSchema: {
53
- target: z.string().optional().describe("What to record, e.g. window:My App (default: full)."),
54
- notes: z.string().optional().describe("What the bug is."),
55
- },
56
- }, ({ target, notes }) => message(PROMPT_TEXT.bugReproClip(target || "full", notes ?? "")));
57
- server.registerPrompt("file-bug-report", {
58
- title: "File a bug report",
59
- description: "Record a repro with input events, then package it with bug_report: redacted clip, GIF, steps, error text, and report.md.",
60
- argsSchema: {
61
- target: z.string().optional().describe("What to record, e.g. window:My App (default: full)."),
62
- notes: z.string().optional().describe("What the bug is."),
63
- expected: z.string().optional().describe("What should happen instead."),
64
- },
65
- }, ({ target, notes, expected }) => message(PROMPT_TEXT.fileBugReport(target || "full", notes ?? "", expected ?? "")));
66
- server.registerPrompt("demo-gif", {
67
- title: "Make a demo GIF",
68
- description: "Record a feature walkthrough and export a GIF small enough for a README or PR.",
69
- argsSchema: {
70
- target: z.string().optional().describe("What to record (default: full)."),
71
- maxMB: z.string().optional().describe("Size budget in MB (default 10)."),
72
- },
73
- }, ({ target, maxMB }) => message(PROMPT_TEXT.demoGif(target || "full", maxMB || "10")));
74
- server.registerPrompt("verify-ui-change", {
75
- title: "Verify a UI change",
76
- description: "Screenshot before, make the change, wait for the screen to settle, diff, and check the text.",
77
- argsSchema: {
78
- target: z.string().optional().describe("What to watch (default: full)."),
79
- expectation: z.string().optional().describe("What should change."),
80
- },
81
- }, ({ target, expectation }) => message(PROMPT_TEXT.verifyUiChange(target || "full", expectation ?? "")));
82
- server.registerPrompt("review-recording", {
83
- title: "Review a recording",
84
- description: "Summarize what happens in a recording, with timestamps, using a contact sheet and scene frames.",
85
- argsSchema: { path: z.string().describe("Path to the recording.") },
86
- }, ({ path }) => message(PROMPT_TEXT.reviewRecording(path)));
87
- server.registerPrompt("document-steps", {
88
- title: "Document what I just did",
89
- description: "Record a task with input events and markers, then turn it into a step-by-step guide with step_guide.",
90
- argsSchema: {
91
- target: z.string().optional().describe("What to record (default: full)."),
92
- task: z.string().optional().describe("The task the guide teaches."),
93
- },
94
- }, ({ target, task }) => message(PROMPT_TEXT.documentSteps(target || "full", task ?? "")));
95
- }