UNPKG

cortexweaver

Version:

CortexWeaver is a command-line interface (CLI) tool that orchestrates a swarm of specialized AI agents, powered by Claude Code and Gemini CLI, to assist in software development. It transforms a high-level project plan (plan.md) into a series of coordinate

198 lines 7.67 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigService = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const dotenv = __importStar(require("dotenv")); const auth_manager_1 = require("./auth-manager"); class ConfigService { constructor(projectRoot = process.cwd()) { this.projectRoot = projectRoot; this.envFilePath = path.join(projectRoot, '.env'); this.configFilePath = path.join(projectRoot, '.cortexweaver', 'config.json'); } loadEnvironmentVariables() { if (!fs.existsSync(this.envFilePath)) { return {}; } const envConfig = dotenv.parse(fs.readFileSync(this.envFilePath)); return envConfig; } loadProjectConfig() { const defaultConfig = { models: { claude: 'claude-3-opus-20240229', gemini: 'gemini-pro' }, costs: { claudeTokenCost: 0.015, geminiTokenCost: 0.0005 }, budget: { maxTokens: 50000, maxCost: 500 } }; if (!fs.existsSync(this.configFilePath)) { return defaultConfig; } try { const configContent = fs.readFileSync(this.configFilePath, 'utf-8'); const config = JSON.parse(configContent); return { models: { ...defaultConfig.models, ...config.models }, costs: { ...defaultConfig.costs, ...config.costs }, budget: { ...defaultConfig.budget, ...config.budget } }; } catch (error) { console.warn(`Failed to parse config file: ${error}. Using default configuration.`); return defaultConfig; } } getRequiredEnvVar(name) { const value = process.env[name]; if (!value) { throw new Error(`Required environment variable ${name} is not set`); } return value; } saveProjectConfig(config) { const configDir = path.dirname(this.configFilePath); if (!fs.existsSync(configDir)) { fs.mkdirSync(configDir, { recursive: true }); } fs.writeFileSync(this.configFilePath, JSON.stringify(config, null, 2)); } getProjectRoot() { return this.projectRoot; } getCortexWeaverDir() { return path.join(this.projectRoot, '.cortexweaver'); } /** * Get Claude API key with AuthManager integration * Checks AuthManager first, then falls back to environment variables * @deprecated Use getClaudeCredentials() instead for session token support */ async getClaudeApiKey() { try { const authManager = new auth_manager_1.AuthManager(this.projectRoot); await authManager.discoverAuthentication(); const credentials = await authManager.getClaudeCredentials(); if (credentials?.apiKey) { return credentials.apiKey; } } catch (error) { // Fall back to environment variables if AuthManager fails console.warn('AuthManager failed, falling back to environment variables:', error.message); } // Fallback to environment variables return this.getRequiredEnvVar('CLAUDE_API_KEY'); } /** * Get Claude credentials (API key or session token) with AuthManager integration * Checks AuthManager first, then falls back to environment variables */ async getClaudeCredentials() { try { const authManager = new auth_manager_1.AuthManager(this.projectRoot); await authManager.discoverAuthentication(); const credentials = await authManager.getClaudeCredentials(); if (credentials?.apiKey || credentials?.sessionToken) { return { apiKey: credentials.apiKey, sessionToken: credentials.sessionToken }; } } catch (error) { // Fall back to environment variables if AuthManager fails console.warn('AuthManager failed, falling back to environment variables:', error.message); } // Fallback to environment variables const apiKey = process.env.CLAUDE_API_KEY || process.env.ANTHROPIC_API_KEY; if (apiKey) { return { apiKey }; } throw new Error('No Claude authentication found. Set CLAUDE_API_KEY/ANTHROPIC_API_KEY environment variable or configure Claude Code CLI.'); } /** * Get Gemini API key with AuthManager integration * Checks AuthManager first, then falls back to environment variables */ async getGeminiApiKey() { try { const authManager = new auth_manager_1.AuthManager(this.projectRoot); await authManager.discoverAuthentication(); const credentials = await authManager.getGeminiCredentials(); if (credentials?.apiKey) { return credentials.apiKey; } } catch (error) { // Fall back to environment variables if AuthManager fails console.warn('AuthManager failed, falling back to environment variables:', error.message); } // Fallback to environment variables return this.getRequiredEnvVar('GEMINI_API_KEY'); } /** * Check if authentication is properly configured */ async checkAuthenticationStatus() { try { const authManager = new auth_manager_1.AuthManager(this.projectRoot); await authManager.discoverAuthentication(); const status = await authManager.getAuthStatus(); return { claude: status.claudeAuth.isAuthenticated, gemini: status.geminiAuth.isAuthenticated, recommendations: status.recommendations }; } catch (error) { return { claude: false, gemini: false, recommendations: [`Failed to check authentication: ${error.message}`] }; } } } exports.ConfigService = ConfigService; //# sourceMappingURL=config.js.map