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

show the prompt actually sent to the renderer in the deck card preview

[._.]/ Adam Eivye8e40991ee36
diff --git a/client/src/components/decks/DeckCardDrawer.jsx b/client/src/components/decks/DeckCardDrawer.jsx
index b6320e9541..ec9f590b7f 100644
--- a/client/src/components/decks/DeckCardDrawer.jsx
+++ b/client/src/components/decks/DeckCardDrawer.jsx
@@ -1,7 +1,8 @@
import { useEffect, useState } from 'react';
-import { Link2, Loader2, Sparkles, Star, Trash2 } from 'lucide-react';
+import { Copy, Link2, Loader2, Sparkles, Star, Trash2 } from 'lucide-react';
import Drawer from '../Drawer';
import { composeCardRenderPrompt } from '../../lib/decks';
+import { copyToClipboard } from '../../lib/clipboard';
const INPUT_CLASS = 'w-full bg-port-bg border border-port-border rounded-lg px-3 py-2 text-sm text-white focus:outline-none focus:border-port-accent';
@@ -62,11 +63,27 @@ export default function DeckCardDrawer({ deck, card, open, inFlight, onClose, on
</button>
</div>
- <details className="rounded border border-port-border bg-port-bg/40 p-2">
- <summary className="text-xs text-gray-400 cursor-pointer">Composed render prompt</summary>
- <p className="mt-2 text-xs text-gray-300 whitespace-pre-wrap">{composed.prompt}</p>
- {composed.negativePrompt ? <p className="mt-2 text-xs text-port-error/80">Negative: {composed.negativePrompt}</p> : null}
- </details>
+ <section className="rounded border border-port-border bg-port-bg/40 p-3 space-y-3">
+ <div className="flex items-center justify-between gap-2">
+ <h3 className="text-xs text-gray-400">What the renderer receives</h3>
+ <button
+ type="button"
+ onClick={() => copyToClipboard(composed.prompt, 'Render prompt')}
+ className="inline-flex min-h-[32px] items-center gap-1 rounded px-2 text-xs text-gray-400 hover:text-white"
+ title="Copy the whole composed prompt"
+ >
+ <Copy size={12} aria-hidden="true" /> Copy
+ </button>
+ </div>
+ <PromptPart label="Deck style" hint="from the style guide" value={composed.parts.style} />
+ <PromptPart label="Layout" hint="shared by every card" value={composed.parts.layout} />
+ <PromptPart label="Subject" hint="this card" value={composed.parts.subject} />
+ <PromptPart label="Negative" value={composed.negativePrompt} tone="error" />
+ <details>
+ <summary className="text-xs text-gray-400 cursor-pointer">Full composed prompt</summary>
+ <p className="mt-2 text-xs text-gray-300 whitespace-pre-wrap">{composed.prompt}</p>
+ </details>
+ </section>
<section>
<h3 className="text-xs text-gray-400 mb-2">Renders ({refs.length})</h3>
@@ -116,3 +133,21 @@ export default function DeckCardDrawer({ deck, card, open, inFlight, onClose, on
</Drawer>
);
}
+
+/**
+ * One read-only clause of the composed render prompt. Empty clauses still
+ * render their label — "Deck style: —" is the answer to "why does my card
+ * look nothing like the deck?", and hiding the row hides the answer.
+ */
+function PromptPart({ label, hint, value, tone }) {
+ return (
+ <div>
+ <p className="text-[11px] uppercase tracking-wide text-gray-500">
+ {label}{hint ? <span className="normal-case tracking-normal text-gray-600"> · {hint}</span> : null}
+ </p>
+ <p className={`text-xs whitespace-pre-wrap ${value ? (tone === 'error' ? 'text-port-error/80' : 'text-gray-300') : 'text-gray-600'}`}>
+ {value || '—'}
+ </p>
+ </div>
+ );
+}
diff --git a/client/src/components/decks/DeckCardDrawer.test.jsx b/client/src/components/decks/DeckCardDrawer.test.jsx
new file mode 100644
index 0000000000..87a6931abd
--- /dev/null
+++ b/client/src/components/decks/DeckCardDrawer.test.jsx
@@ -0,0 +1,48 @@
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import DeckCardDrawer from './DeckCardDrawer';
+
+const deck = {
+ id: 'd1',
+ kind: 'tarot',
+ layoutPrompt: 'Full tarot card, framed border',
+ influences: { embrace: ['copperplate engraving'], avoid: ['blurry'] },
+};
+const card = {
+ id: 'c1', key: 'major-0', name: 'The Fool', groupLabel: 'Major Arcana',
+ prompt: 'a youth at a cliff edge', negativePrompt: 'text', imageRefs: [],
+ primaryImageRef: null, render: null, canonRef: null,
+};
+
+const renderDrawer = (over = {}) => render(
+ <DeckCardDrawer
+ deck={deck}
+ card={card}
+ open
+ inFlight={null}
+ onClose={vi.fn()}
+ onSave={vi.fn()}
+ onRender={vi.fn()}
+ onPreview={vi.fn()}
+ {...over}
+ />,
+);
+
+describe('DeckCardDrawer render prompt', () => {
+ it('attributes each clause, so deck-wide wording is not mistaken for the card', () => {
+ renderDrawer();
+ expect(screen.getByText('copperplate engraving')).toBeInTheDocument();
+ expect(screen.getByText('Full tarot card, framed border')).toBeInTheDocument();
+ expect(screen.getByText('The Fool: a youth at a cliff edge')).toBeInTheDocument();
+ expect(screen.getByText('text, blurry')).toBeInTheDocument();
+ expect(screen.getByText(/copperplate engraving\. Full tarot card, framed border\. The Fool: a youth at a cliff edge/)).toBeInTheDocument();
+ });
+
+ it('still names a clause the deck has not filled in', () => {
+ renderDrawer({ deck: { id: 'd1', kind: 'tarot' } });
+ // "Deck style: —" is the answer to "why doesn't my card match the deck?";
+ // dropping the empty row hides the answer.
+ expect(screen.getByText('Deck style')).toBeInTheDocument();
+ expect(screen.getAllByText('—').length).toBeGreaterThan(0);
+ });
+});
diff --git a/client/src/hooks/README.md b/client/src/hooks/README.md
index e0fd9692ba..a90ada634b 100644
--- a/client/src/hooks/README.md
+++ b/client/src/hooks/README.md
@@ -245,4 +245,5 @@ grep -i "what you want to do" client/src/hooks/README.md
| Hook | Purpose | Use when |
|---|---|---|
| `useEidoverseFrame` | Per-load Eidoverse handshake with origin/window/session validation and browser-only label preferences. | Embedding the managed Eidoverse renderer. |
+| `useGallerySidecars` | Hydrates a known filename list into its image-metadata sidecars (the prompt actually sent, negative, model, seed, size), keyed on contents rather than array identity, with a `setSidecar` splice for a freshly written record. | Any page showing renders it owns the refs for (universe draft, deck cards) that must open the lightbox on the real render prompt. |
| `useGalleryPage` | Bounded image or mixed-media browsing with debounced server search, scopes, totals, stale-response cancellation and retryable next pages. | Gallery grids and pickers; `getGalleryImages` hydrates known references separately. |
diff --git a/client/src/hooks/index.js b/client/src/hooks/index.js
index 55a20a71ad..e2db2fe4a1 100644
--- a/client/src/hooks/index.js
+++ b/client/src/hooks/index.js
@@ -26,6 +26,7 @@ export { default as useEscapeKey } from './useEscapeKey.js';
export { default as useFieldDraft } from './useFieldDraft.js';
export { default as useFableLoomAiRun } from './useFableLoomAiRun.js';
export { default as useFocusTrap } from './useFocusTrap.js';
+export { default as useGallerySidecars } from './useGallerySidecars.js';
export { default as useNoteSave } from './useNoteSave.js';
export { default as useHoverTooltip } from './useHoverTooltip.js';
export { default as useImageGenQueue } from './useImageGenQueue.js';
diff --git a/client/src/hooks/useGallerySidecars.js b/client/src/hooks/useGallerySidecars.js
new file mode 100644
index 0000000000..936b2c178b
--- /dev/null
+++ b/client/src/hooks/useGallerySidecars.js
@@ -0,0 +1,47 @@
+import { useCallback, useEffect, useMemo, useState } from 'react';
+import { getGalleryImages } from '../services/apiImageVideo';
+
+/**
+ * Hydrate a known set of gallery filenames into their image-metadata sidecars
+ * (`prompt`, `negativePrompt`, `modelId`, `seed`, size, …).
+ *
+ * Every page that shows renders it *owns* the references for — a universe
+ * draft, a deck's cards — needs the same thing: the record of what was
+ * ACTUALLY sent to the renderer, which is the sidecar, not the page's own
+ * label or the card's subject prompt. Without it a lightbox opened from such
+ * a page shows the row's display text and Refine / Remix / Send to Video open
+ * with the wrong prompt.
+ *
+ * `filenames` may be a fresh array each render — the fetch is keyed on the
+ * sorted, de-duplicated contents, not on array identity. `refreshKey` re-runs
+ * the lookup once a new render has landed on disk.
+ *
+ * Returns `{ byFilename, setSidecar }`; `setSidecar(record)` splices one
+ * freshly written record in (e.g. after a clean) without a refetch.
+ */
+export default function useGallerySidecars(filenames, refreshKey = 0) {
+ const lookupKey = useMemo(
+ () => JSON.stringify([...new Set((Array.isArray(filenames) ? filenames : []).filter(Boolean))].sort()),
+ [filenames],
+ );
+ const [byFilename, setByFilename] = useState(() => new Map());
+ useEffect(() => {
+ const wanted = JSON.parse(lookupKey);
+ if (!wanted.length) { setByFilename(new Map()); return undefined; }
+ let cancelled = false;
+ getGalleryImages(wanted, { silent: true }).then((list) => {
+ if (cancelled) return;
+ const map = new Map();
+ for (const item of Array.isArray(list) ? list : []) {
+ if (item?.filename) map.set(item.filename, item);
+ }
+ setByFilename(map);
+ }).catch(() => { /* non-fatal; callers fall back to their own labels */ });
+ return () => { cancelled = true; };
+ }, [lookupKey, refreshKey]);
+ const setSidecar = useCallback((record) => {
+ if (!record?.filename) return;
+ setByFilename((prev) => new Map(prev).set(record.filename, record));
+ }, []);
+ return { byFilename, setSidecar };
+}
diff --git a/client/src/hooks/useGallerySidecars.test.jsx b/client/src/hooks/useGallerySidecars.test.jsx
new file mode 100644
index 0000000000..a5a4945261
--- /dev/null
+++ b/client/src/hooks/useGallerySidecars.test.jsx
@@ -0,0 +1,46 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { renderHook, waitFor, act } from '@testing-library/react';
+import useGallerySidecars from './useGallerySidecars';
+
+const getGalleryImages = vi.fn();
+vi.mock('../services/apiImageVideo', () => ({ getGalleryImages: (...a) => getGalleryImages(...a) }));
+
+describe('useGallerySidecars', () => {
+ beforeEach(() => {
+ getGalleryImages.mockReset().mockResolvedValue([{ filename: 'a.png', prompt: 'the composed prompt' }]);
+ });
+
+ it('looks up the de-duplicated filenames and keys the map by filename', async () => {
+ const { result } = renderHook(() => useGallerySidecars(['a.png', 'a.png']));
+ await waitFor(() => expect(result.current.byFilename.get('a.png')?.prompt).toBe('the composed prompt'));
+ expect(getGalleryImages).toHaveBeenCalledWith(['a.png'], { silent: true });
+ });
+
+ it('re-fetches on the contents, not on array identity', async () => {
+ const { rerender } = renderHook(({ names }) => useGallerySidecars(names), {
+ initialProps: { names: ['a.png'] },
+ });
+ await waitFor(() => expect(getGalleryImages).toHaveBeenCalledTimes(1));
+ // A page derives this list inside a memo off its record — a fresh array
+ // every render. Re-fetching on identity would hammer the server once per
+ // keystroke on a 79-card deck.
+ rerender({ names: ['a.png'] });
+ expect(getGalleryImages).toHaveBeenCalledTimes(1);
+ rerender({ names: ['a.png', 'b.png'] });
+ await waitFor(() => expect(getGalleryImages).toHaveBeenCalledTimes(2));
+ });
+
+ it('splices one freshly written record in without a refetch', async () => {
+ const { result } = renderHook(() => useGallerySidecars(['a.png']));
+ await waitFor(() => expect(result.current.byFilename.size).toBe(1));
+ act(() => result.current.setSidecar({ filename: 'a-clean.png', prompt: 'cleaned' }));
+ expect(result.current.byFilename.get('a-clean.png')?.prompt).toBe('cleaned');
+ expect(getGalleryImages).toHaveBeenCalledTimes(1);
+ });
+
+ it('skips the request entirely when there is nothing to hydrate', async () => {
+ const { result } = renderHook(() => useGallerySidecars([]));
+ await waitFor(() => expect(result.current.byFilename.size).toBe(0));
+ expect(getGalleryImages).not.toHaveBeenCalled();
+ });
+});
diff --git a/client/src/hooks/useUniverseGallery.js b/client/src/hooks/useUniverseGallery.js
index 419b704540..675d096165 100644
--- a/client/src/hooks/useUniverseGallery.js
+++ b/client/src/hooks/useUniverseGallery.js
@@ -1,7 +1,7 @@
-import { useState, useEffect, useMemo, useCallback } from 'react';
-import { getGalleryImages } from '../services/apiImageVideo';
+import { useState, useMemo, useCallback } from 'react';
import { descriptorForCanonEntry } from '../lib/canonPrompt';
import { listSheetPointers } from '../lib/sheetPointers';
+import useGallerySidecars from './useGallerySidecars';
import usePreviewRoute from './usePreviewRoute';
import useMediaPreviewActions from './useMediaPreviewActions';
import { useMediaAnnotations } from './useMediaAnnotations';
@@ -29,16 +29,12 @@ export default function useUniverseGallery({ draft, runsLength }) {
// modelId, width, height, seed, etc.). Hydrates `previewItems` with the
// ACTUAL prompt that was used to render the image — without this the
// modal would only see the variation's label, and Refine Prompt / Remix
- // / Send to Video would all open with empty fields. Loaded once per
- // mount via bounded lookup of only the draft's referenced filenames
- // and refreshed whenever a render completes (universe `runs` advances).
- const [galleryByFilename, setGalleryByFilename] = useState(() => new Map());
- // Bumped on every job completion so the gallery-metadata fetch below
- // re-runs once the new sidecar exists on disk. Keying the fetch only on
- // `runs.length` was insufficient: that advances when a run is queued or
- // loaded, NOT when one of its jobs completes — so a freshly rendered
- // thumb would open the lightbox with label-only metadata until a full
- // page reload.
+ // / Send to Video would all open with empty fields.
+ //
+ // The refresh key carries two signals: `runsLength` advances when a run is
+ // queued or loaded, and `galleryRefreshKey` is bumped on every job
+ // completion — keying on runs alone left a freshly rendered thumb opening
+ // with label-only metadata until a full page reload.
const [galleryRefreshKey, setGalleryRefreshKey] = useState(0);
const bumpGalleryRefresh = useCallback(() => setGalleryRefreshKey((k) => k + 1), []);
const galleryFilenames = useMemo(() => {
@@ -49,22 +45,9 @@ export default function useUniverseGallery({ draft, runsLength }) {
for (const entry of [...(draft?.compositeSheets || []), ...(draft?.characters || []), ...(draft?.places || []), ...(draft?.objects || [])]) {
for (const filename of entry.imageRefs || []) refs.add(filename);
}
- return JSON.stringify([...refs].sort());
+ return [...refs];
}, [draft]);
- useEffect(() => {
- let cancelled = false;
- getGalleryImages(JSON.parse(galleryFilenames), { silent: true }).then((list) => {
- if (cancelled) return;
- const map = new Map();
- for (const item of Array.isArray(list) ? list : []) {
- if (item?.filename) map.set(item.filename, item);
- }
- setGalleryByFilename(map);
- }).catch(() => { /* non-fatal; modal falls back to filename-only display */ });
- return () => { cancelled = true; };
- // `runsLength` covers initial-load and queue-time; `galleryRefreshKey`
- // covers per-job completion (see bumpGalleryRefresh callers).
- }, [runsLength, galleryRefreshKey, galleryFilenames]);
+ const { byFilename: galleryByFilename, setSidecar } = useGallerySidecars(galleryFilenames, `${runsLength}:${galleryRefreshKey}`);
const { annotations, updateAnnotation } = useMediaAnnotations();
const previewItems = useMemo(() => {
const out = [];
@@ -173,16 +156,7 @@ export default function useUniverseGallery({ draft, runsLength }) {
// as the History grid + Image Gen page. `onCleanComplete` splices the
// cleaned image into the local gallery map so the next preview open
// shows it immediately — no full refetch needed.
- const previewActions = useMediaPreviewActions({
- onCleanComplete: useCallback((cleaned) => {
- if (!cleaned?.filename) return;
- setGalleryByFilename((prev) => {
- const next = new Map(prev);
- next.set(cleaned.filename, cleaned);
- return next;
- });
- }, []),
- });
+ const previewActions = useMediaPreviewActions({ onCleanComplete: setSidecar });
// Generic filename → preview opener used by every clickable thumb on the
// page (variation grids, composite sheets, canon entries, character
// reference sheets). `opts.isSheet` forces a key match against the
diff --git a/client/src/pages/DeckDetail.jsx b/client/src/pages/DeckDetail.jsx
index be097ac5be..0d968d1397 100644
--- a/client/src/pages/DeckDetail.jsx
+++ b/client/src/pages/DeckDetail.jsx
@@ -36,6 +36,7 @@ import useMounted from '../hooks/useMounted';
import useUrlParams from '../hooks/useUrlParams';
import usePreviewRoute from '../hooks/usePreviewRoute';
import useFieldDraft from '../hooks/useFieldDraft';
+import useGallerySidecars from '../hooks/useGallerySidecars';
import { DECK_KIND_LABELS, cardInFlightJobId, deckCompletion } from '../lib/decks';
import {
deleteDeck, generateDeckPrompts, getDeck, listUniverseSummaries, removeDeckSample,
@@ -111,9 +112,30 @@ function DeckEditor({ id }) {
() => (deck && cardParam ? deck.cards.find((c) => c.id === cardParam) || null : null),
[deck, cardParam],
);
+ const cardImageRefs = useMemo(
+ () => (deck ? deck.cards.flatMap((c) => c.imageRefs) : []),
+ [deck],
+ );
+ // The card's own `prompt` is only the subject line. What the renderer was
+ // actually sent is the composed prompt — deck style clause, layout clause,
+ // titled subject, merged negatives — and that is what the sidecar recorded,
+ // so hydrate from it and let the lightbox show the real thing. The card
+ // prompt stays the fallback for a render whose sidecar is missing (a legacy
+ // deck render, or a refetch that has not landed yet). A finished render
+ // appends its filename to the card, which re-keys the lookup on its own —
+ // the sidecar is on disk before the server hook attaches the image.
+ const { byFilename: sidecars } = useGallerySidecars(cardImageRefs);
const previewItems = useMemo(() => (deck
- ? deck.cards.flatMap((c) => c.imageRefs.map((filename) => normalizeImage({ filename, path: `/data/images/${filename}`, prompt: c.prompt })))
- : []), [deck]);
+ ? deck.cards.flatMap((c) => c.imageRefs.map((filename) => {
+ const meta = sidecars.get(filename) || null;
+ return normalizeImage({
+ ...(meta || {}),
+ filename,
+ path: `/data/images/${filename}`,
+ prompt: meta?.prompt || c.prompt,
+ });
+ }))
+ : []), [deck, sidecars]);
const [preview, setPreview] = usePreviewRoute(previewItems);
const previewFilename = (filename) => {
const item = previewItems.find((i) => i.filename === filename);
diff --git a/client/src/pages/DeckDetail.preview.test.jsx b/client/src/pages/DeckDetail.preview.test.jsx
new file mode 100644
index 0000000000..7d1bb96b69
--- /dev/null
+++ b/client/src/pages/DeckDetail.preview.test.jsx
@@ -0,0 +1,92 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { render, waitFor } from '@testing-library/react';
+import { MemoryRouter, Routes, Route } from 'react-router';
+import DeckDetail from './DeckDetail';
+
+// The deck page shows each card's SUBJECT prompt in its editor, but a render
+// was sent the composed prompt (deck style clause + layout + subject). The
+// lightbox must show what was actually sent, which only the image sidecar
+// records — hence the gallery hydration this suite pins.
+const getDeck = vi.fn();
+const getGalleryImages = vi.fn();
+let previewProps = null;
+
+vi.mock('../services/api', () => ({
+ deleteDeck: vi.fn(),
+ generateDeckPrompts: vi.fn(),
+ getDeck: (...a) => getDeck(...a),
+ listUniverseSummaries: vi.fn(async () => []),
+ removeDeckSample: vi.fn(),
+ renderDeckCard: vi.fn(),
+ renderDeckCards: vi.fn(),
+ updateDeck: vi.fn(),
+ updateDeckCard: vi.fn(),
+}));
+vi.mock('../services/apiImageVideo', () => ({ getGalleryImages: (...a) => getGalleryImages(...a) }));
+vi.mock('../components/media/MediaPreview', () => ({
+ default: (props) => { previewProps = props; return null; },
+}));
+// The render bar and the card grid each own their own suite; both pull live
+// settings/socket state that says nothing about which prompt the lightbox gets.
+vi.mock('../components/decks/DeckRenderControls', () => ({ default: () => null }));
+vi.mock('../components/decks/DeckCardGrid', () => ({ default: () => null }));
+vi.mock('../hooks/useDeckRenderTarget', () => ({
+ default: () => ({ summary: 'Local · flux2 · 1096×1536', blocked: false, mode: 'local', options: [] }),
+}));
+
+const deck = {
+ id: 'd1',
+ name: 'Test Deck',
+ kind: 'tarot',
+ universeId: null,
+ layoutPrompt: 'Full tarot card, framed border',
+ influences: { embrace: ['copperplate engraving'], avoid: ['blurry'] },
+ cardSize: { width: 1096, height: 1536 },
+ samples: [],
+ cards: [{
+ id: 'c1', key: 'major-0', name: 'The Fool', group: 'major', groupLabel: 'Major Arcana',
+ prompt: 'a youth at a cliff edge', negativePrompt: '', imageRefs: ['fool.png'],
+ primaryImageRef: 'fool.png', render: null, canonRef: null,
+ }],
+};
+
+const renderPage = () => render(
+ <MemoryRouter initialEntries={['/decks/d1']}>
+ <Routes><Route path="/decks/:id" element={<DeckDetail />} /></Routes>
+ </MemoryRouter>,
+);
+
+describe('DeckDetail preview items', () => {
+ beforeEach(() => {
+ previewProps = null;
+ getDeck.mockReset().mockResolvedValue(deck);
+ getGalleryImages.mockReset();
+ });
+
+ it('shows the prompt the renderer was actually sent, not the card subject alone', async () => {
+ getGalleryImages.mockResolvedValue([{
+ filename: 'fool.png',
+ prompt: 'copperplate engraving. Full tarot card, framed border. The Fool: a youth at a cliff edge',
+ negativePrompt: 'blurry',
+ modelId: 'flux2-klein-9b',
+ seed: 42,
+ }]);
+ renderPage();
+ await waitFor(() => expect(getGalleryImages).toHaveBeenCalledWith(['fool.png'], { silent: true }));
+ await waitFor(() => {
+ const item = previewProps?.items?.find((i) => i.filename === 'fool.png');
+ expect(item?.prompt).toBe('copperplate engraving. Full tarot card, framed border. The Fool: a youth at a cliff edge');
+ expect(item?.negativePrompt).toBe('blurry');
+ expect(item?.seed).toBe(42);
+ });
+ });
+
+ it('falls back to the card prompt when the render has no sidecar', async () => {
+ getGalleryImages.mockResolvedValue([]);
+ renderPage();
+ await waitFor(() => {
+ const item = previewProps?.items?.find((i) => i.filename === 'fool.png');
+ expect(item?.prompt).toBe('a youth at a cliff edge');
+ });
+ });
+});
diff --git a/server/lib/deckTemplates.js b/server/lib/deckTemplates.js
index a8633c7e40..03d0569794 100644
--- a/server/lib/deckTemplates.js
+++ b/server/lib/deckTemplates.js
@@ -198,17 +198,24 @@ const trimmed = (v) => (typeof v === 'string' ? v.trim() : '');
* embrace influences lead (diffusion models weight early tokens heaviest),
* then the shared layout clause, then the card's own subject. The avoid list
* becomes the negative prompt, after any per-card negative.
+ *
+ * `parts` carries the same clauses unjoined, so the card editor can show
+ * which contribution came from the deck (style, layout, avoid list) and which
+ * from the card itself — a composed blob alone leaves the user unable to tell
+ * why a render picked up wording they never typed.
*/
export function composeCardRenderPrompt(deck, card) {
// A deck carries the same `influences` shape a universe does, so the
// universe's visual-style projection is the one definition of "what the
// embrace/avoid lists contribute to an image prompt".
- const embrace = buildVisualStyleClause(deck);
+ const style = buildVisualStyleClause(deck);
const avoid = universeVisualStyleTokens(deck).avoid.join(', ');
const layout = trimmed(deck?.layoutPrompt);
const subject = [trimmed(card?.name), trimmed(card?.prompt)].filter(Boolean).join(': ');
+ const cardNegative = trimmed(card?.negativePrompt);
const body = [layout, subject].filter(Boolean).join('. ');
- return composeStyledPrompt(body, trimmed(card?.negativePrompt), { prompt: embrace, negativePrompt: avoid });
+ const composed = composeStyledPrompt(body, cardNegative, { prompt: style, negativePrompt: avoid });
+ return { ...composed, parts: { style, layout, subject, cardNegative, styleNegative: avoid } };
}
const IN_FLIGHT_RENDER = new Set(['queued', 'running']);
diff --git a/server/lib/deckTemplates.test.js b/server/lib/deckTemplates.test.js
index 623b3b30f3..7fdf03e70c 100644
--- a/server/lib/deckTemplates.test.js
+++ b/server/lib/deckTemplates.test.js
@@ -41,7 +41,20 @@ describe('composeCardRenderPrompt', () => {
it('degrades cleanly when the deck has no style guide yet', () => {
const out = composeCardRenderPrompt({}, { name: 'Ace of Spades', prompt: 'one large ornate spade' });
- expect(out).toEqual({ prompt: 'Ace of Spades: one large ornate spade', negativePrompt: '' });
+ expect(out.prompt).toBe('Ace of Spades: one large ornate spade');
+ expect(out.negativePrompt).toBe('');
+ expect(out.parts).toEqual({ style: '', layout: '', subject: 'Ace of Spades: one large ornate spade', cardNegative: '', styleNegative: '' });
+ });
+
+ it('reports each contribution unjoined so the editor can attribute it', () => {
+ const out = composeCardRenderPrompt(deck, { name: 'XVII · The Star', prompt: 'a kneeling figure', negativePrompt: 'text' });
+ expect(out.parts).toEqual({
+ style: 'copperplate engraving, aged paper',
+ layout: 'Full tarot card, framed border',
+ subject: 'XVII · The Star: a kneeling figure',
+ cardNegative: 'text',
+ styleNegative: 'blurry',
+ });
});
});