qwen-code/packages/cli/src/ui/hooks/useShowMemoryCommand.ts
tanzhenxin 7995c65571 feat(cli): migrate console calls to debugLogger and stdioHelpers (M3 Phase 7-9)
Route CLI console.* calls to structured logging:
- Debug/internal diagnostics → debugLogger (logfile)
- User-facing output → writeStdoutLine/writeStderrLine/clearScreen (stdioHelpers)
- Add stdioHelpers.ts with writeStdoutLine, writeStderrLine, clearScreen
- Migrate pre-session files (gemini.tsx, sandbox.ts, config.ts) to stdioHelpers
- Migrate extension/MCP commands to stdioHelpers
- Migrate non-interactive session/control to debugLogger
- Migrate UI hooks and components to debugLogger
2026-01-26 15:02:37 +08:00

73 lines
2.3 KiB
TypeScript

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type { Message } from '../types.js';
import { MessageType } from '../types.js';
import type { Config } from '@qwen-code/qwen-code-core';
import type { LoadedSettings } from '../../config/settings.js';
import { createDebugLogger } from '@qwen-code/qwen-code-core';
const debugLogger = createDebugLogger('SHOW_MEMORY');
export function createShowMemoryAction(
config: Config | null,
settings: LoadedSettings,
addMessage: (message: Message) => void,
) {
return async () => {
if (!config) {
addMessage({
type: MessageType.ERROR,
content: 'Configuration not available. Cannot show memory.',
timestamp: new Date(),
});
return;
}
debugLogger.debug('[DEBUG] Show Memory command invoked.');
const currentMemory = config.getUserMemory();
const fileCount = config.getGeminiMdFileCount();
const contextFileName = settings.merged.context?.fileName;
const contextFileNames = Array.isArray(contextFileName)
? contextFileName
: [contextFileName];
debugLogger.debug(
`[DEBUG] Showing memory. Content from config.getUserMemory() (first 200 chars): ${currentMemory.substring(0, 200)}...`,
);
debugLogger.debug(`[DEBUG] Number of context files loaded: ${fileCount}`);
if (fileCount > 0) {
const allNamesTheSame = new Set(contextFileNames).size < 2;
const name = allNamesTheSame ? contextFileNames[0] : 'context';
addMessage({
type: MessageType.INFO,
content: `Loaded memory from ${fileCount} ${name} file${
fileCount > 1 ? 's' : ''
}.`,
timestamp: new Date(),
});
}
if (currentMemory && currentMemory.trim().length > 0) {
addMessage({
type: MessageType.INFO,
content: `Current combined memory content:\n\`\`\`markdown\n${currentMemory}\n\`\`\``,
timestamp: new Date(),
});
} else {
addMessage({
type: MessageType.INFO,
content:
fileCount > 0
? 'Hierarchical memory (QWEN.md or other context files) is loaded but content is empty.'
: 'No hierarchical memory (QWEN.md or other context files) is currently loaded.',
timestamp: new Date(),
});
}
};
}