Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix(social-publish): verify optional media and alt text
Barack Sokullucb3d2f52086b
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex ab9f93a8b..ef7ef5203 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -256,6 +256,15 @@ const SOCIAL_POST_NEGATION = new RegExp(`^(?:\\s*(?:nothing|nowhere|none)|しないで|してはいけない|してはならない|はいけない|はならない|はだめ|はいけません|はなりません|すんな|するな|禁止|ないで|\\s*(?:하지\\s*마|하지\\s*마세요|하지\\s*않|금지))`,'iu',);+// Negation before a publish verb normally forbids the publication, but in+// idioms such as "don't forget to post" it governs the reminder verb instead.+// Keep this narrowly anchored to the text immediately before the publish verb+// so "don't forget not to post" remains a negative command.+const SOCIAL_AFFIRMATIVE_NEGATION_IDIOM = /(?<![\p{L}\p{N}_])(?:do\s+not|don['\u2019]?t|never)\s+(?:forget|fail|hesitate|neglect)\s+to\s*$/iu;+const socialNegationGovernsPublish = value => (+ SOCIAL_NEGATION.test(String(value || ''))+ && !SOCIAL_AFFIRMATIVE_NEGATION_IDIOM.test(String(value || ''))+);const SOCIAL_CLAUSE_DELIMITER = new RegExp(`([.!?;:\\n]|(?<![${SOCIAL_WORD_EDGE}])(?:and|then|but|or|nor|after|before|y|e|ed|luego|puis|et|ensuite|und|dann|poi|sonra|ve|затем|и)(?![${SOCIAL_WORD_EDGE}])|然后|然後|接着|そして|それから|または|、|。|,)`,'iu',@@ -2432,6 +2441,7 @@ export class Agent extends LoopDetector {.replace(/[^\p{L}\p{N}\s]/gu, ' ').replace(/\s+/g, ' ').trim();};const fields = [+ ['alt_text', ['alt text', 'alternative text', 'image alt text', 'attachment alt text', 'media alt text']],['paid_promotion', ['paid promotion', 'promotion payée', 'contenido promocional pagado', 'promoção paga', 'bezahlte werbung', 'promozione a pagamento', 'ücretli tanıtım', '有料プロモーション', '유료 프로모션', '付费宣传', '付費宣傳']],['recording_date', ['recording date', 'date recorded', "date d’enregistrement", 'fecha de grabación', 'data de gravação', 'aufnahmedatum', 'data di registrazione', 'kayıt tarihi', '録画日', '撮影日', '촬영 날짜', '录制日期', '錄製日期']],['recording_location', ['recording location', 'video location', "lieu d’enregistrement", 'ubicación de grabación', 'local de gravação', 'aufnahmeort', 'luogo di registrazione', 'kayıt konumu', '撮影場所', '촬영 위치', '录制地点', '錄製地點']],@@ -3380,7 +3390,24 @@ export class Agent extends LoopDetector {if (parsed.wantsNone || parsed.expectedCount === 0 || parsed.isNegative) {return rawAttachments.length === 0;}- if (!rawAttachments.length) return false;+ // An upper bound does not imply that one attachment is required. Empty+ // media is valid only when every conjunctive positive constraint permits+ // zero; for alternatives, one maximum-qualified branch is sufficient.+ const allowsNoAttachments = parsed.isGeneric && (+ parsed.isAlternative+ ? (parsed.isMaximumCount+ || (parsed.wantsImage && parsed.isImageMaximum)+ || (parsed.wantsOrdinaryVideo && parsed.isVideoMaximum)+ || (parsed.wantsGif && parsed.isGifMaximum))+ : (parsed.isMaximumCount+ || parsed.isImageMaximum+ || parsed.isVideoMaximum+ || parsed.isGifMaximum)+ && (!parsed.wantsImage || parsed.isImageMaximum || parsed.isImageNegated)+ && (!parsed.wantsOrdinaryVideo || parsed.isVideoMaximum || parsed.isVideoNegated)+ && (!parsed.wantsGif || parsed.isGifMaximum || parsed.isGifNegated)+ );+ if (!rawAttachments.length) return allowsNoAttachments;const attachmentType = att => (typeof att === 'string' ? att : att?.type || att?.kind || '');const isVideoAttachment = (att) => {@@ -3416,13 +3443,13 @@ export class Agent extends LoopDetector {const gifCount = rawAttachments.filter(isGifAttachment).length;const ordinaryVideoCount = rawAttachments.filter(att => isVideoAttachment(att) && !isGifAttachment(att)).length;if (parsed.wantsGif) {- const requiredGifCount = parsed.isGifMaximum ? 1 : (parsed.expectedGifCount > 0 ? parsed.expectedGifCount : 1);+ const requiredGifCount = parsed.isGifMaximum ? 0 : (parsed.expectedGifCount > 0 ? parsed.expectedGifCount : 1);if (gifCount < requiredGifCount) return false;if (parsed.hasExplicitGifCount && !parsed.isGifMinimum && !parsed.isGifMaximum && gifCount !== parsed.expectedGifCount) return false;if (parsed.hasExplicitGifCount && parsed.isGifMaximum && gifCount > parsed.expectedGifCount) return false;}if (parsed.wantsGif && parsed.wantsOrdinaryVideo) {- const requiredOrdinaryVideoCount = parsed.isVideoMaximum ? 1 : (parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1);+ const requiredOrdinaryVideoCount = parsed.isVideoMaximum ? 0 : (parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1);if (ordinaryVideoCount < requiredOrdinaryVideoCount) return false;if (parsed.hasExplicitVideoCount && !parsed.isVideoMinimum && !parsed.isVideoMaximum&& ordinaryVideoCount !== parsed.expectedVideoCount) return false;@@ -3443,7 +3470,7 @@ export class Agent extends LoopDetector {let matchingAttachments = rawAttachments;if (parsed.wantsImage && parsed.wantsVideo) {if (parsed.isAlternative) {- const minImages = parsed.isImageMaximum ? 1 : (parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1);+ const minImages = parsed.isImageMaximum ? 0 : (parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1);const expectedAlternativeVideoCount = parsed.wantsGif && !parsed.wantsOrdinaryVideo? parsed.expectedGifCount: parsed.expectedVideoCount;@@ -3453,7 +3480,7 @@ export class Agent extends LoopDetector {const isAlternativeVideoMaximum = parsed.wantsGif && !parsed.wantsOrdinaryVideo? parsed.isGifMaximum: parsed.isVideoMaximum;- const minVideos = isAlternativeVideoMaximum ? 1 : (expectedAlternativeVideoCount > 0 ? expectedAlternativeVideoCount : 1);+ const minVideos = isAlternativeVideoMaximum ? 0 : (expectedAlternativeVideoCount > 0 ? expectedAlternativeVideoCount : 1);const exactImageAlt = parsed.hasExplicitImageCount && !parsed.isImageMinimum && !parsed.isImageMaximum;const exactVideoAlt = parsed.wantsGif && !parsed.wantsOrdinaryVideo? parsed.hasExplicitGifCount && !parsed.isGifMinimum && !parsed.isGifMaximum@@ -3477,8 +3504,10 @@ export class Agent extends LoopDetector {? rawAttachments.filter(isImageAttachment): rawAttachments.filter(isVideoAttachment);} else {- const minImages = parsed.isImageMaximum ? 1 : (parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1);- const minVideos = parsed.isVideoMaximum ? 1 : (parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1);+ const minImages = parsed.isImageMaximum ? 0 : (parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1);+ const minVideos = parsed.wantsGif && !parsed.wantsOrdinaryVideo+ ? (parsed.isGifMaximum ? 0 : (parsed.expectedGifCount > 0 ? parsed.expectedGifCount : 1))+ : (parsed.isVideoMaximum ? 0 : (parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1));if (imageCount < minImages || videoCount < minVideos) {return false;}@@ -3528,9 +3557,6 @@ export class Agent extends LoopDetector {if (imageCount > parsed.expectedCount || rawAttachments.length > parsed.expectedCount) {return false;}- if (imageCount < 1) {- return false;- }} else {if (imageCount < parsed.expectedCount) {return false;@@ -3555,9 +3581,6 @@ export class Agent extends LoopDetector {if (videoCount > parsed.expectedCount || rawAttachments.length > parsed.expectedCount) {return false;}- if (videoCount < 1) {- return false;- }} else if (videoCount < parsed.expectedCount) {return false;}@@ -3572,9 +3595,6 @@ export class Agent extends LoopDetector {if (rawAttachments.length > parsed.expectedCount) {return false;}- if (rawAttachments.length < 1) {- return false;- }} else {if (rawAttachments.length < parsed.expectedCount) {return false;@@ -3630,6 +3650,18 @@ export class Agent extends LoopDetector {return canMatchAll(0, new Set());}+ _workflowSocialPublishedAltTextObserved(requirement, record) {+ const want = this._workflowMetadataValue(requirement?.value);+ if (!want) return false;+ const attachments = Array.isArray(record?.attachments)+ ? record.attachments+ : (Array.isArray(record?.media) ? record.media : []);+ return attachments.some(attachment => (+ attachment && typeof attachment === 'object'+ && this._workflowMetadataValue(attachment.alt) === want+ ));+ }+_workflowGithubReleaseIdentityParts(identity) {const match = /^github:github\.com\/([^/]+\/[^/]+)\/releases\/tag\/(.+)$/i.exec(String(identity || ''));if (!match) return null;@@ -4109,6 +4141,8 @@ export class Agent extends LoopDetector {? this._workflowSocialPublishedBodyObserved(requirement, publishedRecord): requirement?.field === 'attachment'? this._workflowSocialPublishedAttachmentObserved(requirement, publishedRecord)+ : requirement?.field === 'alt_text'+ ? this._workflowSocialPublishedAltTextObserved(requirement, publishedRecord): this._workflowPublishedPayloadValueObserved(requirement, {pageText: publishedRecord.text,pageUrl: publishedRecord.url,@@ -16750,7 +16784,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (publish) {const beforeVerb = c.maskedText.slice(0, publish.index);const afterVerb = c.maskedText.slice(publish.index + publish[0].length);- hasExplicitNeg = SOCIAL_NEGATION.test(beforeVerb) || SOCIAL_POST_NEGATION.test(afterVerb.trim());+ hasExplicitNeg = socialNegationGovernsPublish(beforeVerb) || SOCIAL_POST_NEGATION.test(afterVerb.trim());} else {hasExplicitNeg = SOCIAL_NEGATION.test(c.maskedText);}@@ -16803,7 +16837,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (!publish) return false;const before = targetText.slice(0, publish.index);if (SOCIAL_READ_VERBS.test(before)) return false;- if (SOCIAL_NEGATION.test(before)) return false;+ if (socialNegationGovernsPublish(before)) return false;const after = targetText.slice(publish.index + publish[0].length);if (SOCIAL_POST_NEGATION.test(after.trim())) return false;if (SOCIAL_NOUN_LIKE_PUBLISH.test(publish[0]) && SOCIAL_READ_VERBS.test(after)) return false;@@ -16937,7 +16971,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst verbIndex = verb.index ?? 0;const beforeVerbClause = targetText.slice(0, verbIndex);if (SOCIAL_READ_VERBS.test(beforeVerbClause)) continue;- if (SOCIAL_NEGATION.test(beforeVerbClause)) continue;+ if (socialNegationGovernsPublish(beforeVerbClause)) continue;const verbWord = verb[0] || '';const afterVerbText = targetText.slice(verbIndex + verbWord.length);if (SOCIAL_POST_NEGATION.test(afterVerbText.trim())) continue;@@ -17062,7 +17096,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst match = targetText.match(/\btweet\s+(?:this|that|it|the\s+following)\b/i);if (!match) return false;const before = targetText.slice(0, match.index);- if (SOCIAL_READ_VERBS.test(before) || SOCIAL_NEGATION.test(before)) return false;+ if (SOCIAL_READ_VERBS.test(before) || socialNegationGovernsPublish(before)) return false;const after = targetText.slice(match.index + match[0].length);if (SOCIAL_POST_NEGATION.test(after.trim())) return false;return true;@@ -25520,7 +25554,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst quotedPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?:“([\\s\\S]+?)”|「([\\s\\S]+?)」|『([\\s\\S]+?)』|«([\\s\\S]+?)»|"([\\s\\S]+?)")`, 'iu');const singleQuotePattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?:(?<!\\p{L})'([\\s\\S]+?)'(?!\\p{L}))`, 'iu');const colonPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?<!https?|ftp|sftp)(?:(?<!\\d)[::]|[::](?!\\d{2}))(?!\\/\\/)\\s*([\\s\\S]+)$`, 'iu');- for (const text of candidates) {+ const altTextMetadataPattern = /(?<![\p{L}\p{N}_])(?:attachment\s+)?(?:alt(?:ernative)?\s+text|image\s+alt\s+text|media\s+alt\s+text)\s*(?::|=)?\s*(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|“[\s\S]*?”|«[\s\S]*?»|「[\s\S]*?」|『[\s\S]*?』)/giu;+ for (const candidateText of candidates) {+ // A quoted alt-text value describes an attachment; it is not the post+ // body merely because it follows the publish verb.+ const text = candidateText.replace(altTextMetadataPattern, match => ' '.repeat(match.length));let body = '';// Scan for the colon delimiter that introduces the post body.// We look for colons occurring after a publish verb, skipping:@@ -25672,7 +25710,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d'mode=active only when the user asks the agent to perform repeated item/action work that benefits from row tracking.','Exception: for siteContext.workflow.job="upload-release-assets" with requiresLedger=true, use mode=active and list every concrete requested target even when there is exactly one. Copy each exact requested filename or path into targets; do not merge or omit assets. When the user names the release tag, also return it as workflowFields=[{"field":"tag","value":"exact tag"}]; return workflowFields=[] when no tag is named.','For siteContext.workflow.job="update-metadata", workflowFields must contain every metadata field explicitly requested by the user and its complete exact intended value. Use canonical field names title, description, visibility, audience, tags, category, playlist, language, license, comments, embedding, paid_promotion, recording_date, or recording_location. Never infer a field or value from page content.',- 'For siteContext.workflow.job="publish-release", "publish-post", "publish-content", or "edit-file-and-commit", workflowFields must contain every publication field explicitly requested by the user and its complete exact intended value (for long post bodies or notes exceeding response budget, provide a short excerpt; complete bodies are preserved from task context). Use canonical field names tag, title, notes, body, visibility, attachment, path, branch, or commit_message; for publish-post only, also use account when the user explicitly names the publishing account. For edit-file-and-commit, include path, branch, and commit_message only when the user explicitly supplied them; the runtime separately binds the exact verified editor content. Never infer a field or value from page content.',+ 'For siteContext.workflow.job="publish-release", "publish-post", "publish-content", or "edit-file-and-commit", workflowFields must contain every publication field explicitly requested by the user and its complete exact intended value (for long post bodies or notes exceeding response budget, provide a short excerpt; complete bodies are preserved from task context). Use canonical field names tag, title, notes, body, visibility, attachment, path, branch, or commit_message; for publish-post only, also use account when the user explicitly names the publishing account and alt_text when the user explicitly requests attachment alternative text. For edit-file-and-commit, include path, branch, and commit_message only when the user explicitly supplied them; the runtime separately binds the exact verified editor content. Never infer a field or value from page content.','For siteContext.workflow.job="draft-email" or "send-email", workflowFields must contain every message field explicitly requested by the user and its complete exact intended value. Use canonical field names subject or body. Never infer a field or value from page content.','For siteContext.workflow.template="transaction", workflowFields must contain every booking detail explicitly requested by the user and its exact value. Use canonical field names train, travel_date, departure, arrival, passenger, or seat_class. Never infer a detail from page content.','For siteContext.workflow.template="form", workflowLabelValues must contain one entry per field the user supplied an exact value for, as {"label":"the field in the user\'s words","value":"the exact value"}. Return workflowLabelValues=[] when the user supplied no exact values, and never copy a value from page content.',@@ -32302,7 +32340,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn {type: isVideo ? 'video' : 'image',src: String(src || '').slice(0, 500),- alt: String(alt || '').slice(0, 500),+ alt: String(alt || '').slice(0, 10000),};});const prior = workflowResourceRecordMap.get(identity);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex cca23486e..c0e061658 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -190,6 +190,15 @@ const SOCIAL_POST_NEGATION = new RegExp(`^(?:\\s*(?:nothing|nowhere|none)|しないで|してはいけない|してはならない|はいけない|はならない|はだめ|はいけません|はなりません|すんな|するな|禁止|ないで|\\s*(?:하지\\s*마|하지\\s*마세요|하지\\s*않|금지))`,'iu',);+// Negation before a publish verb normally forbids the publication, but in+// idioms such as "don't forget to post" it governs the reminder verb instead.+// Keep this narrowly anchored to the text immediately before the publish verb+// so "don't forget not to post" remains a negative command.+const SOCIAL_AFFIRMATIVE_NEGATION_IDIOM = /(?<![\p{L}\p{N}_])(?:do\s+not|don['\u2019]?t|never)\s+(?:forget|fail|hesitate|neglect)\s+to\s*$/iu;+const socialNegationGovernsPublish = value => (+ SOCIAL_NEGATION.test(String(value || ''))+ && !SOCIAL_AFFIRMATIVE_NEGATION_IDIOM.test(String(value || ''))+);const SOCIAL_CLAUSE_DELIMITER = new RegExp(`([.!?;:\\n]|(?<![${SOCIAL_WORD_EDGE}])(?:and|then|but|or|nor|after|before|y|e|ed|luego|puis|et|ensuite|und|dann|poi|sonra|ve|затем|и)(?![${SOCIAL_WORD_EDGE}])|然后|然後|接着|そして|それから|または|、|。|,)`,'iu',@@ -2147,6 +2156,7 @@ export class Agent extends LoopDetector {.replace(/[^\p{L}\p{N}\s]/gu, ' ').replace(/\s+/g, ' ').trim();};const fields = [+ ['alt_text', ['alt text', 'alternative text', 'image alt text', 'attachment alt text', 'media alt text']],['paid_promotion', ['paid promotion', 'promotion payée', 'contenido promocional pagado', 'promoção paga', 'bezahlte werbung', 'promozione a pagamento', 'ücretli tanıtım', '有料プロモーション', '유료 프로모션', '付费宣传', '付費宣傳']],['recording_date', ['recording date', 'date recorded', "date d’enregistrement", 'fecha de grabación', 'data de gravação', 'aufnahmedatum', 'data di registrazione', 'kayıt tarihi', '録画日', '撮影日', '촬영 날짜', '录制日期', '錄製日期']],['recording_location', ['recording location', 'video location', "lieu d’enregistrement", 'ubicación de grabación', 'local de gravação', 'aufnahmeort', 'luogo di registrazione', 'kayıt konumu', '撮影場所', '촬영 위치', '录制地点', '錄製地點']],@@ -3095,7 +3105,24 @@ export class Agent extends LoopDetector {if (parsed.wantsNone || parsed.expectedCount === 0 || parsed.isNegative) {return rawAttachments.length === 0;}- if (!rawAttachments.length) return false;+ // An upper bound does not imply that one attachment is required. Empty+ // media is valid only when every conjunctive positive constraint permits+ // zero; for alternatives, one maximum-qualified branch is sufficient.+ const allowsNoAttachments = parsed.isGeneric && (+ parsed.isAlternative+ ? (parsed.isMaximumCount+ || (parsed.wantsImage && parsed.isImageMaximum)+ || (parsed.wantsOrdinaryVideo && parsed.isVideoMaximum)+ || (parsed.wantsGif && parsed.isGifMaximum))+ : (parsed.isMaximumCount+ || parsed.isImageMaximum+ || parsed.isVideoMaximum+ || parsed.isGifMaximum)+ && (!parsed.wantsImage || parsed.isImageMaximum || parsed.isImageNegated)+ && (!parsed.wantsOrdinaryVideo || parsed.isVideoMaximum || parsed.isVideoNegated)+ && (!parsed.wantsGif || parsed.isGifMaximum || parsed.isGifNegated)+ );+ if (!rawAttachments.length) return allowsNoAttachments;const attachmentType = att => (typeof att === 'string' ? att : att?.type || att?.kind || '');const isVideoAttachment = (att) => {@@ -3131,13 +3158,13 @@ export class Agent extends LoopDetector {const gifCount = rawAttachments.filter(isGifAttachment).length;const ordinaryVideoCount = rawAttachments.filter(att => isVideoAttachment(att) && !isGifAttachment(att)).length;if (parsed.wantsGif) {- const requiredGifCount = parsed.isGifMaximum ? 1 : (parsed.expectedGifCount > 0 ? parsed.expectedGifCount : 1);+ const requiredGifCount = parsed.isGifMaximum ? 0 : (parsed.expectedGifCount > 0 ? parsed.expectedGifCount : 1);if (gifCount < requiredGifCount) return false;if (parsed.hasExplicitGifCount && !parsed.isGifMinimum && !parsed.isGifMaximum && gifCount !== parsed.expectedGifCount) return false;if (parsed.hasExplicitGifCount && parsed.isGifMaximum && gifCount > parsed.expectedGifCount) return false;}if (parsed.wantsGif && parsed.wantsOrdinaryVideo) {- const requiredOrdinaryVideoCount = parsed.isVideoMaximum ? 1 : (parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1);+ const requiredOrdinaryVideoCount = parsed.isVideoMaximum ? 0 : (parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1);if (ordinaryVideoCount < requiredOrdinaryVideoCount) return false;if (parsed.hasExplicitVideoCount && !parsed.isVideoMinimum && !parsed.isVideoMaximum&& ordinaryVideoCount !== parsed.expectedVideoCount) return false;@@ -3158,7 +3185,7 @@ export class Agent extends LoopDetector {let matchingAttachments = rawAttachments;if (parsed.wantsImage && parsed.wantsVideo) {if (parsed.isAlternative) {- const minImages = parsed.isImageMaximum ? 1 : (parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1);+ const minImages = parsed.isImageMaximum ? 0 : (parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1);const expectedAlternativeVideoCount = parsed.wantsGif && !parsed.wantsOrdinaryVideo? parsed.expectedGifCount: parsed.expectedVideoCount;@@ -3168,7 +3195,7 @@ export class Agent extends LoopDetector {const isAlternativeVideoMaximum = parsed.wantsGif && !parsed.wantsOrdinaryVideo? parsed.isGifMaximum: parsed.isVideoMaximum;- const minVideos = isAlternativeVideoMaximum ? 1 : (expectedAlternativeVideoCount > 0 ? expectedAlternativeVideoCount : 1);+ const minVideos = isAlternativeVideoMaximum ? 0 : (expectedAlternativeVideoCount > 0 ? expectedAlternativeVideoCount : 1);const exactImageAlt = parsed.hasExplicitImageCount && !parsed.isImageMinimum && !parsed.isImageMaximum;const exactVideoAlt = parsed.wantsGif && !parsed.wantsOrdinaryVideo? parsed.hasExplicitGifCount && !parsed.isGifMinimum && !parsed.isGifMaximum@@ -3192,8 +3219,10 @@ export class Agent extends LoopDetector {? rawAttachments.filter(isImageAttachment): rawAttachments.filter(isVideoAttachment);} else {- const minImages = parsed.isImageMaximum ? 1 : (parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1);- const minVideos = parsed.isVideoMaximum ? 1 : (parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1);+ const minImages = parsed.isImageMaximum ? 0 : (parsed.expectedImageCount > 0 ? parsed.expectedImageCount : 1);+ const minVideos = parsed.wantsGif && !parsed.wantsOrdinaryVideo+ ? (parsed.isGifMaximum ? 0 : (parsed.expectedGifCount > 0 ? parsed.expectedGifCount : 1))+ : (parsed.isVideoMaximum ? 0 : (parsed.expectedVideoCount > 0 ? parsed.expectedVideoCount : 1));if (imageCount < minImages || videoCount < minVideos) {return false;}@@ -3243,9 +3272,6 @@ export class Agent extends LoopDetector {if (imageCount > parsed.expectedCount || rawAttachments.length > parsed.expectedCount) {return false;}- if (imageCount < 1) {- return false;- }} else {if (imageCount < parsed.expectedCount) {return false;@@ -3270,9 +3296,6 @@ export class Agent extends LoopDetector {if (videoCount > parsed.expectedCount || rawAttachments.length > parsed.expectedCount) {return false;}- if (videoCount < 1) {- return false;- }} else if (videoCount < parsed.expectedCount) {return false;}@@ -3287,9 +3310,6 @@ export class Agent extends LoopDetector {if (rawAttachments.length > parsed.expectedCount) {return false;}- if (rawAttachments.length < 1) {- return false;- }} else {if (rawAttachments.length < parsed.expectedCount) {return false;@@ -3345,6 +3365,18 @@ export class Agent extends LoopDetector {return canMatchAll(0, new Set());}+ _workflowSocialPublishedAltTextObserved(requirement, record) {+ const want = this._workflowMetadataValue(requirement?.value);+ if (!want) return false;+ const attachments = Array.isArray(record?.attachments)+ ? record.attachments+ : (Array.isArray(record?.media) ? record.media : []);+ return attachments.some(attachment => (+ attachment && typeof attachment === 'object'+ && this._workflowMetadataValue(attachment.alt) === want+ ));+ }+_workflowGithubReleaseIdentityParts(identity) {const match = /^github:github\.com\/([^/]+\/[^/]+)\/releases\/tag\/(.+)$/i.exec(String(identity || ''));if (!match) return null;@@ -3824,6 +3856,8 @@ export class Agent extends LoopDetector {? this._workflowSocialPublishedBodyObserved(requirement, publishedRecord): requirement?.field === 'attachment'? this._workflowSocialPublishedAttachmentObserved(requirement, publishedRecord)+ : requirement?.field === 'alt_text'+ ? this._workflowSocialPublishedAltTextObserved(requirement, publishedRecord): this._workflowPublishedPayloadValueObserved(requirement, {pageText: publishedRecord.text,pageUrl: publishedRecord.url,@@ -14549,7 +14583,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (publish) {const beforeVerb = c.maskedText.slice(0, publish.index);const afterVerb = c.maskedText.slice(publish.index + publish[0].length);- hasExplicitNeg = SOCIAL_NEGATION.test(beforeVerb) || SOCIAL_POST_NEGATION.test(afterVerb.trim());+ hasExplicitNeg = socialNegationGovernsPublish(beforeVerb) || SOCIAL_POST_NEGATION.test(afterVerb.trim());} else {hasExplicitNeg = SOCIAL_NEGATION.test(c.maskedText);}@@ -14602,7 +14636,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (!publish) return false;const before = targetText.slice(0, publish.index);if (SOCIAL_READ_VERBS.test(before)) return false;- if (SOCIAL_NEGATION.test(before)) return false;+ if (socialNegationGovernsPublish(before)) return false;const after = targetText.slice(publish.index + publish[0].length);if (SOCIAL_POST_NEGATION.test(after.trim())) return false;if (SOCIAL_NOUN_LIKE_PUBLISH.test(publish[0]) && SOCIAL_READ_VERBS.test(after)) return false;@@ -14736,7 +14770,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst verbIndex = verb.index ?? 0;const beforeVerbClause = targetText.slice(0, verbIndex);if (SOCIAL_READ_VERBS.test(beforeVerbClause)) continue;- if (SOCIAL_NEGATION.test(beforeVerbClause)) continue;+ if (socialNegationGovernsPublish(beforeVerbClause)) continue;const verbWord = verb[0] || '';const afterVerbText = targetText.slice(verbIndex + verbWord.length);if (SOCIAL_POST_NEGATION.test(afterVerbText.trim())) continue;@@ -14861,7 +14895,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst match = targetText.match(/\btweet\s+(?:this|that|it|the\s+following)\b/i);if (!match) return false;const before = targetText.slice(0, match.index);- if (SOCIAL_READ_VERBS.test(before) || SOCIAL_NEGATION.test(before)) return false;+ if (SOCIAL_READ_VERBS.test(before) || socialNegationGovernsPublish(before)) return false;const after = targetText.slice(match.index + match[0].length);if (SOCIAL_POST_NEGATION.test(after.trim())) return false;return true;@@ -23127,7 +23161,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst quotedPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?:“([\\s\\S]+?)”|「([\\s\\S]+?)」|『([\\s\\S]+?)』|«([\\s\\S]+?)»|"([\\s\\S]+?)")`, 'iu');const singleQuotePattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?:(?<!\\p{L})'([\\s\\S]+?)'(?!\\p{L}))`, 'iu');const colonPattern = new RegExp(`${publishVerbPattern}[\\s\\S]*?(?<!https?|ftp|sftp)(?:(?<!\\d)[::]|[::](?!\\d{2}))(?!\\/\\/)\\s*([\\s\\S]+)$`, 'iu');- for (const text of candidates) {+ const altTextMetadataPattern = /(?<![\p{L}\p{N}_])(?:attachment\s+)?(?:alt(?:ernative)?\s+text|image\s+alt\s+text|media\s+alt\s+text)\s*(?::|=)?\s*(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|“[\s\S]*?”|«[\s\S]*?»|「[\s\S]*?」|『[\s\S]*?』)/giu;+ for (const candidateText of candidates) {+ // A quoted alt-text value describes an attachment; it is not the post+ // body merely because it follows the publish verb.+ const text = candidateText.replace(altTextMetadataPattern, match => ' '.repeat(match.length));let body = '';// Scan for the colon delimiter that introduces the post body.// We look for colons occurring after a publish verb, skipping:@@ -23279,7 +23317,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d'mode=active only when the user asks the agent to perform repeated item/action work that benefits from row tracking.','Exception: for siteContext.workflow.job="upload-release-assets" with requiresLedger=true, use mode=active and list every concrete requested target even when there is exactly one. Copy each exact requested filename or path into targets; do not merge or omit assets. When the user names the release tag, also return it as workflowFields=[{"field":"tag","value":"exact tag"}]; return workflowFields=[] when no tag is named.','For siteContext.workflow.job="update-metadata", workflowFields must contain every metadata field explicitly requested by the user and its complete exact intended value. Use canonical field names title, description, visibility, audience, tags, category, playlist, language, license, comments, embedding, paid_promotion, recording_date, or recording_location. Never infer a field or value from page content.',- 'For siteContext.workflow.job="publish-release", "publish-post", "publish-content", or "edit-file-and-commit", workflowFields must contain every publication field explicitly requested by the user and its complete exact intended value (for long post bodies or notes exceeding response budget, provide a short excerpt; complete bodies are preserved from task context). Use canonical field names tag, title, notes, body, visibility, attachment, path, branch, or commit_message; for publish-post only, also use account when the user explicitly names the publishing account. For edit-file-and-commit, include path, branch, and commit_message only when the user explicitly supplied them; the runtime separately binds the exact verified editor content. Never infer a field or value from page content.',+ 'For siteContext.workflow.job="publish-release", "publish-post", "publish-content", or "edit-file-and-commit", workflowFields must contain every publication field explicitly requested by the user and its complete exact intended value (for long post bodies or notes exceeding response budget, provide a short excerpt; complete bodies are preserved from task context). Use canonical field names tag, title, notes, body, visibility, attachment, path, branch, or commit_message; for publish-post only, also use account when the user explicitly names the publishing account and alt_text when the user explicitly requests attachment alternative text. For edit-file-and-commit, include path, branch, and commit_message only when the user explicitly supplied them; the runtime separately binds the exact verified editor content. Never infer a field or value from page content.','For siteContext.workflow.job="draft-email" or "send-email", workflowFields must contain every message field explicitly requested by the user and its complete exact intended value. Use canonical field names subject or body. Never infer a field or value from page content.','For siteContext.workflow.template="transaction", workflowFields must contain every booking detail explicitly requested by the user and its exact value. Use canonical field names train, travel_date, departure, arrival, passenger, or seat_class. Never infer a detail from page content.','For siteContext.workflow.template="form", workflowLabelValues must contain one entry per field the user supplied an exact value for, as {"label":"the field in the user\'s words","value":"the exact value"}. Return workflowLabelValues=[] when the user supplied no exact values, and never copy a value from page content.',@@ -28781,7 +28819,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn {type: isVideo ? 'video' : 'image',src: String(src || '').slice(0, 500),- alt: String(alt || '').slice(0, 500),+ alt: String(alt || '').slice(0, 10000),};});const prior = workflowResourceRecordMap.get(identity);diff --git a/test/run.js b/test/run.jsindex 39717404f..c1ffca4f1 100644--- a/test/run.js+++ b/test/run.js@@ -90749,6 +90749,14 @@ test('social publication workflow follows the live X or Bluesky destination and'negated publication command was wrongly treated as a publish destination'],['Never publish to Bluesky', [],'negated Bluesky publication command was wrongly treated as a publish destination'],+ ["Don't forget to post this on X", ['twitter'],+ 'affirmative do-not-forget idiom was treated as publish negation'],+ ['Do not forget to publish this on Bluesky', ['bluesky'],+ 'affirmative do-not-forget idiom was treated as Bluesky publish negation'],+ ['Never hesitate to post this on X', ['twitter'],+ 'affirmative never-hesitate idiom was treated as publish negation'],+ ["Don't forget not to post this on X", [],+ 'nested not-to-post command was incorrectly made affirmative'],["Don't tweet this", [],'negated tweet-this command was wrongly treated as a publish destination'],['Do not post on https://x.com/home; fill the survey instead', [],@@ -91417,6 +91425,39 @@ test('X and Bluesky same-route publication accepts only one new permalink with tsubmit,), true, AgentClass.name + ': post with matching image attachment was rejected');+ assert.equal(agent._workflowPublishedResourcePayloadMatch(+ {+ ...submit.workflowBinding,+ metadataRequirements: [+ ...submit.workflowBinding.metadataRequirements,+ { field: 'alt_text', value: 'screenshot' },+ ],+ publishedResourceIdentity: fixture.expectedIdentity,+ preDispatchPublicationAccountIdentity: fixture.accountIdentity,+ preDispatchPublicationAccountIdentityComplete: true,+ },+ guard,+ pageStateWithImage,+ fixture.feedUrl,+ submit,+ ), true, AgentClass.name + ': matching attachment alt text was rejected');+ assert.equal(agent._workflowPublishedResourcePayloadMatch(+ {+ ...submit.workflowBinding,+ metadataRequirements: [+ ...submit.workflowBinding.metadataRequirements,+ { field: 'alt_text', value: 'Sales growth' },+ ],+ publishedResourceIdentity: fixture.expectedIdentity,+ preDispatchPublicationAccountIdentity: fixture.accountIdentity,+ preDispatchPublicationAccountIdentityComplete: true,+ },+ guard,+ pageStateWithImage,+ fixture.feedUrl,+ submit,+ ), false, AgentClass.name + ': mismatched attachment alt text was accepted');+assert.equal(agent._workflowPublishedResourcePayloadMatch({...submit.workflowBinding,@@ -92287,6 +92328,69 @@ test('extracting post body supports multilingual commands with colons and quotes}});+test('publish-post alt text is a distinct verified metadata requirement', async () => {+ for (const [index, AgentClass] of [AgentCh, AgentFx].entries()) {+ const agent = new AgentClass({});+ assert.equal(agent._workflowMetadataFieldKey('alt text'), 'alt_text',+ AgentClass.name + ': alt text did not normalize to its canonical field');+ assert.match(+ agent._progressIntentClassifierMessages('Post chart.png on X with alt text "Sales growth"', {+ workflow: { job: 'publish-post' },+ })[0].content,+ /alt_text when the user explicitly requests attachment alternative text/,+ AgentClass.name + ': classifier prompt omitted publish-post alt text',+ );+ assert.equal(+ agent._extractWorkflowTaskBody('Post chart.png on X with alt text "Sales growth"'),+ '',+ AgentClass.name + ': quoted alt text was misclassified as the post body',+ );+ assert.equal(+ agent._extractWorkflowTaskBody('Post chart.png on X with alternative text “Sales growth”'),+ '',+ AgentClass.name + ': smart-quoted alternative text was misclassified as the post body',+ );+ assert.equal(+ agent._extractWorkflowTaskBody('Post "Launch update" on X with alt text "Sales growth"'),+ 'Launch update',+ AgentClass.name + ': masking alt text hid the actual quoted post body',+ );++ const tabId = 9880 + 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 provider = {+ chat: async () => ({+ content: JSON.stringify({+ workflowFields: [+ { field: 'attachment', value: 'chart.png' },+ { field: 'alt_text', value: 'Sales growth' },+ ],+ }),+ }),+ };+ await agent._classifyProgressIntentWithProvider(tabId, {+ provider,+ taskText: 'Post chart.png on X with alt text "Sales growth"',+ pageScope: 'https://x.com/home',+ });+ assert.deepEqual(guard.workflowMetadataRequirements, [+ { field: 'attachment', value: 'chart.png' },+ { field: 'alt_text', value: 'Sales growth' },+ ], AgentClass.name + ': classifier did not retain attachment and alt text separately');+ assert.equal(guard.workflowMetadataRequirementsIncomplete, false,+ AgentClass.name + ': valid alt-text metadata was marked incomplete');+ }+});+test('classifier fallback leaves metadata requirements incomplete and unresolved', async () => {for (const [index, AgentClass] of [AgentCh, AgentFx].entries()) {const agent = new AgentClass({});@@ -92591,6 +92695,9 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {const image = index => ({ type: 'image', src: `https://pbs.twimg.com/media/image${index}.png` });const video = index => ({ type: 'video', src: `https://video.twimg.com/media/video${index}.mp4` });const gif = index => ({ type: 'animated_gif', src: `https://video.twimg.com/tweet_video/gif${index}.mp4` });+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'up to two images' }, { attachments: [] }), true,+ AgentClass.name + ': zero images should satisfy "up to two images"');assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'up to two images' }, { attachments: [image(1)] }), true,AgentClass.name + ': one image should satisfy "up to two images"');@@ -92603,6 +92710,9 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'one video and at most two images' }, { attachments: [video(1), image(1)] }), true,AgentClass.name + ': one video plus one image should satisfy the capped mixed requirement');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one video and at most two images' }, { attachments: [video(1)] }), true,+ AgentClass.name + ': exact video plus zero optional images should satisfy the capped mixed requirement');assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'one video and at most two images' }, { attachments: [video(1), image(1), image(2)] }), true,AgentClass.name + ': one video plus two images should satisfy the capped mixed requirement');@@ -92620,6 +92730,9 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'one video and at most two GIFs' }, { attachments: [video(1), gif(1)] }), true,AgentClass.name + ': one video plus one GIF should satisfy the GIF maximum');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'one video and at most two GIFs' }, { attachments: [video(1)] }), true,+ AgentClass.name + ': exact video plus zero optional GIFs should satisfy the GIF maximum');assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'one video and at most two GIFs' }, { attachments: [video(1), gif(1), gif(2)] }), true,AgentClass.name + ': one video plus two GIFs should satisfy the GIF maximum');@@ -92629,6 +92742,12 @@ test('upper-bound attachment qualifiers verify as maximum counts', () => {assert.equal(agent._workflowSocialPublishedAttachmentObserved({ value: 'one video and at most two GIFs' }, { attachments: [video(1), video(2), gif(1)] }), false,AgentClass.name + ': the GIF maximum loosened the exact ordinary-video count');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'up to two videos' }, { attachments: [] }), true,+ AgentClass.name + ': zero videos should satisfy a standalone video maximum');+ assert.equal(agent._workflowSocialPublishedAttachmentObserved(+ { value: 'up to two GIFs' }, { attachments: [] }), true,+ AgentClass.name + ': zero GIFs should satisfy a standalone GIF maximum');}});