Skip to content

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 adds the motlab command when npm's folder is off PATH (0.2.1)

StaryOne984fcea1c212
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 207bbf1..14fd631 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,22 @@
Changes are listed by release, newest first. The sections dated before 0.1.0 record what was built on the way to the first release.
+## 0.2.1 (not released yet)
+
+### Fixed
+
+- `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.
+- `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.
+
+### Changed
+
+- 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.
+
+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.
+
## 0.2.0 (2026-11-17)
### Added
diff --git a/README.md b/README.md
index f977f0e..a34047f 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
A video engine where every scene is code, and an agent skill that writes the scenes for you.
-<code>npm install -g @motlab/cli && motlab setup</code>
+<code>npm install -g @motlab/cli && npx @motlab/cli setup</code>
[Demo](#watch-the-demo) · [Install](#install) · [Quick start](#quick-start) · [Speed](#speed) · [How it works](#how-it-works) · [Docs](#documentation) · [FAQ](#faq) · [Roadmap](ROADMAP.md)
@@ -46,10 +46,10 @@ You need Node 24 or newer, Google Chrome or Chromium, and ffmpeg with ffprobe on
```bash
npm install -g @motlab/cli
-motlab setup
+npx @motlab/cli setup
```
-npm installs the engine and the `motlab` command. `motlab setup` copies both skills to `~/.claude/skills/` and checks the machine; `motlab doctor` checks it again at any time.
+npm installs the engine. Setup copies both skills to `~/.claude/skills/`, checks the machine, and makes sure the `motlab` command works: where npm's folder is not on PATH (nvm for Windows), it adds the command to `~/.local/bin`. After that it is `motlab` everywhere, and `motlab doctor` checks the machine again at any time.
<details><summary>Skills for other agents, and the other options</summary>
@@ -74,7 +74,7 @@ cd motlab
node install.js
```
-The installer runs `npm ci`, puts a `motlab` command in `~/.local/bin` and copies the skills. It takes the same options, plus `--skill none` for no skills. Use it too when npm's global folder is not on PATH. With nvm for Windows 2.0 it is not, and `npm config set prefix "%APPDATA%\npm"` before the npm install fixes that instead ([details](docs/install.md#from-npm)).
+The installer runs `npm ci`, puts a `motlab` command in `~/.local/bin` and copies the skills. It takes the same options, plus `--skill none` for no skills.
</details>
diff --git a/docs/cli.md b/docs/cli.md
index 278bb8f..de5aa26 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -9,7 +9,7 @@ motlab stills <page.html> <outDir> <t1> <t2> ... single frames as PNG or JPEG
motlab video <page.html> <out.mp4> [options] one page as an MP4
motlab events <page.html> <out.json> the page's EVENTS, for syncing sound
motlab doctor check Node, Chrome, ffmpeg and the skill's Python packages
-motlab setup [--skill <target>] [--update] ... copy the skills to agent folders, after npm install -g
+motlab setup [--skill <target>] [--update] ... copy the skills to agent folders after npm install -g, and add the command if needed
motlab update [--dry-run] the newest motlab (from GitHub, or the npm commands that get it), and the skills copied again where they were installed
motlab uninstall [--dry-run] [--yes] remove the skills, ~/.motlab, the encoder cache and a clone's command
```
diff --git a/docs/install-for-agents.md b/docs/install-for-agents.md
index 8faa37e..4663152 100644
--- a/docs/install-for-agents.md
+++ b/docs/install-for-agents.md
@@ -14,17 +14,17 @@ Node must be 24 or newer. If Node is missing or older, tell the user and give th
## 2. npm or a clone
-Ask which they want. npm is simpler for using motlab; a clone is for working on it, or for a machine where `npm prefix -g` is not on PATH (with nvm for Windows 2.0 it is not; `npm config set prefix "%APPDATA%\npm"` fixes it, but it moves every global package, so ask first).
+Ask which they want. npm is simpler for using motlab; a clone is for working on it.
With npm, pick the skill target as in step 3, then:
```bash
npm install -g @motlab/cli
-motlab setup --skill <target> --dry-run
-motlab setup --skill <target>
+npx @motlab/cli setup --skill <target> --dry-run
+npx @motlab/cli setup --skill <target>
```
-`motlab setup` takes the same skill options as the installer and runs `motlab doctor` at the end. If `motlab` is not found after the npm install, show the user `npm prefix -g` and ask before changing their PATH. To update later, `motlab update` prints the two commands (`npm install -g @motlab/cli@latest`, then `motlab setup --update`). Then skip to step 4.
+Setup takes the same skill options as the installer and runs `motlab doctor` at the end. When npm's command folder is not on PATH (nvm for Windows), it writes a `motlab` launcher to `~/.local/bin`; if it then prints that `~/.local/bin` is not on PATH, show the user the line and ask before changing their PATH. To update later, `motlab update` prints the two commands (`npm install -g @motlab/cli@latest`, then `motlab setup --update`). Then skip to step 4.
## Get the repository
diff --git a/docs/install.md b/docs/install.md
index 0b39bc4..43c5ebc 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -31,12 +31,14 @@ python -m pip install -r skills/motlab/requirements.txt
```bash
npm install -g @motlab/cli
-motlab setup
+npx @motlab/cli setup
```
-npm installs the engine and its one dependency and makes the `motlab` command. `motlab setup` copies both skills to an agent skill folder (Claude Code by default) and runs `motlab doctor`. It takes the skill options of the installer below: `--skill`, `--skill-dir`, `--link`, `--update`, `--force` and `--dry-run`, so `motlab setup --skill claude,agents` puts the skills in two places. The engine folder is inside npm's global folder; `motlab --help` prints it, and the example project is in it.
+npm installs the engine and its one dependency and makes the `motlab` command. Setup copies both skills to an agent skill folder (Claude Code by default) and runs `motlab doctor`. It takes the skill options of the installer below: `--skill`, `--skill-dir`, `--link`, `--update`, `--force` and `--dry-run`, so `npx @motlab/cli setup --skill claude,agents` puts the skills in two places. It is run through npx because `motlab` may not be on PATH yet; npx runs the installed package and downloads nothing. Once the command works, `motlab setup` is the same. The engine folder is inside npm's global folder; `motlab --help` prints it, and the example project is in it.
-The command only works if npm's global folder is on PATH. `npm prefix -g` prints that folder (on Windows the command goes in it, elsewhere in its `bin`). With the Node installer from nodejs.org or Homebrew it is on PATH already. With nvm for Windows 2.0 in its default shim mode it is not: npm puts the command in the Node version's own folder (`installs\v24.x`), and nvm's `.shim` folder only holds the shims nvm ships with (node, npm, npx, pnpm, corepack, codex), so `motlab` is not found. Point npm's global folder at one that is on PATH, once, before installing:
+The command only works if npm's global folder is on PATH. `npm prefix -g` prints that folder (on Windows the command goes in it, elsewhere in its `bin`). With the Node installer from nodejs.org or Homebrew it is on PATH already. With nvm for Windows 2.0 in its default shim mode it is not: npm puts the command in the Node version's own folder (`installs\v24.x`), and nvm's `.shim` folder only holds the shims nvm ships with (node, npm, npx, pnpm, corepack, codex), so `motlab` is not found. Setup sees this and writes its own `motlab` launcher to `~/.local/bin`, as the clone installer does (`--bin <dir>` puts it elsewhere), and prints the line that adds that folder to PATH if it is not there. The launcher runs the engine in npm's folder, so `npm install -g @motlab/cli@latest` updates it, and `motlab uninstall` removes it. An older launcher there, from a clone, is replaced, and setup says what it ran.
+
+Instead of the launcher, npm's global folder can point at one that is on PATH, once, before installing:
```bash
npm config set prefix "%APPDATA%\npm"
@@ -44,7 +46,7 @@ npm config set prefix "%APPDATA%\npm"
In PowerShell write `"$env:APPDATA\npm"`. `%APPDATA%\npm` is npm's usual global folder on Windows and is often on PATH from an earlier Node install; `where npm` lists it if so, otherwise add it to PATH. This changes where every global package goes, not only motlab, and the packages there are shared by all Node versions. `motlab update` keeps working, because its `npm install -g` follows the same setting. The clone below also works there, since its installer writes its own launcher.
-This was tested on Windows 11, from the registry and from a packed tarball, each installed into a separate npm folder: `setup`, `update`, `uninstall` and a render of the example. It was also installed globally with nvm for Windows 2.0: into the nvm folder the command was not found, and with the prefix in `%APPDATA%\npm` it was (`--help` and `update`). It has not been tried on macOS or Linux.
+This was tested on Windows 11, from the registry and from a packed tarball, each installed into a separate npm folder: `setup`, `update`, `uninstall` and a render of the example. It was also installed globally with nvm for Windows 2.0: `npx @motlab/cli` ran the installed package from the nvm folder, setup wrote the launcher when that folder was off PATH and none when it was on PATH, and with the prefix in `%APPDATA%\npm` the command was found without one. It has not been tried on macOS or Linux.
## With the installer
@@ -74,7 +76,7 @@ Options:
| `--bin <dir>` | put the launcher somewhere else |
| `--update` | the skills again in every folder from `~/.motlab/install.json`, and in any folder from the table below that already has the motlab skill (an install from before that file). `--skill` and `--skill-dir` add folders. `motlab update` runs this |
| `--force` | replace a folder at a skill path that has no `SKILL.md` |
-| `--skills-only` | the skills and `motlab doctor` only: no `npm ci` and no launcher. `motlab setup` runs this |
+| `--skills-only` | the skills and `motlab doctor`, no `npm ci`, and a launcher only for an npm install whose command folder is not on PATH. `motlab setup` runs this |
| `--dry-run` | print every step and change nothing |
Skill targets. Each one is the agent's user skill folder, as its docs gave it in November 2026:
diff --git a/install.js b/install.js
index 934fec2..ad3a53a 100644
--- a/install.js
+++ b/install.js
@@ -9,8 +9,8 @@
// node install.js --bin <dir> where the `motlab` command goes (default ~/.local/bin)
// node install.js --dry-run print what would happen and change nothing
// node install.js --update the skills again where they went last time (what `motlab update` runs)
-// node install.js --skills-only only the skills: no npm ci and no launcher (what `motlab setup` runs after
-// `npm install -g @motlab/cli`, where npm made the command)
+// node install.js --skills-only the skills, no npm ci (what `motlab setup` runs after `npm install -g
+// @motlab/cli`); a launcher only when npm's command folder is not on PATH
//
// Where the skills, the launcher and --link went is kept in ~/.motlab/install.json for --update. It never installs
// Chrome, ffmpeg or Python; it says how to get them.
@@ -64,16 +64,33 @@ if (!only && !dry) {
}
// 2. the `motlab` command: small launchers that run this folder's bin/motlab.js
-// With --skills-only npm made the command, and the record keeps the launcher folder of a clone install, if there was one.
-const bin = only ? prev.bin : resolve(o.bin || last.bin || join(HOME, '.local', 'bin')), entry = join(HERE, 'bin', 'motlab.js');
+// 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 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;
+const needLaunchers = !only || (fromNpm && !onPathDir(npmBin));
+if (only && needLaunchers) console.log(`npm put the motlab command in ${resolve(npmBin)}, which is not on PATH, so motlab writes its own.`);
+const bin = needLaunchers ? resolve(o.bin || last.bin || prev.bin || join(HOME, '.local', 'bin')) : prev.bin, entry = join(HERE, 'bin', 'motlab.js');
const launchers = WIN
? [['motlab.cmd', `@node "${entry}" %*\r\n`], ['motlab', `#!/bin/sh\nexec node "${entry.replaceAll('\\', '/')}" "$@"\n`]] // cmd/PowerShell, Git Bash
: [['motlab', `#!/bin/sh\nexec node "${entry}" "$@"\n`]];
-if (!only) for (const [name, body] of launchers) {
- say(`write ${join(bin, name)}`);
+if (needLaunchers) for (const [name, body] of launchers) {
+ let old = ''; try { old = readFileSync(join(bin, name), 'utf8'); } catch {}
+ say(old && old !== body ? `replace ${join(bin, name)} (it ran ${(/"([^"]+motlab\.js)"/.exec(old) || [, 'something else'])[1]})` : `write ${join(bin, name)}`);
if (!dry) { mkdirSync(bin, { recursive: true }); writeFileSync(join(bin, name), body); if (!WIN) chmodSync(join(bin, name), 0o755); }
}
-const onPath = only || (process.env.PATH || '').split(delimiter).some(p => p && resolve(p).toLowerCase() === bin.toLowerCase());
+const onPath = !needLaunchers || onPathDir(bin);
if (!onPath) console.log(`\n${bin} is not on PATH yet. Add it, then open a new terminal:\n ${WIN
? `[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', 'User') + ';${bin}', 'User') (PowerShell)`
: `echo 'export PATH="${bin}:$PATH"' >> ~/.profile`}\n`);
diff --git a/package-lock.json b/package-lock.json
index cd72991..7d79b0f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@motlab/cli",
- "version": "0.2.0",
+ "version": "0.2.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@motlab/cli",
- "version": "0.2.0",
+ "version": "0.2.1",
"license": "MIT",
"dependencies": {
"mediabunny": "1.65.2"
diff --git a/package.json b/package.json
index 79ebce9..b4181e9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@motlab/cli",
- "version": "0.2.0",
+ "version": "0.2.1",
"description": "Video as code: canvas scene pages rendered frame by frame in headless Chrome with WebCodecs, a project format with audio, a web viewer, and an agent skill that builds the scenes.",
"license": "MIT",
"author": "StaryOne",
diff --git a/skills/motlab/SKILL.md b/skills/motlab/SKILL.md
index 6d02a64..65d33a8 100644
--- a/skills/motlab/SKILL.md
+++ b/skills/motlab/SKILL.md
@@ -27,8 +27,8 @@ your own work) and `motlab events` are fine. Render only if the user asks for it
`motlab` is a command on PATH. Run `motlab --help` once at the start: it lists the commands and prints the engine
folder (its README, the `example/` project and `src/page/footage.js`).
-If `motlab` is not found, ask the user how they installed it. From npm (`npm install -g @motlab/cli`), npm's
-global folder (`npm prefix -g`) is probably not on PATH; show them that and ask before changing PATH. From a clone (the
+If `motlab` is not found, ask the user how they installed it. From npm (`npm install -g @motlab/cli`), run
+`npx @motlab/cli setup --skill none`; it adds the command when npm's folder is not on PATH. From a clone (the
folder with `install.js` and `bin/motlab.js`), run `node install.js --skill none` there; it puts the command on PATH.
If they have neither, follow `docs/install-for-agents.md` from https://github.com/staryone/motlab. Until the command is on PATH, call
`node <engine>/bin/motlab.js`. Never hard-code the engine path anywhere else. If a render or still fails because Chrome
diff --git a/src/cli.js b/src/cli.js
index a56961f..623beb7 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -24,7 +24,8 @@ const USAGE = `motlab: render a canvas page (canvas #c, renderAt(t), TOTAL, read
motlab doctor check Node, Chrome, ffmpeg and the skill's Python packages
motlab setup [--skill claude|agents|antigravity|...] [--skill-dir <dir>] [--link] [--update] [--dry-run]
copy the skills to agent folders (after npm install -g; default
- Claude Code). --update copies them again where they went before
+ Claude Code), and add the command when npm's folder is not on
+ PATH. --update copies them again where they went before
motlab update [--dry-run] the newest motlab from GitHub, its npm packages, and the skills
copied again to every agent folder they were installed in (for an
npm install it says which version is out and how to get it)
diff --git a/src/doctor.js b/src/doctor.js
index 6351618..6b4f1c9 100644
--- a/src/doctor.js
+++ b/src/doctor.js
@@ -1,9 +1,12 @@
// `motlab doctor`: checks what the engine and the skill need on this machine and says how to get what is missing.
// It never installs anything. The installer (install.js) runs the same checks.
import { spawnSync } from 'node:child_process';
-import { existsSync } from 'node:fs';
+import { createRequire } from 'node:module';
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.
+const hasMediabunny = () => { try { createRequire(import.meta.url).resolve('mediabunny'); return true; } catch { return false; } };
+
const run = (cmd, args) => {
const r = spawnSync(cmd, args, { encoding: 'utf8', shell: false });
return r.status === 0 ? (r.stdout || r.stderr).trim() : null;
@@ -29,7 +32,7 @@ export function checks() {
const v = firstLine(run(tool, ['-version']));
out.push({ name: tool, ok: !!v, detail: v ? v.replace(/ Copyright.*/, '') : 'not on PATH', fix: hint.ffmpeg });
}
- out.push({ name: 'npm packages (mediabunny)', ok: existsSync(new URL('../node_modules/mediabunny/package.json', import.meta.url)), detail: '', fix: 'run npm ci in the engine folder' });
+ out.push({ name: 'npm packages (mediabunny)', ok: hasMediabunny(), detail: '', fix: 'run npm ci in the engine folder' });
// Python is only for the skill's helper scripts (contact sheets, sound effects, mixing, fonts).
const py = ['python3', 'python'].map(p => ({ p, v: firstLine(run(p, ['--version'])) })).find(x => x.v && /Python 3/.test(x.v));
diff --git a/test/install.test.js b/test/install.test.js
index a8c109c..ca6dd02 100644
--- a/test/install.test.js
+++ b/test/install.test.js
@@ -1,8 +1,8 @@
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
-import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { cpSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { join } from 'node:path';
+import { delimiter, join } from 'node:path';
import { test } from 'node:test';
// `motlab update` runs `install.js --update`, which has to find every folder the skills went to: the ones in
@@ -64,3 +64,25 @@ test('motlab setup copies the skills and nothing else', () => {
assert.ok(!/npm ci|write .*motlab/.test(r.stdout), r.stdout);
} finally { rmSync(home, { recursive: true, force: true }); }
});
+
+// After `npm install -g`, setup writes its own launcher only when npm's command folder is not on PATH (nvm for
+// Windows 2.0 keeps it off). The package is laid out as npm lays out a global install: <prefix>\node_modules\@motlab\cli
+// on Windows, <prefix>/lib/node_modules/@motlab/cli with the command in <prefix>/bin elsewhere.
+test('setup from an npm install adds the command only when npm put it off PATH', () => {
+ const root = mkdtempSync(join(tmpdir(), 'motlab-npm-'));
+ try {
+ const win = process.platform === 'win32';
+ 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'));
+ 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);
+ assert.equal(off.status, 0, off.stderr);
+ assert.ok(off.stdout.includes('which is not on PATH') && off.stdout.includes(`write ${join(root, '.local', 'bin', 'motlab')}`), off.stdout);
+ const on = run([process.env.PATH, npmBin].join(delimiter));
+ assert.equal(on.status, 0, on.stderr);
+ assert.ok(!/write|not on PATH/.test(on.stdout), on.stdout);
+ } finally { rmSync(root, { recursive: true, force: true }); }
+});