Skip to content

Commit f26b069

Browse files
Danilo Verde RibeiroDanilo Verde Ribeiro
authored andcommitted
refactor: clean up PR sudo-tee#42 based on maintainer feedback
- Remove unnecessary inline type annotations in session_formatter.lua - Remove deprecated assistant_mode field from Message type - Simplify mode field documentation - Remove assistant_mode fallback logic in header formatting - Restore accidentally deleted keymap and context config fields - Fix indentation inconsistencies This addresses all review feedback from @sudo-tee while preserving the core feature: using CLI-persisted mode field to display agent names (BUILD, PLAN, etc.) in assistant message headers.
1 parent c3f6e17 commit f26b069

2 files changed

Lines changed: 56 additions & 24 deletions

File tree

lua/opencode/types.lua

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
---@field diff_close string
5858
---@field diff_revert_all_last_prompt string
5959
---@field diff_revert_this_last_prompt string
60+
---@field diff_revert_all string
61+
---@field diff_revert_this string
62+
---@field diff_restore_snapshot_file string
63+
---@field diff_restore_snapshot_all string
64+
---@field open_configuration_file string
6065
---@field swap_position string # Swap Opencode pane left/right
6166

6267
---@class OpencodeKeymapWindow
@@ -72,12 +77,9 @@
7277
---@field toggle_pane string
7378
---@field prev_prompt_history string
7479
---@field next_prompt_history string
75-
---@field focus_input string
76-
---@field debug_message string
77-
---@field debug_session string
78-
---@field debug_output string
7980
---@field switch_mode string
80-
---@field select_child_session string
81+
---@field focus_input string
82+
---@field select_child_session string\n---@field debug_message string\n---@field debug_output string\n---@field debug_session string
8183
---@class OpencodeKeymap
8284
---@field global OpencodeKeymapGlobal
8385
---@field window OpencodeKeymapWindow
@@ -109,17 +111,52 @@
109111

110112
---@class OpencodeContextConfig
111113
---@field enabled boolean
114+
---@field plugin_versions { enabled: boolean, limit: number }
112115
---@field cursor_data { enabled: boolean }
113116
---@field diagnostics { info: boolean, warning: boolean, error: boolean }
114-
---@field current_file { enabled: boolean }
117+
---@field current_file { enabled: boolean, show_full_path: boolean }
115118
---@field selection { enabled: boolean }
119+
---@field marks { enabled: boolean, limit: number }
120+
---@field jumplist { enabled: boolean, limit: number }
121+
---@field recent_buffers { enabled: boolean, limit: number, symbols_only: boolean }
122+
---@field undo_history { enabled: boolean, limit: number }
123+
---@field windows_tabs { enabled: boolean }
124+
---@field highlights { enabled: boolean }
125+
---@field session_info { enabled: boolean }
126+
---@field registers { enabled: boolean, include: string[] }
127+
---@field command_history { enabled: boolean, limit: number }
128+
---@field search_history { enabled: boolean, limit: number }
129+
---@field debug_data { enabled: boolean }
130+
---@field lsp_context { enabled: boolean, diagnostics_limit: number, code_actions: boolean }
131+
---@field git_info { enabled: boolean, diff_limit: number, changes_limit: number }
132+
---@field fold_info { enabled: boolean }
133+
---@field cursor_surrounding { enabled: boolean, lines_above: number, lines_below: number }
134+
---@field quickfix_loclist { enabled: boolean, limit: number }
135+
---@field macros { enabled: boolean, register: string }
136+
---@field terminal_buffers { enabled: boolean }
137+
---@field session_duration { enabled: boolean }
116138

117139
---@class OpencodeDebugConfig
118140
---@field enabled boolean
119141

120142
--- @class OpencodeProviders
121143
--- @field [string] string[]
122144

145+
---@class OpencodeConfigModule
146+
---@field defaults OpencodeConfig
147+
---@field values OpencodeConfig
148+
---@field setup fun(opts?: OpencodeConfig): nil
149+
---@overload fun(key: nil): OpencodeConfig
150+
---@overload fun(key: "preferred_picker"): 'mini.pick' | 'telescope' | 'fzf' | 'snacks' | nil
151+
---@overload fun(key: "preferred_completion"): 'blink' | 'nvim-cmp' | 'vim_complete' | nil
152+
---@overload fun(key: "default_mode"): 'build' | 'plan'
153+
---@overload fun(key: "default_global_keymaps"): boolean
154+
---@overload fun(key: "keymap"): OpencodeKeymap
155+
---@overload fun(key: "ui"): OpencodeUIConfig
156+
---@overload fun(key: "providers"): OpencodeProviders
157+
---@overload fun(key: "context"): OpencodeContextConfig
158+
---@overload fun(key: "debug"): OpencodeDebugConfig
159+
123160
---@class OpencodeConfig
124161
---@field preferred_picker 'telescope' | 'fzf' | 'mini.pick' | 'snacks' | nil
125162
---@field preferred_completion 'blink' | 'nvim-cmp' | 'vim_complete' | nil -- Preferred completion strategy for mentons and commands
@@ -256,8 +293,7 @@
256293
---@field providerID string Provider identifier
257294
---@field role 'user'|'assistant'|'system' Role of the message sender
258295
---@field system_role string|nil Role defined in system messages
259-
---@field mode string|nil Agent/mode used to create this message (from CLI)
260-
---@field assistant_mode string|nil Assistant mode active when message was created (deprecated)
296+
---@field mode string|nil Agent or mode identifier
261297
---@field error table
262298

263299
---@class RestorePoint

lua/opencode/ui/session_formatter.lua

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ function M._format_revert_message(stats)
192192
end
193193
if #file_diff > 0 then
194194
local line_str = string.format(icons.get('file') .. '%s: %s', file, table.concat(file_diff, ' '))
195-
local line_idx = M.output:add_line(line_str) ---@type number
196-
local col = #(' ' .. file .. ': ') ---@type number
195+
local line_idx = M.output:add_line(line_str)
196+
local col = #(' ' .. file .. ': ')
197197
for _, diff in ipairs(file_diff) do
198-
local hl_group = diff:sub(1, 1) == '+' and 'OpencodeDiffAddText' or 'OpencodeDiffDeleteText' ---@type string
198+
local hl_group = diff:sub(1, 1) == '+' and 'OpencodeDiffAddText' or 'OpencodeDiffDeleteText'
199199
M.output:add_extmark(line_idx, {
200200
virt_text = { { diff, hl_group } },
201201
virt_text_pos = 'inline',
@@ -251,7 +251,7 @@ function M._format_patch(part)
251251
util.time_ago(restore_point.created_at)
252252
)
253253
)
254-
local restore_line = M.output:get_line_count() ---@type number
254+
local restore_line = M.output:get_line_count()
255255
M.output:add_action({
256256
text = 'Restore [A]ll',
257257
type = 'diff_restore_snapshot_all',
@@ -293,10 +293,9 @@ function M._format_message_header(message, msg_idx)
293293
M.output:add_empty_line()
294294
M.output:add_metadata({ msg_idx = msg_idx, part_idx = 1, role = role, type = 'header' })
295295

296-
-- Use the mode field from the message (stable label from CLI)
297296
local display_name
298297
if role == 'assistant' then
299-
local mode = message.mode or message.assistant_mode
298+
local mode = message.mode
300299
if mode and mode ~= '' then
301300
display_name = mode:upper()
302301
else
@@ -360,7 +359,7 @@ function M._format_user_message(text, message)
360359
context = context_module.extract_from_opencode_message(message)
361360
end
362361

363-
local start_line = M.output:get_line_count() - 1 ---@type number
362+
local start_line = M.output:get_line_count() - 1
364363

365364
M.output:add_empty_line()
366365
M.output:add_lines(vim.split(context.prompt, '\n'))
@@ -378,7 +377,7 @@ function M._format_user_message(text, message)
378377
M.output:add_line(string.format('[%s](%s)', path, context.current_file))
379378
end
380379

381-
local end_line = M.output:get_line_count() ---@type number
380+
local end_line = M.output:get_line_count()
382381

383382
M._add_vertical_border(start_line, end_line, 'OpencodeMessageRoleUser', -3)
384383
end
@@ -519,12 +518,9 @@ function M._format_tool(part)
519518
end
520519

521520
local start_line = M.output:get_line_count() + 1
522-
---@type TaskToolInput|BashToolInput|FileToolInput|TodoToolInput|GlobToolInput|GrepToolInput|WebFetchToolInput|ListToolInput
523-
local input = (part.state and part.state.input) or {}
524-
---@type ToolMetadataBase|TaskToolMetadata|WebFetchToolMetadata|BashToolMetadata|FileToolMetadata|GlobToolMetadata|GrepToolMetadata|ListToolMetadata
525-
local metadata = (part.state and part.state.metadata) or {}
526-
---@type string
527-
local output = (part.state and part.state.output) or ''
521+
local input = (part.state and part.state.input) or {}
522+
local metadata = (part.state and part.state.metadata) or {}
523+
local output = (part.state and part.state.output) or ''
528524

529525
if tool == 'bash' then
530526
M._format_bash_tool(input --[[@as BashToolInput]], metadata --[[@as BashToolMetadata]])
@@ -552,7 +548,7 @@ function M._format_tool(part)
552548

553549
M.output:add_empty_line()
554550

555-
local end_line = M.output:get_line_count() ---@type number
551+
local end_line = M.output:get_line_count()
556552
if end_line - start_line > 1 then
557553
M._add_vertical_border(start_line, end_line - 1, 'OpencodeToolBorder', -1)
558554
end
@@ -581,7 +577,7 @@ function M._format_task_tool(input, metadata, output)
581577
end
582578
end
583579

584-
local end_line = M.output:get_line_count() ---@type number
580+
local end_line = M.output:get_line_count()
585581
M.output:add_action({
586582
text = '[S]elect Child Session',
587583
type = 'select_child_session',

0 commit comments

Comments
 (0)