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

Method recreate

src/index.ts:533–563  ·  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

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