@tmhs/screencast-mcp 0.38.0 → 0.44.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/README.md +58 -14
  2. package/assets/icon.png +0 -0
  3. package/assets/ui/player.html +38 -302
  4. package/assets/ui/player.js +382 -0
  5. package/dist/context.js +0 -5
  6. package/dist/index.js +7 -115
  7. package/dist/prompts.js +0 -7
  8. package/dist/resources.js +2 -14
  9. package/dist/server.js +129 -0
  10. package/dist/tools/assembleHighlights.js +12 -7
  11. package/dist/tools/burnSubtitles.js +12 -6
  12. package/dist/tools/callout.js +32 -16
  13. package/dist/tools/clip.js +12 -9
  14. package/dist/tools/compress.js +10 -5
  15. package/dist/tools/concat.js +16 -15
  16. package/dist/tools/contactSheet.js +26 -22
  17. package/dist/tools/convert.js +12 -6
  18. package/dist/tools/crop.js +12 -7
  19. package/dist/tools/cutIdle.js +15 -9
  20. package/dist/tools/denoise.js +12 -6
  21. package/dist/tools/doctor.js +133 -0
  22. package/dist/tools/exportGif.js +14 -10
  23. package/dist/tools/exportPreset.js +11 -8
  24. package/dist/tools/extractAudio.js +10 -8
  25. package/dist/tools/findText.js +69 -65
  26. package/dist/tools/getMediaInfo.js +17 -3
  27. package/dist/tools/getSession.js +15 -3
  28. package/dist/tools/listAudioDevices.js +14 -7
  29. package/dist/tools/listSessions.js +13 -3
  30. package/dist/tools/listTargets.js +76 -0
  31. package/dist/tools/musicBed.js +14 -10
  32. package/dist/tools/normalizeAudio.js +12 -8
  33. package/dist/tools/overlay.js +16 -12
  34. package/dist/tools/pipeline.js +31 -22
  35. package/dist/tools/readEvents.js +21 -12
  36. package/dist/tools/redactRegion.js +19 -17
  37. package/dist/tools/reframe.js +9 -5
  38. package/dist/tools/reviewRecording.js +63 -22
  39. package/dist/tools/sampleFrames.js +33 -40
  40. package/dist/tools/scale.js +9 -3
  41. package/dist/tools/screenDiff.js +23 -17
  42. package/dist/tools/screenshot.js +21 -17
  43. package/dist/tools/speed.js +15 -4
  44. package/dist/tools/startRecording.js +48 -52
  45. package/dist/tools/stopRecording.js +10 -9
  46. package/dist/tools/titleCard.js +19 -11
  47. package/dist/tools/transcribe.js +13 -7
  48. package/dist/tools/trim.js +11 -10
  49. package/dist/tools/waitForChange.js +37 -22
  50. package/dist/tools/xfadeTransition.js +12 -8
  51. package/dist/tools/zoom.js +26 -29
  52. package/dist/utils/anim.js +1 -21
  53. package/dist/utils/animExport.js +5 -10
  54. package/dist/utils/audio.js +4 -33
  55. package/dist/utils/audioDevices.js +1 -48
  56. package/dist/utils/callout.js +1 -19
  57. package/dist/utils/calloutAssets.js +21 -11
  58. package/dist/utils/capabilities.js +95 -0
  59. package/dist/utils/captions.js +9 -26
  60. package/dist/utils/consent.js +29 -0
  61. package/dist/utils/diff.js +0 -46
  62. package/dist/utils/errors.js +5 -13
  63. package/dist/utils/events.js +21 -77
  64. package/dist/utils/expr.js +11 -0
  65. package/dist/utils/ffmpeg.js +119 -48
  66. package/dist/utils/fontCoverage.js +177 -0
  67. package/dist/utils/fonts.js +139 -23
  68. package/dist/utils/idle.js +12 -24
  69. package/dist/utils/images.js +0 -17
  70. package/dist/utils/jobs.js +42 -41
  71. package/dist/utils/lifecycle.js +0 -29
  72. package/dist/utils/logging.js +75 -0
  73. package/dist/utils/media.js +11 -122
  74. package/dist/utils/monitors.js +7 -43
  75. package/dist/utils/ocr.js +53 -71
  76. package/dist/utils/paths.js +68 -31
  77. package/dist/utils/pipeline.js +0 -23
  78. package/dist/utils/player.js +50 -27
  79. package/dist/utils/produce.js +6 -66
  80. package/dist/utils/resolveTarget.js +0 -19
  81. package/dist/utils/retention.js +1 -15
  82. package/dist/utils/roots.js +42 -0
  83. package/dist/utils/sessions.js +195 -160
  84. package/dist/utils/sheet.js +0 -19
  85. package/dist/utils/still.js +0 -15
  86. package/dist/utils/targetList.js +63 -0
  87. package/dist/utils/targets.js +5 -70
  88. package/dist/utils/toolSpec.js +25 -0
  89. package/dist/utils/toolsets.js +102 -0
  90. package/dist/utils/validate.js +0 -22
  91. package/dist/utils/wgc.js +0 -46
  92. package/dist/utils/windows.js +5 -50
  93. package/dist/utils/zoom.js +55 -85
  94. package/dist/wgcRecorder.js +1 -30
  95. package/package.json +7 -3
  96. package/dist/context.d.ts +0 -9
  97. package/dist/context.d.ts.map +0 -1
  98. package/dist/context.js.map +0 -1
  99. package/dist/index.d.ts +0 -3
  100. package/dist/index.d.ts.map +0 -1
  101. package/dist/index.js.map +0 -1
  102. package/dist/prompts.d.ts +0 -10
  103. package/dist/prompts.d.ts.map +0 -1
  104. package/dist/prompts.js.map +0 -1
  105. package/dist/resources.d.ts +0 -3
  106. package/dist/resources.d.ts.map +0 -1
  107. package/dist/resources.js.map +0 -1
  108. package/dist/tools/assembleHighlights.d.ts +0 -3
  109. package/dist/tools/assembleHighlights.d.ts.map +0 -1
  110. package/dist/tools/assembleHighlights.js.map +0 -1
  111. package/dist/tools/burnSubtitles.d.ts +0 -3
  112. package/dist/tools/burnSubtitles.d.ts.map +0 -1
  113. package/dist/tools/burnSubtitles.js.map +0 -1
  114. package/dist/tools/callout.d.ts +0 -37
  115. package/dist/tools/callout.d.ts.map +0 -1
  116. package/dist/tools/callout.js.map +0 -1
  117. package/dist/tools/clip.d.ts +0 -3
  118. package/dist/tools/clip.d.ts.map +0 -1
  119. package/dist/tools/clip.js.map +0 -1
  120. package/dist/tools/compress.d.ts +0 -3
  121. package/dist/tools/compress.d.ts.map +0 -1
  122. package/dist/tools/compress.js.map +0 -1
  123. package/dist/tools/concat.d.ts +0 -3
  124. package/dist/tools/concat.d.ts.map +0 -1
  125. package/dist/tools/concat.js.map +0 -1
  126. package/dist/tools/contactSheet.d.ts +0 -3
  127. package/dist/tools/contactSheet.d.ts.map +0 -1
  128. package/dist/tools/contactSheet.js.map +0 -1
  129. package/dist/tools/convert.d.ts +0 -3
  130. package/dist/tools/convert.d.ts.map +0 -1
  131. package/dist/tools/convert.js.map +0 -1
  132. package/dist/tools/crop.d.ts +0 -3
  133. package/dist/tools/crop.d.ts.map +0 -1
  134. package/dist/tools/crop.js.map +0 -1
  135. package/dist/tools/cutIdle.d.ts +0 -3
  136. package/dist/tools/cutIdle.d.ts.map +0 -1
  137. package/dist/tools/cutIdle.js.map +0 -1
  138. package/dist/tools/denoise.d.ts +0 -3
  139. package/dist/tools/denoise.d.ts.map +0 -1
  140. package/dist/tools/denoise.js.map +0 -1
  141. package/dist/tools/exportGif.d.ts +0 -3
  142. package/dist/tools/exportGif.d.ts.map +0 -1
  143. package/dist/tools/exportGif.js.map +0 -1
  144. package/dist/tools/exportPreset.d.ts +0 -3
  145. package/dist/tools/exportPreset.d.ts.map +0 -1
  146. package/dist/tools/exportPreset.js.map +0 -1
  147. package/dist/tools/extractAudio.d.ts +0 -3
  148. package/dist/tools/extractAudio.d.ts.map +0 -1
  149. package/dist/tools/extractAudio.js.map +0 -1
  150. package/dist/tools/findText.d.ts +0 -6
  151. package/dist/tools/findText.d.ts.map +0 -1
  152. package/dist/tools/findText.js.map +0 -1
  153. package/dist/tools/getMediaInfo.d.ts +0 -3
  154. package/dist/tools/getMediaInfo.d.ts.map +0 -1
  155. package/dist/tools/getMediaInfo.js.map +0 -1
  156. package/dist/tools/getSession.d.ts +0 -3
  157. package/dist/tools/getSession.d.ts.map +0 -1
  158. package/dist/tools/getSession.js.map +0 -1
  159. package/dist/tools/listAudioDevices.d.ts +0 -3
  160. package/dist/tools/listAudioDevices.d.ts.map +0 -1
  161. package/dist/tools/listAudioDevices.js.map +0 -1
  162. package/dist/tools/listSessions.d.ts +0 -3
  163. package/dist/tools/listSessions.d.ts.map +0 -1
  164. package/dist/tools/listSessions.js.map +0 -1
  165. package/dist/tools/musicBed.d.ts +0 -3
  166. package/dist/tools/musicBed.d.ts.map +0 -1
  167. package/dist/tools/musicBed.js.map +0 -1
  168. package/dist/tools/normalizeAudio.d.ts +0 -3
  169. package/dist/tools/normalizeAudio.d.ts.map +0 -1
  170. package/dist/tools/normalizeAudio.js.map +0 -1
  171. package/dist/tools/overlay.d.ts +0 -3
  172. package/dist/tools/overlay.d.ts.map +0 -1
  173. package/dist/tools/overlay.js.map +0 -1
  174. package/dist/tools/pipeline.d.ts +0 -3
  175. package/dist/tools/pipeline.d.ts.map +0 -1
  176. package/dist/tools/pipeline.js.map +0 -1
  177. package/dist/tools/readEvents.d.ts +0 -6
  178. package/dist/tools/readEvents.d.ts.map +0 -1
  179. package/dist/tools/readEvents.js.map +0 -1
  180. package/dist/tools/redactRegion.d.ts +0 -13
  181. package/dist/tools/redactRegion.d.ts.map +0 -1
  182. package/dist/tools/redactRegion.js.map +0 -1
  183. package/dist/tools/reframe.d.ts +0 -3
  184. package/dist/tools/reframe.d.ts.map +0 -1
  185. package/dist/tools/reframe.js.map +0 -1
  186. package/dist/tools/reviewRecording.d.ts +0 -5
  187. package/dist/tools/reviewRecording.d.ts.map +0 -1
  188. package/dist/tools/reviewRecording.js.map +0 -1
  189. package/dist/tools/sampleFrames.d.ts +0 -3
  190. package/dist/tools/sampleFrames.d.ts.map +0 -1
  191. package/dist/tools/sampleFrames.js.map +0 -1
  192. package/dist/tools/scale.d.ts +0 -3
  193. package/dist/tools/scale.d.ts.map +0 -1
  194. package/dist/tools/scale.js.map +0 -1
  195. package/dist/tools/screenDiff.d.ts +0 -3
  196. package/dist/tools/screenDiff.d.ts.map +0 -1
  197. package/dist/tools/screenDiff.js.map +0 -1
  198. package/dist/tools/screenshot.d.ts +0 -3
  199. package/dist/tools/screenshot.d.ts.map +0 -1
  200. package/dist/tools/screenshot.js.map +0 -1
  201. package/dist/tools/speed.d.ts +0 -3
  202. package/dist/tools/speed.d.ts.map +0 -1
  203. package/dist/tools/speed.js.map +0 -1
  204. package/dist/tools/startRecording.d.ts +0 -3
  205. package/dist/tools/startRecording.d.ts.map +0 -1
  206. package/dist/tools/startRecording.js.map +0 -1
  207. package/dist/tools/stopRecording.d.ts +0 -3
  208. package/dist/tools/stopRecording.d.ts.map +0 -1
  209. package/dist/tools/stopRecording.js.map +0 -1
  210. package/dist/tools/titleCard.d.ts +0 -3
  211. package/dist/tools/titleCard.d.ts.map +0 -1
  212. package/dist/tools/titleCard.js.map +0 -1
  213. package/dist/tools/transcribe.d.ts +0 -3
  214. package/dist/tools/transcribe.d.ts.map +0 -1
  215. package/dist/tools/transcribe.js.map +0 -1
  216. package/dist/tools/trim.d.ts +0 -3
  217. package/dist/tools/trim.d.ts.map +0 -1
  218. package/dist/tools/trim.js.map +0 -1
  219. package/dist/tools/waitForChange.d.ts +0 -3
  220. package/dist/tools/waitForChange.d.ts.map +0 -1
  221. package/dist/tools/waitForChange.js.map +0 -1
  222. package/dist/tools/xfadeTransition.d.ts +0 -3
  223. package/dist/tools/xfadeTransition.d.ts.map +0 -1
  224. package/dist/tools/xfadeTransition.js.map +0 -1
  225. package/dist/tools/zoom.d.ts +0 -15
  226. package/dist/tools/zoom.d.ts.map +0 -1
  227. package/dist/tools/zoom.js.map +0 -1
  228. package/dist/utils/anim.d.ts +0 -33
  229. package/dist/utils/anim.d.ts.map +0 -1
  230. package/dist/utils/anim.js.map +0 -1
  231. package/dist/utils/animExport.d.ts +0 -27
  232. package/dist/utils/animExport.d.ts.map +0 -1
  233. package/dist/utils/animExport.js.map +0 -1
  234. package/dist/utils/audio.d.ts +0 -49
  235. package/dist/utils/audio.d.ts.map +0 -1
  236. package/dist/utils/audio.js.map +0 -1
  237. package/dist/utils/audioDevices.d.ts +0 -33
  238. package/dist/utils/audioDevices.d.ts.map +0 -1
  239. package/dist/utils/audioDevices.js.map +0 -1
  240. package/dist/utils/callout.d.ts +0 -72
  241. package/dist/utils/callout.d.ts.map +0 -1
  242. package/dist/utils/callout.js.map +0 -1
  243. package/dist/utils/calloutAssets.d.ts +0 -3
  244. package/dist/utils/calloutAssets.d.ts.map +0 -1
  245. package/dist/utils/calloutAssets.js.map +0 -1
  246. package/dist/utils/captions.d.ts +0 -26
  247. package/dist/utils/captions.d.ts.map +0 -1
  248. package/dist/utils/captions.js.map +0 -1
  249. package/dist/utils/diff.d.ts +0 -112
  250. package/dist/utils/diff.d.ts.map +0 -1
  251. package/dist/utils/diff.js.map +0 -1
  252. package/dist/utils/errors.d.ts +0 -33
  253. package/dist/utils/errors.d.ts.map +0 -1
  254. package/dist/utils/errors.js.map +0 -1
  255. package/dist/utils/events.d.ts +0 -143
  256. package/dist/utils/events.d.ts.map +0 -1
  257. package/dist/utils/events.js.map +0 -1
  258. package/dist/utils/ffmpeg.d.ts +0 -50
  259. package/dist/utils/ffmpeg.d.ts.map +0 -1
  260. package/dist/utils/ffmpeg.js.map +0 -1
  261. package/dist/utils/fonts.d.ts +0 -17
  262. package/dist/utils/fonts.d.ts.map +0 -1
  263. package/dist/utils/fonts.js.map +0 -1
  264. package/dist/utils/idle.d.ts +0 -23
  265. package/dist/utils/idle.d.ts.map +0 -1
  266. package/dist/utils/idle.js.map +0 -1
  267. package/dist/utils/images.d.ts +0 -21
  268. package/dist/utils/images.d.ts.map +0 -1
  269. package/dist/utils/images.js.map +0 -1
  270. package/dist/utils/jobs.d.ts +0 -44
  271. package/dist/utils/jobs.d.ts.map +0 -1
  272. package/dist/utils/jobs.js.map +0 -1
  273. package/dist/utils/lifecycle.d.ts +0 -29
  274. package/dist/utils/lifecycle.d.ts.map +0 -1
  275. package/dist/utils/lifecycle.js.map +0 -1
  276. package/dist/utils/media.d.ts +0 -272
  277. package/dist/utils/media.d.ts.map +0 -1
  278. package/dist/utils/media.js.map +0 -1
  279. package/dist/utils/monitors.d.ts +0 -47
  280. package/dist/utils/monitors.d.ts.map +0 -1
  281. package/dist/utils/monitors.js.map +0 -1
  282. package/dist/utils/ocr.d.ts +0 -50
  283. package/dist/utils/ocr.d.ts.map +0 -1
  284. package/dist/utils/ocr.js.map +0 -1
  285. package/dist/utils/paths.d.ts +0 -28
  286. package/dist/utils/paths.d.ts.map +0 -1
  287. package/dist/utils/paths.js.map +0 -1
  288. package/dist/utils/pipeline.d.ts +0 -69
  289. package/dist/utils/pipeline.d.ts.map +0 -1
  290. package/dist/utils/pipeline.js.map +0 -1
  291. package/dist/utils/player.d.ts +0 -30
  292. package/dist/utils/player.d.ts.map +0 -1
  293. package/dist/utils/player.js.map +0 -1
  294. package/dist/utils/produce.d.ts +0 -126
  295. package/dist/utils/produce.d.ts.map +0 -1
  296. package/dist/utils/produce.js.map +0 -1
  297. package/dist/utils/resolveTarget.d.ts +0 -32
  298. package/dist/utils/resolveTarget.d.ts.map +0 -1
  299. package/dist/utils/resolveTarget.js.map +0 -1
  300. package/dist/utils/retention.d.ts +0 -10
  301. package/dist/utils/retention.d.ts.map +0 -1
  302. package/dist/utils/retention.js.map +0 -1
  303. package/dist/utils/sessions.d.ts +0 -154
  304. package/dist/utils/sessions.d.ts.map +0 -1
  305. package/dist/utils/sessions.js.map +0 -1
  306. package/dist/utils/sheet.d.ts +0 -26
  307. package/dist/utils/sheet.d.ts.map +0 -1
  308. package/dist/utils/sheet.js.map +0 -1
  309. package/dist/utils/still.d.ts +0 -7
  310. package/dist/utils/still.d.ts.map +0 -1
  311. package/dist/utils/still.js.map +0 -1
  312. package/dist/utils/targets.d.ts +0 -113
  313. package/dist/utils/targets.d.ts.map +0 -1
  314. package/dist/utils/targets.js.map +0 -1
  315. package/dist/utils/validate.d.ts +0 -15
  316. package/dist/utils/validate.d.ts.map +0 -1
  317. package/dist/utils/validate.js.map +0 -1
  318. package/dist/utils/wgc.d.ts +0 -46
  319. package/dist/utils/wgc.d.ts.map +0 -1
  320. package/dist/utils/wgc.js.map +0 -1
  321. package/dist/utils/windows.d.ts +0 -94
  322. package/dist/utils/windows.d.ts.map +0 -1
  323. package/dist/utils/windows.js.map +0 -1
  324. package/dist/utils/zoom.d.ts +0 -95
  325. package/dist/utils/zoom.d.ts.map +0 -1
  326. package/dist/utils/zoom.js.map +0 -1
  327. package/dist/wgcRecorder.d.ts +0 -2
  328. package/dist/wgcRecorder.d.ts.map +0 -1
  329. package/dist/wgcRecorder.js.map +0 -1
@@ -3,101 +3,105 @@ import { extname, join } from "node:path";
3
3
  import { existsSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
6
+ import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
6
7
  import { requireFfmpeg, runFfmpeg, probeMedia } from "../utils/ffmpeg.js";
8
+ import { jobTimeoutMs } from "../utils/jobs.js";
7
9
  import { resolveCaptureTarget } from "../utils/resolveTarget.js";
8
10
  import { captureStill } from "../utils/still.js";
9
11
  import { buildHighlightArgs, targetSize } from "../utils/diff.js";
10
12
  import { recognize, mergePasses, findMatches, redactionRects, passScales } from "../utils/ocr.js";
11
13
  import { buildSampleByFpsArgs, planFpsSampling } from "../utils/media.js";
12
14
  import { windowMatchReport } from "../utils/windows.js";
15
+ import { confirmCapture, describeTarget } from "../utils/consent.js";
13
16
  import { subdir, stamp, rand, stillOutput } from "../utils/paths.js";
14
17
  import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
15
18
  const IMAGE_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".bmp", ".gif", ".webp", ".tif", ".tiff"]);
16
19
  const MAX_LINES = 300;
17
- /** Default and largest frame count for a whole-clip scan (#204). */
18
20
  export const DEFAULT_SCAN_FRAMES = 30;
19
21
  export const MAX_SCAN_FRAMES = 120;
20
22
  const inputSchema = {
21
23
  target: z
22
24
  .string()
23
25
  .optional()
24
- .describe("Read text live from the screen: 'full' | 'monitor:<index>' | 'window:<title>' (or window:exe=<app.exe> / window:hwnd=<handle>) | 'region:...'."),
25
- input: z.string().optional().describe("Or read text from an image or video file (one of target / input)."),
26
- timestamp: z.number().nonnegative().optional().describe("For a video input: the second to read (default 0). Ignored with scanEverySec."),
26
+ .describe("Live screen target (full | monitor:<i> | window:... | region:...), or pass input."),
27
+ input: z.string().optional().describe("Image or video file to read instead of a live target."),
28
+ timestamp: z.number().nonnegative().optional().describe("Video input: second to read (default 0)."),
27
29
  scanEverySec: z
28
30
  .number()
29
31
  .positive()
30
32
  .optional()
31
- .describe("For a video input: read a frame every N seconds across the whole clip instead of one frame, so " +
32
- "text shown at any moment is found (use it to check a clip for secrets before sharing). Each match " +
33
- "gets its time, and redactRegions get start/end. The interval widens to stay within maxFrames."),
33
+ .describe("Video input: scan a frame every N s across the clip (e.g. for secrets before sharing); matches " +
34
+ "and redactRegions get times. Widens to stay within maxFrames."),
34
35
  maxFrames: z
35
36
  .number()
36
37
  .int()
37
38
  .min(1)
38
39
  .max(MAX_SCAN_FRAMES)
39
40
  .optional()
40
- .describe(`With scanEverySec: most frames to read (default ${DEFAULT_SCAN_FRAMES}); each takes about a second.`),
41
- exactTitle: z.boolean().optional().describe("For window: targets, match the title exactly (default false)."),
41
+ .describe(`scanEverySec frame cap (default ${DEFAULT_SCAN_FRAMES}; ~1 s each).`),
42
+ exactTitle: z.boolean().optional().describe("window: targets match the whole title only (default false)."),
42
43
  backend: z
43
44
  .enum(["gdigrab", "wgc"])
44
45
  .optional()
45
- .describe("For a live target: gdigrab (default) reads what is visible; 'wgc' (window: targets, FFmpeg 8+) " +
46
- "reads the window's own surface even when other windows cover it."),
46
+ .describe("Live target: gdigrab (default) = what is visible; wgc (window:, FFmpeg 8+) = the window even if covered."),
47
47
  query: z
48
48
  .string()
49
49
  .optional()
50
- .describe("Text to look for. Case-insensitive, and tolerant of common OCR misreads (_ vs -, I vs l, " +
51
- "O vs 0; regexes get the _ vs - tolerance). Without a query, all recognised text is returned."),
50
+ .describe("Text to find (case-insensitive, tolerates OCR misreads like I/l, O/0, _/-). Omit to return all text."),
52
51
  regex: z.boolean().optional().describe("Treat query as a regular expression (case-insensitive)."),
53
52
  redact: z
54
53
  .boolean()
55
54
  .optional()
56
- .describe("Also return padded rectangles around each match, ready to pass to redact_region " +
57
- "(regions) to cover them. Detection is best-effort: review the result."),
55
+ .describe("Also return padded match rectangles ready for redact_region's regions."),
58
56
  keep: z
59
57
  .boolean()
60
58
  .optional()
61
- .describe("For a live target: keep the captured screenshot and return its path (default false: it is " +
62
- "deleted after reading, since it may show the secrets being looked for)."),
59
+ .describe("Live target: keep the capture and return its path (default false: deleted after reading)."),
63
60
  returnImage: z
64
61
  .boolean()
65
62
  .optional()
66
- .describe("Return the image inline with matches outlined in red (default true when there is a query)."),
63
+ .describe("Return the image with matches outlined (default: true with a query)."),
67
64
  };
68
- /** OCR several frames in one PowerShell run: each frame is upscaled for every
69
- * pass (passScales), and the passes are merged back per frame. */
70
- async function readFrames(sources, work) {
71
- const sized = await Promise.all(sources.map((s) => probeMedia(s)));
65
+ async function readFrames(sources, work, signal) {
66
+ const sized = await Promise.all(sources.map(async (source) => {
67
+ const { width, height } = await probeMedia(source);
68
+ if (!width || !height)
69
+ throw new ScreencastError("Could not read the image size.");
70
+ return { source, width, height };
71
+ }));
72
72
  const passes = [];
73
73
  const passScaleList = [];
74
74
  const owner = [];
75
- for (let f = 0; f < sources.length; f++) {
76
- const { width, height } = sized[f];
77
- if (!width || !height)
78
- throw new ScreencastError("Could not read the image size.");
75
+ for (const [f, { source, width, height }] of sized.entries()) {
79
76
  for (const [i, scale] of passScales(width, height).entries()) {
80
77
  const out = join(work, `pass${f}-${i}.png`);
81
- await runFfmpeg(["-y", "-v", "error", "-i", sources[f], "-vf", `scale=iw*${scale}:ih*${scale}:flags=lanczos`, out], 60_000);
78
+ await runFfmpeg(["-y", "-v", "error", "-i", source, "-vf", `scale=iw*${scale}:ih*${scale}:flags=lanczos`, out], 60_000, {
79
+ signal,
80
+ });
82
81
  passes.push(out);
83
82
  passScaleList.push(scale);
84
83
  owner.push(f);
85
84
  }
86
85
  }
87
86
  const results = await recognize(passes, passScaleList);
88
- return sources.map((_, f) => ({
87
+ return sized.map(({ width, height }, f) => ({
89
88
  lines: mergePasses(results.filter((_r, i) => owner[i] === f)),
90
- width: sized[f].width,
91
- height: sized[f].height,
89
+ width,
90
+ height,
92
91
  }));
93
92
  }
94
93
  export function register(server) {
95
- server.tool("find_text", "Read text on screen or in an image/video frame with the OCR engine built into Windows " +
96
- "(no install), with each line's and match's bounding box. Find where a label or button " +
97
- "is, check what the screen says, or locate secrets (e.g. regex 'sk-|ghp_|api.?key') and get " +
98
- "redact_region rectangles for them; for a video, scanEverySec checks the whole clip. Boxes are " +
99
- "in the image's pixels; for a live target, add `origin` for desktop coordinates. Best-effort " +
100
- "detection: always review.", inputSchema, async (args) => {
94
+ server.registerTool("find_text", {
95
+ title: "Find Text (OCR)",
96
+ description: "OCR (built into Windows) on the screen, an image, or video frames, with line and match boxes " +
97
+ "in image pixels (add `origin` for desktop coordinates). Locate UI text or secrets (e.g. regex " +
98
+ "'sk-|ghp_|api.?key') to redact. Best-effort: review results.",
99
+ inputSchema,
100
+ outputSchema: looseOutput({
101
+ imageSize: looseOutput({ width: z.number(), height: z.number() }),
102
+ }),
103
+ annotations: READ_ONLY,
104
+ }, async (args, extra) => {
101
105
  try {
102
106
  requireFfmpeg();
103
107
  if ((args.target === undefined) === (args.input === undefined)) {
@@ -106,21 +110,18 @@ export function register(server) {
106
110
  const work = mkdtempSync(join(tmpdir(), "screencast-ocr-"));
107
111
  try {
108
112
  if (args.scanEverySec !== undefined)
109
- return await scanClip(args, work);
110
- // 1. Get the source as one PNG frame.
113
+ return await scanClip(args, work, extra.signal);
111
114
  let source;
112
115
  let windowReport = {};
113
116
  let origin;
114
117
  if (args.target !== undefined) {
115
118
  const resolved = await resolveCaptureTarget(args.target, { exactTitle: args.exactTitle, backend: args.backend });
116
- // Captures go to the work dir and vanish with it unless kept (#209).
117
119
  source = args.keep ? join(subdir("screenshots"), `ocr-${stamp()}-${rand()}.png`) : join(work, "capture.png");
118
120
  const backend = args.backend ?? "gdigrab";
121
+ await confirmCapture(server, `Capture ${describeTarget(args.target, resolved.window)} once to read the text on it?`, extra.signal);
119
122
  await captureStill(resolved, source, backend);
120
123
  if (resolved.window)
121
124
  windowReport = windowMatchReport(resolved.window);
122
- // Where the image sits on the desktop: boxes are image pixels (#233).
123
- // A WGC still is the window's client area.
124
125
  const area = targetSize(resolved.target, resolved.monitors);
125
126
  origin = backend === "wgc" && resolved.window?.client ? resolved.window.client : { x: area.x, y: area.y };
126
127
  }
@@ -129,17 +130,18 @@ export function register(server) {
129
130
  throw new ScreencastError(`Input file not found: ${args.input}`);
130
131
  const isImage = IMAGE_EXTENSIONS.has(extname(args.input).toLowerCase());
131
132
  source = join(work, "frame.png");
132
- await runFfmpeg(["-y", "-v", "error", ...(isImage ? [] : ["-ss", String(args.timestamp ?? 0)]), "-i", args.input, "-frames:v", "1", ...stillOutput(source)], 60_000);
133
+ await runFfmpeg(["-y", "-v", "error", ...(isImage ? [] : ["-ss", String(args.timestamp ?? 0)]), "-i", args.input, "-frames:v", "1", ...stillOutput(source)], 60_000, { signal: extra.signal });
133
134
  }
134
- // 2. Upscaled copies for each recognition pass, then OCR them in one run.
135
- const [{ lines, width, height }] = await readFrames([source], work);
136
- // 3. Match, and optionally outline / suggest redactions.
135
+ const [frame] = await readFrames([source], work, extra.signal);
136
+ if (!frame)
137
+ throw new ScreencastError("Could not read the frame.");
138
+ const { lines, width, height } = frame;
137
139
  const matches = args.query ? findMatches(lines, args.query, args.regex === true) : [];
138
140
  const images = [];
139
141
  const wantImage = args.returnImage ?? Boolean(args.query);
140
142
  if (wantImage) {
141
143
  const shown = join(work, "shown.png");
142
- await runFfmpeg(buildHighlightArgs(source, matches, shown), 30_000);
144
+ await runFfmpeg(buildHighlightArgs(source, matches, shown), 30_000, { signal: extra.signal });
143
145
  images.push(...(await encodeInlineImages([shown], DEFAULT_MAX_IMAGE_WIDTH, 1)).images);
144
146
  }
145
147
  return okResponse({
@@ -170,11 +172,7 @@ export function register(server) {
170
172
  }
171
173
  });
172
174
  }
173
- /** Whole-clip scan (#204): OCR a frame every scanEverySec seconds (widened to
174
- * fit maxFrames) and report each match with its time. A redaction window runs
175
- * from the previous sample to the next, since the text may be on screen for
176
- * any part of the time between two samples. */
177
- async function scanClip(args, work) {
175
+ async function scanClip(args, work, signal) {
178
176
  if (args.input === undefined)
179
177
  throw new ScreencastError("scanEverySec reads a video file: pass input, not target.");
180
178
  if (!existsSync(args.input))
@@ -185,14 +183,17 @@ async function scanClip(args, work) {
185
183
  const info = await probeMedia(args.input);
186
184
  const maxFrames = args.maxFrames ?? DEFAULT_SCAN_FRAMES;
187
185
  const plan = planFpsSampling(info.videoDurationSec ?? info.durationSec, 1 / args.scanEverySec, maxFrames);
188
- await runFfmpeg(buildSampleByFpsArgs(args.input, plan.fps, join(work, "scan_%05d.png"), maxFrames), 10 * 60_000);
186
+ await runFfmpeg(buildSampleByFpsArgs(args.input, plan.fps, join(work, "scan_%05d.png"), maxFrames), jobTimeoutMs(info.durationSec), { signal });
189
187
  const frames = readdirSync(work).filter((f) => f.startsWith("scan_")).sort().map((f) => join(work, f));
190
188
  if (frames.length === 0)
191
189
  throw new ScreencastError("Could not read any frames from the video.");
192
190
  const step = 1 / plan.fps;
193
- const times = frames.map((_, i) => Math.round(i * step * 1000) / 1000);
194
- const end = info.videoDurationSec ?? info.durationSec ?? times[times.length - 1] + step;
195
- const read = await readFrames(frames, work);
191
+ const timeAt = (i) => Math.round(i * step * 1000) / 1000;
192
+ const end = info.videoDurationSec ?? info.durationSec ?? timeAt(frames.length - 1) + step;
193
+ const read = await readFrames(frames, work, signal);
194
+ const [size] = read;
195
+ if (!size)
196
+ throw new ScreencastError("Could not read any frames from the video.");
196
197
  const matches = [];
197
198
  const redactRegions = [];
198
199
  const seenLines = new Set();
@@ -202,25 +203,29 @@ async function scanClip(args, work) {
202
203
  if (!args.query)
203
204
  return;
204
205
  const hits = findMatches(frame.lines, args.query, args.regex === true);
205
- const start = Math.max(0, Math.round((times[i] - step) * 1000) / 1000);
206
- const stop = Math.min(end, Math.round((times[i] + step) * 1000) / 1000);
207
- for (const [k, rect] of redactionRects(hits, frame).entries()) {
208
- matches.push({ t: times[i], ...hits[k] });
209
- redactRegions.push({ ...rect, start, end: stop });
206
+ const t = timeAt(i);
207
+ const start = Math.max(0, Math.round((t - step) * 1000) / 1000);
208
+ const stop = Math.min(end, Math.round((t + step) * 1000) / 1000);
209
+ const rects = redactionRects(hits, frame);
210
+ for (const [k, hit] of hits.entries()) {
211
+ matches.push({ t, ...hit });
212
+ const rect = rects[k];
213
+ if (rect)
214
+ redactRegions.push({ ...rect, start, end: stop });
210
215
  }
211
216
  });
212
217
  const images = [];
213
218
  const first = matches[0];
214
- if ((args.returnImage ?? Boolean(args.query)) && first) {
215
- const i = times.indexOf(first.t);
219
+ const firstFrame = first && frames.find((_, i) => timeAt(i) === first.t);
220
+ if ((args.returnImage ?? Boolean(args.query)) && first && firstFrame) {
216
221
  const shown = join(work, "shown.png");
217
- await runFfmpeg(buildHighlightArgs(frames[i], matches.filter((m) => m.t === first.t), shown), 30_000);
222
+ await runFfmpeg(buildHighlightArgs(firstFrame, matches.filter((m) => m.t === first.t), shown), 30_000, { signal });
218
223
  images.push(...(await encodeInlineImages([shown], DEFAULT_MAX_IMAGE_WIDTH, 1)).images);
219
224
  }
220
225
  const text = [...seenLines].join("\n");
221
226
  return okResponse({
222
227
  input: args.input,
223
- imageSize: { width: read[0].width, height: read[0].height },
228
+ imageSize: { width: size.width, height: size.height },
224
229
  scan: {
225
230
  everySec: Math.round(step * 1000) / 1000,
226
231
  framesScanned: frames.length,
@@ -239,4 +244,3 @@ async function scanClip(args, work) {
239
244
  "or stylised text, can be missed. Review before sharing, especially for redaction.",
240
245
  }, images);
241
246
  }
242
- //# sourceMappingURL=findText.js.map
@@ -1,13 +1,28 @@
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 { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
4
5
  import { probeMedia } from "../utils/ffmpeg.js";
5
6
  const inputSchema = {
6
7
  input: z.string().min(1).describe("Path to the media file to probe."),
7
8
  };
8
9
  export function register(server) {
9
- server.tool("get_media_info", "Probe a media file with ffprobe and return duration, resolution, frame " +
10
- "rate, codecs, container format, and size.", inputSchema, async (args) => {
10
+ server.registerTool("get_media_info", {
11
+ title: "Get Media Info",
12
+ description: "Probe a media file with ffprobe and return duration, resolution, frame " +
13
+ "rate, codecs, container format, and size.",
14
+ inputSchema,
15
+ outputSchema: looseOutput({
16
+ input: z.string(),
17
+ durationSec: z.number().nullable(),
18
+ width: z.number().nullable(),
19
+ height: z.number().nullable(),
20
+ fps: z.number().nullable(),
21
+ videoCodec: z.string().nullable(),
22
+ audioCodec: z.string().nullable(),
23
+ }),
24
+ annotations: READ_ONLY,
25
+ }, async (args) => {
11
26
  try {
12
27
  if (!existsSync(args.input)) {
13
28
  throw new ScreencastError(`Input file not found: ${args.input}`);
@@ -19,4 +34,3 @@ export function register(server) {
19
34
  }
20
35
  });
21
36
  }
22
- //# sourceMappingURL=getMediaInfo.js.map
@@ -1,14 +1,27 @@
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 { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
4
5
  import { isAlive } from "../utils/sessions.js";
5
6
  import { getStore } from "../context.js";
6
7
  const inputSchema = {
7
8
  sessionId: z.string().min(1).describe("Session id returned by start_recording."),
8
9
  };
9
10
  export function register(server) {
10
- server.tool("get_session", "Inspect a single recording session by id, including live status and " +
11
- "whether its output file exists on disk.", inputSchema, async (args) => {
11
+ server.registerTool("get_session", {
12
+ title: "Get Session",
13
+ description: "Inspect a single recording session by id, including live status and " +
14
+ "whether its output file exists on disk.",
15
+ inputSchema,
16
+ outputSchema: looseOutput({
17
+ id: z.string(),
18
+ status: z.string(),
19
+ outputPath: z.string(),
20
+ alive: z.boolean(),
21
+ fileExists: z.boolean(),
22
+ }),
23
+ annotations: READ_ONLY,
24
+ }, async (args) => {
12
25
  try {
13
26
  const record = getStore().get(args.sessionId);
14
27
  if (!record) {
@@ -25,4 +38,3 @@ export function register(server) {
25
38
  }
26
39
  });
27
40
  }
28
- //# sourceMappingURL=getSession.js.map
@@ -1,15 +1,23 @@
1
+ import { z } from "zod";
1
2
  import { errorResponse, okResponse } from "../utils/errors.js";
3
+ import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
2
4
  import { requireFfmpeg } from "../utils/ffmpeg.js";
3
5
  import { listDshowAudioDevices, pickLoopbackDevice, NO_LOOPBACK_HINT, } from "../utils/audioDevices.js";
4
6
  export function register(server) {
5
- server.tool("list_audio_devices", "List the DirectShow audio devices ffmpeg can see on this machine, and flag a " +
6
- "likely system-audio loopback device. Use the returned name as the `audio` " +
7
- "device for start_recording. System audio needs a loopback device (Stereo " +
8
- "Mix or a virtual-audio driver); microphone capture is not supported.", {}, async () => {
7
+ server.registerTool("list_audio_devices", {
8
+ title: "List Audio Devices",
9
+ description: "List DirectShow audio devices and flag a likely loopback (Stereo Mix or a virtual-audio " +
10
+ "driver), for start_recording's audio.device.",
11
+ inputSchema: {},
12
+ outputSchema: looseOutput({
13
+ devices: z.array(z.unknown()),
14
+ loopbackDevice: z.string().nullable(),
15
+ note: z.string(),
16
+ }),
17
+ annotations: READ_ONLY,
18
+ }, async () => {
9
19
  try {
10
20
  requireFfmpeg();
11
- // Always re-probe: this is the explicit "show me what's available" call,
12
- // so a device enabled since the last recording must show up.
13
21
  const devices = await listDshowAudioDevices(true);
14
22
  const loopback = pickLoopbackDevice(devices);
15
23
  return okResponse({
@@ -25,4 +33,3 @@ export function register(server) {
25
33
  }
26
34
  });
27
35
  }
28
- //# sourceMappingURL=listAudioDevices.js.map
@@ -1,9 +1,20 @@
1
+ import { z } from "zod";
1
2
  import { errorResponse, okResponse } from "../utils/errors.js";
3
+ import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
2
4
  import { isAlive } from "../utils/sessions.js";
3
5
  import { getStore } from "../context.js";
4
6
  export function register(server) {
5
- server.tool("list_sessions", "List all recording sessions (active and finished) with their status, " +
6
- "target, output path, and whether the process is still alive.", {}, async () => {
7
+ server.registerTool("list_sessions", {
8
+ title: "List Sessions",
9
+ description: "List all recording sessions (active and finished) with their status, " +
10
+ "target, output path, and whether the process is still alive.",
11
+ inputSchema: {},
12
+ outputSchema: looseOutput({
13
+ count: z.number().int(),
14
+ sessions: z.array(looseOutput({ id: z.string(), status: z.string(), outputPath: z.string(), alive: z.boolean() })),
15
+ }),
16
+ annotations: READ_ONLY,
17
+ }, async () => {
7
18
  try {
8
19
  const sessions = getStore()
9
20
  .list()
@@ -15,4 +26,3 @@ export function register(server) {
15
26
  }
16
27
  });
17
28
  }
18
- //# sourceMappingURL=listSessions.js.map
@@ -0,0 +1,76 @@
1
+ import { z } from "zod";
2
+ import { errorResponse, okResponse } from "../utils/errors.js";
3
+ import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
4
+ import { getMonitors } from "../utils/monitors.js";
5
+ import { getRawWindows } from "../utils/windows.js";
6
+ import { wgcAvailable } from "../utils/ffmpeg.js";
7
+ import { buildTargetList } from "../utils/targetList.js";
8
+ const inputSchema = {
9
+ exe: z
10
+ .string()
11
+ .min(1)
12
+ .optional()
13
+ .describe("Only list windows of this executable, e.g. 'Code.exe' or 'code'."),
14
+ titleContains: z
15
+ .string()
16
+ .min(1)
17
+ .optional()
18
+ .describe("Only list windows whose title contains this text (case-insensitive)."),
19
+ capturableOnly: z
20
+ .boolean()
21
+ .optional()
22
+ .describe("Leave out windows neither backend can capture (minimized, off screen). Default false."),
23
+ };
24
+ const bounds = z.object({ x: z.number(), y: z.number(), width: z.number(), height: z.number() });
25
+ const outputSchema = looseOutput({
26
+ full: z.looseObject({ target: z.literal("full"), bounds }),
27
+ monitors: z.array(z.looseObject({
28
+ target: z.string(),
29
+ index: z.number(),
30
+ primary: z.boolean(),
31
+ bounds,
32
+ dpi: z.number().nullable(),
33
+ scale: z.number().nullable(),
34
+ })),
35
+ windows: z.array(z.looseObject({
36
+ target: z.string(),
37
+ title: z.string(),
38
+ exe: z.string().nullable(),
39
+ pid: z.number().nullable(),
40
+ hwnd: z.number().nullable(),
41
+ bounds,
42
+ minimized: z.boolean(),
43
+ cloaked: z.boolean(),
44
+ capturable: z.boolean(),
45
+ wgcCapturable: z.boolean(),
46
+ })),
47
+ wgcAvailable: z.boolean(),
48
+ note: z.string(),
49
+ });
50
+ export function register(server) {
51
+ server.registerTool("list_targets", {
52
+ title: "List Capture Targets",
53
+ description: "List the desktop, monitors, and visible windows (topmost first, with capturability per backend). " +
54
+ "Each entry has a `target` string to pass as-is to capture tools; use it instead of guessing a title.",
55
+ inputSchema,
56
+ outputSchema,
57
+ annotations: READ_ONLY,
58
+ }, async (args) => {
59
+ try {
60
+ const [monitors, windows] = await Promise.all([getMonitors(), getRawWindows()]);
61
+ const list = buildTargetList(monitors, windows, {
62
+ wgcAvailable: wgcAvailable(),
63
+ filter: { exe: args.exe, titleContains: args.titleContains, capturableOnly: args.capturableOnly },
64
+ });
65
+ return okResponse({
66
+ ...list,
67
+ note: "Pass a target string unchanged. A window handle lasts until the app closes the window; " +
68
+ "list again after an app restarts, or target it by window:exe=<app.exe>. " +
69
+ 'A window with capturable false but wgcCapturable true needs backend: "wgc".',
70
+ });
71
+ }
72
+ catch (error) {
73
+ return errorResponse(error);
74
+ }
75
+ });
76
+ }
@@ -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 { buildMusicBedArgs } from "../utils/produce.js";
@@ -8,19 +9,23 @@ import { editOutputExt, assertEditContainer } from "../utils/media.js";
8
9
  import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
9
10
  const inputSchema = {
10
11
  video: z.string().min(1).describe("Path to the video."),
11
- music: z.string().min(1).describe("Path to the music audio file (looped/trimmed to the video length)."),
12
- musicVolume: z.number().nonnegative().optional().describe("Music level 0..1 (default 0.25 over existing audio, 0.8 alone)."),
13
- fadeIn: z.number().nonnegative().optional().describe("Music fade-in seconds (default 1)."),
14
- fadeOut: z.number().nonnegative().optional().describe("Music fade-out seconds (default 2)."),
15
- duck: z.boolean().optional().describe("Duck the music under the original audio via a sidechain (default false)."),
12
+ music: z.string().min(1).describe("Music audio file."),
13
+ musicVolume: z.number().nonnegative().optional().describe("0..1 (default 0.25 over existing audio, 0.8 alone)."),
14
+ fadeIn: z.number().nonnegative().optional().describe("Fade-in seconds (default 1)."),
15
+ fadeOut: z.number().nonnegative().optional().describe("Fade-out seconds (default 2)."),
16
+ duck: z.boolean().optional().describe("Duck the music under the original audio (default false)."),
16
17
  output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
17
18
  overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
18
19
  };
19
20
  export function register(server) {
20
- server.tool("music_bed", "Lay a music track under a video: the music is looped/trimmed to the video " +
21
- "length, faded in and out, and leveled. When the video already has audio " +
22
- "the two are mixed, optionally ducking the music under the original. The " +
23
- "video stream is copied; only audio is re-encoded.", inputSchema, async (args, extra) => {
21
+ server.registerTool("music_bed", {
22
+ title: "Add Music Bed",
23
+ description: "Lay music under a video: looped or trimmed to length, faded, leveled, and mixed with any " +
24
+ "existing audio. Video is stream-copied.",
25
+ inputSchema,
26
+ outputSchema: OUTPUT_PATH,
27
+ annotations: WRITES_FILE,
28
+ }, async (args, extra) => {
24
29
  try {
25
30
  requireFfmpeg();
26
31
  for (const f of [args.video, args.music]) {
@@ -48,4 +53,3 @@ export function register(server) {
48
53
  }
49
54
  });
50
55
  }
51
- //# sourceMappingURL=musicBed.js.map
@@ -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, runCapture, probeMedia } from "../utils/ffmpeg.js";
5
6
  import { runEditJob, jobTimeoutMs } from "../utils/jobs.js";
6
7
  import { loudnessTarget, buildLoudnessMeasureArgs, buildLoudnessApplyArgs, parseLoudnorm, } from "../utils/audio.js";
@@ -11,15 +12,19 @@ const inputSchema = {
11
12
  target: z
12
13
  .union([z.enum(["youtube", "podcast", "broadcast"]), z.number()])
13
14
  .optional()
14
- .describe("Loudness target: 'youtube' (-14 LUFS, default), 'podcast' (-16 LUFS), 'broadcast' " +
15
- "(EBU R128, -23 LUFS), or a LUFS number such as -18."),
15
+ .describe("youtube (-14 LUFS, default), podcast (-16), broadcast (-23), or a LUFS number."),
16
16
  output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
17
17
  overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
18
18
  };
19
19
  export function register(server) {
20
- server.tool("normalize_audio", "Normalize a recording's loudness to a delivery target (EBU R128, two-pass loudnorm) so " +
21
- "narration and system audio are neither too quiet nor clipping. Video is copied " +
22
- "untouched. Reports the loudness before and after.", inputSchema, async (args, extra) => {
20
+ server.registerTool("normalize_audio", {
21
+ title: "Normalize Loudness",
22
+ description: "Normalize loudness to a delivery target (two-pass EBU R128 loudnorm); video is copied. " +
23
+ "Reports loudness before and after.",
24
+ inputSchema,
25
+ outputSchema: OUTPUT_PATH,
26
+ annotations: WRITES_FILE,
27
+ }, async (args, extra) => {
23
28
  try {
24
29
  const { ffmpeg } = requireFfmpeg();
25
30
  if (!existsSync(args.input)) {
@@ -33,14 +38,14 @@ export function register(server) {
33
38
  const ext = editOutputExt(args.input, { audio: true });
34
39
  const output = resolveOutput(args.output, subdir("edits"), `loudnorm-${stamp()}-${rand()}${ext}`, args.overwrite);
35
40
  const timeout = jobTimeoutMs(info.durationSec);
36
- const before = await runCapture(ffmpeg, buildLoudnessMeasureArgs(args.input, t), timeout);
41
+ const before = await runCapture(ffmpeg, buildLoudnessMeasureArgs(args.input, t), timeout, { signal: extra.signal });
37
42
  const measured = parseLoudnorm(before.stderr);
38
43
  await runEditJob(buildLoudnessApplyArgs(args.input, output, t, measured), {
39
44
  output,
40
45
  durationSec: info.durationSec,
41
46
  extra,
42
47
  });
43
- const after = parseLoudnorm((await runCapture(ffmpeg, buildLoudnessMeasureArgs(output, t), timeout)).stderr);
48
+ const after = parseLoudnorm((await runCapture(ffmpeg, buildLoudnessMeasureArgs(output, t), timeout, { signal: extra.signal })).stderr);
44
49
  return okResponse({
45
50
  outputPath: output,
46
51
  target: { lufs: t.i, truePeakDb: t.tp, lra: t.lra },
@@ -53,4 +58,3 @@ export function register(server) {
53
58
  }
54
59
  });
55
60
  }
56
- //# sourceMappingURL=normalizeAudio.js.map