Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix(social-publish): scope live and enumerated choices
Barack Sokullu9ef03f909f2b
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex feaaf628a..64ba1dd17 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -3614,11 +3614,37 @@ export class Agent extends LoopDetector {: [];const commaMediaDisjunction = new RegExp(`[,;]\\s*${COUNT_DISJUNCTION_PATTERN}\\s+`, 'iu');const leadingMediaDisjunction = new RegExp(`^${COUNT_DISJUNCTION_PATTERN}\\s*`, 'iu');- const commaMediaBranches = isGeneric && commaMediaDisjunction.test(text)+ let commaMediaBranches = isGeneric && commaMediaDisjunction.test(text)? text.replace(/^either\s+/iu, '').split(/\s*[,;]\s*/u).map(branch => branch.replace(leadingMediaDisjunction, '').trim()).filter(Boolean): [];+ if (commaMediaBranches.length > 1) {+ const scopedEither = commaMediaBranches[0].match(+ new RegExp(`(?<![${SOCIAL_WORD_EDGE}])either(?![${SOCIAL_WORD_EDGE}])`, 'iu'),+ );+ let sharedPrefix = '';+ if (scopedEither) {+ sharedPrefix = commaMediaBranches[0].slice(0, scopedEither.index || 0)+ .replace(/(?:\s*[,;]\s*)?(?:and|plus|also|as\s+well\s+as)\s*$/iu, '')+ .trim();+ commaMediaBranches[0] = commaMediaBranches[0]+ .slice((scopedEither.index || 0) + scopedEither[0].length)+ .trim();+ }+ let sharedSuffix = '';+ const lastBranch = commaMediaBranches[commaMediaBranches.length - 1];+ const sharedSuffixMatch = lastBranch.match(/^(?:and|plus|also|as\s+well\s+as)\s+([\s\S]+)$/iu);+ if (sharedSuffixMatch) {+ sharedSuffix = sharedSuffixMatch[1].trim();+ commaMediaBranches.pop();+ }+ if (sharedPrefix || sharedSuffix) {+ commaMediaBranches = commaMediaBranches.map(choice => (+ [sharedPrefix, choice, sharedSuffix].filter(Boolean).join(' and ')+ ));+ }+ }const enumeratedMediaBranches = oneOfMediaBranches.length > 1? oneOfMediaBranches: commaMediaBranches;@@ -17711,13 +17737,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d&& current.job.template === 'publish'&& current.job.requiresSubmission === true&& ['twitter', 'bluesky'].includes(current.adapterName);- if (currentIsSocialPublish) targets.add(current.adapterName);const trustedContext = [guard?.taskText, guard?.approvedPlanAnchor].map(value => String(value || '').trim()).filter(Boolean).join(' ');const hasPublishIntent = this._socialPublicationCommandIn(trustedContext);const clauses = this._socialPublicationClauses(trustedContext);+ const currentPlatformPattern = current?.adapterName === 'twitter'+ ? /(?<![\p{L}\p{N}_])(?:x|x\.com|twitter(?:\.com)?)(?![\p{L}\p{N}_])/iu+ : /(?<![\p{L}\p{N}_])(?:bluesky|bsky(?:\.app)?)(?![\p{L}\p{N}_])/iu;+ const currentIsExplicitlyExcluded = currentIsSocialPublish && clauses.some(clause => (+ clause.isNegated && currentPlatformPattern.test(clause.maskedText || clause.text || '')+ ));const hasContrastivePublishIntent = clauses.some((clause, index) => (index > 0&& /^(?:but)$/iu.test(clause.delim || '')@@ -17805,7 +17836,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst publishesTo = (platform) => {const destPreps = '(?:on|onto|to|via|in|at|en|sur|sobre|\u00e0|au|auf|su|em|na|no|nos|nas|para|\u0432|\u043d\u0430)';const coordConj = '(?:and|und|et|e|y|ve|и|oder|or|ou|o|as\\s+well\\s+as|&|\\/)';- const listModifiers = '(?:both|either|all|ambos|ambas|entrambi|entrambe|beide|beiden|les\\s+deux|tous\\s+les\\s+deux|\u043e\u0431\u0430|\u043e\u0431\u0435|\u4e24\u8005|\u4e24\u4e2a|\u4e24|\u4e21\u65b9|\u4e21\u8005|\u4e21|\ub458\\s*\ub2e4|\ub458|\uc591\uc790|\uc591)';+ const listModifiers = '(?:both|either|all|one\\s+of(?:\\s+the)?|ambos|ambas|entrambi|entrambe|beide|beiden|les\\s+deux|tous\\s+les\\s+deux|\u043e\u0431\u0430|\u043e\u0431\u0435|\u4e24\u8005|\u4e24\u4e2a|\u4e24|\u4e21\u65b9|\u4e21\u8005|\u4e21|\ub458\\s*\ub2e4|\ub458|\uc591\uc790|\uc591)';const coordItem = `(?:the\\s+)?(?:${listModifiers}\\s+)?[a-z0-9_.-]+(?:\\s+page|\\s+account|\\s+profile)?`;const coordPrefix = `(?:${coordItem}(?:\\s*,\\s*${coordItem})*\\s*(?:,\\s*${coordConj}|,|;|\\s+${coordConj})\\s+(?:the\\s+)?)`;const platformPattern = new RegExp(@@ -17997,6 +18028,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d|| tweetsThis) {targets.add('twitter');}+ // The live tab is a fallback only when the task did not authorize another+ // destination. Never let it override an explicit negative platform clause.+ if (currentIsSocialPublish && targets.size < 1 && !currentIsExplicitlyExcluded) {+ targets.add(current.adapterName);+ }return targets;}diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex a505c1629..a491cc7ad 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -3329,11 +3329,37 @@ export class Agent extends LoopDetector {: [];const commaMediaDisjunction = new RegExp(`[,;]\\s*${COUNT_DISJUNCTION_PATTERN}\\s+`, 'iu');const leadingMediaDisjunction = new RegExp(`^${COUNT_DISJUNCTION_PATTERN}\\s*`, 'iu');- const commaMediaBranches = isGeneric && commaMediaDisjunction.test(text)+ let commaMediaBranches = isGeneric && commaMediaDisjunction.test(text)? text.replace(/^either\s+/iu, '').split(/\s*[,;]\s*/u).map(branch => branch.replace(leadingMediaDisjunction, '').trim()).filter(Boolean): [];+ if (commaMediaBranches.length > 1) {+ const scopedEither = commaMediaBranches[0].match(+ new RegExp(`(?<![${SOCIAL_WORD_EDGE}])either(?![${SOCIAL_WORD_EDGE}])`, 'iu'),+ );+ let sharedPrefix = '';+ if (scopedEither) {+ sharedPrefix = commaMediaBranches[0].slice(0, scopedEither.index || 0)+ .replace(/(?:\s*[,;]\s*)?(?:and|plus|also|as\s+well\s+as)\s*$/iu, '')+ .trim();+ commaMediaBranches[0] = commaMediaBranches[0]+ .slice((scopedEither.index || 0) + scopedEither[0].length)+ .trim();+ }+ let sharedSuffix = '';+ const lastBranch = commaMediaBranches[commaMediaBranches.length - 1];+ const sharedSuffixMatch = lastBranch.match(/^(?:and|plus|also|as\s+well\s+as)\s+([\s\S]+)$/iu);+ if (sharedSuffixMatch) {+ sharedSuffix = sharedSuffixMatch[1].trim();+ commaMediaBranches.pop();+ }+ if (sharedPrefix || sharedSuffix) {+ commaMediaBranches = commaMediaBranches.map(choice => (+ [sharedPrefix, choice, sharedSuffix].filter(Boolean).join(' and ')+ ));+ }+ }const enumeratedMediaBranches = oneOfMediaBranches.length > 1? oneOfMediaBranches: commaMediaBranches;@@ -15510,13 +15536,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d&& current.job.template === 'publish'&& current.job.requiresSubmission === true&& ['twitter', 'bluesky'].includes(current.adapterName);- if (currentIsSocialPublish) targets.add(current.adapterName);const trustedContext = [guard?.taskText, guard?.approvedPlanAnchor].map(value => String(value || '').trim()).filter(Boolean).join(' ');const hasPublishIntent = this._socialPublicationCommandIn(trustedContext);const clauses = this._socialPublicationClauses(trustedContext);+ const currentPlatformPattern = current?.adapterName === 'twitter'+ ? /(?<![\p{L}\p{N}_])(?:x|x\.com|twitter(?:\.com)?)(?![\p{L}\p{N}_])/iu+ : /(?<![\p{L}\p{N}_])(?:bluesky|bsky(?:\.app)?)(?![\p{L}\p{N}_])/iu;+ const currentIsExplicitlyExcluded = currentIsSocialPublish && clauses.some(clause => (+ clause.isNegated && currentPlatformPattern.test(clause.maskedText || clause.text || '')+ ));const hasContrastivePublishIntent = clauses.some((clause, index) => (index > 0&& /^(?:but)$/iu.test(clause.delim || '')@@ -15604,7 +15635,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst publishesTo = (platform) => {const destPreps = '(?:on|onto|to|via|in|at|en|sur|sobre|\u00e0|au|auf|su|em|na|no|nos|nas|para|\u0432|\u043d\u0430)';const coordConj = '(?:and|und|et|e|y|ve|и|oder|or|ou|o|as\\s+well\\s+as|&|\\/)';- const listModifiers = '(?:both|either|all|ambos|ambas|entrambi|entrambe|beide|beiden|les\\s+deux|tous\\s+les\\s+deux|\u043e\u0431\u0430|\u043e\u0431\u0435|\u4e24\u8005|\u4e24\u4e2a|\u4e24|\u4e21\u65b9|\u4e21\u8005|\u4e21|\ub458\\s*\ub2e4|\ub458|\uc591\uc790|\uc591)';+ const listModifiers = '(?:both|either|all|one\\s+of(?:\\s+the)?|ambos|ambas|entrambi|entrambe|beide|beiden|les\\s+deux|tous\\s+les\\s+deux|\u043e\u0431\u0430|\u043e\u0431\u0435|\u4e24\u8005|\u4e24\u4e2a|\u4e24|\u4e21\u65b9|\u4e21\u8005|\u4e21|\ub458\\s*\ub2e4|\ub458|\uc591\uc790|\uc591)';const coordItem = `(?:the\\s+)?(?:${listModifiers}\\s+)?[a-z0-9_.-]+(?:\\s+page|\\s+account|\\s+profile)?`;const coordPrefix = `(?:${coordItem}(?:\\s*,\\s*${coordItem})*\\s*(?:,\\s*${coordConj}|,|;|\\s+${coordConj})\\s+(?:the\\s+)?)`;const platformPattern = new RegExp(@@ -15796,6 +15827,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d|| tweetsThis) {targets.add('twitter');}+ // The live tab is a fallback only when the task did not authorize another+ // destination. Never let it override an explicit negative platform clause.+ if (currentIsSocialPublish && targets.size < 1 && !currentIsExplicitlyExcluded) {+ targets.add(current.adapterName);+ }return targets;}diff --git a/test/run.js b/test/run.jsindex 45f92a7dc..9168566b4 100644--- a/test/run.js+++ b/test/run.js@@ -91053,6 +91053,23 @@ test('social publication workflow follows the live X or Bluesky destination and);}+ const liveTwitterWorkflow = agent._resolvePlannerSiteWorkflow('https://x.com/compose/post', {+ request_kind: 'execute',+ site_job: 'publish-post',+ });+ assert.deepEqual([...agent._trustedSocialPublishTargetAdapters({+ taskText: 'Post on Bluesky, not X',+ siteWorkflow: liveTwitterWorkflow,+ })], ['bluesky'], AgentClass.name + ': an explicitly excluded live X workflow was seeded as authorized');+ const liveBlueskyWorkflow = agent._resolvePlannerSiteWorkflow('https://bsky.app/', {+ request_kind: 'execute',+ site_job: 'publish-post',+ });+ assert.deepEqual([...agent._trustedSocialPublishTargetAdapters({+ taskText: 'Post on X, not Bluesky',+ siteWorkflow: liveBlueskyWorkflow,+ })], ['twitter'], AgentClass.name + ': an explicitly excluded live Bluesky workflow was seeded as authorized');+const genericTabId = tabId + 300;agent.conversations.set(genericTabId, [{ role: 'system', content: 'system' },@@ -93128,6 +93145,30 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {'one video and one image','one gif and one image',], AgentClass.name + ': shared media suffix was not distributed into every scoped alternative');+ const enumeratedSharedChoice = agent._parseWorkflowAttachmentRequirement(+ 'one image and either one video, one GIF, or two videos',+ );+ assert.deepEqual(enumeratedSharedChoice.mediaAlternativeBranches.map(branch => branch.normalized), [+ 'one image and one video',+ 'one image and one gif',+ 'one image and two videos',+ ], AgentClass.name + ': shared conjunct was lost from comma-enumerated media alternatives');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one image and either one video, one GIF, or two videos' },+ { attachments: [image(1), gif(1)] },+ ), true, AgentClass.name + ': valid image-plus-GIF enumerated choice was rejected');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one image and either one video, one GIF, or two videos' },+ { attachments: [gif(1)] },+ ), false, AgentClass.name + ': GIF-only evidence omitted the enumerated shared image conjunct');+ const enumeratedSharedSuffix = agent._parseWorkflowAttachmentRequirement(+ 'either one video, one GIF, or two videos, and one image',+ );+ assert.deepEqual(enumeratedSharedSuffix.mediaAlternativeBranches.map(branch => branch.normalized), [+ 'one video and one image',+ 'one gif and one image',+ 'two videos and one image',+ ], AgentClass.name + ': shared suffix was lost from comma-enumerated media alternatives');const neitherVideoNorGif = agent._parseWorkflowAttachmentRequirement('one image but neither a video nor a GIF',);