diff --git a/packages/opencode/src/cli/cmd/tui/app.tsx b/packages/opencode/src/cli/cmd/tui/app.tsx index 31897111..348ce1e5 100644 --- a/packages/opencode/src/cli/cmd/tui/app.tsx +++ b/packages/opencode/src/cli/cmd/tui/app.tsx @@ -62,6 +62,7 @@ import { Provider } from "@/provider" import { ArgsProvider, useArgs, type Args } from "./context/args" import open from "open" import { Process } from "@/util" +import * as Log from "@/util/log" import { PromptRefProvider, usePromptRef } from "./context/prompt" import { TuiConfigProvider, useTuiConfig } from "./context/tui-config" import { TuiConfig } from "@/cli/cmd/tui/config/tui" @@ -99,7 +100,7 @@ function rendererConfig(_config: TuiConfig.Info, plainTerminal: boolean): CliRen keyBindings: [{ name: "y", ctrl: true, action: "copy-selection" }], onCopySelection: (text) => { Clipboard.copy(text).catch((error) => { - console.error(`Failed to copy console selection to clipboard: ${error}`) + log.warn("Failed to copy console selection to clipboard", { error }) }) }, }, @@ -267,12 +268,13 @@ function App(props: { onSnapshot?: () => Promise }) { renderer, }) const [ready, setReady] = createSignal(false) + const log = Log.create({ service: "tui.app" }) TuiPluginRuntime.init({ api, config: tuiConfig, }) .catch((error) => { - console.error("Failed to load TUI plugins", error) + log.warn("Failed to load TUI plugins", { error }) }) .finally(() => { setReady(true) diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx index b1616b95..e750d408 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -45,6 +45,7 @@ import { DialogWorkspaceCreate, restoreWorkspaceSession } from "../dialog-worksp import { DialogWorkspaceUnavailable } from "../dialog-workspace-unavailable" import { DialogAgreement, FREE_AGREEMENT_KEY, FREE_MODEL_IDS } from "../dialog-agreement" import { useArgs } from "@tui/context/args" +import * as Log from "@/util/log" export type PromptProps = { sessionID?: string @@ -1063,7 +1064,7 @@ export function Prompt(props: PromptProps) { const res = await sdk.client.session.create({ workspace: props.workspaceID }) if (res.error) { - console.log("Creating a session failed:", res.error) + log.warn("Creating a session failed", { error: res.error }) toast.show({ message: "Creating a session failed. Open console for more details.", diff --git a/packages/opencode/src/cli/cmd/tui/context/kv.tsx b/packages/opencode/src/cli/cmd/tui/context/kv.tsx index 17cc0764..acabd95f 100644 --- a/packages/opencode/src/cli/cmd/tui/context/kv.tsx +++ b/packages/opencode/src/cli/cmd/tui/context/kv.tsx @@ -1,4 +1,5 @@ import { Global } from "@/global" +import * as Log from "@/util/log" import { Filesystem } from "@/util" import { Flock } from "@mimo-ai/shared/util/flock" import { rename, rm } from "fs/promises" @@ -14,6 +15,7 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({ const [store, setStore] = createStore>() const filePath = path.join(Global.Path.state, "kv.json") const lock = `tui-kv:${filePath}` + const log = Log.create({ service: "tui.kv" }) // Queue same-process writes so rapid updates persist in order. let write = Promise.resolve() @@ -34,7 +36,7 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({ setStore(x) }) .catch((error) => { - console.error("Failed to read KV state", { filePath, error }) + log.warn("Failed to read KV state", { filePath, error }) }) .finally(() => { setReady(true) @@ -67,7 +69,7 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({ write = write .then(() => Flock.withLock(lock, () => writeSnapshot(snapshot))) .catch((error) => { - console.error("Failed to write KV state", { filePath, error }) + log.warn("Failed to write KV state", { filePath, error }) }) }, delete(key: string) { @@ -77,7 +79,7 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({ write = write .then(() => Flock.withLock(lock, () => writeSnapshot(snapshot))) .catch((error) => { - console.error("Failed to write KV state", { filePath, error }) + log.warn("Failed to write KV state", { filePath, error }) }) }, } diff --git a/packages/opencode/src/cli/cmd/tui/plugin/runtime.ts b/packages/opencode/src/cli/cmd/tui/plugin/runtime.ts index 7f93ca84..45068689 100644 --- a/packages/opencode/src/cli/cmd/tui/plugin/runtime.ts +++ b/packages/opencode/src/cli/cmd/tui/plugin/runtime.ts @@ -90,19 +90,16 @@ const EMPTY_TUI: TuiPluginModule = { function fail(message: string, data: Record) { if (!("error" in data)) { log.error(message, data) - console.error(`[tui.plugin] ${message}`, data) return } const text = `${message}: ${errorMessage(data.error)}` const next = { ...data, error: errorData(data.error) } log.error(text, next) - console.error(`[tui.plugin] ${text}`, next) } function warn(message: string, data: Record) { log.warn(message, data) - console.warn(`[tui.plugin] ${message}`, data) } type CleanupResult = { type: "ok" } | { type: "error"; error: unknown } | { type: "timeout" } diff --git a/packages/opencode/src/cli/cmd/tui/plugin/slots.tsx b/packages/opencode/src/cli/cmd/tui/plugin/slots.tsx index 2c0159f8..d449e9cd 100644 --- a/packages/opencode/src/cli/cmd/tui/plugin/slots.tsx +++ b/packages/opencode/src/cli/cmd/tui/plugin/slots.tsx @@ -1,6 +1,7 @@ import type { TuiPluginApi, TuiSlotContext, TuiSlotMap, TuiSlotProps } from "@mimo-ai/plugin/tui" import { createSlot, createSolidSlotRegistry, type JSX, type SolidPlugin } from "@opentui/solid" import { isRecord } from "@/util/record" +import * as Log from "@/util/log" type RuntimeSlotMap = TuiSlotMap> @@ -38,12 +39,13 @@ export function setupSlots(api: HostPluginApi): HostSlots { }, { onPluginError(event) { - console.error("[tui.slot] plugin error", { + const log = Log.create({ service: "tui.slot" }) + log.error("plugin error", { plugin: event.pluginId, slot: event.slot, phase: event.phase, source: event.source, - message: event.error.message, + error: event.error.message, }) }, },