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.

90 lines (89 loc) 3.45 kB
import fs from 'fs/promises'; import path from 'path'; import logger from '../../logger.js'; export function getBaseOutputDir() { return process.env.VIBE_CODER_OUTPUT_DIR ? path.resolve(process.env.VIBE_CODER_OUTPUT_DIR) : path.join(process.cwd(), 'VibeCoderOutput'); } export async function ensureDirectoryExists(dirPath) { try { await fs.mkdir(dirPath, { recursive: true }); logger.debug(`Ensured directory exists: ${dirPath}`); } catch (error) { logger.error({ err: error, path: dirPath }, `Failed to create directory: ${dirPath}`); throw error; } } export async function validateDirectoryIsWritable(dirPath) { try { await ensureDirectoryExists(dirPath); const testFilePath = path.join(dirPath, `.write-test-${Date.now()}.tmp`); await fs.writeFile(testFilePath, 'test'); await fs.unlink(testFilePath); logger.debug(`Validated directory is writable: ${dirPath}`); } catch (error) { logger.error({ err: error, path: dirPath }, `Directory is not writable: ${dirPath}`); throw new Error(`Directory is not writable: ${dirPath}`); } } export function getOutputDirectory(_config) { const baseOutputDir = getBaseOutputDir(); const outputDir = path.join(baseOutputDir, 'code-map-generator'); logger.debug(`Using output directory: ${outputDir}`); return outputDir; } export function getCacheDirectory(config) { const outputDir = getOutputDirectory(config); const cacheDir = path.join(outputDir, '.cache'); logger.debug(`Using cache directory: ${cacheDir}`); return cacheDir; } export function getFileInfoCacheDirectory(cacheDir) { return path.join(cacheDir, 'file-info'); } export function getMetadataCacheDirectory(cacheDir) { return path.join(cacheDir, 'metadata'); } export function getTempDirectory(cacheDir) { return path.join(cacheDir, 'temp'); } export function getJobTempDirectory(tempDir, jobId) { return path.join(tempDir, jobId); } export function generateTimestampFileName(name, extension) { const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); const sanitizedName = name.replace(/[^a-zA-Z0-9-_]/g, '-').toLowerCase(); return `${timestamp}-${sanitizedName}.${extension}`; } export async function createDirectoryStructure(config, jobId) { const baseOutputDir = getBaseOutputDir(); const outputDir = getOutputDirectory(config); const cacheDir = getCacheDirectory(config); const fileInfoCacheDir = getFileInfoCacheDirectory(cacheDir); const metadataCacheDir = getMetadataCacheDirectory(cacheDir); const tempDir = getTempDirectory(cacheDir); const jobTempDir = getJobTempDirectory(tempDir, jobId); await ensureDirectoryExists(baseOutputDir); await ensureDirectoryExists(outputDir); if (config.cache?.enabled !== false) { await ensureDirectoryExists(cacheDir); await ensureDirectoryExists(fileInfoCacheDir); await ensureDirectoryExists(metadataCacheDir); await ensureDirectoryExists(tempDir); await ensureDirectoryExists(jobTempDir); } const directoryStructure = { baseOutputDir, outputDir, cacheDir, fileInfoCacheDir, metadataCacheDir, tempDir, jobTempDir, }; logger.debug({ directoryStructure }, 'Created directory structure for Code-Map Generator'); return directoryStructure; }