Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/cli/src/acp/acpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import * as fs from 'node:fs/promises';
import * as path from 'node:path';
import { ApprovalMode } from '@google/gemini-cli-core/src/policy/types.js';

const startMemoryServiceMock = vi.hoisted(() => vi.fn());

vi.mock('../config/config.js', () => ({
loadCliConfig: vi.fn(),
}));
Expand Down Expand Up @@ -101,6 +103,7 @@ vi.mock(
const actual = await importOriginal();
return {
...actual,
startMemoryService: startMemoryServiceMock,
updatePolicy: vi.fn(),
createPolicyUpdater: vi.fn(),
ReadManyFilesTool: vi.fn(),
Expand Down Expand Up @@ -148,13 +151,16 @@ describe('GeminiAgent', () => {
let agent: GeminiAgent;

beforeEach(() => {
vi.clearAllMocks();
startMemoryServiceMock.mockResolvedValue(undefined);
mockConfig = {
refreshAuth: vi.fn(),
initialize: vi.fn(),
waitForMcpInit: vi.fn(),
getFileSystemService: vi.fn(),
setFileSystemService: vi.fn(),
getContentGeneratorConfig: vi.fn(),
isAutoMemoryEnabled: vi.fn().mockReturnValue(false),
getActiveModel: vi.fn().mockReturnValue('gemini-pro'),
getModel: vi.fn().mockReturnValue('gemini-pro'),
getGeminiClient: vi.fn().mockReturnValue({
Expand Down Expand Up @@ -354,6 +360,34 @@ describe('GeminiAgent', () => {
vi.useRealTimers();
});

it('should start auto memory for new ACP sessions when enabled', async () => {
mockConfig.getContentGeneratorConfig = vi.fn().mockReturnValue({
apiKey: 'test-key',
});
mockConfig.isAutoMemoryEnabled = vi.fn().mockReturnValue(true);

await agent.newSession({
cwd: '/tmp',
mcpServers: [],
});

expect(startMemoryServiceMock).toHaveBeenCalledWith(mockConfig);
});

it('should not start auto memory for new ACP sessions when disabled', async () => {
mockConfig.getContentGeneratorConfig = vi.fn().mockReturnValue({
apiKey: 'test-key',
});
mockConfig.isAutoMemoryEnabled = vi.fn().mockReturnValue(false);

await agent.newSession({
cwd: '/tmp',
mcpServers: [],
});

expect(startMemoryServiceMock).not.toHaveBeenCalled();
});

it('should return modes without plan mode when plan is disabled', async () => {
mockConfig.getContentGeneratorConfig = vi.fn().mockReturnValue({
apiKey: 'test-key',
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/acp/acpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import { randomUUID } from 'node:crypto';
import { loadCliConfig, type CliArgs } from '../config/config.js';
import { runExitCleanup } from '../utils/cleanup.js';
import { SessionSelector } from '../utils/sessionUtils.js';
import { startAutoMemoryIfEnabled } from '../utils/autoMemory.js';

import { CommandHandler } from './commandHandler.js';

Expand Down Expand Up @@ -324,6 +325,7 @@ export class GeminiAgent {

await config.initialize();
startupProfiler.flush(config);
startAutoMemoryIfEnabled(config);

const geminiClient = config.getGeminiClient();
const chat = await geminiClient.startChat();
Expand Down Expand Up @@ -465,6 +467,7 @@ export class GeminiAgent {
// which starts the MCP servers and other heavy resources.
await config.initialize();
startupProfiler.flush(config);
startAutoMemoryIfEnabled(config);

return config;
}
Expand Down
9 changes: 2 additions & 7 deletions packages/cli/src/ui/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ import {
ApiKeyUpdatedEvent,
LegacyAgentProtocol,
type InjectionSource,
startMemoryService,
} from '@google/gemini-cli-core';
import { validateAuthMethod } from '../config/auth.js';
import process from 'node:process';
Expand Down Expand Up @@ -125,6 +124,7 @@ import { type BackgroundTask } from './hooks/useExecutionLifecycle.js';
import { useVim } from './hooks/vim.js';
import { type LoadableSettingScope, SettingScope } from '../config/settings.js';
import { type InitializationResult } from '../core/initializer.js';
import { startAutoMemoryIfEnabled } from '../utils/autoMemory.js';
import { useFocus } from './hooks/useFocus.js';
import { useKeypress, type Key } from './hooks/useKeypress.js';
import { KeypressPriority } from './contexts/KeypressContext.js';
Expand Down Expand Up @@ -486,12 +486,7 @@ export const AppContainer = (props: AppContainerProps) => {
setConfigInitialized(true);
startupProfiler.flush(config);

// Fire-and-forget Auto Memory service (skill extraction from past sessions)
if (config.isAutoMemoryEnabled()) {
startMemoryService(config).catch((e) => {
debugLogger.error('Failed to start memory service:', e);
});
}
startAutoMemoryIfEnabled(config);

const sessionStartSource = resumedSessionData
? SessionStartSource.Resume
Expand Down
21 changes: 21 additions & 0 deletions packages/cli/src/utils/autoMemory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {
debugLogger,
startMemoryService,
type Config,
} from '@google/gemini-cli-core';

export function startAutoMemoryIfEnabled(config: Config): void {
if (!config.isAutoMemoryEnabled()) {
return;
}

startMemoryService(config).catch((e) => {
debugLogger.error('Failed to start memory service:', e);
});
}