Video as code: canvas scenes rendered with WebCodecs in headless Chrome, a review viewer, and agent skills that build the video from your references.
setup: keep Node's folder on PATH under nvm on macOS and Linux
StaryOnec546e33c84f7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9e4cb72..601fccf 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,7 +18,7 @@ Changes are listed by release, newest first. The sections dated before 0.1.0 rec- The README's install section lists the setup command for each agent (Claude Code, the agents that read `~/.agents/skills`, Antigravity, several at once, any other folder) instead of a folded list of options.- The README and the install docs run setup as `npx @motlab/cli setup`, which works before `motlab` is on PATH; npx runs the installed package and downloads nothing.-To tell whether npm's folder is on the user's PATH, setup drops the folders a Node process sees in front of it that the terminal does not have: nvm's shim puts Node's own folder first, and npx adds its `node_modules\.bin` folders, node-gyp-bin and Node's folder again. Under nvm, Node's folder is npm's global folder, so without this the check always passed. `test/install.test.js` covers both cases on the CI runners.+To 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.diff --git a/install.js b/install.jsindex ad3a53a..90a8e6c 100644--- a/install.js+++ b/install.js@@ -17,9 +17,10 @@import { spawnSync } from 'node:child_process';import { chmodSync, cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';import { homedir } from 'node:os';-import { delimiter, dirname, join, resolve } from 'node:path';+import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { parseArgs } from 'node:util';+import { onUserPath } from './src/userpath.js';const HERE = dirname(fileURLToPath(import.meta.url)), WIN = process.platform === 'win32', HOME = homedir();// Each agent's user skill folder, from its docs (November 2026). ~/.agents/skills is the shared one: Codex reads only that,@@ -67,15 +68,7 @@ if (!only && !dry) {// With --skills-only from an npm install, npm made the command in its global folder: <prefix> on Windows, <prefix>/bin// elsewhere. nvm for Windows 2.0 keeps that folder off PATH (its .shim folder only has the shims nvm ships with), so// then the launchers are written as for a clone. From npx's cache there is no install to point a launcher at.-// PATH here can start with folders the user's terminal does not have: nvm's shim puts Node's own folder first (under-// nvm that is npm's global folder), and npx adds node_modules\.bin folders, node-gyp-bin and Node's folder again. That-// leading run is dropped, so the check sees the user's terminal. Where a user put Node's folder first themselves, setup-// writes a launcher it did not need, which runs the same package.-const same = (a, b) => resolve(a).toLowerCase() === resolve(b).toLowerCase();-let userPath = (process.env.PATH || '').split(delimiter).filter(Boolean), lead = 0;-while (lead < userPath.length && (/node_modules[\\/]\.bin$|node-gyp-bin$/i.test(userPath[lead]) || same(userPath[lead], dirname(process.execPath)))) lead++;-userPath = userPath.slice(lead);-const onPathDir = dir => userPath.some(p => same(p, dir));+const onPathDir = dir => onUserPath(dir); // the terminal's PATH, without what npx and nvm put in front (src/userpath.js)const nm = HERE.lastIndexOf(`node_modules`), fromNpm = only && nm > 0;if (fromNpm && /[\\/]_npx[\\/]/.test(HERE)) { console.error('motlab is not installed. Install it first, then run setup again:\n npm install -g @motlab/cli'); process.exit(1); }const npmBin = fromNpm ? (WIN ? HERE.slice(0, nm) : join(HERE.slice(0, nm), '..', 'bin')) : null;diff --git a/src/userpath.js b/src/userpath.jsnew file mode 100644index 0000000..27c564c--- /dev/null+++ b/src/userpath.js@@ -0,0 +1,21 @@+// Whether a folder is on the PATH of the user's terminal, seen from inside a Node process that npm or nvm started.+// That process's PATH can start with folders the terminal does not have: npx adds node_modules/.bin folders,+// node-gyp-bin and Node's own folder once, and on Windows nvm 2.0's shim also puts Node's folder first (under nvm that+// is npm's global folder), so there every leading copy is dropped. On macOS and Linux nvm puts Node's folder first in+// the terminal itself, so only the copy npx added is dropped. A Windows user who put Node's folder first themselves is+// told it is off PATH, and setup writes a launcher it did not need, which runs the same package.+import { posix, win32 } from 'node:path';++export function onUserPath(dir, { env = process.env, execPath = process.execPath, win = process.platform === 'win32' } = {}) {+ const P = win ? win32 : posix;+ const same = win ? (a, b) => P.resolve(a).toLowerCase() === P.resolve(b).toLowerCase() : (a, b) => P.resolve(a) === P.resolve(b);+ const path = (env.PATH || env.Path || '').split(P.delimiter).filter(Boolean), nodeDir = P.dirname(execPath);+ const npx = env.npm_command === 'exec';+ let lead = 0, nodeDirs = 0;+ for (; lead < path.length; lead++) {+ if (/node_modules[\\/]\.bin$|node-gyp-bin$/i.test(path[lead])) continue;+ if (same(path[lead], nodeDir) && (win || (npx && nodeDirs++ === 0))) continue;+ break;+ }+ return path.slice(lead).some(p => same(p, dir));+}diff --git a/test/install.test.js b/test/install.test.jsindex ca6dd02..a7d719f 100644--- a/test/install.test.js+++ b/test/install.test.js@@ -75,7 +75,7 @@ test('setup from an npm install adds the command only when npm put it off PATH',const pkg = win ? join(root, 'prefix', 'node_modules', '@motlab', 'cli') : join(root, 'prefix', 'lib', 'node_modules', '@motlab', 'cli');const npmBin = win ? join(root, 'prefix') : join(root, 'prefix', 'bin');mkdirSync(pkg, { recursive: true });- cpSync('install.js', join(pkg, 'install.js'));+ cpSync('install.js', join(pkg, 'install.js')); mkdirSync(join(pkg, 'src')); cpSync('src/userpath.js', join(pkg, 'src', 'userpath.js'));const run = path => spawnSync(process.execPath, [join(pkg, 'install.js'), '--skills-only', '--skill', 'none', '--dry-run'],{ encoding: 'utf8', env: { ...process.env, HOME: root, USERPROFILE: root, PATH: path } });const off = run(process.env.PATH);@@ -86,3 +86,20 @@ test('setup from an npm install adds the command only when npm put it off PATH',assert.ok(!/write|not on PATH/.test(on.stdout), on.stdout);} finally { rmSync(root, { recursive: true, force: true }); }});++// Seen from inside setup, PATH starts with what npx and nvm put in front of the terminal's. Linux and macOS cases are+// checked here on any machine; nvm for Windows 2.0 was also tried for real (CHANGELOG 0.2.1).+test('the PATH check sees the terminal, not what npx and nvm put in front', async () => {+ const { onUserPath } = await import('../src/userpath.js');+ const bins = ['/home/u/ex/node_modules/.bin', '/node_modules/.bin', '/x/node-gyp-bin'], binsW = ['C:/ex/node_modules/.bin', 'C:/x/node-gyp-bin'];+ const nvm = '/home/u/.nvm/versions/node/v24/bin', nvmW = 'C:/nvm/installs/v24', nodeW = 'C:/Program Files/nodejs';+ const on = (dir, PATH, execDir, { win = false, npx = false } = {}) =>+ onUserPath(dir, { win, env: { PATH: PATH.join(win ? ';' : ':'), ...(npx ? { npm_command: 'exec' } : {}) }, execPath: `${execDir}/node` });+ assert.equal(on(nvm, [nvm, '/usr/bin'], nvm), true, 'Linux nvm, setup run directly');+ assert.equal(on(nvm, [...bins, nvm, nvm, '/usr/bin'], nvm, { npx: true }), true, 'Linux nvm, through npx');+ assert.equal(on('/usr/local/bin', [...bins, '/usr/local/bin', '/usr/bin', '/usr/local/bin'], '/usr/local/bin', { npx: true }), true, 'Linux system Node, through npx');+ assert.equal(on('/opt/node/bin', [...bins, '/opt/node/bin', '/usr/bin'], '/opt/node/bin', { npx: true }), false, 'Linux, npm folder off PATH');+ assert.equal(on(nvmW, [nvmW, ...binsW, nvmW, 'C:/Users/u/bin'], nvmW, { win: true, npx: true }), false, 'nvm for Windows, through npx');+ assert.equal(on(nvmW, [nvmW, 'C:/Users/u/bin'], nvmW, { win: true }), false, 'nvm for Windows, run directly');+ assert.equal(on(nodeW, [...binsW, nodeW, 'C:/Windows', nodeW], nodeW, { win: true, npx: true }), true, 'Node from nodejs.org on Windows, through npx');+});