@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
|
@@ -4,18 +4,20 @@ import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
|
4
4
|
import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
|
|
5
5
|
import { requireFfmpeg, wgcAvailable } from "../utils/ffmpeg.js";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { buildCaptureArgs, captureFrame,
|
|
7
|
+
import { buildCaptureArgs, captureFrame, DEFAULT_FPS, DEFAULT_QUALITY, DEFAULT_MAX_RECORDING_SEC, MAX_RECORDING_CAP_SEC, resolveMaxDuration, captureKeyframeArgs, } from "../utils/targets.js";
|
|
8
8
|
import { resolveCaptureTarget } from "../utils/resolveTarget.js";
|
|
9
9
|
import { windowMatchReport } from "../utils/windows.js";
|
|
10
|
-
import { resolveLoopbackDevice } from "../utils/audioDevices.js";
|
|
10
|
+
import { resolveLoopbackDevice, resolveVideoDevice } from "../utils/audioDevices.js";
|
|
11
11
|
import { confirmCapture, describeTarget } from "../utils/consent.js";
|
|
12
|
-
import { logMessage, StderrWatch } from "../utils/logging.js";
|
|
13
12
|
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
14
13
|
import { getStore } from "../context.js";
|
|
15
|
-
import {
|
|
16
|
-
import { rmSync } from "node:fs";
|
|
14
|
+
import { killPid, serverIdentity } from "../utils/sessions.js";
|
|
15
|
+
import { mkdirSync, rmSync } from "node:fs";
|
|
16
|
+
import { buildDdaInputArgs, ddagrabWorks, encoderArgs, getDxgiOutputs, planDdaSource, resolveEncoder, startWithEncoderFallback, } from "../utils/gpu.js";
|
|
17
|
+
import { attachExitHandler, captureStartMs, settleCapture, tailLines, watchStderr, } from "../utils/recorder.js";
|
|
18
|
+
import { DEFAULT_WEBCAM_SIZE, eventClock, partsDir, sessionEnded, webcamOutputPath, webcamPartPath, } from "../utils/pause.js";
|
|
17
19
|
import { basename, join } from "node:path";
|
|
18
|
-
import { MAX_REPLAY_SEC, MIN_REPLAY_SEC, discardReplay, planReplayBuffer, prepareReplayDir, segmentOutputArgs, } from "../utils/replay.js";
|
|
20
|
+
import { MAX_REPLAY_SEC, MIN_REPLAY_SEC, discardReplay, planReplayBuffer, prepareReplayDir, replayEventRotateSec, resetReplaySegments, segmentOutputArgs, } from "../utils/replay.js";
|
|
19
21
|
import { DEFAULT_KEY_MODE, eventPaths, parseCaptureStart, prepareEventPaths, startEventLogger, stopEventLogger, summarizeEvents, trackFinalizer, writeEventsFile, } from "../utils/events.js";
|
|
20
22
|
const inputSchema = {
|
|
21
23
|
target: z
|
|
@@ -73,19 +75,49 @@ const inputSchema = {
|
|
|
73
75
|
.optional()
|
|
74
76
|
.describe("With events: masked (default) logs typing only as 0.5 s-grid bursts, never keys; shortcuts " +
|
|
75
77
|
"also names Ctrl/Alt/Win chords. Typed text is never logged."),
|
|
78
|
+
cursor: z
|
|
79
|
+
.enum(["os", "events"])
|
|
80
|
+
.optional()
|
|
81
|
+
.describe('events: leave the OS cursor out and log it (implies events) for the cursor tool to redraw.'),
|
|
76
82
|
backend: z
|
|
77
|
-
.enum(["gdigrab", "wgc"])
|
|
83
|
+
.enum(["gdigrab", "wgc", "ddagrab"])
|
|
78
84
|
.optional()
|
|
79
85
|
.describe("gdigrab (default): the screen rectangle. wgc (window: targets, FFmpeg 8+): the window's own " +
|
|
80
|
-
"surface, even when covered or moved; client area only, no audio."),
|
|
86
|
+
"surface, even when covered or moved; client area only, no audio. ddagrab: one display on the GPU, low CPU."),
|
|
87
|
+
encoder: z
|
|
88
|
+
.enum(["auto", "x264", "nvenc", "qsv", "amf"])
|
|
89
|
+
.optional()
|
|
90
|
+
.describe("auto = first working GPU encoder, else x264 (default with ddagrab; else x264)."),
|
|
91
|
+
webcam: z
|
|
92
|
+
.object({
|
|
93
|
+
device: z.string().optional().describe("list_video_devices name (default: first)."),
|
|
94
|
+
corner: z.enum(["top_left", "top_right", "bottom_left", "bottom_right"]).optional(),
|
|
95
|
+
size: z.number().min(0.1).max(0.5).optional().describe("Share of width (0.25)."),
|
|
96
|
+
shape: z.enum(["rect", "circle"]).optional(),
|
|
97
|
+
})
|
|
98
|
+
.optional()
|
|
99
|
+
.describe("Also record a camera to <output>.webcam.mp4, aligned for overlay."),
|
|
81
100
|
replayBufferSec: z
|
|
82
101
|
.number()
|
|
83
102
|
.int()
|
|
84
103
|
.min(MIN_REPLAY_SEC)
|
|
85
104
|
.max(MAX_REPLAY_SEC)
|
|
86
105
|
.optional()
|
|
87
|
-
.describe("Instant replay: keep only the last N s (bounded disk) for save_replay. gdigrab
|
|
106
|
+
.describe("Instant replay: keep only the last N s (bounded disk) for save_replay. gdigrab or ddagrab, not wgc."),
|
|
88
107
|
};
|
|
108
|
+
function frameSize(target, monitors) {
|
|
109
|
+
try {
|
|
110
|
+
const f = captureFrame(target, monitors);
|
|
111
|
+
return { width: f.w, height: f.h };
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function webcamStart(watch, audio) {
|
|
118
|
+
const ms = parseCaptureStart(watch.head(), audio ? 2 : 1);
|
|
119
|
+
return ms !== null ? { webcamStartMs: ms } : {};
|
|
120
|
+
}
|
|
89
121
|
export function register(server) {
|
|
90
122
|
server.registerTool("start_recording", {
|
|
91
123
|
title: "Start Recording",
|
|
@@ -102,6 +134,9 @@ export function register(server) {
|
|
|
102
134
|
}, async (args, extra) => {
|
|
103
135
|
try {
|
|
104
136
|
const { ffmpeg } = requireFfmpeg();
|
|
137
|
+
const hideCursor = args.cursor === "events";
|
|
138
|
+
if (hideCursor)
|
|
139
|
+
args.events = true;
|
|
105
140
|
const { target, monitors, window } = await resolveCaptureTarget(args.target, {
|
|
106
141
|
exactTitle: args.exactTitle,
|
|
107
142
|
backend: args.backend,
|
|
@@ -117,7 +152,7 @@ export function register(server) {
|
|
|
117
152
|
}
|
|
118
153
|
}
|
|
119
154
|
if (args.replayBufferSec !== undefined && backend === "wgc") {
|
|
120
|
-
throw new ScreencastError('replayBufferSec is not supported with backend "wgc" yet; use gdigrab.');
|
|
155
|
+
throw new ScreencastError('replayBufferSec is not supported with backend "wgc" yet; use gdigrab or ddagrab.');
|
|
121
156
|
}
|
|
122
157
|
const replay = args.replayBufferSec !== undefined ? planReplayBuffer(args.replayBufferSec) : null;
|
|
123
158
|
const fps = args.fps ?? DEFAULT_FPS;
|
|
@@ -127,21 +162,48 @@ export function register(server) {
|
|
|
127
162
|
const audio = args.audio?.source === "system"
|
|
128
163
|
? { device: await resolveLoopbackDevice(args.audio.device) }
|
|
129
164
|
: undefined;
|
|
165
|
+
if (args.webcam && (backend === "wgc" || replay)) {
|
|
166
|
+
throw new ScreencastError("webcam works with backend gdigrab or ddagrab, without replayBufferSec.");
|
|
167
|
+
}
|
|
168
|
+
const webcamDevice = args.webcam ? await resolveVideoDevice(args.webcam.device) : undefined;
|
|
169
|
+
const dda = backend === "ddagrab" ? planDdaSource(captureFrame(target, monitors), await getDxgiOutputs()) : null;
|
|
130
170
|
await confirmCapture(server, (replay ? `Keep a rolling ${replay.bufferSec} s replay buffer of ` : "Record ") +
|
|
131
171
|
`${describeTarget(args.target, window)} ` +
|
|
132
172
|
(maxDurationSec > 0 ? `for up to ${maxDurationSec} s` : "with no time limit") +
|
|
133
173
|
(audio ? `, with system audio (${audio.device})` : ", without audio") +
|
|
174
|
+
(webcamDevice ? `, with the webcam (${webcamDevice})` : "") +
|
|
134
175
|
(args.events ? ", logging mouse clicks and typing" : "") +
|
|
135
176
|
(replay ? ", kept only until save_replay or stop_recording { save: true } writes it out?" : `, saved to ${output}?`), extra.signal);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
177
|
+
let pick = await resolveEncoder(args.encoder ?? (backend === "ddagrab" ? "auto" : "x264"), backend === "ddagrab" ? "ddagrab" : "gdigrab", ffmpeg, undefined, backend === "wgc" ? undefined : frameSize(target, monitors));
|
|
178
|
+
const ddaUsable = async (p) => !dda || p.gpuFrames || (await ddagrabWorks(ffmpeg));
|
|
179
|
+
if (!(await ddaUsable(pick))) {
|
|
180
|
+
throw new ScreencastError("Desktop Duplication (ddagrab) does not capture on this machine (a remote session, or no D3D11 GPU).", 'Use backend "gdigrab".');
|
|
181
|
+
}
|
|
182
|
+
const webcamRaw = webcamDevice ? webcamPartPath(output, 0) : undefined;
|
|
183
|
+
if (webcamRaw)
|
|
184
|
+
mkdirSync(partsDir(output), { recursive: true });
|
|
185
|
+
const plan = (p) => {
|
|
186
|
+
const hw = p.encoder !== "x264";
|
|
187
|
+
const captureOpts = {
|
|
188
|
+
fps,
|
|
189
|
+
quality,
|
|
190
|
+
monitors,
|
|
191
|
+
audio,
|
|
192
|
+
drawMouse: !hideCursor,
|
|
193
|
+
...(dda ? { videoInput: buildDdaInputArgs(dda, fps, { download: !p.gpuFrames, drawMouse: !hideCursor }) } : {}),
|
|
194
|
+
...(hw ? { videoCodec: encoderArgs(p.encoder, quality, { gpuFrames: p.gpuFrames }) } : {}),
|
|
195
|
+
};
|
|
196
|
+
const webcam = webcamDevice
|
|
197
|
+
? { device: webcamDevice, ...(hw ? { codec: encoderArgs(p.encoder, quality) } : {}) }
|
|
198
|
+
: undefined;
|
|
199
|
+
const captureArgs = buildCaptureArgs(target, {
|
|
200
|
+
...captureOpts,
|
|
201
|
+
output,
|
|
202
|
+
maxDurationSec,
|
|
203
|
+
...(webcam && webcamRaw ? { webcam: { ...webcam, output: webcamRaw } } : {}),
|
|
204
|
+
});
|
|
205
|
+
return { captureOpts, webcam, ffArgs: replay ? segmentOutputArgs(captureArgs, replay) : captureArgs };
|
|
206
|
+
};
|
|
145
207
|
if (replay)
|
|
146
208
|
prepareReplayDir(replay);
|
|
147
209
|
const keyMode = args.keys ?? DEFAULT_KEY_MODE;
|
|
@@ -151,60 +213,52 @@ export function register(server) {
|
|
|
151
213
|
let frame = args.events
|
|
152
214
|
? captureFrame(target, monitors)
|
|
153
215
|
: null;
|
|
154
|
-
const logger = evPaths
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
? spawn(process.execPath, [
|
|
158
|
-
fileURLToPath(new URL("../wgcRecorder.js", import.meta.url)),
|
|
159
|
-
JSON.stringify({ ffmpeg, hwnd: window.hwnd, fps, encode: [...resolveQuality(quality), ...captureKeyframeArgs(fps)], output, maxDurationSec }),
|
|
160
|
-
], { stdio: ["pipe", "ignore", "pipe"], windowsHide: true })
|
|
161
|
-
: spawn(ffmpeg, ffArgs, {
|
|
162
|
-
stdio: ["pipe", "ignore", "pipe"],
|
|
163
|
-
windowsHide: true,
|
|
164
|
-
});
|
|
165
|
-
let stderrTail = "";
|
|
166
|
-
let stderrHead = "";
|
|
216
|
+
const logger = evPaths
|
|
217
|
+
? await startEventLogger(evPaths.raw, keyMode, replay ? { rotateSec: replayEventRotateSec(replay.bufferSec) } : {})
|
|
218
|
+
: null;
|
|
167
219
|
const id = `rec-${stamp()}-${rand(6)}`;
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
child.stderr?.on("data", () => {
|
|
180
|
-
if (parseCaptureStart(stderrHead) !== null) {
|
|
181
|
-
clearTimeout(timer);
|
|
182
|
-
resolve("running");
|
|
183
|
-
}
|
|
220
|
+
const launch = async (p) => {
|
|
221
|
+
const settings = plan(p);
|
|
222
|
+
const spawnedAt = Date.now();
|
|
223
|
+
const child = backend === "wgc"
|
|
224
|
+
? spawn(process.execPath, [
|
|
225
|
+
fileURLToPath(new URL("../wgcRecorder.js", import.meta.url)),
|
|
226
|
+
JSON.stringify({ ffmpeg, hwnd: window.hwnd, fps, encode: [...encoderArgs(p.encoder, quality), ...captureKeyframeArgs(fps)], output, maxDurationSec, cursor: !hideCursor }),
|
|
227
|
+
], { stdio: ["pipe", "ignore", "pipe"], windowsHide: true })
|
|
228
|
+
: spawn(ffmpeg, settings.ffArgs, {
|
|
229
|
+
stdio: ["pipe", "ignore", "pipe"],
|
|
230
|
+
windowsHide: true,
|
|
184
231
|
});
|
|
185
|
-
|
|
186
|
-
child
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
232
|
+
const watch = watchStderr(child, id);
|
|
233
|
+
const settled = await settleCapture(child, watch, backend);
|
|
234
|
+
return { ...settings, child, watch, spawnedAt, settled };
|
|
235
|
+
};
|
|
236
|
+
const started = await startWithEncoderFallback(pick, launch, {
|
|
237
|
+
why: (r) => tailLines(r.watch, 3),
|
|
238
|
+
canFallback: () => ddaUsable({ encoder: "x264", gpuFrames: false }),
|
|
239
|
+
beforeRetry: () => {
|
|
240
|
+
if (replay)
|
|
241
|
+
resetReplaySegments(replay);
|
|
242
|
+
},
|
|
195
243
|
});
|
|
196
|
-
|
|
244
|
+
const { run, failure: retried } = started;
|
|
245
|
+
pick = started.pick;
|
|
246
|
+
const { child, watch, spawnedAt, captureOpts, webcam } = run;
|
|
247
|
+
if (run.settled === "exited") {
|
|
197
248
|
if (logger)
|
|
198
249
|
await stopEventLogger(logger);
|
|
199
250
|
if (evPaths)
|
|
200
251
|
rmSync(evPaths.raw, { force: true });
|
|
201
252
|
if (replay)
|
|
202
253
|
discardReplay(replay);
|
|
203
|
-
|
|
204
|
-
|
|
254
|
+
if (webcamRaw)
|
|
255
|
+
rmSync(partsDir(output), { recursive: true, force: true });
|
|
256
|
+
throw new ScreencastError(`Recording failed to start (${backend === "wgc" ? "window capture" : "ffmpeg"} exited immediately):\n${tailLines(watch)}` +
|
|
257
|
+
(retried ? `\n(Retried with libx264 after ${retried})` : ""));
|
|
205
258
|
}
|
|
259
|
+
const startMs = captureStartMs(watch, backend, spawnedAt);
|
|
206
260
|
if (backend === "wgc" && frame && window?.client) {
|
|
207
|
-
const m = /wgc: (\d+)x(\d+)/.exec(
|
|
261
|
+
const m = /wgc: (\d+)x(\d+)/.exec(watch.head());
|
|
208
262
|
frame = { x: window.client.x, y: window.client.y, w: m ? Number(m[1]) : frame.w, h: m ? Number(m[2]) : frame.h };
|
|
209
263
|
}
|
|
210
264
|
const record = {
|
|
@@ -217,7 +271,7 @@ export function register(server) {
|
|
|
217
271
|
...serverIdentity(),
|
|
218
272
|
status: "recording",
|
|
219
273
|
startedAt: new Date().toISOString(),
|
|
220
|
-
videoStartMs:
|
|
274
|
+
videoStartMs: startMs,
|
|
221
275
|
...(maxDurationSec > 0 ? { maxDurationSec } : {}),
|
|
222
276
|
...(window ? { matchedWindow: window.matchedTitle } : {}),
|
|
223
277
|
...(evPaths && !replay ? { events: { path: evPaths.jsonl, keys: keyMode } } : {}),
|
|
@@ -226,12 +280,37 @@ export function register(server) {
|
|
|
226
280
|
replay: {
|
|
227
281
|
...replay,
|
|
228
282
|
...(evPaths && frame
|
|
229
|
-
? { events: { raw: evPaths.raw, keys: keyMode, startMs
|
|
283
|
+
? { events: { raw: evPaths.raw, keys: keyMode, startMs, frame } }
|
|
230
284
|
: {}),
|
|
231
285
|
},
|
|
232
286
|
}
|
|
233
287
|
: {}),
|
|
234
288
|
backend,
|
|
289
|
+
...(pick.encoder !== "x264" ? { encoder: pick.encoder } : {}),
|
|
290
|
+
...(backend !== "wgc" && !replay
|
|
291
|
+
? {
|
|
292
|
+
capture: { target, opts: captureOpts, ...(webcam ? { webcam } : {}) },
|
|
293
|
+
segments: {
|
|
294
|
+
parts: [],
|
|
295
|
+
current: {
|
|
296
|
+
path: output,
|
|
297
|
+
startMs,
|
|
298
|
+
...(webcamRaw ? { webcamPath: webcamRaw, ...webcamStart(watch, !!audio) } : {}),
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
}
|
|
302
|
+
: {}),
|
|
303
|
+
...(webcamDevice
|
|
304
|
+
? {
|
|
305
|
+
webcam: {
|
|
306
|
+
device: webcamDevice,
|
|
307
|
+
path: webcamOutputPath(output),
|
|
308
|
+
corner: args.webcam?.corner ?? "bottom_right",
|
|
309
|
+
size: args.webcam?.size ?? DEFAULT_WEBCAM_SIZE,
|
|
310
|
+
shape: args.webcam?.shape ?? "rect",
|
|
311
|
+
},
|
|
312
|
+
}
|
|
313
|
+
: {}),
|
|
235
314
|
processImage: backend === "wgc" ? basename(process.execPath).toLowerCase() : "ffmpeg.exe",
|
|
236
315
|
};
|
|
237
316
|
const store = getStore();
|
|
@@ -249,6 +328,8 @@ export function register(server) {
|
|
|
249
328
|
rmSync(evPaths.raw, { force: true });
|
|
250
329
|
if (replay)
|
|
251
330
|
discardReplay(replay);
|
|
331
|
+
if (webcamRaw)
|
|
332
|
+
rmSync(partsDir(output), { recursive: true, force: true });
|
|
252
333
|
throw new ScreencastError(`Recording stopped: the session registry could not be written (${err.message}).`);
|
|
253
334
|
}
|
|
254
335
|
if (logger && replay) {
|
|
@@ -256,12 +337,11 @@ export function register(server) {
|
|
|
256
337
|
trackFinalizer(id, exited.then(() => stopEventLogger(logger)));
|
|
257
338
|
}
|
|
258
339
|
else if (logger && evPaths && frame) {
|
|
259
|
-
|
|
260
|
-
trackFinalizer(id, exited.then(async () => {
|
|
340
|
+
trackFinalizer(id, sessionEnded(id).then(async () => {
|
|
261
341
|
await stopEventLogger(logger);
|
|
262
|
-
const startMs = parseCaptureStart(stderrHead) ?? spawnedAt;
|
|
263
342
|
try {
|
|
264
|
-
const
|
|
343
|
+
const clock = eventClock(store.get(id)?.segments, startMs, Date.now());
|
|
344
|
+
const events = writeEventsFile(evPaths, { ...clock, frame });
|
|
265
345
|
store.tryUpdate(id, {
|
|
266
346
|
events: { path: evPaths.jsonl, keys: keyMode, count: events.length, summary: summarizeEvents(events) },
|
|
267
347
|
});
|
|
@@ -275,23 +355,7 @@ export function register(server) {
|
|
|
275
355
|
process.stderr.write(`Event log for ${id} failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
276
356
|
}));
|
|
277
357
|
}
|
|
278
|
-
|
|
279
|
-
store.detachChild(id);
|
|
280
|
-
const cur = store.get(id);
|
|
281
|
-
if (!cur || cur.status !== "recording" || store.isStopping(id))
|
|
282
|
-
return;
|
|
283
|
-
const verdict = classifyUnrequestedExit({ code, backend, maxDurationSec, elapsedMs: Date.now() - spawnedAt });
|
|
284
|
-
logMessage(verdict.status === "failed" ? "error" : "notice", verdict.status === "failed"
|
|
285
|
-
? `Recording ${id} failed: the recorder exited with code ${code}.`
|
|
286
|
-
: `Recording ${id} ended on its own (${verdict.endReason}).`, { sessionId: id, ...verdict });
|
|
287
|
-
store.tryUpdate(id, {
|
|
288
|
-
...verdict,
|
|
289
|
-
stoppedAt: new Date().toISOString(),
|
|
290
|
-
...(verdict.status === "failed"
|
|
291
|
-
? { error: `${backend === "wgc" ? "The window recorder" : "ffmpeg"} exited with code ${code}:\n${stderrTail.trim().split("\n").slice(-6).join("\n")}` }
|
|
292
|
-
: {}),
|
|
293
|
-
});
|
|
294
|
-
});
|
|
358
|
+
attachExitHandler(store, id, child, { backend, maxDurationSec, spawnedAt, watch });
|
|
295
359
|
return okResponse({
|
|
296
360
|
sessionId: id,
|
|
297
361
|
status: "recording",
|
|
@@ -302,6 +366,10 @@ export function register(server) {
|
|
|
302
366
|
quality,
|
|
303
367
|
audioDevice: audio?.device ?? null,
|
|
304
368
|
maxDurationSec: maxDurationSec > 0 ? maxDurationSec : null,
|
|
369
|
+
encoder: pick.encoder,
|
|
370
|
+
...(pick.note ? { encoderNote: pick.note } : {}),
|
|
371
|
+
...(dda ? { gpuFrames: pick.gpuFrames } : {}),
|
|
372
|
+
...(webcamDevice ? { webcam: { device: webcamDevice, path: webcamOutputPath(output) } } : {}),
|
|
305
373
|
...(window ? windowMatchReport(window) : {}),
|
|
306
374
|
...(evPaths && !replay ? { eventsPath: evPaths.jsonl, keys: keyMode } : {}),
|
|
307
375
|
...(replay
|
|
@@ -310,7 +378,8 @@ export function register(server) {
|
|
|
310
378
|
note: (replay
|
|
311
379
|
? `Replay buffer running: save_replay keeps the last seconds (up to ${replay.bufferSec}s) without stopping it; ` +
|
|
312
380
|
"stop_recording discards the buffer unless save: true (then it writes outputPath)."
|
|
313
|
-
: "Call stop_recording with this sessionId to finalize the file
|
|
381
|
+
: "Call stop_recording with this sessionId to finalize the file" +
|
|
382
|
+
(backend === "wgc" ? "." : " (pause_recording/resume_recording leave stretches out).")) +
|
|
314
383
|
(maxDurationSec > 0
|
|
315
384
|
? ` It stops on its own after ${maxDurationSec}s (maxDurationSec).`
|
|
316
385
|
: ""),
|
package/dist/tools/stepGuide.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, rmdirSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
@@ -13,9 +13,10 @@ import { ocrStatus } from "../utils/capabilities.js";
|
|
|
13
13
|
import { readFrames, scanMatches } from "../utils/ocrScan.js";
|
|
14
14
|
import { DEFAULT_SECRET_PATTERN } from "../utils/bugReport.js";
|
|
15
15
|
import { resolveOutputDir, subdir, stamp, rand } from "../utils/paths.js";
|
|
16
|
-
import { GUIDE_FILES, MAX_GUIDE_STEPS, assignSections, buildGuideHtml, buildGuideMarkdown, buildStepFrameArgs, buildStepShotArgs, caption, guideSteps, labelAt, shotFilter, } from "../utils/stepGuide.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
17
|
import { resolveSource } from "./bugReport.js";
|
|
18
18
|
const OCR_BATCH = 10;
|
|
19
|
+
const HTML_SAMPLE = 5;
|
|
19
20
|
const inputSchema = {
|
|
20
21
|
input: z.string().min(1).optional().describe("Recording path (uses its .events.jsonl)."),
|
|
21
22
|
sessionId: z.string().min(1).optional().describe("Or a stopped session's id."),
|
|
@@ -149,10 +150,62 @@ export function register(server) {
|
|
|
149
150
|
written.push(paths.markdown);
|
|
150
151
|
}
|
|
151
152
|
if (wantHtml) {
|
|
152
|
-
const
|
|
153
|
-
|
|
153
|
+
const htmlDir = join(work, "html");
|
|
154
|
+
mkdirSync(htmlDir, { recursive: true });
|
|
155
|
+
const files = steps.flatMap((s) => (s.image ? [s.image] : []));
|
|
156
|
+
const src = (file) => `data:image/jpeg;base64,${readFileSync(join(htmlDir, htmlImageName(file))).toString("base64")}`;
|
|
157
|
+
const encode = async (file, rung) => {
|
|
158
|
+
const out = join(htmlDir, htmlImageName(file));
|
|
159
|
+
await runFfmpeg(buildHtmlImageArgs(join(imageDir, file), rung, out), 60_000, { signal: extra.signal });
|
|
160
|
+
return base64Bytes(statSync(out).size);
|
|
161
|
+
};
|
|
162
|
+
const sample = files.length > HTML_SAMPLE ? files.filter((_, k) => k % Math.ceil(files.length / HTML_SAMPLE) === 0) : [];
|
|
163
|
+
let start = 0;
|
|
164
|
+
for (; sample.length > 0 && start < HTML_IMAGE_LADDER.length - 1; start++) {
|
|
165
|
+
let bytes = 0;
|
|
166
|
+
for (const f of sample)
|
|
167
|
+
bytes += await encode(f, HTML_IMAGE_LADDER[start]);
|
|
168
|
+
if ((bytes / sample.length) * files.length <= HTML_MAX_BYTES * 0.9)
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
let page = "";
|
|
172
|
+
for (let r = start; r !== null;) {
|
|
173
|
+
const rung = HTML_IMAGE_LADDER[r];
|
|
174
|
+
let images = 0;
|
|
175
|
+
for (const file of files)
|
|
176
|
+
images += await encode(file, rung);
|
|
177
|
+
page = images <= HTML_MAX_BYTES ? buildGuideHtml(data, src) : "";
|
|
178
|
+
const bytes = page ? Buffer.byteLength(page) : images;
|
|
179
|
+
if (bytes <= HTML_MAX_BYTES)
|
|
180
|
+
break;
|
|
181
|
+
const next = nextHtmlRung(r, bytes);
|
|
182
|
+
if (next === null) {
|
|
183
|
+
page ||= buildGuideHtml(data, src);
|
|
184
|
+
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; ` +
|
|
185
|
+
"use format: md for a guide this long.");
|
|
186
|
+
}
|
|
187
|
+
r = next;
|
|
188
|
+
}
|
|
189
|
+
writeFileSync(paths.html, page);
|
|
154
190
|
written.push(paths.html);
|
|
155
191
|
}
|
|
192
|
+
if (args.overwrite) {
|
|
193
|
+
if (!wantHtml)
|
|
194
|
+
rmSync(paths.html, { force: true });
|
|
195
|
+
if (!wantMd) {
|
|
196
|
+
rmSync(paths.markdown, { force: true });
|
|
197
|
+
if (existsSync(paths.images)) {
|
|
198
|
+
for (const f of readdirSync(paths.images))
|
|
199
|
+
if (/^step-\d+\.png$/.test(f))
|
|
200
|
+
rmSync(join(paths.images, f), { force: true });
|
|
201
|
+
try {
|
|
202
|
+
rmdirSync(paths.images);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
156
209
|
if (data.stepsOmitted)
|
|
157
210
|
warnings.push(`Only the first ${MAX_GUIDE_STEPS} steps were written; ${data.stepsOmitted} more were left out.`);
|
|
158
211
|
if (stepsNote)
|
|
@@ -2,10 +2,11 @@ import { z } from "zod";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
4
4
|
import { STOPS_SESSION, looseOutput } from "../utils/toolSpec.js";
|
|
5
|
-
import { requireFfmpeg } from "../utils/ffmpeg.js";
|
|
5
|
+
import { probeMedia, requireFfmpeg } from "../utils/ffmpeg.js";
|
|
6
6
|
import { probeDuration, stopSession } from "../utils/lifecycle.js";
|
|
7
7
|
import { getStore } from "../context.js";
|
|
8
8
|
import { finishReplay } from "../utils/replay.js";
|
|
9
|
+
import { webcamPlacement } from "../utils/pause.js";
|
|
9
10
|
function replayReport(r) {
|
|
10
11
|
return {
|
|
11
12
|
saved: r.saved,
|
|
@@ -14,6 +15,37 @@ function replayReport(r) {
|
|
|
14
15
|
...(r.error ? { error: r.error, note: "The buffer was kept; call stop_recording with save: true again, or save_replay." } : {}),
|
|
15
16
|
};
|
|
16
17
|
}
|
|
18
|
+
async function webcamReport(cam, output) {
|
|
19
|
+
if (cam.error || !existsSync(cam.path))
|
|
20
|
+
return { error: cam.error ?? `No webcam file was written (${cam.path}).` };
|
|
21
|
+
const size = async (p) => {
|
|
22
|
+
try {
|
|
23
|
+
const info = await probeMedia(p);
|
|
24
|
+
return info.width && info.height ? { width: info.width, height: info.height } : null;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const [screen, camSize] = await Promise.all([size(output), size(cam.path)]);
|
|
31
|
+
const circle = cam.shape === "circle";
|
|
32
|
+
const place = screen && camSize ? webcamPlacement(screen, circle ? { width: 1, height: 1 } : camSize, cam.corner, cam.size) : null;
|
|
33
|
+
return {
|
|
34
|
+
path: cam.path,
|
|
35
|
+
...(place
|
|
36
|
+
? {
|
|
37
|
+
overlay: {
|
|
38
|
+
input: output,
|
|
39
|
+
overlay: cam.path,
|
|
40
|
+
x: place.x,
|
|
41
|
+
y: place.y,
|
|
42
|
+
...(circle ? { height: place.height, shape: "circle" } : { width: place.width }),
|
|
43
|
+
},
|
|
44
|
+
note: "Aligned with the recording: pass `overlay` to the overlay tool (any corner or size works).",
|
|
45
|
+
}
|
|
46
|
+
: {}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
17
49
|
const inputSchema = {
|
|
18
50
|
sessionId: z.string().min(1).describe("Session id returned by start_recording."),
|
|
19
51
|
save: z
|
|
@@ -40,7 +72,7 @@ export function register(server) {
|
|
|
40
72
|
if (!record) {
|
|
41
73
|
throw new ScreencastError(`No session with id "${args.sessionId}".`);
|
|
42
74
|
}
|
|
43
|
-
if (record.status !== "recording") {
|
|
75
|
+
if (record.status !== "recording" && record.status !== "paused") {
|
|
44
76
|
const replay = record.replay && existsSync(record.replay.dir)
|
|
45
77
|
? await finishReplay(record.replay, {
|
|
46
78
|
save: args.save ?? false,
|
|
@@ -64,7 +96,7 @@ export function register(server) {
|
|
|
64
96
|
});
|
|
65
97
|
}
|
|
66
98
|
const { ffprobe } = requireFfmpeg();
|
|
67
|
-
const { record: updated, graceful, durationSec, replay } = await stopSession(store, record, {
|
|
99
|
+
const { record: updated, graceful, durationSec, replay, segments } = await stopSession(store, record, {
|
|
68
100
|
reason: "stopped",
|
|
69
101
|
probe: (path) => probeDuration(ffprobe, path),
|
|
70
102
|
saveReplay: args.save,
|
|
@@ -76,6 +108,9 @@ export function register(server) {
|
|
|
76
108
|
durationSec: durationSec ?? null,
|
|
77
109
|
finalizedGracefully: graceful,
|
|
78
110
|
...(replay ? { replay: replayReport(replay) } : {}),
|
|
111
|
+
...(segments && segments.count > 1 ? { segmentsJoined: segments.count } : {}),
|
|
112
|
+
...(segments?.error ? { segmentsError: segments.error } : {}),
|
|
113
|
+
...(updated?.webcam ? { webcam: await webcamReport(updated.webcam, record.outputPath) } : {}),
|
|
79
114
|
...(updated?.events
|
|
80
115
|
? { eventsPath: updated.events.path, events: updated.events.summary ?? {}, ...(updated.events.error ? { eventsError: updated.events.error } : {}) }
|
|
81
116
|
: {}),
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { assertInputAllowed, assertLocalPath } from "./paths.js";
|
|
2
|
+
const INPUT_KEYS = new Set([
|
|
3
|
+
"input", "inputs", "inputA", "inputB", "clips", "a", "b", "image", "overlay",
|
|
4
|
+
"music", "video", "subtitles", "srt", "transcript", "events",
|
|
5
|
+
]);
|
|
6
|
+
const LOCAL_ONLY_KEYS = new Set(["output", "outputDir", "model", "fontFile"]);
|
|
7
|
+
const KEYWORDS = new Set(["whisper"]);
|
|
8
|
+
function strings(value) {
|
|
9
|
+
if (typeof value === "string")
|
|
10
|
+
return [value];
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return value.filter((v) => typeof v === "string");
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
export function assertArgPaths(args) {
|
|
16
|
+
const visit = (node) => {
|
|
17
|
+
if (Array.isArray(node)) {
|
|
18
|
+
node.forEach(visit);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!node || typeof node !== "object")
|
|
22
|
+
return;
|
|
23
|
+
for (const [key, value] of Object.entries(node)) {
|
|
24
|
+
if (INPUT_KEYS.has(key)) {
|
|
25
|
+
for (const s of strings(value)) {
|
|
26
|
+
if (s.trim().length > 0 && !KEYWORDS.has(s))
|
|
27
|
+
assertInputAllowed(s, `Input "${key}"`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (LOCAL_ONLY_KEYS.has(key)) {
|
|
31
|
+
for (const s of strings(value))
|
|
32
|
+
assertLocalPath(s, `"${key}"`);
|
|
33
|
+
}
|
|
34
|
+
if (value && typeof value === "object")
|
|
35
|
+
visit(value);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
visit(args);
|
|
39
|
+
}
|
|
@@ -14,6 +14,12 @@ export const NO_LOOPBACK_HINT = "System audio capture needs a virtual-audio loop
|
|
|
14
14
|
"virtual-audio-capturer, or VB-CABLE). Then pass its name as `device`, or run " +
|
|
15
15
|
"list_audio_devices to see what is available. Microphone capture is not supported.";
|
|
16
16
|
export function parseDshowAudioDevices(stderr) {
|
|
17
|
+
return parseDshowDevices(stderr, "audio");
|
|
18
|
+
}
|
|
19
|
+
export function parseDshowVideoDevices(stderr) {
|
|
20
|
+
return parseDshowDevices(stderr, "video");
|
|
21
|
+
}
|
|
22
|
+
function parseDshowDevices(stderr, kind) {
|
|
17
23
|
const names = [];
|
|
18
24
|
let section = null;
|
|
19
25
|
for (const line of stderr.split(/\r?\n/)) {
|
|
@@ -33,7 +39,8 @@ export function parseDshowAudioDevices(stderr) {
|
|
|
33
39
|
const inlineAudio = /\(audio\)/i.test(line);
|
|
34
40
|
const inlineVideo = /\(video\)/i.test(line);
|
|
35
41
|
const isAudio = inlineAudio || (!inlineVideo && section === "audio");
|
|
36
|
-
|
|
42
|
+
const isVideo = inlineVideo || (!inlineAudio && section === "video");
|
|
43
|
+
if ((kind === "audio" ? isAudio : isVideo) && quoted[1])
|
|
37
44
|
names.push(quoted[1]);
|
|
38
45
|
}
|
|
39
46
|
return [...new Set(names)];
|
|
@@ -50,9 +57,32 @@ const ENUM_FAILED_HINT = "Enumerating DirectShow audio devices timed out or fail
|
|
|
50
57
|
"misbehaving audio driver, or no audio device present. Record without system " +
|
|
51
58
|
"audio, or fix the device, then retry. " + NO_LOOPBACK_HINT;
|
|
52
59
|
let cachedDevices = null;
|
|
60
|
+
let cachedVideo = null;
|
|
53
61
|
export async function listDshowAudioDevices(forceRefresh = false) {
|
|
54
62
|
if (!forceRefresh && cachedDevices)
|
|
55
63
|
return cachedDevices;
|
|
64
|
+
await enumerateDshow();
|
|
65
|
+
return cachedDevices ?? [];
|
|
66
|
+
}
|
|
67
|
+
export async function listDshowVideoDevices(forceRefresh = false) {
|
|
68
|
+
if (!forceRefresh && cachedVideo)
|
|
69
|
+
return cachedVideo;
|
|
70
|
+
await enumerateDshow();
|
|
71
|
+
return cachedVideo ?? [];
|
|
72
|
+
}
|
|
73
|
+
export async function resolveVideoDevice(explicit) {
|
|
74
|
+
const devices = await listDshowVideoDevices();
|
|
75
|
+
if (explicit && explicit.trim().length > 0) {
|
|
76
|
+
if (devices.includes(explicit))
|
|
77
|
+
return explicit;
|
|
78
|
+
throw new ScreencastError(`Video device "${explicit}" not found. Available dshow video devices: ${devices.join(", ") || "none"}.`);
|
|
79
|
+
}
|
|
80
|
+
const first = devices[0];
|
|
81
|
+
if (!first)
|
|
82
|
+
throw new ScreencastError("No webcam (dshow video device) found.", "Connect a camera, then run list_video_devices.");
|
|
83
|
+
return first;
|
|
84
|
+
}
|
|
85
|
+
async function enumerateDshow() {
|
|
56
86
|
const { ffmpeg } = requireFfmpeg();
|
|
57
87
|
let res;
|
|
58
88
|
try {
|
|
@@ -61,12 +91,12 @@ export async function listDshowAudioDevices(forceRefresh = false) {
|
|
|
61
91
|
catch (err) {
|
|
62
92
|
throw new ScreencastError(`Could not enumerate audio devices (${err.message}).`, ENUM_FAILED_HINT);
|
|
63
93
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return devices;
|
|
94
|
+
cachedDevices = parseDshowAudioDevices(res.stderr);
|
|
95
|
+
cachedVideo = parseDshowVideoDevices(res.stderr);
|
|
67
96
|
}
|
|
68
97
|
export function clearAudioDeviceCache() {
|
|
69
98
|
cachedDevices = null;
|
|
99
|
+
cachedVideo = null;
|
|
70
100
|
}
|
|
71
101
|
export async function resolveLoopbackDevice(explicit) {
|
|
72
102
|
const devices = await listDshowAudioDevices();
|