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
This commit is contained in:
tanzhenxin 2026-01-26 15:02:37 +08:00
parent 45df0e8b82
commit 7995c65571
82 changed files with 606 additions and 485 deletions

View file

@ -10,6 +10,7 @@ import type { UseHistoryManagerReturn } from './useHistoryManager.js';
import {
type Logger,
type Config,
createDebugLogger,
GitService,
logSlashCommand,
makeSlashCommandEvent,
@ -33,12 +34,14 @@ import { BuiltinCommandLoader } from '../../services/BuiltinCommandLoader.js';
import { FileCommandLoader } from '../../services/FileCommandLoader.js';
import { McpPromptLoader } from '../../services/McpPromptLoader.js';
import { parseSlashCommand } from '../../utils/commands.js';
import { clearScreen } from '../../utils/stdioHelpers.js';
import {
type ExtensionUpdateAction,
type ExtensionUpdateStatus,
} from '../state/extensions.js';
type SerializableHistoryItem = Record<string, unknown>;
const debugLogger = createDebugLogger('SLASH_COMMAND_PROCESSOR');
function serializeHistoryItemForRecording(
item: Omit<HistoryItem, 'id'>,
@ -200,7 +203,7 @@ export const useSlashCommandProcessor = (
addItem,
clear: () => {
clearItems();
console.clear();
clearScreen();
refreshStatic();
},
loadHistory,
@ -600,12 +603,10 @@ export const useSlashCommandProcessor = (
});
}
} catch (recordError) {
if (config.getDebugMode()) {
console.error(
'[slashCommand] Failed to record slash command:',
recordError,
);
}
debugLogger.error(
'[slashCommand] Failed to record slash command:',
recordError,
);
}
}
if (config && resolvedCommandPath[0] && !hasError) {