cuetake 0.2.0 → 0.3.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 +2 -2
- package/package.json +1 -1
- package/src/cli.js +9 -3
- package/src/cursor.js +3 -32
- package/src/edit.js +37 -44
- package/src/look.js +72 -58
- package/src/pipeline.js +28 -24
- package/src/render-page.js +325 -192
- package/src/render.js +26 -11
- package/src/stage.js +28 -44
- package/src/styles/arrow.js +13 -0
- package/src/styles/browser.js +24 -0
- package/src/styles/dot.js +11 -0
- package/src/styles/fluted.glsl +35 -0
- package/src/styles/macos.js +12 -0
- package/src/styles/shadow.glsl +10 -0
- package/src/styles/spark.js +19 -0
- package/src/styles.js +105 -0
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
Built entirely for AI agents, CueTake turns browser interactions into sharp product demo videos with a precise cursor and continuous camera moves. Give an agent a scenario, then capture, render, and verify the result locally.
|
|
8
8
|
|
|
9
|
-

|
|
10
10
|
|
|
11
11
|
- Retina tab capture at 30 or 60 fps and a 2× pixel scale, headless by default.
|
|
12
12
|
- An automatic camera in the style of Screen Studio: it arrives just before each click, field and drag, follows the cursor on a spring, and ends on the wide shot.
|
|
13
|
-
- The page framed in a browser or macOS window
|
|
13
|
+
- The page framed in a browser or macOS window over fluted glass lit in the product's brand color, at any output size; backgrounds, chrome, cursors and click effects are shaders or drawing code the agent can write.
|
|
14
14
|
- Cursor and click sparks drawn at Render time, so a Take can be restyled without recording again.
|
|
15
15
|
- Styling chosen in conversation: the agent shows Previews of candidate Looks side by side in about a second, and the Look you pick is saved for later Takes.
|
|
16
16
|
- Rendering in Chromium with WebGL and WebCodecs: no FFmpeg, 4K60 by default.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { parseArgs } from 'node:util';
|
|
|
3
3
|
import pkg from '../package.json' with { type: 'json' };
|
|
4
4
|
import { recordScenario, renderTake, verifyTake, previewTake, applyLookToTake, saveLookFromTake } from './pipeline.js';
|
|
5
5
|
import { listLooks, removeLook } from './look.js';
|
|
6
|
+
import { BUILTINS, BUILTIN_DIR } from './styles.js';
|
|
6
7
|
import { doctor, installBrowser } from './environment.js';
|
|
7
8
|
import { login } from './auth.js';
|
|
8
9
|
import { extractFrame } from './render.js';
|
|
@@ -23,18 +24,22 @@ const help = `CueTake ${pkg.version} — browser demos directed by code
|
|
|
23
24
|
cuetake look save <name> <take-directory> [--global] [--replace]
|
|
24
25
|
cuetake look apply <name|file.json> <take-directory>
|
|
25
26
|
cuetake look rm <name> [--global]
|
|
27
|
+
cuetake styles
|
|
26
28
|
|
|
27
29
|
install-browser downloads the Chromium build this CueTake version drives (about 150 MB).
|
|
28
30
|
record captures, renders and verifies a new take; an existing directory is never overwritten.
|
|
29
31
|
Capture runs headless; --headed shows the browser window while recording.
|
|
30
32
|
--look seeds the first Edit from a Look; fields the Scenario config names win.
|
|
31
|
-
preview writes preview.png in the take: the current Edit beside
|
|
33
|
+
preview writes preview.png in the take: the current Edit beside each Look, at --at seconds
|
|
32
34
|
or at the end with the camera wide. It never changes edit.json or final.mp4.
|
|
33
35
|
render reuses source.webm, timeline.json and edit.json, replacing final.mp4 only on success.
|
|
34
36
|
frame saves one Final frame as a PNG for inspection.
|
|
35
37
|
login opens a separate browser; close its window after logging in to save the profile.
|
|
36
|
-
A Look is a take's reusable styling. Looks are saved locally
|
|
37
|
-
unless --global; a local Look hides a global one with the same
|
|
38
|
+
A Look is a take's reusable styling, with the files it draws with. Looks are saved locally
|
|
39
|
+
(.cuetake/looks in this directory) unless --global; a local Look hides a global one with the same
|
|
40
|
+
name. list names the code each Look runs. apply rewrites edit.json and copies files into styles/.
|
|
41
|
+
styles lists the built-in shaders and drawing code, with their files and starting parameters.
|
|
42
|
+
Styling is agent-written code and is not validated; the render page has no network.
|
|
38
43
|
Scenario files are trusted JavaScript. Recording runs locally, without audio.
|
|
39
44
|
`;
|
|
40
45
|
try {
|
|
@@ -58,5 +63,6 @@ try {
|
|
|
58
63
|
else if (command === 'look' && target === 'save' && positionals[3]) print(await saveLookFromTake(positionals[2], positionals[3], { global: values.global, replace: values.replace }));
|
|
59
64
|
else if (command === 'look' && target === 'apply' && positionals[3]) print(await applyLookToTake(positionals[2], positionals[3]));
|
|
60
65
|
else if (command === 'look' && target === 'rm' && positionals[2]) print(await removeLook(positionals[2], { global: values.global }));
|
|
66
|
+
else if (command === 'styles') print(Object.entries(BUILTINS).map(([name, { file, params }]) => ({ name, kind: file.endsWith('.glsl') ? 'shader' : 'draw', path: join(BUILTIN_DIR, file), params })));
|
|
61
67
|
else throw new Error(`Unknown or incomplete command.\n${help}`);
|
|
62
68
|
} catch (error) { console.error(`CueTake: ${error.message}`); process.exitCode = 1; }
|
package/src/cursor.js
CHANGED
|
@@ -20,38 +20,9 @@ export function presses(events) {
|
|
|
20
20
|
: event.type === 'drag' ? [{ t: event.t, ...event.from }] : []);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
/**
|
|
23
|
+
/** Click effects alive at `t`, each with its progress from 0 to 1; `clickEffect: false` shows none. */
|
|
24
24
|
export function sparksAt(pressList, clickEffect, t) {
|
|
25
|
-
if (clickEffect
|
|
26
|
-
const life = clickEffect.duration / 1000;
|
|
25
|
+
if (!clickEffect) return [];
|
|
26
|
+
const life = (clickEffect.duration ?? 400) / 1000;
|
|
27
27
|
return pressList.filter(p => t >= p.t && t < p.t + life).map(p => ({ x: p.x, y: p.y, progress: (t - p.t) / life }));
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
/** Arrow outline in its 28×36 design box; the hotspot is the tip at (2, 2). */
|
|
31
|
-
export const ARROW_PATH = 'M2 2 L2 27 L8.5 21 L14 33 L19 30.5 L13.5 19 L23 19 Z';
|
|
32
|
-
|
|
33
|
-
/** Cursor sprite geometry in CSS pixels: drawn size and the hotspot offset from its top-left. */
|
|
34
|
-
export function cursorGeometry(cursor) {
|
|
35
|
-
return cursor.style === 'arrow'
|
|
36
|
-
? { width: cursor.size, height: cursor.size * 36 / 28, hotspot: { x: cursor.size * 2 / 28, y: cursor.size * 2 / 28 } }
|
|
37
|
-
: { width: cursor.size, height: cursor.size, hotspot: { x: cursor.size / 2, y: cursor.size / 2 } };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Draws one spark centered in a 2D context whose unit is one CSS pixel. */
|
|
41
|
-
export function drawSpark(ctx, x, y, progress, clickEffect, color) {
|
|
42
|
-
const eased = 1 - (1 - progress) ** 3;
|
|
43
|
-
const distance = 5 + eased * clickEffect.radius;
|
|
44
|
-
const length = clickEffect.length * (1 - eased);
|
|
45
|
-
ctx.globalAlpha = 1 - progress;
|
|
46
|
-
ctx.lineCap = 'round';
|
|
47
|
-
for (let i = 0; i < clickEffect.count; i++) {
|
|
48
|
-
const angle = 2 * Math.PI * i / clickEffect.count + Math.PI / 8;
|
|
49
|
-
ctx.beginPath();
|
|
50
|
-
ctx.moveTo(x + distance * Math.cos(angle), y + distance * Math.sin(angle));
|
|
51
|
-
ctx.lineTo(x + (distance + length) * Math.cos(angle), y + (distance + length) * Math.sin(angle));
|
|
52
|
-
// A dark edge under a cursor-colored core stays legible on light and dark pages.
|
|
53
|
-
ctx.strokeStyle = '#171717'; ctx.lineWidth = 4.5; ctx.stroke();
|
|
54
|
-
ctx.strokeStyle = color; ctx.lineWidth = 2.5; ctx.stroke();
|
|
55
|
-
}
|
|
56
|
-
ctx.globalAlpha = 1;
|
|
57
|
-
}
|
package/src/edit.js
CHANGED
|
@@ -1,61 +1,55 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { SHORT_SIDE, CHROME_HEIGHT, BACKGROUNDS } from './stage.js';
|
|
3
2
|
|
|
4
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* An Edit holds every choice Render makes; a Scenario's config only seeds the first one. Styling is
|
|
5
|
+
* agent-written and not validated (ADR 0005): defaults fill in what an Edit leaves out, and anything
|
|
6
|
+
* else an item names is passed to its shader or drawing code as a parameter.
|
|
7
|
+
*
|
|
8
|
+
* Drawn things are items: `{ shader }`, `{ draw }` or `{ image }` naming a file (relative to the Take)
|
|
9
|
+
* or a built-in (a name without an extension, see styles.js), plus optional `files` and parameters.
|
|
10
|
+
*/
|
|
11
|
+
export const EDIT_VERSION = 3;
|
|
5
12
|
export const evenSize = z.number().int().min(240).max(7680).refine(n => n % 2 === 0, 'Must be an even pixel count');
|
|
6
|
-
const box = z.object({ x: z.number(), y: z.number(), width: z.number().nonnegative(), height: z.number().nonnegative() });
|
|
7
|
-
|
|
8
|
-
// size names the Final's short side; quality is the H.264 quantizer (lower is sharper and larger).
|
|
9
|
-
export const outputFields = z.object({
|
|
10
|
-
size: z.union([z.enum(Object.keys(SHORT_SIDE)), evenSize]).default('2160p'),
|
|
11
|
-
aspect: z.enum(['16:9', '1:1', '9:16']).default('16:9'),
|
|
12
|
-
quality: z.number().int().min(10).max(40).default(22),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
// The page in a window on a background. Radius is in 1080p pixels.
|
|
16
|
-
export const frameFields = z.object({
|
|
17
|
-
window: z.enum(Object.keys(CHROME_HEIGHT)).default('browser'),
|
|
18
|
-
background: z.enum([...Object.keys(BACKGROUNDS), 'auto', 'blur']).default('aurora'),
|
|
19
|
-
padding: z.number().min(0).max(0.3).default(0.08),
|
|
20
|
-
radius: z.number().min(0).max(48).default(12),
|
|
21
|
-
shadow: z.boolean().default(true),
|
|
22
|
-
url: z.string().max(200).optional(),
|
|
23
|
-
});
|
|
24
13
|
|
|
25
14
|
/** Times are seconds except clickEffect.duration, which is milliseconds; geometry is CSS pixels. */
|
|
26
|
-
export const
|
|
27
|
-
cursor:
|
|
28
|
-
clickEffect:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
15
|
+
export const DEFAULT_STYLE = {
|
|
16
|
+
cursor: { draw: 'arrow', size: 24, color: '#ffffff' },
|
|
17
|
+
clickEffect: { draw: 'spark', duration: 420 },
|
|
18
|
+
// quality is the H.264 quantizer (lower is sharper and larger).
|
|
19
|
+
output: { width: 3840, height: 2160, quality: 22 },
|
|
20
|
+
// padding is a fraction of the short side, one number or [top, right, bottom, left]; radius is in 1080p pixels.
|
|
21
|
+
frame: { padding: 0.08, radius: 12, chrome: { draw: 'browser' }, background: [{ shader: 'fluted' }], effects: [{ shader: 'shadow' }] },
|
|
32
22
|
// See camera.js. Each target is framed with `padding` CSS px around it, zooming at most `maxZoom`;
|
|
33
23
|
// fits below `minZoom` stay wide. The camera arrives `lead` before an action, holds `hold` after the
|
|
34
24
|
// last one in a segment, settles in about `response`, and returns wide `endWide` before the end.
|
|
35
|
-
camera:
|
|
36
|
-
maxZoom: z.number().min(1).max(4).default(2), minZoom: z.number().min(1).max(4).default(1.2), padding: z.number().min(0).max(400).default(48),
|
|
37
|
-
lead: z.number().min(0).max(3).default(0.6), hold: z.number().min(0).max(30).default(1.5), chainGap: z.number().min(0).max(30).default(2),
|
|
38
|
-
response: z.number().min(0.1).max(3).default(0.6), follow: z.boolean().default(true), endWide: z.number().min(0).max(10).default(1.5),
|
|
39
|
-
}).default({}),
|
|
25
|
+
camera: { maxZoom: 2, minZoom: 1.2, padding: 48, lead: 0.6, hold: 1.5, chainGap: 2, response: 0.6, follow: true, endWide: 1.5 },
|
|
40
26
|
};
|
|
41
27
|
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
29
|
+
/** Naming what draws an item starts a new item, so the old drawing's parameters do not leak into it. */
|
|
30
|
+
const namesDrawing = value => ['shader', 'draw', 'image'].some(key => key in value);
|
|
31
|
+
/** `over` wins field by field: nested objects merge; anything else, including arrays and `false`, replaces. */
|
|
32
|
+
export function merge(base, over) {
|
|
33
|
+
const merged = { ...base };
|
|
34
|
+
for (const [key, value] of Object.entries(over ?? {})) {
|
|
35
|
+
if (value === undefined) continue;
|
|
36
|
+
merged[key] = isObject(value) && isObject(base?.[key]) && !namesDrawing(value) ? merge(base[key], value) : value;
|
|
37
|
+
}
|
|
38
|
+
return merged;
|
|
39
|
+
}
|
|
44
40
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
...
|
|
48
|
-
|
|
49
|
-
// The Final's frame rate; a new Take takes it from the Scenario's capture rate.
|
|
50
|
-
output: outputFields.extend({ fps: z.union([z.literal(30), z.literal(60)]).default(60) }).default({}),
|
|
51
|
-
});
|
|
41
|
+
/** A complete Edit: the defaults under whatever `edit` names. */
|
|
42
|
+
export function withDefaults(edit) {
|
|
43
|
+
return merge({ schemaVersion: EDIT_VERSION, ...DEFAULT_STYLE, output: { ...DEFAULT_STYLE.output, fps: 60 }, camera: { ...DEFAULT_STYLE.camera, targets: [] } }, edit);
|
|
44
|
+
}
|
|
52
45
|
|
|
53
46
|
/**
|
|
54
47
|
* Camera targets: observed clicks, typing and drags, except those inside a `wide` window ({ start, end }
|
|
55
48
|
* seconds) from an action with `focus: false`. Like a manual zoom in Screen Studio, an explicit focus
|
|
56
49
|
* target replaces only the automatic targets inside its own span (from `lead` before it to `hold` after).
|
|
57
50
|
*/
|
|
58
|
-
export function cameraTargets(timeline, focus, wide = [],
|
|
51
|
+
export function cameraTargets(timeline, focus, wide = [], camera = {}) {
|
|
52
|
+
const { lead, hold } = { ...DEFAULT_STYLE.camera, ...camera };
|
|
59
53
|
const spans = focus.map(f => ({ start: f.t - lead, end: (f.until ?? f.t) + hold }));
|
|
60
54
|
const inside = (t, windows) => windows.some(w => t >= w.start && t <= w.end);
|
|
61
55
|
const automatic = timeline.events.filter(event => !inside(event.t, wide) && !inside(event.t, spans)).flatMap(event => {
|
|
@@ -71,11 +65,10 @@ export function cameraTargets(timeline, focus, wide = [], { lead, hold } = editF
|
|
|
71
65
|
}
|
|
72
66
|
|
|
73
67
|
export function createEdit(config, timeline, focus, wide = []) {
|
|
74
|
-
return
|
|
75
|
-
schemaVersion: 2,
|
|
68
|
+
return withDefaults({
|
|
76
69
|
cursor: config.cursor, clickEffect: config.clickEffect, output: { ...config.output, fps: config.capture.fps },
|
|
77
70
|
// The browser chrome shows the Scenario's host unless the config names something else.
|
|
78
|
-
frame:
|
|
71
|
+
frame: { url: new URL(config.url).host, ...config.frame },
|
|
79
72
|
camera: { ...config.camera, targets: cameraTargets(timeline, focus, wide, config.camera) },
|
|
80
73
|
});
|
|
81
74
|
}
|
package/src/look.js
CHANGED
|
@@ -1,46 +1,34 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { merge } from './edit.js';
|
|
5
|
+
import { absolute, bundle, codeRefs, fileRefs } from './styles.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A Look is the part of an Edit that does not depend on one Take: everything except camera targets,
|
|
9
|
-
* the address bar's url and the frame rate.
|
|
9
|
+
* the address bar's url and the frame rate. A Look sets only what it names, and is not validated.
|
|
10
10
|
*/
|
|
11
|
-
export const
|
|
12
|
-
cursor: editFields.cursor.removeDefault().partial().strict(),
|
|
13
|
-
clickEffect: editFields.clickEffect.removeDefault().partial().strict(),
|
|
14
|
-
output: outputFields.partial().strict(),
|
|
15
|
-
frame: z.union([z.literal(false), frameFields.omit({ url: true }).partial().strict()]),
|
|
16
|
-
camera: editFields.camera.removeDefault().partial().strict(),
|
|
17
|
-
}).partial().strict();
|
|
18
|
-
|
|
19
|
-
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
20
|
-
/** `over` wins field by field: nested objects merge, anything else (including `frame: false`) replaces. */
|
|
21
|
-
export function mergeLook(base, over) {
|
|
22
|
-
const merged = { ...base };
|
|
23
|
-
for (const [key, value] of Object.entries(over ?? {})) merged[key] = isObject(value) && isObject(base?.[key]) ? mergeLook(base[key], value) : value;
|
|
24
|
-
return merged;
|
|
25
|
-
}
|
|
11
|
+
export const mergeLook = merge;
|
|
26
12
|
|
|
27
13
|
/** The Look an Edit carries. */
|
|
28
|
-
export function lookFromEdit(
|
|
29
|
-
const {
|
|
30
|
-
|
|
14
|
+
export function lookFromEdit(edit) {
|
|
15
|
+
const { schemaVersion, output: { fps, ...output } = {}, frame, camera: { targets, ...camera } = {}, ...rest } = edit;
|
|
16
|
+
const { url, ...styling } = frame ?? {};
|
|
17
|
+
return { ...rest, output, frame: styling, camera };
|
|
31
18
|
}
|
|
32
19
|
|
|
33
20
|
/** The Edit with a Look adopted. Camera targets and the frame rate stay; the address bar keeps its url, else shows `host`. */
|
|
34
21
|
export function applyLook(edit, look, host) {
|
|
35
|
-
const next =
|
|
36
|
-
|
|
37
|
-
return
|
|
22
|
+
const next = merge(edit, look);
|
|
23
|
+
next.frame = { ...next.frame, url: edit.frame?.url ?? host };
|
|
24
|
+
return next;
|
|
38
25
|
}
|
|
39
26
|
|
|
40
|
-
|
|
27
|
+
const label = item => item && typeof item === 'object' ? basename(String(item.shader ?? item.draw ?? item.image ?? '')) : item === false ? 'none' : null;
|
|
28
|
+
/** One line for listings, such as "browser-dark · fluted · 3840×2160". */
|
|
41
29
|
export function summarize(look) {
|
|
42
|
-
const { frame, output
|
|
43
|
-
const parts = frame
|
|
30
|
+
const { frame, output } = look;
|
|
31
|
+
const parts = [label(frame?.chrome), ...(Array.isArray(frame?.background) ? frame.background.map(label) : []), output?.width && output?.height ? `${output.width}×${output.height}` : null];
|
|
44
32
|
return parts.filter(Boolean).join(' · ') || Object.keys(look).join(', ') || 'empty';
|
|
45
33
|
}
|
|
46
34
|
|
|
@@ -49,59 +37,85 @@ const scopes = (cwd = process.cwd()) => ({
|
|
|
49
37
|
local: join(cwd, '.cuetake', 'looks'),
|
|
50
38
|
global: process.env.CUETAKE_LOOK_DIR || join(homedir(), '.local/share/cuetake/looks'),
|
|
51
39
|
});
|
|
52
|
-
function
|
|
40
|
+
function checkName(name) {
|
|
53
41
|
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(name)) throw new Error('Use a short lowercase Look name, such as brand');
|
|
54
|
-
return join(scopes(cwd)[scope], `${name}.json`);
|
|
55
42
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
const readIfPresent = path => fs.readFile(path, 'utf8').catch(error => { if (['ENOENT', 'ENOTDIR'].includes(error.code)) return null; throw error; });
|
|
44
|
+
const parse = (text, path) => { try { return JSON.parse(text); } catch (error) { throw new Error(`${path} is not JSON: ${error.message}`); } };
|
|
45
|
+
|
|
46
|
+
/** A saved Look is `<name>.json`, or a `<name>/` folder holding `look.json` and the files it names. */
|
|
47
|
+
async function readSaved(dir, name) {
|
|
48
|
+
for (const path of [join(dir, `${name}.json`), join(dir, name, 'look.json')]) {
|
|
49
|
+
const text = await readIfPresent(path);
|
|
50
|
+
if (text !== null) return { path, dir: dirname(path), look: parse(text, path) };
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
60
53
|
}
|
|
61
|
-
const readIfPresent = path => fs.readFile(path, 'utf8').catch(error => { if (error.code === 'ENOENT') return null; throw error; });
|
|
62
54
|
|
|
63
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* A Look by name, local before global, or from a JSON file labeled by its `name` or file name. `dir` is
|
|
57
|
+
* where its file refs resolve.
|
|
58
|
+
*/
|
|
64
59
|
export async function loadLook(ref, cwd = process.cwd()) {
|
|
65
60
|
if (ref.endsWith('.json')) {
|
|
66
61
|
const path = resolve(cwd, ref);
|
|
67
|
-
const { name = basename(ref, '.json'), ...look } =
|
|
68
|
-
return { name: String(name),
|
|
62
|
+
const { name = basename(ref, '.json'), ...look } = parse(await fs.readFile(path, 'utf8'), path);
|
|
63
|
+
return { name: String(name), dir: dirname(path), look };
|
|
69
64
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
checkName(ref);
|
|
66
|
+
for (const [scope, root] of Object.entries(scopes(cwd))) {
|
|
67
|
+
const saved = await readSaved(root, ref);
|
|
68
|
+
if (saved) return { name: ref, scope, dir: saved.dir, look: saved.look };
|
|
73
69
|
}
|
|
74
70
|
const { local, global } = scopes(cwd);
|
|
75
71
|
throw new Error(`No Look named '${ref}' in ${local} or ${global}`);
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
/**
|
|
74
|
+
/** A Look's styling with its file refs made absolute, ready to merge with styling from elsewhere. */
|
|
75
|
+
export const resolvedLook = ({ look, dir }) => absolute(look, dir);
|
|
76
|
+
|
|
77
|
+
/** Every saved Look, with the code files it runs; a global Look hidden by a local one with the same name is marked shadowed. */
|
|
79
78
|
export async function listLooks(cwd = process.cwd()) {
|
|
80
79
|
const found = [];
|
|
81
|
-
for (const [scope,
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
80
|
+
for (const [scope, root] of Object.entries(scopes(cwd))) {
|
|
81
|
+
const entries = await fs.readdir(root, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error; });
|
|
82
|
+
const names = entries.flatMap(e => e.isDirectory() ? [e.name] : e.name.endsWith('.json') ? [basename(e.name, '.json')] : []).sort();
|
|
83
|
+
for (const name of new Set(names)) {
|
|
84
|
+
const saved = await readSaved(root, name).catch(error => ({ error }));
|
|
85
|
+
if (!saved) continue;
|
|
86
|
+
const entry = { name, scope, shadowed: scope === 'global' && found.some(l => l.scope === 'local' && l.name === name), path: saved.path ?? join(root, name) };
|
|
87
|
+
if (saved.error) found.push({ ...entry, summary: `invalid: ${saved.error.message}` });
|
|
88
|
+
else found.push({ ...entry, summary: summarize(saved.look), code: codeRefs(absolute(saved.look, saved.dir)) });
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
return found;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Saves a Look locally unless `global`, with its file refs resolved against `from`. A Look that names
|
|
96
|
+
* files becomes a folder holding copies of them. An existing Look with the name is kept unless `replace`.
|
|
97
|
+
*/
|
|
98
|
+
export async function saveLook(name, look, { global = false, replace = false, cwd, from = cwd ?? process.cwd() } = {}) {
|
|
99
|
+
checkName(name);
|
|
100
|
+
const scope = global ? 'global' : 'local', root = scopes(cwd)[scope];
|
|
101
|
+
const existing = await readSaved(root, name);
|
|
102
|
+
if (existing && !replace) throw new Error(`A ${scope} Look named '${name}' already exists at ${existing.path}; pass --replace to overwrite it`);
|
|
103
|
+
await fs.rm(join(root, `${name}.json`), { force: true });
|
|
104
|
+
await fs.rm(join(root, name), { recursive: true, force: true });
|
|
105
|
+
const hasFiles = fileRefs(look).length > 0, dir = hasFiles ? join(root, name) : root;
|
|
106
|
+
const saved = hasFiles ? await bundle(look, from, dir) : look;
|
|
107
|
+
const path = hasFiles ? join(dir, 'look.json') : join(root, `${name}.json`);
|
|
95
108
|
await fs.mkdir(dirname(path), { recursive: true });
|
|
96
|
-
await fs.writeFile(path, JSON.stringify(
|
|
97
|
-
|
|
98
|
-
throw error;
|
|
99
|
-
});
|
|
100
|
-
return { name, scope, path, summary: summarize(look) };
|
|
109
|
+
await fs.writeFile(path, JSON.stringify(saved, null, 2) + '\n');
|
|
110
|
+
return { name, scope, path, summary: summarize(saved), code: codeRefs(absolute(saved, dir)) };
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
export async function removeLook(name, { global = false, cwd } = {}) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
checkName(name);
|
|
115
|
+
const scope = global ? 'global' : 'local', root = scopes(cwd)[scope];
|
|
116
|
+
const saved = await readSaved(root, name);
|
|
117
|
+
if (!saved) throw new Error(`No ${scope} Look named '${name}' in ${root}`);
|
|
118
|
+
const removed = saved.path === join(root, `${name}.json`) ? saved.path : saved.dir;
|
|
119
|
+
await fs.rm(removed, { recursive: true, force: true });
|
|
120
|
+
return { name, scope, removed };
|
|
107
121
|
}
|
package/src/pipeline.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
import { join, resolve } from 'node:path';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { doctor } from './environment.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { startRecording, getRecordingPage, beginCapture, stopRecording, cleanup } from './recorder.js';
|
|
7
7
|
import { renderFinal, inspectFinal, composePreview } from './render.js';
|
|
8
|
-
import { outputSize } from './stage.js';
|
|
8
|
+
import { outputSize, atShortSide } from './stage.js';
|
|
9
9
|
import { resolveAuthProfile } from './auth.js';
|
|
10
10
|
import { createDirector } from './director.js';
|
|
11
11
|
import { collectTimeline } from './probe.js';
|
|
12
|
-
import {
|
|
13
|
-
import { loadLook,
|
|
12
|
+
import { createEdit, evenSize, merge, withDefaults } from './edit.js';
|
|
13
|
+
import { loadLook, resolvedLook, applyLook, lookFromEdit, saveLook, summarize } from './look.js';
|
|
14
|
+
import { absolute, bundle, forRender } from './styles.js';
|
|
14
15
|
import pkg from '../package.json' with { type: 'json' };
|
|
15
16
|
|
|
16
|
-
const SCHEMA_VERSION =
|
|
17
|
-
/** Scenario config: capture settings plus
|
|
17
|
+
const SCHEMA_VERSION = 3;
|
|
18
|
+
/** Scenario config: capture settings, validated, plus styling that seeds each Take's Edit, which is not (ADR 0005). */
|
|
18
19
|
export const scenarioSchema = z.object({
|
|
19
20
|
name: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
20
21
|
url: z.string().url().refine(s => /^https?:/.test(s), 'Capture requires HTTP(S)'),
|
|
21
22
|
viewport: z.object({ width: evenSize, height: evenSize }).default({ width: 1440, height: 900 }),
|
|
22
23
|
capture: z.object({ fps: z.union([z.literal(30), z.literal(60)]).default(60), resolutionScale: z.union([z.literal(1), z.literal(2)]).default(2) }).default({}),
|
|
23
|
-
|
|
24
|
-
});
|
|
24
|
+
}).passthrough();
|
|
25
25
|
const writeJson = (path, data) => fs.writeFile(path, JSON.stringify(data, null, 2) + '\n');
|
|
26
26
|
const readJson = async path => JSON.parse(await fs.readFile(path, 'utf8'));
|
|
27
27
|
|
|
28
28
|
/** New take directories are exclusive: reruns never overwrite a previous take. */
|
|
29
29
|
export async function recordScenario(scenarioPath, outputDir, options = {}) {
|
|
30
30
|
const scenario = await import(pathToFileURL(resolve(scenarioPath)).href);
|
|
31
|
-
// A Look sits under the Scenario: every field the config names wins over it.
|
|
31
|
+
// A Look sits under the Scenario: every field the config names wins over it. File refs resolve
|
|
32
|
+
// against the Look and the Scenario file, and the files are copied into the Take.
|
|
32
33
|
const look = options.look ? await loadLook(options.look) : null;
|
|
33
|
-
const config = scenarioSchema.parse(look ?
|
|
34
|
+
const config = scenarioSchema.parse(merge(look ? resolvedLook(look) : {}, absolute(scenario.config, dirname(resolve(scenarioPath)))));
|
|
34
35
|
if (typeof scenario.run !== 'function') throw new Error('Scenario must export run(director)');
|
|
35
36
|
const authState = options.authProfile ? await resolveAuthProfile(options.authProfile) : undefined;
|
|
36
37
|
const ready = await doctor();
|
|
@@ -63,7 +64,7 @@ export async function recordScenario(scenarioPath, outputDir, options = {}) {
|
|
|
63
64
|
pointer: observed.pointer, events: [...observed.events, ...focus.map(f => ({ type: 'focus', ...f }))].sort((a, b) => a.t - b.t),
|
|
64
65
|
};
|
|
65
66
|
await writeJson(join(dir, 'timeline.json'), timeline);
|
|
66
|
-
await writeJson(join(dir, 'edit.json'), createEdit(config, timeline, focus, wide));
|
|
67
|
+
await writeJson(join(dir, 'edit.json'), await intoTake(createEdit(config, timeline, focus, wide), dir));
|
|
67
68
|
project = { ...project, status: 'captured', duration: stopped.durationSeconds, evidence: evidence ?? null };
|
|
68
69
|
await writeJson(join(dir, 'project.json'), project);
|
|
69
70
|
} catch (error) {
|
|
@@ -75,26 +76,29 @@ export async function recordScenario(scenarioPath, outputDir, options = {}) {
|
|
|
75
76
|
return { directory: dir, final: join(dir, 'final.mp4'), verification };
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
/** The Edit with every file it names copied into the Take's styles/ folder, so the Take stands alone (ADR 0002). */
|
|
80
|
+
const intoTake = (edit, dir) => bundle(edit, dir, join(dir, 'styles'), 'styles/');
|
|
81
|
+
|
|
78
82
|
/** Reads a Take's project.json, Timeline and Edit, refusing Takes from an older schema. */
|
|
79
83
|
async function loadTake(dir) {
|
|
80
84
|
const project = await readJson(join(dir, 'project.json'));
|
|
81
85
|
if (project.schemaVersion !== SCHEMA_VERSION) throw new Error(`${dir} was recorded by an older CueTake (schema ${project.schemaVersion ?? 1}); record it again`);
|
|
82
|
-
return { project, config: scenarioSchema.parse(project.config), timeline: await readJson(join(dir, 'timeline.json')), edit:
|
|
86
|
+
return { project, config: scenarioSchema.parse(project.config), timeline: await readJson(join(dir, 'timeline.json')), edit: withDefaults(await readJson(join(dir, 'edit.json'))) };
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
/**
|
|
86
|
-
* Writes preview.png: the Take's current Edit beside each Look (names or JSON files), composed
|
|
87
|
-
*
|
|
90
|
+
* Writes preview.png: the Take's current Edit beside each Look (names or JSON files), composed with a
|
|
91
|
+
* 1080-pixel short side in each output's own proportions. Without `at` it shows the last moment with the camera wide.
|
|
88
92
|
*/
|
|
89
93
|
export async function previewTake(directory, refs = [], { at } = {}) {
|
|
90
94
|
const dir = resolve(directory);
|
|
91
95
|
const { config, timeline, edit } = await loadTake(dir);
|
|
92
|
-
if (refs.length > 5) throw new Error('Compare at most five Looks with the current Edit');
|
|
93
96
|
if (at !== undefined && !(at >= 0 && at <= timeline.duration)) throw new Error(`--at must be between 0 and ${timeline.duration} seconds`);
|
|
94
97
|
const host = new URL(config.url).host;
|
|
95
98
|
const looks = await Promise.all(refs.map(ref => loadLook(ref)));
|
|
96
|
-
const tiles = [{ name: 'current', edit }, ...looks.map(
|
|
97
|
-
const
|
|
99
|
+
const tiles = [{ name: 'current', edit }, ...looks.map(look => ({ name: look.name, edit: applyLook(edit, resolvedLook(look), host) }))];
|
|
100
|
+
const files = {}, shown = tiles.map(({ name, edit }) => ({ name, edit: forRender(atShortSide(edit, 1080), dir, files).edit }));
|
|
101
|
+
const png = await composePreview({ sourcePath: join(dir, 'source.webm'), timeline, at, tiles: shown, files });
|
|
98
102
|
const preview = join(dir, 'preview.png');
|
|
99
103
|
await fs.writeFile(preview, png);
|
|
100
104
|
return { preview, at: at ?? 'end, camera wide', tiles: tiles.map(({ name, edit }) => ({ name, summary: summarize(lookFromEdit(edit)) })) };
|
|
@@ -104,16 +108,16 @@ export async function previewTake(directory, refs = [], { at } = {}) {
|
|
|
104
108
|
export async function applyLookToTake(ref, directory) {
|
|
105
109
|
const dir = resolve(directory);
|
|
106
110
|
const { config, edit } = await loadTake(dir);
|
|
107
|
-
const
|
|
108
|
-
const next = applyLook(edit, look, new URL(config.url).host);
|
|
111
|
+
const look = await loadLook(ref);
|
|
112
|
+
const next = await intoTake(applyLook(edit, resolvedLook(look), new URL(config.url).host), dir);
|
|
109
113
|
await writeJson(join(dir, 'edit.json'), next);
|
|
110
|
-
return { look: name, edit: join(dir, 'edit.json'), summary: summarize(lookFromEdit(next)), next: `cuetake render ${dir}` };
|
|
114
|
+
return { look: look.name, edit: join(dir, 'edit.json'), summary: summarize(lookFromEdit(next)), next: `cuetake render ${dir}` };
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
/** Saves the Take's styling as a Look, locally unless `global`. */
|
|
114
118
|
export async function saveLookFromTake(name, directory, options) {
|
|
115
|
-
const { edit } = await loadTake(
|
|
116
|
-
return saveLook(name, lookFromEdit(edit), options);
|
|
119
|
+
const dir = resolve(directory), { edit } = await loadTake(dir);
|
|
120
|
+
return saveLook(name, lookFromEdit(edit), { ...options, from: dir });
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
export async function renderTake(directory) {
|
|
@@ -122,7 +126,7 @@ export async function renderTake(directory) {
|
|
|
122
126
|
// Render to a temporary output; preserve the last complete final if encoding fails.
|
|
123
127
|
const temporary = join(dir, 'final.pending.mp4');
|
|
124
128
|
try {
|
|
125
|
-
const render = await renderFinal({ sourcePath: join(dir, 'source.webm'), finalPath: temporary, timeline, edit });
|
|
129
|
+
const render = await renderFinal({ sourcePath: join(dir, 'source.webm'), finalPath: temporary, timeline, ...forRender(edit, dir) });
|
|
126
130
|
await fs.rename(temporary, join(dir, 'final.mp4'));
|
|
127
131
|
await writeJson(join(dir, 'render.json'), render);
|
|
128
132
|
await fs.rm(join(dir, 'verification.json'), { force: true });
|
|
@@ -143,7 +147,7 @@ export async function verifyTake(directory) {
|
|
|
143
147
|
const { project, config, timeline, edit } = await loadTake(dir);
|
|
144
148
|
const media = await inspectFinal(join(dir, 'final.mp4'));
|
|
145
149
|
const { fps } = edit.output;
|
|
146
|
-
const expected = { ...outputSize(edit
|
|
150
|
+
const expected = { ...outputSize(edit), fps, frames: Math.round(project.duration * fps) };
|
|
147
151
|
const problems = [
|
|
148
152
|
media.width !== expected.width || media.height !== expected.height ? `size ${media.width}×${media.height}, expected ${expected.width}×${expected.height}` : null,
|
|
149
153
|
Math.abs(media.fps - expected.fps) > 0.01 ? `${media.fps} fps, expected ${expected.fps}` : null,
|