Skip to content

Turn one illustration into an animated 2D mesh avatar with a coding agent and a local editor

Add a setup command and an environment check

shinshin86af1c9d7ae73f
diff --git a/.changeset/setup-command.md b/.changeset/setup-command.md
new file mode 100644
index 0000000..42f5966
--- /dev/null
+++ b/.changeset/setup-command.md
@@ -0,0 +1,5 @@
+---
+'create-mesh-avatar-studio': minor
+---
+
+First release: `npx create-mesh-avatar-studio` downloads Mesh Avatar Studio, installs its packages and checks Node.js, uv, Python and Playwright Chromium, explaining what each missing tool is needed for.
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a4eb832..e9164b8 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -46,6 +46,9 @@ jobs:
- name: Check runtime package contents
run: npm pack --dry-run -w mesh-avatar
+ - name: Check the setup command package
+ run: npm pack --dry-run -w create-mesh-avatar-studio
+
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
diff --git a/README.ja.md b/README.ja.md
index c23a4e6..256c12c 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -11,20 +11,23 @@
## サンプルで試す
-Node.js 22.17 以上が必要です。
+Node.js 22.17 以上と Git が必要です。
```sh
-npm install
+npx create-mesh-avatar-studio
+cd mesh-avatar-studio
npm run dev
```
+最初のコマンドで、リポジトリのダウンロード、パッケージのインストール、必要なツールの確認までを行います。自分でリポジトリを取得した場合は、`npm install` のあとに `npm run doctor` を実行すると同じ確認ができます。エディタと配信画面に必要なのは Node.js だけです。uv と Python はレイヤーの作り直しに、Playwright の Chromium はエージェントがアバターを作るときの動きの確認に使います。足りないものは警告で知らせます。
+
ターミナルに表示された URL(例: `http://127.0.0.1:5173/`)をブラウザで開くと、同梱のサンプル(チャイナドレスのミコ)が表示されます。左の一覧からパーツを選び、画像の上の点をドラッグすると、右のプレビューに結果が反映されます。サンプルは読み取り専用なので、編集すると「コピーして編集を続ける」ボタンが出ます。押すと自分用のコピーで作業を続けられます。
### Windows で使うとき
リポジトリの取得には、できれば `git clone` を使ってください。ZIP を使う場合は、展開する前にエクスプローラーで ZIP のプロパティを開き、ブロック解除の項目があれば解除してください。
-エージェントに作業を頼む前に、自分の Windows アカウントで `projects/` フォルダを作っておいてください。別のアカウントやサンドボックス内で動くエージェントが作ったフォルダは、アクセス権限の違いでエディタから読めないことがあります。読めない場合は、フォルダの「プロパティ → セキュリティ」で、自分のアカウントにプロジェクト全体へのアクセス権限を付け直してください。中のファイルやサブフォルダにも権限が引き継がれるように設定します。
+エージェントに作業を頼む前に、自分の Windows アカウントで `projects/` フォルダを作っておいてください(`npx create-mesh-avatar-studio` を使った場合は作成済みです)。別のアカウントやサンドボックス内で動くエージェントが作ったフォルダは、アクセス権限の違いでエディタから読めないことがあります。読めない場合は、フォルダの「プロパティ → セキュリティ」で、自分のアカウントにプロジェクト全体へのアクセス権限を付け直してください。中のファイルやサブフォルダにも権限が引き継がれるように設定します。
## 使い方の流れ
diff --git a/README.md b/README.md
index ad1e66e..f154adf 100644
--- a/README.md
+++ b/README.md
@@ -14,13 +14,20 @@ To move it with your own face and voice without installing anything, open the
## Try the sample
-Requires Node.js 22.17+.
+Requires Node.js 22.17+ and Git.
```sh
-npm install
+npx create-mesh-avatar-studio
+cd mesh-avatar-studio
npm run dev
```
+The first command downloads the repository, installs its packages and checks the tools
+Studio needs. If you cloned the repository yourself, run `npm install`, then
+`npm run doctor` for the same check. Only Node.js is needed for the editor and the Live
+page. uv and Python rebuild layers, and Playwright Chromium renders the motion review when
+an agent creates an avatar; the check warns about each one that is missing.
+
Open the URL printed in the terminal (for example `http://127.0.0.1:5173/`). The editor opens
the bundled sample, Miko in a qipao. Pick a part on the left, drag its dots on the image and
watch the preview on the right. The sample is read-only; when you change it, choose
@@ -31,7 +38,8 @@ watch the preview on the right. The sample is read-only; when you change it, cho
Use `git clone` to download the repository when possible. If you use a ZIP, open its
Properties in File Explorer and select **Unblock**, if shown, before extracting it.
-Create `projects/` yourself under your Windows account before asking an agent to work in it.
+Create `projects/` yourself under your Windows account before asking an agent to work in it
+(`npx create-mesh-avatar-studio` creates it for you).
Folders created by another account or an agent running in a sandbox can have permissions
that prevent the editor from reading them. If a project cannot be read, use the folder's
**Properties → Security** settings to grant your account access to the whole project,
diff --git a/docs/agent-guide.md b/docs/agent-guide.md
index 19eccc6..8d4cd4a 100644
--- a/docs/agent-guide.md
+++ b/docs/agent-guide.md
@@ -11,7 +11,9 @@ quality of the result depends on looking at your own output and correcting it.
### Tools
Node.js 22.17+, Python 3.10+ with [uv](https://docs.astral.sh/uv/), and Playwright Chromium
-(`npx playwright install chromium`). Run `npm install` once.
+(`npx playwright install chromium`). Run `npm install` once, then `npm run doctor`: it reports
+each missing tool. Treat its warnings as blockers for this guide, since every step below needs
+uv, Python or Chromium.
### Model
Reading pixel coordinates from images needs strong vision. These setups are known to work:
diff --git a/package-lock.json b/package-lock.json
index b6860cf..01f8094 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2807,6 +2807,10 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/create-mesh-avatar-studio": {
+ "resolved": "packages/create-mesh-avatar-studio",
+ "link": true
+ },
"node_modules/cross-spawn": {
"version": "7.0.6",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
@@ -4973,9 +4977,19 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "packages/create-mesh-avatar-studio": {
+ "version": "0.0.0",
+ "license": "MIT",
+ "bin": {
+ "create-mesh-avatar-studio": "index.mjs"
+ },
+ "engines": {
+ "node": ">=22.17"
+ }
+ },
"packages/runtime": {
"name": "mesh-avatar",
- "version": "0.0.0",
+ "version": "0.2.0",
"license": "MIT",
"dependencies": {
"fflate": "^0.8.3"
diff --git a/package.json b/package.json
index 5ec6767..f7d339b 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
"preview:site": "vite preview --config site/vite.config.ts",
"screenshots": "node tools/capture-readme-screenshots.mjs",
"test": "vitest run",
- "lint": "eslint src tests e2e tools/*.mjs packages/runtime/src packages/runtime/tests packages/runtime/vite.config.ts packages/runtime/*.mjs site/src site/vite.config.ts",
+ "lint": "eslint src tests e2e tools/*.mjs packages/create-mesh-avatar-studio/*.mjs packages/runtime/src packages/runtime/tests packages/runtime/vite.config.ts packages/runtime/*.mjs site/src site/vite.config.ts",
"build": "tsc --noEmit && vite build",
"build:runtime": "npm run build -w mesh-avatar",
"changeset": "changeset",
@@ -21,7 +21,8 @@
"validate-rig": "node --experimental-strip-types tools/validate-rig.mjs",
"validate-avatar": "node --experimental-strip-types tools/validate-avatar.mjs",
"pack-avatar": "node --experimental-strip-types tools/pack-avatar.mjs",
- "render-poses": "node --experimental-strip-types tools/render-poses.mjs"
+ "render-poses": "node --experimental-strip-types tools/render-poses.mjs",
+ "doctor": "node tools/doctor.mjs"
},
"dependencies": {
"@mediapipe/tasks-vision": "0.10.21",
diff --git a/packages/create-mesh-avatar-studio/LICENSE b/packages/create-mesh-avatar-studio/LICENSE
new file mode 100644
index 0000000..8b20d89
--- /dev/null
+++ b/packages/create-mesh-avatar-studio/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 Yuki Shindo
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/packages/create-mesh-avatar-studio/README.md b/packages/create-mesh-avatar-studio/README.md
new file mode 100644
index 0000000..231cd12
--- /dev/null
+++ b/packages/create-mesh-avatar-studio/README.md
@@ -0,0 +1,41 @@
+# create-mesh-avatar-studio
+
+Set up [Mesh Avatar Studio](https://github.com/shinshin86/mesh-avatar-studio) in one command.
+
+```sh
+npx create-mesh-avatar-studio
+```
+
+It downloads the repository with Git into `mesh-avatar-studio/` (or the folder you name),
+installs its packages and checks the tools it needs. Then start the editor:
+
+```sh
+cd mesh-avatar-studio
+npm run dev
+```
+
+Requires Node.js 22.17+ and Git.
+
+## Options
+
+```sh
+npx create-mesh-avatar-studio my-avatars # choose the folder
+npx create-mesh-avatar-studio --lang ja # messages in Japanese (default follows your locale)
+```
+
+## What the check reports
+
+The same check runs any time with `npm run doctor` inside the folder.
+
+| Tool | Needed for |
+|---|---|
+| Node.js 22.17+ and the installed packages | The editor and the Live page. Missing ones are errors. |
+| uv and Python 3.10+ | Rebuilding layers and creating avatars. Missing ones are warnings. |
+| Playwright Chromium | Rendering the motion review when an agent creates an avatar or imports drawn eyes and mouths. A missing browser is a warning. |
+
+To try an avatar without installing anything, open the
+[Player](https://shinshin86.github.io/mesh-avatar-studio/play/) in Chrome or Edge.
+
+## License
+
+MIT. See [LICENSE](./LICENSE).
diff --git a/packages/create-mesh-avatar-studio/index.mjs b/packages/create-mesh-avatar-studio/index.mjs
new file mode 100755
index 0000000..54adfe2
--- /dev/null
+++ b/packages/create-mesh-avatar-studio/index.mjs
@@ -0,0 +1,108 @@
+#!/usr/bin/env node
+// Downloads Mesh Avatar Studio, installs its packages and runs its environment check.
+// Avatars are made inside the downloaded folder, so it is a full Git clone of the repository.
+import { spawnSync } from 'node:child_process';
+import { existsSync, mkdirSync, readdirSync, realpathSync } from 'node:fs';
+import { resolve } from 'node:path';
+import { pathToFileURL } from 'node:url';
+
+export const REPOSITORY = 'https://github.com/shinshin86/mesh-avatar-studio.git';
+export const DEFAULT_DIRECTORY = 'mesh-avatar-studio';
+const MIN_NODE = [22, 17];
+
+const text = {
+ en: {
+ usage: `Usage: npx create-mesh-avatar-studio [directory] [--lang en|ja]
+
+Downloads Mesh Avatar Studio into the directory (default: ${DEFAULT_DIRECTORY}),
+installs its packages and checks the tools it needs.`,
+ nodeOld: version => `Node.js ${MIN_NODE.join('.')} or later is required (found ${version}). Install it from https://nodejs.org/`,
+ gitMissing: 'Git was not found. Install it from https://git-scm.com/downloads and run this command again.',
+ notEmpty: directory => `${directory} already exists and is not empty. Choose another directory name.`,
+ cloning: directory => `Downloading Mesh Avatar Studio into ${directory}…`,
+ cloneFailed: 'Could not download the repository. Check your network connection and try again.',
+ installing: 'Installing packages (npm ci)…',
+ installFailed: directory => `Could not install the packages. Fix the error above, then run "npm ci" in ${directory}.`,
+ next: (directory, ready) => `
+Next steps:
+ cd ${directory}
+ ${ready ? 'npm run dev' : 'npm run doctor # after installing the tools above'}
+
+Open the URL that npm run dev prints, for example http://127.0.0.1:5173/.
+To create an avatar from your illustration, open Claude Code or Codex in ${directory}
+and follow README.md.`,
+ },
+ ja: {
+ usage: `使い方: npx create-mesh-avatar-studio [フォルダ名] [--lang en|ja]
+
+Mesh Avatar Studio をフォルダ(既定: ${DEFAULT_DIRECTORY})にダウンロードし、
+パッケージのインストールと必要なツールの確認を行います。`,
+ nodeOld: version => `Node.js ${MIN_NODE.join('.')} 以降が必要です(現在 ${version})。https://nodejs.org/ からインストールしてください。`,
+ gitMissing: 'Git が見つかりません。https://git-scm.com/downloads からインストールして、もう一度実行してください。',
+ notEmpty: directory => `${directory} はすでにあり、空ではありません。別のフォルダ名を指定してください。`,
+ cloning: directory => `Mesh Avatar Studio を ${directory} にダウンロードしています…`,
+ cloneFailed: 'リポジトリをダウンロードできませんでした。ネットワーク接続を確認して、もう一度実行してください。',
+ installing: 'パッケージをインストールしています(npm ci)…',
+ installFailed: directory => `パッケージをインストールできませんでした。上のエラーを解決してから、${directory} で「npm ci」を実行してください。`,
+ next: (directory, ready) => `
+次の手順:
+ cd ${directory}
+ ${ready ? 'npm run dev' : 'npm run doctor # 上のツールをインストールしたあとで確認'}
+
+npm run dev が表示する URL(例: http://127.0.0.1:5173/)をブラウザで開きます。
+自分のイラストからアバターを作るときは、${directory} で Claude Code か Codex を開き、
+README.ja.md の手順に沿って進めてください。`,
+ },
+};
+
+export function parseArgs(argv, env = process.env) {
+ let directory, lang, help = false;
+ for (let i = 0; i < argv.length; i++) {
+ const arg = argv[i];
+ if (arg === '--help' || arg === '-h') help = true;
+ else if (arg === '--lang') lang = argv[++i];
+ else if (arg.startsWith('--lang=')) lang = arg.slice(7);
+ else if (!arg.startsWith('-') && directory === undefined) directory = arg;
+ }
+ if (lang !== 'en' && lang !== 'ja') {
+ const locale = env.LC_ALL || env.LC_MESSAGES || env.LANG || Intl.DateTimeFormat().resolvedOptions().locale;
+ lang = /^ja/i.test(locale ?? '') ? 'ja' : 'en';
+ }
+ return { directory: directory ?? DEFAULT_DIRECTORY, lang, help };
+}
+
+export function nodeVersionOk(version) {
+ const [major, minor] = version.replace(/^v/, '').split('.').map(Number);
+ return major > MIN_NODE[0] || (major === MIN_NODE[0] && minor >= MIN_NODE[1]);
+}
+
+/** Runs a command with its output shown to the person. Returns the exit status, or null when the command is missing. */
+export function runCommand(command, args, cwd) {
+ // npm is a batch file on Windows, which Node starts only through a shell.
+ const result = spawnSync(command, args, { cwd, stdio: 'inherit', shell: process.platform === 'win32' && command === 'npm' });
+ return result.error ? null : result.status;
+}
+
+export function create(argv, { run = runCommand, log = console.log, error = console.error, cwd = process.cwd(), env = process.env, version = process.version } = {}) {
+ const options = parseArgs(argv, env), t = text[options.lang];
+ if (options.help) { log(t.usage); return 0; }
+ if (!nodeVersionOk(version)) { error(t.nodeOld(version.replace(/^v/, ''))); return 1; }
+ if (run('git', ['--version'], cwd) !== 0) { error(t.gitMissing); return 1; }
+ const target = resolve(cwd, options.directory);
+ if (existsSync(target) && readdirSync(target).length) { error(t.notEmpty(options.directory)); return 1; }
+ log(t.cloning(options.directory));
+ if (run('git', ['clone', REPOSITORY, target], cwd) !== 0) { error(t.cloneFailed); return 1; }
+ // Create the ignored project folder as this user. On Windows, a folder made later by an
+ // agent in a sandbox can have permissions the editor cannot read.
+ mkdirSync(resolve(target, 'projects'), { recursive: true });
+ log(t.installing);
+ if (run('npm', ['ci'], target) !== 0) { error(t.installFailed(options.directory)); return 1; }
+ const ready = run(process.execPath, ['tools/doctor.mjs', '--lang', options.lang], target) === 0;
+ log(t.next(options.directory, ready));
+ return 0;
+}
+
+// npx and npm run start this file through a link, so compare real paths.
+if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
+ process.exitCode = create(process.argv.slice(2));
+}
diff --git a/packages/create-mesh-avatar-studio/package.json b/packages/create-mesh-avatar-studio/package.json
new file mode 100644
index 0000000..c689cd8
--- /dev/null
+++ b/packages/create-mesh-avatar-studio/package.json
@@ -0,0 +1,35 @@
+{
+ "name": "create-mesh-avatar-studio",
+ "version": "0.0.0",
+ "type": "module",
+ "license": "MIT",
+ "description": "Set up Mesh Avatar Studio in one command: download it, install packages and check the tools it needs.",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/shinshin86/mesh-avatar-studio.git",
+ "directory": "packages/create-mesh-avatar-studio"
+ },
+ "homepage": "https://github.com/shinshin86/mesh-avatar-studio",
+ "keywords": [
+ "avatar",
+ "2d",
+ "vtuber",
+ "mesh-avatar",
+ "create"
+ ],
+ "bin": {
+ "create-mesh-avatar-studio": "./index.mjs"
+ },
+ "files": [
+ "index.mjs",
+ "README.md",
+ "LICENSE"
+ ],
+ "engines": {
+ "node": ">=22.17"
+ },
+ "publishConfig": {
+ "access": "public",
+ "provenance": true
+ }
+}
diff --git a/tests/create-cli.test.ts b/tests/create-cli.test.ts
new file mode 100644
index 0000000..300846c
--- /dev/null
+++ b/tests/create-cli.test.ts
@@ -0,0 +1,76 @@
+import { mkdirSync, mkdtempSync, writeFileSync, existsSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { describe, expect, test } from 'vitest';
+import { create, parseArgs, REPOSITORY } from '../packages/create-mesh-avatar-studio/index.mjs';
+
+function harness(statuses: Record<string, number | null> = {}) {
+ const calls: { command: string; args: string[]; cwd: string }[] = [], logs: string[] = [], errors: string[] = [];
+ const cwd = mkdtempSync(join(tmpdir(), 'create-studio-'));
+ const run = (command: string, args: string[], dir: string) => {
+ calls.push({ command, args, cwd: dir });
+ const key = command === process.execPath ? 'doctor' : `${command} ${args[0]}`;
+ if (key === 'git clone') mkdirSync(args[2], { recursive: true });
+ return key in statuses ? statuses[key] : 0;
+ };
+ return { calls, logs, errors, cwd, options: { run, log: (m: string) => logs.push(m), error: (m: string) => errors.push(m), cwd, env: { LANG: 'en_US.UTF-8' }, version: 'v22.17.1' } };
+}
+
+describe('create-mesh-avatar-studio', () => {
+ test('parses the folder, language and help', () => {
+ expect(parseArgs([], { LANG: 'en_US' })).toEqual({ directory: 'mesh-avatar-studio', lang: 'en', help: false });
+ expect(parseArgs(['mine', '--lang', 'ja'], {})).toEqual({ directory: 'mine', lang: 'ja', help: false });
+ expect(parseArgs(['--lang=xx', '-h'], { LANG: 'ja_JP.UTF-8' })).toEqual({ directory: 'mesh-avatar-studio', lang: 'ja', help: true });
+ });
+
+ test('clones, creates projects/, installs, checks and prints the next steps', () => {
+ const h = harness();
+ expect(create(['mine'], h.options)).toBe(0);
+ const target = join(h.cwd, 'mine');
+ expect(h.calls.map(c => [c.command === process.execPath ? 'node' : c.command, ...c.args])).toEqual([
+ ['git', '--version'], ['git', 'clone', REPOSITORY, target], ['npm', 'ci'], ['node', 'tools/doctor.mjs', '--lang', 'en'],
+ ]);
+ expect(h.calls.slice(2).every(c => c.cwd === target)).toBe(true);
+ expect(existsSync(join(target, 'projects'))).toBe(true);
+ expect(h.logs.at(-1)).toContain('cd mine\n npm run dev');
+ });
+
+ test('suggests rerunning the check when doctor reports an error', () => {
+ const h = harness({ doctor: 1 });
+ expect(create([], h.options)).toBe(0);
+ expect(h.logs.at(-1)).toContain('npm run doctor');
+ });
+
+ test('stops with a reason for an old Node.js, missing Git, a used folder or failed steps', () => {
+ const old = harness();
+ expect(create([], { ...old.options, version: 'v20.19.0' })).toBe(1);
+ expect(old.errors[0]).toContain('Node.js 22.17 or later is required (found 20.19.0)');
+ expect(old.calls).toEqual([]);
+
+ const noGit = harness({ 'git --version': null });
+ expect(create([], noGit.options)).toBe(1);
+ expect(noGit.errors[0]).toContain('https://git-scm.com/downloads');
+
+ const used = harness();
+ mkdirSync(join(used.cwd, 'mesh-avatar-studio')); writeFileSync(join(used.cwd, 'mesh-avatar-studio', 'notes.txt'), 'x');
+ expect(create([], used.options)).toBe(1);
+ expect(used.errors[0]).toContain('already exists and is not empty');
+ expect(used.calls.map(c => c.args[0])).toEqual(['--version']);
+
+ const offline = harness({ 'git clone': 128 });
+ expect(create([], offline.options)).toBe(1);
+ expect(offline.errors[0]).toContain('Could not download the repository');
+
+ const install = harness({ 'npm ci': 1 });
+ expect(create(['mine'], install.options)).toBe(1);
+ expect(install.errors[0]).toContain('run "npm ci" in mine');
+ });
+
+ test('accepts an existing empty folder and speaks Japanese', () => {
+ const h = harness();
+ mkdirSync(join(h.cwd, 'mesh-avatar-studio'));
+ expect(create(['--lang', 'ja'], h.options)).toBe(0);
+ expect(h.logs[0]).toContain('ダウンロードしています');
+ expect(h.logs.at(-1)).toContain('README.ja.md');
+ });
+});
diff --git a/tests/doctor.test.ts b/tests/doctor.test.ts
new file mode 100644
index 0000000..bfe2711
--- /dev/null
+++ b/tests/doctor.test.ts
@@ -0,0 +1,48 @@
+import { describe, expect, test } from 'vitest';
+import { checkEnvironment, formatReport, language, nodeVersionOk } from '../tools/doctor.mjs';
+
+const ready = { node: async () => '22.17.1', packages: async () => true, uv: async () => '0.9.21', python: async () => '3.12.4', chromium: async () => true };
+const statuses = (results: { id: string; status: string }[]) => Object.fromEntries(results.map(r => [r.id, r.status]));
+
+describe('environment check', () => {
+ test('requires Node.js 22.17 or later', () => {
+ expect([nodeVersionOk('v22.17.0'), nodeVersionOk('22.16.9'), nodeVersionOk('23.0.0'), nodeVersionOk('20.19.0')]).toEqual([true, false, true, false]);
+ });
+
+ test('passes with every tool and tells the person how to start the editor', async () => {
+ const results = await checkEnvironment('en', ready);
+ expect(statuses(results)).toEqual({ node: 'ok', packages: 'ok', uv: 'ok', python: 'ok', chromium: 'ok' });
+ expect(formatReport(results, 'en')).toContain('Everything is ready. Start the editor with: npm run dev');
+ });
+
+ test('an old Node.js or missing packages are errors', async () => {
+ const results = await checkEnvironment('en', { ...ready, node: async () => '20.19.0', packages: async () => false });
+ expect(statuses(results)).toMatchObject({ node: 'error', packages: 'error' });
+ expect(formatReport(results, 'en')).toMatch(/✗ Node\.js 22\.17 or later is required \(found 20\.19\.0\)[\s\S]*✗ Packages are not installed\. Run: npm install[\s\S]*Fix the errors above/);
+ });
+
+ test('missing uv, Python or Chromium are warnings that keep the editor usable', async () => {
+ const noUv = await checkEnvironment('en', { ...ready, uv: async () => null, chromium: async () => false });
+ expect(statuses(noUv)).toEqual({ node: 'ok', packages: 'ok', uv: 'warn', python: 'warn', chromium: 'warn' });
+ const report = formatReport(noUv, 'en');
+ expect(report).toContain('Python was not checked because uv is missing.');
+ expect(report).toContain('Creating avatars with an agent, or importing drawn eyes and mouths, needs it');
+ expect(report).toContain('npx playwright install chromium');
+ expect(report).toContain('You can start the editor with: npm run dev');
+ const noPython = await checkEnvironment('en', { ...ready, python: async () => null });
+ expect(formatReport(noPython, 'en')).toContain('uv python install 3.12');
+ });
+
+ test('a free-threaded Python is a warning because OpenCV has no package for it', async () => {
+ const results = await checkEnvironment('en', { ...ready, python: async () => '3.14.0t' });
+ expect(statuses(results).python).toBe('warn');
+ expect(formatReport(results, 'en')).toContain('free-threaded Python 3.14.0');
+ });
+
+ test('reports in Japanese, chosen by flag or locale', async () => {
+ expect([language(['--lang', 'ja'], {}), language(['--lang=en'], { LANG: 'ja_JP.UTF-8' }), language([], { LANG: 'ja_JP.UTF-8' }), language([], { LANG: 'en_US.UTF-8' })]).toEqual(['ja', 'en', 'ja', 'en']);
+ const report = formatReport(await checkEnvironment('ja', { ...ready, chromium: async () => false }), 'ja');
+ expect(report).toContain('⚠ Playwright の Chromium が見つかりません。エディタと配信画面はこのまま使えます。');
+ expect(report).toContain('エディタは次のコマンドで起動できます: npm run dev');
+ });
+});
diff --git a/tools/doctor.mjs b/tools/doctor.mjs
new file mode 100644
index 0000000..bc00764
--- /dev/null
+++ b/tools/doctor.mjs
@@ -0,0 +1,113 @@
+#!/usr/bin/env node
+// Checks what Mesh Avatar Studio needs on this machine and explains what each missing tool
+// is for. Only Node.js and the installed packages are required to run the editor.
+import { execFile } from 'node:child_process';
+import { existsSync, realpathSync } from 'node:fs';
+import { fileURLToPath, pathToFileURL } from 'node:url';
+
+export const MIN_NODE = [22, 17];
+const root = fileURLToPath(new URL('..', import.meta.url));
+
+const text = {
+ en: {
+ title: 'Mesh Avatar Studio environment check',
+ node: version => `Node.js ${version}`,
+ nodeOld: version => `Node.js ${MIN_NODE.join('.')} or later is required (found ${version}). Install it from https://nodejs.org/`,
+ packages: 'Packages installed',
+ packagesMissing: 'Packages are not installed. Run: npm install',
+ uv: version => `uv ${version}`,
+ uvMissing: 'uv was not found. The editor works without it, but rebuilding layers and creating avatars need it.\n Install: https://docs.astral.sh/uv/getting-started/installation/',
+ python: version => `Python ${version} (found by uv)`,
+ pythonMissing: 'uv found no Python 3.10 or later. The editor works, but rebuilding layers and creating avatars need it.\n Install: uv python install 3.12',
+ pythonSkipped: 'Python was not checked because uv is missing.',
+ pythonFreeThreaded: version => `uv picks the free-threaded Python ${version}. OpenCV has no ready-made package for it, so rebuilding layers can fail.\n Install a regular build: uv python install 3.13`,
+ chromium: 'Playwright Chromium',
+ chromiumMissing: 'Playwright Chromium was not found. The editor and the Live page work as they are.\n Creating avatars with an agent, or importing drawn eyes and mouths, needs it to render the motion review.\n Install: npx playwright install chromium',
+ failed: 'Fix the errors above before starting the editor.',
+ warned: 'You can start the editor with: npm run dev\nInstall the tools marked with a warning before creating avatars.',
+ passed: 'Everything is ready. Start the editor with: npm run dev',
+ },
+ ja: {
+ title: 'Mesh Avatar Studio の動作環境チェック',
+ node: version => `Node.js ${version}`,
+ nodeOld: version => `Node.js ${MIN_NODE.join('.')} 以降が必要です(現在 ${version})。https://nodejs.org/ からインストールしてください。`,
+ packages: 'パッケージはインストール済みです',
+ packagesMissing: 'パッケージがインストールされていません。次を実行してください: npm install',
+ uv: version => `uv ${version}`,
+ uvMissing: 'uv が見つかりません。エディタはこのまま使えますが、レイヤーの作り直しとアバターの作成には必要です。\n インストール: https://docs.astral.sh/uv/getting-started/installation/',
+ python: version => `Python ${version}(uv で検出)`,
+ pythonMissing: 'uv から Python 3.10 以降が見つかりません。エディタは使えますが、レイヤーの作り直しとアバターの作成には必要です。\n インストール: uv python install 3.12',
+ pythonSkipped: 'uv がないため、Python は確認していません。',
+ pythonFreeThreaded: version => `uv がフリースレッド版の Python ${version} を選んでいます。OpenCV にはこの版向けのビルド済みパッケージがなく、レイヤーの作り直しに失敗することがあります。\n 通常版をインストール: uv python install 3.13`,
+ chromium: 'Playwright の Chromium',
+ chromiumMissing: 'Playwright の Chromium が見つかりません。エディタと配信画面はこのまま使えます。\n エージェントでアバターを作るときや、描き分け画像を取り込むときは、動きの確認(ポーズ画像の書き出し)に必要です。\n インストール: npx playwright install chromium',
+ failed: '上のエラーを解決してからエディタを起動してください。',
+ warned: 'エディタは次のコマンドで起動できます: npm run dev\nアバターを作る前に、警告の付いたツールをインストールしてください。',
+ passed: 'すべて揃っています。次のコマンドでエディタを起動できます: npm run dev',
+ },
+};
+
+export function language(argv = process.argv.slice(2), env = process.env) {
+ const flag = argv.find(arg => arg.startsWith('--lang='))?.slice(7) ?? argv[argv.indexOf('--lang') + 1];
+ if (flag === 'ja' || flag === 'en') return flag;
+ const locale = env.LC_ALL || env.LC_MESSAGES || env.LANG || Intl.DateTimeFormat().resolvedOptions().locale;
+ return /^ja/i.test(locale ?? '') ? 'ja' : 'en';
+}
+
+export function nodeVersionOk(version) {
+ const [major, minor] = version.replace(/^v/, '').split('.').map(Number);
+ return major > MIN_NODE[0] || (major === MIN_NODE[0] && minor >= MIN_NODE[1]);
+}
+
+const run = (command, args) => new Promise(done => {
+ execFile(command, args, { cwd: root, timeout: 30_000, windowsHide: true }, (error, stdout) => done(error ? null : stdout.trim()));
+});
+
+/** Probes the machine. Each probe returns null when the tool is missing. */
+export const probes = {
+ node: async () => process.version.replace(/^v/, ''),
+ packages: async () => existsSync(fileURLToPath(new URL('../node_modules/vite/package.json', import.meta.url))),
+ uv: async () => (await run('uv', ['--version']))?.replace(/^uv\s+/, '').split(' ')[0] ?? null,
+ // Studio runs its tools with an interpreter uv finds, without downloading one.
+ python: async () => {
+ const path = await run('uv', ['python', 'find', '>=3.10']);
+ // A trailing "t" marks a free-threaded build, as in python3.14t.
+ return path ? (await run(path, ['-c', "import platform, sysconfig; print(platform.python_version() + ('t' if sysconfig.get_config_var('Py_GIL_DISABLED') else ''))"])) ?? path : null;
+ },
+ chromium: async () => {
+ try {
+ const { chromium } = await import('@playwright/test');
+ return existsSync(chromium.executablePath());
+ } catch { return false; }
+ },
+};
+
+/** Returns one result per check: ok, warn (optional for the editor) or error (blocks it). */
+export async function checkEnvironment(lang, probe = probes) {
+ const t = text[lang], results = [];
+ const node = await probe.node();
+ results.push(nodeVersionOk(node) ? { id: 'node', status: 'ok', message: t.node(node) } : { id: 'node', status: 'error', message: t.nodeOld(node) });
+ results.push(await probe.packages() ? { id: 'packages', status: 'ok', message: t.packages } : { id: 'packages', status: 'error', message: t.packagesMissing });
+ const uv = await probe.uv();
+ results.push(uv ? { id: 'uv', status: 'ok', message: t.uv(uv) } : { id: 'uv', status: 'warn', message: t.uvMissing });
+ const python = uv ? await probe.python() : null;
+ if (!python) results.push({ id: 'python', status: 'warn', message: uv ? t.pythonMissing : t.pythonSkipped });
+ else if (/^\d+\.\d+\.\d+t$/.test(python)) results.push({ id: 'python', status: 'warn', message: t.pythonFreeThreaded(python.slice(0, -1)) });
+ else results.push({ id: 'python', status: 'ok', message: t.python(python) });
+ results.push(await probe.chromium() ? { id: 'chromium', status: 'ok', message: t.chromium } : { id: 'chromium', status: 'warn', message: t.chromiumMissing });
+ return results;
+}
+
+export function formatReport(results, lang) {
+ const t = text[lang], mark = { ok: '✓', warn: '⚠', error: '✗' };
+ const summary = results.some(r => r.status === 'error') ? t.failed : results.some(r => r.status === 'warn') ? t.warned : t.passed;
+ return [t.title, '', ...results.map(r => `${mark[r.status]} ${r.message}`), '', summary].join('\n');
+}
+
+// npx and npm run start this file through a link, so compare real paths.
+if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
+ const lang = language();
+ const results = await checkEnvironment(lang);
+ console.log(formatReport(results, lang));
+ process.exitCode = results.some(r => r.status === 'error') ? 1 : 0;
+}