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

fix(mood-boards): reuse gallery prompts so board analyze skips already-prompted pins

Adam Eivy1c800504d95d
diff --git a/client/src/components/moodBoard/MoodBoardStylePanel.jsx b/client/src/components/moodBoard/MoodBoardStylePanel.jsx
index 4658e8ff36..bf1816d561 100644
--- a/client/src/components/moodBoard/MoodBoardStylePanel.jsx
+++ b/client/src/components/moodBoard/MoodBoardStylePanel.jsx
@@ -18,7 +18,7 @@ import useProviderModels from '../../hooks/useProviderModels';
import useVisionModelIds from '../../hooks/useVisionModelIds';
import useImageRenderSettings from '../../hooks/useImageRenderSettings';
import useSingleImageRender from '../../hooks/useSingleImageRender';
-import { promptFromMedia, updateMoodBoard, updateMoodBoardItem, composeMoodBoardPrompt } from '../../services/api';
+import { promptFromMedia, updateMoodBoard, updateMoodBoardItem, composeMoodBoardPrompt, backfillMoodBoardPrompts } from '../../services/api';
import { isVisionCapableCliProvider, visionLocalModelFilter } from '../../utils/providers';
import { formatCount } from '../../utils/formatters';
import { moodBoardItemAnalysisSource, moodBoardPosterSrc } from '../../lib/moodBoardItemSrc';
@@ -147,7 +147,12 @@ export default function MoodBoardStylePanel({ board, onBoardChange }) {
}
setBusy(true);
let failures = 0;
- const pending = plan.pending;
+ // Adopt gallery prompts for older pins first so they aren't re-analyzed.
+ const filled = await backfillMoodBoardPrompts(board.id, { silent: true }).catch(() => null);
+ if (!mountedRef.current) return;
+ const activePlan = filled ? boardAnalyzePlan(filled.items) : plan;
+ if (filled) onBoardChange(filled);
+ const pending = activePlan.pending;
for (let i = 0; i < pending.length; i += 1) {
const item = pending[i];
const source = moodBoardItemAnalysisSource(item);
@@ -175,7 +180,7 @@ export default function MoodBoardStylePanel({ board, onBoardChange }) {
replaceItem(saved);
}
setProgress('');
- const analyzedNow = plan.analyzed + (pending.length - failures);
+ const analyzedNow = activePlan.analyzed + (pending.length - failures);
if (analyzedNow < 1) {
setBusy(false);
toast.error('No item could be analyzed, so the board style was not composed');
diff --git a/client/src/components/moodBoard/MoodBoardStylePanel.test.jsx b/client/src/components/moodBoard/MoodBoardStylePanel.test.jsx
index 304ccf71bb..2ce8b01fc5 100644
--- a/client/src/components/moodBoard/MoodBoardStylePanel.test.jsx
+++ b/client/src/components/moodBoard/MoodBoardStylePanel.test.jsx
@@ -17,6 +17,7 @@ const {
vi.mock('../../services/api', () => ({
promptFromMedia: (...args) => mockPrompt(...args),
composeMoodBoardPrompt: (...args) => mockCompose(...args),
+ backfillMoodBoardPrompts: async () => null,
updateMoodBoardItem: (...args) => mockUpdateItem(...args),
updateMoodBoard: (...args) => mockUpdateBoard(...args),
}));
diff --git a/client/src/services/README.md b/client/src/services/README.md
index 58f7208772..67b88ee3bd 100644
--- a/client/src/services/README.md
+++ b/client/src/services/README.md
@@ -84,7 +84,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire
| `apiHealth.js` | Apple Health. |
| `apiMeatspace.js` | MeatSpace health, genome, POST, memory-practice, and atomic POST training-run APIs. |
| `apiMortalLoom.js` | Mortality tracking. |
-| `apiMoodBoard.js` | Mood boards (inspiration canvas + items), `listMoodBoardNames()` for pickers, and `composeMoodBoardPrompt()` which stores the board's composite style prompt. |
+| `apiMoodBoard.js` | Mood boards (inspiration canvas + items), `listMoodBoardNames()` for pickers, `backfillMoodBoardPrompts()` and `composeMoodBoardPrompt()` which stores the board's composite style prompt. |
| `apiTribe.js` | Tribe people (relationship rings + contacts), plus `getTribeDuplicateIdentifiers()` (`GET /tribe/duplicate-identifiers`): a non-blocking report of emails/phones shared by more than one person. |
| `apiTimeline.js` | Human-activity timeline: `/timeline/day`. |
| `apiCalendar.js` | Calendar events. |
diff --git a/client/src/services/apiMoodBoard.js b/client/src/services/apiMoodBoard.js
index 849af0e8db..ca98671445 100644
--- a/client/src/services/apiMoodBoard.js
+++ b/client/src/services/apiMoodBoard.js
@@ -49,6 +49,11 @@ export const removeMoodBoardItem = (id, itemId, options) =>
...options,
});
+// Copy gallery generation prompts onto pins that lack any prompt (resolves to
+// the updated board) so analyzing the board skips them.
+export const backfillMoodBoardPrompts = (id, options = {}) =>
+ request(`/mood-boards/${encodeURIComponent(id)}/backfill-prompts`, { method: 'POST', ...options });
+
// Distill stored per-item analyses into the board's own composite style prompt
// and persist it on the board (`style`). Resolves to the updated board.
export const composeMoodBoardPrompt = (id, { providerId, model } = {}, options = {}) =>
diff --git a/server/routes/moodBoard.js b/server/routes/moodBoard.js
index c6fdc36e11..5466e8b339 100644
--- a/server/routes/moodBoard.js
+++ b/server/routes/moodBoard.js
@@ -33,6 +33,7 @@ import {
updateBoard,
deleteBoard,
addBoardItem,
+ backfillGalleryPrompts,
updateBoardItem,
removeBoardItem,
linkPinterestBoard,
@@ -128,6 +129,14 @@ const composePromptSchema = z.object({
providerId: z.string().trim().max(128).optional(),
model: z.string().trim().max(256).optional(),
}).strict();
+// Copy gallery generation prompts onto pins that lack any prompt, so the board
+// analyze step doesn't re-run vision on them. Resolves to the updated board.
+router.post('/:id/backfill-prompts', asyncHandler(async (req, res) => {
+ const board = await backfillGalleryPrompts(req.params.id);
+ if (!board) throw new ServerError('Mood board not found', { status: 404, code: 'NOT_FOUND' });
+ res.json(board);
+}));
+
router.post('/:id/compose-prompt', asyncHandler(async (req, res) => {
const body = validateRequest(composePromptSchema, req.body ?? {});
const board = await getBoard(req.params.id);
diff --git a/server/routes/moodBoard.test.js b/server/routes/moodBoard.test.js
index d6c243b825..271ea8e4b6 100644
--- a/server/routes/moodBoard.test.js
+++ b/server/routes/moodBoard.test.js
@@ -13,6 +13,7 @@ vi.mock('../services/moodBoard/index.js', () => ({
updateBoard: vi.fn(),
deleteBoard: vi.fn(),
addBoardItem: vi.fn(),
+ backfillGalleryPrompts: vi.fn(),
updateBoardItem: vi.fn(),
removeBoardItem: vi.fn(),
linkPinterestBoard: vi.fn(),
@@ -160,6 +161,17 @@ describe('mood-board routes', () => {
});
});
+ describe('POST /:id/backfill-prompts', () => {
+ it('404s when the board is missing and returns the updated board otherwise', async () => {
+ svc.backfillGalleryPrompts.mockResolvedValueOnce(null);
+ expect((await request(makeApp()).post('/api/mood-boards/nope/backfill-prompts')).status).toBe(404);
+ svc.backfillGalleryPrompts.mockResolvedValueOnce({ id: 'mb-1', items: [{ id: 'i1', caption: 'p' }] });
+ const res = await request(makeApp()).post('/api/mood-boards/mb-1/backfill-prompts');
+ expect(res.status).toBe(200);
+ expect(res.body.items[0].caption).toBe('p');
+ });
+ });
+
describe('POST /:id/x-post', () => {
it('validates the body and passes it to the service', async () => {
svc.importXPost.mockResolvedValueOnce({ board: { id: 'mb-1' }, added: 2 });
diff --git a/server/services/moodBoard/index.js b/server/services/moodBoard/index.js
index 290a17292b..9e6e0130b2 100644
--- a/server/services/moodBoard/index.js
+++ b/server/services/moodBoard/index.js
@@ -97,12 +97,10 @@ export async function deleteBoard(id) {
// 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;
-
+// Gallery prompt (image sidecar / video history) for a pinned gallery item, or
+// '' when none is recorded. `videoHistory` lets a batch caller load it once.
+async function lookupGalleryPrompt(input, videoHistory) {
+ if (!input || (input.type !== 'image' && input.type !== 'video')) return '';
try {
if (input.type === 'image') {
let filename = null;
@@ -112,33 +110,54 @@ async function resolveGalleryItemCaption(input) {
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, prompt: input.prompt || prompt, caption: 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, prompt: input.prompt || prompt, caption: input.caption || prompt };
- }
- }
+ if (!filename) return '';
+ const { readImageSidecar } = await import('../imageGen/local.js');
+ const { metadata } = await readImageSidecar(filename).catch(() => ({}));
+ const prompt = typeof metadata?.prompt === 'string' ? metadata.prompt.trim() : '';
+ return prompt && prompt !== '(no prompt)' ? prompt : '';
}
+ if (typeof input.mediaKey !== 'string' || !input.mediaKey.startsWith('video:')) return '';
+ const ref = input.mediaKey.slice('video:'.length);
+ const history = videoHistory ?? await (await import('../videoGen/history.js')).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() : '';
+ return prompt && prompt !== '(no prompt)' ? prompt : '';
} catch (_err) {
- // Silently fall back to input if lookup fails
+ return '';
+ }
+}
+
+// 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;
+ const prompt = await lookupGalleryPrompt(input);
+ return prompt ? { ...input, caption: prompt } : input;
+}
+
+// Board "Analyze" must not spend vision runs on pins whose generation prompt is
+// already on record. Pins made before captions were auto-filled from the gallery
+// have neither analysis, prompt nor caption; copy the gallery prompt onto those
+// as their caption (never overwriting user text) so the client plan skips them.
+export async function backfillGalleryPrompts(id) {
+ const board = await store.getBoard(id);
+ if (!board) return null;
+ const needs = (board.items || []).filter((it) => (it.type === 'image' || it.type === 'video')
+ && !it.analysis?.prompt?.trim() && !it.prompt?.trim() && !it.caption?.trim());
+ if (!needs.length) return board;
+ const hasVideo = needs.some((it) => it.type === 'video');
+ const history = hasVideo ? await (await import('../videoGen/history.js')).loadHistory().catch(() => []) : [];
+ let changed = false;
+ for (const it of needs) {
+ const prompt = await lookupGalleryPrompt(it, history);
+ if (!prompt) continue;
+ await store.updateBoardItem(id, it.id, { caption: prompt.slice(0, 2000) });
+ changed = true;
}
- return input;
+ if (!changed) return board;
+ emitRecordUpdated('moodBoard', id);
+ return store.getBoard(id);
}
async function withLocalImage(input) {