Skip to content

Conversation

Copy link

Copilot AI commented Jul 12, 2025

This PR implements user-defined commands support in the OpenCode TUI, allowing users to extend the built-in command set through configuration. This addresses the requirement to enable user-defined commands similar to those in packages/tui/internal/commands/command.go.

What's Changed

Core Implementation

  • Extended Config struct with commands field to support user-defined commands
  • Modified LoadFromConfig() to load and merge user commands with built-in defaults
  • Fixed parseBindings() function to properly handle leader key detection with whitespace
  • Added ConfigCommand type with support for descriptions, keybindings, and triggers

Configuration Format

Users can now define custom commands in their opencode.json:

{
  "commands": {
    "my_command": {
      "description": "My custom command",
      "keybind": "<leader>x",
      "trigger": ["custom", "mycmd"]
    },
    "quick_note": {
      "description": "Take a quick note", 
      "keybind": "ctrl+shift+n",
      "trigger": ["note", "quick"]
    }
  }
}

Features Supported

  • Custom descriptions for user commands
  • Flexible keybindings including leader key combinations and multi-key bindings
  • Text triggers for command activation (e.g., /custom, /note)
  • Integration with command completions and fuzzy search
  • Coexistence with built-in commands without conflicts

Integration Points

  • User commands appear in command completions when typing /
  • Keybindings work seamlessly with the existing input system
  • Commands are included in help and command listings
  • Fuzzy search finds user commands alongside built-in ones

Testing

Added comprehensive test coverage with 9 test cases:

  • Basic user command loading and configuration
  • Complex keybinding scenarios with leader keys
  • Integration with command registry and sorting
  • Completions provider integration
  • Conflict prevention between user and built-in commands
  • Empty configuration handling
  • Custom keybinding application

Documentation

  • Created USER_DEFINED_COMMANDS.md with detailed usage instructions
  • Provided example configuration file demonstrating all features
  • Documented keybinding format and configuration options

Backward Compatibility

✅ Fully backward compatible - existing configurations continue to work unchanged
✅ All existing commands and keybindings remain functional
✅ No breaking changes to the command system API

Example Usage

After adding commands to config, users can:

  1. Type /custom to trigger the command via text
  2. Press Ctrl+X x (leader + x) to trigger via keybinding
  3. See commands in completions when typing / and searching
  4. View in help alongside built-in commands

This provides a solid foundation for future extensibility where users will be able to define custom behavior for their commands.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] enable user defined commands, similar to those in packages/tui/internal/commands/command.go Enable user-defined commands in TUI configuration Jul 12, 2025
Copilot AI requested a review from jasonpaulso July 12, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants