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

fix(publish): keep Suno cross-link backfill within the caption limit and drop stale carried links

[._.]/ Adam Eivy453bc2cd1ab9
diff --git a/server/lib/musicVideoCrossLinks.js b/server/lib/musicVideoCrossLinks.js
index bcd499482b..c216f59f18 100644
--- a/server/lib/musicVideoCrossLinks.js
+++ b/server/lib/musicVideoCrossLinks.js
@@ -86,3 +86,19 @@ export function mergeCarriedLinks(existing, added) {
const all = [...(Array.isArray(existing) ? existing : []), ...(Array.isArray(added) ? added : [])];
return [...new Set(all.filter((t) => Object.hasOwn(CROSS_LINK_LABELS, t)))];
}
+
+/**
+ * `posts` with `target` struck from every other post's carried links: those
+ * posts show the old URL (or a removed post), not whatever `target` becomes.
+ * Posts reading their links from the legacy defaults are given an explicit list.
+ * `kit` is the kit as it was before the change.
+ */
+export function dropCarriedLink(kit, posts, target) {
+ const out = { ...posts };
+ for (const [other, post] of Object.entries(posts)) {
+ if (other === target || !post || typeof post !== 'object') continue;
+ const carried = carriedLinks(kit, other);
+ if (carried.includes(target)) out[other] = { ...post, links: carried.filter((t) => t !== target) };
+ }
+ return out;
+}
diff --git a/server/lib/musicVideoCrossLinks.test.js b/server/lib/musicVideoCrossLinks.test.js
index efa1bd59a1..2391ef115a 100644
--- a/server/lib/musicVideoCrossLinks.test.js
+++ b/server/lib/musicVideoCrossLinks.test.js
@@ -3,7 +3,7 @@
* what its draft always linked, counted only when that link existed first.
*/
import { describe, expect, it } from 'vitest';
-import { carriedLinks, crossLinkBackfill } from './musicVideoCrossLinks.js';
+import { carriedLinks, crossLinkBackfill, dropCarriedLink } from './musicVideoCrossLinks.js';
const song = 'https://suno.com/song/12345678-abcd-4abc-8abc-123456789abc';
@@ -25,4 +25,20 @@ describe('cross-links between release posts', () => {
expect(rows.youtube.missing.map((l) => l.target)).toEqual(['suno', 'x']);
expect(rows.stackerNews).toBeUndefined();
});
+
+ it('stops counting a removed or replaced post as linked, so backfill offers the new URL', () => {
+ const kit = { posts: {
+ youtube: { url: 'https://youtu.be/abc', postedAt: '2026-01-01T00:00:00Z', links: [] },
+ x: { url: 'https://x.com/a/status/1', postedAt: '2026-01-02T00:00:00Z', links: ['youtube'] },
+ } };
+ const posts = dropCarriedLink(kit, kit.posts, 'youtube');
+ expect(posts.x.links).toEqual([]);
+ expect(posts.youtube).toBe(kit.posts.youtube);
+ // Legacy post without a links list is given an explicit one.
+ const legacy = { posts: { youtube: kit.posts.youtube, suno: { url: song, postedAt: '2026-01-03T00:00:00Z' } } };
+ expect(dropCarriedLink(legacy, legacy.posts, 'youtube').suno.links).toEqual([]);
+ // Reposted on a new URL: the other post is missing it again.
+ const reposted = { posts: { ...posts, youtube: { url: 'https://youtu.be/new', postedAt: '2026-01-04T00:00:00Z', links: [] } } };
+ expect(crossLinkBackfill(reposted).find((r) => r.target === 'x').missing.map((l) => l.url)).toContain('https://youtu.be/new');
+ });
});
diff --git a/server/services/musicVideo/publish/crossLinkEdits.js b/server/services/musicVideo/publish/crossLinkEdits.js
index 97ba093191..fe1f50e6a9 100644
--- a/server/services/musicVideo/publish/crossLinkEdits.js
+++ b/server/services/musicVideo/publish/crossLinkEdits.js
@@ -10,6 +10,9 @@
import { PUBLISH_STEP_TIMEOUT_MS as T, loginRequired, pasteText, step } from './browser.js';
import { markSunoSongMenu } from '../../../lib/sunoPage.js';
+// Suno's caption limit; the new-draft builder enforces the same one.
+const SUNO_CAPTION_MAX = 500;
+
const youtubeIdOf = (url) => String(url).match(/(?:youtu\.be\/|[?&]v=|\/shorts\/)([\w-]{6,})/)?.[1] || null;
const tweetIdOf = (url) => String(url).match(/\/status\/(\d+)/)?.[1] || null;
const sunoSongIdOf = (url) => String(url).match(/\/song\/([0-9a-f-]{36})/i)?.[1] || null;
@@ -66,9 +69,21 @@ const suno = {
})().catch(() => null);
if (!caption) return { added: [], leftForYou: [`Open the song's details and add to its caption:\n${row.text}`, 'Save'] };
const current = await caption.inputValue();
- const lines = linesNotIn(row.text, current);
- if (lines.length) await step(this.label, 'add the links to the caption', () => caption.fill([current.trimEnd(), lines.join('\n')].filter(Boolean).join('\n')));
- return { added: lines.length ? lines : ['Nothing: the caption already has every link'], leftForYou: ['Save'] };
+ const pending = linesNotIn(row.text, current);
+ // Whole lines only, while the caption fits: an overflow link stays for the director.
+ let next = current.trimEnd();
+ const lines = [];
+ const overflow = [];
+ for (const line of pending) {
+ const joined = next ? `${next}\n${line}` : line;
+ if (joined.length > SUNO_CAPTION_MAX) { overflow.push(line); continue; }
+ next = joined;
+ lines.push(line);
+ }
+ if (lines.length) await step(this.label, 'add the links to the caption', () => caption.fill(next));
+ const leftForYou = ['Save'];
+ if (overflow.length) leftForYou.unshift(`Too long for the ${SUNO_CAPTION_MAX}-character caption, add elsewhere:\n${overflow.join('\n')}`);
+ return { added: lines.length ? lines : [overflow.length ? 'Nothing: the caption has no room' : 'Nothing: the caption already has every link'], leftForYou };
},
};
diff --git a/server/services/musicVideo/publish/crossLinkEdits.test.js b/server/services/musicVideo/publish/crossLinkEdits.test.js
index 31177f9b9b..d1cf8cb0c3 100644
--- a/server/services/musicVideo/publish/crossLinkEdits.test.js
+++ b/server/services/musicVideo/publish/crossLinkEdits.test.js
@@ -43,4 +43,16 @@ describe('cross-link edits', () => {
expect(summary.added).toEqual([]);
expect(summary.leftForYou[0]).toContain('Stacker News: https://stacker.news/items/7');
});
+
+ it('keeps the Suno caption within its limit and leaves an overflow link for the director', async () => {
+ const url = 'https://suno.com/song/12345678-abcd-4abc-8abc-123456789abc';
+ const filled = [];
+ const field = { waitFor: async () => {}, inputValue: async () => 'x'.repeat(480), fill: async (t) => filled.push(t) };
+ const item = { isVisible: async () => true, click: async () => {}, hover: async () => {} };
+ const page = fakePage({ url });
+ page.locator = (sel) => (String(sel).includes('textarea') ? { first: () => field } : { first: () => item, filter: () => ({ first: () => item }), click: async () => {}, count: async () => 1 });
+ const summary = await CROSS_LINK_ADAPTERS.suno.prepare(page, row('suno', url));
+ expect(filled.every((t) => t.length <= 500)).toBe(true);
+ expect(summary.leftForYou[0]).toContain('https://stacker.news/items/7');
+ });
});
diff --git a/server/services/musicVideo/publish/index.js b/server/services/musicVideo/publish/index.js
index eabbaa7be0..ccc0b464c2 100644
--- a/server/services/musicVideo/publish/index.js
+++ b/server/services/musicVideo/publish/index.js
@@ -31,7 +31,7 @@ import { sunoHookAdapter } from './sunoHook.js';
import { distrokidAdapter } from './distrokid.js';
import { musicVideoEvents } from '../events.js';
import { CROSS_LINK_ADAPTERS } from './crossLinkEdits.js';
-import { carriedLinks, crossLinkBackfill, mergeCarriedLinks } from '../../../lib/musicVideoCrossLinks.js';
+import { carriedLinks, crossLinkBackfill, dropCarriedLink, mergeCarriedLinks } from '../../../lib/musicVideoCrossLinks.js';
export const PUBLISH_ADAPTERS = Object.freeze({
youtube: youtubeAdapter, shorts: shortsAdapter, tiktok: tiktokAdapter, instagram: instagramAdapter,
@@ -312,9 +312,13 @@ export async function recordPublishPost(projectId, target, input = {}, deps = {}
}
const { project } = await mutateProjectRecord(projectId, (current) => {
const kit = current.publishKit && typeof current.publishKit === 'object' ? current.publishKit : {};
- const posts = { ...(kit.posts || {}) };
+ let posts = { ...(kit.posts || {}) };
if (Array.isArray(input.links) && posts[target]) input = { ...input, links: mergeCarriedLinks(carriedLinks(kit, target), input.links) };
- posts[target] = normalizePost(posts[target], input);
+ const before = posts[target];
+ const next = normalizePost(before, input);
+ // Other posts that linked the old URL no longer link this post.
+ if (before?.url && before.url !== next.url) posts = dropCarriedLink(kit, posts, target);
+ posts[target] = next;
return { project: { ...current, publishKit: { ...kit, posts } } };
});
return { project, post: project.publishKit.posts[target] };
@@ -366,8 +370,8 @@ export async function removePublishPost(projectId, target) {
const { project } = await mutateProjectRecord(projectId, (current) => {
const kit = current.publishKit && typeof current.publishKit === 'object' ? current.publishKit : {};
if (!kit.posts?.[target]) return { project: current };
- const { [target]: _removed, ...posts } = kit.posts;
- return { project: { ...current, publishKit: { ...kit, posts } } };
+ const { [target]: _removed, ...rest } = kit.posts;
+ return { project: { ...current, publishKit: { ...kit, posts: dropCarriedLink(kit, rest, target) } } };
});
return { project };
}