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(desktop): restore additive CA semantics for the macOS agent sidecar
yexisue8f126c290b9
diff --git a/apps/desktop/electron/main/agent-sidecar.ts b/apps/desktop/electron/main/agent-sidecar.tsindex d30a403c3..c22befd4c 100644--- a/apps/desktop/electron/main/agent-sidecar.ts+++ b/apps/desktop/electron/main/agent-sidecar.ts@@ -52,9 +52,19 @@ export class AgentSidecar extends RuntimeAgentSidecar {super({launch: {command: process.execPath,- // Electron 43's Node supports the OS trust store. Keep bundled roots- // and inherited NODE_EXTRA_CA_CERTS; never bypass TLS verification.- args: ["--max-old-space-size=2048", "--use-system-ca", resolveSidecarEntry()],+ // Keep the OS trust store available to the sidecar. On macOS the+ // Electron 43 build applies `--use-system-ca` by replacing the+ // bundled roots instead of adding them (its keychain enumeration+ // misses public anchors like GlobalSign Root CA - R3, issue #1187),+ // so there the sidecar merges bundled + system + extra CAs itself+ // (agent-runtime system-ca) and this launcher omits the flag. On+ // Windows and Linux the flag behaves as documented and stays.+ // Never bypass TLS verification.+ args: [+ "--max-old-space-size=2048",+ ...(process.platform === "darwin" ? [] : ["--use-system-ca"]),+ resolveSidecarEntry(),+ ],env: {...process.env,ELECTRON_RUN_AS_NODE: "1",diff --git a/packages/agent-runtime/src/sidecar.ts b/packages/agent-runtime/src/sidecar.tsindex e2b16309a..e08e79483 100644--- a/packages/agent-runtime/src/sidecar.ts+++ b/packages/agent-runtime/src/sidecar.ts@@ -27,6 +27,7 @@ import {} from "./sidecar-config.js";import { matchesExpectedTurnId } from "./turn-target.js";import { applyNodeNetworkProxy } from "./node-proxy.js";+import { applyAdditiveDefaultCaCertificates } from "./system-ca.js";import { NATIVE_PI_SESSION_PREFIX, nativePiService } from "./native-pi-session.js";import {isCommandShellOption,@@ -627,4 +628,7 @@ if (bootProxy) {// Invalid boot payload is ignored; sidecar.configure will replace it.}}+// The default TLS context is configured before any provider request can be+// issued, so the merged CA set covers every transport this sidecar builds.+applyAdditiveDefaultCaCertificates();process.stderr.write("[agent-sidecar] ready (host-proxy mode)\n");diff --git a/packages/agent-runtime/src/system-ca.test.ts b/packages/agent-runtime/src/system-ca.test.tsnew file mode 100644index 000000000..f2119849f--- /dev/null+++ b/packages/agent-runtime/src/system-ca.test.ts@@ -0,0 +1,30 @@+import { X509Certificate } from "node:crypto";+import * as tls from "node:tls";+import { expect, it } from "vitest";+import { applyAdditiveDefaultCaCertificates } from "./system-ca.js";++// `setDefaultCACertificates` re-serializes its input, so later reads return+// strings that differ in encoding whitespace; identity is the certificate+// content, compared by SHA-256 fingerprint.+function fingerprints(certs: readonly string[]): Set<string> {+ return new Set(certs.map((cert) => new X509Certificate(cert).fingerprint256));+}++it("applyAdditiveDefaultCaCertificates keeps pre-existing default roots", () => {+ const before = fingerprints(tls.getCACertificates("default"));+ applyAdditiveDefaultCaCertificates();+ const after = fingerprints(tls.getCACertificates("default"));+ // The default set can only grow: every pre-existing root (bundled, extra,+ // or a flag-added system root) is preserved.+ for (const fingerprint of before) {+ expect(after.has(fingerprint)).toBe(true);+ }+});++it("applyAdditiveDefaultCaCertificates is idempotent", () => {+ applyAdditiveDefaultCaCertificates();+ const once = fingerprints(tls.getCACertificates("default")).size;+ applyAdditiveDefaultCaCertificates();+ const twice = fingerprints(tls.getCACertificates("default")).size;+ expect(twice).toBe(once);+});diff --git a/packages/agent-runtime/src/system-ca.ts b/packages/agent-runtime/src/system-ca.tsnew file mode 100644index 000000000..6dcebe3fe--- /dev/null+++ b/packages/agent-runtime/src/system-ca.ts@@ -0,0 +1,47 @@+import * as tls from "node:tls";++/**+ * Explicit, additive default CA set for the sidecar (#1187).+ *+ * `--use-system-ca` is documented as additive: bundled roots, plus the system+ * store, plus `NODE_EXTRA_CA_CERTS`. On the Electron 43 macOS build the flag+ * instead replaces the bundled Mozilla roots with the enumerated system set,+ * and that enumeration misses public anchors it should include — a chain+ * anchored at GlobalSign Root CA - R3 fails with `UNABLE_TO_GET_ISSUER_CERT`+ * while the same runtime without the flag verifies it. Homebrew's stock Node+ * 24 with the same flag verifies the same chain, so the divergence is in the+ * Electron build, not Node's contract.+ *+ * Reproducing the documented additive semantics here keeps every trust source+ * the app promised (ADR: sidecar uses the OS trust store): bundled roots stay,+ * locally installed inspection roots still enter through the system store,+ * and an inherited `NODE_EXTRA_CA_CERTS` still lands in the `extra` set.+ * Certificate chain, expiration and hostname validation are untouched — this+ * widens the trust set, it never disables verification.+ */+export function applyAdditiveDefaultCaCertificates(): void {+ if (typeof tls.setDefaultCACertificates !== "function") return;+ const bundled = tls.getCACertificates("bundled");+ const extra = tls.getCACertificates("extra");+ const system = tls.getCACertificates("system");+ if (system.length === 0) return;+ const seen = new Set(bundled.map((cert) => cert));+ const merged = [...bundled, ...extra.filter((cert) => !seen.has(cert))];+ for (const cert of system) {+ if (!seen.has(cert)) {+ seen.add(cert);+ merged.push(cert);+ }+ }+ try {+ tls.setDefaultCACertificates(merged);+ } catch (error) {+ // A rejection here leaves the runtime default (the flag's outcome) in+ // place; say so once on stderr instead of failing the sidecar.+ process.stderr.write(+ `[agent-sidecar] default CA merge failed: ${+ error instanceof Error ? error.message : String(error)+ }\n`,+ );+ }+}