MCPcopy Create free account
hub / github.com/Stevenic/codepilot / rebuild

Method rebuild

src/CodeIndex.ts:282–317  ·  view source on GitHub ↗

* Rebuilds the code index.

()

Source from the content-addressed store, hash-verified

280 * Rebuilds the code index.
281 */
282 public async rebuild(): Promise<void> {
283 if (!await this.isCreated()) {
284 throw new Error('Index has not been created yet. Please run `codepilot create` first.');
285 }
286 if (!await this.hasKeys()) {
287 throw new Error("A local vectra.keys file couldn't be found. Please run `codepilot set --key <your OpenAI key>`.");
288 }
289
290 // Create fresh index
291 const index = await this.load();
292 if (await index.isCatalogCreated()) {
293 await index.deleteIndex();
294 }
295 await index.createIndex();
296
297 // Index files
298 const fetcher = new FileFetcher();
299 for (const source of this._config!.sources) {
300 await fetcher.fetch(source, async (uri, text, docType) => {
301 // Ignore binary files
302 if (IGNORED_FILES.includes(path.extname(uri))) {
303 return true;
304 }
305
306 // Ignore any disallowed extensions
307 if (this._config!.extensions && docType && !this._config!.extensions!.includes(docType)) {
308 return true;
309 }
310
311 // Upsert document
312 console.log(Colorize.progress(`adding: ${uri}`));
313 await index.upsertDocument(uri, text, docType);
314 return true;
315 });
316 }
317 }
318
319 // LLM-REGION
320

Callers 1

runFunction · 0.95

Calls 5

isCreatedMethod · 0.95
hasKeysMethod · 0.95
loadMethod · 0.95
progressMethod · 0.45
upsertDocumentMethod · 0.45

Tested by

no test coverage detected