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
Fix Facebook Fill draft for the current composer and add its AI label
Claude1e5d7e5ab37e
diff --git a/client/src/components/musicVideo/PublishPostingPanel.jsx b/client/src/components/musicVideo/PublishPostingPanel.jsxindex 58e40845b7..b4c097c13e 100644--- a/client/src/components/musicVideo/PublishPostingPanel.jsx+++ b/client/src/components/musicVideo/PublishPostingPanel.jsx@@ -19,7 +19,7 @@ export const PUBLISH_TARGETS = [},{target: 'facebook', label: 'Facebook', accountPlaceholder: 'Your name or Page',- note: 'Your short post with the 1080p video uploaded (Facebook shares it as a reel), and the links in a first comment. Posts as the profile or Page active in the PortOS Browser. You press Post, then open the post: PortOS records the link and types the comment for you to send',+ note: 'Your short post with the 1080p video uploaded (Facebook shares it as a reel) and its AI label on, and the links in a first comment. Posts as the profile or Page active in the PortOS Browser. You press Post, then open the post: PortOS records the link and types the comment for you to send',},{ 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' },@@ -199,11 +199,17 @@ function TargetOptions({ target, kit, project, options, setOption, commitOption,);}if (target === 'linkedin' || target === 'facebook') {- return (- <label className="flex items-center gap-1.5 text-xs min-h-[44px] sm:min-h-0">- <input type="checkbox" checked={options.linksComment !== false} onChange={(e) => setOption('linksComment', e.target.checked)} /> Put the links (full video, song, other posts) in a first comment+ const check = (key, text) => (+ <label key={key} className="flex items-center gap-1.5 text-xs min-h-[44px] sm:min-h-0">+ <input type="checkbox" checked={options[key] !== false} onChange={(e) => setOption(key, e.target.checked)} /> {text}</label>);+ return (+ <div className="flex flex-wrap gap-x-4">+ {check('linksComment', 'Put the links (full video, song, other posts) in a first comment')}+ {target === 'facebook' && check('aiLabel', "Add Facebook's AI label")}+ </div>+ );}if (target === 'stackerNews') {return <div className="grid sm:grid-cols-2 gap-2">{text('territory', 'Territory', 'art')}<div className="sm:col-span-2">{area('firstComment', 'First comment (optional)')}</div></div>;diff --git a/client/src/components/musicVideo/PublishPostingPanel.test.jsx b/client/src/components/musicVideo/PublishPostingPanel.test.jsxindex 3734583b5b..c0ed2a11a8 100644--- a/client/src/components/musicVideo/PublishPostingPanel.test.jsx+++ b/client/src/components/musicVideo/PublishPostingPanel.test.jsx@@ -78,6 +78,18 @@ describe('PublishPostingPanel (#9282)', () => {expect(publishing.prepare).toHaveBeenLastCalledWith(target, { linksComment: false });});+ it('turns on the Facebook AI label unless the director turns it off', () => {+ const publishing = hook();+ render(<PublishPostingPanel project={project()} publishing={publishing} />);+ expandAll();+ const card = row('Facebook');+ const label = within(card).getByLabelText("Add Facebook's AI label");+ expect(label).toBeChecked();+ fireEvent.click(label);+ fireEvent.click(within(card).getByRole('button', { name: 'Fill draft' }));+ expect(publishing.prepare).toHaveBeenLastCalledWith('facebook', { aiLabel: false });+ });+it('picks the X story image from thumbnails, with No image as the default', () => {const publishing = hook();render(<PublishPostingPanel project={project({ thumbnails: ['t1.jpg', 't2.jpg'] })} publishing={publishing} />);diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.jsindex 3e3bb86918..92c365c31d 100644--- a/server/lib/musicVideoValidation.js+++ b/server/lib/musicVideoValidation.js@@ -822,6 +822,8 @@ export const musicVideoPublishPrepareSchema = z.object({firstComment: kitText(10000),// LinkedIn, Facebook: put the full video and song links in a first comment (default on).linksComment: z.boolean(),+ // Facebook: turn on the post's AI label (default on).+ aiLabel: z.boolean(),territory: z.string().max(40),// Substack: the publication (name.substack.com or a custom domain); defaults to the account under Where you post.publication: z.string().trim().min(1).max(200),diff --git a/server/services/musicVideo/publish/facebook.js b/server/services/musicVideo/publish/facebook.jsindex f2c7fee9b0..12dc0af123 100644--- a/server/services/musicVideo/publish/facebook.js+++ b/server/services/musicVideo/publish/facebook.js@@ -5,10 +5,13 @@* director wants them, saved for the first comment instead.** prepare() opens the feed's "What's on your mind" composer, pastes the text,- * attaches the 1080p encode through Photo/video and waits for the upload.- * PortOS never presses Next or Post. The composer posts as whichever profile- * is active in the PortOS Browser, so a Page posts the same way once the- * director switches to it.+ * hands the 1080p encode to the composer's file input (its drop zone holds one+ * from the start; older layouts show it behind a Photo/video button), waits for+ * the upload (the caption box then reads "Describe your reel") and turns on+ * Facebook's AI label unless the director said not to. PortOS never presses+ * Next or Post, and leaves the audience as Facebook has it. The composer posts+ * as whichever profile is active in the PortOS Browser, so a Page posts the+ * same way once the director switches to it.** Facebook stays on the feed after Post. Once the director opens the new post* (its timestamp), findPost records the post's link and, when there is a@@ -29,6 +32,8 @@ const COMMENT_BOX = `${TEXTBOX}[aria-label*="comment" i]`;// Drafts whose first comment was already typed: a reload of the post page must not type it twice.const commented = new WeakSet();const UPLOAD_WAIT_MS = 600_000;+const MEDIA_BUTTON = /Add photos(?:\/| or )videos/i;+const AI_LABEL = /^\s*Add AI label/i;// A post's own page: a reel (every uploaded video), a video, a post, or a permalink.const POST_URL = /^https:\/\/(?:www|web|m)\.facebook\.com\/(?:reel\/\d+|[\w.-]+\/(?:posts|videos)\/[\w.-]+|permalink\.php\?[^#]*story_fbid=[\w-]+[^#]*|watch\/?\?v=\d+)/;@@ -59,10 +64,14 @@ async function pasteInto(page, locator, text) {}}-/** Whether the composer is done uploading: no progress bar or Uploading/Processing note. */+/**+ * Whether the composer is done uploading: an "Uploaded media" section with a+ * Remove video button, and no Uploading/Processing note or progress bar.+ */async function uploadSettled(page) {const composer = page.locator(COMPOSER).last();- if (!(await composer.locator('video, img').count())) return false;+ if (!(await page.locator(COMPOSER).filter({ hasText: /Uploaded media/i }).count())) return false;+ if (!(await button(composer, 'Remove video').count())) return false;if (await composer.locator('[role=progressbar], progress').count()) return false;return !(await page.locator(COMPOSER).filter({ hasText: /Uploading|Processing/i }).count());}@@ -80,21 +89,37 @@ async function openComposer(page) {async function attachVideo(page, video) {await step(label, 'attach the video', async () => {const composer = page.locator(COMPOSER).last();- // Photo/video opens the composer's media area, which holds the file input.- await button(composer, 'Photo/video').click({ timeout: T });const input = composer.locator('input[type=file]').first();- if (await input.waitFor({ state: 'attached', timeout: 10_000 }).then(() => true, () => false)) {+ const hasInput = () => input.waitFor({ state: 'attached', timeout: 5000 }).then(() => true, () => false);+ // The drop zone's input is there from the start; an older layout adds it behind Photo/video.+ if (!(await hasInput())) await button(composer, 'Photo/video').click({ timeout: 10_000 }).catch(() => {});+ if (await hasInput()) {await input.setInputFiles(video.path);return;}const [chooser] = await Promise.all([page.waitForEvent('filechooser', { timeout: T }),- composer.locator('[role=button]', { hasText: /Add photos\/videos/i }).first().click({ timeout: T }),+ composer.locator('[role=button]', { hasText: MEDIA_BUTTON }).first().click({ timeout: T }),]);await chooser.setFiles(video.path);});}+/**+ * Turn on the composer's "Add AI label" row. Its switch has no useful name+ * ("Off"), so the row is found by its text and the switch inside it read for+ * its state. Resolves 'On', or null when the row is missing or did not turn on.+ */+async function labelAsAi(composer) {+ const row = composer.locator('[role=button]').filter({ hasText: AI_LABEL }).first();+ if (!(await row.count())) return null;+ const toggle = row.locator('[role=switch]').first();+ const on = async () => (await toggle.getAttribute('aria-checked', { timeout: 5000 }).catch(() => null)) === 'true';+ if (await on()) return 'On';+ await ((await toggle.count()) ? toggle : row).click({ timeout: 10_000 });+ return (await on()) ? 'On' : null;+}+/** Type `text` into the open post's comment box (never sent: the director presses Enter). */export const typeFacebookComment = (page, text) => pasteInto(page, page.locator(COMMENT_BOX).first(), text);@@ -115,10 +140,15 @@ export const facebookAdapter = {}});const composer = page.locator(COMPOSER).last();+ const aiLabel = payload.aiLabel === false ? 'Off (you chose)'+ // A miss never fails the draft: the summary asks the director to turn it on.+ : (await labelAsAi(composer).catch(() => null)) || 'Not turned on: switch on Add AI label yourself';const length = await composer.locator(TEXTBOX).first().innerText().then((t) => t.trim().length, () => null);const next = await button(composer, 'Next').count().catch(() => 0);return {characters: length,+ aiLabel,+ audience: 'As Facebook has it (check Post audience)',// A video post may ask for Next (post settings) before Post; neither is pressed here.youPress: next ? 'Next, then Post' : 'Post',firstComment: payload.firstComment ? 'Typed into the comment box once you press Post and open the post' : null,diff --git a/server/services/musicVideo/publish/facebook.test.js b/server/services/musicVideo/publish/facebook.test.jsindex 994fbc779e..3201e69a8e 100644--- a/server/services/musicVideo/publish/facebook.test.js+++ b/server/services/musicVideo/publish/facebook.test.js@@ -6,11 +6,16 @@import { describe, expect, it, vi } from 'vitest';import { facebookAdapter } from './facebook.js';-// A page whose elements exist only for locators, logging every click, paste and file.-function fakePage({ url = 'https://www.facebook.com/', shows = '', signedOut = false, nextButton = false } = {}) {+// A page whose elements exist only for locators, logging every click, paste and+// file. Like Facebook's composer (2026), the drop zone's file input is there+// from the start, the upload ends in an "Uploaded media" section with Remove+// video, and the AI label row holds an unnamed switch.+function fakePage({ url = 'https://www.facebook.com/', shows = '', signedOut = false, nextButton = false, inputPresent = true, aiRow = true } = {}) {const log = [];const typed = {};let uploaded = false;+ let photoVideoOpened = false;+ let aiOn = false;const element = (sel, name) => {const el = {first: () => el,@@ -21,12 +26,18 @@ function fakePage({ url = 'https://www.facebook.com/', shows = '', signedOut = fcount: async () => {if (/input\[name=pass\]/.test(sel)) return signedOut ? 1 : 0;if (/progressbar/.test(sel)) return 0;- if (/video, img/.test(sel)) return uploaded ? 1 : 0;+ if (/Uploaded media/.test(String(name)) || name === 'Remove video') return uploaded ? 1 : 0;+ if (/AI label/.test(String(name))) return aiRow ? 1 : 0;if (name === 'Next') return nextButton ? 1 : 0;return /Uploading/.test(String(name)) ? 0 : 1;},- waitFor: async () => {},- click: async () => { log.push(['click', name || sel]); },+ waitFor: async () => { if (/input\[type=file\]/.test(sel) && !inputPresent && !photoVideoOpened) throw new Error('timeout'); },+ getAttribute: async () => String(aiOn),+ click: async () => {+ log.push(['click', name || sel]);+ if (name === 'Photo/video') photoVideoOpened = true;+ if (/AI label/.test(String(name))) aiOn = true;+ },setInputFiles: async (path) => { log.push(['setFiles', path]); uploaded = true; },evaluate: async (_fn, text) => { typed[sel] = text; log.push(['paste', sel, text]); },innerText: async () => typed[sel] || '',@@ -47,16 +58,27 @@ function fakePage({ url = 'https://www.facebook.com/', shows = '', signedOut = fconst payload = { video: { path: '/videos/x.mp4' }, text: 'I made a music video.\n\nMore.', firstComment: 'Full video: https://youtu.be/abc' };describe('Facebook adapter', () => {- it('writes the post and uploads the video, never pressing Next or Post', async () => {+ it('writes the post, hands the video to the drop zone and turns on the AI label, never pressing Next or Post', async () => {const page = fakePage({ nextButton: true });- const summary = await facebookAdapter.prepare(page, payload);+ const summary = await facebookAdapter.prepare(page, { ...payload, aiLabel: true });expect(page.log[0]).toEqual(['goto', 'https://www.facebook.com/']);expect(page.log).toContainEqual(['click', 'on your mind']);- expect(page.log).toContainEqual(['click', 'Photo/video']);expect(page.log).toContainEqual(['setFiles', '/videos/x.mp4']);+ expect(page.log.some(([, what]) => what === 'Photo/video')).toBe(false);expect(page.log.find(([kind]) => kind === 'paste')[2]).toBe(payload.text);expect(page.log.some(([kind, what]) => kind === 'click' && /^(Post|Next)$/.test(what))).toBe(false);- expect(summary).toMatchObject({ characters: payload.text.length, youPress: 'Next, then Post', firstComment: expect.stringMatching(/open the post/) });+ expect(summary).toMatchObject({ characters: payload.text.length, aiLabel: 'On', youPress: 'Next, then Post', firstComment: expect.stringMatching(/open the post/) });+ });++ it('opens Photo/video when the composer has no file input yet, and leaves a missing AI label to the director', async () => {+ const page = fakePage({ inputPresent: false, aiRow: false });+ const summary = await facebookAdapter.prepare(page, { ...payload, aiLabel: true });+ expect(page.log).toContainEqual(['click', 'Photo/video']);+ expect(page.log).toContainEqual(['setFiles', '/videos/x.mp4']);+ expect(summary.aiLabel).toMatch(/yourself/);+ const off = fakePage();+ expect((await facebookAdapter.prepare(off, { ...payload, aiLabel: false })).aiLabel).toMatch(/Off/);+ expect(off.log.some(([, what]) => /AI label/.test(what))).toBe(false);});it('asks for sign-in when Facebook shows its login form', async () => {diff --git a/server/services/musicVideo/publish/payloads.js b/server/services/musicVideo/publish/payloads.jsindex aa027f66a6..a28731454b 100644--- a/server/services/musicVideo/publish/payloads.js+++ b/server/services/musicVideo/publish/payloads.js@@ -235,7 +235,8 @@ const BUILDERS = {const post = text(kit.copy?.facebook?.post);if (!post) throw missing('Write the Facebook post in the release copy first');if (post.length > FACEBOOK_POST_MAX) throw missing(`The Facebook post is ${post.length} characters; the limit is ${FACEBOOK_POST_MAX}`);- return { video: nativeVideo(project, kit, 'Facebook'), text: post, ...linksComment(kit, options, 'facebook') };+ // Facebook's own "AI label" on the post: on unless the director turns it off (like TikTok's and Instagram's).+ return { video: nativeVideo(project, kit, 'Facebook'), text: post, aiLabel: options.aiLabel !== false, ...linksComment(kit, options, 'facebook') };},reddit: (project, kit, options = {}) => {// r/aivideo is the default (#9307): a native video post, title + flair, no@@ -414,6 +415,7 @@ export function publishPreviewParts(platform, project, payload) {case 'facebook':add('Video', 'The 1080p encode of the final render');add('Post', p.text);+ if (platform === 'facebook') add('AI label', yesNo(p.aiLabel));add(platform === 'facebook' ? 'First comment (you press Enter)' : 'First comment (you press Comment)', p.firstComment);break;case 'reddit':diff --git a/server/services/musicVideo/publish/payloads.test.js b/server/services/musicVideo/publish/payloads.test.jsindex d255211a90..89f7c7e1d5 100644--- a/server/services/musicVideo/publish/payloads.test.js+++ b/server/services/musicVideo/publish/payloads.test.js@@ -65,12 +65,12 @@ describe('buildPublishPayload (#9282)', () => {const posted = project({ copy: { facebook: { post: 'I made a music video.' } }, posts: { x: { url: 'https://x.com/example/status/42' }, facebook: { url: 'https://www.facebook.com/reel/1' } } });const p = buildPublishPayload('facebook', posted);expect(p).toEqual({- video: { dir: 'videos', name: 'x.mp4' }, text: 'I made a music video.',+ video: { dir: 'videos', name: 'x.mp4' }, text: 'I made a music video.', aiLabel: true,firstComment: 'Full video: https://youtu.be/abc\nThe song: https://suno.com/song/12345678-abcd-4abc-8abc-123456789abc\nX: https://x.com/example/status/42',crossLinks: ['youtube', 'suno', 'x'],});- expect(publishPreviewParts('facebook', posted, p).map((r) => r.label)).toEqual(['Video', 'Post', 'First comment (you press Enter)']);- expect(buildPublishPayload('facebook', posted, { linksComment: false })).toMatchObject({ firstComment: null, crossLinks: [] });+ expect(publishPreviewParts('facebook', posted, p).map((r) => r.label)).toEqual(['Video', 'Post', 'AI label', 'First comment (you press Enter)']);+ expect(buildPublishPayload('facebook', posted, { linksComment: false, aiLabel: false })).toMatchObject({ firstComment: null, crossLinks: [], aiLabel: false });expect(() => buildPublishPayload('facebook', project())).toThrow(/Facebook post/);});