MCPcopy Create free account
hub / github.com/anus-dev/ANUS / findProjectRoot

Function findProjectRoot

packages/core/src/utils/memoryImportProcessor.ts:52–73  ·  view source on GitHub ↗
(startDir: string)

Source from the content-addressed store, hash-verified

50
51// Helper to find the project root (looks for .git directory)
52async function findProjectRoot(startDir: string): Promise<string> {
53 let currentDir = path.resolve(startDir);
54 while (true) {
55 const gitPath = path.join(currentDir, '.git');
56 try {
57 const stats = await fs.lstat(gitPath);
58 if (stats.isDirectory()) {
59 return currentDir;
60 }
61 } catch {
62 // .git not found, continue to parent
63 }
64 const parentDir = path.dirname(currentDir);
65 if (parentDir === currentDir) {
66 // Reached filesystem root
67 break;
68 }
69 currentDir = parentDir;
70 }
71 // Fallback to startDir if .git not found
72 return path.resolve(startDir);
73}
74
75// Add a type guard for error objects
76function hasMessage(err: unknown): err is { message: string } {

Callers 1

processImportsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected