mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 13:22:35 -07:00
fix(acp): resolve agent mode disconnect and improve mode awareness (#26332)
This commit is contained in:
@@ -33,6 +33,10 @@ export class GeminiAgent {
|
||||
this.sessionManager = new AcpSessionManager(settings, argv, connection);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.sessionManager.dispose();
|
||||
}
|
||||
|
||||
async initialize(
|
||||
args: acp.InitializeRequest,
|
||||
): Promise<acp.InitializeResponse> {
|
||||
|
||||
@@ -564,4 +564,26 @@ describe('Session', () => {
|
||||
|
||||
expect(result.stopReason).toBe('max_turn_requests');
|
||||
});
|
||||
|
||||
it('should send sessionUpdate when approval mode changes', async () => {
|
||||
const { coreEvents, CoreEvent, ApprovalMode } = await import(
|
||||
'@google/gemini-cli-core'
|
||||
);
|
||||
|
||||
coreEvents.emit(CoreEvent.ApprovalModeChanged, {
|
||||
sessionId: 'session-1',
|
||||
mode: ApprovalMode.PLAN,
|
||||
});
|
||||
|
||||
expect(mockConnection.sessionUpdate).toHaveBeenCalledWith({
|
||||
sessionId: 'session-1',
|
||||
update: {
|
||||
sessionUpdate: 'agent_message_chunk',
|
||||
content: {
|
||||
type: 'text',
|
||||
text: `[MODE_UPDATE] ${ApprovalMode.PLAN}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,6 +8,9 @@ import {
|
||||
type ApprovalMode,
|
||||
type ConversationRecord,
|
||||
CoreToolCallStatus,
|
||||
coreEvents,
|
||||
CoreEvent,
|
||||
type ApprovalModeChangedPayload,
|
||||
logToolCall,
|
||||
convertToFunctionResponse,
|
||||
ToolConfirmationOutcome,
|
||||
@@ -69,7 +72,31 @@ export class Session {
|
||||
private readonly context: AgentLoopContext,
|
||||
private readonly connection: acp.AgentSideConnection,
|
||||
private readonly settings: LoadedSettings,
|
||||
) {}
|
||||
) {
|
||||
coreEvents.on(
|
||||
CoreEvent.ApprovalModeChanged,
|
||||
this.handleApprovalModeChanged,
|
||||
);
|
||||
}
|
||||
|
||||
private handleApprovalModeChanged = (payload: ApprovalModeChangedPayload) => {
|
||||
if (payload.sessionId === this.id) {
|
||||
void this.sendUpdate({
|
||||
sessionUpdate: 'agent_message_chunk',
|
||||
content: {
|
||||
type: 'text',
|
||||
text: `[MODE_UPDATE] ${payload.mode}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
dispose(): void {
|
||||
coreEvents.off(
|
||||
CoreEvent.ApprovalModeChanged,
|
||||
this.handleApprovalModeChanged,
|
||||
);
|
||||
}
|
||||
|
||||
async cancelPendingPrompt(): Promise<void> {
|
||||
if (!this.pendingPrompt) {
|
||||
|
||||
@@ -48,6 +48,13 @@ export class AcpSessionManager {
|
||||
return this.sessions.get(sessionId);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
for (const session of this.sessions.values()) {
|
||||
session.dispose();
|
||||
}
|
||||
this.sessions.clear();
|
||||
}
|
||||
|
||||
async newSession(
|
||||
{ cwd, mcpServers }: acp.NewSessionRequest,
|
||||
authDetails: AuthDetails,
|
||||
@@ -183,6 +190,12 @@ export class AcpSessionManager {
|
||||
this.connection,
|
||||
this.settings,
|
||||
);
|
||||
|
||||
const existingSession = this.sessions.get(sessionId);
|
||||
if (existingSession) {
|
||||
existingSession.dispose();
|
||||
}
|
||||
|
||||
this.sessions.set(sessionId, session);
|
||||
|
||||
// Stream history back to client
|
||||
|
||||
Reference in New Issue
Block a user