@tmhs/screencast-mcp 0.45.0 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,8 @@ export const TOOLSETS = {
18
18
  "screen_diff",
19
19
  "wait_for_change",
20
20
  "find_text",
21
+ "index_recording",
22
+ "search_recording",
21
23
  "review_recording",
22
24
  "player_frames",
23
25
  ],
@@ -34,6 +36,7 @@ export const TOOLSETS = {
34
36
  "compress",
35
37
  "redact_region",
36
38
  "cut_idle",
39
+ "cut_by_transcript",
37
40
  ],
38
41
  produce: [
39
42
  "callout",
@@ -49,6 +52,7 @@ export const TOOLSETS = {
49
52
  "burn_subtitles",
50
53
  "chapters",
51
54
  "bug_report",
55
+ "step_guide",
52
56
  ],
53
57
  audio: ["extract_audio", "normalize_audio", "denoise", "transcribe", "music_bed"],
54
58
  };
@@ -87,11 +91,13 @@ export function serverInstructions(selection) {
87
91
  }
88
92
  if (on.has("watch")) {
89
93
  lines.push("Look: contact_sheet is the cheapest overview, sample_frames (mode scenes) for detail, find_text for OCR " +
90
- "and secret finding, wait_for_change instead of sleeping, screen_diff to compare two states.");
94
+ "and secret finding, wait_for_change instead of sleeping, screen_diff to compare two states. " +
95
+ "Long recording: index_recording once, then search_recording finds moments as text.");
91
96
  }
92
97
  if (on.has("edit")) {
93
- lines.push("Edit: prefer one pipeline call (trim, crop, scale, speed, redact, callout, keystroke_overlay, reframe, zoom, backdrop, then " +
94
- "export_preset or export_gif) over chaining single-edit tools; each tool call re-encodes. trim = one " +
98
+ lines.push("Edit: prefer one pipeline call (trim, crop, scale, speed, cut_idle, redact, callout, keystroke_overlay, reframe, zoom, backdrop, " +
99
+ "audio, burn_subtitles, then export_preset or export_gif) over chaining single-edit tools; each tool call re-encodes. " +
100
+ "To polish a raw recording, start from pipeline recipe pr_demo, tutorial or social_reel (dryRun shows its steps). trim = one " +
95
101
  "segment, clip = several files; export_gif for size-bounded GIF/WebP, compress for a smaller mp4.");
96
102
  }
97
103
  if (on.has("produce")) {
@@ -110,7 +116,7 @@ export function serverInstructions(selection) {
110
116
  lines.push(`Markers: ${marks.filter(Boolean).join(" ")}`);
111
117
  }
112
118
  if (on.has("audio")) {
113
- lines.push("Audio: extract_audio, normalize_audio, denoise, music_bed; transcribe makes an SRT for burn_subtitles.");
119
+ lines.push("Audio: extract_audio, normalize_audio, denoise, music_bed; transcribe makes an SRT for burn_subtitles (words: true for word timing, then cut_by_transcript cuts by quoting it).");
114
120
  }
115
121
  lines.push("Outputs go under SCREENCAST_HOME unless a call names a path; times are seconds and positions video pixels. " +
116
122
  "Screen content can include secrets: redact (find_text redact: true -> redact_region) before sharing. " +
@@ -0,0 +1,134 @@
1
+ import { ScreencastError } from "./errors.js";
2
+ export const FILLERS = ["um", "umm", "uh", "uhh", "uhm", "erm", "er", "ah", "hmm", "hm", "mm", "mhm"];
3
+ export const FILLER_REACH = 0.5;
4
+ export const normWord = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "");
5
+ const r3 = (n) => Number(n.toFixed(3));
6
+ export function cueWords(cues) {
7
+ const out = [];
8
+ cues.forEach((c, ci) => {
9
+ const text = c.text.replace(/\s+/g, " ").trim();
10
+ const toks = [...text.matchAll(/\S+/g)];
11
+ const len = text.length || 1;
12
+ const dur = c.end - c.start;
13
+ toks.forEach((m, k) => {
14
+ const at = m.index;
15
+ out.push({
16
+ cue: ci,
17
+ raw: m[0],
18
+ norm: normWord(m[0]),
19
+ start: k === 0 ? c.start : c.start + (at / len) * dur,
20
+ end: k === toks.length - 1 ? c.end : c.start + ((at + m[0].length) / len) * dur,
21
+ first: k === 0,
22
+ last: k === toks.length - 1,
23
+ });
24
+ });
25
+ });
26
+ return out;
27
+ }
28
+ const spoken = (words) => words.flatMap((w, i) => (w.norm ? [i] : []));
29
+ export function findQuote(words, quote) {
30
+ const q = quote.split(/\s+/).map(normWord).filter(Boolean);
31
+ if (q.length === 0)
32
+ throw new ScreencastError(`Quote "${quote}" has no words to match.`);
33
+ const idx = spoken(words);
34
+ const hits = [];
35
+ for (let i = 0; i + q.length <= idx.length; i++) {
36
+ if (q.every((w, k) => words[idx[i + k]].norm === w))
37
+ hits.push([idx[i], idx[i + q.length - 1]]);
38
+ }
39
+ return hits;
40
+ }
41
+ function rangeCut(words, from, to) {
42
+ let end = to;
43
+ while (words[end + 1] && !words[end + 1].norm && words[end + 1].cue === words[to].cue)
44
+ end++;
45
+ const a = words[from];
46
+ const b = words[end];
47
+ return {
48
+ start: r3(a.start),
49
+ end: r3(b.end),
50
+ text: words.slice(from, end + 1).map((w) => w.raw).join(" "),
51
+ exact: a.first && b.last,
52
+ };
53
+ }
54
+ export function mergeCuts(cuts) {
55
+ const sorted = [...cuts].filter((c) => c.end - c.start > 0.001).sort((a, b) => a.start - b.start);
56
+ const out = [];
57
+ for (const c of sorted) {
58
+ const prev = out[out.length - 1];
59
+ if (prev && c.start <= prev.end + 0.01) {
60
+ if (c.end > prev.end) {
61
+ prev.end = c.end;
62
+ prev.text = `${prev.text} ${c.text}`;
63
+ }
64
+ prev.exact &&= c.exact;
65
+ }
66
+ else
67
+ out.push({ ...c });
68
+ }
69
+ return out;
70
+ }
71
+ export function planTranscriptCuts(cues, req) {
72
+ const words = cueWords(cues);
73
+ const cuts = [];
74
+ for (const r of req.remove ?? []) {
75
+ if (typeof r === "number") {
76
+ const c = cues[r - 1];
77
+ if (!Number.isInteger(r) || !c)
78
+ throw new ScreencastError(`No cue ${r}: the transcript has cues 1-${cues.length}.`);
79
+ cuts.push({ start: r3(c.start), end: r3(c.end), text: c.text.replace(/\s+/g, " "), exact: true });
80
+ continue;
81
+ }
82
+ const hits = findQuote(words, r);
83
+ if (hits.length === 0)
84
+ throw new ScreencastError(`Quote not found in the transcript: "${r}".`);
85
+ if (hits.length > 1) {
86
+ throw new ScreencastError(`Quote "${r}" occurs ${hits.length} times; quote more words or use cue numbers.`);
87
+ }
88
+ cuts.push(rangeCut(words, ...hits[0]));
89
+ }
90
+ let skippedFillers = 0;
91
+ if (req.fillers) {
92
+ const fill = new Set(FILLERS);
93
+ words.forEach((w) => {
94
+ if (!fill.has(w.norm))
95
+ return;
96
+ const alone = words.every((o) => o.cue !== w.cue || o === w || !o.norm);
97
+ if (!alone) {
98
+ skippedFillers++;
99
+ return;
100
+ }
101
+ const cue = cues[w.cue];
102
+ const start = Math.max(cues[w.cue - 1]?.end ?? 0, cue.start - FILLER_REACH);
103
+ const end = Math.min(cues[w.cue + 1]?.start ?? Infinity, cue.end + FILLER_REACH);
104
+ cuts.push({ start: r3(Math.min(start, cue.start)), end: r3(Math.max(end, cue.end)), text: words.filter((o) => o.cue === w.cue).map((o) => o.raw).join(" "), exact: true });
105
+ });
106
+ }
107
+ return { cuts: mergeCuts(cuts), skippedFillers };
108
+ }
109
+ export function mapTime(t, cuts) {
110
+ let shift = 0;
111
+ for (const c of cuts) {
112
+ if (t <= c.start)
113
+ break;
114
+ shift += Math.min(t, c.end) - c.start;
115
+ }
116
+ return t - shift;
117
+ }
118
+ export function retimeCues(cues, cuts) {
119
+ const words = cueWords(cues);
120
+ const inCut = (w) => cuts.some((c) => w.start >= c.start - 0.0005 && w.end <= c.end + 0.0005);
121
+ const out = [];
122
+ cues.forEach((c, ci) => {
123
+ const own = words.filter((w) => w.cue === ci);
124
+ const kept = own.filter((w) => !inCut(w));
125
+ if (!kept.some((w) => w.norm))
126
+ return;
127
+ const text = kept.length === own.length ? c.text : kept.map((w) => w.raw).join(" ");
128
+ const start = r3(mapTime(c.start, cuts));
129
+ const end = r3(mapTime(c.end, cuts));
130
+ if (end > start)
131
+ out.push({ start, end, text });
132
+ });
133
+ return out;
134
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmhs/screencast-mcp",
3
- "version": "0.45.0",
3
+ "version": "0.46.0",
4
4
  "description": "Let AI agents record the Windows screen, watch it as frames, and edit it with ffmpeg",
5
5
  "mcpName": "io.github.TMHSDigital/screencast-mcp",
6
6
  "type": "module",