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

Function resolveProjectPath

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

242 * (must have .codegraph/codegraph.db, not just .codegraph/lessons.db)
243 */
244function resolveProjectPath(pathArg?: string): string {
245 const absolutePath = path.resolve(pathArg || process.cwd());
246
247 // If exact path is initialized (has codegraph.db), use it
248 if (isInitialized(absolutePath)) {
249 return absolutePath;
250 }
251
252 // Walk up to find nearest parent with CodeGraph initialized
253 // Note: findNearestCodeGraphRoot finds any .codegraph folder, but we need one with codegraph.db
254 let current = absolutePath;
255 const root = path.parse(current).root;
256
257 while (current !== root) {
258 const parent = path.dirname(current);
259 if (parent === current) break;
260 current = parent;
261
262 if (isInitialized(current)) {
263 return current;
264 }
265 }
266
267 // Not found - return original path (will fail later with helpful error)
268 return absolutePath;
269}
270
271/**
272 * Format a number with commas

Callers 1

mainFunction · 0.85

Calls 2

isInitializedFunction · 0.90
resolveMethod · 0.80

Tested by

no test coverage detected