feat(cli): add support for --prompt-interactive/-i flag (#1743)
This commit is contained in:
parent
5b5f496436
commit
5b6608ad84
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { loadCliConfig } from './config.js';
|
import { loadCliConfig, parseArguments } from './config.js';
|
||||||
import { Settings } from './settings.js';
|
import { Settings } from './settings.js';
|
||||||
import { Extension } from './extension.js';
|
import { Extension } from './extension.js';
|
||||||
import * as ServerConfig from '@google/gemini-cli-core';
|
import * as ServerConfig from '@google/gemini-cli-core';
|
||||||
|
@ -46,6 +46,100 @@ vi.mock('@google/gemini-cli-core', async () => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('parseArguments', () => {
|
||||||
|
const originalArgv = process.argv;
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
process.argv = originalArgv;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error when both --prompt and --prompt-interactive are used together', async () => {
|
||||||
|
process.argv = [
|
||||||
|
'node',
|
||||||
|
'script.js',
|
||||||
|
'--prompt',
|
||||||
|
'test prompt',
|
||||||
|
'--prompt-interactive',
|
||||||
|
'interactive prompt',
|
||||||
|
];
|
||||||
|
|
||||||
|
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
|
||||||
|
throw new Error('process.exit called');
|
||||||
|
});
|
||||||
|
|
||||||
|
const mockConsoleError = vi
|
||||||
|
.spyOn(console, 'error')
|
||||||
|
.mockImplementation(() => {});
|
||||||
|
|
||||||
|
await expect(parseArguments()).rejects.toThrow('process.exit called');
|
||||||
|
|
||||||
|
expect(mockConsoleError).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
'Cannot use both --prompt (-p) and --prompt-interactive (-i) together',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
mockExit.mockRestore();
|
||||||
|
mockConsoleError.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error when using short flags -p and -i together', async () => {
|
||||||
|
process.argv = [
|
||||||
|
'node',
|
||||||
|
'script.js',
|
||||||
|
'-p',
|
||||||
|
'test prompt',
|
||||||
|
'-i',
|
||||||
|
'interactive prompt',
|
||||||
|
];
|
||||||
|
|
||||||
|
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
|
||||||
|
throw new Error('process.exit called');
|
||||||
|
});
|
||||||
|
|
||||||
|
const mockConsoleError = vi
|
||||||
|
.spyOn(console, 'error')
|
||||||
|
.mockImplementation(() => {});
|
||||||
|
|
||||||
|
await expect(parseArguments()).rejects.toThrow('process.exit called');
|
||||||
|
|
||||||
|
expect(mockConsoleError).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
'Cannot use both --prompt (-p) and --prompt-interactive (-i) together',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
mockExit.mockRestore();
|
||||||
|
mockConsoleError.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow --prompt without --prompt-interactive', async () => {
|
||||||
|
process.argv = ['node', 'script.js', '--prompt', 'test prompt'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
expect(argv.prompt).toBe('test prompt');
|
||||||
|
expect(argv.promptInteractive).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow --prompt-interactive without --prompt', async () => {
|
||||||
|
process.argv = [
|
||||||
|
'node',
|
||||||
|
'script.js',
|
||||||
|
'--prompt-interactive',
|
||||||
|
'interactive prompt',
|
||||||
|
];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
expect(argv.promptInteractive).toBe('interactive prompt');
|
||||||
|
expect(argv.prompt).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow -i flag as alias for --prompt-interactive', async () => {
|
||||||
|
process.argv = ['node', 'script.js', '-i', 'interactive prompt'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
expect(argv.promptInteractive).toBe('interactive prompt');
|
||||||
|
expect(argv.prompt).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('loadCliConfig', () => {
|
describe('loadCliConfig', () => {
|
||||||
const originalArgv = process.argv;
|
const originalArgv = process.argv;
|
||||||
const originalEnv = { ...process.env };
|
const originalEnv = { ...process.env };
|
||||||
|
@ -64,29 +158,33 @@ describe('loadCliConfig', () => {
|
||||||
|
|
||||||
it('should set showMemoryUsage to true when --show-memory-usage flag is present', async () => {
|
it('should set showMemoryUsage to true when --show-memory-usage flag is present', async () => {
|
||||||
process.argv = ['node', 'script.js', '--show-memory-usage'];
|
process.argv = ['node', 'script.js', '--show-memory-usage'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {};
|
const settings: Settings = {};
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getShowMemoryUsage()).toBe(true);
|
expect(config.getShowMemoryUsage()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set showMemoryUsage to false when --memory flag is not present', async () => {
|
it('should set showMemoryUsage to false when --memory flag is not present', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {};
|
const settings: Settings = {};
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getShowMemoryUsage()).toBe(false);
|
expect(config.getShowMemoryUsage()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set showMemoryUsage to false by default from settings if CLI flag is not present', async () => {
|
it('should set showMemoryUsage to false by default from settings if CLI flag is not present', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { showMemoryUsage: false };
|
const settings: Settings = { showMemoryUsage: false };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getShowMemoryUsage()).toBe(false);
|
expect(config.getShowMemoryUsage()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prioritize CLI flag over settings for showMemoryUsage (CLI true, settings false)', async () => {
|
it('should prioritize CLI flag over settings for showMemoryUsage (CLI true, settings false)', async () => {
|
||||||
process.argv = ['node', 'script.js', '--show-memory-usage'];
|
process.argv = ['node', 'script.js', '--show-memory-usage'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { showMemoryUsage: false };
|
const settings: Settings = { showMemoryUsage: false };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getShowMemoryUsage()).toBe(true);
|
expect(config.getShowMemoryUsage()).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -109,59 +207,67 @@ describe('loadCliConfig telemetry', () => {
|
||||||
|
|
||||||
it('should set telemetry to false by default when no flag or setting is present', async () => {
|
it('should set telemetry to false by default when no flag or setting is present', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {};
|
const settings: Settings = {};
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryEnabled()).toBe(false);
|
expect(config.getTelemetryEnabled()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set telemetry to true when --telemetry flag is present', async () => {
|
it('should set telemetry to true when --telemetry flag is present', async () => {
|
||||||
process.argv = ['node', 'script.js', '--telemetry'];
|
process.argv = ['node', 'script.js', '--telemetry'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {};
|
const settings: Settings = {};
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryEnabled()).toBe(true);
|
expect(config.getTelemetryEnabled()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set telemetry to false when --no-telemetry flag is present', async () => {
|
it('should set telemetry to false when --no-telemetry flag is present', async () => {
|
||||||
process.argv = ['node', 'script.js', '--no-telemetry'];
|
process.argv = ['node', 'script.js', '--no-telemetry'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {};
|
const settings: Settings = {};
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryEnabled()).toBe(false);
|
expect(config.getTelemetryEnabled()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use telemetry value from settings if CLI flag is not present (settings true)', async () => {
|
it('should use telemetry value from settings if CLI flag is not present (settings true)', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { enabled: true } };
|
const settings: Settings = { telemetry: { enabled: true } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryEnabled()).toBe(true);
|
expect(config.getTelemetryEnabled()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use telemetry value from settings if CLI flag is not present (settings false)', async () => {
|
it('should use telemetry value from settings if CLI flag is not present (settings false)', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { enabled: false } };
|
const settings: Settings = { telemetry: { enabled: false } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryEnabled()).toBe(false);
|
expect(config.getTelemetryEnabled()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prioritize --telemetry CLI flag (true) over settings (false)', async () => {
|
it('should prioritize --telemetry CLI flag (true) over settings (false)', async () => {
|
||||||
process.argv = ['node', 'script.js', '--telemetry'];
|
process.argv = ['node', 'script.js', '--telemetry'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { enabled: false } };
|
const settings: Settings = { telemetry: { enabled: false } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryEnabled()).toBe(true);
|
expect(config.getTelemetryEnabled()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prioritize --no-telemetry CLI flag (false) over settings (true)', async () => {
|
it('should prioritize --no-telemetry CLI flag (false) over settings (true)', async () => {
|
||||||
process.argv = ['node', 'script.js', '--no-telemetry'];
|
process.argv = ['node', 'script.js', '--no-telemetry'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { enabled: true } };
|
const settings: Settings = { telemetry: { enabled: true } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryEnabled()).toBe(false);
|
expect(config.getTelemetryEnabled()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use telemetry OTLP endpoint from settings if CLI flag is not present', async () => {
|
it('should use telemetry OTLP endpoint from settings if CLI flag is not present', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {
|
const settings: Settings = {
|
||||||
telemetry: { otlpEndpoint: 'http://settings.example.com' },
|
telemetry: { otlpEndpoint: 'http://settings.example.com' },
|
||||||
};
|
};
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryOtlpEndpoint()).toBe(
|
expect(config.getTelemetryOtlpEndpoint()).toBe(
|
||||||
'http://settings.example.com',
|
'http://settings.example.com',
|
||||||
);
|
);
|
||||||
|
@ -174,26 +280,29 @@ describe('loadCliConfig telemetry', () => {
|
||||||
'--telemetry-otlp-endpoint',
|
'--telemetry-otlp-endpoint',
|
||||||
'http://cli.example.com',
|
'http://cli.example.com',
|
||||||
];
|
];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {
|
const settings: Settings = {
|
||||||
telemetry: { otlpEndpoint: 'http://settings.example.com' },
|
telemetry: { otlpEndpoint: 'http://settings.example.com' },
|
||||||
};
|
};
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryOtlpEndpoint()).toBe('http://cli.example.com');
|
expect(config.getTelemetryOtlpEndpoint()).toBe('http://cli.example.com');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use default endpoint if no OTLP endpoint is provided via CLI or settings', async () => {
|
it('should use default endpoint if no OTLP endpoint is provided via CLI or settings', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { enabled: true } };
|
const settings: Settings = { telemetry: { enabled: true } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryOtlpEndpoint()).toBe('http://localhost:4317');
|
expect(config.getTelemetryOtlpEndpoint()).toBe('http://localhost:4317');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use telemetry target from settings if CLI flag is not present', async () => {
|
it('should use telemetry target from settings if CLI flag is not present', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {
|
const settings: Settings = {
|
||||||
telemetry: { target: ServerConfig.DEFAULT_TELEMETRY_TARGET },
|
telemetry: { target: ServerConfig.DEFAULT_TELEMETRY_TARGET },
|
||||||
};
|
};
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryTarget()).toBe(
|
expect(config.getTelemetryTarget()).toBe(
|
||||||
ServerConfig.DEFAULT_TELEMETRY_TARGET,
|
ServerConfig.DEFAULT_TELEMETRY_TARGET,
|
||||||
);
|
);
|
||||||
|
@ -201,17 +310,19 @@ describe('loadCliConfig telemetry', () => {
|
||||||
|
|
||||||
it('should prioritize --telemetry-target CLI flag over settings', async () => {
|
it('should prioritize --telemetry-target CLI flag over settings', async () => {
|
||||||
process.argv = ['node', 'script.js', '--telemetry-target', 'gcp'];
|
process.argv = ['node', 'script.js', '--telemetry-target', 'gcp'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {
|
const settings: Settings = {
|
||||||
telemetry: { target: ServerConfig.DEFAULT_TELEMETRY_TARGET },
|
telemetry: { target: ServerConfig.DEFAULT_TELEMETRY_TARGET },
|
||||||
};
|
};
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryTarget()).toBe('gcp');
|
expect(config.getTelemetryTarget()).toBe('gcp');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use default target if no target is provided via CLI or settings', async () => {
|
it('should use default target if no target is provided via CLI or settings', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { enabled: true } };
|
const settings: Settings = { telemetry: { enabled: true } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryTarget()).toBe(
|
expect(config.getTelemetryTarget()).toBe(
|
||||||
ServerConfig.DEFAULT_TELEMETRY_TARGET,
|
ServerConfig.DEFAULT_TELEMETRY_TARGET,
|
||||||
);
|
);
|
||||||
|
@ -219,29 +330,33 @@ describe('loadCliConfig telemetry', () => {
|
||||||
|
|
||||||
it('should use telemetry log prompts from settings if CLI flag is not present', async () => {
|
it('should use telemetry log prompts from settings if CLI flag is not present', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { logPrompts: false } };
|
const settings: Settings = { telemetry: { logPrompts: false } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryLogPromptsEnabled()).toBe(false);
|
expect(config.getTelemetryLogPromptsEnabled()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prioritize --telemetry-log-prompts CLI flag (true) over settings (false)', async () => {
|
it('should prioritize --telemetry-log-prompts CLI flag (true) over settings (false)', async () => {
|
||||||
process.argv = ['node', 'script.js', '--telemetry-log-prompts'];
|
process.argv = ['node', 'script.js', '--telemetry-log-prompts'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { logPrompts: false } };
|
const settings: Settings = { telemetry: { logPrompts: false } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryLogPromptsEnabled()).toBe(true);
|
expect(config.getTelemetryLogPromptsEnabled()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prioritize --no-telemetry-log-prompts CLI flag (false) over settings (true)', async () => {
|
it('should prioritize --no-telemetry-log-prompts CLI flag (false) over settings (true)', async () => {
|
||||||
process.argv = ['node', 'script.js', '--no-telemetry-log-prompts'];
|
process.argv = ['node', 'script.js', '--no-telemetry-log-prompts'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { logPrompts: true } };
|
const settings: Settings = { telemetry: { logPrompts: true } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryLogPromptsEnabled()).toBe(false);
|
expect(config.getTelemetryLogPromptsEnabled()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use default log prompts (true) if no value is provided via CLI or settings', async () => {
|
it('should use default log prompts (true) if no value is provided via CLI or settings', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { telemetry: { enabled: true } };
|
const settings: Settings = { telemetry: { enabled: true } };
|
||||||
const config = await loadCliConfig(settings, [], 'test-session');
|
const config = await loadCliConfig(settings, [], 'test-session', argv);
|
||||||
expect(config.getTelemetryLogPromptsEnabled()).toBe(true);
|
expect(config.getTelemetryLogPromptsEnabled()).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -286,7 +401,8 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
await loadCliConfig(settings, extensions, 'session-id');
|
const argv = await parseArguments();
|
||||||
|
await loadCliConfig(settings, extensions, 'session-id', argv);
|
||||||
expect(ServerConfig.loadServerHierarchicalMemory).toHaveBeenCalledWith(
|
expect(ServerConfig.loadServerHierarchicalMemory).toHaveBeenCalledWith(
|
||||||
expect.any(String),
|
expect.any(String),
|
||||||
false,
|
false,
|
||||||
|
@ -346,7 +462,9 @@ describe('mergeMcpServers', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const originalSettings = JSON.parse(JSON.stringify(settings));
|
const originalSettings = JSON.parse(JSON.stringify(settings));
|
||||||
await loadCliConfig(settings, extensions, 'test-session');
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
await loadCliConfig(settings, extensions, 'test-session', argv);
|
||||||
expect(settings).toEqual(originalSettings);
|
expect(settings).toEqual(originalSettings);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -372,7 +490,14 @@ describe('mergeExcludeTools', () => {
|
||||||
contextFiles: [],
|
contextFiles: [],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const config = await loadCliConfig(settings, extensions, 'test-session');
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(
|
||||||
|
settings,
|
||||||
|
extensions,
|
||||||
|
'test-session',
|
||||||
|
argv,
|
||||||
|
);
|
||||||
expect(config.getExcludeTools()).toEqual(
|
expect(config.getExcludeTools()).toEqual(
|
||||||
expect.arrayContaining(['tool1', 'tool2', 'tool3', 'tool4', 'tool5']),
|
expect.arrayContaining(['tool1', 'tool2', 'tool3', 'tool4', 'tool5']),
|
||||||
);
|
);
|
||||||
|
@ -391,7 +516,14 @@ describe('mergeExcludeTools', () => {
|
||||||
contextFiles: [],
|
contextFiles: [],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const config = await loadCliConfig(settings, extensions, 'test-session');
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(
|
||||||
|
settings,
|
||||||
|
extensions,
|
||||||
|
'test-session',
|
||||||
|
argv,
|
||||||
|
);
|
||||||
expect(config.getExcludeTools()).toEqual(
|
expect(config.getExcludeTools()).toEqual(
|
||||||
expect.arrayContaining(['tool1', 'tool2', 'tool3']),
|
expect.arrayContaining(['tool1', 'tool2', 'tool3']),
|
||||||
);
|
);
|
||||||
|
@ -418,7 +550,14 @@ describe('mergeExcludeTools', () => {
|
||||||
contextFiles: [],
|
contextFiles: [],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const config = await loadCliConfig(settings, extensions, 'test-session');
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(
|
||||||
|
settings,
|
||||||
|
extensions,
|
||||||
|
'test-session',
|
||||||
|
argv,
|
||||||
|
);
|
||||||
expect(config.getExcludeTools()).toEqual(
|
expect(config.getExcludeTools()).toEqual(
|
||||||
expect.arrayContaining(['tool1', 'tool2', 'tool3', 'tool4']),
|
expect.arrayContaining(['tool1', 'tool2', 'tool3', 'tool4']),
|
||||||
);
|
);
|
||||||
|
@ -428,14 +567,28 @@ describe('mergeExcludeTools', () => {
|
||||||
it('should return an empty array when no excludeTools are specified', async () => {
|
it('should return an empty array when no excludeTools are specified', async () => {
|
||||||
const settings: Settings = {};
|
const settings: Settings = {};
|
||||||
const extensions: Extension[] = [];
|
const extensions: Extension[] = [];
|
||||||
const config = await loadCliConfig(settings, extensions, 'test-session');
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(
|
||||||
|
settings,
|
||||||
|
extensions,
|
||||||
|
'test-session',
|
||||||
|
argv,
|
||||||
|
);
|
||||||
expect(config.getExcludeTools()).toEqual([]);
|
expect(config.getExcludeTools()).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle settings with excludeTools but no extensions', async () => {
|
it('should handle settings with excludeTools but no extensions', async () => {
|
||||||
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = { excludeTools: ['tool1', 'tool2'] };
|
const settings: Settings = { excludeTools: ['tool1', 'tool2'] };
|
||||||
const extensions: Extension[] = [];
|
const extensions: Extension[] = [];
|
||||||
const config = await loadCliConfig(settings, extensions, 'test-session');
|
const config = await loadCliConfig(
|
||||||
|
settings,
|
||||||
|
extensions,
|
||||||
|
'test-session',
|
||||||
|
argv,
|
||||||
|
);
|
||||||
expect(config.getExcludeTools()).toEqual(
|
expect(config.getExcludeTools()).toEqual(
|
||||||
expect.arrayContaining(['tool1', 'tool2']),
|
expect.arrayContaining(['tool1', 'tool2']),
|
||||||
);
|
);
|
||||||
|
@ -454,7 +607,14 @@ describe('mergeExcludeTools', () => {
|
||||||
contextFiles: [],
|
contextFiles: [],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const config = await loadCliConfig(settings, extensions, 'test-session');
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(
|
||||||
|
settings,
|
||||||
|
extensions,
|
||||||
|
'test-session',
|
||||||
|
argv,
|
||||||
|
);
|
||||||
expect(config.getExcludeTools()).toEqual(
|
expect(config.getExcludeTools()).toEqual(
|
||||||
expect.arrayContaining(['tool1', 'tool2']),
|
expect.arrayContaining(['tool1', 'tool2']),
|
||||||
);
|
);
|
||||||
|
@ -474,7 +634,9 @@ describe('mergeExcludeTools', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const originalSettings = JSON.parse(JSON.stringify(settings));
|
const originalSettings = JSON.parse(JSON.stringify(settings));
|
||||||
await loadCliConfig(settings, extensions, 'test-session');
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
|
await loadCliConfig(settings, extensions, 'test-session', argv);
|
||||||
expect(settings).toEqual(originalSettings);
|
expect(settings).toEqual(originalSettings);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -505,7 +667,8 @@ describe('loadCliConfig with allowed-mcp-server-names', () => {
|
||||||
|
|
||||||
it('should allow all MCP servers if the flag is not provided', async () => {
|
it('should allow all MCP servers if the flag is not provided', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(baseSettings, [], 'test-session', argv);
|
||||||
expect(config.getMcpServers()).toEqual(baseSettings.mcpServers);
|
expect(config.getMcpServers()).toEqual(baseSettings.mcpServers);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -516,7 +679,8 @@ describe('loadCliConfig with allowed-mcp-server-names', () => {
|
||||||
'--allowed-mcp-server-names',
|
'--allowed-mcp-server-names',
|
||||||
'server1',
|
'server1',
|
||||||
];
|
];
|
||||||
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(baseSettings, [], 'test-session', argv);
|
||||||
expect(config.getMcpServers()).toEqual({
|
expect(config.getMcpServers()).toEqual({
|
||||||
server1: { url: 'http://localhost:8080' },
|
server1: { url: 'http://localhost:8080' },
|
||||||
});
|
});
|
||||||
|
@ -531,7 +695,8 @@ describe('loadCliConfig with allowed-mcp-server-names', () => {
|
||||||
'--allowed-mcp-server-names',
|
'--allowed-mcp-server-names',
|
||||||
'server3',
|
'server3',
|
||||||
];
|
];
|
||||||
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(baseSettings, [], 'test-session', argv);
|
||||||
expect(config.getMcpServers()).toEqual({
|
expect(config.getMcpServers()).toEqual({
|
||||||
server1: { url: 'http://localhost:8080' },
|
server1: { url: 'http://localhost:8080' },
|
||||||
server3: { url: 'http://localhost:8082' },
|
server3: { url: 'http://localhost:8082' },
|
||||||
|
@ -547,7 +712,8 @@ describe('loadCliConfig with allowed-mcp-server-names', () => {
|
||||||
'--allowed-mcp-server-names',
|
'--allowed-mcp-server-names',
|
||||||
'server4',
|
'server4',
|
||||||
];
|
];
|
||||||
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(baseSettings, [], 'test-session', argv);
|
||||||
expect(config.getMcpServers()).toEqual({
|
expect(config.getMcpServers()).toEqual({
|
||||||
server1: { url: 'http://localhost:8080' },
|
server1: { url: 'http://localhost:8080' },
|
||||||
});
|
});
|
||||||
|
@ -555,7 +721,8 @@ describe('loadCliConfig with allowed-mcp-server-names', () => {
|
||||||
|
|
||||||
it('should allow no MCP servers if the flag is provided but empty', async () => {
|
it('should allow no MCP servers if the flag is provided but empty', async () => {
|
||||||
process.argv = ['node', 'script.js', '--allowed-mcp-server-names', ''];
|
process.argv = ['node', 'script.js', '--allowed-mcp-server-names', ''];
|
||||||
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
const argv = await parseArguments();
|
||||||
|
const config = await loadCliConfig(baseSettings, [], 'test-session', argv);
|
||||||
expect(config.getMcpServers()).toEqual({});
|
expect(config.getMcpServers()).toEqual({});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -574,11 +741,13 @@ describe('loadCliConfig extensions', () => {
|
||||||
|
|
||||||
it('should not filter extensions if --extensions flag is not used', async () => {
|
it('should not filter extensions if --extensions flag is not used', async () => {
|
||||||
process.argv = ['node', 'script.js'];
|
process.argv = ['node', 'script.js'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {};
|
const settings: Settings = {};
|
||||||
const config = await loadCliConfig(
|
const config = await loadCliConfig(
|
||||||
settings,
|
settings,
|
||||||
mockExtensions,
|
mockExtensions,
|
||||||
'test-session',
|
'test-session',
|
||||||
|
argv,
|
||||||
);
|
);
|
||||||
expect(config.getExtensionContextFilePaths()).toEqual([
|
expect(config.getExtensionContextFilePaths()).toEqual([
|
||||||
'/path/to/ext1.md',
|
'/path/to/ext1.md',
|
||||||
|
@ -588,11 +757,13 @@ describe('loadCliConfig extensions', () => {
|
||||||
|
|
||||||
it('should filter extensions if --extensions flag is used', async () => {
|
it('should filter extensions if --extensions flag is used', async () => {
|
||||||
process.argv = ['node', 'script.js', '--extensions', 'ext1'];
|
process.argv = ['node', 'script.js', '--extensions', 'ext1'];
|
||||||
|
const argv = await parseArguments();
|
||||||
const settings: Settings = {};
|
const settings: Settings = {};
|
||||||
const config = await loadCliConfig(
|
const config = await loadCliConfig(
|
||||||
settings,
|
settings,
|
||||||
mockExtensions,
|
mockExtensions,
|
||||||
'test-session',
|
'test-session',
|
||||||
|
argv,
|
||||||
);
|
);
|
||||||
expect(config.getExtensionContextFilePaths()).toEqual(['/path/to/ext1.md']);
|
expect(config.getExtensionContextFilePaths()).toEqual(['/path/to/ext1.md']);
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,12 +34,13 @@ const logger = {
|
||||||
error: (...args: any[]) => console.error('[ERROR]', ...args),
|
error: (...args: any[]) => console.error('[ERROR]', ...args),
|
||||||
};
|
};
|
||||||
|
|
||||||
interface CliArgs {
|
export interface CliArgs {
|
||||||
model: string | undefined;
|
model: string | undefined;
|
||||||
sandbox: boolean | string | undefined;
|
sandbox: boolean | string | undefined;
|
||||||
sandboxImage: string | undefined;
|
sandboxImage: string | undefined;
|
||||||
debug: boolean | undefined;
|
debug: boolean | undefined;
|
||||||
prompt: string | undefined;
|
prompt: string | undefined;
|
||||||
|
promptInteractive: string | undefined;
|
||||||
allFiles: boolean | undefined;
|
allFiles: boolean | undefined;
|
||||||
all_files: boolean | undefined;
|
all_files: boolean | undefined;
|
||||||
showMemoryUsage: boolean | undefined;
|
showMemoryUsage: boolean | undefined;
|
||||||
|
@ -55,7 +56,7 @@ interface CliArgs {
|
||||||
listExtensions: boolean | undefined;
|
listExtensions: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function parseArguments(): Promise<CliArgs> {
|
export async function parseArguments(): Promise<CliArgs> {
|
||||||
const yargsInstance = yargs(hideBin(process.argv))
|
const yargsInstance = yargs(hideBin(process.argv))
|
||||||
.scriptName('gemini')
|
.scriptName('gemini')
|
||||||
.usage(
|
.usage(
|
||||||
|
@ -73,6 +74,12 @@ async function parseArguments(): Promise<CliArgs> {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'Prompt. Appended to input on stdin (if any).',
|
description: 'Prompt. Appended to input on stdin (if any).',
|
||||||
})
|
})
|
||||||
|
.option('prompt-interactive', {
|
||||||
|
alias: 'i',
|
||||||
|
type: 'string',
|
||||||
|
description:
|
||||||
|
'Execute the provided prompt and continue in interactive mode',
|
||||||
|
})
|
||||||
.option('sandbox', {
|
.option('sandbox', {
|
||||||
alias: 's',
|
alias: 's',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
@ -173,10 +180,17 @@ async function parseArguments(): Promise<CliArgs> {
|
||||||
.alias('v', 'version')
|
.alias('v', 'version')
|
||||||
.help()
|
.help()
|
||||||
.alias('h', 'help')
|
.alias('h', 'help')
|
||||||
.strict();
|
.strict()
|
||||||
|
.check((argv) => {
|
||||||
|
if (argv.prompt && argv.promptInteractive) {
|
||||||
|
throw new Error(
|
||||||
|
'Cannot use both --prompt (-p) and --prompt-interactive (-i) together',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
yargsInstance.wrap(yargsInstance.terminalWidth());
|
yargsInstance.wrap(yargsInstance.terminalWidth());
|
||||||
|
|
||||||
return yargsInstance.argv;
|
return yargsInstance.argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,8 +222,8 @@ export async function loadCliConfig(
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
extensions: Extension[],
|
extensions: Extension[],
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
|
argv: CliArgs,
|
||||||
): Promise<Config> {
|
): Promise<Config> {
|
||||||
const argv = await parseArguments();
|
|
||||||
const debugMode =
|
const debugMode =
|
||||||
argv.debug ||
|
argv.debug ||
|
||||||
[process.env.DEBUG, process.env.DEBUG_MODE].some(
|
[process.env.DEBUG, process.env.DEBUG_MODE].some(
|
||||||
|
@ -267,7 +281,7 @@ export async function loadCliConfig(
|
||||||
sandbox: sandboxConfig,
|
sandbox: sandboxConfig,
|
||||||
targetDir: process.cwd(),
|
targetDir: process.cwd(),
|
||||||
debugMode,
|
debugMode,
|
||||||
question: argv.prompt || '',
|
question: argv.promptInteractive || argv.prompt || '',
|
||||||
fullContext: argv.allFiles || argv.all_files || false,
|
fullContext: argv.allFiles || argv.all_files || false,
|
||||||
coreTools: settings.coreTools || undefined,
|
coreTools: settings.coreTools || undefined,
|
||||||
excludeTools,
|
excludeTools,
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from 'ink';
|
import { render } from 'ink';
|
||||||
import { AppWrapper } from './ui/App.js';
|
import { AppWrapper } from './ui/App.js';
|
||||||
import { loadCliConfig } from './config/config.js';
|
import { loadCliConfig, parseArguments, CliArgs } from './config/config.js';
|
||||||
import { readStdin } from './utils/readStdin.js';
|
import { readStdin } from './utils/readStdin.js';
|
||||||
import { basename } from 'node:path';
|
import { basename } from 'node:path';
|
||||||
import v8 from 'node:v8';
|
import v8 from 'node:v8';
|
||||||
|
@ -102,8 +102,21 @@ export async function main() {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const argv = await parseArguments();
|
||||||
const extensions = loadExtensions(workspaceRoot);
|
const extensions = loadExtensions(workspaceRoot);
|
||||||
const config = await loadCliConfig(settings.merged, extensions, sessionId);
|
const config = await loadCliConfig(
|
||||||
|
settings.merged,
|
||||||
|
extensions,
|
||||||
|
sessionId,
|
||||||
|
argv,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (argv.promptInteractive && !process.stdin.isTTY) {
|
||||||
|
console.error(
|
||||||
|
'Error: The --prompt-interactive flag is not supported when piping input from stdin.',
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (config.getListExtensions()) {
|
if (config.getListExtensions()) {
|
||||||
console.log('Installed extensions:');
|
console.log('Installed extensions:');
|
||||||
|
@ -182,8 +195,11 @@ export async function main() {
|
||||||
...(await getUserStartupWarnings(workspaceRoot)),
|
...(await getUserStartupWarnings(workspaceRoot)),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const shouldBeInteractive =
|
||||||
|
!!argv.promptInteractive || (process.stdin.isTTY && input?.length === 0);
|
||||||
|
|
||||||
// Render UI, passing necessary config values. Check that there is no command line question.
|
// Render UI, passing necessary config values. Check that there is no command line question.
|
||||||
if (process.stdin.isTTY && input?.length === 0) {
|
if (shouldBeInteractive) {
|
||||||
const version = await getCliVersion();
|
const version = await getCliVersion();
|
||||||
setWindowTitle(basename(workspaceRoot), settings);
|
setWindowTitle(basename(workspaceRoot), settings);
|
||||||
render(
|
render(
|
||||||
|
@ -224,6 +240,7 @@ export async function main() {
|
||||||
config,
|
config,
|
||||||
extensions,
|
extensions,
|
||||||
settings,
|
settings,
|
||||||
|
argv,
|
||||||
);
|
);
|
||||||
|
|
||||||
await runNonInteractive(nonInteractiveConfig, input, prompt_id);
|
await runNonInteractive(nonInteractiveConfig, input, prompt_id);
|
||||||
|
@ -264,6 +281,7 @@ async function loadNonInteractiveConfig(
|
||||||
config: Config,
|
config: Config,
|
||||||
extensions: Extension[],
|
extensions: Extension[],
|
||||||
settings: LoadedSettings,
|
settings: LoadedSettings,
|
||||||
|
argv: CliArgs,
|
||||||
) {
|
) {
|
||||||
let finalConfig = config;
|
let finalConfig = config;
|
||||||
if (config.getApprovalMode() !== ApprovalMode.YOLO) {
|
if (config.getApprovalMode() !== ApprovalMode.YOLO) {
|
||||||
|
@ -287,6 +305,7 @@ async function loadNonInteractiveConfig(
|
||||||
nonInteractiveSettings,
|
nonInteractiveSettings,
|
||||||
extensions,
|
extensions,
|
||||||
config.getSessionId(),
|
config.getSessionId(),
|
||||||
|
argv,
|
||||||
);
|
);
|
||||||
await finalConfig.initialize();
|
await finalConfig.initialize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,12 @@ import {
|
||||||
ToolRegistry,
|
ToolRegistry,
|
||||||
AccessibilitySettings,
|
AccessibilitySettings,
|
||||||
SandboxConfig,
|
SandboxConfig,
|
||||||
|
GeminiClient,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import { LoadedSettings, SettingsFile, Settings } from '../config/settings.js';
|
import { LoadedSettings, SettingsFile, Settings } from '../config/settings.js';
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
|
import { useGeminiStream } from './hooks/useGeminiStream.js';
|
||||||
|
import { StreamingState } from './types.js';
|
||||||
import { Tips } from './components/Tips.js';
|
import { Tips } from './components/Tips.js';
|
||||||
|
|
||||||
// Define a more complete mock server config based on actual Config
|
// Define a more complete mock server config based on actual Config
|
||||||
|
@ -67,6 +70,7 @@ interface MockServerConfig {
|
||||||
getAccessibility: Mock<() => AccessibilitySettings>;
|
getAccessibility: Mock<() => AccessibilitySettings>;
|
||||||
getProjectRoot: Mock<() => string | undefined>;
|
getProjectRoot: Mock<() => string | undefined>;
|
||||||
getAllGeminiMdFilenames: Mock<() => string[]>;
|
getAllGeminiMdFilenames: Mock<() => string[]>;
|
||||||
|
getGeminiClient: Mock<() => GeminiClient | undefined>;
|
||||||
getUserTier: Mock<() => Promise<string | undefined>>;
|
getUserTier: Mock<() => Promise<string | undefined>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +128,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||||
getVertexAI: vi.fn(() => opts.vertexai),
|
getVertexAI: vi.fn(() => opts.vertexai),
|
||||||
getShowMemoryUsage: vi.fn(() => opts.showMemoryUsage ?? false),
|
getShowMemoryUsage: vi.fn(() => opts.showMemoryUsage ?? false),
|
||||||
getAccessibility: vi.fn(() => opts.accessibility ?? {}),
|
getAccessibility: vi.fn(() => opts.accessibility ?? {}),
|
||||||
getProjectRoot: vi.fn(() => opts.projectRoot),
|
getProjectRoot: vi.fn(() => opts.targetDir),
|
||||||
getGeminiClient: vi.fn(() => ({})),
|
getGeminiClient: vi.fn(() => ({})),
|
||||||
getCheckpointingEnabled: vi.fn(() => opts.checkpointing ?? true),
|
getCheckpointingEnabled: vi.fn(() => opts.checkpointing ?? true),
|
||||||
getAllGeminiMdFilenames: vi.fn(() => ['GEMINI.md']),
|
getAllGeminiMdFilenames: vi.fn(() => ['GEMINI.md']),
|
||||||
|
@ -508,4 +512,48 @@ describe('App UI', () => {
|
||||||
expect(lastFrame()).not.toContain('Select Theme');
|
expect(lastFrame()).not.toContain('Select Theme');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with initial prompt from --prompt-interactive', () => {
|
||||||
|
it('should submit the initial prompt automatically', async () => {
|
||||||
|
const mockSubmitQuery = vi.fn();
|
||||||
|
|
||||||
|
mockConfig.getQuestion = vi.fn(() => 'hello from prompt-interactive');
|
||||||
|
|
||||||
|
vi.mocked(useGeminiStream).mockReturnValue({
|
||||||
|
streamingState: StreamingState.Idle,
|
||||||
|
submitQuery: mockSubmitQuery,
|
||||||
|
initError: null,
|
||||||
|
pendingHistoryItems: [],
|
||||||
|
thought: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
mockConfig.getGeminiClient.mockReturnValue({
|
||||||
|
isInitialized: vi.fn(() => true),
|
||||||
|
} as unknown as GeminiClient);
|
||||||
|
|
||||||
|
const { unmount, rerender } = render(
|
||||||
|
<App
|
||||||
|
config={mockConfig as unknown as ServerConfig}
|
||||||
|
settings={mockSettings}
|
||||||
|
version={mockVersion}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
// Force a re-render to trigger useEffect
|
||||||
|
rerender(
|
||||||
|
<App
|
||||||
|
config={mockConfig as unknown as ServerConfig}
|
||||||
|
settings={mockSettings}
|
||||||
|
version={mockVersion}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
|
||||||
|
expect(mockSubmitQuery).toHaveBeenCalledWith(
|
||||||
|
'hello from prompt-interactive',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -148,6 +148,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||||
const openPrivacyNotice = useCallback(() => {
|
const openPrivacyNotice = useCallback(() => {
|
||||||
setShowPrivacyNotice(true);
|
setShowPrivacyNotice(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
const initialPromptSubmitted = useRef(false);
|
||||||
|
|
||||||
const errorCount = useMemo(
|
const errorCount = useMemo(
|
||||||
() => consoleMessages.filter((msg) => msg.type === 'error').length,
|
() => consoleMessages.filter((msg) => msg.type === 'error').length,
|
||||||
|
@ -637,6 +638,34 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||||
return getAllGeminiMdFilenames();
|
return getAllGeminiMdFilenames();
|
||||||
}, [settings.merged.contextFileName]);
|
}, [settings.merged.contextFileName]);
|
||||||
|
|
||||||
|
const initialPrompt = useMemo(() => config.getQuestion(), [config]);
|
||||||
|
const geminiClient = config.getGeminiClient();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
initialPrompt &&
|
||||||
|
!initialPromptSubmitted.current &&
|
||||||
|
!isAuthenticating &&
|
||||||
|
!isAuthDialogOpen &&
|
||||||
|
!isThemeDialogOpen &&
|
||||||
|
!isEditorDialogOpen &&
|
||||||
|
!showPrivacyNotice &&
|
||||||
|
geminiClient?.isInitialized?.()
|
||||||
|
) {
|
||||||
|
submitQuery(initialPrompt);
|
||||||
|
initialPromptSubmitted.current = true;
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
initialPrompt,
|
||||||
|
submitQuery,
|
||||||
|
isAuthenticating,
|
||||||
|
isAuthDialogOpen,
|
||||||
|
isThemeDialogOpen,
|
||||||
|
isEditorDialogOpen,
|
||||||
|
showPrivacyNotice,
|
||||||
|
geminiClient,
|
||||||
|
]);
|
||||||
|
|
||||||
if (quittingMessages) {
|
if (quittingMessages) {
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column" marginBottom={1}>
|
<Box flexDirection="column" marginBottom={1}>
|
||||||
|
|
|
@ -134,6 +134,10 @@ export class GeminiClient {
|
||||||
return this.chat;
|
return this.chat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isInitialized(): boolean {
|
||||||
|
return this.chat !== undefined && this.contentGenerator !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
getHistory(): Content[] {
|
getHistory(): Content[] {
|
||||||
return this.getChat().getHistory();
|
return this.getChat().getHistory();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue