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

@ -21,9 +21,11 @@ import {
MINIMUM_MAX_HEIGHT,
} from '../components/shared/MaxSizedBox.js';
import type { LoadedSettings } from '../../config/settings.js';
import { createDebugLogger } from '@qwen-code/qwen-code-core';
// Configure theming and parsing utilities.
const lowlight = createLowlight(common);
const debugLogger = createDebugLogger('CODE_COLORIZER');
function renderHastNode(
node: Root | Element | HastText | RootContent,
@ -188,7 +190,7 @@ export function colorizeCode(
</MaxSizedBox>
);
} catch (error) {
console.error(
debugLogger.error(
`[colorizeCode] Error highlighting code for language "${language}":`,
error,
);

View file

@ -8,6 +8,7 @@ import React from 'react';
import { Text } from 'ink';
import { theme } from '../semantic-colors.js';
import stringWidth from 'string-width';
import { createDebugLogger } from '@qwen-code/qwen-code-core';
// Constants for Markdown parsing
const BOLD_MARKER_LENGTH = 2; // For "**"
@ -17,6 +18,8 @@ const INLINE_CODE_MARKER_LENGTH = 1; // For "`"
const UNDERLINE_TAG_START_LENGTH = 3; // For "<u>"
const UNDERLINE_TAG_END_LENGTH = 4; // For "</u>"
const debugLogger = createDebugLogger('INLINE_MARKDOWN');
interface RenderInlineProps {
text: string;
textColor?: string;
@ -143,7 +146,7 @@ const RenderInlineInternal: React.FC<RenderInlineProps> = ({
);
}
} catch (e) {
console.error('Error parsing inline markdown part:', fullMatch, e);
debugLogger.error('Error parsing inline markdown part:', fullMatch, e);
renderedNode = null;
}

View file

@ -6,10 +6,12 @@
import * as fs from 'node:fs/promises';
import * as path from 'node:path';
import { execCommand } from '@qwen-code/qwen-code-core';
import { createDebugLogger, execCommand } from '@qwen-code/qwen-code-core';
const MACOS_CLIPBOARD_TIMEOUT_MS = 1500;
const debugLogger = createDebugLogger('CLIPBOARD_UTILS');
/**
* Checks if the system clipboard contains an image (macOS only for now)
* @returns true if clipboard contains an image
@ -115,7 +117,7 @@ export async function saveClipboardImage(
// No format worked
return null;
} catch (error) {
console.error('Error saving clipboard image:', error);
debugLogger.error('Error saving clipboard image:', error);
return null;
}
}

View file

@ -6,6 +6,7 @@
import type { SpawnOptions } from 'node:child_process';
import { spawn } from 'node:child_process';
import { createDebugLogger } from '@qwen-code/qwen-code-core';
/**
* Common Windows console code pages (CP) used for encoding conversions.
@ -61,6 +62,8 @@ export const isSlashCommand = (query: string): boolean => {
return true;
};
const debugLogger = createDebugLogger('COMMAND_UTILS');
// Copies a string snippet to the clipboard for different platforms
export const copyToClipboard = async (text: string): Promise<void> => {
const run = (cmd: string, args: string[], options?: SpawnOptions) =>
@ -162,7 +165,7 @@ export const getUrlOpenCommand = (): string => {
default:
// Default to xdg-open, which appears to be supported for the less popular operating systems.
openCmd = 'xdg-open';
console.warn(
debugLogger.warn(
`Unknown platform: ${process.platform}. Attempting to open URLs with: ${openCmd}.`,
);
break;

View file

@ -114,7 +114,7 @@ async function backupFile(filePath: string): Promise<void> {
await fs.copyFile(filePath, backupPath);
} catch (error) {
// Log backup errors but continue with operation
console.warn(`Failed to create backup of ${filePath}:`, error);
debugLogger.warn(`Failed to create backup of ${filePath}:`, error);
}
}

View file

@ -8,6 +8,9 @@ import type { UpdateInfo } from 'update-notifier';
import updateNotifier from 'update-notifier';
import semver from 'semver';
import { getPackageJson } from '../../utils/package.js';
import { createDebugLogger } from '@qwen-code/qwen-code-core';
const debugLogger = createDebugLogger('UPDATE_CHECK');
export const FETCH_TIMEOUT_MS = 2000;
@ -95,7 +98,7 @@ export async function checkForUpdates(): Promise<UpdateObject | null> {
return null;
} catch (e) {
console.warn('Failed to check for updates: ' + e);
debugLogger.warn('Failed to check for updates: ' + e);
return null;
}
}