commands

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasCommandPrefix

func HasCommandPrefix(input string) bool

HasCommandPrefix returns true if the input starts with a recognized command prefix (e.g. "/" or "!").

Types

type Definition

type Definition struct {
	Name        string
	Description string
	Usage       string // for simple commands; ignored when SubCommands is set
	Aliases     []string
	SubCommands []SubCommand // optional; when set, Executor routes to sub-command handlers
	Handler     Handler      // for simple commands without sub-commands
}

Definition is the single-source metadata and behavior contract for a slash command.

Design notes (phase 1):

  • Every channel reads command shape from this type instead of keeping local copies.
  • Visibility is global: all definitions are considered available to all channels.
  • Platform menu registration (for example Telegram BotCommand) also derives from this same definition so UI labels and runtime behavior stay aligned.

func BuiltinDefinitions

func BuiltinDefinitions() []Definition

BuiltinDefinitions returns all built-in command definitions. Each command group is defined in its own cmd_*.go file. Definitions are stateless — runtime dependencies are provided via the Runtime parameter passed to handlers at execution time.

func (Definition) EffectiveUsage

func (d Definition) EffectiveUsage() string

EffectiveUsage returns the usage string. When SubCommands are present, it is auto-generated from sub-command names so metadata and behavior cannot drift.

type ExecuteResult

type ExecuteResult struct {
	Outcome Outcome
	Command string
	Err     error
}

type Executor

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

func NewExecutor

func NewExecutor(reg *Registry, rt *Runtime) *Executor

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, req Request) ExecuteResult

Execute implements a two-state command decision: 1) handled: execute command immediately; 2) passthrough: not a command or intentionally deferred to agent logic.

type Handler

type Handler func(ctx context.Context, req Request, rt *Runtime) error

type Outcome

type Outcome int
const (
	// OutcomePassthrough means this input should continue through normal agent flow.
	OutcomePassthrough Outcome = iota
	// OutcomeHandled means a command handler executed (with or without handler error).
	OutcomeHandled
)

type Registry

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

func NewRegistry

func NewRegistry(defs []Definition) *Registry

NewRegistry stores the canonical command set used by both dispatch and optional platform registration adapters.

func (*Registry) Definitions

func (r *Registry) Definitions() []Definition

Definitions returns all registered command definitions. Command availability is global and no longer channel-scoped.

func (*Registry) Lookup

func (r *Registry) Lookup(name string) (Definition, bool)

Lookup returns a command definition by normalized command name or alias.

type Request

type Request struct {
	Channel  string
	ChatID   string
	SenderID string
	Text     string
	Reply    func(text string) error
}

type Runtime

type Runtime struct {
	Config             *config.Config
	GetModelInfo       func() (name, provider string)
	ListAgentIDs       func() []string
	ListDefinitions    func() []Definition
	GetEnabledChannels func() []string
	SwitchModel        func(value string) (oldModel string, err error)
	SwitchChannel      func(value string) error
	ClearHistory       func() error
}

Runtime provides runtime dependencies to command handlers. It is constructed per-request by the agent loop so that per-request state (like session scope) can coexist with long-lived callbacks (like GetModelInfo).

type SubCommand

type SubCommand struct {
	Name        string
	Description string
	ArgsUsage   string // optional, e.g. "<session-id>"
	Handler     Handler
}

SubCommand defines a single sub-command within a parent command.

Jump to

Keyboard shortcuts

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