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
Report a selection with no room as an error, not a cut-off to continue
Claude844579eb6096
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e4e61d995..0676f979e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,7 +10,7 @@ This changelog was generated from the repository Git history and release tags. V- Selecting text on a page now shows a small bar, **Translate | Explain | Proofread | More…**, instead of the single `?` button. Translate, Explain and Proofread answer in a card next to the selection: Translate shows the detected source language, the original text and a target-language picker, and every card has an "Ask a follow-up" box that, once the answer is there, continues in the side panel with the card's answer as context. **More…** opens the same popup the `?` button opened (Summarize, Quiz me, Humanize, a question box and Hide this; Translate, Explain and Proofread are on the bar, so they are not repeated there). A card sends the selected text to your configured model provider, like any other selection action; selections over 4,000 characters go to the side panel instead of a card. A card answer that reaches the model's output limit says it was cut off and offers to continue in the side panel, which picks up from the unfinished text instead of starting over (a side-panel reply that is cut off again says so, including when an OpenAI Responses model reports the limit as an error, in which case the text it wrote is kept and the call still counts toward your cloud-cost allowance), and closing or redoing a card, or reloading or leaving the page, cancels the request it no longer needs. Chrome and Firefox.### Fixed-- Chrome: sending a follow-up or a selection action to WebBrain while the side panel is already open no longer closes it. Each side panel now tells the background whether it is on screen, and the background skips re-opening a panel that is already showing and hands it the prompt directly A panel that was open while the background restarted tells the new worker about itself at once instead of after a delay, so a request in that moment does not close it. The same holds for actions chosen on a selection in WebBrain's PDF viewer, where a panel that was closed is opened once rather than twice. A side panel that the browser moves to another window (its tab dragged out) now reports its new window, so an action in that window no longer closes it and an action in the old window opens a panel again. The PDF viewer keeps its own window up to date the same way, so a viewer tab dragged to another window reports where it is now, taking the new window from the tab-attached event rather than from a lookup a quick click could outrun. A card answer whose request is the one to reach the cloud cost allowance now says so under the answer instead of showing it as an ordinary success. The room a card leaves for the prompt in a small context window is now estimated as a worst case (a token per ASCII character, four for anything else), so dense text such as minified code or hashes is handed to the side panel on a 4k local model instead of being sent a request the backend rejects. Continuing a cut-off Proofread in the side panel no longer asks for the whole corrected version again alongside the request for only the remainder. Continuing a cut-off card answer, or asking a follow-up, in the side panel now sizes the reply to what the model's context window leaves, so a small local model is not sent a request it rejects; when nothing fits it says the selection is too long for the model instead of failing. A card answer is now held to a fixed 64,000-character limit that is enforced when it is produced and when the card receives it, so a follow-up or a continuation carries exactly what the card shows instead of an answer silently shortened by a token-ratio estimate; a longer one is cut and offered to the side panel.+- Chrome: sending a follow-up or a selection action to WebBrain while the side panel is already open no longer closes it. Each side panel now tells the background whether it is on screen, and the background skips re-opening a panel that is already showing and hands it the prompt directly A panel that was open while the background restarted tells the new worker about itself at once instead of after a delay, so a request in that moment does not close it. The same holds for actions chosen on a selection in WebBrain's PDF viewer, where a panel that was closed is opened once rather than twice. A side panel that the browser moves to another window (its tab dragged out) now reports its new window, so an action in that window no longer closes it and an action in the old window opens a panel again. The PDF viewer keeps its own window up to date the same way, so a viewer tab dragged to another window reports where it is now, taking the new window from the tab-attached event rather than from a lookup a quick click could outrun. A card answer whose request is the one to reach the cloud cost allowance now says so under the answer instead of showing it as an ordinary success. The room a card leaves for the prompt in a small context window is now estimated as a worst case (a token per ASCII character, four for anything else), so dense text such as minified code or hashes on a 4k local model is reported as too long for the model instead of being sent a request the backend rejects. Continuing a cut-off Proofread in the side panel no longer asks for the whole corrected version again alongside the request for only the remainder. Continuing a cut-off card answer, or asking a follow-up, in the side panel now sizes the reply to what the model's context window leaves, so a small local model is not sent a request it rejects; when nothing fits it says the selection is too long for the model instead of failing. A card answer is now held to a fixed 64,000-character limit that is enforced when it is produced and when the card receives it, so a follow-up or a continuation carries exactly what the card shows instead of an answer silently shortened by a token-ratio estimate; a longer one is cut and offered to the side panel. A selection too long for the model's context window is reported as an error in the card instead of being offered as a continuation the side panel would refuse as well.- Stopping a task while WebBrain was waiting for page navigation to settle now stops it immediately. The pending settle step previously kept waiting and could let the run continue after you chose Stop.- Mastodon: replying to toots in a narrow window no longer posts the same reply several times and stops before the next toot. There, a toot's Reply button opens the composer at /publish, and after posting Mastodon goes back to the previous column by itself. WebBrain took both page changes for something you did, so it reported each click's outcome as unknown; the agent then concluded its reply had not been posted, wrote it again, and never reached the next toot. In Chrome, a page's own Back is now told apart from your browser's Back button: the page a click opens counts as that click's verified effect, and a click after which the page goes back by itself counts as delivered, to be checked on the page. The Mastodon notes now cover replies (start with the prefilled @mentions once, check the reply under the toot before any retry) and stay active on Favourites, Bookmarks and the other columns. Firefox still treats a page's own Back as yours until its Back button reporting is verified.- Finishing a form you asked WebBrain not to submit no longer takes most of a minute. The completion check removed every line that mentioned a password, so "fill out this form with a random password … don't submit" reached its judge as "[credential omitted]", and so did the approved plan and the agent's summary. Seeing only an unsubmitted signup form, the judge answered "pending" again and again; in the trace it took four attempts and about 50 seconds, ending only when a slow screenshot check ran out of time. The active model's check, which already holds these texts in the conversation, now receives every line of them, with only addresses shortened and bearer tokens and entered passwords hidden, as in all judge evidence. A decision model on this device, or WebBrain Cloud's own while WebBrain Cloud is also your provider, receives that same copy; any other decision model keeps whole-line redaction, and when that leaves it without the task, it is no longer asked while the active model can judge. A password WebBrain typed into a password field during the run is now hidden in the text judges receive, such as the agent's summary or a field a "show password" control revealed, unless the typing tool could not tell what kind of field it was; other entered values stay visible, so a judge can still catch a mistyped one. The judges are told that a task asking not to submit is complete once the staged values match, that a hidden value neither proves nor disproves an entry, and, for each recorded entry, whether its field read back what was entered, whether it is a credential field and which field it targeted; a credential field's line in the page evidence keeps its role and reference. Staged field edits are judged from the accessibility tree first: a screenshot shows passwords only as dots, and the focused field's blinking caret made each one stale before its verdict returned.diff --git a/docs/architecture.md b/docs/architecture.mdindex 72bc5c92c..5f6cc5aa1 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -524,8 +524,9 @@ character, up to 8,000) and never exceeds the provider's own output ceiling or tcontext window leaves after the prompt (estimated on the high side, since the provider's tokenizeris not available: a whole token per ASCII character, as dense text such as minified code or hashes can need, four per other character, the most a byte-level fallback spends on one code point (accented letters, CJK, emoji),plus a reserve), so a small local window is not sent a request it would reject. When the prompt-leaves less than 256 tokens for the answer, the background makes no call and answers with the-cut-off shape, so the card hands the selection to the side panel. If the reply+leaves less than 256 tokens for the answer, the background makes no call and answers with a plain+context-window error (not the cut-off shape: the side panel sizes its reply to the same window and+would refuse the same selection, so the card must not offer it as a way to finish). If the replystill stopped at the cap (finish reason, Anthropic `stop_reason` or Responses`incomplete_details`, or token usage at the budget when no reason is reported; OpenAIResponses reports the limit as an error, which the background treats the same way anddiff --git a/src/chrome/src/background.js b/src/chrome/src/background.jsindex 56a5567fd..7d4dcb73b 100644--- a/src/chrome/src/background.js+++ b/src/chrome/src/background.js@@ -1796,10 +1796,11 @@ async function answerInlineSelection(msg) {contextWindow: provider?.contextWindow,messages,});- // The prompt alone fills the model's context window: no call could answer, so the- // card offers the side panel, which manages its own context, instead.+ // The prompt alone fills the model's context window: no call could answer. This is a plain+ // error, not a cut-off: the side panel sizes its reply to the same window and would refuse+ // the same selection, so the card must not offer it as a way to finish the answer.if (maxTokens === 0) {- return { ok: false, truncated: true, error: 'This selection is too long for the model\'s context window.' };+ return { ok: false, error: 'This selection is too long for the model\'s context window.' };}const result = await agent._chatWithCostAllowance(provider,diff --git a/src/chrome/src/context-menu-storage.js b/src/chrome/src/context-menu-storage.jsindex 2658a7247..06214c5eb 100644--- a/src/chrome/src/context-menu-storage.js+++ b/src/chrome/src/context-menu-storage.js@@ -285,7 +285,7 @@ const INLINE_FALLBACK_OUTPUT_CEILING = 4096;// code, identifiers, hashes and other high-entropy text can take that, and prose takes far// less), anything else (accented Latin, CJK, Indic, Arabic, Cyrillic, emoji) at four, the// most a byte-level fallback spends on one code point (its UTF-8 bytes). Over-counting only-// makes a tight window end in a flagged cut-off or a hand-off to the side panel instead of a+// makes a tight window end in a flagged cut-off or a plain "too long for the model" error instead of a// refused request. Chat-template tokens are covered by the reserve.const INLINE_ASCII_TOKENS_PER_CHAR = 1;const INLINE_OTHER_TOKENS_PER_CHAR = 4;@@ -323,7 +323,7 @@ export function fitAnswerToContext({ contextWindow, messages, wanted }) {export const SELECTION_TOO_LONG_FOR_CONTEXT = 'This selection, with the earlier text it builds on, is too long for the model\'s context window, so it was not sent. Select less text, or switch to a model with a larger context window.';// 0 means the prompt alone leaves the answer less than its floor in the provider's-// context window, so the card should hand the selection to the side panel.+// context window, so no call is made and the card reports it as too long for the model.export function inlineSelectionMaxTokens(selectionText, action, providerCeiling, { contextWindow, messages } = {}) {const chars = String(selectionText || '').trim().length;const wanted = String(action || '').trim() === 'explain'diff --git a/src/firefox/src/background.js b/src/firefox/src/background.jsindex 3c68e527a..00f9609ae 100644--- a/src/firefox/src/background.js+++ b/src/firefox/src/background.js@@ -1547,10 +1547,11 @@ async function answerInlineSelection(msg) {contextWindow: provider?.contextWindow,messages,});- // The prompt alone fills the model's context window: no call could answer, so the- // card offers the side panel, which manages its own context, instead.+ // The prompt alone fills the model's context window: no call could answer. This is a plain+ // error, not a cut-off: the side panel sizes its reply to the same window and would refuse+ // the same selection, so the card must not offer it as a way to finish the answer.if (maxTokens === 0) {- return { ok: false, truncated: true, error: 'This selection is too long for the model\'s context window.' };+ return { ok: false, error: 'This selection is too long for the model\'s context window.' };}const result = await agent._chatWithCostAllowance(provider,diff --git a/src/firefox/src/context-menu-storage.js b/src/firefox/src/context-menu-storage.jsindex ecb654ada..c992ecd8d 100644--- a/src/firefox/src/context-menu-storage.js+++ b/src/firefox/src/context-menu-storage.js@@ -285,7 +285,7 @@ const INLINE_FALLBACK_OUTPUT_CEILING = 4096;// code, identifiers, hashes and other high-entropy text can take that, and prose takes far// less), anything else (accented Latin, CJK, Indic, Arabic, Cyrillic, emoji) at four, the// most a byte-level fallback spends on one code point (its UTF-8 bytes). Over-counting only-// makes a tight window end in a flagged cut-off or a hand-off to the side panel instead of a+// makes a tight window end in a flagged cut-off or a plain "too long for the model" error instead of a// refused request. Chat-template tokens are covered by the reserve.const INLINE_ASCII_TOKENS_PER_CHAR = 1;const INLINE_OTHER_TOKENS_PER_CHAR = 4;@@ -323,7 +323,7 @@ export function fitAnswerToContext({ contextWindow, messages, wanted }) {export const SELECTION_TOO_LONG_FOR_CONTEXT = 'This selection, with the earlier text it builds on, is too long for the model\'s context window, so it was not sent. Select less text, or switch to a model with a larger context window.';// 0 means the prompt alone leaves the answer less than its floor in the provider's-// context window, so the card should hand the selection to the side panel.+// context window, so no call is made and the card reports it as too long for the model.export function inlineSelectionMaxTokens(selectionText, action, providerCeiling, { contextWindow, messages } = {}) {const chars = String(selectionText || '').trim().length;const wanted = String(action || '').trim() === 'explain'diff --git a/test/run.js b/test/run.jsindex c85de2e46..47dc257b4 100644--- a/test/run.js+++ b/test/run.js@@ -52357,7 +52357,8 @@ test('inline card answers are one tool-less, bounded model call behind validatedassert.match(body, /if \(!messages\) return \{ ok: false/, `${prefix}: invalid requests are refused before any model call`);assert.match(body, /agent\._chatWithCostAllowance\(\s*provider,\s*messages,\s*\{ maxTokens, temperature: 0, signal: controller\.signal \},\s*agent\._newCostRunState\(\),/, `${prefix}: the call is bounded, abortable and goes through the cost allowance`);assert.match(body, /const maxTokens = inlineSelectionMaxTokens\(msg\.selectionText, msg\.action, provider\?\.maxOutputTokens, \{\s*contextWindow: provider\?\.contextWindow,\s*messages,\s*\}\);/, `${prefix}: the budget is sized to the selection, the provider's ceiling and the room its context window leaves after the prompt`);- assert.match(body, /if \(maxTokens === 0\) \{\s*return \{ ok: false, truncated: true, error: [^}]*context window[^}]*\};\s*\}\s*const result = await agent\._chatWithCostAllowance/, `${prefix}: a prompt that fills the context window is handed to the side panel without a model call`);+ assert.match(body, /if \(maxTokens === 0\) \{\s*return \{ ok: false, error: [^}]*context window[^}]*\};\s*\}\s*const result = await agent\._chatWithCostAllowance/, `${prefix}: a prompt that fills the context window is reported as an error without a model call`);+ assert.doesNotMatch(body.slice(body.indexOf('if (maxTokens === 0)'), body.indexOf('const result = await')), /truncated/, `${prefix}: and is not offered as a cut-off to finish in the side panel, which would refuse it too`);assert.match(body, /inlineAnswerWasCut\(result, maxTokens\) \? \{ \.\.\.answer, truncated: true \} : answer/, `${prefix}: a capped answer is flagged instead of passing as complete`);assert.match(body, /catch \(error\) \{\s*if \(inlineErrorWasCut\(error\)\) \{[\s\S]*?\{ ok: true, text: partial, truncated: true, \.\.\.\(notice \? \{ notice \} : \{\}\) \}[\s\S]*?\{ ok: false, truncated: true, error:/, `${prefix}: a provider that reports the output limit as an error still ends in the cut-off state`);@@ -52499,6 +52500,34 @@ test('a card never holds more than its answer limit, so a follow-up or continuat}});+test('a selection that leaves the model no room is an error the card reports, not a cut-off to continue', async () => {+ for (const prefix of ['src/chrome', 'src/firefox']) {+ const background = fs.readFileSync(path.join(ROOT, prefix, 'src/background.js'), 'utf8');+ const helperStart = background.indexOf('function inlineCostNotice(source) {');+ const start = background.indexOf('async function answerInlineSelection(msg) {');+ const source = background.slice(helperStart, background.indexOf('\n}\n', start) + 2);+ let called = 0;+ const context = vm.createContext({+ AbortController, setTimeout, clearTimeout, String, Map,+ INLINE_SELECTION_TIMEOUT_MS: 1000,+ INLINE_JOB_ID_PATTERN: /^[a-z0-9]{8,64}$/,+ inlineSelectionJobs: new Map(),+ buildInlineSelectionMessages: () => [{ role: 'user', content: 'x' }],+ inlineSelectionMaxTokens: () => 0,+ inlineAnswerWasCut: () => false,+ inlineErrorWasCut: () => false,+ capInlineAnswer: (text) => ({ text, cut: false }),+ providerManager: { providers: { size: 1 }, getActive: () => ({}) },+ agent: { _newCostRunState: () => ({}), _chatWithCostAllowance: async () => { called += 1; return { content: 'never' }; } },+ });+ vm.runInContext(`${source}\nthis.answerInlineSelection = answerInlineSelection;`, context);+ const result = JSON.parse(JSON.stringify(await context.answerInlineSelection({ selectionText: 'x', action: 'translate', language: 'fr' })));+ assert.deepEqual(result, { ok: false, error: "This selection is too long for the model's context window." },+ `${prefix}: a plain error, so the card does not offer a continuation the side panel would refuse`);+ assert.equal(called, 0, `${prefix}: and no model call is made`);+ }+});+test('inline card token budget follows the selection and never exceeds the provider ceiling', () => {for (const [label, min, max, budget] of [['chrome', INLINE_ANSWER_MIN_TOKENS_CH, INLINE_ANSWER_MAX_TOKENS_CH, inlineSelectionMaxTokensCh],