avoid loading and initializing CLI config twice in non-interactive mode (#5793)

This commit is contained in:
Jacob MacDonald
2025-08-07 14:19:06 -07:00
committed by GitHub
parent 53f8617b24
commit 19491b7b94
6 changed files with 201 additions and 61 deletions

View File

@@ -150,6 +150,18 @@ describe('Server Config (config.ts)', () => {
await expect(config.initialize()).resolves.toBeUndefined();
});
it('should throw an error if initialized more than once', async () => {
const config = new Config({
...baseParams,
checkpointing: false,
});
await expect(config.initialize()).resolves.toBeUndefined();
await expect(config.initialize()).rejects.toThrow(
'Config was already initialized',
);
});
});
describe('refreshAuth', () => {

View File

@@ -197,6 +197,7 @@ export interface ConfigParameters {
ideMode?: boolean;
loadMemoryFromIncludeDirectories?: boolean;
chatCompression?: ChatCompressionSettings;
interactive?: boolean;
}
export class Config {
@@ -260,6 +261,8 @@ export class Config {
private readonly experimentalAcp: boolean = false;
private readonly loadMemoryFromIncludeDirectories: boolean = false;
private readonly chatCompression: ChatCompressionSettings | undefined;
private readonly interactive: boolean;
private initialized: boolean = false;
constructor(params: ConfigParameters) {
this.sessionId = params.sessionId;
@@ -326,6 +329,7 @@ export class Config {
this.loadMemoryFromIncludeDirectories =
params.loadMemoryFromIncludeDirectories ?? false;
this.chatCompression = params.chatCompression;
this.interactive = params.interactive ?? false;
if (params.contextFileName) {
setGeminiMdFilename(params.contextFileName);
@@ -344,7 +348,14 @@ export class Config {
}
}
/**
* Must only be called once, throws if called again.
*/
async initialize(): Promise<void> {
if (this.initialized) {
throw Error('Config was already initialized');
}
this.initialized = true;
// Initialize centralized FileDiscoveryService
this.getFileService();
if (this.getCheckpointingEnabled()) {
@@ -685,6 +696,10 @@ export class Config {
return this.chatCompression;
}
isInteractive(): boolean {
return this.interactive;
}
async getGitService(): Promise<GitService> {
if (!this.gitService) {
this.gitService = new GitService(this.targetDir);