Skip to content

Conversation

@shuv1337
Copy link
Collaborator

@shuv1337 shuv1337 commented Dec 27, 2025

Greptile Summary

Added plugin command system that enables plugins to register custom slash commands accessible via /command in TUI/web.

Key changes:

  • Commands now have a type field ("template" or "plugin") to distinguish between template-based and plugin-provided commands
  • Plugin commands support aliases for alternate names, and sessionOnly flag to restrict commands to existing sessions
  • The Command.get() function now resolves aliases by searching through all commands
  • Plugin command execution happens directly via the plugin's execute function, with error handling and event publishing
  • Command.Event.Executed is only emitted when a plugin command creates a new message (checked by comparing message IDs before/after execution)
  • Added comprehensive test coverage for plugin commands including alias resolution, execution, error handling, and session-only guards

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-structured with proper error handling, comprehensive test coverage, and clear separation of concerns. The changes follow existing code patterns and include appropriate guards for edge cases.
  • No files require special attention

Important Files Changed

Filename Overview
packages/opencode/src/command/index.ts Added plugin command support with type field, aliases, and sessionOnly flag - implementation looks clean
packages/opencode/src/session/prompt.ts Added plugin command execution logic with sessionOnly guard and event emission only when message created
packages/plugin/src/index.ts Added plugin.command hook interface definition with description, aliases, sessionOnly, and execute function

Sequence Diagram

sequenceDiagram
    participant User
    participant SessionPrompt
    participant Command
    participant Plugin
    participant PluginCommand
    participant Session
    participant Bus

    User->>SessionPrompt: command(input)
    SessionPrompt->>Command: get(input.command)
    Command->>Plugin: list()
    Plugin-->>Command: plugin hooks with plugin.command
    Command-->>SessionPrompt: command info (with type, aliases, sessionOnly)
    
    alt command not found
        SessionPrompt->>SessionPrompt: log warning & return
    end
    
    alt sessionOnly is true
        SessionPrompt->>Session: get(sessionID)
        alt session not found
            Session-->>SessionPrompt: throw error
            SessionPrompt->>Bus: publish(Session.Event.Error)
            SessionPrompt-->>User: throw error
        end
    end
    
    alt command.type === "plugin"
        SessionPrompt->>Session: messages(sessionID, limit=1)
        Session-->>SessionPrompt: messagesBefore
        SessionPrompt->>Plugin: client()
        Plugin-->>SessionPrompt: opencode client
        SessionPrompt->>PluginCommand: execute({sessionID, arguments, client})
        alt execution fails
            PluginCommand-->>SessionPrompt: throw error
            SessionPrompt->>Bus: publish(Session.Event.Error)
            SessionPrompt-->>User: throw error
        end
        PluginCommand-->>SessionPrompt: success
        SessionPrompt->>Session: messages(sessionID, limit=1)
        Session-->>SessionPrompt: messagesAfter
        alt new message created
            SessionPrompt->>Bus: publish(Command.Event.Executed)
            SessionPrompt-->>User: return new message
        else no new message
            SessionPrompt-->>User: return
        end
    else command.type === "template"
        SessionPrompt->>SessionPrompt: process template command
        SessionPrompt->>Bus: publish(Command.Event.Executed)
        SessionPrompt-->>User: return message
    end
Loading

@greptile-apps
Copy link

greptile-apps bot commented Dec 27, 2025

Greptile's behavior is changing!

From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

@shuv1337 shuv1337 merged commit 1ab747e into plugin-slash-commands Dec 27, 2025
3 checks passed
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