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): bind nested media intent
Barack Sokulluacb9c6fdcb73
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex b4222c9f1..dfca5369e 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -3194,6 +3194,15 @@ export class Agent extends LoopDetector {if (!segmentImage && !segmentVideo && !segmentGif) minScopedGeneric = true;}}+ for (const postfixMinimum of text.matchAll(+ /(?<![\p{L}\p{N}_])or\s+more\s+(images?|photos?|pictures?|pics?|videos?|clips?|recordings?|gifs?|attachments?|files?|media|uploads?|items?|assets?)(?![\p{L}\p{N}_])/giu,+ )) {+ const noun = postfixMinimum[1] || '';+ if (RAW_GIF_NOUN_REGEX.test(noun)) minScopedGif = true;+ else if (RAW_IMAGE_NOUN_REGEX.test(noun)) minScopedImage = true;+ else if (RAW_VIDEO_NOUN_REGEX.test(noun)) minScopedVideo = true;+ else minScopedGeneric = true;+ }if (hasBoundedCountRange) {if (boundedRangeKind === 'image') minScopedImage = true;else if (boundedRangeKind === 'video') minScopedVideo = true;@@ -3280,7 +3289,9 @@ export class Agent extends LoopDetector {}const DISJUNCTION_REGEX = /(?:\b(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\b|[或或者]|(?:또는|혹은)|(?:または|それとも))/i;- const hasDisjunction = isGeneric && DISJUNCTION_REGEX.test(text);+ // "one or more" is one lower-bound phrase, not a choice between counts.+ const disjunctionText = text.replace(MIN_ATTACHMENT_COUNT_STRIP_REGEX, ' ');+ const hasDisjunction = isGeneric && DISJUNCTION_REGEX.test(disjunctionText);const requestedTypeCount = Number(wantsImage) + Number(wantsOrdinaryVideo) + Number(wantsGif);const alternativeCounts = hasDisjunction && requestedTypeCount <= 1? [...countText.matchAll(new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${countPrefix})(?![${SOCIAL_WORD_EDGE}])`, 'giu'))]@@ -3578,10 +3589,10 @@ export class Agent extends LoopDetector {const type = attachmentType(att);if (type === 'animated_gif' || type === 'gif') return true;const src = String(att?.src || att?.url || '');- const alt = String(att?.alt || att?.description || '');+ const name = String(att?.name || '');return /\.gif(?:\.mp4)?(?:[?#]|$)/i.test(src)|| /\/tweet_video(?:_thumb)?\//i.test(src)- || /\.gif(?:[?#\s]|$)/i.test(alt);+ || /\.gif(?:[?#]|$)/i.test(name);};const canMatchSpecificTargets = (targets, candidates) => {@@ -17211,7 +17222,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (SOCIAL_READ_VERBS.test(beforeVerbClause)) continue;if (socialNegationGovernsPublish(beforeVerbClause)) continue;const verbWord = verb[0] || '';- const afterVerbText = targetText.slice(verbIndex + verbWord.length);+ const unscopedAfterVerbText = targetText.slice(verbIndex + verbWord.length);+ const nextPublish = unscopedAfterVerbText.match(SOCIAL_PUBLISH_VERBS);+ const afterVerbText = nextPublish+ ? unscopedAfterVerbText.slice(0, nextPublish.index)+ : unscopedAfterVerbText;if (socialPostNegationGovernsPublish(afterVerbText)) continue;if (SOCIAL_NOUN_LIKE_PUBLISH.test(verbWord) && (SOCIAL_READ_VERBS.test(afterVerbText)@@ -17219,7 +17234,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d|| NON_SOCIAL_DESTINATION_IN_TEXT.test(beforeVerbClause))) continue;if (/^shares?$/i.test(verbWord) && /(?<![\p{L}\p{N}_])(?:market|mind|revenue|profit|traffic|audience|wallet|fair|lion's|stock|equity|file|screen|time)\s+$/iu.test(beforeVerbClause)) continue;- const afterVerb = targetText.slice(verbIndex + verbWord.length);+ const afterVerb = afterVerbText;const beforeVerb = targetText.slice(0, verbIndex);for (const matchAfter of afterVerb.matchAll(platformPattern)) {diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 7355f320b..0deef186a 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -2909,6 +2909,15 @@ export class Agent extends LoopDetector {if (!segmentImage && !segmentVideo && !segmentGif) minScopedGeneric = true;}}+ for (const postfixMinimum of text.matchAll(+ /(?<![\p{L}\p{N}_])or\s+more\s+(images?|photos?|pictures?|pics?|videos?|clips?|recordings?|gifs?|attachments?|files?|media|uploads?|items?|assets?)(?![\p{L}\p{N}_])/giu,+ )) {+ const noun = postfixMinimum[1] || '';+ if (RAW_GIF_NOUN_REGEX.test(noun)) minScopedGif = true;+ else if (RAW_IMAGE_NOUN_REGEX.test(noun)) minScopedImage = true;+ else if (RAW_VIDEO_NOUN_REGEX.test(noun)) minScopedVideo = true;+ else minScopedGeneric = true;+ }if (hasBoundedCountRange) {if (boundedRangeKind === 'image') minScopedImage = true;else if (boundedRangeKind === 'video') minScopedVideo = true;@@ -2995,7 +3004,9 @@ export class Agent extends LoopDetector {}const DISJUNCTION_REGEX = /(?:\b(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\b|[或或者]|(?:또는|혹은)|(?:または|それとも))/i;- const hasDisjunction = isGeneric && DISJUNCTION_REGEX.test(text);+ // "one or more" is one lower-bound phrase, not a choice between counts.+ const disjunctionText = text.replace(MIN_ATTACHMENT_COUNT_STRIP_REGEX, ' ');+ const hasDisjunction = isGeneric && DISJUNCTION_REGEX.test(disjunctionText);const requestedTypeCount = Number(wantsImage) + Number(wantsOrdinaryVideo) + Number(wantsGif);const alternativeCounts = hasDisjunction && requestedTypeCount <= 1? [...countText.matchAll(new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${countPrefix})(?![${SOCIAL_WORD_EDGE}])`, 'giu'))]@@ -3293,10 +3304,10 @@ export class Agent extends LoopDetector {const type = attachmentType(att);if (type === 'animated_gif' || type === 'gif') return true;const src = String(att?.src || att?.url || '');- const alt = String(att?.alt || att?.description || '');+ const name = String(att?.name || '');return /\.gif(?:\.mp4)?(?:[?#]|$)/i.test(src)|| /\/tweet_video(?:_thumb)?\//i.test(src)- || /\.gif(?:[?#\s]|$)/i.test(alt);+ || /\.gif(?:[?#]|$)/i.test(name);};const canMatchSpecificTargets = (targets, candidates) => {@@ -15010,7 +15021,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (SOCIAL_READ_VERBS.test(beforeVerbClause)) continue;if (socialNegationGovernsPublish(beforeVerbClause)) continue;const verbWord = verb[0] || '';- const afterVerbText = targetText.slice(verbIndex + verbWord.length);+ const unscopedAfterVerbText = targetText.slice(verbIndex + verbWord.length);+ const nextPublish = unscopedAfterVerbText.match(SOCIAL_PUBLISH_VERBS);+ const afterVerbText = nextPublish+ ? unscopedAfterVerbText.slice(0, nextPublish.index)+ : unscopedAfterVerbText;if (socialPostNegationGovernsPublish(afterVerbText)) continue;if (SOCIAL_NOUN_LIKE_PUBLISH.test(verbWord) && (SOCIAL_READ_VERBS.test(afterVerbText)@@ -15018,7 +15033,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d|| NON_SOCIAL_DESTINATION_IN_TEXT.test(beforeVerbClause))) continue;if (/^shares?$/i.test(verbWord) && /(?<![\p{L}\p{N}_])(?:market|mind|revenue|profit|traffic|audience|wallet|fair|lion's|stock|equity|file|screen|time)\s+$/iu.test(beforeVerbClause)) continue;- const afterVerb = targetText.slice(verbIndex + verbWord.length);+ const afterVerb = afterVerbText;const beforeVerb = targetText.slice(0, verbIndex);for (const matchAfter of afterVerb.matchAll(platformPattern)) {diff --git a/test/run.js b/test/run.jsindex 18a6bfd5b..6f4ebb255 100644--- a/test/run.js+++ b/test/run.js@@ -90791,6 +90791,8 @@ test('social publication workflow follows the live X or Bluesky destination and'explicit affirmative publish clause inherited negation from X'],['Post this not on X but on Bluesky', ['bluesky'],'post-verb destination negation selected X instead of contrastive Bluesky'],+ ['Post on X without posting on Bluesky', ['twitter'],+ 'a nested negated publish clause added its forbidden Bluesky destination'],['Post or publish this on X', ['twitter'],'affirmative coordinated publish verbs were wrongly rejected for X'],['Post "Do not panic" on X', ['twitter'],@@ -93519,6 +93521,7 @@ test('attachment verification matches specific attachment names without substrin// A GIF is a video, but an ordinary video is not a GIF.const gifMedia = {mp4: { type: 'video', src: 'https://video.twimg.com/media/clip.mp4' },+ altNamedMp4: { type: 'video', src: 'https://video.twimg.com/media/clip.mp4', alt: 'demo.gif' },typed: { type: 'animated_gif', src: 'https://video.twimg.com/tweet_video/loop.mp4' },named: { type: 'video', src: 'https://video.twimg.com/tweet_video/animation.gif.mp4', alt: 'animation.gif' },plain: { type: 'video', src: 'https://cdn.example.com/loop.gif' },@@ -93551,6 +93554,19 @@ test('attachment verification matches specific attachment names without substrintrue,AgentClass.name + ': an ordinary mp4 should pass a negated GIF requirement',);+ assert.equal(+ agent._workflowSocialPublishedAttachmentObserved({ value: 'a GIF' }, { attachments: [gifMedia.altNamedMp4] }),+ false,+ AgentClass.name + ': alt text ending in .gif reclassified an ordinary mp4',+ );+ assert.equal(+ agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one video and no GIFs' },+ { attachments: [gifMedia.altNamedMp4] },+ ),+ true,+ AgentClass.name + ': GIF-like alt text violated a no-GIF requirement for an ordinary mp4',+ );const twoGifRequirement = agent._parseWorkflowAttachmentRequirement({ value: 'two GIFs' });assert.equal(twoGifRequirement.expectedGifCount, 2,AgentClass.name + ': the GIF count was collapsed into the general video count');@@ -93631,6 +93647,7 @@ test('attachment verification matches specific attachment names without substrin// Minimum-count qualifiers bound the count from below instead of naming a file.for (const [minReq, minCount] of [+ ['one or more images', 1],['at least two images', 2],['at least 2 images', 2],['minimum of 3 photos', 3],@@ -93701,6 +93718,23 @@ test('attachment verification matches specific attachment names without substrin{ attachments: [image(1), image(2), video(1), video(2)] },), false, AgentClass.name + ': the video minimum incorrectly loosened the exact image count');+ const postfixVideoMinimum = { value: 'one image and one or more videos' };+ const parsedPostfixVideoMinimum = agent._parseWorkflowAttachmentRequirement(postfixVideoMinimum);+ assert.equal(parsedPostfixVideoMinimum.isAlternative, false,+ AgentClass.name + ': "or more" was parsed as a media alternative');+ assert.equal(parsedPostfixVideoMinimum.isVideoMinimum, true,+ AgentClass.name + ': postfix video minimum scope was lost');+ assert.equal(parsedPostfixVideoMinimum.isImageMinimum, false,+ AgentClass.name + ': postfix video minimum leaked onto the image count');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ postfixVideoMinimum,+ { attachments: [image(1), video(1), video(2)] },+ ), true, AgentClass.name + ': extra video did not satisfy the postfix minimum');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ postfixVideoMinimum,+ { attachments: [image(1)] },+ ), false, AgentClass.name + ': missing videos satisfied the postfix minimum');+const alternativeScopedMinimum = { value: 'at least two images or one video' };const parsedAlternativeScopedMinimum = agent._parseWorkflowAttachmentRequirement(alternativeScopedMinimum);assert.equal(parsedAlternativeScopedMinimum.isImageMinimum, true,