@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,14 +1,20 @@
1
1
  import { z } from "zod";
2
- import { existsSync, readFileSync } from "node:fs";
2
+ import { existsSync, readFileSync, rmSync } from "node:fs";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
5
+ import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
5
6
  import { requireFfmpeg, probeMedia, runFfmpegBuffer } from "../utils/ffmpeg.js";
6
7
  import { jobTimeoutMs } from "../utils/jobs.js";
7
- import { buildPlayerFramesArgs, playerFramePlan, playerFrameTimes, splitJpegs, DEFAULT_PLAYER_FRAMES, DEFAULT_PLAYER_WIDTH, MAX_PLAYER_FRAMES, MCP_APP_MIME, PLAYER_TOOL_META, PLAYER_URI, } from "../utils/player.js";
8
+ import { tempPath } from "../utils/paths.js";
9
+ import { buildPlayerFramesArgs, clientSupportsApps, parsePlayerFrameLog, pickPlayerFrames, playerFramePlan, splitJpegs, DEFAULT_PLAYER_FRAMES, DEFAULT_PLAYER_WIDTH, MAX_PLAYER_FRAMES, MCP_APP_MIME, PLAYER_TOOL_META, PLAYER_URI, } from "../utils/player.js";
8
10
  import { getStore } from "../context.js";
9
- /** The player page, shipped in assets/ui (dist/tools -> ../../assets). */
11
+ import { markersOrChapters, readMarkers } from "../utils/chapters.js";
12
+ const uiAsset = (name) => readFileSync(fileURLToPath(new URL(`../../assets/ui/${name}`, import.meta.url)), "utf8");
10
13
  export function playerHtml() {
11
- return readFileSync(fileURLToPath(new URL("../../assets/ui/player.html", import.meta.url)), "utf8");
14
+ const js = uiAsset("player.js");
15
+ if (/<\/script/i.test(js))
16
+ throw new ScreencastError("player.js must not contain a closing script tag.");
17
+ return uiAsset("player.html").replace('<script src="player.js"></script>', () => `<script>\n${js}</script>`);
12
18
  }
13
19
  function resolveInput(args) {
14
20
  if (args.sessionId) {
@@ -23,8 +29,10 @@ function resolveInput(args) {
23
29
  return args.input;
24
30
  throw new ScreencastError("Pass input or sessionId.");
25
31
  }
32
+ function markersField(markers) {
33
+ return markers && markers.length > 0 ? { markers: markers.map(({ t, label }) => ({ t, label })) } : {};
34
+ }
26
35
  export function register(server) {
27
- // The player page itself, for hosts that support MCP Apps.
28
36
  server.registerResource("review-player", PLAYER_URI, {
29
37
  title: "Recording review player",
30
38
  description: "Interactive player: scrub, trim, and draw redaction boxes on a recording.",
@@ -33,14 +41,22 @@ export function register(server) {
33
41
  contents: [{ uri: PLAYER_URI, mimeType: MCP_APP_MIME, text: playerHtml(), _meta: { ui: { prefersBorder: true } } }],
34
42
  }));
35
43
  server.registerTool("review_recording", {
36
- description: "Open a recording for a person to review. In clients that support MCP Apps it shows an " +
37
- "inline player: scrub the timeline, drag trim handles, and draw redaction boxes, then export " +
38
- "a trimmed, redacted copy (their choices run as a pipeline call). Elsewhere it returns the " +
39
- "video's details; use contact_sheet or sample_frames to look at it.",
44
+ title: "Review Recording",
45
+ description: "Open a recording for a person to review: in MCP Apps clients an inline player to scrub, trim, " +
46
+ "and redact, then export; elsewhere just the video's details.",
40
47
  inputSchema: {
41
48
  input: z.string().optional().describe("Path to the video."),
42
49
  sessionId: z.string().optional().describe("Or the session id of a stopped recording."),
43
50
  },
51
+ outputSchema: looseOutput({
52
+ input: z.string(),
53
+ durationSec: z.number().nullable(),
54
+ width: z.number().nullable(),
55
+ height: z.number().nullable(),
56
+ fps: z.number().nullable(),
57
+ hasAudio: z.boolean(),
58
+ }),
59
+ annotations: READ_ONLY,
44
60
  _meta: PLAYER_TOOL_META,
45
61
  }, async (args) => {
46
62
  try {
@@ -56,6 +72,7 @@ export function register(server) {
56
72
  height: info.height,
57
73
  fps: info.fps,
58
74
  hasAudio: info.audioCodec !== null,
75
+ ...markersField(args.sessionId ? getStore().get(args.sessionId)?.markers ?? readMarkers(input) : readMarkers(input)),
59
76
  note: "Clients with MCP Apps show an inline review player for this result. Without it, " +
60
77
  "look with contact_sheet or sample_frames, then trim and redact with pipeline.",
61
78
  });
@@ -64,27 +81,54 @@ export function register(server) {
64
81
  return errorResponse(error);
65
82
  }
66
83
  });
67
- // Called by the player (app visibility only), not by the model.
68
- server.registerTool("player_frames", {
69
- description: "Preview frames for the review player: JPEGs spread evenly over the video, with their times. " +
70
- "Used by the inline player; agents should use sample_frames or contact_sheet instead.",
84
+ const playerFrames = server.registerTool("player_frames", {
85
+ title: "Player Frames",
86
+ description: "Preview frames for the review player: JPEGs on an even grid over the video plus frames at " +
87
+ "scene changes, with their real times. Used by the inline player; agents should use " +
88
+ "sample_frames or contact_sheet instead.",
71
89
  inputSchema: {
72
90
  input: z.string().min(1).describe("Path to the video."),
73
- maxFrames: z.number().int().min(1).max(MAX_PLAYER_FRAMES).optional().describe(`Most frames (default ${DEFAULT_PLAYER_FRAMES}).`),
91
+ maxFrames: z.number().int().min(1).max(MAX_PLAYER_FRAMES).optional().describe(`Frames on the even grid (default ${DEFAULT_PLAYER_FRAMES}); scene-change frames come on top, up to as many again.`),
74
92
  width: z.number().int().min(64).max(1280).optional().describe(`Frame width (default ${DEFAULT_PLAYER_WIDTH}).`),
75
93
  },
94
+ annotations: READ_ONLY,
76
95
  _meta: { ui: { visibility: ["app"] } },
77
- }, async (args) => {
96
+ }, async (args, extra) => {
78
97
  try {
79
98
  requireFfmpeg();
80
99
  if (!existsSync(args.input))
81
100
  throw new ScreencastError(`Input file not found: ${args.input}`);
82
101
  const info = await probeMedia(args.input);
83
102
  const durationSec = info.durationSec ?? 0;
84
- const { count, fps } = playerFramePlan(durationSec, args.maxFrames ?? DEFAULT_PLAYER_FRAMES);
85
- const raw = await runFfmpegBuffer(buildPlayerFramesArgs(args.input, fps, args.width ?? DEFAULT_PLAYER_WIDTH, count), jobTimeoutMs(durationSec));
86
- const jpegs = splitJpegs(raw);
87
- const times = playerFrameTimes(durationSec, jpegs.length);
103
+ const plan = playerFramePlan(durationSec, args.maxFrames ?? DEFAULT_PLAYER_FRAMES);
104
+ const log = tempPath(".txt");
105
+ let jpegs;
106
+ let frames;
107
+ try {
108
+ const raw = await runFfmpegBuffer(buildPlayerFramesArgs(args.input, plan, args.width ?? DEFAULT_PLAYER_WIDTH, log), jobTimeoutMs(durationSec), { signal: extra.signal });
109
+ jpegs = splitJpegs(raw);
110
+ frames = parsePlayerFrameLog(existsSync(log) ? readFileSync(log, "utf8") : "").slice(0, jpegs.length);
111
+ }
112
+ finally {
113
+ rmSync(log, { force: true });
114
+ }
115
+ const [firstFrame] = frames;
116
+ if (!firstFrame)
117
+ throw new ScreencastError("ffmpeg returned no preview frames.");
118
+ const keep = pickPlayerFrames(frames, plan.count).flatMap((i) => {
119
+ const frame = frames[i];
120
+ const jpeg = jpegs[i];
121
+ return frame && jpeg ? [{ frame, jpeg }] : [];
122
+ });
123
+ const t0 = firstFrame.timeSec;
124
+ let markers = [];
125
+ try {
126
+ markers = (await markersOrChapters(args.input, extra.signal)).markers.map(({ t, label }) => ({ t, label }));
127
+ }
128
+ catch {
129
+ }
130
+ const frameTimes = keep.map(({ frame }) => Math.round((frame.timeSec - t0) * 1000) / 1000);
131
+ const sceneFrames = keep.flatMap(({ frame }, k) => (frame.scene ? [k] : []));
88
132
  return {
89
133
  content: [
90
134
  {
@@ -95,10 +139,13 @@ export function register(server) {
95
139
  width: info.width,
96
140
  height: info.height,
97
141
  hasAudio: info.audioCodec !== null,
98
- frameTimes: times,
142
+ frameTimes,
143
+ intervalSec: plan.intervalSec,
144
+ sceneFrames,
145
+ markers,
99
146
  }),
100
147
  },
101
- ...jpegs.map((j) => ({ type: "image", data: j.toString("base64"), mimeType: "image/jpeg" })),
148
+ ...keep.map(({ jpeg }) => ({ type: "image", data: jpeg.toString("base64"), mimeType: "image/jpeg" })),
102
149
  ],
103
150
  };
104
151
  }
@@ -106,5 +153,11 @@ export function register(server) {
106
153
  return errorResponse(error);
107
154
  }
108
155
  });
156
+ playerFrames.disable();
157
+ const previous = server.server.oninitialized;
158
+ server.server.oninitialized = () => {
159
+ previous?.();
160
+ if (clientSupportsApps(server.server.getClientCapabilities()))
161
+ playerFrames.enable();
162
+ };
109
163
  }
110
- //# sourceMappingURL=reviewRecording.js.map
@@ -2,77 +2,81 @@ import { z } from "zod";
2
2
  import { join } from "node:path";
3
3
  import { mkdirSync, readdirSync, existsSync, rmSync } from "node:fs";
4
4
  import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
5
+ import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
5
6
  import { requireFfmpeg, runFfmpeg, runCapture, probeMedia } from "../utils/ffmpeg.js";
6
7
  import { jobTimeoutMs } from "../utils/jobs.js";
7
8
  import { buildSampleByFpsArgs, buildSampleAtTimestampArgs, planFpsSampling, buildSceneScanArgs, parseSceneScan, pickSceneFrames, DEFAULT_SCENE_THRESHOLD, DEFAULT_MAX_FRAMES, MAX_FRAMES_CEILING, } from "../utils/media.js";
8
- import { subdir, stamp, rand, sequencePattern } from "../utils/paths.js";
9
+ import { subdir, stamp, rand, sequencePattern, resolveOutputDir } from "../utils/paths.js";
9
10
  import { encodeInlineImages, clampInlineCount, DEFAULT_MAX_IMAGE_WIDTH, DEFAULT_MAX_INLINE_IMAGES, MAX_INLINE_IMAGES, } from "../utils/images.js";
10
11
  const inputSchema = {
11
12
  input: z.string().min(1).describe("Path to the source video file."),
12
13
  mode: z
13
14
  .enum(["fps", "timestamps", "scenes"])
14
15
  .optional()
15
- .describe("How to pick frames. 'scenes' returns only frames where the screen changed " +
16
- "(plus the first frame), strongest changes first up to maxFrames, which is " +
17
- "usually the cheapest way to review a recording. Defaults to 'fps' or " +
18
- "'timestamps' depending on which of those is given."),
16
+ .describe("scenes: only frames where the screen changed (strongest first), usually the cheapest review. " +
17
+ "Default: fps or timestamps, whichever is given."),
19
18
  fps: z
20
19
  .number()
21
20
  .positive()
22
21
  .optional()
23
- .describe("Sample this many frames per second (mode 'fps')."),
22
+ .describe("Frames per second (mode fps)."),
24
23
  timestamps: z
25
24
  .array(z.number().nonnegative())
26
25
  .optional()
27
- .describe("Explicit second offsets to grab one frame at each (mode 'timestamps')."),
26
+ .describe("Seconds to grab a frame at (mode timestamps)."),
28
27
  sceneThreshold: z
29
28
  .number()
30
29
  .gt(0)
31
30
  .lt(1)
32
31
  .optional()
33
- .describe(`Mode 'scenes': how much the frame must change to count, 0-1 (default ${DEFAULT_SCENE_THRESHOLD}; ` +
34
- "raise it to keep only big changes)."),
32
+ .describe(`Mode scenes: change needed to count, 0-1 (default ${DEFAULT_SCENE_THRESHOLD}).`),
35
33
  dedupe: z
36
34
  .boolean()
37
35
  .optional()
38
- .describe("Mode 'fps': drop frames that are nearly identical to the previous one (default false)."),
36
+ .describe("Mode fps: drop near-duplicate frames (default false)."),
39
37
  outputDir: z
40
38
  .string()
41
39
  .optional()
42
- .describe("Optional folder for the frames. Defaults to SCREENCAST_HOME/frames/<id>."),
40
+ .describe("Optional folder for the frames (a relative path resolves under SCREENCAST_HOME/frames). Defaults to SCREENCAST_HOME/frames/<id>."),
43
41
  maxFrames: z
44
42
  .number()
45
43
  .int()
46
44
  .min(1)
47
45
  .max(MAX_FRAMES_CEILING)
48
46
  .optional()
49
- .describe(`Most frames this call may write (default ${DEFAULT_MAX_FRAMES}, max ${MAX_FRAMES_CEILING}). ` +
50
- "In fps mode a rate that would exceed it is lowered so the frames still span the whole video."),
47
+ .describe(`Frame cap (default ${DEFAULT_MAX_FRAMES}); fps is lowered to fit while still spanning the video.`),
51
48
  returnImages: z
52
49
  .boolean()
53
50
  .optional()
54
- .describe("Also return the frames inline as images the model can view directly " +
55
- "(default true). Only the first maxInlineImages frames are embedded."),
51
+ .describe("Return the first maxInlineImages frames inline (default true)."),
56
52
  maxInlineImages: z
57
53
  .number()
58
54
  .int()
59
55
  .min(0)
60
56
  .max(MAX_INLINE_IMAGES)
61
57
  .optional()
62
- .describe(`How many frames to embed inline (default ${DEFAULT_MAX_INLINE_IMAGES}, max ${MAX_INLINE_IMAGES}). ` +
63
- "Every frame is still written to disk and listed by path."),
58
+ .describe(`Frames to embed inline (default ${DEFAULT_MAX_INLINE_IMAGES}); all are listed by path.`),
64
59
  maxImageWidth: z
65
60
  .number()
66
61
  .int()
67
62
  .min(16)
68
63
  .optional()
69
- .describe(`Downscale inline images to at most this width (default ${DEFAULT_MAX_IMAGE_WIDTH}).`),
64
+ .describe(`Max inline image width (default ${DEFAULT_MAX_IMAGE_WIDTH}).`),
70
65
  };
71
66
  export function register(server) {
72
- server.tool("sample_frames", "Sample frames from a video so the agent can actually view what happened: " +
73
- "either at a fixed rate (fps) or at explicit timestamps. Writes PNG frames " +
74
- "to a folder and returns their paths, plus the first few frames inline so " +
75
- "the model can view them directly (disable with returnImages: false).", inputSchema, async (args) => {
67
+ server.registerTool("sample_frames", {
68
+ title: "Sample Frames",
69
+ description: "Sample PNG frames from a video (by fps, timestamps, or scene changes) and return the first " +
70
+ "few inline so the model can see what happened.",
71
+ inputSchema,
72
+ outputSchema: looseOutput({
73
+ frameDir: z.string(),
74
+ frameCount: z.number().int(),
75
+ frames: z.array(z.string()),
76
+ mode: z.string(),
77
+ }),
78
+ annotations: READ_ONLY,
79
+ }, async (args, extra) => {
76
80
  try {
77
81
  requireFfmpeg();
78
82
  if (!existsSync(args.input)) {
@@ -93,34 +97,28 @@ export function register(server) {
93
97
  throw new ScreencastError(`${args.timestamps.length} timestamps exceeds maxFrames (${maxFrames}). ` +
94
98
  `Pass fewer timestamps, or raise maxFrames (up to ${MAX_FRAMES_CEILING}).`);
95
99
  }
96
- // Size an fps request against the video's length before writing
97
- // anything, so a high rate on a long recording cannot fill the disk (#80).
98
100
  const durationSec = mode === "timestamps" ? null : (await probeMedia(args.input)).durationSec;
99
101
  const plan = mode === "fps" ? planFpsSampling(durationSec, args.fps, maxFrames) : null;
100
- // Scenes (#114): a cheap low-res pass finds where the screen changed;
101
- // the chosen moments are then grabbed at full size like timestamps.
102
102
  let scenes = null;
103
103
  let sceneTimes = [];
104
104
  if (mode === "scenes") {
105
105
  const { ffmpeg } = requireFfmpeg();
106
- const scan = await runCapture(ffmpeg, buildSceneScanArgs(args.input, args.sceneThreshold ?? DEFAULT_SCENE_THRESHOLD), jobTimeoutMs(durationSec));
106
+ const scan = await runCapture(ffmpeg, buildSceneScanArgs(args.input, args.sceneThreshold ?? DEFAULT_SCENE_THRESHOLD), jobTimeoutMs(durationSec), { signal: extra.signal });
107
107
  if (scan.code !== 0) {
108
108
  throw new ScreencastError(`Scene scan failed (exit ${scan.code}): ${scan.stderr.trim().slice(-400)}`);
109
109
  }
110
110
  scenes = parseSceneScan(scan.stdout);
111
111
  sceneTimes = pickSceneFrames(scenes, maxFrames);
112
112
  }
113
- const dir = args.outputDir ?? join(subdir("frames"), `sample-${stamp()}-${rand()}`);
113
+ const dir = resolveOutputDir(args.outputDir, subdir("frames")) ?? join(subdir("frames"), `sample-${stamp()}-${rand()}`);
114
114
  mkdirSync(dir, { recursive: true });
115
115
  let frames = [];
116
116
  const skipped = [];
117
117
  if (plan) {
118
118
  const isPng = (f) => f.endsWith(".png");
119
- // Snapshot any pre-existing PNGs so a reused outputDir does not
120
- // contaminate the result; return only the frames this run wrote.
121
119
  const before = new Set(readdirSync(dir).filter(isPng));
122
120
  const pattern = sequencePattern(dir, "frame_%05d.png");
123
- await runFfmpeg(buildSampleByFpsArgs(args.input, plan.fps, pattern, maxFrames, args.dedupe === true), 5 * 60_000);
121
+ await runFfmpeg(buildSampleByFpsArgs(args.input, plan.fps, pattern, maxFrames, args.dedupe === true), jobTimeoutMs(durationSec), { signal: extra.signal });
124
122
  frames = readdirSync(dir)
125
123
  .filter(isPng)
126
124
  .filter((f) => !before.has(f))
@@ -129,18 +127,14 @@ export function register(server) {
129
127
  }
130
128
  else {
131
129
  const ts = mode === "scenes" ? sceneTimes : args.timestamps;
132
- for (let i = 0; i < ts.length; i++) {
133
- const out = join(dir, `frame_${String(i).padStart(3, "0")}_${ts[i]}s.png`);
134
- // Clear any stale file at this path (reused outputDir) so existence
135
- // after the run reflects only what this invocation wrote.
130
+ for (const [i, t] of ts.entries()) {
131
+ const out = join(dir, `frame_${String(i).padStart(3, "0")}_${t}s.png`);
136
132
  rmSync(out, { force: true });
137
- await runFfmpeg(buildSampleAtTimestampArgs(args.input, ts[i], out), 60_000);
138
- // A timestamp past the end of the video makes ffmpeg exit 0 without
139
- // writing a file. Report only frames that actually exist (#35).
133
+ await runFfmpeg(buildSampleAtTimestampArgs(args.input, t, out), 60_000, { signal: extra.signal });
140
134
  if (existsSync(out))
141
135
  frames.push(out);
142
136
  else
143
- skipped.push(ts[i]);
137
+ skipped.push(t);
144
138
  }
145
139
  }
146
140
  const inline = args.returnImages === false
@@ -200,4 +194,3 @@ export function register(server) {
200
194
  }
201
195
  });
202
196
  }
203
- //# sourceMappingURL=sampleFrames.js.map
@@ -0,0 +1,90 @@
1
+ import { z } from "zod";
2
+ import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
3
+ import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
4
+ import { requireFfmpeg } from "../utils/ffmpeg.js";
5
+ import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
6
+ import { eventPaths, prepareEventPaths } from "../utils/events.js";
7
+ import { logMessage } from "../utils/logging.js";
8
+ import { MAX_REPLAY_SEC, replayDiskBytes, saveReplay } from "../utils/replay.js";
9
+ import { getStore } from "../context.js";
10
+ const inputSchema = {
11
+ sessionId: z.string().min(1).describe("Session id of a replay buffer."),
12
+ lastSec: z
13
+ .number()
14
+ .positive()
15
+ .max(MAX_REPLAY_SEC)
16
+ .optional()
17
+ .describe("Seconds back from now (default and max: the buffer length)."),
18
+ output: z.string().optional().describe("Output .mp4 path (default under SCREENCAST_HOME/recordings)."),
19
+ overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
20
+ reencode: z
21
+ .boolean()
22
+ .optional()
23
+ .describe("Frame-exact re-encode. Default: instant stream copy that may hide up to 2 s of earlier frames."),
24
+ };
25
+ export function register(server) {
26
+ server.registerTool("save_replay", {
27
+ title: "Save Replay",
28
+ description: "Save the last N seconds of a replay buffer (start_recording replayBufferSec) to an mp4; the buffer keeps running.",
29
+ inputSchema,
30
+ outputSchema: looseOutput({
31
+ sessionId: z.string(),
32
+ outputPath: z.string(),
33
+ durationSec: z.number(),
34
+ }),
35
+ annotations: WRITES_FILE,
36
+ }, async (args, extra) => {
37
+ try {
38
+ const record = getStore().get(args.sessionId);
39
+ if (!record)
40
+ throw new ScreencastError(`No session with id "${args.sessionId}".`);
41
+ if (!record.replay) {
42
+ throw new ScreencastError(`Session "${args.sessionId}" is not a replay buffer.`, "Start one with start_recording { replayBufferSec: 60 }; for an ordinary recording use stop_recording and trim.");
43
+ }
44
+ const { ffmpeg, ffprobe } = requireFfmpeg();
45
+ const buf = record.replay;
46
+ const lastSec = Math.min(args.lastSec ?? buf.bufferSec, buf.bufferSec);
47
+ const output = resolveOutput(args.output, subdir("recordings"), `replay-${stamp()}-${rand()}.mp4`, args.overwrite);
48
+ if (buf.events)
49
+ prepareEventPaths(eventPaths(output), args.overwrite);
50
+ const started = Date.now();
51
+ const result = await saveReplay(buf, {
52
+ ffmpeg,
53
+ ffprobe,
54
+ lastSec,
55
+ output,
56
+ reencode: args.reencode,
57
+ quality: record.quality,
58
+ live: record.status === "recording",
59
+ signal: extra.signal,
60
+ });
61
+ const elapsedMs = Date.now() - started;
62
+ logMessage("info", `Saved ${result.durationSec}s of replay ${record.id} to ${output}.`, {
63
+ sessionId: record.id,
64
+ outputPath: output,
65
+ durationSec: result.durationSec,
66
+ });
67
+ const short = result.durationSec + 0.25 < lastSec;
68
+ return okResponse({
69
+ sessionId: record.id,
70
+ ...result,
71
+ requestedSec: args.lastSec ?? null,
72
+ bufferSec: buf.bufferSec,
73
+ bufferRunning: record.status === "recording",
74
+ bufferDiskBytes: replayDiskBytes(buf),
75
+ elapsedMs,
76
+ note: (args.lastSec !== undefined && args.lastSec > buf.bufferSec
77
+ ? `Capped at the buffer length (${buf.bufferSec}s). `
78
+ : "") +
79
+ (short ? "The buffer held less footage than requested (it started recently). " : "") +
80
+ (result.includesLive ? "" : "The clip ends at the last completed segment, up to 2 s before now. ") +
81
+ (record.status === "recording"
82
+ ? "The buffer keeps running; stop_recording discards it unless save: true."
83
+ : "This buffer is no longer recording; stop_recording discards it."),
84
+ });
85
+ }
86
+ catch (error) {
87
+ return errorResponse(error);
88
+ }
89
+ });
90
+ }
@@ -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 } from "../utils/ffmpeg.js";
5
6
  import { runEditJob, probeDuration } from "../utils/jobs.js";
6
7
  import { buildScaleArgs, editOutputExt, assertEditContainer } from "../utils/media.js";
@@ -13,8 +14,14 @@ const inputSchema = {
13
14
  overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
14
15
  };
15
16
  export function register(server) {
16
- server.tool("scale", "Resize a video to a target width and/or height and re-encode. Provide one " +
17
- "side to keep the aspect ratio, or both to set an exact size.", inputSchema, async (args, extra) => {
17
+ server.registerTool("scale", {
18
+ title: "Scale Video",
19
+ description: "Resize a video to a target width and/or height and re-encode. Provide one " +
20
+ "side to keep the aspect ratio, or both to set an exact size.",
21
+ inputSchema,
22
+ outputSchema: OUTPUT_PATH,
23
+ annotations: WRITES_FILE,
24
+ }, async (args, extra) => {
18
25
  try {
19
26
  requireFfmpeg();
20
27
  if (!existsSync(args.input)) {
@@ -35,4 +42,3 @@ export function register(server) {
35
42
  }
36
43
  });
37
44
  }
38
- //# sourceMappingURL=scale.js.map
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { existsSync, rmSync } 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 { requireFfmpeg, runCapture, runFfmpeg, runFfmpegBuffer, probeMedia } from "../utils/ffmpeg.js";
5
6
  import { detectionSize, diffFrames, buildRawFrameArgs, buildSsimArgs, buildHighlightArgs, parseSsim, DEFAULT_PIXEL_THRESHOLD, } from "../utils/diff.js";
6
7
  import { stamp, rand } from "../utils/paths.js";
@@ -8,25 +9,34 @@ import { tmpdir } from "node:os";
8
9
  import { join } from "node:path";
9
10
  import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
10
11
  const inputSchema = {
11
- a: z.string().min(1).describe("The 'before' image (or video: its first frame is used)."),
12
- b: z.string().min(1).describe("The 'after' image (or video). Scaled to a's size if it differs."),
12
+ a: z.string().min(1).describe("Before image (or video: first frame)."),
13
+ b: z.string().min(1).describe("After image (or video); scaled to a's size."),
13
14
  pixelThreshold: z
14
15
  .number()
15
16
  .min(0)
16
17
  .max(255)
17
18
  .optional()
18
- .describe(`How different (0-255 mean) a cell of about 32x32 image pixels must be to count as changed ` +
19
- `(default ${DEFAULT_PIXEL_THRESHOLD}: catches a changed label or a toast).`),
19
+ .describe(`Mean 0-255 difference for a ~32x32 cell to count as changed (default ${DEFAULT_PIXEL_THRESHOLD}).`),
20
20
  returnImage: z
21
21
  .boolean()
22
22
  .optional()
23
- .describe("Also return 'b' inline with the changed regions outlined in red (default true)."),
23
+ .describe("Return b inline with changes outlined (default true)."),
24
24
  };
25
25
  export function register(server) {
26
- server.tool("screen_diff", "Compare two screenshots or frames: returns an SSIM similarity score, the share of the " +
27
- "image that changed, and bounding boxes of the changed areas in b's pixel coordinates, " +
28
- "plus b inline with those areas outlined. Use it to check that a UI change happened " +
29
- "(and only where expected).", inputSchema, async (args) => {
26
+ server.registerTool("screen_diff", {
27
+ title: "Screen Diff",
28
+ description: "Compare two screenshots or frames: SSIM score, changed share, and changed boxes in b's " +
29
+ "pixels, to check a UI change happened only where expected.",
30
+ inputSchema,
31
+ outputSchema: looseOutput({
32
+ identical: z.boolean(),
33
+ ssim: z.number().nullable(),
34
+ meanDiff: z.number(),
35
+ changedFraction: z.number(),
36
+ regions: z.array(z.unknown()),
37
+ }),
38
+ annotations: READ_ONLY,
39
+ }, async (args, extra) => {
30
40
  try {
31
41
  requireFfmpeg();
32
42
  for (const f of [args.a, args.b]) {
@@ -38,12 +48,10 @@ export function register(server) {
38
48
  throw new ScreencastError(`Could not read the size of ${args.a}.`);
39
49
  const size = detectionSize(ia.width, ia.height);
40
50
  const [ra, rb, ssimRun] = await Promise.all([
41
- runFfmpegBuffer(buildRawFrameArgs(args.a, size)),
42
- runFfmpegBuffer(buildRawFrameArgs(args.b, size)),
43
- runCapture(requireFfmpeg().ffmpeg, buildSsimArgs(args.a, args.b, size), 30_000),
51
+ runFfmpegBuffer(buildRawFrameArgs(args.a, size), 30_000, { signal: extra.signal }),
52
+ runFfmpegBuffer(buildRawFrameArgs(args.b, size), 30_000, { signal: extra.signal }),
53
+ runCapture(requireFfmpeg().ffmpeg, buildSsimArgs(args.a, args.b, size), 30_000, { signal: extra.signal }),
44
54
  ]);
45
- // Map boxes onto b's own pixels so they can be drawn on (and clicked in)
46
- // b, per axis: b was stretched to a's aspect ratio (#211).
47
55
  const diff = diffFrames(ra, rb, size.width, size.height, {
48
56
  scaleX: (ib.width ?? ia.width) / size.width,
49
57
  scaleY: (ib.height ?? ia.height) / size.height,
@@ -51,10 +59,9 @@ export function register(server) {
51
59
  });
52
60
  const images = [];
53
61
  if (args.returnImage !== false) {
54
- // Only returned inline, so it is not left on disk (#209).
55
62
  const highlighted = join(tmpdir(), `screencast-diff-${stamp()}-${rand()}.png`);
56
63
  try {
57
- await runFfmpeg(buildHighlightArgs(args.b, diff.regions, highlighted), 30_000);
64
+ await runFfmpeg(buildHighlightArgs(args.b, diff.regions, highlighted), 30_000, { signal: extra.signal });
58
65
  images.push(...(await encodeInlineImages([highlighted], DEFAULT_MAX_IMAGE_WIDTH, 1)).images);
59
66
  }
60
67
  finally {
@@ -77,4 +84,3 @@ export function register(server) {
77
84
  }
78
85
  });
79
86
  }
80
- //# sourceMappingURL=screenDiff.js.map
@@ -1,30 +1,26 @@
1
1
  import { z } from "zod";
2
2
  import { errorResponse, okResponse } from "../utils/errors.js";
3
+ import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
3
4
  import { requireFfmpeg } from "../utils/ffmpeg.js";
4
5
  import { captureStill } from "../utils/still.js";
5
6
  import { resolveCaptureTarget } from "../utils/resolveTarget.js";
6
7
  import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
7
8
  import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
8
9
  import { windowMatchReport } from "../utils/windows.js";
10
+ import { confirmCapture, describeTarget } from "../utils/consent.js";
9
11
  const inputSchema = {
10
12
  target: z
11
13
  .string()
12
- .describe("Capture target: 'full' | 'monitor:<index>' | 'window:<title>' (or window:exe=<app.exe> / window:hwnd=<handle>) | " +
13
- "'region:<x>,<y>,<w>,<h>'. window: captures the on-screen rectangle the " +
14
- "window occupies as currently displayed - it must be visible, on top, " +
15
- "and not minimized (case-insensitive exact title, else substring; " +
16
- "topmost match wins)."),
14
+ .describe("full | monitor:<i> (0 = primary) | window:<title> (or window:exe=<app.exe> / window:hwnd=<n>) | " +
15
+ "region:<x>,<y>,<w>,<h>. Titles match exactly, else as a substring; topmost wins."),
17
16
  exactTitle: z
18
17
  .boolean()
19
18
  .optional()
20
- .describe("For window: targets, match only a window whose title equals the given " +
21
- "title (case-insensitive); never fall back to a substring match. Default false."),
19
+ .describe("window: targets match the whole title only, never a substring (default false)."),
22
20
  backend: z
23
21
  .enum(["gdigrab", "wgc"])
24
22
  .optional()
25
- .describe("gdigrab (default, ~0.2 s) captures what is visible on screen. 'wgc' (window: targets " +
26
- "only, FFmpeg 8+) captures the window's own surface through Windows Graphics Capture, " +
27
- "even when other windows cover it; slower (~1-2 s)."),
23
+ .describe("gdigrab (default, ~0.2 s): what is visible. wgc (window:, FFmpeg 8+, ~1-2 s): the window even if covered."),
28
24
  output: z
29
25
  .string()
30
26
  .optional()
@@ -33,25 +29,34 @@ const inputSchema = {
33
29
  returnImage: z
34
30
  .boolean()
35
31
  .optional()
36
- .describe("Also return the screenshot inline as an image the model can view directly " +
37
- "(default true). The PNG on disk is always full resolution."),
32
+ .describe("Return the image inline (default true; the PNG on disk stays full size)."),
38
33
  maxImageWidth: z
39
34
  .number()
40
35
  .int()
41
36
  .min(16)
42
37
  .optional()
43
- .describe(`Downscale the inline image to at most this width (default ${DEFAULT_MAX_IMAGE_WIDTH}).`),
38
+ .describe(`Max inline image width (default ${DEFAULT_MAX_IMAGE_WIDTH}).`),
44
39
  };
45
40
  export function register(server) {
46
- server.tool("screenshot", "Capture a single still frame (PNG) of a target (full screen, a monitor, a " +
47
- "window by title, or a region). Returns the image path, plus the image " +
48
- "inline so the model can view it directly (disable with returnImage: false).", inputSchema, async (args) => {
41
+ server.registerTool("screenshot", {
42
+ title: "Take Screenshot",
43
+ description: "Capture one PNG of the screen, a monitor, a window, or a region, returned inline and by path.",
44
+ inputSchema,
45
+ outputSchema: looseOutput({
46
+ outputPath: z.string(),
47
+ target: z.string(),
48
+ backend: z.string(),
49
+ inlineImages: z.number().int(),
50
+ }),
51
+ annotations: WRITES_FILE,
52
+ }, async (args, extra) => {
49
53
  try {
50
54
  requireFfmpeg();
51
55
  const resolved = await resolveCaptureTarget(args.target, { exactTitle: args.exactTitle, backend: args.backend });
52
56
  const { window } = resolved;
53
57
  const output = resolveOutput(args.output, subdir("screenshots"), `shot-${stamp()}-${rand()}.png`, args.overwrite);
54
58
  const backend = args.backend ?? "gdigrab";
59
+ await confirmCapture(server, `Take a screenshot of ${describeTarget(args.target, window)}, saved to ${output}?`, extra.signal);
55
60
  await captureStill(resolved, output, backend);
56
61
  const images = args.returnImage === false
57
62
  ? []
@@ -69,4 +74,3 @@ export function register(server) {
69
74
  }
70
75
  });
71
76
  }
72
- //# sourceMappingURL=screenshot.js.map