summaryrefslogtreecommitdiff
path: root/packages/cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src')
-rw-r--r--packages/cli/src/config/config.integration.test.ts9
-rw-r--r--packages/cli/src/config/config.ts49
-rw-r--r--packages/cli/src/ui/App.test.tsx1
3 files changed, 58 insertions, 1 deletions
diff --git a/packages/cli/src/config/config.integration.test.ts b/packages/cli/src/config/config.integration.test.ts
index 2cbe8c66..99745d29 100644
--- a/packages/cli/src/config/config.integration.test.ts
+++ b/packages/cli/src/config/config.integration.test.ts
@@ -53,6 +53,7 @@ describe('Configuration Integration Tests', () => {
describe('File Filtering Configuration', () => {
it('should load default file filtering settings', async () => {
const configParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: TEST_CONTENT_GENERATOR_CONFIG,
embeddingModel: 'test-embedding-model',
sandbox: false,
@@ -70,6 +71,7 @@ describe('Configuration Integration Tests', () => {
it('should load custom file filtering settings from configuration', async () => {
const configParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: TEST_CONTENT_GENERATOR_CONFIG,
embeddingModel: 'test-embedding-model',
sandbox: false,
@@ -87,6 +89,7 @@ describe('Configuration Integration Tests', () => {
it('should merge user and workspace file filtering settings', async () => {
const configParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: TEST_CONTENT_GENERATOR_CONFIG,
embeddingModel: 'test-embedding-model',
sandbox: false,
@@ -106,6 +109,7 @@ describe('Configuration Integration Tests', () => {
describe('Configuration Integration', () => {
it('should handle partial configuration objects gracefully', async () => {
const configParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: TEST_CONTENT_GENERATOR_CONFIG,
embeddingModel: 'test-embedding-model',
sandbox: false,
@@ -126,6 +130,7 @@ describe('Configuration Integration Tests', () => {
it('should handle empty configuration objects gracefully', async () => {
const configParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: TEST_CONTENT_GENERATOR_CONFIG,
embeddingModel: 'test-embedding-model',
sandbox: false,
@@ -144,6 +149,7 @@ describe('Configuration Integration Tests', () => {
it('should handle missing configuration sections gracefully', async () => {
const configParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: TEST_CONTENT_GENERATOR_CONFIG,
embeddingModel: 'test-embedding-model',
sandbox: false,
@@ -163,6 +169,7 @@ describe('Configuration Integration Tests', () => {
describe('Real-world Configuration Scenarios', () => {
it('should handle a security-focused configuration', async () => {
const configParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: TEST_CONTENT_GENERATOR_CONFIG,
embeddingModel: 'test-embedding-model',
sandbox: false,
@@ -180,6 +187,7 @@ describe('Configuration Integration Tests', () => {
it('should handle a development-focused configuration', async () => {
const configParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: TEST_CONTENT_GENERATOR_CONFIG,
embeddingModel: 'test-embedding-model',
sandbox: false,
@@ -196,6 +204,7 @@ describe('Configuration Integration Tests', () => {
it('should handle a CI/CD environment configuration', async () => {
const configParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: TEST_CONTENT_GENERATOR_CONFIG,
embeddingModel: 'test-embedding-model',
sandbox: false,
diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts
index 2f989883..3ee03c82 100644
--- a/packages/cli/src/config/config.ts
+++ b/packages/cli/src/config/config.ts
@@ -9,16 +9,20 @@ import { hideBin } from 'yargs/helpers';
import process from 'node:process';
import {
Config,
- loadEnvironment,
loadServerHierarchicalMemory,
setGeminiMdFilename as setServerGeminiMdFilename,
getCurrentGeminiMdFilename,
ApprovalMode,
ContentGeneratorConfig,
+ GEMINI_CONFIG_DIR as GEMINI_DIR,
} from '@gemini-cli/core';
import { Settings } from './settings.js';
import { getEffectiveModel } from '../utils/modelCheck.js';
import { ExtensionConfig } from './extension.js';
+import * as dotenv from 'dotenv';
+import * as fs from 'node:fs';
+import * as path from 'node:path';
+import * as os from 'node:os';
// Simple console logger for now - replace with actual logger if available
const logger = {
@@ -196,6 +200,13 @@ export async function loadCliConfig(
fileFilteringAllowBuildArtifacts:
settings.fileFiltering?.allowBuildArtifacts,
checkpoint: argv.checkpoint,
+ proxy:
+ process.env.HTTPS_PROXY ||
+ process.env.https_proxy ||
+ process.env.HTTP_PROXY ||
+ process.env.http_proxy,
+ cwd: process.cwd(),
+ telemetryOtlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
});
}
@@ -259,3 +270,39 @@ async function createContentGeneratorConfig(
return 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 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;
+ }
+ return null;
+ }
+ currentDir = parentDir;
+ }
+}
+
+export function loadEnvironment(): void {
+ const envFilePath = findEnvFile(process.cwd());
+ if (envFilePath) {
+ dotenv.config({ path: envFilePath });
+ }
+}
diff --git a/packages/cli/src/ui/App.test.tsx b/packages/cli/src/ui/App.test.tsx
index bfd2efaf..b8959bfb 100644
--- a/packages/cli/src/ui/App.test.tsx
+++ b/packages/cli/src/ui/App.test.tsx
@@ -194,6 +194,7 @@ describe('App UI', () => {
geminiMdFileCount: 0,
showMemoryUsage: false,
sessionId: 'test-session-id',
+ cwd: '/tmp',
// Provide other required fields for ConfigParameters if necessary
}) as unknown as MockServerConfig;