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): byte-exact Git paths from ingestion
Emre Sokullu453a6cacb0cc
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 4800a71f8..db6a03a60 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -2177,7 +2177,22 @@ export class Agent extends LoopDetector {discarded += 1;continue;}- requirements.set(field, { field, value: this._workflowMetadataValue(value.value) });+ // Keep the byte-exact request text alongside the normalized value, but+ // only when normalization changed something: Git paths preserve+ // distinctions NFKC/trim fold (fullwidth A vs A, significant+ // whitespace), and scope resolution must compare those. Absent means+ // verbatim equals normalized, so existing shapes are untouched.+ // Re-ingestion keeps an existing rawValue instead of re-deriving it+ // from the already-normalized value.+ const normalizedValue = this._workflowMetadataValue(value.value);+ const verbatimValue = typeof value.rawValue === 'string'+ ? value.rawValue+ : String(value.value ?? '');+ requirements.set(field, {+ field,+ value: normalizedValue,+ ...(verbatimValue !== normalizedValue ? { rawValue: verbatimValue } : {}),+ });}return { items: [...requirements.values()], incomplete: discarded > 0 };}@@ -2303,7 +2318,12 @@ export class Agent extends LoopDetector {try { return decodeURIComponent(segment); } catch { return segment; }});const byField = new Map((Array.isArray(requirements) ? requirements : [])- .map(item => [item?.field, this._workflowMetadataValue(item?.value)]));+ // Byte-exact scope values: prefer the verbatim request text kept at+ // ingestion (rawValue). NFKC/trim would fold distinctions Git+ // preserves (fullwidth A vs A, significant whitespace), turning a+ // valid request into a null scope. Only the documented slash+ // tolerance applies below.+ .map(item => [item?.field, typeof item?.rawValue === 'string' ? item.rawValue : item?.value]));const requestedPath = String(byField.get('path') || '').replace(/^\/+/, '');const requestedBranch = String(byField.get('branch') || '').replace(/^\/+|\/+$/g, '');let branch = requestedBranch;@@ -2403,7 +2423,10 @@ export class Agent extends LoopDetector {: [];const requestedScopeValue = (field) => {const entry = requirements.find(requirement => requirement?.field === field);- return String(this._workflowMetadataValue(entry?.value) || '').replace(/^\/+/, '');+ // Byte-exact like the scope parser: emptiness is tested on the+ // verbatim request text, not the normalized value.+ const raw = typeof entry?.rawValue === 'string' ? entry.rawValue : entry?.value;+ return String(raw || '').replace(/^\/+/, '');};const scopeAmbiguous = !requestedScopeValue('path') && !requestedScopeValue('branch');const segments = `${expected.branch}/${expected.path}`.split('/');diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 31cfd5a64..31ebe2ff1 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -1891,7 +1891,22 @@ export class Agent extends LoopDetector {discarded += 1;continue;}- requirements.set(field, { field, value: this._workflowMetadataValue(value.value) });+ // Keep the byte-exact request text alongside the normalized value, but+ // only when normalization changed something: Git paths preserve+ // distinctions NFKC/trim fold (fullwidth A vs A, significant+ // whitespace), and scope resolution must compare those. Absent means+ // verbatim equals normalized, so existing shapes are untouched.+ // Re-ingestion keeps an existing rawValue instead of re-deriving it+ // from the already-normalized value.+ const normalizedValue = this._workflowMetadataValue(value.value);+ const verbatimValue = typeof value.rawValue === 'string'+ ? value.rawValue+ : String(value.value ?? '');+ requirements.set(field, {+ field,+ value: normalizedValue,+ ...(verbatimValue !== normalizedValue ? { rawValue: verbatimValue } : {}),+ });}return { items: [...requirements.values()], incomplete: discarded > 0 };}@@ -2017,7 +2032,12 @@ export class Agent extends LoopDetector {try { return decodeURIComponent(segment); } catch { return segment; }});const byField = new Map((Array.isArray(requirements) ? requirements : [])- .map(item => [item?.field, this._workflowMetadataValue(item?.value)]));+ // Byte-exact scope values: prefer the verbatim request text kept at+ // ingestion (rawValue). NFKC/trim would fold distinctions Git+ // preserves (fullwidth A vs A, significant whitespace), turning a+ // valid request into a null scope. Only the documented slash+ // tolerance applies below.+ .map(item => [item?.field, typeof item?.rawValue === 'string' ? item.rawValue : item?.value]));const requestedPath = String(byField.get('path') || '').replace(/^\/+/, '');const requestedBranch = String(byField.get('branch') || '').replace(/^\/+|\/+$/g, '');let branch = requestedBranch;@@ -2117,7 +2137,10 @@ export class Agent extends LoopDetector {: [];const requestedScopeValue = (field) => {const entry = requirements.find(requirement => requirement?.field === field);- return String(this._workflowMetadataValue(entry?.value) || '').replace(/^\/+/, '');+ // Byte-exact like the scope parser: emptiness is tested on the+ // verbatim request text, not the normalized value.+ const raw = typeof entry?.rawValue === 'string' ? entry.rawValue : entry?.value;+ return String(raw || '').replace(/^\/+/, '');};const scopeAmbiguous = !requestedScopeValue('path') && !requestedScopeValue('branch');const segments = `${expected.branch}/${expected.path}`.split('/');diff --git a/test/run.js b/test/run.jsindex b108533b7..0a1dc5da6 100644--- a/test/run.js+++ b/test/run.js@@ -75746,6 +75746,50 @@ test('commit page blob links feed verification scope evidence', () => {}});+test('edit-file scope keeps Git paths byte-exact', () => {+ for (const [label, AgentClass] of [['chrome', AgentCh], ['firefox', AgentFx]]) {+ const agent = new AgentClass({});+ // Ingestion keeps the verbatim request text next to the normalized value.+ const details = agent._normalizeWorkflowMetadataRequirementsDetails([+ { field: 'path', value: 'A.txt' },+ ]);+ assert.equal(details.items[0]?.value, 'A.txt', `${label}: normalized value changed shape`);+ assert.equal(details.items[0]?.rawValue, 'A.txt', `${label}: verbatim path was not preserved`);+ // Re-ingestion keeps the original verbatim text instead of re-deriving+ // it from the already-normalized value.+ const again = agent._normalizeWorkflowMetadataRequirementsDetails(details.items);+ assert.equal(again.items[0]?.rawValue, 'A.txt', `${label}: re-ingestion lost the verbatim path`);+ // Fullwidth A (U+FF21) survives percent-decoding on the route and must+ // match byte-exactly: NFKC would fold it to A and null the scope.+ assert.deepEqual(agent._workflowGithubEditFileScope(+ 'https://github.com/Example/Repo/edit/main/%EF%BC%A1.txt',+ [{ field: 'path', value: 'A.txt', rawValue: 'A.txt' }],+ ), {+ repository: 'example/repo',+ branch: 'main',+ path: 'A.txt',+ }, `${label}: NFKC-sensitive path did not resolve byte-exactly`);+ // Significant trailing whitespace likewise survives.+ assert.deepEqual(agent._workflowGithubEditFileScope(+ 'https://github.com/Example/Repo/edit/main/docs/plan.md%20',+ [{ field: 'path', value: 'docs/plan.md', rawValue: 'docs/plan.md ' }],+ ), {+ repository: 'example/repo',+ branch: 'main',+ path: 'docs/plan.md ',+ }, `${label}: trailing-space path did not resolve byte-exactly`);+ // The explicitly supported leading-slash tolerance still applies.+ assert.deepEqual(agent._workflowGithubEditFileScope(+ 'https://github.com/Example/Repo/edit/main/docs/plan.md',+ [{ field: 'path', value: '/docs/plan.md', rawValue: '/docs/plan.md' }],+ ), {+ repository: 'example/repo',+ branch: 'main',+ path: 'docs/plan.md',+ }, `${label}: leading-slash tolerance regressed`);+ }+});+test('GitHub edit-file workflow verifies the exact committed raw blob', async () => {const originalFetch = globalThis.fetch;const body = '# Corrected document\n\nOne complete copy.\n';