Skip to content

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

Mode picker: wait for a stored mode before sending; Act warning follows the run

Claude546665a97e23
diff --git a/src/chrome/src/ui/composer-mode-pin.js b/src/chrome/src/ui/composer-mode-pin.js
index 4e7aee79b..582a37b06 100644
--- a/src/chrome/src/ui/composer-mode-pin.js
+++ b/src/chrome/src/ui/composer-mode-pin.js
@@ -17,6 +17,9 @@ export function createComposerModePins(storageArea) {
const pins = new Map();
// Tabs whose choice this document made: storage can no longer override it.
const decided = new Set();
+ // Tabs already read from storage, and reads still going (shared).
+ const loaded = new Set();
+ const loading = new Map();
const key = tabId => `${COMPOSER_MODE_PIN_PREFIX}${tabId}`;
return {
get(tabId) {
@@ -39,16 +42,24 @@ export function createComposerModePins(storageArea) {
clear(tabId) {
return this.set(tabId, null);
},
- // A choice made in this document wins over a stored one.
+ // A choice made in this document wins over a stored one. Each tab is read
+ // once; later calls return at once (a send waits on this).
async load(tabId) {
if (tabId == null) return null;
const id = String(tabId);
- if (decided.has(id)) return pins.get(id) || null;
- try {
- const stored = await area()?.get?.(key(id));
- const pin = normalizeComposerModePin(stored?.[key(id)]);
- if (pin && !decided.has(id)) pins.set(id, pin);
- } catch {}
+ if (decided.has(id) || loaded.has(id)) return pins.get(id) || null;
+ if (!loading.has(id)) {
+ loading.set(id, (async () => {
+ try {
+ const stored = await area()?.get?.(key(id));
+ const pin = normalizeComposerModePin(stored?.[key(id)]);
+ if (pin && !decided.has(id)) pins.set(id, pin);
+ } catch {}
+ loaded.add(id);
+ loading.delete(id);
+ })());
+ }
+ await loading.get(id);
return pins.get(id) || null;
},
};
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index 69bcc6077..2de1d33be 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -1905,6 +1905,13 @@ function restoreComposerModeForCurrentTab() {
});
}
+async function restoreComposerModeBeforeSend(tabId) {
+ if (isStandaloneWindow || tabId == null) return;
+ const before = composerModePins.get(tabId);
+ await composerModePins.load(tabId);
+ if (sameTabId(currentTabId, tabId) && composerModePins.get(tabId) !== before) syncComposerModeForCurrentTab();
+}
+
function setComposerModePinForTab(tabId, mode) {
if (isStandaloneWindow || tabId == null) return;
// Any change (a pick, a new chat, a recovered record, a selection scope, a
@@ -2048,16 +2055,19 @@ renderPermissionGateControl();
renderComposerModePicker();
// An automatically routed run that is acting in the visible tab.
-function autoActionRunVisible() {
- return autoModeSelection && isProcessing
- && ['act', 'dev'].includes(currentAssistantEl?.dataset?.runMode);
+// The mode of the run on screen, while it is going. It can differ from the
+// mode the next message uses (Auto, or the one kept in the "!" menu): an
+// automatic route, a one-message slash command, Retry or Continue.
+function visibleRunMode() {
+ const mode = isProcessing ? currentAssistantEl?.dataset?.runMode : '';
+ return ['ask', 'act', 'dev'].includes(mode) ? mode : '';
}
function updateActWarning() {
if (!actWarning) return;
const show = actWarningPreferenceLoaded
&& !actWarningDismissed
- && (agentMode !== 'ask' || autoActionRunVisible())
+ && (visibleRunMode() ? visibleRunMode() !== 'ask' : agentMode !== 'ask')
&& !askBeforeConsequential;
actWarning.classList.toggle('hidden', !show);
}
@@ -9984,6 +9994,9 @@ async function sendMessage(extraChatParams = {}) {
if (selectionAction) chatExtraParams.selectionAction = selectionAction;
await composerDeliveryModeReady;
await waitForVisibleSidePanelStateRefresh();
+ // A reopened panel may still be reading the tab's kept mode: never send a
+ // message as Auto that the user kept in Ask, Act or Dev.
+ await restoreComposerModeBeforeSend(composerSubmission.tabId);
if (!sameTabId(submissionRenderedTabId, composerSubmission.tabId)
|| !composerSubmissionIsCurrent(composerSubmission, { allowProcessing: submissionStartedDuringRun })) {
await releaseOwnedContextMenuClaim();
diff --git a/src/firefox/src/ui/composer-mode-pin.js b/src/firefox/src/ui/composer-mode-pin.js
index 4e7aee79b..582a37b06 100644
--- a/src/firefox/src/ui/composer-mode-pin.js
+++ b/src/firefox/src/ui/composer-mode-pin.js
@@ -17,6 +17,9 @@ export function createComposerModePins(storageArea) {
const pins = new Map();
// Tabs whose choice this document made: storage can no longer override it.
const decided = new Set();
+ // Tabs already read from storage, and reads still going (shared).
+ const loaded = new Set();
+ const loading = new Map();
const key = tabId => `${COMPOSER_MODE_PIN_PREFIX}${tabId}`;
return {
get(tabId) {
@@ -39,16 +42,24 @@ export function createComposerModePins(storageArea) {
clear(tabId) {
return this.set(tabId, null);
},
- // A choice made in this document wins over a stored one.
+ // A choice made in this document wins over a stored one. Each tab is read
+ // once; later calls return at once (a send waits on this).
async load(tabId) {
if (tabId == null) return null;
const id = String(tabId);
- if (decided.has(id)) return pins.get(id) || null;
- try {
- const stored = await area()?.get?.(key(id));
- const pin = normalizeComposerModePin(stored?.[key(id)]);
- if (pin && !decided.has(id)) pins.set(id, pin);
- } catch {}
+ if (decided.has(id) || loaded.has(id)) return pins.get(id) || null;
+ if (!loading.has(id)) {
+ loading.set(id, (async () => {
+ try {
+ const stored = await area()?.get?.(key(id));
+ const pin = normalizeComposerModePin(stored?.[key(id)]);
+ if (pin && !decided.has(id)) pins.set(id, pin);
+ } catch {}
+ loaded.add(id);
+ loading.delete(id);
+ })());
+ }
+ await loading.get(id);
return pins.get(id) || null;
},
};
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index ca774f9fc..0138ab1e1 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -2080,6 +2080,13 @@ function restoreComposerModeForCurrentTab() {
});
}
+async function restoreComposerModeBeforeSend(tabId) {
+ if (isStandaloneWindow || tabId == null) return;
+ const before = composerModePins.get(tabId);
+ await composerModePins.load(tabId);
+ if (sameTabId(currentTabId, tabId) && composerModePins.get(tabId) !== before) syncComposerModeForCurrentTab();
+}
+
function setComposerModePinForTab(tabId, mode) {
if (isStandaloneWindow || tabId == null) return;
// Any change (a pick, a new chat, a recovered record, a selection scope, a
@@ -2218,16 +2225,19 @@ renderPermissionGateControl();
renderComposerModePicker();
// An automatically routed run that is acting in the visible tab.
-function autoActionRunVisible() {
- return autoModeSelection && isProcessing
- && ['act', 'dev'].includes(currentAssistantEl?.dataset?.runMode);
+// The mode of the run on screen, while it is going. It can differ from the
+// mode the next message uses (Auto, or the one kept in the "!" menu): an
+// automatic route, a one-message slash command, Retry or Continue.
+function visibleRunMode() {
+ const mode = isProcessing ? currentAssistantEl?.dataset?.runMode : '';
+ return ['ask', 'act', 'dev'].includes(mode) ? mode : '';
}
function updateActWarning() {
if (!actWarning) return;
const show = actWarningPreferenceLoaded
&& !actWarningDismissed
- && (agentMode !== 'ask' || autoActionRunVisible())
+ && (visibleRunMode() ? visibleRunMode() !== 'ask' : agentMode !== 'ask')
&& !askBeforeConsequential;
actWarning.classList.toggle('hidden', !show);
}
@@ -9670,6 +9680,9 @@ async function sendMessage(extraChatParams = {}) {
if (selectionAction) chatExtraParams.selectionAction = selectionAction;
await composerDeliveryModeReady;
await waitForVisibleSidePanelStateRefresh();
+ // A reopened panel may still be reading the tab's kept mode: never send a
+ // message as Auto that the user kept in Ask, Act or Dev.
+ await restoreComposerModeBeforeSend(composerSubmission.tabId);
if (!sameTabId(submissionRenderedTabId, composerSubmission.tabId)
|| !composerSubmissionIsCurrent(composerSubmission, { allowProcessing: submissionStartedDuringRun })) {
await releaseOwnedContextMenuClaim();
diff --git a/test/auto-mode.mjs b/test/auto-mode.mjs
index 6cc10cad3..b1ca2cd5e 100644
--- a/test/auto-mode.mjs
+++ b/test/auto-mode.mjs
@@ -58,6 +58,12 @@ test('a kept composer mode is per tab, survives a reopened panel and clears for
await racing.clear(5);
assert.equal(await loading, null);
assert.equal(racing.get(5), null);
+ // Each tab is read once; concurrent reads share one storage call.
+ let reads = 0;
+ const counting = createComposerModePins({ ...area, async get(key) { reads += 1; return area.get(key); } });
+ await Promise.all([counting.load(1), counting.load(1)]);
+ assert.equal(await counting.load(1), 'act');
+ assert.equal(reads, 1);
// Without storage it still works in memory.
const volatile = createComposerModePins(() => undefined);
await volatile.set(9, 'ask');
@@ -860,6 +866,21 @@ for (const build of BUILDS) {
assert.match(panel, /if \(previousMode === 'dev' && mode !== 'dev' && !pinned\) \{/);
assert.match(panel, /if \(previous === 'dev' && mode !== 'dev'\) \{\s*sendToBackground\('disable_dev_diagnostics', \{ tabId: Number\(tabId\) \}\)/);
}
+ // A send waits until a reopened panel has read the tab's kept mode.
+ assert.match(panel, /await waitForVisibleSidePanelStateRefresh\(\);\s*(?:\/\/[^\n]*\n\s*)+await restoreComposerModeBeforeSend\(composerSubmission\.tabId\);/);
+ // The Act warning follows the run on screen, else the mode the next message uses.
+ const warning = vm.createContext({ actWarning: { hidden: true, classList: { toggle(_name, hide) { warning.actWarning.hidden = hide; } } },
+ actWarningPreferenceLoaded: true, actWarningDismissed: false, askBeforeConsequential: false,
+ agentMode: 'ask', isProcessing: false, currentAssistantEl: null });
+ vm.runInContext(`${extract(panel, 'visibleRunMode')}\n${extract(panel, 'updateActWarning')}`, warning);
+ const shown = (state) => { Object.assign(warning, state); vm.runInContext('updateActWarning()', warning); return !warning.actWarning.hidden; };
+ assert.equal(shown({ agentMode: 'act' }), true, 'Act kept, idle');
+ assert.equal(shown({ agentMode: 'ask' }), false, 'Ask kept or Auto, idle');
+ assert.equal(shown({ agentMode: 'ask', isProcessing: true, currentAssistantEl: { dataset: { runMode: 'act' } } }), true, 'a one-message /act run under a kept Ask');
+ assert.equal(shown({ agentMode: 'act', isProcessing: true, currentAssistantEl: { dataset: { runMode: 'ask' } } }), false, 'a one-message Ask run under a kept Act');
+ assert.equal(shown({ agentMode: 'ask', isProcessing: true, currentAssistantEl: { dataset: { runMode: 'auto' } } }), false, 'an automatic run before it is routed');
+ assert.equal(shown({ agentMode: 'ask', isProcessing: true, currentAssistantEl: { dataset: { runMode: 'dev' } } }), true);
+ assert.equal(shown({ askBeforeConsequential: true }), false, 'only while permission prompts are off');
// The menu checks Act and Dev like the shortcuts but never switches through them.
assert.match(panel, /const allowed = pin === 'act' \? await ensureActMode\(\{ switchMode: false \}\)\s*: pin === 'dev' \? await ensureDevMode\(\{ switchMode: false \}\)\s*: true;/);
const input = { value: '/act book it', focus() {}, setSelectionRange() {} };