diff options
| author | Olcan <[email protected]> | 2025-06-02 14:16:48 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-02 14:16:48 -0700 |
| commit | 8365c8f954b2732be3ec9441f8464117d4c0cb93 (patch) | |
| tree | 7a29ed4ef13b2cef8ff2b80b56d5e886ed064bb7 /packages/core/src | |
| parent | 7f20425c98d5adb5531e6c33ed92975b71b34c90 (diff) | |
prefer to load gemini-specific .env file from .gemini folder when it exists there (#697)
Diffstat (limited to 'packages/core/src')
| -rw-r--r-- | packages/core/src/config/config.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 71c4a7d2..dc77208c 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -21,6 +21,7 @@ import { WebFetchTool } from '../tools/web-fetch.js'; import { ReadManyFilesTool } from '../tools/read-many-files.js'; import { MemoryTool, setGeminiMdFilename } from '../tools/memoryTool.js'; import { WebSearchTool } from '../tools/web-search.js'; +import { GEMINI_CONFIG_DIR as GEMINI_DIR } from '../tools/memoryTool.js'; export enum ApprovalMode { DEFAULT = 'default', @@ -204,13 +205,22 @@ export class Config { function findEnvFile(startDir: string): string | null { let currentDir = path.resolve(startDir); while (true) { + // prefer gemini-specific .env under GEMINI_DIR + const geminiEnvPath = path.join(currentDir, GEMINI_DIR, '.env'); + if (fs.existsSync(geminiEnvPath)) { + return geminiEnvPath; + } const envPath = path.join(currentDir, '.env'); if (fs.existsSync(envPath)) { return envPath; } const parentDir = path.dirname(currentDir); if (parentDir === currentDir || !parentDir) { - // check ~/.env as fallback + // check .env under home as fallback, again preferring gemini-specific .env + const homeGeminiEnvPath = path.join(os.homedir(), GEMINI_DIR, '.env'); + if (fs.existsSync(homeGeminiEnvPath)) { + return homeGeminiEnvPath; + } const homeEnvPath = path.join(os.homedir(), '.env'); if (fs.existsSync(homeEnvPath)) { return homeEnvPath; |
