@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
@@ -0,0 +1,86 @@
1
+ import { z } from "zod";
2
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
+ import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
5
+ import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
6
+ import { runEditJob } from "../utils/jobs.js";
7
+ import { parseSrt, normalizeCues, formatSrt } from "../utils/captions.js";
8
+ import { buildCutIdleArgs, MAX_CUTS } from "../utils/idle.js";
9
+ import { planTranscriptCuts, retimeCues } from "../utils/transcriptCut.js";
10
+ import { editOutputExt, assertEditContainer } from "../utils/media.js";
11
+ import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
12
+ const inputSchema = {
13
+ input: z.string().min(1).describe("Path to the source video."),
14
+ srt: z.string().min(1).describe("Its .srt (transcribe; words: true for word timing)."),
15
+ remove: z
16
+ .array(z.union([z.number().int().min(1).max(99999), z.string().min(1)]))
17
+ .optional()
18
+ .describe("Cue numbers, or transcript text quoted exactly (must occur once)."),
19
+ fillers: z.boolean().optional().describe("Also cut fillers (um, uh...) that have their own cue."),
20
+ dryRun: z.boolean().optional().describe("Only report the cuts."),
21
+ output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
22
+ overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
23
+ };
24
+ export function register(server) {
25
+ server.registerTool("cut_by_transcript", {
26
+ title: "Cut By Transcript",
27
+ description: "Edit a video by its transcript: cut quoted text, cue numbers, or fillers. Also writes the re-timed .srt.",
28
+ inputSchema,
29
+ outputSchema: looseOutput({ cuts: z.array(z.unknown()), removedSec: z.number() }),
30
+ annotations: WRITES_FILE,
31
+ }, async (args, extra) => {
32
+ try {
33
+ requireFfmpeg();
34
+ for (const f of [args.input, args.srt])
35
+ if (!existsSync(f))
36
+ throw new ScreencastError(`File not found: ${f}`);
37
+ if (!args.remove?.length && !args.fillers)
38
+ throw new ScreencastError("Nothing to cut: pass remove and/or fillers: true.");
39
+ const info = await probeMedia(args.input);
40
+ const duration = info.durationSec;
41
+ if (duration === null || !info.videoCodec)
42
+ throw new ScreencastError(`Not a readable video: ${args.input}`);
43
+ const cues = normalizeCues(parseSrt(readFileSync(args.srt, "utf8")));
44
+ if (cues.length === 0)
45
+ throw new ScreencastError(`No cues in ${args.srt}.`);
46
+ const { cuts, skippedFillers } = planTranscriptCuts(cues, { remove: args.remove, fillers: args.fillers });
47
+ if (cuts.length > MAX_CUTS)
48
+ throw new ScreencastError(`Too many cuts (${cuts.length}, max ${MAX_CUTS}); cut in batches.`);
49
+ const removedSec = Number(cuts.reduce((s, c) => s + Math.min(c.end, duration) - Math.min(c.start, duration), 0).toFixed(2));
50
+ const retimed = retimeCues(cues, cuts);
51
+ const notes = [
52
+ cuts.length === 0 && "Nothing matched; nothing to cut.",
53
+ skippedFillers > 0 && `${skippedFillers} filler(s) inside longer cues were kept; transcribe with words: true to cut them.`,
54
+ cuts.some((c) => !c.exact) && "Some edges were estimated inside a cue; transcribe with words: true for word timing.",
55
+ ].filter(Boolean);
56
+ const summary = {
57
+ cuts,
58
+ removedSec,
59
+ originalSec: Number(duration.toFixed(2)),
60
+ newDurationSec: Number((duration - removedSec).toFixed(2)),
61
+ ...(notes.length ? { note: notes.join(" ") } : {}),
62
+ };
63
+ if (args.dryRun || cuts.length === 0) {
64
+ const text = retimed.map((c) => c.text.replace(/\n/g, " ")).join(" ");
65
+ return okResponse({ ...summary, ...(cuts.length ? { dryRun: true } : {}), text: text.length > 4000 ? `${text.slice(0, 4000)}…` : text });
66
+ }
67
+ assertEditContainer(args.output);
68
+ const ext = editOutputExt(args.input);
69
+ const output = resolveOutput(args.output, subdir("edits"), `cut-transcript-${stamp()}-${rand()}${ext}`, args.overwrite);
70
+ const srtPath = output.replace(/\.[^.\\/]+$/, "") + ".srt";
71
+ if (!args.overwrite && existsSync(srtPath))
72
+ throw new ScreencastError(`Output already exists: ${srtPath}. Pass overwrite: true to replace it.`);
73
+ await runEditJob(buildCutIdleArgs(args.input, output, cuts, info.audioCodec !== null), {
74
+ output,
75
+ durationSec: duration - removedSec,
76
+ inputDurationSec: duration,
77
+ extra,
78
+ });
79
+ writeFileSync(srtPath, formatSrt(retimed));
80
+ return okResponse({ outputPath: output, srtPath, ...summary });
81
+ }
82
+ catch (error) {
83
+ return errorResponse(error);
84
+ }
85
+ });
86
+ }
@@ -8,6 +8,8 @@ import { detectFfmpeg, hasFilter, wgcAvailable } from "../utils/ffmpeg.js";
8
8
  import { allowedOutputDirs, envAllowedDirs, homeRoot } from "../utils/paths.js";
9
9
  import { FFMPEG_FEATURE_MAJOR, KEY_FILTERS, devicesText, envSettings, locate, ocrStatus, parseDevices, parseFfmpegVersion, versionText, } from "../utils/capabilities.js";
10
10
  import { parseToolsets, SELECTABLE_TOOLSETS } from "../utils/toolsets.js";
11
+ import { ttsStatus } from "../utils/narrate.js";
12
+ import { probeHwEncoders } from "../utils/gpu.js";
11
13
  const { version: serverVersion } = createRequire(import.meta.url)("../../package.json");
12
14
  const binary = z.looseObject({
13
15
  found: z.boolean(),
@@ -87,10 +89,19 @@ export function register(server) {
87
89
  if (process.platform !== "win32") {
88
90
  problems.push("Not Windows: capture (screenshot, start_recording, list_targets) and OCR are unavailable; the watch and edit tools work.");
89
91
  }
90
- const ocr = await ocrStatus();
92
+ const gpu = tools
93
+ ? {
94
+ ddagrab: process.platform === "win32" && hasFilter("ddagrab"),
95
+ encoders: await probeHwEncoders(tools.ffmpeg),
96
+ }
97
+ : null;
98
+ const [ocr, tts] = await Promise.all([ocrStatus(), ttsStatus()]);
91
99
  if (process.platform === "win32" && !ocr.available) {
92
100
  problems.push(`Windows OCR unavailable: find_text cannot read the screen. ${ocr.error ?? "Install an OCR language (Settings > Time & language > Language)."}`);
93
101
  }
102
+ if (process.platform === "win32" && !tts.available) {
103
+ problems.push(`Windows speech unavailable: narrate cannot speak. ${tts.error ?? ""} Install a voice (Settings > Time & language > Speech).`.replace(/\s+/g, " "));
104
+ }
94
105
  const env = envSettings();
95
106
  const model = env.SCREENCAST_WHISPER_MODEL;
96
107
  if (model && !existsSync(model))
@@ -113,7 +124,9 @@ export function register(server) {
113
124
  filters,
114
125
  devices,
115
126
  wgc: { available: filters.gfxcapture === true },
127
+ ...(gpu ? { gpu } : {}),
116
128
  ocr,
129
+ tts,
117
130
  storage: {
118
131
  home,
119
132
  homeExists: existsSync(home),
@@ -0,0 +1,173 @@
1
+ import { z } from "zod";
2
+ import { join } from "node:path";
3
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
6
+ import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
7
+ import { requireFfmpeg, runFfmpeg, runCapture, probeMedia, hasFilter } from "../utils/ffmpeg.js";
8
+ import { jobTimeoutMs, progressReporter } from "../utils/jobs.js";
9
+ import { buildSceneScanArgs, parseSceneScan, buildSampleAtTimestampArgs } from "../utils/media.js";
10
+ import { readFrames } from "../utils/ocrScan.js";
11
+ import { ocrStatus } from "../utils/capabilities.js";
12
+ import { parseEventsJsonl } from "../utils/events.js";
13
+ import { resolveWhisperModel, buildTranscribeArgs, parseSrt, normalizeCues } from "../utils/captions.js";
14
+ import { subdir, tempPath } from "../utils/paths.js";
15
+ import { DEFAULT_INDEX_FRAMES, DEFAULT_INDEX_THRESHOLD, INDEX_VERSION, MAX_INDEX_FRAMES, attach, cueTexts, eventTexts, fingerprintFile, findIndex, indexWritePath, keyframeTime, markerTexts, mergeSegments, planKeyframes, readIndex, resolveRecording, sameFingerprint, segmentsFrom, writeIndex, } from "../utils/recordingIndex.js";
16
+ const OCR_BATCH = 8;
17
+ const inputSchema = {
18
+ input: z.string().optional().describe("Recording path."),
19
+ sessionId: z.string().optional().describe("Or a stopped session id."),
20
+ sceneThreshold: z.number().gt(0).lt(1).optional().describe(`Change starting a segment (default ${DEFAULT_INDEX_THRESHOLD}).`),
21
+ maxFrames: z.number().int().min(1).max(MAX_INDEX_FRAMES).optional().describe(`Keyframes to OCR (default ${DEFAULT_INDEX_FRAMES}).`),
22
+ transcript: z.string().optional().describe("An .srt, or 'whisper' to transcribe. Default: <video>.srt if any."),
23
+ force: z.boolean().optional().describe("Re-OCR despite a matching cached index."),
24
+ };
25
+ export function register(server) {
26
+ server.registerTool("index_recording", {
27
+ title: "Index Recording",
28
+ description: "Build a recording's text timeline (<video>.index.json: OCR per scene, events, markers, transcript) " +
29
+ "for search_recording.",
30
+ inputSchema,
31
+ outputSchema: looseOutput({ indexPath: z.string(), segments: z.number() }),
32
+ annotations: WRITES_FILE,
33
+ }, async (args, extra) => {
34
+ const work = mkdtempSync(join(tmpdir(), "screencast-index-"));
35
+ try {
36
+ const { ffmpeg } = requireFfmpeg();
37
+ const source = await resolveRecording(args);
38
+ const info = await probeMedia(source.path);
39
+ const duration = info.videoDurationSec ?? info.durationSec;
40
+ if (!info.width || duration === null || !(duration > 0)) {
41
+ throw new ScreencastError(`Could not read the video size and duration of ${source.path}.`);
42
+ }
43
+ const threshold = args.sceneThreshold ?? DEFAULT_INDEX_THRESHOLD;
44
+ const maxFrames = args.maxFrames ?? DEFAULT_INDEX_FRAMES;
45
+ const edits = subdir("edits");
46
+ const outPath = indexWritePath(source.path, edits);
47
+ const fingerprint = fingerprintFile(source.path);
48
+ const report = progressReporter(extra);
49
+ const notes = [];
50
+ const existingPath = args.force ? null : findIndex(source.path, edits);
51
+ const prior = existingPath ? readIndex(existingPath) : null;
52
+ const cached = prior !== null &&
53
+ sameFingerprint(prior.fingerprint, fingerprint) &&
54
+ prior.sceneThreshold === threshold &&
55
+ prior.maxFrames === maxFrames;
56
+ let segments;
57
+ let framesRead = 0;
58
+ let ocr = false;
59
+ if (cached) {
60
+ segments = prior.segments;
61
+ framesRead = prior.framesRead;
62
+ ocr = prior.ocr;
63
+ }
64
+ else {
65
+ const scan = await runCapture(ffmpeg, buildSceneScanArgs(source.path, threshold), jobTimeoutMs(duration), {
66
+ signal: extra.signal,
67
+ });
68
+ if (scan.code !== 0)
69
+ throw new ScreencastError(`Scene scan failed (exit ${scan.code}): ${scan.stderr.trim().slice(-400)}`);
70
+ report?.(0.1);
71
+ const spans = segmentsFrom(planKeyframes(parseSceneScan(scan.stdout), duration, maxFrames), duration);
72
+ const texts = spans.map(() => []);
73
+ ocr = process.platform === "win32" && (await ocrStatus()).available;
74
+ if (ocr) {
75
+ for (let b = 0; b < spans.length; b += OCR_BATCH) {
76
+ extra.signal.throwIfAborted();
77
+ const batch = spans.slice(b, b + OCR_BATCH);
78
+ const frames = [];
79
+ for (const [i, span] of batch.entries()) {
80
+ const out = join(work, `key_${b + i}.png`);
81
+ await runFfmpeg(buildSampleAtTimestampArgs(source.path, keyframeTime(span), out), 60_000, { signal: extra.signal });
82
+ if (existsSync(out))
83
+ frames.push({ at: b + i, path: out });
84
+ }
85
+ const read = frames.length > 0 ? await readFrames(frames.map((f) => f.path), work, extra.signal) : [];
86
+ read.forEach((f, i) => (texts[frames[i].at] = f.lines.map((l) => l.text)));
87
+ framesRead += read.length;
88
+ report?.(0.1 + (0.85 * Math.min(spans.length, b + OCR_BATCH)) / spans.length);
89
+ }
90
+ }
91
+ else {
92
+ notes.push("Windows OCR is not available, so the index holds no screen text; install an OCR language (doctor).");
93
+ }
94
+ const read = spans.map((s, i) => ({ ...s, ocr: texts[i] ?? [] }));
95
+ segments = ocr ? mergeSegments(read) : read;
96
+ }
97
+ const events = source.eventsPath ? eventTexts(parseEventsJsonl(readFileSync(source.eventsPath, "utf8"))) : [];
98
+ segments = attach(segments, events, "events");
99
+ segments = attach(segments, markerTexts(source.markers), "markers");
100
+ const cues = await transcriptCues(args.transcript, source.path, info.audioCodec !== null, duration, extra.signal, notes);
101
+ if (cues !== null)
102
+ segments = attach(segments, cueTexts(cues), "transcript");
103
+ else if (cached) {
104
+ const kept = prior.segments.flatMap((s) => s.transcript ?? []);
105
+ segments = attach(segments, kept, "transcript");
106
+ }
107
+ const index = {
108
+ version: INDEX_VERSION,
109
+ video: source.path,
110
+ fingerprint,
111
+ durationSec: duration,
112
+ createdAt: new Date().toISOString(),
113
+ sceneThreshold: threshold,
114
+ maxFrames,
115
+ framesRead,
116
+ ocr,
117
+ segments,
118
+ };
119
+ mkdirSync(join(outPath, ".."), { recursive: true });
120
+ writeIndex(outPath, index);
121
+ report?.(1);
122
+ const count = (f) => segments.reduce((n, s) => n + (s[f]?.length ?? 0), 0);
123
+ return okResponse({
124
+ indexPath: outPath,
125
+ segments: segments.length,
126
+ cached,
127
+ framesRead,
128
+ durationSec: duration,
129
+ sources: {
130
+ screenLines: segments.reduce((n, s) => n + s.ocr.length, 0),
131
+ events: count("events"),
132
+ markers: count("markers"),
133
+ transcriptCues: count("transcript"),
134
+ },
135
+ ...(notes.length > 0 ? { note: notes.join(" ") } : {}),
136
+ next: "search_recording { query } returns timecoded hits; the index holds raw screen text, so treat it like the video.",
137
+ });
138
+ }
139
+ catch (error) {
140
+ return errorResponse(error);
141
+ }
142
+ finally {
143
+ rmSync(work, { recursive: true, force: true });
144
+ }
145
+ });
146
+ }
147
+ async function transcriptCues(arg, video, hasAudio, duration, signal, notes) {
148
+ if (arg === "whisper") {
149
+ if (!hasAudio) {
150
+ notes.push("The recording has no audio, so there is no transcript.");
151
+ return null;
152
+ }
153
+ if (!hasFilter("whisper")) {
154
+ throw new ScreencastError("This ffmpeg has no whisper filter.", "transcript: 'whisper' needs FFmpeg 8 built with whisper.cpp; or pass an .srt.");
155
+ }
156
+ const model = resolveWhisperModel(undefined);
157
+ const raw = tempPath(".srt");
158
+ try {
159
+ await runFfmpeg(buildTranscribeArgs(video, model, raw), jobTimeoutMs(duration), { signal });
160
+ return existsSync(raw) ? normalizeCues(parseSrt(readFileSync(raw, "utf8"))) : [];
161
+ }
162
+ finally {
163
+ rmSync(raw, { force: true });
164
+ }
165
+ }
166
+ const path = arg ?? `${video.replace(/\.[^./\\]+$/, "")}.srt`;
167
+ if (!existsSync(path)) {
168
+ if (arg !== undefined)
169
+ throw new ScreencastError(`Transcript not found: ${arg}`);
170
+ return null;
171
+ }
172
+ return normalizeCues(parseSrt(readFileSync(path, "utf8")));
173
+ }
@@ -0,0 +1,26 @@
1
+ import { z } from "zod";
2
+ import { errorResponse, okResponse } from "../utils/errors.js";
3
+ import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
4
+ import { requireFfmpeg } from "../utils/ffmpeg.js";
5
+ import { listDshowVideoDevices } from "../utils/audioDevices.js";
6
+ export function register(server) {
7
+ server.registerTool("list_video_devices", {
8
+ title: "List Video Devices",
9
+ description: "List DirectShow cameras for start_recording's webcam.device.",
10
+ inputSchema: {},
11
+ outputSchema: looseOutput({ devices: z.array(z.string()) }),
12
+ annotations: READ_ONLY,
13
+ }, async () => {
14
+ try {
15
+ requireFfmpeg();
16
+ const devices = await listDshowVideoDevices(true);
17
+ return okResponse({
18
+ devices,
19
+ note: devices.length ? `start_recording { webcam: { device: "${devices[0]}" } } records it.` : "No camera found.",
20
+ });
21
+ }
22
+ catch (error) {
23
+ return errorResponse(error);
24
+ }
25
+ });
26
+ }
@@ -0,0 +1,84 @@
1
+ import { z } from "zod";
2
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
6
+ import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
7
+ import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
8
+ import { runEditJob } from "../utils/jobs.js";
9
+ import { editOutputExt, assertEditContainer } from "../utils/media.js";
10
+ import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
11
+ import { markersOrChapters, readMarkers, writeMarkers } from "../utils/chapters.js";
12
+ import { formatSrt } from "../utils/captions.js";
13
+ import { buildNarrateArgs, narrationCues, placementWarnings, resolveLines, synthesize, wavDurationSec, MAX_RATE, MIN_RATE, } from "../utils/narrate.js";
14
+ const inputSchema = {
15
+ video: z.string().min(1).describe("Path to the video."),
16
+ lines: z
17
+ .array(z.object({
18
+ t: z.number().nonnegative().optional().describe("Seconds."),
19
+ marker: z.string().optional().describe("Or a marker label."),
20
+ text: z.string().min(1),
21
+ }))
22
+ .min(1),
23
+ voice: z.string().optional().describe("Voice name or part (doctor lists them)."),
24
+ rate: z.number().min(MIN_RATE).max(MAX_RATE).optional().describe("Default 1."),
25
+ duck: z.boolean().optional().describe("Duck the original audio (default true)."),
26
+ output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
27
+ overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
28
+ };
29
+ export function register(server) {
30
+ server.registerTool("narrate", {
31
+ title: "Narrate",
32
+ description: "Offline voiceover with the built-in Windows voices: speaks each line at its time or marker " +
33
+ "over the audio, plus an SRT.",
34
+ inputSchema,
35
+ outputSchema: OUTPUT_PATH,
36
+ annotations: WRITES_FILE,
37
+ }, async (args, extra) => {
38
+ let work = null;
39
+ try {
40
+ requireFfmpeg();
41
+ if (!existsSync(args.video))
42
+ throw new ScreencastError(`Input file not found: ${args.video}`);
43
+ const info = await probeMedia(args.video);
44
+ if (info.durationSec === null)
45
+ throw new ScreencastError(`Could not read duration of ${args.video}.`);
46
+ const needsMarkers = args.lines.some((l) => l.marker !== undefined);
47
+ const markers = needsMarkers ? (await markersOrChapters(args.video, extra.signal)).markers : [];
48
+ const lines = resolveLines(args.lines, markers);
49
+ assertEditContainer(args.output);
50
+ const output = resolveOutput(args.output, subdir("edits"), `narrated-${stamp()}-${rand()}${editOutputExt(args.video)}`, args.overwrite);
51
+ work = mkdtempSync(join(tmpdir(), "screencast-tts-"));
52
+ const wavs = lines.map((_, i) => join(work, `line-${i}.wav`));
53
+ const voice = await synthesize(lines.map((l, i) => ({ text: l.text, path: wavs[i] })), { voice: args.voice, rate: args.rate, signal: extra.signal });
54
+ const placed = lines.map((l, i) => ({ ...l, durationSec: wavDurationSec(readFileSync(wavs[i])) }));
55
+ const warnings = placementWarnings(placed, info.durationSec);
56
+ const ffArgs = buildNarrateArgs(args.video, wavs, output, placed, info.durationSec, {
57
+ hasAudio: info.audioCodec !== null,
58
+ channels: info.channels,
59
+ duck: args.duck,
60
+ });
61
+ await runEditJob(ffArgs, { output, durationSec: info.durationSec, extra });
62
+ const srtPath = output.replace(/\.[^./\\]+$/, "") + ".srt";
63
+ writeFileSync(srtPath, formatSrt(narrationCues(placed, info.durationSec)));
64
+ const inputMarkers = readMarkers(args.video);
65
+ if (inputMarkers.length > 0)
66
+ writeMarkers(output, inputMarkers);
67
+ return okResponse({
68
+ outputPath: output,
69
+ srtPath,
70
+ voice,
71
+ lines: placed.map((p) => ({ t: p.t, durationSec: Math.round(p.durationSec * 100) / 100 })),
72
+ mixedWithOriginal: info.audioCodec !== null,
73
+ ...(warnings.length ? { warnings } : {}),
74
+ });
75
+ }
76
+ catch (error) {
77
+ return errorResponse(error);
78
+ }
79
+ finally {
80
+ if (work)
81
+ rmSync(work, { recursive: true, force: true });
82
+ }
83
+ });
84
+ }
@@ -15,6 +15,7 @@ const inputSchema = {
15
15
  height: z.number().int().positive().optional().describe("Scale to this height."),
16
16
  start: z.number().nonnegative().optional().describe("Show from this second."),
17
17
  end: z.number().positive().optional().describe("Hide after this second."),
18
+ shape: z.enum(["rect", "circle"]).optional().describe("circle: centre square masked round (webcam)."),
18
19
  output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
19
20
  overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
20
21
  };
@@ -48,6 +49,7 @@ export function register(server) {
48
49
  start: args.start,
49
50
  end: args.end,
50
51
  scale,
52
+ shape: args.shape,
51
53
  durationSec,
52
54
  });
53
55
  await runEditJob(ffArgs, { output, durationSec, extra });
@@ -0,0 +1,44 @@
1
+ import { z } from "zod";
2
+ import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
3
+ import { STOPS_SESSION, looseOutput } from "../utils/toolSpec.js";
4
+ import { requireFfmpeg } from "../utils/ffmpeg.js";
5
+ import { pauseSession, probeDuration } from "../utils/lifecycle.js";
6
+ import { recordedSec } from "../utils/pause.js";
7
+ import { getStore } from "../context.js";
8
+ const r3 = (n) => Math.round(n * 1000) / 1000;
9
+ export function register(server) {
10
+ server.registerTool("pause_recording", {
11
+ title: "Pause Recording",
12
+ description: "Pause a recording; until resume_recording nothing is captured, and the gap is left out of the file, events, and markers.",
13
+ inputSchema: { sessionId: z.string().min(1).describe("From start_recording.") },
14
+ outputSchema: looseOutput({ sessionId: z.string(), status: z.string(), recordedSec: z.number() }),
15
+ annotations: STOPS_SESSION,
16
+ }, async (args) => {
17
+ try {
18
+ const store = getStore();
19
+ const record = store.get(args.sessionId);
20
+ if (!record)
21
+ throw new ScreencastError(`No session with id "${args.sessionId}".`);
22
+ if (record.status === "paused") {
23
+ return okResponse({
24
+ sessionId: record.id,
25
+ status: "paused",
26
+ recordedSec: r3(recordedSec(record.segments?.parts ?? [])),
27
+ note: "Already paused.",
28
+ });
29
+ }
30
+ const { ffprobe } = requireFfmpeg();
31
+ const res = await pauseSession(store, record, { probe: (p) => probeDuration(ffprobe, p) });
32
+ return okResponse({
33
+ sessionId: record.id,
34
+ status: "paused",
35
+ recordedSec: r3(res.recordedSec),
36
+ segments: res.record?.segments?.parts.length ?? 0,
37
+ note: "Nothing is captured until resume_recording; stop_recording joins what was recorded.",
38
+ });
39
+ }
40
+ catch (error) {
41
+ return errorResponse(error);
42
+ }
43
+ });
44
+ }