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: import universe and mood board styles into decks
[._.]/ Adam Eivy80cfd6cd04f0
diff --git a/client/src/components/decks/DeckStylePanel.jsx b/client/src/components/decks/DeckStylePanel.jsxindex 61e9de3428..64c01f4301 100644--- a/client/src/components/decks/DeckStylePanel.jsx+++ b/client/src/components/decks/DeckStylePanel.jsx@@ -2,6 +2,7 @@ import { useState } from 'react';import { ImagePlus, Trash2 } from 'lucide-react';import InfluenceChipsInput from '../universeBuilder/InfluenceChipsInput';import DeckSampleModal from './DeckSampleModal';+import DeckStyleSources from './DeckStyleSources';import useFieldDraft from '../../hooks/useFieldDraft';import {DECK_CARD_ORIENTATION, DECK_CARD_ORIENTATION_LABELS, DECK_CARD_ORIENTATIONS, DECK_KIND_LABELS,@@ -33,6 +34,7 @@ export default function DeckStylePanel({ deck, universes, onPatch, onDeckReplace<div className="grid grid-cols-1 gap-4 lg:grid-cols-2"><section className="space-y-3 bg-port-card border border-port-border rounded-md p-3"><h2 className="text-sm font-medium text-white">Style guide</h2>+ <DeckStyleSources key={`${deck.id}:${deck.universeId || ''}`} deck={deck} onPatch={onPatch} /><div><label htmlFor="deck-description" className="block text-xs text-gray-400 mb-1">Concept</label><textarea id="deck-description" rows={2} value={description.value} onChange={description.onChange} onBlur={description.onBlur} placeholder="What this deck is about — its world, its mood, who it is for." className={INPUT_CLASS} />diff --git a/client/src/components/decks/DeckStyleSources.jsx b/client/src/components/decks/DeckStyleSources.jsxnew file mode 100644index 0000000000..b3c12983da--- /dev/null+++ b/client/src/components/decks/DeckStyleSources.jsx@@ -0,0 +1,61 @@+import { useState } from 'react';+import { getUniverse, listMoodBoardNames } from '../../services/api';+import useAsyncAction from '../../hooks/useAsyncAction';+import useMounted from '../../hooks/useMounted';+import MoodBoardStyleSynthesis from '../universeBuilder/MoodBoardStyleSynthesis';++/** One-time style imports; selecting a source never changes its original record. */+export default function DeckStyleSources({ deck, onPatch }) {+ const [boards, setBoards] = useState(null);+ const [boardId, setBoardId] = useState('');+ const mounted = useMounted();+ const [importUniverse, importing] = useAsyncAction(async () => {+ const universe = await getUniverse(deck.universeId, { silent: true });+ if (!mounted.current) return;+ await onPatch({+ styleNotes: universe.styleNotes ?? '',+ influences: {+ embrace: universe.influences?.embrace ?? [],+ avoid: universe.influences?.avoid ?? [],+ },+ });+ });+ const [loadBoards, loading] = useAsyncAction(async () => {+ const names = await listMoodBoardNames({ silent: true });+ if (mounted.current) setBoards(names);+ });++ return (+ <div className="space-y-2 rounded border border-port-border p-3">+ <div className="flex flex-wrap gap-2">+ <button type="button" disabled={!deck.universeId || importing} onClick={importUniverse}+ className="min-h-[38px] rounded border border-port-accent/40 px-2.5 text-xs text-port-accent disabled:opacity-50">+ {importing ? 'Importing…' : 'Re-import universe style'}+ </button>+ {boards === null ? (+ <button type="button" disabled={loading} onClick={loadBoards}+ className="min-h-[38px] rounded border border-port-accent/40 px-2.5 text-xs text-port-accent disabled:opacity-50">+ {loading ? 'Loading mood boards…' : 'Apply mood board style'}+ </button>+ ) : null}+ </div>+ <p className="text-[11px] text-gray-500">+ Import replaces art direction, style prompt and negative prompt. Card layout, orientation and existing images stay unchanged.+ {!deck.universeId ? ' Link a universe below to import its latest style.' : ''}+ </p>+ {boards !== null ? (+ <div className="space-y-2">+ <label htmlFor="deck-style-board" className="block text-xs text-gray-400">Mood board style source</label>+ <select id="deck-style-board" value={boardId} onChange={(event) => setBoardId(event.target.value)}+ className="w-full min-w-0 rounded border border-port-border bg-port-bg px-3 py-2 text-sm text-white">+ <option value="">Choose a mood board</option>+ {boards.map((board) => <option key={board.id} value={board.id}>{board.name}</option>)}+ </select>+ {boards.length === 0 ? <p className="text-xs text-gray-500">No mood boards yet. <a href="/mood-boards" className="text-port-accent">Create a mood board</a> to collect style references.</p> : null}+ <MoodBoardStyleSynthesis key={boardId} boardId={boardId} universeId={deck.id} targetLabel="deck"+ styleNotes={deck.styleNotes} influences={deck.influences} saved={!importing} onAdopt={onPatch} />+ </div>+ ) : null}+ </div>+ );+}diff --git a/client/src/components/decks/DeckStyleSources.test.jsx b/client/src/components/decks/DeckStyleSources.test.jsxnew file mode 100644index 0000000000..652b4a58f7--- /dev/null+++ b/client/src/components/decks/DeckStyleSources.test.jsx@@ -0,0 +1,66 @@+import { fireEvent, render, screen, waitFor } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';+import DeckStyleSources from './DeckStyleSources';+import { getUniverse, listMoodBoardNames, synthesizeMoodBoardStyle } from '../../services/api';+import toast from '../ui/Toast';++vi.mock('../../services/api', () => ({ getUniverse: vi.fn(), listMoodBoardNames: vi.fn(), synthesizeMoodBoardStyle: vi.fn() }));+vi.mock('../../hooks/useProviderModels', () => ({ default: () => ({+ providers: [{ id: 'p1', name: 'Example provider', type: 'api', enabled: true }],+ selectedProviderId: 'p1', selectedModel: 'example-model', availableModels: ['example-model'],+ setSelectedProviderId: vi.fn(), setSelectedModel: vi.fn(), loading: false,+}) }));+vi.mock('../ui/Toast', () => ({ default: { error: vi.fn() } }));+const deck = { id: 'd1', universeId: 'u1', styleNotes: 'Old style', influences: { embrace: ['ink'], avoid: [] } };++describe('Deck style imports', () => {+ beforeEach(() => vi.clearAllMocks());++ it('re-imports fresh universe style in one patch, including intentionally empty values', async () => {+ getUniverse.mockResolvedValue({ styleNotes: '', influences: { embrace: [], avoid: ['gloss'] }, description: 'Do not import' });+ const onPatch = vi.fn().mockResolvedValue(true);+ render(<DeckStyleSources deck={deck} onPatch={onPatch} />);+ fireEvent.click(screen.getByRole('button', { name: 'Re-import universe style' }));+ await waitFor(() => expect(onPatch).toHaveBeenCalledWith({ styleNotes: '', influences: { embrace: [], avoid: ['gloss'] } }));+ expect(getUniverse).toHaveBeenCalledWith('u1', { silent: true });+ });++ it('leaves the deck untouched on failed or superseded universe loads', async () => {+ const onPatch = vi.fn();+ getUniverse.mockRejectedValueOnce(new Error('Unavailable'));+ const view = render(<DeckStyleSources deck={deck} onPatch={onPatch} />);+ fireEvent.click(screen.getByRole('button', { name: 'Re-import universe style' }));+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Unavailable'));+ expect(onPatch).not.toHaveBeenCalled();+ let resolve;+ getUniverse.mockReturnValueOnce(new Promise((done) => { resolve = done; }));+ fireEvent.click(screen.getByRole('button', { name: 'Re-import universe style' }));+ view.unmount();+ resolve({ styleNotes: 'Stale style' });+ await waitFor(() => expect(onPatch).not.toHaveBeenCalled());+ });++ it('previews mood board synthesis and keeps adoption open when saving fails', async () => {+ listMoodBoardNames.mockResolvedValue([{ id: 'b1', name: 'Example board' }]);+ const proposed = { styleNotes: 'Watercolor', influences: { embrace: ['soft pigment'], avoid: ['gloss'] } };+ synthesizeMoodBoardStyle.mockResolvedValue({ proposed, diff: { hasChanges: true } });+ const onPatch = vi.fn().mockResolvedValueOnce(false).mockResolvedValueOnce(true);+ render(<DeckStyleSources deck={{ ...deck, universeId: null }} onPatch={onPatch} />);+ expect(screen.getByRole('button', { name: 'Re-import universe style' })).toBeDisabled();+ expect(listMoodBoardNames).not.toHaveBeenCalled();+ fireEvent.click(screen.getByRole('button', { name: 'Apply mood board style' }));+ await screen.findByRole('option', { name: 'Example board' });+ fireEvent.change(screen.getByLabelText('Mood board style source'), { target: { value: 'b1' } });+ fireEvent.click(screen.getByRole('button', { name: 'Synthesize style' }));+ expect(synthesizeMoodBoardStyle).not.toHaveBeenCalled();+ fireEvent.click(screen.getByRole('button', { name: 'Synthesize' }));+ await screen.findByText('Style guide preview');+ expect(synthesizeMoodBoardStyle).toHaveBeenCalledWith('b1', expect.objectContaining({ styleNotes: deck.styleNotes, influences: deck.influences }), { silent: true });+ expect(onPatch).not.toHaveBeenCalled();+ fireEvent.click(screen.getByRole('button', { name: 'Adopt style' }));+ await waitFor(() => expect(onPatch).toHaveBeenCalledWith(proposed));+ await waitFor(() => expect(screen.getByRole('button', { name: 'Adopt style' })).toBeEnabled());+ fireEvent.click(screen.getByRole('button', { name: 'Adopt style' }));+ await waitFor(() => expect(screen.queryByText('Style guide preview')).not.toBeInTheDocument());+ });+});diff --git a/client/src/components/universeBuilder/MoodBoardStyleSynthesis.jsx b/client/src/components/universeBuilder/MoodBoardStyleSynthesis.jsxindex b49a9c31e9..d1268a42f6 100644--- a/client/src/components/universeBuilder/MoodBoardStyleSynthesis.jsx+++ b/client/src/components/universeBuilder/MoodBoardStyleSynthesis.jsx@@ -27,7 +27,7 @@ const apiProviderFilter = (p) => p.enabled && p.type === 'api';// until the modal actually opens. The parent keys this by universe+board, so// switching targets remounts it and a stale proposal can never be adopted// into a different universe.-function SynthesisBody({ boardId, styleNotes, influences, locked, onAdopt, onBusyChange, onClose }) {+function SynthesisBody({ targetLabel, boardId, styleNotes, influences, locked, onAdopt, onBusyChange, onClose }) {const [result, setResult] = useState(null);const [running, setRunning] = useState(false);const [adopting, setAdopting] = useState(false);@@ -116,7 +116,7 @@ function SynthesisBody({ boardId, styleNotes, influences, locked, onAdopt, onBus{result ? (<StyleDiffPreviewanalysis={result}- description="Review this diff before deciding whether the board's synthesized style should update the universe."+ description={`Review this diff before deciding whether the board's synthesized style should update the ${targetLabel}.`}/>) : null}{result?.context?.droppedItems ? (@@ -145,7 +145,7 @@ function SynthesisBody({ boardId, styleNotes, influences, locked, onAdopt, onBustype="button"onClick={adopt}disabled={busy || !result.diff?.hasChanges}- title={result.diff?.hasChanges ? 'Apply the proposed style guide to the universe' : 'The current guidance already matches the proposal'}+ title={result.diff?.hasChanges ? `Apply the proposed style guide to the ${targetLabel}` : 'The current guidance already matches the proposal'}className="inline-flex min-h-[38px] items-center gap-2 rounded bg-port-accent px-3 py-2 text-sm text-white disabled:opacity-50">{adopting ? <Loader2 size={14} className="animate-spin" /> : <Sparkles size={14} />}@@ -160,6 +160,7 @@ function SynthesisBody({ boardId, styleNotes, influences, locked, onAdopt, onBusexport default function MoodBoardStyleSynthesis({boardId,universeId,+ targetLabel = 'universe',styleNotes,influences,locked,@@ -178,14 +179,14 @@ export default function MoodBoardStyleSynthesis({setOpen(false);};return (- <div className="flex items-center gap-2">+ <div className="flex flex-wrap items-center gap-2"><buttontype="button"onClick={() => setOpen(true)}disabled={!saved}title={saved- ? 'Distill the linked mood board into the universe style guide'- : 'Save the universe before synthesizing its style'}+ ? `Distill the linked mood board into the ${targetLabel} style guide`+ : `Save the ${targetLabel} before synthesizing its style`}className="inline-flex min-h-[38px] items-center gap-1.5 rounded border border-port-accent/40 px-2.5 py-1.5 text-xs text-port-accent hover:bg-port-accent/10 disabled:opacity-50"><Sparkles size={14} />@@ -199,11 +200,12 @@ export default function MoodBoardStyleSynthesis({closeOnBackdrop={!bodyBusy}usePortalpanelClassName="bg-port-card border border-port-border rounded-xl"- ariaLabel="Synthesize universe style from mood board"+ ariaLabel={`Synthesize ${targetLabel} style from mood board`}>{open ? (<SynthesisBodykey={`${universeId || ''}:${boardId}`}+ targetLabel={targetLabel}boardId={boardId}styleNotes={styleNotes}influences={influences}