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): proper-name scope, polite requests, plus ellipsis
Barack Sokulluda2fac1134fe
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex d3c4629fb..915348442 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -288,6 +288,10 @@ const SOCIAL_COORDINATING_DELIMITER = new RegExp(// destination, but it must not carry polarity: "do not post on X, then post on// Bluesky" starts a new command while "post on X, then on Bluesky" names two.const SOCIAL_SEQUENTIAL_DELIMITER = /^(?:then|luego|puis|ensuite|dann|poi|sonra|затем|然后|然後|接着|そして|それから)$/iu;+// A proper name can masquerade as a leading publication verb: "Post Malone+// is on Bluesky." is prose about a person, not a command. Post + Name ++// copula/reporting verb stays body prose instead of opening a new command.+const SOCIAL_PROPER_NAME_PROSE_LEAD = /^post\s+[A-Z][a-z]+(?:'[a-z]+)?\s+(?:is|are|was|were|be|been|being|has|have|had|say|says|said|announce|announces|announced)\b/i;const SOCIAL_CLAUSE_BREAK = new RegExp(`[.!?;:,\\n]|(?<![${SOCIAL_WORD_EDGE}])(?:and|then|but|or|nor|after|before|y|e|ed|luego|puis|et|ensuite|und|dann|poi|sonra|ve|затем|и)(?![${SOCIAL_WORD_EDGE}])|然后|然後|接着|そして|それから|または|、|。`,'iu',@@ -3096,17 +3100,19 @@ export class Agent extends LoopDetector {// Elliptical conjunction ("one PNG and one JPEG image") omits the first// media noun. Restore it so each counted format parses as its own// conjunctive clause; "or" choices keep sharing one noun and are handled- // by the format-qualifier grammar instead.+ // by the format-qualifier grammar instead. The other unambiguously+ // conjunctive separators ("plus", "also", "as well as") restore alike.{const ellipticalCount = '(?:\\d+|zero|one|two|three|four|five|six|seven|eight|nine|ten|a|an|single|both)';+ const ellipticalConjunction = '(and|plus|also|as\\s+well\\s+as)';text = text.replace(- new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${ellipticalCount})\\s+(${IMAGE_ATTACHMENT_FORMAT})\\s+and\\s+(${ellipticalCount})\\s+(${IMAGE_ATTACHMENT_FORMAT})\\s+(images?|photos?|pictures?|pics?)(?![${SOCIAL_WORD_EDGE}])`, 'giu'),- '$1 $2 $5 and $3 $4 $5',+ new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${ellipticalCount})\\s+(${IMAGE_ATTACHMENT_FORMAT})\\s+${ellipticalConjunction}\\s+(${ellipticalCount})\\s+(${IMAGE_ATTACHMENT_FORMAT})\\s+(images?|photos?|pictures?|pics?)(?![${SOCIAL_WORD_EDGE}])`, 'giu'),+ '$1 $2 $6 $3 $4 $5 $6',).replace(- new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${ellipticalCount})\\s+(${VIDEO_ATTACHMENT_FORMAT})\\s+and\\s+(${ellipticalCount})\\s+(${VIDEO_ATTACHMENT_FORMAT})\\s+(videos?|clips?|recordings?)(?![${SOCIAL_WORD_EDGE}])`, 'giu'),- '$1 $2 $5 and $3 $4 $5',+ new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${ellipticalCount})\\s+(${VIDEO_ATTACHMENT_FORMAT})\\s+${ellipticalConjunction}\\s+(${ellipticalCount})\\s+(${VIDEO_ATTACHMENT_FORMAT})\\s+(videos?|clips?|recordings?)(?![${SOCIAL_WORD_EDGE}])`, 'giu'),+ '$1 $2 $6 $3 $4 $5 $6',);}@@ -18062,7 +18068,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}if (inColonBodyScope) {const clauseDelim = clause.delim || '';- const leadsWithPublish = startsWithPublishVerb.test(String(clause.maskedText || clause.text || '').trimStart());+ const leadText = String(clause.maskedText || clause.text || '').trimStart();+ const leadsWithPublish = startsWithPublishVerb.test(leadText)+ && !SOCIAL_PROPER_NAME_PROSE_LEAD.test(leadText);if (!SOCIAL_COORDINATING_DELIMITER.test(clauseDelim)&& !SOCIAL_SEQUENTIAL_DELIMITER.test(clauseDelim)&& clauseDelim.trim() !== ','@@ -26798,6 +26806,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst startsNewPublication = (clauseMasked) => {const text = String(clauseMasked || '');if (!SOCIAL_PUBLISH_VERBS.test(text)) return false;+ if (SOCIAL_PROPER_NAME_PROSE_LEAD.test(text.trimStart())) return false;for (const platformMatch of text.matchAll(new RegExp(anyPlatformPattern.source, 'giu'))) {const before = text.slice(0, platformMatch.index || 0);const prep = before.match(new RegExp(`(?:${destinationPrepPattern})\\s+(?:the\\s+)?$`, 'iu'));@@ -26821,12 +26830,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d);const metadataAttachmentVerb = /(?<![\p{L}\p{N}_])(?:attach(?:ed|ing|ment)?s?|upload(?:ed|ing|s)?|detach(?:ed|ing)?)(?![\p{L}\p{N}_])/iu;const metadataNarrativeSubject = /(?<![\p{L}\p{N}_])(?:i|we|you|he|she|they|it)(?![\p{L}\p{N}_])[\s,]*$/iu;+ const metadataPoliteRequest = /(?<![\p{L}\p{N}_])(?:could|can|would|will|shall|should|may|might|please)(?:\s+you)?(?![\p{L}\p{N}_])[\s,]*$/iu;const startsMetadataInstruction = (clauseMasked) => {const text = String(clauseMasked || '');if (!metadataInstructionPattern.test(text)) return false;const verb = text.match(metadataAttachmentVerb);if (!verb) return true;- return !metadataNarrativeSubject.test(text.slice(0, verb.index));+ const before = text.slice(0, verb.index);+ return !metadataNarrativeSubject.test(before) || metadataPoliteRequest.test(before);};for (const rawCandidate of rawCandidates) {const clauses = this._socialPublicationClauses(rawCandidate);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 843b1f8c7..cd1368df1 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -222,6 +222,10 @@ const SOCIAL_COORDINATING_DELIMITER = new RegExp(// destination, but it must not carry polarity: "do not post on X, then post on// Bluesky" starts a new command while "post on X, then on Bluesky" names two.const SOCIAL_SEQUENTIAL_DELIMITER = /^(?:then|luego|puis|ensuite|dann|poi|sonra|затем|然后|然後|接着|そして|それから)$/iu;+// A proper name can masquerade as a leading publication verb: "Post Malone+// is on Bluesky." is prose about a person, not a command. Post + Name ++// copula/reporting verb stays body prose instead of opening a new command.+const SOCIAL_PROPER_NAME_PROSE_LEAD = /^post\s+[A-Z][a-z]+(?:'[a-z]+)?\s+(?:is|are|was|were|be|been|being|has|have|had|say|says|said|announce|announces|announced)\b/i;const SOCIAL_CLAUSE_BREAK = new RegExp(`[.!?;:,\\n]|(?<![${SOCIAL_WORD_EDGE}])(?:and|then|but|or|nor|after|before|y|e|ed|luego|puis|et|ensuite|und|dann|poi|sonra|ve|затем|и)(?![${SOCIAL_WORD_EDGE}])|然后|然後|接着|そして|それから|または|、|。`,'iu',@@ -2811,17 +2815,19 @@ export class Agent extends LoopDetector {// Elliptical conjunction ("one PNG and one JPEG image") omits the first// media noun. Restore it so each counted format parses as its own// conjunctive clause; "or" choices keep sharing one noun and are handled- // by the format-qualifier grammar instead.+ // by the format-qualifier grammar instead. The other unambiguously+ // conjunctive separators ("plus", "also", "as well as") restore alike.{const ellipticalCount = '(?:\\d+|zero|one|two|three|four|five|six|seven|eight|nine|ten|a|an|single|both)';+ const ellipticalConjunction = '(and|plus|also|as\\s+well\\s+as)';text = text.replace(- new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${ellipticalCount})\\s+(${IMAGE_ATTACHMENT_FORMAT})\\s+and\\s+(${ellipticalCount})\\s+(${IMAGE_ATTACHMENT_FORMAT})\\s+(images?|photos?|pictures?|pics?)(?![${SOCIAL_WORD_EDGE}])`, 'giu'),- '$1 $2 $5 and $3 $4 $5',+ new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${ellipticalCount})\\s+(${IMAGE_ATTACHMENT_FORMAT})\\s+${ellipticalConjunction}\\s+(${ellipticalCount})\\s+(${IMAGE_ATTACHMENT_FORMAT})\\s+(images?|photos?|pictures?|pics?)(?![${SOCIAL_WORD_EDGE}])`, 'giu'),+ '$1 $2 $6 $3 $4 $5 $6',).replace(- new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${ellipticalCount})\\s+(${VIDEO_ATTACHMENT_FORMAT})\\s+and\\s+(${ellipticalCount})\\s+(${VIDEO_ATTACHMENT_FORMAT})\\s+(videos?|clips?|recordings?)(?![${SOCIAL_WORD_EDGE}])`, 'giu'),- '$1 $2 $5 and $3 $4 $5',+ new RegExp(`(?<![${SOCIAL_WORD_EDGE}])(${ellipticalCount})\\s+(${VIDEO_ATTACHMENT_FORMAT})\\s+${ellipticalConjunction}\\s+(${ellipticalCount})\\s+(${VIDEO_ATTACHMENT_FORMAT})\\s+(videos?|clips?|recordings?)(?![${SOCIAL_WORD_EDGE}])`, 'giu'),+ '$1 $2 $6 $3 $4 $5 $6',);}@@ -15861,7 +15867,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}if (inColonBodyScope) {const clauseDelim = clause.delim || '';- const leadsWithPublish = startsWithPublishVerb.test(String(clause.maskedText || clause.text || '').trimStart());+ const leadText = String(clause.maskedText || clause.text || '').trimStart();+ const leadsWithPublish = startsWithPublishVerb.test(leadText)+ && !SOCIAL_PROPER_NAME_PROSE_LEAD.test(leadText);if (!SOCIAL_COORDINATING_DELIMITER.test(clauseDelim)&& !SOCIAL_SEQUENTIAL_DELIMITER.test(clauseDelim)&& clauseDelim.trim() !== ','@@ -24405,6 +24413,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst startsNewPublication = (clauseMasked) => {const text = String(clauseMasked || '');if (!SOCIAL_PUBLISH_VERBS.test(text)) return false;+ if (SOCIAL_PROPER_NAME_PROSE_LEAD.test(text.trimStart())) return false;for (const platformMatch of text.matchAll(new RegExp(anyPlatformPattern.source, 'giu'))) {const before = text.slice(0, platformMatch.index || 0);const prep = before.match(new RegExp(`(?:${destinationPrepPattern})\\s+(?:the\\s+)?$`, 'iu'));@@ -24428,12 +24437,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d);const metadataAttachmentVerb = /(?<![\p{L}\p{N}_])(?:attach(?:ed|ing|ment)?s?|upload(?:ed|ing|s)?|detach(?:ed|ing)?)(?![\p{L}\p{N}_])/iu;const metadataNarrativeSubject = /(?<![\p{L}\p{N}_])(?:i|we|you|he|she|they|it)(?![\p{L}\p{N}_])[\s,]*$/iu;+ const metadataPoliteRequest = /(?<![\p{L}\p{N}_])(?:could|can|would|will|shall|should|may|might|please)(?:\s+you)?(?![\p{L}\p{N}_])[\s,]*$/iu;const startsMetadataInstruction = (clauseMasked) => {const text = String(clauseMasked || '');if (!metadataInstructionPattern.test(text)) return false;const verb = text.match(metadataAttachmentVerb);if (!verb) return true;- return !metadataNarrativeSubject.test(text.slice(0, verb.index));+ const before = text.slice(0, verb.index);+ return !metadataNarrativeSubject.test(before) || metadataPoliteRequest.test(before);};for (const rawCandidate of rawCandidates) {const clauses = this._socialPublicationClauses(rawCandidate);diff --git a/test/run.js b/test/run.jsindex e79659c18..7bd870e9e 100644--- a/test/run.js+++ b/test/run.js@@ -91027,6 +91027,8 @@ test('social publication workflow follows the live X or Bluesky destination and'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: Hello. Post Malone is on Bluesky.', ['twitter'],+ 'proper-name prose left colon scope and adopted Bluesky'],['Do not publish anything; open https://x.com/compose/post to inspect it, then submit findings in the form', [],'a prohibited composer URL was adopted as a publish destination'],['Post on X: hello. Post on Bluesky: world', ['twitter', 'bluesky'],@@ -91199,6 +91201,10 @@ test('social destination rebinding refreshes platform-specific payload and uploaAgentClass.name + ': prose mentioning an upload without media ended the post body');assert.equal(agent._extractWorkflowTaskBody('Post on X: Hello. I upload photos every weekend.', '', 'twitter'), 'Hello. I upload photos every weekend.',AgentClass.name + ': narrative prose naming media ended the post body');+ assert.equal(agent._extractWorkflowTaskBody('Post on X: Hello. Could you attach image.png?', '', 'twitter'), 'Hello',+ AgentClass.name + ': a polite attachment request contaminated the post body');+ assert.equal(agent._extractWorkflowTaskBody('Post on X: Hello. Post Malone is on Bluesky.', '', 'twitter'), 'Hello. Post Malone is on Bluesky.',+ AgentClass.name + ': proper-name prose truncated the post body');assert.equal(agent._extractWorkflowTaskBody('Post on X: Hello world. Then let me know when it is done', '', 'twitter'), 'Hello world',AgentClass.name + ': sequential follow-up instruction contaminated the post body');assert.equal(agent._workflowExtractedBodySupersedesClassified('Alpha beta', 'Alpha beta gamma delta'), true,@@ -93276,6 +93282,13 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'one PNG and one JPEG image' }, { attachments: [image(1)] },), false, AgentClass.name + ': one PNG satisfied a two-format elliptical conjunction');+ const ellipticalPlusFormats = agent._parseWorkflowAttachmentRequirement('one PNG plus one JPEG image');+ assert.equal(ellipticalPlusFormats.isGeneric, true,+ AgentClass.name + ': an elliptical plus-format conjunction was parsed as filenames');+ assert.deepEqual(ellipticalPlusFormats.imageFormatCounts, [+ { format: 'png', count: 1 },+ { format: 'jpeg', count: 1 },+ ], AgentClass.name + ': elliptical plus-format counts were not distributed');for (const [attachments, expected, message] of [[[{ type: 'image', src: 'https://cdn.example/a.jpg' }], true, 'the required JPEG was rejected by a separate PNG prohibition'],[[{ type: 'image', src: 'https://cdn.example/a.webp' }], false, 'an unrequested WebP satisfied a required JPEG'],