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

Function findProjectRoot

packages/core/src/utils/memoryDiscovery.ts:43–85  ·  view source on GitHub ↗
(startDir: string)

Source from the content-addressed store, hash-verified

41}
42
43async function findProjectRoot(startDir: string): Promise<string | null> {
44 let currentDir = path.resolve(startDir);
45 while (true) {
46 const gitPath = path.join(currentDir, '.git');
47 try {
48 const stats = await fs.lstat(gitPath);
49 if (stats.isDirectory()) {
50 return currentDir;
51 }
52 } catch (error: unknown) {
53 // Don't log ENOENT errors as they're expected when .git doesn't exist
54 // Also don't log errors in test environments, which often have mocked fs
55 const isENOENT =
56 typeof error === 'object' &&
57 error !== null &&
58 'code' in error &&
59 (error as { code: string }).code === 'ENOENT';
60
61 // Only log unexpected errors in non-test environments
62 // process.env['NODE_ENV'] === 'test' or VITEST are common test indicators
63 const isTestEnv =
64 process.env['NODE_ENV'] === 'test' || process.env['VITEST'];
65
66 if (!isENOENT && !isTestEnv) {
67 if (typeof error === 'object' && error !== null && 'code' in error) {
68 const fsError = error as { code: string; message: string };
69 logger.warn(
70 `Error checking for .git directory at ${gitPath}: ${fsError.message}`,
71 );
72 } else {
73 logger.warn(
74 `Non-standard error checking for .git directory at ${gitPath}: ${String(error)}`,
75 );
76 }
77 }
78 }
79 const parentDir = path.dirname(currentDir);
80 if (parentDir === currentDir) {
81 return null;
82 }
83 currentDir = parentDir;
84 }
85}
86
87async function getAnusMdFilePathsInternal(
88 currentWorkingDirectory: string,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected