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
Keep an active Dev run's capture when switching to Automatic
Claude7273ea14cc83
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.jsindex b8582d537..db064e6fe 100644--- a/src/chrome/src/ui/sidepanel.js+++ b/src/chrome/src/ui/sidepanel.js@@ -1258,6 +1258,10 @@ let agentMode = 'ask'; // 'ask' | 'act' | 'dev'// sends "auto" and the agent routes each turn (src/*/src/agent/auto-mode.js);// slash commands and the mode shortcuts choose a mode for one message.let autoModeSelection = false;+// Set when switching to Automatic left Dev while a run was still active:+// that run keeps its console and network capture until the panel has no+// run left, then the drain that leaving Dev asks for runs.+let devDiagnosticsDrainDeferred = false;let abortRequested = false;const awaitingPlanReviewTabs = new Set();const processingTabs = new Set();@@ -1334,6 +1338,14 @@ function setTabProcessing(tabId, processing) {if (typeof syncFailureRecoveryButtons === 'function') syncFailureRecoveryButtons();if (typeof updateActWarning === 'function') updateActWarning();}+ if (!effectiveProcessing && typeof drainDeferredDevDiagnostics === 'function') drainDeferredDevDiagnostics();+}++function drainDeferredDevDiagnostics() {+ if (!devDiagnosticsDrainDeferred || processingTabs.size > 0) return;+ devDiagnosticsDrainDeferred = false;+ if (agentMode === 'dev') return;+ sendToBackground('disable_dev_diagnostics', { all: true }).catch(() => {});}function isTabProcessing(tabId) {@@ -2119,9 +2131,12 @@ function applyModeSelection(value) {autoModeSelection = value === 'auto' && !isStandaloneWindow;document.documentElement.dataset.modeSelection = autoModeSelection ? 'auto' : 'manual';// A mode pinned before switching to Automatic must not linger in the- // composer styling; Automatic chooses per turn.- if (autoModeSelection && agentMode !== 'ask') setMode('ask');- else {+ // composer styling; Automatic chooses per turn. A run still going keeps+ // the Dev capture it may read until the panel's runs have ended.+ if (autoModeSelection && agentMode !== 'ask') {+ if (agentMode === 'dev' && processingTabs.size > 0) devDiagnosticsDrainDeferred = true;+ setMode('ask');+ } else {updateActWarning();resetInputPlaceholderRotation();}@@ -14553,7 +14568,9 @@ function setMode(mode) {if (autoModeSelection) mode = 'ask';const previousMode = agentMode;agentMode = mode;- if (previousMode === 'dev' && mode !== 'dev') {+ if (mode === 'dev') devDiagnosticsDrainDeferred = false;+ // A drain already owed to the end of the panel's runs is not sent twice.+ if (previousMode === 'dev' && mode !== 'dev' && !devDiagnosticsDrainDeferred) {// Dev mode is panel-wide, while diagnostics may be active on a tab the// user switched away from. Ask the background to drain its tracked set// instead of assuming currentTabId is the tab that started capture.diff --git a/test/auto-mode.mjs b/test/auto-mode.mjsindex c9e6631e7..654bbcb6f 100644--- a/test/auto-mode.mjs+++ b/test/auto-mode.mjs@@ -507,6 +507,51 @@ function extract(text, name) {return text.slice(start, end + 2);}+test('chrome: switching to Automatic during a Dev run keeps its capture until the run ends', () => {+ const panel = source('chrome', 'ui/sidepanel.js');+ const sent = [];+ const classList = { toggle() {}, remove() {} };+ const context = vm.createContext({+ agentMode: 'dev', autoModeSelection: false, isStandaloneWindow: false, devDiagnosticsDrainDeferred: false,+ processingTabs: new Set([7]), failedConversationClearRecoveryTabs: new Set(), currentTabId: 7, isProcessing: true,+ document: { documentElement: { dataset: {} } },+ modeAskBtn: { classList }, modeActBtn: { classList }, modeDevBtn: { classList }, inputArea: { classList },+ modeToggleHighlight: { classList }, positionModeHighlight() {}, updateActWarning() {}, resetInputPlaceholderRotation() {},+ syncSelectionScopeRestoreAvailability() {}, sameTabId: (a, b) => Number(a) === Number(b),+ sendToBackground: (type, payload) => { sent.push(`${type} ${JSON.stringify(payload)}`); return Promise.resolve(); },+ });+ for (const name of ['normalizeAgentMode', 'setMode', 'applyModeSelection', 'setTabProcessing', 'drainDeferredDevDiagnostics']) {+ vm.runInContext(extract(panel, name), context);+ }+ const drain = 'disable_dev_diagnostics {"all":true}';++ context.applyModeSelection('auto');+ assert.equal(context.agentMode, 'ask', 'the composer leaves Dev at once');+ assert.deepEqual(sent, [], 'the active run keeps its console and network history');+ context.setTabProcessing(7, false);+ assert.deepEqual(sent, [drain], 'drained once the panel has no run left');+ context.setTabProcessing(7, false);+ assert.deepEqual(sent, [drain], 'drained only once');++ sent.length = 0;+ context.applyModeSelection('manual');+ context.setMode('dev');+ context.applyModeSelection('auto');+ assert.deepEqual(sent, [drain], 'with no run active the drain is immediate');++ sent.length = 0;+ context.applyModeSelection('manual');+ context.setMode('dev');+ context.setTabProcessing(7, true);+ context.applyModeSelection('auto');+ context.applyModeSelection('manual');+ context.setMode('dev');+ context.setTabProcessing(7, false);+ assert.deepEqual(sent, [], 'choosing Dev again before the run ends cancels the owed drain');+ context.setMode('ask');+ assert.deepEqual(sent, [drain], 'leaving Dev by hand still drains at once');+});+for (const build of BUILDS) {const panel = source(build, 'ui/sidepanel.js');