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: turn /music/generate into a stepped music designer (#4305)
[._.]/ Adam Eivy4fe11c978c69
diff --git a/client/src/components/music/MusicDesigner.jsx b/client/src/components/music/MusicDesigner.jsxnew file mode 100644index 0000000000..a317e06134--- /dev/null+++ b/client/src/components/music/MusicDesigner.jsx@@ -0,0 +1,448 @@+/**+ * MusicDesigner (#4305) — the Music studio's Generate tab, as a stepped+ * designer instead of a bare three-field form.+ *+ * concept → description → lyrics (optional) → render+ *+ * The user starts from a short reference/vibe ("a cross between X and Y"), an+ * AI provider of their choosing expands it into a rich, genre-dense musical+ * description, they optionally generate lyrics from that description plus their+ * own extra guidance, and the existing `MusicGenPanel` renders the track. Every+ * step's output lands in an editable textarea — **the AI drafts, the human owns+ * the text** — and every step stays revisitable from the step bar.+ *+ * Two constraints shape this component:+ *+ * - **No cold-bootstrap LLM calls** (root CLAUDE.md). Both provider calls fire+ * only from an explicit button press in the same interaction — nothing runs+ * on mount, on blur, or ahead of the user.+ * - **Selection lives in the URL.** The active step is the `:id` slot of the+ * existing `music/:tab/:id` route (`/music/generate/description`), so it is+ * deep-linkable and reload-safe. Text state is in-memory for the tab's+ * lifetime (drafts are out of scope); the provider/model/effort pin and the+ * meta-prompt overrides persist to `settings.music.designer`.+ */++import { useEffect, useRef, useState } from 'react';+import { Navigate, useNavigate, useParams } from 'react-router';+import {+ AudioLines, ChevronDown, ChevronUp, FileText, Lightbulb, Loader2, Mic2, Sparkles, Wand2,+} from 'lucide-react';+import MusicGenPanel from './MusicGenPanel';+import ProviderModelSelector from '../ProviderModelSelector';+import TabPills from '../ui/TabPills';+import toast from '../ui/Toast';+import useMounted from '../../hooks/useMounted';+import useProviderModels from '../../hooks/useProviderModels';+import { describeMusic, generateLyrics, getSettings, updateSettings } from '../../services/api';++const STEPS = [+ { id: 'concept', label: 'Concept', icon: Lightbulb },+ { id: 'description', label: 'Description', icon: FileText },+ { id: 'lyrics', label: 'Lyrics', icon: Mic2 },+ { id: 'render', label: 'Render', icon: AudioLines },+];+const STEP_IDS = STEPS.map((s) => s.id);+const FIRST_STEP = STEP_IDS[0];++// Display-only mirrors of the shipped meta-prompts in+// `server/services/musicDesigner.js`. They are rendered as placeholder text so+// the user can see what they're overriding; the SERVER is the authority — an+// empty override field sends no `template` at all and the server falls back to+// its own constant, so drift here is cosmetic and can never change what runs.+const DESCRIBE_PLACEHOLDER = 'Describe the given musical reference and description in richer detail in English, focusing primarily on the sound, instruments, feel, and the overall atmosphere. Also briefly describe the composition, instrumentation, beats, lyrical or instrumental style (maybe it doesn\'t have lyrics), and aesthetic. Keep it concise and genre-focused rather than overly technical.';+const LYRICS_PLACEHOLDER = 'Write original song lyrics that fit the musical description below. Use the section syntax the audio engine expects: a bracketed section tag alone on its line ([verse], [chorus], [bridge], [outro]) with that section\'s lines beneath it. Match the mood, genre, energy, and vocal style implied by the description, and keep the phrasing singable. Keep the lyrics original (do not reproduce copyrighted lyrics verbatim).';++const FIELD_CLASS = 'w-full rounded border border-port-border bg-port-bg px-3 py-2 text-sm text-white';+const LABEL_CLASS = 'mb-1 block text-xs uppercase tracking-wider text-gray-500';+const PRIMARY_BTN = 'inline-flex items-center justify-center gap-1.5 rounded-lg bg-port-accent px-3 py-2 text-sm font-medium text-white transition-colors hover:bg-port-accent/80 disabled:opacity-50 min-h-[40px]';+const GHOST_BTN = 'inline-flex items-center justify-center gap-1.5 rounded-lg border border-port-border px-3 py-2 text-sm text-gray-300 transition-colors hover:border-port-accent hover:text-white disabled:opacity-50 min-h-[40px]';++export default function MusicDesigner() {+ const navigate = useNavigate();+ const { id } = useParams();+ const mountedRef = useMounted();++ // Wizard text — lifted here so MusicGenPanel (which never writes back to+ // prompt/lyrics) can be re-hosted under step 4 unchanged, and so edits+ // survive step navigation.+ const [concept, setConcept] = useState('');+ const [conceptGuidance, setConceptGuidance] = useState('');+ const [description, setDescription] = useState('');+ const [lyricsGuidance, setLyricsGuidance] = useState('');+ const [lyrics, setLyrics] = useState('');+ const [title, setTitle] = useState('');++ // Meta-prompt overrides. Blank = "use the shipped default" (resolved+ // server-side), which is exactly what "Reset to default" restores.+ const [describeTemplate, setDescribeTemplate] = useState('');+ const [lyricsTemplate, setLyricsTemplate] = useState('');+ const [advancedOpen, setAdvancedOpen] = useState(false);++ const [effort, setEffort] = useState('');+ const [describing, setDescribing] = useState(false);+ const [writing, setWriting] = useState(false);+ // Saved provider pin, parked until the provider list loads — the hook+ // auto-selects a default when its list arrives, so applying immediately would+ // race that load (same pattern as ChiptunePanel).+ const [savedPin, setSavedPin] = useState(null);+ const musicSettingsRef = useRef({});++ const {+ providers, selectedProviderId, selectedModel, availableModels,+ setSelectedProviderId, setSelectedModel, loading: providersLoading,+ } = useProviderModels({ silent: true, withEffort: true });++ // Load saved prefs once. Templates apply immediately; the provider pin waits+ // for the provider list.+ useEffect(() => {+ getSettings({ silent: true }).then((settings) => {+ if (!mountedRef.current) return;+ const music = settings?.music || {};+ musicSettingsRef.current = music;+ const saved = music.designer || {};+ if (saved.describeTemplate) setDescribeTemplate(saved.describeTemplate);+ if (saved.lyricsTemplate) setLyricsTemplate(saved.lyricsTemplate);+ if (saved.providerId) {+ setSavedPin({ providerId: saved.providerId, model: saved.model || '', effort: saved.effort || '' });+ } else if (saved.effort) {+ setEffort(saved.effort);+ }+ }).catch(() => {});+ }, []);++ // Apply the saved pin once providers are loaded. A stale saved provider id+ // degrades to the hook's own default selection; a stale saved MODEL is+ // skipped too — the select doesn't render unmatched values, so applying it+ // would send a model the provider no longer has while showing another.+ useEffect(() => {+ if (!savedPin || providersLoading || !providers.length) return;+ const provider = providers.find((p) => p.id === savedPin.providerId);+ if (provider) {+ setSelectedProviderId(savedPin.providerId);+ const models = (provider.models?.length ? provider.models : [provider.defaultModel])+ .map((m) => (typeof m === 'string' ? m : m?.id)).filter(Boolean);+ if (savedPin.model && models.includes(savedPin.model)) setSelectedModel(savedPin.model);+ if (savedPin.effort) setEffort(savedPin.effort);+ }+ setSavedPin(null); // apply once+ }, [savedPin, providersLoading, providers, setSelectedProviderId, setSelectedModel]);++ const persistDesignerPrefs = (patch) => {+ const music = musicSettingsRef.current;+ const next = { ...music, designer: { ...(music.designer || {}), ...patch } };+ musicSettingsRef.current = next;+ updateSettings({ music: next }, { silent: true }).catch(() => {});+ };++ const goTo = (stepId) => navigate(`/music/generate/${stepId}`);++ const runDescribe = async ({ advance }) => {+ if (!concept.trim()) { toast.error('Describe the vibe (or name a reference) first'); return; }+ setDescribing(true);+ const res = await describeMusic({+ concept: concept.trim(),+ guidance: conceptGuidance.trim() || undefined,+ template: describeTemplate.trim() || undefined,+ providerId: selectedProviderId || undefined,+ model: selectedModel || undefined,+ effort: effort || undefined,+ }, { silent: true }).catch((err) => { toast.error(err?.message || 'Could not describe the music'); return null; });+ if (!mountedRef.current) return;+ setDescribing(false);+ if (!res?.description) return;+ setDescription(res.description);+ persistDesignerPrefs({ providerId: selectedProviderId || '', model: selectedModel || '', effort: effort || '' });+ if (advance) goTo('description');+ };++ const runLyrics = async () => {+ if (!description.trim()) { toast.error('Write the musical description first'); return; }+ setWriting(true);+ const res = await generateLyrics({+ description: description.trim(),+ guidance: lyricsGuidance.trim() || undefined,+ template: lyricsTemplate.trim() || undefined,+ providerId: selectedProviderId || undefined,+ model: selectedModel || undefined,+ effort: effort || undefined,+ }, { silent: true }).catch((err) => { toast.error(err?.message || 'Could not write the lyrics'); return null; });+ if (!mountedRef.current) return;+ setWriting(false);+ if (!res?.lyrics) return;+ setLyrics(res.lyrics);+ persistDesignerPrefs({ providerId: selectedProviderId || '', model: selectedModel || '', effort: effort || '' });+ };++ const busy = describing || writing;++ const providerPicker = (+ <ProviderModelSelector+ providers={providers}+ selectedProviderId={selectedProviderId}+ selectedModel={selectedModel}+ availableModels={availableModels}+ onProviderChange={(pid) => { setSelectedProviderId(pid); setEffort(''); }}+ onModelChange={setSelectedModel}+ effort={effort}+ onEffortChange={setEffort}+ disabled={busy || providersLoading}+ layout="stacked"+ />+ );++ // Unknown step → the first step, rather than an empty shell (mirrors the tab+ // fallback in pages/Music.jsx). Declared after the hooks so the hook order is+ // stable across the redirect render.+ const step = id || FIRST_STEP;+ if (!STEP_IDS.includes(step)) return <Navigate to={`/music/generate/${FIRST_STEP}`} replace />;++ return (+ <section className="max-w-4xl space-y-4">+ <div>+ <h2 className="text-lg font-semibold text-white">Design a tune</h2>+ <p className="text-sm text-gray-400">+ Start from a reference or a vibe. AI drafts the musical description and the lyrics — you edit both before anything is rendered.+ </p>+ </div>++ <TabPills+ tabs={STEPS}+ activeTab={step}+ onChange={goTo}+ mobileDropdown+ mobileSelectId="music-designer-step"+ ariaLabel="Music designer steps"+ />++ {step === 'concept' && (+ <div className="space-y-4">+ <label htmlFor="music-designer-concept" className="block">+ <span className={LABEL_CLASS}>What do you want to hear?</span>+ <textarea+ id="music-designer-concept"+ value={concept}+ onChange={(event) => setConcept(event.target.value)}+ rows={3}+ maxLength={8000}+ placeholder="A cross between a rain-soaked downtempo instrumental and a late-night synth ballad…"+ className={FIELD_CLASS}+ />+ </label>++ <label htmlFor="music-designer-concept-guidance" className="block">+ <span className={LABEL_CLASS}>Extra guidance (optional)</span>+ <input+ id="music-designer-concept-guidance"+ value={conceptGuidance}+ onChange={(event) => setConceptGuidance(event.target.value)}+ maxLength={4000}+ placeholder="Keep it under 100 BPM, no vocals in the intro…"+ className={FIELD_CLASS}+ />+ </label>++ <div className="rounded border border-port-border bg-port-bg/60 p-3">+ <span className={LABEL_CLASS}>AI provider</span>+ {providerPicker}+ </div>++ <div className="rounded border border-port-border bg-port-bg/60">+ <button+ type="button"+ onClick={() => setAdvancedOpen((open) => !open)}+ aria-expanded={advancedOpen}+ className="flex w-full items-center justify-between gap-2 px-3 py-2 text-xs font-medium text-gray-300 hover:text-white min-h-[40px]"+ >+ <span>Advanced — meta-prompts</span>+ {advancedOpen ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}+ </button>+ {advancedOpen && (+ <div className="space-y-3 border-t border-port-border p-3">+ <p className="text-xs text-gray-500">+ Leave a field blank to use the shipped instruction shown in it.+ </p>+ <div>+ <div className="flex items-center justify-between gap-2">+ <label htmlFor="music-designer-describe-template" className={LABEL_CLASS}>Description instruction</label>+ <button+ type="button"+ onClick={() => { setDescribeTemplate(''); persistDesignerPrefs({ describeTemplate: '' }); }}+ disabled={!describeTemplate}+ className="text-xs text-port-accent hover:underline disabled:opacity-40 min-h-[32px]"+ >+ Reset to default+ </button>+ </div>+ <textarea+ id="music-designer-describe-template"+ value={describeTemplate}+ onChange={(event) => setDescribeTemplate(event.target.value)}+ onBlur={() => persistDesignerPrefs({ describeTemplate: describeTemplate.trim() })}+ rows={4}+ maxLength={8000}+ placeholder={DESCRIBE_PLACEHOLDER}+ className={FIELD_CLASS}+ />+ </div>+ <div>+ <div className="flex items-center justify-between gap-2">+ <label htmlFor="music-designer-lyrics-template" className={LABEL_CLASS}>Lyrics instruction</label>+ <button+ type="button"+ onClick={() => { setLyricsTemplate(''); persistDesignerPrefs({ lyricsTemplate: '' }); }}+ disabled={!lyricsTemplate}+ className="text-xs text-port-accent hover:underline disabled:opacity-40 min-h-[32px]"+ >+ Reset to default+ </button>+ </div>+ <textarea+ id="music-designer-lyrics-template"+ value={lyricsTemplate}+ onChange={(event) => setLyricsTemplate(event.target.value)}+ onBlur={() => persistDesignerPrefs({ lyricsTemplate: lyricsTemplate.trim() })}+ rows={4}+ maxLength={8000}+ placeholder={LYRICS_PLACEHOLDER}+ className={FIELD_CLASS}+ />+ </div>+ </div>+ )}+ </div>++ <div className="flex flex-wrap gap-2">+ <button+ type="button"+ onClick={() => runDescribe({ advance: true })}+ disabled={busy || !concept.trim()}+ className={PRIMARY_BTN}+ >+ {describing ? <Loader2 className="h-4 w-4 animate-spin" /> : <Sparkles className="h-4 w-4" />}+ <span>{describing ? 'Describing…' : 'Describe it'}</span>+ </button>+ {description.trim() && (+ <button type="button" onClick={() => goTo('description')} disabled={busy} className={GHOST_BTN}>+ Keep my description+ </button>+ )}+ </div>+ </div>+ )}++ {step === 'description' && (+ <div className="space-y-4">+ <label htmlFor="music-designer-description" className="block">+ <span className={LABEL_CLASS}>Music description</span>+ <textarea+ id="music-designer-description"+ value={description}+ onChange={(event) => setDescription(event.target.value)}+ rows={8}+ maxLength={8000}+ placeholder="Warm instrumental soul, relaxed pocket, Rhodes piano, 92 BPM…"+ className={FIELD_CLASS}+ />+ </label>+ <p className="text-xs text-gray-500">This is what conditions the render — edit it freely.</p>+ <div className="flex flex-wrap gap-2">+ <button+ type="button"+ onClick={() => runDescribe({ advance: false })}+ disabled={busy || !concept.trim()}+ className={GHOST_BTN}+ >+ {describing ? <Loader2 className="h-4 w-4 animate-spin" /> : <Wand2 className="h-4 w-4" />}+ <span>{describing ? 'Regenerating…' : 'Regenerate'}</span>+ </button>+ <button+ type="button"+ onClick={() => goTo('lyrics')}+ disabled={busy || !description.trim()}+ className={PRIMARY_BTN}+ >+ Next: lyrics+ </button>+ </div>+ </div>+ )}++ {step === 'lyrics' && (+ <div className="space-y-4">+ <p className="text-sm text-gray-400">+ Lyrics are optional — leave them blank for an instrumental.+ </p>+ <label htmlFor="music-designer-lyrics-guidance" className="block">+ <span className={LABEL_CLASS}>Lyric guidance (optional)</span>+ <input+ id="music-designer-lyrics-guidance"+ value={lyricsGuidance}+ onChange={(event) => setLyricsGuidance(event.target.value)}+ maxLength={4000}+ placeholder="Make the chorus about leaving a city at dawn…"+ className={FIELD_CLASS}+ />+ </label>+ <div className="rounded border border-port-border bg-port-bg/60 p-3">+ <span className={LABEL_CLASS}>AI provider</span>+ {providerPicker}+ </div>+ <div className="flex flex-wrap gap-2">+ <button+ type="button"+ onClick={runLyrics}+ disabled={busy || !description.trim()}+ className={PRIMARY_BTN}+ >+ {writing ? <Loader2 className="h-4 w-4 animate-spin" /> : <Sparkles className="h-4 w-4" />}+ <span>{writing ? 'Writing lyrics…' : (lyrics.trim() ? 'Rewrite lyrics' : 'Generate lyrics')}</span>+ </button>+ {lyrics.trim() && (+ <button type="button" onClick={() => setLyrics('')} disabled={busy} className={GHOST_BTN}>+ Clear lyrics+ </button>+ )}+ </div>+ <label htmlFor="music-designer-lyrics" className="block">+ <span className={LABEL_CLASS}>Lyrics</span>+ <textarea+ id="music-designer-lyrics"+ value={lyrics}+ onChange={(event) => setLyrics(event.target.value)}+ rows={10}+ maxLength={20000}+ placeholder={'[verse]\n…\n[chorus]\n…'}+ className={`${FIELD_CLASS} font-mono`}+ />+ </label>+ <button type="button" onClick={() => goTo('render')} disabled={busy} className={PRIMARY_BTN}>+ {lyrics.trim() ? 'Next: render' : 'Skip — make it instrumental'}+ </button>+ </div>+ )}++ {step === 'render' && (+ <div className="space-y-4">+ <label htmlFor="music-designer-title" className="block">+ <span className={LABEL_CLASS}>Title (optional)</span>+ <input+ id="music-designer-title"+ value={title}+ onChange={(event) => setTitle(event.target.value)}+ maxLength={200}+ placeholder="Derived from the prompt if left blank"+ className={FIELD_CLASS}+ />+ </label>+ <MusicGenPanel+ title={title}+ prompt={description}+ lyrics={lyrics}+ onGenerated={(track) => navigate(`/music/tracks/${encodeURIComponent(track.id)}`)}+ />+ </div>+ )}+ </section>+ );+}diff --git a/client/src/components/music/MusicDesigner.test.jsx b/client/src/components/music/MusicDesigner.test.jsxnew file mode 100644index 0000000000..e64b59917f--- /dev/null+++ b/client/src/components/music/MusicDesigner.test.jsx@@ -0,0 +1,260 @@+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';+import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/react';+import { MemoryRouter, Routes, Route, useLocation } from 'react-router';+import MusicDesigner from './MusicDesigner';+import * as api from '../../services/api';++vi.mock('../../services/api', () => ({+ describeMusic: vi.fn(),+ generateLyrics: vi.fn(),+ getSettings: vi.fn(),+ updateSettings: vi.fn(),+}));++// The render step hosts MusicGenPanel unchanged; stub it to a props readout so+// the wizard's hand-off (prompt = the enriched description, lyrics = possibly+// empty) is directly assertable without the engine-list fetch.+vi.mock('./MusicGenPanel', () => ({+ default: ({ title, prompt, lyrics }) => (+ <div data-testid="gen-panel" data-title={title} data-prompt={prompt} data-lyrics={lyrics} />+ ),+}));++// Stateful stub of useProviderModels: the pin-restore effect calls its setters,+// so they have to actually move the returned selection for the restore path to+// be observable.+const hook = vi.hoisted(() => ({+ providers: [{ id: 'provider-a', name: 'Provider A', models: ['model-a'], defaultModel: 'model-a' }],+ selectedProviderId: 'provider-a',+ selectedModel: 'model-a',+ loading: false,+ setSelectedProviderId: null,+ setSelectedModel: null,+}));+vi.mock('../../hooks/useProviderModels', () => ({+ default: () => ({+ providers: hook.providers,+ selectedProviderId: hook.selectedProviderId,+ selectedModel: hook.selectedModel,+ availableModels: hook.providers.find((p) => p.id === hook.selectedProviderId)?.models || [],+ setSelectedProviderId: hook.setSelectedProviderId,+ setSelectedModel: hook.setSelectedModel,+ loading: hook.loading,+ }),+}));++function LocationDisplay() {+ const location = useLocation();+ return <div data-testid="location">{location.pathname}</div>;+}++const renderAt = (path) => render(+ <MemoryRouter initialEntries={[path]}>+ <Routes>+ <Route path="/music/:tab" element={<><LocationDisplay /><MusicDesigner /></>} />+ <Route path="/music/:tab/:id" element={<><LocationDisplay /><MusicDesigner /></>} />+ <Route path="/music/tracks/:id" element={<LocationDisplay />} />+ </Routes>+ </MemoryRouter>,+);++describe('<MusicDesigner>', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ hook.providers = [{ id: 'provider-a', name: 'Provider A', models: ['model-a'], defaultModel: 'model-a' }];+ hook.selectedProviderId = 'provider-a';+ hook.selectedModel = 'model-a';+ hook.loading = false;+ hook.setSelectedProviderId = vi.fn();+ hook.setSelectedModel = vi.fn();+ api.getSettings.mockResolvedValue({ music: {} });+ api.updateSettings.mockResolvedValue({});+ });++ afterEach(cleanup);++ describe('step routing', () => {+ it('defaults a bare /music/generate to the concept step', async () => {+ renderAt('/music/generate');+ expect(await screen.findByLabelText(/what do you want to hear/i)).toBeInTheDocument();+ });++ it('renders the step named in the URL', async () => {+ renderAt('/music/generate/lyrics');+ expect(await screen.findByLabelText('Lyrics')).toBeInTheDocument();+ expect(screen.queryByLabelText(/what do you want to hear/i)).toBeNull();+ });++ it('redirects an unknown step to the first step instead of an empty shell', async () => {+ renderAt('/music/generate/bogus');+ await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/concept'));+ expect(screen.getByLabelText(/what do you want to hear/i)).toBeInTheDocument();+ });++ it('moves the URL when a step in the step bar is clicked', async () => {+ renderAt('/music/generate/concept');+ await screen.findByLabelText(/what do you want to hear/i);+ fireEvent.click(screen.getByRole('tab', { name: /render/i }));+ expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/render');+ });+ });++ describe('the describe step', () => {+ it('fires no LLM call on mount — both provider calls need an explicit press', async () => {+ renderAt('/music/generate/concept');+ await screen.findByLabelText(/what do you want to hear/i);+ await waitFor(() => expect(api.getSettings).toHaveBeenCalled());+ expect(api.describeMusic).not.toHaveBeenCalled();+ expect(api.generateLyrics).not.toHaveBeenCalled();+ });++ it('sends the concept, guidance and picker selection, then advances with the result editable', async () => {+ api.describeMusic.mockResolvedValue({ description: 'Lush pads over a broken beat.', llm: { provider: 'provider-a', model: 'model-a' } });+ renderAt('/music/generate/concept');++ fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });+ fireEvent.change(screen.getByLabelText(/extra guidance/i), { target: { value: 'under 100 BPM' } });+ fireEvent.click(screen.getByRole('button', { name: /describe it/i }));++ await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/description'));+ expect(api.describeMusic).toHaveBeenCalledWith({+ concept: 'a rainy downtempo loop',+ guidance: 'under 100 BPM',+ template: undefined,+ providerId: 'provider-a',+ model: 'model-a',+ effort: undefined,+ }, { silent: true });++ const box = screen.getByLabelText(/music description/i);+ expect(box).toHaveValue('Lush pads over a broken beat.');+ fireEvent.change(box, { target: { value: 'My own words.' } });+ expect(box).toHaveValue('My own words.');+ });++ it('persists the provider pin after a successful describe', async () => {+ api.describeMusic.mockResolvedValue({ description: 'Lush pads.', llm: {} });+ renderAt('/music/generate/concept');+ fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'x' } });+ fireEvent.click(screen.getByRole('button', { name: /describe it/i }));++ await waitFor(() => expect(api.updateSettings).toHaveBeenCalledWith(+ { music: { designer: { providerId: 'provider-a', model: 'model-a', effort: '' } } },+ { silent: true },+ ));+ });++ it('keeps the user on the concept step when the call fails', async () => {+ api.describeMusic.mockRejectedValue(new Error('no provider'));+ renderAt('/music/generate/concept');+ fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'x' } });+ fireEvent.click(screen.getByRole('button', { name: /describe it/i }));++ await waitFor(() => expect(api.describeMusic).toHaveBeenCalled());+ expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/concept');+ });+ });++ describe('the lyrics step', () => {+ it('generates lyrics from the description without leaving the step', async () => {+ api.describeMusic.mockResolvedValue({ description: 'Lush pads over a broken beat.', llm: {} });+ api.generateLyrics.mockResolvedValue({ lyrics: '[verse]\nrain on the window', llm: {} });+ renderAt('/music/generate/concept');++ fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });+ fireEvent.click(screen.getByRole('button', { name: /describe it/i }));+ await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/description'));+ fireEvent.click(screen.getByRole('button', { name: /next: lyrics/i }));++ fireEvent.change(screen.getByLabelText(/lyric guidance/i), { target: { value: 'about leaving at dawn' } });+ fireEvent.click(screen.getByRole('button', { name: /generate lyrics/i }));++ await waitFor(() => expect(screen.getByLabelText('Lyrics')).toHaveValue('[verse]\nrain on the window'));+ expect(api.generateLyrics).toHaveBeenCalledWith({+ description: 'Lush pads over a broken beat.',+ guidance: 'about leaving at dawn',+ template: undefined,+ providerId: 'provider-a',+ model: 'model-a',+ effort: undefined,+ }, { silent: true });+ expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/lyrics');+ });++ it('is skippable — an instrumental reaches the generator with empty lyrics', async () => {+ api.describeMusic.mockResolvedValue({ description: 'Lush pads over a broken beat.', llm: {} });+ renderAt('/music/generate/concept');++ fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });+ fireEvent.click(screen.getByRole('button', { name: /describe it/i }));+ await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/description'));+ fireEvent.click(screen.getByRole('button', { name: /next: lyrics/i }));++ fireEvent.click(screen.getByRole('button', { name: /skip — make it instrumental/i }));++ const panel = await screen.findByTestId('gen-panel');+ expect(panel).toHaveAttribute('data-prompt', 'Lush pads over a broken beat.');+ expect(panel).toHaveAttribute('data-lyrics', '');+ expect(api.generateLyrics).not.toHaveBeenCalled();+ });+ });++ describe('the saved provider pin', () => {+ it('restores a pin that still matches a live provider', async () => {+ hook.providers = [+ { id: 'provider-a', name: 'Provider A', models: ['model-a'], defaultModel: 'model-a' },+ { id: 'provider-b', name: 'Provider B', models: ['model-b'], defaultModel: 'model-b' },+ ];+ api.getSettings.mockResolvedValue({ music: { designer: { providerId: 'provider-b', model: 'model-b' } } });+ renderAt('/music/generate/concept');++ await waitFor(() => expect(hook.setSelectedProviderId).toHaveBeenCalledWith('provider-b'));+ expect(hook.setSelectedModel).toHaveBeenCalledWith('model-b');+ });++ it('degrades to the hook default for a stale provider id', async () => {+ api.getSettings.mockResolvedValue({ music: { designer: { providerId: 'provider-gone', model: 'model-gone' } } });+ renderAt('/music/generate/concept');++ await waitFor(() => expect(api.getSettings).toHaveBeenCalled());+ await waitFor(() => expect(screen.getByLabelText(/what do you want to hear/i)).toBeInTheDocument());+ expect(hook.setSelectedProviderId).not.toHaveBeenCalled();+ expect(hook.setSelectedModel).not.toHaveBeenCalled();+ });++ it('skips a stale MODEL on a provider that still exists', async () => {+ api.getSettings.mockResolvedValue({ music: { designer: { providerId: 'provider-a', model: 'model-removed' } } });+ renderAt('/music/generate/concept');++ await waitFor(() => expect(hook.setSelectedProviderId).toHaveBeenCalledWith('provider-a'));+ expect(hook.setSelectedModel).not.toHaveBeenCalled();+ });+ });++ describe('meta-prompt overrides', () => {+ it('sends a saved override as the template, and stops sending it once reset', async () => {+ api.getSettings.mockResolvedValue({ music: { designer: { describeTemplate: 'Be terse.' } } });+ api.describeMusic.mockResolvedValue({ description: 'Terse.', llm: {} });+ renderAt('/music/generate/concept');++ fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'x' } });+ fireEvent.click(screen.getByRole('button', { name: /advanced — meta-prompts/i }));+ await waitFor(() => expect(screen.getByLabelText(/description instruction/i)).toHaveValue('Be terse.'));++ fireEvent.click(screen.getByRole('button', { name: /describe it/i }));+ await waitFor(() => expect(api.describeMusic).toHaveBeenCalledWith(+ expect.objectContaining({ template: 'Be terse.' }),+ { silent: true },+ ));++ // Reset clears the override so the server falls back to the shipped default.+ fireEvent.click(screen.getByRole('tab', { name: /concept/i }));+ fireEvent.click(screen.getAllByRole('button', { name: /reset to default/i })[0]);+ fireEvent.click(screen.getByRole('button', { name: /describe it/i }));+ await waitFor(() => expect(api.describeMusic).toHaveBeenLastCalledWith(+ expect.objectContaining({ template: undefined }),+ { silent: true },+ ));+ });+ });+});diff --git a/client/src/pages/Music.jsx b/client/src/pages/Music.jsxindex edcc869a77..a15dc6654e 100644--- a/client/src/pages/Music.jsx+++ b/client/src/pages/Music.jsx@@ -15,7 +15,7 @@ import { Music as MusicIcon, Mic, Disc3, AudioLines, Wand2 } from 'lucide-react'import ArtistsManager from '../components/music/ArtistsManager';import AlbumsManager from '../components/music/AlbumsManager';import TracksManager from '../components/music/TracksManager';-import QuickMusicGenerator from '../components/music/QuickMusicGenerator';+import MusicDesigner from '../components/music/MusicDesigner';import TabPills from '../components/ui/TabPills';const TABS = [@@ -52,7 +52,7 @@ export default function Music() {className="mb-6"/>- {active === 'generate' && <QuickMusicGenerator />}+ {active === 'generate' && <MusicDesigner />}{active === 'artists' && <ArtistsManager />}{active === 'albums' && <AlbumsManager />}{active === 'tracks' && <TracksManager />}diff --git a/client/src/pages/Music.test.jsx b/client/src/pages/Music.test.jsxindex f53ea8538a..6d1f3e4e57 100644--- a/client/src/pages/Music.test.jsx+++ b/client/src/pages/Music.test.jsx@@ -9,7 +9,7 @@ import { afterEach } from 'vitest';vi.mock('../components/music/ArtistsManager', () => ({ default: () => <div data-testid="artists-manager" /> }));vi.mock('../components/music/AlbumsManager', () => ({ default: () => <div data-testid="albums-manager" /> }));vi.mock('../components/music/TracksManager', () => ({ default: () => <div data-testid="tracks-manager" /> }));-vi.mock('../components/music/QuickMusicGenerator', () => ({ default: () => <div data-testid="quick-generator" /> }));+vi.mock('../components/music/MusicDesigner', () => ({ default: () => <div data-testid="music-designer" /> }));import Music from './Music.jsx';@@ -43,16 +43,16 @@ describe('<Music>', () => {expect(screen.queryByTestId('tracks-manager')).toBeNull();});- it('defaults bare /music to quick generation', () => {+ it('defaults bare /music to the stepped designer', () => {renderAt('/music');- expect(screen.getByTestId('quick-generator')).toBeInTheDocument();+ expect(screen.getByTestId('music-designer')).toBeInTheDocument();expect(screen.queryByTestId('albums-manager')).toBeNull();});it('redirects an unknown tab param to /music/artists', () => {renderAt('/music/bogus');expect(screen.getByTestId('location')).toHaveTextContent('/music/generate');- expect(screen.getByTestId('quick-generator')).toBeInTheDocument();+ expect(screen.getByTestId('music-designer')).toBeInTheDocument();});it('clicking a TabPill navigates the URL to the matching tab route', () => {diff --git a/client/src/services/README.md b/client/src/services/README.mdindex dcf89a101f..d3230b2ae4 100644--- a/client/src/services/README.md+++ b/client/src/services/README.md@@ -112,7 +112,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire| `apiAlbums.js` | Music albums (title, artist FK + name, description, genre, release year, cover art, ordered track ids). || `apiTracks.js` | Music tracks (title, album/artist FKs, lyrics, prompt, gen metadata, audio-library pointer) + shared music-library list + audio upload/attach/clear. || `apiVideoDownload.js` | Dev Tools video downloader (#1946): start/cancel a YouTube/x.com full-video download via yt-dlp (SSE progress), list + delete downloaded clips. |-| `apiMusic.js` | On-device music generation (MusicGen / AudioLDM2 / ACE-Step): list engines (+ readiness) and generate a track from a prompt/lyrics. |+| `apiMusic.js` | On-device music generation (MusicGen / AudioLDM2 / ACE-Step): list engines (+ readiness), the stepped designer's AI describe/lyrics steps, and generate a track from a prompt/lyrics. || `apiWritersRoom.js` | Writers Room (folders + works + drafts, live continuation + render-preview reservation, scene-image attach). || `apiSharing.js` | Share buckets + federation sync. || `apiRounds.js` | Rounds workbench CRUD (a cappella round writing + arranging voice layers + learning tracking). |diff --git a/client/src/services/apiMusic.js b/client/src/services/apiMusic.jsindex b105e0f6fd..986dc503cd 100644--- a/client/src/services/apiMusic.js+++ b/client/src/services/apiMusic.js@@ -19,6 +19,29 @@ export const generateMusic = (body, requestOptions = {}) => request('/music/gene...requestOptions,});+// ---- Stepped music designer (#4305) ----+// Both fire one LLM call each and are only ever invoked from an explicit button+// press in the designer wizard. Callers own their loading/error UI, so pass+// `{ silent: true }`.++// Expand a short reference/vibe into a rich musical description.+// body: { concept, guidance?, template?, providerId?, model?, effort? }+// → { description, llm: { provider, model } }+export const describeMusic = (body, requestOptions = {}) => request('/music/describe', {+ method: 'POST',+ body: JSON.stringify(body),+ ...requestOptions,+});++// Write original lyrics from an enriched description (+ optional guidance).+// body: { description, guidance?, template?, providerId?, model?, effort? }+// → { lyrics, llm: { provider, model } }+export const generateLyrics = (body, requestOptions = {}) => request('/music/lyrics', {+ method: 'POST',+ body: JSON.stringify(body),+ ...requestOptions,+});+// The merged shipped+user model list for one engine → { models }.export const listEngineModels = (engine, options = {}) => request(`/music/models/${encodeURIComponent(engine)}`, options);