@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,243 +0,0 @@
1
- import { z } from "zod";
2
- import { createRequire } from "node:module";
3
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
- import { tmpdir, release, version as osVersion } from "node:os";
5
- import { join } from "node:path";
6
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
7
- import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
8
- import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
9
- import { runEditJob } from "../utils/jobs.js";
10
- import { planPipeline } from "../utils/pipeline.js";
11
- import { exportAnimation } from "../utils/animExport.js";
12
- import { DEFAULT_MAX_BYTES } from "../utils/anim.js";
13
- import { evenTimes, DEFAULT_SHEET_COUNT, DEFAULT_TILE_WIDTH, renderContactSheet } from "../utils/sheet.js";
14
- import { scanVideoFrames, scanMatches, DEFAULT_SCAN_FRAMES, MAX_SCAN_FRAMES } from "../utils/ocrScan.js";
15
- import { parseEventsJsonl } from "../utils/events.js";
16
- import { ocrStatus, parseFfmpegVersion, versionText } from "../utils/capabilities.js";
17
- import { getMonitors } from "../utils/monitors.js";
18
- import { resolveOutputDir, subdir, stamp, rand } from "../utils/paths.js";
19
- import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
20
- import { DEFAULT_CLIP_SEC, DEFAULT_ERROR_PATTERN, DEFAULT_SCAN_EVERY_SEC, DEFAULT_SECRET_PATTERN, MAX_CLIP_SEC, MAX_STEPS, REPORT_FILES, buildReportMarkdown, clipWindow, errorFindings, maskSecrets, mergeRedactions, reconstructSteps, resolveSource, } from "../utils/bugReport.js";
21
- import { redactRegionSchema } from "../utils/media.js";
22
- const { version: serverVersion } = createRequire(import.meta.url)("../../package.json");
23
- const inputSchema = {
24
- input: z.string().min(1).optional().describe("Recording path (uses its .events.jsonl)."),
25
- sessionId: z.string().min(1).optional().describe("Or a stopped session's id."),
26
- title: z.string().max(200).optional().describe("Issue title."),
27
- actual: z.string().max(4000).optional().describe("What happened."),
28
- expected: z.string().max(4000).optional().describe("What should happen."),
29
- start: z.number().nonnegative().optional().describe("Clip start s (default: end - clipSec)."),
30
- end: z.number().positive().optional().describe("Clip end s (default: recording end)."),
31
- clipSec: z.number().positive().max(MAX_CLIP_SEC).optional().describe(`Clip length without start (default ${DEFAULT_CLIP_SEC}).`),
32
- redact: z.boolean().optional().describe("Box out OCR-found secrets in every output (default true; needs Windows OCR)."),
33
- secretPattern: z.string().optional().describe("Secret regex (default: API keys, tokens, password: values)."),
34
- regions: z.array(redactRegionSchema).optional().describe("Extra boxes (video px; start/end on the clip clock)."),
35
- errorPattern: z.string().optional().describe("Error-line regex."),
36
- scanEverySec: z.number().positive().optional().describe(`OCR every N s (default ${DEFAULT_SCAN_EVERY_SEC}).`),
37
- maxFrames: z.number().int().min(1).max(MAX_SCAN_FRAMES).optional().describe(`Scan frame cap (default ${DEFAULT_SCAN_FRAMES}).`),
38
- gif: z.boolean().optional().describe("Also export a GIF (default true)."),
39
- maxBytes: z.number().int().min(10_000).optional().describe(`GIF size budget (default ${DEFAULT_MAX_BYTES}).`),
40
- outputDir: z.string().optional().describe("Package folder (default: a new one in SCREENCAST_HOME/edits)."),
41
- overwrite: z.boolean().optional().describe("Replace a report already in outputDir."),
42
- };
43
- const r3 = (n) => Math.round(n * 1000) / 1000;
44
- async function displayRows() {
45
- if (process.platform !== "win32")
46
- return null;
47
- try {
48
- const monitors = await getMonitors();
49
- return monitors
50
- .map((m) => `${m.width}x${m.height}${m.dpi ? ` @${Math.round((m.dpi / 96) * 100)}%` : ""}${m.primary ? " (primary)" : ""}`)
51
- .join(", ");
52
- }
53
- catch {
54
- return null;
55
- }
56
- }
57
- export function register(server) {
58
- server.registerTool("bug_report", {
59
- title: "Bug Report Package",
60
- description: "Package a recording as a paste-ready repro folder: secret-scanned, redacted clip and GIF, contact " +
61
- "sheet, steps from the event log, OCR'd errors, environment, report.md for gh issue create --body-file.",
62
- inputSchema,
63
- outputSchema: looseOutput({
64
- outputDir: z.string(),
65
- reportPath: z.string(),
66
- jsonPath: z.string(),
67
- clipPath: z.string(),
68
- }),
69
- annotations: WRITES_FILE,
70
- }, async (args, extra) => {
71
- let createdDir = null;
72
- const written = [];
73
- try {
74
- if ((args.input === undefined) === (args.sessionId === undefined)) {
75
- throw new ScreencastError("Provide exactly one of: input (a recording path) or sessionId.");
76
- }
77
- const { ffmpeg } = requireFfmpeg();
78
- const source = await resolveSource(args);
79
- const info = await probeMedia(source.path);
80
- if (!info.width || !info.height)
81
- throw new ScreencastError(`Could not read the size of ${source.path}.`);
82
- const duration = info.videoDurationSec ?? info.durationSec;
83
- if (duration === null)
84
- throw new ScreencastError(`Could not read the duration of ${source.path}.`);
85
- const window = clipWindow(duration, args);
86
- const clipLen = r3(window.end - window.start);
87
- const redact = args.redact !== false;
88
- const secretPattern = args.secretPattern ?? DEFAULT_SECRET_PATTERN;
89
- maskSecrets(["x"], secretPattern);
90
- if (args.errorPattern !== undefined)
91
- maskSecrets(["x"], args.errorPattern);
92
- const format = "gif";
93
- const dir = resolveOutputDir(args.outputDir, subdir("edits")) ?? join(subdir("edits"), `bug-report-${stamp()}-${rand()}`);
94
- const paths = {
95
- markdown: join(dir, REPORT_FILES.markdown),
96
- json: join(dir, REPORT_FILES.json),
97
- clip: join(dir, REPORT_FILES.clip),
98
- gif: join(dir, REPORT_FILES.gif(format)),
99
- sheet: join(dir, REPORT_FILES.contactSheet),
100
- };
101
- const clash = Object.values(paths).filter((p) => existsSync(p));
102
- if (clash.length > 0 && !args.overwrite) {
103
- throw new ScreencastError(`The folder already holds a report: ${clash.join(", ")}. Pass overwrite: true to replace it, or choose another outputDir.`);
104
- }
105
- if (!existsSync(dir)) {
106
- mkdirSync(dir, { recursive: true });
107
- createdDir = dir;
108
- }
109
- const warnings = [];
110
- const work = mkdtempSync(join(tmpdir(), "screencast-bug-"));
111
- try {
112
- let ocr = "unavailable";
113
- let scan = null;
114
- const status = await ocrStatus();
115
- if (status.available) {
116
- scan = await scanVideoFrames(source.path, {
117
- everySec: args.scanEverySec ?? DEFAULT_SCAN_EVERY_SEC,
118
- maxFrames: args.maxFrames ?? DEFAULT_SCAN_FRAMES,
119
- range: { start: window.start, duration: clipLen },
120
- }, work, extra.signal);
121
- ocr = "read";
122
- }
123
- else if (redact) {
124
- throw new ScreencastError(`The secret scan needs Windows OCR, which is unavailable here${status.error ? ` (${status.error})` : ""}.`, "Pass redact: false to package without it (then check the clip yourself before sharing), or run doctor.");
125
- }
126
- else {
127
- warnings.push("Windows OCR is unavailable, so no error text was read.");
128
- }
129
- const found = scan && redact ? mergeRedactions(scanMatches(scan, secretPattern, true, "line").redactRegions) : [];
130
- const regions = [...found, ...(args.regions ?? [])];
131
- const errors = scan ? errorFindings(scan.frames, args.errorPattern ?? DEFAULT_ERROR_PATTERN, redact ? secretPattern : null) : [];
132
- extra.signal.throwIfAborted();
133
- const steps = [
134
- { op: "trim", start: window.start, end: window.end },
135
- ...(regions.length > 0 ? [{ op: "redact", regions, style: "box" }] : []),
136
- ];
137
- const plan = planPipeline(source.path, paths.clip, steps, {
138
- width: info.width,
139
- height: info.height,
140
- fps: info.fps ?? 30,
141
- durationSec: info.durationSec,
142
- hasAudio: info.audioCodec !== null,
143
- });
144
- await runEditJob(plan.args, { output: paths.clip, durationSec: plan.durationSec, inputDurationSec: clipLen, extra });
145
- written.push(paths.clip);
146
- let anim = null;
147
- if (args.gif !== false) {
148
- anim = await exportAnimation(paths.clip, paths.gif, { format, maxBytes: args.maxBytes ?? DEFAULT_MAX_BYTES }, extra);
149
- written.push(paths.gif);
150
- if (anim.note)
151
- warnings.push(anim.note);
152
- }
153
- await renderContactSheet(paths.clip, evenTimes(clipLen, DEFAULT_SHEET_COUNT), paths.sheet, { tileWidth: DEFAULT_TILE_WIDTH }, extra.signal);
154
- written.push(paths.sheet);
155
- const allSteps = source.eventsPath ? reconstructSteps(parseEventsJsonl(readFileSync(source.eventsPath, "utf8"))) : [];
156
- const stepsNote = source.eventsPath
157
- ? allSteps.length === 0
158
- ? "The event log has no clicks, shortcuts, typing, or scrolls."
159
- : undefined
160
- : "The recording has no input event log (record with start_recording events: true).";
161
- const ff = parseFfmpegVersion(versionText(ffmpeg) ?? "");
162
- const displays = await displayRows();
163
- const record = source.record;
164
- const mask = (s) => (redact ? (maskSecrets([s], secretPattern)[0] ?? s) : s);
165
- const environment = [
166
- ["OS", `${osVersion()} (${release()}), ${process.arch}`],
167
- ...(displays ? [["Displays", displays]] : []),
168
- ...(record ? [["Recorded target", mask(record.target)]] : []),
169
- ...(record?.matchedWindow ? [["Window", mask(record.matchedWindow)]] : []),
170
- ...(record?.backend ? [["Capture backend", record.backend]] : []),
171
- [
172
- "Recording",
173
- `${info.width}x${info.height}${info.fps ? ` @ ${Math.round(info.fps * 100) / 100} fps` : ""}, ` +
174
- `${r3(duration)} s${info.videoCodec ? `, ${info.videoCodec}` : ""}`,
175
- ],
176
- ["ffmpeg", ff.version ?? "unknown"],
177
- ["screencast-mcp", `${serverVersion} (Node ${process.version})`],
178
- ];
179
- const data = {
180
- title: args.title?.trim() || "Bug report",
181
- ...(args.expected ? { expected: args.expected } : {}),
182
- ...(args.actual ? { actual: args.actual } : {}),
183
- createdAt: new Date().toISOString(),
184
- clip: { start: window.start, end: window.end, recordingDurationSec: r3(duration), width: info.width, height: info.height },
185
- files: {
186
- clip: REPORT_FILES.clip,
187
- ...(anim ? { gif: REPORT_FILES.gif(format) } : {}),
188
- contactSheet: REPORT_FILES.contactSheet,
189
- },
190
- ...(anim ? { gif: { format, sizeBytes: anim.sizeBytes, withinBudget: anim.withinBudget } } : {}),
191
- steps: allSteps.slice(0, MAX_STEPS),
192
- ...(allSteps.length > MAX_STEPS ? { stepsOmitted: allSteps.length - MAX_STEPS } : {}),
193
- ...(stepsNote ? { stepsNote } : {}),
194
- errors,
195
- ocr,
196
- redaction: {
197
- scanned: scan !== null && redact,
198
- ...(scan && redact ? { everySec: r3(scan.step), framesScanned: scan.frames.length } : {}),
199
- found: found.length,
200
- manual: args.regions?.length ?? 0,
201
- },
202
- environment,
203
- };
204
- writeFileSync(paths.markdown, buildReportMarkdown(data));
205
- written.push(paths.markdown);
206
- writeFileSync(paths.json, JSON.stringify({ ...data, steps: allSteps, redaction: { ...data.redaction, regions } }, null, 2) + "\n");
207
- written.push(paths.json);
208
- if (scan?.clamped) {
209
- warnings.push(`The scan interval was widened to ${r3(scan.step)} s to fit maxFrames.`);
210
- }
211
- const { images } = await encodeInlineImages([paths.sheet], DEFAULT_MAX_IMAGE_WIDTH, 1);
212
- return okResponse({
213
- outputDir: dir,
214
- reportPath: paths.markdown,
215
- jsonPath: paths.json,
216
- clipPath: paths.clip,
217
- ...(anim ? { gifPath: paths.gif, gifSizeBytes: anim.sizeBytes, gifWithinBudget: anim.withinBudget } : {}),
218
- contactSheetPath: paths.sheet,
219
- clip: { start: window.start, end: window.end },
220
- steps: allSteps.length,
221
- errors: errors.map((e) => e.text),
222
- ocr,
223
- redaction: data.redaction,
224
- ...(warnings.length > 0 ? { warnings } : {}),
225
- next: `Review the clip and report.md, then: gh issue create --title ${JSON.stringify(data.title)} ` +
226
- `--body-file ${JSON.stringify(paths.markdown)} and drag the GIF into the issue.`,
227
- note: "Redaction is OCR-based and best-effort: look at the clip before posting it anywhere public.",
228
- }, images);
229
- }
230
- finally {
231
- rmSync(work, { recursive: true, force: true });
232
- }
233
- }
234
- catch (error) {
235
- if (createdDir)
236
- rmSync(createdDir, { recursive: true, force: true });
237
- else
238
- for (const p of written)
239
- rmSync(p, { force: true });
240
- return errorResponse(error);
241
- }
242
- });
243
- }
@@ -1,56 +0,0 @@
1
- import { z } from "zod";
2
- import { dirname } 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, probeMedia, hasFilter } from "../utils/ffmpeg.js";
7
- import { runEditJob } from "../utils/jobs.js";
8
- import { buildBurnSubtitlesArgs, CAPTION_STYLE_NAMES } from "../utils/captions.js";
9
- import { bundledFontPath } from "../utils/fonts.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
- subtitles: z.string().min(1).describe("Path to an .srt (e.g. from transcribe) or .ass subtitle file."),
15
- style: z
16
- .enum(CAPTION_STYLE_NAMES)
17
- .optional()
18
- .describe("clean (default for .srt): outlined line. social: big bold text on a dark box. .ass keeps its own " +
19
- "styling unless set."),
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("burn_subtitles", {
25
- title: "Burn In Subtitles",
26
- description: "Burn SRT/ASS subtitles (e.g. from transcribe) into a video in the bundled font.",
27
- inputSchema,
28
- outputSchema: OUTPUT_PATH,
29
- annotations: WRITES_FILE,
30
- }, async (args, extra) => {
31
- try {
32
- requireFfmpeg();
33
- for (const f of [args.input, args.subtitles]) {
34
- if (!existsSync(f))
35
- throw new ScreencastError(`File not found: ${f}`);
36
- }
37
- if (!hasFilter("subtitles")) {
38
- throw new ScreencastError("This ffmpeg has no subtitles filter (it needs libass).", "Install a full ffmpeg build, e.g. `winget install Gyan.FFmpeg`.");
39
- }
40
- assertEditContainer(args.output);
41
- const ext = editOutputExt(args.input);
42
- const output = resolveOutput(args.output, subdir("edits"), `subtitled-${stamp()}-${rand()}${ext}`, args.overwrite);
43
- const fontsDir = dirname(bundledFontPath("regular"));
44
- const style = args.style ?? (/\.(ass|ssa)$/i.test(args.subtitles) ? null : "clean");
45
- await runEditJob(buildBurnSubtitlesArgs(args.input, args.subtitles, output, fontsDir, style), {
46
- output,
47
- durationSec: (await probeMedia(args.input)).durationSec,
48
- extra,
49
- });
50
- return okResponse({ outputPath: output, style: style ?? "file" });
51
- }
52
- catch (error) {
53
- return errorResponse(error);
54
- }
55
- });
56
- }
@@ -1,62 +0,0 @@
1
- import { z } from "zod";
2
- import { join } from "node:path";
3
- import { existsSync, mkdtempSync, rmSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
6
- import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
7
- import { requireFfmpeg } from "../utils/ffmpeg.js";
8
- import { runEditJob, probeDuration } from "../utils/jobs.js";
9
- import { buildCalloutArgs, calloutItemSchema, fontFileSchema } from "../utils/callout.js";
10
- import { prepareCalloutAssets } from "../utils/calloutAssets.js";
11
- import { stillEdit } from "../utils/media.js";
12
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
13
- const inputSchema = {
14
- input: z.string().min(1).describe("Path to the source video or image (png/jpg; from/to are ignored for an image)."),
15
- items: z
16
- .array(calloutItemSchema)
17
- .min(1)
18
- .max(50)
19
- .describe("Boxes, text labels, and arrows, drawn in order (later on top), in video pixels. Each shows " +
20
- "from..to seconds (default: whole video); color is a name, #RRGGBB, or name@alpha."),
21
- fontFile: fontFileSchema,
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("callout", {
27
- title: "Add Callouts",
28
- description: "Annotate a video or screenshot with timed boxes, text labels, and arrows. Fallback fonts used are listed in " +
29
- "fallbackFonts; characters no font covers are reported in warnings.",
30
- inputSchema,
31
- outputSchema: OUTPUT_PATH,
32
- annotations: WRITES_FILE,
33
- }, async (args, extra) => {
34
- try {
35
- requireFfmpeg();
36
- if (!existsSync(args.input)) {
37
- throw new ScreencastError(`Input file not found: ${args.input}`);
38
- }
39
- const items = args.items;
40
- const { still, ext } = stillEdit(args.input, args.output);
41
- const output = resolveOutput(args.output, subdir("edits"), `callout-${stamp()}-${rand()}${ext}`, args.overwrite);
42
- const work = mkdtempSync(join(tmpdir(), "screencast-callout-"));
43
- try {
44
- const assets = await prepareCalloutAssets(items, work, "", args.fontFile);
45
- const ffArgs = buildCalloutArgs(args.input, output, items, assets, undefined, still);
46
- await runEditJob(ffArgs, { output, durationSec: still ? null : await probeDuration(args.input), extra });
47
- return okResponse({
48
- outputPath: output,
49
- callouts: items.length,
50
- ...(assets.fallbackFonts.length > 0 && { fallbackFonts: assets.fallbackFonts }),
51
- ...(assets.warnings.length > 0 && { warnings: assets.warnings }),
52
- });
53
- }
54
- finally {
55
- rmSync(work, { recursive: true, force: true });
56
- }
57
- }
58
- catch (error) {
59
- return errorResponse(error);
60
- }
61
- });
62
- }
@@ -1,156 +0,0 @@
1
- import { z } from "zod";
2
- import { extname, join } from "node:path";
3
- import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } 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, probeMedia, runCapture } from "../utils/ffmpeg.js";
8
- import { jobTimeoutMs, runEditJob } from "../utils/jobs.js";
9
- import { buildSceneScanArgs, parseSceneScan, editOutputExt, DEFAULT_SCENE_THRESHOLD } from "../utils/media.js";
10
- import { parseSrt } from "../utils/captions.js";
11
- import { buildChapters, buildChaptersMuxArgs, ffmetadata, markerPoints, markersOrChapters, scenePoints, transcriptPoints, youtubeChapters, YOUTUBE_MIN_CHAPTER_SEC, } from "../utils/chapters.js";
12
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
13
- import { getStore } from "../context.js";
14
- const CONTAINERS = new Set([".mp4", ".mkv", ".mov"]);
15
- const MAX_SCENE_CHAPTERS = 12;
16
- const inputSchema = {
17
- input: z.string().min(1).optional().describe("Path to the video."),
18
- sessionId: z.string().min(1).optional().describe("Or a stopped recording's id."),
19
- from: z
20
- .enum(["markers", "scenes", "transcript"])
21
- .optional()
22
- .describe("markers (default; add_marker, else the file's chapters), scenes (screen changes), or transcript (SRT sections)."),
23
- chapters: z
24
- .array(z.object({ start: z.number().min(0), title: z.string().min(1).max(100) }))
25
- .min(1)
26
- .max(200)
27
- .optional()
28
- .describe("Or explicit { start, title } chapters."),
29
- transcript: z.string().optional().describe("The .srt for from: transcript."),
30
- minChapterSec: z
31
- .number()
32
- .min(0)
33
- .optional()
34
- .describe(`Shortest chapter (default 1; scenes ${YOUTUBE_MIN_CHAPTER_SEC}, transcript 30).`),
35
- subtitles: z.string().optional().describe("Also mux this .srt/.vtt/.ass as a soft subtitle track."),
36
- subtitleLanguage: z.string().regex(/^[a-z]{3}$/).optional().describe('ISO 639-2, e.g. "eng".'),
37
- textOnly: z.boolean().optional().describe("Return chapters and YouTube text only; write no file."),
38
- output: z.string().optional().describe("Optional .mp4/.mkv/.mov path. Defaults under SCREENCAST_HOME/edits."),
39
- overwrite: z.boolean().optional().describe("Allow replacing an existing output file."),
40
- };
41
- export function register(server) {
42
- server.registerTool("chapters", {
43
- title: "Chapters",
44
- description: "Write chapters (markers, scene changes, transcript, or a list) into an mp4/mkv/mov copy without " +
45
- "re-encoding; returns YouTube chapter text. Can mux an SRT as soft subtitles.",
46
- inputSchema,
47
- outputSchema: looseOutput({
48
- chapters: z.array(looseOutput({ start: z.number(), end: z.number(), title: z.string() })),
49
- youtube: z.string(),
50
- }),
51
- annotations: WRITES_FILE,
52
- }, async (args, extra) => {
53
- try {
54
- requireFfmpeg();
55
- let input = args.input;
56
- let sessionMarkers;
57
- if (args.sessionId) {
58
- const record = getStore().get(args.sessionId);
59
- if (!record)
60
- throw new ScreencastError(`No session with id "${args.sessionId}".`);
61
- if (record.status === "recording" || record.status === "paused")
62
- throw new ScreencastError("The recording is still running; stop it first.");
63
- input ??= record.outputPath;
64
- sessionMarkers = record.markers;
65
- }
66
- if (!input)
67
- throw new ScreencastError("Pass input or sessionId.");
68
- if (!existsSync(input))
69
- throw new ScreencastError(`Input file not found: ${input}`);
70
- for (const f of [args.transcript, args.subtitles]) {
71
- if (f !== undefined && !existsSync(f))
72
- throw new ScreencastError(`File not found: ${f}`);
73
- }
74
- if (args.subtitles && !/\.(srt|vtt|ass|ssa)$/i.test(args.subtitles)) {
75
- throw new ScreencastError("subtitles must be an .srt, .vtt, or .ass file.");
76
- }
77
- const info = await probeMedia(input);
78
- const durationSec = info.durationSec;
79
- if (!durationSec || durationSec <= 0)
80
- throw new ScreencastError(`Could not read the duration of ${input}.`);
81
- const from = args.chapters ? "list" : (args.from ?? "markers");
82
- let points;
83
- let minDefault = 1;
84
- let source = from;
85
- if (args.chapters) {
86
- points = args.chapters;
87
- }
88
- else if (from === "scenes") {
89
- minDefault = YOUTUBE_MIN_CHAPTER_SEC;
90
- const { ffmpeg } = requireFfmpeg();
91
- const scan = await runCapture(ffmpeg, buildSceneScanArgs(input, DEFAULT_SCENE_THRESHOLD), jobTimeoutMs(durationSec), { signal: extra.signal });
92
- if (scan.code !== 0) {
93
- throw new ScreencastError(`Scene scan failed (exit ${scan.code}): ${scan.stderr.trim().slice(-400)}`);
94
- }
95
- points = scenePoints(parseSceneScan(scan.stdout), args.minChapterSec ?? minDefault, MAX_SCENE_CHAPTERS);
96
- }
97
- else if (from === "transcript") {
98
- if (!args.transcript)
99
- throw new ScreencastError("from: transcript needs transcript (an .srt path).");
100
- minDefault = 30;
101
- points = transcriptPoints(parseSrt(readFileSync(args.transcript, "utf8")), { minChapterSec: args.minChapterSec ?? minDefault });
102
- if (points.length === 0)
103
- throw new ScreencastError(`No cues in ${args.transcript}.`);
104
- }
105
- else {
106
- let markers = sessionMarkers ?? [];
107
- if (markers.length === 0) {
108
- const found = await markersOrChapters(input, extra.signal);
109
- markers = found.markers;
110
- if (found.from === "chapters")
111
- source = "embedded chapters";
112
- }
113
- if (markers.length === 0) {
114
- throw new ScreencastError(`No markers for ${input}.`, "Add some with add_marker, or use from: scenes / transcript, or pass chapters.");
115
- }
116
- points = markerPoints(markers);
117
- }
118
- const chapters = buildChapters(points, durationSec, { minChapterSec: args.minChapterSec ?? minDefault });
119
- if (chapters.length === 0)
120
- throw new ScreencastError("No chapter falls inside the video.");
121
- const yt = youtubeChapters(chapters, durationSec);
122
- const result = {
123
- source,
124
- chapters,
125
- youtube: yt.text,
126
- ...(yt.issues.length > 0 ? { youtubeIssues: yt.issues } : {}),
127
- };
128
- if (args.textOnly)
129
- return okResponse(result);
130
- const ext = (args.output ? extname(args.output).toLowerCase() : editOutputExt(input));
131
- if (!CONTAINERS.has(ext)) {
132
- throw new ScreencastError(`Chapters can be written to .mp4, .mkv, or .mov, not ${ext || "a file without an extension"}.`);
133
- }
134
- const output = resolveOutput(args.output, subdir("edits"), `chapters-${stamp()}-${rand()}${ext}`, args.overwrite);
135
- const work = mkdtempSync(join(tmpdir(), "screencast-chapters-"));
136
- try {
137
- const meta = join(work, "chapters.txt");
138
- writeFileSync(meta, ffmetadata(chapters));
139
- await runEditJob(buildChaptersMuxArgs(input, meta, output, { container: ext, subtitles: args.subtitles, language: args.subtitleLanguage }), { output, durationSec, extra });
140
- }
141
- finally {
142
- rmSync(work, { recursive: true, force: true });
143
- }
144
- return okResponse({
145
- outputPath: output,
146
- ...result,
147
- ...(args.subtitles
148
- ? { subtitleTrack: { file: args.subtitles, codec: ext === ".mkv" ? "copy" : "mov_text", ...(args.subtitleLanguage ? { language: args.subtitleLanguage } : {}) } }
149
- : {}),
150
- });
151
- }
152
- catch (error) {
153
- return errorResponse(error);
154
- }
155
- });
156
- }
@@ -1,52 +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 } from "../utils/ffmpeg.js";
6
- import { runEditJob } from "../utils/jobs.js";
7
- import { buildClipArgs, editOutputExt, assertEditContainer } from "../utils/media.js";
8
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
9
- const inputSchema = {
10
- input: z.string().min(1).describe("Path to the source video."),
11
- segments: z
12
- .array(z.object({
13
- start: z.number().nonnegative(),
14
- end: z.number().positive(),
15
- }))
16
- .min(1)
17
- .describe("{start, end} segments in seconds; each becomes its own file."),
18
- output: z
19
- .string()
20
- .optional()
21
- .describe("Optional output path. Only honored for a single segment; multi-segment output lands 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("clip", {
26
- title: "Extract Clips",
27
- description: "Extract several frame-exact segments, each to its own file. For one segment, trim does the same.",
28
- inputSchema,
29
- outputSchema: looseOutput({ outputs: z.array(z.string()), count: z.number().int() }),
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
- assertEditContainer(args.output);
38
- const ext = editOutputExt(args.input);
39
- const single = args.segments.length === 1;
40
- const outputs = [];
41
- for (const [i, seg] of args.segments.entries()) {
42
- const output = resolveOutput(single ? args.output : undefined, subdir("edits"), `clip-${stamp()}-${rand()}-${String(i).padStart(2, "0")}${ext}`, args.overwrite);
43
- await runEditJob(buildClipArgs(args.input, output, seg), { output, durationSec: seg.end - seg.start, extra });
44
- outputs.push(output);
45
- }
46
- return okResponse({ outputs, count: outputs.length });
47
- }
48
- catch (error) {
49
- return errorResponse(error);
50
- }
51
- });
52
- }
@@ -1,51 +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 } from "../utils/ffmpeg.js";
6
- import { runEditJob, probeDuration } from "../utils/jobs.js";
7
- import { buildCompressArgs, editOutputExt, assertEditContainer } from "../utils/media.js";
8
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
9
- const inputSchema = {
10
- input: z.string().min(1).describe("Path to the source video."),
11
- level: z
12
- .enum(["light", "medium", "heavy"])
13
- .optional()
14
- .describe("CRF 23 / 28 / 32 (default medium)."),
15
- maxWidth: z
16
- .number()
17
- .int()
18
- .positive()
19
- .optional()
20
- .describe("Width cap in px (only downscales)."),
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("compress", {
26
- title: "Compress Video",
27
- description: "Re-encode a video smaller (H.264 CRF ladder, optional width cap). For a platform target use export_preset.",
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
- assertEditContainer(args.output);
38
- const ext = editOutputExt(args.input);
39
- const output = resolveOutput(args.output, subdir("edits"), `compress-${stamp()}-${rand()}${ext}`, args.overwrite);
40
- const ffArgs = buildCompressArgs(args.input, output, {
41
- level: args.level,
42
- maxWidth: args.maxWidth,
43
- });
44
- await runEditJob(ffArgs, { output, durationSec: await probeDuration(args.input), extra });
45
- return okResponse({ outputPath: output, level: args.level ?? "medium" });
46
- }
47
- catch (error) {
48
- return errorResponse(error);
49
- }
50
- });
51
- }