cuetake 0.5.0 → 0.6.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/package.json +1 -1
- package/src/auth.js +3 -2
- package/src/cli.js +16 -9
- package/src/cursor.js +24 -4
- package/src/edit.js +5 -3
- package/src/home.js +23 -0
- package/src/look.js +24 -23
- package/src/pipeline.js +3 -2
- package/src/recorder.js +1 -1
- package/src/render.js +7 -2
- package/src/uninstall.js +22 -9
package/package.json
CHANGED
package/src/auth.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { chromium } from 'playwright';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
3
|
import { join } from 'node:path';
|
|
5
4
|
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { userHome } from './home.js';
|
|
6
6
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
7
|
-
|
|
7
|
+
/** Auth profiles stay per user, in the user Home, whichever Home a skill uses (ADR 0011). */
|
|
8
|
+
const root = () => process.env.CUETAKE_AUTH_DIR || join(userHome(), 'auth');
|
|
8
9
|
const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
9
10
|
function profilePath(profile) {
|
|
10
11
|
if (!NAME.test(profile)) throw new Error('Use a short lowercase profile name, such as product-demo');
|
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, importNarration } from './pipeline.js';
|
|
5
5
|
import { listLooks, removeLook } from './look.js';
|
|
6
|
+
import { ensureHome } from './home.js';
|
|
6
7
|
import { BUILTINS, BUILTIN_DIR } from './styles.js';
|
|
7
8
|
import { doctor, installBrowser } from './environment.js';
|
|
8
9
|
import { uninstall } from './uninstall.js';
|
|
@@ -17,7 +18,8 @@ const help = `CueTake ${pkg.version} — browser demos directed by code
|
|
|
17
18
|
|
|
18
19
|
cuetake doctor
|
|
19
20
|
cuetake install-browser
|
|
20
|
-
cuetake
|
|
21
|
+
cuetake home
|
|
22
|
+
cuetake uninstall [--auth] [--looks] [--takes] [--scenarios] [--dry-run]
|
|
21
23
|
cuetake record <scenario.mjs> [--out <new-directory>] [--auth-profile <name>] [--look <name|file.json>] [--narration <narration.json>] [--headed] [--use-running]
|
|
22
24
|
cuetake tree <app>
|
|
23
25
|
cuetake narrate import <take-directory> <narration.json>
|
|
@@ -33,10 +35,14 @@ const help = `CueTake ${pkg.version} — browser demos directed by code
|
|
|
33
35
|
cuetake styles
|
|
34
36
|
|
|
35
37
|
install-browser downloads the Chromium build this CueTake version drives (about 150 MB).
|
|
38
|
+
home prints the Home, where Scenarios, Takes and Looks live, and creates it when missing: <project>/.cuetake
|
|
39
|
+
when the skill that ran is installed in a project, else the user Home, ~/.local/share/cuetake.
|
|
40
|
+
CUETAKE_HOME overrides it. A project Home starts with a .gitignore for takes/, which you may change.
|
|
36
41
|
uninstall removes CueTake's npx cache and its browser, unless another Playwright installation uses it.
|
|
37
|
-
It keeps Auth profiles unless --auth and
|
|
38
|
-
|
|
39
|
-
record captures, renders and verifies a new take
|
|
42
|
+
It keeps Auth profiles unless --auth, and the user Home's Looks, Takes and Scenarios unless --looks,
|
|
43
|
+
--takes and --scenarios; a project Home is never touched. --dry-run lists what would go and removes nothing.
|
|
44
|
+
record captures, renders and verifies a new take in <home>/takes/<name>/<time>, or in --out; an existing
|
|
45
|
+
directory is never overwritten.
|
|
40
46
|
Capture runs headless; --headed shows the browser window while recording.
|
|
41
47
|
A Scenario naming an app instead of a url records a desktop App on macOS: its windows on a Desktop.
|
|
42
48
|
An App the user already runs stops it; --use-running, with the user's consent, records it as it is,
|
|
@@ -52,22 +58,23 @@ preview writes preview.png in the take: the current Edit beside each Look, at --
|
|
|
52
58
|
render reuses source.webm, timeline.json and edit.json, replacing final.mp4 only on success.
|
|
53
59
|
frame saves one Final frame as a PNG for inspection.
|
|
54
60
|
login opens a separate browser; close its window after logging in to save the profile.
|
|
55
|
-
A Look is a take's reusable styling, with the files it draws with. Looks are saved
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
A Look is a take's reusable styling, with the files it draws with. Looks are saved in the Home, or the
|
|
62
|
+
user Home with --global; a project Look hides a user Look with the same name. list names the code
|
|
63
|
+
each Look runs. apply rewrites edit.json and copies files into styles/.
|
|
58
64
|
styles lists the built-in shaders and drawing code, with their files and starting parameters.
|
|
59
65
|
Styling is agent-written code and is not validated; the render page has no network.
|
|
60
66
|
Scenario files are trusted JavaScript. Recording runs locally and captures no page audio; Narration is
|
|
61
67
|
voiced beforehand by a speech tool of your choice.
|
|
62
68
|
`;
|
|
63
69
|
try {
|
|
64
|
-
const { values, positionals } = parseArgs({ args: process.argv.slice(2), allowPositionals: true, options: { out: { type: 'string' }, help: { type: 'boolean', short: 'h' }, 'auth-profile': { type: 'string' }, headed: { type: 'boolean' }, look: { type: 'string', multiple: true }, narration: { type: 'string' }, at: { type: 'string' }, global: { type: 'boolean' }, replace: { type: 'boolean' }, auth: { type: 'boolean' }, looks: { type: 'boolean' }, 'dry-run': { type: 'boolean' }, 'use-running': { type: 'boolean' } } });
|
|
70
|
+
const { values, positionals } = parseArgs({ args: process.argv.slice(2), allowPositionals: true, options: { out: { type: 'string' }, help: { type: 'boolean', short: 'h' }, 'auth-profile': { type: 'string' }, headed: { type: 'boolean' }, look: { type: 'string', multiple: true }, narration: { type: 'string' }, at: { type: 'string' }, global: { type: 'boolean' }, replace: { type: 'boolean' }, auth: { type: 'boolean' }, looks: { type: 'boolean' }, takes: { type: 'boolean' }, scenarios: { type: 'boolean' }, 'dry-run': { type: 'boolean' }, 'use-running': { type: 'boolean' } } });
|
|
65
71
|
const [command, target] = positionals, looks = values.look ?? [];
|
|
66
72
|
const print = data => console.log(JSON.stringify(data, null, 2));
|
|
67
73
|
if (values.help || !command) console.log(help);
|
|
68
74
|
else if (command === 'doctor') { const result = await doctor(); console.log(JSON.stringify(result, null, 2)); if (!result.ok) process.exitCode = 1; }
|
|
69
75
|
else if (command === 'install-browser') console.log(JSON.stringify(await installBrowser(), null, 2));
|
|
70
|
-
else if (command === '
|
|
76
|
+
else if (command === 'home' && !target) console.log(await ensureHome());
|
|
77
|
+
else if (command === 'uninstall' && !target) print(await uninstall({ auth: values.auth, looks: values.looks, takes: values.takes, scenarios: values.scenarios, dryRun: values['dry-run'] }));
|
|
71
78
|
else if (command === 'record' && target && looks.length <= 1) print(await recordScenario(target, values.out, { authProfile: values['auth-profile'], look: looks[0], narration: values.narration, headed: values.headed, useRunning: values['use-running'] }));
|
|
72
79
|
else if (command === 'tree' && target) console.log(treeLines(await appTree(target)).join('\n'));
|
|
73
80
|
else if (command === 'narrate' && target === 'import' && positionals[3]) print(await importNarration(positionals[2], positionals[3]));
|
package/src/cursor.js
CHANGED
|
@@ -68,17 +68,37 @@ const ALIASES = {
|
|
|
68
68
|
/** The shape a cursor drawing `drawn` (a Set of names) shows for `keyword`: itself, its alias, or `default`. */
|
|
69
69
|
export const drawnShape = (keyword, drawn) => drawn.has(keyword) ? keyword : drawn.has(ALIASES[keyword]) ? ALIASES[keyword] : 'default';
|
|
70
70
|
|
|
71
|
+
// Seconds a shape must be asked for before the Cursor takes it. The Edit's default, also used when its cursor
|
|
72
|
+
// item has no `settle`: an item naming its own drawing, and any Edit written before `settle`, replace the default item.
|
|
73
|
+
export const SETTLE = 0.15;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The shapes the Cursor shows: each the page asked for at least `settle` seconds, or while a button was held
|
|
77
|
+
* (`spans`), from the moment it was asked; a shorter one, asked only while the Cursor passed over, keeps the
|
|
78
|
+
* shape before it.
|
|
79
|
+
*/
|
|
80
|
+
function settledShapes(shapes, spans, settle) {
|
|
81
|
+
if (!(settle > 0)) return shapes;
|
|
82
|
+
const shown = [];
|
|
83
|
+
shapes.forEach(([t, shape], i) => {
|
|
84
|
+
const end = shapes[i + 1]?.[0] ?? Infinity;
|
|
85
|
+
const keep = end - t >= settle || spans.some(span => span.t < end && span.end >= t);
|
|
86
|
+
if (keep && shape !== (shown.at(-1)?.[1] ?? 'default')) shown.push([t, shape]);
|
|
87
|
+
});
|
|
88
|
+
return shown;
|
|
89
|
+
}
|
|
90
|
+
|
|
71
91
|
/**
|
|
72
|
-
* The Cursor through a Take: `at(t)` gives its point, scale and the shape
|
|
73
|
-
*
|
|
92
|
+
* The Cursor through a Take: `at(t)` gives its point, scale and the shape it shows, or null before
|
|
93
|
+
* the first pointer sample. `cursor` is the Edit's cursor item.
|
|
74
94
|
*/
|
|
75
95
|
export function cursorTrack({ pointer, shapes = [], events }, cursor) {
|
|
76
|
-
const spans = heldSpans(events);
|
|
96
|
+
const spans = heldSpans(events), shown = settledShapes(shapes, spans, cursor.settle ?? SETTLE);
|
|
77
97
|
return {
|
|
78
98
|
at(t) {
|
|
79
99
|
const point = pointerAt(pointer, t);
|
|
80
100
|
if (!point) return null;
|
|
81
|
-
return { ...point, scale: pressScale(spans, cursor.press, t), shape: shapeAt(
|
|
101
|
+
return { ...point, scale: pressScale(spans, cursor.press, t), shape: shapeAt(shown, t) };
|
|
82
102
|
},
|
|
83
103
|
};
|
|
84
104
|
}
|
package/src/edit.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { isPopup } from './tabs.js';
|
|
3
|
+
import { SETTLE } from './cursor.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* An Edit holds every choice Render makes; a Scenario's config only seeds the first one. Styling is
|
|
@@ -14,9 +15,10 @@ export const evenSize = z.number().int().min(240).max(7680).refine(n => n % 2 ==
|
|
|
14
15
|
|
|
15
16
|
/** Times are seconds except clickEffect.duration, which is milliseconds; geometry is CSS pixels. */
|
|
16
17
|
export const DEFAULT_STYLE = {
|
|
17
|
-
// The Cursor shrinks to `press` while a button is held; `false` turns that off.
|
|
18
|
-
//
|
|
19
|
-
|
|
18
|
+
// The Cursor shrinks to `press` while a button is held; `false` turns that off. It takes a shape only
|
|
19
|
+
// once the page has asked for it `settle` seconds or at a press; 0 shows every shape. A click shows on
|
|
20
|
+
// the Cursor, so no click effect is drawn unless named.
|
|
21
|
+
cursor: { draw: 'arrow', size: 24, color: '#ffffff', press: 0.8, settle: SETTLE },
|
|
20
22
|
clickEffect: false,
|
|
21
23
|
// quality is the H.264 quantizer (lower is sharper and larger). shutter is the fraction of each
|
|
22
24
|
// frame over which the camera and the Cursor blur as they move (shutter.js); 0 turns blur off.
|
package/src/home.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
/** The user Home, shared by every project; on macOS and Linux it follows $HOME. */
|
|
6
|
+
export const userHome = () => join(process.env.HOME || homedir(), '.local', 'share', 'cuetake');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The Home of the skill copy that ran: `CUETAKE_HOME`, which the skill's launcher sets for a skill installed
|
|
10
|
+
* in a project, else the user Home (ADR 0011).
|
|
11
|
+
*/
|
|
12
|
+
export const home = () => process.env.CUETAKE_HOME ? resolve(process.env.CUETAKE_HOME) : userHome();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The Home, created when missing. A project Home is created with a .gitignore that keeps its Takes out of
|
|
16
|
+
* git; CueTake never writes that file again, so the user may change it.
|
|
17
|
+
*/
|
|
18
|
+
export async function ensureHome() {
|
|
19
|
+
const dir = home();
|
|
20
|
+
const created = await fs.mkdir(dir, { recursive: true });
|
|
21
|
+
if (created && dir !== userHome()) await fs.writeFile(join(dir, '.gitignore'), 'takes/\n');
|
|
22
|
+
return dir;
|
|
23
|
+
}
|
package/src/look.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
2
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
4
3
|
import { merge } from './edit.js';
|
|
4
|
+
import { ensureHome, home, userHome } from './home.js';
|
|
5
5
|
import { absolute, bundle, codeRefs, fileRefs } from './styles.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -37,11 +37,11 @@ export function summarize(look) {
|
|
|
37
37
|
return parts.filter(Boolean).join(' · ') || Object.keys(look).join(', ') || 'empty';
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/**
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
/** Looks live in the Home; a project Home's Looks come before the user Home's, which serve every project. */
|
|
41
|
+
const inProject = () => home() !== userHome();
|
|
42
|
+
const scopes = () => ({ ...(inProject() && { project: join(home(), 'looks') }), user: join(userHome(), 'looks') });
|
|
43
|
+
/** Where `look save` and `look rm` act: the user Home with --global, else the Home. */
|
|
44
|
+
const scopeFor = global => !global && inProject() ? 'project' : 'user';
|
|
45
45
|
const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
46
46
|
function checkName(name) {
|
|
47
47
|
if (!NAME.test(name)) throw new Error('Use a short lowercase Look name, such as brand');
|
|
@@ -59,7 +59,7 @@ async function readSaved(dir, name) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* A Look by name,
|
|
62
|
+
* A Look by name, the project's before the user's, or from a JSON file labeled by its `name` or file name. `dir` is
|
|
63
63
|
* where its file refs resolve.
|
|
64
64
|
*/
|
|
65
65
|
export async function loadLook(ref, cwd = process.cwd()) {
|
|
@@ -69,27 +69,26 @@ export async function loadLook(ref, cwd = process.cwd()) {
|
|
|
69
69
|
return { name: String(name), dir: dirname(path), look };
|
|
70
70
|
}
|
|
71
71
|
checkName(ref);
|
|
72
|
-
for (const [scope, root] of Object.entries(scopes(
|
|
72
|
+
for (const [scope, root] of Object.entries(scopes())) {
|
|
73
73
|
const saved = await readSaved(root, ref);
|
|
74
74
|
if (saved) return { name: ref, scope, dir: saved.dir, look: saved.look };
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
throw new Error(`No Look named '${ref}' in ${local} or ${global}`);
|
|
76
|
+
throw new Error(`No Look named '${ref}' in ${Object.values(scopes()).join(' or ')}`);
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
/** A Look's styling with its file refs made absolute, ready to merge with styling from elsewhere. */
|
|
81
80
|
export const resolvedLook = ({ look, dir }) => absolute(look, dir);
|
|
82
81
|
|
|
83
|
-
/** Every saved Look, with the code files it runs; a
|
|
84
|
-
export async function listLooks(
|
|
82
|
+
/** Every saved Look, with the code files it runs; a user Look hidden by a project one with the same name is marked shadowed. */
|
|
83
|
+
export async function listLooks() {
|
|
85
84
|
const found = [];
|
|
86
|
-
for (const [scope, root] of Object.entries(scopes(
|
|
85
|
+
for (const [scope, root] of Object.entries(scopes())) {
|
|
87
86
|
const entries = await fs.readdir(root, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error; });
|
|
88
87
|
const names = entries.flatMap(e => e.isDirectory() ? [e.name] : e.name.endsWith('.json') ? [basename(e.name, '.json')] : []).sort();
|
|
89
88
|
for (const name of new Set(names)) {
|
|
90
89
|
const saved = await readSaved(root, name).catch(error => ({ error }));
|
|
91
90
|
if (!saved) continue;
|
|
92
|
-
const entry = { name, scope, shadowed: scope === '
|
|
91
|
+
const entry = { name, scope, shadowed: scope === 'user' && found.some(l => l.scope === 'project' && l.name === name), path: saved.path ?? join(root, name) };
|
|
93
92
|
if (saved.error) found.push({ ...entry, summary: `invalid: ${saved.error.message}` });
|
|
94
93
|
else found.push({ ...entry, summary: summarize(saved.look), code: codeRefs(absolute(saved.look, saved.dir)) });
|
|
95
94
|
}
|
|
@@ -98,12 +97,14 @@ export async function listLooks(cwd = process.cwd()) {
|
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
/**
|
|
101
|
-
* Saves a Look
|
|
102
|
-
* files becomes a folder holding copies of them. An existing Look with the name is kept
|
|
100
|
+
* Saves a Look in the Home, or the user Home when `global`, with its file refs resolved against `from`. A
|
|
101
|
+
* Look that names files becomes a folder holding copies of them. An existing Look with the name is kept
|
|
102
|
+
* unless `replace`.
|
|
103
103
|
*/
|
|
104
|
-
export async function saveLook(name, look, { global = false, replace = false,
|
|
104
|
+
export async function saveLook(name, look, { global = false, replace = false, from = process.cwd() } = {}) {
|
|
105
105
|
checkName(name);
|
|
106
|
-
const scope = global
|
|
106
|
+
const scope = scopeFor(global), root = scopes()[scope];
|
|
107
|
+
if (scope === 'project') await ensureHome();
|
|
107
108
|
const existing = await readSaved(root, name);
|
|
108
109
|
if (existing && !replace) throw new Error(`A ${scope} Look named '${name}' already exists at ${existing.path}; pass --replace to overwrite it`);
|
|
109
110
|
await fs.rm(join(root, `${name}.json`), { force: true });
|
|
@@ -116,9 +117,9 @@ export async function saveLook(name, look, { global = false, replace = false, cw
|
|
|
116
117
|
return { name, scope, path, summary: summarize(saved), code: codeRefs(absolute(saved, dir)) };
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
/** The file or folder of every
|
|
120
|
-
export async function
|
|
121
|
-
const dir = scopes().
|
|
120
|
+
/** The file or folder of every Look in the user Home; other files in the folder are not CueTake's. */
|
|
121
|
+
export async function userLookFiles() {
|
|
122
|
+
const dir = scopes().user, paths = [];
|
|
122
123
|
const entries = await fs.readdir(dir, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error; });
|
|
123
124
|
for (const entry of entries) {
|
|
124
125
|
const path = join(dir, entry.name);
|
|
@@ -128,9 +129,9 @@ export async function globalLookFiles() {
|
|
|
128
129
|
return { dir, paths: paths.sort() };
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
export async function removeLook(name, { global = false
|
|
132
|
+
export async function removeLook(name, { global = false } = {}) {
|
|
132
133
|
checkName(name);
|
|
133
|
-
const scope = global
|
|
134
|
+
const scope = scopeFor(global), root = scopes()[scope];
|
|
134
135
|
const saved = await readSaved(root, name);
|
|
135
136
|
if (!saved) throw new Error(`No ${scope} Look named '${name}' in ${root}`);
|
|
136
137
|
const removed = saved.path === join(root, `${name}.json`) ? saved.path : saved.dir;
|
package/src/pipeline.js
CHANGED
|
@@ -15,6 +15,7 @@ import { desktopWarnings } from './desktop.js';
|
|
|
15
15
|
import { collectTimeline } from './probe.js';
|
|
16
16
|
import { createEdit, evenSize, merge, withDefaults } from './edit.js';
|
|
17
17
|
import { loadLook, resolvedLook, applyLook, lookFromEdit, saveLook, summarize } from './look.js';
|
|
18
|
+
import { ensureHome } from './home.js';
|
|
18
19
|
import { absolute, bundle, forRender } from './styles.js';
|
|
19
20
|
import { burnsIn, cuesFor, isCjk, lineProblems, toSrt, toVtt } from './narration.js';
|
|
20
21
|
import { linesInFinal, timeMap } from './time-map.js';
|
|
@@ -273,7 +274,7 @@ export async function recordScenario(scenarioPath, outputDir, options = {}) {
|
|
|
273
274
|
const gpu = ready.checks.find(check => check.name === 'gpu');
|
|
274
275
|
const { resolutionScale, lowered } = config.app ? { resolutionScale: config.capture.resolutionScale, lowered: false } : captureScale(given.capture?.resolutionScale, gpu);
|
|
275
276
|
config.capture.resolutionScale = resolutionScale;
|
|
276
|
-
const dir = resolve(outputDir || join('
|
|
277
|
+
const dir = resolve(outputDir || join(await ensureHome(), 'takes', config.name, new Date().toISOString().replace(/[:.]/g, '-')));
|
|
277
278
|
await fs.mkdir(resolve(dir, '..'), { recursive: true });
|
|
278
279
|
await fs.mkdir(dir); // EEXIST is intentional, including for empty existing folders.
|
|
279
280
|
let project = { schemaVersion: SCHEMA_VERSION, tool: 'CueTake', version: pkg.version, createdAt: new Date().toISOString(), status: 'recording', authenticated: Boolean(authState), ...(look && { look: look.name }), config };
|
|
@@ -384,7 +385,7 @@ export async function applyLookToTake(ref, directory) {
|
|
|
384
385
|
return { look: look.name, edit: join(dir, 'edit.json'), summary: summarize(lookFromEdit(next)), next: `cuetake render ${dir}` };
|
|
385
386
|
}
|
|
386
387
|
|
|
387
|
-
/** Saves the Take's styling as a Look,
|
|
388
|
+
/** Saves the Take's styling as a Look in the Home, or the user Home when `global`. */
|
|
388
389
|
export async function saveLookFromTake(name, directory, options) {
|
|
389
390
|
const dir = resolve(directory), { edit } = await loadTake(dir);
|
|
390
391
|
return saveLook(name, lookFromEdit(edit), { ...options, from: dir });
|
package/src/recorder.js
CHANGED
|
@@ -18,7 +18,7 @@ export async function startRecording(url, options = {}) {
|
|
|
18
18
|
headless: !options.headed, channel: 'chromium',
|
|
19
19
|
args: [...captureArgs, '--disable-backgrounding-occluded-windows', '--disable-renderer-backgrounding', ...(options.headed ? [] : [`--force-device-scale-factor=${resolutionScale}`])],
|
|
20
20
|
});
|
|
21
|
-
const outputDir = options
|
|
21
|
+
const { outputDir } = options;
|
|
22
22
|
await mkdir(outputDir, { recursive: true });
|
|
23
23
|
const context = await browser.newContext({ viewport: { width, height }, deviceScaleFactor: resolutionScale, ...(options.storageState ? { storageState: options.storageState } : {}) });
|
|
24
24
|
const sessionId = randomUUID().slice(0, 8);
|
package/src/render.js
CHANGED
|
@@ -30,11 +30,16 @@ const pageFiles = {
|
|
|
30
30
|
'/mediabunny.js': { path: mediabunnyBundle, type: 'text/javascript' },
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
// A range reader such as Mediabunny's UrlSource asks for `bytes=N-`; answering with the rest of a long
|
|
34
|
+
// Source or Final at once sends hundreds of MB through one Playwright message and takes the browser down.
|
|
35
|
+
const RANGE_CHUNK = 8 * 1024 * 1024;
|
|
36
|
+
|
|
37
|
+
/** Answers `route` from the file at `path`: a range with at most RANGE_CHUNK bytes, a plain request with the whole file. */
|
|
38
|
+
export async function serveRange(route, path) {
|
|
34
39
|
const { size } = await fs.stat(path);
|
|
35
40
|
const match = /bytes=(\d+)-(\d*)/.exec(route.request().headers().range ?? '');
|
|
36
41
|
const start = match ? Number(match[1]) : 0;
|
|
37
|
-
const end = match
|
|
42
|
+
const end = match ? Math.min(match[2] ? Number(match[2]) : size - 1, start + RANGE_CHUNK - 1, size - 1) : size - 1;
|
|
38
43
|
const handle = await fs.open(path);
|
|
39
44
|
try {
|
|
40
45
|
const body = Buffer.alloc(end - start + 1);
|
package/src/uninstall.js
CHANGED
|
@@ -3,7 +3,8 @@ import { homedir } from 'node:os';
|
|
|
3
3
|
import { basename, dirname, join } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { authProfileFiles } from './auth.js';
|
|
6
|
-
import {
|
|
6
|
+
import { userLookFiles } from './look.js';
|
|
7
|
+
import { userHome } from './home.js';
|
|
7
8
|
import { uninstallBrowser } from './environment.js';
|
|
8
9
|
|
|
9
10
|
const PACKAGE_DIR = fileURLToPath(new URL('..', import.meta.url)).replace(/[\\/]$/, '');
|
|
@@ -26,13 +27,24 @@ export async function npxFolders({ cache = process.env.npm_config_cache || join(
|
|
|
26
27
|
return found.sort();
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
const entries = async dir => (await fs.readdir(dir, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error; }))
|
|
31
|
+
.sort((a, b) => a.name.localeCompare(b.name)).map(entry => ({ path: join(dir, entry.name), folder: entry.isDirectory() }));
|
|
32
|
+
|
|
33
|
+
/** Each Take folder in the user Home, at `takes/<scenario>/<time>`. */
|
|
34
|
+
async function userTakes() {
|
|
35
|
+
const dir = join(userHome(), 'takes'), folders = (await entries(dir)).filter(e => e.folder).map(e => e.path), paths = [];
|
|
36
|
+
for (const folder of folders) for (const take of await entries(folder)) if (take.folder) paths.push(take.path);
|
|
37
|
+
return { dir, paths, folders };
|
|
38
|
+
}
|
|
39
|
+
const userScenarios = async () => { const dir = join(userHome(), 'scenarios'); return { dir, paths: (await entries(dir)).map(e => e.path) }; };
|
|
40
|
+
|
|
29
41
|
/**
|
|
30
42
|
* Removes what CueTake put on this machine outside the user's projects: its npx folders and, through
|
|
31
|
-
* Playwright, the browser unless another Playwright installation still uses it. Auth profiles and
|
|
32
|
-
* Looks are the user's and go only when asked.
|
|
43
|
+
* Playwright, the browser unless another Playwright installation still uses it. Auth profiles and the user
|
|
44
|
+
* Home's Looks, Takes and Scenarios are the user's and go only when asked. A project Home is never touched.
|
|
33
45
|
*/
|
|
34
|
-
export async function uninstall({ auth = false, looks = false, dryRun = false, removeBrowser = uninstallBrowser } = {}) {
|
|
35
|
-
const npx = await npxFolders()
|
|
46
|
+
export async function uninstall({ auth = false, looks = false, takes = false, scenarios = false, dryRun = false, removeBrowser = uninstallBrowser } = {}) {
|
|
47
|
+
const npx = await npxFolders();
|
|
36
48
|
const removed = [], kept = [];
|
|
37
49
|
const remove = async (item, paths) => {
|
|
38
50
|
for (const path of paths) {
|
|
@@ -47,16 +59,17 @@ export async function uninstall({ auth = false, looks = false, dryRun = false, r
|
|
|
47
59
|
if (browser.existed && dryRun) removed.push({ item: 'browser', path: browser.path, note: 'kept if another Playwright installation still uses it' });
|
|
48
60
|
else if (browser.removed) removed.push({ item: 'browser', path: browser.path });
|
|
49
61
|
else if (browser.existed) kept.push({ item: 'browser', path: browser.path, reason: 'another Playwright installation still uses it' });
|
|
50
|
-
|
|
62
|
+
const kinds = [['Auth profile', '--auth', auth, await authProfileFiles()], ['Look', '--looks', looks, await userLookFiles()], ['Take', '--takes', takes, await userTakes()], ['Scenario', '--scenarios', scenarios, await userScenarios()]];
|
|
63
|
+
for (const [item, flag, wanted, { dir, paths, folders = [] }] of kinds) {
|
|
51
64
|
if (wanted) await remove(item, paths);
|
|
52
65
|
else if (paths.length) kept.push({ item, path: dir, count: paths.length, reason: `pass ${flag} to remove` });
|
|
53
|
-
if (wanted && !dryRun) await fs.rmdir(
|
|
66
|
+
if (wanted && !dryRun) for (const folder of [...folders, dir]) await fs.rmdir(folder).catch(() => {});
|
|
54
67
|
}
|
|
55
68
|
// This CLI's own npx folder goes last, once nothing else needs its files.
|
|
56
69
|
await remove('npx cache', npx.filter(path => path === own));
|
|
57
|
-
if (!dryRun) await fs.rmdir(
|
|
70
|
+
if (!dryRun) await fs.rmdir(userHome()).catch(() => {});
|
|
58
71
|
return {
|
|
59
72
|
dryRun, [dryRun ? 'wouldRemove' : 'removed']: removed, kept,
|
|
60
|
-
note: '
|
|
73
|
+
note: 'Every project Home (.cuetake in a project) stays. The skill is removed by the tool that installed it.',
|
|
61
74
|
};
|
|
62
75
|
}
|