slashcmd

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package slashcmd is the slash-command dispatcher — extracted from control.Controller to keep the turn loop lean. It classifies and routes slash commands to a Handler interface that the Controller implements. Completion logic lives here too so both the CLI TUI and desktop frontends share one implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActKind

type ActKind int

ActKind tells the Controller what to do.

const (
	ActNormal      ActKind = iota // run a normal turn
	ActMemory                     // # quick-add
	ActCompact                    // /compact
	ActNewSession                 // /new
	ActCancel                     // /cancel
	ActDST                        // /dst on|off|status|run
	ActShowAudit                  // /audit
	ActShowSearch                 // /search
	ActPermissions                // /permissions
	ActMCP                        // /mcp__...
	ActCustomCmd                  // custom command
	ActSkill                      // run skill
	ActNotice                     // management notice (already emitted)
	ActUnknown                    // unknown command
)

type Action

type Action struct {
	Kind       ActKind
	RawInput   string   // original or ref-expanded input
	Composed   string   // already composed (for custom commands / skills)
	MemoryNote string   // for ActMemory
	SearchTerm string   // for ActShowSearch
	PermInput  string   // for ActPermissions
	DSTCmd     string   // for ActDST
	NoticeText string   // pre-formatted notice (for ActNotice)
	RefErrs    []string // @-ref resolution errors
}

Action is a classified user input with enough context for the Controller to execute.

type ArgData

type ArgData struct {
	Skills       []skill.Skill
	ServerNames  []string
	ModelRefs    []string
	CurrentModel string
}

ArgData supplies dynamic data for slash-argument completion.

type Dispatcher

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

Dispatcher routes slash commands to the handler.

func New

func New(h Handler, cmds []command.Command, skills []skill.Skill, host *plugin.Host, sink event.Sink, refs RefResolver) *Dispatcher

New creates a Dispatcher.

func (*Dispatcher) Classify

func (d *Dispatcher) Classify(input string) Action

Dispatch classifies a raw input and returns an Action. It does NOT execute side effects — the caller (Controller) does that, keeping the turn loop in one place. This separation means Dispatch is pure classification; the Controller remains the sole execution engine.

func (*Dispatcher) ClassifyWithRefs

func (d *Dispatcher) ClassifyWithRefs(ctx context.Context, input string) Action

ClassifyWithRefs resolves @-references for plain-text input and returns Action.

func (*Dispatcher) Sink

func (d *Dispatcher) Sink() event.Sink

Sink returns the event sink so the caller (Controller) can emit events not covered by this dispatcher (e.g., plan-mode approval).

type Handler

type Handler interface {
	// List accessors for management notices
	Label() string
	MemoryDocs() []MemoryDoc
	Skills() []skill.Skill
	HookDescs() []HookDesc
	MCPServerNames() []string

	// Turn orchestration
	Compose(text string) string
	RunTurn(ctx context.Context, input string) error
	CustomCommand(input string) (sent string, found bool)
	RunSkill(input string) (sent string, found bool)
	MCPPrompt(ctx context.Context, input string) (sent string, found bool, err error)

	// Session
	Compact(ctx context.Context) error
	Snapshot() error
	NewSession() error
	Running() bool

	// Memory
	QuickAdd(note string) (string, error)

	// DST
	IsDSTAvailable() bool
	SetDSTEnabled(v bool)
	DSTEnabled() bool

	// Turn control
	Cancel()

	// Display
	ShowAudit()
	ShowSearch(term string)
	HandlePermissions(input string)
}

Handler is what the dispatcher needs from its host (control.Controller).

type HookDesc

type HookDesc struct {
	Event   string
	Scope   string
	Match   string
	Command string
}

HookDesc is a simplified hook description for listing.

type MemoryDoc

type MemoryDoc struct {
	Scope string
	Path  string
}

MemoryDoc is a simplified memory document for listing.

type RefResolver

type RefResolver interface {
	HasRefs(line string) bool
	ResolveRefs(ctx context.Context, line string) (block string, errs []string)
}

RefResolver resolves @-references in user input.

type SlashItem

type SlashItem struct {
	Label   string `json:"label"`
	Insert  string `json:"insert"`
	Hint    string `json:"hint"`
	Descend bool   `json:"descend"`
}

SlashItem is one slash-completion suggestion.

Jump to

Keyboard shortcuts

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