@@ -388,7 +388,7 @@ function M.select_agent()
388388end
389389
390390function M .switch_mode ()
391- local modes = require (' opencode.config_file' ).get_opencode_agents ()
391+ local modes = require (' opencode.config_file' ).get_opencode_agents () --[[ @as string[] ]]
392392
393393 local current_index = util .index_of (modes , state .current_mode )
394394
@@ -512,6 +512,33 @@ function M.mcp()
512512 ui .render_lines (msg )
513513end
514514
515+ function M .commands_list ()
516+ local info = require (' opencode.config_file' )
517+ local commands = info .get_user_commands ()
518+ if not commands then
519+ vim .notify (' No user commands found. Please check your opencode config file.' , vim .log .levels .WARN )
520+ return
521+ end
522+
523+ state .display_route = ' /commands'
524+ M .open_input ()
525+
526+ local msg = M .with_header ({
527+ ' ### Available User Commands' ,
528+ ' ' ,
529+ ' | Name | Description |' ,
530+ ' |------|-------------|' ,
531+ })
532+
533+ for name , def in pairs (commands ) do
534+ local desc = def .description or ' '
535+ table.insert (msg , string.format (' | %s | %s |' , name , desc ))
536+ end
537+
538+ table.insert (msg , ' ' )
539+ ui .render_lines (msg )
540+ end
541+
515542--- Runs a user-defined command by name.
516543--- @param name string The name of the user command to run.
517544--- @param args ? string[] Additional arguments to pass to the command.
@@ -1008,6 +1035,11 @@ M.commands = {
10081035 fn = M .mcp ,
10091036 },
10101037
1038+ commands_list = {
1039+ desc = ' Show user-defined commands' ,
1040+ fn = M .commands_list ,
1041+ },
1042+
10111043 permission = {
10121044 desc = ' Respond to permissions (accept/accept_all/deny)' ,
10131045 completions = { ' accept' , ' accept_all' , ' deny' },
@@ -1032,6 +1064,7 @@ M.slash_commands_map = {
10321064 [' /agent' ] = { fn = M .select_agent , desc = ' Select agent mode' },
10331065 [' /agents_init' ] = { fn = M .initialize , desc = ' Initialize AGENTS.md session' },
10341066 [' /child-sessions' ] = { fn = M .select_child_session , desc = ' Select child session' },
1067+ [' /commands' ] = { fn = M .commands_list , desc = ' Show user-defined commands' },
10351068 [' /compact' ] = { fn = M .compact_session , desc = ' Compact current session' },
10361069 [' /mcp' ] = { fn = M .mcp , desc = ' Show MCP server configuration' },
10371070 [' /models' ] = { fn = M .configure_provider , desc = ' Switch provider/model' },
0 commit comments