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: persist the mood board collage and sample the composite style across the whole board

[._.]/ Adam Eivyb6489b078620
diff --git a/client/src/components/moodBoard/MoodBoardCollagePanel.jsx b/client/src/components/moodBoard/MoodBoardCollagePanel.jsx
index 9f96f5507b..bf2e5d2e1c 100644
--- a/client/src/components/moodBoard/MoodBoardCollagePanel.jsx
+++ b/client/src/components/moodBoard/MoodBoardCollagePanel.jsx
@@ -2,6 +2,7 @@ import { useState } from 'react';
import { LayoutGrid, Download } from 'lucide-react';
import toast from '../ui/Toast';
import { composeMoodBoardCollage } from '../../services/api';
+import { moodBoardCollageSrc } from '../../lib/moodBoardItemSrc';
/**
* Board-level "Collage" control: compiles every image (plus sampled video
@@ -17,6 +18,7 @@ export default function MoodBoardCollagePanel({ board, onBoardChange }) {
const [result, setResult] = useState(null);
if (!hasVisual) return null;
+ const shownSrc = result?.url || moodBoardCollageSrc(board);
const handleBuild = async () => {
setBuilding(true);
@@ -28,7 +30,7 @@ export default function MoodBoardCollagePanel({ board, onBoardChange }) {
setBuilding(false);
if (!res) return;
setResult(res);
- if (res.board && addFramesToBoard) onBoardChange?.(res.board);
+ if (res.board) onBoardChange?.(res.board);
toast.success(`Collage built: ${res.cols}×${res.rows} grid, ${res.cells} image${res.cells === 1 ? '' : 's'}`);
};
@@ -73,12 +75,12 @@ export default function MoodBoardCollagePanel({ board, onBoardChange }) {
{building ? 'Building…' : 'Build collage'}
</button>
</div>
- {result ? (
+ {shownSrc ? (
<div className="space-y-2">
- <img src={result.url} alt="Board collage" className="w-full max-w-md rounded border border-port-border" />
+ <img src={shownSrc} alt="Board collage" className="w-full max-w-md rounded border border-port-border" />
<div className="flex items-center gap-3 text-xs text-gray-400">
- <span>{result.width}×{result.height}px · {result.cols}×{result.rows} grid{result.skipped ? ` · ${result.skipped} skipped` : ''}</span>
- <a href={result.url} download={result.filename} className="flex items-center gap-1 text-port-accent hover:underline">
+ {result ? <span>{result.width}×{result.height}px · {result.cols}×{result.rows} grid{result.skipped ? ` · ${result.skipped} skipped` : ''}</span> : null}
+ <a href={shownSrc} download className="flex items-center gap-1 text-port-accent hover:underline">
<Download className="w-3.5 h-3.5" aria-hidden="true" /> Download
</a>
</div>
diff --git a/client/src/lib/moodBoardItemSrc.js b/client/src/lib/moodBoardItemSrc.js
index 8e398fb775..cd18a5f314 100644
--- a/client/src/lib/moodBoardItemSrc.js
+++ b/client/src/lib/moodBoardItemSrc.js
@@ -27,6 +27,13 @@ export function moodBoardPosterSrc(board) {
return `/data/images/${encodeURIComponent(name)}`;
}
+// The board's last compiled collage (persisted so it survives a reload).
+export function moodBoardCollageSrc(board) {
+ const name = typeof board?.collageImageRef === 'string' ? board.collageImageRef.trim() : '';
+ if (!name || name.includes('/') || name.includes('\\')) return null;
+ return `/data/images/${encodeURIComponent(name)}`;
+}
+
export function moodBoardItemSrc(item) {
if (item?.imageUrl) return item.imageUrl;
if (typeof item?.mediaKey === 'string' && item.mediaKey.startsWith(IMAGE_PREFIX)) {
diff --git a/server/lib/conflictJournal.js b/server/lib/conflictJournal.js
index f465fca9be..a54214606e 100644
--- a/server/lib/conflictJournal.js
+++ b/server/lib/conflictJournal.js
@@ -536,7 +536,7 @@ export const RESTORABLE_FIELDS = Object.freeze({
// the Conflicts UI offers for restore. `moodBoard` matches the record kind,
// and the resolver routes restore through restoreBoard → applyBoardRestore
// (which accepts items, unlike the route's applyBoardPatch).
- moodBoard: ['name', 'description', 'items', 'style', 'posterImageRef'],
+ moodBoard: ['name', 'description', 'items', 'style', 'posterImageRef', 'collageImageRef'],
// Writers Room works (#1565): the user-authored manifest fields the merge can
// restore through `updateWork` (which accepts exactly this set + the liveMode
// partial-merge). Server-owned / structural fields are excluded — `id`/
diff --git a/server/lib/moodBoardStyleContext.js b/server/lib/moodBoardStyleContext.js
index d640a85d57..22d855a284 100644
--- a/server/lib/moodBoardStyleContext.js
+++ b/server/lib/moodBoardStyleContext.js
@@ -31,9 +31,7 @@ const CONTEXT_TOTAL_CHARS_MAX = 24000;
*/
export function collectBoardStyleContext(board) {
const items = Array.isArray(board?.items) ? board.items : [];
- const fragments = [];
- let dropped = 0;
- let totalChars = 0;
+ const entries = [];
for (const it of items) {
if (!it || typeof it !== 'object') continue;
const entry = {};
@@ -57,14 +55,26 @@ export function collectBoardStyleContext(board) {
}
}
if (!Object.keys(entry).length) continue;
- const entrySize = Object.values(entry).reduce((sum, v) => sum + v.length, 0);
- if (fragments.length >= CONTEXT_ITEMS_MAX || totalChars + entrySize > CONTEXT_TOTAL_CHARS_MAX) {
- dropped += 1;
- continue;
- }
- totalChars += entrySize;
- fragments.push({ kind: it.type, ...entry });
+ entries.push({ kind: it.type, ...entry });
+ }
+ // Over budget, keep an evenly spaced sample of the WHOLE board rather than the
+ // first N — truncating in board order made the composite describe only the
+ // earliest pins. Order is preserved so the curated sequence still reads through.
+ const entrySize = (e) => Object.values(e).reduce((sum, v) => sum + (typeof v === 'string' ? v.length : 0), 0);
+ const avgSize = entries.length ? entries.reduce((sum, e) => sum + entrySize(e), 0) / entries.length : 0;
+ const budgetItems = Math.min(CONTEXT_ITEMS_MAX, avgSize ? Math.floor(CONTEXT_TOTAL_CHARS_MAX / avgSize) : CONTEXT_ITEMS_MAX);
+ const candidates = entries.length <= budgetItems
+ ? entries
+ : Array.from({ length: budgetItems }, (_, i) => entries[Math.floor(((i + 0.5) * entries.length) / budgetItems)]);
+ const fragments = [];
+ let totalChars = 0;
+ for (const e of candidates) {
+ const size = entrySize(e);
+ if (fragments.length >= CONTEXT_ITEMS_MAX || totalChars + size > CONTEXT_TOTAL_CHARS_MAX) break;
+ totalChars += size;
+ fragments.push(e);
}
+ const dropped = entries.length - fragments.length;
// The board's own composite prompt is the distilled through-line. It is one
// field, so it gets the description budget rather than the per-item cap —
// clipping it to 600 would drop the look downstream renders are asked to match.
diff --git a/server/lib/moodBoardValidation.js b/server/lib/moodBoardValidation.js
index 26b6badb0d..69f69a0c7f 100644
--- a/server/lib/moodBoardValidation.js
+++ b/server/lib/moodBoardValidation.js
@@ -86,6 +86,7 @@ export const moodBoardUpdateSchema = z.object({
description: z.string().max(5000).optional(),
style: moodBoardStyleSchema.nullable().optional(),
posterImageRef: posterFilenameSchema.nullable().optional(),
+ collageImageRef: posterFilenameSchema.nullable().optional(),
}).strict();
// Add-item. An `image` item requires at least one of mediaKey / imageUrl; a
diff --git a/server/lib/schemaVersions.js b/server/lib/schemaVersions.js
index 7b69675fc6..1979491b5b 100644
--- a/server/lib/schemaVersions.js
+++ b/server/lib/schemaVersions.js
@@ -528,7 +528,7 @@ export const PORTOS_SCHEMA_VERSIONS = Object.freeze({
// the ahead-version push until it upgrades. Video bytes ride the existing
// asset manifest (`video:<filename>` ref → PATHS.videos, receiver regenerates
// the poster thumbnail on pull).
- // A board's composite `style` prompt and `posterImageRef` are additive on
+ // A board's composite `style` prompt, `posterImageRef` and `collageImageRef` are additive on
// that same v2 record: whole-record LWW plus every local mutator spreads the
// board, so an older peer preserves both keys and does not execute against
// them. The poster file rides the asset manifest as a gallery image. No bump.
diff --git a/server/services/moodBoard/collage.js b/server/services/moodBoard/collage.js
index e34629b6c3..321e203702 100644
--- a/server/services/moodBoard/collage.js
+++ b/server/services/moodBoard/collage.js
@@ -201,6 +201,8 @@ export async function composeBoardCollage(boardId, { framesPerVideo, addFramesTo
nextBoard = res.board;
if (res.added) emitRecordUpdated('moodBoard', boardId);
}
+ nextBoard = await store.updateBoard(boardId, { collageImageRef: filename });
+ emitRecordUpdated('moodBoard', boardId);
console.log(`🧩 Mood board ${boardId}: collage ${cols}x${rows} (${composites.length} cells, ${skipped} skipped) → ${filename}`);
return { filename, url: `/data/images/${filename}`, width, height, cols, rows, cells: composites.length, skipped, board: nextBoard };
} finally {
diff --git a/server/services/moodBoard/logic.js b/server/services/moodBoard/logic.js
index 90b813e2db..1d2c144844 100644
--- a/server/services/moodBoard/logic.js
+++ b/server/services/moodBoard/logic.js
@@ -174,6 +174,7 @@ export function applyBoardPatch(board, patch) {
if (patch.description !== undefined) next.description = patch.description;
if (patch.style !== undefined) next.style = normalizeBoardStyle(patch.style);
if (patch.posterImageRef !== undefined) next.posterImageRef = patch.posterImageRef ?? null;
+ if (patch.collageImageRef !== undefined) next.collageImageRef = patch.collageImageRef ?? null;
next.updatedAt = nowIso();
return next;
}
@@ -305,6 +306,7 @@ export function applyBoardRestore(board, patch) {
if (Array.isArray(patch.items)) next.items = patch.items;
if (patch.style !== undefined) next.style = normalizeBoardStyle(patch.style);
if (patch.posterImageRef !== undefined) next.posterImageRef = patch.posterImageRef ?? null;
+ if (patch.collageImageRef !== undefined) next.collageImageRef = patch.collageImageRef ?? null;
next.updatedAt = nowIso();
return next;
}
diff --git a/server/services/moodBoard/styleContext.test.js b/server/services/moodBoard/styleContext.test.js
index 4e8af386eb..4435986cdc 100644
--- a/server/services/moodBoard/styleContext.test.js
+++ b/server/services/moodBoard/styleContext.test.js
@@ -80,4 +80,15 @@ describe('collectBoardStyleContext', () => {
const total = ctx.items.reduce((sum, it) => sum + it.note.length, 0);
expect(total).toBeLessThanOrEqual(24000);
});
+
+ it('samples across the whole board when over budget instead of keeping only the first items', () => {
+ const many = Array.from({ length: 200 }, (_, i) => ({ id: `t${i}`, type: 'text', text: `pin-${i}` }));
+ const ctx = collectBoardStyleContext(boardWith(many));
+ expect(ctx.items).toHaveLength(60);
+ const idx = ctx.items.map((it) => Number(it.note.slice(4)));
+ expect(idx).toEqual([...idx].sort((a, b) => a - b));
+ expect(idx[0]).toBeLessThan(10);
+ expect(idx[idx.length - 1]).toBeGreaterThan(190);
+ expect(ctx.droppedItems).toBe(140);
+ });
});
diff --git a/server/services/moodBoardCompositeStyle.js b/server/services/moodBoardCompositeStyle.js
index 62d98eb3dc..74afc7d617 100644
--- a/server/services/moodBoardCompositeStyle.js
+++ b/server/services/moodBoardCompositeStyle.js
@@ -48,7 +48,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" 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.
+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. Every item is a peer: draw on elements from across the WHOLE board — recurring motifs, palette, materials, subjects, and light seen in many pins — and never build the prompt around any single pin or one pin's subject. 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.
diff --git a/server/services/sharing/peerSyncAssets.js b/server/services/sharing/peerSyncAssets.js
index 09e2b41c3d..eb439b4e5f 100644
--- a/server/services/sharing/peerSyncAssets.js
+++ b/server/services/sharing/peerSyncAssets.js
@@ -662,6 +662,8 @@ export function referenceBoardAssetManifest(board) {
// is dropped later by the hash step, same as any other image ref.
const poster = imageAssetReference(board?.posterImageRef);
if (poster) dedup.set(`${poster.kind}:${poster.filename}`, poster);
+ const collage = imageAssetReference(board?.collageImageRef);
+ if (collage) dedup.set(`${collage.kind}:${collage.filename}`, collage);
for (const it of Array.isArray(board?.items) ? board.items : []) {
// `video` items (#4188) carry a `video:<filename>` mediaKey (the ref IS
// the on-disk filename, so collectionVideoRefToFilename passes it through