Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 })
})
},
},
Expand Down Expand Up @@ -267,12 +268,13 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
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)
Expand Down
3 changes: 2 additions & 1 deletion packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.",
Expand Down
8 changes: 5 additions & 3 deletions packages/opencode/src/cli/cmd/tui/context/kv.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -14,6 +15,7 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
const [store, setStore] = createStore<Record<string, any>>()
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()

Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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 })
})
},
}
Expand Down
3 changes: 0 additions & 3 deletions packages/opencode/src/cli/cmd/tui/plugin/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,16 @@ const EMPTY_TUI: TuiPluginModule = {
function fail(message: string, data: Record<string, unknown>) {
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<string, unknown>) {
log.warn(message, data)
console.warn(`[tui.plugin] ${message}`, data)
}

type CleanupResult = { type: "ok" } | { type: "error"; error: unknown } | { type: "timeout" }
Expand Down
6 changes: 4 additions & 2 deletions packages/opencode/src/cli/cmd/tui/plugin/slots.tsx
Original file line number Diff line number Diff line change
@@ -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<Record<string, object>>

Expand Down Expand Up @@ -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,
})
},
},
Expand Down