cortexweaver
Version:
CortexWeaver is a command-line interface (CLI) tool that orchestrates a swarm of specialized AI agents, powered by Claude Code and Gemini CLI, to assist in software development. It transforms a high-level project plan (plan.md) into a series of coordinate
188 lines • 6.54 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileAnalyzer = void 0;
const fsp = __importStar(require("fs/promises"));
const path = __importStar(require("path"));
/**
* FileAnalyzer handles code file analysis and language detection
*/
class FileAnalyzer {
constructor(projectRoot) {
this.projectRoot = projectRoot;
}
/**
* Analyze a single code file
*/
async analyzeCodeFile(filePath, rootPath, includeContent = false) {
try {
const stats = await fsp.stat(filePath);
const ext = path.extname(filePath).toLowerCase();
const basename = path.basename(filePath).toLowerCase();
const relativePath = path.relative(rootPath, filePath);
// Determine file type
let type;
if (basename.includes('test') || basename.includes('spec') || relativePath.includes('/test/') || relativePath.includes('/tests/')) {
type = 'test';
}
else if (['.md', '.txt', '.rst', '.adoc'].includes(ext)) {
type = 'documentation';
}
else if (['.json', '.yaml', '.yml', '.toml', '.ini', '.config', '.env'].includes(ext)) {
type = 'config';
}
else {
type = 'source';
}
// Determine language
const language = this.getLanguageFromExtension(ext);
// Skip files that are too large
if (stats.size > (1024 * 1024)) { // 1MB
return null;
}
let content;
if (includeContent) {
const fileContent = await this.readFileContent(filePath);
content = fileContent ?? undefined;
}
return {
path: filePath,
relativePath,
type,
language,
size: stats.size,
lastModified: stats.mtime,
content
};
}
catch (error) {
console.warn(`Failed to analyze file ${filePath}:`, error);
return null;
}
}
/**
* Check if a file should be included based on options
*/
shouldIncludeFile(file, options) {
// Check file type inclusion options
if (!options.includeTests && file.type === 'test')
return false;
if (!options.includeDocs && file.type === 'documentation')
return false;
if (!options.includeConfig && file.type === 'config')
return false;
// Check file size
if (options.maxFileSize && file.size > options.maxFileSize)
return false;
// Check extensions
if (options.extensions && options.extensions.length > 0) {
const ext = path.extname(file.path).toLowerCase();
if (!options.extensions.includes(ext))
return false;
}
return true;
}
/**
* Read file content safely
*/
async readFileContent(filePath) {
try {
const fullPath = path.isAbsolute(filePath) ? filePath : path.join(this.projectRoot, filePath);
const stats = await fsp.stat(fullPath);
// Skip files that are too large
if (stats.size > 1024 * 1024) { // 1MB limit
console.warn(`File ${filePath} is too large (${stats.size} bytes), skipping content read`);
return null;
}
return await fsp.readFile(fullPath, 'utf-8');
}
catch (error) {
console.warn(`Failed to read file ${filePath}:`, error);
return null;
}
}
/**
* Get language from file extension
*/
getLanguageFromExtension(ext) {
const languageMap = {
'.ts': 'typescript',
'.tsx': 'typescript',
'.js': 'javascript',
'.jsx': 'javascript',
'.py': 'python',
'.java': 'java',
'.cpp': 'cpp',
'.cxx': 'cpp',
'.cc': 'cpp',
'.c': 'c',
'.h': 'c',
'.hpp': 'cpp',
'.cs': 'csharp',
'.go': 'go',
'.rs': 'rust',
'.rb': 'ruby',
'.php': 'php',
'.swift': 'swift',
'.kt': 'kotlin',
'.scala': 'scala',
'.clj': 'clojure',
'.hs': 'haskell',
'.ml': 'ocaml',
'.fs': 'fsharp',
'.vb': 'vbnet',
'.pl': 'perl',
'.r': 'r',
'.m': 'matlab',
'.sh': 'bash',
'.ps1': 'powershell',
'.json': 'json',
'.yaml': 'yaml',
'.yml': 'yaml',
'.xml': 'xml',
'.html': 'html',
'.css': 'css',
'.scss': 'scss',
'.sass': 'sass',
'.less': 'less',
'.md': 'markdown',
'.tex': 'latex',
'.sql': 'sql'
};
return languageMap[ext] || 'unknown';
}
}
exports.FileAnalyzer = FileAnalyzer;
//# sourceMappingURL=file-analyzer.js.map