slash

package
v0.0.0-beta Latest Latest
Warning

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

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

Documentation

Overview

Package slash provides slash command registry and dispatch for interactive commands.

Index

Constants

This section is empty.

Variables

View Source
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.

func (Command) Usage

func (c Command) Usage() string

Usage returns the full usage string (e.g. "/mode [name]").

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

type ProviderModels struct {
	Name   string
	Models model.Models
	Err    error
}

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 New

func New(cmd ...Command) *Registry

New creates a new slash command registry with built-in /help.

func (*Registry) ByCategory

func (r *Registry) ByCategory(cat string) []Command

ByCategory returns commands in the given category, sorted alphabetically by name.

func (*Registry) Categories

func (r *Registry) Categories() []string

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

func (r *Registry) HintFor(name string) string

HintFor returns the hint text for a command name, resolving aliases. Returns empty string if the command is not found or has no hints.

func (*Registry) Lookup

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

Lookup checks if a command name is already registered (case-insensitive).

func (*Registry) Register

func (r *Registry) Register(cmd ...Command)

Register adds a command to the registry. Names and aliases are stored lowercase for case-insensitive lookup.

func (*Registry) Sorted

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

Sorted returns all registered commands sorted by name.

Directories

Path Synopsis
Package commands provides built-in slash command implementations.
Package commands provides built-in slash command implementations.

Jump to

Keyboard shortcuts

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