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 destination and file alternatives
Barack Sokulluf409166ab7fc
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 47d9ba507..41cffd26a 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -3299,13 +3299,26 @@ export class Agent extends LoopDetector {// Word joiners need surrounding whitespace so a filename such as// report-or-draft.png remains one target. CJK joiners need no spaces.const disjunctionSplit = /(?:\s+(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+|\s*(?:或者|或|または|それとも|또는|혹은)\s*)/iu;- const specificTargetAlternatives = DISJUNCTION_REGEX.test(text)+ let specificTargetAlternatives = DISJUNCTION_REGEX.test(text)? this._parseSpecificAttachmentTargets(rawVal, disjunctionSplit)- .map(group => this._parseSpecificAttachmentTargets(- group.replace(/^(?:either|one\s+of)\s+/iu, ''),- ))+ .map(group => this._parseSpecificAttachmentTargets(group)).filter(group => group.length > 0): [];+ // In "logo.png and either chart.png or graph.png", `either` scopes the+ // choice while everything before it remains a requirement in both+ // branches. Distribute that shared prefix instead of parsing ordinary+ // AND-before-OR precedence and accidentally accepting graph.png alone.+ if (specificTargetAlternatives.length > 1) {+ const eitherIndex = specificTargetAlternatives[0]+ .findIndex(target => /^(?:either|one\s+of)\s+/iu.test(target));+ if (eitherIndex >= 0) {+ const sharedPrefix = specificTargetAlternatives[0].slice(0, eitherIndex);+ const firstChoice = specificTargetAlternatives[0].slice(eitherIndex);+ firstChoice[0] = firstChoice[0].replace(/^(?:either|one\s+of)\s+/iu, '');+ specificTargetAlternatives = [firstChoice, ...specificTargetAlternatives.slice(1)]+ .map(group => [...sharedPrefix, ...group]);+ }+ }if (specificTargetAlternatives.length > 1) {expectedCount = Math.min(...specificTargetAlternatives.map(group => group.length));hasExplicitGenericCount = true;@@ -17205,7 +17218,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d? knownTargets: this._trustedSocialPublishTargetAdapters(guard);if (targets.size < 2 || !targets.has('twitter') || !targets.has('bluesky')) return false;- const alternativeJoiner = /(?<![\p{L}\p{N}_])(?:or|either|oder|ou|o|oppure|veya|ya\s+da|(?:\u0438\u043b\u0438)|(?:\u043b\u0438\u0431\u043e))(?![\p{L}\p{N}_])|(?:\u6216\u8005|\u6216|\u307e\u305f\u306f|\u305d\u308c\u3068\u3082|\uB610\uB294|\uD639\uC740)/iu;+ // Only list-shaped glue may sit between the two platform mentions. An+ // unrelated branch such as "X or report the blocker; also post on+ // Bluesky" contains `or`, but it does not coordinate the destinations.+ const directAlternativeBridge = /^\s*(?:(?:page|account|profile)\s*)?(?:,\s*)?(?:(?:or|oder|ou|o|oppure|veya|ya\s+da|\u0438\u043b\u0438|\u043b\u0438\u0431\u043e)(?![\p{L}\p{N}_])|(?:\u6216\u8005|\u6216|\u307e\u305f\u306f|\u305d\u308c\u3068\u3082|\uB610\uB294|\uD639\uC740))\s*(?:(?:post|publish|share|tweet|send|reply|respond)\s+)?(?:(?:also\s+)?(?:on|onto|to|via|in|at|en|sur|sobre|\u00e0|au|auf|su|em|na|no|nos|nas|para|\u0432|\u043d\u0430)\s+)?(?:the\s+)?$/iu;const platformPattern = /(?:https?:\/\/(?:www\.)?(?:x\.com|twitter\.com|bsky\.app)(?:[/?#]|$)|(?<![\p{L}\p{N}_])(?:x|twitter|bluesky|bsky\.app)(?![\p{L}\p{N}_]))/giu;const texts = [guard?.taskText, guard?.approvedPlanAnchor].map(value => String(value || '').trim())@@ -17221,7 +17237,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst left = platforms[index - 1];const right = platforms[index];if (left.name === right.name) continue;- if (alternativeJoiner.test(masked.slice(left.end, right.index))) return true;+ if (directAlternativeBridge.test(masked.slice(left.end, right.index))) return true;}return false;});diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 7c6d936ea..52f7e750a 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -3014,13 +3014,26 @@ export class Agent extends LoopDetector {// Word joiners need surrounding whitespace so a filename such as// report-or-draft.png remains one target. CJK joiners need no spaces.const disjunctionSplit = /(?:\s+(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+|\s*(?:或者|或|または|それとも|또는|혹은)\s*)/iu;- const specificTargetAlternatives = DISJUNCTION_REGEX.test(text)+ let specificTargetAlternatives = DISJUNCTION_REGEX.test(text)? this._parseSpecificAttachmentTargets(rawVal, disjunctionSplit)- .map(group => this._parseSpecificAttachmentTargets(- group.replace(/^(?:either|one\s+of)\s+/iu, ''),- ))+ .map(group => this._parseSpecificAttachmentTargets(group)).filter(group => group.length > 0): [];+ // In "logo.png and either chart.png or graph.png", `either` scopes the+ // choice while everything before it remains a requirement in both+ // branches. Distribute that shared prefix instead of parsing ordinary+ // AND-before-OR precedence and accidentally accepting graph.png alone.+ if (specificTargetAlternatives.length > 1) {+ const eitherIndex = specificTargetAlternatives[0]+ .findIndex(target => /^(?:either|one\s+of)\s+/iu.test(target));+ if (eitherIndex >= 0) {+ const sharedPrefix = specificTargetAlternatives[0].slice(0, eitherIndex);+ const firstChoice = specificTargetAlternatives[0].slice(eitherIndex);+ firstChoice[0] = firstChoice[0].replace(/^(?:either|one\s+of)\s+/iu, '');+ specificTargetAlternatives = [firstChoice, ...specificTargetAlternatives.slice(1)]+ .map(group => [...sharedPrefix, ...group]);+ }+ }if (specificTargetAlternatives.length > 1) {expectedCount = Math.min(...specificTargetAlternatives.map(group => group.length));hasExplicitGenericCount = true;@@ -15004,7 +15017,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d? knownTargets: this._trustedSocialPublishTargetAdapters(guard);if (targets.size < 2 || !targets.has('twitter') || !targets.has('bluesky')) return false;- const alternativeJoiner = /(?<![\p{L}\p{N}_])(?:or|either|oder|ou|o|oppure|veya|ya\s+da|(?:\u0438\u043b\u0438)|(?:\u043b\u0438\u0431\u043e))(?![\p{L}\p{N}_])|(?:\u6216\u8005|\u6216|\u307e\u305f\u306f|\u305d\u308c\u3068\u3082|\uB610\uB294|\uD639\uC740)/iu;+ // Only list-shaped glue may sit between the two platform mentions. An+ // unrelated branch such as "X or report the blocker; also post on+ // Bluesky" contains `or`, but it does not coordinate the destinations.+ const directAlternativeBridge = /^\s*(?:(?:page|account|profile)\s*)?(?:,\s*)?(?:(?:or|oder|ou|o|oppure|veya|ya\s+da|\u0438\u043b\u0438|\u043b\u0438\u0431\u043e)(?![\p{L}\p{N}_])|(?:\u6216\u8005|\u6216|\u307e\u305f\u306f|\u305d\u308c\u3068\u3082|\uB610\uB294|\uD639\uC740))\s*(?:(?:post|publish|share|tweet|send|reply|respond)\s+)?(?:(?:also\s+)?(?:on|onto|to|via|in|at|en|sur|sobre|\u00e0|au|auf|su|em|na|no|nos|nas|para|\u0432|\u043d\u0430)\s+)?(?:the\s+)?$/iu;const platformPattern = /(?:https?:\/\/(?:www\.)?(?:x\.com|twitter\.com|bsky\.app)(?:[/?#]|$)|(?<![\p{L}\p{N}_])(?:x|twitter|bluesky|bsky\.app)(?![\p{L}\p{N}_]))/giu;const texts = [guard?.taskText, guard?.approvedPlanAnchor].map(value => String(value || '').trim())@@ -15020,7 +15036,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst left = platforms[index - 1];const right = platforms[index];if (left.name === right.name) continue;- if (alternativeJoiner.test(masked.slice(left.end, right.index))) return true;+ if (directAlternativeBridge.test(masked.slice(left.end, right.index))) return true;}return false;});diff --git a/test/run.js b/test/run.jsindex 16433f7bb..c803daa4f 100644--- a/test/run.js+++ b/test/run.js@@ -91193,6 +91193,18 @@ test('alternative social destinations require one verified publication, not everassert.equal(agent._socialPublishTargetsAreAlternatives(conjunctive), false);assert.deepEqual(agent._missingSocialPublishTargets(conjunctive), ['bluesky'],AgentClass.name + ': conjunctive destinations were weakened to alternatives');+ const unrelatedOr = {+ ...guard,+ taskText: 'Post on X or report the blocker; also post on Bluesky.',+ };+ assert.equal(agent._socialPublishTargetsAreAlternatives(unrelatedOr), false,+ AgentClass.name + ': unrelated or branch weakened two required destinations');+ assert.deepEqual(agent._missingSocialPublishTargets(unrelatedOr), ['bluesky'],+ AgentClass.name + ': unrelated or branch hid the missing Bluesky publication');+ assert.equal(agent._socialPublishTargetsAreAlternatives({+ ...guard,+ taskText: 'Post on X or publish on Bluesky.',+ }), true, AgentClass.name + ': directly repeated publish verb broke a destination alternative');}});@@ -93300,6 +93312,33 @@ test('attachment verification matches specific attachment names without substrinfalse,AgentClass.name + ': incomplete conjunctive alternative group was accepted',);+ const sharedConjunctAlternatives = agent._parseWorkflowAttachmentRequirement(+ 'logo.png and either chart.png or graph.png',+ );+ assert.deepEqual(sharedConjunctAlternatives.specificTargetAlternatives,+ [['logo.png', 'chart.png'], ['logo.png', 'graph.png']],+ AgentClass.name + ': shared conjunct was not retained in every explicit either/or branch');+ assert.equal(+ agent._workflowSocialPublishedAttachmentObserved(+ { value: 'logo.png and either chart.png or graph.png' },+ {+ attachments: [+ { type: 'image', src: 'https://pbs.twimg.com/media/logo.png' },+ { type: 'image', src: 'https://pbs.twimg.com/media/chart.png' },+ ],+ },+ ),+ true,+ AgentClass.name + ': valid shared-conjunct alternative was rejected',+ );+ assert.equal(+ agent._workflowSocialPublishedAttachmentObserved(+ { value: 'logo.png and either chart.png or graph.png' },+ { attachments: [{ type: 'image', src: 'https://pbs.twimg.com/media/graph.png' }] },+ ),+ false,+ AgentClass.name + ': alternative file alone satisfied a missing shared conjunct',+ );for (const [allowedName, type] of [['chart.png', 'image'], ['clip.mp4', 'video']]) {assert.equal(agent._workflowSocialPublishedAttachmentObserved(