Documentation
¶
Overview ¶
Package fragments provides a template system for reusable prompt fragments and recipes. It supports variable substitution, bash command execution, and markdown-based template processing for automating routine tasks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ArgumentMeta ¶
type ArgumentMeta struct {
Description string `yaml:"description,omitempty"`
Default string `yaml:"default,omitempty"`
}
ArgumentMeta defines metadata for a fragment argument
type HookConfig ¶
type HookConfig struct {
Handler string `yaml:"handler"` // Built-in handler name (e.g., "swap_context")
Once bool `yaml:"once,omitempty"` // If true, only execute on the first turn
}
HookConfig defines configuration for a recipe hook
type Metadata ¶
type Metadata struct {
Name string `yaml:"name,omitempty"`
Description string `yaml:"description,omitempty"`
AllowedTools []string `yaml:"allowed_tools,omitempty"`
AllowedCommands []string `yaml:"allowed_commands,omitempty"`
Arguments map[string]ArgumentMeta `yaml:"arguments,omitempty"` // Argument definitions with descriptions
Hooks map[string]HookConfig `yaml:"hooks,omitempty"` // Lifecycle hooks -> handler config
Workflow bool `yaml:"workflow,omitempty"` // If true, this fragment can be used as a subagent workflow
Profile string `yaml:"profile,omitempty"` // Profile name to use for workflow execution
}
Metadata represents YAML frontmatter in fragment files
type Option ¶
Option is a function that configures a FragmentProcessor
func WithAdditionalDirs ¶
WithAdditionalDirs adds additional fragment directories to the current ones If no directories are currently set, it starts with defaults first If dirs is empty, this is a no-op
func WithDefaultDirs ¶
func WithDefaultDirs() Option
WithDefaultDirs resets to default fragment directories
func WithFragmentDirs ¶
WithFragmentDirs sets custom fragment directories
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor handles fragment loading and rendering
func NewFragmentProcessor ¶
NewFragmentProcessor creates a new fragment processor with optional configuration
func (*Processor) GetFragmentMetadata ¶
GetFragmentMetadata retrieves a fragment's metadata and raw content without processing templates or executing bash commands. This is useful for listing and inspecting fragments without side effects.
func (*Processor) ListFragmentsWithMetadata ¶
ListFragmentsWithMetadata returns all available fragments from configured directories and built-in recipes, including their parsed metadata and content. Fragments are deduplicated with precedence given to user directories over built-ins.
func (*Processor) LoadFragment ¶
LoadFragment loads and processes a fragment template by name, applying variable substitution and executing any embedded bash commands. It returns the parsed fragment with its metadata and rendered content.