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(agent): support coordinated payload clauses and skip clock colons in body extraction
Emre Sokulluc7dc79a773aa
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex b1b8f574e..a35bba395 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -15393,8 +15393,24 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d&& (isComposer|| SOCIAL_PUBLISH_VERBS.test(firstAfterClause.maskedText || firstAfterClause.text));if (firstAfterNegatesPublish) continue;+ let publishGoverned = this._socialPublicationCommandIn(lastBeforeClause?.text || '');+ if (!publishGoverned && beforeClauses.length > 1 && !lastBeforeClause?.isNegated) {+ for (let bIdx = beforeClauses.length - 2; bIdx >= 0; bIdx--) {+ const nextB = beforeClauses[bIdx + 1];+ const isCoord = SOCIAL_COORDINATING_DELIMITER.test(nextB.delim || '')+ || (nextB.delim || '').trim() === ',';+ if (!isCoord) break;+ const bClause = beforeClauses[bIdx];+ if (bClause.isNegated) break;+ if (SOCIAL_READ_VERBS.test(bClause.maskedText || bClause.text)) break;+ if (this._socialPublicationCommandIn(bClause.text || '')) {+ publishGoverned = true;+ break;+ }+ }+ }const governed = (isComposer && !firstAfterClause?.isNegated)- || this._socialPublicationCommandIn(lastBeforeClause?.text || '')+ || publishGoverned|| (SOCIAL_PUBLISH_DESTINATION_LEAD.test(lastBeforeClause?.text || '')&& this._socialPublicationCommandIn(firstAfterClause?.text || ''));if (!governed) continue;@@ -15444,6 +15460,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn true;}}+ for (let nextIdx = clauseIdx + 1; nextIdx < clauses.length; nextIdx++) {+ const nextClause = clauses[nextIdx];+ if (nextClause.isNegated) break;+ const isCoord = SOCIAL_COORDINATING_DELIMITER.test(nextClause.delim || '')+ || (nextClause.delim || '').trim() === ',';+ if (!isCoord) break;+ const nextTargetText = nextClause.maskedText || nextClause.text;+ if (SOCIAL_READ_VERBS.test(nextTargetText)) break;+ if (SOCIAL_PUBLISH_VERBS.test(nextTargetText)) break;+ platformPattern.lastIndex = 0;+ if (platformPattern.test(nextTargetText)) return true;+ }}return false;});@@ -22485,7 +22513,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst publishVerbPattern = `(?:${SOCIAL_PUBLISH_VERBS.source}|message|update)`;const quotedPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?:“([\\s\\S]+?)”|「([\\s\\S]+?)」|『([\\s\\S]+?)』|«([\\s\\S]+?)»|"([\\s\\S]+?)")`, 'iu');const singleQuotePattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?:(?<!\\p{L})'([\\s\\S]+?)'(?!\\p{L}))`, 'iu');- const colonPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?<!https?|ftp|sftp)[::](?!//)\\s*([\\s\\S]+)$`, 'iu');+ const colonPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?<!https?|ftp|sftp)(?:(?<!\\d)[::]|[::](?!\\d{2}))(?!\\/\\/)\\s*([\\s\\S]+)$`, 'iu');for (const text of candidates) {let body = '';// Scan for the colon delimiter that introduces the post body.@@ -22493,6 +22521,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// 1. URL schemes (e.g. "https://", "ftp://")// 2. Colons inside parentheses, brackets, or quotes (e.g. "(account: @acme):")// 3. Incidental metadata key labels (e.g. "account: @acme")+ // 4. Clock notation colons (e.g. "3:00", "14:30")const verbMatches = [...text.matchAll(new RegExp(publishVerbPattern, 'giu'))];let colonBody = '';let colonDelimIndex = -1;@@ -22539,6 +22568,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (ch === ':' || ch === '\uff1a') {if (text.slice(i, i + 3) === '://' || text.slice(i, i + 2) === ':\u2044\u2044') continue;if (/(?:https?|ftp|sftp|file|mailto)$/i.test(text.slice(Math.max(0, i - 10), i))) continue;+ if (/\d/.test(prevChar) && /^\d{2}/.test(text.slice(i + 1))) continue;if (parenDepth > 0 || bracketDepth > 0 || braceDepth > 0|| inDoubleQuote || inSingleQuote || inSmartQuote > 0 || inCjkQuote > 0 || inGuillemet > 0) {diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 1fae578e0..9b7b89242 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -13193,8 +13193,24 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d&& (isComposer|| SOCIAL_PUBLISH_VERBS.test(firstAfterClause.maskedText || firstAfterClause.text));if (firstAfterNegatesPublish) continue;+ let publishGoverned = this._socialPublicationCommandIn(lastBeforeClause?.text || '');+ if (!publishGoverned && beforeClauses.length > 1 && !lastBeforeClause?.isNegated) {+ for (let bIdx = beforeClauses.length - 2; bIdx >= 0; bIdx--) {+ const nextB = beforeClauses[bIdx + 1];+ const isCoord = SOCIAL_COORDINATING_DELIMITER.test(nextB.delim || '')+ || (nextB.delim || '').trim() === ',';+ if (!isCoord) break;+ const bClause = beforeClauses[bIdx];+ if (bClause.isNegated) break;+ if (SOCIAL_READ_VERBS.test(bClause.maskedText || bClause.text)) break;+ if (this._socialPublicationCommandIn(bClause.text || '')) {+ publishGoverned = true;+ break;+ }+ }+ }const governed = (isComposer && !firstAfterClause?.isNegated)- || this._socialPublicationCommandIn(lastBeforeClause?.text || '')+ || publishGoverned|| (SOCIAL_PUBLISH_DESTINATION_LEAD.test(lastBeforeClause?.text || '')&& this._socialPublicationCommandIn(firstAfterClause?.text || ''));if (!governed) continue;@@ -13244,6 +13260,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn true;}}+ for (let nextIdx = clauseIdx + 1; nextIdx < clauses.length; nextIdx++) {+ const nextClause = clauses[nextIdx];+ if (nextClause.isNegated) break;+ const isCoord = SOCIAL_COORDINATING_DELIMITER.test(nextClause.delim || '')+ || (nextClause.delim || '').trim() === ',';+ if (!isCoord) break;+ const nextTargetText = nextClause.maskedText || nextClause.text;+ if (SOCIAL_READ_VERBS.test(nextTargetText)) break;+ if (SOCIAL_PUBLISH_VERBS.test(nextTargetText)) break;+ platformPattern.lastIndex = 0;+ if (platformPattern.test(nextTargetText)) return true;+ }}return false;});@@ -20088,7 +20116,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst publishVerbPattern = `(?:${SOCIAL_PUBLISH_VERBS.source}|message|update)`;const quotedPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?:“([\\s\\S]+?)”|「([\\s\\S]+?)」|『([\\s\\S]+?)』|«([\\s\\S]+?)»|"([\\s\\S]+?)")`, 'iu');const singleQuotePattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?:(?<!\\p{L})'([\\s\\S]+?)'(?!\\p{L}))`, 'iu');- const colonPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?<!https?|ftp|sftp)[::](?!//)\\s*([\\s\\S]+)$`, 'iu');+ const colonPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?<!https?|ftp|sftp)(?:(?<!\\d)[::]|[::](?!\\d{2}))(?!\\/\\/)\\s*([\\s\\S]+)$`, 'iu');for (const text of candidates) {let body = '';// Scan for the colon delimiter that introduces the post body.@@ -20096,6 +20124,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// 1. URL schemes (e.g. "https://", "ftp://")// 2. Colons inside parentheses, brackets, or quotes (e.g. "(account: @acme):")// 3. Incidental metadata key labels (e.g. "account: @acme")+ // 4. Clock notation colons (e.g. "3:00", "14:30")const verbMatches = [...text.matchAll(new RegExp(publishVerbPattern, 'giu'))];let colonBody = '';let colonDelimIndex = -1;@@ -20142,6 +20171,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (ch === ':' || ch === '\uff1a') {if (text.slice(i, i + 3) === '://' || text.slice(i, i + 2) === ':\u2044\u2044') continue;if (/(?:https?|ftp|sftp|file|mailto)$/i.test(text.slice(Math.max(0, i - 10), i))) continue;+ if (/\d/.test(prevChar) && /^\d{2}/.test(text.slice(i + 1))) continue;if (parenDepth > 0 || bracketDepth > 0 || braceDepth > 0|| inDoubleQuote || inSingleQuote || inSmartQuote > 0 || inCjkQuote > 0 || inGuillemet > 0) {diff --git a/test/run.js b/test/run.jsindex e9396b277..717b4d3f4 100644--- a/test/run.js+++ b/test/run.js@@ -86404,6 +86404,12 @@ test('social publication workflow follows the live X or Bluesky destination and'guillemet quotation containing inner ASCII quote mispaired delimiters'],['Post 「He said 『hello; world』 today」 on X', ['twitter'],'nested CJK quotation marks mispaired delimiters'],+ ['Post research and development news on X', ['twitter'],+ 'payload conjunction and before on X split command and destination into separate clauses'],+ ['Post research and development news to https://x.com/home', ['twitter'],+ 'payload conjunction and before explicit social URL split command and destination into separate clauses'],+ ['Post research, development, and marketing news on X', ['twitter'],+ 'multiple payload conjunctions and commas before on X split command and destination into separate clauses'],]) {assert.deepEqual([...agent._trustedSocialPublishTargetAdapters({ taskText })],@@ -88028,6 +88034,21 @@ test('post body extraction skips incidental command colons and parenthesized met'Breaking: Version 2 is released',AgentClass.name + ': body containing colon should preserve colon after payload delimiter');+ assert.equal(+ agent._extractWorkflowTaskBody('Post on X at 3:00: Hello world'),+ 'Hello world',+ AgentClass.name + ': clock colon in at 3:00 should not be captured as body delimiter'+ );+ assert.equal(+ agent._extractWorkflowTaskBody('Post on X at 14:30: Hello world'),+ 'Hello world',+ AgentClass.name + ': 24-hour clock colon in at 14:30 should not be captured as body delimiter'+ );+ assert.equal(+ agent._extractWorkflowTaskBody('Post on X at 3:00 PM: Hello world'),+ 'Hello world',+ AgentClass.name + ': clock colon with AM/PM should not be captured as body delimiter'+ );}});