Help us shape the future of Go! Take the 2026 Go Developer Survey

command

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package command 定义了 Golem 斜杠命令(Slash Commands)的接口、注册与分发逻辑。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {
	// Name 返回触发该命令的名称(不含前导斜杠,如 "new")。
	Name() string
	// Description 返回该命令的简短描述。
	Description() string
	// Execute 执行命令逻辑。args 是命令名称后紧跟的参数文本。
	Execute(ctx context.Context, args string, env Env) Result
}

Command 是所有斜杠命令必须实现的接口。

type CronCommand

type CronCommand struct{}

CronCommand 实现 /cron — 管理定时任务。 子命令: list, remove <id>, enable <id>, disable <id>, run <id>

func (*CronCommand) Description

func (c *CronCommand) Description() string

func (*CronCommand) Execute

func (c *CronCommand) Execute(ctx context.Context, args string, env Env) Result

func (*CronCommand) Name

func (c *CronCommand) Name() string

type Env

type Env struct {
	Channel       string                  // 消息来源通道
	ChatID        string                  // 聊天 ID
	SenderID      string                  // 发送者 ID
	SessionKey    string                  // 唯一的会话标识符
	Sessions      *session.Manager        // 会话管理器,用于操作聊天历史
	WorkspacePath string                  // 工作区根路径
	Config        *config.Config          // 全局配置实例
	Metrics       *metrics.RuntimeMetrics // 运行时指标记录器
	ListCommands  func() []Command        // 用于 /help 获取所有可用命令的回调函数
}

Env 携带斜杠命令执行时的上下文环境信息。

type HelpCommand

type HelpCommand struct{}

HelpCommand 实现 /help 命令 — 用于列出当前所有已注册且可用的斜杠命令。

func (*HelpCommand) Description

func (c *HelpCommand) Description() string

Description 返回命令描述。

func (*HelpCommand) Execute

func (c *HelpCommand) Execute(_ context.Context, _ string, env Env) Result

Execute 执行列出命令的逻辑。

func (*HelpCommand) Name

func (c *HelpCommand) Name() string

Name 返回命令名称。

type MemoryCommand

type MemoryCommand struct{}

MemoryCommand 实现 /memory 命令 — 用于读取长期记忆 (MEMORY.md) 或查询日记条目。 使用方式:

/memory [read] - 读取长期记忆内容
/memory diary [date|recent] - 读取指定日期或最近的日记分录

func (*MemoryCommand) Description

func (c *MemoryCommand) Description() string

Description 返回命令描述。

func (*MemoryCommand) Execute

func (c *MemoryCommand) Execute(_ context.Context, args string, env Env) Result

Execute 执行记忆查询逻辑。

func (*MemoryCommand) Name

func (c *MemoryCommand) Name() string

Name 返回命令名称。

type NewSessionCommand

type NewSessionCommand struct{}

NewSessionCommand 实现 /new 命令 — 用于重置当前会话,清除历史上下文。

func (*NewSessionCommand) Description

func (c *NewSessionCommand) Description() string

Description 返回命令描述。

func (*NewSessionCommand) Execute

func (c *NewSessionCommand) Execute(_ context.Context, _ string, env Env) Result

Execute 执行重置会话逻辑。

func (*NewSessionCommand) Name

func (c *NewSessionCommand) Name() string

Name 返回命令名称。

type Registry

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

Registry 负责存储所有已注册的斜杠命令并进行匹配分发。

func NewRegistry

func NewRegistry() *Registry

NewRegistry 创建并返回一个空的命令注册表。

func (*Registry) List

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

List 返回按名称字母顺序排序的所有已注册命令列表。

func (*Registry) Lookup

func (r *Registry) Lookup(content string) (Command, string, bool)

Lookup 解析用户输入。如果输入以 "/" 开头且匹配已注册命令,则返回该命令及其参数。

func (*Registry) Register

func (r *Registry) Register(cmd Command)

Register 向注册表中添加一个命令。如果存在同名命令,将触发 panic。

type Result

type Result struct {
	Content string // 返回给用户的文本消息
}

Result 封装了斜杠命令执行后的输出内容。

type SkillsCommand

type SkillsCommand struct{}

SkillsCommand 实现 /skills 命令 — 用于查看已安装技能及其详细信息。 使用方式:

/skills [list] - 列出所有已发现的技能
/skills show <name> - 显示指定技能的完整 Markdown 内容

func (*SkillsCommand) Description

func (c *SkillsCommand) Description() string

Description 返回命令描述。

func (*SkillsCommand) Execute

func (c *SkillsCommand) Execute(_ context.Context, args string, env Env) Result

Execute 执行技能管理逻辑。

func (*SkillsCommand) Name

func (c *SkillsCommand) Name() string

Name 返回命令名称。

type StatusCommand

type StatusCommand struct{}

StatusCommand 实现 /status 命令 — 用于显示 Agent 当前的运行时状态、配置概览及性能指标。

func (*StatusCommand) Description

func (c *StatusCommand) Description() string

Description 返回命令描述。

func (*StatusCommand) Execute

func (c *StatusCommand) Execute(_ context.Context, _ string, env Env) Result

Execute 执行显示状态摘要的逻辑。

func (*StatusCommand) Name

func (c *StatusCommand) Name() string

Name 返回命令名称。

type VersionCommand

type VersionCommand struct{}

VersionCommand 实现 /version 命令 — 用于显示当前 Golem 二进制文件的版本及构建环境。

func (*VersionCommand) Description

func (c *VersionCommand) Description() string

Description 返回命令描述。

func (*VersionCommand) Execute

func (c *VersionCommand) Execute(_ context.Context, _ string, _ Env) Result

Execute 执行显示版本信息的逻辑。

func (*VersionCommand) Name

func (c *VersionCommand) Name() string

Name 返回命令名称。

Jump to

Keyboard shortcuts

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