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

address review (claude): cover the clear-before-draw and reserved-aspect contracts

[._.]/ Adam Eivyaaf5dde1d885
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index b90ab6515c..afc3322e33 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -25,7 +25,7 @@
## Sprite Manager
-- **[issue-2977] Loop Trimmer frames are pixel-crisp again** — the frame thumbnails and the playback preview in the Loop Trimmer rendered soft and washed-out, as if the artwork had been compressed, which made it impossible to judge a frame before saving a trim. Your artwork was never affected — the trimmer was shrinking each frame to a fraction of its real size to draw it, then blurrily stretching that back up. Frames now draw at their full source resolution with the same crisp pixel scaling every other sprite view uses, so what you review is exactly what gets saved. The transparency checkerboard behind each frame also keeps a consistent square size instead of turning into fine noise, and the frame grid no longer jumps as the strip finishes loading.
+- **[issue-2977] Loop Trimmer frames now render pixel-crisp** — the frame thumbnails and the playback preview in the Loop Trimmer looked soft and washed-out, as if the artwork had been compressed, which made it impossible to judge a frame before saving a trim. Your artwork was never affected — the trimmer was shrinking each frame to a fraction of its real size to draw it, then blurrily stretching that back up. Frames now draw at their full source resolution with the same crisp pixel scaling every other sprite view uses, so what you review is exactly what gets saved. The transparency checkerboard behind each frame is drawn by the page now instead of being baked into the shrunken frame, so its squares stay crisp and a fixed size rather than coming out blurry and oversized.
- **[issue-2978] Saving a loop trim now works on imported characters** — for a character whose walk cycles came in through the source-pipeline import, the Loop Trimmer would load, scrub, and play the animation perfectly, then fail on **Save trim** with "Packaged run manifest is missing or inconsistent" — after you'd already picked your frames, and with nothing saved. The imported artwork was never damaged; PortOS was simply looking for the packaged manifest under the wrong folder and giving up. Trims now save on imported characters, keep the real gait-phase labels (left-contact, left-passing, …) for each kept frame, and record the correct source strip. A run whose manifest went missing entirely now falls back to the strip's own geometry and still trims, while a manifest that's genuinely corrupt still refuses loudly instead of quietly guessing. The same lookup fixed approving an imported walk direction, which would have failed the same way.
- **Steer a directional-anchor re-roll with a correction note** — when a directional anchor comes out wrong (say the north-east pose grew a pocket on the arm that has none in every other view), re-rolling it with the same inputs tended to just reproduce the same mistake. Each unlocked anchor tile now has a small **Correction (optional)** box: type what to fix ("no pocket on the right sleeve") and hit **Regenerate**, and the note is appended to that pose's prompt as an explicit override so the new render actually diverges. The button reads **Generate** on the first render and **Regenerate** once candidates exist, the correction is per-direction (so eight different fixes don't collide), and it rides into the candidate's saved prompt so the image preview shows exactly what was asked for. Main-reference iteration is unchanged — it already has its own design-prompt box.
- **[issue-2964] The same correction note now steers a re-roll from the asset card too** — the correction box used to live only on the Reference Set's anchor grid, so re-rolling a directional-anchor candidate from its card in the Assets library ignored any fix you'd typed. Each anchor candidate card now carries the same correction affordance: click its note icon to type ("no pocket on the right sleeve") and hit **Regenerate**, and that guidance is appended to the pose's prompt exactly as it is from the grid. The two surfaces share one correction per direction, so a note you type in either place shows up in the other, and both re-rolls send the identical instruction.
diff --git a/client/src/components/sprites/LoopTrimmer.test.jsx b/client/src/components/sprites/LoopTrimmer.test.jsx
index 2cc09fbcfb..78886b72ea 100644
--- a/client/src/components/sprites/LoopTrimmer.test.jsx
+++ b/client/src/components/sprites/LoopTrimmer.test.jsx
@@ -21,7 +21,23 @@ import { trimSpriteWalk } from '../../services/apiSprites.js';
// jsdom has no 2D canvas; the component already guards a null context. Stub
// getContext to return null explicitly so the suite doesn't spam jsdom's
// "Not implemented: getContext" warning for every frame canvas it renders.
-HTMLCanvasElement.prototype.getContext = () => null;
+// The paint test below swaps in a recording context so the actual draw calls
+// can be asserted, then restores this default.
+const nullContext = () => null;
+HTMLCanvasElement.prototype.getContext = nullContext;
+
+// Records every 2D call a frame canvas makes, so the paint path (which is
+// otherwise invisible under the null-context stub) can be pinned.
+function recordingContext() {
+ const calls = [];
+ const ctx = {
+ imageSmoothingEnabled: true,
+ clearRect: (...args) => calls.push(['clearRect', ...args]),
+ drawImage: (...args) => calls.push(['drawImage', ...args]),
+ };
+ HTMLCanvasElement.prototype.getContext = () => ctx;
+ return { calls, ctx, restore: () => { HTMLCanvasElement.prototype.getContext = nullContext; } };
+}
// jsdom never fetches, so a real `new Image()` would never fire onload and the
// trimmer's cell geometry would stay 0×0 — the frame canvases would never
@@ -143,6 +159,31 @@ describe('LoopTrimmer', () => {
});
});
+ // Moving the checkerboard onto the box left the canvas transparent, which makes
+ // the clear-before-draw load-bearing: without it a frame swap composites the new
+ // cell over the previous one wherever the new cell is transparent (ghosting).
+ it('clears before each draw and copies the cell 1:1 with smoothing off', async () => {
+ const { calls, ctx, restore } = recordingContext();
+ try {
+ renderTrimmer();
+ await waitFor(() => expect(calls.some(([fn]) => fn === 'drawImage')).toBe(true));
+ const drawAt = calls.map(([fn], i) => (fn === 'drawImage' ? i : -1)).filter((i) => i >= 0);
+ drawAt.forEach((i) => {
+ // Every draw is immediately preceded by a full-surface clear.
+ expect(calls[i - 1]).toEqual(['clearRect', 0, 0, STRIP_CELL_PX, STRIP_CELL_PX]);
+ // 1:1 — source rect and destination rect are both the natural cell size,
+ // so drawImage never resamples. Source x lands on a cell boundary.
+ const [, , sx, sy, sw, sh, dx, dy, dw, dh] = calls[i];
+ expect([sy, sw, sh]).toEqual([0, STRIP_CELL_PX, STRIP_CELL_PX]);
+ expect([dx, dy, dw, dh]).toEqual([0, 0, STRIP_CELL_PX, STRIP_CELL_PX]);
+ expect(sx % STRIP_CELL_PX).toBe(0);
+ });
+ expect(ctx.imageSmoothingEnabled).toBe(false);
+ } finally {
+ restore();
+ }
+ });
+
it('puts the checkerboard on the frame box, not inside the canvas', async () => {
const { container } = renderTrimmer();
await waitFor(() => expect(container.querySelectorAll('canvas').length).toBeGreaterThan(0));
@@ -151,11 +192,19 @@ describe('LoopTrimmer', () => {
expect(canvas.parentElement.getAttribute('style')).toMatch(/linear-gradient/);
});
- it('holds the frame boxes with a checkerboard placeholder before the strip loads', () => {
+ it('reserves each frame box at the cell aspect before and after the strip loads', async () => {
const { container } = renderTrimmer();
+ const boxes = () => [...container.querySelectorAll('[style*="linear-gradient"]')];
+ // Pre-load: no canvas yet, but every box (8 thumbnails + main preview) already
+ // reserves a square — it is `aspectRatio`, not the canvas, that holds the layout.
expect(container.querySelectorAll('canvas')).toHaveLength(0);
- // Every frame box (8 thumbnails + main preview) is already laid out.
- expect(container.querySelectorAll('[style*="linear-gradient"]')).toHaveLength(STRIP_FRAMES + 1);
+ expect(boxes()).toHaveLength(STRIP_FRAMES + 1);
+ boxes().forEach((box) => expect(box.style.aspectRatio).toBe('1 / 1'));
+ // Post-load: the reserved aspect is unchanged, so nothing reflows.
+ await waitFor(() => expect(container.querySelectorAll('canvas').length).toBeGreaterThan(0));
+ boxes().forEach((box) => {
+ expect(box.style.aspectRatio).toBe(`${STRIP_CELL_PX} / ${STRIP_CELL_PX}`);
+ });
});
it('shows an empty state when there is nothing to trim', () => {