Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(settings): remember the custom proxy across mode switches
Gargantuafd327cd0be78
diff --git a/apps/desktop/src/components/settings/NetworkProxySection.tsx b/apps/desktop/src/components/settings/NetworkProxySection.tsxindex a7bb6dbad..56cec5f87 100644--- a/apps/desktop/src/components/settings/NetworkProxySection.tsx+++ b/apps/desktop/src/components/settings/NetworkProxySection.tsx@@ -68,7 +68,10 @@ export function NetworkProxySection({if (mode === saved.mode) return;setTestState("idle");if (mode !== "custom") {- void persist({ mode });+ // Carry the custom URL and bypass across the switch: the mode is what+ // changes, and picking Custom again must restore the user's own proxy+ // instead of the built-in default (issue #1541).+ void persist({ mode, url: saved.url, bypass: saved.bypass });return;}const parsed = parseProxyUrl(urlDraft);diff --git a/apps/desktop/test/settings-general.test.mjs b/apps/desktop/test/settings-general.test.mjsindex bcb984216..69c14fe4f 100644--- a/apps/desktop/test/settings-general.test.mjs+++ b/apps/desktop/test/settings-general.test.mjs@@ -203,6 +203,12 @@ test("language persists as part of shared app settings", () => {test("General Network card persists a custom HTTP or SOCKS5 proxy and the relaxed network mode", () => {assert.match(settingsPageSource, /<NetworkProxySection /);assert.match(networkProxySource, /settings\.networkRelaxedMode/);+ // A mode switch carries the custom URL and bypass, so choosing Custom again+ // restores the user's own proxy instead of the built-in default (#1541).+ assert.match(+ networkProxySource,+ /persist\(\{ mode, url: saved\.url, bypass: saved\.bypass \}\)/,+ );// Fake-IP tolerance belongs to the network mode now, not to the proxy payload.assert.doesNotMatch(networkProxySource, /allowFakeIp/);assert.match(settingsSearchSource, /settings\.proxy/);diff --git a/docs/spec/03-runtime/04-data-storage.md b/docs/spec/03-runtime/04-data-storage.mdindex 667cbcd5d..f2683181d 100644--- a/docs/spec/03-runtime/04-data-storage.md+++ b/docs/spec/03-runtime/04-data-storage.md@@ -360,7 +360,7 @@ CREATE TABLE kv (| ns | contents ||---|---|-| `app` | the settings blob (`settings.get/set`), `currentProjectId`. Optional `networkProxy` (`mode`/`url`/`bypass`) is a JSON field in that blob; no schema version bump (D340) |+| `app` | the settings blob (`settings.get/set`), `currentProjectId`. Optional `networkProxy` (`mode`/`url`/`bypass`) is a JSON field in that blob: `url`/`bypass` survive a switch to System or Direct and are applied only in Custom mode (issue #1541); no schema version bump (D340) || `ui` | non-critical UI state the renderer asks the host to keep || `cache` | model-refresh stamps, recent model refs (spec 13 §3) || `plugin:<id>` | per-plugin settings; uninstall = `DELETE WHERE ns = ?` |diff --git a/docs/spec/04-ux/06-settings-ia.md b/docs/spec/04-ux/06-settings-ia.mdindex 4d0a1d9dd..5fcb526eb 100644--- a/docs/spec/04-ux/06-settings-ia.md+++ b/docs/spec/04-ux/06-settings-ia.md@@ -185,6 +185,10 @@ Settings is a **full-window page** that replaces the app sidebar + main chrome (- The selection persists as optional `AppSettings.networkProxy`(`mode` / `url` / `bypass`). Absent means System. No host protocol orstorage schema version bump (D340 / ADR 0177).+ - System and Direct keep the `url` and `bypass` the user configured: `mode`+ decides what applies, and the values come back with Custom instead of the+ built-in `socks5://127.0.0.1:1080` (issue #1541). Nothing applies them+ while another mode is selected.- **Relaxed network mode**: one switch persisting as`AppSettings.networkPolicy.mode` (`relaxed` | `strict`), **on by default**.When it is on, an endpoint the user typed themselves — a model base URL, andiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex e9d68a16e..4db4a918e 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -13344,7 +13344,9 @@ are withdrawn with ADR 0165.7. Switch to System. Confirm Chromium returns to `mode: "system"` and send aprovider request and marketplace refresh. Confirm both follow the OS/PACroute selected for each destination, including ordered proxy-to-direct- fallback, without restarting the app.+ fallback, without restarting the app. Select Custom again. Confirm the URL+ and Bypass entered in step 3 come back from `AppSettings.networkProxy`,+ which kept them while System was selected.- **Expected**: Custom covers model calls, marketplace, updates, plugin`net.fetch`, and the in-app browser. System covers provider and marketplacerequests through Electron's OS/PAC resolver. Workspace Bash `env` does notdiff --git a/docs/zh-CN/spec/04-ux/06-settings-ia.md b/docs/zh-CN/spec/04-ux/06-settings-ia.mdindex 847f54ded..105c0c3f4 100644--- a/docs/zh-CN/spec/04-ux/06-settings-ia.md+++ b/docs/zh-CN/spec/04-ux/06-settings-ia.md@@ -90,7 +90,7 @@手动睡眠和合盖遵循系统设置。- **网络**卡:- **代理**:分段控件 — 系统 / 直连 / 自定义。默认是系统(Chromium 跟随操作系统代理)。直连禁用代理。自定义将一个 HTTP、HTTPS 或 SOCKS5 URL 应用到应用自有出站请求(模型调用、扩展市场、更新、模型目录、插件 `net.fetch`、内置浏览器)。工作区 Bash 和 OAuth 用的系统浏览器不会被改写。- - 自定义显示代理 URL(含 `user:pass@`)、默认 `localhost,127.0.0.1,::1,<local>,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,169.254.0.0/16` 的绕过列表(本机、本地模型与所有局域网服务直连,不被代理吞掉),以及一次走该代理的测试。带认证的 URL 通过回环 SOCKS5 中继交给 Chromium(issue #490)。选择持久化为可选 `AppSettings.networkProxy`。无协议/存储版本升级(D340 / ADR 0177)。+ - 自定义显示代理 URL(含 `user:pass@`)、默认 `localhost,127.0.0.1,::1,<local>,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,169.254.0.0/16` 的绕过列表(本机、本地模型与所有局域网服务直连,不被代理吞掉),以及一次走该代理的测试。带认证的 URL 通过回环 SOCKS5 中继交给 Chromium(issue #490)。选择持久化为可选 `AppSettings.networkProxy`;系统/直连模式下同样保留用户填写的 `url` 与 `bypass`(只有 `mode` 决定谁生效),因此再次选择自定义会恢复它们而不是内置的 `socks5://127.0.0.1:1080`(issue #1541)。无协议/存储版本升级(D340 / ADR 0177)。- **网络宽松模式**:一个开关,持久化为 `AppSettings.networkPolicy.mode`(`relaxed` | `strict`),**默认开启**。开启时,你自己填写的端点(模型服务、MCP 服务器、git 远端)可以是回环或局域网地址、可以使用明文 `http`,并容忍透明代理的 fake-IP 答案;关闭则回到"只允许公网 https"。首次用明文访问这类端点时会弹一次告知。它取代的三个旧确认开关(`networkProxy.allowFakeIp`、`configSync.allowInsecureHttp`、以及自填明文开关)都已删除(ADR 0304)。- 平台支持的**关闭行为**仍保留在常规中,因为它改变的是应用程序窗口行为,而不是智能体行为。diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex e9401aa89..ef04f3de6 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -7455,7 +7455,7 @@ eleven-tool-round desktop paths are verified by3. 输入 `socks5://127.0.0.1:1080` 或 `http://127.0.0.1:7890` 并失焦。确认 `settings.get` 中 `networkProxy.mode` 为 `custom`。4. 对正在监听的代理点测试,确认已连接;对关闭的端口点测试,确认失败且不改已保存 URL。对需要认证的 HTTP / SOCKS5 代理填入 `user:pass@` 后再测,确认是已连接而不是 `net::ERR_NO_SUPPORTED_PROXIES`(issue #490)。5. 保存自定义代理后,通过已配置供应商发送一条简短提示。确认供应商请求和响应经过代理;即使 SOCKS5 代理将完整 bind 响应合并在一个 TCP 数据块中,请求仍能完成。再确认扩展市场刷新和 models.dev 刷新走代理;绕过列表中的回环地址不走代理。- 6. 切到直连再切回系统。确认无需重启应用即可生效。+ 6. 切到直连再切回系统。确认无需重启应用即可生效。再选回自定义,确认第 3 步的 URL 与绕过列表原样回来(系统/直连期间它们保留在 `AppSettings.networkProxy` 里)。- **预期**:自定义覆盖模型请求、市场、更新、插件 `net.fetch` 和内置浏览器。工作区 Bash 的 `env` 看不到该设置写入的 `HTTP_PROXY` / `ALL_PROXY`。OAuth 仍走系统浏览器。`file:` / `ftp:`、SOCKS4 以及百分号编码错误的认证信息均被拒绝。带账号密码的 HTTP / SOCKS5 测试与应用不再报 `net::ERR_NO_SUPPORTED_PROXIES`(issue #490)。无协议/存储版本升级。- **链接规格**:`04-ux/06-settings-ia.md`、`03-runtime/07-process-model.md`、ADR 0177、D340- **验收**:B(设置)、F(供应商)、安全diff --git a/packages/shared/src/network-proxy.test.ts b/packages/shared/src/network-proxy.test.tsindex ca05ebf03..31b15b028 100644--- a/packages/shared/src/network-proxy.test.ts+++ b/packages/shared/src/network-proxy.test.ts@@ -66,14 +66,32 @@ describe("parseProxyUrl", () => {});describe("validateNetworkProxy", () => {- it("defaults unknown values to system and drops custom URL for non-custom modes", () => {+ it("defaults unknown values to system and keeps the URL a mode switch restores", () => {expect(validateNetworkProxy(undefined)).toEqual({ok: true,value: { mode: "system" },});- expect(validateNetworkProxy({ mode: "direct", url: "socks5://127.0.0.1:1080" })).toEqual({+ // System and Direct remember the custom URL and bypass; only `mode`+ // decides what is in effect (issue #1541).+ expect(+ validateNetworkProxy({+ mode: "direct",+ url: " socks5://127.0.0.1:7891 ",+ bypass: " localhost ",+ }),+ ).toEqual({ok: true,- value: { mode: "direct" },+ value: {+ mode: "direct",+ url: "socks5://127.0.0.1:7891",+ bypass: "localhost",+ },+ });+ // A URL that cannot describe a proxy is dropped, not refused: it must not+ // block the mode switch itself.+ expect(validateNetworkProxy({ mode: "system", url: "not-a-proxy" })).toEqual({+ ok: true,+ value: { mode: "system" },});});it("drops the retired fake-IP key from a stored proxy", () => {@@ -98,6 +116,48 @@ describe("validateNetworkProxy", () => {value: { mode: "custom", url: "socks5://127.0.0.1:1080" },});});++ it("restores the custom proxy after a detour through system mode", () => {+ // Every step is what `settings.set` validates, so this is the stored blob.+ const saved = validateNetworkProxy({+ mode: "custom",+ url: "socks5://127.0.0.1:7891",+ bypass: "localhost,10.8.0.0/24",+ });+ if (!saved.ok) throw new Error(saved.error);+ let stored = saved.value;++ // NetworkProxySection.chooseMode("system") carries the values along.+ const system = validateNetworkProxy({+ mode: "system",+ url: stored.url,+ bypass: stored.bypass,+ });+ if (!system.ok) throw new Error(system.error);+ stored = system.value;+ expect(stored).toEqual({+ mode: "system",+ url: "socks5://127.0.0.1:7891",+ bypass: "localhost,10.8.0.0/24",+ });++ // Choosing Custom again rebuilds it from what the settings still hold,+ // instead of the built-in default the fields would otherwise fall back to.+ expect(+ validateNetworkProxy({+ mode: "custom",+ url: stored.url,+ bypass: stored.bypass,+ }),+ ).toEqual({+ ok: true,+ value: {+ mode: "custom",+ url: "socks5://127.0.0.1:7891",+ bypass: "localhost,10.8.0.0/24",+ },+ });+ });});describe("chromium and env projections", () => {diff --git a/packages/shared/src/network-proxy.ts b/packages/shared/src/network-proxy.tsindex 016162a7a..db8489a2a 100644--- a/packages/shared/src/network-proxy.ts+++ b/packages/shared/src/network-proxy.ts@@ -43,11 +43,19 @@ export const PROXY_ENV_KEYS = [export type NetworkProxySettings = {mode: NetworkProxyMode;- /** Required when `mode` is `custom`. Canonical proxy URL. */+ /**+ * Canonical proxy URL. Required when `mode` is `custom`.+ *+ * System and Direct keep it too: `mode` decides what is in effect, and the+ * URL the user configured is remembered so the Custom control restores their+ * proxy instead of the built-in default (issue #1541). Nothing applies it+ * while another mode is selected.+ */url?: string;/*** Comma-separated bypass list. Absent uses- * {@link DEFAULT_NETWORK_PROXY_BYPASS} for custom mode.+ * {@link DEFAULT_NETWORK_PROXY_BYPASS} for custom mode, and kept across+ * modes like `url`.*/bypass?: string;};@@ -200,7 +208,15 @@ export function validateNetworkProxy(): { ok: true; value: NetworkProxySettings } | { ok: false; error: string } {const settings = normalizeNetworkProxy(value);if (settings.mode !== "custom") {+ // System and Direct keep the URL and bypass the user configured. `mode`+ // decides what applies, and remembering those values is what lets the+ // Custom control come back with their own proxy (issue #1541). A URL that+ // cannot describe a proxy is dropped rather than refused: it is not what+ // this write is about, and rejecting it would block the mode switch.const next: NetworkProxySettings = { mode: settings.mode };+ const parsed = settings.url ? parseProxyUrl(settings.url) : null;+ if (parsed?.ok) next.url = parsed.value.href;+ if (settings.bypass?.trim()) next.bypass = settings.bypass.trim();return { ok: true, value: next };}const parsed = parseProxyUrl(settings.url ?? "");