@tmhs/screencast-mcp 0.39.0 → 0.45.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 +95 -17
- package/assets/icon.png +0 -0
- package/assets/ui/player.html +47 -302
- package/assets/ui/player.js +402 -0
- package/dist/context.js +0 -5
- package/dist/index.js +17 -21
- package/dist/prompts.js +18 -8
- package/dist/resources.js +2 -14
- package/dist/server.js +49 -11
- package/dist/tools/addMarker.js +89 -0
- package/dist/tools/assembleHighlights.js +12 -7
- package/dist/tools/backdrop.js +89 -0
- package/dist/tools/bugReport.js +266 -0
- package/dist/tools/burnSubtitles.js +12 -6
- package/dist/tools/callout.js +32 -16
- package/dist/tools/chapters.js +156 -0
- 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 +39 -33
- 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 +52 -98
- package/dist/tools/getMediaInfo.js +17 -3
- package/dist/tools/getSession.js +15 -3
- package/dist/tools/keystrokeOverlay.js +131 -0
- 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 +86 -25
- 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 +75 -22
- package/dist/tools/sampleFrames.js +33 -40
- package/dist/tools/saveReplay.js +90 -0
- 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 +96 -59
- package/dist/tools/stopRecording.js +35 -10
- 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/backdrop.js +151 -0
- package/dist/utils/bugReport.js +246 -0
- 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/chapters.js +222 -0
- 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/keystrokes.js +170 -0
- package/dist/utils/lifecycle.js +11 -31
- package/dist/utils/logging.js +75 -0
- package/dist/utils/media.js +16 -124
- package/dist/utils/monitors.js +7 -43
- package/dist/utils/ocr.js +53 -71
- package/dist/utils/ocrScan.js +77 -0
- package/dist/utils/paths.js +68 -31
- package/dist/utils/pipeline.js +39 -25
- package/dist/utils/player.js +50 -27
- package/dist/utils/produce.js +6 -66
- package/dist/utils/replay.js +278 -0
- 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 +122 -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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { RootsListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import { setClientRoots } from "./paths.js";
|
|
4
|
+
export function rootDirs(roots) {
|
|
5
|
+
const dirs = [];
|
|
6
|
+
for (const { uri } of roots) {
|
|
7
|
+
if (!uri.startsWith("file:"))
|
|
8
|
+
continue;
|
|
9
|
+
try {
|
|
10
|
+
dirs.push(fileURLToPath(uri));
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return dirs;
|
|
16
|
+
}
|
|
17
|
+
export function trackClientRoots(server) {
|
|
18
|
+
const low = server.server;
|
|
19
|
+
const refresh = async (initial) => {
|
|
20
|
+
if (!low.getClientCapabilities()?.roots) {
|
|
21
|
+
setClientRoots(null);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (initial)
|
|
25
|
+
setClientRoots("pending");
|
|
26
|
+
try {
|
|
27
|
+
const { roots } = await low.listRoots();
|
|
28
|
+
setClientRoots(rootDirs(roots));
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
if (initial)
|
|
32
|
+
setClientRoots(null);
|
|
33
|
+
process.stderr.write(`roots/list failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const previous = low.oninitialized;
|
|
37
|
+
low.oninitialized = () => {
|
|
38
|
+
previous?.();
|
|
39
|
+
void refresh(true);
|
|
40
|
+
};
|
|
41
|
+
low.setNotificationHandler(RootsListChangedNotificationSchema, () => refresh(false));
|
|
42
|
+
}
|
package/dist/utils/sessions.js
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Recording session registry.
|
|
3
|
-
*
|
|
4
|
-
* Sessions are tracked both in memory (with a live child-process handle for
|
|
5
|
-
* graceful stop) and on disk (sessions.json) so that:
|
|
6
|
-
* - stop/list/get survive within a server run, and
|
|
7
|
-
* - a crash leaves a durable record the next boot can reconcile (orphan
|
|
8
|
-
* reaping), ensuring no ffmpeg child silently outlives the server.
|
|
9
|
-
*
|
|
10
|
-
* The child handle is intentionally NOT persisted; only the pid is. Reaping
|
|
11
|
-
* logic (classifyOrphan) is pure so it is unit-tested without real processes.
|
|
12
|
-
*/
|
|
13
1
|
import { spawnSync } from "node:child_process";
|
|
14
|
-
import { readFileSync, writeFileSync, renameSync, existsSync, copyFileSync, openSync, closeSync, unlinkSync, statSync, } from "node:fs";
|
|
2
|
+
import { readFileSync, writeFileSync, renameSync, existsSync, copyFileSync, openSync, closeSync, unlinkSync, statSync, linkSync, } from "node:fs";
|
|
3
|
+
import { basename } from "node:path";
|
|
4
|
+
import { ScreencastError } from "./errors.js";
|
|
15
5
|
import { WGC_WINDOW_CLOSED_EXIT } from "./wgc.js";
|
|
16
|
-
/** Cap on retained finished records, so the registry does not grow without
|
|
17
|
-
* bound. Active ("recording") records are always kept. */
|
|
18
6
|
export const MAX_FINISHED_RECORDS = 100;
|
|
19
|
-
/** Decide what an in-progress session becomes at boot, given liveness.
|
|
20
|
-
* Pure: a still-alive pid is an orphan to be reaped; a dead one simply ended. */
|
|
21
7
|
export function classifyOrphan(record, alive) {
|
|
22
8
|
if (record.status !== "recording") {
|
|
23
9
|
return { status: record.status, reaped: false };
|
|
@@ -26,22 +12,45 @@ export function classifyOrphan(record, alive) {
|
|
|
26
12
|
? { status: "orphaned", reaped: true }
|
|
27
13
|
: { status: "stopped", reaped: false };
|
|
28
14
|
}
|
|
29
|
-
/**
|
|
30
|
-
* True if a "recording" record is owned by a DIFFERENT, still-live server
|
|
31
|
-
* instance. Such a record must be left alone: another running server is actively
|
|
32
|
-
* recording it, so reaping would kill that server's live capture. Pure so the
|
|
33
|
-
* ownership rule is unit-tested without real processes.
|
|
34
|
-
*
|
|
35
|
-
* Records with no `serverPid` (older registries) are not treated as foreign, so
|
|
36
|
-
* genuine orphans there still get reaped.
|
|
37
|
-
*/
|
|
38
15
|
export function isForeignLiveRecording(record, currentServerPid, ownerAlive) {
|
|
39
16
|
return (record.status === "recording" &&
|
|
40
17
|
record.serverPid !== undefined &&
|
|
41
18
|
record.serverPid !== currentServerPid &&
|
|
42
19
|
ownerAlive);
|
|
43
20
|
}
|
|
44
|
-
|
|
21
|
+
export function serverIdentity() {
|
|
22
|
+
return {
|
|
23
|
+
serverPid: process.pid,
|
|
24
|
+
serverStartedAt: new Date(Date.now() - process.uptime() * 1000).toISOString(),
|
|
25
|
+
serverImage: basename(process.execPath).toLowerCase(),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export const OWNER_START_SLACK_MS = 5_000;
|
|
29
|
+
export function isSameServer(record, running) {
|
|
30
|
+
if (!running)
|
|
31
|
+
return true;
|
|
32
|
+
if (record.serverImage && running.image.toLowerCase() !== record.serverImage.toLowerCase())
|
|
33
|
+
return false;
|
|
34
|
+
const ref = Date.parse(record.serverStartedAt ?? record.startedAt);
|
|
35
|
+
return !(Number.isFinite(ref) && running.startMs > ref + OWNER_START_SLACK_MS);
|
|
36
|
+
}
|
|
37
|
+
export function parseProcessInfo(stdout) {
|
|
38
|
+
const m = /^(.+)\|(\d+)\s*$/m.exec(stdout.trim());
|
|
39
|
+
return m?.[1] && m[2] ? { image: m[1].trim(), startMs: Number(m[2]) } : null;
|
|
40
|
+
}
|
|
41
|
+
export function processInfo(pid) {
|
|
42
|
+
if (process.platform !== "win32" || !Number.isInteger(pid) || pid <= 0)
|
|
43
|
+
return null;
|
|
44
|
+
const script = `$p = Get-CimInstance Win32_Process -Filter "ProcessId=${pid}"; ` +
|
|
45
|
+
`if ($p) { "{0}|{1}" -f $p.Name, ([DateTimeOffset]$p.CreationDate).ToUnixTimeMilliseconds() }`;
|
|
46
|
+
const res = spawnSync("powershell", ["-NoProfile", "-NonInteractive", "-Command", script], {
|
|
47
|
+
encoding: "utf8",
|
|
48
|
+
windowsHide: true,
|
|
49
|
+
timeout: 10_000,
|
|
50
|
+
killSignal: "SIGKILL",
|
|
51
|
+
});
|
|
52
|
+
return res.status === 0 && res.stdout ? parseProcessInfo(res.stdout) : null;
|
|
53
|
+
}
|
|
45
54
|
export function isAlive(pid) {
|
|
46
55
|
if (pid === null || !Number.isInteger(pid) || pid <= 0)
|
|
47
56
|
return false;
|
|
@@ -53,19 +62,13 @@ export function isAlive(pid) {
|
|
|
53
62
|
return err.code === "EPERM";
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
|
-
/** The process image a record's pid should belong to: what it stored, else
|
|
57
|
-
* what its backend spawns (the wgc recorder runs under node, #182). Pure. */
|
|
58
65
|
export function expectedImage(record) {
|
|
59
66
|
return record.processImage ?? (record.backend === "wgc" ? "node.exe" : "ffmpeg.exe");
|
|
60
67
|
}
|
|
61
|
-
/** True when a `tasklist /FO CSV` line names the given image. Pure. */
|
|
62
68
|
export function tasklistHasImage(stdout, image) {
|
|
63
69
|
const first = stdout.split(/\r?\n/)[0] ?? "";
|
|
64
70
|
return first.toLowerCase().startsWith(`"${image.toLowerCase()}"`);
|
|
65
71
|
}
|
|
66
|
-
/** On Windows, confirm a pid is still the expected recorder image before
|
|
67
|
-
* killing it, so a recycled pid belonging to an unrelated process is never
|
|
68
|
-
* terminated. */
|
|
69
72
|
export function isRecorderProcess(pid, image) {
|
|
70
73
|
if (pid === null || process.platform !== "win32")
|
|
71
74
|
return false;
|
|
@@ -74,13 +77,9 @@ export function isRecorderProcess(pid, image) {
|
|
|
74
77
|
return false;
|
|
75
78
|
return tasklistHasImage(res.stdout, image);
|
|
76
79
|
}
|
|
77
|
-
/** isRecorderProcess for an ffmpeg.exe. */
|
|
78
80
|
export function isFfmpegProcess(pid) {
|
|
79
81
|
return isRecorderProcess(pid, "ffmpeg.exe");
|
|
80
82
|
}
|
|
81
|
-
/** Classify a recorder exit nobody asked for. Non-zero is a crash; the wgc
|
|
82
|
-
* window-closed code is its own reason; a clean exit is the maxDurationSec cap
|
|
83
|
-
* only once the cap could actually have been reached (#240). Pure. */
|
|
84
83
|
export function classifyUnrequestedExit(opts) {
|
|
85
84
|
const { code, backend, maxDurationSec, elapsedMs } = opts;
|
|
86
85
|
if (backend === "wgc" && code === WGC_WINDOW_CLOSED_EXIT)
|
|
@@ -90,7 +89,6 @@ export function classifyUnrequestedExit(opts) {
|
|
|
90
89
|
const capReached = maxDurationSec > 0 && elapsedMs >= maxDurationSec * 1000 - 2000;
|
|
91
90
|
return { status: "stopped", endReason: capReached ? "max_duration" : "stopped" };
|
|
92
91
|
}
|
|
93
|
-
/** Forcefully terminate a pid tree (used only for orphan reaping). */
|
|
94
92
|
export function killPid(pid) {
|
|
95
93
|
if (process.platform === "win32") {
|
|
96
94
|
spawnSync("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
@@ -103,12 +101,9 @@ export function killPid(pid) {
|
|
|
103
101
|
process.kill(pid, "SIGKILL");
|
|
104
102
|
}
|
|
105
103
|
catch {
|
|
106
|
-
/* already gone */
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
106
|
}
|
|
110
|
-
/** Keep every active recording plus the most recent MAX_FINISHED_RECORDS
|
|
111
|
-
* finished records (newest first), so the registry stays bounded. Pure. */
|
|
112
107
|
export function pruneRecords(records) {
|
|
113
108
|
const active = records.filter((r) => r.status === "recording");
|
|
114
109
|
const finished = records
|
|
@@ -117,16 +112,8 @@ export function pruneRecords(records) {
|
|
|
117
112
|
.slice(0, MAX_FINISHED_RECORDS);
|
|
118
113
|
return [...active, ...finished];
|
|
119
114
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
export const LOCK_STALE_MS = 10_000;
|
|
123
|
-
/** Give up waiting for the lock after this long and write anyway: a stuck
|
|
124
|
-
* lock must not stop a recording from being registered. */
|
|
125
|
-
export const LOCK_WAIT_MS = 2_000;
|
|
126
|
-
/** True when a registry lock can be taken over: it is older than
|
|
127
|
-
* LOCK_STALE_MS, or it names a holder pid that is no longer alive. A lock with
|
|
128
|
-
* no readable pid (just created, not yet written) is judged by age alone.
|
|
129
|
-
* Pure so the rule is unit-tested. */
|
|
115
|
+
export const LOCK_STALE_MS = 30_000;
|
|
116
|
+
export const LOCK_WAIT_MS = 15_000;
|
|
130
117
|
export function isLockStale(holder, now, holderAlive) {
|
|
131
118
|
if (!holder || typeof holder.at !== "number")
|
|
132
119
|
return true;
|
|
@@ -134,13 +121,9 @@ export function isLockStale(holder, now, holderAlive) {
|
|
|
134
121
|
return true;
|
|
135
122
|
return typeof holder.pid === "number" && !holderAlive;
|
|
136
123
|
}
|
|
137
|
-
/** Synchronous sleep for the lock retry loop (persist() is synchronous). */
|
|
138
124
|
function sleepSync(ms) {
|
|
139
125
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
140
126
|
}
|
|
141
|
-
/** renameSync, retried briefly on Windows sharing errors. A rename over a file
|
|
142
|
-
* that another process (an unlocked reader, antivirus, the search indexer)
|
|
143
|
-
* momentarily holds open fails with EPERM/EBUSY rather than waiting. */
|
|
144
127
|
function renameWithRetry(from, to) {
|
|
145
128
|
const deadline = Date.now() + 1_000;
|
|
146
129
|
for (;;) {
|
|
@@ -156,106 +139,113 @@ function renameWithRetry(from, to) {
|
|
|
156
139
|
}
|
|
157
140
|
}
|
|
158
141
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
142
|
+
export function breakStaleLock(lock, raw) {
|
|
143
|
+
const aside = `${lock}.${process.pid}.${Date.now()}.stale`;
|
|
144
|
+
try {
|
|
145
|
+
renameSync(lock, aside);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
let removed = true;
|
|
151
|
+
try {
|
|
152
|
+
if (readFileSync(aside, "utf8") !== raw) {
|
|
153
|
+
removed = false;
|
|
154
|
+
linkSync(aside, lock);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
unlinkSync(aside);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
}
|
|
164
|
+
return removed;
|
|
165
|
+
}
|
|
166
|
+
export function withRegistryLock(registry, fn, waitMs = LOCK_WAIT_MS) {
|
|
164
167
|
const lock = `${registry}.lock`;
|
|
165
|
-
const deadline = Date.now() +
|
|
166
|
-
let
|
|
167
|
-
|
|
168
|
+
const deadline = Date.now() + waitMs;
|
|
169
|
+
let holderPid;
|
|
170
|
+
let mine;
|
|
171
|
+
for (let attempt = 0;; attempt++) {
|
|
168
172
|
try {
|
|
169
173
|
const fd = openSync(lock, "wx");
|
|
170
|
-
|
|
174
|
+
mine = JSON.stringify({ pid: process.pid, at: Date.now(), nonce: Math.random().toString(36).slice(2) });
|
|
175
|
+
writeFileSync(fd, mine);
|
|
171
176
|
closeSync(fd);
|
|
172
|
-
|
|
177
|
+
break;
|
|
173
178
|
}
|
|
174
179
|
catch (err) {
|
|
175
180
|
const code = err.code;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
// On Windows a lock that its holder just deleted, while another process
|
|
181
|
-
// still had it open, lingers as "delete pending": creating it again fails
|
|
182
|
-
// with EPERM/EACCES/EBUSY, not EEXIST. That means busy, so wait.
|
|
183
|
-
if (code === "EPERM" || code === "EACCES" || code === "EBUSY") {
|
|
184
|
-
sleepSync(5 + Math.random() * 10);
|
|
185
|
-
continue;
|
|
181
|
+
const busy = code === "EEXIST" || code === "EPERM" || code === "EACCES" || code === "EBUSY";
|
|
182
|
+
if (!busy) {
|
|
183
|
+
throw new ScreencastError(`Could not lock the session registry (${lock}): ${err.message}`);
|
|
186
184
|
}
|
|
187
|
-
if (code
|
|
188
|
-
|
|
189
|
-
let holder;
|
|
190
|
-
try {
|
|
191
|
-
holder = JSON.parse(readFileSync(lock, "utf8"));
|
|
192
|
-
}
|
|
193
|
-
catch {
|
|
194
|
-
// Unreadable or half-written: judge it by the file's age instead.
|
|
185
|
+
if (code === "EEXIST") {
|
|
186
|
+
let seen;
|
|
195
187
|
try {
|
|
196
|
-
|
|
188
|
+
const raw = readFileSync(lock, "utf8");
|
|
189
|
+
let holder;
|
|
190
|
+
try {
|
|
191
|
+
holder = JSON.parse(raw);
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
holder = { at: statSync(lock).mtimeMs };
|
|
195
|
+
}
|
|
196
|
+
seen = { raw, holder };
|
|
197
197
|
}
|
|
198
198
|
catch {
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
if (isLockStale(holder, Date.now(), isAlive(holder?.pid ?? null))) {
|
|
203
|
-
try {
|
|
204
|
-
unlinkSync(lock);
|
|
199
|
+
seen = null;
|
|
205
200
|
}
|
|
206
|
-
|
|
207
|
-
|
|
201
|
+
if (seen) {
|
|
202
|
+
holderPid = seen.holder?.pid;
|
|
203
|
+
if (isLockStale(seen.holder, Date.now(), isAlive(seen.holder?.pid ?? null)) &&
|
|
204
|
+
breakStaleLock(lock, seen.raw)) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
208
207
|
}
|
|
209
|
-
continue;
|
|
210
208
|
}
|
|
211
|
-
|
|
209
|
+
if (Date.now() >= deadline) {
|
|
210
|
+
throw new ScreencastError(`The session registry is busy: could not take ${lock} within ${waitMs / 1000} s` +
|
|
211
|
+
`${holderPid !== undefined ? ` (held by process ${holderPid})` : ""}. Nothing was written.`, "Another screencast-mcp server is writing to the same registry. Retry; if no other server is running, delete the .lock file.");
|
|
212
|
+
}
|
|
213
|
+
sleepSync(Math.min(50, 2 ** Math.min(attempt, 6)) * (0.5 + Math.random()));
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
216
|
try {
|
|
215
217
|
return fn();
|
|
216
218
|
}
|
|
217
219
|
finally {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
+
try {
|
|
221
|
+
if (readFileSync(lock, "utf8") === mine)
|
|
220
222
|
unlinkSync(lock);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
/* already removed */
|
|
224
|
-
}
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
export class SessionStore {
|
|
229
229
|
path;
|
|
230
|
+
lockWaitMs;
|
|
230
231
|
records = new Map();
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
* stale copy loaded at boot never undoes another instance's update (#55). */
|
|
234
|
-
dirty = new Set();
|
|
232
|
+
pending = new Map();
|
|
233
|
+
seen = null;
|
|
235
234
|
children = new Map();
|
|
236
|
-
/** Ids with a deliberate stop in flight, so the child's exit handler does not
|
|
237
|
-
* misread the clean exit as the maxDurationSec cap firing. */
|
|
238
235
|
stopping = new Set();
|
|
239
|
-
/** Called after every write, e.g. to tell MCP clients the session
|
|
240
|
-
* resources changed (#126). */
|
|
241
236
|
listeners = [];
|
|
242
|
-
constructor(path) {
|
|
237
|
+
constructor(path, lockWaitMs = LOCK_WAIT_MS) {
|
|
243
238
|
this.path = path;
|
|
239
|
+
this.lockWaitMs = lockWaitMs;
|
|
244
240
|
}
|
|
245
|
-
/** Run `cb` after each registry write. A throwing listener is ignored. */
|
|
246
241
|
onChange(cb) {
|
|
247
242
|
this.listeners.push(cb);
|
|
248
243
|
}
|
|
249
|
-
/** Read the on-disk records, tolerating a missing or corrupt file. A corrupt
|
|
250
|
-
* registry is copied to .bak for inspection instead of silently discarded -
|
|
251
|
-
* it may hold "recording" entries whose ffmpeg would otherwise never be
|
|
252
|
-
* reaped. */
|
|
253
244
|
readDisk() {
|
|
254
245
|
if (!existsSync(this.path))
|
|
255
246
|
return new Map();
|
|
256
247
|
try {
|
|
257
|
-
|
|
258
|
-
return new Map(data.map((r) => [r.id, r]));
|
|
248
|
+
return this.parseDisk();
|
|
259
249
|
}
|
|
260
250
|
catch {
|
|
261
251
|
try {
|
|
@@ -263,69 +253,113 @@ export class SessionStore {
|
|
|
263
253
|
process.stderr.write(`Session registry was unreadable; saved a copy to ${this.path}.bak and starting fresh.\n`);
|
|
264
254
|
}
|
|
265
255
|
catch {
|
|
266
|
-
/* best effort */
|
|
267
256
|
}
|
|
268
257
|
return new Map();
|
|
269
258
|
}
|
|
270
259
|
}
|
|
260
|
+
parseDisk() {
|
|
261
|
+
const data = JSON.parse(readFileSync(this.path, "utf8"));
|
|
262
|
+
return new Map(data.map((r) => [r.id, r]));
|
|
263
|
+
}
|
|
264
|
+
signature() {
|
|
265
|
+
try {
|
|
266
|
+
const s = statSync(this.path, { bigint: true });
|
|
267
|
+
return `${s.ino}:${s.size}:${s.mtimeNs}`;
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
overlay(disk) {
|
|
274
|
+
for (const [id, patch] of this.pending) {
|
|
275
|
+
const base = disk.get(id) ?? this.records.get(id);
|
|
276
|
+
if (base)
|
|
277
|
+
disk.set(id, { ...base, ...patch });
|
|
278
|
+
}
|
|
279
|
+
return disk;
|
|
280
|
+
}
|
|
281
|
+
refresh() {
|
|
282
|
+
const sig = this.signature();
|
|
283
|
+
if (sig === this.seen)
|
|
284
|
+
return;
|
|
285
|
+
let disk;
|
|
286
|
+
try {
|
|
287
|
+
disk = sig === null ? new Map() : this.parseDisk();
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
this.seen = sig;
|
|
293
|
+
this.records = new Map(pruneRecords([...this.overlay(disk).values()]).map((r) => [r.id, r]));
|
|
294
|
+
}
|
|
271
295
|
load() {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
296
|
+
const read = () => {
|
|
297
|
+
const disk = this.readDisk();
|
|
298
|
+
this.seen = this.signature();
|
|
299
|
+
return disk;
|
|
300
|
+
};
|
|
301
|
+
let disk;
|
|
302
|
+
try {
|
|
303
|
+
disk = withRegistryLock(this.path, read, this.lockWaitMs);
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
process.stderr.write(`${err.message} Reading the session registry without the lock.\n`);
|
|
307
|
+
disk = read();
|
|
308
|
+
}
|
|
309
|
+
this.records = new Map(pruneRecords([...this.overlay(disk).values()]).map((r) => [r.id, r]));
|
|
276
310
|
}
|
|
277
311
|
persist() {
|
|
278
|
-
// Under the registry lock: re-read the file, overlay only the records this
|
|
279
|
-
// instance changed (anything else on disk is newer than our copy), prune,
|
|
280
|
-
// and write atomically (temp + rename) so a kill mid-write cannot corrupt
|
|
281
|
-
// the file. Our view is then refreshed from what was written.
|
|
282
312
|
withRegistryLock(this.path, () => {
|
|
283
|
-
const
|
|
284
|
-
for (const id of this.dirty) {
|
|
285
|
-
const rec = this.records.get(id);
|
|
286
|
-
if (rec)
|
|
287
|
-
merged.set(id, rec);
|
|
288
|
-
}
|
|
289
|
-
const pruned = pruneRecords([...merged.values()]);
|
|
313
|
+
const pruned = pruneRecords([...this.overlay(this.readDisk()).values()]);
|
|
290
314
|
const tmp = `${this.path}.${process.pid}.tmp`;
|
|
291
315
|
writeFileSync(tmp, JSON.stringify(pruned, null, 2));
|
|
292
316
|
renameWithRetry(tmp, this.path);
|
|
317
|
+
this.seen = this.signature();
|
|
293
318
|
this.records = new Map(pruned.map((r) => [r.id, r]));
|
|
294
|
-
this.
|
|
295
|
-
});
|
|
319
|
+
this.pending.clear();
|
|
320
|
+
}, this.lockWaitMs);
|
|
296
321
|
for (const cb of this.listeners) {
|
|
297
322
|
try {
|
|
298
323
|
cb();
|
|
299
324
|
}
|
|
300
325
|
catch {
|
|
301
|
-
/* a listener must not break a registry write */
|
|
302
326
|
}
|
|
303
327
|
}
|
|
304
328
|
}
|
|
305
329
|
create(record) {
|
|
306
330
|
this.records.set(record.id, record);
|
|
307
|
-
this.
|
|
308
|
-
|
|
331
|
+
this.pending.set(record.id, record);
|
|
332
|
+
try {
|
|
333
|
+
this.persist();
|
|
334
|
+
}
|
|
335
|
+
catch (err) {
|
|
336
|
+
this.records.delete(record.id);
|
|
337
|
+
this.pending.delete(record.id);
|
|
338
|
+
throw err;
|
|
339
|
+
}
|
|
309
340
|
}
|
|
310
341
|
get(id) {
|
|
342
|
+
this.refresh();
|
|
311
343
|
return this.records.get(id);
|
|
312
344
|
}
|
|
313
345
|
list() {
|
|
346
|
+
this.refresh();
|
|
314
347
|
return [...this.records.values()].sort((a, b) => a.startedAt < b.startedAt ? 1 : -1);
|
|
315
348
|
}
|
|
316
349
|
update(id, patch) {
|
|
317
|
-
|
|
350
|
+
let cur = this.records.get(id);
|
|
351
|
+
if (!cur) {
|
|
352
|
+
this.refresh();
|
|
353
|
+
cur = this.records.get(id);
|
|
354
|
+
}
|
|
318
355
|
if (!cur)
|
|
319
356
|
return undefined;
|
|
320
357
|
const next = { ...cur, ...patch };
|
|
321
358
|
this.records.set(id, next);
|
|
322
|
-
this.
|
|
359
|
+
this.pending.set(id, { ...this.pending.get(id), ...patch });
|
|
323
360
|
this.persist();
|
|
324
361
|
return this.records.get(id) ?? next;
|
|
325
362
|
}
|
|
326
|
-
/** update() for event handlers: a failed registry write (a full disk, a
|
|
327
|
-
* locked sessions.json) is logged instead of thrown, because a throw from a
|
|
328
|
-
* child-process or finalizer callback would crash the server (#207). */
|
|
329
363
|
tryUpdate(id, patch) {
|
|
330
364
|
try {
|
|
331
365
|
return this.update(id, patch);
|
|
@@ -344,7 +378,6 @@ export class SessionStore {
|
|
|
344
378
|
detachChild(id) {
|
|
345
379
|
this.children.delete(id);
|
|
346
380
|
}
|
|
347
|
-
/** Ids of recordings this instance owns a live child handle for. */
|
|
348
381
|
activeIds() {
|
|
349
382
|
return [...this.children.keys()].filter((id) => this.records.get(id)?.status === "recording");
|
|
350
383
|
}
|
|
@@ -357,19 +390,22 @@ export class SessionStore {
|
|
|
357
390
|
clearStopping(id) {
|
|
358
391
|
this.stopping.delete(id);
|
|
359
392
|
}
|
|
360
|
-
/**
|
|
361
|
-
* Reconcile persisted "recording" sessions at boot: kill any ffmpeg child
|
|
362
|
-
* that outlived the previous server, and mark records accordingly. Returns
|
|
363
|
-
* the ids that were reaped.
|
|
364
|
-
*/
|
|
365
393
|
reapOrphans() {
|
|
394
|
+
this.refresh();
|
|
366
395
|
const reaped = [];
|
|
396
|
+
const owners = new Map();
|
|
397
|
+
const ownerAlive = (record) => {
|
|
398
|
+
const pid = record.serverPid;
|
|
399
|
+
if (pid === undefined || pid === process.pid || !isAlive(pid))
|
|
400
|
+
return false;
|
|
401
|
+
if (!owners.has(pid))
|
|
402
|
+
owners.set(pid, processInfo(pid));
|
|
403
|
+
return isSameServer(record, owners.get(pid) ?? null);
|
|
404
|
+
};
|
|
367
405
|
for (const record of this.records.values()) {
|
|
368
406
|
if (record.status !== "recording")
|
|
369
407
|
continue;
|
|
370
|
-
|
|
371
|
-
// that would kill its active capture. Leave the record untouched.
|
|
372
|
-
if (isForeignLiveRecording(record, process.pid, isAlive(record.serverPid ?? null))) {
|
|
408
|
+
if (isForeignLiveRecording(record, process.pid, ownerAlive(record))) {
|
|
373
409
|
continue;
|
|
374
410
|
}
|
|
375
411
|
const alive = isAlive(record.pid);
|
|
@@ -379,19 +415,18 @@ export class SessionStore {
|
|
|
379
415
|
killPid(record.pid);
|
|
380
416
|
reaped.push(record.id);
|
|
381
417
|
}
|
|
382
|
-
|
|
383
|
-
this.records.set(record.id, {
|
|
384
|
-
...record,
|
|
418
|
+
const patch = {
|
|
385
419
|
status: verdict.status,
|
|
386
|
-
stoppedAt:
|
|
387
|
-
|
|
388
|
-
? "Reaped on server restart (recording was interrupted)."
|
|
389
|
-
:
|
|
390
|
-
}
|
|
420
|
+
...(record.stoppedAt ? {} : { stoppedAt: new Date().toISOString() }),
|
|
421
|
+
...(verdict.status === "orphaned"
|
|
422
|
+
? { error: "Reaped on server restart (recording was interrupted)." }
|
|
423
|
+
: {}),
|
|
424
|
+
};
|
|
425
|
+
this.records.set(record.id, { ...record, ...patch });
|
|
426
|
+
this.pending.set(record.id, { ...this.pending.get(record.id), ...patch });
|
|
391
427
|
}
|
|
392
428
|
if (this.records.size > 0)
|
|
393
429
|
this.persist();
|
|
394
430
|
return reaped;
|
|
395
431
|
}
|
|
396
432
|
}
|
|
397
|
-
//# sourceMappingURL=sessions.js.map
|
package/dist/utils/sheet.js
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Contact sheets and poster frames (#115).
|
|
3
|
-
*
|
|
4
|
-
* A contact sheet tiles N timestamped frames of a video into one image, so an
|
|
5
|
-
* agent can see a whole recording in a single image read. Each tile is grabbed
|
|
6
|
-
* at its own timestamp (accurate seek), scaled to a fixed width, and labelled;
|
|
7
|
-
* a final pass tiles them. All builders here are pure.
|
|
8
|
-
*/
|
|
9
1
|
import { ScreencastError } from "./errors.js";
|
|
10
2
|
import { escapeFilterPath } from "./fonts.js";
|
|
11
3
|
import { stillOutput } from "./paths.js";
|
|
12
4
|
export const DEFAULT_SHEET_COUNT = 12;
|
|
13
5
|
export const MAX_SHEET_COUNT = 48;
|
|
14
6
|
export const DEFAULT_TILE_WIDTH = 320;
|
|
15
|
-
/** `count` timestamps spread evenly across the video, each in the middle of
|
|
16
|
-
* its slice (so the first is not a black opening frame). Millisecond precision. */
|
|
17
7
|
export function evenTimes(durationSec, count) {
|
|
18
8
|
if (!(durationSec > 0))
|
|
19
9
|
throw new ScreencastError("Could not read the video's duration.");
|
|
20
10
|
return Array.from({ length: count }, (_, i) => Math.round(((i + 0.5) * durationSec) / count * 1000) / 1000);
|
|
21
11
|
}
|
|
22
|
-
/** `m:ss.s`, or `h:mm:ss` from an hour up. */
|
|
23
12
|
export function formatTimecode(sec) {
|
|
24
13
|
const s = Math.max(0, sec);
|
|
25
14
|
const h = Math.floor(s / 3600);
|
|
@@ -29,15 +18,11 @@ export function formatTimecode(sec) {
|
|
|
29
18
|
return `${h}:${String(m).padStart(2, "0")}:${String(Math.floor(rest)).padStart(2, "0")}`;
|
|
30
19
|
return `${m}:${rest.toFixed(1).padStart(4, "0")}`;
|
|
31
20
|
}
|
|
32
|
-
/** Grid for `count` tiles: `columns` if given, else one row for up to four
|
|
33
|
-
* tiles and roughly square beyond that. */
|
|
34
21
|
export function sheetGrid(count, columns) {
|
|
35
22
|
const auto = count <= 4 ? count : Math.ceil(Math.sqrt(count));
|
|
36
23
|
const c = Math.max(1, Math.min(count, columns ?? auto));
|
|
37
24
|
return { columns: c, rows: Math.ceil(count / c) };
|
|
38
25
|
}
|
|
39
|
-
/** Grab one labelled tile: seek to `timeSec`, scale to `tileWidth`, and draw
|
|
40
|
-
* the label (read from `labelFile`, so no text escaping is needed). */
|
|
41
26
|
export function buildTileArgs(input, timeSec, output, tileWidth, fontFile, labelFile) {
|
|
42
27
|
if (!Number.isInteger(tileWidth) || tileWidth < 64) {
|
|
43
28
|
throw new ScreencastError("tileWidth must be an integer of at least 64.");
|
|
@@ -52,7 +37,6 @@ export function buildTileArgs(input, timeSec, output, tileWidth, fontFile, label
|
|
|
52
37
|
...stillOutput(output),
|
|
53
38
|
];
|
|
54
39
|
}
|
|
55
|
-
/** Tile a numbered PNG sequence into one image; unused cells stay black. */
|
|
56
40
|
export function buildSheetArgs(tilePattern, grid, output) {
|
|
57
41
|
return [
|
|
58
42
|
"-y", "-v", "error", "-framerate", "1", "-i", tilePattern,
|
|
@@ -61,8 +45,6 @@ export function buildSheetArgs(tilePattern, grid, output) {
|
|
|
61
45
|
...stillOutput(output),
|
|
62
46
|
];
|
|
63
47
|
}
|
|
64
|
-
/** A single representative poster frame: sample 30 candidates across the
|
|
65
|
-
* whole video and let ffmpeg's `thumbnail` filter pick the most typical. */
|
|
66
48
|
export function buildPosterArgs(input, durationSec, output, width) {
|
|
67
49
|
if (!(durationSec > 0))
|
|
68
50
|
throw new ScreencastError("Could not read the video's duration.");
|
|
@@ -75,4 +57,3 @@ export function buildPosterArgs(input, durationSec, output, width) {
|
|
|
75
57
|
...stillOutput(output),
|
|
76
58
|
];
|
|
77
59
|
}
|
|
78
|
-
//# sourceMappingURL=sheet.js.map
|