commands

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package commands 提供 slash 命令(Commands)系统。

对齐上游:packages/interaction/commands

设计要点:

  • CommandDefinition 描述一个 slash 命令(如 /plan off);
  • 命令入口通过 ctx.commands register/list/execute 路由;
  • 执行 `#command/run` 与 `#command/done` 事件(而非当成普通 user/message);
  • 例如 `/plan off` 直接写入 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 命令名(不含 "/" 前缀,如 "plan")。
	Name string
	// Description 命令描述(帮助展示)。
	Description string
	// Handler 执行函数。
	Handler CommandHandler
}

CommandDefinition 是一个 slash 命令定义。

type CommandHandler

type CommandHandler func(ctx context.Context, args string, sl *session.SessionLog) (output string, err error)

CommandHandler 是命令处理函数:接收参数字符串与事件日志,写事件并返回输出。

type ErrUnknownCommand

type ErrUnknownCommand string

ErrUnknownCommand 表示命令不存在。

func (ErrUnknownCommand) Error

func (e ErrUnknownCommand) Error() string

type Registry

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

Registry 是命令注册中心(H07:基于可冻结共享注册表,Freeze 后读路径无锁)。

func NewRegistry

func NewRegistry() *Registry

NewRegistry 创建命令注册中心,并注册内置 plan/goal 命令。

func (*Registry) Dispatch

func (r *Registry) Dispatch(ctx context.Context, raw string, sl *session.SessionLog) (string, error)

Dispatch 解析 "/name args" 并执行对应命令(不存在返回 ErrUnknownCommand)。

func (*Registry) Freeze

func (r *Registry) Freeze()

Freeze 冻结命令注册表(不可逆):此后读路径无锁走只读快照,写返回 ErrFrozen。

func (*Registry) Get

func (r *Registry) Get(name string) (*CommandDefinition, bool)

Get 按名取命令(冻结后无锁读快照)。

func (*Registry) IsFrozen

func (r *Registry) IsFrozen() bool

IsFrozen 返回注册表是否已冻结。

func (*Registry) List

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

List 返回全部命令名(字典序)。

func (*Registry) Register

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

Register 注册一个命令;冻结后返回 ErrFrozen。

Jump to

Keyboard shortcuts

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