diff options
| author | Allen Hutchison <[email protected]> | 2025-05-31 12:49:28 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-31 12:49:28 -0700 |
| commit | 53bf77849760593cc9c1af9a4fb110a1a74acc4f (patch) | |
| tree | c188b0fa9c295faa198b65d80143491858c18048 /packages/cli/src | |
| parent | cbc1614b8441dc3dcf35cf4f2e6b3c3457045fcb (diff) | |
feat: allow custom filename for context files (#654)
Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/cli/src')
| -rw-r--r-- | packages/cli/src/config/config.ts | 16 | ||||
| -rw-r--r-- | packages/cli/src/config/settings.test.ts | 309 | ||||
| -rw-r--r-- | packages/cli/src/config/settings.ts | 1 | ||||
| -rw-r--r-- | packages/cli/src/ui/App.test.tsx | 289 | ||||
| -rw-r--r-- | packages/cli/src/ui/App.tsx | 11 |
5 files changed, 623 insertions, 3 deletions
diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 04347427..44057fad 100644 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -13,6 +13,8 @@ import { createServerConfig, loadServerHierarchicalMemory, ConfigParameters, + setGeminiMdFilename as setServerGeminiMdFilename, + getCurrentGeminiMdFilename, } from '@gemini-code/core'; import { Settings } from './settings.js'; import { readPackageUp } from 'read-package-up'; @@ -132,6 +134,17 @@ export async function loadCliConfig(settings: Settings): Promise<Config> { const argv = await parseArguments(); const debugMode = argv.debug || false; + // Set the context filename in the server's memoryTool module BEFORE loading memory + // TODO(b/343434939): This is a bit of a hack. The contextFileName should ideally be passed + // directly to the Config constructor in core, and have core handle setGeminiMdFilename. + // However, loadHierarchicalGeminiMemory is called *before* createServerConfig. + if (settings.contextFileName) { + setServerGeminiMdFilename(settings.contextFileName); + } else { + // Reset to default if not provided in settings. + setServerGeminiMdFilename(getCurrentGeminiMdFilename()); + } + // Call the (now wrapper) loadHierarchicalGeminiMemory which calls the server's version const { memoryContent, fileCount } = await loadHierarchicalGeminiMemory( process.cwd(), @@ -159,7 +172,8 @@ export async function loadCliConfig(settings: Settings): Promise<Config> { userMemory: memoryContent, geminiMdFileCount: fileCount, vertexai: useVertexAI, - showMemoryUsage: argv.show_memory_usage || false, + showMemoryUsage: + argv.show_memory_usage || settings.showMemoryUsage || false, }; return createServerConfig(configParams); diff --git a/packages/cli/src/config/settings.test.ts b/packages/cli/src/config/settings.test.ts new file mode 100644 index 00000000..4d61ed8b --- /dev/null +++ b/packages/cli/src/config/settings.test.ts @@ -0,0 +1,309 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/// <reference types="vitest/globals" /> + +const MOCK_HOME_DIR = '/mock/home/user'; // MUST BE FIRST + +// Mock 'os' first. Its factory uses MOCK_HOME_DIR. +import * as osActual from 'os'; // Import for type info for the mock factory +vi.mock('os', async (importOriginal) => { + const actualOs = await importOriginal<typeof osActual>(); + return { + ...actualOs, + homedir: vi.fn(() => MOCK_HOME_DIR), + }; +}); + +// Mock './settings.js' to ensure it uses the mocked 'os.homedir()' for its internal constants. +vi.mock('./settings.js', async (importActual) => { + const originalModule = await importActual<typeof import('./settings.js')>(); + return { + __esModule: true, // Ensure correct module shape + ...originalModule, // Re-export all original members + // We are relying on originalModule's USER_SETTINGS_PATH being constructed with mocked os.homedir() + }; +}); + +// NOW import everything else, including the (now effectively re-exported) settings.js +import * as pathActual from 'path'; // Restored for MOCK_WORKSPACE_SETTINGS_PATH +import { + describe, + it, + expect, + vi, + beforeEach, + afterEach, + type Mocked, + type Mock, +} from 'vitest'; +import * as fs from 'fs'; // fs will be mocked separately +import stripJsonComments from 'strip-json-comments'; // Will be mocked separately + +// These imports will get the versions from the vi.mock('./settings.js', ...) factory. +import { + LoadedSettings, + loadSettings, + USER_SETTINGS_PATH, // This IS the mocked path. + SETTINGS_DIRECTORY_NAME, // This is from the original module, but used by the mock. + SettingScope, +} from './settings.js'; + +const MOCK_WORKSPACE_DIR = '/mock/workspace'; +// Use the (mocked) SETTINGS_DIRECTORY_NAME for consistency +const MOCK_WORKSPACE_SETTINGS_PATH = pathActual.join( + MOCK_WORKSPACE_DIR, + SETTINGS_DIRECTORY_NAME, + 'settings.json', +); + +vi.mock('fs'); +vi.mock('strip-json-comments', () => ({ + default: vi.fn((content) => content), +})); + +describe('Settings Loading and Merging', () => { + let mockFsExistsSync: Mocked<typeof fs.existsSync>; + let mockStripJsonComments: Mocked<typeof stripJsonComments>; + let mockFsMkdirSync: Mocked<typeof fs.mkdirSync>; + + beforeEach(() => { + vi.resetAllMocks(); + + mockFsExistsSync = vi.mocked(fs.existsSync); + mockFsMkdirSync = vi.mocked(fs.mkdirSync); + mockStripJsonComments = vi.mocked(stripJsonComments); + + vi.mocked(osActual.homedir).mockReturnValue(MOCK_HOME_DIR); + (mockStripJsonComments as unknown as Mock).mockImplementation( + (jsonString: string) => jsonString, + ); + (mockFsExistsSync as Mock).mockReturnValue(false); + (fs.readFileSync as Mock).mockReturnValue('{}'); // Return valid empty JSON + (mockFsMkdirSync as Mock).mockImplementation(() => undefined); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + describe('loadSettings', () => { + it('should load empty settings if no files exist', () => { + const settings = loadSettings(MOCK_WORKSPACE_DIR); + expect(settings.user.settings).toEqual({}); + expect(settings.workspace.settings).toEqual({}); + expect(settings.merged).toEqual({}); + }); + + it('should load user settings if only user file exists', () => { + const expectedUserSettingsPath = USER_SETTINGS_PATH; // Use the path actually resolved by the (mocked) module + + (mockFsExistsSync as Mock).mockImplementation( + (p: fs.PathLike) => p === expectedUserSettingsPath, + ); + const userSettingsContent = { + theme: 'dark', + contextFileName: 'USER_CONTEXT.md', + }; + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === expectedUserSettingsPath) + return JSON.stringify(userSettingsContent); + return '{}'; + }, + ); + + const settings = loadSettings(MOCK_WORKSPACE_DIR); + + expect(fs.readFileSync).toHaveBeenCalledWith( + expectedUserSettingsPath, + 'utf-8', + ); + expect(settings.user.settings).toEqual(userSettingsContent); + expect(settings.workspace.settings).toEqual({}); + expect(settings.merged).toEqual(userSettingsContent); + }); + + it('should load workspace settings if only workspace file exists', () => { + (mockFsExistsSync as Mock).mockImplementation( + (p: fs.PathLike) => p === MOCK_WORKSPACE_SETTINGS_PATH, + ); + const workspaceSettingsContent = { + sandbox: true, + contextFileName: 'WORKSPACE_CONTEXT.md', + }; + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === MOCK_WORKSPACE_SETTINGS_PATH) + return JSON.stringify(workspaceSettingsContent); + return ''; + }, + ); + + const settings = loadSettings(MOCK_WORKSPACE_DIR); + + expect(fs.readFileSync).toHaveBeenCalledWith( + MOCK_WORKSPACE_SETTINGS_PATH, + 'utf-8', + ); + expect(settings.user.settings).toEqual({}); + expect(settings.workspace.settings).toEqual(workspaceSettingsContent); + expect(settings.merged).toEqual(workspaceSettingsContent); + }); + + it('should merge user and workspace settings, with workspace taking precedence', () => { + (mockFsExistsSync as Mock).mockReturnValue(true); + const userSettingsContent = { + theme: 'dark', + sandbox: false, + contextFileName: 'USER_CONTEXT.md', + }; + const workspaceSettingsContent = { + sandbox: true, + coreTools: ['tool1'], + contextFileName: 'WORKSPACE_CONTEXT.md', + }; + + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === USER_SETTINGS_PATH) + return JSON.stringify(userSettingsContent); + if (p === MOCK_WORKSPACE_SETTINGS_PATH) + return JSON.stringify(workspaceSettingsContent); + return ''; + }, + ); + + const settings = loadSettings(MOCK_WORKSPACE_DIR); + + expect(settings.user.settings).toEqual(userSettingsContent); + expect(settings.workspace.settings).toEqual(workspaceSettingsContent); + expect(settings.merged).toEqual({ + theme: 'dark', + sandbox: true, + coreTools: ['tool1'], + contextFileName: 'WORKSPACE_CONTEXT.md', + }); + }); + + it('should handle contextFileName correctly when only in user settings', () => { + (mockFsExistsSync as Mock).mockImplementation( + (p: fs.PathLike) => p === USER_SETTINGS_PATH, + ); + const userSettingsContent = { contextFileName: 'CUSTOM.md' }; + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === USER_SETTINGS_PATH) + return JSON.stringify(userSettingsContent); + return ''; + }, + ); + + const settings = loadSettings(MOCK_WORKSPACE_DIR); + expect(settings.merged.contextFileName).toBe('CUSTOM.md'); + }); + + it('should handle contextFileName correctly when only in workspace settings', () => { + (mockFsExistsSync as Mock).mockImplementation( + (p: fs.PathLike) => p === MOCK_WORKSPACE_SETTINGS_PATH, + ); + const workspaceSettingsContent = { + contextFileName: 'PROJECT_SPECIFIC.md', + }; + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === MOCK_WORKSPACE_SETTINGS_PATH) + return JSON.stringify(workspaceSettingsContent); + return ''; + }, + ); + + const settings = loadSettings(MOCK_WORKSPACE_DIR); + expect(settings.merged.contextFileName).toBe('PROJECT_SPECIFIC.md'); + }); + + it('should default contextFileName to undefined if not in any settings file', () => { + (mockFsExistsSync as Mock).mockReturnValue(true); + const userSettingsContent = { theme: 'dark' }; + const workspaceSettingsContent = { sandbox: true }; + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + if (p === USER_SETTINGS_PATH) + return JSON.stringify(userSettingsContent); + if (p === MOCK_WORKSPACE_SETTINGS_PATH) + return JSON.stringify(workspaceSettingsContent); + return ''; + }, + ); + + const settings = loadSettings(MOCK_WORKSPACE_DIR); + expect(settings.merged.contextFileName).toBeUndefined(); + }); + + it('should handle JSON parsing errors gracefully', () => { + (mockFsExistsSync as Mock).mockReturnValue(true); + (fs.readFileSync as Mock).mockImplementation( + (p: fs.PathOrFileDescriptor) => { + // Make it return invalid json for the paths it will try to read + if (p === USER_SETTINGS_PATH || p === MOCK_WORKSPACE_SETTINGS_PATH) + return 'invalid json'; + return ''; + }, + ); + const consoleErrorSpy = vi + .spyOn(console, 'error') + .mockImplementation(() => {}); + + const settings = loadSettings(MOCK_WORKSPACE_DIR); + + expect(settings.user.settings).toEqual({}); + expect(settings.workspace.settings).toEqual({}); + expect(settings.merged).toEqual({}); + expect(consoleErrorSpy).toHaveBeenCalledTimes(2); + + consoleErrorSpy.mockRestore(); + }); + }); + + describe('LoadedSettings class', () => { + it('setValue should update the correct scope and recompute merged settings', () => { + (mockFsExistsSync as Mock).mockReturnValue(false); + const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR) as LoadedSettings; + + vi.mocked(fs.writeFileSync).mockImplementation(() => {}); + // mkdirSync is mocked in beforeEach to return undefined, which is fine for void usage + + loadedSettings.setValue(SettingScope.User, 'theme', 'matrix'); + expect(loadedSettings.user.settings.theme).toBe('matrix'); + expect(loadedSettings.merged.theme).toBe('matrix'); + expect(fs.writeFileSync).toHaveBeenCalledWith( + USER_SETTINGS_PATH, + JSON.stringify({ theme: 'matrix' }, null, 2), + 'utf-8', + ); + + loadedSettings.setValue( + SettingScope.Workspace, + 'contextFileName', + 'MY_AGENTS.md', + ); + expect(loadedSettings.workspace.settings.contextFileName).toBe( + 'MY_AGENTS.md', + ); + expect(loadedSettings.merged.contextFileName).toBe('MY_AGENTS.md'); + expect(loadedSettings.merged.theme).toBe('matrix'); + expect(fs.writeFileSync).toHaveBeenCalledWith( + MOCK_WORKSPACE_SETTINGS_PATH, + JSON.stringify({ contextFileName: 'MY_AGENTS.md' }, null, 2), + 'utf-8', + ); + + loadedSettings.setValue(SettingScope.Workspace, 'theme', 'ocean'); + expect(loadedSettings.workspace.settings.theme).toBe('ocean'); + expect(loadedSettings.merged.theme).toBe('ocean'); + }); + }); +}); diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts index 1aabc127..5d51ba15 100644 --- a/packages/cli/src/config/settings.ts +++ b/packages/cli/src/config/settings.ts @@ -30,6 +30,7 @@ export interface Settings { mcpServerCommand?: string; mcpServers?: Record<string, MCPServerConfig>; showMemoryUsage?: boolean; + contextFileName?: string; // Add other settings here. } diff --git a/packages/cli/src/ui/App.test.tsx b/packages/cli/src/ui/App.test.tsx new file mode 100644 index 00000000..a7811f6a --- /dev/null +++ b/packages/cli/src/ui/App.test.tsx @@ -0,0 +1,289 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, vi, beforeEach, afterEach, Mock } from 'vitest'; +import { render } from 'ink-testing-library'; +import { App } from './App.js'; +import { Config as ServerConfig, MCPServerConfig } from '@gemini-code/core'; +import type { ToolRegistry } from '@gemini-code/core'; +import { LoadedSettings, SettingsFile, Settings } from '../config/settings.js'; + +// Define a more complete mock server config based on actual Config +interface MockServerConfig { + apiKey: string; + model: string; + sandbox: boolean | string; + targetDir: string; + debugMode: boolean; + question?: string; + fullContext: boolean; + coreTools?: string[]; + toolDiscoveryCommand?: string; + toolCallCommand?: string; + mcpServerCommand?: string; + mcpServers?: Record<string, MCPServerConfig>; // Use imported MCPServerConfig + userAgent: string; + userMemory: string; + geminiMdFileCount: number; + alwaysSkipModificationConfirmation: boolean; + vertexai?: boolean; + showMemoryUsage?: boolean; + + getApiKey: Mock<() => string>; + getModel: Mock<() => string>; + getSandbox: Mock<() => boolean | string>; + getTargetDir: Mock<() => string>; + getToolRegistry: Mock<() => ToolRegistry>; // Use imported ToolRegistry type + getDebugMode: Mock<() => boolean>; + getQuestion: Mock<() => string | undefined>; + getFullContext: Mock<() => boolean>; + getCoreTools: Mock<() => string[] | undefined>; + getToolDiscoveryCommand: Mock<() => string | undefined>; + getToolCallCommand: Mock<() => string | undefined>; + getMcpServerCommand: Mock<() => string | undefined>; + getMcpServers: Mock<() => Record<string, MCPServerConfig> | undefined>; + getUserAgent: Mock<() => string>; + getUserMemory: Mock<() => string>; + setUserMemory: Mock<(newUserMemory: string) => void>; + getGeminiMdFileCount: Mock<() => number>; + setGeminiMdFileCount: Mock<(count: number) => void>; + getAlwaysSkipModificationConfirmation: Mock<() => boolean>; + setAlwaysSkipModificationConfirmation: Mock<(skip: boolean) => void>; + getVertexAI: Mock<() => boolean | undefined>; + getShowMemoryUsage: Mock<() => boolean>; +} + +// Mock @gemini-code/core and its Config class +vi.mock('@gemini-code/core', async (importOriginal) => { + const actualCore = await importOriginal<typeof import('@gemini-code/core')>(); + const ConfigClassMock = vi + .fn() + .mockImplementation((optionsPassedToConstructor) => { + const opts = { ...optionsPassedToConstructor }; // Clone + // Basic mock structure, will be extended by the instance in tests + return { + apiKey: opts.apiKey || 'test-key', + model: opts.model || 'test-model-in-mock-factory', + sandbox: typeof opts.sandbox === 'boolean' ? opts.sandbox : false, + targetDir: opts.targetDir || '/test/dir', + debugMode: opts.debugMode || false, + question: opts.question, + fullContext: opts.fullContext ?? false, + coreTools: opts.coreTools, + toolDiscoveryCommand: opts.toolDiscoveryCommand, + toolCallCommand: opts.toolCallCommand, + mcpServerCommand: opts.mcpServerCommand, + mcpServers: opts.mcpServers, + userAgent: opts.userAgent || 'test-agent', + userMemory: opts.userMemory || '', + geminiMdFileCount: opts.geminiMdFileCount || 0, + alwaysSkipModificationConfirmation: + opts.alwaysSkipModificationConfirmation ?? false, + vertexai: opts.vertexai, + showMemoryUsage: opts.showMemoryUsage ?? false, + + getApiKey: vi.fn(() => opts.apiKey || 'test-key'), + getModel: vi.fn(() => opts.model || 'test-model-in-mock-factory'), + getSandbox: vi.fn(() => + typeof opts.sandbox === 'boolean' ? opts.sandbox : false, + ), + getTargetDir: vi.fn(() => opts.targetDir || '/test/dir'), + getToolRegistry: vi.fn(() => ({}) as ToolRegistry), // Simple mock + getDebugMode: vi.fn(() => opts.debugMode || false), + getQuestion: vi.fn(() => opts.question), + getFullContext: vi.fn(() => opts.fullContext ?? false), + getCoreTools: vi.fn(() => opts.coreTools), + getToolDiscoveryCommand: vi.fn(() => opts.toolDiscoveryCommand), + getToolCallCommand: vi.fn(() => opts.toolCallCommand), + getMcpServerCommand: vi.fn(() => opts.mcpServerCommand), + getMcpServers: vi.fn(() => opts.mcpServers), + getUserAgent: vi.fn(() => opts.userAgent || 'test-agent'), + getUserMemory: vi.fn(() => opts.userMemory || ''), + setUserMemory: vi.fn(), + getGeminiMdFileCount: vi.fn(() => opts.geminiMdFileCount || 0), + setGeminiMdFileCount: vi.fn(), + getAlwaysSkipModificationConfirmation: vi.fn( + () => opts.alwaysSkipModificationConfirmation ?? false, + ), + setAlwaysSkipModificationConfirmation: vi.fn(), + getVertexAI: vi.fn(() => opts.vertexai), + getShowMemoryUsage: vi.fn(() => opts.showMemoryUsage ?? false), + }; + }); + return { + ...actualCore, + Config: ConfigClassMock, + MCPServerConfig: actualCore.MCPServerConfig, + }; +}); + +// Mock heavy dependencies or those with side effects +vi.mock('./hooks/useGeminiStream', () => ({ + useGeminiStream: vi.fn(() => ({ + streamingState: 'Idle', + submitQuery: vi.fn(), + initError: null, + pendingHistoryItems: [], + })), +})); + +vi.mock('./hooks/useLogger', () => ({ + useLogger: vi.fn(() => ({ + getPreviousUserMessages: vi.fn().mockResolvedValue([]), + })), +})); + +vi.mock('../config/config.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + // @ts-expect-error - this is fine + ...actual, + loadHierarchicalGeminiMemory: vi + .fn() + .mockResolvedValue({ memoryContent: '', fileCount: 0 }), + }; +}); + +describe('App UI', () => { + let mockConfig: MockServerConfig; + let mockSettings: LoadedSettings; + let currentUnmount: (() => void) | undefined; + + const createMockSettings = ( + settings: Partial<Settings> = {}, + ): LoadedSettings => { + const userSettingsFile: SettingsFile = { + path: '/user/settings.json', + settings: {}, + }; + const workspaceSettingsFile: SettingsFile = { + path: '/workspace/.gemini/settings.json', + settings, + }; + return new LoadedSettings(userSettingsFile, workspaceSettingsFile); + }; + + beforeEach(() => { + const ServerConfigMocked = vi.mocked(ServerConfig, true); + mockConfig = new ServerConfigMocked({ + apiKey: 'test-key', + model: 'test-model-in-options', + sandbox: false, + targetDir: '/test/dir', + debugMode: false, + userAgent: 'test-agent', + userMemory: '', + geminiMdFileCount: 0, + showMemoryUsage: false, + // Provide other required fields for ConfigParameters if necessary + }) as unknown as MockServerConfig; + + // Ensure the getShowMemoryUsage mock function is specifically set up if not covered by constructor mock + if (!mockConfig.getShowMemoryUsage) { + mockConfig.getShowMemoryUsage = vi.fn(() => false); + } + mockConfig.getShowMemoryUsage.mockReturnValue(false); // Default for most tests + + mockSettings = createMockSettings(); + }); + + afterEach(() => { + if (currentUnmount) { + currentUnmount(); + currentUnmount = undefined; + } + vi.clearAllMocks(); // Clear mocks after each test + }); + + it('should display default "GEMINI.md" in footer when contextFileName is not set and count is 1', async () => { + mockConfig.getGeminiMdFileCount.mockReturnValue(1); + // For this test, ensure showMemoryUsage is false or debugMode is false if it relies on that + mockConfig.getDebugMode.mockReturnValue(false); + mockConfig.getShowMemoryUsage.mockReturnValue(false); + + const { lastFrame, unmount } = render( + <App + config={mockConfig as unknown as ServerConfig} + settings={mockSettings} + cliVersion="1.0.0" + />, + ); + currentUnmount = unmount; + await Promise.resolve(); // Wait for any async updates + expect(lastFrame()).toContain('Using 1 GEMINI.md file'); + }); + + it('should display default "GEMINI.md" with plural when contextFileName is not set and count is > 1', async () => { + mockConfig.getGeminiMdFileCount.mockReturnValue(2); + mockConfig.getDebugMode.mockReturnValue(false); + mockConfig.getShowMemoryUsage.mockReturnValue(false); + + const { lastFrame, unmount } = render( + <App + config={mockConfig as unknown as ServerConfig} + settings={mockSettings} + cliVersion="1.0.0" + />, + ); + currentUnmount = unmount; + await Promise.resolve(); + expect(lastFrame()).toContain('Using 2 GEMINI.md files'); + }); + + it('should display custom contextFileName in footer when set and count is 1', async () => { + mockSettings = createMockSettings({ contextFileName: 'AGENTS.MD' }); + mockConfig.getGeminiMdFileCount.mockReturnValue(1); + mockConfig.getDebugMode.mockReturnValue(false); + mockConfig.getShowMemoryUsage.mockReturnValue(false); + + const { lastFrame, unmount } = render( + <App + config={mockConfig as unknown as ServerConfig} + settings={mockSettings} + cliVersion="1.0.0" + />, + ); + currentUnmount = unmount; + await Promise.resolve(); + expect(lastFrame()).toContain('Using 1 AGENTS.MD file'); + }); + + it('should display custom contextFileName with plural when set and count is > 1', async () => { + mockSettings = createMockSettings({ contextFileName: 'MY_NOTES.TXT' }); + mockConfig.getGeminiMdFileCount.mockReturnValue(3); + mockConfig.getDebugMode.mockReturnValue(false); + mockConfig.getShowMemoryUsage.mockReturnValue(false); + + const { lastFrame, unmount } = render( + <App + config={mockConfig as unknown as ServerConfig} + settings={mockSettings} + cliVersion="1.0.0" + />, + ); + currentUnmount = unmount; + await Promise.resolve(); + expect(lastFrame()).toContain('Using 3 MY_NOTES.TXT files'); + }); + + it('should not display context file message if count is 0, even if contextFileName is set', async () => { + mockSettings = createMockSettings({ contextFileName: 'ANY_FILE.MD' }); + mockConfig.getGeminiMdFileCount.mockReturnValue(0); + mockConfig.getDebugMode.mockReturnValue(false); + mockConfig.getShowMemoryUsage.mockReturnValue(false); + + const { lastFrame, unmount } = render( + <App + config={mockConfig as unknown as ServerConfig} + settings={mockSettings} + cliVersion="1.0.0" + />, + ); + currentUnmount = unmount; + await Promise.resolve(); + expect(lastFrame()).not.toContain('ANY_FILE.MD'); + }); +}); diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index e1657984..2f216db7 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -39,7 +39,11 @@ import { DetailedMessagesDisplay } from './components/DetailedMessagesDisplay.js import { HistoryItemDisplay } from './components/HistoryItemDisplay.js'; import { useHistory } from './hooks/useHistoryManager.js'; import process from 'node:process'; -import { getErrorMessage, type Config } from '@gemini-code/core'; +import { + getErrorMessage, + type Config, + getCurrentGeminiMdFilename, +} from '@gemini-code/core'; import { useLogger } from './hooks/useLogger.js'; import { StreamingContext } from './contexts/StreamingContext.js'; import { useGitBranchName } from './hooks/useGitBranchName.js'; @@ -398,7 +402,10 @@ export const App = ({ </Text> ) : geminiMdFileCount > 0 ? ( <Text color={Colors.SubtleComment}> - Using {geminiMdFileCount} GEMINI.md file + Using {geminiMdFileCount}{' '} + {settings.merged.contextFileName || + getCurrentGeminiMdFilename()}{' '} + file {geminiMdFileCount > 1 ? 's' : ''} </Text> ) : ( |
