Skip to content
Merged
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
47 changes: 47 additions & 0 deletions lua/opencode/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,39 @@ function M.toggle_reasoning_output()
ui.render_output()
end

---@type fun(): Promise<void>
M.review = Promise.async(function(args)
local id = require('opencode.id')

local new_session = core.create_new_session('Code review checklist for diffs and PRs'):await()
if not new_session then
vim.notify('Failed to create new session', vim.log.levels.ERROR)
return
end
if not core.initialize_current_model():await() or not state.current_model then
vim.notify('No model selected', vim.log.levels.ERROR)
return
end
local providerId, modelId = state.current_model:match('^(.-)/(.+)$')
if not providerId or not modelId then
vim.notify('Invalid model format: ' .. tostring(state.current_model), vim.log.levels.ERROR)
return
end
state.active_session = new_session
M.open_input():await()
state.api_client
:send_command(state.active_session.id, {
command = 'review',
arguments = table.concat(args or {}, ' '),
model = state.current_model,
})
:and_then(function()
vim.schedule(function()
require('opencode.history').write('/review ' .. table.concat(args or {}, ' '))
end)
end)
end)

---@type table<string, OpencodeUICommand>
M.commands = {
open = {
Expand Down Expand Up @@ -1008,6 +1041,14 @@ M.commands = {
fn = M.swap_position,
},

review = {
desc = 'Review changes [commit|branch|pr], defaults to uncommitted changes',
fn = function(args)
M.review(args)
end,
nargs = '+',
},

session = {
desc = 'Manage sessions (new/select/child/compact/share/unshare/rename)',
completions = { 'new', 'select', 'child', 'compact', 'share', 'unshare', 'agents_init', 'rename' },
Expand Down Expand Up @@ -1304,6 +1345,11 @@ M.slash_commands_map = {
['/rename'] = { fn = M.rename_session, desc = 'Rename current session' },
['/thinking'] = { fn = M.toggle_reasoning_output, desc = 'Toggle reasoning output' },
['/reasoning'] = { fn = M.toggle_reasoning_output, desc = 'Toggle reasoning output' },
['/review'] = {
fn = M.review,
desc = 'Review changes [commit|branch|pr], defaults to uncommitted changes',
args = true,
},
}

M.legacy_command_map = {
Expand Down Expand Up @@ -1442,6 +1488,7 @@ M.get_slash_commands = Promise.async(function()
slash_cmd = slash_cmd,
desc = def.desc,
fn = def.fn,
args = def.args or false,
})
end

Expand Down