UNPKG

@alvinveroy/codecompass

Version:

AI-powered MCP server for codebase navigation and LLM prompt optimization

114 lines (108 loc) 4.89 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const node_cache_1 = __importDefault(require("node-cache")); const server_1 = require("./lib/server"); // Initialize cache: stdTTL is 0 (infinite) as we manage staleness via file mtime // checkOnPreviousTTL: false, as we don't use individual item TTLs here. const changelogCache = new node_cache_1.default({ stdTTL: 0, checkperiod: 0 }); const CACHE_KEY_CONTENT = 'changelogContent'; const CACHE_KEY_MTIME = 'changelogMtime'; // Helper function to read package.json version function getPackageVersion() { try { // Assuming the script runs from dist/index.js, package.json is ../package.json const packageJsonPath = path_1.default.resolve(__dirname, '../package.json'); const packageJsonContent = fs_1.default.readFileSync(packageJsonPath, 'utf8'); const packageJson = JSON.parse(packageJsonContent); return packageJson.version || 'unknown'; } catch { // Silently return 'unknown' on error, e.g. if package.json is not found during certain build phases return 'unknown'; } } function displayHelp() { const version = getPackageVersion(); console.log(` CodeCompass CLI (version ${version}) Usage: codecompass [command|repoPath] Description: AI-powered MCP server for codebase navigation and LLM prompt optimization. If no command is provided, the server starts with the specified or default repoPath. Commands: --help, -h Show this help message and exit. --version, -v Show version information and exit. --changelog Show the project changelog and exit. Supports an optional --verbose flag (e.g., codecompass --changelog --verbose) for potentially more detailed output in the future. Arguments: repoPath (optional) Path to the repository to be analyzed by the server. Defaults to the current directory ('.') if not specified. Example: codecompass /path/to/your/repo codecompass . codecompass For more information, visit: https://github.com/alvinveroy/codecompass `); } function displayChangelog(verbose) { const changelogPath = path_1.default.resolve(__dirname, '../CHANGELOG.md'); try { const stats = fs_1.default.statSync(changelogPath); const currentMtime = stats.mtimeMs; const cachedMtime = changelogCache.get(CACHE_KEY_MTIME); const cachedContent = changelogCache.get(CACHE_KEY_CONTENT); if (cachedContent && cachedMtime && cachedMtime === currentMtime) { console.log(cachedContent); if (verbose) { // Future verbose-specific logic can be added here. } return; } // Cache is stale or doesn't exist, read file const changelogContent = fs_1.default.readFileSync(changelogPath, 'utf8'); changelogCache.set(CACHE_KEY_CONTENT, changelogContent); changelogCache.set(CACHE_KEY_MTIME, currentMtime); console.log(changelogContent); if (verbose) { // Placeholder for future verbose-specific logic. // For now, verbose output is the same as non-verbose for the full changelog. } } catch (error) { console.error('Error reading or caching CHANGELOG.md:', error); } } const primaryArg = process.argv[2]; const secondaryArg = process.argv[3]; // Used for flags like --changelog --verbose if (primaryArg === '--help' || primaryArg === '-h') { displayHelp(); } else if (primaryArg === '--version' || primaryArg === '-v') { console.log(getPackageVersion()); } else if (primaryArg === '--changelog') { const verbose = secondaryArg === '--verbose'; displayChangelog(verbose); } else { // Default behavior: start the server. // Determine repoPath: use primaryArg if it exists and doesn't start with '--', otherwise default to '.'. let repoPath = "."; if (primaryArg && !primaryArg.startsWith('--')) { repoPath = primaryArg; } else if (primaryArg && primaryArg.startsWith('--')) { // An unrecognized flag was passed as primaryArg. // The server will start with the default repoPath '.'. console.warn(`Warning: Unrecognized flag "${primaryArg}". Starting server with default repository path "${repoPath}".`); console.warn(`Run 'codecompass --help' for available commands.`); } // If primaryArg is undefined (no arguments given), repoPath remains '.'. void (0, server_1.startServer)(repoPath); }