@tmhs/screencast-mcp 0.44.2 → 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.
- package/README.md +58 -11
- package/assets/ui/player.html +9 -0
- package/assets/ui/player.js +20 -0
- package/dist/index.js +12 -0
- package/dist/prompts.js +34 -4
- package/dist/server.js +20 -0
- package/dist/tools/addMarker.js +89 -0
- package/dist/tools/backdrop.js +89 -0
- package/dist/tools/bugReport.js +266 -0
- package/dist/tools/chapters.js +156 -0
- package/dist/tools/contactSheet.js +19 -17
- package/dist/tools/cutByTranscript.js +86 -0
- package/dist/tools/findText.js +14 -64
- package/dist/tools/indexRecording.js +173 -0
- package/dist/tools/keystrokeOverlay.js +131 -0
- package/dist/tools/pipeline.js +251 -18
- package/dist/tools/reviewRecording.js +12 -0
- package/dist/tools/saveReplay.js +90 -0
- package/dist/tools/searchRecording.js +73 -0
- package/dist/tools/startRecording.js +51 -10
- package/dist/tools/stepGuide.js +193 -0
- package/dist/tools/stopRecording.js +25 -1
- package/dist/tools/transcribe.js +4 -3
- package/dist/tools/zoom.js +1 -1
- package/dist/utils/audio.js +12 -4
- package/dist/utils/backdrop.js +151 -0
- package/dist/utils/bugReport.js +172 -0
- package/dist/utils/captions.js +19 -6
- package/dist/utils/chapters.js +227 -0
- package/dist/utils/idle.js +10 -3
- package/dist/utils/keystrokes.js +155 -0
- package/dist/utils/lifecycle.js +11 -2
- package/dist/utils/media.js +5 -2
- package/dist/utils/ocrScan.js +77 -0
- package/dist/utils/pipeline.js +169 -15
- package/dist/utils/recipes.js +67 -0
- package/dist/utils/recordingIndex.js +266 -0
- package/dist/utils/replay.js +278 -0
- package/dist/utils/stepGuide.js +205 -0
- package/dist/utils/steps.js +88 -0
- package/dist/utils/timeline.js +85 -0
- package/dist/utils/toolsets.js +32 -6
- package/dist/utils/transcriptCut.js +134 -0
- package/package.json +1 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { maskSecrets, DEFAULT_SECRET_PATTERN } from "./bugReport.js";
|
|
2
|
+
import { formatTimecode } from "./sheet.js";
|
|
3
|
+
import { ringSize, DEFAULT_RING_COLOR } from "./zoom.js";
|
|
4
|
+
export const MAX_GUIDE_STEPS = 100;
|
|
5
|
+
export const SHOT_LEAD_SEC = 0.1;
|
|
6
|
+
export const SHOT_MAX_WIDTH = 1280;
|
|
7
|
+
const LABEL_MAX = 40;
|
|
8
|
+
const LABEL_REACH_PX = 24;
|
|
9
|
+
export const GUIDE_FILES = {
|
|
10
|
+
markdown: "guide.md",
|
|
11
|
+
html: "guide.html",
|
|
12
|
+
images: "images",
|
|
13
|
+
image: (n) => `step-${String(n).padStart(2, "0")}.png`,
|
|
14
|
+
};
|
|
15
|
+
export function caption(s) {
|
|
16
|
+
return s.label ? `${s.text} ${s.label}` : s.text;
|
|
17
|
+
}
|
|
18
|
+
const r3 = (n) => Math.round(n * 1000) / 1000;
|
|
19
|
+
export function shotTime(t, durationSec, fps) {
|
|
20
|
+
const last = Math.max(0, durationSec - 1 / (fps > 0 ? fps : 30));
|
|
21
|
+
return r3(Math.min(Math.max(0, t - SHOT_LEAD_SEC), last));
|
|
22
|
+
}
|
|
23
|
+
function distance(r, x, y) {
|
|
24
|
+
const dx = Math.max(r.x - x, 0, x - (r.x + r.width));
|
|
25
|
+
const dy = Math.max(r.y - y, 0, y - (r.y + r.height));
|
|
26
|
+
return Math.hypot(dx, dy);
|
|
27
|
+
}
|
|
28
|
+
export function labelAt(lines, x, y) {
|
|
29
|
+
const near = lines
|
|
30
|
+
.map((line) => ({ line, d: distance(line, x, y) }))
|
|
31
|
+
.filter((c) => c.d <= LABEL_REACH_PX && c.line.text.trim().length > 0)
|
|
32
|
+
.sort((a, b) => a.d - b.d || a.line.width * a.line.height - b.line.width * b.line.height);
|
|
33
|
+
const best = near[0]?.line;
|
|
34
|
+
if (!best)
|
|
35
|
+
return null;
|
|
36
|
+
let text = best.text.replace(/\s+/g, " ").trim();
|
|
37
|
+
if (text.length > LABEL_MAX) {
|
|
38
|
+
const word = [...best.words].sort((a, b) => distance(a, x, y) - distance(b, x, y))[0];
|
|
39
|
+
text = word ? word.text.trim() : `${text.slice(0, LABEL_MAX - 1).trimEnd()}…`;
|
|
40
|
+
}
|
|
41
|
+
return text.length > 0 ? text : null;
|
|
42
|
+
}
|
|
43
|
+
function clickVerb(s) {
|
|
44
|
+
const verb = s.action === "double_click" ? "double-click" : "click";
|
|
45
|
+
const b = s.button && s.button !== "left" ? `${s.button.charAt(0).toUpperCase()}${s.button.slice(1)}-${verb}` : verb;
|
|
46
|
+
return b.charAt(0).toUpperCase() + b.slice(1);
|
|
47
|
+
}
|
|
48
|
+
export function guideSteps(steps, opts) {
|
|
49
|
+
const pattern = opts.secretPattern ?? DEFAULT_SECRET_PATTERN;
|
|
50
|
+
const mask = (s) => maskSecrets([s], pattern)[0] ?? s;
|
|
51
|
+
let n = 0;
|
|
52
|
+
return steps.map((s, i) => {
|
|
53
|
+
if (s.action === "gap")
|
|
54
|
+
return { n: 0, t: s.t, action: s.action, text: s.text };
|
|
55
|
+
n++;
|
|
56
|
+
const base = { n, t: s.t, action: s.action, text: s.text, shotT: shotTime(s.t, opts.durationSec, opts.fps) };
|
|
57
|
+
const label = opts.labels?.[i];
|
|
58
|
+
if (s.action === "click" || s.action === "double_click") {
|
|
59
|
+
const verb = clickVerb(s);
|
|
60
|
+
if (s.inFrame === false)
|
|
61
|
+
return { ...base, text: `${verb} outside the recorded area` };
|
|
62
|
+
return {
|
|
63
|
+
...base,
|
|
64
|
+
x: s.x,
|
|
65
|
+
y: s.y,
|
|
66
|
+
...(label ? { text: verb, label: mask(label) } : { text: `${verb} the marked spot` }),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (s.action === "scroll") {
|
|
70
|
+
return { ...base, ...(s.inFrame === false ? {} : { x: s.x, y: s.y }), ...(label ? { text: `${s.text} over`, label: mask(label) } : {}) };
|
|
71
|
+
}
|
|
72
|
+
if (s.action === "shortcut")
|
|
73
|
+
return s.keys ? { ...base, text: "Press", label: s.keys } : base;
|
|
74
|
+
return { ...base, text: "Type text" };
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export function assignSections(steps, markers) {
|
|
78
|
+
const sorted = [...markers].sort((a, b) => a.t - b.t);
|
|
79
|
+
return steps.map((s) => {
|
|
80
|
+
const m = sorted.filter((k) => k.t <= s.t + 1e-6).at(-1);
|
|
81
|
+
return m ? { ...s, section: m.label } : s;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
export function shotFilter(size, opts) {
|
|
85
|
+
const n = (v) => String(Math.round(v));
|
|
86
|
+
const chain = [];
|
|
87
|
+
for (const b of opts.boxes ?? [])
|
|
88
|
+
chain.push(`drawbox=x=${n(b.x)}:y=${n(b.y)}:w=${n(b.width)}:h=${n(b.height)}:color=black:t=fill`);
|
|
89
|
+
const scale = `scale=w='min(iw,${SHOT_MAX_WIDTH})':h=-2:flags=lanczos`;
|
|
90
|
+
const base = `[0:v]${chain.length ? chain.join(",") + "," : ""}format=rgba`;
|
|
91
|
+
if (!opts.click)
|
|
92
|
+
return `${base},${scale},format=rgb24[out]`;
|
|
93
|
+
const D = ringSize(size.width, size.height);
|
|
94
|
+
const c = D / 2;
|
|
95
|
+
const th = Math.max(3, Math.round(D / 10));
|
|
96
|
+
const r = c - th / 2 - 1;
|
|
97
|
+
const color = opts.color ?? DEFAULT_RING_COLOR;
|
|
98
|
+
return (`${base}[bg];` +
|
|
99
|
+
`color=c=${color}:s=${D}x${D}:d=1,format=rgba,` +
|
|
100
|
+
`geq=r='r(X,Y)':g='g(X,Y)':b='b(X,Y)':a='if(lt(abs(hypot(X-${c},Y-${c})-${r}),${th / 2}),255,0)'[ring];` +
|
|
101
|
+
`[bg][ring]overlay=x=${n(opts.click.x - c)}:y=${n(opts.click.y - c)},${scale},format=rgb24[out]`);
|
|
102
|
+
}
|
|
103
|
+
export function buildStepFrameArgs(input, t, output) {
|
|
104
|
+
return ["-y", "-v", "error", "-ss", String(t), "-i", input, "-frames:v", "1", output];
|
|
105
|
+
}
|
|
106
|
+
export function buildStepShotArgs(frame, filter, output) {
|
|
107
|
+
return ["-y", "-v", "error", "-i", frame, "-filter_complex", filter, "-map", "[out]", "-frames:v", "1", output];
|
|
108
|
+
}
|
|
109
|
+
const md = (s) => s.replace(/\s*\n\s*/g, " ").replace(/([\\`*_[\]<>#|])/g, "\\$1");
|
|
110
|
+
function footer(g) {
|
|
111
|
+
const scan = g.ocr === "read"
|
|
112
|
+
? `Screenshots scanned for secrets with OCR (best-effort); ${g.redactions} region${g.redactions === 1 ? "" : "s"} boxed out.`
|
|
113
|
+
: "Screenshots were not scanned for secrets: review them before sharing.";
|
|
114
|
+
return `${scan} Typed text is never logged, so it never appears here.`;
|
|
115
|
+
}
|
|
116
|
+
function intro(g) {
|
|
117
|
+
const count = g.steps.filter((s) => s.n > 0).length;
|
|
118
|
+
return `${count} step${count === 1 ? "" : "s"} from a ${formatTimecode(g.recording.durationSec)} recording.`;
|
|
119
|
+
}
|
|
120
|
+
export function buildGuideMarkdown(g) {
|
|
121
|
+
const out = [`# ${md(g.title)}`, "", intro(g), ""];
|
|
122
|
+
if (g.steps.length === 0)
|
|
123
|
+
out.push(`_${g.stepsNote ?? "No steps in the recording."}_`, "");
|
|
124
|
+
let section;
|
|
125
|
+
for (const s of g.steps) {
|
|
126
|
+
if (s.section !== undefined && s.section !== section) {
|
|
127
|
+
section = s.section;
|
|
128
|
+
out.push(`## ${md(section)}`, "");
|
|
129
|
+
}
|
|
130
|
+
if (s.n === 0) {
|
|
131
|
+
out.push(`> _${md(s.text)}_`, "");
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const line = s.label ? `${md(s.text)} **${md(s.label)}**` : md(s.text);
|
|
135
|
+
out.push(`${s.n}. ${line} <sub>${formatTimecode(s.t)}</sub>`, "");
|
|
136
|
+
if (s.image)
|
|
137
|
+
out.push(` `, "");
|
|
138
|
+
}
|
|
139
|
+
if (g.stepsOmitted)
|
|
140
|
+
out.push(`_${g.stepsOmitted} more steps not shown._`, "");
|
|
141
|
+
out.push("<sub>", footer(g), `Generated by screencast-mcp step_guide, ${g.createdAt}.`, "</sub>", "");
|
|
142
|
+
return out.join("\n");
|
|
143
|
+
}
|
|
144
|
+
const html = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
145
|
+
const STYLE = `:root{--bg:#f6f5f2;--card:#fff;--ink:#16161a;--dim:#6b6b74;--line:#e2e0da;--rec:#e5383b}
|
|
146
|
+
@media (prefers-color-scheme:dark){:root{--bg:#121214;--card:#1b1b1f;--ink:#ececf1;--dim:#9a9aa6;--line:#2c2c33}}
|
|
147
|
+
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.55 system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
148
|
+
main{max-width:920px;margin:0 auto;padding:40px 16px 64px}
|
|
149
|
+
header{border-bottom:1px solid var(--line);padding-bottom:20px;margin-bottom:28px}
|
|
150
|
+
.rec{font:600 12px/1 ui-monospace,"Cascadia Mono",Consolas,monospace;letter-spacing:.12em;color:var(--rec);text-transform:uppercase}
|
|
151
|
+
.rec::before{content:"";display:inline-block;width:8px;height:8px;border-radius:50%;background:var(--rec);margin-right:8px;vertical-align:1px}
|
|
152
|
+
h1{font-size:30px;line-height:1.2;margin:10px 0 6px}h2{font-size:20px;margin:40px 0 16px}
|
|
153
|
+
.meta{color:var(--dim);margin:0}ol{list-style:none;margin:0;padding:0}
|
|
154
|
+
li{background:var(--card);border:1px solid var(--line);border-radius:10px;margin:0 0 18px;overflow:hidden}
|
|
155
|
+
.cap{display:flex;gap:14px;align-items:baseline;padding:14px 18px}
|
|
156
|
+
.n{flex:none;font:700 14px/1 ui-monospace,Consolas,monospace;color:var(--rec);min-width:2.2em}
|
|
157
|
+
.t{margin-left:auto;font:12px/1 ui-monospace,Consolas,monospace;color:var(--dim)}
|
|
158
|
+
li img{display:block;width:100%;height:auto;border-top:1px solid var(--line)}
|
|
159
|
+
.note{color:var(--dim);font-style:italic;margin:0 0 18px;padding-left:18px;border-left:3px solid var(--line)}
|
|
160
|
+
footer{color:var(--dim);font-size:13px;margin-top:40px;border-top:1px solid var(--line);padding-top:16px}`;
|
|
161
|
+
export function buildGuideHtml(g, imageSrc) {
|
|
162
|
+
const body = [];
|
|
163
|
+
let section;
|
|
164
|
+
let open = false;
|
|
165
|
+
const close = () => {
|
|
166
|
+
if (open)
|
|
167
|
+
body.push("</ol>");
|
|
168
|
+
open = false;
|
|
169
|
+
};
|
|
170
|
+
for (const s of g.steps) {
|
|
171
|
+
if (s.section !== undefined && s.section !== section) {
|
|
172
|
+
close();
|
|
173
|
+
section = s.section;
|
|
174
|
+
body.push(`<h2>${html(section)}</h2>`);
|
|
175
|
+
}
|
|
176
|
+
if (s.n === 0) {
|
|
177
|
+
close();
|
|
178
|
+
body.push(`<p class="note">${html(s.text)}</p>`);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (!open)
|
|
182
|
+
body.push("<ol>");
|
|
183
|
+
open = true;
|
|
184
|
+
const text = s.label ? `${html(s.text)} <strong>${html(s.label)}</strong>` : html(s.text);
|
|
185
|
+
body.push(`<li><div class="cap"><span class="n">${String(s.n).padStart(2, "0")}</span><span>${text}</span>` +
|
|
186
|
+
`<span class="t">${formatTimecode(s.t)}</span></div>` +
|
|
187
|
+
(s.image ? `<img src="${html(imageSrc(s.image))}" alt="Step ${s.n}: ${html(caption(s))}" loading="lazy">` : "") +
|
|
188
|
+
"</li>");
|
|
189
|
+
}
|
|
190
|
+
close();
|
|
191
|
+
if (g.steps.length === 0)
|
|
192
|
+
body.push(`<p class="note">${html(g.stepsNote ?? "No steps in the recording.")}</p>`);
|
|
193
|
+
if (g.stepsOmitted)
|
|
194
|
+
body.push(`<p class="note">${g.stepsOmitted} more steps not shown.</p>`);
|
|
195
|
+
return [
|
|
196
|
+
"<!doctype html>",
|
|
197
|
+
'<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">',
|
|
198
|
+
`<title>${html(g.title)}</title><style>${STYLE}</style></head><body><main>`,
|
|
199
|
+
`<header><div class="rec">Step guide</div><h1>${html(g.title)}</h1><p class="meta">${html(intro(g))}</p></header>`,
|
|
200
|
+
...body,
|
|
201
|
+
`<footer>${html(footer(g))}<br>Generated by screencast-mcp step_guide, ${html(g.createdAt)}.</footer>`,
|
|
202
|
+
"</main></body></html>",
|
|
203
|
+
"",
|
|
204
|
+
].join("\n");
|
|
205
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const DOUBLE_CLICK_SEC = 0.5;
|
|
2
|
+
const DOUBLE_CLICK_PX = 6;
|
|
3
|
+
const SCROLL_JOIN_SEC = 1;
|
|
4
|
+
const r3 = (n) => Math.round(n * 1000) / 1000;
|
|
5
|
+
const GAP_WHY = {
|
|
6
|
+
input_not_seen: "input went to an elevated window or the lock screen, or the hook was removed",
|
|
7
|
+
helper_stalled: "the event logger paused",
|
|
8
|
+
helper_stopped: "the event logger stopped",
|
|
9
|
+
};
|
|
10
|
+
function clickText(button, double, e) {
|
|
11
|
+
const verb = double ? "double-click" : "click";
|
|
12
|
+
const which = button && button !== "left" ? `${button.charAt(0).toUpperCase()}${button.slice(1)} ${verb}` : `${verb.charAt(0).toUpperCase()}${verb.slice(1)}`;
|
|
13
|
+
return e.inFrame ? `${which} at (${e.x}, ${e.y})` : `${which} outside the recorded area`;
|
|
14
|
+
}
|
|
15
|
+
export function inputSteps(events) {
|
|
16
|
+
const steps = [];
|
|
17
|
+
const sorted = [...events].sort((a, b) => a.t - b.t);
|
|
18
|
+
let lastDown = null;
|
|
19
|
+
let scroll = null;
|
|
20
|
+
const scrollText = (axis, notches) => {
|
|
21
|
+
const dir = axis === "vertical" ? (notches >= 0 ? "up" : "down") : notches >= 0 ? "right" : "left";
|
|
22
|
+
const n = Math.abs(notches);
|
|
23
|
+
return `Scroll ${dir} ${n} notch${n === 1 ? "" : "es"}`;
|
|
24
|
+
};
|
|
25
|
+
for (const e of sorted) {
|
|
26
|
+
if (e.type === "move" || e.type === "up")
|
|
27
|
+
continue;
|
|
28
|
+
if (e.type !== "wheel")
|
|
29
|
+
scroll = null;
|
|
30
|
+
if (e.type === "down") {
|
|
31
|
+
const prev = lastDown;
|
|
32
|
+
if (prev &&
|
|
33
|
+
prev.e.button === e.button &&
|
|
34
|
+
e.t - prev.e.t <= DOUBLE_CLICK_SEC &&
|
|
35
|
+
Math.abs(e.x - prev.e.x) <= DOUBLE_CLICK_PX &&
|
|
36
|
+
Math.abs(e.y - prev.e.y) <= DOUBLE_CLICK_PX &&
|
|
37
|
+
prev.step.action === "click" &&
|
|
38
|
+
steps.at(-1) === prev.step) {
|
|
39
|
+
prev.step.action = "double_click";
|
|
40
|
+
prev.step.text = clickText(e.button, true, prev.e);
|
|
41
|
+
lastDown = null;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const step = {
|
|
45
|
+
t: e.t,
|
|
46
|
+
action: "click",
|
|
47
|
+
text: clickText(e.button, false, e),
|
|
48
|
+
x: e.x,
|
|
49
|
+
y: e.y,
|
|
50
|
+
button: e.button ?? "left",
|
|
51
|
+
inFrame: e.inFrame,
|
|
52
|
+
};
|
|
53
|
+
steps.push(step);
|
|
54
|
+
lastDown = { e, step };
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
lastDown = null;
|
|
58
|
+
if (e.type === "wheel") {
|
|
59
|
+
const axis = e.axis ?? "vertical";
|
|
60
|
+
const delta = e.delta ?? 0;
|
|
61
|
+
if (scroll && scroll.axis === axis && e.t - scroll.last <= SCROLL_JOIN_SEC && Math.sign(delta) === Math.sign(scroll.notches)) {
|
|
62
|
+
scroll.notches += delta;
|
|
63
|
+
scroll.last = e.t;
|
|
64
|
+
scroll.step.text = scrollText(axis, scroll.notches);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const step = { t: e.t, action: "scroll", text: scrollText(axis, delta), x: e.x, y: e.y, inFrame: e.inFrame };
|
|
68
|
+
steps.push(step);
|
|
69
|
+
scroll = { step, axis, notches: delta, last: e.t };
|
|
70
|
+
}
|
|
71
|
+
else if (e.type === "key") {
|
|
72
|
+
steps.push({ t: e.t, action: "shortcut", text: `Press ${e.keys ?? "a shortcut"}`, ...(e.keys ? { keys: e.keys } : {}) });
|
|
73
|
+
}
|
|
74
|
+
else if (e.type === "typing") {
|
|
75
|
+
const d = e.durationSec ?? 0;
|
|
76
|
+
steps.push({ t: e.t, action: "typing", text: `Type${d > 0 ? ` for ${r3(d)} s` : ""} (keys are not logged)`, durationSec: d });
|
|
77
|
+
}
|
|
78
|
+
else if (e.type === "gap") {
|
|
79
|
+
const why = GAP_WHY[e.reason ?? "input_not_seen"];
|
|
80
|
+
const d = r3(e.durationSec ?? 0);
|
|
81
|
+
steps.push({ t: e.t, action: "gap", text: `Input may be missing for ${d} s (${why})`, durationSec: d });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return steps;
|
|
85
|
+
}
|
|
86
|
+
export function reconstructSteps(events) {
|
|
87
|
+
return inputSteps(events).map(({ button: _b, inFrame: _i, keys: _k, durationSec: _d, ...step }) => step);
|
|
88
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const r3 = (v) => Math.round(v * 1000) / 1000;
|
|
2
|
+
export function cutShift(t, spans) {
|
|
3
|
+
let removed = 0;
|
|
4
|
+
for (const s of spans) {
|
|
5
|
+
if (t <= s.start)
|
|
6
|
+
break;
|
|
7
|
+
removed += Math.min(t, s.end) - s.start;
|
|
8
|
+
}
|
|
9
|
+
return removed;
|
|
10
|
+
}
|
|
11
|
+
export function mapTime(t, ops) {
|
|
12
|
+
let v = t;
|
|
13
|
+
for (const op of ops) {
|
|
14
|
+
if (op.op === "trim") {
|
|
15
|
+
if (v < op.start || v >= op.end)
|
|
16
|
+
return null;
|
|
17
|
+
v -= op.start;
|
|
18
|
+
}
|
|
19
|
+
else if (op.op === "speed")
|
|
20
|
+
v /= op.factor;
|
|
21
|
+
else
|
|
22
|
+
v -= cutShift(v, op.spans);
|
|
23
|
+
}
|
|
24
|
+
return v;
|
|
25
|
+
}
|
|
26
|
+
export function mapWindow(from, to, ops) {
|
|
27
|
+
let a = from;
|
|
28
|
+
let b = to;
|
|
29
|
+
for (const op of ops) {
|
|
30
|
+
if (op.op === "trim") {
|
|
31
|
+
a = Math.max(a, op.start) - op.start;
|
|
32
|
+
b = Math.min(b, op.end) - op.start;
|
|
33
|
+
}
|
|
34
|
+
else if (op.op === "speed") {
|
|
35
|
+
a /= op.factor;
|
|
36
|
+
b /= op.factor;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
a -= cutShift(a, op.spans);
|
|
40
|
+
b -= cutShift(b, op.spans);
|
|
41
|
+
}
|
|
42
|
+
if (b <= a)
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return [a, b];
|
|
46
|
+
}
|
|
47
|
+
export function mapSpans(spans, ops) {
|
|
48
|
+
return spans.flatMap((s) => {
|
|
49
|
+
const w = mapWindow(s.start, s.end, ops);
|
|
50
|
+
return w ? [{ start: r3(w[0]), end: r3(w[1]) }] : [];
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export function retimeCues(cues, ops) {
|
|
54
|
+
return cues.flatMap((c) => {
|
|
55
|
+
const w = mapWindow(c.start, c.end, ops);
|
|
56
|
+
return w && w[1] - w[0] >= 0.05 ? [{ ...c, start: r3(w[0]), end: r3(w[1]) }] : [];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const ASS_TIME = /^(\d+):(\d{2}):(\d{2})\.(\d{2})$/;
|
|
60
|
+
const assSec = (s) => {
|
|
61
|
+
const m = s.trim().match(ASS_TIME);
|
|
62
|
+
return m ? Number(m[1]) * 3600 + Number(m[2]) * 60 + Number(m[3]) + Number(m[4]) / 100 : null;
|
|
63
|
+
};
|
|
64
|
+
const assTime = (sec) => {
|
|
65
|
+
const cs = Math.round(sec * 100);
|
|
66
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
67
|
+
return `${Math.floor(cs / 360_000)}:${pad(Math.floor((cs % 360_000) / 6000))}:${pad(Math.floor((cs % 6000) / 100))}.${pad(cs % 100)}`;
|
|
68
|
+
};
|
|
69
|
+
export function retimeAss(text, ops) {
|
|
70
|
+
return text
|
|
71
|
+
.split(/\r?\n/)
|
|
72
|
+
.flatMap((line) => {
|
|
73
|
+
const m = line.match(/^(Dialogue:\s*[^,]*,)([^,]*),([^,]*),(.*)$/);
|
|
74
|
+
if (!m)
|
|
75
|
+
return [line];
|
|
76
|
+
const [, head, s, e, rest] = m;
|
|
77
|
+
const a = assSec(s);
|
|
78
|
+
const b = assSec(e);
|
|
79
|
+
if (a === null || b === null)
|
|
80
|
+
return [line];
|
|
81
|
+
const w = mapWindow(a, b, ops);
|
|
82
|
+
return w && w[1] - w[0] >= 0.05 ? [`${head}${assTime(w[0])},${assTime(w[1])},${rest}`] : [];
|
|
83
|
+
})
|
|
84
|
+
.join("\n");
|
|
85
|
+
}
|
package/dist/utils/toolsets.js
CHANGED
|
@@ -3,9 +3,11 @@ export const TOOLSETS = {
|
|
|
3
3
|
capture: [
|
|
4
4
|
"start_recording",
|
|
5
5
|
"stop_recording",
|
|
6
|
+
"save_replay",
|
|
6
7
|
"list_sessions",
|
|
7
8
|
"get_session",
|
|
8
9
|
"read_events",
|
|
10
|
+
"add_marker",
|
|
9
11
|
"screenshot",
|
|
10
12
|
"list_targets",
|
|
11
13
|
"list_audio_devices",
|
|
@@ -16,6 +18,8 @@ export const TOOLSETS = {
|
|
|
16
18
|
"screen_diff",
|
|
17
19
|
"wait_for_change",
|
|
18
20
|
"find_text",
|
|
21
|
+
"index_recording",
|
|
22
|
+
"search_recording",
|
|
19
23
|
"review_recording",
|
|
20
24
|
"player_frames",
|
|
21
25
|
],
|
|
@@ -32,9 +36,12 @@ export const TOOLSETS = {
|
|
|
32
36
|
"compress",
|
|
33
37
|
"redact_region",
|
|
34
38
|
"cut_idle",
|
|
39
|
+
"cut_by_transcript",
|
|
35
40
|
],
|
|
36
41
|
produce: [
|
|
37
42
|
"callout",
|
|
43
|
+
"keystroke_overlay",
|
|
44
|
+
"backdrop",
|
|
38
45
|
"overlay",
|
|
39
46
|
"zoom",
|
|
40
47
|
"reframe",
|
|
@@ -43,6 +50,9 @@ export const TOOLSETS = {
|
|
|
43
50
|
"assemble_highlights",
|
|
44
51
|
"export_preset",
|
|
45
52
|
"burn_subtitles",
|
|
53
|
+
"chapters",
|
|
54
|
+
"bug_report",
|
|
55
|
+
"step_guide",
|
|
46
56
|
],
|
|
47
57
|
audio: ["extract_audio", "normalize_audio", "denoise", "transcribe", "music_bed"],
|
|
48
58
|
};
|
|
@@ -75,22 +85,38 @@ export function serverInstructions(selection) {
|
|
|
75
85
|
];
|
|
76
86
|
if (on.has("capture")) {
|
|
77
87
|
lines.push("Capture: screenshot for a still; start_recording -> (do the task) -> stop_recording for video " +
|
|
78
|
-
"(events: true also logs clicks for read_events and zoom).
|
|
88
|
+
"(events: true also logs clicks for read_events and zoom). For flaky failures, start_recording " +
|
|
89
|
+
"{ replayBufferSec } keeps a rolling buffer and save_replay writes the last seconds after the fact. " +
|
|
90
|
+
"Never start a recording the user did not ask for.");
|
|
79
91
|
}
|
|
80
92
|
if (on.has("watch")) {
|
|
81
93
|
lines.push("Look: contact_sheet is the cheapest overview, sample_frames (mode scenes) for detail, find_text for OCR " +
|
|
82
|
-
"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.");
|
|
83
96
|
}
|
|
84
97
|
if (on.has("edit")) {
|
|
85
|
-
lines.push("Edit: prefer one pipeline call (trim, crop, scale, speed, redact, callout, reframe, zoom,
|
|
86
|
-
"export_preset or export_gif) over chaining single-edit tools; each tool call re-encodes.
|
|
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 " +
|
|
87
101
|
"segment, clip = several files; export_gif for size-bounded GIF/WebP, compress for a smaller mp4.");
|
|
88
102
|
}
|
|
89
103
|
if (on.has("produce")) {
|
|
90
|
-
lines.push("Produce: callout, zoom, overlay, title_card, xfade_transition, assemble_highlights, burn_subtitles, export_preset.");
|
|
104
|
+
lines.push("Produce: callout, zoom, keystroke_overlay, backdrop, overlay, title_card, xfade_transition, assemble_highlights, burn_subtitles, export_preset.");
|
|
105
|
+
}
|
|
106
|
+
if (on.has("produce")) {
|
|
107
|
+
lines.push("Bug reports: bug_report turns a recording (path or sessionId) into one redacted folder: clip, GIF, " +
|
|
108
|
+
"contact sheet, steps from the event log, OCR'd error text, environment, and report.md.");
|
|
109
|
+
}
|
|
110
|
+
if (on.has("capture") || on.has("produce")) {
|
|
111
|
+
const marks = [
|
|
112
|
+
on.has("capture") && "add_marker stamps a labelled moment during a recording (or at a second of a file).",
|
|
113
|
+
on.has("produce") && "chapters writes markers, scene changes, or a transcript as mp4/mkv chapters plus YouTube text.",
|
|
114
|
+
on.has("edit") && "pipeline chapters: true keeps markers as chapters through trims and speed.",
|
|
115
|
+
];
|
|
116
|
+
lines.push(`Markers: ${marks.filter(Boolean).join(" ")}`);
|
|
91
117
|
}
|
|
92
118
|
if (on.has("audio")) {
|
|
93
|
-
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).");
|
|
94
120
|
}
|
|
95
121
|
lines.push("Outputs go under SCREENCAST_HOME unless a call names a path; times are seconds and positions video pixels. " +
|
|
96
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