@tmhs/screencast-mcp 0.49.1 → 0.50.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 +13 -8
  2. package/dist/index.js +550 -106
  3. package/dist/wgcRecorder.js +15 -139
  4. package/package.json +8 -4
  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
@@ -1,132 +0,0 @@
1
- import { z } from "zod";
2
- import { existsSync } from "node:fs";
3
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
- import { STOPS_SESSION, looseOutput } from "../utils/toolSpec.js";
5
- import { probeDuration, probeMedia, requireFfmpeg } from "../utils/ffmpeg.js";
6
- import { stopSession } from "../utils/lifecycle.js";
7
- import { getStore } from "../context.js";
8
- import { foreignStopRefusal, ownerAlive } from "../utils/sessions.js";
9
- import { finishReplay } from "../utils/replay.js";
10
- import { webcamPlacement } from "../utils/pause.js";
11
- function replayReport(r) {
12
- return {
13
- saved: r.saved,
14
- discarded: r.discarded,
15
- ...(r.save ? { durationSec: r.save.durationSec, eventsPath: r.save.eventsPath } : {}),
16
- ...(r.error ? { error: r.error, note: "The buffer was kept; call stop_recording with save: true again, or save_replay." } : {}),
17
- };
18
- }
19
- async function webcamReport(cam, output) {
20
- if (cam.error || !existsSync(cam.path))
21
- return { error: cam.error ?? `No webcam file was written (${cam.path}).` };
22
- const size = async (p) => {
23
- try {
24
- const info = await probeMedia(p);
25
- return info.width && info.height ? { width: info.width, height: info.height } : null;
26
- }
27
- catch {
28
- return null;
29
- }
30
- };
31
- const [screen, camSize] = await Promise.all([size(output), size(cam.path)]);
32
- const circle = cam.shape === "circle";
33
- const place = screen && camSize ? webcamPlacement(screen, circle ? { width: 1, height: 1 } : camSize, cam.corner, cam.size) : null;
34
- return {
35
- path: cam.path,
36
- ...(place
37
- ? {
38
- overlay: {
39
- input: output,
40
- overlay: cam.path,
41
- x: place.x,
42
- y: place.y,
43
- ...(circle ? { height: place.height, shape: "circle" } : { width: place.width }),
44
- },
45
- note: "Aligned with the recording: pass `overlay` to the overlay tool (any corner or size works).",
46
- }
47
- : {}),
48
- };
49
- }
50
- const inputSchema = {
51
- sessionId: z.string().min(1).describe("Session id returned by start_recording."),
52
- save: z
53
- .boolean()
54
- .optional()
55
- .describe("Replay buffer: write it all to outputPath first (default: discard)."),
56
- };
57
- export function register(server) {
58
- server.registerTool("stop_recording", {
59
- title: "Stop Recording",
60
- description: "Stop a recording gracefully so the file is finalized; returns the path and duration.",
61
- inputSchema,
62
- outputSchema: looseOutput({
63
- sessionId: z.string(),
64
- status: z.string(),
65
- outputPath: z.string(),
66
- durationSec: z.number().nullable(),
67
- }),
68
- annotations: STOPS_SESSION,
69
- }, async (args) => {
70
- try {
71
- const store = getStore();
72
- const record = store.get(args.sessionId);
73
- if (!record) {
74
- throw new ScreencastError(`No session with id "${args.sessionId}".`);
75
- }
76
- if (record.status !== "recording" && record.status !== "paused") {
77
- const replay = record.replay && existsSync(record.replay.dir)
78
- ? await finishReplay(record.replay, {
79
- save: args.save ?? false,
80
- output: record.outputPath,
81
- quality: record.quality,
82
- tools: requireFfmpeg,
83
- })
84
- : undefined;
85
- return okResponse({
86
- ...(replay ? { replay: replayReport(replay) } : {}),
87
- sessionId: record.id,
88
- status: record.status,
89
- outputPath: record.outputPath,
90
- durationSec: record.durationSec ?? null,
91
- endReason: record.endReason ?? null,
92
- note: record.endReason === "max_duration"
93
- ? `Recording already ended at its maxDurationSec cap (${record.maxDurationSec}s).`
94
- : record.endReason === "window_closed"
95
- ? "Recording already ended: the recorded window was closed."
96
- : "Session was not active; returning its recorded final state.",
97
- });
98
- }
99
- const refusal = foreignStopRefusal(record, process.pid, ownerAlive(record));
100
- if (refusal)
101
- throw new ScreencastError(refusal);
102
- const { ffprobe } = requireFfmpeg();
103
- const { record: updated, graceful, durationSec, replay, segments } = await stopSession(store, record, {
104
- reason: "stopped",
105
- probe: (path) => probeDuration(path, { ffprobe }),
106
- saveReplay: args.save,
107
- });
108
- return okResponse({
109
- sessionId: record.id,
110
- status: "stopped",
111
- outputPath: record.outputPath,
112
- durationSec: durationSec ?? null,
113
- finalizedGracefully: graceful,
114
- ...(replay ? { replay: replayReport(replay) } : {}),
115
- ...(segments && segments.count > 1 ? { segmentsJoined: segments.count } : {}),
116
- ...(segments?.error ? { segmentsError: segments.error } : {}),
117
- ...(updated?.webcam ? { webcam: await webcamReport(updated.webcam, record.outputPath) } : {}),
118
- ...(updated?.events
119
- ? { eventsPath: updated.events.path, events: updated.events.summary ?? {}, ...(updated.events.error ? { eventsError: updated.events.error } : {}) }
120
- : {}),
121
- fileExists: existsSync(record.outputPath),
122
- note: graceful
123
- ? "ffmpeg quit cleanly; file finalized."
124
- : "Process terminated by pid; fragmented mp4 keeps the file playable.",
125
- record: updated,
126
- });
127
- }
128
- catch (error) {
129
- return errorResponse(error);
130
- }
131
- });
132
- }
@@ -1,67 +0,0 @@
1
- import { z } from "zod";
2
- import { writeFileSync, rmSync } from "node:fs";
3
- import { errorResponse, okResponse } from "../utils/errors.js";
4
- import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
5
- import { requireFfmpeg } from "../utils/ffmpeg.js";
6
- import { runEditJob } from "../utils/jobs.js";
7
- import { buildTitleCardArgs, DEFAULT_TITLE_DURATION } from "../utils/produce.js";
8
- import { resolveTextFont } from "../utils/fonts.js";
9
- import { resolveOutput, subdir, stamp, rand, tempPath } from "../utils/paths.js";
10
- import { assertEditContainer } from "../utils/media.js";
11
- import { fontFileSchema } from "../utils/callout.js";
12
- const inputSchema = {
13
- text: z.string().min(1).describe("Title text. Multiple lines are allowed (use \\n)."),
14
- duration: z.number().positive().optional().describe("Card length in seconds (default 3)."),
15
- width: z.number().int().positive().optional().describe("Card width (default 1920)."),
16
- height: z.number().int().positive().optional().describe("Card height (default 1080)."),
17
- fps: z.number().int().positive().optional().describe("Card fps (default 30)."),
18
- bg: z.string().optional().describe("Background color (default black)."),
19
- fontColor: z.string().optional().describe("Text color (default white)."),
20
- fontSize: z.number().int().positive().optional().describe("Text size in px (default 96)."),
21
- bold: z.boolean().optional().describe("Use the bold weight (default true)."),
22
- fontFile: fontFileSchema,
23
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
24
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
25
- };
26
- export function register(server) {
27
- server.registerTool("title_card", {
28
- title: "Title Card",
29
- description: "Generate a title card clip (centered text on a solid background, silent audio track) to stitch " +
30
- "in with assemble_highlights. Uncoverable characters are reported in warnings.",
31
- inputSchema,
32
- outputSchema: OUTPUT_PATH,
33
- annotations: WRITES_FILE,
34
- }, async (args, extra) => {
35
- try {
36
- requireFfmpeg();
37
- assertEditContainer(args.output);
38
- const output = resolveOutput(args.output, subdir("edits"), `title-${stamp()}-${rand()}.mp4`, args.overwrite);
39
- const font = resolveTextFont(args.text, { weight: args.bold === false ? "regular" : "bold", fontFile: args.fontFile });
40
- const textFile = tempPath(".txt");
41
- writeFileSync(textFile, args.text);
42
- try {
43
- const ffArgs = buildTitleCardArgs(textFile, font.fontFile, output, {
44
- duration: args.duration,
45
- width: args.width,
46
- height: args.height,
47
- fps: args.fps,
48
- bg: args.bg,
49
- fontColor: args.fontColor,
50
- fontSize: args.fontSize,
51
- });
52
- await runEditJob(ffArgs, { output, durationSec: args.duration ?? DEFAULT_TITLE_DURATION, extra });
53
- }
54
- finally {
55
- rmSync(textFile, { force: true });
56
- }
57
- return okResponse({
58
- outputPath: output,
59
- ...((font.fallback || args.fontFile) && { fontFile: font.fontFile }),
60
- ...(font.warning && { warnings: [font.warning] }),
61
- });
62
- }
63
- catch (error) {
64
- return errorResponse(error);
65
- }
66
- });
67
- }
@@ -1,66 +0,0 @@
1
- import { z } from "zod";
2
- import { existsSync, readFileSync, rmSync, 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, runFfmpeg, probeMedia, hasFilter } from "../utils/ffmpeg.js";
6
- import { jobTimeoutMs } from "../utils/jobs.js";
7
- import { resolveWhisperModel, buildTranscribeArgs, parseSrt, normalizeCues, mergePunctuation, formatSrt, WHISPER_MODEL_ENV, } from "../utils/captions.js";
8
- import { resolveOutput, subdir, stamp, rand, tempPath } from "../utils/paths.js";
9
- const inputSchema = {
10
- input: z.string().min(1).describe("Path to the video or audio to transcribe."),
11
- model: z
12
- .string()
13
- .optional()
14
- .describe(`Path to a whisper.cpp model file (ggml-*.bin). Defaults to ${WHISPER_MODEL_ENV}.`),
15
- language: z.string().optional().describe("Spoken language code, e.g. 'en', or 'auto' (default)."),
16
- words: z.boolean().optional().describe("One word per cue, for word timing (cut_by_transcript)."),
17
- output: z.string().optional().describe("Optional output .srt path. Defaults under SCREENCAST_HOME/edits."),
18
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
19
- };
20
- export function register(server) {
21
- server.registerTool("transcribe", {
22
- title: "Transcribe Speech",
23
- description: "Transcribe a recording's speech to an SRT subtitle file, locally, with FFmpeg 8's " +
24
- "whisper filter (needs a whisper.cpp model file). Returns the SRT path and the text. " +
25
- "Pair with burn_subtitles to caption the video.",
26
- inputSchema,
27
- outputSchema: looseOutput({ srtPath: z.string(), cues: z.number().int(), text: z.string() }),
28
- annotations: WRITES_FILE,
29
- }, async (args, extra) => {
30
- try {
31
- requireFfmpeg();
32
- if (!existsSync(args.input))
33
- throw new ScreencastError(`Input file not found: ${args.input}`);
34
- if (!hasFilter("whisper")) {
35
- throw new ScreencastError("This ffmpeg has no whisper filter.", "transcribe needs FFmpeg 8 built with whisper.cpp (--enable-whisper); recent Windows builds " +
36
- "such as `winget install Gyan.FFmpeg` include it. Check with `ffmpeg -h filter=whisper`.");
37
- }
38
- const model = resolveWhisperModel(args.model);
39
- const info = await probeMedia(args.input);
40
- if (!info.audioCodec)
41
- throw new ScreencastError(`Input has no audio to transcribe: ${args.input}`);
42
- const output = resolveOutput(args.output, subdir("edits"), `captions-${stamp()}-${rand()}.srt`, args.overwrite);
43
- const raw = tempPath(".srt");
44
- try {
45
- await runFfmpeg(buildTranscribeArgs(args.input, model, raw, args.language ?? "auto", args.words), jobTimeoutMs(info.durationSec), {
46
- signal: extra.signal,
47
- });
48
- const cues = existsSync(raw) ? normalizeCues(mergePunctuation(parseSrt(readFileSync(raw, "utf8")))) : [];
49
- writeFileSync(output, formatSrt(cues));
50
- const text = cues.map((c) => c.text.replace(/\n/g, " ")).join(" ");
51
- return okResponse({
52
- srtPath: output,
53
- cues: cues.length,
54
- text: text.length > 4000 ? `${text.slice(0, 4000)}…` : text,
55
- ...(cues.length === 0 ? { note: "No speech was recognised." } : {}),
56
- });
57
- }
58
- finally {
59
- rmSync(raw, { force: true });
60
- }
61
- }
62
- catch (error) {
63
- return errorResponse(error);
64
- }
65
- });
66
- }
@@ -1,57 +0,0 @@
1
- import { z } from "zod";
2
- import { extname } from "node:path";
3
- import { existsSync } from "node:fs";
4
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
5
- import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
6
- import { requireFfmpeg } from "../utils/ffmpeg.js";
7
- import { runEditJob, probeDuration } from "../utils/jobs.js";
8
- import { buildTrimArgs, editOutputExt, assertEditContainer } from "../utils/media.js";
9
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
10
- const inputSchema = {
11
- input: z.string().min(1).describe("Path to the source video."),
12
- start: z.number().nonnegative().describe("Start time in seconds."),
13
- end: z.number().positive().optional().describe("End time in seconds. Use end OR duration."),
14
- duration: z.number().positive().optional().describe("Clip length in seconds. Use end OR duration."),
15
- exact: z
16
- .boolean()
17
- .optional()
18
- .describe("Re-encode for a frame-exact cut with the removed content really gone (default true). false = fast " +
19
- "stream copy that snaps to a keyframe and keeps hidden earlier frames; never use it to remove secrets."),
20
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
21
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
22
- };
23
- export function register(server) {
24
- server.registerTool("trim", {
25
- title: "Trim Video",
26
- description: "Cut a video down to one sub-clip by start + (end or duration). For several segments use clip; " +
27
- "to combine with other edits use pipeline.",
28
- inputSchema,
29
- outputSchema: OUTPUT_PATH,
30
- annotations: WRITES_FILE,
31
- }, async (args, extra) => {
32
- try {
33
- requireFfmpeg();
34
- if (!existsSync(args.input)) {
35
- throw new ScreencastError(`Input file not found: ${args.input}`);
36
- }
37
- if (args.exact !== false)
38
- assertEditContainer(args.output);
39
- const ext = args.exact === false ? extname(args.input) || ".mp4" : editOutputExt(args.input);
40
- const output = resolveOutput(args.output, subdir("edits"), `trim-${stamp()}-${rand()}${ext}`, args.overwrite);
41
- const ffArgs = buildTrimArgs(args.input, output, {
42
- start: args.start,
43
- end: args.end,
44
- duration: args.duration,
45
- exact: args.exact,
46
- });
47
- const start = args.start ?? 0;
48
- const end = args.end ?? (await probeDuration(args.input));
49
- const durationSec = args.duration ?? (end !== null ? end - start : null);
50
- await runEditJob(ffArgs, { output, durationSec, extra });
51
- return okResponse({ outputPath: output });
52
- }
53
- catch (error) {
54
- return errorResponse(error);
55
- }
56
- });
57
- }
@@ -1,142 +0,0 @@
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, runFfmpeg, runFfmpegFrames } from "../utils/ffmpeg.js";
5
- import { resolveCaptureTarget } from "../utils/resolveTarget.js";
6
- import { buildScreenshotArgs } from "../utils/targets.js";
7
- import { detectionSize, targetSize, buildRawStreamArgs, targetDiffOptions, DEFAULT_PIXEL_THRESHOLD, } from "../utils/diff.js";
8
- import { waitLoop } from "../utils/waitLoop.js";
9
- import { FrameQueue } from "../utils/frameQueue.js";
10
- import { windowMatchReport } from "../utils/windows.js";
11
- import { confirmCapture, describeTarget } from "../utils/consent.js";
12
- import { subdir, stamp, rand } from "../utils/paths.js";
13
- import { join } from "node:path";
14
- import { rmSync } from "node:fs";
15
- import { tmpdir } from "node:os";
16
- import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
17
- const inputSchema = {
18
- target: z
19
- .string()
20
- .describe("What to watch: full | monitor:<i> | window:<title> (or exe=/hwnd=) | region:<x>,<y>,<w>,<h>."),
21
- exactTitle: z.boolean().optional().describe("window: targets match the whole title only (default false)."),
22
- mode: z
23
- .enum(["change", "settle"])
24
- .optional()
25
- .describe("change (default): return once it differs from the start. settle: once it has been still for settleSec."),
26
- timeoutSec: z
27
- .number()
28
- .positive()
29
- .max(600)
30
- .optional()
31
- .describe("Give up after this many seconds (default 30; a timeout is a result, not an error)."),
32
- settleSec: z
33
- .number()
34
- .positive()
35
- .max(60)
36
- .optional()
37
- .describe("Mode settle: seconds of stillness (default 1)."),
38
- intervalMs: z
39
- .number()
40
- .int()
41
- .min(100)
42
- .max(5000)
43
- .optional()
44
- .describe("Pause between checks in ms (default 250)."),
45
- pixelThreshold: z
46
- .number()
47
- .min(0)
48
- .max(255)
49
- .optional()
50
- .describe(`Mean 0-255 difference for a ~32x32 cell to count as changed (default ${DEFAULT_PIXEL_THRESHOLD}).`),
51
- returnImage: z
52
- .boolean()
53
- .optional()
54
- .describe("Return the final state inline (default true)."),
55
- keep: z
56
- .boolean()
57
- .optional()
58
- .describe("Keep the final screenshot on disk and return its path (default false)."),
59
- };
60
- export function register(server) {
61
- server.registerTool("wait_for_change", {
62
- title: "Wait for Screen Change",
63
- description: "Wait until part of the screen changes or settles, instead of guessing a sleep. Returns the " +
64
- "elapsed time, changed regions (screenshot pixels; add `origin` for desktop), and the final state.",
65
- inputSchema,
66
- outputSchema: looseOutput({
67
- outcome: z.string(),
68
- mode: z.string(),
69
- elapsedSec: z.number(),
70
- regions: z.array(z.unknown()),
71
- origin: looseOutput({ x: z.number(), y: z.number() }),
72
- }),
73
- annotations: READ_ONLY,
74
- }, async (args, extra) => {
75
- try {
76
- requireFfmpeg();
77
- const mode = args.mode ?? "change";
78
- const timeoutMs = (args.timeoutSec ?? 30) * 1000;
79
- const settleMs = (args.settleSec ?? 1) * 1000;
80
- const interval = args.intervalMs ?? 250;
81
- const { target, monitors, window } = await resolveCaptureTarget(args.target, { exactTitle: args.exactTitle });
82
- await confirmCapture(server, `Watch ${describeTarget(args.target, window)} for up to ${timeoutMs / 1000} s, until it ${mode === "settle" ? "stops changing" : "changes"}?`, extra.signal);
83
- const area = targetSize(target, monitors);
84
- const size = detectionSize(area.width, area.height);
85
- const opts = targetDiffOptions(area, size, args.pixelThreshold);
86
- const frames = new FrameQueue();
87
- const stop = new AbortController();
88
- const capture = runFfmpegFrames(buildRawStreamArgs(target, monitors, size, 1000 / interval), size.width * size.height, (f) => frames.push(f), timeoutMs + 60_000, { signal: AbortSignal.any([extra.signal, stop.signal]) }).then(() => frames.end(), (err) => frames.fail(err));
89
- let loop;
90
- let endedAt = 0;
91
- try {
92
- loop = await waitLoop({
93
- grab: () => frames.next(15_000),
94
- mode,
95
- width: size.width,
96
- height: size.height,
97
- diff: opts,
98
- timeoutMs,
99
- settleMs,
100
- intervalMs: interval,
101
- signal: extra.signal,
102
- sleep: async () => { },
103
- });
104
- endedAt = Date.now();
105
- }
106
- finally {
107
- stop.abort();
108
- await capture;
109
- }
110
- const { outcome, regions, everChanged, startedAt: started } = loop;
111
- const result = {
112
- outcome,
113
- mode,
114
- elapsedSec: Number(((endedAt - started) / 1000).toFixed(2)),
115
- ...(mode === "settle" ? { changedWhileWaiting: everChanged } : {}),
116
- regions,
117
- origin: { x: area.x, y: area.y },
118
- ...(window ? windowMatchReport(window) : {}),
119
- };
120
- const images = [];
121
- if (args.returnImage !== false && outcome !== "cancelled") {
122
- const shot = args.keep
123
- ? join(subdir("screenshots"), `wait-${stamp()}-${rand()}.png`)
124
- : join(tmpdir(), `screencast-wait-${stamp()}-${rand()}.png`);
125
- try {
126
- await runFfmpeg(buildScreenshotArgs(target, shot, monitors), 60_000, { signal: extra.signal });
127
- if (args.keep)
128
- result.screenshotPath = shot;
129
- images.push(...(await encodeInlineImages([shot], DEFAULT_MAX_IMAGE_WIDTH, 1)).images);
130
- }
131
- finally {
132
- if (!args.keep)
133
- rmSync(shot, { force: true });
134
- }
135
- }
136
- return okResponse(result, images);
137
- }
138
- catch (error) {
139
- return errorResponse(error);
140
- }
141
- });
142
- }
@@ -1,58 +0,0 @@
1
- import { z } from "zod";
2
- import { existsSync } from "node:fs";
3
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
- import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
5
- import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
6
- import { runEditJob } from "../utils/jobs.js";
7
- import { buildXfadeArgs, clipLength, DEFAULT_TRANSITION_DUR } from "../utils/produce.js";
8
- import { assertEditContainer } from "../utils/media.js";
9
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
10
- const inputSchema = {
11
- inputA: z.string().min(1).describe("Outgoing video."),
12
- inputB: z.string().min(1).describe("Incoming video."),
13
- transition: z
14
- .string()
15
- .optional()
16
- .describe("xfade name (default fade): fade, wipeleft, slideup, circleopen, dissolve, ..."),
17
- duration: z
18
- .number()
19
- .positive()
20
- .optional()
21
- .describe(`Transition length in seconds (default ${DEFAULT_TRANSITION_DUR}).`),
22
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
23
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
24
- };
25
- export function register(server) {
26
- server.registerTool("xfade_transition", {
27
- title: "Crossfade Transition",
28
- description: "Join two videos with an xfade transition (audio crossfaded); they need not match in size, " +
29
- "fps, or audio. For more clips use assemble_highlights.",
30
- inputSchema,
31
- outputSchema: OUTPUT_PATH,
32
- annotations: WRITES_FILE,
33
- }, async (args, extra) => {
34
- try {
35
- requireFfmpeg();
36
- for (const f of [args.inputA, args.inputB]) {
37
- if (!existsSync(f))
38
- throw new ScreencastError(`Input file not found: ${f}`);
39
- }
40
- assertEditContainer(args.output);
41
- const [a, b] = await Promise.all([probeMedia(args.inputA), probeMedia(args.inputB)]);
42
- const durA = clipLength(a);
43
- const durB = clipLength(b);
44
- if (durA === null || durB === null) {
45
- throw new ScreencastError(`Could not read duration of ${durA === null ? args.inputA : args.inputB}.`);
46
- }
47
- const clipHasAudio = [a.audioCodec !== null, b.audioCodec !== null];
48
- const hasAudio = clipHasAudio[0] || clipHasAudio[1];
49
- const output = resolveOutput(args.output, subdir("edits"), `xfade-${stamp()}-${rand()}.mp4`, args.overwrite);
50
- const ffArgs = buildXfadeArgs(args.inputA, args.inputB, [durA, durB], output, { transition: args.transition, duration: args.duration }, clipHasAudio);
51
- await runEditJob(ffArgs, { output, durationSec: durA + durB, extra });
52
- return okResponse({ outputPath: output, audio: hasAudio });
53
- }
54
- catch (error) {
55
- return errorResponse(error);
56
- }
57
- });
58
- }
@@ -1,134 +0,0 @@
1
- import { z } from "zod";
2
- import { existsSync } from "node:fs";
3
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
- import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
5
- import { requireFfmpeg, runFfmpegFrames, probeMedia } from "../utils/ffmpeg.js";
6
- import { runEditJob, jobTimeoutMs } from "../utils/jobs.js";
7
- import { analysisSize } from "../utils/diff.js";
8
- import { keyframesToViews, buildZoomArgs, createAutoZoomPlanner, planClickZoom, buildAnalysisArgs, DEFAULT_TRANSITION_SEC, DEFAULT_AUTO_MAX_ZOOM, DEFAULT_RING_COLOR, MAX_ZOOM, readClicks, zoomKeyframeSchema, } from "../utils/zoom.js";
9
- import { eventPaths } from "../utils/events.js";
10
- import { validateColor } from "../utils/validate.js";
11
- export const MAX_RINGS = 200;
12
- import { editOutputExt, assertEditContainer } from "../utils/media.js";
13
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
14
- const inputSchema = {
15
- input: z.string().min(1).describe("Path to the source video."),
16
- keyframes: z
17
- .array(zoomKeyframeSchema)
18
- .max(100)
19
- .optional()
20
- .describe("Views reached by time t: a source rectangle (x, y, width, height), or { t, full: true } to " +
21
- "zoom out. Omit to plan them (see follow)."),
22
- follow: z
23
- .enum(["auto", "clicks", "changes"])
24
- .optional()
25
- .describe("Without keyframes: clicks (from the events log of start_recording events: true) or changes " +
26
- "(where the screen changed). auto (default): clicks if logged, else changes."),
27
- events: z
28
- .string()
29
- .optional()
30
- .describe("Events log (default: the input's .events.jsonl); must match the input's timing and size, so " +
31
- "use the original recording."),
32
- highlightClicks: z
33
- .boolean()
34
- .optional()
35
- .describe("Ring each logged click (default false)."),
36
- highlightColor: z.string().optional().describe("Ring color (default #FF4545)."),
37
- transitionSec: z
38
- .number()
39
- .positive()
40
- .max(5)
41
- .optional()
42
- .describe(`How long each zoom/pan eases (default ${DEFAULT_TRANSITION_SEC}).`),
43
- maxZoom: z
44
- .number()
45
- .min(1)
46
- .max(MAX_ZOOM)
47
- .optional()
48
- .describe(`Auto mode: the furthest it zooms in (default ${DEFAULT_AUTO_MAX_ZOOM}).`),
49
- holdSec: z.number().positive().max(30).optional().describe("Auto mode: stay zoomed this long after activity (default 2)."),
50
- dryRun: z.boolean().optional().describe("Return the planned keyframes only (editable, pass back)."),
51
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
52
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
53
- };
54
- export function register(server) {
55
- server.registerTool("zoom", {
56
- title: "Zoom and Pan",
57
- description: "Smooth animated zoom-and-pan into the action and back out, from keyframes or planned from " +
58
- "logged clicks or screen changes.",
59
- inputSchema,
60
- outputSchema: looseOutput({ keyframes: z.array(z.unknown()) }),
61
- annotations: WRITES_FILE,
62
- }, async (args, extra) => {
63
- try {
64
- requireFfmpeg();
65
- if (!existsSync(args.input))
66
- throw new ScreencastError(`Input file not found: ${args.input}`);
67
- const info = await probeMedia(args.input);
68
- const { width: W, height: H, durationSec } = info;
69
- if (!W || !H)
70
- throw new ScreencastError(`Could not read the size of ${args.input}.`);
71
- const fps = info.fps ?? 30;
72
- const transition = args.transitionSec ?? DEFAULT_TRANSITION_SEC;
73
- const eventsPath = args.events ?? eventPaths(args.input).jsonl;
74
- const clicks = readClicks(eventsPath);
75
- if (args.events && !clicks)
76
- throw new ScreencastError(`No event log at ${args.events}.`);
77
- if ((args.follow === "clicks" || args.highlightClicks) && !clicks) {
78
- throw new ScreencastError(`No event log for ${args.input} (looked for ${eventsPath}). Record with start_recording ` +
79
- "events: true, or pass events: <path to .events.jsonl>.");
80
- }
81
- const ringColor = validateColor(args.highlightColor ?? DEFAULT_RING_COLOR, "highlightColor");
82
- let keyframes = args.keyframes;
83
- const planned = !keyframes;
84
- const follow = args.follow === "clicks" || (args.follow !== "changes" && clicks && clicks.length > 0) ? "clicks" : "changes";
85
- if (!keyframes && follow === "clicks") {
86
- keyframes = planClickZoom(clicks ?? [], W, H, { holdSec: args.holdSec, maxZoom: args.maxZoom, transition });
87
- if (keyframes.length === 0) {
88
- return okResponse({ keyframes: [], follow, note: "The event log has no clicks inside the frame; nothing written." });
89
- }
90
- }
91
- if (!keyframes) {
92
- const size = analysisSize(W, H);
93
- const step = 0.25;
94
- const planner = createAutoZoomPlanner(size.width, size.height, W, H, {
95
- step,
96
- holdSec: args.holdSec,
97
- maxZoom: args.maxZoom,
98
- transition,
99
- });
100
- await runFfmpegFrames(buildAnalysisArgs(args.input, size, step), size.width * size.height, (f) => planner.push(f), jobTimeoutMs(durationSec), { signal: extra.signal });
101
- keyframes = planner.finish();
102
- if (keyframes.length === 0) {
103
- return okResponse({ keyframes: [], note: "No localised changes found to zoom into; nothing written." });
104
- }
105
- }
106
- if (args.dryRun) {
107
- return okResponse({ planned, ...(planned ? { follow } : {}), keyframes, transitionSec: transition });
108
- }
109
- if (args.highlightClicks && clicks && clicks.length > MAX_RINGS) {
110
- throw new ScreencastError(`${clicks.length} clicks is more than ${MAX_RINGS} rings; trim the video or the event log first.`);
111
- }
112
- const views = keyframesToViews(keyframes, W, H);
113
- assertEditContainer(args.output);
114
- const ext = editOutputExt(args.input);
115
- const output = resolveOutput(args.output, subdir("edits"), `zoom-${stamp()}-${rand()}${ext}`, args.overwrite);
116
- const rings = args.highlightClicks ? { clicks: clicks ?? [], color: ringColor } : undefined;
117
- await runEditJob(buildZoomArgs(args.input, output, views, { width: W, height: H, fps }, transition, "standard", rings), {
118
- output,
119
- durationSec,
120
- extra,
121
- });
122
- return okResponse({
123
- outputPath: output,
124
- planned,
125
- ...(planned ? { follow } : {}),
126
- keyframes,
127
- ...(rings ? { ringedClicks: rings.clicks.length } : {}),
128
- });
129
- }
130
- catch (error) {
131
- return errorResponse(error);
132
- }
133
- });
134
- }