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
7 changes: 6 additions & 1 deletion lua/opencode/ui/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ function M.format_message_header(message, previous_message)
M._format_callout(output, 'ERROR', error_message)
end

output:add_line('')
local hidden_same_mode_assistant_header = role == 'assistant' and header_style == 'hidden' and same_mode_as_previous

if not hidden_same_mode_assistant_header then
output:add_line('')
end

return output
end

Expand Down
56 changes: 55 additions & 1 deletion tests/unit/formatter_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,64 @@ describe('formatter', function()
parts = {},
})

assert.are.same({ '' }, output.lines)
assert.are.same({}, output.lines)
assert.is_nil(output.extmarks[0])
end)

it('does not add a spacing-only block for hidden same-mode assistant messages', function()
config.setup({
ui = {
output = {
compact_assistant_headers = 'hidden',
},
},
})

local previous_message = {
info = {
id = 'msg_prev',
role = 'assistant',
sessionID = 'ses_1',
mode = 'build',
},
parts = {},
}

local current_message = {
info = {
id = 'msg_current',
role = 'assistant',
sessionID = 'ses_1',
mode = 'build',
},
parts = {},
}

local previous_part = formatter.format_part({
id = 'prt_prev',
type = 'text',
text = 'First reply',
messageID = 'msg_prev',
sessionID = 'ses_1',
}, previous_message, true)

local header = formatter.format_message_header(current_message, previous_message)
local current_part = formatter.format_part({
id = 'prt_current',
type = 'text',
text = 'Second reply',
messageID = 'msg_current',
sessionID = 'ses_1',
}, current_message, true)

local combined_lines = {}
vim.list_extend(combined_lines, previous_part.lines)
vim.list_extend(combined_lines, header.lines)
vim.list_extend(combined_lines, current_part.lines)

assert.are.same({ 'First reply', '', 'Second reply', '' }, combined_lines)
end)

it('keeps full assistant headers when the mode changes', function()
config.setup({
ui = {
Expand Down
Loading