The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.
TypeScript agent-skillsagentic-aiai-agentsai-videobyokclaude-codecodexdeepseek-harnessdsh-plugingenerative-ailocal-firstmcpmotionmotion-graphicsmultimodalopenmotionreverse-engineeringvideo-editingvideo-generationworkbuddy
fix(motion): preserve rational export rates and refresh catalog warnings (#200)
open-design-crew[bot]82bae3054df7
diff --git a/server.ts b/server.tsindex fa31c71f..0be62bd0 100644--- a/server.ts+++ b/server.ts@@ -74,7 +74,8 @@ export async function renderNext(store: WorkspaceStore, runtimeRoot: string, traawait mkdir(path.dirname(output), { recursive: true });// The service owns this job; a short-lived Agent client must not cancel it.await stage('rendering');- const result = await runHyperframes(runtimeRoot, directory, ['render', '.', '--output', output, '--format', 'mp4', ...(job.phase1 ? ['--fps', String(job.expected!.fps)] : []), '--json'], 25 * 60_000, { HYPERFRAMES_RENDER_DETACHED: '1' }, control.signal);+ // Let the engine read the snapshot's exact data-fps (including rational rates).+ const result = await runHyperframes(runtimeRoot, directory, ['render', '.', '--output', output, '--format', 'mp4', '--json'], 25 * 60_000, { HYPERFRAMES_RENDER_DETACHED: '1' }, control.signal);await writeFile(path.join(store.directory, 'jobs', job.id, 'render.log'), result.stdout + '\n' + result.stderr, { mode: 0o600 });if (result.code) throw new Error('Hyperframes render 失败:' + (result.stderr || result.stdout).slice(-1800));// Never label an absent or non-MP4 output as completed, even after exit code 0.diff --git a/studio/src/i18n/ConnectionI18n.test.ts b/studio/src/i18n/ConnectionI18n.test.tsindex d5cd769a..7a317138 100644--- a/studio/src/i18n/ConnectionI18n.test.ts+++ b/studio/src/i18n/ConnectionI18n.test.ts@@ -5,7 +5,37 @@ import { mountConnection } from '../../../web/connect';import { dictionaries, languages, translate, type Locale } from './messages';let controller: ReturnType<typeof mountConnection> | undefined;-afterEach(() => { controller?.destroy(); controller = undefined; document.body.replaceChildren(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });+afterEach(() => { controller?.destroy(); controller = undefined; document.body.replaceChildren(); vi.restoreAllMocks(); vi.unstubAllGlobals(); vi.useRealTimers(); });++it('polls cache warnings independently of publication changes and preserves gallery cards', async () => {+ vi.useFakeTimers();+ vi.stubGlobal('matchMedia', () => ({ matches: false, addEventListener() {}, removeEventListener() {} }));+ vi.stubGlobal('IntersectionObserver', class { observe() {} disconnect() {} });+ let warning: string | undefined;+ const info = { version: '0.6.3', previewUrl: 'http://localhost:4173', transport: { type: 'stdio', command: 'node', args: ['mcp.ts'] }, tools: [] };+ const template = { id: 'prism', title: 'Published template', tags: [], collection: 'example', kind: 'prism' };+ vi.stubGlobal('fetch', vi.fn(async (url: string) => Response.json(url.endsWith('/integration') ? info : {+ items: [template], total: 1, entryTotal: 1, catalogTotal: 1, offset: 0, next: null,+ catalogVersion: 'same-publication', warning,+ })));+ const root = document.createElement('div');+ root.innerHTML = '<input id="template-search"><button id="connection-templates"></button>' + page;+ document.body.append(root);+ controller = mountConnection(root, { locale: 'en', t: message => message, close() {}, useTemplate() {} });+ controller.resume();+ await vi.advanceTimersByTimeAsync(1);+ const card = root.querySelector('[data-template-id]');+ expect(card).not.toBeNull();+ warning = 'Template refresh failed; using cached catalogue';+ await vi.advanceTimersByTimeAsync(5_000);+ expect(root.querySelector<HTMLElement>('#catalog-error')!.hidden).toBe(false);+ expect(root.querySelector('#catalog-error-text')!.textContent).toBe(warning);+ expect(root.querySelector('[data-template-id]')).toBe(card);+ warning = undefined;+ await vi.advanceTimersByTimeAsync(5_000);+ expect(root.querySelector<HTMLElement>('#catalog-error')!.hidden).toBe(true);+ expect(root.querySelector('[data-template-id]')).toBe(card);+});it('updates live dialog labels while preserving the chosen client, search, preview and copied instructions', async () => {vi.stubGlobal('matchMedia', () => ({ matches: false, addEventListener() {}, removeEventListener() {} }));diff --git a/studio/src/motion/HomeTemplates.test.tsx b/studio/src/motion/HomeTemplates.test.tsxindex 77997320..b82576d3 100644--- a/studio/src/motion/HomeTemplates.test.tsx+++ b/studio/src/motion/HomeTemplates.test.tsx@@ -78,6 +78,24 @@ it('Prism templates open as editable projects and published catalog changes refrexpect(state.open).toHaveBeenCalledTimes(1);});+it('updates and clears cache warnings without resetting an unchanged template list', async () => {+ let warning: string | undefined;+ fetcher.mockImplementation(async () => Response.json({+ items: [{ ...builtin, kind: 'prism' }], total: 1, entryTotal: 1, catalogTotal: 1,+ offset: 0, next: null, catalogVersion: 'same-publication', warning,+ }));+ await render();+ const card = container.querySelector('.motion-home-template');+ warning = '模板更新失败,使用已缓存目录:HTTP 503';+ await act(async () => { await vi.advanceTimersByTimeAsync(5_000); });+ expect(container.querySelector('[role="status"]')?.textContent).toContain(warning);+ expect(container.querySelector('.motion-home-template')).toBe(card);+ warning = undefined;+ await act(async () => { await vi.advanceTimersByTimeAsync(5_000); });+ expect(container.querySelector('[role="status"]')).toBeNull();+ expect(container.querySelector('.motion-home-template')).toBe(card);+});+it.each(['de', 'ja', 'ru'] as const)('keeps Prism editing and project guards while localizing labels in %s', async locale => {const id = 'hf-moment-M1147';const warning = '模板更新失败,使用已缓存目录:HTTP 503';diff --git a/studio/src/motion/HomeTemplates.tsx b/studio/src/motion/HomeTemplates.tsxindex df9445ac..1bf5008c 100644--- a/studio/src/motion/HomeTemplates.tsx+++ b/studio/src/motion/HomeTemplates.tsx@@ -46,7 +46,10 @@ export function HomeTemplates({ onSelect }: { onSelect?: (template: GalleryTemplconst timer = setInterval(() => {if (document.visibilityState === 'hidden') return;void motionApi<TemplatePage>('/template-catalog?limit=1', { signal: controller.signal }).then(next => {+ if (controller.signal.aborted) return;if (next.catalogVersion !== page.catalogVersion) { setOffset(0); setPage(null); retry(value => value + 1); }+ else setPage(previous => previous && previous.catalogVersion === next.catalogVersion && previous.warning !== next.warning+ ? { ...previous, warning: next.warning } : previous);}).catch(() => {});}, 5_000);return () => { clearInterval(timer); controller.abort(); };diff --git a/tests/phase1-runtime.test.ts b/tests/phase1-runtime.test.tsindex 25ccb253..0031fb06 100644--- a/tests/phase1-runtime.test.ts+++ b/tests/phase1-runtime.test.ts@@ -3,12 +3,28 @@ import assert from 'node:assert/strict';import { readFile, writeFile, access } from 'node:fs/promises';import path from 'node:path';import { fixture } from './fixtures.ts';-import { startServer } from '../server.ts';+import { renderNext, startServer } from '../server.ts';import { rpc } from '../mcp.ts';-import { delay } from '../hyperframes.ts';+import { delay, pluginRoot } from '../hyperframes.ts';const film = (duration = 1) => `<!doctype html><html><head><meta charset="utf-8"><script src="assets/gsap.min.js"></script><style>body{margin:0}#main{position:relative;width:320px;height:180px;background:#d3e7ae;overflow:hidden}#box{position:absolute;top:60px;left:20px;width:40px;height:40px;background:#203021}</style></head><body><div id="main" data-composition-id="main" data-start="0" data-duration="${duration}" data-width="320" data-height="180" data-fps="10"><div id="box"></div></div><script>const tl=gsap.timeline({paused:true});tl.fromTo('#box',{x:0},{x:200,duration:${duration},ease:'none'},0);window.__timelines={main:tl};</script></body></html>`;+test('phase1 renders the snapshot at its authored rational frame rate', { timeout: 120_000 }, () => fixture(async store => {+ for (const numerator of [24_000, 30_000]) {+ const saved = await store.writeFiles((await store.get()).revision, [{+ path: 'index.html', content: film().replace('data-fps="10"', `data-fps="${numerator}/1001"`),+ }]);+ const job = await store.requestExport(saved.revision, { phase1: true, audio: 'silent' });+ // A later edit must not alter the frame rate in the immutable export snapshot.+ await store.writeFiles(saved.revision, [{ path: 'index.html', content: film() }]);+ await renderNext(store, pluginRoot);+ const completed = (await store.job(job.id))!;+ assert.equal(completed.state, 'completed', JSON.stringify(completed));+ assert.equal(completed.expected!.fps, numerator / 1001);+ assert.equal((completed.verification as any).status, 'passed');+ }+}));+test('real phase1 MCP, active Studio history, confirmed running cancellation and automatically verified MP4', { timeout: 180_000 }, () => fixture(async store => {const running = await startServer(store, 0, { editor: false });const address = running.server.address(); assert.ok(address && typeof address !== 'string');diff --git a/web/template-gallery.ts b/web/template-gallery.tsindex 0a4aa6d0..f87a00c6 100644--- a/web/template-gallery.ts+++ b/web/template-gallery.ts@@ -19,6 +19,7 @@ export function mountTemplates(root: HTMLElement, options: {const lifetime = new AbortController();const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)');let catalogVersion: string | undefined;+ let catalogWarning: string | undefined;let active = false, enabled = false, category = 'featured', loaded = false, next: number | null = 0;let request: AbortController | undefined, sequence = 0, shown = 0, preview: GalleryTemplate | undefined;let previewCleanup = () => {}, rotation: ReturnType<typeof setInterval> | undefined, debounce: ReturnType<typeof setTimeout> | undefined;@@ -127,6 +128,11 @@ export function mountTemplates(root: HTMLElement, options: {button.disabled = !canCopy(); language.attribute(button, 'aria-label', 'Copy to recreate {title}', { title: template.title }); button.onclick = () => copyTemplate(template, button);actions.append(sourceSummary(template), button); details.append(heading, actions); card.append(createMedia(template), details); return card;}+ function updateWarning(warning?: string) {+ catalogWarning = warning;+ element('catalog-error').hidden = !warning;+ language.text(element('catalog-error-text'), warning || '');+ }async function load(reset: boolean) {if (!active) return;request?.abort(); const controller = new AbortController(); request = controller; const ticket = ++sequence;@@ -141,7 +147,7 @@ export function mountTemplates(root: HTMLElement, options: {if (!Array.isArray(page.items) || !Number.isSafeInteger(page.total)) throw new Error("Invalid template catalogue");if (ticket !== sequence || !active) return;catalogVersion = page.catalogVersion;- if (page.warning) { element('catalog-error').hidden = false; language.text(element('catalog-error-text'), page.warning); }+ updateWarning(page.warning);element('template-grid').append(...page.items.map(createCard)); shown += page.items.length; next = page.next; loaded = true;language.text(element('template-count'), page.total ? 'Groups: {shown} / {total} · Templates and clips: {entries}' : 'No matching templates. Try another name, creator or style.', { shown, total: page.total, entries: page.entryTotal });element('more-templates').hidden = next === null;@@ -156,8 +162,11 @@ export function mountTemplates(root: HTMLElement, options: {}const catalogTimer = setInterval(() => {if (!active || request || document.visibilityState === 'hidden' || !catalogVersion) return;+ const ticket = sequence;void fetch('/motion-api/template-catalog?limit=1', { signal: lifetime.signal }).then(response => response.ok ? response.json() : null).then(page => {- if (active && page?.catalogVersion && page.catalogVersion !== catalogVersion) void load(true);+ if (!active || lifetime.signal.aborted || request || ticket !== sequence || !page?.catalogVersion) return;+ if (page.catalogVersion !== catalogVersion) void load(true);+ else if (page.warning !== catalogWarning) updateWarning(page.warning);}).catch(() => {});}, 5_000);lifetime.signal.addEventListener('abort', () => clearInterval(catalogTimer), { once: true });