commands

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateCommand = errors.New("commands: duplicate registration")
	ErrUnknownCommand   = errors.New("commands: unknown command")
)
View Source
var (
	ErrNoCommand      = errors.New("commands: no slash command found")
	ErrInvalidCommand = errors.New("commands: invalid command")
)

Functions

func SetCommandFileOpsForTest

func SetCommandFileOpsForTest(
	read func(string) ([]byte, error),
	open func(string) (*os.File, error),
	stat func(string) (fs.FileInfo, error),
) (restore func())

SetCommandFileOpsForTest swaps filesystem helpers; intended for white-box tests only.

Types

type CommandFile

type CommandFile struct {
	Name     string
	Path     string
	Metadata CommandMetadata
}

CommandFile captures an on-disk command definition.

type CommandMetadata

type CommandMetadata struct {
	Name                   string `yaml:"name"`
	Description            string `yaml:"description"`
	AllowedTools           string `yaml:"allowed-tools"`
	ArgumentHint           string `yaml:"argument-hint"`
	Model                  string `yaml:"model"`
	DisableModelInvocation bool   `yaml:"disable-model-invocation"`
}

CommandMetadata describes optional YAML frontmatter fields.

type CommandRegistration

type CommandRegistration struct {
	Definition Definition
	Handler    Handler
}

CommandRegistration wires a definition to its handler.

func LoadFromFS

func LoadFromFS(opts LoaderOptions) ([]CommandRegistration, []error)

LoadFromFS loads slash commands from the filesystem. It never returns a nil registrations slice. Errors are aggregated so a single bad file doesn't prevent others from loading.

type Definition

type Definition struct {
	Name        string
	Description string
	Priority    int
	MutexKey    string
}

Definition describes a slash command handler.

func (Definition) Validate

func (d Definition) Validate() error

Validate ensures the definition is sound.

type Executor

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

Executor routes parsed slash commands to registered handlers.

func NewExecutor

func NewExecutor() *Executor

NewExecutor creates a new command executor.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, invocations []Invocation) ([]Result, error)

Execute runs already parsed invocations.

func (*Executor) List

func (e *Executor) List() []Definition

List returns registered command definitions sorted by priority + name.

func (*Executor) Register

func (e *Executor) Register(def Definition, handler Handler) error

Register adds a command definition + handler pair.

func (*Executor) Run

func (e *Executor) Run(ctx context.Context, text string) ([]Result, error)

Run parses text and executes slash commands sequentially.

type Handler

type Handler interface {
	Handle(context.Context, Invocation) (Result, error)
}

Handler executes a parsed invocation.

type HandlerFunc

type HandlerFunc func(context.Context, Invocation) (Result, error)

HandlerFunc turns a function into a Handler.

func (HandlerFunc) Handle

func (fn HandlerFunc) Handle(ctx context.Context, inv Invocation) (Result, error)

Handle implements Handler.

type Invocation

type Invocation struct {
	Name     string
	Args     []string
	Flags    map[string]string
	Raw      string
	Position int
}

Invocation represents a parsed slash command invocation.

func Parse

func Parse(input string) ([]Invocation, error)

Parse extracts slash commands from the input text. Each line beginning with '/' is treated as a command. Quoted arguments and --flag syntax are supported.

func (Invocation) Flag

func (i Invocation) Flag(name string) (string, bool)

Flag retrieves a flag value.

type LoaderOptions

type LoaderOptions struct {
	ProjectRoot string
	// Deprecated: user-level scanning has been removed; this field is ignored.
	UserHome string
	// Deprecated: user-level scanning has been removed; this flag is ignored.
	EnableUser bool
	FS         *config.FS
}

LoaderOptions controls how commands are discovered from the filesystem.

type Result

type Result struct {
	Command  string
	Output   any
	Metadata map[string]any
	Error    string
}

Result captures handler output.

Jump to

Keyboard shortcuts

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