fix(config): Resolve duplicate config loading from home directory (#5090)

Co-authored-by: Allen Hutchison <adh@google.com>
Co-authored-by: Allen Hutchison <allen@hutchison.org>
This commit is contained in:
TIRUMALASETTI PRANITH
2025-08-02 03:52:17 +05:30
committed by GitHub
parent 387706607d
commit 15a1f1af9d
4 changed files with 117 additions and 110 deletions

View File

@@ -4,6 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
import * as fs from 'fs';
import * as path from 'path';
import { homedir } from 'node:os';
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import process from 'node:process';
@@ -244,16 +247,24 @@ export async function loadHierarchicalGeminiMemory(
memoryImportFormat: 'flat' | 'tree' = 'tree',
fileFilteringOptions?: FileFilteringOptions,
): Promise<{ memoryContent: string; fileCount: number }> {
// FIX: Use real, canonical paths for a reliable comparison to handle symlinks.
const realCwd = fs.realpathSync(path.resolve(currentWorkingDirectory));
const realHome = fs.realpathSync(path.resolve(homedir()));
const isHomeDirectory = realCwd === realHome;
// If it is the home directory, pass an empty string to the core memory
// function to signal that it should skip the workspace search.
const effectiveCwd = isHomeDirectory ? '' : currentWorkingDirectory;
if (debugMode) {
logger.debug(
`CLI: Delegating hierarchical memory load to server for CWD: ${currentWorkingDirectory} (memoryImportFormat: ${memoryImportFormat})`,
);
}
// Directly call the server function.
// The server function will use its own homedir() for the global path.
// Directly call the server function with the corrected path.
return loadServerHierarchicalMemory(
currentWorkingDirectory,
effectiveCwd,
debugMode,
fileService,
extensionContextFilePaths,