MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / recreate

Method recreate

src/index.ts:532–562  ·  view source on GitHub ↗

* Rebuild the project's database from scratch and return a fresh, empty * instance — the "same result as a fresh init" semantics that `codegraph * index` documents. * * Unlike `open()` followed by `clear()`, this DISCARDS the existing * `.codegraph/codegraph.db` (and its `-wal`/`-shm`

(projectRoot: string)

Source from the content-addressed store, hash-verified

530 * (and running migrations against) the poisoned database entirely.
531 */
532 static async recreate(projectRoot: string): Promise<CodeGraph> {
533 await initGrammars();
534 const resolvedRoot = path.resolve(projectRoot);
535
536 // Check if initialized — recreate REBUILDS an existing project; it is not a
537 // first-time `init`.
538 if (!isInitialized(resolvedRoot)) {
539 throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
540 }
541
542 const dbPath = getDatabasePath(resolvedRoot);
543 try {
544 removeDatabaseFiles(dbPath);
545 } catch (err) {
546 // POSIX unlinks an open file fine; this fires mainly on Windows when a
547 // live daemon/MCP server still holds the database. Turn the raw EBUSY into
548 // an actionable instruction instead of a generic failure.
549 const reason = err instanceof Error ? err.message : String(err);
550 throw new Error(
551 `Could not rebuild the index — the database file is in use (${reason}). ` +
552 `Stop any running CodeGraph MCP server/daemon for this project and retry, ` +
553 `or remove the ${getCodeGraphDir(resolvedRoot)} directory and run "codegraph init".`
554 );
555 }
556
557 // Re-create an empty, freshly-schema'd database at the same path.
558 const db = DatabaseConnection.initialize(dbPath);
559 const queries = new QueryBuilder(db.getDb());
560
561 return new CodeGraph(db, queries, resolvedRoot);
562 }
563
564 /**
565 * Open synchronously (without sync).

Callers 15

mainFunction · 0.80
reindexFromScratchFunction · 0.80
reindexFromScratchFunction · 0.80
matchesFullIndexFunction · 0.80
rebuildFunction · 0.80
rebuildEdgeSetFunction · 0.80
convergesFunction · 0.80

Calls 8

initGrammarsFunction · 0.90
isInitializedFunction · 0.90
getDatabasePathFunction · 0.90
removeDatabaseFilesFunction · 0.90
getCodeGraphDirFunction · 0.90
getDbMethod · 0.80
resolveMethod · 0.65
initializeMethod · 0.45

Tested by 6

reindexFromScratchFunction · 0.64
reindexFromScratchFunction · 0.64
matchesFullIndexFunction · 0.64
rebuildFunction · 0.64
rebuildEdgeSetFunction · 0.64
convergesFunction · 0.64