@tmhs/screencast-mcp 0.49.1 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +15 -9
  2. package/dist/index.js +551 -106
  3. package/dist/wgcRecorder.js +15 -139
  4. package/package.json +9 -5
  5. package/assets/.gitkeep +0 -0
  6. package/assets/icon.png +0 -0
  7. package/dist/cli.js +0 -516
  8. package/dist/context.js +0 -50
  9. package/dist/prompts.js +0 -95
  10. package/dist/resources.js +0 -93
  11. package/dist/server.js +0 -174
  12. package/dist/setup.js +0 -438
  13. package/dist/tools/addMarker.js +0 -93
  14. package/dist/tools/assembleHighlights.js +0 -69
  15. package/dist/tools/backdrop.js +0 -79
  16. package/dist/tools/bugReport.js +0 -243
  17. package/dist/tools/burnSubtitles.js +0 -56
  18. package/dist/tools/callout.js +0 -62
  19. package/dist/tools/chapters.js +0 -156
  20. package/dist/tools/clip.js +0 -52
  21. package/dist/tools/compress.js +0 -51
  22. package/dist/tools/concat.js +0 -67
  23. package/dist/tools/contactSheet.js +0 -113
  24. package/dist/tools/convert.js +0 -46
  25. package/dist/tools/crop.js +0 -43
  26. package/dist/tools/cursor.js +0 -67
  27. package/dist/tools/cutByTranscript.js +0 -86
  28. package/dist/tools/cutIdle.js +0 -84
  29. package/dist/tools/deleteRecording.js +0 -119
  30. package/dist/tools/denoise.js +0 -60
  31. package/dist/tools/doctor.js +0 -146
  32. package/dist/tools/exportGif.js +0 -57
  33. package/dist/tools/exportPreset.js +0 -48
  34. package/dist/tools/extractAudio.js +0 -65
  35. package/dist/tools/findText.js +0 -194
  36. package/dist/tools/getMediaInfo.js +0 -36
  37. package/dist/tools/getSession.js +0 -40
  38. package/dist/tools/indexRecording.js +0 -195
  39. package/dist/tools/keystrokeOverlay.js +0 -90
  40. package/dist/tools/listAudioDevices.js +0 -35
  41. package/dist/tools/listSessions.js +0 -28
  42. package/dist/tools/listTargets.js +0 -76
  43. package/dist/tools/listVideoDevices.js +0 -26
  44. package/dist/tools/musicBed.js +0 -55
  45. package/dist/tools/narrate.js +0 -86
  46. package/dist/tools/normalizeAudio.js +0 -59
  47. package/dist/tools/overlay.js +0 -62
  48. package/dist/tools/pauseRecording.js +0 -44
  49. package/dist/tools/pipeline.js +0 -397
  50. package/dist/tools/readEvents.js +0 -98
  51. package/dist/tools/redactRegion.js +0 -62
  52. package/dist/tools/reframe.js +0 -46
  53. package/dist/tools/resumeRecording.js +0 -46
  54. package/dist/tools/reviewRecording.js +0 -163
  55. package/dist/tools/sampleFrames.js +0 -200
  56. package/dist/tools/saveReplay.js +0 -90
  57. package/dist/tools/scale.js +0 -44
  58. package/dist/tools/screenDiff.js +0 -86
  59. package/dist/tools/screenshot.js +0 -76
  60. package/dist/tools/searchRecording.js +0 -79
  61. package/dist/tools/speed.js +0 -46
  62. package/dist/tools/startRecording.js +0 -398
  63. package/dist/tools/stepGuide.js +0 -249
  64. package/dist/tools/stopRecording.js +0 -132
  65. package/dist/tools/titleCard.js +0 -67
  66. package/dist/tools/transcribe.js +0 -66
  67. package/dist/tools/trim.js +0 -57
  68. package/dist/tools/waitForChange.js +0 -142
  69. package/dist/tools/xfadeTransition.js +0 -58
  70. package/dist/tools/zoom.js +0 -134
  71. package/dist/utils/anim.js +0 -54
  72. package/dist/utils/animExport.js +0 -56
  73. package/dist/utils/argPaths.js +0 -39
  74. package/dist/utils/audio.js +0 -117
  75. package/dist/utils/audioDevices.js +0 -107
  76. package/dist/utils/backdrop.js +0 -162
  77. package/dist/utils/bugReport.js +0 -195
  78. package/dist/utils/callout.js +0 -132
  79. package/dist/utils/calloutAssets.js +0 -42
  80. package/dist/utils/capabilities.js +0 -96
  81. package/dist/utils/captions.js +0 -104
  82. package/dist/utils/chapters.js +0 -227
  83. package/dist/utils/consent.js +0 -29
  84. package/dist/utils/cursor.js +0 -338
  85. package/dist/utils/diff.js +0 -186
  86. package/dist/utils/errors.js +0 -29
  87. package/dist/utils/events.js +0 -403
  88. package/dist/utils/expr.js +0 -11
  89. package/dist/utils/ffmpeg.js +0 -285
  90. package/dist/utils/fontCoverage.js +0 -177
  91. package/dist/utils/fonts.js +0 -154
  92. package/dist/utils/frameQueue.js +0 -50
  93. package/dist/utils/gpu.js +0 -219
  94. package/dist/utils/idle.js +0 -91
  95. package/dist/utils/images.js +0 -38
  96. package/dist/utils/jobs.js +0 -129
  97. package/dist/utils/keystrokes.js +0 -198
  98. package/dist/utils/lifecycle.js +0 -233
  99. package/dist/utils/logging.js +0 -75
  100. package/dist/utils/media.js +0 -584
  101. package/dist/utils/monitors.js +0 -124
  102. package/dist/utils/narrate.js +0 -233
  103. package/dist/utils/ocr.js +0 -222
  104. package/dist/utils/ocrScan.js +0 -93
  105. package/dist/utils/paths.js +0 -155
  106. package/dist/utils/pause.js +0 -190
  107. package/dist/utils/pipeline.js +0 -361
  108. package/dist/utils/player.js +0 -85
  109. package/dist/utils/pool.js +0 -29
  110. package/dist/utils/produce.js +0 -300
  111. package/dist/utils/recipes.js +0 -71
  112. package/dist/utils/recorder.js +0 -173
  113. package/dist/utils/recordingFiles.js +0 -32
  114. package/dist/utils/recordingIndex.js +0 -312
  115. package/dist/utils/replay.js +0 -283
  116. package/dist/utils/resolveTarget.js +0 -25
  117. package/dist/utils/retention.js +0 -48
  118. package/dist/utils/roots.js +0 -43
  119. package/dist/utils/sessions.js +0 -499
  120. package/dist/utils/sheet.js +0 -82
  121. package/dist/utils/stepGuide.js +0 -231
  122. package/dist/utils/steps.js +0 -88
  123. package/dist/utils/still.js +0 -38
  124. package/dist/utils/targetList.js +0 -64
  125. package/dist/utils/targets.js +0 -265
  126. package/dist/utils/timeline.js +0 -85
  127. package/dist/utils/toolSpec.js +0 -31
  128. package/dist/utils/toolsets.js +0 -134
  129. package/dist/utils/transcriptCut.js +0 -149
  130. package/dist/utils/validate.js +0 -23
  131. package/dist/utils/waitLoop.js +0 -50
  132. package/dist/utils/wgc.js +0 -84
  133. package/dist/utils/windows.js +0 -192
  134. package/dist/utils/zoom.js +0 -252
@@ -1,195 +0,0 @@
1
- import { z } from "zod";
2
- import { dirname, join } from "node:path";
3
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, 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, canReuseIndex, cueTexts, defaultTranscriptPath, eventTexts, fingerprintFile, findIndex, indexMatchesVideo, indexWritePath, keyframeTime, legacyIndexSidecarPath, markerTexts, maskSegmentText, mergeSegments, planKeyframes, readIndex, resolveRecording, segmentsFrom, writeIndex, } from "../utils/recordingIndex.js";
16
- import { mapPool } from "../utils/pool.js";
17
- const OCR_BATCH = 8;
18
- const inputSchema = {
19
- input: z.string().optional().describe("Recording path."),
20
- sessionId: z.string().optional().describe("Or a stopped session id."),
21
- sceneThreshold: z.number().gt(0).lt(1).optional().describe(`Change starting a segment (default ${DEFAULT_INDEX_THRESHOLD}).`),
22
- maxFrames: z.number().int().min(1).max(MAX_INDEX_FRAMES).optional().describe(`Keyframes to OCR (default ${DEFAULT_INDEX_FRAMES}).`),
23
- transcript: z.string().optional().describe("An .srt, or 'whisper' to transcribe. Default: <video>.srt if any."),
24
- force: z.boolean().optional().describe("Re-OCR despite a matching cached index."),
25
- };
26
- export function register(server) {
27
- server.registerTool("index_recording", {
28
- title: "Index Recording",
29
- description: "Build a recording's text timeline (<video>.index.json: OCR per scene, events, markers, transcript) " +
30
- "for search_recording.",
31
- inputSchema,
32
- outputSchema: looseOutput({ indexPath: z.string(), segments: z.number() }),
33
- annotations: WRITES_FILE,
34
- }, async (args, extra) => {
35
- const work = mkdtempSync(join(tmpdir(), "screencast-index-"));
36
- try {
37
- const { ffmpeg } = requireFfmpeg();
38
- const source = await resolveRecording(args);
39
- const info = await probeMedia(source.path);
40
- const duration = info.videoDurationSec ?? info.durationSec;
41
- if (!info.width || duration === null || !(duration > 0)) {
42
- throw new ScreencastError(`Could not read the video size and duration of ${source.path}.`);
43
- }
44
- const threshold = args.sceneThreshold ?? DEFAULT_INDEX_THRESHOLD;
45
- const maxFrames = args.maxFrames ?? DEFAULT_INDEX_FRAMES;
46
- const edits = subdir("edits");
47
- const outPath = indexWritePath(source.path, edits);
48
- const fingerprint = fingerprintFile(source.path);
49
- const report = progressReporter(extra);
50
- const notes = [];
51
- const existingPath = args.force ? null : findIndex(source.path, edits, fingerprint);
52
- const prior = existingPath ? readIndex(existingPath) : null;
53
- let ocrNow = null;
54
- const ocrAvailable = async () => (ocrNow ??= process.platform === "win32" && (await ocrStatus()).available);
55
- const cached = canReuseIndex(prior, {
56
- fingerprint,
57
- sceneThreshold: threshold,
58
- maxFrames,
59
- ocrAvailable: prior !== null && !prior.ocr ? await ocrAvailable() : false,
60
- });
61
- let segments;
62
- let framesRead = 0;
63
- let ocr = false;
64
- if (cached) {
65
- segments = prior.segments;
66
- framesRead = prior.framesRead;
67
- ocr = prior.ocr;
68
- }
69
- else {
70
- const scan = await runCapture(ffmpeg, buildSceneScanArgs(source.path, threshold), jobTimeoutMs(duration), {
71
- signal: extra.signal,
72
- });
73
- if (scan.code !== 0)
74
- throw new ScreencastError(`Scene scan failed (exit ${scan.code}): ${scan.stderr.trim().slice(-400)}`);
75
- report?.(0.1);
76
- const spans = segmentsFrom(planKeyframes(parseSceneScan(scan.stdout), duration, maxFrames), duration);
77
- const texts = spans.map(() => []);
78
- ocr = await ocrAvailable();
79
- if (ocr) {
80
- for (let b = 0; b < spans.length; b += OCR_BATCH) {
81
- extra.signal.throwIfAborted();
82
- const batch = spans.slice(b, b + OCR_BATCH);
83
- const grabbed = await mapPool(batch, async (span, i) => {
84
- const out = join(work, `key_${b + i}.png`);
85
- await runFfmpeg(buildSampleAtTimestampArgs(source.path, keyframeTime(span), out), 60_000, { signal: extra.signal });
86
- return { at: b + i, path: out };
87
- });
88
- const frames = grabbed.filter((f) => existsSync(f.path));
89
- const read = frames.length > 0 ? await readFrames(frames.map((f) => f.path), work, extra.signal, { sameSize: true }) : [];
90
- read.forEach((f, i) => (texts[frames[i].at] = f.lines.map((l) => l.text)));
91
- framesRead += read.length;
92
- report?.(0.1 + (0.85 * Math.min(spans.length, b + OCR_BATCH)) / spans.length);
93
- }
94
- }
95
- else {
96
- notes.push("Windows OCR is not available, so the index holds no screen text; install an OCR language (doctor).");
97
- }
98
- const read = spans.map((s, i) => ({ ...s, ocr: texts[i] ?? [] }));
99
- segments = ocr ? mergeSegments(read) : read;
100
- }
101
- segments = maskSegmentText(segments);
102
- const events = source.eventsPath ? eventTexts(parseEventsJsonl(readFileSync(source.eventsPath, "utf8"))) : [];
103
- segments = attach(segments, events, "events");
104
- segments = attach(segments, markerTexts(source.markers), "markers");
105
- const cues = await transcriptCues(args.transcript, source.path, info.audioCodec !== null, duration, extra.signal, notes);
106
- if (cues !== null)
107
- segments = attach(segments, cueTexts(cues), "transcript");
108
- else if (cached && prior) {
109
- const kept = prior.segments.flatMap((s) => s.transcript ?? []);
110
- segments = attach(segments, kept, "transcript");
111
- }
112
- const index = {
113
- version: INDEX_VERSION,
114
- video: source.path,
115
- fingerprint,
116
- durationSec: duration,
117
- createdAt: new Date().toISOString(),
118
- sceneThreshold: threshold,
119
- maxFrames,
120
- framesRead,
121
- ocr,
122
- segments,
123
- };
124
- mkdirSync(join(outPath, ".."), { recursive: true });
125
- writeIndex(outPath, index);
126
- const legacy = legacyIndexSidecarPath(source.path);
127
- if (legacy !== outPath && existsSync(legacy)) {
128
- const old = readIndex(legacy);
129
- if (old && indexMatchesVideo(old, source.path, fingerprint))
130
- rmSync(legacy, { force: true });
131
- }
132
- report?.(1);
133
- const count = (f) => segments.reduce((n, s) => n + (s[f]?.length ?? 0), 0);
134
- return okResponse({
135
- indexPath: outPath,
136
- segments: segments.length,
137
- cached,
138
- framesRead,
139
- durationSec: duration,
140
- sources: {
141
- screenLines: segments.reduce((n, s) => n + s.ocr.length, 0),
142
- events: count("events"),
143
- markers: count("markers"),
144
- transcriptCues: count("transcript"),
145
- },
146
- ...(notes.length > 0 ? { note: notes.join(" ") } : {}),
147
- next: "search_recording { query } returns timecoded hits. Secret-shaped screen text is stored masked; the rest " +
148
- "of the index is plain text, so treat it like the video.",
149
- });
150
- }
151
- catch (error) {
152
- return errorResponse(error);
153
- }
154
- finally {
155
- rmSync(work, { recursive: true, force: true });
156
- }
157
- });
158
- }
159
- async function transcriptCues(arg, video, hasAudio, duration, signal, notes) {
160
- if (arg === "whisper") {
161
- if (!hasAudio) {
162
- notes.push("The recording has no audio, so there is no transcript.");
163
- return null;
164
- }
165
- if (!hasFilter("whisper")) {
166
- throw new ScreencastError("This ffmpeg has no whisper filter.", "transcript: 'whisper' needs FFmpeg 8 built with whisper.cpp; or pass an .srt.");
167
- }
168
- const model = resolveWhisperModel(undefined);
169
- const raw = tempPath(".srt");
170
- try {
171
- await runFfmpeg(buildTranscribeArgs(video, model, raw), jobTimeoutMs(duration), { signal });
172
- return existsSync(raw) ? normalizeCues(parseSrt(readFileSync(raw, "utf8"))) : [];
173
- }
174
- finally {
175
- rmSync(raw, { force: true });
176
- }
177
- }
178
- if (arg !== undefined) {
179
- if (!existsSync(arg))
180
- throw new ScreencastError(`Transcript not found: ${arg}`);
181
- return normalizeCues(parseSrt(readFileSync(arg, "utf8")));
182
- }
183
- let siblings;
184
- try {
185
- siblings = readdirSync(dirname(video));
186
- }
187
- catch {
188
- return null;
189
- }
190
- const found = defaultTranscriptPath(video, siblings);
191
- if (found.ambiguous) {
192
- notes.push("Another video in the folder shares this one's base name, so its .srt was not attached; pass transcript.");
193
- }
194
- return found.path ? normalizeCues(parseSrt(readFileSync(found.path, "utf8"))) : null;
195
- }
@@ -1,90 +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 { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
7
- import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
8
- import { runEditJob } from "../utils/jobs.js";
9
- import { groupBadges, buildKeystrokeArgs, DEFAULT_LINGER_SEC, keystrokeOptionsSchema, loadBadges, prepareKeystrokeAssets, } from "../utils/keystrokes.js";
10
- import { editOutputExt, assertEditContainer } from "../utils/media.js";
11
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
12
- import { fontFileSchema } from "../utils/callout.js";
13
- const o = keystrokeOptionsSchema;
14
- const inputSchema = {
15
- input: z.string().min(1).describe("Path to the recording."),
16
- events: o.events.describe("Event log (default: the input's .events.jsonl)."),
17
- clicks: o.clicks.describe("Show clicks (default true)."),
18
- typing: o.typing.describe('Show typing as "Typing…" (default true).'),
19
- keys: o.keys.describe("shortcuts (default): the chord (Ctrl + S); masked: modifiers only (Ctrl + …)."),
20
- lingerSec: o.lingerSec.describe(`Seconds a badge stays up (default ${DEFAULT_LINGER_SEC}).`),
21
- position: o.position.describe("Default bottom (centred)."),
22
- size: o.size.describe("Font px (default 4.5% of the frame height)."),
23
- color: o.color.describe("Text color (default white)."),
24
- fontFile: fontFileSchema,
25
- dryRun: z.boolean().optional().describe("Return the planned badges; write nothing."),
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("keystroke_overlay", {
31
- title: "Keystroke Overlay",
32
- description: "Burn keycast-style badges for shortcuts, clicks, and typing from the recording's input event log " +
33
- "(start_recording events: true). Never shows typed text: the log has none.",
34
- inputSchema,
35
- outputSchema: looseOutput({ badges: z.number().int() }),
36
- annotations: WRITES_FILE,
37
- }, async (args, extra) => {
38
- try {
39
- requireFfmpeg();
40
- if (!existsSync(args.input))
41
- throw new ScreencastError(`Input file not found: ${args.input}`);
42
- const plan = { clicks: args.clicks, typing: args.typing, keys: args.keys, lingerSec: args.lingerSec };
43
- const { badges, shortcutsLogged } = loadBadges(args.input, args.events, plan);
44
- const note = shortcutsLogged === 0
45
- ? 'The log names no shortcuts (recorded with keys: "masked"), so only clicks and typing can show.'
46
- : undefined;
47
- if (badges.length === 0) {
48
- return okResponse({ badges: 0, note: "Nothing to show: the log has no clicks, shortcuts, or typing; nothing written." });
49
- }
50
- const groups = groupBadges(badges);
51
- if (args.dryRun) {
52
- const assets = prepareKeystrokeAssets(groups.map((g) => g.label), null, "", args.fontFile);
53
- return okResponse({
54
- dryRun: true,
55
- badges: badges.length,
56
- plan: badges,
57
- ...(assets.fallbackFont && { fallbackFont: assets.fallbackFont }),
58
- ...(assets.warnings.length > 0 && { warnings: assets.warnings }),
59
- ...(note && { note }),
60
- });
61
- }
62
- assertEditContainer(args.output);
63
- const info = await probeMedia(args.input);
64
- if (!info.height)
65
- throw new ScreencastError(`Could not read the size of ${args.input}.`);
66
- const output = resolveOutput(args.output, subdir("edits"), `keys-${stamp()}-${rand()}${editOutputExt(args.input)}`, args.overwrite);
67
- const work = mkdtempSync(join(tmpdir(), "screencast-keys-"));
68
- try {
69
- const assets = prepareKeystrokeAssets(groups.map((g) => g.label), work, "", args.fontFile);
70
- const style = { position: args.position, size: args.size, color: args.color };
71
- const ffArgs = buildKeystrokeArgs(args.input, output, groups, assets, style, { height: info.height });
72
- await runEditJob(ffArgs, { output, durationSec: info.durationSec, extra });
73
- return okResponse({
74
- outputPath: output,
75
- badges: badges.length,
76
- labels: groups.map((g) => g.label),
77
- ...(assets.fallbackFont && { fallbackFont: assets.fallbackFont }),
78
- ...(assets.warnings.length > 0 && { warnings: assets.warnings }),
79
- ...(note && { note }),
80
- });
81
- }
82
- finally {
83
- rmSync(work, { recursive: true, force: true });
84
- }
85
- }
86
- catch (error) {
87
- return errorResponse(error);
88
- }
89
- });
90
- }
@@ -1,35 +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 } from "../utils/ffmpeg.js";
5
- import { listDshowAudioDevices, pickLoopbackDevice, NO_LOOPBACK_HINT, } from "../utils/audioDevices.js";
6
- export function register(server) {
7
- server.registerTool("list_audio_devices", {
8
- title: "List Audio Devices",
9
- description: "List DirectShow audio devices and flag a likely loopback (Stereo Mix or a virtual-audio " +
10
- "driver), for start_recording's audio.device.",
11
- inputSchema: {},
12
- outputSchema: looseOutput({
13
- devices: z.array(z.unknown()),
14
- loopbackDevice: z.string().nullable(),
15
- note: z.string(),
16
- }),
17
- annotations: READ_ONLY,
18
- }, async () => {
19
- try {
20
- requireFfmpeg();
21
- const devices = await listDshowAudioDevices(true);
22
- const loopback = pickLoopbackDevice(devices);
23
- return okResponse({
24
- devices,
25
- loopbackDevice: loopback,
26
- note: loopback
27
- ? `Pass "${loopback}" as the audio device to capture system audio.`
28
- : `No loopback device detected. ${NO_LOOPBACK_HINT}`,
29
- });
30
- }
31
- catch (error) {
32
- return errorResponse(error);
33
- }
34
- });
35
- }
@@ -1,28 +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 { isAlive } from "../utils/sessions.js";
5
- import { getStore } from "../context.js";
6
- export function register(server) {
7
- server.registerTool("list_sessions", {
8
- title: "List Sessions",
9
- description: "List all recording sessions (active and finished) with their status, " +
10
- "target, output path, and whether the process is still alive.",
11
- inputSchema: {},
12
- outputSchema: looseOutput({
13
- count: z.number().int(),
14
- sessions: z.array(looseOutput({ id: z.string(), status: z.string(), outputPath: z.string(), alive: z.boolean() })),
15
- }),
16
- annotations: READ_ONLY,
17
- }, async () => {
18
- try {
19
- const sessions = getStore()
20
- .list()
21
- .map((s) => ({ ...s, alive: s.status === "recording" && isAlive(s.pid) }));
22
- return okResponse({ count: sessions.length, sessions });
23
- }
24
- catch (error) {
25
- return errorResponse(error);
26
- }
27
- });
28
- }
@@ -1,76 +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 { getMonitors } from "../utils/monitors.js";
5
- import { getRawWindows } from "../utils/windows.js";
6
- import { wgcAvailable } from "../utils/ffmpeg.js";
7
- import { buildTargetList } from "../utils/targetList.js";
8
- const inputSchema = {
9
- exe: z
10
- .string()
11
- .min(1)
12
- .optional()
13
- .describe("Only list windows of this executable, e.g. 'Code.exe' or 'code'."),
14
- titleContains: z
15
- .string()
16
- .min(1)
17
- .optional()
18
- .describe("Only list windows whose title contains this text (case-insensitive)."),
19
- capturableOnly: z
20
- .boolean()
21
- .optional()
22
- .describe("Leave out windows neither backend can capture (minimized, off screen). Default false."),
23
- };
24
- const bounds = z.object({ x: z.number(), y: z.number(), width: z.number(), height: z.number() });
25
- const outputSchema = looseOutput({
26
- full: z.looseObject({ target: z.literal("full"), bounds }),
27
- monitors: z.array(z.looseObject({
28
- target: z.string(),
29
- index: z.number(),
30
- primary: z.boolean(),
31
- bounds,
32
- dpi: z.number().nullable(),
33
- scale: z.number().nullable(),
34
- })),
35
- windows: z.array(z.looseObject({
36
- target: z.string(),
37
- title: z.string(),
38
- exe: z.string().nullable(),
39
- pid: z.number().nullable(),
40
- hwnd: z.number().nullable(),
41
- bounds,
42
- minimized: z.boolean(),
43
- cloaked: z.boolean(),
44
- capturable: z.boolean(),
45
- wgcCapturable: z.boolean(),
46
- })),
47
- wgcAvailable: z.boolean(),
48
- note: z.string(),
49
- });
50
- export function register(server) {
51
- server.registerTool("list_targets", {
52
- title: "List Capture Targets",
53
- description: "List the desktop, monitors, and visible windows (topmost first, with capturability per backend). " +
54
- "Each entry has a `target` string to pass as-is to capture tools; use it instead of guessing a title.",
55
- inputSchema,
56
- outputSchema,
57
- annotations: READ_ONLY,
58
- }, async (args) => {
59
- try {
60
- const [monitors, windows] = await Promise.all([getMonitors(), getRawWindows()]);
61
- const list = buildTargetList(monitors, windows, {
62
- wgcAvailable: wgcAvailable(),
63
- filter: { exe: args.exe, titleContains: args.titleContains, capturableOnly: args.capturableOnly },
64
- });
65
- return okResponse({
66
- ...list,
67
- note: "Pass a target string unchanged. A window handle lasts until the app closes the window; " +
68
- "list again after an app restarts, or target it by window:exe=<app.exe>. " +
69
- 'A window with capturable false but wgcCapturable true needs backend: "wgc".',
70
- });
71
- }
72
- catch (error) {
73
- return errorResponse(error);
74
- }
75
- });
76
- }
@@ -1,26 +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 } 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
- }
@@ -1,55 +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 { buildMusicBedArgs } from "../utils/produce.js";
8
- import { editOutputExt, assertEditContainer } from "../utils/media.js";
9
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
10
- const inputSchema = {
11
- video: z.string().min(1).describe("Path to the video."),
12
- music: z.string().min(1).describe("Music audio file."),
13
- musicVolume: z.number().nonnegative().optional().describe("0..1 (default 0.25 over existing audio, 0.8 alone)."),
14
- fadeIn: z.number().nonnegative().optional().describe("Fade-in seconds (default 1)."),
15
- fadeOut: z.number().nonnegative().optional().describe("Fade-out seconds (default 2)."),
16
- duck: z.boolean().optional().describe("Duck the music under the original audio (default false)."),
17
- output: z.string().optional().describe("Optional output 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("music_bed", {
22
- title: "Add Music Bed",
23
- description: "Lay music under a video: looped or trimmed to length, faded, leveled, and mixed with any " +
24
- "existing audio. Video is stream-copied.",
25
- inputSchema,
26
- outputSchema: OUTPUT_PATH,
27
- annotations: WRITES_FILE,
28
- }, async (args, extra) => {
29
- try {
30
- requireFfmpeg();
31
- for (const f of [args.video, args.music]) {
32
- if (!existsSync(f))
33
- throw new ScreencastError(`Input file not found: ${f}`);
34
- }
35
- const info = await probeMedia(args.video);
36
- if (info.durationSec === null) {
37
- throw new ScreencastError(`Could not read duration of ${args.video}.`);
38
- }
39
- assertEditContainer(args.output);
40
- const ext = editOutputExt(args.video);
41
- const output = resolveOutput(args.output, subdir("edits"), `music-${stamp()}-${rand()}${ext}`, args.overwrite);
42
- const ffArgs = buildMusicBedArgs(args.video, args.music, output, info.durationSec, info.audioCodec !== null, {
43
- musicVolume: args.musicVolume,
44
- fadeIn: args.fadeIn,
45
- fadeOut: args.fadeOut,
46
- duck: args.duck,
47
- });
48
- await runEditJob(ffArgs, { output, durationSec: info.durationSec, extra });
49
- return okResponse({ outputPath: output, mixedWithOriginal: info.audioCodec !== null });
50
- }
51
- catch (error) {
52
- return errorResponse(error);
53
- }
54
- });
55
- }
@@ -1,86 +0,0 @@
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
- const srtPath = output.replace(/\.[^./\\]+$/, "") + ".srt";
52
- if (!args.overwrite && existsSync(srtPath))
53
- throw new ScreencastError(`Output already exists: ${srtPath}. Pass overwrite: true to replace it.`);
54
- work = mkdtempSync(join(tmpdir(), "screencast-tts-"));
55
- const wavs = lines.map((_, i) => join(work, `line-${i}.wav`));
56
- const voice = await synthesize(lines.map((l, i) => ({ text: l.text, path: wavs[i] })), { voice: args.voice, rate: args.rate, signal: extra.signal });
57
- const placed = lines.map((l, i) => ({ ...l, durationSec: wavDurationSec(readFileSync(wavs[i])) }));
58
- const warnings = placementWarnings(placed, info.durationSec);
59
- const ffArgs = buildNarrateArgs(args.video, wavs, output, placed, info.durationSec, {
60
- hasAudio: info.audioCodec !== null,
61
- channels: info.channels,
62
- duck: args.duck,
63
- });
64
- await runEditJob(ffArgs, { output, durationSec: info.durationSec, extra });
65
- writeFileSync(srtPath, formatSrt(narrationCues(placed, info.durationSec)));
66
- const inputMarkers = readMarkers(args.video);
67
- if (inputMarkers.length > 0)
68
- writeMarkers(output, inputMarkers);
69
- return okResponse({
70
- outputPath: output,
71
- srtPath,
72
- voice,
73
- lines: placed.map((p) => ({ t: p.t, durationSec: Math.round(p.durationSec * 100) / 100 })),
74
- mixedWithOriginal: info.audioCodec !== null,
75
- ...(warnings.length ? { warnings } : {}),
76
- });
77
- }
78
- catch (error) {
79
- return errorResponse(error);
80
- }
81
- finally {
82
- if (work)
83
- rmSync(work, { recursive: true, force: true });
84
- }
85
- });
86
- }
@@ -1,59 +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, runCapture, probeMedia } from "../utils/ffmpeg.js";
6
- import { runEditJob, jobTimeoutMs } from "../utils/jobs.js";
7
- import { loudnessTarget, buildLoudnessMeasureArgs, buildLoudnessApplyArgs, parseLoudnorm, loudnessTargetSchema, } from "../utils/audio.js";
8
- import { 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 or audio file."),
12
- target: loudnessTargetSchema
13
- .optional()
14
- .describe("youtube (-14 LUFS, default), podcast (-16), broadcast (-23), or a LUFS number (-70 to -5)."),
15
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
16
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
17
- };
18
- export function register(server) {
19
- server.registerTool("normalize_audio", {
20
- title: "Normalize Loudness",
21
- description: "Normalize loudness to a delivery target (two-pass EBU R128 loudnorm); video is copied. " +
22
- "Reports loudness before and after.",
23
- inputSchema,
24
- outputSchema: OUTPUT_PATH,
25
- annotations: WRITES_FILE,
26
- }, async (args, extra) => {
27
- try {
28
- const { ffmpeg } = requireFfmpeg();
29
- if (!existsSync(args.input)) {
30
- throw new ScreencastError(`Input file not found: ${args.input}`);
31
- }
32
- const info = await probeMedia(args.input);
33
- if (!info.audioCodec)
34
- throw new ScreencastError(`Input has no audio stream: ${args.input}`);
35
- const t = loudnessTarget(args.target);
36
- assertEditContainer(args.output);
37
- const ext = editOutputExt(args.input, { audio: true });
38
- const output = resolveOutput(args.output, subdir("edits"), `loudnorm-${stamp()}-${rand()}${ext}`, args.overwrite);
39
- const timeout = jobTimeoutMs(info.durationSec);
40
- const before = await runCapture(ffmpeg, buildLoudnessMeasureArgs(args.input, t), timeout, { signal: extra.signal });
41
- const measured = parseLoudnorm(before.stderr);
42
- await runEditJob(buildLoudnessApplyArgs(args.input, output, t, measured), {
43
- output,
44
- durationSec: info.durationSec,
45
- extra,
46
- });
47
- const after = parseLoudnorm((await runCapture(ffmpeg, buildLoudnessMeasureArgs(output, t), timeout, { signal: extra.signal })).stderr);
48
- return okResponse({
49
- outputPath: output,
50
- target: { lufs: t.i, truePeakDb: t.tp, lra: t.lra },
51
- before: { lufs: measured.input_i, truePeakDb: measured.input_tp },
52
- after: { lufs: after.input_i, truePeakDb: after.input_tp },
53
- });
54
- }
55
- catch (error) {
56
- return errorResponse(error);
57
- }
58
- });
59
- }