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
Music video: release copy notes, links and draft choices save as you edit
Claude44d710d486db
diff --git a/client/src/components/musicVideo/PublishKitPanel.jsx b/client/src/components/musicVideo/PublishKitPanel.jsxindex e186787007..7380e5aaed 100644--- a/client/src/components/musicVideo/PublishKitPanel.jsx+++ b/client/src/components/musicVideo/PublishKitPanel.jsx@@ -1,4 +1,4 @@-import { useState } from 'react';+import { useRef, useState } from 'react';import { Package, Download, Copy, Sparkles, Image as ImageIcon, Captions, ListOrdered } from 'lucide-react';import useProviderModels from '../../hooks/useProviderModels.js';import ProviderModelSelector from '../ProviderModelSelector.jsx';@@ -42,7 +42,7 @@ const fieldValue = (copy, platform, field) => {return typeof v === 'string' ? v : '';};-function CopyField({ id, field, initial, onSave, disabled }) {+function CopyField({ id, field, initial, onSave }) {const [value, setValue] = useState(initial);const over = field.max && value.length > field.max;const commit = () => {@@ -60,7 +60,7 @@ function CopyField({ id, field, initial, onSave, disabled }) {aria-label={`Copy ${field.label}`} className="text-port-text-muted disabled:opacity-40 min-h-[44px] sm:min-h-0 px-1"><Copy size={12} /></button></div></div>- <Input id={id} value={value} disabled={disabled} rows={field.multiline ? 4 : undefined}+ <Input id={id} value={value} rows={field.multiline ? 4 : undefined}onChange={(e) => setValue(e.target.value)} onBlur={commit}className="w-full bg-port-bg border border-port-border rounded px-1.5 py-1 text-xs min-h-[44px] sm:min-h-0" /></div>@@ -91,6 +91,21 @@ export default function PublishKitPanel({ project, publishKit, enabledTargets })const lyricLines = (project?.lyricCues || []).filter((c) => typeof c?.text === 'string' && c.text.trim() && typeof c.startSec === 'number' && Number.isFinite(c.startSec)).length;const [confirmReplace, setConfirmReplace] = useState(false);+ // Every field saves as it is edited (posts and notes on blur, choices on change);+ // the card says so, since there is no Save button to press.+ const [saveState, setSaveState] = useState(null);+ const saveSeq = useRef(0);+ const save = (patch) => {+ const seq = ++saveSeq.current;+ setSaveState('saving');+ // Only the newest save reports, so an earlier one landing late can't claim "saved" over it.+ return publishKit.saveCopy(patch).then((saved) => { if (seq === saveSeq.current) setSaveState(saved ? 'saved' : 'failed'); });+ };+ const saveLink = (key, value) => {+ const url = value.trim();+ if (url === (kit.links?.[key] || '') || (url && !/^https?:\/\//.test(url))) return;+ save({ links: { [key]: url } });+ };// Mirrors the server's copyEditedSinceDraft: a draft would replace posts written or edited by hand.const editedAt = Date.parse(kit.copyEditedAt || '');const draftedAt = Date.parse(kit.copyDraftedAt || '');@@ -199,21 +214,27 @@ export default function PublishKitPanel({ project, publishKit, enabledTargets })<PublishCard projectId={project?.id} cardId="copy" label="Release copy" icon={Sparkles}summary={hasCopy ? 'Drafted' : 'Not drafted yet'} defaultOpen={!hasCopy}>- <p className="text-port-text-muted">Each post below is exactly what goes out. Write it yourself, or have the writer draft it from your notes, the links and only what you tick under Draft from. Nothing runs until you press Draft.</p>+ <p className="text-port-text-muted">Each post below is exactly what goes out. Write it yourself, or have the writer draft it from your notes, the links and only what you tick under Draft from. Nothing runs until you press Draft. Edits save on their own when you leave a field.</p>+ {saveState && (+ <p role="status" className={`text-[11px] ${saveState === 'failed' ? 'text-port-error' : 'text-port-text-muted'}`}>+ {saveState === 'saving' ? 'Saving…' : saveState === 'saved' ? 'All changes saved' : 'Last change did not save. Edit the field again to retry.'}+ </p>+ )}<div className="space-y-0.5"><label htmlFor={idFor('notes')} className="text-[11px] text-port-text-muted">Making-of notes (your story, in your words)</label><textarea id={idFor('notes')} value={notes} maxLength={8000} rows={4} onChange={(e) => setNotes(e.target.value)}+ onBlur={() => { if (notes !== (kit.notes || '')) save({ notes }); }}className="w-full bg-port-bg border border-port-border rounded px-1.5 py-1 text-xs" /></div><div className="grid sm:grid-cols-2 gap-2"><div><label htmlFor={idFor('youtube-url')} className="block text-[11px] text-port-text-muted">Full video URL (optional)</label>- <input id={idFor('youtube-url')} value={youtubeUrl} onChange={(e) => setYoutubeUrl(e.target.value)} placeholder="https://…"+ <input id={idFor('youtube-url')} value={youtubeUrl} onChange={(e) => setYoutubeUrl(e.target.value)} onBlur={() => saveLink('youtube', youtubeUrl)} placeholder="https://…"className="w-full bg-port-bg border border-port-border rounded px-1.5 py-1 text-xs min-h-[44px] sm:min-h-0" /></div><div><label htmlFor={idFor('song-url')} className="block text-[11px] text-port-text-muted">Song URL (optional)</label>- <input id={idFor('song-url')} value={songUrl} onChange={(e) => setSongUrl(e.target.value)} placeholder="https://…"+ <input id={idFor('song-url')} value={songUrl} onChange={(e) => setSongUrl(e.target.value)} onBlur={() => saveLink('song', songUrl)} placeholder="https://…"className="w-full bg-port-bg border border-port-border rounded px-1.5 py-1 text-xs min-h-[44px] sm:min-h-0" /></div></div>@@ -222,7 +243,11 @@ export default function PublishKitPanel({ project, publishKit, enabledTargets }){includeRows.map(({ key, label, detail, available }) => (<label key={key} htmlFor={idFor(`include-${key}`)} className={`flex items-center gap-2 min-h-[44px] sm:min-h-0 ${available ? '' : 'opacity-50'}`}><input id={idFor(`include-${key}`)} type="checkbox" checked={available && include[key]} disabled={!available || publishKit.drafting}- onChange={(e) => setInclude((cur) => ({ ...cur, [key]: e.target.checked }))} />+ onChange={(e) => {+ const checked = e.target.checked;+ setInclude((cur) => ({ ...cur, [key]: checked }));+ save({ draftOptions: { include: { [key]: checked } } });+ }} /><span>{label} <span className="text-port-text-muted">· {detail}</span></span></label>))}@@ -232,7 +257,7 @@ export default function PublishKitPanel({ project, publishKit, enabledTargets }){[['short', 'A sentence or two'], ['full', 'Full making-of']].map(([value, label]) => (<label key={value} htmlFor={idFor(`length-${value}`)} className="flex items-center gap-1.5 min-h-[44px] sm:min-h-0"><input id={idFor(`length-${value}`)} type="radio" name={idFor('length')} value={value} checked={length === value}- disabled={publishKit.drafting} onChange={() => setLength(value)} />+ disabled={publishKit.drafting} onChange={() => { setLength(value); save({ draftOptions: { length: value } }); }} />{label}</label>))}@@ -266,8 +291,8 @@ export default function PublishKitPanel({ project, publishKit, enabledTargets })<legend className="px-1 text-[11px] font-medium">{label}</legend>{fields.map((field) => (<CopyField key={field.key} id={idFor(`${platform}-${field.key}`)} field={field}- initial={fieldValue(kit.copy, platform, field)} disabled={publishKit.saving}- onSave={(value) => publishKit.saveCopy({ [platform]: { [field.key]: value } })} />+ initial={fieldValue(kit.copy, platform, field)}+ onSave={(value) => save({ [platform]: { [field.key]: value } })} />))}</fieldset>))}diff --git a/client/src/components/musicVideo/PublishKitPanel.test.jsx b/client/src/components/musicVideo/PublishKitPanel.test.jsxindex 88393505ec..3abd769887 100644--- a/client/src/components/musicVideo/PublishKitPanel.test.jsx+++ b/client/src/components/musicVideo/PublishKitPanel.test.jsx@@ -4,7 +4,7 @@* saves on blur (tags as a list), and the thumbnail choice goes to the server.*/import { describe, it, expect, vi } from 'vitest';-import { render, screen, fireEvent } from '@testing-library/react';+import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';vi.mock('../../hooks/useProviderModels.js', () => ({default: () => ({ providers: [], selectedProviderId: '', selectedModel: '', availableModels: [], setSelectedProviderId: vi.fn(), setSelectedModel: vi.fn() }),@@ -40,7 +40,7 @@ describe('PublishKitPanel (#9281)', () => {expect(k.build).toHaveBeenCalled();});- it('drafts copy from the notes, only well-formed links and only what is ticked', () => {+ it('drafts copy from the notes, only well-formed links and only what is ticked', async () => {const k = hook();const project = { id: 'mv-1', name: 'Example Song', renderHistoryId: 'rh-1', lyricCues: [{ text: 'a line', startSec: 1 }, { text: 'untimed' }], productionRuns: [{ usage: { spentUsd: 4.5 } }] };render(<PublishKitPanel project={project} publishKit={k} />);@@ -64,6 +64,36 @@ describe('PublishKitPanel (#9281)', () => {fireEvent.click(screen.getByLabelText('Full making-of'));fireEvent.click(screen.getByRole('button', { name: /Draft copy/ }));expect(k.draftCopy).toHaveBeenLastCalledWith(expect.objectContaining({ include: { ...none, title: false, lyrics: true, spend: true, hashtags: true }, length: 'full' }));+ await act(async () => {}); // let the field saves settle+ });++ it('saves notes, links and draft choices as they are edited and says when they are saved', async () => {+ const k = hook({ saveCopy: vi.fn(async () => ({ id: 'mv-1' })) });+ render(<PublishKitPanel project={{ id: 'mv-1', name: 'Example Song', renderHistoryId: 'rh-1', publishKit: { links: { song: 'https://example.com/old' } } }} publishKit={k} />);+ expandAll();+ const notes = screen.getByLabelText(/Making-of notes/);+ fireEvent.change(notes, { target: { value: 'hummed it in the car' } });+ fireEvent.blur(notes);+ expect(k.saveCopy).toHaveBeenLastCalledWith({ notes: 'hummed it in the car' });+ expect(await screen.findByText('All changes saved')).toBeInTheDocument();++ const video = screen.getByLabelText(/Full video URL/);+ fireEvent.change(video, { target: { value: 'not a url' } });+ fireEvent.blur(video);+ expect(k.saveCopy).toHaveBeenCalledTimes(1); // a malformed link is never sent+ const song = screen.getByLabelText(/Song URL/);+ fireEvent.change(song, { target: { value: '' } });+ fireEvent.blur(song);+ expect(k.saveCopy).toHaveBeenLastCalledWith({ links: { song: '' } });++ fireEvent.click(screen.getByLabelText('Full making-of'));+ expect(k.saveCopy).toHaveBeenLastCalledWith({ draftOptions: { length: 'full' } });+ fireEvent.click(screen.getByLabelText(/Hashtags and YouTube tags/));+ expect(k.saveCopy).toHaveBeenLastCalledWith({ draftOptions: { include: { hashtags: true } } });++ k.saveCopy.mockResolvedValueOnce(null);+ fireEvent.click(screen.getByLabelText('A sentence or two'));+ await waitFor(() => expect(screen.getByText(/did not save/)).toBeInTheDocument());});it('asks before a draft replaces posts edited by hand', () => {@@ -80,7 +110,7 @@ describe('PublishKitPanel (#9281)', () => {expect(k.draftCopy).toHaveBeenCalledWith(expect.objectContaining({ replaceEdited: true }));});- it('cannot tick lyrics or spend the project does not have, and lets you write a post without drafting', () => {+ it('cannot tick lyrics or spend the project does not have, and lets you write a post without drafting', async () => {const k = hook();render(<PublishKitPanel project={{ id: 'mv-1', name: 'Example Song', renderHistoryId: 'rh-1', lyricCues: [{ text: 'untimed' }] }} publishKit={k} enabledTargets={['x']} />);expandAll();@@ -90,9 +120,10 @@ describe('PublishKitPanel (#9281)', () => {fireEvent.change(hook_, { target: { value: 'One sentence of my own.' } });fireEvent.blur(hook_);expect(k.saveCopy).toHaveBeenCalledWith({ x: { hook: 'One sentence of my own.' } });+ await act(async () => {}); // let the field saves settle});- it('shows the built kit, saves an edited field on blur and picks a thumbnail', () => {+ it('shows the built kit, saves an edited field on blur and picks a thumbnail', async () => {const k = hook();render(<PublishKitPanel project={{ id: 'mv-1', renderHistoryId: 'rh-1', publishKit: built }} publishKit={k} />);expandAll();@@ -104,6 +135,7 @@ describe('PublishKitPanel (#9281)', () => {expect(k.saveCopy).toHaveBeenCalledWith({ youtube: { tags: ['music', 'ai video', 'claude'] } });fireEvent.click(screen.getByRole('button', { name: 'Use thumbnail t2.jpg' }));expect(k.selectThumbnail).toHaveBeenCalledWith('t2.jpg');+ await act(async () => {}); // let the field saves settle});it('makes the cover art from a project image with the title, and asks Codex for a new one', () => {diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.jsindex 562c485566..f139395fad 100644--- a/server/lib/musicVideoValidation.js+++ b/server/lib/musicVideoValidation.js@@ -711,6 +711,12 @@ export const musicVideoPublishCopyPatchSchema = z.object({stackerNews: z.object({ title: kitText(80), body: kitText(40000) }).partial().strict().optional(),substack: z.object({ title: kitText(100), subtitle: kitText(250), body: kitText(40000) }).partial().strict().optional(),notes: kitText(8000).optional(),+ // The draft inputs save as they are edited, not only when Draft runs; '' clears a link.+ links: z.object({ youtube: z.union([z.string().url().max(500), z.literal('')]), song: z.union([z.string().url().max(500), z.literal('')]) }).partial().strict().optional(),+ draftOptions: z.object({+ include: z.object({ title: z.boolean(), lyrics: z.boolean(), spend: z.boolean(), chapters: z.boolean(), hashtags: z.boolean() }).partial().strict().optional(),+ length: z.enum(['short', 'full']).optional(),+ }).strict().optional(),}).strict();export const musicVideoPublishCopyDraftSchema = z.object({providerId: z.string().max(200).nullable().optional(),diff --git a/server/services/musicVideo/publishKit.js b/server/services/musicVideo/publishKit.jsindex ea312742c5..cbf7646791 100644--- a/server/services/musicVideo/publishKit.js+++ b/server/services/musicVideo/publishKit.js@@ -265,11 +265,31 @@ export async function updatePublishKitCopy(projectId, patch) {return mutateProjectRecord(projectId, (current) => {const kit = projectPublishKit(current);const copy = { ...(kit.copy || {}) };+ let postEdited = false;for (const platform of PUBLISH_PLATFORMS) {- if (patch?.[platform] && typeof patch[platform] === 'object') copy[platform] = { ...(copy[platform] || {}), ...patch[platform] };+ if (patch?.[platform] && typeof patch[platform] === 'object') {+ copy[platform] = { ...(copy[platform] || {}), ...patch[platform] };+ postEdited = true;+ }}- const next = { ...kit, copy, copyEditedAt: new Date().toISOString() };+ // Only a post's own text counts as hand-edited copy a redraft must not silently replace.+ const next = { ...kit, copy, ...(postEdited ? { copyEditedAt: new Date().toISOString() } : {}) };if (typeof patch?.notes === 'string') next.notes = patch.notes;+ if (patch?.links && typeof patch.links === 'object') {+ const links = { ...(kit.links || {}) };+ for (const [key, url] of Object.entries(patch.links)) {+ if (url) links[key] = url; else delete links[key];+ }+ next.links = links;+ }+ if (patch?.draftOptions && typeof patch.draftOptions === 'object') {+ const prior = kit.draftOptions || {};+ next.draftOptions = {+ ...prior,+ ...(patch.draftOptions.include ? { include: { ...(prior.include || {}), ...patch.draftOptions.include } } : {}),+ ...(patch.draftOptions.length ? { length: patch.draftOptions.length } : {}),+ };+ }return { project: { ...current, publishKit: next } };});}diff --git a/server/services/musicVideo/publishKit.test.js b/server/services/musicVideo/publishKit.test.jsindex 501e281a54..f921ee98ec 100644--- a/server/services/musicVideo/publishKit.test.js+++ b/server/services/musicVideo/publishKit.test.js@@ -334,6 +334,21 @@ describe('publishing kit copy (#9281)', () => {await expect(kit.draftPublishKitCopy(id, {}, deps)).resolves.toBeTruthy();});+ it('saves the draft inputs as they are edited without marking the posts hand-edited', async () => {+ const { id } = await projects.createProject({ name: 'Example Song' });+ await kit.updatePublishKitCopy(id, { notes: 'made it on a Sunday', links: { youtube: 'https://example.com/v', song: 'https://example.com/s' } });+ await kit.updatePublishKitCopy(id, { links: { song: '' }, draftOptions: { include: { lyrics: true }, length: 'full' } });+ const { project } = await kit.updatePublishKitCopy(id, { draftOptions: { include: { spend: true } } });+ expect(project.publishKit).toMatchObject({+ notes: 'made it on a Sunday',+ links: { youtube: 'https://example.com/v' },+ draftOptions: { include: { lyrics: true, spend: true }, length: 'full' },+ });+ expect(project.publishKit.links).not.toHaveProperty('song');+ // Notes, links and options are draft inputs, not posts: a draft still runs without the replace confirmation.+ expect(project.publishKit).not.toHaveProperty('copyEditedAt');+ });+it('clears tags an earlier draft wrote once hashtags are unticked', async () => {const { id } = await projects.createProject({ name: 'Example Song' });const reply = JSON.stringify({ youtube: { title: 'Drafted', description: 'd', tags: ['model tag'] } });