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 r3): expose spriteRef through job sanitization, clip-risk lock gate, thread saved local model
[._.]/ Adam Eivydb574e239941
diff --git a/client/src/components/sprites/ReferenceWorkflow.jsx b/client/src/components/sprites/ReferenceWorkflow.jsxindex 6ef69f3fb9..6b6eeb763d 100644--- a/client/src/components/sprites/ReferenceWorkflow.jsx+++ b/client/src/components/sprites/ReferenceWorkflow.jsx@@ -33,7 +33,7 @@ function SpriteImg({ recordId, path, className }) {// Candidate thumbnail with an inline lock confirm (locking is irreversible —// per the repo's confirmation UX convention this is an inline confirm row,// not a browser dialog or a hidden two-click arm).-function CandidateTile({ recordId, candidate, locking, onLock }) {+function CandidateTile({ recordId, candidate, locking, onLock, clipRisk }) {const [confirming, setConfirming] = useState(false);return (<div className="bg-port-bg border border-port-border rounded p-1 space-y-1">@@ -41,7 +41,18 @@ function CandidateTile({ recordId, candidate, locking, onLock }) {<p className="text-[10px] text-gray-500 truncate" title={candidate.path}>{candidate.path.split('/').pop()}{candidate.mode ? ` · ${candidate.mode}` : ''}</p>- {confirming ? (+ {clipRisk ? (+ <div className="space-y-1 text-[10px]">+ <p className="text-port-warning">{clipRisk}</p>+ <button+ onClick={() => onLock(candidate, true)}+ disabled={locking}+ className="w-full px-1.5 py-0.5 text-xs bg-port-warning/20 border border-port-warning rounded text-port-warning disabled:opacity-50"+ >+ Lock anyway+ </button>+ </div>+ ) : confirming ? (<div className="flex items-center gap-1 text-xs"><span className="text-port-warning">Freeze forever?</span><button onClick={() => { setConfirming(false); onLock(candidate); }} disabled={locking} className="px-1.5 py-0.5 bg-port-accent text-white rounded disabled:opacity-50">Lock</button>@@ -168,8 +179,27 @@ export default function ReferenceWorkflow({ record, reference, onChanged }) {}};- const [lock, locking] = useAsyncAction(async (target, candidate) => {- await lockSpriteReference(recordId, { target, candidate: candidate.path }, { silent: true });+ // path → clip-risk message; a risky main lock 409s until the user+ // explicitly locks through it from the candidate tile.+ const [clipRisks, setClipRisks] = useState({});++ const [lock, locking] = useAsyncAction(async (target, candidate, acceptClipRisk = false) => {+ try {+ await lockSpriteReference(recordId, {+ target, candidate: candidate.path, ...(acceptClipRisk ? { acceptClipRisk: true } : {}),+ }, { silent: true });+ } catch (err) {+ if (err?.code === 'CHROMA_CLIP_RISK') {+ setClipRisks((prev) => ({ ...prev, [candidate.path]: err.message }));+ return;+ }+ throw err; // useAsyncAction toasts+ }+ setClipRisks((prev) => {+ const next = { ...prev };+ delete next[candidate.path];+ return next;+ });toast.success(target === 'main' ? 'Main reference frozen' : `Anchor ${target} locked`);onChanged();}, { errorMessage: 'Lock failed' });@@ -277,7 +307,7 @@ export default function ReferenceWorkflow({ record, reference, onChanged }) {{(candidatesByTarget.main || []).length > 0 && (<div className="grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-6 gap-2">{candidatesByTarget.main.map((c) => (- <CandidateTile key={c.path} recordId={recordId} candidate={c} locking={locking} onLock={(cand) => lock('main', cand)} />+ <CandidateTile key={c.path} recordId={recordId} candidate={c} locking={locking} clipRisk={clipRisks[c.path]} onLock={(cand, accept) => lock('main', cand, accept)} />))}</div>)}diff --git a/server/lib/validation.js b/server/lib/validation.jsindex 04df173d9f..857f65805e 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -994,6 +994,8 @@ export const spriteReferenceGenerateSchema = z.object({export const spriteReferenceLockSchema = z.object({target: spriteReferenceTargetSchema,candidate: z.string().min(1).max(500),+ // Confirm-through for a clip-risk main lock (409 CHROMA_CLIP_RISK otherwise).+ acceptClipRisk: z.boolean().optional(),});// =============================================================================diff --git a/server/routes/mediaJobs.js b/server/routes/mediaJobs.jsindex 74235c22ff..dd1059d232 100644--- a/server/routes/mediaJobs.js+++ b/server/routes/mediaJobs.js@@ -86,6 +86,11 @@ const PARAM_ALLOWLIST = new Set([// rows ("Training: Kessa · mflux · 1000 steps") without exposing paths.'runId', 'runtime', 'datasetId', 'characterId', 'characterName','triggerWord', 'rank', 'baseModelId',+ // Sprite reference destination tag (#2896) — pure identifiers (record id,+ // target/direction, key hex, mode/model), no filesystem paths. The Sprites+ // UI correlates queued/running renders by it to rehydrate its in-flight+ // guard after a reload.+ 'spriteRef',]);function sanitizeJob(job) {if (!job) return job;diff --git a/server/services/sprites/reference.js b/server/services/sprites/reference.jsindex b140491e21..5037d6c3ae 100644--- a/server/services/sprites/reference.js+++ b/server/services/sprites/reference.js@@ -265,7 +265,10 @@ async function startReferenceGenerationImpl(recordId, body, upload = null) {? { mode, codexPath: settings.imageGen?.codex?.codexPath, model: codexModel, effort: body.effort || settings.imageGen?.codex?.effort, ...baseParams }: mode === IMAGE_GEN_MODE.GROK? { mode, grokPath: settings.imageGen?.grok?.grokPath, aspectRatio: settings.imageGen?.grok?.aspectRatio, ...baseParams }- : { mode, pythonPath: settings.imageGen?.local?.pythonPath || null, ...(body.model ? { modelId: body.model } : {}), ...baseParams };+ // Thread the resolved model (request override → saved local model) —+ // the queue dispatches straight to local.generateImage, which does NOT+ // read settings and would otherwise fall back to its own default.+ : { mode, pythonPath: settings.imageGen?.local?.pythonPath || null, ...(effectiveModel ? { modelId: effectiveModel } : {}), ...baseParams };const { jobId } = enqueueJob({ kind: 'image', params, owner: 'sprites' });console.log(`🧍 sprite reference render queued ${recordId}/${anchorId} mode=${mode} jobId=${jobId.slice(0, 8)}`);@@ -321,7 +324,7 @@ export function lockReference(recordId, args) {return manifestWriteTail(recordId, () => lockReferenceImpl(recordId, args));}-async function lockReferenceImpl(recordId, { target, candidate }) {+async function lockReferenceImpl(recordId, { target, candidate, acceptClipRisk = false }) {const record = await requireCharacter(recordId);// Seed on demand — a candidate may predate the manifest (e.g. files placed// by an import or a crash-recovered tree); the lock is what makes it real.@@ -364,6 +367,12 @@ async function lockReferenceImpl(recordId, { target, candidate }) {// gone from the palette, so surface the risk instead of silently locking// a clipped identity root.const clipWarning = keyProximityWarning(palette, maskKey);+ // A clip-risk lock is irreversible (the frozen root may already be+ // missing exact-key details) — refuse unless the caller explicitly+ // accepts, so the user learns BEFORE the 409 wall goes up, not after.+ if (clipWarning && !acceptClipRisk) {+ throw new ServerError(`${clipWarning}. Re-send with acceptClipRisk to lock anyway.`, { status: 409, code: 'CHROMA_CLIP_RISK' });+ }const rel = `reference/${await nextVersionPath(refDir, `${recordId}-walk-south`)}`;const destAbs = join(spriteDir(recordId), rel);await normalizeFromAnalysis(analysis, candAbs, destAbs, selectedKey);diff --git a/server/services/sprites/reference.test.js b/server/services/sprites/reference.test.jsindex 8cca56bcb8..e6206b78f5 100644--- a/server/services/sprites/reference.test.js+++ b/server/services/sprites/reference.test.js@@ -44,7 +44,7 @@ const settings = {mode: 'codex',codex: { enabled: true, codexPath: '/usr/local/bin/codex', model: 'gpt-5.6-luna', effort: 'low' },grok: { enabled: true, grokPath: '/usr/local/bin/grok', aspectRatio: '1:1' },- local: { pythonPath: '/usr/bin/python3' },+ local: { pythonPath: '/usr/bin/python3', modelId: 'flux-dev-4bit' },},};vi.mock('../settings.js', () => ({ getSettings: async () => settings }));@@ -244,21 +244,38 @@ describe('lockReference', () => {expect(record.status).toBe('reference');});- it('auto-selects AWAY from the key a magenta-clothed character would clash with, and warns about clip risk', async () => {+ it('409s a clip-risk main lock until accepted, then selects away from the clashing key', async () => {const id = newId();await createCharacter(id);const rel = await placeCandidate(id, 'main', 'walk-south-candidate-01.png', {- fg: { r: 255, g: 80, b: 230 }, // pink/magenta outfit+ fg: { r: 255, g: 80, b: 230 }, // pink/magenta outfit near the magenta key});- const result = await lockReference(id, { target: 'main', candidate: rel });+ // The freeze is irreversible — a clip-risk lock must be refused until+ // the user explicitly locks through it.+ await expect(lockReference(id, { target: 'main', candidate: rel }))+ .rejects.toMatchObject({ status: 409, code: 'CHROMA_CLIP_RISK' });+ let manifest = (await getReferenceSet(id)).manifest;+ expect(manifest?.mainReference?.locked ?? false).toBe(false);++ const result = await lockReference(id, { target: 'main', candidate: rel, acceptClipRisk: true });+ expect(result.manifest.mainReference.locked).toBe(true);expect(result.manifest.chromaKey).not.toBe('#FF00FF');const record = await records.getRecord(id);expect(record.chromaKey).toBe(result.manifest.chromaKey);- // Near-generation-key palette ⇒ exact-key details may already be masked- // out of the locked artifact — the manifest must say so.+ // The accepted risk stays visible on the manifest.expect(result.manifest.chromaKeyWarning).toMatch(/generation key #FF00FF/);});+ it('threads the saved local model into local-mode renders and provenance', async () => {+ const id = newId();+ await createCharacter(id);+ await startReferenceGeneration(id, { target: 'main', designPrompt: 'x', mode: 'local' });+ const call = enqueueJob.mock.calls[0][0];+ expect(call.params.mode).toBe('local');+ expect(call.params.modelId).toBe('flux-dev-4bit');+ expect(call.params.spriteRef.model).toBe('flux-dev-4bit');+ });+it('rebases legacy repo-root manifest paths from a phase-1 import', async () => {const id = newId();await createCharacter(id);