Documentation
¶
Overview ¶
Package commands 提供可扩展的 slash 命令处理
Package commands 示例:如何扩展 slash 命令系统
Index ¶
- Constants
- Variables
- func BrowserCommand() *cobra.Command
- func ChannelsCommand() *cobra.Command
- func GatewayCommand() *cobra.Command
- func HealthCommand() *cobra.Command
- func Register(registry *CommandRegistry)
- func StatusCommand() *cobra.Command
- func TUICommand() *cobra.Command
- type ArgSpec
- type BrowserCommandRegistry
- type ChannelInfo
- type ChannelStatusResponse
- type Command
- type CommandRegistry
- func (r *CommandRegistry) Execute(input string) (string, bool, bool)
- func (r *CommandRegistry) GetCommandListAsText() string
- func (r *CommandRegistry) GetCommandPrompt() string
- func (r *CommandRegistry) GetSessionManager() *session.Manager
- func (r *CommandRegistry) IsMenuMode() bool
- func (r *CommandRegistry) IsStopped() bool
- func (r *CommandRegistry) List() []*Command
- func (r *CommandRegistry) NewCompleter() readline.AutoCompleter
- func (r *CommandRegistry) Register(cmd *Command)
- func (r *CommandRegistry) ResetStop()
- func (r *CommandRegistry) SelectCommand() string
- func (r *CommandRegistry) SetMenuMode(enabled bool)
- func (r *CommandRegistry) SetSessionManager(mgr *session.Manager)
- func (r *CommandRegistry) SetSkillsGetter(getter func() ([]*SkillInfo, error))
- func (r *CommandRegistry) SetTUIAgent(agent *TUIAgent)
- func (r *CommandRegistry) SetToolGetter(getter func() (map[string]interface{}, error))
- func (r *CommandRegistry) Stop()
- func (r *CommandRegistry) Unregister(name string)
- type Completer
- type FailureTracker
- type GatewayStatus
- type LogEntry
- type MissingDepsInfo
- type SessionStatus
- type SkillInfo
- type SystemStatus
- type TUIAgent
Constants ¶
const SpecialMarker = "__MENU_SELECT__"
SpecialMarker 是用于触发菜单选择的特殊标记
Variables ¶
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 日志查看命令
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 ¶
BrowserCommand returns the browser cobra command
func ChannelsCommand ¶
ChannelsCommand returns the channels command
func GatewayCommand ¶
GatewayCommand returns the gateway 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 ¶
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 (*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) NewCompleter ¶
func (r *CommandRegistry) NewCompleter() readline.AutoCompleter
NewCompleter 创建自动补全器
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) Unregister ¶
func (r *CommandRegistry) Unregister(name string)
Unregister 注销命令
type Completer ¶
type Completer struct {
// contains filtered or unexported fields
}
Completer 自动补全器
type FailureTracker ¶
type FailureTracker struct {
// contains filtered or unexported fields
}
FailureTracker 追踪工具调用失败
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 ¶
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