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): verb-bearing exclusions and per-clause format negation
Barack Sokullu11bee5628243
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 8def41ced..3ea6beef5 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -3151,15 +3151,18 @@ export class Agent extends LoopDetector {const normalizeAttachmentFormat = format => (/^jpe?g$/iu.test(format) ? 'jpeg' : String(format || '').toLowerCase());// A coordinated format choice may repeat the cardinality before each// format ("one PNG or one JPEG image"): the shared media noun is still- // omitted, so an optional count is accepted after every conjunction.+ // omitted, so an optional count is accepted after "or". A counted "and"+ // starts a separate quantified clause ("no PNG images and one JPEG+ // image"), so conjunctions other than "or" take no count and negation+ // stays scoped to each repeated format clause.const formatChoiceCountWord = '(?:\\d+|zero|one|two|three|four|five|six|seven|eight|nine|ten|a|an|single|both)';- const imageFormatQualifier = `${IMAGE_ATTACHMENT_FORMAT}(?:\\s*(?:or|and|/|,)\\s*(?:${formatChoiceCountWord}\\s+)?${IMAGE_ATTACHMENT_FORMAT})*`;- const videoFormatQualifier = `${VIDEO_ATTACHMENT_FORMAT}(?:\\s*(?:or|and|/|,)\\s*(?:${formatChoiceCountWord}\\s+)?${VIDEO_ATTACHMENT_FORMAT})*`;+ const imageFormatQualifier = `${IMAGE_ATTACHMENT_FORMAT}(?:\\s*or\\s*(?:${formatChoiceCountWord}\\s+)?${IMAGE_ATTACHMENT_FORMAT}|\\s*(?:and|/|,)\\s*${IMAGE_ATTACHMENT_FORMAT})*`;+ const videoFormatQualifier = `${VIDEO_ATTACHMENT_FORMAT}(?:\\s*or\\s*(?:${formatChoiceCountWord}\\s+)?${VIDEO_ATTACHMENT_FORMAT}|\\s*(?:and|/|,)\\s*${VIDEO_ATTACHMENT_FORMAT})*`;const formatPostfixLead = '(?:in|as)\\s+(?:the\\s+)?';const formatPostfixSuffix = '(?:\\s+formats?)?';const mediaFormatMatchIsNegated = (start) => {const precedingSegment = negationText.slice(0, start)- .split(/(?:[,;]|\\s+(?:and|but|plus|also|as\\s+well\\s+as)\\s+)/iu)+ .split(/(?:[,;]|\s+(?:and|but|plus|also|as\s+well\s+as)\s+)/iu).pop() || '';return /(?<![\p{L}\p{N}_])(?:no(?!\s+(?:more\s+than|fewer\s+than|less\s+than))|not(?!\s+only)(?!\s+(?:more\s+than|fewer\s+than|less\s+than))|without(?:\s+any)?|zero|0)(?![\p{L}\p{N}_])/iu.test(precedingSegment);};@@ -17752,7 +17755,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (publish) {const beforeVerb = c.maskedText.slice(0, publish.index);const afterVerb = c.maskedText.slice(publish.index + publish[0].length);- hasExplicitNeg = socialNegationGovernsPublish(beforeVerb) || socialPostNegationGovernsPublish(afterVerb);+ // An exclusion clause may carry its own publish verb ("except for+ // posting on Bluesky"), so the destination-exclusion matcher runs on+ // verb-bearing clauses too instead of only generic publish negation.+ hasExplicitNeg = socialNegationGovernsPublish(beforeVerb) || socialPostNegationGovernsPublish(afterVerb)+ || SOCIAL_DESTINATION_EXCLUSION.test(c.maskedText);} else {hasExplicitNeg = SOCIAL_NEGATION.test(c.maskedText)|| SOCIAL_DESTINATION_EXCLUSION.test(c.maskedText);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 80cc5fdca..286c0f8fe 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -2866,15 +2866,18 @@ export class Agent extends LoopDetector {const normalizeAttachmentFormat = format => (/^jpe?g$/iu.test(format) ? 'jpeg' : String(format || '').toLowerCase());// A coordinated format choice may repeat the cardinality before each// format ("one PNG or one JPEG image"): the shared media noun is still- // omitted, so an optional count is accepted after every conjunction.+ // omitted, so an optional count is accepted after "or". A counted "and"+ // starts a separate quantified clause ("no PNG images and one JPEG+ // image"), so conjunctions other than "or" take no count and negation+ // stays scoped to each repeated format clause.const formatChoiceCountWord = '(?:\\d+|zero|one|two|three|four|five|six|seven|eight|nine|ten|a|an|single|both)';- const imageFormatQualifier = `${IMAGE_ATTACHMENT_FORMAT}(?:\\s*(?:or|and|/|,)\\s*(?:${formatChoiceCountWord}\\s+)?${IMAGE_ATTACHMENT_FORMAT})*`;- const videoFormatQualifier = `${VIDEO_ATTACHMENT_FORMAT}(?:\\s*(?:or|and|/|,)\\s*(?:${formatChoiceCountWord}\\s+)?${VIDEO_ATTACHMENT_FORMAT})*`;+ const imageFormatQualifier = `${IMAGE_ATTACHMENT_FORMAT}(?:\\s*or\\s*(?:${formatChoiceCountWord}\\s+)?${IMAGE_ATTACHMENT_FORMAT}|\\s*(?:and|/|,)\\s*${IMAGE_ATTACHMENT_FORMAT})*`;+ const videoFormatQualifier = `${VIDEO_ATTACHMENT_FORMAT}(?:\\s*or\\s*(?:${formatChoiceCountWord}\\s+)?${VIDEO_ATTACHMENT_FORMAT}|\\s*(?:and|/|,)\\s*${VIDEO_ATTACHMENT_FORMAT})*`;const formatPostfixLead = '(?:in|as)\\s+(?:the\\s+)?';const formatPostfixSuffix = '(?:\\s+formats?)?';const mediaFormatMatchIsNegated = (start) => {const precedingSegment = negationText.slice(0, start)- .split(/(?:[,;]|\\s+(?:and|but|plus|also|as\\s+well\\s+as)\\s+)/iu)+ .split(/(?:[,;]|\s+(?:and|but|plus|also|as\s+well\s+as)\s+)/iu).pop() || '';return /(?<![\p{L}\p{N}_])(?:no(?!\s+(?:more\s+than|fewer\s+than|less\s+than))|not(?!\s+only)(?!\s+(?:more\s+than|fewer\s+than|less\s+than))|without(?:\s+any)?|zero|0)(?![\p{L}\p{N}_])/iu.test(precedingSegment);};@@ -15551,7 +15554,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (publish) {const beforeVerb = c.maskedText.slice(0, publish.index);const afterVerb = c.maskedText.slice(publish.index + publish[0].length);- hasExplicitNeg = socialNegationGovernsPublish(beforeVerb) || socialPostNegationGovernsPublish(afterVerb);+ // An exclusion clause may carry its own publish verb ("except for+ // posting on Bluesky"), so the destination-exclusion matcher runs on+ // verb-bearing clauses too instead of only generic publish negation.+ hasExplicitNeg = socialNegationGovernsPublish(beforeVerb) || socialPostNegationGovernsPublish(afterVerb)+ || SOCIAL_DESTINATION_EXCLUSION.test(c.maskedText);} else {hasExplicitNeg = SOCIAL_NEGATION.test(c.maskedText)|| SOCIAL_DESTINATION_EXCLUSION.test(c.maskedText);diff --git a/test/run.js b/test/run.jsindex 8eb16478a..f8eeb8b2f 100644--- a/test/run.js+++ b/test/run.js@@ -90841,6 +90841,10 @@ test('social publication workflow follows the live X or Bluesky destination and'an except-for clause adopted its forbidden Bluesky destination'],['Post on Bluesky, except for X', ['bluesky'],'an except-for clause adopted its forbidden X destination'],+ ['Post on X, except for posting on Bluesky', ['twitter'],+ 'a verb-bearing except-for clause adopted its forbidden Bluesky destination'],+ ['Post on Bluesky, excluding publishing on X', ['bluesky'],+ 'a verb-bearing excluding clause adopted its forbidden X destination'],['Post on Bluesky rather than posting on X', ['bluesky'],'rather-than clause adopted its expressly excluded X destination'],['Post on Bluesky rather than on X', ['bluesky'],@@ -93166,6 +93170,15 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'one PNG or one JPEG image' }, { attachments: [image(1), { type: 'image', src: 'https://cdn.example/a.jpg' }] }), false,AgentClass.name + ': two images satisfied a single-image format choice');+ for (const [attachments, expected, message] of [+ [[{ type: 'image', src: 'https://cdn.example/a.jpg' }], true, 'the required JPEG was rejected by a separate PNG prohibition'],+ [[{ type: 'image', src: 'https://cdn.example/a.webp' }], false, 'an unrequested WebP satisfied a required JPEG'],+ [[image(1)], false, 'a prohibited PNG satisfied the JPEG contract'],+ ]) {+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'no PNG images and one JPEG image' }, { attachments },+ ), expected, AgentClass.name + ': ' + message);+ }for (const [attachments, expected, message] of [[[image(1)], true, 'one image alone was rejected by a no-more-than video cap'],[[image(1), video(1)], true, 'one image plus one video was rejected by a no-more-than video cap'],