@tmhs/screencast-mcp 0.45.0 → 0.47.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 (56) hide show
  1. package/README.md +138 -82
  2. package/assets/cursor/arrow.png +0 -0
  3. package/dist/cli.js +360 -0
  4. package/dist/index.js +10 -2
  5. package/dist/prompts.js +16 -3
  6. package/dist/server.js +18 -0
  7. package/dist/tools/addMarker.js +6 -2
  8. package/dist/tools/bugReport.js +2 -2
  9. package/dist/tools/chapters.js +1 -1
  10. package/dist/tools/cursor.js +87 -0
  11. package/dist/tools/cutByTranscript.js +86 -0
  12. package/dist/tools/doctor.js +14 -1
  13. package/dist/tools/indexRecording.js +173 -0
  14. package/dist/tools/listVideoDevices.js +26 -0
  15. package/dist/tools/narrate.js +84 -0
  16. package/dist/tools/overlay.js +2 -0
  17. package/dist/tools/pauseRecording.js +44 -0
  18. package/dist/tools/pipeline.js +215 -19
  19. package/dist/tools/readEvents.js +1 -1
  20. package/dist/tools/resumeRecording.js +46 -0
  21. package/dist/tools/reviewRecording.js +1 -1
  22. package/dist/tools/searchRecording.js +73 -0
  23. package/dist/tools/startRecording.js +106 -67
  24. package/dist/tools/stepGuide.js +193 -0
  25. package/dist/tools/stopRecording.js +38 -3
  26. package/dist/tools/transcribe.js +4 -3
  27. package/dist/tools/zoom.js +1 -1
  28. package/dist/utils/audio.js +12 -4
  29. package/dist/utils/audioDevices.js +34 -4
  30. package/dist/utils/bugReport.js +1 -75
  31. package/dist/utils/captions.js +19 -6
  32. package/dist/utils/chapters.js +5 -0
  33. package/dist/utils/cursor.js +317 -0
  34. package/dist/utils/events.js +22 -4
  35. package/dist/utils/gpu.js +173 -0
  36. package/dist/utils/idle.js +10 -3
  37. package/dist/utils/keystrokes.js +2 -17
  38. package/dist/utils/lifecycle.js +85 -2
  39. package/dist/utils/media.js +4 -0
  40. package/dist/utils/monitors.js +5 -2
  41. package/dist/utils/narrate.js +224 -0
  42. package/dist/utils/pause.js +176 -0
  43. package/dist/utils/pipeline.js +154 -14
  44. package/dist/utils/recipes.js +67 -0
  45. package/dist/utils/recorder.js +163 -0
  46. package/dist/utils/recordingIndex.js +266 -0
  47. package/dist/utils/sessions.js +29 -5
  48. package/dist/utils/stepGuide.js +205 -0
  49. package/dist/utils/steps.js +88 -0
  50. package/dist/utils/targets.js +31 -7
  51. package/dist/utils/timeline.js +85 -0
  52. package/dist/utils/toolsets.js +17 -6
  53. package/dist/utils/transcriptCut.js +134 -0
  54. package/dist/utils/wgc.js +2 -2
  55. package/dist/wgcRecorder.js +1 -1
  56. package/package.json +3 -1
@@ -150,6 +150,11 @@ export function targetInputArgs(target, monitors, opts = {}) {
150
150
  }
151
151
  }
152
152
  }
153
+ export function buildWebcamInputArgs(device) {
154
+ if (device.trim().length === 0)
155
+ throw new ScreencastError("webcam device must not be empty.");
156
+ return ["-f", "dshow", "-use_wallclock_as_timestamps", "1", "-rtbufsize", "256M", "-i", `video=${device}`];
157
+ }
153
158
  export const DEFAULT_MAX_RECORDING_SEC = 3600;
154
159
  export function resolveMaxDuration(explicit, env = process.env) {
155
160
  if (explicit !== undefined)
@@ -180,26 +185,45 @@ function validateFps(fps) {
180
185
  export function captureKeyframeArgs(fps) {
181
186
  return ["-g", String(Math.max(1, Math.round(fps * 2)))];
182
187
  }
188
+ const FRAGMENTED_MP4 = ["-movflags", "+frag_keyframe+empty_moov+default_base_moof"];
183
189
  export function buildCaptureArgs(target, opts) {
184
190
  const fps = validateFps(opts.fps ?? DEFAULT_FPS);
185
191
  const quality = opts.quality ?? DEFAULT_QUALITY;
186
192
  const monitors = opts.monitors ?? [];
187
193
  const cap = validateMaxDuration(opts.maxDurationSec ?? 0);
194
+ const capArgs = cap > 0 ? ["-t", String(cap)] : [];
195
+ const cam = opts.webcam;
196
+ const camInput = opts.audio ? 2 : 1;
188
197
  return [
189
198
  "-y",
190
- "-f", "gdigrab",
191
- "-framerate", String(fps),
192
- ...targetInputArgs(target, monitors, { evenSize: true }),
199
+ ...(opts.videoInput ?? [
200
+ "-f", "gdigrab",
201
+ "-framerate", String(fps),
202
+ ...(opts.drawMouse === false ? ["-draw_mouse", "0"] : []),
203
+ ...targetInputArgs(target, monitors, { evenSize: true }),
204
+ ]),
193
205
  ...buildAudioInputArgs(opts.audio),
194
- ...(target.kind === "full" && monitors.length === 0
206
+ ...(cam ? buildWebcamInputArgs(cam.device) : []),
207
+ ...(cam ? ["-map", "0:v", ...(opts.audio ? ["-map", "1:a"] : [])] : []),
208
+ ...(!opts.videoInput && target.kind === "full" && monitors.length === 0
195
209
  ? ["-vf", "crop=trunc(iw/2)*2:trunc(ih/2)*2"]
196
210
  : []),
197
- ...resolveQuality(quality),
211
+ ...(opts.videoCodec ?? resolveQuality(quality)),
198
212
  ...captureKeyframeArgs(fps),
199
213
  ...(opts.audio ? ["-c:a", "aac", "-b:a", "160k"] : []),
200
- "-movflags", "+frag_keyframe+empty_moov+default_base_moof",
201
- ...(cap > 0 ? ["-t", String(cap)] : []),
214
+ ...FRAGMENTED_MP4,
215
+ ...capArgs,
202
216
  opts.output,
217
+ ...(cam
218
+ ? [
219
+ "-map", `${camInput}:v`,
220
+ ...(cam.codec ?? resolveQuality(quality)),
221
+ ...captureKeyframeArgs(fps),
222
+ ...FRAGMENTED_MP4,
223
+ ...capArgs,
224
+ cam.output,
225
+ ]
226
+ : []),
203
227
  ];
204
228
  }
205
229
  export const SCREENSHOT_GRAB_FPS = 30;
@@ -0,0 +1,85 @@
1
+ const r3 = (v) => Math.round(v * 1000) / 1000;
2
+ export function cutShift(t, spans) {
3
+ let removed = 0;
4
+ for (const s of spans) {
5
+ if (t <= s.start)
6
+ break;
7
+ removed += Math.min(t, s.end) - s.start;
8
+ }
9
+ return removed;
10
+ }
11
+ export function mapTime(t, ops) {
12
+ let v = t;
13
+ for (const op of ops) {
14
+ if (op.op === "trim") {
15
+ if (v < op.start || v >= op.end)
16
+ return null;
17
+ v -= op.start;
18
+ }
19
+ else if (op.op === "speed")
20
+ v /= op.factor;
21
+ else
22
+ v -= cutShift(v, op.spans);
23
+ }
24
+ return v;
25
+ }
26
+ export function mapWindow(from, to, ops) {
27
+ let a = from;
28
+ let b = to;
29
+ for (const op of ops) {
30
+ if (op.op === "trim") {
31
+ a = Math.max(a, op.start) - op.start;
32
+ b = Math.min(b, op.end) - op.start;
33
+ }
34
+ else if (op.op === "speed") {
35
+ a /= op.factor;
36
+ b /= op.factor;
37
+ }
38
+ else {
39
+ a -= cutShift(a, op.spans);
40
+ b -= cutShift(b, op.spans);
41
+ }
42
+ if (b <= a)
43
+ return null;
44
+ }
45
+ return [a, b];
46
+ }
47
+ export function mapSpans(spans, ops) {
48
+ return spans.flatMap((s) => {
49
+ const w = mapWindow(s.start, s.end, ops);
50
+ return w ? [{ start: r3(w[0]), end: r3(w[1]) }] : [];
51
+ });
52
+ }
53
+ export function retimeCues(cues, ops) {
54
+ return cues.flatMap((c) => {
55
+ const w = mapWindow(c.start, c.end, ops);
56
+ return w && w[1] - w[0] >= 0.05 ? [{ ...c, start: r3(w[0]), end: r3(w[1]) }] : [];
57
+ });
58
+ }
59
+ const ASS_TIME = /^(\d+):(\d{2}):(\d{2})\.(\d{2})$/;
60
+ const assSec = (s) => {
61
+ const m = s.trim().match(ASS_TIME);
62
+ return m ? Number(m[1]) * 3600 + Number(m[2]) * 60 + Number(m[3]) + Number(m[4]) / 100 : null;
63
+ };
64
+ const assTime = (sec) => {
65
+ const cs = Math.round(sec * 100);
66
+ const pad = (n) => String(n).padStart(2, "0");
67
+ return `${Math.floor(cs / 360_000)}:${pad(Math.floor((cs % 360_000) / 6000))}:${pad(Math.floor((cs % 6000) / 100))}.${pad(cs % 100)}`;
68
+ };
69
+ export function retimeAss(text, ops) {
70
+ return text
71
+ .split(/\r?\n/)
72
+ .flatMap((line) => {
73
+ const m = line.match(/^(Dialogue:\s*[^,]*,)([^,]*),([^,]*),(.*)$/);
74
+ if (!m)
75
+ return [line];
76
+ const [, head, s, e, rest] = m;
77
+ const a = assSec(s);
78
+ const b = assSec(e);
79
+ if (a === null || b === null)
80
+ return [line];
81
+ const w = mapWindow(a, b, ops);
82
+ return w && w[1] - w[0] >= 0.05 ? [`${head}${assTime(w[0])},${assTime(w[1])},${rest}`] : [];
83
+ })
84
+ .join("\n");
85
+ }
@@ -3,6 +3,8 @@ export const TOOLSETS = {
3
3
  capture: [
4
4
  "start_recording",
5
5
  "stop_recording",
6
+ "pause_recording",
7
+ "resume_recording",
6
8
  "save_replay",
7
9
  "list_sessions",
8
10
  "get_session",
@@ -11,6 +13,7 @@ export const TOOLSETS = {
11
13
  "screenshot",
12
14
  "list_targets",
13
15
  "list_audio_devices",
16
+ "list_video_devices",
14
17
  ],
15
18
  watch: [
16
19
  "sample_frames",
@@ -18,6 +21,8 @@ export const TOOLSETS = {
18
21
  "screen_diff",
19
22
  "wait_for_change",
20
23
  "find_text",
24
+ "index_recording",
25
+ "search_recording",
21
26
  "review_recording",
22
27
  "player_frames",
23
28
  ],
@@ -34,10 +39,12 @@ export const TOOLSETS = {
34
39
  "compress",
35
40
  "redact_region",
36
41
  "cut_idle",
42
+ "cut_by_transcript",
37
43
  ],
38
44
  produce: [
39
45
  "callout",
40
46
  "keystroke_overlay",
47
+ "cursor",
41
48
  "backdrop",
42
49
  "overlay",
43
50
  "zoom",
@@ -49,8 +56,9 @@ export const TOOLSETS = {
49
56
  "burn_subtitles",
50
57
  "chapters",
51
58
  "bug_report",
59
+ "step_guide",
52
60
  ],
53
- audio: ["extract_audio", "normalize_audio", "denoise", "transcribe", "music_bed"],
61
+ audio: ["extract_audio", "normalize_audio", "denoise", "transcribe", "music_bed", "narrate"],
54
62
  };
55
63
  export const SELECTABLE_TOOLSETS = Object.keys(TOOLSETS).filter((t) => t !== "core");
56
64
  export function toolsetOf(tool) {
@@ -83,19 +91,22 @@ export function serverInstructions(selection) {
83
91
  lines.push("Capture: screenshot for a still; start_recording -> (do the task) -> stop_recording for video " +
84
92
  "(events: true also logs clicks for read_events and zoom). For flaky failures, start_recording " +
85
93
  "{ replayBufferSec } keeps a rolling buffer and save_replay writes the last seconds after the fact. " +
94
+ "pause_recording/resume_recording skip setup; backend ddagrab uses the GPU. " +
86
95
  "Never start a recording the user did not ask for.");
87
96
  }
88
97
  if (on.has("watch")) {
89
98
  lines.push("Look: contact_sheet is the cheapest overview, sample_frames (mode scenes) for detail, find_text for OCR " +
90
- "and secret finding, wait_for_change instead of sleeping, screen_diff to compare two states.");
99
+ "and secret finding, wait_for_change instead of sleeping, screen_diff to compare two states. " +
100
+ "Long recording: index_recording once, then search_recording finds moments as text.");
91
101
  }
92
102
  if (on.has("edit")) {
93
- lines.push("Edit: prefer one pipeline call (trim, crop, scale, speed, redact, callout, keystroke_overlay, reframe, zoom, backdrop, then " +
94
- "export_preset or export_gif) over chaining single-edit tools; each tool call re-encodes. trim = one " +
103
+ lines.push("Edit: prefer one pipeline call (trim, crop, scale, speed, cut_idle, redact, callout, keystroke_overlay, reframe, zoom, backdrop, " +
104
+ "audio, burn_subtitles, then export_preset or export_gif) over chaining single-edit tools; each tool call re-encodes. " +
105
+ "To polish a raw recording, start from pipeline recipe pr_demo, tutorial or social_reel (dryRun shows its steps). trim = one " +
95
106
  "segment, clip = several files; export_gif for size-bounded GIF/WebP, compress for a smaller mp4.");
96
107
  }
97
108
  if (on.has("produce")) {
98
- lines.push("Produce: callout, zoom, keystroke_overlay, backdrop, overlay, title_card, xfade_transition, assemble_highlights, burn_subtitles, export_preset.");
109
+ lines.push("Produce: callout, zoom, keystroke_overlay, cursor, backdrop, overlay, title_card, xfade_transition, assemble_highlights, burn_subtitles, export_preset.");
99
110
  }
100
111
  if (on.has("produce")) {
101
112
  lines.push("Bug reports: bug_report turns a recording (path or sessionId) into one redacted folder: clip, GIF, " +
@@ -110,7 +121,7 @@ export function serverInstructions(selection) {
110
121
  lines.push(`Markers: ${marks.filter(Boolean).join(" ")}`);
111
122
  }
112
123
  if (on.has("audio")) {
113
- lines.push("Audio: extract_audio, normalize_audio, denoise, music_bed; transcribe makes an SRT for burn_subtitles.");
124
+ lines.push("Audio: extract_audio, normalize_audio, denoise, music_bed, narrate (offline voiceover); transcribe makes an SRT for burn_subtitles (words: true for word timing, then cut_by_transcript cuts by quoting it).");
114
125
  }
115
126
  lines.push("Outputs go under SCREENCAST_HOME unless a call names a path; times are seconds and positions video pixels. " +
116
127
  "Screen content can include secrets: redact (find_text redact: true -> redact_region) before sharing. " +
@@ -0,0 +1,134 @@
1
+ import { ScreencastError } from "./errors.js";
2
+ export const FILLERS = ["um", "umm", "uh", "uhh", "uhm", "erm", "er", "ah", "hmm", "hm", "mm", "mhm"];
3
+ export const FILLER_REACH = 0.5;
4
+ export const normWord = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "");
5
+ const r3 = (n) => Number(n.toFixed(3));
6
+ export function cueWords(cues) {
7
+ const out = [];
8
+ cues.forEach((c, ci) => {
9
+ const text = c.text.replace(/\s+/g, " ").trim();
10
+ const toks = [...text.matchAll(/\S+/g)];
11
+ const len = text.length || 1;
12
+ const dur = c.end - c.start;
13
+ toks.forEach((m, k) => {
14
+ const at = m.index;
15
+ out.push({
16
+ cue: ci,
17
+ raw: m[0],
18
+ norm: normWord(m[0]),
19
+ start: k === 0 ? c.start : c.start + (at / len) * dur,
20
+ end: k === toks.length - 1 ? c.end : c.start + ((at + m[0].length) / len) * dur,
21
+ first: k === 0,
22
+ last: k === toks.length - 1,
23
+ });
24
+ });
25
+ });
26
+ return out;
27
+ }
28
+ const spoken = (words) => words.flatMap((w, i) => (w.norm ? [i] : []));
29
+ export function findQuote(words, quote) {
30
+ const q = quote.split(/\s+/).map(normWord).filter(Boolean);
31
+ if (q.length === 0)
32
+ throw new ScreencastError(`Quote "${quote}" has no words to match.`);
33
+ const idx = spoken(words);
34
+ const hits = [];
35
+ for (let i = 0; i + q.length <= idx.length; i++) {
36
+ if (q.every((w, k) => words[idx[i + k]].norm === w))
37
+ hits.push([idx[i], idx[i + q.length - 1]]);
38
+ }
39
+ return hits;
40
+ }
41
+ function rangeCut(words, from, to) {
42
+ let end = to;
43
+ while (words[end + 1] && !words[end + 1].norm && words[end + 1].cue === words[to].cue)
44
+ end++;
45
+ const a = words[from];
46
+ const b = words[end];
47
+ return {
48
+ start: r3(a.start),
49
+ end: r3(b.end),
50
+ text: words.slice(from, end + 1).map((w) => w.raw).join(" "),
51
+ exact: a.first && b.last,
52
+ };
53
+ }
54
+ export function mergeCuts(cuts) {
55
+ const sorted = [...cuts].filter((c) => c.end - c.start > 0.001).sort((a, b) => a.start - b.start);
56
+ const out = [];
57
+ for (const c of sorted) {
58
+ const prev = out[out.length - 1];
59
+ if (prev && c.start <= prev.end + 0.01) {
60
+ if (c.end > prev.end) {
61
+ prev.end = c.end;
62
+ prev.text = `${prev.text} ${c.text}`;
63
+ }
64
+ prev.exact &&= c.exact;
65
+ }
66
+ else
67
+ out.push({ ...c });
68
+ }
69
+ return out;
70
+ }
71
+ export function planTranscriptCuts(cues, req) {
72
+ const words = cueWords(cues);
73
+ const cuts = [];
74
+ for (const r of req.remove ?? []) {
75
+ if (typeof r === "number") {
76
+ const c = cues[r - 1];
77
+ if (!Number.isInteger(r) || !c)
78
+ throw new ScreencastError(`No cue ${r}: the transcript has cues 1-${cues.length}.`);
79
+ cuts.push({ start: r3(c.start), end: r3(c.end), text: c.text.replace(/\s+/g, " "), exact: true });
80
+ continue;
81
+ }
82
+ const hits = findQuote(words, r);
83
+ if (hits.length === 0)
84
+ throw new ScreencastError(`Quote not found in the transcript: "${r}".`);
85
+ if (hits.length > 1) {
86
+ throw new ScreencastError(`Quote "${r}" occurs ${hits.length} times; quote more words or use cue numbers.`);
87
+ }
88
+ cuts.push(rangeCut(words, ...hits[0]));
89
+ }
90
+ let skippedFillers = 0;
91
+ if (req.fillers) {
92
+ const fill = new Set(FILLERS);
93
+ words.forEach((w) => {
94
+ if (!fill.has(w.norm))
95
+ return;
96
+ const alone = words.every((o) => o.cue !== w.cue || o === w || !o.norm);
97
+ if (!alone) {
98
+ skippedFillers++;
99
+ return;
100
+ }
101
+ const cue = cues[w.cue];
102
+ const start = Math.max(cues[w.cue - 1]?.end ?? 0, cue.start - FILLER_REACH);
103
+ const end = Math.min(cues[w.cue + 1]?.start ?? Infinity, cue.end + FILLER_REACH);
104
+ cuts.push({ start: r3(Math.min(start, cue.start)), end: r3(Math.max(end, cue.end)), text: words.filter((o) => o.cue === w.cue).map((o) => o.raw).join(" "), exact: true });
105
+ });
106
+ }
107
+ return { cuts: mergeCuts(cuts), skippedFillers };
108
+ }
109
+ export function mapTime(t, cuts) {
110
+ let shift = 0;
111
+ for (const c of cuts) {
112
+ if (t <= c.start)
113
+ break;
114
+ shift += Math.min(t, c.end) - c.start;
115
+ }
116
+ return t - shift;
117
+ }
118
+ export function retimeCues(cues, cuts) {
119
+ const words = cueWords(cues);
120
+ const inCut = (w) => cuts.some((c) => w.start >= c.start - 0.0005 && w.end <= c.end + 0.0005);
121
+ const out = [];
122
+ cues.forEach((c, ci) => {
123
+ const own = words.filter((w) => w.cue === ci);
124
+ const kept = own.filter((w) => !inCut(w));
125
+ if (!kept.some((w) => w.norm))
126
+ return;
127
+ const text = kept.length === own.length ? c.text : kept.map((w) => w.raw).join(" ");
128
+ const start = r3(mapTime(c.start, cuts));
129
+ const end = r3(mapTime(c.end, cuts));
130
+ if (end > start)
131
+ out.push({ start, end, text });
132
+ });
133
+ return out;
134
+ }
package/dist/utils/wgc.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ScreencastError } from "./errors.js";
2
- export function buildWgcGrabArgs(hwnd, fps) {
2
+ export function buildWgcGrabArgs(hwnd, fps, cursor = true) {
3
3
  if (!Number.isSafeInteger(hwnd) || hwnd <= 0)
4
4
  throw new ScreencastError("Invalid window handle.");
5
5
  return [
6
6
  "-hide_banner", "-nostats", "-loglevel", "info",
7
7
  "-f", "lavfi",
8
- "-i", `gfxcapture=hwnd=${hwnd}:max_framerate=${fps},hwdownload,format=bgra,crop=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,
8
+ "-i", `gfxcapture=hwnd=${hwnd}:max_framerate=${fps}${cursor ? "" : ":capture_cursor=0"},hwdownload,format=bgra,crop=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,
9
9
  "-flush_packets", "1",
10
10
  "-f", "rawvideo", "-",
11
11
  ];
@@ -5,7 +5,7 @@ const FIRST_FRAME_TIMEOUT_MS = 10_000;
5
5
  const MAX_QUEUED_FRAMES = 4;
6
6
  const cfg = JSON.parse(process.argv[2] ?? "{}");
7
7
  const log = (s) => process.stderr.write(s.endsWith("\n") ? s : `${s}\n`);
8
- const grab = spawn(cfg.ffmpeg, buildWgcGrabArgs(cfg.hwnd, cfg.fps), { stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
8
+ const grab = spawn(cfg.ffmpeg, buildWgcGrabArgs(cfg.hwnd, cfg.fps, cfg.cursor !== false), { stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
9
9
  const nudge = spawn("powershell", ["-NoProfile", "-NonInteractive", "-Command", nudgeScript(cfg.hwnd, 200, process.pid)], {
10
10
  stdio: "ignore",
11
11
  windowsHide: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmhs/screencast-mcp",
3
- "version": "0.45.0",
3
+ "version": "0.47.0",
4
4
  "description": "Let AI agents record the Windows screen, watch it as frames, and edit it with ffmpeg",
5
5
  "mcpName": "io.github.TMHSDigital/screencast-mcp",
6
6
  "type": "module",
@@ -27,6 +27,8 @@
27
27
  "test:watch": "vitest",
28
28
  "eval": "tsx evals/run.ts",
29
29
  "typecheck:evals": "tsc -p evals/tsconfig.json",
30
+ "docs": "tsc && node scripts/build-tool-docs.mjs",
31
+ "docs:check": "tsc && node scripts/build-tool-docs.mjs --check",
30
32
  "prepublishOnly": "npm run build"
31
33
  },
32
34
  "author": "TMHSDigital",