commands

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 42 Imported by: 0

Documentation

Overview

Package commands 提供可扩展的 slash 命令处理

Package commands 示例:如何扩展 slash 命令系统

Index

Constants

View Source
const SpecialMarker = "__MENU_SELECT__"

SpecialMarker 是用于触发菜单选择的特殊标记

Variables

View Source
var LogsCmd = &cobra.Command{
	Use:   "logs",
	Short: "View goclaw logs",
	Long:  `View and follow goclaw application logs with color formatting and filtering.`,
	Run:   runLogs,
}

LogsCmd 日志查看命令

View Source
var MemoryCmd = &cobra.Command{
	Use:   "memory",
	Short: "Manage goclaw memory",
	Long:  `View status, index, and search memory stores. Supports builtin and QMD backends.`,
}

MemoryCmd 记忆管理命令

Functions

func BrowserCommand

func BrowserCommand() *cobra.Command

BrowserCommand returns the browser cobra command

func ChannelsCommand

func ChannelsCommand() *cobra.Command

ChannelsCommand returns the channels command

func GatewayCommand

func GatewayCommand() *cobra.Command

GatewayCommand returns the gateway command

func HealthCommand

func HealthCommand() *cobra.Command

HealthCommand returns the health command

func Register

func Register(registry *CommandRegistry)

Register 注册 new 命令

func StatusCommand

func StatusCommand() *cobra.Command

StatusCommand returns the status command

func TUICommand

func TUICommand() *cobra.Command

TUICommand returns the tui command

Types

type ArgSpec

type ArgSpec struct {
	Name        string
	Description string
	Type        string // "file", "directory", "enum"
	EnumValues  []string
}

ArgSpec 参数定义

type BrowserCommandRegistry

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

BrowserCommandRegistry Browser commands registry

func NewBrowserCommandRegistry

func NewBrowserCommandRegistry() *BrowserCommandRegistry

NewBrowserCommandRegistry Create browser command registry

func (*BrowserCommandRegistry) GetCommandPrompts

func (r *BrowserCommandRegistry) GetCommandPrompts() string

GetCommandPrompts Get browser command prompts for help

func (*BrowserCommandRegistry) RegisterCommands

func (r *BrowserCommandRegistry) RegisterCommands(registry *CommandRegistry)

RegisterCommands Register browser commands with the command registry

type ChannelInfo

type ChannelInfo struct {
	Name    string `json:"name"`
	Enabled bool   `json:"enabled"`
}

ChannelInfo represents information about a channel

type ChannelStatusResponse

type ChannelStatusResponse struct {
	Name    string                 `json:"name"`
	Enabled bool                   `json:"enabled"`
	Extra   map[string]interface{} `json:"extra,omitempty"`
}

ChannelStatusResponse represents the response from gateway channels.status

type Command

type Command struct {
	Name        string
	Usage       string
	Description string
	Handler     func(args []string) (string, bool) // 返回结果和是否应该退出
	ArgsSpec    []ArgSpec                          // 参数定义(用于补全)
}

Command 命令定义

type CommandRegistry

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

CommandRegistry 命令注册表

func NewCommandRegistry

func NewCommandRegistry() *CommandRegistry

NewCommandRegistry 创建命令注册表

func (*CommandRegistry) Execute

func (r *CommandRegistry) Execute(input string) (string, bool, bool)

Execute 执行命令 返回 (响应消息, 是否是命令, 是否应该退出)

func (*CommandRegistry) GetCommandListAsText

func (r *CommandRegistry) GetCommandListAsText() string

GetCommandListAsText 获取命令列表文本格式 用于显示给用户

func (*CommandRegistry) GetCommandPrompt

func (r *CommandRegistry) GetCommandPrompt() string

GetCommandPrompt 获取命令提示信息

func (*CommandRegistry) GetSessionManager

func (r *CommandRegistry) GetSessionManager() *session.Manager

GetSessionManager 获取会话管理器

func (*CommandRegistry) IsMenuMode

func (r *CommandRegistry) IsMenuMode() bool

IsMenuMode 检查是否在菜单模式

func (*CommandRegistry) IsStopped

func (r *CommandRegistry) IsStopped() bool

IsStopped 检查是否被停止

func (*CommandRegistry) List

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

List 列出所有命令

func (*CommandRegistry) NewCompleter

func (r *CommandRegistry) NewCompleter() readline.AutoCompleter

NewCompleter 创建自动补全器

func (*CommandRegistry) Register

func (r *CommandRegistry) Register(cmd *Command)

Register 注册命令

func (*CommandRegistry) ResetStop

func (r *CommandRegistry) ResetStop()

ResetStop 重置停止标志

func (*CommandRegistry) SelectCommand

func (r *CommandRegistry) SelectCommand() string

SelectCommand 使用交互式菜单选择命令 返回选择的命令名,空字符串表示取消

func (*CommandRegistry) SetMenuMode

func (r *CommandRegistry) SetMenuMode(enabled bool)

SetMenuMode 设置菜单模式

func (*CommandRegistry) SetSessionManager

func (r *CommandRegistry) SetSessionManager(mgr *session.Manager)

SetSessionManager 设置会话管理器

func (*CommandRegistry) SetSkillsGetter

func (r *CommandRegistry) SetSkillsGetter(getter func() ([]*SkillInfo, error))

SetSkillsGetter 设置技能获取函数

func (*CommandRegistry) SetTUIAgent

func (r *CommandRegistry) SetTUIAgent(agent *TUIAgent)

SetTUIAgent 设置 TUIAgent(用于从工具和技能信息获取数据)

func (*CommandRegistry) SetToolGetter

func (r *CommandRegistry) SetToolGetter(getter func() (map[string]interface{}, error))

SetToolGetter 设置工具获取函数

func (*CommandRegistry) Stop

func (r *CommandRegistry) Stop()

Stop 设置停止标志,用于中止正在运行的 agent

func (*CommandRegistry) Unregister

func (r *CommandRegistry) Unregister(name string)

Unregister 注销命令

type Completer

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

Completer 自动补全器

func (*Completer) Do

func (c *Completer) Do(line []rune, pos int) (newLine [][]rune, length int)

Do 实现 AutoCompleter 接口

type FailureTracker

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

FailureTracker 追踪工具调用失败

func NewFailureTracker

func NewFailureTracker() *FailureTracker

NewFailureTracker 创建失败追踪器

func (*FailureTracker) GetFailedToolNames

func (ft *FailureTracker) GetFailedToolNames() []string

GetFailedToolNames 获取失败的工具名称列表

func (*FailureTracker) HasConsecutiveFailures

func (ft *FailureTracker) HasConsecutiveFailures(threshold int) bool

HasConsecutiveFailures 检查是否有连续失败

func (*FailureTracker) RecordFailure

func (ft *FailureTracker) RecordFailure(toolName string)

RecordFailure 记录工具失败

func (*FailureTracker) RecordSuccess

func (ft *FailureTracker) RecordSuccess(toolName string)

RecordSuccess 记录工具成功

type GatewayStatus

type GatewayStatus struct {
	Online    bool   `json:"online"`
	URL       string `json:"url,omitempty"`
	Status    string `json:"status,omitempty"`
	Version   string `json:"version,omitempty"`
	Timestamp int64  `json:"timestamp,omitempty"`
}

GatewayStatus represents gateway status information

type LogEntry

type LogEntry struct {
	Time    string                 `json:"time"`
	Level   string                 `json:"level"`
	Message string                 `json:"msg"`
	Fields  map[string]interface{} `json:"fields,omitempty"`
}

LogEntry represents a structured log entry

type MissingDepsInfo

type MissingDepsInfo struct {
	Bins       []string `json:"bins,omitempty"`
	AnyBins    []string `json:"any_bins,omitempty"`
	Env        []string `json:"env,omitempty"`
	PythonPkgs []string `json:"python_pkgs,omitempty"`
	NodePkgs   []string `json:"node_pkgs,omitempty"`
}

MissingDepsInfo 缺失依赖信息

type SessionStatus

type SessionStatus struct {
	Key           string    `json:"key"`
	MessageCount  int       `json:"message_count"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
	Size          int64     `json:"size_bytes,omitempty"`
	HasMetadata   bool      `json:"has_metadata,omitempty"`
	LastMessageAt time.Time `json:"last_message_at,omitempty"`
}

SessionStatus represents session status information

type SkillInfo

type SkillInfo struct {
	Name        string           `json:"name"`
	Description string           `json:"description"`
	Version     string           `json:"version"`
	Author      string           `json:"author"`
	Homepage    string           `json:"homepage"`
	Always      bool             `json:"always"`
	Emoji       string           `json:"emoji"`
	MissingDeps *MissingDepsInfo `json:"missing_deps,omitempty"`
}

SkillInfo 技能信息

type SystemStatus

type SystemStatus struct {
	Gateway      GatewayStatus   `json:"gateway"`
	Sessions     []SessionStatus `json:"sessions"`
	SessionDir   string          `json:"session_dir"`
	TotalSize    int64           `json:"total_size_bytes"`
	SessionCount int             `json:"session_count"`
}

SystemStatus represents overall system status

type TUIAgent

type TUIAgent struct {
	*agent.Agent
	// contains filtered or unexported fields
}

TUIAgent wraps Agent for TUI with additional functionality

func NewTUIAgent

func NewTUIAgent(
	messageBus *bus.MessageBus,
	sessionMgr *session.Manager,
	provider providers.Provider,
	contextBuilder *agent.ContextBuilder,
	workspace string,
	maxIterations int,
	skillsLoader *agent.SkillsLoader,
	cronService *cron.Service,
) (*TUIAgent, error)

NewTUIAgent creates a new TUI agent

Jump to

Keyboard shortcuts

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