Skip to content

Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy

Rust

config: move override summary helpers

Raine Virtacbfc09aada9c
diff --git a/src/cli.ts b/src/cli.ts
index b3c3b00..a09af7b 100755
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -3,16 +3,10 @@ import { startServer } from "./server.ts";
import { createLogger, logFile } from "./log.ts";
import {
port as configPort,
- getConfig,
- aliasProvider as configAliasProvider,
- codexTransport,
- codexPreviousResponseId,
- cursorBaseUrl,
- cursorClientVersion,
+ configPath,
+ configOverrideSummaryLines,
} from "./config.ts";
-import { configDir } from "./paths.ts";
import { existsSync } from "node:fs";
-import { join } from "node:path";
import {
allSupportedModels,
getProvider,
@@ -126,72 +120,12 @@ function printSupportedModels(): void {
}
function printConfigSummary(): void {
- const cfg = getConfig();
- const fromFile = cfg.file;
- const overrides: string[] = [];
-
- const configPath = join(configDir(), "config.json");
- if (existsSync(configPath)) {
- console.log(`Config: ${configPath}`);
+ const path = configPath();
+ if (existsSync(path)) {
+ console.log(`Config: ${path}`);
}
- if (cfg.env.CCP_CODEX_ORIGINATOR) overrides.push("CCP_CODEX_ORIGINATOR (env)");
- else if (fromFile.codex?.originator) overrides.push("codex.originator (config)");
-
- if (cfg.env.CCP_CODEX_USER_AGENT) overrides.push("CCP_CODEX_USER_AGENT (env)");
- else if (cfg.env.CCP_USER_AGENT) overrides.push("CCP_USER_AGENT (env)");
- else if (fromFile.codex?.userAgent) overrides.push("codex.userAgent (config)");
-
- if (cfg.env.CCP_KIMI_USER_AGENT) overrides.push("CCP_KIMI_USER_AGENT (env)");
- else if (fromFile.kimi?.userAgent) overrides.push("kimi.userAgent (config)");
-
- if (cfg.env.CCP_CODEX_MODEL) overrides.push("CCP_CODEX_MODEL (env)");
- else if (fromFile.codex?.model) overrides.push("codex.model (config)");
-
- if (cfg.env.CCP_CODEX_EFFORT) overrides.push("CCP_CODEX_EFFORT (env)");
- else if (fromFile.codex?.effort) overrides.push("codex.effort (config)");
-
- if (cfg.env.CCP_CODEX_SERVICE_TIER) overrides.push("CCP_CODEX_SERVICE_TIER (env)");
- else if (fromFile.codex?.serviceTier) overrides.push("codex.serviceTier (config)");
-
- if (cfg.env.CCP_CODEX_BASE_URL) overrides.push("CCP_CODEX_BASE_URL (env)");
- else if (fromFile.codex?.baseUrl) overrides.push("codex.baseUrl (config)");
-
- if (cfg.env.CCP_CODEX_TRANSPORT) overrides.push(`CCP_CODEX_TRANSPORT=${codexTransport()} (env)`);
- else if (fromFile.codex?.transport)
- overrides.push(`codex.transport=${fromFile.codex.transport} (config)`);
-
- if (cfg.env.CCP_CODEX_PREVIOUS_RESPONSE_ID !== undefined)
- overrides.push(`CCP_CODEX_PREVIOUS_RESPONSE_ID=${codexPreviousResponseId()} (env)`);
- else if (fromFile.codex?.previousResponseId !== undefined)
- overrides.push(`codex.previousResponseId=${fromFile.codex.previousResponseId} (config)`);
-
- if (cfg.env.CCP_ALIAS_PROVIDER)
- overrides.push(`CCP_ALIAS_PROVIDER=${configAliasProvider()} (env)`);
- else if (fromFile.aliasProvider)
- overrides.push(`aliasProvider=${fromFile.aliasProvider} (config)`);
-
- if (cfg.env.CCP_LOG_VERBOSE !== undefined) overrides.push("CCP_LOG_VERBOSE (env)");
- else if (fromFile.log?.verbose) overrides.push("log.verbose (config)");
-
- if (cfg.env.CCP_LOG_STDERR !== undefined) overrides.push("CCP_LOG_STDERR (env)");
- else if (fromFile.log?.stderr) overrides.push("log.stderr (config)");
-
- if (cfg.env.CCP_KIMI_OAUTH_HOST) overrides.push("CCP_KIMI_OAUTH_HOST (env)");
- else if (fromFile.kimi?.oauthHost) overrides.push("kimi.oauthHost (config)");
-
- if (cfg.env.CCP_KIMI_BASE_URL) overrides.push("CCP_KIMI_BASE_URL (env)");
- else if (fromFile.kimi?.baseUrl) overrides.push("kimi.baseUrl (config)");
-
- if (cfg.env.CCP_CURSOR_BASE_URL) overrides.push(`CCP_CURSOR_BASE_URL=${cursorBaseUrl()} (env)`);
- else if (fromFile.cursor?.baseUrl) overrides.push("cursor.baseUrl (config)");
-
- if (cfg.env.CCP_CURSOR_CLIENT_VERSION)
- overrides.push(`CCP_CURSOR_CLIENT_VERSION=${cursorClientVersion()} (env)`);
- else if (fromFile.cursor?.clientVersion) overrides.push("cursor.clientVersion (config)");
-
- if (cfg.env.CCP_CURSOR_AGENT_BUNDLE) overrides.push("CCP_CURSOR_AGENT_BUNDLE (env)");
- else if (fromFile.cursor?.agentBundle) overrides.push("cursor.agentBundle (config)");
+ const overrides = configOverrideSummaryLines();
if (overrides.length > 0) {
console.log("Overrides:");
diff --git a/src/config.test.ts b/src/config.test.ts
index 587ebe6..6fda353 100644
--- a/src/config.test.ts
+++ b/src/config.test.ts
@@ -4,6 +4,9 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import {
loadConfig,
+ getConfig,
+ configPath as resolveConfigPath,
+ configOverrideSummaryLines,
port,
codexOriginator,
codexUserAgent,
@@ -317,3 +320,182 @@ describe("malformed config", () => {
expect(port()).toBe(18765);
});
});
+
+describe("config summary", () => {
+ it("resolves config.json under the configured directory", () => {
+ expect(resolveConfigPath("/tmp/ccp-config")).toBe(join("/tmp/ccp-config", "config.json"));
+ });
+
+ it("returns no override lines for defaults", () => {
+ setEnv({});
+ expect(configOverrideSummaryLines(getConfig())).toEqual([]);
+ });
+
+ it("summarizes file override lines with existing labels", () => {
+ writeFileSync(
+ configPath,
+ JSON.stringify({
+ codex: {
+ originator: "file-originator",
+ userAgent: "file-codex-ua",
+ model: "gpt-5.2",
+ effort: "high",
+ serviceTier: "flex",
+ baseUrl: "https://codex-file.example.com",
+ transport: "http",
+ previousResponseId: false,
+ },
+ kimi: {
+ userAgent: "file-kimi-ua",
+ oauthHost: "https://kimi-auth-file.example.com",
+ baseUrl: "https://kimi-file.example.com",
+ },
+ cursor: {
+ baseUrl: "https://cursor-file.example.com",
+ clientVersion: "cli-file",
+ agentBundle: "/file/index.js",
+ },
+ aliasProvider: "kimi",
+ log: { verbose: true, stderr: true },
+ }),
+ );
+ setEnv({});
+
+ expect(configOverrideSummaryLines(getConfig())).toEqual([
+ "codex.originator (config)",
+ "codex.userAgent (config)",
+ "kimi.userAgent (config)",
+ "codex.model (config)",
+ "codex.effort (config)",
+ "codex.serviceTier (config)",
+ "codex.baseUrl (config)",
+ "codex.transport=http (config)",
+ "codex.previousResponseId=false (config)",
+ "aliasProvider=kimi (config)",
+ "log.verbose (config)",
+ "log.stderr (config)",
+ "kimi.oauthHost (config)",
+ "kimi.baseUrl (config)",
+ "cursor.baseUrl (config)",
+ "cursor.clientVersion (config)",
+ "cursor.agentBundle (config)",
+ ]);
+ });
+
+ it("summarizes env override lines with current precedence and display values", () => {
+ writeFileSync(
+ configPath,
+ JSON.stringify({
+ codex: {
+ originator: "file-originator",
+ userAgent: "file-codex-ua",
+ model: "gpt-5.2",
+ effort: "high",
+ serviceTier: "flex",
+ baseUrl: "https://codex-file.example.com",
+ transport: "http",
+ previousResponseId: false,
+ },
+ kimi: {
+ userAgent: "file-kimi-ua",
+ oauthHost: "https://kimi-auth-file.example.com",
+ baseUrl: "https://kimi-file.example.com",
+ },
+ cursor: {
+ baseUrl: "https://cursor-file.example.com",
+ clientVersion: "cli-file",
+ agentBundle: "/file/index.js",
+ },
+ aliasProvider: "kimi",
+ log: { verbose: true, stderr: false },
+ }),
+ );
+ setEnv({
+ CCP_CODEX_ORIGINATOR: "env-originator",
+ CCP_CODEX_USER_AGENT: "env-codex-ua",
+ CCP_KIMI_USER_AGENT: "env-kimi-ua",
+ CCP_CODEX_MODEL: "gpt-5.5",
+ CCP_CODEX_EFFORT: "medium",
+ CCP_CODEX_SERVICE_TIER: "fast",
+ CCP_CODEX_BASE_URL: "https://codex-env.example.com",
+ CCP_CODEX_TRANSPORT: "auto",
+ CCP_CODEX_PREVIOUS_RESPONSE_ID: "true",
+ CCP_ALIAS_PROVIDER: "codex",
+ CCP_LOG_VERBOSE: "0",
+ CCP_LOG_STDERR: "",
+ CCP_KIMI_OAUTH_HOST: "https://kimi-auth-env.example.com",
+ CCP_KIMI_BASE_URL: "https://kimi-env.example.com",
+ CCP_CURSOR_BASE_URL: "https://cursor-env.example.com",
+ CCP_CURSOR_CLIENT_VERSION: "cli-env",
+ CCP_CURSOR_AGENT_BUNDLE: "/env/index.js",
+ });
+
+ expect(configOverrideSummaryLines(getConfig())).toEqual([
+ "CCP_CODEX_ORIGINATOR (env)",
+ "CCP_CODEX_USER_AGENT (env)",
+ "CCP_KIMI_USER_AGENT (env)",
+ "CCP_CODEX_MODEL (env)",
+ "CCP_CODEX_EFFORT (env)",
+ "CCP_CODEX_SERVICE_TIER (env)",
+ "CCP_CODEX_BASE_URL (env)",
+ "CCP_CODEX_TRANSPORT=auto (env)",
+ "CCP_CODEX_PREVIOUS_RESPONSE_ID=true (env)",
+ "CCP_ALIAS_PROVIDER=codex (env)",
+ "CCP_LOG_VERBOSE (env)",
+ "CCP_LOG_STDERR (env)",
+ "CCP_KIMI_OAUTH_HOST (env)",
+ "CCP_KIMI_BASE_URL (env)",
+ "CCP_CURSOR_BASE_URL=https://cursor-env.example.com (env)",
+ "CCP_CURSOR_CLIENT_VERSION=cli-env (env)",
+ "CCP_CURSOR_AGENT_BUNDLE (env)",
+ ]);
+ });
+
+ it("preserves current empty-string display semantics", () => {
+ writeFileSync(
+ configPath,
+ JSON.stringify({
+ codex: { model: "gpt-5.2", transport: "http", previousResponseId: true },
+ aliasProvider: "kimi",
+ cursor: { baseUrl: "https://cursor-file.example.com" },
+ }),
+ );
+ setEnv({
+ CCP_CODEX_MODEL: "",
+ CCP_CODEX_TRANSPORT: "",
+ CCP_CODEX_PREVIOUS_RESPONSE_ID: "",
+ CCP_ALIAS_PROVIDER: "",
+ CCP_LOG_STDERR: "",
+ CCP_CURSOR_BASE_URL: "",
+ });
+
+ expect(configOverrideSummaryLines(getConfig())).toEqual([
+ "codex.model (config)",
+ "codex.transport=http (config)",
+ "CCP_CODEX_PREVIOUS_RESPONSE_ID=true (env)",
+ "aliasProvider=kimi (config)",
+ "CCP_LOG_STDERR (env)",
+ "cursor.baseUrl (config)",
+ ]);
+ });
+
+ it("summarizes generic CCP_USER_AGENT fallback once in the existing position", () => {
+ setEnv({ CCP_USER_AGENT: "generic-env" });
+
+ expect(configOverrideSummaryLines(getConfig())).toEqual(["CCP_USER_AGENT (env)"]);
+ });
+
+ it("uses the supplied loaded config instead of the module cache", () => {
+ setEnv({ CCP_CODEX_TRANSPORT: "http", CCP_CURSOR_CLIENT_VERSION: "cached" });
+
+ const supplied = loadConfig({
+ configPath,
+ env: { CCP_CODEX_TRANSPORT: "auto", CCP_CURSOR_CLIENT_VERSION: "supplied" },
+ });
+
+ expect(configOverrideSummaryLines(supplied)).toEqual([
+ "CCP_CODEX_TRANSPORT=auto (env)",
+ "CCP_CURSOR_CLIENT_VERSION=supplied (env)",
+ ]);
+ });
+});
diff --git a/src/config.ts b/src/config.ts
index 96c8191..6293919 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -41,7 +41,7 @@ export interface FileConfig {
};
}
-interface LoadedConfig {
+export interface LoadedConfig {
file: FileConfig;
env: NodeJS.ProcessEnv;
}
@@ -54,6 +54,10 @@ interface LoadOptions {
let cached: LoadedConfig | undefined;
+export function configPath(configDirectory = configDir()): string {
+ return join(configDirectory, "config.json");
+}
+
// Most env-var consumers historically used `??` semantics — empty string is
// a real value that wins. Only CCP_CODEX_MODEL and CCP_CODEX_EFFORT had
// explicit empty-string-as-unset handling in the legacy code, so only those
@@ -186,7 +190,7 @@ export function loadConfig(opts: LoadOptions = {}): LoadedConfig {
return cached;
}
const env = opts.env ?? process.env;
- const path = opts.configPath ?? join(configDir(), "config.json");
+ const path = opts.configPath ?? configPath();
let file: FileConfig = {};
try {
const raw = readFileSync(path, "utf8");
@@ -268,30 +272,15 @@ export function codexBaseUrl(defaultValue: string): string {
}
export function codexTransport(): CodexTransport {
- const c = getConfig();
- return (
- parseCodexTransport("CCP_CODEX_TRANSPORT", emptyOrUnset(c.env.CCP_CODEX_TRANSPORT)) ??
- c.file.codex?.transport ??
- "websocket"
- );
+ return resolvedCodexTransport(getConfig());
}
export function codexPreviousResponseId(): boolean {
- const c = getConfig();
- return (
- parseBooleanEnv(c.env.CCP_CODEX_PREVIOUS_RESPONSE_ID) ??
- c.file.codex?.previousResponseId ??
- false
- );
+ return resolvedCodexPreviousResponseId(getConfig());
}
export function aliasProvider(): AliasProvider {
- const c = getConfig();
- return (
- parseAliasProvider("CCP_ALIAS_PROVIDER", emptyOrUnset(c.env.CCP_ALIAS_PROVIDER)) ??
- c.file.aliasProvider ??
- "codex"
- );
+ return resolvedAliasProvider(getConfig());
}
export function kimiUserAgent(defaultValue: string): string {
@@ -321,6 +310,103 @@ export function cursorClientVersion(): string {
return c.env.CCP_CURSOR_CLIENT_VERSION ?? c.file.cursor?.clientVersion ?? "cli-2026.06.04-5fd875e";
}
+function resolvedCodexTransport(c: LoadedConfig): CodexTransport {
+ return (
+ parseCodexTransport("CCP_CODEX_TRANSPORT", emptyOrUnset(c.env.CCP_CODEX_TRANSPORT)) ??
+ c.file.codex?.transport ??
+ "websocket"
+ );
+}
+
+function resolvedCodexPreviousResponseId(c: LoadedConfig): boolean {
+ return (
+ parseBooleanEnv(c.env.CCP_CODEX_PREVIOUS_RESPONSE_ID) ??
+ c.file.codex?.previousResponseId ??
+ false
+ );
+}
+
+function resolvedAliasProvider(c: LoadedConfig): AliasProvider {
+ return (
+ parseAliasProvider("CCP_ALIAS_PROVIDER", emptyOrUnset(c.env.CCP_ALIAS_PROVIDER)) ??
+ c.file.aliasProvider ??
+ "codex"
+ );
+}
+
+function resolvedCursorBaseUrl(c: LoadedConfig): string {
+ return c.env.CCP_CURSOR_BASE_URL ?? c.file.cursor?.baseUrl ?? "https://api2.cursor.sh";
+}
+
+function resolvedCursorClientVersion(c: LoadedConfig): string {
+ return c.env.CCP_CURSOR_CLIENT_VERSION ?? c.file.cursor?.clientVersion ?? "cli-2026.06.04-5fd875e";
+}
+
+export function configOverrideSummaryLines(cfg: LoadedConfig = getConfig()): string[] {
+ const fromFile = cfg.file;
+ const overrides: string[] = [];
+
+ if (cfg.env.CCP_CODEX_ORIGINATOR) overrides.push("CCP_CODEX_ORIGINATOR (env)");
+ else if (fromFile.codex?.originator) overrides.push("codex.originator (config)");
+
+ if (cfg.env.CCP_CODEX_USER_AGENT) overrides.push("CCP_CODEX_USER_AGENT (env)");
+ else if (cfg.env.CCP_USER_AGENT) overrides.push("CCP_USER_AGENT (env)");
+ else if (fromFile.codex?.userAgent) overrides.push("codex.userAgent (config)");
+
+ if (cfg.env.CCP_KIMI_USER_AGENT) overrides.push("CCP_KIMI_USER_AGENT (env)");
+ else if (fromFile.kimi?.userAgent) overrides.push("kimi.userAgent (config)");
+
+ if (cfg.env.CCP_CODEX_MODEL) overrides.push("CCP_CODEX_MODEL (env)");
+ else if (fromFile.codex?.model) overrides.push("codex.model (config)");
+
+ if (cfg.env.CCP_CODEX_EFFORT) overrides.push("CCP_CODEX_EFFORT (env)");
+ else if (fromFile.codex?.effort) overrides.push("codex.effort (config)");
+
+ if (cfg.env.CCP_CODEX_SERVICE_TIER) overrides.push("CCP_CODEX_SERVICE_TIER (env)");
+ else if (fromFile.codex?.serviceTier) overrides.push("codex.serviceTier (config)");
+
+ if (cfg.env.CCP_CODEX_BASE_URL) overrides.push("CCP_CODEX_BASE_URL (env)");
+ else if (fromFile.codex?.baseUrl) overrides.push("codex.baseUrl (config)");
+
+ if (cfg.env.CCP_CODEX_TRANSPORT)
+ overrides.push(`CCP_CODEX_TRANSPORT=${resolvedCodexTransport(cfg)} (env)`);
+ else if (fromFile.codex?.transport)
+ overrides.push(`codex.transport=${fromFile.codex.transport} (config)`);
+
+ if (cfg.env.CCP_CODEX_PREVIOUS_RESPONSE_ID !== undefined)
+ overrides.push(`CCP_CODEX_PREVIOUS_RESPONSE_ID=${resolvedCodexPreviousResponseId(cfg)} (env)`);
+ else if (fromFile.codex?.previousResponseId !== undefined)
+ overrides.push(`codex.previousResponseId=${fromFile.codex.previousResponseId} (config)`);
+
+ if (cfg.env.CCP_ALIAS_PROVIDER) overrides.push(`CCP_ALIAS_PROVIDER=${resolvedAliasProvider(cfg)} (env)`);
+ else if (fromFile.aliasProvider) overrides.push(`aliasProvider=${fromFile.aliasProvider} (config)`);
+
+ if (cfg.env.CCP_LOG_VERBOSE !== undefined) overrides.push("CCP_LOG_VERBOSE (env)");
+ else if (fromFile.log?.verbose) overrides.push("log.verbose (config)");
+
+ if (cfg.env.CCP_LOG_STDERR !== undefined) overrides.push("CCP_LOG_STDERR (env)");
+ else if (fromFile.log?.stderr) overrides.push("log.stderr (config)");
+
+ if (cfg.env.CCP_KIMI_OAUTH_HOST) overrides.push("CCP_KIMI_OAUTH_HOST (env)");
+ else if (fromFile.kimi?.oauthHost) overrides.push("kimi.oauthHost (config)");
+
+ if (cfg.env.CCP_KIMI_BASE_URL) overrides.push("CCP_KIMI_BASE_URL (env)");
+ else if (fromFile.kimi?.baseUrl) overrides.push("kimi.baseUrl (config)");
+
+ if (cfg.env.CCP_CURSOR_BASE_URL)
+ overrides.push(`CCP_CURSOR_BASE_URL=${resolvedCursorBaseUrl(cfg)} (env)`);
+ else if (fromFile.cursor?.baseUrl) overrides.push("cursor.baseUrl (config)");
+
+ if (cfg.env.CCP_CURSOR_CLIENT_VERSION)
+ overrides.push(`CCP_CURSOR_CLIENT_VERSION=${resolvedCursorClientVersion(cfg)} (env)`);
+ else if (fromFile.cursor?.clientVersion) overrides.push("cursor.clientVersion (config)");
+
+ if (cfg.env.CCP_CURSOR_AGENT_BUNDLE) overrides.push("CCP_CURSOR_AGENT_BUNDLE (env)");
+ else if (fromFile.cursor?.agentBundle) overrides.push("cursor.agentBundle (config)");
+
+ return overrides;
+}
+
export function cursorAgentBundle(): string | undefined {
const c = getConfig();
return emptyOrUnset(c.env.CCP_CURSOR_AGENT_BUNDLE) ?? emptyOrUnset(c.file.cursor?.agentBundle);