fix(cliproxy): load remote config from config.yaml for proxy resolution

- Import loadOrCreateUnifiedConfig to access cliproxy_server settings
- Pass remote/local config to resolveProxyConfig() function
- Enables CLI to detect remote mode from user's config.yaml
This commit is contained in:
kaitranntt
2025-12-21 04:13:57 -05:00
parent d0599e8d2c
commit a2d01bcc8a
+32 -2
View File
@@ -51,6 +51,7 @@ import {
import { registerSession, unregisterSession, cleanupOrphanedSessions } from './session-tracker'; import { registerSession, unregisterSession, cleanupOrphanedSessions } from './session-tracker';
import { detectRunningProxy, waitForProxyHealthy, reclaimOrphanedProxy } from './proxy-detector'; import { detectRunningProxy, waitForProxyHealthy, reclaimOrphanedProxy } from './proxy-detector';
import { withStartupLock } from './startup-lock'; import { withStartupLock } from './startup-lock';
import { loadOrCreateUnifiedConfig } from '../config/unified-config-loader';
/** Default executor configuration */ /** Default executor configuration */
const DEFAULT_CONFIG: ExecutorConfig = { const DEFAULT_CONFIG: ExecutorConfig = {
@@ -126,7 +127,25 @@ export async function execClaudeWithCLIProxy(
// 0. Resolve proxy configuration (CLI > ENV > config.yaml > defaults) // 0. Resolve proxy configuration (CLI > ENV > config.yaml > defaults)
// This filters proxy flags from args and returns resolved config // This filters proxy flags from args and returns resolved config
const { config: proxyConfig, remainingArgs: argsWithoutProxy } = resolveProxyConfig(args); const unifiedConfig = loadOrCreateUnifiedConfig();
const cliproxyServerConfig = unifiedConfig.cliproxy_server;
const { config: proxyConfig, remainingArgs: argsWithoutProxy } = resolveProxyConfig(args, {
remote: cliproxyServerConfig?.remote
? {
enabled: cliproxyServerConfig.remote.enabled,
host: cliproxyServerConfig.remote.host,
port: cliproxyServerConfig.remote.port,
protocol: cliproxyServerConfig.remote.protocol,
auth_token: cliproxyServerConfig.remote.auth_token,
}
: undefined,
local: cliproxyServerConfig?.local
? {
port: cliproxyServerConfig.local.port,
auto_start: cliproxyServerConfig.local.auto_start,
}
: undefined,
});
// Use resolved port from proxy config (overrides ExecutorConfig) // Use resolved port from proxy config (overrides ExecutorConfig)
if (proxyConfig.port !== CLIPROXY_DEFAULT_PORT) { if (proxyConfig.port !== CLIPROXY_DEFAULT_PORT) {
@@ -516,6 +535,17 @@ export async function execClaudeWithCLIProxy(
// 7. Execute Claude CLI with proxied environment // 7. Execute Claude CLI with proxied environment
// Use remote or local env vars based on mode // Use remote or local env vars based on mode
// When remote is configured (even if using local), pass config for URL rewriting
const remoteRewriteConfig =
proxyConfig.mode === 'remote' && proxyConfig.host
? {
host: proxyConfig.host,
port: proxyConfig.port,
protocol: proxyConfig.protocol,
authToken: proxyConfig.authToken,
}
: undefined;
const envVars = useRemoteProxy const envVars = useRemoteProxy
? getRemoteEnvVars(provider, { ? getRemoteEnvVars(provider, {
host: proxyConfig.host ?? 'localhost', host: proxyConfig.host ?? 'localhost',
@@ -523,7 +553,7 @@ export async function execClaudeWithCLIProxy(
protocol: proxyConfig.protocol, protocol: proxyConfig.protocol,
authToken: proxyConfig.authToken, authToken: proxyConfig.authToken,
}) })
: getEffectiveEnvVars(provider, cfg.port, cfg.customSettingsPath); : getEffectiveEnvVars(provider, cfg.port, cfg.customSettingsPath, remoteRewriteConfig);
const webSearchEnv = getWebSearchHookEnv(); const webSearchEnv = getWebSearchHookEnv();
const env = { const env = {
...process.env, ...process.env,