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

Release copy: tidy what removing a hashtag leaves, and drop stale drafted tags

Claude230eba40be98
diff --git a/server/services/musicVideo/publishKit.js b/server/services/musicVideo/publishKit.js
index e5cd27938e..9d12f0c122 100644
--- a/server/services/musicVideo/publishKit.js
+++ b/server/services/musicVideo/publishKit.js
@@ -234,6 +234,8 @@ export async function updatePublishKitCopy(projectId, patch) {
});
}
+const sameTags = (a, b) => Array.isArray(b) && b.length > 0 && a.length === b.length && a.every((t, i) => t === b[i]);
+
/** True when a post was written or edited by hand after the last draft (or with no draft yet). */
export function copyEditedSinceDraft(kit) {
const edited = Date.parse(kit?.copyEditedAt || '');
@@ -281,6 +283,13 @@ export async function draftPublishKitCopy(projectId, { providerId = null, model
const kit = projectPublishKit(current);
const merged = { ...(kit.copy || {}) };
for (const [platform, fields] of Object.entries(copy)) merged[platform] = { ...(merged[platform] || {}), ...fields };
- return { project: { ...current, publishKit: { ...kit, copy: merged, notes, draftOptions: options, links: { ...(kit.links || {}), ...links }, copyDraftedAt: new Date().toISOString() } } };
+ // With hashtags off the draft returns no tags: typed tags stay, but tags an
+ // earlier draft wrote (still unedited) go, so none remain unasked.
+ const youtube = merged.youtube;
+ if (copy.youtube && !('tags' in copy.youtube) && Array.isArray(youtube?.tags) && sameTags(youtube.tags, kit.draftedTags)) {
+ merged.youtube = { ...youtube, tags: [] };
+ }
+ const draftedTags = Array.isArray(copy.youtube?.tags) ? copy.youtube.tags : [];
+ return { project: { ...current, publishKit: { ...kit, copy: merged, draftedTags, notes, draftOptions: options, links: { ...(kit.links || {}), ...links }, copyDraftedAt: new Date().toISOString() } } };
});
}
diff --git a/server/services/musicVideo/publishKit.test.js b/server/services/musicVideo/publishKit.test.js
index f3dff256ec..82681f4010 100644
--- a/server/services/musicVideo/publishKit.test.js
+++ b/server/services/musicVideo/publishKit.test.js
@@ -162,6 +162,16 @@ describe('publishing kit copy (#9281)', () => {
await expect(kit.draftPublishKitCopy(id, {}, deps)).resolves.toBeTruthy();
});
+ 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'] } });
+ const deps = { platforms: { youtube: { enabled: true } }, history: {}, runner: runner(reply) };
+ const first = await kit.draftPublishKitCopy(id, { include: { hashtags: true } }, deps);
+ expect(first.project.publishKit.copy.youtube.tags).toEqual(['model tag']);
+ const second = await kit.draftPublishKitCopy(id, {}, deps);
+ expect(second.project.publishKit.copy.youtube.tags).toEqual([]);
+ });
+
it('reports an unusable draft instead of saving it', async () => {
const { id } = await projects.createProject({ name: 'Example Song' });
await expect(kit.draftPublishKitCopy(id, {}, { platforms: ALL_ON, history: {}, runner: runner('sorry, no JSON') })).rejects.toMatchObject({ status: 502, code: 'PUBLISH_COPY_UNPARSEABLE' });
diff --git a/server/services/musicVideo/publishKitText.js b/server/services/musicVideo/publishKitText.js
index 763cb1062e..ca86576d96 100644
--- a/server/services/musicVideo/publishKitText.js
+++ b/server/services/musicVideo/publishKitText.js
@@ -150,21 +150,27 @@ function copySpecs({ include, length }) {
// A run of hashtags: `#` plus a word with at least one letter (so `#1` and
// `#2` stay), standing at a line start or after a space or opening bracket or
-// quote (so a URL fragment like `/album/#listen` and `'` stay). Markdown
-// headings ("# Heading") have a space after the `#` and never match.
+// quote (so a URL fragment like `/album/#listen` and `'` stay), optionally
+// wrapped whole in parentheses. Markdown headings ("# Heading") have a space
+// after the `#` and never match.
const TAG = String.raw`#[\p{N}_]*\p{L}[\p{L}\p{N}_]*`;
-const HASHTAG_RUN = new RegExp(String.raw`([ \t]*)(?<=^|[\s(\[{"'“‘])${TAG}(?:[ \t]+${TAG})*([ \t]*)`, 'gmu');
+const RUN = String.raw`${TAG}(?:[ \t]+${TAG})*`;
+const HASHTAG_RUN = new RegExp(String.raw`([ \t]*)(?:(?<=^|[\s"'“‘])\(${RUN}\)|(?<=^|[\s(\[{"'“‘])${RUN})([ \t]*(?:\r?\n)?)`, 'gmu');
+const CLOSING = /^[,.;:!?)\]}]/;
/**
- * The text with every hashtag removed. Only the spacing around a removed tag
- * changes: a run ending its line takes the spaces before it too, and one
+ * The text with every hashtag removed. Only the spacing around a removed run
+ * changes: a line that held only tags goes away, a run ending its line takes
+ * the spaces before it, one before punctuation takes its space, and one
* mid-line leaves a single space, so indentation and markdown line breaks
* elsewhere are untouched.
*/
-export const stripHashtags = (text) => String(text || '').replace(HASHTAG_RUN, (match, lead, _trail, offset, whole) => {
+export const stripHashtags = (text) => String(text || '').replace(HASHTAG_RUN, (match, lead, trail, offset, whole) => {
const end = offset + match.length;
const lineStart = offset === 0 || whole[offset - 1] === '\n';
- if (end >= whole.length || whole[end] === '\n' || whole[end] === '\r') return lineStart ? lead : '';
- return lineStart ? lead : (lead ? ' ' : '');
+ const newline = trail.match(/\r?\n$/)?.[0] || '';
+ if (newline || end >= whole.length) return lineStart ? '' : newline;
+ if (lineStart) return lead;
+ return lead && !CLOSING.test(whole.slice(end)) ? ' ' : '';
});
/**
diff --git a/server/services/musicVideo/publishKitText.test.js b/server/services/musicVideo/publishKitText.test.js
index 8d2dd6d4cb..f32355bdf5 100644
--- a/server/services/musicVideo/publishKitText.test.js
+++ b/server/services/musicVideo/publishKitText.test.js
@@ -68,9 +68,10 @@ describe('publish copy prompt + parser (#9281)', () => {
it('strips hashtags the model added unasked and leaves everything else as written', () => {
const description = '# Heading\nA line #tagged here, my #1 take\n - nested item \nSee https://example.com/album/#listen';
- const reply = JSON.stringify({ tiktok: { caption: 'Made this one slowly. #music #aivideo' }, youtube: { title: 'T', description, tags: ['music'] } });
+ const reply = JSON.stringify({ tiktok: { caption: 'Out now #newmusic, link below (#music)\n#a #b\nMade this one slowly. #music #aivideo' }, youtube: { title: 'T', description, tags: ['music'] } });
const copy = parsePublishCopy(reply, ['tiktok', 'youtube'], { hashtags: false });
- expect(copy.tiktok.caption).toBe('Made this one slowly.');
+ // No stray space before punctuation, no empty brackets, no line left holding only tags.
+ expect(copy.tiktok.caption).toBe('Out now, link below\nMade this one slowly.');
// Numbers, URL fragments, headings, indentation and markdown hard breaks survive.
expect(copy.youtube.description).toBe('# Heading\nA line here, my #1 take\n - nested item \nSee https://example.com/album/#listen');
// No tags come back, so a redraft keeps the ones the director typed.