Skip to content

Commit e15db4a

Browse files
authored
feat(api): add '/review' command for code review checklist and diff/PR review (#186)
1 parent 5b93cef commit e15db4a

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

lua/opencode/api.lua

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,39 @@ function M.toggle_reasoning_output()
941941
ui.render_output()
942942
end
943943

944+
---@type fun(): Promise<void>
945+
M.review = Promise.async(function(args)
946+
local id = require('opencode.id')
947+
948+
local new_session = core.create_new_session('Code review checklist for diffs and PRs'):await()
949+
if not new_session then
950+
vim.notify('Failed to create new session', vim.log.levels.ERROR)
951+
return
952+
end
953+
if not core.initialize_current_model():await() or not state.current_model then
954+
vim.notify('No model selected', vim.log.levels.ERROR)
955+
return
956+
end
957+
local providerId, modelId = state.current_model:match('^(.-)/(.+)$')
958+
if not providerId or not modelId then
959+
vim.notify('Invalid model format: ' .. tostring(state.current_model), vim.log.levels.ERROR)
960+
return
961+
end
962+
state.active_session = new_session
963+
M.open_input():await()
964+
state.api_client
965+
:send_command(state.active_session.id, {
966+
command = 'review',
967+
arguments = table.concat(args or {}, ' '),
968+
model = state.current_model,
969+
})
970+
:and_then(function()
971+
vim.schedule(function()
972+
require('opencode.history').write('/review ' .. table.concat(args or {}, ' '))
973+
end)
974+
end)
975+
end)
976+
944977
---@type table<string, OpencodeUICommand>
945978
M.commands = {
946979
open = {
@@ -1008,6 +1041,14 @@ M.commands = {
10081041
fn = M.swap_position,
10091042
},
10101043

1044+
review = {
1045+
desc = 'Review changes [commit|branch|pr], defaults to uncommitted changes',
1046+
fn = function(args)
1047+
M.review(args)
1048+
end,
1049+
nargs = '+',
1050+
},
1051+
10111052
session = {
10121053
desc = 'Manage sessions (new/select/child/compact/share/unshare/rename)',
10131054
completions = { 'new', 'select', 'child', 'compact', 'share', 'unshare', 'agents_init', 'rename' },
@@ -1304,6 +1345,11 @@ M.slash_commands_map = {
13041345
['/rename'] = { fn = M.rename_session, desc = 'Rename current session' },
13051346
['/thinking'] = { fn = M.toggle_reasoning_output, desc = 'Toggle reasoning output' },
13061347
['/reasoning'] = { fn = M.toggle_reasoning_output, desc = 'Toggle reasoning output' },
1348+
['/review'] = {
1349+
fn = M.review,
1350+
desc = 'Review changes [commit|branch|pr], defaults to uncommitted changes',
1351+
args = true,
1352+
},
13071353
}
13081354

13091355
M.legacy_command_map = {
@@ -1442,6 +1488,7 @@ M.get_slash_commands = Promise.async(function()
14421488
slash_cmd = slash_cmd,
14431489
desc = def.desc,
14441490
fn = def.fn,
1491+
args = def.args or false,
14451492
})
14461493
end
14471494

0 commit comments

Comments
 (0)