@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.
Files changed (344) hide show
  1. package/README.md +95 -17
  2. package/assets/icon.png +0 -0
  3. package/assets/ui/player.html +47 -302
  4. package/assets/ui/player.js +402 -0
  5. package/dist/context.js +0 -5
  6. package/dist/index.js +17 -21
  7. package/dist/prompts.js +18 -8
  8. package/dist/resources.js +2 -14
  9. package/dist/server.js +49 -11
  10. package/dist/tools/addMarker.js +89 -0
  11. package/dist/tools/assembleHighlights.js +12 -7
  12. package/dist/tools/backdrop.js +89 -0
  13. package/dist/tools/bugReport.js +266 -0
  14. package/dist/tools/burnSubtitles.js +12 -6
  15. package/dist/tools/callout.js +32 -16
  16. package/dist/tools/chapters.js +156 -0
  17. package/dist/tools/clip.js +12 -9
  18. package/dist/tools/compress.js +10 -5
  19. package/dist/tools/concat.js +16 -15
  20. package/dist/tools/contactSheet.js +39 -33
  21. package/dist/tools/convert.js +12 -6
  22. package/dist/tools/crop.js +12 -7
  23. package/dist/tools/cutIdle.js +15 -9
  24. package/dist/tools/denoise.js +12 -6
  25. package/dist/tools/doctor.js +133 -0
  26. package/dist/tools/exportGif.js +14 -10
  27. package/dist/tools/exportPreset.js +11 -8
  28. package/dist/tools/extractAudio.js +10 -8
  29. package/dist/tools/findText.js +52 -98
  30. package/dist/tools/getMediaInfo.js +17 -3
  31. package/dist/tools/getSession.js +15 -3
  32. package/dist/tools/keystrokeOverlay.js +131 -0
  33. package/dist/tools/listAudioDevices.js +14 -7
  34. package/dist/tools/listSessions.js +13 -3
  35. package/dist/tools/listTargets.js +76 -0
  36. package/dist/tools/musicBed.js +14 -10
  37. package/dist/tools/normalizeAudio.js +12 -8
  38. package/dist/tools/overlay.js +16 -12
  39. package/dist/tools/pipeline.js +86 -25
  40. package/dist/tools/readEvents.js +21 -12
  41. package/dist/tools/redactRegion.js +19 -17
  42. package/dist/tools/reframe.js +9 -5
  43. package/dist/tools/reviewRecording.js +75 -22
  44. package/dist/tools/sampleFrames.js +33 -40
  45. package/dist/tools/saveReplay.js +90 -0
  46. package/dist/tools/scale.js +9 -3
  47. package/dist/tools/screenDiff.js +23 -17
  48. package/dist/tools/screenshot.js +21 -17
  49. package/dist/tools/speed.js +15 -4
  50. package/dist/tools/startRecording.js +96 -59
  51. package/dist/tools/stopRecording.js +35 -10
  52. package/dist/tools/titleCard.js +19 -11
  53. package/dist/tools/transcribe.js +13 -7
  54. package/dist/tools/trim.js +11 -10
  55. package/dist/tools/waitForChange.js +37 -22
  56. package/dist/tools/xfadeTransition.js +12 -8
  57. package/dist/tools/zoom.js +26 -29
  58. package/dist/utils/anim.js +1 -21
  59. package/dist/utils/animExport.js +5 -10
  60. package/dist/utils/audio.js +4 -33
  61. package/dist/utils/audioDevices.js +1 -48
  62. package/dist/utils/backdrop.js +151 -0
  63. package/dist/utils/bugReport.js +246 -0
  64. package/dist/utils/callout.js +1 -19
  65. package/dist/utils/calloutAssets.js +21 -11
  66. package/dist/utils/capabilities.js +95 -0
  67. package/dist/utils/captions.js +9 -26
  68. package/dist/utils/chapters.js +222 -0
  69. package/dist/utils/consent.js +29 -0
  70. package/dist/utils/diff.js +0 -46
  71. package/dist/utils/errors.js +5 -13
  72. package/dist/utils/events.js +21 -77
  73. package/dist/utils/expr.js +11 -0
  74. package/dist/utils/ffmpeg.js +119 -48
  75. package/dist/utils/fontCoverage.js +177 -0
  76. package/dist/utils/fonts.js +139 -23
  77. package/dist/utils/idle.js +12 -24
  78. package/dist/utils/images.js +0 -17
  79. package/dist/utils/jobs.js +42 -41
  80. package/dist/utils/keystrokes.js +170 -0
  81. package/dist/utils/lifecycle.js +11 -31
  82. package/dist/utils/logging.js +75 -0
  83. package/dist/utils/media.js +16 -124
  84. package/dist/utils/monitors.js +7 -43
  85. package/dist/utils/ocr.js +53 -71
  86. package/dist/utils/ocrScan.js +77 -0
  87. package/dist/utils/paths.js +68 -31
  88. package/dist/utils/pipeline.js +39 -25
  89. package/dist/utils/player.js +50 -27
  90. package/dist/utils/produce.js +6 -66
  91. package/dist/utils/replay.js +278 -0
  92. package/dist/utils/resolveTarget.js +0 -19
  93. package/dist/utils/retention.js +1 -15
  94. package/dist/utils/roots.js +42 -0
  95. package/dist/utils/sessions.js +195 -160
  96. package/dist/utils/sheet.js +0 -19
  97. package/dist/utils/still.js +0 -15
  98. package/dist/utils/targetList.js +63 -0
  99. package/dist/utils/targets.js +5 -70
  100. package/dist/utils/toolSpec.js +25 -0
  101. package/dist/utils/toolsets.js +122 -0
  102. package/dist/utils/validate.js +0 -22
  103. package/dist/utils/wgc.js +0 -46
  104. package/dist/utils/windows.js +5 -50
  105. package/dist/utils/zoom.js +55 -85
  106. package/dist/wgcRecorder.js +1 -30
  107. package/package.json +7 -3
  108. package/dist/context.d.ts +0 -9
  109. package/dist/context.d.ts.map +0 -1
  110. package/dist/context.js.map +0 -1
  111. package/dist/index.d.ts +0 -3
  112. package/dist/index.d.ts.map +0 -1
  113. package/dist/index.js.map +0 -1
  114. package/dist/prompts.d.ts +0 -10
  115. package/dist/prompts.d.ts.map +0 -1
  116. package/dist/prompts.js.map +0 -1
  117. package/dist/resources.d.ts +0 -3
  118. package/dist/resources.d.ts.map +0 -1
  119. package/dist/resources.js.map +0 -1
  120. package/dist/server.d.ts +0 -3
  121. package/dist/server.d.ts.map +0 -1
  122. package/dist/server.js.map +0 -1
  123. package/dist/tools/assembleHighlights.d.ts +0 -3
  124. package/dist/tools/assembleHighlights.d.ts.map +0 -1
  125. package/dist/tools/assembleHighlights.js.map +0 -1
  126. package/dist/tools/burnSubtitles.d.ts +0 -3
  127. package/dist/tools/burnSubtitles.d.ts.map +0 -1
  128. package/dist/tools/burnSubtitles.js.map +0 -1
  129. package/dist/tools/callout.d.ts +0 -37
  130. package/dist/tools/callout.d.ts.map +0 -1
  131. package/dist/tools/callout.js.map +0 -1
  132. package/dist/tools/clip.d.ts +0 -3
  133. package/dist/tools/clip.d.ts.map +0 -1
  134. package/dist/tools/clip.js.map +0 -1
  135. package/dist/tools/compress.d.ts +0 -3
  136. package/dist/tools/compress.d.ts.map +0 -1
  137. package/dist/tools/compress.js.map +0 -1
  138. package/dist/tools/concat.d.ts +0 -3
  139. package/dist/tools/concat.d.ts.map +0 -1
  140. package/dist/tools/concat.js.map +0 -1
  141. package/dist/tools/contactSheet.d.ts +0 -3
  142. package/dist/tools/contactSheet.d.ts.map +0 -1
  143. package/dist/tools/contactSheet.js.map +0 -1
  144. package/dist/tools/convert.d.ts +0 -3
  145. package/dist/tools/convert.d.ts.map +0 -1
  146. package/dist/tools/convert.js.map +0 -1
  147. package/dist/tools/crop.d.ts +0 -3
  148. package/dist/tools/crop.d.ts.map +0 -1
  149. package/dist/tools/crop.js.map +0 -1
  150. package/dist/tools/cutIdle.d.ts +0 -3
  151. package/dist/tools/cutIdle.d.ts.map +0 -1
  152. package/dist/tools/cutIdle.js.map +0 -1
  153. package/dist/tools/denoise.d.ts +0 -3
  154. package/dist/tools/denoise.d.ts.map +0 -1
  155. package/dist/tools/denoise.js.map +0 -1
  156. package/dist/tools/exportGif.d.ts +0 -3
  157. package/dist/tools/exportGif.d.ts.map +0 -1
  158. package/dist/tools/exportGif.js.map +0 -1
  159. package/dist/tools/exportPreset.d.ts +0 -3
  160. package/dist/tools/exportPreset.d.ts.map +0 -1
  161. package/dist/tools/exportPreset.js.map +0 -1
  162. package/dist/tools/extractAudio.d.ts +0 -3
  163. package/dist/tools/extractAudio.d.ts.map +0 -1
  164. package/dist/tools/extractAudio.js.map +0 -1
  165. package/dist/tools/findText.d.ts +0 -6
  166. package/dist/tools/findText.d.ts.map +0 -1
  167. package/dist/tools/findText.js.map +0 -1
  168. package/dist/tools/getMediaInfo.d.ts +0 -3
  169. package/dist/tools/getMediaInfo.d.ts.map +0 -1
  170. package/dist/tools/getMediaInfo.js.map +0 -1
  171. package/dist/tools/getSession.d.ts +0 -3
  172. package/dist/tools/getSession.d.ts.map +0 -1
  173. package/dist/tools/getSession.js.map +0 -1
  174. package/dist/tools/listAudioDevices.d.ts +0 -3
  175. package/dist/tools/listAudioDevices.d.ts.map +0 -1
  176. package/dist/tools/listAudioDevices.js.map +0 -1
  177. package/dist/tools/listSessions.d.ts +0 -3
  178. package/dist/tools/listSessions.d.ts.map +0 -1
  179. package/dist/tools/listSessions.js.map +0 -1
  180. package/dist/tools/musicBed.d.ts +0 -3
  181. package/dist/tools/musicBed.d.ts.map +0 -1
  182. package/dist/tools/musicBed.js.map +0 -1
  183. package/dist/tools/normalizeAudio.d.ts +0 -3
  184. package/dist/tools/normalizeAudio.d.ts.map +0 -1
  185. package/dist/tools/normalizeAudio.js.map +0 -1
  186. package/dist/tools/overlay.d.ts +0 -3
  187. package/dist/tools/overlay.d.ts.map +0 -1
  188. package/dist/tools/overlay.js.map +0 -1
  189. package/dist/tools/pipeline.d.ts +0 -3
  190. package/dist/tools/pipeline.d.ts.map +0 -1
  191. package/dist/tools/pipeline.js.map +0 -1
  192. package/dist/tools/readEvents.d.ts +0 -6
  193. package/dist/tools/readEvents.d.ts.map +0 -1
  194. package/dist/tools/readEvents.js.map +0 -1
  195. package/dist/tools/redactRegion.d.ts +0 -13
  196. package/dist/tools/redactRegion.d.ts.map +0 -1
  197. package/dist/tools/redactRegion.js.map +0 -1
  198. package/dist/tools/reframe.d.ts +0 -3
  199. package/dist/tools/reframe.d.ts.map +0 -1
  200. package/dist/tools/reframe.js.map +0 -1
  201. package/dist/tools/reviewRecording.d.ts +0 -5
  202. package/dist/tools/reviewRecording.d.ts.map +0 -1
  203. package/dist/tools/reviewRecording.js.map +0 -1
  204. package/dist/tools/sampleFrames.d.ts +0 -3
  205. package/dist/tools/sampleFrames.d.ts.map +0 -1
  206. package/dist/tools/sampleFrames.js.map +0 -1
  207. package/dist/tools/scale.d.ts +0 -3
  208. package/dist/tools/scale.d.ts.map +0 -1
  209. package/dist/tools/scale.js.map +0 -1
  210. package/dist/tools/screenDiff.d.ts +0 -3
  211. package/dist/tools/screenDiff.d.ts.map +0 -1
  212. package/dist/tools/screenDiff.js.map +0 -1
  213. package/dist/tools/screenshot.d.ts +0 -3
  214. package/dist/tools/screenshot.d.ts.map +0 -1
  215. package/dist/tools/screenshot.js.map +0 -1
  216. package/dist/tools/speed.d.ts +0 -3
  217. package/dist/tools/speed.d.ts.map +0 -1
  218. package/dist/tools/speed.js.map +0 -1
  219. package/dist/tools/startRecording.d.ts +0 -3
  220. package/dist/tools/startRecording.d.ts.map +0 -1
  221. package/dist/tools/startRecording.js.map +0 -1
  222. package/dist/tools/stopRecording.d.ts +0 -3
  223. package/dist/tools/stopRecording.d.ts.map +0 -1
  224. package/dist/tools/stopRecording.js.map +0 -1
  225. package/dist/tools/titleCard.d.ts +0 -3
  226. package/dist/tools/titleCard.d.ts.map +0 -1
  227. package/dist/tools/titleCard.js.map +0 -1
  228. package/dist/tools/transcribe.d.ts +0 -3
  229. package/dist/tools/transcribe.d.ts.map +0 -1
  230. package/dist/tools/transcribe.js.map +0 -1
  231. package/dist/tools/trim.d.ts +0 -3
  232. package/dist/tools/trim.d.ts.map +0 -1
  233. package/dist/tools/trim.js.map +0 -1
  234. package/dist/tools/waitForChange.d.ts +0 -3
  235. package/dist/tools/waitForChange.d.ts.map +0 -1
  236. package/dist/tools/waitForChange.js.map +0 -1
  237. package/dist/tools/xfadeTransition.d.ts +0 -3
  238. package/dist/tools/xfadeTransition.d.ts.map +0 -1
  239. package/dist/tools/xfadeTransition.js.map +0 -1
  240. package/dist/tools/zoom.d.ts +0 -15
  241. package/dist/tools/zoom.d.ts.map +0 -1
  242. package/dist/tools/zoom.js.map +0 -1
  243. package/dist/utils/anim.d.ts +0 -33
  244. package/dist/utils/anim.d.ts.map +0 -1
  245. package/dist/utils/anim.js.map +0 -1
  246. package/dist/utils/animExport.d.ts +0 -27
  247. package/dist/utils/animExport.d.ts.map +0 -1
  248. package/dist/utils/animExport.js.map +0 -1
  249. package/dist/utils/audio.d.ts +0 -49
  250. package/dist/utils/audio.d.ts.map +0 -1
  251. package/dist/utils/audio.js.map +0 -1
  252. package/dist/utils/audioDevices.d.ts +0 -33
  253. package/dist/utils/audioDevices.d.ts.map +0 -1
  254. package/dist/utils/audioDevices.js.map +0 -1
  255. package/dist/utils/callout.d.ts +0 -72
  256. package/dist/utils/callout.d.ts.map +0 -1
  257. package/dist/utils/callout.js.map +0 -1
  258. package/dist/utils/calloutAssets.d.ts +0 -3
  259. package/dist/utils/calloutAssets.d.ts.map +0 -1
  260. package/dist/utils/calloutAssets.js.map +0 -1
  261. package/dist/utils/captions.d.ts +0 -26
  262. package/dist/utils/captions.d.ts.map +0 -1
  263. package/dist/utils/captions.js.map +0 -1
  264. package/dist/utils/diff.d.ts +0 -112
  265. package/dist/utils/diff.d.ts.map +0 -1
  266. package/dist/utils/diff.js.map +0 -1
  267. package/dist/utils/errors.d.ts +0 -33
  268. package/dist/utils/errors.d.ts.map +0 -1
  269. package/dist/utils/errors.js.map +0 -1
  270. package/dist/utils/events.d.ts +0 -143
  271. package/dist/utils/events.d.ts.map +0 -1
  272. package/dist/utils/events.js.map +0 -1
  273. package/dist/utils/ffmpeg.d.ts +0 -50
  274. package/dist/utils/ffmpeg.d.ts.map +0 -1
  275. package/dist/utils/ffmpeg.js.map +0 -1
  276. package/dist/utils/fonts.d.ts +0 -17
  277. package/dist/utils/fonts.d.ts.map +0 -1
  278. package/dist/utils/fonts.js.map +0 -1
  279. package/dist/utils/idle.d.ts +0 -23
  280. package/dist/utils/idle.d.ts.map +0 -1
  281. package/dist/utils/idle.js.map +0 -1
  282. package/dist/utils/images.d.ts +0 -21
  283. package/dist/utils/images.d.ts.map +0 -1
  284. package/dist/utils/images.js.map +0 -1
  285. package/dist/utils/jobs.d.ts +0 -44
  286. package/dist/utils/jobs.d.ts.map +0 -1
  287. package/dist/utils/jobs.js.map +0 -1
  288. package/dist/utils/lifecycle.d.ts +0 -29
  289. package/dist/utils/lifecycle.d.ts.map +0 -1
  290. package/dist/utils/lifecycle.js.map +0 -1
  291. package/dist/utils/media.d.ts +0 -272
  292. package/dist/utils/media.d.ts.map +0 -1
  293. package/dist/utils/media.js.map +0 -1
  294. package/dist/utils/monitors.d.ts +0 -47
  295. package/dist/utils/monitors.d.ts.map +0 -1
  296. package/dist/utils/monitors.js.map +0 -1
  297. package/dist/utils/ocr.d.ts +0 -50
  298. package/dist/utils/ocr.d.ts.map +0 -1
  299. package/dist/utils/ocr.js.map +0 -1
  300. package/dist/utils/paths.d.ts +0 -28
  301. package/dist/utils/paths.d.ts.map +0 -1
  302. package/dist/utils/paths.js.map +0 -1
  303. package/dist/utils/pipeline.d.ts +0 -69
  304. package/dist/utils/pipeline.d.ts.map +0 -1
  305. package/dist/utils/pipeline.js.map +0 -1
  306. package/dist/utils/player.d.ts +0 -30
  307. package/dist/utils/player.d.ts.map +0 -1
  308. package/dist/utils/player.js.map +0 -1
  309. package/dist/utils/produce.d.ts +0 -126
  310. package/dist/utils/produce.d.ts.map +0 -1
  311. package/dist/utils/produce.js.map +0 -1
  312. package/dist/utils/resolveTarget.d.ts +0 -32
  313. package/dist/utils/resolveTarget.d.ts.map +0 -1
  314. package/dist/utils/resolveTarget.js.map +0 -1
  315. package/dist/utils/retention.d.ts +0 -10
  316. package/dist/utils/retention.d.ts.map +0 -1
  317. package/dist/utils/retention.js.map +0 -1
  318. package/dist/utils/sessions.d.ts +0 -154
  319. package/dist/utils/sessions.d.ts.map +0 -1
  320. package/dist/utils/sessions.js.map +0 -1
  321. package/dist/utils/sheet.d.ts +0 -26
  322. package/dist/utils/sheet.d.ts.map +0 -1
  323. package/dist/utils/sheet.js.map +0 -1
  324. package/dist/utils/still.d.ts +0 -7
  325. package/dist/utils/still.d.ts.map +0 -1
  326. package/dist/utils/still.js.map +0 -1
  327. package/dist/utils/targets.d.ts +0 -113
  328. package/dist/utils/targets.d.ts.map +0 -1
  329. package/dist/utils/targets.js.map +0 -1
  330. package/dist/utils/validate.d.ts +0 -15
  331. package/dist/utils/validate.d.ts.map +0 -1
  332. package/dist/utils/validate.js.map +0 -1
  333. package/dist/utils/wgc.d.ts +0 -46
  334. package/dist/utils/wgc.d.ts.map +0 -1
  335. package/dist/utils/wgc.js.map +0 -1
  336. package/dist/utils/windows.d.ts +0 -94
  337. package/dist/utils/windows.d.ts.map +0 -1
  338. package/dist/utils/windows.js.map +0 -1
  339. package/dist/utils/zoom.d.ts +0 -95
  340. package/dist/utils/zoom.d.ts.map +0 -1
  341. package/dist/utils/zoom.js.map +0 -1
  342. package/dist/wgcRecorder.d.ts +0 -2
  343. package/dist/wgcRecorder.d.ts.map +0 -1
  344. package/dist/wgcRecorder.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { existsSync } from "node:fs";
3
3
  import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
+ import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
4
5
  import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
5
6
  import { runEditJob } from "../utils/jobs.js";
6
7
  import { buildSpeedArgs, editOutputExt, assertEditContainer } from "../utils/media.js";
@@ -12,8 +13,14 @@ const inputSchema = {
12
13
  overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
13
14
  };
14
15
  export function register(server) {
15
- server.tool("speed", "Change playback speed by a factor (>1 faster, <1 slower) and re-encode. " +
16
- "Audio is retempo'd to match when the source has an audio track.", inputSchema, async (args, extra) => {
16
+ server.registerTool("speed", {
17
+ title: "Change Speed",
18
+ description: "Change playback speed by a factor (>1 faster, <1 slower) and re-encode. " +
19
+ "Audio is retempo'd to match when the source has an audio track.",
20
+ inputSchema,
21
+ outputSchema: OUTPUT_PATH,
22
+ annotations: WRITES_FILE,
23
+ }, async (args, extra) => {
17
24
  try {
18
25
  requireFfmpeg();
19
26
  if (!existsSync(args.input)) {
@@ -24,7 +31,12 @@ export function register(server) {
24
31
  const ext = editOutputExt(args.input);
25
32
  const output = resolveOutput(args.output, subdir("edits"), `speed-${stamp()}-${rand()}${ext}`, args.overwrite);
26
33
  const ffArgs = buildSpeedArgs(args.input, output, args.factor, audioCodec !== null);
27
- await runEditJob(ffArgs, { output, durationSec: durationSec !== null ? durationSec / args.factor : null, extra });
34
+ await runEditJob(ffArgs, {
35
+ output,
36
+ durationSec: durationSec !== null ? durationSec / args.factor : null,
37
+ inputDurationSec: durationSec,
38
+ extra,
39
+ });
28
40
  return okResponse({ outputPath: output, factor: args.factor, audio: audioCodec !== null });
29
41
  }
30
42
  catch (error) {
@@ -32,4 +44,3 @@ export function register(server) {
32
44
  }
33
45
  });
34
46
  }
35
- //# sourceMappingURL=speed.js.map
@@ -1,31 +1,32 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { z } from "zod";
3
3
  import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
+ import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
4
5
  import { requireFfmpeg, wgcAvailable } from "../utils/ffmpeg.js";
5
6
  import { fileURLToPath } from "node:url";
6
7
  import { buildCaptureArgs, captureFrame, resolveQuality, DEFAULT_FPS, DEFAULT_QUALITY, DEFAULT_MAX_RECORDING_SEC, MAX_RECORDING_CAP_SEC, resolveMaxDuration, captureKeyframeArgs, } from "../utils/targets.js";
7
8
  import { resolveCaptureTarget } from "../utils/resolveTarget.js";
8
9
  import { windowMatchReport } from "../utils/windows.js";
9
10
  import { resolveLoopbackDevice } from "../utils/audioDevices.js";
11
+ import { confirmCapture, describeTarget } from "../utils/consent.js";
12
+ import { logMessage, StderrWatch } from "../utils/logging.js";
10
13
  import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
11
14
  import { getStore } from "../context.js";
12
- import { classifyUnrequestedExit, killPid } from "../utils/sessions.js";
15
+ import { classifyUnrequestedExit, killPid, serverIdentity } from "../utils/sessions.js";
13
16
  import { rmSync } from "node:fs";
14
- import { basename } from "node:path";
15
- import { DEFAULT_KEY_MODE, eventPaths, parseCaptureStart, startEventLogger, stopEventLogger, summarizeEvents, trackFinalizer, writeEventsFile, } from "../utils/events.js";
17
+ import { basename, join } from "node:path";
18
+ import { MAX_REPLAY_SEC, MIN_REPLAY_SEC, discardReplay, planReplayBuffer, prepareReplayDir, segmentOutputArgs, } from "../utils/replay.js";
19
+ import { DEFAULT_KEY_MODE, eventPaths, parseCaptureStart, prepareEventPaths, startEventLogger, stopEventLogger, summarizeEvents, trackFinalizer, writeEventsFile, } from "../utils/events.js";
16
20
  const inputSchema = {
17
21
  target: z
18
22
  .string()
19
- .describe("Capture target: 'full' | 'monitor:<index>' (0 = primary) | " +
20
- "'window:<title>' (or window:exe=<app.exe> / window:hwnd=<handle>, without relying on the title) | 'region:<x>,<y>,<w>,<h>' (absolute pixels). " +
21
- "window: records the on-screen rectangle the window occupies, resolved " +
22
- "ONCE at start (it must be visible, on top, not minimized); it does not " +
23
- "follow a window moved or resized mid-recording."),
23
+ .describe("full | monitor:<i> (0 = primary) | window:<title> (or window:exe=<app.exe> / window:hwnd=<n>) | " +
24
+ "region:<x>,<y>,<w>,<h>. With gdigrab a window's rectangle is resolved once at start (visible, " +
25
+ "on top); it does not follow the window."),
24
26
  exactTitle: z
25
27
  .boolean()
26
28
  .optional()
27
- .describe("For window: targets, match only a window whose title equals the given " +
28
- "title (case-insensitive); never fall back to a substring match. Default false."),
29
+ .describe("window: targets match the whole title only, never a substring (default false)."),
29
30
  fps: z
30
31
  .number()
31
32
  .int()
@@ -41,20 +42,18 @@ const inputSchema = {
41
42
  .object({
42
43
  source: z
43
44
  .enum(["system", "none"])
44
- .describe("system captures what is playing on the machine; none is video-only."),
45
+ .describe("system = what the machine plays (needs a loopback device); none = video only."),
45
46
  device: z
46
47
  .string()
47
48
  .optional()
48
- .describe("Optional dshow loopback device name (from list_audio_devices). When " +
49
- "omitted, a loopback device is auto-detected."),
49
+ .describe("dshow loopback device (from list_audio_devices); auto-detected if omitted."),
50
50
  })
51
51
  .optional()
52
- .describe("Audio capture (default none, video-only). source 'system' needs a " +
53
- "loopback device; microphone capture is not supported."),
52
+ .describe("Audio (default none). No microphone capture."),
54
53
  output: z
55
54
  .string()
56
55
  .optional()
57
- .describe("Optional output .mp4 path. Defaults to a file under SCREENCAST_HOME/recordings."),
56
+ .describe("Output .mp4 path (default under SCREENCAST_HOME/recordings)."),
58
57
  overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
59
58
  maxDurationSec: z
60
59
  .number()
@@ -62,34 +61,45 @@ const inputSchema = {
62
61
  .min(0)
63
62
  .max(MAX_RECORDING_CAP_SEC)
64
63
  .optional()
65
- .describe(`Stop automatically after this many seconds, finalizing the file (default ` +
66
- `${DEFAULT_MAX_RECORDING_SEC}, or SCREENCAST_MAX_RECORDING_SEC; at most ${MAX_RECORDING_CAP_SEC}, 7 days). 0 = no cap. ` +
67
- "A safety net against a recording that is never stopped."),
64
+ .describe(`Auto-stop after this many seconds (default ${DEFAULT_MAX_RECORDING_SEC} or ` +
65
+ "SCREENCAST_MAX_RECORDING_SEC; max 7 days; 0 = no cap)."),
68
66
  events: z
69
67
  .boolean()
70
68
  .optional()
71
- .describe("Also log mouse clicks, scroll, cursor positions, and typing to " +
72
- "<recording>.events.jsonl, timed to the video and in video pixels (default " +
73
- "false). Read it with read_events. Adds about a second to start."),
69
+ .describe("Also log clicks, scroll, cursor, and typing (video-timed, video pixels) for read_events " +
70
+ "(default false; ~1 s slower start)."),
74
71
  keys: z
75
72
  .enum(["masked", "shortcuts"])
76
73
  .optional()
77
- .describe("With events: masked (default) logs typing only as bursts (start and length on a 0.5 s grid), " +
78
- "never which keys or when each one was pressed. shortcuts also names chords made with Ctrl, Alt, " +
79
- "or Win (e.g. Ctrl+S), with their times; typed text is never logged."),
74
+ .describe("With events: masked (default) logs typing only as 0.5 s-grid bursts, never keys; shortcuts " +
75
+ "also names Ctrl/Alt/Win chords. Typed text is never logged."),
80
76
  backend: z
81
77
  .enum(["gdigrab", "wgc"])
82
78
  .optional()
83
- .describe("gdigrab (default) records the screen rectangle. wgc (window: targets, FFmpeg 8+) records the " +
84
- "window's own surface through Windows Graphics Capture: it keeps recording the window when " +
85
- "it is covered, moved, or in the background, and frames only its client area. No audio with wgc."),
79
+ .describe("gdigrab (default): the screen rectangle. wgc (window: targets, FFmpeg 8+): the window's own " +
80
+ "surface, even when covered or moved; client area only, no audio."),
81
+ replayBufferSec: z
82
+ .number()
83
+ .int()
84
+ .min(MIN_REPLAY_SEC)
85
+ .max(MAX_REPLAY_SEC)
86
+ .optional()
87
+ .describe("Instant replay: keep only the last N s (bounded disk) for save_replay. gdigrab only."),
86
88
  };
87
89
  export function register(server) {
88
- server.tool("start_recording", "Start a screen recording (Windows gdigrab) as a background ffmpeg process. " +
89
- "Returns a session id and output path. Recording is explicit and never " +
90
- "auto-starts. Use stop_recording with the id to finalize the file. " +
91
- "Audio is video-only by default; set audio.source = 'system' to also " +
92
- "capture system (loopback) audio. Microphone capture is not supported.", inputSchema, async (args) => {
90
+ server.registerTool("start_recording", {
91
+ title: "Start Recording",
92
+ description: "Start a background screen recording. Returns a session id; finalize it with stop_recording. " +
93
+ "Never auto-starts.",
94
+ inputSchema,
95
+ outputSchema: looseOutput({
96
+ sessionId: z.string(),
97
+ status: z.string(),
98
+ backend: z.string(),
99
+ outputPath: z.string(),
100
+ }),
101
+ annotations: WRITES_FILE,
102
+ }, async (args, extra) => {
93
103
  try {
94
104
  const { ffmpeg } = requireFfmpeg();
95
105
  const { target, monitors, window } = await resolveCaptureTarget(args.target, {
@@ -106,16 +116,24 @@ export function register(server) {
106
116
  throw new ScreencastError('backend "wgc" needs FFmpeg 8 or newer (the gfxcapture filter). Use gdigrab, or update ffmpeg.');
107
117
  }
108
118
  }
119
+ if (args.replayBufferSec !== undefined && backend === "wgc") {
120
+ throw new ScreencastError('replayBufferSec is not supported with backend "wgc" yet; use gdigrab.');
121
+ }
122
+ const replay = args.replayBufferSec !== undefined ? planReplayBuffer(args.replayBufferSec) : null;
109
123
  const fps = args.fps ?? DEFAULT_FPS;
110
124
  const quality = args.quality ?? DEFAULT_QUALITY;
111
125
  const maxDurationSec = resolveMaxDuration(args.maxDurationSec);
112
126
  const output = resolveOutput(args.output, subdir("recordings"), `rec-${stamp()}-${rand()}.mp4`, args.overwrite);
113
- // Resolve a loopback device up front so a missing one fails before the
114
- // ffmpeg child is spawned, with a clear install hint.
115
127
  const audio = args.audio?.source === "system"
116
128
  ? { device: await resolveLoopbackDevice(args.audio.device) }
117
129
  : undefined;
118
- const ffArgs = buildCaptureArgs(target, {
130
+ await confirmCapture(server, (replay ? `Keep a rolling ${replay.bufferSec} s replay buffer of ` : "Record ") +
131
+ `${describeTarget(args.target, window)} ` +
132
+ (maxDurationSec > 0 ? `for up to ${maxDurationSec} s` : "with no time limit") +
133
+ (audio ? `, with system audio (${audio.device})` : ", without audio") +
134
+ (args.events ? ", logging mouse clicks and typing" : "") +
135
+ (replay ? ", kept only until save_replay or stop_recording { save: true } writes it out?" : `, saved to ${output}?`), extra.signal);
136
+ const captureArgs = buildCaptureArgs(target, {
119
137
  fps,
120
138
  quality,
121
139
  output,
@@ -123,10 +141,13 @@ export function register(server) {
123
141
  audio,
124
142
  maxDurationSec,
125
143
  });
126
- // The event logger starts first so the first frames have events (#118).
144
+ const ffArgs = replay ? segmentOutputArgs(captureArgs, replay) : captureArgs;
145
+ if (replay)
146
+ prepareReplayDir(replay);
127
147
  const keyMode = args.keys ?? DEFAULT_KEY_MODE;
128
- const evPaths = args.events ? eventPaths(output) : null;
129
- // wgc frames the client area; its size is known once the recorder starts.
148
+ const evPaths = args.events ? (replay ? { raw: join(replay.dir, "events.raw"), jsonl: "" } : eventPaths(output)) : null;
149
+ if (evPaths && !replay)
150
+ prepareEventPaths(evPaths, args.overwrite);
130
151
  let frame = args.events
131
152
  ? captureFrame(target, monitors)
132
153
  : null;
@@ -141,18 +162,17 @@ export function register(server) {
141
162
  stdio: ["pipe", "ignore", "pipe"],
142
163
  windowsHide: true,
143
164
  });
144
- // Detect an immediate failure (bad window title, busy device, etc.).
145
- // The head keeps the input banner, whose start: time aligns events.
146
165
  let stderrTail = "";
147
166
  let stderrHead = "";
167
+ const id = `rec-${stamp()}-${rand(6)}`;
168
+ const watch = new StderrWatch(() => ({ sessionId: id }));
148
169
  child.stderr?.on("data", (d) => {
149
170
  const text = d.toString();
150
171
  stderrTail = (stderrTail + text).slice(-2000);
151
172
  if (stderrHead.length < 8000)
152
173
  stderrHead += text;
174
+ watch.feed(text);
153
175
  });
154
- // gdigrab is running once it survives a moment; the wgc recorder says
155
- // so when its first frame is written (a repaint can take a second).
156
176
  const settled = await new Promise((resolve) => {
157
177
  const timer = setTimeout(() => resolve("running"), backend === "wgc" ? 15_000 : 1200);
158
178
  if (backend === "wgc") {
@@ -173,12 +193,13 @@ export function register(server) {
173
193
  resolve("exited");
174
194
  });
175
195
  });
176
- const id = `rec-${stamp()}-${rand(6)}`;
177
196
  if (settled === "exited") {
178
197
  if (logger)
179
198
  await stopEventLogger(logger);
180
199
  if (evPaths)
181
200
  rmSync(evPaths.raw, { force: true });
201
+ if (replay)
202
+ discardReplay(replay);
182
203
  const tail = stderrTail.trim().split("\n").slice(-6).join("\n");
183
204
  throw new ScreencastError(`Recording failed to start (${backend === "wgc" ? "window capture" : "ffmpeg"} exited immediately):\n${tail}`);
184
205
  }
@@ -193,18 +214,27 @@ export function register(server) {
193
214
  fps,
194
215
  quality,
195
216
  pid: child.pid ?? null,
196
- serverPid: process.pid,
217
+ ...serverIdentity(),
197
218
  status: "recording",
198
219
  startedAt: new Date().toISOString(),
220
+ videoStartMs: parseCaptureStart(stderrHead) ?? spawnedAt,
199
221
  ...(maxDurationSec > 0 ? { maxDurationSec } : {}),
200
222
  ...(window ? { matchedWindow: window.matchedTitle } : {}),
201
- ...(evPaths ? { events: { path: evPaths.jsonl, keys: keyMode } } : {}),
223
+ ...(evPaths && !replay ? { events: { path: evPaths.jsonl, keys: keyMode } } : {}),
224
+ ...(replay
225
+ ? {
226
+ replay: {
227
+ ...replay,
228
+ ...(evPaths && frame
229
+ ? { events: { raw: evPaths.raw, keys: keyMode, startMs: parseCaptureStart(stderrHead) ?? spawnedAt, frame } }
230
+ : {}),
231
+ },
232
+ }
233
+ : {}),
202
234
  backend,
203
235
  processImage: backend === "wgc" ? basename(process.execPath).toLowerCase() : "ffmpeg.exe",
204
236
  };
205
237
  const store = getStore();
206
- // Register the child for shutdown first; if the registry write fails,
207
- // stop the capture rather than leave one nothing can reach (#207).
208
238
  store.attachChild(id, child);
209
239
  try {
210
240
  store.create(record);
@@ -217,9 +247,15 @@ export function register(server) {
217
247
  await stopEventLogger(logger);
218
248
  if (evPaths)
219
249
  rmSync(evPaths.raw, { force: true });
250
+ if (replay)
251
+ discardReplay(replay);
220
252
  throw new ScreencastError(`Recording stopped: the session registry could not be written (${err.message}).`);
221
253
  }
222
- if (logger && evPaths && frame) {
254
+ if (logger && replay) {
255
+ const exited = new Promise((resolve) => child.once("exit", () => resolve()));
256
+ trackFinalizer(id, exited.then(() => stopEventLogger(logger)));
257
+ }
258
+ else if (logger && evPaths && frame) {
223
259
  const exited = new Promise((resolve) => child.once("exit", () => resolve()));
224
260
  trackFinalizer(id, exited.then(async () => {
225
261
  await stopEventLogger(logger);
@@ -239,19 +275,15 @@ export function register(server) {
239
275
  process.stderr.write(`Event log for ${id} failed: ${err instanceof Error ? err.message : String(err)}\n`);
240
276
  }));
241
277
  }
242
- // Keep the on-disk record consistent if the child dies on its own. A
243
- // non-zero exit is a crash (disk full, encoder failure), not a clean
244
- // stop - record it as "failed" with the stderr tail so the caller can
245
- // tell the two apart. A clean exit nobody requested is the
246
- // maxDurationSec cap, or the recorded window closing (#240).
247
278
  child.on("exit", (code) => {
248
279
  store.detachChild(id);
249
280
  const cur = store.get(id);
250
- // A deliberate stop (stop_recording / shutdown) records its own final
251
- // state; only an exit nobody asked for is classified here.
252
281
  if (!cur || cur.status !== "recording" || store.isStopping(id))
253
282
  return;
254
283
  const verdict = classifyUnrequestedExit({ code, backend, maxDurationSec, elapsedMs: Date.now() - spawnedAt });
284
+ logMessage(verdict.status === "failed" ? "error" : "notice", verdict.status === "failed"
285
+ ? `Recording ${id} failed: the recorder exited with code ${code}.`
286
+ : `Recording ${id} ended on its own (${verdict.endReason}).`, { sessionId: id, ...verdict });
255
287
  store.tryUpdate(id, {
256
288
  ...verdict,
257
289
  stoppedAt: new Date().toISOString(),
@@ -271,8 +303,14 @@ export function register(server) {
271
303
  audioDevice: audio?.device ?? null,
272
304
  maxDurationSec: maxDurationSec > 0 ? maxDurationSec : null,
273
305
  ...(window ? windowMatchReport(window) : {}),
274
- ...(evPaths ? { eventsPath: evPaths.jsonl, keys: keyMode } : {}),
275
- note: "Call stop_recording with this sessionId to finalize the file." +
306
+ ...(evPaths && !replay ? { eventsPath: evPaths.jsonl, keys: keyMode } : {}),
307
+ ...(replay
308
+ ? { replay: { bufferSec: replay.bufferSec, segmentSec: replay.segmentSec, dir: replay.dir, events: !!evPaths } }
309
+ : {}),
310
+ note: (replay
311
+ ? `Replay buffer running: save_replay keeps the last seconds (up to ${replay.bufferSec}s) without stopping it; ` +
312
+ "stop_recording discards the buffer unless save: true (then it writes outputPath)."
313
+ : "Call stop_recording with this sessionId to finalize the file.") +
276
314
  (maxDurationSec > 0
277
315
  ? ` It stops on its own after ${maxDurationSec}s (maxDurationSec).`
278
316
  : ""),
@@ -283,4 +321,3 @@ export function register(server) {
283
321
  }
284
322
  });
285
323
  }
286
- //# sourceMappingURL=startRecording.js.map
@@ -1,23 +1,38 @@
1
1
  import { z } from "zod";
2
2
  import { existsSync } from "node:fs";
3
3
  import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
+ import { STOPS_SESSION, looseOutput } from "../utils/toolSpec.js";
4
5
  import { requireFfmpeg } from "../utils/ffmpeg.js";
5
6
  import { probeDuration, stopSession } from "../utils/lifecycle.js";
6
7
  import { getStore } from "../context.js";
7
- import { PLAYER_TOOL_META } from "../utils/player.js";
8
+ import { finishReplay } from "../utils/replay.js";
9
+ function replayReport(r) {
10
+ return {
11
+ saved: r.saved,
12
+ discarded: r.discarded,
13
+ ...(r.save ? { durationSec: r.save.durationSec, eventsPath: r.save.eventsPath } : {}),
14
+ ...(r.error ? { error: r.error, note: "The buffer was kept; call stop_recording with save: true again, or save_replay." } : {}),
15
+ };
16
+ }
8
17
  const inputSchema = {
9
18
  sessionId: z.string().min(1).describe("Session id returned by start_recording."),
19
+ save: z
20
+ .boolean()
21
+ .optional()
22
+ .describe("Replay buffer: write it all to outputPath first (default: discard)."),
10
23
  };
11
24
  export function register(server) {
12
25
  server.registerTool("stop_recording", {
13
- description: "Stop a recording by session id. Sends ffmpeg a graceful quit so the file " +
14
- "is finalized rather than truncated, then returns the final path and " +
15
- "duration. Falls back to terminating the process by pid if the live " +
16
- "handle was lost (for example after a server restart). Clients with MCP " +
17
- "Apps show the review player for the result.",
26
+ title: "Stop Recording",
27
+ description: "Stop a recording gracefully so the file is finalized; returns the path and duration.",
18
28
  inputSchema,
19
- // The review player (#128) renders for this result in Apps-capable hosts.
20
- _meta: PLAYER_TOOL_META,
29
+ outputSchema: looseOutput({
30
+ sessionId: z.string(),
31
+ status: z.string(),
32
+ outputPath: z.string(),
33
+ durationSec: z.number().nullable(),
34
+ }),
35
+ annotations: STOPS_SESSION,
21
36
  }, async (args) => {
22
37
  try {
23
38
  const store = getStore();
@@ -26,7 +41,16 @@ export function register(server) {
26
41
  throw new ScreencastError(`No session with id "${args.sessionId}".`);
27
42
  }
28
43
  if (record.status !== "recording") {
44
+ const replay = record.replay && existsSync(record.replay.dir)
45
+ ? await finishReplay(record.replay, {
46
+ save: args.save ?? false,
47
+ output: record.outputPath,
48
+ quality: record.quality,
49
+ tools: requireFfmpeg,
50
+ })
51
+ : undefined;
29
52
  return okResponse({
53
+ ...(replay ? { replay: replayReport(replay) } : {}),
30
54
  sessionId: record.id,
31
55
  status: record.status,
32
56
  outputPath: record.outputPath,
@@ -40,9 +64,10 @@ export function register(server) {
40
64
  });
41
65
  }
42
66
  const { ffprobe } = requireFfmpeg();
43
- const { record: updated, graceful, durationSec } = await stopSession(store, record, {
67
+ const { record: updated, graceful, durationSec, replay } = await stopSession(store, record, {
44
68
  reason: "stopped",
45
69
  probe: (path) => probeDuration(ffprobe, path),
70
+ saveReplay: args.save,
46
71
  });
47
72
  return okResponse({
48
73
  sessionId: record.id,
@@ -50,6 +75,7 @@ export function register(server) {
50
75
  outputPath: record.outputPath,
51
76
  durationSec: durationSec ?? null,
52
77
  finalizedGracefully: graceful,
78
+ ...(replay ? { replay: replayReport(replay) } : {}),
53
79
  ...(updated?.events
54
80
  ? { eventsPath: updated.events.path, events: updated.events.summary ?? {}, ...(updated.events.error ? { eventsError: updated.events.error } : {}) }
55
81
  : {}),
@@ -65,4 +91,3 @@ export function register(server) {
65
91
  }
66
92
  });
67
93
  }
68
- //# sourceMappingURL=stopRecording.js.map
@@ -1,10 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import { writeFileSync, rmSync } from "node:fs";
3
3
  import { errorResponse, okResponse } from "../utils/errors.js";
4
+ import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
4
5
  import { requireFfmpeg } from "../utils/ffmpeg.js";
5
6
  import { runEditJob } from "../utils/jobs.js";
6
7
  import { buildTitleCardArgs, DEFAULT_TITLE_DURATION } from "../utils/produce.js";
7
- import { bundledFontPath } from "../utils/fonts.js";
8
+ import { resolveTextFont } from "../utils/fonts.js";
9
+ import { fontFileSchema } from "./callout.js";
8
10
  import { resolveOutput, subdir, stamp, rand, tempPath } from "../utils/paths.js";
9
11
  const inputSchema = {
10
12
  text: z.string().min(1).describe("Title text. Multiple lines are allowed (use \\n)."),
@@ -16,24 +18,27 @@ const inputSchema = {
16
18
  fontColor: z.string().optional().describe("Text color (default white)."),
17
19
  fontSize: z.number().int().positive().optional().describe("Text size in px (default 96)."),
18
20
  bold: z.boolean().optional().describe("Use the bold weight (default true)."),
21
+ fontFile: fontFileSchema,
19
22
  output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
20
23
  overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
21
24
  };
22
25
  export function register(server) {
23
- server.tool("title_card", "Generate a standalone title card: centered text on a solid background, with " +
24
- "a silent audio track so it composes with audio-bearing clips (use " +
25
- "assemble_highlights to stitch it in). Text is rendered with a bundled " +
26
- "font, so no system font is required.", inputSchema, async (args, extra) => {
26
+ server.registerTool("title_card", {
27
+ title: "Title Card",
28
+ description: "Generate a title card clip (centered text on a solid background, silent audio track) to stitch " +
29
+ "in with assemble_highlights. Uncoverable characters are reported in warnings.",
30
+ inputSchema,
31
+ outputSchema: OUTPUT_PATH,
32
+ annotations: WRITES_FILE,
33
+ }, async (args, extra) => {
27
34
  try {
28
35
  requireFfmpeg();
29
36
  const output = resolveOutput(args.output, subdir("edits"), `title-${stamp()}-${rand()}.mp4`, args.overwrite);
30
- const fontFile = bundledFontPath(args.bold === false ? "regular" : "bold");
31
- // Write the text to a temp file so arbitrary content (quotes, colons,
32
- // percent signs) needs no inline filtergraph escaping.
37
+ const font = resolveTextFont(args.text, { weight: args.bold === false ? "regular" : "bold", fontFile: args.fontFile });
33
38
  const textFile = tempPath(".txt");
34
39
  writeFileSync(textFile, args.text);
35
40
  try {
36
- const ffArgs = buildTitleCardArgs(textFile, fontFile, output, {
41
+ const ffArgs = buildTitleCardArgs(textFile, font.fontFile, output, {
37
42
  duration: args.duration,
38
43
  width: args.width,
39
44
  height: args.height,
@@ -47,11 +52,14 @@ export function register(server) {
47
52
  finally {
48
53
  rmSync(textFile, { force: true });
49
54
  }
50
- return okResponse({ outputPath: output });
55
+ return okResponse({
56
+ outputPath: output,
57
+ ...((font.fallback || args.fontFile) && { fontFile: font.fontFile }),
58
+ ...(font.warning && { warnings: [font.warning] }),
59
+ });
51
60
  }
52
61
  catch (error) {
53
62
  return errorResponse(error);
54
63
  }
55
64
  });
56
65
  }
57
- //# sourceMappingURL=titleCard.js.map
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
+ import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
4
5
  import { requireFfmpeg, runFfmpeg, probeMedia, hasFilter } from "../utils/ffmpeg.js";
5
6
  import { jobTimeoutMs } from "../utils/jobs.js";
6
7
  import { resolveWhisperModel, buildTranscribeArgs, parseSrt, normalizeCues, formatSrt, WHISPER_MODEL_ENV, } from "../utils/captions.js";
@@ -16,9 +17,15 @@ const inputSchema = {
16
17
  overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
17
18
  };
18
19
  export function register(server) {
19
- server.tool("transcribe", "Transcribe a recording's speech to an SRT subtitle file, locally, with FFmpeg 8's " +
20
- "whisper filter (needs a whisper.cpp model file). Returns the SRT path and the text. " +
21
- "Pair with burn_subtitles to caption the video.", inputSchema, async (args) => {
20
+ server.registerTool("transcribe", {
21
+ title: "Transcribe Speech",
22
+ description: "Transcribe a recording's speech to an SRT subtitle file, locally, with FFmpeg 8's " +
23
+ "whisper filter (needs a whisper.cpp model file). Returns the SRT path and the text. " +
24
+ "Pair with burn_subtitles to caption the video.",
25
+ inputSchema,
26
+ outputSchema: looseOutput({ srtPath: z.string(), cues: z.number().int(), text: z.string() }),
27
+ annotations: WRITES_FILE,
28
+ }, async (args, extra) => {
22
29
  try {
23
30
  requireFfmpeg();
24
31
  if (!existsSync(args.input))
@@ -32,11 +39,11 @@ export function register(server) {
32
39
  if (!info.audioCodec)
33
40
  throw new ScreencastError(`Input has no audio to transcribe: ${args.input}`);
34
41
  const output = resolveOutput(args.output, subdir("edits"), `captions-${stamp()}-${rand()}.srt`, args.overwrite);
35
- // whisper writes (appends) to its destination; use a fresh temp file,
36
- // then tidy it into the output.
37
42
  const raw = tempPath(".srt");
38
43
  try {
39
- await runFfmpeg(buildTranscribeArgs(args.input, model, raw, args.language ?? "auto"), jobTimeoutMs(info.durationSec));
44
+ await runFfmpeg(buildTranscribeArgs(args.input, model, raw, args.language ?? "auto"), jobTimeoutMs(info.durationSec), {
45
+ signal: extra.signal,
46
+ });
40
47
  const cues = existsSync(raw) ? normalizeCues(parseSrt(readFileSync(raw, "utf8"))) : [];
41
48
  writeFileSync(output, formatSrt(cues));
42
49
  const text = cues.map((c) => c.text.replace(/\n/g, " ")).join(" ");
@@ -56,4 +63,3 @@ export function register(server) {
56
63
  }
57
64
  });
58
65
  }
59
- //# sourceMappingURL=transcribe.js.map
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  import { extname } from "node:path";
3
3
  import { existsSync } from "node:fs";
4
4
  import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
5
+ import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
5
6
  import { requireFfmpeg } from "../utils/ffmpeg.js";
6
7
  import { runEditJob, probeDuration } from "../utils/jobs.js";
7
8
  import { buildTrimArgs, editOutputExt, assertEditContainer } from "../utils/media.js";
@@ -14,23 +15,25 @@ const inputSchema = {
14
15
  exact: z
15
16
  .boolean()
16
17
  .optional()
17
- .describe("Re-encode so the cut is frame-exact and nothing before start stays in the file (default true). " +
18
- "false stream-copies: much faster, but the cut snaps to a keyframe and the frames before start " +
19
- "still ship in the file, hidden only by an edit list. Never use false to remove sensitive content."),
18
+ .describe("Re-encode for a frame-exact cut with the removed content really gone (default true). false = fast " +
19
+ "stream copy that snaps to a keyframe and keeps hidden earlier frames; never use it to remove secrets."),
20
20
  output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
21
21
  overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
22
22
  };
23
23
  export function register(server) {
24
- server.tool("trim", "Trim a video to a sub-clip by start + (end or duration). Re-encodes by default, " +
25
- "so the cut is frame-exact and the removed content is really gone; set exact: false " +
26
- "for a fast stream copy that keeps hidden frames from before start in the file.", inputSchema, async (args, extra) => {
24
+ server.registerTool("trim", {
25
+ title: "Trim Video",
26
+ description: "Cut a video down to one sub-clip by start + (end or duration). For several segments use clip; " +
27
+ "to combine with other edits use pipeline.",
28
+ inputSchema,
29
+ outputSchema: OUTPUT_PATH,
30
+ annotations: WRITES_FILE,
31
+ }, async (args, extra) => {
27
32
  try {
28
33
  requireFfmpeg();
29
34
  if (!existsSync(args.input)) {
30
35
  throw new ScreencastError(`Input file not found: ${args.input}`);
31
36
  }
32
- // A stream copy keeps the input's container; a re-encode needs one that
33
- // holds libx264/AAC.
34
37
  if (args.exact !== false)
35
38
  assertEditContainer(args.output);
36
39
  const ext = args.exact === false ? extname(args.input) || ".mp4" : editOutputExt(args.input);
@@ -41,7 +44,6 @@ export function register(server) {
41
44
  duration: args.duration,
42
45
  exact: args.exact,
43
46
  });
44
- // Length of the trimmed clip, which sizes the job's timeout and progress.
45
47
  const start = args.start ?? 0;
46
48
  const end = args.end ?? (await probeDuration(args.input));
47
49
  const durationSec = args.duration ?? (end !== null ? end - start : null);
@@ -53,4 +55,3 @@ export function register(server) {
53
55
  }
54
56
  });
55
57
  }
56
- //# sourceMappingURL=trim.js.map