Skip to content
Open
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
15 changes: 11 additions & 4 deletions packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path"
import { Global } from "@/global"
import { Filesystem } from "@/util"
import { Filesystem, Log } from "@/util"
import { onMount } from "solid-js"
import { createStore, produce, unwrap } from "solid-js/store"
import { createSimpleContext } from "../../context/helper"
Expand Down Expand Up @@ -31,6 +31,7 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create
name: "PromptHistory",
init: () => {
const historyPath = path.join(Global.Path.state, "prompt-history.jsonl")
const log = Log.create({ service: "prompt-history" })
onMount(async () => {
const text = await Filesystem.readText(historyPath).catch(() => "")
const lines = text
Expand All @@ -51,7 +52,9 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create
// Rewrite file with only valid entries to self-heal corruption
if (lines.length > 0) {
const content = lines.map((line) => JSON.stringify(line)).join("\n") + "\n"
writeFile(historyPath, content).catch(() => {})
writeFile(historyPath, content).catch((error) => {
log.error("Failed to rewrite history file during self-heal", { path: historyPath, error })
})
}
})

Expand Down Expand Up @@ -97,11 +100,15 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create

if (trimmed) {
const content = store.history.map((line) => JSON.stringify(line)).join("\n") + "\n"
writeFile(historyPath, content).catch(() => {})
writeFile(historyPath, content).catch((error) => {
log.error("Failed to trim history file", { path: historyPath, error })
})
return
}

appendFile(historyPath, JSON.stringify(entry) + "\n").catch(() => {})
appendFile(historyPath, JSON.stringify(entry) + "\n").catch((error) => {
log.error("Failed to append to history file", { path: historyPath, error })
})
},
}
},
Expand Down