mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 04:17:54 +00:00
fix(proxy): clean up temp launch settings
This commit is contained in:
@@ -5,10 +5,15 @@ import * as path from 'path';
|
||||
import type { Settings } from '../types/config';
|
||||
import { stripAnthropicRoutingEnv } from './shell-executor';
|
||||
|
||||
export function createOpenAICompatLaunchSettingsPath(
|
||||
export interface OpenAICompatLaunchSettings {
|
||||
settingsPath: string;
|
||||
cleanup: () => void;
|
||||
}
|
||||
|
||||
export function createOpenAICompatLaunchSettings(
|
||||
settingsPath: string,
|
||||
settings: Settings
|
||||
): string {
|
||||
): OpenAICompatLaunchSettings {
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-openai-compat-settings-'));
|
||||
fs.chmodSync(tempDir, 0o700);
|
||||
|
||||
@@ -31,5 +36,17 @@ export function createOpenAICompatLaunchSettingsPath(
|
||||
mode: 0o600,
|
||||
});
|
||||
|
||||
return launchSettingsPath;
|
||||
let cleanedUp = false;
|
||||
const cleanup = (): void => {
|
||||
if (cleanedUp) {
|
||||
return;
|
||||
}
|
||||
cleanedUp = true;
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
};
|
||||
|
||||
return {
|
||||
settingsPath: launchSettingsPath,
|
||||
cleanup,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -208,7 +208,8 @@ export function getWindowsEscapedCommandShell(): SpawnOptions['shell'] {
|
||||
export function execClaude(
|
||||
claudeCli: string,
|
||||
args: string[],
|
||||
envVars: NodeJS.ProcessEnv | null = null
|
||||
envVars: NodeJS.ProcessEnv | null = null,
|
||||
onExitCleanup?: () => void
|
||||
): void {
|
||||
const isWindows = process.platform === 'win32';
|
||||
const isPowerShellScript = isWindows && /\.ps1$/i.test(claudeCli);
|
||||
@@ -286,6 +287,17 @@ export function execClaude(
|
||||
});
|
||||
}
|
||||
|
||||
let cleanedUp = false;
|
||||
const runExitCleanup = (): void => {
|
||||
if (cleanedUp) {
|
||||
return;
|
||||
}
|
||||
cleanedUp = true;
|
||||
onExitCleanup?.();
|
||||
};
|
||||
child.once('exit', runExitCleanup);
|
||||
child.once('error', runExitCleanup);
|
||||
|
||||
wireChildProcessSignals(child, async (err: NodeJS.ErrnoException) => {
|
||||
if (err.code === 'EACCES') {
|
||||
console.error(`[X] Claude CLI is not executable: ${claudeCli}`);
|
||||
|
||||
Reference in New Issue
Block a user