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: fill a Suno Hook draft from the vertical cut (#10375)

Adam Eivydb5d790ceac9
diff --git a/client/src/components/musicVideo/PublishPostingPanel.jsx b/client/src/components/musicVideo/PublishPostingPanel.jsx
index b920ed405a..e53273fa3e 100644
--- a/client/src/components/musicVideo/PublishPostingPanel.jsx
+++ b/client/src/components/musicVideo/PublishPostingPanel.jsx
@@ -10,6 +10,7 @@ import { publishRowAnchor } from '../../lib/musicVideoStages.js';
export const PUBLISH_TARGETS = [
{ target: 'youtube', label: 'YouTube', note: 'The final render, with chapters, thumbnail and captions' },
{ target: 'suno', label: 'Suno', note: 'Publishes the song with the cover and a link to the video' },
+ { target: 'sunoHook', label: 'Suno Hook', note: 'A 9:16 cut (the newest by default) set to its window of the song. You press Post' },
{ target: 'x', label: 'X thread', note: 'Hook with the 1080p video, then the story, prompt and links' },
{ target: 'shorts', label: 'YouTube Shorts', note: 'A 9:16 cut (the newest by default)' },
{ target: 'tiktok', label: 'TikTok', note: 'A 9:16 cut (the newest by default), labelled AI-generated' },
@@ -64,7 +65,7 @@ function TargetOptions({ target, kit, project, options, setOption, flairs, idFor
const area = (key, label) => field(key, label,
<textarea id={idFor(key)} value={options[key] || ''} rows={3} onChange={(e) => setOption(key, e.target.value)} className={inputCls} />);
- if (VERTICAL_TARGETS.includes(target)) {
+ const cutPicker = () => {
const cuts = verticalCutChoices(project);
if (cuts.length < 2) return null;
return field('cutId', 'Vertical cut to post', (
@@ -72,6 +73,18 @@ function TargetOptions({ target, kit, project, options, setOption, flairs, idFor
<option value="">Newest fresh cut (default)</option>
{[...cuts].reverse().map((c) => <option key={c.id} value={c.id}>{c.label}</option>)}
</select>));
+ };
+ if (VERTICAL_TARGETS.includes(target)) return cutPicker();
+ if (target === 'sunoHook') {
+ return (
+ <div className="grid sm:grid-cols-2 gap-2 items-end">
+ {text('songUrl', 'Song URL (the take the Hook plays)', kit.links?.song || 'https://suno.com/song/…')}
+ {cutPicker()}
+ <label className="flex items-center gap-1.5 text-xs min-h-[44px] sm:min-h-0">
+ <input type="checkbox" checked={options.showLyrics === true} onChange={(e) => setOption('showLyrics', e.target.checked)} /> Show Suno's lyrics (off when the cut has its own)
+ </label>
+ </div>
+ );
}
if (target === 'reddit') {
return (
@@ -221,7 +234,7 @@ function TargetRow({ project, kit, entry, publishing }) {
const idFor = (key) => `mv-post-${project.id}-${target}-${key}`;
const [options, setOptions] = useState(() => {
// Prefill Suno URL from autonomous run if available
- if (target === 'suno' && project?.autonomousRun?.output?.sunoSongIds?.length > 0) {
+ if ((target === 'suno' || target === 'sunoHook') && project?.autonomousRun?.output?.sunoSongIds?.length > 0) {
const songId = project.autonomousRun.output.sunoSongIds[0];
return { songUrl: `https://suno.com/song/${encodeURIComponent(songId)}` };
}
diff --git a/client/src/components/musicVideo/PublishPostingPanel.test.jsx b/client/src/components/musicVideo/PublishPostingPanel.test.jsx
index b3696ba770..4946635763 100644
--- a/client/src/components/musicVideo/PublishPostingPanel.test.jsx
+++ b/client/src/components/musicVideo/PublishPostingPanel.test.jsx
@@ -7,7 +7,7 @@ import { describe, it, expect, vi } from 'vitest';
import { render, screen, fireEvent, within, act } from '@testing-library/react';
import PublishPostingPanel, { PUBLISH_TARGETS } from './PublishPostingPanel.jsx';
-const ALL = ['youtube', 'suno', 'x', 'shorts', 'tiktok', 'instagram', 'reddit', 'stackerNews', 'distrokid'];
+const ALL = ['youtube', 'suno', 'sunoHook', 'x', 'shorts', 'tiktok', 'instagram', 'reddit', 'stackerNews', 'distrokid'];
const hook = (over = {}) => ({ drafts: {}, busy: {}, errors: {}, prepare: vi.fn(), submit: vi.fn(), discard: vi.fn(), enabledTargets: ALL, platforms: {}, recordPost: vi.fn(async () => null), ...over });
const project = (kit = {}) => ({ id: 'mv-1', publishKit: { builtAt: '2026-01-01T00:00:00.000Z', thumbnails: ['t1.jpg'], ...kit } });
const row = (label) => screen.getByText(label, { selector: 'div' }).closest('li');
diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.js
index bde9d3d376..b3e35c5182 100644
--- a/server/lib/musicVideoValidation.js
+++ b/server/lib/musicVideoValidation.js
@@ -736,7 +736,7 @@ export const musicVideoCoverArtGenerateSchema = z.object({
// #9282: posting to a platform through the PortOS Browser. One strict options
// object covers every target; each target's payload builder reads only its own.
-export const MUSIC_VIDEO_PUBLISH_TARGETS = Object.freeze(['youtube', 'shorts', 'tiktok', 'instagram', 'x', 'reddit', 'stackerNews', 'suno', 'distrokid']);
+export const MUSIC_VIDEO_PUBLISH_TARGETS = Object.freeze(['youtube', 'shorts', 'tiktok', 'instagram', 'x', 'reddit', 'stackerNews', 'suno', 'sunoHook', 'distrokid']);
export const musicVideoPublishTargetSchema = z.enum(MUSIC_VIDEO_PUBLISH_TARGETS);
const publishUrl = z.string().url().max(500);
// #9287: which platforms the director posts to (opt-in), the account for each,
@@ -758,6 +758,8 @@ export const musicVideoPublishPrepareSchema = z.object({
territory: z.string().max(40),
songUrl: publishUrl,
pin: z.boolean(),
+ // Suno Hook: keep the page's lyric overlay (default off: the cut carries its own).
+ showLyrics: z.boolean(),
prompt: kitText(25000),
storyImage: z.string().min(1).max(300),
cutId: z.string().min(1).max(100),
diff --git a/server/services/musicVideo/publish/index.js b/server/services/musicVideo/publish/index.js
index 0fa855d8d4..1585682aa0 100644
--- a/server/services/musicVideo/publish/index.js
+++ b/server/services/musicVideo/publish/index.js
@@ -22,12 +22,13 @@ import { xAdapter } from './x.js';
import { redditAdapter } from './reddit.js';
import { stackerNewsAdapter } from './stackerNews.js';
import { sunoAdapter } from './suno.js';
+import { sunoHookAdapter } from './sunoHook.js';
import { distrokidAdapter } from './distrokid.js';
import { musicVideoEvents } from '../events.js';
export const PUBLISH_ADAPTERS = Object.freeze({
youtube: youtubeAdapter, shorts: shortsAdapter, tiktok: tiktokAdapter, instagram: instagramAdapter,
- x: xAdapter, reddit: redditAdapter, stackerNews: stackerNewsAdapter, suno: sunoAdapter, distrokid: distrokidAdapter,
+ x: xAdapter, reddit: redditAdapter, stackerNews: stackerNewsAdapter, suno: sunoAdapter, sunoHook: sunoHookAdapter, distrokid: distrokidAdapter,
});
// The tab stays open past this: the human publishes from it. After the TTL only
// the CDP session is dropped; the tab closes on Discard, Fill again, or by hand.
diff --git a/server/services/musicVideo/publish/payloads.js b/server/services/musicVideo/publish/payloads.js
index e6be2f6c40..bbf1d4b584 100644
--- a/server/services/musicVideo/publish/payloads.js
+++ b/server/services/musicVideo/publish/payloads.js
@@ -24,6 +24,7 @@ function requireFreshKit(project, kit) {
if ((kit.master?.renderHistoryId ?? null) !== (project?.renderHistoryId ?? null)) throw stale();
}
+const SUNO_SONG_URL = /^https:\/\/(?:www\.)?suno\.com\/song\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i;
const VERTICAL_NEEDS = 'Render a 9:16 social cut on the Review stage (or rebuild the publishing kit for a 16:9 render) first';
const isVerticalCut = (e) => e?.status === 'complete' && e.aspect === '9:16' && e.filename;
@@ -175,6 +176,22 @@ const BUILDERS = {
const caption = [lead, video ? `Music video: ${video}` : ''].filter(Boolean).join(' ').slice(0, 500);
return { songUrl: song, caption, cover: releaseCover(kit), pin: options.pin !== false };
},
+ // A Suno Hook (#10375): the vertical cut set to a window of the project's song.
+ sunoHook: (project, kit, options = {}) => {
+ const song = songUrl(kit, options);
+ const songId = song.match(SUNO_SONG_URL)?.[1]?.toLowerCase();
+ if (!songId) throw missing('Give the Suno song URL the Hook plays (suno.com/song/…)');
+ const cut = pickVerticalCut(project, options);
+ const caption = text(kit.copy?.tiktok?.caption) || text(kit.copy?.shorts?.description).slice(0, 300);
+ const duration = Number(project?.audioAnalysis?.durationSec);
+ return {
+ video: { dir: 'videos', name: cut.filename }, songUrl: song, songId, title: text(project?.name),
+ durationSec: Number.isFinite(duration) && duration > 0 ? duration : null,
+ // The audio window opens where the cut's own audio does.
+ startSec: Math.max(0, Number(cut.startSec) || 0),
+ caption, showLyrics: options.showLyrics === true,
+ };
+ },
// The song as a single for Spotify and the other stores. The service adds the
// project's source audio; the cover is the kit's cover art, else its thumbnail cut square.
distrokid: (project, kit, options = {}) => {
diff --git a/server/services/musicVideo/publish/sunoHook.js b/server/services/musicVideo/publish/sunoHook.js
new file mode 100644
index 0000000000..c9eed6b9ad
--- /dev/null
+++ b/server/services/musicVideo/publish/sunoHook.js
@@ -0,0 +1,139 @@
+/**
+ * Suno Hook adapter (#10375): a Hook is Suno's short 9:16 video set to a window
+ * of one of the director's songs (suno.com/hooks/create). prepare() uploads the
+ * vertical cut, picks the song, sets the audio window to the cut's start and
+ * writes the caption; submit() presses Post. Nothing is posted before then.
+ *
+ * The window is a fixed box over a waveform with no numeric field, so it is set
+ * in two tries: keyboard nudges on a slider role when the page exposes one,
+ * else a drag calibrated at WAVEFORM_PX_PER_SEC. Either way the page's own m:ss
+ * label is read back and the fill fails rather than post the wrong stretch.
+ */
+import { PUBLISH_STEP_TIMEOUT_MS as T, clickVisibleText, loginRequired, step } from './browser.js';
+
+const CREATE_URL = 'https://suno.com/hooks/create';
+const label = 'Suno Hook';
+// Measured on the 2026-10 picker: one waveform second is about this many CSS px; dragging right moves the window earlier.
+export const WAVEFORM_PX_PER_SEC = 23.6;
+// The page's readout is a rounded m:ss, so a one-second miss is the finest check it can support.
+const READBACK_TOLERANCE_SEC = 1;
+
+const fmtClock = (sec) => `${Math.floor(sec / 60)}:${String(Math.floor(sec % 60)).padStart(2, '0')}`;
+const parseClock = (text) => {
+ const m = String(text).match(/(\d+):(\d{2})/);
+ return m ? Number(m[1]) * 60 + Number(m[2]) : null;
+};
+
+/**
+ * Which picker row is the song: by id when a row carries it, else by the one
+ * row with the song's length, else the only row. Pure; rows are `{ text, html }`.
+ */
+export function pickSongRow(rows, { songId, durationSec, title }) {
+ const byId = rows.findIndex((r) => songId && r.html.toLowerCase().includes(songId.toLowerCase()));
+ if (byId >= 0) return byId;
+ const named = rows.map((r, i) => [r, i]).filter(([r]) => !title || r.text.toLowerCase().includes(title.toLowerCase()));
+ const pool = named.length ? named : rows.map((r, i) => [r, i]);
+ if (pool.length === 1) return pool[0][1];
+ const clock = Number.isFinite(durationSec) ? fmtClock(Math.round(durationSec)) : null;
+ const sameLength = clock ? pool.filter(([r]) => r.text.includes(clock)) : [];
+ if (sameLength.length === 1) return sameLength[0][1];
+ return -1;
+}
+
+async function selectSong(page, payload) {
+ await page.locator('text=Select Song').first().click({ timeout: T });
+ await page.locator('[role=dialog]').first().waitFor({ timeout: T });
+ const search = page.locator('textarea[placeholder*="Search by song name"]').first();
+ await search.fill(payload.title, { timeout: T });
+ await page.waitForTimeout(2500);
+ const rows = await page.evaluate(() => [...document.querySelectorAll('[role=dialog] button')]
+ .filter((b) => (b.innerText || '').trim() === 'Use')
+ .map((b) => {
+ let row = b;
+ for (let i = 0; i < 4 && row.parentElement && row.parentElement.querySelectorAll('button').length < 3; i += 1) row = row.parentElement;
+ return { text: row.innerText || '', html: row.innerHTML };
+ }));
+ const index = pickSongRow(rows, payload);
+ if (index < 0) throw new Error(`${rows.length} rows match "${payload.title}" and none could be told apart by id or length`);
+ await page.locator('[role=dialog] button').filter({ hasText: /^Use$/ }).nth(index).click({ timeout: T });
+ await page.waitForTimeout(1500);
+}
+
+/** The window's start as the page reports it, in seconds (null when no readout is found). */
+const readWindowStart = (page) => page.evaluate(() => {
+ const el = [...document.querySelectorAll('span,div')].find((e) => e.children.length === 0 && /^\d+:\d{2}$/.test(e.textContent.trim()) && e.offsetParent);
+ return el ? el.textContent.trim() : null;
+}).then((text) => (text ? parseClock(text) : null));
+
+async function setWindowStart(page, startSec) {
+ if (!(startSec > 0)) return 0; // the page opens the window at 0:00
+ const slider = page.locator('[role=slider]').first();
+ if (await slider.count()) {
+ await slider.focus();
+ for (let i = 0; i < 400; i += 1) {
+ const now = Number(await slider.getAttribute('aria-valuenow'));
+ const gap = startSec - now;
+ if (Number.isFinite(now) && Math.abs(gap) <= 0.1) return now;
+ await page.keyboard.press(gap > 0 ? 'ArrowRight' : 'ArrowLeft');
+ }
+ }
+ const box = await page.locator('[class*=waveform], [data-testid*=waveform], canvas').first().boundingBox();
+ if (!box) throw new Error('no waveform to set the window on');
+ const x = box.x + box.width / 2;
+ const y = box.y + box.height / 2;
+ await page.mouse.move(x, y);
+ await page.mouse.down();
+ await page.mouse.move(x - startSec * WAVEFORM_PX_PER_SEC, y, { steps: 20 }); // dragging right moves the window earlier
+ await page.mouse.up();
+ await page.waitForTimeout(500);
+ const got = await readWindowStart(page);
+ if (got == null || Math.abs(got - startSec) > READBACK_TOLERANCE_SEC) {
+ throw new Error(`the window reads ${got == null ? 'nothing' : fmtClock(got)}, wanted ${fmtClock(startSec)}`);
+ }
+ return got;
+}
+
+export const sunoHookAdapter = {
+ label,
+ async prepare(page, payload) {
+ await step(label, 'open Create Hook', () => page.goto(CREATE_URL, { waitUntil: 'domcontentloaded', timeout: T }));
+ await page.waitForTimeout(4000);
+ if (/\/(login|sign-?in)/.test(page.url()) || !(await page.locator('input[type=file][accept*=mp4]').count())) throw loginRequired(label, CREATE_URL);
+ await step(label, 'upload the vertical cut', async () => {
+ await page.locator('input[type=file][accept*=mp4]').first().setInputFiles(payload.video.path, { timeout: T });
+ await page.waitForTimeout(4000);
+ });
+ await step(label, 'select the song', () => selectSong(page, payload));
+ const windowStart = await step(label, 'set the audio window', () => setWindowStart(page, payload.startSec));
+ await step(label, 'open the Post Hook dialog', async () => {
+ await clickVisibleText(page, 'Next');
+ await page.locator('textarea[placeholder="Add a caption..."]').first().waitFor({ timeout: T });
+ });
+ if (payload.caption) await step(label, 'write the caption', () => page.locator('textarea[placeholder="Add a caption..."]').first().fill(payload.caption));
+ // Show Lyrics is on by default; a cut that carries its own lyric text would show them twice.
+ const lyrics = payload.showLyrics ? true : await step(label, 'turn off Show Lyrics', async () => {
+ const state = await page.evaluate(() => {
+ const text = [...document.querySelectorAll('span,div,label')].find((e) => e.children.length === 0 && e.textContent.trim() === 'Show Lyrics');
+ let node = text;
+ for (let i = 0; i < 8 && node; i += 1) {
+ node = node.parentElement;
+ const sw = node?.querySelector('[role=switch],input[type=checkbox]');
+ if (sw) {
+ const on = sw.getAttribute('aria-checked') === 'true' || sw.checked === true;
+ if (on) sw.click();
+ return true;
+ }
+ }
+ return null;
+ });
+ if (state === null) throw new Error('no Show Lyrics switch');
+ return false;
+ });
+ return { songUrl: payload.songUrl, windowStart, caption: payload.caption, showLyrics: lyrics };
+ },
+ async submit(page) {
+ await step(label, 'post', () => clickVisibleText(page, 'Post'));
+ await step(label, 'confirm it posted', () => page.waitForFunction(() => !document.querySelector('textarea[placeholder="Add a caption..."]'), null, { timeout: 60_000 }));
+ return { url: null };
+ },
+};
diff --git a/server/services/musicVideo/publish/sunoHook.test.js b/server/services/musicVideo/publish/sunoHook.test.js
new file mode 100644
index 0000000000..d330ef7f85
--- /dev/null
+++ b/server/services/musicVideo/publish/sunoHook.test.js
@@ -0,0 +1,37 @@
+import { describe, it, expect } from 'vitest';
+import { pickSongRow } from './sunoHook.js';
+import { buildPublishPayload } from './payloads.js';
+import { captureMusicVideoEvidence } from '../../../lib/musicVideoDependencies.js';
+
+const ID = '12345678-abcd-4abc-8abc-123456789abc';
+const project = (extra = {}) => {
+ const base = {
+ name: 'Night Drive', scenes: [], renderHistoryId: 'r1', audioAnalysis: { durationSec: 187 },
+ publishKit: { links: { song: `https://suno.com/song/${ID}` }, copy: { tiktok: { caption: 'Hook caption' } } },
+ };
+ const excerpts = [{ id: 'e1', status: 'complete', aspect: '9:16', filename: 'cut.mp4', startSec: 42, endSec: 62, dependencies: captureMusicVideoEvidence(base, { startSec: 42, endSec: 62 }) }];
+ return { ...base, excerpts, ...extra };
+};
+
+describe('Suno Hook payload', () => {
+ it('sets the window to the cut start and keeps the song id, title, length and caption', () => {
+ const p = buildPublishPayload('sunoHook', project());
+ expect(p).toMatchObject({ songId: ID, title: 'Night Drive', durationSec: 187, startSec: 42, caption: 'Hook caption', showLyrics: false, video: { dir: 'videos', name: 'cut.mp4' } });
+ });
+ it('refuses a missing song URL and a project with no vertical cut', () => {
+ expect(() => buildPublishPayload('sunoHook', project({ publishKit: {} }))).toThrow(/Suno song URL/);
+ expect(() => buildPublishPayload('sunoHook', project({ excerpts: [] }))).toThrow(/9:16/);
+ });
+});
+
+describe('pickSongRow', () => {
+ const row = (text, html = '') => ({ text, html });
+ it('prefers an id match, then the same length, and refuses an ambiguous pick', () => {
+ const rows = [row('Night Drive 2:10 synthwave'), row('Night Drive 3:07 synthwave', `<a href="/song/${ID}">`)];
+ expect(pickSongRow(rows, { songId: ID, title: 'Night Drive', durationSec: 130 })).toBe(1);
+ const noIds = [row('Night Drive 2:10'), row('Night Drive 3:07')];
+ expect(pickSongRow(noIds, { songId: ID, title: 'Night Drive', durationSec: 187 })).toBe(1);
+ expect(pickSongRow(noIds, { songId: ID, title: 'Night Drive', durationSec: null })).toBe(-1);
+ expect(pickSongRow([row('Night Drive 2:10')], { songId: ID, title: 'Night Drive' })).toBe(0);
+ });
+});