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): paired bounds, colon discovery, leading fallbacks
Barack Sokullu5d08fc82be4e
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 95f7b1f99..8c8f52137 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -3355,11 +3355,27 @@ export class Agent extends LoopDetector {let minimumGifCount = 0;let minimumGenericCount = 0;if (hasMinCountQualifier) {- for (const segment of text.split(MIN_COUNT_SCOPE_SPLIT)) {+ const minSegments = text.split(MIN_COUNT_SCOPE_SPLIT);+ for (let segmentIndex = 0; segmentIndex < minSegments.length; segmentIndex++) {+ const segment = minSegments[segmentIndex];if (!segment || !MIN_ATTACHMENT_COUNT_REGEX.test(segment)) continue;- const segmentImage = RAW_IMAGE_NOUN_REGEX.test(segment);- const segmentGif = RAW_GIF_NOUN_REGEX.test(segment);- const segmentVideo = RAW_VIDEO_NOUN_REGEX.test(segment);+ let segmentImage = RAW_IMAGE_NOUN_REGEX.test(segment);+ let segmentGif = RAW_GIF_NOUN_REGEX.test(segment);+ let segmentVideo = RAW_VIDEO_NOUN_REGEX.test(segment);+ if (!segmentImage && !segmentVideo && !segmentGif) {+ // A bare lower bound ("at least one and at most two images")+ // inherits the trailing segment's media noun when exactly one type+ // follows, instead of becoming a generic minimum for every type.+ const trailing = minSegments.slice(segmentIndex + 1).join(' ');+ const trailingImage = RAW_IMAGE_NOUN_REGEX.test(trailing);+ const trailingGif = RAW_GIF_NOUN_REGEX.test(trailing);+ const trailingVideo = RAW_VIDEO_NOUN_REGEX.test(trailing);+ if (Number(trailingImage) + Number(trailingGif) + Number(trailingVideo) === 1) {+ segmentImage = trailingImage;+ segmentGif = trailingGif;+ segmentVideo = trailingVideo;+ }+ }const segmentCount = qualifiedCountInSegment(segment, MIN_ATTACHMENT_COUNT_REGEX);if (segmentImage) {minScopedImage = true;@@ -17998,6 +18014,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst verbPattern = new RegExp(SOCIAL_PUBLISH_VERBS.source, 'giu');return clauses.some((clause, clauseIdx) => {if (!clause.text || clause.isNegated) return false;+ // Colon-scoped payload is body prose, not a new destination command:+ // "Post on X: I posted on Bluesky yesterday." must not adopt Bluesky+ // without a genuine coordinated command boundary.+ if ((clause.delim || '').trim() === ':') return false;const targetText = clause.maskedText || clause.text;// "Post this not on X but on Bluesky" carries the publish action into// the positive contrastive destination even though that clause is@@ -18196,7 +18216,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// 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|otherwise|failing\s+that|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*(?:,\s*)?(?:(?:alternatively|otherwise|else)(?:\s*,\s*|\s+))?(?:,\s*if\s+(?:unavailable|not\s+available|available|needed|necessary|possible|unable|unsuccessful|failing|failed|fails?|failure)\b[^,;]*,?\s*)?(?:(?:post|publish|share|tweet|send|reply|respond)\s+(?:(?:this|that|it|the\s+following)\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 directAlternativeBridge = /^\s*(?:(?:page|account|profile)\s*)?(?:,\s*)?(?:if\s+(?:unavailable|not\s+available|available|needed|necessary|possible|possibly|unable|unsuccessful|failing|failed|fails?|failure)\b[^,;]*,?\s*)?(?:(?:or|otherwise|failing\s+that|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*(?:,\s*)?(?:(?:alternatively|otherwise|else)(?:\s*,\s*|\s+))?(?:,\s*if\s+(?:unavailable|not\s+available|available|needed|necessary|possible|unable|unsuccessful|failing|failed|fails?|failure)\b[^,;]*,?\s*)?(?:(?:post|publish|share|tweet|send|reply|respond)\s+(?:(?:this|that|it|the\s+following)\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 explicitAlternativeBridge = /^\s*(?:(?:page|account|profile)\s*)?(?:,\s*)?(?:(?:alternatively|otherwise|failing\s+that)(?:\s*,\s*)?(?:[\s,]+(?:on|onto|to|via|in|at))?|as\s+an\s+alternative\s+to)\s*(?:the\s+)?$/iu;const oneOfAlternativeLead = /(?<![\p{L}\p{N}_])one\s+of\s+(?:the\s+)?$/iu;const oneOfAlternativeBridge = /^\s*(?:,\s*)?(?:and|or)\s+(?:the\s+)?$/iu;diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex cbadeb552..029455004 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -3070,11 +3070,27 @@ export class Agent extends LoopDetector {let minimumGifCount = 0;let minimumGenericCount = 0;if (hasMinCountQualifier) {- for (const segment of text.split(MIN_COUNT_SCOPE_SPLIT)) {+ const minSegments = text.split(MIN_COUNT_SCOPE_SPLIT);+ for (let segmentIndex = 0; segmentIndex < minSegments.length; segmentIndex++) {+ const segment = minSegments[segmentIndex];if (!segment || !MIN_ATTACHMENT_COUNT_REGEX.test(segment)) continue;- const segmentImage = RAW_IMAGE_NOUN_REGEX.test(segment);- const segmentGif = RAW_GIF_NOUN_REGEX.test(segment);- const segmentVideo = RAW_VIDEO_NOUN_REGEX.test(segment);+ let segmentImage = RAW_IMAGE_NOUN_REGEX.test(segment);+ let segmentGif = RAW_GIF_NOUN_REGEX.test(segment);+ let segmentVideo = RAW_VIDEO_NOUN_REGEX.test(segment);+ if (!segmentImage && !segmentVideo && !segmentGif) {+ // A bare lower bound ("at least one and at most two images")+ // inherits the trailing segment's media noun when exactly one type+ // follows, instead of becoming a generic minimum for every type.+ const trailing = minSegments.slice(segmentIndex + 1).join(' ');+ const trailingImage = RAW_IMAGE_NOUN_REGEX.test(trailing);+ const trailingGif = RAW_GIF_NOUN_REGEX.test(trailing);+ const trailingVideo = RAW_VIDEO_NOUN_REGEX.test(trailing);+ if (Number(trailingImage) + Number(trailingGif) + Number(trailingVideo) === 1) {+ segmentImage = trailingImage;+ segmentGif = trailingGif;+ segmentVideo = trailingVideo;+ }+ }const segmentCount = qualifiedCountInSegment(segment, MIN_ATTACHMENT_COUNT_REGEX);if (segmentImage) {minScopedImage = true;@@ -15797,6 +15813,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst verbPattern = new RegExp(SOCIAL_PUBLISH_VERBS.source, 'giu');return clauses.some((clause, clauseIdx) => {if (!clause.text || clause.isNegated) return false;+ // Colon-scoped payload is body prose, not a new destination command:+ // "Post on X: I posted on Bluesky yesterday." must not adopt Bluesky+ // without a genuine coordinated command boundary.+ if ((clause.delim || '').trim() === ':') return false;const targetText = clause.maskedText || clause.text;// "Post this not on X but on Bluesky" carries the publish action into// the positive contrastive destination even though that clause is@@ -15995,7 +16015,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// 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|otherwise|failing\s+that|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*(?:,\s*)?(?:(?:alternatively|otherwise|else)(?:\s*,\s*|\s+))?(?:,\s*if\s+(?:unavailable|not\s+available|available|needed|necessary|possible|unable|unsuccessful|failing|failed|fails?|failure)\b[^,;]*,?\s*)?(?:(?:post|publish|share|tweet|send|reply|respond)\s+(?:(?:this|that|it|the\s+following)\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 directAlternativeBridge = /^\s*(?:(?:page|account|profile)\s*)?(?:,\s*)?(?:if\s+(?:unavailable|not\s+available|available|needed|necessary|possible|possibly|unable|unsuccessful|failing|failed|fails?|failure)\b[^,;]*,?\s*)?(?:(?:or|otherwise|failing\s+that|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*(?:,\s*)?(?:(?:alternatively|otherwise|else)(?:\s*,\s*|\s+))?(?:,\s*if\s+(?:unavailable|not\s+available|available|needed|necessary|possible|unable|unsuccessful|failing|failed|fails?|failure)\b[^,;]*,?\s*)?(?:(?:post|publish|share|tweet|send|reply|respond)\s+(?:(?:this|that|it|the\s+following)\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 explicitAlternativeBridge = /^\s*(?:(?:page|account|profile)\s*)?(?:,\s*)?(?:(?:alternatively|otherwise|failing\s+that)(?:\s*,\s*)?(?:[\s,]+(?:on|onto|to|via|in|at))?|as\s+an\s+alternative\s+to)\s*(?:the\s+)?$/iu;const oneOfAlternativeLead = /(?<![\p{L}\p{N}_])one\s+of\s+(?:the\s+)?$/iu;const oneOfAlternativeBridge = /^\s*(?:,\s*)?(?:and|or)\s+(?:the\s+)?$/iu;diff --git a/test/run.js b/test/run.jsindex e2f5cfd96..ef9ad5d96 100644--- a/test/run.js+++ b/test/run.js@@ -91025,6 +91025,8 @@ test('social publication workflow follows the live X or Bluesky destination and'coordinated destinations on X plus Bluesky should both be targeted'],['Post on X: hello; and on Bluesky: goodbye', ['twitter', 'bluesky'],'per-destination bodies should still discover both platforms'],+ ['Post on X: I posted on Bluesky yesterday.', ['twitter'],+ 'colon-scoped body prose adopted Bluesky as a destination'],['Post on X along with Bluesky', ['twitter', 'bluesky'],'coordinated destinations on X along with Bluesky should both be targeted'],['Post on X, then on Bluesky', ['twitter', 'bluesky'],@@ -91386,6 +91388,10 @@ test('alternative social destinations require one verified publication, not ever...guard,taskText: 'Post on X, or alternatively, Bluesky.',}), true, AgentClass.name + ': punctuated alternatively bridge required a second public post');+ assert.equal(agent._socialPublishTargetsAreAlternatives({+ ...guard,+ taskText: 'Post on X if possible, otherwise on Bluesky.',+ }), true, AgentClass.name + ': leading-condition fallback required a second public post');assert.deepEqual(agent._missingSocialPublishTargets({ ...guard, taskText: 'Post on Bluesky' }), ['bluesky'],AgentClass.name + ': a run bound to X reported no missing destination for a Bluesky-only request');assert.deepEqual(agent._missingSocialPublishTargets({ ...guard, taskText: 'Post on X' }), [],@@ -93361,6 +93367,16 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {{ value: 'at least one image and at most two JPEG images' }, { attachments },), expected, AgentClass.name + ': ' + message);}+ for (const [attachments, expected, message] of [+ [[image(1)], true, 'one image was rejected by a paired image bound'],+ [[image(1), image(2)], true, 'two images were rejected by a paired image bound'],+ [[], false, 'empty attachments satisfied a paired image minimum'],+ [[image(1), image(2), image(3)], false, 'three images satisfied a paired image maximum'],+ ]) {+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'at least one and at most two images' }, { attachments },+ ), expected, AgentClass.name + ': ' + message);+ }for (const [attachments, expected, message] of [[[video(1)], true, 'the required MP4 alone was rejected by its scoped MOV cap'],[[video(1), { type: 'video', src: 'https://cdn.example/b.mov' }], true, 'an MP4 plus a capped MOV was capped by the total video count'],