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
feat: save and use gallery prompts as captions for mood board analysis
[._.]/ Adam Eivy979544ce626a
diff --git a/client/src/components/media/PinToMoodBoardMenu.jsx b/client/src/components/media/PinToMoodBoardMenu.jsxindex 332119e6cf..d7d12a594c 100644--- a/client/src/components/media/PinToMoodBoardMenu.jsx+++ b/client/src/components/media/PinToMoodBoardMenu.jsx@@ -81,11 +81,16 @@ export default function PinToMoodBoardMenu({ item, size = 'sm' }) {// toggle + create-and-pin paths can't drift. Null when there's nothing to pin.const pinPayload = useMemo(() => {if (!mediaKey && !thumbUrl) return null;- const payload = { type: 'image' };+ const isVideo = mediaKey?.startsWith('video:');+ const payload = { type: isVideo ? 'video' : 'image' };if (mediaKey) payload.mediaKey = mediaKey;if (thumbUrl) payload.imageUrl = thumbUrl;+ const promptText = typeof item?.prompt === 'string' && item.prompt !== '(no prompt)' ? item.prompt.trim() : '';+ const captionText = typeof item?.caption === 'string' ? item.caption.trim() : '';+ const effectiveCaption = captionText || promptText || null;+ if (effectiveCaption) payload.caption = effectiveCaption;return payload;- }, [mediaKey, thumbUrl]);+ }, [mediaKey, thumbUrl, item?.prompt, item?.caption]);// The identifiers membership/dedup keys on (mirror the payload).const pinKey = useMemo(() => ({ mediaKey, imageUrl: thumbUrl }), [mediaKey, thumbUrl]);diff --git a/client/src/components/media/PinToMoodBoardMenu.test.jsx b/client/src/components/media/PinToMoodBoardMenu.test.jsxindex fbdf7b6ad6..00b097c1c5 100644--- a/client/src/components/media/PinToMoodBoardMenu.test.jsx+++ b/client/src/components/media/PinToMoodBoardMenu.test.jsx@@ -50,6 +50,23 @@ describe('PinToMoodBoardMenu', () => {await waitFor(() => expect(row).toHaveAttribute('aria-pressed', 'true'));});+ it('includes prompt as caption when pinning gallery media with a prompt', async () => {+ api.listMoodBoards.mockResolvedValue([{ id: 'b1', name: 'Refs', items: [] }]);+ api.addMoodBoardItem.mockResolvedValue({ id: 'mbi-1', type: 'image', mediaKey: 'image:hero.png' });++ render(<PinToMoodBoardMenu item={{ ...imageItem, prompt: 'A cinematic cyberpunk alleyway' }} />);+ fireEvent.click(screen.getByTitle('Pin to mood board'));++ const row = await screen.findByRole('button', { name: /Refs/ });+ await act(async () => { fireEvent.click(row); });++ expect(api.addMoodBoardItem).toHaveBeenCalledWith(+ 'b1',+ { type: 'image', mediaKey: 'image:hero.png', imageUrl: '/data/images/hero.png', caption: 'A cinematic cyberpunk alleyway' },+ { silent: true },+ );+ });+it('unpins when the board already contains the media-key (toggle)', async () => {api.listMoodBoards.mockResolvedValue([{ id: 'b1', name: 'Refs', items: [{ id: 'mbi-9', type: 'image', mediaKey: 'image:hero.png' }] },diff --git a/client/src/lib/moodBoardAnalysis.js b/client/src/lib/moodBoardAnalysis.jsindex c93aa3fc79..49de6144dc 100644--- a/client/src/lib/moodBoardAnalysis.js+++ b/client/src/lib/moodBoardAnalysis.js@@ -49,8 +49,9 @@ export function boardAnalyzePlan(items) {let analyzed = 0;let skipped = 0;for (const item of list) {- const stored = item?.analysis?.prompt;- if (typeof stored === 'string' && stored.trim()) {+ const stored = (item?.analysis?.prompt && typeof item.analysis.prompt === 'string' && item.analysis.prompt.trim())+ || (typeof item?.caption === 'string' && item.caption.trim());+ if (stored) {analyzed += 1;continue;}diff --git a/client/src/lib/moodBoardAnalysis.test.js b/client/src/lib/moodBoardAnalysis.test.jsindex 2dbc69c20f..d4519116b9 100644--- a/client/src/lib/moodBoardAnalysis.test.js+++ b/client/src/lib/moodBoardAnalysis.test.js@@ -46,8 +46,9 @@ describe('boardAnalyzePlan', () => {{ id: 'b', type: 'image', mediaKey: 'image:b.png' },{ id: 'c', type: 'image', imageUrl: 'https://example.com/c.png' },{ id: 'd', type: 'text', text: 'a note' },+ { id: 'e', type: 'image', mediaKey: 'image:e.png', caption: 'caption prompt' },]);- expect(plan.analyzed).toBe(1);+ expect(plan.analyzed).toBe(2);expect(plan.pending.map((it) => it.id)).toEqual(['b']);expect(plan.skipped).toBe(1);});diff --git a/client/src/pages/MoodBoardDetail.jsx b/client/src/pages/MoodBoardDetail.jsxindex 5e5c3cc1bd..ca0bc1bd40 100644--- a/client/src/pages/MoodBoardDetail.jsx+++ b/client/src/pages/MoodBoardDetail.jsx@@ -186,19 +186,23 @@ function MoodBoardEditor({ id }) {const handlePickGalleryImage = (picked) => {if (!picked?.previewUrl && !picked?.key) return;+ const promptText = typeof picked.prompt === 'string' && picked.prompt !== '(no prompt)' ? picked.prompt.trim() : '';addPickedItem({type: 'image',mediaKey: typeof picked.key === 'string' && picked.key.startsWith('image:') ? picked.key : null,imageUrl: picked.previewUrl || null,+ caption: promptText || null,});};const handlePickGalleryVideo = (picked) => {if (!picked?.filename) return;+ const promptText = typeof picked.prompt === 'string' && picked.prompt !== '(no prompt)' ? picked.prompt.trim() : '';addPickedItem({type: 'video',mediaKey: `video:${picked.filename}`,imageUrl: picked.previewUrl || null,+ caption: promptText || null,});};diff --git a/server/services/moodBoard/index.js b/server/services/moodBoard/index.jsindex 40d079260f..4155cc780b 100644--- a/server/services/moodBoard/index.js+++ b/server/services/moodBoard/index.js@@ -95,13 +95,60 @@ export async function deleteBoard(id) {// Pinned/added remote image URLs are downloaded first so the item is born local// (falls back to the URL when the host is unreachable — localizeBoardMedia can// retry later).+import { localImageFilename, assetBasename } from '../../lib/localImageFilename.js';++// Auto-populate item.caption from gallery sidecar / video history prompt when+// no caption was explicitly supplied.+async function resolveGalleryItemCaption(input) {+ if (!input || (input.type !== 'image' && input.type !== 'video')) return input;+ if (typeof input.caption === 'string' && input.caption.trim()) return input;++ try {+ if (input.type === 'image') {+ let filename = null;+ if (typeof input.mediaKey === 'string' && input.mediaKey.startsWith('image:')) {+ filename = assetBasename(input.mediaKey.slice('image:'.length));+ }+ if (!filename && input.imageUrl) {+ filename = localImageFilename(input.imageUrl);+ }+ if (filename) {+ const { readImageSidecar } = await import('../imageGen/local.js');+ const { metadata } = await readImageSidecar(filename).catch(() => ({}));+ const prompt = typeof metadata?.prompt === 'string' ? metadata.prompt.trim() : '';+ if (prompt && prompt !== '(no prompt)') {+ return { ...input, caption: prompt };+ }+ }+ } else if (input.type === 'video') {+ let ref = null;+ if (typeof input.mediaKey === 'string' && input.mediaKey.startsWith('video:')) {+ ref = input.mediaKey.slice('video:'.length);+ }+ if (ref) {+ const { loadHistory } = await import('../videoGen/history.js');+ const history = await loadHistory().catch(() => []);+ const entry = (history || []).find((row) => row && (row.id === ref || row.filename === ref || row.thumbnail === ref));+ const prompt = typeof entry?.prompt === 'string' ? entry.prompt.trim() : '';+ if (prompt && prompt !== '(no prompt)') {+ return { ...input, caption: prompt };+ }+ }+ }+ } catch (_err) {+ // Silently fall back to input if lookup fails+ }+ return input;+}+async function withLocalImage(input) {if (!input || (input.type !== 'image' && input.type !== 'video')) return input;return input.imageUrl ? { ...input, imageUrl: await localizeImageUrl(input.imageUrl) } : input;}export async function addBoardItem(id, itemInput) {- const item = await store.addBoardItem(id, await withLocalImage(itemInput));+ const resolved = await resolveGalleryItemCaption(itemInput);+ const item = await store.addBoardItem(id, await withLocalImage(resolved));emitRecordUpdated('moodBoard', id);return item;}diff --git a/server/services/moodBoardCompositeStyle.js b/server/services/moodBoardCompositeStyle.jsindex 34438d48ca..0f990c297b 100644--- a/server/services/moodBoardCompositeStyle.js+++ b/server/services/moodBoardCompositeStyle.js@@ -19,17 +19,20 @@ const REASON_MAX = 1200;function analyzedItems(board) {const items = Array.isArray(board?.items) ? board.items : [];- return items.filter((it) => it?.analysis && typeof it.analysis.prompt === 'string' && it.analysis.prompt.trim());+ return items.filter((it) => (it?.analysis && typeof it.analysis.prompt === 'string' && it.analysis.prompt.trim())+ || (typeof it?.caption === 'string' && it.caption.trim()));}-// Analyses first so the context budget spends itself on decomposed prompts-// before captions and notes. The stored board order is not rewritten.+// Analyses/captions first so the context budget spends itself on decomposed prompts+// and item captions before notes. The stored board order is not rewritten.function withAnalysesFirst(board) {const items = Array.isArray(board?.items) ? board.items : [];const analyzed = [];const rest = [];for (const it of items) {- if (it?.analysis && typeof it.analysis.prompt === 'string' && it.analysis.prompt.trim()) analyzed.push(it);+ const hasPrompt = (it?.analysis && typeof it.analysis.prompt === 'string' && it.analysis.prompt.trim())+ || (typeof it?.caption === 'string' && it.caption.trim());+ if (hasPrompt) analyzed.push(it);else rest.push(it);}return { ...board, items: [...analyzed, ...rest] };@@ -43,7 +46,7 @@ function buildCompositeStylePrompt({ context, analyzedItemCount }) {const payload = JSON.stringify({ board: context, analyzedItemCount });return `You are a senior prompt engineer. Compose ONE ready-to-render still-image prompt that captures the shared visual style of a mood board.-The board's items have already been decomposed: each "analyzedPrompt" is a render prompt reverse-engineered from that pin. Treat those prompts as the source of truth. Captions and notes are supporting context only. Find the through-line — medium, mark-making, palette, light, texture, lens, composition, mood — and write a single prompt for a canonical reference image of that style. The image is a poster for the board itself: an editorial style reference a viewer would recognize as this board's look, not a collage that restates every item's subject, and not a description of one pin.+The board's items have already been decomposed: each "analyzedPrompt" or "caption" is a render prompt reverse-engineered or carried by that pin. Treat those prompts and captions as the source of truth. Captions and notes are supporting context only. Find the through-line — medium, mark-making, palette, light, texture, lens, composition, mood — and write a single prompt for a canonical reference image of that style. The image is a poster for the board itself: an editorial style reference a viewer would recognize as this board's look, not a collage that restates every item's subject, and not a description of one pin.Do not invent named characters, brands, logos, or copyrighted-artist attribution that the analyses do not already state.@@ -68,16 +71,16 @@ export async function composeBoardPrompt({ board, providerId, model } = {}) {const analyzed = analyzedItems(board);if (!analyzed.length) {throw new ServerError(- 'Analyze at least one item with prompt-from-media before composing a board style. The composite is built from those prompts.',+ 'Analyze at least one item with prompt-from-media or add captions before composing a board style. The composite is built from those prompts.',{ status: 400, code: 'NOTHING_ANALYZED' },);}const context = collectBoardStyleContext(withAnalysesFirst(board));- const fed = context.items.filter((it) => it.analyzedPrompt).length;+ const fed = context.items.filter((it) => it.analyzedPrompt || it.caption).length;if (!fed) {throw new ServerError(- 'The item analyses did not fit the style context. Remove some notes and compose again.',+ 'The item analyses or captions did not fit the style context. Remove some notes and compose again.',{ status: 400, code: 'NOTHING_ANALYZED' },);}diff --git a/server/services/moodBoardCompositeStyle.test.js b/server/services/moodBoardCompositeStyle.test.jsindex 9c7e3c00c1..c4b21a0427 100644--- a/server/services/moodBoardCompositeStyle.test.js+++ b/server/services/moodBoardCompositeStyle.test.js@@ -33,13 +33,23 @@ beforeEach(() => {});describe('composeBoardPrompt', () => {- it('refuses a board whose items have not been decomposed into prompts', async () => {+ it('refuses a board whose items carry neither an analysis nor a caption', async () => {await expect(composeBoardPrompt({- board: { id: 'mb-1', name: 'Empty', items: [{ id: 'i1', type: 'image', mediaKey: 'image:a.png', caption: 'a caption' }] },+ board: { id: 'mb-1', name: 'Empty', items: [{ id: 'i1', type: 'image', mediaKey: 'image:a.png', caption: null }] },})).rejects.toMatchObject({ code: 'NOTHING_ANALYZED', status: 400 });expect(promptRunner.runPromptThroughProvider).not.toHaveBeenCalled();});+ it('accepts items with prompt captions for style composition', async () => {+ const style = await composeBoardPrompt({+ board: { id: 'mb-1', name: 'Captioned', items: [{ id: 'i1', type: 'image', mediaKey: 'image:a.png', caption: 'granular ink wash' }] },+ providerId: 'ollama',+ model: 'qwen',+ });+ expect(style.prompt.startsWith('a weathered foundry')).toBe(true);+ expect(style.analyzedItemCount).toBe(1);+ });+it('distills stored item prompts into one still-image style and strips an imperative prefix', async () => {const style = await composeBoardPrompt({board: {