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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor([issue-2996]): normalize unlocked v1 sprite manifests on read, delete the schemaVersion fork
[._.]/ Adam Eivy6c2a83d9da57
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 7cfb13e24a..72c6a6ab2b 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -25,6 +25,7 @@## Sprite Manager+- **[issue-2996] A character you'd started but not locked now begins at the turnaround sheet too** — when turnaround sheets landed, characters already in progress kept the old flow: they'd still ask for a main reference first, and only pick up sheets afterward. Now a character that hasn't frozen anything yet simply starts at step 1 like a new one — nothing of yours is lost, because nothing was locked. Characters that *have* frozen a main reference are untouched: their locked artwork stays exactly as it is, and they still backfill a sheet from it. Uploading a design image is now accepted only on the turnaround step, where it actually seeds the render — attaching one to the main reference used to be quietly ignored.- **[issue-2979] Characters now start from a turnaround sheet, so accessories stop jumping sides** — directional anchors used to be drawn from a single front-facing reference, which meant the AI had to invent every side it hadn't seen: a hip bag on the character's front would migrate to their back in the north view, and pockets or straps would swap sides between the east and west profiles. The reference workflow is now three ordered steps. **1 · Turnaround sheet**: describe the character (or attach a design image) and generate one image showing them from four angles — front, right, back, left — with every accessory pinned to the same side of the body in each panel. Lock it, and it becomes the character's identity root. **2 · Main reference**: redrawn from the sheet's front panel with one click, no separate design input. **3 · Directional anchors**: each pose is now redrawn from the sheet's panel for *that* side, so the model can see the hip bag instead of guessing at it. Picking the chroma-key background also moved to the sheet lock, where it can see the character from every angle — so a green backpack that's only visible from behind is accounted for up front instead of surprising you later. Forking a character now seeds the new one's sheet from the original's, inheriting every side.- **[issue-2979] Existing characters can backfill a turnaround sheet from their locked main** — a character you built before this shows the same three steps, with step 1 offering **Generate from locked main**: it expands the front view you already froze into the full four-view sheet, keeps your existing chroma key exactly as-is, and unblocks the directional anchors you haven't locked yet — which are then drawn from the sheet like a new character's. Already-locked references and anchors are untouched (they're immutable by design), so the benefit applies to whatever poses you still have left to derive.- **[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.diff --git a/server/routes/sprites.js b/server/routes/sprites.jsindex 7ea9a95e7f..6ea7414c5b 100644--- a/server/routes/sprites.js+++ b/server/routes/sprites.js@@ -130,11 +130,11 @@ router.post('/:id/reference/generate', referenceUpload, asyncHandler(async (req,const upload = file ? { tempPath: file.path, originalname: file.originalname } : null;if (upload) res.on('close', () => { unlink(upload.tempPath).catch(() => {}); });const body = validateRequest(spriteReferenceGenerateSchema, req.body ?? {});- // A design upload seeds the identity root only. That's the turnaround sheet- // on a turnaround-first record and the main on a legacy one (#2979) — the- // service decides which applies; everything downstream derives from the sheet.- if (upload && body.target !== 'turnaround' && body.target !== 'main') {- throw new ServerError('Reference image uploads seed the turnaround sheet or the main reference — directional anchors always derive from the locked turnaround', { status: 400, code: 'UPLOAD_MAIN_ONLY' });+ // A design upload seeds the identity root, which is always the turnaround+ // sheet (#2979, #2996) — the main and every anchor derive from that sheet, so+ // there is nowhere for a seed of their own to go.+ if (upload && body.target !== 'turnaround') {+ throw new ServerError('Reference image uploads seed the turnaround sheet — the main reference and directional anchors always derive from it', { status: 400, code: 'UPLOAD_TURNAROUND_ONLY' });}res.json(await startReferenceGeneration(req.params.id, body, upload));}));diff --git a/server/routes/sprites.test.js b/server/routes/sprites.test.jsindex 0b73b1d2e5..51eac8d708 100644--- a/server/routes/sprites.test.js+++ b/server/routes/sprites.test.js@@ -242,18 +242,17 @@ describe('sprites routes', () => {return Buffer.concat(parts);};- it('POST /:id/reference/generate accepts a multipart design-image upload for main', async () => {+ it('POST /:id/reference/generate rejects an upload for main — the sheet is the only seedable target', async () => {+ // #2996: the main derives from the locked turnaround, so a seed sent with it+ // has nowhere to go. Accepting one silently discarded it.const boundary = '----spritetest';const res = await request(app).post('/api/sprites/pioneer/reference/generate').set('content-type', `multipart/form-data; boundary=${boundary}`).send(buildMultipart(boundary, { fields: { target: 'main', designPrompt: 'a ranger' } }));- expect(res.status).toBe(200);- expect(reference.startReferenceGeneration).toHaveBeenCalledWith(- 'pioneer',- expect.objectContaining({ target: 'main', designPrompt: 'a ranger' }),- expect.objectContaining({ originalname: 'design.png', tempPath: expect.any(String) }),- );+ expect(res.status).toBe(400);+ expect(res.body.code).toBe('UPLOAD_TURNAROUND_ONLY');+ expect(reference.startReferenceGeneration).not.toHaveBeenCalled();});it('POST /:id/reference/generate accepts a multipart design-image upload for the turnaround', async () => {@@ -277,7 +276,7 @@ describe('sprites routes', () => {.set('content-type', `multipart/form-data; boundary=${boundary}`).send(buildMultipart(boundary, { fields: { target: 'east' } }));expect(res.status).toBe(400);- expect(res.body.code).toBe('UPLOAD_MAIN_ONLY');+ expect(res.body.code).toBe('UPLOAD_TURNAROUND_ONLY');expect(reference.startReferenceGeneration).not.toHaveBeenCalled();});diff --git a/server/services/sprites/reference.js b/server/services/sprites/reference.jsindex 19224adbf4..7cfbc76814 100644--- a/server/services/sprites/reference.js+++ b/server/services/sprites/reference.js@@ -57,12 +57,14 @@ const UPLOAD_DEFAULT_STRENGTH = 0.65;// write) — module-scope so the candidate listing doesn't recompile it per file.const TURNAROUND_CANDIDATE_RE = /^turnaround-candidate-\d+\.png$/;-// Manifests seeded from #2979 onward are turnaround-first: the sheet is the-// identity root, the main descends from it, and so does every anchor. A v1-// manifest was main-first (key frozen at main lock) and keeps that flow — it-// only has to backfill a sheet before deriving further anchors.+// Manifests are turnaround-first from #2979 onward: the sheet is the identity+// root, the main descends from it, and so does every anchor. A v1 manifest was+// main-first; `upgradeManifestShape` on read moves the ones holding no locked+// evidence onto v2, so the ONLY v1 manifests left in play are those with a+// frozen main — which keep their locked artifacts and backfill a sheet before+// deriving further anchors. Every branch below therefore reads the record's+// actual state (`turnaround.locked`), never its schema version.const TURNAROUND_FIRST_SCHEMA = 2;-const isTurnaroundFirst = (manifest) => (manifest?.schemaVersion || 1) >= TURNAROUND_FIRST_SCHEMA;const manifestRelPath = (id) => `reference/${id}-reference-set-v1.json`;@@ -82,9 +84,34 @@ function rebaseLegacyPath(p, recordId) {return typeof p === 'string' && p.startsWith(marker) ? p.slice(marker.length) : p;}+/**+ * Move a pre-#2979 manifest onto the turnaround-first shape — but ONLY when it+ * holds no locked evidence.+ *+ * A manifest whose main is not locked has frozen nothing, so nothing is lost by+ * putting it on the current standard: the user generates a sheet first, which is+ * what they'd do for a new character anyway. A manifest WITH a locked main is+ * returned untouched — its locked artifacts are immutable evidence, and it+ * backfills a sheet from that main instead (see the turnaround generate branch).+ *+ * This is the whole migration. The upgraded shape reaches disk on the next+ * `saveManifest`, which for an unlocked draft is the very next generate; a+ * record holding locked evidence is never rewritten as a side effect of a read.+ */+function upgradeManifestShape(manifest) {+ if (manifest.schemaVersion >= TURNAROUND_FIRST_SCHEMA || manifest.mainReference?.locked) return manifest;+ manifest.schemaVersion = TURNAROUND_FIRST_SCHEMA;+ manifest.turnaround = manifest.turnaround || {+ path: null, role: 'identity-root', background: 'chroma-key', locked: false, views: TURNAROUND_VIEWS,+ };+ if (!manifest.status || manifest.status === 'needs-main-reference') manifest.status = 'needs-turnaround';+ return manifest;+}+export async function loadManifest(recordId) {const manifest = await readJSONFile(join(spriteDir(recordId), manifestRelPath(recordId)), null);if (!manifest) return null;+ upgradeManifestShape(manifest);if (manifest.mainReference) {manifest.mainReference.path = rebaseLegacyPath(manifest.mainReference.path, recordId);manifest.mainReference.lockedFrom = rebaseLegacyPath(manifest.mainReference.lockedFrom, recordId);@@ -289,20 +316,18 @@ async function startReferenceGenerationImpl(recordId, body, upload = null) {const turnaroundLocked = manifest.turnaround?.locked === true;const designPrompt = typeof body.designPrompt === 'string' ? body.designPrompt.trim() : '';- // A render that establishes the character's look needs SOME input: a prompt,- // an uploaded image, a gallery pick, or another sprite's reference to seed- // from. `alsoSeeded` covers a source the branch supplies itself (the legacy- // main a backfilled sheet expands, the sheet the main descends from).- const requireDesignInput = (alsoSeeded = false) => {- if (designPrompt || alsoSeeded || upload || body.initImageGalleryFile || body.initImageSpriteId) return;- throw new ServerError('Provide a design prompt and/or a reference image', { status: 400, code: 'DESIGN_INPUT_REQUIRED' });- };if (target === TURNAROUND_ID) {if (turnaroundLocked) {throw new ServerError('Turnaround sheet is locked — corrections require a new character version, never regeneration', { status: 409, code: 'REFERENCE_LOCKED' });}- requireDesignInput(manifest.mainReference.locked);+ // The sheet establishes the character's look, so it needs SOME input: a+ // prompt, an uploaded image, a gallery pick, another sprite's reference —+ // or, on a legacy record, the locked main this backfill expands.+ if (!designPrompt && !upload && !body.initImageGalleryFile && !body.initImageSpriteId+ && !manifest.mainReference.locked) {+ throw new ServerError('Provide a design prompt and/or a reference image', { status: 400, code: 'DESIGN_INPUT_REQUIRED' });+ }anchorId = TURNAROUND_ID;prompt = buildTurnaroundPrompt({name: record.name,@@ -330,11 +355,11 @@ async function startReferenceGenerationImpl(recordId, body, upload = null) {if (manifest.mainReference.locked) {throw new ServerError('Main reference is locked — corrections require a new character version, never regeneration', { status: 409, code: 'REFERENCE_LOCKED' });}- // Turnaround-first (#2979): on a manifest seeded under the new standard the- // main is the sheet's front view, so the sheet must exist first. A legacy- // v1 manifest predates the sheet and keeps its main-first flow — it only- // has to backfill a sheet before deriving further anchors.- if (!turnaroundLocked && isTurnaroundFirst(manifest)) {+ // The main is always the sheet's front view: a manifest that reaches here+ // with no locked sheet was either seeded turnaround-first or upgraded to it+ // on read (upgradeManifestShape), and the only manifests that skip that+ // upgrade have a locked main — which threw REFERENCE_LOCKED just above.+ if (!turnaroundLocked) {throw new ServerError('Lock the turnaround sheet before deriving the main reference', { status: 409, code: 'TURNAROUND_NOT_LOCKED' });}anchorId = anchorIdForDirection('south');@@ -343,24 +368,15 @@ async function startReferenceGenerationImpl(recordId, body, upload = null) {name: record.name,designPrompt: designPrompt || manifest.designPrompt,chromaKey: genKey,- fromTurnaround: turnaroundLocked,+ fromTurnaround: true,});- if (turnaroundLocked) {- // The sheet IS the seed here, so a caller-supplied one has nowhere to go.- // Reject rather than silently dropping it (the route accepts an upload for- // this target because a legacy record's main does take one).- if (upload || body.initImageGalleryFile || body.initImageSpriteId) {- throw new ServerError('The main reference derives from the locked turnaround sheet — seed a new design through the sheet, not the main', { status: 400, code: 'SEED_NOT_APPLICABLE' });- }- initImagePath = await requireLockedTurnaroundPath(recordId, manifest);- initImageStrength ??= ANCHOR_DEFAULT_STRENGTH;- } else {- // Legacy v1 main, still on the main-first flow: a prompt, an uploaded- // image, a gallery pick, or another sprite's reference is required.- requireDesignInput();- ({ initImagePath, designReferencePath } = await resolveSeedSource(recordId, body, upload));- if (initImagePath) initImageStrength ??= UPLOAD_DEFAULT_STRENGTH;+ // The sheet IS the seed here, so a caller-supplied one has nowhere to go.+ // Reject rather than silently dropping it.+ if (upload || body.initImageGalleryFile || body.initImageSpriteId) {+ throw new ServerError('The main reference derives from the locked turnaround sheet — seed a new design through the sheet, not the main', { status: 400, code: 'SEED_NOT_APPLICABLE' });}+ initImagePath = await requireLockedTurnaroundPath(recordId, manifest);+ initImageStrength ??= ANCHOR_DEFAULT_STRENGTH;// Nothing else in this branch mutates the manifest, so skip the write —// and its per-record serialization — on the common no-prompt re-roll.if (designPrompt) {diff --git a/server/services/sprites/reference.test.js b/server/services/sprites/reference.test.jsindex 92b5d7a93e..d231089b0a 100644--- a/server/services/sprites/reference.test.js+++ b/server/services/sprites/reference.test.js@@ -78,30 +78,48 @@ async function lockMain(recordId) {return lockReference(recordId, { target: 'main', candidate: rel });}-// A pre-#2979 manifest: main-first (schemaVersion 1, no turnaround block),-// nothing locked — written straight to disk the way an install upgraded from-// phase 2 would have it mid-workflow.-async function writeLegacyManifest(recordId) {+const DIRECTIONS = ['south', 'south-east', 'east', 'north-east', 'north', 'north-west', 'west', 'south-west'];++// Write a pre-#2979 manifest verbatim to disk — main-first, schemaVersion 1, no+// turnaround block. `lockedMain` produces what an install upgraded from phase 2+// actually holds (the frozen PNG + a locked mainReference + the key it froze),+// which is the ONLY v1 shape that survives upgradeManifestShape; the unlocked+// variant is a mid-workflow draft, which normalizes to v2 on read.+//+// These are written straight to disk rather than locked through lockReference,+// because that path would normalize the draft to v2 first and so could never+// reproduce a genuine v1-with-locked-main.+async function writeLegacyManifest(recordId, { lockedMain = false } = {}) {const dir = join(TEST_ROOT, 'sprites', recordId, 'reference');await mkdir(dir, { recursive: true });+ const mainPath = `reference/${recordId}-walk-south-v1.png`;+ if (lockedMain) await writeCandidatePng(join(TEST_ROOT, 'sprites', recordId, mainPath));await writeFile(join(dir, `${recordId}-reference-set-v1.json`), JSON.stringify({schemaVersion: 1,manifestId: `${recordId}-reference-set-v1`,- status: 'needs-main-reference',+ status: lockedMain ? 'in-progress' : 'needs-main-reference',characterFamily: recordId,- chromaKey: null,- mainReference: { path: null, role: 'immutable-root', background: 'chroma-key', locked: false },- anchors: ['south', 'south-east', 'east', 'north-east', 'north', 'north-west', 'west', 'south-west']- .map((direction) => ({ id: `walk-${direction}`, kind: 'walk-anchor', direction, status: 'pending' })),+ chromaKey: lockedMain ? '#FF00FF' : null,+ ...(lockedMain ? { chromaKeyAutoSelected: true } : {}),+ mainReference: {+ path: lockedMain ? mainPath : null,+ role: 'immutable-root',+ background: 'chroma-key',+ locked: lockedMain,+ ...(lockedMain ? { lockedFrom: 'reference/candidates/walk-south-candidate-01.png', lockedAt: '2026-01-01T00:00:00.000Z' } : {}),+ },+ anchors: DIRECTIONS.map((direction) => ({+ id: `walk-${direction}`,+ kind: 'walk-anchor',+ direction,+ status: lockedMain && direction === 'south' ? 'locked' : 'pending',+ ...(lockedMain && direction === 'south' ? { path: mainPath } : {}),+ })),}));+ if (lockedMain) await records.updateRecord(recordId, { chromaKey: '#FF00FF', status: 'reference' });}-// …and the same record with its main locked through the legacy main-first path.-async function legacyLockedMain(recordId) {- await writeLegacyManifest(recordId);- const rel = await placeCandidate(recordId, 'main', 'walk-south-candidate-01.png');- return lockReference(recordId, { target: 'main', candidate: rel });-}+const legacyLockedMain = (recordId) => writeLegacyManifest(recordId, { lockedMain: true });beforeEach(() => {enqueueJob.mockClear();@@ -221,14 +239,36 @@ describe('startReferenceGeneration', () => {await writeCandidatePng(tmp);await expect(startReferenceGeneration(id, { target: 'main' }, { tempPath: tmp, originalname: 'concept.png' })).rejects.toMatchObject({ code: 'SEED_NOT_APPLICABLE', status: 400 });- // A legacy record's main still accepts one — the gate is sheet-conditional,- // not a blanket ban on seeding the main.- const legacy = newId();- await createCharacter(legacy);- await writeLegacyManifest(legacy);- enqueueJob.mockClear();- await startReferenceGeneration(legacy, { target: 'main', designPrompt: 'x', initImageGalleryFile: galleryName });- expect(enqueueJob.mock.calls[0][0].params.initImagePath).toBe(join(TEST_ROOT, 'images', galleryName));+ });++ it('normalizes an unlocked legacy manifest to turnaround-first on read (#2996)', async () => {+ // A v1 draft has frozen nothing, so moving it onto the current standard+ // costs the user nothing — and it means no reachable main generate can+ // observe the old main-first flow.+ const id = newId();+ await createCharacter(id);+ await writeLegacyManifest(id); // schemaVersion 1, nothing locked+ const { manifest } = await getReferenceSet(id);+ expect(manifest.schemaVersion).toBe(2);+ expect(manifest.status).toBe('needs-turnaround');+ expect(manifest.turnaround).toMatchObject({ locked: false, role: 'identity-root' });+ await expect(startReferenceGeneration(id, { target: 'main', designPrompt: 'x' }))+ .rejects.toMatchObject({ code: 'TURNAROUND_NOT_LOCKED', status: 409 });+ });++ it('never normalizes — or rewrites — a legacy manifest holding a locked main', async () => {+ const id = newId();+ await createCharacter(id);+ await legacyLockedMain(id);+ const abs = join(TEST_ROOT, 'sprites', id, 'reference', `${id}-reference-set-v1.json`);+ const before = await readFile(abs, 'utf8');++ const { manifest } = await getReferenceSet(id);+ expect(manifest.schemaVersion).toBe(1);+ expect(manifest.turnaround).toBeUndefined();+ expect(manifest.chromaKey).toBe('#FF00FF');+ // Locked evidence is never rewritten as a side effect of a read.+ expect(await readFile(abs, 'utf8')).toBe(before);});it('derives anchors from the locked turnaround via i2i with the selected key in the prompt', async () => {