sync gemini-cli 0.1.17

Co-Authored-By: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Yiheng Xu
2025-08-05 16:44:06 +08:00
235 changed files with 16997 additions and 3736 deletions

View File

@@ -47,9 +47,11 @@ import { ClearcutLogger } from '../telemetry/clearcut-logger/clearcut-logger.js'
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
import { MCPOAuthConfig } from '../mcp/oauth-provider.js';
import { IdeClient } from '../ide/ide-client.js';
import type { Content } from '@google/genai';
// Re-export OAuth config type
export type { MCPOAuthConfig };
import { WorkspaceContext } from '../utils/workspaceContext.js';
export enum ApprovalMode {
DEFAULT = 'default',
@@ -81,6 +83,7 @@ export interface GeminiCLIExtension {
name: string;
version: string;
isActive: boolean;
path: string;
}
export interface FileFilteringOptions {
respectGitIgnore: boolean;
@@ -171,6 +174,7 @@ export interface ConfigParameters {
proxy?: string;
cwd: string;
fileDiscoveryService?: FileDiscoveryService;
includeDirectories?: string[];
bugCommand?: BugCommandSettings;
model: string;
extensionContextFilePaths?: string[];
@@ -183,6 +187,7 @@ export interface ConfigParameters {
blockedMcpServers?: Array<{ name: string; extensionName: string }>;
noBrowser?: boolean;
summarizeToolOutput?: Record<string, SummarizeToolOutputSettings>;
ideModeFeature?: boolean;
ideMode?: boolean;
ideClient?: IdeClient;
enableOpenAILogging?: boolean;
@@ -206,6 +211,7 @@ export class Config {
private readonly embeddingModel: string;
private readonly sandbox: SandboxConfig | undefined;
private readonly targetDir: string;
private workspaceContext: WorkspaceContext;
private readonly debugMode: boolean;
private readonly question: string | undefined;
private readonly fullContext: boolean;
@@ -237,14 +243,15 @@ export class Config {
private readonly model: string;
private readonly extensionContextFilePaths: string[];
private readonly noBrowser: boolean;
private readonly ideMode: boolean;
private readonly ideClient: IdeClient | undefined;
private readonly ideModeFeature: boolean;
private ideMode: boolean;
private ideClient: IdeClient;
private inFallbackMode = false;
private readonly systemPromptMappings?: Array<{
baseUrls?: string[];
modelNames?: string[];
template?: string;
}>;
private modelSwitchedDuringSession: boolean = false;
private readonly maxSessionTurns: number;
private readonly sessionTokenLimit: number;
private readonly maxFolderItems: number;
@@ -272,6 +279,10 @@ export class Config {
params.embeddingModel ?? DEFAULT_GEMINI_EMBEDDING_MODEL;
this.sandbox = params.sandbox;
this.targetDir = path.resolve(params.targetDir);
this.workspaceContext = new WorkspaceContext(
this.targetDir,
params.includeDirectories ?? [],
);
this.debugMode = params.debugMode;
this.question = params.question;
this.fullContext = params.fullContext ?? false;
@@ -317,8 +328,11 @@ export class Config {
this._blockedMcpServers = params.blockedMcpServers ?? [];
this.noBrowser = params.noBrowser ?? false;
this.summarizeToolOutput = params.summarizeToolOutput;
this.ideModeFeature = params.ideModeFeature ?? false;
this.ideMode = params.ideMode ?? false;
this.ideClient = params.ideClient;
this.ideClient =
params.ideClient ??
IdeClient.getInstance(this.ideMode && this.ideModeFeature);
this.systemPromptMappings = params.systemPromptMappings;
this.enableOpenAILogging = params.enableOpenAILogging ?? false;
this.sampling_params = params.sampling_params;
@@ -352,16 +366,33 @@ export class Config {
}
async refreshAuth(authMethod: AuthType) {
this.contentGeneratorConfig = createContentGeneratorConfig(
// Save the current conversation history before creating a new client
let existingHistory: Content[] = [];
if (this.geminiClient && this.geminiClient.isInitialized()) {
existingHistory = this.geminiClient.getHistory();
}
// Create new content generator config
const newContentGeneratorConfig = createContentGeneratorConfig(
this,
authMethod,
);
this.geminiClient = new GeminiClient(this);
await this.geminiClient.initialize(this.contentGeneratorConfig);
// Create and initialize new client in local variable first
const newGeminiClient = new GeminiClient(this);
await newGeminiClient.initialize(newContentGeneratorConfig);
// Only assign to instance properties after successful initialization
this.contentGeneratorConfig = newContentGeneratorConfig;
this.geminiClient = newGeminiClient;
// Restore the conversation history to the new client
if (existingHistory.length > 0) {
this.geminiClient.setHistory(existingHistory);
}
// Reset the session flag since we're explicitly changing auth and using default model
this.modelSwitchedDuringSession = false;
this.inFallbackMode = false;
}
getSessionId(): string {
@@ -379,19 +410,15 @@ export class Config {
setModel(newModel: string): void {
if (this.contentGeneratorConfig) {
this.contentGeneratorConfig.model = newModel;
this.modelSwitchedDuringSession = true;
}
}
isModelSwitchedDuringSession(): boolean {
return this.modelSwitchedDuringSession;
isInFallbackMode(): boolean {
return this.inFallbackMode;
}
resetModelToDefault(): void {
if (this.contentGeneratorConfig) {
this.contentGeneratorConfig.model = this.model; // Reset to the original default model
this.modelSwitchedDuringSession = false;
}
setFallbackMode(active: boolean): void {
this.inFallbackMode = active;
}
setFlashFallbackHandler(handler: FlashFallbackHandler): void {
@@ -426,6 +453,17 @@ export class Config {
return this.sandbox;
}
isRestrictiveSandbox(): boolean {
const sandboxConfig = this.getSandbox();
const seatbeltProfile = process.env.SEATBELT_PROFILE;
return (
!!sandboxConfig &&
sandboxConfig.command === 'sandbox-exec' &&
!!seatbeltProfile &&
seatbeltProfile.startsWith('restrictive-')
);
}
getTargetDir(): string {
return this.targetDir;
}
@@ -434,6 +472,10 @@ export class Config {
return this.targetDir;
}
getWorkspaceContext(): WorkspaceContext {
return this.workspaceContext;
}
getToolRegistry(): Promise<ToolRegistry> {
return Promise.resolve(this.toolRegistry);
}
@@ -620,12 +662,28 @@ export class Config {
return this.summarizeToolOutput;
}
getIdeModeFeature(): boolean {
return this.ideModeFeature;
}
getIdeClient(): IdeClient {
return this.ideClient;
}
getIdeMode(): boolean {
return this.ideMode;
}
getIdeClient(): IdeClient | undefined {
return this.ideClient;
setIdeMode(value: boolean): void {
this.ideMode = value;
}
setIdeClientDisconnected(): void {
this.ideClient.setDisconnected();
}
setIdeClientConnected(): void {
this.ideClient.reconnect(this.ideMode && this.ideModeFeature);
}
getEnableOpenAILogging(): boolean {