Add codebase indexing system (Milestone 4)

- Add project type detection (Node.js, Python, Rust, Go, generic)
- Add file scanner with ignore patterns and hash tracking
- Add TypeScript/JavaScript parser (exports, imports, classes, functions)
- Add Python parser (imports, classes, functions, __all__)
- Add relationship mapper for import dependencies
- Add architecture summary generation with tech stack detection
- Add incremental update support via file hash comparison
- Add CLI command: cortex index [path] [--update] [--dry-run]
- Add MCP tools: memory_index, memory_components
This commit is contained in:
2026-02-03 10:53:26 +01:00
parent 9490cd1db4
commit 056a02d936
12 changed files with 1061 additions and 0 deletions

View File

@@ -590,6 +590,57 @@ server.tool(
}
);
// --- memory_index ---
import { indexProject } from '../core/indexer';
server.tool(
'memory_index',
'Index a codebase to create component nodes. Scans files, extracts exports/imports, and maps relationships.',
{
path: z.string().optional().describe('Path to index (default: current directory)'),
update: z.boolean().optional().describe('Only update changed files (incremental)'),
language: z.string().optional().describe('Only index specific language (ts, js, py)'),
maxDepth: z.number().optional().describe('Maximum directory depth (default: 10)'),
},
async ({ path: inputPath, update, language, maxDepth }) => {
const result = await indexProject(inputPath || '.', {
update,
language,
maxDepth,
});
return { content: [{ type: 'text' as const, text: serialize(result) }] };
}
);
// --- memory_components ---
server.tool(
'memory_components',
'List indexed components for a project',
{
project: z.string().optional().describe('Project name to filter by'),
limit: z.number().optional().describe('Max results (default: 50)'),
},
async ({ project, limit }) => {
const tags = project ? [project, 'indexed'] : ['indexed'];
const components = listNodes({ kind: 'component' as NodeKind, tags, limit: limit || 50 });
return {
content: [{
type: 'text' as const,
text: serialize({
count: components.length,
components: components.map(c => ({
id: c.id,
title: c.title,
filePath: c.metadata?.filePath,
exports: (c.metadata?.exports as string[])?.length || 0,
loc: c.metadata?.loc,
})),
}),
}],
};
}
);
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);