summaryrefslogtreecommitdiff
path: root/packages/core/src
diff options
context:
space:
mode:
authorJacob MacDonald <[email protected]>2025-08-07 14:19:06 -0700
committerGitHub <[email protected]>2025-08-07 21:19:06 +0000
commit19491b7b940912c2fb3fe24b2f189d3fd5668669 (patch)
tree6112b96d342a87bea824caa405e5786715a0ab2f /packages/core/src
parent53f8617b249c9f0443f5082a293a30504a118030 (diff)
avoid loading and initializing CLI config twice in non-interactive mode (#5793)
Diffstat (limited to 'packages/core/src')
-rw-r--r--packages/core/src/config/config.test.ts12
-rw-r--r--packages/core/src/config/config.ts15
2 files changed, 27 insertions, 0 deletions
diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts
index 64692139..8e6ca38f 100644
--- a/packages/core/src/config/config.test.ts
+++ b/packages/core/src/config/config.test.ts
@@ -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', () => {
diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts
index db226c76..473ab5a6 100644
--- a/packages/core/src/config/config.ts
+++ b/packages/core/src/config/config.ts
@@ -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);