mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Refactor(server): Centralize GEMINI.md discovery logic in server (#498)
This commit is contained in:
@@ -6,11 +6,6 @@
|
||||
|
||||
import { Message, MessageType } from '../types.js';
|
||||
import { Config } from '@gemini-code/server';
|
||||
import { getGeminiMdFilePaths } from '../../config/config.js';
|
||||
import { homedir } from 'os';
|
||||
import process from 'node:process';
|
||||
|
||||
export const SHOW_MEMORY_COMMAND_NAME = '/showmemory';
|
||||
|
||||
export function createShowMemoryAction(
|
||||
config: Config | null,
|
||||
@@ -27,52 +22,42 @@ export function createShowMemoryAction(
|
||||
}
|
||||
|
||||
const debugMode = config.getDebugMode();
|
||||
const cwd = process.cwd();
|
||||
const homeDir = homedir();
|
||||
|
||||
if (debugMode) {
|
||||
console.log(`[DEBUG] Show Memory: CWD=${cwd}, Home=${homeDir}`);
|
||||
}
|
||||
|
||||
const filePaths = await getGeminiMdFilePaths(cwd, homeDir, debugMode);
|
||||
|
||||
if (filePaths.length > 0) {
|
||||
addMessage({
|
||||
type: MessageType.INFO,
|
||||
content: `The following GEMINI.md files are being used (in order of precedence):\n- ${filePaths.join('\n- ')}`,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
} else {
|
||||
addMessage({
|
||||
type: MessageType.INFO,
|
||||
content: 'No GEMINI.md files found in the hierarchy.',
|
||||
timestamp: new Date(),
|
||||
});
|
||||
console.log('[DEBUG] Show Memory command invoked.');
|
||||
}
|
||||
|
||||
const currentMemory = config.getUserMemory();
|
||||
const fileCount = config.getGeminiMdFileCount();
|
||||
|
||||
if (config.getDebugMode()) {
|
||||
if (debugMode) {
|
||||
console.log(
|
||||
`[DEBUG] Showing memory. Content from config.getUserMemory() (first 200 chars): ${currentMemory.substring(0, 200)}...`,
|
||||
);
|
||||
console.log(`[DEBUG] Number of GEMINI.md files loaded: ${fileCount}`);
|
||||
}
|
||||
|
||||
if (fileCount > 0) {
|
||||
addMessage({
|
||||
type: MessageType.INFO,
|
||||
content: `Loaded memory from ${fileCount} GEMINI.md file(s).`,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
}
|
||||
|
||||
if (currentMemory && currentMemory.trim().length > 0) {
|
||||
addMessage({
|
||||
type: MessageType.INFO,
|
||||
// Display with a clear heading, and potentially format for readability if very long.
|
||||
// For now, direct display. Consider using Markdown formatting for code blocks if memory contains them.
|
||||
content: `Current combined GEMINI.md memory content:\n\`\`\`markdown\n${currentMemory}\n\`\`\``,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
} else {
|
||||
// This message might be redundant if filePaths.length === 0, but kept for explicitness
|
||||
// if somehow memory is empty even if files were found (e.g., all files are empty).
|
||||
addMessage({
|
||||
type: MessageType.INFO,
|
||||
content:
|
||||
'No hierarchical memory (GEMINI.md) is currently loaded or memory is empty.',
|
||||
fileCount > 0
|
||||
? 'Hierarchical memory (GEMINI.md) is loaded but content is empty.'
|
||||
: 'No hierarchical memory (GEMINI.md) is currently loaded.',
|
||||
timestamp: new Date(),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user