UNPKG

vibe-coder-mcp

Version:

Production-ready MCP server with complete agent integration, multi-transport support, and comprehensive development automation tools for AI-assisted workflows.

83 lines (82 loc) 3.06 kB
import path from 'path'; import os from 'os'; import fs from 'fs-extra'; import logger from '../logger.js'; export class UserConfigManager { static instance = null; userConfigDir; configVersion = '0.3.0'; constructor() { this.userConfigDir = this.determineUserConfigDir(); } static getInstance() { if (!UserConfigManager.instance) { UserConfigManager.instance = new UserConfigManager(); } return UserConfigManager.instance; } determineUserConfigDir() { const platform = os.platform(); if (process.env.XDG_CONFIG_HOME) { return path.join(process.env.XDG_CONFIG_HOME, 'vibe-coder'); } switch (platform) { case 'win32': return path.join(process.env.APPDATA || os.homedir(), 'vibe-coder'); case 'darwin': return path.join(os.homedir(), 'Library', 'Application Support', 'vibe-coder'); default: return path.join(os.homedir(), '.config', 'vibe-coder'); } } async ensureUserConfigDir() { try { const dirs = [ this.userConfigDir, path.join(this.userConfigDir, 'configs'), path.join(this.userConfigDir, 'backups'), path.join(this.userConfigDir, 'logs') ]; for (const dir of dirs) { await fs.ensureDir(dir); logger.debug({ dir }, 'Ensured config directory exists'); } } catch (error) { logger.error({ err: error }, 'Failed to create config directories'); throw error; } } async copyDefaultConfigs() { const templateDir = path.join(process.cwd(), 'src', 'config-templates'); const configDir = path.join(this.userConfigDir, 'configs'); const templates = [ { src: '.env.template', dest: '.env' }, { src: 'llm_config.template.json', dest: 'llm_config.json' }, { src: 'mcp-config.template.json', dest: 'mcp-config.json' } ]; for (const template of templates) { const srcPath = path.join(templateDir, template.src); const destPath = path.join(configDir, template.dest); if (!await fs.pathExists(destPath)) { await fs.copy(srcPath, destPath); logger.info({ file: template.dest }, 'Copied default config'); } } } async backupExistingConfigs() { const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); const backupDir = path.join(this.userConfigDir, 'backups', timestamp); const configDir = path.join(this.userConfigDir, 'configs'); if (await fs.pathExists(configDir)) { await fs.copy(configDir, backupDir); logger.info({ backupDir }, 'Backed up existing configs'); } } getUserConfigDir() { return this.userConfigDir; } getConfigVersion() { return this.configVersion; } }