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

measure the overlay guard on the canvas, refuse copy compositing, and say what it does not catch

[._.]/ Adam Eivybe20d295c7c9
diff --git a/server/services/codeAnimation/prompt.js b/server/services/codeAnimation/prompt.js
index ba6c7b2f09..3d88b07669 100644
--- a/server/services/codeAnimation/prompt.js
+++ b/server/services/codeAnimation/prompt.js
@@ -463,7 +463,7 @@ export function buildMixedMediaDocumentPrompt({ title, song, palette, treatment,
renderer === 'three' ? '' : CODE_VIDEO_RULES.replace('- Canvas 2D only. No external assets, fonts, or network.', '- Canvas 2D only. No network, remote URLs, filesystem paths or font loading. The host binds only the listed selected project assets; draw over footage/stills without obscuring them, and draw the entire authored world for card scenes, including characters, environments, camera staging, lighting and narrative actions. Local packaged fonts MV Mono, MV Cond and MV Stencil are available; authored titles are allowed, but do not duplicate host subtitles.'),
MUSIC_VIDEO_DIRECTION,
MUSIC_VIDEO_CHOREOGRAPHY,
- renderer === 'three' ? 'The authored Three.js world receives no selected-media handles; all visual staging uses geometry and the host text overlay.' : 'env additionally has mediaKind (video, image or null) and visualLayer (footage, still, card or code — a code shot has no media and is drawn entirely by the section). The host has already drawn the selected media at its in/out time: when env.mediaKind is set, the section is an overlay, so never fill or clear the whole canvas (a full-frame fill is reduced to a faint wash) and keep the footage readable; paint full backgrounds only when env.mediaKind is null. Do not read DOM or load assets in a section function. Use seeded arithmetic from env.frame for visual motion. Keep repeated hooks related but deliberately vary their action.',
+ renderer === 'three' ? 'The authored Three.js world receives no selected-media handles; all visual staging uses geometry and the host text overlay.' : 'env additionally has mediaKind (video, image or null) and visualLayer (footage, still, card or code — a code shot has no media and is drawn entirely by the section). The host has already drawn the selected media at its in/out time: when env.mediaKind is set, the section is an overlay: never fill, clear or paint the whole canvas (no full-frame fillRect, path fill or drawImage; the host reduces a full-frame fillRect to a faint wash) and keep the footage readable; paint full backgrounds only when env.mediaKind is null. Do not read DOM or load assets in a section function. Use seeded arithmetic from env.frame for visual motion. Keep repeated hooks related but deliberately vary their action.',
'NARRATIVE CLOCK: song.narrativeEvents are resolved absolute startFrame/endFrame bindings. env.events supplies active events with progress and counter value; env.reactiveGain is bounded by the section gain/maxGain and is zero during silence. The host freezes song time, media and graphics for silence, and draws exact event text/counters/motif labels after your function. Use the narrativeFunction, motif and mediumRationale to motivate your graphic actions; do not duplicate event text or infer new onsets. Prefer code/stills/selected media for exact text and graphics. Footage is for actions that need it and must already be selected.',
`SHARED STYLE CONTRACT:\n${JSON.stringify(sharedStyle || { palette, treatment: { brief: treatment?.brief || null, motifs: treatment?.arc?.motifs || [], styleLook: treatment?.styleLook || null }, visualSpec, styleLines })}`,
directionContext ? `APPROVED CAST & SETS DEFINITIONS AND RULES:\n${directionContext}` : '',
diff --git a/server/services/musicVideo/documentTemplates/layered/engine.js b/server/services/musicVideo/documentTemplates/layered/engine.js
index eb749b3fd0..003357e1d9 100644
--- a/server/services/musicVideo/documentTemplates/layered/engine.js
+++ b/server/services/musicVideo/documentTemplates/layered/engine.js
@@ -438,29 +438,41 @@
}
}
- // A view of ctx for authored code drawn over footage: a fill or clear covering most of the
- // canvas is limited to a translucent wash (clears are dropped), everything else passes
- // through. Authored functions are told to leave footage visible; this keeps it so when a
- // model paints a full-frame background anyway.
+ // A view of ctx for authored code drawn over footage: a fillRect or clearRect whose
+ // on-canvas area (after the current transform, clipped to the frame) covers most of it is
+ // limited to a translucent wash (clears are dropped), and the 'copy' composite mode, which
+ // replaces every pixel, is refused. Other full-frame paints (a canvas-sized path fill or
+ // drawImage) are not caught here; the prompt tells the model not to make them.
const FOOTAGE_WASH_ALPHA = 0.25;
function footageOverlayContext(target) {
- const covers = (w, h) => Math.abs(w * h) >= W * H * 0.9;
+ const covers = (x, y, w, h) => {
+ const m = typeof target.getTransform === 'function' ? target.getTransform() : null;
+ const map = (px, py) => (m ? [m.a * px + m.c * py + m.e, m.b * px + m.d * py + m.f] : [px, py]);
+ const pts = [map(x, y), map(x + w, y), map(x, y + h), map(x + w, y + h)];
+ const xs = pts.map((p) => p[0]); const ys = pts.map((p) => p[1]);
+ const cw = Math.max(0, Math.min(W, Math.max(...xs)) - Math.max(0, Math.min(...xs)));
+ const ch = Math.max(0, Math.min(H, Math.max(...ys)) - Math.max(0, Math.min(...ys)));
+ return cw * ch >= W * H * 0.9;
+ };
return new Proxy(target, {
get(obj, prop) {
if (prop === 'fillRect') {
return (x, y, w, h) => {
- if (!covers(w, h)) return obj.fillRect(x, y, w, h);
+ if (!covers(x, y, w, h)) return obj.fillRect(x, y, w, h);
const alpha = obj.globalAlpha;
obj.globalAlpha = Math.min(alpha, FOOTAGE_WASH_ALPHA);
obj.fillRect(x, y, w, h);
obj.globalAlpha = alpha;
};
}
- if (prop === 'clearRect') return (x, y, w, h) => { if (!covers(w, h)) obj.clearRect(x, y, w, h); };
+ if (prop === 'clearRect') return (x, y, w, h) => { if (!covers(x, y, w, h)) obj.clearRect(x, y, w, h); };
const value = Reflect.get(obj, prop, obj);
return typeof value === 'function' ? value.bind(obj) : value;
},
- set(obj, prop, value) { return Reflect.set(obj, prop, value, obj); },
+ set(obj, prop, value) {
+ if (prop === 'globalCompositeOperation' && value === 'copy') return true;
+ return Reflect.set(obj, prop, value, obj);
+ },
});
}
diff --git a/server/services/musicVideo/documentTemplates/layered/engine.overlay.test.js b/server/services/musicVideo/documentTemplates/layered/engine.overlay.test.js
index adf51616e4..b689240a95 100644
--- a/server/services/musicVideo/documentTemplates/layered/engine.overlay.test.js
+++ b/server/services/musicVideo/documentTemplates/layered/engine.overlay.test.js
@@ -8,10 +8,11 @@ const helper = engine.slice(engine.indexOf(' const FOOTAGE_WASH_ALPHA'), engine
const W = 1920; const H = 1080;
const footageOverlayContext = new Function('W', 'H', `${helper}\nreturn footageOverlayContext;`)(W, H);
-function fakeContext() {
+function fakeContext(transform = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }) {
const calls = [];
return {
- calls, globalAlpha: 1, fillStyle: '#000',
+ calls, globalAlpha: 1, fillStyle: '#000', globalCompositeOperation: 'source-over',
+ getTransform() { return transform; },
fillRect(x, y, w, h) { calls.push(['fillRect', w, h, this.globalAlpha]); },
clearRect(x, y, w, h) { calls.push(['clearRect', w, h]); },
beginPath() { calls.push(['beginPath']); },
@@ -28,14 +29,27 @@ describe('layered engine footage overlay guard', () => {
expect(ctx.globalAlpha).toBe(1);
});
- it('passes partial fills, other methods and property writes through unchanged', () => {
+ it('measures the on-canvas area: a mostly off-screen panel passes, a scaled unit fill is caught', () => {
+ const ctx = fakeContext();
+ footageOverlayContext(ctx).fillRect(-W * 0.8, 0, W, H);
+ expect(ctx.calls).toEqual([['fillRect', W, H, 1]]);
+ const scaled = fakeContext({ a: W, b: 0, c: 0, d: H, e: 0, f: 0 });
+ footageOverlayContext(scaled).fillRect(0, 0, 1, 1);
+ expect(scaled.calls).toEqual([['fillRect', 1, 1, 0.25]]);
+ });
+
+ it('refuses the copy composite mode and passes everything else through', () => {
const ctx = fakeContext();
const view = footageOverlayContext(ctx);
+ view.globalCompositeOperation = 'copy';
+ expect(ctx.globalCompositeOperation).toBe('source-over');
+ view.globalCompositeOperation = 'screen';
view.globalAlpha = 0.6;
view.fillStyle = '#fff';
view.fillRect(10, 10, 200, 100);
view.clearRect(0, 0, 50, 50);
view.beginPath();
+ expect(ctx.globalCompositeOperation).toBe('screen');
expect(ctx.fillStyle).toBe('#fff');
expect(ctx.calls).toEqual([['fillRect', 200, 100, 0.6], ['clearRect', 50, 50], ['beginPath']]);
});