@tmhs/screencast-mcp 0.39.0 → 0.44.2
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 +58 -14
- package/assets/icon.png +0 -0
- package/assets/ui/player.html +38 -302
- package/assets/ui/player.js +382 -0
- package/dist/context.js +0 -5
- package/dist/index.js +5 -21
- package/dist/prompts.js +0 -7
- package/dist/resources.js +2 -14
- package/dist/server.js +37 -11
- package/dist/tools/assembleHighlights.js +12 -7
- package/dist/tools/burnSubtitles.js +12 -6
- package/dist/tools/callout.js +32 -16
- package/dist/tools/clip.js +12 -9
- package/dist/tools/compress.js +10 -5
- package/dist/tools/concat.js +16 -15
- package/dist/tools/contactSheet.js +26 -22
- package/dist/tools/convert.js +12 -6
- package/dist/tools/crop.js +12 -7
- package/dist/tools/cutIdle.js +15 -9
- package/dist/tools/denoise.js +12 -6
- package/dist/tools/doctor.js +133 -0
- package/dist/tools/exportGif.js +14 -10
- package/dist/tools/exportPreset.js +11 -8
- package/dist/tools/extractAudio.js +10 -8
- package/dist/tools/findText.js +69 -65
- package/dist/tools/getMediaInfo.js +17 -3
- package/dist/tools/getSession.js +15 -3
- package/dist/tools/listAudioDevices.js +14 -7
- package/dist/tools/listSessions.js +13 -3
- package/dist/tools/listTargets.js +76 -0
- package/dist/tools/musicBed.js +14 -10
- package/dist/tools/normalizeAudio.js +12 -8
- package/dist/tools/overlay.js +16 -12
- package/dist/tools/pipeline.js +31 -22
- package/dist/tools/readEvents.js +21 -12
- package/dist/tools/redactRegion.js +19 -17
- package/dist/tools/reframe.js +9 -5
- package/dist/tools/reviewRecording.js +63 -22
- package/dist/tools/sampleFrames.js +33 -40
- package/dist/tools/scale.js +9 -3
- package/dist/tools/screenDiff.js +23 -17
- package/dist/tools/screenshot.js +21 -17
- package/dist/tools/speed.js +15 -4
- package/dist/tools/startRecording.js +48 -52
- package/dist/tools/stopRecording.js +10 -9
- package/dist/tools/titleCard.js +19 -11
- package/dist/tools/transcribe.js +13 -7
- package/dist/tools/trim.js +11 -10
- package/dist/tools/waitForChange.js +37 -22
- package/dist/tools/xfadeTransition.js +12 -8
- package/dist/tools/zoom.js +26 -29
- package/dist/utils/anim.js +1 -21
- package/dist/utils/animExport.js +5 -10
- package/dist/utils/audio.js +4 -33
- package/dist/utils/audioDevices.js +1 -48
- package/dist/utils/callout.js +1 -19
- package/dist/utils/calloutAssets.js +21 -11
- package/dist/utils/capabilities.js +95 -0
- package/dist/utils/captions.js +9 -26
- package/dist/utils/consent.js +29 -0
- package/dist/utils/diff.js +0 -46
- package/dist/utils/errors.js +5 -13
- package/dist/utils/events.js +21 -77
- package/dist/utils/expr.js +11 -0
- package/dist/utils/ffmpeg.js +119 -48
- package/dist/utils/fontCoverage.js +177 -0
- package/dist/utils/fonts.js +139 -23
- package/dist/utils/idle.js +12 -24
- package/dist/utils/images.js +0 -17
- package/dist/utils/jobs.js +42 -41
- package/dist/utils/lifecycle.js +0 -29
- package/dist/utils/logging.js +75 -0
- package/dist/utils/media.js +11 -122
- package/dist/utils/monitors.js +7 -43
- package/dist/utils/ocr.js +53 -71
- package/dist/utils/paths.js +68 -31
- package/dist/utils/pipeline.js +0 -23
- package/dist/utils/player.js +50 -27
- package/dist/utils/produce.js +6 -66
- package/dist/utils/resolveTarget.js +0 -19
- package/dist/utils/retention.js +1 -15
- package/dist/utils/roots.js +42 -0
- package/dist/utils/sessions.js +195 -160
- package/dist/utils/sheet.js +0 -19
- package/dist/utils/still.js +0 -15
- package/dist/utils/targetList.js +63 -0
- package/dist/utils/targets.js +5 -70
- package/dist/utils/toolSpec.js +25 -0
- package/dist/utils/toolsets.js +102 -0
- package/dist/utils/validate.js +0 -22
- package/dist/utils/wgc.js +0 -46
- package/dist/utils/windows.js +5 -50
- package/dist/utils/zoom.js +55 -85
- package/dist/wgcRecorder.js +1 -30
- package/package.json +7 -3
- package/dist/context.d.ts +0 -9
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/prompts.d.ts +0 -10
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js.map +0 -1
- package/dist/resources.d.ts +0 -3
- package/dist/resources.d.ts.map +0 -1
- package/dist/resources.js.map +0 -1
- package/dist/server.d.ts +0 -3
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/tools/assembleHighlights.d.ts +0 -3
- package/dist/tools/assembleHighlights.d.ts.map +0 -1
- package/dist/tools/assembleHighlights.js.map +0 -1
- package/dist/tools/burnSubtitles.d.ts +0 -3
- package/dist/tools/burnSubtitles.d.ts.map +0 -1
- package/dist/tools/burnSubtitles.js.map +0 -1
- package/dist/tools/callout.d.ts +0 -37
- package/dist/tools/callout.d.ts.map +0 -1
- package/dist/tools/callout.js.map +0 -1
- package/dist/tools/clip.d.ts +0 -3
- package/dist/tools/clip.d.ts.map +0 -1
- package/dist/tools/clip.js.map +0 -1
- package/dist/tools/compress.d.ts +0 -3
- package/dist/tools/compress.d.ts.map +0 -1
- package/dist/tools/compress.js.map +0 -1
- package/dist/tools/concat.d.ts +0 -3
- package/dist/tools/concat.d.ts.map +0 -1
- package/dist/tools/concat.js.map +0 -1
- package/dist/tools/contactSheet.d.ts +0 -3
- package/dist/tools/contactSheet.d.ts.map +0 -1
- package/dist/tools/contactSheet.js.map +0 -1
- package/dist/tools/convert.d.ts +0 -3
- package/dist/tools/convert.d.ts.map +0 -1
- package/dist/tools/convert.js.map +0 -1
- package/dist/tools/crop.d.ts +0 -3
- package/dist/tools/crop.d.ts.map +0 -1
- package/dist/tools/crop.js.map +0 -1
- package/dist/tools/cutIdle.d.ts +0 -3
- package/dist/tools/cutIdle.d.ts.map +0 -1
- package/dist/tools/cutIdle.js.map +0 -1
- package/dist/tools/denoise.d.ts +0 -3
- package/dist/tools/denoise.d.ts.map +0 -1
- package/dist/tools/denoise.js.map +0 -1
- package/dist/tools/exportGif.d.ts +0 -3
- package/dist/tools/exportGif.d.ts.map +0 -1
- package/dist/tools/exportGif.js.map +0 -1
- package/dist/tools/exportPreset.d.ts +0 -3
- package/dist/tools/exportPreset.d.ts.map +0 -1
- package/dist/tools/exportPreset.js.map +0 -1
- package/dist/tools/extractAudio.d.ts +0 -3
- package/dist/tools/extractAudio.d.ts.map +0 -1
- package/dist/tools/extractAudio.js.map +0 -1
- package/dist/tools/findText.d.ts +0 -6
- package/dist/tools/findText.d.ts.map +0 -1
- package/dist/tools/findText.js.map +0 -1
- package/dist/tools/getMediaInfo.d.ts +0 -3
- package/dist/tools/getMediaInfo.d.ts.map +0 -1
- package/dist/tools/getMediaInfo.js.map +0 -1
- package/dist/tools/getSession.d.ts +0 -3
- package/dist/tools/getSession.d.ts.map +0 -1
- package/dist/tools/getSession.js.map +0 -1
- package/dist/tools/listAudioDevices.d.ts +0 -3
- package/dist/tools/listAudioDevices.d.ts.map +0 -1
- package/dist/tools/listAudioDevices.js.map +0 -1
- package/dist/tools/listSessions.d.ts +0 -3
- package/dist/tools/listSessions.d.ts.map +0 -1
- package/dist/tools/listSessions.js.map +0 -1
- package/dist/tools/musicBed.d.ts +0 -3
- package/dist/tools/musicBed.d.ts.map +0 -1
- package/dist/tools/musicBed.js.map +0 -1
- package/dist/tools/normalizeAudio.d.ts +0 -3
- package/dist/tools/normalizeAudio.d.ts.map +0 -1
- package/dist/tools/normalizeAudio.js.map +0 -1
- package/dist/tools/overlay.d.ts +0 -3
- package/dist/tools/overlay.d.ts.map +0 -1
- package/dist/tools/overlay.js.map +0 -1
- package/dist/tools/pipeline.d.ts +0 -3
- package/dist/tools/pipeline.d.ts.map +0 -1
- package/dist/tools/pipeline.js.map +0 -1
- package/dist/tools/readEvents.d.ts +0 -6
- package/dist/tools/readEvents.d.ts.map +0 -1
- package/dist/tools/readEvents.js.map +0 -1
- package/dist/tools/redactRegion.d.ts +0 -13
- package/dist/tools/redactRegion.d.ts.map +0 -1
- package/dist/tools/redactRegion.js.map +0 -1
- package/dist/tools/reframe.d.ts +0 -3
- package/dist/tools/reframe.d.ts.map +0 -1
- package/dist/tools/reframe.js.map +0 -1
- package/dist/tools/reviewRecording.d.ts +0 -5
- package/dist/tools/reviewRecording.d.ts.map +0 -1
- package/dist/tools/reviewRecording.js.map +0 -1
- package/dist/tools/sampleFrames.d.ts +0 -3
- package/dist/tools/sampleFrames.d.ts.map +0 -1
- package/dist/tools/sampleFrames.js.map +0 -1
- package/dist/tools/scale.d.ts +0 -3
- package/dist/tools/scale.d.ts.map +0 -1
- package/dist/tools/scale.js.map +0 -1
- package/dist/tools/screenDiff.d.ts +0 -3
- package/dist/tools/screenDiff.d.ts.map +0 -1
- package/dist/tools/screenDiff.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -3
- package/dist/tools/screenshot.d.ts.map +0 -1
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/speed.d.ts +0 -3
- package/dist/tools/speed.d.ts.map +0 -1
- package/dist/tools/speed.js.map +0 -1
- package/dist/tools/startRecording.d.ts +0 -3
- package/dist/tools/startRecording.d.ts.map +0 -1
- package/dist/tools/startRecording.js.map +0 -1
- package/dist/tools/stopRecording.d.ts +0 -3
- package/dist/tools/stopRecording.d.ts.map +0 -1
- package/dist/tools/stopRecording.js.map +0 -1
- package/dist/tools/titleCard.d.ts +0 -3
- package/dist/tools/titleCard.d.ts.map +0 -1
- package/dist/tools/titleCard.js.map +0 -1
- package/dist/tools/transcribe.d.ts +0 -3
- package/dist/tools/transcribe.d.ts.map +0 -1
- package/dist/tools/transcribe.js.map +0 -1
- package/dist/tools/trim.d.ts +0 -3
- package/dist/tools/trim.d.ts.map +0 -1
- package/dist/tools/trim.js.map +0 -1
- package/dist/tools/waitForChange.d.ts +0 -3
- package/dist/tools/waitForChange.d.ts.map +0 -1
- package/dist/tools/waitForChange.js.map +0 -1
- package/dist/tools/xfadeTransition.d.ts +0 -3
- package/dist/tools/xfadeTransition.d.ts.map +0 -1
- package/dist/tools/xfadeTransition.js.map +0 -1
- package/dist/tools/zoom.d.ts +0 -15
- package/dist/tools/zoom.d.ts.map +0 -1
- package/dist/tools/zoom.js.map +0 -1
- package/dist/utils/anim.d.ts +0 -33
- package/dist/utils/anim.d.ts.map +0 -1
- package/dist/utils/anim.js.map +0 -1
- package/dist/utils/animExport.d.ts +0 -27
- package/dist/utils/animExport.d.ts.map +0 -1
- package/dist/utils/animExport.js.map +0 -1
- package/dist/utils/audio.d.ts +0 -49
- package/dist/utils/audio.d.ts.map +0 -1
- package/dist/utils/audio.js.map +0 -1
- package/dist/utils/audioDevices.d.ts +0 -33
- package/dist/utils/audioDevices.d.ts.map +0 -1
- package/dist/utils/audioDevices.js.map +0 -1
- package/dist/utils/callout.d.ts +0 -72
- package/dist/utils/callout.d.ts.map +0 -1
- package/dist/utils/callout.js.map +0 -1
- package/dist/utils/calloutAssets.d.ts +0 -3
- package/dist/utils/calloutAssets.d.ts.map +0 -1
- package/dist/utils/calloutAssets.js.map +0 -1
- package/dist/utils/captions.d.ts +0 -26
- package/dist/utils/captions.d.ts.map +0 -1
- package/dist/utils/captions.js.map +0 -1
- package/dist/utils/diff.d.ts +0 -112
- package/dist/utils/diff.d.ts.map +0 -1
- package/dist/utils/diff.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -33
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/events.d.ts +0 -143
- package/dist/utils/events.d.ts.map +0 -1
- package/dist/utils/events.js.map +0 -1
- package/dist/utils/ffmpeg.d.ts +0 -50
- package/dist/utils/ffmpeg.d.ts.map +0 -1
- package/dist/utils/ffmpeg.js.map +0 -1
- package/dist/utils/fonts.d.ts +0 -17
- package/dist/utils/fonts.d.ts.map +0 -1
- package/dist/utils/fonts.js.map +0 -1
- package/dist/utils/idle.d.ts +0 -23
- package/dist/utils/idle.d.ts.map +0 -1
- package/dist/utils/idle.js.map +0 -1
- package/dist/utils/images.d.ts +0 -21
- package/dist/utils/images.d.ts.map +0 -1
- package/dist/utils/images.js.map +0 -1
- package/dist/utils/jobs.d.ts +0 -44
- package/dist/utils/jobs.d.ts.map +0 -1
- package/dist/utils/jobs.js.map +0 -1
- package/dist/utils/lifecycle.d.ts +0 -29
- package/dist/utils/lifecycle.d.ts.map +0 -1
- package/dist/utils/lifecycle.js.map +0 -1
- package/dist/utils/media.d.ts +0 -272
- package/dist/utils/media.d.ts.map +0 -1
- package/dist/utils/media.js.map +0 -1
- package/dist/utils/monitors.d.ts +0 -47
- package/dist/utils/monitors.d.ts.map +0 -1
- package/dist/utils/monitors.js.map +0 -1
- package/dist/utils/ocr.d.ts +0 -50
- package/dist/utils/ocr.d.ts.map +0 -1
- package/dist/utils/ocr.js.map +0 -1
- package/dist/utils/paths.d.ts +0 -28
- package/dist/utils/paths.d.ts.map +0 -1
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/pipeline.d.ts +0 -69
- package/dist/utils/pipeline.d.ts.map +0 -1
- package/dist/utils/pipeline.js.map +0 -1
- package/dist/utils/player.d.ts +0 -30
- package/dist/utils/player.d.ts.map +0 -1
- package/dist/utils/player.js.map +0 -1
- package/dist/utils/produce.d.ts +0 -126
- package/dist/utils/produce.d.ts.map +0 -1
- package/dist/utils/produce.js.map +0 -1
- package/dist/utils/resolveTarget.d.ts +0 -32
- package/dist/utils/resolveTarget.d.ts.map +0 -1
- package/dist/utils/resolveTarget.js.map +0 -1
- package/dist/utils/retention.d.ts +0 -10
- package/dist/utils/retention.d.ts.map +0 -1
- package/dist/utils/retention.js.map +0 -1
- package/dist/utils/sessions.d.ts +0 -154
- package/dist/utils/sessions.d.ts.map +0 -1
- package/dist/utils/sessions.js.map +0 -1
- package/dist/utils/sheet.d.ts +0 -26
- package/dist/utils/sheet.d.ts.map +0 -1
- package/dist/utils/sheet.js.map +0 -1
- package/dist/utils/still.d.ts +0 -7
- package/dist/utils/still.d.ts.map +0 -1
- package/dist/utils/still.js.map +0 -1
- package/dist/utils/targets.d.ts +0 -113
- package/dist/utils/targets.d.ts.map +0 -1
- package/dist/utils/targets.js.map +0 -1
- package/dist/utils/validate.d.ts +0 -15
- package/dist/utils/validate.d.ts.map +0 -1
- package/dist/utils/validate.js.map +0 -1
- package/dist/utils/wgc.d.ts +0 -46
- package/dist/utils/wgc.d.ts.map +0 -1
- package/dist/utils/wgc.js.map +0 -1
- package/dist/utils/windows.d.ts +0 -94
- package/dist/utils/windows.d.ts.map +0 -1
- package/dist/utils/windows.js.map +0 -1
- package/dist/utils/zoom.d.ts +0 -95
- package/dist/utils/zoom.d.ts.map +0 -1
- package/dist/utils/zoom.js.map +0 -1
- package/dist/wgcRecorder.d.ts +0 -2
- package/dist/wgcRecorder.d.ts.map +0 -1
- package/dist/wgcRecorder.js.map +0 -1
package/dist/utils/idle.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dead-air removal (#122). Recordings of an agent at work are full of long
|
|
3
|
-
* still stretches while it thinks. A scan finds frozen video (freezedetect)
|
|
4
|
-
* and silent audio (silencedetect); idle time is where the picture is frozen
|
|
5
|
-
* and, if there is audio, it is also silent. Each idle stretch is cut except
|
|
6
|
-
* for a short pad at both edges, in one select/aselect pass. Pure helpers.
|
|
7
|
-
*/
|
|
8
1
|
import { ScreencastError } from "./errors.js";
|
|
9
2
|
import { resolveQuality } from "./targets.js";
|
|
3
|
+
import { sumExpr } from "./expr.js";
|
|
10
4
|
export const DEFAULT_MIN_IDLE_SEC = 2;
|
|
11
5
|
export const DEFAULT_KEEP_SEC = 0.4;
|
|
12
|
-
/** Cap on cut intervals, keeping the select expression a sane length. */
|
|
13
6
|
export const MAX_CUTS = 200;
|
|
14
|
-
/** Scan for freezes (and silences, when the file has audio); the reports go
|
|
15
|
-
* to stderr at info level. */
|
|
16
7
|
export function buildIdleScanArgs(input, minIdleSec, withAudio) {
|
|
17
8
|
if (!(minIdleSec > 0))
|
|
18
9
|
throw new ScreencastError("minIdleSec must be positive.");
|
|
@@ -23,8 +14,6 @@ export function buildIdleScanArgs(input, minIdleSec, withAudio) {
|
|
|
23
14
|
"-f", "null", "-",
|
|
24
15
|
];
|
|
25
16
|
}
|
|
26
|
-
/** Pair start/end markers from the scan. An open interval (the stretch runs to
|
|
27
|
-
* the end of the file) is closed at `duration`. Pure. */
|
|
28
17
|
function pairs(stderr, startRe, endRe, duration) {
|
|
29
18
|
const out = [];
|
|
30
19
|
let open = null;
|
|
@@ -50,25 +39,26 @@ export function parseFreezes(stderr, duration) {
|
|
|
50
39
|
export function parseSilences(stderr, duration) {
|
|
51
40
|
return pairs(stderr, /silence_start:\s*([\d.]+)/, /silence_end:\s*([\d.]+)/, duration);
|
|
52
41
|
}
|
|
53
|
-
/** Overlap of two sorted interval lists. Pure. */
|
|
54
42
|
export function intersect(a, b) {
|
|
55
43
|
const out = [];
|
|
56
44
|
let i = 0;
|
|
57
45
|
let j = 0;
|
|
58
|
-
while (
|
|
59
|
-
const
|
|
60
|
-
const
|
|
46
|
+
while (true) {
|
|
47
|
+
const x = a[i];
|
|
48
|
+
const y = b[j];
|
|
49
|
+
if (!x || !y)
|
|
50
|
+
break;
|
|
51
|
+
const start = Math.max(x.start, y.start);
|
|
52
|
+
const end = Math.min(x.end, y.end);
|
|
61
53
|
if (end > start)
|
|
62
54
|
out.push({ start, end });
|
|
63
|
-
if (
|
|
55
|
+
if (x.end < y.end)
|
|
64
56
|
i++;
|
|
65
57
|
else
|
|
66
58
|
j++;
|
|
67
59
|
}
|
|
68
60
|
return out;
|
|
69
61
|
}
|
|
70
|
-
/** Idle stretches (at least minIdleSec long) shrunk by `keep` at each edge,
|
|
71
|
-
* i.e. the spans that will actually be removed. Pure. */
|
|
72
62
|
export function cutsFor(idle, minIdleSec, keep) {
|
|
73
63
|
return idle
|
|
74
64
|
.filter((r) => r.end - r.start >= minIdleSec)
|
|
@@ -76,21 +66,19 @@ export function cutsFor(idle, minIdleSec, keep) {
|
|
|
76
66
|
.filter((r) => r.end - r.start > 0.05)
|
|
77
67
|
.map((r) => ({ start: Number(r.start.toFixed(3)), end: Number(r.end.toFixed(3)) }));
|
|
78
68
|
}
|
|
79
|
-
/** Remove the cut spans from video (and audio) in one pass. Timestamps are
|
|
80
|
-
* regenerated so the result plays continuously. Pure. */
|
|
81
69
|
export function buildCutIdleArgs(input, output, cuts, withAudio, quality = "standard") {
|
|
82
70
|
if (cuts.length === 0)
|
|
83
71
|
throw new ScreencastError("Nothing to cut.");
|
|
84
72
|
if (cuts.length > MAX_CUTS)
|
|
85
73
|
throw new ScreencastError(`Too many idle stretches (${cuts.length}); raise minIdleSec.`);
|
|
86
|
-
const drop = cuts.map((c) => `between(t,${c.start},${c.end})`)
|
|
74
|
+
const drop = sumExpr(cuts.map((c) => `between(t,${c.start},${c.end})`));
|
|
75
|
+
const removed = sumExpr(cuts.map((c) => `clip(T-${c.start},0,${Number((c.end - c.start).toFixed(3))})`));
|
|
87
76
|
return [
|
|
88
77
|
"-y", "-i", input,
|
|
89
|
-
"-vf", `select='not(${drop})',setpts=
|
|
78
|
+
"-vf", `select='not(${drop})',setpts='(T-(${removed}))/TB'`,
|
|
90
79
|
...(withAudio ? ["-af", `aselect='not(${drop})',asetpts=N/SR/TB`] : ["-an"]),
|
|
91
80
|
...resolveQuality(quality),
|
|
92
81
|
...(withAudio ? ["-c:a", "aac", "-b:a", "160k"] : []),
|
|
93
82
|
output,
|
|
94
83
|
];
|
|
95
84
|
}
|
|
96
|
-
//# sourceMappingURL=idle.js.map
|
package/dist/utils/images.js
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Inline image results (#79).
|
|
3
|
-
*
|
|
4
|
-
* Tools that produce frames can return them as MCP `image` content blocks so a
|
|
5
|
-
* client shows them to the model directly, with no filesystem tool needed.
|
|
6
|
-
* Payloads stay bounded: every frame is downscaled to a max width and
|
|
7
|
-
* re-encoded as JPEG, and only the first N frames are embedded.
|
|
8
|
-
*/
|
|
9
1
|
import { readFileSync, rmSync } from "node:fs";
|
|
10
2
|
import { ScreencastError } from "./errors.js";
|
|
11
3
|
import { runFfmpeg } from "./ffmpeg.js";
|
|
12
4
|
import { tempPath, stillOutput } from "./paths.js";
|
|
13
|
-
/** Default downscale width for inline previews. */
|
|
14
5
|
export const DEFAULT_MAX_IMAGE_WIDTH = 1280;
|
|
15
|
-
/** Default number of frames embedded in one tool result. */
|
|
16
6
|
export const DEFAULT_MAX_INLINE_IMAGES = 8;
|
|
17
|
-
/** Hard ceiling on embedded frames, whatever the caller asks for. */
|
|
18
7
|
export const MAX_INLINE_IMAGES = 20;
|
|
19
|
-
/** Build args that turn one image or video frame into a downscaled JPEG
|
|
20
|
-
* preview. The width cap only ever downscales (min of the source width and
|
|
21
|
-
* maxWidth); -2 keeps the aspect ratio. */
|
|
22
8
|
export function buildPreviewArgs(input, output, maxWidth) {
|
|
23
9
|
if (!Number.isInteger(maxWidth) || maxWidth < 16) {
|
|
24
10
|
throw new ScreencastError("maxImageWidth must be an integer of at least 16.");
|
|
@@ -31,12 +17,10 @@ export function buildPreviewArgs(input, output, maxWidth) {
|
|
|
31
17
|
...stillOutput(output),
|
|
32
18
|
];
|
|
33
19
|
}
|
|
34
|
-
/** Clamp a caller-supplied inline-image count to [0, MAX_INLINE_IMAGES]. */
|
|
35
20
|
export function clampInlineCount(requested) {
|
|
36
21
|
const n = requested ?? DEFAULT_MAX_INLINE_IMAGES;
|
|
37
22
|
return Math.max(0, Math.min(MAX_INLINE_IMAGES, Math.floor(n)));
|
|
38
23
|
}
|
|
39
|
-
/** Encode up to `maxCount` image files as downscaled JPEG image blocks. */
|
|
40
24
|
export async function encodeInlineImages(paths, maxWidth = DEFAULT_MAX_IMAGE_WIDTH, maxCount = DEFAULT_MAX_INLINE_IMAGES) {
|
|
41
25
|
const chosen = paths.slice(0, maxCount);
|
|
42
26
|
const images = [];
|
|
@@ -52,4 +36,3 @@ export async function encodeInlineImages(paths, maxWidth = DEFAULT_MAX_IMAGE_WID
|
|
|
52
36
|
}
|
|
53
37
|
return { images, omitted: paths.length - chosen.length };
|
|
54
38
|
}
|
|
55
|
-
//# sourceMappingURL=images.js.map
|
package/dist/utils/jobs.js
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Long-running edit jobs (#81).
|
|
3
|
-
*
|
|
4
|
-
* Edit tools used to run ffmpeg with a fixed 5-20 minute timeout, wrote
|
|
5
|
-
* straight to the output path, and reported nothing until they finished. A
|
|
6
|
-
* long recording could time out partway, leave a truncated file at `output`
|
|
7
|
-
* (which then blocked a retry with "Output already exists"), and the agent had
|
|
8
|
-
* no idea how far it got. runEditJob fixes all three:
|
|
9
|
-
*
|
|
10
|
-
* - the timeout scales with the media's duration (env override available);
|
|
11
|
-
* - ffmpeg writes a `.partial` sibling that is renamed onto `output` only on
|
|
12
|
-
* success and deleted on any failure, timeout, or cancellation;
|
|
13
|
-
* - `-progress pipe:1` is parsed and forwarded as MCP progress notifications
|
|
14
|
-
* when the request carried a progressToken.
|
|
15
|
-
*/
|
|
16
1
|
import { basename, dirname, extname, join } from "node:path";
|
|
17
2
|
import { renameSync, rmSync } from "node:fs";
|
|
18
3
|
import { ScreencastError } from "./errors.js";
|
|
19
4
|
import { probeMedia, runFfmpeg } from "./ffmpeg.js";
|
|
20
|
-
/** Env var that overrides every edit job's timeout, in milliseconds. */
|
|
21
5
|
export const JOB_TIMEOUT_ENV = "SCREENCAST_JOB_TIMEOUT_MS";
|
|
22
|
-
/** Floor for a duration-scaled timeout. */
|
|
23
6
|
export const BASE_TIMEOUT_MS = 10 * 60_000;
|
|
24
|
-
/** Timeout when the media's duration could not be probed. */
|
|
25
7
|
export const UNKNOWN_DURATION_TIMEOUT_MS = 30 * 60_000;
|
|
26
|
-
/** Allow this many seconds of wall-clock time per second of media. A slow
|
|
27
|
-
* preset on a laptop runs around real time; 4x leaves ample headroom. */
|
|
28
8
|
export const SECONDS_PER_MEDIA_SECOND = 4;
|
|
29
|
-
/** Timeout for a job over `durationSec` of media: max(base, duration * 4x),
|
|
30
|
-
* or the env override when it is a positive integer. */
|
|
31
9
|
export function jobTimeoutMs(durationSec, env = process.env) {
|
|
32
10
|
const override = Number(env[JOB_TIMEOUT_ENV]);
|
|
33
11
|
if (Number.isInteger(override) && override > 0)
|
|
@@ -36,14 +14,10 @@ export function jobTimeoutMs(durationSec, env = process.env) {
|
|
|
36
14
|
return UNKNOWN_DURATION_TIMEOUT_MS;
|
|
37
15
|
return Math.max(BASE_TIMEOUT_MS, Math.ceil(durationSec * SECONDS_PER_MEDIA_SECOND * 1000));
|
|
38
16
|
}
|
|
39
|
-
/** `dir/name.partial.ext`: keeps the extension so ffmpeg picks the same muxer. */
|
|
40
17
|
export function partialPath(output) {
|
|
41
18
|
const ext = extname(output);
|
|
42
19
|
return join(dirname(output), `${basename(output, ext)}.partial${ext}`);
|
|
43
20
|
}
|
|
44
|
-
/** Point a builder's args at `partial` instead of `output`. Builders put the
|
|
45
|
-
* output path last; replacing the last occurrence leaves an identical input
|
|
46
|
-
* path (rare, but legal with overwrite) untouched. */
|
|
47
21
|
export function retargetOutput(args, output, partial) {
|
|
48
22
|
const i = args.lastIndexOf(output);
|
|
49
23
|
if (i === -1) {
|
|
@@ -53,8 +27,6 @@ export function retargetOutput(args, output, partial) {
|
|
|
53
27
|
next[i] = partial;
|
|
54
28
|
return next;
|
|
55
29
|
}
|
|
56
|
-
/** Feed `-progress pipe:1` output in chunks; returns the latest media time in
|
|
57
|
-
* seconds seen so far. Lines can split across chunks, so it buffers. */
|
|
58
30
|
export function createProgressParser() {
|
|
59
31
|
let buffer = "";
|
|
60
32
|
let latest = null;
|
|
@@ -63,8 +35,6 @@ export function createProgressParser() {
|
|
|
63
35
|
const lines = buffer.split(/\r?\n/);
|
|
64
36
|
buffer = lines.pop() ?? "";
|
|
65
37
|
for (const line of lines) {
|
|
66
|
-
// out_time_us is microseconds; ffmpeg's out_time_ms is also microseconds
|
|
67
|
-
// (a long-standing naming bug), so either works as a fallback.
|
|
68
38
|
const m = line.match(/^out_time_(?:us|ms)=(\d+)$/);
|
|
69
39
|
if (m)
|
|
70
40
|
latest = Number(m[1]) / 1_000_000;
|
|
@@ -72,9 +42,6 @@ export function createProgressParser() {
|
|
|
72
42
|
return latest;
|
|
73
43
|
};
|
|
74
44
|
}
|
|
75
|
-
/** A progress callback that forwards to the client as MCP progress
|
|
76
|
-
* notifications, or undefined when the request asked for none. Updates are
|
|
77
|
-
* throttled to whole-percent steps. */
|
|
78
45
|
export function progressReporter(extra) {
|
|
79
46
|
const token = extra?._meta?.progressToken;
|
|
80
47
|
if (token === undefined || !extra)
|
|
@@ -91,21 +58,29 @@ export function progressReporter(extra) {
|
|
|
91
58
|
params: { progressToken: token, progress: percent, total: 100 },
|
|
92
59
|
})
|
|
93
60
|
.catch(() => {
|
|
94
|
-
/* a client that went away must not fail the job */
|
|
95
61
|
});
|
|
96
62
|
};
|
|
97
63
|
}
|
|
98
|
-
|
|
99
|
-
|
|
64
|
+
const activeJobs = new Set();
|
|
65
|
+
let jobsClosed = false;
|
|
100
66
|
export async function runEditJob(args, job) {
|
|
67
|
+
if (jobsClosed)
|
|
68
|
+
throw new ScreencastError("The server is shutting down; the edit was not started.");
|
|
101
69
|
const partial = partialPath(job.output);
|
|
102
70
|
const report = progressReporter(job.extra);
|
|
103
71
|
const parse = createProgressParser();
|
|
104
72
|
const duration = job.durationSec != null && job.durationSec > 0 ? job.durationSec : null;
|
|
73
|
+
const input = job.inputDurationSec != null && job.inputDurationSec > 0 ? job.inputDurationSec : null;
|
|
74
|
+
const decoded = input !== null && duration !== null ? Math.max(input, duration) : (input ?? duration);
|
|
105
75
|
const ffArgs = ["-progress", "pipe:1", "-nostats", ...retargetOutput(args, job.output, partial)];
|
|
76
|
+
const controller = new AbortController();
|
|
77
|
+
const signal = job.extra?.signal ? AbortSignal.any([job.extra.signal, controller.signal]) : controller.signal;
|
|
78
|
+
let finish;
|
|
79
|
+
const active = { partial, controller, done: new Promise((r) => (finish = r)) };
|
|
80
|
+
activeJobs.add(active);
|
|
106
81
|
try {
|
|
107
|
-
await runFfmpeg(ffArgs, jobTimeoutMs(
|
|
108
|
-
signal
|
|
82
|
+
await runFfmpeg(ffArgs, jobTimeoutMs(decoded), {
|
|
83
|
+
signal,
|
|
109
84
|
onStdout: report && duration
|
|
110
85
|
? (chunk) => {
|
|
111
86
|
const t = parse(chunk);
|
|
@@ -121,9 +96,36 @@ export async function runEditJob(args, job) {
|
|
|
121
96
|
rmSync(partial, { force: true });
|
|
122
97
|
throw error;
|
|
123
98
|
}
|
|
99
|
+
finally {
|
|
100
|
+
activeJobs.delete(active);
|
|
101
|
+
finish();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function activeEditJobs() {
|
|
105
|
+
return activeJobs.size;
|
|
106
|
+
}
|
|
107
|
+
export async function abortEditJobs(graceMs = 3_000) {
|
|
108
|
+
jobsClosed = true;
|
|
109
|
+
const jobs = [...activeJobs];
|
|
110
|
+
if (jobs.length === 0)
|
|
111
|
+
return 0;
|
|
112
|
+
for (const job of jobs)
|
|
113
|
+
job.controller.abort();
|
|
114
|
+
let timer;
|
|
115
|
+
await Promise.race([
|
|
116
|
+
Promise.all(jobs.map((j) => j.done)),
|
|
117
|
+
new Promise((r) => (timer = setTimeout(r, graceMs))),
|
|
118
|
+
]);
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
for (const job of jobs) {
|
|
121
|
+
try {
|
|
122
|
+
rmSync(job.partial, { force: true });
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return jobs.length;
|
|
124
128
|
}
|
|
125
|
-
/** Probe a file's duration, or null when it cannot be read. Used to size
|
|
126
|
-
* timeouts and progress; never fails the job on its own. */
|
|
127
129
|
export async function probeDuration(input) {
|
|
128
130
|
try {
|
|
129
131
|
return (await probeMedia(input)).durationSec;
|
|
@@ -132,4 +134,3 @@ export async function probeDuration(input) {
|
|
|
132
134
|
return null;
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
|
-
//# sourceMappingURL=jobs.js.map
|
package/dist/utils/lifecycle.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Recording stop sequence, shared by stop_recording and server shutdown.
|
|
3
|
-
*
|
|
4
|
-
* Graceful first: ffmpeg quits cleanly (and finalizes the mp4) on 'q' over
|
|
5
|
-
* stdin. If it does not exit in time, or the live handle was lost (a
|
|
6
|
-
* cross-restart stop), the process is terminated by pid; the fragmented-mp4
|
|
7
|
-
* muxing keeps a killed recording playable either way.
|
|
8
|
-
*/
|
|
9
1
|
import { existsSync, rmSync, writeFileSync } from "node:fs";
|
|
10
2
|
import { runCapture } from "./ffmpeg.js";
|
|
11
3
|
import { whenFinalized } from "./events.js";
|
|
@@ -13,14 +5,12 @@ import { buildProbeArgs, parseMediaInfo } from "./media.js";
|
|
|
13
5
|
import { ScreencastError } from "./errors.js";
|
|
14
6
|
import { wgcStopFile } from "./wgc.js";
|
|
15
7
|
import { expectedImage, isAlive, isRecorderProcess, killPid, } from "./sessions.js";
|
|
16
|
-
/** Poll until a pid is gone (process fully exited, file handles released). */
|
|
17
8
|
async function waitForPidExit(pid, ms) {
|
|
18
9
|
const deadline = Date.now() + ms;
|
|
19
10
|
while (Date.now() < deadline && isAlive(pid)) {
|
|
20
11
|
await new Promise((r) => setTimeout(r, 100));
|
|
21
12
|
}
|
|
22
13
|
}
|
|
23
|
-
/** Wait up to ms for a child to exit; resolve true if it did. */
|
|
24
14
|
export function waitForExit(child, ms) {
|
|
25
15
|
return new Promise((resolve) => {
|
|
26
16
|
if (child.exitCode !== null || child.signalCode !== null)
|
|
@@ -32,7 +22,6 @@ export function waitForExit(child, ms) {
|
|
|
32
22
|
});
|
|
33
23
|
});
|
|
34
24
|
}
|
|
35
|
-
/** Probe a finished file's duration, or null if it is missing/unreadable. */
|
|
36
25
|
export async function probeDuration(ffprobe, path) {
|
|
37
26
|
if (!existsSync(path))
|
|
38
27
|
return null;
|
|
@@ -46,11 +35,6 @@ export async function probeDuration(ffprobe, path) {
|
|
|
46
35
|
return null;
|
|
47
36
|
}
|
|
48
37
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Stop every recording this instance owns (server shutdown, #76). Stops run in
|
|
51
|
-
* parallel and the whole pass is capped at `capMs` so a wedged ffmpeg cannot
|
|
52
|
-
* hold the process open; never throws. Returns the ids it attempted.
|
|
53
|
-
*/
|
|
54
38
|
export async function stopAll(store, probe, capMs = 10_000) {
|
|
55
39
|
const ids = store.activeIds();
|
|
56
40
|
const stops = ids.map(async (id) => {
|
|
@@ -72,12 +56,7 @@ export async function stopAll(store, probe, capMs = 10_000) {
|
|
|
72
56
|
clearTimeout(timer);
|
|
73
57
|
return ids;
|
|
74
58
|
}
|
|
75
|
-
/** Stops in flight, per store and session id. A second stop of the same
|
|
76
|
-
* session (an agent retry, or shutdown racing stop_recording) joins the first
|
|
77
|
-
* instead of force-killing a recording that is still finalizing (#181). */
|
|
78
59
|
const inFlight = new WeakMap();
|
|
79
|
-
/** Stop an active recording and record its final state. The caller has already
|
|
80
|
-
* checked the record exists and is "recording". */
|
|
81
60
|
export function stopSession(store, record, opts) {
|
|
82
61
|
let stops = inFlight.get(store);
|
|
83
62
|
if (!stops)
|
|
@@ -105,12 +84,8 @@ async function runStop(store, record, opts) {
|
|
|
105
84
|
}
|
|
106
85
|
}
|
|
107
86
|
else if (record.pid !== null && isAlive(record.pid)) {
|
|
108
|
-
// Cross-restart stop: no stdin handle. Act on the pid only while it is
|
|
109
|
-
// still the recorder this record started (never a recycled, unrelated
|
|
110
|
-
// process); the wgc recorder runs under node, not ffmpeg (#182).
|
|
111
87
|
if (isRecorderProcess(record.pid, expectedImage(record))) {
|
|
112
88
|
if (stopFile) {
|
|
113
|
-
// The wgc recorder finalizes when its stop file appears.
|
|
114
89
|
writeFileSync(stopFile, "");
|
|
115
90
|
await waitForPidExit(record.pid, opts.gracefulMs ?? 8000);
|
|
116
91
|
graceful = !isAlive(record.pid);
|
|
@@ -125,7 +100,6 @@ async function runStop(store, record, opts) {
|
|
|
125
100
|
}
|
|
126
101
|
}
|
|
127
102
|
store.detachChild(record.id);
|
|
128
|
-
// The input event log converts once ffmpeg has exited (#118).
|
|
129
103
|
await whenFinalized(record.id);
|
|
130
104
|
const durationSec = await opts.probe(record.outputPath);
|
|
131
105
|
const updated = store.update(record.id, {
|
|
@@ -133,8 +107,6 @@ async function runStop(store, record, opts) {
|
|
|
133
107
|
stoppedAt: new Date().toISOString(),
|
|
134
108
|
durationSec: durationSec ?? undefined,
|
|
135
109
|
endReason: opts.reason,
|
|
136
|
-
// A forced kill can transiently mark the record "failed" via the crash
|
|
137
|
-
// detector in start_recording; a deliberate stop is not a failure.
|
|
138
110
|
error: undefined,
|
|
139
111
|
});
|
|
140
112
|
return { record: updated, graceful, durationSec };
|
|
@@ -145,4 +117,3 @@ async function runStop(store, record, opts) {
|
|
|
145
117
|
store.clearStopping(record.id);
|
|
146
118
|
}
|
|
147
119
|
}
|
|
148
|
-
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export const LOGGER_NAME = "screencast-mcp";
|
|
2
|
+
const servers = new Set();
|
|
3
|
+
export function attachLogging(server) {
|
|
4
|
+
servers.add(server);
|
|
5
|
+
}
|
|
6
|
+
export function logMessage(level, message, data = {}) {
|
|
7
|
+
for (const server of servers) {
|
|
8
|
+
if (!server.isConnected())
|
|
9
|
+
continue;
|
|
10
|
+
server
|
|
11
|
+
.sendLoggingMessage({ level, logger: LOGGER_NAME, data: { message, ...data } })
|
|
12
|
+
.catch(() => { });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const PROGRESS = /^\s*(?:frame|size)=/;
|
|
16
|
+
const WARNING = /\b(?:warning|deprecated|dropp(?:ed|ing)|too full|discard\w*|non[- ]?monoton\w*|past duration|could not|cannot|failed|invalid|corrupt\w*|missing|error)\b/i;
|
|
17
|
+
const BENIGN = /^\s*configuration:|deprecated pixel format used/i;
|
|
18
|
+
export const MAX_WARNINGS = 20;
|
|
19
|
+
function isWarning(line) {
|
|
20
|
+
return !PROGRESS.test(line) && WARNING.test(line) && !BENIGN.test(line);
|
|
21
|
+
}
|
|
22
|
+
export function ffmpegWarnings(stderr) {
|
|
23
|
+
const out = new Set();
|
|
24
|
+
for (const raw of stderr.split(/[\r\n]+/)) {
|
|
25
|
+
const line = raw.trim();
|
|
26
|
+
if (line && isWarning(line))
|
|
27
|
+
out.add(line);
|
|
28
|
+
if (out.size >= MAX_WARNINGS)
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
return [...out];
|
|
32
|
+
}
|
|
33
|
+
export function logFfmpegWarnings(stderr, data = {}) {
|
|
34
|
+
const warnings = ffmpegWarnings(stderr);
|
|
35
|
+
if (warnings.length > 0)
|
|
36
|
+
logMessage("warning", "ffmpeg reported warnings.", { ...data, warnings });
|
|
37
|
+
}
|
|
38
|
+
export const DROP_REPORT_INTERVAL_MS = 10_000;
|
|
39
|
+
export class StderrWatch {
|
|
40
|
+
data;
|
|
41
|
+
send;
|
|
42
|
+
now;
|
|
43
|
+
partial = "";
|
|
44
|
+
seen = new Set();
|
|
45
|
+
dropped = 0;
|
|
46
|
+
lastDropReport = -Infinity;
|
|
47
|
+
constructor(data, send = logMessage, now = Date.now) {
|
|
48
|
+
this.data = data;
|
|
49
|
+
this.send = send;
|
|
50
|
+
this.now = now;
|
|
51
|
+
}
|
|
52
|
+
feed(chunk) {
|
|
53
|
+
const parts = (this.partial + chunk).split(/[\r\n]/);
|
|
54
|
+
this.partial = parts.pop() ?? "";
|
|
55
|
+
for (const raw of parts)
|
|
56
|
+
this.line(raw.trim());
|
|
57
|
+
}
|
|
58
|
+
line(line) {
|
|
59
|
+
if (!line)
|
|
60
|
+
return;
|
|
61
|
+
if (PROGRESS.test(line)) {
|
|
62
|
+
const drop = Number(/\bdrop=\s*(\d+)/.exec(line)?.[1] ?? 0);
|
|
63
|
+
if (drop > this.dropped && this.now() - this.lastDropReport >= DROP_REPORT_INTERVAL_MS) {
|
|
64
|
+
this.lastDropReport = this.now();
|
|
65
|
+
this.dropped = drop;
|
|
66
|
+
this.send("warning", `The recording has dropped ${drop} frame(s) so far.`, { ...this.data(), dropped: drop });
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!isWarning(line) || this.seen.has(line) || this.seen.size >= MAX_WARNINGS)
|
|
71
|
+
return;
|
|
72
|
+
this.seen.add(line);
|
|
73
|
+
this.send("warning", line, { ...this.data(), source: "ffmpeg" });
|
|
74
|
+
}
|
|
75
|
+
}
|