commands

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 7 Imported by: 0

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

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) IsFrozen

func (r *Registry) IsFrozen() bool

IsFrozen reports whether the registry is frozen.

func (*Registry) List

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

List returns command names in lexical order.

func (*Registry) Register

func (r *Registry) Register(def *CommandDefinition) error

Register adds a command or returns ErrFrozen after freezing.

Jump to

Keyboard shortcuts

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