@tmhs/screencast-mcp 0.48.2 → 0.49.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 +8 -7
- package/dist/resources.js +26 -0
- package/dist/server.js +2 -0
- package/dist/tools/callout.js +6 -7
- package/dist/tools/contactSheet.js +3 -2
- package/dist/tools/deleteRecording.js +119 -0
- package/dist/tools/indexRecording.js +6 -6
- package/dist/tools/redactRegion.js +6 -7
- package/dist/tools/sampleFrames.js +6 -2
- package/dist/tools/stepGuide.js +12 -8
- package/dist/tools/waitForChange.js +13 -45
- package/dist/utils/callout.js +6 -2
- package/dist/utils/images.js +4 -4
- package/dist/utils/media.js +17 -3
- package/dist/utils/ocrScan.js +33 -19
- package/dist/utils/paths.js +3 -0
- package/dist/utils/pool.js +29 -0
- package/dist/utils/recordingFiles.js +32 -0
- package/dist/utils/replay.js +16 -23
- package/dist/utils/sessions.js +25 -0
- package/dist/utils/toolSpec.js +6 -0
- package/dist/utils/toolsets.js +1 -0
- package/dist/utils/waitLoop.js +50 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**An MCP server that lets an agent record the screen, _watch_ the footage, and make minimal ffmpeg edits — over stdio, on Windows.**
|
|
6
6
|
|
|
7
|
-
Capture the desktop, a monitor, a window, or a region; sample a recording into frames the agent can actually look at; trim, crop, redact, annotate, zoom toward clicks, and export for GitHub or social. No cloud service, no telemetry: ffmpeg and ffprobe behind <!--tool-count-->
|
|
7
|
+
Capture the desktop, a monitor, a window, or a region; sample a recording into frames the agent can actually look at; trim, crop, redact, annotate, zoom toward clicks, and export for GitHub or social. No cloud service, no telemetry: ffmpeg and ffprobe behind <!--tool-count-->59<!--/tool-count--> typed tools.
|
|
8
8
|
|
|
9
9
|
**For developers who want their coding agent to see and prove UI changes on Windows**: bug repros, UI verification, and demo clips the agent records, checks, and edits itself. Capture is Windows-only; the watch and edit tools work on any OS with ffmpeg. Free for non-commercial use ([CC BY-NC-ND 4.0](#license)); [why not OBS, Playwright, or a screenshot MCP?](#why-not-just)
|
|
10
10
|
|
|
@@ -75,7 +75,7 @@ The core is the **watch loop**: the agent records, samples the footage into fram
|
|
|
75
75
|
## Tools
|
|
76
76
|
|
|
77
77
|
<!-- tools:start -->
|
|
78
|
-
|
|
78
|
+
59 tools in 6 toolsets, generated from the server's own schemas by `npm run docs` (do not edit between the markers). Each name links to its reference page with every parameter, an example call, and what it returns; [`mcp-tools.json`](mcp-tools.json) is the same list as JSON, and [`llms-full.txt`](https://tmhsdigital.github.io/screencast-mcp/llms-full.txt) all of it in one file.
|
|
79
79
|
|
|
80
80
|
### Core
|
|
81
81
|
|
|
@@ -94,6 +94,7 @@ Record or screenshot the desktop, a monitor, a window, or a region. Every captur
|
|
|
94
94
|
| --- | --- |
|
|
95
95
|
| [`start_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/start_recording.html) | Start a background screen recording. Returns a session id; finalize it with stop_recording. Never auto-starts. |
|
|
96
96
|
| [`stop_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/stop_recording.html) | Stop a recording gracefully so the file is finalized; returns the path and duration. |
|
|
97
|
+
| [`delete_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/delete_recording.html) | Delete a finished recording with its sidecars (event log, webcam, transcript, index, markers, pause parts) and registry entries; reports bytes freed. Asks the user first when the client supports it. Edits made from it are kept. |
|
|
97
98
|
| [`pause_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/pause_recording.html) | Pause a recording; until resume_recording nothing is captured, and the gap is left out of the file, events, and markers. |
|
|
98
99
|
| [`resume_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/resume_recording.html) | Resume a paused recording (same target and settings). |
|
|
99
100
|
| [`save_replay`](https://tmhsdigital.github.io/screencast-mcp/tools/save_replay.html) | Save the last N seconds of a replay buffer (start_recording replayBufferSec) to an mp4; the buffer keeps running. |
|
|
@@ -139,7 +140,7 @@ Cut, convert, compress, and redact. A tool that writes a file refuses to replace
|
|
|
139
140
|
| [`clip`](https://tmhsdigital.github.io/screencast-mcp/tools/clip.html) | Extract several frame-exact segments, each to its own file. For one segment, trim does the same. |
|
|
140
141
|
| [`cut_idle`](https://tmhsdigital.github.io/screencast-mcp/tools/cut_idle.html) | Remove dead air: cut stretches where the screen is frozen (and silent), keeping a short pad. Returns the time saved. |
|
|
141
142
|
| [`cut_by_transcript`](https://tmhsdigital.github.io/screencast-mcp/tools/cut_by_transcript.html) | Edit a video by its transcript: cut quoted text, cue numbers, or fillers. Also writes the re-timed .srt. |
|
|
142
|
-
| [`redact_region`](https://tmhsdigital.github.io/screencast-mcp/tools/redact_region.html) | Cover given rectangles in a video (e.g. secrets on screen). Not automatic detection: find them with find_text redact: true. Off-frame regions are rejected. |
|
|
143
|
+
| [`redact_region`](https://tmhsdigital.github.io/screencast-mcp/tools/redact_region.html) | Cover given rectangles in a video or screenshot (e.g. secrets on screen). Not automatic detection: find them with find_text redact: true. Off-frame regions are rejected. |
|
|
143
144
|
| [`pipeline`](https://tmhsdigital.github.io/screencast-mcp/tools/pipeline.html) | Run several edits (trim, crop, scale, speed, cut_idle, redact, callout, keystroke_overlay, cursor, reframe, zoom, backdrop, audio, burn_subtitles, then optionally export_preset or export_gif) in one ffmpeg pass: one re-encode, no intermediate files. Prefer it over chaining edit tools; a recipe does the usual polish in one call. |
|
|
144
145
|
|
|
145
146
|
### Produce
|
|
@@ -149,7 +150,7 @@ Annotate, frame, and assemble a finished piece. Tools that combine clips normali
|
|
|
149
150
|
| Tool | What it does |
|
|
150
151
|
| --- | --- |
|
|
151
152
|
| [`overlay`](https://tmhsdigital.github.io/screencast-mcp/tools/overlay.html) | Composite an image or video (logo, watermark, picture-in-picture) onto a video at a pixel position, optionally scaled and time-limited; keeps the base's audio and length. |
|
|
152
|
-
| [`callout`](https://tmhsdigital.github.io/screencast-mcp/tools/callout.html) | Annotate a video with timed boxes, text labels, and arrows. Fallback fonts used are listed in fallbackFonts; characters no font covers are reported in warnings. |
|
|
153
|
+
| [`callout`](https://tmhsdigital.github.io/screencast-mcp/tools/callout.html) | Annotate a video or screenshot with timed boxes, text labels, and arrows. Fallback fonts used are listed in fallbackFonts; characters no font covers are reported in warnings. |
|
|
153
154
|
| [`keystroke_overlay`](https://tmhsdigital.github.io/screencast-mcp/tools/keystroke_overlay.html) | Burn keycast-style badges for shortcuts, clicks, and typing from the recording's input event log (start_recording events: true). Never shows typed text: the log has none. |
|
|
154
155
|
| [`cursor`](https://tmhsdigital.github.io/screencast-mcp/tools/cursor.html) | Draw a smoothed, scaled cursor that hides when idle from the event log of a start_recording cursor: "events" recording (no OS cursor in the video), with click ripples and an optional spotlight. |
|
|
155
156
|
| [`backdrop`](https://tmhsdigital.github.io/screencast-mcp/tools/backdrop.html) | Frame a video or screenshot on a gradient, color, or wallpaper with padding, rounded corners, and a drop shadow, optionally on a 16:9/1:1/9:16/4:5 canvas. |
|
|
@@ -203,7 +204,7 @@ Every capture tool takes one `target` string: `full`, `monitor:<index>`, `window
|
|
|
203
204
|
<!-- toolsets:start -->
|
|
204
205
|
| Toolset | Tools |
|
|
205
206
|
| --- | --- |
|
|
206
|
-
| `capture` | `start_recording`, `stop_recording`, `pause_recording`, `resume_recording`, `save_replay`, `list_sessions`, `get_session`, `read_events`, `add_marker`, `screenshot`, `list_audio_devices`, `list_video_devices`, `list_targets` |
|
|
207
|
+
| `capture` | `start_recording`, `stop_recording`, `delete_recording`, `pause_recording`, `resume_recording`, `save_replay`, `list_sessions`, `get_session`, `read_events`, `add_marker`, `screenshot`, `list_audio_devices`, `list_video_devices`, `list_targets` |
|
|
207
208
|
| `watch` | `review_recording`, `player_frames`, `sample_frames`, `contact_sheet`, `screen_diff`, `wait_for_change`, `find_text`, `index_recording`, `search_recording` |
|
|
208
209
|
| `edit` | `trim`, `concat`, `convert`, `export_gif`, `crop`, `scale`, `speed`, `compress`, `clip`, `cut_idle`, `cut_by_transcript`, `redact_region`, `pipeline` |
|
|
209
210
|
| `produce` | `overlay`, `callout`, `keystroke_overlay`, `cursor`, `backdrop`, `burn_subtitles`, `chapters`, `xfade_transition`, `assemble_highlights`, `title_card`, `reframe`, `zoom`, `export_preset`, `bug_report`, `step_guide` |
|
|
@@ -221,7 +222,7 @@ Every capture tool takes one `target` string: `full`, `monitor:<index>`, `window
|
|
|
221
222
|
with:
|
|
222
223
|
command: npm run test:e2e
|
|
223
224
|
```
|
|
224
|
-
- **Prompts and resources:** the server also ships MCP prompts that clients show as slash commands (`bug-repro-clip`, `file-bug-report`, `document-steps`, `demo-gif`, `verify-ui-change`, `review-recording`) and `screencast://sessions` resources for attaching recordings without a filesystem tool.
|
|
225
|
+
- **Prompts and resources:** the server also ships MCP prompts that clients show as slash commands (`bug-repro-clip`, `file-bug-report`, `document-steps`, `demo-gif`, `verify-ui-change`, `review-recording`) and `screencast://sessions` resources for attaching recordings without a filesystem tool. A client can subscribe to the list or one session and is notified when it changes, such as a recording that stopped at its cap.
|
|
225
226
|
- **Threat model and Windows notes:** what capture can expose, and how window, monitor, WGC, and system-audio capture behave, are on the [docs home page](https://tmhsdigital.github.io/screencast-mcp/#threat-model).
|
|
226
227
|
|
|
227
228
|
## Privacy
|
|
@@ -230,7 +231,7 @@ Every capture tool takes one `target` string: `full`, `monitor:<index>`, `window
|
|
|
230
231
|
- **What a tool returns goes to your model provider.** Inline frames, OCR text, and event summaries reach your agent like any tool result; files on disk stay on disk unless a tool returns them or you share them.
|
|
231
232
|
- **Everything is stored under `SCREENCAST_HOME`** (`recordings/`, `screenshots/`, `frames/`, `edits/`, `sessions.json`) unless a call names another path. `find_text` and `wait_for_change` delete their captures after the call by default (`keep: true` keeps them); `screen_diff` compares existing images and captures nothing.
|
|
232
233
|
- **The event log never records typed text.** Only with `start_recording` `events: true` (or `cursor: "events"`), and only while that recording runs: clicks, scrolls, and cursor positions system-wide, and typing as bursts on a 0.5 s grid with no key names (`keys: "shortcuts"` also names Ctrl/Alt/Win chords). There is no microphone capture; system audio only with `audio.source` = `system`.
|
|
233
|
-
- **Deleting data.**
|
|
234
|
+
- **Deleting data.** `delete_recording` removes a recording with its sidecars (event log, webcam, transcript, index with its screen text, markers) and registry entry, asking you first when the client supports it. Otherwise delete files under `SCREENCAST_HOME`, or set `SCREENCAST_RETENTION_DAYS`; recordings and edits are never deleted automatically.
|
|
234
235
|
|
|
235
236
|
## Contributing
|
|
236
237
|
|
package/dist/resources.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, rmSync } from "node:fs";
|
|
2
2
|
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { SubscribeRequestSchema, UnsubscribeRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
3
4
|
import { getStore, isShuttingDown } from "./context.js";
|
|
4
5
|
import { ScreencastError } from "./utils/errors.js";
|
|
5
6
|
import { runFfmpeg, probeMedia } from "./utils/ffmpeg.js";
|
|
@@ -55,6 +56,16 @@ export function registerResources(server) {
|
|
|
55
56
|
rmSync(frame, { force: true });
|
|
56
57
|
}
|
|
57
58
|
});
|
|
59
|
+
const subscribed = new Map();
|
|
60
|
+
server.server.registerCapabilities({ resources: { subscribe: true } });
|
|
61
|
+
server.server.setRequestHandler(SubscribeRequestSchema, (req) => {
|
|
62
|
+
subscribed.set(req.params.uri, resourceSnapshot(req.params.uri));
|
|
63
|
+
return {};
|
|
64
|
+
});
|
|
65
|
+
server.server.setRequestHandler(UnsubscribeRequestSchema, (req) => {
|
|
66
|
+
subscribed.delete(req.params.uri);
|
|
67
|
+
return {};
|
|
68
|
+
});
|
|
58
69
|
getStore().onChange(() => {
|
|
59
70
|
if (isShuttingDown() || !server.isConnected())
|
|
60
71
|
return;
|
|
@@ -63,5 +74,20 @@ export function registerResources(server) {
|
|
|
63
74
|
}
|
|
64
75
|
catch {
|
|
65
76
|
}
|
|
77
|
+
for (const [uri, before] of subscribed) {
|
|
78
|
+
const now = resourceSnapshot(uri);
|
|
79
|
+
if (now === before)
|
|
80
|
+
continue;
|
|
81
|
+
subscribed.set(uri, now);
|
|
82
|
+
server.server.sendResourceUpdated({ uri }).catch(() => {
|
|
83
|
+
});
|
|
84
|
+
}
|
|
66
85
|
});
|
|
67
86
|
}
|
|
87
|
+
export function resourceSnapshot(uri) {
|
|
88
|
+
if (uri === "screencast://sessions")
|
|
89
|
+
return JSON.stringify(getStore().list());
|
|
90
|
+
const m = /^screencast:\/\/sessions\/([^/]+)$/.exec(uri);
|
|
91
|
+
const s = m ? getStore().get(decodeURIComponent(m[1])) : undefined;
|
|
92
|
+
return s ? JSON.stringify(s) : null;
|
|
93
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -3,6 +3,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
3
3
|
import { parseToolsets, serverInstructions, SELECTABLE_TOOLSETS, toolsetOf, } from "./utils/toolsets.js";
|
|
4
4
|
import { register as registerStartRecording } from "./tools/startRecording.js";
|
|
5
5
|
import { register as registerStopRecording } from "./tools/stopRecording.js";
|
|
6
|
+
import { register as registerDeleteRecording } from "./tools/deleteRecording.js";
|
|
6
7
|
import { register as registerSaveReplay } from "./tools/saveReplay.js";
|
|
7
8
|
import { register as registerPauseRecording } from "./tools/pauseRecording.js";
|
|
8
9
|
import { register as registerResumeRecording } from "./tools/resumeRecording.js";
|
|
@@ -79,6 +80,7 @@ export function createServer(options = {}) {
|
|
|
79
80
|
const tools = captureRegisteredTools(server);
|
|
80
81
|
registerStartRecording(server);
|
|
81
82
|
registerStopRecording(server);
|
|
83
|
+
registerDeleteRecording(server);
|
|
82
84
|
registerPauseRecording(server);
|
|
83
85
|
registerResumeRecording(server);
|
|
84
86
|
registerSaveReplay(server);
|
package/dist/tools/callout.js
CHANGED
|
@@ -8,7 +8,7 @@ import { requireFfmpeg } from "../utils/ffmpeg.js";
|
|
|
8
8
|
import { runEditJob, probeDuration } from "../utils/jobs.js";
|
|
9
9
|
import { buildCalloutArgs } from "../utils/callout.js";
|
|
10
10
|
import { prepareCalloutAssets } from "../utils/calloutAssets.js";
|
|
11
|
-
import {
|
|
11
|
+
import { stillEdit } from "../utils/media.js";
|
|
12
12
|
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
13
13
|
const timing = {
|
|
14
14
|
from: z.number().nonnegative().optional(),
|
|
@@ -52,7 +52,7 @@ export const calloutItemSchema = z.discriminatedUnion("type", [
|
|
|
52
52
|
}),
|
|
53
53
|
]);
|
|
54
54
|
const inputSchema = {
|
|
55
|
-
input: z.string().min(1).describe("Path to the source video."),
|
|
55
|
+
input: z.string().min(1).describe("Path to the source video or image (png/jpg; from/to are ignored for an image)."),
|
|
56
56
|
items: z
|
|
57
57
|
.array(calloutItemSchema)
|
|
58
58
|
.min(1)
|
|
@@ -66,7 +66,7 @@ const inputSchema = {
|
|
|
66
66
|
export function register(server) {
|
|
67
67
|
server.registerTool("callout", {
|
|
68
68
|
title: "Add Callouts",
|
|
69
|
-
description: "Annotate a video with timed boxes, text labels, and arrows. Fallback fonts used are listed in " +
|
|
69
|
+
description: "Annotate a video or screenshot with timed boxes, text labels, and arrows. Fallback fonts used are listed in " +
|
|
70
70
|
"fallbackFonts; characters no font covers are reported in warnings.",
|
|
71
71
|
inputSchema,
|
|
72
72
|
outputSchema: OUTPUT_PATH,
|
|
@@ -78,14 +78,13 @@ export function register(server) {
|
|
|
78
78
|
throw new ScreencastError(`Input file not found: ${args.input}`);
|
|
79
79
|
}
|
|
80
80
|
const items = args.items;
|
|
81
|
-
|
|
82
|
-
const ext = editOutputExt(args.input);
|
|
81
|
+
const { still, ext } = stillEdit(args.input, args.output);
|
|
83
82
|
const output = resolveOutput(args.output, subdir("edits"), `callout-${stamp()}-${rand()}${ext}`, args.overwrite);
|
|
84
83
|
const work = mkdtempSync(join(tmpdir(), "screencast-callout-"));
|
|
85
84
|
try {
|
|
86
85
|
const assets = await prepareCalloutAssets(items, work, "", args.fontFile);
|
|
87
|
-
const ffArgs = buildCalloutArgs(args.input, output, items, assets);
|
|
88
|
-
await runEditJob(ffArgs, { output, durationSec: await probeDuration(args.input), extra });
|
|
86
|
+
const ffArgs = buildCalloutArgs(args.input, output, items, assets, undefined, still);
|
|
87
|
+
await runEditJob(ffArgs, { output, durationSec: still ? null : await probeDuration(args.input), extra });
|
|
89
88
|
return okResponse({
|
|
90
89
|
outputPath: output,
|
|
91
90
|
callouts: items.length,
|
|
@@ -11,6 +11,7 @@ import { evenTimes, formatTimecode, sheetGrid, buildTileArgs, buildSheetArgs, bu
|
|
|
11
11
|
import { bundledFontPath } from "../utils/fonts.js";
|
|
12
12
|
import { resolveOutput, subdir, stamp, rand, sequencePattern } from "../utils/paths.js";
|
|
13
13
|
import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
|
|
14
|
+
import { mapPool } from "../utils/pool.js";
|
|
14
15
|
const inputSchema = {
|
|
15
16
|
input: z.string().min(1).describe("Path to the source video."),
|
|
16
17
|
count: z
|
|
@@ -60,12 +61,12 @@ export async function renderContactSheet(input, times, output, opts, signal) {
|
|
|
60
61
|
const work = mkdtempSync(join(tmpdir(), "screencast-sheet-"));
|
|
61
62
|
try {
|
|
62
63
|
const font = bundledFontPath("bold");
|
|
63
|
-
|
|
64
|
+
await mapPool(times, async (t, i) => {
|
|
64
65
|
const labelFile = join(work, `label_${i}.txt`);
|
|
65
66
|
writeFileSync(labelFile, formatTimecode(t));
|
|
66
67
|
const tile = join(work, `tile_${String(i).padStart(3, "0")}.png`);
|
|
67
68
|
await runFfmpeg(buildTileArgs(input, t, tile, opts.tileWidth, font, labelFile), 60_000, { signal });
|
|
68
|
-
}
|
|
69
|
+
});
|
|
69
70
|
await runFfmpeg(buildSheetArgs(sequencePattern(work, "tile_%03d.png"), grid, output), 60_000, { signal });
|
|
70
71
|
}
|
|
71
72
|
finally {
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { existsSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { errorMessage, errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
5
|
+
import { DELETES_FILE, looseOutput } from "../utils/toolSpec.js";
|
|
6
|
+
import { getStore } from "../context.js";
|
|
7
|
+
import { isLive } from "../utils/sessions.js";
|
|
8
|
+
import { samePath } from "../utils/recordingIndex.js";
|
|
9
|
+
import { assertDeleteAllowed, recordingSidecars } from "../utils/recordingFiles.js";
|
|
10
|
+
import { subdir } from "../utils/paths.js";
|
|
11
|
+
import { CONFIRM_TIMEOUT_MS, confirmCaptureEnabled, CONFIRM_CAPTURE_ENV } from "../utils/consent.js";
|
|
12
|
+
const inputSchema = {
|
|
13
|
+
sessionId: z.string().min(1).optional().describe("Session id of the recording to delete."),
|
|
14
|
+
input: z.string().min(1).optional().describe("Or the recording's path."),
|
|
15
|
+
};
|
|
16
|
+
function sizeOf(path) {
|
|
17
|
+
try {
|
|
18
|
+
const st = statSync(path);
|
|
19
|
+
if (!st.isDirectory())
|
|
20
|
+
return st.size;
|
|
21
|
+
return readdirSync(path).reduce((n, name) => n + sizeOf(resolve(path, name)), 0);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function confirmDelete(server, message, signal) {
|
|
28
|
+
if (!server.server.getClientCapabilities()?.elicitation?.form) {
|
|
29
|
+
if (confirmCaptureEnabled()) {
|
|
30
|
+
throw new ScreencastError(`Not deleted: ${CONFIRM_CAPTURE_ENV} requires the user to confirm, but this client does not support MCP elicitation.`);
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
let action;
|
|
35
|
+
try {
|
|
36
|
+
({ action } = await server.server.elicitInput({ message, requestedSchema: { type: "object", properties: {} } }, { signal, timeout: CONFIRM_TIMEOUT_MS }));
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
throw new ScreencastError(`Not deleted: the confirmation request failed (${errorMessage(err)}).`);
|
|
40
|
+
}
|
|
41
|
+
if (action !== "accept")
|
|
42
|
+
throw new ScreencastError(`Not deleted: ${action === "decline" ? "declined" : "cancelled"} by the user.`);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
export function register(server) {
|
|
46
|
+
server.registerTool("delete_recording", {
|
|
47
|
+
title: "Delete Recording",
|
|
48
|
+
description: "Delete a finished recording with its sidecars (event log, webcam, transcript, index, markers, pause parts) " +
|
|
49
|
+
"and registry entries; reports bytes freed. Asks the user first when the client supports it. Edits made from it are kept.",
|
|
50
|
+
inputSchema,
|
|
51
|
+
outputSchema: looseOutput({
|
|
52
|
+
outputPath: z.string(),
|
|
53
|
+
deleted: z.array(z.string()),
|
|
54
|
+
bytesFreed: z.number(),
|
|
55
|
+
sessionsRemoved: z.array(z.string()),
|
|
56
|
+
}),
|
|
57
|
+
annotations: DELETES_FILE,
|
|
58
|
+
}, async (args, extra) => {
|
|
59
|
+
try {
|
|
60
|
+
if (!!args.sessionId === !!args.input)
|
|
61
|
+
throw new ScreencastError("Give exactly one of sessionId or input.");
|
|
62
|
+
const store = getStore();
|
|
63
|
+
let video;
|
|
64
|
+
if (args.sessionId) {
|
|
65
|
+
const record = store.get(args.sessionId);
|
|
66
|
+
if (!record)
|
|
67
|
+
throw new ScreencastError(`No session with id "${args.sessionId}".`);
|
|
68
|
+
video = record.outputPath;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
video = resolve(args.input);
|
|
72
|
+
}
|
|
73
|
+
assertDeleteAllowed(video);
|
|
74
|
+
const sessions = store.list().filter((r) => samePath(r.outputPath, video));
|
|
75
|
+
const live = sessions.find((r) => isLive(r.status));
|
|
76
|
+
if (live)
|
|
77
|
+
throw new ScreencastError(`Recording ${live.id} is still ${live.status}; stop it first.`);
|
|
78
|
+
let siblings = [];
|
|
79
|
+
try {
|
|
80
|
+
siblings = readdirSync(dirname(video));
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
}
|
|
84
|
+
const side = recordingSidecars(video, siblings, subdir("edits"));
|
|
85
|
+
const targets = [video, ...side.files, ...side.dirs].filter((p) => existsSync(p));
|
|
86
|
+
if (targets.length === 0 && sessions.length === 0)
|
|
87
|
+
throw new ScreencastError(`Nothing to delete: ${video} does not exist.`);
|
|
88
|
+
const asked = await confirmDelete(server, `Delete ${video} and ${targets.length - (existsSync(video) ? 1 : 0)} sidecar file(s)? This cannot be undone.`, extra.signal);
|
|
89
|
+
let bytesFreed = 0;
|
|
90
|
+
const deleted = [];
|
|
91
|
+
const failed = [];
|
|
92
|
+
for (const p of targets) {
|
|
93
|
+
const size = sizeOf(p);
|
|
94
|
+
try {
|
|
95
|
+
rmSync(p, { recursive: true, force: true });
|
|
96
|
+
deleted.push(p);
|
|
97
|
+
bytesFreed += size;
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
failed.push(`${p}: ${errorMessage(err)}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const removedIds = existsSync(video) ? [] : sessions.map((r) => r.id);
|
|
104
|
+
if (removedIds.length > 0)
|
|
105
|
+
store.remove(removedIds);
|
|
106
|
+
return okResponse({
|
|
107
|
+
outputPath: video,
|
|
108
|
+
deleted,
|
|
109
|
+
bytesFreed,
|
|
110
|
+
sessionsRemoved: removedIds,
|
|
111
|
+
confirmedByUser: asked,
|
|
112
|
+
...(failed.length > 0 ? { failed, note: "Some files could not be deleted (in use?); the registry entry was kept if the recording remains." } : {}),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return errorResponse(error);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -13,6 +13,7 @@ import { parseEventsJsonl } from "../utils/events.js";
|
|
|
13
13
|
import { resolveWhisperModel, buildTranscribeArgs, parseSrt, normalizeCues } from "../utils/captions.js";
|
|
14
14
|
import { subdir, tempPath } from "../utils/paths.js";
|
|
15
15
|
import { DEFAULT_INDEX_FRAMES, DEFAULT_INDEX_THRESHOLD, INDEX_VERSION, MAX_INDEX_FRAMES, attach, canReuseIndex, cueTexts, defaultTranscriptPath, eventTexts, fingerprintFile, findIndex, indexMatchesVideo, indexWritePath, keyframeTime, legacyIndexSidecarPath, markerTexts, maskSegmentText, mergeSegments, planKeyframes, readIndex, resolveRecording, segmentsFrom, writeIndex, } from "../utils/recordingIndex.js";
|
|
16
|
+
import { mapPool } from "../utils/pool.js";
|
|
16
17
|
const OCR_BATCH = 8;
|
|
17
18
|
const inputSchema = {
|
|
18
19
|
input: z.string().optional().describe("Recording path."),
|
|
@@ -79,14 +80,13 @@ export function register(server) {
|
|
|
79
80
|
for (let b = 0; b < spans.length; b += OCR_BATCH) {
|
|
80
81
|
extra.signal.throwIfAborted();
|
|
81
82
|
const batch = spans.slice(b, b + OCR_BATCH);
|
|
82
|
-
const
|
|
83
|
-
for (const [i, span] of batch.entries()) {
|
|
83
|
+
const grabbed = await mapPool(batch, async (span, i) => {
|
|
84
84
|
const out = join(work, `key_${b + i}.png`);
|
|
85
85
|
await runFfmpeg(buildSampleAtTimestampArgs(source.path, keyframeTime(span), out), 60_000, { signal: extra.signal });
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const read = frames.length > 0 ? await readFrames(frames.map((f) => f.path), work, extra.signal) : [];
|
|
86
|
+
return { at: b + i, path: out };
|
|
87
|
+
});
|
|
88
|
+
const frames = grabbed.filter((f) => existsSync(f.path));
|
|
89
|
+
const read = frames.length > 0 ? await readFrames(frames.map((f) => f.path), work, extra.signal, { sameSize: true }) : [];
|
|
90
90
|
read.forEach((f, i) => (texts[frames[i].at] = f.lines.map((l) => l.text)));
|
|
91
91
|
framesRead += read.length;
|
|
92
92
|
report?.(0.1 + (0.85 * Math.min(spans.length, b + OCR_BATCH)) / spans.length);
|
|
@@ -4,7 +4,7 @@ import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
|
4
4
|
import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
|
|
5
5
|
import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
|
|
6
6
|
import { runEditJob } from "../utils/jobs.js";
|
|
7
|
-
import { buildRedactArgs,
|
|
7
|
+
import { buildRedactArgs, stillEdit } from "../utils/media.js";
|
|
8
8
|
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
9
9
|
export const redactRegionSchema = z.object({
|
|
10
10
|
x: z.number().int().nonnegative(),
|
|
@@ -15,7 +15,7 @@ export const redactRegionSchema = z.object({
|
|
|
15
15
|
end: z.number().positive().optional(),
|
|
16
16
|
});
|
|
17
17
|
const inputSchema = {
|
|
18
|
-
input: z.string().min(1).describe("Path to the source video."),
|
|
18
|
+
input: z.string().min(1).describe("Path to the source video or image (png/jpg; time ranges are ignored for an image)."),
|
|
19
19
|
regions: z
|
|
20
20
|
.array(redactRegionSchema)
|
|
21
21
|
.min(1)
|
|
@@ -37,7 +37,7 @@ const inputSchema = {
|
|
|
37
37
|
export function register(server) {
|
|
38
38
|
server.registerTool("redact_region", {
|
|
39
39
|
title: "Redact Regions",
|
|
40
|
-
description: "Cover given rectangles in a video (e.g. secrets on screen). Not automatic detection: find " +
|
|
40
|
+
description: "Cover given rectangles in a video or screenshot (e.g. secrets on screen). Not automatic detection: find " +
|
|
41
41
|
"them with find_text redact: true. Off-frame regions are rejected.",
|
|
42
42
|
inputSchema,
|
|
43
43
|
outputSchema: OUTPUT_PATH,
|
|
@@ -49,15 +49,14 @@ export function register(server) {
|
|
|
49
49
|
throw new ScreencastError(`Input file not found: ${args.input}`);
|
|
50
50
|
}
|
|
51
51
|
const { width, height, durationSec } = await probeMedia(args.input);
|
|
52
|
-
|
|
53
|
-
const ext = editOutputExt(args.input);
|
|
52
|
+
const { still, ext } = stillEdit(args.input, args.output);
|
|
54
53
|
const output = resolveOutput(args.output, subdir("edits"), `redact-${stamp()}-${rand()}${ext}`, args.overwrite);
|
|
55
54
|
const ffArgs = buildRedactArgs(args.input, output, args.regions, {
|
|
56
55
|
style: args.style,
|
|
57
56
|
pad: args.pad,
|
|
58
57
|
color: args.color,
|
|
59
|
-
}, { width, height });
|
|
60
|
-
await runEditJob(ffArgs, { output, durationSec, extra });
|
|
58
|
+
}, { width, height }, still);
|
|
59
|
+
await runEditJob(ffArgs, { output, durationSec: still ? null : durationSec, extra });
|
|
61
60
|
return okResponse({
|
|
62
61
|
outputPath: output,
|
|
63
62
|
regions: args.regions.length,
|
|
@@ -8,6 +8,7 @@ import { jobTimeoutMs } from "../utils/jobs.js";
|
|
|
8
8
|
import { buildSampleByFpsArgs, pickFramePrefix, buildSampleAtTimestampArgs, planFpsSampling, buildSceneScanArgs, parseSceneScan, pickSceneFrames, DEFAULT_SCENE_THRESHOLD, DEFAULT_MAX_FRAMES, MAX_FRAMES_CEILING, } from "../utils/media.js";
|
|
9
9
|
import { subdir, stamp, rand, sequencePattern, resolveOutputDir } from "../utils/paths.js";
|
|
10
10
|
import { encodeInlineImages, clampInlineCount, DEFAULT_MAX_IMAGE_WIDTH, DEFAULT_MAX_INLINE_IMAGES, MAX_INLINE_IMAGES, } from "../utils/images.js";
|
|
11
|
+
import { mapPool } from "../utils/pool.js";
|
|
11
12
|
const inputSchema = {
|
|
12
13
|
input: z.string().min(1).describe("Path to the source video file."),
|
|
13
14
|
mode: z
|
|
@@ -127,14 +128,17 @@ export function register(server) {
|
|
|
127
128
|
}
|
|
128
129
|
else {
|
|
129
130
|
const ts = mode === "scenes" ? sceneTimes : args.timestamps;
|
|
130
|
-
|
|
131
|
+
const outs = await mapPool(ts, async (t, i) => {
|
|
131
132
|
const out = join(dir, `frame_${String(i).padStart(3, "0")}_${t}s.png`);
|
|
132
133
|
rmSync(out, { force: true });
|
|
133
134
|
await runFfmpeg(buildSampleAtTimestampArgs(args.input, t, out), 60_000, { signal: extra.signal });
|
|
135
|
+
return out;
|
|
136
|
+
});
|
|
137
|
+
for (const [i, out] of outs.entries()) {
|
|
134
138
|
if (existsSync(out))
|
|
135
139
|
frames.push(out);
|
|
136
140
|
else
|
|
137
|
-
skipped.push(
|
|
141
|
+
skipped.push(ts[i]);
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
144
|
const inline = args.returnImages === false
|
package/dist/tools/stepGuide.js
CHANGED
|
@@ -15,6 +15,7 @@ import { DEFAULT_SECRET_PATTERN } from "../utils/bugReport.js";
|
|
|
15
15
|
import { resolveOutputDir, subdir, stamp, rand } from "../utils/paths.js";
|
|
16
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
|
+
import { mapPool } from "../utils/pool.js";
|
|
18
19
|
const OCR_BATCH = 10;
|
|
19
20
|
const HTML_SAMPLE = 5;
|
|
20
21
|
const inputSchema = {
|
|
@@ -84,18 +85,17 @@ export function register(server) {
|
|
|
84
85
|
const total = shots.length * (useOcr ? 3 : 2) || 1;
|
|
85
86
|
let done = 0;
|
|
86
87
|
const tick = () => progress?.(++done / total);
|
|
87
|
-
const frames =
|
|
88
|
-
for (const { s } of shots) {
|
|
88
|
+
const frames = await mapPool(shots, async ({ s }) => {
|
|
89
89
|
const out = join(work, `frame-${String(s.n).padStart(3, "0")}.png`);
|
|
90
90
|
await runFfmpeg(buildStepFrameArgs(source.path, s.shotT, out), 60_000, { signal: extra.signal });
|
|
91
|
-
frames.push(out);
|
|
92
91
|
tick();
|
|
93
|
-
|
|
92
|
+
return out;
|
|
93
|
+
});
|
|
94
94
|
const read = frames.map(() => null);
|
|
95
95
|
if (useOcr) {
|
|
96
96
|
for (let b = 0; b < frames.length; b += OCR_BATCH) {
|
|
97
97
|
extra.signal.throwIfAborted();
|
|
98
|
-
const batch = await readFrames(frames.slice(b, b + OCR_BATCH), work, extra.signal);
|
|
98
|
+
const batch = await readFrames(frames.slice(b, b + OCR_BATCH), work, extra.signal, { sameSize: true });
|
|
99
99
|
batch.forEach((f, k) => {
|
|
100
100
|
read[b + k] = f;
|
|
101
101
|
tick();
|
|
@@ -121,18 +121,22 @@ export function register(server) {
|
|
|
121
121
|
}
|
|
122
122
|
mkdirSync(imageDir, { recursive: true });
|
|
123
123
|
let redactions = 0;
|
|
124
|
-
|
|
124
|
+
const frameSize = { width: info.width, height: info.height };
|
|
125
|
+
const rendered = await mapPool(shots, async ({ i }, k) => {
|
|
125
126
|
const step = steps[i];
|
|
126
127
|
const file = GUIDE_FILES.image(step.n);
|
|
127
128
|
const ring = step.x !== undefined && step.y !== undefined ? { x: step.x, y: step.y } : undefined;
|
|
128
|
-
const filter = shotFilter(
|
|
129
|
+
const filter = shotFilter(frameSize, { click: ring, boxes: boxes[k] });
|
|
129
130
|
const out = join(imageDir, file);
|
|
130
131
|
await runFfmpeg(buildStepShotArgs(frames[k], filter, out), 60_000, { signal: extra.signal });
|
|
132
|
+
tick();
|
|
133
|
+
return { step, file, out };
|
|
134
|
+
});
|
|
135
|
+
for (const [k, { step, file, out }] of rendered.entries()) {
|
|
131
136
|
if (wantMd)
|
|
132
137
|
written.push(out);
|
|
133
138
|
step.image = file;
|
|
134
139
|
redactions += boxes[k].length;
|
|
135
|
-
tick();
|
|
136
140
|
}
|
|
137
141
|
const stepsNote = all.length === 0 ? "The event log has no clicks, shortcuts, typing, or scrolls." : undefined;
|
|
138
142
|
const data = {
|
|
@@ -4,7 +4,8 @@ import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
|
|
|
4
4
|
import { requireFfmpeg, runFfmpeg, runFfmpegBuffer } from "../utils/ffmpeg.js";
|
|
5
5
|
import { resolveCaptureTarget } from "../utils/resolveTarget.js";
|
|
6
6
|
import { buildScreenshotArgs } from "../utils/targets.js";
|
|
7
|
-
import { detectionSize, targetSize,
|
|
7
|
+
import { detectionSize, targetSize, buildRawGrabArgs, targetDiffOptions, DEFAULT_PIXEL_THRESHOLD, } from "../utils/diff.js";
|
|
8
|
+
import { waitLoop } from "../utils/waitLoop.js";
|
|
8
9
|
import { windowMatchReport } from "../utils/windows.js";
|
|
9
10
|
import { confirmCapture, describeTarget } from "../utils/consent.js";
|
|
10
11
|
import { subdir, stamp, rand } from "../utils/paths.js";
|
|
@@ -55,7 +56,6 @@ const inputSchema = {
|
|
|
55
56
|
.optional()
|
|
56
57
|
.describe("Keep the final screenshot on disk and return its path (default false)."),
|
|
57
58
|
};
|
|
58
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
59
59
|
export function register(server) {
|
|
60
60
|
server.registerTool("wait_for_change", {
|
|
61
61
|
title: "Wait for Screen Change",
|
|
@@ -83,49 +83,17 @@ export function register(server) {
|
|
|
83
83
|
const size = detectionSize(area.width, area.height);
|
|
84
84
|
const grab = () => runFfmpegBuffer(buildRawGrabArgs(target, monitors, size), 15_000, { signal: extra.signal });
|
|
85
85
|
const opts = targetDiffOptions(area, size, args.pixelThreshold);
|
|
86
|
-
const started =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
await sleep(interval);
|
|
99
|
-
const current = await grab().catch((error) => {
|
|
100
|
-
if (extra.signal.aborted)
|
|
101
|
-
return null;
|
|
102
|
-
throw error;
|
|
103
|
-
});
|
|
104
|
-
if (!current) {
|
|
105
|
-
outcome = "cancelled";
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (mode === "change") {
|
|
109
|
-
const d = diffFrames(baseline, current, size.width, size.height, opts);
|
|
110
|
-
if (d.regions.length > 0) {
|
|
111
|
-
regions = d.regions;
|
|
112
|
-
outcome = "changed";
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
const changed = settle.push(current);
|
|
118
|
-
if (changed.length > 0) {
|
|
119
|
-
everChanged = true;
|
|
120
|
-
lastChangeAt = Date.now();
|
|
121
|
-
regions = changed;
|
|
122
|
-
}
|
|
123
|
-
else if (Date.now() - lastChangeAt >= settleMs) {
|
|
124
|
-
outcome = "settled";
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
86
|
+
const { outcome, regions, everChanged, startedAt: started } = await waitLoop({
|
|
87
|
+
grab,
|
|
88
|
+
mode,
|
|
89
|
+
width: size.width,
|
|
90
|
+
height: size.height,
|
|
91
|
+
diff: opts,
|
|
92
|
+
timeoutMs,
|
|
93
|
+
settleMs,
|
|
94
|
+
intervalMs: interval,
|
|
95
|
+
signal: extra.signal,
|
|
96
|
+
});
|
|
129
97
|
const result = {
|
|
130
98
|
outcome,
|
|
131
99
|
mode,
|
package/dist/utils/callout.js
CHANGED
|
@@ -73,8 +73,12 @@ export function calloutSteps(items, assets, input, firstInput, tag) {
|
|
|
73
73
|
});
|
|
74
74
|
return { steps, out: cur, extraInputs };
|
|
75
75
|
}
|
|
76
|
-
export function buildCalloutArgs(input, output, items, assets, quality = "standard") {
|
|
77
|
-
const {
|
|
76
|
+
export function buildCalloutArgs(input, output, items, assets, quality = "standard", still = false) {
|
|
77
|
+
const drawn = still ? items.map(({ from: _f, to: _t, ...c }) => c) : items;
|
|
78
|
+
const { steps, out, extraInputs } = calloutSteps(drawn, assets, "[0:v]", 1, "");
|
|
79
|
+
if (still) {
|
|
80
|
+
return ["-y", "-i", input, ...extraInputs, "-filter_complex", steps.join(";"), "-map", out, "-frames:v", "1", ...stillOutput(output)];
|
|
81
|
+
}
|
|
78
82
|
return [
|
|
79
83
|
"-y", "-i", input, ...extraInputs,
|
|
80
84
|
"-filter_complex", steps.join(";"),
|
package/dist/utils/images.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFileSync, rmSync } from "node:fs";
|
|
|
2
2
|
import { ScreencastError } from "./errors.js";
|
|
3
3
|
import { runFfmpeg } from "./ffmpeg.js";
|
|
4
4
|
import { tempPath, stillOutput } from "./paths.js";
|
|
5
|
+
import { mapPool } from "./pool.js";
|
|
5
6
|
export const DEFAULT_MAX_IMAGE_WIDTH = 1280;
|
|
6
7
|
export const DEFAULT_MAX_INLINE_IMAGES = 8;
|
|
7
8
|
export const MAX_INLINE_IMAGES = 20;
|
|
@@ -23,16 +24,15 @@ export function clampInlineCount(requested) {
|
|
|
23
24
|
}
|
|
24
25
|
export async function encodeInlineImages(paths, maxWidth = DEFAULT_MAX_IMAGE_WIDTH, maxCount = DEFAULT_MAX_INLINE_IMAGES) {
|
|
25
26
|
const chosen = paths.slice(0, maxCount);
|
|
26
|
-
const images =
|
|
27
|
-
for (const path of chosen) {
|
|
27
|
+
const images = await mapPool(chosen, async (path) => {
|
|
28
28
|
const tmp = tempPath(".jpg");
|
|
29
29
|
try {
|
|
30
30
|
await runFfmpeg(buildPreviewArgs(path, tmp, maxWidth), 30_000);
|
|
31
|
-
|
|
31
|
+
return { type: "image", data: readFileSync(tmp).toString("base64"), mimeType: "image/jpeg" };
|
|
32
32
|
}
|
|
33
33
|
finally {
|
|
34
34
|
rmSync(tmp, { force: true });
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
});
|
|
37
37
|
return { images, omitted: paths.length - chosen.length };
|
|
38
38
|
}
|
package/dist/utils/media.js
CHANGED
|
@@ -2,7 +2,7 @@ import { extname } from "node:path";
|
|
|
2
2
|
import { ScreencastError } from "./errors.js";
|
|
3
3
|
import { resolveQuality } from "./targets.js";
|
|
4
4
|
import { validateColor, validateEvenDimension } from "./validate.js";
|
|
5
|
-
import { stillOutput } from "./paths.js";
|
|
5
|
+
import { isStillImage, stillOutput } from "./paths.js";
|
|
6
6
|
const DEFAULT_EDIT_QUALITY = "standard";
|
|
7
7
|
function numberOrNull(v) {
|
|
8
8
|
if (v === undefined)
|
|
@@ -542,8 +542,22 @@ export function redactSteps(regions, opts, dims, input, tag) {
|
|
|
542
542
|
});
|
|
543
543
|
return { steps, out: `[${tag}out]` };
|
|
544
544
|
}
|
|
545
|
-
export function
|
|
546
|
-
|
|
545
|
+
export function stillEdit(input, output) {
|
|
546
|
+
if (!isStillImage(input)) {
|
|
547
|
+
assertEditContainer(output);
|
|
548
|
+
return { still: false, ext: editOutputExt(input) };
|
|
549
|
+
}
|
|
550
|
+
if (output && !isStillImage(output)) {
|
|
551
|
+
throw new ScreencastError("An image input writes an image: give the output a .png or .jpg extension.");
|
|
552
|
+
}
|
|
553
|
+
return { still: true, ext: /\.jpe?g$/i.test(input) ? extname(input).toLowerCase() : ".png" };
|
|
554
|
+
}
|
|
555
|
+
export function buildRedactArgs(input, output, regions, opts = {}, dims, still = false) {
|
|
556
|
+
const rs = still ? regions.map(({ start: _s, end: _e, ...r }) => r) : regions;
|
|
557
|
+
const { steps, out } = redactSteps(rs, opts, dims, "[0:v]", "");
|
|
558
|
+
if (still) {
|
|
559
|
+
return ["-y", "-i", input, "-filter_complex", steps.join(";"), "-map", out, "-frames:v", "1", ...stillOutput(output)];
|
|
560
|
+
}
|
|
547
561
|
const [chain] = steps;
|
|
548
562
|
if ((opts.style ?? "box") === "box" && chain !== undefined) {
|
|
549
563
|
const vf = chain.slice("[0:v]".length, -out.length);
|
package/dist/utils/ocrScan.js
CHANGED
|
@@ -5,27 +5,41 @@ import { probeMedia, runFfmpeg } from "./ffmpeg.js";
|
|
|
5
5
|
import { jobTimeoutMs } from "./jobs.js";
|
|
6
6
|
import { buildSampleByFpsArgs, planFpsSampling } from "./media.js";
|
|
7
7
|
import { recognize, mergePasses, findMatches, redactionRects, passScales } from "./ocr.js";
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
import { mapPool } from "./pool.js";
|
|
9
|
+
export function buildOcrPassArgs(source, scales, outputs) {
|
|
10
|
+
if (scales.length === 0 || scales.length !== outputs.length) {
|
|
11
|
+
throw new ScreencastError("Each OCR pass needs one output.");
|
|
12
|
+
}
|
|
13
|
+
const scale = (s) => `scale=iw*${s}:ih*${s}:flags=lanczos`;
|
|
14
|
+
const png = ["-compression_level", "0"];
|
|
15
|
+
if (scales.length === 1)
|
|
16
|
+
return ["-y", "-v", "error", "-i", source, "-vf", scale(scales[0]), ...png, outputs[0]];
|
|
17
|
+
const labels = scales.map((_s, i) => `[s${i}]`);
|
|
18
|
+
const graph = [`[0:v]split=${scales.length}${labels.join("")}`, ...scales.map((s, i) => `${labels[i]}${scale(s)}[o${i}]`)].join(";");
|
|
19
|
+
return [
|
|
20
|
+
"-y", "-v", "error", "-i", source, "-filter_complex", graph,
|
|
21
|
+
...outputs.flatMap((out, i) => ["-map", `[o${i}]`, ...png, out]),
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
export async function readFrames(sources, work, signal, opts = {}) {
|
|
25
|
+
const sizeOf = async (source) => {
|
|
10
26
|
const { width, height } = await probeMedia(source);
|
|
11
27
|
if (!width || !height)
|
|
12
28
|
throw new ScreencastError("Could not read the image size.");
|
|
13
|
-
return {
|
|
14
|
-
}
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
+
return { width, height };
|
|
30
|
+
};
|
|
31
|
+
const shared = opts.sameSize && sources[0] ? await sizeOf(sources[0]) : null;
|
|
32
|
+
const sized = await mapPool(sources, async (source) => ({ source, ...(shared ?? (await sizeOf(source))) }));
|
|
33
|
+
const perFrame = await mapPool(sized, async ({ source, width, height }, f) => {
|
|
34
|
+
const scales = passScales(width, height);
|
|
35
|
+
const outs = scales.map((_s, i) => join(work, `pass${f}-${i}.png`));
|
|
36
|
+
await runFfmpeg(buildOcrPassArgs(source, scales, outs), 60_000, { signal });
|
|
37
|
+
return scales.map((scale, i) => ({ out: outs[i], scale, f }));
|
|
38
|
+
});
|
|
39
|
+
const flat = perFrame.flat();
|
|
40
|
+
const passes = flat.map((p) => p.out);
|
|
41
|
+
const passScaleList = flat.map((p) => p.scale);
|
|
42
|
+
const owner = flat.map((p) => p.f);
|
|
29
43
|
const results = await recognize(passes, passScaleList);
|
|
30
44
|
return sized.map(({ width, height }, f) => ({
|
|
31
45
|
lines: mergePasses(results.filter((_r, i) => owner[i] === f)),
|
|
@@ -45,7 +59,7 @@ export async function scanVideoFrames(input, opts, work, signal) {
|
|
|
45
59
|
const step = 1 / plan.fps;
|
|
46
60
|
const timeAt = (i) => Math.round(i * step * 1000) / 1000;
|
|
47
61
|
const end = length ?? timeAt(paths.length - 1) + step;
|
|
48
|
-
const read = await readFrames(paths, work, signal);
|
|
62
|
+
const read = await readFrames(paths, work, signal, { sameSize: true });
|
|
49
63
|
return {
|
|
50
64
|
frames: read.map((frame, i) => ({ ...frame, t: timeAt(i), path: paths[i] ?? "" })),
|
|
51
65
|
step,
|
package/dist/utils/paths.js
CHANGED
|
@@ -30,6 +30,9 @@ export function sequencePattern(dir, name) {
|
|
|
30
30
|
return join(dir.replace(/%/g, "%%"), name);
|
|
31
31
|
}
|
|
32
32
|
const STILL_IMAGE = /\.(png|jpe?g|bmp|tiff?)$/i;
|
|
33
|
+
export function isStillImage(path) {
|
|
34
|
+
return STILL_IMAGE.test(path);
|
|
35
|
+
}
|
|
33
36
|
export function stillOutput(output) {
|
|
34
37
|
return STILL_IMAGE.test(output) ? ["-update", "1", output] : [output];
|
|
35
38
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { availableParallelism } from "node:os";
|
|
2
|
+
export function frameConcurrency(cores = availableParallelism()) {
|
|
3
|
+
return Math.min(4, Math.max(2, Math.floor(cores / 4)));
|
|
4
|
+
}
|
|
5
|
+
export async function mapPool(items, fn, limit = frameConcurrency()) {
|
|
6
|
+
const results = new Array(items.length);
|
|
7
|
+
let next = 0;
|
|
8
|
+
let failed = false;
|
|
9
|
+
let error;
|
|
10
|
+
const worker = async () => {
|
|
11
|
+
while (!failed && next < items.length) {
|
|
12
|
+
const i = next++;
|
|
13
|
+
try {
|
|
14
|
+
results[i] = await fn(items[i], i);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
if (!failed) {
|
|
18
|
+
failed = true;
|
|
19
|
+
error = err;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const n = Math.max(1, Math.min(Math.floor(limit), items.length));
|
|
25
|
+
await Promise.all(Array.from({ length: n }, worker));
|
|
26
|
+
if (failed)
|
|
27
|
+
throw error;
|
|
28
|
+
return results;
|
|
29
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { markersPath } from "./chapters.js";
|
|
3
|
+
import { eventPaths } from "./events.js";
|
|
4
|
+
import { partsDir, webcamOutputPath } from "./pause.js";
|
|
5
|
+
import { allowedOutputDirs, assertLocalPath, homeRoot, isWithin } from "./paths.js";
|
|
6
|
+
import { ScreencastError } from "./errors.js";
|
|
7
|
+
import { defaultTranscriptPath, fallbackIndexPath, indexSidecarPath } from "./recordingIndex.js";
|
|
8
|
+
import { wgcStopFile } from "./wgc.js";
|
|
9
|
+
export function recordingSidecars(video, siblings, editsDir) {
|
|
10
|
+
const events = eventPaths(video);
|
|
11
|
+
const transcript = defaultTranscriptPath(video, siblings);
|
|
12
|
+
const files = [
|
|
13
|
+
events.jsonl,
|
|
14
|
+
events.raw,
|
|
15
|
+
`${events.raw}.stop`,
|
|
16
|
+
webcamOutputPath(video),
|
|
17
|
+
indexSidecarPath(video),
|
|
18
|
+
fallbackIndexPath(video, editsDir),
|
|
19
|
+
markersPath(video),
|
|
20
|
+
wgcStopFile(video),
|
|
21
|
+
...(transcript.path && !transcript.ambiguous ? [transcript.path] : []),
|
|
22
|
+
];
|
|
23
|
+
return { files: [...new Set(files)].filter((f) => basename(f) !== basename(video)), dirs: [partsDir(video)] };
|
|
24
|
+
}
|
|
25
|
+
export function assertDeleteAllowed(path) {
|
|
26
|
+
assertLocalPath(path, "Recording");
|
|
27
|
+
const dirs = [homeRoot(), ...(allowedOutputDirs() ?? [])];
|
|
28
|
+
if (dirs.some((d) => isWithin(path, d)))
|
|
29
|
+
return;
|
|
30
|
+
throw new ScreencastError(`Recording ${path} is outside SCREENCAST_HOME and the allowed directories, so it is not deleted. ` +
|
|
31
|
+
"Add its folder to SCREENCAST_ALLOWED_DIRS or the client's workspace roots, or delete it yourself.");
|
|
32
|
+
}
|
package/dist/utils/replay.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createReadStream, createWriteStream, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { pipeline } from "node:stream/promises";
|
|
2
4
|
import { join } from "node:path";
|
|
3
5
|
import { errorMessage, ScreencastError } from "./errors.js";
|
|
4
6
|
import { runCapture } from "./ffmpeg.js";
|
|
@@ -103,24 +105,14 @@ export function sliceEvents(events, from, to) {
|
|
|
103
105
|
return selectEvents(events, { from, to }).map((e) => ({ ...e, t: round3(e.t - from) }));
|
|
104
106
|
}
|
|
105
107
|
const round3 = (n) => Math.round(n * 1000) / 1000;
|
|
106
|
-
function copyShared(src, dst) {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
let read = 0;
|
|
112
|
-
while (read < size) {
|
|
113
|
-
const n = readSync(fd, buf, read, size - read, read);
|
|
114
|
-
if (n === 0)
|
|
115
|
-
break;
|
|
116
|
-
read += n;
|
|
117
|
-
}
|
|
118
|
-
writeFileSync(dst, buf.subarray(0, read));
|
|
119
|
-
return read;
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
closeSync(fd);
|
|
108
|
+
export async function copyShared(src, dst, signal) {
|
|
109
|
+
const size = (await stat(src)).size;
|
|
110
|
+
if (size === 0) {
|
|
111
|
+
await writeFile(dst, "");
|
|
112
|
+
return 0;
|
|
123
113
|
}
|
|
114
|
+
await pipeline(createReadStream(src, { start: 0, end: size - 1 }), createWriteStream(dst), { signal });
|
|
115
|
+
return (await stat(dst)).size;
|
|
124
116
|
}
|
|
125
117
|
async function probeStart(ffprobe, path, signal) {
|
|
126
118
|
const res = await runCapture(ffprobe, ["-v", "error", "-show_entries", "format=start_time", "-of", "csv=p=0", path], 15_000, { signal });
|
|
@@ -136,16 +128,17 @@ export async function saveReplay(buf, opts) {
|
|
|
136
128
|
const picked = pickSegments(entries, opts.lastSec);
|
|
137
129
|
const snap = mkdtempSync(join(buf.dir, "save-"));
|
|
138
130
|
try {
|
|
139
|
-
const files =
|
|
131
|
+
const files = [];
|
|
132
|
+
for (const [i, e] of picked.entries()) {
|
|
140
133
|
const dst = join(snap, `${String(i).padStart(5, "0")}.ts`);
|
|
141
|
-
copyShared(join(buf.dir, e.file), dst);
|
|
142
|
-
|
|
143
|
-
}
|
|
134
|
+
await copyShared(join(buf.dir, e.file), dst, opts.signal);
|
|
135
|
+
files.push(dst);
|
|
136
|
+
}
|
|
144
137
|
let includesLive = false;
|
|
145
138
|
if (opts.live !== false) {
|
|
146
139
|
const src = join(buf.dir, liveSegmentFile(entries, buf.wrap));
|
|
147
140
|
const dst = join(snap, "live.ts");
|
|
148
|
-
if (existsSync(src) && copyShared(src, dst) > 0) {
|
|
141
|
+
if (existsSync(src) && (await copyShared(src, dst, opts.signal)) > 0) {
|
|
149
142
|
const newest = files.at(-1);
|
|
150
143
|
const [liveStart, lastStart] = await Promise.all([
|
|
151
144
|
probeStart(opts.ffprobe, dst, opts.signal),
|
package/dist/utils/sessions.js
CHANGED
|
@@ -259,6 +259,7 @@ export class SessionStore {
|
|
|
259
259
|
lockWaitMs;
|
|
260
260
|
records = new Map();
|
|
261
261
|
pending = new Map();
|
|
262
|
+
removed = new Set();
|
|
262
263
|
seen = null;
|
|
263
264
|
children = new Map();
|
|
264
265
|
stopping = new Set();
|
|
@@ -305,6 +306,8 @@ export class SessionStore {
|
|
|
305
306
|
if (base)
|
|
306
307
|
disk.set(id, { ...base, ...patch });
|
|
307
308
|
}
|
|
309
|
+
for (const id of this.removed)
|
|
310
|
+
disk.delete(id);
|
|
308
311
|
return disk;
|
|
309
312
|
}
|
|
310
313
|
refresh() {
|
|
@@ -346,6 +349,7 @@ export class SessionStore {
|
|
|
346
349
|
this.seen = this.signature();
|
|
347
350
|
this.records = new Map(pruned.map((r) => [r.id, r]));
|
|
348
351
|
this.pending.clear();
|
|
352
|
+
this.removed.clear();
|
|
349
353
|
}, this.lockWaitMs);
|
|
350
354
|
for (const cb of this.listeners) {
|
|
351
355
|
try {
|
|
@@ -367,6 +371,27 @@ export class SessionStore {
|
|
|
367
371
|
throw err;
|
|
368
372
|
}
|
|
369
373
|
}
|
|
374
|
+
remove(ids) {
|
|
375
|
+
const before = ids.flatMap((id) => {
|
|
376
|
+
const r = this.records.get(id);
|
|
377
|
+
return r ? [r] : [];
|
|
378
|
+
});
|
|
379
|
+
for (const id of ids) {
|
|
380
|
+
this.removed.add(id);
|
|
381
|
+
this.pending.delete(id);
|
|
382
|
+
this.records.delete(id);
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
this.persist();
|
|
386
|
+
}
|
|
387
|
+
catch (err) {
|
|
388
|
+
for (const id of ids)
|
|
389
|
+
this.removed.delete(id);
|
|
390
|
+
for (const r of before)
|
|
391
|
+
this.records.set(r.id, r);
|
|
392
|
+
throw err;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
370
395
|
get(id) {
|
|
371
396
|
this.refresh();
|
|
372
397
|
return this.records.get(id);
|
package/dist/utils/toolSpec.js
CHANGED
|
@@ -17,6 +17,12 @@ export const STOPS_SESSION = {
|
|
|
17
17
|
idempotentHint: true,
|
|
18
18
|
openWorldHint: false,
|
|
19
19
|
};
|
|
20
|
+
export const DELETES_FILE = {
|
|
21
|
+
readOnlyHint: false,
|
|
22
|
+
destructiveHint: true,
|
|
23
|
+
idempotentHint: true,
|
|
24
|
+
openWorldHint: false,
|
|
25
|
+
};
|
|
20
26
|
export function looseOutput(shape) {
|
|
21
27
|
return z.looseObject(shape);
|
|
22
28
|
}
|
package/dist/utils/toolsets.js
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { diffFrames, SettleTracker } from "./diff.js";
|
|
2
|
+
const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
3
|
+
export async function waitLoop(o) {
|
|
4
|
+
const now = o.now ?? Date.now;
|
|
5
|
+
const sleep = o.sleep ?? defaultSleep;
|
|
6
|
+
const startedAt = now();
|
|
7
|
+
const baseline = await o.grab();
|
|
8
|
+
const settle = new SettleTracker(baseline, o.width, o.height, o.diff);
|
|
9
|
+
let lastChangeAt = startedAt;
|
|
10
|
+
let everChanged = false;
|
|
11
|
+
let regions = [];
|
|
12
|
+
let outcome = "timeout";
|
|
13
|
+
while (now() - startedAt < o.timeoutMs) {
|
|
14
|
+
if (o.signal.aborted) {
|
|
15
|
+
outcome = "cancelled";
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
await sleep(o.intervalMs);
|
|
19
|
+
const current = await o.grab().catch((error) => {
|
|
20
|
+
if (o.signal.aborted)
|
|
21
|
+
return null;
|
|
22
|
+
throw error;
|
|
23
|
+
});
|
|
24
|
+
if (!current) {
|
|
25
|
+
outcome = "cancelled";
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
if (o.mode === "change") {
|
|
29
|
+
const d = diffFrames(baseline, current, o.width, o.height, o.diff);
|
|
30
|
+
if (d.regions.length > 0) {
|
|
31
|
+
regions = d.regions;
|
|
32
|
+
outcome = "changed";
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const changed = settle.push(current);
|
|
38
|
+
if (changed.length > 0) {
|
|
39
|
+
everChanged = true;
|
|
40
|
+
lastChangeAt = now();
|
|
41
|
+
regions = changed;
|
|
42
|
+
}
|
|
43
|
+
else if (now() - lastChangeAt >= o.settleMs) {
|
|
44
|
+
outcome = "settled";
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { outcome, regions, everChanged, startedAt };
|
|
50
|
+
}
|
package/package.json
CHANGED