Skip to content

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

fix(agent): scan full clause before explicit social URLs and fix multi-embed exclusion predicate

Emre Sokullu22c6ef772001
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 9a6082465..07e41113a 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -15308,11 +15308,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// so it is a destination only when publication language governs it.
// A composer route needs no verb: it is a destination by construction,
// in any language.
- const before = trustedContext.slice(Math.max(0, match.index - 60), match.index);
- const after = trustedContext.slice(
- match.index + match[0].length,
- match.index + match[0].length + 60,
- );
+ const before = trustedContext.slice(0, match.index);
+ const after = trustedContext.slice(match.index + match[0].length);
const beforeClauses = this._socialPublicationClauses(before);
let lastBeforeClause = beforeClauses[beforeClauses.length - 1];
if (lastBeforeClause && !lastBeforeClause.text.trim()) {
diff --git a/src/chrome/src/agent/completion-invariant.js b/src/chrome/src/agent/completion-invariant.js
index 80e1a6919..7ac904901 100644
--- a/src/chrome/src/agent/completion-invariant.js
+++ b/src/chrome/src/agent/completion-invariant.js
@@ -330,7 +330,7 @@ export function publicationResourceRecordRoot(link, identity, publicationResourc
const found = identityOf(candidate);
if (!found || found === value) continue;
if (isInsideAuthoredText(candidate)) continue;
- if (excluded.some(node => node === candidate || node.contains?.(node))) continue;
+ if (excluded.some(node => node === candidate || node.contains?.(candidate))) continue;
let embedContainer = null;
if (embedSelector) {
try {
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index ce30559ff..ed0d5d7c2 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -13108,11 +13108,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// so it is a destination only when publication language governs it.
// A composer route needs no verb: it is a destination by construction,
// in any language.
- const before = trustedContext.slice(Math.max(0, match.index - 60), match.index);
- const after = trustedContext.slice(
- match.index + match[0].length,
- match.index + match[0].length + 60,
- );
+ const before = trustedContext.slice(0, match.index);
+ const after = trustedContext.slice(match.index + match[0].length);
const beforeClauses = this._socialPublicationClauses(before);
let lastBeforeClause = beforeClauses[beforeClauses.length - 1];
if (lastBeforeClause && !lastBeforeClause.text.trim()) {
diff --git a/src/firefox/src/agent/completion-invariant.js b/src/firefox/src/agent/completion-invariant.js
index 80e1a6919..7ac904901 100644
--- a/src/firefox/src/agent/completion-invariant.js
+++ b/src/firefox/src/agent/completion-invariant.js
@@ -330,7 +330,7 @@ export function publicationResourceRecordRoot(link, identity, publicationResourc
const found = identityOf(candidate);
if (!found || found === value) continue;
if (isInsideAuthoredText(candidate)) continue;
- if (excluded.some(node => node === candidate || node.contains?.(node))) continue;
+ if (excluded.some(node => node === candidate || node.contains?.(candidate))) continue;
let embedContainer = null;
if (embedSelector) {
try {
diff --git a/test/run.js b/test/run.js
index 86bf74b76..845e29ea4 100644
--- a/test/run.js
+++ b/test/run.js
@@ -24649,6 +24649,54 @@ test('publication resource records keep the owning social card when it embeds an
assert.equal(foreignRecord.root, foreignCard, `${label}: authored permalink discarded the owning card`);
assert.deepEqual(foreignRecord.excluded, [], `${label}: authored foreign permalink was treated as an embedded post`);
assert.deepEqual(foreignRecord.authored, [foreignBodyNode], `${label}: authored body containing foreign permalink was lost`);
+
+ // A card with multiple distinct embedded posts excludes all of them without
+ // letting the first exclusion short-circuit later embedded post exclusions.
+ const embedCandidate1 = {
+ getAttribute: () => '/other/status/333',
+ href: '/other/status/333',
+ closest: sel => (sel && (sel.includes('quote') || sel.includes('embed')) ? embedContainer1 : null),
+ };
+ const embedContainer1 = {
+ querySelectorAll: () => [embedCandidate1],
+ contains: node => node === embedCandidate1 || node === embedContainer1,
+ };
+ embedCandidate1.parentElement = embedContainer1;
+
+ const embedCandidate2 = {
+ getAttribute: () => '/other/status/444',
+ href: '/other/status/444',
+ closest: sel => (sel && (sel.includes('quote') || sel.includes('embed')) ? embedContainer2 : null),
+ };
+ const embedContainer2 = {
+ querySelectorAll: () => [embedCandidate2],
+ contains: node => node === embedCandidate2 || node === embedContainer2,
+ };
+ embedCandidate2.parentElement = embedContainer2;
+
+ const multiEmbedPermalink = {
+ innerText: '2m',
+ getAttribute: () => '/me/status/222',
+ href: '/me/status/222',
+ closest: () => multiEmbedCard,
+ };
+ const multiEmbedCard = {
+ innerText: 'Author\nQuoting two posts',
+ querySelectorAll: selector => {
+ const s = String(selector);
+ if (s.includes('Text')) return [];
+ return [multiEmbedPermalink, embedCandidate1, embedCandidate2];
+ },
+ contains: node => [multiEmbedCard, multiEmbedPermalink, embedCandidate1, embedContainer1, embedCandidate2, embedContainer2].includes(node),
+ };
+ multiEmbedPermalink.parentElement = multiEmbedCard;
+ embedContainer1.parentElement = multiEmbedCard;
+ embedContainer2.parentElement = multiEmbedCard;
+
+ const multiEmbedRecord = invariant.publicationResourceRecordRoot(multiEmbedPermalink, identity, identityOf);
+ assert.equal(multiEmbedRecord.root, multiEmbedCard, `${label}: multi-embed discarded the owning card`);
+ assert.deepEqual(multiEmbedRecord.excluded, [embedContainer1, embedContainer2],
+ `${label}: failed to exclude multiple distinct embedded posts`);
}
for (const [label, rel] of [
@@ -86338,6 +86386,10 @@ test('social publication workflow follows the live X or Bluesky destination and
'long quoted body before to Bluesky was cut off by character window'],
['Post "Check our thoughts on X" to Bluesky', ['bluesky'],
'platform mentioned inside quoted body leaked into target detection'],
+ ['Post "This is a very long announcement body that contains far more than fifty or sixty characters and explains everything clearly" on https://x.com/home', ['twitter'],
+ 'long quoted body before on https://x.com/home was cut off by character window'],
+ ['Post "This is a very long announcement body that contains far more than fifty or sixty characters and explains everything clearly" to https://bsky.app/', ['bluesky'],
+ 'long quoted body before to https://bsky.app/ was cut off by character window'],
]) {
assert.deepEqual(
[...agent._trustedSocialPublishTargetAdapters({ taskText })],