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
Harden message metadata and X history proofs
Emre Sokullua0e871f6a73c
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex d8255ef42..9c3256868 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -28497,7 +28497,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst details = this._normalizeWorkflowMetadataRequirementsDetails(obj?.workflowFields ?? obj?.workflow_fields,);- const extractedBody = this._extractWorkflowTaskBody(taskText, approvedPlanText, siteWorkflow?.adapterName);+ // The concise "Send Alex: ..." recovery is deliberately limited to+ // X DMs. Other messaging adapters have structured fields (for+ // example, Gmail subject/body), which a generic Send parser must not+ // replace or invent.+ const recoverTwitterMessageBody = siteWorkflow?.adapterName === 'twitter'+ && siteWorkflow?.job?.template === 'message'+ && siteWorkflow?.job?.id === 'send-message';+ const extractedBody = recoverTwitterMessageBody+ ? this._extractWorkflowTaskBody(taskText, approvedPlanText, 'twitter')+ : '';if (extractedBody) {const bodyReq = details.items.find(r => r.field === 'body');if (bodyReq) {@@ -28541,7 +28550,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d&& (siteWorkflow?.job?.template !== 'publish' || !SOCIAL_PLATFORMS.includes(siteWorkflow?.adapterName))) {const guard = this._planExecutionGuards.get(tabId);if (guard && guard.workflowMetadataRequirementsResolved !== true) {- const extractedBody = this._extractWorkflowTaskBody(taskText, approvedPlanText, siteWorkflow?.adapterName);+ const recoverTwitterMessageBody = siteWorkflow?.adapterName === 'twitter'+ && siteWorkflow?.job?.template === 'message'+ && siteWorkflow?.job?.id === 'send-message';+ const extractedBody = recoverTwitterMessageBody+ ? this._extractWorkflowTaskBody(taskText, approvedPlanText, 'twitter')+ : '';if (extractedBody) {guard.workflowMetadataRequirements = [{field: 'body',diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex e269fe378..238b73b33 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -4421,11 +4421,18 @@function _settledEmptyTwitterLog(log) {if (!log?.isConnected) return false;let loading = false;+ let historyComplete = false;try {- loading = log.getAttribute('aria-busy') === 'true'+ const ariaBusy = log.getAttribute('aria-busy');+ loading = ariaBusy === 'true'|| !!log.querySelector('[aria-busy="true"],[role="progressbar"]');+ // An empty log alone is ambiguous: history may still mount after the+ // submit. Require X to expose either its finished busy state or its+ // app-owned empty-state marker before pinning a first-message baseline.+ historyComplete = ariaBusy === 'false'+ || !!log.querySelector('[data-testid="dm-empty-state"],[data-testid="empty_state"],[data-testid="empty-state"]');} catch {}- if (loading) {+ if (loading || !historyComplete) {_twitterEmptyLogObservations.delete(log);return false;}@@ -4436,8 +4443,8 @@: { firstSeenAt: now, count: 1 };_twitterEmptyLogObservations.set(log, observation);// A first-message conversation has no historic tail to pin. Require the- // same empty log to survive two non-loading reads before treating that- // exceptional baseline as settled.+ // same positively-complete empty log to survive two reads before treating+ // that exceptional baseline as settled.return observation.count >= 2 && now - observation.firstSeenAt >= 300;}diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex ed75da39d..9d488d39f 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -26111,7 +26111,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst details = this._normalizeWorkflowMetadataRequirementsDetails(obj?.workflowFields ?? obj?.workflow_fields,);- const extractedBody = this._extractWorkflowTaskBody(taskText, approvedPlanText, siteWorkflow?.adapterName);+ // The concise "Send Alex: ..." recovery is deliberately limited to+ // X DMs. Other messaging adapters have structured fields (for+ // example, Gmail subject/body), which a generic Send parser must not+ // replace or invent.+ const recoverTwitterMessageBody = siteWorkflow?.adapterName === 'twitter'+ && siteWorkflow?.job?.template === 'message'+ && siteWorkflow?.job?.id === 'send-message';+ const extractedBody = recoverTwitterMessageBody+ ? this._extractWorkflowTaskBody(taskText, approvedPlanText, 'twitter')+ : '';if (extractedBody) {const bodyReq = details.items.find(r => r.field === 'body');if (bodyReq) {@@ -26155,7 +26164,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d&& (siteWorkflow?.job?.template !== 'publish' || !SOCIAL_PLATFORMS.includes(siteWorkflow?.adapterName))) {const guard = this._planExecutionGuards.get(tabId);if (guard && guard.workflowMetadataRequirementsResolved !== true) {- const extractedBody = this._extractWorkflowTaskBody(taskText, approvedPlanText, siteWorkflow?.adapterName);+ const recoverTwitterMessageBody = siteWorkflow?.adapterName === 'twitter'+ && siteWorkflow?.job?.template === 'message'+ && siteWorkflow?.job?.id === 'send-message';+ const extractedBody = recoverTwitterMessageBody+ ? this._extractWorkflowTaskBody(taskText, approvedPlanText, 'twitter')+ : '';if (extractedBody) {guard.workflowMetadataRequirements = [{field: 'body',diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.jsindex f1f627672..a7243b34b 100644--- a/src/firefox/src/content/content.js+++ b/src/firefox/src/content/content.js@@ -3733,11 +3733,18 @@function _settledEmptyTwitterLog(log) {if (!log?.isConnected) return false;let loading = false;+ let historyComplete = false;try {- loading = log.getAttribute('aria-busy') === 'true'+ const ariaBusy = log.getAttribute('aria-busy');+ loading = ariaBusy === 'true'|| !!log.querySelector('[aria-busy="true"],[role="progressbar"]');+ // An empty log alone is ambiguous: history may still mount after the+ // submit. Require X to expose either its finished busy state or its+ // app-owned empty-state marker before pinning a first-message baseline.+ historyComplete = ariaBusy === 'false'+ || !!log.querySelector('[data-testid="dm-empty-state"],[data-testid="empty_state"],[data-testid="empty-state"]');} catch {}- if (loading) {+ if (loading || !historyComplete) {_twitterEmptyLogObservations.delete(log);return false;}@@ -3748,8 +3755,8 @@: { firstSeenAt: now, count: 1 };_twitterEmptyLogObservations.set(log, observation);// A first-message conversation has no historic tail to pin. Require the- // same empty log to survive two non-loading reads before treating that- // exceptional baseline as settled.+ // same positively-complete empty log to survive two reads before treating+ // that exceptional baseline as settled.return observation.count >= 2 && now - observation.firstSeenAt >= 300;}diff --git a/test/run.js b/test/run.jsindex a887e5361..0dbeda523 100644--- a/test/run.js+++ b/test/run.js@@ -7890,6 +7890,55 @@ test('message recipient dispatch binding detects composer and active-thread race}});+test('empty X history baselines require a positive completion signal', () => {+ for (const [label, rel] of [+ ['chrome', 'src/chrome/src/content/content.js'],+ ['firefox', 'src/firefox/src/content/content.js'],+ ]) {+ const source = fs.readFileSync(path.join(ROOT, rel), 'utf8');+ const start = source.indexOf('const _messageRecipientDispatchBindings = new Map();');+ const end = source.indexOf(label === 'chrome'+ ? '\n\n // Above this length'+ : '\n\n function _releaseDispatchBinding', start);+ assert.ok(start >= 0 && end > start, `${label}: empty-X helper should remain independently testable`);+ let now = 0;+ const { settledEmptyTwitterLog } = vm.runInNewContext(`(() => {+ ${source.slice(start, end)}+ return { settledEmptyTwitterLog: _settledEmptyTwitterLog };+ })()`, {+ Date: { now: () => now },+ });+ const log = ({ ariaBusy = null, emptyState = false, loading = false } = {}) => ({+ isConnected: true,+ getAttribute: name => name === 'aria-busy' ? ariaBusy : null,+ querySelector: selector => {+ if (selector === '[aria-busy="true"],[role="progressbar"]') return loading ? {} : null;+ return emptyState ? {} : null;+ },+ });+ const ambiguousEmptyLog = log();+ assert.equal(settledEmptyTwitterLog(ambiguousEmptyLog), false,+ `${label}: a bare empty X log was accepted before history completion`);+ now += 300;+ assert.equal(settledEmptyTwitterLog(ambiguousEmptyLog), false,+ `${label}: a bare empty X log became a first-message baseline`);++ const completedEmptyLog = log({ ariaBusy: 'false' });+ assert.equal(settledEmptyTwitterLog(completedEmptyLog), false,+ `${label}: the first completed empty-X observation was accepted`);+ now += 300;+ assert.equal(settledEmptyTwitterLog(completedEmptyLog), true,+ `${label}: a stable aria-busy=false X log did not become a baseline`);++ const markedEmptyLog = log({ emptyState: true });+ assert.equal(settledEmptyTwitterLog(markedEmptyLog), false,+ `${label}: the first explicit X empty-state observation was accepted`);+ now += 300;+ assert.equal(settledEmptyTwitterLog(markedEmptyLog), true,+ `${label}: a stable X empty-state marker did not become a baseline`);+ }+});+test('matches BOSS Zhipin job surfaces with safe search and communication guidance', () => {const trustedUrls = ['https://zhipin.com/',@@ -93999,6 +94048,48 @@ test('publication workflows classify and bind requested payload fields', async (assert.deepEqual(xGuard.workflowMetadataRequirements, [{ field: 'body', value: 'Hello there' },], `${AgentClass.name}: an explicit X DM body was not bound after an empty classifier response`);++ const gmailTabId = 8997 + index;+ const gmailUrl = 'https://mail.google.com/mail/u/0/#inbox';+ const gmailTask = 'Send an email to Alice with subject: Message: Hello and body: How are you?';+ const gmailWorkflow = agent._resolvePlannerSiteWorkflow(gmailUrl, {+ request_kind: 'execute',+ site_job: 'send-email',+ requires_submission: true,+ messaging: { target_kind: 'named', recipients: ['Alice'] },+ });+ assert.equal(gmailWorkflow?.job?.id, 'send-email');+ assert.equal(agent._extractWorkflowTaskBody(gmailTask, '', 'gmail'), 'Hello and body: How are you?',+ `${AgentClass.name}: the regression fixture no longer exercises Gmail's generic Send parser`);+ agent.conversations.set(gmailTabId, [+ { role: 'system', content: 'system' },+ { role: 'user', content: gmailTask },+ ]);+ const gmailGuard = agent._startPlanExecutionGuard(gmailTabId, 'act', {+ requestKind: 'execute',+ requiresStateChange: true,+ requiresSubmission: true,+ messaging: { target_kind: 'named', recipients: ['Alice'] },+ siteWorkflow: gmailWorkflow,+ });+ agent._chatWithCostAllowance = async () => ({ content: JSON.stringify({+ mode: 'inactive', allowedActions: [], forbiddenActions: [], targets: [],+ workflowFields: [+ { field: 'subject', value: 'Message: Hello' },+ { field: 'body', value: 'How are you?' },+ ],+ confidence: 0.99, pageScopePolicy: 'page',+ }) });+ await agent._ensureProgressSessionForCurrentTask(gmailTabId, {+ provider: { chat: async () => ({ content: '{}' }) },+ progressLedgerPolicy: 'disabled',+ taskText: gmailTask,+ pageScope: gmailUrl,+ });+ assert.deepEqual(gmailGuard.workflowMetadataRequirements, [+ { field: 'subject', value: 'Message: Hello' },+ { field: 'body', value: 'How are you?' },+ ], `${AgentClass.name}: X's body recovery rewrote Gmail's structured subject/body fields`);const xTerminal = (body) => {const workflowBinding = agent._workflowSubmitBindingForAttempt(xTabId, xUrl, {messageRecipientGuardRequired: true,