From ae8a6c5eb8047856a48cd2b24b245b4789c975c3 Mon Sep 17 00:00:00 2001 From: justsisyphus Date: Fri, 30 Jan 2026 12:45:37 +0900 Subject: [PATCH] refactor: replace console.log/warn/error with file-based log() for silent logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace all console output with shared logger to write to /tmp/oh-my-opencode.log instead of stdout/stderr. Files changed: - index.ts: console.warn → log() - hook-message-injector/injector.ts: console.warn → log() - lsp/client.ts: console.error → log() - ast-grep/downloader.ts: console.log/error → log() - session-recovery/index.ts: console.error → log() - comment-checker/downloader.ts: console.log/error → log() CLI tools (install.ts, doctor, etc.) retain console output for UX. --- src/features/hook-message-injector/injector.ts | 3 ++- src/hooks/comment-checker/downloader.ts | 9 +++++---- src/hooks/session-recovery/index.ts | 3 ++- src/index.ts | 2 +- src/tools/ast-grep/downloader.ts | 9 +++++---- src/tools/lsp/client.ts | 3 ++- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/features/hook-message-injector/injector.ts b/src/features/hook-message-injector/injector.ts index a4a238b8f..bd3c55371 100644 --- a/src/features/hook-message-injector/injector.ts +++ b/src/features/hook-message-injector/injector.ts @@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from import { join } from "node:path" import { MESSAGE_STORAGE, PART_STORAGE } from "./constants" import type { MessageMeta, OriginalMessageContext, TextPart, ToolPermission } from "./types" +import { log } from "../../shared/logger" export interface StoredMessage { agent?: string @@ -117,7 +118,7 @@ export function injectHookMessage( ): boolean { // Validate hook content to prevent empty message injection if (!hookContent || hookContent.trim().length === 0) { - console.warn("[hook-message-injector] Attempted to inject empty hook content, skipping injection", { + log("[hook-message-injector] Attempted to inject empty hook content, skipping injection", { sessionID, hasAgent: !!originalMessage.agent, hasModel: !!(originalMessage.model?.providerID && originalMessage.model?.modelID) diff --git a/src/hooks/comment-checker/downloader.ts b/src/hooks/comment-checker/downloader.ts index d57443329..b2b0b1475 100644 --- a/src/hooks/comment-checker/downloader.ts +++ b/src/hooks/comment-checker/downloader.ts @@ -4,6 +4,7 @@ import { join } from "path" import { homedir, tmpdir } from "os" import { createRequire } from "module" import { extractZip } from "../../shared" +import { log } from "../../shared/logger" const DEBUG = process.env.COMMENT_CHECKER_DEBUG === "1" const DEBUG_FILE = join(tmpdir(), "comment-checker-debug.log") @@ -127,7 +128,7 @@ export async function downloadCommentChecker(): Promise { const downloadUrl = `https://github.com/${REPO}/releases/download/v${version}/${assetName}` debugLog(`Downloading from: ${downloadUrl}`) - console.log(`[oh-my-opencode] Downloading comment-checker binary...`) + log(`[oh-my-opencode] Downloading comment-checker binary...`) try { // Ensure cache directory exists @@ -166,14 +167,14 @@ export async function downloadCommentChecker(): Promise { } debugLog(`Successfully downloaded binary to: ${binaryPath}`) - console.log(`[oh-my-opencode] comment-checker binary ready.`) + log(`[oh-my-opencode] comment-checker binary ready.`) return binaryPath } catch (err) { debugLog(`Failed to download: ${err}`) - console.error(`[oh-my-opencode] Failed to download comment-checker: ${err instanceof Error ? err.message : err}`) - console.error(`[oh-my-opencode] Comment checking disabled.`) + log(`[oh-my-opencode] Failed to download comment-checker: ${err instanceof Error ? err.message : err}`) + log(`[oh-my-opencode] Comment checking disabled.`) return null } } diff --git a/src/hooks/session-recovery/index.ts b/src/hooks/session-recovery/index.ts index 79f31fc5d..ffd090774 100644 --- a/src/hooks/session-recovery/index.ts +++ b/src/hooks/session-recovery/index.ts @@ -16,6 +16,7 @@ import { stripThinkingParts, } from "./storage" import type { MessageData, ResumeConfig } from "./types" +import { log } from "../../shared/logger" export interface SessionRecoveryOptions { experimental?: ExperimentalConfig @@ -414,7 +415,7 @@ export function createSessionRecoveryHook(ctx: PluginInput, options?: SessionRec return success } catch (err) { - console.error("[session-recovery] Recovery failed:", err) + log("[session-recovery] Recovery failed:", err) return false } finally { processingErrors.delete(assistantMsgID) diff --git a/src/index.ts b/src/index.ts index 240844d96..f97410e13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -118,7 +118,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => { if (externalNotifier.detected && !forceEnable) { // External notification plugin detected - skip our notification to avoid conflicts - console.warn(getNotificationConflictWarning(externalNotifier.pluginName!)); + log(getNotificationConflictWarning(externalNotifier.pluginName!)); log("session-notification disabled due to external notifier conflict", { detected: externalNotifier.pluginName, allPlugins: externalNotifier.allPlugins, diff --git a/src/tools/ast-grep/downloader.ts b/src/tools/ast-grep/downloader.ts index 6ed228847..d1addb184 100644 --- a/src/tools/ast-grep/downloader.ts +++ b/src/tools/ast-grep/downloader.ts @@ -3,6 +3,7 @@ import { join } from "path" import { homedir } from "os" import { createRequire } from "module" import { extractZip } from "../../shared" +import { log } from "../../shared/logger" const REPO = "ast-grep/ast-grep" @@ -63,7 +64,7 @@ export async function downloadAstGrep(version: string = DEFAULT_VERSION): Promis const platformInfo = PLATFORM_MAP[platformKey] if (!platformInfo) { - console.error(`[oh-my-opencode] Unsupported platform for ast-grep: ${platformKey}`) + log(`[oh-my-opencode] Unsupported platform for ast-grep: ${platformKey}`) return null } @@ -79,7 +80,7 @@ export async function downloadAstGrep(version: string = DEFAULT_VERSION): Promis const assetName = `app-${arch}-${os}.zip` const downloadUrl = `https://github.com/${REPO}/releases/download/${version}/${assetName}` - console.log(`[oh-my-opencode] Downloading ast-grep binary...`) + log(`[oh-my-opencode] Downloading ast-grep binary...`) try { if (!existsSync(cacheDir)) { @@ -106,11 +107,11 @@ export async function downloadAstGrep(version: string = DEFAULT_VERSION): Promis chmodSync(binaryPath, 0o755) } - console.log(`[oh-my-opencode] ast-grep binary ready.`) + log(`[oh-my-opencode] ast-grep binary ready.`) return binaryPath } catch (err) { - console.error( + log( `[oh-my-opencode] Failed to download ast-grep: ${err instanceof Error ? err.message : err}` ) return null diff --git a/src/tools/lsp/client.ts b/src/tools/lsp/client.ts index 8ba7dc629..b4802033a 100644 --- a/src/tools/lsp/client.ts +++ b/src/tools/lsp/client.ts @@ -11,6 +11,7 @@ import { } from "vscode-jsonrpc/node" import { getLanguageId } from "./config" import type { Diagnostic, ResolvedServer } from "./types" +import { log } from "../../shared/logger" interface ManagedClient { client: LSPClient @@ -306,7 +307,7 @@ export class LSPClient { }) this.connection.onError((error) => { - console.error("LSP connection error:", error) + log("LSP connection error:", error) }) this.connection.listen()