@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,21 +1,10 @@
1
- /**
2
- * Captions (#120): transcribe speech to SRT with FFmpeg 8's built-in whisper
3
- * filter (whisper.cpp, runs locally), and burn subtitles into a video.
4
- *
5
- * Whisper's SRT needs tidying: it numbers cues from 0 and lets consecutive
6
- * cues overlap (one starting before the previous ends), which some players
7
- * render as two stacked lines. normalizeSrt fixes both. Builders and the SRT
8
- * handling are pure.
9
- */
10
1
  import { existsSync } from "node:fs";
11
2
  import { ScreencastError } from "./errors.js";
12
3
  import { escapeFilterPath } from "./fonts.js";
13
4
  import { resolveQuality } from "./targets.js";
14
- /** Env var naming the default whisper.cpp model file. */
15
5
  export const WHISPER_MODEL_ENV = "SCREENCAST_WHISPER_MODEL";
16
6
  const MODEL_HINT = `Download a whisper.cpp model (ggml-base.en.bin is a good start; ggml-tiny.en.bin is fastest) from ` +
17
7
  `https://huggingface.co/ggerganov/whisper.cpp and pass its path as model, or set ${WHISPER_MODEL_ENV}.`;
18
- /** The model to use: the argument, else the env var. It must exist. */
19
8
  export function resolveWhisperModel(arg, env = process.env) {
20
9
  const model = arg ?? env[WHISPER_MODEL_ENV];
21
10
  if (!model || model.trim().length === 0) {
@@ -25,7 +14,6 @@ export function resolveWhisperModel(arg, env = process.env) {
25
14
  throw new ScreencastError(`Whisper model not found: ${model}`, MODEL_HINT);
26
15
  return model;
27
16
  }
28
- /** Transcribe the input's audio to an SRT file (whisper wants 16 kHz). */
29
17
  export function buildTranscribeArgs(input, model, srtOut, language = "auto") {
30
18
  if (!/^[a-z]{2,3}$|^auto$/.test(language)) {
31
19
  throw new ScreencastError(`language must be a code like "en" or "auto", got "${language}".`);
@@ -48,16 +36,16 @@ function fmt(sec) {
48
36
  const pad = (n, w = 2) => String(n).padStart(w, "0");
49
37
  return `${pad(h)}:${pad(m)}:${pad(s)},${pad(ms % 1000, 3)}`;
50
38
  }
51
- /** Parse SRT into cues (tolerant of CRLF, 0-based numbering, blank lines). */
52
39
  export function parseSrt(srt) {
53
40
  const cues = [];
54
41
  for (const block of srt.replace(/\r\n/g, "\n").split(/\n\s*\n/)) {
55
42
  const lines = block.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
56
43
  const i = lines.findIndex((l) => l.includes("-->"));
57
- if (i === -1)
44
+ const header = lines[i];
45
+ if (header === undefined)
58
46
  continue;
59
- const [a, b] = lines[i].split("-->");
60
- const sa = a.match(TIME);
47
+ const [a, b] = header.split("-->");
48
+ const sa = a?.match(TIME);
61
49
  const sb = b?.match(TIME);
62
50
  if (!sa || !sb)
63
51
  continue;
@@ -67,8 +55,6 @@ export function parseSrt(srt) {
67
55
  }
68
56
  return cues;
69
57
  }
70
- /** Renumber from 1, sort by start, and end each cue no later than the next
71
- * one starts, so cues never overlap. Pure. */
72
58
  export function normalizeCues(cues) {
73
59
  const sorted = [...cues].sort((p, q) => p.start - q.start);
74
60
  return sorted
@@ -82,24 +68,21 @@ export function normalizeCues(cues) {
82
68
  export function formatSrt(cues) {
83
69
  return cues.map((c, i) => `${i + 1}\n${fmt(c.start)} --> ${fmt(c.end)}\n${c.text}\n`).join("\n");
84
70
  }
85
- /** libass force_style overrides. SRT is laid out on a 288 px-tall canvas, so
86
- * sizes are relative to that: "clean" is a modest outlined line at the bottom;
87
- * "social" is large, bold, on a dark box, raised clear of app UI. */
88
71
  export const CAPTION_STYLES = {
89
72
  clean: "FontName=Inter,FontSize=16,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=1.5,Shadow=0,MarginV=16",
90
73
  social: "FontName=Inter,Bold=1,FontSize=22,PrimaryColour=&H00FFFFFF,BackColour=&H99000000,BorderStyle=3,Outline=6,Shadow=0,MarginV=40",
91
74
  };
92
- /** Burn an SRT/ASS file into the video with the bundled font. */
93
75
  export function buildBurnSubtitlesArgs(input, subtitles, output, fontsDir, style = "clean", quality = "standard") {
94
- const force = CAPTION_STYLES[style];
95
- if (!force)
76
+ const force = style === null ? null : CAPTION_STYLES[style];
77
+ if (force === undefined)
96
78
  throw new ScreencastError(`Unknown caption style "${style}".`);
97
79
  return [
98
80
  "-y", "-i", input,
99
- "-vf", `subtitles=filename=${escapeFilterPath(subtitles)}:fontsdir=${escapeFilterPath(fontsDir)}:force_style='${force}'`,
81
+ "-vf",
82
+ `subtitles=filename=${escapeFilterPath(subtitles)}:fontsdir=${escapeFilterPath(fontsDir)}` +
83
+ (force ? `:force_style='${force}'` : ""),
100
84
  ...resolveQuality(quality),
101
85
  "-c:a", "copy",
102
86
  output,
103
87
  ];
104
88
  }
105
- //# sourceMappingURL=captions.js.map
@@ -0,0 +1,29 @@
1
+ import { ScreencastError } from "./errors.js";
2
+ export const CONFIRM_CAPTURE_ENV = "SCREENCAST_CONFIRM_CAPTURE";
3
+ export const CONFIRM_TIMEOUT_MS = 5 * 60 * 1000;
4
+ export function confirmCaptureEnabled(env = process.env) {
5
+ return ["1", "true", "yes", "on"].includes((env[CONFIRM_CAPTURE_ENV] ?? "").trim().toLowerCase());
6
+ }
7
+ export function describeTarget(target, window) {
8
+ if (window)
9
+ return `window "${window.matchedTitle}"`;
10
+ return target === "full" ? "the full screen (all monitors)" : target;
11
+ }
12
+ export async function confirmCapture(server, request, signal) {
13
+ if (!confirmCaptureEnabled())
14
+ return;
15
+ if (!server.server.getClientCapabilities()?.elicitation?.form) {
16
+ throw new ScreencastError(`Capture blocked: ${CONFIRM_CAPTURE_ENV} requires the user to confirm each capture, ` +
17
+ "but this client does not support MCP elicitation. Nothing was captured.", `Use a client that supports elicitation, or unset ${CONFIRM_CAPTURE_ENV} to capture without confirmation.`);
18
+ }
19
+ let action;
20
+ try {
21
+ ({ action } = await server.server.elicitInput({ message: request, requestedSchema: { type: "object", properties: {} } }, { signal, timeout: CONFIRM_TIMEOUT_MS }));
22
+ }
23
+ catch (err) {
24
+ throw new ScreencastError(`Capture blocked: the confirmation request failed (${err instanceof Error ? err.message : String(err)}). Nothing was captured.`);
25
+ }
26
+ if (action !== "accept") {
27
+ throw new ScreencastError(`Capture ${action === "decline" ? "declined" : "cancelled"} by the user. Nothing was captured.`);
28
+ }
29
+ }
@@ -1,31 +1,11 @@
1
- /**
2
- * Frame differencing for screen_diff and wait_for_change (#116).
3
- *
4
- * Frames are compared as small grayscale bitmaps (detectionSize: about a
5
- * quarter of the source width, 320-1600 px). The image is split into a grid of cells; a cell counts as changed when its mean
6
- * absolute difference passes a threshold, and touching changed cells are
7
- * grouped into bounding boxes mapped back to the source's pixel coordinates.
8
- * Everything here is pure, so it is unit-tested on synthetic bitmaps.
9
- */
10
1
  import { ScreencastError } from "./errors.js";
11
2
  import { targetInputArgs, SCREENSHOT_GRAB_FPS } from "./targets.js";
12
3
  import { stillOutput } from "./paths.js";
13
- /** Width frames are analysed at by analysisSize (auto-zoom's whole-video scan). */
14
4
  export const ANALYSIS_WIDTH = 320;
15
- /** screen_diff and wait_for_change analyse at one pixel per this many source
16
- * pixels, so a cell covers the same ~32 source px on a 4K monitor or a
17
- * three-monitor desktop as on a laptop, and a small label change still
18
- * passes the threshold (#234). */
19
5
  export const SOURCE_PX_PER_ANALYSIS_PX = 4;
20
- /** Cap on detectionSize's width, for cost (a 5760 px desktop analyses at 1440). */
21
6
  export const MAX_DETECTION_WIDTH = 1600;
22
- /** Cell size in analysis pixels. */
23
7
  export const CELL = 8;
24
- /** A cell's mean |a - b| (0-255) above this counts as changed. Low enough to
25
- * catch a text caret or a button highlight, high enough to ignore encoder noise. */
26
8
  export const DEFAULT_PIXEL_THRESHOLD = 12;
27
- /** Analysis size for a source of `width` x `height`: at most ANALYSIS_WIDTH
28
- * wide, aspect kept, both sides even and at least 2. */
29
9
  export function analysisSize(width, height) {
30
10
  if (!(width > 0) || !(height > 0))
31
11
  throw new ScreencastError("Image has no size.");
@@ -33,9 +13,6 @@ export function analysisSize(width, height) {
33
13
  const h = Math.max(2, Math.round((height * w) / width / 2) * 2);
34
14
  return { width: Math.max(2, Math.round(w / 2) * 2), height: h };
35
15
  }
36
- /** Analysis size for change detection (#234): SOURCE_PX_PER_ANALYSIS_PX
37
- * source pixels per analysis pixel, between ANALYSIS_WIDTH and
38
- * MAX_DETECTION_WIDTH wide (never wider than the source), aspect kept. */
39
16
  export function detectionSize(width, height) {
40
17
  if (!(width > 0) || !(height > 0))
41
18
  throw new ScreencastError("Image has no size.");
@@ -43,7 +20,6 @@ export function detectionSize(width, height) {
43
20
  const h = Math.max(2, Math.round((height * w) / width / 2) * 2);
44
21
  return { width: Math.max(2, Math.round(w / 2) * 2), height: h };
45
22
  }
46
- /** Pixel size of a resolved capture target (`full` is the union of monitors). */
47
23
  export function targetSize(target, monitors) {
48
24
  switch (target.kind) {
49
25
  case "region":
@@ -67,7 +43,6 @@ export function targetSize(target, monitors) {
67
43
  throw new ScreencastError("Internal: resolve window targets to a region first.");
68
44
  }
69
45
  }
70
- /** Mean |a - b| over two equal-size grayscale bitmaps, as a 0-1 fraction. */
71
46
  export function meanDifference(a, b) {
72
47
  if (a.length !== b.length || a.length === 0)
73
48
  throw new ScreencastError("Frames differ in size.");
@@ -76,8 +51,6 @@ export function meanDifference(a, b) {
76
51
  sum += Math.abs(a[i] - b[i]);
77
52
  return sum / a.length / 255;
78
53
  }
79
- /** Compare two `width` x `height` grayscale bitmaps. `scale` (or `scaleX` /
80
- * `scaleY`) maps analysis pixels to source pixels; `origin` offsets the boxes. */
81
54
  export function diffFrames(a, b, width, height, opts = {}) {
82
55
  if (a.length !== width * height || b.length !== width * height) {
83
56
  throw new ScreencastError("Frame size does not match its dimensions.");
@@ -101,7 +74,6 @@ export function diffFrames(a, b, width, height, opts = {}) {
101
74
  changed[cy * cols + cx] = 1;
102
75
  }
103
76
  }
104
- // Group touching changed cells (8-neighbour flood fill) into boxes.
105
77
  const seen = new Uint8Array(cols * rows);
106
78
  const boxes = [];
107
79
  for (let start = 0; start < changed.length; start++) {
@@ -157,18 +129,9 @@ export function diffFrames(a, b, width, height, opts = {}) {
157
129
  const changedCount = changed.reduce((s, v) => s + v, 0);
158
130
  return { meanDiff: meanDifference(a, b), changedFraction: changedCount / changed.length, regions };
159
131
  }
160
- /** Diff options mapping analysis boxes onto a captured target's own pixels,
161
- * i.e. onto the screenshot of it, not the desktop (#233): callers report the
162
- * target's x/y as `origin` instead. */
163
132
  export function targetDiffOptions(area, size, pixelThreshold) {
164
133
  return { scaleX: area.width / size.width, scaleY: area.height / size.height, pixelThreshold };
165
134
  }
166
- /**
167
- * Settle detection for wait_for_change (#234). Each frame is compared with the
168
- * previous one and with the first frame of the current quiet stretch, so a
169
- * change too slow to pass the threshold between two frames (a progress bar
170
- * creeping along) still ends the quiet stretch once it adds up.
171
- */
172
135
  export class SettleTracker {
173
136
  width;
174
137
  height;
@@ -182,7 +145,6 @@ export class SettleTracker {
182
145
  this.previous = first;
183
146
  this.anchor = first;
184
147
  }
185
- /** Feed the next frame; returns the changed regions, empty when still quiet. */
186
148
  push(frame) {
187
149
  const step = diffFrames(this.previous, frame, this.width, this.height, this.opts).regions;
188
150
  const drift = step.length > 0 ? step : diffFrames(this.anchor, frame, this.width, this.height, this.opts).regions;
@@ -192,8 +154,6 @@ export class SettleTracker {
192
154
  return drift;
193
155
  }
194
156
  }
195
- /** Grab args that decode one frame of a still or video file to a raw gray
196
- * bitmap at the analysis size on stdout. */
197
157
  export function buildRawFrameArgs(input, size) {
198
158
  return [
199
159
  "-v", "error", "-i", input, "-frames:v", "1",
@@ -201,8 +161,6 @@ export function buildRawFrameArgs(input, size) {
201
161
  "-f", "rawvideo", "-",
202
162
  ];
203
163
  }
204
- /** Grab one live frame of a resolved target as a raw gray bitmap at the
205
- * analysis size on stdout (gdigrab at 30 fps; see SCREENSHOT_GRAB_FPS). */
206
164
  export function buildRawGrabArgs(target, monitors, size) {
207
165
  return [
208
166
  "-v", "error", "-f", "gdigrab", "-framerate", String(SCREENSHOT_GRAB_FPS),
@@ -212,19 +170,15 @@ export function buildRawGrabArgs(target, monitors, size) {
212
170
  "-f", "rawvideo", "-",
213
171
  ];
214
172
  }
215
- /** SSIM between two images, both scaled to `size`; score printed to stderr. */
216
173
  export function buildSsimArgs(a, b, size) {
217
174
  const s = `scale=${size.width}:${size.height}:flags=area,format=gray`;
218
175
  return ["-v", "info", "-i", a, "-i", b, "-lavfi", `[0]${s}[x];[1]${s}[y];[x][y]ssim`, "-frames:v", "1", "-f", "null", "-"];
219
176
  }
220
- /** Draw each changed region as a red outline on `input`, for a quick visual. */
221
177
  export function buildHighlightArgs(input, regions, output) {
222
178
  const boxes = regions.map((r) => `drawbox=x=${r.x}:y=${r.y}:w=${r.width}:h=${r.height}:color=red@0.9:t=3`);
223
179
  return ["-y", "-v", "error", "-i", input, "-frames:v", "1", ...(boxes.length ? ["-vf", boxes.join(",")] : []), ...stillOutput(output)];
224
180
  }
225
- /** Parse the `All:` score from ffmpeg's ssim filter output, or null. */
226
181
  export function parseSsim(stderr) {
227
182
  const m = stderr.match(/All:([\d.]+)/);
228
183
  return m ? Number(m[1]) : null;
229
184
  }
230
- //# sourceMappingURL=diff.js.map
@@ -1,12 +1,4 @@
1
- /**
2
- * Shared error type and MCP response helpers.
3
- *
4
- * Every tool returns a JSON text block first; tools that produce frames may
5
- * append image blocks after it (#79). Errors are surfaced as `isError: true` so
6
- * an agent sees an actionable message instead of a transport-level failure.
7
- */
8
1
  export class ScreencastError extends Error {
9
- /** Optional remediation hint shown to the caller (e.g. an install command). */
10
2
  hint;
11
3
  constructor(message, hint) {
12
4
  super(message);
@@ -14,13 +6,14 @@ export class ScreencastError extends Error {
14
6
  this.hint = hint;
15
7
  }
16
8
  }
17
- /** Wrap a JSON-serializable value as a successful tool result, optionally
18
- * followed by image blocks. */
19
9
  export function okResponse(value, images = []) {
20
10
  const text = typeof value === "string" ? value : JSON.stringify(value, null, 2);
21
- return { content: [{ type: "text", text }, ...images] };
11
+ const result = { content: [{ type: "text", text }, ...images] };
12
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
13
+ result.structuredContent = JSON.parse(text);
14
+ }
15
+ return result;
22
16
  }
23
- /** Wrap any thrown value as an error tool result, appending a hint if present. */
24
17
  export function errorResponse(error) {
25
18
  let message;
26
19
  if (error instanceof ScreencastError) {
@@ -34,4 +27,3 @@ export function errorResponse(error) {
34
27
  }
35
28
  return { content: [{ type: "text", text: message }], isError: true };
36
29
  }
37
- //# sourceMappingURL=errors.js.map
@@ -1,43 +1,9 @@
1
- /**
2
- * Input event log for recordings (#118): mouse clicks, scroll, and sampled
3
- * cursor positions, plus key presses, on the video's clock and in video pixels.
4
- *
5
- * A small helper (C# low-level mouse/keyboard hooks, compiled by PowerShell)
6
- * runs for the life of one recording and appends raw lines to
7
- * `<recording>.events.raw`:
8
- *
9
- * <epoch ms>,<type>,<x>,<y>,<data>
10
- *
11
- * When ffmpeg exits the raw file is converted to `<recording>.events.jsonl`:
12
- * times become seconds from the first video frame (gdigrab reports that frame's
13
- * wall-clock time as `start:`), and coordinates are shifted by the capture
14
- * origin so they are video pixels.
15
- *
16
- * Keys are never logged as text, and typed keys are not logged one by one
17
- * (#210): typing becomes `typing` bursts (start and length on a 0.5 s grid),
18
- * because per-key timing alone leaks password lengths and can partly
19
- * reconstruct text. "shortcuts" also names chords made with Ctrl, Alt, or Win
20
- * (Ctrl+S, Alt+Tab) as timed `key` events, which is what a keystroke overlay
21
- * shows; plain typing, Shift+letter, and AltGr characters (including
22
- * Ctrl+Alt+key on AltGr layouts) stay bursts. There is no mode that records
23
- * typed text: that would be a system-wide keylogger.
24
- *
25
- * The helper also writes a heartbeat every second and notes when Windows saw
26
- * input its hooks did not. Those become `gap` events, so a log that stopped
27
- * early says so instead of looking complete.
28
- *
29
- * Everything but `startEventLogger` is pure so it is unit-tested anywhere.
30
- */
31
1
  import { spawn } from "node:child_process";
32
2
  import { existsSync, readFileSync, writeFileSync, unlinkSync, rmSync } from "node:fs";
33
3
  import { ScreencastError } from "./errors.js";
34
4
  export const DEFAULT_KEY_MODE = "masked";
35
5
  export const EVENT_TYPES = ["down", "up", "move", "wheel", "key", "typing", "gap"];
36
- /** Cursor positions are sampled at most this often while the mouse moves. */
37
6
  export const MOVE_SAMPLE_MS = 33;
38
- /** The first input's start time in epoch ms from ffmpeg's stderr banner, or
39
- * null if it has not been printed. gdigrab stamps frames with wall-clock time,
40
- * so `start: 1792936190.232363` is when the first frame was grabbed. */
41
7
  export function parseCaptureStart(stderr) {
42
8
  const input = stderr.indexOf("Input #0");
43
9
  if (input < 0)
@@ -45,11 +11,6 @@ export function parseCaptureStart(stderr) {
45
11
  const m = /start: (\d{9,}\.\d+)/.exec(stderr.slice(input));
46
12
  return m ? Math.round(Number(m[1]) * 1000) : null;
47
13
  }
48
- /**
49
- * Convert raw helper lines to events. Lines that do not parse are skipped (the
50
- * last one can be cut short when the helper is killed). Events before the first
51
- * frame or after `endSec` are dropped.
52
- */
53
14
  export function convertEvents(raw, opts) {
54
15
  const out = [];
55
16
  const beats = [];
@@ -85,7 +46,7 @@ export function convertEvents(raw, opts) {
85
46
  missFrom = null;
86
47
  continue;
87
48
  }
88
- if (type === "gap" || !EVENT_TYPES.includes(type))
49
+ if (type === undefined || type === "gap" || !EVENT_TYPES.includes(type))
89
50
  continue;
90
51
  if (t < 0 || (opts.endSec !== undefined && t > opts.endSec))
91
52
  continue;
@@ -114,21 +75,20 @@ export function convertEvents(raw, opts) {
114
75
  const lastSec = opts.endSec ?? Math.max(0, ...out.map((e) => e.t), ...beats);
115
76
  if (missFrom)
116
77
  gap(missFrom.t, missFrom.x, missFrom.y, lastSec, "input_not_seen");
117
- // Heartbeats only exist in logs from helpers that write them.
118
- if (beats.length > 0) {
119
- beats.sort((a, b) => a - b);
120
- for (let i = 1; i < beats.length; i++) {
121
- if (beats[i] - beats[i - 1] > HEARTBEAT_GAP_SEC)
122
- gap(beats[i - 1], 0, 0, beats[i], "helper_stalled");
123
- }
124
- const last = beats[beats.length - 1];
78
+ beats.sort((a, b) => a - b);
79
+ const last = beats.at(-1);
80
+ if (last !== undefined) {
81
+ beats.reduce((prev, beat) => {
82
+ if (beat - prev > HEARTBEAT_GAP_SEC)
83
+ gap(prev, 0, 0, beat, "helper_stalled");
84
+ return beat;
85
+ });
125
86
  if (opts.endSec !== undefined && opts.endSec - last > HEARTBEAT_GAP_SEC)
126
87
  gap(last, 0, 0, opts.endSec, "helper_stopped");
127
88
  }
128
89
  return out.sort((a, b) => a.t - b.t);
129
90
  }
130
91
  const r3 = (n) => Math.round(n * 1000) / 1000;
131
- /** The gaps in a log, for a summary: where events may be missing. */
132
92
  export function eventGaps(events) {
133
93
  return events
134
94
  .filter((e) => e.type === "gap")
@@ -146,7 +106,6 @@ export function parseEventsJsonl(text) {
146
106
  out.push(JSON.parse(line));
147
107
  }
148
108
  catch {
149
- // A torn line: skip it rather than fail the whole read.
150
109
  }
151
110
  }
152
111
  return out;
@@ -157,7 +116,6 @@ export function selectEvents(events, q) {
157
116
  (!q.types || q.types.includes(e.type)) &&
158
117
  (!q.inFrameOnly || e.inFrame));
159
118
  }
160
- /** Counts per type, for a one-line summary. */
161
119
  export function summarizeEvents(events) {
162
120
  const counts = {};
163
121
  for (const e of events) {
@@ -173,20 +131,10 @@ export function summarizeEvents(events) {
173
131
  }
174
132
  return counts;
175
133
  }
176
- /** Typing is logged as bursts on this grid (ms), never as single keys (#210). */
177
134
  export const TYPING_GRAIN_MS = 500;
178
- /** A pause this long (ms) ends a typing burst. */
179
135
  export const TYPING_GAP_MS = 1000;
180
- /** The helper reports missed input when Windows saw input this long (ms)
181
- * after the hooks last ran: the hook was removed, or the input went to an
182
- * elevated window or the secure desktop. */
183
136
  export const MISSED_INPUT_MS = 2000;
184
- /** Helper heartbeats arrive every second; a gap longer than this (s) means
185
- * the helper stalled or stopped. */
186
137
  export const HEARTBEAT_GAP_SEC = 3;
187
- // The hook helper. __PATH__ is the raw output file (base64 UTF-8), __MODE__ is
188
- // 1 for shortcuts, __PARENT__ the server pid: the helper exits on its own if
189
- // the server dies, so a crash cannot leave a hook running.
190
138
  const PS_HOOK = `
191
139
  $ErrorActionPreference='Stop'
192
140
  $ProgressPreference='SilentlyContinue'
@@ -286,7 +234,6 @@ export function buildHookScript(rawPath, mode, parentPid) {
286
234
  .replace("__MODE__", mode === "shortcuts" ? "1" : "0")
287
235
  .replace("__PARENT__", String(parentPid));
288
236
  }
289
- /** PowerShell reports errors on a redirected stderr as CLIXML; keep the text. */
290
237
  export function cleanPsError(stderr) {
291
238
  if (!stderr.startsWith("#< CLIXML"))
292
239
  return stderr.trim();
@@ -299,14 +246,12 @@ export function cleanPsError(stderr) {
299
246
  .replace(/&amp;/g, "&")
300
247
  .trim();
301
248
  }
302
- /** How long the helper gets to compile its hooks and report ready. */
303
249
  export const LOGGER_READY_TIMEOUT_MS = 20_000;
304
- /** Start the hook helper and resolve once its hooks are installed. */
305
250
  export async function startEventLogger(rawPath, mode) {
306
251
  if (process.platform !== "win32") {
307
252
  throw new ScreencastError("The input event log is implemented for Windows only.");
308
253
  }
309
- rmSync(`${rawPath}.stop`, { force: true }); // a stale one would stop the helper at once
254
+ rmSync(`${rawPath}.stop`, { force: true });
310
255
  const encoded = Buffer.from(buildHookScript(rawPath, mode, process.pid), "utf16le").toString("base64");
311
256
  const child = spawn("powershell", ["-NoProfile", "-NonInteractive", "-EncodedCommand", encoded], {
312
257
  stdio: ["ignore", "pipe", "pipe"],
@@ -340,12 +285,8 @@ export async function startEventLogger(rawPath, mode) {
340
285
  stopFiles.set(child, `${rawPath}.stop`);
341
286
  return child;
342
287
  }
343
- /** Stop file per helper: when it appears, the helper writes out its buffer
344
- * and any open typing burst, then exits. */
345
288
  const stopFiles = new WeakMap();
346
- /** How long a helper gets to flush and exit before it is killed. */
347
289
  export const LOGGER_STOP_GRACE_MS = 2_000;
348
- /** Stop the helper and wait for it to exit, so the raw file is complete. */
349
290
  export function stopEventLogger(child) {
350
291
  if (child.exitCode !== null || child.signalCode !== null)
351
292
  return Promise.resolve();
@@ -355,7 +296,7 @@ export function stopEventLogger(child) {
355
296
  writeFileSync(stop, "");
356
297
  }
357
298
  catch {
358
- stop = undefined; // fall back to killing it
299
+ stop = undefined;
359
300
  }
360
301
  }
361
302
  return new Promise((resolve) => {
@@ -371,13 +312,20 @@ export function stopEventLogger(child) {
371
312
  rmSync(stop, { force: true });
372
313
  });
373
314
  }
374
- /** Sibling paths for a recording's raw and converted event logs. */
375
315
  export function eventPaths(recording) {
376
316
  const base = recording.replace(/\.[^./\\]+$/, "");
377
317
  return { raw: `${base}.events.raw`, jsonl: `${base}.events.jsonl` };
378
318
  }
379
- /** Convert the raw helper output to the recording's events.jsonl and remove
380
- * the raw file. Returns how many events were kept. */
319
+ export function prepareEventPaths(paths, overwrite = false) {
320
+ if (!overwrite) {
321
+ const existing = [paths.jsonl, paths.raw].find((p) => existsSync(p));
322
+ if (existing) {
323
+ throw new ScreencastError(`Event log already exists: ${existing}. Pass overwrite: true to replace it, or choose a different output path.`);
324
+ }
325
+ return;
326
+ }
327
+ rmSync(paths.raw, { force: true });
328
+ }
381
329
  export function writeEventsFile(paths, opts) {
382
330
  const raw = existsSync(paths.raw) ? readFileSync(paths.raw, "utf8") : "";
383
331
  const events = convertEvents(raw, opts);
@@ -386,12 +334,9 @@ export function writeEventsFile(paths, opts) {
386
334
  unlinkSync(paths.raw);
387
335
  }
388
336
  catch {
389
- // Left behind if locked; harmless and gitignored.
390
337
  }
391
338
  return events;
392
339
  }
393
- // Event logs finish converting after ffmpeg exits. stopSession waits on this
394
- // so stop_recording reports the finished log instead of racing it.
395
340
  const finalizers = new Map();
396
341
  export function trackFinalizer(sessionId, done) {
397
342
  finalizers.set(sessionId, done);
@@ -406,4 +351,3 @@ export async function whenFinalized(sessionId, timeoutMs = 10_000) {
406
351
  return;
407
352
  await Promise.race([done, new Promise((r) => setTimeout(r, timeoutMs))]);
408
353
  }
409
- //# sourceMappingURL=events.js.map
@@ -0,0 +1,11 @@
1
+ export const SUM_GROUP = 50;
2
+ export function sumExpr(terms) {
3
+ if (terms.length === 0)
4
+ return "0";
5
+ if (terms.length <= SUM_GROUP)
6
+ return terms.join("+");
7
+ const groups = [];
8
+ for (let i = 0; i < terms.length; i += SUM_GROUP)
9
+ groups.push(`(${terms.slice(i, i + SUM_GROUP).join("+")})`);
10
+ return sumExpr(groups);
11
+ }