@tmhs/screencast-mcp 0.39.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 (332) 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 +5 -21
  7. package/dist/prompts.js +0 -7
  8. package/dist/resources.js +2 -14
  9. package/dist/server.js +37 -11
  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/server.d.ts +0 -3
  109. package/dist/server.d.ts.map +0 -1
  110. package/dist/server.js.map +0 -1
  111. package/dist/tools/assembleHighlights.d.ts +0 -3
  112. package/dist/tools/assembleHighlights.d.ts.map +0 -1
  113. package/dist/tools/assembleHighlights.js.map +0 -1
  114. package/dist/tools/burnSubtitles.d.ts +0 -3
  115. package/dist/tools/burnSubtitles.d.ts.map +0 -1
  116. package/dist/tools/burnSubtitles.js.map +0 -1
  117. package/dist/tools/callout.d.ts +0 -37
  118. package/dist/tools/callout.d.ts.map +0 -1
  119. package/dist/tools/callout.js.map +0 -1
  120. package/dist/tools/clip.d.ts +0 -3
  121. package/dist/tools/clip.d.ts.map +0 -1
  122. package/dist/tools/clip.js.map +0 -1
  123. package/dist/tools/compress.d.ts +0 -3
  124. package/dist/tools/compress.d.ts.map +0 -1
  125. package/dist/tools/compress.js.map +0 -1
  126. package/dist/tools/concat.d.ts +0 -3
  127. package/dist/tools/concat.d.ts.map +0 -1
  128. package/dist/tools/concat.js.map +0 -1
  129. package/dist/tools/contactSheet.d.ts +0 -3
  130. package/dist/tools/contactSheet.d.ts.map +0 -1
  131. package/dist/tools/contactSheet.js.map +0 -1
  132. package/dist/tools/convert.d.ts +0 -3
  133. package/dist/tools/convert.d.ts.map +0 -1
  134. package/dist/tools/convert.js.map +0 -1
  135. package/dist/tools/crop.d.ts +0 -3
  136. package/dist/tools/crop.d.ts.map +0 -1
  137. package/dist/tools/crop.js.map +0 -1
  138. package/dist/tools/cutIdle.d.ts +0 -3
  139. package/dist/tools/cutIdle.d.ts.map +0 -1
  140. package/dist/tools/cutIdle.js.map +0 -1
  141. package/dist/tools/denoise.d.ts +0 -3
  142. package/dist/tools/denoise.d.ts.map +0 -1
  143. package/dist/tools/denoise.js.map +0 -1
  144. package/dist/tools/exportGif.d.ts +0 -3
  145. package/dist/tools/exportGif.d.ts.map +0 -1
  146. package/dist/tools/exportGif.js.map +0 -1
  147. package/dist/tools/exportPreset.d.ts +0 -3
  148. package/dist/tools/exportPreset.d.ts.map +0 -1
  149. package/dist/tools/exportPreset.js.map +0 -1
  150. package/dist/tools/extractAudio.d.ts +0 -3
  151. package/dist/tools/extractAudio.d.ts.map +0 -1
  152. package/dist/tools/extractAudio.js.map +0 -1
  153. package/dist/tools/findText.d.ts +0 -6
  154. package/dist/tools/findText.d.ts.map +0 -1
  155. package/dist/tools/findText.js.map +0 -1
  156. package/dist/tools/getMediaInfo.d.ts +0 -3
  157. package/dist/tools/getMediaInfo.d.ts.map +0 -1
  158. package/dist/tools/getMediaInfo.js.map +0 -1
  159. package/dist/tools/getSession.d.ts +0 -3
  160. package/dist/tools/getSession.d.ts.map +0 -1
  161. package/dist/tools/getSession.js.map +0 -1
  162. package/dist/tools/listAudioDevices.d.ts +0 -3
  163. package/dist/tools/listAudioDevices.d.ts.map +0 -1
  164. package/dist/tools/listAudioDevices.js.map +0 -1
  165. package/dist/tools/listSessions.d.ts +0 -3
  166. package/dist/tools/listSessions.d.ts.map +0 -1
  167. package/dist/tools/listSessions.js.map +0 -1
  168. package/dist/tools/musicBed.d.ts +0 -3
  169. package/dist/tools/musicBed.d.ts.map +0 -1
  170. package/dist/tools/musicBed.js.map +0 -1
  171. package/dist/tools/normalizeAudio.d.ts +0 -3
  172. package/dist/tools/normalizeAudio.d.ts.map +0 -1
  173. package/dist/tools/normalizeAudio.js.map +0 -1
  174. package/dist/tools/overlay.d.ts +0 -3
  175. package/dist/tools/overlay.d.ts.map +0 -1
  176. package/dist/tools/overlay.js.map +0 -1
  177. package/dist/tools/pipeline.d.ts +0 -3
  178. package/dist/tools/pipeline.d.ts.map +0 -1
  179. package/dist/tools/pipeline.js.map +0 -1
  180. package/dist/tools/readEvents.d.ts +0 -6
  181. package/dist/tools/readEvents.d.ts.map +0 -1
  182. package/dist/tools/readEvents.js.map +0 -1
  183. package/dist/tools/redactRegion.d.ts +0 -13
  184. package/dist/tools/redactRegion.d.ts.map +0 -1
  185. package/dist/tools/redactRegion.js.map +0 -1
  186. package/dist/tools/reframe.d.ts +0 -3
  187. package/dist/tools/reframe.d.ts.map +0 -1
  188. package/dist/tools/reframe.js.map +0 -1
  189. package/dist/tools/reviewRecording.d.ts +0 -5
  190. package/dist/tools/reviewRecording.d.ts.map +0 -1
  191. package/dist/tools/reviewRecording.js.map +0 -1
  192. package/dist/tools/sampleFrames.d.ts +0 -3
  193. package/dist/tools/sampleFrames.d.ts.map +0 -1
  194. package/dist/tools/sampleFrames.js.map +0 -1
  195. package/dist/tools/scale.d.ts +0 -3
  196. package/dist/tools/scale.d.ts.map +0 -1
  197. package/dist/tools/scale.js.map +0 -1
  198. package/dist/tools/screenDiff.d.ts +0 -3
  199. package/dist/tools/screenDiff.d.ts.map +0 -1
  200. package/dist/tools/screenDiff.js.map +0 -1
  201. package/dist/tools/screenshot.d.ts +0 -3
  202. package/dist/tools/screenshot.d.ts.map +0 -1
  203. package/dist/tools/screenshot.js.map +0 -1
  204. package/dist/tools/speed.d.ts +0 -3
  205. package/dist/tools/speed.d.ts.map +0 -1
  206. package/dist/tools/speed.js.map +0 -1
  207. package/dist/tools/startRecording.d.ts +0 -3
  208. package/dist/tools/startRecording.d.ts.map +0 -1
  209. package/dist/tools/startRecording.js.map +0 -1
  210. package/dist/tools/stopRecording.d.ts +0 -3
  211. package/dist/tools/stopRecording.d.ts.map +0 -1
  212. package/dist/tools/stopRecording.js.map +0 -1
  213. package/dist/tools/titleCard.d.ts +0 -3
  214. package/dist/tools/titleCard.d.ts.map +0 -1
  215. package/dist/tools/titleCard.js.map +0 -1
  216. package/dist/tools/transcribe.d.ts +0 -3
  217. package/dist/tools/transcribe.d.ts.map +0 -1
  218. package/dist/tools/transcribe.js.map +0 -1
  219. package/dist/tools/trim.d.ts +0 -3
  220. package/dist/tools/trim.d.ts.map +0 -1
  221. package/dist/tools/trim.js.map +0 -1
  222. package/dist/tools/waitForChange.d.ts +0 -3
  223. package/dist/tools/waitForChange.d.ts.map +0 -1
  224. package/dist/tools/waitForChange.js.map +0 -1
  225. package/dist/tools/xfadeTransition.d.ts +0 -3
  226. package/dist/tools/xfadeTransition.d.ts.map +0 -1
  227. package/dist/tools/xfadeTransition.js.map +0 -1
  228. package/dist/tools/zoom.d.ts +0 -15
  229. package/dist/tools/zoom.d.ts.map +0 -1
  230. package/dist/tools/zoom.js.map +0 -1
  231. package/dist/utils/anim.d.ts +0 -33
  232. package/dist/utils/anim.d.ts.map +0 -1
  233. package/dist/utils/anim.js.map +0 -1
  234. package/dist/utils/animExport.d.ts +0 -27
  235. package/dist/utils/animExport.d.ts.map +0 -1
  236. package/dist/utils/animExport.js.map +0 -1
  237. package/dist/utils/audio.d.ts +0 -49
  238. package/dist/utils/audio.d.ts.map +0 -1
  239. package/dist/utils/audio.js.map +0 -1
  240. package/dist/utils/audioDevices.d.ts +0 -33
  241. package/dist/utils/audioDevices.d.ts.map +0 -1
  242. package/dist/utils/audioDevices.js.map +0 -1
  243. package/dist/utils/callout.d.ts +0 -72
  244. package/dist/utils/callout.d.ts.map +0 -1
  245. package/dist/utils/callout.js.map +0 -1
  246. package/dist/utils/calloutAssets.d.ts +0 -3
  247. package/dist/utils/calloutAssets.d.ts.map +0 -1
  248. package/dist/utils/calloutAssets.js.map +0 -1
  249. package/dist/utils/captions.d.ts +0 -26
  250. package/dist/utils/captions.d.ts.map +0 -1
  251. package/dist/utils/captions.js.map +0 -1
  252. package/dist/utils/diff.d.ts +0 -112
  253. package/dist/utils/diff.d.ts.map +0 -1
  254. package/dist/utils/diff.js.map +0 -1
  255. package/dist/utils/errors.d.ts +0 -33
  256. package/dist/utils/errors.d.ts.map +0 -1
  257. package/dist/utils/errors.js.map +0 -1
  258. package/dist/utils/events.d.ts +0 -143
  259. package/dist/utils/events.d.ts.map +0 -1
  260. package/dist/utils/events.js.map +0 -1
  261. package/dist/utils/ffmpeg.d.ts +0 -50
  262. package/dist/utils/ffmpeg.d.ts.map +0 -1
  263. package/dist/utils/ffmpeg.js.map +0 -1
  264. package/dist/utils/fonts.d.ts +0 -17
  265. package/dist/utils/fonts.d.ts.map +0 -1
  266. package/dist/utils/fonts.js.map +0 -1
  267. package/dist/utils/idle.d.ts +0 -23
  268. package/dist/utils/idle.d.ts.map +0 -1
  269. package/dist/utils/idle.js.map +0 -1
  270. package/dist/utils/images.d.ts +0 -21
  271. package/dist/utils/images.d.ts.map +0 -1
  272. package/dist/utils/images.js.map +0 -1
  273. package/dist/utils/jobs.d.ts +0 -44
  274. package/dist/utils/jobs.d.ts.map +0 -1
  275. package/dist/utils/jobs.js.map +0 -1
  276. package/dist/utils/lifecycle.d.ts +0 -29
  277. package/dist/utils/lifecycle.d.ts.map +0 -1
  278. package/dist/utils/lifecycle.js.map +0 -1
  279. package/dist/utils/media.d.ts +0 -272
  280. package/dist/utils/media.d.ts.map +0 -1
  281. package/dist/utils/media.js.map +0 -1
  282. package/dist/utils/monitors.d.ts +0 -47
  283. package/dist/utils/monitors.d.ts.map +0 -1
  284. package/dist/utils/monitors.js.map +0 -1
  285. package/dist/utils/ocr.d.ts +0 -50
  286. package/dist/utils/ocr.d.ts.map +0 -1
  287. package/dist/utils/ocr.js.map +0 -1
  288. package/dist/utils/paths.d.ts +0 -28
  289. package/dist/utils/paths.d.ts.map +0 -1
  290. package/dist/utils/paths.js.map +0 -1
  291. package/dist/utils/pipeline.d.ts +0 -69
  292. package/dist/utils/pipeline.d.ts.map +0 -1
  293. package/dist/utils/pipeline.js.map +0 -1
  294. package/dist/utils/player.d.ts +0 -30
  295. package/dist/utils/player.d.ts.map +0 -1
  296. package/dist/utils/player.js.map +0 -1
  297. package/dist/utils/produce.d.ts +0 -126
  298. package/dist/utils/produce.d.ts.map +0 -1
  299. package/dist/utils/produce.js.map +0 -1
  300. package/dist/utils/resolveTarget.d.ts +0 -32
  301. package/dist/utils/resolveTarget.d.ts.map +0 -1
  302. package/dist/utils/resolveTarget.js.map +0 -1
  303. package/dist/utils/retention.d.ts +0 -10
  304. package/dist/utils/retention.d.ts.map +0 -1
  305. package/dist/utils/retention.js.map +0 -1
  306. package/dist/utils/sessions.d.ts +0 -154
  307. package/dist/utils/sessions.d.ts.map +0 -1
  308. package/dist/utils/sessions.js.map +0 -1
  309. package/dist/utils/sheet.d.ts +0 -26
  310. package/dist/utils/sheet.d.ts.map +0 -1
  311. package/dist/utils/sheet.js.map +0 -1
  312. package/dist/utils/still.d.ts +0 -7
  313. package/dist/utils/still.d.ts.map +0 -1
  314. package/dist/utils/still.js.map +0 -1
  315. package/dist/utils/targets.d.ts +0 -113
  316. package/dist/utils/targets.d.ts.map +0 -1
  317. package/dist/utils/targets.js.map +0 -1
  318. package/dist/utils/validate.d.ts +0 -15
  319. package/dist/utils/validate.d.ts.map +0 -1
  320. package/dist/utils/validate.js.map +0 -1
  321. package/dist/utils/wgc.d.ts +0 -46
  322. package/dist/utils/wgc.d.ts.map +0 -1
  323. package/dist/utils/wgc.js.map +0 -1
  324. package/dist/utils/windows.d.ts +0 -94
  325. package/dist/utils/windows.d.ts.map +0 -1
  326. package/dist/utils/windows.js.map +0 -1
  327. package/dist/utils/zoom.d.ts +0 -95
  328. package/dist/utils/zoom.d.ts.map +0 -1
  329. package/dist/utils/zoom.js.map +0 -1
  330. package/dist/wgcRecorder.d.ts +0 -2
  331. package/dist/wgcRecorder.d.ts.map +0 -1
  332. package/dist/wgcRecorder.js.map +0 -1
package/dist/utils/ocr.js CHANGED
@@ -1,30 +1,13 @@
1
- /**
2
- * On-screen text recognition with the OCR engine built into Windows
3
- * (Windows.Media.Ocr), so no model or package is installed (#117).
4
- *
5
- * The engine misses small text and, notably, drops ALL_CAPS words joined by
6
- * underscores (an env-var name like OPENAI_API_KEY, and anything glued to it
7
- * with `=`) at ordinary sizes. Measured on 18 px UI text: missing at 1x-3x,
8
- * recovered at 4x. So recognition runs two passes (2x and 4x upscales) in one
9
- * PowerShell process and merges them, and matching tolerates the engine's
10
- * usual confusions (`_` read as `-`, `I` as `l`).
11
- *
12
- * The PowerShell/WinRT call is impure; parsing, merging, and matching are pure.
13
- */
1
+ import { runInNewContext } from "node:vm";
14
2
  import { ScreencastError } from "./errors.js";
15
3
  import { runPowerShell, psTimeoutMs } from "./monitors.js";
16
- /** Upscale factors for the two recognition passes. */
17
4
  export const OCR_SCALES = [2, 4];
18
- /** Windows.Media.Ocr refuses images larger than this on either side. */
19
5
  export const OCR_MAX_DIMENSION = 10_000;
20
- /** Recognise every image in `paths` (already upscaled by `scales[i]`) in one
21
- * PowerShell run. Paths travel base64-encoded, so no quoting is involved. */
22
6
  export async function recognize(paths, scales) {
23
7
  if (process.platform !== "win32") {
24
8
  throw new ScreencastError("find_text uses the Windows OCR engine and runs on Windows only.");
25
9
  }
26
10
  const list = Buffer.from(JSON.stringify(paths), "utf8").toString("base64");
27
- // The limit grows with the image count, so a whole-clip scan gets the time it needs.
28
11
  const stdout = await runPowerShell(PS_OCR.replace("__PATHS__", list), "text (OCR)", {
29
12
  timeoutMs: psTimeoutMs(OCR_TIMEOUT_MS + Math.max(0, paths.length - 2) * OCR_PER_IMAGE_MS),
30
13
  });
@@ -38,8 +21,6 @@ export async function recognize(paths, scales) {
38
21
  const passes = Array.isArray(raw) ? raw : [raw];
39
22
  return passes.map((p, i) => parseOcrPass(p, scales[i] ?? 1));
40
23
  }
41
- /** Turn one pass's JSON into lines in ORIGINAL image pixels (dividing out the
42
- * upscale), each with a bounding box around its words. Pure. */
43
24
  export function parseOcrPass(raw, scale) {
44
25
  const pass = (raw ?? {});
45
26
  if (pass.error) {
@@ -77,34 +58,62 @@ function overlapRatio(a, b) {
77
58
  return 0;
78
59
  return (w * h) / Math.min(a.width * a.height, b.width * b.height);
79
60
  }
80
- /** Merge recognition passes: start from the first, then add lines a later pass
81
- * found that overlap nothing already kept; where they overlap, keep the
82
- * longer reading. Result is in reading order. Pure. */
83
61
  export function mergePasses(passes) {
84
62
  const kept = [];
85
63
  for (const pass of passes) {
86
64
  for (const line of pass) {
87
65
  const i = kept.findIndex((k) => overlapRatio(k, line) > 0.5);
88
- if (i === -1)
66
+ const match = kept[i];
67
+ if (!match)
89
68
  kept.push(line);
90
- else if (line.text.length > kept[i].text.length)
69
+ else if (line.text.length > match.text.length)
91
70
  kept[i] = line;
92
71
  }
93
72
  }
94
73
  return kept.sort((a, b) => a.y - b.y || a.x - b.x);
95
74
  }
96
- /** Fold the engine's usual confusions so a query still matches a misread:
97
- * case, `-`/`_`/space, `l`/`I`/`1`/`|`, and `O`/`0`. Pure. */
98
75
  export function normalizeForMatch(s) {
99
76
  return s.toLowerCase().replace(/[-_\s]+/g, "_").replace(/[l1|]/g, "i").replace(/0/g, "o");
100
77
  }
101
- /** Find `query` (plain text, or a regular expression when `regex`) in the
102
- * lines. Plain queries also match through normalizeForMatch. Each hit is
103
- * boxed around the words it spans. Pure. */
78
+ export const MAX_QUERY_LENGTH = 500;
79
+ export const REGEX_BUDGET_MS = 1_000;
80
+ const REGEX_SCAN = `JSON.stringify(texts.map((text) => {
81
+ const re = new RegExp(query, "gi");
82
+ const seen = new Set();
83
+ const ranges = [];
84
+ for (const variant of [text, text.replace(/-/g, "_"), text.replace(/_/g, "-")]) {
85
+ for (const m of variant.matchAll(re)) {
86
+ const key = m.index + ":" + m[0].length;
87
+ if (m[0].length > 0 && !seen.has(key)) {
88
+ seen.add(key);
89
+ ranges.push([m.index, m.index + m[0].length]);
90
+ }
91
+ }
92
+ }
93
+ return ranges;
94
+ }))`;
95
+ export function regexRanges(texts, query, budgetMs = REGEX_BUDGET_MS) {
96
+ try {
97
+ new RegExp(query, "gi");
98
+ }
99
+ catch (err) {
100
+ throw new ScreencastError(`Invalid regex: ${err.message}`);
101
+ }
102
+ try {
103
+ return JSON.parse(runInNewContext(REGEX_SCAN, { texts, query }, { timeout: budgetMs }));
104
+ }
105
+ catch (err) {
106
+ if (err.code === "ERR_SCRIPT_EXECUTION_TIMEOUT") {
107
+ throw new ScreencastError(`The regex took longer than ${budgetMs / 1000} s to run and was stopped.`, "Simplify it: nested quantifiers such as (a+)+ backtrack catastrophically.");
108
+ }
109
+ throw err;
110
+ }
111
+ }
104
112
  export function findMatches(lines, query, regex = false) {
105
- const out = [];
106
- for (const line of lines) {
107
- // Rebuild the line from its words so character offsets map to words.
113
+ if (query.length > MAX_QUERY_LENGTH) {
114
+ throw new ScreencastError(`The query is ${query.length} characters; at most ${MAX_QUERY_LENGTH} are allowed.`);
115
+ }
116
+ const rebuilt = lines.map((line) => {
108
117
  const spans = [];
109
118
  let text = "";
110
119
  for (const w of line.words) {
@@ -113,35 +122,19 @@ export function findMatches(lines, query, regex = false) {
113
122
  spans.push({ start: text.length, end: text.length + w.text.length, word: w });
114
123
  text += w.text;
115
124
  }
116
- const ranges = [];
117
- if (regex) {
118
- let re;
119
- try {
120
- re = new RegExp(query, "gi");
121
- }
122
- catch (err) {
123
- throw new ScreencastError(`Invalid regex: ${err.message}`);
124
- }
125
- // Also try the text with `_` and `-` swapped either way: the engine
126
- // often reads one as the other, and a secret pattern like `ghp_` must
127
- // still match `ghp-` (#236). Same length, so offsets map to words as is.
128
- const seen = new Set();
129
- for (const variant of [text, text.replace(/-/g, "_"), text.replace(/_/g, "-")]) {
130
- for (const m of variant.matchAll(re)) {
131
- const key = `${m.index}:${m[0].length}`;
132
- if (m[0].length > 0 && !seen.has(key)) {
133
- seen.add(key);
134
- ranges.push([m.index, m.index + m[0].length]);
135
- }
136
- }
137
- }
125
+ return { line, spans, text };
126
+ });
127
+ const regexHits = regex ? regexRanges(rebuilt.map((r) => r.text), query) : null;
128
+ const out = [];
129
+ rebuilt.forEach(({ line, spans }, i) => {
130
+ let ranges = [];
131
+ if (regexHits) {
132
+ ranges = regexHits[i] ?? [];
138
133
  }
139
134
  else {
140
- // normalizeForMatch keeps string length except for collapsing runs of
141
- // separators, so search the normalized text and map back word by word.
142
135
  const needle = normalizeForMatch(query);
143
136
  if (!needle)
144
- continue;
137
+ return;
145
138
  const hay = spans.map((s) => normalizeForMatch(s.word.text)).join("_");
146
139
  let from = 0;
147
140
  for (let at = hay.indexOf(needle, from); at !== -1; at = hay.indexOf(needle, from)) {
@@ -157,11 +150,9 @@ export function findMatches(lines, query, regex = false) {
157
150
  words.forEach((w) => boxed.add(w));
158
151
  out.push({ text: words.map((w) => w.text).join(" "), line: line.text, ...unionRect(words) });
159
152
  }
160
- }
153
+ });
161
154
  return out;
162
155
  }
163
- /** Map a range in the `_`-joined normalized word string back to a range in
164
- * the space-joined text (both join words with one character). */
165
156
  function normalizedRangeToText(spans, start, end) {
166
157
  let pos = 0;
167
158
  let textStart = -1;
@@ -176,9 +167,8 @@ function normalizedRangeToText(spans, start, end) {
176
167
  }
177
168
  pos += len + 1;
178
169
  }
179
- return [textStart === -1 ? 0 : textStart, textEnd === -1 ? spans[spans.length - 1].end : textEnd];
170
+ return [textStart === -1 ? 0 : textStart, textEnd === -1 ? (spans.at(-1)?.end ?? 0) : textEnd];
180
171
  }
181
- /** Padded rectangles for redact_region, clamped to the frame. Pure. */
182
172
  export function redactionRects(matches, frame, pad = 4) {
183
173
  return matches.map((m) => {
184
174
  const x = Math.max(0, m.x - pad);
@@ -191,21 +181,14 @@ export function redactionRects(matches, frame, pad = 4) {
191
181
  };
192
182
  });
193
183
  }
194
- /** The scales actually used for an image of this size: each OCR_SCALES entry,
195
- * capped so the upscaled image stays within the engine's limit. Pure. */
196
184
  export function passScales(width, height) {
197
185
  const cap = OCR_MAX_DIMENSION / Math.max(width, height);
198
186
  const scales = OCR_SCALES.map((s) => Math.min(s, Math.floor(cap * 100) / 100)).filter((s) => s >= 1);
199
187
  return [...new Set(scales.length ? scales : [Math.min(1, cap)])];
200
188
  }
201
- /** Limit for one OCR run (all passes of all images) (#183). */
202
189
  export const OCR_TIMEOUT_MS = 60_000;
203
- /** Extra time per image beyond the first two (a whole-clip scan, #204). */
204
190
  export const OCR_PER_IMAGE_MS = 5_000;
205
- /** Limit for one WinRT call inside it (open, decode, recognise). */
206
191
  export const OCR_STEP_TIMEOUT_MS = 20_000;
207
- // Windows PowerShell 5.1 + WinRT: decode each image, recognise it with the
208
- // user's profile languages, and print one JSON object per image.
209
192
  const PS_OCR = `
210
193
  $ErrorActionPreference = 'Stop'
211
194
  Add-Type -AssemblyName System.Runtime.WindowsRuntime
@@ -232,4 +215,3 @@ $out = foreach ($p in $paths) {
232
215
  }
233
216
  ConvertTo-Json -InputObject @($out) -Depth 6 -Compress
234
217
  `;
235
- //# sourceMappingURL=ocr.js.map
@@ -1,15 +1,6 @@
1
- /**
2
- * Output location and filename helpers.
3
- *
4
- * By default everything the server writes lands under SCREENCAST_HOME
5
- * (default: <homedir>/.screencast-mcp), NOT the current working directory, so
6
- * captures never accidentally land inside a checked-out repo. Callers may still
7
- * pass an absolute `output` path per call. The repo .gitignore is a second line
8
- * of defence for the case where output is pointed back into the project.
9
- */
10
1
  import { homedir, tmpdir } from "node:os";
11
- import { join, isAbsolute, resolve } from "node:path";
12
- import { mkdirSync, existsSync } from "node:fs";
2
+ import { basename, delimiter, dirname, join, isAbsolute, relative, resolve, sep } from "node:path";
3
+ import { mkdirSync, existsSync, realpathSync } from "node:fs";
13
4
  import { ScreencastError } from "./errors.js";
14
5
  export function homeRoot() {
15
6
  const override = process.env.SCREENCAST_HOME;
@@ -22,50 +13,90 @@ export function subdir(name) {
22
13
  mkdirSync(dir, { recursive: true });
23
14
  return dir;
24
15
  }
25
- /** The on-disk session registry path. */
26
16
  export function registryPath() {
27
17
  const dir = homeRoot();
28
18
  mkdirSync(dir, { recursive: true });
29
19
  return join(dir, "sessions.json");
30
20
  }
31
- /** A compact UTC timestamp like 20260615-192430-880. */
32
21
  export function stamp(date = new Date()) {
33
22
  const iso = date.toISOString().replace(/[-:T]/g, "").replace(/\..+/, "");
34
23
  const ms = String(date.getMilliseconds()).padStart(3, "0");
35
24
  return `${iso.slice(0, 8)}-${iso.slice(8, 14)}-${ms}`;
36
25
  }
37
- /** Short random suffix to make ids/filenames unique within the same ms. */
38
26
  export function rand(n = 4) {
39
27
  return Math.random().toString(36).slice(2, 2 + n);
40
28
  }
41
- /** An ffmpeg image-sequence pattern (`name` holds the `%0Nd`) inside `dir`. A
42
- * `%` in the directory itself is escaped as `%%` so ffmpeg reads it literally
43
- * (#238). */
44
29
  export function sequencePattern(dir, name) {
45
30
  return join(dir.replace(/%/g, "%%"), name);
46
31
  }
47
32
  const STILL_IMAGE = /\.(png|jpe?g|bmp|tiff?)$/i;
48
- /** The output args for a single still image. ffmpeg's image2 muxer reads a `%`
49
- * in the file name as a sequence pattern (`b%dx.png` becomes `b1x.png`), so
50
- * `-update 1` keeps the name literal and the returned path real (#238). */
51
33
  export function stillOutput(output) {
52
34
  return STILL_IMAGE.test(output) ? ["-update", "1", output] : [output];
53
35
  }
54
- /** A unique scratch path in the OS temp dir for short-lived working files (a
55
- * concat list, a drawtext textfile). Kept out of SCREENCAST_HOME/edits so a hard
56
- * crash before cleanup leaves it where the OS reaps it, not next to outputs. */
57
36
  export function tempPath(suffix = "") {
58
37
  return join(tmpdir(), `screencast-${stamp()}-${rand()}${suffix}`);
59
38
  }
60
- /** Resolve a caller-supplied output path, or build a default under a subdir.
61
- *
62
- * A caller-supplied path that already exists is refused unless the caller
63
- * passed overwrite: true - every ffmpeg builder runs with -y, so this is the
64
- * one place that stands between a reused path and a silently clobbered file.
65
- * Auto-generated default names are unique and skip the check. */
39
+ export const ALLOWED_DIRS_ENV = "SCREENCAST_ALLOWED_DIRS";
40
+ export function envAllowedDirs(env = process.env) {
41
+ const raw = env[ALLOWED_DIRS_ENV];
42
+ if (!raw)
43
+ return [];
44
+ return raw
45
+ .split(delimiter)
46
+ .map((d) => d.trim())
47
+ .filter((d) => d.length > 0)
48
+ .map((d) => resolve(d));
49
+ }
50
+ let clientRoots = null;
51
+ export function setClientRoots(dirs) {
52
+ clientRoots = dirs === null || dirs === "pending" ? dirs : dirs.map((d) => resolve(d));
53
+ }
54
+ export function getClientRoots() {
55
+ return Array.isArray(clientRoots) ? clientRoots : null;
56
+ }
57
+ export function allowedOutputDirs(env = process.env) {
58
+ const fromEnv = envAllowedDirs(env);
59
+ if (clientRoots === null && fromEnv.length === 0)
60
+ return null;
61
+ const roots = Array.isArray(clientRoots) ? clientRoots : [];
62
+ return [resolve(homeRoot()), ...fromEnv, ...roots];
63
+ }
64
+ function realish(path) {
65
+ const tail = [];
66
+ let cur = resolve(path);
67
+ for (;;) {
68
+ try {
69
+ return join(realpathSync.native(cur), ...tail.reverse());
70
+ }
71
+ catch {
72
+ const parent = dirname(cur);
73
+ if (parent === cur)
74
+ return resolve(path);
75
+ tail.push(basename(cur));
76
+ cur = parent;
77
+ }
78
+ }
79
+ }
80
+ export function isWithin(path, dir) {
81
+ const rel = relative(realish(dir), realish(path));
82
+ return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
83
+ }
84
+ export function assertOutputAllowed(path) {
85
+ if (clientRoots === "pending" && envAllowedDirs().length === 0 && !isWithin(path, homeRoot())) {
86
+ throw new ScreencastError(`Output ${path} is outside SCREENCAST_HOME and the client's workspace roots have not loaded yet. ` +
87
+ "Retry the call in a moment, or omit the path to write under SCREENCAST_HOME.");
88
+ }
89
+ const allowed = allowedOutputDirs();
90
+ if (allowed === null || allowed.some((dir) => isWithin(path, dir)))
91
+ return;
92
+ throw new ScreencastError(`Output ${path} is outside the allowed directories: ${allowed.join(", ")}. ` +
93
+ `Write under one of them (a relative path lands in SCREENCAST_HOME), or add the folder to ` +
94
+ `${ALLOWED_DIRS_ENV} or the client's workspace roots.`);
95
+ }
66
96
  export function resolveOutput(provided, defaultDir, defaultName, overwrite = false) {
67
97
  if (provided && provided.trim().length > 0) {
68
- const path = isAbsolute(provided) ? provided : resolve(provided);
98
+ const path = resolve(defaultDir, provided);
99
+ assertOutputAllowed(path);
69
100
  if (!overwrite && existsSync(path)) {
70
101
  throw new ScreencastError(`Output already exists: ${path}. Pass overwrite: true to replace it, ` +
71
102
  `or choose a different path.`);
@@ -74,4 +105,10 @@ export function resolveOutput(provided, defaultDir, defaultName, overwrite = fal
74
105
  }
75
106
  return join(defaultDir, defaultName);
76
107
  }
77
- //# sourceMappingURL=paths.js.map
108
+ export function resolveOutputDir(provided, defaultParent) {
109
+ if (!provided || provided.trim().length === 0)
110
+ return undefined;
111
+ const dir = resolve(defaultParent, provided);
112
+ assertOutputAllowed(dir);
113
+ return dir;
114
+ }
@@ -1,19 +1,3 @@
1
- /**
2
- * pipeline (#125): run a chain of edits as ONE ffmpeg process instead of one
3
- * re-encode (and one intermediate file) per tool call.
4
- *
5
- * Each step contributes filter-graph steps over the current video label, built
6
- * by the same helpers as the standalone tools, so a pipeline step behaves like
7
- * its tool. Frame size, fps, and duration are tracked through the chain so each
8
- * step is validated against the frame it actually receives, and times inside a
9
- * step (callout from/to, redact start/end, zoom keyframes) are on the timeline
10
- * as it is at that step (after an earlier trim or speed change).
11
- *
12
- * A leading trim becomes an input seek, the cheapest form. export_preset and
13
- * export_gif can only be the last step: export_preset sets the encoder; an
14
- * export_gif tail renders the chain to a temporary high-quality mp4 first and
15
- * then runs the size-budget ladder, so it is two stages. All of this is pure.
16
- */
17
1
  import { ScreencastError } from "./errors.js";
18
2
  import { atempoChain, cropFilter, redactSteps, scaleFilter, scaledSize } from "./media.js";
19
3
  import { calloutSteps } from "./callout.js";
@@ -22,7 +6,6 @@ import { keyframesToViews, zoomFilter, DEFAULT_TRANSITION_SEC } from "./zoom.js"
22
6
  import { resolveQuality } from "./targets.js";
23
7
  export const MAX_PIPELINE_STEPS = 30;
24
8
  const r3 = (v) => Math.round(v * 1000) / 1000;
25
- /** Plan the fused command. `assets[i]` holds the files callout step i needs. */
26
9
  export function planPipeline(input, output, steps, src, assets = {}, quality = "standard") {
27
10
  if (steps.length === 0)
28
11
  throw new ScreencastError("Give at least one step.");
@@ -33,8 +16,6 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
33
16
  throw new ScreencastError(`${s.op} must be the last step (it is step ${i + 1} of ${steps.length}).`);
34
17
  }
35
18
  });
36
- // A zoom moves the content within the frame over time, so a fixed redact
37
- // box after it would slide off the secret (#204).
38
19
  const zoomAt = steps.findIndex((s) => s.op === "zoom");
39
20
  const lateRedact = zoomAt === -1 ? -1 : steps.findIndex((s, i) => i > zoomAt && s.op === "redact");
40
21
  if (lateRedact !== -1) {
@@ -184,14 +165,11 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
184
165
  }
185
166
  if (src.hasAudio)
186
167
  args.push("-map", audio.length > 0 && graph.length > 0 ? "[aout]" : "0:a");
187
- // Assigned inside the forEach above, which TypeScript does not track.
188
168
  const finalEncode = encode;
189
169
  if (finalEncode) {
190
170
  args.push(...finalEncode);
191
171
  }
192
172
  else {
193
- // An export_gif tail reads this file once, so give it more quality; a
194
- // redaction gets it too, like redact_region, so its edges stay crisp (#204).
195
173
  args.push(...resolveQuality(gif || redacts ? "high" : quality));
196
174
  if (src.hasAudio)
197
175
  args.push(...(audioReencode ? ["-c:a", "aac", "-b:a", "160k"] : ["-c:a", "copy"]));
@@ -200,4 +178,3 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
200
178
  args.push(output);
201
179
  return { args, width: W, height: H, fps, durationSec: dur === null ? null : r3(dur), gif, summary };
202
180
  }
203
- //# sourceMappingURL=pipeline.js.map
@@ -1,47 +1,71 @@
1
- /**
2
- * The review player (#128): an MCP Apps view (a sandboxed HTML page the host
3
- * shows inline) where a person scrubs a recording, sets trim handles, and
4
- * draws redaction boxes; their choices come back as a pipeline call.
5
- *
6
- * The page gets the video as JPEG frames (data: images work under the strict
7
- * CSP hosts apply to apps, unlike a local file or HTTP server, and keep
8
- * "output stays local"). These helpers plan and split those frames. Pure.
9
- */
10
1
  import { ScreencastError } from "./errors.js";
11
- /** The MCP Apps resource the player is served as, and its MIME type. */
2
+ import { escapeFilterPath } from "./fonts.js";
12
3
  export const PLAYER_URI = "ui://screencast/player";
13
4
  export const MCP_APP_MIME = "text/html;profile=mcp-app";
14
- /** Tool _meta that tells an Apps host to render the player for a tool's
15
- * result. Both the current and the legacy key, as the spec asks hosts to read. */
16
5
  export const PLAYER_TOOL_META = { ui: { resourceUri: PLAYER_URI }, "ui/resourceUri": PLAYER_URI };
6
+ export const MCP_APPS_EXTENSION = "io.modelcontextprotocol/ui";
7
+ export function clientSupportsApps(caps) {
8
+ const c = caps;
9
+ const ext = (c?.extensions?.[MCP_APPS_EXTENSION] ?? c?.experimental?.[MCP_APPS_EXTENSION]);
10
+ if (!ext || typeof ext !== "object")
11
+ return false;
12
+ return !Array.isArray(ext.mimeTypes) || ext.mimeTypes.includes(MCP_APP_MIME);
13
+ }
17
14
  export const DEFAULT_PLAYER_FRAMES = 120;
18
15
  export const MAX_PLAYER_FRAMES = 300;
19
16
  export const PLAYER_FPS = 4;
20
17
  export const DEFAULT_PLAYER_WIDTH = 640;
21
- /** How many preview frames, and at what rate, to cover `durationSec`: up to
22
- * PLAYER_FPS per second, at most `maxFrames`, spread evenly. */
18
+ export const PLAYER_SCENE_THRESHOLD = 0.01;
23
19
  export function playerFramePlan(durationSec, maxFrames = DEFAULT_PLAYER_FRAMES) {
24
20
  if (!(durationSec > 0))
25
21
  throw new ScreencastError("The video has no duration to review.");
26
22
  const count = Math.max(1, Math.min(maxFrames, Math.ceil(durationSec * PLAYER_FPS)));
27
- return { count, fps: count / durationSec };
28
- }
29
- /** Each frame's time: the middle of its slice of the video. */
30
- export function playerFrameTimes(durationSec, count) {
31
- return Array.from({ length: count }, (_, i) => Math.round(((i + 0.5) * durationSec * 1000) / count) / 1000);
23
+ const intervalSec = Number((durationSec / count).toFixed(6));
24
+ return { count, intervalSec, sceneGapSec: Number(Math.max(0.25, intervalSec / 4).toFixed(6)) };
32
25
  }
33
- /** Decode `input` to JPEG frames on stdout at `fps`, `width` wide. */
34
- export function buildPlayerFramesArgs(input, fps, width, count) {
26
+ export function buildPlayerFramesArgs(input, plan, width, logFile, threshold = PLAYER_SCENE_THRESHOLD) {
27
+ const i = plan.intervalSec;
28
+ const grid = `isnan(prev_t)+gt(floor((t-start_t)/${i})\\,floor((prev_t-start_t)/${i}))`;
29
+ const scene = `gt(scene\\,${threshold})*not(${grid})*(isnan(prev_selected_t)+gte(t-prev_selected_t\\,${plan.sceneGapSec}))`;
35
30
  return [
36
31
  "-v", "error", "-i", input, "-an",
37
- "-vf", `fps=${Number(fps.toFixed(6))},scale='min(${width},iw)':-2`,
38
- "-frames:v", String(count),
32
+ "-vf",
33
+ `scale='min(${width},iw)':-2,split[g][s];` +
34
+ `[g]select='${grid}',metadata=add:key=kind:value=grid[g1];` +
35
+ `[s]select='${scene}',metadata=add:key=kind:value=scene[s1];` +
36
+ `[g1][s1]interleave,metadata=print:file=${escapeFilterPath(logFile)}`,
37
+ "-fps_mode", "passthrough",
39
38
  "-q:v", "6", "-f", "image2pipe", "-c:v", "mjpeg", "-",
40
39
  ];
41
40
  }
42
- /** Split concatenated JPEGs (ffmpeg's mjpeg image2pipe) at their start/end
43
- * markers. In entropy-coded data 0xFF is always followed by 0x00 or a restart
44
- * marker, so 0xFFD9 only ever ends an image. */
41
+ export function parsePlayerFrameLog(text) {
42
+ const out = [];
43
+ for (const line of text.split(/\r?\n/)) {
44
+ const t = line.match(/pts_time:\s*(-?[\d.]+)/);
45
+ if (t) {
46
+ out.push({ timeSec: Number(t[1]), scene: false, score: 0 });
47
+ continue;
48
+ }
49
+ const last = out.at(-1);
50
+ if (!last)
51
+ continue;
52
+ if (line === "kind=scene")
53
+ last.scene = true;
54
+ const s = line.match(/^lavfi\.scene_score=([\d.]+)/);
55
+ if (s)
56
+ last.score = Number(s[1]);
57
+ }
58
+ return out;
59
+ }
60
+ export function pickPlayerFrames(frames, maxScene) {
61
+ const scene = frames
62
+ .map((f, i) => ({ f, i }))
63
+ .filter((x) => x.f.scene)
64
+ .sort((a, b) => b.f.score - a.f.score)
65
+ .slice(0, Math.max(0, maxScene));
66
+ const keep = new Set(scene.map((x) => x.i));
67
+ return frames.flatMap((f, i) => (!f.scene || keep.has(i) ? [i] : []));
68
+ }
45
69
  export function splitJpegs(buf) {
46
70
  const out = [];
47
71
  let start = -1;
@@ -59,4 +83,3 @@ export function splitJpegs(buf) {
59
83
  }
60
84
  return out;
61
85
  }
62
- //# sourceMappingURL=player.js.map