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

pass the autopilot prompt to the lyric writer and reviewer so a requested hook survives

[._.]/ Adam Eivybc9a18326b36
diff --git a/server/services/musicDesigner.js b/server/services/musicDesigner.js
index 290f6194c3..c9c5f61d59 100644
--- a/server/services/musicDesigner.js
+++ b/server/services/musicDesigner.js
@@ -99,9 +99,15 @@ const lengthContract = (targetSeconds) => {
return `\n\nTARGET LENGTH: the finished song should run about ${minutes} minute${minutes === '1' ? '' : 's'} (${sec} seconds). Write roughly ${lines} sung lyric lines in total (section tags excluded) and never more than ${Math.round(lines * 1.2)}; keep sections concise rather than adding verses. This overrides any instruction above to add more sections.`;
};
-export function buildLyricsPrompt({ description, guidance, template, targetSeconds } = {}) {
+// The listener-facing request a song was commissioned from (an autonomous run's
+// prompt). The musical description covers only sound, so without this the hook
+// phrase, subject and imagery the user asked for never reach the lyricist.
+const SONG_REQUEST_LABEL = 'SONG REQUEST (what the lyrics must deliver: honour every hook phrase, subject and image it names)';
+
+export function buildLyricsPrompt({ description, guidance, request, template, targetSeconds } = {}) {
return [
pickTemplate(template, DEFAULT_LYRICS_TEMPLATE),
+ section(SONG_REQUEST_LABEL, trimTo(request, MAX_GUIDANCE)),
section('MUSICAL DESCRIPTION', trimTo(description, MAX_DESCRIPTION) || '(none given)'),
section('ADDITIONAL GUIDANCE FROM THE USER', trimTo(guidance, MAX_GUIDANCE)),
lengthContract(targetSeconds),
@@ -118,6 +124,7 @@ const LYRICS_REVIEW_INSTRUCTIONS = [
'Keep the length roughly equal to the draft: about the same number of sung lines per section.',
'Improve scansion and singability, sharpen weak or generic lines, give the chorus more punch, and make the argument of the song land more clearly.',
'Never add new topics, characters or story beats the draft does not already contain. Keep the lyrics original.',
+ 'Exception: when a SONG REQUEST is given, check the draft against it first. Any hook phrase, title phrase or required image it names that the draft lacks must appear in the revision (a named hook belongs in the chorus), and your notes must say what was missing.',
].join(' ');
const LYRICS_REVIEW_OUTPUT_CONTRACT = [
'Return the complete revised lyric sheet first, with its section tags.',
@@ -126,9 +133,10 @@ const LYRICS_REVIEW_OUTPUT_CONTRACT = [
'No preamble, no other commentary, no markdown fence.',
].join('\n');
-function buildLyricsReviewPrompt({ lyrics, description, guidance } = {}) {
+function buildLyricsReviewPrompt({ lyrics, description, guidance, request } = {}) {
return [
LYRICS_REVIEW_INSTRUCTIONS,
+ section(SONG_REQUEST_LABEL, trimTo(request, MAX_GUIDANCE)),
section('MUSICAL DESCRIPTION', trimTo(description, MAX_DESCRIPTION) || '(none given)'),
section('ADDITIONAL GUIDANCE FROM THE USER', trimTo(guidance, MAX_GUIDANCE)),
section('DRAFT LYRICS', trimTo(lyrics, MAX_LYRICS)),
@@ -193,6 +201,7 @@ export async function describeMusic({ concept, guidance, template, providerId, m
* @param {object} args
* @param {string} args.description — the enriched musical description
* @param {string} [args.guidance] — "make the chorus about X", etc.
+ * @param {string} [args.request] — the song request it is commissioned from (hook, subject, imagery)
* @param {string} [args.template] — meta-prompt override; blank → the default
* @param {number} [args.targetSeconds] — intended song length; default 180 (~3 min)
* @param {string} [args.providerId]
@@ -200,11 +209,11 @@ export async function describeMusic({ concept, guidance, template, providerId, m
* @param {string} [args.effort]
* @returns {Promise<{ lyrics: string, llm: { provider: string, model: string|null } }>}
*/
-export async function writeLyrics({ description, guidance, template, targetSeconds, providerId, model, effort } = {}) {
+export async function writeLyrics({ description, guidance, request, template, targetSeconds, providerId, model, effort } = {}) {
const { provider, selectedModel } = await resolveProviderAndModel({ providerId, model });
assertProvider(provider, { message: 'No AI provider available to write lyrics', code: 'NO_PROVIDER' });
- const prompt = buildLyricsPrompt({ description, guidance, template, targetSeconds });
+ const prompt = buildLyricsPrompt({ description, guidance, request, template, targetSeconds });
const { text, model: ranModel } = await runPromptThroughProvider({
provider, model: selectedModel, effort, prompt, source: 'music-lyrics',
});
@@ -224,19 +233,20 @@ export async function writeLyrics({ description, guidance, template, targetSecon
* @param {string} args.lyrics — the draft to revise
* @param {string} [args.description] — the musical description it was written against
* @param {string} [args.guidance]
+ * @param {string} [args.request] — the song request the draft must honour
* @param {string} [args.providerId]
* @param {string} [args.model]
* @param {string} [args.effort]
* @returns {Promise<{ lyrics: string, notes: string, llm: { provider: string, model: string|null } }>}
*/
-export async function reviewLyrics({ lyrics, description, guidance, providerId, model, effort } = {}) {
+export async function reviewLyrics({ lyrics, description, guidance, request, providerId, model, effort } = {}) {
if (!trimTo(lyrics, MAX_LYRICS)) {
throw new ServerError('There are no lyrics to review.', { status: 400, code: 'VALIDATION_ERROR' });
}
const { provider, selectedModel } = await resolveProviderAndModel({ providerId, model });
assertProvider(provider, { message: 'No AI provider available to review lyrics', code: 'NO_PROVIDER' });
- const prompt = buildLyricsReviewPrompt({ lyrics, description, guidance });
+ const prompt = buildLyricsReviewPrompt({ lyrics, description, guidance, request });
const { text, model: ranModel } = await runPromptThroughProvider({
provider, model: selectedModel, effort, prompt, source: 'music-lyrics-review',
});
diff --git a/server/services/musicDesigner.test.js b/server/services/musicDesigner.test.js
index fdec83105a..93a9b466e7 100644
--- a/server/services/musicDesigner.test.js
+++ b/server/services/musicDesigner.test.js
@@ -146,6 +146,15 @@ describe('writeLyrics', () => {
expect(lastRunArgs().prompt).toContain('about leaving at dawn');
});
+ it('puts the song request ahead of the musical description so its hook reaches the lyricist', async () => {
+ await writeLyrics({ description: 'synth-pop', request: 'a chorus built around the phrase "airplane mode"' });
+ const { prompt } = lastRunArgs();
+ expect(prompt).toMatch(/SONG REQUEST[^\n]*hook phrase[^\n]*:\na chorus built around the phrase "airplane mode"/);
+ expect(prompt.indexOf('SONG REQUEST')).toBeLessThan(prompt.indexOf('MUSICAL DESCRIPTION'));
+ await writeLyrics({ description: 'synth-pop' });
+ expect(lastRunArgs().prompt).not.toContain('SONG REQUEST');
+ });
+
it('passes effort through to the runner', async () => {
await writeLyrics({ description: 'x', effort: 'low' });
expect(lastRunArgs().effort).toBe('low');
@@ -183,6 +192,14 @@ describe('reviewLyrics', () => {
expect(prompt).toMatch(/Never add new topics/);
});
+ it('checks the draft against the song request and keeps a named hook', async () => {
+ ai.runPromptThroughProvider.mockResolvedValue({ text: '[verse]\nrain\n---\nAdded the missing hook.', model: 'ran-model' });
+ await reviewLyrics({ lyrics: DRAFT, description: 'synthwave', request: 'chorus must say "airplane mode"' });
+ const { prompt } = lastRunArgs();
+ expect(prompt).toContain('chorus must say "airplane mode"');
+ expect(prompt).toMatch(/hook phrase, title phrase or required image it names that the draft lacks must appear/);
+ });
+
it('treats an answer with no separator as all lyrics (empty notes), unwrapping a fence', async () => {
ai.runPromptThroughProvider.mockResolvedValue({ text: '```\n[verse]\nrain against the glass\n```', model: 'ran-model' });
expect(await reviewLyrics({ lyrics: DRAFT })).toMatchObject({ lyrics: '[verse]\nrain against the glass', notes: '' });
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.js
index 02609fb60e..aaeea4398b 100644
--- a/server/services/musicVideo/autonomousService.js
+++ b/server/services/musicVideo/autonomousService.js
@@ -660,13 +660,15 @@ async function writeRunLyrics({ project, run, save }) {
const review = autonomousLyricsReviewEnabled(run.brief);
const description = run.output.musicalDescription;
const guidance = run.brief.guidance || undefined;
+ // The prompt carries the lyrical intent (hook, subject, imagery); the musical description only the sound.
+ const request = run.brief.prompt || undefined;
const step = (name) => patchRun(project.id, (r) => stagePatch(r, 'lyrics', { step: name }));
let draft = review ? run.output.lyricsDraft : null;
let draftRoute = review ? run.output.lyricsRoute : null;
if (!draft) {
if (review) await step('draft');
const { route, ...llm } = await llmOf(run, 'lyrics');
- ({ lyrics: draft } = await deps.writeLyrics({ description, guidance, ...llm }));
+ ({ lyrics: draft } = await deps.writeLyrics({ description, guidance, request, ...llm }));
draftRoute = route;
await recordRoute(project, 'lyrics', route);
if (!review) return { output: { lyrics: draft, ...(route ? { lyricsRoute: route } : {}) } };
@@ -674,7 +676,7 @@ async function writeRunLyrics({ project, run, save }) {
}
await step('review');
const { route, ...llm } = await llmOf(run, 'lyricsReview');
- const revised = await deps.reviewLyrics({ lyrics: draft, description, guidance, ...llm });
+ const revised = await deps.reviewLyrics({ lyrics: draft, description, guidance, request, ...llm });
await recordRoute(project, 'lyricsReview', route);
return { output: {
lyricsDraft: draft,
diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.js
index 8602cb23fd..9317791c6c 100644
--- a/server/services/musicVideo/autonomousService.test.js
+++ b/server/services/musicVideo/autonomousService.test.js
@@ -346,9 +346,9 @@ describe('startAutonomousVideo', () => {
musicVideoEvents.off('autonomous', onEvent);
}
expect(calls).toEqual(['createProject', 'brief', 'updateProject', 'lyrics', 'review']);
- expect(doubles.writeLyrics).toHaveBeenCalledWith(expect.objectContaining({ providerId: 'local-llm', model: 'small' }));
+ expect(doubles.writeLyrics).toHaveBeenCalledWith(expect.objectContaining({ providerId: 'local-llm', model: 'small', request: 'p' }));
expect(doubles.reviewLyrics).toHaveBeenCalledWith(expect.objectContaining({
- lyrics: '[verse]\nrain on glass', description: BRIEF.musicalDescription, providerId: 'cloud', model: 'big', effort: 'high',
+ lyrics: '[verse]\nrain on glass', description: BRIEF.musicalDescription, request: 'p', providerId: 'cloud', model: 'big', effort: 'high',
}));
expect(steps).toEqual(expect.arrayContaining(['draft', 'review']));
// The checkpoint parks on the revision, keeping the draft and the critique beside it.