feat(cliproxy): set WRITABLE_PATH for log storage in ~/.ccs/cliproxy/

- Add getCliproxyWritablePath() helper function
- Set WRITABLE_PATH env var when spawning CLIProxy in both executors
- Logs will now be stored in ~/.ccs/cliproxy/logs/ instead of CWD
- Enables error log viewer to find logs in predictable location

Note: CLIProxyAPI still has hardcoded MaxBackups=0 (unlimited).
Log rotation should be addressed in CLIProxyAPI upstream.
This commit is contained in:
kaitranntt
2025-12-18 02:54:46 -05:00
parent 1ef625ee86
commit 6b9396fbc6
3 changed files with 19 additions and 0 deletions
+5
View File
@@ -24,6 +24,7 @@ import {
getProviderConfig,
ensureProviderSettings,
CLIPROXY_DEFAULT_PORT,
getCliproxyWritablePath,
} from './config-generator';
import { isAuthenticated } from './auth-handler';
import { CLIProxyProvider, ExecutorConfig } from './types';
@@ -369,6 +370,10 @@ export async function execClaudeWithCLIProxy(
proxy = spawn(binaryPath, proxyArgs, {
stdio: ['ignore', 'ignore', 'ignore'],
detached: true, // Persist after parent terminal closes
env: {
...process.env,
WRITABLE_PATH: getCliproxyWritablePath(), // Logs stored in ~/.ccs/cliproxy/logs/
},
});
// Unref so parent process can exit independently
+9
View File
@@ -30,6 +30,15 @@ export const CCS_INTERNAL_API_KEY = 'ccs-internal-managed';
/** Simple secret key for Control Panel login (user-facing) */
export const CCS_CONTROL_PANEL_SECRET = 'ccs';
/**
* Get CLIProxy writable directory for logs and runtime files.
* This directory is set as WRITABLE_PATH env var when spawning CLIProxy.
* Logs will be stored in ~/.ccs/cliproxy/logs/
*/
export function getCliproxyWritablePath(): string {
return path.join(getCcsDir(), 'cliproxy');
}
/**
* Config version - bump when config format changes to trigger regeneration
* v1: Initial config (port, auth-dir, api-keys only)
+5
View File
@@ -19,6 +19,7 @@ import {
regenerateConfig,
configNeedsRegeneration,
CLIPROXY_DEFAULT_PORT,
getCliproxyWritablePath,
} from './config-generator';
import { isCliproxyRunning } from './stats-fetcher';
@@ -171,6 +172,10 @@ export async function ensureCliproxyService(
proxyProcess = spawn(binaryPath, proxyArgs, {
stdio: ['ignore', verbose ? 'pipe' : 'ignore', verbose ? 'pipe' : 'ignore'],
detached: true, // Allow process to run independently
env: {
...process.env,
WRITABLE_PATH: getCliproxyWritablePath(), // Logs stored in ~/.ccs/cliproxy/logs/
},
});
// Forward output in verbose mode