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(agent): pass resolved navigation links in commit gate
Emre Sokulluff998f69a082
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 612b54735..4800a71f8 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -1856,11 +1856,14 @@ export class Agent extends LoopDetector {// no evidence) cannot be proven to be a non-submit, so it must clear the// same binding gate as an observed submit. Non-submit-capable tools keep// the early exit, as do clicks the probe resolved to an editable field- // (focusing it cannot submit); the positively identified reversible- // dialog launcher is exempted below.+ // (focusing it cannot submit) or to a pure navigation link such as the+ // blob page's Edit control (navigating cannot submit or mutate fields);+ // the positively identified reversible dialog launcher is exempted below.const resolvedEditableTarget = (name === 'click' || name === 'click_ax' || name === 'iframe_click')&& detectedSubmit?.resolvedEditableTarget === true;- const inconclusiveSubmitCapable = !looksLikeSubmit && !resolvedEditableTarget+ const resolvedNavigationTarget = (name === 'click' || name === 'click_ax' || name === 'iframe_click')+ && detectedSubmit?.resolvedNavigationTarget === true;+ const inconclusiveSubmitCapable = !looksLikeSubmit && !resolvedEditableTarget && !resolvedNavigationTarget&& this._isFormValidationCandidate(name, args);if (!looksLikeSubmit && !inconclusiveSubmitCapable) return null;const detectedFields = [@@ -18684,6 +18687,21 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dresolvedEditableTarget: true,};}+ // Explicit negative: the probe resolved the click target to a pure+ // navigation link, proving activation only navigates. Propagated like+ // the editable flag so the gate can pass it without verified proofs.+ const resolvedNavigation = (Array.isArray(rawResults) ? rawResults : [])+ .find(item => item && item.isSubmit !== true && item.resolvedNavigationTarget === true);+ if (resolvedNavigation+ && (name === 'click' || name === 'click_ax' || name === 'iframe_click')) {+ return {+ isSubmit: false,+ host: normalizeHost(resolvedNavigation.host || resolvedNavigation.url || args?.urlFilter || currentUrl) || 'this site',+ tool: name,+ reason: String(resolvedNavigation.reason || 'click target is a navigation link').slice(0, 200),+ resolvedNavigationTarget: true,+ };+ }} catch {// Fall through to explicit-argument fallbacks below.}@@ -19106,6 +19124,26 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn false;}};+ // Explicit negative for the commit gate: activation on a pure navigation+ // control can neither submit a form nor mutate field values, so it needs+ // no verified proofs (the later commit click still does). Strictly+ // positive only: an anchor with a navigating href, free of activation+ // handlers. Anything with a handler, a submit classification, an+ // unresolvable target, or a script-executing href stays inconclusive+ // (fail-closed): javascript:/data:/vbscript: hrefs run code rather than+ // navigate. type=button stays gated per the submit-candidate posture.+ const isNavigationLinkTarget = (el) => {+ try {+ if (!el || el.nodeType !== 1) return false;+ if (el.hasAttribute?.('onclick') || el.hasAttribute?.('data-action')) return false;+ if (String(el.tagName || '').toLowerCase() !== 'a') return false;+ const href = String(el.getAttribute?.('href') || '').trim();+ if (!href || /^(?:javascript|data|vbscript)\s*:/i.test(href)) return false;+ return !isSubmitControl(el);+ } catch {+ return false;+ }+ };const formForSubmitControl = (el) => {const target = labelControlFor(el) || el;const candidate = target?.closest?.('button,input') || target;@@ -19284,6 +19322,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dresolvedEditableTarget: true,};}+ if (target+ && (toolName === 'click' || toolName === 'click_ax' || toolName === 'iframe_click')+ && isNavigationLinkTarget(target)) {+ return {+ isSubmit: false,+ host,+ url,+ tool: toolName,+ reason: 'click target resolves to a navigation link',+ resolvedNavigationTarget: true,+ };+ }} catch {}return null;};diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex fce8a6379..31cfd5a64 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -1570,11 +1570,14 @@ export class Agent extends LoopDetector {// no evidence) cannot be proven to be a non-submit, so it must clear the// same binding gate as an observed submit. Non-submit-capable tools keep// the early exit, as do clicks the probe resolved to an editable field- // (focusing it cannot submit); the positively identified reversible- // dialog launcher is exempted below.+ // (focusing it cannot submit) or to a pure navigation link such as the+ // blob page's Edit control (navigating cannot submit or mutate fields);+ // the positively identified reversible dialog launcher is exempted below.const resolvedEditableTarget = (name === 'click' || name === 'click_ax' || name === 'iframe_click')&& detectedSubmit?.resolvedEditableTarget === true;- const inconclusiveSubmitCapable = !looksLikeSubmit && !resolvedEditableTarget+ const resolvedNavigationTarget = (name === 'click' || name === 'click_ax' || name === 'iframe_click')+ && detectedSubmit?.resolvedNavigationTarget === true;+ const inconclusiveSubmitCapable = !looksLikeSubmit && !resolvedEditableTarget && !resolvedNavigationTarget&& this._isFormValidationCandidate(name, args);if (!looksLikeSubmit && !inconclusiveSubmitCapable) return null;const detectedFields = [@@ -16432,6 +16435,21 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dresolvedEditableTarget: true,};}+ // Explicit negative: the probe resolved the click target to a pure+ // navigation link, proving activation only navigates. Propagated like+ // the editable flag so the gate can pass it without verified proofs.+ const resolvedNavigation = (Array.isArray(rawResults) ? rawResults : [])+ .find(item => item && item.isSubmit !== true && item.resolvedNavigationTarget === true);+ if (resolvedNavigation+ && (name === 'click' || name === 'click_ax' || name === 'iframe_click')) {+ return {+ isSubmit: false,+ host: normalizeHost(resolvedNavigation.host || resolvedNavigation.url || args?.urlFilter || currentUrl) || 'this site',+ tool: name,+ reason: String(resolvedNavigation.reason || 'click target is a navigation link').slice(0, 200),+ resolvedNavigationTarget: true,+ };+ }} catch {// Fall through to explicit-argument fallbacks below.}@@ -16766,6 +16784,26 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn false;}};+ // Explicit negative for the commit gate: activation on a pure navigation+ // control can neither submit a form nor mutate field values, so it needs+ // no verified proofs (the later commit click still does). Strictly+ // positive only: an anchor with a navigating href, free of activation+ // handlers. Anything with a handler, a submit classification, an+ // unresolvable target, or a script-executing href stays inconclusive+ // (fail-closed): javascript:/data:/vbscript: hrefs run code rather than+ // navigate. type=button stays gated per the submit-candidate posture.+ const isNavigationLinkTarget = (el) => {+ try {+ if (!el || el.nodeType !== 1) return false;+ if (el.hasAttribute?.('onclick') || el.hasAttribute?.('data-action')) return false;+ if (String(el.tagName || '').toLowerCase() !== 'a') return false;+ const href = String(el.getAttribute?.('href') || '').trim();+ if (!href || /^(?:javascript|data|vbscript)\s*:/i.test(href)) return false;+ return !isSubmitControl(el);+ } catch {+ return false;+ }+ };const formForSubmitControl = (el) => {const target = labelControlFor(el) || el;const candidate = target?.closest?.('button,input') || target;@@ -16909,6 +16947,18 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dresolvedEditableTarget: true,};}+ if (target+ && (toolName === 'click' || toolName === 'click_ax' || toolName === 'iframe_click')+ && isNavigationLinkTarget(target)) {+ return {+ isSubmit: false,+ host,+ url,+ tool: toolName,+ reason: 'click target resolves to a navigation link',+ resolvedNavigationTarget: true,+ };+ }} catch {}return null;};diff --git a/test/run.js b/test/run.jsindex 6811c6aa2..b108533b7 100644--- a/test/run.js+++ b/test/run.js@@ -76009,6 +76009,58 @@ test('GitHub edit-file workflow fails closed when submit detection is inconclusi}});+test('GitHub edit-file workflow passes resolved navigation links', async () => {+ for (const rel of [+ 'src/chrome/src/agent/agent.js',+ 'src/firefox/src/agent/agent.js',+ ]) {+ const source = fs.readFileSync(path.join(ROOT, rel), 'utf8');+ assert.match(source, /const isNavigationLinkTarget = \(el\) => \{/,+ `${rel}: navigation-link probe is missing`);+ assert.match(source, /resolvedNavigationTarget: true/,+ `${rel}: navigation resolution is not propagated`);+ assert.match(source, /javascript\|data\|vbscript/,+ `${rel}: script-executing hrefs are not excluded from navigation`);+ }+ const editUrl = 'https://github.com/Example/Repo/edit/main/docs/plan.md';+ for (const [label, AgentClass, tabId] of [+ ['chrome', AgentCh, 9512],+ ['firefox', AgentFx, 9513],+ ]) {+ const agent = new AgentClass({});+ agent._planExecutionGuards.set(tabId, {+ enabled: true,+ siteWorkflow: { adapterName: 'github', job: { id: 'edit-file-and-commit' } },+ workflowMetadataRequirements: [],+ workflowMetadataRequirementsResolved: true,+ });+ agent._currentUrl = async () => editUrl;+ agent._workflowSubmitBindingForAttempt = () => ({ metadataRequirementsIncomplete: true });+ // The blob page's Edit control resolves to a pure navigation link: it+ // cannot submit or mutate fields, so it passes without a binding (which+ // cannot exist before the /edit route is even reached).+ assert.equal(await agent._workflowPreSubmitDispatchBlock(+ tabId, 'click_ax', { ref_id: 'ref_edit_link' },+ { isSubmit: false, resolvedNavigationTarget: true },+ ), null, `${label}: resolved navigation link stayed blocked`);+ // Unresolved clicks stay fail-closed.+ assert.equal((await agent._workflowPreSubmitDispatchBlock(+ tabId, 'click_ax', { ref_id: 'ref_edit_link' }, null,+ ))?.noDispatch, true, `${label}: unresolved click escaped the commit guard`);+ // A submit-looking label still takes the binding path even with the+ // flag: positive navigation evidence only lifts the inconclusive gate.+ assert.equal((await agent._workflowPreSubmitDispatchBlock(+ tabId, 'click', { text: 'Commit changes' },+ { isSubmit: false, resolvedNavigationTarget: true },+ ))?.noDispatch, true, `${label}: label-classified submit bypassed the binding`);+ // The flag is click-scoped: Enter stays blocked.+ assert.equal((await agent._workflowPreSubmitDispatchBlock(+ tabId, 'press_keys', { key: 'Enter' },+ { isSubmit: false, resolvedNavigationTarget: true },+ ))?.noDispatch, true, `${label}: flagged Enter escaped the commit guard`);+ }+});+test('GitHub edit-file workflow blocks compound submit actions on existing bindings', async () => {const editUrl = 'https://github.com/Example/Repo/edit/main/docs/plan.md';for (const [label, AgentClass, tabId] of [