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
11 changes: 6 additions & 5 deletions packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ export type PromptInfo = {
)[]
}

const MAX_HISTORY_ENTRIES = 50

export const { use: usePromptHistory, provider: PromptHistoryProvider } = createSimpleContext({
name: "PromptHistory",
init: () => {
const historyFile = Bun.file(path.join(Global.Path.state, "prompt-history.jsonl"))
// Default to 50, this will be overridden by config if set
let maxEntries = 50

onMount(async () => {
const text = await historyFile.text().catch(() => "")
const lines = text
Expand All @@ -44,7 +45,7 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create
}
})
.filter((line): line is PromptInfo => line !== null)
.slice(-MAX_HISTORY_ENTRIES)
.slice(-maxEntries)

setStore("history", lines)

Expand Down Expand Up @@ -87,8 +88,8 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create
setStore(
produce((draft) => {
draft.history.push(entry)
if (draft.history.length > MAX_HISTORY_ENTRIES) {
draft.history = draft.history.slice(-MAX_HISTORY_ENTRIES)
if (draft.history.length > maxEntries) {
draft.history = draft.history.slice(-maxEntries)
trimmed = true
}
draft.index = 0
Expand Down
7 changes: 7 additions & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,13 @@ export namespace Config {
.enum(["auto", "stacked"])
.optional()
.describe("Control diff rendering style: 'auto' adapts to terminal width, 'stacked' always shows single column"),
prompt_history_max_size: z
.number()
.int()
.positive()
.optional()
.default(50)
.describe("Maximum number of prompt history entries to keep in memory"),
})

export const Layout = z.enum(["auto", "stretch"]).meta({
Expand Down