Skip to content

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

fix(social-publish): tighten media alternative evidence

Barack Sokullu6f83ac97d2c4
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 318ab5fcc..5fdab4537 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -2924,7 +2924,7 @@ export class Agent extends LoopDetector {
if (target) return target.toLowerCase();
}
const suffixMatch = text.match(/^(.+?)\s*(?:の|의)?\s*(?:images?|photos?|pictures?|videos?|gifs?|animated\s+gifs?|attachments?|files?|bilder?|fotos?|vidéos?|archivos?|dateien?|allegat[oi]?|anexos?|вложения?|사진|이미지|동영상|画像|写真|视频|影片)$/i);
- if (suffixMatch) {
+ if (suffixMatch && !/\.$/.test(suffixMatch[1].trim())) {
let target = suffixMatch[1].trim();
target = target.replace(/^['"“”«»`]+|['"“”«»`]+$/g, '').trim();
if (target) return target.toLowerCase();
@@ -2954,10 +2954,6 @@ export class Agent extends LoopDetector {
if (att.name) rawCandidates.push(String(att.name));
if (att.src) rawCandidates.push(String(att.src));
if (att.url) rawCandidates.push(String(att.url));
- if (att.alt) rawCandidates.push(String(att.alt));
- if (att.title) rawCandidates.push(String(att.title));
- if (att.ariaLabel) rawCandidates.push(String(att.ariaLabel));
- if (att.text) rawCandidates.push(String(att.text));
}
const candidateNames = new Set();
@@ -2985,7 +2981,13 @@ export class Agent extends LoopDetector {
let last = segments[segments.length - 1];
try { last = decodeURIComponent(last); } catch {}
last = last.trim().toLowerCase();
- if (last) candidateNames.add(last);
+ if (last) {
+ candidateNames.add(last);
+ // X transcodes an uploaded .gif to a source path ending in
+ // .gif.mp4. The source is provenance-bearing, so retain the
+ // original logical filename without consulting descriptive alt.
+ if (/\.gif\.mp4$/i.test(last)) candidateNames.add(last.slice(0, -4));
+ }
}
} catch {
const withoutQuery = trimmed.split(/[?#]/)[0];
@@ -3334,12 +3336,30 @@ export class Agent extends LoopDetector {
const specificTargets = this._parseSpecificAttachmentTargets(rawVal);
// Word joiners need surrounding whitespace so a filename such as
// report-or-draft.png remains one target. CJK joiners need no spaces.
- const disjunctionSplit = /(?:\s+(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+|\s*(?:或者|或|または|それとも|또는|혹은)\s*)/iu;
+ const disjunctionSplit = /(?:\s*[,;]\s*(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+|\s+(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+|\s*(?:或者|或|または|それとも|또는|혹은)\s*)/iu;
let specificTargetAlternatives = DISJUNCTION_REGEX.test(text)
? this._parseSpecificAttachmentTargets(rawVal, disjunctionSplit)
.map(group => this._parseSpecificAttachmentTargets(group))
.filter(group => group.length > 0)
: [];
+ // A terminal ", or" marks an enumerated choice list rather than a
+ // conjunctive comma list. Preserve every listed filename as its own
+ // branch, including the common "one of a, b, or c" spelling.
+ const maskedSpecificTargets = this._maskQuotedPayload(String(rawVal || ''));
+ const commaDisjunction = /[,;]\s*(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+/iu;
+ if (commaDisjunction.test(maskedSpecificTargets)) {
+ const enumeratedTargets = specificTargets.map(target => (
+ target.replace(/^(?:either|one\s+of)\s+/iu, '')
+ )).filter(Boolean);
+ const firstHasChoiceMarker = /^(?:either|one\s+of)\s+/iu.test(specificTargets[0] || '');
+ const [commaChoicePrefix = '', commaChoiceTail = ''] = maskedSpecificTargets.split(commaDisjunction);
+ const hasConjunctivePrefix = /\s+(?:and|und|et|e|y|ve|и|as\s+well\s+as|&)\s+/iu.test(commaChoicePrefix);
+ const hasTrailingConjunct = /(?:[,;]\s*|\s+)(?:and|und|et|e|y|ve|и|as\s+well\s+as|&)\s+/iu.test(commaChoiceTail);
+ if (enumeratedTargets.length > 1 && !hasTrailingConjunct
+ && (firstHasChoiceMarker || !hasConjunctivePrefix)) {
+ specificTargetAlternatives = enumeratedTargets.map(target => [target]);
+ }
+ }
// In "logo.png and either chart.png or graph.png, and caption.png",
// `either` scopes the choice while the surrounding conjuncts remain
// requirements in both branches. Distribute both sides instead of
@@ -3656,6 +3676,7 @@ export class Agent extends LoopDetector {
const matchesVideoAlt = alternativeVideoCount >= minVideos
&& (!exactVideoAlt || alternativeVideoCount === expectedAlternativeVideoCount)
&& (!isAlternativeVideoMaximum || alternativeVideoCount <= expectedAlternativeVideoCount)
+ && (!(parsed.wantsGif && !parsed.wantsOrdinaryVideo) || rawAttachments.length === gifCount)
&& imageCount === 0
&& (!exactVideoAlt || rawAttachments.length === expectedAlternativeVideoCount)
&& (!isAlternativeVideoMaximum || rawAttachments.length <= expectedAlternativeVideoCount);
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index d0b3b6fa1..ac075c21e 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -2639,7 +2639,7 @@ export class Agent extends LoopDetector {
if (target) return target.toLowerCase();
}
const suffixMatch = text.match(/^(.+?)\s*(?:の|의)?\s*(?:images?|photos?|pictures?|videos?|gifs?|animated\s+gifs?|attachments?|files?|bilder?|fotos?|vidéos?|archivos?|dateien?|allegat[oi]?|anexos?|вложения?|사진|이미지|동영상|画像|写真|视频|影片)$/i);
- if (suffixMatch) {
+ if (suffixMatch && !/\.$/.test(suffixMatch[1].trim())) {
let target = suffixMatch[1].trim();
target = target.replace(/^['"“”«»`]+|['"“”«»`]+$/g, '').trim();
if (target) return target.toLowerCase();
@@ -2669,10 +2669,6 @@ export class Agent extends LoopDetector {
if (att.name) rawCandidates.push(String(att.name));
if (att.src) rawCandidates.push(String(att.src));
if (att.url) rawCandidates.push(String(att.url));
- if (att.alt) rawCandidates.push(String(att.alt));
- if (att.title) rawCandidates.push(String(att.title));
- if (att.ariaLabel) rawCandidates.push(String(att.ariaLabel));
- if (att.text) rawCandidates.push(String(att.text));
}
const candidateNames = new Set();
@@ -2700,7 +2696,13 @@ export class Agent extends LoopDetector {
let last = segments[segments.length - 1];
try { last = decodeURIComponent(last); } catch {}
last = last.trim().toLowerCase();
- if (last) candidateNames.add(last);
+ if (last) {
+ candidateNames.add(last);
+ // X transcodes an uploaded .gif to a source path ending in
+ // .gif.mp4. The source is provenance-bearing, so retain the
+ // original logical filename without consulting descriptive alt.
+ if (/\.gif\.mp4$/i.test(last)) candidateNames.add(last.slice(0, -4));
+ }
}
} catch {
const withoutQuery = trimmed.split(/[?#]/)[0];
@@ -3049,12 +3051,30 @@ export class Agent extends LoopDetector {
const specificTargets = this._parseSpecificAttachmentTargets(rawVal);
// Word joiners need surrounding whitespace so a filename such as
// report-or-draft.png remains one target. CJK joiners need no spaces.
- const disjunctionSplit = /(?:\s+(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+|\s*(?:或者|或|または|それとも|또는|혹은)\s*)/iu;
+ const disjunctionSplit = /(?:\s*[,;]\s*(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+|\s+(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+|\s*(?:或者|或|または|それとも|또는|혹은)\s*)/iu;
let specificTargetAlternatives = DISJUNCTION_REGEX.test(text)
? this._parseSpecificAttachmentTargets(rawVal, disjunctionSplit)
.map(group => this._parseSpecificAttachmentTargets(group))
.filter(group => group.length > 0)
: [];
+ // A terminal ", or" marks an enumerated choice list rather than a
+ // conjunctive comma list. Preserve every listed filename as its own
+ // branch, including the common "one of a, b, or c" spelling.
+ const maskedSpecificTargets = this._maskQuotedPayload(String(rawVal || ''));
+ const commaDisjunction = /[,;]\s*(?:or|oder|ou|o|oppure|или|либо|veya|ya\s+da)\s+/iu;
+ if (commaDisjunction.test(maskedSpecificTargets)) {
+ const enumeratedTargets = specificTargets.map(target => (
+ target.replace(/^(?:either|one\s+of)\s+/iu, '')
+ )).filter(Boolean);
+ const firstHasChoiceMarker = /^(?:either|one\s+of)\s+/iu.test(specificTargets[0] || '');
+ const [commaChoicePrefix = '', commaChoiceTail = ''] = maskedSpecificTargets.split(commaDisjunction);
+ const hasConjunctivePrefix = /\s+(?:and|und|et|e|y|ve|и|as\s+well\s+as|&)\s+/iu.test(commaChoicePrefix);
+ const hasTrailingConjunct = /(?:[,;]\s*|\s+)(?:and|und|et|e|y|ve|и|as\s+well\s+as|&)\s+/iu.test(commaChoiceTail);
+ if (enumeratedTargets.length > 1 && !hasTrailingConjunct
+ && (firstHasChoiceMarker || !hasConjunctivePrefix)) {
+ specificTargetAlternatives = enumeratedTargets.map(target => [target]);
+ }
+ }
// In "logo.png and either chart.png or graph.png, and caption.png",
// `either` scopes the choice while the surrounding conjuncts remain
// requirements in both branches. Distribute both sides instead of
@@ -3371,6 +3391,7 @@ export class Agent extends LoopDetector {
const matchesVideoAlt = alternativeVideoCount >= minVideos
&& (!exactVideoAlt || alternativeVideoCount === expectedAlternativeVideoCount)
&& (!isAlternativeVideoMaximum || alternativeVideoCount <= expectedAlternativeVideoCount)
+ && (!(parsed.wantsGif && !parsed.wantsOrdinaryVideo) || rawAttachments.length === gifCount)
&& imageCount === 0
&& (!exactVideoAlt || rawAttachments.length === expectedAlternativeVideoCount)
&& (!isAlternativeVideoMaximum || rawAttachments.length <= expectedAlternativeVideoCount);
diff --git a/test/run.js b/test/run.js
index 59ce9e237..5f7a29792 100644
--- a/test/run.js
+++ b/test/run.js
@@ -92901,6 +92901,18 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {
assert.equal(agent._workflowSocialPublishedAttachmentObserved(
{ value: 'up to two GIFs' }, { attachments: [] }), true,
AgentClass.name + ': zero GIFs should satisfy a standalone GIF maximum');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'at most two GIFs or one image' }, { attachments: [video(1)] }), false,
+ AgentClass.name + ': ordinary video satisfied neither GIF-maximum nor image alternative');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'at most two GIFs or one image' }, { attachments: [video(1), video(2)] }), false,
+ AgentClass.name + ': ordinary videos were counted under the GIF-maximum alternative');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'at most two GIFs or one image' }, { attachments: [gif(1)] }), true,
+ AgentClass.name + ': valid GIF-maximum alternative was rejected');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'at most two GIFs or one image' }, { attachments: [image(1)] }), true,
+ AgentClass.name + ': valid image alternative was rejected');
}
});
@@ -93204,7 +93216,14 @@ test('attachment verification matches specific attachment names without substrin
{ value: 'chart.png' },
{ attachments: [{ type: 'image', src: 'https://pbs.twimg.com/media/random-id.jpg', alt: 'Uploaded chart.png' }] }
);
- assert.equal(exactChartAlt, true, AgentClass.name + ': alt with chart.png should satisfy chart.png');
+ assert.equal(exactChartAlt, false, AgentClass.name + ': alt text was treated as attachment filename evidence');
+
+ const wrongNameExactAlt = agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'chart.png' },
+ { attachments: [{ type: 'image', name: 'wrong.png', src: 'https://pbs.twimg.com/media/random-id.jpg', alt: 'chart.png' }] },
+ );
+ assert.equal(wrongNameExactAlt, false,
+ AgentClass.name + ': exact requested filename in alt text overrode wrong upload provenance');
const cleanedPrefixAccepted = agent._workflowSocialPublishedAttachmentObserved(
{ value: 'an image of chart.png' },
@@ -93308,6 +93327,24 @@ test('attachment verification matches specific attachment names without substrin
[['chart.png'], ['graph.png']],
AgentClass.name + ': either modifier became part of a filename alternative',
);
+ for (const commaChoice of [
+ 'chart.png, graph.png, or logo.png',
+ 'one of chart.png, graph.png, or logo.png',
+ ]) {
+ assert.deepEqual(
+ agent._parseWorkflowAttachmentRequirement(commaChoice).specificTargetAlternatives,
+ [['chart.png'], ['graph.png'], ['logo.png']],
+ AgentClass.name + `: Oxford-comma attachment choices were not preserved for "${commaChoice}"`,
+ );
+ assert.equal(
+ agent._workflowSocialPublishedAttachmentObserved(
+ { value: commaChoice },
+ { attachments: [{ type: 'image', src: 'https://pbs.twimg.com/media/graph.png' }] },
+ ),
+ true,
+ AgentClass.name + `: one permitted Oxford-comma attachment was rejected for "${commaChoice}"`,
+ );
+ }
assert.deepEqual(
agent._parseWorkflowAttachmentRequirement('report-or-draft.png').specificTargetAlternatives,
[],