Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

fix(agent): scope coordinating negation, support article media counts, and refine body parsing

Emre Sokullu49378407bc33
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 9bd82abcb..7fa189091 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -259,7 +259,7 @@ const SOCIAL_CLAUSE_DELIMITER = new RegExp(
'iu',
);
const SOCIAL_COORDINATING_DELIMITER = new RegExp(
- `^(?:or|nor|and|neither|o|ou|oder|ni|nem|né|veya|ya\\s+da|или|ни|或|或者|または|もしくは|や|또는|이나|거나|,|、)$`,
+ `^(?:or|nor|and|neither|o|ou|oder|ni|nem|né|veya|ya\\s+da|или|ни|或|或者|または|もしくは|や|또는|이나|거나)$`,
'iu',
);
const SOCIAL_CLAUSE_BREAK = new RegExp(
@@ -2362,7 +2362,7 @@ export class Agent extends LoopDetector {
return wordToNum[s] || 0;
};
- const countPrefix = '(?:\\d+|one|two|three|four|five|six|seven|eight|nine|ten|single|both|multiple|un|une|deux|trois|quatre|cinq|uno|una|unos|unas|dos|tres|cuatro|cinco|due|tre|quattro|cinque|ein|eine|einen|einer|zwei|drei|vier|fünf|um|uma|dois|duas|três|один|одна|одно|два|две|три|четыре|пять|[一二两三四五六七八九十])';
+ const countPrefix = '(?:\\d+|a|an|one|two|three|four|five|six|seven|eight|nine|ten|single|both|multiple|un|une|deux|trois|quatre|cinq|uno|una|unos|unas|dos|tres|cuatro|cinco|due|tre|quattro|cinque|ein|eine|einen|einer|zwei|drei|vier|fünf|um|uma|dois|duas|três|один|одна|одно|два|две|три|четыре|пять|[一二两三四五六七八九十])';
const imageCountMatch = text.match(new RegExp(`(?:^|[\\s,;and+])(${countPrefix})\\s+(?:images?|photos?|pictures?|pics?|foto|fotos|bild|bilder|imagen(?:es)?|imágenes|画像|写真|图片|照片|圖片|изображение|фото)`, 'i'));
const expectedImageCount = imageCountMatch ? parseCountWord(imageCountMatch[1]) : 0;
@@ -22127,7 +22127,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
body = singleQuoteMatch[1].trim();
} else {
// 2. Colon-introduced body: "Publish this exact post on X:\s*<body text>", "Tweet:\s*<body text>", "Post the following on X:\s*<body text>"
- const colonMatch = text.match(/(?:publish(?:ing|es)?|post(?:ing|s)?|tweet(?:ing|s)?|message|update)[\s\S]*?:\s*([\s\S]+)$/i);
+ const colonMatch = text.match(/(?:publish(?:ing|es)?|post(?:ing|s)?|tweet(?:ing|s)?|message|update)[\s\S]*?(?<!https?|ftp|sftp):(?!\/\/)\s*([\s\S]+)$/i);
if (colonMatch && colonMatch[1]?.trim()) {
let candidateBody = colonMatch[1].trim();
const innerQuote = candidateBody.match(/^["“「『«]([\s\S]+)["”」』»]$/) || candidateBody.match(/^'([\s\S]+)'$/);
@@ -22266,8 +22266,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
field: 'body',
value: this._workflowMetadataValue(extractedBody, 25000),
}];
- guard.workflowMetadataRequirementsIncomplete = false;
- guard.workflowMetadataRequirementsResolved = true;
+ guard.workflowMetadataRequirementsIncomplete = true;
}
}
}
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index a666261cf..ae38e70d6 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -192,7 +192,7 @@ const SOCIAL_CLAUSE_DELIMITER = new RegExp(
'iu',
);
const SOCIAL_COORDINATING_DELIMITER = new RegExp(
- `^(?:or|nor|and|neither|o|ou|oder|ni|nem|né|veya|ya\\s+da|или|ни|或|或者|または|もしくは|や|또는|이나|거나|,|、)$`,
+ `^(?:or|nor|and|neither|o|ou|oder|ni|nem|né|veya|ya\\s+da|или|ни|或|或者|または|もしくは|や|또는|이나|거나)$`,
'iu',
);
const SOCIAL_CLAUSE_BREAK = new RegExp(
@@ -2076,7 +2076,7 @@ export class Agent extends LoopDetector {
return wordToNum[s] || 0;
};
- const countPrefix = '(?:\\d+|one|two|three|four|five|six|seven|eight|nine|ten|single|both|multiple|un|une|deux|trois|quatre|cinq|uno|una|unos|unas|dos|tres|cuatro|cinco|due|tre|quattro|cinque|ein|eine|einen|einer|zwei|drei|vier|fünf|um|uma|dois|duas|três|один|одна|одно|два|две|три|четыре|пять|[一二两三四五六七八九十])';
+ const countPrefix = '(?:\\d+|a|an|one|two|three|four|five|six|seven|eight|nine|ten|single|both|multiple|un|une|deux|trois|quatre|cinq|uno|una|unos|unas|dos|tres|cuatro|cinco|due|tre|quattro|cinque|ein|eine|einen|einer|zwei|drei|vier|fünf|um|uma|dois|duas|três|один|одна|одно|два|две|три|четыре|пять|[一二两三四五六七八九十])';
const imageCountMatch = text.match(new RegExp(`(?:^|[\\s,;and+])(${countPrefix})\\s+(?:images?|photos?|pictures?|pics?|foto|fotos|bild|bilder|imagen(?:es)?|imágenes|画像|写真|图片|照片|圖片|изображение|фото)`, 'i'));
const expectedImageCount = imageCountMatch ? parseCountWord(imageCountMatch[1]) : 0;
@@ -19730,7 +19730,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
body = singleQuoteMatch[1].trim();
} else {
// 2. Colon-introduced body: "Publish this exact post on X:\s*<body text>", "Tweet:\s*<body text>", "Post the following on X:\s*<body text>"
- const colonMatch = text.match(/(?:publish(?:ing|es)?|post(?:ing|s)?|tweet(?:ing|s)?|message|update)[\s\S]*?:\s*([\s\S]+)$/i);
+ const colonMatch = text.match(/(?:publish(?:ing|es)?|post(?:ing|s)?|tweet(?:ing|s)?|message|update)[\s\S]*?(?<!https?|ftp|sftp):(?!\/\/)\s*([\s\S]+)$/i);
if (colonMatch && colonMatch[1]?.trim()) {
let candidateBody = colonMatch[1].trim();
const innerQuote = candidateBody.match(/^["“「『«]([\s\S]+)["”」』»]$/) || candidateBody.match(/^'([\s\S]+)'$/);
@@ -19869,8 +19869,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
field: 'body',
value: this._workflowMetadataValue(extractedBody, 25000),
}];
- guard.workflowMetadataRequirementsIncomplete = false;
- guard.workflowMetadataRequirementsResolved = true;
+ guard.workflowMetadataRequirementsIncomplete = true;
}
}
}
diff --git a/test/run.js b/test/run.js
index 1eb37d909..3482a3301 100644
--- a/test/run.js
+++ b/test/run.js
@@ -86285,6 +86285,10 @@ test('social publication workflow follows the live X or Bluesky destination and
'single-quoted negation inside payload was treated as command negation'],
['Do not post "panic" on X', [],
'actual negation governing publish verb was missed'],
+ ['Do not submit the survey, post this on X', ['twitter'],
+ 'independent affirmative clause after negated non-publish clause separated by comma was wrongly rejected'],
+ ['Do not post on Bluesky, post this on X', ['twitter'],
+ 'independent affirmative publish clause separated by comma from negated publish clause was wrongly rejected'],
]) {
assert.deepEqual(
[...agent._trustedSocialPublishTargetAdapters({ taskText })],
@@ -87328,6 +87332,84 @@ test('a thread published with Post all binds the post carrying the reviewed body
}
});
+test('article-qualified mixed media requirements are counted and typed correctly', () => {
+ for (const AgentClass of [AgentCh, AgentFx]) {
+ const agent = new AgentClass({});
+ const req1 = agent._parseWorkflowAttachmentRequirement('an image and a video');
+ assert.equal(req1.expectedCount, 2, AgentClass.name + ': expectedCount should be 2 for an image and a video');
+ assert.equal(req1.expectedImageCount, 1, AgentClass.name + ': expectedImageCount should be 1');
+ assert.equal(req1.expectedVideoCount, 1, AgentClass.name + ': expectedVideoCount should be 1');
+ assert.equal(req1.wantsImage, true, AgentClass.name + ': wantsImage should be true');
+ assert.equal(req1.wantsVideo, true, AgentClass.name + ': wantsVideo should be true');
+
+ const req2 = agent._parseWorkflowAttachmentRequirement('an image, a video');
+ assert.equal(req2.expectedCount, 2, AgentClass.name + ': expectedCount should be 2 for an image, a video');
+ assert.equal(req2.expectedImageCount, 1, AgentClass.name + ': expectedImageCount should be 1');
+ assert.equal(req2.expectedVideoCount, 1, AgentClass.name + ': expectedVideoCount should be 1');
+
+ const req3 = agent._parseWorkflowAttachmentRequirement('a photo and a clip');
+ assert.equal(req3.expectedCount, 2, AgentClass.name + ': expectedCount should be 2 for a photo and a clip');
+ assert.equal(req3.expectedImageCount, 1);
+ assert.equal(req3.expectedVideoCount, 1);
+ }
+});
+
+test('extracting post body skips URL scheme colons', () => {
+ for (const AgentClass of [AgentCh, AgentFx]) {
+ const agent = new AgentClass({});
+ assert.equal(
+ agent._extractWorkflowTaskBody('Publish this on https://x.com/home: Hello world'),
+ 'Hello world',
+ AgentClass.name + ': URL scheme colon halted body extraction',
+ );
+ assert.equal(
+ agent._extractWorkflowTaskBody('Post to https://x.com: Hello world'),
+ 'Hello world',
+ AgentClass.name + ': URL scheme colon before domain colon halted body extraction',
+ );
+ assert.equal(
+ agent._extractWorkflowTaskBody('Post the following on https://bluesky.app/: Announcing v2!'),
+ 'Announcing v2!',
+ AgentClass.name + ': Bluesky URL scheme colon halted body extraction',
+ );
+ }
+});
+
+test('classifier fallback leaves metadata requirements incomplete and unresolved', async () => {
+ for (const [index, AgentClass] of [AgentCh, AgentFx].entries()) {
+ const agent = new AgentClass({});
+ const tabId = 9870 + index;
+ const siteWorkflow = agent._resolvePlannerSiteWorkflow('https://x.com/home', {
+ request_kind: 'execute',
+ site_job: 'publish-post',
+ });
+ const guard = agent._startPlanExecutionGuard(tabId, 'act', {
+ requestKind: 'execute',
+ requiresStateChange: true,
+ requiresSubmission: true,
+ siteWorkflow,
+ });
+ const failingProvider = {
+ chat: async () => {
+ throw new Error('Classifier network error');
+ },
+ };
+ await agent._classifyProgressIntentWithProvider(tabId, {
+ provider: failingProvider,
+ taskText: 'Publish this on X: Hello from fallback',
+ pageScope: 'https://x.com/home',
+ });
+ assert.equal(guard.workflowMetadataRequirementsIncomplete, true,
+ AgentClass.name + ': fallback should mark workflowMetadataRequirementsIncomplete as true');
+ assert.notEqual(guard.workflowMetadataRequirementsResolved, true,
+ AgentClass.name + ': fallback should not mark workflowMetadataRequirementsResolved as true');
+ assert.deepEqual(guard.workflowMetadataRequirements, [{
+ field: 'body',
+ value: 'Hello from fallback',
+ }], AgentClass.name + ': fallback should extract body requirement');
+ }
+});
+
test('YouTube metadata success requires exact app-classified post-save readback', async () => {
for (const [index, AgentClass] of [AgentCh, AgentFx].entries()) {
const agent = new AgentClass({ getActive: () => ({ chat: async () => ({ content: '{}' }) }) });