import fs from 'fs'; import path from 'path'; import os from 'os'; const CONFIG_DIR = path.join(os.homedir(), '.git-ai-pilot'); const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json'); export interface Config { GEMINI_API_KEY?: string; OPENAI_API_KEY?: string; customCommand?: string; } export function getGlobalConfig(): Config { if (!fs.existsSync(CONFIG_FILE)) { return {}; } try { const content = fs.readFileSync(CONFIG_FILE, 'utf-8'); return JSON.parse(content); } catch (error) { return {}; } } export function saveGlobalConfig(config: Config): void { if (!fs.existsSync(CONFIG_DIR)) { fs.mkdirSync(CONFIG_DIR, { recursive: true }); } fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2)); } export function getApiKey(): string | undefined { if (process.env.GEMINI_API_KEY) { return process.env.GEMINI_API_KEY; } const config = getGlobalConfig(); return config.GEMINI_API_KEY; } export function getOpenAiApiKey(): string | undefined { if (process.env.OPENAI_API_KEY) { return process.env.OPENAI_API_KEY; } const config = getGlobalConfig(); return config.OPENAI_API_KEY; }