slash

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name         string
	Description  string
	ReadOnlySafe bool // true = 只读浏览模式下允许执行(纯查询/展示)
	Handler      func(args []string, ctx *Context) Result
}

Command 斜杠命令定义

type Context

type Context struct {
	// 模型/配置信息
	Model      string
	Provider   string
	Version    string
	PermMode   string
	Currency   string
	MaxContext int

	// token/费用信息
	InputTokens  int
	OutputTokens int
	TotalTokens  int
	CostString   string
	CostUSD      float64

	// 会话信息
	SessionID    string
	SessionTurns int
	WorkDir      string

	// 缓存信息
	CacheCreationTokens int
	CacheReadTokens     int

	// 回调函数(需要外部行为的命令)
	OnClear       func()                            // /clear
	OnCompact     func() string                     // /compact
	OnModelSwitch func(string)                      // /model <name>
	OnExport      func() string                     // /export
	OnResume      func() ([]ResumeEntryData, error) // /resume
	OnLogin       func() string                     // /login
	OnLogout      func() string                     // /logout
	OnMCPList     func() string                     // /mcp
	OnSkillsList  func() string                     // /skills
	OnPluginsList func() string                     // /plugins
	OnHooksList   func() string                     // /hooks
	OnThemeSwitch func(string) string               // /theme <dark|light>
}

Context 命令执行上下文(由 TUI/Agent 注入)

type Handler

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

Handler 斜杠命令路由器

func NewHandler

func NewHandler() *Handler

NewHandler 创建命令路由器

func (*Handler) AllCommands

func (h *Handler) AllCommands() []*Command

AllCommands 返回所有命令(按名称排序)

func (*Handler) CommandNames

func (h *Handler) CommandNames() []string

CommandNames 返回所有命令名称列表(用于 TUI 补全)

func (*Handler) Handle

func (h *Handler) Handle(input string, ctx *Context) (Result, bool)

Handle 处理斜杠命令

func (*Handler) IsReadOnlySafe

func (h *Handler) IsReadOnlySafe(input string) bool

IsReadOnlySafe 检查给定的 slash 输入在只读模式下是否允许执行

type Result

type Result struct {
	Type    ResultType
	Content string
}

Result 斜杠命令执行结果

type ResultType

type ResultType string

ResultType 命令结果类型

const (
	ResultNotice   ResultType = "notice"   // 短提示(临时通知,~10 秒消失)
	ResultPanel    ResultType = "panel"    // 长文本(可滚动面板,Esc 关闭)
	ResultSelector ResultType = "selector" // 打开选择器(如 /resume)
	ResultPrompt   ResultType = "prompt"   // 发送预设 prompt 给 Agent
	ResultAction   ResultType = "action"   // 执行内部动作(如退出、清屏)
)

type ResumeEntryData

type ResumeEntryData struct {
	ID         string
	Model      string
	Provider   string
	BaseURL    string
	AuthSource string
	Turns      int
	Cost       string
	Mode       string // "continue" / "readonly" / "blocked"
	ModeReason string
}

ResumeEntryData 历史会话条目(slash 层传递数据用)

Jump to

Keyboard shortcuts

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