🔧 Miscellaneous Improvements and Refactoring (#466)

This commit is contained in:
tanzhenxin
2025-08-27 17:32:57 +08:00
committed by GitHub
parent 347e606366
commit 600c58bbcb
16 changed files with 755 additions and 81 deletions

View File

@@ -210,16 +210,16 @@ describe('bfsFileSearch', () => {
for (let i = 0; i < numTargetDirs; i++) {
// Add target files in some directories
fileCreationPromises.push(
createTestFile('content', `dir${i}`, 'GEMINI.md'),
createTestFile('content', `dir${i}`, 'QWEN.md'),
);
fileCreationPromises.push(
createTestFile('content', `dir${i}`, 'subdir1', 'GEMINI.md'),
createTestFile('content', `dir${i}`, 'subdir1', 'QWEN.md'),
);
}
const expectedFiles = await Promise.all(fileCreationPromises);
const result = await bfsFileSearch(testRootDir, {
fileName: 'GEMINI.md',
fileName: 'QWEN.md',
// Provide a generous maxDirs limit to ensure it doesn't prematurely stop
// in this large test case. Total dirs created is 200.
maxDirs: 250,

View File

@@ -143,9 +143,28 @@ async function getGeminiMdFilePathsInternalForEachDir(
// It's okay if it's not found.
}
// FIX: Only perform the workspace search (upward and downward scans)
// if a valid currentWorkingDirectory is provided.
if (dir) {
// Handle the case where we're in the home directory (dir is empty string or home path)
const resolvedDir = dir ? path.resolve(dir) : resolvedHome;
const isHomeDirectory = resolvedDir === resolvedHome;
if (isHomeDirectory) {
// For home directory, only check for QWEN.md directly in the home directory
const homeContextPath = path.join(resolvedHome, geminiMdFilename);
try {
await fs.access(homeContextPath, fsSync.constants.R_OK);
if (homeContextPath !== globalMemoryPath) {
allPaths.add(homeContextPath);
if (debugMode)
logger.debug(
`Found readable home ${geminiMdFilename}: ${homeContextPath}`,
);
}
} catch {
// Not found, which is okay
}
} else if (dir) {
// FIX: Only perform the workspace search (upward and downward scans)
// if a valid currentWorkingDirectory is provided and it's not the home directory.
const resolvedCwd = path.resolve(dir);
if (debugMode)
logger.debug(