index_repository
Index or re-index a repository to enable code navigation and retrieval tools. Uses cached index for unchanged files to reduce token usage when querying specific code symbols.
Instructions
🔧 REQUIRED FIRST STEP: Index or re-index the repository to enable all context-manager tools. Uses cached index if files haven't changed. ALWAYS call this when starting work on a repository or if files have changed significantly. Fast (<2s for most repos).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Path to repository root. Default: process.cwd() | |
| forceReindex | No | Force re-indexing even if cache is available. Default: false |
Implementation Reference
- src/index.ts:373-384 (handler)The handler for the index_repository tool which parses the arguments and calls the indexer.indexRepository method.
case 'index_repository': { const path = (args as any).path || process.cwd(); const forceReindex = (args as any).forceReindex || false; await indexer.indexRepository(path, forceReindex); return { content: [ { type: 'text', text: `Repository indexed successfully.\nFiles: ${indexer.getStats().totalFiles}\nSymbols: ${indexer.getStats().totalSymbols}`, }, ], }; - src/index.ts:126-142 (registration)The definition of the index_repository tool in the tools array.
{ name: 'index_repository', description: '🔧 REQUIRED FIRST STEP: Index or re-index the repository to enable all context-manager tools. Uses cached index if files haven\'t changed. ALWAYS call this when starting work on a repository or if files have changed significantly. Fast (<2s for most repos).', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to repository root. Default: process.cwd()', }, forceReindex: { type: 'boolean', description: 'Force re-indexing even if cache is available. Default: false', }, }, }, }, - src/indexer.ts:48-100 (handler)The implementation of indexRepository in the Indexer class, which handles the actual indexing logic.
async indexRepository(rootPath: string, forceReindex: boolean = false): Promise<void> { this.rootPath = rootPath; // Try to load from cache if not forcing re-index if (!forceReindex) { const loaded = await this.loadFromCache(rootPath); if (loaded) { console.error(`Loaded from cache: ${this.index.size} files with ${this.getTotalSymbols()} symbols`); return; } } // Clear existing index this.index.clear(); this.symbolMap.clear(); // Load ignore patterns await this.loadIgnorePatterns(); // Index all files await this.indexDirectory(rootPath); console.error(`Indexed ${this.index.size} files with ${this.getTotalSymbols()} symbols`); // Save to cache await this.saveToCache(rootPath); } private async loadIgnorePatterns(): Promise<void> { const gitignorePath = path.join(this.rootPath, '.gitignore'); // Default patterns this.ignorePatterns = [ 'node_modules', '.git', 'dist', 'build', 'coverage', '.next', '.nuxt', 'out', '.cache', '*.min.js', '*.map', 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', ]; try { const gitignore = await fs.readFile(gitignorePath, 'utf-8'); const lines = gitignore .split('\n')