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): sole-target mismatch, max-qualifier negation, repeated format counts
Barack Sokullu0062dd991916
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex a40efc51b..8def41ced 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -3130,7 +3130,9 @@ export class Agent extends LoopDetector {const precedingSegment = negationText.slice(0, matchIndex).split(/(?:[,;]|\s+(?:and|but|plus|also|as\s+well\s+as)\s+)/iu).pop() || '';- return /(?<![\p{L}\p{N}_])(?:no|not(?!\s+only)|without(?:\s+any)?|zero|0)(?![\p{L}\p{N}_])/iu.test(precedingSegment);+ // Minimum/maximum phrases ("no more than", "no fewer than") bound a+ // count instead of negating the media, so they never mark an occurrence.+ 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);};const hasAffirmativeMediaMatch = (pattern) => {for (const match of text.matchAll(new RegExp(pattern.source, 'giu'))) {@@ -3147,15 +3149,19 @@ export class Agent extends LoopDetector {const wantsVideo = wantsOrdinaryVideo || wantsGif;const wantsImage = hasRawImage && !isImageNegated;const normalizeAttachmentFormat = format => (/^jpe?g$/iu.test(format) ? 'jpeg' : String(format || '').toLowerCase());- const imageFormatQualifier = `${IMAGE_ATTACHMENT_FORMAT}(?:\\s*(?:or|and|/|,)\\s*${IMAGE_ATTACHMENT_FORMAT})*`;- const videoFormatQualifier = `${VIDEO_ATTACHMENT_FORMAT}(?:\\s*(?:or|and|/|,)\\s*${VIDEO_ATTACHMENT_FORMAT})*`;+ // 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.+ 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 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).pop() || '';- return /(?<![\p{L}\p{N}_])(?:no|not(?!\s+only)|without(?:\s+any)?|zero|0)(?![\p{L}\p{N}_])/iu.test(precedingSegment);+ 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);};const collectMediaFormatMatches = (formatQualifier, nounPattern) => {const matches = [];@@ -18201,8 +18207,22 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d} catch {return ['unknown'];}- // One destination is already covered by the ordinary terminal evidence.- if (!targets || targets.size < 2) return [];+ // One destination is already covered by the ordinary terminal evidence,+ // but only when the bound workflow is that destination. A run bound to X+ // for a Bluesky-only request must still report Bluesky as missing.+ if (!targets || targets.size < 2) {+ const boundAdapter = state?.siteWorkflow?.adapterName;+ const boundIsSocialPublish = !!state?.siteWorkflow?.job+ && state.siteWorkflow.job.id === 'publish-post'+ && ['twitter', 'bluesky'].includes(boundAdapter);+ if (boundIsSocialPublish && targets?.size === 1 && !targets.has(boundAdapter)) {+ const satisfied = Array.isArray(state.socialPublishSatisfiedTargets)+ ? state.socialPublishSatisfiedTargets+ : [];+ return [...targets].filter(name => !satisfied.includes(name));+ }+ return [];+ }const satisfied = Array.isArray(state.socialPublishSatisfiedTargets)? state.socialPublishSatisfiedTargets: [];diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex d0225819d..80cc5fdca 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -2845,7 +2845,9 @@ export class Agent extends LoopDetector {const precedingSegment = negationText.slice(0, matchIndex).split(/(?:[,;]|\s+(?:and|but|plus|also|as\s+well\s+as)\s+)/iu).pop() || '';- return /(?<![\p{L}\p{N}_])(?:no|not(?!\s+only)|without(?:\s+any)?|zero|0)(?![\p{L}\p{N}_])/iu.test(precedingSegment);+ // Minimum/maximum phrases ("no more than", "no fewer than") bound a+ // count instead of negating the media, so they never mark an occurrence.+ 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);};const hasAffirmativeMediaMatch = (pattern) => {for (const match of text.matchAll(new RegExp(pattern.source, 'giu'))) {@@ -2862,15 +2864,19 @@ export class Agent extends LoopDetector {const wantsVideo = wantsOrdinaryVideo || wantsGif;const wantsImage = hasRawImage && !isImageNegated;const normalizeAttachmentFormat = format => (/^jpe?g$/iu.test(format) ? 'jpeg' : String(format || '').toLowerCase());- const imageFormatQualifier = `${IMAGE_ATTACHMENT_FORMAT}(?:\\s*(?:or|and|/|,)\\s*${IMAGE_ATTACHMENT_FORMAT})*`;- const videoFormatQualifier = `${VIDEO_ATTACHMENT_FORMAT}(?:\\s*(?:or|and|/|,)\\s*${VIDEO_ATTACHMENT_FORMAT})*`;+ // 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.+ 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 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).pop() || '';- return /(?<![\p{L}\p{N}_])(?:no|not(?!\s+only)|without(?:\s+any)?|zero|0)(?![\p{L}\p{N}_])/iu.test(precedingSegment);+ 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);};const collectMediaFormatMatches = (formatQualifier, nounPattern) => {const matches = [];@@ -16000,8 +16006,22 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d} catch {return ['unknown'];}- // One destination is already covered by the ordinary terminal evidence.- if (!targets || targets.size < 2) return [];+ // One destination is already covered by the ordinary terminal evidence,+ // but only when the bound workflow is that destination. A run bound to X+ // for a Bluesky-only request must still report Bluesky as missing.+ if (!targets || targets.size < 2) {+ const boundAdapter = state?.siteWorkflow?.adapterName;+ const boundIsSocialPublish = !!state?.siteWorkflow?.job+ && state.siteWorkflow.job.id === 'publish-post'+ && ['twitter', 'bluesky'].includes(boundAdapter);+ if (boundIsSocialPublish && targets?.size === 1 && !targets.has(boundAdapter)) {+ const satisfied = Array.isArray(state.socialPublishSatisfiedTargets)+ ? state.socialPublishSatisfiedTargets+ : [];+ return [...targets].filter(name => !satisfied.includes(name));+ }+ return [];+ }const satisfied = Array.isArray(state.socialPublishSatisfiedTargets)? state.socialPublishSatisfiedTargets: [];diff --git a/test/run.js b/test/run.jsindex 866855c79..8eb16478a 100644--- a/test/run.js+++ b/test/run.js@@ -91343,6 +91343,10 @@ test('alternative social destinations require one verified publication, not ever...guard,taskText: 'Post on X or, if unavailable, Bluesky.',}), true, AgentClass.name + ': conditional fallback turned alternative destinations into two mandatory posts');+ 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' }), [],+ AgentClass.name + ': a run bound to its sole requested destination reported it missing');for (const taskText of ['Post this on X alongside Bluesky.','Post this on X together with Bluesky.',@@ -93144,6 +93148,33 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'one PNG or JPEG image' }, { attachments: [{ type: 'image', src: 'https://cdn.example/a.webp' }] }), false,AgentClass.name + ': WebP satisfied a PNG-or-JPEG format choice');+ const repeatedCountFormatChoice = agent._parseWorkflowAttachmentRequirement('one PNG or one JPEG image');+ assert.equal(repeatedCountFormatChoice.isGeneric, true,+ AgentClass.name + ': a repeated-count format choice was parsed as filenames');+ assert.deepEqual(repeatedCountFormatChoice.specificTargets, [],+ AgentClass.name + ': a repeated-count format choice created specific targets');+ assert.deepEqual(repeatedCountFormatChoice.requestedImageFormats, ['png', 'jpeg']);+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one PNG or one JPEG image' }, { attachments: [image(1)] }), true,+ AgentClass.name + ': PNG did not satisfy the repeated-count format choice');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one PNG or one JPEG image' }, { attachments: [{ type: 'image', src: 'https://cdn.example/a.jpg' }] }), true,+ AgentClass.name + ': JPEG did not satisfy the repeated-count format choice');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one PNG or one JPEG image' }, { attachments: [{ type: 'image', src: 'https://cdn.example/a.webp' }] }), false,+ AgentClass.name + ': WebP satisfied a repeated-count format choice');+ 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 [+ [[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'],+ [[image(1), video(1), video(2)], false, 'too many videos satisfied a no-more-than video cap'],+ ]) {+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one image and no more than one video' }, { attachments },+ ), expected, AgentClass.name + ': ' + message);+ }const unrestrictedOrPngImage = agent._parseWorkflowAttachmentRequirement('one image or one PNG image');assert.equal(unrestrictedOrPngImage.mediaAlternativeBranches.length, 2,AgentClass.name + ': a format token consumed the noun slot of a whole-media alternative');