fix: CLAUDE.md compatibility for GEMINI.md '@' file import behavior (#2978)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Allen Hutchison <adh@google.com>
This commit is contained in:
Niladri Das
2025-07-31 22:06:50 +05:30
committed by GitHub
parent ae86c7ba05
commit 9a6422f331
14 changed files with 1355 additions and 215 deletions

View File

@@ -43,7 +43,7 @@ async function findProjectRoot(startDir: string): Promise<string | null> {
while (true) {
const gitPath = path.join(currentDir, '.git');
try {
const stats = await fs.stat(gitPath);
const stats = await fs.lstat(gitPath);
if (stats.isDirectory()) {
return currentDir;
}
@@ -230,6 +230,7 @@ async function getGeminiMdFilePathsInternal(
async function readGeminiMdFiles(
filePaths: string[],
debugMode: boolean,
importFormat: 'flat' | 'tree' = 'tree',
): Promise<GeminiFileContent[]> {
const results: GeminiFileContent[] = [];
for (const filePath of filePaths) {
@@ -237,16 +238,19 @@ async function readGeminiMdFiles(
const content = await fs.readFile(filePath, 'utf-8');
// Process imports in the content
const processedContent = await processImports(
const processedResult = await processImports(
content,
path.dirname(filePath),
debugMode,
undefined,
undefined,
importFormat,
);
results.push({ filePath, content: processedContent });
results.push({ filePath, content: processedResult.content });
if (debugMode)
logger.debug(
`Successfully read and processed imports: ${filePath} (Length: ${processedContent.length})`,
`Successfully read and processed imports: ${filePath} (Length: ${processedResult.content.length})`,
);
} catch (error: unknown) {
const isTestEnv = process.env.NODE_ENV === 'test' || process.env.VITEST;
@@ -293,12 +297,13 @@ export async function loadServerHierarchicalMemory(
debugMode: boolean,
fileService: FileDiscoveryService,
extensionContextFilePaths: string[] = [],
importFormat: 'flat' | 'tree' = 'tree',
fileFilteringOptions?: FileFilteringOptions,
maxDirs: number = 200,
): Promise<{ memoryContent: string; fileCount: number }> {
if (debugMode)
logger.debug(
`Loading server hierarchical memory for CWD: ${currentWorkingDirectory}`,
`Loading server hierarchical memory for CWD: ${currentWorkingDirectory} (importFormat: ${importFormat})`,
);
// For the server, homedir() refers to the server process's home.
@@ -317,7 +322,11 @@ export async function loadServerHierarchicalMemory(
if (debugMode) logger.debug('No GEMINI.md files found in hierarchy.');
return { memoryContent: '', fileCount: 0 };
}
const contentsWithPaths = await readGeminiMdFiles(filePaths, debugMode);
const contentsWithPaths = await readGeminiMdFiles(
filePaths,
debugMode,
importFormat,
);
// Pass CWD for relative path display in concatenated content
const combinedInstructions = concatenateInstructions(
contentsWithPaths,