Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/cli/src/studio-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ export async function startStudioServer(ctx: CliContext, port: number): Promise<
process.stderr.write(
`[studio:export] proj=${projectId} done in ${ms}ms → ${outputPath}\n`,
);
sse({ type: 'export_done', output_path: outputPath, project, elapsed_ms: ms });
// Compute the actual video duration to show in the UI (not the render wall-clock time).
const videoDurationSec = (project.frames && project.frames.length > 0)
? project.frames.reduce((s, f) => s + (f.durationSec || 0), 0)
: (project.preferences.durationTargetSec ?? null);
sse({ type: 'export_done', output_path: outputPath, project, elapsed_ms: ms, duration_sec: videoDurationSec });
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
process.stderr.write(`[studio:export] proj=${projectId} failed: ${msg}\n`);
Expand Down Expand Up @@ -958,6 +962,16 @@ export async function startStudioServer(ctx: CliContext, port: number): Promise<
let textChunks = 0;
let summaryLine = '';

// Persist user duration preference at generate time so exportMp4 can
// honor it regardless of single-frame vs multi-frame path.
if (phaseInfo.phase === 'generate' && phaseInfo.inputs.collected) {
const parsedDur = Number(phaseInfo.inputs.collected.duration ?? '') || 0;
if (parsedDur > 0) {
project.preferences = { ...project.preferences, durationTargetSec: parsedDur };
await ctx.projects.save(project);
}
}

// ---- generate-phase: multi-frame path runs split (graph + per-frame) ----
// Empirically claude --print returns 1 byte ~50% of the time when asked
// to emit a graph and 4-6 full HTML pages in a single response. Each
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,24 @@ export class ProjectOrchestrator {
const tmpl = this.deps.templates.get(project.templateId);
const adapter = this.deps.engines.get(tmpl.engine);

// Use the agent-generated HTML if available; fall back to the template source.
const singleFrameTemplateRef = project.lastPreviewHtmlPath
? { id: tmpl.id, engine: tmpl.engine, sourcePath: project.lastPreviewHtmlPath }
: templateRefFromMeta(tmpl);
// Honor the user-set duration; fall back to 'auto' so the adapter probes animation length.
const singleFrameDuration = project.preferences.durationTargetSec ?? 'auto';
const singleFrameDurationMode = typeof singleFrameDuration === 'number' ? 'explicit' as const : undefined;

await adapter.render(
{
template: templateRefFromMeta(tmpl),
template: singleFrameTemplateRef,
variables: project.variables,
config: {
format: 'mp4',
resolution: project.preferences.resolution ?? { width: 1920, height: 1080 },
fps: project.preferences.fps ?? 60,
duration: 'auto',
duration: singleFrameDuration,
...(singleFrameDurationMode && { durationMode: singleFrameDurationMode }),
outputPath,
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/project-studio/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async function startExportStream() {
state.exporting = false;
state.exportProgress = null;
if (ev.project) state.selected = ev.project;
const seconds = ev.elapsed_ms ? `${(ev.elapsed_ms / 1000).toFixed(1)}s` : '';
const seconds = ev.duration_sec != null ? `${Number(ev.duration_sec).toFixed(1)}s` : '';
state.messages.push({
role: 'preview-event',
content: seconds ? t('export.done_seconds', { seconds }) : t('export.done_no_seconds'),
Expand Down