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
address review (codex r7): legacy lowercase pins, recoverable lock ordering, clip-accept reset, upload provenance, explicit-id input
[._.]/ Adam Eivy8bb6fcd8da07
diff --git a/client/src/components/sprites/ReferenceWorkflow.jsx b/client/src/components/sprites/ReferenceWorkflow.jsxindex 0c815aed09..ed7b901857 100644--- a/client/src/components/sprites/ReferenceWorkflow.jsx+++ b/client/src/components/sprites/ReferenceWorkflow.jsx@@ -218,6 +218,10 @@ export default function ReferenceWorkflow({ record, reference, onChanged }) {const [setChromaKey, keySaving] = useAsyncAction(async (hex) => {await updateSpriteRecord(recordId, { chromaKey: hex }, { silent: true });+ // A key change invalidates any clip-risk warning the user was shown —+ // force a fresh 409/confirm cycle instead of letting a stale "Lock+ // anyway" accept a risk computed for the old key.+ setClipRisks({});onChanged();}, { errorMessage: 'Failed to set chroma key' });diff --git a/client/src/pages/Sprites.jsx b/client/src/pages/Sprites.jsxindex 0bb42c5941..15b7418640 100644--- a/client/src/pages/Sprites.jsx+++ b/client/src/pages/Sprites.jsx@@ -114,11 +114,16 @@ function ImportPanel({ onImported }) {function NewCharacterPanel({ onCreated }) {const [open, setOpen] = useState(false);const [name, setName] = useState('');+ const [id, setId] = useState('');const [create, creating] = useAsyncAction(async () => {- const record = await createSpriteRecord({ name: name.trim() }, { silent: true });+ const record = await createSpriteRecord({+ name: name.trim(),+ ...(id.trim() ? { id: id.trim() } : {}),+ }, { silent: true });setOpen(false);setName('');+ setId('');onCreated(record);}, { errorMessage: 'Failed to create character' });@@ -153,6 +158,19 @@ function NewCharacterPanel({ onCreated }) {className="w-full bg-port-bg border border-port-border rounded px-3 py-1.5 text-sm text-white"/></div>+ <div>+ <label htmlFor="sprite-new-id" className="block text-xs text-gray-400 mb-1">+ Id <span className="text-gray-600">(optional — derived from the name; required for names with no a–z/0–9 characters)</span>+ </label>+ <input+ id="sprite-new-id"+ type="text"+ value={id}+ onChange={(e) => setId(e.target.value)}+ placeholder="trail-hand"+ className="w-full bg-port-bg border border-port-border rounded px-3 py-1.5 text-sm text-white"+ />+ </div><buttononClick={create}disabled={creating || !name.trim()}diff --git a/server/services/sprites/reference.js b/server/services/sprites/reference.jsindex a0c76c14ab..749aa4c8dc 100644--- a/server/services/sprites/reference.js+++ b/server/services/sprites/reference.js@@ -232,6 +232,7 @@ async function startReferenceGenerationImpl(recordId, body, upload = null) {let initImageStrength = Number.isFinite(body.initImageStrength) ? body.initImageStrength : undefined;let anchorId;let direction;+ let designReferencePath;if (target === 'main') {if (manifest.mainReference.locked) {@@ -246,10 +247,13 @@ async function startReferenceGenerationImpl(recordId, body, upload = null) {prompt = buildMainReferencePrompt({ name: record.name, designPrompt, chromaKey: genKey });if (upload) {// Shared temp-import (uuid-prefixed name, EXDEV-safe copy+unlink) —- // the upload persists in the record dir as design provenance.+ // the upload persists in the record dir as design provenance, and its+ // record-relative path rides the tag into the candidate sidecar so a+ // locked candidate stays traceable to the upload that guided it.const uploadsDir = join(spriteDir(recordId), 'reference', 'uploads');const { filename } = await importFileToDir(upload.tempPath, upload.originalname || 'design-reference.png', uploadsDir);initImagePath = join(uploadsDir, filename);+ designReferencePath = `reference/uploads/${filename}`;initImageStrength ??= UPLOAD_DEFAULT_STRENGTH;}if (designPrompt) manifest.designPrompt = designPrompt;@@ -300,6 +304,7 @@ async function startReferenceGenerationImpl(recordId, body, upload = null) {spriteRef: {recordId, target, direction, anchorId, chromaKey: genKey, mode, model: effectiveModel,...(target === 'main' && body.designPrompt ? { designPrompt: body.designPrompt } : {}),+ ...(designReferencePath ? { designReferencePath } : {}),},};const params = mode === IMAGE_GEN_MODE.CODEX@@ -346,6 +351,7 @@ export async function attachReferenceCandidate(ctx) {model: ctx.job?.params?.model || ctx.job?.params?.modelId || ctx.model || null,jobId: ctx.jobId || null,...(ctx.designPrompt ? { designPrompt: ctx.designPrompt } : {}),+ ...(ctx.designReferencePath ? { designReferencePath: ctx.designReferencePath } : {}),generatedAt: new Date().toISOString(),candidatePath: relPath,candidateSha256: await sha256File(dest),@@ -410,9 +416,12 @@ async function lockReferenceImpl(recordId, { target, candidate, acceptClipRisk =// pinned because the clip warning below needs it.const analysis = await analyzeForeground(candAbs, maskKey);const palette = paletteFromAnalysis(analysis);- const userPinned = CHROMA_KEY_HEXES.includes(record.chromaKey);- const auto = userPinned ? null : pickChromaKey(palette);- const selectedKey = userPinned ? record.chromaKey : auto.hex;+ // Case-insensitive pin check: phase-1 accepted any-case hex, so an+ // upgraded record can hold '#00ff00' — that is still a pin, not auto.+ const pinnedKey = CHROMA_KEY_HEXES.find((k) => k === (record.chromaKey || '').toUpperCase()) || null;+ const auto = pinnedKey ? null : pickChromaKey(palette);+ const selectedKey = pinnedKey || auto.hex;+ const userPinned = Boolean(pinnedKey);// Selection only sees pixels that SURVIVED the generation-key mask —// exact-key details (magenta garment on the magenta default) are already// gone from the palette — and a pinned key can collide with the palette@@ -444,8 +453,12 @@ async function lockReferenceImpl(recordId, { target, candidate, acceptClipRisk =const south = findAnchor(manifest, anchorIdForDirection('south'));if (south) Object.assign(south, { status: 'locked', path: rel, lockedFrom: candidate, sha256 });manifest.status = 'in-progress';- await saveManifest(recordId, manifest);+ // Record BEFORE manifest: a crash between the two leaves the record+ // updated but the manifest unlocked — recoverable by re-locking. The+ // reverse order would wedge (locked manifest + stale record, with both+ // relock and key PATCH returning 409 forever).await updateRecord(recordId, { chromaKey: selectedKey, status: 'reference' });+ await saveManifest(recordId, manifest);} else {if (!ANCHOR_DIRECTIONS.includes(target)) {throw new ServerError(`Unknown reference target: ${target}`, { status: 400, code: 'INVALID_TARGET' });diff --git a/server/services/sprites/reference.test.js b/server/services/sprites/reference.test.jsindex fb0dc931b9..599a33e778 100644--- a/server/services/sprites/reference.test.js+++ b/server/services/sprites/reference.test.js@@ -141,6 +141,18 @@ describe('startReferenceGeneration', () => {expect(manifest.designPrompt).toBe('a wiry ranger');});+ it('persists an uploaded design reference and records it in the tag provenance', async () => {+ const id = newId();+ await createCharacter(id);+ const tmp = join(TEST_ROOT, 'upload-tmp.png');+ await writeCandidatePng(tmp);+ await startReferenceGeneration(id, { target: 'main' }, { tempPath: tmp, originalname: 'concept.png' });+ const call = enqueueJob.mock.calls[0][0];+ expect(call.params.spriteRef.designReferencePath).toMatch(/^reference\/uploads\/.+concept\.png$/);+ expect(call.params.initImagePath).toContain('/reference/uploads/');+ expect(call.params.initImageStrength).toBe(0.65);+ });+it('refuses anchors before the main is locked, and south always', async () => {const id = newId();await createCharacter(id);@@ -283,6 +295,15 @@ describe('lockReference', () => {expect(result.manifest.chromaKeyWarning).toMatch(/generation key #FF00FF/);});+ it('honors a legacy lowercase pinned key at lock time (phase-1 records)', async () => {+ const id = newId();+ await createCharacter(id);+ await records.updateRecord(id, { chromaKey: '#0000ff' }); // phase-1 stored any-case hex+ const result = await lockMain(id);+ expect(result.manifest.chromaKey).toBe('#0000FF');+ expect(result.manifest.chromaKeyAutoSelected).toBe(false);+ });+it('409s a lock whose PINNED key collides with the surviving palette', async () => {const id = newId();await createCharacter(id);