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

Function resolveProjectPath

src/bin/codegraph.ts:268–293  ·  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

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