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

Method open

src/index.ts:335–363  ·  view source on GitHub ↗

* Open an existing CodeGraph project * * @param projectRoot - Path to the project root directory * @param options - Open options * @returns A CodeGraph instance

(projectRoot: string, options: OpenOptions = {})

Source from the content-addressed store, hash-verified

333 * @returns A CodeGraph instance
334 */
335 static async open(projectRoot: string, options: OpenOptions = {}): Promise<CodeGraph> {
336 await initGrammars();
337 const resolvedRoot = path.resolve(projectRoot);
338
339 // Check if initialized
340 if (!isInitialized(resolvedRoot)) {
341 throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
342 }
343
344 // Validate directory structure
345 const validation = validateDirectory(resolvedRoot);
346 if (!validation.valid) {
347 throw new Error(`Invalid CodeGraph directory: ${validation.errors.join(', ')}`);
348 }
349
350 // Open database
351 const dbPath = getDatabasePath(resolvedRoot);
352 const db = DatabaseConnection.open(dbPath);
353 const queries = new QueryBuilder(db.getDb());
354
355 const instance = new CodeGraph(db, queries, resolvedRoot);
356
357 // Sync if requested
358 if (options.sync) {
359 await instance.sync();
360 }
361
362 return instance;
363 }
364
365 /**
366 * Rebuild the project's database from scratch and return a fresh, empty

Callers 2

reopenIfReplacedMethod · 0.45
openSyncMethod · 0.45

Calls 8

syncMethod · 0.95
initGrammarsFunction · 0.90
isInitializedFunction · 0.90
validateDirectoryFunction · 0.90
getDatabasePathFunction · 0.90
getDbMethod · 0.80
resolveMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected