| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- /**
- * Configuration manager for the Claude client
- */
- import { readFileSync, existsSync } from 'fs';
- import { join } from 'path';
- import { MCPServerConfig } from './types.js';
- import { McpConfigManager } from './mcpConfigManager.js';
- export class Config {
- private static envVars: Map<string, string> = new Map();
- /**
- * Load environment variables from .env file
- */
- static load(repoPath: string): void {
- const envPath = join(repoPath, '.env');
- if (!existsSync(envPath)) {
- return;
- }
- try {
- const content = readFileSync(envPath, 'utf-8');
- const lines = content.split('\n');
- for (const line of lines) {
- const trimmed = line.trim();
- // Skip comments and empty lines
- if (!trimmed || trimmed.startsWith('#')) {
- continue;
- }
- const match = trimmed.match(/^([^=]+)=(.*)$/);
- if (match) {
- const key = match[1].trim();
- const value = match[2].trim();
- this.envVars.set(key, value);
- // Also set in process.env if not already set
- if (!process.env[key]) {
- process.env[key] = value;
- }
- }
- }
- } catch (error) {
- console.error(`Warning: Failed to load .env file: ${error}`);
- }
- }
- /**
- * Get environment variable value
- */
- static get(key: string, defaultValue?: string): string {
- return this.envVars.get(key) || process.env[key] || defaultValue || '';
- }
- /**
- * Get the path to gogs-mcp server
- */
- static getGogsMcpPath(): string {
- return this.get('GOGS_MCP_PATH', '/data/gogs-mcp/dist/index.js');
- }
- /**
- * Generate MCP configuration for a repository
- *
- * Priority:
- * 1. Repository-specific config: ~/.config/agent-manager/mcp/{owner}/{repo}.json
- * 2. Global default config: ~/.config/agent-manager/mcp/default.json
- * 3. Hardcoded fallback (gogs-mcp only)
- */
- static generateMcpConfig(repoPath: string, owner?: string, repo?: string): MCPServerConfig {
- const gogsMcpPath = this.getGogsMcpPath();
- // If owner and repo are provided, try to load per-repository config
- if (owner && repo) {
- return McpConfigManager.getMcpConfig(owner, repo, gogsMcpPath);
- }
- // Fallback to hardcoded config
- return {
- mcpServers: {
- gogs: {
- type: 'stdio',
- command: 'node',
- args: [gogsMcpPath],
- env: {}
- }
- }
- };
- }
- }
|