mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Update contextFileName to support an optional list of strings (#1001)
This commit is contained in:
@@ -16,7 +16,7 @@ export interface ExtensionConfig {
|
||||
name: string;
|
||||
version: string;
|
||||
mcpServers?: Record<string, MCPServerConfig>;
|
||||
contextFileName?: string;
|
||||
contextFileName?: string | string[];
|
||||
}
|
||||
|
||||
export function loadExtensions(workspaceDir: string): ExtensionConfig[] {
|
||||
@@ -76,12 +76,15 @@ function loadExtensionsFromDir(dir: string): ExtensionConfig[] {
|
||||
}
|
||||
|
||||
if (extensionConfig.contextFileName) {
|
||||
const contextFilePath = path.join(
|
||||
extensionDir,
|
||||
extensionConfig.contextFileName,
|
||||
);
|
||||
if (fs.existsSync(contextFilePath)) {
|
||||
extensionConfig.contextFileName = contextFilePath;
|
||||
const contextFileNames = Array.isArray(extensionConfig.contextFileName)
|
||||
? extensionConfig.contextFileName
|
||||
: [extensionConfig.contextFileName];
|
||||
const resolvedPaths = contextFileNames
|
||||
.map((fileName) => path.join(extensionDir, fileName))
|
||||
.filter((filePath) => fs.existsSync(filePath));
|
||||
if (resolvedPaths.length > 0) {
|
||||
extensionConfig.contextFileName =
|
||||
resolvedPaths.length === 1 ? resolvedPaths[0] : resolvedPaths;
|
||||
}
|
||||
} else {
|
||||
const contextFilePath = path.join(extensionDir, 'gemini.md');
|
||||
|
||||
@@ -35,7 +35,7 @@ export interface Settings {
|
||||
mcpServerCommand?: string;
|
||||
mcpServers?: Record<string, MCPServerConfig>;
|
||||
showMemoryUsage?: boolean;
|
||||
contextFileName?: string;
|
||||
contextFileName?: string | string[];
|
||||
accessibility?: AccessibilitySettings;
|
||||
telemetry?: boolean;
|
||||
preferredEditor?: string;
|
||||
|
||||
@@ -64,6 +64,7 @@ interface MockServerConfig {
|
||||
getShowMemoryUsage: Mock<() => boolean>;
|
||||
getAccessibility: Mock<() => AccessibilitySettings>;
|
||||
getProjectRoot: Mock<() => string | undefined>;
|
||||
getAllGeminiMdFilenames: Mock<() => string[]>;
|
||||
}
|
||||
|
||||
// Mock @gemini-cli/core and its Config class
|
||||
@@ -124,12 +125,14 @@ vi.mock('@gemini-cli/core', async (importOriginal) => {
|
||||
getProjectRoot: vi.fn(() => opts.projectRoot),
|
||||
getGeminiClient: vi.fn(() => ({})),
|
||||
getCheckpointEnabled: vi.fn(() => opts.checkpoint ?? true),
|
||||
getAllGeminiMdFilenames: vi.fn(() => ['GEMINI.md']),
|
||||
};
|
||||
});
|
||||
return {
|
||||
...actualCore,
|
||||
Config: ConfigClassMock,
|
||||
MCPServerConfig: actualCore.MCPServerConfig,
|
||||
getAllGeminiMdFilenames: vi.fn(() => ['GEMINI.md']),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -269,6 +272,26 @@ describe('App UI', () => {
|
||||
expect(lastFrame()).toContain('Using 1 AGENTS.MD file');
|
||||
});
|
||||
|
||||
it('should display the first custom contextFileName when an array is provided', async () => {
|
||||
mockSettings = createMockSettings({
|
||||
contextFileName: ['AGENTS.MD', 'CONTEXT.MD'],
|
||||
theme: 'Default',
|
||||
});
|
||||
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}
|
||||
/>,
|
||||
);
|
||||
currentUnmount = unmount;
|
||||
await Promise.resolve();
|
||||
expect(lastFrame()).toContain('Using 2 AGENTS.MD files');
|
||||
});
|
||||
|
||||
it('should display custom contextFileName with plural when set and count is > 1', async () => {
|
||||
mockSettings = createMockSettings({
|
||||
contextFileName: 'MY_NOTES.TXT',
|
||||
|
||||
@@ -45,7 +45,7 @@ import process from 'node:process';
|
||||
import {
|
||||
getErrorMessage,
|
||||
type Config,
|
||||
getCurrentGeminiMdFilename,
|
||||
getAllGeminiMdFilenames,
|
||||
ApprovalMode,
|
||||
isEditorAvailable,
|
||||
EditorType,
|
||||
@@ -373,6 +373,14 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => {
|
||||
|
||||
const branchName = useGitBranchName(config.getTargetDir());
|
||||
|
||||
const contextFileNames = useMemo(() => {
|
||||
const fromSettings = settings.merged.contextFileName;
|
||||
if (fromSettings) {
|
||||
return Array.isArray(fromSettings) ? fromSettings : [fromSettings];
|
||||
}
|
||||
return getAllGeminiMdFilenames();
|
||||
}, [settings.merged.contextFileName]);
|
||||
|
||||
if (quittingMessages) {
|
||||
return (
|
||||
<Box flexDirection="column" marginBottom={1}>
|
||||
@@ -509,10 +517,7 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => {
|
||||
) : (
|
||||
<ContextSummaryDisplay
|
||||
geminiMdFileCount={geminiMdFileCount}
|
||||
contextFileName={
|
||||
settings.merged.contextFileName ||
|
||||
getCurrentGeminiMdFilename()
|
||||
}
|
||||
contextFileNames={contextFileNames}
|
||||
mcpServers={config.getMcpServers()}
|
||||
showToolDescriptions={showToolDescriptions}
|
||||
/>
|
||||
|
||||
@@ -11,14 +11,14 @@ import { type MCPServerConfig } from '@gemini-cli/core';
|
||||
|
||||
interface ContextSummaryDisplayProps {
|
||||
geminiMdFileCount: number;
|
||||
contextFileName: string;
|
||||
contextFileNames: string[];
|
||||
mcpServers?: Record<string, MCPServerConfig>;
|
||||
showToolDescriptions?: boolean;
|
||||
}
|
||||
|
||||
export const ContextSummaryDisplay: React.FC<ContextSummaryDisplayProps> = ({
|
||||
geminiMdFileCount,
|
||||
contextFileName,
|
||||
contextFileNames,
|
||||
mcpServers,
|
||||
showToolDescriptions,
|
||||
}) => {
|
||||
@@ -30,7 +30,9 @@ export const ContextSummaryDisplay: React.FC<ContextSummaryDisplayProps> = ({
|
||||
|
||||
const geminiMdText =
|
||||
geminiMdFileCount > 0
|
||||
? `${geminiMdFileCount} ${contextFileName} file${geminiMdFileCount > 1 ? 's' : ''}`
|
||||
? `${geminiMdFileCount} ${contextFileNames[0]} file${
|
||||
geminiMdFileCount > 1 ? 's' : ''
|
||||
}`
|
||||
: '';
|
||||
|
||||
const mcpText =
|
||||
|
||||
Reference in New Issue
Block a user