Documentation
¶
Overview ¶
Package slash provides slash command registry and dispatch for interactive commands.
Index ¶
- Variables
- type AgentState
- type Command
- type Context
- type ProviderModels
- type Registry
- func (r *Registry) ByCategory(cat string) []Command
- func (r *Registry) Categories() []string
- func (r *Registry) Handle(ctx context.Context, sctx Context, input string) (string, bool, bool, error)
- func (r *Registry) HintFor(name string) string
- func (r *Registry) Lookup(name string) (Command, bool)
- func (r *Registry) Register(cmd ...Command)
- func (r *Registry) Sorted() []Command
Constants ¶
This section is empty.
Variables ¶
var ErrUsage = errors.New("invalid argument")
ErrUsage is returned by commands to signal that usage help should be shown.
Functions ¶
This section is empty.
Types ¶
type AgentState ¶
type AgentState struct {
Name string
Mode string
ModelName string
Provider string
Think thinking.Value
Context int
Prompt string
ToolNames []string
LoadedTools []string
}
AgentState is a snapshot of the agent's current runtime state. Commands use this to read agent properties without accessing the Agent struct directly.
func (AgentState) Meta ¶
func (a AgentState) Meta(verbose bool, rbp tool.ReadBeforePolicy) session.Meta
Meta returns a session.Meta snapshot from the current agent state.
type Command ¶
type Command struct {
Name string
Aliases []string
Description string
Hints string // Argument hint text shown as ghost text in TUI (e.g. "[name]", "<file> [options]").
Category string // Grouping label for /help display (e.g. "agent", "session", "tools").
Forward bool // Forward causes the result to be sent to the LLM as a user message instead of displayed as a CommandResult.
Silent bool // Silent suppresses the pre-execution command echo in chat history.
Execute func(ctx context.Context, c Context, args ...string) (string, error)
}
Command defines a slash command.
func FromCustomCommands ¶
func FromCustomCommands(cmds config.Collection[config.CustomCommand]) []Command
FromCustomCommands converts loaded custom command configs into slash commands. Each command has Forward=true so the rendered body is sent to the LLM as a user message.
type Context ¶
type Context interface {
// Agent/mode/model switching
SwitchAgent(name, reason string) error
SwitchMode(mode string) error
SwitchModel(ctx context.Context, provider, model string) error
SetThink(t thinking.Value) error
SetSandbox(enabled bool) error
ResizeContext(size int) error
SetAuto(val bool)
ResetTokens()
// Heavy operations
Compact(ctx context.Context, force bool) error
GenerateTitle(ctx context.Context) (string, error)
ProcessInput(ctx context.Context, input string) error
Reload(ctx context.Context) error
ResumeSession(ctx context.Context, sess *session.Session) []string
// Read-only state
Status() ui.Status
DisplayHints() ui.DisplayHints
SandboxDisplay() string
AgentState() AgentState
SessionMeta() session.Meta
ResolvedModel() model.Model
// Sub-object access
ToolPolicy() *config.ToolPolicy
Cfg() config.Config
Paths() config.Paths
Runtime() *config.Runtime
Builder() *conversation.Builder
SessionManager() *session.Manager
TodoList() *todo.List
SessionStats() *stats.Stats
InjectorRegistry() *injector.Registry
MCPSessions() []*mcp.Session
RegisterMCPSession(s *mcp.Session) error
SnapshotManager() *snapshot.Manager
EventChan() chan<- ui.Event
// Lifecycle
RequestExit()
// Simple state
Verbose() bool
SetVerbose(val bool)
AutoEnabled() bool
DoneEnabled() bool
SetDone(val bool) error
MaxSteps() int
ReadBeforePolicy() tool.ReadBeforePolicy
SetReadBeforePolicy(tool.ReadBeforePolicy) error
// Template variables
TemplateVars() map[string]string
// Plugin display
PluginSummary() string
// Caching
ModelListCache() []ProviderModels
CacheModelList(v []ProviderModels)
ClearModelListCache()
}
Context is the interface that slash commands use to interact with the assistant. It exposes only the state and actions that commands actually need, decoupling the slash system from the assistant's internal structure.
type ProviderModels ¶
ProviderModels holds the result of querying a single provider for its models.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all registered slash commands.
func (*Registry) ByCategory ¶
ByCategory returns commands in the given category, sorted alphabetically by name.
func (*Registry) Categories ¶
Categories returns the ordered list of categories present in the registry. Known categories appear in categoryOrder; unknown ones sort alphabetically after.
func (*Registry) Handle ¶
func (r *Registry) Handle(ctx context.Context, sctx Context, input string) (string, bool, bool, error)
Handle processes user input. Returns (message, handled, forward, error). If input doesn't start with "/", returns ("", false, nil). When forward is true, the message should be sent to the LLM as a user message.
Handle is the single source of command echoes in the TUI. Non-Silent commands emit CommandResult{Command: input} before execution. All other CommandResult emissions should use Message/Error only.
func (*Registry) HintFor ¶
HintFor returns the hint text for a command name, resolving aliases. Returns empty string if the command is not found or has no hints.