From 3f8f3f925be038907ae4195e214eb661a92cfe97 Mon Sep 17 00:00:00 2001 From: wishforge Date: Mon, 9 Nov 2026 01:09:18 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Pass=20proxy=20settings=20to=20t?= =?UTF-8?q?he=20model=20CLI=20so=20gateways=20behind=20a=20proxy=20are=20r?= =?UTF-8?q?eachable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/runtime/src/providers/claude-ask.ts | 3 +++ packages/runtime/test/claude-ask.test.ts | 19 +++++++++++++++++++ scripts/local-services.mjs | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/providers/claude-ask.ts b/packages/runtime/src/providers/claude-ask.ts index 63ca6d3..616257b 100644 --- a/packages/runtime/src/providers/claude-ask.ts +++ b/packages/runtime/src/providers/claude-ask.ts @@ -3,6 +3,7 @@ import os from 'node:os'; import path from 'node:path'; import { executeCommand, type CommandExecutor } from '../process.js'; import { RuntimeError } from '../types.js'; +import { PROXY_VARIABLES } from '../sandbox.js'; import { localCredentialEnv } from './codebuddy.js'; /** @@ -67,6 +68,8 @@ export async function askClaude( env: { PATH: process.env.PATH, HOME: home, + // The host's egress proxy, if any: the model gateway may only be reachable through it. + ...Object.fromEntries(PROXY_VARIABLES.flatMap(key => (process.env[key] ? [[key, process.env[key]]] : []))), // The operator's settings only when this call signs in with the operator's login. ...(input.home ? await localCredentialEnv(input.home) : {}), ...modelEnv, diff --git a/packages/runtime/test/claude-ask.test.ts b/packages/runtime/test/claude-ask.test.ts index e270191..7caee44 100644 --- a/packages/runtime/test/claude-ask.test.ts +++ b/packages/runtime/test/claude-ask.test.ts @@ -46,6 +46,25 @@ describe('asking the local Claude CLI', () => { expect(seen!.env).not.toHaveProperty('WF_DEV_AUTH_TOKEN'); expect(existsSync(seen!.cwd!)).toBe(false); }); + it('carries the host egress proxy so a gateway behind it stays reachable', async () => { + const saved = { https: process.env.https_proxy, token: process.env.WF_DEV_AUTH_TOKEN }; + process.env.https_proxy = 'http://127.0.0.1:7890'; + process.env.WF_DEV_AUTH_TOKEN = 'must-not-leak'; + try { + let seen: Command | undefined; + await askClaude(input, async command => { + seen = command; + return { exitCode: 0, stdout: JSON.stringify({ structured_output: {} }), stderr: '', durationMs: 1 }; + }); + expect(seen!.env).toMatchObject({ https_proxy: 'http://127.0.0.1:7890' }); + expect(seen!.env).not.toHaveProperty('WF_DEV_AUTH_TOKEN'); + } finally { + if (saved.https === undefined) delete process.env.https_proxy; + else process.env.https_proxy = saved.https; + if (saved.token === undefined) delete process.env.WF_DEV_AUTH_TOKEN; + else process.env.WF_DEV_AUTH_TOKEN = saved.token; + } + }); it('passes a named model and server-held credential environment to the CLI', async () => { let seen: Command | undefined; await askClaude( diff --git a/scripts/local-services.mjs b/scripts/local-services.mjs index 645ca8a..ca3fb81 100644 --- a/scripts/local-services.mjs +++ b/scripts/local-services.mjs @@ -42,7 +42,20 @@ export function webListener(env = process.env) { const inherited = () => Object.fromEntries( - ['PATH', 'HOME', 'TMPDIR', 'LANG', 'TERM', 'HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY'] + // Proxy variables in both spellings: macOS proxy tools usually export the lowercase ones. + [ + 'PATH', + 'HOME', + 'TMPDIR', + 'LANG', + 'TERM', + 'HTTP_PROXY', + 'HTTPS_PROXY', + 'NO_PROXY', + 'http_proxy', + 'https_proxy', + 'no_proxy', + ] .filter(key => process.env[key]) .map(key => [key, process.env[key]]), );