UNPKG

mira-consciousness

Version:

Memory & Intelligence Retention Archive - Preserving The Spark

59 lines 2.29 kB
import fs from 'fs-extra'; import * as path from 'path'; export class ProjectRootFinder { /** * Find the actual project root (workspace root, not MIRA installation) */ static findProjectRoot(startPath) { let currentPath = path.resolve(startPath); // If we're inside the mira-memory directory, go up to find workspace root if (currentPath.includes('mira-memory')) { // Go up until we're out of mira-memory directory while (currentPath.includes('mira-memory') && currentPath !== path.dirname(currentPath)) { currentPath = path.dirname(currentPath); } } // Look for git root or workspace indicators while (currentPath !== path.dirname(currentPath)) { // Check for git directory if (fs.existsSync(path.join(currentPath, '.git'))) { return currentPath; } // Check for package.json, tsconfig.json, or other project indicators const indicators = [ 'package.json', 'tsconfig.json', '.vscode', 'Cargo.toml', 'pyproject.toml', 'go.mod', 'composer.json', 'Gemfile', 'requirements.txt', 'pom.xml', 'build.gradle' ]; if (indicators.some(indicator => fs.existsSync(path.join(currentPath, indicator)))) { return currentPath; } currentPath = path.dirname(currentPath); } // Fallback to the provided path if no indicators found return path.resolve(startPath); } /** * Check if a path is within the MIRA installation directory */ static isWithinMIRAInstallation(checkPath) { const resolved = path.resolve(checkPath); return resolved.includes('mira-memory') || resolved.includes('node_modules'); } /** * Get the MIRA memory directory for a project */ static getMIRAMemoryDir(projectRoot) { const root = projectRoot ? this.findProjectRoot(projectRoot) : this.findProjectRoot(process.cwd()); return path.join(root, '.mira'); } } //# sourceMappingURL=ProjectRootFinder.js.map