@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
@@ -1,18 +1,9 @@
1
- /**
2
- * Dead-air removal (#122). Recordings of an agent at work are full of long
3
- * still stretches while it thinks. A scan finds frozen video (freezedetect)
4
- * and silent audio (silencedetect); idle time is where the picture is frozen
5
- * and, if there is audio, it is also silent. Each idle stretch is cut except
6
- * for a short pad at both edges, in one select/aselect pass. Pure helpers.
7
- */
8
1
  import { ScreencastError } from "./errors.js";
9
2
  import { resolveQuality } from "./targets.js";
3
+ import { sumExpr } from "./expr.js";
10
4
  export const DEFAULT_MIN_IDLE_SEC = 2;
11
5
  export const DEFAULT_KEEP_SEC = 0.4;
12
- /** Cap on cut intervals, keeping the select expression a sane length. */
13
6
  export const MAX_CUTS = 200;
14
- /** Scan for freezes (and silences, when the file has audio); the reports go
15
- * to stderr at info level. */
16
7
  export function buildIdleScanArgs(input, minIdleSec, withAudio) {
17
8
  if (!(minIdleSec > 0))
18
9
  throw new ScreencastError("minIdleSec must be positive.");
@@ -23,8 +14,6 @@ export function buildIdleScanArgs(input, minIdleSec, withAudio) {
23
14
  "-f", "null", "-",
24
15
  ];
25
16
  }
26
- /** Pair start/end markers from the scan. An open interval (the stretch runs to
27
- * the end of the file) is closed at `duration`. Pure. */
28
17
  function pairs(stderr, startRe, endRe, duration) {
29
18
  const out = [];
30
19
  let open = null;
@@ -50,25 +39,26 @@ export function parseFreezes(stderr, duration) {
50
39
  export function parseSilences(stderr, duration) {
51
40
  return pairs(stderr, /silence_start:\s*([\d.]+)/, /silence_end:\s*([\d.]+)/, duration);
52
41
  }
53
- /** Overlap of two sorted interval lists. Pure. */
54
42
  export function intersect(a, b) {
55
43
  const out = [];
56
44
  let i = 0;
57
45
  let j = 0;
58
- while (i < a.length && j < b.length) {
59
- const start = Math.max(a[i].start, b[j].start);
60
- const end = Math.min(a[i].end, b[j].end);
46
+ while (true) {
47
+ const x = a[i];
48
+ const y = b[j];
49
+ if (!x || !y)
50
+ break;
51
+ const start = Math.max(x.start, y.start);
52
+ const end = Math.min(x.end, y.end);
61
53
  if (end > start)
62
54
  out.push({ start, end });
63
- if (a[i].end < b[j].end)
55
+ if (x.end < y.end)
64
56
  i++;
65
57
  else
66
58
  j++;
67
59
  }
68
60
  return out;
69
61
  }
70
- /** Idle stretches (at least minIdleSec long) shrunk by `keep` at each edge,
71
- * i.e. the spans that will actually be removed. Pure. */
72
62
  export function cutsFor(idle, minIdleSec, keep) {
73
63
  return idle
74
64
  .filter((r) => r.end - r.start >= minIdleSec)
@@ -76,21 +66,19 @@ export function cutsFor(idle, minIdleSec, keep) {
76
66
  .filter((r) => r.end - r.start > 0.05)
77
67
  .map((r) => ({ start: Number(r.start.toFixed(3)), end: Number(r.end.toFixed(3)) }));
78
68
  }
79
- /** Remove the cut spans from video (and audio) in one pass. Timestamps are
80
- * regenerated so the result plays continuously. Pure. */
81
69
  export function buildCutIdleArgs(input, output, cuts, withAudio, quality = "standard") {
82
70
  if (cuts.length === 0)
83
71
  throw new ScreencastError("Nothing to cut.");
84
72
  if (cuts.length > MAX_CUTS)
85
73
  throw new ScreencastError(`Too many idle stretches (${cuts.length}); raise minIdleSec.`);
86
- const drop = cuts.map((c) => `between(t,${c.start},${c.end})`).join("+");
74
+ const drop = sumExpr(cuts.map((c) => `between(t,${c.start},${c.end})`));
75
+ const removed = sumExpr(cuts.map((c) => `clip(T-${c.start},0,${Number((c.end - c.start).toFixed(3))})`));
87
76
  return [
88
77
  "-y", "-i", input,
89
- "-vf", `select='not(${drop})',setpts=N/FRAME_RATE/TB`,
78
+ "-vf", `select='not(${drop})',setpts='(T-(${removed}))/TB'`,
90
79
  ...(withAudio ? ["-af", `aselect='not(${drop})',asetpts=N/SR/TB`] : ["-an"]),
91
80
  ...resolveQuality(quality),
92
81
  ...(withAudio ? ["-c:a", "aac", "-b:a", "160k"] : []),
93
82
  output,
94
83
  ];
95
84
  }
96
- //# sourceMappingURL=idle.js.map
@@ -1,24 +1,10 @@
1
- /**
2
- * Inline image results (#79).
3
- *
4
- * Tools that produce frames can return them as MCP `image` content blocks so a
5
- * client shows them to the model directly, with no filesystem tool needed.
6
- * Payloads stay bounded: every frame is downscaled to a max width and
7
- * re-encoded as JPEG, and only the first N frames are embedded.
8
- */
9
1
  import { readFileSync, rmSync } from "node:fs";
10
2
  import { ScreencastError } from "./errors.js";
11
3
  import { runFfmpeg } from "./ffmpeg.js";
12
4
  import { tempPath, stillOutput } from "./paths.js";
13
- /** Default downscale width for inline previews. */
14
5
  export const DEFAULT_MAX_IMAGE_WIDTH = 1280;
15
- /** Default number of frames embedded in one tool result. */
16
6
  export const DEFAULT_MAX_INLINE_IMAGES = 8;
17
- /** Hard ceiling on embedded frames, whatever the caller asks for. */
18
7
  export const MAX_INLINE_IMAGES = 20;
19
- /** Build args that turn one image or video frame into a downscaled JPEG
20
- * preview. The width cap only ever downscales (min of the source width and
21
- * maxWidth); -2 keeps the aspect ratio. */
22
8
  export function buildPreviewArgs(input, output, maxWidth) {
23
9
  if (!Number.isInteger(maxWidth) || maxWidth < 16) {
24
10
  throw new ScreencastError("maxImageWidth must be an integer of at least 16.");
@@ -31,12 +17,10 @@ export function buildPreviewArgs(input, output, maxWidth) {
31
17
  ...stillOutput(output),
32
18
  ];
33
19
  }
34
- /** Clamp a caller-supplied inline-image count to [0, MAX_INLINE_IMAGES]. */
35
20
  export function clampInlineCount(requested) {
36
21
  const n = requested ?? DEFAULT_MAX_INLINE_IMAGES;
37
22
  return Math.max(0, Math.min(MAX_INLINE_IMAGES, Math.floor(n)));
38
23
  }
39
- /** Encode up to `maxCount` image files as downscaled JPEG image blocks. */
40
24
  export async function encodeInlineImages(paths, maxWidth = DEFAULT_MAX_IMAGE_WIDTH, maxCount = DEFAULT_MAX_INLINE_IMAGES) {
41
25
  const chosen = paths.slice(0, maxCount);
42
26
  const images = [];
@@ -52,4 +36,3 @@ export async function encodeInlineImages(paths, maxWidth = DEFAULT_MAX_IMAGE_WID
52
36
  }
53
37
  return { images, omitted: paths.length - chosen.length };
54
38
  }
55
- //# sourceMappingURL=images.js.map
@@ -1,33 +1,11 @@
1
- /**
2
- * Long-running edit jobs (#81).
3
- *
4
- * Edit tools used to run ffmpeg with a fixed 5-20 minute timeout, wrote
5
- * straight to the output path, and reported nothing until they finished. A
6
- * long recording could time out partway, leave a truncated file at `output`
7
- * (which then blocked a retry with "Output already exists"), and the agent had
8
- * no idea how far it got. runEditJob fixes all three:
9
- *
10
- * - the timeout scales with the media's duration (env override available);
11
- * - ffmpeg writes a `.partial` sibling that is renamed onto `output` only on
12
- * success and deleted on any failure, timeout, or cancellation;
13
- * - `-progress pipe:1` is parsed and forwarded as MCP progress notifications
14
- * when the request carried a progressToken.
15
- */
16
1
  import { basename, dirname, extname, join } from "node:path";
17
2
  import { renameSync, rmSync } from "node:fs";
18
3
  import { ScreencastError } from "./errors.js";
19
4
  import { probeMedia, runFfmpeg } from "./ffmpeg.js";
20
- /** Env var that overrides every edit job's timeout, in milliseconds. */
21
5
  export const JOB_TIMEOUT_ENV = "SCREENCAST_JOB_TIMEOUT_MS";
22
- /** Floor for a duration-scaled timeout. */
23
6
  export const BASE_TIMEOUT_MS = 10 * 60_000;
24
- /** Timeout when the media's duration could not be probed. */
25
7
  export const UNKNOWN_DURATION_TIMEOUT_MS = 30 * 60_000;
26
- /** Allow this many seconds of wall-clock time per second of media. A slow
27
- * preset on a laptop runs around real time; 4x leaves ample headroom. */
28
8
  export const SECONDS_PER_MEDIA_SECOND = 4;
29
- /** Timeout for a job over `durationSec` of media: max(base, duration * 4x),
30
- * or the env override when it is a positive integer. */
31
9
  export function jobTimeoutMs(durationSec, env = process.env) {
32
10
  const override = Number(env[JOB_TIMEOUT_ENV]);
33
11
  if (Number.isInteger(override) && override > 0)
@@ -36,14 +14,10 @@ export function jobTimeoutMs(durationSec, env = process.env) {
36
14
  return UNKNOWN_DURATION_TIMEOUT_MS;
37
15
  return Math.max(BASE_TIMEOUT_MS, Math.ceil(durationSec * SECONDS_PER_MEDIA_SECOND * 1000));
38
16
  }
39
- /** `dir/name.partial.ext`: keeps the extension so ffmpeg picks the same muxer. */
40
17
  export function partialPath(output) {
41
18
  const ext = extname(output);
42
19
  return join(dirname(output), `${basename(output, ext)}.partial${ext}`);
43
20
  }
44
- /** Point a builder's args at `partial` instead of `output`. Builders put the
45
- * output path last; replacing the last occurrence leaves an identical input
46
- * path (rare, but legal with overwrite) untouched. */
47
21
  export function retargetOutput(args, output, partial) {
48
22
  const i = args.lastIndexOf(output);
49
23
  if (i === -1) {
@@ -53,8 +27,6 @@ export function retargetOutput(args, output, partial) {
53
27
  next[i] = partial;
54
28
  return next;
55
29
  }
56
- /** Feed `-progress pipe:1` output in chunks; returns the latest media time in
57
- * seconds seen so far. Lines can split across chunks, so it buffers. */
58
30
  export function createProgressParser() {
59
31
  let buffer = "";
60
32
  let latest = null;
@@ -63,8 +35,6 @@ export function createProgressParser() {
63
35
  const lines = buffer.split(/\r?\n/);
64
36
  buffer = lines.pop() ?? "";
65
37
  for (const line of lines) {
66
- // out_time_us is microseconds; ffmpeg's out_time_ms is also microseconds
67
- // (a long-standing naming bug), so either works as a fallback.
68
38
  const m = line.match(/^out_time_(?:us|ms)=(\d+)$/);
69
39
  if (m)
70
40
  latest = Number(m[1]) / 1_000_000;
@@ -72,9 +42,6 @@ export function createProgressParser() {
72
42
  return latest;
73
43
  };
74
44
  }
75
- /** A progress callback that forwards to the client as MCP progress
76
- * notifications, or undefined when the request asked for none. Updates are
77
- * throttled to whole-percent steps. */
78
45
  export function progressReporter(extra) {
79
46
  const token = extra?._meta?.progressToken;
80
47
  if (token === undefined || !extra)
@@ -91,21 +58,29 @@ export function progressReporter(extra) {
91
58
  params: { progressToken: token, progress: percent, total: 100 },
92
59
  })
93
60
  .catch(() => {
94
- /* a client that went away must not fail the job */
95
61
  });
96
62
  };
97
63
  }
98
- /** Run an ffmpeg edit job atomically: write a .partial sibling, rename it onto
99
- * the output on success, and delete it on any failure. */
64
+ const activeJobs = new Set();
65
+ let jobsClosed = false;
100
66
  export async function runEditJob(args, job) {
67
+ if (jobsClosed)
68
+ throw new ScreencastError("The server is shutting down; the edit was not started.");
101
69
  const partial = partialPath(job.output);
102
70
  const report = progressReporter(job.extra);
103
71
  const parse = createProgressParser();
104
72
  const duration = job.durationSec != null && job.durationSec > 0 ? job.durationSec : null;
73
+ const input = job.inputDurationSec != null && job.inputDurationSec > 0 ? job.inputDurationSec : null;
74
+ const decoded = input !== null && duration !== null ? Math.max(input, duration) : (input ?? duration);
105
75
  const ffArgs = ["-progress", "pipe:1", "-nostats", ...retargetOutput(args, job.output, partial)];
76
+ const controller = new AbortController();
77
+ const signal = job.extra?.signal ? AbortSignal.any([job.extra.signal, controller.signal]) : controller.signal;
78
+ let finish;
79
+ const active = { partial, controller, done: new Promise((r) => (finish = r)) };
80
+ activeJobs.add(active);
106
81
  try {
107
- await runFfmpeg(ffArgs, jobTimeoutMs(duration), {
108
- signal: job.extra?.signal,
82
+ await runFfmpeg(ffArgs, jobTimeoutMs(decoded), {
83
+ signal,
109
84
  onStdout: report && duration
110
85
  ? (chunk) => {
111
86
  const t = parse(chunk);
@@ -121,9 +96,36 @@ export async function runEditJob(args, job) {
121
96
  rmSync(partial, { force: true });
122
97
  throw error;
123
98
  }
99
+ finally {
100
+ activeJobs.delete(active);
101
+ finish();
102
+ }
103
+ }
104
+ export function activeEditJobs() {
105
+ return activeJobs.size;
106
+ }
107
+ export async function abortEditJobs(graceMs = 3_000) {
108
+ jobsClosed = true;
109
+ const jobs = [...activeJobs];
110
+ if (jobs.length === 0)
111
+ return 0;
112
+ for (const job of jobs)
113
+ job.controller.abort();
114
+ let timer;
115
+ await Promise.race([
116
+ Promise.all(jobs.map((j) => j.done)),
117
+ new Promise((r) => (timer = setTimeout(r, graceMs))),
118
+ ]);
119
+ clearTimeout(timer);
120
+ for (const job of jobs) {
121
+ try {
122
+ rmSync(job.partial, { force: true });
123
+ }
124
+ catch {
125
+ }
126
+ }
127
+ return jobs.length;
124
128
  }
125
- /** Probe a file's duration, or null when it cannot be read. Used to size
126
- * timeouts and progress; never fails the job on its own. */
127
129
  export async function probeDuration(input) {
128
130
  try {
129
131
  return (await probeMedia(input)).durationSec;
@@ -132,4 +134,3 @@ export async function probeDuration(input) {
132
134
  return null;
133
135
  }
134
136
  }
135
- //# sourceMappingURL=jobs.js.map
@@ -1,11 +1,3 @@
1
- /**
2
- * Recording stop sequence, shared by stop_recording and server shutdown.
3
- *
4
- * Graceful first: ffmpeg quits cleanly (and finalizes the mp4) on 'q' over
5
- * stdin. If it does not exit in time, or the live handle was lost (a
6
- * cross-restart stop), the process is terminated by pid; the fragmented-mp4
7
- * muxing keeps a killed recording playable either way.
8
- */
9
1
  import { existsSync, rmSync, writeFileSync } from "node:fs";
10
2
  import { runCapture } from "./ffmpeg.js";
11
3
  import { whenFinalized } from "./events.js";
@@ -13,14 +5,12 @@ import { buildProbeArgs, parseMediaInfo } from "./media.js";
13
5
  import { ScreencastError } from "./errors.js";
14
6
  import { wgcStopFile } from "./wgc.js";
15
7
  import { expectedImage, isAlive, isRecorderProcess, killPid, } from "./sessions.js";
16
- /** Poll until a pid is gone (process fully exited, file handles released). */
17
8
  async function waitForPidExit(pid, ms) {
18
9
  const deadline = Date.now() + ms;
19
10
  while (Date.now() < deadline && isAlive(pid)) {
20
11
  await new Promise((r) => setTimeout(r, 100));
21
12
  }
22
13
  }
23
- /** Wait up to ms for a child to exit; resolve true if it did. */
24
14
  export function waitForExit(child, ms) {
25
15
  return new Promise((resolve) => {
26
16
  if (child.exitCode !== null || child.signalCode !== null)
@@ -32,7 +22,6 @@ export function waitForExit(child, ms) {
32
22
  });
33
23
  });
34
24
  }
35
- /** Probe a finished file's duration, or null if it is missing/unreadable. */
36
25
  export async function probeDuration(ffprobe, path) {
37
26
  if (!existsSync(path))
38
27
  return null;
@@ -46,11 +35,6 @@ export async function probeDuration(ffprobe, path) {
46
35
  return null;
47
36
  }
48
37
  }
49
- /**
50
- * Stop every recording this instance owns (server shutdown, #76). Stops run in
51
- * parallel and the whole pass is capped at `capMs` so a wedged ffmpeg cannot
52
- * hold the process open; never throws. Returns the ids it attempted.
53
- */
54
38
  export async function stopAll(store, probe, capMs = 10_000) {
55
39
  const ids = store.activeIds();
56
40
  const stops = ids.map(async (id) => {
@@ -72,12 +56,7 @@ export async function stopAll(store, probe, capMs = 10_000) {
72
56
  clearTimeout(timer);
73
57
  return ids;
74
58
  }
75
- /** Stops in flight, per store and session id. A second stop of the same
76
- * session (an agent retry, or shutdown racing stop_recording) joins the first
77
- * instead of force-killing a recording that is still finalizing (#181). */
78
59
  const inFlight = new WeakMap();
79
- /** Stop an active recording and record its final state. The caller has already
80
- * checked the record exists and is "recording". */
81
60
  export function stopSession(store, record, opts) {
82
61
  let stops = inFlight.get(store);
83
62
  if (!stops)
@@ -105,12 +84,8 @@ async function runStop(store, record, opts) {
105
84
  }
106
85
  }
107
86
  else if (record.pid !== null && isAlive(record.pid)) {
108
- // Cross-restart stop: no stdin handle. Act on the pid only while it is
109
- // still the recorder this record started (never a recycled, unrelated
110
- // process); the wgc recorder runs under node, not ffmpeg (#182).
111
87
  if (isRecorderProcess(record.pid, expectedImage(record))) {
112
88
  if (stopFile) {
113
- // The wgc recorder finalizes when its stop file appears.
114
89
  writeFileSync(stopFile, "");
115
90
  await waitForPidExit(record.pid, opts.gracefulMs ?? 8000);
116
91
  graceful = !isAlive(record.pid);
@@ -125,7 +100,6 @@ async function runStop(store, record, opts) {
125
100
  }
126
101
  }
127
102
  store.detachChild(record.id);
128
- // The input event log converts once ffmpeg has exited (#118).
129
103
  await whenFinalized(record.id);
130
104
  const durationSec = await opts.probe(record.outputPath);
131
105
  const updated = store.update(record.id, {
@@ -133,8 +107,6 @@ async function runStop(store, record, opts) {
133
107
  stoppedAt: new Date().toISOString(),
134
108
  durationSec: durationSec ?? undefined,
135
109
  endReason: opts.reason,
136
- // A forced kill can transiently mark the record "failed" via the crash
137
- // detector in start_recording; a deliberate stop is not a failure.
138
110
  error: undefined,
139
111
  });
140
112
  return { record: updated, graceful, durationSec };
@@ -145,4 +117,3 @@ async function runStop(store, record, opts) {
145
117
  store.clearStopping(record.id);
146
118
  }
147
119
  }
148
- //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1,75 @@
1
+ export const LOGGER_NAME = "screencast-mcp";
2
+ const servers = new Set();
3
+ export function attachLogging(server) {
4
+ servers.add(server);
5
+ }
6
+ export function logMessage(level, message, data = {}) {
7
+ for (const server of servers) {
8
+ if (!server.isConnected())
9
+ continue;
10
+ server
11
+ .sendLoggingMessage({ level, logger: LOGGER_NAME, data: { message, ...data } })
12
+ .catch(() => { });
13
+ }
14
+ }
15
+ const PROGRESS = /^\s*(?:frame|size)=/;
16
+ const WARNING = /\b(?:warning|deprecated|dropp(?:ed|ing)|too full|discard\w*|non[- ]?monoton\w*|past duration|could not|cannot|failed|invalid|corrupt\w*|missing|error)\b/i;
17
+ const BENIGN = /^\s*configuration:|deprecated pixel format used/i;
18
+ export const MAX_WARNINGS = 20;
19
+ function isWarning(line) {
20
+ return !PROGRESS.test(line) && WARNING.test(line) && !BENIGN.test(line);
21
+ }
22
+ export function ffmpegWarnings(stderr) {
23
+ const out = new Set();
24
+ for (const raw of stderr.split(/[\r\n]+/)) {
25
+ const line = raw.trim();
26
+ if (line && isWarning(line))
27
+ out.add(line);
28
+ if (out.size >= MAX_WARNINGS)
29
+ break;
30
+ }
31
+ return [...out];
32
+ }
33
+ export function logFfmpegWarnings(stderr, data = {}) {
34
+ const warnings = ffmpegWarnings(stderr);
35
+ if (warnings.length > 0)
36
+ logMessage("warning", "ffmpeg reported warnings.", { ...data, warnings });
37
+ }
38
+ export const DROP_REPORT_INTERVAL_MS = 10_000;
39
+ export class StderrWatch {
40
+ data;
41
+ send;
42
+ now;
43
+ partial = "";
44
+ seen = new Set();
45
+ dropped = 0;
46
+ lastDropReport = -Infinity;
47
+ constructor(data, send = logMessage, now = Date.now) {
48
+ this.data = data;
49
+ this.send = send;
50
+ this.now = now;
51
+ }
52
+ feed(chunk) {
53
+ const parts = (this.partial + chunk).split(/[\r\n]/);
54
+ this.partial = parts.pop() ?? "";
55
+ for (const raw of parts)
56
+ this.line(raw.trim());
57
+ }
58
+ line(line) {
59
+ if (!line)
60
+ return;
61
+ if (PROGRESS.test(line)) {
62
+ const drop = Number(/\bdrop=\s*(\d+)/.exec(line)?.[1] ?? 0);
63
+ if (drop > this.dropped && this.now() - this.lastDropReport >= DROP_REPORT_INTERVAL_MS) {
64
+ this.lastDropReport = this.now();
65
+ this.dropped = drop;
66
+ this.send("warning", `The recording has dropped ${drop} frame(s) so far.`, { ...this.data(), dropped: drop });
67
+ }
68
+ return;
69
+ }
70
+ if (!isWarning(line) || this.seen.has(line) || this.seen.size >= MAX_WARNINGS)
71
+ return;
72
+ this.seen.add(line);
73
+ this.send("warning", line, { ...this.data(), source: "ffmpeg" });
74
+ }
75
+ }