Show it a video you love. Get a new video in the same style. An AI crew (Claude Code or Codex) plans, builds and reviews it with you.
JavaScript 2d-animationai-agentsai-videoanimationclaude-codecodexmulti-agentstyle-transfervideo-generation
Review fixes: usage-limit check only on failed turns, drop each turn's abort listener, re-check reviews afresh after a shared cast fix
許元豪9ee4c1b40d42
diff --git a/app/server/agents/index.ts b/app/server/agents/index.tsindex 1391891..20dc7c7 100644--- a/app/server/agents/index.ts+++ b/app/server/agents/index.ts@@ -104,7 +104,9 @@ export function runAgent({ kind, cwd, prompt, sessionId, onEvent = () => {}, sig// Windows: npm shims (claude.cmd) need a shell; args are fixed literals, the prompt goes through stdin.// its own process group (POSIX), so a cancel stops the renders and browsers it started too, not only the CLIconst child = spawn(cmd, args, { cwd, shell: IS_WIN, ...treeOpts, env: { ...process.env, HYPERFRAMES_NO_TELEMETRY: '1', DO_NOT_TRACK: '1' } });- if (signal) { if (signal.aborted) killTree(child); else signal.addEventListener('abort', () => killTree(child), { once: true }); }+ // the signal lives as long as the whole flow: drop the listener when this turn ends, so finished children aren't killed (or kept) later+ const onAbort = () => killTree(child);+ if (signal) { if (signal.aborted) killTree(child); else signal.addEventListener('abort', onAbort, { once: true }); }lines(child.stdout, (l) => {let obj: Json; try { obj = JSON.parse(l); } catch { return; }(isClaude ? parseClaude : parseCodex)(obj, emit, st);@@ -113,6 +115,7 @@ export function runAgent({ kind, cwd, prompt, sessionId, onEvent = () => {}, siglines(child.stderr, (l) => { err += l + '\n'; if (!/^\s*$/.test(l) && !/DeprecationWarning|ExperimentalWarning/.test(l)) emit({ type: 'error', text: short(l, 400) }); });child.on('error', (e) => { emit({ type: 'error', text: `${cmd} failed to start: ${e.message}` }); });child.on('close', (code) => {+ signal?.removeEventListener('abort', onAbort);if (code !== 0) st.ok = false;else if (!isClaude && st.ok === false && !err) st.ok = true;onEvent({ type: 'done', ok: st.ok, text: st.text, cost: st.cost });diff --git a/app/server/cast.ts b/app/server/cast.tsindex dfe01a2..36b9e27 100644--- a/app/server/cast.ts+++ b/app/server/cast.ts@@ -27,10 +27,10 @@ export async function castGate(id: string, prev: Pipeline): Promise<boolean> {chat(id, 'system', L(id, `角色關:${chars.length} 個角色各自由一組審查+修正同時進行`, `Characters: reviewing and fixing ${chars.length} character${chars.length > 1 ? 's' : ''} in parallel`));const shared: SharedItem[] = [];let broken = null as TurnResult | null; // the first agent turn that failed: reported as itself, not as "didn't pass review"- const one = async (c: CastMember): Promise<CastResult> => {+ const one = async (c: CastMember, recheck = false): Promise<CastResult> => {const reviewFile = join(d, 'out', 'check', 'cast', `review_${c.id}.json`);// resuming a character that stopped at its round limit: its last review is still current, so fix those issues first- const reuse = keep[c.id]?.state === 'failed' && existsSync(reviewFile);+ const reuse = !recheck && keep[c.id]?.state === 'failed' && existsSync(reviewFile); // a re-check after a shared fix always reviews afreshconst { end, last } = await reviewFix<Review>({review: async (round) => {setC(c.id, { state: 'reviewing', round });@@ -63,7 +63,7 @@ export async function castGate(id: string, prev: Pipeline): Promise<boolean> {const f = await turn(id, 'cast_fix', { issues: [...shared], round: 'shared', shared: true }, ['out/check/cast/sheet.jpg'], { who: 'director' });if (!f.ok) return fail(id, 'producing', f);shared.length = 0;- res = await Promise.all(chars.map((c, i) => (res[i] === 'passed' || res[i] === 'shared' ? one(c) : res[i])));+ res = await Promise.all(chars.map((c, i) => (res[i] === 'passed' || res[i] === 'shared' ? one(c, true) : res[i])));if (broken) return fail(id, 'producing', broken);if (res.includes('needs')) return pause(id);}diff --git a/app/server/pipeline.test.ts b/app/server/pipeline.test.tsindex 51a4c5d..c95834e 100644--- a/app/server/pipeline.test.ts+++ b/app/server/pipeline.test.ts@@ -27,6 +27,7 @@ interface Scenario {crash?: (step: string) => string | null; // this turn fails with that error text, writing nothingholdMs?: (step: string) => number; // this turn takes that long (ends early when cancelled)broken?: (step: string) => 'once' | 'always' | null; // its JSON files come out unreadable; 'once': the format fix repairs them+ say?: (step: string) => string | null; // this turn succeeds and replies with that text}const pending = new Map<string, { files: [string, unknown][]; always: boolean }>(); // per project: the good files a format fix writeslet S: Scenario;@@ -110,7 +111,7 @@ async function fakeAgent({ cwd, prompt, onEvent, signal }: AgentRun) {for (const [f] of json) put(dir, f, '{ not json');}onEvent?.({ type: 'session', id: `sess-${calls.length}` });- return { sessionId: `sess-${calls.length}`, text: `did ${name}`, ok: true, code: 0, stderr: '', lastError: '' };+ return { sessionId: `sess-${calls.length}`, text: S.say?.(name) || `did ${name}`, ok: true, code: 0, stderr: '', lastError: '' };}function put(dir: string, f: string, v: unknown) {const p = join(dir, f); mkdirSync(dirname(p), { recursive: true });@@ -416,6 +417,13 @@ describe('one flow per project', () => {assert.ok(!calls.includes('assemble'));});+ test('a turn that finished is not stopped for mentioning a rate limit or quota', async () => {+ S = base({ say: (s) => (s === 'build:C1' ? 'yt-dlp hit a rate limit, retried, done' : s === 'shot_qa:S2:1' ? 'within quota' : null) });+ const id = newProject('plan_review');+ await J.approve(id);+ assert.equal(J.load(id).stage, 'done');+ });+test('an agent that fails on the shot line is reported as that error, not as a part to judge', async () => {S = base({ crash: (s) => (s === 'build:C2' ? 'segfault' : null) });const id = newProject('plan_review');diff --git a/app/server/turn.ts b/app/server/turn.tsindex 37bfe1d..ea12f90 100644--- a/app/server/turn.ts+++ b/app/server/turn.ts@@ -74,8 +74,9 @@ export async function turn<P extends Phase>(id: string, phase: P, vars: StepVarsif (missing.length && r.ok && load(id).retryPending) missing = missing.filter((f) => !existsSync(join(d, f)));if (load(id).retryPending) update(id, (x) => { delete x.retryPending; });if (r.text) chat(id, session === 'fresh' ? 'critic' : session === 'director' ? 'agent' : 'builder', r.text, { phase, who: label });- // an account limit is the real cause, even when it also left outputs missing: say so plainly- const limit = [r.lastError, r.text, r.stderr].find((t) => t && LIMIT.test(t));+ // an account limit is the real cause, even when it also left outputs missing: say so plainly. Only for a turn that+ // failed: a finished one may mention "rate limit" or "quota" (yt-dlp output, a reviewer's notes) without being stopped by one+ const limit = (!r.ok || missing.length) && [r.lastError, r.text, r.stderr].find((t) => t && LIMIT.test(t));if (limit) return { ok: false, why: 'limit', text: r.text, missing, detail: limit.slice(-300) };if (!r.ok && !missing.length) return { ok: false, why: 'crashed', text: r.text, detail: r.stderr.slice(-300) };if (missing.length) return { ok: false, why: 'missing', text: r.text, missing };