Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: share Code Animation pacing rule and derive brief merge from one field list

[._.]/ Adam Eivy4e60010b6101
diff --git a/client/src/pages/CodeAnimation.jsx b/client/src/pages/CodeAnimation.jsx
index 83c37e8805..d8307514cc 100644
--- a/client/src/pages/CodeAnimation.jsx
+++ b/client/src/pages/CodeAnimation.jsx
@@ -410,16 +410,11 @@ export default function CodeAnimation() {
// builds the prompt.
const handleWriteBrief = async () => {
if (!canWriteBrief) return;
- const startingBrief = {
- title: draft.title,
- concept: draft.concept,
- cast: draft.cast,
- onScreenText: draft.onScreenText,
- styleNotes: draft.styleNotes,
- };
+ const ideaInput = toBriefIdeaInput(draft);
+ const startingBrief = ideaInput.current;
setWritingBrief(true);
const result = await generateCodeAnimationBrief({
- ...toBriefIdeaInput(draft),
+ ...ideaInput,
providerId: briefProviderId || undefined,
model: briefModel || undefined,
effort: briefEffort || undefined,
@@ -429,17 +424,19 @@ export default function CodeAnimation() {
});
setWritingBrief(false);
if (!result?.brief) return;
- const { title, concept, cast = '', onScreenText, styleNotes } = result.brief;
- // Style refinements live in the Style section, not the brief — only replace
- // the artist's own notes when the writer actually asked for a refinement.
- setDraft((previous) => ({
- ...previous,
- ...(previous.title === startingBrief.title ? { title } : {}),
- ...(previous.concept === startingBrief.concept ? { concept } : {}),
- ...(previous.cast === startingBrief.cast ? { cast } : {}),
- ...(previous.onScreenText === startingBrief.onScreenText ? { onScreenText } : {}),
- ...(styleNotes && previous.styleNotes === startingBrief.styleNotes ? { styleNotes } : {}),
- }));
+ // Fill only the fields the artist left untouched while the writer ran.
+ setDraft((previous) => {
+ const next = { ...previous };
+ for (const [key, before] of Object.entries(startingBrief)) {
+ const written = result.brief[key];
+ if (typeof written !== 'string' || previous[key] !== before) continue;
+ // Style refinements live in the Style section, not the brief — only replace
+ // the artist's own notes when the writer actually asked for a refinement.
+ if (key === 'styleNotes' && !written) continue;
+ next[key] = written;
+ }
+ return next;
+ });
toast.success('Brief written — edit it before building the prompt');
};
diff --git a/server/services/codeAnimation/brief.js b/server/services/codeAnimation/brief.js
index bc83af45f4..ffaa9c6524 100644
--- a/server/services/codeAnimation/brief.js
+++ b/server/services/codeAnimation/brief.js
@@ -28,7 +28,7 @@ import { isNonBlankStr, trimTo } from '../../lib/textUtils.js';
import { extractJson } from '../../lib/jsonExtract.js';
import { renderCanonForPrompt } from '../../lib/universePromptRenderers.js';
import { ServerError } from '../../lib/errorHandler.js';
-import { CODE_ANIMATION_LIMITS, moodBoardSection, universeStyleLines } from './prompt.js';
+import { CODE_ANIMATION_LIMITS, PACING_RULE, moodBoardSection, universeStyleLines } from './prompt.js';
// What separates a studio short from a moving screensaver, distilled from how
// strong animation briefs are written. Static text — the per-film specifics
@@ -36,7 +36,7 @@ import { CODE_ANIMATION_LIMITS, moodBoardSection, universeStyleLines } from './p
const DIRECTING_PRINCIPLES = `HOW TO DIRECT IT:
- The film in one line: a premise that escalates and pays off with a reveal, twist, or loop. If you can't say it in one sentence, it's too complicated for this length.
- Wordless and readable: the story must land with zero dialogue. Characters act through their eyes, posture, and one signature expressive feature (an antenna, a tail, ears, a scarf), plus a small vocabulary of non-verbal sounds.
-- Hook and density: open cold, mid-action, and hook within two seconds. Give the audience a new visual payoff every 3–5 seconds, and escalate — each repetition of a device bigger or stranger than the last (the rule of three works).
+- Hook and density: ${PACING_RULE}. Escalate — each repetition of a device bigger or stranger than the last (the rule of three works).
- An emotional arc for the lead, beat by beat (e.g. delighted → curious → worried → determined), and one quiet, kind beat inside the chaos — often a small object or motif they protect — so we care.
- A signature device: one distinctive, recurring visual mechanism (a transition, a transformation, a rule of the world) that is this film's own, varied each time it recurs.
- Scale and camera: choose a point of view that makes the world cinematic (a tiny character with a camera at their eye level turns a curb into a cliff), and say how the camera moves in each beat.
diff --git a/server/services/codeAnimation/brief.test.js b/server/services/codeAnimation/brief.test.js
index b1a206777d..b6dc758681 100644
--- a/server/services/codeAnimation/brief.test.js
+++ b/server/services/codeAnimation/brief.test.js
@@ -41,7 +41,6 @@ describe('buildCodeAnimationBriefPrompt', () => {
it('asks for a director\'s plan: a timed beat sheet and a rig-ready character bible', () => {
const prompt = buildCodeAnimationBriefPrompt({ seedIdea: 'a robot realizes its world is generated', format: FORMAT });
expect(prompt).toContain('HOW TO DIRECT IT');
- expect(prompt).toContain('new visual payoff every 3–5 seconds');
expect(prompt).toContain('each led by its time range covering the full 20 seconds');
expect(prompt).toContain('identity lock');
});
diff --git a/server/services/codeAnimation/prompt.js b/server/services/codeAnimation/prompt.js
index b5ca4d6daf..0c269df52d 100644
--- a/server/services/codeAnimation/prompt.js
+++ b/server/services/codeAnimation/prompt.js
@@ -199,7 +199,7 @@ function castSection(cast) {
return `CHARACTERS — the design bible (non-negotiable; every frame must stay on-model):
${trimTo(cast, CODE_ANIMATION_LIMITS.castMax)}
-Build each lead ONCE as a 2D cutout rig before animating anything:
+Build each lead ONCE as a cutout rig (2D, or its equivalent in your renderer) before animating anything:
- A part hierarchy with pivots (root → body → head → face; limbs as segmented chains; appendages like antennae, tails, ears, or scarves as their own joints), drawn from functions that take pose parameters.
- A procedural face: eyes, lids, pupils, brows, and mouth driven by parameters (size, lid cuts, pupil position, highlight, squash/stretch, special shapes such as hearts, stars, spirals, flat lines). Implement every named expression as a parameter preset and blend between presets; blink in 3–4 frames.
- Secondary motion on damped springs — appendages, hair, cloth, suspension, head lag when the body accelerates or brakes — so nothing moves rigidly.
@@ -208,19 +208,21 @@ Build each lead ONCE as a 2D cutout rig before animating anything:
- Locomotion that is physically honest: wheels rotate by distance traveled, feet plant without sliding, stops land with weight.`;
}
+// The pacing bar both halves hold a film to — the brief writer plans to it and
+// the coding model stages to it — stated once so the two can't drift apart.
+export const PACING_RULE = 'open cold, mid-action, and hook within two seconds; give the audience a new visual payoff every 3–5 seconds; vary each repeated device (direction, noise seed, timing) so it never feels copy-pasted';
+
// The craft bar. A one-shot HTML file can't run a multi-session render-and-
// review loop, so the loop is folded into how the model structures the code
// and what it checks before answering.
-function directionSection() {
- return `DIRECTION — make it feel like a studio short, not a tech demo:
-- Structure the code like a production: a shot/beat timeline (an array of { start, end, … } entries mapped from the brief's timestamps), a virtual camera (position, zoom, rotation, seeded handheld micro-shake, shake impulses, tilts, dolly moves), a scene/world layer system shared by every shot, the character rigs, the transitions, and a final finish pass.
+const DIRECTION = `DIRECTION — make it feel like a studio short, not a tech demo:
+- Structure the code like a production: a shot/beat timeline (an array of { start, end, … } entries at the brief's timestamps; where it gives none, time the beats yourself: establish → develop → climax → resolve), a virtual camera (position, zoom, rotation, seeded handheld micro-shake, shake impulses, tilts, dolly moves), a scene/world layer system shared by every shot, the character rigs, the transitions, and a final finish pass.
- Depth and scale (unless the art style is deliberately flat): at least four parallax layers per scene with atmospheric perspective (haze and desaturation with distance), a shallow-focus feel (blurred foreground elements), and a camera height chosen to sell the characters' scale.
-- Lighting: key, fill, and rim on the characters as gradient overlays and multiplied shadow layers; glowing elements cast light on nearby surfaces. Finish the whole frame with a pass that suits the style (e.g. subtle grain and a gentle vignette).
+- Lighting: key, fill, and rim on the characters (gradient overlays and multiplied shadow layers in 2D, shader terms in WebGL); glowing elements cast light on nearby surfaces. Finish the whole frame with a pass that suits the style (e.g. subtle grain and a gentle vignette).
- Performance: anticipation, squash and stretch, overlap, easing, and deliberate holds — a held reaction (a one-second deadpan, a freeze) is what lets a gag land. Emotion reads through the eyes, posture, and signature appendage, never through captions.
-- Pacing: open cold and hook in the first two seconds; give the audience a new visual payoff every 3–5 seconds; vary each repeated device (transition direction, noise seed, timing) so it never feels copy-pasted.
+- Pacing: ${PACING_RULE}.
- Readability: compose on thirds, and keep faces, eyes, and any text legible at phone size (about 360px wide); typed on-screen text types at a human rhythm with small pauses.
- Endings: the player loops the film — when the brief ends by returning to its opening, match the final frame's framing, lighting, and motion to t=0 so the cut back feels intentional.`;
-}
// The critique pass the reference workflow runs on rendered stills, as a
// pre-answer check against the failures one-shot animation code shows most.
@@ -300,9 +302,8 @@ export function buildCodeAnimationPrompt({
const imagesText = referenceImagesSection(referenceImages, delivery);
if (imagesText) sections.push(imagesText);
sections.push(`SOUND:\n${audioSection({ audio, soundtrack, durationSeconds })}`);
- sections.push(`FORMAT: ${format.aspectRatio} at ${width}×${height}px, ${fps}fps, ${durationSeconds}s. ${RENDERER_GUIDANCE[renderer] || RENDERER_GUIDANCE.auto}
-Stage the brief's beats at their timestamps; where it gives none, plan the film as timed beats yourself (establish → develop → climax → resolve).`);
- sections.push(directionSection());
+ sections.push(`FORMAT: ${format.aspectRatio} at ${width}×${height}px, ${fps}fps, ${durationSeconds}s. ${RENDERER_GUIDANCE[renderer] || RENDERER_GUIDANCE.auto}`);
+ sections.push(DIRECTION);
sections.push(runtimeContract({ width, height, fps, durationSeconds, interactive, hasAudio: !!audio }));
sections.push(SELF_REVIEW);
sections.push(`OUTPUT: Return ONLY the finished HTML document in a single \`\`\`html fenced code block, starting with <!DOCTYPE html>. No explanation before or after it.${delivery === 'cli' ? ' Do not create or edit any files — print the document as your final answer.' : ''}`);
diff --git a/server/services/codeAnimation/prompt.test.js b/server/services/codeAnimation/prompt.test.js
index 54ea1a776d..3d55b7f4bd 100644
--- a/server/services/codeAnimation/prompt.test.js
+++ b/server/services/codeAnimation/prompt.test.js
@@ -39,14 +39,12 @@ describe('buildCodeAnimationPrompt', () => {
});
expect(withCast).toContain('CHARACTERS — the design bible');
expect(withCast).toContain('Wick — a palm-sized paper lantern whose wire handle droops when sad');
- expect(withCast).toContain('procedural face');
expect(buildCodeAnimationPrompt({ concept: 'x', format })).not.toContain('CHARACTERS —');
});
it('holds every film to the direction bar and a pre-answer self-review', () => {
const prompt = buildCodeAnimationPrompt({ concept: 'x', format });
expect(prompt).toContain('DIRECTION — make it feel like a studio short');
- expect(prompt).toContain('virtual camera');
expect(prompt).toContain('SELF-REVIEW before you answer');
// The self-review follows the runtime contract, right before the output rule.
expect(prompt.indexOf('SELF-REVIEW')).toBeGreaterThan(prompt.indexOf('RUNTIME CONTRACT'));