Skip to content

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

Draw every variant by default in npm run create, after asking first

shinshin8695f326c5c5d0
diff --git a/README.ja.md b/README.ja.md
index c269433..0ec43d3 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -61,10 +61,11 @@ npm run dev
npm run create -- /path/to/your-image.png
```
+Codex は OpenAI の画像生成で、閉じ目・口の形・表情の描き分けも作ります。画像とマスクが OpenAI に送られるため、
+コマンドは最初に確認します。`--yes` を付けると事前に同意し、`--no-variants` を付けるとすべて手元のマシンの中で行います。
通常は数十分かかります。Codex のメモは `projects/<name>/HANDOVER.md` に書き出されます。
Codex は `--approve-for-me` 付きで動くため、ポーズ確認用の Chromium など sandbox の外でツールを動かす許可は、
-あなたの代わりに自動レビューが判断します。`--variants` を付けると閉じ目と口の形も描かせます。
-`--expressions` を付けると、さらに悲しい目・驚いた目・怒った口・悲しい口も描かせます。どちらも画像とマスクが Codex の画像生成に送られます。オプションは `npm run create -- --help` で確認できます。
+あなたの代わりに自動レビューが判断します。オプションは `npm run create -- --help` で確認できます。
### 2. プロジェクトを開いて確認する
diff --git a/README.md b/README.md
index b3aaaf8..7c67339 100644
--- a/README.md
+++ b/README.md
@@ -82,11 +82,13 @@ on the result:
npm run create -- /path/to/your-image.png
```
-It usually takes tens of minutes. Codex writes its notes to `projects/<name>/HANDOVER.md`.
-It runs with `--approve-for-me`, so its requests to run tools outside its sandbox, such as
-Chromium for the pose review, are reviewed automatically instead of by you. Add `--variants`
-to have it draw closed eyes and mouth shapes as well, or `--expressions` to add sad and
-surprised eyes and angry and sad mouths; both send the image and masks to its image generator. `npm run create -- --help` lists the options.
+Codex also draws closed eyes, mouth shapes and expressions with OpenAI image generation. This
+sends the image and masks to OpenAI, so the command asks first; add `--yes` to agree in
+advance, or `--no-variants` to keep everything on your machine. It usually takes tens of
+minutes. Codex writes its notes to `projects/<name>/HANDOVER.md`. It runs with
+`--approve-for-me`, so its requests to run tools outside its sandbox, such as Chromium for the
+pose review, are reviewed automatically instead of by you. `npm run create -- --help` lists the
+options.
### 2. Open the project and check it
diff --git a/README.zh.md b/README.zh.md
index 4cd7547..17fac06 100644
--- a/README.zh.md
+++ b/README.zh.md
@@ -61,10 +61,10 @@ npm run dev
npm run create -- /path/to/your-image.png
```
-通常需要几十分钟。Codex 的说明写在 `projects/<name>/HANDOVER.md`。Codex 以 `--approve-for-me`
-运行,因此在沙箱外运行工具(例如姿势检查用的 Chromium)的请求由自动审核代替你决定。加上
-`--variants` 还会绘制闭眼和嘴型;加上 `--expressions` 还会绘制悲伤和惊讶的眼睛以及生气和悲伤的嘴。两者都会把图像和遮罩发送到 Codex 的图像生成器。用
-`npm run create -- --help` 查看全部选项。
+Codex 还会用 OpenAI 图像生成绘制闭眼、嘴型和表情。这会把图像和遮罩发送到 OpenAI,因此命令会先询问;
+加上 `--yes` 可预先同意,加上 `--no-variants` 则全部在本机完成。通常需要几十分钟。Codex 的说明写在
+`projects/<name>/HANDOVER.md`。Codex 以 `--approve-for-me` 运行,因此在沙箱外运行工具(例如姿势检查用的
+Chromium)的请求由自动审核代替你决定。用 `npm run create -- --help` 查看全部选项。
### 2. 打开项目并检查
diff --git a/tests/create-avatar.test.ts b/tests/create-avatar.test.ts
index bc3987a..4942824 100644
--- a/tests/create-avatar.test.ts
+++ b/tests/create-avatar.test.ts
@@ -6,8 +6,8 @@ import { agentPrompt, create, parseArgs, projectName } from '../tools/create.mjs
const root = fileURLToPath(new URL('..', import.meta.url));
const ready = async () => ['node', 'packages', 'uv', 'python', 'chromium'].map(id => ({ id, status: 'ok', message: id }));
-function harness({ files = [] as string[], statuses = {} as Record<string, number | null>, environment = ready } = {}) {
- const calls: { command: string; args: string[]; options?: { stdio?: unknown } }[] = [], logs: string[] = [], errors: string[] = [];
+function harness({ files = [] as string[], statuses = {} as Record<string, number | null>, environment = ready, answer = true as boolean | null, interactive = true } = {}) {
+ const calls: { command: string; args: string[]; options?: { stdio?: unknown } }[] = [], logs: string[] = [], errors: string[] = [], questions: string[] = [];
const existing = new Set(files);
const run = async (command: string, args: string[], options?: { stdio?: unknown }) => {
calls.push({ command, args, options });
@@ -19,15 +19,16 @@ function harness({ files = [] as string[], statuses = {} as Record<string, numbe
return key in statuses ? statuses[key] : 0;
};
const read = async (command: string) => command === 'codex' ? 'codex-cli 0.164.0' : '/cache/uv';
- const deps = { run, read, exists: (path: string) => existing.has(path), environment, log: (m: string) => logs.push(m), error: (m: string) => errors.push(m), cwd: '/work' };
- return { calls, logs, errors, deps };
+ const ask = async (question: string) => { questions.push(question); return answer; };
+ const deps = { run, read, ask, interactive, exists: (path: string) => existing.has(path), environment, log: (m: string) => logs.push(m), error: (m: string) => errors.push(m), cwd: '/work' };
+ return { calls, logs, errors, questions, deps };
}
describe('npm run create', () => {
test('parses the image, name and flags', () => {
- expect(parseArgs(['a.png', '--name', 'mio', '--variants', '--no-open', '--lang', 'ja'])).toMatchObject({ image: 'a.png', name: 'mio', variants: true, open: false });
- expect(parseArgs(['--name=mio', 'b.png'])).toMatchObject({ image: 'b.png', name: 'mio', variants: false, open: true });
- expect(parseArgs(['c.png', '--expressions'])).toMatchObject({ variants: true, expressions: true });
+ expect(parseArgs(['a.png', '--name', 'mio', '--yes', '--no-open', '--lang', 'ja'])).toMatchObject({ image: 'a.png', name: 'mio', variants: true, yes: true, open: false });
+ expect(parseArgs(['--name=mio', 'b.png', '--no-variants'])).toMatchObject({ image: 'b.png', name: 'mio', variants: false, yes: false, open: true });
+ expect(parseArgs(['c.png', '-y'])).toMatchObject({ variants: true, yes: true });
});
test('derives a project name from the file name and skips taken names', () => {
@@ -36,7 +37,7 @@ describe('npm run create', () => {
expect(projectName('mio.png', name => name === 'mio' || name === 'mio-2')).toBe('mio-3');
});
- test('answers every question of the guide and sends the image only with --variants', () => {
+ test('answers every question of the guide and draws every variant only with consent', () => {
const plain = agentPrompt('mio', { variants: false });
expect(plain).toContain('docs/agent-guide.md');
expect(plain).toContain('projects/mio/HANDOVER.md');
@@ -46,20 +47,48 @@ describe('npm run create', () => {
expect(plain).toContain('Do not post-process built/');
const variants = agentPrompt('mio', { variants: true });
expect(variants).toContain('the person agreed to send source.png and the masks');
- expect(variants).toContain('not the optional expression ones');
- expect(agentPrompt('mio', { variants: true, expressions: true })).toContain('eyes_sad, eyes_surprise, mouth_angry, mouth_sad');
+ expect(variants).toContain('eyes_sad, eyes_surprise, mouth_angry and mouth_sad');
});
- test('creates the project, runs Codex and opens the editor on it', async () => {
- const { calls, deps } = harness({ files: ['/work/mio.png'] });
+ test('asks about OpenAI image generation first, then creates the project, runs Codex and opens the editor', async () => {
+ const { calls, questions, deps } = harness({ files: ['/work/mio.png'] });
expect(await create(['mio.png', '--lang', 'en'], deps)).toBe(0);
+ expect(questions).toHaveLength(1);
+ expect(questions[0]).toContain('This sends the image and masks to OpenAI.');
expect(calls.map(call => `${call.command === process.execPath ? 'vite' : call.command} ${call.args[0]}`)).toEqual(['uv run', 'codex exec', 'vite ' + join(root, 'node_modules/vite/bin/vite.js')]);
expect(calls[0].args).toEqual(['run', 'tools/new-project.py', '/work/mio.png', 'mio']);
expect(calls[1].args.slice(0, 6)).toEqual(['exec', '--approve-for-me', '-C', root, '--add-dir', '/cache/uv']);
+ expect(calls[1].args.at(-1)).toContain('the person agreed to send');
expect(calls[1].options?.stdio).toEqual(['ignore', 'inherit', 'inherit']);
expect(calls[2].args).toContain('/?project=mio');
});
+ test('a declined, skipped or pre-approved image generation is not asked again', async () => {
+ const declined = harness({ files: ['/work/mio.png'], answer: false });
+ expect(await create(['mio.png', '--lang', 'en'], declined.deps)).toBe(0);
+ expect(declined.logs).toContain('Not sending the image. The avatar is made without drawn variants.');
+ expect(declined.calls[1].args.at(-1)).toContain('Step 6: skip it');
+ for (const [flag, step] of [['--yes', 'the person agreed to send'], ['--no-variants', 'Step 6: skip it']]) {
+ const { calls, questions, deps } = harness({ files: ['/work/mio.png'], interactive: false });
+ expect(await create(['mio.png', flag, '--lang', 'en'], deps)).toBe(0);
+ expect(questions).toEqual([]);
+ expect(calls[1].args.at(-1)).toContain(step);
+ }
+ });
+
+ test('cancelling the question stops before anything runs', async () => {
+ const { calls, deps } = harness({ files: ['/work/mio.png'], answer: null });
+ expect(await create(['mio.png', '--lang', 'en'], deps)).toBe(130);
+ expect(calls).toEqual([]);
+ });
+
+ test('without a terminal it needs --yes or --no-variants before doing anything', async () => {
+ const { calls, errors, deps } = harness({ files: ['/work/mio.png'], interactive: false });
+ expect(await create(['mio.png', '--lang', 'en'], deps)).toBe(1);
+ expect(errors[0]).toContain('add --yes to agree or --no-variants');
+ expect(calls).toEqual([]);
+ });
+
test('stops before creating anything when a tool is missing', async () => {
const environment = async () => [{ id: 'chromium', status: 'warn', message: 'Playwright Chromium was not found.' }];
const { calls, errors, deps } = harness({ files: ['/work/mio.png'], environment });
diff --git a/tools/create.mjs b/tools/create.mjs
index d0dcc46..bc85bf6 100644
--- a/tools/create.mjs
+++ b/tools/create.mjs
@@ -11,16 +11,20 @@ const root = fileURLToPath(new URL('..', import.meta.url));
const text = {
en: {
- usage: 'Usage: npm run create -- <image.png> [--name <name>] [--variants] [--expressions] [--no-open]\n\n'
- + ' --name project name under projects/ (default: from the file name)\n'
- + ' --variants let Codex send source.png and masks to its image generator for drawn\n'
- + ' closed eyes and mouth shapes (Step 6 of the agent guide)\n'
- + ' --expressions also draw sad and surprised eyes and angry and sad mouths (implies --variants)\n'
- + ' --no-open do not start the editor when the avatar is ready',
+ usage: 'Usage: npm run create -- <image.png> [--name <name>] [--yes | --no-variants] [--no-open]\n\n'
+ + 'Codex also draws closed eyes, mouth shapes and expressions with OpenAI image generation.\n'
+ + 'The command asks first, because this sends the image and masks to OpenAI.\n\n'
+ + ' --name project name under projects/ (default: from the file name)\n'
+ + ' --yes, -y agree to the image generation without asking\n'
+ + ' --no-variants keep everything on this machine and skip the drawn variants\n'
+ + ' --no-open do not start the editor when the avatar is ready',
missingImage: 'Give the path of a PNG illustration.',
noImage: path => `Image not found: ${path}`,
badName: name => `Invalid project name: ${name}. Use letters, digits, hyphens or underscores.`,
exists: name => `projects/${name} already exists. Choose another --name.`,
+ consent: 'Codex will draw closed eyes, mouth shapes and expressions with OpenAI image generation.\nThis sends the image and masks to OpenAI. Continue? [Y/n] ',
+ noConsent: 'Not sending the image. The avatar is made without drawn variants.',
+ needConsent: 'Drawn variants send the image to OpenAI image generation. Without a terminal to ask, add --yes to agree or --no-variants to skip them.',
environment: 'Fix the tools marked above, then run this command again.',
noCodex: 'Codex CLI was not found. Install it and sign in: https://github.com/openai/codex',
creating: name => `Creating projects/${name} …`,
@@ -31,16 +35,20 @@ const text = {
opening: 'Starting the editor. Press Ctrl+C to stop it.',
},
ja: {
- usage: '使い方: npm run create -- <image.png> [--name <name>] [--variants] [--expressions] [--no-open]\n\n'
- + ' --name projects/ に作るプロジェクト名(既定: ファイル名から作成)\n'
- + ' --variants 閉じ目と口の形の描き分けのため、source.png とマスクを Codex の画像生成に\n'
- + ' 送ることを許可する(エージェントガイドの Step 6)\n'
- + ' --expressions 悲しい目・驚いた目・怒った口・悲しい口も描かせる(--variants を含む)\n'
- + ' --no-open アバターができてもエディタを起動しない',
+ usage: '使い方: npm run create -- <image.png> [--name <name>] [--yes | --no-variants] [--no-open]\n\n'
+ + 'Codex は OpenAI の画像生成で、閉じ目・口の形・表情の描き分けも作ります。\n'
+ + '画像とマスクが OpenAI に送られるため、始める前に確認します。\n\n'
+ + ' --name projects/ に作るプロジェクト名(既定: ファイル名から作成)\n'
+ + ' --yes, -y 確認せずに画像生成に同意する\n'
+ + ' --no-variants すべてこのマシンの中で行い、描き分けは作らない\n'
+ + ' --no-open アバターができてもエディタを起動しない',
missingImage: 'PNG のイラストのパスを指定してください。',
noImage: path => `画像が見つかりません: ${path}`,
badName: name => `プロジェクト名が使えません: ${name}。英数字、ハイフン、アンダースコアを使ってください。`,
exists: name => `projects/${name} は既にあります。別の --name を指定してください。`,
+ consent: 'Codex が OpenAI の画像生成で、閉じ目・口の形・表情の描き分けを作ります。\n画像とマスクが OpenAI に送られます。続けますか? [Y/n] ',
+ noConsent: '画像は送りません。描き分けなしでアバターを作ります。',
+ needConsent: '描き分けを作ると画像が OpenAI の画像生成に送られます。確認できる端末がないため、同意するなら --yes、作らないなら --no-variants を付けてください。',
environment: '上の警告やエラーのツールを用意してから、もう一度実行してください。',
noCodex: 'Codex CLI が見つかりません。インストールしてサインインしてください: https://github.com/openai/codex',
creating: name => `projects/${name} を作成しています…`,
@@ -53,12 +61,12 @@ const text = {
};
export function parseArgs(argv) {
- const options = { image: undefined, name: undefined, variants: false, expressions: false, open: true, help: false };
+ const options = { image: undefined, name: undefined, variants: true, yes: false, open: true, help: false };
for (let index = 0; index < argv.length; index++) {
const arg = argv[index];
if (arg === '--help' || arg === '-h') options.help = true;
- else if (arg === '--variants') options.variants = true;
- else if (arg === '--expressions') options.variants = options.expressions = true;
+ else if (arg === '--yes' || arg === '-y') options.yes = true;
+ else if (arg === '--no-variants') options.variants = false;
else if (arg === '--no-open') options.open = false;
else if (arg === '--name') options.name = argv[++index];
else if (arg.startsWith('--name=')) options.name = arg.slice(7);
@@ -79,7 +87,7 @@ export function projectName(image, taken = name => existsSync(join(root, 'projec
}
/** The request Codex runs non-interactively: every question in the guide is answered here. */
-export function agentPrompt(name, { variants, expressions = false }) {
+export function agentPrompt(name, { variants }) {
const project = `projects/${name}`;
return [
`Create a mesh avatar in ${project} by following docs/agent-guide.md from "Before you start" through Step 7.`,
@@ -90,7 +98,7 @@ export function agentPrompt(name, { variants, expressions = false }) {
`- Vision check: run it with ${project}/work/vision-check as the folder. If the score fails, stop and explain it in the hand-over notes.`,
'- Image warnings (pose, covered face, missing transparency): record them in the hand-over notes and continue.',
variants
- ? `- Step 6: the person agreed to send source.png and the masks to your built-in image generator. Generate the required variants (closed, half and smiling eyes; mouths あ, half あ, い, お)${expressions ? ' and the expression variants (eyes_sad, eyes_surprise, mouth_angry, mouth_sad)' : ', not the optional expression ones'}, then run build-sprites and review the poses again. Generate a variant again when build-sprites rejects it or its pose frames look wrong.`
+ ? '- Step 6: the person agreed to send source.png and the masks to your built-in image generator. Generate every variant: closed, half and smiling eyes; mouths あ, half あ, い, お; and the expression variants eyes_sad, eyes_surprise, mouth_angry and mouth_sad. Then run build-sprites and review the poses again. Generate a variant again when build-sprites rejects it or its pose frames look wrong.'
: '- Step 6: skip it. The person did not agree to send the image to an image generator.',
`- Step 7: write the hand-over notes to ${project}/HANDOVER.md instead of telling the person. The editor is opened for them, so leave out how to open it.`,
'',
@@ -108,6 +116,13 @@ const execute = (command, args, options = {}) => new Promise(done => {
child.on('exit', status => done(status));
});
+const confirm = async question => {
+ const { createInterface } = await import('node:readline/promises');
+ const prompt = createInterface({ input: process.stdin, output: process.stdout });
+ // Ctrl+C rejects the question; that cancels the whole command (null) rather than declining.
+ try { return !/^n/i.test((await prompt.question(question)).trim()); } catch { return null; } finally { prompt.close(); }
+};
+
const capture = (command, args) => new Promise(done => {
const child = spawn(command, args, { cwd: root, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
let output = '';
@@ -118,7 +133,7 @@ const capture = (command, args) => new Promise(done => {
export async function create(argv, deps = {}) {
const { run = execute, read = capture, exists = existsSync, environment = checkEnvironment, log = console.log, error = console.error,
- cwd = process.env.INIT_CWD || process.cwd() } = deps;
+ ask = confirm, interactive = Boolean(process.stdin.isTTY), cwd = process.env.INIT_CWD || process.cwd() } = deps;
const lang = language(argv), t = text[lang], options = parseArgs(argv);
if (options.help) { log(t.usage); return 0; }
if (!options.image) { error(`${t.missingImage}\n\n${t.usage}`); return 1; }
@@ -128,6 +143,13 @@ export async function create(argv, deps = {}) {
const name = options.name ?? projectName(options.image, value => exists(join(root, 'projects', value)));
if (!validName(name)) { error(t.badName(name)); return 1; }
if (exists(join(root, 'projects', name))) { error(t.exists(name)); return 1; }
+ // Ask before anything slow: the answer decides whether the image may leave this machine.
+ if (options.variants && !options.yes) {
+ if (!interactive) { error(t.needConsent); return 1; }
+ const answer = await ask(t.consent);
+ if (answer === null) return 130;
+ if (!answer) { options.variants = false; log(t.noConsent); }
+ }
// Every step of the guide needs uv, Python and Chromium, so a warning blocks here.
const results = await environment(lang);