Video as code: canvas scenes rendered with WebCodecs in headless Chrome, a review viewer, and agent skills that build the video from your references.
Transitions rebuild a lost WebGL context; doctor prints the full pip path
StaryOnef8d9c446493b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 601fccf..1ec046e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,8 +9,9 @@ Changes are listed by release, newest first. The sections dated before 0.1.0 rec- `npm install -g @motlab/cli` gave no working `motlab` command under nvm for Windows 2.0, whose shim mode keeps npm's global folder off PATH, and the README's next step, `motlab setup`, failed there with "not recognized". Setup now notices when npm's command folder is not on PATH and writes the same `motlab` launcher to `~/.local/bin` that the clone installer writes, pointing at the engine in npm's folder, and prints the line that adds `~/.local/bin` to PATH when it is missing. `motlab uninstall` removes it, and an update with `npm install -g @motlab/cli@latest` keeps it working. Where npm's folder is on PATH nothing changes.- Setup run from npx's cache, with no global install, stops and says to install first instead of copying skills from a folder npx may clear.- When mediabunny is not installed, as in a clone where `npm ci` was never run, the renderer said only that the page "failed to fetch dynamically imported module ... mediabunny.mjs" before it fell back to the raw bitstream. It now says mediabunny is not installed and to run `npm ci` in the engine folder. Seen on a Linux VPS where the tests ran in a fresh clone; checked on Windows with a copy of the engine that has no `node_modules`.-- A scene transition whose WebGL context was lost failed with "transition fade: null", because the shader logs come back empty then. It now says the context was lost and to render again. Seen once on CI's Ubuntu runner, where Chrome draws with SwiftShader, and passed when the job ran again; the message was checked by losing the context on purpose with `WEBGL_lose_context`.+- A scene transition whose WebGL context was lost failed with "transition fade: null", because the shader logs come back empty then. It happened twice in three CI runs on the Ubuntu runner, where Chrome draws with SwiftShader, at the first shader compile. The mixer now builds a new canvas and context and draws the frame again, and only a second loss stops the render, with a message that says so. A loss that draws nothing without an error is caught too, by checking the context after the draw. Checked in Chrome on Windows with `WEBGL_lose_context`: a context lost once drew the frame (the right colour), one lost every time stopped with the message, and a normal one drew as before. Why the runner loses the context was not found; a GPU watchdog during a slow software compile is a guess.- `motlab doctor` reported mediabunny missing when npm put it next to the engine folder instead of inside it, as npx does. It now finds it the way the server does, through Node's module resolution.+- `motlab doctor` told a user missing Python packages to run `pip install -r skills/motlab/requirements.txt`, a path that only works from a clone. It now prints the full path. Seen on the Linux VPS after an npm install.### Changed@@ -20,7 +21,7 @@ Changes are listed by release, newest first. The sections dated before 0.1.0 recTo tell whether npm's folder is on the user's PATH, setup (`src/userpath.js`) drops the folders a Node process sees in front of it that the terminal does not have. npx adds its `node_modules/.bin` folders, node-gyp-bin and Node's own folder once; on Windows, nvm 2.0's shim also puts Node's folder first, and under nvm that is npm's global folder, so there every leading copy goes. On macOS and Linux, nvm puts Node's folder first in the terminal itself, so only the copy npx added goes. A first version dropped every copy on all systems, which would have written an unneeded launcher under nvm on Linux; seven PATH cases in `test/install.test.js` (Linux nvm directly and through npx, Linux system Node, a folder really off PATH, nvm for Windows directly and through npx, Node from nodejs.org) now cover it on the CI runners.-Tried on Windows 11 with the packed tarball in separate npm folders and home folders: npm's folder off PATH (launcher written, `motlab --help` through it, uninstall removed it), on PATH (no launcher), from a copy laid out like npx's cache (stops, exit 1), and over a clone's launcher (dry run: replaced, naming what it ran). With nvm for Windows 2.0 and this laptop's own PATH, the README's two commands: `npm install -g` of the 0.2.1 tarball, then `npx @motlab/cli setup` from a test home wrote the launcher, `motlab --help` and `update` ran through it; with npm's folder added to PATH no launcher was written. `doctor` found mediabunny inside the engine folder and next to it, and failed with it gone. Not tried: macOS and Linux.+Tried on Windows 11 with the packed tarball in separate npm folders and home folders: npm's folder off PATH (launcher written, `motlab --help` through it, uninstall removed it), on PATH (no launcher), from a copy laid out like npx's cache (stops, exit 1), and over a clone's launcher (dry run: replaced, naming what it ran). With nvm for Windows 2.0 and this laptop's own PATH, the README's two commands: `npm install -g` of the 0.2.1 tarball, then `npx @motlab/cli setup` from a test home wrote the launcher, `motlab --help` and `update` ran through it; with npm's folder added to PATH no launcher was written. `doctor` found mediabunny inside the engine folder and next to it, and failed with it gone. On a Linux VPS (Ubuntu, Xeon Platinum 8255C, 2 cores, 8 GB, no GPU, Node 24.22.3 with npm's prefix in `~/.npm-global`): `npx @motlab/cli setup --skill none` wrote no launcher, `which motlab` found npm's own command, `doctor` was ready, the example rendered at 960x540 with SwiftShader and the software H.264 encoder (about 180 to 215 fps, 1.5 to 2.3 s a scene), and after `npm ci` in a clone `npm test` passed. Not tried: macOS, and nvm on Linux outside the tests.## 0.2.0 (2026-11-17)diff --git a/docs/install.md b/docs/install.mdindex 6d706dc..51350a1 100644--- a/docs/install.md+++ b/docs/install.md@@ -27,7 +27,7 @@ Google Chrome on Debian or Ubuntu (x64), the command `motlab doctor` prints whenwget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && sudo apt install -y ./google-chrome-stable_current_amd64.deb```-The skill's scripts need numpy, scipy and Pillow:+The skill's scripts need numpy, scipy and Pillow. From the engine folder (`motlab --help` prints it; `motlab doctor` prints this command with the full path when they are missing):```bashpython -m pip install -r skills/motlab/requirements.txtdiff --git a/src/doctor.js b/src/doctor.jsindex 8542e32..4973837 100644--- a/src/doctor.js+++ b/src/doctor.js@@ -2,6 +2,7 @@// It never installs anything. The installer (install.js) runs the same checks.import { spawnSync } from 'node:child_process';import { createRequire } from 'node:module';+import { fileURLToPath } from 'node:url';import { findChrome } from './chrome.js';// Found the way the server finds it: npm may put it inside the engine folder (a clone, a global install) or next to it.@@ -44,7 +45,7 @@ export function checks() {if (py) {const missing = ['numpy', 'scipy', 'PIL'].filter(m => run(py.p, ['-c', `import ${m}`]) === null);out.push({ name: 'Python packages (numpy, scipy, Pillow)', ok: !missing.length, optional: true, detail: missing.length ? `missing: ${missing.join(', ')}` : '',- fix: `${py.p} -m pip install -r skills/motlab/requirements.txt` });+ fix: `${py.p} -m pip install -r "${fileURLToPath(new URL('../skills/motlab/requirements.txt', import.meta.url))}"` }); // the full path: an npm install is not the current folder}return out;}diff --git a/src/page/transitions.js b/src/page/transitions.jsindex 3d286f9..e79adf3 100644--- a/src/page/transitions.js+++ b/src/page/transitions.js@@ -57,56 +57,68 @@ void main() { gl_FragColor = transition(vUv); }`;// One WebGL canvas that mixes two canvases (or images, or video frames). draw() returns that canvas; copy it onto// the frame with drawImage right away.export function createMixer() {- const cv = document.createElement('canvas');- const gl = cv.getContext('webgl2', { premultipliedAlpha: false, preserveDrawingBuffer: true, antialias: false });- if (!gl) throw new Error('scene transitions need WebGL2');- const programs = new Map(), textures = [gl.createTexture(), gl.createTexture()];- for (const t of textures) {- gl.bindTexture(gl.TEXTURE_2D, t);- for (const [k, v] of [[gl.TEXTURE_MIN_FILTER, gl.LINEAR], [gl.TEXTURE_MAG_FILTER, gl.LINEAR], [gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE], [gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE]]) gl.texParameteri(gl.TEXTURE_2D, k, v);- }- gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW); // one triangle over the frame- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);-+ let cv, gl, programs, textures;// A lost context makes every WebGL call fail and the info logs come back null ("transition fade: null"). It happened- // once on a GPU-less CI runner, where Chrome draws with SwiftShader; render again.- const lost = () => { if (gl.isContextLost()) throw new Error("scene transitions lost their WebGL context (Chrome's GPU process restarted); render again"); };+ // on the GPU-less Ubuntu CI runner, where Chrome draws with SwiftShader, at the first shader compile. draw() then+ // builds a new canvas and context and tries the frame once more.+ function init() {+ cv = document.createElement('canvas');+ gl = cv.getContext('webgl2', { premultipliedAlpha: false, preserveDrawingBuffer: true, antialias: false });+ if (!gl) throw new Error('scene transitions need WebGL2');+ programs = new Map(); textures = [gl.createTexture(), gl.createTexture()];+ for (const t of textures) {+ gl.bindTexture(gl.TEXTURE_2D, t);+ for (const [k, v] of [[gl.TEXTURE_MIN_FILTER, gl.LINEAR], [gl.TEXTURE_MAG_FILTER, gl.LINEAR], [gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE], [gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE]]) gl.texParameteri(gl.TEXTURE_2D, k, v);+ }+ gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW); // one triangle over the frame+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);+ }+ init();function program(name) {if (programs.has(name)) return programs.get(name);- lost();const t = findTransition(name), p = gl.createProgram();for (const [type, src] of [[gl.VERTEX_SHADER, VERT], [gl.FRAGMENT_SHADER, frag(t.glsl)]]) {const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s);- if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) { lost(); throw new Error(`transition ${t.name}: ${gl.getShaderInfoLog(s)}`); }+ if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(`transition ${t.name}: ${gl.getShaderInfoLog(s)}`);gl.attachShader(p, s);}gl.bindAttribLocation(p, 0, 'p'); gl.linkProgram(p);- if (!gl.getProgramParameter(p, gl.LINK_STATUS)) { lost(); throw new Error(`transition ${t.name}: ${gl.getProgramInfoLog(p)}`); }+ if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(`transition ${t.name}: ${gl.getProgramInfoLog(p)}`);const entry = { p, t, u: n => gl.getUniformLocation(p, n) };programs.set(name, entry); return entry;}+ function drawOnce(name, from, to, progress, params) {+ const w = from.width, h = from.height;+ if (cv.width !== w || cv.height !== h) { cv.width = w; cv.height = h; }+ const { p, t, u } = program(name);+ gl.viewport(0, 0, w, h); gl.useProgram(p);+ [from, to].forEach((img, i) => { gl.activeTexture(gl.TEXTURE0 + i); gl.bindTexture(gl.TEXTURE_2D, textures[i]); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img); });+ gl.uniform1i(u('uFrom'), 0); gl.uniform1i(u('uTo'), 1); gl.uniform1f(u('progress'), progress); gl.uniform1f(u('ratio'), w / h);+ for (const [k, type] of Object.entries(t.types)) {+ const v = params[k] ?? t.defaults[k], loc = u(k);+ if (loc === null || v === undefined) continue;+ if (type === 'float') gl.uniform1f(loc, v);+ else if (type === 'bool' || type === 'int') gl.uniform1i(loc, Number(v));+ else gl[`uniform${type.slice(3)}fv`](loc, v); // vec2, vec3, vec4+ }+ gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);+ gl.drawArrays(gl.TRIANGLES, 0, 3);+ return cv;+ }+return {- canvas: cv,+ get canvas() { return cv; },+ // A context lost mid-frame throws from a compile or draws nothing, so both are checked; a second loss is reported.draw(name, from, to, progress, params = {}) {- const w = from.width, h = from.height;- if (cv.width !== w || cv.height !== h) { cv.width = w; cv.height = h; }- const { p, t, u } = program(name);- gl.viewport(0, 0, w, h); gl.useProgram(p);- [from, to].forEach((img, i) => { gl.activeTexture(gl.TEXTURE0 + i); gl.bindTexture(gl.TEXTURE_2D, textures[i]); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img); });- gl.uniform1i(u('uFrom'), 0); gl.uniform1i(u('uTo'), 1); gl.uniform1f(u('progress'), progress); gl.uniform1f(u('ratio'), w / h);- for (const [k, type] of Object.entries(t.types)) {- const v = params[k] ?? t.defaults[k], loc = u(k);- if (loc === null || v === undefined) continue;- if (type === 'float') gl.uniform1f(loc, v);- else if (type === 'bool' || type === 'int') gl.uniform1i(loc, Number(v));- else gl[`uniform${type.slice(3)}fv`](loc, v); // vec2, vec3, vec4+ for (let tries = 0; tries < 2; tries++) {+ try { const out = drawOnce(name, from, to, progress, params); if (!gl.isContextLost()) return out; }+ catch (e) { if (!gl.isContextLost()) throw e; }+ if (tries === 0) init();}- gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);- gl.drawArrays(gl.TRIANGLES, 0, 3);- return cv;+ throw new Error("scene transitions lost their WebGL context twice (Chrome's GPU process restarted); render again");},};}