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

Function resolveProjectPath

src/bin/codegraph.ts:269–294  ·  view source on GitHub ↗

* Resolve project path from argument or current directory * Walks up parent directories to find nearest initialized CodeGraph project * (must have .codegraph/codegraph.db, not just .codegraph/lessons.db)

(pathArg?: string)

Source from the content-addressed store, hash-verified

267 * (must have .codegraph/codegraph.db, not just .codegraph/lessons.db)
268 */
269function resolveProjectPath(pathArg?: string): string {
270 const absolutePath = path.resolve(pathArg || process.cwd());
271
272 // If exact path is initialized (has codegraph.db), use it
273 if (isInitialized(absolutePath)) {
274 return absolutePath;
275 }
276
277 // Walk up to find nearest parent with CodeGraph initialized
278 // Note: findNearestCodeGraphRoot finds any .codegraph folder, but we need one with codegraph.db
279 let current = absolutePath;
280 const root = path.parse(current).root;
281
282 while (current !== root) {
283 const parent = path.dirname(current);
284 if (parent === current) break;
285 current = parent;
286
287 if (isInitialized(current)) {
288 return current;
289 }
290 }
291
292 // Not found - return original path (will fail later with helpful error)
293 return absolutePath;
294}
295
296/**
297 * Format a number with commas

Callers 1

mainFunction · 0.85

Calls 3

isInitializedFunction · 0.90
parseMethod · 0.80
resolveMethod · 0.65

Tested by

no test coverage detected