Documentation
¶
Overview ¶
Package commands implements slash commands, matching interaction/commands. Definitions describe commands such as /plan off; ctx.commands registers, lists, and dispatches them. Execution emits command/run and command/done rather than ordinary user messages. For example, /plan off directly emits plan/mode(off).
Index ¶
- type CommandDefinition
- type CommandHandler
- type ErrUnknownCommand
- type Registry
- func (r *Registry) Dispatch(ctx context.Context, raw string, sl *session.SessionLog) (string, error)
- func (r *Registry) Freeze()
- func (r *Registry) Get(name string) (*CommandDefinition, bool)
- func (r *Registry) IsFrozen() bool
- func (r *Registry) List() []string
- func (r *Registry) Register(def *CommandDefinition) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandDefinition ¶
type CommandDefinition struct {
// Name excludes the slash prefix, for example plan.
Name string
// Description is shown in help.
Description string
// Handler executes the command.
Handler CommandHandler
}
CommandDefinition defines a slash command.
type CommandHandler ¶
type CommandHandler func(ctx context.Context, args string, sl *session.SessionLog) (output string, err error)
CommandHandler receives arguments and a log, writes events, and returns output.
type ErrUnknownCommand ¶
type ErrUnknownCommand string
ErrUnknownCommand indicates an unregistered command.
func (ErrUnknownCommand) Error ¶
func (e ErrUnknownCommand) Error() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry uses a freezable shared registry with immutable snapshots after Freeze (H07).
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a registry with the built-in plan and goal commands.
func (*Registry) Dispatch ¶
func (r *Registry) Dispatch(ctx context.Context, raw string, sl *session.SessionLog) (string, error)
Dispatch parses /name args and runs the command, or returns ErrUnknownCommand.
func (*Registry) Freeze ¶
func (r *Registry) Freeze()
Freeze irreversibly enables immutable snapshot reads and rejects writes with ErrFrozen.
func (*Registry) Get ¶
func (r *Registry) Get(name string) (*CommandDefinition, bool)
Get looks up a command, using immutable snapshots after freezing.
func (*Registry) Register ¶
func (r *Registry) Register(def *CommandDefinition) error
Register adds a command or returns ErrFrozen after freezing.