spells

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinFS

func BuiltinFS() fs.FS

BuiltinFS returns the embedded filesystem containing builtin spells

Types

type AppliedSpell

type AppliedSpell struct {
	// SpellName is the name of the spell that was applied
	SpellName string

	// SystemPrompt is the final system prompt after applying mode logic
	SystemPrompt string

	// Tool configuration
	EnabledTools  []string
	DisabledTools []string

	// Response configuration
	MaxTokens      int
	ResponseFormat string
	ResponseStyle  string

	// Reasoning configuration
	ReasoningEffort ReasoningEffort
	ShowThinking    bool

	// Sampling configuration
	Temperature float64
}

AppliedSpell contains the result of applying a spell to a session

func ApplySpell

func ApplySpell(spell *Spell, basePrompt string, modeOverride *LayerMode) *AppliedSpell

ApplySpell applies a spell to the session configuration basePrompt is the existing system prompt (from CLAUDE.md, etc.) modeOverride allows the user to override the spell's default mode

type LayerMode

type LayerMode string

LayerMode determines how a spell interacts with existing system prompt

const (
	// LayerModeReplace completely replaces the existing system prompt
	LayerModeReplace LayerMode = "replace"
	// LayerModeLayer adds to the existing system prompt
	LayerModeLayer LayerMode = "layer"
)

type Loader

type Loader struct {
	UserDir     string // User-global spells directory (~/.hex/spells/)
	ProjectDir  string // Project-local spells directory (.hex/spells/)
	BuiltinDir  string // Built-in spells directory (deprecated, use BuiltinFS)
	BuiltinFSys fs.FS  // Embedded filesystem for builtin spells
}

Loader discovers and loads spells from multiple directories

func NewLoader

func NewLoader() *Loader

NewLoader creates a loader with default directories

func (*Loader) LoadAll

func (l *Loader) LoadAll() ([]*Spell, error)

LoadAll discovers and loads all spells from all directories Later directories override earlier ones if spell names conflict

func (*Loader) LoadByName

func (l *Loader) LoadByName(name string) (*Spell, error)

LoadByName loads a specific spell by name from any directory

type ReasoningConfig

type ReasoningConfig struct {
	Effort       ReasoningEffort `yaml:"effort,omitempty"`        // none, low, medium, high
	ShowThinking bool            `yaml:"show_thinking,omitempty"` // expose thinking blocks
}

ReasoningConfig defines reasoning behavior for modern models

type ReasoningEffort

type ReasoningEffort string

ReasoningEffort levels for modern AI models

const (
	ReasoningEffortNone   ReasoningEffort = "none"
	ReasoningEffortLow    ReasoningEffort = "low"
	ReasoningEffortMedium ReasoningEffort = "medium"
	ReasoningEffortHigh   ReasoningEffort = "high"
)

type Registry

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

Registry stores and manages loaded spells

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new spell registry

func (*Registry) All

func (r *Registry) All() []*Spell

All returns all registered spells sorted by name

func (*Registry) Clear

func (r *Registry) Clear()

Clear removes all spells from the registry

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of registered spells

func (*Registry) Get

func (r *Registry) Get(name string) (*Spell, error)

Get retrieves a spell by name

func (*Registry) List

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

List returns all registered spell names sorted alphabetically

func (*Registry) Register

func (r *Registry) Register(spell *Spell) error

Register adds a spell to the registry

type ResponseConfig

type ResponseConfig struct {
	MaxTokens int    `yaml:"max_tokens,omitempty"` // max response tokens
	Format    string `yaml:"format,omitempty"`     // text, json, markdown
	Style     string `yaml:"style,omitempty"`      // concise, detailed, code-first
}

ResponseConfig defines response preferences

type SamplingConfig

type SamplingConfig struct {
	Temperature float64 `yaml:"temperature,omitempty"`
}

SamplingConfig defines legacy sampling parameters

type Spell

type Spell struct {
	// Metadata from system.md frontmatter
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
	Author      string `yaml:"author,omitempty"`
	Version     string `yaml:"version,omitempty"`

	// System prompt content (body of system.md)
	SystemPrompt string `yaml:"-"`

	// Configuration from config.yaml
	Config SpellConfig `yaml:"-"`

	// Tool overrides from tools/*.yaml
	ToolOverrides map[string]ToolOverride `yaml:"-"`

	// Runtime metadata
	Mode     LayerMode `yaml:"-"` // Effective mode (from config or override)
	Source   string    `yaml:"-"` // builtin, user, project
	FilePath string    `yaml:"-"` // Path to spell directory
}

Spell represents a switchable agent personality

func ParseSpellDirectory

func ParseSpellDirectory(dir string) (*Spell, error)

ParseSpellDirectory loads a spell from a directory

func ParseSpellFromFS

func ParseSpellFromFS(fsys fs.FS, spellName string) (*Spell, error)

ParseSpellFromFS loads a spell from an embedded filesystem

func (*Spell) String

func (s *Spell) String() string

String returns a formatted representation for display

func (*Spell) Validate

func (s *Spell) Validate() error

Validate checks if a spell has required fields

type SpellConfig

type SpellConfig struct {
	Mode      LayerMode       `yaml:"mode,omitempty"`
	Tools     ToolsConfig     `yaml:"tools,omitempty"`
	Reasoning ReasoningConfig `yaml:"reasoning,omitempty"`
	Response  ResponseConfig  `yaml:"response,omitempty"`
	Sampling  SamplingConfig  `yaml:"sampling,omitempty"`
}

SpellConfig holds all configuration options for a spell

type ToolOverride

type ToolOverride struct {
	Schema       map[string]interface{} `yaml:"schema,omitempty"`
	Defaults     map[string]interface{} `yaml:"defaults,omitempty"`
	Restrictions []string               `yaml:"restrictions,omitempty"`
}

ToolOverride customizes a specific tool's behavior

type ToolsConfig

type ToolsConfig struct {
	Enabled  []string `yaml:"enabled,omitempty"`  // Tools to enable (empty = all)
	Disabled []string `yaml:"disabled,omitempty"` // Tools to disable
}

ToolsConfig defines tool availability for a spell

Jump to

Keyboard shortcuts

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