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

feat: persist music designer drafts

[._.]/ Adam Eivyf98ff8f50844
diff --git a/.changelog/next/changed-agent-9753ce56.md b/.changelog/next/changed-agent-9753ce56.md
new file mode 100644
index 0000000000..f99e4e7d1f
--- /dev/null
+++ b/.changelog/next/changed-agent-9753ce56.md
@@ -0,0 +1 @@
+- Music designer drafts now persist immediately and include manual lyrics structure guidance.
diff --git a/client/src/components/music/MusicDesigner.jsx b/client/src/components/music/MusicDesigner.jsx
index a317e06134..bc580397f3 100644
--- a/client/src/components/music/MusicDesigner.jsx
+++ b/client/src/components/music/MusicDesigner.jsx
@@ -17,14 +17,14 @@
* 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`.
+ * existing `music/:tab/:id` route (`/music/generate/description`), while the
+ * persisted draft track rides in `?trackId=…`, so the wizard is deep-linkable
+ * and reload-safe. Provider/model/effort pins and meta-prompt overrides
+ * persist to `settings.music.designer` too.
*/
import { useEffect, useRef, useState } from 'react';
-import { Navigate, useNavigate, useParams } from 'react-router';
+import { Navigate, useNavigate, useParams, useSearchParams } from 'react-router';
import {
AudioLines, ChevronDown, ChevronUp, FileText, Lightbulb, Loader2, Mic2, Sparkles, Wand2,
} from 'lucide-react';
@@ -34,7 +34,9 @@ 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';
+import {
+ createTrack, describeMusic, generateLyrics, getSettings, getTrack, updateSettings, updateTrack,
+} from '../../services/api';
const STEPS = [
{ id: 'concept', label: 'Concept', icon: Lightbulb },
@@ -44,6 +46,8 @@ const STEPS = [
];
const STEP_IDS = STEPS.map((s) => s.id);
const FIRST_STEP = STEP_IDS[0];
+const DRAFT_TITLE = 'Untitled music draft';
+const ACTIVE_DRAFT_KEY = 'portos.musicDesigner.activeDraft';
// Display-only mirrors of the shipped meta-prompts in
// `server/services/musicDesigner.js`. They are rendered as placeholder text so
@@ -61,7 +65,10 @@ const GHOST_BTN = 'inline-flex items-center justify-center gap-1.5 rounded-lg bo
export default function MusicDesigner() {
const navigate = useNavigate();
const { id } = useParams();
+ const [searchParams] = useSearchParams();
const mountedRef = useMounted();
+ const requestedTrackId = searchParams.get('trackId') || '';
+ const storedDraftId = requestedTrackId || window.localStorage.getItem(ACTIVE_DRAFT_KEY) || '';
// Wizard text — lifted here so MusicGenPanel (which never writes back to
// prompt/lyrics) can be re-hosted under step 4 unchanged, and so edits
@@ -72,6 +79,9 @@ export default function MusicDesigner() {
const [lyricsGuidance, setLyricsGuidance] = useState('');
const [lyrics, setLyrics] = useState('');
const [title, setTitle] = useState('');
+ const [trackId, setTrackId] = useState('');
+ const [draftLoading, setDraftLoading] = useState(true);
+ const draftSaveTailRef = useRef(Promise.resolve());
// Meta-prompt overrides. Blank = "use the shipped default" (resolved
// server-side), which is exactly what "Reset to default" restores.
@@ -88,6 +98,55 @@ export default function MusicDesigner() {
const [savedPin, setSavedPin] = useState(null);
const musicSettingsRef = useRef({});
+ const stepFromUrl = STEP_IDS.includes(id) ? id : FIRST_STEP;
+
+ const hydrateDraft = (track) => {
+ setTrackId(track.id);
+ if (track.title === DRAFT_TITLE) window.localStorage.setItem(ACTIVE_DRAFT_KEY, track.id);
+ else window.localStorage.removeItem(ACTIVE_DRAFT_KEY);
+ setConcept(track.concept || '');
+ setDescription(track.prompt || '');
+ setLyrics(track.lyrics || '');
+ setTitle(track.title === DRAFT_TITLE ? '' : (track.title || ''));
+ };
+
+ // Create the persisted record before the first designer action. Its id is
+ // carried in the URL so step navigation and browser-history returns resolve
+ // the same draft instead of starting a second in-memory wizard.
+ useEffect(() => {
+ let cancelled = false;
+ const createDraft = async () => {
+ const created = await createTrack({ title: DRAFT_TITLE }, { silent: true }).catch((err) => {
+ if (mountedRef.current) toast.error(err?.message || 'Could not create a music draft');
+ return null;
+ });
+ if (cancelled || !mountedRef.current) return;
+ if (created) {
+ hydrateDraft(created);
+ navigate(`/music/generate/${stepFromUrl}?trackId=${encodeURIComponent(created.id)}`, { replace: true });
+ }
+ setDraftLoading(false);
+ };
+
+ if (storedDraftId) {
+ getTrack(storedDraftId, { silent: true }).then((track) => {
+ if (cancelled || !mountedRef.current) return;
+ if (track) {
+ hydrateDraft(track);
+ if (!requestedTrackId) {
+ navigate(`/music/generate/${stepFromUrl}?trackId=${encodeURIComponent(track.id)}`, { replace: true });
+ }
+ setDraftLoading(false);
+ } else {
+ createDraft();
+ }
+ }).catch(() => createDraft());
+ } else {
+ createDraft();
+ }
+ return () => { cancelled = true; };
+ }, []);
+
const {
providers, selectedProviderId, selectedModel, availableModels,
setSelectedProviderId, setSelectedModel, loading: providersLoading,
@@ -135,10 +194,26 @@ export default function MusicDesigner() {
updateSettings({ music: next }, { silent: true }).catch(() => {});
};
- const goTo = (stepId) => navigate(`/music/generate/${stepId}`);
+ const saveDraft = (patch) => {
+ if (!trackId || !patch || Object.keys(patch).length === 0) return Promise.resolve(null);
+ draftSaveTailRef.current = draftSaveTailRef.current
+ .catch(() => null)
+ .then(() => updateTrack(trackId, patch, { silent: true }))
+ .catch((err) => {
+ if (mountedRef.current) toast.error(err?.message || 'Could not save the music draft');
+ return null;
+ });
+ return draftSaveTailRef.current;
+ };
+
+ const goTo = (stepId) => {
+ const suffix = trackId ? `?trackId=${encodeURIComponent(trackId)}` : '';
+ navigate(`/music/generate/${stepId}${suffix}`);
+ };
const runDescribe = async ({ advance }) => {
if (!concept.trim()) { toast.error('Describe the vibe (or name a reference) first'); return; }
+ saveDraft({ concept: concept.trim() });
setDescribing(true);
const res = await describeMusic({
concept: concept.trim(),
@@ -148,9 +223,10 @@ export default function MusicDesigner() {
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 (mountedRef.current) setDescribing(false);
if (!res?.description) return;
+ saveDraft({ concept: concept.trim(), prompt: res.description });
+ if (!mountedRef.current) return;
setDescription(res.description);
persistDesignerPrefs({ providerId: selectedProviderId || '', model: selectedModel || '', effort: effort || '' });
if (advance) goTo('description');
@@ -158,6 +234,7 @@ export default function MusicDesigner() {
const runLyrics = async () => {
if (!description.trim()) { toast.error('Write the musical description first'); return; }
+ saveDraft({ prompt: description.trim() });
setWriting(true);
const res = await generateLyrics({
description: description.trim(),
@@ -167,14 +244,16 @@ export default function MusicDesigner() {
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 (mountedRef.current) setWriting(false);
if (!res?.lyrics) return;
+ saveDraft({ lyrics: res.lyrics });
+ if (!mountedRef.current) return;
setLyrics(res.lyrics);
persistDesignerPrefs({ providerId: selectedProviderId || '', model: selectedModel || '', effort: effort || '' });
};
const busy = describing || writing;
+ const draftReady = !!trackId && !draftLoading;
const providerPicker = (
<ProviderModelSelector
@@ -186,7 +265,7 @@ export default function MusicDesigner() {
onModelChange={setSelectedModel}
effort={effort}
onEffortChange={setEffort}
- disabled={busy || providersLoading}
+ disabled={busy || providersLoading || !draftReady}
layout="stacked"
/>
);
@@ -223,6 +302,8 @@ export default function MusicDesigner() {
id="music-designer-concept"
value={concept}
onChange={(event) => setConcept(event.target.value)}
+ onBlur={() => saveDraft({ concept: concept.trim() })}
+ disabled={draftLoading}
rows={3}
maxLength={8000}
placeholder="A cross between a rain-soaked downtempo instrumental and a late-night synth ballad…"
@@ -236,6 +317,7 @@ export default function MusicDesigner() {
id="music-designer-concept-guidance"
value={conceptGuidance}
onChange={(event) => setConceptGuidance(event.target.value)}
+ disabled={draftLoading}
maxLength={4000}
placeholder="Keep it under 100 BPM, no vocals in the intro…"
className={FIELD_CLASS}
@@ -316,7 +398,7 @@ export default function MusicDesigner() {
<button
type="button"
onClick={() => runDescribe({ advance: true })}
- disabled={busy || !concept.trim()}
+ disabled={busy || !draftReady || !concept.trim()}
className={PRIMARY_BTN}
>
{describing ? <Loader2 className="h-4 w-4 animate-spin" /> : <Sparkles className="h-4 w-4" />}
@@ -339,6 +421,8 @@ export default function MusicDesigner() {
id="music-designer-description"
value={description}
onChange={(event) => setDescription(event.target.value)}
+ onBlur={() => saveDraft({ prompt: description.trim() })}
+ disabled={draftLoading}
rows={8}
maxLength={8000}
placeholder="Warm instrumental soul, relaxed pocket, Rhodes piano, 92 BPM…"
@@ -350,7 +434,7 @@ export default function MusicDesigner() {
<button
type="button"
onClick={() => runDescribe({ advance: false })}
- disabled={busy || !concept.trim()}
+ disabled={busy || !draftReady || !concept.trim()}
className={GHOST_BTN}
>
{describing ? <Loader2 className="h-4 w-4 animate-spin" /> : <Wand2 className="h-4 w-4" />}
@@ -359,7 +443,7 @@ export default function MusicDesigner() {
<button
type="button"
onClick={() => goTo('lyrics')}
- disabled={busy || !description.trim()}
+ disabled={busy || !draftReady || !description.trim()}
className={PRIMARY_BTN}
>
Next: lyrics
@@ -379,6 +463,7 @@ export default function MusicDesigner() {
id="music-designer-lyrics-guidance"
value={lyricsGuidance}
onChange={(event) => setLyricsGuidance(event.target.value)}
+ disabled={draftLoading}
maxLength={4000}
placeholder="Make the chorus about leaving a city at dawn…"
className={FIELD_CLASS}
@@ -392,7 +477,7 @@ export default function MusicDesigner() {
<button
type="button"
onClick={runLyrics}
- disabled={busy || !description.trim()}
+ disabled={busy || !draftReady || !description.trim()}
className={PRIMARY_BTN}
>
{writing ? <Loader2 className="h-4 w-4 animate-spin" /> : <Sparkles className="h-4 w-4" />}
@@ -404,19 +489,31 @@ export default function MusicDesigner() {
</button>
)}
</div>
+ <div className="rounded border border-port-border bg-port-bg/60 p-3 text-xs text-gray-400">
+ <p className="mb-2 font-medium text-gray-300">Manual composition structure</p>
+ <p className="mb-2">Put one section tag on its own line, then its singable lines. A useful arc is: intro → verse → pre-chorus → chorus → verse 2 → chorus → bridge → final chorus → outro.</p>
+ <ul className="mb-3 list-disc space-y-1 pl-4">
+ <li>Use 4–8 short lines for a verse and 2–4 lines for a pre-chorus or bridge.</li>
+ <li>Give the chorus a repeated hook; repeat the tag when the chorus returns.</li>
+ <li>Leave a blank line between sections and keep tags lowercase, such as <code className="text-gray-300">[verse]</code> and <code className="text-gray-300">[chorus]</code>.</li>
+ </ul>
+ <pre className="overflow-x-auto rounded bg-port-bg p-2 font-mono text-[11px] text-gray-300">{`[verse]\nShort image, short line\nA second line to sing\n\n[pre-chorus]\nBuild the thought\nTurn toward the hook\n\n[chorus]\nA repeatable hook\nA repeatable hook`}</pre>
+ </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)}
+ onBlur={() => saveDraft({ lyrics: lyrics.trim() })}
+ disabled={draftLoading}
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}>
+ <button type="button" onClick={() => { saveDraft({ prompt: description.trim(), lyrics: lyrics.trim() }); goTo('render'); }} disabled={busy || !draftReady} className={PRIMARY_BTN}>
{lyrics.trim() ? 'Next: render' : 'Skip — make it instrumental'}
</button>
</div>
@@ -430,12 +527,20 @@ export default function MusicDesigner() {
id="music-designer-title"
value={title}
onChange={(event) => setTitle(event.target.value)}
+ onBlur={() => {
+ const nextTitle = title.trim() || DRAFT_TITLE;
+ if (title.trim()) window.localStorage.removeItem(ACTIVE_DRAFT_KEY);
+ else window.localStorage.setItem(ACTIVE_DRAFT_KEY, trackId);
+ saveDraft({ title: nextTitle });
+ }}
+ disabled={!draftReady}
maxLength={200}
placeholder="Derived from the prompt if left blank"
className={FIELD_CLASS}
/>
</label>
<MusicGenPanel
+ track={trackId ? { id: trackId } : undefined}
title={title}
prompt={description}
lyrics={lyrics}
diff --git a/client/src/components/music/MusicDesigner.test.jsx b/client/src/components/music/MusicDesigner.test.jsx
index e64b59917f..05741a37e3 100644
--- a/client/src/components/music/MusicDesigner.test.jsx
+++ b/client/src/components/music/MusicDesigner.test.jsx
@@ -5,10 +5,13 @@ import MusicDesigner from './MusicDesigner';
import * as api from '../../services/api';
vi.mock('../../services/api', () => ({
+ createTrack: vi.fn(),
describeMusic: vi.fn(),
generateLyrics: vi.fn(),
getSettings: vi.fn(),
+ getTrack: vi.fn(),
updateSettings: vi.fn(),
+ updateTrack: vi.fn(),
}));
// The render step hosts MusicGenPanel unchanged; stub it to a props readout so
@@ -61,6 +64,7 @@ const renderAt = (path) => render(
describe('<MusicDesigner>', () => {
beforeEach(() => {
vi.clearAllMocks();
+ window.localStorage.clear();
hook.providers = [{ id: 'provider-a', name: 'Provider A', models: ['model-a'], defaultModel: 'model-a' }];
hook.selectedProviderId = 'provider-a';
hook.selectedModel = 'model-a';
@@ -68,7 +72,10 @@ describe('<MusicDesigner>', () => {
hook.setSelectedProviderId = vi.fn();
hook.setSelectedModel = vi.fn();
api.getSettings.mockResolvedValue({ music: {} });
+ api.createTrack.mockResolvedValue({ id: 'track-draft', title: 'Untitled music draft', concept: '', prompt: '', lyrics: '' });
+ api.getTrack.mockResolvedValue({ id: 'track-draft', title: 'Untitled music draft', concept: '', prompt: '', lyrics: '' });
api.updateSettings.mockResolvedValue({});
+ api.updateTrack.mockResolvedValue({ id: 'track-draft', title: 'Untitled music draft' });
});
afterEach(cleanup);
@@ -97,6 +104,35 @@ describe('<MusicDesigner>', () => {
fireEvent.click(screen.getByRole('tab', { name: /render/i }));
expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/render');
});
+
+ it('creates a persisted draft immediately and uses its id for the wizard', async () => {
+ renderAt('/music/generate/concept');
+
+ await screen.findByLabelText(/what do you want to hear/i);
+ expect(api.createTrack).toHaveBeenCalledWith({ title: 'Untitled music draft' }, { silent: true });
+ });
+
+ it('reopens the active unnamed draft after leaving the Music section', async () => {
+ renderAt('/music/generate/concept');
+ await screen.findByLabelText(/what do you want to hear/i);
+ cleanup();
+
+ renderAt('/music/generate/lyrics');
+ await screen.findByLabelText('Lyrics');
+ expect(api.getTrack).toHaveBeenCalledWith('track-draft', { silent: true });
+ });
+
+ it('hydrates a saved draft when returning through its track id', async () => {
+ api.getTrack.mockResolvedValue({
+ id: 'track-saved', title: 'Untitled music draft', concept: 'A dusk-time pulse',
+ prompt: 'Warm synths and a patient beat.', lyrics: '[verse]\nKeep moving',
+ });
+ renderAt('/music/generate/lyrics?trackId=track-saved');
+
+ expect(await screen.findByLabelText('Lyrics')).toHaveValue('[verse]\nKeep moving');
+ expect(screen.getByLabelText('Lyrics')).toHaveValue('[verse]\nKeep moving');
+ expect(api.getTrack).toHaveBeenCalledWith('track-saved', { silent: true });
+ });
});
describe('the describe step', () => {
@@ -130,6 +166,10 @@ describe('<MusicDesigner>', () => {
expect(box).toHaveValue('Lush pads over a broken beat.');
fireEvent.change(box, { target: { value: 'My own words.' } });
expect(box).toHaveValue('My own words.');
+ await waitFor(() => expect(api.updateTrack).toHaveBeenCalledWith(
+ 'track-draft', expect.objectContaining({ concept: 'a rainy downtempo loop', prompt: 'Lush pads over a broken beat.' }),
+ { silent: true },
+ ));
});
it('persists the provider pin after a successful describe', async () => {
@@ -170,6 +210,7 @@ describe('<MusicDesigner>', () => {
fireEvent.click(screen.getByRole('button', { name: /generate lyrics/i }));
await waitFor(() => expect(screen.getByLabelText('Lyrics')).toHaveValue('[verse]\nrain on the window'));
+ expect(screen.getByText(/manual composition structure/i)).toBeInTheDocument();
expect(api.generateLyrics).toHaveBeenCalledWith({
description: 'Lush pads over a broken beat.',
guidance: 'about leaving at dawn',
diff --git a/client/src/services/apiTracks.js b/client/src/services/apiTracks.js
index 387deaff78..2e83d07252 100644
--- a/client/src/services/apiTracks.js
+++ b/client/src/services/apiTracks.js
@@ -112,6 +112,7 @@ export const publishTrackChiptune = (id, body, requestOptions = {}) => request(`
// Mirror server caps in server/services/tracks/logic.js — bump both sides.
export const TRACK_TITLE_MAX = 200;
+export const TRACK_CONCEPT_MAX = 8000;
export const TRACK_LYRICS_MAX = 20000;
export const TRACK_PROMPT_MAX = 8000;
export const TRACK_DURATION_MIN_SEC = 1;
diff --git a/server/lib/conflictJournal.js b/server/lib/conflictJournal.js
index 352ea2c225..fd2470cec1 100644
--- a/server/lib/conflictJournal.js
+++ b/server/lib/conflictJournal.js
@@ -120,7 +120,12 @@ const HASH_FIELDS = Object.freeze({
// — nothing enforces the two staying in lockstep; it's fine for them to
// diverge (a wire-compat bump doesn't always change what the local hash
// cares about, and vice versa).
- track: Object.freeze({ 3: Object.freeze(['chiptuneScore', 'chiptunePrompt']) }),
+ // v4: concept, the user-authored creative brief used by resumable music
+ // designer drafts.
+ track: Object.freeze({
+ 3: Object.freeze(['chiptuneScore', 'chiptunePrompt']),
+ 4: Object.freeze(['concept']),
+ }),
});
// Precomputed field→version lookup per kind, inverted from HASH_FIELDS once
@@ -431,7 +436,7 @@ export const RESTORABLE_FIELDS = Object.freeze({
// #2912, DO participate in the content hash via the version-gated HASH_FIELDS
// mechanism (see above) — a base hash predating the field just compares at
// its own stored version until the next sync re-stamps it.
- track: ['title', 'albumId', 'artistId', 'artist', 'lyrics', 'prompt', 'engine', 'modelId', 'durationSec', 'audioFilename', 'renders', 'chiptuneScore', 'chiptunePrompt'],
+ track: ['title', 'albumId', 'artistId', 'artist', 'concept', 'lyrics', 'prompt', 'engine', 'modelId', 'durationSec', 'audioFilename', 'renders', 'chiptuneScore', 'chiptunePrompt'],
// Issue: the user-authored content the merge can restore. `stages` carries
// the bulk of the work (prose, comic pages, render metadata). Server-owned /
// structural fields are excluded deliberately — `number` is renumber-managed,
diff --git a/server/lib/schemaVersions.js b/server/lib/schemaVersions.js
index a31019e839..c10571a2bc 100644
--- a/server/lib/schemaVersions.js
+++ b/server/lib/schemaVersions.js
@@ -242,7 +242,10 @@ export const PORTOS_SCHEMA_VERSIONS = Object.freeze({
// field was chosen to match this one for a human reading both files; the
// two mechanisms are otherwise independent — HASH_FIELDS gates a purely
// local hash-store concern, not cross-peer wire compatibility.)
- tracks: 3,
+ // tracks v4 = `track.concept` for resumable stepped music-designer drafts.
+ // Older peers must reject the record rather than round-trip it through a
+ // concept-unaware sanitizer and silently erase the saved creative brief.
+ tracks: 4,
// v1 = creative ingredients catalog (Postgres tables: catalog_scraps,
// catalog_ingredients, catalog_ingredient_sources, catalog_ingredient_refs).
// v2 = `catalog_ingredients.search_tsv` expanded to also index the
diff --git a/server/routes/tracks.js b/server/routes/tracks.js
index 0051ce690f..19fb316933 100644
--- a/server/routes/tracks.js
+++ b/server/routes/tracks.js
@@ -49,6 +49,7 @@ const titleField = z.string().trim().min(1).max(tracks.TITLE_MAX);
const albumIdField = z.string().trim().max(tracks.ALBUM_ID_MAX);
const artistIdField = z.string().trim().max(tracks.ARTIST_ID_MAX);
const artistNameField = z.string().trim().max(tracks.ARTIST_NAME_MAX);
+const conceptField = z.string().trim().max(tracks.CONCEPT_MAX);
const lyricsField = z.string().trim().max(tracks.LYRICS_MAX);
const promptField = z.string().trim().max(tracks.PROMPT_MAX);
const engineField = z.string().trim().max(tracks.ENGINE_MAX);
@@ -73,6 +74,7 @@ const createSchema = z.object({
albumId: albumIdField.optional().default(''),
artistId: artistIdField.optional().default(''),
artist: artistNameField.optional().default(''),
+ concept: conceptField.optional().default(''),
lyrics: lyricsField.optional().default(''),
prompt: promptField.optional().default(''),
engine: engineField.optional().default(''),
@@ -86,6 +88,7 @@ const patchSchema = z.object({
albumId: albumIdField.optional(),
artistId: artistIdField.optional(),
artist: artistNameField.optional(),
+ concept: conceptField.optional(),
lyrics: lyricsField.optional(),
prompt: promptField.optional(),
engine: engineField.optional(),
diff --git a/server/routes/tracks.test.js b/server/routes/tracks.test.js
index a086a0a9a8..96f353b313 100644
--- a/server/routes/tracks.test.js
+++ b/server/routes/tracks.test.js
@@ -7,6 +7,7 @@ vi.mock('../services/tracks/index.js', () => ({
ALBUM_ID_MAX: 80,
ARTIST_ID_MAX: 80,
ARTIST_NAME_MAX: 120,
+ CONCEPT_MAX: 8000,
LYRICS_MAX: 20000,
PROMPT_MAX: 8000,
ENGINE_MAX: 60,
diff --git a/server/services/tracks/file.test.js b/server/services/tracks/file.test.js
index c3b2040fd1..438448f086 100644
--- a/server/services/tracks/file.test.js
+++ b/server/services/tracks/file.test.js
@@ -35,7 +35,7 @@ const journalEntries = () => cj.conflictJournalStore().loadAll();
// mergeTracksFromSync actually persists (the fields participate in the
// content hash as of #2912 — see conflictJournal.js HASH_FIELDS).
const track = (id, extra = {}) => ({
- id, title: id, albumId: '', artistId: '', artist: '', lyrics: '', prompt: '',
+ id, title: id, albumId: '', artistId: '', artist: '', concept: '', lyrics: '', prompt: '',
engine: '', modelId: '', durationSec: null, audioFilename: '',
chiptuneScore: null, chiptunePrompt: '',
createdAt: '2026-01-01T00:00:00.000Z', updatedAt: '2026-01-01T00:00:00.000Z',
diff --git a/server/services/tracks/index.js b/server/services/tracks/index.js
index 5a4fe03cf1..4a0229d729 100644
--- a/server/services/tracks/index.js
+++ b/server/services/tracks/index.js
@@ -20,6 +20,7 @@ export {
ALBUM_ID_MAX,
ARTIST_ID_MAX,
ARTIST_NAME_MAX,
+ CONCEPT_MAX,
LYRICS_MAX,
PROMPT_MAX,
ENGINE_MAX,
diff --git a/server/services/tracks/logic.js b/server/services/tracks/logic.js
index 1857844297..c107b710e3 100644
--- a/server/services/tracks/logic.js
+++ b/server/services/tracks/logic.js
@@ -11,6 +11,7 @@
* - albumId — FK to the owning album (`album-…`), or '' for a single
* - artistId — FK to the performing artist (`artist-…`), or '' for none
* - artist — denormalized artist name (renders before the artist syncs)
+ * - concept — short creative brief captured by the stepped music designer
* - lyrics — full lyrics (also the conditioning text for lyric-aware
* generators like Ace-Step)
* - prompt — the text/style prompt used (or to use) for generation
@@ -45,6 +46,7 @@ export const TITLE_MAX = 200;
export const ALBUM_ID_MAX = 80;
export const ARTIST_ID_MAX = 80;
export const ARTIST_NAME_MAX = 120;
+export const CONCEPT_MAX = 8000;
export const LYRICS_MAX = 20000;
export const PROMPT_MAX = 8000;
export const ENGINE_MAX = 60;
@@ -165,6 +167,7 @@ export function sanitizeTrack(raw) {
albumId: trimTo(raw.albumId, ALBUM_ID_MAX),
artistId: trimTo(raw.artistId, ARTIST_ID_MAX),
artist: trimTo(raw.artist, ARTIST_NAME_MAX),
+ concept: trimTo(raw.concept, CONCEPT_MAX),
lyrics,
prompt,
engine,
@@ -205,6 +208,7 @@ export function buildTrackRecord(input, { id, now }) {
albumId: input.albumId || '',
artistId: input.artistId || '',
artist: input.artist || '',
+ concept: input.concept || '',
lyrics: input.lyrics || '',
prompt: input.prompt || '',
engine: input.engine || '',
@@ -273,7 +277,7 @@ export function deleteRenderPatch(current, renderId) {
// server-managed (generate/upload/select/delete-render routes set it); the
// generic create/patch route schemas omit it so a client can't inject history.
const PATCHABLE = [
- 'title', 'albumId', 'artistId', 'artist', 'lyrics', 'prompt', 'engine', 'modelId', 'durationSec', 'audioFilename', 'renders',
+ 'title', 'albumId', 'artistId', 'artist', 'concept', 'lyrics', 'prompt', 'engine', 'modelId', 'durationSec', 'audioFilename', 'renders',
'chiptuneScore', 'chiptunePrompt',
];
@@ -296,6 +300,7 @@ export function mergeTrackRecord(local, remoteRaw) {
// covers the accepted sender-behind direction.)
if (remoteWins && next === remote) {
const carry = {};
+ if (!('concept' in remoteRaw) && local.concept) carry.concept = local.concept;
if (!('chiptuneScore' in remoteRaw) && local.chiptuneScore) carry.chiptuneScore = local.chiptuneScore;
if (!('chiptunePrompt' in remoteRaw) && local.chiptunePrompt) carry.chiptunePrompt = local.chiptunePrompt;
if (Object.keys(carry).length) next = { ...remote, ...carry };
diff --git a/server/services/tracks/logic.test.js b/server/services/tracks/logic.test.js
index fd823f2a99..8c4d511d90 100644
--- a/server/services/tracks/logic.test.js
+++ b/server/services/tracks/logic.test.js
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
import {
sanitizeTrack, buildTrackRecord, applyTrackPatch, mergeTrackRecord, trackAudioFilename,
sanitizeRender, makeRender, selectRenderPatch, deleteRenderPatch,
- TITLE_MAX, LYRICS_MAX, DURATION_MIN_SEC, DURATION_MAX_SEC, RENDERS_MAX,
+ TITLE_MAX, CONCEPT_MAX, LYRICS_MAX, DURATION_MIN_SEC, DURATION_MAX_SEC, RENDERS_MAX,
} from './logic.js';
describe('tracks logic', () => {
@@ -21,6 +21,7 @@ describe('tracks logic', () => {
albumId: ' album-9 ',
artistId: ' artist-9 ',
artist: ' Nova ',
+ concept: ` ${'c'.repeat(CONCEPT_MAX + 10)} `,
lyrics: ` ${'l'.repeat(LYRICS_MAX + 10)} `,
prompt: ' warm folk ',
engine: ' acestep ',
@@ -32,6 +33,7 @@ describe('tracks logic', () => {
expect(t.albumId).toBe('album-9');
expect(t.artistId).toBe('artist-9');
expect(t.artist).toBe('Nova');
+ expect(t.concept.length).toBe(CONCEPT_MAX);
expect(t.lyrics.length).toBe(LYRICS_MAX);
expect(t.engine).toBe('acestep');
expect(t.modelId).toBe('ace-v1');
@@ -54,6 +56,12 @@ describe('tracks logic', () => {
expect(next.title).toBe('Intro (Reprise)');
expect(next.lyrics).toBe('');
});
+
+ it('preserves a saved concept until it is explicitly replaced or cleared', () => {
+ const next = applyTrackPatch(base, { concept: 'A dusk-time pulse' });
+ expect(next.concept).toBe('A dusk-time pulse');
+ expect(applyTrackPatch(next, { concept: '' }).concept).toBe('');
+ });
});
describe('mergeTrackRecord (LWW)', () => {