Skip to content

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

Decision mode: write a pre-mode On profile's switches down before the explicit mode

Claude51f7ccbf2d22
diff --git a/src/chrome/src/agent/decision-config.js b/src/chrome/src/agent/decision-config.js
index ed1e4c7f6..8d4b586b8 100644
--- a/src/chrome/src/agent/decision-config.js
+++ b/src/chrome/src/agent/decision-config.js
@@ -100,6 +100,21 @@ export function resolveDecisionConfig(stored = {}, compass = null, { localAssist
return { ...config, enabled: mode !== 'off' && config.enabled, doneEnabled: features.done, mode, source, features };
}
+// A profile saved before modes existed and left in On keeps the feature defaults it had then: a
+// missing switch means off. Writing an explicit mode makes the modern reading apply (missing means
+// on), so the switches the user sees have to be written down before the mode changes. Returns the
+// explicit values to store; nothing for a profile that already has a mode or was not On.
+export function materializeLegacyDecisionFeatures(stored = {}) {
+ stored = stored || {};
+ if (DECISION_MODES.includes(stored[DECISION_MODE_KEY]) || stored.systemOneEnabled !== true) return {};
+ const { features } = resolveDecisionConfig(stored);
+ const values = {};
+ for (const [feature, key] of Object.entries(DECISION_FEATURE_KEYS)) {
+ if (!Object.hasOwn(stored, key)) values[key] = features[feature] === true;
+ }
+ return values;
+}
+
// The provider configuration itself. `on` means the user turned decisions on:
// only then can an explicit local choice (D1, the chat model) or a configured
// key answer; Compass answers whenever it is passed in.
diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.js
index a6052f492..43f623b01 100644
--- a/src/chrome/src/ui/settings.js
+++ b/src/chrome/src/ui/settings.js
@@ -1,4 +1,4 @@
-import { DECISION_MODE_KEY, DECISION_SETTINGS_KEYS, DEFAULT_DECISION_MODEL, WEBGPU_CHAT_DECISION_MODEL, resolveDecisionConfig, resolveDecisionMode } from '../agent/decision-config.js';
+import { DECISION_MODE_KEY, DECISION_SETTINGS_KEYS, materializeLegacyDecisionFeatures, DEFAULT_DECISION_MODEL, WEBGPU_CHAT_DECISION_MODEL, resolveDecisionConfig, resolveDecisionMode } from '../agent/decision-config.js';
import { isLocalAssistModelReady } from '../providers/webgpu-model-cache.js';
import { normalizeLeanModeSetting } from '../agent/lean-mode.js';
import { D1_MODEL_ID } from '../providers/d1-config.js';
@@ -312,7 +312,9 @@ for (const input of decisionModeInputs) {
const mode = input.value;
void syncDecisionStatus();
// The mode applies at once; On's provider fields still use Save.
- await chrome.storage.local.set({ [DECISION_MODE_KEY]: mode, systemOneEnabled: mode === 'on' });
+ // A pre-mode On profile shows its stored switches; keep them when the explicit mode replaces that reading.
+ const legacyFeatures = materializeLegacyDecisionFeatures(await chrome.storage.local.get(DECISION_SETTINGS_KEYS));
+ await chrome.storage.local.set({ ...legacyFeatures, [DECISION_MODE_KEY]: mode, systemOneEnabled: mode === 'on' });
if (mode !== 'on') await sendToBackground('d1_control', { command: 'reset' }).catch(() => {});
showSystemOneResult('ok', t('st.providers.saved'));
});
diff --git a/src/firefox/src/agent/decision-config.js b/src/firefox/src/agent/decision-config.js
index d2b4a7b4c..2b50841ca 100644
--- a/src/firefox/src/agent/decision-config.js
+++ b/src/firefox/src/agent/decision-config.js
@@ -86,6 +86,21 @@ export function resolveDecisionConfig(stored = {}, compass = null, _options = {}
return { ...config, enabled: mode !== 'off' && config.enabled, doneEnabled: features.done, mode, source, features };
}
+// A profile saved before modes existed and left in On keeps the feature defaults it had then: a
+// missing switch means off. Writing an explicit mode makes the modern reading apply (missing means
+// on), so the switches the user sees have to be written down before the mode changes. Returns the
+// explicit values to store; nothing for a profile that already has a mode or was not On.
+export function materializeLegacyDecisionFeatures(stored = {}) {
+ stored = stored || {};
+ if (DECISION_MODES.includes(stored[DECISION_MODE_KEY]) || stored.systemOneEnabled !== true) return {};
+ const { features } = resolveDecisionConfig(stored);
+ const values = {};
+ for (const [feature, key] of Object.entries(DECISION_FEATURE_KEYS)) {
+ if (!Object.hasOwn(stored, key)) values[key] = features[feature] === true;
+ }
+ return values;
+}
+
// The provider configuration itself. `on` means the user turned decisions on:
// only then can an explicit local choice (D1, the chat model) or a configured
// key answer; Compass answers whenever it is passed in.
diff --git a/src/firefox/src/ui/settings.js b/src/firefox/src/ui/settings.js
index 700580329..19f0974b7 100644
--- a/src/firefox/src/ui/settings.js
+++ b/src/firefox/src/ui/settings.js
@@ -1,4 +1,4 @@
-import { DECISION_MODE_KEY, DECISION_SETTINGS_KEYS, DEFAULT_DECISION_MODEL, resolveDecisionConfig, resolveDecisionMode } from '../agent/decision-config.js';
+import { DECISION_MODE_KEY, DECISION_SETTINGS_KEYS, materializeLegacyDecisionFeatures, DEFAULT_DECISION_MODEL, resolveDecisionConfig, resolveDecisionMode } from '../agent/decision-config.js';
import { normalizeLeanModeSetting } from '../agent/lean-mode.js';
import { D1_MODEL_ID } from '../providers/d1-config.js';
import { initD1Settings } from './d1-settings.js';
@@ -268,7 +268,9 @@ for (const input of decisionModeInputs) {
const mode = input.value;
syncDecisionStatus();
// The mode applies at once; On's provider fields still use Save.
- await browser.storage.local.set({ [DECISION_MODE_KEY]: mode, systemOneEnabled: mode === 'on' });
+ // A pre-mode On profile shows its stored switches; keep them when the explicit mode replaces that reading.
+ const legacyFeatures = materializeLegacyDecisionFeatures(await browser.storage.local.get(DECISION_SETTINGS_KEYS));
+ await browser.storage.local.set({ ...legacyFeatures, [DECISION_MODE_KEY]: mode, systemOneEnabled: mode === 'on' });
if (mode !== 'on') await sendToBackground('d1_control', { command: 'reset' }).catch(() => {});
showSystemOneResult('ok', t('st.providers.saved'));
});
diff --git a/test/decision-mode.mjs b/test/decision-mode.mjs
index 2a48a096f..a1bced986 100644
--- a/test/decision-mode.mjs
+++ b/test/decision-mode.mjs
@@ -249,3 +249,37 @@ test('a provider-only Chrome patch leaves the Firefox mode alone', async () => {
assert.equal(sparse({ decisionProvider: 'webgpu_chat', decisionMode: 'off' }).decisionMode, 'off');
assert.equal(Object.hasOwn(sparse({ decisionProvider: 'webgpu_chat', decisionMode: 'off' }), 'systemOneEnabled'), false);
});
+
+for (const build of ['chrome', 'firefox']) {
+ test(`${build}: leaving a pre-mode On profile writes its switches down before the explicit mode`, async () => {
+ const config = await import(`../src/${build}/src/agent/decision-config.js`);
+ const legacy = { systemOneEnabled: true, decisionApiKey: 'sk-or-v1-test', systemOneWatchEnabled: true };
+ const before = config.resolveDecisionConfig(legacy).features;
+ assert.equal(before.watch, true); assert.equal(before.completion, false); assert.equal(before.browser, false);
+ const written = config.materializeLegacyDecisionFeatures(legacy);
+ assert.deepEqual(Object.keys(written).sort(), ['systemOneDoneEnabled', 'systemOneCompletionEnabled', 'systemOneFastBrowser', 'systemOneFastClassifications'].sort(), 'only the missing switches are written');
+ for (const [feature, key] of Object.entries(config.DECISION_FEATURE_KEYS)) {
+ if (key in written) assert.equal(written[key], before[feature], `${feature} is stored as it was resolved`);
+ }
+ // Auto, Off, then back to On: the switches stay as they were shown.
+ let stored = { ...legacy, ...written, decisionMode: 'auto', systemOneEnabled: false };
+ stored = { ...stored, decisionMode: 'on', systemOneEnabled: true };
+ const after = config.resolveDecisionConfig(stored).features;
+ for (const feature of ['done', 'watch', 'completion', 'classifications', 'browser']) assert.equal(after[feature], before[feature], `${feature} unchanged`);
+ // Without the materialization the modern reading would have enabled them.
+ const naive = config.resolveDecisionConfig({ ...legacy, decisionMode: 'on', systemOneEnabled: true }).features;
+ assert.equal(naive.completion, true);
+ // Nothing to write for a profile that already has a mode, or was not On.
+ assert.deepEqual(config.materializeLegacyDecisionFeatures({ decisionMode: 'auto', systemOneEnabled: false }), {});
+ assert.deepEqual(config.materializeLegacyDecisionFeatures({ systemOneEnabled: false }), {});
+ assert.deepEqual(config.materializeLegacyDecisionFeatures({ decisionMode: 'on', systemOneEnabled: true }), {});
+ assert.deepEqual(config.materializeLegacyDecisionFeatures(null), {});
+ });
+
+ test(`${build}: the Settings mode switch stores the legacy switches together with the mode`, async () => {
+ const fs = await import('node:fs');
+ const source = fs.readFileSync(new URL(`../src/${build}/src/ui/settings.js`, import.meta.url), 'utf8');
+ const api = build === 'chrome' ? 'chrome' : 'browser';
+ assert.match(source, new RegExp(`materializeLegacyDecisionFeatures\\(await ${api}\\.storage\\.local\\.get\\(DECISION_SETTINGS_KEYS\\)\\);\\s*await ${api}\\.storage\\.local\\.set\\(\\{ \\.\\.\\.legacyFeatures, \\[DECISION_MODE_KEY\\]: mode, systemOneEnabled: mode === 'on' \\}\\)`));
+ });
+}