Update memory and context summary UI for multiple context filenames (#1282)
This commit is contained in:
parent
03af6235a9
commit
99a6dc0267
|
@ -260,7 +260,7 @@ describe('App UI', () => {
|
||||||
|
|
||||||
it('should display custom contextFileName in footer when set and count is 1', async () => {
|
it('should display custom contextFileName in footer when set and count is 1', async () => {
|
||||||
mockSettings = createMockSettings({
|
mockSettings = createMockSettings({
|
||||||
contextFileName: 'AGENTS.MD',
|
contextFileName: 'AGENTS.md',
|
||||||
theme: 'Default',
|
theme: 'Default',
|
||||||
});
|
});
|
||||||
mockConfig.getGeminiMdFileCount.mockReturnValue(1);
|
mockConfig.getGeminiMdFileCount.mockReturnValue(1);
|
||||||
|
@ -275,12 +275,12 @@ describe('App UI', () => {
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
expect(lastFrame()).toContain('Using 1 AGENTS.MD file');
|
expect(lastFrame()).toContain('Using 1 AGENTS.md file');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display the first custom contextFileName when an array is provided', async () => {
|
it('should display a generic message when multiple context files with different names are provided', async () => {
|
||||||
mockSettings = createMockSettings({
|
mockSettings = createMockSettings({
|
||||||
contextFileName: ['AGENTS.MD', 'CONTEXT.MD'],
|
contextFileName: ['AGENTS.md', 'CONTEXT.md'],
|
||||||
theme: 'Default',
|
theme: 'Default',
|
||||||
});
|
});
|
||||||
mockConfig.getGeminiMdFileCount.mockReturnValue(2);
|
mockConfig.getGeminiMdFileCount.mockReturnValue(2);
|
||||||
|
@ -295,7 +295,7 @@ describe('App UI', () => {
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
expect(lastFrame()).toContain('Using 2 AGENTS.MD files');
|
expect(lastFrame()).toContain('Using 2 context files');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display custom contextFileName with plural when set and count is > 1', async () => {
|
it('should display custom contextFileName with plural when set and count is > 1', async () => {
|
||||||
|
|
|
@ -172,7 +172,7 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => {
|
||||||
addItem(
|
addItem(
|
||||||
{
|
{
|
||||||
type: MessageType.INFO,
|
type: MessageType.INFO,
|
||||||
text: 'Refreshing hierarchical memory (GEMINI.md files)...',
|
text: 'Refreshing hierarchical memory (GEMINI.md or other context files)...',
|
||||||
},
|
},
|
||||||
Date.now(),
|
Date.now(),
|
||||||
);
|
);
|
||||||
|
@ -217,6 +217,7 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => {
|
||||||
pendingHistoryItems: pendingSlashCommandHistoryItems,
|
pendingHistoryItems: pendingSlashCommandHistoryItems,
|
||||||
} = useSlashCommandProcessor(
|
} = useSlashCommandProcessor(
|
||||||
config,
|
config,
|
||||||
|
settings,
|
||||||
history,
|
history,
|
||||||
addItem,
|
addItem,
|
||||||
clearItems,
|
clearItems,
|
||||||
|
|
|
@ -28,12 +28,16 @@ export const ContextSummaryDisplay: React.FC<ContextSummaryDisplayProps> = ({
|
||||||
return <Text> </Text>; // Render an empty space to reserve height
|
return <Text> </Text>; // Render an empty space to reserve height
|
||||||
}
|
}
|
||||||
|
|
||||||
const geminiMdText =
|
const geminiMdText = (() => {
|
||||||
geminiMdFileCount > 0
|
if (geminiMdFileCount === 0) {
|
||||||
? `${geminiMdFileCount} ${contextFileNames[0]} file${
|
return '';
|
||||||
geminiMdFileCount > 1 ? 's' : ''
|
}
|
||||||
}`
|
const allNamesTheSame = new Set(contextFileNames).size < 2;
|
||||||
: '';
|
const name = allNamesTheSame ? contextFileNames[0] : 'context';
|
||||||
|
return `${geminiMdFileCount} ${name} file${
|
||||||
|
geminiMdFileCount > 1 ? 's' : ''
|
||||||
|
}`;
|
||||||
|
})();
|
||||||
|
|
||||||
const mcpText =
|
const mcpText =
|
||||||
mcpServerCount > 0
|
mcpServerCount > 0
|
||||||
|
|
|
@ -62,14 +62,15 @@ import {
|
||||||
} from './slashCommandProcessor.js';
|
} from './slashCommandProcessor.js';
|
||||||
import { MessageType } from '../types.js';
|
import { MessageType } from '../types.js';
|
||||||
import {
|
import {
|
||||||
type Config,
|
Config,
|
||||||
MCPServerStatus,
|
|
||||||
getMCPServerStatus,
|
|
||||||
MCPDiscoveryState,
|
MCPDiscoveryState,
|
||||||
|
MCPServerStatus,
|
||||||
getMCPDiscoveryState,
|
getMCPDiscoveryState,
|
||||||
|
getMCPServerStatus,
|
||||||
GeminiClient,
|
GeminiClient,
|
||||||
} from '@gemini-cli/core';
|
} from '@gemini-cli/core';
|
||||||
import { useSessionStats } from '../contexts/SessionContext.js';
|
import { useSessionStats } from '../contexts/SessionContext.js';
|
||||||
|
import { LoadedSettings } from '../../config/settings.js';
|
||||||
|
|
||||||
vi.mock('@gemini-code/core', async (importOriginal) => {
|
vi.mock('@gemini-code/core', async (importOriginal) => {
|
||||||
const actual = await importOriginal<typeof import('@gemini-code/core')>();
|
const actual = await importOriginal<typeof import('@gemini-code/core')>();
|
||||||
|
@ -161,10 +162,16 @@ describe('useSlashCommandProcessor', () => {
|
||||||
process.env = { ...globalThis.process.env };
|
process.env = { ...globalThis.process.env };
|
||||||
});
|
});
|
||||||
|
|
||||||
const getProcessorHook = (showToolDescriptions: boolean = false) =>
|
const getProcessorHook = (showToolDescriptions: boolean = false) => {
|
||||||
renderHook(() =>
|
const settings = {
|
||||||
|
merged: {
|
||||||
|
contextFileName: 'GEMINI.md',
|
||||||
|
},
|
||||||
|
} as LoadedSettings;
|
||||||
|
return renderHook(() =>
|
||||||
useSlashCommandProcessor(
|
useSlashCommandProcessor(
|
||||||
mockConfig,
|
mockConfig,
|
||||||
|
settings,
|
||||||
[],
|
[],
|
||||||
mockAddItem,
|
mockAddItem,
|
||||||
mockClearItems,
|
mockClearItems,
|
||||||
|
@ -181,6 +188,7 @@ describe('useSlashCommandProcessor', () => {
|
||||||
mockSetQuittingMessages,
|
mockSetQuittingMessages,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const getProcessor = (showToolDescriptions: boolean = false) =>
|
const getProcessor = (showToolDescriptions: boolean = false) =>
|
||||||
getProcessorHook(showToolDescriptions).result.current;
|
getProcessorHook(showToolDescriptions).result.current;
|
||||||
|
@ -253,7 +261,11 @@ describe('useSlashCommandProcessor', () => {
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
ShowMemoryCommandModule.createShowMemoryAction,
|
ShowMemoryCommandModule.createShowMemoryAction,
|
||||||
).toHaveBeenCalledWith(mockConfig, expect.any(Function));
|
).toHaveBeenCalledWith(
|
||||||
|
mockConfig,
|
||||||
|
expect.any(Object),
|
||||||
|
expect.any(Function),
|
||||||
|
);
|
||||||
expect(mockReturnedShowAction).toHaveBeenCalled();
|
expect(mockReturnedShowAction).toHaveBeenCalled();
|
||||||
expect(commandResult).toBe(true);
|
expect(commandResult).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,6 +32,7 @@ import { createShowMemoryAction } from './useShowMemoryCommand.js';
|
||||||
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
|
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
|
||||||
import { formatDuration, formatMemoryUsage } from '../utils/formatters.js';
|
import { formatDuration, formatMemoryUsage } from '../utils/formatters.js';
|
||||||
import { getCliVersion } from '../../utils/version.js';
|
import { getCliVersion } from '../../utils/version.js';
|
||||||
|
import { LoadedSettings } from '../../config/settings.js';
|
||||||
|
|
||||||
export interface SlashCommandActionReturn {
|
export interface SlashCommandActionReturn {
|
||||||
shouldScheduleTool?: boolean;
|
shouldScheduleTool?: boolean;
|
||||||
|
@ -60,6 +61,7 @@ export interface SlashCommand {
|
||||||
*/
|
*/
|
||||||
export const useSlashCommandProcessor = (
|
export const useSlashCommandProcessor = (
|
||||||
config: Config | null,
|
config: Config | null,
|
||||||
|
settings: LoadedSettings,
|
||||||
history: HistoryItem[],
|
history: HistoryItem[],
|
||||||
addItem: UseHistoryManagerReturn['addItem'],
|
addItem: UseHistoryManagerReturn['addItem'],
|
||||||
clearItems: UseHistoryManagerReturn['clearItems'],
|
clearItems: UseHistoryManagerReturn['clearItems'],
|
||||||
|
@ -135,9 +137,9 @@ export const useSlashCommandProcessor = (
|
||||||
);
|
);
|
||||||
|
|
||||||
const showMemoryAction = useCallback(async () => {
|
const showMemoryAction = useCallback(async () => {
|
||||||
const actionFn = createShowMemoryAction(config, addMessage);
|
const actionFn = createShowMemoryAction(config, settings, addMessage);
|
||||||
await actionFn();
|
await actionFn();
|
||||||
}, [config, addMessage]);
|
}, [config, settings, addMessage]);
|
||||||
|
|
||||||
const addMemoryAction = useCallback(
|
const addMemoryAction = useCallback(
|
||||||
(
|
(
|
||||||
|
|
|
@ -6,9 +6,11 @@
|
||||||
|
|
||||||
import { Message, MessageType } from '../types.js';
|
import { Message, MessageType } from '../types.js';
|
||||||
import { Config } from '@gemini-cli/core';
|
import { Config } from '@gemini-cli/core';
|
||||||
|
import { LoadedSettings } from '../../config/settings.js';
|
||||||
|
|
||||||
export function createShowMemoryAction(
|
export function createShowMemoryAction(
|
||||||
config: Config | null,
|
config: Config | null,
|
||||||
|
settings: LoadedSettings,
|
||||||
addMessage: (message: Message) => void,
|
addMessage: (message: Message) => void,
|
||||||
) {
|
) {
|
||||||
return async () => {
|
return async () => {
|
||||||
|
@ -29,18 +31,26 @@ export function createShowMemoryAction(
|
||||||
|
|
||||||
const currentMemory = config.getUserMemory();
|
const currentMemory = config.getUserMemory();
|
||||||
const fileCount = config.getGeminiMdFileCount();
|
const fileCount = config.getGeminiMdFileCount();
|
||||||
|
const contextFileName = settings.merged.contextFileName;
|
||||||
|
const contextFileNames = Array.isArray(contextFileName)
|
||||||
|
? contextFileName
|
||||||
|
: [contextFileName];
|
||||||
|
|
||||||
if (debugMode) {
|
if (debugMode) {
|
||||||
console.log(
|
console.log(
|
||||||
`[DEBUG] Showing memory. Content from config.getUserMemory() (first 200 chars): ${currentMemory.substring(0, 200)}...`,
|
`[DEBUG] Showing memory. Content from config.getUserMemory() (first 200 chars): ${currentMemory.substring(0, 200)}...`,
|
||||||
);
|
);
|
||||||
console.log(`[DEBUG] Number of GEMINI.md files loaded: ${fileCount}`);
|
console.log(`[DEBUG] Number of context files loaded: ${fileCount}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileCount > 0) {
|
if (fileCount > 0) {
|
||||||
|
const allNamesTheSame = new Set(contextFileNames).size < 2;
|
||||||
|
const name = allNamesTheSame ? contextFileNames[0] : 'context';
|
||||||
addMessage({
|
addMessage({
|
||||||
type: MessageType.INFO,
|
type: MessageType.INFO,
|
||||||
content: `Loaded memory from ${fileCount} GEMINI.md file(s).`,
|
content: `Loaded memory from ${fileCount} ${name} file${
|
||||||
|
fileCount > 1 ? 's' : ''
|
||||||
|
}.`,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -48,7 +58,7 @@ export function createShowMemoryAction(
|
||||||
if (currentMemory && currentMemory.trim().length > 0) {
|
if (currentMemory && currentMemory.trim().length > 0) {
|
||||||
addMessage({
|
addMessage({
|
||||||
type: MessageType.INFO,
|
type: MessageType.INFO,
|
||||||
content: `Current combined GEMINI.md memory content:\n\`\`\`markdown\n${currentMemory}\n\`\`\``,
|
content: `Current combined memory content:\n\`\`\`markdown\n${currentMemory}\n\`\`\``,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,8 +66,8 @@ export function createShowMemoryAction(
|
||||||
type: MessageType.INFO,
|
type: MessageType.INFO,
|
||||||
content:
|
content:
|
||||||
fileCount > 0
|
fileCount > 0
|
||||||
? 'Hierarchical memory (GEMINI.md) is loaded but content is empty.'
|
? 'Hierarchical memory (GEMINI.md or other context files) is loaded but content is empty.'
|
||||||
: 'No hierarchical memory (GEMINI.md) is currently loaded.',
|
: 'No hierarchical memory (GEMINI.md or other context files) is currently loaded.',
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue