@tmhs/screencast-mcp 0.49.0 → 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.
- package/README.md +13 -8
- package/dist/index.js +550 -106
- package/dist/wgcRecorder.js +15 -139
- package/package.json +8 -4
- package/assets/.gitkeep +0 -0
- package/assets/icon.png +0 -0
- package/dist/cli.js +0 -516
- package/dist/context.js +0 -50
- package/dist/prompts.js +0 -95
- package/dist/resources.js +0 -93
- package/dist/server.js +0 -174
- package/dist/setup.js +0 -438
- package/dist/tools/addMarker.js +0 -93
- package/dist/tools/assembleHighlights.js +0 -69
- package/dist/tools/backdrop.js +0 -89
- package/dist/tools/bugReport.js +0 -266
- package/dist/tools/burnSubtitles.js +0 -56
- package/dist/tools/callout.js +0 -103
- package/dist/tools/chapters.js +0 -156
- package/dist/tools/clip.js +0 -52
- package/dist/tools/compress.js +0 -51
- package/dist/tools/concat.js +0 -67
- package/dist/tools/contactSheet.js +0 -135
- package/dist/tools/convert.js +0 -46
- package/dist/tools/crop.js +0 -43
- package/dist/tools/cursor.js +0 -87
- package/dist/tools/cutByTranscript.js +0 -86
- package/dist/tools/cutIdle.js +0 -84
- package/dist/tools/deleteRecording.js +0 -119
- package/dist/tools/denoise.js +0 -60
- package/dist/tools/doctor.js +0 -146
- package/dist/tools/exportGif.js +0 -57
- package/dist/tools/exportPreset.js +0 -48
- package/dist/tools/extractAudio.js +0 -65
- package/dist/tools/findText.js +0 -196
- package/dist/tools/getMediaInfo.js +0 -36
- package/dist/tools/getSession.js +0 -40
- package/dist/tools/indexRecording.js +0 -195
- package/dist/tools/keystrokeOverlay.js +0 -131
- package/dist/tools/listAudioDevices.js +0 -35
- package/dist/tools/listSessions.js +0 -28
- package/dist/tools/listTargets.js +0 -76
- package/dist/tools/listVideoDevices.js +0 -26
- package/dist/tools/musicBed.js +0 -55
- package/dist/tools/narrate.js +0 -86
- package/dist/tools/normalizeAudio.js +0 -60
- package/dist/tools/overlay.js +0 -62
- package/dist/tools/pauseRecording.js +0 -44
- package/dist/tools/pipeline.js +0 -400
- package/dist/tools/readEvents.js +0 -98
- package/dist/tools/redactRegion.js +0 -70
- package/dist/tools/reframe.js +0 -46
- package/dist/tools/resumeRecording.js +0 -46
- package/dist/tools/reviewRecording.js +0 -163
- package/dist/tools/sampleFrames.js +0 -200
- package/dist/tools/saveReplay.js +0 -90
- package/dist/tools/scale.js +0 -44
- package/dist/tools/screenDiff.js +0 -86
- package/dist/tools/screenshot.js +0 -76
- package/dist/tools/searchRecording.js +0 -79
- package/dist/tools/speed.js +0 -46
- package/dist/tools/startRecording.js +0 -398
- package/dist/tools/stepGuide.js +0 -250
- package/dist/tools/stopRecording.js +0 -132
- package/dist/tools/titleCard.js +0 -67
- package/dist/tools/transcribe.js +0 -66
- package/dist/tools/trim.js +0 -57
- package/dist/tools/waitForChange.js +0 -128
- package/dist/tools/xfadeTransition.js +0 -58
- package/dist/tools/zoom.js +0 -149
- package/dist/utils/anim.js +0 -54
- package/dist/utils/animExport.js +0 -56
- package/dist/utils/argPaths.js +0 -39
- package/dist/utils/audio.js +0 -113
- package/dist/utils/audioDevices.js +0 -107
- package/dist/utils/backdrop.js +0 -151
- package/dist/utils/bugReport.js +0 -172
- package/dist/utils/callout.js +0 -90
- package/dist/utils/calloutAssets.js +0 -42
- package/dist/utils/capabilities.js +0 -96
- package/dist/utils/captions.js +0 -103
- package/dist/utils/chapters.js +0 -227
- package/dist/utils/consent.js +0 -29
- package/dist/utils/cursor.js +0 -317
- package/dist/utils/diff.js +0 -184
- package/dist/utils/errors.js +0 -29
- package/dist/utils/events.js +0 -403
- package/dist/utils/expr.js +0 -11
- package/dist/utils/ffmpeg.js +0 -285
- package/dist/utils/fontCoverage.js +0 -177
- package/dist/utils/fonts.js +0 -154
- package/dist/utils/gpu.js +0 -219
- package/dist/utils/idle.js +0 -91
- package/dist/utils/images.js +0 -38
- package/dist/utils/jobs.js +0 -129
- package/dist/utils/keystrokes.js +0 -155
- package/dist/utils/lifecycle.js +0 -233
- package/dist/utils/logging.js +0 -75
- package/dist/utils/media.js +0 -574
- package/dist/utils/monitors.js +0 -124
- package/dist/utils/narrate.js +0 -233
- package/dist/utils/ocr.js +0 -222
- package/dist/utils/ocrScan.js +0 -91
- package/dist/utils/paths.js +0 -155
- package/dist/utils/pause.js +0 -190
- package/dist/utils/pipeline.js +0 -361
- package/dist/utils/player.js +0 -85
- package/dist/utils/pool.js +0 -29
- package/dist/utils/produce.js +0 -298
- package/dist/utils/recipes.js +0 -71
- package/dist/utils/recorder.js +0 -173
- package/dist/utils/recordingFiles.js +0 -32
- package/dist/utils/recordingIndex.js +0 -312
- package/dist/utils/replay.js +0 -283
- package/dist/utils/resolveTarget.js +0 -25
- package/dist/utils/retention.js +0 -48
- package/dist/utils/roots.js +0 -43
- package/dist/utils/sessions.js +0 -499
- package/dist/utils/sheet.js +0 -59
- package/dist/utils/stepGuide.js +0 -231
- package/dist/utils/steps.js +0 -88
- package/dist/utils/still.js +0 -38
- package/dist/utils/targetList.js +0 -64
- package/dist/utils/targets.js +0 -265
- package/dist/utils/timeline.js +0 -85
- package/dist/utils/toolSpec.js +0 -31
- package/dist/utils/toolsets.js +0 -134
- package/dist/utils/transcriptCut.js +0 -149
- package/dist/utils/validate.js +0 -23
- package/dist/utils/waitLoop.js +0 -50
- package/dist/utils/wgc.js +0 -84
- package/dist/utils/windows.js +0 -192
- package/dist/utils/zoom.js +0 -234
package/dist/tools/stepGuide.js
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, rmdirSync, statSync, 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 { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
|
|
7
|
-
import { requireFfmpeg, probeMedia, runFfmpeg } from "../utils/ffmpeg.js";
|
|
8
|
-
import { progressReporter } from "../utils/jobs.js";
|
|
9
|
-
import { parseEventsJsonl } from "../utils/events.js";
|
|
10
|
-
import { inputSteps } from "../utils/steps.js";
|
|
11
|
-
import { readMarkers } from "../utils/chapters.js";
|
|
12
|
-
import { ocrStatus } from "../utils/capabilities.js";
|
|
13
|
-
import { readFrames, scanMatches } from "../utils/ocrScan.js";
|
|
14
|
-
import { DEFAULT_SECRET_PATTERN } from "../utils/bugReport.js";
|
|
15
|
-
import { resolveOutputDir, subdir, stamp, rand } from "../utils/paths.js";
|
|
16
|
-
import { GUIDE_FILES, HTML_IMAGE_LADDER, HTML_MAX_BYTES, MAX_GUIDE_STEPS, assignSections, base64Bytes, buildHtmlImageArgs, buildGuideHtml, buildGuideMarkdown, buildStepFrameArgs, buildStepShotArgs, caption, guideSteps, htmlImageName, labelAt, nextHtmlRung, shotFilter, } from "../utils/stepGuide.js";
|
|
17
|
-
import { resolveSource } from "./bugReport.js";
|
|
18
|
-
import { mapPool } from "../utils/pool.js";
|
|
19
|
-
const OCR_BATCH = 10;
|
|
20
|
-
const HTML_SAMPLE = 5;
|
|
21
|
-
const inputSchema = {
|
|
22
|
-
input: z.string().min(1).optional().describe("Recording path (uses its .events.jsonl)."),
|
|
23
|
-
sessionId: z.string().min(1).optional().describe("Or a stopped session's id."),
|
|
24
|
-
title: z.string().max(200).optional().describe("Guide title."),
|
|
25
|
-
format: z.enum(["md", "html", "both"]).optional().describe("md + images/, self-contained html, or both (default)."),
|
|
26
|
-
ocr: z.boolean().optional().describe("OCR shots for captions and secret boxes (default true; needs Windows OCR)."),
|
|
27
|
-
outputDir: z.string().optional().describe("Guide folder (default: new in SCREENCAST_HOME/edits)."),
|
|
28
|
-
overwrite: z.boolean().optional().describe("Replace a guide already in outputDir."),
|
|
29
|
-
};
|
|
30
|
-
export function register(server) {
|
|
31
|
-
server.registerTool("step_guide", {
|
|
32
|
-
title: "Step-by-Step Guide",
|
|
33
|
-
description: "Turn a recording's event log into a numbered how-to: a ringed screenshot and caption per step, marker " +
|
|
34
|
-
"headings; Markdown and/or one HTML file. Never includes typed text.",
|
|
35
|
-
inputSchema,
|
|
36
|
-
outputSchema: looseOutput({ outputDir: z.string() }),
|
|
37
|
-
annotations: WRITES_FILE,
|
|
38
|
-
}, async (args, extra) => {
|
|
39
|
-
let createdDir = null;
|
|
40
|
-
const written = [];
|
|
41
|
-
try {
|
|
42
|
-
if ((args.input === undefined) === (args.sessionId === undefined)) {
|
|
43
|
-
throw new ScreencastError("Provide exactly one of: input (a recording path) or sessionId.");
|
|
44
|
-
}
|
|
45
|
-
requireFfmpeg();
|
|
46
|
-
const source = await resolveSource(args);
|
|
47
|
-
if (!source.eventsPath) {
|
|
48
|
-
throw new ScreencastError("The recording has no input event log, so there are no steps to write.", "Record with start_recording events: true, or pass a recording that has a .events.jsonl beside it.");
|
|
49
|
-
}
|
|
50
|
-
const info = await probeMedia(source.path);
|
|
51
|
-
if (!info.width || !info.height)
|
|
52
|
-
throw new ScreencastError(`Could not read the size of ${source.path}.`);
|
|
53
|
-
const duration = info.videoDurationSec ?? info.durationSec;
|
|
54
|
-
if (duration === null)
|
|
55
|
-
throw new ScreencastError(`Could not read the duration of ${source.path}.`);
|
|
56
|
-
const fps = info.fps ?? 30;
|
|
57
|
-
const format = args.format ?? "both";
|
|
58
|
-
const wantMd = format !== "html";
|
|
59
|
-
const wantHtml = format !== "md";
|
|
60
|
-
const useOcr = args.ocr !== false;
|
|
61
|
-
if (useOcr) {
|
|
62
|
-
const status = await ocrStatus();
|
|
63
|
-
if (!status.available) {
|
|
64
|
-
throw new ScreencastError(`Captions and the secret scan need Windows OCR, which is unavailable here${status.error ? ` (${status.error})` : ""}.`, "Pass ocr: false for a guide without them (then check the screenshots yourself before sharing), or run doctor.");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const dir = resolveOutputDir(args.outputDir, subdir("edits")) ?? join(subdir("edits"), `step-guide-${stamp()}-${rand()}`);
|
|
68
|
-
const paths = { markdown: join(dir, GUIDE_FILES.markdown), html: join(dir, GUIDE_FILES.html), images: join(dir, GUIDE_FILES.images) };
|
|
69
|
-
const clash = [paths.markdown, paths.html].filter((p) => existsSync(p));
|
|
70
|
-
if (clash.length > 0 && !args.overwrite) {
|
|
71
|
-
throw new ScreencastError(`The folder already holds a guide: ${clash.join(", ")}. Pass overwrite: true to replace it, or choose another outputDir.`);
|
|
72
|
-
}
|
|
73
|
-
const all = inputSteps(parseEventsJsonl(readFileSync(source.eventsPath, "utf8")));
|
|
74
|
-
const kept = all.slice(0, MAX_GUIDE_STEPS);
|
|
75
|
-
const plain = guideSteps(kept, { durationSec: duration, fps });
|
|
76
|
-
const shots = plain.map((s, i) => ({ i, s })).filter(({ s }) => s.shotT !== undefined);
|
|
77
|
-
const warnings = [];
|
|
78
|
-
if (!existsSync(dir)) {
|
|
79
|
-
mkdirSync(dir, { recursive: true });
|
|
80
|
-
createdDir = dir;
|
|
81
|
-
}
|
|
82
|
-
const work = mkdtempSync(join(tmpdir(), "screencast-guide-"));
|
|
83
|
-
try {
|
|
84
|
-
const progress = progressReporter(extra);
|
|
85
|
-
const total = shots.length * (useOcr ? 3 : 2) || 1;
|
|
86
|
-
let done = 0;
|
|
87
|
-
const tick = () => progress?.(++done / total);
|
|
88
|
-
const frames = await mapPool(shots, async ({ s }) => {
|
|
89
|
-
const out = join(work, `frame-${String(s.n).padStart(3, "0")}.png`);
|
|
90
|
-
await runFfmpeg(buildStepFrameArgs(source.path, s.shotT, out), 60_000, { signal: extra.signal });
|
|
91
|
-
tick();
|
|
92
|
-
return out;
|
|
93
|
-
});
|
|
94
|
-
const read = frames.map(() => null);
|
|
95
|
-
if (useOcr) {
|
|
96
|
-
for (let b = 0; b < frames.length; b += OCR_BATCH) {
|
|
97
|
-
extra.signal.throwIfAborted();
|
|
98
|
-
const batch = await readFrames(frames.slice(b, b + OCR_BATCH), work, extra.signal, { sameSize: true });
|
|
99
|
-
batch.forEach((f, k) => {
|
|
100
|
-
read[b + k] = f;
|
|
101
|
-
tick();
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const labels = kept.map(() => null);
|
|
106
|
-
const boxes = shots.map(({ i, s }, k) => {
|
|
107
|
-
const frame = read[k];
|
|
108
|
-
if (!frame)
|
|
109
|
-
return [];
|
|
110
|
-
if (s.x !== undefined && s.y !== undefined)
|
|
111
|
-
labels[i] = labelAt(frame.lines, s.x, s.y);
|
|
112
|
-
return scanMatches({ frames: [{ ...frame, t: 0, path: "" }], step: 1, end: 1 }, DEFAULT_SECRET_PATTERN, true, "line")
|
|
113
|
-
.redactRegions;
|
|
114
|
-
});
|
|
115
|
-
const steps = assignSections(guideSteps(kept, { durationSec: duration, fps, labels }), readMarkers(source.path));
|
|
116
|
-
const imageDir = wantMd ? paths.images : join(work, "images");
|
|
117
|
-
if (wantMd && existsSync(imageDir) && args.overwrite) {
|
|
118
|
-
for (const f of readdirSync(imageDir))
|
|
119
|
-
if (/^step-\d+\.png$/.test(f))
|
|
120
|
-
rmSync(join(imageDir, f), { force: true });
|
|
121
|
-
}
|
|
122
|
-
mkdirSync(imageDir, { recursive: true });
|
|
123
|
-
let redactions = 0;
|
|
124
|
-
const frameSize = { width: info.width, height: info.height };
|
|
125
|
-
const rendered = await mapPool(shots, async ({ i }, k) => {
|
|
126
|
-
const step = steps[i];
|
|
127
|
-
const file = GUIDE_FILES.image(step.n);
|
|
128
|
-
const ring = step.x !== undefined && step.y !== undefined ? { x: step.x, y: step.y } : undefined;
|
|
129
|
-
const filter = shotFilter(frameSize, { click: ring, boxes: boxes[k] });
|
|
130
|
-
const out = join(imageDir, file);
|
|
131
|
-
await runFfmpeg(buildStepShotArgs(frames[k], filter, out), 60_000, { signal: extra.signal });
|
|
132
|
-
tick();
|
|
133
|
-
return { step, file, out };
|
|
134
|
-
});
|
|
135
|
-
for (const [k, { step, file, out }] of rendered.entries()) {
|
|
136
|
-
if (wantMd)
|
|
137
|
-
written.push(out);
|
|
138
|
-
step.image = file;
|
|
139
|
-
redactions += boxes[k].length;
|
|
140
|
-
}
|
|
141
|
-
const stepsNote = all.length === 0 ? "The event log has no clicks, shortcuts, typing, or scrolls." : undefined;
|
|
142
|
-
const data = {
|
|
143
|
-
title: args.title?.trim() || "Step-by-step guide",
|
|
144
|
-
createdAt: new Date().toISOString(),
|
|
145
|
-
recording: { durationSec: Math.round(duration * 1000) / 1000, width: info.width, height: info.height },
|
|
146
|
-
steps,
|
|
147
|
-
...(all.length > MAX_GUIDE_STEPS ? { stepsOmitted: all.length - MAX_GUIDE_STEPS } : {}),
|
|
148
|
-
...(stepsNote ? { stepsNote } : {}),
|
|
149
|
-
ocr: useOcr ? "read" : "off",
|
|
150
|
-
redactions,
|
|
151
|
-
};
|
|
152
|
-
if (wantMd) {
|
|
153
|
-
writeFileSync(paths.markdown, buildGuideMarkdown(data));
|
|
154
|
-
written.push(paths.markdown);
|
|
155
|
-
}
|
|
156
|
-
if (wantHtml) {
|
|
157
|
-
const htmlDir = join(work, "html");
|
|
158
|
-
mkdirSync(htmlDir, { recursive: true });
|
|
159
|
-
const files = steps.flatMap((s) => (s.image ? [s.image] : []));
|
|
160
|
-
const src = (file) => `data:image/jpeg;base64,${readFileSync(join(htmlDir, htmlImageName(file))).toString("base64")}`;
|
|
161
|
-
const encode = async (file, rung) => {
|
|
162
|
-
const out = join(htmlDir, htmlImageName(file));
|
|
163
|
-
await runFfmpeg(buildHtmlImageArgs(join(imageDir, file), rung, out), 60_000, { signal: extra.signal });
|
|
164
|
-
return base64Bytes(statSync(out).size);
|
|
165
|
-
};
|
|
166
|
-
const sample = files.length > HTML_SAMPLE ? files.filter((_, k) => k % Math.ceil(files.length / HTML_SAMPLE) === 0) : [];
|
|
167
|
-
let start = 0;
|
|
168
|
-
for (; sample.length > 0 && start < HTML_IMAGE_LADDER.length - 1; start++) {
|
|
169
|
-
let bytes = 0;
|
|
170
|
-
for (const f of sample)
|
|
171
|
-
bytes += await encode(f, HTML_IMAGE_LADDER[start]);
|
|
172
|
-
if ((bytes / sample.length) * files.length <= HTML_MAX_BYTES * 0.9)
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
let page = "";
|
|
176
|
-
for (let r = start; r !== null;) {
|
|
177
|
-
const rung = HTML_IMAGE_LADDER[r];
|
|
178
|
-
let images = 0;
|
|
179
|
-
for (const file of files)
|
|
180
|
-
images += await encode(file, rung);
|
|
181
|
-
page = images <= HTML_MAX_BYTES ? buildGuideHtml(data, src) : "";
|
|
182
|
-
const bytes = page ? Buffer.byteLength(page) : images;
|
|
183
|
-
if (bytes <= HTML_MAX_BYTES)
|
|
184
|
-
break;
|
|
185
|
-
const next = nextHtmlRung(r, bytes);
|
|
186
|
-
if (next === null) {
|
|
187
|
-
page ||= buildGuideHtml(data, src);
|
|
188
|
-
warnings.push(`guide.html is ${(Buffer.byteLength(page) / 1e6).toFixed(1)} MB, over the ${HTML_MAX_BYTES / 1e6} MB budget even with ${rung.width} px JPEGs; ` +
|
|
189
|
-
"use format: md for a guide this long.");
|
|
190
|
-
}
|
|
191
|
-
r = next;
|
|
192
|
-
}
|
|
193
|
-
writeFileSync(paths.html, page);
|
|
194
|
-
written.push(paths.html);
|
|
195
|
-
}
|
|
196
|
-
if (args.overwrite) {
|
|
197
|
-
if (!wantHtml)
|
|
198
|
-
rmSync(paths.html, { force: true });
|
|
199
|
-
if (!wantMd) {
|
|
200
|
-
rmSync(paths.markdown, { force: true });
|
|
201
|
-
if (existsSync(paths.images)) {
|
|
202
|
-
for (const f of readdirSync(paths.images))
|
|
203
|
-
if (/^step-\d+\.png$/.test(f))
|
|
204
|
-
rmSync(join(paths.images, f), { force: true });
|
|
205
|
-
try {
|
|
206
|
-
rmdirSync(paths.images);
|
|
207
|
-
}
|
|
208
|
-
catch {
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
if (data.stepsOmitted)
|
|
214
|
-
warnings.push(`Only the first ${MAX_GUIDE_STEPS} steps were written; ${data.stepsOmitted} more were left out.`);
|
|
215
|
-
if (stepsNote)
|
|
216
|
-
warnings.push(stepsNote);
|
|
217
|
-
return okResponse({
|
|
218
|
-
outputDir: dir,
|
|
219
|
-
...(wantMd ? { markdownPath: paths.markdown, imagesDir: paths.images } : {}),
|
|
220
|
-
...(wantHtml ? { htmlPath: paths.html } : {}),
|
|
221
|
-
steps: steps.map((s) => ({
|
|
222
|
-
...(s.n > 0 ? { n: s.n } : {}),
|
|
223
|
-
t: s.t,
|
|
224
|
-
action: s.action,
|
|
225
|
-
caption: caption(s),
|
|
226
|
-
...(s.section ? { section: s.section } : {}),
|
|
227
|
-
...(s.image ? { image: s.image } : {}),
|
|
228
|
-
})),
|
|
229
|
-
ocr: data.ocr,
|
|
230
|
-
redactions,
|
|
231
|
-
...(warnings.length > 0 ? { warnings } : {}),
|
|
232
|
-
note: useOcr
|
|
233
|
-
? "Captions are OCR-based templates: rewrite them in guide.md as needed. The secret scan is best-effort: look at the screenshots before sharing."
|
|
234
|
-
: "Not scanned for secrets: look at the screenshots before sharing.",
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
finally {
|
|
238
|
-
rmSync(work, { recursive: true, force: true });
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
catch (error) {
|
|
242
|
-
if (createdDir)
|
|
243
|
-
rmSync(createdDir, { recursive: true, force: true });
|
|
244
|
-
else
|
|
245
|
-
for (const p of written)
|
|
246
|
-
rmSync(p, { force: true });
|
|
247
|
-
return errorResponse(error);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
@@ -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
|
-
}
|
package/dist/tools/titleCard.js
DELETED
|
@@ -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 { fontFileSchema } from "./callout.js";
|
|
10
|
-
import { resolveOutput, subdir, stamp, rand, tempPath } from "../utils/paths.js";
|
|
11
|
-
import { assertEditContainer } from "../utils/media.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
|
-
}
|
package/dist/tools/transcribe.js
DELETED
|
@@ -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
|
-
}
|
package/dist/tools/trim.js
DELETED
|
@@ -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
|
-
}
|