Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

fix: reject bare MiniCPM calls when response holds prose; document Compass-only WebGPU flow

Emre Sokullu8bb1945fa8ab
diff --git a/docs/apocalypse-mode.md b/docs/apocalypse-mode.md
index 5de638453..e2170b5f1 100644
--- a/docs/apocalypse-mode.md
+++ b/docs/apocalypse-mode.md
@@ -18,14 +18,13 @@ fallback** control in **Settings β†’ Multimodal β†’ Vision** checks WebGPU suppo
records explicit consent, and starts caching the approximately 810 MB model
from Hugging Face. The download continues in the background, but screenshot
operations report its status and never wait for it. Wikipedia archives still
-require their own confirmation. The local **text** model defaults to LFM2.5
-2.6B (about 1.55 GB), and that download starts automatically when Apocalypse
-Mode is enabled. The picker also offers opt-in LFM2.5 1.2B Instruct and
-Thinking presets (about 760 MB each), LFM2.5-VL 1.6B and 3B multimodal presets
-(about 2.3 GB and 4.0 GB), Nanbeige4.2-3B (about 3.1 GB), and Bonsai 27B
-(about 3.8 GB, 16 GB+ RAM/VRAM recommended). Only the default is
-auto-downloaded. The two VL choices support
-image inputs directly when selected as the normal WebGPU provider. Disabling
+require their own confirmation. The local **text** model is Compass Tiny v2.1
+(`webbrain-one/webbrain-compass-tiny-v2.1`, about 1.87 GB, 32k context
+window), and it is the only text preset the picker offers. That download
+starts automatically when Apocalypse Mode is enabled. Once downloaded,
+Compass works without Apocalypse Mode enabled: it is selectable as a chat
+provider under Settings β†’ Providers and through the standalone chat control.
+Disabling
local vision preserves its cache and any configured remote vision provider.
Archive language is selected independently from WebBrain's interface language.
diff --git a/src/chrome/src/agent/tool-call-parser.js b/src/chrome/src/agent/tool-call-parser.js
index 4b41149d2..42e687c4c 100644
--- a/src/chrome/src/agent/tool-call-parser.js
+++ b/src/chrome/src/agent/tool-call-parser.js
@@ -397,19 +397,25 @@ export function parseToolCallsFromText(text, allowedNames) {
/<functioncall>\s*([\s\S]*?)\s*<\/functioncall>/gi,
];
+ const wrapperSpans = [];
for (const re of patterns) {
let match;
while ((match = re.exec(text)) !== null) {
+ const spanStart = match.index;
+ const spanEnd = match.index + match[0].length;
+ const pushedBefore = results.length;
const inner = match[1].trim();
const wrappedArray = parseWholeResponseJsonArray(inner, allowedNames);
if (wrappedArray !== null) {
results.push(...wrappedArray);
+ wrapperSpans.push({ start: spanStart, end: spanEnd });
continue;
}
try {
const obj = JSON.parse(inner);
if (obj && obj.name && allowedNames.has(obj.name)) {
results.push(obj);
+ wrapperSpans.push({ start: spanStart, end: spanEnd });
continue;
}
} catch { /* not JSON β€” try call:name{} format below */ }
@@ -419,6 +425,7 @@ export function parseToolCallsFromText(text, allowedNames) {
const bailingCall = parseBailingToolCall(inner);
if (bailingCall) {
results.push(bailingCall);
+ wrapperSpans.push({ start: spanStart, end: spanEnd });
continue;
}
@@ -434,6 +441,7 @@ export function parseToolCallsFromText(text, allowedNames) {
results.push({ name: toolName, arguments: args });
} catch { /* malformed arguments must never dispatch */ }
}
+ if (results.length > pushedBefore) wrapperSpans.push({ start: spanStart, end: spanEnd });
}
}
@@ -441,6 +449,7 @@ export function parseToolCallsFromText(text, allowedNames) {
// <tool_call><function=click_ax><parameter=ref_id>ref_6</parameter>...
const xmlToolRe = /<tool_call>\s*<function(?:\s*=\s*["']?([A-Za-z_]\w*)["']?|\s+name\s*=\s*["']?([A-Za-z_]\w*)["']?)\s*>\s*([\s\S]*?)\s*<\/function>\s*<\/tool_call>/gi;
const xmlToolSpans = [];
+ const xmlPushedSpans = [];
let xmlMatch;
while ((xmlMatch = xmlToolRe.exec(text)) !== null) {
xmlToolSpans.push({ start: xmlMatch.index, end: xmlMatch.index + xmlMatch[0].length });
@@ -455,21 +464,21 @@ export function parseToolCallsFromText(text, allowedNames) {
if (!key) continue;
args[key] = parseXmlParamValue(paramMatch[3]);
}
+ xmlPushedSpans.push({ start: xmlMatch.index, end: xmlMatch.index + xmlMatch[0].length });
results.push({ name: toolName, arguments: args });
}
// MiniCPM5-2B native tool format (no outer <tool_call> wrapper):
// <function name="click"><param name="ref_id">ref_6</param>...</function>
const minicpmFunctionRe = /<function(?:\s+name\s*=\s*["']([A-Za-z_]\w*)["']|\s*=\s*["']?([A-Za-z_]\w*)["']?)\s*>\s*([\s\S]*?)\s*<\/function>/gi;
+ const minicpmCandidates = [];
let minicpmMatch;
while ((minicpmMatch = minicpmFunctionRe.exec(text)) !== null) {
// Skip functions already consumed inside a <tool_call> wrapper above.
if (xmlToolSpans.some(span => minicpmMatch.index >= span.start && minicpmMatch.index < span.end)) continue;
- // A bare call replaces the model's prose outright, so only accept it on
- // the same standalone-line boundary the JSON fallback requires. This
- // keeps quoted/explanatory markup such as `Do not call <function ...>`
- // from dispatching while still allowing genuine calls emitted on their
- // own lines.
+ // A bare call replaces the model's prose outright, so it must stand alone
+ // on its own line like the JSON fallback requires. Quoted or inline
+ // markup such as `Do not call <function ...>` never dispatches.
const matchEnd = minicpmMatch.index + minicpmMatch[0].length - 1;
if (!standsAloneOnLine(text, minicpmMatch.index, matchEnd)) continue;
const toolName = minicpmMatch[1] || minicpmMatch[2];
@@ -483,7 +492,33 @@ export function parseToolCallsFromText(text, allowedNames) {
if (!key) continue;
args[key] = parseXmlParamValue(paramMatch[3]);
}
- results.push({ name: toolName, arguments: args });
+ minicpmCandidates.push({
+ start: minicpmMatch.index,
+ end: minicpmMatch.index + minicpmMatch[0].length,
+ call: { name: toolName, arguments: args },
+ });
+ }
+ // Dispatch bare calls only when the response holds nothing but call
+ // elements: explanatory prose on any other line (e.g. `Do not execute
+ // this:` above the call) rejects them, since a dispatch would discard that
+ // prose. Only successfully parsed wrapper calls count as call elements, so
+ // a disallowed or malformed call-shaped block still blocks bare dispatch.
+ if (minicpmCandidates.length > 0) {
+ const callSpans = [
+ ...wrapperSpans,
+ ...xmlPushedSpans,
+ ...minicpmCandidates.map(({ start, end }) => ({ start, end })),
+ ].sort((a, b) => a.start - b.start);
+ let remainder = '';
+ let cursor = 0;
+ for (const span of callSpans) {
+ if (span.start > cursor) remainder += text.slice(cursor, span.start);
+ cursor = Math.max(cursor, span.end);
+ }
+ remainder += text.slice(cursor);
+ if (remainder.trim() === '') {
+ for (const candidate of minicpmCandidates) results.push(candidate.call);
+ }
}
if (results.length === 0) {
diff --git a/src/firefox/src/agent/tool-call-parser.js b/src/firefox/src/agent/tool-call-parser.js
index 4b41149d2..42e687c4c 100644
--- a/src/firefox/src/agent/tool-call-parser.js
+++ b/src/firefox/src/agent/tool-call-parser.js
@@ -397,19 +397,25 @@ export function parseToolCallsFromText(text, allowedNames) {
/<functioncall>\s*([\s\S]*?)\s*<\/functioncall>/gi,
];
+ const wrapperSpans = [];
for (const re of patterns) {
let match;
while ((match = re.exec(text)) !== null) {
+ const spanStart = match.index;
+ const spanEnd = match.index + match[0].length;
+ const pushedBefore = results.length;
const inner = match[1].trim();
const wrappedArray = parseWholeResponseJsonArray(inner, allowedNames);
if (wrappedArray !== null) {
results.push(...wrappedArray);
+ wrapperSpans.push({ start: spanStart, end: spanEnd });
continue;
}
try {
const obj = JSON.parse(inner);
if (obj && obj.name && allowedNames.has(obj.name)) {
results.push(obj);
+ wrapperSpans.push({ start: spanStart, end: spanEnd });
continue;
}
} catch { /* not JSON β€” try call:name{} format below */ }
@@ -419,6 +425,7 @@ export function parseToolCallsFromText(text, allowedNames) {
const bailingCall = parseBailingToolCall(inner);
if (bailingCall) {
results.push(bailingCall);
+ wrapperSpans.push({ start: spanStart, end: spanEnd });
continue;
}
@@ -434,6 +441,7 @@ export function parseToolCallsFromText(text, allowedNames) {
results.push({ name: toolName, arguments: args });
} catch { /* malformed arguments must never dispatch */ }
}
+ if (results.length > pushedBefore) wrapperSpans.push({ start: spanStart, end: spanEnd });
}
}
@@ -441,6 +449,7 @@ export function parseToolCallsFromText(text, allowedNames) {
// <tool_call><function=click_ax><parameter=ref_id>ref_6</parameter>...
const xmlToolRe = /<tool_call>\s*<function(?:\s*=\s*["']?([A-Za-z_]\w*)["']?|\s+name\s*=\s*["']?([A-Za-z_]\w*)["']?)\s*>\s*([\s\S]*?)\s*<\/function>\s*<\/tool_call>/gi;
const xmlToolSpans = [];
+ const xmlPushedSpans = [];
let xmlMatch;
while ((xmlMatch = xmlToolRe.exec(text)) !== null) {
xmlToolSpans.push({ start: xmlMatch.index, end: xmlMatch.index + xmlMatch[0].length });
@@ -455,21 +464,21 @@ export function parseToolCallsFromText(text, allowedNames) {
if (!key) continue;
args[key] = parseXmlParamValue(paramMatch[3]);
}
+ xmlPushedSpans.push({ start: xmlMatch.index, end: xmlMatch.index + xmlMatch[0].length });
results.push({ name: toolName, arguments: args });
}
// MiniCPM5-2B native tool format (no outer <tool_call> wrapper):
// <function name="click"><param name="ref_id">ref_6</param>...</function>
const minicpmFunctionRe = /<function(?:\s+name\s*=\s*["']([A-Za-z_]\w*)["']|\s*=\s*["']?([A-Za-z_]\w*)["']?)\s*>\s*([\s\S]*?)\s*<\/function>/gi;
+ const minicpmCandidates = [];
let minicpmMatch;
while ((minicpmMatch = minicpmFunctionRe.exec(text)) !== null) {
// Skip functions already consumed inside a <tool_call> wrapper above.
if (xmlToolSpans.some(span => minicpmMatch.index >= span.start && minicpmMatch.index < span.end)) continue;
- // A bare call replaces the model's prose outright, so only accept it on
- // the same standalone-line boundary the JSON fallback requires. This
- // keeps quoted/explanatory markup such as `Do not call <function ...>`
- // from dispatching while still allowing genuine calls emitted on their
- // own lines.
+ // A bare call replaces the model's prose outright, so it must stand alone
+ // on its own line like the JSON fallback requires. Quoted or inline
+ // markup such as `Do not call <function ...>` never dispatches.
const matchEnd = minicpmMatch.index + minicpmMatch[0].length - 1;
if (!standsAloneOnLine(text, minicpmMatch.index, matchEnd)) continue;
const toolName = minicpmMatch[1] || minicpmMatch[2];
@@ -483,7 +492,33 @@ export function parseToolCallsFromText(text, allowedNames) {
if (!key) continue;
args[key] = parseXmlParamValue(paramMatch[3]);
}
- results.push({ name: toolName, arguments: args });
+ minicpmCandidates.push({
+ start: minicpmMatch.index,
+ end: minicpmMatch.index + minicpmMatch[0].length,
+ call: { name: toolName, arguments: args },
+ });
+ }
+ // Dispatch bare calls only when the response holds nothing but call
+ // elements: explanatory prose on any other line (e.g. `Do not execute
+ // this:` above the call) rejects them, since a dispatch would discard that
+ // prose. Only successfully parsed wrapper calls count as call elements, so
+ // a disallowed or malformed call-shaped block still blocks bare dispatch.
+ if (minicpmCandidates.length > 0) {
+ const callSpans = [
+ ...wrapperSpans,
+ ...xmlPushedSpans,
+ ...minicpmCandidates.map(({ start, end }) => ({ start, end })),
+ ].sort((a, b) => a.start - b.start);
+ let remainder = '';
+ let cursor = 0;
+ for (const span of callSpans) {
+ if (span.start > cursor) remainder += text.slice(cursor, span.start);
+ cursor = Math.max(cursor, span.end);
+ }
+ remainder += text.slice(cursor);
+ if (remainder.trim() === '') {
+ for (const candidate of minicpmCandidates) results.push(candidate.call);
+ }
}
if (results.length === 0) {
diff --git a/test/run.js b/test/run.js
index 3dd313dd6..f7abdfdcb 100644
--- a/test/run.js
+++ b/test/run.js
@@ -100789,6 +100789,8 @@ test('text tool-call parser is production code with format and allowlist coverag
['array on a labeled response line', 'Options:\n[{"name":"click","arguments":{"text":"Yes"}}]'],
['bare function inline warning', 'Do not call <function name="click_ax"><param name="ref_id">ref_7</param></function> here.'],
['bare function on a labeled line', 'Option A: <function name="click_ax"><param name="ref_id">ref_7</param></function>'],
+ ['bare function with prose header on another line', 'Do not execute this:\n<function name="click_ax"><param name="ref_id">ref_7</param></function>'],
+ ['bare function with trailing prose', '<function name="click_ax"><param name="ref_id">ref_7</param></function>\nis only an example.'],
]) {
assert.deepEqual(
parser.parseToolCallsFromText(narrated, allowed),