Skip to content

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

fix(agent): bind social evidence per destination

Emre Sokullua19afb9e98a4
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 1ec46f5a7..21f941d53 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -1660,6 +1660,15 @@ export class Agent extends LoopDetector {
}
const next = recordCompletionToolResult(state, name, completionArgs, result);
this.completionInvariants.set(tabId, next);
+ const socialUploadEvidence = this._rememberSocialPublishUploadEvidence(
+ tabId,
+ name,
+ result,
+ next,
+ );
+ if (socialUploadEvidence && result && typeof result === 'object') {
+ result.socialUploadEvidence = socialUploadEvidence;
+ }
const workflowControlEvidence = this._rememberWorkflowControlActionEvidence(
tabId,
name,
@@ -2113,6 +2122,9 @@ export class Agent extends LoopDetector {
? {
preDispatchPublicationAccountIdentity,
preDispatchPublicationAccountIdentityComplete: !!preDispatchPublicationAccountIdentity,
+ uploadedAttachmentNames: (Array.isArray(guard.workflowSocialUploadEvidence)
+ ? guard.workflowSocialUploadEvidence
+ : []).map(item => String(item?.name || '').trim()).filter(Boolean).slice(-12),
}
: {}),
...(githubFileCommit ? { githubFileCommit } : {}),
@@ -2956,7 +2968,7 @@ export class Agent extends LoopDetector {
_parseWorkflowAttachmentRequirement(value) {
const rawVal = (typeof value === 'object' && value !== null && 'value' in value) ? value.value : value;
const text = String(rawVal || '').trim().toLowerCase();
- if (!text) return { isGeneric: true, expectedCount: 1, expectedImageCount: 0, expectedVideoCount: 0, wantsImage: false, wantsVideo: false, wantsGif: false, specificTargets: [], normalized: '' };
+ if (!text) return { isGeneric: true, expectedCount: 1, expectedImageCount: 0, expectedVideoCount: 0, expectedGifCount: 0, wantsImage: false, wantsVideo: false, wantsOrdinaryVideo: false, wantsGif: false, specificTargets: [], normalized: '' };
if (this._isNegativeAttachmentRequirement(text)) {
return {
@@ -2999,10 +3011,12 @@ export class Agent extends LoopDetector {
}
const hasRawGif = RAW_GIF_NOUN_REGEX.test(text);
- const hasRawVideo = hasRawGif || RAW_VIDEO_NOUN_REGEX.test(text);
+ const hasRawOrdinaryVideo = RAW_VIDEO_NOUN_REGEX.test(text);
+ const hasRawVideo = hasRawGif || hasRawOrdinaryVideo;
const hasRawImage = RAW_IMAGE_NOUN_REGEX.test(text);
const wantsGif = hasRawGif && !isGifNegated;
+ const wantsOrdinaryVideo = hasRawOrdinaryVideo && !isVideoNegated;
const wantsVideo = (hasRawVideo && !isVideoNegated) || wantsGif;
const wantsImage = hasRawImage && !isImageNegated;
@@ -3073,20 +3087,24 @@ export class Agent extends LoopDetector {
// media type does not loosen an exact count on the other.
let minScopedImage = false;
let minScopedVideo = false;
+ let minScopedGif = false;
let minScopedGeneric = false;
if (hasMinCountQualifier) {
for (const segment of text.split(MIN_COUNT_SCOPE_SPLIT)) {
if (!segment || !MIN_ATTACHMENT_COUNT_REGEX.test(segment)) continue;
const segmentImage = RAW_IMAGE_NOUN_REGEX.test(segment);
- const segmentVideo = RAW_GIF_NOUN_REGEX.test(segment) || RAW_VIDEO_NOUN_REGEX.test(segment);
+ const segmentGif = RAW_GIF_NOUN_REGEX.test(segment);
+ const segmentVideo = RAW_VIDEO_NOUN_REGEX.test(segment);
if (segmentImage) minScopedImage = true;
if (segmentVideo) minScopedVideo = true;
- if (!segmentImage && !segmentVideo) minScopedGeneric = true;
+ if (segmentGif) minScopedGif = true;
+ if (!segmentImage && !segmentVideo && !segmentGif) minScopedGeneric = true;
}
}
const isMinimumCount = isGeneric && hasMinCountQualifier;
const isImageMinimum = isGeneric && (minScopedImage || minScopedGeneric);
const isVideoMinimum = isGeneric && (minScopedVideo || minScopedGeneric);
+ const isGifMinimum = isGeneric && (minScopedGif || minScopedGeneric);
const countPrefix = '(?:\\d+|zero|cero|zéro|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|один|одна|одно|два|две|три|четыре|пять|[一二两三四五六七八九十]|하나|둘|셋|넷|다섯|한(?=\\s*(?:장|개|건|편|개의|장의))|두(?=\\s*(?:장|개|건|편|개의|장의))|세(?=\\s*(?:장|개|건|편|개의|장의))|네(?=\\s*(?:장|개|건|편|개의|장의))|[일이삼사오](?=\\s*(?:장|개|건|편|개의|장의)))';
const countSeparator = '(?:^|[\\s,;+&/|、,。;:]|(?:\\b(?:and|und|et|e|y)\\b\\s*)|[와과및])';
@@ -3106,8 +3124,21 @@ export class Agent extends LoopDetector {
hasExplicitImageCount = isExplicitCountWord(imageCountMatch[1]);
}
+ const gifCountMatch = isGeneric
+ ? countText.match(new RegExp(`${countSeparator}(${countPrefix})(?:\\s*(?:枚|つ|本|张|條|条|个|個|장|개|건|편))?\\s*(?:gifs?|animated[-_ ]gifs?|動圖|动图|움짤)(?:\\s*(?:개|편|건))?`, 'i'))
+ : null;
+ let expectedGifCount = 0;
+ let hasExplicitGifCount = false;
+ if (isGifNegated) {
+ expectedGifCount = 0;
+ hasExplicitGifCount = true;
+ } else if (gifCountMatch) {
+ expectedGifCount = parseCountWord(gifCountMatch[1]);
+ hasExplicitGifCount = isExplicitCountWord(gifCountMatch[1]);
+ }
+
const videoCountMatch = isGeneric
- ? (countText.match(new RegExp(`${countSeparator}(${countPrefix})(?:\\s*(?:枚|つ|本|张|條|条|个|個|장|개|건|편))?\\s*(?:videos?|clips?|recordings?|gifs?|animated[-_ ]gifs?|vidéo|vidéos|動画|视频|影片|видео|동영상|비디오|영상)(?:\\s*(?:개|편|건))?`, 'i'))
+ ? (countText.match(new RegExp(`${countSeparator}(${countPrefix})(?:\\s*(?:枚|つ|本|张|條|条|个|個|장|개|건|편))?\\s*(?:videos?|clips?|recordings?|vidéo|vidéos|動画|视频|影片|видео|동영상|비디오|영상)(?:\\s*(?:개|편|건))?`, 'i'))
|| countText.match(/(?:동영상|비디오|영상)\s*([0-9하나둘셋넷다섯]+|[한두세네일이삼사오](?=\\s*(?:장|개|건|편|개의|장의)))\s*(?:개|편|건)?/i)
|| countText.match(/(?:動画|视频|影片)\s*([0-9一二两三四五六七八九十]+)\s*(?:つ|本|個|个|條|条|편|개)?/i))
: null;
@@ -3127,24 +3158,25 @@ export class Agent extends LoopDetector {
let hasExplicitGenericCount = false;
let expectedCount = 1;
if (isGeneric) {
+ const combinedVideoCount = expectedVideoCount + expectedGifCount;
if (isAlternative) {
- if (expectedImageCount > 0 && expectedVideoCount > 0) {
- expectedCount = Math.min(expectedImageCount, expectedVideoCount);
+ if (expectedImageCount > 0 && combinedVideoCount > 0) {
+ expectedCount = Math.min(expectedImageCount, combinedVideoCount);
} else if (expectedImageCount > 0) {
expectedCount = expectedImageCount;
- } else if (expectedVideoCount > 0) {
- expectedCount = expectedVideoCount;
+ } else if (combinedVideoCount > 0) {
+ expectedCount = combinedVideoCount;
} else {
expectedCount = 1;
}
- } else if (expectedImageCount > 0 && expectedVideoCount > 0) {
- expectedCount = expectedImageCount + expectedVideoCount;
+ } else if (expectedImageCount > 0 && combinedVideoCount > 0) {
+ expectedCount = expectedImageCount + combinedVideoCount;
} else if (expectedImageCount > 0) {
expectedCount = expectedImageCount + (wantsVideo ? 1 : 0);
- } else if (expectedVideoCount > 0) {
- expectedCount = expectedVideoCount + (wantsImage ? 1 : 0);
+ } else if (combinedVideoCount > 0) {
+ expectedCount = combinedVideoCount + (wantsImage ? 1 : 0);
} else if (wantsVideo && !wantsImage) {
- expectedCount = expectedVideoCount > 0 ? expectedVideoCount : 1;
+ expectedCount = combinedVideoCount > 0 ? combinedVideoCount : 1;
} else if (wantsImage && !wantsVideo) {
expectedCount = expectedImageCount > 0 ? expectedImageCount : 1;
} else {
@@ -3176,7 +3208,9 @@ export class Agent extends LoopDetector {
const hasExplicitPositiveImageCount = hasExplicitImageCount && !isImageNegated;
const hasExplicitPositiveVideoCount = hasExplicitVideoCount && !isVideoNegated;
- const hasExplicitCardinality = hasExplicitPositiveImageCount || hasExplicitPositiveVideoCount || hasExplicitGenericCount || (isImageNegated && isVideoNegated);
+ const hasExplicitPositiveGifCount = hasExplicitGifCount && !isGifNegated;
+ const hasExplicitCardinality = hasExplicitPositiveImageCount || hasExplicitPositiveVideoCount
+ || hasExplicitPositiveGifCount || hasExplicitGenericCount || (isImageNegated && isVideoNegated);
const specificTargets = isGeneric ? [] : this._parseSpecificAttachmentTargets(rawVal);
return {
@@ -3184,8 +3218,10 @@ export class Agent extends LoopDetector {
expectedCount,
expectedImageCount,
expectedVideoCount,
+ expectedGifCount,
hasExplicitImageCount,
hasExplicitVideoCount,
+ hasExplicitGifCount,
hasExplicitCardinality,
isImageNegated,
isVideoNegated,
@@ -3194,14 +3230,71 @@ export class Agent extends LoopDetector {
isMinimumCount,
isImageMinimum,
isVideoMinimum,
+ isGifMinimum,
wantsImage,
wantsVideo,
+ wantsOrdinaryVideo,
wantsGif,
specificTargets,
normalized: text,
};
}
+ _workflowSocialRecordWithUploadedAttachmentNames(record, binding) {
+ const attachments = Array.isArray(record?.attachments)
+ ? record.attachments
+ : (Array.isArray(record?.media) ? record.media : []);
+ const names = (Array.isArray(binding?.uploadedAttachmentNames)
+ ? binding.uploadedAttachmentNames
+ : []).map(value => String(value || '').split(/[\\/]/).pop().trim()).filter(Boolean);
+ // A filename may describe an observed published attachment, but it may
+ // never create one. Require one upload name per DOM-observed media node and
+ // a type-compatible bijection before adding the names to the record.
+ if (!attachments.length || names.length !== attachments.length) return record;
+ const nameKind = (name) => (
+ /\.gif(?:[?#]|$)/i.test(name) ? 'video'
+ : /\.(?:mp4|mov|webm|mkv)(?:[?#]|$)/i.test(name) ? 'video'
+ : /\.(?:png|jpe?g|webp|avif|heic|bmp|svg)(?:[?#]|$)/i.test(name) ? 'image'
+ : ''
+ );
+ const attachmentKind = (attachment) => {
+ const type = String(attachment?.type || attachment?.kind || '').toLowerCase();
+ if (type === 'video' || type === 'animated_gif' || type === 'gif') return 'video';
+ if (type === 'image' || type === 'photo') return 'image';
+ const source = typeof attachment === 'string'
+ ? attachment
+ : String(attachment?.src || attachment?.url || '');
+ if (/\.(?:mp4|mov|webm|mkv|gif)(?:[?#]|$)/i.test(source)
+ || /\/tweet_video(?:_thumb)?\//i.test(source)) return 'video';
+ return 'image';
+ };
+ const assignment = new Array(attachments.length).fill(-1);
+ const matchNames = (attachmentIndex, usedNames) => {
+ if (attachmentIndex >= attachments.length) return true;
+ const observedKind = attachmentKind(attachments[attachmentIndex]);
+ for (let nameIndex = 0; nameIndex < names.length; nameIndex++) {
+ if (usedNames.has(nameIndex)) continue;
+ const uploadedKind = nameKind(names[nameIndex]);
+ if (uploadedKind && uploadedKind !== observedKind) continue;
+ assignment[attachmentIndex] = nameIndex;
+ usedNames.add(nameIndex);
+ if (matchNames(attachmentIndex + 1, usedNames)) return true;
+ usedNames.delete(nameIndex);
+ assignment[attachmentIndex] = -1;
+ }
+ return false;
+ };
+ if (!matchNames(0, new Set())) return record;
+ return {
+ ...record,
+ attachments: attachments.map((attachment, index) => (
+ typeof attachment === 'string'
+ ? { src: attachment, name: names[assignment[index]] }
+ : { ...attachment, name: names[assignment[index]] }
+ )),
+ };
+ }
+
_workflowSocialPublishedAttachmentObserved(requirement, record) {
const rawAttachments = Array.isArray(record?.attachments)
? record.attachments
@@ -3247,24 +3340,53 @@ export class Agent extends LoopDetector {
const imageCount = rawAttachments.filter(isImageAttachment).length;
const videoCount = rawAttachments.filter(isVideoAttachment).length;
const gifCount = rawAttachments.filter(isGifAttachment).length;
- if (parsed.wantsGif && gifCount < 1) return false;
+ const ordinaryVideoCount = rawAttachments.filter(att => isVideoAttachment(att) && !isGifAttachment(att)).length;
+ if (parsed.wantsGif) {
+ const requiredGifCount = parsed.expectedGifCount > 0 ? parsed.expectedGifCount : 1;
+ if (gifCount < requiredGifCount) return false;
+ if (parsed.hasExplicitGifCount && !parsed.isGifMinimum && gifCount !== parsed.expectedGifCount) return false;
+ }
+ if (parsed.wantsGif && parsed.wantsOrdinaryVideo) {
+ const requiredOrdinaryVideoCount = parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1;
+ if (ordinaryVideoCount < requiredOrdinaryVideoCount) return false;
+ if (parsed.hasExplicitVideoCount && !parsed.isVideoMinimum
+ && ordinaryVideoCount !== parsed.expectedVideoCount) return false;
+ }
if (parsed.isGifNegated && gifCount > 0) return false;
+ const exactTypedTotal = parsed.isGeneric && !parsed.isAlternative
+ && (!parsed.wantsImage || (parsed.hasExplicitImageCount && !parsed.isImageMinimum))
+ && (!parsed.wantsOrdinaryVideo || (parsed.hasExplicitVideoCount && !parsed.isVideoMinimum))
+ && (!parsed.wantsGif || (parsed.hasExplicitGifCount && !parsed.isGifMinimum));
+ if (exactTypedTotal && (parsed.wantsImage || parsed.wantsOrdinaryVideo || parsed.wantsGif)) {
+ const expectedTypedTotal = (parsed.wantsImage ? parsed.expectedImageCount : 0)
+ + (parsed.wantsOrdinaryVideo ? parsed.expectedVideoCount : 0)
+ + (parsed.wantsGif ? parsed.expectedGifCount : 0);
+ if (rawAttachments.length !== expectedTypedTotal) return false;
+ }
let matchingAttachments = rawAttachments;
if (parsed.wantsImage && parsed.wantsVideo) {
if (parsed.isAlternative) {
const minImages = parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1;
- const minVideos = parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1;
+ const expectedAlternativeVideoCount = parsed.wantsGif && !parsed.wantsOrdinaryVideo
+ ? parsed.expectedGifCount
+ : parsed.expectedVideoCount;
+ const alternativeVideoCount = parsed.wantsGif && !parsed.wantsOrdinaryVideo
+ ? gifCount
+ : videoCount;
+ const minVideos = expectedAlternativeVideoCount > 0 ? expectedAlternativeVideoCount : 1;
const exactImageAlt = parsed.hasExplicitImageCount && !parsed.isImageMinimum;
- const exactVideoAlt = parsed.hasExplicitVideoCount && !parsed.isVideoMinimum;
+ const exactVideoAlt = parsed.wantsGif && !parsed.wantsOrdinaryVideo
+ ? parsed.hasExplicitGifCount && !parsed.isGifMinimum
+ : parsed.hasExplicitVideoCount && !parsed.isVideoMinimum;
const matchesImageAlt = imageCount >= minImages
&& (!exactImageAlt || imageCount === parsed.expectedImageCount)
&& videoCount === 0
&& (!exactImageAlt || rawAttachments.length === parsed.expectedImageCount);
- const matchesVideoAlt = videoCount >= minVideos
- && (!exactVideoAlt || videoCount === parsed.expectedVideoCount)
+ const matchesVideoAlt = alternativeVideoCount >= minVideos
+ && (!exactVideoAlt || alternativeVideoCount === expectedAlternativeVideoCount)
&& imageCount === 0
- && (!exactVideoAlt || rawAttachments.length === parsed.expectedVideoCount);
+ && (!exactVideoAlt || rawAttachments.length === expectedAlternativeVideoCount);
if (!matchesImageAlt && !matchesVideoAlt) {
return false;
}
@@ -3285,7 +3407,7 @@ export class Agent extends LoopDetector {
}
if (parsed.hasExplicitImageCount && parsed.hasExplicitVideoCount
&& !parsed.isImageMinimum && !parsed.isVideoMinimum) {
- if (rawAttachments.length !== (parsed.expectedImageCount + parsed.expectedVideoCount)) {
+ if (rawAttachments.length !== (parsed.expectedImageCount + parsed.expectedVideoCount + parsed.expectedGifCount)) {
return false;
}
} else if (parsed.hasExplicitCardinality) {
@@ -3310,8 +3432,9 @@ export class Agent extends LoopDetector {
matchingAttachments = rawAttachments.filter(isImageAttachment);
} else if (parsed.wantsVideo && !parsed.wantsImage) {
if (imageCount > 0) return false;
- const hasExactVideoCount = !parsed.isVideoMinimum
- && ((parsed.hasExplicitVideoCount && !parsed.isVideoNegated) || parsed.hasExplicitGenericCount);
+ const hasExactVideoCount = (parsed.hasExplicitVideoCount && !parsed.isVideoNegated && !parsed.isVideoMinimum)
+ || (parsed.hasExplicitGifCount && !parsed.isGifNegated && !parsed.isGifMinimum)
+ || parsed.hasExplicitGenericCount;
if (hasExactVideoCount) {
if (videoCount !== parsed.expectedCount || rawAttachments.length !== parsed.expectedCount) {
return false;
@@ -3848,16 +3971,17 @@ export class Agent extends LoopDetector {
if (!intendedAccount || !publishedAccount
|| !accountMatches(requestedAccount)
|| !accountMatches(capturedAccount)) return false;
+ const publishedRecord = this._workflowSocialRecordWithUploadedAttachmentNames(records[0], binding);
return requirements.every(requirement => (
requirement?.field === 'account'
? true
: requirement?.field === 'body'
- ? this._workflowSocialPublishedBodyObserved(requirement, records[0])
+ ? this._workflowSocialPublishedBodyObserved(requirement, publishedRecord)
: requirement?.field === 'attachment'
- ? this._workflowSocialPublishedAttachmentObserved(requirement, records[0])
+ ? this._workflowSocialPublishedAttachmentObserved(requirement, publishedRecord)
: this._workflowPublishedPayloadValueObserved(requirement, {
- pageText: records[0].text,
- pageUrl: records[0].url,
+ pageText: publishedRecord.text,
+ pageUrl: publishedRecord.url,
publishedResourceIdentity: binding.publishedResourceIdentity,
})
));
@@ -16054,6 +16178,34 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return proof;
}
+ _rememberSocialPublishUploadEvidence(tabId, name, result = {}, completionState = null) {
+ const guard = this._planExecutionGuards.get(tabId);
+ const siteWorkflow = guard?.siteWorkflow;
+ if (!guard?.enabled
+ || name !== 'upload_file'
+ || siteWorkflow?.job?.id !== 'publish-post'
+ || !['twitter', 'bluesky'].includes(siteWorkflow.adapterName)
+ || !this._isSuccessfulExecutionEvidence(result)
+ || !['input_attached', 'page_consumed'].includes(result?.attachmentState)) return null;
+ const fileName = String(result?.attached?.name || '').split(/[\\/]/).pop().trim().slice(0, 500);
+ const actionSequence = Number(completionState?.lastAction?.sequence || completionState?.sequence || 0);
+ if (!fileName || !actionSequence) return null;
+ const prior = Array.isArray(guard.workflowSocialUploadEvidence)
+ ? guard.workflowSocialUploadEvidence
+ : [];
+ const normalizedName = fileName.toLocaleLowerCase();
+ const evidence = {
+ name: fileName,
+ attachmentState: result.attachmentState,
+ actionSequence,
+ };
+ guard.workflowSocialUploadEvidence = [
+ ...prior.filter(item => String(item?.name || '').toLocaleLowerCase() !== normalizedName),
+ evidence,
+ ].slice(-12);
+ return evidence;
+ }
+
_rememberWorkflowInventoryObservation(tabId, name, args, result) {
const guard = this._planExecutionGuards.get(tabId);
const siteWorkflow = guard?.siteWorkflow;
@@ -16813,6 +16965,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
guard.siteWorkflowUrl = liveUrl;
guard.workflowTerminalEvidence = null;
guard.verifiedSubmissionEvidence = false;
+ // Publication requirements and upload provenance belong to the currently
+ // bound destination. Reclassify and recollect them after X <-> Bluesky
+ // navigation instead of reusing the first platform's payload.
+ guard.workflowMetadataRequirements = [];
+ guard.workflowMetadataRequirementsResolved = false;
+ guard.workflowMetadataRequirementsIncomplete = false;
+ guard.workflowSocialUploadEvidence = [];
await this._ensureWorkflowMetadataRequirements(
tabId,
{ provider, costState: this.currentCostState.get(tabId) || null },
@@ -25411,8 +25570,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (extractedBody) {
const bodyReq = details.items.find(r => r.field === 'body');
if (bodyReq) {
- if (extractedBody.length > (bodyReq.value || '').length
- || bodyReq.value === '[from task]'
+ if (bodyReq.value === '[from task]'
|| extractedBody.includes(bodyReq.value)) {
bodyReq.value = this._workflowMetadataValue(extractedBody, 25000);
}
@@ -26183,6 +26341,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
socialPublishSatisfiedTargets: carryMatches && Array.isArray(carried.socialPublishSatisfiedTargets)
? [...carried.socialPublishSatisfiedTargets]
: [],
+ workflowSocialUploadEvidence: carryMatches && Array.isArray(carried.workflowSocialUploadEvidence)
+ ? carried.workflowSocialUploadEvidence.map(item => ({ ...item }))
+ : [],
workflowTerminalEvidence: carryMatches && carried.workflowTerminalEvidence
? { ...carried.workflowTerminalEvidence }
: null,
@@ -26511,6 +26672,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
|| Object.keys(guard.workflowReleaseAssetEvidence || {}).length > 0
|| Object.keys(guard.workflowPendingReleaseAssetEvidence || {}).length > 0
|| Object.keys(guard.workflowPendingUploadEvidence || {}).length > 0
+ || (guard.workflowSocialUploadEvidence || []).length > 0
)) {
const submit = this._completionSubmitStates.get(tabId);
this._continuationExecutionEvidence.set(tabId, {
@@ -26537,6 +26699,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
socialPublishSatisfiedTargets: Array.isArray(guard.socialPublishSatisfiedTargets)
? [...guard.socialPublishSatisfiedTargets]
: [],
+ workflowSocialUploadEvidence: Array.isArray(guard.workflowSocialUploadEvidence)
+ ? guard.workflowSocialUploadEvidence.map(item => ({ ...item }))
+ : [],
workflowTerminalEvidence: guard.workflowTerminalEvidence
? { ...guard.workflowTerminalEvidence }
: null,
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 9c0b893cc..87f4a5949 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -1376,6 +1376,15 @@ export class Agent extends LoopDetector {
}
const next = recordCompletionToolResult(state, name, completionArgs, result);
this.completionInvariants.set(tabId, next);
+ const socialUploadEvidence = this._rememberSocialPublishUploadEvidence(
+ tabId,
+ name,
+ result,
+ next,
+ );
+ if (socialUploadEvidence && result && typeof result === 'object') {
+ result.socialUploadEvidence = socialUploadEvidence;
+ }
const workflowControlEvidence = this._rememberWorkflowControlActionEvidence(
tabId,
name,
@@ -1828,6 +1837,9 @@ export class Agent extends LoopDetector {
? {
preDispatchPublicationAccountIdentity,
preDispatchPublicationAccountIdentityComplete: !!preDispatchPublicationAccountIdentity,
+ uploadedAttachmentNames: (Array.isArray(guard.workflowSocialUploadEvidence)
+ ? guard.workflowSocialUploadEvidence
+ : []).map(item => String(item?.name || '').trim()).filter(Boolean).slice(-12),
}
: {}),
...(githubFileCommit ? { githubFileCommit } : {}),
@@ -2671,7 +2683,7 @@ export class Agent extends LoopDetector {
_parseWorkflowAttachmentRequirement(value) {
const rawVal = (typeof value === 'object' && value !== null && 'value' in value) ? value.value : value;
const text = String(rawVal || '').trim().toLowerCase();
- if (!text) return { isGeneric: true, expectedCount: 1, expectedImageCount: 0, expectedVideoCount: 0, wantsImage: false, wantsVideo: false, wantsGif: false, specificTargets: [], normalized: '' };
+ if (!text) return { isGeneric: true, expectedCount: 1, expectedImageCount: 0, expectedVideoCount: 0, expectedGifCount: 0, wantsImage: false, wantsVideo: false, wantsOrdinaryVideo: false, wantsGif: false, specificTargets: [], normalized: '' };
if (this._isNegativeAttachmentRequirement(text)) {
return {
@@ -2714,10 +2726,12 @@ export class Agent extends LoopDetector {
}
const hasRawGif = RAW_GIF_NOUN_REGEX.test(text);
- const hasRawVideo = hasRawGif || RAW_VIDEO_NOUN_REGEX.test(text);
+ const hasRawOrdinaryVideo = RAW_VIDEO_NOUN_REGEX.test(text);
+ const hasRawVideo = hasRawGif || hasRawOrdinaryVideo;
const hasRawImage = RAW_IMAGE_NOUN_REGEX.test(text);
const wantsGif = hasRawGif && !isGifNegated;
+ const wantsOrdinaryVideo = hasRawOrdinaryVideo && !isVideoNegated;
const wantsVideo = (hasRawVideo && !isVideoNegated) || wantsGif;
const wantsImage = hasRawImage && !isImageNegated;
@@ -2788,20 +2802,24 @@ export class Agent extends LoopDetector {
// media type does not loosen an exact count on the other.
let minScopedImage = false;
let minScopedVideo = false;
+ let minScopedGif = false;
let minScopedGeneric = false;
if (hasMinCountQualifier) {
for (const segment of text.split(MIN_COUNT_SCOPE_SPLIT)) {
if (!segment || !MIN_ATTACHMENT_COUNT_REGEX.test(segment)) continue;
const segmentImage = RAW_IMAGE_NOUN_REGEX.test(segment);
- const segmentVideo = RAW_GIF_NOUN_REGEX.test(segment) || RAW_VIDEO_NOUN_REGEX.test(segment);
+ const segmentGif = RAW_GIF_NOUN_REGEX.test(segment);
+ const segmentVideo = RAW_VIDEO_NOUN_REGEX.test(segment);
if (segmentImage) minScopedImage = true;
if (segmentVideo) minScopedVideo = true;
- if (!segmentImage && !segmentVideo) minScopedGeneric = true;
+ if (segmentGif) minScopedGif = true;
+ if (!segmentImage && !segmentVideo && !segmentGif) minScopedGeneric = true;
}
}
const isMinimumCount = isGeneric && hasMinCountQualifier;
const isImageMinimum = isGeneric && (minScopedImage || minScopedGeneric);
const isVideoMinimum = isGeneric && (minScopedVideo || minScopedGeneric);
+ const isGifMinimum = isGeneric && (minScopedGif || minScopedGeneric);
const countPrefix = '(?:\\d+|zero|cero|zéro|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|один|одна|одно|два|две|три|четыре|пять|[一二两三四五六七八九十]|하나|둘|셋|넷|다섯|한(?=\\s*(?:장|개|건|편|개의|장의))|두(?=\\s*(?:장|개|건|편|개의|장의))|세(?=\\s*(?:장|개|건|편|개의|장의))|네(?=\\s*(?:장|개|건|편|개의|장의))|[일이삼사오](?=\\s*(?:장|개|건|편|개의|장의)))';
const countSeparator = '(?:^|[\\s,;+&/|、,。;:]|(?:\\b(?:and|und|et|e|y)\\b\\s*)|[와과및])';
@@ -2821,8 +2839,21 @@ export class Agent extends LoopDetector {
hasExplicitImageCount = isExplicitCountWord(imageCountMatch[1]);
}
+ const gifCountMatch = isGeneric
+ ? countText.match(new RegExp(`${countSeparator}(${countPrefix})(?:\\s*(?:枚|つ|本|张|條|条|个|個|장|개|건|편))?\\s*(?:gifs?|animated[-_ ]gifs?|動圖|动图|움짤)(?:\\s*(?:개|편|건))?`, 'i'))
+ : null;
+ let expectedGifCount = 0;
+ let hasExplicitGifCount = false;
+ if (isGifNegated) {
+ expectedGifCount = 0;
+ hasExplicitGifCount = true;
+ } else if (gifCountMatch) {
+ expectedGifCount = parseCountWord(gifCountMatch[1]);
+ hasExplicitGifCount = isExplicitCountWord(gifCountMatch[1]);
+ }
+
const videoCountMatch = isGeneric
- ? (countText.match(new RegExp(`${countSeparator}(${countPrefix})(?:\\s*(?:枚|つ|本|张|條|条|个|個|장|개|건|편))?\\s*(?:videos?|clips?|recordings?|gifs?|animated[-_ ]gifs?|vidéo|vidéos|動画|视频|影片|видео|동영상|비디오|영상)(?:\\s*(?:개|편|건))?`, 'i'))
+ ? (countText.match(new RegExp(`${countSeparator}(${countPrefix})(?:\\s*(?:枚|つ|本|张|條|条|个|個|장|개|건|편))?\\s*(?:videos?|clips?|recordings?|vidéo|vidéos|動画|视频|影片|видео|동영상|비디오|영상)(?:\\s*(?:개|편|건))?`, 'i'))
|| countText.match(/(?:동영상|비디오|영상)\s*([0-9하나둘셋넷다섯]+|[한두세네일이삼사오](?=\\s*(?:장|개|건|편|개의|장의)))\s*(?:개|편|건)?/i)
|| countText.match(/(?:動画|视频|影片)\s*([0-9一二两三四五六七八九十]+)\s*(?:つ|本|個|个|條|条|편|개)?/i))
: null;
@@ -2842,24 +2873,25 @@ export class Agent extends LoopDetector {
let hasExplicitGenericCount = false;
let expectedCount = 1;
if (isGeneric) {
+ const combinedVideoCount = expectedVideoCount + expectedGifCount;
if (isAlternative) {
- if (expectedImageCount > 0 && expectedVideoCount > 0) {
- expectedCount = Math.min(expectedImageCount, expectedVideoCount);
+ if (expectedImageCount > 0 && combinedVideoCount > 0) {
+ expectedCount = Math.min(expectedImageCount, combinedVideoCount);
} else if (expectedImageCount > 0) {
expectedCount = expectedImageCount;
- } else if (expectedVideoCount > 0) {
- expectedCount = expectedVideoCount;
+ } else if (combinedVideoCount > 0) {
+ expectedCount = combinedVideoCount;
} else {
expectedCount = 1;
}
- } else if (expectedImageCount > 0 && expectedVideoCount > 0) {
- expectedCount = expectedImageCount + expectedVideoCount;
+ } else if (expectedImageCount > 0 && combinedVideoCount > 0) {
+ expectedCount = expectedImageCount + combinedVideoCount;
} else if (expectedImageCount > 0) {
expectedCount = expectedImageCount + (wantsVideo ? 1 : 0);
- } else if (expectedVideoCount > 0) {
- expectedCount = expectedVideoCount + (wantsImage ? 1 : 0);
+ } else if (combinedVideoCount > 0) {
+ expectedCount = combinedVideoCount + (wantsImage ? 1 : 0);
} else if (wantsVideo && !wantsImage) {
- expectedCount = expectedVideoCount > 0 ? expectedVideoCount : 1;
+ expectedCount = combinedVideoCount > 0 ? combinedVideoCount : 1;
} else if (wantsImage && !wantsVideo) {
expectedCount = expectedImageCount > 0 ? expectedImageCount : 1;
} else {
@@ -2891,7 +2923,9 @@ export class Agent extends LoopDetector {
const hasExplicitPositiveImageCount = hasExplicitImageCount && !isImageNegated;
const hasExplicitPositiveVideoCount = hasExplicitVideoCount && !isVideoNegated;
- const hasExplicitCardinality = hasExplicitPositiveImageCount || hasExplicitPositiveVideoCount || hasExplicitGenericCount || (isImageNegated && isVideoNegated);
+ const hasExplicitPositiveGifCount = hasExplicitGifCount && !isGifNegated;
+ const hasExplicitCardinality = hasExplicitPositiveImageCount || hasExplicitPositiveVideoCount
+ || hasExplicitPositiveGifCount || hasExplicitGenericCount || (isImageNegated && isVideoNegated);
const specificTargets = isGeneric ? [] : this._parseSpecificAttachmentTargets(rawVal);
return {
@@ -2899,8 +2933,10 @@ export class Agent extends LoopDetector {
expectedCount,
expectedImageCount,
expectedVideoCount,
+ expectedGifCount,
hasExplicitImageCount,
hasExplicitVideoCount,
+ hasExplicitGifCount,
hasExplicitCardinality,
isImageNegated,
isVideoNegated,
@@ -2909,14 +2945,71 @@ export class Agent extends LoopDetector {
isMinimumCount,
isImageMinimum,
isVideoMinimum,
+ isGifMinimum,
wantsImage,
wantsVideo,
+ wantsOrdinaryVideo,
wantsGif,
specificTargets,
normalized: text,
};
}
+ _workflowSocialRecordWithUploadedAttachmentNames(record, binding) {
+ const attachments = Array.isArray(record?.attachments)
+ ? record.attachments
+ : (Array.isArray(record?.media) ? record.media : []);
+ const names = (Array.isArray(binding?.uploadedAttachmentNames)
+ ? binding.uploadedAttachmentNames
+ : []).map(value => String(value || '').split(/[\\/]/).pop().trim()).filter(Boolean);
+ // A filename may describe an observed published attachment, but it may
+ // never create one. Require one upload name per DOM-observed media node and
+ // a type-compatible bijection before adding the names to the record.
+ if (!attachments.length || names.length !== attachments.length) return record;
+ const nameKind = (name) => (
+ /\.gif(?:[?#]|$)/i.test(name) ? 'video'
+ : /\.(?:mp4|mov|webm|mkv)(?:[?#]|$)/i.test(name) ? 'video'
+ : /\.(?:png|jpe?g|webp|avif|heic|bmp|svg)(?:[?#]|$)/i.test(name) ? 'image'
+ : ''
+ );
+ const attachmentKind = (attachment) => {
+ const type = String(attachment?.type || attachment?.kind || '').toLowerCase();
+ if (type === 'video' || type === 'animated_gif' || type === 'gif') return 'video';
+ if (type === 'image' || type === 'photo') return 'image';
+ const source = typeof attachment === 'string'
+ ? attachment
+ : String(attachment?.src || attachment?.url || '');
+ if (/\.(?:mp4|mov|webm|mkv|gif)(?:[?#]|$)/i.test(source)
+ || /\/tweet_video(?:_thumb)?\//i.test(source)) return 'video';
+ return 'image';
+ };
+ const assignment = new Array(attachments.length).fill(-1);
+ const matchNames = (attachmentIndex, usedNames) => {
+ if (attachmentIndex >= attachments.length) return true;
+ const observedKind = attachmentKind(attachments[attachmentIndex]);
+ for (let nameIndex = 0; nameIndex < names.length; nameIndex++) {
+ if (usedNames.has(nameIndex)) continue;
+ const uploadedKind = nameKind(names[nameIndex]);
+ if (uploadedKind && uploadedKind !== observedKind) continue;
+ assignment[attachmentIndex] = nameIndex;
+ usedNames.add(nameIndex);
+ if (matchNames(attachmentIndex + 1, usedNames)) return true;
+ usedNames.delete(nameIndex);
+ assignment[attachmentIndex] = -1;
+ }
+ return false;
+ };
+ if (!matchNames(0, new Set())) return record;
+ return {
+ ...record,
+ attachments: attachments.map((attachment, index) => (
+ typeof attachment === 'string'
+ ? { src: attachment, name: names[assignment[index]] }
+ : { ...attachment, name: names[assignment[index]] }
+ )),
+ };
+ }
+
_workflowSocialPublishedAttachmentObserved(requirement, record) {
const rawAttachments = Array.isArray(record?.attachments)
? record.attachments
@@ -2962,24 +3055,53 @@ export class Agent extends LoopDetector {
const imageCount = rawAttachments.filter(isImageAttachment).length;
const videoCount = rawAttachments.filter(isVideoAttachment).length;
const gifCount = rawAttachments.filter(isGifAttachment).length;
- if (parsed.wantsGif && gifCount < 1) return false;
+ const ordinaryVideoCount = rawAttachments.filter(att => isVideoAttachment(att) && !isGifAttachment(att)).length;
+ if (parsed.wantsGif) {
+ const requiredGifCount = parsed.expectedGifCount > 0 ? parsed.expectedGifCount : 1;
+ if (gifCount < requiredGifCount) return false;
+ if (parsed.hasExplicitGifCount && !parsed.isGifMinimum && gifCount !== parsed.expectedGifCount) return false;
+ }
+ if (parsed.wantsGif && parsed.wantsOrdinaryVideo) {
+ const requiredOrdinaryVideoCount = parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1;
+ if (ordinaryVideoCount < requiredOrdinaryVideoCount) return false;
+ if (parsed.hasExplicitVideoCount && !parsed.isVideoMinimum
+ && ordinaryVideoCount !== parsed.expectedVideoCount) return false;
+ }
if (parsed.isGifNegated && gifCount > 0) return false;
+ const exactTypedTotal = parsed.isGeneric && !parsed.isAlternative
+ && (!parsed.wantsImage || (parsed.hasExplicitImageCount && !parsed.isImageMinimum))
+ && (!parsed.wantsOrdinaryVideo || (parsed.hasExplicitVideoCount && !parsed.isVideoMinimum))
+ && (!parsed.wantsGif || (parsed.hasExplicitGifCount && !parsed.isGifMinimum));
+ if (exactTypedTotal && (parsed.wantsImage || parsed.wantsOrdinaryVideo || parsed.wantsGif)) {
+ const expectedTypedTotal = (parsed.wantsImage ? parsed.expectedImageCount : 0)
+ + (parsed.wantsOrdinaryVideo ? parsed.expectedVideoCount : 0)
+ + (parsed.wantsGif ? parsed.expectedGifCount : 0);
+ if (rawAttachments.length !== expectedTypedTotal) return false;
+ }
let matchingAttachments = rawAttachments;
if (parsed.wantsImage && parsed.wantsVideo) {
if (parsed.isAlternative) {
const minImages = parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1;
- const minVideos = parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1;
+ const expectedAlternativeVideoCount = parsed.wantsGif && !parsed.wantsOrdinaryVideo
+ ? parsed.expectedGifCount
+ : parsed.expectedVideoCount;
+ const alternativeVideoCount = parsed.wantsGif && !parsed.wantsOrdinaryVideo
+ ? gifCount
+ : videoCount;
+ const minVideos = expectedAlternativeVideoCount > 0 ? expectedAlternativeVideoCount : 1;
const exactImageAlt = parsed.hasExplicitImageCount && !parsed.isImageMinimum;
- const exactVideoAlt = parsed.hasExplicitVideoCount && !parsed.isVideoMinimum;
+ const exactVideoAlt = parsed.wantsGif && !parsed.wantsOrdinaryVideo
+ ? parsed.hasExplicitGifCount && !parsed.isGifMinimum
+ : parsed.hasExplicitVideoCount && !parsed.isVideoMinimum;
const matchesImageAlt = imageCount >= minImages
&& (!exactImageAlt || imageCount === parsed.expectedImageCount)
&& videoCount === 0
&& (!exactImageAlt || rawAttachments.length === parsed.expectedImageCount);
- const matchesVideoAlt = videoCount >= minVideos
- && (!exactVideoAlt || videoCount === parsed.expectedVideoCount)
+ const matchesVideoAlt = alternativeVideoCount >= minVideos
+ && (!exactVideoAlt || alternativeVideoCount === expectedAlternativeVideoCount)
&& imageCount === 0
- && (!exactVideoAlt || rawAttachments.length === parsed.expectedVideoCount);
+ && (!exactVideoAlt || rawAttachments.length === expectedAlternativeVideoCount);
if (!matchesImageAlt && !matchesVideoAlt) {
return false;
}
@@ -3000,7 +3122,7 @@ export class Agent extends LoopDetector {
}
if (parsed.hasExplicitImageCount && parsed.hasExplicitVideoCount
&& !parsed.isImageMinimum && !parsed.isVideoMinimum) {
- if (rawAttachments.length !== (parsed.expectedImageCount + parsed.expectedVideoCount)) {
+ if (rawAttachments.length !== (parsed.expectedImageCount + parsed.expectedVideoCount + parsed.expectedGifCount)) {
return false;
}
} else if (parsed.hasExplicitCardinality) {
@@ -3025,8 +3147,9 @@ export class Agent extends LoopDetector {
matchingAttachments = rawAttachments.filter(isImageAttachment);
} else if (parsed.wantsVideo && !parsed.wantsImage) {
if (imageCount > 0) return false;
- const hasExactVideoCount = !parsed.isVideoMinimum
- && ((parsed.hasExplicitVideoCount && !parsed.isVideoNegated) || parsed.hasExplicitGenericCount);
+ const hasExactVideoCount = (parsed.hasExplicitVideoCount && !parsed.isVideoNegated && !parsed.isVideoMinimum)
+ || (parsed.hasExplicitGifCount && !parsed.isGifNegated && !parsed.isGifMinimum)
+ || parsed.hasExplicitGenericCount;
if (hasExactVideoCount) {
if (videoCount !== parsed.expectedCount || rawAttachments.length !== parsed.expectedCount) {
return false;
@@ -3563,16 +3686,17 @@ export class Agent extends LoopDetector {
if (!intendedAccount || !publishedAccount
|| !accountMatches(requestedAccount)
|| !accountMatches(capturedAccount)) return false;
+ const publishedRecord = this._workflowSocialRecordWithUploadedAttachmentNames(records[0], binding);
return requirements.every(requirement => (
requirement?.field === 'account'
? true
: requirement?.field === 'body'
- ? this._workflowSocialPublishedBodyObserved(requirement, records[0])
+ ? this._workflowSocialPublishedBodyObserved(requirement, publishedRecord)
: requirement?.field === 'attachment'
- ? this._workflowSocialPublishedAttachmentObserved(requirement, records[0])
+ ? this._workflowSocialPublishedAttachmentObserved(requirement, publishedRecord)
: this._workflowPublishedPayloadValueObserved(requirement, {
- pageText: records[0].text,
- pageUrl: records[0].url,
+ pageText: publishedRecord.text,
+ pageUrl: publishedRecord.url,
publishedResourceIdentity: binding.publishedResourceIdentity,
})
));
@@ -13853,6 +13977,34 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return proof;
}
+ _rememberSocialPublishUploadEvidence(tabId, name, result = {}, completionState = null) {
+ const guard = this._planExecutionGuards.get(tabId);
+ const siteWorkflow = guard?.siteWorkflow;
+ if (!guard?.enabled
+ || name !== 'upload_file'
+ || siteWorkflow?.job?.id !== 'publish-post'
+ || !['twitter', 'bluesky'].includes(siteWorkflow.adapterName)
+ || !this._isSuccessfulExecutionEvidence(result)
+ || !['input_attached', 'page_consumed'].includes(result?.attachmentState)) return null;
+ const fileName = String(result?.attached?.name || '').split(/[\\/]/).pop().trim().slice(0, 500);
+ const actionSequence = Number(completionState?.lastAction?.sequence || completionState?.sequence || 0);
+ if (!fileName || !actionSequence) return null;
+ const prior = Array.isArray(guard.workflowSocialUploadEvidence)
+ ? guard.workflowSocialUploadEvidence
+ : [];
+ const normalizedName = fileName.toLocaleLowerCase();
+ const evidence = {
+ name: fileName,
+ attachmentState: result.attachmentState,
+ actionSequence,
+ };
+ guard.workflowSocialUploadEvidence = [
+ ...prior.filter(item => String(item?.name || '').toLocaleLowerCase() !== normalizedName),
+ evidence,
+ ].slice(-12);
+ return evidence;
+ }
+
_rememberWorkflowInventoryObservation(tabId, name, args, result) {
const guard = this._planExecutionGuards.get(tabId);
const siteWorkflow = guard?.siteWorkflow;
@@ -14612,6 +14764,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
guard.siteWorkflowUrl = liveUrl;
guard.workflowTerminalEvidence = null;
guard.verifiedSubmissionEvidence = false;
+ // Publication requirements and upload provenance belong to the currently
+ // bound destination. Reclassify and recollect them after X <-> Bluesky
+ // navigation instead of reusing the first platform's payload.
+ guard.workflowMetadataRequirements = [];
+ guard.workflowMetadataRequirementsResolved = false;
+ guard.workflowMetadataRequirementsIncomplete = false;
+ guard.workflowSocialUploadEvidence = [];
await this._ensureWorkflowMetadataRequirements(
tabId,
{ provider, costState: this.currentCostState.get(tabId) || null },
@@ -23018,8 +23177,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (extractedBody) {
const bodyReq = details.items.find(r => r.field === 'body');
if (bodyReq) {
- if (extractedBody.length > (bodyReq.value || '').length
- || bodyReq.value === '[from task]'
+ if (bodyReq.value === '[from task]'
|| extractedBody.includes(bodyReq.value)) {
bodyReq.value = this._workflowMetadataValue(extractedBody, 25000);
}
@@ -23790,6 +23948,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
socialPublishSatisfiedTargets: carryMatches && Array.isArray(carried.socialPublishSatisfiedTargets)
? [...carried.socialPublishSatisfiedTargets]
: [],
+ workflowSocialUploadEvidence: carryMatches && Array.isArray(carried.workflowSocialUploadEvidence)
+ ? carried.workflowSocialUploadEvidence.map(item => ({ ...item }))
+ : [],
workflowTerminalEvidence: carryMatches && carried.workflowTerminalEvidence
? { ...carried.workflowTerminalEvidence }
: null,
@@ -24118,6 +24279,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
|| Object.keys(guard.workflowReleaseAssetEvidence || {}).length > 0
|| Object.keys(guard.workflowPendingReleaseAssetEvidence || {}).length > 0
|| Object.keys(guard.workflowPendingUploadEvidence || {}).length > 0
+ || (guard.workflowSocialUploadEvidence || []).length > 0
)) {
const submit = this._completionSubmitStates.get(tabId);
this._continuationExecutionEvidence.set(tabId, {
@@ -24144,6 +24306,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
socialPublishSatisfiedTargets: Array.isArray(guard.socialPublishSatisfiedTargets)
? [...guard.socialPublishSatisfiedTargets]
: [],
+ workflowSocialUploadEvidence: Array.isArray(guard.workflowSocialUploadEvidence)
+ ? guard.workflowSocialUploadEvidence.map(item => ({ ...item }))
+ : [],
workflowTerminalEvidence: guard.workflowTerminalEvidence
? { ...guard.workflowTerminalEvidence }
: null,
diff --git a/test/run.js b/test/run.js
index 0f8ad957c..aaccab86e 100644
--- a/test/run.js
+++ b/test/run.js
@@ -90946,6 +90946,59 @@ test('social publication workflow follows the live X or Bluesky destination and
}
});
+test('social destination rebinding refreshes platform-specific payload and upload evidence', async () => {
+ for (const [index, AgentClass] of [AgentCh, AgentFx].entries()) {
+ const agent = new AgentClass({});
+ agent.useSiteAdapters = true;
+ agent._persist = () => {};
+ const tabId = 9040 + index;
+ const taskText = 'Post "A much longer announcement" on X and "B" on Bluesky.';
+ agent.conversations.set(tabId, [
+ { role: 'system', content: 'system' },
+ { role: 'user', content: taskText },
+ ]);
+ const twitterWorkflow = agent._resolvePlannerSiteWorkflow('https://x.com/compose/post', {
+ request_kind: 'execute',
+ site_job: 'publish-post',
+ });
+ const guard = agent._startPlanExecutionGuard(tabId, 'act', {
+ requestKind: 'execute',
+ requiresStateChange: true,
+ requiresSubmission: true,
+ siteWorkflow: twitterWorkflow,
+ siteWorkflowUrl: 'https://x.com/compose/post',
+ });
+ guard.workflowMetadataRequirements = [{ field: 'body', value: 'A much longer announcement' }];
+ guard.workflowMetadataRequirementsResolved = true;
+ guard.workflowSocialUploadEvidence = [{ name: 'x-card.png', attachmentState: 'input_attached', actionSequence: 3 }];
+ agent._currentUrl = async () => 'https://bsky.app/';
+ agent._currentProgressPageScope = () => 'https://bsky.app/';
+ let classifiedAdapter = '';
+ agent._chatWithCostAllowance = async (_provider, messages) => {
+ const context = JSON.parse(messages[1].content).siteContext;
+ classifiedAdapter = context?.workflow?.adapter || '';
+ return {
+ content: JSON.stringify({
+ mode: 'inactive',
+ allowedActions: [],
+ forbiddenActions: [],
+ targets: [],
+ workflowFields: [{ field: 'body', value: 'B' }],
+ confidence: 0.99,
+ pageScopePolicy: 'page',
+ }),
+ };
+ };
+ assert.equal(await agent._adoptLiveSocialPublishWorkflow(tabId, { chat: async () => ({ content: '{}' }) }), true);
+ assert.equal(classifiedAdapter, 'bluesky', AgentClass.name + ': rebind classified the stale platform');
+ assert.deepEqual(guard.workflowMetadataRequirements, [{ field: 'body', value: 'B' }],
+ AgentClass.name + ': longer X body overwrote the Bluesky-specific payload');
+ assert.equal(guard.workflowMetadataRequirementsResolved, true);
+ assert.deepEqual(guard.workflowSocialUploadEvidence, [],
+ AgentClass.name + ': X upload provenance leaked into the Bluesky binding');
+ }
+});
+
test('multi-platform social publication requires verified evidence for every destination', async () => {
for (const [index, AgentClass] of [AgentCh, AgentFx].entries()) {
const agent = new AgentClass({});
@@ -91383,6 +91436,23 @@ test('X and Bluesky same-route publication accepts only one new permalink with t
fixture.feedUrl,
submit,
), false, AgentClass.name + ': wrong uploaded asset satisfied specific attachment requirement');
+ assert.equal(agent._workflowPublishedResourcePayloadMatch(
+ {
+ ...submit.workflowBinding,
+ metadataRequirements: [
+ ...submit.workflowBinding.metadataRequirements,
+ { field: 'attachment', value: 'quarterly-chart.png' },
+ ],
+ uploadedAttachmentNames: ['quarterly-chart.png'],
+ publishedResourceIdentity: fixture.expectedIdentity,
+ preDispatchPublicationAccountIdentity: fixture.accountIdentity,
+ preDispatchPublicationAccountIdentityComplete: true,
+ },
+ guard,
+ pageStateWithImage,
+ fixture.feedUrl,
+ submit,
+ ), true, AgentClass.name + ': bound source filename did not survive a rewritten published CDN URL');
const pageStateWithSpecificImage = {
...exactPageState,
@@ -92266,6 +92336,81 @@ test('attachment requirement parser ignores numbers in specific attachment filen
}
});
+test('social upload filenames bind to type-compatible published DOM attachments', () => {
+ for (const [index, AgentClass] of [AgentCh, AgentFx].entries()) {
+ const agent = new AgentClass({});
+ agent.useSiteAdapters = true;
+ const tabId = 9220 + index;
+ const pageUrl = 'https://x.com/compose/post';
+ const siteWorkflow = agent._resolvePlannerSiteWorkflow(pageUrl, {
+ request_kind: 'execute',
+ site_job: 'publish-post',
+ });
+ const guard = agent._startPlanExecutionGuard(tabId, 'act', {
+ requestKind: 'execute',
+ requiresStateChange: true,
+ requiresSubmission: true,
+ siteWorkflow,
+ siteWorkflowUrl: pageUrl,
+ });
+ guard.workflowMetadataRequirements = [
+ { field: 'body', value: 'Quarterly results' },
+ { field: 'attachment', value: 'chart.png' },
+ ];
+ guard.workflowMetadataRequirementsResolved = true;
+ const upload = agent._rememberSocialPublishUploadEvidence(tabId, 'upload_file', {
+ success: true,
+ attached: { name: 'chart.png', size: 1234 },
+ attachmentState: 'input_attached',
+ }, { lastAction: { sequence: 4 } });
+ assert.equal(upload?.name, 'chart.png', AgentClass.name + ': upload filename was not retained');
+ const binding = agent._workflowSubmitBindingForAttempt(tabId, pageUrl, {}, {
+ publicationAccountIdentity: '@acme',
+ publicationAccountIdentityComplete: true,
+ });
+ assert.deepEqual(binding?.uploadedAttachmentNames, ['chart.png'],
+ AgentClass.name + ': pre-submit binding omitted the verified upload filename');
+
+ const cdnRecord = {
+ attachments: [{ type: 'image', src: 'https://pbs.twimg.com/media/G7RANDOM?format=png' }],
+ };
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'chart.png' }, cdnRecord,
+ ), false, AgentClass.name + ': rewritten CDN URL unexpectedly retained the source filename');
+ const namedRecord = agent._workflowSocialRecordWithUploadedAttachmentNames(cdnRecord, binding);
+ assert.equal(namedRecord.attachments?.[0]?.name, 'chart.png',
+ AgentClass.name + ': upload provenance was not joined to the observed media node');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'chart.png' }, namedRecord,
+ ), true, AgentClass.name + ': source filename did not verify the observed published media');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'chart.png' }, agent._workflowSocialRecordWithUploadedAttachmentNames(
+ { attachments: [{ type: 'video', src: 'https://video.twimg.com/ext_tw_video/123/pu/vid/clip.mp4' }] },
+ binding,
+ ),
+ ), false, AgentClass.name + ': an image filename was attached to an incompatible video record');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'chart.png' }, agent._workflowSocialRecordWithUploadedAttachmentNames(
+ { attachments: [] },
+ binding,
+ ),
+ ), false, AgentClass.name + ': upload provenance invented a missing published attachment');
+
+ guard.successfulTaskToolCalls = 1;
+ guard.evidenceTaskKey = guard.taskKey;
+ agent._storeContinuationExecutionEvidence(tabId);
+ const resumed = agent._startPlanExecutionGuard(tabId, 'act', {
+ requestKind: 'execute',
+ requiresStateChange: true,
+ requiresSubmission: true,
+ siteWorkflow,
+ siteWorkflowUrl: pageUrl,
+ }, { trustedContinuation: true });
+ assert.deepEqual(resumed.workflowSocialUploadEvidence, [upload],
+ AgentClass.name + ': trusted Continue discarded source filename provenance');
+ }
+});
+
test('attachment requirement parser treats conjunction-based requirements as generic', () => {
for (const AgentClass of [AgentCh, AgentFx]) {
const agent = new AgentClass({});
@@ -92712,6 +92857,48 @@ test('attachment verification matches specific attachment names without substrin
true,
AgentClass.name + ': an ordinary mp4 should pass a negated GIF requirement',
);
+ const twoGifRequirement = agent._parseWorkflowAttachmentRequirement({ value: 'two GIFs' });
+ assert.equal(twoGifRequirement.expectedGifCount, 2,
+ AgentClass.name + ': the GIF count was collapsed into the general video count');
+ assert.equal(twoGifRequirement.expectedVideoCount, 0,
+ AgentClass.name + ': GIFs were also counted as requested ordinary videos');
+ assert.equal(twoGifRequirement.hasExplicitGifCount, true);
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'two GIFs' },
+ { attachments: [gifMedia.typed] },
+ ), false, AgentClass.name + ': one GIF satisfied an exact two-GIF requirement');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'two GIFs' },
+ { attachments: [gifMedia.typed, gifMedia.named] },
+ ), true, AgentClass.name + ': two GIFs did not satisfy an exact two-GIF requirement');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'two GIFs' },
+ { attachments: [gifMedia.typed, gifMedia.mp4] },
+ ), false, AgentClass.name + ': an ordinary video substituted for the second GIF');
+
+ const gifAndVideoRequirement = agent._parseWorkflowAttachmentRequirement({ value: 'one GIF and one video' });
+ assert.equal(gifAndVideoRequirement.expectedGifCount, 1);
+ assert.equal(gifAndVideoRequirement.expectedVideoCount, 1);
+ assert.equal(gifAndVideoRequirement.expectedCount, 2);
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'one GIF and one video' },
+ { attachments: [gifMedia.typed, gifMedia.mp4] },
+ ), true, AgentClass.name + ': one GIF plus one ordinary video did not satisfy both typed counts');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'one GIF and one video' },
+ { attachments: [gifMedia.typed, gifMedia.named] },
+ ), false, AgentClass.name + ': two GIFs satisfied a GIF-plus-video requirement');
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'one GIF and one video' },
+ { attachments: [gifMedia.typed, gifMedia.mp4, { ...gifMedia.mp4, src: 'second.mp4' }] },
+ ), false, AgentClass.name + ': an extra ordinary video bypassed the exact typed counts');
+
+ const minimumGifs = agent._parseWorkflowAttachmentRequirement({ value: 'at least two GIFs' });
+ assert.equal(minimumGifs.isGifMinimum, true);
+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(
+ { value: 'at least two GIFs' },
+ { attachments: [gifMedia.typed, gifMedia.named, gifMedia.plain] },
+ ), true, AgentClass.name + ': a GIF minimum was incorrectly treated as an exact count');
// A singular article counts as exactly one, the same as the word "one".
const oneImage = { type: 'image', src: 'https://pbs.twimg.com/media/first.png' };