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

@ -8,6 +8,7 @@ import type { Config } from '@qwen-code/qwen-code-core';
import {
KittySequenceOverflowEvent,
logKittySequenceOverflow,
createDebugLogger,
} from '@qwen-code/qwen-code-core';
import { useStdin } from 'ink';
import type React from 'react';
@ -65,6 +66,7 @@ interface KeypressContextValue {
const KeypressContext = createContext<KeypressContextValue | undefined>(
undefined,
);
const debugLogger = createDebugLogger('KEYPRESS');
export function useKeypressContext() {
const context = useContext(KeypressContext);
@ -486,7 +488,7 @@ export function KeypressProvider({
key.sequence === `${ESC}${KITTY_CTRL_C}`
) {
if (kittySequenceBuffer && debugKeystrokeLogging) {
console.log(
debugLogger.debug(
'[DEBUG] Kitty buffer cleared on Ctrl+C:',
kittySequenceBuffer,
);
@ -520,7 +522,7 @@ export function KeypressProvider({
kittySequenceBuffer += key.sequence;
if (debugKeystrokeLogging) {
console.log(
debugLogger.debug(
'[DEBUG] Kitty buffer accumulating:',
kittySequenceBuffer,
);
@ -538,7 +540,7 @@ export function KeypressProvider({
const nextStart = kittySequenceBuffer.indexOf(`${ESC}[`, 1);
if (nextStart > 0) {
if (debugKeystrokeLogging) {
console.log(
debugLogger.debug(
'[DEBUG] Skipping incomplete/invalid CSI prefix:',
kittySequenceBuffer.slice(0, nextStart),
);
@ -554,12 +556,12 @@ export function KeypressProvider({
parsed.length,
);
if (kittySequenceBuffer.length > parsed.length) {
console.log(
debugLogger.debug(
'[DEBUG] Kitty sequence parsed successfully (prefix):',
parsedSequence,
);
} else {
console.log(
debugLogger.debug(
'[DEBUG] Kitty sequence parsed successfully:',
parsedSequence,
);
@ -576,12 +578,12 @@ export function KeypressProvider({
const codes = Array.from(kittySequenceBuffer).map((ch) =>
ch.charCodeAt(0),
);
console.warn('Kitty sequence buffer has char codes:', codes);
debugLogger.warn('Kitty sequence buffer has char codes:', codes);
}
if (kittySequenceBuffer.length > MAX_KITTY_SEQUENCE_LENGTH) {
if (debugKeystrokeLogging) {
console.log(
debugLogger.debug(
'[DEBUG] Kitty buffer overflow, clearing:',
kittySequenceBuffer,
);