@tmhs/screencast-mcp 0.49.1 → 0.50.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.
Files changed (134) hide show
  1. package/README.md +13 -8
  2. package/dist/index.js +550 -106
  3. package/dist/wgcRecorder.js +15 -139
  4. package/package.json +8 -4
  5. package/assets/.gitkeep +0 -0
  6. package/assets/icon.png +0 -0
  7. package/dist/cli.js +0 -516
  8. package/dist/context.js +0 -50
  9. package/dist/prompts.js +0 -95
  10. package/dist/resources.js +0 -93
  11. package/dist/server.js +0 -174
  12. package/dist/setup.js +0 -438
  13. package/dist/tools/addMarker.js +0 -93
  14. package/dist/tools/assembleHighlights.js +0 -69
  15. package/dist/tools/backdrop.js +0 -79
  16. package/dist/tools/bugReport.js +0 -243
  17. package/dist/tools/burnSubtitles.js +0 -56
  18. package/dist/tools/callout.js +0 -62
  19. package/dist/tools/chapters.js +0 -156
  20. package/dist/tools/clip.js +0 -52
  21. package/dist/tools/compress.js +0 -51
  22. package/dist/tools/concat.js +0 -67
  23. package/dist/tools/contactSheet.js +0 -113
  24. package/dist/tools/convert.js +0 -46
  25. package/dist/tools/crop.js +0 -43
  26. package/dist/tools/cursor.js +0 -67
  27. package/dist/tools/cutByTranscript.js +0 -86
  28. package/dist/tools/cutIdle.js +0 -84
  29. package/dist/tools/deleteRecording.js +0 -119
  30. package/dist/tools/denoise.js +0 -60
  31. package/dist/tools/doctor.js +0 -146
  32. package/dist/tools/exportGif.js +0 -57
  33. package/dist/tools/exportPreset.js +0 -48
  34. package/dist/tools/extractAudio.js +0 -65
  35. package/dist/tools/findText.js +0 -194
  36. package/dist/tools/getMediaInfo.js +0 -36
  37. package/dist/tools/getSession.js +0 -40
  38. package/dist/tools/indexRecording.js +0 -195
  39. package/dist/tools/keystrokeOverlay.js +0 -90
  40. package/dist/tools/listAudioDevices.js +0 -35
  41. package/dist/tools/listSessions.js +0 -28
  42. package/dist/tools/listTargets.js +0 -76
  43. package/dist/tools/listVideoDevices.js +0 -26
  44. package/dist/tools/musicBed.js +0 -55
  45. package/dist/tools/narrate.js +0 -86
  46. package/dist/tools/normalizeAudio.js +0 -59
  47. package/dist/tools/overlay.js +0 -62
  48. package/dist/tools/pauseRecording.js +0 -44
  49. package/dist/tools/pipeline.js +0 -397
  50. package/dist/tools/readEvents.js +0 -98
  51. package/dist/tools/redactRegion.js +0 -62
  52. package/dist/tools/reframe.js +0 -46
  53. package/dist/tools/resumeRecording.js +0 -46
  54. package/dist/tools/reviewRecording.js +0 -163
  55. package/dist/tools/sampleFrames.js +0 -200
  56. package/dist/tools/saveReplay.js +0 -90
  57. package/dist/tools/scale.js +0 -44
  58. package/dist/tools/screenDiff.js +0 -86
  59. package/dist/tools/screenshot.js +0 -76
  60. package/dist/tools/searchRecording.js +0 -79
  61. package/dist/tools/speed.js +0 -46
  62. package/dist/tools/startRecording.js +0 -398
  63. package/dist/tools/stepGuide.js +0 -249
  64. package/dist/tools/stopRecording.js +0 -132
  65. package/dist/tools/titleCard.js +0 -67
  66. package/dist/tools/transcribe.js +0 -66
  67. package/dist/tools/trim.js +0 -57
  68. package/dist/tools/waitForChange.js +0 -142
  69. package/dist/tools/xfadeTransition.js +0 -58
  70. package/dist/tools/zoom.js +0 -134
  71. package/dist/utils/anim.js +0 -54
  72. package/dist/utils/animExport.js +0 -56
  73. package/dist/utils/argPaths.js +0 -39
  74. package/dist/utils/audio.js +0 -117
  75. package/dist/utils/audioDevices.js +0 -107
  76. package/dist/utils/backdrop.js +0 -162
  77. package/dist/utils/bugReport.js +0 -195
  78. package/dist/utils/callout.js +0 -132
  79. package/dist/utils/calloutAssets.js +0 -42
  80. package/dist/utils/capabilities.js +0 -96
  81. package/dist/utils/captions.js +0 -104
  82. package/dist/utils/chapters.js +0 -227
  83. package/dist/utils/consent.js +0 -29
  84. package/dist/utils/cursor.js +0 -338
  85. package/dist/utils/diff.js +0 -186
  86. package/dist/utils/errors.js +0 -29
  87. package/dist/utils/events.js +0 -403
  88. package/dist/utils/expr.js +0 -11
  89. package/dist/utils/ffmpeg.js +0 -285
  90. package/dist/utils/fontCoverage.js +0 -177
  91. package/dist/utils/fonts.js +0 -154
  92. package/dist/utils/frameQueue.js +0 -50
  93. package/dist/utils/gpu.js +0 -219
  94. package/dist/utils/idle.js +0 -91
  95. package/dist/utils/images.js +0 -38
  96. package/dist/utils/jobs.js +0 -129
  97. package/dist/utils/keystrokes.js +0 -198
  98. package/dist/utils/lifecycle.js +0 -233
  99. package/dist/utils/logging.js +0 -75
  100. package/dist/utils/media.js +0 -584
  101. package/dist/utils/monitors.js +0 -124
  102. package/dist/utils/narrate.js +0 -233
  103. package/dist/utils/ocr.js +0 -222
  104. package/dist/utils/ocrScan.js +0 -93
  105. package/dist/utils/paths.js +0 -155
  106. package/dist/utils/pause.js +0 -190
  107. package/dist/utils/pipeline.js +0 -361
  108. package/dist/utils/player.js +0 -85
  109. package/dist/utils/pool.js +0 -29
  110. package/dist/utils/produce.js +0 -300
  111. package/dist/utils/recipes.js +0 -71
  112. package/dist/utils/recorder.js +0 -173
  113. package/dist/utils/recordingFiles.js +0 -32
  114. package/dist/utils/recordingIndex.js +0 -312
  115. package/dist/utils/replay.js +0 -283
  116. package/dist/utils/resolveTarget.js +0 -25
  117. package/dist/utils/retention.js +0 -48
  118. package/dist/utils/roots.js +0 -43
  119. package/dist/utils/sessions.js +0 -499
  120. package/dist/utils/sheet.js +0 -82
  121. package/dist/utils/stepGuide.js +0 -231
  122. package/dist/utils/steps.js +0 -88
  123. package/dist/utils/still.js +0 -38
  124. package/dist/utils/targetList.js +0 -64
  125. package/dist/utils/targets.js +0 -265
  126. package/dist/utils/timeline.js +0 -85
  127. package/dist/utils/toolSpec.js +0 -31
  128. package/dist/utils/toolsets.js +0 -134
  129. package/dist/utils/transcriptCut.js +0 -149
  130. package/dist/utils/validate.js +0 -23
  131. package/dist/utils/waitLoop.js +0 -50
  132. package/dist/utils/wgc.js +0 -84
  133. package/dist/utils/windows.js +0 -192
  134. package/dist/utils/zoom.js +0 -252
@@ -1,67 +0,0 @@
1
- import { z } from "zod";
2
- import { extname, resolve } from "node:path";
3
- import { existsSync, writeFileSync, rmSync } from "node:fs";
4
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
5
- import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
6
- import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
7
- import { runEditJob } from "../utils/jobs.js";
8
- import { buildConcatArgs, buildConcatListContent, concatCopyBlocker, editOutputExt, assertEditContainer, } from "../utils/media.js";
9
- import { buildAssembleArgs, clipLength } from "../utils/produce.js";
10
- import { resolveOutput, subdir, stamp, rand, tempPath } from "../utils/paths.js";
11
- const inputSchema = {
12
- inputs: z
13
- .array(z.string().min(1))
14
- .min(2)
15
- .describe("Video paths to join, in order."),
16
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
17
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
18
- };
19
- export function register(server) {
20
- server.registerTool("concat", {
21
- title: "Concatenate Videos",
22
- description: "Join videos end to end with hard cuts: stream copy when they match, else a re-encode (`mode` " +
23
- "says which). For transitions use xfade_transition or assemble_highlights.",
24
- inputSchema,
25
- outputSchema: OUTPUT_PATH,
26
- annotations: WRITES_FILE,
27
- }, async (args, extra) => {
28
- try {
29
- requireFfmpeg();
30
- const inputs = args.inputs.map((f) => resolve(f));
31
- for (const f of inputs) {
32
- if (!existsSync(f))
33
- throw new ScreencastError(`Input file not found: ${f}`);
34
- }
35
- const infos = await Promise.all(inputs.map((f) => probeMedia(f)));
36
- const [firstInput] = inputs;
37
- const [first] = infos;
38
- if (firstInput === undefined || first === undefined)
39
- throw new ScreencastError("concat needs at least two inputs.");
40
- const durations = infos.map((i) => clipLength(i));
41
- const durationSec = durations.every((d) => d !== null) ? durations.reduce((a, d) => a + d, 0) : null;
42
- const reason = concatCopyBlocker(inputs, infos);
43
- if (reason !== null) {
44
- assertEditContainer(args.output);
45
- const output = resolveOutput(args.output, subdir("edits"), `concat-${stamp()}-${rand()}${editOutputExt(firstInput)}`, args.overwrite);
46
- const even = (n) => (n !== null && n >= 2 ? n - (n % 2) : undefined);
47
- const ffArgs = buildAssembleArgs(inputs, durations.map((d) => d ?? 0), output, { transition: "cut", width: even(first.width), height: even(first.height), fps: first.fps ?? undefined }, infos.map((i) => i.audioCodec !== null));
48
- await runEditJob(ffArgs, { output, durationSec, extra });
49
- return okResponse({ outputPath: output, inputCount: inputs.length, mode: "reencode", reason });
50
- }
51
- const ext = extname(firstInput) || ".mp4";
52
- const output = resolveOutput(args.output, subdir("edits"), `concat-${stamp()}-${rand()}${ext}`, args.overwrite);
53
- const listFile = tempPath(".txt");
54
- writeFileSync(listFile, buildConcatListContent(inputs));
55
- try {
56
- await runEditJob(buildConcatArgs(listFile, output), { output, durationSec, extra });
57
- }
58
- finally {
59
- rmSync(listFile, { force: true });
60
- }
61
- return okResponse({ outputPath: output, inputCount: inputs.length, mode: "copy" });
62
- }
63
- catch (error) {
64
- return errorResponse(error);
65
- }
66
- });
67
- }
@@ -1,113 +0,0 @@
1
- import { z } from "zod";
2
- import { existsSync } from "node:fs";
3
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
- import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
5
- import { requireFfmpeg, runFfmpeg, runCapture, probeMedia } from "../utils/ffmpeg.js";
6
- import { jobTimeoutMs } from "../utils/jobs.js";
7
- import { buildSceneScanArgs, parseSceneScan, pickSceneFrames, DEFAULT_SCENE_THRESHOLD, } from "../utils/media.js";
8
- import { evenTimes, buildPosterArgs, DEFAULT_SHEET_COUNT, MAX_SHEET_COUNT, DEFAULT_TILE_WIDTH, renderContactSheet, } from "../utils/sheet.js";
9
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
10
- import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
11
- const inputSchema = {
12
- input: z.string().min(1).describe("Path to the source video."),
13
- count: z
14
- .number()
15
- .int()
16
- .min(1)
17
- .max(MAX_SHEET_COUNT)
18
- .optional()
19
- .describe(`Frames to tile (default ${DEFAULT_SHEET_COUNT}).`),
20
- mode: z
21
- .enum(["even", "scenes"])
22
- .optional()
23
- .describe("even (default) or scenes (strongest changes; static stretches take no tiles)."),
24
- sceneThreshold: z
25
- .number()
26
- .gt(0)
27
- .lt(1)
28
- .optional()
29
- .describe(`Mode scenes: change needed, 0-1 (default ${DEFAULT_SCENE_THRESHOLD}).`),
30
- columns: z.number().int().min(1).max(12).optional().describe("Tiles per row (default: roughly square)."),
31
- tileWidth: z
32
- .number()
33
- .int()
34
- .min(64)
35
- .max(1920)
36
- .optional()
37
- .describe(`Tile width in px (default ${DEFAULT_TILE_WIDTH}).`),
38
- poster: z
39
- .boolean()
40
- .optional()
41
- .describe("Write one representative poster frame instead of a sheet."),
42
- output: z.string().optional().describe("Optional output .png path. Defaults under SCREENCAST_HOME/frames."),
43
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
44
- returnImage: z
45
- .boolean()
46
- .optional()
47
- .describe("Return the sheet inline (default true)."),
48
- maxImageWidth: z
49
- .number()
50
- .int()
51
- .min(16)
52
- .optional()
53
- .describe(`Max inline image width (default ${DEFAULT_MAX_IMAGE_WIDTH}).`),
54
- };
55
- export function register(server) {
56
- server.registerTool("contact_sheet", {
57
- title: "Contact Sheet",
58
- description: "Tile timestamped frames of a video into one image to see a whole recording at a glance " +
59
- "(the cheapest first look).",
60
- inputSchema,
61
- outputSchema: looseOutput({ outputPath: z.string(), inlineImages: z.number().int() }),
62
- annotations: WRITES_FILE,
63
- }, async (args, extra) => {
64
- try {
65
- const { ffmpeg } = requireFfmpeg();
66
- if (!existsSync(args.input)) {
67
- throw new ScreencastError(`Input file not found: ${args.input}`);
68
- }
69
- const { durationSec } = await probeMedia(args.input);
70
- if (durationSec === null)
71
- throw new ScreencastError(`Could not read duration of ${args.input}.`);
72
- const kind = args.poster ? "poster" : "sheet";
73
- const output = resolveOutput(args.output, subdir("frames"), `${kind}-${stamp()}-${rand()}.png`, args.overwrite);
74
- const tileWidth = args.tileWidth ?? DEFAULT_TILE_WIDTH;
75
- let result;
76
- if (args.poster) {
77
- await runFfmpeg(buildPosterArgs(args.input, durationSec, output, Math.max(tileWidth, 1280)), jobTimeoutMs(durationSec), {
78
- signal: extra.signal,
79
- });
80
- result = { outputPath: output, poster: true };
81
- }
82
- else {
83
- const count = args.count ?? DEFAULT_SHEET_COUNT;
84
- let times;
85
- if (args.mode === "scenes") {
86
- const scan = await runCapture(ffmpeg, buildSceneScanArgs(args.input, args.sceneThreshold ?? DEFAULT_SCENE_THRESHOLD), jobTimeoutMs(durationSec), { signal: extra.signal });
87
- if (scan.code !== 0) {
88
- throw new ScreencastError(`Scene scan failed (exit ${scan.code}): ${scan.stderr.trim().slice(-400)}`);
89
- }
90
- times = pickSceneFrames(parseSceneScan(scan.stdout), count);
91
- }
92
- else {
93
- times = evenTimes(durationSec, count);
94
- }
95
- const grid = await renderContactSheet(args.input, times, output, { tileWidth, columns: args.columns }, extra.signal);
96
- result = {
97
- outputPath: output,
98
- mode: args.mode ?? "even",
99
- frameTimes: times,
100
- columns: grid.columns,
101
- rows: grid.rows,
102
- };
103
- }
104
- const images = args.returnImage === false
105
- ? []
106
- : (await encodeInlineImages([output], args.maxImageWidth ?? DEFAULT_MAX_IMAGE_WIDTH, 1)).images;
107
- return okResponse({ ...result, inlineImages: images.length }, images);
108
- }
109
- catch (error) {
110
- return errorResponse(error);
111
- }
112
- });
113
- }
@@ -1,46 +0,0 @@
1
- import { z } from "zod";
2
- import { existsSync } from "node:fs";
3
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
- import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
5
- import { requireFfmpeg } from "../utils/ffmpeg.js";
6
- import { runEditJob, probeDuration } from "../utils/jobs.js";
7
- import { buildConvertArgs } from "../utils/media.js";
8
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
9
- const inputSchema = {
10
- input: z.string().min(1).describe("Path to the source media."),
11
- format: z
12
- .enum(["mp4", "gif", "webm"])
13
- .describe("mp4 (H.264), webm (VP9), or gif (palette)."),
14
- fps: z.number().positive().optional().describe("gif only: fps (default 12)."),
15
- width: z.number().positive().optional().describe("gif only: width in px (default 720)."),
16
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
17
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
18
- };
19
- export function register(server) {
20
- server.registerTool("convert", {
21
- title: "Convert Format",
22
- description: "Convert media to mp4, webm, or gif. For a size-bounded GIF/WebP prefer export_gif; for a " +
23
- "smaller mp4, compress or export_preset.",
24
- inputSchema,
25
- outputSchema: OUTPUT_PATH,
26
- annotations: WRITES_FILE,
27
- }, async (args, extra) => {
28
- try {
29
- requireFfmpeg();
30
- if (!existsSync(args.input)) {
31
- throw new ScreencastError(`Input file not found: ${args.input}`);
32
- }
33
- const format = args.format;
34
- const output = resolveOutput(args.output, subdir("edits"), `convert-${stamp()}-${rand()}.${format}`, args.overwrite);
35
- const ffArgs = buildConvertArgs(args.input, output, format, {
36
- fps: args.fps,
37
- width: args.width,
38
- });
39
- await runEditJob(ffArgs, { output, durationSec: await probeDuration(args.input), extra });
40
- return okResponse({ outputPath: output, format });
41
- }
42
- catch (error) {
43
- return errorResponse(error);
44
- }
45
- });
46
- }
@@ -1,43 +0,0 @@
1
- import { z } from "zod";
2
- import { existsSync } from "node:fs";
3
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
- import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
5
- import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
6
- import { runEditJob } from "../utils/jobs.js";
7
- import { buildCropArgs, editOutputExt, assertEditContainer } from "../utils/media.js";
8
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
9
- const inputSchema = {
10
- input: z.string().min(1).describe("Path to the source video."),
11
- x: z.number().int().nonnegative(),
12
- y: z.number().int().nonnegative(),
13
- width: z.number().int().positive(),
14
- height: z.number().int().positive(),
15
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
16
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
17
- };
18
- export function register(server) {
19
- server.registerTool("crop", {
20
- title: "Crop Video",
21
- description: "Crop a video to a pixel rectangle; one running off the frame is rejected.",
22
- inputSchema,
23
- outputSchema: OUTPUT_PATH,
24
- annotations: WRITES_FILE,
25
- }, async (args, extra) => {
26
- try {
27
- requireFfmpeg();
28
- if (!existsSync(args.input)) {
29
- throw new ScreencastError(`Input file not found: ${args.input}`);
30
- }
31
- const { width, height, durationSec } = await probeMedia(args.input);
32
- assertEditContainer(args.output);
33
- const ext = editOutputExt(args.input);
34
- const output = resolveOutput(args.output, subdir("edits"), `crop-${stamp()}-${rand()}${ext}`, args.overwrite);
35
- const ffArgs = buildCropArgs(args.input, output, { x: args.x, y: args.y, width: args.width, height: args.height }, { width, height });
36
- await runEditJob(ffArgs, { output, durationSec, extra });
37
- return okResponse({ outputPath: output });
38
- }
39
- catch (error) {
40
- return errorResponse(error);
41
- }
42
- });
43
- }
@@ -1,67 +0,0 @@
1
- import { z } from "zod";
2
- import { join } from "node:path";
3
- import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
6
- import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
7
- import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
8
- import { runEditJob } from "../utils/jobs.js";
9
- import { buildCursorArgs, cursorSpritePath, transformCursor, DEFAULT_CURSOR_SIZE, DEFAULT_HIDE_AFTER_SEC, cursorOptionsSchema, loadCursor, } from "../utils/cursor.js";
10
- import { editOutputExt, assertEditContainer } from "../utils/media.js";
11
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
12
- const o = cursorOptionsSchema;
13
- const inputSchema = {
14
- input: z.string().min(1).describe("Path to the recording."),
15
- events: o.events.describe("Event log (default: the input's .events.jsonl)."),
16
- size: o.size.describe(`Times a typical cursor's size (default ${DEFAULT_CURSOR_SIZE}).`),
17
- smoothing: o.smoothing.describe("0 = as logged, 1 = floaty (default 0.5)."),
18
- hideAfterSec: o.hideAfterSec.describe(`Hide when the mouse rests this long; 0 = never (default ${DEFAULT_HIDE_AFTER_SEC}).`),
19
- clicks: o.clicks.describe("Ripple on clicks (default true)."),
20
- spotlight: o.spotlight.describe("Dim all but the area around the cursor."),
21
- dryRun: z.boolean().optional().describe("Return the plan; write nothing."),
22
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
23
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
24
- };
25
- export function register(server) {
26
- server.registerTool("cursor", {
27
- title: "Re-rendered Cursor",
28
- description: 'Draw a smoothed, scaled cursor that hides when idle from the event log of a start_recording cursor: "events" ' +
29
- "recording (no OS cursor in the video), with click ripples and an optional spotlight.",
30
- inputSchema,
31
- outputSchema: looseOutput({ segments: z.number().int() }),
32
- annotations: WRITES_FILE,
33
- }, async (args, extra) => {
34
- try {
35
- requireFfmpeg();
36
- if (!existsSync(args.input))
37
- throw new ScreencastError(`Input file not found: ${args.input}`);
38
- const info = await probeMedia(args.input);
39
- if (!info.width || !info.height)
40
- throw new ScreencastError(`Could not read the size of ${args.input}.`);
41
- const plan = transformCursor(loadCursor(args.input, args.events, args, info.durationSec));
42
- const summary = {
43
- segments: plan.path.length,
44
- clicks: plan.clicks.length,
45
- shownSec: Math.round(plan.visible.reduce((s, [a, b]) => s + (Math.min(b, info.durationSec ?? b) - a), 0) * 10) / 10,
46
- };
47
- if (args.dryRun)
48
- return okResponse({ dryRun: true, ...summary, visible: plan.visible });
49
- assertEditContainer(args.output);
50
- const output = resolveOutput(args.output, subdir("edits"), `cursor-${stamp()}-${rand()}${editOutputExt(args.input)}`, args.overwrite);
51
- const work = mkdtempSync(join(tmpdir(), "screencast-cursor-"));
52
- try {
53
- const cmdFile = join(work, "cursor.cmd");
54
- const { args: ffArgs, commands } = buildCursorArgs(args.input, output, plan, { size: args.size, clicks: args.clicks, spotlight: args.spotlight }, { width: info.width, height: info.height }, cursorSpritePath(), cmdFile);
55
- writeFileSync(cmdFile, commands);
56
- await runEditJob(ffArgs, { output, durationSec: info.durationSec, extra });
57
- return okResponse({ outputPath: output, ...summary });
58
- }
59
- finally {
60
- rmSync(work, { recursive: true, force: true });
61
- }
62
- }
63
- catch (error) {
64
- return errorResponse(error);
65
- }
66
- });
67
- }
@@ -1,86 +0,0 @@
1
- import { z } from "zod";
2
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
- import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
5
- import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
6
- import { runEditJob } from "../utils/jobs.js";
7
- import { parseSrt, normalizeCues, formatSrt } from "../utils/captions.js";
8
- import { buildCutIdleArgs, MAX_CUTS } from "../utils/idle.js";
9
- import { planTranscriptCuts, retimeCues } from "../utils/transcriptCut.js";
10
- import { editOutputExt, assertEditContainer } from "../utils/media.js";
11
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
12
- const inputSchema = {
13
- input: z.string().min(1).describe("Path to the source video."),
14
- srt: z.string().min(1).describe("Its .srt (transcribe; words: true for word timing)."),
15
- remove: z
16
- .array(z.union([z.number().int().min(0).max(99999), z.string().min(1)]))
17
- .optional()
18
- .describe("Cue numbers as the .srt numbers them, or transcript text quoted exactly (must occur once)."),
19
- fillers: z.boolean().optional().describe("Also cut fillers (um, uh...) that have their own cue."),
20
- dryRun: z.boolean().optional().describe("Only report the cuts."),
21
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
22
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
23
- };
24
- export function register(server) {
25
- server.registerTool("cut_by_transcript", {
26
- title: "Cut By Transcript",
27
- description: "Edit a video by its transcript: cut quoted text, cue numbers, or fillers. Also writes the re-timed .srt.",
28
- inputSchema,
29
- outputSchema: looseOutput({ cuts: z.array(z.unknown()), removedSec: z.number() }),
30
- annotations: WRITES_FILE,
31
- }, async (args, extra) => {
32
- try {
33
- requireFfmpeg();
34
- for (const f of [args.input, args.srt])
35
- if (!existsSync(f))
36
- throw new ScreencastError(`File not found: ${f}`);
37
- if (!args.remove?.length && !args.fillers)
38
- throw new ScreencastError("Nothing to cut: pass remove and/or fillers: true.");
39
- const info = await probeMedia(args.input);
40
- const duration = info.durationSec;
41
- if (duration === null || !info.videoCodec)
42
- throw new ScreencastError(`Not a readable video: ${args.input}`);
43
- const cues = normalizeCues(parseSrt(readFileSync(args.srt, "utf8"), { index: true }));
44
- if (cues.length === 0)
45
- throw new ScreencastError(`No cues in ${args.srt}.`);
46
- const { cuts, skippedFillers } = planTranscriptCuts(cues, { remove: args.remove, fillers: args.fillers });
47
- if (cuts.length > MAX_CUTS)
48
- throw new ScreencastError(`Too many cuts (${cuts.length}, max ${MAX_CUTS}); cut in batches.`);
49
- const removedSec = Number(cuts.reduce((s, c) => s + Math.min(c.end, duration) - Math.min(c.start, duration), 0).toFixed(2));
50
- const retimed = retimeCues(cues, cuts);
51
- const notes = [
52
- cuts.length === 0 && "Nothing matched; nothing to cut.",
53
- skippedFillers > 0 && `${skippedFillers} filler(s) inside longer cues were kept; transcribe with words: true to cut them.`,
54
- cuts.some((c) => !c.exact) && "Some edges were estimated inside a cue; transcribe with words: true for word timing.",
55
- ].filter(Boolean);
56
- const summary = {
57
- cuts,
58
- removedSec,
59
- originalSec: Number(duration.toFixed(2)),
60
- newDurationSec: Number((duration - removedSec).toFixed(2)),
61
- ...(notes.length ? { note: notes.join(" ") } : {}),
62
- };
63
- if (args.dryRun || cuts.length === 0) {
64
- const text = retimed.map((c) => c.text.replace(/\n/g, " ")).join(" ");
65
- return okResponse({ ...summary, ...(cuts.length ? { dryRun: true } : {}), text: text.length > 4000 ? `${text.slice(0, 4000)}…` : text });
66
- }
67
- assertEditContainer(args.output);
68
- const ext = editOutputExt(args.input);
69
- const output = resolveOutput(args.output, subdir("edits"), `cut-transcript-${stamp()}-${rand()}${ext}`, args.overwrite);
70
- const srtPath = output.replace(/\.[^.\\/]+$/, "") + ".srt";
71
- if (!args.overwrite && existsSync(srtPath))
72
- throw new ScreencastError(`Output already exists: ${srtPath}. Pass overwrite: true to replace it.`);
73
- await runEditJob(buildCutIdleArgs(args.input, output, cuts, info.audioCodec !== null), {
74
- output,
75
- durationSec: duration - removedSec,
76
- inputDurationSec: duration,
77
- extra,
78
- });
79
- writeFileSync(srtPath, formatSrt(retimed));
80
- return okResponse({ outputPath: output, srtPath, ...summary });
81
- }
82
- catch (error) {
83
- return errorResponse(error);
84
- }
85
- });
86
- }
@@ -1,84 +0,0 @@
1
- import { z } from "zod";
2
- import { existsSync } from "node:fs";
3
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
- import { WRITES_FILE } from "../utils/toolSpec.js";
5
- import { requireFfmpeg, runCapture, probeMedia } from "../utils/ffmpeg.js";
6
- import { runEditJob, jobTimeoutMs } from "../utils/jobs.js";
7
- import { buildIdleScanArgs, parseFreezes, parseSilences, intersect, cutsFor, buildCutIdleArgs, DEFAULT_MIN_IDLE_SEC, DEFAULT_KEEP_SEC, } from "../utils/idle.js";
8
- import { editOutputExt, assertEditContainer } from "../utils/media.js";
9
- import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
10
- const inputSchema = {
11
- input: z.string().min(1).describe("Path to the source video."),
12
- minIdleSec: z
13
- .number()
14
- .positive()
15
- .optional()
16
- .describe(`Only cut still stretches at least this long (default ${DEFAULT_MIN_IDLE_SEC}).`),
17
- keepSec: z
18
- .number()
19
- .min(0)
20
- .optional()
21
- .describe(`Seconds kept at each edge of a cut (default ${DEFAULT_KEEP_SEC}).`),
22
- useAudio: z
23
- .boolean()
24
- .optional()
25
- .describe("Require silent audio too (default true when there is audio)."),
26
- dryRun: z.boolean().optional().describe("Only report what would be cut."),
27
- output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
28
- overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
29
- };
30
- export function register(server) {
31
- server.registerTool("cut_idle", {
32
- title: "Cut Idle Stretches",
33
- description: "Remove dead air: cut stretches where the screen is frozen (and silent), keeping a short pad. " +
34
- "Returns the time saved.",
35
- inputSchema,
36
- annotations: WRITES_FILE,
37
- }, async (args, extra) => {
38
- try {
39
- const { ffmpeg } = requireFfmpeg();
40
- if (!existsSync(args.input))
41
- throw new ScreencastError(`Input file not found: ${args.input}`);
42
- const info = await probeMedia(args.input);
43
- const duration = info.durationSec;
44
- if (duration === null)
45
- throw new ScreencastError(`Could not read duration of ${args.input}.`);
46
- const minIdle = args.minIdleSec ?? DEFAULT_MIN_IDLE_SEC;
47
- const keep = args.keepSec ?? DEFAULT_KEEP_SEC;
48
- const hasAudio = info.audioCodec !== null;
49
- const useAudio = (args.useAudio ?? true) && hasAudio;
50
- const scan = await runCapture(ffmpeg, buildIdleScanArgs(args.input, minIdle, useAudio), jobTimeoutMs(duration), {
51
- signal: extra.signal,
52
- });
53
- if (scan.code !== 0)
54
- throw new ScreencastError(`Idle scan failed (exit ${scan.code}): ${scan.stderr.trim().slice(-400)}`);
55
- const freezes = parseFreezes(scan.stderr, duration);
56
- const idle = useAudio ? intersect(freezes, parseSilences(scan.stderr, duration)) : freezes;
57
- const cuts = cutsFor(idle, minIdle, keep);
58
- const removedSec = Number(cuts.reduce((s, c) => s + (c.end - c.start), 0).toFixed(2));
59
- const summary = {
60
- cuts,
61
- removedSec,
62
- originalSec: Number(duration.toFixed(2)),
63
- newDurationSec: Number((duration - removedSec).toFixed(2)),
64
- idleRule: useAudio ? "frozen video and silent audio" : "frozen video",
65
- };
66
- if (args.dryRun || cuts.length === 0) {
67
- return okResponse({ ...summary, ...(cuts.length === 0 ? { note: "No idle stretches found; nothing to cut." } : { dryRun: true }) });
68
- }
69
- assertEditContainer(args.output);
70
- const ext = editOutputExt(args.input);
71
- const output = resolveOutput(args.output, subdir("edits"), `trimmed-idle-${stamp()}-${rand()}${ext}`, args.overwrite);
72
- await runEditJob(buildCutIdleArgs(args.input, output, cuts, hasAudio), {
73
- output,
74
- durationSec: duration - removedSec,
75
- inputDurationSec: duration,
76
- extra,
77
- });
78
- return okResponse({ outputPath: output, ...summary });
79
- }
80
- catch (error) {
81
- return errorResponse(error);
82
- }
83
- });
84
- }
@@ -1,119 +0,0 @@
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
- }