commands

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package commands provides slash command loading and execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// Name is the unique identifier for the command (used with /name)
	Name string `yaml:"name"`
	// Description explains what the command does
	Description string `yaml:"description"`
	// Args maps argument names to their descriptions for template expansion
	Args map[string]string `yaml:"args"`

	// Content is the markdown template body after frontmatter
	Content string `yaml:"-"`

	// FilePath is the absolute path to the command file
	FilePath string `yaml:"-"`
	// Source indicates where the command was loaded from: "user", "project", or "builtin"
	Source string `yaml:"-"`
}

Command represents a slash command with metadata and template content

func Parse

func Parse(path string) (*Command, error)

Parse reads and parses a command file from disk

func ParseBytes

func ParseBytes(path string, data []byte) (*Command, error)

ParseBytes parses command data from bytes

func (*Command) ArgNames

func (c *Command) ArgNames() []string

ArgNames returns the names of expected arguments

func (*Command) Expand

func (c *Command) Expand(args map[string]interface{}) (string, error)

Expand expands the command template with provided arguments

func (*Command) HasArgs

func (c *Command) HasArgs() bool

HasArgs returns true if the command expects arguments

func (*Command) String

func (c *Command) String() string

String returns a formatted representation for display

func (*Command) UsageString

func (c *Command) UsageString() string

UsageString returns a formatted usage string for the command

type Loader

type Loader struct {
	UserDir     string   // User-global commands directory (~/.hex/commands/)
	ProjectDir  string   // Project-local commands directory (.hex/commands/)
	BuiltinDir  string   // Built-in commands directory (embedded or distributed)
	PluginPaths []string // Additional command paths from plugins
}

Loader discovers and loads commands from multiple directories

func NewLoader

func NewLoader() *Loader

NewLoader creates a loader with default directories

func (*Loader) LoadAll

func (l *Loader) LoadAll() ([]*Command, error)

LoadAll discovers and loads all commands from all directories Later directories override earlier ones if command names conflict

func (*Loader) LoadByName

func (l *Loader) LoadByName(name string) (*Command, error)

LoadByName loads a specific command by name from any directory

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry stores loaded commands and provides thread-safe access

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty command registry

func (*Registry) All

func (r *Registry) All() []*Command

All returns all registered commands, sorted by name

func (*Registry) Clear

func (r *Registry) Clear()

Clear removes all commands from the registry

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of registered commands

func (*Registry) Get

func (r *Registry) Get(name string) (*Command, error)

Get retrieves a command by name

func (*Registry) Has

func (r *Registry) Has(name string) bool

Has checks if a command exists

func (*Registry) List

func (r *Registry) List() []string

List returns all registered command names, sorted alphabetically

func (*Registry) Register

func (r *Registry) Register(cmd *Command) error

Register adds a command to the registry

func (*Registry) RegisterAll

func (r *Registry) RegisterAll(commands []*Command) error

RegisterAll adds multiple commands to the registry

func (*Registry) Remove

func (r *Registry) Remove(name string) bool

Remove removes a command by name

type SlashCommandTool

type SlashCommandTool struct {
	// contains filtered or unexported fields
}

SlashCommandTool allows Claude to execute slash commands

func NewSlashCommandTool

func NewSlashCommandTool(registry *Registry) *SlashCommandTool

NewSlashCommandTool creates a new slash command tool with the given registry

func (*SlashCommandTool) Description

func (t *SlashCommandTool) Description() string

Description returns the tool description

func (*SlashCommandTool) Execute

func (t *SlashCommandTool) Execute(_ context.Context, params map[string]interface{}) (*tools.Result, error)

Execute expands and returns a slash command's content

func (*SlashCommandTool) Name

func (t *SlashCommandTool) Name() string

Name returns the tool name

func (*SlashCommandTool) RequiresApproval

func (t *SlashCommandTool) RequiresApproval(_ map[string]interface{}) bool

RequiresApproval returns false - slash commands are safe to execute

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL