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): enforce exclusions and GIF typing
Barack Sokulluda882488fad2
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 015f38381..aeb060a22 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -261,6 +261,7 @@ const SOCIAL_POST_DESTINATION_NEGATION = new RegExp('iu',);const SOCIAL_CONTRASTIVE_EXCLUSION = /(?<![\p{L}\p{N}_])(?:rather\s+than|instead\s+of)(?:\s+(?:post(?:ing)?|publish(?:ing)?|shar(?:e|ing)|tweet(?:ing)?|send(?:ing)?))?(?:\s+(?:on|onto|to|via|in|at))?\s*$/iu;+const SOCIAL_DESTINATION_EXCLUSION = /^\s*(?:exclude|excluding)\s+(?:(?:post(?:ing)?|publish(?:ing)?|shar(?:e|ing)|tweet(?:ing)?|send(?:ing)?)\s+)?(?:(?:on|onto|to|via|in|at)\s+)?(?:the\s+)?(?:x|twitter|bluesky|bsky(?:\.app)?)(?![\p{L}\p{N}_.-])\s*$/iu;const socialPostNegationGovernsPublish = value => (SOCIAL_POST_NEGATION.test(String(value || '').trim())|| SOCIAL_POST_DESTINATION_NEGATION.test(String(value || ''))@@ -3826,6 +3827,9 @@ export class Agent extends LoopDetector {let matchingAttachments = rawAttachments;if (parsed.wantsImage && parsed.wantsVideo) {+ const requiresGifOnly = parsed.wantsGif && !parsed.wantsOrdinaryVideo;+ if (requiresGifOnly && rawAttachments.length !== (imageCount + gifCount)) return false;+ if (ordinaryVideoOnly && rawAttachments.length !== (imageCount + ordinaryVideoCount)) return false;if (parsed.isAlternative) {const minImages = imageAlternativeCounts.length? Math.min(...imageAlternativeCounts)@@ -17205,7 +17209,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst afterVerb = c.maskedText.slice(publish.index + publish[0].length);hasExplicitNeg = socialNegationGovernsPublish(beforeVerb) || socialPostNegationGovernsPublish(afterVerb);} else {- hasExplicitNeg = SOCIAL_NEGATION.test(c.maskedText);+ hasExplicitNeg = SOCIAL_NEGATION.test(c.maskedText)+ || SOCIAL_DESTINATION_EXCLUSION.test(c.maskedText);}if (hasExplicitNeg) {@@ -17222,9 +17227,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}}- let carriedPostNegation = false;- for (let i = clauses.length - 1; i >= 0; i--) {- const c = clauses[i];+ for (const c of clauses) {const publish = c.maskedText.match(SOCIAL_PUBLISH_VERBS);let hasExplicitPostNeg = false;if (publish) {@@ -17236,11 +17239,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (hasExplicitPostNeg) {c.isNegated = true;- carriedPostNegation = true;- } else if (carriedPostNegation && i < clauses.length - 1 && SOCIAL_COORDINATING_DELIMITER.test(clauses[i + 1].delim)) {- c.isNegated = true;- } else {- carriedPostNegation = false;}}diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 0a0c4b7fe..6601728bc 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -195,6 +195,7 @@ const SOCIAL_POST_DESTINATION_NEGATION = new RegExp('iu',);const SOCIAL_CONTRASTIVE_EXCLUSION = /(?<![\p{L}\p{N}_])(?:rather\s+than|instead\s+of)(?:\s+(?:post(?:ing)?|publish(?:ing)?|shar(?:e|ing)|tweet(?:ing)?|send(?:ing)?))?(?:\s+(?:on|onto|to|via|in|at))?\s*$/iu;+const SOCIAL_DESTINATION_EXCLUSION = /^\s*(?:exclude|excluding)\s+(?:(?:post(?:ing)?|publish(?:ing)?|shar(?:e|ing)|tweet(?:ing)?|send(?:ing)?)\s+)?(?:(?:on|onto|to|via|in|at)\s+)?(?:the\s+)?(?:x|twitter|bluesky|bsky(?:\.app)?)(?![\p{L}\p{N}_.-])\s*$/iu;const socialPostNegationGovernsPublish = value => (SOCIAL_POST_NEGATION.test(String(value || '').trim())|| SOCIAL_POST_DESTINATION_NEGATION.test(String(value || ''))@@ -3541,6 +3542,9 @@ export class Agent extends LoopDetector {let matchingAttachments = rawAttachments;if (parsed.wantsImage && parsed.wantsVideo) {+ const requiresGifOnly = parsed.wantsGif && !parsed.wantsOrdinaryVideo;+ if (requiresGifOnly && rawAttachments.length !== (imageCount + gifCount)) return false;+ if (ordinaryVideoOnly && rawAttachments.length !== (imageCount + ordinaryVideoCount)) return false;if (parsed.isAlternative) {const minImages = imageAlternativeCounts.length? Math.min(...imageAlternativeCounts)@@ -15004,7 +15008,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst afterVerb = c.maskedText.slice(publish.index + publish[0].length);hasExplicitNeg = socialNegationGovernsPublish(beforeVerb) || socialPostNegationGovernsPublish(afterVerb);} else {- hasExplicitNeg = SOCIAL_NEGATION.test(c.maskedText);+ hasExplicitNeg = SOCIAL_NEGATION.test(c.maskedText)+ || SOCIAL_DESTINATION_EXCLUSION.test(c.maskedText);}if (hasExplicitNeg) {@@ -15021,9 +15026,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}}- let carriedPostNegation = false;- for (let i = clauses.length - 1; i >= 0; i--) {- const c = clauses[i];+ for (const c of clauses) {const publish = c.maskedText.match(SOCIAL_PUBLISH_VERBS);let hasExplicitPostNeg = false;if (publish) {@@ -15035,11 +15038,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (hasExplicitPostNeg) {c.isNegated = true;- carriedPostNegation = true;- } else if (carriedPostNegation && i < clauses.length - 1 && SOCIAL_COORDINATING_DELIMITER.test(clauses[i + 1].delim)) {- c.isNegated = true;- } else {- carriedPostNegation = false;}}diff --git a/test/run.js b/test/run.jsindex fe470b469..4333f88ec 100644--- a/test/run.js+++ b/test/run.js@@ -90809,6 +90809,14 @@ test('social publication workflow follows the live X or Bluesky destination and'post-verb neither/nor destination scope adopted a forbidden platform'],['Post neither on X nor on Bluesky', [],'pre-preposition neither/nor destination scope adopted a forbidden platform'],+ ['Post on Bluesky and not on X', ['bluesky'],+ 'a later negated destination propagated backward onto affirmative Bluesky'],+ ['Post on X and not on Bluesky', ['twitter'],+ 'a later negated destination propagated backward onto affirmative X'],+ ['Post on Bluesky, excluding X', ['bluesky'],+ 'an explicitly excluded X destination was adopted'],+ ['Post on Bluesky, exclude X', ['bluesky'],+ 'an exclude 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'],@@ -92950,6 +92958,18 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'one video and at most two GIFs' }, { attachments: [video(1), video(2), gif(1)] }), false,AgentClass.name + ': the GIF maximum loosened the exact ordinary-video count');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one image and at most two GIFs' }, { attachments: [image(1)] }), true,+ AgentClass.name + ': zero optional GIFs did not satisfy a mixed GIF maximum');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one image and at most two GIFs' }, { attachments: [image(1), gif(1)] }), true,+ AgentClass.name + ': one GIF did not satisfy a mixed GIF maximum');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one image and at most two GIFs' }, { attachments: [image(1), gif(1), gif(2)] }), true,+ AgentClass.name + ': two GIFs did not satisfy a mixed GIF maximum');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one image and at most two GIFs' }, { attachments: [image(1), video(1)] }), false,+ AgentClass.name + ': an ordinary video satisfied a mixed GIF-only constraint');assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'up to two videos' }, { attachments: [] }), true,AgentClass.name + ': zero videos should satisfy a standalone video maximum');