Skip to content

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

fix(agent): enforce full authored post equality, unambiguous links, and read-intent noun guards

Emre Sokullu22de30fd8812
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 66b16d335..8197ca5f0 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -240,6 +240,10 @@ const SOCIAL_READ_VERBS = new RegExp(
+ '|\u9605\u8bfb|\u95b1\u8b80|\u8bfb|\u8b80|\u67e5\u770b|\u6d4f\u89c8|\u700f\u89bd|\u8aad\u3093\u3067|\u8aad\u3080|\u8aad\u307f|\uc77d\uace0|\uc77d\uc5b4|\uc77d\uc740',
'iu',
);
+const SOCIAL_NOUN_LIKE_PUBLISH = new RegExp(
+ '^(?:posts?|tweets?|skeets?|publica[c\u00e7][i\u00ed]?[o\u00f3]n(?:es)?|publica[c\u00e7][a\u00e3]o|publica[c\u00e7][o\u00f5]es|publication|publications|\u6295\u7a3f|\u63a8\u6587)$',
+ 'iu',
+);
const SOCIAL_CLAUSE_BREAK = new RegExp('[.!?;:,\\n]|(?<![\\p{L}\\p{N}_])(?:and|then|but|or|after|before|y|luego|puis|et|ensuite|und|dann|poi|sonra|ve|затем|и)(?![\\p{L}\\p{N}_])|然后|然後|接着|そして|それから|、|。', 'iu');
// "On <url>, publish this" names a destination just as plainly as
@@ -2193,8 +2197,18 @@ export class Agent extends LoopDetector {
_workflowSocialLinkMatchesRequested(link, requested) {
if (!link || !requested) return false;
- return ['href', 'text', 'title', 'ariaLabel', 'expandedUrl']
- .some(field => this._workflowSocialDisplayedUrlMatchesRequested(link[field], requested));
+ const expected = this._workflowSocialDisplayUrl(requested);
+ if (!expected) return false;
+ return ['expandedUrl', 'title', 'ariaLabel', 'href', 'text'].some((field) => {
+ const value = link[field];
+ if (!value) return false;
+ const observed = this._workflowSocialDisplayUrl(value);
+ if (!observed) return false;
+ if (observed === expected) return true;
+ const hasEllipsis = /(?:\u2026|\.{3})$/.test(observed);
+ if (hasEllipsis) return false;
+ return observed === expected;
+ });
}
// A card also renders the author name, timestamp, and controls, so matching
@@ -2207,11 +2221,17 @@ export class Agent extends LoopDetector {
}
_workflowSocialPublishedBodyObserved(requirement, record) {
- const authoredText = this._workflowSocialAuthoredText(record);
- if (this._workflowPublishedPayloadValueObserved(requirement, { pageText: authoredText })) return true;
const expectedBody = this._workflowMessageBody(requirement?.value);
- let observedBody = this._workflowMessageBody(authoredText);
- if (!expectedBody || !observedBody) return false;
+ if (!expectedBody) return false;
+ const authoredText = this._workflowSocialAuthoredText(record);
+ const observedBody = this._workflowMessageBody(authoredText);
+ if (!observedBody) return false;
+ const hasDedicatedAuthoredText = !!this._workflowMessageBody(record?.bodyText);
+ if (hasDedicatedAuthoredText) {
+ if (observedBody === expectedBody) return true;
+ } else {
+ if (this._workflowPublishedPayloadValueObserved(requirement, { pageText: authoredText })) return true;
+ }
const links = Array.isArray(record?.links) ? record.links : [];
// "!", ";" and ":" are valid path characters, so a URL like
// https://en.wikipedia.org/wiki/Yahoo! is not punctuated, it just ends
@@ -2258,6 +2278,9 @@ export class Agent extends LoopDetector {
comparableObserved = replaceFirst(comparableObserved, displayed, marker);
if (!comparableExpected || !comparableObserved) return false;
}
+ if (hasDedicatedAuthoredText) {
+ return comparableExpected === comparableObserved;
+ }
return this._workflowPublishedPayloadValueObserved(
{ ...requirement, value: comparableExpected },
{ pageText: comparableObserved },
@@ -14744,7 +14767,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
_socialPublicationCommandIn(text) {
return String(text || '').split(SOCIAL_CLAUSE_BREAK).some((clause) => {
const publish = clause ? clause.match(SOCIAL_PUBLISH_VERBS) : null;
- return !!publish && !SOCIAL_READ_VERBS.test(clause.slice(0, publish.index));
+ if (!publish) return false;
+ const before = clause.slice(0, publish.index);
+ if (SOCIAL_READ_VERBS.test(before)) return false;
+ const after = clause.slice(publish.index + publish[0].length);
+ if (SOCIAL_NOUN_LIKE_PUBLISH.test(publish[0]) && SOCIAL_READ_VERBS.test(after)) return false;
+ return true;
});
}
@@ -14825,7 +14853,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
for (const verb of clause.matchAll(verbPattern)) {
const verbIndex = verb.index ?? 0;
if (SOCIAL_READ_VERBS.test(clause.slice(0, verbIndex))) continue;
- const afterVerb = clause.slice(verbIndex, verbIndex + (verb[0]?.length ?? 0) + 60);
+ const verbWord = verb[0] || '';
+ const afterVerbText = clause.slice(verbIndex + verbWord.length);
+ if (SOCIAL_NOUN_LIKE_PUBLISH.test(verbWord) && SOCIAL_READ_VERBS.test(afterVerbText)) continue;
+ const afterVerb = clause.slice(verbIndex, verbIndex + verbWord.length + 60);
const beforeVerb = clause.slice(Math.max(0, verbIndex - 60), verbIndex);
platformPattern.lastIndex = 0;
if (platformPattern.test(afterVerb) || platformPattern.test(beforeVerb)) return true;
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 5a33ab59d..45fcd423d 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -173,6 +173,10 @@ const SOCIAL_READ_VERBS = new RegExp(
+ '|\u9605\u8bfb|\u95b1\u8b80|\u8bfb|\u8b80|\u67e5\u770b|\u6d4f\u89c8|\u700f\u89bd|\u8aad\u3093\u3067|\u8aad\u3080|\u8aad\u307f|\uc77d\uace0|\uc77d\uc5b4|\uc77d\uc740',
'iu',
);
+const SOCIAL_NOUN_LIKE_PUBLISH = new RegExp(
+ '^(?:posts?|tweets?|skeets?|publica[c\u00e7][i\u00ed]?[o\u00f3]n(?:es)?|publica[c\u00e7][a\u00e3]o|publica[c\u00e7][o\u00f5]es|publication|publications|\u6295\u7a3f|\u63a8\u6587)$',
+ 'iu',
+);
const SOCIAL_CLAUSE_BREAK = new RegExp('[.!?;:,\\n]|(?<![\\p{L}\\p{N}_])(?:and|then|but|or|after|before|y|luego|puis|et|ensuite|und|dann|poi|sonra|ve|затем|и)(?![\\p{L}\\p{N}_])|然后|然後|接着|そして|それから|、|。', 'iu');
// "On <url>, publish this" names a destination just as plainly as
@@ -1907,8 +1911,18 @@ export class Agent extends LoopDetector {
_workflowSocialLinkMatchesRequested(link, requested) {
if (!link || !requested) return false;
- return ['href', 'text', 'title', 'ariaLabel', 'expandedUrl']
- .some(field => this._workflowSocialDisplayedUrlMatchesRequested(link[field], requested));
+ const expected = this._workflowSocialDisplayUrl(requested);
+ if (!expected) return false;
+ return ['expandedUrl', 'title', 'ariaLabel', 'href', 'text'].some((field) => {
+ const value = link[field];
+ if (!value) return false;
+ const observed = this._workflowSocialDisplayUrl(value);
+ if (!observed) return false;
+ if (observed === expected) return true;
+ const hasEllipsis = /(?:\u2026|\.{3})$/.test(observed);
+ if (hasEllipsis) return false;
+ return observed === expected;
+ });
}
// A card also renders the author name, timestamp, and controls, so matching
@@ -1921,11 +1935,17 @@ export class Agent extends LoopDetector {
}
_workflowSocialPublishedBodyObserved(requirement, record) {
- const authoredText = this._workflowSocialAuthoredText(record);
- if (this._workflowPublishedPayloadValueObserved(requirement, { pageText: authoredText })) return true;
const expectedBody = this._workflowMessageBody(requirement?.value);
- let observedBody = this._workflowMessageBody(authoredText);
- if (!expectedBody || !observedBody) return false;
+ if (!expectedBody) return false;
+ const authoredText = this._workflowSocialAuthoredText(record);
+ const observedBody = this._workflowMessageBody(authoredText);
+ if (!observedBody) return false;
+ const hasDedicatedAuthoredText = !!this._workflowMessageBody(record?.bodyText);
+ if (hasDedicatedAuthoredText) {
+ if (observedBody === expectedBody) return true;
+ } else {
+ if (this._workflowPublishedPayloadValueObserved(requirement, { pageText: authoredText })) return true;
+ }
const links = Array.isArray(record?.links) ? record.links : [];
// "!", ";" and ":" are valid path characters, so a URL like
// https://en.wikipedia.org/wiki/Yahoo! is not punctuated, it just ends
@@ -1972,6 +1992,9 @@ export class Agent extends LoopDetector {
comparableObserved = replaceFirst(comparableObserved, displayed, marker);
if (!comparableExpected || !comparableObserved) return false;
}
+ if (hasDedicatedAuthoredText) {
+ return comparableExpected === comparableObserved;
+ }
return this._workflowPublishedPayloadValueObserved(
{ ...requirement, value: comparableExpected },
{ pageText: comparableObserved },
@@ -12544,7 +12567,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
_socialPublicationCommandIn(text) {
return String(text || '').split(SOCIAL_CLAUSE_BREAK).some((clause) => {
const publish = clause ? clause.match(SOCIAL_PUBLISH_VERBS) : null;
- return !!publish && !SOCIAL_READ_VERBS.test(clause.slice(0, publish.index));
+ if (!publish) return false;
+ const before = clause.slice(0, publish.index);
+ if (SOCIAL_READ_VERBS.test(before)) return false;
+ const after = clause.slice(publish.index + publish[0].length);
+ if (SOCIAL_NOUN_LIKE_PUBLISH.test(publish[0]) && SOCIAL_READ_VERBS.test(after)) return false;
+ return true;
});
}
@@ -12625,7 +12653,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
for (const verb of clause.matchAll(verbPattern)) {
const verbIndex = verb.index ?? 0;
if (SOCIAL_READ_VERBS.test(clause.slice(0, verbIndex))) continue;
- const afterVerb = clause.slice(verbIndex, verbIndex + (verb[0]?.length ?? 0) + 60);
+ const verbWord = verb[0] || '';
+ const afterVerbText = clause.slice(verbIndex + verbWord.length);
+ if (SOCIAL_NOUN_LIKE_PUBLISH.test(verbWord) && SOCIAL_READ_VERBS.test(afterVerbText)) continue;
+ const afterVerb = clause.slice(verbIndex, verbIndex + verbWord.length + 60);
const beforeVerb = clause.slice(Math.max(0, verbIndex - 60), verbIndex);
platformPattern.lastIndex = 0;
if (platformPattern.test(afterVerb) || platformPattern.test(beforeVerb)) return true;
diff --git a/test/run.js b/test/run.js
index 47ac45c53..e22a63425 100644
--- a/test/run.js
+++ b/test/run.js
@@ -86139,6 +86139,10 @@ test('social publication workflow follows the live X or Bluesky destination and
// "post" and "posts" are nouns as often as commands. The clause decides.
['Read posts on https://x.com/home, then submit a summary in the survey', [],
'the noun "posts" was read as a publish command'],
+ ['Posts to read on X, then submit a summary in the survey', [],
+ 'noun-like publish token followed by read intent was treated as a publish command'],
+ ['Tweets to read on X, then summarize them', [],
+ 'tweets followed by read intent was treated as a publish command'],
['Read the post on https://x.com/home and submit a summary in the survey', [],
'a read verb governing "post" did not disqualify it'],
['Check the latest posts on https://x.com/home then fill the form', [],
@@ -86231,7 +86235,11 @@ test('X and Bluesky same-route publication accepts only one new permalink with t
accountIdentity: 'twitter:webbrain',
wrongAccountUrl: 'https://x.com/notwebbrain/status/4444444444444444444',
displayedRepoUrl: 'github.com/webbrain-one/…',
- repoLink: { href: 'https://t.co/abc123', text: 'github.com/webbrain-one/…' },
+ repoLink: {
+ href: 'https://t.co/abc123',
+ text: 'github.com/webbrain-one/…',
+ expandedUrl: 'https://github.com/webbrain-one/webbrain',
+ },
},
{
adapterName: 'bluesky',
@@ -86629,6 +86637,76 @@ test('X and Bluesky same-route publication accepts only one new permalink with t
), false, AgentClass.name + ': Premium body with mismatched suffix past 10k chars was accepted');
}
+ const staleFooterState = {
+ ...exactPageState,
+ workflowResourceRecords: [
+ {
+ ...exactPageState.workflowResourceRecords[0],
+ bodyText: productionNormalizedBody + '\nstale footer text',
+ text: 'WebBrain\n' + productionNormalizedBody + '\nstale footer text\n2m',
+ },
+ ],
+ };
+ assert.equal(agent._workflowPublishedResourcePayloadMatch(
+ {
+ ...submit.workflowBinding,
+ publishedResourceIdentity: fixture.expectedIdentity,
+ preDispatchPublicationAccountIdentity: fixture.accountIdentity,
+ preDispatchPublicationAccountIdentityComplete: true,
+ },
+ guard,
+ staleFooterState,
+ fixture.feedUrl,
+ submit,
+ ), false, AgentClass.name + ': bodyText with stale footer was accepted instead of requiring complete equality');
+
+ const exactBodyTextState = {
+ ...exactPageState,
+ workflowResourceRecords: [
+ {
+ ...exactPageState.workflowResourceRecords[0],
+ bodyText: productionNormalizedBody,
+ text: 'WebBrain\n' + productionNormalizedBody + '\n2m',
+ },
+ ],
+ };
+ assert.equal(agent._workflowPublishedResourcePayloadMatch(
+ {
+ ...submit.workflowBinding,
+ publishedResourceIdentity: fixture.expectedIdentity,
+ preDispatchPublicationAccountIdentity: fixture.accountIdentity,
+ preDispatchPublicationAccountIdentityComplete: true,
+ },
+ guard,
+ exactBodyTextState,
+ fixture.feedUrl,
+ submit,
+ ), true, AgentClass.name + ': exact bodyText was rejected');
+
+ if (fixture.adapterName === 'twitter') {
+ const ambiguousLinkPageState = {
+ ...exactPageState,
+ workflowResourceRecords: [
+ {
+ ...exactPageState.workflowResourceRecords[0],
+ links: [{ href: 'https://t.co/ambiguous', text: 'github.com/webbrain-one/…' }],
+ },
+ ],
+ };
+ assert.equal(agent._workflowPublishedResourcePayloadMatch(
+ {
+ ...submit.workflowBinding,
+ publishedResourceIdentity: fixture.expectedIdentity,
+ preDispatchPublicationAccountIdentity: fixture.accountIdentity,
+ preDispatchPublicationAccountIdentityComplete: true,
+ },
+ guard,
+ ambiguousLinkPageState,
+ fixture.feedUrl,
+ submit,
+ ), false, AgentClass.name + ': ambiguous truncated URL label without full URL proof was accepted');
+ }
+
assert.equal(agent._workflowTerminalEvidenceFromDone(
tabId,
exactPageState,