@phil65/demoreel 0.3.1 → 0.5.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 +47 -12
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/args.js +26 -0
- package/dist/cli.js +53 -3
- package/dist/compose.d.ts +4 -0
- package/dist/compose.js +4 -0
- package/dist/gif.d.ts +16 -0
- package/dist/gif.js +19 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -2
- package/dist/mcp.d.ts +5 -0
- package/dist/mcp.js +441 -0
- package/dist/openscreen/project.js +3 -3
- package/dist/project.d.ts +51 -1
- package/dist/project.js +89 -1
- package/dist/record.d.ts +6 -1
- package/dist/record.js +2 -1
- package/dist/renderer/assets/CanvasPool-PBu3bHFZ.js +1 -0
- package/dist/renderer/assets/CanvasRenderer-HmF-4gyW.js +1 -0
- package/dist/renderer/assets/RenderTargetSystem-Dk1U4wDJ.js +184 -0
- package/dist/renderer/assets/WebGLRenderer-C0v9HBel.js +149 -0
- package/dist/renderer/assets/WebGPURenderer-Ce0-U9Q1.js +95 -0
- package/dist/renderer/assets/{browserAll-aHn2isHo.js → browserAll-DhvWQ7nM.js} +2 -2
- package/dist/renderer/assets/canvasUtils-KRroregW.js +1 -0
- package/dist/renderer/assets/{getTexelRangeRects-yD6MQ0xy.js → getTexelRangeRects-D3pwCyRt.js} +3 -3
- package/dist/renderer/assets/index-CE-lli1m.js +556 -0
- package/dist/renderer/assets/init-DfmWKarH.js +83 -0
- package/dist/renderer/assets/webworkerAll-B41hok0-.js +1 -0
- package/dist/renderer/index.html +1 -6
- package/dist/scene.d.ts +24 -4
- package/dist/scene.js +74 -5
- package/dist/sheet.d.ts +6 -0
- package/dist/sheet.js +10 -0
- package/dist/types.d.ts +4 -0
- package/package.json +7 -1
- package/skills/demoreel/SKILL.md +161 -0
- package/dist/renderer/assets/CanvasPool-CHSHS1-v.js +0 -23
- package/dist/renderer/assets/RenderTargetSystem-EAUH9iQk.js +0 -404
- package/dist/renderer/assets/canvasUtils-n5g2f3_X.js +0 -1
- package/dist/renderer/assets/getTextureBatchBindGroup-Bwvgbco6.js +0 -1
- package/dist/renderer/assets/index-BwP6rH7I.js +0 -556
- package/dist/renderer/assets/init-C2Za5NQh.js +0 -83
- package/dist/renderer/assets/webworkerAll-JSSmbaR2.js +0 -1
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official MCP server for demoreel (`demoreel mcp`, stdio transport).
|
|
3
|
+
*
|
|
4
|
+
* Exposes the full inspect -> dry-run -> record/render -> contact-sheet -> frame-check -> rezoom -> gif
|
|
5
|
+
* loop with inline PNG images and live `notifications/progress` updates during renders.
|
|
6
|
+
*/
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
11
|
+
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { parseSize } from "./args.js";
|
|
14
|
+
import { readTimeline, rezoom } from "./compose.js";
|
|
15
|
+
import { checkFfmpeg, detectGpu, launchChromium } from "./env.js";
|
|
16
|
+
import { exportGif } from "./gif.js";
|
|
17
|
+
import { loadScenario } from "./load.js";
|
|
18
|
+
import { dryRunScenario, recordScenario, resolveStorageState } from "./record.js";
|
|
19
|
+
import { renderProject, validateProject } from "./render.js";
|
|
20
|
+
import { extractFrame, findFramesheet, reviewSheet } from "./sheet.js";
|
|
21
|
+
function pngBlock(filePath) {
|
|
22
|
+
if (!fs.existsSync(filePath))
|
|
23
|
+
return null;
|
|
24
|
+
return { type: "image", data: fs.readFileSync(filePath).toString("base64"), mimeType: "image/png" };
|
|
25
|
+
}
|
|
26
|
+
function resolveVideoTarget(targetPath) {
|
|
27
|
+
const p = path.resolve(targetPath);
|
|
28
|
+
if (fs.existsSync(p) && fs.statSync(p).isDirectory()) {
|
|
29
|
+
const tl = readTimeline(p);
|
|
30
|
+
return {
|
|
31
|
+
videoPath: path.join(p, tl.files?.video ?? `${tl.scenario}.mp4`),
|
|
32
|
+
marksPath: path.join(p, tl.files?.marks ?? "marks.json"),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return { videoPath: p, marksPath: path.join(path.dirname(p), "marks.json") };
|
|
36
|
+
}
|
|
37
|
+
function readPackageVersion() {
|
|
38
|
+
try {
|
|
39
|
+
const pkg = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
40
|
+
return pkg.version ?? "0.0.0";
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return "0.0.0";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function makeProgressNotifier(ctx) {
|
|
47
|
+
const token = ctx.mcpReq?._meta?.progressToken;
|
|
48
|
+
const notify = ctx.mcpReq?.notify;
|
|
49
|
+
let lastSent = -1;
|
|
50
|
+
return (progress, message) => {
|
|
51
|
+
if (token === undefined || !notify)
|
|
52
|
+
return;
|
|
53
|
+
const pct = Math.min(100, Math.max(0, Math.round(progress)));
|
|
54
|
+
if (pct === lastSent && !message)
|
|
55
|
+
return;
|
|
56
|
+
lastSent = pct;
|
|
57
|
+
void notify({
|
|
58
|
+
method: "notifications/progress",
|
|
59
|
+
params: { progressToken: token, progress: pct, total: 100, ...(message ? { message } : {}) },
|
|
60
|
+
}).catch(() => { });
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const logStderr = (msg) => console.error(msg);
|
|
64
|
+
/** Creates a configured demoreel `McpServer` instance (connect to stdio or any MCP transport). */
|
|
65
|
+
export function createMcpServer() {
|
|
66
|
+
const server = new McpServer({ name: "demoreel", version: readPackageVersion() }, {
|
|
67
|
+
instructions: "demoreel records scripted Playwright product demos with smooth cursor motion, auto-zoom, captions, keycap HUDs, and OpenScreen MP4/GIF rendering. Follow the loop: inspect_page -> write scenario -> dry_run_scenario -> run_scenario -> inspect contact sheet (and inspect_frame for dense UI) -> rezoom or refine.",
|
|
68
|
+
});
|
|
69
|
+
server.registerTool("doctor", {
|
|
70
|
+
title: "Check demoreel environment",
|
|
71
|
+
description: "Checks Chromium, ffmpeg, hardware GPU acceleration, and framesheet availability.",
|
|
72
|
+
inputSchema: z.object({}),
|
|
73
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
74
|
+
}, async () => {
|
|
75
|
+
let chromium = "missing";
|
|
76
|
+
try {
|
|
77
|
+
const b = await launchChromium();
|
|
78
|
+
chromium = b.version();
|
|
79
|
+
await b.close();
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
chromium = `error: ${e.message.split("\n")[0]}`;
|
|
83
|
+
}
|
|
84
|
+
let ffmpeg = "ok";
|
|
85
|
+
try {
|
|
86
|
+
checkFfmpeg();
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
ffmpeg = `error: ${e.message.split("\n")[0]}`;
|
|
90
|
+
}
|
|
91
|
+
const gpu = await detectGpu();
|
|
92
|
+
const fsCmd = findFramesheet();
|
|
93
|
+
const info = {
|
|
94
|
+
version: readPackageVersion(),
|
|
95
|
+
node: process.version,
|
|
96
|
+
platform: process.platform,
|
|
97
|
+
chromium,
|
|
98
|
+
ffmpeg,
|
|
99
|
+
gpu,
|
|
100
|
+
framesheet: fsCmd ? `${fsCmd.cmd} ${fsCmd.args.join(" ")}`.trim() : null,
|
|
101
|
+
};
|
|
102
|
+
return { content: [{ type: "text", text: JSON.stringify(info, null, 2) }] };
|
|
103
|
+
});
|
|
104
|
+
server.registerTool("inspect_page", {
|
|
105
|
+
title: "Inspect a URL or scenario end state",
|
|
106
|
+
description: "Returns the ARIA accessibility snapshot (YAML tree) and an optional inline PNG screenshot of a URL, or dry-runs a scenario file and inspects its end/failure state.",
|
|
107
|
+
inputSchema: z.object({
|
|
108
|
+
target: z.string().describe("HTTP(S) URL or path to a *.scenario.ts/.mts/.mjs file."),
|
|
109
|
+
screenshot: z.boolean().optional().default(true).describe("Return an inline PNG screenshot (default true)."),
|
|
110
|
+
viewport: z.string().optional().describe("Optional WxH viewport override, e.g. '1280x800'."),
|
|
111
|
+
state: z.string().optional().describe("Optional Playwright storageState JSON file path."),
|
|
112
|
+
}),
|
|
113
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
114
|
+
}, async ({ target, screenshot, viewport, state }) => {
|
|
115
|
+
const isUrl = /^https?:\/\//i.test(target);
|
|
116
|
+
let aria = "";
|
|
117
|
+
let summary = "";
|
|
118
|
+
const tmpPng = screenshot ? path.join(os.tmpdir(), `demoreel-inspect-${Date.now()}.png`) : null;
|
|
119
|
+
try {
|
|
120
|
+
if (isUrl) {
|
|
121
|
+
const vp = viewport ? parseSize(viewport) : { width: 1280, height: 800 };
|
|
122
|
+
const storageState = resolveStorageState(state);
|
|
123
|
+
const browser = await launchChromium();
|
|
124
|
+
try {
|
|
125
|
+
const ctx = await browser.newContext({ viewport: vp, ...(storageState ? { storageState } : {}) });
|
|
126
|
+
const page = await ctx.newPage();
|
|
127
|
+
await page.goto(target, { waitUntil: "load" });
|
|
128
|
+
aria = await page.locator("body").ariaSnapshot();
|
|
129
|
+
if (tmpPng)
|
|
130
|
+
await page.screenshot({ path: tmpPng });
|
|
131
|
+
summary = `Inspected URL ${target} (${vp.width}x${vp.height})`;
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
await browser.close().catch(() => { });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const file = path.resolve(target);
|
|
139
|
+
const scenario = await loadScenario(file);
|
|
140
|
+
const overrides = {};
|
|
141
|
+
if (viewport)
|
|
142
|
+
overrides.viewport = parseSize(viewport);
|
|
143
|
+
const res = await dryRunScenario(scenario, {
|
|
144
|
+
scenarioFile: file,
|
|
145
|
+
overrides,
|
|
146
|
+
storageState: state,
|
|
147
|
+
atEnd: async (page) => {
|
|
148
|
+
aria = await page.locator("body").ariaSnapshot();
|
|
149
|
+
if (tmpPng)
|
|
150
|
+
await page.screenshot({ path: tmpPng });
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
summary = res.ok
|
|
154
|
+
? `Dry-run "${scenario.name}": ${res.actions.length} actions ok (${(res.durationMs / 1000).toFixed(1)}s)`
|
|
155
|
+
: `Dry-run "${scenario.name}" FAILED at action #${res.error?.actionIndex}: ${res.error?.message}`;
|
|
156
|
+
}
|
|
157
|
+
const content = [{ type: "text", text: `${summary}\n\n${aria}` }];
|
|
158
|
+
if (tmpPng) {
|
|
159
|
+
const img = pngBlock(tmpPng);
|
|
160
|
+
if (img)
|
|
161
|
+
content.push(img);
|
|
162
|
+
}
|
|
163
|
+
return { content };
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
if (tmpPng && fs.existsSync(tmpPng))
|
|
167
|
+
fs.rmSync(tmpPng, { force: true });
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
server.registerTool("dry_run_scenario", {
|
|
171
|
+
title: "Dry-run a scenario",
|
|
172
|
+
description: "Runs a scenario in fast mode (no sleeps, no ffmpeg, no output files) to verify every selector and action in seconds. On failure, includes the ARIA snapshot and failure screenshot.",
|
|
173
|
+
inputSchema: z.object({
|
|
174
|
+
scenarioPath: z.string().describe("Path to the scenario file (*.scenario.ts/.mts/.mjs)."),
|
|
175
|
+
viewport: z.string().optional().describe("Optional WxH viewport override."),
|
|
176
|
+
state: z.string().optional().describe("Optional Playwright storageState JSON file path."),
|
|
177
|
+
}),
|
|
178
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
179
|
+
}, async ({ scenarioPath, viewport, state }) => {
|
|
180
|
+
const file = path.resolve(scenarioPath);
|
|
181
|
+
const scenario = await loadScenario(file);
|
|
182
|
+
const overrides = {};
|
|
183
|
+
if (viewport)
|
|
184
|
+
overrides.viewport = parseSize(viewport);
|
|
185
|
+
let failureAria = "";
|
|
186
|
+
const tmpPng = path.join(os.tmpdir(), `demoreel-fail-${Date.now()}.png`);
|
|
187
|
+
try {
|
|
188
|
+
const res = await dryRunScenario(scenario, {
|
|
189
|
+
scenarioFile: file,
|
|
190
|
+
overrides,
|
|
191
|
+
storageState: state,
|
|
192
|
+
onFailure: async (_err, page) => {
|
|
193
|
+
failureAria = await page.locator("body").ariaSnapshot().catch(() => "");
|
|
194
|
+
await page.screenshot({ path: tmpPng }).catch(() => { });
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
const lines = res.actions.map((a, i) => `${i}: ok ${a.kind}${a.label ? ` ${a.label}` : ""}`);
|
|
198
|
+
if (!res.ok && res.error) {
|
|
199
|
+
lines.push(`FAIL action #${res.error.actionIndex}: ${res.error.message}`);
|
|
200
|
+
if (failureAria)
|
|
201
|
+
lines.push("", "ARIA at failure:", failureAria);
|
|
202
|
+
const content = [{ type: "text", text: lines.join("\n") }];
|
|
203
|
+
const img = pngBlock(tmpPng);
|
|
204
|
+
if (img)
|
|
205
|
+
content.push(img);
|
|
206
|
+
return { isError: true, content };
|
|
207
|
+
}
|
|
208
|
+
lines.push(`dry-run "${scenario.name}": ${res.actions.length} actions ok (${(res.durationMs / 1000).toFixed(1)}s)`);
|
|
209
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
if (fs.existsSync(tmpPng))
|
|
213
|
+
fs.rmSync(tmpPng, { force: true });
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
server.registerTool("run_scenario", {
|
|
217
|
+
title: "Record and render a demo video",
|
|
218
|
+
description: "Records a scenario, writes the OpenScreen project + timeline.json + marks.json, renders the MP4 (and optional GIF), builds the contact sheet, and returns the sheet PNG inline.",
|
|
219
|
+
inputSchema: z.object({
|
|
220
|
+
scenarioPath: z.string().describe("Path to the scenario file (*.scenario.ts/.mts/.mjs)."),
|
|
221
|
+
outDir: z.string().optional().describe("Output directory (default: out/<name>)."),
|
|
222
|
+
quality: z.enum(["medium", "good", "source"]).optional().default("good").describe("medium (720p), good (1080p, default), or source."),
|
|
223
|
+
fps: z.number().int().min(10).max(60).optional().default(30).describe("Output frame rate (default 30)."),
|
|
224
|
+
speed: z.number().positive().optional().describe("Optional pacing speed multiplier."),
|
|
225
|
+
viewport: z.string().optional().describe("Optional WxH viewport override, e.g. '1280x720'."),
|
|
226
|
+
trimIdle: z.boolean().optional().describe("Cut idle stretches with OpenScreen trim regions."),
|
|
227
|
+
gif: z.boolean().optional().default(false).describe("Also export a palette-optimised GIF next to the MP4."),
|
|
228
|
+
frames: z.number().int().min(4).max(32).optional().default(12).describe("Number of contact-sheet tiles (default 12)."),
|
|
229
|
+
state: z.string().optional().describe("Optional Playwright storageState JSON file path."),
|
|
230
|
+
render: z.boolean().optional().default(true).describe("Render MP4 after recording (default true)."),
|
|
231
|
+
}),
|
|
232
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
233
|
+
}, async (args, ctx) => {
|
|
234
|
+
const progress = makeProgressNotifier(ctx);
|
|
235
|
+
const file = path.resolve(args.scenarioPath);
|
|
236
|
+
const scenario = await loadScenario(file);
|
|
237
|
+
const overrides = {};
|
|
238
|
+
if (args.viewport)
|
|
239
|
+
overrides.viewport = parseSize(args.viewport);
|
|
240
|
+
if (args.speed !== undefined)
|
|
241
|
+
overrides.pacing = { ...scenario.pacing, speed: args.speed };
|
|
242
|
+
if (args.trimIdle !== undefined)
|
|
243
|
+
overrides.trimIdle = args.trimIdle && (scenario.trimIdle || true);
|
|
244
|
+
const outDir = path.resolve(args.outDir ?? path.join("out", scenario.name));
|
|
245
|
+
progress(5, `Recording "${scenario.name}"...`);
|
|
246
|
+
const rec = await recordScenario(scenario, {
|
|
247
|
+
outDir,
|
|
248
|
+
scenarioFile: file,
|
|
249
|
+
overrides,
|
|
250
|
+
storageState: args.state,
|
|
251
|
+
log: logStderr,
|
|
252
|
+
});
|
|
253
|
+
const validation = await validateProject(rec.projectPath);
|
|
254
|
+
const summary = {
|
|
255
|
+
scenario: scenario.name,
|
|
256
|
+
outDir,
|
|
257
|
+
recordedDurationMs: rec.timeline.durationMs,
|
|
258
|
+
outputDurationMs: rec.timeline.outputDurationMs,
|
|
259
|
+
actions: rec.timeline.actions.length,
|
|
260
|
+
zoomRegions: rec.timeline.zoomRegions.length,
|
|
261
|
+
trimRegions: rec.timeline.trimRegions.length,
|
|
262
|
+
valid: validation.valid,
|
|
263
|
+
projectPath: rec.projectPath,
|
|
264
|
+
timelinePath: rec.timelinePath,
|
|
265
|
+
marksPath: rec.marksPath,
|
|
266
|
+
};
|
|
267
|
+
const content = [];
|
|
268
|
+
if (args.render) {
|
|
269
|
+
const mp4 = path.join(outDir, `${scenario.name}.mp4`);
|
|
270
|
+
const rendered = await renderProject({
|
|
271
|
+
projectPath: rec.projectPath,
|
|
272
|
+
outputPath: mp4,
|
|
273
|
+
frameRate: args.fps,
|
|
274
|
+
quality: args.quality,
|
|
275
|
+
cursor: scenario.cursor,
|
|
276
|
+
log: logStderr,
|
|
277
|
+
onProgress: (p) => progress(15 + p * 0.75, `Rendering ${Math.round(p)}%`),
|
|
278
|
+
});
|
|
279
|
+
summary.videoPath = rendered.outputPath;
|
|
280
|
+
summary.width = rendered.width;
|
|
281
|
+
summary.height = rendered.height;
|
|
282
|
+
summary.bytes = rendered.bytes;
|
|
283
|
+
summary.gpu = rendered.gpu;
|
|
284
|
+
summary.renderMs = rendered.renderMs;
|
|
285
|
+
if (args.gif) {
|
|
286
|
+
progress(92, "Exporting GIF...");
|
|
287
|
+
const g = await exportGif(mp4);
|
|
288
|
+
summary.gifPath = g.outputPath;
|
|
289
|
+
summary.gifBytes = g.bytes;
|
|
290
|
+
}
|
|
291
|
+
progress(96, "Building contact sheet...");
|
|
292
|
+
const sheet = await reviewSheet(mp4, {
|
|
293
|
+
outDir,
|
|
294
|
+
marks: rec.marksPath,
|
|
295
|
+
frames: args.frames,
|
|
296
|
+
log: logStderr,
|
|
297
|
+
});
|
|
298
|
+
summary.sheetPath = sheet.sheet;
|
|
299
|
+
summary.sheetTool = sheet.tool;
|
|
300
|
+
if (sheet.summary)
|
|
301
|
+
summary.framesheetSummary = sheet.summary;
|
|
302
|
+
content.push({ type: "text", text: JSON.stringify(summary, null, 2) });
|
|
303
|
+
const img = pngBlock(sheet.sheet);
|
|
304
|
+
if (img)
|
|
305
|
+
content.push(img);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
content.push({ type: "text", text: JSON.stringify(summary, null, 2) });
|
|
309
|
+
}
|
|
310
|
+
progress(100, "Done");
|
|
311
|
+
return { content };
|
|
312
|
+
});
|
|
313
|
+
server.registerTool("rezoom", {
|
|
314
|
+
title: "Tune zooms, idle trims, or keycap HUD without re-recording",
|
|
315
|
+
description: "Re-derives zoomRegions, trimRegions, and keycap annotations from timeline.json in an existing output directory, optionally re-renders the MP4, and returns the updated contact sheet PNG.",
|
|
316
|
+
inputSchema: z.object({
|
|
317
|
+
outDir: z.string().describe("Output directory containing timeline.json."),
|
|
318
|
+
maxDepth: z.number().int().min(1).max(6).optional().describe("Deepest automatic zoom tier (1=1.25x .. 6=5x)."),
|
|
319
|
+
leadMs: z.number().optional().describe("Zoom-in lead time before cursor arrives (ms)."),
|
|
320
|
+
holdMs: z.number().optional().describe("Hold zoom after action ends (ms)."),
|
|
321
|
+
autoZoom: z.boolean().optional().describe("Enable/disable automatic zooms (false = manual scene.zoom() only)."),
|
|
322
|
+
trimIdle: z.boolean().optional().describe("Enable/disable idle trimming."),
|
|
323
|
+
ignoreFrames: z.boolean().optional().describe("Ignore raw screencast frame bursts when trimming idle (useful for WebGL/rAF apps)."),
|
|
324
|
+
showKeys: z.boolean().optional().describe("Toggle floating keycap HUD for scene.press() shortcuts."),
|
|
325
|
+
render: z.boolean().optional().default(true).describe("Re-render the MP4 and contact sheet (default true)."),
|
|
326
|
+
quality: z.enum(["medium", "good", "source"]).optional().default("good"),
|
|
327
|
+
fps: z.number().int().min(10).max(60).optional().default(30),
|
|
328
|
+
frames: z.number().int().min(4).max(32).optional().default(12),
|
|
329
|
+
}),
|
|
330
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false },
|
|
331
|
+
}, async (args, ctx) => {
|
|
332
|
+
const progress = makeProgressNotifier(ctx);
|
|
333
|
+
const dir = path.resolve(args.outDir);
|
|
334
|
+
const zoom = {};
|
|
335
|
+
if (args.maxDepth !== undefined)
|
|
336
|
+
zoom.maxDepth = args.maxDepth;
|
|
337
|
+
if (args.leadMs !== undefined)
|
|
338
|
+
zoom.leadMs = args.leadMs;
|
|
339
|
+
if (args.holdMs !== undefined)
|
|
340
|
+
zoom.holdMs = args.holdMs;
|
|
341
|
+
if (args.autoZoom !== undefined)
|
|
342
|
+
zoom.auto = args.autoZoom;
|
|
343
|
+
const trimIdle = args.trimIdle === false
|
|
344
|
+
? false
|
|
345
|
+
: args.trimIdle || args.ignoreFrames !== undefined
|
|
346
|
+
? { ...(args.ignoreFrames !== undefined ? { ignoreFrames: args.ignoreFrames } : {}) }
|
|
347
|
+
: undefined;
|
|
348
|
+
const look = args.showKeys !== undefined ? { showKeys: args.showKeys } : undefined;
|
|
349
|
+
const res = rezoom(dir, { zoom, trimIdle, look });
|
|
350
|
+
const summary = {
|
|
351
|
+
scenario: res.timeline.scenario,
|
|
352
|
+
outputDurationMs: res.timeline.outputDurationMs,
|
|
353
|
+
zoomRegions: res.timeline.zoomRegions,
|
|
354
|
+
trimRegions: res.timeline.trimRegions,
|
|
355
|
+
speedRegions: res.timeline.speedRegions,
|
|
356
|
+
};
|
|
357
|
+
const content = [];
|
|
358
|
+
if (args.render) {
|
|
359
|
+
const rendered = await renderProject({
|
|
360
|
+
projectPath: res.projectPath,
|
|
361
|
+
frameRate: args.fps,
|
|
362
|
+
quality: args.quality,
|
|
363
|
+
cursor: res.timeline.options?.cursor,
|
|
364
|
+
log: logStderr,
|
|
365
|
+
onProgress: (p) => progress(p * 0.9, `Rendering ${Math.round(p)}%`),
|
|
366
|
+
});
|
|
367
|
+
summary.videoPath = rendered.outputPath;
|
|
368
|
+
summary.renderMs = rendered.renderMs;
|
|
369
|
+
const sheet = await reviewSheet(rendered.outputPath, {
|
|
370
|
+
outDir: dir,
|
|
371
|
+
marks: res.marksPath,
|
|
372
|
+
frames: args.frames,
|
|
373
|
+
log: logStderr,
|
|
374
|
+
});
|
|
375
|
+
summary.sheetPath = sheet.sheet;
|
|
376
|
+
if (sheet.summary)
|
|
377
|
+
summary.framesheetSummary = sheet.summary;
|
|
378
|
+
content.push({ type: "text", text: JSON.stringify(summary, null, 2) });
|
|
379
|
+
const img = pngBlock(sheet.sheet);
|
|
380
|
+
if (img)
|
|
381
|
+
content.push(img);
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
content.push({ type: "text", text: JSON.stringify(summary, null, 2) });
|
|
385
|
+
}
|
|
386
|
+
progress(100, "Done");
|
|
387
|
+
return { content };
|
|
388
|
+
});
|
|
389
|
+
server.registerTool("inspect_frame", {
|
|
390
|
+
title: "Extract a full-resolution frame at a timestamp",
|
|
391
|
+
description: "Extracts a single full-resolution PNG frame from a rendered MP4 (or demoreel output directory) at `seconds` and returns it inline — ideal for checking dense UI, small badges, or zoomed text that contact-sheet thumbnails shrink.",
|
|
392
|
+
inputSchema: z.object({
|
|
393
|
+
target: z.string().describe("Path to an MP4 file or a demoreel output directory."),
|
|
394
|
+
seconds: z.number().min(0).describe("Timestamp in seconds."),
|
|
395
|
+
outPath: z.string().optional().describe("Optional output PNG path."),
|
|
396
|
+
}),
|
|
397
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
398
|
+
}, async ({ target, seconds, outPath }) => {
|
|
399
|
+
const { videoPath } = resolveVideoTarget(target);
|
|
400
|
+
const tmp = outPath ? null : path.join(os.tmpdir(), `demoreel-frame-${Date.now()}.png`);
|
|
401
|
+
try {
|
|
402
|
+
const res = await extractFrame(videoPath, seconds, outPath ?? tmp ?? undefined);
|
|
403
|
+
const content = [
|
|
404
|
+
{
|
|
405
|
+
type: "text",
|
|
406
|
+
text: JSON.stringify({ videoPath, seconds: res.seconds, duration: res.duration, ...(outPath ? { outPath: res.outPng } : {}) }, null, 2),
|
|
407
|
+
},
|
|
408
|
+
];
|
|
409
|
+
const img = pngBlock(res.outPng);
|
|
410
|
+
if (img)
|
|
411
|
+
content.push(img);
|
|
412
|
+
return { content };
|
|
413
|
+
}
|
|
414
|
+
finally {
|
|
415
|
+
if (tmp && fs.existsSync(tmp))
|
|
416
|
+
fs.rmSync(tmp, { force: true });
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
server.registerTool("export_gif", {
|
|
420
|
+
title: "Export a palette-optimised GIF",
|
|
421
|
+
description: "Converts a rendered MP4 (or demoreel output directory) into a looping two-pass palette-optimised GIF suitable for READMEs and docs.",
|
|
422
|
+
inputSchema: z.object({
|
|
423
|
+
target: z.string().describe("Path to an MP4 file or a demoreel output directory."),
|
|
424
|
+
outPath: z.string().optional().describe("Optional output GIF path (default: next to the MP4)."),
|
|
425
|
+
width: z.number().int().min(0).max(1920).optional().default(960).describe("Output width in px (default 960; 0 = source)."),
|
|
426
|
+
fps: z.number().int().min(1).max(30).optional().default(12).describe("Output frame rate (default 12)."),
|
|
427
|
+
}),
|
|
428
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false },
|
|
429
|
+
}, async ({ target, outPath, width, fps }) => {
|
|
430
|
+
const { videoPath } = resolveVideoTarget(target);
|
|
431
|
+
const res = await exportGif(videoPath, outPath, { width, fps });
|
|
432
|
+
return { content: [{ type: "text", text: JSON.stringify(res, null, 2) }] };
|
|
433
|
+
});
|
|
434
|
+
return server;
|
|
435
|
+
}
|
|
436
|
+
/** Starts the demoreel MCP server over stdio. */
|
|
437
|
+
export async function runMcpServer() {
|
|
438
|
+
const server = createMcpServer();
|
|
439
|
+
const transport = new StdioServerTransport();
|
|
440
|
+
await server.connect(transport);
|
|
441
|
+
}
|
|
@@ -548,9 +548,9 @@ function getAspectRatioValue(aspectRatio) {
|
|
|
548
548
|
case "9:16": return 9 / 16;
|
|
549
549
|
case "1:1": return 1;
|
|
550
550
|
case "4:3": return 4 / 3;
|
|
551
|
-
case "4:5": return
|
|
552
|
-
case "16:10": return
|
|
553
|
-
case "10:16": return
|
|
551
|
+
case "4:5": return .8;
|
|
552
|
+
case "16:10": return 1.6;
|
|
553
|
+
case "10:16": return .625;
|
|
554
554
|
case "native": return NATIVE_ASPECT_RATIO_FALLBACK;
|
|
555
555
|
default: return aspectRatio;
|
|
556
556
|
}
|
package/dist/project.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import type { Caption, CursorSample, SpeedRegion, TrimRegion, ZoomRegion } from "./types.ts";
|
|
1
|
+
import type { ActionRecord, Caption, CursorSample, SpeedRegion, TrimRegion, ZoomRegion } from "./types.ts";
|
|
2
2
|
export declare const PROJECT_VERSION = 2;
|
|
3
3
|
export declare const CURSOR_TELEMETRY_VERSION = 2;
|
|
4
|
+
export type KeyHudPosition = "bottom-right" | "top-right" | "bottom-left" | "top-left";
|
|
5
|
+
export interface KeyHudOptions {
|
|
6
|
+
/** Corner where shortcut keycap badges appear (default "bottom-right"). */
|
|
7
|
+
position?: KeyHudPosition;
|
|
8
|
+
/** How long each keycap stays visible (ms, default 1100). */
|
|
9
|
+
durationMs?: number;
|
|
10
|
+
/** Font size in px (default 24). */
|
|
11
|
+
fontSize?: number;
|
|
12
|
+
}
|
|
4
13
|
export interface LookOptions {
|
|
5
14
|
/** Wallpaper: "#hex", CSS gradient, or one of OpenScreen's "/wallpapers/wallpaperN.jpg". */
|
|
6
15
|
wallpaper: string;
|
|
@@ -14,6 +23,8 @@ export interface LookOptions {
|
|
|
14
23
|
/** Where captions sit; "auto" (default) = bottom, unless that covers an active target. */
|
|
15
24
|
captionPosition: "auto" | "bottom" | "top";
|
|
16
25
|
captionFontSize: number;
|
|
26
|
+
/** Show floating keycap pills for `scene.press()` shortcuts (default false). */
|
|
27
|
+
showKeys?: boolean | KeyHudOptions;
|
|
17
28
|
}
|
|
18
29
|
export declare const DEFAULT_LOOK: LookOptions;
|
|
19
30
|
/** Caption box in percent of the output canvas (OpenScreen annotation position/size). */
|
|
@@ -23,6 +34,44 @@ export declare function captionRect(position: LookOptions["captionPosition"] | u
|
|
|
23
34
|
width: number;
|
|
24
35
|
height: number;
|
|
25
36
|
};
|
|
37
|
+
/** Formats a Playwright key chord (e.g. "Control+Shift+K") into a compact keycap label ("Ctrl + ⇧ + K"). */
|
|
38
|
+
export declare function formatKeycap(key: string): string;
|
|
39
|
+
/** Keycap HUD box in percent of the output canvas (sits clear of top/bottom captions). */
|
|
40
|
+
export declare function keycapRect(position?: KeyHudPosition, text?: string): {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
};
|
|
46
|
+
/** Builds OpenScreen text annotations for `scene.press()` actions when enabled globally or per-action. */
|
|
47
|
+
export declare function keycapAnnotations(actions: ActionRecord[], look?: LookOptions, startZIndex?: number): {
|
|
48
|
+
id: string;
|
|
49
|
+
startMs: number;
|
|
50
|
+
endMs: number;
|
|
51
|
+
type: string;
|
|
52
|
+
content: string;
|
|
53
|
+
textContent: string;
|
|
54
|
+
position: {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
};
|
|
58
|
+
size: {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
};
|
|
62
|
+
style: {
|
|
63
|
+
color: string;
|
|
64
|
+
backgroundColor: string;
|
|
65
|
+
fontSize: number;
|
|
66
|
+
fontFamily: string;
|
|
67
|
+
fontWeight: string;
|
|
68
|
+
fontStyle: string;
|
|
69
|
+
textDecoration: string;
|
|
70
|
+
textAlign: string;
|
|
71
|
+
textAnimation: string;
|
|
72
|
+
};
|
|
73
|
+
zIndex: number;
|
|
74
|
+
}[];
|
|
26
75
|
export declare function captionAnnotations(captions: Caption[], look?: LookOptions): {
|
|
27
76
|
id: string;
|
|
28
77
|
startMs: number;
|
|
@@ -55,6 +104,7 @@ export interface BuildProjectOptions {
|
|
|
55
104
|
videoPath: string;
|
|
56
105
|
zoomRegions: ZoomRegion[];
|
|
57
106
|
captions: Caption[];
|
|
107
|
+
actions?: ActionRecord[];
|
|
58
108
|
trimRegions?: TrimRegion[];
|
|
59
109
|
speedRegions?: SpeedRegion[];
|
|
60
110
|
look?: Partial<LookOptions>;
|
package/dist/project.js
CHANGED
|
@@ -16,11 +16,97 @@ export const DEFAULT_LOOK = {
|
|
|
16
16
|
aspectRatio: "16:9",
|
|
17
17
|
captionPosition: "auto",
|
|
18
18
|
captionFontSize: 30,
|
|
19
|
+
showKeys: false,
|
|
19
20
|
};
|
|
20
21
|
/** Caption box in percent of the output canvas (OpenScreen annotation position/size). */
|
|
21
22
|
export function captionRect(position) {
|
|
22
23
|
return { x: 15, y: position === "top" ? 3.5 : 88.5, width: 70, height: 8 };
|
|
23
24
|
}
|
|
25
|
+
const KEY_LABELS = {
|
|
26
|
+
meta: "⌘",
|
|
27
|
+
cmd: "⌘",
|
|
28
|
+
command: "⌘",
|
|
29
|
+
control: "Ctrl",
|
|
30
|
+
ctrl: "Ctrl",
|
|
31
|
+
controlormeta: "⌘",
|
|
32
|
+
shift: "⇧",
|
|
33
|
+
alt: "Alt",
|
|
34
|
+
option: "⌥",
|
|
35
|
+
enter: "↵",
|
|
36
|
+
return: "↵",
|
|
37
|
+
escape: "Esc",
|
|
38
|
+
esc: "Esc",
|
|
39
|
+
backspace: "⌫",
|
|
40
|
+
delete: "Del",
|
|
41
|
+
tab: "⇥",
|
|
42
|
+
space: "Space",
|
|
43
|
+
" ": "Space",
|
|
44
|
+
arrowup: "↑",
|
|
45
|
+
arrowdown: "↓",
|
|
46
|
+
arrowleft: "←",
|
|
47
|
+
arrowright: "→",
|
|
48
|
+
};
|
|
49
|
+
/** Formats a Playwright key chord (e.g. "Control+Shift+K") into a compact keycap label ("Ctrl + ⇧ + K"). */
|
|
50
|
+
export function formatKeycap(key) {
|
|
51
|
+
return key
|
|
52
|
+
.split("+")
|
|
53
|
+
.map((part) => {
|
|
54
|
+
const trimmed = part.trim();
|
|
55
|
+
const mapped = KEY_LABELS[trimmed.toLowerCase()];
|
|
56
|
+
if (mapped)
|
|
57
|
+
return mapped;
|
|
58
|
+
return trimmed.length === 1 ? trimmed.toUpperCase() : trimmed;
|
|
59
|
+
})
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.join(" + ");
|
|
62
|
+
}
|
|
63
|
+
/** Keycap HUD box in percent of the output canvas (sits clear of top/bottom captions). */
|
|
64
|
+
export function keycapRect(position = "bottom-right", text = "") {
|
|
65
|
+
const width = Math.min(34, Math.max(12, 8 + text.length * 1.5));
|
|
66
|
+
const height = 6.5;
|
|
67
|
+
const x = position.endsWith("left") ? 4 : 95 - width;
|
|
68
|
+
const y = position.startsWith("top") ? 13 : 77.5;
|
|
69
|
+
return { x: Math.round(x * 10) / 10, y, width: Math.round(width * 10) / 10, height };
|
|
70
|
+
}
|
|
71
|
+
/** Builds OpenScreen text annotations for `scene.press()` actions when enabled globally or per-action. */
|
|
72
|
+
export function keycapAnnotations(actions, look = DEFAULT_LOOK, startZIndex = 1) {
|
|
73
|
+
const globalOn = Boolean(look.showKeys);
|
|
74
|
+
const opts = typeof look.showKeys === "object" && look.showKeys ? look.showKeys : {};
|
|
75
|
+
const position = opts.position ?? "bottom-right";
|
|
76
|
+
const defaultDur = opts.durationMs ?? 1100;
|
|
77
|
+
const fontSize = opts.fontSize ?? 24;
|
|
78
|
+
const presses = actions.filter((a) => a.kind === "press" && (a.showKey ?? globalOn) && (a.text ?? a.label));
|
|
79
|
+
return presses.map((a, i) => {
|
|
80
|
+
const raw = a.text ?? a.label ?? "";
|
|
81
|
+
const text = formatKeycap(raw);
|
|
82
|
+
const r = keycapRect(position, text);
|
|
83
|
+
const nextStart = presses[i + 1]?.startMs;
|
|
84
|
+
const desiredEnd = a.startMs + (a.keyDurationMs ?? defaultDur);
|
|
85
|
+
const endMs = nextStart !== undefined ? Math.max(a.startMs + 250, Math.min(desiredEnd, nextStart - 60)) : desiredEnd;
|
|
86
|
+
return {
|
|
87
|
+
id: `keycap-${i + 1}`,
|
|
88
|
+
startMs: Math.round(a.startMs),
|
|
89
|
+
endMs: Math.round(endMs),
|
|
90
|
+
type: "text",
|
|
91
|
+
content: text,
|
|
92
|
+
textContent: text,
|
|
93
|
+
position: { x: r.x, y: r.y },
|
|
94
|
+
size: { width: r.width, height: r.height },
|
|
95
|
+
style: {
|
|
96
|
+
color: "#f8fafc",
|
|
97
|
+
backgroundColor: "rgba(15, 18, 32, 0.88)",
|
|
98
|
+
fontSize,
|
|
99
|
+
fontFamily: "'JetBrains Mono', ui-monospace, 'DejaVu Sans Mono', monospace",
|
|
100
|
+
fontWeight: "bold",
|
|
101
|
+
fontStyle: "normal",
|
|
102
|
+
textDecoration: "none",
|
|
103
|
+
textAlign: "center",
|
|
104
|
+
textAnimation: "none",
|
|
105
|
+
},
|
|
106
|
+
zIndex: startZIndex + i,
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
24
110
|
export function captionAnnotations(captions, look = DEFAULT_LOOK) {
|
|
25
111
|
return captions.map((c, i) => {
|
|
26
112
|
const r = captionRect(c.position ?? look.captionPosition);
|
|
@@ -51,6 +137,8 @@ export function captionAnnotations(captions, look = DEFAULT_LOOK) {
|
|
|
51
137
|
export function buildProject(opts) {
|
|
52
138
|
const look = { ...DEFAULT_LOOK, ...opts.look };
|
|
53
139
|
const videoPath = path.resolve(opts.videoPath);
|
|
140
|
+
const captions = captionAnnotations(opts.captions, look);
|
|
141
|
+
const keycaps = keycapAnnotations(opts.actions ?? [], look, captions.length + 1);
|
|
54
142
|
return {
|
|
55
143
|
version: PROJECT_VERSION,
|
|
56
144
|
// Legacy field: OpenScreen <= 1.2 (v1 projects) only reads `videoPath`; >= 1.3 prefers `media`.
|
|
@@ -73,7 +161,7 @@ export function buildProject(opts) {
|
|
|
73
161
|
autoFocusAll: false,
|
|
74
162
|
trimRegions: opts.trimRegions ?? [],
|
|
75
163
|
speedRegions: opts.speedRegions ?? [],
|
|
76
|
-
annotationRegions:
|
|
164
|
+
annotationRegions: [...captions, ...keycaps],
|
|
77
165
|
aspectRatio: look.aspectRatio,
|
|
78
166
|
webcamLayoutPreset: "picture-in-picture",
|
|
79
167
|
webcamMaskShape: "rectangle",
|
package/dist/record.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { Page } from "playwright";
|
|
|
2
2
|
import { type ComposeResult } from "./compose.ts";
|
|
3
3
|
import type { IdleOptions } from "./idle.ts";
|
|
4
4
|
import type { LookOptions } from "./project.ts";
|
|
5
|
-
import
|
|
5
|
+
import type { CursorStyle } from "./render.ts";
|
|
6
|
+
import { type ClickRippleOptions, type PacingOptions, Scene } from "./scene.ts";
|
|
6
7
|
import type { ActionRecord, RecordingResult, Viewport } from "./types.ts";
|
|
7
8
|
import type { ZoomOptions } from "./zoom.ts";
|
|
8
9
|
export interface ScenarioContext {
|
|
@@ -31,6 +32,10 @@ export interface Scenario {
|
|
|
31
32
|
pacing?: Partial<PacingOptions>;
|
|
32
33
|
zoom?: Partial<ZoomOptions>;
|
|
33
34
|
look?: Partial<LookOptions>;
|
|
35
|
+
/** Optional OpenScreen cursor styling (size, clickBounce, smoothing, motionBlur, show). */
|
|
36
|
+
cursor?: CursorStyle;
|
|
37
|
+
/** Draw an expanding translucent ring at each click (default false). */
|
|
38
|
+
clickRipple?: boolean | ClickRippleOptions;
|
|
34
39
|
/** Cut (or speed up) idle stretches with OpenScreen trim/speed regions. */
|
|
35
40
|
trimIdle?: boolean | Partial<IdleOptions>;
|
|
36
41
|
run(scene: Scene, ctx: ScenarioContext): Promise<void>;
|