From e58afd77905d40ce4526a85e4f59cea4fc33ff50 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Tue, 30 Dec 2025 12:42:54 -0500 Subject: [PATCH] fix(cliproxy): pass variant port to executor for isolation Variants configured with dedicated ports (8318-8417) were not using their assigned port. The executor always defaulted to 8317. Changes: - Add port field to ProfileDetectionResult interface - Pass variant.port from profile-detector to ccs.ts - Forward port to execClaudeWithCLIProxy options - Update executor priority: CLI flags > variant port > config.yaml > default Closes #228 --- src/auth/profile-detector.ts | 3 +++ src/ccs.ts | 6 +++++- src/cliproxy/cliproxy-executor.ts | 12 +++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/auth/profile-detector.ts b/src/auth/profile-detector.ts index 16accd5f..ad6d4c3f 100644 --- a/src/auth/profile-detector.ts +++ b/src/auth/profile-detector.ts @@ -39,6 +39,8 @@ export interface ProfileDetectionResult { message?: string; /** For cliproxy variants: the underlying provider (gemini, codex, agy, qwen) */ provider?: CLIProxyProfileName; + /** For cliproxy variants: dedicated port for isolation (8318-8417) */ + port?: number; /** For unified config profiles: merged env vars (config + secrets) */ env?: Record; /** For copilot profile: the copilot config */ @@ -250,6 +252,7 @@ class ProfileDetector { name: profileName, provider: variant.provider as CLIProxyProfileName, settingsPath: variant.settings, + port: variant.port, }; } diff --git a/src/ccs.ts b/src/ccs.ts index dc2df697..fc1d1d83 100644 --- a/src/ccs.ts +++ b/src/ccs.ts @@ -511,7 +511,11 @@ async function main(): Promise { // CLIPROXY FLOW: OAuth-based profiles (gemini, codex, agy, qwen) or user-defined variants const provider = profileInfo.provider || (profileInfo.name as CLIProxyProvider); const customSettingsPath = profileInfo.settingsPath; // undefined for hardcoded profiles - await execClaudeWithCLIProxy(claudeCli, provider, remainingArgs, { customSettingsPath }); + const variantPort = profileInfo.port; // variant-specific port for isolation + await execClaudeWithCLIProxy(claudeCli, provider, remainingArgs, { + customSettingsPath, + port: variantPort, + }); } else if (profileInfo.type === 'copilot') { // COPILOT FLOW: GitHub Copilot subscription via copilot-api proxy const { executeCopilotProfile } = await import('./copilot'); diff --git a/src/cliproxy/cliproxy-executor.ts b/src/cliproxy/cliproxy-executor.ts index f8ebbf20..d23e3506 100644 --- a/src/cliproxy/cliproxy-executor.ts +++ b/src/cliproxy/cliproxy-executor.ts @@ -154,7 +154,17 @@ export async function execClaudeWithCLIProxy( }); // Use resolved port from proxy config (overrides ExecutorConfig) - if (proxyConfig.port !== CLIPROXY_DEFAULT_PORT) { + // Priority: CLI flags > Variant port (cfg.port) > config.yaml > default + // cfg.port is set if variant has dedicated port; proxyConfig.port comes from CLI/ENV/config.yaml + if (cfg.port && cfg.port !== CLIPROXY_DEFAULT_PORT) { + // Variant port already set via config param - keep it (highest priority after CLI flags) + // CLI flags would have been parsed in resolveProxyConfig and set proxyConfig.port + // So if proxyConfig.port differs from default AND cfg.port differs, CLI wins + if (proxyConfig.port !== CLIPROXY_DEFAULT_PORT) { + cfg.port = proxyConfig.port; // CLI/ENV override variant port + } + // else: keep cfg.port (variant port) + } else if (proxyConfig.port !== CLIPROXY_DEFAULT_PORT) { cfg.port = proxyConfig.port; }