MCPcopy
hub / github.com/colbymchenry/codegraph / open

Method open

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

290 * @returns A CodeGraph instance
291 */
292 static async open(projectRoot: string, options: OpenOptions = {}): Promise<CodeGraph> {
293 await initGrammars();
294 const resolvedRoot = path.resolve(projectRoot);
295
296 // Check if initialized
297 if (!isInitialized(resolvedRoot)) {
298 throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
299 }
300
301 // Validate directory structure
302 const validation = validateDirectory(resolvedRoot);
303 if (!validation.valid) {
304 throw new Error(`Invalid CodeGraph directory: ${validation.errors.join(', ')}`);
305 }
306
307 // Open database
308 const dbPath = getDatabasePath(resolvedRoot);
309 const db = DatabaseConnection.open(dbPath);
310 const queries = new QueryBuilder(db.getDb());
311
312 const instance = new CodeGraph(db, queries, resolvedRoot);
313
314 // Sync if requested
315 if (options.sync) {
316 await instance.sync();
317 }
318
319 return instance;
320 }
321
322 /**
323 * Rebuild the project's database from scratch and return a fresh, empty

Callers 6

reopenIfReplacedMethod · 0.45
openSyncMethod · 0.45
resolution.test.tsFile · 0.45
foundation.test.tsFile · 0.45

Calls 8

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

Tested by

no test coverage detected