Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ require('opencode').setup({
markdown_debounce_ms = 250, -- Debounce time for markdown rendering on new data (default: 250ms)
on_data_rendered = nil, -- Called when new data is rendered; set to false to disable default RenderMarkdown/Markview behavior
},
max_messages = nil, -- Max number of messages to keep in the output buffer; older messages will be removed as new ones arrive (default: nil, which means no limit)
},
input = {
min_height = 0.10, -- min height of prompt input as percentage of window height
Expand Down
1 change: 1 addition & 0 deletions lua/opencode/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ local action_groups = {
debug_session = workflow.debug_session,
toggle_tool_output = workflow.toggle_tool_output,
toggle_reasoning_output = workflow.toggle_reasoning_output,
toggle_max_messages = workflow.toggle_max_messages,
submit_input_prompt = workflow.submit_input_prompt,
run = workflow.run,
run_new_session = workflow.run_new_session,
Expand Down
21 changes: 21 additions & 0 deletions lua/opencode/commands/handlers/workflow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,23 @@ function M.actions.toggle_reasoning_output()
ui.render_output()
end

local original_max_messages = config.ui.output.max_messages
function M.actions.toggle_max_messages()
local current = config.ui.output.max_messages
local next_val
if type(current) == 'number' and current > 0 then
next_val = nil
else
next_val = original_max_messages or 20
end

local action_text = next_val == nil and 'Disabling' or 'Enabling'
local val_text = next_val == nil and 'none' or tostring(next_val)
vim.notify(action_text .. ' message limit to ' .. val_text, vim.log.levels.INFO)
config.values.ui.output.max_messages = next_val
ui.render_output()
end

M.actions.review = Promise.async(function(args)
local new_session = core.create_new_session('Code review checklist for diffs and PRs'):await()
if not new_session then
Expand Down Expand Up @@ -453,6 +470,10 @@ M.command_defs = {
desc = 'Toggle reasoning output visibility in the output window',
execute = M.actions.toggle_reasoning_output,
},
toggle_max_messages = {
desc = 'Toggle maximum number of rendered messages',
execute = M.actions.toggle_max_messages,
},
paste_image = {
desc = 'Paste image from clipboard and add to context',
execute = M.actions.paste_image,
Expand Down
3 changes: 3 additions & 0 deletions lua/opencode/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ M.defaults = {
['<leader>ox'] = { 'swap_position', desc = 'Swap window position' },
['<leader>otr'] = { 'toggle_reasoning_output', desc = 'Toggle reasoning output' },
['<leader>ott'] = { 'toggle_tool_output', desc = 'Toggle tool output' },
['<leader>otm'] = { 'toggle_max_messages', desc = 'Toggle max messages' },
['<leader>o/'] = { 'quick_chat', mode = { 'n', 'x' }, desc = 'Quick chat with current context' },

},
output_window = {
['<esc>'] = { 'close', desc = 'Close Opencode windows' },
Expand Down Expand Up @@ -155,6 +157,7 @@ M.defaults = {
show_output = true,
show_reasoning_output = true,
},
max_messages = nil,
always_scroll_to_bottom = false,
},
questions = {
Expand Down
3 changes: 2 additions & 1 deletion lua/opencode/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
---@class OpencodeUIOutputConfig
---@field tools { show_output: boolean, show_reasoning_output: boolean }
---@field rendering OpencodeUIOutputRenderingConfig
---@field max_messages integer|nil
---@field always_scroll_to_bottom boolean
---@field filetype string
---@field compact_assistant_headers boolean
Expand Down Expand Up @@ -498,7 +499,7 @@

---@class OutputAction
---@field text string Action text
---@field type 'diff_revert_all'|'diff_revert_selected_file'|'diff_open'|'diff_restore_snapshot_file'|'diff_restore_snapshot_all'|'select_child_session' Type of action
---@field type 'diff_revert_all'|'diff_revert_selected_file'|'diff_open'|'diff_restore_snapshot_file'|'diff_restore_snapshot_all'|'select_child_session'|'toggle_max_messages'
---@field args? string[] Optional arguments for the command
---@field key string keybinding for the action
---@field display_line number Line number to display the action
Expand Down
30 changes: 30 additions & 0 deletions lua/opencode/ui/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ function M._format_revert_message(session_data, start_idx)
return output
end

---@param hidden_count integer
---@return Output
function M._format_hidden_messages_notice(hidden_count)
local output = Output.new()
local message_text = hidden_count == 1 and 'message is' or 'messages are'

output:add_line(string.format('> %d older %s not displayed.', hidden_count, message_text))
output:add_action({
text = 'Show [A]ll messages',
type = 'toggle_max_messages',
args = {},
key = 'A',
display_line = output:get_line_count() - 1,
range = { from = output:get_line_count() - 1, to = output:get_line_count() - 1 },
})
output:add_empty_line()

return output
end

---@param output Output
---@param text string
---@param action_type string
Expand Down Expand Up @@ -167,6 +187,10 @@ function M.format_message_header(message, previous_message)
return output
end

if message.info and message.info.id == '__opencode_hidden_messages_notice__' then
return output
end

local role = message.info.role or 'unknown'
local icon = message.info.role == 'user' and icons.get('header_user') or icons.get('header_assistant')

Expand Down Expand Up @@ -664,6 +688,12 @@ function M.format_part(part, message, is_last_part, get_child_parts)
output = M._format_revert_message(state.messages or {}, revert_index)
content_added = output:get_line_count() > 0
end
elseif part.type == 'hidden-messages-display' then
local hidden_count = part.state and part.state.hidden_count
if type(hidden_count) == 'number' and hidden_count > 0 then
output = M._format_hidden_messages_notice(hidden_count)
content_added = output:get_line_count() > 0
end
end
end

Expand Down
Loading
Loading