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(recipient-guard): apply grouped role labels across coordinate recipient lists
Emre Sokullub97b0e272ccc
diff --git a/src/chrome/src/agent/message-recipient-guard.js b/src/chrome/src/agent/message-recipient-guard.jsindex 859c0a384..fbbca4dcb 100644--- a/src/chrome/src/agent/message-recipient-guard.js+++ b/src/chrome/src/agent/message-recipient-guard.js@@ -300,6 +300,7 @@ export function clarificationAuthorizesRecipientRole(clarifyContext, answer, can};const delimiterRe = /[,;,;\n\r|/]|(?:\s+(?:and|or|while|whilst|but|whereas|yet|however|instead\s+of|rather\s+than|as\s+well\s+as|以及|与|及|而|但是|但)\s+)/gi;+ const roleWordsRe = /\b(?:to|cc|bcc|carbon\s+copy|blind\s+carbon\s+copy)\b|收件人|主送|抄送|密送|暗送/i;let hasSpans = false;for (const alias of candidateAliases) {@@ -331,6 +332,28 @@ export function clarificationAuthorizesRecipientRole(clarifyContext, answer, canif (prefixPatterns[role].test(prefix) || suffixPatterns[role].test(suffix)) {return true;}++ // Grouped role suffix: e.g. Put Alice and Bob in BCC / 把Alice和Bob设为密送+ const fullSuffix = answerText.slice(span.end);+ const coordMatch = fullSuffix.match(/^(?:\s*(?:[,;,;和]|(?:\s+(?:and|or|以及|与|及)\s*))\s*[^,;,;\n\r|/]+?)+?(\s*(?:(?:as|in|into|to)\s+(?:the\s+)?(?:to|cc|bcc|blind\s+carbon\s+copy|carbon\s+copy)(?:\s+(?:field|role|recipient))?\b|[(\[【]\s*(?:to|cc|bcc)\s*[)\]】]|\s*[::]\s*(?:to|cc|bcc)\b|(?:作为|设为)?(?:收件人|主送|抄送|密送|暗送)))/i);+ if (coordMatch) {+ const intervening = fullSuffix.slice(0, coordMatch.index + coordMatch[0].length - coordMatch[1].length);+ const rolePart = coordMatch[1];+ if (!roleWordsRe.test(intervening) && suffixPatterns[role].test(rolePart)) {+ return true;+ }+ }++ // Grouped role prefix: e.g. To: Alice and Bob+ const fullPrefix = answerText.slice(0, span.start);+ const prefixCoordMatch = fullPrefix.match(/(?:(\b(?:to|cc|bcc)\s*[::]|(?:作为|设为)?(?:收件人|主送|抄送|密送|暗送)\s*[::]?)\s*[^,;,;\n\r|/]+(?:\s*(?:[,;,;和]|(?:\s+(?:and|or|以及|与|及)\s*))\s*[^,;,;\n\r|/]+)*\s*(?:[,;,;和]|(?:\s+(?:and|or|以及|与|及)\s*))\s*)$/i);+ if (prefixCoordMatch) {+ const roleLeader = prefixCoordMatch[1];+ const intervening = prefixCoordMatch[0].slice(roleLeader.length);+ if (!roleWordsRe.test(intervening) && prefixPatterns[role].test(roleLeader)) {+ return true;+ }+ }}}}diff --git a/src/firefox/src/agent/message-recipient-guard.js b/src/firefox/src/agent/message-recipient-guard.jsindex 859c0a384..fbbca4dcb 100644--- a/src/firefox/src/agent/message-recipient-guard.js+++ b/src/firefox/src/agent/message-recipient-guard.js@@ -300,6 +300,7 @@ export function clarificationAuthorizesRecipientRole(clarifyContext, answer, can};const delimiterRe = /[,;,;\n\r|/]|(?:\s+(?:and|or|while|whilst|but|whereas|yet|however|instead\s+of|rather\s+than|as\s+well\s+as|以及|与|及|而|但是|但)\s+)/gi;+ const roleWordsRe = /\b(?:to|cc|bcc|carbon\s+copy|blind\s+carbon\s+copy)\b|收件人|主送|抄送|密送|暗送/i;let hasSpans = false;for (const alias of candidateAliases) {@@ -331,6 +332,28 @@ export function clarificationAuthorizesRecipientRole(clarifyContext, answer, canif (prefixPatterns[role].test(prefix) || suffixPatterns[role].test(suffix)) {return true;}++ // Grouped role suffix: e.g. Put Alice and Bob in BCC / 把Alice和Bob设为密送+ const fullSuffix = answerText.slice(span.end);+ const coordMatch = fullSuffix.match(/^(?:\s*(?:[,;,;和]|(?:\s+(?:and|or|以及|与|及)\s*))\s*[^,;,;\n\r|/]+?)+?(\s*(?:(?:as|in|into|to)\s+(?:the\s+)?(?:to|cc|bcc|blind\s+carbon\s+copy|carbon\s+copy)(?:\s+(?:field|role|recipient))?\b|[(\[【]\s*(?:to|cc|bcc)\s*[)\]】]|\s*[::]\s*(?:to|cc|bcc)\b|(?:作为|设为)?(?:收件人|主送|抄送|密送|暗送)))/i);+ if (coordMatch) {+ const intervening = fullSuffix.slice(0, coordMatch.index + coordMatch[0].length - coordMatch[1].length);+ const rolePart = coordMatch[1];+ if (!roleWordsRe.test(intervening) && suffixPatterns[role].test(rolePart)) {+ return true;+ }+ }++ // Grouped role prefix: e.g. To: Alice and Bob+ const fullPrefix = answerText.slice(0, span.start);+ const prefixCoordMatch = fullPrefix.match(/(?:(\b(?:to|cc|bcc)\s*[::]|(?:作为|设为)?(?:收件人|主送|抄送|密送|暗送)\s*[::]?)\s*[^,;,;\n\r|/]+(?:\s*(?:[,;,;和]|(?:\s+(?:and|or|以及|与|及)\s*))\s*[^,;,;\n\r|/]+)*\s*(?:[,;,;和]|(?:\s+(?:and|or|以及|与|及)\s*))\s*)$/i);+ if (prefixCoordMatch) {+ const roleLeader = prefixCoordMatch[1];+ const intervening = prefixCoordMatch[0].slice(roleLeader.length);+ if (!roleWordsRe.test(intervening) && prefixPatterns[role].test(roleLeader)) {+ return true;+ }+ }}}}diff --git a/test/run.js b/test/run.jsindex 68b21177b..77a7a3a24 100644--- a/test/run.js+++ b/test/run.js@@ -4866,6 +4866,65 @@ test('direct-message recipient guard uses structured intent and exact active ide'multi-recipient answer associating roles to different recipients must resolve each recipient to their authorized role',);+ // Grouped role authorization tests:+ assert.equal(+ helper.clarificationAuthorizesRecipientRole(null, 'Put Alice and Bob in BCC', 'Alice', 'bcc'),+ true,+ 'Alice in grouped answer Put Alice and Bob in BCC must be authorized as BCC',+ );+ assert.equal(+ helper.clarificationAuthorizesRecipientRole(null, 'Put Alice and Bob in BCC', 'Alice', 'to'),+ false,+ 'Alice in grouped answer Put Alice and Bob in BCC must not be authorized as To',+ );+ assert.equal(+ helper.clarificationAuthorizesRecipientRole(null, 'Put Alice and Bob in BCC', 'Bob', 'bcc'),+ true,+ 'Bob in grouped answer Put Alice and Bob in BCC must be authorized as BCC',+ );+ assert.equal(+ helper.clarificationAuthorizesRecipientRole(null, 'Put Alice and Bob in BCC', 'Bob', 'to'),+ false,+ 'Bob in grouped answer Put Alice and Bob in BCC must not be authorized as To',+ );+ assert.equal(+ helper.clarificationAuthorizesRecipientRole(null, 'To: Alice and Bob', 'Alice', 'to'),+ true,+ 'Alice in grouped prefix answer To: Alice and Bob must be authorized as To',+ );+ assert.equal(+ helper.clarificationAuthorizesRecipientRole(null, 'To: Alice and Bob', 'Bob', 'to'),+ true,+ 'Bob in grouped prefix answer To: Alice and Bob must be authorized as To',+ );+ assert.equal(+ helper.clarificationAuthorizesRecipientRole(null, 'To: Alice and Bob', 'Bob', 'bcc'),+ false,+ 'Bob in grouped prefix answer To: Alice and Bob must not be authorized as BCC',+ );+ assert.deepEqual(+ helper.resolveClarifiedRecipients(+ [+ { identity: '[email protected]', role: 'bcc', aliases: ['[email protected]', 'Alice'] },+ { identity: '[email protected]', role: 'bcc', aliases: ['[email protected]', 'Bob'] },+ ],+ {+ target_kind: 'named',+ recipients: [+ { identity: '[email protected]', role: 'to' },+ { identity: '[email protected]', role: 'to' },+ ],+ },+ null,+ 'Put Alice and Bob in BCC',+ ),+ [+ { identity: '[email protected]', role: 'bcc' },+ { identity: '[email protected]', role: 'bcc' },+ ],+ 'grouped role answer Put Alice and Bob in BCC must rebind both recipients to BCC',+ );+assert.equal(helper.messageTargetMatchesObservedIdentities({ target_kind: 'named', recipients: ['Alice', '[email protected]'] },['Alice'],