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: preserve keyed preview identity in URL, honor autoClean on 2 more enqueue paths

[._.]/ Adam Eivy4253c5492429
diff --git a/client/src/hooks/usePreviewRoute.js b/client/src/hooks/usePreviewRoute.js
index d449a30450..ed45188789 100644
--- a/client/src/hooks/usePreviewRoute.js
+++ b/client/src/hooks/usePreviewRoute.js
@@ -5,7 +5,13 @@ import { useSearchParams } from 'react-router-dom';
// shape every MediaPreview host already expects, but the source of truth is a
// `?preview=<filename>` query param so previews are deep-linkable, reload-safe,
// and shareable. setPreview(null) drops the param; setPreview(item) writes the
-// item's filename (falling back to its key).
+// item's key (falling back to its filename). Pages that mix multiple static
+// prefixes in the same items list — UniverseBuilder hosts gallery images
+// (/data/images) AND character reference sheets (/data/image-refs) under the
+// same modal — rely on the key prefix (`canon-sheet:foo.png` vs `image:foo.png`)
+// to disambiguate basename collisions; without the prefix in the URL the
+// resolver's filename-match below picks the first hit (typically the gallery
+// image) and the wrong asset opens.
//
// Match strategy against the host's items list (in order):
// 1. exact filename match
@@ -38,7 +44,7 @@ export default function usePreviewRoute(items, { paramName = 'preview' } = {}) {
const isOpen = !!item;
const next = new URLSearchParams(searchParams);
if (!item) next.delete(paramName);
- else next.set(paramName, item.filename || item.key || '');
+ else next.set(paramName, item.key || item.filename || '');
setSearchParams(next, { replace: wasOpen || !isOpen });
}, [searchParams, setSearchParams, paramName]);
diff --git a/client/src/hooks/usePreviewRoute.test.jsx b/client/src/hooks/usePreviewRoute.test.jsx
index 8b1a7cea7d..f9584c6ee3 100644
--- a/client/src/hooks/usePreviewRoute.test.jsx
+++ b/client/src/hooks/usePreviewRoute.test.jsx
@@ -44,13 +44,36 @@ describe('usePreviewRoute', () => {
expect(result.current.pair[0]).toBeNull();
});
- it('setPreview(item) writes the filename to the URL', () => {
+ it('setPreview(item) writes the key (URL-encoded) when present', () => {
+ // The URL contract is "write key, fall back to filename" — without the key
+ // in the URL a basename-collision case (canon-sheet:foo.png vs
+ // image:foo.png on the same items list) would open the wrong asset on
+ // reload / share. URL search params encode `:` as `%3A`.
const { result } = renderWithRouter([FOO, BAR]);
act(() => result.current.pair[1](BAR));
- expect(result.current.location.search).toContain('preview=bar.png');
+ expect(result.current.location.search).toContain('preview=image%3Abar.png');
expect(result.current.pair[0]).toBe(BAR);
});
+ it('setPreview(item) falls back to filename when key is absent', () => {
+ const BAR_NO_KEY = { filename: 'bar.png', prompt: 'bar' };
+ const { result } = renderWithRouter([{ filename: 'foo.png' }, BAR_NO_KEY]);
+ act(() => result.current.pair[1](BAR_NO_KEY));
+ expect(result.current.location.search).toContain('preview=bar.png');
+ expect(result.current.pair[0]).toBe(BAR_NO_KEY);
+ });
+
+ it('keyed setPreview survives a basename collision on reload', () => {
+ // SHEET and FOO share filename 'foo.png'. Writing the bare filename to the
+ // URL would resolve back to whichever item is first in the list (FOO), so
+ // setPreview(SHEET) followed by a reload would open the wrong asset. Writing
+ // the key preserves identity.
+ const { result } = renderWithRouter([FOO, SHEET]);
+ act(() => result.current.pair[1](SHEET));
+ expect(result.current.location.search).toContain('preview=canon-sheet%3Afoo.png');
+ expect(result.current.pair[0]).toBe(SHEET);
+ });
+
it('setPreview(null) drops the preview param but preserves siblings', () => {
const { result } = renderWithRouter([FOO, BAR], '/x?preview=foo.png&tab=cast');
act(() => result.current.pair[1](null));
@@ -63,7 +86,7 @@ describe('usePreviewRoute', () => {
const { result } = renderWithRouter([FOO, BAR], '/x?preview=foo.png');
expect(result.current.pair[0]).toBe(FOO);
act(() => result.current.pair[1](BAR));
- expect(result.current.location.search).toContain('preview=bar.png');
+ expect(result.current.location.search).toContain('preview=image%3Abar.png');
expect(result.current.pair[0]).toBe(BAR);
});
});
diff --git a/server/routes/universeBuilder.js b/server/routes/universeBuilder.js
index 9383fefae4..1c2d7d3605 100644
--- a/server/routes/universeBuilder.js
+++ b/server/routes/universeBuilder.js
@@ -32,6 +32,7 @@ import { findOrCreateUniverseCollection } from '../services/mediaCollections.js'
import { registerUniverseBuilderRun } from '../services/universeBuilderCollectionHook.js';
import { getImageModels, isFlux2, isZImage, isErnie } from '../lib/mediaModels.js';
import { IMAGE_GEN_MODE, IMAGE_GEN_MODES } from '../services/imageGen/modes.js';
+import { resolveAutoClean } from '../services/imageGen/index.js';
import { getStylePresetById } from '../lib/writersRoomStylePresets.js';
const router = Router();
@@ -555,18 +556,24 @@ router.post('/:id/render', asyncHandler(async (req, res) => {
},
};
let queued;
+ // The queue dispatches directly to imageGen/{codex,local}.generateImage,
+ // bypassing imageGen/index.js's dispatcher that resolves autoClean for
+ // direct callers. Resolve here so saved settings.imageGen[mode].autoClean
+ // applies to Universe Builder batch renders the same way it does for
+ // /api/image-gen/generate and pipeline renders.
+ const autoClean = resolveAutoClean(undefined, settings, mode);
if (mode === IMAGE_GEN_MODE.CODEX) {
const c = settings.imageGen?.codex || {};
queued = enqueueJob({
kind: 'image',
- params: { mode: IMAGE_GEN_MODE.CODEX, codexPath: c.codexPath, model: c.model, ...params },
+ params: { mode: IMAGE_GEN_MODE.CODEX, codexPath: c.codexPath, model: c.model, autoClean, ...params },
});
} else {
// mode === IMAGE_GEN_MODE.LOCAL (validated upfront).
const py = settings.imageGen?.local?.pythonPath || null;
queued = enqueueJob({
kind: 'image',
- params: { pythonPath: py, modelId: body.modelId, ...params },
+ params: { pythonPath: py, modelId: body.modelId, autoClean, ...params },
});
}
jobIds.push(queued.jobId);
diff --git a/server/services/universeCharacterSheet.js b/server/services/universeCharacterSheet.js
index 146a412aa0..5643a81605 100644
--- a/server/services/universeCharacterSheet.js
+++ b/server/services/universeCharacterSheet.js
@@ -25,6 +25,7 @@ import { getImageModels } from '../lib/mediaModels.js';
import { enqueueJob, mediaJobEvents } from './mediaJobQueue/index.js';
import { findOrCreateUniverseCollection } from './mediaCollections.js';
import { IMAGE_GEN_MODE } from './imageGen/modes.js';
+import { resolveAutoClean } from './imageGen/index.js';
import {
flattenStats, flattenPalette, flattenWardrobes, flattenProps, flattenNamedList,
} from '../lib/canonPrompt.js';
@@ -234,12 +235,19 @@ export async function renderCharacterReferenceSheet(universeId, entryId, options
// first-class. External SD-API has no multi-zone layout support, so it
// gets a clear remediation rather than a silently-degraded render.
const activeMode = settings.imageGen?.mode || IMAGE_GEN_MODE.LOCAL;
+ // The queue dispatches directly to imageGen/{codex,local}.generateImage,
+ // bypassing imageGen/index.js's dispatcher that resolves autoClean for
+ // direct callers. Resolve here so saved settings.imageGen[mode].autoClean
+ // applies to character reference-sheet renders the same way it does for
+ // /api/image-gen/generate, pipeline, and Universe Builder batch renders.
+ const autoClean = resolveAutoClean(undefined, settings, activeMode);
const baseParams = {
mode: activeMode,
prompt,
negativePrompt,
width: built.width,
height: built.height,
+ autoClean,
};
let modelId = null;