@tmhs/screencast-mcp 0.46.0 → 0.48.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 +127 -303
- package/assets/cursor/arrow.png +0 -0
- package/assets/fonts/Inter-Bold.ttf +0 -0
- package/assets/fonts/Inter-Regular.ttf +0 -0
- package/dist/cli.js +515 -0
- package/dist/index.js +10 -2
- package/dist/server.js +23 -0
- package/dist/setup.js +437 -0
- package/dist/tools/addMarker.js +6 -2
- package/dist/tools/bugReport.js +1 -1
- package/dist/tools/chapters.js +1 -1
- package/dist/tools/cursor.js +87 -0
- package/dist/tools/cutByTranscript.js +3 -3
- package/dist/tools/doctor.js +14 -1
- package/dist/tools/indexRecording.js +37 -15
- package/dist/tools/listVideoDevices.js +26 -0
- package/dist/tools/narrate.js +86 -0
- package/dist/tools/overlay.js +2 -0
- package/dist/tools/pauseRecording.js +44 -0
- package/dist/tools/pipeline.js +37 -13
- package/dist/tools/readEvents.js +1 -1
- package/dist/tools/resumeRecording.js +46 -0
- package/dist/tools/reviewRecording.js +1 -1
- package/dist/tools/searchRecording.js +9 -3
- package/dist/tools/startRecording.js +155 -86
- package/dist/tools/stepGuide.js +57 -4
- package/dist/tools/stopRecording.js +38 -3
- package/dist/utils/argPaths.js +39 -0
- package/dist/utils/audioDevices.js +34 -4
- package/dist/utils/captions.js +5 -3
- package/dist/utils/cursor.js +317 -0
- package/dist/utils/events.js +62 -12
- package/dist/utils/gpu.js +219 -0
- package/dist/utils/lifecycle.js +136 -13
- package/dist/utils/media.js +7 -2
- package/dist/utils/monitors.js +39 -5
- package/dist/utils/narrate.js +233 -0
- package/dist/utils/ocr.js +8 -3
- package/dist/utils/paths.js +41 -3
- package/dist/utils/pause.js +190 -0
- package/dist/utils/pipeline.js +29 -2
- package/dist/utils/recipes.js +7 -3
- package/dist/utils/recorder.js +172 -0
- package/dist/utils/recordingIndex.js +55 -9
- package/dist/utils/replay.js +20 -2
- package/dist/utils/retention.js +4 -1
- package/dist/utils/roots.js +1 -1
- package/dist/utils/sessions.js +32 -6
- package/dist/utils/stepGuide.js +26 -0
- package/dist/utils/targets.js +31 -7
- package/dist/utils/toolsets.js +8 -3
- package/dist/utils/transcriptCut.js +20 -5
- package/dist/utils/wgc.js +2 -2
- package/dist/wgcRecorder.js +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdirSync, rmSync } from "node:fs";
|
|
3
|
+
import { ScreencastError } from "./errors.js";
|
|
4
|
+
import { logMessage, StderrWatch } from "./logging.js";
|
|
5
|
+
import { parseCaptureStart, whenFinalized } from "./events.js";
|
|
6
|
+
import { buildCaptureArgs } from "./targets.js";
|
|
7
|
+
import { requireFfmpeg } from "./ffmpeg.js";
|
|
8
|
+
import { joinSegments, probeDuration, withSessionOp } from "./lifecycle.js";
|
|
9
|
+
import { endSession, isPausing, partPath, partsDir, recordedSec, remainingCapSec, resumeBlocker, webcamPartPath, } from "./pause.js";
|
|
10
|
+
import { classifyUnrequestedExit, killPid } from "./sessions.js";
|
|
11
|
+
export function watchStderr(child, sessionId) {
|
|
12
|
+
let head = "";
|
|
13
|
+
let tail = "";
|
|
14
|
+
let outputAt = null;
|
|
15
|
+
const watch = new StderrWatch(() => ({ sessionId }));
|
|
16
|
+
child.stderr?.on("data", (d) => {
|
|
17
|
+
const text = d.toString();
|
|
18
|
+
tail = (tail + text).slice(-2000);
|
|
19
|
+
if (head.length < 8000)
|
|
20
|
+
head += text;
|
|
21
|
+
if (outputAt === null && /Output #0/.test(head))
|
|
22
|
+
outputAt = Date.now();
|
|
23
|
+
watch.feed(text);
|
|
24
|
+
});
|
|
25
|
+
child.on("error", (err) => {
|
|
26
|
+
tail += `\n${err.message}`;
|
|
27
|
+
});
|
|
28
|
+
return { head: () => head, tail: () => tail, outputAt: () => outputAt };
|
|
29
|
+
}
|
|
30
|
+
export function tailLines(watch, n = 6) {
|
|
31
|
+
return watch.tail().trim().split("\n").slice(-n).join("\n");
|
|
32
|
+
}
|
|
33
|
+
export function settleCapture(child, watch, backend) {
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
const timer = setTimeout(() => resolve("running"), backend === "wgc" ? 15_000 : backend === "ddagrab" ? 2000 : 1200);
|
|
36
|
+
if (backend === "wgc") {
|
|
37
|
+
child.stderr?.on("data", () => {
|
|
38
|
+
if (parseCaptureStart(watch.head()) !== null) {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
resolve("running");
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
child.on("error", () => {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
resolve("exited");
|
|
47
|
+
});
|
|
48
|
+
child.on("exit", () => {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
resolve("exited");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function captureStartMs(watch, backend, spawnedAt) {
|
|
55
|
+
const banner = parseCaptureStart(watch.head());
|
|
56
|
+
if (banner !== null)
|
|
57
|
+
return banner;
|
|
58
|
+
return backend === "ddagrab" ? (watch.outputAt() ?? spawnedAt) : spawnedAt;
|
|
59
|
+
}
|
|
60
|
+
export function attachExitHandler(store, id, child, opts) {
|
|
61
|
+
child.on("exit", (code) => {
|
|
62
|
+
const attached = store.getChild(id);
|
|
63
|
+
if (attached && attached !== child)
|
|
64
|
+
return;
|
|
65
|
+
store.detachChild(id, child);
|
|
66
|
+
if (!isPausing(id))
|
|
67
|
+
endSession(id);
|
|
68
|
+
const cur = store.get(id);
|
|
69
|
+
if (!cur || cur.status !== "recording" || store.isStopping(id))
|
|
70
|
+
return;
|
|
71
|
+
const verdict = classifyUnrequestedExit({
|
|
72
|
+
code,
|
|
73
|
+
backend: opts.backend,
|
|
74
|
+
maxDurationSec: opts.maxDurationSec,
|
|
75
|
+
elapsedMs: Date.now() - opts.spawnedAt,
|
|
76
|
+
});
|
|
77
|
+
logMessage(verdict.status === "failed" ? "error" : "notice", verdict.status === "failed"
|
|
78
|
+
? `Recording ${id} failed: the recorder exited with code ${code}.`
|
|
79
|
+
: `Recording ${id} ended on its own (${verdict.endReason}).`, { sessionId: id, ...verdict });
|
|
80
|
+
store.tryUpdate(id, {
|
|
81
|
+
...verdict,
|
|
82
|
+
stoppedAt: new Date().toISOString(),
|
|
83
|
+
...(verdict.status === "failed"
|
|
84
|
+
? { error: `${opts.backend === "wgc" ? "The window recorder" : "ffmpeg"} exited with code ${code}:\n${tailLines(opts.watch)}` }
|
|
85
|
+
: {}),
|
|
86
|
+
});
|
|
87
|
+
if (cur.segments && (cur.segments.parts.length > 0 || cur.webcam)) {
|
|
88
|
+
void finalizeSegments(store, cur).catch((err) => {
|
|
89
|
+
process.stderr.write(`Joining ${id}'s segments failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async function finalizeSegments(store, record) {
|
|
95
|
+
const tools = requireFfmpeg();
|
|
96
|
+
await whenFinalized(record.id);
|
|
97
|
+
const { patch, error } = await joinSegments(record, tools);
|
|
98
|
+
const durationSec = await probeDuration(tools.ffprobe, record.outputPath);
|
|
99
|
+
store.tryUpdate(record.id, { ...patch, durationSec: durationSec ?? undefined, ...(error ? { error } : {}) });
|
|
100
|
+
}
|
|
101
|
+
export function resumeSession(store, record, ffmpeg) {
|
|
102
|
+
return withSessionOp(store, record.id, "resume", () => runResume(store, store.get(record.id) ?? record, ffmpeg));
|
|
103
|
+
}
|
|
104
|
+
async function runResume(store, record, ffmpeg) {
|
|
105
|
+
const blocker = resumeBlocker(record, store.ownsPaused(record.id));
|
|
106
|
+
if (blocker)
|
|
107
|
+
throw new ScreencastError(`Cannot resume ${record.id}: ${blocker}.`);
|
|
108
|
+
const seg = record.segments;
|
|
109
|
+
const capture = record.capture;
|
|
110
|
+
const backend = record.backend ?? "gdigrab";
|
|
111
|
+
const done = recordedSec(seg.parts);
|
|
112
|
+
const capSec = remainingCapSec(record.maxDurationSec, done);
|
|
113
|
+
const index = seg.parts.length;
|
|
114
|
+
const path = partPath(record.outputPath, index);
|
|
115
|
+
const webcamPath = capture.webcam ? webcamPartPath(record.outputPath, index) : undefined;
|
|
116
|
+
if (index > 0 || webcamPath)
|
|
117
|
+
mkdirSync(partsDir(record.outputPath), { recursive: true });
|
|
118
|
+
const args = buildCaptureArgs(capture.target, {
|
|
119
|
+
...capture.opts,
|
|
120
|
+
output: path,
|
|
121
|
+
maxDurationSec: capSec,
|
|
122
|
+
...(capture.webcam && webcamPath ? { webcam: { ...capture.webcam, output: webcamPath } } : {}),
|
|
123
|
+
});
|
|
124
|
+
const spawnedAt = Date.now();
|
|
125
|
+
const child = spawn(ffmpeg, args, { stdio: ["pipe", "ignore", "pipe"], windowsHide: true });
|
|
126
|
+
const watch = watchStderr(child, record.id);
|
|
127
|
+
const cleanup = () => {
|
|
128
|
+
const other = store.getChild(record.id);
|
|
129
|
+
if (other && other !== child)
|
|
130
|
+
return;
|
|
131
|
+
if (index > 0)
|
|
132
|
+
rmSync(path, { force: true });
|
|
133
|
+
if (webcamPath)
|
|
134
|
+
rmSync(webcamPath, { force: true });
|
|
135
|
+
};
|
|
136
|
+
if ((await settleCapture(child, watch, backend)) === "exited") {
|
|
137
|
+
cleanup();
|
|
138
|
+
throw new ScreencastError(`Resume failed (ffmpeg exited immediately); the recording stays paused:\n${tailLines(watch)}`);
|
|
139
|
+
}
|
|
140
|
+
const startMs = captureStartMs(watch, backend, spawnedAt);
|
|
141
|
+
const camStart = webcamPath ? parseCaptureStart(watch.head(), capture.opts.audio ? 2 : 1) : null;
|
|
142
|
+
store.attachChild(record.id, child);
|
|
143
|
+
const abandon = () => {
|
|
144
|
+
store.detachChild(record.id, child);
|
|
145
|
+
if (child.pid !== undefined)
|
|
146
|
+
killPid(child.pid);
|
|
147
|
+
cleanup();
|
|
148
|
+
};
|
|
149
|
+
let updated;
|
|
150
|
+
try {
|
|
151
|
+
updated = store.update(record.id, {
|
|
152
|
+
status: "recording",
|
|
153
|
+
pid: child.pid ?? null,
|
|
154
|
+
videoStartMs: startMs - done * 1000,
|
|
155
|
+
segments: {
|
|
156
|
+
parts: seg.parts,
|
|
157
|
+
current: { path, startMs, ...(webcamPath ? { webcamPath, ...(camStart !== null ? { webcamStartMs: camStart } : {}) } : {}) },
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
abandon();
|
|
163
|
+
throw new ScreencastError(`Resume stopped: the session registry could not be written (${err.message}).`);
|
|
164
|
+
}
|
|
165
|
+
if (!updated) {
|
|
166
|
+
abandon();
|
|
167
|
+
throw new ScreencastError(`No session with id "${record.id}".`);
|
|
168
|
+
}
|
|
169
|
+
store.clearPaused(record.id);
|
|
170
|
+
attachExitHandler(store, record.id, child, { backend, maxDurationSec: capSec, spawnedAt, watch });
|
|
171
|
+
return { record: updated, recordedSec: done, capSec };
|
|
172
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { closeSync, existsSync, openSync, readFileSync, readSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { basename, join, resolve } from "node:path";
|
|
3
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
4
4
|
import { ScreencastError } from "./errors.js";
|
|
5
5
|
import { pickSceneFrames } from "./media.js";
|
|
6
6
|
import { normalizeForMatch, regexRanges, MAX_QUERY_LENGTH } from "./ocr.js";
|
|
@@ -20,8 +20,20 @@ export const MAX_SNIPPET = 200;
|
|
|
20
20
|
export const MAX_MATCHES_PER_HIT = 5;
|
|
21
21
|
const r3 = (v) => Math.round(v * 1000) / 1000;
|
|
22
22
|
export function indexSidecarPath(video) {
|
|
23
|
+
return `${video}.index.json`;
|
|
24
|
+
}
|
|
25
|
+
export function legacyIndexSidecarPath(video) {
|
|
23
26
|
return `${video.replace(/\.[^./\\]+$/, "")}.index.json`;
|
|
24
27
|
}
|
|
28
|
+
export function samePath(a, b) {
|
|
29
|
+
const norm = (p) => (process.platform === "win32" ? resolve(p).toLowerCase() : resolve(p));
|
|
30
|
+
return norm(a) === norm(b);
|
|
31
|
+
}
|
|
32
|
+
export function indexMatchesVideo(index, video, fingerprint) {
|
|
33
|
+
if (typeof index.video === "string" && samePath(index.video, video))
|
|
34
|
+
return true;
|
|
35
|
+
return fingerprint !== undefined && !!index.fingerprint && sameFingerprint(index.fingerprint, fingerprint);
|
|
36
|
+
}
|
|
25
37
|
export function fallbackIndexPath(video, editsDir) {
|
|
26
38
|
const key = createHash("sha1").update(resolve(video).toLowerCase()).digest("hex").slice(0, 12);
|
|
27
39
|
const name = basename(video).replace(/\.[^.]+$/, "");
|
|
@@ -37,12 +49,41 @@ export function indexWritePath(video, editsDir) {
|
|
|
37
49
|
return fallbackIndexPath(video, editsDir);
|
|
38
50
|
}
|
|
39
51
|
}
|
|
40
|
-
export function findIndex(video, editsDir) {
|
|
52
|
+
export function findIndex(video, editsDir, fingerprint) {
|
|
41
53
|
for (const p of [indexSidecarPath(video), fallbackIndexPath(video, editsDir)])
|
|
42
54
|
if (existsSync(p))
|
|
43
55
|
return p;
|
|
56
|
+
const legacy = legacyIndexSidecarPath(video);
|
|
57
|
+
if (legacy !== indexSidecarPath(video) && existsSync(legacy)) {
|
|
58
|
+
const index = readIndex(legacy);
|
|
59
|
+
if (index && indexMatchesVideo(index, video, fingerprint))
|
|
60
|
+
return legacy;
|
|
61
|
+
}
|
|
44
62
|
return null;
|
|
45
63
|
}
|
|
64
|
+
export function canReuseIndex(prior, want) {
|
|
65
|
+
return (prior !== null &&
|
|
66
|
+
sameFingerprint(prior.fingerprint, want.fingerprint) &&
|
|
67
|
+
prior.sceneThreshold === want.sceneThreshold &&
|
|
68
|
+
prior.maxFrames === want.maxFrames &&
|
|
69
|
+
(prior.ocr || !want.ocrAvailable));
|
|
70
|
+
}
|
|
71
|
+
export function maskSegmentText(segments, pattern = DEFAULT_SECRET_PATTERN) {
|
|
72
|
+
return segments.map((s) => (s.ocr.length > 0 ? { ...s, ocr: maskSecrets(s.ocr, pattern) } : s));
|
|
73
|
+
}
|
|
74
|
+
const VIDEO_EXT = /\.(mp4|mkv|mov|webm|avi|m4v|wmv|flv|gif|ts|mpg|mpeg)$/i;
|
|
75
|
+
const stemOf = (name) => name.replace(/\.[^.]+$/, "").toLowerCase();
|
|
76
|
+
export function defaultTranscriptPath(video, siblings) {
|
|
77
|
+
const names = new Set(siblings.map((n) => n.toLowerCase()));
|
|
78
|
+
const own = basename(video);
|
|
79
|
+
if (names.has(`${own}.srt`.toLowerCase()))
|
|
80
|
+
return { path: `${video}.srt`, ambiguous: false };
|
|
81
|
+
const shortName = `${own.replace(/\.[^.]+$/, "")}.srt`;
|
|
82
|
+
if (!names.has(shortName.toLowerCase()))
|
|
83
|
+
return { path: null, ambiguous: false };
|
|
84
|
+
const rival = siblings.some((n) => n.toLowerCase() !== own.toLowerCase() && VIDEO_EXT.test(n) && stemOf(n) === stemOf(own));
|
|
85
|
+
return rival ? { path: null, ambiguous: true } : { path: join(dirname(video), shortName), ambiguous: false };
|
|
86
|
+
}
|
|
46
87
|
export function planKeyframes(changes, durationSec, maxFrames, maxGap = MAX_SEGMENT_SEC) {
|
|
47
88
|
const times = pickSceneFrames(changes.filter((c) => c.timeSec < durationSec), maxFrames).map(r3);
|
|
48
89
|
while (times.length < maxFrames) {
|
|
@@ -188,7 +229,16 @@ export function searchIndex(index, query, opts = {}) {
|
|
|
188
229
|
if (query.length > MAX_QUERY_LENGTH) {
|
|
189
230
|
throw new ScreencastError(`The query is ${query.length} characters; at most ${MAX_QUERY_LENGTH} are allowed.`);
|
|
190
231
|
}
|
|
191
|
-
|
|
232
|
+
if (opts.video !== undefined && !indexMatchesVideo(index, opts.video, opts.fingerprint)) {
|
|
233
|
+
throw new ScreencastError(`The index found is for ${index.video}, not ${opts.video}.`, "Run index_recording on this recording.");
|
|
234
|
+
}
|
|
235
|
+
if (!opts.regex && !/[\p{L}\p{N}]/u.test(normalizeForMatch(query))) {
|
|
236
|
+
throw new ScreencastError("query needs at least one letter or digit.", "For punctuation, use regex: true.");
|
|
237
|
+
}
|
|
238
|
+
const pattern = opts.secretPattern === undefined ? DEFAULT_SECRET_PATTERN : opts.secretPattern;
|
|
239
|
+
const raw = itemsOf(index);
|
|
240
|
+
const masked = pattern ? maskSecrets(raw.map((i) => i.text), pattern) : raw.map((i) => i.text);
|
|
241
|
+
const items = raw.map((item, i) => ({ ...item, text: masked[i] ?? "" }));
|
|
192
242
|
const matched = new Map();
|
|
193
243
|
const add = (item, score) => {
|
|
194
244
|
const entry = matched.get(item.seg) ?? { score: 0, matches: [] };
|
|
@@ -230,13 +280,9 @@ export function searchIndex(index, query, opts = {}) {
|
|
|
230
280
|
.map(([seg, m]) => ({ seg, ...m }))
|
|
231
281
|
.sort((a, b) => b.score - a.score || index.segments[a.seg].start - index.segments[b.seg].start);
|
|
232
282
|
const chosen = ranked.slice(0, opts.limit ?? DEFAULT_SEARCH_LIMIT);
|
|
233
|
-
const pattern = opts.secretPattern === undefined ? DEFAULT_SECRET_PATTERN : opts.secretPattern;
|
|
234
|
-
const shown = chosen.flatMap((c) => c.matches.slice(0, MAX_MATCHES_PER_HIT));
|
|
235
|
-
const masked = pattern ? maskSecrets(shown.map((m) => m.text), pattern) : shown.map((m) => m.text);
|
|
236
|
-
let k = 0;
|
|
237
283
|
const hits = chosen.map((c) => {
|
|
238
284
|
const seg = index.segments[c.seg];
|
|
239
|
-
const matches = c.matches.slice(0, MAX_MATCHES_PER_HIT).map((m) => ({ source: m.source, t: m.t, text: snippet(
|
|
285
|
+
const matches = c.matches.slice(0, MAX_MATCHES_PER_HIT).map((m) => ({ source: m.source, t: m.t, text: snippet(m.text) }));
|
|
240
286
|
return { start: seg.start, end: seg.end, t: Math.min(...c.matches.map((m) => m.t)), score: c.score, matches };
|
|
241
287
|
});
|
|
242
288
|
return { hits, total: matched.size };
|
|
@@ -249,7 +295,7 @@ export async function resolveRecording(args) {
|
|
|
249
295
|
const record = getStore().get(args.sessionId);
|
|
250
296
|
if (!record)
|
|
251
297
|
throw new ScreencastError(`No session with id "${args.sessionId}".`);
|
|
252
|
-
if (record.status === "recording")
|
|
298
|
+
if (record.status === "recording" || record.status === "paused")
|
|
253
299
|
throw new ScreencastError("The recording is still running; stop_recording it first.");
|
|
254
300
|
await whenFinalized(record.id);
|
|
255
301
|
if (!existsSync(record.outputPath))
|
package/dist/utils/replay.js
CHANGED
|
@@ -6,7 +6,7 @@ import { jobTimeoutMs } from "./jobs.js";
|
|
|
6
6
|
import { buildProbeArgs, parseMediaInfo } from "./media.js";
|
|
7
7
|
import { homeRoot, rand, sequencePattern, stamp } from "./paths.js";
|
|
8
8
|
import { resolveQuality } from "./targets.js";
|
|
9
|
-
import { convertEvents, eventPaths, formatEventsJsonl, selectEvents, summarizeEvents, } from "./events.js";
|
|
9
|
+
import { convertEvents, eventPaths, formatEventsJsonl, readRawEventLog, selectEvents, summarizeEvents, } from "./events.js";
|
|
10
10
|
export const REPLAY_SEGMENT_SEC = 2;
|
|
11
11
|
export const REPLAY_SLACK_SEGMENTS = 3;
|
|
12
12
|
export const MIN_REPLAY_SEC = 4;
|
|
@@ -15,6 +15,10 @@ const SEGMENT_PATTERN = "seg%05d.ts";
|
|
|
15
15
|
const SEGMENT_NAME = /^seg(\d{5})\.ts$/;
|
|
16
16
|
const LIST_NAME = "segments.csv";
|
|
17
17
|
const DIR_NAME = /^buf-[\w-]+$/;
|
|
18
|
+
export const REPLAY_EVENT_SLACK_SEC = 60;
|
|
19
|
+
export function replayEventRotateSec(bufferSec) {
|
|
20
|
+
return bufferSec + REPLAY_EVENT_SLACK_SEC;
|
|
21
|
+
}
|
|
18
22
|
export function replayRoot() {
|
|
19
23
|
return join(homeRoot(), "replay");
|
|
20
24
|
}
|
|
@@ -197,7 +201,8 @@ export async function saveReplay(buf, opts) {
|
|
|
197
201
|
includesLive,
|
|
198
202
|
};
|
|
199
203
|
if (buf.events) {
|
|
200
|
-
const
|
|
204
|
+
const sinceMs = buf.events.startMs + fromSec * 1000 - REPLAY_EVENT_SLACK_SEC * 1000;
|
|
205
|
+
const raw = readRawEventLog(buf.events.raw, sinceMs);
|
|
201
206
|
const events = sliceEvents(convertEvents(raw, { startMs: buf.events.startMs, frame: buf.events.frame }), fromSec, toSec);
|
|
202
207
|
const { jsonl } = eventPaths(opts.output);
|
|
203
208
|
writeFileSync(jsonl, formatEventsJsonl(events));
|
|
@@ -213,6 +218,19 @@ export async function saveReplay(buf, opts) {
|
|
|
213
218
|
export function prepareReplayDir(buf) {
|
|
214
219
|
mkdirSync(buf.dir, { recursive: true });
|
|
215
220
|
}
|
|
221
|
+
export function resetReplaySegments(buf) {
|
|
222
|
+
let names;
|
|
223
|
+
try {
|
|
224
|
+
names = readdirSync(buf.dir);
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
for (const name of names) {
|
|
230
|
+
if (SEGMENT_NAME.test(name) || name === LIST_NAME)
|
|
231
|
+
rmSync(join(buf.dir, name), { force: true });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
216
234
|
export function discardReplay(buf) {
|
|
217
235
|
try {
|
|
218
236
|
rmSync(buf.dir, { recursive: true, force: true });
|
package/dist/utils/retention.js
CHANGED
|
@@ -6,6 +6,7 @@ export function retentionDays(env = process.env) {
|
|
|
6
6
|
const n = Number(env[RETENTION_ENV]);
|
|
7
7
|
return Number.isFinite(n) && n > 0 ? n : null;
|
|
8
8
|
}
|
|
9
|
+
const INDEX_FILE = /\.index\.json(\.\d+\.tmp)?$/;
|
|
9
10
|
export function pruneCaptures(days, now = Date.now(), root = homeRoot()) {
|
|
10
11
|
const cutoff = now - days * 86_400_000;
|
|
11
12
|
const result = { removed: 0, bytes: 0 };
|
|
@@ -40,6 +41,8 @@ export function pruneCaptures(days, now = Date.now(), root = homeRoot()) {
|
|
|
40
41
|
};
|
|
41
42
|
prune(join(root, "screenshots"), () => false, true);
|
|
42
43
|
prune(join(root, "frames"), () => false, true);
|
|
43
|
-
prune(join(root, "recordings"), (name) => !/\.events\.raw(\.stop)?$/.test(name), false);
|
|
44
|
+
prune(join(root, "recordings"), (name) => !/\.events\.raw(\.stop)?$/.test(name) && !INDEX_FILE.test(name), false);
|
|
45
|
+
prune(join(root, "edits"), (name) => !INDEX_FILE.test(name), false);
|
|
46
|
+
prune(join(root, "edits", "indexes"), (name) => !INDEX_FILE.test(name), false);
|
|
44
47
|
return result;
|
|
45
48
|
}
|
package/dist/utils/roots.js
CHANGED
package/dist/utils/sessions.js
CHANGED
|
@@ -4,7 +4,12 @@ import { basename } from "node:path";
|
|
|
4
4
|
import { ScreencastError } from "./errors.js";
|
|
5
5
|
import { WGC_WINDOW_CLOSED_EXIT } from "./wgc.js";
|
|
6
6
|
export const MAX_FINISHED_RECORDS = 100;
|
|
7
|
+
export function isLive(status) {
|
|
8
|
+
return status === "recording" || status === "paused";
|
|
9
|
+
}
|
|
7
10
|
export function classifyOrphan(record, alive) {
|
|
11
|
+
if (record.status === "paused")
|
|
12
|
+
return { status: "stopped", reaped: false };
|
|
8
13
|
if (record.status !== "recording") {
|
|
9
14
|
return { status: record.status, reaped: false };
|
|
10
15
|
}
|
|
@@ -13,7 +18,7 @@ export function classifyOrphan(record, alive) {
|
|
|
13
18
|
: { status: "stopped", reaped: false };
|
|
14
19
|
}
|
|
15
20
|
export function isForeignLiveRecording(record, currentServerPid, ownerAlive) {
|
|
16
|
-
return (record.status
|
|
21
|
+
return (isLive(record.status) &&
|
|
17
22
|
record.serverPid !== undefined &&
|
|
18
23
|
record.serverPid !== currentServerPid &&
|
|
19
24
|
ownerAlive);
|
|
@@ -105,9 +110,9 @@ export function killPid(pid) {
|
|
|
105
110
|
}
|
|
106
111
|
}
|
|
107
112
|
export function pruneRecords(records) {
|
|
108
|
-
const active = records.filter((r) => r.status
|
|
113
|
+
const active = records.filter((r) => isLive(r.status));
|
|
109
114
|
const finished = records
|
|
110
|
-
.filter((r) => r.status
|
|
115
|
+
.filter((r) => !isLive(r.status))
|
|
111
116
|
.sort((a, b) => (a.startedAt < b.startedAt ? 1 : -1))
|
|
112
117
|
.slice(0, MAX_FINISHED_RECORDS);
|
|
113
118
|
return [...active, ...finished];
|
|
@@ -375,11 +380,26 @@ export class SessionStore {
|
|
|
375
380
|
getChild(id) {
|
|
376
381
|
return this.children.get(id);
|
|
377
382
|
}
|
|
378
|
-
detachChild(id) {
|
|
383
|
+
detachChild(id, child) {
|
|
384
|
+
if (child && this.children.get(id) !== child)
|
|
385
|
+
return;
|
|
379
386
|
this.children.delete(id);
|
|
380
387
|
}
|
|
381
388
|
activeIds() {
|
|
382
|
-
return [
|
|
389
|
+
return [
|
|
390
|
+
...[...this.children.keys()].filter((id) => this.records.get(id)?.status === "recording"),
|
|
391
|
+
...[...this.paused].filter((id) => this.records.get(id)?.status === "paused" && !this.children.has(id)),
|
|
392
|
+
];
|
|
393
|
+
}
|
|
394
|
+
paused = new Set();
|
|
395
|
+
markPaused(id) {
|
|
396
|
+
this.paused.add(id);
|
|
397
|
+
}
|
|
398
|
+
ownsPaused(id) {
|
|
399
|
+
return this.paused.has(id);
|
|
400
|
+
}
|
|
401
|
+
clearPaused(id) {
|
|
402
|
+
this.paused.delete(id);
|
|
383
403
|
}
|
|
384
404
|
markStopping(id) {
|
|
385
405
|
this.stopping.add(id);
|
|
@@ -403,7 +423,7 @@ export class SessionStore {
|
|
|
403
423
|
return isSameServer(record, owners.get(pid) ?? null);
|
|
404
424
|
};
|
|
405
425
|
for (const record of this.records.values()) {
|
|
406
|
-
if (record.status
|
|
426
|
+
if (!isLive(record.status))
|
|
407
427
|
continue;
|
|
408
428
|
if (isForeignLiveRecording(record, process.pid, ownerAlive(record))) {
|
|
409
429
|
continue;
|
|
@@ -421,6 +441,12 @@ export class SessionStore {
|
|
|
421
441
|
...(verdict.status === "orphaned"
|
|
422
442
|
? { error: "Reaped on server restart (recording was interrupted)." }
|
|
423
443
|
: {}),
|
|
444
|
+
...(record.status === "paused"
|
|
445
|
+
? {
|
|
446
|
+
endReason: "shutdown",
|
|
447
|
+
error: `The server exited while this recording was paused; its parts were not joined (${record.segments?.parts.map((p) => p.path).join(", ") ?? record.outputPath}).`,
|
|
448
|
+
}
|
|
449
|
+
: {}),
|
|
424
450
|
};
|
|
425
451
|
this.records.set(record.id, { ...record, ...patch });
|
|
426
452
|
this.pending.set(record.id, { ...this.pending.get(record.id), ...patch });
|
package/dist/utils/stepGuide.js
CHANGED
|
@@ -103,6 +103,32 @@ export function shotFilter(size, opts) {
|
|
|
103
103
|
export function buildStepFrameArgs(input, t, output) {
|
|
104
104
|
return ["-y", "-v", "error", "-ss", String(t), "-i", input, "-frames:v", "1", output];
|
|
105
105
|
}
|
|
106
|
+
export const HTML_MAX_BYTES = 10_000_000;
|
|
107
|
+
export const HTML_IMAGE_LADDER = [
|
|
108
|
+
{ width: 1280, q: 4 },
|
|
109
|
+
{ width: 960, q: 6 },
|
|
110
|
+
{ width: 800, q: 8 },
|
|
111
|
+
{ width: 640, q: 10 },
|
|
112
|
+
{ width: 480, q: 14 },
|
|
113
|
+
{ width: 360, q: 20 },
|
|
114
|
+
];
|
|
115
|
+
export const htmlImageName = (file) => file.replace(/\.png$/i, ".jpg");
|
|
116
|
+
export function buildHtmlImageArgs(png, rung, output) {
|
|
117
|
+
return [
|
|
118
|
+
"-y", "-v", "error", "-i", png,
|
|
119
|
+
"-vf", `scale=w='min(iw,${rung.width})':h=-2:flags=lanczos,format=yuvj420p`,
|
|
120
|
+
"-frames:v", "1", "-q:v", String(rung.q), output,
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
export const base64Bytes = (n) => 4 * Math.ceil(n / 3);
|
|
124
|
+
export function nextHtmlRung(at, bytes, budget = HTML_MAX_BYTES) {
|
|
125
|
+
const w = HTML_IMAGE_LADDER[at].width;
|
|
126
|
+
for (let k = at + 1; k < HTML_IMAGE_LADDER.length; k++) {
|
|
127
|
+
if (bytes * (HTML_IMAGE_LADDER[k].width / w) ** 2 <= budget)
|
|
128
|
+
return k;
|
|
129
|
+
}
|
|
130
|
+
return at + 1 < HTML_IMAGE_LADDER.length ? HTML_IMAGE_LADDER.length - 1 : null;
|
|
131
|
+
}
|
|
106
132
|
export function buildStepShotArgs(frame, filter, output) {
|
|
107
133
|
return ["-y", "-v", "error", "-i", frame, "-filter_complex", filter, "-map", "[out]", "-frames:v", "1", output];
|
|
108
134
|
}
|
package/dist/utils/targets.js
CHANGED
|
@@ -150,6 +150,11 @@ export function targetInputArgs(target, monitors, opts = {}) {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
+
export function buildWebcamInputArgs(device) {
|
|
154
|
+
if (device.trim().length === 0)
|
|
155
|
+
throw new ScreencastError("webcam device must not be empty.");
|
|
156
|
+
return ["-f", "dshow", "-use_wallclock_as_timestamps", "1", "-rtbufsize", "256M", "-i", `video=${device}`];
|
|
157
|
+
}
|
|
153
158
|
export const DEFAULT_MAX_RECORDING_SEC = 3600;
|
|
154
159
|
export function resolveMaxDuration(explicit, env = process.env) {
|
|
155
160
|
if (explicit !== undefined)
|
|
@@ -180,26 +185,45 @@ function validateFps(fps) {
|
|
|
180
185
|
export function captureKeyframeArgs(fps) {
|
|
181
186
|
return ["-g", String(Math.max(1, Math.round(fps * 2)))];
|
|
182
187
|
}
|
|
188
|
+
const FRAGMENTED_MP4 = ["-movflags", "+frag_keyframe+empty_moov+default_base_moof"];
|
|
183
189
|
export function buildCaptureArgs(target, opts) {
|
|
184
190
|
const fps = validateFps(opts.fps ?? DEFAULT_FPS);
|
|
185
191
|
const quality = opts.quality ?? DEFAULT_QUALITY;
|
|
186
192
|
const monitors = opts.monitors ?? [];
|
|
187
193
|
const cap = validateMaxDuration(opts.maxDurationSec ?? 0);
|
|
194
|
+
const capArgs = cap > 0 ? ["-t", String(cap)] : [];
|
|
195
|
+
const cam = opts.webcam;
|
|
196
|
+
const camInput = opts.audio ? 2 : 1;
|
|
188
197
|
return [
|
|
189
198
|
"-y",
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
199
|
+
...(opts.videoInput ?? [
|
|
200
|
+
"-f", "gdigrab",
|
|
201
|
+
"-framerate", String(fps),
|
|
202
|
+
...(opts.drawMouse === false ? ["-draw_mouse", "0"] : []),
|
|
203
|
+
...targetInputArgs(target, monitors, { evenSize: true }),
|
|
204
|
+
]),
|
|
193
205
|
...buildAudioInputArgs(opts.audio),
|
|
194
|
-
...(
|
|
206
|
+
...(cam ? buildWebcamInputArgs(cam.device) : []),
|
|
207
|
+
...(cam ? ["-map", "0:v", ...(opts.audio ? ["-map", "1:a"] : [])] : []),
|
|
208
|
+
...(!opts.videoInput && target.kind === "full" && monitors.length === 0
|
|
195
209
|
? ["-vf", "crop=trunc(iw/2)*2:trunc(ih/2)*2"]
|
|
196
210
|
: []),
|
|
197
|
-
...resolveQuality(quality),
|
|
211
|
+
...(opts.videoCodec ?? resolveQuality(quality)),
|
|
198
212
|
...captureKeyframeArgs(fps),
|
|
199
213
|
...(opts.audio ? ["-c:a", "aac", "-b:a", "160k"] : []),
|
|
200
|
-
|
|
201
|
-
...
|
|
214
|
+
...FRAGMENTED_MP4,
|
|
215
|
+
...capArgs,
|
|
202
216
|
opts.output,
|
|
217
|
+
...(cam
|
|
218
|
+
? [
|
|
219
|
+
"-map", `${camInput}:v`,
|
|
220
|
+
...(cam.codec ?? resolveQuality(quality)),
|
|
221
|
+
...captureKeyframeArgs(fps),
|
|
222
|
+
...FRAGMENTED_MP4,
|
|
223
|
+
...capArgs,
|
|
224
|
+
cam.output,
|
|
225
|
+
]
|
|
226
|
+
: []),
|
|
203
227
|
];
|
|
204
228
|
}
|
|
205
229
|
export const SCREENSHOT_GRAB_FPS = 30;
|
package/dist/utils/toolsets.js
CHANGED
|
@@ -3,6 +3,8 @@ export const TOOLSETS = {
|
|
|
3
3
|
capture: [
|
|
4
4
|
"start_recording",
|
|
5
5
|
"stop_recording",
|
|
6
|
+
"pause_recording",
|
|
7
|
+
"resume_recording",
|
|
6
8
|
"save_replay",
|
|
7
9
|
"list_sessions",
|
|
8
10
|
"get_session",
|
|
@@ -11,6 +13,7 @@ export const TOOLSETS = {
|
|
|
11
13
|
"screenshot",
|
|
12
14
|
"list_targets",
|
|
13
15
|
"list_audio_devices",
|
|
16
|
+
"list_video_devices",
|
|
14
17
|
],
|
|
15
18
|
watch: [
|
|
16
19
|
"sample_frames",
|
|
@@ -41,6 +44,7 @@ export const TOOLSETS = {
|
|
|
41
44
|
produce: [
|
|
42
45
|
"callout",
|
|
43
46
|
"keystroke_overlay",
|
|
47
|
+
"cursor",
|
|
44
48
|
"backdrop",
|
|
45
49
|
"overlay",
|
|
46
50
|
"zoom",
|
|
@@ -54,7 +58,7 @@ export const TOOLSETS = {
|
|
|
54
58
|
"bug_report",
|
|
55
59
|
"step_guide",
|
|
56
60
|
],
|
|
57
|
-
audio: ["extract_audio", "normalize_audio", "denoise", "transcribe", "music_bed"],
|
|
61
|
+
audio: ["extract_audio", "normalize_audio", "denoise", "transcribe", "music_bed", "narrate"],
|
|
58
62
|
};
|
|
59
63
|
export const SELECTABLE_TOOLSETS = Object.keys(TOOLSETS).filter((t) => t !== "core");
|
|
60
64
|
export function toolsetOf(tool) {
|
|
@@ -87,6 +91,7 @@ export function serverInstructions(selection) {
|
|
|
87
91
|
lines.push("Capture: screenshot for a still; start_recording -> (do the task) -> stop_recording for video " +
|
|
88
92
|
"(events: true also logs clicks for read_events and zoom). For flaky failures, start_recording " +
|
|
89
93
|
"{ replayBufferSec } keeps a rolling buffer and save_replay writes the last seconds after the fact. " +
|
|
94
|
+
"pause_recording/resume_recording skip setup; backend ddagrab uses the GPU. " +
|
|
90
95
|
"Never start a recording the user did not ask for.");
|
|
91
96
|
}
|
|
92
97
|
if (on.has("watch")) {
|
|
@@ -101,7 +106,7 @@ export function serverInstructions(selection) {
|
|
|
101
106
|
"segment, clip = several files; export_gif for size-bounded GIF/WebP, compress for a smaller mp4.");
|
|
102
107
|
}
|
|
103
108
|
if (on.has("produce")) {
|
|
104
|
-
lines.push("Produce: callout, zoom, keystroke_overlay, backdrop, overlay, title_card, xfade_transition, assemble_highlights, burn_subtitles, export_preset.");
|
|
109
|
+
lines.push("Produce: callout, zoom, keystroke_overlay, cursor, backdrop, overlay, title_card, xfade_transition, assemble_highlights, burn_subtitles, export_preset.");
|
|
105
110
|
}
|
|
106
111
|
if (on.has("produce")) {
|
|
107
112
|
lines.push("Bug reports: bug_report turns a recording (path or sessionId) into one redacted folder: clip, GIF, " +
|
|
@@ -116,7 +121,7 @@ export function serverInstructions(selection) {
|
|
|
116
121
|
lines.push(`Markers: ${marks.filter(Boolean).join(" ")}`);
|
|
117
122
|
}
|
|
118
123
|
if (on.has("audio")) {
|
|
119
|
-
lines.push("Audio: extract_audio, normalize_audio, denoise, music_bed; transcribe makes an SRT for burn_subtitles (words: true for word timing, then cut_by_transcript cuts by quoting it).");
|
|
124
|
+
lines.push("Audio: extract_audio, normalize_audio, denoise, music_bed, narrate (offline voiceover); transcribe makes an SRT for burn_subtitles (words: true for word timing, then cut_by_transcript cuts by quoting it).");
|
|
120
125
|
}
|
|
121
126
|
lines.push("Outputs go under SCREENCAST_HOME unless a call names a path; times are seconds and positions video pixels. " +
|
|
122
127
|
"Screen content can include secrets: redact (find_text redact: true -> redact_region) before sharing. " +
|
|
@@ -57,10 +57,10 @@ export function mergeCuts(cuts) {
|
|
|
57
57
|
for (const c of sorted) {
|
|
58
58
|
const prev = out[out.length - 1];
|
|
59
59
|
if (prev && c.start <= prev.end + 0.01) {
|
|
60
|
-
if (c.end > prev.end)
|
|
60
|
+
if (c.end > prev.end)
|
|
61
61
|
prev.end = c.end;
|
|
62
|
+
if (!prev.text.includes(c.text))
|
|
62
63
|
prev.text = `${prev.text} ${c.text}`;
|
|
63
|
-
}
|
|
64
64
|
prev.exact &&= c.exact;
|
|
65
65
|
}
|
|
66
66
|
else
|
|
@@ -68,14 +68,29 @@ export function mergeCuts(cuts) {
|
|
|
68
68
|
}
|
|
69
69
|
return out;
|
|
70
70
|
}
|
|
71
|
+
export function cueByNumber(cues, n) {
|
|
72
|
+
const numbers = cues.flatMap((c) => (c.index === undefined ? [] : [c.index]));
|
|
73
|
+
if (numbers.length === 0) {
|
|
74
|
+
const c = Number.isInteger(n) ? cues[n - 1] : undefined;
|
|
75
|
+
if (!c)
|
|
76
|
+
throw new ScreencastError(`No cue ${n}: the transcript has cues 1-${cues.length}.`);
|
|
77
|
+
return c;
|
|
78
|
+
}
|
|
79
|
+
const hits = cues.filter((c) => c.index === n);
|
|
80
|
+
if (hits.length > 1)
|
|
81
|
+
throw new ScreencastError(`The transcript numbers ${hits.length} cues ${n}; quote the text to cut instead.`);
|
|
82
|
+
if (hits.length === 0) {
|
|
83
|
+
throw new ScreencastError(`No cue ${n}: the transcript's cues are numbered ${Math.min(...numbers)}-${Math.max(...numbers)}` +
|
|
84
|
+
" (a cue with no duration, or wholly overlapped by the next, has no time to cut).");
|
|
85
|
+
}
|
|
86
|
+
return hits[0];
|
|
87
|
+
}
|
|
71
88
|
export function planTranscriptCuts(cues, req) {
|
|
72
89
|
const words = cueWords(cues);
|
|
73
90
|
const cuts = [];
|
|
74
91
|
for (const r of req.remove ?? []) {
|
|
75
92
|
if (typeof r === "number") {
|
|
76
|
-
const c = cues
|
|
77
|
-
if (!Number.isInteger(r) || !c)
|
|
78
|
-
throw new ScreencastError(`No cue ${r}: the transcript has cues 1-${cues.length}.`);
|
|
93
|
+
const c = cueByNumber(cues, r);
|
|
79
94
|
cuts.push({ start: r3(c.start), end: r3(c.end), text: c.text.replace(/\s+/g, " "), exact: true });
|
|
80
95
|
continue;
|
|
81
96
|
}
|
package/dist/utils/wgc.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ScreencastError } from "./errors.js";
|
|
2
|
-
export function buildWgcGrabArgs(hwnd, fps) {
|
|
2
|
+
export function buildWgcGrabArgs(hwnd, fps, cursor = true) {
|
|
3
3
|
if (!Number.isSafeInteger(hwnd) || hwnd <= 0)
|
|
4
4
|
throw new ScreencastError("Invalid window handle.");
|
|
5
5
|
return [
|
|
6
6
|
"-hide_banner", "-nostats", "-loglevel", "info",
|
|
7
7
|
"-f", "lavfi",
|
|
8
|
-
"-i", `gfxcapture=hwnd=${hwnd}:max_framerate=${fps},hwdownload,format=bgra,crop=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,
|
|
8
|
+
"-i", `gfxcapture=hwnd=${hwnd}:max_framerate=${fps}${cursor ? "" : ":capture_cursor=0"},hwdownload,format=bgra,crop=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,
|
|
9
9
|
"-flush_packets", "1",
|
|
10
10
|
"-f", "rawvideo", "-",
|
|
11
11
|
];
|