@@ -395,7 +395,7 @@ function M.select_agent()
395395end
396396
397397function M .switch_mode ()
398- local modes = require (' opencode.config_file' ).get_opencode_agents ()
398+ local modes = require (' opencode.config_file' ).get_opencode_agents () --[[ @as string[] ]]
399399
400400 local current_index = util .index_of (modes , state .current_mode )
401401
@@ -519,6 +519,33 @@ function M.mcp()
519519 ui .render_lines (msg )
520520end
521521
522+ function M .commands_list ()
523+ local info = require (' opencode.config_file' )
524+ local commands = info .get_user_commands ()
525+ if not commands then
526+ vim .notify (' No user commands found. Please check your opencode config file.' , vim .log .levels .WARN )
527+ return
528+ end
529+
530+ state .display_route = ' /commands'
531+ M .open_input ()
532+
533+ local msg = M .with_header ({
534+ ' ### Available User Commands' ,
535+ ' ' ,
536+ ' | Name | Description |' ,
537+ ' |------|-------------|' ,
538+ })
539+
540+ for name , def in pairs (commands ) do
541+ local desc = def .description or ' '
542+ table.insert (msg , string.format (' | %s | %s |' , name , desc ))
543+ end
544+
545+ table.insert (msg , ' ' )
546+ ui .render_lines (msg )
547+ end
548+
522549--- Runs a user-defined command by name.
523550--- @param name string The name of the user command to run.
524551--- @param args ? string[] Additional arguments to pass to the command.
@@ -1015,6 +1042,11 @@ M.commands = {
10151042 fn = M .mcp ,
10161043 },
10171044
1045+ commands_list = {
1046+ desc = ' Show user-defined commands' ,
1047+ fn = M .commands_list ,
1048+ },
1049+
10181050 permission = {
10191051 desc = ' Respond to permissions (accept/accept_all/deny)' ,
10201052 completions = { ' accept' , ' accept_all' , ' deny' },
@@ -1039,6 +1071,7 @@ M.slash_commands_map = {
10391071 [' /agent' ] = { fn = M .select_agent , desc = ' Select agent mode' },
10401072 [' /agents_init' ] = { fn = M .initialize , desc = ' Initialize AGENTS.md session' },
10411073 [' /child-sessions' ] = { fn = M .select_child_session , desc = ' Select child session' },
1074+ [' /commands' ] = { fn = M .commands_list , desc = ' Show user-defined commands' },
10421075 [' /compact' ] = { fn = M .compact_session , desc = ' Compact current session' },
10431076 [' /mcp' ] = { fn = M .mcp , desc = ' Show MCP server configuration' },
10441077 [' /models' ] = { fn = M .configure_provider , desc = ' Switch provider/model' },
0 commit comments