summaryrefslogtreecommitdiff
path: root/packages/core/src/config
diff options
context:
space:
mode:
authorMarat Boshernitsan <[email protected]>2025-06-12 17:17:29 -0700
committerGitHub <[email protected]>2025-06-12 17:17:29 -0700
commit181abde2ffa8f1f68b6c540a5600346116cb5145 (patch)
tree0081aeb6e48116865ed7d081024fc789dfae8c80 /packages/core/src/config
parent3c3da655b0fd4dafce7a642c4112e2375e3fa02f (diff)
Reduce coupling between core and cli packages (#961)
Co-authored-by: Marat Boshernitsan <[email protected]>
Diffstat (limited to 'packages/core/src/config')
-rw-r--r--packages/core/src/config/config.test.ts1
-rw-r--r--packages/core/src/config/config.ts56
2 files changed, 17 insertions, 40 deletions
diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts
index 2827f581..71af832b 100644
--- a/packages/core/src/config/config.test.ts
+++ b/packages/core/src/config/config.test.ts
@@ -51,6 +51,7 @@ describe('Server Config (config.ts)', () => {
const EMBEDDING_MODEL = 'gemini-embedding';
const SESSION_ID = 'test-session-id';
const baseParams: ConfigParameters = {
+ cwd: '/tmp',
contentGeneratorConfig: {
apiKey: API_KEY,
model: MODEL,
diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts
index b94a88a4..3bb9815f 100644
--- a/packages/core/src/config/config.ts
+++ b/packages/core/src/config/config.ts
@@ -4,11 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import * as dotenv from 'dotenv';
-import * as fs from 'node:fs';
import * as path from 'node:path';
import process from 'node:process';
-import * as os from 'node:os';
import { ContentGeneratorConfig } from '../core/contentGenerator.js';
import { ToolRegistry } from '../tools/tool-registry.js';
import { LSTool } from '../tools/ls.js';
@@ -79,9 +76,12 @@ export interface ConfigParameters {
accessibility?: AccessibilitySettings;
telemetry?: boolean;
telemetryLogUserPromptsEnabled?: boolean;
+ telemetryOtlpEndpoint?: string;
fileFilteringRespectGitIgnore?: boolean;
fileFilteringAllowBuildArtifacts?: boolean;
checkpoint?: boolean;
+ proxy?: string;
+ cwd: string;
}
export class Config {
@@ -115,6 +115,8 @@ export class Config {
private fileDiscoveryService: FileDiscoveryService | null = null;
private gitService: GitService | undefined = undefined;
private readonly checkpoint: boolean;
+ private readonly proxy: string | undefined;
+ private readonly cwd: string;
constructor(params: ConfigParameters) {
this.sessionId = params.sessionId;
@@ -140,12 +142,14 @@ export class Config {
this.telemetryLogUserPromptsEnabled =
params.telemetryLogUserPromptsEnabled ?? true;
this.telemetryOtlpEndpoint =
- process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? 'http://localhost:4317';
+ params.telemetryOtlpEndpoint ?? 'http://localhost:4317';
this.fileFilteringRespectGitIgnore =
params.fileFilteringRespectGitIgnore ?? true;
this.fileFilteringAllowBuildArtifacts =
params.fileFilteringAllowBuildArtifacts ?? false;
this.checkpoint = params.checkpoint ?? false;
+ this.proxy = params.proxy;
+ this.cwd = params.cwd ?? process.cwd();
if (params.contextFileName) {
setGeminiMdFilename(params.contextFileName);
@@ -297,6 +301,14 @@ export class Config {
return this.checkpoint;
}
+ getProxy(): string | undefined {
+ return this.proxy;
+ }
+
+ getWorkingDir(): string {
+ return this.cwd;
+ }
+
async getFileService(): Promise<FileDiscoveryService> {
if (!this.fileDiscoveryService) {
this.fileDiscoveryService = new FileDiscoveryService(this.targetDir);
@@ -317,42 +329,6 @@ 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 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 });
- }
-}
-
export function createToolRegistry(config: Config): Promise<ToolRegistry> {
const registry = new ToolRegistry(config);
const targetDir = config.getTargetDir();