feat(core,cli): migrate console.debug to debugLogger (M3 Phase 1-3)

This commit is contained in:
tanzhenxin 2026-01-25 20:57:25 +08:00
parent ba2824b0b0
commit 3959b73bce
63 changed files with 554 additions and 538 deletions

View file

@ -24,6 +24,7 @@ import {
} from './tools.js';
import { DEFAULT_QWEN_MODEL } from '../config/models.js';
import { ToolNames, ToolDisplayNames } from './tool-names.js';
import { createDebugLogger, type DebugLogger } from '../utils/debugLogger.js';
const URL_FETCH_TIMEOUT_MS = 10000;
const MAX_CONTENT_LENGTH = 100000;
@ -49,11 +50,14 @@ class WebFetchToolInvocation extends BaseToolInvocation<
WebFetchToolParams,
ToolResult
> {
private readonly debugLogger: DebugLogger;
constructor(
private readonly config: Config,
params: WebFetchToolParams,
) {
super(params);
this.debugLogger = createDebugLogger('WEB_FETCH');
}
private async executeDirectFetch(signal: AbortSignal): Promise<ToolResult> {
@ -64,22 +68,24 @@ class WebFetchToolInvocation extends BaseToolInvocation<
url = url
.replace('github.com', 'raw.githubusercontent.com')
.replace('/blob/', '/');
console.debug(
this.debugLogger.debug(
`[WebFetchTool] Converted GitHub blob URL to raw URL: ${url}`,
);
}
try {
console.debug(`[WebFetchTool] Fetching content from: ${url}`);
this.debugLogger.debug(`[WebFetchTool] Fetching content from: ${url}`);
const response = await fetchWithTimeout(url, URL_FETCH_TIMEOUT_MS);
if (!response.ok) {
const errorMessage = `Request failed with status code ${response.status} ${response.statusText}`;
console.error(`[WebFetchTool] ${errorMessage}`);
this.debugLogger.error(`[WebFetchTool] ${errorMessage}`);
throw new Error(errorMessage);
}
console.debug(`[WebFetchTool] Successfully fetched content from ${url}`);
this.debugLogger.debug(
`[WebFetchTool] Successfully fetched content from ${url}`,
);
const html = await response.text();
const textContent = convert(html, {
wordwrap: false,
@ -89,7 +95,7 @@ class WebFetchToolInvocation extends BaseToolInvocation<
],
}).substring(0, MAX_CONTENT_LENGTH);
console.debug(
this.debugLogger.debug(
`[WebFetchTool] Converted HTML to text (${textContent.length} characters)`,
);
@ -102,7 +108,7 @@ I have fetched the content from ${this.params.url}. Please use the following con
${textContent}
---`;
console.debug(
this.debugLogger.debug(
`[WebFetchTool] Processing content with prompt: "${this.params.prompt}"`,
);
@ -114,7 +120,7 @@ ${textContent}
);
const resultText = getResponseText(result) || '';
console.debug(
this.debugLogger.debug(
`[WebFetchTool] Successfully processed content from ${this.params.url}`,
);
@ -125,7 +131,7 @@ ${textContent}
} catch (e) {
const error = e as Error;
const errorMessage = `Error during fetch for ${url}: ${error.message}`;
console.error(`[WebFetchTool] ${errorMessage}`, error);
this.debugLogger.error(`[WebFetchTool] ${errorMessage}`, error);
return {
llmContent: `Error: ${errorMessage}`,
returnDisplay: `Error: ${errorMessage}`,
@ -171,11 +177,11 @@ ${textContent}
const isPrivate = isPrivateIp(this.params.url);
if (isPrivate) {
console.debug(
this.debugLogger.debug(
`[WebFetchTool] Private IP detected for ${this.params.url}, using direct fetch`,
);
} else {
console.debug(
this.debugLogger.debug(
`[WebFetchTool] Public URL detected for ${this.params.url}, using direct fetch`,
);
}