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 alternatives to commands, unless-then fallback
Barack Sokullu4d73648fb88f
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex d8a2bfcaf..d3c4629fb 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -18270,7 +18270,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*)?(?:(?:if\s+(?:(?:that|it|this)\s+)?(?:unavailable|not\s+available|not\s+work(?:ing|s)?|(?:do|does|did)\s+not\s+work|(?:do|does|did)n['β]?t\s+work|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))?|(?:(?: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+(?:(?:that|it|this)\s+)?(?:unavailable|not\s+available|not\s+work(?:ing|s)?|(?:do|does|did)\s+not\s+work|(?:do|does|did)n['β]?t\s+work|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+(?:(?:that|it|this)\s+)?(?:unavailable|not\s+available|not\s+work(?:ing|s)?|(?:do|does|did)\s+not\s+work|(?:do|does|did)n['β]?t\s+work|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))?|(?:(?: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))|(?:unless\s+[^,;]*,\s*then\s*))\s*(?:,\s*)?(?:(?:alternatively|otherwise|else)(?:\s*,\s*|\s+))?(?:,\s*if\s+(?:(?:that|it|this)\s+)?(?:unavailable|not\s+available|not\s+work(?:ing|s)?|(?:do|does|did)\s+not\s+work|(?:do|does|did)n['β]?t\s+work|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;@@ -18280,6 +18280,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d.filter(Boolean);return texts.some((text) => {const masked = this._maskQuotedPayload(text);+ // URL punctuation is sentence content, not a boundary: hide URLs so a+ // host dot cannot split the publication command a pair belongs to.+ const urlBlind = masked.replace(+ /https?:\/\/[^\s<>"'`\u3002\u3001\uff0c\uff1b\uff1a\uff01\uff1f\u2026\u2025]+/gi,+ match => ' '.repeat(match.length),+ );const platforms = [...masked.matchAll(platformPattern)].map(match => {const matchedText = /^https?:/i.test(match[0])? this._workflowTrimUrlPunctuation(match[0])@@ -18294,6 +18300,22 @@ 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;+ // An alternative pair only counts inside a publication command: a+ // later unrelated choice ("Compare X or Bluesky afterward.") must+ // not suppress an explicitly requested second publication.+ const sentenceStart = Math.max(+ urlBlind.lastIndexOf('.', left.index),+ urlBlind.lastIndexOf('?', left.index),+ urlBlind.lastIndexOf('!', left.index),+ urlBlind.lastIndexOf(';', left.index),+ urlBlind.lastIndexOf('\n', left.index),+ ) + 1;+ let sentenceEnd = urlBlind.length;+ for (const boundary of ['.', '?', '!', ';', '\n']) {+ const at = urlBlind.indexOf(boundary, right.end);+ if (at >= 0 && at < sentenceEnd) sentenceEnd = at;+ }+ if (!this._socialPublicationCommandIn(masked.slice(sentenceStart, sentenceEnd))) continue;const bridge = masked.slice(left.end, right.index);if (directAlternativeBridge.test(bridge)|| explicitAlternativeBridge.test(bridge)diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 338d22d20..843b1f8c7 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -16069,7 +16069,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*)?(?:(?:if\s+(?:(?:that|it|this)\s+)?(?:unavailable|not\s+available|not\s+work(?:ing|s)?|(?:do|does|did)\s+not\s+work|(?:do|does|did)n['β]?t\s+work|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))?|(?:(?: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+(?:(?:that|it|this)\s+)?(?:unavailable|not\s+available|not\s+work(?:ing|s)?|(?:do|does|did)\s+not\s+work|(?:do|does|did)n['β]?t\s+work|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+(?:(?:that|it|this)\s+)?(?:unavailable|not\s+available|not\s+work(?:ing|s)?|(?:do|does|did)\s+not\s+work|(?:do|does|did)n['β]?t\s+work|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))?|(?:(?: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))|(?:unless\s+[^,;]*,\s*then\s*))\s*(?:,\s*)?(?:(?:alternatively|otherwise|else)(?:\s*,\s*|\s+))?(?:,\s*if\s+(?:(?:that|it|this)\s+)?(?:unavailable|not\s+available|not\s+work(?:ing|s)?|(?:do|does|did)\s+not\s+work|(?:do|does|did)n['β]?t\s+work|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;@@ -16079,6 +16079,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d.filter(Boolean);return texts.some((text) => {const masked = this._maskQuotedPayload(text);+ // URL punctuation is sentence content, not a boundary: hide URLs so a+ // host dot cannot split the publication command a pair belongs to.+ const urlBlind = masked.replace(+ /https?:\/\/[^\s<>"'`\u3002\u3001\uff0c\uff1b\uff1a\uff01\uff1f\u2026\u2025]+/gi,+ match => ' '.repeat(match.length),+ );const platforms = [...masked.matchAll(platformPattern)].map(match => {const matchedText = /^https?:/i.test(match[0])? this._workflowTrimUrlPunctuation(match[0])@@ -16093,6 +16099,22 @@ 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;+ // An alternative pair only counts inside a publication command: a+ // later unrelated choice ("Compare X or Bluesky afterward.") must+ // not suppress an explicitly requested second publication.+ const sentenceStart = Math.max(+ urlBlind.lastIndexOf('.', left.index),+ urlBlind.lastIndexOf('?', left.index),+ urlBlind.lastIndexOf('!', left.index),+ urlBlind.lastIndexOf(';', left.index),+ urlBlind.lastIndexOf('\n', left.index),+ ) + 1;+ let sentenceEnd = urlBlind.length;+ for (const boundary of ['.', '?', '!', ';', '\n']) {+ const at = urlBlind.indexOf(boundary, right.end);+ if (at >= 0 && at < sentenceEnd) sentenceEnd = at;+ }+ if (!this._socialPublicationCommandIn(masked.slice(sentenceStart, sentenceEnd))) continue;const bridge = masked.slice(left.end, right.index);if (directAlternativeBridge.test(bridge)|| explicitAlternativeBridge.test(bridge)diff --git a/test/run.js b/test/run.jsindex 3d95d70f2..e79659c18 100644--- a/test/run.js+++ b/test/run.js@@ -91420,6 +91420,14 @@ test('alternative social destinations require one verified publication, not ever...guard,taskText: 'Post on X; if that does not work, post on Bluesky.',}), true, AgentClass.name + ': does-not-work fallback required a second public post');+ assert.equal(agent._socialPublishTargetsAreAlternatives({+ ...guard,+ taskText: 'Post on X unless it is unavailable, then post on Bluesky.',+ }), true, AgentClass.name + ': unless-then fallback required a second public post');+ assert.equal(agent._socialPublishTargetsAreAlternatives({+ ...guard,+ taskText: 'Post hello on X and Bluesky. Compare X or Bluesky afterward.',+ }), false, AgentClass.name + ': an unrelated later comparison suppressed a requested publication');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' }), [],